struggling with drives PIC hardware interrupts
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Signed-off-by: Julien CLEMENT <julien.clement@epita.fr>
This commit is contained in:
parent
5e41662c09
commit
8e0fbfe263
@ -54,7 +54,7 @@ static ATAPI_SIG: [u8; 4] = [
|
||||
];
|
||||
|
||||
lazy_static! {
|
||||
static ref DRIVE: Mutex<Option<ATABus>> = {
|
||||
pub static ref DRIVE: Mutex<Option<ATABus>> = {
|
||||
Mutex::new(ATABus::discover_atapi_drive())
|
||||
};
|
||||
}
|
||||
@ -80,7 +80,7 @@ pub fn init() {
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct ATABus {
|
||||
pub struct ATABus {
|
||||
base_port: u16,
|
||||
|
||||
// IO ports
|
||||
@ -99,7 +99,7 @@ struct ATABus {
|
||||
|
||||
current_drive: u8,
|
||||
|
||||
block: [u8; CD_SECTOR_SIZE],
|
||||
pub block: [u8; CD_SECTOR_SIZE],
|
||||
}
|
||||
|
||||
impl ATABus {
|
||||
@ -108,7 +108,7 @@ impl ATABus {
|
||||
|
||||
unsafe {
|
||||
primary_bus.dcr.write(ATA_SRST);
|
||||
primary_bus.dcr.write(ATA_INTERRUPT_DISABLE);
|
||||
primary_bus.dcr.write(0);
|
||||
}
|
||||
|
||||
primary_bus.select_drive(ATA_DRIVE_MASTER);
|
||||
@ -125,7 +125,7 @@ impl ATABus {
|
||||
|
||||
unsafe {
|
||||
secondary_bus.dcr.write(ATA_SRST);
|
||||
primary_bus.dcr.write(ATA_INTERRUPT_DISABLE);
|
||||
primary_bus.dcr.write(0);
|
||||
}
|
||||
|
||||
secondary_bus.select_drive(ATA_DRIVE_MASTER);
|
||||
@ -204,7 +204,7 @@ impl ATABus {
|
||||
}
|
||||
}
|
||||
|
||||
fn read_block(&mut self, lba: u32) {
|
||||
pub fn read_block(&mut self, lba: u32) {
|
||||
let mut packet = SCSIPacket::new();
|
||||
|
||||
packet.op_code = SCSI_READ_12;
|
||||
|
@ -3,7 +3,14 @@ use crate::hlt_loop;
|
||||
use crate::memory::gdt;
|
||||
use crate::println;
|
||||
use lazy_static::lazy_static;
|
||||
use pic::{init_pic, keyboard_interrupt_handler, timer_interrupt_handler, InterruptIndex};
|
||||
use pic::{
|
||||
init_pic,
|
||||
keyboard_interrupt_handler,
|
||||
timer_interrupt_handler,
|
||||
disk1_interrupt_handler,
|
||||
disk2_interrupt_handler,
|
||||
InterruptIndex
|
||||
};
|
||||
use x86_64::structures::idt::PageFaultErrorCode;
|
||||
use x86_64::structures::idt::{InterruptDescriptorTable, InterruptStackFrame};
|
||||
|
||||
@ -21,6 +28,8 @@ lazy_static! {
|
||||
}
|
||||
idt[InterruptIndex::Timer.as_usize()].set_handler_fn(timer_interrupt_handler);
|
||||
idt[InterruptIndex::Keyboard.as_usize()].set_handler_fn(keyboard_interrupt_handler);
|
||||
idt[InterruptIndex::HardDisk1.as_usize()].set_handler_fn(disk1_interrupt_handler);
|
||||
idt[InterruptIndex::HardDisk2.as_usize()].set_handler_fn(disk2_interrupt_handler);
|
||||
idt
|
||||
};
|
||||
}
|
||||
|
24
src/interrupts/pic/disk.rs
Normal file
24
src/interrupts/pic/disk.rs
Normal file
@ -0,0 +1,24 @@
|
||||
use crate::println;
|
||||
|
||||
use super::{InterruptIndex, PICS};
|
||||
use x86_64::structures::idt::InterruptStackFrame;
|
||||
|
||||
fn disk_interrupt_handler(disk: u16) {
|
||||
println!("Received disk {} interrupt", disk);
|
||||
}
|
||||
|
||||
pub extern "x86-interrupt" fn disk1_interrupt_handler(_stack_frame: InterruptStackFrame) {
|
||||
disk_interrupt_handler(1);
|
||||
unsafe {
|
||||
PICS.lock()
|
||||
.notify_end_of_interrupt(InterruptIndex::HardDisk1.as_u8());
|
||||
}
|
||||
}
|
||||
|
||||
pub extern "x86-interrupt" fn disk2_interrupt_handler(_stack_frame: InterruptStackFrame) {
|
||||
disk_interrupt_handler(2);
|
||||
unsafe {
|
||||
PICS.lock()
|
||||
.notify_end_of_interrupt(InterruptIndex::HardDisk2.as_u8());
|
||||
}
|
||||
}
|
@ -2,9 +2,11 @@ use crate::println;
|
||||
pub use keyboard::keyboard_interrupt_handler;
|
||||
use pic8259::ChainedPics;
|
||||
pub use pit::timer_interrupt_handler;
|
||||
pub use disk::{disk1_interrupt_handler, disk2_interrupt_handler};
|
||||
|
||||
pub mod keyboard;
|
||||
pub mod pit;
|
||||
pub mod disk;
|
||||
|
||||
pub const PIC_1_OFFSET: u8 = 32;
|
||||
pub const PIC_2_OFFSET: u8 = PIC_1_OFFSET + 8;
|
||||
@ -14,6 +16,8 @@ pub const PIC_2_OFFSET: u8 = PIC_1_OFFSET + 8;
|
||||
pub enum InterruptIndex {
|
||||
Timer = PIC_1_OFFSET,
|
||||
Keyboard,
|
||||
HardDisk1 = PIC_1_OFFSET + 14,
|
||||
HardDisk2 = PIC_1_OFFSET + 15,
|
||||
}
|
||||
|
||||
impl InterruptIndex {
|
||||
|
@ -40,8 +40,10 @@ pub fn init(boot_info: &BootInformation) {
|
||||
println!("Starting init");
|
||||
memory::init(boot_info);
|
||||
memory::gdt::init_gdt();
|
||||
drivers::atapi::init();
|
||||
interrupts::init_idt();
|
||||
drivers::atapi::init();
|
||||
drivers::atapi::DRIVE.lock().as_mut().unwrap().read_block(0);
|
||||
serial_println!("{:x?}", drivers::atapi::DRIVE.lock().as_mut().unwrap().block);
|
||||
vga::change_color(ColorCode::new(Color::LightGreen, Color::Black));
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user