master
c 84 lines 2.05 KB
Raw
1 /*
2 * QTest testcase for RISC-V CSRs
3 *
4 * Copyright (c) 2024 Syntacore.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * for more details.
15 */
16
17 #include "qemu/osdep.h"
18 #include "libqtest.h"
19
20 #define CSR_MVENDORID 0xf11
21 #define CSR_MISELECT 0x350
22
23 #define CSR_SEED 0x015
24
25 #define SEED_OPST_MASK (UINT64_C(0x3) << 30)
26 #define SEED_OPST_ES16 (UINT64_C(0x2) << 30)
27 #define SEED_OPST_DEAD (UINT64_C(0x3) << 30)
28
29 static void run_test_csr(void)
30 {
31 uint64_t res;
32 uint64_t val = 0;
33
34 QTestState *qts = qtest_init("-machine virt -cpu veyron-v1");
35
36 res = qtest_csr_call(qts, "get_csr", 0, CSR_MVENDORID, &val);
37
38 g_assert_cmpint(res, ==, 0);
39 g_assert_cmpint(val, ==, 0x61f);
40
41 val = 0xff;
42 res = qtest_csr_call(qts, "set_csr", 0, CSR_MISELECT, &val);
43
44 g_assert_cmpint(res, ==, 0);
45
46 val = 0;
47 res = qtest_csr_call(qts, "get_csr", 0, CSR_MISELECT, &val);
48
49 g_assert_cmpint(res, ==, 0);
50 g_assert_cmpint(val, ==, 0xff);
51
52 qtest_quit(qts);
53 }
54
55 static void run_test_seed_csr(void)
56 {
57 uint64_t val = 0;
58 uint64_t opst;
59 QTestState *qts;
60
61 qts = qtest_init("-machine virt -cpu tt-ascalon");
62
63 qtest_csr_call(qts, "get_csr", 0, CSR_SEED, &val);
64
65 opst = val & SEED_OPST_MASK;
66 g_assert_true(opst == SEED_OPST_ES16 ||
67 opst == SEED_OPST_DEAD);
68
69 g_assert_cmphex(val >> 32, ==, 0);
70
71 qtest_quit(qts);
72 }
73
74 int main(int argc, char **argv)
75 {
76 g_test_init(&argc, &argv, NULL);
77
78 if (qtest_has_machine("virt")) {
79 qtest_add_func("/cpu/csr", run_test_csr);
80 qtest_add_func("/cpu/csr/seed", run_test_seed_csr);
81 }
82
83 return g_test_run();
84 }