Skip to content

Commit a03e1bd

Browse files
committed
更新 axplat-aarch64-dyn 平台的依赖项,移除不必要的版本号,添加物理地址与虚拟地址转换函数,完善时间管理功能。
1 parent 2aab152 commit a03e1bd

File tree

7 files changed

+77
-59
lines changed

7 files changed

+77
-59
lines changed

Cargo.lock

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

platforms/axplat-aarch64-dyn/Cargo.toml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ repository.workspace = true
99
version = "0.1.0"
1010

1111
[dependencies]
12+
aarch64-cpu = "10"
13+
any-uart = "0.2.11"
1214
axconfig-macros = "0.2"
13-
axplat = {git = "https://github.com/arceos-org/axplat_crates"}
15+
axcpu = {workspace = true}
16+
axplat = {workspace = true}
17+
fdt-parser = "0.4"
18+
heapless = "0.8"
19+
memory_addr = "0.3"
1420
pie-boot = {version = "0.2.2"}
15-
any-uart = "0.2.11"
1621
spin = "0.10"
17-
axcpu = { workspace = true }
18-
heapless = "0.8"
19-
fdt-parser = "0.4"

platforms/axplat-aarch64-dyn/src/init.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,13 @@ impl InitIf for InitIfImpl {
6868
/// * Timer interrupts are enabled (if applicable).
6969
/// * Other platform devices are initialized.
7070
fn init_later(cpu_id: usize, arg: usize) {
71-
todo!()
71+
7272
}
7373

7474
/// Initializes the platform at the later stage for secondary cores.
7575
///
7676
/// See [`init_later`] for details.
7777
fn init_later_secondary(cpu_id: usize) {
78-
todo!()
78+
7979
}
8080
}

platforms/axplat-aarch64-dyn/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
extern crate axplat;
66

77
use pie_boot::BootInfo;
8-
use spin::Once;
98

109
mod console;
1110
mod init;

platforms/axplat-aarch64-dyn/src/mem.rs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
use core::ops::Range;
2+
13
use axplat::mem::{MemIf, RawRange};
24
use heapless::Vec;
3-
use pie_boot::{MemoryRegionKind, boot_info};
5+
use memory_addr::{PhysAddr, VirtAddr};
6+
use pie_boot::{KIMAGE_VADDR, KLINER_OFFSET, MemoryRegionKind, boot_info};
47
use spin::{Mutex, Once};
58

69
struct MemIfImpl;
@@ -67,4 +70,31 @@ impl MemIf for MemIfImpl {
6770
fn mmio_ranges() -> &'static [RawRange] {
6871
&[]
6972
}
73+
74+
fn phys_to_virt(p: PhysAddr) -> VirtAddr {
75+
if kimage_range_phys().contains(&p) {
76+
VirtAddr::from_usize(p.as_usize() + KIMAGE_VADDR)
77+
} else {
78+
// MMIO or other reserved regions
79+
VirtAddr::from_usize(p.as_usize() + KLINER_OFFSET)
80+
}
81+
}
82+
fn virt_to_phys(p: VirtAddr) -> PhysAddr {
83+
if (KIMAGE_VADDR..KLINER_OFFSET).contains(&p.as_usize()) {
84+
PhysAddr::from_usize(p.as_usize() - KIMAGE_VADDR)
85+
} else {
86+
PhysAddr::from_usize(p.as_usize() - KLINER_OFFSET)
87+
}
88+
}
89+
}
90+
91+
fn kimage_range_phys() -> Range<PhysAddr> {
92+
unsafe extern "C" {
93+
fn _skernel();
94+
fn _ekernel();
95+
}
96+
97+
let start = PhysAddr::from_usize(_skernel as usize - KIMAGE_VADDR);
98+
let end = PhysAddr::from_usize(_ekernel as usize - KIMAGE_VADDR);
99+
start..end
70100
}

platforms/axplat-aarch64-dyn/src/power.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use aarch64_cpu::asm::wfi;
12
use axplat::power::PowerIf;
23

34
struct PowerImpl;
@@ -15,6 +16,8 @@ impl PowerIf for PowerImpl {
1516

1617
/// Shutdown the whole system.
1718
fn system_off() -> ! {
18-
todo!()
19+
loop {
20+
wfi();
21+
}
1922
}
2023
}

platforms/axplat-aarch64-dyn/src/time.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use aarch64_cpu::registers::*;
12
use axplat::time::TimeIf;
23

34
struct TimeIfImpl;
@@ -6,17 +7,21 @@ struct TimeIfImpl;
67
impl TimeIf for TimeIfImpl {
78
/// Returns the current clock time in hardware ticks.
89
fn current_ticks() -> u64 {
9-
todo!()
10+
CNTPCT_EL0.get()
1011
}
1112

1213
/// Converts hardware ticks to nanoseconds.
1314
fn ticks_to_nanos(ticks: u64) -> u64 {
14-
todo!()
15+
let freq = CNTFRQ_EL0.get();
16+
// Convert ticks to nanoseconds using the frequency.
17+
(ticks * axplat::time::NANOS_PER_SEC) / freq
1518
}
1619

1720
/// Converts nanoseconds to hardware ticks.
1821
fn nanos_to_ticks(nanos: u64) -> u64 {
19-
todo!()
22+
let freq = CNTFRQ_EL0.get();
23+
// Convert nanoseconds to ticks using the frequency.
24+
(nanos * freq) / axplat::time::NANOS_PER_SEC
2025
}
2126

2227
/// Return epoch offset in nanoseconds (wall time offset to monotonic

0 commit comments

Comments
 (0)