This commit is contained in:
2026-02-25 14:08:27 +01:00
parent 8a8034bd11
commit 4dc05c4151
23 changed files with 554 additions and 66 deletions

View File

@@ -1,7 +1,9 @@
use core::time::Duration;
use core::{alloc::Layout, time::Duration};
#[repr(u64)]
pub enum SysCall {
Alloc = 40,
Dealloc = 41,
Exit = 60,
NanoSleep = 101,
WriteIntTemp = 998,
@@ -12,6 +14,8 @@ pub enum SysCall {
impl From<u64> for SysCall {
fn from(value: u64) -> Self {
match value {
40 => SysCall::Alloc,
41 => SysCall::Dealloc,
60 => SysCall::Exit,
101 => SysCall::NanoSleep,
998 => SysCall::WriteIntTemp,
@@ -90,7 +94,7 @@ pub fn sleep(duration: Duration) {
}
}
pub fn write_string_temp(content: &'static str) {
pub fn write_string_temp(content: &str) {
unsafe {
syscall!(
SysCall::WriteTemp,
@@ -104,3 +108,19 @@ pub fn write_int_temp(content: u64) {
syscall!(SysCall::WriteIntTemp, content);
}
}
pub fn alloc(layout: Layout) -> *mut u8 {
unsafe {
let size = layout.size();
let align = layout.align();
let (ptr, ..) = syscall!(SysCall::Alloc, size as u64, align as u64);
ptr as *mut u8
}
}
pub fn dealloc(ptr: *mut u8, layout: core::alloc::Layout) {
unsafe {
let size = layout.size();
let align = layout.align();
syscall!(SysCall::Dealloc, ptr as u64, size as u64, align as u64);
}
}