Files
FPGA-Core/Tutorial/phase-08-gcc-toolchain/phase-08-02-first-gcc-program.md
T
imple b008b37d49 Add phase-by-phase tutorial notes
Add a Tutorial tree that mirrors the roadmap from Phase 0 through Linux bring-up.
Each phase and subphase gets a short learning note with consistent sections for
context, goals, new concepts, mental model, learning tasks, pitfalls, tooling,
testing, and references.

The tutorial material is intentionally explanatory rather than implementation
code. It gives a systems-oriented learner enough FPGA, SystemVerilog, RISC-V,
firmware, and Linux bring-up context to approach each roadmap phase without
turning the notes into copy-paste RTL.
2026-04-28 12:11:23 +02:00

1.5 KiB

Phase 8.2 - First GCC Program

Context

The first compiled program proves your hardware can execute compiler-generated code, not just carefully hand-authored assembly.

Goals

  • Compile a tiny C firmware for rv32im.
  • Convert the ELF into a memory image.
  • Print through UART MMIO from C.

New Concepts

  • -march: compiler ISA target string.
  • -mabi: ABI selection, here ilp32 for 32-bit integer/long/pointer.
  • objcopy: tool that converts ELF into raw binary or other formats.
  • Disassembly: readable assembly representation of generated machine code.

How To Think About It

Treat the compiler as an external producer of instructions. Your job is to verify that every emitted instruction is implemented or fails loudly.

Learning Tasks

  • Compare C source to generated assembly.
  • Identify every load/store used for UART access.
  • Confirm no CSR or fence.i instructions appear before Phase 9.

Pitfalls

  • Using the wrong -march and accidentally generating unsupported instructions.
  • Forgetting volatile on MMIO accesses in firmware.
  • Assuming the compiler will preserve simple-looking loops exactly.

Tooling And Testing

  • Always inspect early firmware with objdump.
  • Build at low optimization first, then compare optimized output later.
  • Keep firmware small enough to single-step mentally.

References