Add userspace entry_point macro (#354)

* Add entry_point macro

* Simplify userspace programs with entry_point macro

* Fix tests
This commit is contained in:
Vincent Ollivier 2022-06-16 21:40:00 +02:00 committed by GitHub
parent 783a41981d
commit cbf115b781
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 38 additions and 62 deletions

View File

@ -1,3 +1,23 @@
#[cfg(not(test))]
#[macro_export]
macro_rules! entry_point {
($path:path) => {
#[panic_handler]
fn panic(_info: &core::panic::PanicInfo) -> ! {
$crate::api::syscall::write(1, b"An exception occured!\n");
loop {}
}
#[export_name = "_start"]
pub unsafe extern "sysv64" fn __impl_start(args_ptr: u64, args_len: usize) {
let args = core::slice::from_raw_parts(args_ptr as *const _, args_len);
let f: fn(&[&str]) -> usize = $path;
let code = f(args);
$crate::api::syscall::exit(code);
}
};
}
#[macro_export]
macro_rules! print {
($($arg:tt)*) => ({

View File

@ -2,16 +2,11 @@
#![no_main]
use moros::api::syscall;
use core::panic::PanicInfo;
use moros::entry_point;
#[panic_handler]
fn panic(_info: &PanicInfo) -> ! {
syscall::write(1, b"An exception occured!\n");
loop {}
}
entry_point!(main);
#[no_mangle]
pub unsafe extern "sysv64" fn _start() {
fn main(_args: &[&str]) -> usize {
syscall::write(1, b"\x1b[2J\x1b[1;1H"); // Clear screen and move cursor to top
syscall::exit(0);
0
}

View File

@ -2,17 +2,11 @@
#![no_main]
use moros::api::syscall;
use moros::entry_point;
use core::panic::PanicInfo;
entry_point!(main);
#[panic_handler]
fn panic(_info: &PanicInfo) -> ! {
syscall::write(1, b"An exception occured!\n");
loop {}
}
#[no_mangle]
pub unsafe extern "sysv64" fn _start() {
fn main(_args: &[&str]) -> usize {
syscall::write(1, b"\x1b[93m"); // Yellow
syscall::write(1, b"MOROS has reached its fate, the system is now halting.\n");
syscall::write(1, b"\x1b[0m"); // Reset

View File

@ -2,16 +2,11 @@
#![no_main]
use moros::api::syscall;
use core::panic::PanicInfo;
use moros::entry_point;
#[panic_handler]
fn panic(_info: &PanicInfo) -> ! {
syscall::write(1, b"An exception occured!\n");
loop {}
}
entry_point!(main);
#[no_mangle]
pub unsafe extern "sysv64" fn _start() {
fn main(_args: &[&str]) -> usize {
syscall::write(1, b"Hello, World!\n");
syscall::exit(0);
0
}

View File

@ -1,21 +1,10 @@
#![no_std]
#![no_main]
use moros::entry_point;
use moros::api::syscall;
use core::panic::PanicInfo;
#[panic_handler]
fn panic(_info: &PanicInfo) -> ! {
syscall::write(1, b"An exception occured!\n");
loop {}
}
#[no_mangle]
pub unsafe extern "sysv64" fn _start(args_ptr: u64, args_len: usize) {
let args = core::slice::from_raw_parts(args_ptr as *const _, args_len);
let code = main(args);
syscall::exit(code);
}
entry_point!(main);
fn main(args: &[&str]) -> usize {
let n = args.len();

View File

@ -2,17 +2,11 @@
#![no_main]
use moros::api::syscall;
use moros::entry_point;
use core::panic::PanicInfo;
entry_point!(main);
#[panic_handler]
fn panic(_info: &PanicInfo) -> ! {
syscall::write(1, b"An exception occured!\n");
loop {}
}
#[no_mangle]
pub unsafe extern "sysv64" fn _start() {
fn main(_args: &[&str]) -> usize {
syscall::write(1, b"\x1b[93m"); // Yellow
syscall::write(1, b"MOROS has reached its fate, the system is now rebooting.\n");
syscall::write(1, b"\x1b[0m"); // Reset

View File

@ -2,20 +2,9 @@
#![no_main]
use moros::api::syscall;
use core::panic::PanicInfo;
use moros::entry_point;
#[panic_handler]
fn panic(_info: &PanicInfo) -> ! {
syscall::write(1, b"An exception occured!\n");
loop {}
}
#[no_mangle]
pub unsafe extern "sysv64" fn _start(args_ptr: u64, args_len: usize) {
let args = core::slice::from_raw_parts(args_ptr as *const _, args_len);
let code = main(args);
syscall::exit(code);
}
entry_point!(main);
fn main(args: &[&str]) -> usize {
if args.len() == 2 {