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
00055 #define CPU_SAVED_REGS_CNT 7
00056 #define CPU_STACK_GROWS_UPWARD 0
00057 #define CPU_SP_ON_EMPTY_SLOT 0
00058
00059 #elif CPU_ARM
00060
00061 #define CPU_SAVED_REGS_CNT 10
00062 #define CPU_STACK_GROWS_UPWARD 0
00063 #define CPU_SP_ON_EMPTY_SLOT 0
00064
00073 #define CPU_CREATE_NEW_STACK(stack, entry, exit) \
00074 do { \
00075 \
00076 CPU_PUSH_CALL_FRAME(stack, entry); \
00077 \
00078 CPU_PUSH_CALL_FRAME(stack, exit); \
00079 \
00080 CPU_PUSH_WORD(stack, 0x11111111); \
00081 \
00082 CPU_PUSH_WORD(stack, 0x10101010); \
00083 \
00084 CPU_PUSH_WORD(stack, 0x09090909); \
00085 \
00086 CPU_PUSH_WORD(stack, 0x08080808); \
00087 \
00088 CPU_PUSH_WORD(stack, 0x07070707); \
00089 \
00090 CPU_PUSH_WORD(stack, 0x06060606); \
00091 \
00092 CPU_PUSH_WORD(stack, 0x05050505); \
00093 \
00094 CPU_PUSH_WORD(stack, 0x04040404); \
00095 \
00096 CPU_PUSH_WORD(stack, 0x00000013); \
00097 } while (0)
00098
00099 #elif CPU_PPC
00100
00101 #define CPU_SAVED_REGS_CNT 1
00102 #define CPU_STACK_GROWS_UPWARD 0
00103 #define CPU_SP_ON_EMPTY_SLOT 1
00104
00105 #elif CPU_DSP56K
00106
00107 #define CPU_SAVED_REGS_CNT 8
00108 #define CPU_STACK_GROWS_UPWARD 1
00109 #define CPU_SP_ON_EMPTY_SLOT 0
00110
00111 #elif CPU_AVR
00112
00113 #define CPU_SAVED_REGS_CNT 19
00114 #define CPU_STACK_GROWS_UPWARD 0
00115 #define CPU_SP_ON_EMPTY_SLOT 1
00116
00123 #define CPU_REG_INIT_VALUE(reg) (reg == 0 ? 0x80 : 0)
00124
00125 #else
00126 #error No CPU_... defined.
00127 #endif
00128
00129 #ifndef CPU_STACK_GROWS_UPWARD
00130 #error CPU_STACK_GROWS_UPWARD should have been defined to either 0 or 1
00131 #endif
00132
00133 #ifndef CPU_SP_ON_EMPTY_SLOT
00134 #error CPU_SP_ON_EMPTY_SLOT should have been defined to either 0 or 1
00135 #endif
00136
00138 #ifndef CPU_REG_INIT_VALUE
00139 #define CPU_REG_INIT_VALUE(reg) 0
00140 #endif
00141
00142
00143
00144
00145
00146
00147
00148 #if !CPU_STACK_GROWS_UPWARD
00149 #if !CPU_SP_ON_EMPTY_SLOT
00150
00151 #define CPU_PUSH_WORD(sp, data) \
00152 do { *--(sp) = (data); } while (0)
00153 #define CPU_POP_WORD(sp) \
00154 (*(sp)++)
00155 #else
00156
00157 #define CPU_PUSH_WORD(sp, data) \
00158 do { *(sp)-- = (data); } while (0)
00159 #define CPU_POP_WORD(sp) \
00160 (*++(sp))
00161 #endif
00162
00163 #else
00164
00165 #if !CPU_SP_ON_EMPTY_SLOT
00166
00167 #define CPU_PUSH_WORD(sp, data) \
00168 do { *++(sp) = (cpu_stack_t)(data); } while (0)
00169 #define CPU_POP_WORD(sp) \
00170 (*(sp)--)
00171 #else
00172 #error I bet you cannot find a CPU like this
00173 #endif
00174 #endif
00175
00176
00177 #if CPU_DSP56K
00178
00179
00180
00181
00182
00183 #define CPU_PUSH_CALL_FRAME(sp, func) \
00184 do { \
00185 CPU_PUSH_WORD((sp), (func)); \
00186 CPU_PUSH_WORD((sp), 0x100); \
00187 } while (0);
00188
00189 #elif CPU_AVR
00190
00191
00192
00193
00194
00195 #define CPU_PUSH_CALL_FRAME(sp, func) \
00196 do { \
00197 uint16_t funcaddr = (uint16_t)(func); \
00198 CPU_PUSH_WORD((sp), funcaddr); \
00199 CPU_PUSH_WORD((sp), funcaddr>>8); \
00200 } while (0)
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224 #define CPU_IDLE NOP
00225
00226 #elif CPU_PPC
00227
00228 #define CPU_PUSH_CALL_FRAME(sp, func) \
00229 do { \
00230 CPU_PUSH_WORD((sp), (cpu_stack_t)(func)); \
00231 CPU_PUSH_WORD((sp), 0); \
00232 } while (0)
00233
00234 #else
00235 #define CPU_PUSH_CALL_FRAME(sp, func) \
00236 CPU_PUSH_WORD((sp), (cpu_stack_t)(func))
00237 #endif
00238
00248 #ifndef CPU_IDLE
00249 #if defined(ARCH_QT) && (ARCH & ARCH_QT)
00250
00251 EXTERN_C_BEGIN
00252 void emul_idle(void);
00253 EXTERN_C_END
00254 #define CPU_IDLE emul_idle()
00255 #else
00256 #define CPU_IDLE do { } while (0)
00257 #endif
00258 #endif
00259
00263 #ifndef CPU_CREATE_NEW_STACK
00264
00265 #define CPU_CREATE_NEW_STACK(stack, entry, exit) \
00266 do { \
00267 size_t i; \
00268 \
00269 CPU_PUSH_CALL_FRAME(stack, exit); \
00270 CPU_PUSH_CALL_FRAME(stack, entry); \
00271 \
00272 for (i = 0; i < CPU_SAVED_REGS_CNT; i++) \
00273 CPU_PUSH_WORD(stack, CPU_REG_INIT_VALUE(i)); \
00274 } while (0)
00275 #endif
00276
00277 #endif