12#define DASM_ARCH "ppc"
15#define DASM_EXTERN(a,b,c,d) 0
29#define DASM_MAXSECPOS 25
32#define DASM_S_OK 0x00000000
33#define DASM_S_NOMEM 0x01000000
34#define DASM_S_PHASE 0x02000000
35#define DASM_S_MATCH_SEC 0x03000000
36#define DASM_S_RANGE_I 0x11000000
37#define DASM_S_RANGE_SEC 0x12000000
38#define DASM_S_RANGE_LG 0x13000000
39#define DASM_S_RANGE_PC 0x14000000
40#define DASM_S_RANGE_REL 0x15000000
41#define DASM_S_UNDEF_LG 0x21000000
42#define DASM_S_UNDEF_PC 0x22000000
45#define DASM_POS2IDX(pos) ((pos)&0x00ffffff)
46#define DASM_POS2BIAS(pos) ((pos)&0xff000000)
47#define DASM_SEC2POS(sec) ((sec)<<24)
48#define DASM_POS2SEC(pos) ((pos)>>24)
49#define DASM_POS2PTR(D, pos) (D->sections[DASM_POS2SEC(pos)].rbuf + (pos))
81#define DASM_PSZ(ms) (sizeof(dasm_State)+(ms-1)*sizeof(dasm_Section))
98 D->maxsection = maxsection;
107 for (i = 0; i <
D->maxsection; i++)
108 if (
D->sections[i].buf)
120 DASM_M_GROW(Dst,
int,
D->lglabels,
D->lgsize, (10+maxgl)*
sizeof(
int));
127 size_t osz =
D->pcsize;
128 DASM_M_GROW(Dst,
int,
D->pclabels,
D->pcsize, maxpc*
sizeof(
int));
129 memset((
void *)(((
unsigned char *)
D->pclabels)+osz), 0,
D->pcsize-osz);
139 D->section = &
D->sections[0];
140 memset((
void *)
D->lglabels, 0,
D->lgsize);
141 if (
D->pclabels)
memset((
void *)
D->pclabels, 0,
D->pcsize);
142 for (i = 0; i <
D->maxsection; i++) {
144 D->sections[i].rbuf =
D->sections[i].buf -
D->sections[i].pos;
145 D->sections[i].ofs = 0;
153 D->status = DASM_S_##st|(p-D->actionlist-1); return; } } while (0)
154#define CKPL(kind, st) \
155 do { if ((size_t)((char *)pl-(char *)D->kind##labels) >= D->kind##size) { \
156 D->status = DASM_S_RANGE_##st|(p-D->actionlist-1); return; } } while (0)
158#define CK(x, st) ((void)0)
159#define CKPL(kind, st) ((void)0)
184 unsigned int ins = *
p++;
185 unsigned int action = (ins >> 16);
189 int *pl,
n = action >=
DASM_REL_PC ? va_arg(ap,
int) : 0;
193 n = (ins & 255);
CK(
n < D->maxsection, RANGE_SEC);
194 D->section = &
D->sections[
n];
goto stop;
199 n = (ins & 2047) - 10; pl =
D->lglabels +
n;
201 if (
n >= 0) {
CK(
n>=10||*pl<0, RANGE_LG);
CKPL(lg,
LG);
goto putrel; }
206 pl =
D->pclabels +
n;
CKPL(pc, PC);
219 pl =
D->lglabels + (ins & 2047) - 10;
CKPL(lg,
LG);
goto putlabel;
221 pl =
D->pclabels +
n;
CKPL(pc, PC);
231 CK((
n & ((1<<((ins>>10)&31))-1)) == 0, RANGE_I);
233 n >>= ((ins>>10)&31);
236 CK(((
n + (1<<(((ins>>5)&31)-1)))>>((ins>>5)&31)) == 0, RANGE_I);
238 CK((
n>>((ins>>5)&31)) == 0, RANGE_I);
243 CK((
n >> 6) == 0, RANGE_I);
268 for (pc = 0; pc*
sizeof(int) <
D->pcsize; pc++)
275 for (idx = 10; idx*
sizeof(int) <
D->lgsize; idx++) {
276 int n =
D->lglabels[idx];
283 for (secnum = 0; secnum <
D->maxsection; secnum++) {
287 int lastpos = sec->
pos;
289 while (
pos != lastpos) {
292 unsigned int ins = *
p++;
293 unsigned int action = (ins >> 16);
298 case DASM_ALIGN: ofs -= (b[
pos++] + ofs) & (ins & 255);
break;
316 do { if (!(x)) return DASM_S_##st|(p-D->actionlist-1); } while (0)
318#define CK(x, st) ((void)0)
325 char *base = (
char *)
buffer;
326 unsigned int *
cp = (
unsigned int *)
buffer;
330 for (secnum = 0; secnum <
D->maxsection; secnum++) {
333 int *endb = sec->
rbuf + sec->
pos;
338 unsigned int ins = *
p++;
339 unsigned int action = (ins >> 16);
348 ins &= 255;
while ((((
char *)
cp - base) & ins)) *
cp++ = 0x60000000;
357 CK(
n >= 0, UNDEF_PC);
361 (((
n+4) + ((ins & 2048) ? 0x00008000 : 0x02000000)) >>
362 ((ins & 2048) ? 16 : 26)) == 0, RANGE_REL);
363 cp[-1] |= ((
n+4) & ((ins & 2048) ? 0x0000fffc: 0x03fffffc));
366 ins &= 2047;
if (ins >= 20)
D->globals[ins-20] = (
void *)(base +
n);
370 cp[-1] |= (
n & ((1<<((ins>>5)&31))-1)) << (ins&31);
373 cp[-1] |= (ins & 1) ? ((
n&31)<<11)|((
n&32)>>4) : ((
n&31)<<6)|(
n&32);
375 default: *
cp++ = ins;
break;
382 if (base +
D->codesize != (
char *)
cp)
392 if (pc*
sizeof(
int) <
D->pcsize) {
393 int pos =
D->pclabels[pc];
395 if (
pos > 0)
return -1;
407 for (i = 1; i <= 9; i++) {
412 if (
D->status ==
DASM_S_OK && secmatch >= 0 &&
413 D->section != &
D->sections[secmatch])
const unsigned int * dasm_ActList
void dasm_put(Dst_DECL, int start,...)
void dasm_growpc(Dst_DECL, unsigned int maxpc)
int dasm_encode(Dst_DECL, void *buffer)
void dasm_init(Dst_DECL, int maxsection)
#define DASM_POS2PTR(D, pos)
#define DASM_POS2BIAS(pos)
#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)
#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
const unsigned char * dasm_ActList
memset(ptr, 0, type->size)
zend_ffi_ctype_name_buf buf
unsigned const char * pos
ZEND_API void(ZEND_FASTCALL *zend_touch_vm_stack_data)(void *vm_stack_data)