Files
Yaya48 cf256aa081 Import QEMU upstream snapshot d2e570c
Upstream: https://gitlab.com/qemu-project/qemu.git

Upstream-Commit: d2e570cc0f97b936902a5b1b86b73c0f5998b475
2026-08-31 02:15:30 +02:00

85 lines
2.0 KiB
C

/*
* QTest testcase for RISC-V CSRs
*
* Copyright (c) 2024 Syntacore.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
#include "qemu/osdep.h"
#include "libqtest.h"
#define CSR_MVENDORID 0xf11
#define CSR_MISELECT 0x350
#define CSR_SEED 0x015
#define SEED_OPST_MASK (UINT64_C(0x3) << 30)
#define SEED_OPST_ES16 (UINT64_C(0x2) << 30)
#define SEED_OPST_DEAD (UINT64_C(0x3) << 30)
static void run_test_csr(void)
{
uint64_t res;
uint64_t val = 0;
QTestState *qts = qtest_init("-machine virt -cpu veyron-v1");
res = qtest_csr_call(qts, "get_csr", 0, CSR_MVENDORID, &val);
g_assert_cmpint(res, ==, 0);
g_assert_cmpint(val, ==, 0x61f);
val = 0xff;
res = qtest_csr_call(qts, "set_csr", 0, CSR_MISELECT, &val);
g_assert_cmpint(res, ==, 0);
val = 0;
res = qtest_csr_call(qts, "get_csr", 0, CSR_MISELECT, &val);
g_assert_cmpint(res, ==, 0);
g_assert_cmpint(val, ==, 0xff);
qtest_quit(qts);
}
static void run_test_seed_csr(void)
{
uint64_t val = 0;
uint64_t opst;
QTestState *qts;
qts = qtest_init("-machine virt -cpu tt-ascalon");
qtest_csr_call(qts, "get_csr", 0, CSR_SEED, &val);
opst = val & SEED_OPST_MASK;
g_assert_true(opst == SEED_OPST_ES16 ||
opst == SEED_OPST_DEAD);
g_assert_cmphex(val >> 32, ==, 0);
qtest_quit(qts);
}
int main(int argc, char **argv)
{
g_test_init(&argc, &argv, NULL);
if (qtest_has_machine("virt")) {
qtest_add_func("/cpu/csr", run_test_csr);
qtest_add_func("/cpu/csr/seed", run_test_seed_csr);
}
return g_test_run();
}