SimpleOS

LXR

Navigation



Site hébergé par : enix

The LXR Cross Referencer for SOS

source navigation ]
diff markup ]
identifier search ]
general search ]
 
 
Article:1 ] [ 2 ] [ 3 ] [ 4 ] [ 5 ] [ 6 ] [ 6.5 ] [ 7 ] [ 7.5 ] [ 8 ] [ 9 ] [ 9.5 ]

Diff markup

Differences between /hwcore/cpu_context.h (Article 6.5) and /hwcore/cpu_context.h (Article 6)


001 /* Copyright (C) 2005  David Decotigny         !! 001 /* Copyright (C) 2000-2004, The KOS team
002    Copyright (C) 2000-2004, The KOS team       !! 002    Copyright (C) 1999  Free Software Foundation, Inc.
003                                                   003 
004    This program is free software; you can redi    004    This program is free software; you can redistribute it and/or
005    modify it under the terms of the GNU Genera    005    modify it under the terms of the GNU General Public License
006    as published by the Free Software Foundatio    006    as published by the Free Software Foundation; either version 2
007    of the License, or (at your option) any lat    007    of the License, or (at your option) any later version.
008                                                   008    
009    This program is distributed in the hope tha    009    This program is distributed in the hope that it will be useful,
010    but WITHOUT ANY WARRANTY; without even the     010    but WITHOUT ANY WARRANTY; without even the implied warranty of
011    MERCHANTABILITY or FITNESS FOR A PARTICULAR    011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
012    GNU General Public License for more details    012    GNU General Public License for more details.
013                                                   013    
014    You should have received a copy of the GNU     014    You should have received a copy of the GNU General Public License
015    along with this program; if not, write to t    015    along with this program; if not, write to the Free Software
016    Foundation, Inc., 59 Temple Place - Suite 3    016    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
017    USA.                                           017    USA. 
018 */                                                018 */
019 #ifndef _SOS_CPUCTXT_H_                           019 #ifndef _SOS_CPUCTXT_H_
020 #define _SOS_CPUCTXT_H_                           020 #define _SOS_CPUCTXT_H_
021                                                   021 
022                                                   022 
023 /**                                               023 /**
024  * @file cpu_context.h                            024  * @file cpu_context.h
025  *                                                025  *
026  * Low level API to manage kernel and user thr    026  * Low level API to manage kernel and user thread CPU contexts. Should
027  * be some kind of architecture-independent.      027  * be some kind of architecture-independent.
028  */                                               028  */
029                                                   029 
030 #include <sos/types.h>                            030 #include <sos/types.h>
031 #include <sos/errno.h>                            031 #include <sos/errno.h>
032                                                   032 
033                                                   033 
034 /**                                               034 /**
035  * Opaque structure storing the CPU context of !! 035  * Opaque structure storing the CPU context of an inactive kernel
036  * user thread, as saved by the low level prim !! 036  * thread, as saved by the low level primitives below or by the
037  * interrupt/exception handlers.                  037  * interrupt/exception handlers.
038  *                                                038  *
039  * @note This is an (architecture-independent)    039  * @note This is an (architecture-independent) forward declaration:
040  * see cpu_context.c and the *.S files for its    040  * see cpu_context.c and the *.S files for its
041  * (architecture-dependent) definition.           041  * (architecture-dependent) definition.
042  */                                               042  */
043 struct sos_cpu_state;                          !! 043 struct sos_cpu_kstate;
044                                                   044 
045                                                   045 
046 /**                                               046 /**
047  * The type of the functions passed as argumen !! 047  * The type of the functions passed as arguments below
048  * related functions.                          << 
049  */                                               048  */
050 typedef void (sos_cpu_kstate_function_arg1_t(s    049 typedef void (sos_cpu_kstate_function_arg1_t(sos_ui32_t arg1));
051                                                   050 
052                                                   051 
053 /**                                               052 /**
054  * Function to create an initial context for a    053  * Function to create an initial context for a kernel thread starting
055  * its execution at function start_func with t    054  * its execution at function start_func with the argument initial_arg,
056  * and having the stack defined by stack_botto    055  * and having the stack defined by stack_bottom/stack_size. When the
057  * start_func function returns, the function e    056  * start_func function returns, the function exit_func is called with
058  * argument exit_arg.                             057  * argument exit_arg.
059  *                                                058  *
060  * @param kctxt The kernel thread CPU context  !! 059  * @param ctxt The kernel thread CPU context to initialize. The
061  * address of the newly-initialized struct sos !! 060  * address of the newly-initialized struct sos_cpu_kstate will be
062  * stored in this variable. The contents of th !! 061  * stored in this variable. The contents of this struct sos_cpu_kstate
063  * are actually located /inside/ the stack.       062  * are actually located /inside/ the stack.
064  *                                                063  *
065  * @param start_func The address of the first     064  * @param start_func The address of the first instruction that will be
066  * executed when this context will be first tr    065  * executed when this context will be first transferred on
067  * CPU. Practically speaking, this is the addr    066  * CPU. Practically speaking, this is the address of a function that
068  * is assumed to take 1 argument.                 067  * is assumed to take 1 argument.
069  *                                                068  *
070  * @param start_arg The value that will be pas    069  * @param start_arg The value that will be passed as the argument to
071  * start_func when the thread starts. The stac    070  * start_func when the thread starts. The stack will be setup
072  * accordingly to simulate a real call to the     071  * accordingly to simulate a real call to the function and really
073  * passing this arguement.                        072  * passing this arguement.
074  *                                                073  *
075  * @param stack_bottom The lowest address of t    074  * @param stack_bottom The lowest address of the stack.
076  *                                                075  *
077  * @param stack_size The size of the stack.       076  * @param stack_size The size of the stack.
078  *                                                077  *
079  * @param exit_func The address of the instruc    078  * @param exit_func The address of the instruction executed after the
080  * function start_func has returned. This func    079  * function start_func has returned. This function takes 1 parameter
081  * as argument: exit_arg.                         080  * as argument: exit_arg.
082  *                                                081  *
083  * @param exit_arg The argument passed to the     082  * @param exit_arg The argument passed to the function exit_func.
084  *                                                083  *
085  * @note the newly created context is INTERRUP    084  * @note the newly created context is INTERRUPTIBLE by default !
086  */                                               085  */
087 sos_ret_t sos_cpu_kstate_init(struct sos_cpu_s !! 086 sos_ret_t sos_cpu_kstate_init(struct sos_cpu_kstate **ctxt,
088                               sos_cpu_kstate_f    087                               sos_cpu_kstate_function_arg1_t *start_func,
089                               sos_ui32_t  star    088                               sos_ui32_t  start_arg,
090                               sos_vaddr_t stac    089                               sos_vaddr_t stack_bottom,
091                               sos_size_t  stac    090                               sos_size_t  stack_size,
092                               sos_cpu_kstate_f    091                               sos_cpu_kstate_function_arg1_t *exit_func,
093                               sos_ui32_t  exit    092                               sos_ui32_t  exit_arg);
094                                                   093 
095                                                   094 
096 /**                                               095 /**
097  * Function that performs an immediate context !! 096  * Function that performs an immediate context-switch from one kernel
098  * kernel/user thread to another one. It store !! 097  * thread to another one. It stores the current executing context in
099  * context in from_ctxt, and restores to_conte !! 098  * from_ctxt, and restores to_context on CPU.
100  *                                                099  *
101  * @param from_ctxt The address of the struct  !! 100  * @param from_ctxt The address of the struct sos_cpu_kstate will be
102  * stored in this variable. Must NOT be NULL.     101  * stored in this variable. Must NOT be NULL.
103  *                                                102  *
104  * @param to_ctxt The CPU will resume its exec    103  * @param to_ctxt The CPU will resume its execution with the struct
105  * sos_cpu_state located at this address. Must !! 104  * sos_cpu_kstate located at this address. Must NOT be NULL.
106  */                                               105  */
107 void sos_cpu_context_switch(struct sos_cpu_sta !! 106 void sos_cpu_kstate_switch(struct sos_cpu_kstate **from_ctxt,
108                             struct sos_cpu_sta !! 107                            struct sos_cpu_kstate *to_ctxt);
109                                                   108 
110                                                   109 
111 /*                                                110 /*
112  * Switch to the new given context (of a kerne !! 111  * Switch to the new given context (of a kernel thread) without saving
113  * saving the old context (of another kernel/u !! 112  * the old context (of another kernel thread), and call the function
114  * the function reclaiming_func passing it the !! 113  * reclaiming_func passing it the recalining_arg argument. The
115  * argument. The reclaining function is called !! 114  * reclaining function is called from within the stack of the new
116  * of the new context, so that it can (among o !! 115  * context, so that it can (among other things) safely destroy the
117  * destroy the stack of the former context.    !! 116  * stack of the former context.
118  *                                                117  *
119  * @param switch_to_ctxt The context that will    118  * @param switch_to_ctxt The context that will be restored on the CPU
120  *                                                119  *
121  * @param reclaiming_func The address of the f    120  * @param reclaiming_func The address of the function that will be
122  * called after having changed the stack, but     121  * called after having changed the stack, but before restoring the CPU
123  * context to switch_to_ctxt.                     122  * context to switch_to_ctxt.
124  */                                               123  */
125 void                                              124 void
126 sos_cpu_context_exit_to(struct sos_cpu_state * !! 125 sos_cpu_kstate_exit_to(struct sos_cpu_kstate *switch_to_ctxt,
127                         sos_cpu_kstate_functio !! 126                        sos_cpu_kstate_function_arg1_t *reclaiming_func,
128                         sos_ui32_t reclaiming_ !! 127                        sos_ui32_t reclaiming_arg) __attribute__((noreturn));
                                                   >> 128 
129                                                   129 
130 /* ===========================================    130 /* =======================================================================
131  * Public Accessor functions                      131  * Public Accessor functions
132  */                                               132  */
133                                                   133 
134                                                << 
135 /**                                               134 /**
136  * Return Program Counter stored in the saved  !! 135  * Return Program Counter stored in the saved context
137  */                                               136  */
138 sos_vaddr_t sos_cpu_context_get_PC(const struc !! 137 sos_vaddr_t sos_cpu_kstate_get_PC(const struct sos_cpu_kstate *ctxt);
139                                                   138 
140                                                   139 
141 /**                                               140 /**
142  * Return Stack Pointer stored in the saved ke !! 141  * Return Stack Pointer stored in the saved context
143  */                                               142  */
144 sos_vaddr_t sos_cpu_context_get_SP(const struc !! 143 sos_vaddr_t sos_cpu_kstate_get_SP(const struct sos_cpu_kstate *ctxt);
145                                                   144 
146                                                   145 
147 /**                                               146 /**
148  * Dump the contents of the CPU context (bochs    147  * Dump the contents of the CPU context (bochs + x86_videomem)
149  */                                               148  */
150 void sos_cpu_context_dump(const struct sos_cpu !! 149 void sos_cpu_kstate_dump(const struct sos_cpu_kstate *ctxt);
151                                                   150 
152                                                   151 
153 /* ===========================================    152 /* =======================================================================
154  * Public Accessor functions TO BE USED ONLY B    153  * Public Accessor functions TO BE USED ONLY BY Exception handlers
155  */                                               154  */
156                                                   155 
157                                                   156 
158 /**                                               157 /**
159  * Return the argument passed by the CPU upon     158  * Return the argument passed by the CPU upon exception, as stored in the
160  * saved context                                  159  * saved context
161  */                                               160  */
162 sos_ui32_t sos_cpu_context_get_EX_info(const s !! 161 sos_ui32_t sos_cpu_kstate_get_EX_info(const struct sos_cpu_kstate *ctxt);
163                                                   162 
164                                                   163 
165 /**                                               164 /**
166  * Return the faulting address of the exceptio    165  * Return the faulting address of the exception
167  */                                               166  */
168 sos_vaddr_t                                       167 sos_vaddr_t
169 sos_cpu_context_get_EX_faulting_vaddr(const st !! 168 sos_cpu_kstate_get_EX_faulting_vaddr(const struct sos_cpu_kstate *ctxt);
170                                                   169 
171                                                   170 
172 /* ===========================================    171 /* =======================================================================
173  * Macros controlling stack poisoning.            172  * Macros controlling stack poisoning.
174  * Stack poisoning can be used to detect:         173  * Stack poisoning can be used to detect:
175  *  - unitialized local variables                 174  *  - unitialized local variables
176  *  - when the thread might have gone too deep    175  *  - when the thread might have gone too deep in the stack
177  */                                               176  */
178 /** The signature of the poison */                177 /** The signature of the poison */
179 #define SOS_CPU_STATE_STACK_POISON 0xa5        !! 178 #define SOS_CPU_KSTATE_STACK_POISON 0xa5
180                                                   179 
181 /**                                               180 /**
182  * When set, mean that the whole stack is pois    181  * When set, mean that the whole stack is poisoned to detect use of
183  * unititialized variables                        182  * unititialized variables
184  */                                               183  */
185 #define SOS_CPU_STATE_DETECT_UNINIT_KERNEL_VAR !! 184 #define SOS_CPU_KSTATE_DETECT_UNINIT_VARS
186 /* #undef SOS_CPU_STATE_DETECT_UNINIT_KERNEL_V !! 185 /* #undef SOS_CPU_KSTATE_DETECT_UNINIT_VARS */
187                                                   186 
188 /**                                               187 /**
189  * When set, mean that the bottom of the stack    188  * When set, mean that the bottom of the stack is poisoned to detect
190  * probable stack overflow. Its value indicate    189  * probable stack overflow. Its value indicates the number of bytes
191  * used for this detection.                       190  * used for this detection.
192  */                                               191  */
193 #define SOS_CPU_STATE_DETECT_KERNEL_STACK_OVER !! 192 #define SOS_CPU_KSTATE_DETECT_STACK_OVERFLOW  64
194 /* #undef SOS_CPU_STATE_DETECT_KERNEL_STACK_OV !! 193 /* #undef SOS_CPU_KSTATE_DETECT_STACK_OVERFLOW */
195                                                   194 
196 #if defined(SOS_CPU_STATE_DETECT_KERNEL_STACK_ !! 195 #if defined(SOS_CPU_KSTATE_DETECT_STACK_OVERFLOW)
197 void                                              196 void
198 sos_cpu_state_prepare_detect_kernel_stack_over !! 197 sos_cpu_kstate_prepare_detect_stack_overflow(const struct sos_cpu_kstate *ctxt,
199                                                !! 198                                              sos_vaddr_t stack_bottom,
200                                                !! 199                                              sos_size_t stack_size);
201 void sos_cpu_state_detect_kernel_stack_overflo !! 200 void sos_cpu_kstate_detect_stack_overflow(const struct sos_cpu_kstate *ctxt,
202                                                !! 201                                           sos_vaddr_t stack_bottom,
203                                                !! 202                                           sos_size_t stack_size);
204 #else                                             203 #else
205 # define sos_cpu_state_prepare_detect_kernel_s !! 204 # define sos_cpu_kstate_prepare_detect_stack_overflow(ctxt,stkbottom,stksize) \
206   ({ /* nop */ })                                 205   ({ /* nop */ })
207 # define sos_cpu_state_detect_kernel_stack_ove !! 206 # define sos_cpu_kstate_detect_stack_overflow(ctxt,stkbottom,stksize) \
208   ({ /* nop */ })                                 207   ({ /* nop */ })
209 #endif                                            208 #endif
210                                                   209 
211                                                   210 
212 /* ===========================================    211 /* =======================================================================
213  * Backtrace facility. To be used for DEBUGgin    212  * Backtrace facility. To be used for DEBUGging purpose ONLY.
214  */                                               213  */
215                                                   214 
216                                                   215 
217 /**                                               216 /**
218  * The function called at each step of the bac    217  * The function called at each step of the backtrace iterations
219  *                                                218  *
220  * @param PC The address of the next instructi    219  * @param PC The address of the next instruction of the function that
221  * will be executed                               220  * will be executed
222  *                                                221  *
223  * @param params The address of the array of t    222  * @param params The address of the array of the parameteres that have
224  * been passed to the function considered         223  * been passed to the function considered
225  *                                                224  *
226  * @param depth The index of the iteration (ie    225  * @param depth The index of the iteration (ie the depth of the
227  * current frame into the stack)                  226  * current frame into the stack)
228  *                                                227  *
229  * @param custom_arg Whatever you want: this i    228  * @param custom_arg Whatever you want: this is the argument passed as
230  * custom_arg to sos_backtrace()                  229  * custom_arg to sos_backtrace()
231  */                                               230  */
232 typedef void (sos_backtrace_callback_t)(sos_va    231 typedef void (sos_backtrace_callback_t)(sos_vaddr_t PC,
233                                         sos_va    232                                         sos_vaddr_t params,
234                                         sos_ui    233                                         sos_ui32_t depth,
235                                         void *    234                                         void *custom_arg);
236                                                   235 
237                                                   236 
238 /**                                               237 /**
239  * Call the backtracer callback on each frame  !! 238  * Call the backtracer callback on each frame stored in the cpu_kstate
240  *                                                239  *
241  * @param cpu_state The CPU context we want to !! 240  * @param cpu_kstate The CPU context we want to explore. NULL to
242  * context of a thread in Kernel mode, or NULL !! 241  * backtrace the current CPU context.
243  * the current CPU context.                    << 
244  *                                                242  *
245  * @param max_depth The maximum number of fram    243  * @param max_depth The maximum number of frames to explore
246  *                                                244  *
247  * @param stack_bottom The lower boundary of t    245  * @param stack_bottom The lower boundary of the stack. This is used
248  * to make sure that the frame addresses fit i    246  * to make sure that the frame addresses fit inside the stack
249  * boudaries (ie are potentially correct).        247  * boudaries (ie are potentially correct).
250  *                                                248  *
251  * @param stack_size The size of the stack. Sa    249  * @param stack_size The size of the stack. Same comment.
252  *                                                250  *
253  * @param backtracer The function to call to h    251  * @param backtracer The function to call to handle the frame for each
254  * iteration                                      252  * iteration
255  *                                                253  *
256  * @param custom_arg The arg passed as custom_    254  * @param custom_arg The arg passed as custom_arg to the backtracer
257  *                                                255  *
258  * @return The number of frames explored.         256  * @return The number of frames explored.
259  *                                                257  *
260  * @note Might be inaccurate when gcc's -fomit    258  * @note Might be inaccurate when gcc's -fomit-frame-pointer has been
261  * used.                                          259  * used.
262  */                                               260  */
263 sos_ui32_t sos_backtrace(const struct sos_cpu_ !! 261 sos_ui32_t sos_backtrace(const struct sos_cpu_kstate *cpu_kstate,
264                          sos_ui32_t max_depth,    262                          sos_ui32_t max_depth,
265                          sos_vaddr_t stack_bot    263                          sos_vaddr_t stack_bottom,
266                          sos_size_t stack_size    264                          sos_size_t stack_size,
267                          sos_backtrace_callbac    265                          sos_backtrace_callback_t * backtracer,
268                          void *custom_arg);       266                          void *custom_arg);
269                                                   267 
270 #endif /* _SOS_CPUCTXT_H_ */                      268 #endif /* _SOS_CPUCTXT_H_ */
                                                      

source navigation ] diff markup ] identifier search ] general search ]