ccd1875f94401e5bc561143810fd33d95eb476ed
[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 // - Memory Layout
10 #define MM_USER_MIN     0x00200000
11 #define USER_STACK_SZ   0x00010000
12 #define USER_STACK_TOP  0x00800000
13 #define MM_USER_MAX     0xBC000000
14 #define MM_PPD_MIN      0xBC000000      // Per-Process Data
15 #define MM_PPD_VFS      0xBC000000      // 
16 #define MM_PPD_CFG      0xBFFFF000      // 
17 #define MM_PPD_MAX      0xB0000000
18 #define KERNEL_BASE     0xC0000000
19 #define MM_KHEAP_BASE   0xC0400000      // C+4MiB
20 #define MM_KHEAP_MAX    0xCF000000      //
21 #define MM_KERNEL_VFS   0xCF000000      // 
22 #define MM_KUSER_CODE   0xCFFF0000      // 16 Pages
23 #define MM_MODULE_MIN   0xD0000000      // Lowest Module Address
24 #define MM_MODULE_MAX   0xF0000000      // 512 MiB
25
26 #define BITS    32
27
28 // - Processor/Machine Specific Features
29 #if ARCH == i386
30 // Uses no advanced features
31 # define        USE_MP  0
32 # define        USE_PAE 0
33 #elif ARCH == i486
34 // MP Only
35 # define        USE_MP  1
36 # define        USE_PAE 0
37 #elif ARCH == i586
38 // All Enabled
39 # define        USE_MP  1
40 # define        USE_PAE 1
41 #else
42 # error "Unknown architecture '" #ARCH "'"
43 #endif
44
45 #if USE_MP
46 # define        MAX_CPUS        8
47 #else
48 # define        MAX_CPUS        1
49 #endif
50
51 #if USE_PAE
52 # define        PHYS_BITS       48
53 #else
54 # define        PHYS_BITS       32
55 #endif
56
57 // === MACROS ===
58 typedef volatile int    tSpinlock;
59 #define LOCK(lockptr)   do {int v=1;\
60         while(v)__asm__ __volatile__("lock xchgl %%eax, (%%edi)":"=a"(v):"a"(1),"D"(lockptr));}while(0)
61 #define RELEASE(lockptr)        __asm__ __volatile__("lock andl $0, (%%edi)"::"D"(lockptr));
62 #define HALT()  __asm__ __volatile__ ("hlt")
63
64 // === TYPES ===
65 typedef unsigned int    Uint;   // Unsigned machine native integer
66 typedef unsigned char   Uint8;
67 typedef unsigned short  Uint16;
68 typedef unsigned long   Uint32;
69 typedef unsigned long long      Uint64;
70 typedef signed int              Sint;   // Signed Machine Native integer
71 typedef signed char             Sint8;
72 typedef signed short    Sint16;
73 typedef signed long             Sint32;
74 typedef signed long long        Sint64;
75 typedef Uint    size_t;
76
77 typedef Uint64  tPAddr;
78 typedef Uint32  tVAddr;
79
80 typedef struct {
81     Uint        gs, fs, es, ds;
82     Uint        edi, esi, ebp, kesp;
83         Uint    ebx, edx, ecx, eax;
84     Uint        int_num, err_code;
85     Uint        eip, cs;
86         Uint    eflags, esp, ss;
87 } tRegs;
88
89 typedef struct {
90         Uint    Resvd1[4];      // GS, FS, ES, DS
91         Uint    Arg4, Arg5;     // EDI, ESI
92         Uint    Arg6;   // EBP
93         Uint    Resvd2[1];      // Kernel ESP
94         union {
95                 Uint    Arg1;
96                 Uint    Error;
97         };      // EBX
98         union {
99                 Uint    Arg3;
100                 Uint    RetHi;  // High 32 bits of ret
101         };      // EDX
102         Uint    Arg2;   // ECX
103         union {
104                 Uint    Num;
105                 Uint    Return;
106         };      // EAX
107         Uint    Resvd3[5];      // Int, Err, Eip, CS, ...
108         Uint    StackPointer;   // ESP
109         Uint    Resvd4[1];      // SS
110 } tSyscallRegs;
111
112 typedef struct {
113         Uint16  LimitLow;
114         Uint16  BaseLow;
115         Uint8   BaseMid;
116         Uint8   Access;
117         struct {
118                 unsigned LimitHi:       4;
119                 unsigned Flags:         4;
120         } __attribute__ ((packed));
121         Uint8   BaseHi;
122 } __attribute__ ((packed)) tGDT;
123
124 typedef struct {
125         #if USE_PAE
126         Uint    PDPT[4];
127         #else
128         Uint    CR3;
129         #endif
130 } tMemoryState;
131
132 typedef struct {
133         Uint    EIP, ESP, EBP;
134 } tTaskState;
135
136 #endif  // !defined(_ARCH_H_)

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