Add VGA implementation for mipsel malta board

Signed-off-by: Harry Chen <i@harrychen.xyz>
master
Harry Chen 6 years ago
parent 4e72c66087
commit c32b0d6bee

@ -4,12 +4,16 @@ use mips::registers::cp0;
#[path = "../../../../drivers/serial/ti_16c550c.rs"]
pub mod serial;
#[path = "../../../../drivers/gpu/qemu_stdvga.rs"]
pub mod vga;
#[path = "../../../../drivers/gpu/fb.rs"]
pub mod fb;
#[path = "../../../../drivers/console/mod.rs"]
pub mod console;
pub mod consts;
use fb::FramebufferInfo;
/// Initialize serial port first
pub fn init_serial_early() {
assert_has_not_been_called!("board::init must be called only once");
@ -27,9 +31,21 @@ pub fn init_serial_early() {
/// Initialize other board drivers
pub fn init_driver() {
// TODO: add possibly more drivers
// timer::init();
vga::init(0x92050000, 800, 600);
}
pub fn probe_fb_info(_width: u32, _height: u32, _depth: u32) -> fb::FramebufferResult {
Err(String::from("Framebuffer not usable on malta board"))
let fb_info = FramebufferInfo {
xres: 800,
yres: 600,
xres_virtual: 800,
yres_virtual: 600,
xoffset: 0,
yoffset: 0,
depth: 8,
pitch: 800,
bus_addr: 0x90000000,
screen_size: 800 * 600,
};
Ok((fb_info, fb::ColorConfig::VgaPalette, 0x90000000))
}

@ -0,0 +1,41 @@
//! driver for qemu stdvga (Cirrus)
use crate::util::{read, write};
const VGA_MMIO_OFFSET: usize = 0x400 - 0x3c0;
const VBE_MMIO_OFFSET: usize = 0x500;
const VGA_AR_ADDR: u16 = 0x3C0;
const VBE_DISPI_INDEX_XRES: u16 = 0x01;
const VBE_DISPI_INDEX_YRES: u16 = 0x02;
const VBE_DISPI_INDEX_BPP: u16 = 0x03;
const VBE_DISPI_INDEX_ENABLE: u16 = 0x04;
const VGA_AR_PAS: u8 = 0x20;
const VBE_DISPI_ENABLED: u16 = 0x01;
pub fn init(vga_base: usize, x_res: u16, y_res: u16) {
let vga_write_io = |offset: u16, value: u8| {
write(vga_base + VGA_MMIO_OFFSET + (offset as usize), value);
};
let vga_write_vbe = |offset: u16, value: u16| {
write(vga_base + VBE_MMIO_OFFSET + (offset as usize) * 2, value);
};
let vga_read_vbe = |offset: u16| -> u16 {
read(vga_base + VBE_MMIO_OFFSET + (offset as usize) * 2)
};
// enable palette access
vga_write_io(VGA_AR_ADDR, VGA_AR_PAS);
// set resolution and color depth
vga_write_vbe(VBE_DISPI_INDEX_XRES, x_res);
vga_write_vbe(VBE_DISPI_INDEX_YRES, y_res);
vga_write_vbe(VBE_DISPI_INDEX_BPP, 8);
// enable vbe
let vbe_enable = vga_read_vbe(VBE_DISPI_INDEX_ENABLE) | VBE_DISPI_ENABLED;
vga_write_vbe(VBE_DISPI_INDEX_ENABLE, vbe_enable);
}

@ -3,7 +3,7 @@
#![allow(dead_code)]
use core::fmt::{Write, Result, Arguments};
use core::ptr::{read_volatile, write_volatile};
use crate::util::{read, write};
use spin::Mutex;
pub struct SerialPort {
@ -83,16 +83,6 @@ impl Write for SerialPort {
}
}
fn write<T>(addr: usize, content: T) {
let cell = (addr) as *mut T;
unsafe { write_volatile(cell, content); }
}
fn read<T>(addr: usize) -> T {
let cell = (addr) as *const T;
unsafe { read_volatile(cell) }
}
const COM_RX :usize = 0; // In: Receive buffer (DLAB=0)
const COM_TX :usize = 0; // Out: Transmit buffer (DLAB=0)

@ -1,7 +1,7 @@
//! naive serial adapter driver for thinpad
use core::fmt::{Write, Result, Arguments};
use core::ptr::{read_volatile, write_volatile};
use crate::util::{read, write};
#[derive(Debug, Clone, Copy)]
pub struct SerialPort {
@ -73,16 +73,6 @@ impl Write for SerialPort {
}
}
fn write<T>(addr: usize, content: T) {
let cell = (addr) as *mut T;
unsafe { write_volatile(cell, content); }
}
fn read<T>(addr: usize) -> T {
let cell = (addr) as *const T;
unsafe { read_volatile(cell) }
}
pub static SERIAL_PORT: SerialPort = SerialPort {
base: 0
};

@ -3,8 +3,8 @@
#![allow(dead_code)]
use core::fmt::{Write, Result, Arguments};
use core::ptr::{read_volatile, write_volatile};
use spin::Mutex;
use crate::util::{read, write};
pub struct SerialPort {
base: usize
@ -83,17 +83,6 @@ impl Write for SerialPort {
}
}
fn write<T>(addr: usize, content: T) {
let cell = (addr) as *mut T;
unsafe { write_volatile(cell, content); }
}
fn read<T>(addr: usize) -> T {
let cell = (addr) as *const T;
unsafe { read_volatile(cell) }
}
const COM_RX :usize = 0x00; // In: Receive buffer (DLAB=0)
const COM_TX :usize = 0x00; // Out: Transmit buffer (DLAB=0)
const COM_INT_EN :usize = 0x08; // In: Interrupt enable

@ -1,3 +1,5 @@
use core::ptr::{read_volatile, write_volatile};
pub mod color;
pub mod escape_parser;
@ -13,3 +15,15 @@ pub unsafe fn write_cstr(ptr: *mut u8, s: &str) {
ptr.copy_from(s.as_ptr(), s.len());
ptr.add(s.len()).write(0);
}
#[inline(always)]
pub fn write<T>(addr: usize, content: T) {
let cell = (addr) as *mut T;
unsafe { write_volatile(cell, content); }
}
#[inline(always)]
pub fn read<T>(addr: usize) -> T {
let cell = (addr) as *const T;
unsafe { read_volatile(cell) }
}

@ -1 +1 @@
Subproject commit 215b8c52b33ef5f31935fe6be1abec57b64d8866
Subproject commit 07619a48d4e8051766c294d9d616337869e4c1a0
Loading…
Cancel
Save