forked from xt-sys/exectos
Import build scripts and xtldr bootdata
This commit is contained in:
2
sdk/cmake/baseaddress.cmake
Normal file
2
sdk/cmake/baseaddress.cmake
Normal file
@@ -0,0 +1,2 @@
|
||||
# Set base addresses for all modules
|
||||
set(BASEADDRESS_XTOSKRNL 0x00400000)
|
129
sdk/cmake/functions.cmake
Normal file
129
sdk/cmake/functions.cmake
Normal file
@@ -0,0 +1,129 @@
|
||||
# This function enables the addition of ASM compiler switches
|
||||
function(add_compiler_asmflags FLAGS)
|
||||
if(NOT ${ARGC} EQUAL 1)
|
||||
message(FATAL_ERROR "Invalid number of arguments passed to add_compiler_asmflags() function")
|
||||
endif()
|
||||
set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} ${FLAGS}" PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
# This function enables the addition of C compiler switches
|
||||
function(add_compiler_cflags FLAGS)
|
||||
if(NOT ${ARGC} EQUAL 1)
|
||||
message(FATAL_ERROR "Invalid number of arguments passed to add_compiler_cflags() function")
|
||||
endif()
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${FLAGS}" PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
# This function enables the addition of C/C++ compilers switches
|
||||
function(add_compiler_ccxxflags FLAGS)
|
||||
if(NOT ${ARGC} EQUAL 1)
|
||||
message(FATAL_ERROR "Invalid number of arguments passed to add_compiler_ccxxflags() function")
|
||||
endif()
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${FLAGS}" PARENT_SCOPE)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLAGS}" PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
# This function enables the addition of C++ compiler switches
|
||||
function(add_compiler_cxxflags FLAGS)
|
||||
if(NOT ${ARGC} EQUAL 1)
|
||||
message(FATAL_ERROR "Invalid number of arguments passed to add_compiler_cxxflags() function")
|
||||
endif()
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLAGS}" PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
# This function enables the addition of ASM/C/C++ compilers switches
|
||||
function(add_compiler_flags FLAGS)
|
||||
if(NOT ${ARGC} EQUAL 1)
|
||||
message(FATAL_ERROR "Invalid number of arguments passed to add_compiler_flags() function")
|
||||
endif()
|
||||
set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} ${FLAGS}" PARENT_SCOPE)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${FLAGS}" PARENT_SCOPE)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLAGS}" PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
# This function enables the addition of linker switches
|
||||
function(add_linker_flags FLAGS)
|
||||
if(NOT ${ARGC} EQUAL 1)
|
||||
message(FATAL_ERROR "Invalid number of arguments passwd to add_linker_flags() function")
|
||||
endif()
|
||||
foreach(TYPE EXE MODULE SHARED)
|
||||
set(CMAKE_${TYPE}_LINKER_FLAGS "${CMAKE_${TYPE}_LINKER_FLAGS} ${FLAGS}" PARENT_SCOPE)
|
||||
endforeach()
|
||||
endfunction()
|
||||
|
||||
# This function enabled the addition of linker switches for specified module
|
||||
function(add_module_linker_flags MODULE FLAGS)
|
||||
if(NOT ${ARGC} EQUAL 2)
|
||||
message(FATAL_ERROR "Invalid number of arguments passwd to add_module_linker_flags() function")
|
||||
endif()
|
||||
set_module_property(${MODULE} LINK_FLAGS ${FLAGS})
|
||||
endfunction()
|
||||
|
||||
# This function sets a property for specified module
|
||||
function(set_module_property MODULE PROPERTY FLAGS)
|
||||
if(NOT ${ARGC} EQUAL 3)
|
||||
message(FATAL_ERROR "Invalid number of arguments passwd to add_module_property() function")
|
||||
endif()
|
||||
get_target_property(VAL ${MODULE} ${PROPERTY})
|
||||
if(VAL)
|
||||
set(VAL "${VAL} ${FLAGS}")
|
||||
else()
|
||||
set(VAL "${FLAGS}")
|
||||
endif()
|
||||
set_property(TARGET ${MODULE} PROPERTY ${PROPERTY} ${VAL})
|
||||
endfunction()
|
||||
|
||||
# This function installs specified directory recursively under destination directory
|
||||
function(set_install_dir DIRECTORY DESTINATION)
|
||||
install(DIRECTORY ${DIRECTORY} DESTINATION ${EXECTOS_BINARY_DIR}/output/binaries/${DESTINATION})
|
||||
endfunction()
|
||||
|
||||
# This function installs specified file under destination directory
|
||||
function(set_install_file FILENAME DESTINATION)
|
||||
install(FILES ${FILENAME} DESTINATION ${EXECTOS_BINARY_DIR}/output/binaries/${DESTINATION})
|
||||
endfunction()
|
||||
|
||||
# This function installs specified target results under destination directory
|
||||
function(set_install_target TARGET DESTINATION)
|
||||
install(TARGETS ${TARGET} DESTINATION ${EXECTOS_BINARY_DIR}/output/binaries/${DESTINATION})
|
||||
endfunction()
|
||||
|
||||
# This function enables or disables binary ordinals export for specified module
|
||||
function(set_ordinals MODULE STATE)
|
||||
if(NOT ${ARGC} EQUAL 2)
|
||||
message(FATAL_ERROR "Invalid number of arguments passed to set_ordinals() function")
|
||||
endif()
|
||||
set_module_property(${MODULE} ENABLE_EXPORTS ${STATE})
|
||||
endfunction()
|
||||
|
||||
# This function is responsible for compiling module SPEC file
|
||||
function(set_specfile SPECFILE)
|
||||
if(NOT ${ARGC} EQUAL 1)
|
||||
message(FATAL_ERROR "Invalid number of arguments passed to set_specfile() function")
|
||||
endif()
|
||||
get_filename_component(FILENAME ${SPECFILE} NAME_WE)
|
||||
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${FILENAME}.def ${CMAKE_CURRENT_BINARY_DIR}/${FILENAME}.c
|
||||
COMMAND ${CMAKE_SPEC_COMPILER} -a=${ARCH} -d=${CMAKE_CURRENT_BINARY_DIR}/${FILENAME}.def -s=${CMAKE_CURRENT_BINARY_DIR}/${FILENAME}.c ${CMAKE_CURRENT_SOURCE_DIR}/${SPECFILE})
|
||||
endfunction()
|
||||
|
||||
# This function sets the the qemu disk image size (in MiB)
|
||||
function(set_disk_image_size SIZE)
|
||||
MATH(EXPR DISK_BLOCKS ${SIZE}*1024*1024/512)
|
||||
MATH(EXPR PART_BLOCKS ${DISK_BLOCKS}-2048)
|
||||
set(PROJECT_DISK_IMAGE_BLOCKS ${DISK_BLOCKS} CACHE INTERNAL "PROJECT_DISK_IMAGE_BLOCKS")
|
||||
set(PROJECT_PART_IMAGE_BLOCKS ${PART_BLOCKS} CACHE INTERNAL "PROJECT_PART_IMAGE_BLOCKS")
|
||||
endfunction()
|
||||
|
||||
# This target creates a disk image
|
||||
add_custom_target(diskimg
|
||||
DEPENDS install
|
||||
COMMAND sh -c "dd if=/dev/zero of=${EXECTOS_BINARY_DIR}/output/disk.img bs=512 count=${PROJECT_DISK_IMAGE_BLOCKS} &>/dev/null"
|
||||
COMMAND parted ${EXECTOS_BINARY_DIR}/output/disk.img -s -a minimal mklabel gpt
|
||||
COMMAND parted ${EXECTOS_BINARY_DIR}/output/disk.img -s -a minimal mkpart EFI FAT32 2048s ${PROJECT_PART_IMAGE_BLOCKS}s
|
||||
COMMAND parted ${EXECTOS_BINARY_DIR}/output/disk.img -s -a minimal toggle 1 boot
|
||||
COMMAND sh -c "dd if=/dev/zero of=${EXECTOS_BINARY_DIR}/output/part.img bs=512 count=${PROJECT_PART_IMAGE_BLOCKS} &>/dev/null"
|
||||
COMMAND mformat -i ${EXECTOS_BINARY_DIR}/output/part.img -h32 -t32 -n64 -L32
|
||||
COMMAND sh -c "mcopy -s -i ${EXECTOS_BINARY_DIR}/output/part.img ${EXECTOS_BINARY_DIR}/output/binaries/* ::"
|
||||
COMMAND sh -c "dd if=${EXECTOS_BINARY_DIR}/output/part.img of=${EXECTOS_BINARY_DIR}/output/disk.img bs=512 count=${PROJECT_PART_IMAGE_BLOCKS} seek=2048 conv=notrunc &>/dev/null"
|
||||
COMMAND rm ${EXECTOS_BINARY_DIR}/output/part.img
|
||||
VERBATIM)
|
17
sdk/cmake/toolchain.cmake
Normal file
17
sdk/cmake/toolchain.cmake
Normal file
@@ -0,0 +1,17 @@
|
||||
# Set target operating system name
|
||||
set(CMAKE_SYSTEM_NAME Windows)
|
||||
|
||||
# Set toolchain compilers
|
||||
set(CMAKE_ASM_COMPILER nasm)
|
||||
set(CMAKE_C_COMPILER clang-cl)
|
||||
set(CMAKE_CXX_COMPILER clang-cl)
|
||||
set(CMAKE_MC_COMPILER wmc)
|
||||
set(CMAKE_RC_COMPILER wrc)
|
||||
set(CMAKE_SPEC_COMPILER xtcspecc)
|
||||
|
||||
# Assume that C/C++ compiler is working
|
||||
set(CMAKE_C_COMPILER_WORKS 1)
|
||||
set(CMAKE_CXX_COMPILER_WORKS 1)
|
||||
|
||||
# Disable standard C libraries
|
||||
set(CMAKE_C_STANDARD_LIBRARIES "" CACHE INTERNAL "")
|
22
sdk/cmake/version.cmake
Normal file
22
sdk/cmake/version.cmake
Normal file
@@ -0,0 +1,22 @@
|
||||
# Set XTOS version
|
||||
set(XTOS_VERSION_MAJOR "0")
|
||||
set(XTOS_VERSION_MINOR "1")
|
||||
set(XTOS_VERSION_BUILD "devel")
|
||||
|
||||
# Set common XTOS version variables
|
||||
string(TIMESTAMP XTOS_VERSION_YEAR %Y)
|
||||
string(TIMESTAMP XTOS_VERSION_DATE "%d/%m/%Y %H:%M UTC" UTC)
|
||||
|
||||
# Set latest GIT revision
|
||||
set(XTOS_VERSION_HASH "unknown")
|
||||
if(EXISTS "${EXECTOS_SOURCE_DIR}/.git")
|
||||
execute_process(COMMAND git describe --abbrev=7 --long --always
|
||||
WORKING_DIRECTORY ${EXECTOS_SOURCE_DIR}
|
||||
OUTPUT_VARIABLE XTOS_VERSION_HASH
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
endif()
|
||||
|
||||
# Prepare xtver.h header file
|
||||
add_custom_target(xtver ALL COMMAND ${CMAKE_COMMAND} -E touch ${EXECTOS_SOURCE_DIR}/sdk/cmake/version/xtver.h.cmake)
|
||||
configure_file(sdk/cmake/version/xtver.h.cmake ${EXECTOS_BINARY_DIR}/sdk/includes/xtver.h)
|
||||
include_directories(${EXECTOS_BINARY_DIR}/sdk/includes)
|
25
sdk/cmake/version/xtver.h.cmake
Normal file
25
sdk/cmake/version/xtver.h.cmake
Normal file
@@ -0,0 +1,25 @@
|
||||
/**
|
||||
* PROJECT: ExectOS
|
||||
* COPYRIGHT: See COPYING.md in the top level directory
|
||||
* FILE: includes/cmake/version/xtver.h.cmake
|
||||
* DESCRIPTION: XT version information - generated by toolchain
|
||||
* DEVELOPERS: Rafal Kupiec <belliash@codingworkshop.eu.org>
|
||||
*/
|
||||
|
||||
#ifndef __XTGEN_XTVER_H
|
||||
#define __XTGEN_XTVER_H
|
||||
|
||||
#define XTOS_VERSION "@XTOS_VERSION_MAJOR@.@XTOS_VERSION_MINOR@-@XTOS_VERSION_BUILD@"
|
||||
#define XTOS_VERSION_MAJOR @XTOS_VERSION_MAJOR@
|
||||
#define XTOS_VERSION_MINOR @XTOS_VERSION_MINOR@
|
||||
#define XTOS_VERSION_BUILD "@XTOS_VERSION_BUILD@"
|
||||
#define XTOS_VERSION_HASH "@XTOS_VERSION_HASH@"
|
||||
|
||||
#define XTOS_VERSION_ARCH "@ARCH@"
|
||||
#define XTOS_VERSION_DATE "@XTOS_VERSION_DATE@"
|
||||
#define XTOS_VERSION_YEAR "@XTOS_VERSION_YEAR@"
|
||||
|
||||
#define XTOS_COMPILER_NAME "@CMAKE_C_COMPILER_ID@"
|
||||
#define XTOS_COMPILER_VERSION "@CMAKE_C_COMPILER_VERSION@"
|
||||
|
||||
#endif /* __XTGEN_XTVER_H */
|
84
sdk/cmake/xtchain.cmake
Normal file
84
sdk/cmake/xtchain.cmake
Normal file
@@ -0,0 +1,84 @@
|
||||
# Architecture specific flags
|
||||
if(ARCH STREQUAL i686)
|
||||
add_compiler_flags("-m32 --target=i686-w64-windows-msvc")
|
||||
add_linker_flags("/machine:X86")
|
||||
set(HOTPATCH_LINKER_FLAG "/FUNCTIONPADMIN:5")
|
||||
elseif(ARCH STREQUAL amd64)
|
||||
add_compiler_flags("-m64 --target=x86_64-w64-windows-msvc")
|
||||
add_linker_flags("/machine:X64")
|
||||
set(HOTPATCH_LINKER_FLAG "/FUNCTIONPADMIN:6")
|
||||
endif()
|
||||
|
||||
# Set build optimisation
|
||||
if(BUILD_TYPE STREQUAL "DEBUG")
|
||||
add_compiler_flags("/Zi")
|
||||
add_compiler_ccxxflags("-Ob0 -Od")
|
||||
add_linker_flags("/DEBUG /INCREMENTAL /OPT:NOREF /OPT:NOICF")
|
||||
else()
|
||||
add_compiler_ccxxflags("-Ob2 -Oy")
|
||||
add_linker_flags("/INCREMENTAL:NO /OPT:REF /OPT:ICF")
|
||||
endif()
|
||||
|
||||
# Enable string pooling
|
||||
add_compiler_ccxxflags("-GF")
|
||||
|
||||
# Disable builtin CRT library
|
||||
add_compiler_ccxxflags("-Zl")
|
||||
|
||||
# Disable RTTI and buffer security checks
|
||||
add_compiler_ccxxflags("-GR- -GS-")
|
||||
|
||||
# Disable thread-safe initialization
|
||||
add_compiler_flags("-Zc:threadSafeInit-")
|
||||
|
||||
# Enable function level linking
|
||||
add_compiler_ccxxflags("-Gy")
|
||||
|
||||
# Enable Structured Exception Handling (SEH)
|
||||
add_compiler_ccxxflags("-EHa")
|
||||
|
||||
# Control warnings levels
|
||||
add_compiler_flags("-W3 -w14115")
|
||||
add_compiler_flags("-wd4200 -wd4214 -wd4244 -wd4290 -wd4800")
|
||||
add_compiler_flags("-we4013 -we4020 -we4022 -we4028 -we4047 -we4098 -we4101 -we4113 -we4129 -we4133")
|
||||
add_compiler_flags("-we4163 -we4189 -we4229 -we4311 -we4312 -we4313 -we4477 -we4603 -we4700 -we4715 -we4716")
|
||||
|
||||
# Disable warnings about specific features
|
||||
add_compiler_ccxxflags("-nostdinc -Wno-char-subscripts -Wno-incompatible-library-redeclaration -Wno-microsoft-anon-tag")
|
||||
add_compiler_ccxxflags("-Wno-microsoft-enum-forward-reference -Wno-multichar -Wno-parentheses-equality -Wno-undefined-inline")
|
||||
add_compiler_ccxxflags("-Wno-gnu-folding-constant")
|
||||
|
||||
# Set debugging symbols output directory
|
||||
set(CMAKE_PDB_OUTPUT_DIRECTORY "${EXECTOS_BINARY_DIR}/output/symbols")
|
||||
|
||||
# Set linker flags
|
||||
add_linker_flags("${HOTPATCH_LINKER_FLAG} /IGNORE:4039 /IGNORE:4104 /MANIFEST:NO /NODEFAULTLIB /SAFESEH:NO")
|
||||
|
||||
# Set runtime library
|
||||
set(CMAKE_MSVC_RUNTIME_LIBRARY "")
|
||||
|
||||
# Set default subsystem
|
||||
set(CMAKE_CREATE_CONSOLE_EXE "")
|
||||
|
||||
# Export compile commands for clangd
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS on)
|
||||
|
||||
# This function sets entrypoint of the binary
|
||||
function(set_entrypoint MODULE ENTRYPOINT)
|
||||
if(${ENTRYPOINT} STREQUAL "0")
|
||||
add_module_linker_flags(${MODULE} "/NOENTRY")
|
||||
else()
|
||||
add_module_linker_flags(${MODULE} "/ENTRY:${ENTRYPOINT}")
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
# This function sets imagebase address of the binary
|
||||
function(set_imagebase MODULE IMAGEBASE)
|
||||
add_module_linker_flags(${MODULE} "/BASE:${IMAGEBASE}")
|
||||
endfunction()
|
||||
|
||||
# This functions sets PE/COFF subsystem of the binary
|
||||
function(set_subsystem MODULE SUBSYSTEM)
|
||||
string(TOUPPER ${SUBSYSTEM} SUBSYSTEM)
|
||||
add_module_linker_flags(${MODULE} "/SUBSYSTEM:${SUBSYSTEM},6.03")
|
||||
endfunction()
|
Reference in New Issue
Block a user