Fix mouse position, map display on APs

This commit is contained in:
Jeremy Soller 2016-09-01 08:12:50 -06:00
parent 1e5d992ab5
commit 722d738254
6 changed files with 53 additions and 9 deletions

View file

@ -51,8 +51,6 @@ impl Context {
#[inline(never)]
#[naked]
pub unsafe fn switch_to(&mut self, next: &mut Context) {
asm!("xchg bx, bx" : : : "memory" : "intel", "volatile");
/*
asm!("fxsave [$0]" : : "r"(self.fx) : "memory" : "intel", "volatile");
self.loadable = true;

View file

@ -1,4 +1,4 @@
use core::slice;
use core::{cmp, slice};
use spin::Mutex;
use memory::Frame;
@ -72,6 +72,26 @@ pub unsafe fn init(active_table: &mut ActivePageTable) {
}
}
pub unsafe fn init_ap(active_table: &mut ActivePageTable) {
active_table.identity_map(Frame::containing_address(PhysicalAddress::new(0x5200)), entry::PRESENT | entry::NO_EXECUTE);
let mode_info = &*(0x5200 as *const VBEModeInfo);
if mode_info.physbaseptr > 0 {
let width = mode_info.xresolution as usize;
let height = mode_info.yresolution as usize;
let start = mode_info.physbaseptr as usize;
let size = width * height;
{
let start_frame = Frame::containing_address(PhysicalAddress::new(start));
let end_frame = Frame::containing_address(PhysicalAddress::new(start + size * 4 - 1));
for frame in Frame::range_inclusive(start_frame, end_frame) {
active_table.identity_map(frame, entry::PRESENT | entry::WRITABLE | entry::NO_EXECUTE);
}
}
}
}
/// A display
pub struct Display {
pub width: usize,
@ -87,4 +107,20 @@ impl Display {
data: data,
}
}
pub fn rect(&mut self, x: usize, y: usize, w: usize, h: usize, color: u32) {
let start_y = cmp::min(self.height - 1, y);
let end_y = cmp::min(self.height, y + h);
let start_x = cmp::min(self.width - 1, x);
let len = cmp::min(self.width, x + w) - start_x;
for y in start_y..end_y {
let offset = y * self.width + start_x;
let row = &mut self.data[offset..offset + len];
for pixel in row.iter_mut() {
*pixel = color;
}
}
}
}

View file

@ -7,3 +7,7 @@ pub unsafe fn init(active_table: &mut ActivePageTable){
display::init(active_table);
ps2::init();
}
pub unsafe fn init_ap(active_table: &mut ActivePageTable) {
display::init_ap(active_table);
}

View file

@ -285,8 +285,8 @@ impl Ps2 {
//print!("MOUSE {:?}, {}, {}, {}\n", flags, dx, dy, extra);
if let Some(ref mut display) = *super::display::DISPLAY.lock() {
self.mouse_x = cmp::min(display.width, cmp::max(0, self.mouse_x as isize + dx) as usize);
self.mouse_y = cmp::min(display.height, cmp::max(0, self.mouse_y as isize - dy) as usize);
self.mouse_x = cmp::max(0, cmp::min(display.width as isize - 1, self.mouse_x as isize + dx)) as usize;
self.mouse_y = cmp::max(0, cmp::min(display.height as isize - 1, self.mouse_y as isize - dy)) as usize;
let offset = self.mouse_y * display.width + self.mouse_x;
display.data[offset as usize] = 0xFF0000;
}

View file

@ -44,8 +44,7 @@ macro_rules! interrupt {
}
// Push scratch registers
asm!("xchg bx, bx
push rax
asm!("push rax
push rcx
push rdx
push rdi
@ -86,8 +85,7 @@ macro_rules! interrupt_error {
}
// Push scratch registers
asm!("xchg bx, bx
push rax
asm!("push rax
push rcx
push rdx
push rdi

View file

@ -165,6 +165,9 @@ pub unsafe extern fn kstart_ap(stack_start: usize, stack_end: usize) -> ! {
assert_eq!(TDATA_TEST_NONZERO, 0xFFFFFFFFFFFFFFFE);
}
// Init devices for AP
device::init_ap(&mut active_table);
// Map heap
{
let heap_start_page = Page::containing_address(VirtualAddress::new(HEAP_START));
@ -192,5 +195,10 @@ pub unsafe extern fn kstart_ap(stack_start: usize, stack_end: usize) -> ! {
interrupt::pause();
}
if let Some(ref mut display) = *device::display::DISPLAY.lock() {
let width = display.width;
display.rect(0, ap_number * 32, width, 16, 0xFF00);
}
kmain_ap(ap_number);
}