Update the VGA buffer post for the second edition

This commit is contained in:
Philipp Oppermann
2018-02-28 14:14:13 +01:00
parent fab439d6a3
commit 557b869aa4
8 changed files with 414 additions and 316 deletions

View File

@@ -1,29 +1,29 @@
#![feature(lang_items)] // required for defining the panic handler
#![feature(const_fn)] // allow declaring functions as const
#![no_std] // don't link the Rust standard library
#![no_main] // disable all Rust-level entry points
//extern crate rlibc;
extern crate volatile;
extern crate rlibc;
extern crate spin;
#[macro_use]
extern crate lazy_static;
static HELLO: &[u8] = b"Hello World!";
#[macro_use]
mod vga_buffer;
/// This function is the entry point, since the linker looks for a function
/// named `_start_` by default.
#[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;
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;
}
}
println!("Hello World{}", "!");
loop {}
}
#[lang = "panic_fmt"] // define a function that should be called on panic
#[no_mangle] // TODO required?
/// This function is called on panic.
#[lang = "panic_fmt"]
#[no_mangle]
pub extern fn rust_begin_panic(_msg: core::fmt::Arguments,
_file: &'static str,
_line: u32,