X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Kernel%2Farch%2Fx86_64%2Finclude%2Farch.h;h=bde7abda96fc85cda76fd33ffceff6700d4927cb;hb=fad68a47fc99c28c0557c06631b95277c8ed9159;hp=d419234179fa8d7d2dfe40da1823e76606a1822a;hpb=f5f082502f5aeaa144a6ff60ad331e23957b0bbb;p=tpg%2Facess2.git diff --git a/Kernel/arch/x86_64/include/arch.h b/Kernel/arch/x86_64/include/arch.h index d4192341..bde7abda 100644 --- a/Kernel/arch/x86_64/include/arch.h +++ b/Kernel/arch/x86_64/include/arch.h @@ -6,9 +6,15 @@ #define _ARCH_H_ //#include -//#define KERNEL_BASE 0xFFFF8000##00000000 +#define USER_MAX 0x00007FFF##FFFFF000 #define KERNEL_BASE 0xFFFFFFFF##80000000 #define BITS 64 +#define PAGE_SIZE 0x1000 + +#define STACKED_LOCKS 2 // 0: No, 1: Per-CPU, 2: Per-Thread +#define LOCK_DISABLE_INTS 0 + +#define INVLPTR ((void*)0x0FFFFFFFFFFFFFFFULL) //#define INT_MAX 0x7FFFFFFF //#define UINT_MAX 0xFFFFFFFF @@ -34,18 +40,19 @@ typedef Uint64 tPAddr; typedef Uint64 tVAddr; typedef Uint64 size_t; +typedef char BOOL; + +#define __ASM__ __asm__ __volatile__ -typedef volatile int tSpinlock; -#define IS_LOCKED(lockptr) (!!(*(tSpinlock*)lockptr)) -#define _LOCK(lockptr,action) do {int v=1;\ - while(v)\ - __asm__ __volatile__("lock xchgl %0, (%2)":"=r"(v):"r"(1),"r"(lockptr));\ - if(v) action;\ - }while(0) -#define TIGHTLOCK(lockptr) _LOCK(lockptr, __asm__ __volatile__ ("hlt")); -#define LOCK(lockptr) _LOCK(lockptr, Threads_Yield()); -#define RELEASE(lockptr) __asm__ __volatile__("lock andl $0, (%0)"::"r"(lockptr)); -#define HALT() __asm__ __volatile__ ("hlt") +// === MACROS === +/** + * \brief Halt the CPU + */ +#define HALT() __asm__ __volatile__ ("sti;\n\thlt") +/** + * \brief Fire a magic breakpoint (bochs) + */ +#define MAGIC_BREAK() __asm__ __volatile__ ("xchg %bx, %bx") // Systemcall Registers // TODO: Fix this structure @@ -55,21 +62,48 @@ typedef struct sSyscallRegs Uint Num; Uint Return; }; // RAX - Uint Arg4; // RCX - Uint Arg3; // RDX Uint Error; // RBX - Uint Resvd1[2]; // Kernel RSP, RBP - Uint Arg2; // RSI Uint Arg1; // RDI + Uint Arg2; // RSI + Uint Arg3; // RDX + Uint Arg4; // RCX Uint Arg5; // R8 Uint Arg6; // R9 - Uint Resvd2[6]; // R10 - R15 - Uint Resvd3[5]; // IntNum, ErrCode, RIP, CS, RFLAGS - - Uint Resvd4[5]; // Int, Err, rip, CS, ... + Uint _Flags; + Uint _IP; Uint StackPointer; // RSP - Uint Resvd5[1]; // SS + } tSyscallRegs; +/** + * \brief Short Spinlock structure + */ +struct sShortSpinlock { + #if STACKED_LOCKS == 2 + volatile void *Lock; //!< Lock value + #else + volatile int Lock; //!< Lock value + #endif + + #if LOCK_DISABLE_INTS + int IF; //!< Interrupt state on call to SHORTLOCK + #endif + #if STACKED_LOCKS + int Depth; + #endif +}; + +// === FUNCTIONS === +extern int IS_LOCKED(struct sShortSpinlock *Lock); +extern int CPU_HAS_LOCK(struct sShortSpinlock *Lock); +extern void SHORTLOCK(struct sShortSpinlock *Lock); +extern void SHORTREL(struct sShortSpinlock *Lock); + +extern void Debug_PutCharDebug(char ch); +extern void Debug_PutStringDebug(const char *Str); + +// TODO: Move this to acess.h +extern tPAddr MM_AllocateZero(tVAddr VAddr); + #endif