1 /* 2 * Copyright (c) 2013-2014 Wind River Systems, Inc. 3 * Copyright 2024 Arm Limited and/or its affiliates <open-source-office@arm.com> 4 * 5 * SPDX-License-Identifier: Apache-2.0 6 */ 7 8 /** 9 * @file 10 * @brief ARM Cortex-A and Cortex-R System Control Block interface 11 */ 12 13 #include <zephyr/kernel.h> 14 #include <zephyr/arch/cpu.h> 15 #include <zephyr/sys/util.h> 16 #include <zephyr/linker/linker-defs.h> 17 18 #if defined(CONFIG_AARCH32_ARMV8_R) 19 20 #define VECTOR_ADDRESS ((uintptr_t)_vector_start) 21 relocate_vector_table(void)22static inline void relocate_vector_table(void) 23 { 24 write_sctlr(read_sctlr() & ~HIVECS); 25 write_vbar(VECTOR_ADDRESS & VBAR_MASK); 26 barrier_isync_fence_full(); 27 } 28 29 #else 30 31 /* 32 * GCC can detect if memcpy is passed a NULL argument, however one of 33 * the cases of relocate_vector_table() it is valid to pass NULL, so we 34 * suppress the warning for this case. We need to do this before 35 * string.h is included to get the declaration of memcpy. 36 */ TOOLCHAIN_DISABLE_WARNING(TOOLCHAIN_WARNING_NONNULL)37TOOLCHAIN_DISABLE_WARNING(TOOLCHAIN_WARNING_NONNULL) 38 39 #include <string.h> 40 41 #define VECTOR_ADDRESS 0 42 43 void __weak relocate_vector_table(void) 44 { 45 #if defined(CONFIG_XIP) && (CONFIG_FLASH_BASE_ADDRESS != 0) || \ 46 !defined(CONFIG_XIP) && (CONFIG_SRAM_BASE_ADDRESS != 0) 47 write_sctlr(read_sctlr() & ~HIVECS); 48 size_t vector_size = (size_t)_vector_end - (size_t)_vector_start; 49 (void)memcpy(VECTOR_ADDRESS, _vector_start, vector_size); 50 #endif 51 } 52 TOOLCHAIN_ENABLE_WARNING(TOOLCHAIN_WARNING_NONNULL)53TOOLCHAIN_ENABLE_WARNING(TOOLCHAIN_WARNING_NONNULL) 54 55 #endif /* !CONFIG_AARCH32_ARMV8_R */ 56 57 void z_arm_relocate_vector_table(void) 58 { 59 relocate_vector_table(); 60 } 61 62 /** 63 * 64 * @brief Reset the system 65 * 66 * This routine resets the processor. 67 * 68 */ 69 sys_arch_reboot(int type)70void __weak sys_arch_reboot(int type) 71 { 72 ARG_UNUSED(type); 73 } 74