Kernel/x86 - Cleaning up and implmented address space nuking
[tpg/acess2.git] / Kernel / arch / x86 / include / arch.h
1 /*
2  * Acess2
3  * - x86 Architecture
4  * arch/x86/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 LOCK_DISABLE_INTS       1
18
19 // - Processor/Machine Specific Features
20 #if ARCH != x86 && ARCH != x86_smp
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         volatile int    Lock;   //!< Lock value
44         
45         #if LOCK_DISABLE_INTS
46          int    IF;     //!< Interrupt state on call to SHORTLOCK
47         #endif
48 };
49
50 // === MACROS ===
51 /**
52  * \brief Halt the CPU (shorter version of yield)
53  */
54 #if 1
55 #define HALT()  do { \
56         Uint32  flags; \
57         __asm__ __volatile__ ("pushf;pop %0" : "=a"(flags)); \
58         if( !(flags & 0x200) )  Panic("HALT called with interrupts disabled"); \
59         __asm__ __volatile__ ("hlt"); \
60 } while(0)
61 #else
62 #define HALT()  __asm__ __volatile__ ("hlt")
63 #endif
64 /**
65  * \brief Fire a magic breakpoint (bochs)
66  */
67 #define MAGIC_BREAK()   __asm__ __volatile__ ("xchg %bx, %bx")
68
69 // === TYPES ===
70 typedef unsigned int    Uint;   // Unsigned machine native integer
71 typedef unsigned char   Uint8;
72 typedef unsigned short  Uint16;
73 typedef unsigned long   Uint32;
74 typedef unsigned long long      Uint64;
75 typedef signed int              Sint;   // Signed Machine Native integer
76 typedef signed char             Sint8;
77 typedef signed short    Sint16;
78 typedef signed long             Sint32;
79 typedef signed long long        Sint64;
80 typedef Uint    size_t;
81 typedef char    BOOL;
82
83 typedef Uint32  tPAddr;
84 typedef Uint32  tVAddr;
85
86 typedef struct {
87         Uint32  gs, fs, es, ds;
88         Uint32  edi, esi, ebp, kesp;
89         Uint32  ebx, edx, ecx, eax;
90         Uint32  int_num, err_code;
91         Uint32  eip, cs;
92         Uint32  eflags, esp, ss;
93 } tRegs;
94
95 typedef struct {
96         Uint    Resvd1[4];      // GS, FS, ES, DS
97         Uint    Arg4, Arg5;     // EDI, ESI
98         Uint    Arg6;   // EBP
99         Uint    Resvd2[1];      // Kernel ESP
100         union {
101                 Uint    Arg1;
102                 Uint    Error;
103         };      // EBX
104         union {
105                 Uint    Arg3;
106                 Uint    RetHi;  // High 32 bits of ret
107         };      // EDX
108         Uint    Arg2;   // ECX
109         union {
110                 Uint    Num;
111                 Uint    Return;
112         };      // EAX
113         Uint    Resvd3[5];      // Int, Err, Eip, CS, ...
114         Uint    StackPointer;   // ESP
115         Uint    Resvd4[1];      // SS
116 } tSyscallRegs;
117
118 // === FUNCTIONS ===
119 extern void     Debug_PutCharDebug(char ch);
120 extern void     Debug_PutStringDebug(const char *String);
121
122 extern int      IS_LOCKED(struct sShortSpinlock *Lock);
123 extern int      CPU_HAS_LOCK(struct sShortSpinlock *Lock);
124 extern void     SHORTLOCK(struct sShortSpinlock *Lock);
125 extern void     SHORTREL(struct sShortSpinlock *Lock);
126
127 #endif  // !defined(_ARCH_H_)

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