diff options
Diffstat (limited to 'Private')
| -rw-r--r-- | Private/ArchKit/ArchKit.hpp | 5 | ||||
| -rw-r--r-- | Private/HALKit/AMD64/HalCoreInterruptHandler.cpp | 8 | ||||
| -rw-r--r-- | Private/HALKit/AMD64/HalCoreSyscallHandlerAMD64.cpp | 5 | ||||
| -rw-r--r-- | Private/HALKit/AMD64/HalInterruptRouting.asm | 37 | ||||
| -rw-r--r-- | Private/HALKit/AMD64/HalKernelMain.cxx (renamed from Private/Source/KernelMain.cxx) | 58 | ||||
| -rw-r--r-- | Private/HALKit/AMD64/HalNewBoot.asm | 27 | ||||
| -rw-r--r-- | Private/HALKit/AMD64/HalPlatformAMD64.cpp | 31 | ||||
| -rw-r--r-- | Private/HALKit/AMD64/HalRoutines.s | 12 | ||||
| -rw-r--r-- | Private/HALKit/AMD64/Processor.hpp | 4 | ||||
| -rw-r--r-- | Private/HALKit/AXP/CoreSyscallHandlerDEC.cpp | 14 | ||||
| -rw-r--r-- | Private/HALKit/PowerPC/HalCoreSyscallHandlerPowerPC.cpp | 5 | ||||
| -rw-r--r-- | Private/NewBoot/Source/makefile | 10 | ||||
| -rw-r--r-- | Private/makefile | 2 |
13 files changed, 146 insertions, 72 deletions
diff --git a/Private/ArchKit/ArchKit.hpp b/Private/ArchKit/ArchKit.hpp index 15f5a5e7..a96846f4 100644 --- a/Private/ArchKit/ArchKit.hpp +++ b/Private/ArchKit/ArchKit.hpp @@ -55,11 +55,10 @@ constexpr static inline SSizeT syscall_hash(const char *seed, int mul) { bool ke_init_hal(); } // namespace HCore -#define kMaxSyscalls (0xFFFF) -#define kSyscallGate 0x21 +#define kKernelMaxSystemCalls (0xFFF) extern HCore::Array<void (*)(HCore::Int32 id, HCore::HAL::StackFrame *), - kMaxSyscalls> + kKernelMaxSystemCalls> kSyscalls; EXTERN_C HCore::Void rt_wait_for_io(); diff --git a/Private/HALKit/AMD64/HalCoreInterruptHandler.cpp b/Private/HALKit/AMD64/HalCoreInterruptHandler.cpp index a668a0e4..1e46e5af 100644 --- a/Private/HALKit/AMD64/HalCoreInterruptHandler.cpp +++ b/Private/HALKit/AMD64/HalCoreInterruptHandler.cpp @@ -16,10 +16,14 @@ extern "C" HCore::UIntPtr rt_handle_interrupts(HCore::UIntPtr &rsp) { HCore::HAL::StackFramePtr sf = (HCore::HAL::StackFramePtr)rsp; - rt_syscall_handle(sf); + if (sf->IntNum == 0x21) { + rt_syscall_handle(sf); + } - HCore::kcout << "Krnl\\rt_handle_interrupts: Done\r\n"; + HCore::HAL::Out8(0x20, 0x20); + HCore::HAL::Out8(0xa0, 0x20); HCore::HAL::rt_sti(); + return rsp; } diff --git a/Private/HALKit/AMD64/HalCoreSyscallHandlerAMD64.cpp b/Private/HALKit/AMD64/HalCoreSyscallHandlerAMD64.cpp index 2e75b6cb..cacb66d8 100644 --- a/Private/HALKit/AMD64/HalCoreSyscallHandlerAMD64.cpp +++ b/Private/HALKit/AMD64/HalCoreSyscallHandlerAMD64.cpp @@ -11,12 +11,13 @@ #include <HALKit/AMD64/Processor.hpp> #include <KernelKit/PermissionSelector.hxx> -HCore::Array<void (*)(HCore::Int32 id, HCore::HAL::StackFrame *), kMaxSyscalls> +HCore::Array<void (*)(HCore::Int32 id, HCore::HAL::StackFrame *), + kKernelMaxSystemCalls> kSyscalls; /// @brief Interrupt system call handler. extern "C" void rt_syscall_handle(HCore::HAL::StackFrame *stack) { - for (HCore::SizeT index = 0UL; index < kMaxSyscalls; ++index) { + for (HCore::SizeT index = 0UL; index < kKernelMaxSystemCalls; ++index) { if (kSyscalls[index]) (kSyscalls[index].Leak().Leak())(stack->R15, stack); } } diff --git a/Private/HALKit/AMD64/HalInterruptRouting.asm b/Private/HALKit/AMD64/HalInterruptRouting.asm index 0f8ad89b..f50fb752 100644 --- a/Private/HALKit/AMD64/HalInterruptRouting.asm +++ b/Private/HALKit/AMD64/HalInterruptRouting.asm @@ -20,7 +20,6 @@ HCoreInterrupt%1: cli push %1 jmp ke_handle_irq - iretq %endmacro %macro IntNormal 1 @@ -29,7 +28,6 @@ HCoreInterrupt%1: push 0 push %1 jmp ke_handle_irq - iretq %endmacro ; This file handles the core interrupt table @@ -78,7 +76,7 @@ ke_handle_irq: pop rbx pop rax - retf + iretq section .data @@ -115,11 +113,7 @@ section .data IntExp 30 IntNormal 31 - %assign i 32 - %rep 224 - IntNormal i - %assign i i+1 - %endrep +section .data __EXEC_IVT: %assign i 0 @@ -128,25 +122,10 @@ __EXEC_IVT: %assign i i+1 %endrep -section .text - -[bits 64] - -extern rt_load_gdt - -global Main -extern RuntimeMain -extern MainLong - -;; Just a simple setup, we'd also need to tell some before -Main: - push rcx - jmp MainLong + %assign i 32 + %rep 224 + IntNormal i + %assign i i+1 + %endrep -MainLong: - jmp RuntimeMain - pop rcx -L0: - cli - hlt - jmp $ + ret diff --git a/Private/Source/KernelMain.cxx b/Private/HALKit/AMD64/HalKernelMain.cxx index 10a5d761..b581f6de 100644 --- a/Private/Source/KernelMain.cxx +++ b/Private/HALKit/AMD64/HalKernelMain.cxx @@ -20,6 +20,36 @@ #include <NewKit/KernelHeap.hpp> #include <NewKit/UserHeap.hpp> +extern "C" HCore::UIntPtr __EXEC_IVT; + +namespace Detail { +using namespace HCore; + +Void PowerOnSelfTest() { + kcout << "POST: Starting PowerOn-Self Test...\r\n"; + asm("int $0x21"); + kcout << "POST: Done\r\n"; +} + +struct PACKED HC_GDT_ENTRY final { + UInt16 Limit0; + UInt16 Base0; + UInt8 Base1; + UInt8 AccessByte; + UInt8 Limit1_Flags; + UInt8 Base2; +}; + +struct PACKED ALIGN(0x1000) HC_GDT final { + HC_GDT_ENTRY Null; + HC_GDT_ENTRY KernCode; + HC_GDT_ENTRY KernData; + HC_GDT_ENTRY UserNull; + HC_GDT_ENTRY UserCode; + HC_GDT_ENTRY UserData; +}; +} // namespace Detail + EXTERN_C void RuntimeMain( HCore::HEL::HandoverInformationHeader* HandoverHeader) { HCore::kcout << "HCoreKrnl: (R) Version 1.00, (C) MahroussLogic all rights " @@ -32,6 +62,32 @@ EXTERN_C void RuntimeMain( kKernelPhysicalSize = HandoverHeader->f_VirtualSize; kKernelPhysicalStart = HandoverHeader->f_VirtualStart; + static Detail::HC_GDT GDT = { + {0, 0, 0, 0x00, 0x00, 0}, // null entry + {0, 0, 0, 0x9a, 0xa0, 0}, // kernel code + {0, 0, 0, 0x92, 0xa0, 0}, // kernel data + {0, 0, 0, 0x00, 0x00, 0}, // null entry + {0, 0, 0, 0x9a, 0xa0, 0}, // user code + {0, 0, 0, 0x92, 0xa0, 0}, // user data + }; + + HCore::HAL::Register64 gdtBase; + + gdtBase.Base = (HCore::UIntPtr)&GDT; + gdtBase.Limit = sizeof(Detail::HC_GDT) - 1; + + HCore::HAL::GDTLoader gdt; + gdt.Load(gdtBase); + + HCore::VoidPtr IDT = new HCore::VoidPtr; + + HCore::HAL::Register64 idtBase; + idtBase.Base = (HCore::UIntPtr)IDT; + idtBase.Limit = 0x0FFF; + + HCore::HAL::IDTLoader idt; + idt.Load(idtBase); + if (HandoverHeader->f_Bootloader == 0xDD) { /// Mount a New partition. HCore::IFilesystemManager::Mount(new HCore::NewFilesystemManager()); @@ -58,6 +114,8 @@ EXTERN_C void RuntimeMain( DrawResource(PoweredByAward, HandoverHeader, POWEREDBYAWARD_HEIGHT, POWEREDBYAWARD_WIDTH, POWEREDBYAWARD_WIDTH + 20, 10); + Detail::PowerOnSelfTest(); + /** ** This draws the HCore resource icon.. */ diff --git a/Private/HALKit/AMD64/HalNewBoot.asm b/Private/HALKit/AMD64/HalNewBoot.asm index 93456c89..8c7d7d1a 100644 --- a/Private/HALKit/AMD64/HalNewBoot.asm +++ b/Private/HALKit/AMD64/HalNewBoot.asm @@ -13,9 +13,6 @@ [global MainLong] [global MainUnsupported] -;; External symbols needed by this unit. -[extern Main] - %define kTypeKernel 100 %define kArchAmd64 122 @@ -26,3 +23,27 @@ HandoverType: dw kTypeKernel HandoverArch: dw kArchAmd64 ;; This NewBootStart points to Main. HandoverStart: dq Main + +section .text + +[bits 64] + +extern rt_load_gdt +extern rt_load_ivt + +global Main +extern RuntimeMain +extern MainLong + +;; Just a simple setup, we'd also need to tell some before +Main: + push rcx + jmp MainLong + +MainLong: + jmp RuntimeMain + pop rcx +L0: + cli + hlt + jmp $ diff --git a/Private/HALKit/AMD64/HalPlatformAMD64.cpp b/Private/HALKit/AMD64/HalPlatformAMD64.cpp index e9e7fb82..b2e98004 100644 --- a/Private/HALKit/AMD64/HalPlatformAMD64.cpp +++ b/Private/HALKit/AMD64/HalPlatformAMD64.cpp @@ -10,21 +10,13 @@ #include <ArchKit/ArchKit.hpp> namespace HCore::HAL { -namespace Detail { -struct PACKED RegisterAMD64 final { - UIntPtr base; - UShort limit; -}; -} // namespace Detail - void GDTLoader::Load(Register64 &gdt) { - Detail::RegisterAMD64 *gdtReg = new Detail::RegisterAMD64(); - MUST_PASS(gdtReg); + Register64 gdtReg; - gdtReg->base = gdt.Base; - gdtReg->limit = gdt.Limit; + gdtReg.Base = gdt.Base; + gdtReg.Limit = gdt.Limit; - rt_load_gdt((VoidPtr)gdtReg); + rt_load_gdt(gdtReg); } namespace Detail::AMD64 { @@ -49,15 +41,16 @@ struct InterruptDescriptorAMD64 final { extern "C" HCore::UIntPtr rt_handle_interrupts(HCore::UIntPtr &rsp); -static ALIGN( - 0x10) Detail::AMD64::InterruptDescriptorAMD64 kIdtRegs[kMaxSyscalls]; +static ALIGN(0x10) + Detail::AMD64::InterruptDescriptorAMD64 kIdtRegs[kKernelMaxSystemCalls]; static HAL::Register64 kRegIdt; void IDTLoader::Load(Register64 &idt) { for (auto i = 0; i < 32; i++) { kIdtRegs[i].Selector = kGdtSelector; kIdtRegs[i].Ist = 0x00; - kIdtRegs[i].TypeAttributes = kInterruptGate | kRing0 | kIdtPresent; + kIdtRegs[i].TypeAttributes = + kInterruptGate | kTrapGate | kRing0 | kIdtPresent; kIdtRegs[i].OffsetLow = (((UIntPtr *)idt.Base)[i]) & 0xFFFF; kIdtRegs[i].OffsetMid = (((UIntPtr *)idt.Base)[i] >> 16) & 0xFFFF; kIdtRegs[i].OffsetHigh = (((UIntPtr *)idt.Base)[i] >> 32) & 0xFFFF; @@ -75,9 +68,13 @@ void IDTLoader::Load(Register64 &idt) { kRegIdt.Base = (UIntPtr)kIdtRegs; kRegIdt.Limit = sizeof(Detail::AMD64::InterruptDescriptorAMD64) * idt.Limit; - rt_load_idt((VoidPtr)&kRegIdt); + kcout << "HCoreKrnl: Installing Interrupt vector...\n"; + + rt_load_idt(kRegIdt); + + asm volatile("sti"); - kcout << "Krnl: IDT loaded\n"; + kcout << "HCoreKrnl: Interrupt Vector installed.\n"; } void GDTLoader::Load(Ref<Register64> &gdt) { GDTLoader::Load(gdt.Leak()); } diff --git a/Private/HALKit/AMD64/HalRoutines.s b/Private/HALKit/AMD64/HalRoutines.s index 28833c47..d809541f 100644 --- a/Private/HALKit/AMD64/HalRoutines.s +++ b/Private/HALKit/AMD64/HalRoutines.s @@ -6,7 +6,17 @@ .section .text rt_load_gdt: lgdt (%rcx) - ret + mov $0x10, %ax + mov %ax, %ds + mov %ax, %es + mov %ax, %fs + mov %ax, %gs + mov %ax, %ss + pop %rdi + mov $0x08, %rax + push %rax + push %rdi + retfq rt_load_idt: lidt (%rcx) diff --git a/Private/HALKit/AMD64/Processor.hpp b/Private/HALKit/AMD64/Processor.hpp index a624b795..2ba98abf 100644 --- a/Private/HALKit/AMD64/Processor.hpp +++ b/Private/HALKit/AMD64/Processor.hpp @@ -138,5 +138,5 @@ extern "C" void idt_handle_gpf(HCore::UIntPtr rsp); extern "C" void idt_handle_math(HCore::UIntPtr rsp); extern "C" void idt_handle_pf(HCore::UIntPtr rsp); -extern "C" void rt_load_idt(HCore::voidPtr ptr); -extern "C" void rt_load_gdt(HCore::voidPtr ptr); +extern "C" void rt_load_idt(HCore::HAL::Register64 ptr); +extern "C" void rt_load_gdt(HCore::HAL::Register64 ptr); diff --git a/Private/HALKit/AXP/CoreSyscallHandlerDEC.cpp b/Private/HALKit/AXP/CoreSyscallHandlerDEC.cpp index 5d1c6d2b..51b1fa0d 100644 --- a/Private/HALKit/AXP/CoreSyscallHandlerDEC.cpp +++ b/Private/HALKit/AXP/CoreSyscallHandlerDEC.cpp @@ -10,12 +10,12 @@ #include <ArchKit/ArchKit.hpp> #include <HALKit/Alpha/Processor.hpp> -HCore::Array<void (*)(HCore::Int32 id, HCore::HAL::StackFrame *), kMaxSyscalls> kSyscalls; +HCore::Array<void (*)(HCore::Int32 id, HCore::HAL::StackFrame *), + kKernelMaxSystemCalls> + kSyscalls; -extern "C" void rt_syscall_handle(HCore::HAL::StackFrame *stack) -{ - for (HCore::SizeT index = 0UL; index < kMaxSyscalls; ++index) - { - (kSyscalls[index].Leak().Leak())(stack->ID, stack); - } +extern "C" void rt_syscall_handle(HCore::HAL::StackFrame *stack) { + for (HCore::SizeT index = 0UL; index < kKernelMaxSystemCalls; ++index) { + (kSyscalls[index].Leak().Leak())(stack->ID, stack); + } } diff --git a/Private/HALKit/PowerPC/HalCoreSyscallHandlerPowerPC.cpp b/Private/HALKit/PowerPC/HalCoreSyscallHandlerPowerPC.cpp index c1672e68..71554dc4 100644 --- a/Private/HALKit/PowerPC/HalCoreSyscallHandlerPowerPC.cpp +++ b/Private/HALKit/PowerPC/HalCoreSyscallHandlerPowerPC.cpp @@ -10,11 +10,12 @@ #include <ArchKit/ArchKit.hpp> #include <NewKit/Array.hpp> -HCore::Array<void (*)(HCore::Int32 id, HCore::HAL::StackFrame *), kMaxSyscalls> +HCore::Array<void (*)(HCore::Int32 id, HCore::HAL::StackFrame *), + kKernelMaxSystemCalls> kSyscalls; extern "C" void rt_syscall_handle(HCore::HAL::StackFrame *stack) { - for (HCore::SizeT index = 0UL; index < kMaxSyscalls; ++index) { + for (HCore::SizeT index = 0UL; index < kKernelMaxSystemCalls; ++index) { (kSyscalls[index].Leak().Leak())(stack->ID, stack); } } diff --git a/Private/NewBoot/Source/makefile b/Private/NewBoot/Source/makefile index 0e9cd4d2..30213e07 100644 --- a/Private/NewBoot/Source/makefile +++ b/Private/NewBoot/Source/makefile @@ -20,15 +20,19 @@ invalid-recipe: bootloader-amd64: $(CC_GNU) $(FLAG_GNU) HEL/AMD64/*.cxx *.cxx $(ASM) $(FLAG_ASM) HEl/AMD64/AMD64-VirtualMemory.asm - $(LD_GNU) $(OBJ) $(LD_FLAGS) -o HCoreKrnl.exe - cp HCoreKrnl.exe CDROM/EFI/BOOT/BOOTX64.EFI + $(LD_GNU) $(OBJ) $(LD_FLAGS) -o HCoreLdr.exe + cp HCoreLdr.exe CDROM/EFI/BOOT/BOOTX64.EFI + cp HCoreLdr.exe CDROM/EFI/BOOT/HCORELDR.EFI cp ../../HCoreKrnl.dll CDROM/HCOREKRNL.DLL .PHONY: run-efi-amd64 run-efi-amd64: - wget https://retrage.github.io/edk2-nightly/bin/DEBUGX64_OVMF.fd -O OVMF.fd qemu-system-x86_64 -net none -smp 2 -m 4G -M q35 -bios OVMF.fd -drive file=fat:rw:CDROM,index=1,format=raw -serial stdio +.PHONY: download-edk +download-edk: + wget https://retrage.github.io/edk2-nightly/bin/DEBUGX64_OVMF.fd -O OVMF.fd + .PHONY: clean clean: rm -f $(OBJ) HCoreLdr.exe OVMF.fd diff --git a/Private/makefile b/Private/makefile index 6717a581..9e10d7bc 100644 --- a/Private/makefile +++ b/Private/makefile @@ -5,7 +5,7 @@ CC = x86_64-w64-mingw32-g++ LD = x86_64-w64-mingw32-ld -CCFLAGS = -c -ffreestanding -fno-rtti -fno-exceptions -std=c++20 -D__DEBUG__ -D__FSKIT_NEWFS__ -D__HAVE_HCORE_APIS__ -D__HCORE__ -I../ -I./ -I$(HOME)/ +CCFLAGS = -c -ffreestanding -mgeneral-regs-only -mno-red-zone -fno-rtti -fno-exceptions -std=c++20 -D__DEBUG__ -D__FSKIT_NEWFS__ -D__HAVE_HCORE_APIS__ -D__HCORE__ -I../ -I./ -I$(HOME)/ ASM = nasm ASMFLAGS = -f win64 LDFLAGS = -e Main -shared --subsystem=17 |
