summaryrefslogtreecommitdiffhomepage
path: root/Private/NewBoot
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-01-29 09:55:05 +0100
committerAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-01-29 09:55:44 +0100
commit2529c8722d6d3491a3e19aa728f4bfce099bcc91 (patch)
tree116a1cfb461884b33c6805bde6fcfe868ae5e491 /Private/NewBoot
parent202db65935d71650600de9de59e4950ad047a122 (diff)
Kernel: Improve BootKit and EFIKit.
TODO: Add File Protocol support and Pool support for EFIKit. Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'Private/NewBoot')
-rw-r--r--Private/NewBoot/BootKit/Boot.hxx (renamed from Private/NewBoot/BootKit/Boot.hpp)2
-rw-r--r--Private/NewBoot/BootKit/EPM.hxx (renamed from Private/NewBoot/Source/HEL/AMD64/PartitionMap.hxx)2
-rw-r--r--Private/NewBoot/BootKit/Processor.hxx24
-rw-r--r--Private/NewBoot/BootKit/Protocol.hxx (renamed from Private/NewBoot/Source/HEL/AMD64/Protocol.hxx)0
-rw-r--r--Private/NewBoot/CxxKit/__cxxkit_unwind.cxx11
-rw-r--r--Private/NewBoot/CxxRuntime/manifest.json (renamed from Private/NewBoot/CxxKit/manifest.json)0
-rw-r--r--Private/NewBoot/CxxRuntime/unwind.cxx11
-rw-r--r--Private/NewBoot/Source/CDROM/MAHROUSS/.gitkeep0
-rw-r--r--Private/NewBoot/Source/HEL/AMD64/BIOSAllocApi.inc40
-rw-r--r--Private/NewBoot/Source/HEL/AMD64/BIOSApiGdt.inc36
-rw-r--r--Private/NewBoot/Source/HEL/AMD64/BIOSRuntime.cxx10
-rw-r--r--Private/NewBoot/Source/HEL/AMD64/BIOSRuntime0.asm50
-rw-r--r--Private/NewBoot/Source/HEL/AMD64/Boot.cxx (renamed from Private/NewBoot/Source/HEL/AMD64/BootAMD64.cxx)5
-rw-r--r--Private/NewBoot/Source/HEL/AMD64/EfiMain.cxx12
-rw-r--r--Private/NewBoot/Source/HEL/AMD64/Processor.cxx36
-rw-r--r--Private/NewBoot/Source/makefile2
16 files changed, 78 insertions, 163 deletions
diff --git a/Private/NewBoot/BootKit/Boot.hpp b/Private/NewBoot/BootKit/Boot.hxx
index 6df2e08f..07148702 100644
--- a/Private/NewBoot/BootKit/Boot.hpp
+++ b/Private/NewBoot/BootKit/Boot.hxx
@@ -66,4 +66,4 @@ enum
#define BK_START_KERNEL (0x10000000)
-long long int BStrLen(const char *ptr);
+hCore::SizeT BStrLen(const char *ptr);
diff --git a/Private/NewBoot/Source/HEL/AMD64/PartitionMap.hxx b/Private/NewBoot/BootKit/EPM.hxx
index 490cc41a..803d500c 100644
--- a/Private/NewBoot/Source/HEL/AMD64/PartitionMap.hxx
+++ b/Private/NewBoot/BootKit/EPM.hxx
@@ -7,4 +7,6 @@
* ========================================================
*/
+#pragma once
+
#include <HALKit/EPM.hxx>
diff --git a/Private/NewBoot/BootKit/Processor.hxx b/Private/NewBoot/BootKit/Processor.hxx
new file mode 100644
index 00000000..d4143094
--- /dev/null
+++ b/Private/NewBoot/BootKit/Processor.hxx
@@ -0,0 +1,24 @@
+/*
+ * ========================================================
+ *
+ * h-core
+ * Copyright 2024, Mahrouss Logic, all rights reserved.
+ *
+ * ========================================================
+ */
+
+#pragma once
+
+/**
+ @file Processor.hxx
+ @brief Processor specific code.
+*/
+
+#ifdef __x86_64__
+
+extern "C" void rt_halt();
+extern "C" void rt_cli();
+extern "C" void rt_sti();
+extern "C" void rt_cld();
+
+#endif /* ifdef __x86_64__ */
diff --git a/Private/NewBoot/Source/HEL/AMD64/Protocol.hxx b/Private/NewBoot/BootKit/Protocol.hxx
index 7e292c7d..7e292c7d 100644
--- a/Private/NewBoot/Source/HEL/AMD64/Protocol.hxx
+++ b/Private/NewBoot/BootKit/Protocol.hxx
diff --git a/Private/NewBoot/CxxKit/__cxxkit_unwind.cxx b/Private/NewBoot/CxxKit/__cxxkit_unwind.cxx
deleted file mode 100644
index 477b6302..00000000
--- a/Private/NewBoot/CxxKit/__cxxkit_unwind.cxx
+++ /dev/null
@@ -1,11 +0,0 @@
-namespace cxxkit
-{
- ///! @brief C++ ABI unwinding
- ///! finis array (r1)
- ///! n of finis (r2)
- void __unwind(void(**finis)(void), int cnt)
- {
- for (int i = 0; i < cnt; ++i)
- (finis[i])();
- }
-}
diff --git a/Private/NewBoot/CxxKit/manifest.json b/Private/NewBoot/CxxRuntime/manifest.json
index 42b5d166..42b5d166 100644
--- a/Private/NewBoot/CxxKit/manifest.json
+++ b/Private/NewBoot/CxxRuntime/manifest.json
diff --git a/Private/NewBoot/CxxRuntime/unwind.cxx b/Private/NewBoot/CxxRuntime/unwind.cxx
new file mode 100644
index 00000000..acfc0b6b
--- /dev/null
+++ b/Private/NewBoot/CxxRuntime/unwind.cxx
@@ -0,0 +1,11 @@
+namespace cxxkit
+{
+///! @brief C++ ABI unwinding
+///! finis array (r1)
+///! n of finis (r2)
+extern "C" void __unwind(void (**finis)(void), int cnt)
+{
+ for (int i = 0; i < cnt; ++i)
+ (finis[i])();
+}
+} // namespace cxxkit
diff --git a/Private/NewBoot/Source/CDROM/MAHROUSS/.gitkeep b/Private/NewBoot/Source/CDROM/MAHROUSS/.gitkeep
deleted file mode 100644
index e69de29b..00000000
--- a/Private/NewBoot/Source/CDROM/MAHROUSS/.gitkeep
+++ /dev/null
diff --git a/Private/NewBoot/Source/HEL/AMD64/BIOSAllocApi.inc b/Private/NewBoot/Source/HEL/AMD64/BIOSAllocApi.inc
deleted file mode 100644
index a43881fa..00000000
--- a/Private/NewBoot/Source/HEL/AMD64/BIOSAllocApi.inc
+++ /dev/null
@@ -1,40 +0,0 @@
-;; COPYRIGHT Mahrouss Logic, all rights reserved
-
-bits 32
-
-[global __BIOSLoadRegister]
-[global __BIOSAlloc]
-
-__BIOSLoadRegister:
- cmp [ebp - 4], 0
- jmp __BIOSLoadGDT
- ret
-__BIOSLoadGDT:
- lgdt [ebp - 8]
- ret
-
-;; This memory resides in the BIOS Memory Region BMR (0x9000-(0x9000 + 0x1000))
-;; It contains bootloader data.
-
-__BIOSAlloc:
- push ebp
- mov ebp, esp
- mov eax, __bios_lookup_table
-__BIOSAllocLoop:
- cmp eax, __end_bios_lookup_table
- jne __BIOSAllocDone
- add eax, 4
- jmp $
-__BIOSAllocDone:
- cmp eax, 0
- je __BIOSAllocLoop
- add esp, 12
- mov esp, ebp
- pop ebp
- ret
-
-;; Allocation table.
-
-__bios_lookup_table:
- resb 8096 * 4
-__end_bios_lookup_table:
diff --git a/Private/NewBoot/Source/HEL/AMD64/BIOSApiGdt.inc b/Private/NewBoot/Source/HEL/AMD64/BIOSApiGdt.inc
deleted file mode 100644
index be7a97e3..00000000
--- a/Private/NewBoot/Source/HEL/AMD64/BIOSApiGdt.inc
+++ /dev/null
@@ -1,36 +0,0 @@
-[BITS 32]
-
-NewBootGdtRegister:
- dw NewBootGdtEnd - NewBootGdt - 1
- dq NewBootGdt
-
-[BITS 32]
-
-NewBootGdt:
- ;; Entry 0x0: Null descriptor
- dd 0x0
- dd 0x0
- ;; Entry 0x8: Code segment
-NewBootGdtCode:
- dw 0xffff ; Limit
- dw 0x0000 ; Base 15:00
- db 0x00 ; Base 23:16
- dw 0xcf9a ; Flags / Limit / Type [F,L,F,Type]
- db 0x00 ; Base 32:24
- ;; Entry 0x10: Data segment
-NewBootGdtData:
- dw 0xffff ; Limit
- dw 0x0000 ; Base 15:00
- db 0x00 ; Base 23:16
- dw 0xcf92 ; Flags / Limit / Type [F,L,F,Type]
- db 0x00 ;Base 32:24
- ;; Entry 0x18: GS Data segment
- dw 0x0100 ; Limit
- dw 0x1000 ; Base 15:00
- db 0x00 ; Base 23:16
- dw 0x4092 ; Flags / Limit / Type [F,L,F,Type]
- db 0x00 ; Base 32:24
-NewBootGdtEnd:
-
-NB_CODE: db 0x8
-NB_DATA: db 0x10 \ No newline at end of file
diff --git a/Private/NewBoot/Source/HEL/AMD64/BIOSRuntime.cxx b/Private/NewBoot/Source/HEL/AMD64/BIOSRuntime.cxx
deleted file mode 100644
index 1cc249ee..00000000
--- a/Private/NewBoot/Source/HEL/AMD64/BIOSRuntime.cxx
+++ /dev/null
@@ -1,10 +0,0 @@
-/*
- * Copyright 2024 Mahrouss Logic, all rights reserved
- */
-
-#include <BootKit/Boot.hpp>
-
-// unused now, used to be in dev;
-#ifdef __BIOS__
-extern "C" char __runtime_stack[4096] = {0};
-#endif // ifdef __BIOS__
diff --git a/Private/NewBoot/Source/HEL/AMD64/BIOSRuntime0.asm b/Private/NewBoot/Source/HEL/AMD64/BIOSRuntime0.asm
deleted file mode 100644
index f5ba44ec..00000000
--- a/Private/NewBoot/Source/HEL/AMD64/BIOSRuntime0.asm
+++ /dev/null
@@ -1,50 +0,0 @@
-;; Copyright 2024 Mahrouss Logic, all rights reserved
-
-extern __runtime_stack
-global NBRuntimeZero
-
-bits 16
-
-NBRuntimeZero:
- cli
-
- lgdt [NewBootGdtRegister]
-
- mov ebx, cr0
- or ebx, 1
- mov cr0, ebx
-
- jmp 0x8:NBProtectedMode
-
-%include "BIOSApiGdt.inc"
-
-[bits 32]
-
-NBMasterPartitionTable:
- resb 32
- resw 1
- resw 1
- resw 1
- resb 211
-NBMasterPartitionTableEnd:
-
-NBProtectedMode:
- mov ax, 0x10 ; 0x10 is a stand-in for your data segment
- mov ds, ax
- mov es, ax
- mov fs, ax
- mov gs, ax
- mov ss, ax
-
- mov esp, __runtime_stack
- jmp 0x8000000
-
-NBLoopOne:
- cli
- hlt
- jmp $
-
-NBMasterBootRecord:
- times 510 - ($-$$) db 0
- dw 0xAA55
-NBEndMasterBootRecord: \ No newline at end of file
diff --git a/Private/NewBoot/Source/HEL/AMD64/BootAMD64.cxx b/Private/NewBoot/Source/HEL/AMD64/Boot.cxx
index 39f8761e..96c30c12 100644
--- a/Private/NewBoot/Source/HEL/AMD64/BootAMD64.cxx
+++ b/Private/NewBoot/Source/HEL/AMD64/Boot.cxx
@@ -7,13 +7,14 @@
* ========================================================
*/
-#include <BootKit/Boot.hpp>
+#include <BootKit/Boot.hxx>
constexpr hCore::UInt32 kVGABaseAddress = 0xb8000;
-long long int BStrLen(const char *ptr)
+hCore::SizeT BStrLen(const char *ptr)
{
long long int cnt = 0;
+
while (*ptr != 0)
{
++ptr;
diff --git a/Private/NewBoot/Source/HEL/AMD64/EfiMain.cxx b/Private/NewBoot/Source/HEL/AMD64/EfiMain.cxx
index d8a26acd..9b00a6a9 100644
--- a/Private/NewBoot/Source/HEL/AMD64/EfiMain.cxx
+++ b/Private/NewBoot/Source/HEL/AMD64/EfiMain.cxx
@@ -7,11 +7,19 @@
* ========================================================
*/
-#include "Protocol.hxx"
+#include <BootKit/Boot.hxx>
+#include <BootKit/Processor.hxx>
+#include <BootKit/Protocol.hxx>
extern "C" int EfiMain(void *ImageHandle, EfiSystemTable *SystemTable)
{
- SystemTable->conOut->output_string(SystemTable->conOut, L"HCORELDR: Preparing Handover structure...\r\n");
+ SystemTable->conOut->outputString(SystemTable->conOut, L"HCoreLdr: Starting HCore...\r\n");
+
+ while (true)
+ {
+ rt_cli();
+ rt_halt();
+ }
return 0;
}
diff --git a/Private/NewBoot/Source/HEL/AMD64/Processor.cxx b/Private/NewBoot/Source/HEL/AMD64/Processor.cxx
index d2a0c15f..f1f9b617 100644
--- a/Private/NewBoot/Source/HEL/AMD64/Processor.cxx
+++ b/Private/NewBoot/Source/HEL/AMD64/Processor.cxx
@@ -1,11 +1,11 @@
/*
-* ========================================================
-*
-* NewBoot
-* Copyright 2024 Mahrouss Logic, all rights reserved.
-*
-* ========================================================
-*/
+ * ========================================================
+ *
+ * NewBoot
+ * Copyright 2024 Mahrouss Logic, all rights reserved.
+ *
+ * ========================================================
+ */
/*
*
@@ -14,10 +14,24 @@
*
*/
-extern "C" void rt_halt(void) { asm volatile("hlt"); }
+#include <BootKit/Processor.hxx>
+
+extern "C" void rt_halt(void)
+{
+ asm volatile("hlt");
+}
-extern "C" void rt_cli(void) { asm volatile("cli"); }
+extern "C" void rt_cli(void)
+{
+ asm volatile("cli");
+}
-extern "C" void rt_sti(void) { asm volatile("sti"); }
+extern "C" void rt_sti(void)
+{
+ asm volatile("sti");
+}
-extern "C" void rt_cld(void) { asm volatile("cld"); }
+extern "C" void rt_cld(void)
+{
+ asm volatile("cld");
+}
diff --git a/Private/NewBoot/Source/makefile b/Private/NewBoot/Source/makefile
index c5c382ac..b84f4425 100644
--- a/Private/NewBoot/Source/makefile
+++ b/Private/NewBoot/Source/makefile
@@ -12,9 +12,11 @@ arch-amd64:
$(CC_GNU) $(FLAG_GNU) HEL/AMD64/*.cxx
$(LD_GNU) *.o -e efi_main -filealign:16 -shared --subsystem=10 -ffreestanding -o HCORELDR.EXE
cp HCORELDR.EXE CDROM/EFI/BOOT/BOOTX64.EFI
+ cp -r ../../Root ./CDROM/MAHROUSS
.PHONY: efi-debug
efi-debug:
+ wget https://retrage.github.io/edk2-nightly/bin/DEBUGX64_OVMF.fd -O OVMF.fd
qemu-system-x86_64 -bios OVMF.fd -net none -drive file=fat:rw:CDROM,format=raw -d int
.PHONY: clean