Skip to content

Commit

Permalink
Merge pull request #188 from MRNIU/boot
Browse files Browse the repository at this point in the history
A completely new version of boot code
  • Loading branch information
MRNIU authored Sep 18, 2024
2 parents fdc917d + a3652c1 commit 430420f
Show file tree
Hide file tree
Showing 140 changed files with 28,176 additions and 3,155 deletions.
4 changes: 2 additions & 2 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
---
# @version clang-format version 15
# @see https://clang.llvm.org/docs/ClangFormatStyleOptions.html
# 使用 LLVM 规范
BasedOnStyle: LLVM
# 使用 Google 规范
BasedOnStyle: Google
...
103 changes: 30 additions & 73 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ env:
CMAKE_BUILD_TYPE: Release

jobs:
build_docs:
name: Build and publish documentation
build_ubuntu:
runs-on: ubuntu-latest
permissions:
contents: write
Expand All @@ -25,90 +24,48 @@ jobs:

- name: Install dependencies
run: |
sudo apt update
sudo apt install --fix-missing -y doxygen graphviz clang-format clang-tidy cppcheck qemu-system lcov
sudo apt install --fix-missing -y gcc g++ gcc-riscv64-linux-gnu g++-riscv64-linux-gnu gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
- name: Build
run: |
cmake --preset=build_x86_64
cmake --build build_x86_64 --target doc
- name: Publish
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ${{github.workspace}}/doc/html

build_ubuntu:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Install dependencies
run: |
sudo apt update
sudo apt install --fix-missing -y doxygen graphviz clang-format clang-tidy cppcheck qemu-system lcov
sudo apt update --fix-missing -y
sudo apt upgrade --fix-missing -y
sudo apt install --fix-missing -y gcc g++ gcc-riscv64-linux-gnu g++-riscv64-linux-gnu gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
sudo apt install --fix-missing -y cmake qemu-system gdb-multiarch
sudo apt install --fix-missing -y doxygen graphviz
sudo apt install --fix-missing -y clang-format clang-tidy cppcheck libgtest-dev lcov
git submodule update --init --recursive
- name: x86_64
run: |
cmake --preset=build_x86_64
# @todo ci 暂时跑不过
# cmake --build build_x86_64 --target boot
# cmake --build build_x86_64 --target kernel
cmake --preset=build_x86_64
cmake --build build_x86_64 --target boot
cmake --build build_x86_64 --target kernel
cmake --build build_x86_64 --target unit-test
cmake --build build_x86_64 --target coverage
- name: riscv64
run: |
cmake --preset=build_riscv64
# @todo ci 暂时跑不过
# cmake --build build_riscv64 --target kernel
cmake --build build_riscv64 --target kernel
- name: aarch64
run: |
cmake --preset=build_aarch64
cmake --build build_aarch64 --target boot
cmake --build build_aarch64 --target kernel
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
with:
files: build_x86_64/coverage/coverage.info
verbose: true

# build_osx:
# runs-on: macos-latest
# steps:
# - name: get code
# uses: actions/checkout@v3
#
# - name: setup toolchain
# shell: bash
# run: |
# brew install x86_64-elf-gcc
# brew tap riscv-software-src/riscv
# brew install riscv-tools
#
# - name: make build dir
# shell: bash
# run: |
# mkdir ${{github.workspace}}/build
#
# - name: osx-i386
# shell: bash
# working-directory: ${{github.workspace}}/build
# run: |
# cmake -DTOOLCHAIN_PREFIX=x86_64-elf- -DCMAKE_C_COMPILER=x86_64-elf-gcc -DCMAKE_CXX_COMPILER=x86_64-elf-g++ -DARCH=i386 -DCMAKE_BUILD_TYPE=RELEASE -DHAVE_FLAG_SEARCH_PATHS_FIRST=0 ..
# make
# rm -rf ./*
#
# - name: osx-x86_64
# shell: bash
# working-directory: ${{github.workspace}}/build
# run: |
# cmake -DTOOLCHAIN_PREFIX=x86_64-elf- -DCMAKE_C_COMPILER=x86_64-elf-gcc -DCMAKE_CXX_COMPILER=x86_64-elf-g++ -DARCH=x86_64 -DCMAKE_BUILD_TYPE=RELEASE -DHAVE_FLAG_SEARCH_PATHS_FIRST=0 ..
# make
# rm -rf ./*
#
# - name: osx-riscv64
# shell: bash
# working-directory: ${{github.workspace}}/build
# run: |
# cmake -DTOOLCHAIN_PREFIX=riscv64-unknown-elf- -DCMAKE_C_COMPILER=riscv64-unknown-elf-gcc -DCMAKE_CXX_COMPILER=riscv64-unknown-elf-g++ -DARCH=riscv64 -DCMAKE_BUILD_TYPE=RELEASE -DHAVE_FLAG_SEARCH_PATHS_FIRST=0 ..
# make
# rm -rf ./*
- name: Build Doc
if: github.ref == 'refs/heads/main'
run: |
cmake --preset=build_x86_64
cmake --build build_x86_64 --target doc
- name: Publish
if: github.ref == 'refs/heads/main'
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{secrets.GITHUB_TOKEN}}
publish_dir: ${{github.workspace}}/doc/html
6 changes: 1 addition & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,13 @@
#
# .gitignore for Simple-XX/SimpleKernel.

*.o
.DS_Store
build
build_aarch64
build_riscv64
build_x86_64
doc/html
cmake-build*
.gdbinit
tools/opensbi/build
.vscode
.idea
3rd
Doxyfile
.gdbinit
22 changes: 22 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

[submodule "3rd/printf_bare_metal"]
path = 3rd/printf_bare_metal
url = https://github.com/MRNIU/printf_bare_metal.git
[submodule "3rd/opensbi_interface"]
path = 3rd/opensbi_interface
url = https://github.com/MRNIU/opensbi_interface.git
[submodule "3rd/opensbi"]
path = 3rd/opensbi
url = https://github.com/riscv-software-src/opensbi.git
[submodule "3rd/gdbinit"]
path = 3rd/gdbinit
url = https://github.com/gdbinit/Gdbinit.git
[submodule "3rd/gnu-efi"]
path = 3rd/gnu-efi
url = https://github.com/ncroxon/gnu-efi.git
[submodule "3rd/dtc"]
path = 3rd/dtc
url = https://git.kernel.org/pub/scm/utils/dtc/dtc.git
[submodule "3rd/googletest"]
path = 3rd/googletest
url = https://github.com/google/googletest.git
1 change: 1 addition & 0 deletions 3rd/dtc
Submodule dtc added at c17d76
1 change: 1 addition & 0 deletions 3rd/gdbinit
Submodule gdbinit added at 40c819
1 change: 1 addition & 0 deletions 3rd/gnu-efi
Submodule gnu-efi added at 9e4797
1 change: 1 addition & 0 deletions 3rd/googletest
Submodule googletest added at 1d17ea
1 change: 1 addition & 0 deletions 3rd/opensbi
Submodule opensbi added at a2b255
1 change: 1 addition & 0 deletions 3rd/opensbi_interface
Submodule opensbi_interface added at 993b56
1 change: 1 addition & 0 deletions 3rd/printf_bare_metal
Submodule printf_bare_metal added at 127aaa
64 changes: 37 additions & 27 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")

# 导入项目配置
include(project_config)
# 导入头文件处理
include(add_header)
# 导入函数
include(functions)

Expand All @@ -41,42 +39,54 @@ include(compile_config)

# qemu 参数设置
list(APPEND QEMU_FLAGS
# 使用标准输出显示
-serial stdio
# 启动 telnet 服务,使用 2333 端口,不等待连接
-monitor ${QEMU_MONITOR_ARG}
# 不启用图形界面
-nographic
# 使用标准输出显示
-serial stdio
# 启动 telnet 服务,使用 2333 端口,不等待连接
-monitor ${QEMU_MONITOR_ARG}
)
# 目标平台参数
if(TARGET_ARCH STREQUAL "x86_64")
if (CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
list(APPEND QEMU_FLAGS
-m 128M
-net none
-bios ${ovmf_BINARY_DIR}/OVMF_${TARGET_ARCH}.fd
-hda fat:rw:./image/
-m 128M
-net none
-bios ${ovmf_BINARY_DIR}/OVMF_${CMAKE_SYSTEM_PROCESSOR}.fd
-hda fat:rw:./image/
)
elseif(TARGET_ARCH STREQUAL "riscv64")
elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL "riscv64")
list(APPEND QEMU_FLAGS
-machine virt
-nographic
# 可选项,qemu7.0 自带了 opensbi1.0
-bios ${opensbi_BINARY_DIR}/platform/generic/firmware/fw_jump.elf
-kernel $<TARGET_FILE:kernel>
-machine virt
# 可选项,qemu7.0 自带了 opensbi1.0
-bios ${opensbi_BINARY_DIR}/platform/generic/firmware/fw_jump.elf
-kernel $<TARGET_FILE:kernel>
# @todo 暂时还不支持 riscv64 的 uefi 启动
# 预期路线: qemu->uefi->opensbi + kernel(payload)
# -bios ${ovmf_BINARY_DIR}/OVMF_${CMAKE_SYSTEM_PROCESSOR}.fd
# -hda fat:rw:./image/
)
elseif(TARGET_ARCH STREQUAL "aarch64")
# @todo
endif()
elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64")
list(APPEND QEMU_FLAGS
-machine virt
-cpu cortex-a57
-m 128M
-net none
-bios ${ovmf_BINARY_DIR}/OVMF_${CMAKE_SYSTEM_PROCESSOR}.fd
-hda fat:rw:./image/
)
endif ()

# 添加要编译的目录
add_subdirectory(${PROJECT_SOURCE_DIR}/src)
add_subdirectory(${PROJECT_SOURCE_DIR}/test)
add_subdirectory(${PROJECT_SOURCE_DIR}/doc)

# 添加 run 和 debug target
add_run_target(NAME run
DEPENDS $<$<STREQUAL:${TARGET_ARCH},x86_64>:boot> kernel ${RUN_DEPENDS} ${DEBUG_DEPENDS}
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
TARGET ${TARGET_ARCH}
BOOT ${PROJECT_BINARY_DIR}/src/boot/boot.efi
KERNEL $<TARGET_FILE:kernel>
QEMU_FLAGS ${QEMU_FLAGS}
add_run_target(
DEPENDS ovmf $<$<STREQUAL:${CMAKE_SYSTEM_PROCESSOR},riscv64>:opensbi-fw_jump> $<$<STREQUAL:${CMAKE_SYSTEM_PROCESSOR},x86_64>:boot> $<$<STREQUAL:${CMAKE_SYSTEM_PROCESSOR},riscv64>:boot> $<$<STREQUAL:${CMAKE_SYSTEM_PROCESSOR},aarch64>:boot> kernel
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
TARGET ${CMAKE_SYSTEM_PROCESSOR}
BOOT ${PROJECT_BINARY_DIR}/src/boot/boot.efi
KERNEL $<TARGET_FILE:kernel>
QEMU_FLAGS ${QEMU_FLAGS}
)
Loading

0 comments on commit 430420f

Please sign in to comment.