1# SPDX-License-Identifier: Apache-2.0 2 3zephyr_cc_option(-mlongcalls) 4 5zephyr_library() 6 7zephyr_library_sources( 8 cpu_idle.c 9 fatal.c 10 window_vectors.S 11 xtensa_asm2_util.S 12 irq_manage.c 13 thread.c 14 vector_handlers.c 15 prep_c.c 16 ) 17 18zephyr_library_sources_ifdef(CONFIG_XTENSA_USE_CORE_CRT1 crt1.S) 19zephyr_library_sources_ifdef(CONFIG_IRQ_OFFLOAD irq_offload.c) 20zephyr_library_sources_ifdef(CONFIG_THREAD_LOCAL_STORAGE tls.c) 21zephyr_library_sources_ifdef(CONFIG_XTENSA_ENABLE_BACKTRACE xtensa_backtrace.c) 22zephyr_library_sources_ifdef(CONFIG_XTENSA_ENABLE_BACKTRACE debug_helpers_asm.S) 23zephyr_library_sources_ifdef(CONFIG_DEBUG_COREDUMP coredump.c) 24zephyr_library_sources_ifdef(CONFIG_TIMING_FUNCTIONS timing.c) 25zephyr_library_sources_ifdef(CONFIG_GDBSTUB gdbstub.c) 26zephyr_library_sources_ifdef(CONFIG_XTENSA_MMU ptables.c mmu.c) 27zephyr_library_sources_ifdef(CONFIG_XTENSA_MPU mpu.c) 28zephyr_library_sources_ifdef(CONFIG_USERSPACE userspace.S syscall_helper.c) 29zephyr_library_sources_ifdef(CONFIG_LLEXT elf.c) 30zephyr_library_sources_ifdef(CONFIG_SMP smp.c) 31zephyr_library_sources_ifdef(CONFIG_XTENSA_HIFI_SHARING xtensa_hifi.S) 32 33zephyr_library_sources_ifdef( 34 CONFIG_KERNEL_VM_USE_CUSTOM_MEM_RANGE_CHECK 35 mem_manage.c 36) 37 38if("${ZEPHYR_TOOLCHAIN_VARIANT}" STREQUAL "xcc") 39 zephyr_library_sources(xcc_stubs.c) 40endif() 41 42add_subdirectory(startup) 43 44# This produces a preprocessed and regenerated (in the sense of gcc 45# -dM, supported by all Xtensa toolchains) core-isa.h file available 46# as "core-isa-dM.h". This can be easily parsed by non-C tooling. 47# 48# Note that this adds the SOC/HAL include directory explicitly, they 49# are the official places where we find core-isa.h. (Also that we 50# undefine __XCC_ because that compiler actually trips an error trying 51# to build this file to protect against mismatched versions.) 52set(CORE_ISA_DM ${CMAKE_BINARY_DIR}/zephyr/include/generated/zephyr/core-isa-dM.h) 53set(CORE_ISA_IN ${CMAKE_BINARY_DIR}/zephyr/include/generated/core-isa-dM.c) 54file(WRITE ${CORE_ISA_IN} "#include <xtensa/config/core-isa.h>\n") 55add_custom_command(OUTPUT ${CORE_ISA_DM} 56 COMMAND ${CMAKE_C_COMPILER} -E -dM -U__XCC__ ${XTENSA_CORE_LOCAL_C_FLAG} 57 -I${ZEPHYR_XTENSA_MODULE_DIR}/zephyr/soc/${CONFIG_SOC} 58 -I${SOC_FULL_DIR} 59 ${CORE_ISA_IN} -o ${CORE_ISA_DM}) 60 61if(CONFIG_USERSPACE AND NOT CONFIG_THREAD_LOCAL_STORAGE) 62 # It is possible that the SoC does not have THREADPTR. 63 # This means that we cannot use THREADPTR as a shortcut to 64 # in arch_is_user_context(). However, whether a SoC has 65 # THREADPTR is in core-isa.h which can be parsed in gen_zsr.py. 66 # There, if there is no THREADPTR, we need a scratch register 67 # so we can do arch_is_user_context() via syscall. 68 set(MAY_NEED_SYSCALL_SCRATCH_REG true) 69else() 70 # With thread local storage, the variable is_user_mode is 71 # stored in the thread's TLS area. There is no need for 72 # scratch register. 73 set(MAY_NEED_SYSCALL_SCRATCH_REG false) 74endif() 75 76# Generates a list of device-specific scratch register choices 77set(ZSR_H ${CMAKE_BINARY_DIR}/zephyr/include/generated/zephyr/zsr.h) 78add_custom_command(OUTPUT ${ZSR_H} DEPENDS ${CORE_ISA_DM} 79 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/gen_zsr.py 80 $<$<BOOL:${CONFIG_XTENSA_MMU}>:--mmu> 81 $<$<BOOL:${MAY_NEED_SYSCALL_SCRATCH_REG}>:--syscall-scratch> 82 $<$<BOOL:${CONFIG_KERNEL_COHERENCE}>:--coherence> 83 ${CORE_ISA_DM} ${ZSR_H}) 84add_custom_target(zsr_h DEPENDS ${ZSR_H}) 85add_dependencies(zephyr_interface zsr_h) 86 87unset(MAY_NEED_SYSCALL_SCRATCH_REG) 88 89# Similar: auto-generate interrupt handlers 90set(HANDLERS ${CMAKE_BINARY_DIR}/zephyr/include/generated/xtensa_handlers) 91 92add_custom_command( 93 OUTPUT ${HANDLERS}_tmp.c 94 COMMAND ${CMAKE_C_COMPILER} -E -U__XCC__ 95 -I${ZEPHYR_XTENSA_MODULE_DIR}/zephyr/soc/${CONFIG_SOC} 96 -o ${HANDLERS}_tmp.c 97 - < ${CMAKE_CURRENT_SOURCE_DIR}/xtensa_intgen.tmpl) 98 99add_custom_command( 100 OUTPUT ${HANDLERS}.h 101 DEPENDS ${HANDLERS}_tmp.c 102 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/xtensa_intgen.py 103 ${HANDLERS}_tmp.c > ${HANDLERS}.h) 104 105add_custom_target(xtensa_handlers_h DEPENDS ${HANDLERS}.h) 106add_dependencies(zephyr_interface xtensa_handlers_h) 107 108# Auto-generate interrupt vector entry 109set(VECS_LD ${CMAKE_BINARY_DIR}/zephyr/include/generated/xtensa_vectors.ld) 110add_custom_command(OUTPUT ${VECS_LD} DEPENDS ${CORE_ISA_DM} 111 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/gen_vectors.py 112 ${CORE_ISA_DM} > ${VECS_LD}) 113add_custom_target(xtensa_vectors_ld DEPENDS ${VECS_LD}) 114add_dependencies(zephyr_interface xtensa_vectors_ld) 115