/* Table of opcodes for the OpenRISC 1000 ISA.
- Copyright 2002, 2004, 2005 Free Software Foundation, Inc.
+ Copyright 2002, 2004, 2005, 2007, 2008, 2009, 2012
+ Free Software Foundation, Inc.
Contributed by Damjan Lampret (lampret@opencores.org).
- This file is part of gen_or1k_isa, or1k, GDB and GAS.
+ This file is part of the GNU opcodes library.
- This program is free software; you can redistribute it and/or modify
+ This library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
+ It is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
MA 02110-1301, USA. */
-/* We treat all letters the same in encode/decode routines so
- we need to assign some characteristics to them like signess etc. */
+#include "sysdep.h"
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include "safe-ctype.h"
#include "ansidecl.h"
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
#include "opcode/or32.h"
+/* We treat all letters the same in encode/decode routines so
+ we need to assign some characteristics to them like signess etc. */
+
const struct or32_letter or32_letters[] =
{
{ 'A', NUM_UNSIGNED },
/* Define dummy, if debug is not defined. */
#if !defined HAS_DEBUG
-static void
+static void ATTRIBUTE_PRINTF_2
debug (int level ATTRIBUTE_UNUSED, const char *format ATTRIBUTE_UNUSED, ...)
{
}
/* Calculates instruction length in bytes. Always 4 for OR32. */
int
-insn_len (int insn_index ATTRIBUTE_UNUSED)
+insn_len (int i_index ATTRIBUTE_UNUSED)
{
return 4;
}
}
const char *
-insn_name (int index)
+insn_name (int op_index)
{
- if (index >= 0 && index < (int) or32_num_opcodes)
- return or32_opcodes[index].name;
+ if (op_index >= 0 && op_index < (int) or32_num_opcodes)
+ return or32_opcodes[op_index].name;
else
return "???";
}
last_match = i;
}
- debug (8, "%08X %08X\n", mask, cur_mask);
+ debug (8, "%08X %08lX\n", mask, cur_mask);
if (ninstr == 0)
return 0;
if (ninstr == 1)
{
/* Leaf holds instruction index. */
- debug (8, "%i>I%i %s\n",
- cur - automata, last_match, or32_opcodes[last_match].name);
+ debug (8, "%li>I%i %s\n",
+ (long)(cur - automata), last_match, or32_opcodes[last_match].name);
*cur = LEAF_FLAG | last_match;
cur++;
{
unsigned long m = (1UL << ((unsigned long) len)) - 1;
- debug (9, " (%i(%08X & %08X>>%i = %08X, %08X)",
+ debug (9, " (%i(%08lX & %08lX>>%i = %08lX, %08lX)",
len,m, cur_mask, i, (cur_mask >> (unsigned)i),
(cur_mask >> (unsigned) i) & m);
exit (1);
}
- debug (8, "%i> #### %i << %i (%i) ####\n",
- cur - automata, best_len, best_first, ninstr);
+ debug (8, "%li> #### %i << %i (%i) ####\n",
+ (long)(cur - automata), best_len, best_first, ninstr);
*cur = best_first;
cur++;
&& ((ti[j].insn_mask >> best_first) & cur_mask) == cur_mask)
ti[j].in_pass = curpass;
- debug (9, "%08X %08X %i\n", mask, cur_mask, best_first);
+ debug (9, "%08X %08lX %i\n", mask, cur_mask, best_first);
c = cover_insn (cur, curpass, mask & (~(cur_mask << best_first)));
if (c)
{
- debug (8, "%i> #%X -> %u\n", next - automata, i, cur - automata);
+ debug (8, "%li> #%X -> %lu\n", (long)(next - automata), i,
+ (unsigned long)(cur - automata));
*next = cur - automata;
cur = c;
}
else
{
- debug (8, "%i> N/A\n", next - automata);
+ debug (8, "%li> N/A\n", (long)(next - automata));
*next = 0;
}
next++;
{
cur->type = OPTYPE_REG | OPTYPE_OP | OPTYPE_LAST;
cur->data = 0;
- debug (9, "#%08X %08X\n", cur->type, cur->data);
+ debug (9, "#%08lX %08lX\n", cur->type, cur->data);
cur++;
return cur;
}
unsigned long arg;
arg = insn_extract (*args, opcode->encoding);
- debug (9, "%s : %08X ------\n", opcode->name, arg);
+ debug (9, "%s : %08lX ------\n", opcode->name, arg);
if (letter_signed (*args))
{
type |= OPTYPE_SIG;
cur->type = type | shr;
cur->data = mask;
arg &= ~(((1 << mask) - 1) << shr);
- debug (6, "|%08X %08X\n", cur->type, cur->data);
+ debug (6, "|%08lX %08lX\n", cur->type, cur->data);
cur++;
}
args++;
Later we will treat them as one operand. */
cur--;
cur->type = type | cur->type | OPTYPE_DIS | OPTYPE_OP;
- debug (9, ">%08X %08X\n", cur->type, cur->data);
+ debug (9, ">%08lX %08lX\n", cur->type, cur->data);
cur++;
type = 0;
i++;
{
cur--;
cur->type = type | cur->type | OPTYPE_OP;
- debug (9, ">%08X %08X\n", cur->type, cur->data);
+ debug (9, ">%08lX %08lX\n", cur->type, cur->data);
cur++;
type = 0;
i++;
{
cur->type = type;
cur->data = 0;
- debug (9, ">%08X %08X\n", cur->type, cur->data);
+ debug (9, ">%08lX %08lX\n", cur->type, cur->data);
cur++;
type = 0;
i++;
cur--;
cur->type = type | cur->type | OPTYPE_OP | OPTYPE_LAST;
- debug (9, "#%08X %08X\n", cur->type, cur->data);
+ debug (9, "#%08lX %08lX\n", cur->type, cur->data);
cur++;
return cur;
{
unsigned int first = *a;
- debug (9, "%i ", a - automata);
+ debug (9, "%li ", (long)(a - automata));
a++;
i = (insn >> first) & *a;
if (!*(a + i))
{
/* Invalid instruction found? */
- debug (9, "XXX\n", i);
+ debug (9, "XXX\n");
return -1;
}
a = automata + *(a + i);
{
unsigned long tmp = strtol (enc, NULL, 16);
#if DEBUG
- printf (" enc=%s, tmp=%x ", enc, tmp);
+ printf (" enc=%s, tmp=%lx ", enc, tmp);
#endif
if (param_ch == '0')
tmp = 15 - tmp;
opc_pos--;
param_pos--;
#if DEBUG
- printf ("\n ret=%x opc_pos=%x, param_pos=%x\n", ret, opc_pos, param_pos);
+ printf ("\n ret=%lx opc_pos=%x, param_pos=%x\n", ret, opc_pos, param_pos);
#endif
if (ISLOWER (param_ch))
ret -= ((insn >> opc_pos) & 0x1) << param_pos;
enc++;
#if DEBUG
- printf ("ret=%x\n", ret);
+ printf ("ret=%lx\n", ret);
#endif
return ret;
}
or32_print_register (char param_ch, char *encoding, unsigned long insn)
{
int regnum = or32_extract(param_ch, encoding, insn);
-
- sprintf (disassembled, "%sr%d", disassembled, regnum);
+ char s_regnum[20];
+
+ sprintf (s_regnum, "r%d", regnum);
+ strcat (disassembled, s_regnum);
}
/* Print immediate. Used only by print_insn. */
or32_print_immediate (char param_ch, char *encoding, unsigned long insn)
{
int imm = or32_extract (param_ch, encoding, insn);
+ char s_imm[20];
imm = extend_imm (imm, param_ch);
-
+
if (letter_signed (param_ch))
{
if (imm < 0)
- sprintf (disassembled, "%s%d", disassembled, imm);
+ sprintf (s_imm, "%d", imm);
else
- sprintf (disassembled, "%s0x%x", disassembled, imm);
+ sprintf (s_imm, "0x%x", imm);
}
else
- sprintf (disassembled, "%s%#x", disassembled, imm);
+ sprintf (s_imm, "%#x", imm);
+ strcat (disassembled, s_imm);
}
/* Disassemble one instruction from insn to disassemble.
int
disassemble_insn (unsigned long insn)
{
- int index;
- index = insn_decode (insn);
+ int op_index;
+ op_index = insn_decode (insn);
- if (index >= 0)
+ if (op_index >= 0)
{
- struct or32_opcode const *opcode = &or32_opcodes[index];
+ struct or32_opcode const *opcode = &or32_opcodes[op_index];
char *s;
sprintf (disassembled, "%s ", opcode->name);
if (strchr (opcode->encoding, *s))
or32_print_immediate (*s, opcode->encoding, insn);
else
- sprintf (disassembled, "%s%c", disassembled, *s);
+ {
+ char s_encoding[2] = { *s, '\0' };
+
+ strcat (disassembled, s_encoding);
+ }
+
}
}
}
else
{
+ char s_insn[20];
+
/* This used to be %8x for binutils. */
- sprintf (disassembled, "%s.word 0x%08lx", disassembled, insn);
+ sprintf (s_insn, ".word 0x%08lx", insn);
+ strcat (disassembled, s_insn);
}
return insn_len (insn);