it runs
This commit is contained in:
parent
3d532a5a7a
commit
5412334168
6 changed files with 70 additions and 68 deletions
|
|
@ -11,7 +11,3 @@ rlibc = "1.0"
|
||||||
bitflags = "1.0.1"
|
bitflags = "1.0.1"
|
||||||
# spin = "0.4.5"
|
# spin = "0.4.5"
|
||||||
multiboot2 = { path = "multiboot2-elf64" }
|
multiboot2 = { path = "multiboot2-elf64" }
|
||||||
|
|
||||||
# [dependencies.lazy_static]
|
|
||||||
# version = "0.2.4"
|
|
||||||
# features = ["spin_no_std"]
|
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,11 @@
|
||||||
extern crate core;
|
extern crate core;
|
||||||
extern crate multiboot2;
|
// extern crate multiboot2;
|
||||||
|
|
||||||
use acpi;
|
use acpi;
|
||||||
use cpuio;
|
use cpuio;
|
||||||
|
use context;
|
||||||
|
// use multiboot2;
|
||||||
use core::char;
|
use core::char;
|
||||||
use context::*;
|
|
||||||
use vga::*;
|
use vga::*;
|
||||||
|
|
||||||
fn dispatch(command: &str) -> Result <(), &'static str> {
|
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",
|
print!("{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}\n",
|
||||||
"acpi => Return acpi state (ENABLED|DISABLE)",
|
"acpi => Return acpi state (ENABLED|DISABLE)",
|
||||||
"help | h => Print this help",
|
"help | h => Print this help",
|
||||||
"memory => lolilol", // TODO
|
"memory => print memory areas", // TODO
|
||||||
"multiboot => lolilol", // TODO
|
"multiboot => print multiboot information", // TODO
|
||||||
"reboot => reboot",
|
"reboot => reboot",
|
||||||
"sections => lolilol", // TODO
|
"sections => print elf sections", // TODO
|
||||||
"shutdown | halt | q => Kill a kitten, then shutdown",
|
"shutdown | halt | q => Kill a kitten, then shutdown",
|
||||||
"stack => Print kernel stack in a fancy way");
|
"stack => Print kernel stack in a fancy way");
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
@ -120,7 +121,7 @@ fn print_stack() -> Result <(), &'static str> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mb2_memory() -> 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()
|
let memory_map_tag = boot_info.memory_map_tag()
|
||||||
.expect("Memory map tag required");
|
.expect("Memory map tag required");
|
||||||
|
|
@ -134,7 +135,7 @@ fn mb2_memory() -> Result <(), &'static str> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mb2_sections() -> 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()
|
let elf_sections_tag = boot_info.elf_sections_tag()
|
||||||
.expect("Elf-sections tag required");
|
.expect("Elf-sections tag required");
|
||||||
|
|
@ -148,7 +149,7 @@ fn mb2_sections() -> Result <(), &'static str> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mb2_info() -> 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()
|
let command_line_tag = boot_info.command_line_tag()
|
||||||
.expect("Elf-sections tag required");
|
.expect("Elf-sections tag required");
|
||||||
|
|
|
||||||
|
|
@ -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) {
|
pub fn init_screen() {
|
||||||
self.current_term = {
|
set_color!(White, Cyan);
|
||||||
if self.current_term == 0 { 1 }
|
print!("{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
|
||||||
else { 0 }
|
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{
|
pub fn switch_term() {
|
||||||
if self.current_term == 0 {
|
context().current_term = {
|
||||||
&mut self.vga1
|
if context().current_term == 0 { 1 }
|
||||||
} else {
|
else { 0 }
|
||||||
&mut self.vga2
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 {
|
unsafe {
|
||||||
match CONTEXT {
|
match CONTEXT {
|
||||||
Some(ref mut x) => &mut *x,
|
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)) };
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
extern crate core;
|
extern crate core;
|
||||||
|
|
||||||
use cpuio;
|
use cpuio;
|
||||||
use context::*;
|
use context;
|
||||||
|
|
||||||
const MAX_KEYS: usize = 59;
|
const MAX_KEYS: usize = 59;
|
||||||
const KEYMAP_US: [[u8;2]; MAX_KEYS] = [
|
const KEYMAP_US: [[u8;2]; MAX_KEYS] = [
|
||||||
|
|
@ -93,18 +93,18 @@ pub fn kbd_callback() {
|
||||||
0x38 => {ALT = !is_release},
|
0x38 => {ALT = !is_release},
|
||||||
0x1D => {CTRL = !is_release},
|
0x1D => {CTRL = !is_release},
|
||||||
0x0F if !is_release => {
|
0x0F if !is_release => {
|
||||||
context().switch_term();
|
context::switch_term();
|
||||||
context().current_term().flush();
|
context::current_term().flush();
|
||||||
},
|
},
|
||||||
0x0E if !is_release => {
|
0x0E if !is_release => {
|
||||||
context().current_term().backspace();
|
context::current_term().backspace();
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Some(ascii) if !is_release => {
|
Some(ascii) if !is_release => {
|
||||||
let sym = if SHIFT { ascii[1] } else { ascii[0] };
|
let sym = if SHIFT { ascii[1] } else { ascii[0] };
|
||||||
context().current_term().keypress(sym);
|
context::current_term().keypress(sym);
|
||||||
},
|
},
|
||||||
Some(_) => {},
|
Some(_) => {},
|
||||||
None =>{},
|
None =>{},
|
||||||
|
|
|
||||||
|
|
@ -25,34 +25,13 @@ pub mod acpi;
|
||||||
/// simple area frame allocator implementation
|
/// simple area frame allocator implementation
|
||||||
pub mod memory;
|
pub mod memory;
|
||||||
|
|
||||||
use context::*;
|
// use vga::{Color, ColorCode};
|
||||||
use memory::*;
|
|
||||||
|
|
||||||
use vga::{Color, ColorCode};
|
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern fn kmain(multiboot_info_addr: usize) -> ! {
|
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();
|
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(); }
|
loop { keyboard::kbd_callback(); }
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ pub mod color;
|
||||||
|
|
||||||
pub use self::color::{Color, ColorCode};
|
pub use self::color::{Color, ColorCode};
|
||||||
|
|
||||||
use context::*;
|
use context;
|
||||||
use cpuio;
|
use cpuio;
|
||||||
use console;
|
use console;
|
||||||
|
|
||||||
|
|
@ -25,21 +25,21 @@ macro_rules! println {
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! flush {
|
macro_rules! flush {
|
||||||
() => (context().current_term().flush());
|
() => (context::current_term().flush());
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! set_color {
|
macro_rules! set_color {
|
||||||
() => (context().current_term().color_code =
|
() => ($crate::context::current_term().color_code =
|
||||||
ColorCode::new(Color::White, Color::Black));
|
$crate::vga::ColorCode::new($crate::vga::Color::White, $crate::vga::Color::Black));
|
||||||
($fg:ident) => (context().current_term().color_code =
|
($fg:ident) => ($crate::context::current_term().color_code =
|
||||||
ColorCode::new(Color::$fg, Color::Black));
|
$crate::vga::ColorCode::new($crate::vga::Color::$fg, $crate::vga::Color::Black));
|
||||||
($fg:ident, $bg:ident) => (context().current_term().color_code =
|
($fg:ident, $bg:ident) => ($crate::context::current_term().color_code =
|
||||||
ColorCode::new(Color::$fg, Color::$bg));
|
$crate::vga::ColorCode::new($crate::vga::Color::$fg, $crate::vga::Color::$bg));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn print(args: fmt::Arguments) {
|
pub fn print(args: fmt::Arguments) {
|
||||||
use core::fmt::Write;
|
use core::fmt::Write;
|
||||||
context().current_term().write_fmt(args).unwrap();
|
context::current_term().write_fmt(args).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
extern crate core;
|
extern crate core;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue