1
0
Fork 0
forked from AbleOS/ableos

minor changes

This commit is contained in:
Able 2024-09-16 20:45:00 -05:00
parent 5f2b181f22
commit fb42351638
4 changed files with 61 additions and 28 deletions

View file

@ -47,6 +47,7 @@ pub fn init(device_tree: &mut DeviceTree) {
pci_info.set_attribute("id", id);
pci_info.set_attribute("device", device_info.device);
pci_info.set_attribute("vendor", vendor);
pci_info.set_attribute("bus", bus);
pci_info.set_attribute("class", device_info.full_class.to_string());
dev.set_child(pci_info);
devices.push((dev_type, dev));
@ -68,7 +69,8 @@ pub fn check_device(bus: u8, device: u8) -> Option<PciDeviceInfo> {
return None;
}
let reg2 = unsafe { pci_config_read(bus, device, 0, 0x8) };
let (reg2, addr) = unsafe { pci_config_read_2(bus, device, 0, 0x8) };
log::info!("pci device-({}) addr {} is {}", device, addr, reg2);
let class = ((reg2 >> 16) & 0x0000_FFFF) as u16;
let pci_class = PciFullClass::from_u16(class);
let header_type = get_header_type(bus, device, 0);
@ -459,9 +461,7 @@ unsafe fn pci_config_read(bus: u8, device: u8, func: u8, offset: u8) -> u32 {
let func = func as u32;
let offset = offset as u32;
// construct address param
let address =
((bus << 16) | (device << 11) | (func << 8) | (offset & 0xFC) | 0x8000_0000) as u32;
let address = (bus << 16) | (device << 11) | (func << 8) | (offset & 0xFC) | 0x8000_0000;
// write address
Port::new(0xCF8).write(address);
@ -469,6 +469,20 @@ unsafe fn pci_config_read(bus: u8, device: u8, func: u8, offset: u8) -> u32 {
Port::new(0xCFC).read()
}
unsafe fn pci_config_read_2(bus: u8, device: u8, func: u8, offset: u8) -> (u32, u32) {
let bus = bus as u32;
let device = device as u32;
let func = func as u32;
let offset = offset as u32;
// construct address param
let address = (bus << 16) | (device << 11) | (func << 8) | (offset & 0xFC) | 0x8000_0000;
// write address
Port::new(0xCF8).write(address);
// read data
(Port::new(0xCFC).read(), address)
}
unsafe fn pci_config_write(bus: u8, device: u8, func: u8, offset: u8, value: u32) {
let bus = bus as u32;
let device = device as u32;

View file

@ -1,3 +1,6 @@
stn := @use("rel:../../stn/src/lib.hb");
.{string, memory, buffer} := stn
PCIAddress := struct {
bus: u8,
device: u8,
@ -13,16 +16,17 @@ scan_bus := fn(): void {
config_read32 := fn(bus: u32, device: u32, func: u32, offset: u32): u32 {
// construct address param
address := bus << 16 | device << 11 | func << 8
address |= offset
address &= 0xFC
offset_and := offset & 0xFC
address := bus << 16
address |= device << 11
address |= func << 8
address |= offset_and
address |= 0x80000000
// write address
//Port::new(0xCF8).write(address);
memory.outl(0xCF8, address)
// read data
//Port::new(0xCFC).read()
return
return memory.inl(0xCFC)
}

View file

@ -3,36 +3,45 @@ length := fn(ptr: ^u8): int {
loop if *(ptr + len) == 0 break else len += 1
return len
}
display_int := fn(num: int, p: ^u8): ^u8 {
i := 0
if num == 0 {
*p = 48
*p = 48;
*(p + 1) = 0
return p
}
neg := false
if num < 0 {
neg = true
num = -num
}
loop if num == 0 break else {
*(p + i) = num % 10 + 48
num /= 10
i += 1
}
@inline(reverse, p);
*(p + i) = 0
if neg {
*(p + i) = 45
i += 1
}
reverse(p, i)
return p
}
reverse := fn(s: ^u8): void {
//reverse a string, don't remove digits
len := 0
loop if *(s + len) == 0 break else len += 1
i := 0
j := len - 1
temp := 0
loop if i >= j break else {
temp = *(s + i);
*(s + i) = *(s + j);
*(s + j) = temp
i += 1
j -= 1
reverse := fn(p: ^u8, len: int): void {
start := 0
end := len - 1
loop if start >= end break else {
temp := *(p + start);
*(p + start) = *(p + end);
*(p + end) = temp
start += 1
end -= 1
}
return
}

View file

@ -27,6 +27,12 @@ SVGA_disable := fn(): void {
}
main := fn(): int {
a := pci.config_read32(0, 2, 0, 0x8)
b := "\0\0\0\0\0\0\0"
string.display_int(a, b)
stn.log.info(b)
init()
return 0