summaryrefslogtreecommitdiffhomepage
path: root/dev
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@nekernel.org>2025-04-10 09:41:33 +0200
committerAmlal El Mahrouss <amlal@nekernel.org>2025-04-10 09:41:33 +0200
commite50f871e6852beacb53986f930ed2d5dead84838 (patch)
treef9a526d927e9b73a588e9c7db5cd99bf1622ca23 /dev
parent26932fb28c6d8724222fc80705976369f2f5dbb3 (diff)
kernel, boot: a lot of improvements regarding memory probing.
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
Diffstat (limited to 'dev')
-rw-r--r--dev/boot/modules/BootNet/amd64.json2
-rw-r--r--dev/boot/modules/SysChk/SysChk.cc6
-rw-r--r--dev/boot/modules/SysChk/amd64-ahci.json (renamed from dev/boot/modules/SysChk/amd64.json)3
-rw-r--r--dev/boot/modules/SysChk/amd64-pio.json25
-rw-r--r--dev/boot/src/HEL/AMD64/BootEFI.cc65
-rw-r--r--dev/kernel/amd64-ci.make2
-rw-r--r--dev/kernel/amd64-desktop.make2
-rw-r--r--dev/kernel/src/BitMapMgr.cc4
8 files changed, 58 insertions, 51 deletions
diff --git a/dev/boot/modules/BootNet/amd64.json b/dev/boot/modules/BootNet/amd64.json
index 86143e6a..da4a15f0 100644
--- a/dev/boot/modules/BootNet/amd64.json
+++ b/dev/boot/modules/BootNet/amd64.json
@@ -10,7 +10,7 @@
"-fPIC",
"-fno-rtti",
"-fno-exceptions",
- "-Wl,--subsystem=17,--image-base,0x1000000,-e,BootNetModuleMain"
+ "-Wl,--subsystem=17,--image-base,0x10000000,-e,BootNetModuleMain"
],
"cpp_macros": [
"__NEOSKRNL__",
diff --git a/dev/boot/modules/SysChk/SysChk.cc b/dev/boot/modules/SysChk/SysChk.cc
index ed14d2cd..3086cdc6 100644
--- a/dev/boot/modules/SysChk/SysChk.cc
+++ b/dev/boot/modules/SysChk/SysChk.cc
@@ -23,12 +23,12 @@
// Makes the compiler shut up.
#ifndef kMachineModel
-#define kMachineModel "NeKrnl"
+#define kMachineModel "Ne"
#endif // !kMachineModel
EXTERN_C Int32 SysChkModuleMain(Kernel::HEL::BootInfoHeader* handover)
{
-#ifdef __NE_AMD64__
+#ifdef __ATA_PIO__
Boot::BDiskFormatFactory<BootDeviceATA> partition_factory;
if (partition_factory.IsPartitionValid())
@@ -40,7 +40,7 @@ EXTERN_C Int32 SysChkModuleMain(Kernel::HEL::BootInfoHeader* handover)
desc.fFileName[1] = 0;
desc.fKind = kNeFSCatalogKindDir;
- partition_factory.Format(kMachineModel, &desc, sizeof(Boot::BDiskFormatFactory<BootDeviceATA>::BFileDescriptor));
+ partition_factory.Format(kMachineModel, &desc, 1);
if (partition_factory.IsPartitionValid())
return kEfiOk;
diff --git a/dev/boot/modules/SysChk/amd64.json b/dev/boot/modules/SysChk/amd64-ahci.json
index 3b5bab6f..527e79f9 100644
--- a/dev/boot/modules/SysChk/amd64.json
+++ b/dev/boot/modules/SysChk/amd64-ahci.json
@@ -10,13 +10,14 @@
"-fPIC",
"-fno-rtti",
"-fno-exceptions",
- "-Wl,--subsystem=17,--image-base,0x1000000,-e,SysChkModuleMain"
+ "-Wl,--subsystem=17,--image-base,0x10000000,-e,SysChkModuleMain"
],
"cpp_macros": [
"__NEOSKRNL__",
"__BOOTZ__",
"__BOOTZ_STANDALONE__",
"__NE_AMD64__",
+ "__AHCI__",
"kChkVersionHighest=0x0100",
"kChkVersionLowest=0x0100",
"kChkVersion=0x0100"
diff --git a/dev/boot/modules/SysChk/amd64-pio.json b/dev/boot/modules/SysChk/amd64-pio.json
new file mode 100644
index 00000000..de3195ce
--- /dev/null
+++ b/dev/boot/modules/SysChk/amd64-pio.json
@@ -0,0 +1,25 @@
+{
+ "compiler_path": "x86_64-w64-mingw32-g++",
+ "compiler_std": "c++20",
+ "headers_path": ["../", "../../", "../../../kernel", "../../../", "./"],
+ "sources_path": ["*.cc", "*.S", "../../src/HEL/AMD64/*.cc", "../../src/HEL/AMD64/*.S", "../../src/*.cc"],
+ "output_name": "chk.efi",
+ "compiler_flags": [
+ "-nostdlib",
+ "-std=c++20",
+ "-fPIC",
+ "-fno-rtti",
+ "-fno-exceptions",
+ "-Wl,--subsystem=17,--image-base,0x10000000,-e,SysChkModuleMain"
+ ],
+ "cpp_macros": [
+ "__NEOSKRNL__",
+ "__BOOTZ__",
+ "__BOOTZ_STANDALONE__",
+ "__NE_AMD64__",
+ "__ATA_PIO__",
+ "kChkVersionHighest=0x0100",
+ "kChkVersionLowest=0x0100",
+ "kChkVersion=0x0100"
+ ]
+}
diff --git a/dev/boot/src/HEL/AMD64/BootEFI.cc b/dev/boot/src/HEL/AMD64/BootEFI.cc
index e07ad6d6..57651016 100644
--- a/dev/boot/src/HEL/AMD64/BootEFI.cc
+++ b/dev/boot/src/HEL/AMD64/BootEFI.cc
@@ -165,58 +165,39 @@ EFI_EXTERN_C EFI_API Int32 ModuleMain(EfiHandlePtr image_handle,
// Fill handover header now.
- // ---------------------------------------------------- //
- // The following checks for an exisiting partition
- // inside the disk, if it doesn't have one,
- // format the disk.
- // ---------------------------------------------------- //
-
Boot::BootTextWriter writer;
- auto ret = BS->GetMemoryMap(&size_struct_ptr, struct_ptr, &map_key, &sz_desc, &rev_desc);
-
- if (ret == kEfiFail)
- {
- writer.Write("BootZ: GetMemoryMap failed (x1)\r");
- Boot::Stop();
- }
-
- size_struct_ptr += sz_desc * 2;
- BS->AllocatePool(EfiMemoryType::EfiBootServicesData, size_struct_ptr, reinterpret_cast<VoidPtr*>(&struct_ptr));
+ //-------------------------------------------------------------//
+ // Update handover file specific table and phyiscal start field.
+ //-------------------------------------------------------------//
- ret = BS->GetMemoryMap(&size_struct_ptr, struct_ptr, &map_key, &sz_desc, &rev_desc);
+ handover_hdr->f_BitMapSize = gib_cast(4); /* Size of bitmap in bytes. */
+ Int32 trials = 5 * 10000000;
- if (ret == kEfiFail)
+ while (BS->AllocatePool(EfiLoaderData, handover_hdr->f_BitMapSize, &handover_hdr->f_BitMapStart) != kEfiOk)
{
- writer.Write("BootZ: GetMemoryMap failed (x2)\r");
- Boot::Stop();
- }
+ --trials;
- //-----------------------------------------------------------//
- // A simple loop which finds a usable memory region for us.
- //-----------------------------------------------------------//
+ if (!trials)
+ {
+ writer.Write("BootZ: Unable to allocate sufficent memory, trying again with 2GB...\r");
- SizeT lookup_index = 0UL;
- SizeT entry_count = size_struct_ptr / sz_desc;
+ trials = 3 * 10000000;
- for (; lookup_index < entry_count; ++lookup_index)
- {
- if (struct_ptr[lookup_index].Kind == EfiMemoryType::EfiConventionalMemory)
- break;
- }
+ handover_hdr->f_BitMapSize = gib_cast(2); /* Size of bitmap in bytes. */
- if (lookup_index > entry_count)
- {
- writer.Write("BootZ: No usable entries.\r");
- Boot::Stop();
- }
+ while (BS->AllocatePool(EfiLoaderData, handover_hdr->f_BitMapSize, &handover_hdr->f_BitMapStart) != kEfiOk)
+ {
+ --trials;
- //-------------------------------------------------------------//
- // Update handover file specific table and phyiscal start field.
- //-------------------------------------------------------------//
-
- handover_hdr->f_BitMapStart = (VoidPtr)(struct_ptr[lookup_index].VirtualStart); /* Start of bitmap. */
- handover_hdr->f_BitMapSize = struct_ptr[lookup_index].NumberOfPages * kib_cast(4); /* Size of bitmap in bytes. */
+ if (!trials)
+ {
+ writer.Write("BootZ: Unable to allocate sufficent memory, aborting...\r");
+ Boot::Stop();
+ }
+ }
+ }
+ }
handover_hdr->f_FirmwareCustomTables[0] = (VoidPtr)BS;
handover_hdr->f_FirmwareCustomTables[1] = (VoidPtr)ST;
diff --git a/dev/kernel/amd64-ci.make b/dev/kernel/amd64-ci.make
index d74b5523..a03c8fdd 100644
--- a/dev/kernel/amd64-ci.make
+++ b/dev/kernel/amd64-ci.make
@@ -33,7 +33,7 @@ COPY = cp
ASMFLAGS = -f win64
# Kernel subsystem is 17 and entrypoint is hal_init_platform
-LDFLAGS = -e hal_init_platform --subsystem=17 --image-base 0x1000000
+LDFLAGS = -e hal_init_platform --subsystem=17 --image-base 0x4000000
LDOBJ = obj/*.obj
# This file is the Kernel, responsible of task, memory, driver, sci, disk and device management.
diff --git a/dev/kernel/amd64-desktop.make b/dev/kernel/amd64-desktop.make
index d74b5523..a03c8fdd 100644
--- a/dev/kernel/amd64-desktop.make
+++ b/dev/kernel/amd64-desktop.make
@@ -33,7 +33,7 @@ COPY = cp
ASMFLAGS = -f win64
# Kernel subsystem is 17 and entrypoint is hal_init_platform
-LDFLAGS = -e hal_init_platform --subsystem=17 --image-base 0x1000000
+LDFLAGS = -e hal_init_platform --subsystem=17 --image-base 0x4000000
LDOBJ = obj/*.obj
# This file is the Kernel, responsible of task, memory, driver, sci, disk and device management.
diff --git a/dev/kernel/src/BitMapMgr.cc b/dev/kernel/src/BitMapMgr.cc
index 4f27e654..63cadde3 100644
--- a/dev/kernel/src/BitMapMgr.cc
+++ b/dev/kernel/src/BitMapMgr.cc
@@ -95,9 +95,9 @@ namespace Kernel
if (!size)
return nullptr;
- constexpr const UInt32 kStartOffset = 0x1000;
+ VoidPtr base = reinterpret_cast<VoidPtr>((UIntPtr)base_ptr);
- VoidPtr base = reinterpret_cast<VoidPtr>(((UIntPtr)base_ptr) + kStartOffset);
+ MUST_PASS(base);
static SizeT biggest = 0UL;