From 1adc381399ae9f288738c4889a0088874b7123d2 Mon Sep 17 00:00:00 2001 From: Able Date: Mon, 15 Jul 2024 16:56:46 -0500 Subject: [PATCH] Hack in an inb/outb api --- kernel/src/holeybytes/ecah.rs | 31 ++++++++++++++++++++++++++++++ sysdata/programs/tests/src/main.hb | 8 ++++++++ 2 files changed, 39 insertions(+) diff --git a/kernel/src/holeybytes/ecah.rs b/kernel/src/holeybytes/ecah.rs index c42423dfc..fbf0f103a 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 277e4b846..942f9271e 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