From 9828f432fe1ec678a5a78ad841b4f4d6beb3795b Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Wed, 4 Jun 2025 10:04:44 +0200 Subject: fix: Better architectural design of BootZ's SATA device. fix: Use 512 instead of 4096 as a sector size inside SATA's BootZ device. Signed-off-by: Amlal El Mahrouss --- dev/boot/BootKit/Device.h | 4 ++-- dev/boot/BootKit/HW/SATA.h | 6 ++---- 2 files changed, 4 insertions(+), 6 deletions(-) (limited to 'dev/boot/BootKit') diff --git a/dev/boot/BootKit/Device.h b/dev/boot/BootKit/Device.h index 8f5bf854..6ae8cd6b 100644 --- a/dev/boot/BootKit/Device.h +++ b/dev/boot/BootKit/Device.h @@ -20,8 +20,8 @@ class Device { NE_MOVE_DEFAULT(Device) struct Trait { - SizeT mBase{1024}; - SizeT mSize{1024}; + SizeT mBase{0}; + SizeT mSize{0}; }; virtual Trait& Leak() = 0; diff --git a/dev/boot/BootKit/HW/SATA.h b/dev/boot/BootKit/HW/SATA.h index eecf426d..ebb1151e 100644 --- a/dev/boot/BootKit/HW/SATA.h +++ b/dev/boot/BootKit/HW/SATA.h @@ -10,7 +10,7 @@ #include #include -#define kAHCISectorSz (4096) +#define kAHCISectorSz (512) class BootDeviceSATA final { public: @@ -19,11 +19,9 @@ class BootDeviceSATA final { NE_COPY_DEFAULT(BootDeviceSATA) - struct SATATrait final { - Kernel::SizeT mBase{1024}; + struct SATATrait final : public Device::Trait { Kernel::Boolean mErr{false}; Kernel::Boolean mDetected{false}; - Kernel::SizeT mSize{0}; operator bool() { return !this->mErr; } }; -- cgit v1.2.3 From e4c4041182480e96d52d289204d7f5363e6be3e4 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Wed, 4 Jun 2025 14:41:29 +0200 Subject: meta: Ran `./format.sh` Signed-off-by: Amlal El Mahrouss --- dev/boot/BootKit/HW/SATA.h | 2 +- dev/boot/src/HEL/AMD64/BootATA.cc | 13 +- dev/kernel/KernelKit/ThreadLocalStorage.h | 2 +- dev/kernel/src/AsciiUtils.cc | 55 ++--- dev/kernel/src/CxxAbi-ARM64.cc | 2 +- dev/kernel/src/ThreadLocalStorage.cc | 3 +- tooling/fsck.hefs.cc | 2 +- tooling/mkfs.hefs.cc | 383 ++++++++++++++---------------- 8 files changed, 219 insertions(+), 243 deletions(-) (limited to 'dev/boot/BootKit') diff --git a/dev/boot/BootKit/HW/SATA.h b/dev/boot/BootKit/HW/SATA.h index ebb1151e..d880c3af 100644 --- a/dev/boot/BootKit/HW/SATA.h +++ b/dev/boot/BootKit/HW/SATA.h @@ -19,7 +19,7 @@ class BootDeviceSATA final { NE_COPY_DEFAULT(BootDeviceSATA) - struct SATATrait final : public Device::Trait { + struct SATATrait final : public Device::Trait { Kernel::Boolean mErr{false}; Kernel::Boolean mDetected{false}; diff --git a/dev/boot/src/HEL/AMD64/BootATA.cc b/dev/boot/src/HEL/AMD64/BootATA.cc index e5e0d8c2..25810222 100644 --- a/dev/boot/src/HEL/AMD64/BootATA.cc +++ b/dev/boot/src/HEL/AMD64/BootATA.cc @@ -88,7 +88,8 @@ 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); @@ -114,14 +115,15 @@ 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); @@ -147,14 +149,15 @@ 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/kernel/KernelKit/ThreadLocalStorage.h b/dev/kernel/KernelKit/ThreadLocalStorage.h index 35c17db0..1b8e4821 100644 --- a/dev/kernel/KernelKit/ThreadLocalStorage.h +++ b/dev/kernel/KernelKit/ThreadLocalStorage.h @@ -28,7 +28,7 @@ struct THREAD_INFORMATION_BLOCK; /// Located in GS on AMD64, other architectures have their own stuff. (64x0, 32x0, ARM64) struct PACKED THREAD_INFORMATION_BLOCK final { Kernel::Char Cookie[kTLSCookieLen]{0}; //! Thread Magic Number. - Kernel::VoidPtr UserData{nullptr}; //! Thread Information Record (User defined canary structure) + Kernel::VoidPtr UserData{nullptr}; //! Thread Information Record (User defined canary structure) }; ///! @brief Cookie Sanity check. diff --git a/dev/kernel/src/AsciiUtils.cc b/dev/kernel/src/AsciiUtils.cc index 087b6d5f..bfc56aec 100644 --- a/dev/kernel/src/AsciiUtils.cc +++ b/dev/kernel/src/AsciiUtils.cc @@ -8,40 +8,35 @@ namespace Kernel { -STATIC Int rt_copy_memory_safe(const voidPtr src, voidPtr dst, Size len, Size dst_size); +STATIC Int rt_copy_memory_safe(const voidPtr src, voidPtr dst, Size len, Size dst_size); STATIC voidPtr rt_set_memory_safe(voidPtr dst, UInt32 value, Size len, Size dst_size); Int32 rt_string_cmp(const Char* src, const Char* cmp, Size size) { for (Size i = 0; i < size; ++i) { - if (src[i] != cmp[i]) - return static_cast(src[i]) - static_cast(cmp[i]); + if (src[i] != cmp[i]) return static_cast(src[i]) - static_cast(cmp[i]); } return 0; } SizeT rt_string_len(const Char* str, SizeT max_len) { SizeT len = 0; - while (len < max_len && str[len] != '\0') - ++len; + while (len < max_len && str[len] != '\0') ++len; return len; } Size rt_string_len(const Char* ptr) { Size cnt = 0; - while (ptr[cnt] != '\0') - ++cnt; + while (ptr[cnt] != '\0') ++cnt; return cnt; } const Char* rt_alloc_string(const Char* src) { - SizeT slen = rt_string_len(src); + SizeT slen = rt_string_len(src); Char* buffer = new Char[slen + 1]; if (!buffer) return nullptr; if (rt_copy_memory_safe(reinterpret_cast(const_cast(src)), - reinterpret_cast(buffer), - slen, - slen + 1) < 0) { + reinterpret_cast(buffer), slen, slen + 1) < 0) { delete[] buffer; return nullptr; } @@ -59,17 +54,15 @@ STATIC Int rt_copy_memory_safe(const voidPtr src, voidPtr dst, Size len, Size ds } auto s = reinterpret_cast(src); auto d = reinterpret_cast(dst); - for (Size i = 0; i < len; ++i) - d[i] = s[i]; + for (Size i = 0; i < len; ++i) d[i] = s[i]; return static_cast(len); } STATIC voidPtr rt_set_memory_safe(voidPtr dst, UInt32 value, Size len, Size dst_size) { if (!dst || len > dst_size) return nullptr; - auto p = reinterpret_cast(dst); + auto p = reinterpret_cast(dst); UInt8 v = static_cast(value & 0xFF); - for (Size i = 0; i < len; ++i) - p[i] = v; + for (Size i = 0; i < len; ++i) p[i] = v; return dst; } @@ -80,12 +73,12 @@ 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(src); + auto p = reinterpret_cast(src); UInt8 v = static_cast(value & 0xFF); - for (Size i = 0; i < len; ++i) - p[i] = v; + for (Size i = 0; i < len; ++i) p[i] = v; return src; } @@ -97,13 +90,11 @@ Int rt_copy_memory(const voidPtr src, voidPtr dst, Size len) { auto s = reinterpret_cast(src); auto d = reinterpret_cast(dst); - for (Size i = 0; i < len; ++i) - d[i] = s[i]; + for (Size i = 0; i < len; ++i) d[i] = s[i]; return static_cast(len); } - Int32 rt_to_uppercase(Int32 ch) { return (ch >= 'a' && ch <= 'z') ? ch - 0x20 : ch; } @@ -113,9 +104,7 @@ Int32 rt_to_lower(Int32 ch) { } Int32 rt_is_alnum(Int32 ch) { - return (ch >= 'a' && ch <= 'z') || - (ch >= 'A' && ch <= 'Z') || - (ch >= '0' && ch <= '9'); + return (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || (ch >= '0' && ch <= '9'); } Boolean rt_is_space(Char ch) { @@ -141,18 +130,17 @@ Bool rt_to_string(Char* str, UInt64 value, Int32 base) { str[i] = '\0'; // in-place for (Int j = 0; j < i / 2; ++j) { - Char tmp = str[j]; - str[j] = str[i - j - 1]; + Char tmp = str[j]; + str[j] = str[i - j - 1]; str[i - j - 1] = tmp; } #endif return true; } - VoidPtr rt_string_in_string(const Char* haystack, const Char* needle) { SizeT needle_len = rt_string_len(needle); - SizeT hay_len = rt_string_len(haystack); + SizeT hay_len = rt_string_len(haystack); if (needle_len > hay_len) return nullptr; for (SizeT i = 0; i <= hay_len - needle_len; ++i) { @@ -173,11 +161,10 @@ Int32 rt_strcmp(const Char* a, const Char* b) { while (a[i] != '\0' && b[i] != '\0' && a[i] == b[i]) { ++i; } - return static_cast(static_cast(a[i]) - - static_cast(b[i])); + return static_cast(static_cast(a[i]) - static_cast(b[i])); } - // @uses the deprecated version callers should ensure 'len' is valid. +// @uses the deprecated version callers should ensure 'len' is valid. extern "C" void* memset(void* dst, int c, long long unsigned int len) { return Kernel::rt_set_memory(dst, c, static_cast(len)); } @@ -191,4 +178,4 @@ extern "C" Kernel::Int32 strcmp(const char* a, const char* b) { return Kernel::rt_strcmp(a, b); } -} +} // namespace Kernel diff --git a/dev/kernel/src/CxxAbi-ARM64.cc b/dev/kernel/src/CxxAbi-ARM64.cc index d351b024..e91eb958 100644 --- a/dev/kernel/src/CxxAbi-ARM64.cc +++ b/dev/kernel/src/CxxAbi-ARM64.cc @@ -37,7 +37,7 @@ EXTERN_C void __cxa_finalize(void* f) { while (i--) { if (__atexit_funcs[i].destructor_func) { (*__atexit_funcs[i].destructor_func)(); - __atexit_funcs[i].destructor_func = 0; + __atexit_funcs[i].destructor_func = 0; }; } diff --git a/dev/kernel/src/ThreadLocalStorage.cc b/dev/kernel/src/ThreadLocalStorage.cc index 88fefee4..03a71f1a 100644 --- a/dev/kernel/src/ThreadLocalStorage.cc +++ b/dev/kernel/src/ThreadLocalStorage.cc @@ -30,7 +30,8 @@ Boolean tls_check_tib(THREAD_INFORMATION_BLOCK* tib_ptr) { if (!tib_ptr) return false; return tib_ptr->Cookie[kCookieMag0Idx] == kCookieMag0 && - tib_ptr->Cookie[kCookieMag1Idx] == kCookieMag1 && tib_ptr->Cookie[kCookieMag2Idx] == kCookieMag2; + tib_ptr->Cookie[kCookieMag1Idx] == kCookieMag1 && + tib_ptr->Cookie[kCookieMag2Idx] == kCookieMag2; } /** diff --git a/tooling/fsck.hefs.cc b/tooling/fsck.hefs.cc index 2898f09b..37dfbdd7 100644 --- a/tooling/fsck.hefs.cc +++ b/tooling/fsck.hefs.cc @@ -15,7 +15,7 @@ int main(int argc, char** argv) { return EXIT_FAILURE; } - (void)(argv); + (void) (argv); return EXIT_SUCCESS; } \ No newline at end of file diff --git a/tooling/mkfs.hefs.cc b/tooling/mkfs.hefs.cc index ef6ceb32..3960fa5e 100644 --- a/tooling/mkfs.hefs.cc +++ b/tooling/mkfs.hefs.cc @@ -6,228 +6,213 @@ #include #include +#include #include #include #include #include -#include namespace detail { /// @internal /// @brief GB‐to‐byte conversion (use multiplication, not XOR). static constexpr size_t gib_cast(uint32_t gb) { - return static_cast(gb) * 1024ULL * 1024ULL * 1024ULL; + return static_cast(gb) * 1024ULL * 1024ULL * 1024ULL; } } // namespace detail -static size_t kDiskSize = detail::gib_cast(4UL); -static uint16_t kVersion = kHeFSVersion; -static std::u8string kLabel; +static size_t kDiskSize = detail::gib_cast(4UL); +static uint16_t kVersion = kHeFSVersion; +static std::u8string kLabel; static size_t kSectorSize = 512; static bool parse_decimal(const std::string& opt, unsigned long long& out) { - if (opt.empty()) return false; - char* endptr = nullptr; - unsigned long long val = std::strtoull(opt.c_str(), &endptr, 10); - if (endptr == opt.c_str() || *endptr != '\0') return false; - out = val; - return true; + if (opt.empty()) return false; + char* endptr = nullptr; + unsigned long long val = std::strtoull(opt.c_str(), &endptr, 10); + if (endptr == opt.c_str() || *endptr != '\0') return false; + out = val; + return true; } static bool parse_signed(const std::string& opt, long& out, int base = 10) { - if (opt.empty()) return false; - char* endptr = nullptr; - long val = std::strtol(opt.c_str(), &endptr, base); - if (endptr == opt.c_str() || *endptr != '\0' || val < 0) return false; - out = val; - return true; + if (opt.empty()) return false; + char* endptr = nullptr; + long val = std::strtol(opt.c_str(), &endptr, base); + if (endptr == opt.c_str() || *endptr != '\0' || val < 0) return false; + out = val; + return true; } static std::string build_args(int argc, char** argv) { - std::string combined; - for (int i = 1; i < argc; ++i) { - combined += argv[i]; - combined += ' '; - } - return combined; + std::string combined; + for (int i = 1; i < argc; ++i) { + combined += argv[i]; + combined += ' '; + } + return combined; } int main(int argc, char** argv) { - if (argc < 2) { - mkfs::console_out() - << "hefs: usage: mkfs.hefs -L=