diff options
23 files changed, 266 insertions, 160 deletions
diff --git a/Private/ArchKit/ArchKit.hpp b/Private/ArchKit/ArchKit.hpp index 17a7db4c..4fbe55ac 100644 --- a/Private/ArchKit/ArchKit.hpp +++ b/Private/ArchKit/ArchKit.hpp @@ -61,7 +61,7 @@ extern HCore::Array<void (*)(HCore::Int32 id, HCore::HAL::StackFrame *), kKernelMaxSystemCalls> kSyscalls; -EXTERN_C HCore::Void rt_wait_for_io(); +EXTERN_C HCore::Void rt_wait_400ns(); EXTERN_C HCore::Void rt_syscall_handle(HCore::HAL::StackFramePtr stackFrame); EXTERN_C HCore::HAL::StackFramePtr rt_get_current_context(); EXTERN_C HCore::Void rt_do_context_switch(HCore::HAL::StackFramePtr stackFrame); diff --git a/Private/CompilerKit/Version.hxx b/Private/CompilerKit/Version.hxx index 66f9a749..d29e0543 100644 --- a/Private/CompilerKit/Version.hxx +++ b/Private/CompilerKit/Version.hxx @@ -1,4 +1,4 @@ #pragma once -#define BOOTLOADER_VERSION L"v1.13" -#define KERNEL_VERSION "v1.13" +#define BOOTLOADER_VERSION L"v1.13.A" +#define KERNEL_VERSION "v1.13.A" diff --git a/Private/HALKit/AMD64/HalCoreInterruptHandler.cpp b/Private/HALKit/AMD64/HalCoreInterruptHandler.cpp index 0b3af515..2acfc454 100644 --- a/Private/HALKit/AMD64/HalCoreInterruptHandler.cpp +++ b/Private/HALKit/AMD64/HalCoreInterruptHandler.cpp @@ -14,23 +14,23 @@ static const char* kExceptionMessages[32] = { "Division by zero", "Debug Breakpoint", - "Non-maskable interrupt", + "Non-maskable Interrupt", "Breakpoint", - "Detected overflow", - "Out-of-bounds", - "Invalid opcode", - "No coprocessor", - "Double fault", - "Coprocessor segment overrun", + "Detected Overflow", + "Out-Of-Bounds", + "Invalid Opcode", + "No Coprocessor", + "Double Fault", + "Coprocessor Segment Overrun", "Bad TSS", - "Segment not found", - "Stack error.", + "Segment Not Found", + "Stack Error", "General Protection Fault", "Page Fault", - "Invalid interrupt", - "Coprocessor fault", - "Alignment check", - "Machine check", + "Invalid Interrupt", + "Coprocessor Fault", + "Alignment Check", + "Machine Check", "Reserved", "Reserved", "Reserved", @@ -49,13 +49,14 @@ static const char* kExceptionMessages[32] = { /// @brief System call interrupt (like DOS and NT) #define kKernelSyscallInterrupt (0x21) -extern "C" { +EXTERN_C { HCore::UIntPtr rt_handle_interrupts(HCore::HAL::StackFramePtr sf) { - HCore::HAL::rt_cli(); + MUST_PASS(sf); if (sf->IntNum < 32) { } else if (sf->IntNum == 0x21) { + rt_syscall_handle(sf); } if ((sf->IntNum - 32) >= 12) { @@ -64,8 +65,6 @@ HCore::UIntPtr rt_handle_interrupts(HCore::HAL::StackFramePtr sf) { HCore::HAL::Out8(0x20, 0x20); - HCore::HAL::rt_sti(); - return (HCore::UIntPtr)sf; } diff --git a/Private/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cpp b/Private/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cpp index f1001410..d1483ef3 100644 --- a/Private/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cpp +++ b/Private/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cpp @@ -39,7 +39,7 @@ extern "C" void idt_handle_scheduler(HCore::UIntPtr rsp) { HCore::kcout << "HCoreKrnl: Will be scheduled back later " << HCore::ProcessManager::Shared().Leak().GetCurrent().Leak().GetName() - << HCore::EndLine(); + << HCore::end_line(); /// schedule another process. if (!HCore::ProcessHelper::StartScheduling()) { diff --git a/Private/HALKit/AMD64/HalCoreSyscallHandlerAMD64.cpp b/Private/HALKit/AMD64/HalCoreSyscallHandlerAMD64.cpp index cacb66d8..3a3b49b3 100644 --- a/Private/HALKit/AMD64/HalCoreSyscallHandlerAMD64.cpp +++ b/Private/HALKit/AMD64/HalCoreSyscallHandlerAMD64.cpp @@ -11,13 +11,13 @@ #include <HALKit/AMD64/Processor.hpp> #include <KernelKit/PermissionSelector.hxx> -HCore::Array<void (*)(HCore::Int32 id, HCore::HAL::StackFrame *), - kKernelMaxSystemCalls> - kSyscalls; +typedef HCore::Void (*rt_syscall_proc)(HCore::Int32 id, HCore::HAL::StackFramePtr); + +HCore::Array<rt_syscall_proc, kKernelMaxSystemCalls> kSyscalls; /// @brief Interrupt system call handler. -extern "C" void rt_syscall_handle(HCore::HAL::StackFrame *stack) { - for (HCore::SizeT index = 0UL; index < kKernelMaxSystemCalls; ++index) { - if (kSyscalls[index]) (kSyscalls[index].Leak().Leak())(stack->R15, stack); +extern "C" void rt_syscall_handle(HCore::HAL::StackFramePtr stack) { + if (stack->R15 < kKernelMaxSystemCalls && kSyscalls[stack->R15] != 0) { + (kSyscalls[stack->R15].Leak().Leak())(stack->R15, stack); } } diff --git a/Private/HALKit/AMD64/HalDebugPort.cxx b/Private/HALKit/AMD64/HalDebugPort.cxx index d292f95d..510aa421 100644 --- a/Private/HALKit/AMD64/HalDebugPort.cxx +++ b/Private/HALKit/AMD64/HalDebugPort.cxx @@ -42,16 +42,16 @@ void rt_debug_listen(DebuggerPorts* theHook) noexcept { for (UInt32 i = 0U; i < kDebugMaxPorts; ++i) { HAL::Out16(theHook->fPort[i], kDebugMag0); - HAL::rt_wait_for_io(); + HAL::rt_wait_400ns(); HAL::Out16(theHook->fPort[i], kDebugMag1); - HAL::rt_wait_for_io(); + HAL::rt_wait_400ns(); HAL::Out16(theHook->fPort[i], kDebugMag2); - HAL::rt_wait_for_io(); + HAL::rt_wait_400ns(); HAL::Out16(theHook->fPort[i], kDebugMag3); - HAL::rt_wait_for_io(); + HAL::rt_wait_400ns(); if (HAL::In16(theHook->fPort[i] != kDebugUnboundPort)) theHook->fBoundCnt++; } diff --git a/Private/HALKit/AMD64/HalDescriptorLoader.cpp b/Private/HALKit/AMD64/HalDescriptorLoader.cpp index 59952cd3..53218c17 100644 --- a/Private/HALKit/AMD64/HalDescriptorLoader.cpp +++ b/Private/HALKit/AMD64/HalDescriptorLoader.cpp @@ -9,10 +9,8 @@ #include <ArchKit/ArchKit.hpp> -EXTERN_C HCore::UIntPtr ke_handle_irq; - namespace HCore::HAL { -static Register64 kRegGdt; +STATIC Register64 kRegGdt; void GDTLoader::Load(Register64 &gdt) { kRegGdt.Base = gdt.Base; @@ -21,37 +19,58 @@ void GDTLoader::Load(Register64 &gdt) { rt_load_gdt(kRegGdt); } -static volatile HAL::Register64 kRegIdt; +STATIC HAL::Register64 kRegIdt; void IDTLoader::Load(Register64 &idt) { + UInt8 a1, a2; + + a1 = HAL::In8(0x21); // save masks + a2 = HAL::In8(0xA1); + // Remap PIC. HAL::Out8(0x20, 0x11); + HAL::rt_wait_400ns(); HAL::Out8(0xA0, 0x11); + HAL::rt_wait_400ns(); HAL::Out8(0x21, 0x20); + HAL::rt_wait_400ns(); HAL::Out8(0xA1, 0x28); + HAL::rt_wait_400ns(); HAL::Out8(0x21, 0x04); + HAL::rt_wait_400ns(); HAL::Out8(0xA1, 0x02); + HAL::rt_wait_400ns(); HAL::Out8(0x21, 0x01); + HAL::rt_wait_400ns(); HAL::Out8(0xA1, 0x01); - HAL::Out8(0x21, 0x0); - HAL::Out8(0xA1, 0x0); + HAL::rt_wait_400ns(); + HAL::Out8(0x21, a1); + HAL::rt_wait_400ns(); + HAL::Out8(0xA1, a2); - volatile ::HCore::Detail::AMD64::InterruptDescriptorAMD64 *baseIdt = - (::HCore::Detail::AMD64::InterruptDescriptorAMD64 *)idt.Base; + volatile ::HCore::UIntPtr *baseIdt = (::HCore::UIntPtr *)idt.Base; + + MUST_PASS(baseIdt[0]); + + ::HCore::Detail::AMD64::InterruptDescriptorAMD64 *kInterruptVectorTable = + new ::HCore::Detail::AMD64::InterruptDescriptorAMD64[kKernelIdtSize]; for (auto i = 0; i < kKernelIdtSize; i++) { - baseIdt[i].Selector = kGdtCodeSelector; - baseIdt[i].Ist = 0x0; - baseIdt[i].TypeAttributes = kInterruptGate; - baseIdt[i].OffsetLow = (UInt16)((UInt32)ke_handle_irq & 0x000000000000ffff); - baseIdt[i].OffsetMid = - (UInt16)(((UInt32)ke_handle_irq & 0x00000000ffff0000) >> 16); - baseIdt[i].OffsetHigh = - (UInt32)(((UInt32)ke_handle_irq & 0xffffffff00000000) >> 32); - baseIdt[i].Zero = 0x0; + kInterruptVectorTable[i].Selector = kGdtCodeSelector; + kInterruptVectorTable[i].Ist = 0x0; + kInterruptVectorTable[i].TypeAttributes = kInterruptGate; + kInterruptVectorTable[i].OffsetLow = (baseIdt[i] & 0xFF); + kInterruptVectorTable[i].OffsetMid = ((baseIdt[i] & 0xFFFF) >> 16); + kInterruptVectorTable[i].OffsetHigh = ((baseIdt[i] & 0xFFFFFFFF) >> 32); + kInterruptVectorTable[i].Zero = 0x0; } - rt_load_idt(idt); + kRegIdt.Base = (UIntPtr)&kInterruptVectorTable[0]; + kRegIdt.Limit = sizeof(::HCore::Detail::AMD64::InterruptDescriptorAMD64) * + kKernelIdtSize - + 1; + + rt_load_idt(kRegIdt); } void GDTLoader::Load(Ref<Register64> &gdt) { GDTLoader::Load(gdt.Leak()); } diff --git a/Private/HALKit/AMD64/HalHardwareAPIC.cpp b/Private/HALKit/AMD64/HalHardwareAPIC.cpp index 4e985f8e..cae54658 100644 --- a/Private/HALKit/AMD64/HalHardwareAPIC.cpp +++ b/Private/HALKit/AMD64/HalHardwareAPIC.cpp @@ -15,12 +15,12 @@ namespace HCore { // @brief wakes up thread. // wakes up thread from hang. void rt_wakeup_thread(HAL::StackFrame* stack) { - __asm__ volatile("cli"); + HAL::rt_cli(); stack->Rbp = stack->R15; stack->Rsi = stack->Rbp; - __asm__ volatile("sti"); + HAL::rt_sti(); } static void __rt_hang_proc(void) { diff --git a/Private/HALKit/AMD64/HalInterruptRouting.asm b/Private/HALKit/AMD64/HalInterruptRouting.asm index 7de90da0..1ed802b4 100644 --- a/Private/HALKit/AMD64/HalInterruptRouting.asm +++ b/Private/HALKit/AMD64/HalInterruptRouting.asm @@ -11,18 +11,36 @@ [bits 64] +%macro IntDecl 1 + dq __HCR_INT_%1 +%endmacro + +%macro IntExp 1 +__HCR_INT_%1: + push 0 + push %1 + call ke_handle_irq + iretq +%endmacro + +%macro IntNormal 1 +__HCR_INT_%1: + push %1 + call ke_handle_irq + iretq +%endmacro + ; This file handles the core interrupt table ; Last edited 31/01/24 extern rt_handle_interrupts -global ke_power_on_self_test +global _ke_power_on_self_test global ke_handle_irq +global kInterruptVectorTable section .text ke_handle_irq: - cld - push rax push rbx push rcx @@ -41,7 +59,7 @@ ke_handle_irq: mov rcx, rsp call rt_handle_interrupts - mov rsp, rax + mov rsp, rcx pop r15 pop r14 @@ -59,12 +77,95 @@ ke_handle_irq: pop rbx pop rax - std - iretq + ret + +section .data + +IntNormal 0 +IntNormal 1 +IntNormal 2 +IntNormal 3 +IntNormal 4 +IntNormal 5 +IntNormal 6 +IntNormal 7 +IntExp 8 +IntNormal 9 +IntExp 10 +IntExp 11 +IntExp 12 +IntExp 13 +IntExp 14 +IntNormal 15 +IntNormal 16 +IntExp 17 +IntNormal 18 +IntNormal 19 +IntNormal 20 +IntNormal 21 +IntNormal 22 +IntNormal 23 +IntNormal 24 +IntNormal 25 +IntNormal 26 +IntNormal 27 +IntNormal 28 +IntNormal 29 +IntExp 30 +IntNormal 31 + +%assign i 32 +%rep 255 + IntNormal i +%assign i i+1 +%endrep + +section .text ;; this one is doing a POST for us. ;; testing interrupts. -ke_power_on_self_test: +_ke_power_on_self_test: + int 0x21 + int 0x21 + int 0x21 int 0x21 - int 0xe - ret
\ No newline at end of file + int 0x21 + int 0x21 + int 0x21 + int 0x21 + + ret + +[global rt_load_gdt] + +rt_load_gdt: + lgdt [rcx] + push 0x08 + lea rax, [rel rt_reload_segments] + push rax + retfq +rt_reload_segments: + mov ax, 0x10 + mov ds, ax + mov es, ax + mov fs, ax + mov gs, ax + mov ss, ax + ret + +global rt_load_idt + +section .text + +rt_load_idt: + lidt [rcx] + ret + +section .data + +kInterruptVectorTable: + %assign i 0 + %rep 255 + IntDecl i + %assign i i+1 + %endrep diff --git a/Private/HALKit/AMD64/HalKernelMain.cxx b/Private/HALKit/AMD64/HalKernelMain.cxx index c4f4ed94..d799e5ae 100644 --- a/Private/HALKit/AMD64/HalKernelMain.cxx +++ b/Private/HALKit/AMD64/HalKernelMain.cxx @@ -20,10 +20,15 @@ #include <NewKit/KernelHeap.hpp> #include <NewKit/UserHeap.hpp> +///! @brief Disk contains HCore files. +#define kInstalledMedia 0xDD + +EXTERN_C VoidStar kInterruptVectorTable[]; + namespace Detail { using namespace HCore; -EXTERN_C void ke_power_on_self_test(void); +EXTERN_C void _ke_power_on_self_test(void); /** @brief Global descriptor table entry, either null, code or data. @@ -55,16 +60,16 @@ EXTERN_C void RuntimeMain( kKernelVirtualSize = HandoverHeader->f_VirtualSize; kKernelVirtualStart = HandoverHeader->f_VirtualStart; - kKernelPhysicalSize = HandoverHeader->f_VirtualSize; - kKernelPhysicalStart = HandoverHeader->f_VirtualStart; + kKernelPhysicalSize = HandoverHeader->f_PhysicalSize; + kKernelPhysicalStart = HandoverHeader->f_PhysicalStart; 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, 0x9a, 0xaf, 0}, // kernel code + {0, 0, 0, 0x92, 0xaf, 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 + {0, 0, 0, 0x9a, 0xaf, 0}, // user code + {0, 0, 0, 0x92, 0xaf, 0}, // user data }; HCore::HAL::Register64 gdtBase; @@ -79,19 +84,15 @@ EXTERN_C void RuntimeMain( /// load idt buffer - constexpr HCore::Int IDT_SIZE = 4095; - - HCore::UIntPtr* kInterruptVectorTable = new HCore::UIntPtr[IDT_SIZE]; - HCore::HAL::Register64 idtBase; idtBase.Base = (HCore::UIntPtr)kInterruptVectorTable; - idtBase.Limit = IDT_SIZE; + idtBase.Limit = 0; HCore::HAL::IDTLoader idt; idt.Load(idtBase); - if (HandoverHeader->f_Bootloader == 0xDD) { - /// Mounts a NewFS partition. + if (HandoverHeader->f_Bootloader == kInstalledMedia) { + /// Mounts a NewFS block. HCore::IFilesystemManager::Mount(new HCore::NewFilesystemManager()); // Open file from first hard-drive. @@ -106,15 +107,8 @@ EXTERN_C void RuntimeMain( ** This does the POST. */ - HCore::kcout << "FOOBAR." << HCore::EndLine(); - - Detail::ke_power_on_self_test(); - - HCore::kcout << "FOOBAR." << HCore::EndLine(); - /** - ** This draws the HCore resource icon.. - */ - + Detail::_ke_power_on_self_test(); + /** This mounts the NewFS drive. */ diff --git a/Private/HALKit/AMD64/HalPageAlloc.cpp b/Private/HALKit/AMD64/HalPageAlloc.cpp index 4654ab7b..84ddc665 100644 --- a/Private/HALKit/AMD64/HalPageAlloc.cpp +++ b/Private/HALKit/AMD64/HalPageAlloc.cpp @@ -22,6 +22,8 @@ namespace HCore { namespace HAL { static auto hal_try_alloc_new_page(SizeT sz, Boolean rw, Boolean user) -> PageTable64 * { + MUST_PASS(sz != 0); + PageTable64 *pte = reinterpret_cast<PageTable64 *>((UIntPtr)kKernelVirtualStart); @@ -29,8 +31,8 @@ static auto hal_try_alloc_new_page(SizeT sz, Boolean rw, Boolean user) pte->User = user; pte->Present = true; - kKernelVirtualStart = - (VoidPtr)((UIntPtr)kKernelVirtualStart + kPageCnt + sz + kKernelPagingPadding); + kKernelVirtualStart = (VoidPtr)((UIntPtr)kKernelVirtualStart + kPageCnt + sz + + kKernelPagingPadding); return pte; } diff --git a/Private/HALKit/AMD64/HalRoutines.s b/Private/HALKit/AMD64/HalRoutines.s index bbef4bbd..a25b25c7 100644 --- a/Private/HALKit/AMD64/HalRoutines.s +++ b/Private/HALKit/AMD64/HalRoutines.s @@ -1,30 +1,10 @@ .globl rt_load_idt .globl rt_load_gdt -.globl rt_wait_for_io +.globl rt_wait_400ns .globl rt_get_current_context .section .text -rt_load_gdt: - lgdt (%rcx) - 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) - sti - ret - -.section .text -rt_wait_for_io: +rt_wait_400ns: jmp .loop .loop: jmp .loop2 diff --git a/Private/HALKit/AMD64/Processor.hpp b/Private/HALKit/AMD64/Processor.hpp index e5e66f09..035b095f 100644 --- a/Private/HALKit/AMD64/Processor.hpp +++ b/Private/HALKit/AMD64/Processor.hpp @@ -36,29 +36,30 @@ namespace Detail::AMD64 { struct PACKED InterruptDescriptorAMD64 final { UInt16 OffsetLow; // offset bits 0..15 UInt16 Selector; // a code segment selector in GDT or LDT - UInt8 Ist; // bits 0..2 holds Interrupt Stack Table offset, rest of bits zero. + UInt8 + Ist; // bits 0..2 holds Interrupt Stack Table offset, rest of bits zero. UInt8 TypeAttributes; // gate type, dpl, and p fields UInt16 OffsetMid; // offset bits 16..31 UInt32 OffsetHigh; // offset bits 32..63 UInt32 Zero; // reserved }; } // namespace Detail::AMD64 -} // namespace HCore +} // namespace HCore namespace HCore::HAL { -extern "C" UChar In8(UInt16 port); -extern "C" UShort In16(UInt16 port); -extern "C" UInt In32(UInt16 port); +EXTERN_C UChar In8(UInt16 port); +EXTERN_C UShort In16(UInt16 port); +EXTERN_C UInt In32(UInt16 port); -extern "C" void Out16(UShort port, UShort byte); -extern "C" void Out8(UShort port, UChar byte); -extern "C" void Out32(UShort port, UInt byte); +EXTERN_C void Out16(UShort port, UShort byte); +EXTERN_C void Out8(UShort port, UChar byte); +EXTERN_C void Out32(UShort port, UInt byte); -extern "C" void rt_wait_for_io(); -extern "C" void rt_halt(); -extern "C" void rt_cli(); -extern "C" void rt_sti(); -extern "C" void rt_cld(); +EXTERN_C void rt_wait_400ns(); +EXTERN_C void rt_halt(); +EXTERN_C void rt_cli(); +EXTERN_C void rt_sti(); +EXTERN_C void rt_cld(); class PACKED Register64 { public: @@ -74,7 +75,6 @@ using interruptTrap = UIntPtr(UIntPtr sp); typedef UIntPtr Reg; struct PACKED StackFrame { - Reg ExceptionZ; Reg IntNum; Reg Rax; Reg Rbx; @@ -151,13 +151,15 @@ class IDTLoader final { void system_get_cores(voidPtr rsdPtr); } // namespace HCore::HAL -extern "C" void idt_handle_system_call(HCore::UIntPtr rsp); -extern "C" void idt_handle_generic(HCore::UIntPtr rsp); -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 idt_handle_system_call(HCore::UIntPtr rsp); +EXTERN_C void idt_handle_generic(HCore::UIntPtr rsp); +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::HAL::Register64 ptr); -extern "C" void rt_load_gdt(HCore::HAL::Register64 ptr); +EXTERN_C void rt_load_idt(HCore::HAL::Register64 ptr); +EXTERN_C void rt_load_gdt(HCore::HAL::Register64 ptr); + +/// @brief Maximum size of the IDT. +#define kKernelIdtSize 256 -#define kKernelIdtSize 256
\ No newline at end of file diff --git a/Private/HALKit/AXP/HAL.s b/Private/HALKit/AXP/HAL.s index 46127130..0178527f 100644 --- a/Private/HALKit/AXP/HAL.s +++ b/Private/HALKit/AXP/HAL.s @@ -1,7 +1,7 @@ -.globl rt_wait_for_io +.globl rt_wait_400ns .section .text -rt_wait_for_io: +rt_wait_400ns: jmp .L .L: jmp .L2 diff --git a/Private/HALKit/PowerPC/HalThread.cxx b/Private/HALKit/PowerPC/HalThread.cxx index b280ba90..0c6cfa4b 100644 --- a/Private/HALKit/PowerPC/HalThread.cxx +++ b/Private/HALKit/PowerPC/HalThread.cxx @@ -11,6 +11,6 @@ #include <KernelKit/DebugOutput.hpp> extern "C" void flush_tlb() {} -extern "C" void rt_wait_for_io() {} +extern "C" void rt_wait_400ns() {} extern "C" HCore::HAL::StackFramePtr rt_get_current_context() { return nullptr; } diff --git a/Private/KernelKit/DebugOutput.hpp b/Private/KernelKit/DebugOutput.hpp index a23b9ab3..4b077599 100644 --- a/Private/KernelKit/DebugOutput.hpp +++ b/Private/KernelKit/DebugOutput.hpp @@ -33,7 +33,7 @@ class TerminalDevice final : public DeviceInterface<const Char *> { static TerminalDevice Shared() noexcept; }; -inline TerminalDevice EndLine() { +inline TerminalDevice end_line() { TerminalDevice selfTerm = TerminalDevice::Shared(); selfTerm << "\n"; return selfTerm; @@ -45,3 +45,5 @@ inline TerminalDevice EndLine() { #endif // ifdef kcout #define kcout TerminalDevice::Shared() +#define endl end_line() + diff --git a/Private/KernelKit/DriveManager.hpp b/Private/KernelKit/DriveManager.hpp index 912c7fd9..f0cd76e6 100644 --- a/Private/KernelKit/DriveManager.hpp +++ b/Private/KernelKit/DriveManager.hpp @@ -62,6 +62,10 @@ struct DriveTraits final { typedef DeviceInterface<DriveTraits> DriveDevice; typedef DriveDevice* DriveDevicePtr; +/** + * @brief Abstracted hard-drive container class. + * @note This class has all of it's drive set to nullptr, allocate them using GetAddressOf(index). + */ class Mountpoint final { public: explicit Mountpoint() = default; @@ -87,7 +91,7 @@ class Mountpoint final { return &mD; default: { GetLastError() = kErrorNoSuchDisk; - kcout << "Krnl\\Mountpoint: Check HError.\n"; + kcout << "HCoreKrnl\\Mountpoint: Check HError.\n"; break; } } @@ -96,7 +100,7 @@ class Mountpoint final { } private: - DriveDevicePtr mA, mB, mC, mD; + DriveDevicePtr mA, mB, mC, mD = nullptr; }; } // namespace HCore diff --git a/Private/NewBoot/Source/BootMain.cxx b/Private/NewBoot/Source/BootMain.cxx index fe9c2d9d..0853180d 100644 --- a/Private/NewBoot/Source/BootMain.cxx +++ b/Private/NewBoot/Source/BootMain.cxx @@ -33,7 +33,7 @@ EFI_EXTERN_C EFI_API Int EfiMain(EfiHandlePtr ImageHandle, BTextWriter writer; - writer.Write(L"HCoreLdr: "); + writer.Write(L"MahroussLogic (R) HCoreLdr: "); writer.Write(BVersionString::Shared()).Write(L"\r\n"); @@ -47,7 +47,7 @@ EFI_EXTERN_C EFI_API Int EfiMain(EfiHandlePtr ImageHandle, .Write(SystemTable->FirmwareVendor) .Write(L"\r\n"); - BFileReader img(L"HCOREKRNL.DLL", ImageHandle); + BFileReader img(L"HCOREKRNL.EXE", ImageHandle); img.Size(kBootReadSize); img.ReadAll(); @@ -129,6 +129,17 @@ EFI_EXTERN_C EFI_API Int EfiMain(EfiHandlePtr ImageHandle, systemIni.Size(1); systemIni.ReadAll(); + ST->ConOut->ClearScreen(ST->ConOut); + + writer.Write( + L"Warning: This computer program is protected by copyright " + L"law and international treaties.\r\nUnauthorized reproduction " + L"or distribution of this program, or any portion of it,\r\nmay " + L"result in severe civil and criminal penalties,\r\nand will be " + L"prosecuted to the maximum extent possible under the law.\r\n"); + + EFI::ExitBootServices(MapKey, ImageHandle); + bool isIniNotFound = (systemIni.Blob() == nullptr); if (isIniNotFound) { @@ -136,10 +147,6 @@ EFI_EXTERN_C EFI_API Int EfiMain(EfiHandlePtr ImageHandle, handoverHdrPtr->f_Version = 0x1011; handoverHdrPtr->f_Bootloader = 0x11; // Installer - writer.Write(L"HCoreLdr: Loading HCore...\r\n"); - - EFI::ExitBootServices(MapKey, ImageHandle); - Main(handoverHdrPtr); } else { diff --git a/Private/NewBoot/Source/makefile b/Private/NewBoot/Source/makefile index 4d714abc..933dd1dd 100644 --- a/Private/NewBoot/Source/makefile +++ b/Private/NewBoot/Source/makefile @@ -5,12 +5,12 @@ CC_GNU=x86_64-w64-mingw32-g++ LD_GNU=x86_64-w64-mingw32-ld -LD_FLAGS=-e efi_main -shared --subsystem=10 -ffreestanding +LD_FLAGS=-e efi_main --subsystem=10 ASM=nasm -OBJ=$(wildcard *.o) $(wildcard ../../Obj/*.obj) $(wildcard ../../*.exe) $(wildcard HEL/AMD64/*.obj) $(wildcard HEL/AMD64/*.o) +OBJ=$(wildcard *.o) $(wildcard ../../Obj/*.obj) $(wildcard HEL/AMD64/*.obj) FLAG_ASM=-f win64 -FLAG_GNU=-fshort-wchar -O0 -D__DEBUG__ -fPIC -DEFI_FUNCTION_WRAPPER -I../ -I../../ -I./ -c -ffreestanding -fno-rtti -fno-exceptions -std=c++20 -D__HAVE_HCORE_APIS__ -D__HCORE__ -I./ -I$(HOME)/ +FLAG_GNU=-fshort-wchar -fPIC -O0 -D__DEBUG__ -DEFI_FUNCTION_WRAPPER -I../ -I../../ -I./ -c -ffreestanding -fno-rtti -fno-exceptions -std=c++20 -D__HAVE_HCORE_APIS__ -D__HCORE__ -I./ -I$(HOME)/ .PHONY: invalid-recipe invalid-recipe: @@ -23,11 +23,11 @@ bootloader-amd64: $(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 + cp ../../HCoreKrnl.exe CDROM/HCOREKRNL.EXE .PHONY: run-efi-amd64 run-efi-amd64: - 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 + qemu-system-x86_64 -net none -smp 2 -m 4G -M q35 -bios OVMF.fd -drive file=fat:rw:CDROM,index=1,format=raw -d int .PHONY: download-edk download-edk: diff --git a/Private/Source/KernelCheck.cxx b/Private/Source/KernelCheck.cxx index 6ce4f4fa..4fc24918 100644 --- a/Private/Source/KernelCheck.cxx +++ b/Private/Source/KernelCheck.cxx @@ -25,7 +25,7 @@ extern "C" [[noreturn]] void ke_wait_for_debugger() { namespace HCore { void ke_stop(const HCore::Int &id) { kcout << "*** STOP *** \r\n"; - kcout << "*** HCoreKrnl.dll has trigerred a runtime stop. *** \r\n"; + kcout << "*** HCoreKrnl.exe has trigerred a runtime stop. *** \r\n"; switch (id) { case RUNTIME_CHECK_PROCESS: { diff --git a/Private/Source/Storage/ATA.cxx b/Private/Source/Storage/ATA.cxx index 6027e6f9..05549e7a 100644 --- a/Private/Source/Storage/ATA.cxx +++ b/Private/Source/Storage/ATA.cxx @@ -53,7 +53,7 @@ const char* ata_read_28(ULong lba) { packet[1] = (UIntPtr)&buffer; packet[4] = lba; - rt_wait_for_io(); + rt_wait_400ns(); return buffer; } @@ -70,7 +70,7 @@ const char* ata_read_48(ULong lba) { packet[1] = (UIntPtr)&buffer; packet[4] = lba; - rt_wait_for_io(); + rt_wait_400ns(); return buffer; } @@ -84,7 +84,7 @@ Int32 ata_write_48(ULong lba, const char* buffer) { packet[1] = (UIntPtr)&buffer; packet[2] = lba; - rt_wait_for_io(); + rt_wait_400ns(); return packet[1] == 2 ? kATAError : 0; } @@ -98,7 +98,7 @@ Int32 ata_write_28(ULong lba, const char* text) { packet[1] = (UIntPtr)&text; packet[2] = lba; - rt_wait_for_io(); + rt_wait_400ns(); return packet[1] == 2 ? kATAError : 0; } diff --git a/Private/Tools/PartTool.cxx b/Private/Tools/PartTool.cxx index 8c8d52b1..dd84cfb2 100644 --- a/Private/Tools/PartTool.cxx +++ b/Private/Tools/PartTool.cxx @@ -16,10 +16,10 @@ /// @brief NewFS partition program. /***********************************************************************************/ -#include <iostream> +#include <ConOut.hxx> int main() { - std::cout + HCore::cout << "PartTool: build a NewFS partition image from a directory!\n" << "Copyright Mahrouss Logic, all rights reserved. (INTERNAL TOOL)\n"; diff --git a/Private/makefile b/Private/makefile index c1f32c59..37245e2c 100644 --- a/Private/makefile +++ b/Private/makefile @@ -5,21 +5,18 @@ CC = x86_64-w64-mingw32-g++ LD = x86_64-w64-mingw32-ld -CCFLAGS = -c -ffreestanding -D__DEBUG__ -mgeneral-regs-only -mno-red-zone -fno-rtti -fno-exceptions -std=c++20 -D__FSKIT_NEWFS__ -D__HAVE_HCORE_APIS__ -D__HCORE__ -I../ -I./ -I$(HOME)/ +CCFLAGS = -c -ffreestanding -O0 -fPIC -D__DEBUG__ -fno-rtti -fno-exceptions -std=c++20 -D__FSKIT_NEWFS__ -D__HAVE_HCORE_APIS__ -D__HCORE__ -I../ -I./ -I$(HOME)/ ASM = nasm ASMFLAGS = -f win64 -LDFLAGS = -e Main -shared --subsystem=17 -ffreestanding +LDFLAGS = -e Main --subsystem=17 LDOBJ = $(wildcard Obj/*.obj) # This file is the kernel, responsible of task management, memory, drivers and more. -KERNEL = HCoreKrnl.dll +KERNEL = HCoreKrnl.exe # The kernel entrypoint SCRIPT = --script=Linker/Platforms/PC.lds -# we want a flat binary -FMT = elf64 - .PHONY: invalid-recipe invalid-recipe: @echo "[HCoreKrnl] invalid-recipe: Use make all instead." @@ -37,7 +34,6 @@ h-core-amd64: $(MOVEALL) OBJCOPY=x86_64-w64-mingw32-objcopy -FONTFLAGS=-b binary .PHONY: link-amd64 link-amd64: |
