mirror of
https://github.com/iceHtwoO/novaOS.git
synced 2026-04-17 04:32:27 +00:00
Hello World on simulator
This commit is contained in:
42
src/main.rs
Normal file
42
src/main.rs
Normal file
@@ -0,0 +1,42 @@
|
||||
#![no_main]
|
||||
#![no_std]
|
||||
#![feature(asm_experimental_arch)]
|
||||
|
||||
use core::{
|
||||
arch::asm,
|
||||
fmt::{self, Write},
|
||||
panic::PanicInfo,
|
||||
};
|
||||
|
||||
#[panic_handler]
|
||||
fn panic(_panic: &PanicInfo) -> ! {
|
||||
loop {}
|
||||
}
|
||||
|
||||
const UART0_DR: u32 = 0x3F20_1000;
|
||||
|
||||
struct Uart;
|
||||
|
||||
impl Write for Uart {
|
||||
fn write_str(&mut self, s: &str) -> fmt::Result {
|
||||
for byte in s.bytes() {
|
||||
unsafe {
|
||||
core::ptr::write_volatile(UART0_DR as *mut u8, byte);
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[unsafe(naked)]
|
||||
pub extern "C" fn _start() -> ! {
|
||||
core::arch::naked_asm!("mov sp, #0x80000", "bl main");
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
fn main() {
|
||||
let mut uart = Uart {};
|
||||
writeln!(uart, "Hello World!\n");
|
||||
loop {}
|
||||
}
|
||||
Reference in New Issue
Block a user