Skip to content
This repository was archived by the owner on Jan 25, 2022. It is now read-only.

Commit 21d7c7c

Browse files
committed
Initial import
0 parents  commit 21d7c7c

File tree

7 files changed

+2259
-0
lines changed

7 files changed

+2259
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
emu-rv32i
2+
test1

AUTHORS

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Fabrice Bellard - original code of RISC-V emulator:
2+
https://bellard.org/tinyemu/
3+
4+
Frank Buss - simplified emulator for RV32I capable of passing compliance tests:
5+
https://gist.github.com/FrankBuss/c974e59826d33e21d7cad54491ab50e8
6+
7+
Alexander Shabarshin - maintainer of this nedoPC-5 project:
8+
https://gitlab.com/nedopc/npc5

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Original MIT License:
2+
3+
Copyright (c) 2016-2017 Fabrice Bellard
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18+
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

Makefile

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
BINS = emu-rv32i test1
2+
3+
CROSS_COMPILE = riscv-none-embed-
4+
RV32I_CFLAGS = -march=rv32i -mabi=ilp32 -O3 -nostdlib
5+
6+
CFLAGS = -O3 -Wall
7+
LDFLAGS = -lelf
8+
9+
all: $(BINS)
10+
11+
emu-rv32i: emu-rv32i.c
12+
$(CC) $(CFLAGS) -o $@ $< $(LDFLAGS)
13+
14+
test1: test1.c
15+
$(CROSS_COMPILE)gcc $(RV32I_CFLAGS) -o $@ $<
16+
17+
check: $(BINS)
18+
./emu-rv32i test1
19+
20+
clean:
21+
$(RM) $(BINS)

README.md

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# RISC-V RV32I[MA] emulator with ELF support
2+
3+
Emulator was originally created by Fabrice Bellard and then modified and shared on Hackaday by Frank Buss
4+
as a single C-file. Shaos added some additional statistics and macros. How to compile it:
5+
6+
gcc -O3 -Wall -lelf emu-rv32i.c -o emu-rv32i
7+
8+
Passed RV32I compliance tests from https://github.com/riscv/riscv-compliance
9+
10+
make RISCV_TARGET=spike RISCV_DEVICE=rv32i TARGET_SIM=/full/path/emulator variant
11+
12+
Compiling and running simple code:
13+
14+
riscv32-unknown-elf-gcc -O3 -nostdlib test1.c -o test1
15+
16+
or
17+
18+
riscv64-unknown-elf-gcc -march=rv32i -mabi=ilp32 -O3 -nostdlib test1.c -o test1
19+
20+
then
21+
22+
./emu-rv32i test1
23+
Hello RISC-V!
24+
25+
RV32M and RV32A instructions may be enabled by commenting #define STRICT_RV32I
26+
27+
## How to build RISC-V toolchain from scratch
28+
29+
https://github.com/riscv/riscv-gnu-toolchain
30+
31+
64-bit universal version (riscv64-unknown-elf-* that can build 32-bit code too):
32+
33+
./configure --prefix=/opt/riscv
34+
make
35+
36+
32-bit version (riscv32-unknown-elf-*):
37+
38+
./configure --prefix=/opt/riscv32 --with-arch=rv32i --with-abi=ilp32
39+
make

0 commit comments

Comments
 (0)