1# Copyright (c) 2019 Intel Corp.
2# SPDX-License-Identifier: Apache-2.0
3
4# Find out if we are optimizing for size
5get_target_property(zephyr_COMPILE_OPTIONS zephyr_interface INTERFACE_COMPILE_OPTIONS)
6if ("-Os" IN_LIST zephyr_COMPILE_OPTIONS)
7  zephyr_cc_option(-mpreferred-stack-boundary=2)
8else()
9  zephyr_compile_definitions(PERF_OPT)
10endif()
11
12set_property(GLOBAL PROPERTY PROPERTY_OUTPUT_ARCH "i386")
13set_property(GLOBAL PROPERTY PROPERTY_OUTPUT_FORMAT "elf32-i386")
14
15if(CMAKE_C_COMPILER_ID STREQUAL "Clang"
16  OR CMAKE_C_COMPILER_ID STREQUAL "IntelLLVM")
17  zephyr_compile_options(-Qunused-arguments)
18
19  zephyr_cc_option(
20    -m32
21    -gdwarf-2
22    )
23endif()
24
25if(CONFIG_X86_MMX)
26  zephyr_cc_option(-mmmx)
27else()
28  zephyr_cc_option(-mno-mmx)
29endif()
30
31if(CONFIG_X86_SSE)
32  zephyr_cc_option(-msse)
33
34  if(CONFIG_X86_SSE_FP_MATH)
35      zephyr_cc_option(-mfpmath=sse)
36  else()
37      zephyr_cc_option(-mfpmath=387)
38  endif()
39
40  if(CONFIG_X86_SSE2)
41    zephyr_cc_option(-msse2)
42  else()
43    zephyr_cc_option(-mno-sse2)
44  endif()
45
46  if(CONFIG_X86_SSE3)
47    zephyr_cc_option(-msse3)
48  else()
49    zephyr_cc_option(-mno-sse3)
50  endif()
51
52  if(CONFIG_X86_SSSE3)
53    zephyr_cc_option(-mssse3)
54  else()
55    zephyr_cc_option(-mno-ssse3)
56  endif()
57
58  if(CONFIG_X86_SSE41)
59    zephyr_cc_option(-msse4.1)
60  else()
61    zephyr_cc_option(-mno-sse4.1)
62  endif()
63
64  if(CONFIG_X86_SSE42)
65    zephyr_cc_option(-msse4.2)
66  else()
67    zephyr_cc_option(-mno-sse4.2)
68  endif()
69
70  if(CONFIG_X86_SSE4A)
71    zephyr_cc_option(-msse4a)
72  else()
73    zephyr_cc_option(-mno-sse4a)
74  endif()
75
76else()
77  zephyr_cc_option(-mno-sse)
78endif()
79
80if(CMAKE_VERBOSE_MAKEFILE)
81  set(GENIDT_EXTRA_ARGS --verbose)
82else()
83  set(GENIDT_EXTRA_ARGS "")
84endif()
85
86set(GENIDT ${ZEPHYR_BASE}/arch/x86/gen_idt.py)
87
88define_property(GLOBAL PROPERTY PROPERTY_OUTPUT_ARCH BRIEF_DOCS " " FULL_DOCS " ")
89
90# Use gen_idt.py and objcopy to generate irq_int_vector_map.o,
91# irq_vectors_alloc.o, and staticIdt.o from the elf file ${ZEPHYR_PREBUILT_EXECUTABLE}
92set(gen_idt_output_files
93  ${CMAKE_CURRENT_BINARY_DIR}/irq_int_vector_map.bin
94  ${CMAKE_CURRENT_BINARY_DIR}/staticIdt.bin
95  ${CMAKE_CURRENT_BINARY_DIR}/irq_vectors_alloc.bin
96  )
97add_custom_target(
98  gen_idt_output
99  DEPENDS
100  ${gen_idt_output_files}
101  )
102add_custom_command(
103  OUTPUT irq_int_vector_map.bin staticIdt.bin irq_vectors_alloc.bin
104  COMMAND
105  ${PYTHON_EXECUTABLE}
106  ${GENIDT}
107  --kernel $<TARGET_FILE:${ZEPHYR_PREBUILT_EXECUTABLE}>
108  --output-idt staticIdt.bin
109  --vector-map irq_int_vector_map.bin
110  --output-vectors-alloc irq_vectors_alloc.bin
111  ${GENIDT_EXTRA_ARGS}
112  DEPENDS ${ZEPHYR_PREBUILT_EXECUTABLE}
113  WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
114  )
115
116# Must be last so that soc/ can override default exception handlers
117add_subdirectory(core)
118
119get_property(OUTPUT_ARCH   GLOBAL PROPERTY PROPERTY_OUTPUT_ARCH)
120get_property(OUTPUT_FORMAT GLOBAL PROPERTY PROPERTY_OUTPUT_FORMAT)
121
122
123
124add_bin_file_to_the_next_link(gen_idt_output staticIdt)
125add_bin_file_to_the_next_link(gen_idt_output irq_int_vector_map)
126add_bin_file_to_the_next_link(gen_idt_output irq_vectors_alloc)
127
128if(CONFIG_GDT_DYNAMIC)
129  # Use gen_gdt.py and objcopy to generate gdt.o from the elf
130  # file ${ZEPHYR_PREBUILT_EXECUTABLE}, creating the temp file gdt.bin along the
131  # way.
132  #
133  # ${ZEPHYR_PREBUILT_EXECUTABLE}.elf -> gdt.bin -> gdt.o
134  add_custom_target(
135    gdt_bin_target
136    DEPENDS
137    gdt.bin
138  )
139  add_custom_command(
140    OUTPUT gdt.bin
141    COMMAND
142    ${PYTHON_EXECUTABLE}
143    ${ZEPHYR_BASE}/arch/x86/gen_gdt.py
144    --kernel $<TARGET_FILE:${ZEPHYR_PREBUILT_EXECUTABLE}>
145    --output-gdt gdt.bin
146    $<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--verbose>
147    DEPENDS ${ZEPHYR_PREBUILT_EXECUTABLE}
148    WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
149    )
150
151  add_bin_file_to_the_next_link(gdt_bin_target gdt)
152endif()
153