2020-08-27 20:37:10 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2010-2014 Wind River Systems, Inc.
|
|
|
|
* Copyright (c) 2020 Intel Corporation
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2022-05-06 17:04:23 +08:00
|
|
|
#include <zephyr/kernel.h>
|
2022-02-11 02:54:49 +08:00
|
|
|
#include <kernel_internal.h>
|
2022-05-06 17:04:23 +08:00
|
|
|
#include <zephyr/linker/linker-defs.h>
|
2020-08-27 20:37:10 +08:00
|
|
|
|
|
|
|
#ifdef CONFIG_STACK_CANARIES
|
2023-08-02 06:07:57 +08:00
|
|
|
#ifdef CONFIG_STACK_CANARIES_TLS
|
|
|
|
extern __thread volatile uintptr_t __stack_chk_guard;
|
|
|
|
#else
|
2020-08-27 20:37:10 +08:00
|
|
|
extern volatile uintptr_t __stack_chk_guard;
|
2023-08-02 06:07:57 +08:00
|
|
|
#endif /* CONFIG_STACK_CANARIES_TLS */
|
2020-08-27 20:37:10 +08:00
|
|
|
#endif /* CONFIG_STACK_CANARIES */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Copy the data section from ROM to RAM
|
|
|
|
*
|
|
|
|
* This routine copies the data section from ROM to RAM.
|
|
|
|
*/
|
|
|
|
void z_data_copy(void)
|
|
|
|
{
|
2022-02-11 02:54:49 +08:00
|
|
|
z_early_memcpy(&__data_region_start, &__data_region_load_start,
|
|
|
|
__data_region_end - __data_region_start);
|
2020-08-27 20:37:10 +08:00
|
|
|
#ifdef CONFIG_ARCH_HAS_RAMFUNC_SUPPORT
|
2022-02-11 02:54:49 +08:00
|
|
|
z_early_memcpy(&__ramfunc_start, &__ramfunc_load_start,
|
|
|
|
(uintptr_t) &__ramfunc_size);
|
2020-08-27 20:37:10 +08:00
|
|
|
#endif /* CONFIG_ARCH_HAS_RAMFUNC_SUPPORT */
|
|
|
|
#if DT_NODE_HAS_STATUS(DT_CHOSEN(zephyr_ccm), okay)
|
2022-02-11 02:54:49 +08:00
|
|
|
z_early_memcpy(&__ccm_data_start, &__ccm_data_rom_start,
|
|
|
|
__ccm_data_end - __ccm_data_start);
|
2020-08-27 20:37:10 +08:00
|
|
|
#endif
|
2021-01-06 22:52:28 +08:00
|
|
|
#if DT_NODE_HAS_STATUS(DT_CHOSEN(zephyr_itcm), okay)
|
2022-02-11 02:54:49 +08:00
|
|
|
z_early_memcpy(&__itcm_start, &__itcm_load_start,
|
|
|
|
(uintptr_t) &__itcm_size);
|
2021-01-06 22:52:28 +08:00
|
|
|
#endif
|
2020-08-27 20:37:10 +08:00
|
|
|
#if DT_NODE_HAS_STATUS(DT_CHOSEN(zephyr_dtcm), okay)
|
2022-02-11 02:54:49 +08:00
|
|
|
z_early_memcpy(&__dtcm_data_start, &__dtcm_data_load_start,
|
|
|
|
__dtcm_data_end - __dtcm_data_start);
|
2020-08-27 20:37:10 +08:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_CODE_DATA_RELOCATION
|
|
|
|
extern void data_copy_xip_relocation(void);
|
|
|
|
|
|
|
|
data_copy_xip_relocation();
|
|
|
|
#endif /* CONFIG_CODE_DATA_RELOCATION */
|
|
|
|
#ifdef CONFIG_USERSPACE
|
|
|
|
#ifdef CONFIG_STACK_CANARIES
|
|
|
|
/* stack canary checking is active for all C functions.
|
|
|
|
* __stack_chk_guard is some uninitialized value living in the
|
|
|
|
* app shared memory sections. Preserve it, and don't make any
|
|
|
|
* function calls to perform the memory copy. The true canary
|
|
|
|
* value gets set later in z_cstart().
|
|
|
|
*/
|
|
|
|
uintptr_t guard_copy = __stack_chk_guard;
|
|
|
|
uint8_t *src = (uint8_t *)&_app_smem_rom_start;
|
|
|
|
uint8_t *dst = (uint8_t *)&_app_smem_start;
|
|
|
|
uint32_t count = _app_smem_end - _app_smem_start;
|
|
|
|
|
|
|
|
guard_copy = __stack_chk_guard;
|
|
|
|
while (count > 0) {
|
|
|
|
*(dst++) = *(src++);
|
|
|
|
count--;
|
|
|
|
}
|
|
|
|
__stack_chk_guard = guard_copy;
|
|
|
|
#else
|
2022-02-11 02:54:49 +08:00
|
|
|
z_early_memcpy(&_app_smem_start, &_app_smem_rom_start,
|
|
|
|
_app_smem_end - _app_smem_start);
|
2020-08-27 20:37:10 +08:00
|
|
|
#endif /* CONFIG_STACK_CANARIES */
|
|
|
|
#endif /* CONFIG_USERSPACE */
|
|
|
|
}
|