Set up some stuff for syscalls?
This commit is contained in:
parent
2915a9e746
commit
d5ca08e647
@ -1,8 +1,9 @@
|
|||||||
|
#![allow(clippy::missing_safety_doc)]
|
||||||
|
|
||||||
use core::arch::asm;
|
use core::arch::asm;
|
||||||
|
|
||||||
#[allow(clippy::missing_safety_doc)]
|
|
||||||
pub unsafe fn halt() {
|
pub unsafe fn halt() {
|
||||||
unsafe {
|
unsafe {
|
||||||
asm!("hlt");
|
asm!("hlt");
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -10,6 +10,7 @@ mod panic;
|
|||||||
mod params;
|
mod params;
|
||||||
mod process;
|
mod process;
|
||||||
mod resources;
|
mod resources;
|
||||||
|
mod syscall;
|
||||||
|
|
||||||
use crate::boot::*;
|
use crate::boot::*;
|
||||||
use crate::log::*;
|
use crate::log::*;
|
||||||
@ -28,7 +29,9 @@ unsafe extern "C" fn main() -> ! {
|
|||||||
|
|
||||||
// Set up some stuff based on kernel params if we get any
|
// Set up some stuff based on kernel params if we get any
|
||||||
if let Some(executable_file_response) = FILE_REQUEST.get_response() {
|
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
|
// Set up logging level from params
|
||||||
if let Some(level) = kernel_parameters.get("-loglevel") {
|
if let Some(level) = kernel_parameters.get("-loglevel") {
|
||||||
@ -51,7 +54,9 @@ unsafe extern "C" fn main() -> ! {
|
|||||||
LogLevel::Info,
|
LogLevel::Info,
|
||||||
&format!(
|
&format!(
|
||||||
"Boot: Kernel cmdline: {}",
|
"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(
|
log(
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#![allow(unused_imports)]
|
#![allow(unused_imports)]
|
||||||
|
|
||||||
use flagset::flags;
|
use enumflags2::*;
|
||||||
|
|
||||||
use core::alloc::{Allocator, Layout};
|
use core::alloc::{Allocator, Layout};
|
||||||
use talc::*;
|
use talc::*;
|
||||||
@ -21,13 +21,22 @@ static ALLOCATOR: Talck<spin::Mutex<()>, ClaimOnOom> = Talc::new(unsafe {
|
|||||||
pub struct MemoryRegion {
|
pub struct MemoryRegion {
|
||||||
start_address: usize,
|
start_address: usize,
|
||||||
end_address: usize,
|
end_address: usize,
|
||||||
flags: MemoryRegionFlags,
|
flags: BitFlags<MemoryRegionFlags>,
|
||||||
}
|
}
|
||||||
|
|
||||||
flags! {
|
impl MemoryRegion {
|
||||||
pub enum MemoryRegionFlags: u8 {
|
// TODO: Memory allocation and virtual addressing
|
||||||
READABLE,
|
#[allow(unused_variables)]
|
||||||
WRITABLE,
|
pub fn new(flags: BitFlags<MemoryRegionFlags>) -> Self {
|
||||||
EXECUTABLE,
|
todo!()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[bitflags]
|
||||||
|
#[repr(u8)]
|
||||||
|
#[derive(Clone, Copy)]
|
||||||
|
pub enum MemoryRegionFlags {
|
||||||
|
READABLE,
|
||||||
|
WRITABLE,
|
||||||
|
EXECUTABLE,
|
||||||
|
}
|
||||||
|
@ -1,12 +1,15 @@
|
|||||||
#![allow(unused_imports)]
|
#![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::MemoryRegion;
|
||||||
|
use crate::memory::MemoryRegionFlags;
|
||||||
use crate::memory::alloc;
|
use crate::memory::alloc;
|
||||||
use alloc::string::String;
|
use alloc::string::String;
|
||||||
use alloc::vec::Vec;
|
use alloc::vec::Vec;
|
||||||
|
use current::asm;
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub struct ProcessTable {}
|
pub struct ProcessTable {}
|
||||||
@ -42,7 +45,7 @@ pub unsafe fn context_switch() -> ! {
|
|||||||
#[allow(unused_unsafe)]
|
#[allow(unused_unsafe)]
|
||||||
unsafe {
|
unsafe {
|
||||||
loop {
|
loop {
|
||||||
crate::arch::current::asm::halt();
|
asm::halt();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -60,20 +63,55 @@ pub enum ProcessState {
|
|||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
pub enum ProcessCapabilities {
|
pub enum ProcessCapabilities {
|
||||||
// Process capabilities
|
// Process capabilities
|
||||||
ProcessEnum, // Enumerate running process IDs and names
|
ProcessEnum, // Enumerate running process IDs and names
|
||||||
ProcessRead, // Read information from a process struct
|
ProcessRead, // Read information from a process struct
|
||||||
ProcessKill, // Kill any process
|
ProcessKill, // Kill any process
|
||||||
ProcessSpawn, // Create a new process
|
ProcessSpawn, // Create a new process
|
||||||
ProcessExec, // Replace self with new process image
|
ProcessExec, // Replace self with new process image
|
||||||
|
ProcessSession, // Create and accept Session requests.
|
||||||
// File system capabilities
|
// File system capabilities
|
||||||
FileEnum, // Enumerate directories and files
|
FileEnum, // Enumerate directories and files
|
||||||
FileRead, // Read files
|
FileRead, // Read files
|
||||||
FileWrite, // Write to files
|
FileWrite, // Write to files
|
||||||
FilePermission, // Modify file permissions
|
FilePermission, // Modify file permissions
|
||||||
FileCreate, // Create files
|
FileCreate, // Create files
|
||||||
FileDelete, // Delete files
|
FileDelete, // Delete files
|
||||||
FileSystem, // Mount, unmount, and modify filesystems
|
FileSystem, // Mount, unmount, and modify filesystems
|
||||||
// Kernel config capabilities
|
// Kernel config capabilities
|
||||||
KernelCfgRead, // Read kernel configurations
|
KernelCfgRead, // Read kernel configurations
|
||||||
KernelCfgWrite, // Modify 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
26
src/kernel/syscall.rs
Normal 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.
|
Loading…
Reference in New Issue
Block a user