12#define DASM_ARCH "x86"
15#define DASM_EXTERN(a,b,c,d) 0
28#define DASM_MAXSECPOS 25
31#define DASM_S_OK 0x00000000
32#define DASM_S_NOMEM 0x01000000
33#define DASM_S_PHASE 0x02000000
34#define DASM_S_MATCH_SEC 0x03000000
35#define DASM_S_RANGE_I 0x11000000
36#define DASM_S_RANGE_SEC 0x12000000
37#define DASM_S_RANGE_LG 0x13000000
38#define DASM_S_RANGE_PC 0x14000000
39#define DASM_S_RANGE_VREG 0x15000000
40#define DASM_S_UNDEF_L 0x21000000
41#define DASM_S_UNDEF_PC 0x22000000
44#define DASM_POS2IDX(pos) ((pos)&0x00ffffff)
45#define DASM_POS2BIAS(pos) ((pos)&0xff000000)
46#define DASM_SEC2POS(sec) ((sec)<<24)
47#define DASM_POS2SEC(pos) ((pos)>>24)
48#define DASM_POS2PTR(D, pos) (D->sections[DASM_POS2SEC(pos)].rbuf + (pos))
80#define DASM_PSZ(ms) (sizeof(dasm_State)+(ms-1)*sizeof(dasm_Section))
83#define DASM_PTR_SUB(p1, off) ((void *) ((uintptr_t) (p1) - sizeof(*p1) * (uintptr_t) (off)))
84#define DASM_PTR_ADD(p1, off) ((void *) ((uintptr_t) (p1) + sizeof(*p1) * (uintptr_t) (off)))
100 D->maxsection = maxsection;
109 for (i = 0; i <
D->maxsection; i++)
110 if (
D->sections[i].buf)
122 DASM_M_GROW(Dst,
int,
D->lglabels,
D->lgsize, (10+maxgl)*
sizeof(
int));
129 size_t osz =
D->pcsize;
130 DASM_M_GROW(Dst,
int,
D->pclabels,
D->pcsize, maxpc*
sizeof(
int));
131 memset((
void *)(((
unsigned char *)
D->pclabels)+osz), 0,
D->pcsize-osz);
141 D->section = &
D->sections[0];
142 memset((
void *)
D->lglabels, 0,
D->lgsize);
143 if (
D->pclabels)
memset((
void *)
D->pclabels, 0,
D->pcsize);
144 for (i = 0; i <
D->maxsection; i++) {
146 D->sections[i].rbuf =
DASM_PTR_SUB(
D->sections[i].buf,
D->sections[i].pos);
147 D->sections[i].ofs = 0;
155 D->status = DASM_S_##st|(int)(p-D->actionlist-1); return; } } while (0)
156#define CKPL(kind, st) \
157 do { if ((size_t)((char *)pl-(char *)D->kind##labels) >= D->kind##size) { \
158 D->status=DASM_S_RANGE_##st|(int)(p-D->actionlist-1); return; } } while (0)
160#define CK(x, st) ((void)0)
161#define CKPL(kind, st) ((void)0)
171 int pos = sec->
pos, ofs = sec->
ofs, mrm = -1;
192 int n = va_arg(ap,
int);
196 if (
n == 0) {
if (mrm < 0) mrm =
p[-2];
if ((mrm&7) != 5)
break; }
198 case DASM_IMM_DB:
if ((((
unsigned)
n+128)&-256) == 0)
goto ob;
201 case DASM_IMM_S:
CK((((
unsigned)
n+128)&-256) == 0, RANGE_I);
goto ob;
202 case DASM_IMM_B:
CK((
n&-256) == 0, RANGE_I); ob: ofs++;
break;
203 case DASM_IMM_WB:
if ((((
unsigned)
n+128)&-256) == 0)
goto ob;
204 case DASM_IMM_W:
CK((
n&-65536) == 0, RANGE_I); ofs += 2;
break;
207 case DASM_VREG:
CK((
n&-16) == 0 && (
n != 4 || (*
p>>5) != 2), RANGE_VREG);
209 if (*
p < 0x20 && (
n&7) == 4) ofs++;
210 switch ((*
p++ >> 3) & 3) {
211 case 3:
n |= b[
pos-3];
212 case 2:
n |= b[
pos-2];
213 case 1:
if (
n <= 7) { b[
pos-1] |= 0x10; ofs--; }
223 n = *
p++; pl =
D->lglabels +
n;
225 if (
n <= 246) {
CK(
n>=10||*pl<0, RANGE_LG);
CKPL(lg,
LG);
goto putrel; }
264 n = *
p;
CK(
n < D->maxsection, RANGE_SEC);
D->section = &
D->sections[
n];
288 for (pc = 0; pc*
sizeof(int) <
D->pcsize; pc++)
295 for (idx = 10; idx*
sizeof(int) <
D->lgsize; idx++) {
296 int n =
D->lglabels[idx];
303 for (secnum = 0; secnum <
D->maxsection; secnum++) {
307 int lastpos = sec->
pos;
309 while (
pos != lastpos) {
322 int shrink = op == 0xe9 ? 3 : ((op&0xf0) == 0x80 ? 4 : 0);
324 int lofs, lpos = b[
pos];
325 if (lpos < 0)
goto noshrink;
330 lofs +=
D->sections[i].ofs;
335 if (lofs >= -128-shrink && lofs <= 127) ofs -= shrink;
336 else { noshrink: shrink = 0; }
368#define dasmb(x) *cp++ = (unsigned char)(x)
369#ifndef DASM_ALIGNED_WRITES
374 do { *((unaligned_short *)cp) = (unsigned short)(x); cp+=2; } while (0)
376 do { *((unaligned_int *)cp) = (unsigned int)(x); cp+=4; } while (0)
378 do { *((unaligned_long_long *)cp) = (unsigned long long)(x); cp+=8; } while (0)
380#define dasmw(x) do { dasmb(x); dasmb((x)>>8); } while (0)
381#define dasmd(x) do { dasmw(x); dasmw((x)>>16); } while (0)
382#define dasmq(x) do { dasmd(x); dasmd((x)>>32); } while (0)
384static unsigned char *dasma_(
unsigned char *
cp,
ptrdiff_t x)
387 dasmq((
unsigned long long)x);
389 dasmd((
unsigned int)x);
392#define dasma(x) (cp = dasma_(cp, (x)))
398 unsigned char *base = (
unsigned char *)
buffer;
399 unsigned char *
cp = base;
403 for (secnum = 0; secnum <
D->maxsection; secnum++) {
410 unsigned char *mark =
NULL;
423 while (((
cp-base) &
n)) *
cp++ = 0x90;
427 case DASM_ESC: action = *
p++; *
cp++ = action;
continue;
434 unsigned char *mm = mark;
436 if (
n == 0) {
int mrm = mm[-1]&7;
if (mrm == 4) mrm = mm[0]&7;
437 if (mrm != 5) { mm[-1] -= 0x80;
break; } }
438 if ((((
unsigned)
n+128) & -256) != 0)
goto wd;
else mm[-1] -= 0x40;
443 db:
if (!mark) mark =
cp; mark[-2] += 2; mark =
NULL;
goto wb;
447 case DASM_IMM_WB:
if ((((
unsigned)
n+128)&-256) == 0)
goto db;
else mark =
NULL;
452 unsigned char *
ex =
cp - (t&7);
453 if ((
n & 8) && t < 0xa0) {
454 if (*
ex & 0x80)
ex[1] ^= 0x20 << (t>>6);
else *
ex ^= 1 << (t>>6);
456 }
else if (
n & 0x10) {
458 *
ex = 0xc5;
ex[1] = (
ex[1] & 0x80) |
ex[2];
ex += 2;
465 if (t >= 0xc0)
n <<= 4;
466 else if (t >= 0x40)
n <<= 3;
467 else if (
n == 4 && t < 0x20) {
cp[-1] ^=
n; *
cp++ = 0x20; }
479 n = *pb - ((int)(
cp-base) + 4-shrink);
480 if (shrink == 0)
goto wd;
481 if (shrink == 4) {
cp--;
cp[-1] = *
cp-0x10; }
else cp[-1] = 0xeb;
500 case DASM_SPACE: {
int fill = *
p++;
while (
n--) *
cp++ = fill;
break; }
507 if (base +
D->codesize !=
cp)
516 if (pc*
sizeof(
int) <
D->pcsize) {
517 int pos =
D->pclabels[pc];
519 if (
pos > 0)
return -1;
531 for (i = 1; i <= 9; i++) {
536 if (
D->status ==
DASM_S_OK && secmatch >= 0 &&
537 D->section != &
D->sections[secmatch])
const unsigned int * dasm_ActList
#define DASM_EXTERN(a, b, c, d)
#define dasm_checkstep(a, b)
#define DASM_M_FREE(ctx, p, sz)
#define DASM_M_GROW(ctx, t, p, sz, need)
struct dasm_Section dasm_Section
#define DASM_POS2SEC(pos)
void dasm_put(Dst_DECL, int start,...)
void dasm_growpc(Dst_DECL, unsigned int maxpc)
int dasm_encode(Dst_DECL, void *buffer)
#define DASM_PTR_ADD(p1, off)
void dasm_init(Dst_DECL, int maxsection)
#define DASM_POS2PTR(D, pos)
#define DASM_POS2BIAS(pos)
#define DASM_PTR_SUB(p1, off)
const unsigned char * dasm_ActList
#define DASM_EXTERN(a, b, c, d)
void dasm_setup(Dst_DECL, const void *actionlist)
int dasm_getpclabel(Dst_DECL, unsigned int pc)
int dasm_link(Dst_DECL, size_t *szp)
#define DASM_SEC2POS(sec)
void dasm_setupglobal(Dst_DECL, void **gl, unsigned int maxgl)
memset(ptr, 0, type->size)
zend_ffi_ctype_name_buf buf
#define IR_SET_ALIGNED(alignment, decl)
unsigned const char * pos
ZEND_API void(ZEND_FASTCALL *zend_touch_vm_stack_data)(void *vm_stack_data)