chore: Update makefiles & macros

This commit is contained in:
EnderIce2
2024-11-29 04:24:27 +02:00
parent ce3cf8162a
commit 7948d0c6e5
116 changed files with 682 additions and 740 deletions

View File

@ -24,11 +24,11 @@
#include "../kernel.h"
#if defined(a64)
#if defined(__amd64__)
using namespace CPU::x64;
#elif defined(a32)
#elif defined(__i386__)
using namespace CPU::x32;
#elif defined(aa64)
#elif defined(__aarch64__)
#endif
namespace CPU
@ -40,19 +40,19 @@ namespace CPU
static char Vendor[13] = {0};
if (Vendor[0] != 0)
return Vendor;
#if defined(a64)
#if defined(__amd64__)
uint32_t eax, ebx, ecx, edx;
x64::cpuid(0x0, &eax, &ebx, &ecx, &edx);
memcpy(Vendor + 0, &ebx, 4);
memcpy(Vendor + 4, &edx, 4);
memcpy(Vendor + 8, &ecx, 4);
#elif defined(a32)
#elif defined(__i386__)
uint32_t eax, ebx, ecx, edx;
x32::cpuid(0x0, &eax, &ebx, &ecx, &edx);
memcpy(Vendor + 0, &ebx, 4);
memcpy(Vendor + 4, &edx, 4);
memcpy(Vendor + 8, &ecx, 4);
#elif defined(aa64)
#elif defined(__aarch64__)
#error "Not implemented"
#endif
return Vendor;
@ -63,7 +63,7 @@ namespace CPU
static char Name[49] = {0};
if (Name[0] != 0)
return Name;
#if defined(a64)
#if defined(__amd64__)
uint32_t eax, ebx, ecx, edx;
x64::cpuid(0x80000002, &eax, &ebx, &ecx, &edx);
memcpy(Name + 0, &eax, 4);
@ -80,7 +80,7 @@ namespace CPU
memcpy(Name + 36, &ebx, 4);
memcpy(Name + 40, &ecx, 4);
memcpy(Name + 44, &edx, 4);
#elif defined(a32)
#elif defined(__i386__)
uint32_t eax, ebx, ecx, edx;
x32::cpuid(0x80000002, &eax, &ebx, &ecx, &edx);
memcpy(Name + 0, &eax, 4);
@ -97,7 +97,7 @@ namespace CPU
memcpy(Name + 36, &ebx, 4);
memcpy(Name + 40, &ecx, 4);
memcpy(Name + 44, &edx, 4);
#elif defined(aa64)
#elif defined(__aarch64__)
#error "Not implemented"
#endif
return Name;
@ -108,7 +108,7 @@ namespace CPU
static char Hypervisor[13] = {0};
if (Hypervisor[0] != 0)
return Hypervisor;
#if defined(a64)
#if defined(__amd64__)
uint32_t eax, ebx, ecx, edx;
x64::cpuid(0x1, &eax, &ebx, &ecx, &edx);
if (!(ecx & (1 << 31))) /* Intel & AMD are the same */
@ -124,7 +124,7 @@ namespace CPU
memcpy(Hypervisor + 0, &ebx, 4);
memcpy(Hypervisor + 4, &ecx, 4);
memcpy(Hypervisor + 8, &edx, 4);
#elif defined(a32)
#elif defined(__i386__)
uint32_t eax, ebx, ecx, edx;
x32::cpuid(0x1, &eax, &ebx, &ecx, &edx);
if (!(ecx & (1 << 31))) /* Intel & AMD are the same */
@ -140,7 +140,7 @@ namespace CPU
memcpy(Hypervisor + 0, &ebx, 4);
memcpy(Hypervisor + 4, &ecx, 4);
memcpy(Hypervisor + 8, &edx, 4);
#elif defined(aa64)
#elif defined(__aarch64__)
#error "Not implemented"
#endif
return Hypervisor;
@ -153,17 +153,17 @@ namespace CPU
case Check:
{
uintptr_t Flags;
#if defined(a64)
#if defined(__amd64__)
asmv("pushfq");
asmv("popq %0"
: "=r"(Flags));
return Flags & (1 << 9);
#elif defined(a32)
#elif defined(__i386__)
asmv("pushfl");
asmv("popl %0"
: "=r"(Flags));
return Flags & (1 << 9);
#elif defined(aa64)
#elif defined(__aarch64__)
asmv("mrs %0, cpsr"
: "=r"(Flags));
return Flags & (1 << 7);
@ -171,18 +171,18 @@ namespace CPU
}
case Enable:
{
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
asmv("sti");
#elif defined(aa64)
#elif defined(__aarch64__)
asmv("cpsie i");
#endif
return true;
}
case Disable:
{
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
asmv("cli");
#elif defined(aa64)
#elif defined(__aarch64__)
asmv("cpsid i");
#endif
return true;
@ -197,7 +197,7 @@ namespace CPU
void *PageTable(void *PT)
{
void *ret;
#if defined(a64)
#if defined(__amd64__)
asmv("movq %%cr3, %0"
: "=r"(ret));
@ -208,7 +208,7 @@ namespace CPU
: "r"(PT)
: "memory");
}
#elif defined(a32)
#elif defined(__i386__)
asmv("movl %%cr3, %0"
: "=r"(ret));
@ -219,7 +219,7 @@ namespace CPU
: "r"(PT)
: "memory");
}
#elif defined(aa64)
#elif defined(__aarch64__)
asmv("mrs %0, ttbr0_el1"
: "=r"(ret));
@ -392,13 +392,13 @@ namespace CPU
{
// TODO: Get the counter from the x2APIC or any other timer that is available. (TSC is not available on all CPUs)
uint64_t Counter;
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
uint32_t eax, edx;
asmv("rdtsc"
: "=a"(eax),
"=d"(edx));
Counter = ((uint64_t)eax) | (((uint64_t)edx) << 32);
#elif defined(aa64)
#elif defined(__aarch64__)
asmv("mrs %0, cntvct_el0"
: "=r"(Counter));
#endif
@ -413,7 +413,7 @@ namespace CPU
#warning "TODO: Proper SIMD support"
return SIMD_NONE;
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
static uint64_t SIMDType = SIMD_NONE;
if (likely(SIMDType != SIMD_NONE))
@ -495,7 +495,7 @@ namespace CPU
}
debug("No SIMD support.");
#endif // a64 || a32
#endif // __amd64__ || __i386__
return SIMD_NONE;
}
@ -504,7 +504,7 @@ namespace CPU
if (unlikely(!SSEEnabled))
return false;
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
if (strcmp(CPU::Vendor(), x86_CPUID_VENDOR_AMD) == 0)
{
CPU::x86::AMD::CPUID0x00000001 cpuid;
@ -545,7 +545,7 @@ namespace CPU
else if (Type == SIMD_SSE)
return cpuid.EDX.SSE;
}
#endif // a64 || a32
#endif // __amd64__ || __i386__
return false;
}
}

View File

@ -22,9 +22,9 @@
#include <smp.hpp>
#include <io.h>
#if defined(a64)
#if defined(__amd64__)
#include "../arch/amd64/cpu/apic.hpp"
#elif defined(a32)
#elif defined(__i386__)
#include "../arch/i386/cpu/apic.hpp"
#endif
#include "../kernel.h"

View File

@ -23,15 +23,15 @@
#include <vector>
#include <io.h>
#if defined(a64)
#if defined(__amd64__)
#include "../arch/amd64/cpu/apic.hpp"
#include "../arch/amd64/cpu/gdt.hpp"
#include "../arch/amd64/cpu/idt.hpp"
#elif defined(a32)
#elif defined(__i386__)
#include "../arch/i386/cpu/apic.hpp"
#include "../arch/i386/cpu/gdt.hpp"
#include "../arch/i386/cpu/idt.hpp"
#elif defined(aa64)
#elif defined(__aarch64__)
#endif
#include "../kernel.h"
@ -106,15 +106,15 @@ namespace Interrupts
std::atomic_uint SortEvents = SORT_START / SORT_DIVIDER;
constexpr uint32_t SORT_ITR = (SORT_START * 100) / SORT_DIVIDER;
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
/* APIC::APIC */ void *apic[MAX_CPU] = {nullptr};
/* APIC::Timer */ void *apicTimer[MAX_CPU] = {nullptr};
#elif defined(aa64)
#elif defined(__aarch64__)
#endif
void Initialize(int Core)
{
#if defined(a64)
#if defined(__amd64__)
GlobalDescriptorTable::Init(Core);
InterruptDescriptorTable::Init(Core);
CPUData *CoreData = GetCPU(Core);
@ -133,7 +133,7 @@ namespace Interrupts
debug("Stack for core %d is %#lx (Address: %#lx)",
Core, CoreData->Stack, CoreData->Stack - STACK_SIZE);
InitializeSystemCalls();
#elif defined(a32)
#elif defined(__i386__)
GlobalDescriptorTable::Init(Core);
InterruptDescriptorTable::Init(Core);
CPUData *CoreData = GetCPU(Core);
@ -151,14 +151,14 @@ namespace Interrupts
}
debug("Stack for core %d is %#lx (Address: %#lx)",
Core, CoreData->Stack, CoreData->Stack - STACK_SIZE);
#elif defined(aa64)
#elif defined(__aarch64__)
warn("aarch64 is not supported yet");
#endif
}
void Enable(int Core)
{
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
if (((ACPI::MADT *)PowerManager->GetMADT())->LAPICAddress != nullptr)
{
// TODO: This function is called by SMP too. Do not initialize timers that doesn't support multiple cores.
@ -171,7 +171,7 @@ namespace Interrupts
error("LAPIC not found");
// TODO: PIC
}
#elif defined(aa64)
#elif defined(__aarch64__)
warn("aarch64 is not supported yet");
#endif
CPU::Interrupts(CPU::Enable);
@ -180,14 +180,14 @@ namespace Interrupts
void InitializeTimer(int Core)
{
// TODO: This function is called by SMP too. Do not initialize timers that doesn't support multiple cores.
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
if (apic[Core] != nullptr)
apicTimer[Core] = new APIC::Timer((APIC::APIC *)apic[Core]);
else
{
fixme("apic not found");
}
#elif defined(aa64)
#elif defined(__aarch64__)
warn("aarch64 is not supported yet");
#endif
}
@ -333,12 +333,12 @@ namespace Interrupts
public:
AutoSwitchPageTable()
{
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
asmv("mov %%cr3, %0" : "=r"(Original));
#endif
if (likely(Original == KernelPageTable))
return;
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
asmv("mov %0, %%cr3" : : "r"(KernelPageTable));
#endif
}
@ -347,7 +347,7 @@ namespace Interrupts
{
if (likely(Original == KernelPageTable))
return;
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
asmv("mov %0, %%cr3" : : "r"(Original));
#endif
}
@ -365,7 +365,7 @@ namespace Interrupts
while (it != RegisteredEvents.end())
{
int iEvNum = it->IRQ;
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
iEvNum += CPU::x86::IRQ0;
#endif
if (iEvNum == s_cst(int, Frame->InterruptNumber))
@ -402,7 +402,7 @@ namespace Interrupts
{
KernelPageTable->Update();
CPU::SchedulerFrame *Frame = (CPU::SchedulerFrame *)Data;
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
assert(Frame->InterruptNumber == CPU::x86::IRQ16);
#else
assert(Frame->InterruptNumber == 16);

View File

@ -75,7 +75,7 @@ namespace Memory
}
}
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
if (bInfo.RSDP)
{
RSDPStart = (uintptr_t)bInfo.RSDP;
@ -101,7 +101,7 @@ namespace Memory
}
#endif
}
#elif defined(aa64)
#elif defined(__aarch64__)
#endif
for (uint64_t i = 0; i < bInfo.Memory.Entries; i++)

View File

@ -121,7 +121,7 @@ namespace Xalloc
{
if (this->SMAPUsed)
{
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
asm volatile("stac" ::
: "cc");
#endif
@ -132,7 +132,7 @@ namespace Xalloc
{
if (this->SMAPUsed)
{
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
asm volatile("clac" ::
: "cc");
#endif

View File

@ -56,7 +56,7 @@ NIF void tracepagetable(PageTable *pt)
{
for (int i = 0; i < 512; i++)
{
#if defined(a64)
#if defined(__amd64__)
if (pt->Entries[i].Present)
debug("Entry %03d: %x %x %x %x %x %x %x %p-%#llx", i,
pt->Entries[i].Present, pt->Entries[i].ReadWrite,
@ -64,8 +64,8 @@ NIF void tracepagetable(PageTable *pt)
pt->Entries[i].CacheDisable, pt->Entries[i].Accessed,
pt->Entries[i].ExecuteDisable, pt->Entries[i].Address << 12,
pt->Entries[i]);
#elif defined(a32)
#elif defined(aa64)
#elif defined(__i386__)
#elif defined(__aarch64__)
#endif
}
}
@ -257,15 +257,15 @@ NIF void CreatePageTable(PageTable *pt)
if (PSESupport)
{
#if defined(a64)
#if defined(__amd64__)
CPU::x64::CR4 cr4 = CPU::x64::readcr4();
cr4.PSE = 1;
CPU::x64::writecr4(cr4);
#elif defined(a32)
#elif defined(__i386__)
CPU::x32::CR4 cr4 = CPU::x32::readcr4();
cr4.PSE = 1;
CPU::x32::writecr4(cr4);
#elif defined(aa64)
#elif defined(__aarch64__)
#endif
trace("PSE Support Enabled");
}
@ -289,7 +289,7 @@ NIF void CreatePageTable(PageTable *pt)
NIF void InitializeMemoryManagement()
{
#ifdef DEBUG
#ifndef a32
#ifndef __i386__
for (uint64_t i = 0; i < bInfo.Memory.Entries; i++)
{
uintptr_t Base = r_cst(uintptr_t, bInfo.Memory.Entry[i].BaseAddress);
@ -333,7 +333,7 @@ NIF void InitializeMemoryManagement()
End,
Type);
}
#endif // a32
#endif // __i386__
#endif // DEBUG
trace("Initializing Physical Memory Manager");
// KernelAllocator = Physical(); <- Already called in the constructor

View File

@ -9,9 +9,9 @@ namespace Memory
{
void PageTable::Update()
{
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
asmv("mov %0, %%cr3" ::"r"(this));
#elif defined(aa64)
#elif defined(__aarch64__)
asmv("msr ttbr0_el1, %0" ::"r"(this));
#endif
}
@ -24,7 +24,7 @@ namespace Memory
memcpy(NewTable, this, sizeof(PageTable));
debug("Forking page table %#lx to %#lx", this, NewTable);
#if defined(a64)
#if defined(__amd64__)
for (size_t i = 0; i < sizeof(Entries) / sizeof(Entries[0]); i++)
{
PageMapLevel4 *PML4 = &Entries[i];

View File

@ -22,7 +22,7 @@ namespace Memory
Virtual::PageMapIndexer::PageMapIndexer(uintptr_t VirtualAddress)
{
uintptr_t Address = VirtualAddress;
#if defined(a64)
#if defined(__amd64__)
Address >>= 12;
this->PTEIndex = Address & 0x1FF;
Address >>= 9;
@ -31,12 +31,12 @@ namespace Memory
this->PDPTEIndex = Address & 0x1FF;
Address >>= 9;
this->PMLIndex = Address & 0x1FF;
#elif defined(a32)
#elif defined(__i386__)
Address >>= 12;
this->PTEIndex = Address & 0x3FF;
Address >>= 10;
this->PDEIndex = Address & 0x3FF;
#elif defined(aa64)
#elif defined(__aarch64__)
#endif
if (VirtualAddress > PAGE_SIZE)
@ -44,7 +44,7 @@ namespace Memory
assert(
this->PTEIndex != 0 ||
this->PDEIndex != 0
#if defined(a64)
#if defined(__amd64__)
|| this->PDPTEIndex != 0 ||
this->PMLIndex != 0
#endif

View File

@ -90,10 +90,10 @@ namespace Memory
Elf_Sym *Symbols = nullptr;
uint8_t *StringAddress = nullptr;
#if defined(a64) || defined(aa64)
#if defined(__amd64__) || defined(__aarch64__)
Elf64_Xword SymbolSize = 0;
Elf64_Xword StringSize = 0;
#elif defined(a32)
#elif defined(__i386__)
Elf32_Word SymbolSize = 0;
Elf32_Word StringSize = 0;
#endif
@ -149,7 +149,7 @@ namespace Memory
TO_PAGES(bInfo.Modules[i].Size));
}
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
if (bInfo.RSDP)
{
debug("Reserving RSDT region %#lx-%#lx...", bInfo.RSDP,
@ -201,7 +201,7 @@ namespace Memory
this->ReservePages(SDTHdr, TO_PAGES(SDTHdr->Length));
}
}
#elif defined(aa64)
#elif defined(__aarch64__)
#endif
}
}

View File

@ -241,9 +241,9 @@ namespace Memory
pte->CopyOnWrite = false;
debug("PFA %#lx is CoW (pt %#lx, flags %#lx)",
PFA, this->Table, pte->raw);
#if defined(a64)
#if defined(__amd64__)
CPU::x64::invlpg((void *)PFA);
#elif defined(a32)
#elif defined(__i386__)
CPU::x32::invlpg((void *)PFA);
#endif
return true;
@ -303,7 +303,7 @@ namespace Memory
void *AddressToMap = (void *)((uintptr_t)ap.Address + (i * PAGE_SIZE));
void *RealAddress = (void *)((uintptr_t)Address + (i * PAGE_SIZE));
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
PageTableEntry *pte = vmm.GetPTE(AddressToMap);
uintptr_t Flags = 0;
Flags |= pte->Present ? (uintptr_t)PTFlag::P : 0;

View File

@ -28,13 +28,13 @@
#include <cpu.hpp>
#include <io.h>
#if defined(a64)
#if defined(__amd64__)
#include "../../arch/amd64/cpu/gdt.hpp"
#include "../arch/amd64/cpu/apic.hpp"
#elif defined(a32)
#elif defined(__i386__)
#include "../../arch/i386/cpu/gdt.hpp"
#include "../arch/i386/cpu/apic.hpp"
#elif defined(aa64)
#elif defined(__aarch64__)
#endif
#include "../../kernel.h"

View File

@ -28,13 +28,13 @@
#include <cpu.hpp>
#include <io.h>
#if defined(a64)
#if defined(__amd64__)
#include "../../arch/amd64/cpu/gdt.hpp"
#include "../arch/amd64/cpu/apic.hpp"
#elif defined(a32)
#elif defined(__i386__)
#include "../../arch/i386/cpu/gdt.hpp"
#include "../arch/i386/cpu/apic.hpp"
#elif defined(aa64)
#elif defined(__aarch64__)
#endif
#include "../../kernel.h"
@ -100,7 +100,7 @@ nsa void HaltAllCores()
if (SMP::CPUCores <= 1)
return;
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
if (Interrupts::apic[0] == nullptr)
return;
@ -131,7 +131,7 @@ nsa void HaltAllCores()
((APIC::APIC *)Interrupts::apic[i])->ICR(icr);
}
}
#elif defined(aa64)
#elif defined(__aarch64__)
#endif
}
@ -187,7 +187,7 @@ nsa __noreturn void HandleUnrecoverableException(CPU::ExceptionFrame *Frame)
ExPrint("\x1b[0m-----------------------------------------------\n");
ExPrint("\x1b[30;41mUnrecoverable exception %#lx on CPU %d\n",
Frame->InterruptNumber, core->ID);
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
ExPrint("CR0=%#lx CR2=%#lx CR3=%#lx CR4=%#lx CR8=%#lx\n",
Frame->cr0, Frame->cr2, Frame->cr3, Frame->cr4, Frame->cr8);
ExPrint("DR0=%#lx DR1=%#lx DR2=%#lx DR3=%#lx DR6=%#lx DR7=%#lx\n",
@ -195,29 +195,29 @@ nsa __noreturn void HandleUnrecoverableException(CPU::ExceptionFrame *Frame)
ExPrint("GS=%#lx FS=%#lx ES=%#lx DS=%#lx SS=%#lx CS=%#lx\n",
Frame->gs, Frame->fs, Frame->es, Frame->ds, Frame->ss, Frame->cs);
#endif
#if defined(a64)
#if defined(__amd64__)
ExPrint("R8=%#lx R9=%#lx R10=%#lx R11=%#lx R12=%#lx R13=%#lx R14=%#lx R15=%#lx\n",
Frame->r8, Frame->r9, Frame->r10, Frame->r11, Frame->r12, Frame->r13,
Frame->r14, Frame->r15);
#endif
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
ExPrint("AX=%#lx BX=%#lx CX=%#lx DX=%#lx SI=%#lx DI=%#lx BP=%#lx SP=%#lx\n",
#ifdef a64
#ifdef __amd64__
Frame->rax, Frame->rbx, Frame->rcx, Frame->rdx, Frame->rsi, Frame->rdi,
Frame->rbp, Frame->rsp);
#else
Frame->eax, Frame->ebx, Frame->ecx, Frame->edx, Frame->esi, Frame->edi,
Frame->ebp, Frame->esp);
#endif /* a64 */
#endif /* __amd64__ */
ExPrint("IP=%#lx FL=%#lx INT=%#lx ERR=%#lx\n",
#ifdef a64
#ifdef __amd64__
Frame->rip, Frame->rflags.raw,
#else
Frame->eip, Frame->eflags.raw,
#endif /* a64 */
#endif /* __amd64__ */
Frame->InterruptNumber, Frame->ErrorCode);
#endif /* a86 */
@ -233,14 +233,14 @@ nsa __noreturn void HandleExceptionInsideException(CPU::ExceptionFrame *Frame)
ExPrint("\x1b[0m-----------------------------------------------\n");
ExPrint("Exception inside exception: %#lx at %#lx\n",
Frame->InterruptNumber,
#if defined(a64)
#if defined(__amd64__)
Frame->rip);
#elif defined(a32)
#elif defined(__i386__)
Frame->eip);
#elif defined(aa64)
#elif defined(__aarch64__)
Frame->pc);
#endif
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
ExPrint("CR0=%#lx CR2=%#lx CR3=%#lx CR4=%#lx CR8=%#lx\n",
Frame->cr0, Frame->cr2, Frame->cr3, Frame->cr4, Frame->cr8);
ExPrint("DR0=%#lx DR1=%#lx DR2=%#lx DR3=%#lx DR6=%#lx DR7=%#lx\n",
@ -248,29 +248,29 @@ nsa __noreturn void HandleExceptionInsideException(CPU::ExceptionFrame *Frame)
ExPrint("GS=%#lx FS=%#lx ES=%#lx DS=%#lx SS=%#lx CS=%#lx\n",
Frame->gs, Frame->fs, Frame->es, Frame->ds, Frame->ss, Frame->cs);
#endif
#if defined(a64)
#if defined(__amd64__)
ExPrint("R8=%#lx R9=%#lx R10=%#lx R11=%#lx R12=%#lx R13=%#lx R14=%#lx R15=%#lx\n",
Frame->r8, Frame->r9, Frame->r10, Frame->r11, Frame->r12, Frame->r13,
Frame->r14, Frame->r15);
#endif
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
ExPrint("AX=%#lx BX=%#lx CX=%#lx DX=%#lx SI=%#lx DI=%#lx BP=%#lx SP=%#lx\n",
#ifdef a64
#ifdef __amd64__
Frame->rax, Frame->rbx, Frame->rcx, Frame->rdx, Frame->rsi, Frame->rdi,
Frame->rbp, Frame->rsp);
#else
Frame->eax, Frame->ebx, Frame->ecx, Frame->edx, Frame->esi, Frame->edi,
Frame->ebp, Frame->esp);
#endif /* a64 */
#endif /* __amd64__ */
ExPrint("IP=%#lx FL=%#lx INT=%#lx ERR=%#lx\n",
#ifdef a64
#ifdef __amd64__
Frame->rip, Frame->rflags.raw,
#else
Frame->eip, Frame->eflags.raw,
#endif /* a64 */
#endif /* __amd64__ */
Frame->InterruptNumber, Frame->ErrorCode);
#endif /* a86 */
Display->UpdateBuffer();

View File

@ -27,10 +27,10 @@
#include <cpu.hpp>
#include <io.h>
#if defined(a64)
#if defined(__amd64__)
#include "../../../arch/amd64/cpu/gdt.hpp"
#elif defined(a32)
#elif defined(aa64)
#elif defined(__i386__)
#elif defined(__aarch64__)
#endif
#include "../../../kernel.h"

View File

@ -31,10 +31,10 @@
#include <cpu.hpp>
#include <io.h>
#if defined(a64)
#if defined(__amd64__)
#include "../../../arch/amd64/cpu/gdt.hpp"
#elif defined(a32)
#elif defined(aa64)
#elif defined(__i386__)
#elif defined(__aarch64__)
#endif
#include "../../../kernel.h"

View File

@ -28,10 +28,10 @@
#include <cpu.hpp>
#include <io.h>
#if defined(a64)
#if defined(__amd64__)
#include "../../../arch/amd64/cpu/gdt.hpp"
#elif defined(a32)
#elif defined(aa64)
#elif defined(__i386__)
#elif defined(__aarch64__)
#endif
#include "../../../kernel.h"
@ -107,7 +107,7 @@ nsa static inline int GetLetterFromScanCode(uint8_t ScanCode)
nsa void CrashPS2KeyboardDriver::PS2Wait(bool Output)
{
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
TimeoutCallNumber++;
int timeout = 100000;
PS2_STATUSES status = {.Raw = inb(PS2_STATUS)};
@ -153,7 +153,7 @@ nsa CrashPS2KeyboardDriver::CrashPS2KeyboardDriver() : Interrupts::Handler(1) /*
/* Dots will be printed at the bottom of the screen as a progress bar. */
ExPrint("\x1b[%d;%dH", (Display->GetWidth / CrashFontRenderer.CurrentFont->GetInfo().Width) - 2, 0);
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
/* Disable port 1 & 2 */
{
@ -355,14 +355,14 @@ nsa CrashPS2KeyboardDriver::CrashPS2KeyboardDriver() : Interrupts::Handler(1) /*
ExPrint(".");
#endif // defined(a86)
#endif // defined(__amd64__) || defined(__i386__)
CPU::Interrupts(CPU::Enable);
}
nsa void CrashPS2KeyboardDriver::OnInterruptReceived(CPU::TrapFrame *)
{
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
uint8_t scanCode = inb(PS2_DATA);
if (scanCode == KEY_D_TAB ||
@ -412,5 +412,5 @@ nsa void CrashPS2KeyboardDriver::OnInterruptReceived(CPU::TrapFrame *)
}
Display->UpdateBuffer(); /* Update as we type. */
}
#endif // a64 || a32
#endif // __amd64__ || __i386__
}

View File

@ -27,10 +27,10 @@
#include <cpu.hpp>
#include <io.h>
#if defined(a64)
#if defined(__amd64__)
#include "../../../arch/amd64/cpu/gdt.hpp"
#elif defined(a32)
#elif defined(aa64)
#elif defined(__i386__)
#elif defined(__aarch64__)
#endif
#include "../../../kernel.h"

View File

@ -27,10 +27,10 @@
#include <cpu.hpp>
#include <io.h>
#if defined(a64)
#if defined(__amd64__)
#include "../../../arch/amd64/cpu/gdt.hpp"
#elif defined(a32)
#elif defined(aa64)
#elif defined(__i386__)
#elif defined(__aarch64__)
#endif
#include "../../../kernel.h"

View File

@ -27,13 +27,13 @@
#include <cpu.hpp>
#include <io.h>
#if defined(a64)
#if defined(__amd64__)
#include "../../arch/amd64/cpu/gdt.hpp"
#include "../arch/amd64/cpu/apic.hpp"
#elif defined(a32)
#elif defined(__i386__)
#include "../../arch/i386/cpu/gdt.hpp"
#include "../arch/i386/cpu/apic.hpp"
#elif defined(aa64)
#elif defined(__aarch64__)
#endif
#include "../../kernel.h"
@ -143,11 +143,11 @@ nsa const char *ExGetKSymbol(CPU::ExceptionFrame *Frame)
Frame->rip > (uintptr_t)&_kernel_end)
return "<OUTSIDE KERNEL>";
#if defined(a64)
#if defined(__amd64__)
return ExGetKSymbolByAddress(Frame->rip);
#elif defined(a32)
#elif defined(__i386__)
return ExGetKSymbolByAddress(Frame->eip);
#elif defined(aa64)
#elif defined(__aarch64__)
return ExGetKSymbolByAddress(Frame->pc);
#endif
}
@ -299,23 +299,23 @@ nsa void DisplayMainScreen(CPU::ExceptionFrame *Frame)
ExPrint("\nWe're sorry, but the system has encountered a critical error and needs to restart.\n");
ExPrint("\nError: %s (%s 0x%x)\n",
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
x86Exceptions[Frame->InterruptNumber].Name,
x86Exceptions[Frame->InterruptNumber].Mnemonic,
#elif defined(aa64)
#elif defined(__aarch64__)
#error "AA64 not implemented"
#endif
Frame->InterruptNumber);
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
ExPrint("Cause: %s\n", x86Exceptions[Frame->InterruptNumber].Cause);
#endif
ExPrint("Exception occurred in function %s (%#lx)\n",
ExGetKSymbol(Frame),
#if defined(a64)
#if defined(__amd64__)
Frame->rip);
#elif defined(a32)
#elif defined(__i386__)
Frame->eip);
#elif defined(aa64)
#elif defined(__aarch64__)
Frame->pc);
#endif
@ -431,9 +431,9 @@ nsa void DisplayStackScreen(CPU::ExceptionFrame *Frame)
{
Memory::Virtual vmm;
struct StackFrame *sf;
#if defined(a64)
#if defined(__amd64__)
sf = (struct StackFrame *)Frame->rbp;
#elif defined(a32)
#elif defined(__i386__)
sf = (struct StackFrame *)Frame->ebp;
#endif
@ -455,11 +455,11 @@ nsa void DisplayStackScreen(CPU::ExceptionFrame *Frame)
/* FIXME: Get symbol offset more efficiently */
uintptr_t fIP;
#if defined(a64)
#if defined(__amd64__)
fIP = Frame->rip;
#elif defined(a32)
#elif defined(__i386__)
fIP = Frame->eip;
#elif defined(aa64)
#elif defined(__aarch64__)
fIP = Frame->pc;
#endif

View File

@ -21,10 +21,10 @@
#include <smp.hpp>
#include <cpu.hpp>
#if defined(a64)
#if defined(__amd64__)
#include "../../arch/amd64/cpu/gdt.hpp"
#elif defined(a32)
#elif defined(aa64)
#elif defined(__i386__)
#elif defined(__aarch64__)
#endif
#include "../../kernel.h"
@ -32,26 +32,26 @@
#ifdef DEBUG
nsa void dbgPrint(CPU::ExceptionFrame *Frame)
{
#if defined(a64)
#if defined(__amd64__)
debug("FS=%#lx GS=%#lx SS=%#lx CS=%#lx DS=%#lx", Frame->fs, Frame->gs, Frame->ss, Frame->cs, Frame->ds);
debug("R8=%#lx R9=%#lx R10=%#lx R11=%#lx", Frame->r8, Frame->r9, Frame->r10, Frame->r11);
debug("R12=%#lx R13=%#lx R14=%#lx R15=%#lx", Frame->r12, Frame->r13, Frame->r14, Frame->r15);
debug("RAX=%#lx RBX=%#lx RCX=%#lx RDX=%#lx", Frame->rax, Frame->rbx, Frame->rcx, Frame->rdx);
debug("RSI=%#lx RDI=%#lx RBP=%#lx RSP=%#lx", Frame->rsi, Frame->rdi, Frame->rbp, Frame->rsp);
debug("RIP=%#lx RFL=%#lx INT=%#lx ERR=%#lx", Frame->rip, Frame->rflags.raw, Frame->InterruptNumber, Frame->ErrorCode);
#elif defined(a32)
#elif defined(__i386__)
debug("FS=%#x GS=%#x CS=%#x DS=%#x", Frame->fs, Frame->gs, Frame->cs, Frame->ds);
debug("EAX=%#x EBX=%#x ECX=%#x EDX=%#x", Frame->eax, Frame->ebx, Frame->ecx, Frame->edx);
debug("ESI=%#x EDI=%#x EBP=%#x ESP=%#x", Frame->esi, Frame->edi, Frame->ebp, Frame->esp);
debug("EIP=%#x EFL=%#x INT=%#x ERR=%#x", Frame->eip, Frame->eflags.raw, Frame->InterruptNumber, Frame->ErrorCode);
#elif defined(aa64)
#elif defined(__aarch64__)
#endif
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
debug("CR2=%#lx CR3=%#lx", Frame->cr2, Frame->cr3);
#endif // defined(a86)
#endif // defined(__amd64__) || defined(__i386__)
#if defined(a64)
#if defined(__amd64__)
debug("RFL: CF:%s PF:%s AF:%s ZF:%s SF:%s TF:%s IF:%s DF:%s OF:%s IOPL:%s NT:%s RF:%s VM:%s AC:%s VIF:%s VIP:%s ID:%s AlwaysOne:%d R0:%#x R1:%#x R2:%#x R3:%#x",
Frame->rflags.CF ? "True " : "False", Frame->rflags.PF ? "True " : "False", Frame->rflags.AF ? "True " : "False", Frame->rflags.ZF ? "True " : "False",
Frame->rflags.SF ? "True " : "False", Frame->rflags.TF ? "True " : "False", Frame->rflags.IF ? "True " : "False", Frame->rflags.DF ? "True " : "False",
@ -59,7 +59,7 @@ nsa void dbgPrint(CPU::ExceptionFrame *Frame)
Frame->rflags.VM ? "True " : "False", Frame->rflags.AC ? "True " : "False", Frame->rflags.VIF ? "True " : "False", Frame->rflags.VIP ? "True " : "False",
Frame->rflags.ID ? "True " : "False", Frame->rflags.AlwaysOne,
Frame->rflags.Reserved0, Frame->rflags.Reserved1, Frame->rflags.Reserved2, Frame->rflags.Reserved3);
#elif defined(a32)
#elif defined(__i386__)
debug("EFL: CF:%s PF:%s AF:%s ZF:%s SF:%s TF:%s IF:%s DF:%s OF:%s IOPL:%s NT:%s RF:%s VM:%s AC:%s VIF:%s VIP:%s ID:%s AlwaysOne:%d R0:%#x R1:%#x R2:%#x",
Frame->eflags.CF ? "True " : "False", Frame->eflags.PF ? "True " : "False", Frame->eflags.AF ? "True " : "False", Frame->eflags.ZF ? "True " : "False",
Frame->eflags.SF ? "True " : "False", Frame->eflags.TF ? "True " : "False", Frame->eflags.IF ? "True " : "False", Frame->eflags.DF ? "True " : "False",
@ -67,7 +67,7 @@ nsa void dbgPrint(CPU::ExceptionFrame *Frame)
Frame->eflags.VM ? "True " : "False", Frame->eflags.AC ? "True " : "False", Frame->eflags.VIF ? "True " : "False", Frame->eflags.VIP ? "True " : "False",
Frame->eflags.ID ? "True " : "False", Frame->eflags.AlwaysOne,
Frame->eflags.Reserved0, Frame->eflags.Reserved1, Frame->eflags.Reserved2);
#elif defined(aa64)
#elif defined(__aarch64__)
#endif
}
#endif

View File

@ -1100,7 +1100,7 @@ namespace PCI
Manager::Manager()
{
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
if (!PowerManager->GetACPI())
{
error("ACPI not found");
@ -1127,7 +1127,7 @@ namespace PCI
for (uint32_t Bus = NewDeviceConfig->StartBus; Bus < NewDeviceConfig->EndBus; Bus++)
EnumerateBus(NewDeviceConfig->BaseAddress, Bus, dev);
}
#elif defined(aa64)
#elif defined(__aarch64__)
error("PCI not implemented on aarch64");
#endif
}

View File

@ -63,7 +63,7 @@ namespace Random
uint16_t rand16()
{
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
if (RDRANDFlag)
{
uint16_t RDRANDValue = 0;
@ -80,7 +80,7 @@ namespace Random
uint32_t rand32()
{
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
if (RDRANDFlag)
{
uint32_t RDRANDValue = 0;
@ -97,7 +97,7 @@ namespace Random
uint64_t rand64()
{
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
if (RDRANDFlag)
{
uintptr_t RDRANDValue = 0;

View File

@ -60,13 +60,13 @@ EXTERNC __noreturn __no_stack_protector void __stack_chk_fail(void)
CPU::PageTable(KernelPageTable);
void *Stack = nullptr;
#if defined(a64)
#if defined(__amd64__)
asmv("movq %%rsp, %0"
: "=r"(Stack));
#elif defined(a32)
#elif defined(__i386__)
asmv("movl %%esp, %0"
: "=r"(Stack));
#elif defined(aa64)
#elif defined(__aarch64__)
asmv("mov %%sp, %0"
: "=r"(Stack));
#endif

View File

@ -101,10 +101,10 @@ namespace SymbolResolver
Elf_Sym *Symbols = nullptr;
uint8_t *StringAddress = nullptr;
#if defined(a64) || defined(aa64)
#if defined(__amd64__) || defined(__aarch64__)
Elf64_Xword SymbolSize = 0;
// Elf64_Xword StringSize = 0;
#elif defined(a32)
#elif defined(__i386__)
Elf32_Word SymbolSize = 0;
// Elf32_Word StringSize = 0;
#endif
@ -218,9 +218,9 @@ namespace SymbolResolver
}
debug("Solving symbols for address: %#llx", ImageAddress);
#if defined(a64) || defined(aa64)
#if defined(__amd64__) || defined(__aarch64__)
Elf64_Ehdr *Header = (Elf64_Ehdr *)ImageAddress;
#elif defined(a32)
#elif defined(__i386__)
Elf32_Ehdr *Header = (Elf32_Ehdr *)ImageAddress;
#endif
if (Header->e_ident[0] != 0x7F &&

View File

@ -28,12 +28,12 @@ namespace Time
{
bool HighPrecisionEventTimer::Sleep(size_t Duration, Units Unit)
{
#if defined(a64)
#if defined(__amd64__)
uint64_t Target = mminq(&hpet->MainCounterValue) + (Duration * ConvertUnit(Unit)) / clk;
while (mminq(&hpet->MainCounterValue) < Target)
CPU::Pause();
return true;
#elif defined(a32)
#elif defined(__i386__)
uint64_t Target = mminl(&hpet->MainCounterValue) + (Duration * ConvertUnit(Unit)) / clk;
while (mminl(&hpet->MainCounterValue) < Target)
CPU::Pause();
@ -44,25 +44,25 @@ namespace Time
uint64_t HighPrecisionEventTimer::GetCounter()
{
#if defined(a64)
#if defined(__amd64__)
return mminq(&hpet->MainCounterValue);
#elif defined(a32)
#elif defined(__i386__)
return mminl(&hpet->MainCounterValue);
#endif
}
uint64_t HighPrecisionEventTimer::CalculateTarget(uint64_t Target, Units Unit)
{
#if defined(a64)
#if defined(__amd64__)
return mminq(&hpet->MainCounterValue) + (Target * ConvertUnit(Unit)) / clk;
#elif defined(a32)
#elif defined(__i386__)
return mminl(&hpet->MainCounterValue) + (Target * ConvertUnit(Unit)) / clk;
#endif
}
uint64_t HighPrecisionEventTimer::GetNanosecondsSinceClassCreation()
{
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
uint64_t Subtraction = this->GetCounter() - this->ClassCreationTime;
if (Subtraction <= 0 || this->clk <= 0)
return 0;
@ -74,7 +74,7 @@ namespace Time
HighPrecisionEventTimer::HighPrecisionEventTimer(void *hpet)
{
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
ACPI::ACPI::HPETHeader *HPET_HDR = (ACPI::ACPI::HPETHeader *)hpet;
Memory::Virtual vmm;
vmm.Map((void *)HPET_HDR->Address.Address,
@ -86,7 +86,7 @@ namespace Time
(void *)HPET_HDR->Address.Address);
clk = s_cst(uint32_t, (uint64_t)this->hpet->GeneralCapabilities >> 32);
KPrint("HPET clock is %u Hz", clk);
#ifdef a64
#ifdef __amd64__
mmoutq(&this->hpet->GeneralConfiguration, 0);
mmoutq(&this->hpet->MainCounterValue, 0);
mmoutq(&this->hpet->GeneralConfiguration, 1);

View File

@ -24,7 +24,7 @@ namespace Time
Clock ReadClock()
{
Clock tm;
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
uint32_t t = 0;
outb(0x70, 0x00);
t = inb(0x71);
@ -45,7 +45,7 @@ namespace Time
t = inb(0x71);
tm.Year = ((t & 0x0F) + ((t >> 4) * 10));
tm.Counter = 0;
#elif defined(aa64)
#elif defined(__aarch64__)
tm.Year = 0;
tm.Month = 0;
tm.Day = 0;

View File

@ -145,7 +145,7 @@ namespace Time
void time::FindTimers(void *acpi)
{
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
/* TODO: RTC check */
/* TODO: PIT check */

View File

@ -28,7 +28,7 @@ namespace Time
{
bool TimeStampCounter::Sleep(size_t Duration, Units Unit)
{
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
uint64_t Target = this->GetCounter() + (Duration * ConvertUnit(Unit)) / this->clk;
while (this->GetCounter() < Target)
CPU::Pause();
@ -38,28 +38,28 @@ namespace Time
uint64_t TimeStampCounter::GetCounter()
{
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
return CPU::Counter();
#endif
}
uint64_t TimeStampCounter::CalculateTarget(uint64_t Target, Units Unit)
{
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
return uint64_t((this->GetCounter() + (Target * ConvertUnit(Unit))) / this->clk);
#endif
}
uint64_t TimeStampCounter::GetNanosecondsSinceClassCreation()
{
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
return uint64_t((this->GetCounter() - this->ClassCreationTime) / this->clk);
#endif
}
TimeStampCounter::TimeStampCounter()
{
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
stub; // FIXME: This is not a good way to measure the clock speed
uint64_t Start = CPU::Counter();
TimeManager->Sleep(1, Units::Milliseconds);

View File

@ -23,7 +23,7 @@
bool serialports[8] = {false, false, false, false, false, false, false, false};
std::vector<UniversalAsynchronousReceiverTransmitter::Events *> RegisteredEvents;
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
NIF __always_inline inline uint8_t NoProfiler_inportb(uint16_t Port)
{
uint8_t Result;
@ -56,7 +56,7 @@ namespace UniversalAsynchronousReceiverTransmitter
nsa NIF UART::UART(SerialPorts Port)
{
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
if (Port == COMNULL)
return;
@ -138,7 +138,7 @@ namespace UniversalAsynchronousReceiverTransmitter
{
if (!this->IsAvailable)
return;
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
while ((NoProfiler_inportb(s_cst(uint16_t, Port + 5)) & SERIAL_BUFFER_EMPTY) == 0)
;
NoProfiler_outportb(Port, Char);
@ -152,7 +152,7 @@ namespace UniversalAsynchronousReceiverTransmitter
{
if (!this->IsAvailable)
return 0;
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
while ((NoProfiler_inportb(s_cst(uint16_t, Port + 5)) & 1) == 0)
;
return NoProfiler_inportb(Port);
@ -161,7 +161,7 @@ namespace UniversalAsynchronousReceiverTransmitter
{
if (e->GetRegisteredPort() == Port || e->GetRegisteredPort() == COMNULL)
{
#if defined(a86)
#if defined(__amd64__) || defined(__i386__)
e->OnReceived(NoProfiler_inportb(Port));
#endif
}