Skip to content

Commit 32f2826

Browse files
committed
2 parents a3a42ad + f831c56 commit 32f2826

File tree

1 file changed

+30
-27
lines changed

1 file changed

+30
-27
lines changed

README.md

+30-27
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# arv32-opt
2-
[Still testing!] Atmega328p port of mini-rv32ima. Let's run Linux on the world's worst Linux PC (and beat Dmitry Grinberg)
2+
[Tested successfully!] Atmega328p port of mini-rv32ima. Let's run Linux on the world's worst Linux PC (and beat Dmitry Grinberg)
3+
4+
![image](https://github.com/raspiduino/arv32-opt/assets/68118236/e457c5f7-110e-457c-ab98-48de47102af9)
5+
6+
[Video on Youtube](https://youtu.be/ZzReAELagG4)
7+
8+
Note: The code is in **pure AVR C**. Arduino IDE is just used as *serial terminal*.
39

410
## What is this?
511
This is a port of [mini-rv32ima](https://github.com/cnlohr/mini-rv32ima) (a minimum RISC-V emulator, capable of booting Linux) on atmega328p (the core of Arduino UNO, a 8-bit AVR microcontroller). So basically, this code is for **booting Linux on Arduino UNO**.
@@ -12,7 +18,7 @@ The idea is really simple: you have an Arduino UNO (or atmega328p) to run the em
1218
The code is written in pure C (and not Arduino) to reduce Arduino overhead (if any). It initializes UART, SPI, SD card, and a digital input-pullup pin for triggering emulator state dump. Finally, it initialize cache, then mini-rv32ima and let the emulator does its works.
1319

1420
## How fast is it?
15-
About ~~175Hz - 205Hz~~ ~~426 - 600Hz~~ 600 - 700 Hz with `-O3` code on an Arduino UNO based on atmega328p, clocked at 16MHz, with a class 4 SDHC card connected via 1-bit SPI interface.
21+
About ~~175Hz - 205Hz~~ ~~426 - 600Hz~~ most of the time 700 Hz, peak 1500Hz, lowest 70Hz with `-O3` code on an Arduino UNO based on atmega328p, clocked at 16MHz, with a class 4 SDHC card connected via 1-bit SPI interface. Complete boot time (from start to shell) is about 15 hours and 44 minutes.
1622

1723
Update 24/9/2023: The speed is double/tripled by implementing icache
1824

@@ -41,7 +47,7 @@ The pinout is really simple. On Arduino UNO, it should be:
4147
### Preparing the SD card
4248
- First, you will need an SD card. Any type larger than 12MB.
4349
> [!WARNING]
44-
> You should backup all your files, since doing this SD card preperation will destroy your SD card's filesystem.
50+
> You should backup all your files, since doing this SD card preparation will destroy your SD card's filesystem.
4551
- Then you need some tool to directly write a file to SD card. On Windows, you can use [HDD Raw Copy Tool](https://hddguru.com/software/HDD-Raw-Copy-Tool/), on *nix you can use `dd if=file.bin of=/dev/sdX conv=notrunc`.
4652
- Download the file [`arv32.bin`](https://github.com/raspiduino/arv32-opt/raw/main/rv32.bin) file.
4753
- Write it directly to the SD card using the tools in step 2.
@@ -81,8 +87,6 @@ arv32-opt: mini-rv32ima on Arduino UNO
8187
SD card initialized successfully!
8288
```
8389

84-
and (optionally, but normally, if your board is fast enough) the line `Currently at 0xB8` after these 2 lines.
85-
8690
> [!IMPORTANT]
8791
> The `Preparing the SD card` section must be repeated every time you boot your emulator. Otherwise it might not boot (if Linux has initialized enough and start cleaning the memory). This might be fixed in the future.
8892
@@ -91,37 +95,36 @@ and (optionally, but normally, if your board is fast enough) the line `Currently
9195
9296
You can also dump the state of the emulator while it's running. Just connect a button to `GND` and then connect pin 9 to the button. When you click the button, state will be dump, and you should see something like this:
9397
```text
94-
Effective emulated speed: 426 Hz, dtime=5632385ms, dcycle=2403328
95-
Current AVR free memory: 689 bytes
98+
Effective emulated speed: 1442 Hz, dtime=233596ms, dcycle=336896
99+
Current AVR free memory: 155 bytes
100+
icache hit/miss: 17931786/983542; dcache hit/miss: 4078057/1731330
96101
==============================================================================
97102
Dumping emulator state:
98103
Registers x0 - x31:
99-
0x00000000 0x80034C74 0x8027FBF0 0x802C29D0
100-
0x80281340 0x000A6465 0x00006C62 0x64656C62
101-
0x8027FC70 0x80284E0C 0x00000000 0x802B0E80
102-
0x00000003 0x00000003 0x00000000 0x00000000
103-
0x80284E0C 0x0000FFFF 0x8027FC78 0x8027FC94
104-
0x00000000 0xBFFFF803 0x3FFFFFFF 0x80284E50
105-
0x00000003 0x802C7000 0x0000000C 0x00000058
106-
0x802C918C 0x802C918C 0x802C916C 0x8027FC2C
107-
pc: 0x80034C74
108-
mstatus: 0x00000000
109-
cyclel: 0x002BA800
104+
0x00000000 0x800E6B34 0x8041F7A0 0x80332FC8
105+
0x80420000 0x9B779A7E 0xDFB0F4A6 0x29EEBE42
106+
0x8041F890 0xDEC0D0A6 0x9EE3B78E 0xA125AEE8
107+
0x0A29015A 0x969C9575 0x31D9B5BA 0x1A086279
108+
0xEFA9A208 0xAF715DDD 0x10C7F938 0x42557158
109+
0x9A2FA369 0x6AA2616B 0x8041F8B4 0x00000000
110+
0x00000000 0x36AAA20D 0x4BD078AB 0x000AF715
111+
0x68A94F06 0x53A31796 0xF822BFDD 0x1A73C5BB
112+
pc: 0x800E7144
113+
mstatus: 0x00001880
114+
cyclel: 0x0120A000
110115
cycleh: 0x00000000
111-
timerl: 0x002BA400
116+
timerl: 0x00904E00
112117
timerh: 0x00000000
113-
timermatchl: 0x00000000
118+
timermatchl: 0x009050BF
114119
timermatchh: 0x00000000
115120
mscratch: 0x00000000
116-
mtvec: 0x80001B78
117-
mie: 0x00000000
121+
mtvec: 0x80001CBC
122+
mie: 0x00000088
118123
mip: 0x00000000
119-
mepc: 0x00000000
124+
mepc: 0x800E6640
120125
mtval: 0x00000000
121-
mcause: 0x00000000
122-
extraflags: 0x015873A3
123-
==============================================================================
124-
Dump completed. Emulator will continue when B1 is set back to HIGH
126+
mcause: 0x80000007
127+
extraflags: 0x019446E3
125128
```
126129
`Effective emulated speed` is the number of instructions the emulator can execute in 1 second at that time. `dtime` is the time difference between current time and the last time you dump the status. `dcycle` is the number of cycle (instructions) excuted from the last time you dump the status until now.
127130
<br>`Registers x0 - x31` sections show registers from `x0` to `x31`, listed in order from left to right then from top down.

0 commit comments

Comments
 (0)