OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [tags/] [gnu-src/] [gdb-6.8/] [pre-binutils-2.20.1-sync/] [sim/] [frv/] [traps.c] - Diff between revs 157 and 223

Only display areas with differences | Details | Blame | View Log

Rev 157 Rev 223
/* frv trap support
/* frv trap support
   Copyright (C) 1999, 2000, 2001, 2003, 2007, 2008
   Copyright (C) 1999, 2000, 2001, 2003, 2007, 2008
   Free Software Foundation, Inc.
   Free Software Foundation, Inc.
   Contributed by Red Hat.
   Contributed by Red Hat.
 
 
This file is part of the GNU simulators.
This file is part of the GNU simulators.
 
 
This program is free software; you can redistribute it and/or modify
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
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
(at your option) any later version.
 
 
This program is distributed in the hope that it will be useful,
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
GNU General Public License for more details.
 
 
You should have received a copy of the GNU General Public License
You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 
#define WANT_CPU frvbf
#define WANT_CPU frvbf
#define WANT_CPU_FRVBF
#define WANT_CPU_FRVBF
 
 
#include "sim-main.h"
#include "sim-main.h"
#include "targ-vals.h"
#include "targ-vals.h"
#include "cgen-engine.h"
#include "cgen-engine.h"
#include "cgen-par.h"
#include "cgen-par.h"
#include "sim-fpu.h"
#include "sim-fpu.h"
 
 
#include "bfd.h"
#include "bfd.h"
#include "libiberty.h"
#include "libiberty.h"
 
 
CGEN_ATTR_VALUE_ENUM_TYPE frv_current_fm_slot;
CGEN_ATTR_VALUE_ENUM_TYPE frv_current_fm_slot;
 
 
/* The semantic code invokes this for invalid (unrecognized) instructions.  */
/* The semantic code invokes this for invalid (unrecognized) instructions.  */
 
 
SEM_PC
SEM_PC
sim_engine_invalid_insn (SIM_CPU *current_cpu, IADDR cia, SEM_PC vpc)
sim_engine_invalid_insn (SIM_CPU *current_cpu, IADDR cia, SEM_PC vpc)
{
{
  frv_queue_program_interrupt (current_cpu, FRV_ILLEGAL_INSTRUCTION);
  frv_queue_program_interrupt (current_cpu, FRV_ILLEGAL_INSTRUCTION);
  return vpc;
  return vpc;
}
}
 
 
/* Process an address exception.  */
/* Process an address exception.  */
 
 
void
void
frv_core_signal (SIM_DESC sd, SIM_CPU *current_cpu, sim_cia cia,
frv_core_signal (SIM_DESC sd, SIM_CPU *current_cpu, sim_cia cia,
                  unsigned int map, int nr_bytes, address_word addr,
                  unsigned int map, int nr_bytes, address_word addr,
                  transfer_type transfer, sim_core_signals sig)
                  transfer_type transfer, sim_core_signals sig)
{
{
  if (sig == sim_core_unaligned_signal)
  if (sig == sim_core_unaligned_signal)
    {
    {
      if (STATE_ARCHITECTURE (sd)->mach == bfd_mach_fr400
      if (STATE_ARCHITECTURE (sd)->mach == bfd_mach_fr400
          || STATE_ARCHITECTURE (sd)->mach == bfd_mach_fr450)
          || STATE_ARCHITECTURE (sd)->mach == bfd_mach_fr450)
        frv_queue_data_access_error_interrupt (current_cpu, addr);
        frv_queue_data_access_error_interrupt (current_cpu, addr);
      else
      else
        frv_queue_mem_address_not_aligned_interrupt (current_cpu, addr);
        frv_queue_mem_address_not_aligned_interrupt (current_cpu, addr);
    }
    }
 
 
  frv_term (sd);
  frv_term (sd);
  sim_core_signal (sd, current_cpu, cia, map, nr_bytes, addr, transfer, sig);
  sim_core_signal (sd, current_cpu, cia, map, nr_bytes, addr, transfer, sig);
}
}
 
 
void
void
frv_sim_engine_halt_hook (SIM_DESC sd, SIM_CPU *current_cpu, sim_cia cia)
frv_sim_engine_halt_hook (SIM_DESC sd, SIM_CPU *current_cpu, sim_cia cia)
{
{
  int i;
  int i;
  if (current_cpu != NULL)
  if (current_cpu != NULL)
    CIA_SET (current_cpu, cia);
    CIA_SET (current_cpu, cia);
 
 
  /* Invalidate the insn and data caches of all cpus.  */
  /* Invalidate the insn and data caches of all cpus.  */
  for (i = 0; i < MAX_NR_PROCESSORS; ++i)
  for (i = 0; i < MAX_NR_PROCESSORS; ++i)
    {
    {
      current_cpu = STATE_CPU (sd, i);
      current_cpu = STATE_CPU (sd, i);
      frv_cache_invalidate_all (CPU_INSN_CACHE (current_cpu), 0);
      frv_cache_invalidate_all (CPU_INSN_CACHE (current_cpu), 0);
      frv_cache_invalidate_all (CPU_DATA_CACHE (current_cpu), 1);
      frv_cache_invalidate_all (CPU_DATA_CACHE (current_cpu), 1);
    }
    }
  frv_term (sd);
  frv_term (sd);
}
}


/* Read/write functions for system call interface.  */
/* Read/write functions for system call interface.  */
 
 
static int
static int
syscall_read_mem (host_callback *cb, struct cb_syscall *sc,
syscall_read_mem (host_callback *cb, struct cb_syscall *sc,
                  unsigned long taddr, char *buf, int bytes)
                  unsigned long taddr, char *buf, int bytes)
{
{
  SIM_DESC sd = (SIM_DESC) sc->p1;
  SIM_DESC sd = (SIM_DESC) sc->p1;
  SIM_CPU *cpu = (SIM_CPU *) sc->p2;
  SIM_CPU *cpu = (SIM_CPU *) sc->p2;
 
 
  frv_cache_invalidate_all (CPU_DATA_CACHE (cpu), 1);
  frv_cache_invalidate_all (CPU_DATA_CACHE (cpu), 1);
  return sim_core_read_buffer (sd, cpu, read_map, buf, taddr, bytes);
  return sim_core_read_buffer (sd, cpu, read_map, buf, taddr, bytes);
}
}
 
 
static int
static int
syscall_write_mem (host_callback *cb, struct cb_syscall *sc,
syscall_write_mem (host_callback *cb, struct cb_syscall *sc,
                   unsigned long taddr, const char *buf, int bytes)
                   unsigned long taddr, const char *buf, int bytes)
{
{
  SIM_DESC sd = (SIM_DESC) sc->p1;
  SIM_DESC sd = (SIM_DESC) sc->p1;
  SIM_CPU *cpu = (SIM_CPU *) sc->p2;
  SIM_CPU *cpu = (SIM_CPU *) sc->p2;
 
 
  frv_cache_invalidate_all (CPU_INSN_CACHE (cpu), 0);
  frv_cache_invalidate_all (CPU_INSN_CACHE (cpu), 0);
  frv_cache_invalidate_all (CPU_DATA_CACHE (cpu), 1);
  frv_cache_invalidate_all (CPU_DATA_CACHE (cpu), 1);
  return sim_core_write_buffer (sd, cpu, write_map, buf, taddr, bytes);
  return sim_core_write_buffer (sd, cpu, write_map, buf, taddr, bytes);
}
}
 
 
/* Handle TRA and TIRA insns.  */
/* Handle TRA and TIRA insns.  */
void
void
frv_itrap (SIM_CPU *current_cpu, PCADDR pc, USI base, SI offset)
frv_itrap (SIM_CPU *current_cpu, PCADDR pc, USI base, SI offset)
{
{
  SIM_DESC sd = CPU_STATE (current_cpu);
  SIM_DESC sd = CPU_STATE (current_cpu);
  host_callback *cb = STATE_CALLBACK (sd);
  host_callback *cb = STATE_CALLBACK (sd);
  USI num = ((base + offset) & 0x7f) + 0x80;
  USI num = ((base + offset) & 0x7f) + 0x80;
 
 
#ifdef SIM_HAVE_BREAKPOINTS
#ifdef SIM_HAVE_BREAKPOINTS
  /* Check for breakpoints "owned" by the simulator first, regardless
  /* Check for breakpoints "owned" by the simulator first, regardless
     of --environment.  */
     of --environment.  */
  if (num == TRAP_BREAKPOINT)
  if (num == TRAP_BREAKPOINT)
    {
    {
      /* First try sim-break.c.  If it's a breakpoint the simulator "owns"
      /* First try sim-break.c.  If it's a breakpoint the simulator "owns"
         it doesn't return.  Otherwise it returns and let's us try.  */
         it doesn't return.  Otherwise it returns and let's us try.  */
      sim_handle_breakpoint (sd, current_cpu, pc);
      sim_handle_breakpoint (sd, current_cpu, pc);
      /* Fall through.  */
      /* Fall through.  */
    }
    }
#endif
#endif
 
 
  if (STATE_ENVIRONMENT (sd) == OPERATING_ENVIRONMENT)
  if (STATE_ENVIRONMENT (sd) == OPERATING_ENVIRONMENT)
    {
    {
      frv_queue_software_interrupt (current_cpu, num);
      frv_queue_software_interrupt (current_cpu, num);
      return;
      return;
    }
    }
 
 
  switch (num)
  switch (num)
    {
    {
    case TRAP_SYSCALL :
    case TRAP_SYSCALL :
      {
      {
        CB_SYSCALL s;
        CB_SYSCALL s;
        CB_SYSCALL_INIT (&s);
        CB_SYSCALL_INIT (&s);
        s.func = GET_H_GR (7);
        s.func = GET_H_GR (7);
        s.arg1 = GET_H_GR (8);
        s.arg1 = GET_H_GR (8);
        s.arg2 = GET_H_GR (9);
        s.arg2 = GET_H_GR (9);
        s.arg3 = GET_H_GR (10);
        s.arg3 = GET_H_GR (10);
 
 
        if (s.func == TARGET_SYS_exit)
        if (s.func == TARGET_SYS_exit)
          {
          {
            sim_engine_halt (sd, current_cpu, NULL, pc, sim_exited, s.arg1);
            sim_engine_halt (sd, current_cpu, NULL, pc, sim_exited, s.arg1);
          }
          }
 
 
        s.p1 = (PTR) sd;
        s.p1 = (PTR) sd;
        s.p2 = (PTR) current_cpu;
        s.p2 = (PTR) current_cpu;
        s.read_mem = syscall_read_mem;
        s.read_mem = syscall_read_mem;
        s.write_mem = syscall_write_mem;
        s.write_mem = syscall_write_mem;
        cb_syscall (cb, &s);
        cb_syscall (cb, &s);
        SET_H_GR (8, s.result);
        SET_H_GR (8, s.result);
        SET_H_GR (9, s.result2);
        SET_H_GR (9, s.result2);
        SET_H_GR (10, s.errcode);
        SET_H_GR (10, s.errcode);
        break;
        break;
      }
      }
 
 
    case TRAP_BREAKPOINT:
    case TRAP_BREAKPOINT:
      sim_engine_halt (sd, current_cpu, NULL, pc, sim_stopped, SIM_SIGTRAP);
      sim_engine_halt (sd, current_cpu, NULL, pc, sim_stopped, SIM_SIGTRAP);
      break;
      break;
 
 
      /* Add support for dumping registers, either at fixed traps, or all
      /* Add support for dumping registers, either at fixed traps, or all
         unknown traps if configured with --enable-sim-trapdump.  */
         unknown traps if configured with --enable-sim-trapdump.  */
    default:
    default:
#if !TRAPDUMP
#if !TRAPDUMP
      frv_queue_software_interrupt (current_cpu, num);
      frv_queue_software_interrupt (current_cpu, num);
      return;
      return;
#endif
#endif
 
 
#ifdef TRAP_REGDUMP1
#ifdef TRAP_REGDUMP1
    case TRAP_REGDUMP1:
    case TRAP_REGDUMP1:
#endif
#endif
 
 
#ifdef TRAP_REGDUMP2
#ifdef TRAP_REGDUMP2
    case TRAP_REGDUMP2:
    case TRAP_REGDUMP2:
#endif
#endif
 
 
#if TRAPDUMP || (defined (TRAP_REGDUMP1)) || (defined (TRAP_REGDUMP2))
#if TRAPDUMP || (defined (TRAP_REGDUMP1)) || (defined (TRAP_REGDUMP2))
      {
      {
        char buf[256];
        char buf[256];
        int i, j;
        int i, j;
 
 
        buf[0] = 0;
        buf[0] = 0;
        if (STATE_TEXT_SECTION (sd)
        if (STATE_TEXT_SECTION (sd)
            && pc >= STATE_TEXT_START (sd)
            && pc >= STATE_TEXT_START (sd)
            && pc < STATE_TEXT_END (sd))
            && pc < STATE_TEXT_END (sd))
          {
          {
            const char *pc_filename = (const char *)0;
            const char *pc_filename = (const char *)0;
            const char *pc_function = (const char *)0;
            const char *pc_function = (const char *)0;
            unsigned int pc_linenum = 0;
            unsigned int pc_linenum = 0;
 
 
            if (bfd_find_nearest_line (STATE_PROG_BFD (sd),
            if (bfd_find_nearest_line (STATE_PROG_BFD (sd),
                                       STATE_TEXT_SECTION (sd),
                                       STATE_TEXT_SECTION (sd),
                                       (struct bfd_symbol **) 0,
                                       (struct bfd_symbol **) 0,
                                       pc - STATE_TEXT_START (sd),
                                       pc - STATE_TEXT_START (sd),
                                       &pc_filename, &pc_function, &pc_linenum)
                                       &pc_filename, &pc_function, &pc_linenum)
                && (pc_function || pc_filename))
                && (pc_function || pc_filename))
              {
              {
                char *p = buf+2;
                char *p = buf+2;
                buf[0] = ' ';
                buf[0] = ' ';
                buf[1] = '(';
                buf[1] = '(';
                if (pc_function)
                if (pc_function)
                  {
                  {
                    strcpy (p, pc_function);
                    strcpy (p, pc_function);
                    p += strlen (p);
                    p += strlen (p);
                  }
                  }
                else
                else
                  {
                  {
                    char *q = (char *) strrchr (pc_filename, '/');
                    char *q = (char *) strrchr (pc_filename, '/');
                    strcpy (p, (q) ? q+1 : pc_filename);
                    strcpy (p, (q) ? q+1 : pc_filename);
                    p += strlen (p);
                    p += strlen (p);
                  }
                  }
 
 
                if (pc_linenum)
                if (pc_linenum)
                  {
                  {
                    sprintf (p, " line %d", pc_linenum);
                    sprintf (p, " line %d", pc_linenum);
                    p += strlen (p);
                    p += strlen (p);
                  }
                  }
 
 
                p[0] = ')';
                p[0] = ')';
                p[1] = '\0';
                p[1] = '\0';
                if ((p+1) - buf > sizeof (buf))
                if ((p+1) - buf > sizeof (buf))
                  abort ();
                  abort ();
              }
              }
          }
          }
 
 
        sim_io_printf (sd,
        sim_io_printf (sd,
                       "\nRegister dump,    pc = 0x%.8x%s, base = %u, offset = %d\n",
                       "\nRegister dump,    pc = 0x%.8x%s, base = %u, offset = %d\n",
                       (unsigned)pc, buf, (unsigned)base, (int)offset);
                       (unsigned)pc, buf, (unsigned)base, (int)offset);
 
 
        for (i = 0; i < 64; i += 8)
        for (i = 0; i < 64; i += 8)
          {
          {
            long g0 = (long)GET_H_GR (i);
            long g0 = (long)GET_H_GR (i);
            long g1 = (long)GET_H_GR (i+1);
            long g1 = (long)GET_H_GR (i+1);
            long g2 = (long)GET_H_GR (i+2);
            long g2 = (long)GET_H_GR (i+2);
            long g3 = (long)GET_H_GR (i+3);
            long g3 = (long)GET_H_GR (i+3);
            long g4 = (long)GET_H_GR (i+4);
            long g4 = (long)GET_H_GR (i+4);
            long g5 = (long)GET_H_GR (i+5);
            long g5 = (long)GET_H_GR (i+5);
            long g6 = (long)GET_H_GR (i+6);
            long g6 = (long)GET_H_GR (i+6);
            long g7 = (long)GET_H_GR (i+7);
            long g7 = (long)GET_H_GR (i+7);
 
 
            if ((g0 | g1 | g2 | g3 | g4 | g5 | g6 | g7) != 0)
            if ((g0 | g1 | g2 | g3 | g4 | g5 | g6 | g7) != 0)
              sim_io_printf (sd,
              sim_io_printf (sd,
                             "\tgr%02d - gr%02d:   0x%.8lx 0x%.8lx 0x%.8lx 0x%.8lx 0x%.8lx 0x%.8lx 0x%.8lx 0x%.8lx\n",
                             "\tgr%02d - gr%02d:   0x%.8lx 0x%.8lx 0x%.8lx 0x%.8lx 0x%.8lx 0x%.8lx 0x%.8lx 0x%.8lx\n",
                             i, i+7, g0, g1, g2, g3, g4, g5, g6, g7);
                             i, i+7, g0, g1, g2, g3, g4, g5, g6, g7);
          }
          }
 
 
        for (i = 0; i < 64; i += 8)
        for (i = 0; i < 64; i += 8)
          {
          {
            long f0 = (long)GET_H_FR (i);
            long f0 = (long)GET_H_FR (i);
            long f1 = (long)GET_H_FR (i+1);
            long f1 = (long)GET_H_FR (i+1);
            long f2 = (long)GET_H_FR (i+2);
            long f2 = (long)GET_H_FR (i+2);
            long f3 = (long)GET_H_FR (i+3);
            long f3 = (long)GET_H_FR (i+3);
            long f4 = (long)GET_H_FR (i+4);
            long f4 = (long)GET_H_FR (i+4);
            long f5 = (long)GET_H_FR (i+5);
            long f5 = (long)GET_H_FR (i+5);
            long f6 = (long)GET_H_FR (i+6);
            long f6 = (long)GET_H_FR (i+6);
            long f7 = (long)GET_H_FR (i+7);
            long f7 = (long)GET_H_FR (i+7);
 
 
            if ((f0 | f1 | f2 | f3 | f4 | f5 | f6 | f7) != 0)
            if ((f0 | f1 | f2 | f3 | f4 | f5 | f6 | f7) != 0)
              sim_io_printf (sd,
              sim_io_printf (sd,
                             "\tfr%02d - fr%02d:   0x%.8lx 0x%.8lx 0x%.8lx 0x%.8lx 0x%.8lx 0x%.8lx 0x%.8lx 0x%.8lx\n",
                             "\tfr%02d - fr%02d:   0x%.8lx 0x%.8lx 0x%.8lx 0x%.8lx 0x%.8lx 0x%.8lx 0x%.8lx 0x%.8lx\n",
                             i, i+7, f0, f1, f2, f3, f4, f5, f6, f7);
                             i, i+7, f0, f1, f2, f3, f4, f5, f6, f7);
          }
          }
 
 
        sim_io_printf (sd,
        sim_io_printf (sd,
                       "\tlr/lcr/cc/ccc: 0x%.8lx 0x%.8lx 0x%.8lx 0x%.8lx\n",
                       "\tlr/lcr/cc/ccc: 0x%.8lx 0x%.8lx 0x%.8lx 0x%.8lx\n",
                       (long)GET_H_SPR (272),
                       (long)GET_H_SPR (272),
                       (long)GET_H_SPR (273),
                       (long)GET_H_SPR (273),
                       (long)GET_H_SPR (256),
                       (long)GET_H_SPR (256),
                       (long)GET_H_SPR (263));
                       (long)GET_H_SPR (263));
      }
      }
      break;
      break;
#endif
#endif
    }
    }
}
}
 
 
/* Handle the MTRAP insn.  */
/* Handle the MTRAP insn.  */
void
void
frv_mtrap (SIM_CPU *current_cpu)
frv_mtrap (SIM_CPU *current_cpu)
{
{
  SIM_DESC sd = CPU_STATE (current_cpu);
  SIM_DESC sd = CPU_STATE (current_cpu);
 
 
  /* Check the status of media exceptions in MSR0.  */
  /* Check the status of media exceptions in MSR0.  */
  SI msr = GET_MSR (0);
  SI msr = GET_MSR (0);
  if (GET_MSR_AOVF (msr) || GET_MSR_MTT (msr) && STATE_ARCHITECTURE (sd)->mach != bfd_mach_fr550)
  if (GET_MSR_AOVF (msr) || GET_MSR_MTT (msr) && STATE_ARCHITECTURE (sd)->mach != bfd_mach_fr550)
    frv_queue_program_interrupt (current_cpu, FRV_MP_EXCEPTION);
    frv_queue_program_interrupt (current_cpu, FRV_MP_EXCEPTION);
}
}
 
 
/* Handle the BREAK insn.  */
/* Handle the BREAK insn.  */
void
void
frv_break (SIM_CPU *current_cpu)
frv_break (SIM_CPU *current_cpu)
{
{
  IADDR pc;
  IADDR pc;
  SIM_DESC sd = CPU_STATE (current_cpu);
  SIM_DESC sd = CPU_STATE (current_cpu);
 
 
#ifdef SIM_HAVE_BREAKPOINTS
#ifdef SIM_HAVE_BREAKPOINTS
  /* First try sim-break.c.  If it's a breakpoint the simulator "owns"
  /* First try sim-break.c.  If it's a breakpoint the simulator "owns"
     it doesn't return.  Otherwise it returns and let's us try.  */
     it doesn't return.  Otherwise it returns and let's us try.  */
  pc = GET_H_PC ();
  pc = GET_H_PC ();
  sim_handle_breakpoint (sd, current_cpu, pc);
  sim_handle_breakpoint (sd, current_cpu, pc);
  /* Fall through.  */
  /* Fall through.  */
#endif
#endif
 
 
  if (STATE_ENVIRONMENT (sd) != OPERATING_ENVIRONMENT)
  if (STATE_ENVIRONMENT (sd) != OPERATING_ENVIRONMENT)
    {
    {
      /* Invalidate the insn cache because the debugger will presumably
      /* Invalidate the insn cache because the debugger will presumably
         replace the breakpoint insn with the real one.  */
         replace the breakpoint insn with the real one.  */
#ifndef SIM_HAVE_BREAKPOINTS
#ifndef SIM_HAVE_BREAKPOINTS
      pc = GET_H_PC ();
      pc = GET_H_PC ();
#endif
#endif
      sim_engine_halt (sd, current_cpu, NULL, pc, sim_stopped, SIM_SIGTRAP);
      sim_engine_halt (sd, current_cpu, NULL, pc, sim_stopped, SIM_SIGTRAP);
    }
    }
 
 
  frv_queue_break_interrupt (current_cpu);
  frv_queue_break_interrupt (current_cpu);
}
}
 
 
/* Return from trap.  */
/* Return from trap.  */
USI
USI
frv_rett (SIM_CPU *current_cpu, PCADDR pc, BI debug_field)
frv_rett (SIM_CPU *current_cpu, PCADDR pc, BI debug_field)
{
{
  USI new_pc;
  USI new_pc;
  /* if (normal running mode and debug_field==0
  /* if (normal running mode and debug_field==0
       PC=PCSR
       PC=PCSR
       PSR.ET=1
       PSR.ET=1
       PSR.S=PSR.PS
       PSR.S=PSR.PS
     else if (debug running mode and debug_field==1)
     else if (debug running mode and debug_field==1)
       PC=(BPCSR)
       PC=(BPCSR)
       PSR.ET=BPSR.BET
       PSR.ET=BPSR.BET
       PSR.S=BPSR.BS
       PSR.S=BPSR.BS
       change to normal running mode
       change to normal running mode
  */
  */
  int psr_s = GET_H_PSR_S ();
  int psr_s = GET_H_PSR_S ();
  int psr_et = GET_H_PSR_ET ();
  int psr_et = GET_H_PSR_ET ();
 
 
  /* Check for exceptions in the priority order listed in the FRV Architecture
  /* Check for exceptions in the priority order listed in the FRV Architecture
     Volume 2.  */
     Volume 2.  */
  if (! psr_s)
  if (! psr_s)
    {
    {
      /* Halt if PSR.ET is not set.  See chapter 6 of the LSI.  */
      /* Halt if PSR.ET is not set.  See chapter 6 of the LSI.  */
      if (! psr_et)
      if (! psr_et)
        {
        {
          SIM_DESC sd = CPU_STATE (current_cpu);
          SIM_DESC sd = CPU_STATE (current_cpu);
          sim_engine_halt (sd, current_cpu, NULL, pc, sim_stopped, SIM_SIGTRAP);
          sim_engine_halt (sd, current_cpu, NULL, pc, sim_stopped, SIM_SIGTRAP);
        }
        }
 
 
      /* privileged_instruction interrupt will have already been queued by
      /* privileged_instruction interrupt will have already been queued by
         frv_detect_insn_access_interrupts.  */
         frv_detect_insn_access_interrupts.  */
      new_pc = pc + 4;
      new_pc = pc + 4;
    }
    }
  else if (psr_et)
  else if (psr_et)
    {
    {
      /* Halt if PSR.S is set.  See chapter 6 of the LSI.  */
      /* Halt if PSR.S is set.  See chapter 6 of the LSI.  */
      if (psr_s)
      if (psr_s)
        {
        {
          SIM_DESC sd = CPU_STATE (current_cpu);
          SIM_DESC sd = CPU_STATE (current_cpu);
          sim_engine_halt (sd, current_cpu, NULL, pc, sim_stopped, SIM_SIGTRAP);
          sim_engine_halt (sd, current_cpu, NULL, pc, sim_stopped, SIM_SIGTRAP);
        }
        }
 
 
      frv_queue_program_interrupt (current_cpu, FRV_ILLEGAL_INSTRUCTION);
      frv_queue_program_interrupt (current_cpu, FRV_ILLEGAL_INSTRUCTION);
      new_pc = pc + 4;
      new_pc = pc + 4;
    }
    }
  else if (! CPU_DEBUG_STATE (current_cpu) && debug_field == 0)
  else if (! CPU_DEBUG_STATE (current_cpu) && debug_field == 0)
    {
    {
      USI psr = GET_PSR ();
      USI psr = GET_PSR ();
      /* Return from normal running state.  */
      /* Return from normal running state.  */
      new_pc = GET_H_SPR (H_SPR_PCSR);
      new_pc = GET_H_SPR (H_SPR_PCSR);
      SET_PSR_ET (psr, 1);
      SET_PSR_ET (psr, 1);
      SET_PSR_S (psr, GET_PSR_PS (psr));
      SET_PSR_S (psr, GET_PSR_PS (psr));
      sim_queue_fn_si_write (current_cpu, frvbf_h_spr_set, H_SPR_PSR, psr);
      sim_queue_fn_si_write (current_cpu, frvbf_h_spr_set, H_SPR_PSR, psr);
    }
    }
  else if (CPU_DEBUG_STATE (current_cpu) && debug_field == 1)
  else if (CPU_DEBUG_STATE (current_cpu) && debug_field == 1)
    {
    {
      USI psr = GET_PSR ();
      USI psr = GET_PSR ();
      /* Return from debug state.  */
      /* Return from debug state.  */
      new_pc = GET_H_SPR (H_SPR_BPCSR);
      new_pc = GET_H_SPR (H_SPR_BPCSR);
      SET_PSR_ET (psr, GET_H_BPSR_BET ());
      SET_PSR_ET (psr, GET_H_BPSR_BET ());
      SET_PSR_S (psr, GET_H_BPSR_BS ());
      SET_PSR_S (psr, GET_H_BPSR_BS ());
      sim_queue_fn_si_write (current_cpu, frvbf_h_spr_set, H_SPR_PSR, psr);
      sim_queue_fn_si_write (current_cpu, frvbf_h_spr_set, H_SPR_PSR, psr);
      CPU_DEBUG_STATE (current_cpu) = 0;
      CPU_DEBUG_STATE (current_cpu) = 0;
    }
    }
  else
  else
    new_pc = pc + 4;
    new_pc = pc + 4;
 
 
  return new_pc;
  return new_pc;
}
}


/* Functions for handling non-excepting instruction side effects.  */
/* Functions for handling non-excepting instruction side effects.  */
static SI next_available_nesr (SIM_CPU *current_cpu, SI current_index)
static SI next_available_nesr (SIM_CPU *current_cpu, SI current_index)
{
{
  FRV_REGISTER_CONTROL *control = CPU_REGISTER_CONTROL (current_cpu);
  FRV_REGISTER_CONTROL *control = CPU_REGISTER_CONTROL (current_cpu);
  if (control->spr[H_SPR_NECR].implemented)
  if (control->spr[H_SPR_NECR].implemented)
    {
    {
      int limit;
      int limit;
      USI necr = GET_NECR ();
      USI necr = GET_NECR ();
 
 
      /* See if any NESRs are implemented. First need to check the validity of
      /* See if any NESRs are implemented. First need to check the validity of
         the NECR.  */
         the NECR.  */
      if (! GET_NECR_VALID (necr))
      if (! GET_NECR_VALID (necr))
        return NO_NESR;
        return NO_NESR;
 
 
      limit = GET_NECR_NEN (necr);
      limit = GET_NECR_NEN (necr);
      for (++current_index; current_index < limit; ++current_index)
      for (++current_index; current_index < limit; ++current_index)
        {
        {
          SI nesr = GET_NESR (current_index);
          SI nesr = GET_NESR (current_index);
          if (! GET_NESR_VALID (nesr))
          if (! GET_NESR_VALID (nesr))
            return current_index;
            return current_index;
        }
        }
    }
    }
  return NO_NESR;
  return NO_NESR;
}
}
 
 
static SI next_valid_nesr (SIM_CPU *current_cpu, SI current_index)
static SI next_valid_nesr (SIM_CPU *current_cpu, SI current_index)
{
{
  FRV_REGISTER_CONTROL *control = CPU_REGISTER_CONTROL (current_cpu);
  FRV_REGISTER_CONTROL *control = CPU_REGISTER_CONTROL (current_cpu);
  if (control->spr[H_SPR_NECR].implemented)
  if (control->spr[H_SPR_NECR].implemented)
    {
    {
      int limit;
      int limit;
      USI necr = GET_NECR ();
      USI necr = GET_NECR ();
 
 
      /* See if any NESRs are implemented. First need to check the validity of
      /* See if any NESRs are implemented. First need to check the validity of
         the NECR.  */
         the NECR.  */
      if (! GET_NECR_VALID (necr))
      if (! GET_NECR_VALID (necr))
        return NO_NESR;
        return NO_NESR;
 
 
      limit = GET_NECR_NEN (necr);
      limit = GET_NECR_NEN (necr);
      for (++current_index; current_index < limit; ++current_index)
      for (++current_index; current_index < limit; ++current_index)
        {
        {
          SI nesr = GET_NESR (current_index);
          SI nesr = GET_NESR (current_index);
          if (GET_NESR_VALID (nesr))
          if (GET_NESR_VALID (nesr))
            return current_index;
            return current_index;
        }
        }
    }
    }
  return NO_NESR;
  return NO_NESR;
}
}
 
 
BI
BI
frvbf_check_non_excepting_load (
frvbf_check_non_excepting_load (
  SIM_CPU *current_cpu, SI base_index, SI disp_index, SI target_index,
  SIM_CPU *current_cpu, SI base_index, SI disp_index, SI target_index,
  SI immediate_disp, QI data_size, BI is_float
  SI immediate_disp, QI data_size, BI is_float
)
)
{
{
  BI rc = 1; /* perform the load.  */
  BI rc = 1; /* perform the load.  */
  SIM_DESC sd = CPU_STATE (current_cpu);
  SIM_DESC sd = CPU_STATE (current_cpu);
  int daec = 0;
  int daec = 0;
  int rec  = 0;
  int rec  = 0;
  int ec   = 0;
  int ec   = 0;
  USI necr;
  USI necr;
  int do_elos;
  int do_elos;
  SI NE_flags[2];
  SI NE_flags[2];
  SI NE_base;
  SI NE_base;
  SI nesr;
  SI nesr;
  SI ne_index;
  SI ne_index;
  FRV_REGISTER_CONTROL *control;
  FRV_REGISTER_CONTROL *control;
 
 
  SI address = GET_H_GR (base_index);
  SI address = GET_H_GR (base_index);
  if (disp_index >= 0)
  if (disp_index >= 0)
    address += GET_H_GR (disp_index);
    address += GET_H_GR (disp_index);
  else
  else
    address += immediate_disp;
    address += immediate_disp;
 
 
  /* Check for interrupt factors.  */
  /* Check for interrupt factors.  */
  switch (data_size)
  switch (data_size)
    {
    {
    case NESR_UQI_SIZE:
    case NESR_UQI_SIZE:
    case NESR_QI_SIZE:
    case NESR_QI_SIZE:
      break;
      break;
    case NESR_UHI_SIZE:
    case NESR_UHI_SIZE:
    case NESR_HI_SIZE:
    case NESR_HI_SIZE:
      if (address & 1)
      if (address & 1)
        ec = 1;
        ec = 1;
      break;
      break;
    case NESR_SI_SIZE:
    case NESR_SI_SIZE:
      if (address & 3)
      if (address & 3)
        ec = 1;
        ec = 1;
      break;
      break;
    case NESR_DI_SIZE:
    case NESR_DI_SIZE:
      if (address & 7)
      if (address & 7)
        ec = 1;
        ec = 1;
      if (target_index & 1)
      if (target_index & 1)
        rec = 1;
        rec = 1;
      break;
      break;
    case NESR_XI_SIZE:
    case NESR_XI_SIZE:
      if (address & 0xf)
      if (address & 0xf)
        ec = 1;
        ec = 1;
      if (target_index & 3)
      if (target_index & 3)
        rec = 1;
        rec = 1;
      break;
      break;
    default:
    default:
      {
      {
        IADDR pc = GET_H_PC ();
        IADDR pc = GET_H_PC ();
        sim_engine_abort (sd, current_cpu, pc,
        sim_engine_abort (sd, current_cpu, pc,
                          "check_non_excepting_load: Incorrect data_size\n");
                          "check_non_excepting_load: Incorrect data_size\n");
        break;
        break;
      }
      }
    }
    }
 
 
  control = CPU_REGISTER_CONTROL (current_cpu);
  control = CPU_REGISTER_CONTROL (current_cpu);
  if (control->spr[H_SPR_NECR].implemented)
  if (control->spr[H_SPR_NECR].implemented)
    {
    {
      necr = GET_NECR ();
      necr = GET_NECR ();
      do_elos = GET_NECR_VALID (necr) && GET_NECR_ELOS (necr);
      do_elos = GET_NECR_VALID (necr) && GET_NECR_ELOS (necr);
    }
    }
  else
  else
    do_elos = 0;
    do_elos = 0;
 
 
  /* NECR, NESR, NEEAR are only implemented for the full frv machine.  */
  /* NECR, NESR, NEEAR are only implemented for the full frv machine.  */
  if (do_elos)
  if (do_elos)
    {
    {
      ne_index = next_available_nesr (current_cpu, NO_NESR);
      ne_index = next_available_nesr (current_cpu, NO_NESR);
      if (ne_index == NO_NESR)
      if (ne_index == NO_NESR)
        {
        {
          IADDR pc = GET_H_PC ();
          IADDR pc = GET_H_PC ();
          sim_engine_abort (sd, current_cpu, pc,
          sim_engine_abort (sd, current_cpu, pc,
                            "No available NESR register\n");
                            "No available NESR register\n");
        }
        }
 
 
      /* Fill in the basic fields of the NESR.  */
      /* Fill in the basic fields of the NESR.  */
      nesr = GET_NESR (ne_index);
      nesr = GET_NESR (ne_index);
      SET_NESR_VALID (nesr);
      SET_NESR_VALID (nesr);
      SET_NESR_EAV (nesr);
      SET_NESR_EAV (nesr);
      SET_NESR_DRN (nesr, target_index);
      SET_NESR_DRN (nesr, target_index);
      SET_NESR_SIZE (nesr, data_size);
      SET_NESR_SIZE (nesr, data_size);
      SET_NESR_NEAN (nesr, ne_index);
      SET_NESR_NEAN (nesr, ne_index);
      if (is_float)
      if (is_float)
        SET_NESR_FR (nesr);
        SET_NESR_FR (nesr);
      else
      else
        CLEAR_NESR_FR (nesr);
        CLEAR_NESR_FR (nesr);
 
 
      /* Set the corresponding NEEAR.  */
      /* Set the corresponding NEEAR.  */
      SET_NEEAR (ne_index, address);
      SET_NEEAR (ne_index, address);
 
 
      SET_NESR_DAEC (nesr, 0);
      SET_NESR_DAEC (nesr, 0);
      SET_NESR_REC (nesr, 0);
      SET_NESR_REC (nesr, 0);
      SET_NESR_EC (nesr, 0);
      SET_NESR_EC (nesr, 0);
    }
    }
 
 
  /* Set the NE flag corresponding to the target register if an interrupt
  /* Set the NE flag corresponding to the target register if an interrupt
     factor was detected.
     factor was detected.
     daec is not checked here yet, but is declared for future reference.  */
     daec is not checked here yet, but is declared for future reference.  */
  if (is_float)
  if (is_float)
    NE_base = H_SPR_FNER0;
    NE_base = H_SPR_FNER0;
  else
  else
    NE_base = H_SPR_GNER0;
    NE_base = H_SPR_GNER0;
 
 
  GET_NE_FLAGS (NE_flags, NE_base);
  GET_NE_FLAGS (NE_flags, NE_base);
  if (rec)
  if (rec)
    {
    {
      SET_NE_FLAG (NE_flags, target_index);
      SET_NE_FLAG (NE_flags, target_index);
      if (do_elos)
      if (do_elos)
        SET_NESR_REC (nesr, NESR_REGISTER_NOT_ALIGNED);
        SET_NESR_REC (nesr, NESR_REGISTER_NOT_ALIGNED);
    }
    }
 
 
  if (ec)
  if (ec)
    {
    {
      SET_NE_FLAG (NE_flags, target_index);
      SET_NE_FLAG (NE_flags, target_index);
      if (do_elos)
      if (do_elos)
        SET_NESR_EC (nesr, NESR_MEM_ADDRESS_NOT_ALIGNED);
        SET_NESR_EC (nesr, NESR_MEM_ADDRESS_NOT_ALIGNED);
    }
    }
 
 
  if (do_elos)
  if (do_elos)
    SET_NESR (ne_index, nesr);
    SET_NESR (ne_index, nesr);
 
 
  /* If no interrupt factor was detected then set the NE flag on the
  /* If no interrupt factor was detected then set the NE flag on the
     target register if the NE flag on one of the input registers
     target register if the NE flag on one of the input registers
     is already set.  */
     is already set.  */
  if (! rec && ! ec && ! daec)
  if (! rec && ! ec && ! daec)
    {
    {
      BI ne_flag = GET_NE_FLAG (NE_flags, base_index);
      BI ne_flag = GET_NE_FLAG (NE_flags, base_index);
      if (disp_index >= 0)
      if (disp_index >= 0)
        ne_flag |= GET_NE_FLAG (NE_flags, disp_index);
        ne_flag |= GET_NE_FLAG (NE_flags, disp_index);
      if (ne_flag)
      if (ne_flag)
        {
        {
          SET_NE_FLAG (NE_flags, target_index);
          SET_NE_FLAG (NE_flags, target_index);
          rc = 0; /* Do not perform the load.  */
          rc = 0; /* Do not perform the load.  */
        }
        }
      else
      else
        CLEAR_NE_FLAG (NE_flags, target_index);
        CLEAR_NE_FLAG (NE_flags, target_index);
    }
    }
 
 
  SET_NE_FLAGS (NE_base, NE_flags);
  SET_NE_FLAGS (NE_base, NE_flags);
 
 
  return rc; /* perform the load?  */
  return rc; /* perform the load?  */
}
}
 
 
/* Record state for media exception: media_cr_not_aligned.  */
/* Record state for media exception: media_cr_not_aligned.  */
void
void
frvbf_media_cr_not_aligned (SIM_CPU *current_cpu)
frvbf_media_cr_not_aligned (SIM_CPU *current_cpu)
{
{
  SIM_DESC sd = CPU_STATE (current_cpu);
  SIM_DESC sd = CPU_STATE (current_cpu);
 
 
  /* On some machines this generates an illegal_instruction interrupt.  */
  /* On some machines this generates an illegal_instruction interrupt.  */
  switch (STATE_ARCHITECTURE (sd)->mach)
  switch (STATE_ARCHITECTURE (sd)->mach)
    {
    {
      /* Note: there is a discrepancy between V2.2 of the FR400
      /* Note: there is a discrepancy between V2.2 of the FR400
         instruction manual and the various FR4xx LSI specs.  The former
         instruction manual and the various FR4xx LSI specs.  The former
         claims that unaligned registers cause an mp_exception while the
         claims that unaligned registers cause an mp_exception while the
         latter say it's an illegal_instruction.  The LSI specs appear
         latter say it's an illegal_instruction.  The LSI specs appear
         to be correct since MTT is fixed at 1.  */
         to be correct since MTT is fixed at 1.  */
    case bfd_mach_fr400:
    case bfd_mach_fr400:
    case bfd_mach_fr450:
    case bfd_mach_fr450:
    case bfd_mach_fr550:
    case bfd_mach_fr550:
      frv_queue_program_interrupt (current_cpu, FRV_ILLEGAL_INSTRUCTION);
      frv_queue_program_interrupt (current_cpu, FRV_ILLEGAL_INSTRUCTION);
      break;
      break;
    default:
    default:
      frv_set_mp_exception_registers (current_cpu, MTT_CR_NOT_ALIGNED, 0);
      frv_set_mp_exception_registers (current_cpu, MTT_CR_NOT_ALIGNED, 0);
      break;
      break;
    }
    }
}
}
 
 
/* Record state for media exception: media_acc_not_aligned.  */
/* Record state for media exception: media_acc_not_aligned.  */
void
void
frvbf_media_acc_not_aligned (SIM_CPU *current_cpu)
frvbf_media_acc_not_aligned (SIM_CPU *current_cpu)
{
{
  SIM_DESC sd = CPU_STATE (current_cpu);
  SIM_DESC sd = CPU_STATE (current_cpu);
 
 
  /* On some machines this generates an illegal_instruction interrupt.  */
  /* On some machines this generates an illegal_instruction interrupt.  */
  switch (STATE_ARCHITECTURE (sd)->mach)
  switch (STATE_ARCHITECTURE (sd)->mach)
    {
    {
      /* See comment in frvbf_cr_not_aligned().  */
      /* See comment in frvbf_cr_not_aligned().  */
    case bfd_mach_fr400:
    case bfd_mach_fr400:
    case bfd_mach_fr450:
    case bfd_mach_fr450:
    case bfd_mach_fr550:
    case bfd_mach_fr550:
      frv_queue_program_interrupt (current_cpu, FRV_ILLEGAL_INSTRUCTION);
      frv_queue_program_interrupt (current_cpu, FRV_ILLEGAL_INSTRUCTION);
      break;
      break;
    default:
    default:
      frv_set_mp_exception_registers (current_cpu, MTT_ACC_NOT_ALIGNED, 0);
      frv_set_mp_exception_registers (current_cpu, MTT_ACC_NOT_ALIGNED, 0);
      break;
      break;
    }
    }
}
}
 
 
/* Record state for media exception: media_register_not_aligned.  */
/* Record state for media exception: media_register_not_aligned.  */
void
void
frvbf_media_register_not_aligned (SIM_CPU *current_cpu)
frvbf_media_register_not_aligned (SIM_CPU *current_cpu)
{
{
  SIM_DESC sd = CPU_STATE (current_cpu);
  SIM_DESC sd = CPU_STATE (current_cpu);
 
 
  /* On some machines this generates an illegal_instruction interrupt.  */
  /* On some machines this generates an illegal_instruction interrupt.  */
  switch (STATE_ARCHITECTURE (sd)->mach)
  switch (STATE_ARCHITECTURE (sd)->mach)
    {
    {
      /* See comment in frvbf_cr_not_aligned().  */
      /* See comment in frvbf_cr_not_aligned().  */
    case bfd_mach_fr400:
    case bfd_mach_fr400:
    case bfd_mach_fr450:
    case bfd_mach_fr450:
    case bfd_mach_fr550:
    case bfd_mach_fr550:
      frv_queue_program_interrupt (current_cpu, FRV_ILLEGAL_INSTRUCTION);
      frv_queue_program_interrupt (current_cpu, FRV_ILLEGAL_INSTRUCTION);
      break;
      break;
    default:
    default:
      frv_set_mp_exception_registers (current_cpu, MTT_INVALID_FR, 0);
      frv_set_mp_exception_registers (current_cpu, MTT_INVALID_FR, 0);
      break;
      break;
    }
    }
}
}
 
 
/* Record state for media exception: media_overflow.  */
/* Record state for media exception: media_overflow.  */
void
void
frvbf_media_overflow (SIM_CPU *current_cpu, int sie)
frvbf_media_overflow (SIM_CPU *current_cpu, int sie)
{
{
  frv_set_mp_exception_registers (current_cpu, MTT_OVERFLOW, sie);
  frv_set_mp_exception_registers (current_cpu, MTT_OVERFLOW, sie);
}
}
 
 
/* Queue a division exception.  */
/* Queue a division exception.  */
enum frv_dtt
enum frv_dtt
frvbf_division_exception (SIM_CPU *current_cpu, enum frv_dtt dtt,
frvbf_division_exception (SIM_CPU *current_cpu, enum frv_dtt dtt,
                          int target_index, int non_excepting)
                          int target_index, int non_excepting)
{
{
  /* If there was an overflow and it is masked, then record it in
  /* If there was an overflow and it is masked, then record it in
     ISR.AEXC.  */
     ISR.AEXC.  */
  USI isr = GET_ISR ();
  USI isr = GET_ISR ();
  if ((dtt & FRV_DTT_OVERFLOW) && GET_ISR_EDE (isr))
  if ((dtt & FRV_DTT_OVERFLOW) && GET_ISR_EDE (isr))
    {
    {
      dtt &= ~FRV_DTT_OVERFLOW;
      dtt &= ~FRV_DTT_OVERFLOW;
      SET_ISR_AEXC (isr);
      SET_ISR_AEXC (isr);
      SET_ISR (isr);
      SET_ISR (isr);
    }
    }
  if (dtt != FRV_DTT_NO_EXCEPTION)
  if (dtt != FRV_DTT_NO_EXCEPTION)
    {
    {
      if (non_excepting)
      if (non_excepting)
        {
        {
          /* Non excepting instruction, simply set the NE flag for the target
          /* Non excepting instruction, simply set the NE flag for the target
             register.  */
             register.  */
          SI NE_flags[2];
          SI NE_flags[2];
          GET_NE_FLAGS (NE_flags, H_SPR_GNER0);
          GET_NE_FLAGS (NE_flags, H_SPR_GNER0);
          SET_NE_FLAG (NE_flags, target_index);
          SET_NE_FLAG (NE_flags, target_index);
          SET_NE_FLAGS (H_SPR_GNER0, NE_flags);
          SET_NE_FLAGS (H_SPR_GNER0, NE_flags);
        }
        }
      else
      else
        frv_queue_division_exception_interrupt (current_cpu, dtt);
        frv_queue_division_exception_interrupt (current_cpu, dtt);
    }
    }
  return dtt;
  return dtt;
}
}
 
 
void
void
frvbf_check_recovering_store (
frvbf_check_recovering_store (
  SIM_CPU *current_cpu, PCADDR address, SI regno, int size, int is_float
  SIM_CPU *current_cpu, PCADDR address, SI regno, int size, int is_float
)
)
{
{
  FRV_CACHE *cache = CPU_DATA_CACHE (current_cpu);
  FRV_CACHE *cache = CPU_DATA_CACHE (current_cpu);
  int reg_ix;
  int reg_ix;
 
 
  CPU_RSTR_INVALIDATE(current_cpu) = 0;
  CPU_RSTR_INVALIDATE(current_cpu) = 0;
 
 
  for (reg_ix = next_valid_nesr (current_cpu, NO_NESR);
  for (reg_ix = next_valid_nesr (current_cpu, NO_NESR);
       reg_ix != NO_NESR;
       reg_ix != NO_NESR;
       reg_ix = next_valid_nesr (current_cpu, reg_ix))
       reg_ix = next_valid_nesr (current_cpu, reg_ix))
    {
    {
      if (address == GET_H_SPR (H_SPR_NEEAR0 + reg_ix))
      if (address == GET_H_SPR (H_SPR_NEEAR0 + reg_ix))
        {
        {
          SI nesr = GET_NESR (reg_ix);
          SI nesr = GET_NESR (reg_ix);
          int nesr_drn = GET_NESR_DRN (nesr);
          int nesr_drn = GET_NESR_DRN (nesr);
          BI nesr_fr = GET_NESR_FR (nesr);
          BI nesr_fr = GET_NESR_FR (nesr);
          SI remain;
          SI remain;
 
 
          /* Invalidate cache block containing this address.
          /* Invalidate cache block containing this address.
             If we need to count cycles, then the cache operation will be
             If we need to count cycles, then the cache operation will be
             initiated from the model profiling functions.
             initiated from the model profiling functions.
             See frvbf_model_....  */
             See frvbf_model_....  */
          if (model_insn)
          if (model_insn)
            {
            {
              CPU_RSTR_INVALIDATE(current_cpu) = 1;
              CPU_RSTR_INVALIDATE(current_cpu) = 1;
              CPU_LOAD_ADDRESS (current_cpu) = address;
              CPU_LOAD_ADDRESS (current_cpu) = address;
            }
            }
          else
          else
            frv_cache_invalidate (cache, address, 1/* flush */);
            frv_cache_invalidate (cache, address, 1/* flush */);
 
 
          /* Copy the stored value to the register indicated by NESR.DRN.  */
          /* Copy the stored value to the register indicated by NESR.DRN.  */
          for (remain = size; remain > 0; remain -= 4)
          for (remain = size; remain > 0; remain -= 4)
            {
            {
              SI value;
              SI value;
 
 
              if (is_float)
              if (is_float)
                value = GET_H_FR (regno);
                value = GET_H_FR (regno);
              else
              else
                value = GET_H_GR (regno);
                value = GET_H_GR (regno);
 
 
              switch (size)
              switch (size)
                {
                {
                case 1:
                case 1:
                  value &= 0xff;
                  value &= 0xff;
                  break;
                  break;
                case 2:
                case 2:
                  value &= 0xffff;
                  value &= 0xffff;
                  break;
                  break;
                default:
                default:
                  break;
                  break;
                }
                }
 
 
              if (nesr_fr)
              if (nesr_fr)
                sim_queue_fn_sf_write (current_cpu, frvbf_h_fr_set, nesr_drn,
                sim_queue_fn_sf_write (current_cpu, frvbf_h_fr_set, nesr_drn,
                                       value);
                                       value);
              else
              else
                sim_queue_fn_si_write (current_cpu, frvbf_h_gr_set, nesr_drn,
                sim_queue_fn_si_write (current_cpu, frvbf_h_gr_set, nesr_drn,
                                       value);
                                       value);
 
 
              nesr_drn++;
              nesr_drn++;
              regno++;
              regno++;
            }
            }
          break; /* Only consider the first matching register.  */
          break; /* Only consider the first matching register.  */
        }
        }
    } /* loop over active neear registers.  */
    } /* loop over active neear registers.  */
}
}
 
 
SI
SI
frvbf_check_acc_range (SIM_CPU *current_cpu, SI regno)
frvbf_check_acc_range (SIM_CPU *current_cpu, SI regno)
{
{
  /* Only applicable to fr550 */
  /* Only applicable to fr550 */
  SIM_DESC sd = CPU_STATE (current_cpu);
  SIM_DESC sd = CPU_STATE (current_cpu);
  if (STATE_ARCHITECTURE (sd)->mach != bfd_mach_fr550)
  if (STATE_ARCHITECTURE (sd)->mach != bfd_mach_fr550)
    return;
    return;
 
 
  /* On the fr550, media insns in slots 0 and 2 can only access
  /* On the fr550, media insns in slots 0 and 2 can only access
     accumulators acc0-acc3. Insns in slots 1 and 3 can only access
     accumulators acc0-acc3. Insns in slots 1 and 3 can only access
     accumulators acc4-acc7 */
     accumulators acc4-acc7 */
  switch (frv_current_fm_slot)
  switch (frv_current_fm_slot)
    {
    {
    case UNIT_FM0:
    case UNIT_FM0:
    case UNIT_FM2:
    case UNIT_FM2:
      if (regno <= 3)
      if (regno <= 3)
        return 1; /* all is ok */
        return 1; /* all is ok */
      break;
      break;
    case UNIT_FM1:
    case UNIT_FM1:
    case UNIT_FM3:
    case UNIT_FM3:
      if (regno >= 4)
      if (regno >= 4)
        return 1; /* all is ok */
        return 1; /* all is ok */
      break;
      break;
    }
    }
 
 
  /* The specified accumulator is out of range. Queue an illegal_instruction
  /* The specified accumulator is out of range. Queue an illegal_instruction
     interrupt.  */
     interrupt.  */
  frv_queue_program_interrupt (current_cpu, FRV_ILLEGAL_INSTRUCTION);
  frv_queue_program_interrupt (current_cpu, FRV_ILLEGAL_INSTRUCTION);
  return 0;
  return 0;
}
}
 
 
void
void
frvbf_check_swap_address (SIM_CPU *current_cpu, SI address)
frvbf_check_swap_address (SIM_CPU *current_cpu, SI address)
{
{
  /* Only applicable to fr550 */
  /* Only applicable to fr550 */
  SIM_DESC sd = CPU_STATE (current_cpu);
  SIM_DESC sd = CPU_STATE (current_cpu);
  if (STATE_ARCHITECTURE (sd)->mach != bfd_mach_fr550)
  if (STATE_ARCHITECTURE (sd)->mach != bfd_mach_fr550)
    return;
    return;
 
 
  /* Adress must be aligned on a word boundary.  */
  /* Adress must be aligned on a word boundary.  */
  if (address & 0x3)
  if (address & 0x3)
    frv_queue_data_access_exception_interrupt (current_cpu);
    frv_queue_data_access_exception_interrupt (current_cpu);
}
}
 
 
static void
static void
clear_nesr_neear (SIM_CPU *current_cpu, SI target_index, BI is_float)
clear_nesr_neear (SIM_CPU *current_cpu, SI target_index, BI is_float)
{
{
  int reg_ix;
  int reg_ix;
 
 
  /* Only implemented for full frv.  */
  /* Only implemented for full frv.  */
  SIM_DESC sd = CPU_STATE (current_cpu);
  SIM_DESC sd = CPU_STATE (current_cpu);
  if (STATE_ARCHITECTURE (sd)->mach != bfd_mach_frv)
  if (STATE_ARCHITECTURE (sd)->mach != bfd_mach_frv)
    return;
    return;
 
 
  /* Clear the appropriate NESR and NEEAR registers.  */
  /* Clear the appropriate NESR and NEEAR registers.  */
  for (reg_ix = next_valid_nesr (current_cpu, NO_NESR);
  for (reg_ix = next_valid_nesr (current_cpu, NO_NESR);
       reg_ix != NO_NESR;
       reg_ix != NO_NESR;
       reg_ix = next_valid_nesr (current_cpu, reg_ix))
       reg_ix = next_valid_nesr (current_cpu, reg_ix))
    {
    {
      SI nesr;
      SI nesr;
      /* The register is available, now check if it is active.  */
      /* The register is available, now check if it is active.  */
      nesr = GET_NESR (reg_ix);
      nesr = GET_NESR (reg_ix);
      if (GET_NESR_FR (nesr) == is_float)
      if (GET_NESR_FR (nesr) == is_float)
        {
        {
          if (target_index < 0 || GET_NESR_DRN (nesr) == target_index)
          if (target_index < 0 || GET_NESR_DRN (nesr) == target_index)
            {
            {
              SET_NESR (reg_ix, 0);
              SET_NESR (reg_ix, 0);
              SET_NEEAR (reg_ix, 0);
              SET_NEEAR (reg_ix, 0);
            }
            }
        }
        }
    }
    }
}
}
 
 
static void
static void
clear_ne_flags (
clear_ne_flags (
  SIM_CPU *current_cpu,
  SIM_CPU *current_cpu,
  SI target_index,
  SI target_index,
  int hi_available,
  int hi_available,
  int lo_available,
  int lo_available,
  SI NE_base
  SI NE_base
)
)
{
{
  SI NE_flags[2];
  SI NE_flags[2];
  int exception;
  int exception;
 
 
  GET_NE_FLAGS (NE_flags, NE_base);
  GET_NE_FLAGS (NE_flags, NE_base);
  if (target_index >= 0)
  if (target_index >= 0)
    CLEAR_NE_FLAG (NE_flags, target_index);
    CLEAR_NE_FLAG (NE_flags, target_index);
  else
  else
    {
    {
      if (lo_available)
      if (lo_available)
        NE_flags[1] = 0;
        NE_flags[1] = 0;
      if (hi_available)
      if (hi_available)
        NE_flags[0] = 0;
        NE_flags[0] = 0;
    }
    }
  SET_NE_FLAGS (NE_base, NE_flags);
  SET_NE_FLAGS (NE_base, NE_flags);
}
}
 
 
/* Return 1 if the given register is available, 0 otherwise.  TARGET_INDEX==-1
/* Return 1 if the given register is available, 0 otherwise.  TARGET_INDEX==-1
   means to check for any register available.  */
   means to check for any register available.  */
static void
static void
which_registers_available (
which_registers_available (
  SIM_CPU *current_cpu, int *hi_available, int *lo_available, int is_float
  SIM_CPU *current_cpu, int *hi_available, int *lo_available, int is_float
)
)
{
{
  if (is_float)
  if (is_float)
    frv_fr_registers_available (current_cpu, hi_available, lo_available);
    frv_fr_registers_available (current_cpu, hi_available, lo_available);
  else
  else
    frv_gr_registers_available (current_cpu, hi_available, lo_available);
    frv_gr_registers_available (current_cpu, hi_available, lo_available);
}
}
 
 
void
void
frvbf_clear_ne_flags (SIM_CPU *current_cpu, SI target_index, BI is_float)
frvbf_clear_ne_flags (SIM_CPU *current_cpu, SI target_index, BI is_float)
{
{
  int hi_available;
  int hi_available;
  int lo_available;
  int lo_available;
  int exception;
  int exception;
  SI NE_base;
  SI NE_base;
  USI necr;
  USI necr;
  FRV_REGISTER_CONTROL *control;
  FRV_REGISTER_CONTROL *control;
 
 
  /* Check for availability of the target register(s).  */
  /* Check for availability of the target register(s).  */
  which_registers_available (current_cpu, & hi_available, & lo_available,
  which_registers_available (current_cpu, & hi_available, & lo_available,
                             is_float);
                             is_float);
 
 
  /* Check to make sure that the target register is available.  */
  /* Check to make sure that the target register is available.  */
  if (! frv_check_register_access (current_cpu, target_index,
  if (! frv_check_register_access (current_cpu, target_index,
                                   hi_available, lo_available))
                                   hi_available, lo_available))
    return;
    return;
 
 
  /* Determine whether we're working with GR or FR registers.  */
  /* Determine whether we're working with GR or FR registers.  */
  if (is_float)
  if (is_float)
    NE_base = H_SPR_FNER0;
    NE_base = H_SPR_FNER0;
  else
  else
    NE_base = H_SPR_GNER0;
    NE_base = H_SPR_GNER0;
 
 
  /* Always clear the appropriate NE flags.  */
  /* Always clear the appropriate NE flags.  */
  clear_ne_flags (current_cpu, target_index, hi_available, lo_available,
  clear_ne_flags (current_cpu, target_index, hi_available, lo_available,
                  NE_base);
                  NE_base);
 
 
  /* Clear the appropriate NESR and NEEAR registers.  */
  /* Clear the appropriate NESR and NEEAR registers.  */
  control = CPU_REGISTER_CONTROL (current_cpu);
  control = CPU_REGISTER_CONTROL (current_cpu);
  if (control->spr[H_SPR_NECR].implemented)
  if (control->spr[H_SPR_NECR].implemented)
    {
    {
      necr = GET_NECR ();
      necr = GET_NECR ();
      if (GET_NECR_VALID (necr) && GET_NECR_ELOS (necr))
      if (GET_NECR_VALID (necr) && GET_NECR_ELOS (necr))
        clear_nesr_neear (current_cpu, target_index, is_float);
        clear_nesr_neear (current_cpu, target_index, is_float);
    }
    }
}
}
 
 
void
void
frvbf_commit (SIM_CPU *current_cpu, SI target_index, BI is_float)
frvbf_commit (SIM_CPU *current_cpu, SI target_index, BI is_float)
{
{
  SI NE_base;
  SI NE_base;
  SI NE_flags[2];
  SI NE_flags[2];
  BI NE_flag;
  BI NE_flag;
  int exception;
  int exception;
  int hi_available;
  int hi_available;
  int lo_available;
  int lo_available;
  USI necr;
  USI necr;
  FRV_REGISTER_CONTROL *control;
  FRV_REGISTER_CONTROL *control;
 
 
  /* Check for availability of the target register(s).  */
  /* Check for availability of the target register(s).  */
  which_registers_available (current_cpu, & hi_available, & lo_available,
  which_registers_available (current_cpu, & hi_available, & lo_available,
                             is_float);
                             is_float);
 
 
  /* Check to make sure that the target register is available.  */
  /* Check to make sure that the target register is available.  */
  if (! frv_check_register_access (current_cpu, target_index,
  if (! frv_check_register_access (current_cpu, target_index,
                                   hi_available, lo_available))
                                   hi_available, lo_available))
    return;
    return;
 
 
  /* Determine whether we're working with GR or FR registers.  */
  /* Determine whether we're working with GR or FR registers.  */
  if (is_float)
  if (is_float)
    NE_base = H_SPR_FNER0;
    NE_base = H_SPR_FNER0;
  else
  else
    NE_base = H_SPR_GNER0;
    NE_base = H_SPR_GNER0;
 
 
  /* Determine whether a ne exception is pending.  */
  /* Determine whether a ne exception is pending.  */
  GET_NE_FLAGS (NE_flags, NE_base);
  GET_NE_FLAGS (NE_flags, NE_base);
  if (target_index >= 0)
  if (target_index >= 0)
    NE_flag = GET_NE_FLAG (NE_flags, target_index);
    NE_flag = GET_NE_FLAG (NE_flags, target_index);
  else
  else
    {
    {
      NE_flag =
      NE_flag =
        hi_available && NE_flags[0] != 0 || lo_available && NE_flags[1] != 0;
        hi_available && NE_flags[0] != 0 || lo_available && NE_flags[1] != 0;
    }
    }
 
 
  /* Always clear the appropriate NE flags.  */
  /* Always clear the appropriate NE flags.  */
  clear_ne_flags (current_cpu, target_index, hi_available, lo_available,
  clear_ne_flags (current_cpu, target_index, hi_available, lo_available,
                  NE_base);
                  NE_base);
 
 
  control = CPU_REGISTER_CONTROL (current_cpu);
  control = CPU_REGISTER_CONTROL (current_cpu);
  if (control->spr[H_SPR_NECR].implemented)
  if (control->spr[H_SPR_NECR].implemented)
    {
    {
      necr = GET_NECR ();
      necr = GET_NECR ();
      if (GET_NECR_VALID (necr) && GET_NECR_ELOS (necr) && NE_flag)
      if (GET_NECR_VALID (necr) && GET_NECR_ELOS (necr) && NE_flag)
        {
        {
          /* Clear the appropriate NESR and NEEAR registers.  */
          /* Clear the appropriate NESR and NEEAR registers.  */
          clear_nesr_neear (current_cpu, target_index, is_float);
          clear_nesr_neear (current_cpu, target_index, is_float);
          frv_queue_program_interrupt (current_cpu, FRV_COMMIT_EXCEPTION);
          frv_queue_program_interrupt (current_cpu, FRV_COMMIT_EXCEPTION);
        }
        }
    }
    }
}
}
 
 
/* Generate the appropriate fp_exception(s) based on the given status code.  */
/* Generate the appropriate fp_exception(s) based on the given status code.  */
void
void
frvbf_fpu_error (CGEN_FPU* fpu, int status)
frvbf_fpu_error (CGEN_FPU* fpu, int status)
{
{
  struct frv_fp_exception_info fp_info = {
  struct frv_fp_exception_info fp_info = {
    FSR_NO_EXCEPTION, FTT_IEEE_754_EXCEPTION
    FSR_NO_EXCEPTION, FTT_IEEE_754_EXCEPTION
  };
  };
 
 
  if (status &
  if (status &
      (sim_fpu_status_invalid_snan |
      (sim_fpu_status_invalid_snan |
       sim_fpu_status_invalid_qnan |
       sim_fpu_status_invalid_qnan |
       sim_fpu_status_invalid_isi |
       sim_fpu_status_invalid_isi |
       sim_fpu_status_invalid_idi |
       sim_fpu_status_invalid_idi |
       sim_fpu_status_invalid_zdz |
       sim_fpu_status_invalid_zdz |
       sim_fpu_status_invalid_imz |
       sim_fpu_status_invalid_imz |
       sim_fpu_status_invalid_cvi |
       sim_fpu_status_invalid_cvi |
       sim_fpu_status_invalid_cmp |
       sim_fpu_status_invalid_cmp |
       sim_fpu_status_invalid_sqrt))
       sim_fpu_status_invalid_sqrt))
    fp_info.fsr_mask |= FSR_INVALID_OPERATION;
    fp_info.fsr_mask |= FSR_INVALID_OPERATION;
 
 
  if (status & sim_fpu_status_invalid_div0)
  if (status & sim_fpu_status_invalid_div0)
    fp_info.fsr_mask |= FSR_DIVISION_BY_ZERO;
    fp_info.fsr_mask |= FSR_DIVISION_BY_ZERO;
 
 
  if (status & sim_fpu_status_inexact)
  if (status & sim_fpu_status_inexact)
    fp_info.fsr_mask |= FSR_INEXACT;
    fp_info.fsr_mask |= FSR_INEXACT;
 
 
  if (status & sim_fpu_status_overflow)
  if (status & sim_fpu_status_overflow)
    fp_info.fsr_mask |= FSR_OVERFLOW;
    fp_info.fsr_mask |= FSR_OVERFLOW;
 
 
  if (status & sim_fpu_status_underflow)
  if (status & sim_fpu_status_underflow)
    fp_info.fsr_mask |= FSR_UNDERFLOW;
    fp_info.fsr_mask |= FSR_UNDERFLOW;
 
 
  if (status & sim_fpu_status_denorm)
  if (status & sim_fpu_status_denorm)
    {
    {
      fp_info.fsr_mask |= FSR_DENORMAL_INPUT;
      fp_info.fsr_mask |= FSR_DENORMAL_INPUT;
      fp_info.ftt = FTT_DENORMAL_INPUT;
      fp_info.ftt = FTT_DENORMAL_INPUT;
    }
    }
 
 
  if (fp_info.fsr_mask != FSR_NO_EXCEPTION)
  if (fp_info.fsr_mask != FSR_NO_EXCEPTION)
    {
    {
      SIM_CPU *current_cpu = (SIM_CPU *)fpu->owner;
      SIM_CPU *current_cpu = (SIM_CPU *)fpu->owner;
      frv_queue_fp_exception_interrupt (current_cpu, & fp_info);
      frv_queue_fp_exception_interrupt (current_cpu, & fp_info);
    }
    }
}
}
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.