41
41
/* This is non-zero if target was set from the command line. */
42
42
static int z8k_target_from_cmdline;
44
static void s_segm PARAMS ((int));
45
static void even PARAMS ((int));
46
static int tohex PARAMS ((int));
47
static void sval PARAMS ((int));
56
machine = bfd_mach_z8001;
50
machine = bfd_mach_z8001;
62
machine = bfd_mach_z8002;
56
machine = bfd_mach_z8002;
69
int ignore ATTRIBUTE_UNUSED;
62
even (int ignore ATTRIBUTE_UNUSED)
71
64
frag_align (1, 0, 0);
72
65
record_alignment (now_seg, 1);
211
196
static expressionS *da_operand;
212
197
static expressionS *imm_operand;
220
static char *whatreg PARAMS ((int *, char *));
221
static char *parse_reg PARAMS ((char *, int *, unsigned int *));
222
static char *parse_exp PARAMS ((char *, expressionS *));
223
static char *checkfor PARAMS ((char *, char));
224
static void regword PARAMS ((int, char *));
225
static void regaddr PARAMS ((int, char *));
226
static void get_ctrl_operand
227
PARAMS ((char **, struct z8k_op *, unsigned int));
228
static void get_flags_operand
229
PARAMS ((char **, struct z8k_op *, unsigned int));
230
static void get_interrupt_operand
231
PARAMS ((char **, struct z8k_op *, unsigned int));
232
static void get_cc_operand
233
PARAMS ((char **, struct z8k_op *, unsigned int));
234
static void get_operand
235
PARAMS ((char **, struct z8k_op *, unsigned int));
236
static char *get_operands
237
PARAMS ((const opcode_entry_type *, char *, op_type *));
238
static opcode_entry_type *get_specific
239
PARAMS ((opcode_entry_type *, op_type *));
241
PARAMS ((int, int, int, expressionS *));
242
static char *apply_fix
243
PARAMS ((char *, int, expressionS *, int));
244
static void build_bytes
245
PARAMS ((opcode_entry_type *, struct z8k_op *));
202
static int the_flags;
203
static int the_interrupt;
206
whatreg (int *reg, char *src)
252
208
if (ISDIGIT (src[1]))
279
235
in SRC after the reg name. */
282
parse_reg (src, mode, reg)
238
parse_reg (char *src, int *mode, unsigned int *reg)
290
if (src[0] == 's' && src[1] == 'p' && (src[2] == 0 || src[2] == ','))
243
/* Check for stack pointer "sp" alias. */
244
if ((src[0] == 's' || src[0] == 'S')
245
&& (src[1] == 'p' || src[1] == 'P')
246
&& (src[2] == 0 || src[2] == ','))
292
248
if (segmented_mode)
316
273
as_bad (_("register rr%d does not exist"), regno);
318
else if (src[1] == 'h')
275
else if (src[1] == 'h' || src[1] == 'H')
320
277
if (src[2] < '0' || src[2] > '9')
321
278
return res; /* Assume no register name but a label starting with 'rh'. */
326
283
as_bad (_("register rh%d out of range"), regno);
328
else if (src[1] == 'l')
285
else if (src[1] == 'l' || src[1] == 'L')
330
287
if (src[2] < '0' || src[2] > '9')
331
288
return res; /* Assume no register name but a label starting with 'rl'. */
336
293
as_bad (_("register rl%d out of range"), regno);
339
else if (src[1] == 'q')
296
else if (src[1] == 'q' || src[1] == 'Q')
341
298
if (src[2] < '0' || src[2] > '9')
342
299
return res; /* Assume no register name but a label starting with 'rq'. */
446
struct ctrl_names ctrl_table[] = {
395
static struct ctrl_names ctrl_table[] = {
396
{ 0x1, "flags" }, /* ldctlb only. */
397
{ 0x2, "fcw" }, /* ldctl only. Applies to all remaining control registers. */
448
398
{ 0x3, "refresh" },
449
399
{ 0x4, "psapseg" },
450
400
{ 0x5, "psapoff" },
459
get_ctrl_operand (ptr, mode, dst)
462
unsigned int dst ATTRIBUTE_UNUSED;
409
get_ctrl_operand (char **ptr, struct z8k_op *mode, unsigned int dst ATTRIBUTE_UNUSED)
464
411
char *src = *ptr;
467
414
while (*src == ' ')
470
417
mode->mode = CLASS_CTRL;
471
418
for (i = 0; ctrl_table[i].name; i++)
475
for (j = 0; ctrl_table[i].name[j]; j++)
477
if (ctrl_table[i].name[j] != src[j])
480
the_ctrl = ctrl_table[i].value;
420
l = strlen (ctrl_table[i].name);
421
if (! strncasecmp (ctrl_table[i].name, src, l))
423
the_ctrl = ctrl_table[i].value;
424
if (*(src + l) && *(src + l) != ',')
426
*ptr = src + l; /* Valid control name found: "consume" it. */
490
433
struct flag_names {
496
struct flag_names flag_table[] = {
438
static struct flag_names flag_table[] = {
507
get_flags_operand (ptr, mode, dst)
510
unsigned int dst ATTRIBUTE_UNUSED;
450
get_flags_operand (char **ptr, struct z8k_op *mode, unsigned int dst ATTRIBUTE_UNUSED)
512
452
char *src = *ptr;
557
get_interrupt_operand (ptr, mode, dst)
560
unsigned int dst ATTRIBUTE_UNUSED;
497
get_interrupt_operand (char **ptr, struct z8k_op *mode, unsigned int dst ATTRIBUTE_UNUSED)
562
499
char *src = *ptr;
565
502
while (*src == ' ')
568
505
mode->mode = CLASS_IMM;
569
for (i = 0; intr_table[i].name; i++)
573
for (j = 0; intr_table[i].name[j]; j++)
575
if (intr_table[i].name[j] != src[j])
578
the_interrupt = intr_table[i].value;
510
for (i = 0; intr_table[i].name; i++)
512
l = strlen (intr_table[i].name);
513
if (! strncasecmp (intr_table[i].name, src, l))
515
the_interrupt |= intr_table[i].value;
516
if (*(src + l) && *(src + l) != ',')
520
as_bad (_("unknown interrupt %s"), src);
521
while (**ptr && ! is_end_of_line[(unsigned char) **ptr])
522
(*ptr)++; /* Consume rest of line. */
584
542
/* No interrupt type specified, opcode won't do anything. */
585
543
as_warn (_("opcode has no effect"));
586
544
the_interrupt = 0x0;
590
547
struct cc_names {
595
struct cc_names table[] = {
552
static struct cc_names table[] = {
622
get_cc_operand (ptr, mode, dst)
625
unsigned int dst ATTRIBUTE_UNUSED;
587
get_cc_operand (char **ptr, struct z8k_op *mode, unsigned int dst ATTRIBUTE_UNUSED)
627
589
char *src = *ptr;
630
592
while (*src == ' ')
633
595
mode->mode = CLASS_CC;
634
596
for (i = 0; table[i].name; i++)
638
for (j = 0; table[i].name[j]; j++)
640
if (table[i].name[j] != src[j])
643
the_cc = table[i].value;
598
l = strlen (table[i].name);
599
if (! strncasecmp (table[i].name, src, l))
601
the_cc = table[i].value;
602
if (*(src + l) && *(src + l) != ',')
604
*ptr = src + l; /* Valid cc found: "consume" it. */
608
the_cc = 0x8; /* Not recognizing the cc defaults to t. (Assuming no cc present.) */
653
get_operand (ptr, mode, dst)
656
unsigned int dst ATTRIBUTE_UNUSED;
612
get_operand (char **ptr, struct z8k_op *mode, unsigned int dst ATTRIBUTE_UNUSED)
658
614
char *src = *ptr;
758
get_operands (opcode, op_end, operand)
759
const opcode_entry_type *opcode;
714
get_operands (const opcode_entry_type *opcode, char *op_end, op_type *operand)
763
716
char *ptr = op_end;
767
719
switch (opcode->noperands)
770
722
operand[0].mode = 0;
771
723
operand[1].mode = 0;
775
729
if (opcode->arg_info[0] == CLASS_CC)
776
get_cc_operand (&ptr, operand + 0, 0);
731
get_cc_operand (&ptr, operand + 0, 0);
734
if (*ptr && ! is_end_of_line[(unsigned char) *ptr])
736
as_bad (_("invalid condition code '%s'"), ptr);
737
while (*ptr && ! is_end_of_line[(unsigned char) *ptr])
738
ptr++; /* Consume rest of line. */
778
741
else if (opcode->arg_info[0] == CLASS_FLAGS)
779
get_flags_operand (&ptr, operand + 0, 0);
743
get_flags_operand (&ptr, operand + 0, 0);
746
if (*ptr && ! is_end_of_line[(unsigned char) *ptr])
748
as_bad (_("invalid flag '%s'"), ptr);
749
while (*ptr && ! is_end_of_line[(unsigned char) *ptr])
750
ptr++; /* Consume rest of line. */
781
753
else if (opcode->arg_info[0] == (CLASS_IMM + (ARG_IMM2)))
782
754
get_interrupt_operand (&ptr, operand + 0, 0);
785
756
get_operand (&ptr, operand + 0, 0);
792
763
if (opcode->arg_info[0] == CLASS_CC)
793
get_cc_operand (&ptr, operand + 0, 0);
765
get_cc_operand (&ptr, operand + 0, 0);
768
if (*ptr != ',' && strchr (ptr + 1, ','))
775
as_bad (_("invalid condition code '%s'"), savptr);
795
778
else if (opcode->arg_info[0] == CLASS_CTRL)
797
780
get_ctrl_operand (&ptr, operand + 0, 0);
856
841
static opcode_entry_type *
857
get_specific (opcode, operands)
858
opcode_entry_type *opcode;
842
get_specific (opcode_entry_type *opcode, op_type *operands)
861
844
opcode_entry_type *this_try = opcode;
953
#if 0 /* Not used. */
955
check_operand (operand, width, string)
956
struct z8k_op *operand;
960
if (operand->exp.X_add_symbol == 0
961
&& operand->exp.X_op_symbol == 0)
964
/* No symbol involved, let's look at offset, it's dangerous if
965
any of the high bits are not 0 or ff's, find out by oring or
966
anding with the width and seeing if the answer is 0 or all
968
if ((operand->exp.X_add_number & ~width) != 0 &&
969
(operand->exp.X_add_number | width) != (~0))
971
as_warn (_("operand %s0x%x out of range"),
972
string, operand->exp.X_add_number);
979
940
static char buffer[20];
982
newfix (ptr, type, size, operand)
985
int size; /* nibbles. */
986
expressionS *operand;
943
newfix (int ptr, int type, int size, expressionS *operand)
988
945
int is_pcrel = 0;
947
/* size is in nibbles. */
990
949
if (operand->X_add_symbol
991
950
|| operand->X_op_symbol
992
951
|| operand->X_add_number)
1011
apply_fix (ptr, type, operand, size)
1014
expressionS *operand;
1015
int size; /* nibbles. */
970
apply_fix (char *ptr, int type, expressionS *operand, int size)
1017
972
long n = operand->X_add_number;
974
/* size is in nibbles. */
1019
976
newfix ((ptr - buffer) / 2, type, size + 1, operand);
1041
998
#define INSERT(x,y) *x++ = y>>24; *x++ = y>> 16; *x++=y>>8; *x++ =y;
1044
build_bytes (this_try, operand)
1045
opcode_entry_type *this_try;
1046
struct z8k_op *operand ATTRIBUTE_UNUSED;
1001
build_bytes (opcode_entry_type *this_try, struct z8k_op *operand ATTRIBUTE_UNUSED)
1048
1003
char *output_ptr = buffer;
1115
1070
*output_ptr++ = the_cc;
1117
1072
case CLASS_0CCC:
1073
if (the_ctrl < 2 || the_ctrl > 7)
1074
as_bad (_("invalid control register name"));
1118
1075
*output_ptr++ = the_ctrl;
1120
1077
case CLASS_1CCC:
1078
if (the_ctrl < 2 || the_ctrl > 7)
1079
as_bad (_("invalid control register name"));
1121
1080
*output_ptr++ = the_ctrl | 0x8;
1123
1082
case CLASS_00II:
1222
1181
the frags/bytes it assembles to. */
1184
md_assemble (char *str)
1229
1187
char *op_start;
1231
1189
struct z8k_op operand[3];
1232
1190
opcode_entry_type *opcode;
1233
opcode_entry_type *prev_opcode;
1235
1192
/* Drop leading whitespace. */
1236
1193
while (*str == ' ')
1286
1244
new_input_line_pointer = get_operands (opcode, op_end, operand);
1287
1245
if (new_input_line_pointer)
1288
1246
input_line_pointer = new_input_line_pointer;
1289
prev_opcode = opcode; /* XXX is this used ?? */
1291
1248
opcode = get_specific (opcode, operand);
1316
1272
/* We have no need to default values of symbols. */
1319
md_undefined_symbol (name)
1320
char *name ATTRIBUTE_UNUSED;
1275
md_undefined_symbol (char *name ATTRIBUTE_UNUSED)
1326
tc_headers_hook (headers)
1327
object_headers *headers ATTRIBUTE_UNUSED;
1281
tc_headers_hook (object_headers *headers ATTRIBUTE_UNUSED)
1329
1283
printf (_("call to tc_headers_hook \n"));
1339
1293
returned, or NULL on OK. */
1342
md_atof (type, litP, sizeP)
1296
md_atof (int type, char *litP, int *sizeP)
1348
1299
LITTLENUM_TYPE words[MAX_LITTLENUMS];
1449
md_convert_frag (headers, seg, fragP)
1450
object_headers *headers ATTRIBUTE_UNUSED;
1451
segT seg ATTRIBUTE_UNUSED;
1452
fragS *fragP ATTRIBUTE_UNUSED;
1397
md_convert_frag (object_headers *headers ATTRIBUTE_UNUSED,
1398
segT seg ATTRIBUTE_UNUSED,
1399
fragS *fragP ATTRIBUTE_UNUSED)
1454
1401
printf (_("call to md_convert_frag\n"));
1459
md_section_align (seg, size)
1406
md_section_align (segT seg, valueT size)
1463
1408
return ((size + (1 << section_alignment[(int) seg]) - 1)
1464
1409
& (-1 << section_alignment[(int) seg]));
1468
1413
has been eliminated, set fix->fx_done. If fix->fx_addsy is non-NULL,
1469
1414
we will have to generate a reloc entry. */
1471
md_apply_fix3 (fixP, valP, segment)
1474
segT segment ATTRIBUTE_UNUSED;
1416
md_apply_fix3 (fixS *fixP, valueT *valP, segT segment ATTRIBUTE_UNUSED)
1476
1418
long val = * (long *) valP;
1477
1419
char *buf = fixP->fx_where + fixP->fx_frag->fr_literal;
1513
as_bad (_("cannot branch to odd address"));
1455
as_bad (_("cannot branch to odd address"));
1515
1457
if (val > 0 || val < -127)
1516
as_bad (_("relative jump out of range"));
1458
as_bad (_("relative jump out of range"));
1517
1459
*buf = (*buf & 0x80) | (-val & 0x7f);
1518
fixP->fx_no_overflow = 1;
1460
fixP->fx_no_overflow = 1;
1519
1461
fixP->fx_done = 1;
1532
1474
as_bad (_("cannot branch to odd address"));
1533
1475
if (val > 4096 || val < -4095)
1534
as_bad (_("relative call out of range"));
1476
as_bad (_("relative call out of range"));
1535
1477
val = -val / 2;
1536
*buf = (*buf & 0xf0) | ((val >> 8) & 0xf);
1538
*buf++ = val & 0xff;
1478
*buf = (*buf & 0xf0) | ((val >> 8) & 0xf);
1480
*buf++ = val & 0xff;
1539
1481
fixP->fx_no_overflow = 1;
1540
1482
fixP->fx_done = 1;
1592
md_estimate_size_before_relax (fragP, segment_type)
1593
register fragS *fragP ATTRIBUTE_UNUSED;
1594
register segT segment_type ATTRIBUTE_UNUSED;
1534
md_estimate_size_before_relax (fragS *fragP ATTRIBUTE_UNUSED,
1535
segT segment_type ATTRIBUTE_UNUSED)
1596
1537
printf (_("call to md_estimate_size_before_relax\n"));
1600
1541
/* Put number into target byte order. */
1603
md_number_to_chars (ptr, use, nbytes)
1544
md_number_to_chars (char *ptr, valueT use, int nbytes)
1608
1546
number_to_chars_bigendian (ptr, use, nbytes);
1611
1549
/* On the Z8000, a PC-relative offset is relative to the address of the
1612
1550
instruction plus its size. */
1614
md_pcrel_from (fixP)
1552
md_pcrel_from (fixS *fixP)
1617
1554
return fixP->fx_size + fixP->fx_where + fixP->fx_frag->fr_address;
1621
tc_coff_symbol_emit_hook (s)
1622
symbolS *s ATTRIBUTE_UNUSED;
1558
tc_coff_symbol_emit_hook (symbolS *s ATTRIBUTE_UNUSED)
1627
tc_reloc_mangle (fix_ptr, intr, base)
1629
struct internal_reloc *intr;
1563
tc_reloc_mangle (fixS *fix_ptr, struct internal_reloc *intr, bfd_vma base)
1633
1565
symbolS *symbol_ptr;