Changed spinlock mechananisim
[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 // - Processor/Machine Specific Features
14 #if ARCH != i386 && ARCH != i486 && ARCH != i586
15 # error "Unknown architecture '" #ARCH "'"
16 #endif
17
18 #if USE_MP
19 # define        MAX_CPUS        8
20 #else
21 # define        MAX_CPUS        1
22 #endif
23
24 #if USE_PAE
25 # define        PHYS_BITS       48
26 #else
27 # define        PHYS_BITS       32
28 #endif
29
30 #define __ASM__ __asm__ __volatile__
31
32 #define LONGLOCK_NUM_THREADS    8
33
34 // === MACROS ===
35 struct sShortSpinlock {
36         volatile int    Lock;
37          int    IF;
38 };
39 /**
40  * \brief Determine if a short spinlock is locked
41  */
42 static inline int IS_LOCKED(struct sShortSpinlock *Lock) {
43         return !!Lock->Lock;
44 }
45 /**
46  * \brief Acquire a Short Spinlock
47  * \note Stops interrupts, so be careful
48  */
49 static inline void SHORTLOCK(struct sShortSpinlock *Lock) {
50          int    v = 1;
51         __ASM__ ("pushf;\n\tpop %%eax" : "=a"(Lock->IF));
52         Lock->IF &= 0x200;
53         __ASM__ ("cli");        // Stop task switches
54         // Wait for another CPU to release
55         while(v)
56                 __ASM__("xchgl %%eax, (%%edi)":"=a"(v):"a"(1),"D"(&Lock->Lock));
57 }
58 /**
59  * \brief Release a short lock
60  */
61 static inline void SHORTREL(struct sShortSpinlock *Lock) {
62         Lock->Lock = 0;
63         #if 0
64         __ASM__ ("pushf;\n\tor %0, (%%esp);\n\tpopf" : : "a"(Lock->IF));
65         #else
66         if(Lock->IF)    __ASM__ ("sti");
67         #endif
68 }
69 /**
70  * \brief Halt the CPU
71  */
72 #define HALT()  __asm__ __volatile__ ("hlt")
73 #define MAGIC_BREAK()   __asm__ __volatile__ ("xchg %bx, %bx")
74
75 // === TYPES ===
76 typedef unsigned int    Uint;   // Unsigned machine native integer
77 typedef unsigned char   Uint8;
78 typedef unsigned short  Uint16;
79 typedef unsigned long   Uint32;
80 typedef unsigned long long      Uint64;
81 typedef signed int              Sint;   // Signed Machine Native integer
82 typedef signed char             Sint8;
83 typedef signed short    Sint16;
84 typedef signed long             Sint32;
85 typedef signed long long        Sint64;
86 typedef Uint    size_t;
87
88 typedef Uint64  tPAddr;
89 typedef Uint32  tVAddr;
90
91 typedef struct {
92     Uint        gs, fs, es, ds;
93     Uint        edi, esi, ebp, kesp;
94         Uint    ebx, edx, ecx, eax;
95     Uint        int_num, err_code;
96     Uint        eip, cs;
97         Uint    eflags, esp, ss;
98 } tRegs;
99
100 typedef struct {
101         Uint    Resvd1[4];      // GS, FS, ES, DS
102         Uint    Arg4, Arg5;     // EDI, ESI
103         Uint    Arg6;   // EBP
104         Uint    Resvd2[1];      // Kernel ESP
105         union {
106                 Uint    Arg1;
107                 Uint    Error;
108         };      // EBX
109         union {
110                 Uint    Arg3;
111                 Uint    RetHi;  // High 32 bits of ret
112         };      // EDX
113         Uint    Arg2;   // ECX
114         union {
115                 Uint    Num;
116                 Uint    Return;
117         };      // EAX
118         Uint    Resvd3[5];      // Int, Err, Eip, CS, ...
119         Uint    StackPointer;   // ESP
120         Uint    Resvd4[1];      // SS
121 } tSyscallRegs;
122
123 typedef struct {
124         #if USE_PAE
125         Uint    PDPT[4];
126         #else
127         Uint    CR3;
128         #endif
129 } tMemoryState;
130
131 typedef struct {
132         Uint    EIP, ESP, EBP;
133 } tTaskState;
134
135 #endif  // !defined(_ARCH_H_)

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