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

@ -3,17 +3,26 @@
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) {
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 ") },
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,
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,
Err(_) => { panic!("Invalid version number ") },
Err(_) => {
panic!("Invalid version number ")
}
};
#[allow(unused_variables)]

View File

@ -0,0 +1 @@

View File

@ -0,0 +1 @@

View File

@ -0,0 +1 @@

View File

@ -1 +1,2 @@
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.
use crate::syscall::*;
struct Registers {
}

View File

@ -1,5 +1,6 @@
#![no_std]
#![allow(unused_imports)]
mod arch;
pub mod registers;
pub mod syscall;
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

@ -11,15 +11,16 @@ pub enum SyscallArgs {
Args3(usize, usize, usize),
Args4(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 {
Ok = 0,
SyscallNotExist = 1,
FileNotExist = 2,
ProcessNotExist = 3,
PermissionDenied = 4,
Aborted = 5,
Ok, // No error.
Unspecified, // Unspecified error occurred.
SyscallNotExist, // System call does not exist.
FileNotExist, // The file mentioned does not exist.
ProcessNotExist, // The process mentioned does not exist.
PermissionDenied, // The process lacks capabilities.
Aborted, // The kernel gave up on a blocking request.
}