Skip to content

Commit

Permalink
Merge branch 'new_intr' into memory
Browse files Browse the repository at this point in the history
Signed-off-by: Zone.N <[email protected]>
  • Loading branch information
MRNIU committed Aug 26, 2024
2 parents 58cdc82 + a54448c commit f4413c0
Show file tree
Hide file tree
Showing 54 changed files with 248 additions and 516 deletions.
4 changes: 1 addition & 3 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 Down Expand Up @@ -85,7 +83,7 @@ add_subdirectory(${PROJECT_SOURCE_DIR}/doc)

# 添加 run 和 debug target
add_run_target(
DEPENDS $<$<STREQUAL:${CMAKE_SYSTEM_PROCESSOR},x86_64>:boot> $<$<STREQUAL:${CMAKE_SYSTEM_PROCESSOR},riscv64>:boot> $<$<STREQUAL:${CMAKE_SYSTEM_PROCESSOR},aarch64>:boot> kernel
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
Expand Down
2 changes: 1 addition & 1 deletion CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"cacheVariables": {
"CMAKE_VERBOSE_MAKEFILE": {
"type": "BOOL",
"value": "FALSE"
"value": "TRUE"
},
"CMAKE_EXPORT_COMPILE_COMMANDS": {
"type": "BOOL",
Expand Down
29 changes: 29 additions & 0 deletions cmake/3rd.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,14 @@ if (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "riscv64")
${opensbi_SOURCE_DIR}/include
${opensbi_BINARY_DIR}/include
)
add_library(opensbi-fw_jump INTERFACE)
add_dependencies(opensbi-fw_jump opensbi)
target_include_directories(opensbi-fw_jump INTERFACE
${dtc_BINARY_DIR}/libfdt
)
target_link_libraries(opensbi-fw_jump INTERFACE
${dtc_BINARY_DIR}/libfdt/libfdt.a
)

# https://github.com/MRNIU/opensbi_interface.git
add_subdirectory(3rd/opensbi_interface)
Expand Down Expand Up @@ -152,6 +160,14 @@ add_custom_target(dtc
COMMAND
make clean
)
add_library(dtc-lib INTERFACE)
add_dependencies(dtc-lib dtc)
target_include_directories(dtc-lib INTERFACE
${dtc_BINARY_DIR}/libfdt
)
target_link_libraries(dtc-lib INTERFACE
${dtc_BINARY_DIR}/libfdt/libfdt.a
)

# https://github.com/ncroxon/gnu-efi.git
set(gnu-efi_SOURCE_DIR ${CMAKE_SOURCE_DIR}/3rd/gnu-efi)
Expand Down Expand Up @@ -189,6 +205,19 @@ add_custom_target(gnu-efi
${gnu-efi_SOURCE_DIR}/inc
${gnu-efi_BINARY_DIR}/inc
)
add_library(gnu-efi-lib INTERFACE)
add_dependencies(gnu-efi-lib gnu-efi)
target_include_directories(gnu-efi-lib INTERFACE
${gnu-efi_BINARY_DIR}/inc
${gnu-efi_BINARY_DIR}/inc/${CMAKE_SYSTEM_PROCESSOR}
${gnu-efi_BINARY_DIR}/inc/protocol
)
target_link_libraries(gnu-efi-lib INTERFACE
${gnu-efi_BINARY_DIR}/gnuefi/reloc_${CMAKE_SYSTEM_PROCESSOR}.o
${gnu-efi_BINARY_DIR}/gnuefi/crt0-efi-${CMAKE_SYSTEM_PROCESSOR}.o
${gnu-efi_BINARY_DIR}/gnuefi/libgnuefi.a
${gnu-efi_BINARY_DIR}/lib/libefi.a
)

# ovmf
# @todo 使用互联网连接或从 edk2 编译
Expand Down
58 changes: 0 additions & 58 deletions cmake/add_header.cmake

This file was deleted.

104 changes: 45 additions & 59 deletions cmake/compile_config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,16 @@
# compile_config.cmake for Simple-XX/SimpleKernel.
# 配置信息

# 通用宏定义
add_library(compile_definitions INTERFACE)
target_compile_definitions(compile_definitions INTERFACE
$<$<CONFIG:Release>:SIMPLEKERNEL_RELEASE>
$<$<CONFIG:Debug>:SIMPLEKERNEL_DEBUG>
)

# 通用编译选项
list(APPEND COMMON_COMPILE_OPTIONS
add_library(compile_options INTERFACE)
target_compile_options(compile_options INTERFACE
# 如果 CMAKE_BUILD_TYPE 为 Release 则使用 -O3 -Werror,否则使用 -O0 -ggdb
# -g 在 Debug 模式下由 cmake 自动添加
$<$<CONFIG:Release>:-O3;-Werror>
Expand Down Expand Up @@ -60,30 +68,28 @@ list(APPEND COMMON_COMPILE_OPTIONS
)

# 通用链接选项
list(APPEND COMMON_LINK_OPTIONS
add_library(link_options INTERFACE)
target_link_options(link_options INTERFACE
# 不链接 ctr0 等启动代码
-nostartfiles
)

# 通用库选项
list(APPEND COMMON_LINK_LIB
add_library(link_libraries INTERFACE)
target_link_libraries(link_libraries INTERFACE
compile_definitions
compile_options
link_options
)

# 通用宏定义
list(APPEND COMMON_DEFINITIONS
$<$<CONFIG:Release>:SIMPLEKERNEL_RELEASE>
$<$<CONFIG:Debug>:SIMPLEKERNEL_DEBUG>
)

list(APPEND DEFAULT_BOOT_DEFINITIONS
${COMMON_DEFINITIONS}

add_library(boot_compile_definitions INTERFACE)
target_compile_definitions(boot_compile_definitions INTERFACE
# 使用 gnu-efi
GNU_EFI_USE_MS_ABI
)

list(APPEND DEFAULT_BOOT_COMPILE_OPTIONS
${COMMON_COMPILE_OPTIONS}
add_library(boot_compile_options INTERFACE)
target_compile_options(boot_compile_options INTERFACE
# 使用 2 字节 wchar_t
-fshort-wchar
# 允许 wchar_t
Expand All @@ -97,9 +103,8 @@ list(APPEND DEFAULT_BOOT_COMPILE_OPTIONS
>
)

list(APPEND DEFAULT_BOOT_LINK_OPTIONS
${COMMON_LINK_OPTIONS}

add_library(boot_link_options INTERFACE)
target_link_options(boot_link_options INTERFACE
$<$<STREQUAL:${CMAKE_SYSTEM_PROCESSOR},x86_64>:
# 编译为共享库
-shared
Expand All @@ -120,43 +125,37 @@ list(APPEND DEFAULT_BOOT_LINK_OPTIONS
>
)

list(APPEND DEFAULT_BOOT_LINK_LIB
${COMMON_LINK_LIB}
add_library(boot_link_libraries INTERFACE)
target_link_libraries(boot_link_libraries INTERFACE
link_libraries
boot_compile_definitions
boot_compile_options
boot_link_options

# 目标平台编译选项
$<$<STREQUAL:${CMAKE_SYSTEM_PROCESSOR},x86_64>:
# 链接 gnu-efi
${gnu-efi_BINARY_DIR}/gnuefi/reloc_${CMAKE_SYSTEM_PROCESSOR}.o
${gnu-efi_BINARY_DIR}/gnuefi/crt0-efi-${CMAKE_SYSTEM_PROCESSOR}.o
${gnu-efi_BINARY_DIR}/gnuefi/libgnuefi.a
${gnu-efi_BINARY_DIR}/lib/libefi.a
gnu-efi-lib
>

$<$<STREQUAL:${CMAKE_SYSTEM_PROCESSOR},riscv64>:
# 链接 gnu-efi
${gnu-efi_BINARY_DIR}/gnuefi/reloc_${CMAKE_SYSTEM_PROCESSOR}.o
${gnu-efi_BINARY_DIR}/gnuefi/crt0-efi-${CMAKE_SYSTEM_PROCESSOR}.o
${gnu-efi_BINARY_DIR}/gnuefi/libgnuefi.a
${gnu-efi_BINARY_DIR}/lib/libefi.a
gnu-efi-lib
>

$<$<STREQUAL:${CMAKE_SYSTEM_PROCESSOR},aarch64>:
# 链接 gnu-efi
${gnu-efi_BINARY_DIR}/gnuefi/reloc_${CMAKE_SYSTEM_PROCESSOR}.o
${gnu-efi_BINARY_DIR}/gnuefi/crt0-efi-${CMAKE_SYSTEM_PROCESSOR}.o
${gnu-efi_BINARY_DIR}/gnuefi/libgnuefi.a
${gnu-efi_BINARY_DIR}/lib/libefi.a
gnu-efi-lib
>
)

list(APPEND DEFAULT_KERNEL_DEFINITIONS
${COMMON_DEFINITIONS}

add_library(kernel_compile_definitions INTERFACE)
target_compile_definitions(kernel_compile_definitions INTERFACE
USE_NO_RELAX=$<BOOL:${USE_NO_RELAX}>
)

list(APPEND DEFAULT_KERNEL_COMPILE_OPTIONS
${COMMON_COMPILE_OPTIONS}

add_library(kernel_compile_options INTERFACE)
target_compile_options(kernel_compile_options INTERFACE
$<$<STREQUAL:${CMAKE_SYSTEM_PROCESSOR},x86_64>:
# 使用 kernel 内存模型
-mcmodel=large
Expand All @@ -169,9 +168,8 @@ list(APPEND DEFAULT_KERNEL_COMPILE_OPTIONS
>
)

list(APPEND DEFAULT_KERNEL_LINK_OPTIONS
${COMMON_LINK_OPTIONS}

add_library(kernel_link_options INTERFACE)
target_link_options(kernel_link_options INTERFACE
# 链接脚本
-T ${CMAKE_SOURCE_DIR}/src/kernel/arch/${CMAKE_SYSTEM_PROCESSOR}/link.ld

Expand All @@ -191,11 +189,15 @@ list(APPEND DEFAULT_KERNEL_LINK_OPTIONS
>
)

list(APPEND DEFAULT_KERNEL_LINK_LIB
${COMMON_LINK_LIB}
add_library(kernel_link_libraries INTERFACE)
target_link_libraries(kernel_link_libraries INTERFACE
link_libraries
kernel_compile_definitions
kernel_compile_options
kernel_link_options

printf_bare_metal
${dtc_BINARY_DIR}/libfdt/libfdt.a
dtc-lib

$<$<STREQUAL:${CMAKE_SYSTEM_PROCESSOR},riscv64>:
opensbi_interface
Expand All @@ -204,19 +206,3 @@ list(APPEND DEFAULT_KERNEL_LINK_LIB
$<$<STREQUAL:${CMAKE_SYSTEM_PROCESSOR},aarch64>:
>
)

# 编译依赖
list(APPEND COMPILE_DEPENDS
ovmf
gnu-efi
dtc
printf_bare_metal
)
if (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64")
elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "riscv64")
list(APPEND COMPILE_DEPENDS
opensbi
opensbi_interface
)
elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "aarch64")
endif ()
27 changes: 4 additions & 23 deletions src/boot/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,33 +20,14 @@ add_executable(${PROJECT_NAME}
)

# 添加头文件
add_header_project(${PROJECT_NAME})
add_header_boot(${PROJECT_NAME})
add_header_3rd(${PROJECT_NAME})

# 添加定义
target_compile_definitions(${PROJECT_NAME} PRIVATE
${DEFAULT_BOOT_DEFINITIONS}
)

# 添加编译参数
target_compile_options(${PROJECT_NAME} PRIVATE
${DEFAULT_BOOT_COMPILE_OPTIONS}
)

# 添加链接参数
target_link_options(${PROJECT_NAME} PRIVATE
${DEFAULT_BOOT_LINK_OPTIONS}
target_include_directories(${PROJECT_NAME} PRIVATE
include
${CMAKE_SOURCE_DIR}/src
)

# 添加要链接的库
target_link_libraries(${PROJECT_NAME} PRIVATE
${DEFAULT_BOOT_LINK_LIB}
)

# 添加依赖
add_dependencies(${PROJECT_NAME}
${COMPILE_DEPENDS}
boot_link_libraries
)

set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "")
Expand Down
1 change: 1 addition & 0 deletions src/boot/boot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ efi_main(EFI_HANDLE image_handle, EFI_SYSTEM_TABLE *system_table) {
uint64_t elf_addr;
size_t elf_size;
} basic_info;
std::fill_n(reinterpret_cast<uint8_t *>(&basic_info), sizeof(basic_info), 0);

// 获取物理内存信息
auto [physical_memory_addr, physical_memory_size] = memory.GetMemory();
Expand Down
Loading

0 comments on commit f4413c0

Please sign in to comment.