bde7abda96fc85cda76fd33ffceff6700d4927cb
[tpg/acess2.git] / KernelLand / 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 USER_MAX        0x00007FFF##FFFFF000
10 #define KERNEL_BASE     0xFFFFFFFF##80000000
11 #define BITS    64
12 #define PAGE_SIZE       0x1000
13
14 #define STACKED_LOCKS   2       // 0: No, 1: Per-CPU, 2: Per-Thread
15 #define LOCK_DISABLE_INTS       0
16
17 #define INVLPTR ((void*)0x0FFFFFFFFFFFFFFFULL)
18
19 //#define INT_MAX       0x7FFFFFFF
20 //#define UINT_MAX      0xFFFFFFFF
21
22 // === Core Types ===
23 typedef signed char     Sint8;
24 typedef unsigned char   Uint8;
25 typedef signed short    Sint16;
26 typedef unsigned short  Uint16;
27 typedef signed int      Sint32;
28 typedef unsigned int    Uint32;
29 #if __WORDSIZE == 64
30 typedef signed long int Sint64;
31 typedef unsigned long int       Uint64;
32 #else
33 typedef signed long long int    Sint64;
34 typedef unsigned long long int  Uint64;
35 #endif
36
37 typedef Sint64  Sint;
38 typedef Uint64  Uint;
39 typedef Uint64  tPAddr;
40 typedef Uint64  tVAddr;
41
42 typedef Uint64  size_t;
43 typedef char    BOOL;
44
45 #define __ASM__ __asm__ __volatile__
46
47 // === MACROS ===
48 /**
49  * \brief Halt the CPU
50  */
51 #define HALT()  __asm__ __volatile__ ("sti;\n\thlt")
52 /**
53  * \brief Fire a magic breakpoint (bochs)
54  */
55 #define MAGIC_BREAK()   __asm__ __volatile__ ("xchg %bx, %bx")
56
57 // Systemcall Registers
58 // TODO: Fix this structure
59 typedef struct sSyscallRegs
60 {
61         union {
62                 Uint    Num;
63                 Uint    Return;
64         };      // RAX
65         Uint    Error;  // RBX
66         Uint    Arg1;   // RDI
67         Uint    Arg2;   // RSI
68         Uint    Arg3;   // RDX
69         Uint    Arg4;   // RCX
70         Uint    Arg5;   // R8
71         Uint    Arg6;   // R9
72         Uint    _Flags;
73         Uint    _IP;
74         Uint    StackPointer;   // RSP
75         
76 }       tSyscallRegs;
77
78 /**
79  * \brief Short Spinlock structure
80  */
81 struct sShortSpinlock {
82         #if STACKED_LOCKS == 2
83         volatile void   *Lock;  //!< Lock value
84         #else
85         volatile int    Lock;   //!< Lock value
86         #endif
87         
88         #if LOCK_DISABLE_INTS
89          int    IF;     //!< Interrupt state on call to SHORTLOCK
90         #endif
91         #if STACKED_LOCKS
92          int    Depth;
93         #endif
94 };
95
96 // === FUNCTIONS ===
97 extern int      IS_LOCKED(struct sShortSpinlock *Lock);
98 extern int      CPU_HAS_LOCK(struct sShortSpinlock *Lock);
99 extern void     SHORTLOCK(struct sShortSpinlock *Lock);
100 extern void     SHORTREL(struct sShortSpinlock *Lock);
101
102 extern void     Debug_PutCharDebug(char ch);
103 extern void     Debug_PutStringDebug(const char *Str);
104
105 // TODO: Move this to acess.h
106 extern tPAddr   MM_AllocateZero(tVAddr VAddr);
107
108 #endif
109

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