aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/install.html32
-rw-r--r--doc/luajit.html2
-rw-r--r--src/host/buildvm.c6
-rw-r--r--src/host/buildvm_peobj.c34
-rw-r--r--src/lj_arch.h2
-rw-r--r--src/lj_def.h32
-rw-r--r--src/lj_frame.h11
-rw-r--r--src/vm_ppc.dasc46
-rw-r--r--src/xedkbuild.bat91
9 files changed, 232 insertions, 24 deletions
diff --git a/doc/install.html b/doc/install.html
index 967f25fd..bb625ec8 100644
--- a/doc/install.html
+++ b/doc/install.html
@@ -134,9 +134,9 @@ operating systems, CPUs and compilers:
134<tr class="even"> 134<tr class="even">
135<td class="compatcpu"><a href="#cross2">PPC</a></td> 135<td class="compatcpu"><a href="#cross2">PPC</a></td>
136<td class="compatos">GCC 4.3+</td> 136<td class="compatos">GCC 4.3+</td>
137<td class="compatos">GCC 4.3+<br>GCC 4.1 (<a href="#cross2">PS3</a>)</td> 137<td class="compatos">GCC 4.3+<br>GCC 4.1 (<a href="#ps3">PS3</a>)</td>
138<td class="compatos compatno">&nbsp;</td>
139<td class="compatos compatno">&nbsp;</td> 138<td class="compatos compatno">&nbsp;</td>
139<td class="compatos">XEDK (<a href="#xbox360">XBox 360</a>)</td>
140</tr> 140</tr>
141<tr class="odd"> 141<tr class="odd">
142<td class="compatcpu"><a href="#cross2">PPC/e500v2</a></td> 142<td class="compatcpu"><a href="#cross2">PPC/e500v2</a></td>
@@ -376,7 +376,7 @@ CPU.
376make HOST_CC="gcc -m32" CROSS=arm-linux-gnueabi- \ 376make HOST_CC="gcc -m32" CROSS=arm-linux-gnueabi- \
377 TARGET_CFLAGS="-mfloat-abi=soft" 377 TARGET_CFLAGS="-mfloat-abi=soft"
378 378
379# ARM soft-float ABI with VFP (example for Cortex-a8) 379# ARM soft-float ABI with VFP (example for Cortex-A8)
380make HOST_CC="gcc -m32" CROSS=arm-linux-gnueabi- \ 380make HOST_CC="gcc -m32" CROSS=arm-linux-gnueabi- \
381 TARGET_CFLAGS="-mcpu=cortex-a8 -mfloat-abi=softfp" 381 TARGET_CFLAGS="-mcpu=cortex-a8 -mfloat-abi=softfp"
382 382
@@ -387,8 +387,6 @@ make HOST_CC="gcc -m32" CROSS=arm-linux-gnueabihf-
387make HOST_CC="gcc -m32" CROSS=powerpc-linux-gnu- 387make HOST_CC="gcc -m32" CROSS=powerpc-linux-gnu-
388# PPC/e500v2 (fast interpreter only) 388# PPC/e500v2 (fast interpreter only)
389make HOST_CC="gcc -m32" CROSS=powerpc-e500v2-linux-gnuspe- 389make HOST_CC="gcc -m32" CROSS=powerpc-e500v2-linux-gnuspe-
390# PS3 (fast interpreter only)
391make HOST_CC="gcc -m32" CROSS=ppu-lv2-
392 390
393# MIPS big-endian 391# MIPS big-endian
394make HOST_CC="gcc -m32" CROSS=mips-linux- 392make HOST_CC="gcc -m32" CROSS=mips-linux-
@@ -460,6 +458,30 @@ ISDKF="-arch armv7 -isysroot $ISDK/SDKs/$ISDKVER"
460make HOST_CC="gcc -m32 -arch i386" CROSS=$ISDKP TARGET_FLAGS="$ISDKF" \ 458make HOST_CC="gcc -m32 -arch i386" CROSS=$ISDKP TARGET_FLAGS="$ISDKF" \
461 TARGET_SYS=iOS 459 TARGET_SYS=iOS
462</pre> 460</pre>
461<p>
462You can cross-compile for <b id="ps3">PS3</b> using the PS3&nbsp;SDK from
463a Linux host or a Windows host (requires 32 bit MinGW (GCC) on the host,
464too). Due to restrictions on consoles, the JIT compiler is disabled and
465only the fast interpreter is built:
466</p>
467<pre class="code">
468make HOST_CC="gcc -m32" CROSS=ppu-lv2-
469</pre>
470<p>
471You can cross-compile for <b id="xbox360">XBox 360</b> using the
472XBox&nbsp;360 SDK (MSVC + XEDK). Due to restrictions on consoles, the
473JIT compiler is disabled and only the fast interpreter is built.
474</p>
475<p>
476Open a "Visual Studio .NET Command Prompt" (32&nbsp;bit host compiler),
477<tt>cd</tt> to the directory where you've unpacked the sources and run
478the following commands. This builds a static library <tt>luajit20.lib</tt>,
479which can be linked against your game, just like the Lua library.
480</p>
481<pre class="code">
482cd src
483xedkbuild
484</pre>
463 485
464<h2 id="embed">Embedding LuaJIT</h2> 486<h2 id="embed">Embedding LuaJIT</h2>
465<p> 487<p>
diff --git a/doc/luajit.html b/doc/luajit.html
index 8fb0e05f..51338412 100644
--- a/doc/luajit.html
+++ b/doc/luajit.html
@@ -158,7 +158,7 @@ LuaJIT is Copyright &copy; 2005-2012 Mike Pall, released under the
158<tr><td>Windows</td><td>Linux</td><td>BSD</td><td>OSX</td><td>POSIX</td></tr> 158<tr><td>Windows</td><td>Linux</td><td>BSD</td><td>OSX</td><td>POSIX</td></tr>
159</table> 159</table>
160<table class="feature os os2"> 160<table class="feature os os2">
161<tr><td><span style="font-size:90%;">Embedded</span></td><td>Android</td><td>iOS</td><td>PS3</td></tr> 161<tr><td><span style="font-size:90%;">Embedded</span></td><td>Android</td><td>iOS</td><td>PS3</td><td>XBox 360</td></tr>
162</table> 162</table>
163<table class="feature compiler"> 163<table class="feature compiler">
164<tr><td>GCC</td><td>CLANG<br>LLVM</td><td>MSVC</td></tr> 164<tr><td>GCC</td><td>CLANG<br>LLVM</td><td>MSVC</td></tr>
diff --git a/src/host/buildvm.c b/src/host/buildvm.c
index 72b74f1f..b56ec1e1 100644
--- a/src/host/buildvm.c
+++ b/src/host/buildvm.c
@@ -100,6 +100,8 @@ static const char *sym_decorate(BuildCtx *ctx,
100 char *p; 100 char *p;
101#if LJ_64 101#if LJ_64
102 const char *symprefix = ctx->mode == BUILD_machasm ? "_" : ""; 102 const char *symprefix = ctx->mode == BUILD_machasm ? "_" : "";
103#elif LJ_TARGET_XBOX360
104 const char *symprefix = "";
103#else 105#else
104 const char *symprefix = ctx->mode != BUILD_elfasm ? "_" : ""; 106 const char *symprefix = ctx->mode != BUILD_elfasm ? "_" : "";
105#endif 107#endif
@@ -136,7 +138,11 @@ static int collect_reloc(BuildCtx *ctx, uint8_t *addr, int idx, int type)
136 ctx->reloc[ctx->nreloc].sym = relocmap[idx]; 138 ctx->reloc[ctx->nreloc].sym = relocmap[idx];
137 ctx->reloc[ctx->nreloc].type = type; 139 ctx->reloc[ctx->nreloc].type = type;
138 ctx->nreloc++; 140 ctx->nreloc++;
141#if LJ_TARGET_XBOX360
142 return (int)(ctx->code - addr) + 4; /* Encode symbol offset of .text. */
143#else
139 return 0; /* Encode symbol offset of 0. */ 144 return 0; /* Encode symbol offset of 0. */
145#endif
140} 146}
141 147
142/* Naive insertion sort. Performance doesn't matter here. */ 148/* Naive insertion sort. Performance doesn't matter here. */
diff --git a/src/host/buildvm_peobj.c b/src/host/buildvm_peobj.c
index 17b3293a..28b771a3 100644
--- a/src/host/buildvm_peobj.c
+++ b/src/host/buildvm_peobj.c
@@ -9,7 +9,7 @@
9#include "buildvm.h" 9#include "buildvm.h"
10#include "lj_bc.h" 10#include "lj_bc.h"
11 11
12#if LJ_TARGET_X86ORX64 12#if LJ_TARGET_X86ORX64 || LJ_TARGET_PPC
13 13
14/* Context for PE object emitter. */ 14/* Context for PE object emitter. */
15static char *strtab; 15static char *strtab;
@@ -84,11 +84,21 @@ typedef struct PEsymaux {
84#define PEOBJ_ARCH_TARGET 0x014c 84#define PEOBJ_ARCH_TARGET 0x014c
85#define PEOBJ_RELOC_REL32 0x14 /* MS: REL32, GNU: DISP32. */ 85#define PEOBJ_RELOC_REL32 0x14 /* MS: REL32, GNU: DISP32. */
86#define PEOBJ_RELOC_DIR32 0x06 86#define PEOBJ_RELOC_DIR32 0x06
87#define PEOBJ_RELOC_OFS 0
88#define PEOBJ_TEXT_FLAGS 0x60500020 /* 60=r+x, 50=align16, 20=code. */
87#elif LJ_TARGET_X64 89#elif LJ_TARGET_X64
88#define PEOBJ_ARCH_TARGET 0x8664 90#define PEOBJ_ARCH_TARGET 0x8664
89#define PEOBJ_RELOC_REL32 0x04 /* MS: REL32, GNU: DISP32. */ 91#define PEOBJ_RELOC_REL32 0x04 /* MS: REL32, GNU: DISP32. */
90#define PEOBJ_RELOC_DIR32 0x02 92#define PEOBJ_RELOC_DIR32 0x02
91#define PEOBJ_RELOC_ADDR32NB 0x03 93#define PEOBJ_RELOC_ADDR32NB 0x03
94#define PEOBJ_RELOC_OFS 0
95#define PEOBJ_TEXT_FLAGS 0x60500020 /* 60=r+x, 50=align16, 20=code. */
96#elif LJ_TARGET_PPC
97#define PEOBJ_ARCH_TARGET 0x01f2
98#define PEOBJ_RELOC_REL32 0x06
99#define PEOBJ_RELOC_DIR32 0x02
100#define PEOBJ_RELOC_OFS (-4)
101#define PEOBJ_TEXT_FLAGS 0x60400020 /* 60=r+x, 40=align8, 20=code. */
92#endif 102#endif
93 103
94/* Section numbers (0-based). */ 104/* Section numbers (0-based). */
@@ -170,12 +180,6 @@ void emit_peobj(BuildCtx *ctx)
170 int i, nrsym; 180 int i, nrsym;
171 union { uint8_t b; uint32_t u; } host_endian; 181 union { uint8_t b; uint32_t u; } host_endian;
172 182
173 host_endian.u = 1;
174 if (host_endian.b != LJ_ENDIAN_SELECT(1, 0)) {
175 fprintf(stderr, "Error: different byte order for host and target\n");
176 exit(1);
177 }
178
179 sofs = sizeof(PEheader) + PEOBJ_NSECTIONS*sizeof(PEsection); 183 sofs = sizeof(PEheader) + PEOBJ_NSECTIONS*sizeof(PEsection);
180 184
181 /* Fill in PE sections. */ 185 /* Fill in PE sections. */
@@ -186,7 +190,7 @@ void emit_peobj(BuildCtx *ctx)
186 pesect[PEOBJ_SECT_TEXT].relocofs = sofs; 190 pesect[PEOBJ_SECT_TEXT].relocofs = sofs;
187 sofs += (pesect[PEOBJ_SECT_TEXT].nreloc = (uint16_t)ctx->nreloc) * PEOBJ_RELOC_SIZE; 191 sofs += (pesect[PEOBJ_SECT_TEXT].nreloc = (uint16_t)ctx->nreloc) * PEOBJ_RELOC_SIZE;
188 /* Flags: 60 = read+execute, 50 = align16, 20 = code. */ 192 /* Flags: 60 = read+execute, 50 = align16, 20 = code. */
189 pesect[PEOBJ_SECT_TEXT].flags = 0x60500020; 193 pesect[PEOBJ_SECT_TEXT].flags = PEOBJ_TEXT_FLAGS;
190 194
191#if LJ_TARGET_X64 195#if LJ_TARGET_X64
192 memcpy(pesect[PEOBJ_SECT_PDATA].name, ".pdata", sizeof(".pdata")-1); 196 memcpy(pesect[PEOBJ_SECT_PDATA].name, ".pdata", sizeof(".pdata")-1);
@@ -236,10 +240,22 @@ void emit_peobj(BuildCtx *ctx)
236 owrite(ctx, &pesect, sizeof(PEsection)*PEOBJ_NSECTIONS); 240 owrite(ctx, &pesect, sizeof(PEsection)*PEOBJ_NSECTIONS);
237 241
238 /* Write .text section. */ 242 /* Write .text section. */
243 host_endian.u = 1;
244 if (host_endian.b != LJ_ENDIAN_SELECT(1, 0)) {
245#if LJ_TARGET_PPC
246 uint32_t *p = (uint32_t *)ctx->code;
247 int n = (int)(ctx->codesz >> 2);
248 for (i = 0; i < n; i++, p++)
249 *p = lj_bswap(*p); /* Byteswap .text section. */
250#else
251 fprintf(stderr, "Error: different byte order for host and target\n");
252 exit(1);
253#endif
254 }
239 owrite(ctx, ctx->code, ctx->codesz); 255 owrite(ctx, ctx->code, ctx->codesz);
240 for (i = 0; i < ctx->nreloc; i++) { 256 for (i = 0; i < ctx->nreloc; i++) {
241 PEreloc reloc; 257 PEreloc reloc;
242 reloc.vaddr = (uint32_t)ctx->reloc[i].ofs; 258 reloc.vaddr = (uint32_t)ctx->reloc[i].ofs + PEOBJ_RELOC_OFS;
243 reloc.symidx = 1+2+ctx->reloc[i].sym; /* Reloc syms are after .text sym. */ 259 reloc.symidx = 1+2+ctx->reloc[i].sym; /* Reloc syms are after .text sym. */
244 reloc.type = ctx->reloc[i].type ? PEOBJ_RELOC_REL32 : PEOBJ_RELOC_DIR32; 260 reloc.type = ctx->reloc[i].type ? PEOBJ_RELOC_REL32 : PEOBJ_RELOC_DIR32;
245 owrite(ctx, &reloc, PEOBJ_RELOC_SIZE); 261 owrite(ctx, &reloc, PEOBJ_RELOC_SIZE);
diff --git a/src/lj_arch.h b/src/lj_arch.h
index 10071ca4..4be2f566 100644
--- a/src/lj_arch.h
+++ b/src/lj_arch.h
@@ -398,7 +398,7 @@
398#endif 398#endif
399 399
400/* Various workarounds for embedded operating systems. */ 400/* Various workarounds for embedded operating systems. */
401#if (defined(__ANDROID__) && !defined(LJ_TARGET_X86ORX64)) || defined(__symbian__) 401#if (defined(__ANDROID__) && !defined(LJ_TARGET_X86ORX64)) || defined(__symbian__) || LJ_TARGET_XBOX360
402#define LUAJIT_NO_LOG2 402#define LUAJIT_NO_LOG2
403#endif 403#endif
404#if defined(__symbian__) 404#if defined(__symbian__)
diff --git a/src/lj_def.h b/src/lj_def.h
index a28d84d7..3d8a972d 100644
--- a/src/lj_def.h
+++ b/src/lj_def.h
@@ -242,12 +242,18 @@ static LJ_AINLINE uint32_t lj_getu32(const void *p)
242#define LJ_FASTCALL __fastcall 242#define LJ_FASTCALL __fastcall
243#endif 243#endif
244 244
245#ifdef _M_PPC
246#pragma intrinsic(_CountLeadingZeros)
247unsigned int _CountLeadingZeros(long);
248static LJ_AINLINE uint32_t lj_fls(uint32_t x)
249{
250 return _CountLeadingZeros(x) ^ 31;
251}
252#else
245#pragma intrinsic(_BitScanForward) 253#pragma intrinsic(_BitScanForward)
246#pragma intrinsic(_BitScanReverse) 254#pragma intrinsic(_BitScanReverse)
247unsigned char _BitScanForward(uint32_t *, unsigned long); 255unsigned char _BitScanForward(uint32_t *, unsigned long);
248unsigned char _BitScanReverse(uint32_t *, unsigned long); 256unsigned char _BitScanReverse(uint32_t *, unsigned long);
249unsigned long _byteswap_ulong(unsigned long);
250uint64_t _byteswap_uint64(uint64_t);
251 257
252static LJ_AINLINE uint32_t lj_ffs(uint32_t x) 258static LJ_AINLINE uint32_t lj_ffs(uint32_t x)
253{ 259{
@@ -258,13 +264,33 @@ static LJ_AINLINE uint32_t lj_fls(uint32_t x)
258{ 264{
259 uint32_t r; _BitScanReverse(&r, x); return r; 265 uint32_t r; _BitScanReverse(&r, x); return r;
260} 266}
267#endif
261 268
269unsigned long _byteswap_ulong(unsigned long);
270uint64_t _byteswap_uint64(uint64_t);
262#define lj_bswap(x) (_byteswap_ulong((x))) 271#define lj_bswap(x) (_byteswap_ulong((x)))
263#define lj_bswap64(x) (_byteswap_uint64((x))) 272#define lj_bswap64(x) (_byteswap_uint64((x)))
264 273
265/* MSVC is only supported on x86/x64, where unaligned loads are always ok. */ 274#if defined(_M_PPC) && defined(LUAJIT_NO_UNALIGNED)
275/*
276** Replacement for unaligned loads on XBox 360. Disabled by default since it's
277** usually more costly than the occasional stall when crossing a cache-line.
278*/
279static LJ_AINLINE uint16_t lj_getu16(const void *v)
280{
281 const uint8_t *p = (const uint8_t *)v;
282 return (uint16_t)((p[0]<<8) | p[1]);
283}
284static LJ_AINLINE uint32_t lj_getu32(const void *v)
285{
286 const uint8_t *p = (const uint8_t *)v;
287 return (uint32_t)((p[0]<<24) | (p[1]<<16) | (p[2]<<8) | p[3]);
288}
289#else
290/* Unaligned loads are generally ok on x86/x64. */
266#define lj_getu16(p) (*(uint16_t *)(p)) 291#define lj_getu16(p) (*(uint16_t *)(p))
267#define lj_getu32(p) (*(uint32_t *)(p)) 292#define lj_getu32(p) (*(uint32_t *)(p))
293#endif
268 294
269#else 295#else
270#error "missing defines for your compiler" 296#error "missing defines for your compiler"
diff --git a/src/lj_frame.h b/src/lj_frame.h
index b8af2349..99b349c2 100644
--- a/src/lj_frame.h
+++ b/src/lj_frame.h
@@ -104,7 +104,16 @@ enum {
104#endif 104#endif
105#define CFRAME_SHIFT_MULTRES 3 105#define CFRAME_SHIFT_MULTRES 3
106#elif LJ_TARGET_PPC 106#elif LJ_TARGET_PPC
107#if LJ_ARCH_PPC64 107#if LJ_TARGET_XBOX360
108#define CFRAME_OFS_ERRF 424
109#define CFRAME_OFS_NRES 420
110#define CFRAME_OFS_PREV 400
111#define CFRAME_OFS_L 416
112#define CFRAME_OFS_PC 412
113#define CFRAME_OFS_MULTRES 408
114#define CFRAME_SIZE 384
115#define CFRAME_SHIFT_MULTRES 3
116#elif LJ_ARCH_PPC64
108#define CFRAME_OFS_ERRF 472 117#define CFRAME_OFS_ERRF 472
109#define CFRAME_OFS_NRES 468 118#define CFRAME_OFS_NRES 468
110#define CFRAME_OFS_PREV 448 119#define CFRAME_OFS_PREV 448
diff --git a/src/vm_ppc.dasc b/src/vm_ppc.dasc
index ac572ec5..19692638 100644
--- a/src/vm_ppc.dasc
+++ b/src/vm_ppc.dasc
@@ -21,6 +21,7 @@
21|// Note: a full PPC64 _LP64 port is not planned. 21|// Note: a full PPC64 _LP64 port is not planned.
22|// GPR64 64 bit registers (but possibly 32 bit pointers, e.g. PS3). 22|// GPR64 64 bit registers (but possibly 32 bit pointers, e.g. PS3).
23|// Affects reg saves, stack layout, carry/overflow/dot flags etc. 23|// Affects reg saves, stack layout, carry/overflow/dot flags etc.
24|// FRAME32 Use 32 bit frame layout, even with GPR64 (XBox 360).
24|// TOC Need table of contents (64 bit or 32 bit variant, e.g. PS3). 25|// TOC Need table of contents (64 bit or 32 bit variant, e.g. PS3).
25|// Function pointers are really a struct: code, TOC, env (optional). 26|// Function pointers are really a struct: code, TOC, env (optional).
26|// TOCENV Function pointers have an environment pointer, too (not on PS3). 27|// TOCENV Function pointers have an environment pointer, too (not on PS3).
@@ -128,6 +129,37 @@
128| 129|
129|// Stack layout while in interpreter. Must match with lj_frame.h. 130|// Stack layout while in interpreter. Must match with lj_frame.h.
130|.if GPR64 131|.if GPR64
132|.if FRAME32
133|
134|// 456(sp) // \ 32/64 bit C frame info
135|.define TONUM_LO, 452(sp) // |
136|.define TONUM_HI, 448(sp) // |
137|.define TMPD_LO, 444(sp) // |
138|.define TMPD_HI, 440(sp) // |
139|.define SAVE_CR, 432(sp) // | 64 bit CR save.
140|.define SAVE_ERRF, 424(sp) // > Parameter save area.
141|.define SAVE_NRES, 420(sp) // |
142|.define SAVE_L, 416(sp) // |
143|.define SAVE_PC, 412(sp) // |
144|.define SAVE_MULTRES, 408(sp) // |
145|.define SAVE_CFRAME, 400(sp) // / 64 bit C frame chain.
146|// 392(sp) // Reserved.
147|.define CFRAME_SPACE, 384 // Delta for sp.
148|// Back chain for sp: 384(sp) <-- sp entering interpreter
149|.define SAVE_LR, 376(sp) // 32 bit LR stored in hi-part.
150|.define SAVE_GPR_, 232 // .. 232+18*8: 64 bit GPR saves.
151|.define SAVE_FPR_, 88 // .. 88+18*8: 64 bit FPR saves.
152|// 80(sp) // Needed for 16 byte stack frame alignment.
153|// 16(sp) // Callee parameter save area (ABI mandated).
154|// 8(sp) // Reserved
155|// Back chain for sp: 0(sp) <-- sp while in interpreter
156|// 32 bit sp stored in hi-part of 0(sp).
157|
158|.define TMPD_BLO, 447(sp)
159|.define TMPD, TMPD_HI
160|.define TONUM_D, TONUM_HI
161|
162|.else
131| 163|
132|// 508(sp) // \ 32 bit C frame info. 164|// 508(sp) // \ 32 bit C frame info.
133|.define SAVE_ERRF, 472(sp) // | 165|.define SAVE_ERRF, 472(sp) // |
@@ -155,6 +187,7 @@
155|.define TMPD, TMPD_HI 187|.define TMPD, TMPD_HI
156|.define TONUM_D, TONUM_HI 188|.define TONUM_D, TONUM_HI
157| 189|
190|.endif
158|.else 191|.else
159| 192|
160|.define SAVE_LR, 276(sp) 193|.define SAVE_LR, 276(sp)
@@ -201,7 +234,7 @@
201|.endmacro 234|.endmacro
202| 235|
203|.macro saveregs 236|.macro saveregs
204|.if GPR64 237|.if GPR64 and not FRAME32
205| stdu sp, -CFRAME_SPACE(sp) 238| stdu sp, -CFRAME_SPACE(sp)
206|.else 239|.else
207| stwu sp, -CFRAME_SPACE(sp) 240| stwu sp, -CFRAME_SPACE(sp)
@@ -209,7 +242,7 @@
209| save_ 14; save_ 15; save_ 16 242| save_ 14; save_ 15; save_ 16
210| mflr r0 243| mflr r0
211| save_ 17; save_ 18; save_ 19; save_ 20; save_ 21; save_ 22 244| save_ 17; save_ 18; save_ 19; save_ 20; save_ 21; save_ 22
212|.if GPR64 245|.if GPR64 and not FRAME32
213| std r0, SAVE_LR 246| std r0, SAVE_LR
214|.else 247|.else
215| stw r0, SAVE_LR 248| stw r0, SAVE_LR
@@ -226,10 +259,15 @@
226|.endmacro 259|.endmacro
227| 260|
228|.macro restoreregs 261|.macro restoreregs
262|.if GPR64 and not FRAME32
263| ld r0, SAVE_LR
264|.else
265| lwz r0, SAVE_LR
266|.endif
229|.if GPR64 267|.if GPR64
230| ld r0, SAVE_LR; ld r12, SAVE_CR 268| ld r12, SAVE_CR
231|.else 269|.else
232| lwz r0, SAVE_LR; lwz r12, SAVE_CR 270| lwz r12, SAVE_CR
233|.endif 271|.endif
234| rest_ 14; rest_ 15; rest_ 16; rest_ 17; rest_ 18; rest_ 19 272| rest_ 14; rest_ 15; rest_ 16; rest_ 17; rest_ 18; rest_ 19
235| mtlr r0; 273| mtlr r0;
diff --git a/src/xedkbuild.bat b/src/xedkbuild.bat
new file mode 100644
index 00000000..0d84d92c
--- /dev/null
+++ b/src/xedkbuild.bat
@@ -0,0 +1,91 @@
1@rem Script to build LuaJIT with the XBox 360 SDK.
2@rem Donated to the public domain.
3@rem
4@rem Open a "Visual Studio .NET Command Prompt" (32 bit host compiler)
5@rem Then cd to this directory and run this script.
6
7@if not defined INCLUDE goto :FAIL
8@if not defined XEDK goto :FAIL
9
10@setlocal
11@rem ---- Host compiler ----
12@set LJCOMPILE=cl /nologo /c /MD /O2 /W3 /D_CRT_SECURE_NO_DEPRECATE
13@set LJLINK=link /nologo
14@set LJMT=mt /nologo
15@set DASMDIR=..\dynasm
16@set DASM=%DASMDIR%\dynasm.lua
17@set ALL_LIB=lib_base.c lib_math.c lib_bit.c lib_string.c lib_table.c lib_io.c lib_os.c lib_package.c lib_debug.c lib_jit.c lib_ffi.c
18
19%LJCOMPILE% host\minilua.c
20@if errorlevel 1 goto :BAD
21%LJLINK% /out:minilua.exe minilua.obj
22@if errorlevel 1 goto :BAD
23if exist minilua.exe.manifest^
24 %LJMT% -manifest minilua.exe.manifest -outputresource:minilua.exe
25
26@rem Error out for 64 bit host compiler
27@minilua
28@if errorlevel 8 goto :FAIL
29
30@set DASMFLAGS=-D GPR64 -D FRAME32 -D PPE -D SQRT -D DUALNUM
31minilua %DASM% -LN %DASMFLAGS% -o host\buildvm_arch.h vm_ppc.dasc
32@if errorlevel 1 goto :BAD
33
34%LJCOMPILE% /I "." /I %DASMDIR% /D_XBOX_VER=200 /DLUAJIT_TARGET=LUAJIT_ARCH_PPC host\buildvm*.c
35@if errorlevel 1 goto :BAD
36%LJLINK% /out:buildvm.exe buildvm*.obj
37@if errorlevel 1 goto :BAD
38if exist buildvm.exe.manifest^
39 %LJMT% -manifest buildvm.exe.manifest -outputresource:buildvm.exe
40
41buildvm -m peobj -o lj_vm.obj
42@if errorlevel 1 goto :BAD
43buildvm -m bcdef -o lj_bcdef.h %ALL_LIB%
44@if errorlevel 1 goto :BAD
45buildvm -m ffdef -o lj_ffdef.h %ALL_LIB%
46@if errorlevel 1 goto :BAD
47buildvm -m libdef -o lj_libdef.h %ALL_LIB%
48@if errorlevel 1 goto :BAD
49buildvm -m recdef -o lj_recdef.h %ALL_LIB%
50@if errorlevel 1 goto :BAD
51buildvm -m vmdef -o jit\vmdef.lua %ALL_LIB%
52@if errorlevel 1 goto :BAD
53buildvm -m folddef -o lj_folddef.h lj_opt_fold.c
54@if errorlevel 1 goto :BAD
55
56@rem ---- Cross compiler ----
57@set LJCOMPILE="%XEDK%\bin\win32\cl" /nologo /c /MT /O2 /W3 /GF /Gm- /GR- /GS- /Gy /openmp- /D_CRT_SECURE_NO_DEPRECATE /DNDEBUG /D_XBOX /D_LIB /DLUAJIT_USE_SYSMALLOC
58@set LJLIB="%XEDK%\bin\win32\lib" /nologo
59
60@if "%1" neq "debug" goto :NODEBUG
61@shift
62@set LJCOMPILE="%LJCOMPILE%" /Zi
63:NODEBUG
64@if "%1"=="amalg" goto :AMALG
65%LJCOMPILE% /DLUA_BUILD_AS_DLL lj_*.c lib_*.c
66@if errorlevel 1 goto :BAD
67%LJLIB% /OUT:luajit20.lib lj_*.obj lib_*.obj
68@if errorlevel 1 goto :BAD
69@goto :NOAMALG
70:AMALG
71%LJCOMPILE% /DLUA_BUILD_AS_DLL ljamalg.c
72@if errorlevel 1 goto :BAD
73%LJLIB% /OUT:luajit20.lib ljamalg.obj lj_vm.obj
74@if errorlevel 1 goto :BAD
75:NOAMALG
76
77@del *.obj *.manifest minilua.exe buildvm.exe
78@echo.
79@echo === Successfully built LuaJIT for XBox 360 ===
80
81@goto :END
82:BAD
83@echo.
84@echo *******************************************************
85@echo *** Build FAILED -- Please check the error messages ***
86@echo *******************************************************
87@goto :END
88:FAIL
89@echo To run this script you must open a "Visual Studio .NET Command Prompt"
90@echo (32 bit host compiler). The XBox 360 SDK must be installed, too.
91:END