2 * Acess2 x86-64 Architecure Module
3 * - By John Hodge (thePowersGang)
9 //#define KERNEL_BASE 0xFFFF8000##00000000
10 #define KERNEL_BASE 0xFFFFFFFF##80000000
13 //#define INT_MAX 0x7FFFFFFF
14 //#define UINT_MAX 0xFFFFFFFF
17 typedef signed char Sint8;
18 typedef unsigned char Uint8;
19 typedef signed short Sint16;
20 typedef unsigned short Uint16;
21 typedef signed int Sint32;
22 typedef unsigned int Uint32;
24 typedef signed long int Sint64;
25 typedef unsigned long int Uint64;
27 typedef signed long long int Sint64;
28 typedef unsigned long long int Uint64;
33 typedef Uint64 tPAddr;
34 typedef Uint64 tVAddr;
36 typedef Uint64 size_t;
38 #define __ASM__ __asm__ __volatile__
44 #define HALT() __asm__ __volatile__ ("hlt")
46 * \brief Fire a magic breakpoint (bochs)
48 #define MAGIC_BREAK() __asm__ __volatile__ ("xchg %bx, %bx")
50 // Systemcall Registers
51 // TODO: Fix this structure
52 typedef struct sSyscallRegs
61 Uint Resvd1[2]; // Kernel RSP, RBP
66 Uint Resvd2[6]; // R10 - R15
67 Uint Resvd3[5]; // IntNum, ErrCode, RIP, CS, RFLAGS
69 Uint Resvd4[5]; // Int, Err, rip, CS, ...
70 Uint StackPointer; // RSP
75 * \brief Short Spinlock structure
77 struct sShortSpinlock {
78 volatile int Lock; //!< Lock value
79 int IF; //!< Interrupt state on call to SHORTLOCK
82 * \brief Determine if a short spinlock is locked
83 * \param Lock Lock pointer
85 static inline int IS_LOCKED(struct sShortSpinlock *Lock) {
89 * \brief Acquire a Short Spinlock
90 * \param Lock Lock pointer
92 * This type of mutex should only be used for very short sections of code,
93 * or in places where a Mutex_* would be overkill, such as appending
94 * an element to linked list (usually two assignement lines in C)
96 * \note This type of lock halts interrupts, so ensure that no timing
97 * functions are called while it is held.
99 static inline void SHORTLOCK(struct sShortSpinlock *Lock) {
102 // Save interrupt state
103 __ASM__ ("pushf;\n\tpop %%rax" : "=a"(Lock->IF));
109 // Wait for another CPU to release
111 __ASM__("xchgl %%eax, (%%rdi)":"=a"(v):"a"(1),"D"(&Lock->Lock));
114 * \brief Release a short lock
115 * \param Lock Lock pointer
117 static inline void SHORTREL(struct sShortSpinlock *Lock) {
119 #if 0 // Which is faster?, meh the test is simpler
120 __ASM__ ("pushf;\n\tor %0, (%%rsp);\n\tpopf" : : "a"(Lock->IF));
122 if(Lock->IF) __ASM__ ("sti");