Skip to content

Commit e400481

Browse files
committed
test: use rcore_console for test-kernel
Signed-off-by: YdrMaster <[email protected]>
1 parent 0f9f917 commit e400481

File tree

6 files changed

+48
-84
lines changed

6 files changed

+48
-84
lines changed

Cargo.lock

Lines changed: 12 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

legacy-console-bench/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,4 @@ sbi-rt = "0.0.2"
1010
riscv = "0.9.0"
1111
r0 = "1"
1212
uart_16550 = "0.2"
13-
14-
console = { git = "https://github.com/YdrMaster/rCore-Tutorial-in-single-workspace" }
13+
rcore-console = "0.0.0"

legacy-console-bench/src/main.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
#![deny(warnings)]
55

66
use core::mem::MaybeUninit;
7-
8-
use console::log;
7+
use rcore_console::log;
98
use riscv::register::*;
109
use sbi_rt::*;
1110
use uart_16550::MmioSerialPort;
@@ -29,21 +28,21 @@ unsafe extern "C" fn _start(hartid: usize, device_tree_paddr: usize) -> ! {
2928
)
3029
}
3130

32-
extern "C" fn rust_main(_hartid: usize, _dtb_pa: usize) -> ! {
31+
extern "C" fn rust_main(hartid: usize, _dtb_pa: usize) -> ! {
3332
extern "C" {
3433
static mut sbss: u64;
3534
static mut ebss: u64;
3635
}
3736
unsafe { r0::zero_bss(&mut sbss, &mut ebss) };
3837
unsafe { UART = MaybeUninit::new(MmioSerialPort::new(0x1000_0000)) };
39-
console::init_console(&Console);
40-
console::set_log_level(option_env!("LOG"));
41-
console::test_log();
38+
rcore_console::init_console(&Console);
39+
rcore_console::set_log_level(option_env!("LOG"));
40+
rcore_console::test_log();
4241

4342
let t0 = time::read();
4443

4544
for _ in 0..0xffff {
46-
let _ = sbi_rt::get_marchid();
45+
let _ = sbi_rt::send_ipi(1 << hartid, 0);
4746
}
4847

4948
let t1 = time::read();
@@ -63,9 +62,9 @@ fn panic(info: &core::panic::PanicInfo) -> ! {
6362
struct Console;
6463
static mut UART: MaybeUninit<MmioSerialPort> = MaybeUninit::uninit();
6564

66-
impl console::Console for Console {
65+
impl rcore_console::Console for Console {
6766
#[inline]
6867
fn put_char(&self, c: u8) {
69-
unsafe { UART.assume_init_mut().send(c) }
68+
unsafe { UART.assume_init_mut() }.send(c);
7069
}
7170
}

test-kernel/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ riscv = "0.9.0"
1414
spin = "0.9"
1515
r0 = "1"
1616
uart_16550 = "0.2"
17+
rcore-console = "0.0.0"
1718
dtb-walker = "=0.2.0-alpha.3"

test-kernel/src/console.rs

Lines changed: 0 additions & 60 deletions
This file was deleted.

test-kernel/src/main.rs

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
#![deny(warnings)]
55

66
#[macro_use]
7-
mod console;
7+
extern crate rcore_console;
88

9-
use core::arch::asm;
9+
use core::{arch::asm, mem::MaybeUninit};
1010
use sbi_testing::sbi;
11+
use spin::Mutex;
12+
use uart_16550::MmioSerialPort;
1113

1214
/// 内核入口。
1315
///
@@ -44,7 +46,9 @@ extern "C" fn rust_main(hartid: usize, dtb_pa: usize) -> ! {
4446
frequency,
4547
uart,
4648
} = BoardInfo::parse(dtb_pa);
47-
console::init(uart);
49+
*UART.lock() = MaybeUninit::new(unsafe { MmioSerialPort::new(uart) });
50+
rcore_console::init_console(&Console);
51+
rcore_console::set_log_level(option_env!("LOG"));
4852
println!(
4953
r"
5054
_____ _ _ __ _
@@ -137,3 +141,22 @@ impl BoardInfo {
137141
ans
138142
}
139143
}
144+
145+
struct Console;
146+
static UART: Mutex<MaybeUninit<MmioSerialPort>> = Mutex::new(MaybeUninit::uninit());
147+
148+
impl rcore_console::Console for Console {
149+
#[inline]
150+
fn put_char(&self, c: u8) {
151+
unsafe { UART.lock().assume_init_mut() }.send(c);
152+
}
153+
154+
#[inline]
155+
fn put_str(&self, s: &str) {
156+
let mut uart = UART.lock();
157+
let uart = unsafe { uart.assume_init_mut() };
158+
for c in s.bytes() {
159+
uart.send(c);
160+
}
161+
}
162+
}

0 commit comments

Comments
 (0)