Charles E. Youse | 8f14b2e | 2019-06-12 14:30:14 -0700 | [diff] [blame] | 1 | # Copyright (c) 2019 Intel Corp. |
Anas Nashif | 3ae5262 | 2019-04-06 09:08:09 -0400 | [diff] [blame] | 2 | # SPDX-License-Identifier: Apache-2.0 |
| 3 | |
Andrew Boie | df2fe7c | 2020-06-17 12:33:20 -0700 | [diff] [blame] | 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. |
| 7 | function(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}) |
| 26 | endfunction() |
| 27 | |
Daniel Leung | b7eb04b | 2019-10-24 12:57:57 -0700 | [diff] [blame] | 28 | if(CONFIG_X86_64) |
Charles E. Youse | 6cf904c | 2019-06-25 09:36:17 -0700 | [diff] [blame] | 29 | include(intel64.cmake) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 30 | else() |
Charles E. Youse | 8f14b2e | 2019-06-12 14:30:14 -0700 | [diff] [blame] | 31 | include(ia32.cmake) |
Sebastian Bøe | 12f8f76 | 2017-10-27 15:43:34 +0200 | [diff] [blame] | 32 | endif() |
Andrew Boie | df2fe7c | 2020-06-17 12:33:20 -0700 | [diff] [blame] | 33 | |
| 34 | # Always set for 64-bit (long mode requires page tables), optional for 32-bit |
| 35 | if (CONFIG_MMU) |
| 36 | set(GEN_MMU ${ZEPHYR_BASE}/arch/x86/gen_mmu.py) |
| 37 | |
Daniel Leung | 7a27509 | 2021-03-05 14:54:27 -0800 | [diff] [blame] | 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 | |
Andrew Boie | df2fe7c | 2020-06-17 12:33:20 -0700 | [diff] [blame] | 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> |
Daniel Leung | 7a27509 | 2021-03-05 14:54:27 -0800 | [diff] [blame] | 62 | ${X86_EXTRA_GEN_MMU_ARGUMENTS} |
Andrew Boie | df2fe7c | 2020-06-17 12:33:20 -0700 | [diff] [blame] | 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) |
| 68 | endif() |
Anas Nashif | d896dec | 2020-08-25 10:00:48 -0400 | [diff] [blame] | 69 | |
| 70 | if(CONFIG_ARCH_HAS_TIMING_FUNCTIONS AND |
| 71 | NOT CONFIG_SOC_HAS_TIMING_FUNCTIONS AND |
| 72 | NOT CONFIG_BOARD_HAS_TIMING_FUNCTIONS) |
| 73 | zephyr_library_sources_ifdef(CONFIG_TIMING_FUNCTIONS timing.c) |
| 74 | endif() |