mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-17 06:47:49 +00:00
use vga buffer module for test output
This commit is contained in:
25
src/lib.rs
25
src/lib.rs
@@ -13,26 +13,29 @@
|
|||||||
// 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)]
|
#![feature(core_str_ext, const_fn)]
|
||||||
#![no_std]
|
#![no_std]
|
||||||
|
|
||||||
extern crate rlibc;
|
extern crate rlibc;
|
||||||
|
|
||||||
use core::intrinsics::offset;
|
use core::fmt::Write;
|
||||||
|
|
||||||
|
#[macro_use]
|
||||||
|
mod vga_buffer;
|
||||||
|
|
||||||
#[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", "!"];
|
use vga_buffer::{Writer, Color};
|
||||||
let screen_pointer = 0xb8000 as *const u16;
|
|
||||||
|
|
||||||
for (byte, i) in x.iter().flat_map(|s| s.bytes()).zip(0..) {
|
vga_buffer::clear_screen();
|
||||||
let c = 0x1f00 | (byte as u16);
|
let mut writer = Writer::new(Color::Blue, Color::LightGreen);
|
||||||
unsafe {
|
writer.write_byte(b'H');
|
||||||
let screen_char = offset(screen_pointer, i) as *mut u16;
|
let _ = writer.write_str("ello! ");
|
||||||
*screen_char = c
|
let _ = write!(writer, "The numbers are {} and {}", 42, 1.0/3.0);
|
||||||
}
|
println!("");
|
||||||
}
|
println!("{} {}", "line", 1);
|
||||||
|
print!("line {}", 2);
|
||||||
|
|
||||||
loop{}
|
loop{}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user