• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

.github/workflows/H15-Oct-2021-2922

arch_test_target/spike/H15-Oct-2021-583438

ci-tests/H15-Oct-2021-128

customext/H07-May-2022-13298

debug_rom/H15-Oct-2021-14192

disasm/H07-May-2022-1,8981,638

fdt/H07-May-2022-5,5342,708

fesvr/H15-Oct-2021-5,3333,797

riscv/H15-Oct-2021-30,31024,624

scripts/H03-May-2022-3,9523,373

softfloat/H07-May-2022-22,65311,331

spike_dasm/H07-May-2022-146114

spike_main/H07-May-2022-694565

tests/H15-Oct-2021-150121

.gitignoreH A D15-Oct-202157 87

ChangeLog.mdH A D15-Oct-2021966 2220

LICENSEH A D15-Oct-20211.4 KiB2521

Makefile.inH A D03-May-202216.9 KiB525262

README.mdH A D15-Oct-20218 KiB289225

VERSIONH A D15-Oct-202134 21

aclocal.m4H A D15-Oct-202110.6 KiB303242

ax_append_flag.m4H A D15-Oct-20211.5 KiB5148

ax_append_link_flags.m4H A D15-Oct-20211.7 KiB4542

ax_boost_asio.m4H A D15-Oct-20213.8 KiB111102

ax_boost_base.m4H A D15-Oct-202113.5 KiB304276

ax_boost_regex.m4H A D15-Oct-20214.1 KiB112104

ax_check_compile_flag.m4H A D15-Oct-20212.1 KiB5451

ax_check_link_flag.m4H A D15-Oct-20211.9 KiB5451

ax_require_defined.m4H A D15-Oct-20211.2 KiB3835

config.h.inH A D15-Oct-20213.7 KiB14398

configureH A D15-Oct-2021215.1 KiB7,7155,956

configure.acH A D15-Oct-20215 KiB127102

riscv-disasm.pc.inH A D15-Oct-2021283 1210

riscv-fesvr.pc.inH A D15-Oct-2021284 1210

README.md

1Spike RISC-V ISA Simulator
2============================
3
4About
5-------------
6
7Spike, the RISC-V ISA Simulator, implements a functional model of one or more
8RISC-V harts.  It is named after the golden spike used to celebrate the
9completion of the US transcontinental railway.
10
11Spike supports the following RISC-V ISA features:
12  - RV32I and RV64I base ISAs, v2.1
13  - Zifencei extension, v2.0
14  - Zicsr extension, v2.0
15  - M extension, v2.0
16  - A extension, v2.1
17  - F extension, v2.2
18  - D extension, v2.2
19  - Q extension, v2.2
20  - C extension, v2.0
21  - K extension, v0.8.1 ([Scalar Cryptography](https://github.com/riscv/riscv-crypto))
22  - V extension, v1.0 (_requires a 64-bit host_)
23  - P extension, v0.9.2
24  - Zba extension, v1.0
25  - Zbb extension, v1.0
26  - Zbc extension, v1.0
27  - Zbs extension, v1.0
28  - Conformance to both RVWMO and RVTSO (Spike is sequentially consistent)
29  - Machine, Supervisor, and User modes, v1.11
30  - Hypervisor extension, v0.6.1
31  - Svnapot extension, v0.1
32  - Svpbmt extension, v0.1
33  - Svinval extension, v0.1
34  - Debug v0.14
35
36As a Spike extension, the remainder of the proposed
37[Bit-Manipulation Extensions](https://github.com/riscv/riscv-bitmanip)
38is provided under the Spike-custom extension name _Xbitmanip_.
39These instructions (and, of course, the extension name) are not RISC-V
40standards.
41
42Versioning and APIs
43-------------------
44
45Projects are versioned primarily to indicate when the API has been extended or
46rendered incompatible.  In that spirit, Spike aims to follow the
47[SemVer](https://semver.org/spec/v2.0.0.html) versioning scheme, in which
48major version numbers are incremented when backwards-incompatible API changes
49are made; minor version numbers are incremented when new APIs are added; and
50patch version numbers are incremented when bugs are fixed in
51a backwards-compatible manner.
52
53Spike's principal public API is the RISC-V ISA.  _The C++ interface to Spike's
54internals is **not** considered a public API at this time_, and
55backwards-incompatible changes to this interface _will_ be made without
56incrementing the major version number.
57
58Build Steps
59---------------
60
61We assume that the RISCV environment variable is set to the RISC-V tools
62install path.
63
64    $ apt-get install device-tree-compiler
65    $ mkdir build
66    $ cd build
67    $ ../configure --prefix=$RISCV
68    $ make
69    $ [sudo] make install
70
71If your system uses the `yum` package manager, you can substitute
72`yum install dtc` for the first step.
73
74Build Steps on OpenBSD
75----------------------
76
77Install bash, gmake, dtc, and use clang.
78
79    $ pkg_add bash gmake dtc
80    $ exec bash
81    $ export CC=cc; export CXX=c++
82    $ mkdir build
83    $ cd build
84    $ ../configure --prefix=$RISCV
85    $ gmake
86    $ [doas] make install
87
88Compiling and Running a Simple C Program
89-------------------------------------------
90
91Install spike (see Build Steps), riscv-gnu-toolchain, and riscv-pk.
92
93Write a short C program and name it hello.c.  Then, compile it into a RISC-V
94ELF binary named hello:
95
96    $ riscv64-unknown-elf-gcc -o hello hello.c
97
98Now you can simulate the program atop the proxy kernel:
99
100    $ spike pk hello
101
102Simulating a New Instruction
103------------------------------------
104
105Adding an instruction to the simulator requires two steps:
106
107  1.  Describe the instruction's functional behavior in the file
108      riscv/insns/<new_instruction_name>.h.  Examine other instructions
109      in that directory as a starting point.
110
111  2.  Add the opcode and opcode mask to riscv/opcodes.h.  Alternatively,
112      add it to the riscv-opcodes package, and it will do so for you:
113        ```
114         $ cd ../riscv-opcodes
115         $ vi opcodes       // add a line for the new instruction
116         $ make install
117        ```
118
119  3.  Rebuild the simulator.
120
121Interactive Debug Mode
122---------------------------
123
124To invoke interactive debug mode, launch spike with -d:
125
126    $ spike -d pk hello
127
128To see the contents of an integer register (0 is for core 0):
129
130    : reg 0 a0
131
132To see the contents of a floating point register:
133
134    : fregs 0 ft0
135
136or:
137
138    : fregd 0 ft0
139
140depending upon whether you wish to print the register as single- or double-precision.
141
142To see the contents of a memory location (physical address in hex):
143
144    : mem 2020
145
146To see the contents of memory with a virtual address (0 for core 0):
147
148    : mem 0 2020
149
150You can advance by one instruction by pressing the enter key. You can also
151execute until a desired equality is reached:
152
153    : until pc 0 2020                   (stop when pc=2020)
154    : until mem 2020 50a9907311096993   (stop when mem[2020]=50a9907311096993)
155
156Alternatively, you can execute as long as an equality is true:
157
158    : while mem 2020 50a9907311096993
159
160You can continue execution indefinitely by:
161
162    : r
163
164At any point during execution (even without -d), you can enter the
165interactive debug mode with `<control>-<c>`.
166
167To end the simulation from the debug prompt, press `<control>-<c>` or:
168
169    : q
170
171Debugging With Gdb
172------------------
173
174An alternative to interactive debug mode is to attach using gdb. Because spike
175tries to be like real hardware, you also need OpenOCD to do that. OpenOCD
176doesn't currently know about address translation, so it's not possible to
177easily debug programs that are run under `pk`. We'll use the following test
178program:
179```
180$ cat rot13.c
181char text[] = "Vafgehpgvba frgf jnag gb or serr!";
182
183// Don't use the stack, because sp isn't set up.
184volatile int wait = 1;
185
186int main()
187{
188    while (wait)
189        ;
190
191    // Doesn't actually go on the stack, because there are lots of GPRs.
192    int i = 0;
193    while (text[i]) {
194        char lower = text[i] | 32;
195        if (lower >= 'a' && lower <= 'm')
196            text[i] += 13;
197        else if (lower > 'm' && lower <= 'z')
198            text[i] -= 13;
199        i++;
200    }
201
202done:
203    while (!wait)
204        ;
205}
206$ cat spike.lds
207OUTPUT_ARCH( "riscv" )
208
209SECTIONS
210{
211  . = 0x10010000;
212  .text : { *(.text) }
213  .data : { *(.data) }
214}
215$ riscv64-unknown-elf-gcc -g -Og -o rot13-64.o -c rot13.c
216$ riscv64-unknown-elf-gcc -g -Og -T spike.lds -nostartfiles -o rot13-64 rot13-64.o
217```
218
219To debug this program, first run spike telling it to listen for OpenOCD:
220```
221$ spike --rbb-port=9824 -m0x10000000:0x20000 rot13-64
222Listening for remote bitbang connection on port 9824.
223```
224
225In a separate shell run OpenOCD with the appropriate configuration file:
226```
227$ cat spike.cfg
228interface remote_bitbang
229remote_bitbang_host localhost
230remote_bitbang_port 9824
231
232set _CHIPNAME riscv
233jtag newtap $_CHIPNAME cpu -irlen 5 -expected-id 0x10e31913
234
235set _TARGETNAME $_CHIPNAME.cpu
236target create $_TARGETNAME riscv -chain-position $_TARGETNAME
237
238gdb_report_data_abort enable
239
240init
241halt
242$ openocd -f spike.cfg
243Open On-Chip Debugger 0.10.0-dev-00002-gc3b344d (2017-06-08-12:14)
244...
245riscv.cpu: target state: halted
246```
247
248In yet another shell, start your gdb debug session:
249```
250tnewsome@compy-vm:~/SiFive/spike-test$ riscv64-unknown-elf-gdb rot13-64
251GNU gdb (GDB) 8.0.50.20170724-git
252Copyright (C) 2017 Free Software Foundation, Inc.
253License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
254This is free software: you are free to change and redistribute it.
255There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
256and "show warranty" for details.
257This GDB was configured as "--host=x86_64-pc-linux-gnu --target=riscv64-unknown-elf".
258Type "show configuration" for configuration details.
259For bug reporting instructions, please see:
260<http://www.gnu.org/software/gdb/bugs/>.
261Find the GDB manual and other documentation resources online at:
262<http://www.gnu.org/software/gdb/documentation/>.
263For help, type "help".
264Type "apropos word" to search for commands related to "word"...
265Reading symbols from rot13-64...done.
266(gdb) target remote localhost:3333
267Remote debugging using localhost:3333
2680x0000000010010004 in main () at rot13.c:8
2698	    while (wait)
270(gdb) print wait
271$1 = 1
272(gdb) print wait=0
273$2 = 0
274(gdb) print text
275$3 = "Vafgehpgvba frgf jnag gb or serr!"
276(gdb) b done
277Breakpoint 1 at 0x10010064: file rot13.c, line 22.
278(gdb) c
279Continuing.
280Disabling abstract command writes to CSRs.
281
282Breakpoint 1, main () at rot13.c:23
28323	    while (!wait)
284(gdb) print wait
285$4 = 0
286(gdb) print text
287...
288```
289