aboutsummaryrefslogtreecommitdiff
path: root/dynasm/dasm_x86.h
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--dynasm/dasm_x86.h18
1 files changed, 6 insertions, 12 deletions
diff --git a/dynasm/dasm_x86.h b/dynasm/dasm_x86.h
index f0327302..66a68ea5 100644
--- a/dynasm/dasm_x86.h
+++ b/dynasm/dasm_x86.h
@@ -68,7 +68,7 @@ struct dasm_State {
68 size_t lgsize; 68 size_t lgsize;
69 int *pclabels; /* PC label chains/pos ptrs. */ 69 int *pclabels; /* PC label chains/pos ptrs. */
70 size_t pcsize; 70 size_t pcsize;
71 void **globals; /* Array of globals (bias -10). */ 71 void **globals; /* Array of globals. */
72 dasm_Section *section; /* Pointer to active section. */ 72 dasm_Section *section; /* Pointer to active section. */
73 size_t codesize; /* Total size of all code sections. */ 73 size_t codesize; /* Total size of all code sections. */
74 int maxsection; /* 0 <= sectionidx < maxsection. */ 74 int maxsection; /* 0 <= sectionidx < maxsection. */
@@ -85,7 +85,6 @@ void dasm_init(Dst_DECL, int maxsection)
85{ 85{
86 dasm_State *D; 86 dasm_State *D;
87 size_t psz = 0; 87 size_t psz = 0;
88 int i;
89 Dst_REF = NULL; 88 Dst_REF = NULL;
90 DASM_M_GROW(Dst, struct dasm_State, Dst_REF, psz, DASM_PSZ(maxsection)); 89 DASM_M_GROW(Dst, struct dasm_State, Dst_REF, psz, DASM_PSZ(maxsection));
91 D = Dst_REF; 90 D = Dst_REF;
@@ -96,12 +95,7 @@ void dasm_init(Dst_DECL, int maxsection)
96 D->pcsize = 0; 95 D->pcsize = 0;
97 D->globals = NULL; 96 D->globals = NULL;
98 D->maxsection = maxsection; 97 D->maxsection = maxsection;
99 for (i = 0; i < maxsection; i++) { 98 memset((void *)D->sections, 0, maxsection * sizeof(dasm_Section));
100 D->sections[i].buf = NULL; /* Need this for pass3. */
101 D->sections[i].rbuf = D->sections[i].buf - DASM_SEC2POS(i);
102 D->sections[i].bsize = 0;
103 D->sections[i].epos = 0; /* Wrong, but is recalculated after resize. */
104 }
105} 99}
106 100
107/* Free DynASM state. */ 101/* Free DynASM state. */
@@ -121,7 +115,7 @@ void dasm_free(Dst_DECL)
121void dasm_setupglobal(Dst_DECL, void **gl, unsigned int maxgl) 115void dasm_setupglobal(Dst_DECL, void **gl, unsigned int maxgl)
122{ 116{
123 dasm_State *D = Dst_REF; 117 dasm_State *D = Dst_REF;
124 D->globals = gl - 10; /* Negative bias to compensate for locals. */ 118 D->globals = gl;
125 DASM_M_GROW(Dst, int, D->lglabels, D->lgsize, (10+maxgl)*sizeof(int)); 119 DASM_M_GROW(Dst, int, D->lglabels, D->lgsize, (10+maxgl)*sizeof(int));
126} 120}
127 121
@@ -445,7 +439,7 @@ int dasm_encode(Dst_DECL, void *buffer)
445 break; 439 break;
446 } 440 }
447 case DASM_REL_LG: p++; if (n >= 0) goto rel_pc; 441 case DASM_REL_LG: p++; if (n >= 0) goto rel_pc;
448 b++; n = (int)(ptrdiff_t)D->globals[-n]; 442 b++; n = (int)(ptrdiff_t)D->globals[-n-10];
449 /* fallthrough */ 443 /* fallthrough */
450 case DASM_REL_A: rel_a: 444 case DASM_REL_A: rel_a:
451 n -= (unsigned int)(ptrdiff_t)(cp+4); goto wd; /* !x64 */ 445 n -= (unsigned int)(ptrdiff_t)(cp+4); goto wd; /* !x64 */
@@ -459,7 +453,7 @@ int dasm_encode(Dst_DECL, void *buffer)
459 } 453 }
460 case DASM_IMM_LG: 454 case DASM_IMM_LG:
461 p++; 455 p++;
462 if (n < 0) { dasma((ptrdiff_t)D->globals[-n]); break; } 456 if (n < 0) { dasma((ptrdiff_t)D->globals[-n-10]); break; }
463 /* fallthrough */ 457 /* fallthrough */
464 case DASM_IMM_PC: { 458 case DASM_IMM_PC: {
465 int *pb = DASM_POS2PTR(D, n); 459 int *pb = DASM_POS2PTR(D, n);
@@ -469,7 +463,7 @@ int dasm_encode(Dst_DECL, void *buffer)
469 case DASM_LABEL_LG: { 463 case DASM_LABEL_LG: {
470 int idx = *p++; 464 int idx = *p++;
471 if (idx >= 10) 465 if (idx >= 10)
472 D->globals[idx] = (void *)(base + (*p == DASM_SETLABEL ? *b : n)); 466 D->globals[idx-10] = (void *)(base + (*p == DASM_SETLABEL ? *b : n));
473 break; 467 break;
474 } 468 }
475 case DASM_LABEL_PC: case DASM_SETLABEL: break; 469 case DASM_LABEL_PC: case DASM_SETLABEL: break;