simos_vars.c 3.25 KB
/*
 * Copyright (C) 1996-1998 by the Board of Trustees
 *    of Leland Stanford Junior University.
 * 
 * This file is part of the SimOS distribution. 
 * See LICENSE file for terms of the license. 
 *
 */

/*****************************************************************
 * simos_vars.c
 *
 * This file incorporates all accesses to the SIMOS array. This array 
 * is used to access variables that refer to the simulator itself
 * rather than any particular workload.
 * 
 * Author: $Author: blythe $
 * Date:   $Date: 2002/05/29 01:09:10 $
 *****************************************************************/

#include <sys/utsname.h>
#include "simutil.h"
#include "tcl_init.h"

extern int restoringCpt;

#if !defined(NO_EMBRA) && (defined(SIM_MIPS32) || defined(SIM_MIPS64))
static int embraPresent = 1;
#else
static int embraPresent = 0;
#endif

#if defined(SIM_ALPHA)
static char simosISA[] = "ALPHA";
#endif
#if defined(SIM_MIPS32)
static char simosISA[] = "MIPS32";
#endif
#if defined(SIM_MIPS64)
static char simosISA[] = "MIPS";
#endif
#if defined(SIM_X86)
static char simosISA[] = "X86";
#endif

#if (defined(SIM_MIPS64) || defined(SIM_MIPS32))
#  if defined(SIM_MIPS64)
#     if defined(IRIX6_4)
         static char targetOS[] = "IRIX6.4";
#     else
         static char targetOS[] = "IRIX6.2";
#     endif
#  else
      static char targetOS[] = "IRIX5.3";
#  endif
#else
#if defined(SIM_X86) 
  static char targetOS[] = "LINUX";
#else
  static char targetOS[] = "UNKNOWN";
#endif
#endif

static char *
HostOSAccess(ClientData clientData, Tcl_Interp *interp,
             char *name1, char *name2, int flags)
{
   struct utsname name;
   
   if (flags & TCL_TRACE_WRITES) {
      return "Writes to SIMOS(HostOS) ignored";
   }

   if (uname(&name) == -1) {
      return "SIMOS(HostOS) implementation failed";
   }
   Tcl_SetVar2(interp, name1, name2, name.sysname, 0);
   return NULL;  
}

static char *ISAAccess(
ClientData clientData, Tcl_Interp *interp,
             char *name1, char *name2, int flags)
{
   struct utsname name;
   
   if (flags & TCL_TRACE_WRITES) {
      return "Writes to SIMOS(ISA) ignored";
   }

   if (uname(&name) == -1) {
      return "SIMOS(ISA) implementation failed";
   }
   Tcl_SetVar2(interp, name1, name2, simosISA, 0);
   return NULL;  
}

static char *TargetOSAccess(
ClientData clientData, Tcl_Interp *interp,
             char *name1, char *name2, int flags)
{
   Tcl_SetVar2(interp, name1, name2, targetOS , 0);
   return NULL;  
}

void
SimOSVarsInit(Tcl_Interp *interp)
{

   Tcl_LinkVar(interp, SaveString("SIMOS(RestoringCpt)"), (char*)&restoringCpt,
               TCL_LINK_READ_ONLY | TCL_LINK_BOOLEAN);

   Tcl_LinkVar(interp, SaveString("SIMOS(EmbraPresent)"), (char*)&embraPresent,
               TCL_LINK_READ_ONLY | TCL_LINK_BOOLEAN);

   Tcl_TraceVar(interp, SaveString("SIMOS(TargetOS)"),
                TCL_TRACE_READS | TCL_GLOBAL_ONLY,
                TargetOSAccess, (ClientData) NULL);

   Tcl_TraceVar(interp, SaveString("SIMOS(HostOS)"),
                TCL_TRACE_READS | TCL_TRACE_WRITES | TCL_GLOBAL_ONLY,
                HostOSAccess, (ClientData) NULL);
                
   Tcl_TraceVar(interp, SaveString("SIMOS(ISA)"),
                TCL_TRACE_READS | TCL_TRACE_WRITES | TCL_GLOBAL_ONLY,
                ISAAccess, (ClientData) NULL);

   
}