summaryrefslogtreecommitdiff
path: root/src/lj_ccallback.c
diff options
context:
space:
mode:
authorMike Pall <mike>2012-01-23 22:20:28 +0100
committerMike Pall <mike>2012-01-23 22:24:11 +0100
commit5bed11e6b4c2bbf0cbec0f00efe998289236b217 (patch)
tree5ed76367d5157df37b358a5874d34a21dc7d60b0 /src/lj_ccallback.c
parent7d2774e4c5ee7c649ccb41f75bfbbb1e7f370a96 (diff)
downloadluajit-5bed11e6b4c2bbf0cbec0f00efe998289236b217.tar.gz
luajit-5bed11e6b4c2bbf0cbec0f00efe998289236b217.tar.bz2
luajit-5bed11e6b4c2bbf0cbec0f00efe998289236b217.zip
MIPS: Add interpreter. Enable MIPS build rules.
Diffstat (limited to 'src/lj_ccallback.c')
-rw-r--r--src/lj_ccallback.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/lj_ccallback.c b/src/lj_ccallback.c
index 3c95958d..d73153b1 100644
--- a/src/lj_ccallback.c
+++ b/src/lj_ccallback.c
@@ -57,6 +57,13 @@ static MSize CALLBACK_OFS2SLOT(MSize ofs)
57#define CALLBACK_OFS2SLOT(ofs) (((ofs)-CALLBACK_MCODE_HEAD)/8) 57#define CALLBACK_OFS2SLOT(ofs) (((ofs)-CALLBACK_MCODE_HEAD)/8)
58#define CALLBACK_MAX_SLOT (CALLBACK_OFS2SLOT(CALLBACK_MCODE_SIZE)) 58#define CALLBACK_MAX_SLOT (CALLBACK_OFS2SLOT(CALLBACK_MCODE_SIZE))
59 59
60#elif LJ_TARGET_MIPS
61
62#define CALLBACK_MCODE_HEAD 24
63#define CALLBACK_SLOT2OFS(slot) (CALLBACK_MCODE_HEAD + 8*(slot))
64#define CALLBACK_OFS2SLOT(ofs) (((ofs)-CALLBACK_MCODE_HEAD)/8)
65#define CALLBACK_MAX_SLOT (CALLBACK_OFS2SLOT(CALLBACK_MCODE_SIZE))
66
60#else 67#else
61 68
62/* Missing support for this architecture. */ 69/* Missing support for this architecture. */
@@ -158,6 +165,25 @@ static void callback_mcode_init(global_State *g, uint32_t *page)
158 } 165 }
159 lua_assert(p - page <= CALLBACK_MCODE_SIZE); 166 lua_assert(p - page <= CALLBACK_MCODE_SIZE);
160} 167}
168#elif LJ_TARGET_MIPS
169static void callback_mcode_init(global_State *g, uint32_t *page)
170{
171 uint32_t *p = page;
172 void *target = (void *)lj_vm_ffi_callback;
173 MSize slot;
174 *p++ = MIPSI_SW | MIPSF_T(RID_R1)|MIPSF_S(RID_SP) | 0;
175 *p++ = MIPSI_LUI | MIPSF_T(RID_R3) | (u32ptr(target) >> 16);
176 *p++ = MIPSI_LUI | MIPSF_T(RID_R2) | (u32ptr(g) >> 16);
177 *p++ = MIPSI_ORI | MIPSF_T(RID_R3)|MIPSF_S(RID_R3) |(u32ptr(target)&0xffff);
178 *p++ = MIPSI_JR | MIPSF_S(RID_R3);
179 *p++ = MIPSI_ORI | MIPSF_T(RID_R2)|MIPSF_S(RID_R2) | (u32ptr(g)&0xffff);
180 for (slot = 0; slot < CALLBACK_MAX_SLOT; slot++) {
181 *p = MIPSI_B | ((page-p-1) & 0x0000ffffu);
182 p++;
183 *p++ = MIPSI_LI | MIPSF_T(RID_R1) | slot;
184 }
185 lua_assert(p - page <= CALLBACK_MCODE_SIZE);
186}
161#else 187#else
162/* Missing support for this architecture. */ 188/* Missing support for this architecture. */
163#define callback_mcode_init(g, p) UNUSED(p) 189#define callback_mcode_init(g, p) UNUSED(p)
@@ -308,6 +334,27 @@ void lj_ccallback_mcode_free(CTState *cts)
308 if (ctype_isfp(ctr->info) && ctr->size == sizeof(float)) \ 334 if (ctype_isfp(ctr->info) && ctr->size == sizeof(float)) \
309 *(double *)dp = *(float *)dp; /* FPRs always hold doubles. */ 335 *(double *)dp = *(float *)dp; /* FPRs always hold doubles. */
310 336
337#elif LJ_TARGET_MIPS
338
339#define CALLBACK_HANDLE_REGARG \
340 if (isfp && nfpr < CCALL_NARG_FPR) { /* Try to pass argument in FPRs. */ \
341 sp = (void *)((uint8_t *)&cts->cb.fpr[nfpr] + ((LJ_BE && n==1) ? 4 : 0)); \
342 nfpr++; ngpr += n; \
343 goto done; \
344 } else { /* Try to pass argument in GPRs. */ \
345 nfpr = CCALL_NARG_FPR; \
346 if (n > 1) ngpr = (ngpr + 1u) & ~1u; /* Align to regpair. */ \
347 if (ngpr + n <= maxgpr) { \
348 sp = &cts->cb.gpr[ngpr]; \
349 ngpr += n; \
350 goto done; \
351 } \
352 }
353
354#define CALLBACK_HANDLE_RET \
355 if (ctype_isfp(ctr->info) && ctr->size == sizeof(float)) \
356 ((float *)dp)[1] = *(float *)dp;
357
311#else 358#else
312#error "Missing calling convention definitions for this architecture" 359#error "Missing calling convention definitions for this architecture"
313#endif 360#endif