Skip to content

Commit

Permalink
aarch64 got HALed
Browse files Browse the repository at this point in the history
  • Loading branch information
n1tram1 committed Oct 20, 2024
1 parent 7268ee3 commit f12fbab
Show file tree
Hide file tree
Showing 23 changed files with 609 additions and 337 deletions.
23 changes: 23 additions & 0 deletions NOTES
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
- gic mappings
- kpt.lock().map(allocator=PMM)
map needs to allocate new node
- pmm.alloc
- kpt.lock().map(allocator=NPA) # second locks

my bug
- pgt.map(allocator=PMM)
needs to allocate new pte
- pmm.give_page
need to map that page
pgt.map(allocated=PMM) etc...
but we need to use the current pagetable instead


case when pagetable maps its own stuff
- pgt.map(allocator=PMM)
lock the mutex
needs to allocate new pte
- pmm.give_page
need to map that page
GLOBAL_PAGETABLE.map(allocated=PMM) if pgt == GLOBAL_PAGETABLR back to step 1
- this make use try to lock the mutex again, hang forever
12 changes: 8 additions & 4 deletions aarch64_qemuvirt/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,15 @@ const LAUNCH_TESTS: bool = cfg!(feature = "launch_tests");

use log::info;

unsafe fn disable_fp_trapping() {
asm!("msr CPACR_EL1, {:x}", in(reg) 0b11 << 20)
}

#[no_mangle]
extern "C" fn k_main(_device_tree_ptr: usize) -> ! {
kernel::hal::cpu::disable_fp_trapping();
unsafe {
disable_fp_trapping();
}

static PL011: Pl011 = Pl011::new(0x0900_0000);
kernel::kernel_console::set_earlyinit_console(&PL011);
Expand All @@ -25,9 +31,7 @@ extern "C" fn k_main(_device_tree_ptr: usize) -> ! {

info!("hello, I am a goOSe! proud member of the gagelen !!!");

unsafe {
kernel::hal::irq::init_el1_exception_handlers();
}
kernel::HAL.init_irqs();

unsafe {
asm!("isb SY");
Expand Down
1 change: 1 addition & 0 deletions hal_aarch64/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ hal_core = { path = "../hal_core" }
tock-registers = "0.8"
cortex-a = "8.1"
log = "0.4"
spin = "0.9.8"
34 changes: 27 additions & 7 deletions hal_aarch64/src/devices/gicv2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,33 @@ use tock_registers::interfaces::{ReadWriteable, Readable, Writeable};
use tock_registers::register_bitfields;
use tock_registers::registers::{ReadOnly, ReadWrite};

use core::fmt;
use hal_core::Error;

pub struct GicV2 {
pub distributor: &'static GicDistributor,
pub cpu: &'static GicCpu,
}

impl fmt::Debug for GicV2 {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("GicV2")
.field(
"distributor",
&(self.distributor as *const GicDistributor as *const ()),
)
.field("cpu", &(self.cpu as *const _ as *const ()))
.finish()
}
}

/// Safety:
/// There are two parts to this:
/// - distributor: I don't think this benefits from locking, if two cores write to the same
/// reg, afaik it will just send two packets to the GIC, the latter will just accept both.
/// - cpu: This is already per-cpu, not need to lock it.
unsafe impl Sync for GicV2 {}

impl GicV2 {
pub fn new(distributor_base: usize, cpu_base: usize) -> Self {
let distributor = unsafe {
Expand All @@ -17,32 +37,32 @@ impl GicV2 {
.unwrap()
};
let cpu = unsafe { (cpu_base as *const GicCpu).as_ref().unwrap() };
let mut gic = Self { distributor, cpu };
let gic = Self { distributor, cpu };

gic.init_distributor();

gic
}

pub fn disable_interrupts(&mut self) {
pub fn disable_interrupts(&self) {
self.distributor
.CTLR
.modify(GICD_CTLR::EnableGrp0::Disable + GICD_CTLR::EnableGrp1::Disable);
}

pub fn enable_interrupts(&mut self) {
pub fn enable_interrupts(&self) {
self.distributor
.CTLR
.modify(GICD_CTLR::EnableGrp0::Enable + GICD_CTLR::EnableGrp1::Enable);
}

pub fn get_int(&mut self) -> Result<u32, Error> {
pub fn get_int(&self) -> Result<u32, Error> {
let intno = self.cpu.IAR.get();

Ok(intno)
}

pub fn clear_int(&mut self, int: u32) {
pub fn clear_int(&self, int: u32) {
// TODO: check (maybe in the TRM) if this could fail / give an error.
self.cpu.EOIR.modify(GICC_EOIR::EOIINTID.val(int));
}
Expand All @@ -54,7 +74,7 @@ impl GicV2 {
}

/// Put the Gic in a known state.
fn init_distributor(&mut self) {
fn init_distributor(&self) {
self.disable_interrupts();

for i in 0..(self.nlines() / 32) {
Expand Down Expand Up @@ -98,7 +118,7 @@ impl GicV2 {
);
}

pub fn enable_line(&mut self, line: u32) -> Result<(), Error> {
pub fn enable_line(&self, line: u32) -> Result<(), Error> {
let line = line as usize;
let enable_reg_index = line >> 5;
let enable_bit: u32 = 1u32 << (line % 32);
Expand Down
66 changes: 0 additions & 66 deletions hal_aarch64/src/exceptions.S

This file was deleted.

Loading

0 comments on commit f12fbab

Please sign in to comment.