What am I doing

This commit is contained in:
River 2025-03-13 14:24:48 -04:00
parent d5ca08e647
commit 4f40b3e9ca
Signed by: shibedrill
GPG Key ID: 5FE0CB25945EFAA2
12 changed files with 95 additions and 31 deletions

8
Cargo.lock generated
View File

@ -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",

View File

@ -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"

View File

@ -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

View File

@ -10,7 +10,7 @@ mod panic;
mod params;
mod process;
mod resources;
mod syscall;
mod syscall_runner;
use crate::boot::*;
use crate::log::*;

View File

@ -36,7 +36,7 @@ impl MemoryRegion {
#[repr(u8)]
#[derive(Clone, Copy)]
pub enum MemoryRegionFlags {
READABLE,
WRITABLE,
EXECUTABLE,
Readable,
Writable,
Executable,
}

View File

@ -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,
),
}
}

View File

@ -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.
#[allow(unused_variables)]
pub fn run_syscall(process: &mut Process) {
// Get the syscall ID from the process's CPU registers.
}

19
src/lib/arch/mod.rs Normal file
View File

@ -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;

View File

@ -0,0 +1 @@
mod syscall_impl;

View File

@ -0,0 +1,9 @@
#![allow(dead_code, unused_variables)]
// The system call API for x86_64.
use crate::syscall::*;
struct Registers {
}

5
src/lib/lib.rs Normal file
View File

@ -0,0 +1,5 @@
#![no_std]
#![allow(unused_imports)]
mod arch;
pub mod syscall;
pub use arch::current::*;

25
src/lib/syscall.rs Normal file
View File

@ -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,
}