This commit is contained in:
Jack Halford 2018-03-05 13:12:02 +01:00
parent 3d532a5a7a
commit 5412334168
6 changed files with 70 additions and 68 deletions

View file

@ -11,7 +11,3 @@ rlibc = "1.0"
bitflags = "1.0.1"
# spin = "0.4.5"
multiboot2 = { path = "multiboot2-elf64" }
# [dependencies.lazy_static]
# version = "0.2.4"
# features = ["spin_no_std"]

View file

@ -1,10 +1,11 @@
extern crate core;
extern crate multiboot2;
// extern crate multiboot2;
use acpi;
use cpuio;
use context;
// use multiboot2;
use core::char;
use context::*;
use vga::*;
fn dispatch(command: &str) -> Result <(), &'static str> {
@ -35,10 +36,10 @@ fn help() -> Result <(), &'static str> {
print!("{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}\n",
"acpi => Return acpi state (ENABLED|DISABLE)",
"help | h => Print this help",
"memory => lolilol", // TODO
"multiboot => lolilol", // TODO
"memory => print memory areas", // TODO
"multiboot => print multiboot information", // TODO
"reboot => reboot",
"sections => lolilol", // TODO
"sections => print elf sections", // TODO
"shutdown | halt | q => Kill a kitten, then shutdown",
"stack => Print kernel stack in a fancy way");
Ok(())
@ -120,7 +121,7 @@ fn print_stack() -> Result <(), &'static str> {
}
fn mb2_memory() -> Result <(), &'static str> {
let boot_info = &context().boot_info;
let boot_info = context::boot_info();
let memory_map_tag = boot_info.memory_map_tag()
.expect("Memory map tag required");
@ -134,7 +135,7 @@ fn mb2_memory() -> Result <(), &'static str> {
}
fn mb2_sections() -> Result <(), &'static str> {
let boot_info = &context().boot_info;
let boot_info = context::boot_info();
let elf_sections_tag = boot_info.elf_sections_tag()
.expect("Elf-sections tag required");
@ -148,7 +149,7 @@ fn mb2_sections() -> Result <(), &'static str> {
}
fn mb2_info() -> Result <(), &'static str> {
let boot_info = &context().boot_info;
let boot_info = context::boot_info();
let command_line_tag = boot_info.command_line_tag()
.expect("Elf-sections tag required");

View file

@ -52,29 +52,51 @@ impl Context
}
}
pub fn init_screen(&mut self) {
self.vga1.prompt();
self.vga2.prompt();
self.vga1.flush();
}
}
pub fn switch_term(&mut self) {
self.current_term = {
if self.current_term == 0 { 1 }
else { 0 }
};
}
pub fn init_screen() {
set_color!(White, 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#" '--' `---' "#));
set_color!();
context().vga1.prompt();
context().vga2.prompt();
context().vga1.flush();
}
pub fn current_term(&mut self) -> &mut vga::Writer{
if self.current_term == 0 {
&mut self.vga1
} else {
&mut self.vga2
}
pub fn switch_term() {
context().current_term = {
if context().current_term == 0 { 1 }
else { 0 }
};
}
pub fn current_term() -> &'static mut vga::Writer{
if context().current_term == 0 {
&mut context().vga1
} else {
&mut context().vga2
}
}
pub fn context() -> &'static mut Context {
pub fn boot_info() -> &'static multiboot2::BootInformation {
&context().boot_info
}
fn context() -> &'static mut Context {
unsafe {
match CONTEXT {
Some(ref mut x) => &mut *x,
@ -82,3 +104,7 @@ pub fn context() -> &'static mut Context {
}
}
}
pub fn init(multiboot_info_addr: usize) {
unsafe { CONTEXT = Some(Context::new(multiboot_info_addr)) };
}

View file

@ -1,7 +1,7 @@
extern crate core;
use cpuio;
use context::*;
use context;
const MAX_KEYS: usize = 59;
const KEYMAP_US: [[u8;2]; MAX_KEYS] = [
@ -93,18 +93,18 @@ pub fn kbd_callback() {
0x38 => {ALT = !is_release},
0x1D => {CTRL = !is_release},
0x0F if !is_release => {
context().switch_term();
context().current_term().flush();
context::switch_term();
context::current_term().flush();
},
0x0E if !is_release => {
context().current_term().backspace();
context::current_term().backspace();
}
_ => {}
}
},
Some(ascii) if !is_release => {
let sym = if SHIFT { ascii[1] } else { ascii[0] };
context().current_term().keypress(sym);
context::current_term().keypress(sym);
},
Some(_) => {},
None =>{},

View file

@ -25,34 +25,13 @@ pub mod acpi;
/// simple area frame allocator implementation
pub mod memory;
use context::*;
use memory::*;
use vga::{Color, ColorCode};
// use vga::{Color, ColorCode};
#[no_mangle]
pub extern fn kmain(multiboot_info_addr: usize) -> ! {
unsafe { CONTEXT = Some(Context::new(multiboot_info_addr)) };
context::init(multiboot_info_addr);
context::init_screen();
acpi::init().unwrap();
context().init_screen();
set_color!(White, 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#" '--' `---' "#));
set_color!();
loop { keyboard::kbd_callback(); }
}

View file

@ -2,7 +2,7 @@ pub mod color;
pub use self::color::{Color, ColorCode};
use context::*;
use context;
use cpuio;
use console;
@ -25,21 +25,21 @@ macro_rules! println {
}
macro_rules! flush {
() => (context().current_term().flush());
() => (context::current_term().flush());
}
macro_rules! set_color {
() => (context().current_term().color_code =
ColorCode::new(Color::White, Color::Black));
($fg:ident) => (context().current_term().color_code =
ColorCode::new(Color::$fg, Color::Black));
($fg:ident, $bg:ident) => (context().current_term().color_code =
ColorCode::new(Color::$fg, Color::$bg));
() => ($crate::context::current_term().color_code =
$crate::vga::ColorCode::new($crate::vga::Color::White, $crate::vga::Color::Black));
($fg:ident) => ($crate::context::current_term().color_code =
$crate::vga::ColorCode::new($crate::vga::Color::$fg, $crate::vga::Color::Black));
($fg:ident, $bg:ident) => ($crate::context::current_term().color_code =
$crate::vga::ColorCode::new($crate::vga::Color::$fg, $crate::vga::Color::$bg));
}
pub fn print(args: fmt::Arguments) {
use core::fmt::Write;
context().current_term().write_fmt(args).unwrap();
context::current_term().write_fmt(args).unwrap();
}
extern crate core;