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

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