00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef UCMACHINE_H
00020 #define UCMACHINE_H
00021
00022 #include <map>
00023 #include <set>
00024
00025 #include "intrinsics.h"
00026
00027 class Process;
00028 class UCProcess;
00029 class ConvertUsecode;
00030 class IDataSource;
00031 class ODataSource;
00032 class BitSet;
00033 class UCList;
00034 class idMan;
00035
00036 class UCMachine
00037 {
00038 public:
00039 UCMachine(Intrinsic *iset, unsigned int icount);
00040 ~UCMachine();
00041
00042 static UCMachine* get_instance() { return ucmachine; }
00043
00044 void reset();
00045
00046 bool execProcess(UCProcess* proc);
00047
00048 std::string& getString(uint16 str);
00049 UCList* getList(uint16 l);
00050
00051 void freeString(uint16 s);
00052 void freeStringList(uint16 l);
00053 void freeList(uint16 l);
00054
00055 uint16 duplicateString(uint16 str);
00056
00057 void usecodeStats();
00058
00059 static uint32 listToPtr(uint16 l);
00060 static uint32 stringToPtr(uint16 s);
00061 static uint32 stackToPtr(uint16 pid, uint16 offset);
00062 static uint32 globalToPtr(uint16 offset);
00063 static uint32 objectToPtr(uint16 objID);
00064
00065 static uint16 ptrToObject(uint32 ptr);
00066
00067 bool assignPointer(uint32 ptr, const uint8* data, uint32 size);
00068 bool dereferencePointer(uint32 ptr, uint8* data, uint32 size);
00069
00070 void saveGlobals(ODataSource* ods);
00071 void saveStrings(ODataSource* ods);
00072 void saveLists(ODataSource* ods);
00073
00074 bool loadGlobals(IDataSource* ids, uint32 version);
00075 bool loadStrings(IDataSource* ids, uint32 version);
00076 bool loadLists(IDataSource* ids, uint32 version);
00077
00078 INTRINSIC(I_true);
00079 INTRINSIC(I_dummyProcess);
00080 INTRINSIC(I_getName);
00081 INTRINSIC(I_urandom);
00082 INTRINSIC(I_rndRange);
00083 INTRINSIC(I_numToStr);
00084 INTRINSIC(I_getCurrentTimerTick);
00085
00086 protected:
00087 void loadIntrinsics(Intrinsic *i, unsigned int icount);
00088
00089 private:
00090
00091 ConvertUsecode* convuse;
00092 Intrinsic* intrinsics;
00093 unsigned int intrinsiccount;
00094
00095 BitSet* globals;
00096
00097 std::map<uint16, UCList*> listHeap;
00098 std::map<uint16, std::string> stringHeap;
00099
00100 uint16 assignString(const char* str);
00101 uint16 assignList(UCList* l);
00102
00103 idMan* listIDs;
00104 idMan* stringIDs;
00105
00106 static UCMachine* ucmachine;
00107
00108 static void ConCmd_getGlobal(const Console::ArgvType &argv);
00109 static void ConCmd_setGlobal(const Console::ArgvType &argv);
00110
00111
00112 #ifdef DEBUG
00113
00114 bool tracing_enabled;
00115 bool trace_all;
00116 bool trace_events;
00117 std::set<ObjId> trace_ObjIDs;
00118 std::set<ProcId> trace_PIDs;
00119 std::set<uint16> trace_classes;
00120
00121 inline bool trace_show(ProcId pid, ObjId objid, uint16 ucclass) {
00122 if (!tracing_enabled) return false;
00123 if (trace_all) return true;
00124 if (trace_ObjIDs.find(objid) != trace_ObjIDs.end()) return true;
00125 if (trace_PIDs.find(pid) != trace_PIDs.end()) return true;
00126 if (trace_classes.find(ucclass) != trace_classes.end()) return true;
00127 return false;
00128 }
00129
00130 public:
00131 bool trace_event() {
00132 return (tracing_enabled && (trace_all || trace_events));
00133 }
00134
00135 private:
00136 static void ConCmd_tracePID(const Console::ArgvType &argv);
00137 static void ConCmd_traceObjID(const Console::ArgvType &argv);
00138 static void ConCmd_traceClass(const Console::ArgvType &argv);
00139 static void ConCmd_traceAll(const Console::ArgvType &argv);
00140 static void ConCmd_traceEvents(const Console::ArgvType &argv);
00141 static void ConCmd_stopTrace(const Console::ArgvType &argv);
00142 #endif
00143 };
00144
00145 #endif