From 27d594142d026f0160170e8775d15b361ebc1542 Mon Sep 17 00:00:00 2001 From: UnbreakableMJ <34196588+UnbreakableMJ@users.noreply.github.com> Date: Tue, 28 Apr 2026 12:40:02 +0300 Subject: [PATCH 1/2] style(bios): rustfmt the M1-16 Path B sources Re-flows trailing comments and wraps the CI fmt job flagged on PR #1. No semantic changes. Co-Authored-By: Claude Opus 4.7 (1M context) --- zamak-bios/src/boot_bundle.rs | 6 +- zamak-bios/src/entry.rs | 6 +- zamak-bios/src/main.rs | 37 +++++------- zamak-bios/src/rm_io.rs | 106 +++++++++++++++++----------------- 4 files changed, 73 insertions(+), 82 deletions(-) diff --git a/zamak-bios/src/boot_bundle.rs b/zamak-bios/src/boot_bundle.rs index 7db5f97..0de7ef7 100644 --- a/zamak-bios/src/boot_bundle.rs +++ b/zamak-bios/src/boot_bundle.rs @@ -224,8 +224,7 @@ const _: () = { // real-mode orchestration writes them last so kmain sees a // fully-initialized bundle only if every step succeeded. assert!( - core::mem::offset_of!(BootDataBundle, kernel_len) - + core::mem::size_of::() + core::mem::offset_of!(BootDataBundle, kernel_len) + core::mem::size_of::() == core::mem::size_of::() ); }; @@ -278,8 +277,7 @@ const _: () = { assert!(bytes[2] == b'D', "ZBDL_MAGIC byte 2 must be 'D'"); assert!(bytes[3] == b'L', "ZBDL_MAGIC byte 3 must be 'L'"); assert!( - core::mem::size_of::<[E820Entry; E820_MAX_ENTRIES]>() - == 24 * E820_MAX_ENTRIES, + core::mem::size_of::<[E820Entry; E820_MAX_ENTRIES]>() == 24 * E820_MAX_ENTRIES, "E820 table must be exactly 24 bytes per entry (no tail padding)" ); // Leave plenty of headroom below the 0x4000 mark where the FAT32 diff --git a/zamak-bios/src/entry.rs b/zamak-bios/src/entry.rs index 0236997..35dcac3 100644 --- a/zamak-bios/src/entry.rs +++ b/zamak-bios/src/entry.rs @@ -61,7 +61,7 @@ global_asm!( "", " lgdt [gdt_descriptor]", "", - " sti", // BIOS services need interrupts on + " sti", // BIOS services need interrupts on // M1-16 Path B: run the entire real-mode I/O phase and populate // the BootDataBundle at phys 0x1000 before CR0.PE. On return, // every BIOS-backed datum kmain needs (E820, MBR, partition @@ -77,7 +77,7 @@ global_asm!( // and SS:SP eventually corrupts the BIOS-handler frame. ".byte 0xE8", ".word rm_phaseb_orchestrate - . - 2", - " cli", // back to IF=0 for the PE switch + " cli", // back to IF=0 for the PE switch "", " mov eax, cr0", " or eax, 1", @@ -100,7 +100,7 @@ global_asm!( " mov fs, ax", " mov gs, ax", " mov ss, ax", - " mov esp, 0x8000", // stable PM stack, above bundle + " mov esp, 0x8000", // stable PM stack, above bundle // Print 'P' to COM1 so we know the 16→32 mode switch succeeded. " mov dx, 0x3F8", " mov al, 'P'", diff --git a/zamak-bios/src/main.rs b/zamak-bios/src/main.rs index 64ad9c7..cd3b672 100644 --- a/zamak-bios/src/main.rs +++ b/zamak-bios/src/main.rs @@ -321,11 +321,11 @@ fn mark(b: u8) { #[cfg(not(feature = "legacy_trampoline"))] #[no_mangle] pub extern "C" fn kmain(bundle_phys: u32) -> ! { - use alloc::string::String; use crate::boot_bundle::{BootDataBundle, ZBDL_MAGIC}; + use alloc::string::String; use zamak_core::protocol::{ - MemmapEntry, MEMMAP_ACPI_NVS, MEMMAP_ACPI_RECLAIMABLE, MEMMAP_BAD_MEMORY, - MEMMAP_RESERVED, MEMMAP_USABLE, + MemmapEntry, MEMMAP_ACPI_NVS, MEMMAP_ACPI_RECLAIMABLE, MEMMAP_BAD_MEMORY, MEMMAP_RESERVED, + MEMMAP_USABLE, }; use zamak_core::ram_fat32::RamFat32; @@ -339,13 +339,9 @@ pub extern "C" fn kmain(bundle_phys: u32) -> ! { // SAFETY: real-mode orchestration writes the bundle at this fixed // address before the PE transition and stamps the magic last. - let bundle: &'static BootDataBundle = - unsafe { &*(bundle_phys as *const BootDataBundle) }; + let bundle: &'static BootDataBundle = unsafe { &*(bundle_phys as *const BootDataBundle) }; let magic = bundle.magic; - assert!( - magic == ZBDL_MAGIC, - "kmain: BootDataBundle magic mismatch" - ); + assert!(magic == ZBDL_MAGIC, "kmain: BootDataBundle magic mismatch"); mark(b'B'); let e820_count = bundle.e820_count as usize; @@ -363,7 +359,11 @@ pub extern "C" fn kmain(bundle_phys: u32) -> ! { 5 => MEMMAP_BAD_MEMORY, _ => MEMMAP_RESERVED, }; - mmap_entries.push(MemmapEntry { base, length: len, typ: limine_typ }); + mmap_entries.push(MemmapEntry { + base, + length: len, + typ: limine_typ, + }); } mark(b'E'); @@ -373,15 +373,12 @@ pub extern "C" fn kmain(bundle_phys: u32) -> ! { // bytes into the high-memory region documented by the bundle. The // address is flat-physical and the slice is read-only for the // duration of kmain. - let image: &'static [u8] = unsafe { - core::slice::from_raw_parts(part_phys as usize as *const u8, part_len as usize) - }; + let image: &'static [u8] = + unsafe { core::slice::from_raw_parts(part_phys as usize as *const u8, part_len as usize) }; let fs = RamFat32::parse(image).expect("FAT32 parse failed"); mark(b'F'); - let cfg_facts = fs - .find_path("zamak.conf") - .expect("zamak.conf missing"); + let cfg_facts = fs.find_path("zamak.conf").expect("zamak.conf missing"); let mut cfg_buf = vec![0u8; cfg_facts.len as usize]; let cfg_n = fs.read_file(&cfg_facts, &mut cfg_buf); let config_str = core::str::from_utf8(&cfg_buf[..cfg_n]).unwrap_or(""); @@ -417,10 +414,7 @@ pub extern "C" fn kmain(bundle_phys: u32) -> ! { const KERNEL_LOAD_PHYS: u64 = 0x0060_0000; for seg in &info.segments { let dest_phys = KERNEL_LOAD_PHYS + seg.vaddr; - let src_end = seg - .offset - .checked_add(seg.file_size) - .expect("seg overflow"); + let src_end = seg.offset.checked_add(seg.file_size).expect("seg overflow"); assert!(src_end <= kernel_buf.len(), "seg out of ELF bounds"); // SAFETY: dest_phys lies inside the dedicated kernel window // (above the bump heap, below the partition image); src is @@ -465,8 +459,7 @@ pub extern "C" fn kmain(bundle_phys: u32) -> ! { let seg_ptr = seg.paddr as *const u8; // SAFETY: parse_elf populated seg.paddr / seg.mem_size with // the loaded segment's protected-mode-visible footprint. - let seg_slice = - unsafe { core::slice::from_raw_parts(seg_ptr, seg.mem_size as usize) }; + let seg_slice = unsafe { core::slice::from_raw_parts(seg_ptr, seg.mem_size as usize) }; let mut reqs = protocol::scan_requests(seg_slice); all_requests.append(&mut reqs); } diff --git a/zamak-bios/src/rm_io.rs b/zamak-bios/src/rm_io.rs index c8fd107..0b159f8 100644 --- a/zamak-bios/src/rm_io.rs +++ b/zamak-bios/src/rm_io.rs @@ -100,9 +100,9 @@ global_asm!( "rm_disk_read_ext:", " mov ah, 0x42", " int 0x13", - " mov al, ah", // move status into AL for caller + " mov al, ah", // move status into AL for caller " xor ah, ah", - " .byte 0xC3", // 16-bit near ret — see module header + " .byte 0xC3", // 16-bit near ret — see module header // ======================================================================= // rm_e820_next // @@ -123,10 +123,10 @@ global_asm!( ".global rm_e820_next", "rm_e820_next:", " mov eax, 0xE820", - " mov edx, 0x534D4150", // 'SMAP' + " mov edx, 0x534D4150", // 'SMAP' " mov ecx, 24", " int 0x15", - " .byte 0xC3", // 16-bit near ret — see module header + " .byte 0xC3", // 16-bit near ret — see module header // ======================================================================= // rm_vbe_info // @@ -145,7 +145,7 @@ global_asm!( "rm_vbe_info:", " mov ax, 0x4F00", " int 0x10", - " .byte 0xC3", // 16-bit near ret — see module header + " .byte 0xC3", // 16-bit near ret — see module header // ======================================================================= // rm_vbe_mode_info // @@ -162,7 +162,7 @@ global_asm!( "rm_vbe_mode_info:", " mov ax, 0x4F01", " int 0x10", - " .byte 0xC3", // 16-bit near ret — see module header + " .byte 0xC3", // 16-bit near ret — see module header // ======================================================================= // rm_vbe_set_mode // @@ -180,7 +180,7 @@ global_asm!( "rm_vbe_set_mode:", " mov ax, 0x4F02", " int 0x10", - " .byte 0xC3", // 16-bit near ret — see module header + " .byte 0xC3", // 16-bit near ret — see module header // ======================================================================= // rm_outb_com1 // @@ -198,7 +198,7 @@ global_asm!( "rm_outb_com1:", " mov dx, 0x3F8", " out dx, al", - " .byte 0xC3", // 16-bit near ret — see module header + " .byte 0xC3", // 16-bit near ret — see module header // ======================================================================= // rm_unreal_enter // @@ -223,11 +223,11 @@ global_asm!( " lgdt [gdt_descriptor]", " mov eax, cr0", " or eax, 1", - " mov cr0, eax", // PE on + " mov cr0, eax", // PE on " mov bx, 0x10", - " mov fs, bx", // FS cache ← flat 32-bit data descriptor + " mov fs, bx", // FS cache ← flat 32-bit data descriptor " and eax, 0xFFFFFFFE", - " mov cr0, eax", // PE off (FS cache persists) + " mov cr0, eax", // PE off (FS cache persists) " sti", " .byte 0xC3", // ======================================================================= @@ -259,18 +259,18 @@ global_asm!( " cli", " mov eax, cr0", " or eax, 1", - " mov cr0, eax", // PE on — required to populate ES cache + " mov cr0, eax", // PE on — required to populate ES cache " mov bx, 0x10", - " mov es, bx", // ES cache ← flat 32-bit data + " mov es, bx", // ES cache ← flat 32-bit data " and eax, 0xFFFFFFFE", - " mov cr0, eax", // PE off (ES cache persists) + " mov cr0, eax", // PE off (ES cache persists) " cld", // `addr32 rep movsb` = 0x67 0xF3 0xA4. Forces 32-bit address size // so the CPU uses ESI / EDI / ECX instead of SI / DI / CX. GAS's // Intel-syntax `addr32` prefix may not parse here, so emit raw. " .byte 0x67, 0xF3, 0xA4", - " pop es", // restore caller's real-mode ES value + - // 64-KiB limit cache (via real-mode seg load) + " pop es", // restore caller's real-mode ES value + + // 64-KiB limit cache (via real-mode seg load) " sti", " .byte 0xC3", // ======================================================================= @@ -331,7 +331,7 @@ global_asm!( " mov ds, ax", " mov es, ax", " mov di, 0x1000", - " mov cx, 0x1E00", // 7680 bytes covers the bundle + " mov cx, 0x1E00", // 7680 bytes covers the bundle " xor al, al", " rep stosb", // Enter unreal mode so FS has a flat cache (rm_memcpy_to_high @@ -382,18 +382,18 @@ global_asm!( " mov es, ax", " mov di, 0x0700", " mov ax, 0x0010", - " stosw", // size + reserved + " stosw", // size + reserved " mov ax, 1", - " stosw", // count + " stosw", // count " mov ax, 0x0500", - " stosw", // offset = 0x0500 + " stosw", // offset = 0x0500 " mov ax, 0", - " stosw", // segment = 0 → phys 0x0500 + " stosw", // segment = 0 → phys 0x0500 " xor ax, ax", - " stosw", // LBA[0..1] = 0 (MBR) - " stosw", // LBA[2..3] - " stosw", // LBA[4..5] - " stosw", // LBA[6..7] + " stosw", // LBA[0..1] = 0 (MBR) + " stosw", // LBA[2..3] + " stosw", // LBA[4..5] + " stosw", // LBA[6..7] " mov dl, [0x0401]", " mov si, 0x0700", " mov ah, 0x42", @@ -406,7 +406,7 @@ global_asm!( " mov bx, 0x06BE", " mov cx, 4", ".Lpb_part_scan:", - " mov al, [bx + 4]", // partition type byte + " mov al, [bx + 4]", // partition type byte " cmp al, 0x0B", " je .Lpb_part_found", " cmp al, 0x0C", @@ -415,12 +415,12 @@ global_asm!( " je .Lpb_part_found", " add bx, 16", " loop .Lpb_part_scan", - " jmp .Lpb_fail", // no FAT32/Linux partition + " jmp .Lpb_fail", // no FAT32/Linux partition ".Lpb_part_found:", - " mov eax, [bx + 8]", // partition LBA (u32, offset 8 in entry) - " mov dword ptr [0x1C0C], eax", // bundle.partition_lba + " mov eax, [bx + 8]", // partition LBA (u32, offset 8 in entry) + " mov dword ptr [0x1C0C], eax", // bundle.partition_lba " mov al, [bx + 4]", - " mov byte ptr [0x1C10], al", // bundle.partition_type + " mov byte ptr [0x1C10], al", // bundle.partition_type // ---- Bulk-load partition into phys 0x0200_0000 (32 MiB), cap 8 MiB ---- " mov al, 'L'", ".byte 0xE8", @@ -444,51 +444,51 @@ global_asm!( " mov dl, [0x0401]", " mov ebx, [0x0424]", " mov edi, [0x0428]", - " push eax", // stash chunk count across rm_load_chunk + " push eax", // stash chunk count across rm_load_chunk ".byte 0xE8", ".word rm_load_chunk - . - 2", - " pop ebx", // chunk sectors (reuse ebx) + " pop ebx", // chunk sectors (reuse ebx) " test al, al", " jnz .Lpb_fail", " mov ecx, ebx", - " shl ecx, 9", // chunk bytes - " add [0x0428], ecx", // dest += bytes - " add [0x0424], ebx", // LBA += chunk - " sub [0x0420], ebx", // remaining -= chunk + " shl ecx, 9", // chunk bytes + " add [0x0428], ecx", // dest += bytes + " add [0x0424], ebx", // LBA += chunk + " sub [0x0420], ebx", // remaining -= chunk " jmp .Lpb_load_loop", ".Lpb_load_done:", " mov al, 'l'", ".byte 0xE8", ".word rm_outb_com1 - . - 2", - " mov dword ptr [0x1C14], 0x02000000", // partition_image_phys low - " mov dword ptr [0x1C18], 0", // partition_image_phys high - " mov dword ptr [0x1C1C], 0x00800000", // partition_image_len low (8 MiB) - " mov dword ptr [0x1C20], 0", // partition_image_len high + " mov dword ptr [0x1C14], 0x02000000", // partition_image_phys low + " mov dword ptr [0x1C18], 0", // partition_image_phys high + " mov dword ptr [0x1C1C], 0x00800000", // partition_image_len low (8 MiB) + " mov dword ptr [0x1C20], 0", // partition_image_len high // ---- RSDP scan 0xE0000..0xFFFF0 for \"RSD PTR \" ---- " mov al, 'R'", ".byte 0xE8", ".word rm_outb_com1 - . - 2", " mov ebx, 0xE0000", ".Lpb_rsdp_loop:", - " cmp dword ptr [ebx + 0], 0x20445352", // \"RSD \" LE + " cmp dword ptr [ebx + 0], 0x20445352", // \"RSD \" LE " jne .Lpb_rsdp_next", - " cmp dword ptr [ebx + 4], 0x20525450", // \"PTR \" LE + " cmp dword ptr [ebx + 4], 0x20525450", // \"PTR \" LE " jne .Lpb_rsdp_next", - " mov dword ptr [0x2D28], ebx", // bundle.rsdp_phys low - " mov dword ptr [0x2D2C], 0", // bundle.rsdp_phys high + " mov dword ptr [0x2D28], ebx", // bundle.rsdp_phys low + " mov dword ptr [0x2D2C], 0", // bundle.rsdp_phys high " jmp .Lpb_rsdp_done", ".Lpb_rsdp_next:", - " add ebx, 16", // RSDP is on 16-byte boundary + " add ebx, 16", // RSDP is on 16-byte boundary " cmp ebx, 0xFFFF0", " jb .Lpb_rsdp_loop", ".Lpb_rsdp_done:", // ---- SMBIOS / VBE: skipped in MVP; bundle fields stay 0. ---- // ---- Stamp ZBDL_MAGIC last so kmain can detect partial init ---- - " mov dword ptr [0x1000], 0x4C44425A", // ZBDL_MAGIC + " mov dword ptr [0x1000], 0x4C44425A", // ZBDL_MAGIC " mov al, 'k'", ".byte 0xE8", ".word rm_outb_com1 - . - 2", - " .byte 0xC3", // 16-bit near ret + " .byte 0xC3", // 16-bit near ret ".Lpb_fail:", // Emit the AL we're panicking on as two hex digits so bring-up // logs distinguish BIOS error code from parse-time 0xFF. @@ -529,12 +529,12 @@ global_asm!( " mov bp, sp", // Stash inputs at DAP / near-scratch so the BIOS call clobbering // general registers doesn't lose them. - " mov word ptr [0x0700], 0x0010", // DAP size + reserved - " mov word ptr [0x0702], ax", // count - " mov word ptr [0x0704], 0x5000", // buffer offset (bounce) - " mov word ptr [0x0706], 0x0000", // buffer segment - " mov dword ptr [0x0708], ebx", // LBA low32 - " mov dword ptr [0x070C], 0", // LBA high32 + " mov word ptr [0x0700], 0x0010", // DAP size + reserved + " mov word ptr [0x0702], ax", // count + " mov word ptr [0x0704], 0x5000", // buffer offset (bounce) + " mov word ptr [0x0706], 0x0000", // buffer segment + " mov dword ptr [0x0708], ebx", // LBA low32 + " mov dword ptr [0x070C], 0", // LBA high32 // Save the chunk byte count (AX × 512) in the scratch dword at // 0x0710 so we can recover it after the BIOS call blows away AX. " movzx ecx, ax", From 3cfcc9f76d2373f5533f0020bae32a66d7c258c9 Mon Sep 17 00:00:00 2001 From: UnbreakableMJ <34196588+UnbreakableMJ@users.noreply.github.com> Date: Tue, 28 Apr 2026 12:53:08 +0300 Subject: [PATCH 2/2] style(core): apply clippy idiom suggestions in ram_fat32 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit CI clippy flagged four lints in the new walker: - `manual_range_contains` × 2 → `(2..FAT32_END_OF_CHAIN).contains(&cluster)` / `!(2..FAT32_END_OF_CHAIN).contains(&cluster)`. - `manual_is_ascii_check` × 2 → `is_ascii_uppercase` / `is_ascii_lowercase`. Plus an `identity_op` (`x + 0x00`) in the LFN test fixture and the rustfmt re-flow that came with replacing the longer literals. No semantic change; 9/9 host walker tests + bios-boot-smoke all still pass locally. Co-Authored-By: Claude Opus 4.7 (1M context) --- zamak-core/src/ram_fat32.rs | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/zamak-core/src/ram_fat32.rs b/zamak-core/src/ram_fat32.rs index 17ffe8d..0e058e6 100644 --- a/zamak-core/src/ram_fat32.rs +++ b/zamak-core/src/ram_fat32.rs @@ -123,7 +123,7 @@ impl<'a> RamFat32<'a> { let cluster_size = self.sectors_per_cluster as usize * SECTOR_SIZE; let mut cluster = facts.first_cluster; let mut written = 0; - while written < total && cluster >= 2 && cluster < FAT32_END_OF_CHAIN { + while written < total && (2..FAT32_END_OF_CHAIN).contains(&cluster) { let bytes = match self.cluster_bytes(cluster) { Some(b) => b, None => break, @@ -221,7 +221,7 @@ impl<'a> RamFat32<'a> { ofs += DIR_ENTRY_SIZE; } cluster = self.next_cluster(cluster)?; - if cluster < 2 || cluster >= FAT32_END_OF_CHAIN { + if !(2..FAT32_END_OF_CHAIN).contains(&cluster) { return None; } } @@ -335,7 +335,7 @@ fn ascii_eq_ignore_case(a: &[u8], b: &[u8]) -> bool { } fn ascii_lower(b: u8) -> u8 { - if (b'A'..=b'Z').contains(&b) { + if b.is_ascii_uppercase() { b + 32 } else { b @@ -361,11 +361,7 @@ fn name_to_8_3(part: &str) -> [u8; 11] { if idx >= 11 { break; } - out[idx] = if (b'a'..=b'z').contains(&ch) { - ch - 32 - } else { - ch - }; + out[idx] = if ch.is_ascii_lowercase() { ch - 32 } else { ch }; idx += 1; } out @@ -446,7 +442,7 @@ mod tests { // LFN entry. seq=1 with bit 0x40 set → "last" (only segment). // Checksum field at 0x0D — we don't validate it so leave 0. - img[lfn + 0x00] = 0x41; + img[lfn] = 0x41; img[lfn + 0x0B] = ATTR_LFN; let positions: [usize; 13] = [ 0x01, 0x03, 0x05, 0x07, 0x09, 0x0E, 0x10, 0x12, 0x14, 0x16, 0x18, 0x1C, 0x1E,