Skip to main content...
S1 · Computer Organization & the RISC-V ISA
25 min

Day 38: Install the riscv-gnu-toolchain; compile your first binary

Installing the toolchain turns C into RISC-V binaries you can inspect, run in your ISS, and later boot on ChipX.

The RISC-V toolchain

The riscv-gnu-toolchain gives you a cross-compiler (riscv32-unknown-elf-gcc), assembler, linker, and the binutils (objdump, readelf) that turn C and assembly into RV32I ELF binaries — and let you *see* the machine code. This is the toolchain your ISS will consume today and ChipX will boot in Stage 4, so setting it up now pays off for the rest of the roadmap.

Compile and disassemble a bare-metal RV32I program
# compile to RV32I (no OS, no standard startup)
riscv32-unknown-elf-gcc -march=rv32i -mabi=ilp32 \
    -nostdlib -O2 -c hello.c -o hello.o

# see the machine code — your hand-assembly, verified
riscv32-unknown-elf-objdump -d hello.o

# a tiny program to try:
# int main(void){ int s=0; for(int i=0;i<10;i++) s+=i; return s; }

Bare-metal from the start

Compile with -nostdlib/-march=rv32i: ChipX has no operating system and only the base integer instructions. Getting comfortable with bare-metal builds now (no printf, no libc assumptions) is exactly the mindset Stage 4 firmware needs — and it keeps your test binaries small enough to trace instruction-by-instruction.

Key terms

Cross-compiler
A compiler that runs on your machine but emits code for a different target (here RV32I).
ELF
The executable/object file format holding machine code, symbols, and section layout.
objdump
A binutils tool that disassembles a binary back to human-readable assembly.
Bare-metal
Code that runs with no operating system or standard library beneath it.

Ship for Day 38

Why compile ChipX test programs with -march=rv32i -nostdlib?

We use cookies

We use cookies to enhance your browsing experience, serve personalized content, and analyze our traffic. By clicking "Accept All", you consent to our use of cookies. Learn more

    Day 38: Install the riscv-gnu-toolchain; compile your first binary | RBTechIconX