diff options
| author | Amlal El Mahrouss <amlalelmahrouss@icloud.com> | 2024-02-26 20:01:37 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlalelmahrouss@icloud.com> | 2024-02-26 20:01:37 +0100 |
| commit | ddb6c818256ad817ba8b5e93e7868571739ae49c (patch) | |
| tree | e5105de6ec9ff2e90528033f51e950fd4dac2f30 | |
| parent | ef334847f61125e610e719f8dc1580d7f07e6c1d (diff) | |
Kernel:HAL: getting IDT to work...
Signed-off-by: Amlal El Mahrouss <amlalelmahrouss@icloud.com>
| -rw-r--r-- | .vscode/c_cpp_properties.json | 2 | ||||
| -rw-r--r-- | Private/HALKit/AMD64/HalCoreInterruptHandler.cpp | 27 | ||||
| -rw-r--r-- | Private/HALKit/AMD64/HalDebugOutput.cxx | 2 | ||||
| -rw-r--r-- | Private/HALKit/AMD64/HalInterruptRouting.asm | 68 | ||||
| -rw-r--r-- | Private/HALKit/AMD64/HalKernelMain.cxx | 12 | ||||
| -rw-r--r-- | Private/HALKit/AMD64/HalNewBoot.asm | 6 | ||||
| -rw-r--r-- | Private/HALKit/AMD64/HalPlatformAMD64.cpp | 6 | ||||
| -rw-r--r-- | Private/HALKit/AMD64/HalRoutines.s | 1 | ||||
| -rw-r--r-- | Private/KernelKit/DebugOutput.hpp | 6 | ||||
| -rw-r--r-- | Private/NewBoot/Source/BootMain.cxx | 6 | ||||
| -rw-r--r-- | Private/NewBoot/Source/makefile | 2 | ||||
| -rw-r--r-- | Private/Root/System/FileExplorerHome.html | 34 | ||||
| -rw-r--r-- | Private/Source/NewFS+IO.cxx | 9 | ||||
| -rw-r--r-- | Private/makefile | 4 |
14 files changed, 80 insertions, 105 deletions
diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index 86e71f01..da97a75e 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -6,7 +6,7 @@ "${workspaceFolder}/Private/**", "${workspaceFolder}/Private/NewBoot/*" ], - "defines": ["__HCORE__", "__HAVE_HCORE_APIS__"], + "defines": ["__HCORE__", "__HAVE_HCORE_APIS__", "__FSKIT_NEWFS__"], "cStandard": "c17", "cppStandard": "c++20", "compilerPath": "/opt/homebrew/bin/x86_64-elf-g++", diff --git a/Private/HALKit/AMD64/HalCoreInterruptHandler.cpp b/Private/HALKit/AMD64/HalCoreInterruptHandler.cpp index b161f1db..5a353b6e 100644 --- a/Private/HALKit/AMD64/HalCoreInterruptHandler.cpp +++ b/Private/HALKit/AMD64/HalCoreInterruptHandler.cpp @@ -33,9 +33,9 @@ static const char* kExceptionMessage[32] = { "Machine check", "Reserved", "Reserved", - "System Process Switch Issued", - "System was interrupted by kernel", - "System hang by kernel", + "Reserved", + "Reserved", + "Reservedl", "Reserved", "Reserved", "Reserved", @@ -46,24 +46,9 @@ static const char* kExceptionMessage[32] = { "Reserved", }; -extern "C" HCore::UIntPtr rt_handle_interrupts(HCore::UIntPtr& rsp) { - HCore::HAL::rt_cli(); - - HCore::HAL::StackFramePtr sf = (HCore::HAL::StackFramePtr)rsp; - - if (sf->IntNum == 0x21) { - rt_syscall_handle(sf); - } - - if (sf->IntNum < 32) { - HCore::kcout << "Exception:" << kExceptionMessage[sf->IntNum] << "\n"; - } - - if (sf->IntNum >= 40) HCore::HAL::Out8(0x20, 0x20); // ACK MASTER - - HCore::HAL::Out8(0xA0, 0x20); // ACK SLAVE - - HCore::HAL::rt_sti(); +/// @brief System call interrupt (like DOS and NT) +#define kKernelSyscallInterrupt (0x21) +EXTERN_C HCore::UIntPtr rt_handle_interrupts(HCore::UIntPtr rsp) { return rsp; } diff --git a/Private/HALKit/AMD64/HalDebugOutput.cxx b/Private/HALKit/AMD64/HalDebugOutput.cxx index 37beb912..6b2c772e 100644 --- a/Private/HALKit/AMD64/HalDebugOutput.cxx +++ b/Private/HALKit/AMD64/HalDebugOutput.cxx @@ -72,7 +72,7 @@ void ke_io_print(const char* bytes) { Detail::kState = kStateReady; } -TerminalDevice& TerminalDevice::Shared() noexcept { +TerminalDevice TerminalDevice::Shared() noexcept { static TerminalDevice out(HCore::ke_io_print, nullptr); return out; } diff --git a/Private/HALKit/AMD64/HalInterruptRouting.asm b/Private/HALKit/AMD64/HalInterruptRouting.asm index a1d532cb..33077e68 100644 --- a/Private/HALKit/AMD64/HalInterruptRouting.asm +++ b/Private/HALKit/AMD64/HalInterruptRouting.asm @@ -17,68 +17,30 @@ %macro IntExp 1 HCoreInterrupt%1: - push 1 + cli push %1 - jmp ke_handle_irq - iretq + call ke_handle_irq %endmacro %macro IntNormal 1 HCoreInterrupt%1: + cli push 0 push %1 - jmp ke_handle_irq - iretq + call ke_handle_irq %endmacro ; This file handles the core interrupt table ; Last edited 31/01/24 extern rt_handle_interrupts -global rt_install_idt global __EXEC_IVT section .text ke_handle_irq: - push rax - push rbx - push rcx - push rdx - push rsi - push rdi - push rbp - push r8 - push r9 - push r10 - push r11 - push r12 - push r13 - push r14 - push r15 - - mov rcx, rsp - call rt_handle_interrupts - add rsp, 8 - - pop r15 - pop r14 - pop r13 - pop r12 - pop r11 - pop r10 - pop r9 - pop r8 - pop rbp - pop rdi - pop rsi - pop rdx - pop rcx - pop rbx - pop rax - sti - retf + iretq __IVT: IntNormal 0 @@ -114,18 +76,18 @@ __IVT: IntExp 30 IntNormal 31 IntNormal 32 - - %assign i 33 - %rep 223 - IntNormal i - %assign i i+1 - %endrep - -section .data - + __EXEC_IVT: %assign i 0 - %rep 256 + %rep 32 IntDecl i %assign i i+1 %endrep + +section .text + +global PowerOnSelfTest + +PowerOnSelfTest: + int 0x21 + ret
\ No newline at end of file diff --git a/Private/HALKit/AMD64/HalKernelMain.cxx b/Private/HALKit/AMD64/HalKernelMain.cxx index 9cced576..686abe9e 100644 --- a/Private/HALKit/AMD64/HalKernelMain.cxx +++ b/Private/HALKit/AMD64/HalKernelMain.cxx @@ -25,12 +25,7 @@ extern "C" HCore::VoidPtr __EXEC_IVT; namespace Detail { using namespace HCore; -/// @brief kernel POST. -Void PowerOnSelfTest() { - kcout << "POST: Starting PowerOn-Self Test...\r\n"; - asm("int $0x21"); // dummy 21h interrupt. - kcout << "POST: Successfuly Done!\r\n"; -} +extern "C" void PowerOnSelfTest(); /** @brief Global descriptor table entry, either null, code or data. @@ -56,8 +51,7 @@ struct PACKED ALIGN(0x1000) HC_GDT final { EXTERN_C void RuntimeMain( HCore::HEL::HandoverInformationHeader* HandoverHeader) { - HCore::kcout << "HCoreKrnl: (R) Version 1.00, (C) MahroussLogic all rights " - "reserved.\n"; + /// Setup kernel globals. kKernelVirtualSize = HandoverHeader->f_VirtualSize; @@ -85,7 +79,7 @@ EXTERN_C void RuntimeMain( HCore::HAL::Register64 idtBase; idtBase.Base = (HCore::UIntPtr)__EXEC_IVT; - idtBase.Limit = 0x0FFF; + idtBase.Limit = kKernelMaxSystemCalls; HCore::HAL::IDTLoader idt; idt.Load(idtBase); diff --git a/Private/HALKit/AMD64/HalNewBoot.asm b/Private/HALKit/AMD64/HalNewBoot.asm index 8c7d7d1a..d84e1956 100644 --- a/Private/HALKit/AMD64/HalNewBoot.asm +++ b/Private/HALKit/AMD64/HalNewBoot.asm @@ -26,8 +26,6 @@ HandoverStart: dq Main section .text -[bits 64] - extern rt_load_gdt extern rt_load_ivt @@ -38,11 +36,7 @@ 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 diff --git a/Private/HALKit/AMD64/HalPlatformAMD64.cpp b/Private/HALKit/AMD64/HalPlatformAMD64.cpp index 80721aed..ab6de613 100644 --- a/Private/HALKit/AMD64/HalPlatformAMD64.cpp +++ b/Private/HALKit/AMD64/HalPlatformAMD64.cpp @@ -61,13 +61,7 @@ void IDTLoader::Load(Register64 &idt) { kRegIdt.Limit = sizeof(Detail::AMD64::InterruptDescriptorAMD64) * idt.Limit - 1; - kcout << "HCoreKrnl: Installing Interrupt vector...\n"; - rt_load_idt(kRegIdt); - - rt_sti(); - - 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 d809541f..80a6b122 100644 --- a/Private/HALKit/AMD64/HalRoutines.s +++ b/Private/HALKit/AMD64/HalRoutines.s @@ -20,6 +20,7 @@ rt_load_gdt: rt_load_idt: lidt (%rcx) + sti ret .section .text diff --git a/Private/KernelKit/DebugOutput.hpp b/Private/KernelKit/DebugOutput.hpp index 9a3db2e8..657e9a13 100644 --- a/Private/KernelKit/DebugOutput.hpp +++ b/Private/KernelKit/DebugOutput.hpp @@ -30,11 +30,11 @@ class TerminalDevice final : public DeviceInterface<const Char *> { HCORE_COPY_DEFAULT(TerminalDevice); - static TerminalDevice &Shared() noexcept; + static TerminalDevice Shared() noexcept; }; -inline TerminalDevice &EndLine() { - TerminalDevice &selfTerm = TerminalDevice::Shared(); +inline TerminalDevice EndLine() { + TerminalDevice selfTerm = TerminalDevice::Shared(); selfTerm << "\n"; return selfTerm; } diff --git a/Private/NewBoot/Source/BootMain.cxx b/Private/NewBoot/Source/BootMain.cxx index 170a7215..165919ef 100644 --- a/Private/NewBoot/Source/BootMain.cxx +++ b/Private/NewBoot/Source/BootMain.cxx @@ -24,7 +24,7 @@ #define kBootReadSize \ (sizeof(DosHeader) + sizeof(ExecHeader) + sizeof(ExecOptionalHeader)) -EXTERN_C EFI_API void Main(HEL::HandoverInformationHeader* HIH); +EXTERN_C EFI_API void RuntimeMain(HEL::HandoverInformationHeader* HIH); EFI_EXTERN_C EFI_API Int EfiMain(EfiHandlePtr ImageHandle, EfiSystemTable* SystemTable) { @@ -138,7 +138,9 @@ EFI_EXTERN_C EFI_API Int EfiMain(EfiHandlePtr ImageHandle, handoverHdrPtr->f_Version = 0x1011; handoverHdrPtr->f_Bootloader = 0x11; // Installer - Main(handoverHdrPtr); + writer.Write(L"HCoreLdr: Jumping to HCore...\r\n"); + + RuntimeMain(handoverHdrPtr); } else { handoverHdrPtr->f_Magic = 0xFF55DD; diff --git a/Private/NewBoot/Source/makefile b/Private/NewBoot/Source/makefile index 28efe7e5..7a8a555f 100644 --- a/Private/NewBoot/Source/makefile +++ b/Private/NewBoot/Source/makefile @@ -27,7 +27,7 @@ bootloader-amd64: .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 -d int + qemu-system-x86_64 -net none -smp 2 -m 8G -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/Root/System/FileExplorerHome.html b/Private/Root/System/FileExplorerHome.html new file mode 100644 index 00000000..9a7ab947 --- /dev/null +++ b/Private/Root/System/FileExplorerHome.html @@ -0,0 +1,34 @@ +<!DOCTYPE html> +<html lang="en"> +<head> + <meta charset="UTF-8"> + <meta name="viewport" content="width=device-width, initial-scale=1.0"> + <title>HCore WebTraveler</title> + + <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.4.1/dist/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous"> + +</head> +<body> + <script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script> + <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script> + <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.4.1/dist/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script> + + <nav class="navbar navbar-expand-lg bg-body-tertiary"> + <div class="container-fluid"> + <a class="navbar-brand" href="#">HCore</a> + <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation"> + <span class="navbar-toggler-icon"></span> + </button> + <div class="collapse navbar-collapse" id="navbarSupportedContent"> + <form action="https://www.google.com/search" method="get" name="searchform" target="_blank" class="d-flex" role="search"> + <input name="q" autocomplete="on" id="searchQuery" class="form-control me-2" type="text" required="required" placeholder="Search the web..." aria-label="Search"/> + </form> + </div> + </div> + </nav> + + <br> + <br> +</body> +</html> + diff --git a/Private/Source/NewFS+IO.cxx b/Private/Source/NewFS+IO.cxx index 2e6559c5..fefb2338 100644 --- a/Private/Source/NewFS+IO.cxx +++ b/Private/Source/NewFS+IO.cxx @@ -27,6 +27,15 @@ using namespace HCore; +enum { + kHCFSSubDriveA, + kHCFSSubDriveB, + kHCFSSubDriveC, + kHCFSSubDriveD, + kHCFSSubDriveInvalid, + kHCFSSubDriveCount, +}; + Int32 KeHCFSRead(Mountpoint* Mnt, DriveTraits& DrvTraits, Int32 DrvIndex) { if (!Mnt) return -1; diff --git a/Private/makefile b/Private/makefile index 5429a6d6..b49663fc 100644 --- a/Private/makefile +++ b/Private/makefile @@ -5,10 +5,10 @@ CC = x86_64-w64-mingw32-g++ LD = x86_64-w64-mingw32-ld -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)/ +CCFLAGS = -c -ffreestanding -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 +LDFLAGS = -e Main -shared --subsystem=17 -ffreestanding LDOBJ = $(wildcard Obj/*.obj) # This file is the kernel, responsible of task management, memory, drivers and more. |
