obj-coff-bfd:

bfd support gets deeper into gas
*h8*
	fixed numerous bugs in instruction encoding
This commit is contained in:
Steve Chamberlain
1991-11-26 02:16:59 +00:00
parent 23de7ff6f5
commit 05b4b0e70c
4 changed files with 384 additions and 241 deletions

View File

@ -51,7 +51,6 @@ mh-cygnus
mh-i386 mh-i386
mt-ebmon29k mt-ebmon29k
mt-h8300 mt-h8300
mt-h8300hds
mt-m68k mt-m68k
mt-mips mt-mips
obj-aout.c obj-aout.c
@ -124,7 +123,13 @@ echo Done in `pwd`.
# #
# #
# $Log$ # $Log$
# Revision 1.9 1991/11/11 23:36:39 sac # Revision 1.10 1991/11/26 02:16:55 sac
# obj-coff-bfd:
# bfd support gets deeper into gas
# *h8*
# fixed numerous bugs in instruction encoding
#
# Revision 1.9 1991/11/11 23:36:39 sac
# Added tc-sparc.c # Added tc-sparc.c
# #
# Revision 1.8 1991/11/06 11:53:16 sac # Revision 1.8 1991/11/06 11:53:16 sac

View File

@ -1,4 +1,5 @@
TARG_CPU_DEPENDENTS=$(srcdir)/../include/h8300-opcode.h TARG_CPU_DEPENDENTS=$(srcdir)/../include/h8300-opcode.h
LOCAL_LOADLIBES=$(srcdir)/../bfd/$(srcdir)/libbfd.a LOCAL_LOADLIBES=$(srcdir)/../bfd/$(srcdir)/libbfd.a
TDEFINES=-DBFD -DMANY_SEGMENTS TDEFINES=-DBFD_HEADERS -DMANY_SEGMENTS -DBFD
CC=gcc

View File

@ -20,6 +20,7 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
/* /*
Written By Steve Chamberlain Written By Steve Chamberlain
steve@cygnus.com steve@cygnus.com
*/ */
@ -70,7 +71,7 @@ reloc_howto_type *r8pcrel;
void md_begin () void md_begin ()
{ {
bfd_arch_info_struct_type *ai; bfd_arch_info_type *ai;
const struct h8_opcode *opcode; const struct h8_opcode *opcode;
opcode_hash_control = hash_new(); opcode_hash_control = hash_new();
@ -96,7 +97,7 @@ struct h8_exp {
}; };
struct h8_op struct h8_op
{ {
op_enum_type mode; op_type mode;
unsigned reg; unsigned reg;
expressionS exp; expressionS exp;
}; };
@ -114,15 +115,15 @@ op_enum_type mode;
*/ */
op_enum_type r8_sord[] = {RS8, RD8}; op_type r8_sord[] = {RS8, RD8};
op_enum_type r16_sord[] = {RS16, RD16}; op_type r16_sord[] = {RS16, RD16};
op_enum_type rind_sord[] = {RSIND, RDIND}; op_type rind_sord[] = {RSIND, RDIND};
op_enum_type abs_sord[2] = {ABS16SRC, ABS16DST}; op_type abs_sord[2] = {ABS16SRC, ABS16DST};
op_enum_type disp_sord[] = {DISPSRC, DISPDST}; op_type disp_sord[] = {DISPSRC, DISPDST};
/* try and parse a reg name, returns number of chars consumed */ /* try and parse a reg name, returns number of chars consumed */
int DEFUN(parse_reg,(src, mode, reg, dst), int DEFUN(parse_reg,(src, mode, reg, dst),
char *src AND char *src AND
op_enum_type *mode AND op_type *mode AND
unsigned int *reg AND unsigned int *reg AND
int dst) int dst)
{ {
@ -199,7 +200,7 @@ DEFUN(get_operand,(ptr, op, dst),
unsigned int dst) unsigned int dst)
{ {
char *src = *ptr; char *src = *ptr;
op_enum_type mode; op_type mode;
unsigned int num; unsigned int num;
unsigned int len; unsigned int len;
op->mode = E; op->mode = E;
@ -309,280 +310,291 @@ DEFUN(md_assemble,(str),
{ {
char *op_start; char *op_start;
char *op_end; char *op_end;
unsigned int i;
struct h8_opcode * opcode; struct h8_opcode * opcode;
/* Drop leading whitespace */ /* Drop leading whitespace */
while (*str == ' ') while (*str == ' ')
str++; str++;
/* find the op code end */ /* find the op code end */
for (op_start = op_end = str; for (op_start = op_end = str;
*op_end != 0 && *op_end != ' '; *op_end != 0 && *op_end != ' ';
op_end ++) op_end ++)
; ;
if (op_end == op_start) { if (op_end == op_start) {
as_bad("can't find opcode "); as_bad("can't find opcode ");
} }
*op_end = 0; *op_end = 0;
opcode = (struct h8_opcode *) hash_find(opcode_hash_control, opcode = (struct h8_opcode *) hash_find(opcode_hash_control,
op_start); op_start);
if (opcode == NULL) { if (opcode == NULL) {
as_bad("unknown opcode"); as_bad("unknown opcode");
return; return;
} }
{ {
int ok = 1; int ok = 1;
int j,i; int j,i;
int dispreg = 0; int dispreg = 0;
struct h8_op operand[2]; struct h8_op operand[2];
char *ptr = op_end+1; char *ptr = op_end+1;
if (opcode->noperands) if (opcode->noperands)
get_operand(& ptr, &operand[0],0); get_operand(& ptr, &operand[0],0);
else operand[0].mode = 0; else operand[0].mode = 0;
if (opcode->noperands==2) { if (opcode->noperands==2) {
if (*ptr == ',') ptr++; if (*ptr == ',') ptr++;
get_operand(& ptr, &operand[1], 1); get_operand(& ptr, &operand[1], 1);
} }
else operand[1].mode = 0; else operand[1].mode = 0;
{ {
struct h8_opcode *this_try ; struct h8_opcode *this_try ;
int found = 0; int found = 0;
for (j = 0; j < opcode->nopcodes && !found; j++) { for (j = 0; j < opcode->nopcodes && !found; j++) {
this_try = opcode + j; this_try = opcode + j;
for (i = 0; i < opcode->noperands; i++) { for (i = 0; i < opcode->noperands; i++) {
op_enum_type op = (this_try->args.nib[i]) & ~(B30|B31); op_type op = (this_try->args.nib[i]) & ~(B30|B31);
switch (op) { switch (op) {
case Hex0: case Hex0:
case Hex1: case Hex1:
case Hex2: case Hex2:
case Hex3: case Hex3:
case Hex4: case Hex4:
case Hex5: case Hex5:
case Hex6: case Hex6:
case Hex7: case Hex7:
case Hex8: case Hex8:
case Hex9: case Hex9:
case HexA: case HexA:
case HexB: case HexB:
case HexC: case HexC:
case HexD: case HexD:
case HexE: case HexE:
case HexF: case HexF:
break; break;
case DISPSRC: case DISPSRC:
case DISPDST: case DISPDST:
dispreg = operand[i].reg; dispreg = operand[i].reg;
case RD8: case RD8:
case RS8: case RS8:
case RDIND: case RDIND:
case RSIND: case RSIND:
case RD16: case RD16:
case RS16: case RS16:
case CCR: case CCR:
case RSINC: case RSINC:
case RDDEC: case RDDEC:
if (operand[i].mode != op) goto fail; if (operand[i].mode != op) goto fail;
break; break;
case KBIT: case IMM8:
case IMM8: /* We have an expression, called IMM16, but we know we
case IMM16: want an 8 bit value here */
case IMM3: if (operand[i].mode != IMM16) goto fail;
if (operand[i].mode != IMM16) goto fail; operand[i].mode = IMM8;
break; break;
case ABS16SRC: case KBIT:
case ABS8SRC: case IMM16:
if (operand[i].mode != ABS16SRC) goto fail; case IMM3:
break; if (operand[i].mode != IMM16) goto fail;
case ABS16DST: break;
case ABS8DST: case ABS16SRC:
if (operand[i].mode != ABS16DST) goto fail; case ABS8SRC:
if (operand[i].mode != ABS16SRC) goto fail;
break;
case ABS16DST:
case ABS8DST:
if (operand[i].mode != ABS16DST) goto fail;
break; break;
}
} }
found =1; }
fail: ; found =1;
} fail: ;
if (found == 0) }
as_bad("illegal operands for opcode"); if (found == 0)
as_bad("illegal operands for opcode");
/* Now we know what sort of opcodes etc, lets build the bytes - /* Now we know what sort of opcodes etc, lets build the bytes -
actually we know how big the instruction will be too. So we actually we know how big the instruction will be too. So we
can get can get
*/ */
{ {
char *output = frag_more(this_try->length); char *output = frag_more(this_try->length);
char *output_ptr = output; char *output_ptr = output;
op_enum_type *nibble_ptr = this_try->data.nib; op_type *nibble_ptr = this_try->data.nib;
char part; char part;
op_enum_type c; op_type c;
char high; char high;
int nib; int nib;
top: ; top: ;
while (*nibble_ptr != E) { while (*nibble_ptr != E) {
int nibble; int nibble;
for (nibble = 0; nibble <2; nibble++) { for (nibble = 0; nibble <2; nibble++) {
c = *nibble_ptr & ~(B30|B31); c = *nibble_ptr & ~(B30|B31);
switch (c) { switch (c) {
default: default:
abort(); abort();
case KBIT:
switch (operand[0].exp.X_add_number) {
case 1:
nib = 0;
break;
case 2:
nib = 8;
break;
default:
as_bad("Need #1 or #2 here");
break;
}
/* stop it making a fix */
operand[0].mode = 0;
break;
case 0:
case 1:
case 2: case 3: case 4: case 5: case 6:
case 7: case 8: case 9: case 10: case 11:
case 12: case 13: case 14: case 15:
nib = c;
break;
case DISPREG:
nib = dispreg;
break;
case IMM8:
nib = 0;
break;
case 0: case DISPDST:
case 1: nib = 0;
case 2: case 3: case 4: case 5: case 6: break;
case 7: case 8: case 9: case 10: case 11: case IMM3:
case 12: case 13: case 14: case 15: if (operand[0].exp.X_add_symbol == 0) {
nib = c; operand[0].mode = 0; /* stop it making a fix */
break; nib = (operand[0].exp.X_add_number);
case DISPREG: }
nib = dispreg; else as_bad("can't have symbol for bit number");
break; break;
case IMM8:
/* if no symbol then put value in place */
if (operand[0].exp.X_add_symbol == 0) {
operand[0].mode = 0; /* stop it making a fix */
*output_ptr++ = (operand[0].exp.X_add_number);
nibble_ptr += 2;
goto top;
}
nib = 0;
break;
case DISPDST: case ABS16DST:
/* if no symbol then put value in place */ nib = 0;
if (operand[1].exp.X_add_symbol == 0) { break;
operand[1].mode = 0; /* stop it making a fix */ case DISPSRC:
*output_ptr++ =(operand[1].exp.X_add_number)>>8; case ABS16SRC:
*output_ptr++ = (operand[1].exp.X_add_number); case IMM16:
nibble_ptr += 4; nib=0;
goto top; break;
}
nib = 0;
break;
case IMM3:
if (operand[0].exp.X_add_symbol == 0) {
operand[0].mode = 0; /* stop it making a fix */
nib = (operand[0].exp.X_add_number);
}
else as_bad("can't have symbol for bit number");
break;
case DISPSRC:
case IMM16:
/* if no symbol then put value in place */
if (operand[0].exp.X_add_symbol == 0) {
operand[0].mode = 0; /* stop it making a fix */
*output_ptr++ =(operand[0].exp.X_add_number)>>8;
*output_ptr++ = (operand[0].exp.X_add_number);
nibble_ptr += 4;
goto top;
}
case ABS16SRC: case ABS8DST:
case ABS16DST: case ABS8SRC:
case IGNORE:
case ABS8DST:
case ABS8SRC:
case IGNORE:
nib = 0; nib = 0;
break; break;
case DISP8: case DISP8:
nib = 0; nib = 0;
break; break;
case RS8: case RS8:
case RS16: case RS16:
case RSIND: case RSIND:
case RSINC: case RSINC:
case RDIND:
nib= operand[0].reg;
break;
case RD8:
case RD16:
case RDDEC:
nib = operand[1].reg;
break; nib= operand[0].reg;
case E: break;
abort(); case RD8:
break; case RD16:
} case RDDEC:
if (*nibble_ptr & B31) nib|=0x8; case RDIND:
if (nibble == 0) { nib = operand[1].reg;
*output_ptr = nib << 4;
} break;
else { case E:
*output_ptr |= nib; abort();
output_ptr++; break;
} }
nibble_ptr++; if (*nibble_ptr & B31) nib|=0x8;
if (nibble == 0) {
*output_ptr = nib << 4;
}
else {
*output_ptr |= nib;
output_ptr++;
}
nibble_ptr++;
} }
} }
/* output any fixes */ /* output any fixes */
{ for (i = 0; i < 2; i++)
int i; {
for (i = 0; i < 2; i++) {
switch (operand[i].mode) { switch (operand[i].mode) {
case 0: case 0:
break; break;
case DISP8: case DISP8:
fix_new(frag_now, fix_new(frag_now,
output+1, output - frag_now->fr_literal + 1,
1, 1,
operand[i].exp.X_add_symbol, operand[i].exp.X_add_symbol,
operand[i].exp.X_subtract_symbol, operand[i].exp.X_subtract_symbol,
operand[i].exp.X_add_number, operand[i].exp.X_add_number -1,
0, 1,
(int)r8pcrel); (int)r8pcrel);
break; break;
case IMM8:
fix_new(frag_now,
output - frag_now->fr_literal + 1,
1,
operand[i].exp.X_add_symbol,
operand[i].exp.X_subtract_symbol,
operand[i].exp.X_add_number,
0,
0);
break;
case ABS16SRC: case ABS16SRC:
case ABS16DST: case ABS16DST:
case IMM16: case IMM16:
case DISPSRC: case DISPSRC:
case DISPDST: case DISPDST:
fix_new(frag_now, fix_new(frag_now,
output+2, output - frag_now->fr_literal + 2,
2, 2,
operand[i].exp.X_add_symbol, operand[i].exp.X_add_symbol,
operand[i].exp.X_subtract_symbol, operand[i].exp.X_subtract_symbol,
operand[i].exp.X_add_number, operand[i].exp.X_add_number,
0, 0,
(int)r16); (int)r16);
break; break;
case RS8: case RS8:
case RD8: case RD8:
case RS16: case RS16:
case RD16: case RD16:
case RDDEC: case RDDEC:
case KBIT:
case RSINC: case RSINC:
case RDIND: case RDIND:
case RSIND: case RSIND:
break; break;
default: default:
abort(); abort();
} }
}
}
} }
}
}
}
}
}
} }
void void
@ -610,17 +622,105 @@ DEFUN_VOID(md_end)
} }
/* Various routines to kill one day */ /* Various routines to kill one day */
/* Equal to MAX_PRECISION in atof-ieee.c */
#define MAX_LITTLENUMS 6
char *md_atof () { printf("call to md_atof \n"); abort(); } /* Turn a string in input_line_pointer into a floating point constant of type
int md_parse_option () { printf("call to md_parse_option \n"); abort(); } type, and store the appropriate bytes in *litP. The number of LITTLENUMS
emitted is stored in *sizeP . An error message is returned, or NULL on OK.
*/
char *
md_atof(type,litP,sizeP)
char type;
char *litP;
int *sizeP;
{
int prec;
LITTLENUM_TYPE words[MAX_LITTLENUMS];
LITTLENUM_TYPE *wordP;
char *t;
char *atof_ieee();
switch(type) {
case 'f':
case 'F':
case 's':
case 'S':
prec = 2;
break;
case 'd':
case 'D':
case 'r':
case 'R':
prec = 4;
break;
case 'x':
case 'X':
prec = 6;
break;
case 'p':
case 'P':
prec = 6;
break;
default:
*sizeP=0;
return "Bad call to MD_ATOF()";
}
t=atof_ieee(input_line_pointer,type,words);
if(t)
input_line_pointer=t;
*sizeP=prec * sizeof(LITTLENUM_TYPE);
for(wordP=words;prec--;) {
md_number_to_chars(litP,(long)(*wordP++),sizeof(LITTLENUM_TYPE));
litP+=sizeof(LITTLENUM_TYPE);
}
return ""; /* Someone should teach Dean about null pointers */
}
int
md_parse_option(argP, cntP, vecP)
char **argP;
int *cntP;
char ***vecP;
{abort();
}
int md_short_jump_size; int md_short_jump_size;
void tc_aout_fix_to_chars () { printf("call to tc_aout_fix_to_chars \n"); void tc_aout_fix_to_chars () { printf("call to tc_aout_fix_to_chars \n");
abort(); } abort(); }
void md_create_long_jump () { printf("call to md_create_long_jump \n"); void md_create_short_jump(ptr, from_addr, to_addr, frag, to_symbol)
abort(); } char *ptr;
void md_convert_frag () { printf("call to md_convert_frag \n"); abort(); } long from_addr;
long to_addr;
fragS *frag;
symbolS *to_symbol;
{
as_fatal("failed sanity check.");
}
void
md_create_long_jump(ptr,from_addr,to_addr,frag,to_symbol)
char *ptr;
long from_addr, to_addr;
fragS *frag;
symbolS *to_symbol;
{
as_fatal("failed sanity check.");
}
void
md_convert_frag(headers, fragP)
object_headers *headers;
fragS * fragP;
{ printf("call to md_convert_frag \n"); abort(); }
long long
DEFUN(md_section_align,(seg, size), DEFUN(md_section_align,(seg, size),
@ -631,18 +731,48 @@ DEFUN(md_section_align,(seg, size),
} }
void md_apply_fix () { printf("call to md_apply_fix \n"); abort(); } void
md_apply_fix(fixP, val)
fixS *fixP;
long val;
{
char *buf = fixP->fx_where + fixP->fx_frag->fr_literal;
switch(fixP->fx_size) {
case 1:
*buf++=val;
break;
case 2:
*buf++=(val>>8);
*buf++=val;
break;
case 4:
*buf++=(val>>24);
*buf++=(val>>16);
*buf++=(val>>8);
*buf++=val;
break;
default:
abort();
}
}
void DEFUN(md_operand, (expressionP),expressionS *expressionP) void DEFUN(md_operand, (expressionP),expressionS *expressionP)
{ } { }
int md_long_jump_size; int md_long_jump_size;
int md_estimate_size_before_relax () { printf("call tomd_estimate_size_before_relax \n"); abort(); } int
md_estimate_size_before_relax(fragP, segment_type)
register fragS *fragP;
register segT segment_type;
{ printf("call tomd_estimate_size_before_relax \n"); abort(); }
/* Put number into target byte order */ /* Put number into target byte order */
void DEFUN(md_number_to_chars,(ptr, use, nbytes), void DEFUN(md_number_to_chars,(ptr, use, nbytes),
char *ptr AND char *ptr AND
int use AND long use AND
unsigned int nbytes) int nbytes)
{ {
switch (nbytes) { switch (nbytes) {
case 4: *ptr++ = (use >> 24) & 0xff; case 4: *ptr++ = (use >> 24) & 0xff;
@ -654,9 +784,7 @@ void DEFUN(md_number_to_chars,(ptr, use, nbytes),
abort(); abort();
} }
} }
long md_pcrel_from(fixP)
long md_pcrel_from () { printf("call to md_pcrel_from \n"); abort(); } fixS *fixP; { abort(); }
void md_create_short_jump () { printf("call to md_create_short_jump \n");
abort(); }
void tc_coff_symbol_emit_hook() { } void tc_coff_symbol_emit_hook() { }

9
gas/config/tc-h8300.h Normal file
View File

@ -0,0 +1,9 @@
#define TC_H8300
/* This macro translates between an internal fix and an coff reloc type */
#define TC_COFF_FIX2RTYPE(fixP) \
(fixP->fx_pcrel ? (fixP->fx_size == 1 ? R_PCRBYTE : R_PCRWORD ) : \
(fixP->fx_size == 1 ? R_RELBYTE : R_RELWORD ))