Move all app common files under apps/common

This commit is contained in:
Toby Jaffey 2025-12-12 15:45:17 +00:00
parent 60f362b819
commit 5bd6a32013
31 changed files with 49 additions and 49 deletions

24
apps/common/crt0.S Normal file
View file

@ -0,0 +1,24 @@
#include "uvm32_sys.h"
.equ uvm32_syscall_halt, 0x1000000
.equ uvm32_syscall_yield, 0x1000001
.equ uvm32_syscall_stackprotect, 0x1000002
.section .initial_jump , "ax", %progbits
.global _start
.align 4
_start:
la a0, _estack
li a7, uvm32_syscall_stackprotect
ecall
# sp is already setup by vm
sw ra,12(sp)
jal ra, main
li a7, uvm32_syscall_halt
ecall
.section .data

86
apps/common/linker.ld Normal file
View file

@ -0,0 +1,86 @@
/*__heap_size = 0x100; */
/*__stack_size = 0x100; */
ENTRY(_start)
SECTIONS
{
. = 0x80000000;
/*
.header : ALIGN( 16 )
{
LONG( 0 )
LONG( 0 )
}
*/
.text : ALIGN(16) {
__TEXT_BEGIN__ = .;
*(.initial_jump)
*(.entry.text)
*(.init.literal)
*(.init)
*(.text)
*(.literal .text .literal.* .text.* .stub)
*(.out_jump.literal.*)
*(.out_jump.*)
__TEXT_END__ = .;
}
/* If we're on a newer compiler */
/DISCARD/ :
{
*(.interp)
*(.dynsym)
*(.dynstr)
*(.header)
} : phdr
.data : ALIGN(16) {
__DATA_BEGIN__ = .;
*(.rodata)
*(.rodata.*)
*(.gnu.linkonce.r.*)
*(.rodata1)
*(.dynsbss)
*(.gnu.linkonce.sb.*)
*(.scommon)
*(.gnu.linkonce.sb2.*)
*(.sbss)
*(.sbss.*)
*(.sbss2)
*(.sbss2.*)
*(.dynbss)
*(.data)
*(.data.*)
*(.got)
*(.got.*)
__DATA_END__ = .;
}
.bss : ALIGN( 16 ) {
__BSS_BEGIN__ = .;
*(.bss) /* Tricky: BSS needs to be allocated but not sent. GCC Will not populate these for calculating data size */
*(.bss.*)
__BSS_END__ = .;
}
/*
.heap : ALIGN( 16 ) {
_sheap = .;
. = . + __heap_size;
_eheap = .;
}
*/
/*
.stack : ALIGN( 16 ) {
_estack = .;
. = . + __stack_size;
_sstack = .;
}
*/
.stack : ALIGN( 16 ) {
_estack = .;
}
}

View file

@ -0,0 +1,36 @@
PREFIX:=riscv64-elf-
OPT ?= -Os
CFLAGS+=-I${TOPDIR}/common
CFLAGS+=${OPT} -fno-stack-protector -fno-builtin-memcpy -fno-builtin
CFLAGS+=-static-libgcc -fdata-sections -ffunction-sections
CFLAGS+=-g -march=rv32im -mabi=ilp32 -static
LDFLAGS:= -T ${TOPDIR}/apps/common/linker.ld -nostdlib -Wl,--gc-sections
LIBS:= -lgcc # needed for softfp
# check if the compiler is installed
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
PREFIX=riscv64-elf-
ifeq (,$(shell which ${PREFIX}gcc))
$(error "Try brew install riscv64-elf-gcc riscv64-elf-binutils")
endif
else
PREFIX=riscv64-unknown-elf-
ifeq (,$(shell which ${PREFIX}gcc))
$(error "Try apt-get install gcc-riscv64-unknown-elf")
endif
endif
all_common:
${PREFIX}gcc -o ${PROJECT}.elf ${CFLAGS} ${LDFLAGS} ${SRCS} ${LIBS}
@$(PREFIX)objcopy ${PROJECT}.elf -O binary ${PROJECT}.bin
disasm_common: all
$(PREFIX)objdump -S -d -f ${PROJECT}.elf
test_common: all
${TOPDIR}/hosts/host/host ${HOST_EXTRA} ${PWD}/${PROJECT}.bin
clean_common:
rm -f ${PROJECT}.o ${PROJECT}.elf ${PROJECT}.bin