diff --git a/kernel/src/arch/x86_64/pci/mod.rs b/kernel/src/arch/x86_64/pci/mod.rs index 5e2bbe7..b02c183 100644 --- a/kernel/src/arch/x86_64/pci/mod.rs +++ b/kernel/src/arch/x86_64/pci/mod.rs @@ -12,7 +12,8 @@ use crate::alloc::string::ToString; /// Enumerate PCI devices and run initialisation routines on ones we support pub fn init(device_tree: &mut DeviceTree) { - device_tree.devices + device_tree + .devices .insert("Unidentified PCI".to_string(), alloc::vec![]); let mut devices = alloc::vec![]; @@ -23,6 +24,7 @@ pub fn init(device_tree: &mut DeviceTree) { let id = device_info.device_id.id; use Vendor::*; let (dev_type, dev_name) = match (vendor, id) { + (VMWareInc, 1029) => ("GPUs", "SVGAII PCI GPU"), (Qemu, 4369) => ("GPUs", "QEMU VGA"), (VirtIO, 4176) => ("GPUs", "VirtIO PCI GPU"), (CirrusLogic, 184) => ("GPUs", "Cirrus SVGA"), //GD 5446? @@ -269,8 +271,7 @@ impl Display for Vendor { use core::fmt::Display; -use x86_64::instructions::port::Port; -use crate::device_tree::DeviceTree; +use {crate::device_tree::DeviceTree, x86_64::instructions::port::Port}; #[allow(non_camel_case_types, dead_code)] #[derive(Debug, Clone, Copy, PartialEq)] diff --git a/kernel/src/holeybytes/ecah.rs b/kernel/src/holeybytes/ecah.rs index 516ae2d..d0202cf 100644 --- a/kernel/src/holeybytes/ecah.rs +++ b/kernel/src/holeybytes/ecah.rs @@ -86,47 +86,98 @@ pub fn handler(vm: &mut Vm) { Ok(_) => {} Err(_) => {} } - // } 3 => { unsafe fn x86_in(address: u16) -> u8 { x86_64::instructions::port::Port::new(address).read() } + unsafe fn x86_in_16(address: u16) -> u16 { + x86_64::instructions::port::Port::new(address).read() + } + unsafe fn x86_in_32(address: u16) -> u32 { + x86_64::instructions::port::Port::new(address).read() + } unsafe fn x86_out(address: u16, value: u8) { x86_64::instructions::port::Port::new(address).write(value); } + unsafe fn x86_out_16(address: u16, value: u16) { + x86_64::instructions::port::Port::new(address).write(value); + } + unsafe fn x86_out_32(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 mut addr = msg_vec[0] as u16; + // XY\0\0V + // X = 0: Read, 1: Write + // Y = 0: 8bit, 1: 16bit, 2: 32bit + // \0 = Port + // V = Value + 0 => 'wow: { + // info!("inb"); + 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 addr2 = msg_vec[0] as u16; + let addr = ((msg_vec[0] as u16) << 8) + msg_vec[1] as u16; msg_vec.remove(0); - - addr = ((addr) << 8) | addr2; - - let value = unsafe { x86_in(addr) }; - + 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 as u64); + vm.registers[1] = hbvm::value::Value(value); } - 1 => { - let mut addr = msg_vec[0] as u16; + 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 addr2 = msg_vec[0] as u16; + let addr = ((msg_vec[0] as u16) << 8) + msg_vec[1] as u16; msg_vec.remove(0); - - addr = ((addr) << 8) | addr2; - - let value = msg_vec[0]; msg_vec.remove(0); - trace!("Setting the address {} to {}", addr, value); - unsafe { x86_out(addr, value) }; + 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?"), + } + } + msg_vec.clear(); } _ => {} } @@ -147,7 +198,7 @@ pub fn handler(vm: &mut Vm) { msg_vec.push(value); } buff.push(msg_vec.clone()); - info!( + debug!( "Message {:?} has been sent to Buffer({})", msg_vec, buffer_id ); @@ -191,7 +242,7 @@ pub fn handler(vm: &mut Vm) { } } - info!("Recieve {:?} from Buffer({})", msg, buffer_id); + debug!("Recieve {:?} from Buffer({})", msg, buffer_id); } } 5 => { diff --git a/kernel/src/logger.rs b/kernel/src/logger.rs index 3431775..b403fa9 100644 --- a/kernel/src/logger.rs +++ b/kernel/src/logger.rs @@ -9,7 +9,11 @@ use { pub fn init() -> Result<(), SetLoggerError> { log::set_logger(&crate::logger::Logger)?; - log::set_max_level(log::LevelFilter::Debug); + if cfg!(debug_assertions) { + log::set_max_level(log::LevelFilter::Debug); + } else { + log::set_max_level(log::LevelFilter::Info); + } Lazy::force(&TERMINAL_LOGGER); diff --git a/sysdata/libraries/stn/src/memory.hb b/sysdata/libraries/stn/src/memory.hb index fbbe80c..5e70120 100644 --- a/sysdata/libraries/stn/src/memory.hb +++ b/sysdata/libraries/stn/src/memory.hb @@ -17,19 +17,41 @@ release_page := fn(ptr: ^u8, page_count: u8): void { return @eca(void, 3, 2, msg, 12) } -outb := fn(addr_high: u8, addr_low: u8, value: u8): void { - msg := "\0\0\0\0"; +outb := fn(addr: u16, value: u8): void { + msg := "\0\0\0\0\0"; *msg = 1; - *(msg + 1) = addr_high; - *(msg + 2) = addr_low; - *(msg + 3) = value - @eca(void, 3, 3, msg, 4) + *(msg + 1) = 0; + *@as(^u16, @bitcast(msg + 2)) = addr; + *(msg + 4) = value + @eca(void, 3, 3, msg, 5) return } -inb := fn(addr_high: u8, addr_low: u8): u8 { +inb := fn(addr: u16): u8 { msg := "\0\0\0\0"; - *(msg + 1) = addr_high; - *(msg + 2) = addr_low - return @eca(u8, 3, 3, msg, 3) + *msg = 0; + *(msg + 1) = 0; + *@as(^u16, @bitcast(msg + 2)) = addr + return @eca(u8, 3, 3, msg, 4) +} + +outl := fn(addr: u16, value: u32): void { + msg := "\0\0\0\0\0\0\0\0"; + *msg = 1; + *(msg + 1) = 2; + *@as(^u16, @bitcast(msg + 2)) = addr; + *(msg + 4) = value >> 24 & 255; + *(msg + 5) = value >> 16 & 255; + *(msg + 6) = value >> 8 & 255; + *(msg + 7) = value & 255 + @eca(void, 3, 3, msg, 8) + return +} + +inl := fn(addr: u16): u32 { + msg := "\0\0\0\0"; + *msg = 0; + *(msg + 1) = 2; + *@as(^u16, @bitcast(msg + 2)) = addr + return @eca(u32, 3, 3, msg, 4) } \ No newline at end of file diff --git a/sysdata/programs/a_serial_driver/src/main.hb b/sysdata/programs/a_serial_driver/src/main.hb index 6ec614e..5a96acd 100644 --- a/sysdata/programs/a_serial_driver/src/main.hb +++ b/sysdata/programs/a_serial_driver/src/main.hb @@ -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 } diff --git a/sysdata/programs/diskio_driver/src/main.hb b/sysdata/programs/diskio_driver/src/main.hb index f8c3517..05e5ff2 100644 --- a/sysdata/programs/diskio_driver/src/main.hb +++ b/sysdata/programs/diskio_driver/src/main.hb @@ -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") diff --git a/sysdata/programs/fb_driver/src/color.hb b/sysdata/programs/fb_driver/src/color.hb index 51bbf14..281f25d 100644 --- a/sysdata/programs/fb_driver/src/color.hb +++ b/sysdata/programs/fb_driver/src/color.hb @@ -19,7 +19,7 @@ LIGHTBLUE := ColorBGRA.{b: 255, g: 0, r: 0, a: 255} LIGHTMAGENTA := ColorBGRA.{b: 255, g: 0, r: 255, a: 255} LIGHTCYAN := ColorBGRA.{b: 255, g: 255, r: 0, a: 255} -// i have no clue if this works. please don't me ask how it works. -aurlex +// i have no clue if this works. please don't me ask how it works. -koniifer blend := fn(fg: ColorBGRA, bg: ColorBGRA): ColorBGRA { s := fg + bg m := s - ((fg ^ bg) & 16843008) & 16843008 diff --git a/sysdata/programs/ps2_driver/src/main.hb b/sysdata/programs/ps2_driver/src/main.hb index 33be926..04e7892 100644 --- a/sysdata/programs/ps2_driver/src/main.hb +++ b/sysdata/programs/ps2_driver/src/main.hb @@ -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,13 +17,13 @@ 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 } prev_input = input keycode_str := string.display_int(input, ptr) - log.info(string.display_int(buf)) + log.info(string.display_int(input, ptr)) buffer.send_message(keycode_str, buf) } return 0