kernel: support receiving process arguments

Support passing process arguments in register 2 as part of arguments to
a process.

This requires updating the `InitialProcess` struct that is received from
the loader, and so requires modeifications to be made in tandem.

Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
Sean Cross 2024-01-07 22:44:51 +08:00
parent d8c6881554
commit 60f2a17649
2 changed files with 16 additions and 14 deletions

View file

@ -127,6 +127,9 @@ pub struct InitialProcess {
/// Address of the top of the stack
pub sp: usize,
/// Address of the environment block
pub env: usize,
}
impl InitialProcess {

View file

@ -31,8 +31,6 @@ const MINIELF_FLG_NC: u8 = 2;
const MINIELF_FLG_X: u8 = 4;
#[cfg(baremetal)]
const MINIELF_FLG_EHF: u8 = 8;
#[cfg(baremetal)]
const MINIELF_FLG_EHH: u8 = 0x10;
#[derive(Debug, Copy, Clone, PartialEq)]
pub struct ExceptionHandler {
@ -414,25 +412,26 @@ impl SystemServices {
// - Process #1 is the kernel
// Any changes to this will break this code!
let mut eh_frame = 0;
let mut eh_frame_size = 0;
let mut eh_frame_header = 0;
let mut eh_frame_header_size = 0;
if let Some(arg) = arg_iter.next() {
for section in arg.data.chunks_exact(2) {
let flags = (section[1] >> 24) as u8;
if flags & MINIELF_FLG_EHF != 0 {
eh_frame = section[0];
eh_frame_size = section[1] & 0xFF_FFFF;
} else if flags & MINIELF_FLG_EHH != 0 {
eh_frame_header = section[0];
eh_frame_header_size = section[1] & 0xFF_FFFF;
}
}
}
let arg0 = eh_frame as _;
#[cfg(target_arch = "riscv32")]
let arg1 = init.env as _;
#[cfg(not(target_arch = "riscv32"))]
let arg1 = 0;
let arg2 = 0;
let arg3 = 0;
// end of assumption area
process.state = ProcessState::Setup(ThreadInit::new(
unsafe { core::mem::transmute::<usize, _>(init.entrypoint) },
init.entrypoint as _,
unsafe {
MemoryRange::new(
init.sp - crate::arch::process::DEFAULT_STACK_SIZE,
@ -440,10 +439,10 @@ impl SystemServices {
)
.unwrap()
},
eh_frame as _,
eh_frame_size as _,
eh_frame_header as _,
eh_frame_header_size as _,
arg0,
arg1,
arg2,
arg3,
));
}
// log_process_update(file!(), line!(), process, old_state);