mirror of
https://github.com/XunilGroup/XunilOS.git
synced 2026-04-25 19:59:02 +02:00
Add ET_EXEC ELF loading and validation, and a non-working ET_REL
implementation, running support, also basic syscalls to test if it works. add a syscall ABI and a new libxunil ABI for calling back to the kernel with syscalls, add user mode protection when running ELF, add TSS Privilege Stack table to fix GPF issues, add invalid opcode handler, fix rust panics using rectangle_filled instead of fb clear. Also add a hello world example binary that runs in usermode at startup.
This commit is contained in:
41
libxunil/src/lib.rs
Normal file
41
libxunil/src/lib.rs
Normal file
@@ -0,0 +1,41 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use crate::syscall::syscall3;
|
||||
|
||||
pub mod syscall;
|
||||
|
||||
const SYS_EXIT: usize = 1;
|
||||
const SYS_WRITE: usize = 60;
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
extern "C" fn write(fd: i32, buf: *const u8, count: usize) -> isize {
|
||||
unsafe { syscall3(SYS_WRITE, fd as usize, buf as usize, count) }
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
extern "C" fn exit(code: i32) -> ! {
|
||||
unsafe { syscall3(SYS_EXIT, code as usize, 0, 0) };
|
||||
loop {}
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
extern "C" fn strlen(s: *const u8) -> usize {
|
||||
let mut len = 0;
|
||||
while unsafe { *s.add(len) } != 0 {
|
||||
len += 1;
|
||||
}
|
||||
len
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
extern "C" fn puts(s: *const u8) -> isize {
|
||||
write(1, s, strlen(s));
|
||||
|
||||
0
|
||||
}
|
||||
|
||||
#[panic_handler]
|
||||
fn panic(_: &core::panic::PanicInfo) -> ! {
|
||||
loop {}
|
||||
}
|
||||
32
libxunil/src/syscall.rs
Normal file
32
libxunil/src/syscall.rs
Normal file
@@ -0,0 +1,32 @@
|
||||
#[inline(always)]
|
||||
pub unsafe fn syscall0(num: usize) -> isize {
|
||||
let ret: isize;
|
||||
unsafe {
|
||||
core::arch::asm!(
|
||||
"int 0x80",
|
||||
in("rax") num,
|
||||
lateout("rax") ret,
|
||||
options(nostack)
|
||||
);
|
||||
}
|
||||
|
||||
ret
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub unsafe fn syscall3(num: usize, arg0: usize, arg1: usize, arg2: usize) -> isize {
|
||||
let ret: isize;
|
||||
unsafe {
|
||||
core::arch::asm!(
|
||||
"int 0x80",
|
||||
in("rax") num,
|
||||
in("rdi") arg0,
|
||||
in("rsi") arg1,
|
||||
in("rdx") arg2,
|
||||
lateout("rax") ret,
|
||||
options(nostack)
|
||||
);
|
||||
}
|
||||
|
||||
ret
|
||||
}
|
||||
Reference in New Issue
Block a user