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

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