simos_vars.c
3.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*
* 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);
}