Skip to content

Commit 7de9e95

Browse files
authored
feat: 添加 spin 依赖并实现共享数据的互斥锁管理 (#50)
fix: 更新构建逻辑以支持强制重建加载器 chore: 更新 Cargo.lock 以包含新依赖
1 parent 8585146 commit 7de9e95

File tree

12 files changed

+73
-34
lines changed

12 files changed

+73
-34
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

loader/pie-boot-loader-aarch64/src/mmu.rs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -122,28 +122,28 @@ where
122122
));
123123
}
124124

125-
let size = if table.entry_size() == table.max_block_size() {
126-
table.entry_size() * (T::TABLE_LEN / 2)
127-
} else {
128-
table.max_block_size() * T::TABLE_LEN
129-
};
130-
let start = 0x0usize;
131-
132-
printkv!("eq", "[{:#x}, {:#x})", start, start + size);
133-
134-
if CurrentEL.read(CurrentEL::EL) == 1 {
135-
early_err!(table.map(
136-
MapConfig {
137-
vaddr: start.into(),
138-
paddr: start.into(),
139-
size,
140-
pte: new_pte(CacheKind::NoCache),
141-
allow_huge: true,
142-
flush: false,
143-
},
144-
access,
145-
));
146-
}
125+
// let size = if table.entry_size() == table.max_block_size() {
126+
// table.entry_size() * (T::TABLE_LEN / 2)
127+
// } else {
128+
// table.max_block_size() * T::TABLE_LEN
129+
// };
130+
// let start = 0x0usize;
131+
132+
// printkv!("eq", "[{:#x}, {:#x})", start, start + size);
133+
134+
// if CurrentEL.read(CurrentEL::EL) == 1 {
135+
// early_err!(table.map(
136+
// MapConfig {
137+
// vaddr: start.into(),
138+
// paddr: start.into(),
139+
// size,
140+
// pte: new_pte(CacheKind::Normal),
141+
// allow_huge: true,
142+
// flush: false,
143+
// },
144+
// access,
145+
// ));
146+
// }
147147
}
148148

149149
let pg = table.paddr().raw() as _;

somehal/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ version = "0.4.1"
1111

1212
[features]
1313
hv = ["kdef-pgtable/space-low"]
14+
force-rebuild-loader = []
1415

1516
[dependencies]
1617
any-uart = {version = "0.2"}

somehal/build.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,17 @@ fn extract_version_from_toml_value(value: &toml::Value) -> Option<String> {
120120
}
121121

122122
fn aarch64_set_loader() {
123-
// 首先尝试从 release 下载,如果失败则回退到本地构建
124-
let download_success = download_latest_release();
125-
126-
if !download_success {
127-
// 回退到原来的本地构建逻辑
123+
let force_rebuild = std::env::var("CARGO_FEATURE_FORCE_REBUILD_LOADER").is_ok();
124+
if force_rebuild {
128125
build_loader_locally();
126+
} else {
127+
let download_success = download_latest_release();
128+
// 首先尝试从 release 下载,如果失败则回退到本地构建
129+
130+
if !download_success {
131+
// 回退到原来的本地构建逻辑
132+
build_loader_locally();
133+
}
129134
}
130135
}
131136

somehal/link.ld

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,9 @@ SECTIONS{
2020
*(.init_array .init_array.*)
2121
__init_array_end = .;
2222
}
23-
. = ALIGN(4K);
24-
_erodata = .;
2523

2624
.data : ALIGN(4K) {
25+
_erodata = .;
2726
_sdata = .;
2827
. = ALIGN(4K);
2928
*(.data .data.*)

somehal/link_base.ld

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ SECTIONS{
2121
}
2222

2323
SECTIONS{
24-
.boot_loader : {
24+
.boot_loader : ALIGN(PAGE_SIZE) {
25+
__boot_loader_start = .;
2526
KEEP(*(.boot_loader))
27+
__boot_loader_end = .;
2628
}
2729
} INSERT BEFORE .data
2830

somehal/src/arch/aarch64/mem/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,7 @@ pub fn iomap(phys: usize, size: usize) -> Result<NonNull<u8>, page_table_generic
2525

2626
Ok(NonNull::new(vaddr).unwrap())
2727
}
28+
29+
pub fn flush_tlb(vaddr: Option<VirtAddr>) {
30+
crate::arch::el::flush_tlb(vaddr);
31+
}

somehal/src/arch/aarch64/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use core::{
33
mem::{offset_of, size_of},
44
};
55

6+
use aarch64_cpu_ext::cache::{CacheOp, dcache_all};
67
use kdef_pgtable::{KLINER_OFFSET, PAGE_SIZE};
78
#[cfg(not(feature = "hv"))]
89
use pie_boot_loader_aarch64::el1::{set_table, setup_sctlr, setup_table_regs};
@@ -196,6 +197,7 @@ fn enable_fp() {
196197

197198
#[start_code]
198199
fn init_mmu() -> usize {
200+
dcache_all(CacheOp::Invalidate);
199201
setup_table_regs();
200202

201203
let addr = boot_info().pg_start as usize;

somehal/src/arch/aarch64/power.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use aarch64_cpu::asm::wfi;
44
use aarch64_cpu_ext::cache::{CacheOp, dcache_range};
55
use fdt_parser::Fdt;
66
use log::debug;
7-
use pie_boot_if::BootInfo;
87
use smccc::{Hvc, Smc, psci};
98

109
use crate::{_start_secondary, boot_info, lazy_static::LazyStatic, println};
@@ -78,9 +77,20 @@ pub fn cpu_on(cpu_id: u64, stack_top: u64) -> Result<(), PsciError> {
7877

7978
let entry = secondary_entry_addr();
8079

81-
let start = boot_info() as *const _ as usize;
82-
let size = core::mem::size_of::<BootInfo>();
80+
unsafe extern "C" {
81+
fn _srodata();
82+
fn __cpu0_stack();
83+
fn __bss_start();
84+
fn __bss_stop();
85+
}
86+
87+
let start = _srodata as usize;
88+
let size = (__cpu0_stack as usize) - start;
89+
90+
dcache_range(CacheOp::Clean, start, size);
8391

92+
let start = __bss_start as usize;
93+
let size = (__bss_stop as usize) - start;
8494
dcache_range(CacheOp::Clean, start, size);
8595

8696
_cpu_on(cpu_id, entry as _, stack_top)

test_aarch64_el2_uboot.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#!/bin/bash
2-
cargo test --target aarch64-unknown-none-softfloat -p test-some-rt --test test --features "hv" -- --show-output --uboot
2+
cargo test --target aarch64-unknown-none-softfloat -p test-some-rt --test test --features "hv,somehal/force-rebuild-loader" -- --show-output --uboot
33
# cargo test --target aarch64-unknown-none-softfloat -p test-some-rt --test test -- --show-output --uboot

0 commit comments

Comments
 (0)