Ignore:
File:
1 edited

Legend:

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

    r7a0359b r716fb9d  
    2727 */
    2828
    29 /** @addtogroup generic
     29/** @addtogroup generic 
    3030 * @{
    3131 */
     
    3636#define KERN_CONTEXT_H_
    3737
    38 #include <typedefs.h>
    39 #include <trace.h>
     38#include <arch/types.h>
    4039#include <arch/context.h>
    4140
    42 #define context_set_generic(ctx, _pc, stack, size) \
    43         (ctx)->pc = (uintptr_t) (_pc); \
    44         (ctx)->sp = ((uintptr_t) (stack)) + (size) - SP_DELTA;
    4541
    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
     48extern int context_save_arch(context_t *c) __attribute__ ((returns_twice));
     49extern void context_restore_arch(context_t *c) __attribute__ ((noreturn));
    4850
    4951/** Save register context.
    5052 *
    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
    5357 * address as the corresponding call to context_save().
    5458 *
    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.
    5762 *
    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.
    7464 *
    7565 * @return context_save() returns 1, context_restore() returns 0.
    76  *
    7766 */
    78 #define context_save(ctx)  context_save_arch(ctx)
     67#define context_save(c)   context_save_arch(c)
    7968
    8069/** Restore register context.
    8170 *
    82  * Restore a previously saved register context (including stack pointer) from
    83  * a context structure.
     71 * Restore previously saved register context (including stack pointers)
     72 * from context structure.
    8473 *
    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.
    8878 *
    89  * @param ctx Context structure.
    90  *
     79 * @param c Context structure.
    9180 */
    92 NO_TRACE static inline void context_restore(context_t *ctx)
     81static inline void context_restore(context_t *c)
    9382{
    94         context_restore_arch(ctx);
     83        context_restore_arch(c);
    9584}
    9685
Note: See TracChangeset for help on using the changeset viewer.