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 {
|
if (control & 1) == 1 {
|
||||||
let scancode = cpuio::inb(0x60);
|
let scancode = cpuio::inb(0x60);
|
||||||
let (is_release, scancode) = check_key_state(scancode);
|
let (is_release, scancode) = check_key_state(scancode);
|
||||||
//TODO implement logic to translate scancode->ascii
|
|
||||||
unsafe {//TODO remove unsafe
|
unsafe {//TODO remove unsafe
|
||||||
match self::KEYMAP_US.get(scancode as usize) {
|
match self::KEYMAP_US.get(scancode as usize) {
|
||||||
Some(b"\0\0") => {
|
Some(b"\0\0") => {
|
||||||
match scancode {
|
match scancode {
|
||||||
0x2A | 0x36 => {SHIFT = !is_release},
|
0x2A | 0x36 => {SHIFT = !is_release},
|
||||||
0x38 => {ALT = !is_release; println!("atl")},
|
0x38 => {ALT = !is_release; println!("atl")},
|
||||||
0x1D => {CTRL = !is_release; println!("ctrl")},
|
0x1D => {CTRL = !is_release; println!("ctrl")},
|
||||||
0x0F if !is_release => {
|
0x0F if !is_release => {
|
||||||
CONTEXT.switch_term();
|
CONTEXT.switch_term();
|
||||||
CONTEXT.current_term().flush();
|
CONTEXT.current_term().flush();
|
||||||
},
|
},
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// 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 && !is_release => {
|
// Some(b"1!") if CTRL && !is_release => {
|
||||||
// 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]);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
terminal.keypress(ascii[0]);
|
terminal.keypress(ascii[0]);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Some(_) => {},
|
Some(_) => {},
|
||||||
None =>{},
|
None =>{},
|
||||||
// None => println!("nokey ctrl {:x}", control),
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
// current_screen.flush();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,15 +11,15 @@ extern crate rlibc;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
mod vga;
|
mod vga;
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
#[macro_use]
|
|
||||||
mod context;
|
mod context;
|
||||||
mod keyboard;
|
mod keyboard;
|
||||||
|
|
||||||
|
use context::CONTEXT;
|
||||||
|
use vga::{Color, ColorCode};
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
mod cpuio;
|
mod cpuio;
|
||||||
|
|
||||||
|
|
||||||
//TODO implement ACPI to have such functionality
|
//TODO implement ACPI to have such functionality
|
||||||
/// Reboot the kernel
|
/// Reboot the kernel
|
||||||
///
|
///
|
||||||
|
|
@ -56,38 +56,28 @@ fn shutdown() -> ! {
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern fn kmain() -> ! {
|
pub extern fn kmain() -> ! {
|
||||||
// use vga::VgaScreen;
|
unsafe { CONTEXT.current_term().color_code = ColorCode::new(Color::White, Color::Cyan); }
|
||||||
// use vga::color::Color;
|
print!("{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
|
||||||
// use vga::color::ColorCode;
|
format_args!("{: ^80}", r#" ,--, "#),
|
||||||
|
format_args!("{: ^80}", r#" ,--.'| ,----, "#),
|
||||||
println!(r#" ,--, "#);
|
format_args!("{: ^80}", r#" ,--, | : .' .' \ "#),
|
||||||
println!(r#" ,--.'| ,----, "#);
|
format_args!("{: ^80}", r#",---.'| : ' ,----,' | "#),
|
||||||
println!(r#" ,--, | : .' .' \ "#);
|
format_args!("{: ^80}", r#"; : | | ; | : . ; "#),
|
||||||
println!(r#",---.'| : ' ,----,' | "#);
|
format_args!("{: ^80}", r#"| | : _' | ; |.' / "#),
|
||||||
println!(r#"; : | | ; | : . ; "#);
|
format_args!("{: ^80}", r#": : |.' | `----'/ ; "#),
|
||||||
println!(r#"| | : _' | ; |.' / "#);
|
format_args!("{: ^80}", r#"| ' ' ; : / ; / "#),
|
||||||
println!(r#": : |.' | `----'/ ; "#);
|
format_args!("{: ^80}", r#"\ \ .'. | ; / /-, "#),
|
||||||
println!(r#"| ' ' ; : / ; / "#);
|
format_args!("{: ^80}", r#" `---`: | ' / / /.`| "#),
|
||||||
println!(r#"\ \ .'. | ; / /-, "#);
|
format_args!("{: ^80}", r#" ' ; |./__; : "#),
|
||||||
println!(r#" `---`: | ' / / /.`| "#);
|
format_args!("{: ^80}", r#" | : ;| : .' "#),
|
||||||
println!(r#" ' ; |./__; : "#);
|
format_args!("{: ^80}", r#" ' ,/ ; | .' "#),
|
||||||
println!(r#" | : ;| : .' "#);
|
format_args!("{: ^80}", r#" '--' `---' "#));
|
||||||
println!(r#" ' ,/ ; | .' "#);
|
unsafe { CONTEXT.current_term().color_code = ColorCode::new(Color::White, Color::Black); }
|
||||||
println!(r#" '--' `---' "#);
|
print!(">");
|
||||||
println!(">> Kernel startup...");
|
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
keyboard::kbd_callback();
|
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]
|
#[lang = "eh_personality"] #[no_mangle]
|
||||||
|
|
@ -97,12 +87,12 @@ pub extern fn eh_personality() {
|
||||||
|
|
||||||
#[lang = "panic_fmt"] #[no_mangle]
|
#[lang = "panic_fmt"] #[no_mangle]
|
||||||
pub extern fn panic_fmt(
|
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!("PANIC: {}", fmt);
|
||||||
// println!("FILE: {}", file);
|
println!("FILE: {}", file);
|
||||||
// println!("LINE: {}", line);
|
println!("LINE: {}", line);
|
||||||
loop {}
|
loop {}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@
|
||||||
|
|
||||||
use super::{Color, ColorCode};
|
use super::{Color, ColorCode};
|
||||||
use ::context::CONTEXT;
|
use ::context::CONTEXT;
|
||||||
|
use cpuio;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
|
|
@ -31,69 +32,87 @@ macro_rules! println {
|
||||||
pub fn print(args: fmt::Arguments) {
|
pub fn print(args: fmt::Arguments) {
|
||||||
use core::fmt::Write;
|
use core::fmt::Write;
|
||||||
unsafe { CONTEXT.current_term().write_fmt(args).unwrap() };
|
unsafe { CONTEXT.current_term().write_fmt(args).unwrap() };
|
||||||
|
unsafe { CONTEXT.current_term().flush() };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
extern crate core;
|
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 {
|
pub struct Writer {
|
||||||
pub position: usize,
|
pub buffer_pos: usize,
|
||||||
color_code: ColorCode,
|
pub color_code: ColorCode,
|
||||||
buffer: [u8; BUFFER_ROWS * BUFFER_COLS],
|
buffer: [u8; BUFFER_ROWS * BUFFER_COLS],
|
||||||
|
command: [u8; 10],
|
||||||
|
command_len: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Writer {
|
impl Writer {
|
||||||
pub const fn new() -> Writer {
|
pub const fn new() -> Writer {
|
||||||
Writer {
|
Writer {
|
||||||
position: 0,
|
buffer_pos: 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],
|
||||||
|
command: [0; 10],
|
||||||
|
command_len: 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn keypress(&mut self, ascii: u8) {
|
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();
|
self.flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn write_byte(&mut self, byte: u8) {
|
pub fn write_byte(&mut self, byte: u8) {
|
||||||
let i = self.position;
|
let i = self.buffer_pos;
|
||||||
|
|
||||||
match byte {
|
match byte {
|
||||||
|
|
||||||
b'\n' => {
|
b'\n' => {
|
||||||
//reset cursor
|
let current_line = self.buffer_pos / (BUFFER_COLS);
|
||||||
self.buffer[self.position + 1] = ColorCode::new(Color::White, Color::Black).0;
|
self.buffer_pos = (current_line + 1) * BUFFER_COLS;
|
||||||
let current_line = self.position / (BUFFER_COLS);
|
|
||||||
self.position = (current_line + 1) * BUFFER_COLS;
|
|
||||||
}
|
}
|
||||||
byte => {
|
byte => {
|
||||||
self.buffer[i] = byte;
|
self.buffer[i] = byte;
|
||||||
self.buffer[i + 1] = self.color_code.0;
|
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();
|
self.scroll();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// cursor
|
fn flush_cursor(&self)
|
||||||
self.buffer[self.position] = b' ';
|
{
|
||||||
self.buffer[self.position + 1] = ColorCode::new(Color::LightGray, Color::LightGray).0;
|
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) {
|
pub fn flush(&mut self) {
|
||||||
let slice = unsafe { core::slice::from_raw_parts_mut(0xb8000 as *mut u8, 4000) };
|
let slice = unsafe { core::slice::from_raw_parts_mut(0xb8000 as *mut u8, 4000) };
|
||||||
slice.as_mut().clone_from_slice(&self.buffer);
|
slice.as_mut().clone_from_slice(&self.buffer);
|
||||||
|
self.flush_cursor();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn scroll(&mut self) {
|
fn scroll(&mut self) {
|
||||||
|
|
@ -110,7 +129,7 @@ impl Writer {
|
||||||
self.buffer[((BUFFER_ROWS - 1) * BUFFER_COLS) + (col * 2)] = b' ';
|
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() {
|
for byte in s.bytes() {
|
||||||
self.write_byte(byte)
|
self.write_byte(byte)
|
||||||
}
|
}
|
||||||
self.flush();
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue