mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-16 14:27:49 +00:00
Merge pull request #4 from phil-opp/better_hello_world
Improve `Hello World!` code
This commit is contained in:
21
src/lib.rs
21
src/lib.rs
@@ -13,27 +13,26 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
#![feature(no_std, lang_items)]
|
#![feature(no_std, lang_items)]
|
||||||
#![feature(core_slice_ext, core_str_ext, core_intrinsics)]
|
|
||||||
#![no_std]
|
#![no_std]
|
||||||
|
|
||||||
extern crate rlibc;
|
extern crate rlibc;
|
||||||
|
|
||||||
use core::intrinsics::offset;
|
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern fn rust_main() {
|
pub extern fn rust_main() {
|
||||||
// ATTENTION: we have a very small stack and no guard page
|
// ATTENTION: we have a very small stack and no guard page
|
||||||
let x = ["Hello", " ", "World", "!"];
|
|
||||||
let screen_pointer = 0xb8000 as *const u16;
|
|
||||||
|
|
||||||
for (byte, i) in x.iter().flat_map(|s| s.bytes()).zip(0..) {
|
let hello = b"Hello World!";
|
||||||
let c = 0x1f00 | (byte as u16);
|
let color_byte = 0x1f; // white foreground, blue background
|
||||||
unsafe {
|
|
||||||
let screen_char = offset(screen_pointer, i) as *mut u16;
|
let mut hello_colored = [color_byte; 24];
|
||||||
*screen_char = c
|
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{}
|
loop{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user