Changes in kernel/generic/include/context.h [716fb9d:7a0359b] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/include/context.h
r716fb9d r7a0359b 27 27 */ 28 28 29 /** @addtogroup generic 29 /** @addtogroup generic 30 30 * @{ 31 31 */ … … 36 36 #define KERN_CONTEXT_H_ 37 37 38 #include <arch/types.h> 38 #include <typedefs.h> 39 #include <trace.h> 39 40 #include <arch/context.h> 40 41 42 #define context_set_generic(ctx, _pc, stack, size) \ 43 (ctx)->pc = (uintptr_t) (_pc); \ 44 (ctx)->sp = ((uintptr_t) (stack)) + (size) - SP_DELTA; 41 45 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)); 46 extern int context_save_arch(context_t *ctx) __attribute__((returns_twice)); 47 extern void context_restore_arch(context_t *ctx) __attribute__((noreturn)); 50 48 51 49 /** Save register context. 52 50 * 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 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 57 53 * address as the corresponding call to context_save(). 58 54 * 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. 55 * Note that context_save_arch() must reuse the stack frame of the function 56 * which called context_save(). We guarantee this by: 62 57 * 63 * @param c Context structure. 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. 64 74 * 65 75 * @return context_save() returns 1, context_restore() returns 0. 76 * 66 77 */ 67 #define context_save(c ) context_save_arch(c)78 #define context_save(ctx) context_save_arch(ctx) 68 79 69 80 /** Restore register context. 70 81 * 71 * Restore previously saved register context (including stack pointers)72 * fromcontext structure.82 * Restore a previously saved register context (including stack pointer) from 83 * a context structure. 73 84 * 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. 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. 78 88 * 79 * @param c Context structure. 89 * @param ctx Context structure. 90 * 80 91 */ 81 static inline void context_restore(context_t *c)92 NO_TRACE static inline void context_restore(context_t *ctx) 82 93 { 83 context_restore_arch(c );94 context_restore_arch(ctx); 84 95 } 85 96
Note:
See TracChangeset
for help on using the changeset viewer.