From 6817874c0b6fc575c150dc5c0a103c30f853a0b6 Mon Sep 17 00:00:00 2001 From: Yukai Wu Date: Fri, 17 Jan 2025 21:16:34 +0800 Subject: [PATCH] parse MCFG table & dummy pcie module --- README.md | 2 ++ kernel/src/acpi.rs | 31 ++++++++++++++++++++++++++++++- kernel/src/lib.rs | 1 + kernel/src/main.rs | 3 ++- kernel/src/pcie/enumrate.rs | 0 kernel/src/pcie/mod.rs | 1 + 6 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 kernel/src/pcie/enumrate.rs create mode 100644 kernel/src/pcie/mod.rs diff --git a/README.md b/README.md index c0cc8cc..4f95e1f 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ # DoglinkOS-2nd 支持加载`GNU/MicroFish` + +已放弃BIOS启动支持,请用UEFI(毕竟虚拟机都能用UEFI了) diff --git a/kernel/src/acpi.rs b/kernel/src/acpi.rs index 745efec..3ece914 100644 --- a/kernel/src/acpi.rs +++ b/kernel/src/acpi.rs @@ -45,9 +45,28 @@ pub struct MADT { flags: u32, } +#[derive(Debug, Copy, Clone)] +#[repr(packed)] +pub struct PCIE_CFG_ALLOC { + base_addr: u64, + pci_segment_group_number: u16, + start_pci_bus_number: u8, + end_pci_bus_number: u8, + reserved: u32, +} + +#[derive(Debug)] +#[repr(packed)] +pub struct MCFG { + header: ACPI_table_header, + reserved: u64, + alloc: PCIE_CFG_ALLOC, +} + pub static mut rsdp: * const RSDP = 0 as * const RSDP; pub static mut xsdt: * const XSDT = 0 as * const XSDT; pub static mut madt: * const MADT = 0 as * const MADT; +pub static mut mcfg: * const MCFG = 0 as * const MCFG; pub fn init(res: &RsdpResponse) { unsafe { @@ -56,11 +75,15 @@ pub fn init(res: &RsdpResponse) { xsdt = phys_to_virt((*rsdp).xsdt_addr) as * const XSDT; // println!("{:?}", *xsdt); for i in 0..16 { + if (*xsdt).pointers[i] == 0 { + break; + } let head = phys_to_virt((*xsdt).pointers[i]) as * const ACPI_table_header; if (*head).signature == [65, 80, 73, 67] { // "APIC" madt = head as * const MADT; - break; // println!("{:?}", *madt); + } else if (*head).signature == [77, 67, 70, 71] { // "MCFG" + mcfg = head as * const MCFG; } } } @@ -91,3 +114,9 @@ pub fn parse_madt() -> u64 { } res } + +pub fn parse_mcfg() { + unsafe { + println!("{:#?}", (*mcfg).alloc); + } +} diff --git a/kernel/src/lib.rs b/kernel/src/lib.rs index 1ea94bf..4f22329 100644 --- a/kernel/src/lib.rs +++ b/kernel/src/lib.rs @@ -7,3 +7,4 @@ pub mod mm; pub mod apic; pub mod acpi; pub mod cpu; +pub mod pcie; diff --git a/kernel/src/main.rs b/kernel/src/main.rs index b64b41a..4e736a7 100644 --- a/kernel/src/main.rs +++ b/kernel/src/main.rs @@ -6,7 +6,7 @@ use DoglinkOS_2nd::console::{init as init_console, clear as clear_console, puts use DoglinkOS_2nd::int::{init as init_interrupt, register as register_interrupt_handler}; use DoglinkOS_2nd::mm::init as init_mm; use DoglinkOS_2nd::apic::{local::init as init_lapic, io::init as init_ioapic}; -use DoglinkOS_2nd::acpi::{init as init_acpi, parse_madt}; +use DoglinkOS_2nd::acpi::{init as init_acpi, parse_madt, parse_mcfg}; use DoglinkOS_2nd::cpu::show_cpu_info; use DoglinkOS_2nd::println; use limine::request::{FramebufferRequest, HhdmRequest, RsdpRequest, RequestsEndMarker, RequestsStartMarker}; @@ -58,6 +58,7 @@ extern "C" fn kmain() -> ! { let ioapic_phys_addr = parse_madt(); init_ioapic(ioapic_phys_addr); show_cpu_info(); + parse_mcfg(); hang(); } diff --git a/kernel/src/pcie/enumrate.rs b/kernel/src/pcie/enumrate.rs new file mode 100644 index 0000000..e69de29 diff --git a/kernel/src/pcie/mod.rs b/kernel/src/pcie/mod.rs new file mode 100644 index 0000000..e8bb32f --- /dev/null +++ b/kernel/src/pcie/mod.rs @@ -0,0 +1 @@ +pub mod enumrate;