1999-04-16 09:35:26 +08:00
|
|
|
|
/* Tracing support for CGEN-based simulators.
|
2024-01-12 23:30:44 +08:00
|
|
|
|
Copyright (C) 1996-2024 Free Software Foundation, Inc.
|
1999-04-16 09:35:26 +08:00
|
|
|
|
Contributed by Cygnus Support.
|
|
|
|
|
|
|
|
|
|
This file is part of GDB, the GNU debugger.
|
|
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU General Public License as published by
|
2007-08-24 22:30:15 +08:00
|
|
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
1999-04-16 09:35:26 +08:00
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
2007-08-24 22:30:15 +08:00
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
1999-04-16 09:35:26 +08:00
|
|
|
|
|
2021-05-02 06:05:23 +08:00
|
|
|
|
/* This must come before any other includes. */
|
|
|
|
|
#include "defs.h"
|
|
|
|
|
|
1999-04-16 09:35:26 +08:00
|
|
|
|
#include <errno.h>
|
2021-12-05 10:04:41 +08:00
|
|
|
|
#include <stdarg.h>
|
2021-01-09 15:43:54 +08:00
|
|
|
|
#include <stdlib.h>
|
2021-12-05 09:24:55 +08:00
|
|
|
|
|
|
|
|
|
#include "bfd.h"
|
2021-06-27 11:11:48 +08:00
|
|
|
|
#include "diagnostics.h"
|
1999-04-16 09:35:26 +08:00
|
|
|
|
#include "dis-asm.h"
|
2021-12-05 09:24:55 +08:00
|
|
|
|
|
1999-04-16 09:35:26 +08:00
|
|
|
|
#include "sim-main.h"
|
2000-12-24 05:52:14 +08:00
|
|
|
|
#include "sim-fpu.h"
|
2021-06-14 10:14:40 +08:00
|
|
|
|
#include "sim/callback.h"
|
1999-04-16 09:35:26 +08:00
|
|
|
|
|
|
|
|
|
#ifndef SIZE_INSTRUCTION
|
|
|
|
|
#define SIZE_INSTRUCTION 16
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifndef SIZE_LOCATION
|
|
|
|
|
#define SIZE_LOCATION 20
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifndef SIZE_PC
|
|
|
|
|
#define SIZE_PC 6
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifndef SIZE_LINE_NUMBER
|
|
|
|
|
#define SIZE_LINE_NUMBER 4
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifndef SIZE_CYCLE_COUNT
|
|
|
|
|
#define SIZE_CYCLE_COUNT 2
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifndef SIZE_TOTAL_CYCLE_COUNT
|
|
|
|
|
#define SIZE_TOTAL_CYCLE_COUNT 9
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifndef SIZE_TRACE_BUF
|
1999-12-07 11:56:43 +08:00
|
|
|
|
#define SIZE_TRACE_BUF 1024
|
1999-04-16 09:35:26 +08:00
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* Text is queued in TRACE_BUF because we want to output the insn's cycle
|
|
|
|
|
count first but that isn't known until after the insn has executed.
|
|
|
|
|
This also handles the queueing of trace results, TRACE_RESULT may be
|
|
|
|
|
called multiple times for one insn. */
|
|
|
|
|
static char trace_buf[SIZE_TRACE_BUF];
|
|
|
|
|
/* If NULL, output to stdout directly. */
|
|
|
|
|
static char *bufptr;
|
|
|
|
|
|
|
|
|
|
/* Non-zero if this is the first insn in a set of parallel insns. */
|
|
|
|
|
static int first_insn_p;
|
|
|
|
|
|
2015-06-12 15:44:02 +08:00
|
|
|
|
/* For communication between cgen_trace_insn and cgen_trace_result. */
|
1999-04-16 09:35:26 +08:00
|
|
|
|
static int printed_result_p;
|
|
|
|
|
|
|
|
|
|
/* Insn and its extracted fields.
|
2015-06-12 15:44:02 +08:00
|
|
|
|
Set by cgen_trace_insn, used by cgen_trace_insn_fini.
|
1999-04-16 09:35:26 +08:00
|
|
|
|
??? Move to SIM_CPU to support heterogeneous multi-cpu case. */
|
|
|
|
|
static const struct cgen_insn *current_insn;
|
|
|
|
|
static const struct argbuf *current_abuf;
|
|
|
|
|
|
|
|
|
|
void
|
2015-06-12 15:44:02 +08:00
|
|
|
|
cgen_trace_insn_init (SIM_CPU *cpu, int first_p)
|
1999-04-16 09:35:26 +08:00
|
|
|
|
{
|
|
|
|
|
bufptr = trace_buf;
|
|
|
|
|
*bufptr = 0;
|
|
|
|
|
first_insn_p = first_p;
|
|
|
|
|
|
2015-06-12 15:44:02 +08:00
|
|
|
|
/* Set to NULL so cgen_trace_insn_fini can know if cgen_trace_insn was
|
|
|
|
|
called. */
|
1999-04-16 09:35:26 +08:00
|
|
|
|
current_insn = NULL;
|
|
|
|
|
current_abuf = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2015-06-12 15:44:02 +08:00
|
|
|
|
cgen_trace_insn_fini (SIM_CPU *cpu, const struct argbuf *abuf, int last_p)
|
1999-04-16 09:35:26 +08:00
|
|
|
|
{
|
|
|
|
|
SIM_DESC sd = CPU_STATE (cpu);
|
|
|
|
|
|
|
|
|
|
/* Was insn traced? It might not be if trace ranges are in effect. */
|
|
|
|
|
if (current_insn == NULL)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
/* The first thing printed is current and total cycle counts. */
|
|
|
|
|
|
|
|
|
|
if (PROFILE_MODEL_P (cpu)
|
|
|
|
|
&& ARGBUF_PROFILE_P (current_abuf))
|
|
|
|
|
{
|
|
|
|
|
unsigned long total = PROFILE_MODEL_TOTAL_CYCLES (CPU_PROFILE_DATA (cpu));
|
|
|
|
|
unsigned long this_insn = PROFILE_MODEL_CUR_INSN_CYCLES (CPU_PROFILE_DATA (cpu));
|
|
|
|
|
|
|
|
|
|
if (last_p)
|
|
|
|
|
{
|
|
|
|
|
trace_printf (sd, cpu, "%-*ld %-*ld ",
|
|
|
|
|
SIZE_CYCLE_COUNT, this_insn,
|
|
|
|
|
SIZE_TOTAL_CYCLE_COUNT, total);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
trace_printf (sd, cpu, "%-*ld %-*s ",
|
|
|
|
|
SIZE_CYCLE_COUNT, this_insn,
|
|
|
|
|
SIZE_TOTAL_CYCLE_COUNT, "---");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Print the disassembled insn. */
|
|
|
|
|
|
|
|
|
|
trace_printf (sd, cpu, "%s", TRACE_PREFIX (CPU_TRACE_DATA (cpu)));
|
|
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
|
/* Print insn results. */
|
|
|
|
|
{
|
|
|
|
|
const CGEN_OPINST *opinst = CGEN_INSN_OPERANDS (current_insn);
|
|
|
|
|
|
|
|
|
|
if (opinst)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
int indices[MAX_OPERAND_INSTANCES];
|
|
|
|
|
|
|
|
|
|
/* Fetch the operands used by the insn. */
|
|
|
|
|
/* FIXME: Add fn ptr to CGEN_CPU_DESC. */
|
|
|
|
|
CGEN_SYM (get_insn_operands) (CPU_CPU_DESC (cpu), current_insn,
|
|
|
|
|
0, CGEN_FIELDS_BITSIZE (&insn_fields),
|
|
|
|
|
indices);
|
|
|
|
|
|
|
|
|
|
for (i = 0;
|
|
|
|
|
CGEN_OPINST_TYPE (opinst) != CGEN_OPINST_END;
|
|
|
|
|
++i, ++opinst)
|
|
|
|
|
{
|
|
|
|
|
if (CGEN_OPINST_TYPE (opinst) == CGEN_OPINST_OUTPUT)
|
2015-06-12 15:44:02 +08:00
|
|
|
|
cgen_trace_result (cpu, current_insn, opinst, indices[i]);
|
1999-04-16 09:35:26 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* Print anything else requested. */
|
|
|
|
|
|
|
|
|
|
if (*trace_buf)
|
|
|
|
|
trace_printf (sd, cpu, " %s\n", trace_buf);
|
|
|
|
|
else
|
|
|
|
|
trace_printf (sd, cpu, "\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2015-06-12 15:44:02 +08:00
|
|
|
|
cgen_trace_insn (SIM_CPU *cpu, const struct cgen_insn *opcode,
|
|
|
|
|
const struct argbuf *abuf, IADDR pc)
|
1999-04-16 09:35:26 +08:00
|
|
|
|
{
|
|
|
|
|
char disasm_buf[50];
|
|
|
|
|
|
|
|
|
|
printed_result_p = 0;
|
|
|
|
|
current_insn = opcode;
|
|
|
|
|
current_abuf = abuf;
|
|
|
|
|
|
|
|
|
|
if (CGEN_INSN_VIRTUAL_P (opcode))
|
|
|
|
|
{
|
|
|
|
|
trace_prefix (CPU_STATE (cpu), cpu, NULL_CIA, pc, 0,
|
2021-02-01 06:31:25 +08:00
|
|
|
|
NULL, 0, "%s", CGEN_INSN_NAME (opcode));
|
1999-04-16 09:35:26 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CPU_DISASSEMBLER (cpu) (cpu, opcode, abuf, pc, disasm_buf);
|
|
|
|
|
trace_prefix (CPU_STATE (cpu), cpu, NULL_CIA, pc, TRACE_LINENUM_P (cpu),
|
|
|
|
|
NULL, 0,
|
|
|
|
|
"%s%-*s",
|
|
|
|
|
first_insn_p ? " " : "|",
|
|
|
|
|
SIZE_INSTRUCTION, disasm_buf);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2021-06-27 10:55:53 +08:00
|
|
|
|
cgen_trace_extract (SIM_CPU *cpu, IADDR pc, const char *name, ...)
|
1999-04-16 09:35:26 +08:00
|
|
|
|
{
|
|
|
|
|
va_list args;
|
|
|
|
|
int printed_one_p = 0;
|
2021-06-27 10:55:53 +08:00
|
|
|
|
const char *fmt;
|
1999-04-16 09:35:26 +08:00
|
|
|
|
|
|
|
|
|
va_start (args, name);
|
|
|
|
|
|
|
|
|
|
trace_printf (CPU_STATE (cpu), cpu, "Extract: 0x%.*lx: %s ",
|
2009-11-23 06:29:28 +08:00
|
|
|
|
SIZE_PC, (unsigned long) pc, name);
|
1999-04-16 09:35:26 +08:00
|
|
|
|
|
|
|
|
|
do {
|
|
|
|
|
int type,ival;
|
|
|
|
|
|
2021-06-27 10:55:53 +08:00
|
|
|
|
fmt = va_arg (args, const char *);
|
1999-04-16 09:35:26 +08:00
|
|
|
|
|
|
|
|
|
if (fmt)
|
|
|
|
|
{
|
|
|
|
|
if (printed_one_p)
|
|
|
|
|
trace_printf (CPU_STATE (cpu), cpu, ", ");
|
|
|
|
|
printed_one_p = 1;
|
|
|
|
|
type = va_arg (args, int);
|
|
|
|
|
switch (type)
|
|
|
|
|
{
|
|
|
|
|
case 'x' :
|
|
|
|
|
ival = va_arg (args, int);
|
2021-06-27 11:11:48 +08:00
|
|
|
|
DIAGNOSTIC_PUSH
|
|
|
|
|
DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL
|
1999-04-16 09:35:26 +08:00
|
|
|
|
trace_printf (CPU_STATE (cpu), cpu, fmt, ival);
|
2021-06-27 11:11:48 +08:00
|
|
|
|
DIAGNOSTIC_POP
|
1999-04-16 09:35:26 +08:00
|
|
|
|
break;
|
|
|
|
|
default :
|
|
|
|
|
abort ();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} while (fmt);
|
|
|
|
|
|
|
|
|
|
va_end (args);
|
|
|
|
|
trace_printf (CPU_STATE (cpu), cpu, "\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2021-06-27 10:55:53 +08:00
|
|
|
|
cgen_trace_result (SIM_CPU *cpu, const char *name, int type, ...)
|
1999-04-16 09:35:26 +08:00
|
|
|
|
{
|
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
|
|
va_start (args, type);
|
|
|
|
|
if (printed_result_p)
|
|
|
|
|
cgen_trace_printf (cpu, ", ");
|
|
|
|
|
|
|
|
|
|
switch (type)
|
|
|
|
|
{
|
|
|
|
|
case 'x' :
|
|
|
|
|
default :
|
|
|
|
|
cgen_trace_printf (cpu, "%s <- 0x%x", name, va_arg (args, int));
|
|
|
|
|
break;
|
2000-12-24 05:52:14 +08:00
|
|
|
|
case 'f':
|
|
|
|
|
{
|
|
|
|
|
DI di;
|
|
|
|
|
sim_fpu f;
|
|
|
|
|
|
|
|
|
|
/* this is separated from previous line for sunos cc */
|
|
|
|
|
di = va_arg (args, DI);
|
|
|
|
|
sim_fpu_64to (&f, di);
|
|
|
|
|
|
|
|
|
|
cgen_trace_printf (cpu, "%s <- ", name);
|
|
|
|
|
sim_fpu_printn_fpu (&f, (sim_fpu_print_func *) cgen_trace_printf, 4, cpu);
|
|
|
|
|
break;
|
|
|
|
|
}
|
1999-04-16 09:35:26 +08:00
|
|
|
|
case 'D' :
|
|
|
|
|
{
|
|
|
|
|
DI di;
|
|
|
|
|
/* this is separated from previous line for sunos cc */
|
|
|
|
|
di = va_arg (args, DI);
|
|
|
|
|
cgen_trace_printf (cpu, "%s <- 0x%x%08x", name,
|
|
|
|
|
GETHIDI(di), GETLODI (di));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
printed_result_p = 1;
|
|
|
|
|
va_end (args);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Print trace output to BUFPTR if active, otherwise print normally.
|
|
|
|
|
This is only for tracing semantic code. */
|
|
|
|
|
|
|
|
|
|
void
|
2021-06-27 10:55:53 +08:00
|
|
|
|
cgen_trace_printf (SIM_CPU *cpu, const char *fmt, ...)
|
1999-04-16 09:35:26 +08:00
|
|
|
|
{
|
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
|
|
va_start (args, fmt);
|
|
|
|
|
|
|
|
|
|
if (bufptr == NULL)
|
|
|
|
|
{
|
|
|
|
|
if (TRACE_FILE (CPU_TRACE_DATA (cpu)) == NULL)
|
|
|
|
|
(* STATE_CALLBACK (CPU_STATE (cpu))->evprintf_filtered)
|
|
|
|
|
(STATE_CALLBACK (CPU_STATE (cpu)), fmt, args);
|
|
|
|
|
else
|
|
|
|
|
vfprintf (TRACE_FILE (CPU_TRACE_DATA (cpu)), fmt, args);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
vsprintf (bufptr, fmt, args);
|
|
|
|
|
bufptr += strlen (bufptr);
|
|
|
|
|
/* ??? Need version of SIM_ASSERT that is always enabled. */
|
|
|
|
|
if (bufptr - trace_buf > SIZE_TRACE_BUF)
|
|
|
|
|
abort ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
va_end (args);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Disassembly support. */
|
|
|
|
|
|
|
|
|
|
/* sprintf to a "stream" */
|
|
|
|
|
|
|
|
|
|
int
|
2014-01-05 12:43:21 +08:00
|
|
|
|
sim_disasm_sprintf (SFILE *f, const char *format, ...)
|
1999-04-16 09:35:26 +08:00
|
|
|
|
{
|
|
|
|
|
int n;
|
|
|
|
|
va_list args;
|
|
|
|
|
|
2014-01-05 12:46:15 +08:00
|
|
|
|
va_start (args, format);
|
1999-04-16 09:35:26 +08:00
|
|
|
|
vsprintf (f->current, format, args);
|
|
|
|
|
f->current += n = strlen (f->current);
|
|
|
|
|
va_end (args);
|
|
|
|
|
return n;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-05 05:38:04 +08:00
|
|
|
|
/* sprintf to a "stream" with styling. */
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
sim_disasm_styled_sprintf (SFILE *f, enum disassembler_style style,
|
|
|
|
|
const char *format, ...)
|
|
|
|
|
{
|
|
|
|
|
int n;
|
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
|
|
va_start (args, format);
|
|
|
|
|
vsprintf (f->current, format, args);
|
|
|
|
|
f->current += n = strlen (f->current);
|
|
|
|
|
va_end (args);
|
|
|
|
|
return n;
|
|
|
|
|
}
|
|
|
|
|
|
1999-04-16 09:35:26 +08:00
|
|
|
|
/* Memory read support for an opcodes disassembler. */
|
|
|
|
|
|
|
|
|
|
int
|
2003-06-21 01:27:10 +08:00
|
|
|
|
sim_disasm_read_memory (bfd_vma memaddr, bfd_byte *myaddr, unsigned int length,
|
1999-04-16 09:35:26 +08:00
|
|
|
|
struct disassemble_info *info)
|
|
|
|
|
{
|
|
|
|
|
SIM_CPU *cpu = (SIM_CPU *) info->application_data;
|
|
|
|
|
SIM_DESC sd = CPU_STATE (cpu);
|
2003-06-21 01:27:10 +08:00
|
|
|
|
unsigned length_read;
|
1999-04-16 09:35:26 +08:00
|
|
|
|
|
|
|
|
|
length_read = sim_core_read_buffer (sd, cpu, read_map, myaddr, memaddr,
|
|
|
|
|
length);
|
|
|
|
|
if (length_read != length)
|
|
|
|
|
return EIO;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Memory error support for an opcodes disassembler. */
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
sim_disasm_perror_memory (int status, bfd_vma memaddr,
|
|
|
|
|
struct disassemble_info *info)
|
|
|
|
|
{
|
|
|
|
|
if (status != EIO)
|
|
|
|
|
/* Can't happen. */
|
|
|
|
|
info->fprintf_func (info->stream, "Unknown error %d.", status);
|
|
|
|
|
else
|
|
|
|
|
/* Actually, address between memaddr and memaddr + len was
|
|
|
|
|
out of bounds. */
|
|
|
|
|
info->fprintf_func (info->stream,
|
2022-08-04 11:18:05 +08:00
|
|
|
|
"Address 0x%" PRIx64 " is out of bounds.",
|
|
|
|
|
(uint64_t) memaddr);
|
1999-04-16 09:35:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Disassemble using the CGEN opcode table.
|
|
|
|
|
??? While executing an instruction, the insn has been decoded and all its
|
|
|
|
|
fields have been extracted. It is certainly possible to do the disassembly
|
|
|
|
|
with that data. This seems simpler, but maybe in the future the already
|
|
|
|
|
extracted fields will be used. */
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
sim_cgen_disassemble_insn (SIM_CPU *cpu, const CGEN_INSN *insn,
|
|
|
|
|
const ARGBUF *abuf, IADDR pc, char *buf)
|
|
|
|
|
{
|
|
|
|
|
unsigned int length;
|
2000-08-29 02:18:49 +08:00
|
|
|
|
unsigned int base_length;
|
1999-04-16 09:35:26 +08:00
|
|
|
|
unsigned long insn_value;
|
|
|
|
|
struct disassemble_info disasm_info;
|
|
|
|
|
SFILE sfile;
|
|
|
|
|
union {
|
2021-12-06 15:29:47 +08:00
|
|
|
|
uint8_t bytes[CGEN_MAX_INSN_SIZE];
|
|
|
|
|
uint16_t shorts[8];
|
|
|
|
|
uint32_t words[4];
|
1999-04-16 09:35:26 +08:00
|
|
|
|
} insn_buf;
|
|
|
|
|
SIM_DESC sd = CPU_STATE (cpu);
|
|
|
|
|
CGEN_CPU_DESC cd = CPU_CPU_DESC (cpu);
|
|
|
|
|
CGEN_EXTRACT_INFO ex_info;
|
|
|
|
|
CGEN_FIELDS *fields = alloca (CGEN_CPU_SIZEOF_FIELDS (cd));
|
|
|
|
|
int insn_bit_length = CGEN_INSN_BITSIZE (insn);
|
|
|
|
|
int insn_length = insn_bit_length / 8;
|
|
|
|
|
|
|
|
|
|
sfile.buffer = sfile.current = buf;
|
|
|
|
|
INIT_DISASSEMBLE_INFO (disasm_info, (FILE *) &sfile,
|
2022-04-05 05:38:04 +08:00
|
|
|
|
(fprintf_ftype) sim_disasm_sprintf,
|
|
|
|
|
(fprintf_styled_ftype) sim_disasm_styled_sprintf);
|
1999-04-16 09:35:26 +08:00
|
|
|
|
disasm_info.endian =
|
|
|
|
|
(bfd_big_endian (STATE_PROG_BFD (sd)) ? BFD_ENDIAN_BIG
|
|
|
|
|
: bfd_little_endian (STATE_PROG_BFD (sd)) ? BFD_ENDIAN_LITTLE
|
|
|
|
|
: BFD_ENDIAN_UNKNOWN);
|
|
|
|
|
|
|
|
|
|
length = sim_core_read_buffer (sd, cpu, read_map, &insn_buf, pc,
|
|
|
|
|
insn_length);
|
|
|
|
|
|
2000-10-09 06:37:14 +08:00
|
|
|
|
if (length != insn_length)
|
|
|
|
|
{
|
2021-05-02 10:29:50 +08:00
|
|
|
|
sim_io_error (sd, "unable to read address %" PRIxTA, pc);
|
2000-10-09 06:37:14 +08:00
|
|
|
|
}
|
|
|
|
|
|
2000-08-29 02:18:49 +08:00
|
|
|
|
/* If the entire insn will fit into an integer, then do it. Otherwise, just
|
|
|
|
|
use the bits of the base_insn. */
|
|
|
|
|
if (insn_bit_length <= 32)
|
|
|
|
|
base_length = insn_bit_length;
|
|
|
|
|
else
|
|
|
|
|
base_length = min (cd->base_insn_bitsize, insn_bit_length);
|
|
|
|
|
switch (base_length)
|
1999-04-16 09:35:26 +08:00
|
|
|
|
{
|
|
|
|
|
case 0 : return; /* fake insn, typically "compile" (aka "invalid") */
|
1999-04-27 02:34:20 +08:00
|
|
|
|
case 8 : insn_value = insn_buf.bytes[0]; break;
|
|
|
|
|
case 16 : insn_value = T2H_2 (insn_buf.shorts[0]); break;
|
|
|
|
|
case 32 : insn_value = T2H_4 (insn_buf.words[0]); break;
|
1999-04-16 09:35:26 +08:00
|
|
|
|
default: abort ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
disasm_info.buffer_vma = pc;
|
|
|
|
|
disasm_info.buffer = insn_buf.bytes;
|
|
|
|
|
disasm_info.buffer_length = length;
|
|
|
|
|
|
2022-05-10 21:27:13 +08:00
|
|
|
|
ex_info.dis_info = &disasm_info;
|
1999-04-16 09:35:26 +08:00
|
|
|
|
ex_info.valid = (1 << length) - 1;
|
|
|
|
|
ex_info.insn_bytes = insn_buf.bytes;
|
|
|
|
|
|
|
|
|
|
length = (*CGEN_EXTRACT_FN (cd, insn)) (cd, insn, &ex_info, insn_value, fields, pc);
|
|
|
|
|
/* Result of extract fn is in bits. */
|
|
|
|
|
/* ??? This assumes that each instruction has a fixed length (and thus
|
|
|
|
|
for insns with multiple versions of variable lengths they would each
|
|
|
|
|
have their own table entry). */
|
|
|
|
|
if (length == insn_bit_length)
|
|
|
|
|
{
|
|
|
|
|
(*CGEN_PRINT_FN (cd, insn)) (cd, &disasm_info, insn, fields, pc, length);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* This shouldn't happen, but aborting is too drastic. */
|
|
|
|
|
strcpy (buf, "***unknown***");
|
|
|
|
|
}
|
|
|
|
|
}
|