chore: use global FDT

This commit is contained in:
Paul Pan 2024-04-19 19:49:09 +08:00
parent e360db4972
commit 8218f87765
3 changed files with 19 additions and 9 deletions

View File

@ -3,14 +3,14 @@ use crate::arch::layout::{mmap_phys_to_virt, zero_bss};
use crate::arch::vspace::{setup_kernel_paging, setup_memory}; use crate::arch::vspace::{setup_kernel_paging, setup_memory};
use crate::entry::{rust_main, HART_ID}; use crate::entry::{rust_main, HART_ID};
use crate::plat::console::mute_console; use crate::plat::console::mute_console;
use fdt::Fdt; use utils::atomic::AtomicConstPtr;
use vspace::addr::AddressOps; use vspace::addr::AddressOps;
#[naked] #[naked]
#[no_mangle] #[no_mangle]
#[allow(named_asm_labels)] #[allow(named_asm_labels)]
#[link_section = ".text.entry"] #[link_section = ".text.entry"]
unsafe extern "C" fn _start(hart_id: usize, device_tree_addr: usize) -> ! { unsafe extern "C" fn _start(hart_id: usize, fdt_addr: usize) -> ! {
// NOTE: no stack here // NOTE: no stack here
// we should be launched by OpenSBI and running is S-mode // we should be launched by OpenSBI and running is S-mode
@ -60,6 +60,8 @@ unsafe extern "C" fn _start(hart_id: usize, device_tree_addr: usize) -> ! {
) )
} }
pub static FDT: AtomicConstPtr<u8> = AtomicConstPtr::new(core::ptr::null());
unsafe fn pre_main(hart_id: usize, fdt_addr: usize) { unsafe fn pre_main(hart_id: usize, fdt_addr: usize) {
zero_bss(); zero_bss();
@ -73,6 +75,8 @@ unsafe fn pre_main(hart_id: usize, fdt_addr: usize) {
// after kernel paging, board level early console is broken (no address mapping) // after kernel paging, board level early console is broken (no address mapping)
mute_console(); mute_console();
let fdt = unsafe { Fdt::from_ptr(mmap_phys_to_virt(fdt_addr.into()).as_const_ptr()).unwrap() }; let fdt_addr: *const u8 = mmap_phys_to_virt(fdt_addr.into()).as_const_ptr();
rust_main(fdt); FDT.store(fdt_addr as *mut u8, core::sync::atomic::Ordering::Release);
rust_main();
} }

View File

@ -11,10 +11,6 @@ cfg_if! {
} }
} }
// Console: plat/console.rs
pub use board::console::init_early_console;
pub use board::console::EarlyConsole;
mod entry; mod entry;
pub mod layout; pub mod layout;
mod lowlevel; mod lowlevel;
@ -22,3 +18,10 @@ mod timer;
mod tls; mod tls;
pub mod trap; pub mod trap;
pub mod vspace; pub mod vspace;
// Console: plat/console.rs
pub use board::console::init_early_console;
pub use board::console::EarlyConsole;
// FDT: entry.rs
pub use entry::FDT;

View File

@ -9,7 +9,10 @@ use log::{debug, error, info, warn};
#[thread_local] #[thread_local]
pub static HART_ID: Cell<usize> = Cell::new(0); pub static HART_ID: Cell<usize> = Cell::new(0);
pub fn rust_main(fdt: Fdt) -> ! { pub fn rust_main() -> ! {
let fdt_addr = crate::arch::FDT.load(core::sync::atomic::Ordering::Acquire);
let fdt = unsafe { Fdt::from_ptr(fdt_addr).unwrap() };
setup_console(&fdt); setup_console(&fdt);
info!("Kernel Started"); info!("Kernel Started");