@@ -5,33 +5,98 @@ parent: Platforms
55nav_order : 2
66---
77
8- # Files
8+ # Prerequisites
9+
10+ #### System
11+
12+ - An x86 Linux workstation
13+ - The ` curl ` and ` telnet ` command line utilities
14+
15+ #### Files
16+
17+ We will download these below.
918
1019 - [ or1ksim.cfg] ( or1ksim.cfg ) - config needed for or1ksim
11- - [ or1ksim-2025-04-27.tar.gz] ( https://github.com/openrisc/or1ksim/releases/download/2025-04-27/or1ksim-2025-04-27.tar.gz )
20+ - [ or1ksim-2025-04-27.tar.gz] ( https://github.com/openrisc/or1ksim/releases/download/2025-04-27/or1ksim-2025-04-27.tar.gz ) - The OpenRISC simulator source code
1221 - [ timer.c] ( ./sw/timer/timer.c ) - timer program
22+
1323# or1ksim Tutorial
1424
15- If you downloaded the tutorials as a release archive, you can directly
16- start. If you have cloned the git repository, you instead need to
17- follow the instructions for building the hardware and software as
18- described below. Please also follow the
19- [ common tutorial setup] ( ../README.md ) .
25+ The or1ksim program is the OpenRISC [ instruction set simulator] ( https://en.wikipedia.org/wiki/Instruction_set_simulator ) which
26+ provides accurate tracing. A simulator is a fast way to debug and ensure
27+ your software works before deploying it to real hardware.
28+
29+ In this tutorial we will cover getting and building or1ksim, and building simple
30+ programs to run on or1ksim.
31+
32+ We break this tutorial down into parts:
33+
34+ - Downloading the pieces
35+ - Compiling a program
36+ - Running a program
37+ - Interacting with the simulator
38+
39+ ## Downloading the Pieces
40+
41+ To get started we will create a temporary directly and setup our environment, if
42+ you plan to do a lot of OpenRISC development consider adding these tools to your
43+ ` PATH ` permanently.
44+
45+ To get everything you need run:
46+
47+ ``` bash
48+ mkdir /tmp/or1ksim/
49+ cd /tmp/or1ksim/
2050
21- To run the demo you need:
51+ # Download or1ksim, toolchain and a test project
52+ curl -L -O https://github.com/openrisc/or1ksim/releases/download/2025-04-27/or1ksim-2025-04-27.tar.gz
53+ curl -L -O https://github.com/stffrdhrn/or1k-toolchain-build/releases/download/or1k-15.1.0-20250621/or1k-elf-15.1.0-20250621.tar.xz
2254
23- * ` or1k-sim ` in your ` PATH ` , check with
55+ # Download example programs
56+ curl -L -O https://openrisc.io/tutorials/sw/hello/hello.c
57+ curl -L -O https://openrisc.io/tutorials/sw/timer/timer.c
2458
25- or1k-sim --version
59+ # Download an example config for or1ksim
60+ curl -L -O https://github.com/stffrdhrn/or1k-utils/raw/refs/heads/master/or1ksim.cfg
61+
62+ # Extract everything
63+ tar -xf or1ksim-2025-04-27.tar.gz
64+ tar -xf or1k-elf-15.1.0-20250621.tar.xz
65+
66+ export PATH=$PATH :$PWD /or1k/bin:$PWD /or1k-elf/bin
67+ ```
68+
69+ ## Compiling a program
70+
71+ To compile programs for or1ksim we use the newlib baremetal toolchain. Binaries
72+ produced by this can run directly on systems with no Operating System. We use
73+ the ` -mboard= ` option to provide newlib with the proper options needed to target
74+ or1ksim. This includes RAM size, address loctions for UART and UART baud rates.
75+
76+ ``` bash
77+ CFLAGS=" -mboard=or1ksim-uart"
78+ or1k-elf-gcc -g -Og $CFLAGS -o hello.elf hello.c
79+ or1k-elf-gcc -g -Og $CFLAGS -o timer.elf timer.c
80+ ```
2681
2782## Run hello world
2883
29- or1k-sim -f or1ksim.cfg hello.elf
84+ To run the demo you need ` or1k-elf-sim ` in your ` PATH ` , check with:
85+
86+ ``` bash
87+ or1k-elf-sim --version
88+ ```
89+
90+ We can then run our program with the following:
91+
92+ ``` bash
93+ or1k-elf-sim -f or1ksim.cfg hello.elf
94+ ```
3095
3196You can find that the last output is ` Hello World! ` . or1ksim can be
3297much more verbose and give you a full execution trace:
3398
34- or1k-sim -f or1ksim.cfg hello.elf -t
99+ or1k-elf- sim -f or1ksim.cfg hello.elf -t
35100
36101This is of course a lot slower and the simulation exits after a
37102while. You can finish the simulation before with ` CTRL+C ` , which will
@@ -40,25 +105,16 @@ command line with `quit`.
40105
41106## Run the timer example
42107
43- or1k-sim -f or1ksim.cfg timer.elf
108+ or1k-elf- sim -f or1ksim.cfg timer.elf
44109
45110In the terminal you can see an UART output every * simulated*
46111second. You can quit this as described before.
47112
48- ## Boot Linux
49-
50- You can also boot Linux:
51-
52- or1k-sim -f or1ksim.cfg ../vmlinux
53-
54- ## (Re-)build the baremetal software
55-
56- Some example software is available, that you can (re-)build for the
57- DE0 nano board by running
113+ ## Next steps
58114
59- make build-sw
115+ Also checkout our tutorial on how to run [ Linux on or1ksim ] ( ../docs/linux-on-or1ksim.html ) .
60116
61- ## Links
117+ ## Further Reading
62118
63119 - [ openrisc/or1ksim] ( https://github.com/openrisc/or1ksim ) - The home page and git repo
64120 - [ Releases] ( https://github.com/openrisc/or1ksim/releases ) - Nightly build and point release
0 commit comments