Remove some options

This commit is contained in:
Ryan Kennedy 2020-04-13 23:57:33 -05:00
parent a0c2a2361b
commit 6708631bbe
2 changed files with 56 additions and 61 deletions

View file

@ -1,4 +1,4 @@
use super::pci::{find_pci_device, PciDevice, PciHeader};
use super::pci::{find_pci_device, PciDevice};
use crate::drawing::{Bresenham, Point, Rectangle};
use x86_64::{instructions::port::Port, PhysAddr, VirtAddr};
@ -40,40 +40,43 @@ pub struct BochsDevice {
}
impl BochsDevice {
pub fn new() -> Option<BochsDevice> {
if let Some(pci_device) = find_pci_device(BOCHS_ID) {
let index_port = Port::new(BOCHS_INDEX_PORT_ADDRESS);
let data_port = Port::new(BOCHS_DATA_PORT_ADDRESS);
let base_address = match pci_device.pci_header {
PciHeader::PciHeaderType0 { base_addresses, .. } => base_addresses[0] & 0xFFFF_FFF0,
};
let physical_address = PhysAddr::new(base_address as u64);
let virtual_address = VirtAddr::new(base_address as u64);
Some(BochsDevice {
pci_device,
index_port,
data_port,
physical_address,
virtual_address,
current_resolution: Resolution::default(),
})
} else {
None
pub fn new() -> BochsDevice {
let pci_device = find_pci_device(BOCHS_ID).expect("no bochs device found");
let index_port = Port::new(BOCHS_INDEX_PORT_ADDRESS);
let data_port = Port::new(BOCHS_DATA_PORT_ADDRESS);
let base_address = pci_device.base_addresses[0] & 0xFFFF_FFF0;
let physical_address = PhysAddr::new(base_address as u64);
let virtual_address = VirtAddr::new(base_address as u64);
BochsDevice {
pci_device,
index_port,
data_port,
physical_address,
virtual_address,
current_resolution: Resolution::default(),
}
}
/// The physical address the frame buffer is mapped to.
pub fn physical_address(&self) -> PhysAddr {
self.physical_address
}
/// The virtual address that's written to for graphics operations.
///
/// **Note:** This address is set to the `physical_address` of the frame buffer
/// by default. If you map the `physical_address` to a different location, `virtual_address`
/// must be set using `set_virtual_address`.
pub fn virtual_address(&self) -> VirtAddr {
self.virtual_address
}
/// Sets the `virtual_address` that's written to for graphics operations.
pub fn set_virtual_address(&mut self, virtual_address: VirtAddr) {
self.virtual_address = virtual_address;
}
/// Returns the max capabilities supported by the `BochsDevice`.
pub fn capabilities(&mut self) -> Resolution {
unsafe {
// Save original value of VBE_DISPI_INDEX_ENABLE
@ -97,6 +100,7 @@ impl BochsDevice {
}
}
/// Clears the screen using the given `color`.
pub fn clear_screen(&self, color: u32) {
let screen_size = self.current_resolution.width * self.current_resolution.height;
let frame_buffer = self.virtual_address.as_mut_ptr::<u32>();
@ -107,12 +111,14 @@ impl BochsDevice {
}
}
/// Draws a line from the given `start` to `end` using the given `color`.
pub fn draw_line(&self, start: Point<isize>, end: Point<isize>, color: u32) {
for (x, y) in Bresenham::new(start, end) {
self.set_pixel(x as usize, y as usize, color);
}
}
/// Draws a rectangle using the given `rectangle` and `color`.
pub fn draw_rectangle(&self, rectangle: &Rectangle, color: u32) {
let p1 = (rectangle.left as isize, rectangle.top as isize);
let p2 = (rectangle.left as isize, rectangle.bottom as isize);
@ -124,6 +130,7 @@ impl BochsDevice {
self.draw_line(p4, p1, color);
}
/// Draws a filled rectangle using the given `rectangle` and `color`.
pub fn fill_rectangle(&self, rectangle: &Rectangle, color: u32) {
for y in rectangle.top..rectangle.bottom {
for x in rectangle.left..rectangle.right {
@ -132,6 +139,7 @@ impl BochsDevice {
}
}
/// Sets the pixel at `(x, y)` to the given `color`.
pub fn set_pixel(&self, x: usize, y: usize, color: u32) {
let offset = (y * self.current_resolution.width) + x;
unsafe {
@ -157,12 +165,14 @@ impl BochsDevice {
}
}
pub fn get_resolution(&mut self) -> Resolution {
/// Returns the current resolution the `BochsDevice` is set to.
pub fn current_resolution(&mut self) -> Resolution {
let width = self.get_width();
let height = self.get_height();
Resolution { width, height }
}
/// Sets the `BochsDevice` to the given `resolution`.
pub fn set_resolution(&mut self, resolution: Resolution) {
self.disable_display();
self.set_width(resolution.width);
@ -172,14 +182,14 @@ impl BochsDevice {
self.current_resolution = resolution;
}
pub fn get_width(&mut self) -> usize {
fn get_width(&mut self) -> usize {
unsafe {
self.index_port.write(VBE_DISPI_INDEX_XRES);
self.data_port.read() as usize
}
}
pub fn get_height(&mut self) -> usize {
fn get_height(&mut self) -> usize {
unsafe {
self.index_port.write(VBE_DISPI_INDEX_YRES);
self.data_port.read() as usize

View file

@ -21,23 +21,16 @@ pub(crate) struct PciDevice {
latency_timer: u8,
header_type: u8,
bist: u8,
pub(crate) pci_header: PciHeader,
}
#[derive(Debug, Copy, Clone)]
pub(crate) enum PciHeader {
PciHeaderType0 {
base_addresses: [u32; 6],
cis: u32,
sub_vendor_id: u16,
sub_system_id: u16,
rom_base_address: u32,
reserved_2: [u32; 2],
interrupt_line: u8,
interrupt_pin: u8,
minimum_grant: u8,
maximum_latency: u8,
},
pub(crate) base_addresses: [u32; 6],
cis: u32,
sub_vendor_id: u16,
sub_system_id: u16,
rom_base_address: u32,
reserved_2: [u32; 2],
interrupt_line: u8,
interrupt_pin: u8,
minimum_grant: u8,
maximum_latency: u8,
}
pub(crate) fn find_pci_device(device_id: u32) -> Option<PciDevice> {
@ -59,26 +52,6 @@ fn read_device(address: u32) -> PciDevice {
let (status, command) = read_2_words(address, 0x04);
let (base_class, sub_class, prog_if, revision_id) = read_4_bytes(address, 0x08);
let (bist, header_type, latency_timer, cache_line_size) = read_4_bytes(address, 0x0C);
let pci_header = read_header_type_0(address);
PciDevice {
vendor_id,
device_id,
status,
command,
base_class,
sub_class,
prog_if,
revision_id,
bist,
header_type,
latency_timer,
cache_line_size,
pci_header,
}
}
fn read_header_type_0(address: u32) -> PciHeader {
let mut base_addresses = [0u32; 6];
base_addresses[0] = read_offset(address, 0x10);
base_addresses[1] = read_offset(address, 0x14);
@ -95,7 +68,19 @@ fn read_header_type_0(address: u32) -> PciHeader {
let (maximum_latency, minimum_grant, interrupt_pin, interrupt_line) =
read_4_bytes(address, 0x3C);
PciHeader::PciHeaderType0 {
PciDevice {
vendor_id,
device_id,
status,
command,
base_class,
sub_class,
prog_if,
revision_id,
bist,
header_type,
latency_timer,
cache_line_size,
base_addresses,
cis,
sub_system_id,