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

Subversion Repositories openrisc

[/] [openrisc/] [tags/] [gdb/] [gdb-6.8/] [gdb-6.8.openrisc-2.1/] [sim/] [common/] [cgen-run.c] - Diff between revs 24 and 33

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

Rev 24 Rev 33
/* Main simulator loop for CGEN-based simulators.
/* Main simulator loop for CGEN-based simulators.
   Copyright (C) 1998, 2007, 2008 Free Software Foundation, Inc.
   Copyright (C) 1998, 2007, 2008 Free Software Foundation, Inc.
   Contributed by Cygnus Solutions.
   Contributed by Cygnus Solutions.
 
 
This file is part of GDB, the GNU debugger.
This file is part of GDB, the GNU debugger.
 
 
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/>.  */
 
 
/* ??? These are old notes, kept around for now.
/* ??? These are old notes, kept around for now.
   Collecting profile data and tracing slow us down so we don't do them in
   Collecting profile data and tracing slow us down so we don't do them in
   "fast mode".
   "fast mode".
   There are 6 possibilities on 2 axes:
   There are 6 possibilities on 2 axes:
   - no-scaching, insn-scaching, basic-block-scaching
   - no-scaching, insn-scaching, basic-block-scaching
   - run with full features or run fast
   - run with full features or run fast
   Supporting all six possibilities in one executable is a bit much but
   Supporting all six possibilities in one executable is a bit much but
   supporting full/fast seems reasonable.
   supporting full/fast seems reasonable.
   If the scache is configured in it is always used.
   If the scache is configured in it is always used.
   If pbb-scaching is configured in it is always used.
   If pbb-scaching is configured in it is always used.
   ??? Sometimes supporting more than one set of semantic functions will make
   ??? Sometimes supporting more than one set of semantic functions will make
   the simulator too large - this should be configurable.  Blah blah blah.
   the simulator too large - this should be configurable.  Blah blah blah.
   ??? Supporting full/fast can be more modular, blah blah blah.
   ??? Supporting full/fast can be more modular, blah blah blah.
   When the framework is more modular, this can be.
   When the framework is more modular, this can be.
*/
*/
 
 
#include "sim-main.h"
#include "sim-main.h"
#include "sim-assert.h"
#include "sim-assert.h"
 
 
#ifndef SIM_ENGINE_PREFIX_HOOK
#ifndef SIM_ENGINE_PREFIX_HOOK
#define SIM_ENGINE_PREFIX_HOOK(sd)
#define SIM_ENGINE_PREFIX_HOOK(sd)
#endif
#endif
#ifndef SIM_ENGINE_POSTFIX_HOOK
#ifndef SIM_ENGINE_POSTFIX_HOOK
#define SIM_ENGINE_POSTFIX_HOOK(sd)
#define SIM_ENGINE_POSTFIX_HOOK(sd)
#endif
#endif
 
 
static sim_event_handler has_stepped;
static sim_event_handler has_stepped;
static void prime_cpu (SIM_CPU *, int);
static void prime_cpu (SIM_CPU *, int);
static void engine_run_1 (SIM_DESC, int, int);
static void engine_run_1 (SIM_DESC, int, int);
static void engine_run_n (SIM_DESC, int, int, int, int);
static void engine_run_n (SIM_DESC, int, int, int, int);
 
 
/* sim_resume for cgen */
/* sim_resume for cgen */
 
 
void
void
sim_resume (SIM_DESC sd, int step, int siggnal)
sim_resume (SIM_DESC sd, int step, int siggnal)
{
{
  sim_engine *engine = STATE_ENGINE (sd);
  sim_engine *engine = STATE_ENGINE (sd);
  jmp_buf buf;
  jmp_buf buf;
  int jmpval;
  int jmpval;
 
 
  ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER);
  ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER);
 
 
  /* we only want to be single stepping the simulator once */
  /* we only want to be single stepping the simulator once */
  if (engine->stepper != NULL)
  if (engine->stepper != NULL)
    {
    {
      sim_events_deschedule (sd, engine->stepper);
      sim_events_deschedule (sd, engine->stepper);
      engine->stepper = NULL;
      engine->stepper = NULL;
    }
    }
  if (step)
  if (step)
    engine->stepper = sim_events_schedule (sd, 1, has_stepped, sd);
    engine->stepper = sim_events_schedule (sd, 1, has_stepped, sd);
 
 
  sim_module_resume (sd);
  sim_module_resume (sd);
 
 
#if WITH_SCACHE
#if WITH_SCACHE
  if (USING_SCACHE_P (sd))
  if (USING_SCACHE_P (sd))
    scache_flush (sd);
    scache_flush (sd);
#endif
#endif
 
 
  /* run/resume the simulator */
  /* run/resume the simulator */
 
 
  sim_engine_set_run_state (sd, sim_running, 0);
  sim_engine_set_run_state (sd, sim_running, 0);
 
 
  engine->jmpbuf = &buf;
  engine->jmpbuf = &buf;
  jmpval = setjmp (buf);
  jmpval = setjmp (buf);
  if (jmpval == sim_engine_start_jmpval
  if (jmpval == sim_engine_start_jmpval
      || jmpval == sim_engine_restart_jmpval)
      || jmpval == sim_engine_restart_jmpval)
    {
    {
      int last_cpu_nr = sim_engine_last_cpu_nr (sd);
      int last_cpu_nr = sim_engine_last_cpu_nr (sd);
      int next_cpu_nr = sim_engine_next_cpu_nr (sd);
      int next_cpu_nr = sim_engine_next_cpu_nr (sd);
      int nr_cpus = sim_engine_nr_cpus (sd);
      int nr_cpus = sim_engine_nr_cpus (sd);
      /* ??? Setting max_insns to 0 allows pbb/jit code to run wild and is
      /* ??? Setting max_insns to 0 allows pbb/jit code to run wild and is
         useful if all one wants to do is run a benchmark.  Need some better
         useful if all one wants to do is run a benchmark.  Need some better
         way to identify this case.  */
         way to identify this case.  */
      int max_insns = (step
      int max_insns = (step
                       ? 1
                       ? 1
                       : (nr_cpus == 1
                       : (nr_cpus == 1
                          /*&& wip:no-events*/
                          /*&& wip:no-events*/
                          /* Don't do this if running under gdb, need to
                          /* Don't do this if running under gdb, need to
                             poll ui for events.  */
                             poll ui for events.  */
                          && STATE_OPEN_KIND (sd) == SIM_OPEN_STANDALONE)
                          && STATE_OPEN_KIND (sd) == SIM_OPEN_STANDALONE)
                       ? 0
                       ? 0
                       : 8); /*FIXME: magic number*/
                       : 8); /*FIXME: magic number*/
      int fast_p = STATE_RUN_FAST_P (sd);
      int fast_p = STATE_RUN_FAST_P (sd);
 
 
      sim_events_preprocess (sd, last_cpu_nr >= nr_cpus, next_cpu_nr >= nr_cpus);
      sim_events_preprocess (sd, last_cpu_nr >= nr_cpus, next_cpu_nr >= nr_cpus);
      if (next_cpu_nr >= nr_cpus)
      if (next_cpu_nr >= nr_cpus)
        next_cpu_nr = 0;
        next_cpu_nr = 0;
      if (nr_cpus == 1)
      if (nr_cpus == 1)
        engine_run_1 (sd, max_insns, fast_p);
        engine_run_1 (sd, max_insns, fast_p);
      else
      else
        engine_run_n (sd, next_cpu_nr, nr_cpus, max_insns, fast_p);
        engine_run_n (sd, next_cpu_nr, nr_cpus, max_insns, fast_p);
    }
    }
#if 1 /*wip*/
#if 1 /*wip*/
  else
  else
    {
    {
      /* Account for the last insn executed.  */
      /* Account for the last insn executed.  */
      SIM_CPU *cpu = STATE_CPU (sd, sim_engine_last_cpu_nr (sd));
      SIM_CPU *cpu = STATE_CPU (sd, sim_engine_last_cpu_nr (sd));
      ++ CPU_INSN_COUNT (cpu);
      ++ CPU_INSN_COUNT (cpu);
      TRACE_INSN_FINI (cpu, NULL, 1);
      TRACE_INSN_FINI (cpu, NULL, 1);
    }
    }
#endif
#endif
 
 
  engine->jmpbuf = NULL;
  engine->jmpbuf = NULL;
 
 
  {
  {
    int i;
    int i;
    int nr_cpus = sim_engine_nr_cpus (sd);
    int nr_cpus = sim_engine_nr_cpus (sd);
 
 
#if 0 /*wip,ignore*/
#if 0 /*wip,ignore*/
    /* If the loop exits, either we single-stepped or @cpu@_engine_stop
    /* If the loop exits, either we single-stepped or @cpu@_engine_stop
       was called.  */
       was called.  */
    if (step)
    if (step)
      sim_engine_set_run_state (sd, sim_stopped, SIM_SIGTRAP);
      sim_engine_set_run_state (sd, sim_stopped, SIM_SIGTRAP);
    else
    else
      sim_engine_set_run_state (sd, pending_reason, pending_sigrc);
      sim_engine_set_run_state (sd, pending_reason, pending_sigrc);
#endif
#endif
 
 
    for (i = 0; i < nr_cpus; ++i)
    for (i = 0; i < nr_cpus; ++i)
      {
      {
        SIM_CPU *cpu = STATE_CPU (sd, i);
        SIM_CPU *cpu = STATE_CPU (sd, i);
 
 
        PROFILE_TOTAL_INSN_COUNT (CPU_PROFILE_DATA (cpu)) += CPU_INSN_COUNT (cpu);
        PROFILE_TOTAL_INSN_COUNT (CPU_PROFILE_DATA (cpu)) += CPU_INSN_COUNT (cpu);
      }
      }
  }
  }
 
 
  sim_module_suspend (sd);
  sim_module_suspend (sd);
}
}
 
 
/* Halt the simulator after just one instruction.  */
/* Halt the simulator after just one instruction.  */
 
 
static void
static void
has_stepped (SIM_DESC sd, void *data)
has_stepped (SIM_DESC sd, void *data)
{
{
  ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER);
  ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER);
  sim_engine_halt (sd, NULL, NULL, NULL_CIA, sim_stopped, SIM_SIGTRAP);
  sim_engine_halt (sd, NULL, NULL, NULL_CIA, sim_stopped, SIM_SIGTRAP);
}
}
 
 
/* Prepare a cpu for running.
/* Prepare a cpu for running.
   MAX_INSNS is the number of insns to execute per time slice.
   MAX_INSNS is the number of insns to execute per time slice.
   If 0 it means the cpu can run as long as it wants (e.g. until the
   If 0 it means the cpu can run as long as it wants (e.g. until the
   program completes).
   program completes).
   ??? Perhaps this should be an argument to the engine_fn.  */
   ??? Perhaps this should be an argument to the engine_fn.  */
 
 
static void
static void
prime_cpu (SIM_CPU *cpu, int max_insns)
prime_cpu (SIM_CPU *cpu, int max_insns)
{
{
  CPU_MAX_SLICE_INSNS (cpu) = max_insns;
  CPU_MAX_SLICE_INSNS (cpu) = max_insns;
  CPU_INSN_COUNT (cpu) = 0;
  CPU_INSN_COUNT (cpu) = 0;
 
 
  /* Initialize the insn descriptor table.
  /* Initialize the insn descriptor table.
     This has to be done after all initialization so we just defer it to
     This has to be done after all initialization so we just defer it to
     here.  */
     here.  */
 
 
  if (MACH_PREPARE_RUN (CPU_MACH (cpu)))
  if (MACH_PREPARE_RUN (CPU_MACH (cpu)))
    (* MACH_PREPARE_RUN (CPU_MACH (cpu))) (cpu);
    (* MACH_PREPARE_RUN (CPU_MACH (cpu))) (cpu);
}
}
 
 
/* Main loop, for 1 cpu.  */
/* Main loop, for 1 cpu.  */
 
 
static void
static void
engine_run_1 (SIM_DESC sd, int max_insns, int fast_p)
engine_run_1 (SIM_DESC sd, int max_insns, int fast_p)
{
{
  sim_cpu *cpu = STATE_CPU (sd, 0);
  sim_cpu *cpu = STATE_CPU (sd, 0);
  ENGINE_FN *fn = fast_p ? CPU_FAST_ENGINE_FN (cpu) : CPU_FULL_ENGINE_FN (cpu);
  ENGINE_FN *fn = fast_p ? CPU_FAST_ENGINE_FN (cpu) : CPU_FULL_ENGINE_FN (cpu);
 
 
  prime_cpu (cpu, max_insns);
  prime_cpu (cpu, max_insns);
 
 
  while (1)
  while (1)
    {
    {
      SIM_ENGINE_PREFIX_HOOK (sd);
      SIM_ENGINE_PREFIX_HOOK (sd);
 
 
      (*fn) (cpu);
      (*fn) (cpu);
 
 
      SIM_ENGINE_POSTFIX_HOOK (sd);
      SIM_ENGINE_POSTFIX_HOOK (sd);
 
 
      /* process any events */
      /* process any events */
      if (sim_events_tick (sd))
      if (sim_events_tick (sd))
        sim_events_process (sd);
        sim_events_process (sd);
    }
    }
}
}
 
 
/* Main loop, for multiple cpus.  */
/* Main loop, for multiple cpus.  */
 
 
static void
static void
engine_run_n (SIM_DESC sd, int next_cpu_nr, int nr_cpus, int max_insns, int fast_p)
engine_run_n (SIM_DESC sd, int next_cpu_nr, int nr_cpus, int max_insns, int fast_p)
{
{
  int i;
  int i;
  ENGINE_FN *engine_fns[MAX_NR_PROCESSORS];
  ENGINE_FN *engine_fns[MAX_NR_PROCESSORS];
 
 
  for (i = 0; i < nr_cpus; ++i)
  for (i = 0; i < nr_cpus; ++i)
    {
    {
      SIM_CPU *cpu = STATE_CPU (sd, i);
      SIM_CPU *cpu = STATE_CPU (sd, i);
 
 
      engine_fns[i] = fast_p ? CPU_FAST_ENGINE_FN (cpu) : CPU_FULL_ENGINE_FN (cpu);
      engine_fns[i] = fast_p ? CPU_FAST_ENGINE_FN (cpu) : CPU_FULL_ENGINE_FN (cpu);
      prime_cpu (cpu, max_insns);
      prime_cpu (cpu, max_insns);
    }
    }
 
 
  while (1)
  while (1)
    {
    {
      SIM_ENGINE_PREFIX_HOOK (sd);
      SIM_ENGINE_PREFIX_HOOK (sd);
 
 
      /* FIXME: proper cycling of all of them, blah blah blah.  */
      /* FIXME: proper cycling of all of them, blah blah blah.  */
      while (next_cpu_nr != nr_cpus)
      while (next_cpu_nr != nr_cpus)
        {
        {
          SIM_CPU *cpu = STATE_CPU (sd, next_cpu_nr);
          SIM_CPU *cpu = STATE_CPU (sd, next_cpu_nr);
 
 
          (* engine_fns[next_cpu_nr]) (cpu);
          (* engine_fns[next_cpu_nr]) (cpu);
          ++next_cpu_nr;
          ++next_cpu_nr;
        }
        }
 
 
      SIM_ENGINE_POSTFIX_HOOK (sd);
      SIM_ENGINE_POSTFIX_HOOK (sd);
 
 
      /* process any events */
      /* process any events */
      if (sim_events_tick (sd))
      if (sim_events_tick (sd))
        sim_events_process (sd);
        sim_events_process (sd);
    }
    }
}
}
 
 

powered by: WebSVN 2.1.0

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