Skip to content

Commit 81f359d

Browse files
committed
Fixed "jc fail" instructions not working properly and updated README.md
1 parent 96f58f2 commit 81f359d

File tree

4 files changed

+15
-9
lines changed

4 files changed

+15
-9
lines changed

bios/boot_sector/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ This executable needs to fit into the 512-byte boot sector, so we need to use al
44

55
## Build Commands
66

7-
1. `cargo build --release -Zbuild-std=core --target x86-16bit.json -Zbuild-std-features=compiler-builtins-mem`
8-
2. `objcopy -I elf32-i386 -O binary target/x86-16bit/release/first_stage target/disk_image.bin
7+
1. `cargo build --profile=stage-1 -Zbuild-std=core --target ../../i386-code16-boot-sector.json -Zbuild-std-features=compiler-builtins-mem`
8+
2. `objcopy -I elf32-i386 -O binary ../../target/i386-code16-boot-sector/stage-1/bootloader-x86_64-bios-boot-sector ../../target/disk_image.img`
99

1010
To run in QEMU:
1111

12-
- `qemu-system-x86_64 -drive format=raw,file=target/disk_image.bin`
12+
- `qemu-system-x86_64 -drive format=raw,file=../../target/disk_image.bin`
1313

1414
To print the contents of the ELF file, e.g. for trying to bring the size down:
1515

16-
- `objdump -xsdS -M i8086,intel target/x86-16bit/release/first_stage`
16+
- `objdump -xsdS -M i8086,intel ../../target/i386-code16-boot-sector/stage-1/bootloader-x86_64-bios-boot-sector`

bios/boot_sector/src/boot.s

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,19 @@ check_int13h_extensions:
3636
mov bx, 0x55aa
3737
# dl contains drive number
3838
int 0x13
39-
jc fail
39+
jc fail_asm
4040
pop ax # pop error code again
4141

4242
rust:
4343
# push arguments
4444
push dx # disk number
4545
call first_stage
46+
# Fail code if first stage returns
47+
push 'x'
48+
49+
# Call rust "fail" function that prints the character on the top of the stack
50+
fail_asm:
51+
call fail
4652

4753
spin:
4854
hlt

bios/boot_sector/src/dap.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ impl DiskAddressPacket {
3838
let self_addr = self as *const Self as u16;
3939
unsafe {
4040
asm!(
41-
"push 0x7a", // error code `z`, passed to `fail` on error
41+
"push 'z'", // error code `z`, passed to `fail` on error
4242
"mov {1:x}, si", // backup the `si` register, whose contents are required by LLVM
4343
"mov si, {0:x}",
4444
"int 0x13",
45-
"jc fail",
45+
"jc fail_asm",
4646
"pop si", // remove error code again
4747
"mov si, {1:x}", // restore the `si` register to its prior state
4848
in(reg) self_addr,

bios/boot_sector/src/mbr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ pub(crate) fn get_partition(partitions_raw: &[u8], index: usize) -> PartitionTab
1616
.get(8..)
1717
.and_then(|s| s.get(..4))
1818
.and_then(|s| s.try_into().ok())
19-
.unwrap_or_fail(b'e'),
19+
.unwrap_or_fail(b'f'),
2020
);
2121
let len = u32::from_le_bytes(
2222
buffer
2323
.get(12..)
2424
.and_then(|s| s.get(..4))
2525
.and_then(|s| s.try_into().ok())
26-
.unwrap_or_fail(b'f'),
26+
.unwrap_or_fail(b'g'),
2727
);
2828
PartitionTableEntry::new(bootable, partition_type, lba, len)
2929
}

0 commit comments

Comments
 (0)