diff options
Diffstat (limited to 'dev/kernel')
50 files changed, 286 insertions, 289 deletions
diff --git a/dev/kernel/CFKit/Property.h b/dev/kernel/CFKit/Property.h index 9d35dc60..7fc9bf07 100644 --- a/dev/kernel/CFKit/Property.h +++ b/dev/kernel/CFKit/Property.h @@ -32,9 +32,9 @@ class Property { Property& operator=(const Property&) = default; Property(const Property&) = default; - BOOL StringEquals(KString& name); - PropertyId& GetValue(); - KString& GetKey(); + BOOL StringEquals(BasicKString<>& name); + PropertyId& GetValue(); + BasicKString<>& GetKey(); private: KString fName{kMaxPropLen}; diff --git a/dev/kernel/FSKit/HeFS.h b/dev/kernel/FSKit/HeFS.h index bb4e3dc0..845ef467 100644 --- a/dev/kernel/FSKit/HeFS.h +++ b/dev/kernel/FSKit/HeFS.h @@ -259,7 +259,7 @@ inline UInt32 hefs_hour_get(ATime raw_atime) noexcept { /// @return the minute value.
/// @note The minute is stored in the lower 8 bits of the ATime value.
inline UInt32 hefs_minute_get(ATime raw_atime) noexcept {
- return (raw_atime) & 0xFF;
+ return (raw_atime) &0xFF;
}
inline constexpr UInt32 kHeFSBaseYear = 1970;
@@ -379,10 +379,10 @@ class HeFileSystemParser final { ~HeFileSystemParser() = default;
public:
- HeFileSystemParser(const HeFileSystemParser&) = delete;
+ HeFileSystemParser(const HeFileSystemParser&) = delete;
HeFileSystemParser& operator=(const HeFileSystemParser&) = delete;
- HeFileSystemParser(HeFileSystemParser&&) = delete;
+ HeFileSystemParser(HeFileSystemParser&&) = delete;
HeFileSystemParser& operator=(HeFileSystemParser&&) = delete;
public:
diff --git a/dev/kernel/FSKit/IndexableProperty.h b/dev/kernel/FSKit/IndexableProperty.h index 3f2c42ac..8be6d7c3 100644 --- a/dev/kernel/FSKit/IndexableProperty.h +++ b/dev/kernel/FSKit/IndexableProperty.h @@ -25,7 +25,7 @@ namespace Indexer { class IndexableProperty final : public Property { public: explicit IndexableProperty() : Property() { - Kernel::KString strProp(kMaxPropLen); + Kernel::BasicKString<> strProp(kMaxPropLen); strProp += "/prop/indexable"; this->GetKey() = strProp; diff --git a/dev/kernel/FirmwareKit/EFI/EFI.h b/dev/kernel/FirmwareKit/EFI/EFI.h index 9b22f5b6..97e3ad01 100644 --- a/dev/kernel/FirmwareKit/EFI/EFI.h +++ b/dev/kernel/FirmwareKit/EFI/EFI.h @@ -57,7 +57,7 @@ typedef Char16 EfiChar16Type; /// @brief Core Handle Kind /// Self is like NT's Win32 HANDLE type. typedef struct EfiHandle { -}* EfiHandlePtr; +} * EfiHandlePtr; /* UEFI uses wide characters by default. */ typedef WideChar EfiCharType; @@ -239,85 +239,63 @@ typedef struct EfiTableHeader { UInt32 Reserved; } EfiTableHeader; -#define EFI_ACPI_TABLE_PROTOCOL_GUID \ - { \ - 0xffe06bdd, 0x6107, 0x46a6, { \ - 0x7b, 0xb2, 0x5a, 0x9c, 0x7e, 0xc5, 0x27, 0x5c \ - } \ +#define EFI_ACPI_TABLE_PROTOCOL_GUID \ + { \ + 0xffe06bdd, 0x6107, 0x46a6, { 0x7b, 0xb2, 0x5a, 0x9c, 0x7e, 0xc5, 0x27, 0x5c } \ } -#define EFI_LOAD_FILE_PROTOCOL_GUID \ - { \ - 0x56EC3091, 0x954C, 0x11d2, { \ - 0x8e, 0x3f, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b \ - } \ +#define EFI_LOAD_FILE_PROTOCOL_GUID \ + { \ + 0x56EC3091, 0x954C, 0x11d2, { 0x8e, 0x3f, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b } \ } -#define EFI_LOAD_FILE2_PROTOCOL_GUID \ - { \ - 0x4006c0c1, 0xfcb3, 0x403e, { \ - 0x99, 0x6d, 0x4a, 0x6c, 0x87, 0x24, 0xe0, 0x6d \ - } \ +#define EFI_LOAD_FILE2_PROTOCOL_GUID \ + { \ + 0x4006c0c1, 0xfcb3, 0x403e, { 0x99, 0x6d, 0x4a, 0x6c, 0x87, 0x24, 0xe0, 0x6d } \ } -#define EFI_LOADED_IMAGE_PROTOCOL_GUID \ - { \ - 0x5B1B31A1, 0x9562, 0x11d2, { \ - 0x8E, 0x3F, 0x00, 0xA0, 0xC9, 0x69, 0x72, 0x3B \ - } \ +#define EFI_LOADED_IMAGE_PROTOCOL_GUID \ + { \ + 0x5B1B31A1, 0x9562, 0x11d2, { 0x8E, 0x3F, 0x00, 0xA0, 0xC9, 0x69, 0x72, 0x3B } \ } -#define EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID \ - { \ - 0x9042a9de, 0x23dc, 0x4a38, { \ - 0x96, 0xfb, 0x7a, 0xde, 0xd0, 0x80, 0x51, 0x6a \ - } \ +#define EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID \ + { \ + 0x9042a9de, 0x23dc, 0x4a38, { 0x96, 0xfb, 0x7a, 0xde, 0xd0, 0x80, 0x51, 0x6a } \ } -#define EFI_SIMPLE_NETWORK_PROTOCOL_GUID \ - { \ - 0xA19832B9, 0xAC25, 0x11D3, { \ - 0x9A, 0x2D, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d \ - } \ +#define EFI_SIMPLE_NETWORK_PROTOCOL_GUID \ + { \ + 0xA19832B9, 0xAC25, 0x11D3, { 0x9A, 0x2D, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d } \ } #define EFI_SIMPLE_NETWORK_PROTOCOL_REVISION 0x00010000 -#define EFI_IP4_PROTOCOL_GUID \ - { \ - 0x41d94cd2, 0x35b6, 0x455a, { \ - 0x82, 0x58, 0xd4, 0xe5, 0x13, 0x34, 0xaa, 0xdd \ - } \ +#define EFI_IP4_PROTOCOL_GUID \ + { \ + 0x41d94cd2, 0x35b6, 0x455a, { 0x82, 0x58, 0xd4, 0xe5, 0x13, 0x34, 0xaa, 0xdd } \ } #define EFI_LOADED_IMAGE_PROTOCOL_REVISION 0x1000 -#define EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID \ - { \ - 0x0964e5b22, 0x6459, 0x11d2, { \ - 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b \ - } \ +#define EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID \ + { \ + 0x0964e5b22, 0x6459, 0x11d2, { 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b } \ } -#define EFI_LOADED_IMAGE_DEVICE_PATH_PROTOCOL_GUID \ - { \ - 0xbc62157e, 0x3e33, 0x4fec, { \ - 0x99, 0x20, 0x2d, 0x3b, 0x36, 0xd7, 0x50, 0xdf \ - } \ +#define EFI_LOADED_IMAGE_DEVICE_PATH_PROTOCOL_GUID \ + { \ + 0xbc62157e, 0x3e33, 0x4fec, { 0x99, 0x20, 0x2d, 0x3b, 0x36, 0xd7, 0x50, 0xdf } \ } -#define EFI_DEVICE_PATH_PROTOCOL_GUID \ - { \ - 0x9576e91, 0x6d3f, 0x11d2, { \ - 0x8e, 0x39, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b \ - } \ +#define EFI_DEVICE_PATH_PROTOCOL_GUID \ + { \ + 0x9576e91, 0x6d3f, 0x11d2, { 0x8e, 0x39, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b } \ } -#define EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID \ - { \ - 0x0964e5b22, 0x6459, 0x11d2, { \ - 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b \ - } \ +#define EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID \ + { \ + 0x0964e5b22, 0x6459, 0x11d2, { 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b } \ } typedef UInt64(EfiImageUnload)(EfiHandlePtr ImageHandle); @@ -373,17 +351,17 @@ typedef struct { typedef EFI_STATUS(EFIAPI* EFI_SIMPLE_NETWORK_TRANSMIT)(IN EFI_SIMPLE_NETWORK_PROTOCOL* This, IN UInt32 HeaderSize, IN UInt32 BufferSize, - IN Void* Buffer, - IN EfiMacAddress* SrcAddr OPTIONAL, + IN Void* Buffer, + IN EfiMacAddress* SrcAddr OPTIONAL, IN EfiMacAddress* DestAddr OPTIONAL, - IN UInt16* Protocol OPTIONAL); + IN UInt16* Protocol OPTIONAL); typedef EFI_STATUS(EFIAPI* EFI_SIMPLE_NETWORK_RECEIVE)(IN EFI_SIMPLE_NETWORK_PROTOCOL* This, - OUT UInt32* HeaderSize OPTIONAL, + OUT UInt32* HeaderSize OPTIONAL, IN OUT UInt32* BufferSize, OUT Void* Buffer, - OUT EfiMacAddress* SrcAddr OPTIONAL, + OUT EfiMacAddress* SrcAddr OPTIONAL, OUT EfiMacAddress* DestAddr OPTIONAL, - OUT UInt16* Protocol OPTIONAL); + OUT UInt16* Protocol OPTIONAL); typedef struct EFI_SIMPLE_NETWORK_PROTOCOL { UInt64 Revision; @@ -528,11 +506,9 @@ typedef struct EFI_GUID EFI_FINAL { * Protocol stuff... */ -#define EFI_SIMPLE_TEXT_INPUT_PROTOCOL_GUID \ - { \ - 0x387477c1, 0x69c7, 0x11d2, { \ - 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b \ - } \ +#define EFI_SIMPLE_TEXT_INPUT_PROTOCOL_GUID \ + { \ + 0x387477c1, 0x69c7, 0x11d2, { 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b } \ } /** some helpers */ @@ -631,7 +607,7 @@ typedef struct { } EfiInputKey; typedef EfiStatusType(EFI_API* EfiInputReadKey)(IN EfiSimpleTextInputProtocol* This, - OUT EfiInputKey* Key); + OUT EfiInputKey* Key); typedef EfiStatusType(EFI_API* EfiInputReset)(IN EfiSimpleTextInputProtocol* This, IN Boolean ExtendedChk); @@ -689,7 +665,7 @@ typedef struct EfiSystemTable { struct { EFI_GUID VendorGUID; VoidPtr VendorTable; - }* ConfigurationTable; + } * ConfigurationTable; } EfiSystemTable; #define kEfiOk 0 @@ -750,11 +726,9 @@ enum { #define EFI_EXTRA_DESCRIPTOR_SIZE 8 -#define EFI_MP_SERVICES_PROTOCOL_GUID \ - { \ - 0x3fdda605, 0xa76e, 0x4f46, { \ - 0xad, 0x29, 0x12, 0xf4, 0x53, 0x1b, 0x3d, 0x08 \ - } \ +#define EFI_MP_SERVICES_PROTOCOL_GUID \ + { \ + 0x3fdda605, 0xa76e, 0x4f46, { 0xad, 0x29, 0x12, 0xf4, 0x53, 0x1b, 0x3d, 0x08 } \ } #define PROCESSOR_AS_BSP_BIT 0x00000001 @@ -851,11 +825,9 @@ typedef struct EfiTime { UInt8 Pad2; } EfiTime; -#define EFI_FILE_INFO_GUID \ - { \ - 0x09576e92, 0x6d3f, 0x11d2, { \ - 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b \ - } \ +#define EFI_FILE_INFO_GUID \ + { \ + 0x09576e92, 0x6d3f, 0x11d2, { 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b } \ } struct EfiFileInfo EFI_FINAL { @@ -924,8 +896,8 @@ typedef EfiStatusType EFI_API (*EfiMpServicesStartupThisAP)( IN Void* ProcedureArgument OPTIONAL, OUT Boolean* Finished OPTIONAL); typedef EfiStatusType EFI_API (*EfiMpServicesDisableThisAP)(IN struct _EfiMpServicesProtocol* Self, - IN UInt32 ProcessorNumber, - IN Boolean EnableAP, + IN UInt32 ProcessorNumber, + IN Boolean EnableAP, IN UInt32* HealthFlag OPTIONAL); typedef EfiStatusType EFI_API (*EfiMpServicesWhoAmI)(IN struct _EfiMpServicesProtocol* Self, diff --git a/dev/kernel/HALKit/AMD64/HalCoreInterruptHandler.cc b/dev/kernel/HALKit/AMD64/HalCoreInterruptHandler.cc index 0c2d0960..b837497e 100644 --- a/dev/kernel/HALKit/AMD64/HalCoreInterruptHandler.cc +++ b/dev/kernel/HALKit/AMD64/HalCoreInterruptHandler.cc @@ -61,7 +61,8 @@ EXTERN_C void idt_handle_scheduler(Kernel::UIntPtr rsp) { hal_idt_send_eoi(32); - while (kIsRunning); + while (kIsRunning) + ; kIsRunning = YES; diff --git a/dev/kernel/HALKit/AMD64/HalKernelMain.cc b/dev/kernel/HALKit/AMD64/HalKernelMain.cc index c7a87b13..3c6e7d36 100644 --- a/dev/kernel/HALKit/AMD64/HalKernelMain.cc +++ b/dev/kernel/HALKit/AMD64/HalKernelMain.cc @@ -168,6 +168,7 @@ EXTERN_C Kernel::Void hal_real_init(Kernel::Void) noexcept { idt_loader.Load(idt_reg); - while (YES); + while (YES) + ; } #endif // ifndef __NE_MODULAR_KERNEL_COMPONENTS__ diff --git a/dev/kernel/HALKit/AMD64/HalSchedulerCorePrimitives.cc b/dev/kernel/HALKit/AMD64/HalSchedulerCorePrimitives.cc index 1dbce4ac..c8f53aa9 100644 --- a/dev/kernel/HALKit/AMD64/HalSchedulerCorePrimitives.cc +++ b/dev/kernel/HALKit/AMD64/HalSchedulerCorePrimitives.cc @@ -13,7 +13,7 @@ namespace Kernel { /// @param /***********************************************************************************/ -EXTERN_C Void __zka_pure_call(USER_PROCESS* process) { +EXTERN_C Void __ne_pure_call(USER_PROCESS* process) { if (process) process->Crash(); } @@ -25,23 +25,27 @@ EXTERN_C Void __zka_pure_call(USER_PROCESS* process) { EXTERN_C Bool hal_check_task(HAL::StackFramePtr stack_ptr) { if (!stack_ptr) return No; - return stack_ptr->SP != 0 && stack_ptr->IP != 0; + return stack_ptr->SP > 0 && stack_ptr->IP > 0; } /// @brief Wakes up thread. /// Wakes up thread from the hang state. Void mp_wakeup_thread(HAL::StackFrame* stack) { - NE_UNUSED(stack); + if (!hal_check_task(stack)) return; + + // RIP is always in R15. R15 is reserved for the RIP. + stack->IP = stack->R15; + Kernel::UserProcessHelper::StartScheduling(); } /// @brief makes the thread sleep on a loop. /// hooks and hangs thread to prevent code from executing. Void mp_hang_thread(HAL::StackFrame* stack) { - NE_UNUSED(stack); + if (!hal_check_task(stack)) return; - while (Yes) { - /* Nothing to do, code is spinning */ - } + // Store IP in R15 + stack->R15 = stack->IP; + stack->IP = 0UL; } } // namespace Kernel diff --git a/dev/kernel/HALKit/AMD64/Paging.h b/dev/kernel/HALKit/AMD64/Paging.h index cf297632..079acde4 100644 --- a/dev/kernel/HALKit/AMD64/Paging.h +++ b/dev/kernel/HALKit/AMD64/Paging.h @@ -57,9 +57,7 @@ namespace Detail { PageEnable = 31, }; - inline UInt8 control_register_cast(ControlRegisterBits reg) { - return static_cast<UInt8>(reg); - } + inline UInt8 control_register_cast(ControlRegisterBits reg) { return static_cast<UInt8>(reg); } } // namespace Detail auto mm_alloc_bitmap(Boolean wr, Boolean user, SizeT size, Bool is_page, SizeT pad = 0) -> VoidPtr; diff --git a/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc b/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc index 3363e809..77e3331d 100644 --- a/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc +++ b/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc @@ -294,7 +294,8 @@ STATIC Void drv_std_input_output_ahci(UInt64 lba, UInt8* buffer, SizeT sector_sz goto ahci_io_end; } else { kout << "ahci: Disk still busy after command completion!\r"; - while (kSATAHba->Ports[kSATAIndex].Tfd & (kSATASRBsy | kSATASRDrq)); + while (kSATAHba->Ports[kSATAIndex].Tfd & (kSATASRBsy | kSATASRDrq)) + ; } ahci_io_end: @@ -307,15 +308,13 @@ STATIC Void drv_std_input_output_ahci(UInt64 lba, UInt8* buffer, SizeT sector_sz @brief Gets the number of sectors inside the drive. @return Sector size in bytes. */ -STATIC ATTRIBUTE(unused) -SizeT drv_get_sector_count_ahci() { +STATIC ATTRIBUTE(unused) SizeT drv_get_sector_count_ahci() { return kSATASectorCount; } /// @brief Get the drive size. /// @return Disk size in bytes. -STATIC ATTRIBUTE(unused) -SizeT drv_get_size_ahci() { +STATIC ATTRIBUTE(unused) SizeT drv_get_size_ahci() { return drv_std_get_sector_count() * kAHCISectorSize; } diff --git a/dev/kernel/HALKit/AMD64/Storage/DMA+Generic.cc b/dev/kernel/HALKit/AMD64/Storage/DMA+Generic.cc index 4688203f..39efb7d3 100644 --- a/dev/kernel/HALKit/AMD64/Storage/DMA+Generic.cc +++ b/dev/kernel/HALKit/AMD64/Storage/DMA+Generic.cc @@ -105,7 +105,7 @@ Void drv_std_read(UInt64 Lba, UInt16 IO, UInt8 Master, Char* Buf, SizeT SectorSz rt_out8(IO + ATA_REG_SEC_COUNT0, ((Size + SectorSz - 1) / 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); @@ -123,7 +123,8 @@ Void drv_std_read(UInt64 Lba, UInt16 IO, UInt8 Master, Char* Buf, SizeT SectorSz rt_out8(kATADevice.Bar(0x20) + 0x00, 0x09); // Start DMA engine - while (rt_in8(kATADevice.Bar(0x20) + ATA_REG_STATUS) & 0x01); + while (rt_in8(kATADevice.Bar(0x20) + ATA_REG_STATUS) & 0x01) + ; rt_out8(kATADevice.Bar(0x20) + 0x00, 0x00); // Stop DMA engine @@ -146,7 +147,7 @@ Void drv_std_write(UInt64 Lba, UInt16 IO, UInt8 Master, Char* Buf, SizeT SectorS rt_out8(IO + ATA_REG_SEC_COUNT0, ((Size + (SectorSz - 1)) / 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); @@ -162,7 +163,8 @@ Void drv_std_write(UInt64 Lba, UInt16 IO, UInt8 Master, Char* Buf, SizeT SectorS rt_out8(IO + 0x00, 0x09); // Start DMA engine - while (rt_in8(kATADevice.Bar(0x20) + ATA_REG_STATUS) & 0x01); + while (rt_in8(kATADevice.Bar(0x20) + ATA_REG_STATUS) & 0x01) + ; rt_out8(kATADevice.Bar(0x20) + 0x00, 0x00); // Stop DMA engine diff --git a/dev/kernel/HALKit/AMD64/Storage/PIO+Generic.cc b/dev/kernel/HALKit/AMD64/Storage/PIO+Generic.cc index 9c5b3931..6fccbdfa 100644 --- a/dev/kernel/HALKit/AMD64/Storage/PIO+Generic.cc +++ b/dev/kernel/HALKit/AMD64/Storage/PIO+Generic.cc @@ -83,7 +83,8 @@ ATAInit_Retry: rt_out8(OutBus + ATA_REG_COMMAND, ATA_CMD_IDENTIFY); - while (!(rt_in8(IO + ATA_REG_STATUS) & ATA_SR_DRQ)); + while (!(rt_in8(IO + ATA_REG_STATUS) & ATA_SR_DRQ)) + ; /// fetch serial info /// model, speed, number of sectors... @@ -116,14 +117,15 @@ Void drv_pio_std_read(UInt64 Lba, UInt16 IO, UInt8 Master, Char* Buf, SizeT Sect 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) { drv_pio_std_wait_io(IO); @@ -147,14 +149,15 @@ Void drv_pio_std_write(UInt64 Lba, UInt16 IO, UInt8 Master, Char* Buf, SizeT Sec 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) { drv_pio_std_wait_io(IO); diff --git a/dev/kernel/HALKit/ARM64/HalCoreInterruptHandler.cc b/dev/kernel/HALKit/ARM64/HalCoreInterruptHandler.cc index 63a42de8..0c26f4cb 100644 --- a/dev/kernel/HALKit/ARM64/HalCoreInterruptHandler.cc +++ b/dev/kernel/HALKit/ARM64/HalCoreInterruptHandler.cc @@ -56,7 +56,8 @@ EXTERN_C void int_handle_scheduler(Kernel::UIntPtr rsp) { hal_int_send_eoi(32); - while (kIsRunning); + while (kIsRunning) + ; kIsRunning = YES; diff --git a/dev/kernel/HALKit/ARM64/HalKernelMain.cc b/dev/kernel/HALKit/ARM64/HalKernelMain.cc index d8e6843b..20bd3d8a 100644 --- a/dev/kernel/HALKit/ARM64/HalKernelMain.cc +++ b/dev/kernel/HALKit/ARM64/HalKernelMain.cc @@ -71,6 +71,7 @@ EXTERN_C void hal_init_platform(Kernel::HEL::BootInfoHeader* handover_hdr) { Kernel::mp_init_cores(); - while (YES); + while (YES) + ; } #endif
\ No newline at end of file diff --git a/dev/kernel/HALKit/ARM64/HalSchedulerCorePrimitives.cc b/dev/kernel/HALKit/ARM64/HalSchedulerCorePrimitives.cc index 10f95e29..2d10fa89 100644 --- a/dev/kernel/HALKit/ARM64/HalSchedulerCorePrimitives.cc +++ b/dev/kernel/HALKit/ARM64/HalSchedulerCorePrimitives.cc @@ -10,10 +10,10 @@ namespace Kernel {
/***********************************************************************************/
/// @brief Unimplemented function (crashes by default)
-/// @param void
+/// @param process The process handle.
/***********************************************************************************/
-EXTERN_C Void __zka_pure_call(USER_PROCESS* process) {
+EXTERN_C Void __ne_pure_call(USER_PROCESS* process) {
if (process) process->Crash();
}
diff --git a/dev/kernel/HALKit/ARM64/Paging.h b/dev/kernel/HALKit/ARM64/Paging.h index be9fb116..7a022141 100644 --- a/dev/kernel/HALKit/ARM64/Paging.h +++ b/dev/kernel/HALKit/ARM64/Paging.h @@ -86,9 +86,7 @@ namespace Detail { PageEnable = 31, }; - inline UInt8 control_register_cast(ControlRegisterBits reg) { - return static_cast<UInt8>(reg); - } + inline UInt8 control_register_cast(ControlRegisterBits reg) { return static_cast<UInt8>(reg); } } // namespace Detail struct PDE_4KB final { diff --git a/dev/kernel/HALKit/POWER/HalApplicationProcessor.cc b/dev/kernel/HALKit/POWER/HalApplicationProcessor.cc index 6059e3be..daa26e53 100644 --- a/dev/kernel/HALKit/POWER/HalApplicationProcessor.cc +++ b/dev/kernel/HALKit/POWER/HalApplicationProcessor.cc @@ -10,7 +10,8 @@ namespace Kernel::Detail { STATIC void mp_hang_fn(void) { - while (YES); + while (YES) + ; } } // namespace Kernel::Detail diff --git a/dev/kernel/HALKit/RISCV/HalApplicationProcessor.cc b/dev/kernel/HALKit/RISCV/HalApplicationProcessor.cc index e6fdddfb..31d4a62e 100644 --- a/dev/kernel/HALKit/RISCV/HalApplicationProcessor.cc +++ b/dev/kernel/HALKit/RISCV/HalApplicationProcessor.cc @@ -13,7 +13,8 @@ using namespace Kernel; namespace Kernel {
namespace Detail {
STATIC void mp_hang_fn(void) {
- while (YES);
+ while (YES)
+ ;
}
} // namespace Detail
diff --git a/dev/kernel/KernelKit/BinaryMutex.h b/dev/kernel/KernelKit/BinaryMutex.h index f2c15af0..abe8d517 100644 --- a/dev/kernel/KernelKit/BinaryMutex.h +++ b/dev/kernel/KernelKit/BinaryMutex.h @@ -28,7 +28,7 @@ class BinaryMutex final { public: bool Lock(USER_PROCESS* process); - bool LockOrWait(USER_PROCESS* process, TimerInterface* timer); + bool LockAndWait(USER_PROCESS* process, TimerInterface* timer); public: NE_COPY_DEFAULT(BinaryMutex) diff --git a/dev/kernel/KernelKit/CoreProcessScheduler.h b/dev/kernel/KernelKit/CoreProcessScheduler.h index a7908b7d..56c2bce0 100644 --- a/dev/kernel/KernelKit/CoreProcessScheduler.h +++ b/dev/kernel/KernelKit/CoreProcessScheduler.h @@ -118,11 +118,6 @@ enum class ProcessSubsystem : Int32 { }; /***********************************************************************************/ -//! @brief Local Process identifier. -/***********************************************************************************/ -typedef Int64 ProcessID; - -/***********************************************************************************/ //! @brief Local Process status enum. /***********************************************************************************/ enum class ProcessStatusKind : Int32 { @@ -181,7 +176,11 @@ inline bool operator>=(AffinityKind lhs, AffinityKind rhs) { using PTime = UInt64; using ProcessTime = PTime; -using PID = Int64; + +/***********************************************************************************/ +//! @brief Local Process identifier. +/***********************************************************************************/ +using ProcessID = Int64; /***********************************************************************************/ /// @note For User manager, tells where we run the code. @@ -201,14 +200,15 @@ using ImagePtr = VoidPtr; /***********************************************************************************/ /// @brief Helper class to contain a process's image and blob. /***********************************************************************************/ -struct PROCESS_IMAGE final { - explicit PROCESS_IMAGE() = default; +struct ProcessImage final { + explicit ProcessImage() = default; private: friend USER_PROCESS; friend KERNEL_TASK; - friend class UserProcessScheduler; + friend UserProcessScheduler; + friend KernelTaskScheduler; ImagePtr fCode{}; ImagePtr fBlob{}; diff --git a/dev/kernel/KernelKit/HardwareThreadScheduler.h b/dev/kernel/KernelKit/HardwareThreadScheduler.h index 168a0cc1..76327a93 100644 --- a/dev/kernel/KernelKit/HardwareThreadScheduler.h +++ b/dev/kernel/KernelKit/HardwareThreadScheduler.h @@ -100,7 +100,7 @@ class HardwareThreadScheduler final : public ISchedulable { public: Ref<HardwareThread*> operator[](SizeT idx); bool operator!() noexcept; - operator bool() noexcept; + operator bool() noexcept; Bool IsUser() override { return Yes; } diff --git a/dev/kernel/KernelKit/IDylibObject.h b/dev/kernel/KernelKit/IDylibObject.h index b673766c..3727e938 100644 --- a/dev/kernel/KernelKit/IDylibObject.h +++ b/dev/kernel/KernelKit/IDylibObject.h @@ -41,5 +41,5 @@ class IDylibObject { }; /// @brief Pure implementation, missing method/function handler. -EXTERN_C void __zka_pure_call(void); +EXTERN_C void __ne_pure_call(void); } // namespace Kernel diff --git a/dev/kernel/KernelKit/IFS.h b/dev/kernel/KernelKit/IFS.h index 5555764f..ed1d87b5 100644 --- a/dev/kernel/KernelKit/IFS.h +++ b/dev/kernel/KernelKit/IFS.h @@ -22,4 +22,4 @@ Int32 fs_ifs_read(MountpointInterface* Mnt, DriveTrait& DrvTrait, Int32 DrvIndex /// @param DrvIndex drive index. /// @return Int32 fs_ifs_write(MountpointInterface* Mnt, DriveTrait& DrvTrait, Int32 DrvIndex); -} // namespace Kernel
\ No newline at end of file +} // namespace Kernel diff --git a/dev/kernel/KernelKit/IPEFDylibObject.h b/dev/kernel/KernelKit/IPEFDylibObject.h index 66b4895d..5788138d 100644 --- a/dev/kernel/KernelKit/IPEFDylibObject.h +++ b/dev/kernel/KernelKit/IPEFDylibObject.h @@ -7,8 +7,8 @@ * ======================================================== */ -#ifndef __KERNELKIT_SHARED_OBJECT_H__ -#define __KERNELKIT_SHARED_OBJECT_H__ +#ifndef __KERNELKIT_PEF_SHARED_OBJECT_H__ +#define __KERNELKIT_PEF_SHARED_OBJECT_H__ #include <KernelKit/IDylibObject.h> #include <KernelKit/PEF.h> @@ -38,7 +38,7 @@ class IPEFDylibObject final NE_DYLIB_OBJECT { DylibTraits* Get() { return fMounted; } public: - void Mount(DylibTraits* to_mount) { + void Mount(DylibTraits* to_mount) noexcept { if (!to_mount || !to_mount->ImageObject) return; fMounted = to_mount; @@ -53,19 +53,19 @@ class IPEFDylibObject final NE_DYLIB_OBJECT { } } - void Unmount() { + void Unmount() noexcept { if (fMounted) fMounted = nullptr; }; template <typename SymbolType> - SymbolType Load(const Char* symbol_name, SizeT len, Int32 kind) { + SymbolType Load(const Char* symbol_name, const SizeT& len, const UInt32& kind) { if (symbol_name == nullptr || *symbol_name == 0) return nullptr; if (len > kPathLen || len < 1) return nullptr; auto ret = reinterpret_cast<SymbolType>(fLoader->FindSymbol(symbol_name, kind).Leak().Leak()); if (!ret) { - if (kind == kPefCode) return (VoidPtr) &__zka_pure_call; + if (kind == kPefCode) return (VoidPtr) &__ne_pure_call; return nullptr; } @@ -83,4 +83,4 @@ EXTERN_C IDylibRef rtl_init_dylib_pef(USER_PROCESS& header); EXTERN_C Void rtl_fini_dylib_pef(USER_PROCESS& header, IDylibRef lib, Bool* successful); } // namespace Kernel -#endif /* ifndef __KERNELKIT_SHARED_OBJECT_H__ */ +#endif /* ifndef __KERNELKIT_PEF_SHARED_OBJECT_H__ */ diff --git a/dev/kernel/KernelKit/KernelTaskScheduler.h b/dev/kernel/KernelKit/KernelTaskScheduler.h index c0879769..527eec5e 100644 --- a/dev/kernel/KernelKit/KernelTaskScheduler.h +++ b/dev/kernel/KernelKit/KernelTaskScheduler.h @@ -17,7 +17,7 @@ namespace Kernel { class KernelTaskHelper; -typedef PID KID; +typedef ProcessID KID; /// @brief Equivalent of USER_PROCESS, but for kernel tasks. /// @author Amlal @@ -28,7 +28,7 @@ class KERNEL_TASK final { HAL::StackFramePtr StackFrame{nullptr}; UInt8* StackReserve{nullptr}; SizeT StackSize{kSchedMaxStackSz}; - PROCESS_IMAGE Image{}; + ProcessImage Image{}; /// @brief a KID is a Kernel Identification Descriptor, it is used to find a task running within /// the kernel. KID Kid{0}; @@ -38,9 +38,9 @@ class KERNEL_TASK final { /// @author Amlal class KernelTaskHelper final { public: - STATIC Bool Switch(HAL::StackFramePtr frame_ptr, PID new_kid); + STATIC Bool Switch(HAL::StackFramePtr frame_ptr, ProcessID new_kid); STATIC Bool CanBeScheduled(const KERNEL_TASK& process); - STATIC ErrorOr<PID> TheCurrentKID(); + STATIC ErrorOr<ProcessID> TheCurrentKID(); STATIC SizeT StartScheduling(); }; } // namespace Kernel
\ No newline at end of file diff --git a/dev/kernel/KernelKit/LoaderInterface.h b/dev/kernel/KernelKit/LoaderInterface.h index ed7d8364..1f9b1e56 100644 --- a/dev/kernel/KernelKit/LoaderInterface.h +++ b/dev/kernel/KernelKit/LoaderInterface.h @@ -23,9 +23,9 @@ class LoaderInterface { public: virtual _Output ErrorOr<VoidPtr> GetBlob() = 0; - virtual _Output const Char* AsString() = 0; - virtual _Output const Char* MIME() = 0; - virtual _Output const Char* Path() = 0; + virtual _Output const Char* AsString() = 0; + virtual _Output const Char* MIME() = 0; + virtual _Output const Char* Path() = 0; virtual _Output ErrorOr<VoidPtr> FindStart() = 0; virtual _Output ErrorOr<VoidPtr> FindSymbol(_Input const Char* name, _Input Int32 kind) = 0; }; diff --git a/dev/kernel/KernelKit/PCI/DMA.h b/dev/kernel/KernelKit/PCI/DMA.h index c4e3b61a..7e7d3f0c 100644 --- a/dev/kernel/KernelKit/PCI/DMA.h +++ b/dev/kernel/KernelKit/PCI/DMA.h @@ -47,7 +47,7 @@ class DMAWrapper final { T* Get(UIntPtr off = 0); public: - operator bool(); + operator bool(); bool operator!(); public: diff --git a/dev/kernel/KernelKit/PEF.h b/dev/kernel/KernelKit/PEF.h index fd39392e..f0ba9ef9 100644 --- a/dev/kernel/KernelKit/PEF.h +++ b/dev/kernel/KernelKit/PEF.h @@ -59,19 +59,20 @@ enum { }; enum { - kPefSubArchGeneric, - kPefSubArchAMD = 200, + kPefSubArchGeneric = 0, + kPefSubArchAMD = 200, kPefSubArchIntel, kPefSubArchARM, kPefSubArchIBM, }; enum { - kPefKindExec = 1, /* .exec */ - kPefKindDylib = 2, /* .dylib */ - kPefKindObject = 4, /* .obj */ - kPefKindDebug = 5, /* .dbg */ - kPefKindDriver = 6, + kPefKindInvalid = 0, + kPefKindExec = 1, /* .exec */ + kPefKindDylib = 2, /* .dylib */ + kPefKindObject = 4, /* .obj */ + kPefKindDebug = 5, /* .dbg */ + kPefKindDriver = 6, kPefKindCount, }; diff --git a/dev/kernel/KernelKit/UserProcessScheduler.h b/dev/kernel/KernelKit/UserProcessScheduler.h index 3dae178a..a7ef13a9 100644 --- a/dev/kernel/KernelKit/UserProcessScheduler.h +++ b/dev/kernel/KernelKit/UserProcessScheduler.h @@ -48,7 +48,7 @@ class USER_PROCESS final { AffinityKind Affinity{AffinityKind::kStandard}; ProcessStatusKind Status{ProcessStatusKind::kKilled}; UInt8 StackReserve[kSchedMaxStackSz]; - PROCESS_IMAGE Image{}; + ProcessImage Image{}; SizeT StackSize{kSchedMaxStackSz}; IDylibObject* DylibDelegate{nullptr}; SizeT MemoryCursor{0UL}; @@ -79,7 +79,7 @@ class USER_PROCESS final { ProcessTime RTime{0}; //! @brief Process run time. ProcessTime UTime{0}; //! #brief Process used time. - PID ProcessId{kSchedInvalidPID}; + ProcessID ProcessId{kSchedInvalidPID}; Int32 Kind{kExecutableKind}; public: @@ -192,7 +192,7 @@ class UserProcessScheduler final : public ISchedulable { NE_MOVE_DELETE(UserProcessScheduler) public: - operator bool(); + operator bool(); bool operator!(); public: @@ -226,9 +226,9 @@ class UserProcessScheduler final : public ISchedulable { class UserProcessHelper final { public: - STATIC Bool Switch(HAL::StackFramePtr frame_ptr, PID new_pid); + STATIC Bool Switch(HAL::StackFramePtr frame_ptr, ProcessID new_pid); STATIC Bool CanBeScheduled(const USER_PROCESS& process); - STATIC ErrorOr<PID> TheCurrentPID(); + STATIC ErrorOr<ProcessID> TheCurrentPID(); STATIC SizeT StartScheduling(); }; } // namespace Kernel diff --git a/dev/kernel/KernelKit/ZXD.h b/dev/kernel/KernelKit/ZXD.h index 10af568b..f1c99a21 100644 --- a/dev/kernel/KernelKit/ZXD.h +++ b/dev/kernel/KernelKit/ZXD.h @@ -8,15 +8,16 @@ #include <NeKit/Defines.h> -namespace ZXD { -using namespace Kernel; +#define kZXDMagicNumber (0x2010AF) +#define kZXDVersion (0x0001) +namespace Kernel { struct ZXD_EXEC_HEADER; struct ZXD_STUB_HEADER; /// @brief ZXD executable header /// @details This header is used to identify ZXD executable files. -struct ZXD_EXEC_HEADER { +struct PACKED ZXD_EXEC_HEADER { UInt32 fMagic; UInt32 fVersion; UInt32 fFlags; @@ -35,9 +36,9 @@ struct ZXD_EXEC_HEADER { /// @brief ZXD stub header /// @details This header is used to identify ZXD stub files. It contains the size of the stub, the /// offset of the stub, and the CRC32 checksum of the stub. -struct ZXD_STUB_HEADER { +struct PACKED ZXD_STUB_HEADER { UInt32 fStubSize; UInt32 fStubOffset; UInt32 fStubCRC32; }; -} // namespace ZXD
\ No newline at end of file +} // namespace Kernel diff --git a/dev/kernel/NeKit/Json.h b/dev/kernel/NeKit/Json.h index 2b2c9c04..24357dd7 100644 --- a/dev/kernel/NeKit/Json.h +++ b/dev/kernel/NeKit/Json.h @@ -25,8 +25,8 @@ namespace Kernel { class Json final { public: explicit Json() { - auto len = kJSONMaxLen; - KString key = KString(len); + auto len = kJSONMaxLen; + BasicKString<> key = KString(len); key += kJSONNullObj; this->AsKey() = key; @@ -42,18 +42,18 @@ class Json final { Bool& IsUndefined() { return fUndefined; } private: - Bool fUndefined; // is this instance undefined? - KString fKey; - KString fValue; + Bool fUndefined; // is this instance undefined? + BasicKString<> fKey; + BasicKString<> fValue; public: /// @brief returns the key of the json /// @return the key as string view. - KString& AsKey() { return fKey; } + BasicKString<>& AsKey() { return fKey; } /// @brief returns the value of the json. /// @return the key as string view. - KString& AsValue() { return fValue; } + BasicKString<>& AsValue() { return fValue; } static Json kNull; }; diff --git a/dev/kernel/NeKit/KString.h b/dev/kernel/NeKit/KString.h index 16b09a78..bbe49f8e 100644 --- a/dev/kernel/NeKit/KString.h +++ b/dev/kernel/NeKit/KString.h @@ -16,10 +16,11 @@ namespace Kernel { /// @brief Kernel string class, not dynamic. -class KString final { +template <SizeT MinSz = kMinimumStringSize> +class BasicKString final { public: - explicit KString() { - fDataSz = kMinimumStringSize; + explicit BasicKString() { + fDataSz = MinSz; fData = new Char[fDataSz]; MUST_PASS(fData); @@ -27,7 +28,7 @@ class KString final { rt_set_memory(fData, 0, fDataSz); } - explicit KString(SizeT Sz) : fDataSz(Sz) { + explicit BasicKString(SizeT Sz) : fDataSz(Sz) { MUST_PASS(Sz > 1); fData = new Char[Sz]; @@ -36,14 +37,14 @@ class KString final { rt_set_memory(fData, 0, Sz); } - ~KString() { + ~BasicKString() { if (fData) { delete[] fData; fData = nullptr; } } - NE_COPY_DEFAULT(KString) + NE_COPY_DEFAULT(BasicKString) Char* Data(); const Char* CData() const; @@ -52,11 +53,13 @@ class KString final { bool operator==(const Char* rhs) const; bool operator!=(const Char* rhs) const; - bool operator==(const KString& rhs) const; - bool operator!=(const KString& rhs) const; + bool operator==(const BasicKString<>& rhs) const; + bool operator!=(const BasicKString<>& rhs) const; - KString& operator+=(const Char* rhs); - KString& operator+=(const KString& rhs); + BasicKString<>& operator+=(const Char* rhs); + BasicKString<>& operator+=(const BasicKString<>& rhs); + + operator const char*() { return fData; } operator bool() { return fData; } @@ -70,6 +73,9 @@ class KString final { friend class KStringBuilder; }; +using KString = BasicKString<>; +using KStringOr = ErrorOr<KString>; + class KStringBuilder final { public: static ErrorOr<KString> Construct(const Char* data); @@ -77,6 +83,7 @@ class KStringBuilder final { static const Char* Format(const Char* fmt, const Char* from); static bool Equals(const Char* lhs, const Char* rhs); static bool Equals(const Utf8Char* lhs, const Utf8Char* rhs); - static bool Equals(const WideChar* lhs, const WideChar* rhs); }; } // namespace Kernel + +#include <NeKit/KString.inl> diff --git a/dev/kernel/src/KString.cc b/dev/kernel/NeKit/KString.inl index f5732280..1faefb08 100644 --- a/dev/kernel/src/KString.cc +++ b/dev/kernel/NeKit/KString.inl @@ -4,26 +4,38 @@ ------------------------------------------- */ -#include <NeKit/KString.h> #include <NeKit/Utils.h> -/// @file KString.cc +/// @file BasicKString<>.cc /// @brief Kernel String manipulation file. namespace Kernel { -Char* KString::Data() { +inline void rt_string_append(Char* lhs, const Char* rhs, Int32 cur) { + SizeT sz_rhs = rt_string_len(rhs); + SizeT rhs_i = 0; + + for (; rhs_i < sz_rhs; ++rhs_i) { + lhs[rhs_i + cur] = rhs[rhs_i]; + } +} + +template <> +inline Char* BasicKString<>::Data() { return this->fData; } -const Char* KString::CData() const { +template <> +inline const Char* BasicKString<>::CData() const { return const_cast<const Char*>(this->fData); } -Size KString::Length() const { +template <> +inline SizeT BasicKString<>::Length() const { return this->fDataSz; } -bool KString::operator==(const KString& rhs) const { +template <> +inline bool BasicKString<>::operator==(const BasicKString<>& rhs) const { if (rhs.Length() != this->Length()) return false; for (Size index = 0; index < this->Length(); ++index) { @@ -33,7 +45,8 @@ bool KString::operator==(const KString& rhs) const { return true; } -bool KString::operator==(const Char* rhs) const { +template <> +inline bool BasicKString<>::operator==(const Char* rhs) const { if (rt_string_len(rhs) != this->Length()) return false; for (Size index = 0; index < rt_string_len(rhs); ++index) { @@ -43,7 +56,8 @@ bool KString::operator==(const Char* rhs) const { return true; } -bool KString::operator!=(const KString& rhs) const { +template <> +inline bool BasicKString<>::operator!=(const BasicKString<>& rhs) const { if (rhs.Length() != this->Length()) return false; for (Size index = 0; index < rhs.Length(); ++index) { @@ -53,7 +67,8 @@ bool KString::operator!=(const KString& rhs) const { return true; } -bool KString::operator!=(const Char* rhs) const { +template <> +inline bool BasicKString<>::operator!=(const Char* rhs) const { if (rt_string_len(rhs) != this->Length()) return false; for (Size index = 0; index < rt_string_len(rhs); ++index) { @@ -63,16 +78,34 @@ bool KString::operator!=(const Char* rhs) const { return true; } -ErrorOr<KString> KStringBuilder::Construct(const Char* data) { - if (!data || *data == 0) return ErrorOr<KString>(new KString(0)); +template <> +inline BasicKString<>& BasicKString<>::operator+=(const BasicKString<>& rhs) { + if (rt_string_len(rhs.fData) > this->Length()) return *this; + + rt_string_append(this->fData, const_cast<Char*>(rhs.fData), this->fCur); + this->fCur += rt_string_len(const_cast<Char*>(rhs.fData)); - KString* view = new KString(rt_string_len(data)); + return *this; +} + +template <> +inline BasicKString<>& BasicKString<>::operator+=(const Char* rhs) { + rt_string_append(this->fData, const_cast<Char*>(rhs), this->fCur); + this->fCur += rt_string_len(const_cast<Char*>(rhs)); + + return *this; +} + +inline ErrorOr<BasicKString<>> KStringBuilder::Construct(const Char* data) { + if (!data || *data == 0) return ErrorOr<BasicKString<>>(new BasicKString<>(0)); + + BasicKString<>* view = new BasicKString<>(rt_string_len(data)); (*view) += data; - return ErrorOr<KString>(*view); + return ErrorOr<BasicKString<>>(*view); } -const Char* KStringBuilder::FromBool(const Char* fmt, bool i) { +inline const Char* KStringBuilder::FromBool(const Char* fmt, bool i) { if (!fmt) return ("?"); const Char* boolean_expr = i ? "YES" : "NO"; @@ -101,7 +134,7 @@ const Char* KStringBuilder::FromBool(const Char* fmt, bool i) { return ret; } -bool KStringBuilder::Equals(const Char* lhs, const Char* rhs) { +inline bool KStringBuilder::Equals(const Char* lhs, const Char* rhs) { if (rt_string_len(rhs) != rt_string_len(lhs)) return false; for (Size index = 0; index < rt_string_len(rhs); ++index) { @@ -111,16 +144,9 @@ bool KStringBuilder::Equals(const Char* lhs, const Char* rhs) { return true; } -/// @note This is unsafe!!! -bool KStringBuilder::Equals(const Utf8Char* lhs, const Utf8Char* rhs) { - for (Size index = 0; index < urt_string_len(rhs); ++index) { - if (rhs[index] != lhs[index]) return false; - } +inline bool KStringBuilder::Equals(const Utf8Char* lhs, const Utf8Char* rhs) { + if (urt_string_len(rhs) != urt_string_len(lhs)) return false; - return true; -} - -bool KStringBuilder::Equals(const WideChar* lhs, const WideChar* rhs) { for (Size index = 0; rhs[index] != 0; ++index) { if (rhs[index] != lhs[index]) return false; } @@ -128,7 +154,7 @@ bool KStringBuilder::Equals(const WideChar* lhs, const WideChar* rhs) { return true; } -const Char* KStringBuilder::Format(const Char* fmt, const Char* fmt2) { +inline const Char* KStringBuilder::Format(const Char* fmt, const Char* fmt2) { if (!fmt || !fmt2) return ("?"); Char* ret = (Char*) RTL_ALLOCA(sizeof(char) * (rt_string_len(fmt2) + rt_string_len(fmt))); @@ -152,29 +178,4 @@ const Char* KStringBuilder::Format(const Char* fmt, const Char* fmt2) { return ret; } - -STATIC void rt_string_append(Char* lhs, const Char* rhs, Int32 cur) { - SizeT sz_rhs = rt_string_len(rhs); - SizeT rhs_i = 0; - - for (; rhs_i < sz_rhs; ++rhs_i) { - lhs[rhs_i + cur] = rhs[rhs_i]; - } -} - -KString& KString::operator+=(const Char* rhs) { - rt_string_append(this->fData, rhs, this->fCur); - this->fCur += rt_string_len(rhs); - - return *this; -} - -KString& KString::operator+=(const KString& rhs) { - if (rt_string_len(rhs.fData) > this->Length()) return *this; - - rt_string_append(this->fData, const_cast<Char*>(rhs.fData), this->fCur); - this->fCur += rt_string_len(const_cast<Char*>(rhs.fData)); - - return *this; -} } // namespace Kernel diff --git a/dev/kernel/NeKit/Macros.h b/dev/kernel/NeKit/Macros.h index e80e2e47..b46ffaa8 100644 --- a/dev/kernel/NeKit/Macros.h +++ b/dev/kernel/NeKit/Macros.h @@ -16,7 +16,7 @@ #endif #ifndef kib_cast -#define kib_cast(X) (Kernel::UInt64)((X) * 1024) +#define kib_cast(X) (Kernel::UInt64)((X) *1024) #endif #ifndef MIB diff --git a/dev/kernel/NeKit/MutableArray.h b/dev/kernel/NeKit/MutableArray.h index 8dee6e03..02c8dc2d 100644 --- a/dev/kernel/NeKit/MutableArray.h +++ b/dev/kernel/NeKit/MutableArray.h @@ -9,21 +9,21 @@ #include <NeKit/Array.h> #include <NeKit/Defines.h> -#define TRY_FIND_NODE(NAME, NODE) \ +#define RTL_TRY_FIND_NODE(NAME, NODE) \ auto* NAME = NODE; \ while (NAME) { \ if (NAME->fIndex == Index) return NAME->fVal; \ NAME = NAME->fNext; \ } -#define TRY_FIND_NODE2(NAME, NODE) \ +#define RTL_TRY_FIND_NODE2(NAME, NODE) \ auto* NAME = NODE; \ while (NAME) { \ if (NAME->fIndex == Index) return Ref<T>{NAME->fVal}; \ NAME = NAME->fNext; \ } -#define TRY_REMOVE_NODE(NODE) \ +#define RTL_TRY_REMOVE_NODE(NODE) \ if (NODE && NODE->fIndex == Index) { \ NODE->fUsed = false; \ NODE->fIndex = 0; \ @@ -31,7 +31,7 @@ return true; \ } -// FIXME: this is a shitty algorithm, which is consumer hungry. +// FIXME: this is a shitty algorithm, because it is memory heavy. // Remove and occurences of that, and remove that class. namespace Kernel { template <typename T> @@ -81,8 +81,8 @@ class NullableMutableArray { public: T operator[](SizeT Index) const { - TRY_FIND_NODE(first, fFirstNode); - TRY_FIND_NODE(last, fLastNode); + RTL_TRY_FIND_NODE(first, fFirstNode); + RTL_TRY_FIND_NODE(last, fLastNode); return _PlaceHolderValue; } @@ -91,8 +91,8 @@ class NullableMutableArray { public: Boolean Remove(SizeT Index) { - TRY_REMOVE_NODE(fFirstNode); - TRY_REMOVE_NODE(fLastNode); + RTL_TRY_REMOVE_NODE(fFirstNode); + RTL_TRY_REMOVE_NODE(fLastNode); return false; } @@ -172,8 +172,8 @@ class MutableArray : public NullableMutableArray<voidPtr, nullptr> { public: Ref<T> operator[](SizeT Index) const { - TRY_FIND_NODE2(first, fFirstNode); - TRY_FIND_NODE2(last, fLastNode); + RTL_TRY_FIND_NODE2(first, fFirstNode); + RTL_TRY_FIND_NODE2(last, fLastNode); return {}; } diff --git a/dev/kernel/NeKit/OwnPtr.h b/dev/kernel/NeKit/OwnPtr.h index f5ff4b54..22435118 100644 --- a/dev/kernel/NeKit/OwnPtr.h +++ b/dev/kernel/NeKit/OwnPtr.h @@ -50,7 +50,7 @@ class OwnPtr final { Ref<T> AsRef() { return Ref<T>(fCls); } - operator bool() { return fCls; } + operator bool() { return fCls; } bool operator!() { return !fCls; } private: @@ -61,7 +61,6 @@ template <typename T, typename... Args> inline OwnPtr<T> mm_make_own_ptr(Args... args) { OwnPtr<T> ret; ret.template New<Args...>(forward(args)...); - MUST_PASS(ret); return ret; } diff --git a/dev/kernel/NeKit/Utils.h b/dev/kernel/NeKit/Utils.h index 11566008..a7576e77 100644 --- a/dev/kernel/NeKit/Utils.h +++ b/dev/kernel/NeKit/Utils.h @@ -34,7 +34,7 @@ voidPtr rt_set_memory_safe(voidPtr dst, UInt32 value, Size len, Size dst_size); /// UNICODE API -Int urt_string_cmp(const Char* src, const Char* cmp, Size len); +Int urt_string_cmp(const Utf8Char* src, const Utf8Char* cmp, Size len); Void urt_set_memory(const voidPtr src, UInt32 dst, Size len); Int urt_copy_memory(const voidPtr src, voidPtr dst, Size len); Size urt_string_len(const Utf8Char* str); diff --git a/dev/kernel/NetworkKit/IPC.h b/dev/kernel/NetworkKit/IPC.h index d14356c0..223a112b 100644 --- a/dev/kernel/NetworkKit/IPC.h +++ b/dev/kernel/NetworkKit/IPC.h @@ -20,7 +20,7 @@ /// IA separator. #define kIPCRemoteSeparator ":" -/// Interchange address, consists of PID:TEAM. +/// Interchange address, consists of ProcessID:TEAM. #define kIPCRemoteInvalid "00:00" #define kIPCHeaderMagic (0x4950434) diff --git a/dev/kernel/src/ACPIFactoryInterface.cc b/dev/kernel/src/ACPIFactoryInterface.cc index 01f30500..b4ac03cc 100644 --- a/dev/kernel/src/ACPIFactoryInterface.cc +++ b/dev/kernel/src/ACPIFactoryInterface.cc @@ -70,11 +70,11 @@ ErrorOr<voidPtr> ACPIFactoryInterface::Find(const Char* signature) { @param len the length of it. */ bool ACPIFactoryInterface::Checksum(const Char* checksum, SSizeT len) { - if (len == 0) return 1; + if (len == 0 || !checksum) return false; - char chr = 0; + Char chr = 0; - for (int index = 0; index < len; ++index) { + for (SSizeT index = 0L; index < len; ++index) { chr += checksum[index]; } @@ -82,6 +82,7 @@ bool ACPIFactoryInterface::Checksum(const Char* checksum, SSizeT len) { } ErrorOr<voidPtr> ACPIFactoryInterface::operator[](const Char* signature) { + if (!signature) return ErrorOr<voidPtr>{-kErrorInvalidData}; return this->Find(signature); } } // namespace Kernel diff --git a/dev/kernel/src/AsciiUtils.cc b/dev/kernel/src/AsciiUtils.cc index 66a4aaef..24e4e220 100644 --- a/dev/kernel/src/AsciiUtils.cc +++ b/dev/kernel/src/AsciiUtils.cc @@ -73,7 +73,8 @@ Void rt_zero_memory(voidPtr pointer, Size len) { #ifdef __NE_ENFORCE_DEPRECATED_WARNINGS [[deprecated("Use rt_set_memory_safe instead")]] #endif -voidPtr rt_set_memory(voidPtr src, UInt32 value, Size len) { +voidPtr +rt_set_memory(voidPtr src, UInt32 value, Size len) { if (!src) return nullptr; auto p = reinterpret_cast<UInt8*>(src); UInt8 v = static_cast<UInt8>(value & 0xFF); diff --git a/dev/kernel/src/BinaryMutex.cc b/dev/kernel/src/BinaryMutex.cc index 9bfb89d9..3fef477c 100644 --- a/dev/kernel/src/BinaryMutex.cc +++ b/dev/kernel/src/BinaryMutex.cc @@ -46,7 +46,7 @@ Bool BinaryMutex::IsLocked() const { /// @brief Try lock or wait. /***********************************************************************************/ -Bool BinaryMutex::LockOrWait(USER_PROCESS* process, TimerInterface* timer) { +Bool BinaryMutex::LockAndWait(USER_PROCESS* process, TimerInterface* timer) { if (timer == nullptr) return No; this->Lock(process); diff --git a/dev/kernel/src/FS/HeFS+FileSystemParser.cc b/dev/kernel/src/FS/HeFS+FileSystemParser.cc index 344369d5..f1531b4c 100644 --- a/dev/kernel/src/FS/HeFS+FileSystemParser.cc +++ b/dev/kernel/src/FS/HeFS+FileSystemParser.cc @@ -91,14 +91,14 @@ namespace Detail { STATIC UInt64 hefsi_hash_64(const Utf8Char* path) { if (!path || *path == 0) return 0; - const UInt64 FNV_OFFSET_BASIS = 0xcbf29ce484222325ULL; - const UInt64 FNV_PRIME = 0x100000001b3ULL; + const UInt64 kFnvBaseOffset = 0xcbf29ce484222325ULL; + const UInt64 kFnvPrimeNumber = 0x100000001b3ULL; - UInt64 hash = FNV_OFFSET_BASIS; + UInt64 hash = kFnvBaseOffset; while (*path) { hash ^= (Utf8Char) (*path++); - hash *= FNV_PRIME; + hash *= kFnvPrimeNumber; } return hefsi_to_big_endian_64(hash); diff --git a/dev/kernel/src/FS/NeFS+FileSystemParser.cc b/dev/kernel/src/FS/NeFS+FileSystemParser.cc index 7b9ebcd6..14e0b974 100644 --- a/dev/kernel/src/FS/NeFS+FileSystemParser.cc +++ b/dev/kernel/src/FS/NeFS+FileSystemParser.cc @@ -154,8 +154,8 @@ _Output BOOL NeFileSystemParser::CreateFork(_Input NEFS_FORK_STRUCT& the_fork) { /// @return the newly found fork. /***********************************************************************************/ _Output NEFS_FORK_STRUCT* NeFileSystemParser::FindFork(_Input NEFS_CATALOG_STRUCT* catalog, - _Input const Char* name, - _Input Boolean is_data) { + _Input const Char* name, + _Input Boolean is_data) { if (!catalog || !name) return nullptr; auto& drive = kMountpoint.A(); @@ -217,7 +217,7 @@ _Output NEFS_CATALOG_STRUCT* NeFileSystemParser::CreateCatalog(_Input const Char /// @param kind the catalog kind. /// @return catalog pointer. /***********************************************************************************/ -_Output NEFS_CATALOG_STRUCT* NeFileSystemParser::CreateCatalog(_Input const Char* name, +_Output NEFS_CATALOG_STRUCT* NeFileSystemParser::CreateCatalog(_Input const Char* name, _Input const Int32& flags, _Input const Int32& kind) { kout << "CreateCatalog(*...*)\r"; diff --git a/dev/kernel/src/IndexableProperty.cc b/dev/kernel/src/IndexableProperty.cc index 251d6645..c11e328d 100644 --- a/dev/kernel/src/IndexableProperty.cc +++ b/dev/kernel/src/IndexableProperty.cc @@ -18,21 +18,13 @@ namespace Kernel { namespace Indexer { - Index& IndexableProperty::Leak() noexcept { - return fIndex; - } + Index& IndexableProperty::Leak() noexcept { return fIndex; } - Void IndexableProperty::AddFlag(Int16 flag) { - fFlags |= flag; - } + Void IndexableProperty::AddFlag(Int16 flag) { fFlags |= flag; } - Void IndexableProperty::RemoveFlag(Int16 flag) { - fFlags &= flag; - } + Void IndexableProperty::RemoveFlag(Int16 flag) { fFlags &= flag; } - Int16 IndexableProperty::HasFlag(Int16 flag) { - return fFlags & flag; - } + Int16 IndexableProperty::HasFlag(Int16 flag) { return fFlags & flag; } /// @brief Index a file into the indexer instance. /// @param filename filesystem path to access. diff --git a/dev/kernel/src/Network/IPAddr.cc b/dev/kernel/src/Network/IPAddress.cc index ec7d8a35..b02eae08 100644 --- a/dev/kernel/src/Network/IPAddr.cc +++ b/dev/kernel/src/Network/IPAddress.cc @@ -91,11 +91,14 @@ bool IPFactory::IpCheckVersion4(const Char* ip) { Int32 cnter = 0; Int32 dot_cnter = 0; + constexpr const auto kIP4DotCharacter = '.'; + for (SizeT base = 0; base < rt_string_len(ip); ++base) { - if (ip[base] == '.') { + if (ip[base] == kIP4DotCharacter) { cnter = 0; ++dot_cnter; } else { + if (ip[base] > '5' || ip[base] < '0') return NO; if (!rt_is_alnum(ip[base])) return NO; if (cnter == 3) return NO; diff --git a/dev/kernel/src/Network/IPCAddr.cc b/dev/kernel/src/Network/IPCAddress.cc index 4c1dd500..4c1dd500 100644 --- a/dev/kernel/src/Network/IPCAddr.cc +++ b/dev/kernel/src/Network/IPCAddress.cc diff --git a/dev/kernel/src/Network/IPCMsg.cc b/dev/kernel/src/Network/IPCMessage.cc index 9abefcef..6f8223f7 100644 --- a/dev/kernel/src/Network/IPCMsg.cc +++ b/dev/kernel/src/Network/IPCMessage.cc @@ -105,10 +105,12 @@ Bool IPC_MSG::Pass(IPC_MSG* src, IPC_MSG* target) noexcept { if (src->IpcMsgSz > target->IpcMsgSz) return No; if (target->IpcMsgSz > src->IpcMsgSz) return No; - UInt32 timeout = 0U; + auto timeout = 0U; + + const auto kLimitTimeout = 1000000U; while ((target->IpcLock % kIPCLockUsed) != 0) { - if (timeout > 100000U) { + if (timeout > kLimitTimeout) { return No; } } diff --git a/dev/kernel/src/Property.cc b/dev/kernel/src/Property.cc index 62aa6ef2..581da501 100644 --- a/dev/kernel/src/Property.cc +++ b/dev/kernel/src/Property.cc @@ -21,14 +21,14 @@ Property::Property() = default; /// @brief Check if property's name equals to name. /// @param name string to check. /***********************************************************************************/ -Bool Property::StringEquals(KString& name) { +Bool Property::StringEquals(BasicKString<>& name) { return this->fName && this->fName == name; } /***********************************************************************************/ /// @brief Gets the key (name) of property. /***********************************************************************************/ -KString& Property::GetKey() { +BasicKString<>& Property::GetKey() { return this->fName; } diff --git a/dev/kernel/src/UserProcessScheduler.cc b/dev/kernel/src/UserProcessScheduler.cc index 45957c7b..19e509ed 100644 --- a/dev/kernel/src/UserProcessScheduler.cc +++ b/dev/kernel/src/UserProcessScheduler.cc @@ -122,7 +122,7 @@ ErrorOr<VoidPtr> USER_PROCESS::New(SizeT sz, SizeT pad_amount) { hal_write_cr3(vm_register); #else - auto ptr = mm_alloc_ptr(sz, Yes, Yes, pad_amount); + auto ptr = mm_alloc_ptr(sz, Yes, Yes, pad_amount); #endif if (!this->HeapTree) { @@ -265,7 +265,6 @@ STATIC Void sched_free_ptr_tree(T* tree) { Void USER_PROCESS::Exit(const Int32& exit_code) { this->Status = exit_code > 0 ? ProcessStatusKind::kKilled : ProcessStatusKind::kFrozen; this->LastExitCode = exit_code; - this->UTime = 0; #ifdef __NE_VIRTUAL_MEMORY_SUPPORT__ auto pd = kKernelVM; @@ -424,6 +423,7 @@ ProcessID UserProcessScheduler::Spawn(const Char* name, VoidPtr code, VoidPtr im process.ProcessId = pid; process.Status = ProcessStatusKind::kRunning; process.PTime = 0; + process.UTime = 0; process.RTime = 0; if (!process.FileTree) { @@ -437,7 +437,7 @@ ProcessID UserProcessScheduler::Spawn(const Char* name, VoidPtr code, VoidPtr im /// @todo File Tree allocation and dispose methods (amlal) } - (Void)(kout << "PID: " << number(process.ProcessId) << kendl); + (Void)(kout << "ProcessID: " << number(process.ProcessId) << kendl); (Void)(kout << "Name: " << process.Name << kendl); return pid; @@ -573,11 +573,11 @@ Ref<USER_PROCESS>& UserProcessScheduler::TheCurrentProcess() { /// @brief Current proccess id getter. /// @return USER_PROCESS ID integer. -ErrorOr<PID> UserProcessHelper::TheCurrentPID() { - if (!UserProcessScheduler::The().TheCurrentProcess()) return ErrorOr<PID>{-kErrorProcessFault}; +ErrorOr<ProcessID> UserProcessHelper::TheCurrentPID() { + if (!UserProcessScheduler::The().TheCurrentProcess()) return ErrorOr<ProcessID>{-kErrorProcessFault}; kout << "UserProcessHelper::TheCurrentPID: Leaking ProcessId...\r"; - return ErrorOr<PID>{UserProcessScheduler::The().TheCurrentProcess().Leak().ProcessId}; + return ErrorOr<ProcessID>{UserProcessScheduler::The().TheCurrentProcess().Leak().ProcessId}; } /// @brief Check if process can be schedulded. @@ -613,11 +613,11 @@ SizeT UserProcessHelper::StartScheduling() { /** * \brief Does a context switch in a CPU. * \param the_stack the stackframe of the running app. - * \param new_pid the process's PID. + * \param new_pid the process's ProcessID. */ /***********************************************************************************/ -Bool UserProcessHelper::Switch(HAL::StackFramePtr frame_ptr, PID new_pid) { +Bool UserProcessHelper::Switch(HAL::StackFramePtr frame_ptr, ProcessID new_pid) { (Void)(kout << "IP: " << hex_number(frame_ptr->IP) << kendl); for (SizeT index = 0UL; index < HardwareThreadScheduler::The().Capacity(); ++index) { diff --git a/dev/kernel/src/UtfUtils.cc b/dev/kernel/src/UtfUtils.cc index a5c03b85..907632ad 100644 --- a/dev/kernel/src/UtfUtils.cc +++ b/dev/kernel/src/UtfUtils.cc @@ -27,7 +27,7 @@ Void urt_set_memory(const voidPtr src, UInt32 dst, Size len) { } } -Int32 rt_string_cmp(const Utf8Char* src, const Utf8Char* cmp, Size size) { +Int32 urt_string_cmp(const Utf8Char* src, const Utf8Char* cmp, Size size) { Int32 counter = 0; for (Size index = 0; index < size; ++index) { diff --git a/dev/kernel/src/ZXD.cc b/dev/kernel/src/ZXD.cc new file mode 100644 index 00000000..8ca6bbf7 --- /dev/null +++ b/dev/kernel/src/ZXD.cc @@ -0,0 +1,7 @@ +/* ------------------------------------------- + + Copyright (C) 2025, Amlal El Mahrouss, all rights reserved. + +------------------------------------------- */ + +#include <KernelKit/ZXD.h> |
