@@ -3,7 +3,7 @@ use super::{
3
3
consts:: { kernel_mem_info, MAX_HART_NUM , STACK_PAGES_PER_HART } ,
4
4
} ;
5
5
use core:: arch:: asm;
6
- use dtb_walker:: { Dtb , DtbObj , Property , Str , WalkOperation :: * } ;
6
+ use dtb_walker:: { Dtb , DtbObj , HeaderError :: * , Property , Str , WalkOperation :: * } ;
7
7
use kernel_hal:: KernelConfig ;
8
8
9
9
/// 内核入口。
@@ -49,15 +49,19 @@ static mut BOOT_PAGE_TABLE: BootPageTable = BootPageTable::ZERO;
49
49
extern "C" fn primary_rust_main ( hartid : usize , device_tree_paddr : usize ) -> ! {
50
50
// 清零 bss 段
51
51
zero_bss ( ) ;
52
- let secondary_hart_start = secondary_hart_start as usize ;
53
52
// 使能启动页表
54
53
let sstatus = unsafe {
55
54
BOOT_PAGE_TABLE . init ( ) ;
56
55
BOOT_PAGE_TABLE . launch ( hartid)
57
56
} ;
58
57
// 检查设备树
59
58
// 副核启动完成前跳板页一直存在,所以可以使用物理地址直接访问设备树
60
- let dtb = unsafe { Dtb :: from_raw_parts_unchecked ( device_tree_paddr as _ ) } ;
59
+ let dtb = unsafe {
60
+ Dtb :: from_raw_parts_filtered ( device_tree_paddr as _ , |e| {
61
+ matches ! ( e, Misaligned ( 4 ) | LastCompVersion ( _) )
62
+ } )
63
+ }
64
+ . unwrap ( ) ;
61
65
let mem_info = kernel_mem_info ( ) ;
62
66
// 打印启动信息
63
67
println ! (
@@ -74,7 +78,11 @@ device tree: {device_tree_paddr:016x}..{:016x}
74
78
device_tree_paddr + dtb. total_size( ) ,
75
79
) ;
76
80
// 启动副核
77
- boot_secondary_harts ( hartid, dtb, secondary_hart_start) ;
81
+ boot_secondary_harts (
82
+ hartid,
83
+ dtb,
84
+ secondary_hart_start as usize - mem_info. offset ( ) ,
85
+ ) ;
78
86
// 转交控制权
79
87
crate :: primary_main ( KernelConfig {
80
88
phys_to_virt_offset : mem_info. offset ( ) ,
0 commit comments