keyboard now works with interrupts, cool
This commit is contained in:
parent
0f79f2843c
commit
4885defefa
7 changed files with 101 additions and 90 deletions
|
|
@ -28,7 +28,7 @@ pub fn cpu_info() -> Result {
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(info) = cpuid.get_feature_info() {
|
if let Some(info) = cpuid.get_feature_info() {
|
||||||
print!("Features:");
|
print!("CPU Features:");
|
||||||
if info.has_fpu() { print!(" fpu") };
|
if info.has_fpu() { print!(" fpu") };
|
||||||
if info.has_vme() { print!(", vme") };
|
if info.has_vme() { print!(", vme") };
|
||||||
if info.has_de() { print!(", de") };
|
if info.has_de() { print!(", de") };
|
||||||
|
|
|
||||||
|
|
@ -36,13 +36,14 @@ pub unsafe fn init() {
|
||||||
MASTER.data.write(master_mask); wait();
|
MASTER.data.write(master_mask); wait();
|
||||||
SLAVE.data.write(slave_mask); wait();
|
SLAVE.data.write(slave_mask); wait();
|
||||||
|
|
||||||
println!("master={:#b}", MASTER.data.read());
|
println!("master={:#x}", MASTER.data.read());
|
||||||
println!("slave ={:#b}", SLAVE.data.read());
|
println!("slave ={:#x}", SLAVE.data.read());
|
||||||
|
|
||||||
unsafe { ::arch::x86::interrupt::irq::trigger(1); }
|
MASTER.mask_set(0);
|
||||||
|
MASTER.mask_clear(1);
|
||||||
|
|
||||||
println!("master={:#b}", MASTER.data.read());
|
// asm!("sti");
|
||||||
println!("slave ={:#b}", SLAVE.data.read());
|
::x86::instructions::interrupts::enable();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Pic {
|
pub struct Pic {
|
||||||
|
|
|
||||||
|
|
@ -1,24 +1,59 @@
|
||||||
// https://wiki.osdev.org/Exceptions
|
// https://wiki.osdev.org/Exceptions
|
||||||
|
|
||||||
|
macro_rules! exception {
|
||||||
|
($name:ident, $func:block) => {
|
||||||
|
pub extern "x86-interrupt" fn $name(stack_frame: &mut ExceptionStackFrame)
|
||||||
|
{
|
||||||
|
println!("Exception: {}", stringify!($name));
|
||||||
|
println!("{:#?}", stack_frame);
|
||||||
|
flush!();
|
||||||
|
|
||||||
|
#[allow(unused_variables)]
|
||||||
|
fn inner(stack: &mut ExceptionStackFrame) {
|
||||||
|
$func
|
||||||
|
}
|
||||||
|
inner(stack_frame);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
macro_rules! exception_err {
|
||||||
|
($name:ident, $func:block) => {
|
||||||
|
pub extern "x86-interrupt" fn $name(
|
||||||
|
stack_frame: &mut ExceptionStackFrame, _error_code: u32)
|
||||||
|
{
|
||||||
|
println!("Exception: {}", stringify!($name));
|
||||||
|
println!("{:#?}", stack_frame);
|
||||||
|
flush!();
|
||||||
|
|
||||||
|
#[allow(unused_variables)]
|
||||||
|
fn inner(stack: &mut ExceptionStackFrame) {
|
||||||
|
$func
|
||||||
|
}
|
||||||
|
inner(stack_frame);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
use x86::structures::idt::*;
|
use x86::structures::idt::*;
|
||||||
|
|
||||||
interrupt!(divide_by_zero, {});
|
exception!(divide_by_zero, {});
|
||||||
interrupt!(debug, {});
|
exception!(debug, {});
|
||||||
interrupt!(non_maskable, {});
|
exception!(non_maskable, {});
|
||||||
interrupt!(breakpoint, {
|
exception!(breakpoint, {
|
||||||
println!("testing here dont mind me");
|
println!("testing here dont mind me");
|
||||||
flush!();
|
flush!();
|
||||||
});
|
});
|
||||||
interrupt!(overflow, {});
|
exception!(overflow, {});
|
||||||
interrupt!(bound_range, {});
|
exception!(bound_range, {});
|
||||||
interrupt!(invalid_opcode, {});
|
exception!(invalid_opcode, {});
|
||||||
interrupt!(device_not_available, {});
|
exception!(device_not_available, {});
|
||||||
interrupt_err!(double_fault, {});
|
exception_err!(double_fault, {});
|
||||||
interrupt!(coprocessor_segment_overrun, {});
|
exception!(coprocessor_segment_overrun, {});
|
||||||
interrupt_err!(invalid_tss, {});
|
exception_err!(invalid_tss, {});
|
||||||
interrupt_err!(segment_not_present, {});
|
exception_err!(segment_not_present, {});
|
||||||
interrupt_err!(stack_segment, {});
|
exception_err!(stack_segment, {});
|
||||||
interrupt_err!(general_protection, {});
|
exception_err!(general_protection, {});
|
||||||
|
|
||||||
pub extern "x86-interrupt" fn page_fault(
|
pub extern "x86-interrupt" fn page_fault(
|
||||||
stack_frame: &mut ExceptionStackFrame, code: PageFaultErrorCode)
|
stack_frame: &mut ExceptionStackFrame, code: PageFaultErrorCode)
|
||||||
|
|
@ -29,9 +64,9 @@ pub extern "x86-interrupt" fn page_fault(
|
||||||
flush!();
|
flush!();
|
||||||
}
|
}
|
||||||
|
|
||||||
interrupt!(x87_fpu, {});
|
exception!(x87_fpu, {});
|
||||||
interrupt_err!(alignment_check, {});
|
exception_err!(alignment_check, {});
|
||||||
interrupt!(machine_check, {});
|
exception!(machine_check, {});
|
||||||
interrupt!(simd, {});
|
exception!(simd, {});
|
||||||
interrupt!(virtualization, {});
|
exception!(virtualization, {});
|
||||||
interrupt_err!(security, {});
|
exception_err!(security, {});
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,22 @@
|
||||||
use x86::structures::idt::*;
|
use x86::structures::idt::*;
|
||||||
use arch::x86::device::pic;
|
use arch::x86::device::pic;
|
||||||
|
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! interrupt {
|
||||||
|
($i:expr, $name:ident, $func:block) => {
|
||||||
|
pub extern "x86-interrupt" fn $name(stack_frame: &mut ExceptionStackFrame)
|
||||||
|
{
|
||||||
|
unsafe { trigger(1); }
|
||||||
|
#[allow(unused_variables)]
|
||||||
|
fn inner(stack: &mut ExceptionStackFrame) {
|
||||||
|
$func
|
||||||
|
}
|
||||||
|
inner(stack_frame);
|
||||||
|
unsafe { acknowledge(1); }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub unsafe fn trigger(irq: u8) {
|
pub unsafe fn trigger(irq: u8) {
|
||||||
if irq < 16 {
|
if irq < 16 {
|
||||||
if irq >= 8 {
|
if irq >= 8 {
|
||||||
|
|
@ -18,34 +34,31 @@ pub unsafe fn acknowledge(irq: usize) {
|
||||||
if irq < 16 {
|
if irq < 16 {
|
||||||
if irq >= 8 {
|
if irq >= 8 {
|
||||||
pic::SLAVE.mask_clear(irq as u8 - 8);
|
pic::SLAVE.mask_clear(irq as u8 - 8);
|
||||||
|
pic::SLAVE.ack();
|
||||||
} else {
|
} else {
|
||||||
pic::MASTER.mask_clear(irq as u8);
|
pic::MASTER.mask_clear(irq as u8);
|
||||||
|
pic::MASTER.ack();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
interrupt!(pit, {});
|
interrupt!(0, pit, {});
|
||||||
|
|
||||||
interrupt!(keyboard, {
|
interrupt!(1, keyboard, {
|
||||||
unsafe { trigger(1); }
|
::keyboard::kbd_callback();
|
||||||
|
|
||||||
println!("IT WOOOOOOOOOORKS WOUHOU!!!!!!");
|
|
||||||
flush!();
|
|
||||||
|
|
||||||
unsafe { acknowledge(1); }
|
|
||||||
});
|
});
|
||||||
|
|
||||||
interrupt!(cascade, {});
|
interrupt!(2, cascade, {});
|
||||||
interrupt!(com2, {});
|
interrupt!(3, com2, {});
|
||||||
interrupt!(com1, {});
|
interrupt!(4, com1, {});
|
||||||
interrupt!(lpt2, {});
|
interrupt!(5, lpt2, {});
|
||||||
interrupt!(floppy, {});
|
interrupt!(6, floppy, {});
|
||||||
interrupt!(lpt1, {});
|
interrupt!(7, lpt1, {});
|
||||||
interrupt!(rtc, {});
|
interrupt!(8, rtc, {});
|
||||||
interrupt!(pci1, {});
|
interrupt!(9, pci1, {});
|
||||||
interrupt!(pci2, {});
|
interrupt!(10, pci2, {});
|
||||||
interrupt!(pci3, {});
|
interrupt!(11, pci3, {});
|
||||||
interrupt!(mouse, {});
|
interrupt!(12, mouse, {});
|
||||||
interrupt!(fpu, {});
|
interrupt!(13, fpu, {});
|
||||||
interrupt!(ata1, {});
|
interrupt!(14, ata1, {});
|
||||||
interrupt!(ata2, {});
|
interrupt!(15, ata2, {});
|
||||||
|
|
|
||||||
|
|
@ -1,36 +0,0 @@
|
||||||
#[macro_export]
|
|
||||||
macro_rules! interrupt {
|
|
||||||
($name:ident, $func:block) => {
|
|
||||||
pub extern "x86-interrupt" fn $name(stack_frame: &mut ExceptionStackFrame)
|
|
||||||
{
|
|
||||||
println!("Exception: {}", stringify!($name));
|
|
||||||
println!("{:#?}", stack_frame);
|
|
||||||
flush!();
|
|
||||||
|
|
||||||
#[allow(unused_variables)]
|
|
||||||
fn inner(stack: &mut ExceptionStackFrame) {
|
|
||||||
$func
|
|
||||||
}
|
|
||||||
inner(stack_frame);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[macro_export]
|
|
||||||
macro_rules! interrupt_err {
|
|
||||||
($name:ident, $func:block) => {
|
|
||||||
pub extern "x86-interrupt" fn $name(
|
|
||||||
stack_frame: &mut ExceptionStackFrame, _error_code: u32)
|
|
||||||
{
|
|
||||||
println!("Exception: {}", stringify!($name));
|
|
||||||
println!("{:#?}", stack_frame);
|
|
||||||
flush!();
|
|
||||||
|
|
||||||
#[allow(unused_variables)]
|
|
||||||
fn inner(stack: &mut ExceptionStackFrame) {
|
|
||||||
$func
|
|
||||||
}
|
|
||||||
inner(stack_frame);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,15 +1,14 @@
|
||||||
extern crate x86;
|
extern crate x86;
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
pub mod macros;
|
|
||||||
pub mod paging;
|
pub mod paging;
|
||||||
pub mod interrupt;
|
pub mod interrupt;
|
||||||
pub mod device;
|
pub mod device;
|
||||||
|
|
||||||
pub mod idt;
|
pub mod idt;
|
||||||
|
|
||||||
use multiboot2;
|
use multiboot2;
|
||||||
use acpi;
|
use acpi;
|
||||||
use raw_cpuid::CpuId;
|
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern fn x86_rust_start(multiboot_info_addr: usize) {
|
pub unsafe extern fn x86_rust_start(multiboot_info_addr: usize) {
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,8 @@
|
||||||
#![feature(abi_x86_interrupt)]
|
#![feature(abi_x86_interrupt)]
|
||||||
|
|
||||||
extern crate rlibc;
|
extern crate rlibc;
|
||||||
#[macro_use] extern crate alloc;
|
// #[macro_use]
|
||||||
|
extern crate alloc;
|
||||||
#[macro_use] extern crate lazy_static;
|
#[macro_use] extern crate lazy_static;
|
||||||
extern crate spin;
|
extern crate spin;
|
||||||
extern crate multiboot2;
|
extern crate multiboot2;
|
||||||
|
|
@ -45,9 +46,7 @@ pub mod arch;
|
||||||
/// kernel entry point. arch module is responsible for calling this
|
/// kernel entry point. arch module is responsible for calling this
|
||||||
pub fn kmain() -> ! {
|
pub fn kmain() -> ! {
|
||||||
|
|
||||||
// x86::instructions::interrupts::disable();
|
// x86::instructions::interrupts::int3();
|
||||||
x86::instructions::interrupts::int3();
|
|
||||||
// x86::instructions::interrupts::enable();
|
|
||||||
|
|
||||||
// fn stack_overflow() { stack_overflow(); }
|
// fn stack_overflow() { stack_overflow(); }
|
||||||
// stack_overflow();
|
// stack_overflow();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue