checkpoint

This commit is contained in:
Steve Chamberlain 1992-12-15 20:41:16 +00:00
parent 16f8723c77
commit 7e8892c382
2 changed files with 473 additions and 368 deletions

View File

@ -17,7 +17,6 @@
along with GAS; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
/*
Written By Steve Chamberlain
sac@cygnus.com
@ -33,18 +32,13 @@
#include <ctype.h>
#include "listing.h"
<<<<<<< tc-z8k.c
char comment_chars[]=
const char comment_chars[] =
{'!', 0};
char line_separator_chars[]=
const char line_separator_chars[] =
{';', 0};
=======
const char comment_chars[] = { '!',0 };
const char line_separator_chars[] = { ';' ,0};
const char line_comment_chars[] = "";
>>>>>>> 1.5
const char line_comment_chars[] = { '#', 0};
extern int machine ;
extern int machine;
extern int coff_flags;
int segmented_mode;
int md_reloc_size;
@ -58,7 +52,6 @@ int md_reloc_size;
void cons ();
void
s_segm ()
{
@ -74,7 +67,44 @@ s_unseg ()
machine = bfd_mach_z8002;
coff_flags = F_Z8002;
}
const pseudo_typeS md_pseudo_table[]=
static
void even()
{
frag_align (1, 0);
record_alignment(now_seg,1);
}
void obj_coff_section();
int tohex(c)
int c;
{
if (isdigit(c)) return c - '0';
if (islower(c)) return c - 'a' + 10;
return c - 'A' + 10;
}
void sval()
{
SKIP_WHITESPACE();
if (*input_line_pointer == '\'') {
int c;
input_line_pointer++;
c = *input_line_pointer++;
while (c != '\'') {
if (c== '%') {
c = (tohex(input_line_pointer[0]) << 4)
| tohex(input_line_pointer[1]);
input_line_pointer+=2;
}
FRAG_APPEND_1_CHAR(c);
c = *input_line_pointer++;
}
demand_empty_rest_of_line();
}
}
const pseudo_typeS md_pseudo_table[] =
{
{"int", cons, 2},
{"data.b", cons, 1},
@ -87,29 +117,34 @@ const pseudo_typeS md_pseudo_table[]=
{"program", s_ignore, 0},
{"z8001", s_segm, 0},
{"z8002", s_unseg, 0},
{"segm", s_segm, 0},
{"unsegm", s_unseg, 0},
{"name", s_app_file, 0},
{"global",s_globl,0},
{"wval",cons,2},
{"lval",cons,4},
{"bval",cons,1},
{"sval",sval,0},
{"rsect",obj_coff_section,0},
{"sect",obj_coff_section,0},
{"block",s_space,0},
{"even",even,0},
{0, 0, 0}
};
const char EXP_CHARS[]= "eE";
const char EXP_CHARS[] = "eE";
/* Chars that mean this number is a floating point constant */
/* As in 0f12.456 */
/* or 0d1.2345e12 */
<<<<<<< tc-z8k.c
char FLT_CHARS[]= "rRsSfFdDxXpP";
=======
const char FLT_CHARS[] = "rRsSfFdDxXpP";
>>>>>>> 1.5
const relax_typeS md_relax_table[1];
static struct hash_control *opcode_hash_control; /* Opcode mnemonics */
void
md_begin ()
{
@ -119,7 +154,6 @@ md_begin ()
opcode_hash_control = hash_new ();
for (opcode = z8k_table; opcode->name; opcode++)
{
/* Only enter unique codes into the table */
@ -134,10 +168,22 @@ md_begin ()
prev_name = opcode->name;
}
/* default to z8002 */
s_unseg();
}
/* default to z8002 */
s_unseg ();
/* insert the pseudo ops too */
for (idx = 0; md_pseudo_table[idx].poc_name; idx++)
{
opcode_entry_type *fake_opcode;
fake_opcode = (opcode_entry_type*)malloc(sizeof(opcode_entry_type));
fake_opcode->name = md_pseudo_table[idx].poc_name,
fake_opcode->func = (void *)(md_pseudo_table+idx);
fake_opcode->opcode = 250;
hash_insert(opcode_hash_control,fake_opcode->name,fake_opcode);
}
}
struct z8k_exp
{
@ -154,14 +200,13 @@ typedef struct z8k_op
unsigned int x_reg; /* any other register associated with the mode */
expressionS exp; /* any expression */
} op_type;
}
op_type;
static expressionS *da_operand;
static expressionS *imm_operand;
int reg[16];
int the_cc;
@ -198,7 +243,6 @@ DEFUN (whatreg, (reg, src),
*/
/* try and parse a reg name, returns number of chars consumed */
char *
DEFUN (parse_reg, (src, mode, reg),
@ -208,6 +252,18 @@ DEFUN (parse_reg, (src, mode, reg),
{
char *res = 0;
if (src[0] == 's' && src[1]=='p') {
if (segmented_mode) {
*mode = CLASS_REG_LONG;
*reg = 14;
}
else
{
*mode = CLASS_REG_WORD;
*reg = 15;
}
return src+2;
}
if (src[0] == 'r')
{
if (src[1] == 'r')
@ -215,15 +271,15 @@ DEFUN (parse_reg, (src, mode, reg),
*mode = CLASS_REG_LONG;
res = whatreg (reg, src + 2);
}
else if (src[1] == 'h')
{
*mode = CLASS_REG_BYTE;
res = whatreg (reg, src + 2);
}
else if (src[1] == 'l')
else if (src[1] == 'h' )
{
*mode = CLASS_REG_BYTE;
res = whatreg (reg, src + 2) ;
}
else if (src[1] == 'l' )
{
*mode = CLASS_REG_BYTE;
res = whatreg (reg, src + 2);
*reg += 8;
}
else if (src[1] == 'q')
@ -239,7 +295,6 @@ DEFUN (parse_reg, (src, mode, reg),
}
return res;
}
char *
@ -341,10 +396,9 @@ struct cc_names
int value;
char *name;
};
struct cc_names table[]=
struct cc_names table[] =
{
0x0, "f",
0x1, "lt",
@ -417,7 +471,6 @@ DEFUN (get_operand, (ptr, mode, dst),
mode->mode = 0;
while (*src == ' ')
src++;
if (*src == '#')
@ -557,6 +610,8 @@ DEFUN (get_operands, (opcode, op_end, operand),
get_operand (&ptr, operand + 0, 0);
}
if(ptr == 0)
return;
if (*ptr == ',')
ptr++;
get_operand (&ptr, operand + 1, 1);
@ -590,7 +645,6 @@ DEFUN (get_operands, (opcode, op_end, operand),
abort ();
}
return ptr;
}
@ -599,9 +653,6 @@ DEFUN (get_operands, (opcode, op_end, operand),
provided
*/
static
opcode_entry_type *
DEFUN (get_specific, (opcode, operands),
@ -641,7 +692,8 @@ DEFUN (get_specific, (opcode, operands),
something that's ok */
goto fail;
}
else goto fail;
else
goto fail;
}
switch (mode & CLASS_MASK)
{
@ -718,22 +770,24 @@ DEFUN (newfix, (ptr, type, operand),
}
static char *
DEFUN (apply_fix,(ptr, type, operand, size),
char* ptr AND
DEFUN (apply_fix, (ptr, type, operand, size),
char *ptr AND
int type AND
expressionS *operand AND
expressionS * operand AND
int size)
{
int n = operand->X_add_number;
operand->X_add_number = n;
newfix((ptr - buffer)/2, type, operand);
newfix ((ptr - buffer) / 2, type, operand);
#if 1
switch (size) {
switch (size)
{
case 8: /* 8 nibbles == 32 bits */
*ptr++ = n>> 28;
*ptr++ = n>> 24;
*ptr++ = n>> 20;
*ptr++ = n>> 16;
*ptr++ = n >> 28;
*ptr++ = n >> 24;
*ptr++ = n >> 20;
*ptr++ = n >> 16;
case 4: /* 4 niblles == 16 bits */
*ptr++ = n >> 12;
*ptr++ = n >> 8;
@ -748,7 +802,6 @@ DEFUN (apply_fix,(ptr, type, operand, size),
}
/* Now we know what sort of opcodes it is, lets build the bytes -
*/
#define INSERT(x,y) *x++ = y>>24; *x++ = y>> 16; *x++=y>>8; *x++ =y;
@ -768,12 +821,13 @@ DEFUN (build_bytes, (this_try, operand),
int nib;
int nibble;
unsigned short *class_ptr;
frag_wane (frag_now);
frag_new (0);
memset (buffer, 20, 0);
class_ptr = this_try->byte_info;
top:;
top:;
for (nibble = 0; c = *class_ptr++; nibble++)
{
@ -787,21 +841,40 @@ DEFUN (build_bytes, (this_try, operand),
/* Direct address, we don't cope with the SS mode right now */
if (segmented_mode)
{
output_ptr = apply_fix (output_ptr , R_DA | R_SEG, da_operand, 8);
da_operand->X_add_number |= 0x80000000;
output_ptr = apply_fix (output_ptr, R_IMM32, da_operand, 8);
}
else
{
output_ptr = apply_fix(output_ptr, R_DA, da_operand, 4);
output_ptr = apply_fix (output_ptr, R_IMM16, da_operand, 4);
}
da_operand = 0;
break;
case CLASS_DISP8:
/* pc rel 8 bit */
output_ptr = apply_fix (output_ptr, R_JR, da_operand, 2);
output_ptr = apply_fix (output_ptr, R_JR, da_operand, 2);
da_operand = 0;
break;
case CLASS_BIT_1OR2:
*output_ptr = c & 0xf;
if (imm_operand)
{
if (imm_operand->X_add_number==2)
{
*output_ptr |= 2;
}
else if (imm_operand->X_add_number != 1)
{
as_bad("immediate must be 1 or 2");
}
}
else
{
as_bad("immediate 1 or 2 expected");
}
output_ptr++;
break;
case CLASS_CC:
*output_ptr++ = the_cc;
break;
@ -823,9 +896,10 @@ output_ptr = apply_fix (output_ptr, R_JR, da_operand, 2);
*output_ptr++ = reg[c & 0xf];
break;
case CLASS_DISP:
output_ptr = apply_fix (output_ptr, R_DA, da_operand, 4);
output_ptr = apply_fix (output_ptr, R_IMM16, da_operand, 4);
da_operand = 0;
break;
case CLASS_IMM:
{
nib = 0;
@ -840,17 +914,15 @@ output_ptr = apply_fix (output_ptr, R_JR, da_operand, 2);
break;
case ARG_IMMNMINUS1:
imm_operand->X_add_number--;
output_ptr = apply_fix (output_ptr, R_IMM4L, imm_operand,1);
output_ptr = apply_fix (output_ptr, R_IMM4L, imm_operand, 1);
break;
case ARG_NIM8:
imm_operand->X_add_number = -imm_operand->X_add_number;
case ARG_IMM8:
output_ptr = apply_fix (output_ptr , R_IMM8, imm_operand, 2);
output_ptr = apply_fix (output_ptr, R_IMM8, imm_operand, 2);
break;
case ARG_IMM16:
output_ptr= apply_fix(output_ptr, R_DA, imm_operand, 4);
output_ptr = apply_fix (output_ptr, R_IMM16, imm_operand, 4);
break;
case ARG_IMM32:
@ -878,7 +950,6 @@ output_ptr = apply_fix (output_ptr, R_JR, da_operand, 2);
fragp++;
}
}
}
@ -888,8 +959,6 @@ output_ptr = apply_fix (output_ptr, R_JR, da_operand, 2);
the frags/bytes it assembles to.
*/
void
DEFUN (md_assemble, (str),
char *str)
@ -928,13 +997,37 @@ DEFUN (md_assemble, (str),
opcode = (opcode_entry_type *) hash_find (opcode_hash_control,
op_start);
if (opcode == NULL)
{
as_bad ("unknown opcode");
return;
}
if (opcode->opcode == 250)
{
/* was really a pseudo op */
pseudo_typeS *p ;
char oc;
char *old = input_line_pointer;
*op_end = c;
input_line_pointer = op_end;
oc = *old;
*old = '\n';
while (*input_line_pointer == ' ')
input_line_pointer++;
p = (pseudo_typeS *)(opcode->func);
(p->poc_handler)(p->poc_val);
input_line_pointer = old;
*old = oc;
}
else {
input_line_pointer = get_operands (opcode, op_end,
operand);
*op_end = c;
@ -955,6 +1048,7 @@ DEFUN (md_assemble, (str),
}
build_bytes (opcode, operand);
}
}
void
@ -1053,8 +1147,15 @@ md_parse_option (argP, cntP, vecP)
char ***vecP;
{
return 0;
if (!strcmp(*argP,"z8001")) {
s_segm();
}
else if (!strcmp(*argP,"z8002")) {
s_unseg();
}
else return 0;
**argP = 0;
return 1;
}
int md_short_jump_size;
@ -1122,15 +1223,13 @@ md_apply_fix (fixP, val)
case R_JR:
*buf++ = val;
/* if (val != 0) abort();*/
/* if (val != 0) abort();*/
break;
case R_IMM8:
buf[0] += val;
break;
break;
case R_DA:
case R_IMM16:
*buf++ = (val >> 8);
*buf++ = val;
break;
@ -1140,12 +1239,15 @@ md_apply_fix (fixP, val)
*buf++ = (val >> 8);
*buf++ = val;
break;
#if 0
case R_DA | R_SEG:
*buf++ = (val >> 16);
*buf++ = 0x00;
*buf++ = (val >> 8);
*buf++ = val;
break;
#endif
default:
abort ();
@ -1177,7 +1279,8 @@ DEFUN (md_number_to_chars, (ptr, use, nbytes),
{
switch (nbytes)
{
case 4:*ptr++ = (use >> 24) & 0xff;
case 4:
*ptr++ = (use >> 24) & 0xff;
case 3:
*ptr++ = (use >> 16) & 0xff;
case 2:
@ -1201,7 +1304,6 @@ tc_coff_symbol_emit_hook ()
{
}
void
tc_reloc_mangle (fix_ptr, intr, base)
fixS *fix_ptr;
@ -1223,11 +1325,14 @@ tc_reloc_mangle (fix_ptr, intr, base)
{
case 2:
intr->r_type = R_DA;
intr->r_type = R_IMM16;
break;
case 1:
intr->r_type = R_IMM8;
break;
case 4:
intr->r_type = R_IMM32;
break;
default:
abort ();
@ -1247,5 +1352,4 @@ tc_reloc_mangle (fix_ptr, intr, base)
else
intr->r_symndx = -1;
}

View File

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