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

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [gdb-6.8/] [sim/] [iq2000/] [iq2000.c] - Diff between revs 24 and 157

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

Rev 24 Rev 157
/* IQ2000 simulator support code
/* IQ2000 simulator support code
   Copyright (C) 2000, 2004, 2007, 2008 Free Software Foundation, Inc.
   Copyright (C) 2000, 2004, 2007, 2008 Free Software Foundation, Inc.
   Contributed by Cygnus Support.
   Contributed by Cygnus Support.
 
 
   This file is part of the GNU simulators.
   This file is part of the GNU simulators.
 
 
   This program is free software; you can redistribute it and/or modify
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3 of the License, or
   the Free Software Foundation; either version 3 of the License, or
   (at your option) any later version.
   (at your option) any later version.
 
 
   This program is distributed in the hope that it will be useful,
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
   GNU General Public License for more details.
 
 
   You should have received a copy of the GNU General Public License
   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 
#define WANT_CPU
#define WANT_CPU
#define WANT_CPU_IQ2000BF
#define WANT_CPU_IQ2000BF
 
 
#include "sim-main.h"
#include "sim-main.h"
#include "cgen-mem.h"
#include "cgen-mem.h"
#include "cgen-ops.h"
#include "cgen-ops.h"
 
 
enum
enum
{
{
  GPR0_REGNUM = 0,
  GPR0_REGNUM = 0,
  NR_GPR = 32,
  NR_GPR = 32,
  PC_REGNUM = 32
  PC_REGNUM = 32
};
};
 
 
enum libgloss_syscall
enum libgloss_syscall
{
{
  SYS_exit = 1,
  SYS_exit = 1,
  SYS_open = 2,
  SYS_open = 2,
  SYS_close = 3,
  SYS_close = 3,
  SYS_read = 4,
  SYS_read = 4,
  SYS_write = 5,
  SYS_write = 5,
  SYS_lseek = 6,
  SYS_lseek = 6,
  SYS_unlink = 7,
  SYS_unlink = 7,
  SYS_getpid = 8,
  SYS_getpid = 8,
  SYS_kill = 9,
  SYS_kill = 9,
  SYS_fstat = 10,
  SYS_fstat = 10,
  SYS_argvlen = 12,
  SYS_argvlen = 12,
  SYS_argv = 13,
  SYS_argv = 13,
  SYS_chdir = 14,
  SYS_chdir = 14,
  SYS_stat = 15,
  SYS_stat = 15,
  SYS_chmod = 16,
  SYS_chmod = 16,
  SYS_utime = 17,
  SYS_utime = 17,
  SYS_time = 18,
  SYS_time = 18,
  SYS_gettimeofday = 19,
  SYS_gettimeofday = 19,
  SYS_times = 20
  SYS_times = 20
};
};
 
 
/* Read a null terminated string from memory, return in a buffer */
/* Read a null terminated string from memory, return in a buffer */
static char *
static char *
fetch_str (current_cpu, pc, addr)
fetch_str (current_cpu, pc, addr)
     SIM_CPU *current_cpu;
     SIM_CPU *current_cpu;
     PCADDR pc;
     PCADDR pc;
     DI addr;
     DI addr;
{
{
  char *buf;
  char *buf;
  int nr = 0;
  int nr = 0;
  while (sim_core_read_1 (current_cpu,
  while (sim_core_read_1 (current_cpu,
                          pc, read_map, CPU2DATA(addr + nr)) != 0)
                          pc, read_map, CPU2DATA(addr + nr)) != 0)
    nr++;
    nr++;
  buf = NZALLOC (char, nr + 1);
  buf = NZALLOC (char, nr + 1);
  sim_read (CPU_STATE (current_cpu), CPU2DATA(addr), buf, nr);
  sim_read (CPU_STATE (current_cpu), CPU2DATA(addr), buf, nr);
  return buf;
  return buf;
}
}
 
 
void
void
do_syscall (SIM_CPU *current_cpu, PCADDR pc)
do_syscall (SIM_CPU *current_cpu, PCADDR pc)
{
{
#if 0
#if 0
  int syscall = H2T_4 (iq2000bf_h_gr_get (current_cpu, 11));
  int syscall = H2T_4 (iq2000bf_h_gr_get (current_cpu, 11));
#endif
#endif
  int syscall_function = iq2000bf_h_gr_get (current_cpu, 4);
  int syscall_function = iq2000bf_h_gr_get (current_cpu, 4);
  int i;
  int i;
  char *buf;
  char *buf;
  int PARM1 = iq2000bf_h_gr_get (current_cpu, 5);
  int PARM1 = iq2000bf_h_gr_get (current_cpu, 5);
  int PARM2 = iq2000bf_h_gr_get (current_cpu, 6);
  int PARM2 = iq2000bf_h_gr_get (current_cpu, 6);
  int PARM3 = iq2000bf_h_gr_get (current_cpu, 7);
  int PARM3 = iq2000bf_h_gr_get (current_cpu, 7);
  const int ret_reg = 2;
  const int ret_reg = 2;
 
 
  switch (syscall_function)
  switch (syscall_function)
    {
    {
    case 0:
    case 0:
      switch (H2T_4 (iq2000bf_h_gr_get (current_cpu, 11)))
      switch (H2T_4 (iq2000bf_h_gr_get (current_cpu, 11)))
        {
        {
        case 0:
        case 0:
          /* Pass.  */
          /* Pass.  */
          puts ("pass");
          puts ("pass");
          exit (0);
          exit (0);
        case 1:
        case 1:
          /* Fail.  */
          /* Fail.  */
          puts ("fail");
          puts ("fail");
          exit (1);
          exit (1);
        }
        }
 
 
    case SYS_write:
    case SYS_write:
      buf = zalloc (PARM3);
      buf = zalloc (PARM3);
      sim_read (CPU_STATE (current_cpu), CPU2DATA(PARM2), buf, PARM3);
      sim_read (CPU_STATE (current_cpu), CPU2DATA(PARM2), buf, PARM3);
      SET_H_GR (ret_reg,
      SET_H_GR (ret_reg,
                sim_io_write (CPU_STATE (current_cpu),
                sim_io_write (CPU_STATE (current_cpu),
                              PARM1, buf, PARM3));
                              PARM1, buf, PARM3));
      zfree (buf);
      zfree (buf);
      break;
      break;
 
 
    case SYS_lseek:
    case SYS_lseek:
      SET_H_GR (ret_reg,
      SET_H_GR (ret_reg,
                sim_io_lseek (CPU_STATE (current_cpu),
                sim_io_lseek (CPU_STATE (current_cpu),
                              PARM1, PARM2, PARM3));
                              PARM1, PARM2, PARM3));
      break;
      break;
 
 
    case SYS_exit:
    case SYS_exit:
      sim_engine_halt (CPU_STATE (current_cpu), current_cpu,
      sim_engine_halt (CPU_STATE (current_cpu), current_cpu,
                       NULL, pc, sim_exited, PARM1);
                       NULL, pc, sim_exited, PARM1);
      break;
      break;
 
 
    case SYS_read:
    case SYS_read:
      buf = zalloc (PARM3);
      buf = zalloc (PARM3);
      SET_H_GR (ret_reg,
      SET_H_GR (ret_reg,
                sim_io_read (CPU_STATE (current_cpu),
                sim_io_read (CPU_STATE (current_cpu),
                             PARM1, buf, PARM3));
                             PARM1, buf, PARM3));
      sim_write (CPU_STATE (current_cpu), CPU2DATA(PARM2), buf, PARM3);
      sim_write (CPU_STATE (current_cpu), CPU2DATA(PARM2), buf, PARM3);
      zfree (buf);
      zfree (buf);
      break;
      break;
 
 
    case SYS_open:
    case SYS_open:
      buf = fetch_str (current_cpu, pc, PARM1);
      buf = fetch_str (current_cpu, pc, PARM1);
      SET_H_GR (ret_reg,
      SET_H_GR (ret_reg,
                sim_io_open (CPU_STATE (current_cpu),
                sim_io_open (CPU_STATE (current_cpu),
                             buf, PARM2));
                             buf, PARM2));
      zfree (buf);
      zfree (buf);
      break;
      break;
 
 
    case SYS_close:
    case SYS_close:
      SET_H_GR (ret_reg,
      SET_H_GR (ret_reg,
                sim_io_close (CPU_STATE (current_cpu), PARM1));
                sim_io_close (CPU_STATE (current_cpu), PARM1));
      break;
      break;
 
 
    case SYS_time:
    case SYS_time:
      SET_H_GR (ret_reg, time (0));
      SET_H_GR (ret_reg, time (0));
      break;
      break;
 
 
    default:
    default:
      SET_H_GR (ret_reg, -1);
      SET_H_GR (ret_reg, -1);
    }
    }
}
}
 
 
void
void
do_break (SIM_CPU *current_cpu, PCADDR pc)
do_break (SIM_CPU *current_cpu, PCADDR pc)
{
{
  SIM_DESC sd = CPU_STATE (current_cpu);
  SIM_DESC sd = CPU_STATE (current_cpu);
  sim_engine_halt (sd, current_cpu, NULL, pc, sim_stopped, SIM_SIGTRAP);
  sim_engine_halt (sd, current_cpu, NULL, pc, sim_stopped, SIM_SIGTRAP);
}
}
 
 
/* The semantic code invokes this for invalid (unrecognized) instructions.  */
/* The semantic code invokes this for invalid (unrecognized) instructions.  */
 
 
SEM_PC
SEM_PC
sim_engine_invalid_insn (SIM_CPU *current_cpu, IADDR cia, SEM_PC vpc)
sim_engine_invalid_insn (SIM_CPU *current_cpu, IADDR cia, SEM_PC vpc)
{
{
  SIM_DESC sd = CPU_STATE (current_cpu);
  SIM_DESC sd = CPU_STATE (current_cpu);
  sim_engine_halt (sd, current_cpu, NULL, cia, sim_stopped, SIM_SIGILL);
  sim_engine_halt (sd, current_cpu, NULL, cia, sim_stopped, SIM_SIGILL);
 
 
  return vpc;
  return vpc;
}
}
 
 
 
 
/* Process an address exception.  */
/* Process an address exception.  */
 
 
void
void
iq2000_core_signal (SIM_DESC sd, SIM_CPU *current_cpu, sim_cia cia,
iq2000_core_signal (SIM_DESC sd, SIM_CPU *current_cpu, sim_cia cia,
                  unsigned int map, int nr_bytes, address_word addr,
                  unsigned int map, int nr_bytes, address_word addr,
                  transfer_type transfer, sim_core_signals sig)
                  transfer_type transfer, sim_core_signals sig)
{
{
  sim_core_signal (sd, current_cpu, cia, map, nr_bytes, addr,
  sim_core_signal (sd, current_cpu, cia, map, nr_bytes, addr,
                   transfer, sig);
                   transfer, sig);
}
}
 
 
 
 
/* Initialize cycle counting for an insn.
/* Initialize cycle counting for an insn.
   FIRST_P is non-zero if this is the first insn in a set of parallel
   FIRST_P is non-zero if this is the first insn in a set of parallel
   insns.  */
   insns.  */
 
 
void
void
iq2000bf_model_insn_before (SIM_CPU *cpu, int first_p)
iq2000bf_model_insn_before (SIM_CPU *cpu, int first_p)
{
{
  /* Do nothing.  */
  /* Do nothing.  */
}
}
 
 
 
 
/* Record the cycles computed for an insn.
/* Record the cycles computed for an insn.
   LAST_P is non-zero if this is the last insn in a set of parallel insns,
   LAST_P is non-zero if this is the last insn in a set of parallel insns,
   and we update the total cycle count.
   and we update the total cycle count.
   CYCLES is the cycle count of the insn.  */
   CYCLES is the cycle count of the insn.  */
 
 
void
void
iq2000bf_model_insn_after(SIM_CPU *cpu, int last_p, int cycles)
iq2000bf_model_insn_after(SIM_CPU *cpu, int last_p, int cycles)
{
{
  /* Do nothing.  */
  /* Do nothing.  */
}
}
 
 
 
 
int
int
iq2000bf_model_iq2000_u_exec (SIM_CPU *cpu, const IDESC *idesc,
iq2000bf_model_iq2000_u_exec (SIM_CPU *cpu, const IDESC *idesc,
                            int unit_num, int referenced)
                            int unit_num, int referenced)
{
{
  return idesc->timing->units[unit_num].done;
  return idesc->timing->units[unit_num].done;
}
}
 
 
PCADDR
PCADDR
get_h_pc (SIM_CPU *cpu)
get_h_pc (SIM_CPU *cpu)
{
{
  return CPU_CGEN_HW(cpu)->h_pc;
  return CPU_CGEN_HW(cpu)->h_pc;
}
}
 
 
void
void
set_h_pc (SIM_CPU *cpu, PCADDR addr)
set_h_pc (SIM_CPU *cpu, PCADDR addr)
{
{
  CPU_CGEN_HW(cpu)->h_pc = addr | IQ2000_INSN_MASK;
  CPU_CGEN_HW(cpu)->h_pc = addr | IQ2000_INSN_MASK;
}
}
 
 
int
int
iq2000bf_fetch_register (SIM_CPU *cpu, int nr, unsigned char *buf, int len)
iq2000bf_fetch_register (SIM_CPU *cpu, int nr, unsigned char *buf, int len)
{
{
  if (nr >= GPR0_REGNUM
  if (nr >= GPR0_REGNUM
      && nr < (GPR0_REGNUM + NR_GPR)
      && nr < (GPR0_REGNUM + NR_GPR)
      && len == 4)
      && len == 4)
    {
    {
      *((unsigned32*)buf) =
      *((unsigned32*)buf) =
        H2T_4 (iq2000bf_h_gr_get (cpu, nr - GPR0_REGNUM));
        H2T_4 (iq2000bf_h_gr_get (cpu, nr - GPR0_REGNUM));
      return 4;
      return 4;
    }
    }
  else if (nr == PC_REGNUM
  else if (nr == PC_REGNUM
           && len == 4)
           && len == 4)
    {
    {
      *((unsigned32*)buf) = H2T_4 (get_h_pc (cpu));
      *((unsigned32*)buf) = H2T_4 (get_h_pc (cpu));
      return 4;
      return 4;
    }
    }
  else
  else
    return 0;
    return 0;
}
}
 
 
int
int
iq2000bf_store_register (SIM_CPU *cpu, int nr, unsigned char *buf, int len)
iq2000bf_store_register (SIM_CPU *cpu, int nr, unsigned char *buf, int len)
{
{
  if (nr >= GPR0_REGNUM
  if (nr >= GPR0_REGNUM
      && nr < (GPR0_REGNUM + NR_GPR)
      && nr < (GPR0_REGNUM + NR_GPR)
      && len == 4)
      && len == 4)
    {
    {
      iq2000bf_h_gr_set (cpu, nr - GPR0_REGNUM, T2H_4 (*((unsigned32*)buf)));
      iq2000bf_h_gr_set (cpu, nr - GPR0_REGNUM, T2H_4 (*((unsigned32*)buf)));
      return 4;
      return 4;
    }
    }
  else if (nr == PC_REGNUM
  else if (nr == PC_REGNUM
           && len == 4)
           && len == 4)
    {
    {
      set_h_pc (cpu, T2H_4 (*((unsigned32*)buf)));
      set_h_pc (cpu, T2H_4 (*((unsigned32*)buf)));
      return 4;
      return 4;
    }
    }
  else
  else
    return 0;
    return 0;
}
}
 
 

powered by: WebSVN 2.1.0

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