Merge tag 'pull-loongarch-20241016' of https://gitlab.com/gaosong/qemu into staging
[qemu/armbru.git] / tests / tcg / aarch64 / system / vtimer.c
blob7d725eced341bd2638935f05bed74a36103d1027
1 /*
2 * Simple Virtual Timer Test
4 * Copyright (c) 2020 Linaro Ltd
6 * SPDX-License-Identifier: GPL-2.0-or-later
7 */
9 #include <stdint.h>
10 #include <minilib.h>
12 /* grabbed from Linux */
13 #define __stringify_1(x...) #x
14 #define __stringify(x...) __stringify_1(x)
16 #define read_sysreg(r) ({ \
17 uint64_t __val; \
18 asm volatile("mrs %0, " __stringify(r) : "=r" (__val)); \
19 __val; \
22 #define write_sysreg(r, v) do { \
23 uint64_t __val = (uint64_t)(v); \
24 asm volatile("msr " __stringify(r) ", %x0" \
25 : : "rZ" (__val)); \
26 } while (0)
28 int main(void)
30 int i;
32 ml_printf("VTimer Test\n");
34 write_sysreg(cntvoff_el2, 1);
35 write_sysreg(cntv_cval_el0, -1);
36 write_sysreg(cntv_ctl_el0, 1);
38 ml_printf("cntvoff_el2=%lx\n", read_sysreg(cntvoff_el2));
39 ml_printf("cntv_cval_el0=%lx\n", read_sysreg(cntv_cval_el0));
40 ml_printf("cntv_ctl_el0=%lx\n", read_sysreg(cntv_ctl_el0));
42 /* Now read cval a few times */
43 for (i = 0; i < 10; i++) {
44 ml_printf("%d: cntv_cval_el0=%lx\n", i, read_sysreg(cntv_cval_el0));
47 return 0;