Skip to content

Commit

Permalink
Make the new bootloader ACPI compat
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy-Python-Programmer committed Apr 15, 2021
1 parent 89a3dee commit ab2a7d6
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 86 deletions.
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,6 @@ preview:
-bios bundled/ovmf/OVMF-pure-efi.fd \
-machine q35 \
-drive if=pflash,format=raw,file=bundled/ovmf/OVMF_CODE-pure-efi.fd \
-drive if=pflash,format=raw,file=bundled/ovmf/OVMF_VARS-pure-efi.fd
-drive if=pflash,format=raw,file=bundled/ovmf/OVMF_VARS-pure-efi.fd \
-m 1G

2 changes: 1 addition & 1 deletion src/aero_kernel/src/acpi/madt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ impl MADT {
intrinsics::atomic_store((TRAMPOLINE as *mut u8).add(i), TRAMPOLINE_BIN[i]);
}

for entry in madt.iter() {}
// for entry in madt.iter() {}
}
}
}
Expand Down
107 changes: 42 additions & 65 deletions src/aero_kernel/src/acpi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ use x86_64::{
PhysAddr, VirtAddr,
};

const LOOKUP_START_ADDRESS: usize = 0xE0000;
const LOOKUP_END_ADDRESS: usize = 0xFFFFF;

use crate::arch::memory::paging::GlobalAllocator;

use self::{fadt::FADT, hpet::HPET, madt::MADT, rsdp::RSDP, sdt::SDT};
Expand Down Expand Up @@ -85,78 +82,58 @@ unsafe fn look_up_table(
}

/// Initialize ACPI tables.
pub fn init(offset_table: &mut OffsetPageTable, frame_allocator: &mut GlobalAllocator) {
pub fn init(
offset_table: &mut OffsetPageTable,
frame_allocator: &mut GlobalAllocator,
rsdp_address: PhysAddr,
physical_memory_offset: VirtAddr,
) {
unsafe {
let start_frame: PhysFrame<Size4KiB> =
PhysFrame::containing_address(PhysAddr::new(LOOKUP_START_ADDRESS as u64));
let end_frame = PhysFrame::containing_address(PhysAddr::new(LOOKUP_END_ADDRESS as u64));

// Map all of the ACPI table space.
for frame in PhysFrame::range_inclusive(start_frame, end_frame) {
let page: Page<Size4KiB> =
Page::containing_address(VirtAddr::new(frame.start_address().as_u64()));

if offset_table.translate_page(page).is_err() {
offset_table
.identity_map(
frame,
PageTableFlags::PRESENT | PageTableFlags::NO_EXECUTE,
frame_allocator,
)
.unwrap()
.flush();
}
}
let rsdp = &*((physical_memory_offset + rsdp_address.as_u64()).as_u64() as *const RSDP);
let sdt_address = rsdp.get_sdt_address() as u64;

let rsdp = RSDP::lookup(LOOKUP_START_ADDRESS, LOOKUP_END_ADDRESS);
let sdt = SDT::from_address(sdt_address, frame_allocator, offset_table);

if let Some(rsdp) = rsdp {
let sdt_address = rsdp.get_sdt_address() as u64;
let sdt = SDT::from_address(sdt_address, frame_allocator, offset_table);
let is_legacy;

let is_legacy;

if sdt.get_signature() == "XSDT" {
is_legacy = false;
} else if sdt.get_signature() == "RSDT" {
is_legacy = true;
} else {
panic!("Invalid RSDP signature.")
}
if sdt.get_signature() == "XSDT" {
is_legacy = false;
} else if sdt.get_signature() == "RSDT" {
is_legacy = true;
} else {
panic!("Invalid RSDP signature.")
}

FADT::new(look_up_table(
fadt::SIGNATURE,
FADT::new(look_up_table(
fadt::SIGNATURE,
sdt,
is_legacy,
frame_allocator,
offset_table,
));

HPET::new(
look_up_table(
hpet::SIGNATURE,
sdt,
is_legacy,
frame_allocator,
offset_table,
));

HPET::new(
look_up_table(
hpet::SIGNATURE,
sdt,
is_legacy,
frame_allocator,
offset_table,
),
frame_allocator,
offset_table,
);

MADT::new(
look_up_table(
madt::SIGNATURE,
sdt,
is_legacy,
frame_allocator,
offset_table,
),
),
frame_allocator,
offset_table,
);

MADT::new(
look_up_table(
madt::SIGNATURE,
sdt,
is_legacy,
frame_allocator,
offset_table,
);
} else {
panic!("Unable to find the RSDP")
}
),
frame_allocator,
offset_table,
);
}
}
17 changes: 0 additions & 17 deletions src/aero_kernel/src/acpi/rsdp.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/// The RSDP (Root System Description Pointer)'s signature.
///
/// **Note**: The trailing space is required.
const RSDP_SIGNATURE: &[u8] = b"RSD PTR ";

#[derive(Copy, Clone, Debug)]
#[repr(C, packed)]
pub struct RSDP {
Expand All @@ -18,18 +13,6 @@ pub struct RSDP {
}

impl RSDP {
pub fn lookup(start_addr: usize, end_addr: usize) -> Option<Self> {
for i in 0..(end_addr + 1 - start_addr) / 16 {
let rsdp = unsafe { &*((start_addr + i * 16) as *const RSDP) };

if &rsdp.signature == RSDP_SIGNATURE {
return Some(*rsdp);
}
}

None
}

/// Get the SDT address.
///
/// Returns the RSDT address if the revision is `0` else it returns the XSDT address.
Expand Down
10 changes: 8 additions & 2 deletions src/aero_kernel/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ mod vga;

use aero_boot::BootInfo;
use linked_list_allocator::LockedHeap;
use x86_64::VirtAddr;
use x86_64::{PhysAddr, VirtAddr};

#[global_allocator]
static AERO_SYSTEM_ALLOCATOR: LockedHeap = LockedHeap::empty();
Expand All @@ -61,6 +61,7 @@ _______ _______ ______ _______ _______ ______
#[export_name = "_start"]
extern "C" fn kernel_main(boot_info: &'static mut BootInfo) -> ! {
let physical_memory_offset = VirtAddr::new(boot_info.physical_memory_offset);
let rsdp_address = PhysAddr::new(boot_info.rsdp_address);

let memory_regions = &boot_info.memory_regions;
let framebuffer = &mut boot_info.framebuffer;
Expand Down Expand Up @@ -96,7 +97,12 @@ extern "C" fn kernel_main(boot_info: &'static mut BootInfo) -> ! {
.expect("Failed to initialize the heap.");
log::info!("Loaded heap");

acpi::init(&mut offset_table, &mut frame_allocator);
acpi::init(
&mut offset_table,
&mut frame_allocator,
rsdp_address,
physical_memory_offset,
);
log::info!("Loaded ACPI");

drivers::pci::init(&mut offset_table, &mut frame_allocator);
Expand Down

0 comments on commit ab2a7d6

Please sign in to comment.