So I'm (starting) to get (almost right) results with this code:
Code:
let mut idx = 0;
loop {
if !dev.bars.contains_key(&idx) || dev.bars[&idx] == 0x00 {
break;
}
let real_idx = match idx {
0 => BAR0,
1 => BAR1,
2 => BAR2,
3 => BAR3,
4 => BAR4,
5 => BAR5,
_ => 0,
};
let oldbar = read_dword(addr, real_idx);
let oldbar2 = if oldbar.get_bits(1..=2) == 0x02 {
read_dword(addr, real_idx + 4)
} else {
0
};
write_dword(addr, real_idx, u32::MAX);
if oldbar.get_bits(1..=2) == 0x02 {
write_dword(addr, real_idx + 4, u32::MAX);
}
let mut bar = read_dword(addr, real_idx);
let bar2 = if oldbar.get_bits(1..=2) == 0x02 {
read_dword(addr, real_idx + 4)
} else {
0
};
write_dword(addr, real_idx, oldbar);
if bar2 == 0x00 {
write_dword(addr, real_idx + 4, oldbar2);
}
let ones = if bar2 == 0x00 {
let bar = if bar.get_bit(0) {
bar.set_bits(0..2, 0)
} else {
bar.set_bits(0..4, 0)
};
!bar.count_ones()
} else {
let mut bar = (bar2 as u64) << 32 | (bar as u64);
if bar.get_bit(0) {
bar.set_bits(0..2, 0);
} else {
bar.set_bits(0..4, 0);
}
!bar.count_ones()
};
info!("BAR {:X} consumes {} bytes", idx, 1 << ones.count_ones());
if oldbar.get_bits(1..=2) == 0x02 {
idx += 2;
} else {
idx += 1;
}
}
Doesn't quite work right though. Either skips BARs or tells me that a BAR needs 256M of RAM (which I don't think is right). Or it might be... Qemu args:
Code:
qemu-system-x86_64 -drive format=raw,file=/home/ethin/source/kernel/target/x86_64-kernel-none/debug/boot-uefi-kernel.img -drive if=pflash,format=raw,file=OVMF.fd,readonly=on -drive file=disk-nvme.img,if=none,id=NVME01 -device nvme,drive=NVME01,serial=0001 -drive id=disk,file=disk-sata.img,if=none -device ahci,id=ahci -device ide-hd,drive=disk,bus=ahci.0 -usb -rtc clock=host -cpu host -smp cpus=8 -M q35 -name kernel -nographic -debugcon file:qemu.log -global isa-debugcon.iobase=0x402 -d int -D qemu2.log -device usb-audio,audiodev=alsa -audiodev alsa,id=alsa -device ich9-intel-hda -device hda-duplex,audiodev=alsa -no-shutdown -no-reboot -device qemu-xhci -device virtio-net,netdev=nic -netdev user,hostname=kernel,id=nic -device virtio-balloon -device virtio-serial-pci -device virtio-rng-pci,rng=rng0 -object rng-random,id=rng0,filename=/dev/urandom -device virtio-gpu --enable-kvm