Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Major improvements from evaluation (#10)" #12

Merged
merged 1 commit into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
.POSIX:
.SECONDARY:
export ROOT=${abspath .}

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

all: ${PROJECTS}
PROJECTS:=projects/hello projects/trapped projects/ping-pong
PLATFORM?=qemu_virt

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

${PROJECTS}: common
all: ${PROJECTS}

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

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

docs:
doxygen

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

.PHONY: all clean format common ${PROJECTS}
.PHONY: all docs clean common ${PROJECTS}
32 changes: 13 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,23 @@
S3K - Simple Secure Separation Kernel
s3k - Simple Secure Separation Kernel
=====================================

S3K is a capability-based separation kernel targetting embedded RISC-V systems.
s3k is a separation kernel targetting embedded RISC-V systems.

Documentation
-------------

| Page | Description |
| --- | --- |
| [Home](https://github.com/kth-step/s3k/wiki) | Documentation Index |
| [S3K Design](https://github.com/kth-step/s3k/wiki/S3K-Design) | High-level design of S3K |
| [S3K Implementation](https://github.com/kth-step/s3k/wiki/S3K-Implementation) | Description of S3K implementation |
| [S3K API](https://github.com/kth-step/s3k/wiki/S3K-API) | User-level Kernel API |

More documenation will be added.
- [Documentation Index](https://github.com/kth-step/s3k/wiki)
- [S3K Design](https://github.com/kth-step/s3k/wiki/S3K-Design)
- [S3K API](https://github.com/kth-step/s3k/wiki/S3K-API)

Configuration
-------------

Set your compiler toolchain in `tools.mk`. By default we have the following:
```
CC =riscv64-unknown-elf-gcc
AR =riscv64-unknown-elf-ar
LD =riscv64-unknown-elf-ld
SIZE =riscv64-unknown-elf-size
OBJDUMP =riscv64-unknown-elf-objdump
OBJCOPY =riscv64-unknown-elf-objcopy
CC=riscv64-unknown-elf-gcc
AR=riscv64-unknown-elf-ar
LD=riscv64-unknown-elf-ld
SIZE=riscv64-unknown-elf-size
OBJDUMP=riscv64-unknown-elf-objdump
OBJCOPY=riscv64-unknown-elf-objcopy
```

Build and Run
Expand Down Expand Up @@ -81,5 +73,7 @@ Repository structure
- hello - Hello, world example with two processes
- ping-ping - IPC example
- trapped - Trap handling example
- wcet - deprecated project (for now)
- API.md - Kernel API
- LICENSE - MIT License file
- tools.mk - Set the compiler tools here
58 changes: 50 additions & 8 deletions common/Makefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,57 @@
.POSIX:
.SECONDARY:

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

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

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

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

.PHONY: all clean
64 changes: 0 additions & 64 deletions common/build.mk

This file was deleted.

5 changes: 0 additions & 5 deletions common/inc/altc/altio.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
#pragma once
#include <stdarg.h>
#include <stddef.h>

int alt_getchar(void);
int alt_putchar(char c);
int alt_putstr(const char *str);
int alt_puts(const char *str);
int alt_gets(char *str);
int alt_printf(const char *fmt, ...);
int alt_snprintf(char *restrict s, size_t n, const char *restrict fmt, ...);
int alt_vsnprintf(char *restrict s, size_t n, const char *restrict fmt,
va_list ap);
17 changes: 17 additions & 0 deletions common/inc/altc/memchr.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.globl memchr
.type memchr,@function

.section .text.libaltc

// void *memchr(const void *s, int c, size_t n);
memchr:
beqz a2,2f // if (n == 0) goto exit1;
add a2,a2,a0 // char *a2 = s + n;
andi a1,a1,0xFF // c = c & 0xFF;
// do {
1: lb t0,(a0) // t0 = *s;
addi a0,a0,1 // ++s;
beq t0,a1,3f // if (t0 == c) goto exit2;
bne a0,a1,1b // } while (s != a2);
2: li a0,0 // exit1: return NULL;
3: ret // exit2: return s;
20 changes: 20 additions & 0 deletions common/inc/altc/memcmp.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.globl memcmp
.type memcmp,@function

.section .text.libaltc

// int memcmp(const void *s1, const void *s2, size_t n);
memcmp:
beqz a2,2f // if (n == 0) goto eq;
add a2,a2,a0 // char *a2 = s + n;
// do {
1: lb t0,(a0) // char t0 = *s1;
lb t1,(a1) // char t1 = *s2;
addi a0,a0,1 // ++s1;
addi a1,a1,1 // ++s2;
bne t0,t1,3f // if (t0 != t1) goto neq;
bne a0,a2,1b // } while (s1 != a2);
2: li a0,1 // eq: return 1;
ret
3: li a0,0 // neq: return 0;
ret
17 changes: 17 additions & 0 deletions common/inc/altc/memcpy.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.globl memcpy
.type memcpy,@function

.section .text.libaltc

// void *memcpy(void *dst, const void *src, size_t n);
memcpy:
beqz a2,2f // if (n == 0) goto exit;
mv t0,a0 // t0 = dst;
add a2,a2,a0 // a2 = dst + n;
// do {
1: lb t1,(a1) // t1 = *src;
addi a1,a1,1 // ++src;
addi t0,t0,1 // ++t0;
sb t1,-1(t0) // *(t0-1) = t1;
bne t0,a2,1b // } while (t0 != a2);
2: ret // exit: return dst;
19 changes: 19 additions & 0 deletions common/inc/altc/memmove.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
.globl memmove
.type memmove,@function

.section .text.libaltc

// void *memmove(void *dst, const void *src, size_t n);
memmove:
beq a0,a1,2f // if (dst == src) goto exit;
beqz a2,2f // if (n == 0) goto exit;
bltu a0,a1,memcpy // if (dst < src) memcpy(dst, src, n);
add a2,a2,a0 // a2 = dst + n;
add a1,a1,a0 // src = src + n;
// do {
1: lb t1,(a1) // t1 = *src;
addi a1,a1,-1 // --src;
addi a2,a2,-1 // --a2;
sb t1,1(a2) // *(a2+1) = t1;
bne a2,a0,1b // } while (a2 != dst);
2: ret // exit: return dst
15 changes: 15 additions & 0 deletions common/inc/altc/memset.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.globl memset
.type memset,@function

.section .text.libaltc

// void *memset(void *s, int c, size_t n);
memset:
beqz a2,2f // if (n == 0) goto exit;
mv t0,a0 // char *t0 = s;
add a2,a2,a0 // char *a2 = s + n;
// do {
1: sb a1,(t0) // *t0 = c;
addi t0,t0,1 // ++t0;
bne t0,a2,1b // } while (t0 != a2);
2: ret // exit: return s;
8 changes: 0 additions & 8 deletions common/inc/plat/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,8 @@

#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
7 changes: 5 additions & 2 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 0
#define S3K_MAX_HART 3

// Total number of usable harts.
#define S3K_HART_CNT (S3K_MAX_HART - S3K_MIN_HART + 1ul)
Expand All @@ -28,10 +28,13 @@
#define INIT_CAPS \
{ \
[0] = cap_mk_pmp(0x20005fff, MEM_RWX), \
[1] = cap_mk_memory(0x80020000, 0x88000000, MEM_RWX), \
[1] = cap_mk_memory(0x80020000, 0x80100000, 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), \
}
Loading
Loading