Rust tell the compiler to not trust the registers?

71 Views Asked by At

I'm making a bootloader for x86_64 and used some compile options to bring the size of my binary down:

strip = true
opt-level = "s"
lto = true
codegen-units = 1
debug = false
overflow-checks = false
panic = "abort" 

The problem is that when I run my bootloader, it issues a int 0x13 which changes some registers (ah=0 & carry flag is set) I think this break the following code, because I have a print statement that causes problems, where it shouldn't

I think it's because rust assumes the registers have the right values but I'm not sure

I tried removing and re-adding the print statement: Without it, everything works BUT, I know the print function is supposed to work because I use it just above ! The function is:

fn write_v8(s: &[u8], offset: usize) {
    let vga_buffer = unsafe { core::slice::from_raw_parts_mut(0xb8000 as *mut u8, 80 * 25 * 2) };
    for (i, char) in s.iter().enumerate() {
        vga_buffer[i * 2 + offset] = *char as u8;
        vga_buffer[i * 2 + offset+1] = *char as u8;
    }
}

So this function shouldn't have any side effects...

0

There are 0 best solutions below