mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-16 22:37:49 +00:00
Print a “Hello World!” in Rust
This commit is contained in:
17
src/lib.rs
17
src/lib.rs
@@ -5,8 +5,21 @@ extern crate rlibc;
|
||||
|
||||
#[no_mangle]
|
||||
pub extern fn rust_main() {
|
||||
let x = ["Hello", "World", "!"];
|
||||
let y = x;
|
||||
// ATTENTION: we have a very small stack and no guard page
|
||||
|
||||
let hello = b"Hello World!";
|
||||
let color_byte = 0x1f; // white foreground, blue background
|
||||
|
||||
let mut hello_colored = [color_byte; 24];
|
||||
for (i, char_byte) in hello.into_iter().enumerate() {
|
||||
hello_colored[i*2] = *char_byte;
|
||||
}
|
||||
|
||||
// write `Hello World!` to the center of the VGA text buffer
|
||||
let buffer_ptr = (0xb8000 + 1988) as *mut _;
|
||||
unsafe { *buffer_ptr = hello_colored };
|
||||
|
||||
loop{}
|
||||
}
|
||||
|
||||
#[lang = "eh_personality"] extern fn eh_personality() {}
|
||||
|
||||
Reference in New Issue
Block a user