From 5af0c919f4b3200779815ebb61c3850d8642a6ff Mon Sep 17 00:00:00 2001 From: shibedrill Date: Fri, 7 Feb 2025 10:47:15 -0500 Subject: [PATCH] Cleaning up structure --- Cargo.lock | 36 ++++++++++++++++++++++++++++++++++++ Cargo.toml | 3 +++ src/alloc.rs | 4 ---- src/boot.rs | 5 +++++ src/lib.rs | 10 ++++++++-- src/main.rs | 6 ++++-- src/memory.rs | 17 ++++++++++++++++- src/process.rs | 22 ++++++++++++++++++++-- src/resources.rs | 0 9 files changed, 92 insertions(+), 11 deletions(-) delete mode 100644 src/alloc.rs create mode 100644 src/boot.rs create mode 100644 src/resources.rs diff --git a/Cargo.lock b/Cargo.lock index 89391c7..e1a970f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8,6 +8,12 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" +[[package]] +name = "bitflags" +version = "2.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f68f53c83ab957f72c32642f3868eec03eb974d1fb82e453128456482613d36" + [[package]] name = "flagset" version = "0.4.6" @@ -19,9 +25,30 @@ name = "gila" version = "0.1.0" dependencies = [ "flagset", + "lazy_static", + "limine", + "spin", "talc", ] +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" +dependencies = [ + "spin", +] + +[[package]] +name = "limine" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ca87cab008b8efeebdbe037cd4d1438037d48c5cb6fed939ffa5aa06315a321" +dependencies = [ + "bitflags", +] + [[package]] name = "lock_api" version = "0.4.12" @@ -38,6 +65,15 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" +dependencies = [ + "lock_api", +] + [[package]] name = "talc" version = "4.4.2" diff --git a/Cargo.toml b/Cargo.toml index 1b0cd09..c4fe782 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,6 +5,9 @@ edition = "2024" [dependencies] flagset = "0.4.6" +lazy_static = { version = "1.5.0", features = ["spin_no_std"] } +limine = "0.3.1" +spin = "0.9.8" talc = "4.4.2" [[bin]] diff --git a/src/alloc.rs b/src/alloc.rs deleted file mode 100644 index 4a04396..0000000 --- a/src/alloc.rs +++ /dev/null @@ -1,4 +0,0 @@ -#![allow(unused_imports)] - -use talc::*; -use core::alloc::{Allocator, Layout}; diff --git a/src/boot.rs b/src/boot.rs new file mode 100644 index 0000000..ccfacb7 --- /dev/null +++ b/src/boot.rs @@ -0,0 +1,5 @@ +#![allow(dead_code)] + +use limine::BaseRevision; + +static BASE: BaseRevision = limine::BaseRevision::new(); \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 9ea2514..f4ebe96 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,7 +1,13 @@ #![no_std] #![feature(allocator_api)] +/// Process representation. pub mod process; +/// Memory regions, allocation, flags, and whatnot. pub mod memory; -pub mod alloc; -pub mod panic; \ No newline at end of file +/// Panic handling function logic. +pub mod panic; +/// Boot services, handled by the Limine boot protocol. +pub mod boot; +/// Resources accessible from many parts of the code. +pub mod resources; \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index b72c39c..c040271 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,13 +1,15 @@ #![no_std] +#![no_main] + #![feature(allocator_api)] #![allow(dead_code)] #![allow(unused_imports)] use gila::process; use gila::memory; -use gila::alloc; use gila::panic; -fn main() { +#[unsafe(no_mangle)] +pub extern "C" fn main() { } diff --git a/src/memory.rs b/src/memory.rs index 6f751d2..33c5208 100644 --- a/src/memory.rs +++ b/src/memory.rs @@ -1,11 +1,26 @@ #![allow(dead_code)] +#![allow(unused_imports)] use flagset::flags; +use talc::*; +use spin; +use core::alloc::{Allocator, Layout}; + +static mut ARENA: [u8; 10000] = [0; 10000]; + +#[global_allocator] +static ALLOCATOR: Talck, ClaimOnOom> = Talc::new(unsafe { + // if we're in a hosted environment, the Rust runtime may allocate before + // main() is called, so we need to initialize the arena automatically + ClaimOnOom::new(Span::from_array(core::ptr::addr_of!(ARENA).cast_mut())) +}).lock(); + + pub struct MemoryRegion { start_address: usize, end_address: usize, - + flags: MemoryRegionFlags, } flags! { diff --git a/src/process.rs b/src/process.rs index b5eb100..e1f8d9b 100644 --- a/src/process.rs +++ b/src/process.rs @@ -1,19 +1,37 @@ #![allow(dead_code)] +#![allow(unused_imports)] use crate::memory::MemoryRegion; +use lazy_static; + extern crate alloc; use alloc::vec::Vec; use alloc::string::String; +pub struct ProcessTable {} + pub struct Process { + /// Unique process ID. proc_id: u32, + /// ID of the parent process. parent_proc_id: u32, + /// List of all child processes. + child_proc_ids: Vec, + /// Human readable name of the process, should be the command. name: String, + /// The base address of the process stack within its memory region. stack_base_addr: usize, - stack_ptr_addr: usize, - mem_regions: Vec, + /// The length of the stack. This, plus the start address, is the stack size. + stack_length: usize, + /// The stack pointer, which is relative to the memory region start. + stack_ptr: usize, + /// The region of memory allocated to the process. + mem_region: MemoryRegion, + /// Process priority. Lower number is higher priority. prio: u16, + /// Which semaphor the process is waiting on. + semaphor_wait: Option, } pub enum ProcessState { diff --git a/src/resources.rs b/src/resources.rs new file mode 100644 index 0000000..e69de29