22c551fc218c818fd03181950ad8689e7124683c
[tpg/acess2.git] / Kernel / arch / x86_64 / include / arch.h
1 /*
2  * Acess2 x86-64 Architecure Module
3  * - By John Hodge (thePowersGang)
4  */
5 #ifndef _ARCH_H_
6 #define _ARCH_H_
7
8 #include <stdint.h>
9 #define KERNEL_BASE     0xFFFF8000##00000000
10 #define BITS    64
11
12 // === Core Types ===
13 typedef signed char     Sint8;
14 typedef unsigned char   Uint8;
15 typedef signed short    Sint16;
16 typedef unsigned short  Uint16;
17 typedef signed int      Sint32;
18 typedef unsigned int    Uint32;
19 #if __WORDSIZE == 64
20 typedef signed long int Sint64;
21 typedef unsigned long int       Uint64;
22 #else
23 typedef signed long long int    Sint64;
24 typedef unsigned long long int  Uint64;
25 #endif
26
27 typedef Uint64  Uint;
28 typedef Uint64  tPAddr;
29 typedef Uint64  tVAddr;
30
31 //typedef unsigned int  size_t;
32 typedef Uint64  size_t;
33
34 typedef volatile int    tSpinlock;
35 #define IS_LOCKED(lockptr)      (!!(*(tSpinlock*)lockptr))
36 #define LOCK(lockptr)   do {int v=1;\
37         while(v)\
38         __asm__ __volatile__("lock xchgl %%eax, (%%rdi)":"=a"(v):"a"(1),"D"(lockptr));\
39         }while(0)
40 #define RELEASE(lockptr)        __asm__ __volatile__("lock andl $0, (%%rdi)"::"D"(lockptr));
41 #define HALT()  __asm__ __volatile__ ("hlt")
42
43 // Systemcall Registers
44 // TODO: Fix this structure
45 typedef struct sSyscallRegs
46 {
47         Uint    Arg4, Arg5;     // RDI, RSI
48         Uint    Arg6;   // RBP
49         Uint    Resvd2[1];      // Kernel RSP
50         union {
51                 Uint    Arg1;
52                 Uint    Error;
53         };      // RBX
54         union {
55                 Uint    Arg3;
56                 Uint    RetHi;  // High 64 bits of ret
57         };      // RDX
58         Uint    Arg2;   // RCX
59         union {
60                 Uint    Num;
61                 Uint    Return;
62         };      // RAX
63         Uint    Resvd3[5];      // Int, Err, rip, CS, ...
64         Uint    StackPointer;   // RSP
65         Uint    Resvd4[1];      // SS   
66 }       tSyscallRegs;
67
68 #endif
69

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