Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions capDL-tool/CapDL/PrintC.hs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ showCap objs (FrameCap id rights _ cached maybe_mapping) _ is_orig _ =
", .is_orig = " ++ is_orig ++
", .rights = " ++ showRights rights ++
", .vm_attribs = " ++
(if cached then "seL4_ARCH_Default_VMAttributes" else "CDL_VM_CacheDisabled") ++
(if cached then "CDL_VM_CacheEnabled" else "CDL_VM_CacheDisabled") ++
", .mapping_container_id = " ++
(case maybe_mapping of
Just (mapping_container, _) -> showObjID objs mapping_container;
Expand Down Expand Up @@ -220,7 +220,7 @@ showSlots objs obj_id (x:xs) irqNode cdt ms =
where
index = fst x
slot = showCap objs (snd x) irqNode is_orig ms
is_orig = if Map.notMember (obj_id, index) cdt then "true" else "false"
is_orig = if Map.notMember (obj_id, index) cdt then "1" else "0"

memberSlots :: Map ObjID Int -> ObjID -> CapMap Word -> IRQMap -> CDT -> ObjMap Word -> String
memberSlots objs obj_id slots irqNode cdt ms =
Expand Down Expand Up @@ -447,7 +447,7 @@ showUntypedDerivations :: AllocationType -> Map ObjID Int -> CoverMap -> String
showUntypedDerivations DynamicAlloc{} _ untypedCovers
| all null (Map.elems untypedCovers) =
".num_untyped = 0," +++
".untyped = NULL,"
".untyped = 0,"
| otherwise = error $
"refusing to generate spec for dynamic allocation because the " ++
"following untypeds already have children:\n" ++
Expand Down Expand Up @@ -500,6 +500,7 @@ printC allocType (Model arch objs irqNode cdt untypedCovers) _ _ =
text $
"/* Generated file. Your changes will be overwritten. */" +++
"" +++
"#define __thread" +++
"#include <capdl.h>" +++
"#include <sel4/sel4.h>" +++
"" +++
Expand Down
123 changes: 113 additions & 10 deletions capdl-loader-app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ config_string(
UNQUOTE
)

config_string(
CapDLLoaderRootStack
CAPDL_LOADER_ROOT_STACK
"Size of the initial stack for the root task"
DEFAULT
16384
)

config_string(
CapDLLoaderFillsPerFrame
CAPDL_LOADER_FILLS_PER_FRAME
Expand Down Expand Up @@ -89,16 +97,111 @@ config_option(

add_config_library(capdl_loader_app "${configure_string}")

# The capdl-loader-app requires outside configuration in order to build. To achieve this
# we just declare a target here with custom properties for describing the source and headers.
# This is done here as at this point we know the source directory and can construct these things.
# Later on the user will construct a rule for actually generating the capdl executable from a
# different project directory
add_custom_target(capdl_app_properties)
set_property(TARGET capdl_app_properties PROPERTY C_FILES "${CMAKE_CURRENT_SOURCE_DIR}/src/main.c")

if(DEFINED platform_yaml)

find_file(PLATFORM_SIFT platform_sift.py PATHS ${CMAKE_MODULE_PATH} NO_CMAKE_FIND_ROOT_PATH)
mark_as_advanced(FORCE PLATFORM_SIFT)
if("${PLATFORM_SIFT}" STREQUAL "PLATFORM_SIFT-NOTFOUND")
message(
FATAL_ERROR
"Failed to find platform_sift.py. Consider using -DPLATFORM_SIFT=/path/to/file"
)
endif()

set(
MEMORY_REGIONS
"${CMAKE_BINARY_DIR}/capdl/capdl-loader-app/gen_config/capdl_loader_app/platform_info.h"
)
add_custom_command(
COMMAND ${PLATFORM_SIFT} --emit-c-syntax ${platform_yaml} > ${MEMORY_REGIONS}
OUTPUT ${MEMORY_REGIONS}
)
add_custom_target(mem_regions DEPENDS ${platform_yaml} ${PLATFORM_SIFT} ${MEMORY_REGIONS})
set_property(
SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/capdl/capdl-loader-app/src/main.c
PROPERTY OBJECT_DEPENDS mem_regions
)
endif()

get_target_property(MUSL_SOURCE_DIR muslc_gen SOURCE_DIR)

if(KernelDebugBuild)
set(print_sources
# Debug sources for printing
src/check.c
${MUSL_SOURCE_DIR}/src/stdio/vfprintf.c
${MUSL_SOURCE_DIR}/src/stdio/fwrite.c
${MUSL_SOURCE_DIR}/src/stdio/__towrite.c
${MUSL_SOURCE_DIR}/src/multibyte/wctomb.c
${MUSL_SOURCE_DIR}/src/multibyte/wcrtomb.c
${MUSL_SOURCE_DIR}/src/math/__signbitl.c
${MUSL_SOURCE_DIR}/src/math/__fpclassifyl.c
${MUSL_SOURCE_DIR}/src/math/frexpl.c
${MUSL_SOURCE_DIR}/src/string/strnlen.c
${MUSL_SOURCE_DIR}/src/string/memchr.c
)
endif()


# Build the application
add_library(capdl_base OBJECT EXCLUDE_FROM_ALL
src/main.c
# Add implementations of memset and memcpy from lib musl
${MUSL_SOURCE_DIR}/src/string/memset.c
${MUSL_SOURCE_DIR}/src/string/memcpy.c

${print_sources}
)

target_include_directories(
capdl_base
PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/include"
${MUSL_SOURCE_DIR}/src/internal
${MUSL_SOURCE_DIR}/arch/aarch64
)
target_link_libraries(
capdl_base
PRIVATE
sel4
cpio
capdl_loader_app_Config
sel4_autoconf
muslc
)

if(DEFINED platform_yaml)
add_dependencies("capdl_base" mem_regions)
endif()

separate_arguments(
cmake_c_flags_sep NATIVE_COMMAND "${CMAKE_C_FLAGS}"
)
add_custom_command(
OUTPUT capdl-loader.o
COMMAND
${CMAKE_C_COMPILER} ${cmake_c_flags_sep} -static -nostdlib -z max-page-size=0x1000 -Wl,-r
$<TARGET_OBJECTS:capdl_base>
$<TARGET_OBJECTS:cpio>
-o capdl-loader.o
DEPENDS $<TARGET_OBJECTS:capdl_base> $<TARGET_OBJECTS:cpio> COMMAND_EXPAND_LISTS
)

add_custom_target(
capdl_loader_precompile
DEPENDS capdl-loader.o
)

add_library(capdl_loader_base STATIC IMPORTED GLOBAL)
set_property(TARGET capdl_loader_base PROPERTY IMPORTED_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/capdl-loader.o")
set_property(
TARGET capdl_app_properties
TARGET capdl_loader_base
PROPERTY INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/include"
"${MUSL_SOURCE_DIR}/src/internal"
"${MUSL_SOURCE_DIR}/arch/aarch64"
)

RequireFile(CAPDL_LOADER_BUILD_HELPERS helpers.cmake)
add_library(capdl_loader INTERFACE)
add_dependencies(capdl_loader capdl_loader_base)
set_property(TARGET capdl_loader PROPERTY INTERFACE_LINK_LIBRARIES capdl_loader_base)
target_include_directories(capdl_loader INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/include")
80 changes: 27 additions & 53 deletions capdl-loader-app/helpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -26,65 +26,39 @@ function(BuildCapDLApplication)
CPIO_SYMBOL
_capdl_archive
)
separate_arguments(
cmake_c_flags_sep NATIVE_COMMAND "${CMAKE_C_FLAGS}"
)

if(DEFINED platform_yaml)

find_file(PLATFORM_SIFT platform_sift.py PATHS ${CMAKE_MODULE_PATH} NO_CMAKE_FIND_ROOT_PATH)
mark_as_advanced(FORCE PLATFORM_SIFT)
if("${PLATFORM_SIFT}" STREQUAL "PLATFORM_SIFT-NOTFOUND")
message(
FATAL_ERROR
"Failed to find platform_sift.py. Consider using -DPLATFORM_SIFT=/path/to/file"
)
endif()
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${CAPDL_BUILD_APP_OUTPUT}.bin
BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/${CAPDL_BUILD_APP_OUTPUT}
COMMAND_EXPAND_LISTS
COMMAND ${CMAKE_C_COMPILER} ${cmake_c_flags_sep} -static -nostdlib -z max-page-size=0x1000

set(
MEMORY_REGIONS
"${CMAKE_BINARY_DIR}/capdl/capdl-loader-app/gen_config/capdl_loader_app/platform_info.h"
)
add_custom_command(
COMMAND ${PLATFORM_SIFT} --emit-c-syntax ${platform_yaml} > ${MEMORY_REGIONS}
OUTPUT ${MEMORY_REGIONS}
)
add_custom_target(mem_regions DEPENDS ${platform_yaml} ${PLATFORM_SIFT} ${MEMORY_REGIONS})
set_property(
SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/capdl/capdl-loader-app/src/main.c
PROPERTY OBJECT_DEPENDS mem_regions
)
endif()

# Build the application
add_executable(
"${CAPDL_BUILD_APP_OUTPUT}"
EXCLUDE_FROM_ALL
$<TARGET_PROPERTY:capdl_app_properties,C_FILES>
${CAPDL_LOADER_APP_C_FILES}
${CAPDL_BUILD_APP_OUTPUT}_archive.o
${CAPDL_BUILD_APP_C_SPEC}
"-I$<JOIN:$<TARGET_PROPERTY:capdl_loader,INTERFACE_INCLUDE_DIRECTORIES>,;-I>"
"-I$<JOIN:$<TARGET_PROPERTY:sel4,INTERFACE_INCLUDE_DIRECTORIES>,;-I>"
"-I$<JOIN:$<TARGET_PROPERTY:sel4_autoconf,INTERFACE_INCLUDE_DIRECTORIES>,;-I>"
-I$<TARGET_PROPERTY:capdl_loader_app_Config,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_OBJECTS:capdl_loader_base>
${CAPDL_BUILD_APP_OUTPUT}_archive.o
${CAPDL_BUILD_APP_C_SPEC}
-lgcc
-o ${CMAKE_CURRENT_BINARY_DIR}/${CAPDL_BUILD_APP_OUTPUT}
COMMAND cp ${CMAKE_CURRENT_BINARY_DIR}/${CAPDL_BUILD_APP_OUTPUT} ${CMAKE_CURRENT_BINARY_DIR}/${CAPDL_BUILD_APP_OUTPUT}.bin
DEPENDS ${CAPDL_BUILD_APP_OUTPUT}_archive.o capdl_loader $<TARGET_OBJECTS:capdl_loader_base>
"${CAPDL_BUILD_APP_ELF}"
${CAPDL_BUILD_APP_DEPENDS}
)

if(DEFINED platform_yaml)
add_dependencies("${CAPDL_BUILD_APP_OUTPUT}" mem_regions)
endif()
add_custom_target("${CAPDL_BUILD_APP_OUTPUT}-custom" DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${CAPDL_BUILD_APP_OUTPUT}.bin)

add_dependencies("${CAPDL_BUILD_APP_OUTPUT}" ${CAPDL_BUILD_APP_DEPENDS})
target_include_directories(
"${CAPDL_BUILD_APP_OUTPUT}"
PRIVATE $<TARGET_PROPERTY:capdl_app_properties,INCLUDE_DIRS>
)
target_link_libraries(
"${CAPDL_BUILD_APP_OUTPUT}"
sel4runtime
sel4
cpio
sel4platsupport
sel4utils
capdl_loader_app_Config
sel4_autoconf
add_library("${CAPDL_BUILD_APP_OUTPUT}" STATIC IMPORTED GLOBAL)
add_dependencies("${CAPDL_BUILD_APP_OUTPUT}" "${CAPDL_BUILD_APP_OUTPUT}-custom")
set_property(
TARGET "${CAPDL_BUILD_APP_OUTPUT}"
PROPERTY IMPORTED_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/${CAPDL_BUILD_APP_OUTPUT}"
)
if(KernelDebugBuild)
target_link_libraries("${CAPDL_BUILD_APP_OUTPUT}" sel4muslcsys)
endif()

endfunction(BuildCapDLApplication)

# Hook for CAmkES build system. This allows CAmkES projects to
Expand Down
Loading