2000-01-25 02:40:50 +00:00
|
|
|
/* Simulator for Motorola's MCore processor
|
2015-01-01 09:32:14 +00:00
|
|
|
Copyright (C) 1999-2015 Free Software Foundation, Inc.
|
1999-04-27 01:33:01 +00:00
|
|
|
Contributed by Cygnus Solutions.
|
|
|
|
|
|
|
|
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 14:30:15 +00:00
|
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
1999-04-27 01:33:01 +00: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 14:30:15 +00: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-27 01:33:01 +00:00
|
|
|
|
2012-05-20 05:34:23 +00:00
|
|
|
#include "config.h"
|
1999-04-27 01:33:01 +00:00
|
|
|
#include <signal.h>
|
2015-02-19 09:09:54 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
1999-04-27 01:33:01 +00:00
|
|
|
#include <sys/times.h>
|
|
|
|
#include <sys/param.h>
|
2015-02-11 13:39:01 +00:00
|
|
|
#include <unistd.h>
|
1999-04-27 01:33:01 +00:00
|
|
|
#include "bfd.h"
|
2002-06-09 15:45:54 +00:00
|
|
|
#include "gdb/callback.h"
|
1999-04-27 01:33:01 +00:00
|
|
|
#include "libiberty.h"
|
2002-06-09 15:45:54 +00:00
|
|
|
#include "gdb/remote-sim.h"
|
1999-04-27 01:33:01 +00:00
|
|
|
|
2015-03-29 07:53:01 +00:00
|
|
|
#include "sim-main.h"
|
|
|
|
#include "sim-base.h"
|
2015-06-15 15:24:21 +00:00
|
|
|
#include "sim-syscall.h"
|
2015-03-29 07:53:01 +00:00
|
|
|
#include "sim-options.h"
|
|
|
|
|
|
|
|
#define target_big_endian (CURRENT_TARGET_BYTE_ORDER == BIG_ENDIAN)
|
1999-04-27 01:33:01 +00:00
|
|
|
|
|
|
|
|
2015-03-16 06:26:48 +00:00
|
|
|
static unsigned long
|
|
|
|
mcore_extract_unsigned_integer (unsigned char *addr, int len)
|
1999-04-27 01:33:01 +00:00
|
|
|
{
|
|
|
|
unsigned long retval;
|
|
|
|
unsigned char * p;
|
|
|
|
unsigned char * startaddr = (unsigned char *)addr;
|
|
|
|
unsigned char * endaddr = startaddr + len;
|
2015-03-16 06:23:02 +00:00
|
|
|
|
1999-04-27 01:33:01 +00:00
|
|
|
if (len > (int) sizeof (unsigned long))
|
2015-03-16 06:26:48 +00:00
|
|
|
printf ("That operation is not available on integers of more than %zu bytes.",
|
1999-04-27 01:33:01 +00:00
|
|
|
sizeof (unsigned long));
|
2015-03-16 06:23:02 +00:00
|
|
|
|
1999-04-27 01:33:01 +00:00
|
|
|
/* Start at the most significant end of the integer, and work towards
|
|
|
|
the least significant. */
|
|
|
|
retval = 0;
|
1999-05-11 13:35:55 +00:00
|
|
|
|
2000-02-10 21:59:03 +00:00
|
|
|
if (! target_big_endian)
|
|
|
|
{
|
|
|
|
for (p = endaddr; p > startaddr;)
|
|
|
|
retval = (retval << 8) | * -- p;
|
|
|
|
}
|
|
|
|
else
|
1999-05-11 13:35:55 +00:00
|
|
|
{
|
|
|
|
for (p = startaddr; p < endaddr;)
|
|
|
|
retval = (retval << 8) | * p ++;
|
|
|
|
}
|
2015-03-16 06:23:02 +00:00
|
|
|
|
1999-04-27 01:33:01 +00:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2015-03-16 06:26:48 +00:00
|
|
|
static void
|
|
|
|
mcore_store_unsigned_integer (unsigned char *addr, int len, unsigned long val)
|
1999-04-27 01:33:01 +00:00
|
|
|
{
|
|
|
|
unsigned char * p;
|
|
|
|
unsigned char * startaddr = (unsigned char *)addr;
|
|
|
|
unsigned char * endaddr = startaddr + len;
|
1999-05-11 13:35:55 +00:00
|
|
|
|
2000-02-10 21:59:03 +00:00
|
|
|
if (! target_big_endian)
|
|
|
|
{
|
|
|
|
for (p = startaddr; p < endaddr;)
|
|
|
|
{
|
|
|
|
* p ++ = val & 0xff;
|
|
|
|
val >>= 8;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
1999-04-27 01:33:01 +00:00
|
|
|
{
|
1999-05-11 13:35:55 +00:00
|
|
|
for (p = endaddr; p > startaddr;)
|
|
|
|
{
|
|
|
|
* -- p = val & 0xff;
|
|
|
|
val >>= 8;
|
|
|
|
}
|
1999-04-27 01:33:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-29 07:53:01 +00:00
|
|
|
static int memcycles = 1;
|
1999-04-27 01:33:01 +00:00
|
|
|
|
2015-11-15 08:42:33 +00:00
|
|
|
#define gr cpu->active_gregs
|
|
|
|
#define cr cpu->regs.cregs
|
|
|
|
#define sr cr[0]
|
|
|
|
#define vbr cr[1]
|
|
|
|
#define esr cr[2]
|
|
|
|
#define fsr cr[3]
|
|
|
|
#define epc cr[4]
|
|
|
|
#define fpc cr[5]
|
|
|
|
#define ss0 cr[6]
|
|
|
|
#define ss1 cr[7]
|
|
|
|
#define ss2 cr[8]
|
|
|
|
#define ss3 cr[9]
|
|
|
|
#define ss4 cr[10]
|
|
|
|
#define gcr cr[11]
|
|
|
|
#define gsr cr[12]
|
1999-04-27 01:33:01 +00:00
|
|
|
|
|
|
|
/* maniuplate the carry bit */
|
2015-11-15 08:42:33 +00:00
|
|
|
#define C_ON() (sr & 1)
|
|
|
|
#define C_VALUE() (sr & 1)
|
|
|
|
#define C_OFF() ((sr & 1) == 0)
|
|
|
|
#define SET_C() {sr |= 1;}
|
|
|
|
#define CLR_C() {sr &= 0xfffffffe;}
|
|
|
|
#define NEW_C(v) {CLR_C(); sr |= ((v) & 1);}
|
|
|
|
|
|
|
|
#define SR_AF() ((sr >> 1) & 1)
|
|
|
|
static void set_active_regs (SIM_CPU *cpu)
|
|
|
|
{
|
|
|
|
if (SR_AF())
|
|
|
|
cpu->active_gregs = cpu->regs.alt_gregs;
|
|
|
|
else
|
|
|
|
cpu->active_gregs = cpu->regs.gregs;
|
|
|
|
}
|
1999-04-27 01:33:01 +00:00
|
|
|
|
|
|
|
#define TRAPCODE 1 /* r1 holds which function we want */
|
|
|
|
#define PARM1 2 /* first parameter */
|
|
|
|
#define PARM2 3
|
|
|
|
#define PARM3 4
|
|
|
|
#define PARM4 5
|
|
|
|
#define RET1 2 /* register for return values. */
|
|
|
|
|
2000-03-02 22:42:51 +00:00
|
|
|
/* Default to a 8 Mbyte (== 2^23) memory space. */
|
2015-04-21 06:55:29 +00:00
|
|
|
#define DEFAULT_MEMORY_SIZE 0x800000
|
1999-04-27 01:33:01 +00:00
|
|
|
|
|
|
|
static void
|
2015-11-15 08:42:33 +00:00
|
|
|
set_initial_gprs (SIM_CPU *cpu)
|
1999-04-27 01:33:01 +00:00
|
|
|
{
|
|
|
|
/* Set up machine just out of reset. */
|
2015-11-15 08:42:33 +00:00
|
|
|
CPU_PC_SET (cpu, 0);
|
|
|
|
sr = 0;
|
2015-03-16 06:23:02 +00:00
|
|
|
|
1999-04-27 01:33:01 +00:00
|
|
|
/* Clean out the GPRs and alternate GPRs. */
|
2015-11-15 08:42:33 +00:00
|
|
|
memset (&cpu->regs.gregs, 0, sizeof(cpu->regs.gregs));
|
|
|
|
memset (&cpu->regs.alt_gregs, 0, sizeof(cpu->regs.alt_gregs));
|
2015-03-16 06:23:02 +00:00
|
|
|
|
1999-04-27 01:33:01 +00:00
|
|
|
/* Make our register set point to the right place. */
|
2015-11-15 08:42:33 +00:00
|
|
|
set_active_regs (cpu);
|
2015-03-16 06:23:02 +00:00
|
|
|
|
1999-04-27 01:33:01 +00:00
|
|
|
/* ABI specifies initial values for these registers. */
|
2015-11-15 08:42:33 +00:00
|
|
|
gr[0] = DEFAULT_MEMORY_SIZE - 4;
|
2015-03-16 06:23:02 +00:00
|
|
|
|
1999-04-27 01:33:01 +00:00
|
|
|
/* dac fix, the stack address must be 8-byte aligned! */
|
2015-11-15 08:42:33 +00:00
|
|
|
gr[0] = gr[0] - gr[0] % 8;
|
|
|
|
gr[PARM1] = 0;
|
|
|
|
gr[PARM2] = 0;
|
|
|
|
gr[PARM3] = 0;
|
|
|
|
gr[PARM4] = gr[0];
|
1999-04-27 01:33:01 +00:00
|
|
|
}
|
|
|
|
|
2015-04-21 06:30:21 +00:00
|
|
|
/* Simulate a monitor trap. */
|
|
|
|
|
1999-04-27 01:33:01 +00:00
|
|
|
static void
|
2015-11-15 08:42:33 +00:00
|
|
|
handle_trap1 (SIM_DESC sd, SIM_CPU *cpu)
|
1999-04-27 01:33:01 +00:00
|
|
|
{
|
2015-04-21 06:30:21 +00:00
|
|
|
/* XXX: We don't pass back the actual errno value. */
|
2015-11-15 08:42:33 +00:00
|
|
|
gr[RET1] = sim_syscall (cpu, gr[TRAPCODE], gr[PARM1], gr[PARM2], gr[PARM3],
|
|
|
|
gr[PARM4]);
|
1999-04-27 01:33:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2015-11-15 08:42:33 +00:00
|
|
|
process_stub (SIM_DESC sd, SIM_CPU *cpu, int what)
|
1999-04-27 01:33:01 +00:00
|
|
|
{
|
|
|
|
/* These values should match those in libgloss/mcore/syscalls.s. */
|
|
|
|
switch (what)
|
|
|
|
{
|
|
|
|
case 3: /* _read */
|
1999-05-11 13:35:55 +00:00
|
|
|
case 4: /* _write */
|
1999-04-27 01:33:01 +00:00
|
|
|
case 5: /* _open */
|
|
|
|
case 6: /* _close */
|
|
|
|
case 10: /* _unlink */
|
|
|
|
case 19: /* _lseek */
|
|
|
|
case 43: /* _times */
|
2015-11-15 08:42:33 +00:00
|
|
|
gr[TRAPCODE] = what;
|
|
|
|
handle_trap1 (sd, cpu);
|
1999-04-27 01:33:01 +00:00
|
|
|
break;
|
2015-03-16 06:23:02 +00:00
|
|
|
|
1999-04-27 01:33:01 +00:00
|
|
|
default:
|
2015-04-21 06:55:29 +00:00
|
|
|
if (STATE_VERBOSE_P (sd))
|
1999-04-27 01:33:01 +00:00
|
|
|
fprintf (stderr, "Unhandled stub opcode: %d\n", what);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2015-11-15 08:42:33 +00:00
|
|
|
util (SIM_DESC sd, SIM_CPU *cpu, unsigned what)
|
1999-04-27 01:33:01 +00:00
|
|
|
{
|
|
|
|
switch (what)
|
|
|
|
{
|
|
|
|
case 0: /* exit */
|
2015-11-15 08:42:33 +00:00
|
|
|
sim_engine_halt (sd, cpu, NULL, cpu->regs.pc, sim_exited, gr[PARM1]);
|
1999-04-27 01:33:01 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 1: /* printf */
|
2015-04-21 06:55:29 +00:00
|
|
|
if (STATE_VERBOSE_P (sd))
|
|
|
|
fprintf (stderr, "WARNING: printf unimplemented\n");
|
1999-04-27 01:33:01 +00:00
|
|
|
break;
|
2015-03-16 06:23:02 +00:00
|
|
|
|
1999-04-27 01:33:01 +00:00
|
|
|
case 2: /* scanf */
|
2015-04-21 06:55:29 +00:00
|
|
|
if (STATE_VERBOSE_P (sd))
|
1999-04-27 01:33:01 +00:00
|
|
|
fprintf (stderr, "WARNING: scanf unimplemented\n");
|
|
|
|
break;
|
2015-03-16 06:23:02 +00:00
|
|
|
|
1999-04-27 01:33:01 +00:00
|
|
|
case 3: /* utime */
|
2015-11-15 08:42:33 +00:00
|
|
|
gr[RET1] = cpu->insts;
|
1999-04-27 01:33:01 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0xFF:
|
2015-11-15 08:42:33 +00:00
|
|
|
process_stub (sd, cpu, gr[1]);
|
1999-04-27 01:33:01 +00:00
|
|
|
break;
|
2015-03-16 06:23:02 +00:00
|
|
|
|
1999-04-27 01:33:01 +00:00
|
|
|
default:
|
2015-04-21 06:55:29 +00:00
|
|
|
if (STATE_VERBOSE_P (sd))
|
1999-04-27 01:33:01 +00:00
|
|
|
fprintf (stderr, "Unhandled util code: %x\n", what);
|
|
|
|
break;
|
|
|
|
}
|
2015-03-16 06:23:02 +00:00
|
|
|
}
|
1999-04-27 01:33:01 +00:00
|
|
|
|
|
|
|
/* For figuring out whether we carried; addc/subc use this. */
|
|
|
|
static int
|
2015-03-16 06:26:48 +00:00
|
|
|
iu_carry (unsigned long a, unsigned long b, int cin)
|
1999-04-27 01:33:01 +00:00
|
|
|
{
|
|
|
|
unsigned long x;
|
2015-03-16 06:23:02 +00:00
|
|
|
|
1999-04-27 01:33:01 +00:00
|
|
|
x = (a & 0xffff) + (b & 0xffff) + cin;
|
|
|
|
x = (x >> 16) + (a >> 16) + (b >> 16);
|
|
|
|
x >>= 16;
|
|
|
|
|
|
|
|
return (x != 0);
|
|
|
|
}
|
|
|
|
|
2015-04-21 06:50:38 +00:00
|
|
|
/* TODO: Convert to common watchpoints. */
|
|
|
|
#undef WATCHFUNCTIONS
|
1999-04-27 01:33:01 +00:00
|
|
|
#ifdef WATCHFUNCTIONS
|
|
|
|
|
|
|
|
#define MAXWL 80
|
|
|
|
word WL[MAXWL];
|
|
|
|
char * WLstr[MAXWL];
|
|
|
|
|
|
|
|
int ENDWL=0;
|
|
|
|
int WLincyc;
|
|
|
|
int WLcyc[MAXWL];
|
|
|
|
int WLcnts[MAXWL];
|
|
|
|
int WLmax[MAXWL];
|
|
|
|
int WLmin[MAXWL];
|
|
|
|
word WLendpc;
|
|
|
|
int WLbcyc;
|
|
|
|
int WLW;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define RD (inst & 0xF)
|
|
|
|
#define RS ((inst >> 4) & 0xF)
|
|
|
|
#define RX ((inst >> 8) & 0xF)
|
|
|
|
#define IMM5 ((inst >> 4) & 0x1F)
|
|
|
|
#define IMM4 ((inst) & 0xF)
|
|
|
|
|
2015-11-15 08:42:33 +00:00
|
|
|
#define rbat(X) sim_core_read_1 (cpu, 0, read_map, X)
|
|
|
|
#define rhat(X) sim_core_read_2 (cpu, 0, read_map, X)
|
|
|
|
#define rlat(X) sim_core_read_4 (cpu, 0, read_map, X)
|
|
|
|
#define wbat(X, D) sim_core_write_1 (cpu, 0, write_map, X, D)
|
|
|
|
#define what(X, D) sim_core_write_2 (cpu, 0, write_map, X, D)
|
|
|
|
#define wlat(X, D) sim_core_write_4 (cpu, 0, write_map, X, D)
|
2015-04-21 06:55:29 +00:00
|
|
|
|
1999-04-27 01:33:01 +00:00
|
|
|
static int tracing = 0;
|
|
|
|
|
2015-11-15 08:09:32 +00:00
|
|
|
#define ILLEGAL() \
|
2015-11-15 08:42:33 +00:00
|
|
|
sim_engine_halt (sd, cpu, NULL, pc, sim_stopped, SIM_SIGILL)
|
2015-11-15 08:09:32 +00:00
|
|
|
|
|
|
|
static void
|
2015-11-15 08:42:33 +00:00
|
|
|
step_once (SIM_DESC sd, SIM_CPU *cpu)
|
1999-04-27 01:33:01 +00:00
|
|
|
{
|
|
|
|
int needfetch;
|
|
|
|
word ibuf;
|
|
|
|
word pc;
|
|
|
|
unsigned short inst;
|
|
|
|
int memops;
|
|
|
|
int bonus_cycles;
|
|
|
|
int insts;
|
|
|
|
int w;
|
|
|
|
int cycs;
|
2015-04-21 06:50:38 +00:00
|
|
|
#ifdef WATCHFUNCTIONS
|
1999-04-27 01:33:01 +00:00
|
|
|
word WLhash;
|
2015-04-21 06:50:38 +00:00
|
|
|
#endif
|
1999-04-27 01:33:01 +00:00
|
|
|
|
2015-11-15 08:42:33 +00:00
|
|
|
pc = CPU_PC_GET (cpu);
|
1999-04-27 01:33:01 +00:00
|
|
|
|
1999-05-11 13:35:55 +00:00
|
|
|
/* Fetch the initial instructions that we'll decode. */
|
1999-04-27 01:33:01 +00:00
|
|
|
ibuf = rlat (pc & 0xFFFFFFFC);
|
|
|
|
needfetch = 0;
|
|
|
|
|
|
|
|
memops = 0;
|
|
|
|
bonus_cycles = 0;
|
|
|
|
insts = 0;
|
2015-03-16 06:23:02 +00:00
|
|
|
|
1999-04-27 01:33:01 +00:00
|
|
|
/* make our register set point to the right place */
|
2015-11-15 08:42:33 +00:00
|
|
|
set_active_regs (cpu);
|
2015-03-16 06:23:02 +00:00
|
|
|
|
2015-04-21 06:50:38 +00:00
|
|
|
#ifdef WATCHFUNCTIONS
|
1999-04-27 01:33:01 +00:00
|
|
|
/* make a hash to speed exec loop, hope it's nonzero */
|
|
|
|
WLhash = 0xFFFFFFFF;
|
|
|
|
|
|
|
|
for (w = 1; w <= ENDWL; w++)
|
|
|
|
WLhash = WLhash & WL[w];
|
2015-04-21 06:50:38 +00:00
|
|
|
#endif
|
1999-04-27 01:33:01 +00:00
|
|
|
|
2015-11-15 08:09:32 +00:00
|
|
|
/* TODO: Unindent this block. */
|
1999-04-27 01:33:01 +00:00
|
|
|
{
|
1999-05-11 13:35:55 +00:00
|
|
|
word oldpc;
|
2015-03-16 06:23:02 +00:00
|
|
|
|
1999-04-27 01:33:01 +00:00
|
|
|
insts ++;
|
2015-03-16 06:23:02 +00:00
|
|
|
|
1999-04-27 01:33:01 +00:00
|
|
|
if (pc & 02)
|
|
|
|
{
|
2000-02-10 21:59:03 +00:00
|
|
|
if (! target_big_endian)
|
|
|
|
inst = ibuf >> 16;
|
|
|
|
else
|
1999-05-11 13:35:55 +00:00
|
|
|
inst = ibuf & 0xFFFF;
|
1999-04-27 01:33:01 +00:00
|
|
|
needfetch = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2000-02-10 21:59:03 +00:00
|
|
|
if (! target_big_endian)
|
|
|
|
inst = ibuf & 0xFFFF;
|
|
|
|
else
|
1999-05-11 13:35:55 +00:00
|
|
|
inst = ibuf >> 16;
|
1999-04-27 01:33:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef WATCHFUNCTIONS
|
|
|
|
/* now scan list of watch addresses, if match, count it and
|
|
|
|
note return address and count cycles until pc=return address */
|
2015-03-16 06:23:02 +00:00
|
|
|
|
1999-04-27 01:33:01 +00:00
|
|
|
if ((WLincyc == 1) && (pc == WLendpc))
|
|
|
|
{
|
2015-11-15 08:42:33 +00:00
|
|
|
cycs = (cpu->cycles + (insts + bonus_cycles +
|
1999-04-27 01:33:01 +00:00
|
|
|
(memops * memcycles)) - WLbcyc);
|
2015-03-16 06:23:02 +00:00
|
|
|
|
1999-04-27 01:33:01 +00:00
|
|
|
if (WLcnts[WLW] == 1)
|
|
|
|
{
|
|
|
|
WLmax[WLW] = cycs;
|
|
|
|
WLmin[WLW] = cycs;
|
|
|
|
WLcyc[WLW] = 0;
|
|
|
|
}
|
2015-03-16 06:23:02 +00:00
|
|
|
|
1999-04-27 01:33:01 +00:00
|
|
|
if (cycs > WLmax[WLW])
|
|
|
|
{
|
|
|
|
WLmax[WLW] = cycs;
|
|
|
|
}
|
2015-03-16 06:23:02 +00:00
|
|
|
|
1999-04-27 01:33:01 +00:00
|
|
|
if (cycs < WLmin[WLW])
|
|
|
|
{
|
|
|
|
WLmin[WLW] = cycs;
|
|
|
|
}
|
2015-03-16 06:23:02 +00:00
|
|
|
|
1999-04-27 01:33:01 +00:00
|
|
|
WLcyc[WLW] += cycs;
|
|
|
|
WLincyc = 0;
|
|
|
|
WLendpc = 0;
|
2015-03-16 06:23:02 +00:00
|
|
|
}
|
1999-04-27 01:33:01 +00:00
|
|
|
|
1999-05-11 13:35:55 +00:00
|
|
|
/* Optimize with a hash to speed loop. */
|
1999-04-27 01:33:01 +00:00
|
|
|
if (WLincyc == 0)
|
|
|
|
{
|
|
|
|
if ((WLhash == 0) || ((WLhash & pc) != 0))
|
|
|
|
{
|
|
|
|
for (w=1; w <= ENDWL; w++)
|
|
|
|
{
|
|
|
|
if (pc == WL[w])
|
|
|
|
{
|
|
|
|
WLcnts[w]++;
|
2015-11-15 08:42:33 +00:00
|
|
|
WLbcyc = cpu->cycles + insts
|
1999-04-27 01:33:01 +00:00
|
|
|
+ bonus_cycles + (memops * memcycles);
|
2015-11-15 08:42:33 +00:00
|
|
|
WLendpc = gr[15];
|
1999-04-27 01:33:01 +00:00
|
|
|
WLincyc = 1;
|
|
|
|
WLW = w;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (tracing)
|
2015-04-21 07:05:57 +00:00
|
|
|
fprintf (stderr, "%.4lx: inst = %.4x ", pc, inst);
|
1999-05-11 13:35:55 +00:00
|
|
|
|
|
|
|
oldpc = pc;
|
2015-03-16 06:23:02 +00:00
|
|
|
|
1999-04-27 01:33:01 +00:00
|
|
|
pc += 2;
|
2015-03-16 06:23:02 +00:00
|
|
|
|
1999-04-27 01:33:01 +00:00
|
|
|
switch (inst >> 8)
|
|
|
|
{
|
|
|
|
case 0x00:
|
|
|
|
switch RS
|
|
|
|
{
|
|
|
|
case 0x0:
|
|
|
|
switch RD
|
|
|
|
{
|
|
|
|
case 0x0: /* bkpt */
|
1999-05-19 19:58:41 +00:00
|
|
|
pc -= 2;
|
2015-11-15 08:42:33 +00:00
|
|
|
sim_engine_halt (sd, cpu, NULL, pc - 2,
|
2015-11-15 08:09:32 +00:00
|
|
|
sim_stopped, SIM_SIGTRAP);
|
1999-04-27 01:33:01 +00:00
|
|
|
break;
|
2015-03-16 06:23:02 +00:00
|
|
|
|
1999-04-27 01:33:01 +00:00
|
|
|
case 0x1: /* sync */
|
|
|
|
break;
|
2015-03-16 06:23:02 +00:00
|
|
|
|
1999-04-27 01:33:01 +00:00
|
|
|
case 0x2: /* rte */
|
2015-11-15 08:42:33 +00:00
|
|
|
pc = epc;
|
|
|
|
sr = esr;
|
1999-04-27 01:33:01 +00:00
|
|
|
needfetch = 1;
|
2015-03-16 06:23:02 +00:00
|
|
|
|
2015-11-15 08:42:33 +00:00
|
|
|
set_active_regs (cpu);
|
1999-04-27 01:33:01 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x3: /* rfi */
|
2015-11-15 08:42:33 +00:00
|
|
|
pc = fpc;
|
|
|
|
sr = fsr;
|
1999-04-27 01:33:01 +00:00
|
|
|
needfetch = 1;
|
|
|
|
|
2015-11-15 08:42:33 +00:00
|
|
|
set_active_regs (cpu);
|
1999-04-27 01:33:01 +00:00
|
|
|
break;
|
2015-03-16 06:23:02 +00:00
|
|
|
|
1999-04-27 01:33:01 +00:00
|
|
|
case 0x4: /* stop */
|
2015-04-21 06:55:29 +00:00
|
|
|
if (STATE_VERBOSE_P (sd))
|
1999-04-27 01:33:01 +00:00
|
|
|
fprintf (stderr, "WARNING: stop unimplemented\n");
|
|
|
|
break;
|
2015-03-16 06:23:02 +00:00
|
|
|
|
1999-04-27 01:33:01 +00:00
|
|
|
case 0x5: /* wait */
|
2015-04-21 06:55:29 +00:00
|
|
|
if (STATE_VERBOSE_P (sd))
|
1999-04-27 01:33:01 +00:00
|
|
|
fprintf (stderr, "WARNING: wait unimplemented\n");
|
|
|
|
break;
|
2015-03-16 06:23:02 +00:00
|
|
|
|
1999-04-27 01:33:01 +00:00
|
|
|
case 0x6: /* doze */
|
2015-04-21 06:55:29 +00:00
|
|
|
if (STATE_VERBOSE_P (sd))
|
1999-05-11 13:35:55 +00:00
|
|
|
fprintf (stderr, "WARNING: doze unimplemented\n");
|
1999-04-27 01:33:01 +00:00
|
|
|
break;
|
2015-03-16 06:23:02 +00:00
|
|
|
|
1999-04-27 01:33:01 +00:00
|
|
|
case 0x7:
|
2015-11-15 08:09:32 +00:00
|
|
|
ILLEGAL (); /* illegal */
|
1999-04-27 01:33:01 +00:00
|
|
|
break;
|
2015-03-16 06:23:02 +00:00
|
|
|
|
1999-04-27 01:33:01 +00:00
|
|
|
case 0x8: /* trap 0 */
|
|
|
|
case 0xA: /* trap 2 */
|
|
|
|
case 0xB: /* trap 3 */
|
2015-11-15 08:42:33 +00:00
|
|
|
sim_engine_halt (sd, cpu, NULL, pc,
|
2015-11-15 08:09:32 +00:00
|
|
|
sim_stopped, SIM_SIGTRAP);
|
1999-04-27 01:33:01 +00:00
|
|
|
break;
|
2015-03-16 06:23:02 +00:00
|
|
|
|
1999-04-27 01:33:01 +00:00
|
|
|
case 0xC: /* trap 4 */
|
|
|
|
case 0xD: /* trap 5 */
|
|
|
|
case 0xE: /* trap 6 */
|
2015-11-15 08:09:32 +00:00
|
|
|
ILLEGAL (); /* illegal */
|
1999-04-27 01:33:01 +00:00
|
|
|
break;
|
2015-03-16 06:23:02 +00:00
|
|
|
|
1999-04-27 01:33:01 +00:00
|
|
|
case 0xF: /* trap 7 */
|
2015-11-15 08:42:33 +00:00
|
|
|
sim_engine_halt (sd, cpu, NULL, pc, /* integer div-by-0 */
|
2015-11-15 08:09:32 +00:00
|
|
|
sim_stopped, SIM_SIGTRAP);
|
1999-04-27 01:33:01 +00:00
|
|
|
break;
|
2015-03-16 06:23:02 +00:00
|
|
|
|
1999-04-27 01:33:01 +00:00
|
|
|
case 0x9: /* trap 1 */
|
2015-11-15 08:42:33 +00:00
|
|
|
handle_trap1 (sd, cpu);
|
1999-04-27 01:33:01 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2015-03-16 06:23:02 +00:00
|
|
|
|
1999-04-27 01:33:01 +00:00
|
|
|
case 0x1:
|
2015-11-15 08:09:32 +00:00
|
|
|
ILLEGAL (); /* illegal */
|
1999-04-27 01:33:01 +00:00
|
|
|
break;
|
2015-03-16 06:23:02 +00:00
|
|
|
|
1999-04-27 01:33:01 +00:00
|
|
|
case 0x2: /* mvc */
|
2015-11-15 08:42:33 +00:00
|
|
|
gr[RD] = C_VALUE();
|
1999-04-27 01:33:01 +00:00
|
|
|
break;
|
|
|
|
case 0x3: /* mvcv */
|
2015-11-15 08:42:33 +00:00
|
|
|
gr[RD] = C_OFF();
|
1999-04-27 01:33:01 +00:00
|
|
|
break;
|
|
|
|
case 0x4: /* ldq */
|
|
|
|
{
|
2015-11-15 08:42:33 +00:00
|
|
|
word addr = gr[RD];
|
1999-04-27 01:33:01 +00:00
|
|
|
int regno = 4; /* always r4-r7 */
|
2015-03-16 06:23:02 +00:00
|
|
|
|
1999-04-27 01:33:01 +00:00
|
|
|
bonus_cycles++;
|
|
|
|
memops += 4;
|
|
|
|
do
|
|
|
|
{
|
2015-11-15 08:42:33 +00:00
|
|
|
gr[regno] = rlat (addr);
|
1999-04-27 01:33:01 +00:00
|
|
|
addr += 4;
|
|
|
|
regno++;
|
|
|
|
}
|
|
|
|
while ((regno&0x3) != 0);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0x5: /* stq */
|
|
|
|
{
|
2015-11-15 08:42:33 +00:00
|
|
|
word addr = gr[RD];
|
1999-04-27 01:33:01 +00:00
|
|
|
int regno = 4; /* always r4-r7 */
|
2015-03-16 06:23:02 +00:00
|
|
|
|
1999-04-27 01:33:01 +00:00
|
|
|
memops += 4;
|
|
|
|
bonus_cycles++;
|
|
|
|
do
|
|
|
|
{
|
2015-11-15 08:42:33 +00:00
|
|
|
wlat (addr, gr[regno]);
|
1999-04-27 01:33:01 +00:00
|
|
|
addr += 4;
|
|
|
|
regno++;
|
|
|
|
}
|
|
|
|
while ((regno & 0x3) != 0);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0x6: /* ldm */
|
|
|
|
{
|
2015-11-15 08:42:33 +00:00
|
|
|
word addr = gr[0];
|
1999-04-27 01:33:01 +00:00
|
|
|
int regno = RD;
|
2015-03-16 06:23:02 +00:00
|
|
|
|
1999-04-27 01:33:01 +00:00
|
|
|
/* bonus cycle is really only needed if
|
|
|
|
the next insn shifts the last reg loaded.
|
2015-03-16 06:23:02 +00:00
|
|
|
|
1999-04-27 01:33:01 +00:00
|
|
|
bonus_cycles++;
|
|
|
|
*/
|
|
|
|
memops += 16-regno;
|
|
|
|
while (regno <= 0xF)
|
|
|
|
{
|
2015-11-15 08:42:33 +00:00
|
|
|
gr[regno] = rlat (addr);
|
1999-04-27 01:33:01 +00:00
|
|
|
addr += 4;
|
|
|
|
regno++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0x7: /* stm */
|
|
|
|
{
|
2015-11-15 08:42:33 +00:00
|
|
|
word addr = gr[0];
|
1999-04-27 01:33:01 +00:00
|
|
|
int regno = RD;
|
2015-03-16 06:23:02 +00:00
|
|
|
|
1999-04-27 01:33:01 +00:00
|
|
|
/* this should be removed! */
|
|
|
|
/* bonus_cycles ++; */
|
|
|
|
|
|
|
|
memops += 16 - regno;
|
|
|
|
while (regno <= 0xF)
|
|
|
|
{
|
2015-11-15 08:42:33 +00:00
|
|
|
wlat (addr, gr[regno]);
|
1999-04-27 01:33:01 +00:00
|
|
|
addr += 4;
|
|
|
|
regno++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x8: /* dect */
|
2015-11-15 08:42:33 +00:00
|
|
|
gr[RD] -= C_VALUE();
|
1999-04-27 01:33:01 +00:00
|
|
|
break;
|
|
|
|
case 0x9: /* decf */
|
2015-11-15 08:42:33 +00:00
|
|
|
gr[RD] -= C_OFF();
|
1999-04-27 01:33:01 +00:00
|
|
|
break;
|
|
|
|
case 0xA: /* inct */
|
2015-11-15 08:42:33 +00:00
|
|
|
gr[RD] += C_VALUE();
|
1999-04-27 01:33:01 +00:00
|
|
|
break;
|
|
|
|
case 0xB: /* incf */
|
2015-11-15 08:42:33 +00:00
|
|
|
gr[RD] += C_OFF();
|
1999-04-27 01:33:01 +00:00
|
|
|
break;
|
|
|
|
case 0xC: /* jmp */
|
2015-11-15 08:42:33 +00:00
|
|
|
pc = gr[RD];
|
1999-05-25 18:09:09 +00:00
|
|
|
if (tracing && RD == 15)
|
2015-04-21 07:05:57 +00:00
|
|
|
fprintf (stderr, "Func return, r2 = %lxx, r3 = %lx\n",
|
2015-11-15 08:42:33 +00:00
|
|
|
gr[2], gr[3]);
|
1999-04-27 01:33:01 +00:00
|
|
|
bonus_cycles++;
|
|
|
|
needfetch = 1;
|
|
|
|
break;
|
|
|
|
case 0xD: /* jsr */
|
2015-11-15 08:42:33 +00:00
|
|
|
gr[15] = pc;
|
|
|
|
pc = gr[RD];
|
1999-04-27 01:33:01 +00:00
|
|
|
bonus_cycles++;
|
|
|
|
needfetch = 1;
|
|
|
|
break;
|
|
|
|
case 0xE: /* ff1 */
|
|
|
|
{
|
|
|
|
word tmp, i;
|
2015-11-15 08:42:33 +00:00
|
|
|
tmp = gr[RD];
|
1999-04-27 01:33:01 +00:00
|
|
|
for (i = 0; !(tmp & 0x80000000) && i < 32; i++)
|
|
|
|
tmp <<= 1;
|
2015-11-15 08:42:33 +00:00
|
|
|
gr[RD] = i;
|
1999-04-27 01:33:01 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0xF: /* brev */
|
|
|
|
{
|
|
|
|
word tmp;
|
2015-11-15 08:42:33 +00:00
|
|
|
tmp = gr[RD];
|
1999-04-27 01:33:01 +00:00
|
|
|
tmp = ((tmp & 0xaaaaaaaa) >> 1) | ((tmp & 0x55555555) << 1);
|
|
|
|
tmp = ((tmp & 0xcccccccc) >> 2) | ((tmp & 0x33333333) << 2);
|
|
|
|
tmp = ((tmp & 0xf0f0f0f0) >> 4) | ((tmp & 0x0f0f0f0f) << 4);
|
|
|
|
tmp = ((tmp & 0xff00ff00) >> 8) | ((tmp & 0x00ff00ff) << 8);
|
2015-11-15 08:42:33 +00:00
|
|
|
gr[RD] = ((tmp & 0xffff0000) >> 16) | ((tmp & 0x0000ffff) << 16);
|
1999-04-27 01:33:01 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0x01:
|
|
|
|
switch RS
|
|
|
|
{
|
2015-03-16 06:23:02 +00:00
|
|
|
case 0x0: /* xtrb3 */
|
2015-11-15 08:42:33 +00:00
|
|
|
gr[1] = (gr[RD]) & 0xFF;
|
|
|
|
NEW_C (gr[RD] != 0);
|
1999-04-27 01:33:01 +00:00
|
|
|
break;
|
|
|
|
case 0x1: /* xtrb2 */
|
2015-11-15 08:42:33 +00:00
|
|
|
gr[1] = (gr[RD]>>8) & 0xFF;
|
|
|
|
NEW_C (gr[RD] != 0);
|
1999-04-27 01:33:01 +00:00
|
|
|
break;
|
|
|
|
case 0x2: /* xtrb1 */
|
2015-11-15 08:42:33 +00:00
|
|
|
gr[1] = (gr[RD]>>16) & 0xFF;
|
|
|
|
NEW_C (gr[RD] != 0);
|
1999-04-27 01:33:01 +00:00
|
|
|
break;
|
|
|
|
case 0x3: /* xtrb0 */
|
2015-11-15 08:42:33 +00:00
|
|
|
gr[1] = (gr[RD]>>24) & 0xFF;
|
|
|
|
NEW_C (gr[RD] != 0);
|
1999-04-27 01:33:01 +00:00
|
|
|
break;
|
|
|
|
case 0x4: /* zextb */
|
2015-11-15 08:42:33 +00:00
|
|
|
gr[RD] &= 0x000000FF;
|
1999-04-27 01:33:01 +00:00
|
|
|
break;
|
|
|
|
case 0x5: /* sextb */
|
|
|
|
{
|
|
|
|
long tmp;
|
2015-11-15 08:42:33 +00:00
|
|
|
tmp = gr[RD];
|
1999-04-27 01:33:01 +00:00
|
|
|
tmp <<= 24;
|
|
|
|
tmp >>= 24;
|
2015-11-15 08:42:33 +00:00
|
|
|
gr[RD] = tmp;
|
1999-04-27 01:33:01 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0x6: /* zexth */
|
2015-11-15 08:42:33 +00:00
|
|
|
gr[RD] &= 0x0000FFFF;
|
1999-04-27 01:33:01 +00:00
|
|
|
break;
|
|
|
|
case 0x7: /* sexth */
|
|
|
|
{
|
|
|
|
long tmp;
|
2015-11-15 08:42:33 +00:00
|
|
|
tmp = gr[RD];
|
1999-04-27 01:33:01 +00:00
|
|
|
tmp <<= 16;
|
|
|
|
tmp >>= 16;
|
2015-11-15 08:42:33 +00:00
|
|
|
gr[RD] = tmp;
|
1999-04-27 01:33:01 +00:00
|
|
|
}
|
|
|
|
break;
|
2015-03-16 06:23:02 +00:00
|
|
|
case 0x8: /* declt */
|
2015-11-15 08:42:33 +00:00
|
|
|
--gr[RD];
|
|
|
|
NEW_C ((long)gr[RD] < 0);
|
1999-04-27 01:33:01 +00:00
|
|
|
break;
|
|
|
|
case 0x9: /* tstnbz */
|
|
|
|
{
|
2015-11-15 08:42:33 +00:00
|
|
|
word tmp = gr[RD];
|
1999-04-27 01:33:01 +00:00
|
|
|
NEW_C ((tmp & 0xFF000000) != 0 &&
|
|
|
|
(tmp & 0x00FF0000) != 0 && (tmp & 0x0000FF00) != 0 &&
|
|
|
|
(tmp & 0x000000FF) != 0);
|
|
|
|
}
|
2015-03-16 06:23:02 +00:00
|
|
|
break;
|
1999-04-27 01:33:01 +00:00
|
|
|
case 0xA: /* decgt */
|
2015-11-15 08:42:33 +00:00
|
|
|
--gr[RD];
|
|
|
|
NEW_C ((long)gr[RD] > 0);
|
1999-04-27 01:33:01 +00:00
|
|
|
break;
|
|
|
|
case 0xB: /* decne */
|
2015-11-15 08:42:33 +00:00
|
|
|
--gr[RD];
|
|
|
|
NEW_C ((long)gr[RD] != 0);
|
1999-04-27 01:33:01 +00:00
|
|
|
break;
|
|
|
|
case 0xC: /* clrt */
|
|
|
|
if (C_ON())
|
2015-11-15 08:42:33 +00:00
|
|
|
gr[RD] = 0;
|
1999-04-27 01:33:01 +00:00
|
|
|
break;
|
|
|
|
case 0xD: /* clrf */
|
|
|
|
if (C_OFF())
|
2015-11-15 08:42:33 +00:00
|
|
|
gr[RD] = 0;
|
1999-04-27 01:33:01 +00:00
|
|
|
break;
|
|
|
|
case 0xE: /* abs */
|
2015-11-15 08:42:33 +00:00
|
|
|
if (gr[RD] & 0x80000000)
|
|
|
|
gr[RD] = ~gr[RD] + 1;
|
1999-04-27 01:33:01 +00:00
|
|
|
break;
|
|
|
|
case 0xF: /* not */
|
2015-11-15 08:42:33 +00:00
|
|
|
gr[RD] = ~gr[RD];
|
1999-04-27 01:33:01 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0x02: /* movt */
|
|
|
|
if (C_ON())
|
2015-11-15 08:42:33 +00:00
|
|
|
gr[RD] = gr[RS];
|
1999-04-27 01:33:01 +00:00
|
|
|
break;
|
|
|
|
case 0x03: /* mult */
|
|
|
|
/* consume 2 bits per cycle from rs, until rs is 0 */
|
|
|
|
{
|
2015-11-15 08:42:33 +00:00
|
|
|
unsigned int t = gr[RS];
|
1999-04-27 01:33:01 +00:00
|
|
|
int ticks;
|
2015-03-16 06:23:02 +00:00
|
|
|
for (ticks = 0; t != 0 ; t >>= 2)
|
1999-04-27 01:33:01 +00:00
|
|
|
ticks++;
|
|
|
|
bonus_cycles += ticks;
|
|
|
|
}
|
|
|
|
bonus_cycles += 2; /* min. is 3, so add 2, plus ticks above */
|
1999-05-25 18:09:09 +00:00
|
|
|
if (tracing)
|
2015-04-21 07:05:57 +00:00
|
|
|
fprintf (stderr, " mult %lx by %lx to give %lx",
|
2015-11-15 08:42:33 +00:00
|
|
|
gr[RD], gr[RS], gr[RD] * gr[RS]);
|
|
|
|
gr[RD] = gr[RD] * gr[RS];
|
1999-04-27 01:33:01 +00:00
|
|
|
break;
|
|
|
|
case 0x04: /* loopt */
|
|
|
|
if (C_ON())
|
|
|
|
{
|
|
|
|
pc += (IMM4 << 1) - 32;
|
|
|
|
bonus_cycles ++;
|
|
|
|
needfetch = 1;
|
|
|
|
}
|
2015-11-15 08:42:33 +00:00
|
|
|
--gr[RS]; /* not RD! */
|
|
|
|
NEW_C (((long)gr[RS]) > 0);
|
2015-03-16 06:23:02 +00:00
|
|
|
break;
|
1999-04-27 01:33:01 +00:00
|
|
|
case 0x05: /* subu */
|
2015-11-15 08:42:33 +00:00
|
|
|
gr[RD] -= gr[RS];
|
1999-04-27 01:33:01 +00:00
|
|
|
break;
|
|
|
|
case 0x06: /* addc */
|
|
|
|
{
|
|
|
|
unsigned long tmp, a, b;
|
2015-11-15 08:42:33 +00:00
|
|
|
a = gr[RD];
|
|
|
|
b = gr[RS];
|
|
|
|
gr[RD] = a + b + C_VALUE ();
|
1999-04-27 01:33:01 +00:00
|
|
|
tmp = iu_carry (a, b, C_VALUE ());
|
|
|
|
NEW_C (tmp);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0x07: /* subc */
|
|
|
|
{
|
|
|
|
unsigned long tmp, a, b;
|
2015-11-15 08:42:33 +00:00
|
|
|
a = gr[RD];
|
|
|
|
b = gr[RS];
|
|
|
|
gr[RD] = a - b + C_VALUE () - 1;
|
1999-04-27 01:33:01 +00:00
|
|
|
tmp = iu_carry (a,~b, C_VALUE ());
|
|
|
|
NEW_C (tmp);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0x08: /* illegal */
|
|
|
|
case 0x09: /* illegal*/
|
2015-11-15 08:09:32 +00:00
|
|
|
ILLEGAL ();
|
1999-04-27 01:33:01 +00:00
|
|
|
break;
|
|
|
|
case 0x0A: /* movf */
|
|
|
|
if (C_OFF())
|
2015-11-15 08:42:33 +00:00
|
|
|
gr[RD] = gr[RS];
|
1999-04-27 01:33:01 +00:00
|
|
|
break;
|
|
|
|
case 0x0B: /* lsr */
|
2015-03-16 06:23:02 +00:00
|
|
|
{
|
1999-04-27 01:33:01 +00:00
|
|
|
unsigned long dst, src;
|
2015-11-15 08:42:33 +00:00
|
|
|
dst = gr[RD];
|
|
|
|
src = gr[RS];
|
2000-01-18 00:55:13 +00:00
|
|
|
/* We must not rely solely upon the native shift operations, since they
|
|
|
|
may not match the M*Core's behaviour on boundary conditions. */
|
|
|
|
dst = src > 31 ? 0 : dst >> src;
|
2015-11-15 08:42:33 +00:00
|
|
|
gr[RD] = dst;
|
1999-04-27 01:33:01 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0x0C: /* cmphs */
|
2015-11-15 08:42:33 +00:00
|
|
|
NEW_C ((unsigned long )gr[RD] >=
|
|
|
|
(unsigned long)gr[RS]);
|
1999-04-27 01:33:01 +00:00
|
|
|
break;
|
|
|
|
case 0x0D: /* cmplt */
|
2015-11-15 08:42:33 +00:00
|
|
|
NEW_C ((long)gr[RD] < (long)gr[RS]);
|
1999-04-27 01:33:01 +00:00
|
|
|
break;
|
|
|
|
case 0x0E: /* tst */
|
2015-11-15 08:42:33 +00:00
|
|
|
NEW_C ((gr[RD] & gr[RS]) != 0);
|
1999-04-27 01:33:01 +00:00
|
|
|
break;
|
|
|
|
case 0x0F: /* cmpne */
|
2015-11-15 08:42:33 +00:00
|
|
|
NEW_C (gr[RD] != gr[RS]);
|
1999-04-27 01:33:01 +00:00
|
|
|
break;
|
|
|
|
case 0x10: case 0x11: /* mfcr */
|
|
|
|
{
|
|
|
|
unsigned r;
|
|
|
|
r = IMM5;
|
|
|
|
if (r <= LAST_VALID_CREG)
|
2015-11-15 08:42:33 +00:00
|
|
|
gr[RD] = cr[r];
|
1999-04-27 01:33:01 +00:00
|
|
|
else
|
2015-11-15 08:09:32 +00:00
|
|
|
ILLEGAL ();
|
1999-04-27 01:33:01 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x12: /* mov */
|
2015-11-15 08:42:33 +00:00
|
|
|
gr[RD] = gr[RS];
|
1999-05-25 18:09:09 +00:00
|
|
|
if (tracing)
|
2015-11-15 08:42:33 +00:00
|
|
|
fprintf (stderr, "MOV %lx into reg %d", gr[RD], RD);
|
1999-04-27 01:33:01 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x13: /* bgenr */
|
2015-11-15 08:42:33 +00:00
|
|
|
if (gr[RS] & 0x20)
|
|
|
|
gr[RD] = 0;
|
1999-04-27 01:33:01 +00:00
|
|
|
else
|
2015-11-15 08:42:33 +00:00
|
|
|
gr[RD] = 1 << (gr[RS] & 0x1F);
|
1999-04-27 01:33:01 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x14: /* rsub */
|
2015-11-15 08:42:33 +00:00
|
|
|
gr[RD] = gr[RS] - gr[RD];
|
1999-04-27 01:33:01 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x15: /* ixw */
|
2015-11-15 08:42:33 +00:00
|
|
|
gr[RD] += gr[RS]<<2;
|
1999-04-27 01:33:01 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x16: /* and */
|
2015-11-15 08:42:33 +00:00
|
|
|
gr[RD] &= gr[RS];
|
1999-04-27 01:33:01 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x17: /* xor */
|
2015-11-15 08:42:33 +00:00
|
|
|
gr[RD] ^= gr[RS];
|
1999-04-27 01:33:01 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x18: case 0x19: /* mtcr */
|
|
|
|
{
|
|
|
|
unsigned r;
|
|
|
|
r = IMM5;
|
|
|
|
if (r <= LAST_VALID_CREG)
|
2015-11-15 08:42:33 +00:00
|
|
|
cr[r] = gr[RD];
|
1999-04-27 01:33:01 +00:00
|
|
|
else
|
2015-11-15 08:09:32 +00:00
|
|
|
ILLEGAL ();
|
2015-03-16 06:23:02 +00:00
|
|
|
|
1999-04-27 01:33:01 +00:00
|
|
|
/* we might have changed register sets... */
|
2015-11-15 08:42:33 +00:00
|
|
|
set_active_regs (cpu);
|
1999-04-27 01:33:01 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x1A: /* asr */
|
2000-01-18 00:55:13 +00:00
|
|
|
/* We must not rely solely upon the native shift operations, since they
|
|
|
|
may not match the M*Core's behaviour on boundary conditions. */
|
2015-11-15 08:42:33 +00:00
|
|
|
if (gr[RS] > 30)
|
|
|
|
gr[RD] = ((long) gr[RD]) < 0 ? -1 : 0;
|
2000-01-18 00:55:13 +00:00
|
|
|
else
|
2015-11-15 08:42:33 +00:00
|
|
|
gr[RD] = (long) gr[RD] >> gr[RS];
|
1999-04-27 01:33:01 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x1B: /* lsl */
|
2000-01-18 00:55:13 +00:00
|
|
|
/* We must not rely solely upon the native shift operations, since they
|
|
|
|
may not match the M*Core's behaviour on boundary conditions. */
|
2015-11-15 08:42:33 +00:00
|
|
|
gr[RD] = gr[RS] > 31 ? 0 : gr[RD] << gr[RS];
|
1999-04-27 01:33:01 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x1C: /* addu */
|
2015-11-15 08:42:33 +00:00
|
|
|
gr[RD] += gr[RS];
|
1999-04-27 01:33:01 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x1D: /* ixh */
|
2015-11-15 08:42:33 +00:00
|
|
|
gr[RD] += gr[RS] << 1;
|
1999-04-27 01:33:01 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x1E: /* or */
|
2015-11-15 08:42:33 +00:00
|
|
|
gr[RD] |= gr[RS];
|
1999-04-27 01:33:01 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x1F: /* andn */
|
2015-11-15 08:42:33 +00:00
|
|
|
gr[RD] &= ~gr[RS];
|
1999-04-27 01:33:01 +00:00
|
|
|
break;
|
|
|
|
case 0x20: case 0x21: /* addi */
|
2015-11-15 08:42:33 +00:00
|
|
|
gr[RD] =
|
|
|
|
gr[RD] + (IMM5 + 1);
|
1999-04-27 01:33:01 +00:00
|
|
|
break;
|
|
|
|
case 0x22: case 0x23: /* cmplti */
|
|
|
|
{
|
|
|
|
int tmp = (IMM5 + 1);
|
2015-11-15 08:42:33 +00:00
|
|
|
if (gr[RD] < tmp)
|
1999-04-27 01:33:01 +00:00
|
|
|
{
|
|
|
|
SET_C();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CLR_C();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0x24: case 0x25: /* subi */
|
2015-11-15 08:42:33 +00:00
|
|
|
gr[RD] =
|
|
|
|
gr[RD] - (IMM5 + 1);
|
1999-04-27 01:33:01 +00:00
|
|
|
break;
|
|
|
|
case 0x26: case 0x27: /* illegal */
|
2015-11-15 08:09:32 +00:00
|
|
|
ILLEGAL ();
|
1999-04-27 01:33:01 +00:00
|
|
|
break;
|
|
|
|
case 0x28: case 0x29: /* rsubi */
|
2015-11-15 08:42:33 +00:00
|
|
|
gr[RD] =
|
|
|
|
IMM5 - gr[RD];
|
1999-04-27 01:33:01 +00:00
|
|
|
break;
|
|
|
|
case 0x2A: case 0x2B: /* cmpnei */
|
2015-11-15 08:42:33 +00:00
|
|
|
if (gr[RD] != IMM5)
|
1999-04-27 01:33:01 +00:00
|
|
|
{
|
|
|
|
SET_C();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CLR_C();
|
|
|
|
}
|
|
|
|
break;
|
2015-03-16 06:23:02 +00:00
|
|
|
|
1999-04-27 01:33:01 +00:00
|
|
|
case 0x2C: case 0x2D: /* bmaski, divu */
|
|
|
|
{
|
|
|
|
unsigned imm = IMM5;
|
2015-03-16 06:23:02 +00:00
|
|
|
|
1999-04-27 01:33:01 +00:00
|
|
|
if (imm == 1)
|
|
|
|
{
|
|
|
|
int exe;
|
|
|
|
int rxnlz, r1nlz;
|
|
|
|
unsigned int rx, r1;
|
|
|
|
|
2015-11-15 08:42:33 +00:00
|
|
|
rx = gr[RD];
|
|
|
|
r1 = gr[1];
|
1999-04-27 01:33:01 +00:00
|
|
|
exe = 0;
|
|
|
|
|
|
|
|
/* unsigned divide */
|
2015-11-15 08:42:33 +00:00
|
|
|
gr[RD] = (word) ((unsigned int) gr[RD] / (unsigned int)gr[1] );
|
2015-03-16 06:23:02 +00:00
|
|
|
|
1999-04-27 01:33:01 +00:00
|
|
|
/* compute bonus_cycles for divu */
|
|
|
|
for (r1nlz = 0; ((r1 & 0x80000000) == 0) && (r1nlz < 32); r1nlz ++)
|
|
|
|
r1 = r1 << 1;
|
|
|
|
|
|
|
|
for (rxnlz = 0; ((rx & 0x80000000) == 0) && (rxnlz < 32); rxnlz ++)
|
|
|
|
rx = rx << 1;
|
|
|
|
|
|
|
|
if (r1nlz < rxnlz)
|
|
|
|
exe += 4;
|
|
|
|
else
|
|
|
|
exe += 5 + r1nlz - rxnlz;
|
|
|
|
|
|
|
|
if (exe >= (2 * memcycles - 1))
|
|
|
|
{
|
|
|
|
bonus_cycles += exe - (2 * memcycles) + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (imm == 0 || imm >= 8)
|
|
|
|
{
|
|
|
|
/* bmaski */
|
|
|
|
if (imm == 0)
|
2015-11-15 08:42:33 +00:00
|
|
|
gr[RD] = -1;
|
1999-04-27 01:33:01 +00:00
|
|
|
else
|
2015-11-15 08:42:33 +00:00
|
|
|
gr[RD] = (1 << imm) - 1;
|
1999-04-27 01:33:01 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* illegal */
|
2015-11-15 08:09:32 +00:00
|
|
|
ILLEGAL ();
|
1999-04-27 01:33:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0x2E: case 0x2F: /* andi */
|
2015-11-15 08:42:33 +00:00
|
|
|
gr[RD] = gr[RD] & IMM5;
|
1999-04-27 01:33:01 +00:00
|
|
|
break;
|
|
|
|
case 0x30: case 0x31: /* bclri */
|
2015-11-15 08:42:33 +00:00
|
|
|
gr[RD] = gr[RD] & ~(1<<IMM5);
|
1999-04-27 01:33:01 +00:00
|
|
|
break;
|
|
|
|
case 0x32: case 0x33: /* bgeni, divs */
|
|
|
|
{
|
|
|
|
unsigned imm = IMM5;
|
|
|
|
if (imm == 1)
|
|
|
|
{
|
|
|
|
int exe,sc;
|
|
|
|
int rxnlz, r1nlz;
|
|
|
|
signed int rx, r1;
|
2015-03-16 06:23:02 +00:00
|
|
|
|
1999-04-27 01:33:01 +00:00
|
|
|
/* compute bonus_cycles for divu */
|
2015-11-15 08:42:33 +00:00
|
|
|
rx = gr[RD];
|
|
|
|
r1 = gr[1];
|
1999-04-27 01:33:01 +00:00
|
|
|
exe = 0;
|
2015-03-16 06:23:02 +00:00
|
|
|
|
1999-04-27 01:33:01 +00:00
|
|
|
if (((rx < 0) && (r1 > 0)) || ((rx >= 0) && (r1 < 0)))
|
|
|
|
sc = 1;
|
|
|
|
else
|
|
|
|
sc = 0;
|
2015-03-16 06:23:02 +00:00
|
|
|
|
1999-04-27 01:33:01 +00:00
|
|
|
rx = abs (rx);
|
|
|
|
r1 = abs (r1);
|
2015-03-16 06:23:02 +00:00
|
|
|
|
1999-04-27 01:33:01 +00:00
|
|
|
/* signed divide, general registers are of type int, so / op is OK */
|
2015-11-15 08:42:33 +00:00
|
|
|
gr[RD] = gr[RD] / gr[1];
|
2015-03-16 06:23:02 +00:00
|
|
|
|
1999-04-27 01:33:01 +00:00
|
|
|
for (r1nlz = 0; ((r1 & 0x80000000) == 0) && (r1nlz < 32) ; r1nlz ++ )
|
|
|
|
r1 = r1 << 1;
|
2015-03-16 06:23:02 +00:00
|
|
|
|
1999-04-27 01:33:01 +00:00
|
|
|
for (rxnlz = 0; ((rx & 0x80000000) == 0) && (rxnlz < 32) ; rxnlz ++ )
|
|
|
|
rx = rx << 1;
|
2015-03-16 06:23:02 +00:00
|
|
|
|
1999-04-27 01:33:01 +00:00
|
|
|
if (r1nlz < rxnlz)
|
|
|
|
exe += 5;
|
|
|
|
else
|
|
|
|
exe += 6 + r1nlz - rxnlz + sc;
|
2015-03-16 06:23:02 +00:00
|
|
|
|
1999-04-27 01:33:01 +00:00
|
|
|
if (exe >= (2 * memcycles - 1))
|
|
|
|
{
|
|
|
|
bonus_cycles += exe - (2 * memcycles) + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (imm >= 7)
|
|
|
|
{
|
|
|
|
/* bgeni */
|
2015-11-15 08:42:33 +00:00
|
|
|
gr[RD] = (1 << IMM5);
|
1999-04-27 01:33:01 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* illegal */
|
2015-11-15 08:09:32 +00:00
|
|
|
ILLEGAL ();
|
1999-04-27 01:33:01 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 0x34: case 0x35: /* bseti */
|
2015-11-15 08:42:33 +00:00
|
|
|
gr[RD] = gr[RD] | (1 << IMM5);
|
1999-04-27 01:33:01 +00:00
|
|
|
break;
|
|
|
|
case 0x36: case 0x37: /* btsti */
|
2015-11-15 08:42:33 +00:00
|
|
|
NEW_C (gr[RD] >> IMM5);
|
1999-04-27 01:33:01 +00:00
|
|
|
break;
|
|
|
|
case 0x38: case 0x39: /* xsr, rotli */
|
|
|
|
{
|
|
|
|
unsigned imm = IMM5;
|
2015-11-15 08:42:33 +00:00
|
|
|
unsigned long tmp = gr[RD];
|
1999-04-27 01:33:01 +00:00
|
|
|
if (imm == 0)
|
|
|
|
{
|
|
|
|
word cbit;
|
|
|
|
cbit = C_VALUE();
|
|
|
|
NEW_C (tmp);
|
2015-11-15 08:42:33 +00:00
|
|
|
gr[RD] = (cbit << 31) | (tmp >> 1);
|
1999-04-27 01:33:01 +00:00
|
|
|
}
|
|
|
|
else
|
2015-11-15 08:42:33 +00:00
|
|
|
gr[RD] = (tmp << imm) | (tmp >> (32 - imm));
|
1999-04-27 01:33:01 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0x3A: case 0x3B: /* asrc, asri */
|
|
|
|
{
|
|
|
|
unsigned imm = IMM5;
|
2015-11-15 08:42:33 +00:00
|
|
|
long tmp = gr[RD];
|
1999-04-27 01:33:01 +00:00
|
|
|
if (imm == 0)
|
|
|
|
{
|
|
|
|
NEW_C (tmp);
|
2015-11-15 08:42:33 +00:00
|
|
|
gr[RD] = tmp >> 1;
|
1999-04-27 01:33:01 +00:00
|
|
|
}
|
|
|
|
else
|
2015-11-15 08:42:33 +00:00
|
|
|
gr[RD] = tmp >> imm;
|
1999-04-27 01:33:01 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0x3C: case 0x3D: /* lslc, lsli */
|
|
|
|
{
|
|
|
|
unsigned imm = IMM5;
|
2015-11-15 08:42:33 +00:00
|
|
|
unsigned long tmp = gr[RD];
|
1999-04-27 01:33:01 +00:00
|
|
|
if (imm == 0)
|
|
|
|
{
|
|
|
|
NEW_C (tmp >> 31);
|
2015-11-15 08:42:33 +00:00
|
|
|
gr[RD] = tmp << 1;
|
1999-04-27 01:33:01 +00:00
|
|
|
}
|
|
|
|
else
|
2015-11-15 08:42:33 +00:00
|
|
|
gr[RD] = tmp << imm;
|
1999-04-27 01:33:01 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0x3E: case 0x3F: /* lsrc, lsri */
|
|
|
|
{
|
|
|
|
unsigned imm = IMM5;
|
2015-11-15 08:42:33 +00:00
|
|
|
unsigned long tmp = gr[RD];
|
1999-04-27 01:33:01 +00:00
|
|
|
if (imm == 0)
|
|
|
|
{
|
|
|
|
NEW_C (tmp);
|
2015-11-15 08:42:33 +00:00
|
|
|
gr[RD] = tmp >> 1;
|
1999-04-27 01:33:01 +00:00
|
|
|
}
|
|
|
|
else
|
2015-11-15 08:42:33 +00:00
|
|
|
gr[RD] = tmp >> imm;
|
1999-04-27 01:33:01 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0x40: case 0x41: case 0x42: case 0x43:
|
|
|
|
case 0x44: case 0x45: case 0x46: case 0x47:
|
|
|
|
case 0x48: case 0x49: case 0x4A: case 0x4B:
|
|
|
|
case 0x4C: case 0x4D: case 0x4E: case 0x4F:
|
2015-11-15 08:09:32 +00:00
|
|
|
ILLEGAL ();
|
1999-04-27 01:33:01 +00:00
|
|
|
break;
|
|
|
|
case 0x50:
|
2015-11-15 08:42:33 +00:00
|
|
|
util (sd, cpu, inst & 0xFF);
|
1999-04-27 01:33:01 +00:00
|
|
|
break;
|
|
|
|
case 0x51: case 0x52: case 0x53:
|
|
|
|
case 0x54: case 0x55: case 0x56: case 0x57:
|
|
|
|
case 0x58: case 0x59: case 0x5A: case 0x5B:
|
|
|
|
case 0x5C: case 0x5D: case 0x5E: case 0x5F:
|
2015-11-15 08:09:32 +00:00
|
|
|
ILLEGAL ();
|
1999-04-27 01:33:01 +00:00
|
|
|
break;
|
|
|
|
case 0x60: case 0x61: case 0x62: case 0x63: /* movi */
|
|
|
|
case 0x64: case 0x65: case 0x66: case 0x67:
|
2015-11-15 08:42:33 +00:00
|
|
|
gr[RD] = (inst >> 4) & 0x7F;
|
1999-04-27 01:33:01 +00:00
|
|
|
break;
|
|
|
|
case 0x68: case 0x69: case 0x6A: case 0x6B:
|
|
|
|
case 0x6C: case 0x6D: case 0x6E: case 0x6F: /* illegal */
|
2015-11-15 08:09:32 +00:00
|
|
|
ILLEGAL ();
|
1999-04-27 01:33:01 +00:00
|
|
|
break;
|
|
|
|
case 0x71: case 0x72: case 0x73:
|
|
|
|
case 0x74: case 0x75: case 0x76: case 0x77:
|
|
|
|
case 0x78: case 0x79: case 0x7A: case 0x7B:
|
|
|
|
case 0x7C: case 0x7D: case 0x7E: /* lrw */
|
2015-11-15 08:42:33 +00:00
|
|
|
gr[RX] = rlat ((pc + ((inst & 0xFF) << 2)) & 0xFFFFFFFC);
|
1999-04-27 01:33:01 +00:00
|
|
|
if (tracing)
|
2015-04-21 07:05:57 +00:00
|
|
|
fprintf (stderr, "LRW of 0x%x from 0x%lx to reg %d",
|
1999-04-27 01:33:01 +00:00
|
|
|
rlat ((pc + ((inst & 0xFF) << 2)) & 0xFFFFFFFC),
|
|
|
|
(pc + ((inst & 0xFF) << 2)) & 0xFFFFFFFC, RX);
|
|
|
|
memops++;
|
|
|
|
break;
|
|
|
|
case 0x7F: /* jsri */
|
2015-11-15 08:42:33 +00:00
|
|
|
gr[15] = pc;
|
1999-05-25 18:09:09 +00:00
|
|
|
if (tracing)
|
2015-04-21 07:05:57 +00:00
|
|
|
fprintf (stderr,
|
|
|
|
"func call: r2 = %lx r3 = %lx r4 = %lx r5 = %lx r6 = %lx r7 = %lx\n",
|
2015-11-15 08:42:33 +00:00
|
|
|
gr[2], gr[3], gr[4], gr[5], gr[6], gr[7]);
|
1999-04-27 01:33:01 +00:00
|
|
|
case 0x70: /* jmpi */
|
|
|
|
pc = rlat ((pc + ((inst & 0xFF) << 2)) & 0xFFFFFFFC);
|
|
|
|
memops++;
|
|
|
|
bonus_cycles++;
|
|
|
|
needfetch = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x80: case 0x81: case 0x82: case 0x83:
|
|
|
|
case 0x84: case 0x85: case 0x86: case 0x87:
|
|
|
|
case 0x88: case 0x89: case 0x8A: case 0x8B:
|
|
|
|
case 0x8C: case 0x8D: case 0x8E: case 0x8F: /* ld */
|
2015-11-15 08:42:33 +00:00
|
|
|
gr[RX] = rlat (gr[RD] + ((inst >> 2) & 0x003C));
|
1999-04-27 01:33:01 +00:00
|
|
|
if (tracing)
|
2015-04-21 07:05:57 +00:00
|
|
|
fprintf (stderr, "load reg %d from 0x%lx with 0x%lx",
|
1999-04-27 01:33:01 +00:00
|
|
|
RX,
|
2015-11-15 08:42:33 +00:00
|
|
|
gr[RD] + ((inst >> 2) & 0x003C), gr[RX]);
|
1999-04-27 01:33:01 +00:00
|
|
|
memops++;
|
|
|
|
break;
|
|
|
|
case 0x90: case 0x91: case 0x92: case 0x93:
|
|
|
|
case 0x94: case 0x95: case 0x96: case 0x97:
|
|
|
|
case 0x98: case 0x99: case 0x9A: case 0x9B:
|
|
|
|
case 0x9C: case 0x9D: case 0x9E: case 0x9F: /* st */
|
2015-11-15 08:42:33 +00:00
|
|
|
wlat (gr[RD] + ((inst >> 2) & 0x003C), gr[RX]);
|
1999-04-27 01:33:01 +00:00
|
|
|
if (tracing)
|
2015-04-21 07:05:57 +00:00
|
|
|
fprintf (stderr, "store reg %d (containing 0x%lx) to 0x%lx",
|
2015-11-15 08:42:33 +00:00
|
|
|
RX, gr[RX],
|
|
|
|
gr[RD] + ((inst >> 2) & 0x003C));
|
1999-04-27 01:33:01 +00:00
|
|
|
memops++;
|
|
|
|
break;
|
|
|
|
case 0xA0: case 0xA1: case 0xA2: case 0xA3:
|
|
|
|
case 0xA4: case 0xA5: case 0xA6: case 0xA7:
|
|
|
|
case 0xA8: case 0xA9: case 0xAA: case 0xAB:
|
|
|
|
case 0xAC: case 0xAD: case 0xAE: case 0xAF: /* ld.b */
|
2015-11-15 08:42:33 +00:00
|
|
|
gr[RX] = rbat (gr[RD] + RS);
|
1999-04-27 01:33:01 +00:00
|
|
|
memops++;
|
|
|
|
break;
|
|
|
|
case 0xB0: case 0xB1: case 0xB2: case 0xB3:
|
|
|
|
case 0xB4: case 0xB5: case 0xB6: case 0xB7:
|
|
|
|
case 0xB8: case 0xB9: case 0xBA: case 0xBB:
|
|
|
|
case 0xBC: case 0xBD: case 0xBE: case 0xBF: /* st.b */
|
2015-11-15 08:42:33 +00:00
|
|
|
wbat (gr[RD] + RS, gr[RX]);
|
1999-04-27 01:33:01 +00:00
|
|
|
memops++;
|
|
|
|
break;
|
|
|
|
case 0xC0: case 0xC1: case 0xC2: case 0xC3:
|
|
|
|
case 0xC4: case 0xC5: case 0xC6: case 0xC7:
|
|
|
|
case 0xC8: case 0xC9: case 0xCA: case 0xCB:
|
|
|
|
case 0xCC: case 0xCD: case 0xCE: case 0xCF: /* ld.h */
|
2015-11-15 08:42:33 +00:00
|
|
|
gr[RX] = rhat (gr[RD] + ((inst >> 3) & 0x001E));
|
1999-04-27 01:33:01 +00:00
|
|
|
memops++;
|
|
|
|
break;
|
|
|
|
case 0xD0: case 0xD1: case 0xD2: case 0xD3:
|
|
|
|
case 0xD4: case 0xD5: case 0xD6: case 0xD7:
|
|
|
|
case 0xD8: case 0xD9: case 0xDA: case 0xDB:
|
|
|
|
case 0xDC: case 0xDD: case 0xDE: case 0xDF: /* st.h */
|
2015-11-15 08:42:33 +00:00
|
|
|
what (gr[RD] + ((inst >> 3) & 0x001E), gr[RX]);
|
1999-04-27 01:33:01 +00:00
|
|
|
memops++;
|
|
|
|
break;
|
|
|
|
case 0xE8: case 0xE9: case 0xEA: case 0xEB:
|
2015-03-16 06:23:02 +00:00
|
|
|
case 0xEC: case 0xED: case 0xEE: case 0xEF: /* bf */
|
1999-04-27 01:33:01 +00:00
|
|
|
if (C_OFF())
|
|
|
|
{
|
|
|
|
int disp;
|
|
|
|
disp = inst & 0x03FF;
|
|
|
|
if (inst & 0x0400)
|
|
|
|
disp |= 0xFFFFFC00;
|
|
|
|
pc += disp<<1;
|
|
|
|
bonus_cycles++;
|
|
|
|
needfetch = 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0xE0: case 0xE1: case 0xE2: case 0xE3:
|
|
|
|
case 0xE4: case 0xE5: case 0xE6: case 0xE7: /* bt */
|
|
|
|
if (C_ON())
|
|
|
|
{
|
|
|
|
int disp;
|
|
|
|
disp = inst & 0x03FF;
|
|
|
|
if (inst & 0x0400)
|
|
|
|
disp |= 0xFFFFFC00;
|
|
|
|
pc += disp<<1;
|
|
|
|
bonus_cycles++;
|
|
|
|
needfetch = 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0xF8: case 0xF9: case 0xFA: case 0xFB:
|
2015-03-16 06:23:02 +00:00
|
|
|
case 0xFC: case 0xFD: case 0xFE: case 0xFF: /* bsr */
|
2015-11-15 08:42:33 +00:00
|
|
|
gr[15] = pc;
|
1999-04-27 01:33:01 +00:00
|
|
|
case 0xF0: case 0xF1: case 0xF2: case 0xF3:
|
|
|
|
case 0xF4: case 0xF5: case 0xF6: case 0xF7: /* br */
|
|
|
|
{
|
|
|
|
int disp;
|
|
|
|
disp = inst & 0x03FF;
|
|
|
|
if (inst & 0x0400)
|
|
|
|
disp |= 0xFFFFFC00;
|
|
|
|
pc += disp<<1;
|
|
|
|
bonus_cycles++;
|
|
|
|
needfetch = 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tracing)
|
|
|
|
fprintf (stderr, "\n");
|
1999-05-11 13:35:55 +00:00
|
|
|
|
2015-03-16 06:23:02 +00:00
|
|
|
if (needfetch)
|
1999-04-27 01:33:01 +00:00
|
|
|
{
|
2015-04-21 06:55:29 +00:00
|
|
|
ibuf = rlat (pc & 0xFFFFFFFC);
|
|
|
|
needfetch = 0;
|
1999-04-27 01:33:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Hide away the things we've cached while executing. */
|
2015-11-15 08:42:33 +00:00
|
|
|
CPU_PC_SET (cpu, pc);
|
|
|
|
cpu->insts += insts; /* instructions done ... */
|
|
|
|
cpu->cycles += insts; /* and each takes a cycle */
|
|
|
|
cpu->cycles += bonus_cycles; /* and extra cycles for branches */
|
|
|
|
cpu->cycles += memops * memcycles; /* and memop cycle delays */
|
1999-04-27 01:33:01 +00:00
|
|
|
}
|
|
|
|
|
2015-11-15 08:09:32 +00:00
|
|
|
void
|
|
|
|
sim_engine_run (SIM_DESC sd,
|
|
|
|
int next_cpu_nr, /* ignore */
|
|
|
|
int nr_cpus, /* ignore */
|
|
|
|
int siggnal) /* ignore */
|
|
|
|
{
|
2015-11-15 08:42:33 +00:00
|
|
|
sim_cpu *cpu;
|
2015-11-15 08:09:32 +00:00
|
|
|
|
|
|
|
SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER);
|
|
|
|
|
2015-11-15 08:42:33 +00:00
|
|
|
cpu = STATE_CPU (sd, 0);
|
2015-11-15 08:09:32 +00:00
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
2015-11-15 08:42:33 +00:00
|
|
|
step_once (sd, cpu);
|
2015-11-15 08:09:32 +00:00
|
|
|
if (sim_events_tick (sd))
|
|
|
|
sim_events_process (sd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-15 08:17:02 +00:00
|
|
|
static int
|
2015-11-15 08:42:33 +00:00
|
|
|
mcore_reg_store (SIM_CPU *cpu, int rn, unsigned char *memory, int length)
|
1999-04-27 01:33:01 +00:00
|
|
|
{
|
|
|
|
if (rn < NUM_MCORE_REGS && rn >= 0)
|
|
|
|
{
|
|
|
|
if (length == 4)
|
|
|
|
{
|
|
|
|
long ival;
|
2015-03-16 06:23:02 +00:00
|
|
|
|
1999-05-11 13:35:55 +00:00
|
|
|
/* misalignment safe */
|
|
|
|
ival = mcore_extract_unsigned_integer (memory, 4);
|
2015-11-15 08:42:33 +00:00
|
|
|
cpu->asints[rn] = ival;
|
1999-04-27 01:33:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-11-15 08:17:02 +00:00
|
|
|
static int
|
2015-11-15 08:42:33 +00:00
|
|
|
mcore_reg_fetch (SIM_CPU *cpu, int rn, unsigned char *memory, int length)
|
1999-04-27 01:33:01 +00:00
|
|
|
{
|
|
|
|
if (rn < NUM_MCORE_REGS && rn >= 0)
|
|
|
|
{
|
|
|
|
if (length == 4)
|
|
|
|
{
|
2015-11-15 08:42:33 +00:00
|
|
|
long ival = cpu->asints[rn];
|
1999-05-11 13:35:55 +00:00
|
|
|
|
|
|
|
/* misalignment-safe */
|
|
|
|
mcore_store_unsigned_integer (memory, 4, ival);
|
1999-04-27 01:33:01 +00:00
|
|
|
}
|
2015-03-16 06:23:02 +00:00
|
|
|
|
1999-04-27 01:33:01 +00:00
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-03-16 06:26:48 +00:00
|
|
|
sim_info (SIM_DESC sd, int verbose)
|
1999-04-27 01:33:01 +00:00
|
|
|
{
|
2015-11-15 08:42:33 +00:00
|
|
|
SIM_CPU *cpu = STATE_CPU (sd, 0);
|
1999-04-27 01:33:01 +00:00
|
|
|
#ifdef WATCHFUNCTIONS
|
|
|
|
int w, wcyc;
|
|
|
|
#endif
|
2015-11-15 08:42:33 +00:00
|
|
|
double virttime = cpu->cycles / 36.0e6;
|
2015-03-29 07:53:01 +00:00
|
|
|
host_callback *callback = STATE_CALLBACK (sd);
|
1999-04-27 01:33:01 +00:00
|
|
|
|
1999-05-11 13:35:55 +00:00
|
|
|
callback->printf_filtered (callback, "\n\n# instructions executed %10d\n",
|
2015-11-15 08:42:33 +00:00
|
|
|
cpu->insts);
|
1999-05-11 13:35:55 +00:00
|
|
|
callback->printf_filtered (callback, "# cycles %10d\n",
|
2015-11-15 08:42:33 +00:00
|
|
|
cpu->cycles);
|
1999-05-11 13:35:55 +00:00
|
|
|
callback->printf_filtered (callback, "# pipeline stalls %10d\n",
|
2015-11-15 08:42:33 +00:00
|
|
|
cpu->stalls);
|
1999-05-11 13:35:55 +00:00
|
|
|
callback->printf_filtered (callback, "# virtual time taken %10.4f\n",
|
|
|
|
virttime);
|
1999-04-27 01:33:01 +00:00
|
|
|
|
|
|
|
#ifdef WATCHFUNCTIONS
|
1999-05-11 13:35:55 +00:00
|
|
|
callback->printf_filtered (callback, "\nNumber of watched functions: %d\n",
|
|
|
|
ENDWL);
|
1999-04-27 01:33:01 +00:00
|
|
|
|
|
|
|
wcyc = 0;
|
2015-03-16 06:23:02 +00:00
|
|
|
|
1999-04-27 01:33:01 +00:00
|
|
|
for (w = 1; w <= ENDWL; w++)
|
|
|
|
{
|
|
|
|
callback->printf_filtered (callback, "WL = %s %8x\n",WLstr[w],WL[w]);
|
1999-05-11 13:35:55 +00:00
|
|
|
callback->printf_filtered (callback, " calls = %d, cycles = %d\n",
|
|
|
|
WLcnts[w],WLcyc[w]);
|
2015-03-16 06:23:02 +00:00
|
|
|
|
1999-04-27 01:33:01 +00:00
|
|
|
if (WLcnts[w] != 0)
|
1999-05-11 13:35:55 +00:00
|
|
|
callback->printf_filtered (callback,
|
|
|
|
" maxcpc = %d, mincpc = %d, avecpc = %d\n",
|
|
|
|
WLmax[w],WLmin[w],WLcyc[w]/WLcnts[w]);
|
1999-04-27 01:33:01 +00:00
|
|
|
wcyc += WLcyc[w];
|
|
|
|
}
|
2015-03-16 06:23:02 +00:00
|
|
|
|
1999-05-11 13:35:55 +00:00
|
|
|
callback->printf_filtered (callback,
|
|
|
|
"Total cycles for watched functions: %d\n",wcyc);
|
1999-04-27 01:33:01 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2015-04-16 06:07:33 +00:00
|
|
|
static sim_cia
|
|
|
|
mcore_pc_get (sim_cpu *cpu)
|
|
|
|
{
|
2015-11-15 08:42:33 +00:00
|
|
|
return cpu->regs.pc;
|
2015-04-16 06:07:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
mcore_pc_set (sim_cpu *cpu, sim_cia pc)
|
|
|
|
{
|
2015-11-15 08:42:33 +00:00
|
|
|
cpu->regs.pc = pc;
|
2015-04-16 06:07:33 +00:00
|
|
|
}
|
|
|
|
|
2015-03-29 07:53:01 +00:00
|
|
|
static void
|
|
|
|
free_state (SIM_DESC sd)
|
|
|
|
{
|
|
|
|
if (STATE_MODULES (sd) != NULL)
|
|
|
|
sim_module_uninstall (sd);
|
|
|
|
sim_cpu_free_all (sd);
|
|
|
|
sim_state_free (sd);
|
|
|
|
}
|
|
|
|
|
1999-04-27 01:33:01 +00:00
|
|
|
SIM_DESC
|
2015-03-16 06:26:48 +00:00
|
|
|
sim_open (SIM_OPEN_KIND kind, host_callback *cb, struct bfd *abfd, char **argv)
|
1999-04-27 01:33:01 +00:00
|
|
|
{
|
2015-04-21 06:55:29 +00:00
|
|
|
int i;
|
2015-03-29 07:53:01 +00:00
|
|
|
SIM_DESC sd = sim_state_alloc (kind, cb);
|
|
|
|
SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER);
|
|
|
|
|
|
|
|
/* The cpu data is kept in a separately allocated chunk of memory. */
|
|
|
|
if (sim_cpu_alloc_all (sd, 1, /*cgen_cpu_max_extra_bytes ()*/0) != SIM_RC_OK)
|
|
|
|
{
|
|
|
|
free_state (sd);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sim_pre_argv_init (sd, argv[0]) != SIM_RC_OK)
|
|
|
|
{
|
|
|
|
free_state (sd);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* getopt will print the error message so we just have to exit if this fails.
|
|
|
|
FIXME: Hmmm... in the case of gdb we need getopt to call
|
|
|
|
print_filtered. */
|
|
|
|
if (sim_parse_args (sd, argv) != SIM_RC_OK)
|
|
|
|
{
|
|
|
|
free_state (sd);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check for/establish the a reference program image. */
|
|
|
|
if (sim_analyze_program (sd,
|
|
|
|
(STATE_PROG_ARGV (sd) != NULL
|
|
|
|
? *STATE_PROG_ARGV (sd)
|
|
|
|
: NULL), abfd) != SIM_RC_OK)
|
|
|
|
{
|
|
|
|
free_state (sd);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Configure/verify the target byte order and other runtime
|
|
|
|
configuration options. */
|
|
|
|
if (sim_config (sd) != SIM_RC_OK)
|
|
|
|
{
|
|
|
|
sim_module_uninstall (sd);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sim_post_argv_init (sd) != SIM_RC_OK)
|
|
|
|
{
|
|
|
|
/* Uninstall the modules to avoid memory leaks,
|
|
|
|
file descriptor leaks, etc. */
|
|
|
|
sim_module_uninstall (sd);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* CPU specific initialization. */
|
|
|
|
for (i = 0; i < MAX_NR_PROCESSORS; ++i)
|
|
|
|
{
|
|
|
|
SIM_CPU *cpu = STATE_CPU (sd, i);
|
2015-04-16 06:07:33 +00:00
|
|
|
|
2015-11-15 08:17:02 +00:00
|
|
|
CPU_REG_FETCH (cpu) = mcore_reg_fetch;
|
|
|
|
CPU_REG_STORE (cpu) = mcore_reg_store;
|
2015-04-16 06:07:33 +00:00
|
|
|
CPU_PC_FETCH (cpu) = mcore_pc_get;
|
|
|
|
CPU_PC_STORE (cpu) = mcore_pc_set;
|
|
|
|
|
2015-03-29 07:53:01 +00:00
|
|
|
set_initial_gprs (cpu); /* Reset the GPR registers. */
|
|
|
|
}
|
2015-03-16 06:23:02 +00:00
|
|
|
|
2015-04-21 06:55:29 +00:00
|
|
|
/* Default to a 8 Mbyte (== 2^23) memory space. */
|
|
|
|
sim_do_commandf (sd, "memory-size %#x", DEFAULT_MEMORY_SIZE);
|
|
|
|
|
2015-03-29 07:53:01 +00:00
|
|
|
return sd;
|
1999-04-27 01:33:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SIM_RC
|
2015-03-16 06:26:48 +00:00
|
|
|
sim_create_inferior (SIM_DESC sd, struct bfd *prog_bfd, char **argv, char **env)
|
1999-04-27 01:33:01 +00:00
|
|
|
{
|
2015-11-15 08:42:33 +00:00
|
|
|
SIM_CPU *cpu = STATE_CPU (sd, 0);
|
1999-04-27 01:33:01 +00:00
|
|
|
char ** avp;
|
|
|
|
int nargs = 0;
|
|
|
|
int nenv = 0;
|
|
|
|
int s_length;
|
|
|
|
int l;
|
|
|
|
unsigned long strings;
|
|
|
|
unsigned long pointers;
|
|
|
|
unsigned long hi_stack;
|
|
|
|
|
|
|
|
|
|
|
|
/* Set the initial register set. */
|
2015-11-15 08:42:33 +00:00
|
|
|
set_initial_gprs (cpu);
|
2015-03-16 06:23:02 +00:00
|
|
|
|
2015-04-21 06:55:29 +00:00
|
|
|
hi_stack = DEFAULT_MEMORY_SIZE - 4;
|
2015-11-15 08:42:33 +00:00
|
|
|
CPU_PC_SET (cpu, bfd_get_start_address (prog_bfd));
|
1999-04-27 01:33:01 +00:00
|
|
|
|
|
|
|
/* Calculate the argument and environment strings. */
|
|
|
|
s_length = 0;
|
|
|
|
nargs = 0;
|
|
|
|
avp = argv;
|
|
|
|
while (avp && *avp)
|
|
|
|
{
|
|
|
|
l = strlen (*avp) + 1; /* include the null */
|
|
|
|
s_length += (l + 3) & ~3; /* make it a 4 byte boundary */
|
|
|
|
nargs++; avp++;
|
|
|
|
}
|
|
|
|
|
|
|
|
nenv = 0;
|
|
|
|
avp = env;
|
|
|
|
while (avp && *avp)
|
|
|
|
{
|
|
|
|
l = strlen (*avp) + 1; /* include the null */
|
|
|
|
s_length += (l + 3) & ~ 3;/* make it a 4 byte boundary */
|
|
|
|
nenv++; avp++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Claim some memory for the pointers and strings. */
|
|
|
|
pointers = hi_stack - sizeof(word) * (nenv+1+nargs+1);
|
|
|
|
pointers &= ~3; /* must be 4-byte aligned */
|
2015-11-15 08:42:33 +00:00
|
|
|
gr[0] = pointers;
|
1999-04-27 01:33:01 +00:00
|
|
|
|
2015-11-15 08:42:33 +00:00
|
|
|
strings = gr[0] - s_length;
|
1999-04-27 01:33:01 +00:00
|
|
|
strings &= ~3; /* want to make it 4-byte aligned */
|
2015-11-15 08:42:33 +00:00
|
|
|
gr[0] = strings;
|
1999-04-27 01:33:01 +00:00
|
|
|
/* dac fix, the stack address must be 8-byte aligned! */
|
2015-11-15 08:42:33 +00:00
|
|
|
gr[0] = gr[0] - gr[0] % 8;
|
1999-04-27 01:33:01 +00:00
|
|
|
|
|
|
|
/* Loop through the arguments and fill them in. */
|
2015-11-15 08:42:33 +00:00
|
|
|
gr[PARM1] = nargs;
|
1999-04-27 01:33:01 +00:00
|
|
|
if (nargs == 0)
|
|
|
|
{
|
|
|
|
/* No strings to fill in. */
|
2015-11-15 08:42:33 +00:00
|
|
|
gr[PARM2] = 0;
|
1999-04-27 01:33:01 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-11-15 08:42:33 +00:00
|
|
|
gr[PARM2] = pointers;
|
1999-04-27 01:33:01 +00:00
|
|
|
avp = argv;
|
|
|
|
while (avp && *avp)
|
|
|
|
{
|
|
|
|
/* Save where we're putting it. */
|
|
|
|
wlat (pointers, strings);
|
|
|
|
|
|
|
|
/* Copy the string. */
|
|
|
|
l = strlen (* avp) + 1;
|
2015-11-15 08:42:33 +00:00
|
|
|
sim_core_write_buffer (sd, cpu, write_map, *avp, strings, l);
|
1999-04-27 01:33:01 +00:00
|
|
|
|
|
|
|
/* Bump the pointers. */
|
|
|
|
avp++;
|
|
|
|
pointers += 4;
|
|
|
|
strings += l+1;
|
|
|
|
}
|
2015-03-16 06:23:02 +00:00
|
|
|
|
1999-04-27 01:33:01 +00:00
|
|
|
/* A null to finish the list. */
|
|
|
|
wlat (pointers, 0);
|
|
|
|
pointers += 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now do the environment pointers. */
|
|
|
|
if (nenv == 0)
|
|
|
|
{
|
|
|
|
/* No strings to fill in. */
|
2015-11-15 08:42:33 +00:00
|
|
|
gr[PARM3] = 0;
|
1999-04-27 01:33:01 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-11-15 08:42:33 +00:00
|
|
|
gr[PARM3] = pointers;
|
1999-04-27 01:33:01 +00:00
|
|
|
avp = env;
|
2015-03-16 06:23:02 +00:00
|
|
|
|
1999-04-27 01:33:01 +00:00
|
|
|
while (avp && *avp)
|
|
|
|
{
|
|
|
|
/* Save where we're putting it. */
|
|
|
|
wlat (pointers, strings);
|
|
|
|
|
|
|
|
/* Copy the string. */
|
|
|
|
l = strlen (* avp) + 1;
|
2015-11-15 08:42:33 +00:00
|
|
|
sim_core_write_buffer (sd, cpu, write_map, *avp, strings, l);
|
1999-04-27 01:33:01 +00:00
|
|
|
|
|
|
|
/* Bump the pointers. */
|
|
|
|
avp++;
|
|
|
|
pointers += 4;
|
|
|
|
strings += l+1;
|
|
|
|
}
|
2015-03-16 06:23:02 +00:00
|
|
|
|
1999-04-27 01:33:01 +00:00
|
|
|
/* A null to finish the list. */
|
|
|
|
wlat (pointers, 0);
|
|
|
|
pointers += 4;
|
|
|
|
}
|
2015-03-16 06:23:02 +00:00
|
|
|
|
1999-04-27 01:33:01 +00:00
|
|
|
return SIM_RC_OK;
|
|
|
|
}
|