-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from Azure-stars/main
Parse ELF files and add monolithic testcases for CI
- Loading branch information
Showing
77 changed files
with
3,009 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
name: Download musl toolchain | ||
|
||
inputs: | ||
arch: | ||
description: 'Architecture' | ||
required: true | ||
type: string | ||
|
||
runs: | ||
using: "composite" | ||
steps: | ||
- name: Cache musl | ||
id: cache-musl | ||
uses: actions/cache/restore@v3 | ||
with: | ||
path: ${{ inputs.arch }}-linux-musl-cross | ||
key: ${{ inputs.arch }}-linux-musl-cross | ||
- name: Download musl toolchain | ||
if: steps.cache-musl.outputs.cache-hit != 'true' | ||
shell: bash | ||
run: | | ||
MUSL_PATH=${{ inputs.arch }}-linux-musl-cross | ||
wget https://musl.cc/${MUSL_PATH}.tgz | ||
tar -xf ${MUSL_PATH}.tgz | ||
- uses: actions/cache/save@v3 | ||
if: steps.cache-musl.outputs.cache-hit != 'true' | ||
with: | ||
path: ${{ inputs.arch }}-linux-musl-cross | ||
key: ${{ inputs.arch }}-linux-musl-cross | ||
|
||
- name: Add to PATH environment variable | ||
shell: bash | ||
run: | | ||
echo "$PWD/${{ inputs.arch }}-linux-musl-cross/bin" >> $GITHUB_PATH | ||
- name: Verify installation | ||
shell: bash | ||
run: | | ||
${{ inputs.arch }}-linux-musl-gcc --version |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
name: Download and build QEMU | ||
|
||
inputs: | ||
qemu-version: | ||
description: 'QEMU version' | ||
required: true | ||
type: string | ||
|
||
runs: | ||
using: "composite" | ||
steps: | ||
- name: Cache QEMU | ||
id: cache-qemu | ||
uses: actions/cache/restore@v3 | ||
with: | ||
path: qemu_build | ||
key: qemu-${{ inputs.qemu-version }}-slirp-1 | ||
- name: Download and build QEMU | ||
if: steps.cache-qemu.outputs.cache-hit != 'true' | ||
env: | ||
QEMU_PATH: qemu-${{ inputs.qemu-version }} | ||
PREFIX: ${{ github.workspace }}/qemu_build | ||
shell: bash | ||
run: | | ||
sudo apt-get update && sudo apt-get install -y ninja-build libslirp-dev | ||
wget https://download.qemu.org/$QEMU_PATH.tar.xz && tar -xJf $QEMU_PATH.tar.xz | ||
cd $QEMU_PATH \ | ||
&& ./configure --prefix=$PREFIX --target-list=x86_64-softmmu,riscv64-softmmu,aarch64-softmmu --enable-slirp \ | ||
&& make -j > /dev/null 2>&1 \ | ||
&& make install | ||
- uses: actions/cache/save@v3 | ||
if: steps.cache-qemu.outputs.cache-hit != 'true' | ||
with: | ||
path: qemu_build | ||
key: qemu-${{ inputs.qemu-version }}-slirp-1 | ||
|
||
- name: Install QEMU | ||
shell: bash | ||
run: | | ||
echo "$PWD/qemu_build/bin" >> $GITHUB_PATH | ||
- name: Verify installation | ||
shell: bash | ||
run: | | ||
qemu-system-x86_64 --version | ||
qemu-system-aarch64 --version | ||
qemu-system-riscv64 --version |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,25 @@ | ||
AX_ROOT ?= $(PWD)/.arceos | ||
AX_TESTCASE ?= nimbos | ||
ARCH ?= x86_64 | ||
|
||
export AX_TESTCASES_LIST=$(shell cat ./apps/$(AX_TESTCASE)/testcase_list | tr '\n' ',') | ||
|
||
all: build | ||
|
||
ax_root: | ||
@./scripts/set_ax_root.sh $(AX_ROOT) | ||
|
||
build run justrun debug disasm clean: ax_root | ||
user_apps: | ||
@make -C ./apps/$(AX_TESTCASE) ARCH=$(ARCH) build | ||
|
||
test: | ||
@./scripts/app_test.sh | ||
|
||
build run justrun debug disasm: ax_root | ||
@make -C $(AX_ROOT) A=$(PWD) $@ | ||
|
||
clean: ax_root | ||
@make -C $(AX_ROOT) A=$(PWD) clean | ||
@cargo clean | ||
|
||
.PHONY: all ax_root build run justrun debug disasm clean |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
build | ||
target | ||
syscall_ids.h | ||
Cargo.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
ARCH ?= x86_64 | ||
MODE ?= release | ||
|
||
BUILD_RUST ?= y | ||
BUILD_C ?= y | ||
|
||
build_dir := build/$(ARCH) | ||
|
||
build: rust c | ||
|
||
build_dir: | ||
@mkdir -p $(build_dir) | ||
|
||
rust: build_dir | ||
ifeq ($(BUILD_RUST), y) | ||
@make -C rust/ | ||
endif | ||
|
||
c: build_dir | ||
ifeq ($(BUILD_C), y) | ||
@make -C c/ | ||
endif | ||
|
||
clean: | ||
@make -C rust/ clean | ||
@make -C c/ clean | ||
@rm -rf $(build_dir) | ||
|
||
.PHONY: build build_dir rust c clean |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
cmake_minimum_required(VERSION 3.0) | ||
|
||
project(nimbos_user) | ||
enable_language(C ASM) | ||
set(CMAKE_OSX_DEPLOYMENT_TARGET "") | ||
|
||
# Toolchain | ||
set(PREFIX ${ARCH}-linux-musl-) | ||
|
||
if (${ARCH} STREQUAL x86_64) | ||
set(CMAKE_C_FLAGS "-mno-sse") | ||
elseif (${ARCH} STREQUAL riscv32) | ||
set(CMAKE_C_FLAGS "-march=rv32imac -mabi=ilp32 -mcmodel=medany") | ||
elseif (${ARCH} STREQUAL riscv64) | ||
set(CMAKE_C_FLAGS "-march=rv64imac -mabi=lp64 -mcmodel=medany") | ||
elseif (${ARCH} STREQUAL aarch64) | ||
set(CMAKE_C_FLAGS "-mgeneral-regs-only") | ||
else() | ||
message("Unsupported arch: ${ARCH}") | ||
endif () | ||
set(CMAKE_ASM_COMPILER ${PREFIX}gcc) | ||
set(CMAKE_C_COMPILER ${PREFIX}gcc) | ||
set(CMAKE_OBJDUMP ${PREFIX}objdump) | ||
set(CMAKE_RANLIB ${PREFIX}ranlib) | ||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -static -no-pie -fno-builtin -nostdinc -fno-stack-protector -ggdb -Wall") | ||
set(CMAKE_ASM_FLAGS ${CMAKE_C_FLAGS}) | ||
set(CMAKE_C_LINK_FLAGS "${LINK_FLAGS} -nostdlib") # override default value to get rid of '-Wl,-search_paths_first -Wl,-headerpad_max_install_names' | ||
set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS) # override default value to get rid of '-rdynamic' on Linux | ||
|
||
# Path | ||
if (${ARCH} STREQUAL riscv32 OR ${ARCH} STREQUAL riscv64) | ||
set(ARCH_DIR lib/arch/riscv) | ||
else() | ||
set(ARCH_DIR lib/arch/${ARCH}) | ||
endif() | ||
|
||
set(ASM_DIR ${ARCH}/asm) | ||
set(BIN_DIR ${ARCH}/bin) | ||
|
||
# Library | ||
aux_source_directory(lib LIBS) | ||
set(LIBS ${ARCH_DIR}/crt.S ${ARCH_DIR}/clone.S ${LIBS}) | ||
add_library(ulib ${LIBS} syscall_ids) | ||
include_directories(include/) | ||
target_include_directories(ulib PRIVATE ${ARCH_DIR}) | ||
|
||
# Execuatble | ||
aux_source_directory(src SRCS) | ||
set(EXECUTABLE_OUTPUT_PATH ${BIN_DIR}) | ||
foreach(PATH ${SRCS}) | ||
get_filename_component(NAME ${PATH} NAME_WE) | ||
add_executable(${NAME} ${PATH}) | ||
target_link_libraries(${NAME} ulib) | ||
|
||
add_custom_command( | ||
TARGET ${NAME} | ||
POST_BUILD | ||
COMMAND mkdir -p ${ASM_DIR} | ||
COMMAND ${CMAKE_OBJDUMP} ARGS -d $<TARGET_FILE:${NAME}> > ${ASM_DIR}/${NAME}.asm | ||
) | ||
endforeach() | ||
|
||
add_custom_command( | ||
OUTPUT syscall_ids.h | ||
COMMAND sed ARGS -n -e s/__NR_/SYS_/p | ||
< ${CMAKE_SOURCE_DIR}/lib/syscall_ids.h.in | ||
> ${CMAKE_SOURCE_DIR}/lib/syscall_ids.h | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
ARCH ?= x86_64 | ||
MODE ?= release | ||
|
||
out_dir := ../build/$(ARCH) | ||
|
||
cmake_build_args := -DARCH=$(ARCH) | ||
ifeq ($(MODE), release) | ||
cmake_build_args += -DCMAKE_BUILD_TYPE=Release | ||
else ifeq ($(MODE), debug) | ||
cmake_build_args += -DCMAKE_BUILD_TYPE=Debug | ||
endif | ||
|
||
build: | ||
@echo Building C user app | ||
@mkdir -p build | ||
@cd build && cmake $(cmake_build_args) .. && make -j | ||
@cp build/$(ARCH)/bin/* $(out_dir) | ||
|
||
clean: | ||
@rm -rf build | ||
|
||
.PHONY: build clean |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#ifndef __ASSERT_H__ | ||
#define __ASSERT_H__ | ||
|
||
#define assert(x) ((void)((x) || (__assert_fail(#x, __FILE__, __LINE__, __func__), 0))) | ||
|
||
_Noreturn void __assert_fail(const char *, const char *, int, const char *); | ||
|
||
#endif // __ASSERT_H__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#ifndef __PTHREAD_H__ | ||
#define __PTHREAD_H__ | ||
|
||
typedef unsigned long pthread_t; | ||
|
||
int pthread_create(pthread_t *res, const void *attrp, void *(*entry)(void *), void *arg); | ||
|
||
#endif // __PTHREAD_H__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#ifndef __STDARG_H__ | ||
#define __STDARG_H__ | ||
|
||
#define va_start(v, l) __builtin_va_start(v, l) | ||
#define va_end(v) __builtin_va_end(v) | ||
#define va_arg(v, l) __builtin_va_arg(v, l) | ||
#define va_copy(d, s) __builtin_va_copy(d, s) | ||
|
||
typedef __builtin_va_list va_list; | ||
|
||
#endif // __STDARG_H__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#ifndef __STDINT_H__ | ||
#define __STDINT_H__ | ||
|
||
/* Represents true-or-false values */ | ||
#ifndef __cplusplus | ||
#define true 1 | ||
#define false 0 | ||
#define bool _Bool | ||
#endif | ||
|
||
/* Explicitly-sized versions of integer types */ | ||
typedef char int8_t; | ||
typedef unsigned char uint8_t; | ||
typedef short int16_t; | ||
typedef unsigned short uint16_t; | ||
typedef int int32_t; | ||
typedef unsigned int uint32_t; | ||
typedef long long int64_t; | ||
typedef unsigned long long uint64_t; | ||
|
||
/* * | ||
* Pointers and addresses are 32 bits long. | ||
* We use pointer types to represent addresses, | ||
* uintptr_t to represent the numerical values of addresses. | ||
* */ | ||
#if __riscv_xlen == 64 || defined(__x86_64__) || defined(__aarch64__) | ||
typedef int64_t intptr_t; | ||
typedef uint64_t uintptr_t; | ||
#elif __riscv_xlen == 32 || defined(__i386__) | ||
typedef int32_t intptr_t; | ||
typedef uint32_t uintptr_t; | ||
#endif | ||
|
||
/* size_t is used for memory object sizes */ | ||
typedef uintptr_t size_t; | ||
typedef intptr_t ssize_t; | ||
|
||
typedef int pid_t; | ||
|
||
#define NULL ((void *)0) | ||
|
||
#endif // __STDINT_H__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#ifndef __STDIO_H__ | ||
#define __STDIO_H__ | ||
|
||
#define stdin 0 | ||
#define stdout 1 | ||
#define stderr 2 | ||
|
||
int getchar(); | ||
int putchar(int); | ||
int puts(const char *s); | ||
void fprintf(int f, const char *fmt, ...); | ||
int fflush(int); | ||
|
||
#define EOF (-1) | ||
|
||
#define printf(...) fprintf(stdout, __VA_ARGS__) | ||
|
||
#endif // __STDIO_H__ |
Oops, something went wrong.