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

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