diff options
| author | Amlal El Mahrouss <amlal@el-mahrouss-logic.com> | 2024-04-04 19:46:31 +0200 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal@el-mahrouss-logic.com> | 2024-04-04 19:46:31 +0200 |
| commit | a45872967f07906297782cd04223706cfc326219 (patch) | |
| tree | f48d43749e4a1536d34e6c7dbb5b25defb8656fa | |
| parent | c33efb3e8a31435b37ed2c55375eec80c9b23155 (diff) | |
NewBoot: Major bootloader improvements, use __EFI_x86_64__ on EFI platforms, add common device class.
Meta: Upate specs and kernel-design.
Signed-off-by: Amlal El Mahrouss <amlal@el-mahrouss-logic.com>
| -rw-r--r-- | .vscode/c_cpp_properties.json | 6 | ||||
| -rw-r--r-- | Private/NewBoot/BootKit/BootKit.hxx | 27 | ||||
| -rw-r--r-- | Private/NewBoot/BootKit/Device.hxx | 34 | ||||
| -rw-r--r-- | Private/NewBoot/BootKit/HW/ATA.hxx (renamed from Private/NewBoot/BootKit/Arch/ATA.hxx) | 16 | ||||
| -rw-r--r-- | Private/NewBoot/BootKit/HW/SATA.hxx (renamed from Private/NewBoot/BootKit/Arch/SATA.hxx) | 0 | ||||
| -rw-r--r-- | Private/NewBoot/NetBoot/Module.cxx (renamed from Private/NewBoot/NetBoot/EfiModule.cxx) | 11 | ||||
| -rw-r--r-- | Private/NewBoot/Source/HEL/AMD64/BootAHCI.cxx | 2 | ||||
| -rw-r--r-- | Private/NewBoot/Source/HEL/AMD64/BootATA.cxx | 2 | ||||
| -rw-r--r-- | Private/NewBoot/Source/HEL/AMD64/BootEPM.cxx | 16 | ||||
| -rw-r--r-- | Private/NewBoot/Source/HEL/AMD64/BootMain.cxx | 2 | ||||
| -rw-r--r-- | Private/NewBoot/Source/HEL/AMD64/New+Delete.cxx | 33 | ||||
| -rw-r--r-- | Private/NewBoot/Source/makefile | 6 | ||||
| -rw-r--r-- | Public/Documentation/Spec.md | 7 | ||||
| -rw-r--r-- | Public/Documentation/kernel-design.drawio | 10 |
14 files changed, 124 insertions, 48 deletions
diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index 08cf70c4..6899e66e 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -13,7 +13,8 @@ "__KERNEL__", "Z_PREFIX", "__HAVE_MAHROUSS_APIS__", - "__FSKIT_NEWFS__" + "__FSKIT_NEWFS__", + "__EFI_x86_64__" ], "cStandard": "c17", "cppStandard": "c++20", @@ -43,7 +44,8 @@ "__KERNEL__", "Z_PREFIX", "__HAVE_MAHROUSS_APIS__", - "__FSKIT_NEWFS__" + "__FSKIT_NEWFS__", + "__EFI_x86_64__" ], "cStandard": "c17", "cppStandard": "c++20", diff --git a/Private/NewBoot/BootKit/BootKit.hxx b/Private/NewBoot/BootKit/BootKit.hxx index be46f64c..66a9aa67 100644 --- a/Private/NewBoot/BootKit/BootKit.hxx +++ b/Private/NewBoot/BootKit/BootKit.hxx @@ -16,11 +16,13 @@ class BFileReader; class BFileRunner; class BVersionString; -#include <BootKit/Arch/ATA.hxx> +#include <BootKit/HW/ATA.hxx> #include <CompilerKit/Version.hxx> +#ifdef __EFI_x86_64__ #include <FirmwareKit/EFI.hxx> -#include <NewKit/Defines.hpp> +#endif // ifdef __EFI_x86_64__ #include <FirmwareKit/EPM.hxx> +#include <NewKit/Defines.hpp> using namespace NewOS; @@ -42,6 +44,7 @@ typedef Char CharacterTypeUTF8; */ class BTextWriter final { BTextWriter &_Write(const Long &num); + public: BTextWriter &Write(const Long &num); BTextWriter &Write(const UChar *str); @@ -76,7 +79,8 @@ NewOS::SizeT BSetMem(CharacterTypeUTF16 *src, const CharacterTypeUTF16 byte, */ class BFileReader final { public: - explicit BFileReader(const CharacterTypeUTF16 *path, EfiHandlePtr ImageHandle); + explicit BFileReader(const CharacterTypeUTF16 *path, + EfiHandlePtr ImageHandle); ~BFileReader(); Void ReadAll(); @@ -163,9 +167,7 @@ inline UInt32 In32(UInt16 port) { return value; } -inline Void rt_hlt() { - asm volatile("hlt"); -} +inline Void rt_hlt() { asm volatile("hlt"); } #endif // __EFI_x86_64__ @@ -181,7 +183,8 @@ const UInt32 kRgbBlue = 0x00FF0000; const UInt32 kRgbBlack = 0x00000000; const UInt32 kRgbWhite = 0x00FFFFFF; -/** QT GOP and related. */ +#ifdef __EFI_x86_64__ +/** GOP and related. */ inline EfiGraphicsOutputProtocol *kGop; inline UInt16 kStride; inline EfiGUID kGopGuid; @@ -199,10 +202,18 @@ inline Void InitGOP() noexcept { kStride = 4; } +#endif // __EFI_x86_64__ class BVersionString final { public: static const CharacterTypeUTF16 *Shared() { return BOOTLOADER_VERSION; } }; -EXTERN_C Boolean boot_write_epm_partition(const Char* namePart, SizeT namePartLength, BootDeviceATA* ataInterface); +/// @brief Writes an EPM partition on the main disk. +/// @param namePart the partition's name +/// @param namePartLength the partition name's length +/// @param bootDev the disk interface. +/// @return +EXTERN_C Boolean boot_write_epm_partition(const Char *namePart, + SizeT namePartLength, + BootDevice *bootDev); diff --git a/Private/NewBoot/BootKit/Device.hxx b/Private/NewBoot/BootKit/Device.hxx new file mode 100644 index 00000000..bc50a576 --- /dev/null +++ b/Private/NewBoot/BootKit/Device.hxx @@ -0,0 +1,34 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + +------------------------------------------- */ + +#pragma once + +#include <Builtins/ATA/Defines.hxx> + +using namespace NewOS; + +/// @brief Device type. +class Device { + public: + Device() = default; + virtual ~Device() = default; + + HCORE_MOVE_DEFAULT(Device); + + struct Trait { + SizeT mBase{1024}; + SizeT mSize{1024}; +}; + + virtual Trait& Leak() = 0; + + virtual Device& Read(Char* Buf, const SizeT& SecCount) = 0; + virtual Device& Write(Char* Buf, const SizeT& SecCount) = 0; +}; + +typedef Device BootDevice; +typedef Device NetworkDevice; +typedef Device DiskDevice; diff --git a/Private/NewBoot/BootKit/Arch/ATA.hxx b/Private/NewBoot/BootKit/HW/ATA.hxx index 5501f947..40402a86 100644 --- a/Private/NewBoot/BootKit/Arch/ATA.hxx +++ b/Private/NewBoot/BootKit/HW/ATA.hxx @@ -7,10 +7,11 @@ #pragma once #include <Builtins/ATA/Defines.hxx> +#include <BootKit/Device.hxx> using namespace NewOS; -class BootDeviceATA final { +class BootDeviceATA final : public Device { public: enum { kPrimary = ATA_PRIMARY_IO, @@ -22,9 +23,7 @@ class BootDeviceATA final { HCORE_COPY_DEFAULT(BootDeviceATA); - struct ATATrait final { - SizeT mBase{1024}; - SizeT mSize{1024}; + struct ATATrait final : public Device::Trait { UInt16 mBus{kPrimary}; UInt8 mMaster{0}; Boolean mErr{false}; @@ -32,13 +31,14 @@ class BootDeviceATA final { operator bool() { return !mErr; } }; + public: operator bool(); - BootDeviceATA& Read(Char* Buf, const SizeT& SecCount); - BootDeviceATA& Write(Char* Buf, const SizeT& SecCount); + BootDeviceATA& Read(Char* Buf, const SizeT& SecCount) override; + BootDeviceATA& Write(Char* Buf, const SizeT& SecCount) override; - ATATrait& Leak(); + ATATrait& Leak() override; private: ATATrait mTrait; -}; +};
\ No newline at end of file diff --git a/Private/NewBoot/BootKit/Arch/SATA.hxx b/Private/NewBoot/BootKit/HW/SATA.hxx index cbaeb404..cbaeb404 100644 --- a/Private/NewBoot/BootKit/Arch/SATA.hxx +++ b/Private/NewBoot/BootKit/HW/SATA.hxx diff --git a/Private/NewBoot/NetBoot/EfiModule.cxx b/Private/NewBoot/NetBoot/Module.cxx index e5df4a3e..c89d0a5f 100644 --- a/Private/NewBoot/NetBoot/EfiModule.cxx +++ b/Private/NewBoot/NetBoot/Module.cxx @@ -7,20 +7,13 @@ * ======================================================== */ -#include <FirmwareKit/EFI.hxx> #include <BootKit/BootKit.hxx> -EXTERN_C Int32 EfiMain(EfiHandlePtr handle, EfiSystemTable* SystemTable) +EXTERN_C Int32 EfiMain(Void) { - InitEFI(ST); - InitGOP(); - - /// - Find a network drive called "/OnlineInstall" + /// - Find a network drive called "/OnlineBoot" /// - Download our image /// - Boot from it. - BTextWriter writer; - writer.Write(L"NetBoot.exe: Updating from OTP...\r\n"); - return kEfiOk; } diff --git a/Private/NewBoot/Source/HEL/AMD64/BootAHCI.cxx b/Private/NewBoot/Source/HEL/AMD64/BootAHCI.cxx index be7010a8..d736ac59 100644 --- a/Private/NewBoot/Source/HEL/AMD64/BootAHCI.cxx +++ b/Private/NewBoot/Source/HEL/AMD64/BootAHCI.cxx @@ -15,4 +15,4 @@ * */ -#include <BootKit/Arch/SATA.hxx> +#include <BootKit/HW/SATA.hxx> diff --git a/Private/NewBoot/Source/HEL/AMD64/BootATA.cxx b/Private/NewBoot/Source/HEL/AMD64/BootATA.cxx index 3f309f31..2a2852fb 100644 --- a/Private/NewBoot/Source/HEL/AMD64/BootATA.cxx +++ b/Private/NewBoot/Source/HEL/AMD64/BootATA.cxx @@ -15,7 +15,7 @@ * */ -#include <BootKit/Arch/ATA.hxx> +#include <BootKit/HW/ATA.hxx> #include <BootKit/BootKit.hxx> /// bugs: 0 diff --git a/Private/NewBoot/Source/HEL/AMD64/BootEPM.cxx b/Private/NewBoot/Source/HEL/AMD64/BootEPM.cxx index e767cb2d..cca9a6ca 100644 --- a/Private/NewBoot/Source/HEL/AMD64/BootEPM.cxx +++ b/Private/NewBoot/Source/HEL/AMD64/BootEPM.cxx @@ -19,19 +19,19 @@ STATIC const BlockGUID kEPMGuid = { /// @brief Write epm partition to disk. /// @param namePart partition name /// @param namePartLength length of name -/// @param ataInterface disk interface, here ATA. +/// @param bootDev disk interface. /// @return EXTERN_C Boolean boot_write_epm_partition(const Char* namePart, SizeT namePartLength, - BootDeviceATA* ataInterface) { + BootDevice* bootDev) { if (namePartLength > kEPMNameLength || !namePart) return No; - if (!ataInterface) return No; + if (!bootDev) return No; - ataInterface->Leak().mBase = kEPMStartPartitionBlk; - ataInterface->Leak().mSize = kATASectorSize; + bootDev->Leak().mBase = kEPMStartPartitionBlk; + bootDev->Leak().mSize = kATASectorSize; - Char buf[512] = {0}; + Char buf[kATASectorSize] = {0}; - ataInterface->Read(buf, 1); + bootDev->Read(buf, 1); BTextWriter writer; @@ -106,7 +106,7 @@ EXTERN_C Boolean boot_write_epm_partition(const Char* namePart, SizeT namePartLe swapBlock->Kind = kNewFSPartitionTypePage; swapBlock->LbaEnd = kSwapSize; /// 4 MIB swap partition. - ataInterface->Write(buf, 1); + bootDev->Write(buf, 1); return No; } diff --git a/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx b/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx index f4eaee33..f2d893c2 100644 --- a/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx +++ b/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx @@ -173,7 +173,7 @@ EFI_EXTERN_C EFI_API Int EfiMain(EfiHandlePtr ImageHandle, handoverHdrPtr->f_Magic = kHandoverMagic; handoverHdrPtr->f_Version = kHandoverVersion; - writer.Write(L"NewOS: Running NewOS...\r\n"); + writer.Write(L"NewOS: Starting kernel...\r\n"); EFI::ExitBootServices(MapKey, ImageHandle); diff --git a/Private/NewBoot/Source/HEL/AMD64/New+Delete.cxx b/Private/NewBoot/Source/HEL/AMD64/New+Delete.cxx new file mode 100644 index 00000000..af7f2f00 --- /dev/null +++ b/Private/NewBoot/Source/HEL/AMD64/New+Delete.cxx @@ -0,0 +1,33 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + +------------------------------------------- */ + +#include <BootKit/BootKit.hxx> + +/// @brief Allocates a new object. +/// @param sz the size. +/// @return +void* operator new(size_t sz) +{ + void* buf = nullptr; + BS->AllocatePool(EfiMemoryType::EfiLoaderData, sz, &buf); + + return buf; +} + +/// @brief Deletes the object. +/// @param buf the object. +void operator delete(void* buf) +{ + BS->FreePool(buf); +} + +/// @brief Deletes the object (array specific). +/// @param buf the object. +/// @param size it's size. +void operator delete(void* buf, size_t size) +{ + BS->FreePool(buf); +}
\ No newline at end of file diff --git a/Private/NewBoot/Source/makefile b/Private/NewBoot/Source/makefile index b9413bb4..4f076580 100644 --- a/Private/NewBoot/Source/makefile +++ b/Private/NewBoot/Source/makefile @@ -26,7 +26,7 @@ REM=rm REM_FLAG=-f FLAG_ASM=-f win64 -FLAG_GNU=-fshort-wchar -mgeneral-regs-only -mno-red-zone -D__KERNEL__ -DEFI_FUNCTION_WRAPPER -I../ -I../../ -I./ -c -ffreestanding -fno-rtti -fno-exceptions -std=c++20 -D__HAVE_MAHROUSS_APIS__ -D__MAHROUSS__ -D__BOOTLOADER__ -I./ +FLAG_GNU=-fshort-wchar -D__EFI_x86_64__ -mgeneral-regs-only -mno-red-zone -D__KERNEL__ -DEFI_FUNCTION_WRAPPER -I../ -I../../ -I./ -c -ffreestanding -fno-rtti -fno-exceptions -std=c++20 -D__HAVE_MAHROUSS_APIS__ -D__MAHROUSS__ -D__BOOTLOADER__ -I./ .PHONY: invalid-recipe invalid-recipe: @@ -38,6 +38,10 @@ all: compile-amd64 $(COPY) NewBoot.exe CDROM/EFI/BOOT/BOOTX64.EFI $(COPY) NewBoot.exe CDROM/EFI/BOOT/NEWBOOT.EFI +ifneq ($(DEBUG_SUPPORT), ) +DEBUG = -D__DEBUG__ +endif + .PHONY: compile-amd64 compile-amd64: windres BootloaderRsrc.rsrc -O coff -o BootloaderRsrc.o diff --git a/Public/Documentation/Spec.md b/Public/Documentation/Spec.md index f2b097a0..aafba3d2 100644 --- a/Public/Documentation/Spec.md +++ b/Public/Documentation/Spec.md @@ -28,7 +28,7 @@ # 2: The Filesystem =================================== -- Catalog based with forks. +- Catalog object with associated forks. - Large storage support. - Long file names. - UNIX path style. @@ -46,8 +46,7 @@ =================================== - Capable of booting from a network drive. -- Loads a PE file which is the kernel +- Loads a PE file which is the kernel. - Sanity checks, based on the number of sections. - Handover compliant. -- Does check for a valid invalid of NewOS (useful in the case of recovering) - +- Does check for a valid partition (useful in the case of recovering) diff --git a/Public/Documentation/kernel-design.drawio b/Public/Documentation/kernel-design.drawio index 90370ab0..d78ac170 100644 --- a/Public/Documentation/kernel-design.drawio +++ b/Public/Documentation/kernel-design.drawio @@ -25,7 +25,7 @@ <mxCell id="dpAw-ApGermXuwIBdtFA-7" value="User Defined Object #3" style="rounded=0;whiteSpace=wrap;html=1;" parent="1" vertex="1"> <mxGeometry x="470" y="280" width="70" height="40" as="geometry" /> </mxCell> - <mxCell id="NTNQYUPq4CuizRvDkpOI-1" value="<h1 style="margin-top: 0px;"><span style="background-color: initial;">System.Core.dll</span></h1><h1 style="margin-top: 0px;"><span style="background-color: initial; font-size: 12px; font-weight: normal;">The System API is written in C/C++ and assembly, meant to interface with the SCI, it provides everything you need to make a NewOS application, properties, objects, threading, heap allocation.</span><br></h1><div><span style="background-color: initial; font-size: 12px; font-weight: normal;">You can also register you own user objects.</span></div>" style="text;html=1;whiteSpace=wrap;overflow=hidden;rounded=0;" parent="1" vertex="1"> + <mxCell id="NTNQYUPq4CuizRvDkpOI-1" value="<h1 style="margin-top: 0px;"><span style="background-color: initial;">SystemLib.lib</span></h1><h1 style="margin-top: 0px;"><span style="background-color: initial; font-size: 12px; font-weight: normal;">The System API is written in C/C++ and assembly, meant to interface with the SCI, it provides everything you need to make a NewOS application, properties, objects, threading, heap allocation.</span><br></h1><div><span style="background-color: initial; font-size: 12px; font-weight: normal;">You can also register you own user objects.</span></div>" style="text;html=1;whiteSpace=wrap;overflow=hidden;rounded=0;" parent="1" vertex="1"> <mxGeometry x="40" y="560" width="360" height="190" as="geometry" /> </mxCell> <mxCell id="NTNQYUPq4CuizRvDkpOI-2" value="System Object" style="rounded=0;whiteSpace=wrap;html=1;" parent="1" vertex="1"> @@ -49,19 +49,19 @@ <mxCell id="NTNQYUPq4CuizRvDkpOI-7" value="/Manifest.xml<div>/NewOS/</div><div><span style="white-space: pre;">	</span>- Library.lib/Dll.dll (Subsystem 17)</div><div>/Resources/</div><div><br></div><div><br></div>" style="rounded=0;whiteSpace=wrap;html=1;align=left;" parent="1" vertex="1"> <mxGeometry x="570" y="650" width="210" height="110" as="geometry" /> </mxCell> - <mxCell id="vm68-OaV5PJmx3jSNiIi-1" value="<h1 style="margin-top: 0px;">System.Graphics.dll (merged with System.Core)</h1><p>Handles input, graphics and sound.</p><p>Uses the ODF format to display graphics and sound is handled by XIFF.</p>" style="text;html=1;whiteSpace=wrap;overflow=hidden;rounded=0;" vertex="1" parent="1"> + <mxCell id="vm68-OaV5PJmx3jSNiIi-1" value="<h1 style="margin-top: 0px;">GraphicsLib.lib (merged with SystemLib)</h1><p>Handles input, graphics and sound.</p><p>Uses the ODF format to display graphics and sound is handled by XIFF.</p>" style="text;html=1;whiteSpace=wrap;overflow=hidden;rounded=0;" vertex="1" parent="1"> <mxGeometry x="31" y="980" width="250" height="120" as="geometry" /> </mxCell> - <mxCell id="vm68-OaV5PJmx3jSNiIi-3" value="System.Graphics.dll" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1"> + <mxCell id="vm68-OaV5PJmx3jSNiIi-3" value="GraphicsLib.lib" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1"> <mxGeometry x="286" y="780" width="114" height="30" as="geometry" /> </mxCell> <mxCell id="vm68-OaV5PJmx3jSNiIi-4" value="System Object" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1"> <mxGeometry x="298" y="1150" width="254" height="70" as="geometry" /> </mxCell> - <mxCell id="vm68-OaV5PJmx3jSNiIi-5" value="System.Graphics.dll" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1"> + <mxCell id="vm68-OaV5PJmx3jSNiIi-5" value="GraphicsLib.lib" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1"> <mxGeometry x="300" y="1110" width="114" height="30" as="geometry" /> </mxCell> - <mxCell id="vm68-OaV5PJmx3jSNiIi-6" value="System.Core.dll" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1"> + <mxCell id="vm68-OaV5PJmx3jSNiIi-6" value="SystemLib.lib" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1"> <mxGeometry x="406" y="780" width="124" height="30" as="geometry" /> </mxCell> </root> |
