kernel/src/main.rs

46 lines
1 KiB
Rust
Raw Normal View History

2024-05-13 18:31:37 -04:00
#![no_std]
#![no_main]
#![feature(naked_functions)]
use core::panic::PanicInfo;
2024-05-13 23:12:29 -04:00
mod uart;
2024-05-13 18:31:37 -04:00
#[naked]
#[no_mangle]
#[link_section = ".text.init"]
unsafe extern "C" fn _start() -> ! {
use core::arch::asm;
asm!(
// before we use the `la` pseudo-instruction for the first time,
// we need to set `gp` (google linker relaxation)
".option push",
".option norelax",
"la gp, _global_pointer",
".option pop",
// set the stack pointer
"la sp, _init_stack_top",
// "tail-call" to {entry} (call without saving a return address)
"tail {entry}",
entry = sym entry, // {entry} refers to the function [entry] below
options(noreturn) // we must handle "returning" from assembly
);
}
extern "C" fn entry() -> ! {
2024-05-13 23:12:29 -04:00
// UNSAFE: correct address for QEMU virt device
let mut console = unsafe { uart::Device::new(0x1000_0000) };
for byte in "Hello, world!".bytes() {
console.put(byte);
2024-05-13 18:31:37 -04:00
}
loop {}
}
#[panic_handler]
fn on_panic(_info: &PanicInfo) -> ! {
loop {}
}