Skip to content

Commit

Permalink
feat(aarch64): add aarch64 support, not finished
Browse files Browse the repository at this point in the history
Signed-off-by: Zone.N <Zone.NiuZH@hotmail.com>
  • Loading branch information
MRNIU committed Jan 4, 2024
1 parent a923865 commit cd71f7d
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 15 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ tools/opensbi/build
.idea
3rd
Doxyfile
.gdbinit
9 changes: 8 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,14 @@ elseif(TARGET_ARCH STREQUAL "riscv64")
-kernel $<TARGET_FILE:kernel>
)
elseif(TARGET_ARCH STREQUAL "aarch64")
# @todo
list(APPEND QEMU_FLAGS
-machine virt
-cpu cortex-a57
-m 128M
-net none
-bios ${ovmf_BINARY_DIR}/OVMF_${TARGET_ARCH}.fd
-hda fat:rw:./image/
)
endif()

# 添加要编译的目录
Expand Down
17 changes: 17 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,23 @@
"value": "riscv64"
}
}
},
{
"name": "build_aarch64",
"hidden": false,
"inherits": [
"configurePresets_base"
],
"displayName": "build aarch64 kernel",
"description": "build aarch64 kernel",
"toolchainFile": "${sourceDir}/cmake/x86_64-aarch64-gcc.cmake",
"binaryDir": "${sourceDir}/build_aarch64",
"cacheVariables": {
"TARGET_ARCH": {
"type": "STRING",
"value": "aarch64"
}
}
}
]
}
10 changes: 6 additions & 4 deletions cmake/3rd.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ if (${TARGET_ARCH} STREQUAL "x86_64" OR ${TARGET_ARCH} STREQUAL "aarch64")
make_directory
${gnu-efi_BINARY_DIR}
COMMAND
make
make lib gnuefi inc
# @note 仅支持 gcc
CC=${CMAKE_C_COMPILER}
AR=${CMAKE_AR}
Expand Down Expand Up @@ -243,9 +243,11 @@ CPMAddPackage(
GIT_REPOSITORY https://github.com/libcxxrt/libcxxrt
GIT_TAG a0f7f5c139a7daf71de0de201b6c405d852b1dc1
)
target_compile_options(cxxrt-static PRIVATE
-fPIC
)
if (libcxxrt_ADDED)
target_compile_options(cxxrt-static PRIVATE
-fPIC
)
endif ()

# https://github.com/cpm-cmake/CPMLicenses.cmake
# 保持在 CPMAddPackage 的最后
Expand Down
9 changes: 4 additions & 5 deletions cmake/add_header.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,15 @@ function (add_header_driver _target)
endfunction ()

function (add_header_3rd _target)
if (${TARGET_ARCH} STREQUAL "x86_64")
if (${TARGET_ARCH} STREQUAL "x86_64" OR ${TARGET_ARCH} STREQUAL "aarch64")
target_include_directories(${_target} PRIVATE
${gnu-efi_BINARY_DIR}/inc)
${gnu-efi_BINARY_DIR}/inc)
target_include_directories(${_target} PRIVATE
${gnu-efi_BINARY_DIR}/inc/${TARGET_ARCH})
${gnu-efi_BINARY_DIR}/inc/${TARGET_ARCH})
target_include_directories(${_target} PRIVATE
${gnu-efi_BINARY_DIR}/inc/protocol)
${gnu-efi_BINARY_DIR}/inc/protocol)
elseif (${TARGET_ARCH} STREQUAL "riscv64")
target_include_directories(${_target} PRIVATE
${opensbi_BINARY_DIR}/include)
elseif (${TARGET_ARCH} STREQUAL "aarch64")
endif ()
endfunction ()
1 change: 1 addition & 0 deletions cmake/compile_config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -170,5 +170,6 @@ elseif (${TARGET_ARCH} STREQUAL "riscv64")
elseif (${TARGET_ARCH} STREQUAL "aarch64")
list(APPEND COMPILE_DEPENDS
gnu-efi
cxxrt-static
)
endif ()
53 changes: 53 additions & 0 deletions cmake/x86_64-aarch64-gcc.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@

# This file is a part of Simple-XX/SimpleKernel
# (https://github.com/Simple-XX/SimpleKernel).
#
# x86_64-aarch64-gcc.cmake for Simple-XX/SimpleKernel.

# 目标为无操作系统的环境
set(CMAKE_SYSTEM_NAME Generic)
# 目标架构
set(CMAKE_SYSTEM_PROCESSOR aarch64)

# @todo mac 测试
if (APPLE)
message(STATUS "Now is Apple system.")
# GCC
find_program(Compiler_gcc aarch64-linux-gnu-g++)
if (NOT Compiler_gcc)
message(FATAL_ERROR "aarch64-linux-gnu-g++ not found.\n"
"Run `brew install x86_64-elf-g++` to install.")
else ()
message(STATUS "Found aarch64-linux-gnu-g++ ${Compiler_gcc}")
endif ()

set(TOOLCHAIN_PREFIX aarch64-linux-gnu-)
set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}gcc)
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}g++)
set(CMAKE_READELF ${TOOLCHAIN_PREFIX}readelf)
set(CMAKE_AR ${TOOLCHAIN_PREFIX}ar)
set(CMAKE_LINKER ${TOOLCHAIN_PREFIX}ld)
set(CMAKE_NM ${TOOLCHAIN_PREFIX}nm)
set(CMAKE_OBJDUMP ${TOOLCHAIN_PREFIX}objdump)
set(CMAKE_RANLIB ${TOOLCHAIN_PREFIX}ranlib)
elseif (UNIX)
message(STATUS "Now is UNIX-like OS's.")
# GCC
find_program(Compiler_gcc aarch64-linux-gnu-g++)
if (NOT Compiler_gcc)
message(FATAL_ERROR "aarch64-linux-gnu-g++ not found.\n"
"Run `sudo apt install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu` to install.")
else ()
message(STATUS "Found aarch64-linux-gnu-g++ ${Compiler_gcc}")
endif ()

set(TOOLCHAIN_PREFIX aarch64-linux-gnu-)
set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}gcc)
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}g++)
set(CMAKE_READELF ${TOOLCHAIN_PREFIX}readelf)
set(CMAKE_AR ${TOOLCHAIN_PREFIX}ar)
set(CMAKE_LINKER ${TOOLCHAIN_PREFIX}ld)
set(CMAKE_NM ${TOOLCHAIN_PREFIX}nm)
set(CMAKE_OBJDUMP ${TOOLCHAIN_PREFIX}objdump)
set(CMAKE_RANLIB ${TOOLCHAIN_PREFIX}ranlib)
endif ()
6 changes: 1 addition & 5 deletions test/system_test/gnu_efi_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,5 @@ add_run_target(NAME ${PROJECT_NAME}
TARGET ${TARGET_ARCH}
BOOT ${BOOT_EFI_OUTPUT_NAME}
KERNEL $<TARGET_FILE:${PROJECT_NAME}_kernel>
QEMU_FLAGS
-m 128M
-net none
-bios ${ovmf_BINARY_DIR}/OVMF_${TARGET_ARCH}.fd
-hda fat:rw:./image/
QEMU_FLAGS ${QEMU_FLAGS}
)
Binary file added tools/ovmf/OVMF_aarch64.fd
Binary file not shown.

0 comments on commit cd71f7d

Please sign in to comment.