chore: move arch traits into plat

This commit is contained in:
Paul Pan 2024-02-15 20:37:48 +08:00
parent 145b8cf076
commit 6cfdb4a237
14 changed files with 34 additions and 16 deletions

View File

@ -1,4 +1,4 @@
use crate::utils::io::{Printer, RawConsole};
use crate::plat::io::{Printer, RawConsole};
/*
Theoretically, we should wait until

View File

@ -1,4 +1,4 @@
use crate::utils::io::{RawConsole, Reader};
use crate::plat::io::{RawConsole, Reader};
impl Reader for RawConsole {
#[inline]

View File

@ -1,5 +1,5 @@
#[allow(unused_imports)]
use crate::utils::io::{Printer, RawConsole, Reader};
use crate::plat::io::{Printer, RawConsole, Reader};
#[cfg(feature = "board_default")]
impl Printer for RawConsole {

View File

@ -1,6 +1,6 @@
use log::error;
use crate::utils::lowlevel::{Hardware, LowLevel};
use crate::plat::lowlevel::{Hardware, LowLevel};
#[cfg(feature = "board_virt")]
use super::board::TEST_DEVICE;

View File

@ -1,17 +1,19 @@
use log::{error, info};
use log::{debug, error, info};
use crate::utils::lowlevel::{Hardware, LowLevel};
use crate::plat::lowlevel::{Hardware, LowLevel};
#[no_mangle]
pub extern "C" fn rust_main(hart_id: usize, device_tree_addr: usize) -> ! {
crate::logging::init();
#[cfg(test)]
crate::test_main(); // test_main will exit
crate::test_main();
// test_main will exit
info!("[rust_main] Kernel Started");
info!("Hello World!");
info!("hart_id = {}", hart_id);
info!("device_tree_addr = {:#x}", device_tree_addr);
debug!("device_tree_addr = {:#x}", device_tree_addr);
// TODO: setup and start scheduler

View File

@ -2,7 +2,7 @@ use core::panic::PanicInfo;
use log::error;
use crate::utils::lowlevel::{Hardware, LowLevel};
use crate::plat::lowlevel::{Hardware, LowLevel};
#[panic_handler]
fn panic(info: &PanicInfo) -> ! {

View File

@ -2,7 +2,7 @@ use core::fmt::Write;
use log::{self, LevelFilter, Log, Metadata, Record};
use crate::utils::io::RawConsole;
use crate::plat::io::RawConsole;
struct SimpleLogger;

View File

@ -26,12 +26,15 @@ pub mod entry;
// page table
pub mod mm;
// utils
pub mod utils;
// plat
pub mod plat;
// logging
pub mod logging;
// utils
pub mod utils;
// test infrastructure
#[cfg(test)]
mod test_runner;

2
src/plat/mod.rs Normal file
View File

@ -0,0 +1,2 @@
pub mod io;
pub mod lowlevel;

View File

@ -1,6 +1,6 @@
use log::info;
use crate::utils::lowlevel::{Hardware, LowLevel};
use crate::plat::lowlevel::{Hardware, LowLevel};
// Reference: https://os.phil-opp.com/testing/

View File

@ -0,0 +1,12 @@
#[macro_export]
macro_rules! function_name {
() => {{
fn f() {}
fn type_name_of<T>(_: T) -> &'static str {
core::any::type_name::<T>()
}
let name = type_name_of(f);
// strip out `::f` at the end of the string
&name[..name.len() - 3]
}};
}

View File

@ -1,2 +1 @@
pub mod io;
pub mod lowlevel;
pub mod function_name;