From ea6ba3bdb0d4a114ed0b6d188cd53cd427e10094 Mon Sep 17 00:00:00 2001 From: Able Date: Tue, 23 Jul 2024 19:37:43 -0500 Subject: [PATCH] in/out b --- kernel/src/holeybytes/ecah.rs | 26 ++++++++++++++++------ repbuild/src/main.rs | 3 ++- sysdata/libraries/stn/src/memory.hb | 17 ++++++++++++++ sysdata/programs/diskio_driver/src/main.hb | 13 ++++++++--- sysdata/programs/tests/src/main.hb | 2 +- 5 files changed, 49 insertions(+), 12 deletions(-) diff --git a/kernel/src/holeybytes/ecah.rs b/kernel/src/holeybytes/ecah.rs index 846957b..59eb329 100644 --- a/kernel/src/holeybytes/ecah.rs +++ b/kernel/src/holeybytes/ecah.rs @@ -68,7 +68,7 @@ pub fn handler(vm: &mut Vm) { let buffer_id = vm.registers[3].cast::(); let mem_addr = vm.registers[4].cast::(); let length = vm.registers[5].cast::() as usize; - // debug!("IPC address: {:?}", mem_addr); + debug!("IPC address: {:?}", mem_addr); use alloc::vec::Vec; match buffer_id { @@ -89,10 +89,10 @@ pub fn handler(vm: &mut Vm) { // } 3 => { - unsafe fn x86_in(address: u16) -> u32 { + unsafe fn x86_in(address: u16) -> u8 { x86_64::instructions::port::Port::new(address).read() } - unsafe fn x86_out(address: u16, value: u32) { + unsafe fn x86_out(address: u16, value: u8) { x86_64::instructions::port::Port::new(address).write(value); } @@ -101,20 +101,32 @@ pub fn handler(vm: &mut Vm) { msg_vec.remove(0); match msg_type { 0 => { - let addr = msg_vec[0]; + let mut addr = msg_vec[0] as u16; msg_vec.remove(0); - let value = unsafe { x86_in(addr as u16) }; + + let addr2 = msg_vec[0] as u16; + msg_vec.remove(0); + + addr = ((addr) << 8) | addr2; + + let value = unsafe { x86_in(addr) }; info!("Read the value {} from address {}", value, addr); vm.registers[1] = hbvm::value::Value(value as u64); } 1 => { - let addr = msg_vec[0]; + let mut addr = msg_vec[0] as u16; msg_vec.remove(0); + + let addr2 = msg_vec[0] as u16; + msg_vec.remove(0); + + addr = ((addr) << 8) | addr2; + 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) }; + unsafe { x86_out(addr, value) }; } _ => {} } diff --git a/repbuild/src/main.rs b/repbuild/src/main.rs index 76be7f5..c308774 100644 --- a/repbuild/src/main.rs +++ b/repbuild/src/main.rs @@ -337,7 +337,8 @@ fn run(release: bool, target: Target) -> Result<(), Error> { "-m", "4G", "-smp", "cores=4", // "-enable-kvm", - "-cpu", "Broadwell-v4" + "-cpu", "Broadwell-v4", + "-device", "isa-debug-exit,iobase=0xf4,iosize=0x04" ]); } Target::Riscv64Virt => { diff --git a/sysdata/libraries/stn/src/memory.hb b/sysdata/libraries/stn/src/memory.hb index c3dddcb..fbbe80c 100644 --- a/sysdata/libraries/stn/src/memory.hb +++ b/sysdata/libraries/stn/src/memory.hb @@ -15,4 +15,21 @@ release_page := fn(ptr: ^u8, page_count: u8): void { *msg_ptr = ptr return @eca(void, 3, 2, msg, 12) +} + +outb := fn(addr_high: u8, addr_low: u8, value: u8): void { + msg := "\0\0\0\0"; + *msg = 1; + *(msg + 1) = addr_high; + *(msg + 2) = addr_low; + *(msg + 3) = value + @eca(void, 3, 3, msg, 4) + return +} + +inb := fn(addr_high: u8, addr_low: u8): u8 { + msg := "\0\0\0\0"; + *(msg + 1) = addr_high; + *(msg + 2) = addr_low + return @eca(u8, 3, 3, msg, 3) } \ No newline at end of file diff --git a/sysdata/programs/diskio_driver/src/main.hb b/sysdata/programs/diskio_driver/src/main.hb index 7493b26..d529528 100644 --- a/sysdata/programs/diskio_driver/src/main.hb +++ b/sysdata/programs/diskio_driver/src/main.hb @@ -1,5 +1,12 @@ +stn := @use("../../../libraries/stn/src/lib.hb"); +.{log, string, memory, buffer} := stn + main := fn(): int { - @eca(i32, 1, 1, 1); - - return 0; + // shuts down ableOS + memory.outb(0, 244, 0) + + a := memory.inb(0, 70) + b := memory.inb(0, 71) + + return 0 } \ No newline at end of file diff --git a/sysdata/programs/tests/src/main.hb b/sysdata/programs/tests/src/main.hb index 05bbc8a..a8dbc78 100644 --- a/sysdata/programs/tests/src/main.hb +++ b/sysdata/programs/tests/src/main.hb @@ -9,6 +9,6 @@ service_search := fn(): void { } main := fn(): int { - service_search() + //service_search() return 0 } \ No newline at end of file