Merge branch 'master' of https://github.com/jzck/kernel
This commit is contained in:
commit
d8e0647153
4 changed files with 53 additions and 44 deletions
|
|
@ -2,30 +2,19 @@ extern crate core;
|
||||||
|
|
||||||
use vga;
|
use vga;
|
||||||
|
|
||||||
|
pub static mut CONTEXT: Context = Context {
|
||||||
|
current_term: 0,
|
||||||
|
vga1: vga::Writer::new(),
|
||||||
|
vga2: vga::Writer::new(),
|
||||||
|
};
|
||||||
|
|
||||||
pub struct Context {
|
pub struct Context {
|
||||||
pub current_term: u8,
|
pub current_term: u8,
|
||||||
pub vga1: vga::Writer<&'static mut [u8]>,
|
pub vga1: vga::Writer,
|
||||||
pub vga2: vga::Writer<&'static mut [u8]>,
|
pub vga2: vga::Writer,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Context {
|
impl Context {
|
||||||
pub fn new() -> Context {
|
|
||||||
let slice1 = unsafe {
|
|
||||||
core::slice::from_raw_parts_mut(0xb8000 as *mut u8, 4000)
|
|
||||||
};
|
|
||||||
|
|
||||||
let slice2 = unsafe {
|
|
||||||
core::slice::from_raw_parts_mut(0xb8000 as *mut u8, 4000)
|
|
||||||
};
|
|
||||||
|
|
||||||
Context {
|
|
||||||
current_term: 0,
|
|
||||||
vga1: vga::Writer::new(slice1),
|
|
||||||
vga2: vga::Writer::new(slice2),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn switch_term(&mut self) {
|
pub fn switch_term(&mut self) {
|
||||||
self.current_term = {
|
self.current_term = {
|
||||||
if self.current_term == 0 { 1 }
|
if self.current_term == 0 { 1 }
|
||||||
|
|
@ -33,7 +22,7 @@ impl Context {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn current_term(&mut self) -> &mut vga::Writer<&'static mut [u8]>{
|
pub fn current_term(&mut self) -> &mut vga::Writer{
|
||||||
if self.current_term == 0 {
|
if self.current_term == 0 {
|
||||||
&mut self.vga1
|
&mut self.vga1
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
extern crate core;
|
extern crate core;
|
||||||
|
|
||||||
use cpuio;
|
use cpuio;
|
||||||
use context;
|
use context::CONTEXT;
|
||||||
// use vga::color::{Color, ColorCode};
|
// use vga::color::{Color, ColorCode};
|
||||||
|
|
||||||
const MAX_KEYS: usize = 59;
|
const MAX_KEYS: usize = 59;
|
||||||
|
|
@ -77,7 +77,7 @@ fn check_key_state(key: u8) -> (bool, usize) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn kbd_callback(context: &mut context::Context) {
|
pub fn kbd_callback() {
|
||||||
static mut SHIFT: bool = false;
|
static mut SHIFT: bool = false;
|
||||||
static mut CTRL: bool = false;
|
static mut CTRL: bool = false;
|
||||||
static mut ALT: bool = false;
|
static mut ALT: bool = false;
|
||||||
|
|
@ -95,28 +95,28 @@ pub fn kbd_callback(context: &mut context::Context) {
|
||||||
0x38 => {ALT = !is_release},
|
0x38 => {ALT = !is_release},
|
||||||
0x1D => {CTRL = !is_release},
|
0x1D => {CTRL = !is_release},
|
||||||
0x0F => {
|
0x0F => {
|
||||||
context.current_term().keypress('T' as u8);
|
CONTEXT.current_term().keypress('T' as u8);
|
||||||
context.switch_term();
|
CONTEXT.switch_term();
|
||||||
context.current_term().keypress('T' as u8);
|
CONTEXT.current_term().keypress('T' as u8);
|
||||||
context.current_term().flush();
|
CONTEXT.current_term().flush();
|
||||||
context.current_term().keypress('T' as u8);
|
CONTEXT.current_term().keypress('T' as u8);
|
||||||
context.current_term().keypress('T' as u8);
|
CONTEXT.current_term().keypress('T' as u8);
|
||||||
context.current_term().keypress('T' as u8);
|
CONTEXT.current_term().keypress('T' as u8);
|
||||||
},
|
},
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// Some(b"2@") if ALT => {
|
// Some(b"2@") if ALT => {
|
||||||
// context.switch_term();
|
// CONTEXT.switch_term();
|
||||||
// context.current_term().flush();
|
// CONTEXT.current_term().flush();
|
||||||
// },
|
// },
|
||||||
Some(b"1!") if CTRL => {
|
Some(b"1!") if CTRL => {
|
||||||
context.switch_term();
|
CONTEXT.switch_term();
|
||||||
context.current_term().keypress('>' as u8);
|
CONTEXT.current_term().keypress('>' as u8);
|
||||||
context.current_term().flush();
|
CONTEXT.current_term().flush();
|
||||||
},
|
},
|
||||||
Some(ascii) if !is_release => {
|
Some(ascii) if !is_release => {
|
||||||
let mut terminal = context.current_term();
|
let mut terminal = CONTEXT.current_term();
|
||||||
if SHIFT {
|
if SHIFT {
|
||||||
terminal.keypress(ascii[1]);
|
terminal.keypress(ascii[1]);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -53,10 +53,8 @@ pub extern fn kmain() -> ! {
|
||||||
// WRITER.lock().color_code = ColorCode::new(Color::White, Color::Black);
|
// WRITER.lock().color_code = ColorCode::new(Color::White, Color::Black);
|
||||||
// println!(">> Kernel startup...");
|
// println!(">> Kernel startup...");
|
||||||
|
|
||||||
let mut context = context::Context::new();
|
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
keyboard::kbd_callback(&mut context);
|
keyboard::kbd_callback();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,20 +16,41 @@ struct ScreenChar {
|
||||||
color_code: ColorCode,
|
color_code: ColorCode,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// macro_rules! print {
|
||||||
|
// ($($arg:tt)*) => ({
|
||||||
|
// $crate::vga_buffer::print(format_args!($($arg)*));
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
|
||||||
|
// macro_rules! println {
|
||||||
|
// ($fmt:expr) => (print!(concat!($fmt, "\n")));
|
||||||
|
// ($fmt:expr, $($arg:tt)*) => (print!(concat!($fmt, "\n"), $($arg)*));
|
||||||
|
// }
|
||||||
|
|
||||||
|
// pub fn print(args: fmt::Arguments) {
|
||||||
|
// use core::fmt::Write;
|
||||||
|
// context.current_screen().write_fmt(args).unwrap();
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
extern crate core;
|
||||||
|
|
||||||
|
// pub const unsafe fn vga_slice() -> &'static [u8] {
|
||||||
|
// unsafe { core::slice::from_raw_parts_mut(0xb8000 as *mut u8, 4000) }
|
||||||
|
// }
|
||||||
|
|
||||||
const BUFFER_ROWS: usize = 25;
|
const BUFFER_ROWS: usize = 25;
|
||||||
const BUFFER_COLS: usize = 80 * 2;
|
const BUFFER_COLS: usize = 80 * 2;
|
||||||
|
|
||||||
pub struct Writer<T: AsMut<[u8]>> {
|
pub struct Writer {
|
||||||
pub position: usize,
|
pub position: usize,
|
||||||
color_code: ColorCode,
|
color_code: ColorCode,
|
||||||
slice: T,
|
|
||||||
buffer: [u8; BUFFER_ROWS * BUFFER_COLS],
|
buffer: [u8; BUFFER_ROWS * BUFFER_COLS],
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: AsMut<[u8]>> Writer<T> {
|
impl Writer {
|
||||||
pub fn new(slice: T) -> Writer<T> {
|
pub const fn new() -> Writer {
|
||||||
Writer {
|
Writer {
|
||||||
slice,
|
|
||||||
position: 0,
|
position: 0,
|
||||||
color_code: ColorCode::new(Color::White, Color::Black),
|
color_code: ColorCode::new(Color::White, Color::Black),
|
||||||
buffer: [0; BUFFER_ROWS * BUFFER_COLS],
|
buffer: [0; BUFFER_ROWS * BUFFER_COLS],
|
||||||
|
|
@ -70,7 +91,8 @@ impl<T: AsMut<[u8]>> Writer<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn flush(&mut self) {
|
pub fn flush(&mut self) {
|
||||||
self.slice.as_mut().clone_from_slice(&self.buffer);
|
let slice = unsafe { core::slice::from_raw_parts_mut(0xb8000 as *mut u8, 4000) };
|
||||||
|
slice.as_mut().clone_from_slice(&self.buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn scroll(&mut self) {
|
fn scroll(&mut self) {
|
||||||
|
|
@ -92,7 +114,7 @@ impl<T: AsMut<[u8]>> Writer<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
use core::fmt;
|
use core::fmt;
|
||||||
impl<T: AsMut<[u8]>> fmt::Write for Writer<T> {
|
impl fmt::Write for Writer {
|
||||||
fn write_str(&mut self, s: &str) -> ::core::fmt::Result {
|
fn write_str(&mut self, s: &str) -> ::core::fmt::Result {
|
||||||
for byte in s.bytes() {
|
for byte in s.bytes() {
|
||||||
self.write_byte(byte)
|
self.write_byte(byte)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue