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/arch/arc/v2/aux_regs.h>
23 #include <zephyr/kernel_structs.h>
24 #include <kernel_internal.h>
25 
26 
27 /* XXX - keep for future use in full-featured cache APIs */
28 #if 0
29 /**
30  * @brief Disable the i-cache if present
31  *
32  * For those ARC CPUs that have a i-cache present,
33  * invalidate the i-cache and then disable it.
34  */
35 
36 static void disable_icache(void)
37 {
38 	unsigned int val;
39 
40 	val = z_arc_v2_aux_reg_read(_ARC_V2_I_CACHE_BUILD);
41 	val &= 0xff; /* version field */
42 	if (val == 0) {
43 		return; /* skip if i-cache is not present */
44 	}
45 	z_arc_v2_aux_reg_write(_ARC_V2_IC_IVIC, 0);
46 	__builtin_arc_nop();
47 	z_arc_v2_aux_reg_write(_ARC_V2_IC_CTRL, 1);
48 }
49 
50 /**
51  * @brief Invalidate the data cache if present
52  *
53  * For those ARC CPUs that have a data cache present,
54  * invalidate the data cache.
55  */
56 
57 static void invalidate_dcache(void)
58 {
59 	unsigned int val;
60 
61 	val = z_arc_v2_aux_reg_read(_ARC_V2_D_CACHE_BUILD);
62 	val &= 0xff; /* version field */
63 	if (val == 0) {
64 		return; /* skip if d-cache is not present */
65 	}
66 	z_arc_v2_aux_reg_write(_ARC_V2_DC_IVDC, 1);
67 }
68 #endif
69 
70 extern FUNC_NORETURN void z_cstart(void);
71 /**
72  * @brief Prepare to and run C code
73  *
74  * This routine prepares for the execution of and runs C code.
75  */
76 
_PrepC(void)77 void _PrepC(void)
78 {
79 	z_bss_zero();
80 	z_data_copy();
81 	z_cstart();
82 	CODE_UNREACHABLE;
83 }
84