diff --git a/etc/aarch64-osdev5.ld b/etc/aarch64-osdev5.ld index 00a2580..b9be323 100644 --- a/etc/aarch64-osdev5.ld +++ b/etc/aarch64-osdev5.ld @@ -12,6 +12,7 @@ SECTIONS { .text : { *(.text._start) *(.text*) + *(.eh_frame*) } :text . = ALIGN(0x1000); diff --git a/init/src/main.rs b/init/src/main.rs index fbf3456..a49088f 100644 --- a/init/src/main.rs +++ b/init/src/main.rs @@ -7,30 +7,5 @@ extern crate libusr; #[no_mangle] fn main() -> i32 { - let mut buf = [0; 128]; - - print!("\x1B[2J\x1B[1;1H"); - println!("Hello!"); - - loop { - print!("> "); - - let count = unsafe { libusr::sys::sys_read(0, &mut buf) }; - if count < 0 { - trace!("Read from stdio failed"); - break; - } - let count = count as usize; - - if let Ok(s) = core::str::from_utf8(&buf[..count]) { - println!("Got string {:?}", s); - - if s == "quit" { - break; - } - } else { - println!("Got string (non-utf8) {:?}", &buf[..count]); - } - } -1 } diff --git a/kernel/src/proc/process.rs b/kernel/src/proc/process.rs index 7ec4a83..79dd6f7 100644 --- a/kernel/src/proc/process.rs +++ b/kernel/src/proc/process.rs @@ -405,6 +405,12 @@ impl Process { unsafe { SCHED.hack_current_pid(lock.id); } + } else { + // Invalidate user ASID + let input = (lock.id.asid() as usize) << 48; + unsafe { + asm!("tlbi aside1, {}", in(reg) input); + } } let new_space = Space::alloc_empty()?; diff --git a/kernel/src/syscall/mod.rs b/kernel/src/syscall/mod.rs index d890406..1cf8b27 100644 --- a/kernel/src/syscall/mod.rs +++ b/kernel/src/syscall/mod.rs @@ -2,7 +2,7 @@ use crate::arch::platform::exception::ExceptionFrame; use crate::debug::Level; -use crate::proc::{wait, Pid, Process}; +use crate::proc::{elf, wait, Pid, Process}; use core::mem::size_of; use core::time::Duration; use error::Errno; @@ -91,6 +91,20 @@ pub fn syscall(num: usize, args: &[usize]) -> Result { io.close_file(fd)?; Ok(0) } + abi::SYS_EXECVE => { + let node = { + let proc = Process::current(); + let mut io = proc.io.lock(); + let filename = validate_user_str(args[0], args[1])?; + // TODO argv, envp array passing ABI? + let node = io.ioctx().find(None, filename, true)?; + drop(io); + node + }; + let mut file = node.open(OpenFlags::O_RDONLY)?; + Process::execve(|space| elf::load_elf(space, &mut file), 0).unwrap(); + panic!(); + } // Extra system calls abi::SYS_EX_DEBUG_TRACE => { diff --git a/syscall/src/abi.rs b/syscall/src/abi.rs index 1186086..ffb6e34 100644 --- a/syscall/src/abi.rs +++ b/syscall/src/abi.rs @@ -9,3 +9,4 @@ pub const SYS_OPENAT: usize = 4; pub const SYS_FSTATAT: usize = 5; pub const SYS_CLOSE: usize = 6; pub const SYS_FORK: usize = 7; +pub const SYS_EXECVE: usize = 8; diff --git a/syscall/src/calls.rs b/syscall/src/calls.rs index c5d5d75..c63a6f5 100644 --- a/syscall/src/calls.rs +++ b/syscall/src/calls.rs @@ -1,5 +1,5 @@ use crate::abi; -use crate::stat::{Stat, OpenFlags, FileMode}; +use crate::stat::{FileMode, OpenFlags, Stat}; // TODO document the syscall ABI @@ -48,11 +48,15 @@ macro_rules! syscall { /// Integer/size argument macro_rules! argn { - ($a:expr) => ($a as usize) + ($a:expr) => { + $a as usize + }; } /// Pointer/base argument macro_rules! argp { - ($a:expr) => ($a as *mut core::ffi::c_void as usize) + ($a:expr) => { + $a as *mut core::ffi::c_void as usize + }; } // /// Immutable pointer/base argument // macro_rules! argpi { @@ -77,7 +81,11 @@ pub unsafe fn sys_ex_nanosleep(ns: u64, rem: &mut [u64; 2]) -> i32 { #[inline(always)] pub unsafe fn sys_ex_debug_trace(msg: &[u8]) -> usize { - syscall!(abi::SYS_EX_DEBUG_TRACE, argp!(msg.as_ptr()), argn!(msg.len())) + syscall!( + abi::SYS_EX_DEBUG_TRACE, + argp!(msg.as_ptr()), + argn!(msg.len()) + ) } #[inline(always)] @@ -94,12 +102,22 @@ pub unsafe fn sys_openat(at: i32, pathname: &str, mode: FileMode, flags: OpenFla #[inline(always)] pub unsafe fn sys_read(fd: i32, data: &mut [u8]) -> isize { - syscall!(abi::SYS_READ, argn!(fd), argp!(data.as_mut_ptr()), argn!(data.len())) as isize + syscall!( + abi::SYS_READ, + argn!(fd), + argp!(data.as_mut_ptr()), + argn!(data.len()) + ) as isize } #[inline(always)] pub unsafe fn sys_write(fd: i32, data: &[u8]) -> isize { - syscall!(abi::SYS_WRITE, argn!(fd), argp!(data.as_ptr()), argn!(data.len())) as isize + syscall!( + abi::SYS_WRITE, + argn!(fd), + argp!(data.as_ptr()), + argn!(data.len()) + ) as isize } #[inline(always)] @@ -118,3 +136,12 @@ pub unsafe fn sys_fstatat(at: i32, pathname: &str, statbuf: &mut Stat, flags: i3 pub unsafe fn sys_fork() -> i32 { syscall!(abi::SYS_FORK) as i32 } + +#[inline(always)] +pub unsafe fn sys_execve(pathname: &str) -> i32 { + syscall!( + abi::SYS_EXECVE, + argp!(pathname.as_ptr()), + argn!(pathname.len()) + ) as i32 +}