Merge branch 'KFS-2' of https://github.com/jzck/kernel into KFS-2
This commit is contained in:
commit
e72afcd086
3 changed files with 99 additions and 94 deletions
|
|
@ -86,44 +86,41 @@ pub fn kbd_callback() {
|
|||
if (control & 1) == 1 {
|
||||
let scancode = cpuio::inb(0x60);
|
||||
let (is_release, scancode) = check_key_state(scancode);
|
||||
//TODO implement logic to translate scancode->ascii
|
||||
unsafe {//TODO remove unsafe
|
||||
match self::KEYMAP_US.get(scancode as usize) {
|
||||
Some(b"\0\0") => {
|
||||
match scancode {
|
||||
0x2A | 0x36 => {SHIFT = !is_release},
|
||||
0x38 => {ALT = !is_release; println!("atl")},
|
||||
0x1D => {CTRL = !is_release; println!("ctrl")},
|
||||
0x0F if !is_release => {
|
||||
CONTEXT.switch_term();
|
||||
CONTEXT.current_term().flush();
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
},
|
||||
// Some(b"2@") if ALT => {
|
||||
// CONTEXT.switch_term();
|
||||
// CONTEXT.current_term().flush();
|
||||
// },
|
||||
// Some(b"1!") if CTRL && !is_release => {
|
||||
// CONTEXT.switch_term();
|
||||
// CONTEXT.current_term().keypress('>' as u8);
|
||||
// CONTEXT.current_term().flush();
|
||||
// },
|
||||
Some(ascii) if !is_release => {
|
||||
let mut terminal = CONTEXT.current_term();
|
||||
if SHIFT {
|
||||
terminal.keypress(ascii[1]);
|
||||
}
|
||||
else {
|
||||
terminal.keypress(ascii[0]);
|
||||
}
|
||||
},
|
||||
Some(_) => {},
|
||||
None =>{},
|
||||
// None => println!("nokey ctrl {:x}", control),
|
||||
match self::KEYMAP_US.get(scancode as usize) {
|
||||
Some(b"\0\0") => {
|
||||
match scancode {
|
||||
0x2A | 0x36 => {SHIFT = !is_release},
|
||||
0x38 => {ALT = !is_release; println!("atl")},
|
||||
0x1D => {CTRL = !is_release; println!("ctrl")},
|
||||
0x0F if !is_release => {
|
||||
CONTEXT.switch_term();
|
||||
CONTEXT.current_term().flush();
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
},
|
||||
// Some(b"2@") if ALT => {
|
||||
// CONTEXT.switch_term();
|
||||
// CONTEXT.current_term().flush();
|
||||
// },
|
||||
// Some(b"1!") if CTRL && !is_release => {
|
||||
// CONTEXT.switch_term();
|
||||
// CONTEXT.current_term().keypress('>' as u8);
|
||||
// CONTEXT.current_term().flush();
|
||||
// },
|
||||
Some(ascii) if !is_release => {
|
||||
let mut terminal = CONTEXT.current_term();
|
||||
if SHIFT {
|
||||
terminal.keypress(ascii[1]);
|
||||
}
|
||||
else {
|
||||
terminal.keypress(ascii[0]);
|
||||
}
|
||||
},
|
||||
Some(_) => {},
|
||||
None =>{},
|
||||
}
|
||||
}
|
||||
}
|
||||
// current_screen.flush();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,15 +11,15 @@ extern crate rlibc;
|
|||
#[macro_use]
|
||||
mod vga;
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[macro_use]
|
||||
mod context;
|
||||
mod keyboard;
|
||||
|
||||
use context::CONTEXT;
|
||||
use vga::{Color, ColorCode};
|
||||
|
||||
#[allow(dead_code)]
|
||||
mod cpuio;
|
||||
|
||||
|
||||
//TODO implement ACPI to have such functionality
|
||||
/// Reboot the kernel
|
||||
///
|
||||
|
|
@ -56,38 +56,28 @@ fn shutdown() -> ! {
|
|||
|
||||
#[no_mangle]
|
||||
pub extern fn kmain() -> ! {
|
||||
// use vga::VgaScreen;
|
||||
// use vga::color::Color;
|
||||
// use vga::color::ColorCode;
|
||||
|
||||
println!(r#" ,--, "#);
|
||||
println!(r#" ,--.'| ,----, "#);
|
||||
println!(r#" ,--, | : .' .' \ "#);
|
||||
println!(r#",---.'| : ' ,----,' | "#);
|
||||
println!(r#"; : | | ; | : . ; "#);
|
||||
println!(r#"| | : _' | ; |.' / "#);
|
||||
println!(r#": : |.' | `----'/ ; "#);
|
||||
println!(r#"| ' ' ; : / ; / "#);
|
||||
println!(r#"\ \ .'. | ; / /-, "#);
|
||||
println!(r#" `---`: | ' / / /.`| "#);
|
||||
println!(r#" ' ; |./__; : "#);
|
||||
println!(r#" | : ;| : .' "#);
|
||||
println!(r#" ' ,/ ; | .' "#);
|
||||
println!(r#" '--' `---' "#);
|
||||
println!(">> Kernel startup...");
|
||||
unsafe { CONTEXT.current_term().color_code = ColorCode::new(Color::White, Color::Cyan); }
|
||||
print!("{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
|
||||
format_args!("{: ^80}", r#" ,--, "#),
|
||||
format_args!("{: ^80}", r#" ,--.'| ,----, "#),
|
||||
format_args!("{: ^80}", r#" ,--, | : .' .' \ "#),
|
||||
format_args!("{: ^80}", r#",---.'| : ' ,----,' | "#),
|
||||
format_args!("{: ^80}", r#"; : | | ; | : . ; "#),
|
||||
format_args!("{: ^80}", r#"| | : _' | ; |.' / "#),
|
||||
format_args!("{: ^80}", r#": : |.' | `----'/ ; "#),
|
||||
format_args!("{: ^80}", r#"| ' ' ; : / ; / "#),
|
||||
format_args!("{: ^80}", r#"\ \ .'. | ; / /-, "#),
|
||||
format_args!("{: ^80}", r#" `---`: | ' / / /.`| "#),
|
||||
format_args!("{: ^80}", r#" ' ; |./__; : "#),
|
||||
format_args!("{: ^80}", r#" | : ;| : .' "#),
|
||||
format_args!("{: ^80}", r#" ' ,/ ; | .' "#),
|
||||
format_args!("{: ^80}", r#" '--' `---' "#));
|
||||
unsafe { CONTEXT.current_term().color_code = ColorCode::new(Color::White, Color::Black); }
|
||||
print!(">");
|
||||
|
||||
loop {
|
||||
keyboard::kbd_callback();
|
||||
}
|
||||
// let control = unsafe { cpuio::inb(0x64) };
|
||||
// if (control & 1) == 1 {
|
||||
// let keycode = unsafe { cpuio::inb(0x60) };
|
||||
// match keyboard::KEY_CODE_TO_ASCII.get(keycode as usize) {
|
||||
// Some(ascii) => print!("{}", *ascii as char),
|
||||
// None =>{},
|
||||
// // None => println!("nokey ctrl {:x}", control),
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
#[lang = "eh_personality"] #[no_mangle]
|
||||
|
|
@ -97,12 +87,12 @@ pub extern fn eh_personality() {
|
|||
|
||||
#[lang = "panic_fmt"] #[no_mangle]
|
||||
pub extern fn panic_fmt(
|
||||
// fmt: core::fmt::Arguments, file: &'static str, line: u32
|
||||
fmt: core::fmt::Arguments, file: &'static str, line: u32
|
||||
)
|
||||
-> ! {
|
||||
// println!("PANIC: {}", fmt);
|
||||
// println!("FILE: {}", file);
|
||||
// println!("LINE: {}", line);
|
||||
println!("PANIC: {}", fmt);
|
||||
println!("FILE: {}", file);
|
||||
println!("LINE: {}", line);
|
||||
loop {}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@
|
|||
|
||||
use super::{Color, ColorCode};
|
||||
use ::context::CONTEXT;
|
||||
use cpuio;
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
#[repr(C)]
|
||||
|
|
@ -31,69 +32,87 @@ macro_rules! println {
|
|||
pub fn print(args: fmt::Arguments) {
|
||||
use core::fmt::Write;
|
||||
unsafe { CONTEXT.current_term().write_fmt(args).unwrap() };
|
||||
unsafe { CONTEXT.current_term().flush() };
|
||||
}
|
||||
|
||||
|
||||
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_COLS: usize = 80 * 2;
|
||||
|
||||
pub struct Writer {
|
||||
pub position: usize,
|
||||
color_code: ColorCode,
|
||||
pub buffer_pos: usize,
|
||||
pub color_code: ColorCode,
|
||||
buffer: [u8; BUFFER_ROWS * BUFFER_COLS],
|
||||
command: [u8; 10],
|
||||
command_len: usize,
|
||||
}
|
||||
|
||||
impl Writer {
|
||||
pub const fn new() -> Writer {
|
||||
Writer {
|
||||
position: 0,
|
||||
buffer_pos: 0,
|
||||
color_code: ColorCode::new(Color::White, Color::Black),
|
||||
buffer: [0; BUFFER_ROWS * BUFFER_COLS],
|
||||
command: [0; 10],
|
||||
command_len: 0,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn keypress(&mut self, ascii: u8) {
|
||||
self.write_byte(ascii);
|
||||
match ascii {
|
||||
b'\n' => {
|
||||
self.command_len = 0;
|
||||
self.write_byte(b'\n');
|
||||
println!("{:?}", self.command.iter());
|
||||
self.write_byte(b'>');
|
||||
}
|
||||
byte => {
|
||||
if self.command_len >= 10 { return };
|
||||
|
||||
self.write_byte(byte);
|
||||
self.command_len += 1;
|
||||
}
|
||||
}
|
||||
self.flush();
|
||||
}
|
||||
|
||||
pub fn write_byte(&mut self, byte: u8) {
|
||||
let i = self.position;
|
||||
let i = self.buffer_pos;
|
||||
|
||||
match byte {
|
||||
|
||||
b'\n' => {
|
||||
//reset cursor
|
||||
self.buffer[self.position + 1] = ColorCode::new(Color::White, Color::Black).0;
|
||||
let current_line = self.position / (BUFFER_COLS);
|
||||
self.position = (current_line + 1) * BUFFER_COLS;
|
||||
let current_line = self.buffer_pos / (BUFFER_COLS);
|
||||
self.buffer_pos = (current_line + 1) * BUFFER_COLS;
|
||||
}
|
||||
byte => {
|
||||
self.buffer[i] = byte;
|
||||
self.buffer[i + 1] = self.color_code.0;
|
||||
self.position += 2;
|
||||
self.buffer_pos += 2;
|
||||
}
|
||||
}
|
||||
|
||||
if self.position >= self.buffer.len() {
|
||||
if self.buffer_pos >= self.buffer.len() {
|
||||
self.scroll();
|
||||
}
|
||||
}
|
||||
|
||||
// cursor
|
||||
self.buffer[self.position] = b' ';
|
||||
self.buffer[self.position + 1] = ColorCode::new(Color::LightGray, Color::LightGray).0;
|
||||
|
||||
fn flush_cursor(&self)
|
||||
{
|
||||
let cursor_position = self.buffer_pos / 2;
|
||||
// 14 awaits the rightmost 8bits
|
||||
cpuio::outb(14, 0x3D4);
|
||||
cpuio::outb((cursor_position >> 8) as u8, 0x3D5);
|
||||
// 15 awaits the leftmost 8bits
|
||||
cpuio::outb(15, 0x3D4);
|
||||
cpuio::outb((cursor_position >> 0) as u8 & 0x00ff, 0x3D5);
|
||||
}
|
||||
|
||||
pub fn flush(&mut self) {
|
||||
let slice = unsafe { core::slice::from_raw_parts_mut(0xb8000 as *mut u8, 4000) };
|
||||
slice.as_mut().clone_from_slice(&self.buffer);
|
||||
self.flush_cursor();
|
||||
}
|
||||
|
||||
fn scroll(&mut self) {
|
||||
|
|
@ -110,7 +129,7 @@ impl Writer {
|
|||
self.buffer[((BUFFER_ROWS - 1) * BUFFER_COLS) + (col * 2)] = b' ';
|
||||
}
|
||||
|
||||
self.position = (BUFFER_ROWS - 1) * BUFFER_COLS;
|
||||
self.buffer_pos = (BUFFER_ROWS - 1) * BUFFER_COLS;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -120,7 +139,6 @@ impl fmt::Write for Writer {
|
|||
for byte in s.bytes() {
|
||||
self.write_byte(byte)
|
||||
}
|
||||
self.flush();
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue