vm_local.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /*
  2. ===========================================================================
  3. Copyright (C) 1999-2005 Id Software, Inc.
  4. This file is part of Quake III Arena source code.
  5. Quake III Arena source code is free software; you can redistribute it
  6. and/or modify it under the terms of the GNU General Public License as
  7. published by the Free Software Foundation; either version 2 of the License,
  8. or (at your option) any later version.
  9. Quake III Arena source code is distributed in the hope that it will be
  10. useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with Foobar; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  16. ===========================================================================
  17. */
  18. #include "../game/q_shared.h"
  19. #include "qcommon.h"
  20. typedef enum {
  21. OP_UNDEF,
  22. OP_IGNORE,
  23. OP_BREAK,
  24. OP_ENTER,
  25. OP_LEAVE,
  26. OP_CALL,
  27. OP_PUSH,
  28. OP_POP,
  29. OP_CONST,
  30. OP_LOCAL,
  31. OP_JUMP,
  32. //-------------------
  33. OP_EQ,
  34. OP_NE,
  35. OP_LTI,
  36. OP_LEI,
  37. OP_GTI,
  38. OP_GEI,
  39. OP_LTU,
  40. OP_LEU,
  41. OP_GTU,
  42. OP_GEU,
  43. OP_EQF,
  44. OP_NEF,
  45. OP_LTF,
  46. OP_LEF,
  47. OP_GTF,
  48. OP_GEF,
  49. //-------------------
  50. OP_LOAD1,
  51. OP_LOAD2,
  52. OP_LOAD4,
  53. OP_STORE1,
  54. OP_STORE2,
  55. OP_STORE4, // *(stack[top-1]) = stack[top]
  56. OP_ARG,
  57. OP_BLOCK_COPY,
  58. //-------------------
  59. OP_SEX8,
  60. OP_SEX16,
  61. OP_NEGI,
  62. OP_ADD,
  63. OP_SUB,
  64. OP_DIVI,
  65. OP_DIVU,
  66. OP_MODI,
  67. OP_MODU,
  68. OP_MULI,
  69. OP_MULU,
  70. OP_BAND,
  71. OP_BOR,
  72. OP_BXOR,
  73. OP_BCOM,
  74. OP_LSH,
  75. OP_RSHI,
  76. OP_RSHU,
  77. OP_NEGF,
  78. OP_ADDF,
  79. OP_SUBF,
  80. OP_DIVF,
  81. OP_MULF,
  82. OP_CVIF,
  83. OP_CVFI
  84. } opcode_t;
  85. typedef int vmptr_t;
  86. typedef struct vmSymbol_s {
  87. struct vmSymbol_s *next;
  88. int symValue;
  89. int profileCount;
  90. char symName[1]; // variable sized
  91. } vmSymbol_t;
  92. #define VM_OFFSET_PROGRAM_STACK 0
  93. #define VM_OFFSET_SYSTEM_CALL 4
  94. struct vm_s {
  95. // DO NOT MOVE OR CHANGE THESE WITHOUT CHANGING THE VM_OFFSET_* DEFINES
  96. // USED BY THE ASM CODE
  97. int programStack; // the vm may be recursively entered
  98. int (*systemCall)( int *parms );
  99. //------------------------------------
  100. char name[MAX_QPATH];
  101. // for dynamic linked modules
  102. void *dllHandle;
  103. int (QDECL *entryPoint)( int callNum, ... );
  104. // for interpreted modules
  105. qboolean currentlyInterpreting;
  106. qboolean compiled;
  107. byte *codeBase;
  108. int codeLength;
  109. int *instructionPointers;
  110. int instructionPointersLength;
  111. byte *dataBase;
  112. int dataMask;
  113. int stackBottom; // if programStack < stackBottom, error
  114. int numSymbols;
  115. struct vmSymbol_s *symbols;
  116. int callLevel; // for debug indenting
  117. int breakFunction; // increment breakCount on function entry to this
  118. int breakCount;
  119. // fqpath member added 7/20/02 by T.Ray
  120. char fqpath[MAX_QPATH+1] ;
  121. };
  122. extern vm_t *currentVM;
  123. extern int vm_debugLevel;
  124. void VM_Compile( vm_t *vm, vmHeader_t *header );
  125. int VM_CallCompiled( vm_t *vm, int *args );
  126. void VM_PrepareInterpreter( vm_t *vm, vmHeader_t *header );
  127. int VM_CallInterpreted( vm_t *vm, int *args );
  128. vmSymbol_t *VM_ValueToFunctionSymbol( vm_t *vm, int value );
  129. int VM_SymbolToValue( vm_t *vm, const char *symbol );
  130. const char *VM_ValueToSymbol( vm_t *vm, int value );
  131. void VM_LogSyscalls( int *args );