92ccf056bfe5e4068e53484688c6e4dbd91f29f7
[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 == i586
34 // All Enabled
35 # define        USE_MP  1
36 # define        USE_PAE 1
37 #else
38 # error "Unknown architecture '" #ARCH "'"
39 #endif
40
41 #if USE_MP
42 # define        MAX_CPUS        8
43 #else
44 # define        MAX_CPUS        1
45 #endif
46
47 #if USE_PAE
48 # define        PHYS_BITS       48
49 #else
50 # define        PHYS_BITS       32
51 #endif
52
53 // === MACROS ===
54 typedef volatile int    tSpinlock;
55 #define LOCK(lockptr)   do {int v=1;\
56         while(v)__asm__ __volatile__("lock xchgl %%eax, (%%edi)":"=a"(v):"a"(1),"D"(lockptr));}while(0)
57 #define RELEASE(lockptr)        __asm__ __volatile__("lock andl $0, (%%edi)"::"D"(lockptr));
58 #define HALT()  __asm__ __volatile__ ("hlt")
59
60 // === TYPES ===
61 typedef unsigned int    Uint;   // Unsigned machine native integer
62 typedef unsigned char   Uint8;
63 typedef unsigned short  Uint16;
64 typedef unsigned long   Uint32;
65 typedef unsigned long long      Uint64;
66 typedef signed int              Sint;   // Signed Machine Native integer
67 typedef signed char             Sint8;
68 typedef signed short    Sint16;
69 typedef signed long             Sint32;
70 typedef signed long long        Sint64;
71 typedef Uint    size_t;
72
73 #if USE_PAE
74 typedef Uint64  tPAddr;
75 #else
76 typedef Uint32  tPAddr;
77 #endif
78 typedef Uint32  tVAddr;
79
80 typedef void (*tThreadFunction)(void*);
81
82 typedef struct {
83     Uint        gs, fs, es, ds;
84     Uint        edi, esi, ebp, kesp;
85         Uint    ebx, edx, ecx, eax;
86     Uint        int_num, err_code;
87     Uint        eip, cs;
88         Uint    eflags, esp, ss;
89 } tRegs;
90
91 typedef struct {
92         Uint    Resvd1[4];      // GS, FS, ES, DS
93         Uint    Arg4, Arg5;     // EDI, ESI
94         Uint    Arg6;   // EBP
95         Uint    Resvd2[1];      // Kernel ESP
96         union {
97                 Uint    Arg1;
98                 Uint    Error;
99         };      // EBX
100         union {
101                 Uint    Arg3;
102                 Uint    RetHi;  // High 32 bits of ret
103         };      // EDX
104         Uint    Arg2;   // ECX
105         union {
106                 Uint    Num;
107                 Uint    Return;
108         };      // EAX
109         Uint    Resvd3[5];      // Int, Err, Eip, CS, ...
110         Uint    StackPointer;   // ESP
111         Uint    Resvd4[1];      // SS
112 } tSyscallRegs;
113
114 typedef struct {
115         Uint16  LimitLow;
116         Uint16  BaseLow;
117         Uint8   BaseMid;
118         Uint8   Access;
119         struct {
120                 unsigned LimitHi:       4;
121                 unsigned Flags:         4;
122         } __attribute__ ((packed));
123         Uint8   BaseHi;
124 } __attribute__ ((packed)) tGDT;
125
126 typedef struct {
127         #if USE_PAE
128         Uint    PDPT[4];
129         #else
130         Uint    CR3;
131         #endif
132 } tMemoryState;
133
134 typedef struct {
135         Uint    EIP, ESP, EBP;
136 } tTaskState;
137
138 // --- Interface Flags & Macros
139 #define CLONE_VM        0x10
140
141 #endif  // !defined(_ARCH_H_)

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