forked from koniifer/ableos
in/out b
This commit is contained in:
parent
3f183e231d
commit
ea6ba3bdb0
|
@ -68,7 +68,7 @@ pub fn handler(vm: &mut Vm) {
|
|||
let buffer_id = vm.registers[3].cast::<u64>();
|
||||
let mem_addr = vm.registers[4].cast::<u64>();
|
||||
let length = vm.registers[5].cast::<u64>() 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) };
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
|
|
@ -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 => {
|
||||
|
|
|
@ -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)
|
||||
}
|
|
@ -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
|
||||
}
|
|
@ -9,6 +9,6 @@ service_search := fn(): void {
|
|||
}
|
||||
|
||||
main := fn(): int {
|
||||
service_search()
|
||||
//service_search()
|
||||
return 0
|
||||
}
|
Loading…
Reference in a new issue