Skip to content

Commit 4911ab8

Browse files
committed
or1ksim: Update docs to align outline with tutorial
1 parent 4f1102a commit 4911ab8

2 files changed

Lines changed: 70 additions & 12 deletions

File tree

docs/linux-on-or1ksim.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ We break this tutorial down into parts:
3838
- Downloading the pieces
3939
- Compiling the kernel
4040
- Running the kernel
41-
- Interacting with the simulator
4241
- Adding custom userspace programs
4342

4443
## Downloading the Pieces
@@ -71,7 +70,7 @@ tar -xf or1k-none-linux-musl-15.1.0-20250621.tar.xz
7170
export PATH=$PATH:$PWD/or1k/bin:$PWD/or1k-none-linux-musl/bin
7271
```
7372

74-
## Building Linux
73+
## Compiling the Kernel
7574

7675
To build a Linux kernel we use the toolchain, kernel source code and rootfs just downloaded
7776
in the following make commands:
@@ -105,7 +104,7 @@ that is build directly into our kernel ELF binary. This is one of the most simp
105104
but it means that our data will be lost after reset. Also, it means that updating userspace utilties
106105
requires rebuilding the kernel.
107106

108-
## Booting the System
107+
## Running the Kernel
109108

110109
To start Linux on `or1ksim` we run `or1k-elf-sim` passing the kernel as an argument.
111110
This will:
@@ -136,7 +135,7 @@ To exit `or1ksim` press: `Ctrl+c`
136135

137136
To exit `telnet` press: `Ctrl+]`
138137

139-
## Adding User Space Programs
138+
## Adding Custom User Space Programs
140139

141140
To add your own programs to the rootfs you can use the [musl](https://musl.libc.org)
142141
toolchain to build executables as follows:

or1ksim/index.md

Lines changed: 67 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ programs to run on or1ksim.
3232
We break this tutorial down into parts:
3333

3434
- Downloading the pieces
35-
- Compiling a program
36-
- Running a program
35+
- Compiling programs
36+
- Running programs
3737
- Interacting with the simulator
3838

3939
## Downloading the Pieces
@@ -66,7 +66,7 @@ tar -xf or1k-elf-15.1.0-20250621.tar.xz
6666
export PATH=$PATH:$PWD/or1k/bin:$PWD/or1k-elf/bin
6767
```
6868

69-
## Compiling a program
69+
## Compiling Programs
7070

7171
To compile programs for or1ksim we use the newlib baremetal toolchain. Binaries
7272
produced by this can run directly on systems with no Operating System. We use
@@ -79,21 +79,21 @@ or1k-elf-gcc -g -Og $CFLAGS -o hello.elf hello.c
7979
or1k-elf-gcc -g -Og $CFLAGS -o timer.elf timer.c
8080
```
8181

82-
## Run hello world
82+
## Running Programs
8383

8484
To run the demo you need `or1k-elf-sim` in your `PATH`, check with:
8585

8686
```bash
8787
or1k-elf-sim --version
8888
```
8989

90-
We can then run our program with the following:
90+
We can then run our first *Hello Wolrd* example program with the following:
9191

9292
```bash
9393
or1k-elf-sim -f or1ksim.cfg hello.elf
9494
```
9595

96-
You can find that the last output is `Hello World!`. or1ksim can be
96+
If everything worked we will see the last output is `Hello World!`. or1ksim can be
9797
much more verbose and give you a full execution trace:
9898

9999
or1k-elf-sim -f or1ksim.cfg hello.elf -t
@@ -103,12 +103,71 @@ while. You can finish the simulation before with `CTRL+C`, which will
103103
take you to the simulators command line (`(sim) `). You can exit the
104104
command line with `quit`.
105105

106-
## Run the timer example
106+
### Run the timer example
107+
108+
A more advanced example is the timer example which uses `or1k_timer_*` APIs from the
109+
newlib or1k [timer module](https://openrisc.io/newlib/docs/html/group__or1k__timer.html) to setup a 1 second timer.
107110

108111
or1k-elf-sim -f or1ksim.cfg timer.elf
109112

110113
In the terminal you can see an UART output every *simulated*
111-
second. You can quit this as described before.
114+
second. You can quit the simulation as described before.
115+
116+
## Interacting with the simulator
117+
118+
When we press `CTRL+C` when running the timer example the simulator will
119+
continue to run. We can interact with the simulator console at this time.
120+
121+
Some example commands to check are:
122+
123+
- `help` - show help about all commands
124+
- `r` - show all registers
125+
- `info` - show all system info
126+
- `stall` - resumes the program
127+
128+
### Example output
129+
130+
```
131+
(sim) info
132+
VR : 0x12000001 UPR : 0x00000619
133+
SR : 0x00008203
134+
MACLO: 0x00000000 MACHI: 0x00000000
135+
EPCR0: 0x00006688 EPCR1: 0x00000000
136+
EEAR0: 0x00000000 EEAR1: 0x00000000
137+
ESR0 : 0x00008203 ESR1 : 0x00000000
138+
TTMR : 0x600f4240 TTCR : 0x00000081
139+
PICMR: 0x00000003 PICSR: 0x00000000
140+
PPC: 0x00002294 NPC : 0x00000000
141+
142+
..
143+
SPR_ITLBMR way 0 set 59 = | | ITLBMR_VPN = 00000000
144+
SPR_ITLBTR way 0 set 59 = ITLBTR_PPN = 00000000
145+
SPR_ITLBMR way 0 set 60 = | | ITLBMR_VPN = 00000000
146+
SPR_ITLBTR way 0 set 60 = ITLBTR_PPN = 00000000
147+
SPR_ITLBMR way 0 set 61 = | | ITLBMR_VPN = 00000000
148+
SPR_ITLBTR way 0 set 61 = ITLBTR_PPN = 00000000
149+
SPR_ITLBMR way 0 set 62 = | | ITLBMR_VPN = 00000000
150+
SPR_ITLBTR way 0 set 62 = ITLBTR_PPN = 00000000
151+
SPR_ITLBMR way 0 set 63 = | | ITLBMR_VPN = 00000000
152+
SPR_ITLBTR way 0 set 63 = ITLBTR_PPN = 00000000
153+
154+
(sim) r
155+
00002294: 13fffffd l.bf -3 (executed) [cycle 166500035, #149819510]
156+
00002298: 15000000 l.nop 0 (next insn) (delay insn)
157+
GPR00: 00000000 GPR01: 007fdff8 GPR02: 007fe000 GPR03: 00000001
158+
GPR04: 90000000 GPR05: 00009588 GPR06: 00000000 GPR07: 00000000
159+
GPR08: 00008b5c GPR09: 00002290 GPR10: 00000000 GPR11: 00000042
160+
GPR12: 00000000 GPR13: 000069ec GPR14: 00000000 GPR15: ffffffff
161+
GPR16: 00000042 GPR17: 00010000 GPR18: 00000000 GPR19: 00008001
162+
GPR20: 00000000 GPR21: 00000011 GPR22: 00000000 GPR23: fffffffd
163+
GPR24: 00000000 GPR25: 000069dc GPR26: 00000000 GPR27: ffffefff
164+
GPR28: 00000000 GPR29: 00000000 GPR30: 00000000 GPR31: 00009394 flag: 1
165+
(sim) stall
166+
A second elapsed
167+
A second elapsed
168+
A second elapsed
169+
A second elapsed
170+
```
112171

113172
## Next steps
114173

0 commit comments

Comments
 (0)