📄 tcl_init.c
字号:
/* * 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. * *//***************************************************************** * tcl_init.c * *****************************************************************/#include <sys/signal.h>#include <sys/times.h>#include <sys/types.h>#include <sys/termios.h>#include <sys/time.h>#include <sys/file.h>#include <sys/socket.h>#include <netinet/in.h>#include <netinet/tcp.h>#include <sys/mman.h>#include <errno.h>#include <math.h>#include <unistd.h>#include <fcntl.h>#include <stdio.h>#include <setjmp.h>#include <string.h>#include <memory.h>#include <ctype.h>#include <stdlib.h>#include <sys/wait.h>#include <sys/socket.h>#include <netdb.h>#include <file_formats.h>#include <signal.h>#include <assert.h>#include "syslimits.h"#include "sim_error.h"#include "cpu_interface.h"#include "simtypes.h"#include "machine_params.h"#include "tcl_init.h"#include "params.h"#include "visual.h"#include <sys/stat.h>#include "profile.h"#include "simutil.h"#include "hw_events.h"#include "arch_specifics.h"static void MiscInit(Tcl_Interp *);static void MachineStateInit(Tcl_Interp *);#ifdef USE_FLASHLITEextern int restoringCpt;static void FlashliteTclInit(Tcl_Interp *);#endifextern void SimOSVarsInit(Tcl_Interp *);extern void AnnotationInit(Tcl_Interp *);extern void SelectorInit(Tcl_Interp *);extern void DetailInit(Tcl_Interp *);extern void SymInit(Tcl_Interp *);extern void StatisticsInit(Tcl_Interp *);extern void TimingInit(Tcl_Interp *);extern void TimingInit(Tcl_Interp *);extern void StackTclInit(Tcl_Interp *);extern void MipsyTclInit(Tcl_Interp *);#ifndef NO_EMBRAextern void EmbraTclInit(Tcl_Interp *);#endifextern void BinaryInit(Tcl_Interp *);extern void ScacheAnnInit(Tcl_Interp *);extern void ScacheAnnLateInit(Tcl_Interp *);extern void ExpectInit(Tcl_Interp *);extern void ParamInit(Tcl_Interp *);extern void SoloTclInit(Tcl_Interp *);#ifdef HWBCOPYextern void HwbcopyAnnInit(Tcl_Interp *);#endifextern void ClusterTclInit(Tcl_Interp *interp);extern void FaultInit(Tcl_Interp *);extern FILE* Simrmt_RemoteFileOpen(char *pathName);extern int HiveCmd(ClientData, Tcl_Interp *, int, char **);#if defined(SIM_ALPHA)extern void AlphaTclInit(Tcl_Interp *);extern void PrintInstsInit(Tcl_Interp *);extern void GammaTclInit(Tcl_Interp *);extern void DeltaTclInit(Tcl_Interp *);extern void EpsilonTclInit(Tcl_Interp *);extern void AlphaTraceTclInit(Tcl_Interp *interp);#ifdef USE_VISTA_SDFextern void SDF_Tcl_Init(Tcl_Interp *);#endifstatic void (*initFunc[])(Tcl_Interp *) = { SimOSVarsInit, ParamInit, AnnotationInit, SelectorInit, DetailInit, SymInit, MachineStateInit, StatisticsInit, MiscInit, BinaryInit, TimingInit, ExpectInit, HWEventsEarlyInit, PrintInstsInit, AlphaTclInit, GammaTclInit, DeltaTclInit, EpsilonTclInit, AlphaTraceTclInit,#ifdef USE_VISTA_SDF SDF_Tcl_Init#endif};#endif#if defined(SIM_MIPS32) || defined(SIM_MIPS64)static void (*initFunc[])(Tcl_Interp *) = { SimOSVarsInit, ParamInit, AnnotationInit, SelectorInit, DetailInit, SymInit, MachineStateInit, StatisticsInit, MiscInit, TimingInit, StackTclInit, MipsyTclInit,#ifndef NO_EMBRA EmbraTclInit,#endif BinaryInit, ScacheAnnInit, FaultInit,#ifdef HWBCOPY HwbcopyAnnInit,#endif ExpectInit,#ifdef USE_FLASHLITE FlashliteTclInit,#endif SoloTclInit, HWEventsEarlyInit};#endif #if defined(SIM_X86)static void (*initFunc[])(Tcl_Interp *) = { SimOSVarsInit, ParamInit, AnnotationInit, SelectorInit, DetailInit, SymInit, MachineStateInit, StatisticsInit, MiscInit, TimingInit, StackTclInit, BinaryInit, ScacheAnnInit, ClusterTclInit, ExpectInit, HWEventsEarlyInit};#endif #define NUM_INIT_FUNCS (sizeof(initFunc)/sizeof(void *))static void (*lateInitFunc[])(Tcl_Interp *) = {#if !defined(SIM_ALPHA) ScacheAnnLateInit#endif};#define NUM_LATE_INIT_FUNCS (sizeof(lateInitFunc)/sizeof(void*))Tcl_Interp *TCLInterp = NULL;static char *errorHandlingScript = NULL;int TclIniting = 1;extern int machineParamVec[MAX_MACHINES];extern MachineScopeType machineScope;void TCLInit(char *initFile){ Tcl_DString result; struct stat buf; char *exname; int i; TCLInterp = Tcl_CreateInterp(); if (Tcl_Init(TCLInterp) != TCL_OK ) { CPUWarning("SIMOS: ERROR initing Tcl: %s\n", TCLInterp->result); exit(1); } for (i=0; i<NUM_INIT_FUNCS; i++) { ASSERT(initFunc[i]); (*initFunc[i])(TCLInterp); } if ((exname = Tcl_TildeSubst(TCLInterp, initFile, &result)) == NULL) { CPUWarning("SIMOS: ERROR: bad init file name: %s\n", initFile); exit(1); } if (stat(exname, &buf)) { CPUWarning("SIMOS: init.simos file required\n"); exit(1); } Tcl_DStringFree(&result); if (Tcl_EvalFile(TCLInterp, initFile) != TCL_OK) { char *errorStr = Tcl_GetVar(TCLInterp, "errorInfo", TCL_GLOBAL_ONLY); CPUWarning("TCL error while initializing.\n%s\n", errorStr); exit(1); } TclIniting = 0; for (i=0; i<NUM_LATE_INIT_FUNCS; i++) { ASSERT(lateInitFunc[i]); (*lateInitFunc[i])(TCLInterp); } MachineSettingsComplete(); SetAdditionalParams(TCLInterp);}/* * command dispatch */static void usage(Tcl_Interp *interp, char *cmdName, tclcmd *cmds){ int i; Tcl_AppendResult(interp, cmdName, " usage:\n\r", NULL); for (i=0; cmds[i].name; i++) { Tcl_AppendResult(interp, cmdName, cmds[i].usage, "\n\r", NULL); }}int DispatchCmd(ClientData data, Tcl_Interp *interp, int argc, char *argv[]){ tclcmd *cmds = (tclcmd*)data; int i, c; size_t length; char *buf; if (argc == 1) { usage(interp, argv[0], cmds); return TCL_OK; } c = argv[1][0]; length = strlen(argv[1]); for (i=0; cmds[i].name; i++) { if ((c == cmds[i].name[0]) && (strncmp(argv[1], cmds[i].name, length) == 0)) { if ((cmds[i].numargs == -1) || (cmds[i].numargs == argc)) { ASSERT(cmds[i].cmd); return (*cmds[i].cmd)(interp, argc, argv); } else { Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], cmds[i].usage, "\"", NULL); return TCL_ERROR; } } } length = 1; for (i=0; i<argc; i++) { length += strlen(argv[i]); length += 1; /* room for space */ } buf = malloc(length); /* cons up a procedure call */ sprintf(buf, "%s_%s", argv[0], argv[1]); for (i=2; i<argc; i++) { strcat(buf, " "); strcat(buf, argv[i]); } if (Tcl_Eval(interp, buf) != TCL_OK) { free(buf); return TCL_ERROR; } free(buf); return TCL_OK;}/* * translate virtual addresses using knowledge of the OS */unsigned TclTranslateVirtual(int cpuNum, VA vAddr){ char buf[64]; unsigned pAddr = 0; if (sizeof(vAddr) == sizeof(int)) sprintf(buf, "TclTranslateVirtual %d 0x%x", cpuNum, (int)vAddr); else { #ifdef __alpha sprintf(buf, "TclTranslateVirtual %d 0x%lx", cpuNum, (Reg64)vAddr);#else#ifdef linux sprintf(buf, "TclTranslateVirtual %d 0x%x", cpuNum, (int)vAddr);#else sprintf(buf, "TclTranslateVirtual %d 0x%llx", cpuNum, (Reg64)vAddr);#endif#endif } if (Tcl_Eval(TCLInterp, buf) != TCL_OK) { CPUWarning("ERROR: in TclTranslateVirtual: %s\n", TCLInterp->result); Tcl_ResetResult(TCLInterp); return 0; } if (Tcl_GetInt(TCLInterp, TCLInterp->result, (int*)&pAddr) != TCL_OK) { CPUWarning("ERROR: TclTranslateVirtual returned non-int \"%s\"\n", TCLInterp->result); Tcl_ResetResult(TCLInterp); return 0; } Tcl_ResetResult(TCLInterp); return (unsigned)pAddr;}/* * Generate disk name based on cell/controller/disk information. * Returns NULL if no DiskFileName procedure has been defined in Tcl. */char* TclDiskFileName(int machine, int node, int ctrl, int unit){ char buf[64]; char* res; sprintf(buf, "DiskFileName %d %d %d %d", machine, node, ctrl, unit); if (Tcl_Eval(TCLInterp, buf) != TCL_OK) { /* probably no Tcl procedure defined */ return (char*) NULL; } /* must return copy of string */ res = (char*) malloc(strlen(TCLInterp->result)+1); ASSERT(res); strcpy(res, TCLInterp->result); Tcl_ResetResult(TCLInterp); return res;}voidTclDoCheckpoint(char* name){ char buf[256]; sprintf(buf, "DoCheckpointProc %s", name); if (Tcl_Eval(TCLInterp, buf) == TCL_OK) { Tcl_ResetResult(TCLInterp); }}voidTclRestoreCheckpoint(char* name){ char buf[256]; sprintf(buf, "RestoreCheckpointProc %s", name); if (Tcl_Eval(TCLInterp, buf) == TCL_OK) { Tcl_ResetResult(TCLInterp); }}/* * misc. tcl commands (log, console, debug) */#ifdef OPTION_AS_HASHTABLEstatic Tcl_HashTable opts;#elsestatic struct OptionBinding { const char *name; const char *value;} *optionBindings = NULL;static int nOptionBindings = 0;#endif /* OPTION_AS_HASHTABLE */static int optsInit = 0;void TCLDefineOption(char *opt, char *val){ Tcl_HashEntry *entry; fprintf(stderr, "Defining option %s with value %s\n", opt, val); fprintf(stderr, "TCLInterp=%p\n", TCLInterp); { int i = nOptionBindings; nOptionBindings++; optionBindings = realloc(optionBindings, nOptionBindings * sizeof(struct OptionBinding)); optionBindings[i].name = SaveString(opt); optionBindings[i].value = SaveString(val); }}static void TCLOptionInit(Tcl_Interp *interp){ int i; for (i = 0; i < nOptionBindings; i++) { Tcl_SetVar2(TCLInterp, "OPTION", optionBindings[i].name, optionBindings[i].value, TCL_GLOBAL_ONLY); }}/* * Search for the file name filename on the simosPath. Result is the * full pathname of the (possibly remote) file. The result is only * good untill the next call to SearchForFile and may be the string * that was passed in. */char fullFileName[2048];char *SearchForFile(char *filename){ int listArgc, j; char **listArgv; Tcl_DString buffer; FILE *fp = NULL; char *fname; char *path; fullFileName[0] = '\0'; if (strchr(filename, ':')) { return filename; } if ((filename[0] == '~') || strchr(filename, '/')) { return filename; } if ((path = Tcl_GetVar(TCLInterp, "simosPath", TCL_GLOBAL_ONLY)) == NULL) { return NULL; } if (Tcl_SplitList(TCLInterp, path, &listArgc, &listArgv) != TCL_OK) { CPUWarning("SIMOS: can't parse simosPath list\n"); return NULL; } for (j = 0; j < listArgc; j++) { ASSERT((strlen(listArgv[j]) + strlen(filename) + 2) < 2048); if (strchr(listArgv[j], ':')) { /* Going remote... */ sprintf(fullFileName, "%s/%s", listArgv[j], filename); fp = Simrmt_RemoteFileOpen(fullFileName); if (fp) { fclose(fp); return fullFileName; } } else { /* Actual local file */ sprintf(fullFileName,"%s/%s", listArgv[j], filename); fname = Tcl_TildeSubst(TCLInterp, fullFileName, &buffer); if (fname) { if (fullFileName != fname) { ASSERT(strlen(fname) < 2048); strcpy(fullFileName, fname); } Tcl_DStringFree(&buffer);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -