Skip to content

Commit b007a6b

Browse files
committed
Don't use LLVM-reserved registers
1 parent d983247 commit b007a6b

File tree

6 files changed

+34
-23
lines changed

6 files changed

+34
-23
lines changed

bios/boot_sector/src/fail.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ impl<T, E> UnwrapOrFail for Result<T, E> {
3232
pub extern "C" fn print_char(c: u8) {
3333
let ax = u16::from(c) | 0x0e00;
3434
unsafe {
35-
asm!("int 0x10", in("ax") ax, in("bx") 0);
35+
asm!("push bx", "mov bx, 0", "int 0x10", "pop bx", in("ax") ax);
3636
}
3737
}
3838

bios/stage-2/src/memory_map.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,18 @@ pub fn query_memory_map() -> Result<&'static mut [E820MemoryRegion], ()> {
2424
let mut offset = 0;
2525
let buf = [0u8; 24];
2626
loop {
27-
let mut ret = 0;
28-
let mut buf_written_len = 0;
27+
let ret: u32;
28+
let buf_written_len;
2929
unsafe {
3030
asm!(
31+
"push ebx",
32+
"mov ebx, edx",
33+
"mov edx, 0x534D4150",
3134
"int 0x15",
32-
inout ("eax") 0xe820 => ret,
33-
in("edx") SMAP,
34-
inout("ebx") offset,
35+
"mov edx, ebx",
36+
"pop ebx",
37+
inout("eax") 0xe820 => ret,
38+
inout("edx") offset,
3539
inout("ecx") buf.len() => buf_written_len,
3640
in("di") &buf
3741
)

bios/stage-2/src/protected_mode.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,11 @@ pub fn enter_protected_mode_and_jump_to_stage_3(entry_point: *const u8, info: &m
112112
// align the stack
113113
"and esp, 0xffffff00",
114114
// push arguments
115-
"push {info}",
115+
"push {info:e}",
116116
// push entry point address
117-
"push {entry_point}",
117+
"push {entry_point:e}",
118118
info = in(reg) info as *const _ as u32,
119119
entry_point = in(reg) entry_point as u32,
120-
out("ebx") _
121120
);
122121
asm!("ljmp $0x8, $2f", "2:", options(att_syntax));
123122
asm!(
@@ -144,13 +143,13 @@ pub fn enter_protected_mode_and_jump_to_stage_3(entry_point: *const u8, info: &m
144143
fn set_protected_mode_bit() -> u32 {
145144
let mut cr0: u32;
146145
unsafe {
147-
asm!("mov {}, cr0", out(reg) cr0, options(nomem, nostack, preserves_flags));
146+
asm!("mov {:e}, cr0", out(reg) cr0, options(nomem, nostack, preserves_flags));
148147
}
149148
let cr0_protected = cr0 | 1;
150149
write_cr0(cr0_protected);
151150
cr0
152151
}
153152

154153
fn write_cr0(val: u32) {
155-
unsafe { asm!("mov cr0, {}", in(reg) val, options(nostack, preserves_flags)) };
154+
unsafe { asm!("mov cr0, {:e}", in(reg) val, options(nostack, preserves_flags)) };
156155
}

bios/stage-2/src/screen.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use core::{arch::asm, fmt::Write as _};
33
pub fn print_char(c: u8) {
44
let ax = u16::from(c) | 0x0e00;
55
unsafe {
6-
asm!("int 0x10", in("ax") ax, in("bx") 0);
6+
asm!("push bx", "mov bx, 0", "int 0x10", "pop bx", in("ax") ax);
77
}
88
}
99

bios/stage-2/src/vesa.rs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ impl<'a> VesaInfo<'a> {
3535
.split_at_mut(core::mem::size_of::<VbeInfoBlock>());
3636
slice.fill(0);
3737
let block_ptr = slice.as_mut_ptr();
38-
let mut ret: u16 = 0;
38+
let ret;
3939
unsafe {
40-
asm!("mov es, bx", "int 0x10", inout("ax") 0x4f00u16 => ret, in("bx")0, in("di") block_ptr)
40+
asm!("mov es, {:x}", "int 0x10", in(reg)0, inout("ax") 0x4f00u16 => ret, in("di") block_ptr)
4141
};
4242
match ret {
4343
0x4f => {
@@ -165,16 +165,16 @@ impl VesaModeInfo {
165165
slice.fill(0);
166166
let block_ptr = slice.as_mut_ptr();
167167

168-
let mut ret: u16 = 0;
168+
let mut ret: u16;
169169
let mut target_addr = block_ptr as u32;
170-
let segment = (target_addr >> 4);
170+
let segment = target_addr >> 4;
171171
target_addr -= segment << 4;
172172
unsafe {
173173
asm!(
174-
"mov es, bx", "int 0x10",
174+
"mov es, {:x}", "int 0x10",
175+
in(reg) segment as u16,
175176
inout("ax") 0x4f01u16 => ret,
176177
in("cx") mode,
177-
in("bx") segment as u16,
178178
in("di") target_addr as u16
179179
)
180180
};
@@ -210,8 +210,17 @@ impl VesaModeInfo {
210210
}
211211

212212
pub fn enable(&self) -> Result<(), u16> {
213-
let mut ret: u16 = 0;
214-
unsafe { asm!("int 0x10", inout("ax") 0x4f02u16 => ret, in("bx") self.mode) };
213+
let mut ret: u16;
214+
unsafe {
215+
asm!(
216+
"push bx",
217+
"mov bx, {:x}",
218+
"int 0x10",
219+
"pop bx",
220+
in(reg) self.mode,
221+
inout("ax") 0x4f02u16 => ret,
222+
)
223+
};
215224
match ret {
216225
0x4f => Ok(()),
217226
other => Err(other),

bios/stage-3/src/main.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,12 @@ pub fn enter_long_mode_and_jump_to_stage_4(info: &mut BiosInfo) {
3636
"and esp, 0xffffff00",
3737
// push arguments (extended to 64 bit)
3838
"push 0",
39-
"push {info}",
39+
"push {info:e}",
4040
// push entry point address (extended to 64 bit)
4141
"push 0",
42-
"push {entry_point}",
42+
"push {entry_point:e}",
4343
info = in(reg) info as *const _ as u32,
4444
entry_point = in(reg) info.stage_4.start as u32,
45-
out("ebx") _
4645
);
4746
asm!("ljmp $0x8, $2f", "2:", options(att_syntax));
4847
asm!(

0 commit comments

Comments
 (0)