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

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