@@ -32,8 +32,8 @@ programs to run on or1ksim.
3232We 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
6666export PATH=$PATH :$PWD /or1k/bin:$PWD /or1k-elf/bin
6767```
6868
69- ## Compiling a program
69+ ## Compiling Programs
7070
7171To compile programs for or1ksim we use the newlib baremetal toolchain. Binaries
7272produced 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
7979or1k-elf-gcc -g -Og $CFLAGS -o timer.elf timer.c
8080```
8181
82- ## Run hello world
82+ ## Running Programs
8383
8484To run the demo you need ` or1k-elf-sim ` in your ` PATH ` , check with:
8585
8686``` bash
8787or1k-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
9393or1k-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
9797much 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
103103take you to the simulators command line (` (sim) ` ). You can exit the
104104command 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
110113In 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