1
0
mirror of https://github.com/rcore-os/rCore.git synced 2024-11-22 16:16:16 +04:00

Get screen info from bootloader for vga

This commit is contained in:
Jiajie Chen 2019-05-24 16:20:25 +08:00
parent aefbecb127
commit e2bb86aa54
6 changed files with 109 additions and 83 deletions

10
kernel/Cargo.lock generated
View File

@ -16,11 +16,11 @@ dependencies = [
[[package]]
name = "apic"
version = "0.1.0"
source = "git+https://github.com/rcore-os/apic-rs#5ddc5fba952ae7420bcf3b7af3d79004e2b8c12f"
source = "git+https://github.com/rcore-os/apic-rs#3bc93873eaa4d21f09fc4134853d0a1ff917951b"
dependencies = [
"bit_field 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
"x86 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
"x86 0.15.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -88,7 +88,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "bootloader"
version = "0.4.0"
source = "git+https://github.com/rcore-os/bootloader?branch=vga#472731f974eb9cddbee030d5bda11fd1ee6959db"
source = "git+https://github.com/rcore-os/bootloader?branch=vga#861e0448eba3085d9af6b5b3c9454d5c8d59f82e"
dependencies = [
"apic 0.1.0 (git+https://github.com/rcore-os/apic-rs)",
"fixedvec 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
@ -622,7 +622,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "x86"
version = "0.12.0"
version = "0.15.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
@ -760,7 +760,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "f10e386af2b13e47c89e7236a7a14a086791a2b88ebad6df9bf42040195cf770"
"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
"checksum x86 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "841e1ca5a87068718a2a26f2473c6f93cf3b8119f9778fa0ae4b39b664d9e66a"
"checksum x86 0.15.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f21eecbd666e3a8edbf0b26d36f270f7a613d8986ca0eafb8205e324f7336dab"
"checksum x86_64 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "f9258d7e2dd25008d69e8c9e9ee37865887a5e1e3d06a62f1cb3f6c209e6f177"
"checksum x86_64 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)" = "bb8f09c32a991cc758ebcb9b7984f530095d32578a4e7b85db6ee1f0bbe4c9c6"
"checksum x86_64 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d69bf2d256c74df90fcc68aaf99862dd205310609e9d56247a5c82ead2f28a93"

View File

@ -3,29 +3,55 @@ pub mod fb;
use crate::consts::KERNEL_OFFSET;
use crate::memory::phys_to_virt;
use bootloader::bootinfo::{BootInfo, VbeModeInfo};
use core::mem::zeroed;
use fb::{ColorConfig, FramebufferInfo, FramebufferResult, FRAME_BUFFER};
pub fn init_driver() {
static mut VBE_MODE: VbeModeInfo = VbeModeInfo {
_1: [0; 6],
window_size: 0,
segment_a: 0,
segment_b: 0,
_2: 0,
pitch: 0,
width: 0,
height: 0,
_3: [0; 3],
bpp: 0,
_4: [0; 14],
framebuffer: 0,
};
pub fn init_driver(boot_info: &BootInfo) {
unsafe {
VBE_MODE = boot_info.vbe_info;
}
#[cfg(not(feature = "nographic"))]
fb::init();
}
pub fn probe_fb_info(width: u32, height: u32, depth: u32) -> FramebufferResult {
pub fn probe_fb_info(_width: u32, _height: u32, _depth: u32) -> FramebufferResult {
let width = unsafe { VBE_MODE.width as u32 };
let height = unsafe { VBE_MODE.height as u32 };
let pitch = unsafe { VBE_MODE.pitch as u32 };
let framebuffer = unsafe { VBE_MODE.framebuffer as usize };
let depth = unsafe { VBE_MODE.bpp as u32 };
let fb_info = FramebufferInfo {
xres: 1024,
yres: 768,
xres_virtual: 1024,
yres_virtual: 768,
xres: width,
yres: height,
xres_virtual: width,
yres_virtual: height,
xoffset: 0,
yoffset: 0,
depth: 24,
pitch: 1024, // TOKNOW
bus_addr: 0xfd00_0000,
screen_size: 1024 * 768 * 3,
depth: depth,
pitch: pitch, // TOKNOW
bus_addr: framebuffer as u32,
screen_size: width * height * 3,
};
// assume BGRA8888 for now
Ok((
fb_info,
fb::ColorConfig::BGRA8888,
phys_to_virt(0xfd00_0000),
phys_to_virt(framebuffer),
))
}

View File

@ -6,13 +6,13 @@ pub mod rtc_cmos;
pub mod serial;
pub mod vga;
use super::board;
use super::{board, BootInfo};
pub use self::board::fb;
#[path = "../../../drivers/console/mod.rs"]
pub mod console;
pub fn init() {
pub fn init(boot_info: &BootInfo) {
// Use IOAPIC instead of PIC
pic::disable();
@ -35,7 +35,7 @@ pub fn init() {
enable_irq(consts::PIRQG);
enable_irq(consts::PIRQH);
*/
board::init_driver();
board::init_driver(boot_info);
console::init();
//if let Some(con) = console::CONSOLE.lock().as_mut() {
//con.clear();

View File

@ -55,7 +55,7 @@ pub extern "C" fn _start(boot_info: &'static BootInfo) -> ! {
//get local apic id of cpu
cpu::init();
// Use IOAPIC instead of PIC, use APIC Timer instead of PIT, init serial&keyboard in x86_64
driver::init();
driver::init(boot_info);
// init pci/bus-based devices ,e.g. Intel 10Gb NIC, ...
crate::drivers::init();
// init cpu scheduler and process manager, and add user shell app in process manager

View File

@ -1,11 +1,11 @@
//! Framebuffer
use crate::fs::vga::{fb_bitfield, fb_var_screeninfo};
use alloc::string::String;
use core::fmt;
use lazy_static::lazy_static;
use log::*;
use spin::Mutex;
use crate::fs::vga::{fb_var_screeninfo, fb_bitfield};
/// Framebuffer information
#[repr(C)]
@ -239,7 +239,7 @@ impl Framebuffer {
self.fill(0, self.fb_info.screen_size as usize, 0);
}
pub fn fill_var_screeninfo(&self, var_info : &mut fb_var_screeninfo) {
pub fn fill_var_screeninfo(&self, var_info: &mut fb_var_screeninfo) {
var_info.xres = self.fb_info.xres;
var_info.yres = self.fb_info.yres;
var_info.xres_virtual = self.fb_info.xres_virtual;

View File

@ -70,17 +70,17 @@ impl INode for Vga {
info!("cmd {:#x} , data {:#x} vga not support ioctl !", cmd, data);
match cmd {
FBIOGET_FSCREENINFO => {
let fb_fix_info = unsafe{ &mut *(data as *mut fb_fix_screeninfo) };
let fb_fix_info = unsafe { &mut *(data as *mut fb_fix_screeninfo) };
fb_fix_info.line_length = 100;
Ok(())
},
}
FBIOGET_VSCREENINFO => {
let fb_var_info = unsafe{ &mut *(data as *mut fb_var_screeninfo) };
let fb_var_info = unsafe { &mut *(data as *mut fb_var_screeninfo) };
if let Some(fb) = FRAME_BUFFER.lock().as_ref() {
fb.fill_var_screeninfo(fb_var_info);
}
Ok(())
},
}
_ => {
warn!("use never support ioctl !");
Err(FsError::NotSupported)
@ -92,76 +92,76 @@ impl INode for Vga {
impl_inode!();
}
const FBIOGET_FSCREENINFO : u32 = 0x4602;
const FBIOGET_VSCREENINFO : u32 = 0x4600;
const FBIOGET_FSCREENINFO: u32 = 0x4602;
const FBIOGET_VSCREENINFO: u32 = 0x4600;
#[repr(C)]
struct fb_fix_screeninfo {
pub id : [u8;16], /* identification string eg "TT Builtin" */
pub smem_start : u64, /* Start of frame buffer mem */
pub id: [u8; 16], /* identification string eg "TT Builtin" */
pub smem_start: u64, /* Start of frame buffer mem */
/* (physical address) */
pub smem_len : u32, /* Length of frame buffer mem */
pub _type : u32, /* see FB_TYPE_* */
pub type_aux : u32, /* Interleave for interleaved Planes */
pub visual : u32, /* see FB_VISUAL_* */
pub xpanstep : u16, /* zero if no hardware panning */
pub ypanstep : u16, /* zero if no hardware panning */
pub ywrapstep : u16, /* zero if no hardware ywrap */
pub line_length : u32, /* length of a line in bytes */
pub mmio_start : u64, /* Start of Memory Mapped I/O */
pub smem_len: u32, /* Length of frame buffer mem */
pub _type: u32, /* see FB_TYPE_* */
pub type_aux: u32, /* Interleave for interleaved Planes */
pub visual: u32, /* see FB_VISUAL_* */
pub xpanstep: u16, /* zero if no hardware panning */
pub ypanstep: u16, /* zero if no hardware panning */
pub ywrapstep: u16, /* zero if no hardware ywrap */
pub line_length: u32, /* length of a line in bytes */
pub mmio_start: u64, /* Start of Memory Mapped I/O */
/* (physical address) */
pub mmio_len : u32, /* Length of Memory Mapped I/O */
pub accel : u32, /* Indicate to driver which */
pub mmio_len: u32, /* Length of Memory Mapped I/O */
pub accel: u32, /* Indicate to driver which */
/* specific chip/card we have */
pub capabilities : u16, /* see FB_CAP_* */
pub reserved : [u16;2], /* Reserved for future compatibility */
pub capabilities: u16, /* see FB_CAP_* */
pub reserved: [u16; 2], /* Reserved for future compatibility */
}
#[repr(C)]
pub struct fb_var_screeninfo {
pub xres : u32, /* visible resolution */
pub yres : u32,
pub xres_virtual : u32, /* virtual resolution */
pub yres_virtual : u32,
pub xoffset : u32, /* offset from virtual to visible */
pub yoffset : u32, /* resolution */
pub xres: u32, /* visible resolution */
pub yres: u32,
pub xres_virtual: u32, /* virtual resolution */
pub yres_virtual: u32,
pub xoffset: u32, /* offset from virtual to visible */
pub yoffset: u32, /* resolution */
pub bits_per_pixel : u32, /* guess what */
pub grayscale : u32, /* 0 = color, 1 = grayscale, */
pub bits_per_pixel: u32, /* guess what */
pub grayscale: u32, /* 0 = color, 1 = grayscale, */
/* >1 = FOURCC */
pub red : fb_bitfield , /* bitfield in fb mem if true color, */
pub green : fb_bitfield , /* else only length is significant */
pub blue : fb_bitfield ,
pub transp : fb_bitfield , /* transparency */
pub red: fb_bitfield, /* bitfield in fb mem if true color, */
pub green: fb_bitfield, /* else only length is significant */
pub blue: fb_bitfield,
pub transp: fb_bitfield, /* transparency */
pub nonstd : u32, /* != 0 Non standard pixel format */
pub nonstd: u32, /* != 0 Non standard pixel format */
pub activate : u32, /* see FB_ACTIVATE_* */
pub activate: u32, /* see FB_ACTIVATE_* */
pub height : u32, /* height of picture in mm */
pub width : u32, /* width of picture in mm */
pub height: u32, /* height of picture in mm */
pub width: u32, /* width of picture in mm */
pub accel_flags : u32, /* (OBSOLETE) see fb_info.flags */
pub accel_flags: u32, /* (OBSOLETE) see fb_info.flags */
/* Timing: All values in pixclocks, except pixclock (of course) */
pub pixclock : u32, /* pixel clock in ps (pico seconds) */
pub left_margin : u32, /* time from sync to picture */
pub right_margin : u32, /* time from picture to sync */
pub upper_margin : u32, /* time from sync to picture */
pub lower_margin : u32,
pub hsync_len : u32, /* length of horizontal sync */
pub vsync_len : u32, /* length of vertical sync */
pub sync : u32, /* see FB_SYNC_* */
pub vmode : u32, /* see FB_VMODE_* */
pub rotate : u32, /* angle we rotate counter clockwise */
pub colorspace : u32, /* colorspace for FOURCC-based modes */
pub reserved : [u32;4], /* Reserved for future compatibility */
pub pixclock: u32, /* pixel clock in ps (pico seconds) */
pub left_margin: u32, /* time from sync to picture */
pub right_margin: u32, /* time from picture to sync */
pub upper_margin: u32, /* time from sync to picture */
pub lower_margin: u32,
pub hsync_len: u32, /* length of horizontal sync */
pub vsync_len: u32, /* length of vertical sync */
pub sync: u32, /* see FB_SYNC_* */
pub vmode: u32, /* see FB_VMODE_* */
pub rotate: u32, /* angle we rotate counter clockwise */
pub colorspace: u32, /* colorspace for FOURCC-based modes */
pub reserved: [u32; 4], /* Reserved for future compatibility */
}
#[repr(C)]
pub struct fb_bitfield {
pub offset : u32, /* beginning of bitfield */
pub length : u32, /* length of bitfield */
pub msb_right : u32, /* != 0 : Most significant bit is */
pub offset: u32, /* beginning of bitfield */
pub length: u32, /* length of bitfield */
pub msb_right: u32, /* != 0 : Most significant bit is */
/* right */
}