1 /*
2  * Copyright (c) 2023 Nordic Semiconductor ASA
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef NSI_COMMON_SRC_INCL_NSI_CPU_IF_H
8 #define NSI_COMMON_SRC_INCL_NSI_CPU_IF_H
9 
10 #ifdef __cplusplus
11 extern "C" {
12 #endif
13 
14 #include "nsi_cpu_if_internal.h"
15 
16 /*
17  * Any symbol annotated by this macro will be visible outside of the
18  * embedded SW library, both by the native simulator runner,
19  * and other possible embedded CPU's SW.
20  */
21 #define NATIVE_SIMULATOR_IF __attribute__((visibility("default"))) \
22 	__attribute__((__section__(".native_sim_if")))
23 /*
24  * Implementation note:
25  * The interface between the embedded SW and the native simulator is allocated in its
26  * own section to allow the embedded software developers to, using a linker script,
27  * direct the linker to keep those symbols even when doing its linking with garbage collection.
28  * It is also be possible for the embedded SW to require the linker to keep those
29  * symbols by requiring each of them to be kept explicitly by name (either by defining them
30  * as entry points, or as required in the output).
31  * It is also possible for the embedded SW developers to not use garbage collection
32  * during their SW linking.
33  */
34 
35 
36 /*
37  * Interfaces the Native Simulator _expects_ from the embedded CPUs:
38  */
39 
40 /*
41  * Called during the earliest initialization (before command line parsing)
42  *
43  * The embedded SW library may provide this function to perform any
44  * early initialization, including registering its own command line arguments
45  * in the runner.
46  */
47 NATIVE_SIMULATOR_IF void nsif_cpu0_pre_cmdline_hooks(void);
48 
49 /*
50  * Called during initialization (before the HW models are initialized)
51  *
52  * The embedded SW library may provide this function to perform any
53  * early initialization, after the command line arguments have been parsed.
54  */
55 NATIVE_SIMULATOR_IF void nsif_cpu0_pre_hw_init_hooks(void);
56 
57 /*
58  * Called by the runner to boot the CPU.
59  *
60  * The embedded SW library must provide this function.
61  * This function is expected to return after the embedded CPU
62  * has gone to sleep for the first time.
63  *
64  * The expectation is that the embedded CPU SW will spawn a
65  * new pthread while in this call, and run the embedded SW
66  * initialization in that pthread.
67  *
68  * It is recommended for the embedded SW to use the NCE (CPU start/stop emulation)
69  * component to achieve this.
70  */
71 NATIVE_SIMULATOR_IF void nsif_cpu0_boot(void);
72 
73 /*
74  * Called by the runner when the simulation is ending/exiting
75  *
76  * The embedded SW library may provide this function.
77  * to do any cleanup it needs.
78  */
79 NATIVE_SIMULATOR_IF int nsif_cpu0_cleanup(void);
80 
81 /*
82  * Called by the runner each time an interrupt is raised by the HW
83  *
84  * The embedded SW library must provide this function.
85  * This function is expected to return after the embedded CPU
86  * has gone back to sleep.
87  */
88 NATIVE_SIMULATOR_IF void nsif_cpu0_irq_raised(void);
89 
90 /*
91  * Called by the runner each time an interrupt is raised in SW context itself.
92  * That is, when a embedded SW action in the HW models, causes an immediate
93  * interrupt to be raised (while the execution is still in the
94  * context of the calling SW thread).
95  */
96 NATIVE_SIMULATOR_IF void nsif_cpu0_irq_raised_from_sw(void);
97 
98 /*
99  * Optional hook which may be used for test functionality.
100  * When the runner HW models use them and for what is up to those
101  * specific models.
102  */
103 NATIVE_SIMULATOR_IF int nsif_cpu0_test_hook(void *p);
104 
105 /* Provide prototypes for all n instances of these hooks */
106 F_TRAMP_LIST(NATIVE_SIMULATOR_IF void nsif_cpu, _pre_cmdline_hooks(void))
107 F_TRAMP_LIST(NATIVE_SIMULATOR_IF void nsif_cpu, _pre_hw_init_hooks(void))
108 F_TRAMP_LIST(NATIVE_SIMULATOR_IF void nsif_cpu, _boot(void))
109 F_TRAMP_LIST(NATIVE_SIMULATOR_IF int nsif_cpu, _cleanup(void))
110 F_TRAMP_LIST(NATIVE_SIMULATOR_IF void nsif_cpu, _irq_raised(void))
111 F_TRAMP_LIST(NATIVE_SIMULATOR_IF void nsif_cpu, _irq_raised_from_sw(void))
112 F_TRAMP_LIST(NATIVE_SIMULATOR_IF int nsif_cpu, _test_hook(void *p))
113 
114 #ifdef __cplusplus
115 }
116 #endif
117 
118 #endif /* NSI_COMMON_SRC_INCL_NSI_CPU_IF_H */
119