summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-01-28 14:23:37 +0100
committerAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-01-28 14:23:37 +0100
commitb177e9c4c954170b590d777fe77442ff3a0cd8d7 (patch)
tree7282e804cabc35d8b905aeb45a94c88cffd982fe
parent89326d7a262b48701cec9dba71b43235d18c6e30 (diff)
HEL: Improve UEFI support, will add a EPM wrapper over it.
EPM will be used to load the Operating System and it's partitions. It was originally meant for kickStart, but we'll it also here. Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
-rw-r--r--Private/NewBoot/Source/HEL/AMD64/BIOSRuntime.cxx10
-rw-r--r--Private/NewBoot/Source/HEL/AMD64/EFIApi.hxx13
-rw-r--r--Private/NewBoot/Source/HEL/AMD64/EFIApiCrt0.cxx3
-rw-r--r--Private/NewBoot/Source/HEL/AMD64/EfiApi.cxx51
-rw-r--r--Private/NewBoot/Source/HEL/AMD64/PartitionMap.hxx93
-rw-r--r--Private/NewBoot/Source/MPT/API.hxx4
-rw-r--r--Private/NewBoot/Source/MPT/Detail.hxx55
-rw-r--r--Private/NewBoot/Source/Start.cxx25
-rw-r--r--Private/NewBoot/Source/makefile17
-rw-r--r--Private/Root/Boot/manifest.json4
-rw-r--r--Private/makefile12
-rw-r--r--Public/SDK/ZipKit/Makefile5
12 files changed, 217 insertions, 75 deletions
diff --git a/Private/NewBoot/Source/HEL/AMD64/BIOSRuntime.cxx b/Private/NewBoot/Source/HEL/AMD64/BIOSRuntime.cxx
index a9cb4fe4..1cc249ee 100644
--- a/Private/NewBoot/Source/HEL/AMD64/BIOSRuntime.cxx
+++ b/Private/NewBoot/Source/HEL/AMD64/BIOSRuntime.cxx
@@ -1,8 +1,10 @@
/*
-* Copyright 2024 Mahrouss Logic, all rights reserved
-*/
+ * Copyright 2024 Mahrouss Logic, all rights reserved
+ */
#include <BootKit/Boot.hpp>
-#include "ATA.hxx"
-extern "C" char __runtime_stack[4096] = { 0 };
+// 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/EFIApi.hxx b/Private/NewBoot/Source/HEL/AMD64/EFIApi.hxx
index 6fac74a9..d6bde7aa 100644
--- a/Private/NewBoot/Source/HEL/AMD64/EFIApi.hxx
+++ b/Private/NewBoot/Source/HEL/AMD64/EFIApi.hxx
@@ -18,8 +18,19 @@ void newboot_mount_drive(const char *name);
void newboot_boot_file(const char *path);
/// @brief initializes epm library.
-void newboot_init_epm(void);
+void newboot_init_epm(EFI_HANDLE pImage);
/// @brief frees the epm library, called when newboot_auto_mount/newboot_boot_file
/// succeeds.
void newboot_fini_epm(void);
+
+namespace HEL
+{
+struct HandoverHeader final
+{
+ int magic;
+ int type;
+ int arch;
+ // WIP
+};
+} // namespace HEL
diff --git a/Private/NewBoot/Source/HEL/AMD64/EFIApiCrt0.cxx b/Private/NewBoot/Source/HEL/AMD64/EFIApiCrt0.cxx
index 916a546d..656326a9 100644
--- a/Private/NewBoot/Source/HEL/AMD64/EFIApiCrt0.cxx
+++ b/Private/NewBoot/Source/HEL/AMD64/EFIApiCrt0.cxx
@@ -19,11 +19,10 @@ EFI_STATUS main(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
Print(L"NewBoot: Booting from EPM...\r\n");
// init
- newboot_init_epm();
+ newboot_init_epm(ImageHandle);
//! these two should execute a program if any on it.
newboot_mount_drive("epm:///system/");
- newboot_mount_drive("epm:///efi/");
// bye
newboot_fini_epm();
diff --git a/Private/NewBoot/Source/HEL/AMD64/EfiApi.cxx b/Private/NewBoot/Source/HEL/AMD64/EfiApi.cxx
new file mode 100644
index 00000000..1728f14b
--- /dev/null
+++ b/Private/NewBoot/Source/HEL/AMD64/EfiApi.cxx
@@ -0,0 +1,51 @@
+/*
+ * ========================================================
+ *
+ * NewBoot
+ * Copyright 2024 Mahrouss Logic, all rights reserved.
+ *
+ * ========================================================
+ */
+
+#include "EFIApi.hxx"
+#include "PartitionMap.hxx"
+
+EFI_FILE_HANDLE kVolume = nullptr;
+BootBlockType *kBootFolder = nullptr;
+PartitionBlockType *kPartitionFolder = nullptr;
+
+void newboot_init_epm(EFI_HANDLE image)
+{
+ EFI_LOADED_IMAGE *loaded_image = NULL; /* image interface */
+ EFI_GUID lipGuid = EFI_LOADED_IMAGE_PROTOCOL_GUID; /* image interface GUID */
+ EFI_FILE_IO_INTERFACE *IOVolume; /* file system interface */
+ EFI_GUID fsGuid = EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID; /* file system interface GUID */
+ EFI_FILE_HANDLE Volume; /* the volume's interface */
+
+ /* get the loaded image protocol interface for our "image" */
+ uefi_call_wrapper((void *)BS->HandleProtocol, 3, image, &lipGuid, (void **)&loaded_image);
+ /* get the volume handle */
+ uefi_call_wrapper((void *)BS->HandleProtocol, 3, loaded_image->DeviceHandle, &fsGuid, (VOID *)&IOVolume);
+ uefi_call_wrapper((void *)IOVolume->OpenVolume, 2, IOVolume, &Volume);
+
+ kVolume = Volume;
+
+ kBootFolder = (BootBlockType *)AllocatePool(sizeof(BootBlockType));
+ kPartitionFolder = (PartitionBlockType *)AllocatePool(sizeof(PartitionBlockType));
+}
+
+/**
+ * @brief fini the EPM library.
+ * Cleans up the memory we claimed and sets the fields to null pointer.
+ */
+void newboot_fini_epm()
+{
+ uefi_call_wrapper((void *)kVolume->Close, 1, kVolume);
+ kVolume = nullptr;
+
+ FreePool(kBootFolder);
+ kBootFolder = nullptr;
+
+ FreePool(kPartitionFolder);
+ kPartitionFolder = nullptr;
+}
diff --git a/Private/NewBoot/Source/HEL/AMD64/PartitionMap.hxx b/Private/NewBoot/Source/HEL/AMD64/PartitionMap.hxx
new file mode 100644
index 00000000..69914b36
--- /dev/null
+++ b/Private/NewBoot/Source/HEL/AMD64/PartitionMap.hxx
@@ -0,0 +1,93 @@
+/*
+ * ========================================================
+ *
+ * h-core
+ * Copyright 2024, Mahrouss Logic, all rights reserved.
+ *
+ * ========================================================
+ */
+
+#ifndef __PARTITION_MAP_H__
+#define __PARTITION_MAP_H__
+
+#define UUID_LEN 37
+
+/* the first 512 > x > 1024 bytes of a disk contains this headers. */
+
+/**
+ * @brief The EPM bootloader block.
+ * boot code info
+ */
+struct boot_block
+{
+ char magic[4];
+ char name[32];
+ char uuid[UUID_LEN];
+ int version;
+ long long int num_blocks;
+ long long int sector_sz;
+ long long int sector_start;
+};
+
+/**
+ * @brief The EPM partition block.
+ * used to explain a partition inside a media.
+ */
+struct part_block
+{
+ char name[32];
+ int magic;
+ long long int sector_end;
+ long long int sector_sz;
+ long long int sector_start;
+ short type;
+ int version;
+ char fs[16]; /* ffs_2 */
+};
+
+typedef struct part_block part_block_t;
+typedef struct boot_block boot_block_t;
+
+/* @brief AMD64 magic for EPM */
+#define EPM_MAGIC_X86 "EPMAM"
+
+/* @brief RISC-V magic for EPM */
+#define EPM_MAGIC_RV "EPMRV"
+
+/* @brief ARM magic for EPM */
+#define EPM_MAGIC_ARM "EPMAR"
+
+/* @brief 64x0 magic for EPM */
+#define EPM_MAGIC_64x0 "EPM64"
+
+/* @brief 32x0 magic for EPM */
+#define EPM_MAGIC_32x0 "EPM32"
+
+#define EPM_MAX_BLKS 128
+
+#define EPM_BOOT_BLK_SZ sizeof(struct boot_block)
+#define EPM_PART_BLK_SZ sizeof(struct part_block)
+
+//! version types.
+//! use in boot block version field.
+
+enum
+{
+ EPM_MPUNIX = 0xcf,
+ EPM_LINUX = 0x8f,
+ EPM_BSD = 0x9f,
+ EPM_HCORE = 0x1f,
+};
+
+/// END SPECS
+
+typedef boot_block_t BootBlockType;
+typedef part_block_t PartitionBlockType;
+
+#ifdef __x86_64__
+#define PM_MAG EPM_MAGIC_X86
+#else
+#define PM_MAG "?"
+#endif
+
+#endif // ifndef __PARTITION_MAP_H__
diff --git a/Private/NewBoot/Source/MPT/API.hxx b/Private/NewBoot/Source/MPT/API.hxx
index 83de5365..5958f1c3 100644
--- a/Private/NewBoot/Source/MPT/API.hxx
+++ b/Private/NewBoot/Source/MPT/API.hxx
@@ -13,5 +13,5 @@
extern "C" int init_ata_mpt(void);
#endif // __MPT_NEED_ATA_SUPPORT
-#include <MPT/Detail.hxx>
-#include <MPT/MPT.hxx> \ No newline at end of file
+#include "Detail.hxx"
+#include "MPT.hxx"
diff --git a/Private/NewBoot/Source/MPT/Detail.hxx b/Private/NewBoot/Source/MPT/Detail.hxx
index 002f5595..420387d1 100644
--- a/Private/NewBoot/Source/MPT/Detail.hxx
+++ b/Private/NewBoot/Source/MPT/Detail.hxx
@@ -1,40 +1,45 @@
/*
-* ========================================================
-*
-* NewBoot
-* Copyright 2024 Mahrouss Logic, all rights reserved.
-*
-* ========================================================
-*/
+ * ========================================================
+ *
+ * NewBoot
+ * Copyright 2024 Mahrouss Logic, all rights reserved.
+ *
+ * ========================================================
+ */
#pragma once
namespace detail
{
- inline void assert_expr(bool expr, const char* str_expr) const
- {
- if (!expr)
- {
- detail::panic("assertion failed!", str_expr);
- detail::hang();
- }
- }
+inline void hang();
+inline void panic(const char *msg, const char *expr)
+{
+}
- inline void hang() const
+inline void assert_expr(bool expr, const char *str_expr)
+{
+ if (!expr)
{
- while (1) {}
+ detail::panic("assertion failed!", str_expr);
+ detail::hang();
}
+}
- enum
+inline void hang()
+{
+ while (1)
{
- okay = 1,
- failed = 0,
- };
+ }
}
+enum
+{
+ okay = 1,
+ failed = 0,
+};
+} // namespace detail
+
#ifdef assert
-# undef assert
-# define assert(expr) detail::assert_expr(expr, #expr)
+#undef assert
+#define assert(expr) detail::assert_expr(expr, #expr)
#endif // ifdef assert
-
-
diff --git a/Private/NewBoot/Source/Start.cxx b/Private/NewBoot/Source/Start.cxx
deleted file mode 100644
index eed20034..00000000
--- a/Private/NewBoot/Source/Start.cxx
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * ========================================================
- *
- * NewBoot
- * Copyright 2024 Mahrouss Logic, all rights reserved.
- *
- * ========================================================
- */
-
-#define __MPT_NEED_ATA_SUPPORT 1
-
-#include <BootKit/Boot.hpp>
-#include <MPT/API.hxx>
-
-extern "C" void Main(void)
-{
-#ifdef __DBG__
-
- BKTextWriter writer;
- writer.WriteString("Booting Kernel...", kBlack, kWhite, 0, 0);
-
-#endif
-
- init_ata_mpt();
-}
diff --git a/Private/NewBoot/Source/makefile b/Private/NewBoot/Source/makefile
index 911cdfef..75993507 100644
--- a/Private/NewBoot/Source/makefile
+++ b/Private/NewBoot/Source/makefile
@@ -1,18 +1,15 @@
-CC=gcc
-CCFLAGS=-I../ -I../../ -std=c++20 -ffreestanding -nostdlib -c
+# (C) Mahrouss Logic, 2024, all rights reserved.
-.PHONY: arch-arc
-arch-arc:
- ${CC} ${CCFLAGS} Start.cxx
-
-CC_GNU=x86_64-elf-gcc
+CC_GNU=x86_64-elf-g++
LD_GNU=x86_64-elf-ld
-FLAG_GNU=-I../ -I../../../efiSDK/inc -c -ffreestanding -fno-rtti -fno-exceptions -std=c++20 -D__HAVE_HCORE_APIS__ -D__hCore__ -I./ -I$(HOME)/
+OBJCOPY_GNU=x86_64-elf-objcopy
+FLAG_GNU=-I../ -I../../ -I../../efiSDK/inc -I./ -c -fPIC -ffreestanding -fno-rtti -fno-exceptions -std=c++20 -D__HAVE_HCORE_APIS__ -D__hCore__ -I./ -I$(HOME)/
.PHONY: arch-amd64
arch-amd64:
- $(CC_GNU) $(FLAG_GNU) -D__DBG__ HEL/AMD64/BootAMD64.cxx *.cxx
- $(LD_GNU) *.o -e Main --oformat binary -o BootloaderStage2.bin
+ $(CC_GNU) $(FLAG_GNU) -D__DBG__ HEL/AMD64/*.cxx
+ $(LD_GNU) *.o -e Main -shared -o HCORELDR.ELF
+ $(OBJCOPY_GNU) -j .text -j .sdata -j .data -j .dynamic -j .dynsym -j .rel -j .rela -j .rel.* -j .rela.* -j .reloc --target efi-app-x86_64 --subsystem=10 HCORELDR.ELF HCORELDR.EFI
.PHONY: clean
clean:
diff --git a/Private/Root/Boot/manifest.json b/Private/Root/Boot/manifest.json
deleted file mode 100644
index 60f27421..00000000
--- a/Private/Root/Boot/manifest.json
+++ /dev/null
@@ -1,4 +0,0 @@
-{
- "pluginName": "h-core",
- "kernelPath": "/System/hKernel.elf"
-} \ No newline at end of file
diff --git a/Private/makefile b/Private/makefile
index aa0631b1..c3e12823 100644
--- a/Private/makefile
+++ b/Private/makefile
@@ -5,14 +5,18 @@ ASM = nasm
ASMFLAGS = -f elf64
# This file is the kernel, responsible of task management, memory, drivers and more.
-KERNEL = hKernel.elf
+KERNEL = hKernel.efi
# The kernel entrypoint
SCRIPT = --script=Linker/AMD64.ld
-# we want a flat binary
+# we want a flat binary
FMT = elf64
+.PHONY: kernel-no
+kernel-no:
+ @echo "Use make all instead."
+
.PHONY: kernel-build
kernel-build:
$(CC) $(CCFLAGS) Source/*.cxx HALKit/AMD64/PCI/*.cpp Source/Network/*.cpp\
@@ -21,9 +25,13 @@ kernel-build:
$(ASM) -f elf64 HALKit/AMD64/SMPCoreManager.asm
mv *.o HALKit/AMD64/*.o Obj/
+
+OBJCOPY = x86_64-elf-objcopy
+
.PHONY: kernel-link
kernel-link:
$(LD) $(SCRIPT) Obj/*.o -o $(KERNEL)
+ $(OBJCOPY) -j .text -j .sdata -j .data -j .dynamic -j .dynsym -j .rel -j .rela -j .rel.* -j .rela.* -j .reloc --target efi-app-x86_64 --subsystem=10 $(KERNEL) $(KERNEL)
cp $(KERNEL) Root/System
.PHONY: all
diff --git a/Public/SDK/ZipKit/Makefile b/Public/SDK/ZipKit/Makefile
new file mode 100644
index 00000000..bb1cd69d
--- /dev/null
+++ b/Public/SDK/ZipKit/Makefile
@@ -0,0 +1,5 @@
+# (C) Mahrouss Logic, 2024, all rights reserved.
+
+.PHONY: zip
+zip:
+ @echo "Later!"