From 4f40b3e9ca9177b26a46b4fb8f1555eb12c8446d Mon Sep 17 00:00:00 2001 From: shibedrill Date: Thu, 13 Mar 2025 14:24:48 -0400 Subject: [PATCH] What am I doing --- Cargo.lock | 8 +++---- Cargo.toml | 4 ++++ README.md | 23 +++++++++++------- src/kernel/main.rs | 2 +- src/kernel/memory.rs | 6 ++--- src/kernel/process.rs | 8 +++---- src/kernel/{syscall.rs => syscall_runner.rs} | 16 +++++-------- src/lib/arch/mod.rs | 19 +++++++++++++++ src/lib/arch/x86_64/mod.rs | 1 + src/lib/arch/x86_64/syscall_impl.rs | 9 +++++++ src/lib/lib.rs | 5 ++++ src/lib/syscall.rs | 25 ++++++++++++++++++++ 12 files changed, 95 insertions(+), 31 deletions(-) rename src/kernel/{syscall.rs => syscall_runner.rs} (51%) create mode 100644 src/lib/arch/mod.rs create mode 100644 src/lib/arch/x86_64/mod.rs create mode 100644 src/lib/arch/x86_64/syscall_impl.rs create mode 100644 src/lib/lib.rs create mode 100644 src/lib/syscall.rs diff --git a/Cargo.lock b/Cargo.lock index c4e198c..c9c7ceb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,9 +4,9 @@ version = 4 [[package]] name = "acpi" -version = "5.1.0" +version = "5.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e42f25ac5fa51f4188d14baf8f387a97dcd8639644b2f3df948bf5f6dd7d6fa" +checksum = "94476c7ef97af4c4d998b3f422c1b01d5211aad57c80ed200baf148d1f1efab6" dependencies = [ "bit_field", "bitflags 2.9.0", @@ -140,9 +140,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.20.3" +version = "1.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "945462a4b81e43c4e3ba96bd7b49d834c6f61198356aa858733bc4acf3cbe62e" +checksum = "cde51589ab56b20a6f686b2c68f7a0bd6add753d697abf720d63f8db3ab7b1ad" dependencies = [ "critical-section", "portable-atomic", diff --git a/Cargo.toml b/Cargo.toml index 1e4d335..a81fd02 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,6 +15,10 @@ talc = "4.4.2" [target.'cfg(target_arch = "x86_64")'.dependencies] vga = "0.2.9" +[lib] +name = "gila" +path = "src/lib/lib.rs" + [[bin]] name = "kernel" path = "src/kernel/main.rs" diff --git a/README.md b/README.md index 8830ca9..b0c66d8 100644 --- a/README.md +++ b/README.md @@ -41,15 +41,20 @@ Licensed under the GNU Public License v3. See [LICENSE](LICENSE) for details. ## Navigating -- [arch/](src/kernelarch/): Architecture specific features like the display, serial, and interrupts. Each architecture is a subfolder, containing a file or module for each feature. -- [boot.rs](src/kernel/boot.rs): Handles bootloader-managed data structures. Gila uses Limine. Other bootloaders are NOT supported. -- [log.rs](src/kernel/log.rs): Logging structures and singletons for logging to serial or the display. -- [main.rs](src/kernel/main.rs): The entry point that gets called by the bootloader. -- [memory.rs](src/kernel/memory.rs): Types relating to memory regions and allocation. -- [panic.rs](src/kernel/panic.rs): The panic handler and associated functionality. -- [params.rs](src/kernel/params.rs): Kernel parameter handler code. -- [process.rs](src/kernel/process.rs): Process types and functions. -- [resources.rs](src/kernel/resources.rs): Resources that are accessible from multiple parts of the code. +- [kernel/](src/kernel/): Kernel-specific code. + - [arch/](src/kernel/arch/): Architecture specific features like the display, serial, and interrupts. Each architecture is a subfolder, containing a file or module for each feature. + - [boot.rs](src/kernel/boot.rs): Handles bootloader-managed data structures. Gila uses Limine. Other bootloaders are NOT supported. + - [log.rs](src/kernel/log.rs): Logging structures and singletons for logging to serial or the display. + - [main.rs](src/kernel/main.rs): The entry point that gets called by the bootloader. + - [memory.rs](src/kernel/memory.rs): Types relating to memory regions and allocation. + - [panic.rs](src/kernel/panic.rs): The panic handler and associated functionality. + - [params.rs](src/kernel/params.rs): Kernel parameter handler code. + - [process.rs](src/kernel/process.rs): Process types and functions. + - [resources.rs](src/kernel/resources.rs): Resources that are accessible from multiple parts of the code. + - [syscall_runner.rs](src/kernel/syscall_runner.rs): Chooses a system call by its ID and defers actual syscall execution to code in `src/lib/`. +- [lib/](src/lib/): Library that all Gila's binary programs will be built against. Some of this code is shared with the kernel. + - [arch/](src/lib/arch/): Architecture specific functionality like system call register storing/loading. + - [syscall.rs](src/lib/syscall.rs): System call types common to apps and the kernel. ## Building and running diff --git a/src/kernel/main.rs b/src/kernel/main.rs index 9f37111..ef5d0ab 100644 --- a/src/kernel/main.rs +++ b/src/kernel/main.rs @@ -10,7 +10,7 @@ mod panic; mod params; mod process; mod resources; -mod syscall; +mod syscall_runner; use crate::boot::*; use crate::log::*; diff --git a/src/kernel/memory.rs b/src/kernel/memory.rs index 963219b..deeeb53 100644 --- a/src/kernel/memory.rs +++ b/src/kernel/memory.rs @@ -36,7 +36,7 @@ impl MemoryRegion { #[repr(u8)] #[derive(Clone, Copy)] pub enum MemoryRegionFlags { - READABLE, - WRITABLE, - EXECUTABLE, + Readable, + Writable, + Executable, } diff --git a/src/kernel/process.rs b/src/kernel/process.rs index 90e6c01..f8c59aa 100644 --- a/src/kernel/process.rs +++ b/src/kernel/process.rs @@ -1,5 +1,4 @@ -#![allow(unused_imports)] -#![allow(dead_code)] +#![allow(unused_imports, dead_code)] use enumflags2::{BitFlags, bitflags, make_bitflags}; @@ -87,7 +86,8 @@ pub enum ProcessCapabilities { // Sessions can only be opened if two processes both request a session with // each other (mutual operation). Submitting a session request is a blocking // system call that will return either once the other process accepts, or the -// kernel denies the request due to missing capability. +// kernel denies the request due to missing capability, or the other process +// not existing yet. pub struct ProcessSession { proc_id_a: u32, proc_id_b: u32, @@ -100,7 +100,7 @@ impl ProcessSession { proc_id_a: a.proc_id, proc_id_b: b.proc_id, shared_mem: MemoryRegion::new( - MemoryRegionFlags::READABLE | MemoryRegionFlags::WRITABLE, + MemoryRegionFlags::Readable | MemoryRegionFlags::Writable, ), } } diff --git a/src/kernel/syscall.rs b/src/kernel/syscall_runner.rs similarity index 51% rename from src/kernel/syscall.rs rename to src/kernel/syscall_runner.rs index 9f3294a..319a8c3 100644 --- a/src/kernel/syscall.rs +++ b/src/kernel/syscall_runner.rs @@ -1,5 +1,7 @@ #![allow(dead_code)] +use crate::process::Process; + // FUCKING ADD CONST UNWRAP!!! pub static KERNEL_VERSION_MAJOR: u8 = match u8::from_str_radix(env!("CARGO_PKG_VERSION_MAJOR"), 10) { Ok(ver) => ver, @@ -14,13 +16,7 @@ pub static KERNEL_VERSION_PATCH: u8 = match u8::from_str_radix(env!("CARGO_PKG_V Err(_) => { panic!("Invalid version number ") }, }; -// TODO: Set up match statement that handles syscalls. -// All syscalls will be a function with the following signature: -// fn syscall(ctx: &mut Process, arg0: usize); -// The ctx variable should be a reference to the calling process, so we can -// modify its stored registers with return values. RAX is used to store the -// status number. - -// TODO: Figure out a way to make the ABI usable. The registers used to store -// system call results must be the same on the kernel side and the user side. -// As such, more work is needed to abstract this nicely. \ No newline at end of file +#[allow(unused_variables)] +pub fn run_syscall(process: &mut Process) { + // Get the syscall ID from the process's CPU registers. +} \ No newline at end of file diff --git a/src/lib/arch/mod.rs b/src/lib/arch/mod.rs new file mode 100644 index 0000000..a92bb82 --- /dev/null +++ b/src/lib/arch/mod.rs @@ -0,0 +1,19 @@ +#[cfg(target_arch = "x86_64")] +pub mod x86_64; +#[cfg(target_arch = "x86_64")] +pub use x86_64 as current; + +#[cfg(target_arch = "aarch64")] +pub mod aarch64; +#[cfg(target_arch = "aarch64")] +pub use aarch64 as current; + +#[cfg(target_arch = "riscv64")] +pub mod riscv64; +#[cfg(target_arch = "riscv64")] +pub use riscv64 as current; + +#[cfg(target_arch = "loongarch64")] +pub mod loongarch64; +#[cfg(target_arch = "loongarch64")] +pub use loongarch64 as current; diff --git a/src/lib/arch/x86_64/mod.rs b/src/lib/arch/x86_64/mod.rs new file mode 100644 index 0000000..edd663b --- /dev/null +++ b/src/lib/arch/x86_64/mod.rs @@ -0,0 +1 @@ +mod syscall_impl; \ No newline at end of file diff --git a/src/lib/arch/x86_64/syscall_impl.rs b/src/lib/arch/x86_64/syscall_impl.rs new file mode 100644 index 0000000..3fc69b5 --- /dev/null +++ b/src/lib/arch/x86_64/syscall_impl.rs @@ -0,0 +1,9 @@ +#![allow(dead_code, unused_variables)] + +// The system call API for x86_64. + +use crate::syscall::*; + +struct Registers { + +} \ No newline at end of file diff --git a/src/lib/lib.rs b/src/lib/lib.rs new file mode 100644 index 0000000..67513b8 --- /dev/null +++ b/src/lib/lib.rs @@ -0,0 +1,5 @@ +#![no_std] +#![allow(unused_imports)] +mod arch; +pub mod syscall; +pub use arch::current::*; \ No newline at end of file diff --git a/src/lib/syscall.rs b/src/lib/syscall.rs new file mode 100644 index 0000000..661a206 --- /dev/null +++ b/src/lib/syscall.rs @@ -0,0 +1,25 @@ +#![allow(dead_code)] + +// TODO: Implement a nice API for system calls. +// I don't want to have to define the argument/return value registers twice +// per architecture. How do I make this work? + +pub enum SyscallArgs { + Args0(), + Args1(usize), + Args2(usize, usize), + Args3(usize, usize, usize), + Args4(usize, usize, usize, usize), + Args5(usize, usize, usize, usize, usize), + Args6(usize, usize, usize, usize, usize, usize) +} + +#[repr(u16)] +pub enum SyscallError { + Ok = 0, + SyscallNotExist = 1, + FileNotExist = 2, + ProcessNotExist = 3, + PermissionDenied = 4, + Aborted = 5, +} \ No newline at end of file