Compare commits
No commits in common. "62be6d047ef6249074e67a1b10002073559a2a45" and "337a40e84ca7eecdf29dca5f55013d32a169aeb5" have entirely different histories.
62be6d047e
...
337a40e84c
17
Cargo.lock
generated
17
Cargo.lock
generated
@ -19,8 +19,6 @@ name = "julios"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"pc-keyboard",
|
|
||||||
"pic8259",
|
|
||||||
"spin",
|
"spin",
|
||||||
"volatile 0.2.7",
|
"volatile 0.2.7",
|
||||||
"x86_64",
|
"x86_64",
|
||||||
@ -35,21 +33,6 @@ dependencies = [
|
|||||||
"spin",
|
"spin",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "pc-keyboard"
|
|
||||||
version = "0.5.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "5c6f2d937e3b8d63449b01401e2bae4041bc9dd1129c2e3e0d239407cf6635ac"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "pic8259"
|
|
||||||
version = "0.10.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "24ec21f514e2e16e94649f1d041ca4a7069b512c037ac156360652a775e6229d"
|
|
||||||
dependencies = [
|
|
||||||
"x86_64",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "spin"
|
name = "spin"
|
||||||
version = "0.5.2"
|
version = "0.5.2"
|
||||||
|
@ -12,8 +12,6 @@ crate-type = ["staticlib"]
|
|||||||
volatile = "0.2.6"
|
volatile = "0.2.6"
|
||||||
spin = "0.5.2"
|
spin = "0.5.2"
|
||||||
x86_64 = "0.14.2"
|
x86_64 = "0.14.2"
|
||||||
pic8259 = "0.10.1"
|
|
||||||
pc-keyboard = "0.5.0"
|
|
||||||
|
|
||||||
[dependencies.lazy_static]
|
[dependencies.lazy_static]
|
||||||
version = "1.0"
|
version = "1.0"
|
||||||
|
17
src/gdt.rs
17
src/gdt.rs
@ -1,11 +1,8 @@
|
|||||||
use crate::println;
|
use crate::println;
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use x86_64::instructions::{
|
use x86_64::{VirtAddr, structures::tss::TaskStateSegment};
|
||||||
segmentation::{Segment, CS},
|
use x86_64::structures::gdt::{GlobalDescriptorTable, Descriptor, SegmentSelector};
|
||||||
tables::load_tss,
|
use x86_64::instructions::{segmentation::{CS, Segment}, tables::load_tss};
|
||||||
};
|
|
||||||
use x86_64::structures::gdt::{Descriptor, GlobalDescriptorTable, SegmentSelector};
|
|
||||||
use x86_64::{structures::tss::TaskStateSegment, VirtAddr};
|
|
||||||
|
|
||||||
pub const DOUBLE_FAULT_IST_INDEX: u16 = 0;
|
pub const DOUBLE_FAULT_IST_INDEX: u16 = 0;
|
||||||
|
|
||||||
@ -29,13 +26,7 @@ lazy_static! {
|
|||||||
let mut gdt = GlobalDescriptorTable::new();
|
let mut gdt = GlobalDescriptorTable::new();
|
||||||
let code_selector = gdt.add_entry(Descriptor::kernel_code_segment());
|
let code_selector = gdt.add_entry(Descriptor::kernel_code_segment());
|
||||||
let tss_selector = gdt.add_entry(Descriptor::tss_segment(&TSS));
|
let tss_selector = gdt.add_entry(Descriptor::tss_segment(&TSS));
|
||||||
(
|
(gdt, Selectors { code_selector, tss_selector })
|
||||||
gdt,
|
|
||||||
Selectors {
|
|
||||||
code_selector,
|
|
||||||
tss_selector,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,49 +1,17 @@
|
|||||||
use crate::gdt;
|
use crate::gdt;
|
||||||
|
use crate::println;
|
||||||
use crate::vga::{self, Color, ColorCode};
|
use crate::vga::{self, Color, ColorCode};
|
||||||
use crate::{print, println};
|
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use pc_keyboard::{layouts, DecodedKey, HandleControl, Keyboard, ScancodeSet1};
|
|
||||||
use pic8259::ChainedPics;
|
|
||||||
use spin::{self, Mutex};
|
|
||||||
use x86_64::instructions::port::Port;
|
|
||||||
use x86_64::structures::idt::{InterruptDescriptorTable, InterruptStackFrame};
|
use x86_64::structures::idt::{InterruptDescriptorTable, InterruptStackFrame};
|
||||||
|
|
||||||
pub const PIC_1_OFFSET: u8 = 32;
|
|
||||||
pub const PIC_2_OFFSET: u8 = PIC_1_OFFSET + 8;
|
|
||||||
|
|
||||||
pub const PS2_CONTROLLER_PORT: u16 = 0x60;
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
|
||||||
#[repr(u8)]
|
|
||||||
pub enum InterruptIndex {
|
|
||||||
Timer = PIC_1_OFFSET,
|
|
||||||
Keyboard,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl InterruptIndex {
|
|
||||||
fn as_u8(self) -> u8 {
|
|
||||||
self as u8
|
|
||||||
}
|
|
||||||
|
|
||||||
fn as_usize(self) -> usize {
|
|
||||||
usize::from(self.as_u8())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub static PICS: spin::Mutex<ChainedPics> =
|
|
||||||
spin::Mutex::new(unsafe { ChainedPics::new(PIC_1_OFFSET, PIC_2_OFFSET) });
|
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
static ref IDT: InterruptDescriptorTable = {
|
static ref IDT: InterruptDescriptorTable = {
|
||||||
let mut idt = InterruptDescriptorTable::new();
|
let mut idt = InterruptDescriptorTable::new();
|
||||||
idt.breakpoint.set_handler_fn(breakpoint_handler);
|
idt.breakpoint.set_handler_fn(breakpoint_handler);
|
||||||
unsafe {
|
unsafe {
|
||||||
idt.double_fault
|
idt.double_fault.set_handler_fn(double_fault_handler)
|
||||||
.set_handler_fn(double_fault_handler)
|
|
||||||
.set_stack_index(gdt::DOUBLE_FAULT_IST_INDEX);
|
.set_stack_index(gdt::DOUBLE_FAULT_IST_INDEX);
|
||||||
}
|
}
|
||||||
idt[InterruptIndex::Timer.as_usize()].set_handler_fn(timer_interrupt_handler);
|
|
||||||
idt[InterruptIndex::Keyboard.as_usize()].set_handler_fn(keyboard_interrupt_handler);
|
|
||||||
idt
|
idt
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -51,12 +19,6 @@ lazy_static! {
|
|||||||
pub fn init_idt() {
|
pub fn init_idt() {
|
||||||
println!("Loading IDT");
|
println!("Loading IDT");
|
||||||
IDT.load();
|
IDT.load();
|
||||||
|
|
||||||
println!("Initializing PIC");
|
|
||||||
unsafe { PICS.lock().initialize() };
|
|
||||||
|
|
||||||
println!("Enabling interrupts");
|
|
||||||
x86_64::instructions::interrupts::enable();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "x86-interrupt" fn breakpoint_handler(stack_frame: InterruptStackFrame) {
|
extern "x86-interrupt" fn breakpoint_handler(stack_frame: InterruptStackFrame) {
|
||||||
@ -72,37 +34,3 @@ extern "x86-interrupt" fn double_fault_handler(
|
|||||||
) -> ! {
|
) -> ! {
|
||||||
panic!("EXCEPTION: DOUBLE FAULT\n{:#?}", stack_frame);
|
panic!("EXCEPTION: DOUBLE FAULT\n{:#?}", stack_frame);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "x86-interrupt" fn timer_interrupt_handler(_stack_frame: InterruptStackFrame) {
|
|
||||||
print!(".");
|
|
||||||
unsafe {
|
|
||||||
PICS.lock()
|
|
||||||
.notify_end_of_interrupt(InterruptIndex::Timer.as_u8());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
extern "x86-interrupt" fn keyboard_interrupt_handler(_stack_frame: InterruptStackFrame) {
|
|
||||||
lazy_static! {
|
|
||||||
static ref KEYBOARD: Mutex<Keyboard<layouts::Us104Key, ScancodeSet1>> =
|
|
||||||
Mutex::new(Keyboard::new(layouts::Us104Key, ScancodeSet1,
|
|
||||||
HandleControl::Ignore)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut keyboard = KEYBOARD.lock();
|
|
||||||
let mut port = Port::new(PS2_CONTROLLER_PORT);
|
|
||||||
let scancode: u8 = unsafe { port.read() };
|
|
||||||
|
|
||||||
if let Ok(Some(key_event)) = keyboard.add_byte(scancode) {
|
|
||||||
if let Some(key) = keyboard.process_keyevent(key_event) {
|
|
||||||
match key {
|
|
||||||
DecodedKey::Unicode(character) => print!("{}", character),
|
|
||||||
DecodedKey::RawKey(key) => print!("{:?}", key),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
unsafe {
|
|
||||||
PICS.lock()
|
|
||||||
.notify_end_of_interrupt(InterruptIndex::Keyboard.as_u8());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -14,13 +14,7 @@ use vga::{Color, ColorCode};
|
|||||||
fn panic_handler(info: &PanicInfo) -> ! {
|
fn panic_handler(info: &PanicInfo) -> ! {
|
||||||
vga::change_color(ColorCode::new(Color::LightRed, Color::Black));
|
vga::change_color(ColorCode::new(Color::LightRed, Color::Black));
|
||||||
println!("{}", info);
|
println!("{}", info);
|
||||||
hlt_loop();
|
loop {}
|
||||||
}
|
|
||||||
|
|
||||||
pub fn hlt_loop() -> ! {
|
|
||||||
loop {
|
|
||||||
x86_64::instructions::hlt();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn init() {
|
pub fn init() {
|
||||||
|
@ -35,13 +35,10 @@ lazy_static! {
|
|||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub fn _print(args: ::core::fmt::Arguments) {
|
pub fn _print(args: ::core::fmt::Arguments) {
|
||||||
use core::fmt::Write;
|
use core::fmt::Write;
|
||||||
use x86_64::instructions::interrupts;
|
|
||||||
interrupts::without_interrupts(|| {
|
|
||||||
SERIAL1
|
SERIAL1
|
||||||
.lock()
|
.lock()
|
||||||
.write_fmt(args)
|
.write_fmt(args)
|
||||||
.expect("Printing to serial failed");
|
.expect("Printing to serial failed");
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Prints to the host through the serial interface.
|
/// Prints to the host through the serial interface.
|
||||||
|
@ -28,11 +28,7 @@ macro_rules! println {
|
|||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub fn _print(args: fmt::Arguments) {
|
pub fn _print(args: fmt::Arguments) {
|
||||||
use core::fmt::Write;
|
use core::fmt::Write;
|
||||||
use x86_64::instructions::interrupts;
|
|
||||||
|
|
||||||
interrupts::without_interrupts(|| {
|
|
||||||
WRITER.lock().write_fmt(args).unwrap();
|
WRITER.lock().write_fmt(args).unwrap();
|
||||||
});
|
|
||||||
}
|
}
|
||||||
pub fn change_color(color: ColorCode) {
|
pub fn change_color(color: ColorCode) {
|
||||||
WRITER.lock().change_color(color)
|
WRITER.lock().change_color(color)
|
||||||
|
Loading…
Reference in New Issue
Block a user