66d7a79259d667b10a66398b0568662293be1437
[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 #define HALT()  __asm__ __volatile__ ("hlt")
62 /**
63  * \brief Fire a magic breakpoint (bochs)
64  */
65 #define MAGIC_BREAK()   __asm__ __volatile__ ("xchg %bx, %bx")
66
67 // === TYPES ===
68 typedef unsigned int    Uint;   // Unsigned machine native integer
69 typedef unsigned char   Uint8;
70 typedef unsigned short  Uint16;
71 typedef unsigned long   Uint32;
72 typedef unsigned long long      Uint64;
73 typedef signed int              Sint;   // Signed Machine Native integer
74 typedef signed char             Sint8;
75 typedef signed short    Sint16;
76 typedef signed long             Sint32;
77 typedef signed long long        Sint64;
78 typedef Uint    size_t;
79 typedef char    BOOL;
80
81 typedef Uint64  tPAddr;
82 typedef Uint32  tVAddr;
83
84 typedef struct {
85         Uint32  gs, fs, es, ds;
86         Uint32  edi, esi, ebp, kesp;
87         Uint32  ebx, edx, ecx, eax;
88         Uint32  int_num, err_code;
89         Uint32  eip, cs;
90         Uint32  eflags, esp, ss;
91 } tRegs;
92
93 typedef struct {
94         Uint    Resvd1[4];      // GS, FS, ES, DS
95         Uint    Arg4, Arg5;     // EDI, ESI
96         Uint    Arg6;   // EBP
97         Uint    Resvd2[1];      // Kernel ESP
98         union {
99                 Uint    Arg1;
100                 Uint    Error;
101         };      // EBX
102         union {
103                 Uint    Arg3;
104                 Uint    RetHi;  // High 32 bits of ret
105         };      // EDX
106         Uint    Arg2;   // ECX
107         union {
108                 Uint    Num;
109                 Uint    Return;
110         };      // EAX
111         Uint    Resvd3[5];      // Int, Err, Eip, CS, ...
112         Uint    StackPointer;   // ESP
113         Uint    Resvd4[1];      // SS
114 } tSyscallRegs;
115
116 typedef struct {
117         #if USE_PAE
118         Uint    PDPT[4];
119         #else
120         Uint    CR3;
121         #endif
122 } tMemoryState;
123
124 typedef struct {
125         Uint    EIP, ESP, EBP;
126         Uint32  UserCS, UserEIP;
127 } tTaskState;
128
129 // === FUNCTIONS ===
130 extern void     Debug_PutCharDebug(char ch);
131 extern void     Debug_PutStringDebug(const char *String);
132
133 extern int      IS_LOCKED(struct sShortSpinlock *Lock);
134 extern int      CPU_HAS_LOCK(struct sShortSpinlock *Lock);
135 extern void     SHORTLOCK(struct sShortSpinlock *Lock);
136 extern void     SHORTREL(struct sShortSpinlock *Lock);
137
138 #endif  // !defined(_ARCH_H_)

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