diff options
| author | Amlal El Mahrouss <amlal@nekernel.org> | 2025-08-16 19:56:21 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-16 19:56:21 +0200 |
| commit | 1a32b9307357ac0fc9095e853b2b6d94f9fe62bb (patch) | |
| tree | f41f723659c8926e38182fbe062746d821ab487e /dev/boot | |
| parent | eb9df5eea339812513c25a8d3b2eeb03c633e7ac (diff) | |
| parent | b301047903b79560dce69085fc271a653a1eb4b6 (diff) | |
Merge pull request #55 from nekernel-org/dev
v0.0.4
Diffstat (limited to 'dev/boot')
| -rw-r--r-- | dev/boot/BootKit/BootKit.h | 16 | ||||
| -rw-r--r-- | dev/boot/BootKit/Device.h | 4 | ||||
| -rw-r--r-- | dev/boot/modules/BootNet/BootNet.cc | 4 | ||||
| -rw-r--r-- | dev/boot/modules/BootNet/BootNet.h | 2 | ||||
| -rw-r--r-- | dev/boot/src/BootSupport.cc | 66 | ||||
| -rw-r--r-- | dev/boot/src/BootThread.cc | 6 | ||||
| -rw-r--r-- | dev/boot/src/HEL/AMD64/BootATA.cc | 13 | ||||
| -rw-r--r-- | dev/boot/src/HEL/ARM64/BootCB.S | 4 | ||||
| -rw-r--r-- | dev/boot/src/HEL/ARM64/BootPlatform.cc | 3 | ||||
| -rw-r--r-- | dev/boot/src/New+Delete.cc | 3 |
10 files changed, 91 insertions, 30 deletions
diff --git a/dev/boot/BootKit/BootKit.h b/dev/boot/BootKit/BootKit.h index 68e4b484..12a5861f 100644 --- a/dev/boot/BootKit/BootKit.h +++ b/dev/boot/BootKit/BootKit.h @@ -293,16 +293,16 @@ inline Boolean BDiskFormatFactory<BootDev>::Format(const Char* part_name) { CopyMem(gpt_part->Signature, reinterpret_cast<VoidPtr>(const_cast<Char*>(kMagicGPT)), StrLen(kMagicGPT)); - gpt_part->Revision = 0x00010000; + gpt_part->Revision = 0x00010000; gpt_part->HeaderSize = sizeof(GPT_PARTITION_TABLE); gpt_part->CRC32 = 0x00000000; - gpt_part->Reserved1 = 0x00000000; - gpt_part->LBAHeader = 0x00000000; - gpt_part->LBAAltHeader = 0x00000000; + gpt_part->Reserved1 = 0x00000000; + gpt_part->LBAHeader = 0x00000000; + gpt_part->LBAAltHeader = 0x00000000; gpt_part->FirstGPTEntry = 0x00000000; - gpt_part->LastGPTEntry = 0x00000000; + gpt_part->LastGPTEntry = 0x00000000; gpt_part->Guid.Data1 = 0x00000000; gpt_part->Guid.Data2 = 0x0000; @@ -312,10 +312,10 @@ inline Boolean BDiskFormatFactory<BootDev>::Format(const Char* part_name) { gpt_part->Revision = 0x00010000; - gpt_part->StartingLBA = 0x00000000; + gpt_part->StartingLBA = 0x00000000; gpt_part->NumPartitionEntries = 0x00000000; - gpt_part->SizeOfEntries = 0x00000000; - gpt_part->CRC32PartEntry = 0x00000000; + gpt_part->SizeOfEntries = 0x00000000; + gpt_part->CRC32PartEntry = 0x00000000; SetMem(gpt_part->Reserved2, 0, kSectorAlignGPT_PartTbl); diff --git a/dev/boot/BootKit/Device.h b/dev/boot/BootKit/Device.h index 6ae8cd6b..9a80e3c9 100644 --- a/dev/boot/BootKit/Device.h +++ b/dev/boot/BootKit/Device.h @@ -9,8 +9,7 @@ #include <modules/AHCI/AHCI.h> #include <modules/ATA/ATA.h> -using namespace Kernel; - +namespace Kernel { /// @brief Device type. class Device { public: @@ -33,3 +32,4 @@ class Device { typedef Device BootDevice; typedef Device NetworkDevice; typedef Device DiskDevice; +} // namespace Kernel
\ No newline at end of file diff --git a/dev/boot/modules/BootNet/BootNet.cc b/dev/boot/modules/BootNet/BootNet.cc index 8236dd0d..d8ea5799 100644 --- a/dev/boot/modules/BootNet/BootNet.cc +++ b/dev/boot/modules/BootNet/BootNet.cc @@ -12,8 +12,8 @@ #include <FirmwareKit/EFI/API.h> #include <modules/BootNet/BootNet.h> -STATIC EFI_GUID kEfiSimpleProtoGUID = EFI_SIMPLE_NETWORK_PROTOCOL_GUID; -STATIC EFI_SIMPLE_NETWORK_PROTOCOL* kEfiProtocol = nullptr; +STATIC EFI_GUID kEfiSimpleProtoGUID = EFI_SIMPLE_NETWORK_PROTOCOL_GUID; +STATIC EFI_SIMPLE_NETWORK_PROTOCOL* kEfiProtocol = nullptr; STATIC Void bootnet_read_ip_packet(BOOTNET_INTERNET_HEADER inet, BOOTNET_INTERNET_HEADER** inet_out); diff --git a/dev/boot/modules/BootNet/BootNet.h b/dev/boot/modules/BootNet/BootNet.h index 0b319387..3e876d09 100644 --- a/dev/boot/modules/BootNet/BootNet.h +++ b/dev/boot/modules/BootNet/BootNet.h @@ -9,4 +9,4 @@ #pragma once -#include <FirmwareKit/CoreBoot/BootNet.h> +#include <FirmwareKit/NeBoot/BootNet.h> diff --git a/dev/boot/src/BootSupport.cc b/dev/boot/src/BootSupport.cc index ce824e0f..4bf3e68a 100644 --- a/dev/boot/src/BootSupport.cc +++ b/dev/boot/src/BootSupport.cc @@ -18,6 +18,69 @@ /// @param dst destination pointer. /// @param byte value to fill in. /// @param len length of of src. +EXTERN_C VoidPtr memnset(void* dst, int byte, long long unsigned int len, + long long unsigned int dst_size) { + if (!dst || len > dst_size) { + // For now, we return nullptr or an error status. + return nullptr; + } + unsigned char* p = (unsigned char*) dst; + unsigned char val = (unsigned char) byte; + for (size_t i = 0UL; i < len; ++i) { + p[i] = val; + } + return dst; +} + +/// @brief memcpy definition in C++. +/// @param dst destination pointer. +/// @param src source pointer. +/// @param len length of of src. +EXTERN_C VoidPtr memncpy(void* dst, const void* src, long long unsigned int len, + long long unsigned int dst_size) { + if (!dst || !src || len > dst_size) { + // Similar to memset, this is a critical failure. + return nullptr; + } + unsigned char* d = (unsigned char*) dst; + const unsigned char* s = (const unsigned char*) src; + for (size_t i = 0UL; i < len; ++i) { + d[i] = s[i]; + } + return dst; +} + +/// @brief strlen definition in C++. +EXTERN_C size_t strnlen(const char* whatToCheck, size_t max_len) { + size_t len = 0; + while (len < max_len && whatToCheck[len] != '\0') { + ++len; + } + return len; +} + +/// @brief strcmp definition in C++. +EXTERN_C int strncmp(const char* whatToCheck, const char* whatToCheckRight, size_t max_len) { + size_t i = 0; + while (i < max_len && whatToCheck[i] == whatToCheckRight[i]) { + if (whatToCheck[i] == '\0') return 0; + ++i; + } + if (i == max_len) { + return 0; + } + return (unsigned char) whatToCheck[i] - (unsigned char) whatToCheckRight[i]; +} + +/// @brief something specific to the Microsoft's ABI, When the stack grows too big. +EXTERN_C void ___chkstk_ms(void) {} + +/// @note GCC expects them to be here. + +/// @brief memset definition in C++. +/// @param dst destination pointer. +/// @param byte value to fill in. +/// @param len length of of src. EXTERN_C VoidPtr memset(void* dst, int byte, long long unsigned int len) { for (size_t i = 0UL; i < len; ++i) { ((int*) dst)[i] = byte; @@ -62,7 +125,4 @@ EXTERN_C int strcmp(const char* whatToCheck, const char* whatToCheckRight) { return len; } -/// @brief something specific to the Microsoft's ABI, When the stack grows too big. -EXTERN_C void ___chkstk_ms(void) {} - #endif diff --git a/dev/boot/src/BootThread.cc b/dev/boot/src/BootThread.cc index c477d659..377e6e3a 100644 --- a/dev/boot/src/BootThread.cc +++ b/dev/boot/src/BootThread.cc @@ -105,6 +105,12 @@ BootThread::BootThread(VoidPtr blob) : fStartAddress(nullptr), fBlob(blob) { writer.Write("BootZ: Executable entry address: ") .Write((UIntPtr) fStartAddress) .Write("\r"); + + /// @note .text region shall be marked as executable on ARM. + +#ifdef __NE_ARM64__ + +#endif } else if (StrCmp(sectionForBootZ, sect->Name) == 0) { struct HANDOVER_INFORMATION_STUB { UInt64 HandoverMagic; diff --git a/dev/boot/src/HEL/AMD64/BootATA.cc b/dev/boot/src/HEL/AMD64/BootATA.cc index 25810222..e5e0d8c2 100644 --- a/dev/boot/src/HEL/AMD64/BootATA.cc +++ b/dev/boot/src/HEL/AMD64/BootATA.cc @@ -88,8 +88,7 @@ ATAInit_Retry: /// fetch serial info /// model, speed, number of sectors... - while (!(rt_in8(IO + ATA_REG_STATUS) & ATA_SR_DRQ)) - ; + while (!(rt_in8(IO + ATA_REG_STATUS) & ATA_SR_DRQ)); for (SizeT indexData = 0ul; indexData < kATADataLen; ++indexData) { kATAData[indexData] = rt_in16(IO + ATA_REG_DATA); @@ -115,15 +114,14 @@ Void boot_ata_read(UInt64 Lba, UInt16 IO, UInt8 Master, CharacterTypeASCII* Buf, rt_out8(IO + ATA_REG_SEC_COUNT0, ((Size + SectorSz) / SectorSz)); - rt_out8(IO + ATA_REG_LBA0, (Lba) &0xFF); + rt_out8(IO + ATA_REG_LBA0, (Lba) & 0xFF); rt_out8(IO + ATA_REG_LBA1, (Lba) >> 8); rt_out8(IO + ATA_REG_LBA2, (Lba) >> 16); rt_out8(IO + ATA_REG_LBA3, (Lba) >> 24); rt_out8(IO + ATA_REG_COMMAND, ATA_CMD_READ_PIO); - while (!(rt_in8(IO + ATA_REG_STATUS) & ATA_SR_DRQ)) - ; + while (!(rt_in8(IO + ATA_REG_STATUS) & ATA_SR_DRQ)); for (SizeT IndexOff = 0; IndexOff < Size; IndexOff += 2) { boot_ata_wait_io(IO); @@ -149,15 +147,14 @@ Void boot_ata_write(UInt64 Lba, UInt16 IO, UInt8 Master, CharacterTypeASCII* Buf rt_out8(IO + ATA_REG_SEC_COUNT0, ((Size + (SectorSz)) / SectorSz)); - rt_out8(IO + ATA_REG_LBA0, (Lba) &0xFF); + rt_out8(IO + ATA_REG_LBA0, (Lba) & 0xFF); rt_out8(IO + ATA_REG_LBA1, (Lba) >> 8); rt_out8(IO + ATA_REG_LBA2, (Lba) >> 16); rt_out8(IO + ATA_REG_LBA3, (Lba) >> 24); rt_out8(IO + ATA_REG_COMMAND, ATA_CMD_WRITE_PIO); - while (!(rt_in8(IO + ATA_REG_STATUS) & ATA_SR_DRQ)) - ; + while (!(rt_in8(IO + ATA_REG_STATUS) & ATA_SR_DRQ)); for (SizeT IndexOff = 0; IndexOff < Size; IndexOff += 2) { boot_ata_wait_io(IO); diff --git a/dev/boot/src/HEL/ARM64/BootCB.S b/dev/boot/src/HEL/ARM64/BootCB.S index 3b0e1737..d52c1dcf 100644 --- a/dev/boot/src/HEL/ARM64/BootCB.S +++ b/dev/boot/src/HEL/ARM64/BootCB.S @@ -4,7 +4,7 @@ ------------------------------------------- */ -#ifdef __NE_COREBOOT__ +#ifdef __NE_NEBOOT__ .section .boot_hdr .align 4 @@ -37,4 +37,4 @@ bootloader_start: bl bootloader_main ret -#endif // __NE_COREBOOT__
\ No newline at end of file +#endif // __NE_NEBOOT__
\ No newline at end of file diff --git a/dev/boot/src/HEL/ARM64/BootPlatform.cc b/dev/boot/src/HEL/ARM64/BootPlatform.cc index 9dd03afe..683245fb 100644 --- a/dev/boot/src/HEL/ARM64/BootPlatform.cc +++ b/dev/boot/src/HEL/ARM64/BootPlatform.cc @@ -13,8 +13,7 @@ using namespace Boot; EXTERN_C void rt_halt() { - while (Yes) - ; + while (Yes); } EXTERN_C void rt_cli() {} diff --git a/dev/boot/src/New+Delete.cc b/dev/boot/src/New+Delete.cc index d4d5dfed..f7ad2898 100644 --- a/dev/boot/src/New+Delete.cc +++ b/dev/boot/src/New+Delete.cc @@ -17,8 +17,7 @@ void* operator new(size_t sz) { void* buf = nullptr; - while (BS->AllocatePool(EfiMemoryType::EfiLoaderData, sz, &buf) != kEfiOk) - ; + while (BS->AllocatePool(EfiMemoryType::EfiLoaderData, sz, &buf) != kEfiOk); return buf; } |
