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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-stable/] [gdb-7.2/] [sim/] [rx/] [reg.c] - Diff between revs 835 and 841

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

Rev 835 Rev 841
/* reg.c --- register set model for RX simulator.
/* reg.c --- register set model for RX simulator.
 
 
   Copyright (C) 2005, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
   Copyright (C) 2005, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
   Contributed by Red Hat, Inc.
   Contributed by Red Hat, Inc.
 
 
   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/>.  */
 
 
 
 
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
 
 
#include "cpu.h"
#include "cpu.h"
#include "bfd.h"
#include "bfd.h"
#include "trace.h"
#include "trace.h"
 
 
int verbose = 0;
int verbose = 0;
int trace = 0;
int trace = 0;
int enable_counting = 0;
int enable_counting = 0;
 
 
int rx_in_gdb = 1;
int rx_in_gdb = 1;
 
 
int rx_flagmask;
int rx_flagmask;
int rx_flagand;
int rx_flagand;
int rx_flagor;
int rx_flagor;
 
 
int rx_big_endian;
int rx_big_endian;
regs_type regs;
regs_type regs;
int step_result;
int step_result;
unsigned int heapbottom = 0;
unsigned int heapbottom = 0;
unsigned int heaptop = 0;
unsigned int heaptop = 0;
 
 
char *reg_names[] = {
char *reg_names[] = {
  /* general registers */
  /* general registers */
  "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
  "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
  "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
  "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
  /* control register */
  /* control register */
  "psw", "pc", "usp", "fpsw", "RES", "RES", "RES", "RES",
  "psw", "pc", "usp", "fpsw", "RES", "RES", "RES", "RES",
  "bpsw", "bpc", "isp", "fintv", "intb", "RES", "RES", "RES",
  "bpsw", "bpc", "isp", "fintv", "intb", "RES", "RES", "RES",
  "RES", "RES", "RES", "RES", "RES", "RES", "RES", "RES",
  "RES", "RES", "RES", "RES", "RES", "RES", "RES", "RES",
  "RES", "RES", "RES", "RES", "RES", "RES", "RES", "RES",
  "RES", "RES", "RES", "RES", "RES", "RES", "RES", "RES",
  "temp", "acc", "acchi", "accmi", "acclo"
  "temp", "acc", "acchi", "accmi", "acclo"
};
};
 
 
unsigned int b2mask[] = { 0, 0xff, 0xffff, 0xffffff, 0xffffffff };
unsigned int b2mask[] = { 0, 0xff, 0xffff, 0xffffff, 0xffffffff };
unsigned int b2signbit[] = { 0, (1 << 7), (1 << 15), (1 << 24), (1 << 31) };
unsigned int b2signbit[] = { 0, (1 << 7), (1 << 15), (1 << 24), (1 << 31) };
int b2maxsigned[] = { 0, 0x7f, 0x7fff, 0x7fffff, 0x7fffffff };
int b2maxsigned[] = { 0, 0x7f, 0x7fff, 0x7fffff, 0x7fffffff };
int b2minsigned[] = { 0, -128, -32768, -8388608, -2147483647 - 1 };
int b2minsigned[] = { 0, -128, -32768, -8388608, -2147483647 - 1 };
 
 
static regs_type oldregs;
static regs_type oldregs;
 
 
void
void
init_regs (void)
init_regs (void)
{
{
  memset (&regs, 0, sizeof (regs));
  memset (&regs, 0, sizeof (regs));
  memset (&oldregs, 0, sizeof (oldregs));
  memset (&oldregs, 0, sizeof (oldregs));
}
}
 
 
static unsigned int
static unsigned int
get_reg_i (int id)
get_reg_i (int id)
{
{
  if (id == 0)
  if (id == 0)
    return regs.r_psw & FLAGBIT_U ? regs.r_usp : regs.r_isp;
    return regs.r_psw & FLAGBIT_U ? regs.r_usp : regs.r_isp;
 
 
  if (id >= 1 && id <= 15)
  if (id >= 1 && id <= 15)
    return regs.r[id];
    return regs.r[id];
 
 
  switch (id)
  switch (id)
    {
    {
    case psw:
    case psw:
      return regs.r_psw;
      return regs.r_psw;
    case fpsw:
    case fpsw:
      return regs.r_fpsw;
      return regs.r_fpsw;
    case isp:
    case isp:
      return regs.r_isp;
      return regs.r_isp;
    case usp:
    case usp:
      return regs.r_usp;
      return regs.r_usp;
    case bpc:
    case bpc:
      return regs.r_bpc;
      return regs.r_bpc;
    case bpsw:
    case bpsw:
      return regs.r_bpsw;
      return regs.r_bpsw;
    case fintv:
    case fintv:
      return regs.r_fintv;
      return regs.r_fintv;
    case intb:
    case intb:
      return regs.r_intb;
      return regs.r_intb;
    case pc:
    case pc:
      return regs.r_pc;
      return regs.r_pc;
    case r_temp_idx:
    case r_temp_idx:
      return regs.r_temp;
      return regs.r_temp;
    case acchi:
    case acchi:
      return (SI)(regs.r_acc >> 32);
      return (SI)(regs.r_acc >> 32);
    case accmi:
    case accmi:
      return (SI)(regs.r_acc >> 16);
      return (SI)(regs.r_acc >> 16);
    case acclo:
    case acclo:
      return (SI)regs.r_acc;
      return (SI)regs.r_acc;
    }
    }
  abort();
  abort();
}
}
 
 
unsigned int
unsigned int
get_reg (int id)
get_reg (int id)
{
{
  unsigned int rv = get_reg_i (id);
  unsigned int rv = get_reg_i (id);
  if (trace > ((id != pc && id != sp) ? 0 : 1))
  if (trace > ((id != pc && id != sp) ? 0 : 1))
    printf ("get_reg (%s) = %08x\n", reg_names[id], rv);
    printf ("get_reg (%s) = %08x\n", reg_names[id], rv);
  return rv;
  return rv;
}
}
 
 
static unsigned long long
static unsigned long long
get_reg64_i (int id)
get_reg64_i (int id)
{
{
  switch (id)
  switch (id)
    {
    {
    case acc64:
    case acc64:
      return regs.r_acc;
      return regs.r_acc;
    default:
    default:
      abort ();
      abort ();
    }
    }
}
}
 
 
unsigned long long
unsigned long long
get_reg64 (int id)
get_reg64 (int id)
{
{
  unsigned long long rv = get_reg64_i (id);
  unsigned long long rv = get_reg64_i (id);
  if (trace > ((id != pc && id != sp) ? 0 : 1))
  if (trace > ((id != pc && id != sp) ? 0 : 1))
    printf ("get_reg (%s) = %016llx\n", reg_names[id], rv);
    printf ("get_reg (%s) = %016llx\n", reg_names[id], rv);
  return rv;
  return rv;
}
}
 
 
static int highest_sp = 0, lowest_sp = 0xffffff;
static int highest_sp = 0, lowest_sp = 0xffffff;
 
 
void
void
stack_heap_stats ()
stack_heap_stats ()
{
{
  if (heapbottom < heaptop)
  if (heapbottom < heaptop)
    printf ("heap:  %08x - %08x (%d bytes)\n", heapbottom, heaptop,
    printf ("heap:  %08x - %08x (%d bytes)\n", heapbottom, heaptop,
            heaptop - heapbottom);
            heaptop - heapbottom);
  if (lowest_sp < highest_sp)
  if (lowest_sp < highest_sp)
    printf ("stack: %08x - %08x (%d bytes)\n", lowest_sp, highest_sp,
    printf ("stack: %08x - %08x (%d bytes)\n", lowest_sp, highest_sp,
            highest_sp - lowest_sp);
            highest_sp - lowest_sp);
}
}
 
 
void
void
put_reg (int id, unsigned int v)
put_reg (int id, unsigned int v)
{
{
  if (trace > ((id != pc) ? 0 : 1))
  if (trace > ((id != pc) ? 0 : 1))
    printf ("put_reg (%s) = %08x\n", reg_names[id], v);
    printf ("put_reg (%s) = %08x\n", reg_names[id], v);
 
 
 
 
  switch (id)
  switch (id)
    {
    {
    case psw:
    case psw:
      regs.r_psw = v;
      regs.r_psw = v;
      break;
      break;
    case fpsw:
    case fpsw:
      {
      {
        SI anded;
        SI anded;
        /* This is an odd one - The Cx flags are AND'd, and the FS flag
        /* This is an odd one - The Cx flags are AND'd, and the FS flag
           is synthetic.  */
           is synthetic.  */
        anded = regs.r_fpsw & v;
        anded = regs.r_fpsw & v;
        anded |= ~ FPSWBITS_CMASK;
        anded |= ~ FPSWBITS_CMASK;
        regs.r_fpsw = v & anded;
        regs.r_fpsw = v & anded;
        if (regs.r_fpsw & FPSWBITS_FMASK)
        if (regs.r_fpsw & FPSWBITS_FMASK)
          regs.r_fpsw |= FPSWBITS_FSUM;
          regs.r_fpsw |= FPSWBITS_FSUM;
        else
        else
          regs.r_fpsw &= ~FPSWBITS_FSUM;
          regs.r_fpsw &= ~FPSWBITS_FSUM;
      }
      }
      break;
      break;
    case isp:
    case isp:
      regs.r_isp = v;
      regs.r_isp = v;
      break;
      break;
    case usp:
    case usp:
      regs.r_usp = v;
      regs.r_usp = v;
      break;
      break;
    case bpc:
    case bpc:
      regs.r_bpc = v;
      regs.r_bpc = v;
      break;
      break;
    case bpsw:
    case bpsw:
      regs.r_bpsw = v;
      regs.r_bpsw = v;
      break;
      break;
    case fintv:
    case fintv:
      regs.r_fintv = v;
      regs.r_fintv = v;
      break;
      break;
    case intb:
    case intb:
      regs.r_intb = v;
      regs.r_intb = v;
      break;
      break;
    case pc:
    case pc:
      regs.r_pc = v;
      regs.r_pc = v;
      break;
      break;
 
 
    case acchi:
    case acchi:
      regs.r_acc = (regs.r_acc & 0xffffffffULL) | ((DI)v << 32);
      regs.r_acc = (regs.r_acc & 0xffffffffULL) | ((DI)v << 32);
      break;
      break;
    case accmi:
    case accmi:
      regs.r_acc = (regs.r_acc & ~0xffffffff0000ULL) | ((DI)v << 16);
      regs.r_acc = (regs.r_acc & ~0xffffffff0000ULL) | ((DI)v << 16);
      break;
      break;
    case acclo:
    case acclo:
      regs.r_acc = (regs.r_acc & ~0xffffffffULL) | ((DI)v);
      regs.r_acc = (regs.r_acc & ~0xffffffffULL) | ((DI)v);
      break;
      break;
 
 
    case 0: /* Stack pointer is "in" R0.  */
    case 0: /* Stack pointer is "in" R0.  */
      {
      {
        if (v < heaptop)
        if (v < heaptop)
          {
          {
            unsigned int line;
            unsigned int line;
            const char * dummy;
            const char * dummy;
            const char * fname = NULL;
            const char * fname = NULL;
 
 
            sim_get_current_source_location (& dummy, & fname, &line);
            sim_get_current_source_location (& dummy, & fname, &line);
 
 
            /* The setjmp and longjmp functions play tricks with the stack pointer.  */
            /* The setjmp and longjmp functions play tricks with the stack pointer.  */
            if (fname == NULL
            if (fname == NULL
                || (strcmp (fname, "_setjmp") != 0
                || (strcmp (fname, "_setjmp") != 0
                    && strcmp (fname, "_longjmp") != 0))
                    && strcmp (fname, "_longjmp") != 0))
              {
              {
                printf ("collision in %s: pc %08x heap %08x stack %08x\n",
                printf ("collision in %s: pc %08x heap %08x stack %08x\n",
                        fname, (unsigned int) regs.r_pc, heaptop, v);
                        fname, (unsigned int) regs.r_pc, heaptop, v);
                exit (1);
                exit (1);
              }
              }
          }
          }
        else
        else
          {
          {
            if (v < lowest_sp)
            if (v < lowest_sp)
              lowest_sp = v;
              lowest_sp = v;
            if (v > highest_sp)
            if (v > highest_sp)
              highest_sp = v;
              highest_sp = v;
          }
          }
 
 
        if (regs.r_psw & FLAGBIT_U)
        if (regs.r_psw & FLAGBIT_U)
          regs.r_usp = v;
          regs.r_usp = v;
        else
        else
          regs.r_isp = v;
          regs.r_isp = v;
        break;
        break;
      }
      }
 
 
    default:
    default:
      if (id >= 1 || id <= 15)
      if (id >= 1 || id <= 15)
        regs.r[id] = v;
        regs.r[id] = v;
      else
      else
        abort ();
        abort ();
    }
    }
}
}
 
 
void
void
put_reg64 (int id, unsigned long long v)
put_reg64 (int id, unsigned long long v)
{
{
  if (trace > ((id != pc) ? 0 : 1))
  if (trace > ((id != pc) ? 0 : 1))
    printf ("put_reg (%s) = %016llx\n", reg_names[id], v);
    printf ("put_reg (%s) = %016llx\n", reg_names[id], v);
 
 
  switch (id)
  switch (id)
    {
    {
    case acc64:
    case acc64:
      regs.r_acc = v;
      regs.r_acc = v;
      break;
      break;
    default:
    default:
      abort ();
      abort ();
    }
    }
}
}
 
 
int
int
condition_true (int cond_id)
condition_true (int cond_id)
{
{
  int f;
  int f;
 
 
  static const char *cond_name[] = {
  static const char *cond_name[] = {
    "Z",
    "Z",
    "!Z",
    "!Z",
    "C",
    "C",
    "!C",
    "!C",
    "C&!Z",
    "C&!Z",
    "!(C&!Z)",
    "!(C&!Z)",
    "!S",
    "!S",
    "S",
    "S",
    "!(S^O)",
    "!(S^O)",
    "S^O",
    "S^O",
    "!((S^O)|Z)",
    "!((S^O)|Z)",
    "(S^O)|Z",
    "(S^O)|Z",
    "O",
    "O",
    "!O",
    "!O",
    "always",
    "always",
    "never"
    "never"
  };
  };
  switch (cond_id & 15)
  switch (cond_id & 15)
    {
    {
    case 0:
    case 0:
      f = FLAG_Z;
      f = FLAG_Z;
      break;            /* EQ/Z */
      break;            /* EQ/Z */
    case 1:
    case 1:
      f = !FLAG_Z;
      f = !FLAG_Z;
      break;            /* NE/NZ */
      break;            /* NE/NZ */
    case 2:
    case 2:
      f = FLAG_C;
      f = FLAG_C;
      break;            /* GEU/C */
      break;            /* GEU/C */
    case 3:
    case 3:
      f = !FLAG_C;
      f = !FLAG_C;
      break;            /* LTU/NC */
      break;            /* LTU/NC */
    case 4:
    case 4:
      f = FLAG_C & !FLAG_Z;
      f = FLAG_C & !FLAG_Z;
      break;            /* GTU */
      break;            /* GTU */
    case 5:
    case 5:
      f = !(FLAG_C & !FLAG_Z);
      f = !(FLAG_C & !FLAG_Z);
      break;            /* LEU */
      break;            /* LEU */
    case 6:
    case 6:
      f = !FLAG_S;
      f = !FLAG_S;
      break;            /* PZ */
      break;            /* PZ */
    case 7:
    case 7:
      f = FLAG_S;
      f = FLAG_S;
      break;            /* N */
      break;            /* N */
 
 
    case 8:
    case 8:
      f = !(FLAG_S ^ FLAG_O);
      f = !(FLAG_S ^ FLAG_O);
      break;            /* GE */
      break;            /* GE */
    case 9:
    case 9:
      f = FLAG_S ^ FLAG_O;
      f = FLAG_S ^ FLAG_O;
      break;            /* LT */
      break;            /* LT */
    case 10:
    case 10:
      f = !((FLAG_S ^ FLAG_O) | FLAG_Z);
      f = !((FLAG_S ^ FLAG_O) | FLAG_Z);
      break;            /* GT */
      break;            /* GT */
    case 11:
    case 11:
      f = (FLAG_S ^ FLAG_O) | FLAG_Z;
      f = (FLAG_S ^ FLAG_O) | FLAG_Z;
      break;            /* LE */
      break;            /* LE */
    case 12:
    case 12:
      f = FLAG_O;
      f = FLAG_O;
      break;            /* O */
      break;            /* O */
    case 13:
    case 13:
      f = !FLAG_O;
      f = !FLAG_O;
      break;            /* NO */
      break;            /* NO */
    case 14:
    case 14:
      f = 1;            /* always */
      f = 1;            /* always */
      break;
      break;
    default:
    default:
      f = 0;             /* never */
      f = 0;             /* never */
      break;
      break;
    }
    }
  if (trace && ((cond_id & 15) != 14))
  if (trace && ((cond_id & 15) != 14))
    printf ("cond[%d] %s = %s\n", cond_id, cond_name[cond_id & 15],
    printf ("cond[%d] %s = %s\n", cond_id, cond_name[cond_id & 15],
            f ? "true" : "false");
            f ? "true" : "false");
  return f;
  return f;
}
}
 
 
void
void
set_flags (int mask, int newbits)
set_flags (int mask, int newbits)
{
{
  regs.r_psw &= rx_flagand;
  regs.r_psw &= rx_flagand;
  regs.r_psw |= rx_flagor;
  regs.r_psw |= rx_flagor;
  regs.r_psw |= (newbits & mask & rx_flagmask);
  regs.r_psw |= (newbits & mask & rx_flagmask);
 
 
  if (trace)
  if (trace)
    {
    {
      int i;
      int i;
      printf ("flags now \033[32m %d", (int)((regs.r_psw >> 24) & 7));
      printf ("flags now \033[32m %d", (int)((regs.r_psw >> 24) & 7));
      for (i = 17; i >= 0; i--)
      for (i = 17; i >= 0; i--)
        if (0x3000f & (1 << i))
        if (0x3000f & (1 << i))
          {
          {
            if (regs.r_psw & (1 << i))
            if (regs.r_psw & (1 << i))
              putchar ("CZSO------------IU"[i]);
              putchar ("CZSO------------IU"[i]);
            else
            else
              putchar ('-');
              putchar ('-');
          }
          }
      printf ("\033[0m\n");
      printf ("\033[0m\n");
    }
    }
}
}
 
 
void
void
set_oszc (long long value, int b, int c)
set_oszc (long long value, int b, int c)
{
{
  unsigned int mask = b2mask[b];
  unsigned int mask = b2mask[b];
  int f = 0;
  int f = 0;
 
 
  if (c)
  if (c)
    f |= FLAGBIT_C;
    f |= FLAGBIT_C;
  if ((value & mask) == 0)
  if ((value & mask) == 0)
    f |= FLAGBIT_Z;
    f |= FLAGBIT_Z;
  if (value & b2signbit[b])
  if (value & b2signbit[b])
    f |= FLAGBIT_S;
    f |= FLAGBIT_S;
  if ((value > b2maxsigned[b]) || (value < b2minsigned[b]))
  if ((value > b2maxsigned[b]) || (value < b2minsigned[b]))
    f |= FLAGBIT_O;
    f |= FLAGBIT_O;
  set_flags (FLAGBIT_Z | FLAGBIT_S | FLAGBIT_O | FLAGBIT_C, f);
  set_flags (FLAGBIT_Z | FLAGBIT_S | FLAGBIT_O | FLAGBIT_C, f);
}
}
 
 
void
void
set_szc (long long value, int b, int c)
set_szc (long long value, int b, int c)
{
{
  unsigned int mask = b2mask[b];
  unsigned int mask = b2mask[b];
  int f = 0;
  int f = 0;
 
 
  if (c)
  if (c)
    f |= FLAGBIT_C;
    f |= FLAGBIT_C;
  if ((value & mask) == 0)
  if ((value & mask) == 0)
    f |= FLAGBIT_Z;
    f |= FLAGBIT_Z;
  if (value & b2signbit[b])
  if (value & b2signbit[b])
    f |= FLAGBIT_S;
    f |= FLAGBIT_S;
  set_flags (FLAGBIT_Z | FLAGBIT_S | FLAGBIT_C, f);
  set_flags (FLAGBIT_Z | FLAGBIT_S | FLAGBIT_C, f);
}
}
 
 
void
void
set_osz (long long value, int b)
set_osz (long long value, int b)
{
{
  unsigned int mask = b2mask[b];
  unsigned int mask = b2mask[b];
  int f = 0;
  int f = 0;
 
 
  if ((value & mask) == 0)
  if ((value & mask) == 0)
    f |= FLAGBIT_Z;
    f |= FLAGBIT_Z;
  if (value & b2signbit[b])
  if (value & b2signbit[b])
    f |= FLAGBIT_S;
    f |= FLAGBIT_S;
  if ((value > b2maxsigned[b]) || (value < b2minsigned[b]))
  if ((value > b2maxsigned[b]) || (value < b2minsigned[b]))
    f |= FLAGBIT_O;
    f |= FLAGBIT_O;
  set_flags (FLAGBIT_Z | FLAGBIT_S | FLAGBIT_O, f);
  set_flags (FLAGBIT_Z | FLAGBIT_S | FLAGBIT_O, f);
}
}
 
 
void
void
set_sz (long long value, int b)
set_sz (long long value, int b)
{
{
  unsigned int mask = b2mask[b];
  unsigned int mask = b2mask[b];
  int f = 0;
  int f = 0;
 
 
  if ((value & mask) == 0)
  if ((value & mask) == 0)
    f |= FLAGBIT_Z;
    f |= FLAGBIT_Z;
  if (value & b2signbit[b])
  if (value & b2signbit[b])
    f |= FLAGBIT_S;
    f |= FLAGBIT_S;
  set_flags (FLAGBIT_Z | FLAGBIT_S, f);
  set_flags (FLAGBIT_Z | FLAGBIT_S, f);
}
}
 
 
void
void
set_zc (int z, int c)
set_zc (int z, int c)
{
{
  set_flags (FLAGBIT_C | FLAGBIT_Z,
  set_flags (FLAGBIT_C | FLAGBIT_Z,
             (c ? FLAGBIT_C : 0) | (z ? FLAGBIT_Z : 0));
             (c ? FLAGBIT_C : 0) | (z ? FLAGBIT_Z : 0));
}
}
 
 
void
void
set_c (int c)
set_c (int c)
{
{
  set_flags (FLAGBIT_C, c ? FLAGBIT_C : 0);
  set_flags (FLAGBIT_C, c ? FLAGBIT_C : 0);
}
}
 
 
static char *
static char *
psw2str(int rpsw)
psw2str(int rpsw)
{
{
  static char buf[10];
  static char buf[10];
  char *bp = buf;
  char *bp = buf;
  int i, ipl;
  int i, ipl;
 
 
  ipl = (rpsw & FLAGBITS_IPL) >> FLAGSHIFT_IPL;
  ipl = (rpsw & FLAGBITS_IPL) >> FLAGSHIFT_IPL;
  if (ipl > 9)
  if (ipl > 9)
    {
    {
      *bp++ = (ipl / 10) + '0';
      *bp++ = (ipl / 10) + '0';
      ipl %= 10;
      ipl %= 10;
    }
    }
  *bp++ = ipl + '0';
  *bp++ = ipl + '0';
  for (i = 20; i >= 0; i--)
  for (i = 20; i >= 0; i--)
    if (0x13000f & (1 << i))
    if (0x13000f & (1 << i))
      {
      {
        if (rpsw & (1 << i))
        if (rpsw & (1 << i))
          *bp++ = "CZSO------------IU--P"[i];
          *bp++ = "CZSO------------IU--P"[i];
        else
        else
          *bp++ = '-';
          *bp++ = '-';
      }
      }
  *bp = 0;
  *bp = 0;
  return buf;
  return buf;
}
}
 
 
static char *
static char *
fpsw2str(int rpsw)
fpsw2str(int rpsw)
{
{
  static char buf[100];
  static char buf[100];
  char *bp = buf;
  char *bp = buf;
  int i;        /*   ---+---+---+---+---+---+---+---+ */
  int i;        /*   ---+---+---+---+---+---+---+---+ */
  const char s1[] = "FFFFFF-----------EEEEE-DCCCCCCRR";
  const char s1[] = "FFFFFF-----------EEEEE-DCCCCCCRR";
  const char s2[] = "SXUZOV-----------XUZOV-NEXUZOV01";
  const char s2[] = "SXUZOV-----------XUZOV-NEXUZOV01";
  const char rm[4][3] = { "RC", "RZ", "RP", "RN" };
  const char rm[4][3] = { "RC", "RZ", "RP", "RN" };
 
 
  for (i = 31; i >= 0; i--)
  for (i = 31; i >= 0; i--)
    if (0xfc007dfc & (1 << i))
    if (0xfc007dfc & (1 << i))
      {
      {
        if (rpsw & (1 << i))
        if (rpsw & (1 << i))
          {
          {
            if (bp > buf)
            if (bp > buf)
              *bp++ = '.';
              *bp++ = '.';
            *bp++ = s1[31-i];
            *bp++ = s1[31-i];
            *bp++ = s2[31-i];
            *bp++ = s2[31-i];
          }
          }
      }
      }
  if (bp > buf)
  if (bp > buf)
    *bp++ = '.';
    *bp++ = '.';
  strcpy (bp, rm[rpsw&3]);
  strcpy (bp, rm[rpsw&3]);
  return buf;
  return buf;
}
}
 
 
#define TRC(f,n) \
#define TRC(f,n) \
  if (oldregs.f != regs.f) \
  if (oldregs.f != regs.f) \
    { \
    { \
      if (tag) { printf (tag); tag = 0; } \
      if (tag) { printf (tag); tag = 0; } \
      printf("  %s %08x:%08x", n, \
      printf("  %s %08x:%08x", n, \
             (unsigned int)oldregs.f, \
             (unsigned int)oldregs.f, \
             (unsigned int)regs.f); \
             (unsigned int)regs.f); \
      oldregs.f = regs.f; \
      oldregs.f = regs.f; \
    }
    }
 
 
void
void
trace_register_changes (void)
trace_register_changes (void)
{
{
  char *tag = "\033[36mREGS:";
  char *tag = "\033[36mREGS:";
  int i;
  int i;
 
 
  if (!trace)
  if (!trace)
    return;
    return;
  for (i=1; i<16; i++)
  for (i=1; i<16; i++)
    TRC (r[i], reg_names[i]);
    TRC (r[i], reg_names[i]);
  TRC (r_intb, "intb");
  TRC (r_intb, "intb");
  TRC (r_usp, "usp");
  TRC (r_usp, "usp");
  TRC (r_isp, "isp");
  TRC (r_isp, "isp");
  if (oldregs.r_psw != regs.r_psw)
  if (oldregs.r_psw != regs.r_psw)
    {
    {
      if (tag) { printf (tag); tag = 0; }
      if (tag) { printf (tag); tag = 0; }
      printf("  psw %s:", psw2str(oldregs.r_psw));
      printf("  psw %s:", psw2str(oldregs.r_psw));
      printf("%s", psw2str(regs.r_psw));
      printf("%s", psw2str(regs.r_psw));
      oldregs.r_psw = regs.r_psw;
      oldregs.r_psw = regs.r_psw;
    }
    }
 
 
  if (oldregs.r_fpsw != regs.r_fpsw)
  if (oldregs.r_fpsw != regs.r_fpsw)
    {
    {
      if (tag) { printf (tag); tag = 0; }
      if (tag) { printf (tag); tag = 0; }
      printf("  fpsw %s:", fpsw2str(oldregs.r_fpsw));
      printf("  fpsw %s:", fpsw2str(oldregs.r_fpsw));
      printf("%s", fpsw2str(regs.r_fpsw));
      printf("%s", fpsw2str(regs.r_fpsw));
      oldregs.r_fpsw = regs.r_fpsw;
      oldregs.r_fpsw = regs.r_fpsw;
    }
    }
 
 
  if (oldregs.r_acc != regs.r_acc)
  if (oldregs.r_acc != regs.r_acc)
    {
    {
      if (tag) { printf (tag); tag = 0; }
      if (tag) { printf (tag); tag = 0; }
      printf("  acc %016llx:", oldregs.r_acc);
      printf("  acc %016llx:", oldregs.r_acc);
      printf("%016llx", regs.r_acc);
      printf("%016llx", regs.r_acc);
      oldregs.r_acc = regs.r_acc;
      oldregs.r_acc = regs.r_acc;
    }
    }
 
 
  if (tag == 0)
  if (tag == 0)
    printf ("\033[0m\n");
    printf ("\033[0m\n");
}
}
 
 

powered by: WebSVN 2.1.0

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