Add ACPICA

This commit is contained in:
Mathieu Strypsteen 2024-07-09 08:05:07 +02:00
parent e60249c5da
commit 0323428974
13 changed files with 540 additions and 0 deletions

2
.gitignore vendored
View file

@ -1,2 +1,4 @@
kernel/src/sys/acpica-bindings.rs
lib/acpica-build/libacpica.a
img
target

3
.gitmodules vendored Normal file
View file

@ -0,0 +1,3 @@
[submodule "lib/acpica"]
path = lib/acpica
url = https://github.com/acpica/acpica

View file

@ -2,6 +2,7 @@
set -e
rm -rf img
mkdir -p img/boot/efi/boot
cd lib/acpica-build && make -j4 && cd ../..
cd kernel && cargo build --release && cd ..
cd loader && cargo build --release && cd ..
cp loader/target/x86_64-unknown-uefi/release/loader.efi img/boot/efi/boot/bootx64.efi

351
kernel/Cargo.lock generated
View file

@ -2,18 +2,56 @@
# It is not intended for manual editing.
version = 3
[[package]]
name = "aho-corasick"
version = "1.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916"
dependencies = [
"memchr",
]
[[package]]
name = "autocfg"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0"
[[package]]
name = "bindgen"
version = "0.69.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a00dc851838a2120612785d195287475a3ac45514741da670b735818822129a0"
dependencies = [
"bitflags",
"cexpr",
"clang-sys",
"itertools",
"lazy_static",
"lazycell",
"log",
"prettyplease",
"proc-macro2",
"quote",
"regex",
"rustc-hash",
"shlex",
"syn",
"which",
]
[[package]]
name = "bitfield"
version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c821a6e124197eb56d907ccc2188eab1038fb919c914f47976e64dd8dbc855d1"
[[package]]
name = "bitflags"
version = "2.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de"
[[package]]
name = "bitvec"
version = "1.0.1"
@ -26,16 +64,83 @@ dependencies = [
"wyz",
]
[[package]]
name = "cexpr"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766"
dependencies = [
"nom",
]
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "clang-sys"
version = "1.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b023947811758c97c59bf9d1c188fd619ad4718dcaa767947df1cadb14f39f4"
dependencies = [
"glob",
"libc",
"libloading",
]
[[package]]
name = "either"
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"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c"
[[package]]
name = "glob"
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"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569"
dependencies = [
"either",
]
[[package]]
name = "kernel"
version = "0.0.1"
dependencies = [
"bindgen",
"bitvec",
"kernel-common",
"linked_list_allocator",
@ -51,6 +156,34 @@ 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"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c"
[[package]]
name = "libloading"
version = "0.8.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e310b3a6b5907f99202fcdb4960ff45b93735d7c7d96b760fcff8db2dc0e103d"
dependencies = [
"cfg-if",
"windows-targets",
]
[[package]]
name = "linked_list_allocator"
version = "0.10.5"
@ -60,6 +193,12 @@ 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"
@ -76,18 +215,128 @@ version = "0.4.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24"
[[package]]
name = "memchr"
version = "2.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
[[package]]
name = "minimal-lexical"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
[[package]]
name = "nom"
version = "7.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a"
dependencies = [
"memchr",
"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"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5f12335488a2f3b0a83b14edad48dca9879ce89b2edd10e80237e4e852dd645e"
dependencies = [
"proc-macro2",
"syn",
]
[[package]]
name = "proc-macro2"
version = "1.0.86"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.36"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7"
dependencies = [
"proc-macro2",
]
[[package]]
name = "radium"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09"
[[package]]
name = "regex"
version = "1.10.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b91213439dad192326a0d7c6ee3955910425f441d7038e0d6933b0aec5c4517f"
dependencies = [
"aho-corasick",
"memchr",
"regex-automata",
"regex-syntax",
]
[[package]]
name = "regex-automata"
version = "0.4.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df"
dependencies = [
"aho-corasick",
"memchr",
"regex-syntax",
]
[[package]]
name = "regex-syntax"
version = "0.8.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b"
[[package]]
name = "rustc-hash"
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"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
[[package]]
name = "shlex"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
[[package]]
name = "spin"
version = "0.9.8"
@ -106,12 +355,114 @@ dependencies = [
"lock_api",
]
[[package]]
name = "syn"
version = "2.0.70"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2f0209b68b3613b093e0ec905354eccaedcfe83b8cb37cbdeae64026c3064c16"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "tap"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369"
[[package]]
name = "unicode-ident"
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"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973"
dependencies = [
"windows_aarch64_gnullvm",
"windows_aarch64_msvc",
"windows_i686_gnu",
"windows_i686_gnullvm",
"windows_i686_msvc",
"windows_x86_64_gnu",
"windows_x86_64_gnullvm",
"windows_x86_64_msvc",
]
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3"
[[package]]
name = "windows_aarch64_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469"
[[package]]
name = "windows_i686_gnu"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b"
[[package]]
name = "windows_i686_gnullvm"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66"
[[package]]
name = "windows_i686_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66"
[[package]]
name = "windows_x86_64_gnu"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d"
[[package]]
name = "windows_x86_64_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
[[package]]
name = "wyz"
version = "0.5.1"

View file

@ -9,3 +9,6 @@ kernel-common = {path = "../lib/kernel-common"}
linked_list_allocator = "0.10.5"
log = "0.4.22"
spin = "0.9.8"
[build-dependencies]
bindgen = "0.69.4"

14
kernel/build.rs Normal file
View file

@ -0,0 +1,14 @@
use bindgen::Builder;
fn main() {
println!("cargo::rustc-link-search=../lib/acpica-build");
println!("cargo::rustc-link-lib=acpica");
let bindings = Builder::default()
.use_core()
.clang_arg("-I../lib/acpica-build")
.header("../lib/acpica-build/acpica.h")
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
.generate()
.unwrap();
bindings.write_to_file("src/sys/acpica-bindings.rs").unwrap();
}

2
kernel/src/sys/acpica.rs Normal file
View file

@ -0,0 +1,2 @@
#![allow(warnings)]
include!("acpica-bindings.rs");

View file

@ -0,0 +1,140 @@
#[no_mangle]
extern "C" fn AcpiOsAcquireLock() {
panic!("Unimplemented");
}
#[no_mangle]
extern "C" fn AcpiOsAllocate() {
panic!("Unimplemented");
}
#[no_mangle]
extern "C" fn AcpiOsCreateLock() {
panic!("Unimplemented");
}
#[no_mangle]
extern "C" fn AcpiOsCreateSemaphore() {
panic!("Unimplemented");
}
#[no_mangle]
extern "C" fn AcpiOsDeleteLock() {
panic!("Unimplemented");
}
#[no_mangle]
extern "C" fn AcpiOsDeleteSemaphore() {
panic!("Unimplemented");
}
#[no_mangle]
extern "C" fn AcpiOsExecute() {
panic!("Unimplemented");
}
#[no_mangle]
extern "C" fn AcpiOsFree() {
panic!("Unimplemented");
}
#[no_mangle]
extern "C" fn AcpiOsGetRootPointer() {
panic!("Unimplemented");
}
#[no_mangle]
extern "C" fn AcpiOsGetThreadId() {
panic!("Unimplemented");
}
#[no_mangle]
extern "C" fn AcpiOsGetTimer() {
panic!("Unimplemented");
}
#[no_mangle]
extern "C" fn AcpiOsInitialize() {
panic!("Unimplemented");
}
#[no_mangle]
extern "C" fn AcpiOsInstallInterruptHandler() {
panic!("Unimplemented");
}
#[no_mangle]
extern "C" fn AcpiOsMapMemory() {
panic!("Unimplemented");
}
#[no_mangle]
extern "C" fn AcpiOsPhysicalTableOverride() {
panic!("Unimplemented");
}
#[no_mangle]
extern "C" fn AcpiOsPredefinedOverride() {
panic!("Unimplemented");
}
#[no_mangle]
extern "C" fn AcpiOsPrintf() {
panic!("Unimplemented");
}
#[no_mangle]
extern "C" fn AcpiOsReadMemory() {
panic!("Unimplemented");
}
#[no_mangle]
extern "C" fn AcpiOsReadPciConfiguration() {
panic!("Unimplemented");
}
#[no_mangle]
extern "C" fn AcpiOsReadPort() {
panic!("Unimplemented");
}
#[no_mangle]
extern "C" fn AcpiOsReleaseLock() {
panic!("Unimplemented");
}
#[no_mangle]
extern "C" fn AcpiOsStall() {
panic!("Unimplemented");
}
#[no_mangle]
extern "C" fn AcpiOsRemoveInterruptHandler() {
panic!("Unimplemented");
}
#[no_mangle]
extern "C" fn AcpiOsSignal() {
panic!("Unimplemented");
}
#[no_mangle]
extern "C" fn AcpiOsSignalSemaphore() {
panic!("Unimplemented");
}
#[no_mangle]
extern "C" fn AcpiOsSleep() {
panic!("Unimplemented");
}
#[no_mangle]
extern "C" fn AcpiOsTableOverride() {
panic!("Unimplemented");
}
#[no_mangle]
extern "C" fn AcpiOsTerminate() {
panic!("Unimplemented");
}
#[no_mangle]
extern "C" fn AcpiOsUnmapMemory() {
panic!("Unimplemented");
}
#[no_mangle]
extern "C" fn AcpiOsVprintf() {
panic!("Unimplemented");
}
#[no_mangle]
extern "C" fn AcpiOsWaitEventsComplete() {
panic!("Unimplemented");
}
#[no_mangle]
extern "C" fn AcpiOsWaitSemaphore() {
panic!("Unimplemented");
}
#[no_mangle]
extern "C" fn AcpiOsWriteMemory() {
panic!("Unimplemented");
}
#[no_mangle]
extern "C" fn AcpiOsWritePciConfiguration() {
panic!("Unimplemented");
}
#[no_mangle]
extern "C" fn AcpiOsWritePort() {
panic!("Unimplemented");
}

View file

@ -1 +1,3 @@
pub mod acpica;
mod acpica_osl;
pub mod pic;

1
lib/acpica Submodule

@ -0,0 +1 @@
Subproject commit a8b050df914875839b717a51e1b32d6c6b86ae96

11
lib/acpica-build/Makefile Normal file
View file

@ -0,0 +1,11 @@
EXEC_PRE:=$(shell rm -f ../acpica/source/include/platform/aclinux.h)
COMPONENTS:=dispatcher events executer hardware namespace parser resources tables utilities
CFILES:=$(foreach comp, $(COMPONENTS), $(wildcard ../acpica/source/components/$(comp)/*.c))
OFILES:=$(patsubst %.c, %.o, $(CFILES))
CC:=clang
CFLAGS:=--target=x86_64-elf -ffreestanding -mcmodel=kernel -mno-red-zone -mno-mmx -mno-sse -mno-sse2 -O2 -I. -I../acpica/source/include -DACPI_LIBRARY -D__linux__
libacpica.a: $(OFILES)
llvm-ar rcD $@ $^
clean:
find ../acpica -name '*.o' -delete

View file

@ -0,0 +1,7 @@
#pragma once
#include <stdint.h>
#define ACPI_MACHINE_WIDTH 64
#define ACPI_UINTPTR_T uintptr_t
#undef ACPI_DEBUGGER
#undef ACPI_DISASSEMBLER
#define ACPI_DEBUG_OUTPUT 1

View file

@ -0,0 +1,3 @@
#pragma once
#define __linux__
#include "../acpica/source/include/acpi.h"