diff --git a/Cargo.lock b/Cargo.lock index bd6e914..536cb6f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11,20 +11,6 @@ dependencies = [ "sptr", ] -[[package]] -name = "acpi" -version = "6.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c85d96f36022f650ee6f184f1353d077124754cecf6a3e91085a708495c6f5a" -dependencies = [ - "bit_field", - "bitflags", - "byteorder", - "log", - "pci_types", - "spinning_top", -] - [[package]] name = "align-address" version = "0.3.0" @@ -49,36 +35,6 @@ version = "2.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "812e12b5285cc515a9c72a5c1d3b6d46a19dac5acfef5265968c166106e31dd3" -[[package]] -name = "build_const" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4ae4235e6dac0694637c763029ecea1a2ec9e4e06ec2729bd21ba4d9c863eb7" - -[[package]] -name = "byteorder" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" - -[[package]] -name = "core2" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "239fa3ae9b63c2dc74bd3fa852d4792b8b305ae64eeede946265b6af62f1fff3" -dependencies = [ - "memchr", -] - -[[package]] -name = "crc" -version = "1.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d663548de7f5cca343f1e0a48d14dcfb0e9eb4e079ec58883b7251539fa10aeb" -dependencies = [ - "build_const", -] - [[package]] name = "critical-section" version = "1.2.0" @@ -105,11 +61,6 @@ dependencies = [ "syn", ] -[[package]] -name = "fdt" -version = "0.2.0-alpha1" -source = "git+https://github.com/repnop/fdt#059bb2383873f8001959456e36ec123228f67642" - [[package]] name = "flagset" version = "0.4.7" @@ -128,35 +79,32 @@ dependencies = [ ] [[package]] -name = "gila" +name = "intbits" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5170c2c8ecda29c1bccb9d95ccbe107bc75fa084dc0c9c6087e719f9d46330e5" + +[[package]] +name = "kernel" version = "0.3.1" dependencies = [ "acid_alloc", - "acpi", "enumflags2", - "fdt", "flagset", "free-list", "intbits", "lazy_static", + "libgila", "limine", - "lzma-rs", "num-derive", "num-traits", "once_cell", "raw-cpuid", "spin 0.10.0", "talc", - "tar-no-std", "x86_64", ] -[[package]] -name = "intbits" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5170c2c8ecda29c1bccb9d95ccbe107bc75fa084dc0c9c6087e719f9d46330e5" - [[package]] name = "lazy_static" version = "1.5.0" @@ -166,6 +114,14 @@ dependencies = [ "spin 0.9.8", ] +[[package]] +name = "libgila" +version = "0.1.0" +dependencies = [ + "num-derive", + "num-traits", +] + [[package]] name = "limine" version = "0.5.0" @@ -184,28 +140,6 @@ dependencies = [ "scopeguard", ] -[[package]] -name = "log" -version = "0.4.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34080505efa8e45a4b816c349525ebe327ceaa8559756f0356cba97ef3bf7432" - -[[package]] -name = "lzma-rs" -version = "0.2.0" -source = "git+https://github.com/glaeqen/lzma-no-std-rs/#5635feaf5923f54161e9582dddb80cd457c07223" -dependencies = [ - "byteorder", - "core2", - "crc", -] - -[[package]] -name = "memchr" -version = "2.7.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273" - [[package]] name = "num-derive" version = "0.4.2" @@ -236,16 +170,6 @@ dependencies = [ "portable-atomic", ] -[[package]] -name = "pci_types" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4325c6aa3cca3373503b1527e75756f9fbfe5fd76be4b4c8a143ee47430b8e0" -dependencies = [ - "bit_field", - "bitflags", -] - [[package]] name = "portable-atomic" version = "1.11.1" @@ -263,9 +187,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.41" +version = "1.0.42" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce25767e7b499d1b604768e7cde645d14cc8584231ea6b295e9c9eb22c02e1d1" +checksum = "a338cc41d27e6cc6dce6cefc13a0729dfbb81c262b1f519331575dd80ef3067f" dependencies = [ "proc-macro2", ] @@ -312,15 +236,6 @@ dependencies = [ "lock_api", ] -[[package]] -name = "spinning_top" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d96d2d1d716fb500937168cc09353ffdc7a012be8475ac7308e1bdf0e3923300" -dependencies = [ - "lock_api", -] - [[package]] name = "sptr" version = "0.2.3" @@ -329,9 +244,9 @@ checksum = "5cdeee85371b1ec1f4b305c91787271a39f56b66e673bdbd73b7742150de5b0e" [[package]] name = "syn" -version = "2.0.109" +version = "2.0.110" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f17c7e013e88258aa9543dcbe81aca68a667a9ac37cd69c9fbc07858bfe0e2f" +checksum = "a99801b5bd34ede4cf3fc688c5919368fea4e4814a4664359503e6015b280aea" dependencies = [ "proc-macro2", "quote", @@ -347,17 +262,6 @@ dependencies = [ "lock_api", ] -[[package]] -name = "tar-no-std" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "715f9a4586706a61c571cb5ee1c3ac2bbb2cf63e15bce772307b95befef5f5ee" -dependencies = [ - "bitflags", - "log", - "num-traits", -] - [[package]] name = "unicode-ident" version = "1.0.22" diff --git a/Cargo.toml b/Cargo.toml index 1389d92..b214f7b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,47 +1,3 @@ -[package] -name = "gila" -version = "0.3.1" -edition = "2024" -license = "MIT" - -[dependencies] -acid_alloc = { version = "0.1.0", features = ["alloc"] } -enumflags2 = "0.7.12" -flagset = "0.4.7" -free-list = { version = "0.3.1", features = ["x86_64"] } -intbits = "0.2.0" -lazy_static = { version = "1.5.0", default-features = false, features = ["spin_no_std"] } -limine = "0.5.0" -num-derive = "0.4.2" -num-traits = { version = "0.2.19", default-features = false } -once_cell = { version = "1.21.3", default-features = false, features = ["alloc", "critical-section"] } -spin = "0.10.0" -talc = "4.4.3" -# Optional Dependencies for Features -tar-no-std = "0.4.2" -fdt = { git = "https://github.com/repnop/fdt", version = "0.2.0-alpha1", optional = true } -acpi = { version = "6.0.1", optional = true } -lzma-rs = { git = "https://github.com/glaeqen/lzma-no-std-rs/", version = "0.2.0", default-features = false, optional = true } - -[target.'cfg(target_arch = "x86_64")'.dependencies] -x86_64 = "0.15.2" -raw-cpuid = "11.6.0" - -[lib] -name = "gila" -path = "src/lib/lib.rs" - -[[bin]] -name = "kernel" -path = "src/kernel/main.rs" -test = false -doctest = false -bench = false - -[features] -default = ["acpi", "dtb", "uefi", "compression"] -acpi = ["dep:acpi"] # Support ACPI -dtb = ["dep:fdt"] # Support device tree blobs -uefi = [] # Enable UEFI dependent features -compression = ["dep:lzma-rs"] # Enable compressed initramfs - +[workspace] +resolver = "3" +members = ["kernel", "libgila"] diff --git a/Makefile.toml b/Makefile.toml index 127f6ed..553521b 100644 --- a/Makefile.toml +++ b/Makefile.toml @@ -1,3 +1,4 @@ + env_scripts = [ ''' #!@duckscript @@ -21,6 +22,9 @@ env_scripts = [ ''' ] +[config] +default_to_workspace = false + [env] # Directory for Limine binaries LIMINEDIR = "/usr/share/limine" @@ -75,20 +79,20 @@ command = "rm" args = ["-rf", "build/initramfs", "build/initramfs.tar.lzma"] [tasks.lib] -condition = { files_modified = { input = ["src/lib/**/*.rs"], output = ["${ARTIFACTDIR}/libgila.rlib"] }, fail_message = "(inputs unchanged)" } +condition = { files_modified = { input = ["libgila/src/**/*.rs"], output = ["${ARTIFACTDIR}/libgila.rlib"] }, fail_message = "(inputs unchanged)" } dependencies = [] command = "cargo" -args = ["build", "--profile", "${PROFILE}", "--lib"] +args = ["build", "--profile", "${PROFILE}", "-p", "libgila"] [tasks.kernel] condition = { files_modified = { input = [ - "src/kernel/**/*.rs", - "src/kernel/**/*.ld", + "kernel/src/**/*.rs", + "kernel/src/**/*.ld", "${ARTIFACTDIR}/libgila.rlib" ], output = ["${ARTIFACTDIR}/kernel"] }, fail_message = "(inputs unchanged)" } dependencies = ["lib"] command = "cargo" -args = ["build", "--profile", "${PROFILE}", "--bin", "kernel"] +args = ["build", "--profile", "${PROFILE}", "-p", "kernel"] [tasks.bins] dependencies = [] diff --git a/README.md b/README.md index ba10c71..36c0d43 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ![An illustrated Gila monster, and the text "Gila: A Minimal Rust Microkernel", superimposed over some serial log output.](gila_banner.png) -Gila is a Rust microkernel OS, inspired by microkernel projects such as seL4 and Redox. I aim to implement multitasking, userspace drivers, IPC, and sandboxing. I do not aim to make it POSIX-compatible, but it will likely end up sharing many features with POSIX operating systems. Its design philosophy is focused around simplicity, isolation, modularity, and minimal privilege. +Gila is a Rust microkernel OS, inspired by microkernel projects such as seL4, Zircon, and Redox. I aim to implement multitasking, userspace drivers, IPC, and sandboxing. I do not aim to make it POSIX-compatible, but it will likely end up sharing many features with POSIX operating systems. Its design philosophy is focused around simplicity, isolation, modularity, and minimal privilege. ## Development @@ -25,10 +25,7 @@ Information on the build system, repo structure, features, configuration options - Display console - Serial console -- Device discovery & APIs -- Power management - Paging -- initramfs decompression & manifest parsing ### Future/Desired diff --git a/docs/DESIGN.md b/docs/DESIGN.md index 9763c77..1f63f4f 100644 --- a/docs/DESIGN.md +++ b/docs/DESIGN.md @@ -9,20 +9,14 @@ similar to (if not compatible with) D-Bus. ## Boot Process Gila initializes as a bare kernel, with the bootloader providing an init RAM -filesystem in the form of a .tar.lzma archive. The kernel reads this file, and -launches an init process (`/system/bin/init`). The init process has its own -configuration file located at `/system/cfg/init.toml`, which should detail the -steps needed to bring the system up to a multi-user status. This config file -will also contain versioning information for compatibility, detailing which -kernel version and architecture it is compatible with. +filesystem in the form of a .tar.lzma archive. -If the init system needs to access a filesystem, it must first get the handle -of the filesystem server. If the filesystem server is not running when this -handle request is made, the kernel will launch the server before returning its -handle. From there, the filesystem server will request the handle of the disk -driver that corresponds to the requested filesystem. The kernel then launches -the disk driver server, and assigns it a seat based on the device it drives, -granting it access to the memory region responsible for that device. +To avoid having to implement things like LZMA, TAR, and ELF parsing into the +kernel proper, Gila will use a compiled-in stub program as its first process. +This process will perform the necessary functionality to scan the initramfs, +read config files, load executables into memory, and start processes. This is +inspired by the Zircon microkernel's userboot setup. This userboot binary is +responsible for starting the proper init system. The benefit of this approach is threefold: diff --git a/docs/DEVELOPMENT.MD b/docs/DEVELOPMENT.MD index f019d2d..efe6d65 100644 --- a/docs/DEVELOPMENT.MD +++ b/docs/DEVELOPMENT.MD @@ -7,44 +7,44 @@ design details can be found in [SECURITY.md](SECURITY.md). ## Navigating -- [kernel/](../src/kernel/): Kernel-specific code. - - [arch/](../src/kernel/arch/): Architecture specific features like the +- [kernel/src/](../kernel/src/): Kernel-specific code. + - [arch/](../kernel/src/arch/): Architecture specific features like the display, serial, and interrupts. Each architecture is a subfolder, containing a file or module for each feature. - - [boot/](../src/kernel/boot/mod.rs): Handles bootloader-managed data + - [boot/](../kernel/src/boot/mod.rs): Handles bootloader-managed data structures. Gila uses Limine. Other bootloaders are NOT supported. - - [params.rs](../src/kernel/boot/params.rs): Command line parameter parsing. - - [modules.rs](../src/kernel/boot/modules.rs): Kernel module handling. - - [constants.rs](../src/kernel/constants.rs): Constants referenced elsewhere + - [params.rs](../kernel/src/boot/params.rs): Command line parameter parsing. + - [modules.rs](../kernel/src/boot/modules.rs): Kernel module handling. + - [constants.rs](../kernel/src/constants.rs): Constants referenced elsewhere in the kernel. - - [device/](../src/kernel/device/mod.rs): Functions for discovering hardware + - [device/](../kernel/src/device/mod.rs): Functions for discovering hardware and assigning drivers. - - [acpi.rs](../src/kernel/device/acpi.rs): ACPI handling functions and + - [acpi.rs](../kernel/src/device/acpi.rs): ACPI handling functions and structures. - - [log.rs](../src/kernel/log.rs): Logging structures, macros, and singletons + - [log.rs](../kernel/src/log.rs): Logging structures, macros, and singletons for logging to serial or the display. - - [interrupt/](../src/kernel/interrupt/mod.rs): Interrupt handlers with + - [interrupt/](../kernel/src/interrupt/mod.rs): Interrupt handlers with platform-agnostic APIs. - - [main.rs](../src/kernel/main.rs): The entry point that gets called by the + - [main.rs](../kernel/src/main.rs): The entry point that gets called by the bootloader. - - [memory.rs](../src/kernel/memory.rs): Types relating to memory regions and + - [memory.rs](../kernel/src/memory.rs): Types relating to memory regions and allocation. - - [panic.rs](../src/kernel/panic.rs): The panic handler and associated + - [panic.rs](../kernel/src/panic.rs): The panic handler and associated functionality. - - [process.rs](../src/kernel/process.rs): Process types and functions. - - [syscall\_runner.rs](../src/kernel/syscall_runner.rs): Chooses a system call + - [process.rs](../kernel/src/process.rs): Process types and functions. + - [syscall\_runner.rs](../kernel/src/syscall_runner.rs): Chooses a system call by its ID and defers actual syscall execution to code in `src/lib/`. -- [lib/](../src/lib/lib.rs): Library that all Gila's binary programs will be +- [libgila/src/](../libgila/src/lib.rs): Library that all Gila's binary programs will be built against. Some of this code is shared with the kernel. - - [arch/](../src/lib/arch/mod.rs): Architecture specific functionality like + - [arch/](../libgila/src/arch/mod.rs): Architecture specific functionality like system call register storing/loading. - - [syscall.rs](../src/lib/syscall.rs): System call types common to apps and + - [syscall.rs](../libgila/src/syscall.rs): System call types common to apps and the kernel. ## Building and running Building a bootable kernel is easy. All you need to do is run -`cargo build --bin kernel`, and a valid, bootable Limine executable will be +`cargo build -p kernel`, and a valid, bootable Limine executable will be generated. However, it cannot be booted without installing it in a bootable Limine filesystem, and it cannot do anything useful without an initramfs containing system servers, such as the init server and device drivers. @@ -88,20 +88,6 @@ and `iso` tasks will automatically be rerun if their input files change. > The `-p {profile}` argument must go between `cargo make` and the task argument. -### Features - -Gila has four optional features, which I made optional in anticipation of a -potential future port to older systems which might not support modern -standards like UEFI or ACPI. They are all enabled by default. Disabling them -reduces kernel size and forces the kernel to fall back to other -implementations for some functionality like device discovery. - -- `acpi`: Advanced Configuration and Power Interface, for device discovery & -power management -- `dtb`: Device Tree Blob, for device discovery in embedded systems -- `compression`: Compressed initramfs archive -- `uefi`: Universal Extensible Firmware Interface specific bootloader features - ### Targets Gila ~~currently supports~~ aims to support four different CPU architectures: diff --git a/docs/SECURITY.md b/docs/SECURITY.md index 9c02838..a7e33b7 100644 --- a/docs/SECURITY.md +++ b/docs/SECURITY.md @@ -95,6 +95,13 @@ namespace, such as IPC and shared memory. ### Capability based MAC +Gila has no concept of ambient authority. Resource access is not governed +based on any inherent privilege level of the accessing process- rather, +processes must possess capabilities specific to that resource. A process +cannot defer a resource access to a process which already has the capability, +it must *copy* or *transfer* its own capability to that resource, to the +process which will access it. + Namespaces will be enforced using capabilities, where a process holds a capability object representing the namespace it is in, and the rights it has within that namespace. By default, processes have no such capabilities, but diff --git a/kernel/Cargo.toml b/kernel/Cargo.toml new file mode 100644 index 0000000..467348c --- /dev/null +++ b/kernel/Cargo.toml @@ -0,0 +1,32 @@ +[package] +name = "kernel" +version = "0.3.1" +edition = "2024" +license = "MIT" + +[dependencies] +acid_alloc = { version = "0.1.0", features = ["alloc"] } +enumflags2 = "0.7.12" +flagset = "0.4.7" +free-list = { version = "0.3.1", features = ["x86_64"] } +intbits = "0.2.0" +lazy_static = { version = "1.5.0", default-features = false, features = ["spin_no_std"] } +limine = "0.5.0" +num-derive = "0.4.2" +num-traits = { version = "0.2.19", default-features = false } +once_cell = { version = "1.21.3", default-features = false, features = ["alloc", "critical-section"] } +spin = "0.10.0" +talc = "4.4.3" + +libgila = { path = "../libgila" } + +[target.'cfg(target_arch = "x86_64")'.dependencies] +x86_64 = "0.15.2" +raw-cpuid = "11.6.0" + +[[bin]] +name = "kernel" +path = "src/main.rs" +test = false +doctest = false +bench = false diff --git a/build.rs b/kernel/build.rs similarity index 60% rename from build.rs rename to kernel/build.rs index e570aaa..758c2a2 100644 --- a/build.rs +++ b/kernel/build.rs @@ -1,7 +1,7 @@ fn main() { let arch = std::env::var("CARGO_CFG_TARGET_ARCH").unwrap(); // Tell cargo to pass the linker script to the linker.. - println!("cargo:rustc-link-arg=-Tsrc/kernel/arch/{arch}/linker.ld"); + println!("cargo:rustc-link-arg=-Tkernel/src/arch/{arch}/linker.ld"); // ..and to re-run if it changes. - println!("cargo:rerun-if-changed=src/kernel/arch/{arch}linker.ld"); + println!("cargo:rerun-if-changed=kernel/src/arch/{arch}linker.ld"); } diff --git a/src/kernel/arch/aarch64/asm.rs b/kernel/src/arch/aarch64/asm.rs similarity index 100% rename from src/kernel/arch/aarch64/asm.rs rename to kernel/src/arch/aarch64/asm.rs diff --git a/src/kernel/arch/aarch64/linker.ld b/kernel/src/arch/aarch64/linker.ld similarity index 100% rename from src/kernel/arch/aarch64/linker.ld rename to kernel/src/arch/aarch64/linker.ld diff --git a/src/kernel/arch/aarch64/mod.rs b/kernel/src/arch/aarch64/mod.rs similarity index 100% rename from src/kernel/arch/aarch64/mod.rs rename to kernel/src/arch/aarch64/mod.rs diff --git a/src/kernel/arch/loongarch64/asm.rs b/kernel/src/arch/loongarch64/asm.rs similarity index 100% rename from src/kernel/arch/loongarch64/asm.rs rename to kernel/src/arch/loongarch64/asm.rs diff --git a/src/kernel/arch/loongarch64/linker.ld b/kernel/src/arch/loongarch64/linker.ld similarity index 100% rename from src/kernel/arch/loongarch64/linker.ld rename to kernel/src/arch/loongarch64/linker.ld diff --git a/src/kernel/arch/loongarch64/mod.rs b/kernel/src/arch/loongarch64/mod.rs similarity index 100% rename from src/kernel/arch/loongarch64/mod.rs rename to kernel/src/arch/loongarch64/mod.rs diff --git a/src/kernel/arch/mod.rs b/kernel/src/arch/mod.rs similarity index 100% rename from src/kernel/arch/mod.rs rename to kernel/src/arch/mod.rs diff --git a/src/kernel/arch/riscv64/asm.rs b/kernel/src/arch/riscv64/asm.rs similarity index 100% rename from src/kernel/arch/riscv64/asm.rs rename to kernel/src/arch/riscv64/asm.rs diff --git a/src/kernel/arch/riscv64/linker.ld b/kernel/src/arch/riscv64/linker.ld similarity index 100% rename from src/kernel/arch/riscv64/linker.ld rename to kernel/src/arch/riscv64/linker.ld diff --git a/src/kernel/arch/riscv64/mod.rs b/kernel/src/arch/riscv64/mod.rs similarity index 100% rename from src/kernel/arch/riscv64/mod.rs rename to kernel/src/arch/riscv64/mod.rs diff --git a/src/kernel/arch/x86_64/amd_virt.rs b/kernel/src/arch/x86_64/amd_virt.rs similarity index 100% rename from src/kernel/arch/x86_64/amd_virt.rs rename to kernel/src/arch/x86_64/amd_virt.rs diff --git a/src/kernel/arch/x86_64/asm.rs b/kernel/src/arch/x86_64/asm.rs similarity index 100% rename from src/kernel/arch/x86_64/asm.rs rename to kernel/src/arch/x86_64/asm.rs diff --git a/src/kernel/arch/x86_64/cpuid.rs b/kernel/src/arch/x86_64/cpuid.rs similarity index 100% rename from src/kernel/arch/x86_64/cpuid.rs rename to kernel/src/arch/x86_64/cpuid.rs diff --git a/src/kernel/arch/x86_64/gdt.rs b/kernel/src/arch/x86_64/gdt.rs similarity index 100% rename from src/kernel/arch/x86_64/gdt.rs rename to kernel/src/arch/x86_64/gdt.rs diff --git a/src/kernel/arch/x86_64/intel_virt.rs b/kernel/src/arch/x86_64/intel_virt.rs similarity index 100% rename from src/kernel/arch/x86_64/intel_virt.rs rename to kernel/src/arch/x86_64/intel_virt.rs diff --git a/src/kernel/arch/x86_64/interrupts.rs b/kernel/src/arch/x86_64/interrupts.rs similarity index 100% rename from src/kernel/arch/x86_64/interrupts.rs rename to kernel/src/arch/x86_64/interrupts.rs diff --git a/src/kernel/arch/x86_64/linker.ld b/kernel/src/arch/x86_64/linker.ld similarity index 100% rename from src/kernel/arch/x86_64/linker.ld rename to kernel/src/arch/x86_64/linker.ld diff --git a/src/kernel/arch/x86_64/mod.rs b/kernel/src/arch/x86_64/mod.rs similarity index 100% rename from src/kernel/arch/x86_64/mod.rs rename to kernel/src/arch/x86_64/mod.rs diff --git a/src/kernel/arch/x86_64/paging.rs b/kernel/src/arch/x86_64/paging.rs similarity index 100% rename from src/kernel/arch/x86_64/paging.rs rename to kernel/src/arch/x86_64/paging.rs index dfe3da4..9fc9b8a 100644 --- a/src/kernel/arch/x86_64/paging.rs +++ b/kernel/src/arch/x86_64/paging.rs @@ -4,8 +4,8 @@ #![allow(dead_code)] use crate::constants::KERNEL_BUILD_PROFILE; -use crate::{LOGGER, LogLevel, format, log_info, log_trace, memory::HHDM_RESPONSE}; use crate::memory::alloc::boxed::Box; +use crate::{LOGGER, LogLevel, format, log_info, log_trace, memory::HHDM_RESPONSE}; use free_list::{PAGE_SIZE, PageLayout}; use lazy_static::lazy_static; use spin::Mutex; diff --git a/src/kernel/arch/x86_64/serial.rs b/kernel/src/arch/x86_64/serial.rs similarity index 100% rename from src/kernel/arch/x86_64/serial.rs rename to kernel/src/arch/x86_64/serial.rs diff --git a/src/kernel/boot/mod.rs b/kernel/src/boot/mod.rs similarity index 100% rename from src/kernel/boot/mod.rs rename to kernel/src/boot/mod.rs diff --git a/src/kernel/boot/modules.rs b/kernel/src/boot/modules.rs similarity index 100% rename from src/kernel/boot/modules.rs rename to kernel/src/boot/modules.rs diff --git a/src/kernel/boot/params.rs b/kernel/src/boot/params.rs similarity index 100% rename from src/kernel/boot/params.rs rename to kernel/src/boot/params.rs diff --git a/src/kernel/constants.rs b/kernel/src/constants.rs similarity index 66% rename from src/kernel/constants.rs rename to kernel/src/constants.rs index 59ebe1d..a9dfc6b 100644 --- a/src/kernel/constants.rs +++ b/kernel/src/constants.rs @@ -1,46 +1,10 @@ // Copyright (c) 2025 shibedrill // SPDX-License-Identifier: MIT -use enumflags2::{BitFlags, bitflags}; -use lazy_static::lazy_static; - use crate::format; use crate::log::LogLevel; use crate::memory::alloc::string::String; -#[bitflags] -#[repr(u8)] -#[derive(Debug, Clone, Copy)] -pub enum Features { - Acpi, - Dtb, - Compression, - Uefi, -} - -lazy_static! { - #[derive(Debug)] - pub static ref FEATURE_FLAGS: BitFlags = { - let mut temp_flags = BitFlags::::empty(); - #[cfg(feature = "acpi")] - temp_flags.insert(Features::Acpi); - #[cfg(feature = "dtb")] - temp_flags.insert(Features::Dtb); - #[cfg(feature = "compression")] - temp_flags.insert(Features::Compression); - #[cfg(feature = "uefi")] - temp_flags.insert(Features::Uefi); - temp_flags - }; -} - -#[allow(dead_code)] -pub static INITRAMFS_DEFAULT_PATH: &str = if cfg!(feature = "compression") { - "/boot/initramfs.tar.lzma" -} else { - "/boot/initramfs.tar" -}; - pub static LOG_DEFAULT_LEVEL: LogLevel = LogLevel::Info; pub static KERNEL_BUILD_PROFILE: &str = { diff --git a/src/kernel/interrupt/mod.rs b/kernel/src/interrupt/mod.rs similarity index 100% rename from src/kernel/interrupt/mod.rs rename to kernel/src/interrupt/mod.rs diff --git a/src/kernel/log.rs b/kernel/src/log.rs similarity index 100% rename from src/kernel/log.rs rename to kernel/src/log.rs diff --git a/src/kernel/main.rs b/kernel/src/main.rs similarity index 95% rename from src/kernel/main.rs rename to kernel/src/main.rs index 4075981..2eef24e 100644 --- a/src/kernel/main.rs +++ b/kernel/src/main.rs @@ -9,7 +9,6 @@ mod arch; mod boot; mod constants; -mod device; mod interrupt; #[macro_use] mod log; @@ -23,12 +22,7 @@ use arch::x86_64::serial::SerialPort; use boot::{BASE_REVISION, params, *}; use constants::*; use log::*; -use memory::alloc::{ - boxed::Box, - format, - string::{String, ToString}, - vec, -}; +use memory::alloc::{boxed::Box, format, string::String, vec}; use params::*; use lazy_static::lazy_static; @@ -100,7 +94,6 @@ unsafe extern "C" fn main() -> ! { .lock() .log_writeln("\tWelcome to the Gila microkernel!\n"); log_info!("Booting gila version {}", kernel_version_string()); - log_info!("Enabled features: {}", FEATURE_FLAGS.to_string()); match boot::FIRMWARE_TYPE_REQUEST.get_response() { Some(resp) => log_info!( @@ -118,8 +111,6 @@ unsafe extern "C" fn main() -> ! { log_info!("Trans rights!"); - device::init_statics(); - if let Some(framebuffer_response) = FRAMEBUFFER_REQUEST.get_response() { let fb = framebuffer_response.framebuffers().next().unwrap(); log_info!("Framebuffer response received"); diff --git a/src/kernel/memory.rs b/kernel/src/memory.rs similarity index 99% rename from src/kernel/memory.rs rename to kernel/src/memory.rs index 826dd81..366ef6d 100644 --- a/src/kernel/memory.rs +++ b/kernel/src/memory.rs @@ -210,7 +210,6 @@ fn init_statics() { let _ = HHDM_RESPONSE; let _ = MODULE_RESPONSE; let _ = MEMMAP_RESPONSE; - crate::device::init_statics(); } #[used] diff --git a/src/kernel/panic.rs b/kernel/src/panic.rs similarity index 100% rename from src/kernel/panic.rs rename to kernel/src/panic.rs index dfa9f2d..4c773dc 100644 --- a/src/kernel/panic.rs +++ b/kernel/src/panic.rs @@ -3,8 +3,8 @@ use core::panic::*; -use crate::{LOGGER, LogLevel}; use crate::format; +use crate::{LOGGER, LogLevel}; #[panic_handler] pub fn panic(info: &PanicInfo) -> ! { diff --git a/src/kernel/process.rs b/kernel/src/process.rs similarity index 100% rename from src/kernel/process.rs rename to kernel/src/process.rs diff --git a/src/kernel/syscall_runner.rs b/kernel/src/syscall_runner.rs similarity index 100% rename from src/kernel/syscall_runner.rs rename to kernel/src/syscall_runner.rs diff --git a/src/kernel/util.rs b/kernel/src/util.rs similarity index 100% rename from src/kernel/util.rs rename to kernel/src/util.rs diff --git a/libgila/Cargo.toml b/libgila/Cargo.toml new file mode 100644 index 0000000..5961147 --- /dev/null +++ b/libgila/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "libgila" +version = "0.1.0" +edition = "2024" + +[dependencies] +num-derive = { version = "0.4.2", default-features = false } +num-traits = { version = "0.2.19", default-features = false } + +[lib] +# Stop appending lib to artifact names!!! it's already a library!!! +name = "gila" \ No newline at end of file diff --git a/src/lib/arch/aarch64/mod.rs b/libgila/src/arch/aarch64/mod.rs similarity index 100% rename from src/lib/arch/aarch64/mod.rs rename to libgila/src/arch/aarch64/mod.rs diff --git a/src/lib/arch/loongarch64/mod.rs b/libgila/src/arch/loongarch64/mod.rs similarity index 100% rename from src/lib/arch/loongarch64/mod.rs rename to libgila/src/arch/loongarch64/mod.rs diff --git a/src/lib/arch/mod.rs b/libgila/src/arch/mod.rs similarity index 100% rename from src/lib/arch/mod.rs rename to libgila/src/arch/mod.rs diff --git a/src/lib/arch/riscv64/mod.rs b/libgila/src/arch/riscv64/mod.rs similarity index 100% rename from src/lib/arch/riscv64/mod.rs rename to libgila/src/arch/riscv64/mod.rs diff --git a/src/lib/arch/x86_64/mod.rs b/libgila/src/arch/x86_64/mod.rs similarity index 100% rename from src/lib/arch/x86_64/mod.rs rename to libgila/src/arch/x86_64/mod.rs diff --git a/src/lib/arch/x86_64/syscall_impl.rs b/libgila/src/arch/x86_64/syscall_impl.rs similarity index 100% rename from src/lib/arch/x86_64/syscall_impl.rs rename to libgila/src/arch/x86_64/syscall_impl.rs diff --git a/src/lib/lib.rs b/libgila/src/lib.rs similarity index 100% rename from src/lib/lib.rs rename to libgila/src/lib.rs diff --git a/src/lib/registers.rs b/libgila/src/registers.rs similarity index 100% rename from src/lib/registers.rs rename to libgila/src/registers.rs diff --git a/src/lib/syscall/mod.rs b/libgila/src/syscall/mod.rs similarity index 100% rename from src/lib/syscall/mod.rs rename to libgila/src/syscall/mod.rs diff --git a/src/kernel/device/acpi.rs b/src/kernel/device/acpi.rs deleted file mode 100644 index e95733f..0000000 --- a/src/kernel/device/acpi.rs +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (c) 2025 shibedrill -// SPDX-License-Identifier: MIT - -// TODO: Implement per-arch memory handlers for ACPI memory map regions - -use lazy_static::lazy_static; -use limine::{request::RsdpRequest, response::RsdpResponse}; - -use crate::{format, log::*, log_info, log_warning}; - -#[used] -#[unsafe(link_section = ".requests")] -pub static RSDP_REQUEST: RsdpRequest = limine::request::RsdpRequest::new(); - -lazy_static! { - pub static ref RSDP: Option<&'static RsdpResponse> = match RSDP_REQUEST.get_response() { - Some(resp) => { - log_info!("Device: Got RSDP pointer"); - Some(resp) - } - None => { - log_warning!("Device: Did not get RSDP pointer, ACPI unavailable"); - None - } - }; -} diff --git a/src/kernel/device/devtree.rs b/src/kernel/device/devtree.rs deleted file mode 100644 index 7bb37b0..0000000 --- a/src/kernel/device/devtree.rs +++ /dev/null @@ -1,34 +0,0 @@ -use fdt::*; -use lazy_static::lazy_static; -use limine::{request::DeviceTreeBlobRequest, response::DeviceTreeBlobResponse}; - -use crate::{format, log::*, log_info, log_trace, log_warning}; - -#[used] -#[unsafe(link_section = ".requests")] -pub static DTB_REQUEST: DeviceTreeBlobRequest = limine::request::DeviceTreeBlobRequest::new(); - -lazy_static! { - pub static ref DTB: Option<&'static DeviceTreeBlobResponse> = match DTB_REQUEST.get_response() { - Some(resp) => { - log_info!("Device: Got DTB pointer"); - Some(resp) - } - None => { - log_warning!("Device: Did not get DTB pointer"); - None - } - }; -} - -#[allow(dead_code)] -pub fn device_tree_parsed() -> Option> { - if let Some(ok_dtb) = *DTB - && let Ok(ok_parsed_dt) = unsafe { fdt::Fdt::from_ptr(ok_dtb.dtb_ptr() as *const u8) } - { - log_trace!("Device: Parsed device tree"); - Some(ok_parsed_dt) - } else { - None - } -} diff --git a/src/kernel/device/mod.rs b/src/kernel/device/mod.rs deleted file mode 100644 index ee03f32..0000000 --- a/src/kernel/device/mod.rs +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (c) 2025 shibedrill -// SPDX-License-Identifier: MIT - -#[cfg(feature = "acpi")] -mod acpi; -#[cfg(feature = "dtb")] -mod devtree; - -use crate::log::{LOGGER, LogLevel}; -use crate::{format, log_error}; - -// Just to check -pub fn init_statics() { - let dtb = { - #[cfg(feature = "dtb")] - { - devtree::DTB.is_some() - } - #[cfg(not(feature = "dtb"))] - false - }; - let rdsp = { - #[cfg(feature = "acpi")] - { - acpi::RSDP.is_some() - } - #[cfg(not(feature = "acpi"))] - false - }; - if !dtb & !rdsp { - log_error!("Device: Neither DTB nor ACPI available, booted system will be useless") - } -}