refactor + wip bios call from protected mode

This commit is contained in:
pantonshire committed 2024-10-16 17:45:52 +01:00
1 parent 121e13165b
commit 766a9c981c
8 files changed
+389 -136

No files matched your search

+38 -22
View File
@@ -8,35 +8,31 @@ const VGA_HEIGHT: usize = 25;
const VGA_SIZE: usize = VGA_WIDTH * VGA_HEIGHT;
const VGA_ADDR: usize = 0xb8000;
const STR: &[u8] = b"the quick brown fox jumps over the lazy dog";
const STR: &[u8] = b"sphinx of black quartz, judge my vow";
// extern "C" {
// fn prelude() -> !;
// }
#[repr(C)]
#[derive(Clone, Debug)]
struct BiosIntr {
eax: u32,
ebx: u32,
ecx: u32,
edx: u32,
esi: u32,
edi: u32,
ds: u16,
es: u16,
eflags: u32,
}
unsafe extern "C" {
unsafe fn bios_call(intr: u32, args: *mut BiosIntr);
}
#[panic_handler]
fn panic(_info: &PanicInfo) -> ! {
hlt()
}
// ```asm
// 00000000 E800000000 call 0x5 ; call / pop gadget to load eip into ecx
// 00000005 59 pop ecx
// 00000006 81C15F000000 add ecx,0x5f
// 0000000C 31C0 xor eax,eax
// 0000000E 8D89D4FFFFFF lea ecx,[ecx-0x2c] ; length of string is 0x2b
// 00000014 0FB611 movzx edx,byte [ecx]
// 00000017 81CA001F0000 or edx,0x1f00
// 0000001D 6689940000800B00 mov [eax+eax+0xb8000],dx
// 00000025 40 inc eax
// 00000026 41 inc ecx
// 00000027 83F82B cmp eax,byte +0x2b
// 0000002A 75E8 jnz 0x14
// 0000002C 66C70500800B0002 mov word [dword 0xb8000],0x1f02
// -1F
// 00000035 F4 hlt
// 00000036 EBFD jmp short 0x35
// ```
#[no_mangle]
pub extern "C" fn _start() -> ! {
let vga_buf: &'static mut [u16; VGA_SIZE] = unsafe { &mut *(VGA_ADDR as *mut [u16; VGA_SIZE]) };
@@ -45,6 +41,26 @@ pub extern "C" fn _start() -> ! {
vga_buf[i] = 0x1f00 | u16::from(b);
}
let mut args = BiosIntr {
eax: 0xe820,
ebx: 0,
ecx: 24,
edx: 0x534d4150,
esi: 0,
edi: 0x6a00,
ds: 0,
es: 0,
eflags: 0,
};
unsafe {
bios_call(0x15, &raw mut args);
}
for (i, b) in STR.iter().copied().enumerate() {
vga_buf[i + VGA_WIDTH] = 0x1f00 | u16::from(b);
}
hlt()
}