X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;ds=sidebyside;f=Kernel%2Farch%2Fx86_64%2Finclude%2Farch.h;h=c2c622e56d3f66ab1cd1a8fd9ec3e472786c0e00;hb=9c61cf12758c0977ee1dc5791cba638fd3437ba6;hp=3993fe9c36258618d36eb59887732a4c1495f23e;hpb=f0b06cece87e5f73678413cbbc1e3100ddf6e247;p=tpg%2Facess2.git diff --git a/Kernel/arch/x86_64/include/arch.h b/Kernel/arch/x86_64/include/arch.h index 3993fe9c..c2c622e5 100644 --- a/Kernel/arch/x86_64/include/arch.h +++ b/Kernel/arch/x86_64/include/arch.h @@ -10,6 +10,11 @@ #define KERNEL_BASE 0xFFFFFFFF##80000000 #define BITS 64 +#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 @@ -42,7 +47,7 @@ typedef char BOOL; /** * \brief Halt the CPU */ -#define HALT() __asm__ __volatile__ ("hlt") +#define HALT() __asm__ __volatile__ ("sti;\n\thlt") /** * \brief Fire a magic breakpoint (bochs) */ @@ -76,53 +81,28 @@ typedef struct sSyscallRegs * \brief Short Spinlock structure */ struct sShortSpinlock { + #if STACKED_LOCKS == 2 + volatile void *Lock; //!< Lock value + #else volatile int Lock; //!< Lock value - int IF; //!< Interrupt state on call to SHORTLOCK -}; -/** - * \brief Determine if a short spinlock is locked - * \param Lock Lock pointer - */ -static inline int IS_LOCKED(struct sShortSpinlock *Lock) { - return !!Lock->Lock; -} -/** - * \brief Acquire a Short Spinlock - * \param Lock Lock pointer - * - * This type of mutex should only be used for very short sections of code, - * or in places where a Mutex_* would be overkill, such as appending - * an element to linked list (usually two assignement lines in C) - * - * \note This type of lock halts interrupts, so ensure that no timing - * functions are called while it is held. - */ -static inline void SHORTLOCK(struct sShortSpinlock *Lock) { - int v = 1; - - // Save interrupt state - __ASM__ ("pushf;\n\tpop %%rax" : "=a"(Lock->IF)); - Lock->IF &= 0x200; - - // Stop interrupts - __ASM__ ("cli"); + #endif - // Wait for another CPU to release - while(v) - __ASM__("xchgl %%eax, (%%rdi)":"=a"(v):"a"(1),"D"(&Lock->Lock)); -} -/** - * \brief Release a short lock - * \param Lock Lock pointer - */ -static inline void SHORTREL(struct sShortSpinlock *Lock) { - Lock->Lock = 0; - #if 0 // Which is faster?, meh the test is simpler - __ASM__ ("pushf;\n\tor %0, (%%rsp);\n\tpopf" : : "a"(Lock->IF)); - #else - if(Lock->IF) __ASM__ ("sti"); + #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); #endif