Added physical and virtual addresses

This commit is contained in:
Ryan Kennedy 2020-04-10 22:45:26 -05:00
parent 823d9ecf4e
commit 4e3460a273

View file

@ -66,6 +66,8 @@ pub struct BochsDevice {
index_port: Port<u16>, index_port: Port<u16>,
data_port: Port<u16>, data_port: Port<u16>,
pci_device: PciDevice, pci_device: PciDevice,
physical_address: u32,
virtual_address: u64,
} }
impl BochsDevice { impl BochsDevice {
@ -73,20 +75,28 @@ impl BochsDevice {
if let Some(pci_device) = find_pci_device(BOCHS_ID) { if let Some(pci_device) = find_pci_device(BOCHS_ID) {
let index_port = Port::new(BOCHS_INDEX_PORT_ADDRESS); let index_port = Port::new(BOCHS_INDEX_PORT_ADDRESS);
let data_port = Port::new(BOCHS_DATA_PORT_ADDRESS); let data_port = Port::new(BOCHS_DATA_PORT_ADDRESS);
let physical_address = match pci_device.pci_header {
PciHeader::PciHeaderType0 { base_addresses, .. } => base_addresses[0] & 0xFFFF_FFF0,
};
let virtual_address = physical_address as u64;
Some(BochsDevice { Some(BochsDevice {
pci_device, pci_device,
index_port, index_port,
data_port, data_port,
physical_address,
virtual_address,
}) })
} else { } else {
None None
} }
} }
pub fn base_address(&self) -> u32 { pub fn physical_address(&self) -> u32 {
match self.pci_device.pci_header { self.physical_address
PciHeader::PciHeaderType0 { base_addresses, .. } => base_addresses[0] & 0xFFFF_FFF0, }
}
pub fn virtual_address(&self) -> u64 {
self.virtual_address
} }
pub fn capabilities(&mut self) -> Capabilities { pub fn capabilities(&mut self) -> Capabilities {
@ -167,21 +177,21 @@ impl BochsDevice {
} }
} }
pub fn set_width(&mut self, width: u16) { fn set_width(&mut self, width: u16) {
unsafe { unsafe {
self.index_port.write(VBE_DISPI_INDEX_XRES); self.index_port.write(VBE_DISPI_INDEX_XRES);
self.data_port.write(width); self.data_port.write(width);
} }
} }
pub fn set_height(&mut self, height: u16) { fn set_height(&mut self, height: u16) {
unsafe { unsafe {
self.index_port.write(VBE_DISPI_INDEX_YRES); self.index_port.write(VBE_DISPI_INDEX_YRES);
self.data_port.write(height); self.data_port.write(height);
} }
} }
pub fn set_bpp(&mut self, bpp: BitsPerPixel) { fn set_bpp(&mut self, bpp: BitsPerPixel) {
unsafe { unsafe {
self.index_port.write(VBE_DISPI_INDEX_BPP); self.index_port.write(VBE_DISPI_INDEX_BPP);
self.data_port.write(bpp as u16); self.data_port.write(bpp as u16);