-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
212 additions
and
30 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
use core::ptr::NonNull; | ||
|
||
use acpi::{AcpiError, AcpiHandler, AcpiTables}; | ||
|
||
use crate::{common::{CPU_NUM, PCI_ADDR}, consts::VIRT_ADDR_START}; | ||
|
||
#[derive(Clone)] | ||
struct AcpiImpl; | ||
|
||
impl AcpiHandler for AcpiImpl { | ||
unsafe fn map_physical_region<T>( | ||
&self, | ||
physical_address: usize, | ||
size: usize, | ||
) -> acpi::PhysicalMapping<Self, T> { | ||
unsafe { | ||
acpi::PhysicalMapping::new( | ||
physical_address, | ||
NonNull::new((physical_address | VIRT_ADDR_START) as *mut T).unwrap(), | ||
size, | ||
size, | ||
AcpiImpl, | ||
) | ||
} | ||
} | ||
|
||
fn unmap_physical_region<T>(_region: &acpi::PhysicalMapping<Self, T>) {} | ||
} | ||
|
||
/// Detects the address of acpi through acpi_signature. | ||
/// | ||
/// Detects in bios area. | ||
pub(crate) fn detect_acpi() -> Result<(), AcpiError> { | ||
unsafe { | ||
match AcpiTables::search_for_rsdp_bios(AcpiImpl) { | ||
Ok(ref acpi_table) => { | ||
let madt = acpi_table.find_table::<acpi::madt::Madt>()?; | ||
let cpu_count = madt | ||
.entries() | ||
.filter(|x| matches!(x, acpi::madt::MadtEntry::LocalApic(_))) | ||
.count(); | ||
CPU_NUM.init(cpu_count); | ||
} | ||
Err(err) => log::warn!("Not Found Available ACPI: {:#x?}", err), | ||
} | ||
} | ||
Err(AcpiError::NoValidRsdp) | ||
} | ||
|
||
/// Parse informations from acpi table. | ||
pub(crate) fn parse_acpi_info() -> Result<(), AcpiError> { | ||
unsafe { | ||
match AcpiTables::search_for_rsdp_bios(AcpiImpl) { | ||
Ok(ref acpi_table) => { | ||
acpi::PciConfigRegions::new(acpi_table).expect("can't find pci config"); | ||
let pci_addr = acpi::PciConfigRegions::new(acpi_table)? | ||
.physical_address(0, 0, 0, 0) | ||
.ok_or(AcpiError::NoValidRsdp)?; | ||
PCI_ADDR.init(pci_addr as _); | ||
} | ||
Err(err) => log::warn!("Not Found Available ACPI: {:#x?}", err), | ||
} | ||
} | ||
Err(AcpiError::NoValidRsdp) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,28 @@ | ||
// TODO: Boot a core with top pointer of the stack | ||
pub fn boot_core(_hart_id: usize, _sp_top: usize) { | ||
log::error!("Boot Core is not implemented yet for aarch64"); | ||
use core::sync::atomic::{AtomicBool, Ordering}; | ||
|
||
/// TODO: Boot a core with top pointer of the stack | ||
/// Fina a way to pass the stack pointer to core. | ||
pub fn boot_core(hart_id: usize, _sp_top: usize) { | ||
static BOOT_LOCK: AtomicBool = AtomicBool::new(false); | ||
|
||
// Waiting until the previous boot is completed. | ||
while BOOT_LOCK.load(Ordering::SeqCst) {}; | ||
|
||
// Set the boot lock to true and start the boot process. | ||
BOOT_LOCK.store(true, Ordering::SeqCst); | ||
log::error!("Boot Core is not implemented yet for x86_64"); | ||
|
||
let apic_id = crate::arch::apic::raw_apic_id(hart_id as _); | ||
let lapic = crate::arch::apic::local_apic(); | ||
|
||
// This is the | ||
const START_PAGE_IDX: u8 = 6; | ||
|
||
unsafe { | ||
lapic.send_init_ipi(apic_id); | ||
|
||
lapic.send_sipi(START_PAGE_IDX, apic_id); | ||
|
||
lapic.send_sipi(START_PAGE_IDX, apic_id); | ||
} | ||
} |
Oops, something went wrong.