summaryrefslogtreecommitdiffhomepage
path: root/Private
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
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')
-rw-r--r--Private/EFIKit/EFI.hxx18
-rw-r--r--Private/HALKit/AMD64/Processor.cpp85
-rw-r--r--Private/KernelKit/ThreadLocalStorage.hxx28
-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
19 files changed, 149 insertions, 223 deletions
diff --git a/Private/EFIKit/EFI.hxx b/Private/EFIKit/EFI.hxx
index 2e7f4443..17f2da48 100644
--- a/Private/EFIKit/EFI.hxx
+++ b/Private/EFIKit/EFI.hxx
@@ -29,21 +29,21 @@ typedef UInt64 (*EfiTextString)(struct EfiSimpleTextOutputProtocol *self, const
typedef struct EfiSimpleTextOutputProtocol
{
UInt64 reset;
- EfiTextString output_string;
- UInt64 test_string;
- UInt64 query_mode;
- UInt64 set_mode;
- UInt64 set_attribute;
- UInt64 clear_screen;
- UInt64 set_cursor_position;
- UInt64 enable_cursor;
+ EfiTextString outputString;
+ UInt64 testString;
+ UInt64 queryMode;
+ UInt64 setMode;
+ UInt64 setAttribute;
+ UInt64 clearScreen;
+ UInt64 setCursorPosition;
+ UInt64 enableCursor;
UInt64 mode;
} EfiSimpleTextOutputProtocol;
typedef struct EfiSystemTable
{
EfiTableHeader hdr;
- Int16 *firmwareVendor;
+ wchar_t *firmwareVendor;
UInt32 firmwareRevision;
VoidPtr consoleInHandle;
UInt64 conIn;
diff --git a/Private/HALKit/AMD64/Processor.cpp b/Private/HALKit/AMD64/Processor.cpp
index 13732381..c70c7959 100644
--- a/Private/HALKit/AMD64/Processor.cpp
+++ b/Private/HALKit/AMD64/Processor.cpp
@@ -9,53 +9,64 @@
#include <HALKit/AMD64/Processor.hpp>
-namespace hCore::HAL {
- void out8(UInt16 port, UInt8 value) {
- asm volatile("outb %%al, %1" : : "a"(value), "Nd"(port) : "memory");
- }
+namespace hCore::HAL
+{
+void out8(UInt16 port, UInt8 value)
+{
+ asm volatile("outb %%al, %1" : : "a"(value), "Nd"(port) : "memory");
+}
- void out16(UInt16 port, UInt16 value) {
- asm volatile("outw %%ax, %1" : : "a"(value), "Nd"(port) : "memory");
- }
+void out16(UInt16 port, UInt16 value)
+{
+ asm volatile("outw %%ax, %1" : : "a"(value), "Nd"(port) : "memory");
+}
- void out32(UInt16 port, UInt32 value) {
- asm volatile("outl %%eax, %1" : : "a"(value), "Nd"(port) : "memory");
- }
+void out32(UInt16 port, UInt32 value)
+{
+ asm volatile("outl %%eax, %1" : : "a"(value), "Nd"(port) : "memory");
+}
- UInt8 in8(UInt16 port) {
- UInt8 value = 0UL;
- asm volatile("inb %1, %%al" : "=a"(value) : "Nd"(port) : "memory");
+UInt8 in8(UInt16 port)
+{
+ UInt8 value = 0UL;
+ asm volatile("inb %1, %%al" : "=a"(value) : "Nd"(port) : "memory");
- return value;
- }
+ return value;
+}
- UInt16 in16(UInt16 port) {
- UInt16 value = 0UL;
- asm volatile("inw %1, %%ax" : "=a"(value) : "Nd"(port) : "memory");
+UInt16 in16(UInt16 port)
+{
+ UInt16 value = 0UL;
+ asm volatile("inw %1, %%ax" : "=a"(value) : "Nd"(port) : "memory");
- return value;
- }
+ return value;
+}
- UInt32 in32(UInt16 port) {
- UInt32 value = 0UL;
- asm volatile("inl %1, %%eax" : "=a"(value) : "Nd"(port) : "memory");
+UInt32 in32(UInt16 port)
+{
+ UInt32 value = 0UL;
+ asm volatile("inl %1, %%eax" : "=a"(value) : "Nd"(port) : "memory");
- return value;
- }
+ return value;
+}
- void rt_halt() {
- asm volatile("hlt");
- }
+void rt_halt()
+{
+ asm volatile("hlt");
+}
- void rt_cli() {
- asm volatile("cli");
- }
+void rt_cli()
+{
+ asm volatile("cli");
+}
- void rt_sti() {
- asm volatile("sti");
- }
+void rt_sti()
+{
+ asm volatile("sti");
+}
- void rt_cld() {
- asm volatile("cld");
- }
+void rt_cld()
+{
+ asm volatile("cld");
+}
} // namespace hCore::HAL
diff --git a/Private/KernelKit/ThreadLocalStorage.hxx b/Private/KernelKit/ThreadLocalStorage.hxx
index afd0afb3..8fc8b9dd 100644
--- a/Private/KernelKit/ThreadLocalStorage.hxx
+++ b/Private/KernelKit/ThreadLocalStorage.hxx
@@ -18,14 +18,11 @@
#define kCookieMag1 'C'
#define kCookieMag2 'o'
-template <typename T>
-T* hcore_tls_new_ptr(void);
+template <typename T> T *hcore_tls_new_ptr(void);
-template <typename T>
-bool hcore_tls_delete_ptr(T* ptr);
+template <typename T> bool hcore_tls_delete_ptr(T *ptr);
-template <typename T, typename... Args>
-T* hcore_tls_new_class(Args&&... args);
+template <typename T, typename... Args> T *hcore_tls_new_class(Args &&...args);
typedef char rt_cookie_type[3];
@@ -33,19 +30,22 @@ typedef char rt_cookie_type[3];
/// Located in GS on AMD64, Virtual Address 0x10000 (64x0, 32x0, ARM64)
struct ThreadInformationBlock final
{
- hCore::Char Name[255]; // Module Name
- hCore::UIntPtr StartCode; // Start Address
- hCore::UIntPtr StartData; // Allocation Heap
+ hCore::Char Name[255]; // Module Name
+ hCore::UIntPtr StartCode; // Start Address
+ hCore::UIntPtr StartData; // Allocation Heap
hCore::UIntPtr StartStack; // Stack Pointer.
- hCore::Int32 Arch; // Architecture and/or platform.
- rt_cookie_type Cookie; // Not shown in public header, this is the way we tell something went wrong.
+ hCore::Int32 Arch; // Architecture and/or platform.
+ rt_cookie_type Cookie; // Not shown in public header, this is the way we tell something went wrong.
};
-//! @brief Cookie Sanity check.
-hCore::Boolean hcore_tls_check(ThreadInformationBlock* ptr);
+/// @brief TLS install TIB
+extern void rt_install_tib(ThreadInformationBlock *pTib);
+
+///! @brief Cookie Sanity check.
+hCore::Boolean hcore_tls_check(ThreadInformationBlock *ptr);
#include "ThreadLocalStorage.inl"
-// last rev 1/27/24
+// last rev 1/29/24
#endif /* ifndef _KERNELKIT_TLS_HPP */
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