Kernel/x86 - Structure for watchpoints (not used)
[tpg/acess2.git] / KernelLand / Kernel / arch / x86 / include / arch.h
1 /*
2  * Acess2
3  * - x86 Architecture
4  * arch/x86/include/arch.h
5  */
6 #ifndef _ARCH_H_
7 #define _ARCH_H_
8
9 // - Base Defintions
10 #define KERNEL_BASE     0xC0000000
11 #define BITS    32
12 #define PAGE_SIZE       0x1000
13
14 #define INVLPTR ((void*)-1)
15
16 // Allow nested spinlocks?
17 #define LOCK_DISABLE_INTS       1
18
19 // - Processor/Machine Specific Features
20 #if ARCH != x86 && ARCH != x86_smp
21 # error "Unknown architecture '" #ARCH "'"
22 #endif
23
24 #if USE_MP
25 # define        MAX_CPUS        8
26 #else
27 # define        MAX_CPUS        1
28 #endif
29
30 #if USE_PAE
31 # define        PHYS_BITS       48
32 #else
33 # define        PHYS_BITS       32
34 #endif
35
36 #define __ASM__ __asm__ __volatile__
37
38 // === Spinlocks ===
39 /**
40  * \brief Short Spinlock structure
41  */
42 struct sShortSpinlock {
43         volatile int    Lock;   //!< Lock value
44         
45         #if LOCK_DISABLE_INTS
46          int    IF;     //!< Interrupt state on call to SHORTLOCK
47         #endif
48         void    *LockedBy;
49 };
50
51 // === MACROS ===
52 /**
53  * \brief Halt the CPU (shorter version of yield)
54  */
55 #if 1
56 #define HALT()  do { \
57         Uint32  flags; \
58         __asm__ __volatile__ ("pushf;pop %0" : "=a"(flags)); \
59         if( !(flags & 0x200) )  Panic("HALT called with interrupts disabled"); \
60         __asm__ __volatile__ ("hlt"); \
61 } while(0)
62 #else
63 #define HALT()  __asm__ __volatile__ ("hlt")
64 #endif
65 /**
66  * \brief Fire a magic breakpoint (bochs)
67  */
68 #define MAGIC_BREAK()   __asm__ __volatile__ ("xchg %bx, %bx")
69 // TODO: SMP halt request too
70 #define HALT_CPU()      for(;;) { __asm__ __volatile__ ("cli; hlt"); }
71
72 #define ASM(v...)       __asm__ __volatile__ (v)
73
74 // === TYPES ===
75 typedef unsigned int    Uint;   // Unsigned machine native integer
76 typedef unsigned char   Uint8;
77 typedef unsigned short  Uint16;
78 typedef unsigned long   Uint32;
79 typedef unsigned long long      Uint64;
80 typedef signed int              Sint;   // Signed Machine Native integer
81 typedef signed char             Sint8;
82 typedef signed short    Sint16;
83 typedef signed long             Sint32;
84 typedef signed long long        Sint64;
85 typedef char    BOOL;
86
87 typedef Uint32  tPAddr;
88 typedef Uint32  tVAddr;
89
90 typedef struct {
91         Uint32  gs, fs, es, ds;
92         Uint32  edi, esi, ebp, kesp;
93         Uint32  ebx, edx, ecx, eax;
94         Uint32  int_num, err_code;
95         Uint32  eip, cs;
96         Uint32  eflags, esp, ss;
97 } tRegs;
98
99 typedef struct {
100         Uint    Resvd1[4];      // GS, FS, ES, DS
101         Uint    Arg4, Arg5;     // EDI, ESI
102         Uint    Arg6;   // EBP
103         Uint    Resvd2[1];      // Kernel ESP
104         union {
105                 Uint    Arg1;
106                 Uint    Error;
107         };      // EBX
108         union {
109                 Uint    Arg3;
110                 Uint    RetHi;  // High 32 bits of ret
111         };      // EDX
112         Uint    Arg2;   // ECX
113         union {
114                 Uint    Num;
115                 Uint    Return;
116         };      // EAX
117         Uint    Resvd3[5];      // Int, Err, Eip, CS, ...
118         Uint    StackPointer;   // ESP
119         Uint    Resvd4[1];      // SS
120 } tSyscallRegs;
121
122 // === FUNCTIONS ===
123 extern void     Debug_PutCharDebug(char ch);
124 extern void     Debug_PutStringDebug(const char *String);
125
126 extern int      IS_LOCKED(struct sShortSpinlock *Lock);
127 extern int      CPU_HAS_LOCK(struct sShortSpinlock *Lock);
128 extern void     SHORTLOCK(struct sShortSpinlock *Lock);
129 extern void     SHORTREL(struct sShortSpinlock *Lock);
130
131 #endif  // !defined(_ARCH_H_)

UCC git Repository :: git.ucc.asn.au