Mercurial > hg-old > index.cgi
comparison src/insn_rel.c @ 101:f59c0916753d
Fixed relative branches and PCR addressing to handle constant intra-section references properly
author | lost |
---|---|
date | Fri, 23 Jan 2009 03:36:27 +0000 |
parents | 81fc353d4d69 |
children |
comparison
equal
deleted
inserted
replaced
100:579ac3697918 | 101:f59c0916753d |
---|---|
36 lwasm_expr_term_t *t; | 36 lwasm_expr_term_t *t; |
37 int r; | 37 int r; |
38 | 38 |
39 lwasm_emitop(as, l, instab[opnum].ops[0]); | 39 lwasm_emitop(as, l, instab[opnum].ops[0]); |
40 | 40 |
41 if ((r = lwasm_expr_result2(as, l, p, 0, &v, 0)) < 0) | 41 if ((r = lwasm_expr_result2(as, l, p, EXPR_SECTCONST, &v, 0)) < 0) |
42 v = 0; | 42 v = 0; |
43 else | 43 else |
44 { | 44 { |
45 if (as -> passnum == 1) | 45 if (as -> passnum == 1) |
46 { | 46 { |
79 int r; | 79 int r; |
80 lwasm_expr_term_t *t; | 80 lwasm_expr_term_t *t; |
81 | 81 |
82 lwasm_emitop(as, l, instab[opnum].ops[0]); | 82 lwasm_emitop(as, l, instab[opnum].ops[0]); |
83 | 83 |
84 r = lwasm_expr_result2(as, l, p, 0, &v, 0); | 84 r = lwasm_expr_result2(as, l, p, EXPR_SECTCONST, &v, 0); |
85 if (r < 0) | 85 if (r < 0) |
86 v = 0; | 86 v = 0; |
87 else | 87 else |
88 { | 88 { |
89 if (as -> passnum == 1) | 89 if (as -> passnum == 1) |
103 l -> exprvals[0] -= as -> addr + 2; | 103 l -> exprvals[0] -= as -> addr + 2; |
104 } | 104 } |
105 } | 105 } |
106 } | 106 } |
107 if (as -> passnum == 2 && r == 1) | 107 if (as -> passnum == 2 && r == 1) |
108 { | |
109 // since we have a reference outside this section, add | |
110 // a subtract of the section base to get the right value | |
111 // upon linking | |
112 t = lwasm_expr_term_create_secbase(); | |
113 lwasm_expr_stack_push(l -> exprs[0], t); | |
114 lwasm_expr_term_free(t); | |
115 t = lwasm_expr_term_create_oper(LWASM_OPER_MINUS); | |
116 lwasm_expr_stack_push(l -> exprs[0], t); | |
117 lwasm_expr_term_free(t); | |
118 | |
108 l -> relocoff = as -> addr - l -> codeaddr; | 119 l -> relocoff = as -> addr - l -> codeaddr; |
120 } | |
109 lwasm_emit(as, l, (v >> 8) & 0xff); | 121 lwasm_emit(as, l, (v >> 8) & 0xff); |
110 lwasm_emit(as, l, v & 0xff); | 122 lwasm_emit(as, l, v & 0xff); |
111 } | 123 } |