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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [gdb-7.1/] [sim/] [rx/] [gdb-if.c] - Diff between revs 227 and 816

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 227 Rev 816
/* gdb-if.c -- sim interface to GDB.
/* gdb-if.c -- sim interface to GDB.
 
 
Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc.
Copyright (C) 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 <assert.h>
#include <assert.h>
#include <signal.h>
#include <signal.h>
#include <string.h>
#include <string.h>
#include <ctype.h>
#include <ctype.h>
#include <stdlib.h>
#include <stdlib.h>
 
 
#include "ansidecl.h"
#include "ansidecl.h"
#include "gdb/callback.h"
#include "gdb/callback.h"
#include "gdb/remote-sim.h"
#include "gdb/remote-sim.h"
#include "gdb/signals.h"
#include "gdb/signals.h"
#include "gdb/sim-rx.h"
#include "gdb/sim-rx.h"
 
 
#include "cpu.h"
#include "cpu.h"
#include "mem.h"
#include "mem.h"
#include "load.h"
#include "load.h"
#include "syscalls.h"
#include "syscalls.h"
#include "err.h"
#include "err.h"
 
 
/* Ideally, we'd wrap up all the minisim's data structures in an
/* Ideally, we'd wrap up all the minisim's data structures in an
   object and pass that around.  However, neither GDB nor run needs
   object and pass that around.  However, neither GDB nor run needs
   that ability.
   that ability.
 
 
   So we just have one instance, that lives in global variables, and
   So we just have one instance, that lives in global variables, and
   each time we open it, we re-initialize it.  */
   each time we open it, we re-initialize it.  */
struct sim_state
struct sim_state
{
{
  const char *message;
  const char *message;
};
};
 
 
static struct sim_state the_minisim = {
static struct sim_state the_minisim = {
  "This is the sole rx minisim instance.  See libsim.a's global variables."
  "This is the sole rx minisim instance.  See libsim.a's global variables."
};
};
 
 
static int open;
static int open;
 
 
SIM_DESC
SIM_DESC
sim_open (SIM_OPEN_KIND kind,
sim_open (SIM_OPEN_KIND kind,
          struct host_callback_struct *callback,
          struct host_callback_struct *callback,
          struct bfd *abfd, char **argv)
          struct bfd *abfd, char **argv)
{
{
  if (open)
  if (open)
    fprintf (stderr, "rx minisim: re-opened sim\n");
    fprintf (stderr, "rx minisim: re-opened sim\n");
 
 
  /* The 'run' interface doesn't use this function, so we don't care
  /* The 'run' interface doesn't use this function, so we don't care
     about KIND; it's always SIM_OPEN_DEBUG.  */
     about KIND; it's always SIM_OPEN_DEBUG.  */
  if (kind != SIM_OPEN_DEBUG)
  if (kind != SIM_OPEN_DEBUG)
    fprintf (stderr, "rx minisim: sim_open KIND != SIM_OPEN_DEBUG: %d\n",
    fprintf (stderr, "rx minisim: sim_open KIND != SIM_OPEN_DEBUG: %d\n",
             kind);
             kind);
 
 
  set_callbacks (callback);
  set_callbacks (callback);
 
 
  /* We don't expect any command-line arguments.  */
  /* We don't expect any command-line arguments.  */
 
 
  init_mem ();
  init_mem ();
  init_regs ();
  init_regs ();
  execution_error_init_debugger ();
  execution_error_init_debugger ();
 
 
  sim_disasm_init (abfd);
  sim_disasm_init (abfd);
  open = 1;
  open = 1;
  return &the_minisim;
  return &the_minisim;
}
}
 
 
static void
static void
check_desc (SIM_DESC sd)
check_desc (SIM_DESC sd)
{
{
  if (sd != &the_minisim)
  if (sd != &the_minisim)
    fprintf (stderr, "rx minisim: desc != &the_minisim\n");
    fprintf (stderr, "rx minisim: desc != &the_minisim\n");
}
}
 
 
void
void
sim_close (SIM_DESC sd, int quitting)
sim_close (SIM_DESC sd, int quitting)
{
{
  check_desc (sd);
  check_desc (sd);
 
 
  /* Not much to do.  At least free up our memory.  */
  /* Not much to do.  At least free up our memory.  */
  init_mem ();
  init_mem ();
 
 
  open = 0;
  open = 0;
}
}
 
 
static bfd *
static bfd *
open_objfile (const char *filename)
open_objfile (const char *filename)
{
{
  bfd *prog = bfd_openr (filename, 0);
  bfd *prog = bfd_openr (filename, 0);
 
 
  if (!prog)
  if (!prog)
    {
    {
      fprintf (stderr, "Can't read %s\n", filename);
      fprintf (stderr, "Can't read %s\n", filename);
      return 0;
      return 0;
    }
    }
 
 
  if (!bfd_check_format (prog, bfd_object))
  if (!bfd_check_format (prog, bfd_object))
    {
    {
      fprintf (stderr, "%s not a rx program\n", filename);
      fprintf (stderr, "%s not a rx program\n", filename);
      return 0;
      return 0;
    }
    }
 
 
  return prog;
  return prog;
}
}
 
 
static struct swap_list
static struct swap_list
{
{
  bfd_vma start, end;
  bfd_vma start, end;
  struct swap_list *next;
  struct swap_list *next;
} *swap_list = NULL;
} *swap_list = NULL;
 
 
static void
static void
free_swap_list (void)
free_swap_list (void)
{
{
  while (swap_list)
  while (swap_list)
    {
    {
      struct swap_list *next = swap_list->next;
      struct swap_list *next = swap_list->next;
      free (swap_list);
      free (swap_list);
      swap_list = next;
      swap_list = next;
    }
    }
}
}
 
 
/* When running in big endian mode, we must do an additional
/* When running in big endian mode, we must do an additional
   byte swap of memory areas used to hold instructions.  See
   byte swap of memory areas used to hold instructions.  See
   the comment preceding rx_load in load.c to see why this is
   the comment preceding rx_load in load.c to see why this is
   so.
   so.
 
 
   Construct a list of memory areas that must be byte swapped.
   Construct a list of memory areas that must be byte swapped.
   This list will be consulted when either reading or writing
   This list will be consulted when either reading or writing
   memory.  */
   memory.  */
 
 
static void
static void
build_swap_list (struct bfd *abfd)
build_swap_list (struct bfd *abfd)
{
{
  asection *s;
  asection *s;
  free_swap_list ();
  free_swap_list ();
 
 
  /* Nothing to do when in little endian mode.  */
  /* Nothing to do when in little endian mode.  */
  if (!rx_big_endian)
  if (!rx_big_endian)
    return;
    return;
 
 
  for (s = abfd->sections; s; s = s->next)
  for (s = abfd->sections; s; s = s->next)
    {
    {
      if ((s->flags & SEC_LOAD) && (s->flags & SEC_CODE))
      if ((s->flags & SEC_LOAD) && (s->flags & SEC_CODE))
        {
        {
          struct swap_list *sl;
          struct swap_list *sl;
          bfd_size_type size;
          bfd_size_type size;
 
 
          size = bfd_get_section_size (s);
          size = bfd_get_section_size (s);
          if (size <= 0)
          if (size <= 0)
            continue;
            continue;
 
 
          sl = malloc (sizeof (struct swap_list));
          sl = malloc (sizeof (struct swap_list));
          assert (sl != NULL);
          assert (sl != NULL);
          sl->next = swap_list;
          sl->next = swap_list;
          sl->start = bfd_section_lma (abfd, s);
          sl->start = bfd_section_lma (abfd, s);
          sl->end = sl->start + size;
          sl->end = sl->start + size;
          swap_list = sl;
          swap_list = sl;
        }
        }
    }
    }
}
}
 
 
static int
static int
addr_in_swap_list (bfd_vma addr)
addr_in_swap_list (bfd_vma addr)
{
{
  struct swap_list *s;
  struct swap_list *s;
 
 
  for (s = swap_list; s; s = s->next)
  for (s = swap_list; s; s = s->next)
    {
    {
      if (s->start <= addr && addr < s->end)
      if (s->start <= addr && addr < s->end)
        return 1;
        return 1;
    }
    }
  return 0;
  return 0;
}
}
 
 
SIM_RC
SIM_RC
sim_load (SIM_DESC sd, char *prog, struct bfd *abfd, int from_tty)
sim_load (SIM_DESC sd, char *prog, struct bfd *abfd, int from_tty)
{
{
  check_desc (sd);
  check_desc (sd);
 
 
  if (!abfd)
  if (!abfd)
    abfd = open_objfile (prog);
    abfd = open_objfile (prog);
  if (!abfd)
  if (!abfd)
    return SIM_RC_FAIL;
    return SIM_RC_FAIL;
 
 
  rx_load (abfd);
  rx_load (abfd);
  build_swap_list (abfd);
  build_swap_list (abfd);
 
 
  return SIM_RC_OK;
  return SIM_RC_OK;
}
}
 
 
SIM_RC
SIM_RC
sim_create_inferior (SIM_DESC sd, struct bfd *abfd, char **argv, char **env)
sim_create_inferior (SIM_DESC sd, struct bfd *abfd, char **argv, char **env)
{
{
  check_desc (sd);
  check_desc (sd);
 
 
  if (abfd)
  if (abfd)
    {
    {
      rx_load (abfd);
      rx_load (abfd);
      build_swap_list (abfd);
      build_swap_list (abfd);
    }
    }
 
 
  return SIM_RC_OK;
  return SIM_RC_OK;
}
}
 
 
int
int
sim_read (SIM_DESC sd, SIM_ADDR mem, unsigned char *buf, int length)
sim_read (SIM_DESC sd, SIM_ADDR mem, unsigned char *buf, int length)
{
{
  int i;
  int i;
 
 
  check_desc (sd);
  check_desc (sd);
 
 
  if (mem == 0)
  if (mem == 0)
    return 0;
    return 0;
 
 
  execution_error_clear_last_error ();
  execution_error_clear_last_error ();
 
 
  for (i = 0; i < length; i++)
  for (i = 0; i < length; i++)
    {
    {
      bfd_vma addr = mem + i;
      bfd_vma addr = mem + i;
      int do_swap = addr_in_swap_list (addr);
      int do_swap = addr_in_swap_list (addr);
      buf[i] = mem_get_qi (addr ^ (do_swap ? 3 : 0));
      buf[i] = mem_get_qi (addr ^ (do_swap ? 3 : 0));
 
 
      if (execution_error_get_last_error () != SIM_ERR_NONE)
      if (execution_error_get_last_error () != SIM_ERR_NONE)
        return i;
        return i;
    }
    }
 
 
  return length;
  return length;
}
}
 
 
int
int
sim_write (SIM_DESC sd, SIM_ADDR mem, unsigned char *buf, int length)
sim_write (SIM_DESC sd, SIM_ADDR mem, unsigned char *buf, int length)
{
{
  int i;
  int i;
 
 
  check_desc (sd);
  check_desc (sd);
 
 
  execution_error_clear_last_error ();
  execution_error_clear_last_error ();
 
 
  for (i = 0; i < length; i++)
  for (i = 0; i < length; i++)
    {
    {
      bfd_vma addr = mem + i;
      bfd_vma addr = mem + i;
      int do_swap = addr_in_swap_list (addr);
      int do_swap = addr_in_swap_list (addr);
      mem_put_qi (addr ^ (do_swap ? 3 : 0), buf[i]);
      mem_put_qi (addr ^ (do_swap ? 3 : 0), buf[i]);
 
 
      if (execution_error_get_last_error () != SIM_ERR_NONE)
      if (execution_error_get_last_error () != SIM_ERR_NONE)
        return i;
        return i;
    }
    }
 
 
  return length;
  return length;
}
}
 
 
/* Read the LENGTH bytes at BUF as an little-endian value.  */
/* Read the LENGTH bytes at BUF as an little-endian value.  */
static DI
static DI
get_le (unsigned char *buf, int length)
get_le (unsigned char *buf, int length)
{
{
  DI acc = 0;
  DI acc = 0;
  while (--length >= 0)
  while (--length >= 0)
    acc = (acc << 8) + buf[length];
    acc = (acc << 8) + buf[length];
 
 
  return acc;
  return acc;
}
}
 
 
/* Read the LENGTH bytes at BUF as a big-endian value.  */
/* Read the LENGTH bytes at BUF as a big-endian value.  */
static DI
static DI
get_be (unsigned char *buf, int length)
get_be (unsigned char *buf, int length)
{
{
  DI acc = 0;
  DI acc = 0;
  while (length-- > 0)
  while (length-- > 0)
    acc = (acc << 8) + *buf++;
    acc = (acc << 8) + *buf++;
 
 
  return acc;
  return acc;
}
}
 
 
/* Store VAL as a little-endian value in the LENGTH bytes at BUF.  */
/* Store VAL as a little-endian value in the LENGTH bytes at BUF.  */
static void
static void
put_le (unsigned char *buf, int length, DI val)
put_le (unsigned char *buf, int length, DI val)
{
{
  int i;
  int i;
 
 
  for (i = 0; i < length; i++)
  for (i = 0; i < length; i++)
    {
    {
      buf[i] = val & 0xff;
      buf[i] = val & 0xff;
      val >>= 8;
      val >>= 8;
    }
    }
}
}
 
 
/* Store VAL as a big-endian value in the LENGTH bytes at BUF.  */
/* Store VAL as a big-endian value in the LENGTH bytes at BUF.  */
static void
static void
put_be (unsigned char *buf, int length, DI val)
put_be (unsigned char *buf, int length, DI val)
{
{
  int i;
  int i;
 
 
  for (i = length-1; i >= 0; i--)
  for (i = length-1; i >= 0; i--)
    {
    {
      buf[i] = val & 0xff;
      buf[i] = val & 0xff;
      val >>= 8;
      val >>= 8;
    }
    }
}
}
 
 
 
 
static int
static int
check_regno (enum sim_rx_regnum regno)
check_regno (enum sim_rx_regnum regno)
{
{
  return 0 <= regno && regno < sim_rx_num_regs;
  return 0 <= regno && regno < sim_rx_num_regs;
}
}
 
 
static size_t
static size_t
reg_size (enum sim_rx_regnum regno)
reg_size (enum sim_rx_regnum regno)
{
{
  size_t size;
  size_t size;
 
 
  switch (regno)
  switch (regno)
    {
    {
    case sim_rx_r0_regnum:
    case sim_rx_r0_regnum:
      size = sizeof (regs.r[0]);
      size = sizeof (regs.r[0]);
      break;
      break;
    case sim_rx_r1_regnum:
    case sim_rx_r1_regnum:
      size = sizeof (regs.r[1]);
      size = sizeof (regs.r[1]);
      break;
      break;
    case sim_rx_r2_regnum:
    case sim_rx_r2_regnum:
      size = sizeof (regs.r[2]);
      size = sizeof (regs.r[2]);
      break;
      break;
    case sim_rx_r3_regnum:
    case sim_rx_r3_regnum:
      size = sizeof (regs.r[3]);
      size = sizeof (regs.r[3]);
      break;
      break;
    case sim_rx_r4_regnum:
    case sim_rx_r4_regnum:
      size = sizeof (regs.r[4]);
      size = sizeof (regs.r[4]);
      break;
      break;
    case sim_rx_r5_regnum:
    case sim_rx_r5_regnum:
      size = sizeof (regs.r[5]);
      size = sizeof (regs.r[5]);
      break;
      break;
    case sim_rx_r6_regnum:
    case sim_rx_r6_regnum:
      size = sizeof (regs.r[6]);
      size = sizeof (regs.r[6]);
      break;
      break;
    case sim_rx_r7_regnum:
    case sim_rx_r7_regnum:
      size = sizeof (regs.r[7]);
      size = sizeof (regs.r[7]);
      break;
      break;
    case sim_rx_r8_regnum:
    case sim_rx_r8_regnum:
      size = sizeof (regs.r[8]);
      size = sizeof (regs.r[8]);
      break;
      break;
    case sim_rx_r9_regnum:
    case sim_rx_r9_regnum:
      size = sizeof (regs.r[9]);
      size = sizeof (regs.r[9]);
      break;
      break;
    case sim_rx_r10_regnum:
    case sim_rx_r10_regnum:
      size = sizeof (regs.r[10]);
      size = sizeof (regs.r[10]);
      break;
      break;
    case sim_rx_r11_regnum:
    case sim_rx_r11_regnum:
      size = sizeof (regs.r[11]);
      size = sizeof (regs.r[11]);
      break;
      break;
    case sim_rx_r12_regnum:
    case sim_rx_r12_regnum:
      size = sizeof (regs.r[12]);
      size = sizeof (regs.r[12]);
      break;
      break;
    case sim_rx_r13_regnum:
    case sim_rx_r13_regnum:
      size = sizeof (regs.r[13]);
      size = sizeof (regs.r[13]);
      break;
      break;
    case sim_rx_r14_regnum:
    case sim_rx_r14_regnum:
      size = sizeof (regs.r[14]);
      size = sizeof (regs.r[14]);
      break;
      break;
    case sim_rx_r15_regnum:
    case sim_rx_r15_regnum:
      size = sizeof (regs.r[15]);
      size = sizeof (regs.r[15]);
      break;
      break;
    case sim_rx_isp_regnum:
    case sim_rx_isp_regnum:
      size = sizeof (regs.r_isp);
      size = sizeof (regs.r_isp);
      break;
      break;
    case sim_rx_usp_regnum:
    case sim_rx_usp_regnum:
      size = sizeof (regs.r_usp);
      size = sizeof (regs.r_usp);
      break;
      break;
    case sim_rx_intb_regnum:
    case sim_rx_intb_regnum:
      size = sizeof (regs.r_intb);
      size = sizeof (regs.r_intb);
      break;
      break;
    case sim_rx_pc_regnum:
    case sim_rx_pc_regnum:
      size = sizeof (regs.r_pc);
      size = sizeof (regs.r_pc);
      break;
      break;
    case sim_rx_ps_regnum:
    case sim_rx_ps_regnum:
      size = sizeof (regs.r_psw);
      size = sizeof (regs.r_psw);
      break;
      break;
    case sim_rx_bpc_regnum:
    case sim_rx_bpc_regnum:
      size = sizeof (regs.r_bpc);
      size = sizeof (regs.r_bpc);
      break;
      break;
    case sim_rx_bpsw_regnum:
    case sim_rx_bpsw_regnum:
      size = sizeof (regs.r_bpsw);
      size = sizeof (regs.r_bpsw);
      break;
      break;
    case sim_rx_fintv_regnum:
    case sim_rx_fintv_regnum:
      size = sizeof (regs.r_fintv);
      size = sizeof (regs.r_fintv);
      break;
      break;
    case sim_rx_fpsw_regnum:
    case sim_rx_fpsw_regnum:
      size = sizeof (regs.r_fpsw);
      size = sizeof (regs.r_fpsw);
      break;
      break;
    default:
    default:
      size = 0;
      size = 0;
      break;
      break;
    }
    }
  return size;
  return size;
}
}
 
 
int
int
sim_fetch_register (SIM_DESC sd, int regno, unsigned char *buf, int length)
sim_fetch_register (SIM_DESC sd, int regno, unsigned char *buf, int length)
{
{
  size_t size;
  size_t size;
  DI val;
  DI val;
 
 
  check_desc (sd);
  check_desc (sd);
 
 
  if (!check_regno (regno))
  if (!check_regno (regno))
    return 0;
    return 0;
 
 
  size = reg_size (regno);
  size = reg_size (regno);
 
 
  if (length != size)
  if (length != size)
    return 0;
    return 0;
 
 
  switch (regno)
  switch (regno)
    {
    {
    case sim_rx_r0_regnum:
    case sim_rx_r0_regnum:
      val = get_reg (0);
      val = get_reg (0);
      break;
      break;
    case sim_rx_r1_regnum:
    case sim_rx_r1_regnum:
      val = get_reg (1);
      val = get_reg (1);
      break;
      break;
    case sim_rx_r2_regnum:
    case sim_rx_r2_regnum:
      val = get_reg (2);
      val = get_reg (2);
      break;
      break;
    case sim_rx_r3_regnum:
    case sim_rx_r3_regnum:
      val = get_reg (3);
      val = get_reg (3);
      break;
      break;
    case sim_rx_r4_regnum:
    case sim_rx_r4_regnum:
      val = get_reg (4);
      val = get_reg (4);
      break;
      break;
    case sim_rx_r5_regnum:
    case sim_rx_r5_regnum:
      val = get_reg (5);
      val = get_reg (5);
      break;
      break;
    case sim_rx_r6_regnum:
    case sim_rx_r6_regnum:
      val = get_reg (6);
      val = get_reg (6);
      break;
      break;
    case sim_rx_r7_regnum:
    case sim_rx_r7_regnum:
      val = get_reg (7);
      val = get_reg (7);
      break;
      break;
    case sim_rx_r8_regnum:
    case sim_rx_r8_regnum:
      val = get_reg (8);
      val = get_reg (8);
      break;
      break;
    case sim_rx_r9_regnum:
    case sim_rx_r9_regnum:
      val = get_reg (9);
      val = get_reg (9);
      break;
      break;
    case sim_rx_r10_regnum:
    case sim_rx_r10_regnum:
      val = get_reg (10);
      val = get_reg (10);
      break;
      break;
    case sim_rx_r11_regnum:
    case sim_rx_r11_regnum:
      val = get_reg (11);
      val = get_reg (11);
      break;
      break;
    case sim_rx_r12_regnum:
    case sim_rx_r12_regnum:
      val = get_reg (12);
      val = get_reg (12);
      break;
      break;
    case sim_rx_r13_regnum:
    case sim_rx_r13_regnum:
      val = get_reg (13);
      val = get_reg (13);
      break;
      break;
    case sim_rx_r14_regnum:
    case sim_rx_r14_regnum:
      val = get_reg (14);
      val = get_reg (14);
      break;
      break;
    case sim_rx_r15_regnum:
    case sim_rx_r15_regnum:
      val = get_reg (15);
      val = get_reg (15);
      break;
      break;
    case sim_rx_isp_regnum:
    case sim_rx_isp_regnum:
      val = get_reg (isp);
      val = get_reg (isp);
      break;
      break;
    case sim_rx_usp_regnum:
    case sim_rx_usp_regnum:
      val = get_reg (usp);
      val = get_reg (usp);
      break;
      break;
    case sim_rx_intb_regnum:
    case sim_rx_intb_regnum:
      val = get_reg (intb);
      val = get_reg (intb);
      break;
      break;
    case sim_rx_pc_regnum:
    case sim_rx_pc_regnum:
      val = get_reg (pc);
      val = get_reg (pc);
      break;
      break;
    case sim_rx_ps_regnum:
    case sim_rx_ps_regnum:
      val = get_reg (psw);
      val = get_reg (psw);
      break;
      break;
    case sim_rx_bpc_regnum:
    case sim_rx_bpc_regnum:
      val = get_reg (bpc);
      val = get_reg (bpc);
      break;
      break;
    case sim_rx_bpsw_regnum:
    case sim_rx_bpsw_regnum:
      val = get_reg (bpsw);
      val = get_reg (bpsw);
      break;
      break;
    case sim_rx_fintv_regnum:
    case sim_rx_fintv_regnum:
      val = get_reg (fintv);
      val = get_reg (fintv);
      break;
      break;
    case sim_rx_fpsw_regnum:
    case sim_rx_fpsw_regnum:
      val = get_reg (fpsw);
      val = get_reg (fpsw);
      break;
      break;
    default:
    default:
      fprintf (stderr, "rx minisim: unrecognized register number: %d\n",
      fprintf (stderr, "rx minisim: unrecognized register number: %d\n",
               regno);
               regno);
      return -1;
      return -1;
    }
    }
 
 
  if (rx_big_endian)
  if (rx_big_endian)
    put_be (buf, length, val);
    put_be (buf, length, val);
  else
  else
    put_le (buf, length, val);
    put_le (buf, length, val);
 
 
  return size;
  return size;
}
}
 
 
int
int
sim_store_register (SIM_DESC sd, int regno, unsigned char *buf, int length)
sim_store_register (SIM_DESC sd, int regno, unsigned char *buf, int length)
{
{
  size_t size;
  size_t size;
  DI val;
  DI val;
 
 
  check_desc (sd);
  check_desc (sd);
 
 
  if (!check_regno (regno))
  if (!check_regno (regno))
    return 0;
    return 0;
 
 
  size = reg_size (regno);
  size = reg_size (regno);
 
 
  if (length != size)
  if (length != size)
    return 0;
    return 0;
 
 
  if (rx_big_endian)
  if (rx_big_endian)
    val = get_be (buf, length);
    val = get_be (buf, length);
  else
  else
    val = get_le (buf, length);
    val = get_le (buf, length);
 
 
  switch (regno)
  switch (regno)
    {
    {
    case sim_rx_r0_regnum:
    case sim_rx_r0_regnum:
      put_reg (0, val);
      put_reg (0, val);
      break;
      break;
    case sim_rx_r1_regnum:
    case sim_rx_r1_regnum:
      put_reg (1, val);
      put_reg (1, val);
      break;
      break;
    case sim_rx_r2_regnum:
    case sim_rx_r2_regnum:
      put_reg (2, val);
      put_reg (2, val);
      break;
      break;
    case sim_rx_r3_regnum:
    case sim_rx_r3_regnum:
      put_reg (3, val);
      put_reg (3, val);
      break;
      break;
    case sim_rx_r4_regnum:
    case sim_rx_r4_regnum:
      put_reg (4, val);
      put_reg (4, val);
      break;
      break;
    case sim_rx_r5_regnum:
    case sim_rx_r5_regnum:
      put_reg (5, val);
      put_reg (5, val);
      break;
      break;
    case sim_rx_r6_regnum:
    case sim_rx_r6_regnum:
      put_reg (6, val);
      put_reg (6, val);
      break;
      break;
    case sim_rx_r7_regnum:
    case sim_rx_r7_regnum:
      put_reg (7, val);
      put_reg (7, val);
      break;
      break;
    case sim_rx_r8_regnum:
    case sim_rx_r8_regnum:
      put_reg (8, val);
      put_reg (8, val);
      break;
      break;
    case sim_rx_r9_regnum:
    case sim_rx_r9_regnum:
      put_reg (9, val);
      put_reg (9, val);
      break;
      break;
    case sim_rx_r10_regnum:
    case sim_rx_r10_regnum:
      put_reg (10, val);
      put_reg (10, val);
      break;
      break;
    case sim_rx_r11_regnum:
    case sim_rx_r11_regnum:
      put_reg (11, val);
      put_reg (11, val);
      break;
      break;
    case sim_rx_r12_regnum:
    case sim_rx_r12_regnum:
      put_reg (12, val);
      put_reg (12, val);
      break;
      break;
    case sim_rx_r13_regnum:
    case sim_rx_r13_regnum:
      put_reg (13, val);
      put_reg (13, val);
      break;
      break;
    case sim_rx_r14_regnum:
    case sim_rx_r14_regnum:
      put_reg (14, val);
      put_reg (14, val);
      break;
      break;
    case sim_rx_r15_regnum:
    case sim_rx_r15_regnum:
      put_reg (15, val);
      put_reg (15, val);
      break;
      break;
    case sim_rx_isp_regnum:
    case sim_rx_isp_regnum:
      put_reg (isp, val);
      put_reg (isp, val);
      break;
      break;
    case sim_rx_usp_regnum:
    case sim_rx_usp_regnum:
      put_reg (usp, val);
      put_reg (usp, val);
      break;
      break;
    case sim_rx_intb_regnum:
    case sim_rx_intb_regnum:
      put_reg (intb, val);
      put_reg (intb, val);
      break;
      break;
    case sim_rx_pc_regnum:
    case sim_rx_pc_regnum:
      put_reg (pc, val);
      put_reg (pc, val);
      break;
      break;
    case sim_rx_ps_regnum:
    case sim_rx_ps_regnum:
      put_reg (psw, val);
      put_reg (psw, val);
      break;
      break;
    case sim_rx_bpc_regnum:
    case sim_rx_bpc_regnum:
      put_reg (bpc, val);
      put_reg (bpc, val);
      break;
      break;
    case sim_rx_bpsw_regnum:
    case sim_rx_bpsw_regnum:
      put_reg (bpsw, val);
      put_reg (bpsw, val);
      break;
      break;
    case sim_rx_fintv_regnum:
    case sim_rx_fintv_regnum:
      put_reg (fintv, val);
      put_reg (fintv, val);
      break;
      break;
    case sim_rx_fpsw_regnum:
    case sim_rx_fpsw_regnum:
      put_reg (fpsw, val);
      put_reg (fpsw, val);
      break;
      break;
    default:
    default:
      fprintf (stderr, "rx minisim: unrecognized register number: %d\n",
      fprintf (stderr, "rx minisim: unrecognized register number: %d\n",
               regno);
               regno);
      return -1;
      return -1;
    }
    }
 
 
  return size;
  return size;
}
}
 
 
void
void
sim_info (SIM_DESC sd, int verbose)
sim_info (SIM_DESC sd, int verbose)
{
{
  check_desc (sd);
  check_desc (sd);
 
 
  printf ("The rx minisim doesn't collect any statistics.\n");
  printf ("The rx minisim doesn't collect any statistics.\n");
}
}
 
 
static volatile int stop;
static volatile int stop;
static enum sim_stop reason;
static enum sim_stop reason;
int siggnal;
int siggnal;
 
 
 
 
/* Given a signal number used by the RX bsp (that is, newlib),
/* Given a signal number used by the RX bsp (that is, newlib),
   return a host signal number.  (Oddly, the gdb/sim interface uses
   return a host signal number.  (Oddly, the gdb/sim interface uses
   host signal numbers...)  */
   host signal numbers...)  */
int
int
rx_signal_to_host (int rx)
rx_signal_to_host (int rx)
{
{
  switch (rx)
  switch (rx)
    {
    {
    case 4:
    case 4:
#ifdef SIGILL
#ifdef SIGILL
      return SIGILL;
      return SIGILL;
#else
#else
      return SIGSEGV;
      return SIGSEGV;
#endif
#endif
 
 
    case 5:
    case 5:
      return SIGTRAP;
      return SIGTRAP;
 
 
    case 10:
    case 10:
#ifdef SIGBUS
#ifdef SIGBUS
      return SIGBUS;
      return SIGBUS;
#else
#else
      return SIGSEGV;
      return SIGSEGV;
#endif
#endif
 
 
    case 11:
    case 11:
      return SIGSEGV;
      return SIGSEGV;
 
 
    case 24:
    case 24:
#ifdef SIGXCPU
#ifdef SIGXCPU
      return SIGXCPU;
      return SIGXCPU;
#else
#else
      break;
      break;
#endif
#endif
 
 
    case 2:
    case 2:
      return SIGINT;
      return SIGINT;
 
 
    case 8:
    case 8:
#ifdef SIGFPE
#ifdef SIGFPE
      return SIGFPE;
      return SIGFPE;
#else
#else
      break;
      break;
#endif
#endif
 
 
    case 6:
    case 6:
      return SIGABRT;
      return SIGABRT;
    }
    }
 
 
  return 0;
  return 0;
}
}
 
 
 
 
/* Take a step return code RC and set up the variables consulted by
/* Take a step return code RC and set up the variables consulted by
   sim_stop_reason appropriately.  */
   sim_stop_reason appropriately.  */
void
void
handle_step (int rc)
handle_step (int rc)
{
{
  if (execution_error_get_last_error () != SIM_ERR_NONE)
  if (execution_error_get_last_error () != SIM_ERR_NONE)
    {
    {
      reason = sim_stopped;
      reason = sim_stopped;
      siggnal = TARGET_SIGNAL_SEGV;
      siggnal = TARGET_SIGNAL_SEGV;
    }
    }
  if (RX_STEPPED (rc) || RX_HIT_BREAK (rc))
  if (RX_STEPPED (rc) || RX_HIT_BREAK (rc))
    {
    {
      reason = sim_stopped;
      reason = sim_stopped;
      siggnal = TARGET_SIGNAL_TRAP;
      siggnal = TARGET_SIGNAL_TRAP;
    }
    }
  else if (RX_STOPPED (rc))
  else if (RX_STOPPED (rc))
    {
    {
      reason = sim_stopped;
      reason = sim_stopped;
      siggnal = rx_signal_to_host (RX_STOP_SIG (rc));
      siggnal = rx_signal_to_host (RX_STOP_SIG (rc));
    }
    }
  else
  else
    {
    {
      assert (RX_EXITED (rc));
      assert (RX_EXITED (rc));
      reason = sim_exited;
      reason = sim_exited;
      siggnal = RX_EXIT_STATUS (rc);
      siggnal = RX_EXIT_STATUS (rc);
    }
    }
}
}
 
 
 
 
void
void
sim_resume (SIM_DESC sd, int step, int sig_to_deliver)
sim_resume (SIM_DESC sd, int step, int sig_to_deliver)
{
{
  check_desc (sd);
  check_desc (sd);
 
 
  if (sig_to_deliver != 0)
  if (sig_to_deliver != 0)
    {
    {
      fprintf (stderr,
      fprintf (stderr,
               "Warning: the rx minisim does not implement "
               "Warning: the rx minisim does not implement "
               "signal delivery yet.\n" "Resuming with no signal.\n");
               "signal delivery yet.\n" "Resuming with no signal.\n");
    }
    }
 
 
  execution_error_clear_last_error ();
  execution_error_clear_last_error ();
 
 
  if (step)
  if (step)
    handle_step (decode_opcode ());
    handle_step (decode_opcode ());
  else
  else
    {
    {
      /* We don't clear 'stop' here, because then we would miss
      /* We don't clear 'stop' here, because then we would miss
         interrupts that arrived on the way here.  Instead, we clear
         interrupts that arrived on the way here.  Instead, we clear
         the flag in sim_stop_reason, after GDB has disabled the
         the flag in sim_stop_reason, after GDB has disabled the
         interrupt signal handler.  */
         interrupt signal handler.  */
      for (;;)
      for (;;)
        {
        {
          if (stop)
          if (stop)
            {
            {
              stop = 0;
              stop = 0;
              reason = sim_stopped;
              reason = sim_stopped;
              siggnal = TARGET_SIGNAL_INT;
              siggnal = TARGET_SIGNAL_INT;
              break;
              break;
            }
            }
 
 
          int rc = decode_opcode ();
          int rc = decode_opcode ();
 
 
          if (execution_error_get_last_error () != SIM_ERR_NONE)
          if (execution_error_get_last_error () != SIM_ERR_NONE)
            {
            {
              reason = sim_stopped;
              reason = sim_stopped;
              siggnal = TARGET_SIGNAL_SEGV;
              siggnal = TARGET_SIGNAL_SEGV;
              break;
              break;
            }
            }
 
 
          if (!RX_STEPPED (rc))
          if (!RX_STEPPED (rc))
            {
            {
              handle_step (rc);
              handle_step (rc);
              break;
              break;
            }
            }
        }
        }
    }
    }
}
}
 
 
int
int
sim_stop (SIM_DESC sd)
sim_stop (SIM_DESC sd)
{
{
  stop = 1;
  stop = 1;
 
 
  return 1;
  return 1;
}
}
 
 
void
void
sim_stop_reason (SIM_DESC sd, enum sim_stop *reason_p, int *sigrc_p)
sim_stop_reason (SIM_DESC sd, enum sim_stop *reason_p, int *sigrc_p)
{
{
  check_desc (sd);
  check_desc (sd);
 
 
  *reason_p = reason;
  *reason_p = reason;
  *sigrc_p = siggnal;
  *sigrc_p = siggnal;
}
}
 
 
void
void
sim_do_command (SIM_DESC sd, char *cmd)
sim_do_command (SIM_DESC sd, char *cmd)
{
{
  check_desc (sd);
  check_desc (sd);
 
 
  char *p = cmd;
  char *p = cmd;
 
 
  /* Skip leading whitespace.  */
  /* Skip leading whitespace.  */
  while (isspace (*p))
  while (isspace (*p))
    p++;
    p++;
 
 
  /* Find the extent of the command word.  */
  /* Find the extent of the command word.  */
  for (p = cmd; *p; p++)
  for (p = cmd; *p; p++)
    if (isspace (*p))
    if (isspace (*p))
      break;
      break;
 
 
  /* Null-terminate the command word, and record the start of any
  /* Null-terminate the command word, and record the start of any
     further arguments.  */
     further arguments.  */
  char *args;
  char *args;
  if (*p)
  if (*p)
    {
    {
      *p = '\0';
      *p = '\0';
      args = p + 1;
      args = p + 1;
      while (isspace (*args))
      while (isspace (*args))
        args++;
        args++;
    }
    }
  else
  else
    args = p;
    args = p;
 
 
  if (strcmp (cmd, "trace") == 0)
  if (strcmp (cmd, "trace") == 0)
    {
    {
      if (strcmp (args, "on") == 0)
      if (strcmp (args, "on") == 0)
        trace = 1;
        trace = 1;
      else if (strcmp (args, "off") == 0)
      else if (strcmp (args, "off") == 0)
        trace = 0;
        trace = 0;
      else
      else
        printf ("The 'sim trace' command expects 'on' or 'off' "
        printf ("The 'sim trace' command expects 'on' or 'off' "
                "as an argument.\n");
                "as an argument.\n");
    }
    }
  else if (strcmp (cmd, "verbose") == 0)
  else if (strcmp (cmd, "verbose") == 0)
    {
    {
      if (strcmp (args, "on") == 0)
      if (strcmp (args, "on") == 0)
        verbose = 1;
        verbose = 1;
      else if (strcmp (args, "off") == 0)
      else if (strcmp (args, "off") == 0)
        verbose = 0;
        verbose = 0;
      else
      else
        printf ("The 'sim verbose' command expects 'on' or 'off'"
        printf ("The 'sim verbose' command expects 'on' or 'off'"
                " as an argument.\n");
                " as an argument.\n");
    }
    }
  else
  else
    printf ("The 'sim' command expects either 'trace' or 'verbose'"
    printf ("The 'sim' command expects either 'trace' or 'verbose'"
            " as a subcommand.\n");
            " as a subcommand.\n");
}
}
 
 

powered by: WebSVN 2.1.0

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