OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [gdb-7.1/] [sim/] [cris/] [crisv32f.c] - Diff between revs 834 and 842

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

Rev 834 Rev 842
/* CRIS v32 simulator support code
/* CRIS v32 simulator support code
   Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010
   Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010
   Free Software Foundation, Inc.
   Free Software Foundation, Inc.
   Contributed by Axis Communications.
   Contributed by Axis Communications.
 
 
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/>.  */
 
 
/* The infrastructure is based on that of i960.c.  */
/* The infrastructure is based on that of i960.c.  */
 
 
#define WANT_CPU_CRISV32F
#define WANT_CPU_CRISV32F
 
 
#define SPECIFIC_U_EXEC_FN
#define SPECIFIC_U_EXEC_FN
#define SPECIFIC_U_SKIP4_FN
#define SPECIFIC_U_SKIP4_FN
#define SPECIFIC_U_CONST16_FN
#define SPECIFIC_U_CONST16_FN
#define SPECIFIC_U_CONST32_FN
#define SPECIFIC_U_CONST32_FN
#define SPECIFIC_U_MEM_FN
#define SPECIFIC_U_MEM_FN
#define SPECIFIC_U_MOVEM_FN
#define SPECIFIC_U_MOVEM_FN
#define BASENUM 32
#define BASENUM 32
#define CRIS_TLS_REGISTER 2
#define CRIS_TLS_REGISTER 2
#include "cris-tmpl.c"
#include "cris-tmpl.c"
 
 
#if WITH_PROFILE_MODEL_P
#if WITH_PROFILE_MODEL_P
 
 
/* Re-use the bit position for the BZ register, since there are no stall
/* Re-use the bit position for the BZ register, since there are no stall
   cycles for reading or writing it.  */
   cycles for reading or writing it.  */
#define CRIS_BZ_REGNO 16
#define CRIS_BZ_REGNO 16
#define CRIS_MODF_JUMP_MASK (1 << CRIS_BZ_REGNO)
#define CRIS_MODF_JUMP_MASK (1 << CRIS_BZ_REGNO)
/* Likewise for the WZ register, marking memory writes.  */
/* Likewise for the WZ register, marking memory writes.  */
#define CRIS_WZ_REGNO 20
#define CRIS_WZ_REGNO 20
#define CRIS_MODF_MEM_WRITE_MASK (1 << CRIS_WZ_REGNO)
#define CRIS_MODF_MEM_WRITE_MASK (1 << CRIS_WZ_REGNO)
#define CRIS_MOF_REGNO (16 + 7)
#define CRIS_MOF_REGNO (16 + 7)
#define CRIS_ALWAYS_CONDITION 14
#define CRIS_ALWAYS_CONDITION 14
 
 
/* This macro must only be used in context where there's only one
/* This macro must only be used in context where there's only one
   dynamic cause for a penalty, except in the u-exec unit.  */
   dynamic cause for a penalty, except in the u-exec unit.  */
 
 
#define PENALIZE1(CNT)                                  \
#define PENALIZE1(CNT)                                  \
  do                                                    \
  do                                                    \
    {                                                   \
    {                                                   \
      CPU_CRIS_MISC_PROFILE (current_cpu)->CNT++;       \
      CPU_CRIS_MISC_PROFILE (current_cpu)->CNT++;       \
      model_data->prev_prev_prev_modf_regs              \
      model_data->prev_prev_prev_modf_regs              \
        = model_data->prev_prev_modf_regs;              \
        = model_data->prev_prev_modf_regs;              \
      model_data->prev_prev_modf_regs                   \
      model_data->prev_prev_modf_regs                   \
        = model_data->prev_modf_regs;                   \
        = model_data->prev_modf_regs;                   \
      model_data->prev_modf_regs = 0;                    \
      model_data->prev_modf_regs = 0;                    \
      model_data->prev_prev_prev_movem_dest_regs        \
      model_data->prev_prev_prev_movem_dest_regs        \
        = model_data->prev_prev_movem_dest_regs;        \
        = model_data->prev_prev_movem_dest_regs;        \
      model_data->prev_prev_movem_dest_regs             \
      model_data->prev_prev_movem_dest_regs             \
        = model_data->prev_movem_dest_regs;             \
        = model_data->prev_movem_dest_regs;             \
      model_data->prev_movem_dest_regs = 0;              \
      model_data->prev_movem_dest_regs = 0;              \
    }                                                   \
    }                                                   \
  while (0)
  while (0)
 
 
 
 
/* Model function for u-skip4 unit.  */
/* Model function for u-skip4 unit.  */
 
 
int
int
MY (XCONCAT3 (f_model_crisv,BASENUM,
MY (XCONCAT3 (f_model_crisv,BASENUM,
              _u_skip4)) (SIM_CPU *current_cpu,
              _u_skip4)) (SIM_CPU *current_cpu,
                          const IDESC *idesc ATTRIBUTE_UNUSED,
                          const IDESC *idesc ATTRIBUTE_UNUSED,
                          int unit_num ATTRIBUTE_UNUSED,
                          int unit_num ATTRIBUTE_UNUSED,
                          int referenced ATTRIBUTE_UNUSED)
                          int referenced ATTRIBUTE_UNUSED)
{
{
  /* Handle PC not being updated with pbb.  FIXME: What if not pbb?  */
  /* Handle PC not being updated with pbb.  FIXME: What if not pbb?  */
  CPU (h_pc) += 4;
  CPU (h_pc) += 4;
  return 0;
  return 0;
}
}
 
 
/* Model function for u-exec unit.  */
/* Model function for u-exec unit.  */
 
 
int
int
MY (XCONCAT3 (f_model_crisv,BASENUM,
MY (XCONCAT3 (f_model_crisv,BASENUM,
              _u_exec)) (SIM_CPU *current_cpu,
              _u_exec)) (SIM_CPU *current_cpu,
                         const IDESC *idesc ATTRIBUTE_UNUSED,
                         const IDESC *idesc ATTRIBUTE_UNUSED,
                         int unit_num ATTRIBUTE_UNUSED,
                         int unit_num ATTRIBUTE_UNUSED,
                         int referenced ATTRIBUTE_UNUSED,
                         int referenced ATTRIBUTE_UNUSED,
                         INT destreg_in,
                         INT destreg_in,
                         INT srcreg,
                         INT srcreg,
                         INT destreg_out)
                         INT destreg_out)
{
{
  MODEL_CRISV32_DATA *model_data
  MODEL_CRISV32_DATA *model_data
    = (MODEL_CRISV32_DATA *) CPU_MODEL_DATA (current_cpu);
    = (MODEL_CRISV32_DATA *) CPU_MODEL_DATA (current_cpu);
  UINT modf_regs
  UINT modf_regs
    = ((destreg_out == -1 ? 0 : (1 << destreg_out))
    = ((destreg_out == -1 ? 0 : (1 << destreg_out))
       | model_data->modf_regs);
       | model_data->modf_regs);
 
 
  if (srcreg != -1)
  if (srcreg != -1)
    {
    {
      if (model_data->prev_movem_dest_regs & (1 << srcreg))
      if (model_data->prev_movem_dest_regs & (1 << srcreg))
        {
        {
          PENALIZE1 (movemdst_stall_count);
          PENALIZE1 (movemdst_stall_count);
          PENALIZE1 (movemdst_stall_count);
          PENALIZE1 (movemdst_stall_count);
          PENALIZE1 (movemdst_stall_count);
          PENALIZE1 (movemdst_stall_count);
        }
        }
      else if (model_data->prev_prev_movem_dest_regs & (1 << srcreg))
      else if (model_data->prev_prev_movem_dest_regs & (1 << srcreg))
        {
        {
          PENALIZE1 (movemdst_stall_count);
          PENALIZE1 (movemdst_stall_count);
          PENALIZE1 (movemdst_stall_count);
          PENALIZE1 (movemdst_stall_count);
        }
        }
      else if (model_data->prev_prev_prev_movem_dest_regs & (1 << srcreg))
      else if (model_data->prev_prev_prev_movem_dest_regs & (1 << srcreg))
        PENALIZE1 (movemdst_stall_count);
        PENALIZE1 (movemdst_stall_count);
    }
    }
 
 
  if (destreg_in != -1)
  if (destreg_in != -1)
    {
    {
      if (model_data->prev_movem_dest_regs & (1 << destreg_in))
      if (model_data->prev_movem_dest_regs & (1 << destreg_in))
        {
        {
          PENALIZE1 (movemdst_stall_count);
          PENALIZE1 (movemdst_stall_count);
          PENALIZE1 (movemdst_stall_count);
          PENALIZE1 (movemdst_stall_count);
          PENALIZE1 (movemdst_stall_count);
          PENALIZE1 (movemdst_stall_count);
        }
        }
      else if (model_data->prev_prev_movem_dest_regs & (1 << destreg_in))
      else if (model_data->prev_prev_movem_dest_regs & (1 << destreg_in))
        {
        {
          PENALIZE1 (movemdst_stall_count);
          PENALIZE1 (movemdst_stall_count);
          PENALIZE1 (movemdst_stall_count);
          PENALIZE1 (movemdst_stall_count);
        }
        }
      else if (model_data->prev_prev_prev_movem_dest_regs & (1 << destreg_in))
      else if (model_data->prev_prev_prev_movem_dest_regs & (1 << destreg_in))
        PENALIZE1 (movemdst_stall_count);
        PENALIZE1 (movemdst_stall_count);
    }
    }
 
 
  model_data->prev_prev_prev_modf_regs
  model_data->prev_prev_prev_modf_regs
    = model_data->prev_prev_modf_regs;
    = model_data->prev_prev_modf_regs;
  model_data->prev_prev_modf_regs = model_data->prev_modf_regs;
  model_data->prev_prev_modf_regs = model_data->prev_modf_regs;
  model_data->prev_modf_regs = modf_regs;
  model_data->prev_modf_regs = modf_regs;
  model_data->modf_regs = 0;
  model_data->modf_regs = 0;
 
 
  model_data->prev_prev_prev_movem_dest_regs
  model_data->prev_prev_prev_movem_dest_regs
    = model_data->prev_prev_movem_dest_regs;
    = model_data->prev_prev_movem_dest_regs;
  model_data->prev_prev_movem_dest_regs = model_data->prev_movem_dest_regs;
  model_data->prev_prev_movem_dest_regs = model_data->prev_movem_dest_regs;
  model_data->prev_movem_dest_regs = model_data->movem_dest_regs;
  model_data->prev_movem_dest_regs = model_data->movem_dest_regs;
  model_data->movem_dest_regs = 0;
  model_data->movem_dest_regs = 0;
 
 
  /* Handle PC not being updated with pbb.  FIXME: What if not pbb?  */
  /* Handle PC not being updated with pbb.  FIXME: What if not pbb?  */
  CPU (h_pc) += 2;
  CPU (h_pc) += 2;
  return 1;
  return 1;
}
}
 
 
/* Special case used when the destination is a special register.  */
/* Special case used when the destination is a special register.  */
 
 
int
int
MY (XCONCAT3 (f_model_crisv,BASENUM,
MY (XCONCAT3 (f_model_crisv,BASENUM,
              _u_exec_to_sr)) (SIM_CPU *current_cpu,
              _u_exec_to_sr)) (SIM_CPU *current_cpu,
                               const IDESC *idesc ATTRIBUTE_UNUSED,
                               const IDESC *idesc ATTRIBUTE_UNUSED,
                               int unit_num ATTRIBUTE_UNUSED,
                               int unit_num ATTRIBUTE_UNUSED,
                               int referenced ATTRIBUTE_UNUSED,
                               int referenced ATTRIBUTE_UNUSED,
                               INT srcreg,
                               INT srcreg,
                               INT specreg)
                               INT specreg)
{
{
  int specdest;
  int specdest;
 
 
  if (specreg != -1)
  if (specreg != -1)
    specdest = specreg + 16;
    specdest = specreg + 16;
  else
  else
    abort ();
    abort ();
 
 
  return MY (XCONCAT3 (f_model_crisv,BASENUM,_u_exec))
  return MY (XCONCAT3 (f_model_crisv,BASENUM,_u_exec))
    (current_cpu, NULL, 0, 0, -1, srcreg,
    (current_cpu, NULL, 0, 0, -1, srcreg,
     /* The positions for constant-zero registers BZ and WZ are recycled
     /* The positions for constant-zero registers BZ and WZ are recycled
        for jump and memory-write markers.  We must take precautions
        for jump and memory-write markers.  We must take precautions
        here not to add false markers for them.  It might be that the
        here not to add false markers for them.  It might be that the
        hardware inserts stall cycles for instructions that actually try
        hardware inserts stall cycles for instructions that actually try
        and write those registers, but we'll burn that bridge when we
        and write those registers, but we'll burn that bridge when we
        get to it; we'd have to find other free bits or make new
        get to it; we'd have to find other free bits or make new
        model_data variables.  However, it's doubtful that there will
        model_data variables.  However, it's doubtful that there will
        ever be a need to be cycle-correct for useless code, at least in
        ever be a need to be cycle-correct for useless code, at least in
        this particular simulator, mainly used for GCC testing.  */
        this particular simulator, mainly used for GCC testing.  */
     specdest == CRIS_BZ_REGNO || specdest == CRIS_WZ_REGNO
     specdest == CRIS_BZ_REGNO || specdest == CRIS_WZ_REGNO
     ? -1 : specdest);
     ? -1 : specdest);
}
}
 
 
 
 
/* Special case for movem.  */
/* Special case for movem.  */
 
 
int
int
MY (XCONCAT3 (f_model_crisv,BASENUM,
MY (XCONCAT3 (f_model_crisv,BASENUM,
              _u_exec_movem)) (SIM_CPU *current_cpu,
              _u_exec_movem)) (SIM_CPU *current_cpu,
                               const IDESC *idesc ATTRIBUTE_UNUSED,
                               const IDESC *idesc ATTRIBUTE_UNUSED,
                               int unit_num ATTRIBUTE_UNUSED,
                               int unit_num ATTRIBUTE_UNUSED,
                               int referenced ATTRIBUTE_UNUSED,
                               int referenced ATTRIBUTE_UNUSED,
                               INT srcreg,
                               INT srcreg,
                               INT destreg_out)
                               INT destreg_out)
{
{
  return MY (XCONCAT3 (f_model_crisv,BASENUM,_u_exec))
  return MY (XCONCAT3 (f_model_crisv,BASENUM,_u_exec))
    (current_cpu, NULL, 0, 0, -1, srcreg, destreg_out);
    (current_cpu, NULL, 0, 0, -1, srcreg, destreg_out);
}
}
 
 
/* Model function for u-const16 unit.  */
/* Model function for u-const16 unit.  */
 
 
int
int
MY (XCONCAT3 (f_model_crisv,BASENUM,
MY (XCONCAT3 (f_model_crisv,BASENUM,
              _u_const16)) (SIM_CPU *current_cpu,
              _u_const16)) (SIM_CPU *current_cpu,
                            const IDESC *idesc ATTRIBUTE_UNUSED,
                            const IDESC *idesc ATTRIBUTE_UNUSED,
                            int unit_num ATTRIBUTE_UNUSED,
                            int unit_num ATTRIBUTE_UNUSED,
                            int referenced ATTRIBUTE_UNUSED)
                            int referenced ATTRIBUTE_UNUSED)
{
{
  MODEL_CRISV32_DATA *model_data
  MODEL_CRISV32_DATA *model_data
    = (MODEL_CRISV32_DATA *) CPU_MODEL_DATA (current_cpu);
    = (MODEL_CRISV32_DATA *) CPU_MODEL_DATA (current_cpu);
 
 
  /* If the previous insn was a jump of some sort and this insn
  /* If the previous insn was a jump of some sort and this insn
     straddles a cache-line, there's a one-cycle penalty.
     straddles a cache-line, there's a one-cycle penalty.
     FIXME: Test-cases for normal const16 and others, like branch.  */
     FIXME: Test-cases for normal const16 and others, like branch.  */
  if ((model_data->prev_modf_regs & CRIS_MODF_JUMP_MASK)
  if ((model_data->prev_modf_regs & CRIS_MODF_JUMP_MASK)
      && (CPU (h_pc) & 0x1e) == 0x1e)
      && (CPU (h_pc) & 0x1e) == 0x1e)
    PENALIZE1 (jumptarget_stall_count);
    PENALIZE1 (jumptarget_stall_count);
 
 
  /* Handle PC not being updated with pbb.  FIXME: What if not pbb?  */
  /* Handle PC not being updated with pbb.  FIXME: What if not pbb?  */
  CPU (h_pc) += 2;
  CPU (h_pc) += 2;
 
 
  return 0;
  return 0;
}
}
 
 
/* Model function for u-const32 unit.  */
/* Model function for u-const32 unit.  */
 
 
int
int
MY (XCONCAT3 (f_model_crisv,BASENUM,
MY (XCONCAT3 (f_model_crisv,BASENUM,
              _u_const32)) (SIM_CPU *current_cpu,
              _u_const32)) (SIM_CPU *current_cpu,
                            const IDESC *idesc ATTRIBUTE_UNUSED,
                            const IDESC *idesc ATTRIBUTE_UNUSED,
                            int unit_num ATTRIBUTE_UNUSED,
                            int unit_num ATTRIBUTE_UNUSED,
                            int referenced ATTRIBUTE_UNUSED)
                            int referenced ATTRIBUTE_UNUSED)
{
{
  MODEL_CRISV32_DATA *model_data
  MODEL_CRISV32_DATA *model_data
    = (MODEL_CRISV32_DATA *) CPU_MODEL_DATA (current_cpu);
    = (MODEL_CRISV32_DATA *) CPU_MODEL_DATA (current_cpu);
 
 
  /* If the previous insn was a jump of some sort and this insn
  /* If the previous insn was a jump of some sort and this insn
     straddles a cache-line, there's a one-cycle penalty.  */
     straddles a cache-line, there's a one-cycle penalty.  */
  if ((model_data->prev_modf_regs & CRIS_MODF_JUMP_MASK)
  if ((model_data->prev_modf_regs & CRIS_MODF_JUMP_MASK)
      && (CPU (h_pc) & 0x1e) == 0x1c)
      && (CPU (h_pc) & 0x1e) == 0x1c)
    PENALIZE1 (jumptarget_stall_count);
    PENALIZE1 (jumptarget_stall_count);
 
 
  /* Handle PC not being updated with pbb.  FIXME: What if not pbb?  */
  /* Handle PC not being updated with pbb.  FIXME: What if not pbb?  */
  CPU (h_pc) += 4;
  CPU (h_pc) += 4;
 
 
  return 0;
  return 0;
}
}
 
 
/* Model function for u-mem unit.  */
/* Model function for u-mem unit.  */
 
 
int
int
MY (XCONCAT3 (f_model_crisv,BASENUM,
MY (XCONCAT3 (f_model_crisv,BASENUM,
              _u_mem)) (SIM_CPU *current_cpu,
              _u_mem)) (SIM_CPU *current_cpu,
                        const IDESC *idesc ATTRIBUTE_UNUSED,
                        const IDESC *idesc ATTRIBUTE_UNUSED,
                        int unit_num ATTRIBUTE_UNUSED,
                        int unit_num ATTRIBUTE_UNUSED,
                        int referenced ATTRIBUTE_UNUSED,
                        int referenced ATTRIBUTE_UNUSED,
                        INT srcreg)
                        INT srcreg)
{
{
  MODEL_CRISV32_DATA *model_data
  MODEL_CRISV32_DATA *model_data
    = (MODEL_CRISV32_DATA *) CPU_MODEL_DATA (current_cpu);
    = (MODEL_CRISV32_DATA *) CPU_MODEL_DATA (current_cpu);
 
 
  if (srcreg == -1)
  if (srcreg == -1)
    abort ();
    abort ();
 
 
  /* If srcreg references a register modified in the previous cycle
  /* If srcreg references a register modified in the previous cycle
     through other than autoincrement, then there's a penalty: one
     through other than autoincrement, then there's a penalty: one
     cycle.  */
     cycle.  */
  if (model_data->prev_modf_regs & (1 << srcreg))
  if (model_data->prev_modf_regs & (1 << srcreg))
    PENALIZE1 (memsrc_stall_count);
    PENALIZE1 (memsrc_stall_count);
 
 
  return 0;
  return 0;
}
}
 
 
/* Model function for u-mem-r unit.  */
/* Model function for u-mem-r unit.  */
 
 
int
int
MY (XCONCAT3 (f_model_crisv,BASENUM,
MY (XCONCAT3 (f_model_crisv,BASENUM,
              _u_mem_r)) (SIM_CPU *current_cpu,
              _u_mem_r)) (SIM_CPU *current_cpu,
                          const IDESC *idesc ATTRIBUTE_UNUSED,
                          const IDESC *idesc ATTRIBUTE_UNUSED,
                          int unit_num ATTRIBUTE_UNUSED,
                          int unit_num ATTRIBUTE_UNUSED,
                          int referenced ATTRIBUTE_UNUSED)
                          int referenced ATTRIBUTE_UNUSED)
{
{
  MODEL_CRISV32_DATA *model_data
  MODEL_CRISV32_DATA *model_data
    = (MODEL_CRISV32_DATA *) CPU_MODEL_DATA (current_cpu);
    = (MODEL_CRISV32_DATA *) CPU_MODEL_DATA (current_cpu);
 
 
  /* There's a two-cycle penalty for read after a memory write in any of
  /* There's a two-cycle penalty for read after a memory write in any of
     the two previous cycles, known as a cache read-after-write hazard.
     the two previous cycles, known as a cache read-after-write hazard.
 
 
     This model function (the model_data member access) depends on being
     This model function (the model_data member access) depends on being
     executed before the u-exec unit.  */
     executed before the u-exec unit.  */
  if ((model_data->prev_modf_regs & CRIS_MODF_MEM_WRITE_MASK)
  if ((model_data->prev_modf_regs & CRIS_MODF_MEM_WRITE_MASK)
      || (model_data->prev_prev_modf_regs & CRIS_MODF_MEM_WRITE_MASK))
      || (model_data->prev_prev_modf_regs & CRIS_MODF_MEM_WRITE_MASK))
    {
    {
      PENALIZE1 (memraw_stall_count);
      PENALIZE1 (memraw_stall_count);
      PENALIZE1 (memraw_stall_count);
      PENALIZE1 (memraw_stall_count);
    }
    }
 
 
  return 0;
  return 0;
}
}
 
 
/* Model function for u-mem-w unit.  */
/* Model function for u-mem-w unit.  */
 
 
int
int
MY (XCONCAT3 (f_model_crisv,BASENUM,
MY (XCONCAT3 (f_model_crisv,BASENUM,
              _u_mem_w)) (SIM_CPU *current_cpu,
              _u_mem_w)) (SIM_CPU *current_cpu,
                          const IDESC *idesc ATTRIBUTE_UNUSED,
                          const IDESC *idesc ATTRIBUTE_UNUSED,
                          int unit_num ATTRIBUTE_UNUSED,
                          int unit_num ATTRIBUTE_UNUSED,
                          int referenced ATTRIBUTE_UNUSED)
                          int referenced ATTRIBUTE_UNUSED)
{
{
  MODEL_CRISV32_DATA *model_data
  MODEL_CRISV32_DATA *model_data
    = (MODEL_CRISV32_DATA *) CPU_MODEL_DATA (current_cpu);
    = (MODEL_CRISV32_DATA *) CPU_MODEL_DATA (current_cpu);
 
 
  /* Mark that memory has been written.  This model function (the
  /* Mark that memory has been written.  This model function (the
     model_data member access) depends on being executed after the
     model_data member access) depends on being executed after the
     u-exec unit.  */
     u-exec unit.  */
  model_data->prev_modf_regs |= CRIS_MODF_MEM_WRITE_MASK;
  model_data->prev_modf_regs |= CRIS_MODF_MEM_WRITE_MASK;
 
 
  return 0;
  return 0;
}
}
 
 
/* Model function for u-movem-rtom unit.  */
/* Model function for u-movem-rtom unit.  */
 
 
int
int
MY (XCONCAT3 (f_model_crisv,BASENUM,
MY (XCONCAT3 (f_model_crisv,BASENUM,
              _u_movem_rtom)) (SIM_CPU *current_cpu,
              _u_movem_rtom)) (SIM_CPU *current_cpu,
                               const IDESC *idesc ATTRIBUTE_UNUSED,
                               const IDESC *idesc ATTRIBUTE_UNUSED,
                               int unit_num ATTRIBUTE_UNUSED,
                               int unit_num ATTRIBUTE_UNUSED,
                               int referenced ATTRIBUTE_UNUSED,
                               int referenced ATTRIBUTE_UNUSED,
                               /* Deliberate order.  */
                               /* Deliberate order.  */
                               INT addrreg, INT limreg)
                               INT addrreg, INT limreg)
{
{
  USI addr;
  USI addr;
  MODEL_CRISV32_DATA *model_data
  MODEL_CRISV32_DATA *model_data
    = (MODEL_CRISV32_DATA *) CPU_MODEL_DATA (current_cpu);
    = (MODEL_CRISV32_DATA *) CPU_MODEL_DATA (current_cpu);
 
 
  if (limreg == -1 || addrreg == -1)
  if (limreg == -1 || addrreg == -1)
    abort ();
    abort ();
 
 
  addr = GET_H_GR (addrreg);
  addr = GET_H_GR (addrreg);
 
 
  /* The movem-to-memory instruction must not move a register modified
  /* The movem-to-memory instruction must not move a register modified
     in one of the previous two cycles.  Enforce by adding penalty
     in one of the previous two cycles.  Enforce by adding penalty
     cycles.  */
     cycles.  */
  if (model_data->prev_modf_regs & ((1 << (limreg + 1)) - 1))
  if (model_data->prev_modf_regs & ((1 << (limreg + 1)) - 1))
    {
    {
      PENALIZE1 (movemsrc_stall_count);
      PENALIZE1 (movemsrc_stall_count);
      PENALIZE1 (movemsrc_stall_count);
      PENALIZE1 (movemsrc_stall_count);
    }
    }
  else if (model_data->prev_prev_modf_regs & ((1 << (limreg + 1)) - 1))
  else if (model_data->prev_prev_modf_regs & ((1 << (limreg + 1)) - 1))
    PENALIZE1 (movemsrc_stall_count);
    PENALIZE1 (movemsrc_stall_count);
 
 
  /* One-cycle penalty for each cache-line straddled.  Use the
  /* One-cycle penalty for each cache-line straddled.  Use the
     documented expressions.  Unfortunately no penalty cycles are
     documented expressions.  Unfortunately no penalty cycles are
     eliminated by any penalty cycles above.  We file these numbers
     eliminated by any penalty cycles above.  We file these numbers
     separately, since they aren't schedulable for all cases.  */
     separately, since they aren't schedulable for all cases.  */
  if ((addr >> 5) == (((addr + 4 * (limreg + 1)) - 1) >> 5))
  if ((addr >> 5) == (((addr + 4 * (limreg + 1)) - 1) >> 5))
    ;
    ;
  else if ((addr >> 5) == (((addr + 4 * (limreg + 1)) - 1) >> 5) - 1)
  else if ((addr >> 5) == (((addr + 4 * (limreg + 1)) - 1) >> 5) - 1)
    PENALIZE1 (movemaddr_stall_count);
    PENALIZE1 (movemaddr_stall_count);
  else if ((addr >> 5) == (((addr + 4 * (limreg + 1)) - 1) >> 5) - 2)
  else if ((addr >> 5) == (((addr + 4 * (limreg + 1)) - 1) >> 5) - 2)
    {
    {
      PENALIZE1 (movemaddr_stall_count);
      PENALIZE1 (movemaddr_stall_count);
      PENALIZE1 (movemaddr_stall_count);
      PENALIZE1 (movemaddr_stall_count);
    }
    }
  else
  else
    abort ();
    abort ();
 
 
  return 0;
  return 0;
}
}
 
 
/* Model function for u-movem-mtor unit.  */
/* Model function for u-movem-mtor unit.  */
 
 
int
int
MY (XCONCAT3 (f_model_crisv,BASENUM,
MY (XCONCAT3 (f_model_crisv,BASENUM,
              _u_movem_mtor)) (SIM_CPU *current_cpu,
              _u_movem_mtor)) (SIM_CPU *current_cpu,
                               const IDESC *idesc ATTRIBUTE_UNUSED,
                               const IDESC *idesc ATTRIBUTE_UNUSED,
                               int unit_num ATTRIBUTE_UNUSED,
                               int unit_num ATTRIBUTE_UNUSED,
                               int referenced ATTRIBUTE_UNUSED,
                               int referenced ATTRIBUTE_UNUSED,
                               /* Deliberate order.  */
                               /* Deliberate order.  */
                               INT addrreg, INT limreg)
                               INT addrreg, INT limreg)
{
{
  USI addr;
  USI addr;
  int nregs = limreg + 1;
  int nregs = limreg + 1;
  MODEL_CRISV32_DATA *model_data
  MODEL_CRISV32_DATA *model_data
    = (MODEL_CRISV32_DATA *) CPU_MODEL_DATA (current_cpu);
    = (MODEL_CRISV32_DATA *) CPU_MODEL_DATA (current_cpu);
 
 
  if (limreg == -1 || addrreg == -1)
  if (limreg == -1 || addrreg == -1)
    abort ();
    abort ();
 
 
  addr = GET_H_GR (addrreg);
  addr = GET_H_GR (addrreg);
 
 
  /* One-cycle penalty for each cache-line straddled.  Use the
  /* One-cycle penalty for each cache-line straddled.  Use the
     documented expressions.  One cycle is the norm; more cycles are
     documented expressions.  One cycle is the norm; more cycles are
     counted as penalties.  Unfortunately no penalty cycles here
     counted as penalties.  Unfortunately no penalty cycles here
     eliminate penalty cycles indicated in ->movem_dest_regs.  */
     eliminate penalty cycles indicated in ->movem_dest_regs.  */
  if ((addr >> 5) == (((addr + 4 * nregs) - 1) >> 5) - 1)
  if ((addr >> 5) == (((addr + 4 * nregs) - 1) >> 5) - 1)
    PENALIZE1 (movemaddr_stall_count);
    PENALIZE1 (movemaddr_stall_count);
  else if ((addr >> 5) == (((addr + 4 * nregs) - 1) >> 5) - 2)
  else if ((addr >> 5) == (((addr + 4 * nregs) - 1) >> 5) - 2)
    {
    {
      PENALIZE1 (movemaddr_stall_count);
      PENALIZE1 (movemaddr_stall_count);
      PENALIZE1 (movemaddr_stall_count);
      PENALIZE1 (movemaddr_stall_count);
    }
    }
 
 
  model_data->modf_regs |= ((1 << nregs) - 1);
  model_data->modf_regs |= ((1 << nregs) - 1);
  model_data->movem_dest_regs  |= ((1 << nregs) - 1);
  model_data->movem_dest_regs  |= ((1 << nregs) - 1);
  return 0;
  return 0;
}
}
 
 
 
 
/* Model function for u-branch unit.
/* Model function for u-branch unit.
   FIXME: newpc and cc are always wrong.  */
   FIXME: newpc and cc are always wrong.  */
 
 
int
int
MY (XCONCAT3 (f_model_crisv,BASENUM,_u_branch)) (SIM_CPU *current_cpu,
MY (XCONCAT3 (f_model_crisv,BASENUM,_u_branch)) (SIM_CPU *current_cpu,
                                                 const IDESC *idesc,
                                                 const IDESC *idesc,
                                                 int unit_num, int referenced)
                                                 int unit_num, int referenced)
{
{
  CRIS_MISC_PROFILE *profp = CPU_CRIS_MISC_PROFILE (current_cpu);
  CRIS_MISC_PROFILE *profp = CPU_CRIS_MISC_PROFILE (current_cpu);
  USI pc = profp->old_pc;
  USI pc = profp->old_pc;
  MODEL_CRISV32_DATA *model_data
  MODEL_CRISV32_DATA *model_data
    = (MODEL_CRISV32_DATA *) CPU_MODEL_DATA (current_cpu);
    = (MODEL_CRISV32_DATA *) CPU_MODEL_DATA (current_cpu);
  int taken = profp->branch_taken;
  int taken = profp->branch_taken;
  int branch_index = (pc & (N_CRISV32_BRANCH_PREDICTORS - 1)) >> 1;
  int branch_index = (pc & (N_CRISV32_BRANCH_PREDICTORS - 1)) >> 1;
  int pred_taken = (profp->branch_predictors[branch_index] & 2) != 0;
  int pred_taken = (profp->branch_predictors[branch_index] & 2) != 0;
 
 
  if (taken != pred_taken)
  if (taken != pred_taken)
    {
    {
      PENALIZE1 (branch_stall_count);
      PENALIZE1 (branch_stall_count);
      PENALIZE1 (branch_stall_count);
      PENALIZE1 (branch_stall_count);
    }
    }
 
 
  if (taken)
  if (taken)
    {
    {
      if (profp->branch_predictors[branch_index] < 3)
      if (profp->branch_predictors[branch_index] < 3)
        profp->branch_predictors[branch_index]++;
        profp->branch_predictors[branch_index]++;
 
 
      return MY (XCONCAT3 (f_model_crisv,BASENUM,_u_jump))
      return MY (XCONCAT3 (f_model_crisv,BASENUM,_u_jump))
        (current_cpu, idesc, unit_num, referenced, -1);
        (current_cpu, idesc, unit_num, referenced, -1);
    }
    }
 
 
  if (profp->branch_predictors[branch_index] != 0)
  if (profp->branch_predictors[branch_index] != 0)
    profp->branch_predictors[branch_index]--;
    profp->branch_predictors[branch_index]--;
 
 
  return 0;
  return 0;
}
}
 
 
/* Model function for u-jump-r unit.  */
/* Model function for u-jump-r unit.  */
 
 
int
int
MY (XCONCAT3 (f_model_crisv,BASENUM,
MY (XCONCAT3 (f_model_crisv,BASENUM,
              _u_jump_r)) (SIM_CPU *current_cpu,
              _u_jump_r)) (SIM_CPU *current_cpu,
                           const IDESC *idesc ATTRIBUTE_UNUSED,
                           const IDESC *idesc ATTRIBUTE_UNUSED,
                           int unit_num ATTRIBUTE_UNUSED,
                           int unit_num ATTRIBUTE_UNUSED,
                           int referenced ATTRIBUTE_UNUSED,
                           int referenced ATTRIBUTE_UNUSED,
                           int regno)
                           int regno)
{
{
  MODEL_CRISV32_DATA *model_data
  MODEL_CRISV32_DATA *model_data
    = (MODEL_CRISV32_DATA *) CPU_MODEL_DATA (current_cpu);
    = (MODEL_CRISV32_DATA *) CPU_MODEL_DATA (current_cpu);
 
 
  if (regno == -1)
  if (regno == -1)
    abort ();
    abort ();
 
 
  /* For jump-to-register, the register must not have been modified the
  /* For jump-to-register, the register must not have been modified the
     last two cycles.  Penalty: two cycles from the modifying insn.  */
     last two cycles.  Penalty: two cycles from the modifying insn.  */
  if ((1 << regno) & model_data->prev_modf_regs)
  if ((1 << regno) & model_data->prev_modf_regs)
    {
    {
      PENALIZE1 (jumpsrc_stall_count);
      PENALIZE1 (jumpsrc_stall_count);
      PENALIZE1 (jumpsrc_stall_count);
      PENALIZE1 (jumpsrc_stall_count);
    }
    }
  else if ((1 << regno) & model_data->prev_prev_modf_regs)
  else if ((1 << regno) & model_data->prev_prev_modf_regs)
    PENALIZE1 (jumpsrc_stall_count);
    PENALIZE1 (jumpsrc_stall_count);
 
 
  return 0;
  return 0;
}
}
 
 
/* Model function for u-jump-sr unit.  */
/* Model function for u-jump-sr unit.  */
 
 
int
int
MY (XCONCAT3 (f_model_crisv,BASENUM,_u_jump_sr)) (SIM_CPU *current_cpu,
MY (XCONCAT3 (f_model_crisv,BASENUM,_u_jump_sr)) (SIM_CPU *current_cpu,
                                                  const IDESC *idesc,
                                                  const IDESC *idesc,
                                                  int unit_num, int referenced,
                                                  int unit_num, int referenced,
                                                  int sr_regno)
                                                  int sr_regno)
{
{
  int regno;
  int regno;
 
 
  MODEL_CRISV32_DATA *model_data
  MODEL_CRISV32_DATA *model_data
    = (MODEL_CRISV32_DATA *) CPU_MODEL_DATA (current_cpu);
    = (MODEL_CRISV32_DATA *) CPU_MODEL_DATA (current_cpu);
 
 
  if (sr_regno == -1)
  if (sr_regno == -1)
    abort ();
    abort ();
 
 
  regno = sr_regno + 16;
  regno = sr_regno + 16;
 
 
  /* For jump-to-register, the register must not have been modified the
  /* For jump-to-register, the register must not have been modified the
     last two cycles.  Penalty: two cycles from the modifying insn.  */
     last two cycles.  Penalty: two cycles from the modifying insn.  */
  if ((1 << regno) & model_data->prev_modf_regs)
  if ((1 << regno) & model_data->prev_modf_regs)
    {
    {
      PENALIZE1 (jumpsrc_stall_count);
      PENALIZE1 (jumpsrc_stall_count);
      PENALIZE1 (jumpsrc_stall_count);
      PENALIZE1 (jumpsrc_stall_count);
    }
    }
  else if ((1 << regno) & model_data->prev_prev_modf_regs)
  else if ((1 << regno) & model_data->prev_prev_modf_regs)
    PENALIZE1 (jumpsrc_stall_count);
    PENALIZE1 (jumpsrc_stall_count);
 
 
  return
  return
    MY (XCONCAT3 (f_model_crisv,BASENUM,_u_jump)) (current_cpu, idesc,
    MY (XCONCAT3 (f_model_crisv,BASENUM,_u_jump)) (current_cpu, idesc,
                                                   unit_num, referenced, -1);
                                                   unit_num, referenced, -1);
}
}
 
 
/* Model function for u-jump unit.  */
/* Model function for u-jump unit.  */
 
 
int
int
MY (XCONCAT3 (f_model_crisv,BASENUM,
MY (XCONCAT3 (f_model_crisv,BASENUM,
              _u_jump)) (SIM_CPU *current_cpu,
              _u_jump)) (SIM_CPU *current_cpu,
                         const IDESC *idesc ATTRIBUTE_UNUSED,
                         const IDESC *idesc ATTRIBUTE_UNUSED,
                         int unit_num ATTRIBUTE_UNUSED,
                         int unit_num ATTRIBUTE_UNUSED,
                         int referenced ATTRIBUTE_UNUSED,
                         int referenced ATTRIBUTE_UNUSED,
                         int out_sr_regno)
                         int out_sr_regno)
{
{
  MODEL_CRISV32_DATA *model_data
  MODEL_CRISV32_DATA *model_data
    = (MODEL_CRISV32_DATA *) CPU_MODEL_DATA (current_cpu);
    = (MODEL_CRISV32_DATA *) CPU_MODEL_DATA (current_cpu);
 
 
  /* Mark that we made a jump.  */
  /* Mark that we made a jump.  */
  model_data->modf_regs
  model_data->modf_regs
    |= (CRIS_MODF_JUMP_MASK
    |= (CRIS_MODF_JUMP_MASK
        | (out_sr_regno == -1 || out_sr_regno == CRIS_BZ_REGNO
        | (out_sr_regno == -1 || out_sr_regno == CRIS_BZ_REGNO
           ? 0 : (1 << (out_sr_regno + 16))));
           ? 0 : (1 << (out_sr_regno + 16))));
  return 0;
  return 0;
}
}
 
 
/* Model function for u-multiply unit.  */
/* Model function for u-multiply unit.  */
 
 
int
int
MY (XCONCAT3 (f_model_crisv,BASENUM,
MY (XCONCAT3 (f_model_crisv,BASENUM,
              _u_multiply)) (SIM_CPU *current_cpu,
              _u_multiply)) (SIM_CPU *current_cpu,
                             const IDESC *idesc ATTRIBUTE_UNUSED,
                             const IDESC *idesc ATTRIBUTE_UNUSED,
                             int unit_num ATTRIBUTE_UNUSED,
                             int unit_num ATTRIBUTE_UNUSED,
                             int referenced ATTRIBUTE_UNUSED,
                             int referenced ATTRIBUTE_UNUSED,
                             int srcreg, int destreg)
                             int srcreg, int destreg)
{
{
  MODEL_CRISV32_DATA *model_data
  MODEL_CRISV32_DATA *model_data
    = (MODEL_CRISV32_DATA *) CPU_MODEL_DATA (current_cpu);
    = (MODEL_CRISV32_DATA *) CPU_MODEL_DATA (current_cpu);
 
 
  /* Sanity-check for cases that should never happen.  */
  /* Sanity-check for cases that should never happen.  */
  if (srcreg == -1 || destreg == -1)
  if (srcreg == -1 || destreg == -1)
    abort ();
    abort ();
 
 
  /* This takes extra cycles when one of the inputs has been modified
  /* This takes extra cycles when one of the inputs has been modified
     through other than autoincrement in the previous cycle.  Penalty:
     through other than autoincrement in the previous cycle.  Penalty:
     one cycle.  */
     one cycle.  */
  if (((1 << srcreg) | (1 << destreg)) & model_data->prev_modf_regs)
  if (((1 << srcreg) | (1 << destreg)) & model_data->prev_modf_regs)
    PENALIZE1 (mulsrc_stall_count);
    PENALIZE1 (mulsrc_stall_count);
 
 
  /* We modified the multiplication destination (marked in u-exec) and
  /* We modified the multiplication destination (marked in u-exec) and
     the MOF register.  */
     the MOF register.  */
  model_data->modf_regs |= (1 << CRIS_MOF_REGNO);
  model_data->modf_regs |= (1 << CRIS_MOF_REGNO);
  return 0;
  return 0;
}
}
 
 
#endif /* WITH_PROFILE_MODEL_P */
#endif /* WITH_PROFILE_MODEL_P */
 
 
int
int
MY (deliver_interrupt) (SIM_CPU *current_cpu,
MY (deliver_interrupt) (SIM_CPU *current_cpu,
                        enum cris_interrupt_type type,
                        enum cris_interrupt_type type,
                        unsigned int vec)
                        unsigned int vec)
{
{
  unsigned32 old_ccs, shifted_ccs, new_ccs;
  unsigned32 old_ccs, shifted_ccs, new_ccs;
  unsigned char entryaddr_le[4];
  unsigned char entryaddr_le[4];
  int was_user;
  int was_user;
  SIM_DESC sd = CPU_STATE (current_cpu);
  SIM_DESC sd = CPU_STATE (current_cpu);
  unsigned32 entryaddr;
  unsigned32 entryaddr;
 
 
  /* We haven't implemented other interrupt-types yet.  */
  /* We haven't implemented other interrupt-types yet.  */
  if (type != CRIS_INT_INT)
  if (type != CRIS_INT_INT)
    abort ();
    abort ();
 
 
  /* We're called outside of branch delay slots etc, so we don't check
  /* We're called outside of branch delay slots etc, so we don't check
     for that.  */
     for that.  */
  if (!GET_H_IBIT_V32 ())
  if (!GET_H_IBIT_V32 ())
    return 0;
    return 0;
 
 
  old_ccs = GET_H_SR_V32 (H_SR_CCS);
  old_ccs = GET_H_SR_V32 (H_SR_CCS);
  shifted_ccs = (old_ccs << 10) & ((1 << 30) - 1);
  shifted_ccs = (old_ccs << 10) & ((1 << 30) - 1);
 
 
  /* The M bit is handled by code below and the M bit setter function, but
  /* The M bit is handled by code below and the M bit setter function, but
     we need to preserve the Q bit.  */
     we need to preserve the Q bit.  */
  new_ccs = shifted_ccs | (old_ccs & (unsigned32) 0x80000000UL);
  new_ccs = shifted_ccs | (old_ccs & (unsigned32) 0x80000000UL);
  was_user = GET_H_UBIT_V32 ();
  was_user = GET_H_UBIT_V32 ();
 
 
  /* We need to force kernel mode since the setter method doesn't allow
  /* We need to force kernel mode since the setter method doesn't allow
     it.  Then we can use setter methods at will, since they then
     it.  Then we can use setter methods at will, since they then
     recognize that we're in kernel mode.  */
     recognize that we're in kernel mode.  */
  CPU (h_ubit_v32) = 0;
  CPU (h_ubit_v32) = 0;
 
 
  SET_H_SR (H_SR_CCS, new_ccs);
  SET_H_SR (H_SR_CCS, new_ccs);
 
 
  if (was_user)
  if (was_user)
    {
    {
      /* These methods require that user mode is unset.  */
      /* These methods require that user mode is unset.  */
      SET_H_SR (H_SR_USP, GET_H_GR (H_GR_SP));
      SET_H_SR (H_SR_USP, GET_H_GR (H_GR_SP));
      SET_H_GR (H_GR_SP, GET_H_KERNEL_SP ());
      SET_H_GR (H_GR_SP, GET_H_KERNEL_SP ());
    }
    }
 
 
  /* ERP setting is simplified by not taking interrupts in delay-slots
  /* ERP setting is simplified by not taking interrupts in delay-slots
     or when halting.  */
     or when halting.  */
  /* For all other exceptions than guru and NMI, store the return
  /* For all other exceptions than guru and NMI, store the return
     address in ERP and set EXS and EXD here.  */
     address in ERP and set EXS and EXD here.  */
  SET_H_SR (H_SR_ERP, GET_H_PC ());
  SET_H_SR (H_SR_ERP, GET_H_PC ());
 
 
  /* Simplified by not having exception types (fault indications).  */
  /* Simplified by not having exception types (fault indications).  */
  SET_H_SR_V32 (H_SR_EXS, (vec * 256));
  SET_H_SR_V32 (H_SR_EXS, (vec * 256));
  SET_H_SR_V32 (H_SR_EDA, 0);
  SET_H_SR_V32 (H_SR_EDA, 0);
 
 
  if (sim_core_read_buffer (sd,
  if (sim_core_read_buffer (sd,
                            current_cpu,
                            current_cpu,
                            read_map, entryaddr_le,
                            read_map, entryaddr_le,
                            GET_H_SR (H_SR_EBP) + vec * 4, 4) == 0)
                            GET_H_SR (H_SR_EBP) + vec * 4, 4) == 0)
    {
    {
      /* Nothing to do actually; either abort or send a signal.  */
      /* Nothing to do actually; either abort or send a signal.  */
      sim_core_signal (sd, current_cpu, CIA_GET (current_cpu), 0, 4,
      sim_core_signal (sd, current_cpu, CIA_GET (current_cpu), 0, 4,
                       GET_H_SR (H_SR_EBP) + vec * 4,
                       GET_H_SR (H_SR_EBP) + vec * 4,
                       read_transfer, sim_core_unmapped_signal);
                       read_transfer, sim_core_unmapped_signal);
      return 0;
      return 0;
    }
    }
 
 
  entryaddr = bfd_getl32 (entryaddr_le);
  entryaddr = bfd_getl32 (entryaddr_le);
  SET_H_PC (entryaddr);
  SET_H_PC (entryaddr);
 
 
  return 1;
  return 1;
}
}
 
 

powered by: WebSVN 2.1.0

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