OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [tags/] [gnu-src/] [gdb-6.8/] [pre-binutils-2.20.1-sync/] [sim/] [m68hc11/] [emulos.c] - Diff between revs 157 and 223

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

Rev 157 Rev 223
/* emulos.c -- Small OS emulation
/* emulos.c -- Small OS emulation
   Copyright 1999, 2000, 2007, 2008 Free Software Foundation, Inc.
   Copyright 1999, 2000, 2007, 2008 Free Software Foundation, Inc.
   Written by Stephane Carrez (stcarrez@worldnet.fr)
   Written by Stephane Carrez (stcarrez@worldnet.fr)
 
 
This file is part of GDB, GAS, and the GNU binutils.
This file is part of GDB, GAS, and the GNU binutils.
 
 
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 "sim-main.h"
#include "sim-main.h"
#ifdef HAVE_UNISTD_H
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#include <unistd.h>
#endif
#endif
 
 
#ifndef WIN32
#ifndef WIN32
#include <sys/types.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/time.h>
 
 
/* This file emulates some OS system calls.
/* This file emulates some OS system calls.
   It's basically used to give access to the host OS facilities
   It's basically used to give access to the host OS facilities
   like: stdin, stdout, files, time of day.  */
   like: stdin, stdout, files, time of day.  */
static int bench_mode = -1;
static int bench_mode = -1;
static struct timeval bench_start;
static struct timeval bench_start;
static struct timeval bench_stop;
static struct timeval bench_stop;
 
 
void
void
emul_bench (struct _sim_cpu* cpu)
emul_bench (struct _sim_cpu* cpu)
{
{
  int op;
  int op;
 
 
  op = cpu_get_d (cpu);
  op = cpu_get_d (cpu);
  switch (op)
  switch (op)
    {
    {
    case 0:
    case 0:
      bench_mode = 0;
      bench_mode = 0;
      gettimeofday (&bench_start, 0);
      gettimeofday (&bench_start, 0);
      break;
      break;
 
 
    case 1:
    case 1:
      gettimeofday (&bench_stop, 0);
      gettimeofday (&bench_stop, 0);
      if (bench_mode != 0)
      if (bench_mode != 0)
        printf ("bench start not called...\n");
        printf ("bench start not called...\n");
      bench_mode = 1;
      bench_mode = 1;
      break;
      break;
 
 
    case 2:
    case 2:
      {
      {
        int sz = 0;
        int sz = 0;
        int addr = cpu_get_x (cpu);
        int addr = cpu_get_x (cpu);
        double t_start, t_stop, t;
        double t_start, t_stop, t;
        char buf[1024];
        char buf[1024];
 
 
        op = cpu_get_y (cpu);
        op = cpu_get_y (cpu);
        t_start = (double) (bench_start.tv_sec) * 1.0e6;
        t_start = (double) (bench_start.tv_sec) * 1.0e6;
        t_start += (double) (bench_start.tv_usec);
        t_start += (double) (bench_start.tv_usec);
        t_stop  = (double) (bench_stop.tv_sec) * 1.0e6;
        t_stop  = (double) (bench_stop.tv_sec) * 1.0e6;
        t_stop  += (double) (bench_stop.tv_usec);
        t_stop  += (double) (bench_stop.tv_usec);
 
 
        while (sz < 1024)
        while (sz < 1024)
          {
          {
            buf[sz] = memory_read8 (cpu, addr);
            buf[sz] = memory_read8 (cpu, addr);
            if (buf[sz] == 0)
            if (buf[sz] == 0)
              break;
              break;
 
 
            sz ++;
            sz ++;
            addr++;
            addr++;
          }
          }
        buf[1023] = 0;
        buf[1023] = 0;
 
 
        if (bench_mode != 1)
        if (bench_mode != 1)
          printf ("bench_stop not called");
          printf ("bench_stop not called");
 
 
        bench_mode = -1;
        bench_mode = -1;
        t = t_stop - t_start;
        t = t_stop - t_start;
        printf ("%-40.40s [%6d] %3.3f us\n", buf,
        printf ("%-40.40s [%6d] %3.3f us\n", buf,
                op, t / (double) (op));
                op, t / (double) (op));
        break;
        break;
      }
      }
    }
    }
}
}
#endif
#endif
 
 
void
void
emul_write(struct _sim_cpu* state)
emul_write(struct _sim_cpu* state)
{
{
  int addr = cpu_get_x (state) & 0x0FFFF;
  int addr = cpu_get_x (state) & 0x0FFFF;
  int size = cpu_get_d (state) & 0x0FFFF;
  int size = cpu_get_d (state) & 0x0FFFF;
 
 
  if (addr + size > 0x0FFFF) {
  if (addr + size > 0x0FFFF) {
    size = 0x0FFFF - addr;
    size = 0x0FFFF - addr;
  }
  }
  state->cpu_running = 0;
  state->cpu_running = 0;
  while (size)
  while (size)
    {
    {
      uint8 val = memory_read8 (state, addr);
      uint8 val = memory_read8 (state, addr);
 
 
      write(0, &val, 1);
      write(0, &val, 1);
      addr ++;
      addr ++;
      size--;
      size--;
    }
    }
}
}
 
 
/* emul_exit () is used by the default startup code of GCC to implement
/* emul_exit () is used by the default startup code of GCC to implement
   the exit ().  For a real target, this will create an ILLEGAL fault.
   the exit ().  For a real target, this will create an ILLEGAL fault.
   But doing an exit () on a real target is really a non-sense.
   But doing an exit () on a real target is really a non-sense.
   exit () is important for the validation of GCC.  The exit status
   exit () is important for the validation of GCC.  The exit status
   is passed in 'D' register.  */
   is passed in 'D' register.  */
void
void
emul_exit (sim_cpu *cpu)
emul_exit (sim_cpu *cpu)
{
{
  sim_engine_halt (CPU_STATE (cpu), cpu,
  sim_engine_halt (CPU_STATE (cpu), cpu,
                   NULL, NULL_CIA, sim_exited,
                   NULL, NULL_CIA, sim_exited,
                   cpu_get_d (cpu));
                   cpu_get_d (cpu));
}
}
 
 
void
void
emul_os (int code, sim_cpu *proc)
emul_os (int code, sim_cpu *proc)
{
{
  proc->cpu_current_cycle = 8;
  proc->cpu_current_cycle = 8;
  switch (code)
  switch (code)
    {
    {
    case 0x0:
    case 0x0:
      break;
      break;
 
 
      /* 0xCD 0x01 */
      /* 0xCD 0x01 */
    case 0x01:
    case 0x01:
      emul_write (proc);
      emul_write (proc);
      break;
      break;
 
 
      /* 0xCD 0x02 */
      /* 0xCD 0x02 */
    case 0x02:
    case 0x02:
      break;
      break;
 
 
      /* 0xCD 0x03 */
      /* 0xCD 0x03 */
    case 0x03:
    case 0x03:
      emul_exit (proc);
      emul_exit (proc);
      break;
      break;
 
 
      /* 0xCD 0x04 */
      /* 0xCD 0x04 */
    case 0x04:
    case 0x04:
#ifndef WIN32
#ifndef WIN32
      emul_bench (proc);
      emul_bench (proc);
#endif
#endif
      break;
      break;
 
 
    default:
    default:
      break;
      break;
    }
    }
}
}
 
 
 
 

powered by: WebSVN 2.1.0

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