773556840a9dca2ca272d5fc2884ef3fff67a422
[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 // === MACROS ===
33 typedef volatile int    tSpinlock;
34 #define IS_LOCKED(lockptr)      (!!(*(tSpinlock*)lockptr))
35 /**
36  * \brief Inter-Process interrupt (does a Yield)
37  */
38 #define LOCK(lockptr)   do {\
39         int v=1;\
40         while(v) {\
41                 __ASM__("xchgl %%eax, (%%edi)":"=a"(v):"a"(1),"D"(lockptr));\
42                 if(v) Threads_Yield();\
43         }\
44 }while(0)
45 /**
46  * \brief Tight spinlock (does a HLT)
47  */
48 #define TIGHTLOCK(lockptr)      do{\
49         int v=1;\
50         while(v) {\
51                 __ASM__("xchgl %%eax,(%%edi)":"=a"(v):"a"(1),"D"(lockptr));\
52                 if(v) __ASM__("hlt");\
53         }\
54 }while(0)
55 /**
56  * \brief Very Tight spinlock (short inter-cpu lock)
57  */
58 #define VTIGHTLOCK(lockptr)     do{\
59         int v=1;\
60         while(v)__ASM__("xchgl %%eax,(%%edi)":"=a"(v):"a"(1),"D"(lockptr));\
61 }while(0)
62 /**
63  * \brief Release a held spinlock
64  */
65 #define RELEASE(lockptr)        __ASM__("lock andl $0, (%%edi)"::"D"(lockptr));
66 /**
67  * \brief Halt the CPU
68  */
69 #define HALT()  __asm__ __volatile__ ("hlt")
70
71 // === TYPES ===
72 typedef unsigned int    Uint;   // Unsigned machine native integer
73 typedef unsigned char   Uint8;
74 typedef unsigned short  Uint16;
75 typedef unsigned long   Uint32;
76 typedef unsigned long long      Uint64;
77 typedef signed int              Sint;   // Signed Machine Native integer
78 typedef signed char             Sint8;
79 typedef signed short    Sint16;
80 typedef signed long             Sint32;
81 typedef signed long long        Sint64;
82 typedef Uint    size_t;
83
84 typedef Uint64  tPAddr;
85 typedef Uint32  tVAddr;
86
87 typedef struct {
88     Uint        gs, fs, es, ds;
89     Uint        edi, esi, ebp, kesp;
90         Uint    ebx, edx, ecx, eax;
91     Uint        int_num, err_code;
92     Uint        eip, cs;
93         Uint    eflags, esp, ss;
94 } tRegs;
95
96 typedef struct {
97         Uint    Resvd1[4];      // GS, FS, ES, DS
98         Uint    Arg4, Arg5;     // EDI, ESI
99         Uint    Arg6;   // EBP
100         Uint    Resvd2[1];      // Kernel ESP
101         union {
102                 Uint    Arg1;
103                 Uint    Error;
104         };      // EBX
105         union {
106                 Uint    Arg3;
107                 Uint    RetHi;  // High 32 bits of ret
108         };      // EDX
109         Uint    Arg2;   // ECX
110         union {
111                 Uint    Num;
112                 Uint    Return;
113         };      // EAX
114         Uint    Resvd3[5];      // Int, Err, Eip, CS, ...
115         Uint    StackPointer;   // ESP
116         Uint    Resvd4[1];      // SS
117 } tSyscallRegs;
118
119 typedef struct {
120         #if USE_PAE
121         Uint    PDPT[4];
122         #else
123         Uint    CR3;
124         #endif
125 } tMemoryState;
126
127 typedef struct {
128         Uint    EIP, ESP, EBP;
129 } tTaskState;
130
131 #endif  // !defined(_ARCH_H_)

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