Tentative API

This commit is contained in:
River 2025-03-13 16:29:38 -04:00
parent 4f40b3e9ca
commit cb50a6d58c
Signed by: shibedrill
GPG Key ID: 5FE0CB25945EFAA2
11 changed files with 75 additions and 24 deletions

View File

@ -6,4 +6,4 @@ pub unsafe fn halt() {
unsafe { unsafe {
asm!("hlt"); asm!("hlt");
} }
} }

View File

@ -3,20 +3,29 @@
use crate::process::Process; use crate::process::Process;
// FUCKING ADD CONST UNWRAP!!! // FUCKING ADD CONST UNWRAP!!!
pub static KERNEL_VERSION_MAJOR: u8 = match u8::from_str_radix(env!("CARGO_PKG_VERSION_MAJOR"), 10) { pub static KERNEL_VERSION_MAJOR: u8 = match u8::from_str_radix(env!("CARGO_PKG_VERSION_MAJOR"), 10)
{
Ok(ver) => ver, Ok(ver) => ver,
Err(_) => { panic!("Invalid version number ") }, Err(_) => {
panic!("Invalid version number ")
}
}; };
pub static KERNEL_VERSION_MINOR: u8 = match u8::from_str_radix(env!("CARGO_PKG_VERSION_MINOR"), 10) { pub static KERNEL_VERSION_MINOR: u8 = match u8::from_str_radix(env!("CARGO_PKG_VERSION_MINOR"), 10)
{
Ok(ver) => ver, Ok(ver) => ver,
Err(_) => { panic!("Invalid version number ") }, Err(_) => {
panic!("Invalid version number ")
}
}; };
pub static KERNEL_VERSION_PATCH: u8 = match u8::from_str_radix(env!("CARGO_PKG_VERSION_PATCH"), 10) { pub static KERNEL_VERSION_PATCH: u8 = match u8::from_str_radix(env!("CARGO_PKG_VERSION_PATCH"), 10)
{
Ok(ver) => ver, Ok(ver) => ver,
Err(_) => { panic!("Invalid version number ") }, Err(_) => {
panic!("Invalid version number ")
}
}; };
#[allow(unused_variables)] #[allow(unused_variables)]
pub fn run_syscall(process: &mut Process) { pub fn run_syscall(process: &mut Process) {
// Get the syscall ID from the process's CPU registers. // Get the syscall ID from the process's CPU registers.
} }

View File

@ -0,0 +1 @@

View File

@ -0,0 +1 @@

View File

@ -0,0 +1 @@

View File

@ -1 +1,2 @@
mod syscall_impl; mod registers_impl;
mod syscall_impl;

View File

@ -0,0 +1,4 @@
#[allow(dead_code)]
pub struct Registers {
// Private fields
}

View File

@ -3,7 +3,3 @@
// The system call API for x86_64. // The system call API for x86_64.
use crate::syscall::*; use crate::syscall::*;
struct Registers {
}

View File

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

36
src/lib/registers.rs Normal file
View File

@ -0,0 +1,36 @@
// Every architecture MUST implement this as part of the ABI.
// Additional registers can be implemented with architecture-specific traits.
pub unsafe trait RegStoreLoad
where
Self: Sized,
Self: Default,
{
// Create an instance of Registers by loading values from the CPU.
// This MUST NOT modify any CPU registers, and can only read them.
fn load_all() -> Self;
// Create a new instance to write to before we commit to the CPU.
// This MUST instantiate a zeroed set of registers.
// Do not represent unmodified registers as None variants of an Option.
fn new_zeroed() -> Self {
Self::default()
}
// Store the instance to the CPU and consume self.
// This MUST write ALL register values to the CPU, including zero values.
fn store_all(self);
// All of these functions below MUST NOT write directly to the CPU.
// The registers will be written when store_all() is called.
// Get the six argument or return register values.
// This MUST read registers in the same order as set_syscall_args sets them.
fn read_syscall_args(&self) -> [usize; 6];
// Get the syscall number or error number.
// This MUST NOT zero or otherwise overwrite the register.
fn read_syscall_num(&self) -> usize;
// Set the six argument or return register values.
// This MUST write registers in the same order as read_syscall_args reads them.
fn set_syscall_args(&mut self, new_values: [usize; 6]);
// Set the syscall number or error number.
// This MUST NOT change any other registers.
fn set_syscall_num(&mut self, new_value: usize);
}

View File

@ -1,7 +1,7 @@
#![allow(dead_code)] #![allow(dead_code)]
// TODO: Implement a nice API for system calls. // TODO: Implement a nice API for system calls.
// I don't want to have to define the argument/return value registers twice // I don't want to have to define the argument/return value registers twice
// per architecture. How do I make this work? // per architecture. How do I make this work?
pub enum SyscallArgs { pub enum SyscallArgs {
@ -11,15 +11,16 @@ pub enum SyscallArgs {
Args3(usize, usize, usize), Args3(usize, usize, usize),
Args4(usize, usize, usize, usize), Args4(usize, usize, usize, usize),
Args5(usize, usize, usize, usize, usize), Args5(usize, usize, usize, usize, usize),
Args6(usize, usize, usize, usize, usize, usize) Args6(usize, usize, usize, usize, usize, usize),
} }
#[repr(u16)] #[repr(usize)]
pub enum SyscallError { pub enum SyscallError {
Ok = 0, Ok, // No error.
SyscallNotExist = 1, Unspecified, // Unspecified error occurred.
FileNotExist = 2, SyscallNotExist, // System call does not exist.
ProcessNotExist = 3, FileNotExist, // The file mentioned does not exist.
PermissionDenied = 4, ProcessNotExist, // The process mentioned does not exist.
Aborted = 5, PermissionDenied, // The process lacks capabilities.
} Aborted, // The kernel gave up on a blocking request.
}