diff options
Diffstat (limited to 'dynasm/dasm_arm.h')
-rw-r--r-- | dynasm/dasm_arm.h | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/dynasm/dasm_arm.h b/dynasm/dasm_arm.h index b88ea17c..824e8be0 100644 --- a/dynasm/dasm_arm.h +++ b/dynasm/dasm_arm.h | |||
@@ -70,7 +70,7 @@ struct dasm_State { | |||
70 | size_t lgsize; | 70 | size_t lgsize; |
71 | int *pclabels; /* PC label chains/pos ptrs. */ | 71 | int *pclabels; /* PC label chains/pos ptrs. */ |
72 | size_t pcsize; | 72 | size_t pcsize; |
73 | void **globals; /* Array of globals (bias -10). */ | 73 | void **globals; /* Array of globals. */ |
74 | dasm_Section *section; /* Pointer to active section. */ | 74 | dasm_Section *section; /* Pointer to active section. */ |
75 | size_t codesize; /* Total size of all code sections. */ | 75 | size_t codesize; /* Total size of all code sections. */ |
76 | int maxsection; /* 0 <= sectionidx < maxsection. */ | 76 | int maxsection; /* 0 <= sectionidx < maxsection. */ |
@@ -87,7 +87,6 @@ void dasm_init(Dst_DECL, int maxsection) | |||
87 | { | 87 | { |
88 | dasm_State *D; | 88 | dasm_State *D; |
89 | size_t psz = 0; | 89 | size_t psz = 0; |
90 | int i; | ||
91 | Dst_REF = NULL; | 90 | Dst_REF = NULL; |
92 | DASM_M_GROW(Dst, struct dasm_State, Dst_REF, psz, DASM_PSZ(maxsection)); | 91 | DASM_M_GROW(Dst, struct dasm_State, Dst_REF, psz, DASM_PSZ(maxsection)); |
93 | D = Dst_REF; | 92 | D = Dst_REF; |
@@ -98,12 +97,7 @@ void dasm_init(Dst_DECL, int maxsection) | |||
98 | D->pcsize = 0; | 97 | D->pcsize = 0; |
99 | D->globals = NULL; | 98 | D->globals = NULL; |
100 | D->maxsection = maxsection; | 99 | D->maxsection = maxsection; |
101 | for (i = 0; i < maxsection; i++) { | 100 | memset((void *)D->sections, 0, maxsection * sizeof(dasm_Section)); |
102 | D->sections[i].buf = NULL; /* Need this for pass3. */ | ||
103 | D->sections[i].rbuf = D->sections[i].buf - DASM_SEC2POS(i); | ||
104 | D->sections[i].bsize = 0; | ||
105 | D->sections[i].epos = 0; /* Wrong, but is recalculated after resize. */ | ||
106 | } | ||
107 | } | 101 | } |
108 | 102 | ||
109 | /* Free DynASM state. */ | 103 | /* Free DynASM state. */ |
@@ -123,7 +117,7 @@ void dasm_free(Dst_DECL) | |||
123 | void dasm_setupglobal(Dst_DECL, void **gl, unsigned int maxgl) | 117 | void dasm_setupglobal(Dst_DECL, void **gl, unsigned int maxgl) |
124 | { | 118 | { |
125 | dasm_State *D = Dst_REF; | 119 | dasm_State *D = Dst_REF; |
126 | D->globals = gl - 10; /* Negative bias to compensate for locals. */ | 120 | D->globals = gl; |
127 | DASM_M_GROW(Dst, int, D->lglabels, D->lgsize, (10+maxgl)*sizeof(int)); | 121 | DASM_M_GROW(Dst, int, D->lglabels, D->lgsize, (10+maxgl)*sizeof(int)); |
128 | } | 122 | } |
129 | 123 | ||
@@ -148,6 +142,7 @@ void dasm_setup(Dst_DECL, const void *actionlist) | |||
148 | if (D->pclabels) memset((void *)D->pclabels, 0, D->pcsize); | 142 | if (D->pclabels) memset((void *)D->pclabels, 0, D->pcsize); |
149 | for (i = 0; i < D->maxsection; i++) { | 143 | for (i = 0; i < D->maxsection; i++) { |
150 | D->sections[i].pos = DASM_SEC2POS(i); | 144 | D->sections[i].pos = DASM_SEC2POS(i); |
145 | D->sections[i].rbuf = D->sections[i].buf - D->sections[i].pos; | ||
151 | D->sections[i].ofs = 0; | 146 | D->sections[i].ofs = 0; |
152 | } | 147 | } |
153 | } | 148 | } |
@@ -294,7 +289,7 @@ int dasm_link(Dst_DECL, size_t *szp) | |||
294 | 289 | ||
295 | { /* Handle globals not defined in this translation unit. */ | 290 | { /* Handle globals not defined in this translation unit. */ |
296 | int idx; | 291 | int idx; |
297 | for (idx = 20; idx*sizeof(int) < D->lgsize; idx++) { | 292 | for (idx = 10; idx*sizeof(int) < D->lgsize; idx++) { |
298 | int n = D->lglabels[idx]; | 293 | int n = D->lglabels[idx]; |
299 | /* Undefined label: Collapse rel chain and replace with marker (< 0). */ | 294 | /* Undefined label: Collapse rel chain and replace with marker (< 0). */ |
300 | while (n > 0) { int *pb = DASM_POS2PTR(D, n); n = *pb; *pb = -idx; } | 295 | while (n > 0) { int *pb = DASM_POS2PTR(D, n); n = *pb; *pb = -idx; } |
@@ -371,7 +366,10 @@ int dasm_encode(Dst_DECL, void *buffer) | |||
371 | ins &= 255; while ((((char *)cp - base) & ins)) *cp++ = 0xe1a00000; | 366 | ins &= 255; while ((((char *)cp - base) & ins)) *cp++ = 0xe1a00000; |
372 | break; | 367 | break; |
373 | case DASM_REL_LG: | 368 | case DASM_REL_LG: |
374 | CK(n >= 0, UNDEF_LG); | 369 | if (n < 0) { |
370 | n = (int)((ptrdiff_t)D->globals[-n-10] - (ptrdiff_t)cp - 4); | ||
371 | goto patchrel; | ||
372 | } | ||
375 | /* fallthrough */ | 373 | /* fallthrough */ |
376 | case DASM_REL_PC: | 374 | case DASM_REL_PC: |
377 | CK(n >= 0, UNDEF_PC); | 375 | CK(n >= 0, UNDEF_PC); |
@@ -393,7 +391,7 @@ int dasm_encode(Dst_DECL, void *buffer) | |||
393 | } | 391 | } |
394 | break; | 392 | break; |
395 | case DASM_LABEL_LG: | 393 | case DASM_LABEL_LG: |
396 | ins &= 2047; if (ins >= 20) D->globals[ins-10] = (void *)(base + n); | 394 | ins &= 2047; if (ins >= 20) D->globals[ins-20] = (void *)(base + n); |
397 | break; | 395 | break; |
398 | case DASM_LABEL_PC: break; | 396 | case DASM_LABEL_PC: break; |
399 | case DASM_IMM: | 397 | case DASM_IMM: |