diff --git a/kernel/src/holeybytes/ecah.rs b/kernel/src/holeybytes/ecah.rs index c42423df..fbf0f103 100644 --- a/kernel/src/holeybytes/ecah.rs +++ b/kernel/src/holeybytes/ecah.rs @@ -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(); diff --git a/sysdata/programs/tests/src/main.hb b/sysdata/programs/tests/src/main.hb index 277e4b84..942f9271 100644 --- a/sysdata/programs/tests/src/main.hb +++ b/sysdata/programs/tests/src/main.hb @@ -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; } \ No newline at end of file