1# Copyright (c) 2019 Intel Corp.
2# SPDX-License-Identifier: Apache-2.0
3
4# Convert the .bin file argument to a .o file, create a wrapper
5# library for the .o file, and register the library as a generated
6# file that is to be linked in after the first link.
7function(add_bin_file_to_the_next_link target_dependency bin)
8  add_custom_command(
9    OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${bin}.o
10    COMMAND
11    ${CMAKE_OBJCOPY}
12    -I binary
13    -B ${OUTPUT_ARCH}
14    -O ${OUTPUT_FORMAT}
15    --rename-section .data=${bin},CONTENTS,ALLOC,LOAD,READONLY,DATA
16    ${bin}.bin
17    ${bin}.o
18    DEPENDS ${target_dependency} ${bin}.bin
19    WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
20    )
21  add_custom_target(${bin}_o DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${bin}.o)
22  add_library(${bin} STATIC IMPORTED GLOBAL)
23  set_property(TARGET ${bin} PROPERTY IMPORTED_LOCATION ${CMAKE_CURRENT_BINARY_DIR}/${bin}.o)
24  add_dependencies(${bin} ${bin}_o)
25  set_property(GLOBAL APPEND PROPERTY GENERATED_KERNEL_OBJECT_FILES ${bin})
26endfunction()
27
28if(CONFIG_X86_64)
29  include(intel64.cmake)
30else()
31  include(ia32.cmake)
32endif()
33
34# Always set for 64-bit (long mode requires page tables), optional for 32-bit
35if (CONFIG_MMU)
36  set(GEN_MMU ${ZEPHYR_BASE}/arch/x86/gen_mmu.py)
37
38  if(DEFINED X86_EXTRA_GEN_MMU_ARGUMENTS)
39    # Make the string into a list, or else it will be passed to ${GEN_MMU}
40    # as a quoted string, which is then parsed as one item by Python's
41    # argparse.
42    string(REPLACE " " ";"
43           X86_EXTRA_GEN_MMU_ARGUMENTS
44           "${X86_EXTRA_GEN_MMU_ARGUMENTS}")
45  else()
46    set(X86_EXTRA_GEN_MMU_ARGUMENTS "")
47  endif()
48
49  add_custom_target(
50    pagetables_bin_target
51    DEPENDS
52    pagetables.bin
53  )
54  add_custom_command(
55    OUTPUT pagetables.bin
56    COMMAND
57    ${PYTHON_EXECUTABLE}
58    ${GEN_MMU}
59    --kernel $<TARGET_FILE:${ZEPHYR_PREBUILT_EXECUTABLE}>
60    --output pagetables.bin
61    $<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--verbose>
62    ${X86_EXTRA_GEN_MMU_ARGUMENTS}
63    WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
64    DEPENDS ${ZEPHYR_PREBUILT_EXECUTABLE} ${GEN_MMU}
65  )
66
67  add_bin_file_to_the_next_link(pagetables_bin_target pagetables)
68endif()
69
70if(CONFIG_ARCH_HAS_TIMING_FUNCTIONS AND
71    NOT CONFIG_SOC_HAS_TIMING_FUNCTIONS AND
72    NOT CONFIG_BOARD_HAS_TIMING_FUNCTIONS)
73zephyr_library_sources_ifdef(CONFIG_TIMING_FUNCTIONS timing.c)
74endif()
75