Skip to content

Commit

Permalink
parse MCFG table & dummy pcie module
Browse files Browse the repository at this point in the history
  • Loading branch information
wuyukai0403 committed Jan 17, 2025
1 parent d963800 commit 6817874
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# DoglinkOS-2nd

支持加载`GNU/MicroFish`

已放弃BIOS启动支持,请用UEFI(毕竟虚拟机都能用UEFI了)
31 changes: 30 additions & 1 deletion kernel/src/acpi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
}
}
}
Expand Down Expand Up @@ -91,3 +114,9 @@ pub fn parse_madt() -> u64 {
}
res
}

pub fn parse_mcfg() {
unsafe {
println!("{:#?}", (*mcfg).alloc);
}
}
1 change: 1 addition & 0 deletions kernel/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ pub mod mm;
pub mod apic;
pub mod acpi;
pub mod cpu;
pub mod pcie;
3 changes: 2 additions & 1 deletion kernel/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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();
}

Expand Down
Empty file added kernel/src/pcie/enumrate.rs
Empty file.
1 change: 1 addition & 0 deletions kernel/src/pcie/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod enumrate;

0 comments on commit 6817874

Please sign in to comment.