orca-sim
HFRiscV.hpp
Go to the documentation of this file.
1 /******************************************************************************
2  * This file is part of project ORCA. More information on the project
3  * can be found at the following repositories at GitHub's website.
4  *
5  * http://https://github.com/andersondomingues/orca-sim
6  * http://https://github.com/andersondomingues/orca-software
7  * http://https://github.com/andersondomingues/orca-mpsoc
8  * http://https://github.com/andersondomingues/orca-tools
9  *
10  * Copyright (C) 2018-2020 Anderson Domingues, <ti.andersondomingues@gmail.com>
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 2 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License along
23  * with this program; if not, write to the Free Software Foundation, Inc.,
24  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 ******************************************************************************/
26 #ifndef MODELS_HFRISCV_CORE_INCLUDE_HFRISCV_HPP_
27 #define MODELS_HFRISCV_CORE_INCLUDE_HFRISCV_HPP_
28 
29 // std libraries
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <string.h>
33 #include <stdint.h>
34 
35 #include <string>
36 
37 // simulator libs
38 #include "ProcessorBase.hpp"
39 
40 // models libs
41 #include "Memory.hpp"
42 #include "Signal.hpp"
43 
44 #define HFRISCV_PC_MEMBASE 0x40000000
45 
46 #define EXIT_TRAP 0xe0000000
47 #define IRQ_VECTOR 0xf0000000
48 #define IRQ_CAUSE 0xf0000010
49 #define IRQ_MASK 0xf0000020
50 #define IRQ_STATUS 0xf0000030
51 #define IRQ_EPC 0xf0000040
52 #define COUNTER 0xf0000050
53 #define COMPARE 0xf0000060
54 #define COMPARE2 0xf0000070
55 #define EXTIO_IN 0xf0000080
56 #define EXTIO_OUT 0xf0000090
57 #define DEBUG_ADDR 0xf00000d0
58 #define UART_WRITE 0xf00000e0
59 #define UART_READ 0xf00000e0
60 #define UART_DIVISOR 0xf00000f0
61 
65 
67 
68 typedef struct {
69  int32_t r[32];
70  uint32_t vector, cause, mask, status, status_dly[4], epc,
71  counter, compare, compare2;
72  uint64_t cycles;
73 } risc_v_state;
74 
75 // inherits for a 32-bit processor
76 class HFRiscV : public ProcessorBase<uint32_t>{
77  private:
78  uint32_t _last_pc;
79 
80  // interruption wire
83 
84  // context
86 
87  int i;
88 
89  #ifdef HFRISCV_ENABLE_COUNTERS
90  void UpdateCounters(int opcode, int funct3);
91 
92  Signal<uint32_t>* _counter_iarith;
93  Signal<uint32_t>* _counter_ilogical;
94  Signal<uint32_t>* _counter_ishift;
95  Signal<uint32_t>* _counter_ibranches;
96  Signal<uint32_t>* _counter_ijumps;
97  Signal<uint32_t>* _counter_iloadstore;
98 
99  Signal<uint32_t>* _counter_cycles_total;
100  Signal<uint32_t>* _counter_cycles_stall;
101 
102  Signal<uint32_t>* _counter_hosttime;
103  #endif
104 
105  public:
106  #ifdef HFRISCV_ENABLE_COUNTERS
107  Signal<uint32_t>* GetSignalCounterArith();
108  Signal<uint32_t>* GetSignalCounterLogical();
109  Signal<uint32_t>* GetSignalCounterShift();
110  Signal<uint32_t>* GetSignalCounterBranches();
111  Signal<uint32_t>* GetSignalCounterJumps();
112  Signal<uint32_t>* GetSignalCounterLoadStore();
113 
114  Signal<uint32_t>* GetSignalCounterCyclesTotal();
115  Signal<uint32_t>* GetSignalCounterCyclesStall();
116 
117  Signal<uint32_t>* GetSignalHostTime();
118  #endif
119 
120  void dumpregs();
121  void bp(risc_v_state *s, uint32_t ir);
122  int32_t mem_read(risc_v_state *s, int32_t size, uint32_t address);
123  void mem_write(risc_v_state *s, int32_t size, uint32_t address,
124  uint32_t value);
125 
126  // ctor./dtor.
127  HFRiscV(std::string name, Signal<uint8_t>* intr, Signal<uint8_t>* stall,
128  Memory* mem);
129  ~HFRiscV();
130 
133 
135 
136  // file output
137  std::ofstream output_debug;
138  std::ofstream output_uart;
139 
140  void Reset();
141 };
142 
143 } // namespace orcasim::models::hfriscv
144 #endif // MODELS_HFRISCV_CORE_INCLUDE_HFRISCV_HPP_
The Signal class models a generic bus of width equals to the sizeof(T)
Definition: Signal.hpp:45
void bp(risc_v_state *s, uint32_t ir)
Definition: HFRiscV.cpp:53
HFRiscV(std::string name, Signal< uint8_t > *intr, Signal< uint8_t > *stall, Memory *mem)
Definition: HFRiscV.cpp:738
Signal< uint8_t > * GetSignalStall()
Definition: HFRiscV.cpp:153
void mem_write(risc_v_state *s, int32_t size, uint32_t address, uint32_t value)
Reads data from memory.
Definition: HFRiscV.cpp:168
uint32_t SimulationTime
Signal< uint8_t > * _signal_stall
Definition: HFRiscV.hpp:82
int32_t mem_read(risc_v_state *s, int32_t size, uint32_t address)
Reads data from the memory.
Definition: HFRiscV.cpp:71
This class models a memory module.
Definition: Memory.hpp:55
This class implements the base operation for generic processor implementations.
Signal< uint8_t > * GetSignalIntr()
Definition: HFRiscV.cpp:157
SimulationTime Run()
Run method from the base TimedModel class, overloaded.
Definition: HFRiscV.cpp:368
Signal< uint8_t > * _signal_intr
Definition: HFRiscV.hpp:81