2
2
3
3
This is a bare metal 64-bit RISC-V assembly program outputing ` Hello. ` . It is
4
4
compiled with the riscv-gnu-toolchain and can be run with the QEMU ` sifive_u `
5
- machine .
5
+ and ` sifive_e ` machines .
6
6
7
7
I searched for such a program on the Internet but the only examples I found
8
8
were either bare metal C, or assembly but relying on an OS. Eventually I took
@@ -29,11 +29,12 @@ Assuming the toolchain is in the `$PATH`, running the following produces our
29
29
` hello ` program.
30
30
31
31
```
32
- $ riscv64-unknown-elf-gcc -march=rv64g -mabi=lp64 -static -mcmodel=medany \
33
- -fvisibility=hidden -nostdlib -nostartfiles -Thello.ld hello.s -o hello
32
+ $ riscv64-unknown-elf-gcc -march=rv64g -mabi=lp64 -static -mcmodel=medany \
33
+ -fvisibility=hidden -nostdlib -nostartfiles -Tsifive_u/hello.ld -Isifive_u \
34
+ hello.s -o hello
34
35
```
35
36
36
- The result is a 64-bit RISC-V binary.
37
+ The result is a 64-bit RISC-V binary compatible with QEMU ` sifive_u ` machine .
37
38
38
39
```
39
40
$ file hello
@@ -55,6 +56,33 @@ Note: the program enters an infinite loop after producing the `Hello.` text.
55
56
Type ` ctrl-a x ` to stop QEMU.
56
57
57
58
59
+ ## Sifive_e machine
60
+
61
+ This program can be compiled for more resticted machines like ` sifive_e `
62
+ that support 32-bit RISC-V, have small amount of RAM and requires executable
63
+ code to be placed in ROM with different start address.
64
+
65
+ Assuming the toolchain is in the ` $PATH ` , running the following produces our
66
+ ` hello ` program, but now ready for ` sifive_e ` .
67
+
68
+ ```
69
+ $ riscv64-unknown-elf-gcc -march=rv32g -mabi=ilp32 -static -mcmodel=medany \
70
+ -fvisibility=hidden -nostdlib -nostartfiles -Tsifive_e/hello.ld -Isifive_e \
71
+ hello.s -o hello
72
+ ```
73
+
74
+ Run it with:
75
+
76
+ ```
77
+ $ qemu-system-riscv32 -nographic -machine sifive_e -bios none -kernel hello
78
+ Hello.
79
+ QEMU: Terminated
80
+ ```
81
+
82
+ Note: the program enters an infinite loop after producing the ` Hello. ` text.
83
+ Type ` ctrl-a x ` to stop QEMU.
84
+
85
+
58
86
## Assembly
59
87
60
88
To disassemble the program:
0 commit comments