mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-17 06:47:49 +00:00
Use static and for loop for printing Hello World
This commit is contained in:
21
src/main.rs
21
src/main.rs
@@ -2,22 +2,21 @@
|
||||
#![no_std] // don't link the Rust standard library
|
||||
#![no_main] // disable all Rust-level entry points
|
||||
|
||||
//extern crate rlibc;
|
||||
|
||||
static HELLO: &[u8] = b"Hello World!";
|
||||
|
||||
#[no_mangle] // don't mangle the name of this function
|
||||
pub fn _start() -> ! {
|
||||
// this function is the entry point, since the linker looks for a function
|
||||
// named `_start_` by default
|
||||
let vga_buffer = 0xb8000 as *const u8 as *mut u8;
|
||||
unsafe {
|
||||
*vga_buffer.offset(0) = b'H';
|
||||
*vga_buffer.offset(1) = 0xa; // foreground color green
|
||||
*vga_buffer.offset(2) = b'e';
|
||||
*vga_buffer.offset(3) = 0xa; // foreground color green
|
||||
*vga_buffer.offset(4) = b'l';
|
||||
*vga_buffer.offset(5) = 0xa;
|
||||
*vga_buffer.offset(6) = b'l';
|
||||
*vga_buffer.offset(7) = 0xa;
|
||||
*vga_buffer.offset(8) = b'o';
|
||||
*vga_buffer.offset(9) = 0xa;
|
||||
|
||||
for (i, &byte) in HELLO.iter().enumerate() {
|
||||
unsafe {
|
||||
*vga_buffer.offset(i as isize * 2) = byte;
|
||||
*vga_buffer.offset(i as isize * 2 + 1) = 0xb;
|
||||
}
|
||||
}
|
||||
|
||||
loop {}
|
||||
|
||||
Reference in New Issue
Block a user