bugaevc/wip-aarch64 branched off gnumach master in early 2024. Since
then upstream's kern/clock.c gained references to two per-arch hooks
that read the ARMv8 generic timer's CNTPCT_EL0 directly:
uint32_t hpclock_read_counter(void);
uint32_t hpclock_get_counter_period_nsec(void);
wip-aarch64 predates them, so the previous commit (the verbatim
import) doesn't link against current master:
undefined reference to `hpclock_read_counter'
undefined reference to `hpclock_get_counter_period_nsec'
Add the two functions to aarch64/arm/timer.c. Both are trivial
wrappers: read CNTPCT_EL0 for the counter, derive the period from
cnt_freq (set during cnt_init from the DTB's clock-frequency
property).
After this commit, gnumach links cleanly on aarch64 against current
savannah master. Two subsequent commits address early-boot bugs
that prevent it from running.
---
aarch64/arm/timer.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/aarch64/arm/timer.c b/aarch64/arm/timer.c
index ac0114f0..1aff1d19 100644
--- a/aarch64/arm/timer.c
+++ b/aarch64/arm/timer.c
@@ -101,3 +101,15 @@ void cnt_init(dtb_node_t node)
}
}
}
+
+uint32_t hpclock_read_counter(void)
+{
+ uint64_t v;
+ asm volatile("mrs %0, CNTPCT_EL0" : "=r"(v));
+ return (uint32_t) v;
+}
+
+uint32_t hpclock_get_counter_period_nsec(void)
+{
+ return cnt_freq ? (uint32_t)(1000000000UL / cnt_freq) : 0;
+}
--
2.54.0