mirror of
https://github.com/AmbiML/sparrow-kata-full.git
synced 2025-07-15 15:01:45 +00:00
Merge "apps: Extract crt0 from C apps"
GitOrigin-RevId: af8b6e41c39a9d5d0b85cb5f7b66d986e1bc3cf9
This commit is contained in:
parent
13799ab779
commit
6ee08d8b47
@ -12,24 +12,8 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
SRC_LIBSEL4 ?= $(ROOTDIR)/kata/kernel/libsel4
|
APPNAME := fibonacci
|
||||||
OUT_KATA ?= $(OUT)/kata/riscv32-unknown-elf/release
|
SOURCES := fibonacci.c
|
||||||
OUT_TMP ?= $(OUT)/tmp/fibonacci
|
|
||||||
|
|
||||||
INCLUDES += -I$(SRC_LIBSEL4)/arch_include/riscv
|
LIBKATA ?= ../libkata
|
||||||
INCLUDES += -I$(SRC_LIBSEL4)/include
|
include $(LIBKATA)/make/app.mk
|
||||||
INCLUDES += -I$(SRC_LIBSEL4)/mode_include/32
|
|
||||||
INCLUDES += -I$(SRC_LIBSEL4)/sel4_arch_include/riscv32/
|
|
||||||
INCLUDES += -I$(OUT_KATA)/kernel/gen_config
|
|
||||||
INCLUDES += -I$(OUT_KATA)/libsel4/autoconf
|
|
||||||
INCLUDES += -I$(OUT_KATA)/libsel4/gen_config/
|
|
||||||
INCLUDES += -I$(OUT_KATA)/libsel4/include
|
|
||||||
INCLUDES += -I$(OUT_KATA)/libsel4/sel4_arch_include/riscv32
|
|
||||||
|
|
||||||
OPT:=-O0
|
|
||||||
DBG:=-g
|
|
||||||
|
|
||||||
$(OUT_TMP)/fibonacci.elf: fibonacci.c
|
|
||||||
mkdir -p $(OUT_TMP)
|
|
||||||
riscv32-unknown-elf-gcc $(DBG) $(OPT) $(INCLUDES) -march=rv32imac -mabi=ilp32 -std=gnu11 -c fibonacci.c -o $(OUT_TMP)/fibonacci.o
|
|
||||||
riscv32-unknown-elf-gcc $(DBG) -static -nostdlib $(OUT_TMP)/fibonacci.o -o $(OUT_TMP)/fibonacci.elf -lgcc
|
|
||||||
|
@ -10,30 +10,8 @@
|
|||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <kernel/gen_config.h>
|
#include <kata.h>
|
||||||
#include <sel4/arch/syscalls.h>
|
|
||||||
#include <stdarg.h>
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
__thread seL4_IPCBuffer *__sel4_ipc_buffer;
|
|
||||||
|
|
||||||
char minisel_tls[4096] __attribute__((__aligned__(4096)));
|
|
||||||
|
|
||||||
__attribute__((naked)) void _start() {
|
|
||||||
asm volatile(
|
|
||||||
".option push \n"
|
|
||||||
".option norelax \n"
|
|
||||||
"la gp, __global_pointer$ \n"
|
|
||||||
"la x4, minisel_tls \n"
|
|
||||||
"addi sp,sp,-16 \n"
|
|
||||||
"sw a0, 12(sp) \n"
|
|
||||||
"sw a1, 8(sp) \n"
|
|
||||||
"sw a2, 4(sp) \n"
|
|
||||||
"sw a3, 0(sp) \n"
|
|
||||||
".option pop \n"
|
|
||||||
"j main \n");
|
|
||||||
}
|
|
||||||
|
|
||||||
// How many Fibonacci numbers to write to the log.
|
// How many Fibonacci numbers to write to the log.
|
||||||
#define LOG_FIBONACCI_LIMIT 80
|
#define LOG_FIBONACCI_LIMIT 80
|
||||||
@ -42,41 +20,6 @@ __attribute__((naked)) void _start() {
|
|||||||
#define INTERRUPTS_PER_VIRT_SEC (1000 / CONFIG_TIMER_TICK_MS)
|
#define INTERRUPTS_PER_VIRT_SEC (1000 / CONFIG_TIMER_TICK_MS)
|
||||||
#define INTERRUPTS_PER_WAIT (1 * INTERRUPTS_PER_VIRT_SEC)
|
#define INTERRUPTS_PER_WAIT (1 * INTERRUPTS_PER_VIRT_SEC)
|
||||||
|
|
||||||
// only prints 32-bit "%x" hex values
|
|
||||||
void minisel_printf(const char *fmt, ...) {
|
|
||||||
#if CONFIG_PRINTING
|
|
||||||
va_list args;
|
|
||||||
va_start(args, fmt);
|
|
||||||
for (; *fmt; fmt++) {
|
|
||||||
if (*fmt == '%') {
|
|
||||||
fmt++;
|
|
||||||
if (*fmt == 'd') {
|
|
||||||
uint32_t arg = va_arg(args, uint32_t);
|
|
||||||
// TODO(sleffler): total hack
|
|
||||||
int printing = 0;
|
|
||||||
for (int d = 1000000000; d > 1; d /= 10) {
|
|
||||||
int n = (arg / d) % 10;
|
|
||||||
if (printing || n > 0) {
|
|
||||||
seL4_DebugPutChar('0' + n);
|
|
||||||
printing = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
seL4_DebugPutChar('0' + (arg % 10));
|
|
||||||
} else if (*fmt == 'x') {
|
|
||||||
uint32_t arg = va_arg(args, uint32_t);
|
|
||||||
for (int i = 7; i >= 0; i--) {
|
|
||||||
int n = (arg >> (4 * i)) & 0xF;
|
|
||||||
seL4_DebugPutChar(n > 9 ? 'A' + n - 10 : '0' + n);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
seL4_DebugPutChar(*fmt);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
va_end(args);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef uint64_t interrupt_count_t;
|
typedef uint64_t interrupt_count_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@ -134,9 +77,9 @@ void fibonacci_log(int pid, const fibonacci_state_t *fibonacci_state,
|
|||||||
"%llu; rdtime == %llu; virt_sec ~= %.2f\n",
|
"%llu; rdtime == %llu; virt_sec ~= %.2f\n",
|
||||||
fibonacci_state->n, fibonacci_state->f1, interrupt_count, rdtime(),
|
fibonacci_state->n, fibonacci_state->f1, interrupt_count, rdtime(),
|
||||||
virtual_seconds(interrupt_count));
|
virtual_seconds(interrupt_count));
|
||||||
minisel_printf(log_buf);
|
debug_printf(log_buf);
|
||||||
#else
|
#else
|
||||||
minisel_printf(
|
debug_printf(
|
||||||
"[%d]: "
|
"[%d]: "
|
||||||
"n == %d; "
|
"n == %d; "
|
||||||
"f == %x; "
|
"f == %x; "
|
||||||
@ -153,7 +96,7 @@ int main(int pid, int a1, int a2, int a3) {
|
|||||||
interrupt_count_t interrupt_count = 0;
|
interrupt_count_t interrupt_count = 0;
|
||||||
fibonacci_state_t fibonacci_state;
|
fibonacci_state_t fibonacci_state;
|
||||||
fibonacci_init(&fibonacci_state);
|
fibonacci_init(&fibonacci_state);
|
||||||
minisel_printf("\nFibonacci: pid %d\n", pid);
|
debug_printf("\nFibonacci: pid %d\n", pid);
|
||||||
while (1) {
|
while (1) {
|
||||||
wait(INTERRUPTS_PER_WAIT, &interrupt_count);
|
wait(INTERRUPTS_PER_WAIT, &interrupt_count);
|
||||||
if (fibonacci_state.n >= LOG_FIBONACCI_LIMIT) {
|
if (fibonacci_state.n >= LOG_FIBONACCI_LIMIT) {
|
||||||
|
@ -12,24 +12,8 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
SRC_LIBSEL4 ?= $(ROOTDIR)/kata/kernel/libsel4
|
APPNAME := hello
|
||||||
OUT_KATA ?= $(OUT)/kata/riscv32-unknown-elf/release
|
SOURCES := hello.c
|
||||||
OUT_TMP ?= $(OUT)/tmp/hello
|
|
||||||
|
|
||||||
INCLUDES += -I$(SRC_LIBSEL4)/arch_include/riscv
|
LIBKATA ?= ../libkata
|
||||||
INCLUDES += -I$(SRC_LIBSEL4)/include
|
include $(LIBKATA)/make/app.mk
|
||||||
INCLUDES += -I$(SRC_LIBSEL4)/mode_include/32
|
|
||||||
INCLUDES += -I$(SRC_LIBSEL4)/sel4_arch_include/riscv32/
|
|
||||||
INCLUDES += -I$(OUT_KATA)/kernel/gen_config
|
|
||||||
INCLUDES += -I$(OUT_KATA)/libsel4/autoconf
|
|
||||||
INCLUDES += -I$(OUT_KATA)/libsel4/gen_config/
|
|
||||||
INCLUDES += -I$(OUT_KATA)/libsel4/include
|
|
||||||
INCLUDES += -I$(OUT_KATA)/libsel4/sel4_arch_include/riscv32
|
|
||||||
|
|
||||||
OPT:=-O0
|
|
||||||
DBG:=-g
|
|
||||||
|
|
||||||
$(OUT_TMP)/hello.elf: hello.c
|
|
||||||
mkdir -p $(OUT_TMP)
|
|
||||||
riscv32-unknown-elf-gcc $(DBG) $(OPT) $(INCLUDES) -march=rv32imac -mabi=ilp32 -std=gnu11 -c hello.c -o $(OUT_TMP)/hello.o
|
|
||||||
riscv32-unknown-elf-gcc $(DBG) -static -nostdlib $(OUT_TMP)/hello.o -o $(OUT_TMP)/hello.elf
|
|
||||||
|
@ -9,62 +9,14 @@
|
|||||||
// using the seL4_DebugPutChar syscall and is intended as a starting
|
// using the seL4_DebugPutChar syscall and is intended as a starting
|
||||||
// point for low-level tests.
|
// point for low-level tests.
|
||||||
|
|
||||||
#include <kernel/gen_config.h>
|
#include <kata.h>
|
||||||
#include <sel4/arch/syscalls.h>
|
|
||||||
#include <stdarg.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
__thread seL4_IPCBuffer *__sel4_ipc_buffer;
|
|
||||||
|
|
||||||
char minisel_tls[4096] __attribute__((__aligned__(4096)));
|
|
||||||
|
|
||||||
__attribute__((naked)) void _start() {
|
|
||||||
asm volatile(
|
|
||||||
".option push \n"
|
|
||||||
".option norelax \n"
|
|
||||||
"la gp, __global_pointer$ \n"
|
|
||||||
"la tp, minisel_tls \n"
|
|
||||||
"lui t1,0 \n"
|
|
||||||
"add t1,t1,tp \n"
|
|
||||||
"sw a0,0(t1) # __sel4_ipc_buffer>\n"
|
|
||||||
"addi sp,sp,-16 \n"
|
|
||||||
"sw a0, 12(sp) \n"
|
|
||||||
"sw a1, 8(sp) \n"
|
|
||||||
"sw a2, 4(sp) \n"
|
|
||||||
"sw a3, 0(sp) \n"
|
|
||||||
".option pop \n"
|
|
||||||
"j main \n");
|
|
||||||
}
|
|
||||||
|
|
||||||
// only prints 32-bit "%x" hex values
|
|
||||||
void minisel_printf(const char *fmt, ...) {
|
|
||||||
#if CONFIG_PRINTING
|
|
||||||
va_list args;
|
|
||||||
va_start(args, fmt);
|
|
||||||
for (; *fmt; fmt++) {
|
|
||||||
if (*fmt == '%') {
|
|
||||||
fmt++;
|
|
||||||
if (*fmt == 'x') {
|
|
||||||
uint32_t arg = va_arg(args, uint32_t);
|
|
||||||
for (int i = 7; i >= 0; i--) {
|
|
||||||
int n = (arg >> (4 * i)) & 0xF;
|
|
||||||
seL4_DebugPutChar(n > 9 ? 'A' + n - 10 : '0' + n);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
seL4_DebugPutChar(*fmt);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
va_end(args);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int a0, int a1, int a2, int a3) {
|
int main(int a0, int a1, int a2, int a3) {
|
||||||
minisel_printf("\nI am a C app!\n");
|
debug_printf("\nI am a C app!\n");
|
||||||
minisel_printf("a0 %x a1 %x a2 %x a3 %x\n", a0, a1, a2, a3);
|
debug_printf("a0 %x a1 %x a2 %x a3 %x\n", a0, a1, a2, a3);
|
||||||
minisel_printf("__sel4_ipc_buffer %x\n", __sel4_ipc_buffer);
|
debug_printf("__sel4_ipc_buffer %x\n", __sel4_ipc_buffer);
|
||||||
|
|
||||||
minisel_printf("Done, sleeping in WFI loop\n");
|
debug_printf("Done, sleeping in WFI loop\n");
|
||||||
while (1) {
|
while (1) {
|
||||||
asm("wfi");
|
asm("wfi");
|
||||||
}
|
}
|
||||||
|
61
apps/c/libkata/Makefile
Normal file
61
apps/c/libkata/Makefile
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
# Copyright 2022 Google LLC
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
|
||||||
|
include make/common.mk
|
||||||
|
include arch/$(BUILD_ARCH)/arch.mk
|
||||||
|
|
||||||
|
INCLUDES += -Iinclude
|
||||||
|
|
||||||
|
SRC_FILES += \
|
||||||
|
printf.c \
|
||||||
|
globals.c
|
||||||
|
|
||||||
|
INCLUDE_FILES := \
|
||||||
|
include/kata.h
|
||||||
|
|
||||||
|
BUILD_DIR := $(BUILD_ROOT)/libkata
|
||||||
|
BUILD_ARCH_DIR := $(BUILD_DIR)/arch/$(BUILD_ARCH)
|
||||||
|
|
||||||
|
OBJ_FILES := $(patsubst arch/$(BUILD_ARCH)/%.S,$(BUILD_ARCH_DIR)/%.o,$(SRC_FILES))
|
||||||
|
OBJ_FILES := $(patsubst %.c,$(BUILD_DIR)/%.o,$(OBJ_FILES))
|
||||||
|
|
||||||
|
## Build Rules ###########################################
|
||||||
|
|
||||||
|
$(BUILD_DIR)/libkata.a: $(BUILD_DIR) $(OBJ_FILES) includes
|
||||||
|
$(AR) rcs $@ $(OBJ_FILES)
|
||||||
|
|
||||||
|
includes: $(INCLUDE_FILES)
|
||||||
|
mkdir -p $(BUILD_DIR)/include
|
||||||
|
cp $(INCLUDE_FILES) $(BUILD_DIR)/include
|
||||||
|
|
||||||
|
$(BUILD_DIR)/%.o: %.c
|
||||||
|
$(CC) $(CFLAGS) -Iinclude -c -o $@ $<
|
||||||
|
|
||||||
|
$(BUILD_DIR)/%.o: %.S
|
||||||
|
$(AS) $(ASFLAGS) -o $@ $<
|
||||||
|
|
||||||
|
$(BUILD_ARCH_DIR)/%.o: %.c
|
||||||
|
$(CC) $(CFLAGS) -Iinclude -c -o $@ $<
|
||||||
|
|
||||||
|
$(BUILD_ARCH_DIR)/%.o: %.S
|
||||||
|
$(AS) $(ASFLAGS) -o $@ $<
|
||||||
|
|
||||||
|
$(BUILD_DIR):
|
||||||
|
mkdir -p $(BUILD_DIR)
|
||||||
|
mkdir -p $(BUILD_ARCH_DIR)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -rf $(BUILD_DIR)
|
||||||
|
|
||||||
|
.PHONY: clean includes
|
15
apps/c/libkata/arch/riscv32/arch.mk
Normal file
15
apps/c/libkata/arch/riscv32/arch.mk
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
# Copyright 2022 Google LLC
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
|
||||||
|
SRC_FILES += arch/riscv32/crt0.S
|
50
apps/c/libkata/arch/riscv32/crt0.S
Normal file
50
apps/c/libkata/arch/riscv32/crt0.S
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022 Google LLC
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
.section .text._start
|
||||||
|
.align 2
|
||||||
|
.globl _start
|
||||||
|
.type _start, @function
|
||||||
|
_start:
|
||||||
|
.option push
|
||||||
|
.option norelax
|
||||||
|
|
||||||
|
la gp, __global_pointer$
|
||||||
|
la x4, _tls
|
||||||
|
|
||||||
|
/* Setup __sel4_ipc_buffer */
|
||||||
|
lui t1, 0
|
||||||
|
add t1, t1, tp
|
||||||
|
sw a0, 0(t1)
|
||||||
|
|
||||||
|
addi sp, sp, -16
|
||||||
|
sw a0, 12(sp)
|
||||||
|
sw a1, 8(sp)
|
||||||
|
sw a2, 4(sp)
|
||||||
|
sw a3, 0(sp)
|
||||||
|
|
||||||
|
.option pop
|
||||||
|
|
||||||
|
j main
|
||||||
|
|
||||||
|
.bss
|
||||||
|
|
||||||
|
.section .bss
|
||||||
|
.align 12
|
||||||
|
.globl _tls
|
||||||
|
.type _tls, tls_object
|
||||||
|
_tls:
|
||||||
|
.ds 4096
|
19
apps/c/libkata/globals.c
Normal file
19
apps/c/libkata/globals.c
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
// Copyright 2022 Google LLC
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
#include <kata.h>
|
||||||
|
#include <kernel/gen_config.h>
|
||||||
|
#include <sel4/arch/syscalls.h>
|
||||||
|
|
||||||
|
__thread seL4_IPCBuffer *__sel4_ipc_buffer;
|
38
apps/c/libkata/include/kata.h
Normal file
38
apps/c/libkata/include/kata.h
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
// Copyright 2022 Google LLC
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
// NOLINT(build/header_guard)
|
||||||
|
#ifndef KATA_H
|
||||||
|
#define KATA_H
|
||||||
|
|
||||||
|
#include <kernel/gen_config.h>
|
||||||
|
#include <sel4/arch/syscalls.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
|
||||||
|
extern __thread seL4_IPCBuffer *__sel4_ipc_buffer;
|
||||||
|
|
||||||
|
#ifdef CONFIG_PRINTING
|
||||||
|
extern void _debug_printf(const char *fmt, ...);
|
||||||
|
#define debug_printf(args...) \
|
||||||
|
do { \
|
||||||
|
_debug_printf(args); \
|
||||||
|
} while (0)
|
||||||
|
#else
|
||||||
|
#define debug_printf(args...) \
|
||||||
|
do { \
|
||||||
|
} while (0)
|
||||||
|
#warning Apps will not log to console because CONFIG_PRINTING is not defined!
|
||||||
|
#endif // CONFIG_PRINTING
|
||||||
|
|
||||||
|
#endif // KATA_H
|
40
apps/c/libkata/make/app.mk
Normal file
40
apps/c/libkata/make/app.mk
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
# Copyright 2022 Google LLC
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
|
||||||
|
MYDIR := $(dir $(realpath $(lastword $(MAKEFILE_LIST))))
|
||||||
|
|
||||||
|
include $(MYDIR)/common.mk
|
||||||
|
include $(MYDIR)/libkata.mk
|
||||||
|
|
||||||
|
BUILD_DIR := $(BUILD_ROOT)/$(APPNAME)
|
||||||
|
INTERMEDIATES := $(patsubst %.c,$(BUILD_DIR)/build/%.o,$(SOURCES))
|
||||||
|
|
||||||
|
$(BUILD_DIR)/$(APPNAME).elf: $(INTERMEDIATES) $(BUILD_ROOT)/libkata/libkata.a | $(BUILD_DIR)
|
||||||
|
$(LD) $(LDFLAGS) -o $(BUILD_DIR)/$(APPNAME).elf $(INTERMEDIATES) $(LIBKATA_LIBS) -lgcc
|
||||||
|
|
||||||
|
$(BUILD_DIR)/build/%.o: %.c $(BUILD_ROOT)/libkata/libkata.a | $(BUILD_DIR)
|
||||||
|
$(CC) $(CFLAGS) $(LIBKATA_INCLUDES) -c -o $@ $<
|
||||||
|
|
||||||
|
$(BUILD_DIR):
|
||||||
|
mkdir -p $(BUILD_DIR)/build
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -rf $(BUILD_DIR)
|
||||||
|
|
||||||
|
.PHONY: clean
|
||||||
|
|
||||||
|
## libkata build linkage
|
||||||
|
|
||||||
|
$(BUILD_ROOT)/libkata/libkata.a:
|
||||||
|
make -C $(MYDIR)/..
|
20
apps/c/libkata/make/arch/riscv32.mk
Normal file
20
apps/c/libkata/make/arch/riscv32.mk
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
# Copyright 2022 Google LLC
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
|
||||||
|
BASE_ARCH_NAME := riscv
|
||||||
|
ARCH_BITS := 32
|
||||||
|
FULL_ARCH_NAME := riscv32
|
||||||
|
ARCH_PREFIX := riscv32-unknown-elf
|
||||||
|
ARCH := rv32imac
|
||||||
|
ABI := ilp32
|
45
apps/c/libkata/make/common.mk
Normal file
45
apps/c/libkata/make/common.mk
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
# Copyright 2022 Google LLC
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
|
||||||
|
MYDIR := $(dir $(realpath $(lastword $(MAKEFILE_LIST))))
|
||||||
|
|
||||||
|
BUILD_TYPE ?= debug
|
||||||
|
BUILD_ARCH ?= riscv32
|
||||||
|
|
||||||
|
include $(MYDIR)/arch/$(BUILD_ARCH).mk
|
||||||
|
include $(MYDIR)/sel4.mk
|
||||||
|
|
||||||
|
ifeq ($(BUILD_TYPE),debug)
|
||||||
|
DEBUG := -g
|
||||||
|
OPT := -O0
|
||||||
|
else
|
||||||
|
DEBUG :=
|
||||||
|
OPT := -O0 # TODO(jtgans): Actually optimize in a release build
|
||||||
|
endif
|
||||||
|
|
||||||
|
ROOTDIR ?= $(MYDIR)
|
||||||
|
BUILD_ROOT ?= $(ROOTDIR)/out/kata/$(ARCH_PREFIX)/$(BUILD_TYPE)/apps
|
||||||
|
|
||||||
|
CC := $(ARCH_PREFIX)-gcc
|
||||||
|
AS := $(ARCH_PREFIX)-as
|
||||||
|
AR := $(ARCH_PREFIX)-ar
|
||||||
|
LD := $(ARCH_PREFIX)-gcc
|
||||||
|
|
||||||
|
CFLAGS := $(DEBUG) $(OPT) $(INCLUDES)
|
||||||
|
CFLAGS += -march=$(ARCH) -mabi=$(ABI)
|
||||||
|
CFLAGS += -std=gnu11 -nostdlib
|
||||||
|
CFLAGS += -ftls-model=local-exec
|
||||||
|
|
||||||
|
ASFLAGS := -march=$(ARCH) -mabi=$(ABI)
|
||||||
|
LDFLAGS := $(DEBUG) -nostartfiles -static -nostdlib
|
17
apps/c/libkata/make/libkata.mk
Normal file
17
apps/c/libkata/make/libkata.mk
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
# Copyright 2022 Google LLC
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
|
||||||
|
LIBKATA_DIR := $(BUILD_ROOT)/libkata
|
||||||
|
LIBKATA_INCLUDES := -I$(LIBKATA_DIR)/include
|
||||||
|
LIBKATA_LIBS := -L$(LIBKATA_DIR) -lkata
|
26
apps/c/libkata/make/sel4.mk
Normal file
26
apps/c/libkata/make/sel4.mk
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
# Copyright 2022 Google LLC
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
|
||||||
|
LIBSEL4_SRC ?= $(ROOTDIR)/kata/kernel/libsel4
|
||||||
|
OUT_KATA ?= $(OUT)/kata/$(ARCH_PREFIX)/$(BUILD_TYPE)
|
||||||
|
|
||||||
|
INCLUDES += -I$(LIBSEL4_SRC)/arch_include/$(BASE_ARCH_NAME)
|
||||||
|
INCLUDES += -I$(LIBSEL4_SRC)/include
|
||||||
|
INCLUDES += -I$(LIBSEL4_SRC)/mode_include/$(ARCH_BITS)
|
||||||
|
INCLUDES += -I$(LIBSEL4_SRC)/sel4_arch_include/$(FULL_ARCH_NAME)
|
||||||
|
INCLUDES += -I$(OUT_KATA)/kernel/gen_config
|
||||||
|
INCLUDES += -I$(OUT_KATA)/libsel4/autoconf
|
||||||
|
INCLUDES += -I$(OUT_KATA)/libsel4/gen_config/
|
||||||
|
INCLUDES += -I$(OUT_KATA)/libsel4/include
|
||||||
|
INCLUDES += -I$(OUT_KATA)/libsel4/sel4_arch_include/$(FULL_ARCH_NAME)
|
53
apps/c/libkata/printf.c
Normal file
53
apps/c/libkata/printf.c
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
// Copyright 2022 Google LLC
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
#include <kata.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#ifdef CONFIG_PRINTING
|
||||||
|
// only prints 32-bit "%x" hex values
|
||||||
|
void _debug_printf(const char *fmt, ...) {
|
||||||
|
va_list args;
|
||||||
|
va_start(args, fmt);
|
||||||
|
for (; *fmt; fmt++) {
|
||||||
|
if (*fmt == '%') {
|
||||||
|
fmt++;
|
||||||
|
if (*fmt == 'd') {
|
||||||
|
uint32_t arg = va_arg(args, uint32_t);
|
||||||
|
// TODO(sleffler): total hack
|
||||||
|
int printing = 0;
|
||||||
|
for (int d = 1000000000; d > 1; d /= 10) {
|
||||||
|
int n = (arg / d) % 10;
|
||||||
|
if (printing || n > 0) {
|
||||||
|
seL4_DebugPutChar('0' + n);
|
||||||
|
printing = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
seL4_DebugPutChar('0' + (arg % 10));
|
||||||
|
} else if (*fmt == 'x') {
|
||||||
|
uint32_t arg = va_arg(args, uint32_t);
|
||||||
|
for (int i = 7; i >= 0; i--) {
|
||||||
|
int n = (arg >> (4 * i)) & 0xF;
|
||||||
|
seL4_DebugPutChar(n > 9 ? 'A' + n - 10 : '0' + n);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
seL4_DebugPutChar(*fmt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
va_end(args);
|
||||||
|
}
|
||||||
|
#endif // CONFIG_PRINTING
|
@ -12,24 +12,8 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
SRC_LIBSEL4 ?= $(ROOTDIR)/kata/kernel/libsel4
|
APPNAME := suicide
|
||||||
OUT_KATA ?= $(OUT)/kata/riscv32-unknown-elf/release
|
SOURCES := suicide.c
|
||||||
OUT_TMP ?= $(OUT)/tmp/suicide
|
|
||||||
|
|
||||||
INCLUDES += -I$(SRC_LIBSEL4)/arch_include/riscv
|
LIBKATA ?= ../libkata
|
||||||
INCLUDES += -I$(SRC_LIBSEL4)/include
|
include $(LIBKATA)/make/app.mk
|
||||||
INCLUDES += -I$(SRC_LIBSEL4)/mode_include/32
|
|
||||||
INCLUDES += -I$(SRC_LIBSEL4)/sel4_arch_include/riscv32/
|
|
||||||
INCLUDES += -I$(OUT_KATA)/kernel/gen_config
|
|
||||||
INCLUDES += -I$(OUT_KATA)/libsel4/autoconf
|
|
||||||
INCLUDES += -I$(OUT_KATA)/libsel4/gen_config/
|
|
||||||
INCLUDES += -I$(OUT_KATA)/libsel4/include
|
|
||||||
INCLUDES += -I$(OUT_KATA)/libsel4/sel4_arch_include/riscv32
|
|
||||||
|
|
||||||
OPT:=-O0
|
|
||||||
DBG:=-g
|
|
||||||
|
|
||||||
$(OUT_TMP)/suicide.elf: suicide.c
|
|
||||||
mkdir -p $(OUT_TMP)
|
|
||||||
riscv32-unknown-elf-gcc $(DBG) $(OPT) $(INCLUDES) -march=rv32imac -mabi=ilp32 -std=gnu11 -c suicide.c -o $(OUT_TMP)/suicide.o
|
|
||||||
riscv32-unknown-elf-gcc $(DBG) -static -nostdlib $(OUT_TMP)/suicide.o -o $(OUT_TMP)/suicide.elf
|
|
||||||
|
@ -8,34 +8,11 @@
|
|||||||
// derefrences a null pointer to kill itself. It's primary use case is to test
|
// derefrences a null pointer to kill itself. It's primary use case is to test
|
||||||
// out KataOS' fault handlers.
|
// out KataOS' fault handlers.
|
||||||
|
|
||||||
#include <kernel/gen_config.h>
|
#include <kata.h>
|
||||||
#include <sel4/arch/syscalls.h>
|
|
||||||
#include <stdarg.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
__thread seL4_IPCBuffer *__sel4_ipc_buffer;
|
|
||||||
|
|
||||||
char minisel_tls[4096] __attribute__((__aligned__(4096)));
|
|
||||||
|
|
||||||
__attribute__((naked)) void _start() {
|
|
||||||
asm volatile(
|
|
||||||
".option push \n"
|
|
||||||
".option norelax \n"
|
|
||||||
"la gp, __global_pointer$ \n"
|
|
||||||
"la x4, minisel_tls \n"
|
|
||||||
"addi sp,sp,-16 \n"
|
|
||||||
"sw a0, 12(sp) \n"
|
|
||||||
"sw a1, 8(sp) \n"
|
|
||||||
"sw a2, 4(sp) \n"
|
|
||||||
"sw a3, 0(sp) \n"
|
|
||||||
".option pop \n"
|
|
||||||
"j main \n");
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int a0, int a1, int a2, int a3) {
|
int main(int a0, int a1, int a2, int a3) {
|
||||||
#if CONFIG_PRINTING
|
debug_printf("Goodbye, cruel world!\n");
|
||||||
seL4_DebugPutString("Goodbye, cruel world!\n");
|
|
||||||
#endif
|
|
||||||
while (1) {
|
while (1) {
|
||||||
char *p = 0x0;
|
char *p = 0x0;
|
||||||
*p = 'g';
|
*p = 'g';
|
||||||
|
Loading…
Reference in New Issue
Block a user