Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
254 additions
and
346 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
cmake_minimum_required(VERSION 3.11.4) | ||
include(ExternalProject) | ||
include(cmake/toolchain.cmake) | ||
|
||
project(pxos ASM C CXX) | ||
|
||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) | ||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -nostdlib -ffreestanding") | ||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -nostdlib -ffreestanding") | ||
|
||
set(SRCDIR "${CMAKE_SOURCE_DIR}/src") | ||
|
||
include(cmake/modules.cmake) | ||
include(cmake/kernel.cmake) | ||
include(cmake/deps.cmake) | ||
include(cmake/iso.cmake) | ||
include(cmake/launch.cmake) | ||
|
||
include(cmake/cpplint.cmake) | ||
include(cmake/pvs.cmake) | ||
add_lint_target("${LINT_SOURCES}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
function(add_lint_target SOURCES_LIST) | ||
find_program(LINT cpplint) | ||
list(REMOVE_DUPLICATES SOURCES_LIST) | ||
list(SORT SOURCES_LIST) | ||
list(FILTER SOURCES_LIST INCLUDE REGEX "\\.(c(c|uh?|pp|xx|\\+\\+|)?|h(pp|\\+\\+|xx)?)$") | ||
|
||
add_custom_target(lint | ||
COMMAND "${CMAKE_COMMAND}" -E chdir | ||
"${CMAKE_CURRENT_SOURCE_DIR}" | ||
"${LINT}" ${SOURCES_LIST} | ||
DEPENDS ${SOURCES_LIST} | ||
VERBATIM | ||
) | ||
endfunction() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
ExternalProject_Add( | ||
ovmf.fd | ||
URL https://mirrors.edge.kernel.org/ubuntu/pool/universe/e/edk2/ovmf_0~20180205.c0d9813c-2_all.deb | ||
URL_HASH SHA256=6c73c1b99fe745d95dd5fc3e1d09924018628d40d8cbad556696f2906d335636 | ||
EXCLUDE_FROM_ALL TRUE | ||
CONFIGURE_COMMAND "" | ||
BUILD_COMMAND ${TAR} xf <SOURCE_DIR>/data.tar.xz -C <BINARY_DIR> --strip-components 4 ./usr/share/ovmf/OVMF.fd | ||
INSTALL_COMMAND "" | ||
) | ||
ExternalProject_Get_Property(ovmf.fd BINARY_DIR) | ||
set(OVMF_PATH ${BINARY_DIR}/OVMF.fd) | ||
|
||
ExternalProject_Add( | ||
syslinux | ||
URL https://mirrors.edge.kernel.org/pub/linux/utils/boot/syslinux/6.xx/syslinux-6.03.tar.xz | ||
URL_HASH SHA256=26d3986d2bea109d5dc0e4f8c4822a459276cf021125e8c9f23c3cca5d8c850e | ||
EXCLUDE_FROM_ALL TRUE | ||
DOWNLOAD_NO_EXTRACT ON | ||
CONFIGURE_COMMAND "" | ||
BUILD_COMMAND ${TAR} xf <DOWNLOADED_FILE> -C <SOURCE_DIR> --strip-components 3 syslinux-6.03/bios/core/isolinux.bin syslinux-6.03/bios/com32/elflink/ldlinux/ldlinux.c32 syslinux-6.03/bios/com32/lib/libcom32.c32 syslinux-6.03/bios/com32/mboot/mboot.c32 | ||
COMMAND cp <SOURCE_DIR>/isolinux.bin <SOURCE_DIR>/elflink/ldlinux/ldlinux.c32 <SOURCE_DIR>/lib/libcom32.c32 <SOURCE_DIR>/mboot/mboot.c32 <BINARY_DIR>/ | ||
INSTALL_COMMAND "" | ||
) | ||
ExternalProject_Get_Property(syslinux BINARY_DIR) | ||
set(SYSLINUX_PATH ${BINARY_DIR}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
set(ISOROOT isodir) | ||
set(ISONAME "PhoeniX-OS") | ||
set(ISOOPTS -quiet -U -A ${ISONAME} -V ${ISONAME} -volset ${ISONAME} -J -joliet-long -r) | ||
set(ISOOPTS ${ISOOPTS} -b isolinux.bin -c boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table) | ||
set(ISOOPTS ${ISOOPTS} -eltorito-alt-boot -e efiboot.img -no-emul-boot) | ||
add_custom_target(phoenixos.iso | ||
mkdir -p ${ISOROOT} | ||
COMMAND truncate -s 4m ${ISOROOT}/efiboot.img | ||
COMMAND ${MKFAT} -t 1 -h 1 -s 8192 -v EFI -L 32 -i ${ISOROOT}/efiboot.img | ||
COMMAND ${MMD} -i ${ISOROOT}/efiboot.img ::efi | ||
COMMAND ${MMD} -i ${ISOROOT}/efiboot.img ::efi/boot | ||
COMMAND ${MCOPY} -i ${ISOROOT}/efiboot.img pxkrnl ::efi/boot/bootx64.efi | ||
COMMAND cp pxkrnl ${SYSLINUX_PATH}/isolinux.bin ${SYSLINUX_PATH}/ldlinux.c32 ${SYSLINUX_PATH}/libcom32.c32 ${SYSLINUX_PATH}/mboot.c32 ${ISOROOT}/ | ||
COMMAND echo 'default /mboot.c32 /pxkrnl' > ${ISOROOT}/isolinux.cfg | ||
COMMAND ${MKISO} ${ISOOPTS} -o phoenixos.iso ${ISOROOT} | ||
DEPENDS pxkrnl syslinux | ||
) | ||
add_custom_target(iso DEPENDS phoenixos.iso) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
set(LINKER_SCRIPT "${CMAKE_SOURCE_DIR}/ld/system.ld") | ||
|
||
set(KERNDIR_TAG kernel.cmake) | ||
|
||
file(GLOB_RECURSE KERNDIRS RELATIVE ${SRCDIR} ${SRCDIR}/**/${KERNDIR_TAG}) | ||
list(TRANSFORM KERNDIRS REPLACE "/${KERNDIR_TAG}$" "") | ||
list(TRANSFORM KERNDIRS REPLACE "/" ".") | ||
|
||
foreach(kerndir ${KERNDIRS}) | ||
list (APPEND INCDIRS "${SRCDIR}/${kerndir}/include") | ||
endforeach(kerndir) | ||
|
||
list(REMOVE_ITEM KERNDIRS "boot") | ||
|
||
foreach(kerndir ${KERNDIRS}) | ||
file(GLOB SRCS "${SRCDIR}/${kerndir}/*.s" "${SRCDIR}/${kerndir}/*.c" "${SRCDIR}/${kerndir}/*.cpp") | ||
add_library(${kerndir} STATIC ${SRCS}) | ||
file(GLOB_RECURSE INCS ${SRCDIR}/${kerndir}/include/*.h ${SRCDIR}/${kerndir}/include/*.hpp) | ||
list(APPEND LINT_SOURCES ${INCS}) | ||
list(APPEND LINT_SOURCES ${SRCS}) | ||
target_include_directories(${kerndir} PRIVATE ${INCDIRS}) | ||
endforeach(kerndir) | ||
|
||
file(GLOB kern_SRCS "${SRCDIR}/boot/*.s" "${SRCDIR}/boot/*.c" "${SRCDIR}/boot/*.cpp") | ||
add_executable(pxkrnl.elf ${kern_SRCS}) | ||
file(GLOB_RECURSE kern_INCS ${SRCDIR}/boot/include/*.h ${SRCDIR}/boot/include/*.hpp) | ||
list(APPEND LINT_SOURCES ${kern_INCS}) | ||
list(APPEND LINT_SOURCES ${kern_SRCS}) | ||
target_include_directories(pxkrnl.elf PRIVATE ${INCDIRS}) | ||
|
||
set_target_properties(pxkrnl.elf PROPERTIES LINK_DEPENDS ${LINKER_SCRIPT}) | ||
set_target_properties(pxkrnl.elf PROPERTIES LINK_FLAGS "-T ${LINKER_SCRIPT}") | ||
target_link_libraries(pxkrnl.elf ${KERNDIRS} modules-linked) | ||
add_custom_target(pxkrnl ALL | ||
${CMAKE_LLVM_OBJCOPY} --strip-all pxkrnl.elf pxkrnl.elf.strip | ||
COMMAND ${CMAKE_OBJCOPY} -Opei-x86-64 --subsystem efi-app --file-alignment 1 --section-alignment 1 pxkrnl.elf.strip pxkrnl | ||
DEPENDS pxkrnl.elf | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
set(EFIROOT efi) | ||
add_custom_target(${EFIROOT} | ||
mkdir -p ${EFIROOT}/efi/boot/ | ||
COMMAND cp pxkrnl ${EFIROOT}/efi/boot/bootx64.efi | ||
DEPENDS pxkrnl | ||
) | ||
|
||
set(QEMU_FLAGS -smp cores=2,threads=2 -cpu Broadwell -serial stdio) | ||
add_custom_target(launch | ||
${QEMU} ${QEMU_FLAGS} -kernel pxkrnl | ||
DEPENDS pxkrnl | ||
) | ||
add_custom_target(launch-efi | ||
${QEMU} ${QEMU_FLAGS} -drive file=fat:rw:${EFIROOT},format=raw,media=disk -bios ${OVMF_PATH} | ||
DEPENDS ${EFIROOT} ovmf.fd | ||
) | ||
add_custom_target(launch-iso | ||
${QEMU} ${QEMU_FLAGS} -cdrom phoenixos.iso | ||
DEPENDS iso | ||
) | ||
add_custom_target(launch-iso-efi | ||
${QEMU} ${QEMU_FLAGS} -cdrom phoenixos.iso -bios ${OVMF_PATH} | ||
DEPENDS iso ovmf.fd | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
set(MODDIR_TAG module.cmake) | ||
|
||
file(GLOB_RECURSE MODDIRS RELATIVE ${SRCDIR} ${SRCDIR}/**/${MODDIR_TAG}) | ||
list(TRANSFORM MODDIRS REPLACE "/${MODDIR_TAG}$" "") | ||
|
||
file(WRITE ${CMAKE_BINARY_DIR}/modules.s ".section .modules, \"a\"\n") | ||
file(APPEND ${CMAKE_BINARY_DIR}/modules.s ".global __modules_start__\n__modules_start__:\n") | ||
add_library(modules-linked STATIC ${CMAKE_BINARY_DIR}/modules.s) | ||
foreach(moddir ${MODDIRS}) | ||
string(REPLACE "/" "." mod ${moddir}) | ||
set(ROOT_${mod} ${SRCDIR}/${moddir}) | ||
file(GLOB SRCS_${mod} ${ROOT_${mod}}/*.s ${ROOT_${mod}}/*.c ${ROOT_${mod}}/*.cpp) | ||
add_library(mod_${mod} SHARED ${SRCS_${mod}}) | ||
add_custom_command( | ||
TARGET mod_${mod} POST_BUILD | ||
COMMAND ${CMAKE_LLVM_OBJCOPY} --strip-non-alloc --strip-debug --strip-unneeded libmod_${mod}.so libmod_${mod}.strip.so | ||
COMMAND touch ${CMAKE_BINARY_DIR}/modules.s | ||
) | ||
list(APPEND LINT_SOURCES ${SRCS_${mod}}) | ||
file(GLOB_RECURSE INCS_${mod} ${ROOT_${mod}}/*.h ${ROOT_${mod}}/*.hpp) | ||
list(APPEND LINT_SOURCES ${INCS_${mod}}) | ||
add_dependencies(modules-linked mod_${mod}) | ||
file(APPEND ${CMAKE_BINARY_DIR}/modules.s ".global __module_${mod}\n__module_${mod}:\n") | ||
file(APPEND ${CMAKE_BINARY_DIR}/modules.s ".incbin \"libmod_${mod}.strip.so\"\n") | ||
endforeach(moddir) | ||
file(APPEND ${CMAKE_BINARY_DIR}/modules.s ".global __modules_end__\n__modules_end__:\n") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
find_program(PVS_ANALYZER pvs-studio-analyzer) | ||
find_program(PLOG_CONVERT plog-converter) | ||
|
||
set(PVS_LOG ${CMAKE_BINARY_DIR}/pvs.log) | ||
set(PVS_TASKS ${CMAKE_BINARY_DIR}/pvs.tasks) | ||
set(PVS_HTML ${CMAKE_BINARY_DIR}/pvs.html) | ||
set(PVS_FILTER "GA:1,2;OP:1,2,3;64:1;CS:1,2,3") | ||
|
||
add_custom_target(check-pvs | ||
COMMAND "${PVS_ANALYZER}" analyze -i -j4 -a13 -o "${PVS_LOG}" | ||
COMMAND "${PLOG_CONVERT}" -m cwe -a "${PVS_FILTER}" -t tasklist -o "${PVS_TASKS}" "${PVS_LOG}" | ||
COMMAND "${PLOG_CONVERT}" -m cwe -a "${PVS_FILTER}" -t fullhtml -o "${PVS_HTML}" "${PVS_LOG}" | ||
DEPENDS ${LINT_SOURCES} | ||
VERBATIM | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
set(CMAKE_SYSTEM_NAME Generic) | ||
set(CMAKE_SYSTEM_PROCESSOR x86_64) | ||
set(CMAKE_CROSSCOMPILING ON) | ||
|
||
set(CROSS_LLVM_PATH /usr/local/opt/llvm/bin) | ||
set(CROSS_BINUTILS_PATH /usr/local/opt/binutils/bin) | ||
|
||
find_program(CMAKE_C_COMPILER clang HINTS ${CROSS_LLVM_PATH}) | ||
find_program(CMAKE_CXX_COMPILER clang++ HINTS ${CROSS_LLVM_PATH}) | ||
|
||
find_program(CMAKE_LLVM_OBJCOPY llvm-objcopy HINTS ${CROSS_LLVM_PATH}) | ||
find_program(CMAKE_OBJCOPY objcopy HINTS ${CROSS_BINUTILS_PATH}) | ||
find_program(CMAKE_AR llvm-ar HINTS ${CROSS_LLVM_PATH}) | ||
find_program(CMAKE_NM llvm-nm HINTS ${CROSS_LLVM_PATH}) | ||
find_program(CMAKE_RANLIB llvm-ranlib HINTS ${CROSS_LLVM_PATH}) | ||
find_program(CMAKE_LINKER ld.lld HINTS ${CROSS_LLVM_PATH}) | ||
|
||
set(CMAKE_TRY_COMPILE_TARGET_TYPE "STATIC_LIBRARY") | ||
set(CROSS_LINKER_FLAGS "") | ||
set(CMAKE_CXX_LINK_EXECUTABLE "<CMAKE_LINKER> -o <TARGET> <LINK_FLAGS> <OBJECTS> <LINK_LIBRARIES>") | ||
set(CMAKE_CXX_CREATE_SHARED_LIBRARY "<CMAKE_LINKER> --shared -o <TARGET> <LINK_FLAGS> <OBJECTS> <LINK_LIBRARIES>") | ||
|
||
set(CMAKE_EXE_LINKER_FLAGS "${CROSS_LINKER_FLAGS} -g -nostdlib -O2 --hash-style=sysv" CACHE STRING "" FORCE) | ||
set(CMAKE_MODULE_LINKER_FLAGS "${CROSS_LINKER_FLAGS} -g -nostdlib -O2 --hash-style=sysv" CACHE STRING "" FORCE) | ||
set(CMAKE_SHARED_LINKER_FLAGS "${CROSS_LINKER_FLAGS} -g -nostdlib -O2 --hash-style=sysv" CACHE STRING "" FORCE) | ||
set(CMAKE_STATIC_LINKER_FLAGS ${CROSS_LINKER_FLAGS} CACHE STRING "" FORCE) | ||
|
||
set(CROSS_TARGET x86_64-none-elf) | ||
set(CROSS_COMPILER_FLAGS "") | ||
|
||
set(CMAKE_ASM_COMPILER_TARGET ${CROSS_TARGET}) | ||
set(CMAKE_C_COMPILER_TARGET ${CROSS_TARGET}) | ||
set(CMAKE_CXX_COMPILER_TARGET ${CROSS_TARGET}) | ||
|
||
set(CMAKE_C_FLAGS "${CROSS_COMPILER_FLAGS}" CACHE STRING "" FORCE) | ||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m64 -mno-sse") | ||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-exceptions -fno-rtti -fshort-wchar") | ||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O2 -Os") | ||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ffunction-sections -fdata-sections -fpic -fpie") | ||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Werror") | ||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wproperty-attribute-mismatch") | ||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wcast-qual -Wcast-align -Winline") | ||
|
||
set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "" FORCE) | ||
|
||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") | ||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu11") | ||
|
||
set(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> qc <TARGET> <OBJECTS>") | ||
set(CMAKE_CXX_ARCHIVE_CREATE "${CMAKE_C_ARCHIVE_CREATE}") | ||
|
||
find_program(TAR tar) | ||
find_program(MKISO xorriso) | ||
if(MKISO) | ||
set(MKISO ${MKISO} -as mkisofs) | ||
else() | ||
find_program(MKISO mkisofs) | ||
endif() | ||
|
||
find_program(MKFAT mformat) | ||
find_program(MCOPY mcopy) | ||
find_program(MMD mmd) | ||
find_program(QEMU qemu-system-x86_64) | ||
|
||
project(stub) | ||
SET_PROPERTY(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS TRUE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.