2016-09-21 05:52:45 +02:00
|
|
|
#![feature(alloc)]
|
|
|
|
#![feature(asm)]
|
|
|
|
#![feature(heap_api)]
|
2016-09-21 20:18:48 +02:00
|
|
|
#![feature(question_mark)]
|
2016-09-21 05:52:45 +02:00
|
|
|
|
|
|
|
extern crate alloc;
|
2016-09-21 20:18:48 +02:00
|
|
|
extern crate ransid;
|
2016-09-21 05:52:45 +02:00
|
|
|
extern crate syscall;
|
|
|
|
|
2016-09-21 20:18:48 +02:00
|
|
|
use std::cell::RefCell;
|
2016-09-21 05:52:45 +02:00
|
|
|
use std::fs::File;
|
2016-09-21 20:18:48 +02:00
|
|
|
use std::io::{Read, Write};
|
2016-09-22 16:43:22 +02:00
|
|
|
use std::{slice, thread};
|
2016-09-21 20:18:48 +02:00
|
|
|
use ransid::{Console, Event};
|
2016-09-22 16:43:22 +02:00
|
|
|
use syscall::{physmap, physunmap, Packet, Result, Scheme, MAP_WRITE, MAP_WRITE_COMBINE};
|
2016-09-21 05:52:45 +02:00
|
|
|
|
|
|
|
use display::Display;
|
|
|
|
use mode_info::VBEModeInfo;
|
2016-09-22 16:43:22 +02:00
|
|
|
use primitive::fast_set64;
|
2016-09-21 05:52:45 +02:00
|
|
|
|
|
|
|
pub mod display;
|
|
|
|
pub mod mode_info;
|
|
|
|
pub mod primitive;
|
|
|
|
|
2016-09-21 20:18:48 +02:00
|
|
|
struct DisplayScheme {
|
|
|
|
console: RefCell<Console>,
|
2016-09-22 16:43:22 +02:00
|
|
|
display: RefCell<Display>
|
2016-09-21 20:18:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Scheme for DisplayScheme {
|
|
|
|
fn open(&self, _path: &[u8], _flags: usize) -> Result<usize> {
|
|
|
|
Ok(0)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn dup(&self, _id: usize) -> Result<usize> {
|
|
|
|
Ok(0)
|
|
|
|
}
|
|
|
|
|
2016-09-22 16:43:22 +02:00
|
|
|
fn fsync(&self, _id: usize) -> Result<usize> {
|
|
|
|
Ok(0)
|
|
|
|
}
|
|
|
|
|
2016-09-21 20:18:48 +02:00
|
|
|
fn write(&self, _id: usize, buf: &[u8]) -> Result<usize> {
|
|
|
|
let mut display = self.display.borrow_mut();
|
|
|
|
self.console.borrow_mut().write(buf, |event| {
|
|
|
|
match event {
|
|
|
|
Event::Char { x, y, c, color, .. } => display.char(x * 8, y * 16, c, color.data),
|
|
|
|
Event::Rect { x, y, w, h, color } => display.rect(x * 8, y * 16, w * 8, h * 16, color.data),
|
|
|
|
Event::Scroll { rows, color } => display.scroll(rows * 16, color.data)
|
|
|
|
}
|
|
|
|
});
|
|
|
|
Ok(buf.len())
|
|
|
|
}
|
|
|
|
|
2016-09-22 16:43:22 +02:00
|
|
|
fn close(&self, _id: usize) -> Result<usize> {
|
2016-09-21 20:18:48 +02:00
|
|
|
Ok(0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-21 05:52:45 +02:00
|
|
|
fn main() {
|
|
|
|
let width;
|
|
|
|
let height;
|
|
|
|
let physbaseptr;
|
|
|
|
|
|
|
|
{
|
|
|
|
let mode_info = unsafe { &*(physmap(0x5200, 4096, 0).expect("vesad: failed to map VBE info") as *const VBEModeInfo) };
|
|
|
|
|
|
|
|
width = mode_info.xresolution as usize;
|
|
|
|
height = mode_info.yresolution as usize;
|
|
|
|
physbaseptr = mode_info.physbaseptr as usize;
|
|
|
|
|
|
|
|
unsafe { let _ = physunmap(mode_info as *const _ as usize); }
|
|
|
|
}
|
|
|
|
|
|
|
|
if physbaseptr > 0 {
|
|
|
|
thread::spawn(move || {
|
2016-09-21 05:56:40 +02:00
|
|
|
let mut socket = File::create(":display").expect("vesad: failed to create display scheme");
|
2016-09-21 20:18:48 +02:00
|
|
|
|
2016-09-21 05:52:45 +02:00
|
|
|
let size = width * height;
|
|
|
|
|
|
|
|
let onscreen = unsafe { physmap(physbaseptr as usize, size * 4, MAP_WRITE | MAP_WRITE_COMBINE).expect("vesad: failed to map VBE LFB") };
|
|
|
|
unsafe { fast_set64(onscreen as *mut u64, 0, size/2) };
|
|
|
|
|
|
|
|
let offscreen = unsafe { alloc::heap::allocate(size * 4, 4096) };
|
|
|
|
unsafe { fast_set64(offscreen as *mut u64, 0, size/2) };
|
|
|
|
|
2016-09-21 20:18:48 +02:00
|
|
|
let scheme = DisplayScheme {
|
|
|
|
console: RefCell::new(Console::new(width/8, height/16)),
|
|
|
|
display: RefCell::new(Display::new(width, height,
|
|
|
|
unsafe { slice::from_raw_parts_mut(onscreen as *mut u32, size) },
|
|
|
|
unsafe { slice::from_raw_parts_mut(offscreen as *mut u32, size) }
|
2016-09-22 16:43:22 +02:00
|
|
|
))
|
2016-09-21 20:18:48 +02:00
|
|
|
};
|
2016-09-21 05:52:45 +02:00
|
|
|
|
2016-09-21 20:18:48 +02:00
|
|
|
loop {
|
|
|
|
let mut packet = Packet::default();
|
2016-09-22 16:43:22 +02:00
|
|
|
socket.read(&mut packet).expect("vesad: failed to read display scheme");
|
2016-09-21 20:18:48 +02:00
|
|
|
//println!("vesad: {:?}", packet);
|
|
|
|
scheme.handle(&mut packet);
|
2016-09-22 16:43:22 +02:00
|
|
|
socket.write(&packet).expect("vesad: failed to write display scheme");
|
2016-09-21 20:18:48 +02:00
|
|
|
}
|
2016-09-21 05:52:45 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|