better inb, outb, mayhaps fix some bugs

This commit is contained in:
koniifer 2024-08-31 00:50:12 +01:00
parent f32d66e50e
commit d9dd42d9c3
7 changed files with 89 additions and 87 deletions

View file

@ -86,7 +86,6 @@ pub fn handler(vm: &mut Vm) {
Ok(_) => {}
Err(_) => {}
}
//
}
3 => {
unsafe fn x86_in(address: u16) -> u8 {
@ -115,64 +114,70 @@ pub fn handler(vm: &mut Vm) {
// XY\0\0V
// X = 0: Read, 1: Write
// Y = 0: 8bit, 1: 16bit, 2: 32bit
// \0\0 = Port Low, Port High
// \0 = Port
// V = Value
0 => {
0 => 'wow: {
// info!("inb");
let size = msg_vec[0];
if size <= 2 {
msg_vec.remove(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 = unsafe {
match size {
0 => x86_in(addr) as u32,
1 => x86_in_16(addr) as u32,
2 => x86_in_32(addr),
_ => panic!("how?"),
}
};
trace!("Read the value {} from address {}", value, addr);
vm.registers[1] = hbvm::value::Value(value as u64);
} else {
error!("Tried to read more than 32 bits.")
}
}
1 => {
// info!("outb");
let size = msg_vec[0];
if size <= 2 {
msg_vec.remove(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 mut value: u32 = 0;
for x in 0..=size {
value |= ((unsafe { msg_vec[0] as u32 }) << size - x) & 255;
msg_vec.remove(0);
let size = match msg_vec[0] {
0 => 1,
1 => 2,
2 => 4,
_ => {
error!("Tried to write more than 32 bits");
break 'wow;
}
};
msg_vec.remove(0);
let addr = ((msg_vec[0] as u16) << 8) + msg_vec[1] as u16;
msg_vec.remove(0);
msg_vec.remove(0);
let value = unsafe {
match size {
1 => x86_in(addr) as u64,
2 => x86_in_16(addr) as u64,
4 => x86_in_32(addr) as u64,
_ => panic!("how?"),
}
};
msg_vec.clear();
trace!("Read the value {} from address {}", value, addr);
vm.registers[1] = hbvm::value::Value(value);
}
1 => 'wow: {
let size = match msg_vec[0] {
0 => 1,
1 => 2,
2 => 4,
_ => {
error!("Tried to write more than 32 bits");
break 'wow;
}
};
msg_vec.remove(0);
let addr = ((msg_vec[0] as u16) << 8) + msg_vec[1] as u16;
msg_vec.remove(0);
msg_vec.remove(0);
trace!("Setting address {}", addr);
unsafe {
match size {
1 => x86_out(addr, msg_vec[0]),
2 => x86_out_16(
addr,
core::mem::transmute::<[u8; 2], u16>(
msg_vec[0..2].try_into().unwrap(),
),
),
4 => x86_out_32(
addr,
core::mem::transmute::<[u8; 4], u32>(
msg_vec[0..4].try_into().unwrap(),
),
),
_ => panic!("How?"),
}
trace!("Setting the address {} to {}", addr, value);
unsafe {
match size {
0 => x86_out(addr, value as u8),
1 => x86_out_16(addr, value as u16),
2 => x86_out_32(addr, value),
_ => panic!("how?"),
}
};
} else {
error!("Tried to write more than 32 bits.")
}
msg_vec.clear();
}
_ => {}
}

View file

@ -7,14 +7,15 @@ get_vendor_id := fn(bus: u8, device: u8, function: u8): u16 {
}
pci_config_read_word := fn(bus: u8, slot: u8, func: u8, offset: u8): u16 {
address := @as(u32, 0)
lbus := @as(u32, bus)
lslot := @as(u32, slot)
lfunc := @as(u32, func)
tmp := 0
tmp := @as(u16, 0)
address := @as(u32, lbus << 16 | lslot << 11 | lfunc << 8 | offset & 2522 | @as(u32, 1 << 31))
memory.outl(address, address + 4, 3320)
tmp = @as(u16, memory.inl(3324, 3328) >> (offset & 2) * 8 & 65535)
address = @as(u32, lbus << 16 | lslot << 1 | lfunc << 8 | offset & 252 | @as(u32, 2147483648))
memory.outl(address, 3320)
tmp = @as(u16, memory.inl(3324) >> (offset & 2) * 8 & 65535)
return tmp
}

View file

@ -17,32 +17,29 @@ release_page := fn(ptr: ^u8, page_count: u8): void {
return @eca(void, 3, 2, msg, 12)
}
outb := fn(addr_low: u8, addr_high: u8, value: u8): void {
outb := fn(addr: u16, value: u8): void {
msg := "\0\0\0\0\0";
*msg = 1;
*(msg + 1) = 0;
*(msg + 2) = addr_low;
*(msg + 3) = addr_high;
*@as(^u16, @bitcast(msg + 2)) = addr;
*(msg + 4) = value
@eca(void, 3, 3, msg, 5)
return
}
inb := fn(addr_low: u8, addr_high: u8): u8 {
inb := fn(addr: u16): u8 {
msg := "\0\0\0\0";
*msg = 0;
*(msg + 1) = 0;
*(msg + 2) = addr_low;
*(msg + 3) = addr_high
*@as(^u16, @bitcast(msg + 2)) = addr
return @eca(u8, 3, 3, msg, 4)
}
outl := fn(addr_low: u8, addr_high: u8, value: u32): void {
outl := fn(addr: u16, value: u32): void {
msg := "\0\0\0\0\0\0\0\0";
*msg = 1;
*(msg + 1) = 2;
*(msg + 2) = addr_low;
*(msg + 3) = addr_high;
*@as(^u16, @bitcast(msg + 2)) = addr;
*(msg + 4) = value >> 24 & 255;
*(msg + 5) = value >> 16 & 255;
*(msg + 6) = value >> 8 & 255;
@ -51,11 +48,10 @@ outl := fn(addr_low: u8, addr_high: u8, value: u32): void {
return
}
inl := fn(addr_low: u8, addr_high: u8): u32 {
inl := fn(addr: u16): u32 {
msg := "\0\0\0\0";
*msg = 0;
*(msg + 1) = 2;
*(msg + 2) = addr_low;
*(msg + 3) = addr_high
*@as(^u16, @bitcast(msg + 2)) = addr
return @eca(u32, 3, 3, msg, 4)
}

View file

@ -5,7 +5,7 @@ serial_print := fn(ptr: ^u8): void {
letter := 0
loop if *ptr == 0 break else {
letter = *ptr
memory.outb(3, 248, letter)
memory.outb(63491, letter)
ptr += 1
}
return
@ -13,8 +13,8 @@ serial_print := fn(ptr: ^u8): void {
serial_println := fn(ptr: ^u8): void {
serial_print(ptr)
memory.outb(3, 248, 12)
memory.outb(3, 248, 13)
memory.outb(63491, 12)
memory.outb(63491, 13)
return
}

View file

@ -3,10 +3,10 @@ stn := @use("../../../libraries/stn/src/lib.hb");
main := fn(): int {
// shuts down ableOS
//memory.outb(0, 244, 0)
//memory.outb(62464, 0)
a := memory.inb(0, 70)
b := memory.inb(0, 71)
a := memory.inb(17920)
b := memory.inb(18176)
c := buffer.search("XNumber\0")

View file

@ -1,8 +1,8 @@
.{memory, log, string, buffer} := @use("../../../libraries/stn/src/lib.hb")
send_byte := fn(byte: u8): u8 {
memory.outb(0, 96, byte)
return memory.inb(0, 96)
memory.outb(24576, byte)
return memory.inb(24576)
}
main := fn(): int {
@ -17,7 +17,7 @@ main := fn(): int {
ptr := memory.request_page(1)
prev_input := 250
loop {
input := memory.inb(0, 96)
input := memory.inb(24576)
if input == prev_input {
continue
}

View file

@ -9,12 +9,12 @@
main := fn(): void {
// check_all_buses()
bus := 0
slot := 0
a := memory.request_page(1)
loop if bus >= 256 break else {
b := pci_config_read_word(bus, 0, 0, 2)
log.info(string.display_int(b, a))
bus += 1
}
// slot := 0
// a := memory.request_page(1)
// loop if bus >= 256 break else {
// b := pci_config_read_word(bus, 0, 0, 0)
// log.info(string.display_int(b, a))
// bus += 1
// }
return
}