|
| 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 | +static void run_test_csr(void) |
| 24 | +{ |
| 25 | + uint64_t res; |
| 26 | + uint64_t val = 0; |
| 27 | + |
| 28 | + QTestState *qts = qtest_init("-machine virt -cpu veyron-v1"); |
| 29 | + |
| 30 | + res = qtest_csr_call(qts, "get_csr", 0, CSR_MVENDORID, &val); |
| 31 | + |
| 32 | + g_assert_cmpint(res, ==, 0); |
| 33 | + g_assert_cmpint(val, ==, 0x61f); |
| 34 | + |
| 35 | + val = 0xff; |
| 36 | + res = qtest_csr_call(qts, "set_csr", 0, CSR_MISELECT, &val); |
| 37 | + |
| 38 | + g_assert_cmpint(res, ==, 0); |
| 39 | + |
| 40 | + val = 0; |
| 41 | + res = qtest_csr_call(qts, "get_csr", 0, CSR_MISELECT, &val); |
| 42 | + |
| 43 | + g_assert_cmpint(res, ==, 0); |
| 44 | + g_assert_cmpint(val, ==, 0xff); |
| 45 | + |
| 46 | + qtest_quit(qts); |
| 47 | +} |
| 48 | + |
| 49 | +int main(int argc, char **argv) |
| 50 | +{ |
| 51 | + g_test_init(&argc, &argv, NULL); |
| 52 | + |
| 53 | + qtest_add_func("/cpu/csr", run_test_csr); |
| 54 | + |
| 55 | + return g_test_run(); |
| 56 | +} |
0 commit comments