Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

269 lines
7.4 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. config.c
  5. Abstract:
  6. This module implements the configuration support for the CPU.
  7. Author:
  8. 13-Jun-1996 BarryBo
  9. Revision History:
  10. --*/
  11. #include <nt.h>
  12. #include <ntrtl.h>
  13. #include <nturtl.h>
  14. #include <windows.h>
  15. #include <stdio.h>
  16. #define _WX86CPUAPI_
  17. #include "wx86.h"
  18. #include "wx86nt.h"
  19. #include "wx86cpu.h"
  20. #include "cpuassrt.h"
  21. #include "config.h"
  22. #include "entrypt.h"
  23. #include "instr.h"
  24. #include "compiler.h"
  25. ASSERTNAME;
  26. char *szBadVarMsg="%Ws value out-of-range - replacing with 0x%x.\n";
  27. //
  28. // The list of all configurable variables in the CPU. All are initialized
  29. // to their default values.
  30. //
  31. DWORD CpuCacheReserve = 6144*1024;
  32. DWORD CpuCacheCommit = MAX_PROLOG_SIZE;
  33. DWORD CpuCacheGrowTicks = 200;
  34. DWORD CpuCacheShrinkTicks = 1000;
  35. DWORD CpuCacheChunkMin = 32*1024;
  36. DWORD CpuCacheChunkMax = 512*1024;
  37. DWORD CpuCacheChunkSize = 64*1024;
  38. LARGE_INTEGER MrswTimeout;
  39. DWORD CompilerFlags = COMPFL_FAST;
  40. DWORD fUseNPXEM = FALSE;
  41. DWORD CpuMaxAllocRetries = 4;
  42. DWORD CpuWaitForMemoryTime = 200;
  43. DWORD CpuInstructionLookahead = MAX_INSTR_COUNT;
  44. DWORD CpuDisableDynamicCache = FALSE;
  45. DWORD CpuEntryPointReserve = 0x1000000;
  46. DWORD CpuDisableRegCache = FALSE;
  47. DWORD CpuDisableNoFlags = FALSE;
  48. DWORD CpuDisableEbpAlign = FALSE;
  49. DWORD CpuSniffWritableCode = FALSE;
  50. #define IsPowerOfTwo(x) (((x) & ((x)-1)) == 0)
  51. VOID
  52. GetConfigurationData(
  53. VOID
  54. )
  55. /*++
  56. Routine Description:
  57. Overrides any variable(s) listed above with values from the Registry.
  58. Arguments:
  59. None
  60. Return Value:
  61. None
  62. --*/
  63. {
  64. PCONFIGVAR pcfg;
  65. pcfg = Wx86FetchConfigVar(STR_CACHE_RESERVE);
  66. if (pcfg) {
  67. if (pcfg->Data < MAX_PROLOG_SIZE) {
  68. CpuCacheReserve = MAX_PROLOG_SIZE;
  69. LOGPRINT((TRACELOG, szBadVarMsg, STR_CACHE_RESERVE, CpuCacheReserve));
  70. } else {
  71. CpuCacheReserve = pcfg->Data;
  72. }
  73. Wx86FreeConfigVar(pcfg);
  74. }
  75. pcfg = Wx86FetchConfigVar(STR_CACHE_COMMIT);
  76. if (pcfg) {
  77. if (pcfg->Data < MAX_PROLOG_SIZE) {
  78. CpuCacheCommit = MAX_PROLOG_SIZE;
  79. LOGPRINT((TRACELOG, szBadVarMsg, STR_CACHE_COMMIT, CpuCacheCommit));
  80. } else {
  81. CpuCacheCommit = pcfg->Data;
  82. }
  83. Wx86FreeConfigVar(pcfg);
  84. }
  85. if (CpuCacheCommit > CpuCacheReserve) {
  86. CpuCacheCommit = CpuCacheReserve;
  87. LOGPRINT((TRACELOG, szBadVarMsg, STR_CACHE_COMMIT, CpuCacheCommit));
  88. }
  89. pcfg = Wx86FetchConfigVar(STR_CACHE_GROW_TICKS);
  90. if (pcfg) {
  91. CpuCacheGrowTicks = pcfg->Data;
  92. Wx86FreeConfigVar(pcfg);
  93. }
  94. pcfg = Wx86FetchConfigVar(STR_CACHE_SHRINK_TICKS);
  95. if (pcfg) {
  96. CpuCacheShrinkTicks = pcfg->Data;
  97. Wx86FreeConfigVar(pcfg);
  98. }
  99. if (CpuCacheShrinkTicks < CpuCacheGrowTicks) {
  100. CpuCacheShrinkTicks = CpuCacheGrowTicks;
  101. LOGPRINT((TRACELOG, szBadVarMsg, STR_CACHE_SHRINK_TICKS, CpuCacheGrowTicks));
  102. }
  103. pcfg = Wx86FetchConfigVar(STR_CACHE_CHUNKMIN);
  104. if (pcfg) {
  105. if (!IsPowerOfTwo(pcfg->Data) ||
  106. pcfg->Data < MAX_PROLOG_SIZE ||
  107. pcfg->Data > CpuCacheReserve) {
  108. LOGPRINT((TRACELOG, szBadVarMsg, STR_CACHE_CHUNKMIN, CpuCacheChunkMin));
  109. } else {
  110. CpuCacheChunkMin = pcfg->Data;
  111. }
  112. Wx86FreeConfigVar(pcfg);
  113. }
  114. pcfg = Wx86FetchConfigVar(STR_CACHE_CHUNKMAX);
  115. if (pcfg) {
  116. if (!IsPowerOfTwo(pcfg->Data)) {
  117. LOGPRINT((TRACELOG, szBadVarMsg, STR_CACHE_CHUNKMAX, CpuCacheChunkMax));
  118. } else {
  119. CpuCacheChunkMax = pcfg->Data;
  120. }
  121. Wx86FreeConfigVar(pcfg);
  122. }
  123. if (CpuCacheChunkMax < CpuCacheChunkMin) {
  124. CpuCacheChunkMax = CpuCacheChunkMin;
  125. LOGPRINT((TRACELOG, szBadVarMsg, STR_CACHE_CHUNKMAX, CpuCacheChunkMax));
  126. } else if (CpuCacheChunkMax > CpuCacheReserve) {
  127. CpuCacheChunkMax = CpuCacheReserve;
  128. LOGPRINT((TRACELOG, szBadVarMsg, STR_CACHE_CHUNKMAX, CpuCacheChunkMax));
  129. }
  130. pcfg = Wx86FetchConfigVar(STR_CACHE_CHUNKSIZE);
  131. if (pcfg) {
  132. if (!IsPowerOfTwo(pcfg->Data)) {
  133. LOGPRINT((TRACELOG, szBadVarMsg, STR_CACHE_CHUNKSIZE, CpuCacheChunkSize));
  134. } else {
  135. CpuCacheChunkSize = pcfg->Data;
  136. }
  137. Wx86FreeConfigVar(pcfg);
  138. }
  139. if (CpuCacheChunkSize < CpuCacheChunkMin) {
  140. CpuCacheChunkSize = CpuCacheChunkMin;
  141. LOGPRINT((TRACELOG, szBadVarMsg, STR_CACHE_CHUNKSIZE, CpuCacheChunkSize));
  142. } else if (CpuCacheChunkSize > CpuCacheChunkMax) {
  143. CpuCacheChunkSize = CpuCacheChunkMax;
  144. LOGPRINT((TRACELOG, szBadVarMsg, STR_CACHE_CHUNKSIZE, CpuCacheChunkSize));
  145. }
  146. pcfg = Wx86FetchConfigVar(STR_MRSW_TIMEOUT);
  147. if (pcfg) {
  148. if (pcfg->Data & 0x80000000) {
  149. //
  150. // Value is negative - use a big negative value to wait forever
  151. //
  152. MrswTimeout.LowPart = 0x00000000;
  153. MrswTimeout.HighPart = 0x80000000;
  154. } else {
  155. //
  156. // Multiply the time in ms by -10000 to convert into a relative
  157. // time usable by NtWaitForSingleObject().
  158. //
  159. MrswTimeout.QuadPart = Int32x32To64(pcfg->Data, -10000);
  160. }
  161. Wx86FreeConfigVar(pcfg);
  162. } else {
  163. //
  164. // Initialize MrswTimeout to be 3 times PEB->CriticalSectionTimeout
  165. //
  166. MrswTimeout.QuadPart = NtCurrentPeb()->CriticalSectionTimeout.QuadPart * 3;
  167. }
  168. pcfg = Wx86FetchConfigVar(STR_COMPILERFLAGS);
  169. if (pcfg) {
  170. if ( (pcfg->Data & (COMPFL_FAST|COMPFL_SLOW)) == (COMPFL_FAST|COMPFL_SLOW)) {
  171. LOGPRINT((TRACELOG, szBadVarMsg, STR_COMPILERFLAGS, CompilerFlags));
  172. } else {
  173. CompilerFlags = pcfg->Data;
  174. }
  175. Wx86FreeConfigVar(pcfg);
  176. }
  177. pcfg = Wx86FetchConfigVar(STR_USEWINPXEM);
  178. if (pcfg) {
  179. fUseNPXEM = pcfg->Data;
  180. Wx86FreeConfigVar(pcfg);
  181. }
  182. pcfg = Wx86FetchConfigVar(STR_CPU_MAX_ALLOC_RETRIES);
  183. if (pcfg) {
  184. CpuMaxAllocRetries = pcfg->Data;
  185. Wx86FreeConfigVar(pcfg);
  186. }
  187. pcfg = Wx86FetchConfigVar(STR_CPU_WAIT_FOR_MEMORY_TIME);
  188. if (pcfg) {
  189. CpuWaitForMemoryTime = pcfg->Data;
  190. Wx86FreeConfigVar(pcfg);
  191. }
  192. pcfg = Wx86FetchConfigVar(STR_CPU_MAX_INSTRUCTIONS);
  193. if (pcfg) {
  194. if (pcfg->Data > MAX_INSTR_COUNT) {
  195. LOGPRINT((TRACELOG, szBadVarMsg, STR_CPU_MAX_INSTRUCTIONS, CpuInstructionLookahead));
  196. } else {
  197. CpuInstructionLookahead = pcfg->Data;
  198. }
  199. Wx86FreeConfigVar(pcfg);
  200. }
  201. pcfg = Wx86FetchConfigVar(STR_CPU_DISABLE_DYNCACHE);
  202. if (pcfg) {
  203. CpuDisableDynamicCache = pcfg->Data;
  204. Wx86FreeConfigVar(pcfg);
  205. }
  206. pcfg = Wx86FetchConfigVar(STR_CPU_DISABLE_REGCACHE);
  207. if (pcfg) {
  208. CpuDisableRegCache = pcfg->Data;
  209. Wx86FreeConfigVar(pcfg);
  210. }
  211. pcfg = Wx86FetchConfigVar(STR_CPU_DISABLE_NOFLAGS);
  212. if (pcfg) {
  213. CpuDisableNoFlags = pcfg->Data;
  214. Wx86FreeConfigVar(pcfg);
  215. }
  216. pcfg = Wx86FetchConfigVar(STR_CPU_DISABLE_EBPALIGN);
  217. if (pcfg) {
  218. CpuDisableEbpAlign = pcfg->Data;
  219. Wx86FreeConfigVar(pcfg);
  220. }
  221. pcfg = Wx86FetchConfigVar(STR_CPU_SNIFF_WRITABLE_CODE);
  222. if (pcfg) {
  223. CpuSniffWritableCode = pcfg->Data;
  224. Wx86FreeConfigVar(pcfg);
  225. }
  226. }