Signed-off-by: Julien CLEMENT <julien.clement@epita.fr>
This commit is contained in:
1 parent
be8f3f2a0f
commit
106e907438
6 files changed
+87
-11
No files matched your search
+3
-3
@@ -2,6 +2,7 @@
|
||||
#![no_main]
|
||||
|
||||
mod vga;
|
||||
mod serial;
|
||||
use core::panic::PanicInfo;
|
||||
use vga::Color;
|
||||
|
||||
@@ -12,11 +13,10 @@ fn panic_handler(info: &PanicInfo) -> ! {
|
||||
loop {}
|
||||
}
|
||||
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn julios_main() -> ! {
|
||||
println!("Hello World!");
|
||||
println!("{}", "***JuliOS***");
|
||||
panic!("Test panic");
|
||||
loop {}
|
||||
serial_println!("Test serial");
|
||||
panic!("Kernel end of flow");
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
use uart_16550::SerialPort;
|
||||
use spin::Mutex;
|
||||
use lazy_static::lazy_static;
|
||||
|
||||
lazy_static! {
|
||||
pub static ref SERIAL1: Mutex<SerialPort> = {
|
||||
let mut serial_port = unsafe { SerialPort::new(0x3F8) };
|
||||
serial_port.init();
|
||||
Mutex::new(serial_port)
|
||||
};
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
pub fn _print(args: ::core::fmt::Arguments) {
|
||||
use core::fmt::Write;
|
||||
SERIAL1.lock().write_fmt(args).expect("Printing to serial failed");
|
||||
}
|
||||
|
||||
/// Prints to the host through the serial interface.
|
||||
#[macro_export]
|
||||
macro_rules! serial_print {
|
||||
($($arg:tt)*) => {
|
||||
$crate::serial::_print(format_args!($($arg)*));
|
||||
};
|
||||
}
|
||||
|
||||
/// Prints to the host through the serial interface, appending a newline.
|
||||
#[macro_export]
|
||||
macro_rules! serial_println {
|
||||
() => ($crate::serial_print!("\n"));
|
||||
($fmt:expr) => ($crate::serial_print!(concat!($fmt, "\n")));
|
||||
($fmt:expr, $($arg:tt)*) => ($crate::serial_print!(
|
||||
concat!($fmt, "\n"), $($arg)*));
|
||||
}
|
||||
+5
-6
@@ -1,7 +1,7 @@
|
||||
use volatile::Volatile;
|
||||
use core::fmt;
|
||||
use lazy_static::lazy_static;
|
||||
use spin::Mutex;
|
||||
use volatile::Volatile;
|
||||
|
||||
const BUFFER_HEIGHT: usize = 25;
|
||||
const BUFFER_WIDTH: usize = 80;
|
||||
@@ -9,7 +9,7 @@ const BUFFER_WIDTH: usize = 80;
|
||||
lazy_static! {
|
||||
pub static ref WRITER: Mutex<Writer> = Mutex::new(Writer {
|
||||
column: 0,
|
||||
color_code: ColorCode::new(Color::LightBlue, Color::Black),
|
||||
color_code: ColorCode::new(Color::LightGreen, Color::Black),
|
||||
buffer: unsafe { &mut *(0xb8000 as *mut VgaBuffer) }
|
||||
});
|
||||
}
|
||||
@@ -34,7 +34,6 @@ pub fn change_color(fg: Color, bg: Color) {
|
||||
WRITER.lock().change_color(ColorCode::new(fg, bg))
|
||||
}
|
||||
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
#[repr(u8)]
|
||||
@@ -90,7 +89,7 @@ impl Writer {
|
||||
for byte in s.bytes() {
|
||||
match byte {
|
||||
0x20..=0x7e | b'\n' => self.write_byte(byte),
|
||||
_ => self.write_byte(0xfe)
|
||||
_ => self.write_byte(0xfe),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -109,7 +108,7 @@ impl Writer {
|
||||
let color_code = self.color_code;
|
||||
self.buffer.chars[row][col].write(VgaChar {
|
||||
character: byte,
|
||||
color_code
|
||||
color_code,
|
||||
});
|
||||
self.column += 1;
|
||||
}
|
||||
@@ -130,7 +129,7 @@ impl Writer {
|
||||
fn clear_row(&mut self, row: usize) {
|
||||
let blank = VgaChar {
|
||||
character: b' ',
|
||||
color_code: self.color_code
|
||||
color_code: self.color_code,
|
||||
};
|
||||
for col in 0..BUFFER_WIDTH {
|
||||
self.buffer.chars[row][col].write(blank);
|
||||
|
||||