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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [gdb-5.0/] [sim/] [z8k/] [iface.c] - Diff between revs 107 and 1765

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

Rev 107 Rev 1765
/* gdb->simulator interface.
/* gdb->simulator interface.
   Copyright (C) 1992, 1993, 1994, 1997 Free Software Foundation, Inc.
   Copyright (C) 1992, 1993, 1994, 1997 Free Software Foundation, Inc.
 
 
This file is part of Z8KSIM
This file is part of Z8KSIM
 
 
Z8KSIM is free software; you can redistribute it and/or modify
Z8KSIM 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 2, or (at your option)
the Free Software Foundation; either version 2, or (at your option)
any later version.
any later version.
 
 
Z8KSIM is distributed in the hope that it will be useful,
Z8KSIM 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 Z8KZIM; if not, write to the Free Software
along with Z8KZIM; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 
 
#include "ansidecl.h"
#include "ansidecl.h"
#include "sim.h"
#include "sim.h"
#include "tm.h"
#include "tm.h"
#include "signal.h"
#include "signal.h"
#include "bfd.h"
#include "bfd.h"
#include "callback.h"
#include "callback.h"
#include "remote-sim.h"
#include "remote-sim.h"
 
 
#ifndef NULL
#ifndef NULL
#define NULL 0
#define NULL 0
#endif
#endif
 
 
host_callback *z8k_callback;
host_callback *z8k_callback;
 
 
static SIM_OPEN_KIND sim_kind;
static SIM_OPEN_KIND sim_kind;
static char *myname;
static char *myname;
 
 
void
void
sim_size (n)
sim_size (n)
     int n;
     int n;
{
{
  /* Size is fixed.  */
  /* Size is fixed.  */
}
}
 
 
int
int
sim_store_register (sd, regno, value, length)
sim_store_register (sd, regno, value, length)
     SIM_DESC sd;
     SIM_DESC sd;
     int regno;
     int regno;
     unsigned char *value;
     unsigned char *value;
     int length;
     int length;
{
{
  /* FIXME: Review the computation of regval.  */
  /* FIXME: Review the computation of regval.  */
  int regval = (value[0] << 24) | (value[1] << 16) | (value[2] << 8) | value[3];
  int regval = (value[0] << 24) | (value[1] << 16) | (value[2] << 8) | value[3];
 
 
  tm_store_register (regno, regval);
  tm_store_register (regno, regval);
  return -1;
  return -1;
}
}
 
 
int
int
sim_fetch_register (sd, regno, buf, length)
sim_fetch_register (sd, regno, buf, length)
     SIM_DESC sd;
     SIM_DESC sd;
     int regno;
     int regno;
     unsigned char *buf;
     unsigned char *buf;
     int length;
     int length;
{
{
  tm_fetch_register (regno, buf);
  tm_fetch_register (regno, buf);
  return -1;
  return -1;
}
}
 
 
int
int
sim_write (sd, where, what, howmuch)
sim_write (sd, where, what, howmuch)
     SIM_DESC sd;
     SIM_DESC sd;
     SIM_ADDR where;
     SIM_ADDR where;
     unsigned char *what;
     unsigned char *what;
     int howmuch;
     int howmuch;
{
{
  int i;
  int i;
 
 
  for (i = 0; i < howmuch; i++)
  for (i = 0; i < howmuch; i++)
    tm_write_byte (where + i, what[i]);
    tm_write_byte (where + i, what[i]);
  return howmuch;
  return howmuch;
}
}
 
 
int
int
sim_read (sd, where, what, howmuch)
sim_read (sd, where, what, howmuch)
     SIM_DESC sd;
     SIM_DESC sd;
     SIM_ADDR where;
     SIM_ADDR where;
     unsigned char *what;
     unsigned char *what;
     int howmuch;
     int howmuch;
{
{
  int i;
  int i;
 
 
  for (i = 0; i < howmuch; i++)
  for (i = 0; i < howmuch; i++)
    what[i] = tm_read_byte (where + i);
    what[i] = tm_read_byte (where + i);
  return howmuch;
  return howmuch;
}
}
 
 
static void
static void
control_c (sig, code, scp, addr)
control_c (sig, code, scp, addr)
     int sig;
     int sig;
     int code;
     int code;
     char *scp;
     char *scp;
     char *addr;
     char *addr;
{
{
  tm_exception (SIM_INTERRUPT);
  tm_exception (SIM_INTERRUPT);
}
}
 
 
int
int
sim_stop (sd)
sim_stop (sd)
     SIM_DESC sd;
     SIM_DESC sd;
{
{
  tm_exception (SIM_INTERRUPT);
  tm_exception (SIM_INTERRUPT);
  return 1;
  return 1;
}
}
 
 
void
void
sim_resume (sd, step, sig)
sim_resume (sd, step, sig)
     SIM_DESC sd;
     SIM_DESC sd;
     int step;
     int step;
     int sig;
     int sig;
{
{
  void (*prev) ();
  void (*prev) ();
 
 
  prev = signal (SIGINT, control_c);
  prev = signal (SIGINT, control_c);
  tm_resume (step);
  tm_resume (step);
  signal (SIGINT, prev);
  signal (SIGINT, prev);
}
}
 
 
void
void
sim_stop_reason (sd, reason, sigrc)
sim_stop_reason (sd, reason, sigrc)
     SIM_DESC sd;
     SIM_DESC sd;
     enum sim_stop *reason;
     enum sim_stop *reason;
     int *sigrc;
     int *sigrc;
{
{
  switch (tm_signal ())
  switch (tm_signal ())
    {
    {
    case SIM_DIV_ZERO:
    case SIM_DIV_ZERO:
      *sigrc = SIGFPE;
      *sigrc = SIGFPE;
      break;
      break;
    case SIM_INTERRUPT:
    case SIM_INTERRUPT:
      *sigrc = SIGINT;
      *sigrc = SIGINT;
      break;
      break;
    case SIM_BAD_INST:
    case SIM_BAD_INST:
      *sigrc = SIGILL;
      *sigrc = SIGILL;
      break;
      break;
    case SIM_BREAKPOINT:
    case SIM_BREAKPOINT:
      *sigrc = SIGTRAP;
      *sigrc = SIGTRAP;
      break;
      break;
    case SIM_SINGLE_STEP:
    case SIM_SINGLE_STEP:
      *sigrc = SIGTRAP;
      *sigrc = SIGTRAP;
      break;
      break;
    case SIM_BAD_SYSCALL:
    case SIM_BAD_SYSCALL:
      *sigrc = SIGILL;
      *sigrc = SIGILL;
      break;
      break;
    case SIM_BAD_ALIGN:
    case SIM_BAD_ALIGN:
      *sigrc = SIGSEGV;
      *sigrc = SIGSEGV;
      break;
      break;
    case SIM_DONE:
    case SIM_DONE:
      {
      {
        sim_state_type x;
        sim_state_type x;
        tm_state (&x);
        tm_state (&x);
        *sigrc = x.regs[2].word & 255;
        *sigrc = x.regs[2].word & 255;
        *reason = sim_exited;
        *reason = sim_exited;
        return;
        return;
      }
      }
    default:
    default:
      abort ();
      abort ();
    }
    }
  *reason = sim_stopped;
  *reason = sim_stopped;
}
}
 
 
void
void
sim_info (sd, verbose)
sim_info (sd, verbose)
     SIM_DESC sd;
     SIM_DESC sd;
     int verbose;
     int verbose;
{
{
  sim_state_type x;
  sim_state_type x;
 
 
  tm_state (&x);
  tm_state (&x);
  tm_info_print (&x);
  tm_info_print (&x);
}
}
 
 
SIM_DESC
SIM_DESC
sim_open (kind, cb, abfd, argv)
sim_open (kind, cb, abfd, argv)
     SIM_OPEN_KIND kind;
     SIM_OPEN_KIND kind;
     host_callback *cb;
     host_callback *cb;
     struct _bfd *abfd;
     struct _bfd *abfd;
     char **argv;
     char **argv;
{
{
  /* FIXME: The code in sim_load that determines the exact z8k arch
  /* FIXME: The code in sim_load that determines the exact z8k arch
     should be moved to here */
     should be moved to here */
 
 
  sim_kind = kind;
  sim_kind = kind;
  myname = argv[0];
  myname = argv[0];
  z8k_callback = cb;
  z8k_callback = cb;
 
 
  /* fudge our descriptor for now */
  /* fudge our descriptor for now */
  return (SIM_DESC) 1;
  return (SIM_DESC) 1;
}
}
 
 
void
void
sim_close (sd, quitting)
sim_close (sd, quitting)
     SIM_DESC sd;
     SIM_DESC sd;
     int quitting;
     int quitting;
{
{
  /* nothing to do */
  /* nothing to do */
}
}
 
 
SIM_RC
SIM_RC
sim_load (sd, prog, abfd, from_tty)
sim_load (sd, prog, abfd, from_tty)
     SIM_DESC sd;
     SIM_DESC sd;
     char *prog;
     char *prog;
     bfd *abfd;
     bfd *abfd;
     int from_tty;
     int from_tty;
{
{
  extern bfd *sim_load_file (); /* ??? Don't know where this should live.  */
  extern bfd *sim_load_file (); /* ??? Don't know where this should live.  */
  bfd *prog_bfd;
  bfd *prog_bfd;
 
 
  /* FIXME: The code determining the type of z9k processor should be
  /* FIXME: The code determining the type of z9k processor should be
     moved from here to sim_open. */
     moved from here to sim_open. */
 
 
  prog_bfd = sim_load_file (sd, myname, z8k_callback, prog, abfd,
  prog_bfd = sim_load_file (sd, myname, z8k_callback, prog, abfd,
                            sim_kind == SIM_OPEN_DEBUG,
                            sim_kind == SIM_OPEN_DEBUG,
                            0, sim_write);
                            0, sim_write);
  if (prog_bfd == NULL)
  if (prog_bfd == NULL)
    return SIM_RC_FAIL;
    return SIM_RC_FAIL;
  if (bfd_get_mach (prog_bfd) == bfd_mach_z8001)
  if (bfd_get_mach (prog_bfd) == bfd_mach_z8001)
    {
    {
      extern int sim_z8001_mode;
      extern int sim_z8001_mode;
      sim_z8001_mode = 1;
      sim_z8001_mode = 1;
    }
    }
  /* Close the bfd if we opened it.  */
  /* Close the bfd if we opened it.  */
  if (abfd == NULL)
  if (abfd == NULL)
    bfd_close (prog_bfd);
    bfd_close (prog_bfd);
  return SIM_RC_OK;
  return SIM_RC_OK;
}
}
 
 
SIM_RC
SIM_RC
sim_create_inferior (sd, abfd, argv, env)
sim_create_inferior (sd, abfd, argv, env)
     SIM_DESC sd;
     SIM_DESC sd;
     struct _bfd *abfd;
     struct _bfd *abfd;
     char **argv;
     char **argv;
     char **env;
     char **env;
{
{
  if (abfd != NULL)
  if (abfd != NULL)
    tm_store_register (REG_PC, bfd_get_start_address (abfd));
    tm_store_register (REG_PC, bfd_get_start_address (abfd));
  else
  else
    tm_store_register (REG_PC, 0);
    tm_store_register (REG_PC, 0);
  return SIM_RC_OK;
  return SIM_RC_OK;
}
}
 
 
void
void
sim_do_command (sd, cmd)
sim_do_command (sd, cmd)
     SIM_DESC sd;
     SIM_DESC sd;
     char *cmd;
     char *cmd;
{
{
}
}
 
 
void
void
sim_set_callbacks (ptr)
sim_set_callbacks (ptr)
     host_callback *ptr;
     host_callback *ptr;
{
{
  z8k_callback = ptr;
  z8k_callback = ptr;
}
}
 
 

powered by: WebSVN 2.1.0

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