File tree Expand file tree Collapse file tree 5 files changed +20
-11
lines changed
Filter options
Expand file tree Collapse file tree 5 files changed +20
-11
lines changed
Original file line number Diff line number Diff line change @@ -4,13 +4,13 @@ This executable needs to fit into the 512-byte boot sector, so we need to use al
4
4
5
5
## Build Commands
6
6
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 `
9
9
10
10
To run in QEMU:
11
11
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 `
13
13
14
14
To print the contents of the ELF file, e.g. for trying to bring the size down:
15
15
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 `
Original file line number Diff line number Diff line change @@ -36,13 +36,18 @@ check_int13h_extensions:
36
36
mov bx , 0x55aa
37
37
# dl contains drive number
38
38
int 0x13
39
- jc fail
39
+ jnc .int13_pass
40
+ call fail
41
+ .int13_pass:
40
42
pop ax # pop error code again
41
43
42
44
rust:
43
45
# push arguments
44
46
push dx # disk number
45
47
call first_stage
48
+ # Fail code if first stage returns
49
+ push 'x'
50
+ call fail
46
51
47
52
spin:
48
53
hlt
Original file line number Diff line number Diff line change @@ -38,11 +38,13 @@ impl DiskAddressPacket {
38
38
let self_addr = self as * const Self as u16 ;
39
39
unsafe {
40
40
asm ! (
41
- "push 0x7a " , // error code `z`, passed to `fail` on error
41
+ "push 'z' " , // error code `z`, passed to `fail` on error
42
42
"mov {1:x}, si" , // backup the `si` register, whose contents are required by LLVM
43
43
"mov si, {0:x}" ,
44
44
"int 0x13" ,
45
- "jc fail" ,
45
+ "jnc 2f" , // carry is set on fail
46
+ "call fail" ,
47
+ "2:" ,
46
48
"pop si" , // remove error code again
47
49
"mov si, {1:x}" , // restore the `si` register to its prior state
48
50
in( reg) self_addr,
Original file line number Diff line number Diff line change @@ -16,14 +16,14 @@ pub(crate) fn get_partition(partitions_raw: &[u8], index: usize) -> PartitionTab
16
16
. get ( 8 ..)
17
17
. and_then ( |s| s. get ( ..4 ) )
18
18
. and_then ( |s| s. try_into ( ) . ok ( ) )
19
- . unwrap_or_fail ( b'e ' ) ,
19
+ . unwrap_or_fail ( b'f ' ) ,
20
20
) ;
21
21
let len = u32:: from_le_bytes (
22
22
buffer
23
23
. get ( 12 ..)
24
24
. and_then ( |s| s. get ( ..4 ) )
25
25
. and_then ( |s| s. try_into ( ) . ok ( ) )
26
- . unwrap_or_fail ( b'f ' ) ,
26
+ . unwrap_or_fail ( b'g ' ) ,
27
27
) ;
28
28
PartitionTableEntry :: new ( bootable, partition_type, lba, len)
29
29
}
Original file line number Diff line number Diff line change @@ -38,11 +38,13 @@ impl DiskAddressPacket {
38
38
pub unsafe fn perform_load ( & self , disk_number : u16 ) {
39
39
let self_addr = self as * const Self as u16 ;
40
40
asm ! (
41
- "push 0x7a " , // error code `z`, passed to `fail` on error
41
+ "push 'z' " , // error code `z`, passed to `fail` on error
42
42
"mov {1:x}, si" ,
43
43
"mov si, {0:x}" ,
44
44
"int 0x13" ,
45
- "jc fail" ,
45
+ "jnc 2f" , // carry is set on fail
46
+ "call fail" ,
47
+ "2:" ,
46
48
"pop si" , // remove error code again
47
49
"mov si, {1:x}" ,
48
50
in( reg) self_addr,
You can’t perform that action at this time.
0 commit comments