* bytecode.c (bc_align_tobytes): Handle cases where some code fills don't

exist (this happens in LC3b).
* lc3barch.c (lc3b_get_fill): NOP pattern is actually all 0's.

svn path=/trunk/yasm/; revision=1264
0.5.0rc2
Peter Johnson 20 years ago
parent d660906db5
commit 8cecb5b2a1
  1. 25
      libyasm/bytecode.c
  2. 24
      modules/arch/lc3b/lc3barch.c

@ -786,7 +786,7 @@ bc_align_tobytes(yasm_bytecode *bc, unsigned char **bufp, void *d,
/*@unused@*/ yasm_output_reloc_func output_reloc) /*@unused@*/ yasm_output_reloc_func output_reloc)
{ {
bytecode_align *align = (bytecode_align *)bc->contents; bytecode_align *align = (bytecode_align *)bc->contents;
unsigned long len, i; unsigned long len;
unsigned long boundary = unsigned long boundary =
yasm_intnum_get_uint(yasm_expr_get_intnum(&align->boundary, NULL)); yasm_intnum_get_uint(yasm_expr_get_intnum(&align->boundary, NULL));
@ -814,11 +814,26 @@ bc_align_tobytes(yasm_bytecode *bc, unsigned char **bufp, void *d,
memset(*bufp, (int)v, len); memset(*bufp, (int)v, len);
*bufp += len; *bufp += len;
} else if (align->code_fill) { } else if (align->code_fill) {
while (len > 15) { unsigned long maxlen = 15;
memcpy(*bufp, align->code_fill[15], 15); while (!align->code_fill[maxlen] && maxlen>0)
*bufp += 15; maxlen--;
len -= 15; if (maxlen == 0) {
yasm__error(bc->line, N_("could not find any code alignment size"));
return 1;
}
/* Fill with maximum code fill as much as possible */
while (len > maxlen) {
memcpy(*bufp, align->code_fill[maxlen], maxlen);
*bufp += maxlen;
len -= maxlen;
}
if (!align->code_fill[len]) {
yasm__error(bc->line, N_("invalid alignment size %d"), len);
return 1;
} }
/* Handle rest of code fill */
memcpy(*bufp, align->code_fill[len], len); memcpy(*bufp, align->code_fill[len], len);
*bufp += len; *bufp += len;
} else { } else {

@ -92,27 +92,27 @@ lc3b_parse_directive(/*@unused@*/ yasm_arch *arch,
static const unsigned char ** static const unsigned char **
lc3b_get_fill(const yasm_arch *arch) lc3b_get_fill(const yasm_arch *arch)
{ {
/* NOP pattern is AND r0, r0, r0 repeated */ /* NOP pattern is all 0's per LC-3b Assembler 3.50 output */
static const char *fill[16] = { static const char *fill[16] = {
NULL, /* unused */ NULL, /* unused */
NULL, /* 1 - illegal; all opcodes are 2 bytes long */ NULL, /* 1 - illegal; all opcodes are 2 bytes long */
"\x50\x00", /* 4 */ "\x00\x00", /* 4 */
NULL, /* 3 - illegal */ NULL, /* 3 - illegal */
"\x50\x00\x50\x00", /* 4 */ "\x00\x00\x00\x00", /* 4 */
NULL, /* 5 - illegal */ NULL, /* 5 - illegal */
"\x50\x00\x50\x00\x50\x00", /* 6 */ "\x00\x00\x00\x00\x00\x00", /* 6 */
NULL, /* 7 - illegal */ NULL, /* 7 - illegal */
"\x50\x00\x50\x00\x50\x00" /* 8 */ "\x00\x00\x00\x00\x00\x00" /* 8 */
"\x50\x00", "\x00\x00",
NULL, /* 9 - illegal */ NULL, /* 9 - illegal */
"\x50\x00\x50\x00\x50\x00" /* 10 */ "\x00\x00\x00\x00\x00\x00" /* 10 */
"\x50\x00\x50\x00", "\x00\x00\x00\x00",
NULL, /* 11 - illegal */ NULL, /* 11 - illegal */
"\x50\x00\x50\x00\x50\x00" /* 12 */ "\x00\x00\x00\x00\x00\x00" /* 12 */
"\x50\x00\x50\x00\x50\x00", "\x00\x00\x00\x00\x00\x00",
NULL, /* 13 - illegal */ NULL, /* 13 - illegal */
"\x50\x00\x50\x00\x50\x00" /* 14 */ "\x00\x00\x00\x00\x00\x00" /* 14 */
"\x50\x00\x50\x00\x50\x00\x50\x00", "\x00\x00\x00\x00\x00\x00\x00\x00",
NULL /* 15 - illegal */ NULL /* 15 - illegal */
}; };
return (const unsigned char **)fill; return (const unsigned char **)fill;

Loading…
Cancel
Save