Changes in kernel/generic/include/context.h [7a0359b:716fb9d] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/include/context.h
r7a0359b r716fb9d 27 27 */ 28 28 29 /** @addtogroup generic 29 /** @addtogroup generic 30 30 * @{ 31 31 */ … … 36 36 #define KERN_CONTEXT_H_ 37 37 38 #include <typedefs.h> 39 #include <trace.h> 38 #include <arch/types.h> 40 39 #include <arch/context.h> 41 40 42 #define context_set_generic(ctx, _pc, stack, size) \43 (ctx)->pc = (uintptr_t) (_pc); \44 (ctx)->sp = ((uintptr_t) (stack)) + (size) - SP_DELTA;45 41 46 extern int context_save_arch(context_t *ctx) __attribute__((returns_twice)); 47 extern void context_restore_arch(context_t *ctx) __attribute__((noreturn)); 42 #ifndef context_set 43 #define context_set(c, _pc, stack, size) \ 44 (c)->pc = (uintptr_t) (_pc); \ 45 (c)->sp = ((uintptr_t) (stack)) + (size) - SP_DELTA; 46 #endif /* context_set */ 47 48 extern int context_save_arch(context_t *c) __attribute__ ((returns_twice)); 49 extern void context_restore_arch(context_t *c) __attribute__ ((noreturn)); 48 50 49 51 /** Save register context. 50 52 * 51 * Save the current register context (including stack pointer) to a context 52 * structure. A subsequent call to context_restore() will return to the same 53 * Save current register context (including stack pointers) 54 * to context structure. 55 * 56 * Note that call to context_restore() will return at the same 53 57 * address as the corresponding call to context_save(). 54 58 * 55 * Note that context_save_arch() must reuse the stack frame of the function 56 * which called context_save(). We guarantee this by: 59 * This MUST be a macro, gcc -O0 does not inline functions even 60 * if they are marked inline and context_save_arch must be called 61 * from level <= that when context_restore is called. 57 62 * 58 * a) implementing context_save_arch() in assembly so that it does not create 59 * its own stack frame, and by 60 * b) defining context_save() as a macro because the inline keyword is just a 61 * hint for the compiler, not a real constraint; the application of a macro 62 * will definitely not create a stack frame either. 63 * 64 * To imagine what could happen if there were some extra stack frames created 65 * either by context_save() or context_save_arch(), we need to realize that the 66 * sp saved in the contex_t structure points to the current stack frame as it 67 * existed when context_save_arch() was executing. After the return from 68 * context_save_arch() and context_save(), any extra stack frames created by 69 * these functions will be destroyed and their contents sooner or later 70 * overwritten by functions called next. Any attempt to restore to a context 71 * saved like that would therefore lead to a disaster. 72 * 73 * @param ctx Context structure. 63 * @param c Context structure. 74 64 * 75 65 * @return context_save() returns 1, context_restore() returns 0. 76 *77 66 */ 78 #define context_save(c tx) context_save_arch(ctx)67 #define context_save(c) context_save_arch(c) 79 68 80 69 /** Restore register context. 81 70 * 82 * Restore a previously saved register context (including stack pointer) from83 * acontext structure.71 * Restore previously saved register context (including stack pointers) 72 * from context structure. 84 73 * 85 * Note that this function does not normally return. Instead, it returns to the 86 * same address as the corresponding call to context_save(), the only difference 87 * being return value. 74 * Note that this function does not normally return. 75 * Instead, it returns at the same address as the 76 * corresponding call to context_save(), the only 77 * difference being return value. 88 78 * 89 * @param ctx Context structure. 90 * 79 * @param c Context structure. 91 80 */ 92 NO_TRACE static inline void context_restore(context_t *ctx)81 static inline void context_restore(context_t *c) 93 82 { 94 context_restore_arch(c tx);83 context_restore_arch(c); 95 84 } 96 85
Note:
See TracChangeset
for help on using the changeset viewer.