Implement IOAPIC

This commit is contained in:
Mathieu Strypsteen 2024-08-17 14:58:32 +02:00
parent 1896464175
commit 8441821993
11 changed files with 77 additions and 109 deletions

108
kernel/Cargo.lock generated
View file

@ -19,16 +19,14 @@ checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0"
[[package]]
name = "bindgen"
version = "0.69.4"
version = "0.70.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a00dc851838a2120612785d195287475a3ac45514741da670b735818822129a0"
checksum = "e0127a1da21afb5adaae26910922c3f7afd3d329ba1a1b98a0884cab4907a251"
dependencies = [
"bitflags",
"cexpr",
"clang-sys",
"itertools",
"lazy_static",
"lazycell",
"log",
"prettyplease",
"proc-macro2",
@ -37,14 +35,13 @@ dependencies = [
"rustc-hash",
"shlex",
"syn",
"which",
]
[[package]]
name = "bitfield"
version = "0.15.0"
version = "0.16.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c821a6e124197eb56d907ccc2188eab1038fb919c914f47976e64dd8dbc855d1"
checksum = "d5acf59e2452f0c4b968b15ce4b9468f57b45f7733b919d68b19fcc39264bfb8"
[[package]]
name = "bitflags"
@ -96,16 +93,6 @@ version = "1.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0"
[[package]]
name = "errno"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba"
dependencies = [
"libc",
"windows-sys",
]
[[package]]
name = "funty"
version = "2.0.0"
@ -118,20 +105,11 @@ version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b"
[[package]]
name = "home"
version = "0.5.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5"
dependencies = [
"windows-sys",
]
[[package]]
name = "itertools"
version = "0.12.1"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569"
checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186"
dependencies = [
"either",
]
@ -156,29 +134,17 @@ dependencies = [
"log",
]
[[package]]
name = "lazy_static"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
[[package]]
name = "lazycell"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
[[package]]
name = "libc"
version = "0.2.155"
version = "0.2.156"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c"
checksum = "a5f43f184355eefb8d17fc948dbecf6c13be3c141f20d834ae842193a448c72a"
[[package]]
name = "libloading"
version = "0.8.4"
version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e310b3a6b5907f99202fcdb4960ff45b93735d7c7d96b760fcff8db2dc0e103d"
checksum = "4979f22fdb869068da03c9f7528f8297c6fd2606bc3a4affe42e6a823fdb8da4"
dependencies = [
"cfg-if",
"windows-targets",
@ -193,12 +159,6 @@ dependencies = [
"spinning_top",
]
[[package]]
name = "linux-raw-sys"
version = "0.4.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89"
[[package]]
name = "lock_api"
version = "0.4.12"
@ -237,12 +197,6 @@ dependencies = [
"minimal-lexical",
]
[[package]]
name = "once_cell"
version = "1.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92"
[[package]]
name = "prettyplease"
version = "0.2.20"
@ -279,9 +233,9 @@ checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09"
[[package]]
name = "regex"
version = "1.10.5"
version = "1.10.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b91213439dad192326a0d7c6ee3955910425f441d7038e0d6933b0aec5c4517f"
checksum = "4219d74c6b67a3654a9fbebc4b419e22126d13d2f3c4a07ee0cb61ff79a79619"
dependencies = [
"aho-corasick",
"memchr",
@ -312,19 +266,6 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
[[package]]
name = "rustix"
version = "0.38.34"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f"
dependencies = [
"bitflags",
"errno",
"libc",
"linux-raw-sys",
"windows-sys",
]
[[package]]
name = "scopeguard"
version = "1.2.0"
@ -357,9 +298,9 @@ dependencies = [
[[package]]
name = "syn"
version = "2.0.71"
version = "2.0.74"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b146dcf730474b4bcd16c311627b31ede9ab149045db4d6088b3becaea046462"
checksum = "1fceb41e3d546d0bd83421d3409b1460cc7444cd389341a4c880fe7a042cb3d7"
dependencies = [
"proc-macro2",
"quote",
@ -378,27 +319,6 @@ version = "1.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
[[package]]
name = "which"
version = "4.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "87ba24419a2078cd2b0f2ede2691b6c66d8e47836da3b6db8265ebad47afbfc7"
dependencies = [
"either",
"home",
"once_cell",
"rustix",
]
[[package]]
name = "windows-sys"
version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d"
dependencies = [
"windows-targets",
]
[[package]]
name = "windows-targets"
version = "0.52.6"

View file

@ -11,4 +11,4 @@ log = "0.4.22"
spin = "0.9.8"
[build-dependencies]
bindgen = "0.69.4"
bindgen = "0.70.0"

39
kernel/src/sys/ioapic.rs Normal file
View file

@ -0,0 +1,39 @@
use core::{
ptr::null_mut,
sync::atomic::{AtomicPtr, AtomicU32, Ordering},
};
use crate::cpu::paging::map_physical;
struct IOAPIC {
address: AtomicPtr<u32>,
start_gsi: AtomicU32,
end_gsi: AtomicU32,
}
const EMPTY_IOAPIC: IOAPIC = IOAPIC {
address: AtomicPtr::new(null_mut()),
start_gsi: AtomicU32::new(0),
end_gsi: AtomicU32::new(0),
};
const REGISTER_VERSION: u8 = 1;
static IOAPICS: [IOAPIC; 32] = [EMPTY_IOAPIC; 32];
fn read_register(apic_i: usize, reg_i: u8) -> u32 {
unsafe {
IOAPICS[apic_i].address.load(Ordering::Relaxed).write_volatile(reg_i as u32);
return IOAPICS[apic_i].address.load(Ordering::Relaxed).add(0x10).read_volatile();
}
}
pub fn setup_ioapic(i: u8, phys: u64, gsi_base: u32) {
let i = i as usize;
let address;
unsafe {
address = map_physical(phys, 0x14) as *mut u32;
}
IOAPICS[i].address.store(address, Ordering::Relaxed);
IOAPICS[i].start_gsi.store(gsi_base, Ordering::Relaxed);
let max_ints = (read_register(i, REGISTER_VERSION) >> 16) & 0xff;
IOAPICS[i].end_gsi.store(gsi_base + max_ints, Ordering::Relaxed);
}

View file

@ -3,7 +3,8 @@ use core::mem::size_of;
use crate::sys::acpica_osl::AE_OK;
use super::{
acpica::{acpi_madt_local_apic_override, acpi_subtable_header, acpi_table_header, acpi_table_madt, AcpiGetTable},
acpica::{acpi_madt_io_apic, acpi_madt_local_apic_override, acpi_subtable_header, acpi_table_header, acpi_table_madt, AcpiGetTable},
ioapic::setup_ioapic,
lapic::setup_lapic,
};
@ -27,6 +28,13 @@ pub fn parse_madt() {
subtable_header = &*(subtable_address as *const acpi_subtable_header);
}
match subtable_header.Type {
1 => {
let subtable;
unsafe {
subtable = &*(subtable_address as *const acpi_madt_io_apic);
}
setup_ioapic(subtable.Id, subtable.Address as u64, subtable.GlobalIrqBase);
}
5 => {
let subtable;
unsafe {

View file

@ -1,5 +1,6 @@
pub mod acpica;
pub mod acpica_osl;
mod ioapic;
mod lapic;
pub mod madt;
pub mod pic;

@ -1 +1 @@
Subproject commit a8b050df914875839b717a51e1b32d6c6b86ae96
Subproject commit 1d9c129746c737b68e642f9f29a894e2700fbf46

View file

@ -4,9 +4,9 @@ version = 3
[[package]]
name = "bitfield"
version = "0.15.0"
version = "0.16.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c821a6e124197eb56d907ccc2188eab1038fb919c914f47976e64dd8dbc855d1"
checksum = "d5acf59e2452f0c4b968b15ce4b9468f57b45f7733b919d68b19fcc39264bfb8"
[[package]]
name = "kernel-common"

View file

@ -4,5 +4,5 @@ version = "0.0.1"
edition = "2021"
[dependencies]
bitfield = "0.15.0"
bitfield = "0.16.1"
log = "0.4.22"

14
loader/Cargo.lock generated
View file

@ -16,9 +16,9 @@ checksum = "dc827186963e592360843fb5ba4b973e145841266c1357f7180c43526f2e5b61"
[[package]]
name = "bitfield"
version = "0.15.0"
version = "0.16.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c821a6e124197eb56d907ccc2188eab1038fb919c914f47976e64dd8dbc855d1"
checksum = "d5acf59e2452f0c4b968b15ce4b9468f57b45f7733b919d68b19fcc39264bfb8"
[[package]]
name = "bitflags"
@ -123,9 +123,9 @@ dependencies = [
[[package]]
name = "syn"
version = "2.0.71"
version = "2.0.74"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b146dcf730474b4bcd16c311627b31ede9ab149045db4d6088b3becaea046462"
checksum = "1fceb41e3d546d0bd83421d3409b1460cc7444cd389341a4c880fe7a042cb3d7"
dependencies = [
"proc-macro2",
"quote",
@ -143,9 +143,9 @@ dependencies = [
[[package]]
name = "uefi"
version = "0.29.0"
version = "0.30.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3e8fb42b46b5e5afaa49a237714d3259ccbf740ba68cbf25d715471b15cabe04"
checksum = "c937815260747b061aaa63a0f721d350a5740b72f166c5a4180226aa6fa204b9"
dependencies = [
"bitflags",
"cfg-if",
@ -165,7 +165,7 @@ checksum = "4f345e42323c05e41e29e409505f5f8e0df7b5743340215d60344dbd79b729f4"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.71",
"syn 2.0.74",
]
[[package]]

View file

@ -8,4 +8,4 @@ elf = {version = "0.7.4", default-features = false}
kernel-common = {path = "../lib/kernel-common"}
log = "0.4.22"
static-alloc = "0.2.5"
uefi = "0.29.0"
uefi = "0.30.0"

View file

@ -2,4 +2,4 @@
# shellcheck disable=SC2068
set -e
./build.sh
qemu-system-x86_64 -M q35 -cpu qemu64,+rdrand -m 256M -L /usr/share/OVMF -bios OVMF_CODE.fd -drive file=img/os.img,format=raw $@
qemu-system-x86_64 -M q35 -accel kvm -cpu qemu64,+rdrand -m 256M -L /usr/share/OVMF -bios OVMF_CODE.fd -drive file=img/os.img,format=raw $@