Skip to content

Instantly share code, notes, and snippets.

@olofk
Last active September 10, 2023 23:09
Show Gist options
  • Save olofk/d0f32e801f4d9d71139f5171aa447af4 to your computer and use it in GitHub Desktop.
Save olofk/d0f32e801f4d9d71139f5171aa447af4 to your computer and use it in GitHub Desktop.
Bare-metal SERV C example
#
# Makefile: Makefile for building subservient firmware
#
# SPDX-FileCopyrightText: 2021 Olof Kindgren <[email protected]>
# SPDX-License-Identifier: Apache-2.0
#
TOOLCHAIN_PREFIX ?= riscv64-unknown-elf-
%.elf: start.S %.c
$(TOOLCHAIN_PREFIX)gcc -Os -march=rv32i -mabi=ilp32 -nostdlib -o $@ \
-Wl,-Bstatic,-Tlink.ld $^
%.elf: %.S
$(TOOLCHAIN_PREFIX)gcc -nostartfiles -march=rv32i -mabi=ilp32 -Tlink.ld -o$@ $<
%.hex: %.elf
$(TOOLCHAIN_PREFIX)objcopy -O verilog $< $@
%.bin: %.elf
$(TOOLCHAIN_PREFIX)objcopy -O binary $< $@
clean:
rm -f *.elf *.bin *.hex
.section .text
_start:
li sp, 0x300
call main
void main(void) {
volatile int i;
volatile int sum;
for (i=0;i<100;i++)
sum += i;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment