Skip to content

Commit

Permalink
Attempt (unsuccessfully) to see if exhaustively placing all DF precur…
Browse files Browse the repository at this point in the history
…sors at stack indices makes a difference
  • Loading branch information
kennystrawnmusic committed Aug 15, 2022
1 parent d21adfb commit 6517d54
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 19 deletions.
4 changes: 3 additions & 1 deletion src/ahci/hba/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ impl HbaPort {
// Populate command table
for i in 0..32 {
let header = &mut cmd_list[i];
header.cmd_table_base.write(&mut tables[i] as *mut _ as usize as u64);
header
.cmd_table_base
.write(&mut tables[i] as *mut _ as usize as u64);
header.prdt_len.write(0);
}

Expand Down
11 changes: 9 additions & 2 deletions src/ahci/hba/structs.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
use alloc::vec::Vec;
use bitflags::bitflags;
use core::{
mem::MaybeUninit,
ops::{BitAnd, BitOr, Not},
ptr::{addr_of, addr_of_mut},
};
use syscall::io::Io;
use core::{mem::MaybeUninit, ptr::{addr_of, addr_of_mut}, ops::{BitAnd, BitOr, Not}};

#[repr(packed)]
pub struct Mmio<T>(MaybeUninit<T>);
Expand All @@ -24,7 +28,10 @@ impl<T> Mmio<T> {
}
}

impl<T> Io for Mmio<T> where T: Copy + PartialEq + BitAnd<Output = T> + BitOr<Output = T> + Not<Output = T> {
impl<T> Io for Mmio<T>
where
T: Copy + PartialEq + BitAnd<Output = T> + BitOr<Output = T> + Not<Output = T>,
{
type Value = T;

fn read(&self) -> Self::Value {
Expand Down
2 changes: 1 addition & 1 deletion src/ahci/sata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ use {
Disk,
},
crate::refactor_hba_int_err,
core::ptr::copy,
alloc::vec::Vec,
core::mem::MaybeUninit,
core::ptr::copy,
};

pub enum BufferKind<'a> {
Expand Down
5 changes: 5 additions & 0 deletions src/exceptions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ pub struct Selectors {

pub const DOUBLE_FAULT_STACK_INDEX: u16 = 0;
pub const PAGE_FAULT_STACK_INDEX: u16 = 1;
pub const INVALID_TSS_STACK_INDEX: u16 = 2;
pub const DIV_ERR_STACK_INDEX: u16 = 3;
pub const SIGBUS_STACK_INDEX: u16 = 4;
pub const SIGSEGV_STACK_INDEX: u16 = 5;
pub const GPF_STACK_INDEX: u16 = 6;

lazy_static! {
pub static ref TSS: TaskStateSegment = {
Expand Down
31 changes: 22 additions & 9 deletions src/interrupts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,28 @@ lazy_static! {
unsafe {
idt.double_fault
.set_handler_fn(double_fault)
.set_stack_index(crate::exceptions::DOUBLE_FAULT_STACK_INDEX)
};
unsafe { idt.page_fault.set_handler_fn(page_fault).set_stack_index(crate::exceptions::PAGE_FAULT_STACK_INDEX); }
idt.divide_error.set_handler_fn(sigfpe);
idt.invalid_tss.set_handler_fn(invalid_tss);
idt.segment_not_present.set_handler_fn(sigbus);
idt.stack_segment_fault.set_handler_fn(sigsegv);
idt.general_protection_fault
.set_handler_fn(general_protection);
.set_stack_index(crate::exceptions::DOUBLE_FAULT_STACK_INDEX);

idt.page_fault
.set_handler_fn(page_fault)
.set_stack_index(crate::exceptions::PAGE_FAULT_STACK_INDEX);
idt.divide_error
.set_handler_fn(sigfpe)
.set_stack_index(crate::exceptions::DIV_ERR_STACK_INDEX);
idt.invalid_tss
.set_handler_fn(invalid_tss)
.set_stack_index(crate::exceptions::INVALID_TSS_STACK_INDEX);
idt.segment_not_present
.set_handler_fn(sigbus)
.set_stack_index(crate::exceptions::SIGBUS_STACK_INDEX);
idt.stack_segment_fault
.set_handler_fn(sigsegv)
.set_stack_index(crate::exceptions::SIGSEGV_STACK_INDEX);
idt.general_protection_fault
.set_handler_fn(general_protection)
.set_stack_index(crate::exceptions::GPF_STACK_INDEX);
}

idt.breakpoint.set_handler_fn(breakpoint);
idt.bound_range_exceeded
.set_handler_fn(bound_range_exceeded);
Expand Down
10 changes: 4 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,16 +379,14 @@ fn maink(boot_info: &'static mut BootInfo) -> ! {

if let HeaderType::Normal(normal_header) = header.header_type {
let abar = normal_header.base_addresses.0[5];
let abar_test_page = Page::<Size2MiB>::containing_address(VirtAddr::new(
abar as u64,
));
let abar_virt =
abar_test_page.start_address().as_u64();
let abar_test_page =
Page::<Size2MiB>::containing_address(VirtAddr::new(abar as u64));
let abar_virt = abar_test_page.start_address().as_u64();

map_page!(
abar,
abar_virt,
Size2MiB,
Size4KiB,
PageTableFlags::PRESENT | PageTableFlags::WRITABLE | PageTableFlags::NO_CACHE
);

Expand Down

0 comments on commit 6517d54

Please sign in to comment.