rtasm: fix labels after (not so) recent change to allow dynamic fn growth

Using char * for labels doesn't work if you realloc the function
during assembly and free the old storage...
This commit is contained in:
Keith Whitwell 2008-05-01 20:41:03 +01:00
parent b8936ca1c2
commit fb3623b235
4 changed files with 28 additions and 41 deletions

View file

@ -347,9 +347,9 @@ struct x86_reg x86_get_base_reg( struct x86_reg reg )
return x86_make_reg( reg.file, reg.idx );
}
unsigned char *x86_get_label( struct x86_function *p )
int x86_get_label( struct x86_function *p )
{
return p->csr;
return p->csr - p->store;
}
@ -361,17 +361,22 @@ unsigned char *x86_get_label( struct x86_function *p )
void x86_jcc( struct x86_function *p,
enum x86_cc cc,
unsigned char *label )
int label )
{
intptr_t offset = pointer_to_intptr( label ) - (pointer_to_intptr( x86_get_label(p) ) + 2);
int offset = label - (x86_get_label(p) + 2);
DUMP_I(cc);
if (offset < 0) {
int amt = p->csr - p->store;
assert(amt > -offset);
}
if (offset <= 127 && offset >= -128) {
emit_1ub(p, 0x70 + cc);
emit_1b(p, (char) offset);
}
else {
offset = pointer_to_intptr( label ) - (pointer_to_intptr( x86_get_label(p) ) + 6);
offset = label - (x86_get_label(p) + 6);
emit_2ub(p, 0x0f, 0x80 + cc);
emit_1i(p, offset);
}
@ -379,8 +384,8 @@ void x86_jcc( struct x86_function *p,
/* Always use a 32bit offset for forward jumps:
*/
unsigned char *x86_jcc_forward( struct x86_function *p,
enum x86_cc cc )
int x86_jcc_forward( struct x86_function *p,
enum x86_cc cc )
{
DUMP_I(cc);
emit_2ub(p, 0x0f, 0x80 + cc);
@ -388,7 +393,7 @@ unsigned char *x86_jcc_forward( struct x86_function *p,
return x86_get_label(p);
}
unsigned char *x86_jmp_forward( struct x86_function *p)
int x86_jmp_forward( struct x86_function *p)
{
DUMP();
emit_1ub(p, 0xe9);
@ -396,7 +401,7 @@ unsigned char *x86_jmp_forward( struct x86_function *p)
return x86_get_label(p);
}
unsigned char *x86_call_forward( struct x86_function *p)
int x86_call_forward( struct x86_function *p)
{
DUMP();
@ -408,42 +413,24 @@ unsigned char *x86_call_forward( struct x86_function *p)
/* Fixup offset from forward jump:
*/
void x86_fixup_fwd_jump( struct x86_function *p,
unsigned char *fixup )
int fixup )
{
*(int *)(fixup - 4) = pointer_to_intptr( x86_get_label(p) ) - pointer_to_intptr( fixup );
*(int *)(p->store + fixup - 4) = x86_get_label(p) - fixup;
}
void x86_jmp( struct x86_function *p, unsigned char *label)
void x86_jmp( struct x86_function *p, int label)
{
DUMP_I( label );
emit_1ub(p, 0xe9);
emit_1i(p, pointer_to_intptr( label ) - pointer_to_intptr( x86_get_label(p) ) - 4);
emit_1i(p, label - x86_get_label(p) - 4);
}
#if 0
static unsigned char *cptr( void (*label)() )
{
return (unsigned char *) label;
}
/* This doesn't work once we start reallocating & copying the
* generated code on buffer fills, because the call is relative to the
* current pc.
*/
void x86_call( struct x86_function *p, void (*label)())
{
DUMP_I( label );
emit_1ub(p, 0xe8);
emit_1i(p, cptr(label) - x86_get_label(p) - 4);
}
#else
void x86_call( struct x86_function *p, struct x86_reg reg)
{
DUMP_R( reg );
emit_1ub(p, 0xff);
emit_modrm_noreg(p, 2, reg);
}
#endif
/* michal:

View file

@ -124,23 +124,23 @@ struct x86_reg x86_get_base_reg( struct x86_reg reg );
/* Labels, jumps and fixup:
*/
unsigned char *x86_get_label( struct x86_function *p );
int x86_get_label( struct x86_function *p );
void x86_jcc( struct x86_function *p,
enum x86_cc cc,
unsigned char *label );
int label );
unsigned char *x86_jcc_forward( struct x86_function *p,
int x86_jcc_forward( struct x86_function *p,
enum x86_cc cc );
unsigned char *x86_jmp_forward( struct x86_function *p);
int x86_jmp_forward( struct x86_function *p);
unsigned char *x86_call_forward( struct x86_function *p);
int x86_call_forward( struct x86_function *p);
void x86_fixup_fwd_jump( struct x86_function *p,
unsigned char *fixup );
int fixup );
void x86_jmp( struct x86_function *p, unsigned char *label );
void x86_jmp( struct x86_function *p, int label );
/* void x86_call( struct x86_function *p, void (*label)() ); */
void x86_call( struct x86_function *p, struct x86_reg reg);

View file

@ -2021,7 +2021,7 @@ static void aos_to_soa( struct x86_function *func, uint aos, uint soa, uint num,
struct x86_reg aos_input;
struct x86_reg num_inputs;
struct x86_reg temp;
unsigned char *inner_loop;
int inner_loop;
soa_input = x86_make_reg( file_REG32, reg_AX );
aos_input = get_temp_base(); /* BX or SI */
@ -2083,7 +2083,7 @@ static void soa_to_aos( struct x86_function *func, uint aos, uint soa, uint num,
struct x86_reg aos_output;
struct x86_reg num_outputs;
struct x86_reg temp;
unsigned char *inner_loop;
int inner_loop;
soa_output = x86_make_reg( file_REG32, reg_AX );
aos_output = get_temp_base(); /* BX or SI */

View file

@ -404,7 +404,7 @@ static boolean build_vertex_emit( struct translate_sse *p,
struct x86_reg srcEAX = x86_make_reg(file_REG32, reg_CX);
struct x86_reg countEBP = x86_make_reg(file_REG32, reg_BP);
struct x86_reg translateESI = x86_make_reg(file_REG32, reg_SI);
uint8_t *fixup, *label;
int fixup, label;
unsigned j;
p->func = func;