1 /*----------------------------------------------------------------------------
\r
2 *------------------------ M a R T E O S -------------------------
\r
3 *----------------------------------------------------------------------------
\r
6 * 'm a r t e _ n o n _ l o c a l _ j m p'
\r
10 * File 'marte_non_local_jmp.h' By MAR.
\r
12 * Non-local jumps for preempted tasks.
\r
13 * Functionality implemented in 'non_local_jump.ad[ab]'.
\r
17 *---------------------------------------------------------------------------*/
\r
20 * 02-08-07: primera versiĆ³n
\r
22 * {MAR>} -------------------------------------------------------------------*/
\r
24 #ifndef _MARTE_NON_LOCAL_JMP_H_
\r
25 #define _MARTE_NON_LOCAL_JMP_H_
\r
27 //#include <sys/cpp_macros.h>
\r
28 #include <sys/types.h>
\r
32 // GNAT 2005: typedef struct { int b[108/4]; } marte_nonlocaljmp_context_t;
\r
34 typedef struct { int b[156/4]; } marte_nonlocaljmp_context_t;
\r
36 /*-----------------------------------
\r
37 *-- marte_nonlocaljmp_savecontext --
\r
38 *-----------------------------------*/
\r
40 * Context stores the information required to modify the stack of a
\r
41 * preempted task with 'restorecontext'.
\r
43 * This function stores in 'context' the registers and its stack frame. This
\r
44 * information can be used for 'restorecontext' to change the stack of the
\r
45 * task (when it is preempted) so that when it is scheduled again it returns
\r
46 * to the end of this function
\r
48 void marte_nonlocaljmp_savecontext
\r
49 (marte_nonlocaljmp_context_t * context);
\r
51 /*----------------------------------
\r
52 *-- marte_nonlocaljmp_afterjmp --
\r
53 *----------------------------------*/
\r
55 * To be invoked after 'Save_Context'. If invoked after a direct invocation
\r
56 * to 'Save_Context', 'After_Jump' shall return 0. If invoked after
\r
57 * returning from 'Save_Context' due to a call to 'Restore_Context',
\r
58 * 'After_Jump' shall return 1.
\r
60 int marte_nonlocaljmp_afterjmp(const marte_nonlocaljmp_context_t * context);
\r
62 /*--------------------------------------
\r
63 *-- marte_nonlocaljmp_restorecontext --
\r
64 *--------------------------------------*/
\r
66 * This procedure changes the return context of a preempted task.
\r
69 * TCB_Ac.Stack_Ptr->| Regs | | |
\r
72 * | | | ret |<-TCB_Ac.Stack_Ptr
\r
74 * | |<-Context.Esp->| SC* |
\r
79 * SC*: stack frame of 'Save_Context'.
\r
81 * The next time the task is scheduled will execute the final part of
\r
84 * The full process is the following: 'Save_Context' stores the registers
\r
85 * and its stack frame in 'Jmp_Context'. 'Restore_Context' restores that
\r
86 * context placing the stored frame in the same position of the stack it was
\r
87 * originally. Over this frame it is placed the value of the ebp register
\r
88 * and the address of label "1:" in 'Save_Context'.
\r
89 * When the task is scheduled again, the first instruction it executes is
\r
90 * "ret" in 'Processor_Registers.Context_Switch' and then the address of
\r
91 * label "1:" in 'Save_Context' is popped from the stack. Once in
\r
92 * 'Save_Context', the ebp register is also popped and, with this
\r
93 * instruction, the registers and stack are in the same situation it was the
\r
94 * time that the contexts was stored, and then the final part of
\r
95 * 'Save_Context' can be executed successfully.
\r
97 void marte_nonlocaljmp_restorecontext
\r
99 marte_nonlocaljmp_context_t * context);
\r
103 #endif // _MARTE_NON_LOCAL_JMP_H_
\r