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:
1
libxunil/.gitignore
vendored
Normal file
1
libxunil/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/target
|
||||
7
libxunil/Cargo.lock
generated
Normal file
7
libxunil/Cargo.lock
generated
Normal file
@@ -0,0 +1,7 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "libxunil"
|
||||
version = "0.1.0"
|
||||
12
libxunil/Cargo.toml
Normal file
12
libxunil/Cargo.toml
Normal file
@@ -0,0 +1,12 @@
|
||||
[package]
|
||||
name = "libxunil"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[lib]
|
||||
name = "xunil"
|
||||
crate-type = ["staticlib"]
|
||||
|
||||
[profile.release]
|
||||
panic = "abort"
|
||||
opt-level = "s"
|
||||
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
|
||||
}
|
||||
4
libxunil/tests/compile.sh
Normal file
4
libxunil/tests/compile.sh
Normal file
@@ -0,0 +1,4 @@
|
||||
gcc -nostdlib -nostdinc -static -no-pie \
|
||||
-o $1 $1.c \
|
||||
-L../target/release -l:libxunil.a
|
||||
mv $1 ../../assets/$1.elf
|
||||
7
libxunil/tests/helloworld.c
Normal file
7
libxunil/tests/helloworld.c
Normal file
@@ -0,0 +1,7 @@
|
||||
void write(int fd, const char* buf, unsigned long count);
|
||||
void exit(int code);
|
||||
|
||||
void _start() {
|
||||
write(1, "Hello from C!\n", 14);
|
||||
exit(0);
|
||||
}
|
||||
Reference in New Issue
Block a user