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

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [trunk/] [or1ksim/] [toplevel-support.c] - Diff between revs 443 and 483

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 443 Rev 483
Line 32... Line 32...
#include <unistd.h>
#include <unistd.h>
#include <stdarg.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdio.h>
#include <errno.h>
#include <errno.h>
#include <signal.h>
#include <signal.h>
 
#include <sys/types.h>
 
#include <sys/stat.h>
 
#include <fcntl.h>
 
 
/* Package includes */
/* Package includes */
#include "toplevel-support.h"
#include "toplevel-support.h"
#include "sim-config.h"
#include "sim-config.h"
#include "debug-unit.h"
#include "debug-unit.h"
Line 67... Line 70...
/*! The list of reset hooks. Local to this source file */
/*! The list of reset hooks. Local to this source file */
static struct sim_reset_hook *sim_reset_hooks = NULL;
static struct sim_reset_hook *sim_reset_hooks = NULL;
 
 
 
 
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
 
/*!Random number initialization
 
 
 
   This has become more important, since we rely on randomness to generate
 
   different MACs in Linux running on Or1ksim.
 
 
 
   We take our seed from /dev/urandom.
 
 
 
   If /dev/urandom is not available, we use srandom with the PID instead.    */
 
/*---------------------------------------------------------------------------*/
 
void
 
init_randomness ()
 
{
 
  unsigned int   seed;
 
  int            fd;
 
 
 
  fd = open ("/dev/urandom", O_RDONLY);
 
 
 
  if (fd >= 0)
 
    {
 
      if (sizeof (seed) != read (fd, (void *) &seed, sizeof (seed)))
 
        {
 
          fprintf (stderr, "Warning: Unable to read /dev/random, using PID.\n");
 
          seed = getpid ();
 
        }
 
    }
 
  else
 
    {
 
      fprintf (stderr, "Warning: Unable to open /dev/random, using PID.\n");
 
      seed = getpid ();
 
    }
 
 
 
  srandom (seed);
 
 
 
  /* Print out the seed just in case we ever need to debug. Note that we
 
     cannot use PRINTF here, since the file handle will not yet have been set
 
     up. */
 
  printf ("Seeding random generator with value 0x%08x\n", seed);
 
 
 
}       /* init_randomness () */
 
 
 
 
 
/*---------------------------------------------------------------------------*/
/*!Signal handler for ctrl-C
/*!Signal handler for ctrl-C
 
 
   Sets the iprompt flag, so the simulator will stop next time round the
   Sets the iprompt flag, so the simulator will stop next time round the
   loop. If the iprompt flag is set when we enter here, that means the
   loop. If the iprompt flag is set when we enter here, that means the
   simulator has not reacted since the last ctrl-C, so we kill the simulation.
   simulator has not reacted since the last ctrl-C, so we kill the simulation.

powered by: WebSVN 2.1.0

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