From 9d41ac2f7b54a33298372bf5873eb15973da4f09 Mon Sep 17 00:00:00 2001 From: xinyangli Date: Tue, 9 Jul 2024 17:42:46 +0800 Subject: [PATCH 1/9] build: add more tests to build system --- .gitignore | 2 +- CMakeLists.txt | 17 +++++++------- benchmarks/microbench/CMakeLists.txt | 3 +++ benchmarks/microbench/src/CMakeLists.txt | 23 +++++++++++++++++++ kernels/CMakeLists.txt | 2 ++ kernels/demo/CMakeLists.txt | 1 + kernels/demo/include/io.h | 2 +- kernels/demo/src/CMakeLists.txt | 20 ++++++++++++++++ kernels/hello/CMakeLists.txt | 14 ++++++++++++ tests/alu-tests/CMakeLists.txt | 29 ++++++++++++++++++++++++ tests/alu-tests/gen_alu_test.c | 2 +- tests/cpu-tests/tests/CMakeLists.txt | 9 +++----- 12 files changed, 107 insertions(+), 17 deletions(-) create mode 100644 benchmarks/microbench/CMakeLists.txt create mode 100644 benchmarks/microbench/src/CMakeLists.txt create mode 100644 kernels/CMakeLists.txt create mode 100644 kernels/demo/CMakeLists.txt create mode 100644 kernels/demo/src/CMakeLists.txt create mode 100644 kernels/hello/CMakeLists.txt create mode 100644 tests/alu-tests/CMakeLists.txt diff --git a/.gitignore b/.gitignore index 5170a12..fe30a49 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ -* !*/ !*.h !*.c @@ -13,3 +12,4 @@ _* *~ build/ !.gitignore +out/ diff --git a/CMakeLists.txt b/CMakeLists.txt index 61f185a..78d91c9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,14 +3,15 @@ cmake_minimum_required(VERSION 3.22) project(am-kernels) set(CMAKE_C_STANDARD 11) enable_language(C ASM) - include(CheckPIESupported) +include(GNUInstallDirs) + +find_package(am-${ARCH}) +find_package(klib) + check_pie_supported() -if(${PLATFORM} MATCHES "native") -set(ARCH "native") -else() -set(ARCH ${ISA}-${PLATFORM}) -endif() - -add_subdirectory(tests/cpu-tests) \ No newline at end of file +add_subdirectory(tests/cpu-tests) +# add_subdirectory(tests/alu-tests) +add_subdirectory(benchmarks/microbench) +add_subdirectory(kernels) diff --git a/benchmarks/microbench/CMakeLists.txt b/benchmarks/microbench/CMakeLists.txt new file mode 100644 index 0000000..0b2b255 --- /dev/null +++ b/benchmarks/microbench/CMakeLists.txt @@ -0,0 +1,3 @@ +include_directories(include) + +add_subdirectory(src) diff --git a/benchmarks/microbench/src/CMakeLists.txt b/benchmarks/microbench/src/CMakeLists.txt new file mode 100644 index 0000000..349cc5c --- /dev/null +++ b/benchmarks/microbench/src/CMakeLists.txt @@ -0,0 +1,23 @@ +add_executable(bench + qsort/qsort.c + ssort/ssort.cc + queen/queen.c + sieve/sieve.c + bf/bf.c + 15pz/15pz.cc + dinic/dinic.cc + lzip/lzip.c + lzip/quicklz.c + md5/md5.c + bench.c + fib/fib.c +) + +target_link_libraries(bench am-${ARCH} klib npcgcc) + +# -- Extract binary file from ELF +add_custom_command(TARGET bench + COMMAND ${CMAKE_OBJCOPY} ARGS -S --set-section-flags .bss=alloc,contents -O binary bench bench.bin) + +install(TARGETS bench RUNTIME DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/am-kernels) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/bench.bin DESTINATION ${CMAKE_INSTALL_DATADIR}/am-kernels) diff --git a/kernels/CMakeLists.txt b/kernels/CMakeLists.txt new file mode 100644 index 0000000..aed5366 --- /dev/null +++ b/kernels/CMakeLists.txt @@ -0,0 +1,2 @@ +add_subdirectory(hello) +add_subdirectory(demo) diff --git a/kernels/demo/CMakeLists.txt b/kernels/demo/CMakeLists.txt new file mode 100644 index 0000000..febd4f0 --- /dev/null +++ b/kernels/demo/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(src) diff --git a/kernels/demo/include/io.h b/kernels/demo/include/io.h index 9ed6b50..b2c7c61 100644 --- a/kernels/demo/include/io.h +++ b/kernels/demo/include/io.h @@ -1,6 +1,6 @@ #ifndef __DRAW_H__ -#define HAS_GUI +// #define HAS_GUI #include #include diff --git a/kernels/demo/src/CMakeLists.txt b/kernels/demo/src/CMakeLists.txt new file mode 100644 index 0000000..b58503b --- /dev/null +++ b/kernels/demo/src/CMakeLists.txt @@ -0,0 +1,20 @@ +add_executable(demo + aclock/aclock.c + ant/ant.c + bf/bf.c + cmatrix/cmatrix.c + donut/donut.c + galton/galton.c + hanoi/hanoi.c + life/life.c + main.c +) +target_include_directories(demo PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../include) +target_link_libraries(demo PRIVATE am-${ARCH} klib npcgcc) + +# -- Extract binary file from ELF +add_custom_command(TARGET demo + COMMAND ${CMAKE_OBJCOPY} ARGS -S --set-section-flags .bss=alloc,contents -O binary demo demo.bin) + +install(TARGETS demo RUNTIME DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/am-kernels) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/demo.bin DESTINATION ${CMAKE_INSTALL_DATADIR}/am-kernels) diff --git a/kernels/hello/CMakeLists.txt b/kernels/hello/CMakeLists.txt new file mode 100644 index 0000000..0afa490 --- /dev/null +++ b/kernels/hello/CMakeLists.txt @@ -0,0 +1,14 @@ +add_executable(hello + hello.c +) +target_include_directories(hello PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../include) +target_link_libraries(hello PRIVATE am-${ARCH} klib npcgcc) +target_compile_options(hello PRIVATE -nostdlib -nodefaultlibs) +target_link_options(hello PRIVATE -nostdlib -nodefaultlibs) + +# -- Extract binary file from ELF +add_custom_command(TARGET hello + COMMAND ${CMAKE_OBJCOPY} ARGS -S --set-section-flags .bss=alloc,contents -O binary hello hello.bin) + +install(TARGETS hello RUNTIME DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/am-kernels) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/hello.bin DESTINATION ${CMAKE_INSTALL_DATADIR}/am-kernels) diff --git a/tests/alu-tests/CMakeLists.txt b/tests/alu-tests/CMakeLists.txt new file mode 100644 index 0000000..4fb0bd4 --- /dev/null +++ b/tests/alu-tests/CMakeLists.txt @@ -0,0 +1,29 @@ +# TODO: CMake does not support multiple toolchain in one run. We need a seperate +# project for native binary compilation + +# cmake_minimum_required(VERSION 3.22) + +# project(alu-tests) +# set(CMAKE_C_STANDARD 11) +# enable_language(C ASM) +# include(GNUInstallDirs) + +# add_executable(gen_alu_test gen_alu_test.c) + +# add_custom_command(TARGET gen_alu_test POST_BUILD +# BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/alu_test.c +# COMMAND $ > alu_test.c) + +add_executable(alu_test alu_test.c) + +target_include_directories(alu_test PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../include) +target_link_libraries(alu_test PRIVATE am-${ARCH} klib npcgcc) +target_compile_options(alu_test PRIVATE -nostdlib -nodefaultlibs) +target_link_options(alu_test PRIVATE -nostdlib -nodefaultlibs) + +# -- Extract binary file from ELF +add_custom_command(TARGET alu_test + COMMAND ${CMAKE_OBJCOPY} ARGS -S --set-section-flags .bss=alloc,contents -O binary alu_test alu_test.bin) + +install(TARGETS alu_test RUNTIME DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/am-kernels) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/alu_test.bin DESTINATION ${CMAKE_INSTALL_DATADIR}/am-kernels) diff --git a/tests/alu-tests/gen_alu_test.c b/tests/alu-tests/gen_alu_test.c index 9ae5009..5e16e56 100644 --- a/tests/alu-tests/gen_alu_test.c +++ b/tests/alu-tests/gen_alu_test.c @@ -114,7 +114,7 @@ int exclude(type t, char* op, int x, int y) int main(void) { printf("#include \n"); - printf("int main(void) {\n"); + printf("int main(const char *) {\n"); printf(" int exit_code = 0;\n"); FOR_SET_ALL(signed int, vsi); diff --git a/tests/cpu-tests/tests/CMakeLists.txt b/tests/cpu-tests/tests/CMakeLists.txt index 3e1bb7a..c03254b 100644 --- a/tests/cpu-tests/tests/CMakeLists.txt +++ b/tests/cpu-tests/tests/CMakeLists.txt @@ -1,6 +1,3 @@ -find_package(am-${ARCH}) -find_package(klib) - set(SOURCES add.c add-longlong.c @@ -42,12 +39,12 @@ foreach(SOURCE IN LISTS SOURCES) get_filename_component(SOURCE_NAME ${SOURCE} NAME_WLE) add_executable(${SOURCE_NAME} ${SOURCE}) - target_link_libraries(${SOURCE_NAME} PRIVATE am-${ARCH}) + target_link_libraries(${SOURCE_NAME} PRIVATE am-${ARCH} klib) # -- Extract binary file from ELF add_custom_command(TARGET ${SOURCE_NAME} COMMAND ${CMAKE_OBJCOPY} ARGS -S --set-section-flags .bss=alloc,contents -O binary ${SOURCE_NAME} ${SOURCE_NAME}.bin) - install(TARGETS ${SOURCE_NAME} RUNTIME DESTINATION ${CMAKE_INSTALL_DATADIR}/elf) - install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${SOURCE_NAME}.bin DESTINATION ${CMAKE_INSTALL_DATADIR}/binary) + install(TARGETS ${SOURCE_NAME} RUNTIME DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/am-kernels) + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${SOURCE_NAME}.bin DESTINATION ${CMAKE_INSTALL_DATADIR}/am-kernels) endforeach() From 02b38e7b44f673f808abcb3bf9464811f8c58d4b Mon Sep 17 00:00:00 2001 From: xinyangli Date: Fri, 12 Jul 2024 16:45:56 +0800 Subject: [PATCH 2/9] build: nix package --- default.nix | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 default.nix diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..a9a4ff2 --- /dev/null +++ b/default.nix @@ -0,0 +1,35 @@ +{ lib, + stdenv, + cmake, + abstract-machine, + arch ? "riscv-nemu" +}: + +stdenv.mkDerivation rec { + pname = "am-kernel"; + version = "2024-07-10"; + + src = ./.; + + nativeBuildInputs = [ + cmake + ]; + + buildInputs = [ + abstract-machine + ]; + + cmakeFlags = [ + (lib.cmakeFeature "ARCH" arch) + ]; + + cmakeBuildType = "RelWithDebInfo"; + dontStrip = true; + + meta = with lib; { + description = "AbstractMachine kernels"; + homepage = "https://github.com/NJU-ProjectN/am-kernels.git"; + license = with licenses; [ ]; + maintainers = with maintainers; [ ]; + }; +} From 0b911f75ce45c4f02a643644792739e5e976d9e1 Mon Sep 17 00:00:00 2001 From: xinyangli Date: Tue, 13 Aug 2024 20:24:57 +0800 Subject: [PATCH 3/9] am-tests,microbench,yield-os: CMake support --- CMakeLists.txt | 1 + benchmarks/microbench/src/bench.c | 2 +- default.nix | 2 +- flake.lock | 379 ++++++++++++++++++ flake.nix | 60 +++ kernels/CMakeLists.txt | 1 + kernels/yield-os/CMakeLists.txt | 11 + tests/am-tests/CMakeLists.txt | 1 + .../tests/audio => include}/little-star.pcm | Bin tests/am-tests/src/CMakeLists.txt | 24 ++ tests/am-tests/src/tests/audio/audio-data.S | 2 +- tests/am-tests/src/tests/hello.c | 2 +- tests/am-tests/src/tests/intr.c | 25 +- 13 files changed, 496 insertions(+), 14 deletions(-) create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 kernels/yield-os/CMakeLists.txt create mode 100644 tests/am-tests/CMakeLists.txt rename tests/am-tests/{src/tests/audio => include}/little-star.pcm (100%) create mode 100644 tests/am-tests/src/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 78d91c9..ad3e5c6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,5 +13,6 @@ check_pie_supported() add_subdirectory(tests/cpu-tests) # add_subdirectory(tests/alu-tests) +add_subdirectory(tests/am-tests) add_subdirectory(benchmarks/microbench) add_subdirectory(kernels) diff --git a/benchmarks/microbench/src/bench.c b/benchmarks/microbench/src/bench.c index 6f36de0..e36d78d 100644 --- a/benchmarks/microbench/src/bench.c +++ b/benchmarks/microbench/src/bench.c @@ -74,7 +74,7 @@ static uint32_t score(Benchmark *b, uint64_t usec) { } int main(const char *args) { - const char *setting_name = args; + const char *setting_name = "test"; if (args == NULL || strcmp(args, "") == 0) { printf("Empty mainargs. Use \"ref\" by default\n"); setting_name = "ref"; diff --git a/default.nix b/default.nix index a9a4ff2..b034704 100644 --- a/default.nix +++ b/default.nix @@ -23,7 +23,7 @@ stdenv.mkDerivation rec { (lib.cmakeFeature "ARCH" arch) ]; - cmakeBuildType = "RelWithDebInfo"; + cmakeBuildType = "Debug"; dontStrip = true; meta = with lib; { diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..71f378d --- /dev/null +++ b/flake.lock @@ -0,0 +1,379 @@ +{ + "nodes": { + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1696426674, + "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-compat_2": { + "flake": false, + "locked": { + "lastModified": 1696426674, + "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1709126324, + "narHash": "sha256-q6EQdSeUZOG26WelxqkmR7kArjgWCdw5sfJVHPH/7j8=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "d465f4819400de7c8d874d50b982301f28a84605", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_2": { + "inputs": { + "systems": "systems_2" + }, + "locked": { + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_3": { + "inputs": { + "systems": "systems_3" + }, + "locked": { + "lastModified": 1709126324, + "narHash": "sha256-q6EQdSeUZOG26WelxqkmR7kArjgWCdw5sfJVHPH/7j8=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "d465f4819400de7c8d874d50b982301f28a84605", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_4": { + "inputs": { + "systems": "systems_4" + }, + "locked": { + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "gitignore": { + "inputs": { + "nixpkgs": [ + "pre-commit-hooks", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1709087332, + "narHash": "sha256-HG2cCnktfHsKV0s4XW83gU3F57gaTljL9KNSuG6bnQs=", + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "637db329424fd7e46cf4185293b9cc8c88c95394", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "gitignore.nix", + "type": "github" + } + }, + "gitignore_2": { + "inputs": { + "nixpkgs": [ + "ysyx-workbench", + "pre-commit-hooks", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1709087332, + "narHash": "sha256-HG2cCnktfHsKV0s4XW83gU3F57gaTljL9KNSuG6bnQs=", + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "637db329424fd7e46cf4185293b9cc8c88c95394", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "gitignore.nix", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1709237383, + "narHash": "sha256-cy6ArO4k5qTx+l5o+0mL9f5fa86tYUX3ozE1S+Txlds=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "1536926ef5621b09bba54035ae2bb6d806d72ac8", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-circt162": { + "locked": { + "lastModified": 1705645507, + "narHash": "sha256-tX3vipIAmNDBA8WNWG4oY4KyTfnm2YieTHO2BhG8ISA=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "7995cae3ad60e3d6931283d650d7f43d31aaa5c7", + "type": "github" + }, + "original": { + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "7995cae3ad60e3d6931283d650d7f43d31aaa5c7", + "type": "github" + } + }, + "nixpkgs-stable": { + "locked": { + "lastModified": 1710695816, + "narHash": "sha256-3Eh7fhEID17pv9ZxrPwCLfqXnYP006RKzSs0JptsN84=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "614b4613980a522ba49f0d194531beddbb7220d3", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-23.11", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-stable_2": { + "locked": { + "lastModified": 1710695816, + "narHash": "sha256-3Eh7fhEID17pv9ZxrPwCLfqXnYP006RKzSs0JptsN84=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "614b4613980a522ba49f0d194531beddbb7220d3", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-23.11", + "repo": "nixpkgs", + "type": "github" + } + }, + "nur-xin": { + "inputs": { + "nixpkgs": [ + "ysyx-workbench", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1721891452, + "narHash": "sha256-2c9nDuXXARzoRXE67lte5kKBeFb1XmTNsvdiIbRUEgE=", + "ref": "refs/heads/master", + "rev": "de8ad578fc4fe527772cec23a7f660bde14c8570", + "revCount": 152, + "type": "git", + "url": "https://git.xinyang.life/xin/nur.git" + }, + "original": { + "type": "git", + "url": "https://git.xinyang.life/xin/nur.git" + } + }, + "pre-commit-hooks": { + "inputs": { + "flake-compat": "flake-compat", + "flake-utils": "flake-utils_2", + "gitignore": "gitignore", + "nixpkgs": [ + "nixpkgs" + ], + "nixpkgs-stable": "nixpkgs-stable" + }, + "locked": { + "lastModified": 1712055707, + "narHash": "sha256-4XLvuSIDZJGS17xEwSrNuJLL7UjDYKGJSbK1WWX2AK8=", + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "rev": "e35aed5fda3cc79f88ed7f1795021e559582093a", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "type": "github" + } + }, + "pre-commit-hooks_2": { + "inputs": { + "flake-compat": "flake-compat_2", + "flake-utils": "flake-utils_4", + "gitignore": "gitignore_2", + "nixpkgs": [ + "ysyx-workbench", + "nixpkgs" + ], + "nixpkgs-stable": "nixpkgs-stable_2" + }, + "locked": { + "lastModified": 1712055707, + "narHash": "sha256-4XLvuSIDZJGS17xEwSrNuJLL7UjDYKGJSbK1WWX2AK8=", + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "rev": "e35aed5fda3cc79f88ed7f1795021e559582093a", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs", + "pre-commit-hooks": "pre-commit-hooks", + "ysyx-workbench": "ysyx-workbench" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_2": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_3": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_4": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "ysyx-workbench": { + "inputs": { + "flake-utils": "flake-utils_3", + "nixpkgs": [ + "nixpkgs" + ], + "nixpkgs-circt162": "nixpkgs-circt162", + "nur-xin": "nur-xin", + "pre-commit-hooks": "pre-commit-hooks_2" + }, + "locked": { + "lastModified": 1723551098, + "narHash": "sha256-/AnVxufgQoAuvNBSKm0BG+tTS++/HuaNoW+loroSQig=", + "ref": "refs/heads/master", + "rev": "8ee1551dc2857091fca6456c1367aab7090899fe", + "revCount": 119, + "type": "git", + "url": "https://git.xinyang.life/xin/ysyx-workbench" + }, + "original": { + "type": "git", + "url": "https://git.xinyang.life/xin/ysyx-workbench" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..dff9e9b --- /dev/null +++ b/flake.nix @@ -0,0 +1,60 @@ +{ + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + pre-commit-hooks = { + url = "github:cachix/pre-commit-hooks.nix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + ysyx-workbench = { + url = "git+https://git.xinyang.life/xin/ysyx-workbench"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + + outputs = { self, flake-utils, nixpkgs, pre-commit-hooks, ysyx-workbench }: + flake-utils.lib.eachDefaultSystem (system: + let + pkgs = import nixpkgs { inherit system; }; + + rv32CrossConfig = import nixpkgs { + localSystem = system; + crossSystem = { + config = "riscv32-none-elf"; + gcc = { + abi = "ilp32"; + arch = "rv32if"; + }; + }; + }; + + ysyx-pkgs = ysyx-workbench.packages.${system}; + in + { + checks = { + pre-commit-check = pre-commit-hooks.lib.${system}.run { + src = ./.; + hooks = { + trim-trailing-whitespace.enable = true; + end-of-file-fixer.enable = true; + cmake-format.enable = true; + }; + }; + }; + + packages = { + am-kernels = pkgs.callPackage ./default.nix { inherit (ysyx-pkgs) abstract-machine; arch = "native"; }; + + rv32Cross = { + am-kernels-npc = rv32CrossConfig.callPackage ./default.nix { + inherit (ysyx-pkgs.rv32Cross) abstract-machine; + arch = "riscv-npc"; + }; + am-kernels-nemu = rv32CrossConfig.callPackage ./default.nix { + inherit (ysyx-pkgs.rv32Cross) abstract-machine; + arch = "riscv-nemu"; + }; + }; + }; + }); +} diff --git a/kernels/CMakeLists.txt b/kernels/CMakeLists.txt index aed5366..b3d5b95 100644 --- a/kernels/CMakeLists.txt +++ b/kernels/CMakeLists.txt @@ -1,2 +1,3 @@ add_subdirectory(hello) add_subdirectory(demo) +add_subdirectory(yield-os) diff --git a/kernels/yield-os/CMakeLists.txt b/kernels/yield-os/CMakeLists.txt new file mode 100644 index 0000000..71f882f --- /dev/null +++ b/kernels/yield-os/CMakeLists.txt @@ -0,0 +1,11 @@ +add_executable(yield-os + yield-os.c +) +target_link_libraries(yield-os PRIVATE am-${ARCH} klib npcgcc) + +# -- Extract binary file from ELF +add_custom_command(TARGET yield-os + COMMAND ${CMAKE_OBJCOPY} ARGS -S --set-section-flags .bss=alloc,contents -O binary yield-os yield-os.bin) + +install(TARGETS yield-os RUNTIME DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/am-kernels) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/yield-os.bin DESTINATION ${CMAKE_INSTALL_DATADIR}/am-kernels) diff --git a/tests/am-tests/CMakeLists.txt b/tests/am-tests/CMakeLists.txt new file mode 100644 index 0000000..febd4f0 --- /dev/null +++ b/tests/am-tests/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(src) diff --git a/tests/am-tests/src/tests/audio/little-star.pcm b/tests/am-tests/include/little-star.pcm similarity index 100% rename from tests/am-tests/src/tests/audio/little-star.pcm rename to tests/am-tests/include/little-star.pcm diff --git a/tests/am-tests/src/CMakeLists.txt b/tests/am-tests/src/CMakeLists.txt new file mode 100644 index 0000000..b9247bb --- /dev/null +++ b/tests/am-tests/src/CMakeLists.txt @@ -0,0 +1,24 @@ +add_executable(am-tests + tests/audio/audio-data.S + tests/audio.c + tests/devscan.c + tests/hello.c + tests/intr.c + tests/keyboard.c + tests/mp.c + tests/rtc.c + tests/video.c + tests/vm.c + main.c +) +# set_property(SOURCE tests/audio/audio-data.S APPEND PROPERTY OBJECT_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/tests/audio/little-star.pcm) + +target_include_directories(am-tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../include) +target_link_libraries(am-tests PRIVATE am-${ARCH} klib npcgcc) + +# -- Extract binary file from ELF +add_custom_command(TARGET am-tests + COMMAND ${CMAKE_OBJCOPY} ARGS -S --set-section-flags .bss=alloc,contents -O binary am-tests am-tests.bin) + +install(TARGETS am-tests RUNTIME DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/am-kernels) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/am-tests.bin DESTINATION ${CMAKE_INSTALL_DATADIR}/am-kernels) diff --git a/tests/am-tests/src/tests/audio/audio-data.S b/tests/am-tests/src/tests/audio/audio-data.S index f1fc11b..90120ea 100644 --- a/tests/am-tests/src/tests/audio/audio-data.S +++ b/tests/am-tests/src/tests/audio/audio-data.S @@ -2,5 +2,5 @@ .global audio_payload, audio_payload_end .p2align 3 audio_payload: -.incbin "src/tests/audio/little-star.pcm" +.incbin "little-star.pcm" audio_payload_end: diff --git a/tests/am-tests/src/tests/hello.c b/tests/am-tests/src/tests/hello.c index 7672018..e2be6a3 100644 --- a/tests/am-tests/src/tests/hello.c +++ b/tests/am-tests/src/tests/hello.c @@ -2,6 +2,6 @@ void hello() { for (int i = 0; i < 10; i ++) { - putstr("Hello, AM World @ " __ISA__ "\n"); + putstr("Hello, AM World @ " "__ISA__" "\n"); } } diff --git a/tests/am-tests/src/tests/intr.c b/tests/am-tests/src/tests/intr.c index 855179d..e9695a5 100644 --- a/tests/am-tests/src/tests/intr.c +++ b/tests/am-tests/src/tests/intr.c @@ -1,15 +1,19 @@ #include Context *simple_trap(Event ev, Context *ctx) { - switch(ev.event) { - case EVENT_IRQ_TIMER: - putch('t'); break; - case EVENT_IRQ_IODEV: - putch('d'); break; - case EVENT_YIELD: - putch('y'); break; - default: - panic("Unhandled event"); break; + switch (ev.event) { + case EVENT_IRQ_TIMER: + putch('t'); + break; + case EVENT_IRQ_IODEV: + putch('d'); + break; + case EVENT_YIELD: + putch('y'); + break; + default: + panic("Unhandled event"); + break; } return ctx; } @@ -20,7 +24,8 @@ void hello_intr() { io_read(AM_INPUT_CONFIG); iset(1); while (1) { - for (volatile int i = 0; i < 10000000; i++) ; + for (volatile int i = 0; i < 10000000; i++) + ; yield(); } } From 3ee527c3de481e38767fffbd9e16bf48359fc638 Mon Sep 17 00:00:00 2001 From: xinyangli Date: Tue, 13 Aug 2024 20:43:19 +0800 Subject: [PATCH 4/9] ci: add auto build ci --- .gitea/workflows/build.yml | 27 +++++++++++++++++++ .gitignore | 54 +++++++++++++++++++++++++++++--------- 2 files changed, 68 insertions(+), 13 deletions(-) create mode 100644 .gitea/workflows/build.yml diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml new file mode 100644 index 0000000..7994ee6 --- /dev/null +++ b/.gitea/workflows/build.yml @@ -0,0 +1,27 @@ +name: Build nix packages +on: [push] + +jobs: + build-matrix: + runs-on: nix + strategy: + matrix: + package: [ "am-kernels", "rv32Cross.am-kernels-nemu", "rv32Cross.am-kernels-npc" ] + steps: + - uses: https://github.com/cachix/cachix-action@v14 + with: + name: ysyx + authToken: '${{ secrets.CACHIX_SIGNING_KEY }}' + - uses: actions/checkout@v4 + - name: Cache develop environment + id: cache-nix-develop + uses: actions/cache@v4 + with: + path: | + /nix/store + /nix/var/nix/db + key: nix-develop-${{ hashFiles('flake.*') }} + + - name: Build am-kernels + run: | + nix build -L .#${{ matrix.package }} diff --git a/.gitignore b/.gitignore index fe30a49..fa429be 100644 --- a/.gitignore +++ b/.gitignore @@ -1,15 +1,43 @@ -!*/ -!*.h -!*.c -!*.cc -!*.S -!Makefile -!README -!README.md -!LICENSE -.* -_* -*~ build/ -!.gitignore out/ +.cache/ +.envrc +.vscode/ +# Created by https://www.toptal.com/developers/gitignore/api/c++ +# Edit at https://www.toptal.com/developers/gitignore?templates=c++ + +### C++ ### +# Prerequisites +*.d + +# Compiled Object files +*.slo +*.lo +*.o +*.obj + +# Precompiled Headers +*.gch +*.pch + +# Compiled Dynamic libraries +*.so +*.dylib +*.dll + +# Fortran module files +*.mod +*.smod + +# Compiled Static libraries +*.lai +*.la +*.a +*.lib + +# Executables +*.exe +*.out +*.app + +# End of https://www.toptal.com/developers/gitignore/api/c++ From 3b43b569f9a827d028f39c51692b22d8e6eda294 Mon Sep 17 00:00:00 2001 From: xinyangli Date: Thu, 15 Aug 2024 15:16:42 +0800 Subject: [PATCH 5/9] bump abstract-machine version --- flake.lock | 611 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 609 insertions(+), 2 deletions(-) diff --git a/flake.lock b/flake.lock index 71f378d..61eeb6b 100644 --- a/flake.lock +++ b/flake.lock @@ -1,5 +1,48 @@ { "nodes": { + "am-kernels": { + "inputs": { + "flake-utils": "flake-utils_3", + "nixpkgs": "nixpkgs_2", + "pre-commit-hooks": "pre-commit-hooks_2", + "ysyx-workbench": "ysyx-workbench_2" + }, + "locked": { + "lastModified": 1723617032, + "narHash": "sha256-oL5Vx933Jhn+T9jn67wFbh8vy7w8OJNCn4DOOlX/r0U=", + "ref": "dev", + "rev": "3ee527c3de481e38767fffbd9e16bf48359fc638", + "revCount": 78, + "type": "git", + "url": "https://git.xinyang.life/xin/am-kernels.git" + }, + "original": { + "ref": "dev", + "type": "git", + "url": "https://git.xinyang.life/xin/am-kernels.git" + } + }, + "diffu": { + "inputs": { + "flake-utils": "flake-utils_7", + "nixpkgs": "nixpkgs_3", + "nur-xin": "nur-xin_2", + "pre-commit-hooks": "pre-commit-hooks_4" + }, + "locked": { + "lastModified": 1723627842, + "narHash": "sha256-+Ovf1e5ESap4sGMsH945SkZLhyYUxGE7shKVl3Ue1CQ=", + "ref": "refs/heads/master", + "rev": "7b3881a9712bcb7bfea90614a44888ae5df6e849", + "revCount": 17, + "type": "git", + "url": "https://git.xinyang.life/xin/diffu.git" + }, + "original": { + "type": "git", + "url": "https://git.xinyang.life/xin/diffu.git" + } + }, "flake-compat": { "flake": false, "locked": { @@ -32,6 +75,54 @@ "type": "github" } }, + "flake-compat_3": { + "flake": false, + "locked": { + "lastModified": 1696426674, + "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-compat_4": { + "flake": false, + "locked": { + "lastModified": 1696426674, + "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-compat_5": { + "flake": false, + "locked": { + "lastModified": 1696426674, + "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, "flake-utils": { "inputs": { "systems": "systems" @@ -50,6 +141,24 @@ "type": "github" } }, + "flake-utils_10": { + "inputs": { + "systems": "systems_10" + }, + "locked": { + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, "flake-utils_2": { "inputs": { "systems": "systems_2" @@ -104,6 +213,96 @@ "type": "github" } }, + "flake-utils_5": { + "inputs": { + "systems": "systems_5" + }, + "locked": { + "lastModified": 1709126324, + "narHash": "sha256-q6EQdSeUZOG26WelxqkmR7kArjgWCdw5sfJVHPH/7j8=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "d465f4819400de7c8d874d50b982301f28a84605", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_6": { + "inputs": { + "systems": "systems_6" + }, + "locked": { + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_7": { + "inputs": { + "systems": "systems_7" + }, + "locked": { + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_8": { + "inputs": { + "systems": "systems_8" + }, + "locked": { + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_9": { + "inputs": { + "systems": "systems_9" + }, + "locked": { + "lastModified": 1709126324, + "narHash": "sha256-q6EQdSeUZOG26WelxqkmR7kArjgWCdw5sfJVHPH/7j8=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "d465f4819400de7c8d874d50b982301f28a84605", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, "gitignore": { "inputs": { "nixpkgs": [ @@ -126,6 +325,76 @@ } }, "gitignore_2": { + "inputs": { + "nixpkgs": [ + "ysyx-workbench", + "am-kernels", + "pre-commit-hooks", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1709087332, + "narHash": "sha256-HG2cCnktfHsKV0s4XW83gU3F57gaTljL9KNSuG6bnQs=", + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "637db329424fd7e46cf4185293b9cc8c88c95394", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "gitignore.nix", + "type": "github" + } + }, + "gitignore_3": { + "inputs": { + "nixpkgs": [ + "ysyx-workbench", + "am-kernels", + "ysyx-workbench", + "pre-commit-hooks", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1709087332, + "narHash": "sha256-HG2cCnktfHsKV0s4XW83gU3F57gaTljL9KNSuG6bnQs=", + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "637db329424fd7e46cf4185293b9cc8c88c95394", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "gitignore.nix", + "type": "github" + } + }, + "gitignore_4": { + "inputs": { + "nixpkgs": [ + "ysyx-workbench", + "diffu", + "pre-commit-hooks", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1709087332, + "narHash": "sha256-HG2cCnktfHsKV0s4XW83gU3F57gaTljL9KNSuG6bnQs=", + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "637db329424fd7e46cf4185293b9cc8c88c95394", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "gitignore.nix", + "type": "github" + } + }, + "gitignore_5": { "inputs": { "nixpkgs": [ "ysyx-workbench", @@ -179,6 +448,22 @@ "type": "github" } }, + "nixpkgs-circt162_2": { + "locked": { + "lastModified": 1705645507, + "narHash": "sha256-tX3vipIAmNDBA8WNWG4oY4KyTfnm2YieTHO2BhG8ISA=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "7995cae3ad60e3d6931283d650d7f43d31aaa5c7", + "type": "github" + }, + "original": { + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "7995cae3ad60e3d6931283d650d7f43d31aaa5c7", + "type": "github" + } + }, "nixpkgs-stable": { "locked": { "lastModified": 1710695816, @@ -211,7 +496,132 @@ "type": "github" } }, + "nixpkgs-stable_3": { + "locked": { + "lastModified": 1710695816, + "narHash": "sha256-3Eh7fhEID17pv9ZxrPwCLfqXnYP006RKzSs0JptsN84=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "614b4613980a522ba49f0d194531beddbb7220d3", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-23.11", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-stable_4": { + "locked": { + "lastModified": 1710695816, + "narHash": "sha256-3Eh7fhEID17pv9ZxrPwCLfqXnYP006RKzSs0JptsN84=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "614b4613980a522ba49f0d194531beddbb7220d3", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-23.11", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-stable_5": { + "locked": { + "lastModified": 1710695816, + "narHash": "sha256-3Eh7fhEID17pv9ZxrPwCLfqXnYP006RKzSs0JptsN84=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "614b4613980a522ba49f0d194531beddbb7220d3", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-23.11", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1709237383, + "narHash": "sha256-cy6ArO4k5qTx+l5o+0mL9f5fa86tYUX3ozE1S+Txlds=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "1536926ef5621b09bba54035ae2bb6d806d72ac8", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_3": { + "locked": { + "lastModified": 1711703276, + "narHash": "sha256-iMUFArF0WCatKK6RzfUJknjem0H9m4KgorO/p3Dopkk=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "d8fe5e6c92d0d190646fb9f1056741a229980089", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, "nur-xin": { + "inputs": { + "nixpkgs": [ + "ysyx-workbench", + "am-kernels", + "ysyx-workbench", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1721891452, + "narHash": "sha256-2c9nDuXXARzoRXE67lte5kKBeFb1XmTNsvdiIbRUEgE=", + "ref": "refs/heads/master", + "rev": "de8ad578fc4fe527772cec23a7f660bde14c8570", + "revCount": 152, + "type": "git", + "url": "https://git.xinyang.life/xin/nur.git" + }, + "original": { + "type": "git", + "url": "https://git.xinyang.life/xin/nur.git" + } + }, + "nur-xin_2": { + "inputs": { + "nixpkgs": [ + "ysyx-workbench", + "diffu", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1721891452, + "narHash": "sha256-2c9nDuXXARzoRXE67lte5kKBeFb1XmTNsvdiIbRUEgE=", + "ref": "refs/heads/master", + "rev": "de8ad578fc4fe527772cec23a7f660bde14c8570", + "revCount": 152, + "type": "git", + "url": "https://git.xinyang.life/xin/nur.git" + }, + "original": { + "type": "git", + "url": "https://git.xinyang.life/xin/nur.git" + } + }, + "nur-xin_3": { "inputs": { "nixpkgs": [ "ysyx-workbench", @@ -263,6 +673,7 @@ "gitignore": "gitignore_2", "nixpkgs": [ "ysyx-workbench", + "am-kernels", "nixpkgs" ], "nixpkgs-stable": "nixpkgs-stable_2" @@ -281,6 +692,84 @@ "type": "github" } }, + "pre-commit-hooks_3": { + "inputs": { + "flake-compat": "flake-compat_3", + "flake-utils": "flake-utils_6", + "gitignore": "gitignore_3", + "nixpkgs": [ + "ysyx-workbench", + "am-kernels", + "ysyx-workbench", + "nixpkgs" + ], + "nixpkgs-stable": "nixpkgs-stable_3" + }, + "locked": { + "lastModified": 1712055707, + "narHash": "sha256-4XLvuSIDZJGS17xEwSrNuJLL7UjDYKGJSbK1WWX2AK8=", + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "rev": "e35aed5fda3cc79f88ed7f1795021e559582093a", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "type": "github" + } + }, + "pre-commit-hooks_4": { + "inputs": { + "flake-compat": "flake-compat_4", + "flake-utils": "flake-utils_8", + "gitignore": "gitignore_4", + "nixpkgs": [ + "ysyx-workbench", + "diffu", + "nixpkgs" + ], + "nixpkgs-stable": "nixpkgs-stable_4" + }, + "locked": { + "lastModified": 1712055707, + "narHash": "sha256-4XLvuSIDZJGS17xEwSrNuJLL7UjDYKGJSbK1WWX2AK8=", + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "rev": "e35aed5fda3cc79f88ed7f1795021e559582093a", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "type": "github" + } + }, + "pre-commit-hooks_5": { + "inputs": { + "flake-compat": "flake-compat_5", + "flake-utils": "flake-utils_10", + "gitignore": "gitignore_5", + "nixpkgs": [ + "ysyx-workbench", + "nixpkgs" + ], + "nixpkgs-stable": "nixpkgs-stable_5" + }, + "locked": { + "lastModified": 1712055707, + "narHash": "sha256-4XLvuSIDZJGS17xEwSrNuJLL7UjDYKGJSbK1WWX2AK8=", + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "rev": "e35aed5fda3cc79f88ed7f1795021e559582093a", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "type": "github" + } + }, "root": { "inputs": { "flake-utils": "flake-utils", @@ -304,6 +793,21 @@ "type": "github" } }, + "systems_10": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, "systems_2": { "locked": { "lastModified": 1681028828, @@ -349,15 +853,118 @@ "type": "github" } }, + "systems_5": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_6": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_7": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_8": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_9": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, "ysyx-workbench": { "inputs": { - "flake-utils": "flake-utils_3", + "am-kernels": "am-kernels", + "diffu": "diffu", + "flake-utils": "flake-utils_9", "nixpkgs": [ "nixpkgs" ], + "nixpkgs-circt162": "nixpkgs-circt162_2", + "nur-xin": "nur-xin_3", + "pre-commit-hooks": "pre-commit-hooks_5" + }, + "locked": { + "lastModified": 1723704951, + "narHash": "sha256-dXdYwsNyAI+gx++E8Omh7ePk+MU/paMUx+r5j48eyZA=", + "ref": "refs/heads/master", + "rev": "b403f8a40be36ee9b092ac3f49d490cf35ab9890", + "revCount": 122, + "type": "git", + "url": "https://git.xinyang.life/xin/ysyx-workbench" + }, + "original": { + "type": "git", + "url": "https://git.xinyang.life/xin/ysyx-workbench" + } + }, + "ysyx-workbench_2": { + "inputs": { + "flake-utils": "flake-utils_5", + "nixpkgs": [ + "ysyx-workbench", + "am-kernels", + "nixpkgs" + ], "nixpkgs-circt162": "nixpkgs-circt162", "nur-xin": "nur-xin", - "pre-commit-hooks": "pre-commit-hooks_2" + "pre-commit-hooks": "pre-commit-hooks_3" }, "locked": { "lastModified": 1723551098, From b09e60afb4c34f445004032c13b1b5cb5ddbda98 Mon Sep 17 00:00:00 2001 From: xinyangli Date: Thu, 15 Aug 2024 15:54:43 +0800 Subject: [PATCH 6/9] bump abstract-machine version --- flake.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/flake.lock b/flake.lock index 61eeb6b..bb609b8 100644 --- a/flake.lock +++ b/flake.lock @@ -941,11 +941,11 @@ "pre-commit-hooks": "pre-commit-hooks_5" }, "locked": { - "lastModified": 1723704951, - "narHash": "sha256-dXdYwsNyAI+gx++E8Omh7ePk+MU/paMUx+r5j48eyZA=", + "lastModified": 1723708371, + "narHash": "sha256-O7xHxmwx3wki8G6u0GhKos6yaQNlp/zwZHjojePgpPA=", "ref": "refs/heads/master", - "rev": "b403f8a40be36ee9b092ac3f49d490cf35ab9890", - "revCount": 122, + "rev": "b0b30293bf827ebca0d29d0ba41cdc6a4452c1c4", + "revCount": 123, "type": "git", "url": "https://git.xinyang.life/xin/ysyx-workbench" }, From b99fc98d8d4569f8bab87e6bf08c2a90dca08b16 Mon Sep 17 00:00:00 2001 From: xinyangli Date: Thu, 15 Aug 2024 16:14:56 +0800 Subject: [PATCH 7/9] bump abstract-machine version --- flake.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/flake.lock b/flake.lock index bb609b8..a0bdfcc 100644 --- a/flake.lock +++ b/flake.lock @@ -941,11 +941,11 @@ "pre-commit-hooks": "pre-commit-hooks_5" }, "locked": { - "lastModified": 1723708371, - "narHash": "sha256-O7xHxmwx3wki8G6u0GhKos6yaQNlp/zwZHjojePgpPA=", + "lastModified": 1723709622, + "narHash": "sha256-xL65SDXbE+5sqS2Vv+JEQyrPMrNW3Crc6NmZYy6L9QM=", "ref": "refs/heads/master", - "rev": "b0b30293bf827ebca0d29d0ba41cdc6a4452c1c4", - "revCount": 123, + "rev": "1f3e64bb379756394c4aea7a55aaf37555bd5a6c", + "revCount": 124, "type": "git", "url": "https://git.xinyang.life/xin/ysyx-workbench" }, From f6c3a13e7feafd763d31f71c5637973811f8c705 Mon Sep 17 00:00:00 2001 From: xinyangli Date: Thu, 15 Aug 2024 16:42:02 +0800 Subject: [PATCH 8/9] build: fix unneeded dependency on npcgcc --- benchmarks/microbench/src/CMakeLists.txt | 2 +- flake.lock | 8 ++++---- kernels/demo/src/CMakeLists.txt | 2 +- kernels/hello/CMakeLists.txt | 5 ++--- kernels/yield-os/CMakeLists.txt | 2 +- tests/alu-tests/CMakeLists.txt | 5 ++--- tests/am-tests/src/CMakeLists.txt | 4 ++-- 7 files changed, 13 insertions(+), 15 deletions(-) diff --git a/benchmarks/microbench/src/CMakeLists.txt b/benchmarks/microbench/src/CMakeLists.txt index 349cc5c..7fd36c7 100644 --- a/benchmarks/microbench/src/CMakeLists.txt +++ b/benchmarks/microbench/src/CMakeLists.txt @@ -13,7 +13,7 @@ add_executable(bench fib/fib.c ) -target_link_libraries(bench am-${ARCH} klib npcgcc) +target_link_libraries(bench am-${ARCH} klib) # -- Extract binary file from ELF add_custom_command(TARGET bench diff --git a/flake.lock b/flake.lock index a0bdfcc..dc497e7 100644 --- a/flake.lock +++ b/flake.lock @@ -941,11 +941,11 @@ "pre-commit-hooks": "pre-commit-hooks_5" }, "locked": { - "lastModified": 1723709622, - "narHash": "sha256-xL65SDXbE+5sqS2Vv+JEQyrPMrNW3Crc6NmZYy6L9QM=", + "lastModified": 1723711136, + "narHash": "sha256-wwVG49IBLtyb2mZ9kNGojuJSYa4evf/2IEcdx8HZxKA=", "ref": "refs/heads/master", - "rev": "1f3e64bb379756394c4aea7a55aaf37555bd5a6c", - "revCount": 124, + "rev": "3d64dbd200ab3e944b99df76ba884abb2cdbbef6", + "revCount": 125, "type": "git", "url": "https://git.xinyang.life/xin/ysyx-workbench" }, diff --git a/kernels/demo/src/CMakeLists.txt b/kernels/demo/src/CMakeLists.txt index b58503b..adce99d 100644 --- a/kernels/demo/src/CMakeLists.txt +++ b/kernels/demo/src/CMakeLists.txt @@ -10,7 +10,7 @@ add_executable(demo main.c ) target_include_directories(demo PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../include) -target_link_libraries(demo PRIVATE am-${ARCH} klib npcgcc) +target_link_libraries(demo PRIVATE am-${ARCH} klib) # -- Extract binary file from ELF add_custom_command(TARGET demo diff --git a/kernels/hello/CMakeLists.txt b/kernels/hello/CMakeLists.txt index 0afa490..e307f4f 100644 --- a/kernels/hello/CMakeLists.txt +++ b/kernels/hello/CMakeLists.txt @@ -2,9 +2,8 @@ add_executable(hello hello.c ) target_include_directories(hello PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../include) -target_link_libraries(hello PRIVATE am-${ARCH} klib npcgcc) -target_compile_options(hello PRIVATE -nostdlib -nodefaultlibs) -target_link_options(hello PRIVATE -nostdlib -nodefaultlibs) +target_link_libraries(hello PRIVATE am-${ARCH} klib) + # -- Extract binary file from ELF add_custom_command(TARGET hello diff --git a/kernels/yield-os/CMakeLists.txt b/kernels/yield-os/CMakeLists.txt index 71f882f..2db7c9c 100644 --- a/kernels/yield-os/CMakeLists.txt +++ b/kernels/yield-os/CMakeLists.txt @@ -1,7 +1,7 @@ add_executable(yield-os yield-os.c ) -target_link_libraries(yield-os PRIVATE am-${ARCH} klib npcgcc) +target_link_libraries(yield-os PRIVATE am-${ARCH} klib) # -- Extract binary file from ELF add_custom_command(TARGET yield-os diff --git a/tests/alu-tests/CMakeLists.txt b/tests/alu-tests/CMakeLists.txt index 4fb0bd4..8d6ed7d 100644 --- a/tests/alu-tests/CMakeLists.txt +++ b/tests/alu-tests/CMakeLists.txt @@ -17,9 +17,8 @@ add_executable(alu_test alu_test.c) target_include_directories(alu_test PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../include) -target_link_libraries(alu_test PRIVATE am-${ARCH} klib npcgcc) -target_compile_options(alu_test PRIVATE -nostdlib -nodefaultlibs) -target_link_options(alu_test PRIVATE -nostdlib -nodefaultlibs) +target_link_libraries(alu_test PRIVATE am-${ARCH} klib) + # -- Extract binary file from ELF add_custom_command(TARGET alu_test diff --git a/tests/am-tests/src/CMakeLists.txt b/tests/am-tests/src/CMakeLists.txt index b9247bb..2859620 100644 --- a/tests/am-tests/src/CMakeLists.txt +++ b/tests/am-tests/src/CMakeLists.txt @@ -11,10 +11,10 @@ add_executable(am-tests tests/vm.c main.c ) -# set_property(SOURCE tests/audio/audio-data.S APPEND PROPERTY OBJECT_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/tests/audio/little-star.pcm) +# set_propertygSOURCE tests/audio/audio-data.S APPEND PROPERTY OBJECT_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/tests/audio/little-star.pcm) target_include_directories(am-tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../include) -target_link_libraries(am-tests PRIVATE am-${ARCH} klib npcgcc) +target_link_libraries(am-tests PRIVATE am-${ARCH} klib) # -- Extract binary file from ELF add_custom_command(TARGET am-tests From 8630fe7667967009757721bece55235dca5b7614 Mon Sep 17 00:00:00 2001 From: xinyangli Date: Thu, 15 Aug 2024 17:52:04 +0800 Subject: [PATCH 9/9] refactor: use cmake macros to do objcopy, install and tests --- CMakeLists.txt | 25 ++++++++++++++++++++++++ benchmarks/microbench/src/CMakeLists.txt | 9 ++------- default.nix | 2 ++ flake.lock | 8 ++++---- kernels/demo/src/CMakeLists.txt | 8 ++------ kernels/demo/src/main.c | 8 ++++---- kernels/hello/CMakeLists.txt | 9 ++------- kernels/yield-os/CMakeLists.txt | 4 ++-- kernels/yield-os/yield-os.c | 14 ++++++++----- tests/am-tests/src/CMakeLists.txt | 8 ++------ tests/cpu-tests/tests/CMakeLists.txt | 8 ++------ tests/cpu-tests/tests/hello-str.c | 15 +++++++------- 12 files changed, 64 insertions(+), 54 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ad3e5c6..59293ed 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,11 +6,36 @@ enable_language(C ASM) include(CheckPIESupported) include(GNUInstallDirs) +if(${ARCH} STREQUAL "native") + include(CTest) +endif() + find_package(am-${ARCH}) find_package(klib) check_pie_supported() +# -- Helper functions +macro(create_binary target_name) + if(NOT ${ARCH} STREQUAL "native") + add_custom_command( + TARGET ${target_name} POST_BUILD + COMMAND ${CMAKE_OBJCOPY} -S --set-section-flags .bss=alloc,contents -O binary ${target_name} ${target_name}.bin + COMMENT "Creating binary file ${target_name}.bin" + ) + endif() +endmacro(create_binary) + +macro(install_target_and_binary target_name) + if(NOT ${ARCH} STREQUAL "native") + install(TARGETS ${target_name} RUNTIME DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/am-kernels) + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${target_name}.bin DESTINATION ${CMAKE_INSTALL_DATADIR}/am-kernels) + else() + install(TARGETS ${target_name}) + add_test(NAME ${target_name}_test COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${target_name}) + endif() +endmacro(install_target_and_binary) + add_subdirectory(tests/cpu-tests) # add_subdirectory(tests/alu-tests) add_subdirectory(tests/am-tests) diff --git a/benchmarks/microbench/src/CMakeLists.txt b/benchmarks/microbench/src/CMakeLists.txt index 7fd36c7..60b1f0f 100644 --- a/benchmarks/microbench/src/CMakeLists.txt +++ b/benchmarks/microbench/src/CMakeLists.txt @@ -14,10 +14,5 @@ add_executable(bench ) target_link_libraries(bench am-${ARCH} klib) - -# -- Extract binary file from ELF -add_custom_command(TARGET bench - COMMAND ${CMAKE_OBJCOPY} ARGS -S --set-section-flags .bss=alloc,contents -O binary bench bench.bin) - -install(TARGETS bench RUNTIME DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/am-kernels) -install(FILES ${CMAKE_CURRENT_BINARY_DIR}/bench.bin DESTINATION ${CMAKE_INSTALL_DATADIR}/am-kernels) +create_binary(bench) +install_target_and_binary(bench) diff --git a/default.nix b/default.nix index b034704..72a3e96 100644 --- a/default.nix +++ b/default.nix @@ -26,6 +26,8 @@ stdenv.mkDerivation rec { cmakeBuildType = "Debug"; dontStrip = true; + doCheck = true; + meta = with lib; { description = "AbstractMachine kernels"; homepage = "https://github.com/NJU-ProjectN/am-kernels.git"; diff --git a/flake.lock b/flake.lock index dc497e7..1e9e208 100644 --- a/flake.lock +++ b/flake.lock @@ -941,11 +941,11 @@ "pre-commit-hooks": "pre-commit-hooks_5" }, "locked": { - "lastModified": 1723711136, - "narHash": "sha256-wwVG49IBLtyb2mZ9kNGojuJSYa4evf/2IEcdx8HZxKA=", + "lastModified": 1723714692, + "narHash": "sha256-EU6HE8DfSorD2Wx7yjBicSSLxGKxKbDD/3XI+RUB7Gs=", "ref": "refs/heads/master", - "rev": "3d64dbd200ab3e944b99df76ba884abb2cdbbef6", - "revCount": 125, + "rev": "0e408882b21b17fa19158b2044498ddad8e691e7", + "revCount": 126, "type": "git", "url": "https://git.xinyang.life/xin/ysyx-workbench" }, diff --git a/kernels/demo/src/CMakeLists.txt b/kernels/demo/src/CMakeLists.txt index adce99d..1c97f14 100644 --- a/kernels/demo/src/CMakeLists.txt +++ b/kernels/demo/src/CMakeLists.txt @@ -12,9 +12,5 @@ add_executable(demo target_include_directories(demo PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../include) target_link_libraries(demo PRIVATE am-${ARCH} klib) -# -- Extract binary file from ELF -add_custom_command(TARGET demo - COMMAND ${CMAKE_OBJCOPY} ARGS -S --set-section-flags .bss=alloc,contents -O binary demo demo.bin) - -install(TARGETS demo RUNTIME DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/am-kernels) -install(FILES ${CMAKE_CURRENT_BINARY_DIR}/demo.bin DESTINATION ${CMAKE_INSTALL_DATADIR}/am-kernels) +create_binary(demo) +install_target_and_binary(demo) diff --git a/kernels/demo/src/main.c b/kernels/demo/src/main.c index 9457fa5..e1b81d2 100644 --- a/kernels/demo/src/main.c +++ b/kernels/demo/src/main.c @@ -36,9 +36,9 @@ int main(const char *args) { } printf("Press Q to Exit\n"); - while (1) { - AM_INPUT_KEYBRD_T ev = io_read(AM_INPUT_KEYBRD); - if (ev.keydown && ev.keycode == AM_KEY_Q) break; - } + // while (1) { + // AM_INPUT_KEYBRD_T ev = io_read(AM_INPUT_KEYBRD); + // if (ev.keydown && ev.keycode == AM_KEY_Q) break; + // } return 0; } diff --git a/kernels/hello/CMakeLists.txt b/kernels/hello/CMakeLists.txt index e307f4f..1571a4f 100644 --- a/kernels/hello/CMakeLists.txt +++ b/kernels/hello/CMakeLists.txt @@ -4,10 +4,5 @@ add_executable(hello target_include_directories(hello PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../include) target_link_libraries(hello PRIVATE am-${ARCH} klib) - -# -- Extract binary file from ELF -add_custom_command(TARGET hello - COMMAND ${CMAKE_OBJCOPY} ARGS -S --set-section-flags .bss=alloc,contents -O binary hello hello.bin) - -install(TARGETS hello RUNTIME DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/am-kernels) -install(FILES ${CMAKE_CURRENT_BINARY_DIR}/hello.bin DESTINATION ${CMAKE_INSTALL_DATADIR}/am-kernels) +create_binary(hello) +install_target_and_binary(hello) diff --git a/kernels/yield-os/CMakeLists.txt b/kernels/yield-os/CMakeLists.txt index 2db7c9c..7684719 100644 --- a/kernels/yield-os/CMakeLists.txt +++ b/kernels/yield-os/CMakeLists.txt @@ -7,5 +7,5 @@ target_link_libraries(yield-os PRIVATE am-${ARCH} klib) add_custom_command(TARGET yield-os COMMAND ${CMAKE_OBJCOPY} ARGS -S --set-section-flags .bss=alloc,contents -O binary yield-os yield-os.bin) -install(TARGETS yield-os RUNTIME DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/am-kernels) -install(FILES ${CMAKE_CURRENT_BINARY_DIR}/yield-os.bin DESTINATION ${CMAKE_INSTALL_DATADIR}/am-kernels) +create_binary(yield-os) +install_target_and_binary(yield-os) diff --git a/kernels/yield-os/yield-os.c b/kernels/yield-os/yield-os.c index 90eb3ff..caf4e84 100644 --- a/kernels/yield-os/yield-os.c +++ b/kernels/yield-os/yield-os.c @@ -4,16 +4,20 @@ #define STACK_SIZE (4096 * 8) typedef union { uint8_t stack[STACK_SIZE]; - struct { Context *cp; }; + struct { + Context *cp; + }; } PCB; static PCB pcb[2], pcb_boot, *current = &pcb_boot; static void f(void *arg) { - while (1) { + for (int i = 0; i < 100; i++) { putch("?AB"[(uintptr_t)arg > 2 ? 0 : (uintptr_t)arg]); - for (int volatile i = 0; i < 100000; i++) ; + for (int volatile i = 0; i < 100000; i++) + ; yield(); } + halt(0); } static Context *schedule(Event ev, Context *prev) { @@ -24,8 +28,8 @@ static Context *schedule(Event ev, Context *prev) { int main() { cte_init(schedule); - pcb[0].cp = kcontext((Area) { pcb[0].stack, &pcb[0] + 1 }, f, (void *)1L); - pcb[1].cp = kcontext((Area) { pcb[1].stack, &pcb[1] + 1 }, f, (void *)2L); + pcb[0].cp = kcontext((Area){pcb[0].stack, &pcb[0] + 1}, f, (void *)1L); + pcb[1].cp = kcontext((Area){pcb[1].stack, &pcb[1] + 1}, f, (void *)2L); yield(); panic("Should not reach here!"); } diff --git a/tests/am-tests/src/CMakeLists.txt b/tests/am-tests/src/CMakeLists.txt index 2859620..5115a71 100644 --- a/tests/am-tests/src/CMakeLists.txt +++ b/tests/am-tests/src/CMakeLists.txt @@ -16,9 +16,5 @@ add_executable(am-tests target_include_directories(am-tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../include) target_link_libraries(am-tests PRIVATE am-${ARCH} klib) -# -- Extract binary file from ELF -add_custom_command(TARGET am-tests - COMMAND ${CMAKE_OBJCOPY} ARGS -S --set-section-flags .bss=alloc,contents -O binary am-tests am-tests.bin) - -install(TARGETS am-tests RUNTIME DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/am-kernels) -install(FILES ${CMAKE_CURRENT_BINARY_DIR}/am-tests.bin DESTINATION ${CMAKE_INSTALL_DATADIR}/am-kernels) +create_binary(am-tests) +install_target_and_binary(am-tests) diff --git a/tests/cpu-tests/tests/CMakeLists.txt b/tests/cpu-tests/tests/CMakeLists.txt index c03254b..03e071d 100644 --- a/tests/cpu-tests/tests/CMakeLists.txt +++ b/tests/cpu-tests/tests/CMakeLists.txt @@ -41,10 +41,6 @@ foreach(SOURCE IN LISTS SOURCES) ${SOURCE}) target_link_libraries(${SOURCE_NAME} PRIVATE am-${ARCH} klib) - # -- Extract binary file from ELF - add_custom_command(TARGET ${SOURCE_NAME} - COMMAND ${CMAKE_OBJCOPY} ARGS -S --set-section-flags .bss=alloc,contents -O binary ${SOURCE_NAME} ${SOURCE_NAME}.bin) - - install(TARGETS ${SOURCE_NAME} RUNTIME DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/am-kernels) - install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${SOURCE_NAME}.bin DESTINATION ${CMAKE_INSTALL_DATADIR}/am-kernels) + create_binary(${SOURCE_NAME}) + install_target_and_binary(${SOURCE_NAME}) endforeach() diff --git a/tests/cpu-tests/tests/hello-str.c b/tests/cpu-tests/tests/hello-str.c index 90e5b1a..c4376b4 100644 --- a/tests/cpu-tests/tests/hello-str.c +++ b/tests/cpu-tests/tests/hello-str.c @@ -3,14 +3,15 @@ char buf[128]; int main() { - sprintf(buf, "%s", "Hello world!\n"); - check(strcmp(buf, "Hello world!\n") == 0); + sprintf(buf, "%s", "Hello world!\n"); + check(strcmp(buf, "Hello world!\n") == 0); - sprintf(buf, "%d + %d = %d\n", 1, 1, 2); - check(strcmp(buf, "1 + 1 = 2\n") == 0); + sprintf(buf, "%d + %d = %d\n", 1, 1, 2); + check(strcmp(buf, "1 + 1 = 2\n") == 0); - sprintf(buf, "%d + %d = %d\n", 2, 10, 12); - check(strcmp(buf, "2 + 10 = 12\n") == 0); + sprintf(buf, "%d + %d = %d\n", 2, 10, 12); + printf(buf); + check(strcmp(buf, "2 + 10 = 12\n") == 0); - return 0; + return 0; }