aboutsummaryrefslogtreecommitdiff
path: root/dynasm/dasm_x86.h
diff options
context:
space:
mode:
Diffstat (limited to 'dynasm/dasm_x86.h')
-rw-r--r--dynasm/dasm_x86.h24
1 files changed, 20 insertions, 4 deletions
diff --git a/dynasm/dasm_x86.h b/dynasm/dasm_x86.h
index 2e2f2334..d8d4928c 100644
--- a/dynasm/dasm_x86.h
+++ b/dynasm/dasm_x86.h
@@ -239,8 +239,11 @@ void dasm_put(Dst_DECL, int start, ...)
239 } 239 }
240 pos++; 240 pos++;
241 ofs += 4; /* Maximum offset needed. */ 241 ofs += 4; /* Maximum offset needed. */
242 if (action == DASM_REL_LG || action == DASM_REL_PC) 242 if (action == DASM_REL_LG || action == DASM_REL_PC) {
243 b[pos++] = ofs; /* Store pass1 offset estimate. */ 243 b[pos++] = ofs; /* Store pass1 offset estimate. */
244 } else if (sizeof(ptrdiff_t) == 8) {
245 ofs += 4;
246 }
244 break; 247 break;
245 case DASM_LABEL_LG: pl = D->lglabels + *p++; CKPL(lg, LG); goto putlabel; 248 case DASM_LABEL_LG: pl = D->lglabels + *p++; CKPL(lg, LG); goto putlabel;
246 case DASM_LABEL_PC: pl = D->pclabels + va_arg(ap, int); CKPL(pc, PC); 249 case DASM_LABEL_PC: pl = D->pclabels + va_arg(ap, int); CKPL(pc, PC);
@@ -365,10 +368,22 @@ int dasm_link(Dst_DECL, size_t *szp)
365 do { *((unsigned short *)cp) = (unsigned short)(x); cp+=2; } while (0) 368 do { *((unsigned short *)cp) = (unsigned short)(x); cp+=2; } while (0)
366#define dasmd(x) \ 369#define dasmd(x) \
367 do { *((unsigned int *)cp) = (unsigned int)(x); cp+=4; } while (0) 370 do { *((unsigned int *)cp) = (unsigned int)(x); cp+=4; } while (0)
371#define dasmq(x) \
372 do { *((unsigned long long *)cp) = (unsigned long long)(x); cp+=8; } while (0)
368#else 373#else
369#define dasmw(x) do { dasmb(x); dasmb((x)>>8); } while (0) 374#define dasmw(x) do { dasmb(x); dasmb((x)>>8); } while (0)
370#define dasmd(x) do { dasmw(x); dasmw((x)>>16); } while (0) 375#define dasmd(x) do { dasmw(x); dasmw((x)>>16); } while (0)
376#define dasmq(x) do { dasmd(x); dasmd((x)>>32); } while (0)
371#endif 377#endif
378static unsigned char *dasma_(unsigned char *cp, ptrdiff_t x)
379{
380 if (sizeof(ptrdiff_t) == 8)
381 dasmq((unsigned long long)x);
382 else
383 dasmd((unsigned int)x);
384 return cp;
385}
386#define dasma(x) (cp = dasma_(cp, (x)))
372 387
373/* Pass 3: Encode sections. */ 388/* Pass 3: Encode sections. */
374int dasm_encode(Dst_DECL, void *buffer) 389int dasm_encode(Dst_DECL, void *buffer)
@@ -443,12 +458,13 @@ int dasm_encode(Dst_DECL, void *buffer)
443 goto wb; 458 goto wb;
444 } 459 }
445 case DASM_IMM_LG: 460 case DASM_IMM_LG:
446 p++; if (n < 0) { n = (int)(ptrdiff_t)D->globals[-n]; goto wd; } 461 p++;
462 if (n < 0) { dasma((ptrdiff_t)D->globals[-n]); break; }
447 /* fallthrough */ 463 /* fallthrough */
448 case DASM_IMM_PC: { 464 case DASM_IMM_PC: {
449 int *pb = DASM_POS2PTR(D, n); 465 int *pb = DASM_POS2PTR(D, n);
450 n = *pb < 0 ? pb[1] : (*pb + (int)(ptrdiff_t)base); 466 dasma(*pb < 0 ? (ptrdiff_t)pb[1] : (*pb + (ptrdiff_t)base));
451 goto wd; 467 break;
452 } 468 }
453 case DASM_LABEL_LG: { 469 case DASM_LABEL_LG: {
454 int idx = *p++; 470 int idx = *p++;