forked from AbleOS/ableos
experimental commit wtf is going on
This commit is contained in:
parent
12ee3a9b87
commit
f32d66e50e
|
@ -92,41 +92,87 @@ pub fn handler(vm: &mut Vm) {
|
|||
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 {
|
||||
// XY\0\0V
|
||||
// X = 0: Read, 1: Write
|
||||
// Y = 0: 8bit, 1: 16bit, 2: 32bit
|
||||
// \0\0 = Port Low, Port High
|
||||
// V = Value
|
||||
0 => {
|
||||
let mut addr = msg_vec[0] as u16;
|
||||
msg_vec.remove(0);
|
||||
// info!("inb");
|
||||
let size = msg_vec[0];
|
||||
if size <= 2 {
|
||||
msg_vec.remove(0);
|
||||
|
||||
let addr2 = msg_vec[0] as u16;
|
||||
msg_vec.remove(0);
|
||||
let mut addr = msg_vec[0] as u16;
|
||||
msg_vec.remove(0);
|
||||
|
||||
addr = ((addr) << 8) | addr2;
|
||||
|
||||
let value = unsafe { x86_in(addr) };
|
||||
|
||||
trace!("Read the value {} from address {}", value, addr);
|
||||
vm.registers[1] = hbvm::value::Value(value as u64);
|
||||
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 => {
|
||||
let mut addr = msg_vec[0] as u16;
|
||||
msg_vec.remove(0);
|
||||
// info!("outb");
|
||||
let size = msg_vec[0];
|
||||
if size <= 2 {
|
||||
msg_vec.remove(0);
|
||||
|
||||
let addr2 = msg_vec[0] as u16;
|
||||
msg_vec.remove(0);
|
||||
let mut addr = msg_vec[0] as u16;
|
||||
msg_vec.remove(0);
|
||||
|
||||
addr = ((addr) << 8) | addr2;
|
||||
let addr2 = msg_vec[0] as u16;
|
||||
msg_vec.remove(0);
|
||||
|
||||
let value = msg_vec[0];
|
||||
msg_vec.remove(0);
|
||||
trace!("Setting the address {} to {}", addr, value);
|
||||
unsafe { x86_out(addr, value) };
|
||||
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);
|
||||
}
|
||||
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.")
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
|
|
@ -338,6 +338,7 @@ fn run(release: bool, target: Target) -> Result<(), Error> {
|
|||
"-smp", "cores=4",
|
||||
"-enable-kvm",
|
||||
"-cpu", "host",
|
||||
"-vga", "vmware",
|
||||
"-device", "isa-debug-exit,iobase=0xf4,iosize=0x04"
|
||||
]);
|
||||
}
|
||||
|
|
2
sysdata/libraries/pci/README.md
Normal file
2
sysdata/libraries/pci/README.md
Normal file
|
@ -0,0 +1,2 @@
|
|||
please, someone smarter than me, write this for me
|
||||
- koniifer
|
71
sysdata/libraries/pci/src/lib.hb
Normal file
71
sysdata/libraries/pci/src/lib.hb
Normal file
|
@ -0,0 +1,71 @@
|
|||
.{memory} := @use("../../../libraries/stn/src/lib.hb")
|
||||
// I DONT UNDERSTAND PCI, current code translated from osdev wiki... - koniifer
|
||||
// All this is basically just pseudocode...
|
||||
|
||||
get_vendor_id := fn(bus: u8, device: u8, function: u8): u16 {
|
||||
return 0
|
||||
}
|
||||
|
||||
pci_config_read_word := fn(bus: u8, slot: u8, func: u8, offset: u8): u16 {
|
||||
lbus := @as(u32, bus)
|
||||
lslot := @as(u32, slot)
|
||||
lfunc := @as(u32, func)
|
||||
tmp := 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)
|
||||
return tmp
|
||||
}
|
||||
|
||||
pci_check_vendor := fn(bus: u8, slot: u8): u16 {
|
||||
vendor := pci_config_read_word(bus, slot, 0, 0)
|
||||
if vendor != 65535 {
|
||||
// device := pci_config_read_word(bus, slot, 0, 2)
|
||||
}
|
||||
return vendor
|
||||
}
|
||||
|
||||
get_header_type := fn(bus: u8, device: u8, function: u8): u16 {
|
||||
// idfk
|
||||
slot := 0
|
||||
return pci_config_read_word(bus, slot, 0, 14)
|
||||
}
|
||||
|
||||
check_device := fn(bus: u8, device: u8): void {
|
||||
function := @as(u8, 0)
|
||||
vendor_id := get_vendor_id(bus, device, function)
|
||||
if vendor_id == 65535 {
|
||||
return
|
||||
}
|
||||
check_function(bus, device, function)
|
||||
header_type := get_header_type(bus, device, function)
|
||||
if (header_type & 128) != 0 {
|
||||
function = 1
|
||||
loop if function >= 8 break else {
|
||||
if get_vendor_id(bus, device, function) != 65535 {
|
||||
check_function(bus, device, function)
|
||||
}
|
||||
function += 1
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
check_function := fn(bus: u8, device: u8, function: u8): void {
|
||||
return
|
||||
}
|
||||
|
||||
check_all_buses := fn(): void {
|
||||
bus := @as(u16, 0)
|
||||
device := @as(u8, 0)
|
||||
|
||||
loop if bus >= 256 break else {
|
||||
loop if device >= 32 break else {
|
||||
check_device(bus, device)
|
||||
device += 1
|
||||
}
|
||||
bus += 1
|
||||
}
|
||||
return
|
||||
}
|
|
@ -17,19 +17,45 @@ 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_low: u8, addr_high: u8, value: u8): void {
|
||||
msg := "\0\0\0\0\0";
|
||||
*msg = 1;
|
||||
*(msg + 1) = addr_high;
|
||||
*(msg + 1) = 0;
|
||||
*(msg + 2) = addr_low;
|
||||
*(msg + 3) = value
|
||||
@eca(void, 3, 3, msg, 4)
|
||||
*(msg + 3) = addr_high;
|
||||
*(msg + 4) = value
|
||||
@eca(void, 3, 3, msg, 5)
|
||||
return
|
||||
}
|
||||
|
||||
inb := fn(addr_high: u8, addr_low: u8): u8 {
|
||||
inb := fn(addr_low: u8, addr_high: u8): 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;
|
||||
*(msg + 2) = addr_low;
|
||||
*(msg + 3) = addr_high
|
||||
return @eca(u8, 3, 3, msg, 4)
|
||||
}
|
||||
|
||||
outl := fn(addr_low: u8, addr_high: u8, 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;
|
||||
*(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_low: u8, addr_high: u8): u32 {
|
||||
msg := "\0\0\0\0";
|
||||
*msg = 0;
|
||||
*(msg + 1) = 2;
|
||||
*(msg + 2) = addr_low;
|
||||
*(msg + 3) = addr_high
|
||||
return @eca(u32, 3, 3, msg, 4)
|
||||
}
|
|
@ -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
|
||||
|
|
|
@ -23,7 +23,7 @@ main := fn(): int {
|
|||
}
|
||||
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
|
||||
|
|
11
sysdata/programs/svga_driver/meta.toml
Normal file
11
sysdata/programs/svga_driver/meta.toml
Normal file
|
@ -0,0 +1,11 @@
|
|||
[package]
|
||||
name = "svga_driver"
|
||||
authors = ["aurlex"]
|
||||
|
||||
[dependants.libraries]
|
||||
|
||||
[dependants.binaries]
|
||||
hblang.version = "1.0.0"
|
||||
|
||||
[build]
|
||||
command = "hblang src/main.hb"
|
20
sysdata/programs/svga_driver/src/main.hb
Normal file
20
sysdata/programs/svga_driver/src/main.hb
Normal file
|
@ -0,0 +1,20 @@
|
|||
.{pci_config_read_word} := @use("../../../libraries/pci/src/lib.hb");
|
||||
.{log, string, memory} := @use("../../../libraries/stn/src/lib.hb")
|
||||
|
||||
// pci device = 2
|
||||
// pci id = 1029
|
||||
// pci vendor = 0x15AD (or 5549)
|
||||
// pci class = 0x0300 (or 768)
|
||||
|
||||
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
|
||||
}
|
||||
return
|
||||
}
|
|
@ -29,11 +29,14 @@ path = "boot:///ps2_driver.hbf"
|
|||
[boot.limine.ableos.modules.diskio_driver]
|
||||
path = "boot:///diskio_driver.hbf"
|
||||
|
||||
[boot.limine.ableos.modules.fb_driver]
|
||||
path = "boot:///fb_driver.hbf"
|
||||
|
||||
[boot.limine.ableos.modules.serial_driver_test]
|
||||
path = "boot:///serial_driver_test.hbf"
|
||||
|
||||
[boot.limine.ableos.modules.fb_driver_stresstest]
|
||||
path = "boot:///fb_driver_stresstest.hbf"
|
||||
[boot.limine.ableos.modules.svga_driver]
|
||||
path = "boot:///svga_driver.hbf"
|
||||
|
||||
# [boot.limine.ableos.modules.fb_driver]
|
||||
# path = "boot:///fb_driver.hbf"
|
||||
|
||||
# [boot.limine.ableos.modules.fb_driver_stresstest]
|
||||
# path = "boot:///fb_driver_stresstest.hbf"
|
||||
|
|
Loading…
Reference in a new issue