Fix `log` crate

master
WangRunji 6 years ago
parent 96d8af8034
commit 7b4cc6d772

@ -13,13 +13,19 @@ qemu_auto_exit = []
link_user_program = []
[profile.dev]
# enable RVO to avoid stack overflow
# MUST >= 1 : Enable RVO to avoid stack overflow
# MUST >= 2 : Avoid (u8, u8) LLVM error in RV32 (at crate 'log')
# Error: Assertion `isSimple() && "Expected a SimpleValueType!"' failed.
# BUT!
# MUST <= 1 : Avoid double fault at -O2 T_T
opt-level = 1
[profile.release]
debug = true
[dependencies]
# Fixed version for RV32
log = { git = "https://github.com/riscv-and-rust-and-decaf/log.git" }
rlibc = "1.0"
spin = "0.4.8"
once = "0.3.3"
@ -37,7 +43,6 @@ multiboot2 = "0.6"
x86_64 = "0.2.6"
linked_list_allocator = "0.6"
redox_syscall = "0.1"
log = "0.4"
uart_16550 = "0.1"
simple-filesystem = { git = "https://github.com/wangrunji0408/SimpleFileSystem-Rust" }

@ -1,4 +1,3 @@
use arch::driver::serial::COM1;
use core::fmt;
use log;
use log::{Level, LevelFilter, Log, Metadata, Record};
@ -35,8 +34,10 @@ macro_rules! with_color {
}};
}
#[cfg(target_arch = "x86_64")]
fn print_in_color(args: fmt::Arguments, color: Color) {
use core::fmt::Write;
use arch::driver::serial::COM1;
// use arch::driver::vga::*;
// {
// let mut writer = vga_writer::VGA_WRITER.lock();
@ -49,12 +50,28 @@ fn print_in_color(args: fmt::Arguments, color: Color) {
COM1.lock().write_fmt(with_color!(args, color)).unwrap();
}
#[cfg(target_arch = "riscv")]
fn print_in_color(args: fmt::Arguments, color: Color) {
use arch::serial::SerialPort;
use core::fmt::Write;
SerialPort.write_fmt(with_color!(args, color)).unwrap();
}
#[cfg(target_arch = "x86_64")]
pub fn print(args: fmt::Arguments) {
use core::fmt::Write;
use arch::driver::serial::COM1;
unsafe { COM1.force_unlock(); }
COM1.lock().write_fmt(args).unwrap();
}
#[cfg(target_arch = "riscv")]
pub fn print(args: fmt::Arguments) {
use arch::serial::SerialPort;
use core::fmt::Write;
SerialPort.write_fmt(args).unwrap();
}
struct SimpleLogger;
impl Log for SimpleLogger {

@ -1,45 +0,0 @@
// FIXME: merge to x86_64 io
use core::fmt;
macro_rules! print {
($($arg:tt)*) => ({
$crate::io::print(format_args!($($arg)*));
});
}
macro_rules! println {
($fmt:expr) => (print!(concat!($fmt, "\n")));
($fmt:expr, $($arg:tt)*) => (print!(concat!($fmt, "\n"), $($arg)*));
}
macro_rules! trace {
($fmt:expr) => (print!(concat!("[trace] ", $fmt, "\n")));
($fmt:expr, $($arg:tt)*) => (print!(concat!("[trace] ", $fmt, "\n"), $($arg)*));
}
macro_rules! debug {
($fmt:expr) => (print!(concat!("[debug] ", $fmt, "\n")));
($fmt:expr, $($arg:tt)*) => (print!(concat!("[debug] ", $fmt, "\n"), $($arg)*));
}
macro_rules! info {
($fmt:expr) => (print!(concat!("[ info] ", $fmt, "\n")));
($fmt:expr, $($arg:tt)*) => (print!(concat!("[ info] ", $fmt, "\n"), $($arg)*));
}
macro_rules! warn {
($fmt:expr) => (print!(concat!("[ warn] ", $fmt, "\n")));
($fmt:expr, $($arg:tt)*) => (print!(concat!("[ warn] ", $fmt, "\n"), $($arg)*));
}
macro_rules! error {
($fmt:expr) => (print!(concat!("[error] ", $fmt, "\n")));
($fmt:expr, $($arg:tt)*) => (print!(concat!("[error] ", $fmt, "\n"), $($arg)*));
}
pub fn print(args: fmt::Arguments) {
use arch::serial::SerialPort;
use core::fmt::Write;
SerialPort.write_fmt(args).unwrap();
}

@ -25,7 +25,7 @@ pub fn panic(info: &PanicInfo) -> ! {
#[lang = "panic_fmt"]
#[no_mangle]
pub fn panic_fmt(fmt: ::core::fmt::Arguments, file: &'static str, line: u32, col: u32) -> ! {
println!("\n\nPANIC in {} at {}:{}\n {}", file, line, col, fmt);
error!("\n\nPANIC in {} at {}:{}\n {}", file, line, col, fmt);
loop {}
}

@ -29,7 +29,6 @@ extern crate bitflags;
extern crate lazy_static;
extern crate linked_list_allocator;
#[macro_use]
#[cfg(target_arch = "x86_64")]
extern crate log;
#[cfg(target_arch = "x86_64")]
extern crate multiboot2;
@ -59,14 +58,7 @@ pub use arch::other_main;
use linked_list_allocator::LockedHeap;
#[macro_use] // print!
#[cfg(target_arch = "x86_64")]
mod io;
#[macro_use] // print!
#[cfg(target_arch = "riscv")]
#[path = "io/riscv_io.rs"]
mod io;
mod memory;
mod lang;
mod util;
@ -97,6 +89,7 @@ fn timer_interrupt() {
#[no_mangle]
#[cfg(target_arch = "riscv")]
pub extern fn rust_main() -> ! {
io::init();
arch::init();
process::init();
info!("RISCV init end");

Loading…
Cancel
Save