Import build scripts and xtldr bootdata

This commit is contained in:
Rafal Kupiec 2022-07-27 09:20:41 +02:00
parent 35c7796527
commit 6f33629b85
Signed by: belliash
GPG Key ID: 4E829243E0CFE6B4
11 changed files with 438 additions and 0 deletions

65
CMakeLists.txt Normal file
View File

@ -0,0 +1,65 @@
# Detect XTChain toolchain
cmake_minimum_required(VERSION 3.19.0)
if(NOT CMAKE_VERSION MATCHES "XTC")
message(FATAL_ERROR "XTChain not detected or corrupted!")
endif()
# Lowercase target architecture
string(TOLOWER ${ARCH} ARCH)
# Validate and set architectures specific definitions
if(ARCH STREQUAL "i686")
add_definitions(-D__i386__ -D__i686__)
elseif(ARCH STREQUAL "amd64")
add_definitions(-D__amd64__ -D__x86_64__)
else()
message(FATAL_ERROR "Unknown target architecture (${ARCH}) set!")
endif()
# Print target architecture
message("-- Target architecture: ${ARCH}")
# Set the build type
if(NOT BUILD_TYPE)
set(BUILD_TYPE DEBUG)
endif()
string(TOUPPER ${BUILD_TYPE} BUILD_TYPE)
set(CMAKE_BUILD_TYPE "")
# Set build type specific definitions
if(BUILD_TYPE STREQUAL "DEBUG")
add_definitions(-DDBG=1)
else()
set(BUILD_TYPE RELEASE)
add_definitions(-DDBG=0)
endif()
# Print build type
message("-- Target build type: ${BUILD_TYPE}")
# Set toolchain file
set(CMAKE_TOOLCHAIN_FILE "sdk/cmake/toolchain.cmake")
# Set project name
project(EXECTOS)
# Load all the CMake SDK
include(sdk/cmake/baseaddress.cmake)
include(sdk/cmake/functions.cmake)
include(sdk/cmake/version.cmake)
include(sdk/cmake/xtchain.cmake)
# Add project specific definitions
add_definitions(-D__XTOS__)
add_definitions(-DXTOS_SOURCE_DIR="${EXECTOS_SOURCE_DIR}")
add_definitions(-DXTOS_BINARY_DIR="${EXECTOS_BINARY_DIR}")
# Compute __FILE__ definition
file(RELATIVE_PATH _PATH_PREFIX ${EXECTOS_BINARY_DIR} ${EXECTOS_SOURCE_DIR})
add_compiler_flags(-D__RELFILE__="&__FILE__[__FILE__[0] == '.' ? sizeof \\\"${_PATH_PREFIX}\\\" - 1 : sizeof XTOS_SOURCE_DIR]")
# Set the virtual disk image size (in MiB)
set_disk_image_size(128)
# Build subprojects
add_subdirectory(bootdata)

1
bootdata/CMakeLists.txt Normal file
View File

@ -0,0 +1 @@
add_subdirectory(xtldr)

View File

@ -0,0 +1 @@
set_install_file(xtldr.ini efi/boot)

51
bootdata/xtldr/xtldr.ini Normal file
View File

@ -0,0 +1,51 @@
# This is the XT Boot Loader (XTLDR) configuration file. It follows an INI format and is divided into sections, which
# contain a properties. Each property has a name and value delimited by an equal (=) character. Comments must start
# with a semicolon (;) or a hash character (#) and run to the end of the line.
#
# Basic section is [XTLDR] which contains a bootloader specific options:
# Debug - enables the debugging port and consists of two comma-separated parameters: com port and baud rate
# Default - specifies which operating system listen in config file will be started if no choice is made
# Theme - allows to set a custom theme to personalize XTLDR's look'n'feel
# Timeout - sets the countdown timer (in seconds) before the default OS get started automatically
# Tune - plays a tune on the pcspeaker right before the XTLDR loads
#
# Another type of section is [OS-Section] which adds a new position (operating system) to the boot menu. Each type
# of the operating system provides a set of available parameters. If unsupported option is added, it is being ignored
# by the XT Boot Loader. The available options are:
# SystemName - sets a long operating system name that will be shown on the boot menu
# SystemType - specifies an OS type from a predefined list of supported boot protocols
# SystemPath - the ARC path, eg. multi(0)disk(0)rdisk(0)partition(1)
# KernelFile - sets kernel filename with optional path relative to SystemPath
# InitrdFile - sets initramfs image filename with optional path relative to SystemPath
# HalFile - sets HAL filename with optional path relative to SystemPath
# Options - specifies extra boot options for the kernel
[XTLDR]
Tone=400 880 2 988 2 783 2 392 2 587 3
Debug=COM1,115200
Timeout=30
Theme=Fancy
Default=ExectOS
[ExectOS]
SystemName="ExectOS Operating System"
SystemType=XTOS
SystemPath=multi(0)disk(0)rdisk(0)partition(1)/ExectOS
KernelFile=xtoskrnl.exe
Options=DEBUG DEBUGPORT=COM1,115200
[Windows]
SystemName="Microsoft Windows 2000"
SystemType=NT50
SystemPath=multi(0)disk(0)rdisk(0)partition(2)/Windows
KernelFile=ntoskrnl.exe
HalFile=hal.dll
Options=/NOGUIBOOT /MININT
[Linux]
SystemName="GNU/Linux"
SystemType=LINUX
SystemPath=multi(0)disk(0)rdisk(0)partition(3)/boot
KernelFile=vmlinuz
InitrdFile=initramfs.cpio.gz
Options=root=/dev/xvda3 rootfstype=ext4

41
configure.sh Executable file
View File

@ -0,0 +1,41 @@
#!/bin/bash
# Check XTCHain
if [ "x${XTCVER}" = "x" ]; then
echo "XTChain not detected or corrupted!"
exit 1
fi
# Set target architecture
: ${ARCH:=${TARGET}}
: ${ARCH:=amd64}
# Set target build type
: ${BUILD_TYPE:=${BUILD_TYPE}}
: ${BUILD_TYPE:=DEBUG}
# Set variables
EXECTOS_SOURCE_DIR=$(cd `dirname ${0}` && pwd)
EXECTOS_BINARY_DIR=build-${ARCH}-xtchain
# Create directories if needed
if [ "${EXECTOS_SOURCE_DIR}" = "${PWD}" ]; then
echo Creating directories in ${EXECTOS_BINARY_DIR}
mkdir -p "${EXECTOS_BINARY_DIR}"
ln -sf ${EXECTOS_BINARY_DIR} build
cd "${EXECTOS_BINARY_DIR}"
fi
# Delete old cache
rm -f CMakeCache.txt host-tools/CMakeCache.txt
# Configure project
cmake -G Ninja -DARCH:STRING=${ARCH} -DBUILD_TYPE:STRING=${BUILD_TYPE} "${EXECTOS_SOURCE_DIR}"
# Check if configuration succeeded
if [ ${?} -ne 0 ]; then
echo "Configure script failed."
exit 1
else
echo "Configure script completed. Enter '${EXECTOS_BINARY_DIR}' directory and execute 'ninja' to build ExectOS."
fi

View File

@ -0,0 +1,2 @@
# Set base addresses for all modules
set(BASEADDRESS_XTOSKRNL 0x00400000)

129
sdk/cmake/functions.cmake Normal file
View 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
View 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
View 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)

View 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
View 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()