Skip to content

Commit

Permalink
Evaluation
Browse files Browse the repository at this point in the history
  • Loading branch information
HAKarlsson committed Dec 7, 2023
1 parent b2bdfe5 commit 0121dd3
Show file tree
Hide file tree
Showing 41 changed files with 718 additions and 851 deletions.
18 changes: 7 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,28 +1,24 @@
.POSIX:

export ROOT=${abspath .}

.SECONDARY:

PROJECTS:=projects/hello \
projects/trapped \
projects/ping-pong \
projects/demonstrator
PLATFORM?=qemu_virt

include tools.mk
include common/plat/${PLATFORM}.mk

all: ${PROJECTS}

${PROJECTS}: common

common ${PROJECTS}:
make -C $@ all PLATFORM=${PLATFORM}
@${MAKE} -C $@ all

clean:
for i in ${PROJECTS}; do \
make -C $$i clean PLATFORM=${PLATFORM}; \
@for i in common ${PROJECTS}; do \
${MAKE} -C $$i clean; \
done

format:
clang-format -i $$(find * -type f -name '*.[hc]')

.PHONY: all docs clean common ${PROJECTS}
.PHONY: all clean format common ${PROJECTS}
58 changes: 8 additions & 50 deletions common/Makefile
Original file line number Diff line number Diff line change
@@ -1,57 +1,15 @@
.POSIX:
.SECONDARY:

include plat/${PLATFORM}.mk
PLATFORM?=${patsubst plat/%.mk, %, ${wildcard plat/*.mk}}

include ${ROOT}/tools.mk
all: ${addsuffix .all, ${PLATFORM}}
clean: ${addsuffix .clean, ${PLATFORM}}

# CFLAGS
CFLAGS:=-march=${ARCH} -mabi=${ABI} -mcmodel=${CMODEL} \
-DPLATFORM_${PLATFORM} \
-Os -flto -ffat-lto-objects \
-nostdlib -Iinc \
%.all:
${MAKE} -f build.mk PLATFORM=${@:.all=} all

BUILD :=build/${PLATFORM}
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}}

TARGETS:=${BUILD}/libplat.a \
${BUILD}/libaltc.a \
${BUILD}/libs3k.a \
${START_OBJS}


all: ${TARGETS}

clean:
rm -rf ${TARGETS}

${BUILD}/libplat.a: ${PLAT_OBJS}
@mkdir -p ${@D}
${AR} cr $@ $^

${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:
${MAKE} -f build.mk PLATFORM=${@:.clean=} clean

.PHONY: all clean
64 changes: 64 additions & 0 deletions common/build.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
.POSIX:

ROOT:=${abspath ..}

include plat/${PLATFORM}.mk

include ${ROOT}/tools.mk

# CFLAGS
CFLAGS:=-march=${ARCH} -mabi=${ABI} -mcmodel=${CMODEL} \
-DPLATFORM_${PLATFORM} \
-Os -flto -ffat-lto-objects \
-nostdlib -Iinc \

BUILD :=build/${PLATFORM}
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}}

TARGETS:=${BUILD}/libplat.a \
${BUILD}/libaltc.a \
${BUILD}/libs3k.a \
${START_OBJS}


all: ${TARGETS}

clean:
rm -rf ${BUILD}

${BUILD}/libplat.a: ${PLAT_OBJS}
@mkdir -p ${@D}
@${AR} cr $@ $^
@printf "AR\t$@\n"

${BUILD}/libaltc.a: ${ALTC_OBJS}
@mkdir -p ${@D}
@${AR} cr $@ $^
@printf "AR\t$@\n"

${BUILD}/libs3k.a: ${S3K_OBJS}
@mkdir -p ${@D}
@${AR} cr $@ $^
@printf "AR\t$@\n"

${BUILD}/%.o: src/%.c
@mkdir -p ${@D}
@${CC} -o $@ $< -c ${CFLAGS}
@printf "CC\t$@\n"

${BUILD}/%.o: src/%.S
@mkdir -p ${@D}
@${CC} -o $@ $< -c ${CFLAGS}
@printf "CC\t$@\n"

.PHONY: all clean
10 changes: 9 additions & 1 deletion common/inc/plat/config.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
#pragma once

#if defined(PLATFORM_qemu_virt) || defined(PLATFORM_qemu_virt4)
#if defined(PLATFORM_qemu_virt)
#include "plat/qemu_virt.h"
#elif defined(PLATFORM_qemu_virt4)
#include "plat/qemu_virt4.h"
#elif defined(PLATFORM_sifive_unleashed)
#include "plat/sifive_unleashed.h"
#elif defined(PLATFORM_sifive_unleashed4)
#include "plat/sifive_unleashed4.h"
#else
#error "Unsupported platform or platform not found"
#endif

#if S3K_HART_CNT > 1
#define SMP
#endif
5 changes: 1 addition & 4 deletions common/inc/plat/qemu_virt.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

// Min and max usable hart ID.
#define S3K_MIN_HART 0
#define S3K_MAX_HART 3
#define S3K_MAX_HART 0

// Total number of usable harts.
#define S3K_HART_CNT (S3K_MAX_HART - S3K_MIN_HART + 1ul)
Expand All @@ -32,9 +32,6 @@
[2] = cap_mk_memory(0x10000000, 0x10001000, MEM_RW), \
[3] = cap_mk_memory(0x200b000, 0x200c000, MEM_R), \
[4] = cap_mk_time(0, 0, S3K_SLOT_CNT), \
[5] = cap_mk_time(1, 0, S3K_SLOT_CNT), \
[6] = cap_mk_time(2, 0, S3K_SLOT_CNT), \
[7] = cap_mk_time(3, 0, S3K_SLOT_CNT), \
[8] = cap_mk_monitor(0, S3K_PROC_CNT), \
[9] = cap_mk_channel(0, S3K_CHAN_CNT), \
}
40 changes: 40 additions & 0 deletions common/inc/plat/qemu_virt4.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* Platform configuration for QEMU virt
*/
#pragma once

#define UART_NS16550A
#define UART0_BASE_ADDR (0x10000000ull)

#define MTIME_BASE_ADDR 0x200bff8ull
#define MTIMECMP_BASE_ADDR 0x2004000ull

// Min and max usable hart ID.
#define S3K_MIN_HART 0
#define S3K_MAX_HART 3

// Total number of usable harts.
#define S3K_HART_CNT (S3K_MAX_HART - S3K_MIN_HART + 1ul)

// Number of PMP slots.
#define S3K_PMP_CNT 8

// RTC ticks per second
#define S3K_RTC_HZ 1000000ull

/// Stack size of 1024 KiB
#define S3K_LOG_STACK_SIZE 10

#define INIT_CAPS \
{ \
[0] = cap_mk_pmp(0x20005fff, MEM_RWX), \
[1] = cap_mk_memory(0x80020000, 0x88000000, MEM_RWX), \
[2] = cap_mk_memory(0x10000000, 0x10001000, MEM_RW), \
[3] = cap_mk_memory(0x200b000, 0x200c000, MEM_R), \
[4] = cap_mk_time(0, 0, S3K_SLOT_CNT), \
[5] = cap_mk_time(1, 0, S3K_SLOT_CNT), \
[6] = cap_mk_time(2, 0, S3K_SLOT_CNT), \
[7] = cap_mk_time(3, 0, S3K_SLOT_CNT), \
[8] = cap_mk_monitor(0, S3K_PROC_CNT), \
[9] = cap_mk_channel(0, S3K_CHAN_CNT), \
}
5 changes: 1 addition & 4 deletions common/inc/plat/sifive_unleashed.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

// Min and max usable hart ID.
#define S3K_MIN_HART 1
#define S3K_MAX_HART 4
#define S3K_MAX_HART 1

// Total number of usable harts.
#define S3K_HART_CNT (S3K_MAX_HART - S3K_MIN_HART + 1ul)
Expand All @@ -31,9 +31,6 @@
[2] = cap_mk_memory(0x10010000, 0x10011000, MEM_RW), \
[3] = cap_mk_memory(0x200b000, 0x200c000, MEM_R), \
[4] = cap_mk_time(1, 0, S3K_SLOT_CNT), \
[5] = cap_mk_time(2, 0, S3K_SLOT_CNT), \
[6] = cap_mk_time(3, 0, S3K_SLOT_CNT), \
[7] = cap_mk_time(4, 0, S3K_SLOT_CNT), \
[8] = cap_mk_monitor(0, S3K_PROC_CNT), \
[9] = cap_mk_channel(0, S3K_CHAN_CNT), \
}
39 changes: 39 additions & 0 deletions common/inc/plat/sifive_unleashed4.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#pragma once

#define UART_SIFIVE
#define UART0_BASE_ADDR (0x10010000ull)

#define MTIME_BASE_ADDR 0x200bff8ull
#define MTIMECMP_BASE_ADDR 0x2004000ull

// Min and max usable hart ID.
#define S3K_MIN_HART 1
#define S3K_MAX_HART 4

// Total number of usable harts.
#define S3K_HART_CNT (S3K_MAX_HART - S3K_MIN_HART + 1ul)

// Number of PMP slots.
#define S3K_PMP_CNT 8

// RTC ticks per second
#define S3K_RTC_HZ 1000000ull

/// Stack size of 1024 KiB
#define S3K_LOG_STACK_SIZE 10

#define UART_SIFIVE

#define INIT_CAPS \
{ \
[0] = cap_mk_pmp(0x20005fff, MEM_RWX), \
[1] = cap_mk_memory(0x80020000, 0x88000000, MEM_RWX), \
[2] = cap_mk_memory(0x10010000, 0x10011000, MEM_RW), \
[3] = cap_mk_memory(0x200b000, 0x200c000, MEM_R), \
[4] = cap_mk_time(1, 0, S3K_SLOT_CNT), \
[5] = cap_mk_time(2, 0, S3K_SLOT_CNT), \
[6] = cap_mk_time(3, 0, S3K_SLOT_CNT), \
[7] = cap_mk_time(4, 0, S3K_SLOT_CNT), \
[8] = cap_mk_monitor(0, S3K_PROC_CNT), \
[9] = cap_mk_channel(0, S3K_CHAN_CNT), \
}
4 changes: 2 additions & 2 deletions common/inc/s3k/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ bool s3k_is_valid(s3k_cap_t a);
bool s3k_is_parent(s3k_cap_t a, s3k_cap_t b);
bool s3k_is_derivable(s3k_cap_t a, s3k_cap_t b);

void s3k_napot_decode(s3k_napot_t napot_addr, s3k_addr_t *begin,
s3k_addr_t *end);
void s3k_napot_decode(s3k_napot_t napot_addr, s3k_addr_t *base,
s3k_addr_t *size);
s3k_napot_t s3k_napot_encode(s3k_addr_t base, s3k_addr_t size);

static inline bool s3k_is_ready(s3k_state_t state)
Expand Down
7 changes: 7 additions & 0 deletions common/plat/sifive_unleashed4.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export ARCH=rv64imac_zicsr_zifencei
export ABI=lp64
export CMODEL=medany
export COMMON_INC:=${ROOT}/common/inc
export COMMON_LIB:=${ROOT}/common/build/${PLATFORM}
export STARTFILES:=${ROOT}/common/build/${PLATFORM}/start
PLAT_SRCS=src/drivers/uart/sifive.c src/drivers/time.c
4 changes: 2 additions & 2 deletions common/src/altc/printf.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,13 @@ int alt_vsnprintf(char *restrict str, size_t size, const char *restrict fmt,
s = write_hex(s, end, va_arg(ap, unsigned int));
break;
case 'X':
s = write_hex(s, end, va_arg(ap, unsigned long long));
s = write_hex(s, end, va_arg(ap, unsigned long));
break;
case 'd':
s = write_dec(s, end, va_arg(ap, unsigned int));
break;
case 'D':
s = write_dec(s, end, va_arg(ap, unsigned long long));
s = write_dec(s, end, va_arg(ap, unsigned long));
break;
case '\0':
break;
Expand Down
2 changes: 1 addition & 1 deletion common/src/s3k/syscall.c
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ s3k_err_t s3k_try_cap_derive(s3k_cidx_t src, s3k_cidx_t dst, s3k_cap_t ncap)
{
sys_args_t args = {
.cap_derive = {src, dst, ncap.raw}
};
};
return DO_ECALL(S3K_SYS_CAP_DERIVE, args, sizeof(args.cap_derive)).err;
}

Expand Down
Loading

0 comments on commit 0121dd3

Please sign in to comment.