feature: framebuffer console WIP

This commit is contained in:
Mark Poliakov 2021-12-27 17:20:22 +02:00
parent d4323e3c8f
commit c255c3fa08
2 changed files with 35 additions and 39 deletions

View File

@ -74,7 +74,7 @@ extern "C" fn __x86_64_bsp_main(mb_checksum: u32, mb_info_ptr: u32) -> ! {
// Setup hardware
unsafe {
x86_64::INTC.enable();
x86_64::INTC.enable().ok();
}
let fb_info = mb_info.framebuffer_tag().unwrap();

View File

@ -19,30 +19,14 @@ use crate::font;
use crate::sync::IrqSafeSpinLock;
use core::convert::TryFrom;
use core::fmt;
use libsys::{debug::TraceLevel, error::Errno};
use libsys::{debug::TraceLevel, error::Errno, mem::memcpy};
pub static LEVEL: Level = Level::Debug;
static COLOR_MAP: [u32; 16] = [
0x000000,
0x0000AA,
0x00AA00,
0x00AAAA,
0xAA0000,
0xAA00AA,
0xAA5500,
0xAAAAAA,
0x555555,
0x5555FF,
0x55FF55,
0x55FFFF,
0xFF5555,
0xFF55FF,
0xFFFF55,
0xFFFFFF,
];
static ATTR_MAP: [usize; 10] = [
0, 4, 2, 6, 1, 5, 3, 7, 7, 7
0x000000, 0x0000AA, 0x00AA00, 0x00AAAA, 0xAA0000, 0xAA00AA, 0xAA5500, 0xAAAAAA, 0x555555,
0x5555FF, 0x55FF55, 0x55FFFF, 0xFF5555, 0xFF55FF, 0xFFFF55, 0xFFFFFF,
];
static ATTR_MAP: [usize; 10] = [0, 4, 2, 6, 1, 5, 3, 7, 7, 7];
static DISPLAY: IrqSafeSpinLock<FramebufferOutput> = IrqSafeSpinLock::new(FramebufferOutput {
display: None,
col: 0,
@ -51,13 +35,13 @@ static DISPLAY: IrqSafeSpinLock<FramebufferOutput> = IrqSafeSpinLock::new(Frameb
bg: 0x000000,
esc: EscapeState::None,
esc_argv: [0; 8],
esc_argc: 0
esc_argc: 0,
});
enum EscapeState {
None,
Esc,
Data
Data,
}
struct FramebufferOutput {
@ -68,7 +52,7 @@ struct FramebufferOutput {
bg: u32,
esc: EscapeState,
esc_argv: [usize; 8],
esc_argc: usize
esc_argc: usize,
}
impl fmt::Write for FramebufferOutput {
@ -233,6 +217,23 @@ impl FramebufferOutput {
font::get().draw(fb, x * Self::CW, y * Self::CH, ch, self.fg, self.bg);
}
pub fn scroll(&mut self, fb: &FramebufferInfo) {
let stride = 4 * Self::CH * fb.width;
let h = fb.height / Self::CH - 1;
if self.row == h {
for y in 0..(h - 1) {
unsafe {
memcpy(
(fb.virt_base + stride * y) as *mut u8,
(fb.virt_base + (y + 1) * stride) as *const u8,
stride,
);
}
}
self.row = h - 1;
}
}
pub fn putc(&mut self, fb: &FramebufferInfo, ch: char) {
match self.esc {
EscapeState::None => {
@ -258,21 +259,15 @@ impl FramebufferOutput {
}
_ => {}
}
if (self.row + 1) * Self::CH >= fb.height {
todo!()
}
}
EscapeState::Esc => {
match ch {
'[' => {
self.esc = EscapeState::Data;
}
_ => {
self.esc = EscapeState::None;
}
EscapeState::Esc => match ch {
'[' => {
self.esc = EscapeState::Data;
}
}
_ => {
self.esc = EscapeState::None;
}
},
EscapeState::Data => {
match ch {
'0'..='9' => {
@ -298,12 +293,13 @@ impl FramebufferOutput {
if item / 10 == 3 {
self.fg = COLOR_MAP[ATTR_MAP[(item % 10) as usize]];
}
}
}
_ => {}
}
}
}
};
self.scroll(fb);
}
}