qemu/target/openrisc/disas.c
<<
>>
Prefs
   1/*
   2 * OpenRISC disassembler
   3 *
   4 * Copyright (c) 2018 Richard Henderson <rth@twiddle.net>
   5 *
   6 * This program is free software: you can redistribute it and/or modify
   7 * it under the terms of the GNU General Public License as published by
   8 * the Free Software Foundation, either version 2 of the License, or
   9 * (at your option) any later version.
  10 *
  11 * This program is distributed in the hope that it will be useful,
  12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14 * GNU General Public License for more details.
  15 *
  16 * You should have received a copy of the GNU General Public License
  17 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18 */
  19
  20#include "qemu/osdep.h"
  21#include "disas/dis-asm.h"
  22#include "qemu/bitops.h"
  23#include "cpu.h"
  24
  25typedef disassemble_info DisasContext;
  26
  27/* Include the auto-generated decoder.  */
  28#include "decode.inc.c"
  29
  30#define output(mnemonic, format, ...) \
  31    (info->fprintf_func(info->stream, "%-9s " format, \
  32                        mnemonic, ##__VA_ARGS__))
  33
  34int print_insn_or1k(bfd_vma addr, disassemble_info *info)
  35{
  36    bfd_byte buffer[4];
  37    uint32_t insn;
  38    int status;
  39
  40    status = info->read_memory_func(addr, buffer, 4, info);
  41    if (status != 0) {
  42        info->memory_error_func(status, addr, info);
  43        return -1;
  44    }
  45    insn = bfd_getb32(buffer);
  46
  47    if (!decode(info, insn)) {
  48        output(".long", "%#08x", insn);
  49    }
  50    return 4;
  51}
  52
  53#define INSN(opcode, format, ...)                                       \
  54static bool trans_l_##opcode(disassemble_info *info, arg_l_##opcode *a) \
  55{                                                                       \
  56    output("l." #opcode, format, ##__VA_ARGS__);                        \
  57    return true;                                                        \
  58}
  59
  60INSN(add,    "r%d, r%d, r%d", a->d, a->a, a->b)
  61INSN(addc,   "r%d, r%d, r%d", a->d, a->a, a->b)
  62INSN(sub,    "r%d, r%d, r%d", a->d, a->a, a->b)
  63INSN(and,    "r%d, r%d, r%d", a->d, a->a, a->b)
  64INSN(or,     "r%d, r%d, r%d", a->d, a->a, a->b)
  65INSN(xor,    "r%d, r%d, r%d", a->d, a->a, a->b)
  66INSN(sll,    "r%d, r%d, r%d", a->d, a->a, a->b)
  67INSN(srl,    "r%d, r%d, r%d", a->d, a->a, a->b)
  68INSN(sra,    "r%d, r%d, r%d", a->d, a->a, a->b)
  69INSN(ror,    "r%d, r%d, r%d", a->d, a->a, a->b)
  70INSN(exths,  "r%d, r%d", a->d, a->a)
  71INSN(extbs,  "r%d, r%d", a->d, a->a)
  72INSN(exthz,  "r%d, r%d", a->d, a->a)
  73INSN(extbz,  "r%d, r%d", a->d, a->a)
  74INSN(cmov,   "r%d, r%d, r%d", a->d, a->a, a->b)
  75INSN(ff1,    "r%d, r%d", a->d, a->a)
  76INSN(fl1,    "r%d, r%d", a->d, a->a)
  77INSN(mul,    "r%d, r%d, r%d", a->d, a->a, a->b)
  78INSN(mulu,   "r%d, r%d, r%d", a->d, a->a, a->b)
  79INSN(div,    "r%d, r%d, r%d", a->d, a->a, a->b)
  80INSN(divu,   "r%d, r%d, r%d", a->d, a->a, a->b)
  81INSN(muld,   "r%d, r%d", a->a, a->b)
  82INSN(muldu,  "r%d, r%d", a->a, a->b)
  83INSN(j,      "%d", a->n)
  84INSN(jal,    "%d", a->n)
  85INSN(bf,     "%d", a->n)
  86INSN(bnf,    "%d", a->n)
  87INSN(jr,     "r%d", a->b)
  88INSN(jalr,   "r%d", a->b)
  89INSN(lwa,    "r%d, %d(r%d)", a->d, a->i, a->a)
  90INSN(lwz,    "r%d, %d(r%d)", a->d, a->i, a->a)
  91INSN(lws,    "r%d, %d(r%d)", a->d, a->i, a->a)
  92INSN(lbz,    "r%d, %d(r%d)", a->d, a->i, a->a)
  93INSN(lbs,    "r%d, %d(r%d)", a->d, a->i, a->a)
  94INSN(lhz,    "r%d, %d(r%d)", a->d, a->i, a->a)
  95INSN(lhs,    "r%d, %d(r%d)", a->d, a->i, a->a)
  96INSN(swa,    "%d(r%d), r%d", a->i, a->a, a->b)
  97INSN(sw,     "%d(r%d), r%d", a->i, a->a, a->b)
  98INSN(sb,     "%d(r%d), r%d", a->i, a->a, a->b)
  99INSN(sh,     "%d(r%d), r%d", a->i, a->a, a->b)
 100INSN(nop,    "")
 101INSN(adrp,   "r%d, %d", a->d, a->i)
 102INSN(addi,   "r%d, r%d, %d", a->d, a->a, a->i)
 103INSN(addic,  "r%d, r%d, %d", a->d, a->a, a->i)
 104INSN(muli,   "r%d, r%d, %d", a->d, a->a, a->i)
 105INSN(maci,   "r%d, %d", a->a, a->i)
 106INSN(andi,   "r%d, r%d, %d", a->d, a->a, a->k)
 107INSN(ori,    "r%d, r%d, %d", a->d, a->a, a->k)
 108INSN(xori,   "r%d, r%d, %d", a->d, a->a, a->i)
 109INSN(mfspr,  "r%d, r%d, %d", a->d, a->a, a->k)
 110INSN(mtspr,  "r%d, r%d, %d", a->a, a->b, a->k)
 111INSN(mac,    "r%d, r%d", a->a, a->b)
 112INSN(msb,    "r%d, r%d", a->a, a->b)
 113INSN(macu,   "r%d, r%d", a->a, a->b)
 114INSN(msbu,   "r%d, r%d", a->a, a->b)
 115INSN(slli,   "r%d, r%d, %d", a->d, a->a, a->l)
 116INSN(srli,   "r%d, r%d, %d", a->d, a->a, a->l)
 117INSN(srai,   "r%d, r%d, %d", a->d, a->a, a->l)
 118INSN(rori,   "r%d, r%d, %d", a->d, a->a, a->l)
 119INSN(movhi,  "r%d, %d", a->d, a->k)
 120INSN(macrc,  "r%d", a->d)
 121INSN(sfeq,   "r%d, r%d", a->a, a->b)
 122INSN(sfne,   "r%d, r%d", a->a, a->b)
 123INSN(sfgtu,  "r%d, r%d", a->a, a->b)
 124INSN(sfgeu,  "r%d, r%d", a->a, a->b)
 125INSN(sfltu,  "r%d, r%d", a->a, a->b)
 126INSN(sfleu,  "r%d, r%d", a->a, a->b)
 127INSN(sfgts,  "r%d, r%d", a->a, a->b)
 128INSN(sfges,  "r%d, r%d", a->a, a->b)
 129INSN(sflts,  "r%d, r%d", a->a, a->b)
 130INSN(sfles,  "r%d, r%d", a->a, a->b)
 131INSN(sfeqi,  "r%d, %d", a->a, a->i)
 132INSN(sfnei,  "r%d, %d", a->a, a->i)
 133INSN(sfgtui, "r%d, %d", a->a, a->i)
 134INSN(sfgeui, "r%d, %d", a->a, a->i)
 135INSN(sfltui, "r%d, %d", a->a, a->i)
 136INSN(sfleui, "r%d, %d", a->a, a->i)
 137INSN(sfgtsi, "r%d, %d", a->a, a->i)
 138INSN(sfgesi, "r%d, %d", a->a, a->i)
 139INSN(sfltsi, "r%d, %d", a->a, a->i)
 140INSN(sflesi, "r%d, %d", a->a, a->i)
 141INSN(sys,    "%d", a->k)
 142INSN(trap,   "%d", a->k)
 143INSN(msync,  "")
 144INSN(psync,  "")
 145INSN(csync,  "")
 146INSN(rfe,    "")
 147
 148#define FP_INSN(opcode, suffix, format, ...)                            \
 149static bool trans_lf_##opcode##_##suffix(disassemble_info *info,        \
 150                                         arg_lf_##opcode##_##suffix *a) \
 151{                                                                       \
 152    output("lf." #opcode "." #suffix, format, ##__VA_ARGS__);           \
 153    return true;                                                        \
 154}
 155
 156FP_INSN(add, s,  "r%d, r%d, r%d", a->d, a->a, a->b)
 157FP_INSN(sub, s,  "r%d, r%d, r%d", a->d, a->a, a->b)
 158FP_INSN(mul, s,  "r%d, r%d, r%d", a->d, a->a, a->b)
 159FP_INSN(div, s,  "r%d, r%d, r%d", a->d, a->a, a->b)
 160FP_INSN(rem, s,  "r%d, r%d, r%d", a->d, a->a, a->b)
 161FP_INSN(itof, s, "r%d, r%d", a->d, a->a)
 162FP_INSN(ftoi, s, "r%d, r%d", a->d, a->a)
 163FP_INSN(madd, s, "r%d, r%d, r%d", a->d, a->a, a->b)
 164FP_INSN(sfeq, s, "r%d, r%d", a->a, a->b)
 165FP_INSN(sfne, s, "r%d, r%d", a->a, a->b)
 166FP_INSN(sfgt, s, "r%d, r%d", a->a, a->b)
 167FP_INSN(sfge, s, "r%d, r%d", a->a, a->b)
 168FP_INSN(sflt, s, "r%d, r%d", a->a, a->b)
 169FP_INSN(sfle, s, "r%d, r%d", a->a, a->b)
 170FP_INSN(sfun, s, "r%d, r%d", a->a, a->b)
 171FP_INSN(sfueq, s, "r%d, r%d", a->a, a->b)
 172FP_INSN(sfuge, s, "r%d, r%d", a->a, a->b)
 173FP_INSN(sfugt, s, "r%d, r%d", a->a, a->b)
 174FP_INSN(sfule, s, "r%d, r%d", a->a, a->b)
 175FP_INSN(sfult, s, "r%d, r%d", a->a, a->b)
 176
 177FP_INSN(add, d,  "r%d,r%d, r%d,r%d, r%d,r%d",
 178        a->d, a->d + a->dp + 1,
 179        a->a, a->a + a->ap + 1,
 180        a->b, a->b + a->bp + 1)
 181FP_INSN(sub, d,  "r%d,r%d, r%d,r%d, r%d,r%d",
 182        a->d, a->d + a->dp + 1,
 183        a->a, a->a + a->ap + 1,
 184        a->b, a->b + a->bp + 1)
 185FP_INSN(mul, d,  "r%d,r%d, r%d,r%d, r%d,r%d",
 186        a->d, a->d + a->dp + 1,
 187        a->a, a->a + a->ap + 1,
 188        a->b, a->b + a->bp + 1)
 189FP_INSN(div, d,  "r%d,r%d, r%d,r%d, r%d,r%d",
 190        a->d, a->d + a->dp + 1,
 191        a->a, a->a + a->ap + 1,
 192        a->b, a->b + a->bp + 1)
 193FP_INSN(rem, d,  "r%d,r%d, r%d,r%d, r%d,r%d",
 194        a->d, a->d + a->dp + 1,
 195        a->a, a->a + a->ap + 1,
 196        a->b, a->b + a->bp + 1)
 197FP_INSN(madd, d, "r%d,r%d, r%d,r%d, r%d,r%d",
 198        a->d, a->d + a->dp + 1,
 199        a->a, a->a + a->ap + 1,
 200        a->b, a->b + a->bp + 1)
 201
 202FP_INSN(itof, d, "r%d,r%d, r%d,r%d",
 203        a->d, a->d + a->dp + 1,
 204        a->a, a->a + a->ap + 1)
 205FP_INSN(ftoi, d, "r%d,r%d, r%d,r%d",
 206        a->d, a->d + a->dp + 1,
 207        a->a, a->a + a->ap + 1)
 208
 209FP_INSN(stod, d, "r%d,r%d, r%d",
 210        a->d, a->d + a->dp + 1, a->a)
 211FP_INSN(dtos, d, "r%d r%d,r%d",
 212        a->d, a->a, a->a + a->ap + 1)
 213
 214FP_INSN(sfeq, d, "r%d,r%d, r%d,r%d",
 215        a->a, a->a + a->ap + 1,
 216        a->b, a->b + a->bp + 1)
 217FP_INSN(sfne, d, "r%d,r%d, r%d,r%d",
 218        a->a, a->a + a->ap + 1,
 219        a->b, a->b + a->bp + 1)
 220FP_INSN(sfgt, d, "r%d,r%d, r%d,r%d",
 221        a->a, a->a + a->ap + 1,
 222        a->b, a->b + a->bp + 1)
 223FP_INSN(sfge, d, "r%d,r%d, r%d,r%d",
 224        a->a, a->a + a->ap + 1,
 225        a->b, a->b + a->bp + 1)
 226FP_INSN(sflt, d, "r%d,r%d, r%d,r%d",
 227        a->a, a->a + a->ap + 1,
 228        a->b, a->b + a->bp + 1)
 229FP_INSN(sfle, d, "r%d,r%d, r%d,r%d",
 230        a->a, a->a + a->ap + 1,
 231        a->b, a->b + a->bp + 1)
 232FP_INSN(sfun, d, "r%d,r%d, r%d,r%d",
 233        a->a, a->a + a->ap + 1,
 234        a->b, a->b + a->bp + 1)
 235FP_INSN(sfueq, d, "r%d,r%d, r%d,r%d",
 236        a->a, a->a + a->ap + 1,
 237        a->b, a->b + a->bp + 1)
 238FP_INSN(sfuge, d, "r%d,r%d, r%d,r%d",
 239        a->a, a->a + a->ap + 1,
 240        a->b, a->b + a->bp + 1)
 241FP_INSN(sfugt, d, "r%d,r%d, r%d,r%d",
 242        a->a, a->a + a->ap + 1,
 243        a->b, a->b + a->bp + 1)
 244FP_INSN(sfule, d, "r%d,r%d, r%d,r%d",
 245        a->a, a->a + a->ap + 1,
 246        a->b, a->b + a->bp + 1)
 247FP_INSN(sfult, d, "r%d,r%d, r%d,r%d",
 248        a->a, a->a + a->ap + 1,
 249        a->b, a->b + a->bp + 1)
 250