From 2503fdb96defd2e096397b5e7d3bf0fa1d2058ab Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Mon, 12 Feb 2018 16:11:47 +0100 Subject: [PATCH] CONTEXT is instanciated at compile time now --- kernel-rs/src/context.rs | 13 +++++-------- kernel-rs/src/keyboard.rs | 27 +++++++++++++-------------- kernel-rs/src/lib.rs | 4 +--- kernel-rs/src/vga/buffer.rs | 2 +- 4 files changed, 20 insertions(+), 26 deletions(-) diff --git a/kernel-rs/src/context.rs b/kernel-rs/src/context.rs index 6eb76626..06ca9bb4 100644 --- a/kernel-rs/src/context.rs +++ b/kernel-rs/src/context.rs @@ -2,6 +2,11 @@ extern crate core; use vga; +pub static mut CONTEXT: Context = Context { + current_term: 0, + vga1: vga::Writer::new(), + vga2: vga::Writer::new(), +}; pub struct Context { pub current_term: u8, @@ -10,14 +15,6 @@ pub struct Context { } impl Context { - pub fn new() -> Context { - Context { - current_term: 0, - vga1: vga::Writer::new(), - vga2: vga::Writer::new(), - } - } - pub fn switch_term(&mut self) { self.current_term = { if self.current_term == 0 { 1 } diff --git a/kernel-rs/src/keyboard.rs b/kernel-rs/src/keyboard.rs index 7cc66263..8ea0148b 100644 --- a/kernel-rs/src/keyboard.rs +++ b/kernel-rs/src/keyboard.rs @@ -1,29 +1,28 @@ extern crate core; use cpuio; -use context; +use context::CONTEXT; // use vga::color::{Color, ColorCode}; pub static SCANCODE_TO_ASCII: [u8; 59] = *b"??1234567890-=??qwertyuiop[]\n?asdfghjkl;'`?\\zxcvbnm,./?*? ?"; -pub fn kbd_callback(context: &mut context::Context) { +pub fn kbd_callback() { // let terminal_two: vga::terminal::Terminal = vga::Screen::new(); let control = unsafe { cpuio::inb(0x64) }; if (control & 1) == 1 { let scancode = unsafe { cpuio::inb(0x60) }; - //TODO implement logic to translate scancode->ascii - match self::SCANCODE_TO_ASCII.get(scancode as usize) { - Some(&b'1') => { - context.switch_term(); - context.current_term().flush(); + unsafe { + match self::SCANCODE_TO_ASCII.get(scancode as usize) { + Some(&b'1') => { + CONTEXT.switch_term(); + CONTEXT.current_term().flush(); + } + Some(ascii) => { + CONTEXT.current_term().keypress(*ascii); + }, + None =>{}, + // None => println!("nokey ctrl {:x}", control), } - Some(ascii) => { - let mut terminal = context.current_term(); - terminal.keypress(*ascii); - }, - None =>{}, - // None => println!("nokey ctrl {:x}", control), } - // current_screen.flush(); } } diff --git a/kernel-rs/src/lib.rs b/kernel-rs/src/lib.rs index 51bb83a1..77f1d37d 100644 --- a/kernel-rs/src/lib.rs +++ b/kernel-rs/src/lib.rs @@ -41,10 +41,8 @@ pub extern fn kmain() -> ! { // WRITER.lock().color_code = ColorCode::new(Color::White, Color::Black); // println!(">> Kernel startup..."); - let mut context = context::Context::new(); - loop { - keyboard::kbd_callback(&mut context); + keyboard::kbd_callback(); } } diff --git a/kernel-rs/src/vga/buffer.rs b/kernel-rs/src/vga/buffer.rs index a7765905..eb946ea9 100644 --- a/kernel-rs/src/vga/buffer.rs +++ b/kernel-rs/src/vga/buffer.rs @@ -49,7 +49,7 @@ pub struct Writer { } impl Writer { - pub fn new() -> Writer { + pub const fn new() -> Writer { Writer { position: 0, color_code: ColorCode::new(Color::White, Color::Black),