You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
73 lines
1001 B
Rust
73 lines
1001 B
Rust
#![no_std]
|
|
#![no_main]
|
|
|
|
mod spin;
|
|
mod vga;
|
|
|
|
use core::{arch::asm, panic::PanicInfo, fmt::Write};
|
|
|
|
#[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) -> ! {
|
|
vga_println!("panic!");
|
|
if let Some(location) = info.location() {
|
|
vga_println!("{}", location);
|
|
}
|
|
vga_println!("{}", info.message());
|
|
hlt()
|
|
}
|
|
|
|
#[no_mangle]
|
|
pub extern "C" fn _start() -> ! {
|
|
vga::vga_init();
|
|
|
|
vga_println!("hello from rust");
|
|
|
|
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);
|
|
}
|
|
|
|
vga_println!("eax = {:x}", args.eax);
|
|
|
|
hlt()
|
|
}
|
|
|
|
#[inline]
|
|
fn hlt() -> ! {
|
|
loop {
|
|
unsafe {
|
|
asm!("hlt");
|
|
}
|
|
}
|
|
}
|
|
|