1 /*
2  * Copyright (c) 2014 Wind River Systems, Inc.
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 /**
8  * @file
9  * @brief Full C support initialization
10  *
11  *
12  * Initialization of full C support: zero the .bss, copy the .data if XIP,
13  * call z_cstart().
14  *
15  * Stack is available in this module, but not the global data/bss until their
16  * initialization is performed.
17  */
18 
19 #include <zephyr/types.h>
20 #include <zephyr/toolchain.h>
21 #include <zephyr/linker/linker-defs.h>
22 #include <zephyr/kernel_structs.h>
23 #include <kernel_internal.h>
24 #include <zephyr/platform/hooks.h>
25 #include <zephyr/arch/cache.h>
26 
27 /**
28  * @brief Prepare to and run C code
29  *
30  * This routine prepares for the execution of and runs C code.
31  */
32 
z_prep_c(void)33 void z_prep_c(void)
34 {
35 #if defined(CONFIG_SOC_PREP_HOOK)
36 	soc_prep_hook();
37 #endif
38 
39 	z_bss_zero();
40 	z_data_copy();
41 	/* In most XIP scenarios we copy the exception code into RAM, so need
42 	 * to flush instruction cache.
43 	 */
44 #ifdef CONFIG_XIP
45 	z_nios2_icache_flush_all();
46 #if ALT_CPU_ICACHE_SIZE > 0
47 	/* Only need to flush the data cache here if there actually is an
48 	 * instruction cache, so that the cached instruction data written is
49 	 * actually committed.
50 	 */
51 	z_nios2_dcache_flush_all();
52 #endif
53 #endif
54 #if CONFIG_ARCH_CACHE
55 	arch_cache_init();
56 #endif
57 	z_cstart();
58 	CODE_UNREACHABLE;
59 }
60