quic/qbox
Loading...
Searching...
No Matches
riscv64.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 <libgssync.h>
17#include <module_factory_registery.h>
18
19#include <cpu.h>
20
21class QemuCpuRiscv64 : public QemuCpu
22{
23public:
24 sc_core::sc_vector<QemuTargetSignalSocket> irq_in;
25
26protected:
27 uint64_t m_hartid;
28 gs::async_event m_irq_ev;
29
30 void mip_update_cb(uint32_t value)
31 {
32 if (value) {
33 m_irq_ev.notify();
34 }
35 }
36
37public:
38 QemuCpuRiscv64(const sc_core::sc_module_name& name, QemuInstance& inst, const char* model, uint64_t hartid)
39 : QemuCpu(name, inst, std::string(model) + "-riscv")
40 , m_hartid(hartid)
41 /*
42 * We have no choice but to attach-suspend here. This is fixable but
43 * non-trivial. It means that the SystemC kernel will never starve...
44 */
45 , m_irq_ev(true)
46 , irq_in("irq_in", 32)
47 {
48 m_external_ev |= m_irq_ev;
49 for (auto& irq : irq_in) {
50 m_external_ev |= irq->default_event();
51 }
52 }
53
54 void before_end_of_elaboration()
55 {
56 QemuCpu::before_end_of_elaboration();
57
58 qemu::CpuRiscv64 cpu(get_qemu_dev());
59 cpu.set_prop_int("hartid", m_hartid);
60 cpu.set_mip_update_callback(std::bind(&QemuCpuRiscv64::mip_update_cb, this, std::placeholders::_1));
61 }
62
63 void end_of_elaboration() override
64 {
65 QemuCpu::end_of_elaboration();
66
67 // Initialize IRQ sockets with GPIO pin numbers 0-31
68 for (int i = 0; i < 32; i++) {
69 irq_in[i].init(m_dev, i);
70 }
71
72 // Register reset handler - needed for proper reset behavior when system reset is requested
73 qemu::CpuRiscv32 cpu(get_qemu_dev());
74 cpu.register_reset();
75 }
76};
77
79{
80public:
81 cpu_riscv64(const sc_core::sc_module_name& name, sc_core::sc_object* o, uint64_t hartid)
82 : cpu_riscv64(name, *(dynamic_cast<QemuInstance*>(o)), hartid)
83 {
84 }
85 cpu_riscv64(const sc_core::sc_module_name& n, QemuInstance& inst, uint64_t hartid)
86 : QemuCpuRiscv64(n, inst, "rv64", hartid)
87 {
88 }
89};
90
91extern "C" void module_register();
Definition riscv64.h:22
Definition cpu.h:31
This class encapsulates a libqemu-cxx qemu::LibQemu instance. It handles QEMU parameters and instance...
Definition qemu-instance.h:86
Definition target.h:160
Definition riscv64.h:79
Definition async_event.h:22
Definition riscv.h:30
Definition riscv.h:38