]> rtime.felk.cvut.cz Git - frescor/fosa.git/blob - marte_non_local_jump/marte_non_local_jmp.h
fosa_partikle: added support for FOSA group clocks
[frescor/fosa.git] / marte_non_local_jump / marte_non_local_jmp.h
1 /*----------------------------------------------------------------------------\r
2  *------------------------      M a R T E   O S      -------------------------\r
3  *----------------------------------------------------------------------------\r
4  *                                                             {MARTE_VERSION}\r
5  *\r
6  *                   'm a r t e _ n o n _ l o c a l _ j m p'\r
7  *\r
8  *                                    H\r
9  *\r
10  * File 'marte_non_local_jmp.h'                                       By MAR.\r
11  *\r
12  * Non-local jumps for preempted tasks.\r
13  * Functionality implemented in 'non_local_jump.ad[ab]'.\r
14  *\r
15  * {MARTE_COPYRIGHT}\r
16  *\r
17  *---------------------------------------------------------------------------*/\r
18 /* {<MAR}\r
19  *\r
20  * 02-08-07: primera versiĆ³n\r
21  *\r
22  * {MAR>} -------------------------------------------------------------------*/\r
23 \r
24 #ifndef _MARTE_NON_LOCAL_JMP_H_\r
25 #define _MARTE_NON_LOCAL_JMP_H_\r
26 \r
27 //#include <sys/cpp_macros.h>\r
28 #include <sys/types.h>\r
29 \r
30 //CPP_BEGIN_DECLS\r
31 \r
32 // GNAT 2005: typedef struct { int b[108/4]; } marte_nonlocaljmp_context_t;\r
33 \r
34 typedef struct { int b[156/4]; } marte_nonlocaljmp_context_t;\r
35 \r
36 /*-----------------------------------\r
37  *-- marte_nonlocaljmp_savecontext --\r
38  *-----------------------------------*/\r
39 /*\r
40  *  Context stores the information required to modify the stack of a\r
41  *  preempted task with 'restorecontext'.\r
42  *\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
47  */\r
48 void marte_nonlocaljmp_savecontext\r
49    (marte_nonlocaljmp_context_t * context);\r
50 \r
51 /*----------------------------------\r
52  *--  marte_nonlocaljmp_afterjmp  --\r
53  *----------------------------------*/\r
54 /*\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
59  */\r
60  int marte_nonlocaljmp_afterjmp(const marte_nonlocaljmp_context_t * context);\r
61 \r
62 /*--------------------------------------\r
63  *-- marte_nonlocaljmp_restorecontext --\r
64  *--------------------------------------*/\r
65 /*\r
66  *  This procedure changes the return context of a preempted task.\r
67  *\r
68  *                    |        |               |       |\r
69  *  TCB_Ac.Stack_Ptr->|  Regs  |               |       |\r
70  *                    |        |               |       |\r
71  *                       ...                      ...\r
72  *                    |        |               |  ret  |<-TCB_Ac.Stack_Ptr\r
73  *                    |        |               |  ebp  |\r
74  *                    |        |<-Context.Esp->|  SC*  |\r
75  *                    |        |               |  SC*  |\r
76  *                    |        |               |  SC*  |\r
77  *                    |        |               |       |\r
78  *                      before                   after\r
79  *  SC*: stack frame of 'Save_Context'.\r
80  *\r
81  *  The next time the task is scheduled will execute the final part of\r
82  *  Save_Context.\r
83  *\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
96  */\r
97 void marte_nonlocaljmp_restorecontext\r
98   (pthread_t th,\r
99    marte_nonlocaljmp_context_t * context);\r
100 \r
101 //CPP_END_DECLS\r
102 \r
103 #endif // _MARTE_NON_LOCAL_JMP_H_\r