1
0
Fork 0
forked from AbleOS/ableos
ableos-idl/kernel/src/holeybytes/ecah.rs

82 lines
2.1 KiB
Rust
Raw Normal View History

2023-10-27 20:26:04 -05:00
//! 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 r1 = vm.registers[1].cast::<u64>();
2023-10-27 20:26:04 -05:00
debug!("Ecall number {:?}", r1);
2023-10-27 20:26:04 -05:00
trace!("Register dump: {:?}", vm.registers);
match r1 {
2023-10-27 20:26:04 -05:00
0 => {
// TODO: explode computer
// hello world ecall
for x in 0u64..=255 {
vm.registers[x as usize] = x.into();
}
}
1 => {
// Make buffer
let bounded = match vm.registers[2].cast::<u64>() {
2023-10-27 20:26:04 -05:00
0 => false,
1 => true,
_ => {
panic!("Bad");
}
};
let length = vm.registers[3].cast::<u64>();
2023-10-27 20:26:04 -05:00
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 {:?}", r1);
2023-10-27 20:26:04 -05:00
}
}
}