frame.h
Go to the documentation of this file.00001
00045 #ifndef CPU_FRAME_H
00046 #define CPU_FRAME_H
00047
00048 #include <cpu/detect.h>
00049
00050 #include "cfg/cfg_arch.h"
00051 #include <cfg/compiler.h>
00052
00053 #if CPU_X86
00054 #if CPU_X86_32
00055 #define CPU_SAVED_REGS_CNT 2
00056 #elif CPU_X86_64
00057 #define CPU_SAVED_REGS_CNT 8
00058 #else
00059 #error "unknown CPU"
00060 #endif
00061 #define CPU_STACK_GROWS_UPWARD 0
00062 #define CPU_SP_ON_EMPTY_SLOT 0
00063
00064 #elif CPU_ARM
00065
00066 #define CPU_SAVED_REGS_CNT 8
00067 #define CPU_STACK_GROWS_UPWARD 0
00068 #define CPU_SP_ON_EMPTY_SLOT 0
00069
00070 #elif CPU_CM3
00071
00072 #define CPU_SAVED_REGS_CNT 8
00073 #define CPU_STACK_GROWS_UPWARD 0
00074 #define CPU_SP_ON_EMPTY_SLOT 0
00075
00076 #elif CPU_PPC
00077
00078 #define CPU_SAVED_REGS_CNT 1
00079 #define CPU_STACK_GROWS_UPWARD 0
00080 #define CPU_SP_ON_EMPTY_SLOT 1
00081
00082 #elif CPU_DSP56K
00083
00084 #define CPU_SAVED_REGS_CNT 8
00085 #define CPU_STACK_GROWS_UPWARD 1
00086 #define CPU_SP_ON_EMPTY_SLOT 0
00087
00088 #elif CPU_AVR
00089
00090 #define CPU_SAVED_REGS_CNT 18
00091 #define CPU_STACK_GROWS_UPWARD 0
00092 #define CPU_SP_ON_EMPTY_SLOT 1
00093
00094 #elif CPU_MSP430
00095
00096 #define CPU_SAVED_REGS_CNT 16
00097 #define CPU_STACK_GROWS_UPWARD 1
00098 #define CPU_SP_ON_EMPTY_SLOT 0
00099
00100 #else
00101 #error No CPU_... defined.
00102 #endif
00103
00104 #ifndef CPU_STACK_GROWS_UPWARD
00105 #error CPU_STACK_GROWS_UPWARD should have been defined to either 0 or 1
00106 #endif
00107
00108 #ifndef CPU_SP_ON_EMPTY_SLOT
00109 #error CPU_SP_ON_EMPTY_SLOT should have been defined to either 0 or 1
00110 #endif
00111
00113 #ifndef CPU_REG_INIT_VALUE
00114 #define CPU_REG_INIT_VALUE(reg) (reg)
00115 #endif
00116
00117
00118
00119
00120
00121
00122
00123 #if !CPU_STACK_GROWS_UPWARD
00124 #if !CPU_SP_ON_EMPTY_SLOT
00125
00126 #define CPU_PUSH_WORD(sp, data) \
00127 do { *--(sp) = (data); } while (0)
00128 #define CPU_POP_WORD(sp) \
00129 (*(sp)++)
00130 #else
00131
00132 #define CPU_PUSH_WORD(sp, data) \
00133 do { *(sp)-- = (data); } while (0)
00134 #define CPU_POP_WORD(sp) \
00135 (*++(sp))
00136 #endif
00137
00138 #else
00139
00140 #if !CPU_SP_ON_EMPTY_SLOT
00141
00142 #define CPU_PUSH_WORD(sp, data) \
00143 do { *++(sp) = (cpu_stack_t)(data); } while (0)
00144 #define CPU_POP_WORD(sp) \
00145 (*(sp)--)
00146 #else
00147 #error I bet you cannot find a CPU like this
00148 #endif
00149 #endif
00150
00151
00152 #if CPU_DSP56K
00153
00154
00155
00156
00157
00158 #define CPU_PUSH_CALL_FRAME(sp, func) \
00159 do { \
00160 CPU_PUSH_WORD((sp), (func)); \
00161 CPU_PUSH_WORD((sp), 0x100); \
00162 } while (0);
00163
00164 #elif CPU_CM3
00165
00166 #if CONFIG_KERN_PREEMPT
00167 INLINE void cm3_preempt_switch_context(cpu_stack_t **new_sp, cpu_stack_t **old_sp)
00168 {
00169 register cpu_stack_t **__new_sp asm ("r0") = new_sp;
00170 register cpu_stack_t **__old_sp asm ("r1") = old_sp;
00171
00172 asm volatile ("svc #0"
00173 : : "r"(__new_sp), "r"(__old_sp) : "memory", "cc");
00174 }
00175 #define asm_switch_context cm3_preempt_switch_context
00176
00177 #define CPU_CREATE_NEW_STACK(stack) \
00178 do { \
00179 size_t i; \
00180 \
00181 CPU_PUSH_WORD((stack), 0x01000000); \
00182 CPU_PUSH_WORD((stack), (cpu_stack_t)proc_entry); \
00183 CPU_PUSH_WORD((stack), 0); \
00184 CPU_PUSH_WORD((stack), 0); \
00185 CPU_PUSH_WORD((stack), 0); \
00186 CPU_PUSH_WORD((stack), 0); \
00187 CPU_PUSH_WORD((stack), 0); \
00188 CPU_PUSH_WORD((stack), 0); \
00189 CPU_PUSH_WORD((stack), 0xfffffffd); \
00190 \
00191 for (i = 0; i < CPU_SAVED_REGS_CNT; i++) \
00192 CPU_PUSH_WORD(stack, CPU_REG_INIT_VALUE(i)); \
00193 CPU_PUSH_WORD(stack, IRQ_PRIO_DISABLED); \
00194 } while (0)
00195
00196 #endif
00197
00198 #elif CPU_AVR
00199
00200
00201
00202
00203
00204 #define CPU_PUSH_CALL_FRAME(sp, func) \
00205 do { \
00206 uint16_t funcaddr = (uint16_t)(func); \
00207 CPU_PUSH_WORD((sp), funcaddr); \
00208 CPU_PUSH_WORD((sp), funcaddr>>8); \
00209 } while (0)
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233 #define CPU_IDLE NOP
00234
00235 #elif CPU_PPC
00236
00237 #define CPU_PUSH_CALL_FRAME(sp, func) \
00238 do { \
00239 CPU_PUSH_WORD((sp), (cpu_stack_t)(func)); \
00240 CPU_PUSH_WORD((sp), 0); \
00241 } while (0)
00242
00243 #endif
00244
00245 #ifndef CPU_PUSH_CALL_FRAME
00246 #define CPU_PUSH_CALL_FRAME(sp, func) \
00247 CPU_PUSH_WORD((sp), (cpu_stack_t)(func))
00248 #endif
00249
00259 #ifndef CPU_IDLE
00260 #define CPU_IDLE PAUSE
00261 #endif
00262
00266 #ifndef CPU_CREATE_NEW_STACK
00267
00268 #define CPU_CREATE_NEW_STACK(stack) \
00269 do { \
00270 size_t i; \
00271 \
00272 CPU_PUSH_CALL_FRAME(stack, proc_entry); \
00273 \
00274 for (i = 0; i < CPU_SAVED_REGS_CNT; i++) \
00275 CPU_PUSH_WORD(stack, CPU_REG_INIT_VALUE(i)); \
00276 } while (0)
00277 #endif
00278
00279 #endif