From b910d9b486f2809380e6e78995c7d5d789f54441 Mon Sep 17 00:00:00 2001 From: Henrik Karlsson Date: Thu, 26 Oct 2023 12:58:55 +0200 Subject: [PATCH] Streamline project build process --- Makefile | 33 ++++++---- common/Makefile | 49 +++++++++++--- common/build.mk | 48 -------------- common/plat/qemu_virt.mk | 14 ++-- common/plat/sifive_unleashed.mk | 14 ++-- kernel/Makefile | 42 ++---------- kernel/inc/kassert.h | 2 +- kernel/s3k_conf.h | 24 ------- projects/demonstrator/Makefile | 21 ++---- projects/demonstrator/app0/Makefile | 5 -- projects/demonstrator/app1/Makefile | 5 -- projects/demonstrator/boot/Makefile | 12 ---- projects/demonstrator/boot/main.c | 8 +-- projects/demonstrator/build.mk | 43 ++++++++++++ projects/demonstrator/crypto/Makefile | 6 -- projects/demonstrator/default.mk | 64 ------------------ projects/demonstrator/monitor/Makefile | 6 -- projects/demonstrator/uartppp/Makefile | 6 -- projects/demonstrator/uartppp/main.c | 19 +++--- projects/hello/Makefile | 20 ++---- projects/hello/app0.ld | 3 + projects/hello/app0/Makefile | 5 -- projects/hello/app1.ld | 3 + projects/hello/app1/Makefile | 5 -- projects/hello/app1/linker.ld | 33 ---------- projects/hello/build.mk | 44 +++++++++++++ .../{wcet/app0/linker.ld => hello/default.ld} | 4 -- projects/hello/default.mk | 65 ------------------- projects/hello/scripts/qemu.sh | 11 ---- projects/ping-pong/Makefile | 19 ++---- projects/ping-pong/app0.ld | 3 + projects/ping-pong/app0/Makefile | 5 -- projects/ping-pong/app0/main.c | 3 +- projects/ping-pong/app1.ld | 3 + projects/ping-pong/app1/Makefile | 5 -- projects/ping-pong/app1/linker.ld | 33 ---------- projects/ping-pong/app1/main.c | 2 +- projects/ping-pong/build.mk | 43 ++++++++++++ .../ping-pong/{app0/linker.ld => default.ld} | 4 -- projects/ping-pong/default.mk | 63 ------------------ projects/trapped/Makefile | 19 ++---- projects/trapped/app0.ld | 3 + projects/trapped/app0/Makefile | 5 -- projects/trapped/app0/linker.ld | 33 ---------- projects/trapped/app0/main.c | 2 +- projects/trapped/build.mk | 43 ++++++++++++ .../app0/linker.ld => trapped/default.ld} | 4 -- projects/trapped/default.mk | 63 ------------------ projects/trapped/scripts/gdb.sh | 30 --------- projects/trapped/scripts/qemu.sh | 9 --- projects/wcet/Makefile | 17 ----- projects/wcet/app0/Makefile | 36 ---------- projects/wcet/app0/src/main.c | 35 ---------- projects/wcet/run.sh | 16 ----- {projects/hello/scripts => scripts}/gdb.sh | 13 ++-- scripts/qemu.sh | 18 +++++ tools.mk | 12 ++-- 57 files changed, 334 insertions(+), 821 deletions(-) delete mode 100644 common/build.mk delete mode 100644 kernel/s3k_conf.h delete mode 100644 projects/demonstrator/app0/Makefile delete mode 100644 projects/demonstrator/app1/Makefile delete mode 100644 projects/demonstrator/boot/Makefile create mode 100644 projects/demonstrator/build.mk delete mode 100644 projects/demonstrator/crypto/Makefile delete mode 100644 projects/demonstrator/default.mk delete mode 100644 projects/demonstrator/monitor/Makefile delete mode 100644 projects/demonstrator/uartppp/Makefile create mode 100644 projects/hello/app0.ld delete mode 100644 projects/hello/app0/Makefile create mode 100644 projects/hello/app1.ld delete mode 100644 projects/hello/app1/Makefile delete mode 100644 projects/hello/app1/linker.ld create mode 100644 projects/hello/build.mk rename projects/{wcet/app0/linker.ld => hello/default.ld} (88%) delete mode 100644 projects/hello/default.mk delete mode 100755 projects/hello/scripts/qemu.sh create mode 100644 projects/ping-pong/app0.ld delete mode 100644 projects/ping-pong/app0/Makefile create mode 100644 projects/ping-pong/app1.ld delete mode 100644 projects/ping-pong/app1/Makefile delete mode 100644 projects/ping-pong/app1/linker.ld create mode 100644 projects/ping-pong/build.mk rename projects/ping-pong/{app0/linker.ld => default.ld} (87%) delete mode 100644 projects/ping-pong/default.mk create mode 100644 projects/trapped/app0.ld delete mode 100644 projects/trapped/app0/Makefile delete mode 100644 projects/trapped/app0/linker.ld create mode 100644 projects/trapped/build.mk rename projects/{hello/app0/linker.ld => trapped/default.ld} (87%) delete mode 100644 projects/trapped/default.mk delete mode 100755 projects/trapped/scripts/gdb.sh delete mode 100755 projects/trapped/scripts/qemu.sh delete mode 100644 projects/wcet/Makefile delete mode 100644 projects/wcet/app0/Makefile delete mode 100644 projects/wcet/app0/src/main.c delete mode 100755 projects/wcet/run.sh rename {projects/hello/scripts => scripts}/gdb.sh (64%) create mode 100755 scripts/qemu.sh diff --git a/Makefile b/Makefile index 4514c868..6f337f3b 100644 --- a/Makefile +++ b/Makefile @@ -1,18 +1,27 @@ -SUBDIRS=common kernel projects/hello projects/trapped projects/ping-pong projects/demonstrator +export ROOT=${abspath .} -all: - for i in $(SUBDIRS); do \ - make -C $$i all; \ - done -$(SUBDIRS): - make -C $@ all +PROJECT?=hello +PLATFORM?=qemu_virt +BUILD?=${ROOT}/build/${PROJECT} +S3K_CONF_H?=${ROOT}/projects/${PROJECT}/s3k_conf.h + +include tools.mk +include common/plat/${PLATFORM}.mk + +all: common kernel projects/${PROJECT} + +common kernel projects/${PROJECT}: + make -C $@ all \ + PLATFORM=${PLATFORM} \ + BUILD=${BUILD} \ + S3K_CONF_H=${S3K_CONF_H} + +qemu gdb: common kernel projects/${PROJECT} + bash scripts/$@.sh ${BUILD} clean: - for i in $(SUBDIRS); do \ - make -C $$i clean; \ - done - rm -rf docs + rm -r ${BUILD} docs: doxygen @@ -20,4 +29,4 @@ docs: format: clang-format -i $(shell find -name '*.[hc]' -not -path '*/.*') -.PHONY: all docs clean $(SUBDIRS) +.PHONY: all docs clean qemu gdb kernel common projects/${PROJECT} diff --git a/common/Makefile b/common/Makefile index 6042c6b3..718a9c93 100644 --- a/common/Makefile +++ b/common/Makefile @@ -1,14 +1,47 @@ -PLATFORM?=${patsubst plat/%.mk, %, ${wildcard plat/*.mk}} +include plat/${PLATFORM}.mk -all: ${PLATFORM} +CFLAGS=-march=${ARCH} -mabi=${ABI} -mcmodel=${CMODEL} +CFLAGS+=-DPLATFORM_${PLATFORM} +CFLAGS+=-Os +CFLAGS+=-flto -ffat-lto-objects +CFLAGS+=-nostdlib -Iinc -${PLATFORM}: - ${MAKE} -f build.mk PLATFORM=$@ all +SRCS2OBJS=${patsubst src/%.S, ${BUILD}/common/%.o, ${filter %.S, ${1}}} \ + ${patsubst src/%.c, ${BUILD}/common/%.o, ${filter %.c, ${1}}} +ALTC_SRCS=${wildcard src/altc/*.[cS]} +S3K_SRCS=${wildcard src/s3k/*.[cS]} +START_SRCS=${wildcard src/start/*.S} + +PLAT_OBJS=${call SRCS2OBJS, ${PLAT_SRCS}} +ALTC_OBJS=${call SRCS2OBJS, ${ALTC_SRCS}} +S3K_OBJS=${call SRCS2OBJS, ${S3K_SRCS}} +START_OBJS=${call SRCS2OBJS, ${START_SRCS}} + +all: ${BUILD}/common/libplat.a ${BUILD}/common/libaltc.a ${BUILD}/common/libs3k.a ${START_OBJS} + +${BUILD}/common/libplat.a: ${PLAT_OBJS} + echo ${PLAT_OBJS} + @mkdir -p ${@D} + ${AR} cr $@ $^ + +${BUILD}/common/libaltc.a: ${ALTC_OBJS} + @mkdir -p ${@D} + ${AR} cr $@ $^ + +${BUILD}/common/libs3k.a: ${S3K_OBJS} + @mkdir -p ${@D} + ${AR} cr $@ $^ + +${BUILD}/common/%.o: src/%.c + @mkdir -p ${@D} + ${CC} -o $@ $< -c ${CFLAGS} + +${BUILD}/common/%.o: src/%.S + @mkdir -p ${@D} + ${CC} -o $@ $< -c ${CFLAGS} clean: - for i in ${PLATFORM}; do \ - ${MAKE} -f build.mk PLATFORM=$$i clean; \ - done + rm -rf ${BUILD} -.PHONY: all +.PHONY: all clean diff --git a/common/build.mk b/common/build.mk deleted file mode 100644 index 4f088b50..00000000 --- a/common/build.mk +++ /dev/null @@ -1,48 +0,0 @@ - -include ../tools.mk -include plat/${PLATFORM}.mk - -BUILD=plat/${PLATFORM} - -CFLAGS=-march=${ARCH} -mabi=${ABI} -mcmodel=${CMODEL} -CFLAGS+=-DPLATFORM_${PLATFORM} -CFLAGS+=-Os -CFLAGS+=-flto -ffat-lto-objects -CFLAGS+=-nostdlib -Iinc - -SRCS2OBJS=${patsubst src/%.S, ${BUILD}/%.o, ${filter %.S, ${1}}} \ - ${patsubst src/%.c, ${BUILD}/%.o, ${filter %.c, ${1}}} - -ALTC_SRCS=${wildcard src/altc/*.[cS]} -S3K_SRCS=${wildcard src/s3k/*.[cS]} -START_SRCS=${wildcard src/start/*.S} - -PLAT_OBJS=${call SRCS2OBJS, ${PLAT_SRCS}} -ALTC_OBJS=${call SRCS2OBJS, ${ALTC_SRCS}} -S3K_OBJS=${call SRCS2OBJS, ${S3K_SRCS}} -START_OBJS=${call SRCS2OBJS, ${START_SRCS}} - -all: ${BUILD}/libplat.a ${BUILD}/libaltc.a ${BUILD}/libs3k.a ${START_OBJS} - -${BUILD}/libplat.a: ${PLAT_OBJS} - @mkdir -p ${@D} - ${AR} cr -flto $@ $^ - -${BUILD}/libaltc.a: ${ALTC_OBJS} - @mkdir -p ${@D} - ${AR} cr $@ $^ - -${BUILD}/libs3k.a: ${S3K_OBJS} - @mkdir -p ${@D} - ${AR} cr $@ $^ - -${BUILD}/%.o: src/%.c - @mkdir -p ${@D} - ${CC} -o $@ $< -c ${CFLAGS} -${BUILD}/%.o: src/%.S - @mkdir -p ${@D} - ${CC} -o $@ $< -c ${CFLAGS} -clean: - rm -rf ${BUILD} - -.PHONY: all clean diff --git a/common/plat/qemu_virt.mk b/common/plat/qemu_virt.mk index fb82a32f..7af542bc 100644 --- a/common/plat/qemu_virt.mk +++ b/common/plat/qemu_virt.mk @@ -1,7 +1,9 @@ -ARCH=rv64imac_zicsr -ABI=lp64 -CMODEL=medany -COMMON_INC=${ROOT}/common/inc -COMMON_LIB=${ROOT}/common/plat/qemu_virt -STARTFILES=${ROOT}/common/plat/qemu_virt/start +export ARCH=rv64imac_zicsr +export ABI=lp64 +export CMODEL=medany +export QEMU_MACHINE=virt +export QEMU_SMP=4 +export COMMON_INC=${ROOT}/common/inc +export COMMON_LIB=${BUILD}/common +export STARTFILES=${BUILD}/common/start PLAT_SRCS=src/drivers/uart/ns16550a.c src/drivers/time.c diff --git a/common/plat/sifive_unleashed.mk b/common/plat/sifive_unleashed.mk index 937da972..d2f314f4 100644 --- a/common/plat/sifive_unleashed.mk +++ b/common/plat/sifive_unleashed.mk @@ -1,7 +1,9 @@ -ARCH=rv64imac_zicsr -ABI=lp64 -CMODEL=medany -COMMON_INC=${ROOT}/common/inc -COMMON_LIB=${ROOT}/common/plat/sifive_unleashed -STARTFILES=${ROOT}/common/plat/sifive_unleashed/start +export ARCH=rv64imac_zicsr +export ABI=lp64 +export CMODEL=medany +export QEMU_MACHINE=sifive_u +export QEMU_SMP=5 +export COMMON_INC=${ROOT}/common/inc +export COMMON_LIB=${BUILD}/common +export STARTFILES=${BUILD}/common/start PLAT_SRCS=src/drivers/uart/sifive.c src/drivers/time.c diff --git a/kernel/Makefile b/kernel/Makefile index 7229a1c0..0456df9b 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -2,28 +2,11 @@ .POSIX: # Kernel basename -PROGRAM?=s3k - -# Kernel config -S3K_CONF_H?=s3k_conf.h - -# Platform config -PLATFORM?=qemu_virt - -# Repository root -ROOT=.. - -# Build target -BUILD?=build - -# Get toolchain -include ${ROOT}/tools.mk - -# Platform specific config -include ${ROOT}/common/plat/${PLATFORM}.mk +PROGRAM?=kernel # CC flags CFLAGS=-march=${ARCH} -mabi=${ABI} -mcmodel=${CMODEL} +CFLAGS+=-DPLATFORM_${PLATFORM} CFLAGS+=-std=c11 CFLAGS+=-Os -g3 CFLAGS+=-Wall -Wextra -Werror @@ -32,7 +15,6 @@ CFLAGS+=-Wshadow -fno-common CFLAGS+=-Wno-builtin-declaration-mismatch CFLAGS+=-fno-stack-protector CFLAGS+=-flto -CFLAGS+=-DPLATFORM_${PLATFORM} # Include files and directories CFLAGS+=-include ${S3K_CONF_H} @@ -53,7 +35,7 @@ LDFLAGS+=-laltc -lplat # Source files S_SRCS=${wildcard src/*.S} C_SRCS=${wildcard src/*.c} - + # Object files OBJS=${patsubst src/%.S, ${BUILD}/${PROGRAM}/%.o, ${S_SRCS}} \ ${patsubst src/%.c, ${BUILD}/${PROGRAM}/%.o, ${C_SRCS}} @@ -63,14 +45,10 @@ DEPS=${patsubst %.o, ${BUILD}/obj/%.d, ${OBJS}} # Targets ELF=${BUILD}/${PROGRAM}.elf -BIN=${ELF:.elf=.bin} -DA=${ELF:.elf=.da} -all: ${ELF} ${BIN} ${DA} +all: ${ELF} elf: ${ELF} -bin: ${BIN} -da: ${DA} ${BUILD}/${PROGRAM}/%.o: src/%.S @mkdir -p ${@D} @@ -84,18 +62,6 @@ ${ELF}: ${OBJS} @mkdir -p ${@D} ${CC} -o $@ ${OBJS} ${LDFLAGS} -${BIN}: ${ELF} - ${OBJCOPY} -O binary $< $@ - -${DA}: ${ELF} - ${OBJDUMP} -D $< > $@ - -format: - clang-format -i $(shell find -name '*.[hc]' -not -path '*/.*') - -clean: - rm -rf $(BUILD) - .PHONY: all elf bin da format clean -include ${DEPS} diff --git a/kernel/inc/kassert.h b/kernel/inc/kassert.h index 35a0298d..b21d5012 100644 --- a/kernel/inc/kassert.h +++ b/kernel/inc/kassert.h @@ -19,7 +19,7 @@ #define _X_(x) #x #define KASSERT_FAILURE(FILE, LINE) \ - altio_puts("Kernel assertion failed at " FILE ":" _X_(LINE) "."); + alt_puts("Kernel assertion failed at " FILE ":" _X_(LINE) "."); #define KASSERT(EXPR) \ do { \ diff --git a/kernel/s3k_conf.h b/kernel/s3k_conf.h deleted file mode 100644 index 525e0f9d..00000000 --- a/kernel/s3k_conf.h +++ /dev/null @@ -1,24 +0,0 @@ -// Default kernel configuration -#pragma once -#include "plat/config.h" - -// Number of user processes -#define S3K_PROC_CNT 8 - -// Number of capabilities per process. -#define S3K_CAP_CNT 32 - -// Number of IPC channels. -#define S3K_CHAN_CNT 16 - -// Number of slots per period -#define S3K_SLOT_CNT 64ull - -// Length of slots in ticks. -#define S3K_SLOT_LEN (S3K_RTC_HZ / S3K_SLOT_CNT / 100ull) - -// Scheduler time -#define S3K_SCHED_TIME (S3K_SLOT_LEN / 10) - -// If debugging, comment -#define NDEBUG diff --git a/projects/demonstrator/Makefile b/projects/demonstrator/Makefile index c1e4a8e0..78d9cf5a 100644 --- a/projects/demonstrator/Makefile +++ b/projects/demonstrator/Makefile @@ -1,21 +1,10 @@ -BUILD ?=build -S3K_CONF_H ?=s3k_conf.h +APPS=boot monitor uartppp crypto app0 app1 -SUBDIRS=../../kernel boot monitor uartppp crypto app0 app1 - -all: ${SUBDIRS} +all: ${APPS} boot: monitor uartppp crypto -${SUBDIRS}: - @${MAKE} -C $@ all \ - BUILD=${abspath ${BUILD}} \ - S3K_CONF_H=${abspath ${S3K_CONF_H}} - -qemu gdb: all - ./scripts/$@.sh - -clean: - rm -rf ${BUILD} +${APPS}: + @${MAKE} -f build.mk PROGRAM=$@ all -.PHONY: all clean ${SUBDIRS} qemu gdb +.PHONY: all ${APPS} diff --git a/projects/demonstrator/app0/Makefile b/projects/demonstrator/app0/Makefile deleted file mode 100644 index a5500e77..00000000 --- a/projects/demonstrator/app0/Makefile +++ /dev/null @@ -1,5 +0,0 @@ -PROGRAM=app0 -BUILD?=build -SRCS=start/start.S s3klib/mem.S s3klib/altio.c main.c - -include ../default.mk diff --git a/projects/demonstrator/app1/Makefile b/projects/demonstrator/app1/Makefile deleted file mode 100644 index 71cba699..00000000 --- a/projects/demonstrator/app1/Makefile +++ /dev/null @@ -1,5 +0,0 @@ -PROGRAM=app1 -BUILD?=build -SRCS=start/start.S s3klib/mem.S s3klib/altio.c main.c - -include ../default.mk diff --git a/projects/demonstrator/boot/Makefile b/projects/demonstrator/boot/Makefile deleted file mode 100644 index 3c7a1152..00000000 --- a/projects/demonstrator/boot/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -PROGRAM=boot -BUILD?=build -SRCS=start/start.S s3klib/mem.S s3k/s3k.c s3klib/altio.c -SRCS+=main.c payload.S - -include ../default.mk - - -# payload dependencies -${BUILD}/${PROGRAM}/payload.S.o: ../build/monitor.bin ../build/crypto.bin ../build/uart.bin - - diff --git a/projects/demonstrator/boot/main.c b/projects/demonstrator/boot/main.c index 38722e16..5f85c428 100644 --- a/projects/demonstrator/boot/main.c +++ b/projects/demonstrator/boot/main.c @@ -1,7 +1,6 @@ #include "../config.h" -#include "drivers/uart.h" #include "s3k/s3k.h" -#include "s3klib/altio.h" +#include "altc/altio.h" #include "string.h" #include @@ -197,11 +196,6 @@ void main(void) S3K_MEM_RW); s3k_pmp_load(5, 1); s3k_sync_mem(); - uart_init(); - while(1) { - char c = alt_getchar(); - alt_putchar(c); - } alt_puts("setting up memory ..."); /* Copy binary of monitor process, setup PMP and program counter. */ diff --git a/projects/demonstrator/build.mk b/projects/demonstrator/build.mk new file mode 100644 index 00000000..0d4724b6 --- /dev/null +++ b/projects/demonstrator/build.mk @@ -0,0 +1,43 @@ +BUILD?=build +PROGRAM?=a + +SRCS=${wildcard ${PROGRAM}/*.[cS]} +OBJS=${patsubst ${PROGRAM}/%, ${BUILD}/${PROGRAM}/%.o, ${SRCS}} ${STARTFILES}/start.o +DEPS=${patsubst ${PROGRAM}/%, ${BUILD}/${PROGRAM}/%.d, ${SRCS}} + +CFLAGS=-march=${ARCH} -mabi=${ABI} -mcmodel=${CMODEL} +CFLAGS+=-DPLATFORM_${PLATFORM} +CFLAGS+=-nostdlib +CFLAGS+=-DSTACK_SIZE=1024 +CFLAGS+=-Os -g3 +CFLAGS+=-Iinc -I${COMMON_INC} -include ${S3K_CONF_H} + +LDFLAGS=-march=${ARCH} -mabi=${ABI} -mcmodel=${CMODEL} +LDFLAGS+=-g3 +LDFLAGS+=-nostartfiles -nostdlib +LDFLAGS+=-T${PROGRAM}/linker.ld -Tdefault.ld +LDFLAGS+=-Wl,--no-warn-rwx-segments +LDFLAGS+=-L${COMMON_LIB} -ls3k -laltc -lplat + +ELF=${BUILD}/${PROGRAM}.elf + +all: ${ELF} + +${BUILD}/${PROGRAM}/%.S.o: ${PROGRAM}/%.S + @mkdir -p ${@D} + ${CC} -o $@ $< ${CFLAGS} ${INC} -MMD -c + +${BUILD}/${PROGRAM}/%.c.o: ${PROGRAM}/%.c + @mkdir -p ${@D} + ${CC} -o $@ $< ${CFLAGS} ${INC} -MMD -c + +${ELF}: ${OBJS} + @mkdir -p ${@D} + ${CC} -o $@ ${OBJS} ${LDFLAGS} -MMD ${INC} + +clean: + rm -f ${ELF} ${OBJS} ${DEPS} + +.PHONY: all elf bin da clean + +-include ${DEPS} diff --git a/projects/demonstrator/crypto/Makefile b/projects/demonstrator/crypto/Makefile deleted file mode 100644 index 732eda7a..00000000 --- a/projects/demonstrator/crypto/Makefile +++ /dev/null @@ -1,6 +0,0 @@ -PROGRAM=crypto -BUILD?=build -SRCS+=start/start.S s3klib/altio.c s3k/s3k.c s3klib/mem.S -SRCS+=main.c aes128.c - -include ../default.mk diff --git a/projects/demonstrator/default.mk b/projects/demonstrator/default.mk deleted file mode 100644 index ea6a3e4c..00000000 --- a/projects/demonstrator/default.mk +++ /dev/null @@ -1,64 +0,0 @@ -BUILD?=build -PROGRAM?=a - -ROOT=../../.. -USERLAND=${ROOT}/userland -PLATFORM=${ROOT}/plat64 - -include ${ROOT}/tools.mk -include ${PLATFORM}/config.mk - -vpath %.c . ${USERLAND}/src -vpath %.S . ${USERLAND}/src - -OBJS=${patsubst %, ${BUILD}/${PROGRAM}/%.o, ${SRCS}} -DEPS=${patsubst %, ${BUILD}/${PROGRAM}/%.d, ${SRCS}} - -CFLAGS+=-march=${ARCH} -mabi=${ABI} -mcmodel=${CMODEL} -CFLAGS+=-nostartfiles -nostdlib -CFLAGS+=-O2 -g -CFLAGS+=-DSTACK_SIZE=1024 -CFLAGS+=-Tlinker.ld -T../default.ld -CFLAGS+=-Wl,--no-warn-rwx-segments - -INC=-Iinc -I${PLATFORM}/inc -I${USERLAND}/inc -include ${S3K_CONF_H} - -ELF=${BUILD}/${PROGRAM}.elf -BIN=${ELF:.elf=.bin} -DA=${ELF:.elf=.da} - -all: ${ELF} ${BIN} ${DA} - -elf: ${ELF} -bin: ${BIN} -da: ${DA} - -${BUILD}/${PROGRAM}/%.S.o: %.S - @mkdir -p ${@D} - @echo "CC $@" - @${CC} ${CFLAGS} ${INC} -MMD -c -o $@ $< - -${BUILD}/${PROGRAM}/%.c.o: %.c - @mkdir -p ${@D} - @echo "CC $@" - @${CC} ${CFLAGS} ${INC} -MMD -c -o $@ $< - -${ELF}: ${OBJS} - @mkdir -p ${@D} - @echo "CC $@" - @${CC} ${CFLAGS} -MMD ${INC} -o $@ ${OBJS} - -${BIN}: ${ELF} - @echo "OBJCOPY $@" - @${OBJCOPY} -O binary $< $@ - -${DA}: ${ELF} - @echo "OBJDUMP $@" - @${OBJDUMP} -D $< > $@ - -clean: - rm -f ${ELF} ${BIN} ${DA} ${OBJS} ${DEPS} - -.PHONY: all elf bin da clean - --include ${DEPS} diff --git a/projects/demonstrator/monitor/Makefile b/projects/demonstrator/monitor/Makefile deleted file mode 100644 index 1fb32436..00000000 --- a/projects/demonstrator/monitor/Makefile +++ /dev/null @@ -1,6 +0,0 @@ -PROGRAM=monitor -BUILD?=build -SRCS=start/start.S s3klib/mem.S s3klib/altio.c s3k/s3k.c -SRCS+=main.c - -include ../default.mk diff --git a/projects/demonstrator/uartppp/Makefile b/projects/demonstrator/uartppp/Makefile deleted file mode 100644 index fb7d15ca..00000000 --- a/projects/demonstrator/uartppp/Makefile +++ /dev/null @@ -1,6 +0,0 @@ -PROGRAM=uart -BUILD?=build -SRCS=start/start.S s3klib/mem.S s3klib/altio.c s3k/s3k.c -SRCS+=main.c - -include ../default.mk diff --git a/projects/demonstrator/uartppp/main.c b/projects/demonstrator/uartppp/main.c index a4038776..87534011 100644 --- a/projects/demonstrator/uartppp/main.c +++ b/projects/demonstrator/uartppp/main.c @@ -1,7 +1,6 @@ #include "../config.h" -#include "drivers/uart.h" #include "s3k/s3k.h" -#include "s3klib/altio.h" +#include "altc/altio.h" #define PPP_ESC 0x7C #define PPP_BGN 0x7B @@ -17,7 +16,7 @@ void main(void) s3k_msg_t msg; s3k_reply_t reply; - while(1) { + while (1) { char c = alt_getchar(); alt_putchar(c); } @@ -44,30 +43,30 @@ void main(void) void ppp_send(char *buf, size_t len) { - uart_putc(PPP_BGN); + alt_putchar(PPP_BGN); for (int i = 0; i < len; ++i) { char c = buf[i]; switch (c) { case PPP_BGN: case PPP_END: case PPP_ESC: - uart_putc(PPP_ESC); + alt_putchar(PPP_ESC); c ^= 0x20; /* fallthrough */ default: - uart_putc(c); + alt_putchar(c); } } - uart_putc(PPP_END); + alt_putchar(PPP_END); } size_t ppp_recv(char *buf) { size_t i = 0; - while (uart_getc() != PPP_BGN) + while (alt_getchar() != PPP_BGN) ; while (1) { - char c = uart_getc(); + char c = alt_getchar(); switch (c) { case PPP_BGN: i = 0; @@ -75,7 +74,7 @@ size_t ppp_recv(char *buf) case PPP_END: return i; case PPP_ESC: - c = uart_getc() ^ 0x20; + c = alt_getchar() ^ 0x20; /* fallthrough */ default: buf[i++] = c; diff --git a/projects/hello/Makefile b/projects/hello/Makefile index e381aa1a..d8c967bd 100644 --- a/projects/hello/Makefile +++ b/projects/hello/Makefile @@ -1,18 +1,8 @@ -export BUILD=${abspath build} -export S3K_CONF_H=${abspath s3k_conf.h} -export PLATFORM=qemu_virt +APPS=app0 app1 -DIRS=../../kernel app0 app1 +all: ${APPS} -all: ${DIRS} +${APPS}: + ${MAKE} -f build.mk PROGRAM=$@ -${DIRS}: - @${MAKE} -C $@ - -gdb qemu: all - ./scripts/$@.sh - -clean: - rm -rf ${BUILD} - -.PHONY: all clean ${DIRS} gdb qemu +.PHONY: all ${APPS} diff --git a/projects/hello/app0.ld b/projects/hello/app0.ld new file mode 100644 index 00000000..a9a658b9 --- /dev/null +++ b/projects/hello/app0.ld @@ -0,0 +1,3 @@ +MEMORY { + RAM (rwx) : ORIGIN = 0x80010000, LENGTH = 0x10000 +} diff --git a/projects/hello/app0/Makefile b/projects/hello/app0/Makefile deleted file mode 100644 index 958738c6..00000000 --- a/projects/hello/app0/Makefile +++ /dev/null @@ -1,5 +0,0 @@ -PROGRAM=app0 - -SRCS=main.c - -include ../default.mk diff --git a/projects/hello/app1.ld b/projects/hello/app1.ld new file mode 100644 index 00000000..7ca7718e --- /dev/null +++ b/projects/hello/app1.ld @@ -0,0 +1,3 @@ +MEMORY { + RAM (rwx) : ORIGIN = 0x80020000, LENGTH = 0x10000 +} diff --git a/projects/hello/app1/Makefile b/projects/hello/app1/Makefile deleted file mode 100644 index 64f9e260..00000000 --- a/projects/hello/app1/Makefile +++ /dev/null @@ -1,5 +0,0 @@ -PROGRAM=app1 - -SRCS=main.c - -include ../default.mk diff --git a/projects/hello/app1/linker.ld b/projects/hello/app1/linker.ld deleted file mode 100644 index 9a158252..00000000 --- a/projects/hello/app1/linker.ld +++ /dev/null @@ -1,33 +0,0 @@ -/* See LICENSE file for copyright and license details. */ -OUTPUT_ARCH(riscv) -ENTRY(_start) - -__global_pointer$ = MIN(_sdata + 0x800, MAX(_data + 0x800, _end - 0x800)); - -MEMORY { - RAM (rwx) : ORIGIN = 0x80020000, LENGTH = 0x10000 -} - -SECTIONS { - .text : { - *( .init ) - *( .text .text.* ) - } > RAM - - .data : { - _data = . ; - *( .data ) - *( .data.* ) - _sdata = . ; - *( .sdata ) - *( .sdata.* ) - } > RAM - - .bss : { - _bss = .; - _sbss = .; - *(.sbss .sbss.*) - *(.bss .bss.*) - _end = .; - } > RAM -} diff --git a/projects/hello/build.mk b/projects/hello/build.mk new file mode 100644 index 00000000..802155fd --- /dev/null +++ b/projects/hello/build.mk @@ -0,0 +1,44 @@ +BUILD?=build +PROGRAM?=a + +SRCS=${wildcard ${PROGRAM}/*.[cS]} +OBJS=${patsubst ${PROGRAM}/%, ${BUILD}/${PROGRAM}/%.o, ${SRCS}} ${STARTFILES}/start.o +DEPS=${patsubst ${PROGRAM}/%, ${BUILD}/${PROGRAM}/%.d, ${SRCS}} + +CFLAGS=-march=${ARCH} -mabi=${ABI} -mcmodel=${CMODEL} +CFLAGS+=-DPLATFORM_${PLATFORM} +CFLAGS+=-nostdlib +CFLAGS+=-DSTACK_SIZE=1024 +CFLAGS+=-Os -g3 +CFLAGS+=-I${COMMON_INC} -include ${S3K_CONF_H} + +LDFLAGS=-march=${ARCH} -mabi=${ABI} -mcmodel=${CMODEL} +LDFLAGS+=-g3 +LDFLAGS+=-nostartfiles -nostdlib +LDFLAGS+=-T${PROGRAM}.ld -Tdefault.ld +LDFLAGS+=-Wl,--no-warn-rwx-segments +LDFLAGS+=-L${COMMON_LIB} -ls3k -laltc -lplat + +ELF=${BUILD}/${PROGRAM}.elf + +all: ${ELF} + +${BUILD}/${PROGRAM}/%.S.o: ${PROGRAM}/%.S + @mkdir -p ${@D} + ${CC} -o $@ $< ${CFLAGS} ${INC} -MMD -c + +${BUILD}/${PROGRAM}/%.c.o: ${PROGRAM}/%.c + @mkdir -p ${@D} + ${CC} -o $@ $< ${CFLAGS} ${INC} -MMD -c + +${ELF}: ${OBJS} + @mkdir -p ${@D} + ${CC} -o $@ ${OBJS} ${LDFLAGS} -MMD ${INC} + +clean: + rm -f ${ELF} ${OBJS} ${DEPS} + +.PHONY: all elf clean + +-include ${DEPS} + diff --git a/projects/wcet/app0/linker.ld b/projects/hello/default.ld similarity index 88% rename from projects/wcet/app0/linker.ld rename to projects/hello/default.ld index b75694a6..5568d1d2 100644 --- a/projects/wcet/app0/linker.ld +++ b/projects/hello/default.ld @@ -4,10 +4,6 @@ ENTRY(_start) __global_pointer$ = MIN(_sdata + 0x800, MAX(_data + 0x800, _end - 0x800)); -MEMORY { - RAM (rwx) : ORIGIN = 0x80010000, LENGTH = 64K -} - SECTIONS { .text : { *( .init ) diff --git a/projects/hello/default.mk b/projects/hello/default.mk deleted file mode 100644 index 0f0b4dc5..00000000 --- a/projects/hello/default.mk +++ /dev/null @@ -1,65 +0,0 @@ -BUILD?=build -PROGRAM?=a - -ROOT=../../.. -STARTFILES=${ROOT}/common/start - -include ${ROOT}/tools.mk -include ${ROOT}/common/plat/${PLATFORM}.mk - -OBJS=${patsubst %, ${BUILD}/${PROGRAM}/%.o, ${SRCS}} ${STARTFILES}/start.o -DEPS=${patsubst %, ${BUILD}/${PROGRAM}/%.d, ${SRCS}} - -CFLAGS=-march=${ARCH} -mabi=${ABI} -mcmodel=${CMODEL} -CFLAGS+=-DPLATFORM_${PLATFORM} -CFLAGS+=-nostdlib -CFLAGS+=-DSTACK_SIZE=1024 -CFLAGS+=-Os -g3 -CFLAGS+=-Iinc -I${COMMON_INC} -include ${S3K_CONF_H} - -LDFLAGS=-march=${ARCH} -mabi=${ABI} -mcmodel=${CMODEL} -LDFLAGS+=-g3 -LDFLAGS+=-nostartfiles -nostdlib -LDFLAGS+=-Tlinker.ld -LDFLAGS+=-Wl,--no-warn-rwx-segments -LDFLAGS+=-L${COMMON_LIB} -ls3k -laltc -lplat - - -ELF=${BUILD}/${PROGRAM}.elf -BIN=${ELF:.elf=.bin} -DA=${ELF:.elf=.da} - -all: ${ELF} ${BIN} ${DA} - -elf: ${ELF} -bin: ${BIN} -da: ${DA} - -${BUILD}/${PROGRAM}/%.S.o: %.S - @mkdir -p ${@D} - @echo "CC $@" - @${CC} -o $@ $< ${CFLAGS} ${INC} -MMD -c -${BUILD}/${PROGRAM}/%.c.o: %.c - @mkdir -p ${@D} - @echo "CC $@" - @${CC} -o $@ $< ${CFLAGS} ${INC} -MMD -c - -${ELF}: ${OBJS} - @mkdir -p ${@D} - @echo "CC $@" - @${CC} -o $@ ${OBJS} ${LDFLAGS} -MMD ${INC} - -${BIN}: ${ELF} - @echo "OBJCOPY $@" - @${OBJCOPY} -O binary $< $@ - -${DA}: ${ELF} - @echo "OBJDUMP $@" - @${OBJDUMP} -D $< > $@ - -clean: - rm -f ${ELF} ${BIN} ${DA} ${OBJS} ${DEPS} - -.PHONY: all elf bin da clean - --include ${DEPS} diff --git a/projects/hello/scripts/qemu.sh b/projects/hello/scripts/qemu.sh deleted file mode 100755 index 28b409f9..00000000 --- a/projects/hello/scripts/qemu.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env bash - -KERNEL=build/s3k -APP0=build/app0 -APP1=build/app1 - -qemu-system-riscv64 -M virt -smp 4 -m 128M \ - -nographic -bios none -kernel $KERNEL.elf \ - -device loader,file=$APP0.bin,addr=0x80010000 \ - -device loader,file=$APP1.bin,addr=0x80020000 \ - $@ diff --git a/projects/ping-pong/Makefile b/projects/ping-pong/Makefile index dafae795..3a000575 100644 --- a/projects/ping-pong/Makefile +++ b/projects/ping-pong/Makefile @@ -1,17 +1,8 @@ -export BUILD=${abspath build} -export S3K_CONF_H=${abspath s3k_conf.h} +APPS=app0 app1 -DIRS=../../kernel app0 app1 +all: ${APPS} -all: ${DIRS} +${APPS}: + @${MAKE} -f build.mk PROGRAM=$@ -${DIRS}: - @${MAKE} -C $@ - -gdb qemu: all - ./scripts/$@.sh - -clean: - rm -rf ${BUILD} - -.PHONY: all clean ${DIRS} gdb qemu +.PHONY: all clean ${APPS} diff --git a/projects/ping-pong/app0.ld b/projects/ping-pong/app0.ld new file mode 100644 index 00000000..a9a658b9 --- /dev/null +++ b/projects/ping-pong/app0.ld @@ -0,0 +1,3 @@ +MEMORY { + RAM (rwx) : ORIGIN = 0x80010000, LENGTH = 0x10000 +} diff --git a/projects/ping-pong/app0/Makefile b/projects/ping-pong/app0/Makefile deleted file mode 100644 index 9458ef6b..00000000 --- a/projects/ping-pong/app0/Makefile +++ /dev/null @@ -1,5 +0,0 @@ -PROGRAM=app0 - -SRCS=start/start.S main.c s3k/s3k.c s3klib/altio.c s3klib/mem.S - -include ../default.mk diff --git a/projects/ping-pong/app0/main.c b/projects/ping-pong/app0/main.c index 63c5a10c..8b3752bc 100644 --- a/projects/ping-pong/app0/main.c +++ b/projects/ping-pong/app0/main.c @@ -1,6 +1,5 @@ #include "s3k/s3k.h" -#include "s3klib/altio.h" -#include "s3klib/mem.h" +#include "altc/altio.h" #define APP0_PID 0 #define APP1_PID 1 diff --git a/projects/ping-pong/app1.ld b/projects/ping-pong/app1.ld new file mode 100644 index 00000000..7ca7718e --- /dev/null +++ b/projects/ping-pong/app1.ld @@ -0,0 +1,3 @@ +MEMORY { + RAM (rwx) : ORIGIN = 0x80020000, LENGTH = 0x10000 +} diff --git a/projects/ping-pong/app1/Makefile b/projects/ping-pong/app1/Makefile deleted file mode 100644 index 1a675b87..00000000 --- a/projects/ping-pong/app1/Makefile +++ /dev/null @@ -1,5 +0,0 @@ -PROGRAM=app1 - -SRCS=start/start.S main.c s3k/s3k.c s3klib/altio.c - -include ../default.mk diff --git a/projects/ping-pong/app1/linker.ld b/projects/ping-pong/app1/linker.ld deleted file mode 100644 index 9a158252..00000000 --- a/projects/ping-pong/app1/linker.ld +++ /dev/null @@ -1,33 +0,0 @@ -/* See LICENSE file for copyright and license details. */ -OUTPUT_ARCH(riscv) -ENTRY(_start) - -__global_pointer$ = MIN(_sdata + 0x800, MAX(_data + 0x800, _end - 0x800)); - -MEMORY { - RAM (rwx) : ORIGIN = 0x80020000, LENGTH = 0x10000 -} - -SECTIONS { - .text : { - *( .init ) - *( .text .text.* ) - } > RAM - - .data : { - _data = . ; - *( .data ) - *( .data.* ) - _sdata = . ; - *( .sdata ) - *( .sdata.* ) - } > RAM - - .bss : { - _bss = .; - _sbss = .; - *(.sbss .sbss.*) - *(.bss .bss.*) - _end = .; - } > RAM -} diff --git a/projects/ping-pong/app1/main.c b/projects/ping-pong/app1/main.c index 4b5bcdf6..f93807b9 100644 --- a/projects/ping-pong/app1/main.c +++ b/projects/ping-pong/app1/main.c @@ -1,5 +1,5 @@ #include "s3k/s3k.h" -#include "s3klib/altio.h" +#include "altc/altio.h" #include diff --git a/projects/ping-pong/build.mk b/projects/ping-pong/build.mk new file mode 100644 index 00000000..e6338ecd --- /dev/null +++ b/projects/ping-pong/build.mk @@ -0,0 +1,43 @@ +BUILD?=build +PROGRAM?=a + +SRCS=${wildcard ${PROGRAM}/*.[cS]} +OBJS=${patsubst ${PROGRAM}/%, ${BUILD}/${PROGRAM}/%.o, ${SRCS}} ${STARTFILES}/start.o +DEPS=${patsubst ${PROGRAM}/%, ${BUILD}/${PROGRAM}/%.d, ${SRCS}} + +CFLAGS=-march=${ARCH} -mabi=${ABI} -mcmodel=${CMODEL} +CFLAGS+=-DPLATFORM_${PLATFORM} +CFLAGS+=-nostdlib +CFLAGS+=-DSTACK_SIZE=1024 +CFLAGS+=-Os -g3 +CFLAGS+=-Iinc -I${COMMON_INC} -include ${S3K_CONF_H} + +LDFLAGS=-march=${ARCH} -mabi=${ABI} -mcmodel=${CMODEL} +LDFLAGS+=-g3 +LDFLAGS+=-nostartfiles -nostdlib +LDFLAGS+=-T${PROGRAM}.ld -Tdefault.ld +LDFLAGS+=-Wl,--no-warn-rwx-segments +LDFLAGS+=-L${COMMON_LIB} -ls3k -laltc -lplat + +ELF=${BUILD}/${PROGRAM}.elf + +all: ${ELF} + +${BUILD}/${PROGRAM}/%.S.o: ${PROGRAM}/%.S + @mkdir -p ${@D} + ${CC} -o $@ $< ${CFLAGS} ${INC} -MMD -c + +${BUILD}/${PROGRAM}/%.c.o: ${PROGRAM}/%.c + @mkdir -p ${@D} + ${CC} -o $@ $< ${CFLAGS} ${INC} -MMD -c + +${ELF}: ${OBJS} + @mkdir -p ${@D} + ${CC} -o $@ ${OBJS} ${LDFLAGS} -MMD ${INC} + +clean: + rm -f ${ELF} ${OBJS} ${DEPS} + +.PHONY: all elf clean + +-include ${DEPS} diff --git a/projects/ping-pong/app0/linker.ld b/projects/ping-pong/default.ld similarity index 87% rename from projects/ping-pong/app0/linker.ld rename to projects/ping-pong/default.ld index 7f5ba272..5568d1d2 100644 --- a/projects/ping-pong/app0/linker.ld +++ b/projects/ping-pong/default.ld @@ -4,10 +4,6 @@ ENTRY(_start) __global_pointer$ = MIN(_sdata + 0x800, MAX(_data + 0x800, _end - 0x800)); -MEMORY { - RAM (rwx) : ORIGIN = 0x80010000, LENGTH = 0x10000 -} - SECTIONS { .text : { *( .init ) diff --git a/projects/ping-pong/default.mk b/projects/ping-pong/default.mk deleted file mode 100644 index 7e5993e5..00000000 --- a/projects/ping-pong/default.mk +++ /dev/null @@ -1,63 +0,0 @@ -BUILD?=build -PROGRAM?=a - -ROOT=../../.. -USERLAND=${ROOT}/userland -PLATFORM=${ROOT}/plat64 - -include ${ROOT}/tools.mk -include ${PLATFORM}/config.mk - -vpath %.c . ${USERLAND}/src -vpath %.S . ${USERLAND}/src - -OBJS=${patsubst %, ${BUILD}/${PROGRAM}/%.o, ${SRCS}} -DEPS=${patsubst %, ${BUILD}/${PROGRAM}/%.d, ${SRCS}} - -CFLAGS+=-march=${ARCH} -mabi=${ABI} -mcmodel=${CMODEL} -CFLAGS+=-nostartfiles -nostdlib -CFLAGS+=-DSTACK_SIZE=1024 -CFLAGS+=-Tlinker.ld -CFLAGS+=-Wl,--no-warn-rwx-segments - -INC=-Iinc -I${PLATFORM}/inc -I${USERLAND}/inc -include ${S3K_CONF_H} - -ELF=${BUILD}/${PROGRAM}.elf -BIN=${ELF:.elf=.bin} -DA=${ELF:.elf=.da} - -all: ${ELF} ${BIN} ${DA} - -elf: ${ELF} -bin: ${BIN} -da: ${DA} - -${BUILD}/${PROGRAM}/%.S.o: %.S - @mkdir -p ${@D} - @echo "CC $@" - @${CC} ${CFLAGS} ${INC} -MMD -c -o $@ $< - -${BUILD}/${PROGRAM}/%.c.o: %.c - @mkdir -p ${@D} - @echo "CC $@" - @${CC} ${CFLAGS} ${INC} -MMD -c -o $@ $< - -${ELF}: ${OBJS} - @mkdir -p ${@D} - @echo "CC $@" - @${CC} ${CFLAGS} -MMD ${INC} -o $@ ${OBJS} - -${BIN}: ${ELF} - @echo "OBJCOPY $@" - @${OBJCOPY} -O binary $< $@ - -${DA}: ${ELF} - @echo "OBJDUMP $@" - @${OBJDUMP} -D $< > $@ - -clean: - rm -f ${ELF} ${BIN} ${DA} ${OBJS} ${DEPS} - -.PHONY: all elf bin da clean - --include ${DEPS} diff --git a/projects/trapped/Makefile b/projects/trapped/Makefile index 6e297342..88fb6fd7 100644 --- a/projects/trapped/Makefile +++ b/projects/trapped/Makefile @@ -1,17 +1,8 @@ -export BUILD=${abspath build} -export S3K_CONF_H=${abspath s3k_conf.h} +APPS=app0 -DIRS=../../kernel app0 +all: ${APPS} -all: ${DIRS} +${APPS}: + @${MAKE} -f build.mk PROGRAM=$@ -${DIRS}: - @${MAKE} -C $@ - -gdb qemu: all - ./scripts/$@.sh - -clean: - rm -rf ${BUILD} - -.PHONY: all clean ${DIRS} gdb qemu +.PHONY: all clean ${APPS} diff --git a/projects/trapped/app0.ld b/projects/trapped/app0.ld new file mode 100644 index 00000000..a9a658b9 --- /dev/null +++ b/projects/trapped/app0.ld @@ -0,0 +1,3 @@ +MEMORY { + RAM (rwx) : ORIGIN = 0x80010000, LENGTH = 0x10000 +} diff --git a/projects/trapped/app0/Makefile b/projects/trapped/app0/Makefile deleted file mode 100644 index 81e0b450..00000000 --- a/projects/trapped/app0/Makefile +++ /dev/null @@ -1,5 +0,0 @@ -PROGRAM?=app0 - -SRCS=start/start.S main.c s3k/s3k.c s3klib/altio.c - -include ../default.mk diff --git a/projects/trapped/app0/linker.ld b/projects/trapped/app0/linker.ld deleted file mode 100644 index 7f5ba272..00000000 --- a/projects/trapped/app0/linker.ld +++ /dev/null @@ -1,33 +0,0 @@ -/* See LICENSE file for copyright and license details. */ -OUTPUT_ARCH(riscv) -ENTRY(_start) - -__global_pointer$ = MIN(_sdata + 0x800, MAX(_data + 0x800, _end - 0x800)); - -MEMORY { - RAM (rwx) : ORIGIN = 0x80010000, LENGTH = 0x10000 -} - -SECTIONS { - .text : { - *( .init ) - *( .text .text.* ) - } > RAM - - .data : { - _data = . ; - *( .data ) - *( .data.* ) - _sdata = . ; - *( .sdata ) - *( .sdata.* ) - } > RAM - - .bss : { - _bss = .; - _sbss = .; - *(.sbss .sbss.*) - *(.bss .bss.*) - _end = .; - } > RAM -} diff --git a/projects/trapped/app0/main.c b/projects/trapped/app0/main.c index f41947a6..b7280b23 100644 --- a/projects/trapped/app0/main.c +++ b/projects/trapped/app0/main.c @@ -1,5 +1,5 @@ #include "s3k/s3k.h" -#include "s3klib/altio.h" +#include "altc/altio.h" #define APP0_PID 0 #define APP1_PID 1 diff --git a/projects/trapped/build.mk b/projects/trapped/build.mk new file mode 100644 index 00000000..e6338ecd --- /dev/null +++ b/projects/trapped/build.mk @@ -0,0 +1,43 @@ +BUILD?=build +PROGRAM?=a + +SRCS=${wildcard ${PROGRAM}/*.[cS]} +OBJS=${patsubst ${PROGRAM}/%, ${BUILD}/${PROGRAM}/%.o, ${SRCS}} ${STARTFILES}/start.o +DEPS=${patsubst ${PROGRAM}/%, ${BUILD}/${PROGRAM}/%.d, ${SRCS}} + +CFLAGS=-march=${ARCH} -mabi=${ABI} -mcmodel=${CMODEL} +CFLAGS+=-DPLATFORM_${PLATFORM} +CFLAGS+=-nostdlib +CFLAGS+=-DSTACK_SIZE=1024 +CFLAGS+=-Os -g3 +CFLAGS+=-Iinc -I${COMMON_INC} -include ${S3K_CONF_H} + +LDFLAGS=-march=${ARCH} -mabi=${ABI} -mcmodel=${CMODEL} +LDFLAGS+=-g3 +LDFLAGS+=-nostartfiles -nostdlib +LDFLAGS+=-T${PROGRAM}.ld -Tdefault.ld +LDFLAGS+=-Wl,--no-warn-rwx-segments +LDFLAGS+=-L${COMMON_LIB} -ls3k -laltc -lplat + +ELF=${BUILD}/${PROGRAM}.elf + +all: ${ELF} + +${BUILD}/${PROGRAM}/%.S.o: ${PROGRAM}/%.S + @mkdir -p ${@D} + ${CC} -o $@ $< ${CFLAGS} ${INC} -MMD -c + +${BUILD}/${PROGRAM}/%.c.o: ${PROGRAM}/%.c + @mkdir -p ${@D} + ${CC} -o $@ $< ${CFLAGS} ${INC} -MMD -c + +${ELF}: ${OBJS} + @mkdir -p ${@D} + ${CC} -o $@ ${OBJS} ${LDFLAGS} -MMD ${INC} + +clean: + rm -f ${ELF} ${OBJS} ${DEPS} + +.PHONY: all elf clean + +-include ${DEPS} diff --git a/projects/hello/app0/linker.ld b/projects/trapped/default.ld similarity index 87% rename from projects/hello/app0/linker.ld rename to projects/trapped/default.ld index 7f5ba272..5568d1d2 100644 --- a/projects/hello/app0/linker.ld +++ b/projects/trapped/default.ld @@ -4,10 +4,6 @@ ENTRY(_start) __global_pointer$ = MIN(_sdata + 0x800, MAX(_data + 0x800, _end - 0x800)); -MEMORY { - RAM (rwx) : ORIGIN = 0x80010000, LENGTH = 0x10000 -} - SECTIONS { .text : { *( .init ) diff --git a/projects/trapped/default.mk b/projects/trapped/default.mk deleted file mode 100644 index 7e5993e5..00000000 --- a/projects/trapped/default.mk +++ /dev/null @@ -1,63 +0,0 @@ -BUILD?=build -PROGRAM?=a - -ROOT=../../.. -USERLAND=${ROOT}/userland -PLATFORM=${ROOT}/plat64 - -include ${ROOT}/tools.mk -include ${PLATFORM}/config.mk - -vpath %.c . ${USERLAND}/src -vpath %.S . ${USERLAND}/src - -OBJS=${patsubst %, ${BUILD}/${PROGRAM}/%.o, ${SRCS}} -DEPS=${patsubst %, ${BUILD}/${PROGRAM}/%.d, ${SRCS}} - -CFLAGS+=-march=${ARCH} -mabi=${ABI} -mcmodel=${CMODEL} -CFLAGS+=-nostartfiles -nostdlib -CFLAGS+=-DSTACK_SIZE=1024 -CFLAGS+=-Tlinker.ld -CFLAGS+=-Wl,--no-warn-rwx-segments - -INC=-Iinc -I${PLATFORM}/inc -I${USERLAND}/inc -include ${S3K_CONF_H} - -ELF=${BUILD}/${PROGRAM}.elf -BIN=${ELF:.elf=.bin} -DA=${ELF:.elf=.da} - -all: ${ELF} ${BIN} ${DA} - -elf: ${ELF} -bin: ${BIN} -da: ${DA} - -${BUILD}/${PROGRAM}/%.S.o: %.S - @mkdir -p ${@D} - @echo "CC $@" - @${CC} ${CFLAGS} ${INC} -MMD -c -o $@ $< - -${BUILD}/${PROGRAM}/%.c.o: %.c - @mkdir -p ${@D} - @echo "CC $@" - @${CC} ${CFLAGS} ${INC} -MMD -c -o $@ $< - -${ELF}: ${OBJS} - @mkdir -p ${@D} - @echo "CC $@" - @${CC} ${CFLAGS} -MMD ${INC} -o $@ ${OBJS} - -${BIN}: ${ELF} - @echo "OBJCOPY $@" - @${OBJCOPY} -O binary $< $@ - -${DA}: ${ELF} - @echo "OBJDUMP $@" - @${OBJDUMP} -D $< > $@ - -clean: - rm -f ${ELF} ${BIN} ${DA} ${OBJS} ${DEPS} - -.PHONY: all elf bin da clean - --include ${DEPS} diff --git a/projects/trapped/scripts/gdb.sh b/projects/trapped/scripts/gdb.sh deleted file mode 100755 index 74027711..00000000 --- a/projects/trapped/scripts/gdb.sh +++ /dev/null @@ -1,30 +0,0 @@ -#!/bin/bash - -KERNEL=build/s3k -APP0=build/app0 -APP1=build/app1 - -if [[ -z "$TMUX" ]]; then - echo "No tmux session" - exit 0 -fi - -tmux split-window -d "./scripts/qemu.sh -s -S" -sleep 0.5 - -riscv64-unknown-elf-gdb \ - -ex "set confirm off" \ - -ex "set pagination off" \ - -ex "set output-radix 16" \ - -ex "symbol-file $KERNEL.elf" \ - -ex "add-symbol-file $APP0.elf" \ - -ex "j 0x80000000" \ - -ex "b _hang" \ - -ex "b *0x80010000" \ - -ex "b *0x80020000" \ - -ex "b handle_exception" \ - -ex "target remote localhost:1234" \ - -ex "layout split" \ - -ex "fs cmd" - -kill -SIGTERM $(pgrep qemu-system-*) diff --git a/projects/trapped/scripts/qemu.sh b/projects/trapped/scripts/qemu.sh deleted file mode 100755 index b8230553..00000000 --- a/projects/trapped/scripts/qemu.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash - -KERNEL=build/s3k -APP0=build/app0 - -qemu-system-riscv64 -M virt -smp 4 -m 128M \ - -nographic -bios none -kernel $KERNEL.elf \ - -device loader,file=$APP0.bin,addr=0x80010000 \ - $@ diff --git a/projects/wcet/Makefile b/projects/wcet/Makefile deleted file mode 100644 index 901af9f5..00000000 --- a/projects/wcet/Makefile +++ /dev/null @@ -1,17 +0,0 @@ - -export CC=riscv64-unknown-elf-gcc -export OBJCOPY=riscv64-unknown-elf-objcopy - -all: s3k app0 - -s3k: - ${MAKE} -C ../../kernel BUILD=${abspath s3k} - -app0: - ${MAKE} -C app0 - -clean: - rm -rf s3k - ${MAKE} -C app0 clean - -.PHONY: clean app0 s3k diff --git a/projects/wcet/app0/Makefile b/projects/wcet/app0/Makefile deleted file mode 100644 index b3e5befb..00000000 --- a/projects/wcet/app0/Makefile +++ /dev/null @@ -1,36 +0,0 @@ -PROGRAM=app0 -ELF=${PROGRAM}.elf -BIN=${PROGRAM}.bin -COMMON=../../../common -LIBS3K=../../../libs3k -DRIVERS=../../../drivers - -PLATFORM=../../../plat/virt - -include ${PLATFORM}/platform.mk - -vpath %.c src - -SRCS=${COMMON}/start.S ${COMMON}/altio.c main.c -SRCS+=${PLATFORM_SRCS} - -CFLAGS+=-march=${ARCH} -mabi=${ABI} -mcmodel=${CMODEL} -CFLAGS+=-nostartfiles -nostdlib -CFLAGS+=-DSTACK_SIZE=1024 -CFLAGS+=-T${PLATFORM}/platform.ld -Tlinker.ld -CFLAGS+=-Wl,--no-warn-rwx-segments - -INC=-I${DRIVERS}/inc -I${COMMON}/inc -I${LIBS3K} - -all: ${ELF} ${BIN} - -${ELF}: ${SRCS} - $(CC) ${CFLAGS} ${INC} -o $@ ${filter %.S, $^} ${filter %.c, $^} - -${BIN}: ${ELF} - ${OBJCOPY} -O binary $< $@ - -clean: - rm -f ${ELF} ${BIN} - -.PHONY: clean diff --git a/projects/wcet/app0/src/main.c b/projects/wcet/app0/src/main.c deleted file mode 100644 index dd0c4e6c..00000000 --- a/projects/wcet/app0/src/main.c +++ /dev/null @@ -1,35 +0,0 @@ -#include "altio.h" -#include "s3k.h" -#include "timer.h" - -#include - -int main(void) -{ - // Access UART and timer - uint64_t uart_addr = s3k_napot_encode(0x10000000, 0x8); - uint64_t time_addr = s3k_napot_encode(0x200bff8, 0x8); - s3k_drvcap(2, 16, s3k_mkpmp(uart_addr, S3K_RW)); - s3k_drvcap(3, 17, s3k_mkpmp(time_addr, 1)); - s3k_pmpset(16, 1); - s3k_pmpset(17, 2); - - alt_puts("hello, world"); - uint64_t old = -1; - uint64_t start, end, elapsed, wcet; - s3k_cap_t time = s3k_mktime(1, 0, 64); - while (1) { - s3k_revcap(5); - while (s3k_drvcap(5, 18, time)) - ; - asm volatile("csrr %0,cycle" : "=r"(start)); - s3k_revcap(5); - asm volatile("csrr %0,cycle" : "=r"(end)); - elapsed = end - start; - if (old == elapsed) - continue; - asm volatile("csrr %0,hpmcounter3" : "=r"(wcet)); - alt_printf("%X %X\n", elapsed, wcet); - old = elapsed; - } -} diff --git a/projects/wcet/run.sh b/projects/wcet/run.sh deleted file mode 100755 index 17c3d2cc..00000000 --- a/projects/wcet/run.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash - -KERNEL_ELF=s3k/s3k.elf -PAYLOAD_ELF=app0/app0.elf -PAYLOAD_BIN=app0/app0.bin - -# Build the kernel and application -make -B - -# Run the kernel, load the application as payload -qemu-system-riscv64 -M virt -smp 1 -m 128M -icount 3 \ - -nographic -bios none -kernel $KERNEL_ELF \ - -device loader,file=$PAYLOAD_BIN,addr=0x80010000 - -# After qemu, kill linguring processes. -pkill -P $$ diff --git a/projects/hello/scripts/gdb.sh b/scripts/gdb.sh similarity index 64% rename from projects/hello/scripts/gdb.sh rename to scripts/gdb.sh index 0f991a61..9c6b6439 100755 --- a/projects/hello/scripts/gdb.sh +++ b/scripts/gdb.sh @@ -9,21 +9,20 @@ if [[ -z "$TMUX" ]]; then exit 0 fi -tmux split-window -d "./scripts/qemu.sh -s -S" +tmux split-window -d "./scripts/qemu.sh '$1' '-s'" sleep 0.5 +ADD_SYMBOL_FILE="" +for elf in `ls $1/*.elf`; do + ADD_SYMBOL_FILE=" -ex \"add-symbol-file $elf\"" +done + riscv64-unknown-elf-gdb \ -ex "set confirm off" \ -ex "set pagination off" \ -ex "set output-radix 16" \ - -ex "symbol-file $KERNEL.elf" \ - -ex "add-symbol-file $APP0.elf" \ - -ex "add-symbol-file $APP1.elf" \ -ex "j 0x80000000" \ -ex "b __hang" \ - -ex "b *0x80010000" \ - -ex "b *0x80020000" \ - -ex "b handle_exception" \ -ex "target remote localhost:1234" \ -ex "layout split" \ -ex "fs cmd" diff --git a/scripts/qemu.sh b/scripts/qemu.sh new file mode 100755 index 00000000..a2459b07 --- /dev/null +++ b/scripts/qemu.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash + + +LOADER="" +for elf in $(ls $1/*.elf); do + LOADER+="-device loader,file=$elf " +done + +if [[ -z "$QEMU_MACHINE" ]]; then + echo "QEMU_MACHINE not set" +fi + +if [[ -z "$QEMU_SMP" ]]; then + echo "QEMU_SMP not set" +fi + +qemu-system-riscv64 -M $QEMU_MACHINE -smp $QEMU_SMP -m 128M -nographic -bios none \ + $LOADER $2 diff --git a/tools.mk b/tools.mk index ab3f2a52..92156e27 100644 --- a/tools.mk +++ b/tools.mk @@ -1,7 +1,7 @@ RISCV_PREFIX?=riscv64-unknown-elf- -CC=${RISCV_PREFIX}gcc -AR=${RISCV_PREFIX}ar -LD=${RISCV_PREFIX}ld -SIZE=${RISCV_PREFIX}size -OBJDUMP=${RISCV_PREFIX}objdump -OBJCOPY=${RISCV_PREFIX}objcopy +export CC=${RISCV_PREFIX}gcc +export AR=${RISCV_PREFIX}ar +export LD=${RISCV_PREFIX}ld +export SIZE=${RISCV_PREFIX}size +export OBJDUMP=${RISCV_PREFIX}objdump +export OBJCOPY=${RISCV_PREFIX}objcopy