Fix booting on real hardware
All checks were successful
Build / build (push) Successful in 1m11s

This commit is contained in:
Mathieu Strypsteen 2024-11-22 11:21:27 +01:00
parent d718473886
commit b9ab8da576
4 changed files with 13 additions and 11 deletions

View file

@ -24,6 +24,7 @@ static SCI_HANDLER: Mutex<Option<unsafe extern "C" fn(context: *mut c_void) -> U
static SCI_CONTEXT: AtomicPtr<c_void> = AtomicPtr::new(null_mut()); static SCI_CONTEXT: AtomicPtr<c_void> = AtomicPtr::new(null_mut());
use super::{ use super::{
hpet::get_current_time,
sync::{create_semaphore, lock_semaphore, unlock_semaphore, Semaphore, Spinlock}, sync::{create_semaphore, lock_semaphore, unlock_semaphore, Semaphore, Spinlock},
task::{CURRENT_TASK, CURRENT_TASK_LOCK, MULTITASKING_ENABLED}, task::{CURRENT_TASK, CURRENT_TASK_LOCK, MULTITASKING_ENABLED},
}; };
@ -100,8 +101,8 @@ extern "C" fn AcpiOsGetThreadId() -> UINT64 {
task_id as UINT64 task_id as UINT64
} }
#[no_mangle] #[no_mangle]
extern "C" fn AcpiOsGetTimer() { extern "C" fn AcpiOsGetTimer() -> UINT64 {
unimplemented!(); get_current_time() as UINT64 * 10
} }
#[no_mangle] #[no_mangle]
extern "C" fn AcpiOsInitialize() -> ACPI_STATUS { extern "C" fn AcpiOsInitialize() -> ACPI_STATUS {

View file

@ -89,7 +89,7 @@ fn handler() {
SLEEP_LOCK.unlock(); SLEEP_LOCK.unlock();
} }
} }
fn get_current_time() -> usize { pub fn get_current_time() -> usize {
let address = ADDRESS.load(Ordering::SeqCst); let address = ADDRESS.load(Ordering::SeqCst);
let current_counter = unsafe { address.add(REGISTER_COUNTER).read_volatile() }; let current_counter = unsafe { address.add(REGISTER_COUNTER).read_volatile() };
ticks_to_us(current_counter as usize) ticks_to_us(current_counter as usize)

View file

@ -1,6 +1,6 @@
use core::{ use core::{
ptr::null_mut, ptr::null_mut,
sync::atomic::{AtomicPtr, AtomicU32, Ordering}, sync::atomic::{AtomicPtr, AtomicU32, AtomicUsize, Ordering},
}; };
use bitfield::bitfield; use bitfield::bitfield;
@ -36,6 +36,7 @@ const REGISTER_VERSION: u8 = 1;
const REGISTER_REDIRECTION: u8 = 0x10; const REGISTER_REDIRECTION: u8 = 0x10;
static IOAPICS: [IOAPIC; 32] = [EMPTY_IOAPIC; 32]; static IOAPICS: [IOAPIC; 32] = [EMPTY_IOAPIC; 32];
static NEXT_IOAPIC_ID: AtomicUsize = AtomicUsize::new(0);
fn read_register(apic_i: usize, reg_i: u8) -> u32 { fn read_register(apic_i: usize, reg_i: u8) -> u32 {
unsafe { unsafe {
@ -92,13 +93,13 @@ pub fn register_irq_handler(vector: usize, handler: fn()) {
} }
} }
} }
pub fn setup_ioapic(apic_i: u8, phys: u64, gsi_base: u32) { pub fn setup_ioapic(phys: u64, gsi_base: u32) {
let apic_i = apic_i as usize;
let address = unsafe { map_physical(phys, 0x14, false) as *mut u32 }; let address = unsafe { map_physical(phys, 0x14, false) as *mut u32 };
IOAPICS[apic_i].address.store(address, Ordering::SeqCst); let next_id = NEXT_IOAPIC_ID.fetch_add(1, Ordering::SeqCst);
IOAPICS[apic_i].start_gsi.store(gsi_base, Ordering::SeqCst); IOAPICS[next_id].address.store(address, Ordering::SeqCst);
let max_ints = (read_register(apic_i, REGISTER_VERSION) >> 16) & 0xff; IOAPICS[next_id].start_gsi.store(gsi_base, Ordering::SeqCst);
IOAPICS[apic_i].end_gsi.store(gsi_base + max_ints, Ordering::SeqCst); let max_ints = (read_register(next_id, REGISTER_VERSION) >> 16) & 0xff;
IOAPICS[next_id].end_gsi.store(gsi_base + max_ints, Ordering::SeqCst);
assert!(gsi_base + max_ints < 128); assert!(gsi_base + max_ints < 128);
for i in gsi_base..gsi_base + max_ints { for i in gsi_base..gsi_base + max_ints {
let mut redirection = RedirectionEntry(0); let mut redirection = RedirectionEntry(0);

View file

@ -21,7 +21,7 @@ pub fn parse_madt(tables: &AcpiTables<EarlyACPIHandler>) {
setup_lapic(lapic_address); setup_lapic(lapic_address);
for i in madt.entries() { for i in madt.entries() {
if let MadtEntry::IoApic(ioapic) = i { if let MadtEntry::IoApic(ioapic) = i {
setup_ioapic(ioapic.io_apic_id, ioapic.io_apic_address as u64, ioapic.global_system_interrupt_base); setup_ioapic(ioapic.io_apic_address as u64, ioapic.global_system_interrupt_base);
} }
} }
for i in madt.entries() { for i in madt.entries() {