diff --git a/arch/x86/CMakeLists.txt b/arch/x86/CMakeLists.txt index ffa62484ac4..2db084a1ad4 100644 --- a/arch/x86/CMakeLists.txt +++ b/arch/x86/CMakeLists.txt @@ -1,164 +1,8 @@ +# Copyright (c) 2019 Intel Corp. # SPDX-License-Identifier: Apache-2.0 - -# Find out if we are optimizing for size -get_target_property(zephyr_COMPILE_OPTIONS zephyr_interface INTERFACE_COMPILE_OPTIONS) -if ("-Os" IN_LIST zephyr_COMPILE_OPTIONS) - zephyr_cc_option(-mpreferred-stack-boundary=2) +if(CONFIG_X86_LONGMODE) + include(x64.cmake) else() - zephyr_compile_definitions(PERF_OPT) -endif() - -if(CONFIG_X86_IAMCU) - set_property(GLOBAL APPEND PROPERTY PROPERTY_LINKER_SCRIPT_DEFINES -D__IAMCU) - set_property(GLOBAL PROPERTY PROPERTY_OUTPUT_FORMAT "elf32-iamcu") - set_property(GLOBAL PROPERTY PROPERTY_OUTPUT_ARCH "iamcu:intel") -else() - set_property(GLOBAL PROPERTY PROPERTY_OUTPUT_ARCH "i386") - set_property(GLOBAL PROPERTY PROPERTY_OUTPUT_FORMAT "elf32-i386") -endif() - - - -if(CMAKE_C_COMPILER_ID STREQUAL "Clang") - if(CONFIG_X86_IAMCU) - zephyr_compile_options(-miamcu) - else() - zephyr_compile_options(-Qunused-arguments) - endif() - - zephyr_cc_option( - -m32 - -gdwarf-2 - ) -endif() - -zephyr_cc_option_ifndef(CONFIG_SSE_FP_MATH -mno-sse) - -if(CMAKE_VERBOSE_MAKEFILE) - set(GENIDT_EXTRA_ARGS --verbose) -else() - set(GENIDT_EXTRA_ARGS "") -endif() - -set(GENIDT ${ZEPHYR_BASE}/arch/x86/gen_idt.py) - -define_property(GLOBAL PROPERTY PROPERTY_OUTPUT_ARCH BRIEF_DOCS " " FULL_DOCS " ") - -# Use gen_idt.py and objcopy to generate irq_int_vector_map.o, -# irq_vectors_alloc.o, and staticIdt.o from the elf file ${ZEPHYR_PREBUILT_EXECUTABLE} -set(gen_idt_output_files - ${CMAKE_CURRENT_BINARY_DIR}/irq_int_vector_map.bin - ${CMAKE_CURRENT_BINARY_DIR}/staticIdt.bin - ${CMAKE_CURRENT_BINARY_DIR}/irq_vectors_alloc.bin - ) -add_custom_target( - gen_idt_output - DEPENDS - ${gen_idt_output_files} - ) -add_custom_command( - OUTPUT irq_int_vector_map.bin staticIdt.bin irq_vectors_alloc.bin - COMMAND - ${PYTHON_EXECUTABLE} - ${GENIDT} - --kernel $ - --output-idt staticIdt.bin - --vector-map irq_int_vector_map.bin - --output-vectors-alloc irq_vectors_alloc.bin - ${GENIDT_EXTRA_ARGS} - DEPENDS ${ZEPHYR_PREBUILT_EXECUTABLE} - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - ) - -# Must be last so that soc/ can override default exception handlers -add_subdirectory(core) - -get_property(OUTPUT_ARCH GLOBAL PROPERTY PROPERTY_OUTPUT_ARCH) -get_property(OUTPUT_FORMAT GLOBAL PROPERTY PROPERTY_OUTPUT_FORMAT) - -# Convert the .bin file argument to a .o file, create a wrapper -# library for the .o file, and register the library as a generated -# file that is to be linked in after the first link. -function(add_bin_file_to_the_next_link target_dependency bin) - add_custom_command( - OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${bin}.o - COMMAND - ${CMAKE_OBJCOPY} - -I binary - -B ${OUTPUT_ARCH} - -O ${OUTPUT_FORMAT} - --rename-section .data=${bin},CONTENTS,ALLOC,LOAD,READONLY,DATA - ${bin}.bin - ${bin}.o - DEPENDS ${target_dependency} ${bin}.bin - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - ) - add_custom_target(${bin}_o DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${bin}.o) - add_library(${bin} STATIC IMPORTED GLOBAL) - set_property(TARGET ${bin} PROPERTY IMPORTED_LOCATION ${CMAKE_CURRENT_BINARY_DIR}/${bin}.o) - add_dependencies(${bin} ${bin}_o) - set_property(GLOBAL APPEND PROPERTY GENERATED_KERNEL_OBJECT_FILES ${bin}) -endfunction() - -add_bin_file_to_the_next_link(gen_idt_output staticIdt) -add_bin_file_to_the_next_link(gen_idt_output irq_int_vector_map) -add_bin_file_to_the_next_link(gen_idt_output irq_vectors_alloc) - -if(CONFIG_X86_MMU) - if(CONFIG_X86_KPTI) - set(user_mmu_tables_bin user_mmu_tables.bin) - endif() - - add_custom_target( - mmu_tables_bin_target - DEPENDS - mmu_tables.bin - ${user_mmu_tables_bin} - ) - add_custom_command( - OUTPUT - mmu_tables.bin - ${user_mmu_tables_bin} - COMMAND - ${PYTHON_EXECUTABLE} - ${ZEPHYR_BASE}/arch/x86/gen_mmu_x86.py - -k $ - -o mmu_tables.bin - -u user_mmu_tables.bin - $<$:-v> - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - DEPENDS ${ZEPHYR_PREBUILT_EXECUTABLE} - ) - - add_bin_file_to_the_next_link( mmu_tables_bin_target mmu_tables) - if(CONFIG_X86_KPTI) - add_bin_file_to_the_next_link(mmu_tables_bin_target user_mmu_tables) - endif() -endif() - -if(CONFIG_GDT_DYNAMIC) - # Use gen_gdt.py and objcopy to generate gdt.o from from the elf - # file ${ZEPHYR_PREBUILT_EXECUTABLE}, creating the temp file gdt.bin along the - # way. - # - # ${ZEPHYR_PREBUILT_EXECUTABLE}.elf -> gdt.bin -> gdt.o - add_custom_target( - gdt_bin_target - DEPENDS - gdt.bin - ) - add_custom_command( - OUTPUT gdt.bin - COMMAND - ${PYTHON_EXECUTABLE} - ${ZEPHYR_BASE}/arch/x86/gen_gdt.py - --kernel $ - --output-gdt gdt.bin - $<$:--verbose> - DEPENDS ${ZEPHYR_PREBUILT_EXECUTABLE} - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - ) - - add_bin_file_to_the_next_link(gdt_bin_target gdt) + include(ia32.cmake) endif() diff --git a/arch/x86/core/CMakeLists.txt b/arch/x86/core/CMakeLists.txt index 55473dc70ab..2a7776bde37 100644 --- a/arch/x86/core/CMakeLists.txt +++ b/arch/x86/core/CMakeLists.txt @@ -1,41 +1,21 @@ +# Copyright (c) 2019 Intel Corp. # SPDX-License-Identifier: Apache-2.0 zephyr_library() -if (CMAKE_C_COMPILER_ID STREQUAL "Clang") - # We rely on GAS for assembling, so don't use the integrated assembler - zephyr_compile_options_ifndef(CONFIG_X86_IAMCU $<$:-no-integrated-as>) -elseif(CMAKE_C_COMPILER_ID STREQUAL "GNU") - zephyr_compile_options($<$:-Wa,--divide>) -endif() - zephyr_compile_options_ifdef(CONFIG_COVERAGE_GCOV -ftest-coverage -fprofile-arcs -fno-inline ) -zephyr_library_sources( - cache.c - cache_s.S - cpuhalt.c - crt0.S - excstub.S - intstub.S - irq_manage.c - swap.S - sys_fatal_error_handler.c - thread.c - spec_ctrl.c - ) +zephyr_library_sources_if_kconfig(pcie.c) +zephyr_library_sources_if_kconfig(reboot_rst_cnt.c) +zephyr_library_sources_ifdef(CONFIG_X86_MULTIBOOT multiboot.c) -zephyr_library_sources_if_kconfig( irq_offload.c) -zephyr_library_sources_if_kconfig( x86_mmu.c) -zephyr_library_sources_if_kconfig( reboot_rst_cnt.c) -zephyr_library_sources_if_kconfig( pcie.c) -zephyr_library_sources_ifdef(CONFIG_LAZY_FP_SHARING float.c) -zephyr_library_sources_ifdef(CONFIG_X86_USERSPACE userspace.S) -zephyr_library_sources_ifdef(CONFIG_X86_MULTIBOOT multiboot.c) +if(CONFIG_X86_LONGMODE) + include(x64.cmake) +else() + include(ia32.cmake) +endif() -# Last since we declare default exception handlers here -zephyr_library_sources(fatal.c) diff --git a/arch/x86/core/ia32.cmake b/arch/x86/core/ia32.cmake new file mode 100644 index 00000000000..ea21bb33f1b --- /dev/null +++ b/arch/x86/core/ia32.cmake @@ -0,0 +1,31 @@ +# Copyright (c) 2019 Intel Corp. +# SPDX-License-Identifier: Apache-2.0 + +if (CMAKE_C_COMPILER_ID STREQUAL "Clang") + # We rely on GAS for assembling, so don't use the integrated assembler + zephyr_compile_options_ifndef(CONFIG_X86_IAMCU $<$:-no-integrated-as>) +elseif(CMAKE_C_COMPILER_ID STREQUAL "GNU") + zephyr_compile_options($<$:-Wa,--divide>) +endif() + +zephyr_library_sources( + cache.c + cache_s.S + cpuhalt.c + crt0.S + excstub.S + intstub.S + irq_manage.c + swap.S + sys_fatal_error_handler.c + thread.c + spec_ctrl.c + ) + +zephyr_library_sources_if_kconfig( irq_offload.c) +zephyr_library_sources_if_kconfig( x86_mmu.c) +zephyr_library_sources_ifdef(CONFIG_X86_USERSPACE userspace.S) +zephyr_library_sources_ifdef(CONFIG_LAZY_FP_SHARING float.c) + +# Last since we declare default exception handlers here +zephyr_library_sources(fatal.c) diff --git a/arch/x86/core/x64.cmake b/arch/x86/core/x64.cmake new file mode 100644 index 00000000000..f6097e5476a --- /dev/null +++ b/arch/x86/core/x64.cmake @@ -0,0 +1,3 @@ +# Copyright (c) 2019 Intel Corp. +# SPDX-License-Identifier: Apache-2.0 + diff --git a/arch/x86/ia32.cmake b/arch/x86/ia32.cmake new file mode 100644 index 00000000000..be15724c673 --- /dev/null +++ b/arch/x86/ia32.cmake @@ -0,0 +1,164 @@ +# Copyright (c) 2019 Intel Corp. +# SPDX-License-Identifier: Apache-2.0 + +# Find out if we are optimizing for size +get_target_property(zephyr_COMPILE_OPTIONS zephyr_interface INTERFACE_COMPILE_OPTIONS) +if ("-Os" IN_LIST zephyr_COMPILE_OPTIONS) + zephyr_cc_option(-mpreferred-stack-boundary=2) +else() + zephyr_compile_definitions(PERF_OPT) +endif() + +if(CONFIG_X86_IAMCU) + set_property(GLOBAL APPEND PROPERTY PROPERTY_LINKER_SCRIPT_DEFINES -D__IAMCU) + set_property(GLOBAL PROPERTY PROPERTY_OUTPUT_FORMAT "elf32-iamcu") + set_property(GLOBAL PROPERTY PROPERTY_OUTPUT_ARCH "iamcu:intel") +else() + set_property(GLOBAL PROPERTY PROPERTY_OUTPUT_ARCH "i386") + set_property(GLOBAL PROPERTY PROPERTY_OUTPUT_FORMAT "elf32-i386") +endif() + + + +if(CMAKE_C_COMPILER_ID STREQUAL "Clang") + if(CONFIG_X86_IAMCU) + zephyr_compile_options(-miamcu) + else() + zephyr_compile_options(-Qunused-arguments) + endif() + + zephyr_cc_option( + -m32 + -gdwarf-2 + ) +endif() + +zephyr_cc_option_ifndef(CONFIG_SSE_FP_MATH -mno-sse) + +if(CMAKE_VERBOSE_MAKEFILE) + set(GENIDT_EXTRA_ARGS --verbose) +else() + set(GENIDT_EXTRA_ARGS "") +endif() + +set(GENIDT ${ZEPHYR_BASE}/arch/x86/gen_idt.py) + +define_property(GLOBAL PROPERTY PROPERTY_OUTPUT_ARCH BRIEF_DOCS " " FULL_DOCS " ") + +# Use gen_idt.py and objcopy to generate irq_int_vector_map.o, +# irq_vectors_alloc.o, and staticIdt.o from the elf file ${ZEPHYR_PREBUILT_EXECUTABLE} +set(gen_idt_output_files + ${CMAKE_CURRENT_BINARY_DIR}/irq_int_vector_map.bin + ${CMAKE_CURRENT_BINARY_DIR}/staticIdt.bin + ${CMAKE_CURRENT_BINARY_DIR}/irq_vectors_alloc.bin + ) +add_custom_target( + gen_idt_output + DEPENDS + ${gen_idt_output_files} + ) +add_custom_command( + OUTPUT irq_int_vector_map.bin staticIdt.bin irq_vectors_alloc.bin + COMMAND + ${PYTHON_EXECUTABLE} + ${GENIDT} + --kernel $ + --output-idt staticIdt.bin + --vector-map irq_int_vector_map.bin + --output-vectors-alloc irq_vectors_alloc.bin + ${GENIDT_EXTRA_ARGS} + DEPENDS ${ZEPHYR_PREBUILT_EXECUTABLE} + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + ) + +# Must be last so that soc/ can override default exception handlers +add_subdirectory(core) + +get_property(OUTPUT_ARCH GLOBAL PROPERTY PROPERTY_OUTPUT_ARCH) +get_property(OUTPUT_FORMAT GLOBAL PROPERTY PROPERTY_OUTPUT_FORMAT) + +# Convert the .bin file argument to a .o file, create a wrapper +# library for the .o file, and register the library as a generated +# file that is to be linked in after the first link. +function(add_bin_file_to_the_next_link target_dependency bin) + add_custom_command( + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${bin}.o + COMMAND + ${CMAKE_OBJCOPY} + -I binary + -B ${OUTPUT_ARCH} + -O ${OUTPUT_FORMAT} + --rename-section .data=${bin},CONTENTS,ALLOC,LOAD,READONLY,DATA + ${bin}.bin + ${bin}.o + DEPENDS ${target_dependency} ${bin}.bin + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + ) + add_custom_target(${bin}_o DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${bin}.o) + add_library(${bin} STATIC IMPORTED GLOBAL) + set_property(TARGET ${bin} PROPERTY IMPORTED_LOCATION ${CMAKE_CURRENT_BINARY_DIR}/${bin}.o) + add_dependencies(${bin} ${bin}_o) + set_property(GLOBAL APPEND PROPERTY GENERATED_KERNEL_OBJECT_FILES ${bin}) +endfunction() + +add_bin_file_to_the_next_link(gen_idt_output staticIdt) +add_bin_file_to_the_next_link(gen_idt_output irq_int_vector_map) +add_bin_file_to_the_next_link(gen_idt_output irq_vectors_alloc) + +if(CONFIG_X86_MMU) + if(CONFIG_X86_KPTI) + set(user_mmu_tables_bin user_mmu_tables.bin) + endif() + + add_custom_target( + mmu_tables_bin_target + DEPENDS + mmu_tables.bin + ${user_mmu_tables_bin} + ) + add_custom_command( + OUTPUT + mmu_tables.bin + ${user_mmu_tables_bin} + COMMAND + ${PYTHON_EXECUTABLE} + ${ZEPHYR_BASE}/arch/x86/gen_mmu_x86.py + -k $ + -o mmu_tables.bin + -u user_mmu_tables.bin + $<$:-v> + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + DEPENDS ${ZEPHYR_PREBUILT_EXECUTABLE} + ) + + add_bin_file_to_the_next_link( mmu_tables_bin_target mmu_tables) + if(CONFIG_X86_KPTI) + add_bin_file_to_the_next_link(mmu_tables_bin_target user_mmu_tables) + endif() +endif() + +if(CONFIG_GDT_DYNAMIC) + # Use gen_gdt.py and objcopy to generate gdt.o from from the elf + # file ${ZEPHYR_PREBUILT_EXECUTABLE}, creating the temp file gdt.bin along the + # way. + # + # ${ZEPHYR_PREBUILT_EXECUTABLE}.elf -> gdt.bin -> gdt.o + add_custom_target( + gdt_bin_target + DEPENDS + gdt.bin + ) + add_custom_command( + OUTPUT gdt.bin + COMMAND + ${PYTHON_EXECUTABLE} + ${ZEPHYR_BASE}/arch/x86/gen_gdt.py + --kernel $ + --output-gdt gdt.bin + $<$:--verbose> + DEPENDS ${ZEPHYR_PREBUILT_EXECUTABLE} + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + ) + + add_bin_file_to_the_next_link(gdt_bin_target gdt) +endif() diff --git a/arch/x86/x64.cmake b/arch/x86/x64.cmake new file mode 100644 index 00000000000..e22dae63d8f --- /dev/null +++ b/arch/x86/x64.cmake @@ -0,0 +1,4 @@ +# Copyright (c) 2019 Intel Corp. +# SPDX-License-Identifier: Apache-2.0 + +message(FATAL_ERROR "nice try, no x64 support yet")