Kernel - x86 Fixed a couple of bugs
[tpg/acess2.git] / Kernel / arch / x86 / include / arch.h
1 /*
2  * Acess2
3  * - x86 Architecture
4  * arch/i386/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
13 #define INVLPTR ((void*)-1)
14
15 // Allow nested spinlocks?
16 #define STACKED_LOCKS   2       // 0: No, 1: Per-CPU, 2: Per-Thread
17 #define LOCK_DISABLE_INTS       1
18
19 // - Processor/Machine Specific Features
20 #if ARCH != i386 && ARCH != i486 && ARCH != i586
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         #if STACKED_LOCKS == 2
44         volatile void   *Lock;  //!< Lock value
45         #else
46         volatile int    Lock;   //!< Lock value
47         #endif
48         
49         #if LOCK_DISABLE_INTS
50          int    IF;     //!< Interrupt state on call to SHORTLOCK
51         #endif
52         #if STACKED_LOCKS
53          int    Depth;
54         #endif
55 };
56
57 // === MACROS ===
58 /**
59  * \brief Halt the CPU (shorter version of yield)
60  */
61 #if 1
62 #define HALT()  do { \
63         Uint32  flags; \
64         __asm__ __volatile__ ("pushf;pop %0" : "=a"(flags)); \
65         if( !(flags & 0x200) )  Panic("HALT called with interrupts disabled"); \
66         __asm__ __volatile__ ("hlt"); \
67 } while(0)
68 #else
69 #define HALT()  __asm__ __volatile__ ("hlt")
70 #endif
71 /**
72  * \brief Fire a magic breakpoint (bochs)
73  */
74 #define MAGIC_BREAK()   __asm__ __volatile__ ("xchg %bx, %bx")
75
76 // === TYPES ===
77 typedef unsigned int    Uint;   // Unsigned machine native integer
78 typedef unsigned char   Uint8;
79 typedef unsigned short  Uint16;
80 typedef unsigned long   Uint32;
81 typedef unsigned long long      Uint64;
82 typedef signed int              Sint;   // Signed Machine Native integer
83 typedef signed char             Sint8;
84 typedef signed short    Sint16;
85 typedef signed long             Sint32;
86 typedef signed long long        Sint64;
87 typedef Uint    size_t;
88 typedef char    BOOL;
89
90 typedef Uint64  tPAddr;
91 typedef Uint32  tVAddr;
92
93 typedef struct {
94         Uint32  gs, fs, es, ds;
95         Uint32  edi, esi, ebp, kesp;
96         Uint32  ebx, edx, ecx, eax;
97         Uint32  int_num, err_code;
98         Uint32  eip, cs;
99         Uint32  eflags, esp, ss;
100 } tRegs;
101
102 typedef struct {
103         Uint    Resvd1[4];      // GS, FS, ES, DS
104         Uint    Arg4, Arg5;     // EDI, ESI
105         Uint    Arg6;   // EBP
106         Uint    Resvd2[1];      // Kernel ESP
107         union {
108                 Uint    Arg1;
109                 Uint    Error;
110         };      // EBX
111         union {
112                 Uint    Arg3;
113                 Uint    RetHi;  // High 32 bits of ret
114         };      // EDX
115         Uint    Arg2;   // ECX
116         union {
117                 Uint    Num;
118                 Uint    Return;
119         };      // EAX
120         Uint    Resvd3[5];      // Int, Err, Eip, CS, ...
121         Uint    StackPointer;   // ESP
122         Uint    Resvd4[1];      // SS
123 } tSyscallRegs;
124
125 typedef struct {
126         #if USE_PAE
127         Uint    PDPT[4];
128         #else
129         Uint    CR3;
130         #endif
131 } tMemoryState;
132
133 typedef struct {
134         Uint    EIP, ESP, EBP;
135         Uint32  UserCS, UserEIP;
136 } tTaskState;
137
138 // === FUNCTIONS ===
139 extern void     Debug_PutCharDebug(char ch);
140 extern void     Debug_PutStringDebug(const char *String);
141
142 extern int      IS_LOCKED(struct sShortSpinlock *Lock);
143 extern int      CPU_HAS_LOCK(struct sShortSpinlock *Lock);
144 extern void     SHORTLOCK(struct sShortSpinlock *Lock);
145 extern void     SHORTREL(struct sShortSpinlock *Lock);
146
147 #endif  // !defined(_ARCH_H_)

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