Last active
September 10, 2023 23:09
-
-
Save olofk/d0f32e801f4d9d71139f5171aa447af4 to your computer and use it in GitHub Desktop.
Bare-metal SERV C example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* link.ld : Linker script for subservient SoC | |
* | |
* SPDX-FileCopyrightText: 2021 Olof Kindgren <[email protected]> | |
* SPDX-License-Identifier: Apache-2.0 | |
*/ | |
OUTPUT_ARCH( "riscv" ) | |
/*ENTRY(_start)*/ | |
SECTIONS | |
{ | |
. = 0; | |
.text : { *(.text) } | |
.data : { *(.data) } | |
.bss : { *(.bss) } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.section .text | |
_start: | |
li sp, 0x300 | |
call main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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