forked from AbleOS/ableos
87 lines
2.4 KiB
Rust
87 lines
2.4 KiB
Rust
|
//! Environment call handling routines
|
||
|
|
||
|
use {
|
||
|
super::{mem::Memory, Vm},
|
||
|
crate::{arch, ipc::buffer::IpcBuffer, kmain::IPC_BUFFERS},
|
||
|
log::{debug, error, info, trace, warn},
|
||
|
};
|
||
|
|
||
|
pub fn handler(vm: &mut Vm) {
|
||
|
let r255 = vm.registers[255].cast::<u64>();
|
||
|
let r254 = vm.registers[254].cast::<u64>();
|
||
|
let r253 = vm.registers[253].cast::<u64>();
|
||
|
|
||
|
debug!("Ecall number {:?}", r255);
|
||
|
trace!("Register dump: {:?}", vm.registers);
|
||
|
|
||
|
match r255 {
|
||
|
0 => {
|
||
|
// TODO: explode computer
|
||
|
// hello world ecall
|
||
|
for x in 0u64..=255 {
|
||
|
vm.registers[x as usize] = x.into();
|
||
|
}
|
||
|
}
|
||
|
1 => {
|
||
|
// Make buffer
|
||
|
let r255 = vm.registers[255].cast::<u64>();
|
||
|
let r254 = vm.registers[254].cast::<u64>();
|
||
|
let r253 = vm.registers[253].cast::<u64>();
|
||
|
|
||
|
let bounded = match r254 {
|
||
|
0 => false,
|
||
|
1 => true,
|
||
|
_ => {
|
||
|
panic!("Bad");
|
||
|
}
|
||
|
};
|
||
|
|
||
|
let length = r254;
|
||
|
|
||
|
let mut buffs = IPC_BUFFERS.lock();
|
||
|
let abc;
|
||
|
|
||
|
match bounded {
|
||
|
false => {
|
||
|
abc = IpcBuffer::new(false, 0);
|
||
|
}
|
||
|
true => {
|
||
|
abc = IpcBuffer::new(true, length);
|
||
|
}
|
||
|
};
|
||
|
let buff_id = arch::hardware_random_u64();
|
||
|
buffs.insert(buff_id, abc);
|
||
|
debug!("Buffer ID: {}", buff_id);
|
||
|
}
|
||
|
2 => {
|
||
|
// Delete buffer
|
||
|
}
|
||
|
3 => {
|
||
|
// Send a message to a buffer
|
||
|
let r254 = vm.registers[254].cast::<u64>();
|
||
|
let r253 = vm.registers[253].cast::<u64>();
|
||
|
let r252 = vm.registers[252].cast::<u64>();
|
||
|
|
||
|
let buffer_id = r254;
|
||
|
let mem_addr = r253;
|
||
|
let length = r252 as usize;
|
||
|
trace!("IPC address: {:?}", mem_addr);
|
||
|
use alloc::vec::Vec;
|
||
|
|
||
|
match buffer_id {
|
||
|
1 => {
|
||
|
error!("Logging via IPC isn't quite ready")
|
||
|
}
|
||
|
buffer_id => {
|
||
|
info!("Message has been sent to {}", buffer_id)
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
// 4
|
||
|
// 5
|
||
|
_ => {
|
||
|
log::error!("Syscall unknown {:?}", r255)
|
||
|
}
|
||
|
}
|
||
|
}
|