quic/qbox
Loading...
Searching...
No Matches
sifive-x280-rtl.h
1/*
2 * This file is part of libqbox
3 * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All Rights Reserved.
4 * Author: GreenSocs 2021
5 *
6 * SPDX-License-Identifier: BSD-3-Clause
7 */
8
9#pragma once
10
11#include <string>
12#include <functional>
13
14#include <libqemu-cxx/target/riscv.h>
15
16#include <module_factory_registery.h>
17
18#include <libgssync.h>
19
20#include <cpu.h>
21
23{
24protected:
25 uint64_t m_hartid;
26 gs::async_event m_irq_ev;
27
28 void mip_update_cb(uint32_t value)
29 {
30 if (value) {
31 m_irq_ev.notify();
32 }
33 }
34
35public:
36 cpu_sifive_X280(const sc_core::sc_module_name& name, sc_core::sc_object* o, /*const char* model*/std::string model, uint64_t hartid)
37 : cpu_sifive_X280(name, *(dynamic_cast<QemuInstance*>(o)), model, hartid)
38 {
39 }
40 cpu_sifive_X280(const sc_core::sc_module_name& name, QemuInstance& inst, /*const char* model*/std::string model, uint64_t hartid)
41 : QemuCpu(name, inst, /*std::string(model)*/ model + "-riscv")
42 , m_hartid(hartid)
43 /*
44 * We have no choice but to attach-suspend here. This is fixable but
45 * non-trivial. It means that the SystemC kernel will never starve...
46 */
47 , m_irq_ev(true)
48 {
49 m_external_ev |= m_irq_ev;
50 }
51
52 void before_end_of_elaboration()
53 {
54 QemuCpu::before_end_of_elaboration();
55
56 qemu::CpuRiscv64SiFiveX280 cpu(get_qemu_dev());
57 cpu.set_prop_int("hartid", m_hartid);
58
59 cpu.set_mip_update_callback(std::bind(&cpu_sifive_X280::mip_update_cb, this, std::placeholders::_1));
60 }
61
62 // properties to be set from main.cc
63};
64
65extern "C" void module_register();
Definition cpu.h:30
This class encapsulates a libqemu-cxx qemu::LibQemu instance. It handles QEMU parameters and instance...
Definition qemu-instance.h:89
Definition target.h:160
Definition sifive-x280-rtl.h:23
Definition async_event.h:22
Definition riscv.h:45