mirror of
https://github.com/LuaJIT/LuaJIT.git
synced 2025-02-08 15:34:09 +00:00
Fix C code in header file and handle br template.
This means that code like this can now be generated on s390x: | ar r2, r3 | br r14 Still need to add support for immediates, memory, labels, other instructions and so on.
This commit is contained in:
parent
000b1a84f0
commit
cf225d27cc
@ -186,10 +186,10 @@ void dasm_put(Dst_DECL, int start, ...)
|
|||||||
|
|
||||||
va_start(ap, start);
|
va_start(ap, start);
|
||||||
while (1) {
|
while (1) {
|
||||||
unsigned int ins = *p++;
|
unsigned short ins = *p++;
|
||||||
unsigned int action = (ins >> 16);
|
unsigned short action = ins;
|
||||||
if (action >= DASM__MAX) {
|
if (action >= DASM__MAX) {
|
||||||
ofs += 4;
|
ofs += 2;
|
||||||
} else {
|
} else {
|
||||||
int *pl, n = action >= DASM_REL_PC ? va_arg(ap, int) : 0;
|
int *pl, n = action >= DASM_REL_PC ? va_arg(ap, int) : 0;
|
||||||
switch (action) {
|
switch (action) {
|
||||||
@ -231,22 +231,11 @@ void dasm_put(Dst_DECL, int start, ...)
|
|||||||
*pl = -pos; /* Label exists now. */
|
*pl = -pos; /* Label exists now. */
|
||||||
b[pos++] = ofs; /* Store pass1 offset estimate. */
|
b[pos++] = ofs; /* Store pass1 offset estimate. */
|
||||||
break;
|
break;
|
||||||
case DASM_IMM:
|
case DASM_IMM16:
|
||||||
#ifdef DASM_CHECKS
|
case DASM_IMM32:
|
||||||
CK((n & ((1<<((ins>>10)&31))-1)) == 0, RANGE_I);
|
case DASM_DISP20:
|
||||||
#endif
|
case DASM_DISP12:
|
||||||
n >>= ((ins>>10)&31);
|
fprintf(stderr, "not implemented\n");
|
||||||
#ifdef DASM_CHECKS
|
|
||||||
if (ins & 0x8000)
|
|
||||||
CK(((n + (1<<(((ins>>5)&31)-1)))>>((ins>>5)&31)) == 0, RANGE_I);
|
|
||||||
else
|
|
||||||
CK((n>>((ins>>5)&31)) == 0, RANGE_I);
|
|
||||||
#endif
|
|
||||||
b[pos++] = n;
|
|
||||||
break;
|
|
||||||
case DASM_IMMSH:
|
|
||||||
CK((n >> 6) == 0, RANGE_I);
|
|
||||||
b[pos++] = n;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -294,8 +283,8 @@ int dasm_link(Dst_DECL, size_t *szp)
|
|||||||
while (pos != lastpos) {
|
while (pos != lastpos) {
|
||||||
dasm_ActList p = D->actionlist + b[pos++];
|
dasm_ActList p = D->actionlist + b[pos++];
|
||||||
while (1) {
|
while (1) {
|
||||||
unsigned int ins = *p++;
|
unsigned short ins = *p++;
|
||||||
unsigned int action = (ins >> 16);
|
unsigned short action = ins;
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case DASM_STOP: case DASM_SECTION: goto stop;
|
case DASM_STOP: case DASM_SECTION: goto stop;
|
||||||
case DASM_ESC: p++; break;
|
case DASM_ESC: p++; break;
|
||||||
@ -303,7 +292,12 @@ int dasm_link(Dst_DECL, size_t *szp)
|
|||||||
case DASM_ALIGN: ofs -= (b[pos++] + ofs) & (ins & 255); break;
|
case DASM_ALIGN: ofs -= (b[pos++] + ofs) & (ins & 255); break;
|
||||||
case DASM_REL_LG: case DASM_REL_PC: pos++; break;
|
case DASM_REL_LG: case DASM_REL_PC: pos++; break;
|
||||||
case DASM_LABEL_LG: case DASM_LABEL_PC: b[pos++] += ofs; break;
|
case DASM_LABEL_LG: case DASM_LABEL_PC: b[pos++] += ofs; break;
|
||||||
case DASM_IMM: case DASM_IMMSH: pos++; break;
|
case DASM_IMM16:
|
||||||
|
case DASM_IMM32:
|
||||||
|
case DASM_DISP20:
|
||||||
|
case DASM_DISP12:
|
||||||
|
fprintf(stderr, "not implemented\n");
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
stop: (void)0;
|
stop: (void)0;
|
||||||
@ -328,7 +322,7 @@ int dasm_encode(Dst_DECL, void *buffer)
|
|||||||
{
|
{
|
||||||
dasm_State *D = Dst_REF;
|
dasm_State *D = Dst_REF;
|
||||||
char *base = (char *)buffer;
|
char *base = (char *)buffer;
|
||||||
unsigned int *cp = (unsigned int *)buffer;
|
unsigned short *cp = (unsigned short *)buffer;
|
||||||
int secnum;
|
int secnum;
|
||||||
|
|
||||||
/* Encode all code sections. No support for data sections (yet). */
|
/* Encode all code sections. No support for data sections (yet). */
|
||||||
@ -340,8 +334,8 @@ int dasm_encode(Dst_DECL, void *buffer)
|
|||||||
while (b != endb) {
|
while (b != endb) {
|
||||||
dasm_ActList p = D->actionlist + *b++;
|
dasm_ActList p = D->actionlist + *b++;
|
||||||
while (1) {
|
while (1) {
|
||||||
unsigned int ins = *p++;
|
unsigned short ins = *p++;
|
||||||
unsigned int action = (ins >> 16);
|
unsigned short action = ins;
|
||||||
int n = (action >= DASM_ALIGN && action < DASM__MAX) ? *b++ : 0;
|
int n = (action >= DASM_ALIGN && action < DASM__MAX) ? *b++ : 0;
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case DASM_STOP: case DASM_SECTION: goto stop;
|
case DASM_STOP: case DASM_SECTION: goto stop;
|
||||||
@ -350,7 +344,7 @@ int dasm_encode(Dst_DECL, void *buffer)
|
|||||||
n = DASM_EXTERN(Dst, (unsigned char *)cp, (ins & 2047), 1) - 4;
|
n = DASM_EXTERN(Dst, (unsigned char *)cp, (ins & 2047), 1) - 4;
|
||||||
goto patchrel;
|
goto patchrel;
|
||||||
case DASM_ALIGN:
|
case DASM_ALIGN:
|
||||||
ins &= 255; while ((((char *)cp - base) & ins)) *cp++ = 0x60000000;
|
ins &= 255; while ((((char *)cp - base) & ins)) *cp++ = 0x0707;
|
||||||
break;
|
break;
|
||||||
case DASM_REL_LG:
|
case DASM_REL_LG:
|
||||||
CK(n >= 0, UNDEF_LG);
|
CK(n >= 0, UNDEF_LG);
|
||||||
@ -367,11 +361,11 @@ int dasm_encode(Dst_DECL, void *buffer)
|
|||||||
ins &= 2047; if (ins >= 20) D->globals[ins-10] = (void *)(base + n);
|
ins &= 2047; if (ins >= 20) D->globals[ins-10] = (void *)(base + n);
|
||||||
break;
|
break;
|
||||||
case DASM_LABEL_PC: break;
|
case DASM_LABEL_PC: break;
|
||||||
case DASM_IMM:
|
case DASM_IMM16:
|
||||||
cp[-1] |= (n & ((1<<((ins>>5)&31))-1)) << (ins&31);
|
case DASM_IMM32:
|
||||||
break;
|
case DASM_DISP20:
|
||||||
case DASM_IMMSH:
|
case DASM_DISP12:
|
||||||
cp[-1] |= (ins & 1) ? ((n&31)<<11)|((n&32)>>4) : ((n&31)<<6)|(n&32);
|
fprintf(stderr, "not implemented\n");
|
||||||
break;
|
break;
|
||||||
default: *cp++ = ins; break;
|
default: *cp++ = ins; break;
|
||||||
}
|
}
|
||||||
|
@ -933,13 +933,13 @@ for cond,c in pairs(map_cond) do
|
|||||||
-- Extended mnemonics for branches.
|
-- Extended mnemonics for branches.
|
||||||
-- TODO: replace 'B' with correct encoding.
|
-- TODO: replace 'B' with correct encoding.
|
||||||
-- brc
|
-- brc
|
||||||
map_op["j"..cond.."_1"] = "00000000"..tohex(0xa7040000+shl(c, 20)).."B"
|
map_op["j"..cond.."_1"] = "00000000"..tohex(0xa7040000+shl(c, 20)).."w"
|
||||||
-- brcl
|
-- brcl
|
||||||
map_op["jg"..cond.."_1"] = tohex(0xc004+shl(c, 4)).."00000000".."B"
|
map_op["jg"..cond.."_1"] = tohex(0xc004+shl(c, 4)).."00000000".."x"
|
||||||
-- bc
|
-- bc
|
||||||
map_op["b"..cond.."_1"] = "00000000"..tohex(0x47000000+shl(c, 20)).."B"
|
map_op["b"..cond.."_1"] = "00000000"..tohex(0x47000000+shl(c, 20)).."y"
|
||||||
-- bcr
|
-- bcr
|
||||||
map_op["b"..cond.."r_1"] = "00000000"..tohex(0x0700+shl(c, 4)).."B"
|
map_op["b"..cond.."r_1"] = "00000000"..tohex(0x0700+shl(c, 4)).."z"
|
||||||
end
|
end
|
||||||
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
||||||
-- Handle opcodes defined with template strings.
|
-- Handle opcodes defined with template strings.
|
||||||
@ -969,7 +969,7 @@ local function parse_template(params, template, nparams, pos)
|
|||||||
local pr1,pr2,pr3
|
local pr1,pr2,pr3
|
||||||
if p == "g" then
|
if p == "g" then
|
||||||
pr1,pr2=params[n],params[n+1]
|
pr1,pr2=params[n],params[n+1]
|
||||||
op2 = op2 + shl(parse_reg(pr1),4) + parse_reg(pr2)
|
op2 = op2 + shl(parse_gpr(pr1),4) + parse_gpr(pr2)
|
||||||
wputhw(op2)
|
wputhw(op2)
|
||||||
elseif p == "h" then
|
elseif p == "h" then
|
||||||
pr1,pr2=params[n],params[n+1]
|
pr1,pr2=params[n],params[n+1]
|
||||||
@ -988,6 +988,9 @@ local function parse_template(params, template, nparams, pos)
|
|||||||
|
|
||||||
elseif p == "n" then
|
elseif p == "n" then
|
||||||
|
|
||||||
|
elseif p == "z" then
|
||||||
|
op2 = op2 + parse_gpr(params[1])
|
||||||
|
wputhw(op2)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user