Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ea3f61a

Browse filesBrowse files
authored
Fixed "jc fail" instructions not working properly and updated README.md (#453)
* Fixed "jc fail" instructions not working properly and updated README.md * Fixed stage 2 fail calls and removed additional asm label
1 parent 96f58f2 commit ea3f61a
Copy full SHA for ea3f61a

File tree

Expand file treeCollapse file tree

5 files changed

+20
-11
lines changed
Filter options
Expand file treeCollapse file tree

5 files changed

+20
-11
lines changed

‎bios/boot_sector/README.md

Copy file name to clipboardExpand all lines: bios/boot_sector/README.md
+4-4Lines 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.img`
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

Copy file name to clipboardExpand all lines: bios/boot_sector/src/boot.s
+6-1Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,18 @@ check_int13h_extensions:
3636
mov bx, 0x55aa
3737
# dl contains drive number
3838
int 0x13
39-
jc fail
39+
jnc .int13_pass
40+
call fail
41+
.int13_pass:
4042
pop ax # pop error code again
4143

4244
rust:
4345
# push arguments
4446
push dx # disk number
4547
call first_stage
48+
# Fail code if first stage returns
49+
push 'x'
50+
call fail
4651

4752
spin:
4853
hlt

‎bios/boot_sector/src/dap.rs

Copy file name to clipboardExpand all lines: bios/boot_sector/src/dap.rs
+4-2Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,13 @@ 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+
"jnc 2f", // carry is set on fail
46+
"call fail",
47+
"2:",
4648
"pop si", // remove error code again
4749
"mov si, {1:x}", // restore the `si` register to its prior state
4850
in(reg) self_addr,

‎bios/boot_sector/src/mbr.rs

Copy file name to clipboardExpand all lines: bios/boot_sector/src/mbr.rs
+2-2Lines 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
}

‎bios/stage-2/src/dap.rs

Copy file name to clipboardExpand all lines: bios/stage-2/src/dap.rs
+4-2Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,13 @@ impl DiskAddressPacket {
3838
pub unsafe fn perform_load(&self, disk_number: u16) {
3939
let self_addr = self as *const Self as u16;
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",
4343
"mov si, {0:x}",
4444
"int 0x13",
45-
"jc fail",
45+
"jnc 2f", // carry is set on fail
46+
"call fail",
47+
"2:",
4648
"pop si", // remove error code again
4749
"mov si, {1:x}",
4850
in(reg) self_addr,

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.