Remove some options
This commit is contained in:
parent
a0c2a2361b
commit
6708631bbe
|
@ -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 crate::drawing::{Bresenham, Point, Rectangle};
|
||||||
use x86_64::{instructions::port::Port, PhysAddr, VirtAddr};
|
use x86_64::{instructions::port::Port, PhysAddr, VirtAddr};
|
||||||
|
|
||||||
|
@ -40,40 +40,43 @@ pub struct BochsDevice {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BochsDevice {
|
impl BochsDevice {
|
||||||
pub fn new() -> Option<BochsDevice> {
|
pub fn new() -> BochsDevice {
|
||||||
if let Some(pci_device) = find_pci_device(BOCHS_ID) {
|
let pci_device = find_pci_device(BOCHS_ID).expect("no bochs device found");
|
||||||
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 base_address = match pci_device.pci_header {
|
let base_address = pci_device.base_addresses[0] & 0xFFFF_FFF0;
|
||||||
PciHeader::PciHeaderType0 { base_addresses, .. } => base_addresses[0] & 0xFFFF_FFF0,
|
|
||||||
};
|
|
||||||
let physical_address = PhysAddr::new(base_address as u64);
|
let physical_address = PhysAddr::new(base_address as u64);
|
||||||
let virtual_address = VirtAddr::new(base_address as u64);
|
let virtual_address = VirtAddr::new(base_address as u64);
|
||||||
Some(BochsDevice {
|
BochsDevice {
|
||||||
pci_device,
|
pci_device,
|
||||||
index_port,
|
index_port,
|
||||||
data_port,
|
data_port,
|
||||||
physical_address,
|
physical_address,
|
||||||
virtual_address,
|
virtual_address,
|
||||||
current_resolution: Resolution::default(),
|
current_resolution: Resolution::default(),
|
||||||
})
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The physical address the frame buffer is mapped to.
|
||||||
pub fn physical_address(&self) -> PhysAddr {
|
pub fn physical_address(&self) -> PhysAddr {
|
||||||
self.physical_address
|
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 {
|
pub fn virtual_address(&self) -> VirtAddr {
|
||||||
self.virtual_address
|
self.virtual_address
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Sets the `virtual_address` that's written to for graphics operations.
|
||||||
pub fn set_virtual_address(&mut self, virtual_address: VirtAddr) {
|
pub fn set_virtual_address(&mut self, virtual_address: VirtAddr) {
|
||||||
self.virtual_address = virtual_address;
|
self.virtual_address = virtual_address;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the max capabilities supported by the `BochsDevice`.
|
||||||
pub fn capabilities(&mut self) -> Resolution {
|
pub fn capabilities(&mut self) -> Resolution {
|
||||||
unsafe {
|
unsafe {
|
||||||
// Save original value of VBE_DISPI_INDEX_ENABLE
|
// 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) {
|
pub fn clear_screen(&self, color: u32) {
|
||||||
let screen_size = self.current_resolution.width * self.current_resolution.height;
|
let screen_size = self.current_resolution.width * self.current_resolution.height;
|
||||||
let frame_buffer = self.virtual_address.as_mut_ptr::<u32>();
|
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) {
|
pub fn draw_line(&self, start: Point<isize>, end: Point<isize>, color: u32) {
|
||||||
for (x, y) in Bresenham::new(start, end) {
|
for (x, y) in Bresenham::new(start, end) {
|
||||||
self.set_pixel(x as usize, y as usize, color);
|
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) {
|
pub fn draw_rectangle(&self, rectangle: &Rectangle, color: u32) {
|
||||||
let p1 = (rectangle.left as isize, rectangle.top as isize);
|
let p1 = (rectangle.left as isize, rectangle.top as isize);
|
||||||
let p2 = (rectangle.left as isize, rectangle.bottom as isize);
|
let p2 = (rectangle.left as isize, rectangle.bottom as isize);
|
||||||
|
@ -124,6 +130,7 @@ impl BochsDevice {
|
||||||
self.draw_line(p4, p1, color);
|
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) {
|
pub fn fill_rectangle(&self, rectangle: &Rectangle, color: u32) {
|
||||||
for y in rectangle.top..rectangle.bottom {
|
for y in rectangle.top..rectangle.bottom {
|
||||||
for x in rectangle.left..rectangle.right {
|
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) {
|
pub fn set_pixel(&self, x: usize, y: usize, color: u32) {
|
||||||
let offset = (y * self.current_resolution.width) + x;
|
let offset = (y * self.current_resolution.width) + x;
|
||||||
unsafe {
|
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 width = self.get_width();
|
||||||
let height = self.get_height();
|
let height = self.get_height();
|
||||||
Resolution { width, height }
|
Resolution { width, height }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Sets the `BochsDevice` to the given `resolution`.
|
||||||
pub fn set_resolution(&mut self, resolution: Resolution) {
|
pub fn set_resolution(&mut self, resolution: Resolution) {
|
||||||
self.disable_display();
|
self.disable_display();
|
||||||
self.set_width(resolution.width);
|
self.set_width(resolution.width);
|
||||||
|
@ -172,14 +182,14 @@ impl BochsDevice {
|
||||||
self.current_resolution = resolution;
|
self.current_resolution = resolution;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_width(&mut self) -> usize {
|
fn get_width(&mut self) -> usize {
|
||||||
unsafe {
|
unsafe {
|
||||||
self.index_port.write(VBE_DISPI_INDEX_XRES);
|
self.index_port.write(VBE_DISPI_INDEX_XRES);
|
||||||
self.data_port.read() as usize
|
self.data_port.read() as usize
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_height(&mut self) -> usize {
|
fn get_height(&mut self) -> usize {
|
||||||
unsafe {
|
unsafe {
|
||||||
self.index_port.write(VBE_DISPI_INDEX_YRES);
|
self.index_port.write(VBE_DISPI_INDEX_YRES);
|
||||||
self.data_port.read() as usize
|
self.data_port.read() as usize
|
||||||
|
|
|
@ -21,13 +21,7 @@ pub(crate) struct PciDevice {
|
||||||
latency_timer: u8,
|
latency_timer: u8,
|
||||||
header_type: u8,
|
header_type: u8,
|
||||||
bist: u8,
|
bist: u8,
|
||||||
pub(crate) pci_header: PciHeader,
|
pub(crate) base_addresses: [u32; 6],
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone)]
|
|
||||||
pub(crate) enum PciHeader {
|
|
||||||
PciHeaderType0 {
|
|
||||||
base_addresses: [u32; 6],
|
|
||||||
cis: u32,
|
cis: u32,
|
||||||
sub_vendor_id: u16,
|
sub_vendor_id: u16,
|
||||||
sub_system_id: u16,
|
sub_system_id: u16,
|
||||||
|
@ -37,7 +31,6 @@ pub(crate) enum PciHeader {
|
||||||
interrupt_pin: u8,
|
interrupt_pin: u8,
|
||||||
minimum_grant: u8,
|
minimum_grant: u8,
|
||||||
maximum_latency: u8,
|
maximum_latency: u8,
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn find_pci_device(device_id: u32) -> Option<PciDevice> {
|
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 (status, command) = read_2_words(address, 0x04);
|
||||||
let (base_class, sub_class, prog_if, revision_id) = read_4_bytes(address, 0x08);
|
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 (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];
|
let mut base_addresses = [0u32; 6];
|
||||||
base_addresses[0] = read_offset(address, 0x10);
|
base_addresses[0] = read_offset(address, 0x10);
|
||||||
base_addresses[1] = read_offset(address, 0x14);
|
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) =
|
let (maximum_latency, minimum_grant, interrupt_pin, interrupt_line) =
|
||||||
read_4_bytes(address, 0x3C);
|
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,
|
base_addresses,
|
||||||
cis,
|
cis,
|
||||||
sub_system_id,
|
sub_system_id,
|
||||||
|
|
Loading…
Reference in a new issue