Skip to content

Commit 430420f

Browse files
authored
Merge pull request #188 from MRNIU/boot
A completely new version of boot code
2 parents fdc917d + a3652c1 commit 430420f

File tree

140 files changed

+28176
-3155
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

140 files changed

+28176
-3155
lines changed

.clang-format

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
---
88
# @version clang-format version 15
99
# @see https://clang.llvm.org/docs/ClangFormatStyleOptions.html
10-
# 使用 LLVM 规范
11-
BasedOnStyle: LLVM
10+
# 使用 Google 规范
11+
BasedOnStyle: Google
1212
...

.github/workflows/workflow.yml

Lines changed: 30 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ env:
1515
CMAKE_BUILD_TYPE: Release
1616

1717
jobs:
18-
build_docs:
19-
name: Build and publish documentation
18+
build_ubuntu:
2019
runs-on: ubuntu-latest
2120
permissions:
2221
contents: write
@@ -25,90 +24,48 @@ jobs:
2524

2625
- name: Install dependencies
2726
run: |
28-
sudo apt update
29-
sudo apt install --fix-missing -y doxygen graphviz clang-format clang-tidy cppcheck qemu-system lcov
30-
sudo apt install --fix-missing -y gcc g++ gcc-riscv64-linux-gnu g++-riscv64-linux-gnu gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
31-
32-
- name: Build
33-
run: |
34-
cmake --preset=build_x86_64
35-
cmake --build build_x86_64 --target doc
36-
37-
- name: Publish
38-
uses: peaceiris/actions-gh-pages@v3
39-
with:
40-
github_token: ${{ secrets.GITHUB_TOKEN }}
41-
publish_dir: ${{github.workspace}}/doc/html
42-
43-
build_ubuntu:
44-
runs-on: ubuntu-latest
45-
steps:
46-
- uses: actions/checkout@v3
47-
48-
- name: Install dependencies
49-
run: |
50-
sudo apt update
51-
sudo apt install --fix-missing -y doxygen graphviz clang-format clang-tidy cppcheck qemu-system lcov
27+
sudo apt update --fix-missing -y
28+
sudo apt upgrade --fix-missing -y
5229
sudo apt install --fix-missing -y gcc g++ gcc-riscv64-linux-gnu g++-riscv64-linux-gnu gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
30+
sudo apt install --fix-missing -y cmake qemu-system gdb-multiarch
31+
sudo apt install --fix-missing -y doxygen graphviz
32+
sudo apt install --fix-missing -y clang-format clang-tidy cppcheck libgtest-dev lcov
33+
git submodule update --init --recursive
5334
5435
- name: x86_64
5536
run: |
56-
cmake --preset=build_x86_64
57-
# @todo ci 暂时跑不过
58-
# cmake --build build_x86_64 --target boot
59-
# cmake --build build_x86_64 --target kernel
37+
cmake --preset=build_x86_64
38+
cmake --build build_x86_64 --target boot
39+
cmake --build build_x86_64 --target kernel
40+
cmake --build build_x86_64 --target unit-test
6041
cmake --build build_x86_64 --target coverage
6142
6243
- name: riscv64
6344
run: |
6445
cmake --preset=build_riscv64
65-
# @todo ci 暂时跑不过
66-
# cmake --build build_riscv64 --target kernel
46+
cmake --build build_riscv64 --target kernel
47+
48+
- name: aarch64
49+
run: |
50+
cmake --preset=build_aarch64
51+
cmake --build build_aarch64 --target boot
52+
cmake --build build_aarch64 --target kernel
6753
6854
- name: Upload coverage reports to Codecov
6955
uses: codecov/codecov-action@v3
7056
with:
7157
files: build_x86_64/coverage/coverage.info
7258
verbose: true
7359

74-
# build_osx:
75-
# runs-on: macos-latest
76-
# steps:
77-
# - name: get code
78-
# uses: actions/checkout@v3
79-
#
80-
# - name: setup toolchain
81-
# shell: bash
82-
# run: |
83-
# brew install x86_64-elf-gcc
84-
# brew tap riscv-software-src/riscv
85-
# brew install riscv-tools
86-
#
87-
# - name: make build dir
88-
# shell: bash
89-
# run: |
90-
# mkdir ${{github.workspace}}/build
91-
#
92-
# - name: osx-i386
93-
# shell: bash
94-
# working-directory: ${{github.workspace}}/build
95-
# run: |
96-
# 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 ..
97-
# make
98-
# rm -rf ./*
99-
#
100-
# - name: osx-x86_64
101-
# shell: bash
102-
# working-directory: ${{github.workspace}}/build
103-
# run: |
104-
# 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 ..
105-
# make
106-
# rm -rf ./*
107-
#
108-
# - name: osx-riscv64
109-
# shell: bash
110-
# working-directory: ${{github.workspace}}/build
111-
# run: |
112-
# 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 ..
113-
# make
114-
# rm -rf ./*
60+
- name: Build Doc
61+
if: github.ref == 'refs/heads/main'
62+
run: |
63+
cmake --preset=build_x86_64
64+
cmake --build build_x86_64 --target doc
65+
66+
- name: Publish
67+
if: github.ref == 'refs/heads/main'
68+
uses: peaceiris/actions-gh-pages@v3
69+
with:
70+
github_token: ${{secrets.GITHUB_TOKEN}}
71+
publish_dir: ${{github.workspace}}/doc/html

.gitignore

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,13 @@
44
#
55
# .gitignore for Simple-XX/SimpleKernel.
66

7-
*.o
87
.DS_Store
9-
build
108
build_aarch64
119
build_riscv64
1210
build_x86_64
1311
doc/html
14-
cmake-build*
1512
.gdbinit
16-
tools/opensbi/build
1713
.vscode
1814
.idea
19-
3rd
2015
Doxyfile
16+
.gdbinit

.gitmodules

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
[submodule "3rd/printf_bare_metal"]
3+
path = 3rd/printf_bare_metal
4+
url = https://github.com/MRNIU/printf_bare_metal.git
5+
[submodule "3rd/opensbi_interface"]
6+
path = 3rd/opensbi_interface
7+
url = https://github.com/MRNIU/opensbi_interface.git
8+
[submodule "3rd/opensbi"]
9+
path = 3rd/opensbi
10+
url = https://github.com/riscv-software-src/opensbi.git
11+
[submodule "3rd/gdbinit"]
12+
path = 3rd/gdbinit
13+
url = https://github.com/gdbinit/Gdbinit.git
14+
[submodule "3rd/gnu-efi"]
15+
path = 3rd/gnu-efi
16+
url = https://github.com/ncroxon/gnu-efi.git
17+
[submodule "3rd/dtc"]
18+
path = 3rd/dtc
19+
url = https://git.kernel.org/pub/scm/utils/dtc/dtc.git
20+
[submodule "3rd/googletest"]
21+
path = 3rd/googletest
22+
url = https://github.com/google/googletest.git

3rd/dtc

Submodule dtc added at c17d76a

3rd/gdbinit

Submodule gdbinit added at 40c819b

3rd/gnu-efi

Submodule gnu-efi added at 9e47972

3rd/googletest

Submodule googletest added at 1d17ea1

3rd/opensbi

Submodule opensbi added at a2b255b

3rd/opensbi_interface

Submodule opensbi_interface added at 993b56c

3rd/printf_bare_metal

Submodule printf_bare_metal added at 127aaad

CMakeLists.txt

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
2828

2929
# 导入项目配置
3030
include(project_config)
31-
# 导入头文件处理
32-
include(add_header)
3331
# 导入函数
3432
include(functions)
3533

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

4240
# qemu 参数设置
4341
list(APPEND QEMU_FLAGS
44-
# 使用标准输出显示
45-
-serial stdio
46-
# 启动 telnet 服务,使用 2333 端口,不等待连接
47-
-monitor ${QEMU_MONITOR_ARG}
42+
# 不启用图形界面
43+
-nographic
44+
# 使用标准输出显示
45+
-serial stdio
46+
# 启动 telnet 服务,使用 2333 端口,不等待连接
47+
-monitor ${QEMU_MONITOR_ARG}
4848
)
4949
# 目标平台参数
50-
if(TARGET_ARCH STREQUAL "x86_64")
50+
if (CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
5151
list(APPEND QEMU_FLAGS
52-
-m 128M
53-
-net none
54-
-bios ${ovmf_BINARY_DIR}/OVMF_${TARGET_ARCH}.fd
55-
-hda fat:rw:./image/
52+
-m 128M
53+
-net none
54+
-bios ${ovmf_BINARY_DIR}/OVMF_${CMAKE_SYSTEM_PROCESSOR}.fd
55+
-hda fat:rw:./image/
5656
)
57-
elseif(TARGET_ARCH STREQUAL "riscv64")
57+
elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL "riscv64")
5858
list(APPEND QEMU_FLAGS
59-
-machine virt
60-
-nographic
61-
# 可选项,qemu7.0 自带了 opensbi1.0
62-
-bios ${opensbi_BINARY_DIR}/platform/generic/firmware/fw_jump.elf
63-
-kernel $<TARGET_FILE:kernel>
59+
-machine virt
60+
# 可选项,qemu7.0 自带了 opensbi1.0
61+
-bios ${opensbi_BINARY_DIR}/platform/generic/firmware/fw_jump.elf
62+
-kernel $<TARGET_FILE:kernel>
63+
# @todo 暂时还不支持 riscv64 的 uefi 启动
64+
# 预期路线: qemu->uefi->opensbi + kernel(payload)
65+
# -bios ${ovmf_BINARY_DIR}/OVMF_${CMAKE_SYSTEM_PROCESSOR}.fd
66+
# -hda fat:rw:./image/
6467
)
65-
elseif(TARGET_ARCH STREQUAL "aarch64")
66-
# @todo
67-
endif()
68+
elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64")
69+
list(APPEND QEMU_FLAGS
70+
-machine virt
71+
-cpu cortex-a57
72+
-m 128M
73+
-net none
74+
-bios ${ovmf_BINARY_DIR}/OVMF_${CMAKE_SYSTEM_PROCESSOR}.fd
75+
-hda fat:rw:./image/
76+
)
77+
endif ()
6878

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

7484
# 添加 run 和 debug target
75-
add_run_target(NAME run
76-
DEPENDS $<$<STREQUAL:${TARGET_ARCH},x86_64>:boot> kernel ${RUN_DEPENDS} ${DEBUG_DEPENDS}
77-
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
78-
TARGET ${TARGET_ARCH}
79-
BOOT ${PROJECT_BINARY_DIR}/src/boot/boot.efi
80-
KERNEL $<TARGET_FILE:kernel>
81-
QEMU_FLAGS ${QEMU_FLAGS}
85+
add_run_target(
86+
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
87+
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
88+
TARGET ${CMAKE_SYSTEM_PROCESSOR}
89+
BOOT ${PROJECT_BINARY_DIR}/src/boot/boot.efi
90+
KERNEL $<TARGET_FILE:kernel>
91+
QEMU_FLAGS ${QEMU_FLAGS}
8292
)

0 commit comments

Comments
 (0)