Skip to content

Commit f434aa6

Browse files
Merge pull request #2 from UnbreakableMJ/m1-16-path-b
style(bios): rustfmt M1-16 Path B sources (fix CI fmt failure on main)
2 parents b8899fb + 3cfcc9f commit f434aa6

5 files changed

Lines changed: 78 additions & 91 deletions

File tree

zamak-bios/src/boot_bundle.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,7 @@ const _: () = {
224224
// real-mode orchestration writes them last so kmain sees a
225225
// fully-initialized bundle only if every step succeeded.
226226
assert!(
227-
core::mem::offset_of!(BootDataBundle, kernel_len)
228-
+ core::mem::size_of::<u64>()
227+
core::mem::offset_of!(BootDataBundle, kernel_len) + core::mem::size_of::<u64>()
229228
== core::mem::size_of::<BootDataBundle>()
230229
);
231230
};
@@ -278,8 +277,7 @@ const _: () = {
278277
assert!(bytes[2] == b'D', "ZBDL_MAGIC byte 2 must be 'D'");
279278
assert!(bytes[3] == b'L', "ZBDL_MAGIC byte 3 must be 'L'");
280279
assert!(
281-
core::mem::size_of::<[E820Entry; E820_MAX_ENTRIES]>()
282-
== 24 * E820_MAX_ENTRIES,
280+
core::mem::size_of::<[E820Entry; E820_MAX_ENTRIES]>() == 24 * E820_MAX_ENTRIES,
283281
"E820 table must be exactly 24 bytes per entry (no tail padding)"
284282
);
285283
// Leave plenty of headroom below the 0x4000 mark where the FAT32

zamak-bios/src/entry.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ global_asm!(
6161
"",
6262
" lgdt [gdt_descriptor]",
6363
"",
64-
" sti", // BIOS services need interrupts on
64+
" sti", // BIOS services need interrupts on
6565
// M1-16 Path B: run the entire real-mode I/O phase and populate
6666
// the BootDataBundle at phys 0x1000 before CR0.PE. On return,
6767
// every BIOS-backed datum kmain needs (E820, MBR, partition
@@ -77,7 +77,7 @@ global_asm!(
7777
// and SS:SP eventually corrupts the BIOS-handler frame.
7878
".byte 0xE8",
7979
".word rm_phaseb_orchestrate - . - 2",
80-
" cli", // back to IF=0 for the PE switch
80+
" cli", // back to IF=0 for the PE switch
8181
"",
8282
" mov eax, cr0",
8383
" or eax, 1",
@@ -100,7 +100,7 @@ global_asm!(
100100
" mov fs, ax",
101101
" mov gs, ax",
102102
" mov ss, ax",
103-
" mov esp, 0x8000", // stable PM stack, above bundle
103+
" mov esp, 0x8000", // stable PM stack, above bundle
104104
// Print 'P' to COM1 so we know the 16→32 mode switch succeeded.
105105
" mov dx, 0x3F8",
106106
" mov al, 'P'",

zamak-bios/src/main.rs

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -321,11 +321,11 @@ fn mark(b: u8) {
321321
#[cfg(not(feature = "legacy_trampoline"))]
322322
#[no_mangle]
323323
pub extern "C" fn kmain(bundle_phys: u32) -> ! {
324-
use alloc::string::String;
325324
use crate::boot_bundle::{BootDataBundle, ZBDL_MAGIC};
325+
use alloc::string::String;
326326
use zamak_core::protocol::{
327-
MemmapEntry, MEMMAP_ACPI_NVS, MEMMAP_ACPI_RECLAIMABLE, MEMMAP_BAD_MEMORY,
328-
MEMMAP_RESERVED, MEMMAP_USABLE,
327+
MemmapEntry, MEMMAP_ACPI_NVS, MEMMAP_ACPI_RECLAIMABLE, MEMMAP_BAD_MEMORY, MEMMAP_RESERVED,
328+
MEMMAP_USABLE,
329329
};
330330
use zamak_core::ram_fat32::RamFat32;
331331

@@ -339,13 +339,9 @@ pub extern "C" fn kmain(bundle_phys: u32) -> ! {
339339

340340
// SAFETY: real-mode orchestration writes the bundle at this fixed
341341
// address before the PE transition and stamps the magic last.
342-
let bundle: &'static BootDataBundle =
343-
unsafe { &*(bundle_phys as *const BootDataBundle) };
342+
let bundle: &'static BootDataBundle = unsafe { &*(bundle_phys as *const BootDataBundle) };
344343
let magic = bundle.magic;
345-
assert!(
346-
magic == ZBDL_MAGIC,
347-
"kmain: BootDataBundle magic mismatch"
348-
);
344+
assert!(magic == ZBDL_MAGIC, "kmain: BootDataBundle magic mismatch");
349345
mark(b'B');
350346

351347
let e820_count = bundle.e820_count as usize;
@@ -363,7 +359,11 @@ pub extern "C" fn kmain(bundle_phys: u32) -> ! {
363359
5 => MEMMAP_BAD_MEMORY,
364360
_ => MEMMAP_RESERVED,
365361
};
366-
mmap_entries.push(MemmapEntry { base, length: len, typ: limine_typ });
362+
mmap_entries.push(MemmapEntry {
363+
base,
364+
length: len,
365+
typ: limine_typ,
366+
});
367367
}
368368
mark(b'E');
369369

@@ -373,15 +373,12 @@ pub extern "C" fn kmain(bundle_phys: u32) -> ! {
373373
// bytes into the high-memory region documented by the bundle. The
374374
// address is flat-physical and the slice is read-only for the
375375
// duration of kmain.
376-
let image: &'static [u8] = unsafe {
377-
core::slice::from_raw_parts(part_phys as usize as *const u8, part_len as usize)
378-
};
376+
let image: &'static [u8] =
377+
unsafe { core::slice::from_raw_parts(part_phys as usize as *const u8, part_len as usize) };
379378
let fs = RamFat32::parse(image).expect("FAT32 parse failed");
380379
mark(b'F');
381380

382-
let cfg_facts = fs
383-
.find_path("zamak.conf")
384-
.expect("zamak.conf missing");
381+
let cfg_facts = fs.find_path("zamak.conf").expect("zamak.conf missing");
385382
let mut cfg_buf = vec![0u8; cfg_facts.len as usize];
386383
let cfg_n = fs.read_file(&cfg_facts, &mut cfg_buf);
387384
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) -> ! {
417414
const KERNEL_LOAD_PHYS: u64 = 0x0060_0000;
418415
for seg in &info.segments {
419416
let dest_phys = KERNEL_LOAD_PHYS + seg.vaddr;
420-
let src_end = seg
421-
.offset
422-
.checked_add(seg.file_size)
423-
.expect("seg overflow");
417+
let src_end = seg.offset.checked_add(seg.file_size).expect("seg overflow");
424418
assert!(src_end <= kernel_buf.len(), "seg out of ELF bounds");
425419
// SAFETY: dest_phys lies inside the dedicated kernel window
426420
// (above the bump heap, below the partition image); src is
@@ -465,8 +459,7 @@ pub extern "C" fn kmain(bundle_phys: u32) -> ! {
465459
let seg_ptr = seg.paddr as *const u8;
466460
// SAFETY: parse_elf populated seg.paddr / seg.mem_size with
467461
// the loaded segment's protected-mode-visible footprint.
468-
let seg_slice =
469-
unsafe { core::slice::from_raw_parts(seg_ptr, seg.mem_size as usize) };
462+
let seg_slice = unsafe { core::slice::from_raw_parts(seg_ptr, seg.mem_size as usize) };
470463
let mut reqs = protocol::scan_requests(seg_slice);
471464
all_requests.append(&mut reqs);
472465
}

zamak-bios/src/rm_io.rs

Lines changed: 53 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,9 @@ global_asm!(
100100
"rm_disk_read_ext:",
101101
" mov ah, 0x42",
102102
" int 0x13",
103-
" mov al, ah", // move status into AL for caller
103+
" mov al, ah", // move status into AL for caller
104104
" xor ah, ah",
105-
" .byte 0xC3", // 16-bit near ret — see module header
105+
" .byte 0xC3", // 16-bit near ret — see module header
106106
// =======================================================================
107107
// rm_e820_next
108108
//
@@ -123,10 +123,10 @@ global_asm!(
123123
".global rm_e820_next",
124124
"rm_e820_next:",
125125
" mov eax, 0xE820",
126-
" mov edx, 0x534D4150", // 'SMAP'
126+
" mov edx, 0x534D4150", // 'SMAP'
127127
" mov ecx, 24",
128128
" int 0x15",
129-
" .byte 0xC3", // 16-bit near ret — see module header
129+
" .byte 0xC3", // 16-bit near ret — see module header
130130
// =======================================================================
131131
// rm_vbe_info
132132
//
@@ -145,7 +145,7 @@ global_asm!(
145145
"rm_vbe_info:",
146146
" mov ax, 0x4F00",
147147
" int 0x10",
148-
" .byte 0xC3", // 16-bit near ret — see module header
148+
" .byte 0xC3", // 16-bit near ret — see module header
149149
// =======================================================================
150150
// rm_vbe_mode_info
151151
//
@@ -162,7 +162,7 @@ global_asm!(
162162
"rm_vbe_mode_info:",
163163
" mov ax, 0x4F01",
164164
" int 0x10",
165-
" .byte 0xC3", // 16-bit near ret — see module header
165+
" .byte 0xC3", // 16-bit near ret — see module header
166166
// =======================================================================
167167
// rm_vbe_set_mode
168168
//
@@ -180,7 +180,7 @@ global_asm!(
180180
"rm_vbe_set_mode:",
181181
" mov ax, 0x4F02",
182182
" int 0x10",
183-
" .byte 0xC3", // 16-bit near ret — see module header
183+
" .byte 0xC3", // 16-bit near ret — see module header
184184
// =======================================================================
185185
// rm_outb_com1
186186
//
@@ -198,7 +198,7 @@ global_asm!(
198198
"rm_outb_com1:",
199199
" mov dx, 0x3F8",
200200
" out dx, al",
201-
" .byte 0xC3", // 16-bit near ret — see module header
201+
" .byte 0xC3", // 16-bit near ret — see module header
202202
// =======================================================================
203203
// rm_unreal_enter
204204
//
@@ -223,11 +223,11 @@ global_asm!(
223223
" lgdt [gdt_descriptor]",
224224
" mov eax, cr0",
225225
" or eax, 1",
226-
" mov cr0, eax", // PE on
226+
" mov cr0, eax", // PE on
227227
" mov bx, 0x10",
228-
" mov fs, bx", // FS cache ← flat 32-bit data descriptor
228+
" mov fs, bx", // FS cache ← flat 32-bit data descriptor
229229
" and eax, 0xFFFFFFFE",
230-
" mov cr0, eax", // PE off (FS cache persists)
230+
" mov cr0, eax", // PE off (FS cache persists)
231231
" sti",
232232
" .byte 0xC3",
233233
// =======================================================================
@@ -259,18 +259,18 @@ global_asm!(
259259
" cli",
260260
" mov eax, cr0",
261261
" or eax, 1",
262-
" mov cr0, eax", // PE on — required to populate ES cache
262+
" mov cr0, eax", // PE on — required to populate ES cache
263263
" mov bx, 0x10",
264-
" mov es, bx", // ES cache ← flat 32-bit data
264+
" mov es, bx", // ES cache ← flat 32-bit data
265265
" and eax, 0xFFFFFFFE",
266-
" mov cr0, eax", // PE off (ES cache persists)
266+
" mov cr0, eax", // PE off (ES cache persists)
267267
" cld",
268268
// `addr32 rep movsb` = 0x67 0xF3 0xA4. Forces 32-bit address size
269269
// so the CPU uses ESI / EDI / ECX instead of SI / DI / CX. GAS's
270270
// Intel-syntax `addr32` prefix may not parse here, so emit raw.
271271
" .byte 0x67, 0xF3, 0xA4",
272-
" pop es", // restore caller's real-mode ES value +
273-
// 64-KiB limit cache (via real-mode seg load)
272+
" pop es", // restore caller's real-mode ES value +
273+
// 64-KiB limit cache (via real-mode seg load)
274274
" sti",
275275
" .byte 0xC3",
276276
// =======================================================================
@@ -331,7 +331,7 @@ global_asm!(
331331
" mov ds, ax",
332332
" mov es, ax",
333333
" mov di, 0x1000",
334-
" mov cx, 0x1E00", // 7680 bytes covers the bundle
334+
" mov cx, 0x1E00", // 7680 bytes covers the bundle
335335
" xor al, al",
336336
" rep stosb",
337337
// Enter unreal mode so FS has a flat cache (rm_memcpy_to_high
@@ -382,18 +382,18 @@ global_asm!(
382382
" mov es, ax",
383383
" mov di, 0x0700",
384384
" mov ax, 0x0010",
385-
" stosw", // size + reserved
385+
" stosw", // size + reserved
386386
" mov ax, 1",
387-
" stosw", // count
387+
" stosw", // count
388388
" mov ax, 0x0500",
389-
" stosw", // offset = 0x0500
389+
" stosw", // offset = 0x0500
390390
" mov ax, 0",
391-
" stosw", // segment = 0 → phys 0x0500
391+
" stosw", // segment = 0 → phys 0x0500
392392
" xor ax, ax",
393-
" stosw", // LBA[0..1] = 0 (MBR)
394-
" stosw", // LBA[2..3]
395-
" stosw", // LBA[4..5]
396-
" stosw", // LBA[6..7]
393+
" stosw", // LBA[0..1] = 0 (MBR)
394+
" stosw", // LBA[2..3]
395+
" stosw", // LBA[4..5]
396+
" stosw", // LBA[6..7]
397397
" mov dl, [0x0401]",
398398
" mov si, 0x0700",
399399
" mov ah, 0x42",
@@ -406,7 +406,7 @@ global_asm!(
406406
" mov bx, 0x06BE",
407407
" mov cx, 4",
408408
".Lpb_part_scan:",
409-
" mov al, [bx + 4]", // partition type byte
409+
" mov al, [bx + 4]", // partition type byte
410410
" cmp al, 0x0B",
411411
" je .Lpb_part_found",
412412
" cmp al, 0x0C",
@@ -415,12 +415,12 @@ global_asm!(
415415
" je .Lpb_part_found",
416416
" add bx, 16",
417417
" loop .Lpb_part_scan",
418-
" jmp .Lpb_fail", // no FAT32/Linux partition
418+
" jmp .Lpb_fail", // no FAT32/Linux partition
419419
".Lpb_part_found:",
420-
" mov eax, [bx + 8]", // partition LBA (u32, offset 8 in entry)
421-
" mov dword ptr [0x1C0C], eax", // bundle.partition_lba
420+
" mov eax, [bx + 8]", // partition LBA (u32, offset 8 in entry)
421+
" mov dword ptr [0x1C0C], eax", // bundle.partition_lba
422422
" mov al, [bx + 4]",
423-
" mov byte ptr [0x1C10], al", // bundle.partition_type
423+
" mov byte ptr [0x1C10], al", // bundle.partition_type
424424
// ---- Bulk-load partition into phys 0x0200_0000 (32 MiB), cap 8 MiB ----
425425
" mov al, 'L'",
426426
".byte 0xE8",
@@ -444,51 +444,51 @@ global_asm!(
444444
" mov dl, [0x0401]",
445445
" mov ebx, [0x0424]",
446446
" mov edi, [0x0428]",
447-
" push eax", // stash chunk count across rm_load_chunk
447+
" push eax", // stash chunk count across rm_load_chunk
448448
".byte 0xE8",
449449
".word rm_load_chunk - . - 2",
450-
" pop ebx", // chunk sectors (reuse ebx)
450+
" pop ebx", // chunk sectors (reuse ebx)
451451
" test al, al",
452452
" jnz .Lpb_fail",
453453
" mov ecx, ebx",
454-
" shl ecx, 9", // chunk bytes
455-
" add [0x0428], ecx", // dest += bytes
456-
" add [0x0424], ebx", // LBA += chunk
457-
" sub [0x0420], ebx", // remaining -= chunk
454+
" shl ecx, 9", // chunk bytes
455+
" add [0x0428], ecx", // dest += bytes
456+
" add [0x0424], ebx", // LBA += chunk
457+
" sub [0x0420], ebx", // remaining -= chunk
458458
" jmp .Lpb_load_loop",
459459
".Lpb_load_done:",
460460
" mov al, 'l'",
461461
".byte 0xE8",
462462
".word rm_outb_com1 - . - 2",
463-
" mov dword ptr [0x1C14], 0x02000000", // partition_image_phys low
464-
" mov dword ptr [0x1C18], 0", // partition_image_phys high
465-
" mov dword ptr [0x1C1C], 0x00800000", // partition_image_len low (8 MiB)
466-
" mov dword ptr [0x1C20], 0", // partition_image_len high
463+
" mov dword ptr [0x1C14], 0x02000000", // partition_image_phys low
464+
" mov dword ptr [0x1C18], 0", // partition_image_phys high
465+
" mov dword ptr [0x1C1C], 0x00800000", // partition_image_len low (8 MiB)
466+
" mov dword ptr [0x1C20], 0", // partition_image_len high
467467
// ---- RSDP scan 0xE0000..0xFFFF0 for \"RSD PTR \" ----
468468
" mov al, 'R'",
469469
".byte 0xE8",
470470
".word rm_outb_com1 - . - 2",
471471
" mov ebx, 0xE0000",
472472
".Lpb_rsdp_loop:",
473-
" cmp dword ptr [ebx + 0], 0x20445352", // \"RSD \" LE
473+
" cmp dword ptr [ebx + 0], 0x20445352", // \"RSD \" LE
474474
" jne .Lpb_rsdp_next",
475-
" cmp dword ptr [ebx + 4], 0x20525450", // \"PTR \" LE
475+
" cmp dword ptr [ebx + 4], 0x20525450", // \"PTR \" LE
476476
" jne .Lpb_rsdp_next",
477-
" mov dword ptr [0x2D28], ebx", // bundle.rsdp_phys low
478-
" mov dword ptr [0x2D2C], 0", // bundle.rsdp_phys high
477+
" mov dword ptr [0x2D28], ebx", // bundle.rsdp_phys low
478+
" mov dword ptr [0x2D2C], 0", // bundle.rsdp_phys high
479479
" jmp .Lpb_rsdp_done",
480480
".Lpb_rsdp_next:",
481-
" add ebx, 16", // RSDP is on 16-byte boundary
481+
" add ebx, 16", // RSDP is on 16-byte boundary
482482
" cmp ebx, 0xFFFF0",
483483
" jb .Lpb_rsdp_loop",
484484
".Lpb_rsdp_done:",
485485
// ---- SMBIOS / VBE: skipped in MVP; bundle fields stay 0. ----
486486
// ---- Stamp ZBDL_MAGIC last so kmain can detect partial init ----
487-
" mov dword ptr [0x1000], 0x4C44425A", // ZBDL_MAGIC
487+
" mov dword ptr [0x1000], 0x4C44425A", // ZBDL_MAGIC
488488
" mov al, 'k'",
489489
".byte 0xE8",
490490
".word rm_outb_com1 - . - 2",
491-
" .byte 0xC3", // 16-bit near ret
491+
" .byte 0xC3", // 16-bit near ret
492492
".Lpb_fail:",
493493
// Emit the AL we're panicking on as two hex digits so bring-up
494494
// logs distinguish BIOS error code from parse-time 0xFF.
@@ -529,12 +529,12 @@ global_asm!(
529529
" mov bp, sp",
530530
// Stash inputs at DAP / near-scratch so the BIOS call clobbering
531531
// general registers doesn't lose them.
532-
" mov word ptr [0x0700], 0x0010", // DAP size + reserved
533-
" mov word ptr [0x0702], ax", // count
534-
" mov word ptr [0x0704], 0x5000", // buffer offset (bounce)
535-
" mov word ptr [0x0706], 0x0000", // buffer segment
536-
" mov dword ptr [0x0708], ebx", // LBA low32
537-
" mov dword ptr [0x070C], 0", // LBA high32
532+
" mov word ptr [0x0700], 0x0010", // DAP size + reserved
533+
" mov word ptr [0x0702], ax", // count
534+
" mov word ptr [0x0704], 0x5000", // buffer offset (bounce)
535+
" mov word ptr [0x0706], 0x0000", // buffer segment
536+
" mov dword ptr [0x0708], ebx", // LBA low32
537+
" mov dword ptr [0x070C], 0", // LBA high32
538538
// Save the chunk byte count (AX × 512) in the scratch dword at
539539
// 0x0710 so we can recover it after the BIOS call blows away AX.
540540
" movzx ecx, ax",

0 commit comments

Comments
 (0)