Set up some stuff for syscalls?

This commit is contained in:
River 2025-03-13 13:09:45 -04:00
parent 2915a9e746
commit d5ca08e647
Signed by: shibedrill
GPG Key ID: 5FE0CB25945EFAA2
5 changed files with 105 additions and 26 deletions

View File

@ -1,8 +1,9 @@
#![allow(clippy::missing_safety_doc)]
use core::arch::asm;
#[allow(clippy::missing_safety_doc)]
pub unsafe fn halt() {
unsafe {
asm!("hlt");
}
}
}

View File

@ -10,6 +10,7 @@ mod panic;
mod params;
mod process;
mod resources;
mod syscall;
use crate::boot::*;
use crate::log::*;
@ -28,7 +29,9 @@ unsafe extern "C" fn main() -> ! {
// Set up some stuff based on kernel params if we get any
if let Some(executable_file_response) = FILE_REQUEST.get_response() {
let kernel_parameters = get_kernel_params(limine::file::File::string(executable_file_response.file()).to_bytes());
let kernel_parameters = get_kernel_params(
limine::file::File::string(executable_file_response.file()).to_bytes(),
);
// Set up logging level from params
if let Some(level) = kernel_parameters.get("-loglevel") {
@ -51,7 +54,9 @@ unsafe extern "C" fn main() -> ! {
LogLevel::Info,
&format!(
"Boot: Kernel cmdline: {}",
String::from_utf8_lossy(limine::file::File::string(executable_file_response.file()).to_bytes())
String::from_utf8_lossy(
limine::file::File::string(executable_file_response.file()).to_bytes()
)
),
);
log(

View File

@ -1,6 +1,6 @@
#![allow(unused_imports)]
use flagset::flags;
use enumflags2::*;
use core::alloc::{Allocator, Layout};
use talc::*;
@ -21,13 +21,22 @@ static ALLOCATOR: Talck<spin::Mutex<()>, ClaimOnOom> = Talc::new(unsafe {
pub struct MemoryRegion {
start_address: usize,
end_address: usize,
flags: MemoryRegionFlags,
flags: BitFlags<MemoryRegionFlags>,
}
flags! {
pub enum MemoryRegionFlags: u8 {
READABLE,
WRITABLE,
EXECUTABLE,
impl MemoryRegion {
// TODO: Memory allocation and virtual addressing
#[allow(unused_variables)]
pub fn new(flags: BitFlags<MemoryRegionFlags>) -> Self {
todo!()
}
}
#[bitflags]
#[repr(u8)]
#[derive(Clone, Copy)]
pub enum MemoryRegionFlags {
READABLE,
WRITABLE,
EXECUTABLE,
}

View File

@ -1,12 +1,15 @@
#![allow(unused_imports)]
#![allow(dead_code)]
use enumflags2::{bitflags, make_bitflags, BitFlags};
use enumflags2::{BitFlags, bitflags, make_bitflags};
use crate::arch::current;
use crate::memory::MemoryRegion;
use crate::memory::MemoryRegionFlags;
use crate::memory::alloc;
use alloc::string::String;
use alloc::vec::Vec;
use current::asm;
#[allow(dead_code)]
pub struct ProcessTable {}
@ -42,7 +45,7 @@ pub unsafe fn context_switch() -> ! {
#[allow(unused_unsafe)]
unsafe {
loop {
crate::arch::current::asm::halt();
asm::halt();
}
}
}
@ -60,20 +63,55 @@ pub enum ProcessState {
#[derive(Copy, Clone)]
pub enum ProcessCapabilities {
// Process capabilities
ProcessEnum, // Enumerate running process IDs and names
ProcessRead, // Read information from a process struct
ProcessKill, // Kill any process
ProcessSpawn, // Create a new process
ProcessExec, // Replace self with new process image
ProcessEnum, // Enumerate running process IDs and names
ProcessRead, // Read information from a process struct
ProcessKill, // Kill any process
ProcessSpawn, // Create a new process
ProcessExec, // Replace self with new process image
ProcessSession, // Create and accept Session requests.
// File system capabilities
FileEnum, // Enumerate directories and files
FileRead, // Read files
FileWrite, // Write to files
FileEnum, // Enumerate directories and files
FileRead, // Read files
FileWrite, // Write to files
FilePermission, // Modify file permissions
FileCreate, // Create files
FileDelete, // Delete files
FileSystem, // Mount, unmount, and modify filesystems
FileCreate, // Create files
FileDelete, // Delete files
FileSystem, // Mount, unmount, and modify filesystems
// Kernel config capabilities
KernelCfgRead, // Read kernel configurations
KernelCfgRead, // Read kernel configurations
KernelCfgWrite, // Modify kernel configurations
}
// Interprocess communication system:
// Processes communicate through "sessions" which are mediated by the kernel.
// 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.
pub struct ProcessSession {
proc_id_a: u32,
proc_id_b: u32,
shared_mem: MemoryRegion,
}
impl ProcessSession {
pub fn new(a: ProcessSessionRequest, b: ProcessSessionRequest) -> Self {
ProcessSession {
proc_id_a: a.proc_id,
proc_id_b: b.proc_id,
shared_mem: MemoryRegion::new(
MemoryRegionFlags::READABLE | MemoryRegionFlags::WRITABLE,
),
}
}
}
pub struct ProcessSessionRequest {
proc_id: u32,
}
impl ProcessSessionRequest {
pub fn accept(self, b: ProcessSessionRequest) -> ProcessSession {
ProcessSession::new(self, b)
}
}

26
src/kernel/syscall.rs Normal file
View File

@ -0,0 +1,26 @@
#![allow(dead_code)]
// FUCKING ADD CONST UNWRAP!!!
pub static KERNEL_VERSION_MAJOR: u8 = match u8::from_str_radix(env!("CARGO_PKG_VERSION_MAJOR"), 10) {
Ok(ver) => ver,
Err(_) => { panic!("Invalid version number ") },
};
pub static KERNEL_VERSION_MINOR: u8 = match u8::from_str_radix(env!("CARGO_PKG_VERSION_MINOR"), 10) {
Ok(ver) => ver,
Err(_) => { panic!("Invalid version number ") },
};
pub static KERNEL_VERSION_PATCH: u8 = match u8::from_str_radix(env!("CARGO_PKG_VERSION_PATCH"), 10) {
Ok(ver) => ver,
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.