diff --git a/.gitea/workflows/abstract-machine-build.yml b/.gitea/workflows/abstract-machine-build.yml deleted file mode 100644 index 3a4547c..0000000 --- a/.gitea/workflows/abstract-machine-build.yml +++ /dev/null @@ -1,27 +0,0 @@ -name: Build abstract machine with nix -on: - push: - branches: - - master - pull_request: - branches: - - master - -jobs: - build-abstract-machine: - runs-on: nix - steps: - - uses: https://github.com/cachix/cachix-action@v14 - with: - name: ysyx - authToken: '${{ secrets.CACHIX_SIGNING_KEY }}' - - uses: actions/checkout@v4 - with: - submodules: true - - name: Build abstract-machine - run: | - nix build .?submodules=1#abstract-machine - - name: Build nemu - run: | - nix build .?submodules=1#nemu - diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml deleted file mode 100644 index 0f02bf1..0000000 --- a/.gitea/workflows/build.yml +++ /dev/null @@ -1,24 +0,0 @@ -name: Run CTests within npc -on: [push] - -jobs: - npc-test: - runs-on: nix - 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 .#{am-kernels} - nix build .#rv32Cross.{am-kernels-nemu, am-kernels-npc} diff --git a/.gitignore b/.gitignore index fa429be..fe30a49 100644 --- a/.gitignore +++ b/.gitignore @@ -1,43 +1,15 @@ +!*/ +!*.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++ diff --git a/CMakeLists.txt b/CMakeLists.txt index ad3e5c6..78d91c9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,6 +13,5 @@ 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 e36d78d..6f36de0 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 = "test"; + const char *setting_name = args; 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 b034704..a9a4ff2 100644 --- a/default.nix +++ b/default.nix @@ -23,7 +23,7 @@ stdenv.mkDerivation rec { (lib.cmakeFeature "ARCH" arch) ]; - cmakeBuildType = "Debug"; + cmakeBuildType = "RelWithDebInfo"; dontStrip = true; meta = with lib; { diff --git a/flake.lock b/flake.lock deleted file mode 100644 index 71f378d..0000000 --- a/flake.lock +++ /dev/null @@ -1,379 +0,0 @@ -{ - "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 deleted file mode 100644 index dff9e9b..0000000 --- a/flake.nix +++ /dev/null @@ -1,60 +0,0 @@ -{ - 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 b3d5b95..aed5366 100644 --- a/kernels/CMakeLists.txt +++ b/kernels/CMakeLists.txt @@ -1,3 +1,2 @@ add_subdirectory(hello) add_subdirectory(demo) -add_subdirectory(yield-os) diff --git a/kernels/yield-os/CMakeLists.txt b/kernels/yield-os/CMakeLists.txt deleted file mode 100644 index 71f882f..0000000 --- a/kernels/yield-os/CMakeLists.txt +++ /dev/null @@ -1,11 +0,0 @@ -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 deleted file mode 100644 index febd4f0..0000000 --- a/tests/am-tests/CMakeLists.txt +++ /dev/null @@ -1 +0,0 @@ -add_subdirectory(src) diff --git a/tests/am-tests/src/CMakeLists.txt b/tests/am-tests/src/CMakeLists.txt deleted file mode 100644 index b9247bb..0000000 --- a/tests/am-tests/src/CMakeLists.txt +++ /dev/null @@ -1,24 +0,0 @@ -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 90120ea..f1fc11b 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 "little-star.pcm" +.incbin "src/tests/audio/little-star.pcm" audio_payload_end: diff --git a/tests/am-tests/include/little-star.pcm b/tests/am-tests/src/tests/audio/little-star.pcm similarity index 100% rename from tests/am-tests/include/little-star.pcm rename to tests/am-tests/src/tests/audio/little-star.pcm diff --git a/tests/am-tests/src/tests/hello.c b/tests/am-tests/src/tests/hello.c index e2be6a3..7672018 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 e9695a5..855179d 100644 --- a/tests/am-tests/src/tests/intr.c +++ b/tests/am-tests/src/tests/intr.c @@ -1,19 +1,15 @@ #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; } @@ -24,8 +20,7 @@ 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(); } }