Fixed compilation failing on i386

This commit is contained in:
Alex 2022-10-28 09:06:09 +03:00
parent 3f0d496eb6
commit a245fb009c
Signed by untrusted user who does not match committer: enderice2
GPG Key ID: EACC3AD603BAB4DD
4 changed files with 94 additions and 3 deletions

View File

@ -0,0 +1,70 @@
# https://en.wikipedia.org/wiki/Spinlock
.text
# void SpinLock_Lock(volatile uint32_t *LockData)
.global SpinLock_Lock
# void SpinLock_Unlock(volatile uint32_t *LockData)
.global SpinLock_Unlock
# uint32_t SpinLock_CheckAndLock(volatile uint32_t *LockData)
.global SpinLock_CheckAndLock
# uint32_t SpinLock_WithTimeout(volatile uint32_t *LockData, volatile uint32_t Iterations)
.global SpinLock_WithTimeout
# DeadLockHandler(volatile <struct> *LockStructure)
.extern DeadLockHandler
SpinLock_Lock:
xor %eax,%eax
lock btsl $0,(%edi)
jc Spin
ret
Spin:
inc %eax
cmp $0x10000000,%eax
je Deadlock
pause
test $1,(%edi)
jnz Spin
jmp SpinLock_Lock
SpinLock_Unlock:
lock btrl $0,(%edi)
ret
Deadlock:
push %edi
push %edi
xor %eax,%eax
call DeadLockHandler
pop %edi
pop %edi
jmp Spin
SpinLock_CheckAndLock:
xor %eax,%eax
lock btsl $0,(%edi)
setc %al
ret
SpinLock_WithTimeout:
xor %eax,%eax
SpinTimeout:
inc %eax
lock btsl $0,(%edi)
setc %bl
cmp $0,%bl
je LockAquired
cmp %esi,%eax
je LockTimedOut
pause
jmp SpinTimeout
LockAquired:
mov $1,%eax
ret
LockTimedOut:
xor %eax,%eax
ret

View File

@ -577,9 +577,13 @@ namespace Tasking
Task::Task(const IP EntryPoint) : Interrupts::Handler(CPU::x64::IRQ16)
{
SmartCriticalSection(TaskingLock);
#if defined(__amd64__)
for (int i = 0; i < SMP::CPUCores; i++)
((APIC::APIC *)Interrupts::apic[i])->RedirectIRQ(i, CPU::x64::IRQ16 - CPU::x64::IRQ0, 1);
#elif defined(__i386__)
#elif defined(__aarch64__)
#endif
KPrint("Starting Tasking With Instruction Pointer: %p (\e666666%s\eCCCCCC)", EntryPoint, KernelSymbolTable->GetSymbolFromAddress(EntryPoint));
TaskingLock.Unlock();
@ -597,7 +601,7 @@ namespace Tasking
debug("Created Kernel Process: %s and Thread: %s", kproc->Name, kthrd->Name);
TaskingLock.Lock(__FUNCTION__);
#if defined(__amd64__) || defined(__i386__)
#if defined(__amd64__)
uint32_t rax, rbx, rcx, rdx;
CPU::x64::cpuid(0x1, &rax, &rbx, &rcx, &rdx);
if (rcx & CPU::x64::CPUID_FEAT_RCX_MONITOR)

View File

@ -252,6 +252,23 @@ namespace CPU
namespace x32
{
/**
* @brief CPUID
*
* @param Function Leaf
* @param eax EAX
* @param ebx EBX
* @param ecx ECX
* @param edx EDX
*/
static inline void cpuid(uint32_t Function, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx)
{
#if defined(__i386__)
asmv("cpuid"
: "=a"(*eax), "=b"(*ebx), "=c"(*ecx), "=d"(*edx)
: "a"(Function));
#endif
}
}
namespace x64

View File

@ -20,7 +20,7 @@ namespace Tasking
enum TaskArchitecture
{
UnknownArchitecture,
x86,
x32,
x64,
ARM,
ARM64