Hack in an inb/outb api

This commit is contained in:
Able 2024-07-15 16:56:46 -05:00
parent f33cc0bf70
commit 1adc381399
2 changed files with 39 additions and 0 deletions

View file

@ -88,6 +88,37 @@ pub fn handler(vm: &mut Vm) {
}
//
}
3 => {
unsafe fn x86_in(address: u16) -> u32 {
x86_64::instructions::port::Port::new(address).read()
}
unsafe fn x86_out(address: u16, value: u32) {
x86_64::instructions::port::Port::new(address).write(value);
}
let mut msg_vec = block_read(mem_addr, length);
let msg_type = msg_vec[0];
msg_vec.remove(0);
match msg_type {
0 => {
let addr = msg_vec[0];
msg_vec.remove(0);
let value = unsafe { x86_in(addr as u16) };
info!("Read the value {} from address {}", value, addr);
vm.registers[1] = hbvm::value::Value(value as u64);
}
1 => {
let addr = msg_vec[0];
msg_vec.remove(0);
let value = msg_vec[0];
msg_vec.remove(0);
info!("Setting the address {} to {}", addr, value);
unsafe { x86_out(addr as u16, value as u32) };
}
_ => {}
}
}
buffer_id => {
let mut buffs = IPC_BUFFERS.lock();

View file

@ -16,5 +16,13 @@ main := fn(): int {
memory.release_page(memory_pages, 3);
// todo: abstract this out
port_str := "\0\{70}\0";
a := @eca(u8, 3, 3, port_str, 2);
return 0;
}