feat(idt): add simple idt

Signed-off-by: Julien CLEMENT <julien.clement@epita.fr>
This commit is contained in:
Julien CLEMENT 2021-12-03 20:21:03 +01:00
parent bec3630c11
commit 20e5771780
5 changed files with 53 additions and 11 deletions

@ -164,7 +164,7 @@ p2_table:
resb 4096 resb 4096
stack_bottom: stack_bottom:
resb 4096 resb 65536
stack_top: stack_top:
@ -184,7 +184,5 @@ long_mode_start:
extern julios_main extern julios_main
call julios_main call julios_main
mov rax, 0x2f592f412f4b2f4f
mov qword [0xb8000], rax
.loop: .loop:
jmp .loop jmp .loop

25
src/interrupts.rs Normal file

@ -0,0 +1,25 @@
use x86_64::structures::idt::{InterruptDescriptorTable, InterruptStackFrame};
use crate::println;
use lazy_static::lazy_static;
use crate::vga::{self, Color, ColorCode};
lazy_static! {
static ref IDT: InterruptDescriptorTable = {
let mut idt = InterruptDescriptorTable::new();
idt.breakpoint.set_handler_fn(breakpoint_handler);
idt
};
}
pub fn init_idt() {
println!("Load IDT");
IDT.load();
}
extern "x86-interrupt" fn breakpoint_handler(
stack_frame: InterruptStackFrame) {
let color: vga::ColorCode = vga::get_color();
vga::change_color(ColorCode::new(Color::Pink, Color::Black));
println!("EXCEPTION: BREAKPOINT\n{:#?}", stack_frame);
vga::change_color(color);
}

@ -1,21 +1,33 @@
#![no_std] #![no_std]
#![no_main] #![no_main]
#![feature(abi_x86_interrupt)]
mod serial; mod serial;
mod vga; mod vga;
mod interrupts;
use core::panic::PanicInfo; use core::panic::PanicInfo;
use vga::Color; use vga::{Color, ColorCode};
#[panic_handler] #[panic_handler]
fn panic_handler(info: &PanicInfo) -> ! { fn panic_handler(info: &PanicInfo) -> ! {
vga::change_color(Color::LightRed, Color::Black); vga::change_color(ColorCode::new(Color::LightRed, Color::Black));
println!("{}", info); println!("{}", info);
loop {} loop {}
} }
pub fn init() {
vga::change_color(ColorCode::new(Color::LightCyan, Color::Black));
println!("Starting init");
interrupts::init_idt();
vga::change_color(ColorCode::new(Color::LightGreen, Color::Black));
}
#[no_mangle] #[no_mangle]
pub extern "C" fn julios_main() -> ! { pub extern "C" fn julios_main() -> ! {
init();
println!("***JuliOS V0.1.0***"); println!("***JuliOS V0.1.0***");
serial_println!("Hello serial"); serial_println!("Hello serial");
x86_64::instructions::interrupts::int3();
panic!("Kernel end of flow"); panic!("Kernel end of flow");
} }

@ -16,7 +16,7 @@ const ENABLE_TRANSMITTER: u8 = 0x1 << 1;
const FIFO: u8 = 0x1; const FIFO: u8 = 0x1;
const TRIGGER_LVL_14: u8 = 0x3 << 6; const TRIGGER_LVL_14: u8 = 0x3 << 6;
const CLEAR_TRANSMIT_FIFO: u8 = 0x1 << 2; const CLEAR_TRANSMIT_FIFO: u8 = 0x1 << 2;
const CLEAR_REVEIVE_FIFO: u8 = 0x1 << 1; const CLEAR_RECEIVE_FIFO: u8 = 0x1 << 1;
const NO_PARITY: u8 = 0x0; const NO_PARITY: u8 = 0x0;
const EIGHT_BITS_LENGTH: u8 = 0x3; const EIGHT_BITS_LENGTH: u8 = 0x3;
@ -118,7 +118,7 @@ impl SerialPort {
unsafe { unsafe {
self.line_control.write(NO_PARITY | EIGHT_BITS_LENGTH); self.line_control.write(NO_PARITY | EIGHT_BITS_LENGTH);
self.fifo_control self.fifo_control
.write(FIFO | TRIGGER_LVL_14 | CLEAR_TRANSMIT_FIFO | CLEAR_REVEIVE_FIFO); .write(FIFO | TRIGGER_LVL_14 | CLEAR_TRANSMIT_FIFO | CLEAR_RECEIVE_FIFO);
self.interrupt_enable.write(ENABLE_TRANSMITTER); self.interrupt_enable.write(ENABLE_TRANSMITTER);
} }
} }

@ -30,8 +30,11 @@ pub fn _print(args: fmt::Arguments) {
use core::fmt::Write; use core::fmt::Write;
WRITER.lock().write_fmt(args).unwrap(); WRITER.lock().write_fmt(args).unwrap();
} }
pub fn change_color(fg: Color, bg: Color) { pub fn change_color(color: ColorCode) {
WRITER.lock().change_color(ColorCode::new(fg, bg)) WRITER.lock().change_color(color)
}
pub fn get_color() -> ColorCode {
WRITER.lock().get_color()
} }
#[allow(dead_code)] #[allow(dead_code)]
@ -58,10 +61,10 @@ pub enum Color {
#[derive(Debug, Clone, Copy, PartialEq, Eq)] #[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(transparent)] #[repr(transparent)]
struct ColorCode(u8); pub struct ColorCode(u8);
impl ColorCode { impl ColorCode {
fn new(fg: Color, bg: Color) -> ColorCode { pub fn new(fg: Color, bg: Color) -> ColorCode {
ColorCode((bg as u8) << 4 | (fg as u8)) ColorCode((bg as u8) << 4 | (fg as u8))
} }
} }
@ -139,6 +142,10 @@ impl Writer {
fn change_color(&mut self, color: ColorCode) { fn change_color(&mut self, color: ColorCode) {
self.color_code = color; self.color_code = color;
} }
fn get_color(&mut self) -> ColorCode {
self.color_code
}
} }
impl fmt::Write for Writer { impl fmt::Write for Writer {