cpu as a console command
This commit is contained in:
parent
4885defefa
commit
24fa39d45c
8 changed files with 46 additions and 40 deletions
|
|
@ -8,27 +8,27 @@ pub fn cpu_info() -> Result {
|
|||
let cpuid = CpuId::new();
|
||||
|
||||
if let Some(info) = cpuid.get_vendor_info() {
|
||||
println!("CPU Vendor: {}", info.as_string());
|
||||
println!("Vendor: {}", info.as_string());
|
||||
}
|
||||
|
||||
if let Some(info) = cpuid.get_extended_function_info() {
|
||||
if let Some(brand) = info.processor_brand_string() {
|
||||
println!("CPU Model: {}", brand);
|
||||
println!("Model: {}", brand);
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(info) = cpuid.get_processor_frequency_info() {
|
||||
println!("CPU Base MHz: {}", info.processor_base_frequency());
|
||||
println!("CPU Max MHz: {}", info.processor_max_frequency());
|
||||
println!("Base MHz: {}", info.processor_base_frequency());
|
||||
println!("Max MHz: {}", info.processor_max_frequency());
|
||||
println!("Bus MHz: {}", info.bus_frequency());
|
||||
} else {
|
||||
set_color!(Red);
|
||||
println!("couldn't retrieve CPU frequency info");
|
||||
println!("Couldn't retrieve cpu frequency info");
|
||||
set_color!();
|
||||
}
|
||||
|
||||
if let Some(info) = cpuid.get_feature_info() {
|
||||
print!("CPU Features:");
|
||||
print!("Features:");
|
||||
if info.has_fpu() { print!(" fpu") };
|
||||
if info.has_vme() { print!(", vme") };
|
||||
if info.has_de() { print!(", de") };
|
||||
|
|
@ -97,7 +97,7 @@ pub fn cpu_info() -> Result {
|
|||
}
|
||||
|
||||
if let Some(info) = cpuid.get_extended_function_info() {
|
||||
print!("CPU extended function:");
|
||||
print!("Extended function:");
|
||||
if info.has_64bit_mode() { print!(" lm") };
|
||||
if info.has_rdtscp() { print!(", rdtscp") };
|
||||
if info.has_1gib_pages() { print!(", pdpe1gb") };
|
||||
|
|
@ -111,7 +111,7 @@ pub fn cpu_info() -> Result {
|
|||
}
|
||||
|
||||
if let Some(info) = cpuid.get_extended_feature_info() {
|
||||
print!("CPU extended features:");
|
||||
print!("Extended features:");
|
||||
if info.has_fsgsbase() { print!(" fsgsbase") };
|
||||
if info.has_tsc_adjust_msr() { print!(", tsc_adjust") };
|
||||
if info.has_bmi1() { print!(", bmi1") };
|
||||
|
|
@ -128,6 +128,5 @@ pub fn cpu_info() -> Result {
|
|||
println!("");
|
||||
}
|
||||
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,9 +15,7 @@ pub struct LocalApic {
|
|||
}
|
||||
|
||||
impl LocalApic {
|
||||
unsafe fn init(&mut self, active_table: &mut ActivePageTable) {
|
||||
// let efer = Efer::read();
|
||||
// println!("efer = {:?}", efer);
|
||||
// flush!();
|
||||
unsafe fn init(&mut self, _active_table: &mut ActivePageTable) {
|
||||
// ???
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,5 +6,4 @@ pub mod cpu;
|
|||
pub unsafe fn init(active_table: &mut ActivePageTable) {
|
||||
pic::init();
|
||||
local_apic::init(active_table);
|
||||
cpu::cpu_info().expect("cpuid not available");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,11 +36,12 @@ pub unsafe fn init() {
|
|||
MASTER.data.write(master_mask); wait();
|
||||
SLAVE.data.write(slave_mask); wait();
|
||||
|
||||
println!("master={:#x}", MASTER.data.read());
|
||||
println!("slave ={:#x}", SLAVE.data.read());
|
||||
|
||||
MASTER.mask_set(0);
|
||||
MASTER.mask_clear(1);
|
||||
// disable all irqs
|
||||
MASTER.data.write(!0); wait();
|
||||
SLAVE.data.write(!0); wait();
|
||||
|
||||
// keyboard active
|
||||
MASTER.mask_clear(1); wait();
|
||||
|
||||
// asm!("sti");
|
||||
::x86::instructions::interrupts::enable();
|
||||
|
|
|
|||
|
|
@ -6,13 +6,15 @@ macro_rules! interrupt {
|
|||
($i:expr, $name:ident, $func:block) => {
|
||||
pub extern "x86-interrupt" fn $name(stack_frame: &mut ExceptionStackFrame)
|
||||
{
|
||||
unsafe { trigger(1); }
|
||||
unsafe { trigger($i); }
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn inner(stack: &mut ExceptionStackFrame) {
|
||||
$func
|
||||
}
|
||||
inner(stack_frame);
|
||||
unsafe { acknowledge(1); }
|
||||
|
||||
unsafe { acknowledge($i); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,7 +42,6 @@ pub unsafe extern fn x86_rust_start(multiboot_info_addr: usize) {
|
|||
// after core has loaded
|
||||
::memory::init_noncore();
|
||||
|
||||
|
||||
// primary CPU entry point
|
||||
::kmain();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ fn dispatch(command: &str) -> Result <(), &'static str> {
|
|||
// others
|
||||
"stack" => self::print_stack(),
|
||||
"regs" => self::regs(),
|
||||
"cpu" => self::cpu(),
|
||||
|
||||
_ => Err("Command unknown. (h|help for help)"),
|
||||
}
|
||||
|
|
@ -48,6 +49,7 @@ fn help() -> Result <(), &'static str> {
|
|||
println!("shutdown | halt | q => Kill a kitten, then shutdown");
|
||||
println!("stack => Print kernel stack in a fancy way");
|
||||
println!("regs => Print controle register");
|
||||
println!("cpu => Print cpu information");
|
||||
flush!();
|
||||
Ok(())
|
||||
}
|
||||
|
|
@ -177,11 +179,17 @@ pub fn acpi_info() -> Result <(), &'static str> {
|
|||
}
|
||||
|
||||
pub fn regs() -> Result <(), &'static str> {
|
||||
use x86::registers::control::*;
|
||||
use ::x86::registers::control::*;
|
||||
println!("cr0={:#b}", Cr0::read());
|
||||
println!("cr3={:?}", Cr3::read());
|
||||
println!("cr4={:?}", Cr4::read());
|
||||
flush!();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn cpu() -> Result <(), &'static str> {
|
||||
use ::arch::x86::device::cpu;
|
||||
cpu::cpu_info().expect("cpu info not available");
|
||||
flush!();
|
||||
// TODO implement cr4 flags in `x86` module
|
||||
// println!("cr4={:#b}", Cr4::read());
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -199,21 +199,21 @@ impl fmt::Write for Writer {
|
|||
|
||||
pub fn init() {
|
||||
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#" '--' `---' "#));
|
||||
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!();
|
||||
unsafe { VGA.prompt(); }
|
||||
unsafe { VGA.flush(); }
|
||||
|
|
|
|||
Loading…
Reference in a new issue