From bef5f13560219e4402c995df4cc4d897bf2bca78 Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Tue, 11 Apr 2017 19:30:19 +0200 Subject: [PATCH] =?UTF-8?q?Print=20a=20=E2=80=9CHello=20World!=E2=80=9D=20?= =?UTF-8?q?in=20Rust?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lib.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index c82ca72..9e2fec8 100644 --- a/src/lib.rs +++ b/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() {}