forked from AbleOS/ableos
minor changes
This commit is contained in:
parent
5f2b181f22
commit
fb42351638
|
@ -47,6 +47,7 @@ pub fn init(device_tree: &mut DeviceTree) {
|
||||||
pci_info.set_attribute("id", id);
|
pci_info.set_attribute("id", id);
|
||||||
pci_info.set_attribute("device", device_info.device);
|
pci_info.set_attribute("device", device_info.device);
|
||||||
pci_info.set_attribute("vendor", vendor);
|
pci_info.set_attribute("vendor", vendor);
|
||||||
|
pci_info.set_attribute("bus", bus);
|
||||||
pci_info.set_attribute("class", device_info.full_class.to_string());
|
pci_info.set_attribute("class", device_info.full_class.to_string());
|
||||||
dev.set_child(pci_info);
|
dev.set_child(pci_info);
|
||||||
devices.push((dev_type, dev));
|
devices.push((dev_type, dev));
|
||||||
|
@ -68,7 +69,8 @@ pub fn check_device(bus: u8, device: u8) -> Option<PciDeviceInfo> {
|
||||||
return None;
|
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 class = ((reg2 >> 16) & 0x0000_FFFF) as u16;
|
||||||
let pci_class = PciFullClass::from_u16(class);
|
let pci_class = PciFullClass::from_u16(class);
|
||||||
let header_type = get_header_type(bus, device, 0);
|
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 func = func as u32;
|
||||||
let offset = offset as u32;
|
let offset = offset as u32;
|
||||||
// construct address param
|
// construct address param
|
||||||
let address =
|
let address = (bus << 16) | (device << 11) | (func << 8) | (offset & 0xFC) | 0x8000_0000;
|
||||||
((bus << 16) | (device << 11) | (func << 8) | (offset & 0xFC) | 0x8000_0000) as u32;
|
|
||||||
|
|
||||||
// write address
|
// write address
|
||||||
Port::new(0xCF8).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()
|
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) {
|
unsafe fn pci_config_write(bus: u8, device: u8, func: u8, offset: u8, value: u32) {
|
||||||
let bus = bus as u32;
|
let bus = bus as u32;
|
||||||
let device = device as u32;
|
let device = device as u32;
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
stn := @use("rel:../../stn/src/lib.hb");
|
||||||
|
.{string, memory, buffer} := stn
|
||||||
|
|
||||||
PCIAddress := struct {
|
PCIAddress := struct {
|
||||||
bus: u8,
|
bus: u8,
|
||||||
device: u8,
|
device: u8,
|
||||||
|
@ -13,16 +16,17 @@ scan_bus := fn(): void {
|
||||||
|
|
||||||
config_read32 := fn(bus: u32, device: u32, func: u32, offset: u32): u32 {
|
config_read32 := fn(bus: u32, device: u32, func: u32, offset: u32): u32 {
|
||||||
// construct address param
|
// construct address param
|
||||||
address := bus << 16 | device << 11 | func << 8
|
offset_and := offset & 0xFC
|
||||||
address |= offset
|
|
||||||
address &= 0xFC
|
address := bus << 16
|
||||||
|
address |= device << 11
|
||||||
|
address |= func << 8
|
||||||
|
address |= offset_and
|
||||||
address |= 0x80000000
|
address |= 0x80000000
|
||||||
|
|
||||||
// write address
|
// write address
|
||||||
//Port::new(0xCF8).write(address);
|
memory.outl(0xCF8, address)
|
||||||
|
|
||||||
// read data
|
// read data
|
||||||
//Port::new(0xCFC).read()
|
return memory.inl(0xCFC)
|
||||||
|
|
||||||
return
|
|
||||||
}
|
}
|
|
@ -3,36 +3,45 @@ length := fn(ptr: ^u8): int {
|
||||||
loop if *(ptr + len) == 0 break else len += 1
|
loop if *(ptr + len) == 0 break else len += 1
|
||||||
return len
|
return len
|
||||||
}
|
}
|
||||||
|
|
||||||
display_int := fn(num: int, p: ^u8): ^u8 {
|
display_int := fn(num: int, p: ^u8): ^u8 {
|
||||||
i := 0
|
i := 0
|
||||||
if num == 0 {
|
if num == 0 {
|
||||||
*p = 48
|
*p = 48;
|
||||||
|
*(p + 1) = 0
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
|
neg := false
|
||||||
|
if num < 0 {
|
||||||
|
neg = true
|
||||||
|
num = -num
|
||||||
|
}
|
||||||
|
|
||||||
loop if num == 0 break else {
|
loop if num == 0 break else {
|
||||||
*(p + i) = num % 10 + 48
|
*(p + i) = num % 10 + 48
|
||||||
num /= 10
|
num /= 10
|
||||||
i += 1
|
i += 1
|
||||||
}
|
}
|
||||||
@inline(reverse, p);
|
|
||||||
*(p + i) = 0
|
if neg {
|
||||||
|
*(p + i) = 45
|
||||||
|
i += 1
|
||||||
|
}
|
||||||
|
|
||||||
|
reverse(p, i)
|
||||||
|
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
reverse := fn(s: ^u8): void {
|
reverse := fn(p: ^u8, len: int): void {
|
||||||
//reverse a string, don't remove digits
|
start := 0
|
||||||
len := 0
|
end := len - 1
|
||||||
loop if *(s + len) == 0 break else len += 1
|
loop if start >= end break else {
|
||||||
i := 0
|
temp := *(p + start);
|
||||||
j := len - 1
|
*(p + start) = *(p + end);
|
||||||
temp := 0
|
*(p + end) = temp
|
||||||
loop if i >= j break else {
|
start += 1
|
||||||
temp = *(s + i);
|
end -= 1
|
||||||
*(s + i) = *(s + j);
|
|
||||||
*(s + j) = temp
|
|
||||||
i += 1
|
|
||||||
j -= 1
|
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
|
@ -27,6 +27,12 @@ SVGA_disable := fn(): void {
|
||||||
}
|
}
|
||||||
|
|
||||||
main := fn(): int {
|
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()
|
init()
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
|
Loading…
Reference in a new issue