Skip to content

Commit

Permalink
Merge pull request #3 from Azure-stars/main
Browse files Browse the repository at this point in the history
Parse ELF files and add monolithic testcases for CI
  • Loading branch information
equation314 authored Aug 6, 2024
2 parents 3c8dfce + c29aee2 commit 5a2d23e
Show file tree
Hide file tree
Showing 77 changed files with 3,009 additions and 42 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/actions/setup-musl/action.yml
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
46 changes: 46 additions & 0 deletions .github/workflows/actions/setup-qemu/action.yml
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
27 changes: 27 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,30 @@ jobs:
- run: ./scripts/get_deps.sh
- name: Build for ${{ matrix.arch }}
run: make ARCH=${{ matrix.arch }}

test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
rust-toolchain: [nightly]
arch: [x86_64]
env:
qemu-version: 8.2.0
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@nightly
with:
toolchain: ${{ matrix.rust-toolchain }}
components: rust-src, llvm-tools
- uses: Swatinem/rust-cache@v2
- run: cargo install cargo-binutils
- run: ./scripts/get_deps.sh
- uses: ./.github/workflows/actions/setup-musl
with:
arch: ${{ matrix.arch }}
- uses: ./.github/workflows/actions/setup-qemu
with:
qemu-version: ${{ env.qemu-version }}
- name: Run tests
run: make test ARCH=${{ matrix.arch }}
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ log = "0.4"
linkme = "0.3"
axerrno = "0.1"
memory_addr = "0.2"
xmas-elf = "0.8"

axstd = { git = "https://github.com/arceos-org/arceos.git", features = ["paging"] }
arceos_posix_api = { git = "https://github.com/arceos-org/arceos.git" }
Expand Down
16 changes: 15 additions & 1 deletion Makefile
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
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,18 @@
[![CI](https://github.com/arceos-org/starry-next/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/arceos-org/starry-next/actions/workflows/ci.yml)

A monolithic kernel based on [ArceOS](https://github.com/arceos-org/arceos).

## Quick Start
```sh
# Clone the base repository
./scripts/get_deps.sh

# Build user applications
make user_apps

# Build kernel
make ARCH=x86_64 build

# Run kernel
make ARCH=x86_64 run
```
4 changes: 4 additions & 0 deletions apps/nimbos/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
build
target
syscall_ids.h
Cargo.lock
29 changes: 29 additions & 0 deletions apps/nimbos/Makefile
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
68 changes: 68 additions & 0 deletions apps/nimbos/c/CMakeLists.txt
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
)
22 changes: 22 additions & 0 deletions apps/nimbos/c/Makefile
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
8 changes: 8 additions & 0 deletions apps/nimbos/c/include/assert.h
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__
8 changes: 8 additions & 0 deletions apps/nimbos/c/include/pthread.h
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__
11 changes: 11 additions & 0 deletions apps/nimbos/c/include/stdarg.h
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__
42 changes: 42 additions & 0 deletions apps/nimbos/c/include/stdint.h
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__
18 changes: 18 additions & 0 deletions apps/nimbos/c/include/stdio.h
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__
Loading

0 comments on commit 5a2d23e

Please sign in to comment.