Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/include/context.h

    r716fb9d r7a0359b  
    2727 */
    2828
    29 /** @addtogroup generic 
     29/** @addtogroup generic
    3030 * @{
    3131 */
     
    3636#define KERN_CONTEXT_H_
    3737
    38 #include <arch/types.h>
     38#include <typedefs.h>
     39#include <trace.h>
    3940#include <arch/context.h>
    4041
     42#define context_set_generic(ctx, _pc, stack, size) \
     43        (ctx)->pc = (uintptr_t) (_pc); \
     44        (ctx)->sp = ((uintptr_t) (stack)) + (size) - SP_DELTA;
    4145
    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));
     46extern int context_save_arch(context_t *ctx) __attribute__((returns_twice));
     47extern void context_restore_arch(context_t *ctx) __attribute__((noreturn));
    5048
    5149/** Save register context.
    5250 *
    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
    5753 * address as the corresponding call to context_save().
    5854 *
    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:
    6257 *
    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.
    6474 *
    6575 * @return context_save() returns 1, context_restore() returns 0.
     76 *
    6677 */
    67 #define context_save(c)   context_save_arch(c)
     78#define context_save(ctx)  context_save_arch(ctx)
    6879
    6980/** Restore register context.
    7081 *
    71  * Restore previously saved register context (including stack pointers)
    72  * from context structure.
     82 * Restore a previously saved register context (including stack pointer) from
     83 * a context structure.
    7384 *
    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.
    7888 *
    79  * @param c Context structure.
     89 * @param ctx Context structure.
     90 *
    8091 */
    81 static inline void context_restore(context_t *c)
     92NO_TRACE static inline void context_restore(context_t *ctx)
    8293{
    83         context_restore_arch(c);
     94        context_restore_arch(ctx);
    8495}
    8596
Note: See TracChangeset for help on using the changeset viewer.