const.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. #pragma once
  2. #ifndef DEBUG
  3. #define DEBUG true
  4. #endif
  5. #define FLAG_CARRY 1
  6. #define FLAG_PARITY 4
  7. #define FLAG_ADJUST 16
  8. #define FLAG_ZERO 64
  9. #define FLAG_SIGN 128
  10. #define FLAG_TRAP 256
  11. #define FLAG_INTERRUPT 512
  12. #define FLAG_DIRECTION 1024
  13. #define FLAG_OVERFLOW 2048
  14. #define FLAG_IOPL (1 << 12 | 1 << 13)
  15. #define FLAG_NT (1 << 14)
  16. #define FLAG_RF (1 << 16)
  17. #define FLAG_VM (1 << 17)
  18. #define FLAG_AC (1 << 18)
  19. #define FLAG_VIF (1 << 19)
  20. #define FLAG_VIP (1 << 20)
  21. #define FLAG_ID (1 << 21)
  22. #define FLAGS_DEFAULT (1 << 1)
  23. #define FLAGS_MASK ( \
  24. FLAG_CARRY | FLAG_PARITY | FLAG_ADJUST | FLAG_ZERO | FLAG_SIGN | FLAG_TRAP | FLAG_INTERRUPT | \
  25. FLAG_DIRECTION | FLAG_OVERFLOW | FLAG_IOPL | FLAG_NT | FLAG_RF | FLAG_VM | FLAG_AC | \
  26. FLAG_VIF | FLAG_VIP | FLAG_ID)
  27. #define FLAGS_ALL (FLAG_CARRY | FLAG_PARITY | FLAG_ADJUST | FLAG_ZERO | FLAG_SIGN | FLAG_OVERFLOW)
  28. #define OPSIZE_8 7
  29. #define OPSIZE_16 15
  30. #define OPSIZE_32 31
  31. #define EAX 0
  32. #define ECX 1
  33. #define EDX 2
  34. #define EBX 3
  35. #define ESP 4
  36. #define EBP 5
  37. #define ESI 6
  38. #define EDI 7
  39. #define AX 0
  40. #define CX 2
  41. #define DX 4
  42. #define BX 6
  43. #define SP 8
  44. #define BP 10
  45. #define SI 12
  46. #define DI 14
  47. #define AL 0
  48. #define CL 4
  49. #define DL 8
  50. #define BL 12
  51. #define AH 1
  52. #define CH 5
  53. #define DH 9
  54. #define BH 13
  55. #define ES 0
  56. #define CS 1
  57. #define SS 2
  58. #define DS 3
  59. #define FS 4
  60. #define GS 5
  61. #define TR 6
  62. #define LDTR 7
  63. #define TLB_SYSTEM_READ 1
  64. #define TLB_SYSTEM_WRITE 2
  65. #define TLB_USER_READ 4
  66. #define TLB_USER_WRITE 8
  67. #define PSE_ENABLED 128
  68. #define PAGE_TABLE_PRESENT_MASK (1 << 0)
  69. #define PAGE_TABLE_RW_MASK (1 << 1)
  70. #define PAGE_TABLE_USER_MASK (1 << 2)
  71. #define PAGE_TABLE_ACCESSED_MASK (1 << 5)
  72. #define PAGE_TABLE_DIRTY_MASK (1 << 6)
  73. #define PAGE_TABLE_PSE_MASK (1 << 7)
  74. #define PAGE_TABLE_GLOBAL_MASK (1 << 8)
  75. #define MMAP_BLOCK_BITS 17
  76. #define MMAP_BLOCK_SIZE = (1 << MMAP_BLOCK_BITS)
  77. #define CR0_PE 1
  78. #define CR0_MP (1 << 1)
  79. #define CR0_EM (1 << 2)
  80. #define CR0_TS (1 << 3)
  81. #define CR0_ET (1 << 4)
  82. #define CR0_WP (1 << 16)
  83. #define CR0_NW (1 << 29)
  84. #define CR0_CD (1 << 30)
  85. #define CR0_PG (1 << 31)
  86. #define CR4_VME (1)
  87. #define CR4_PVI (1 << 1)
  88. #define CR4_TSD (1 << 2)
  89. #define CR4_PSE (1 << 4)
  90. #define CR4_DE (1 << 3)
  91. #define CR4_PAE (1 << 5)
  92. #define CR4_PGE (1 << 7)
  93. #define IA32_SYSENTER_CS 0x174
  94. #define IA32_SYSENTER_ESP 0x175
  95. #define IA32_SYSENTER_EIP 0x176
  96. #define IA32_TIME_STAMP_COUNTER 0x10
  97. #define IA32_PLATFORM_ID 0x17
  98. #define IA32_APIC_BASE_MSR 0x1B
  99. #define IA32_BIOS_SIGN_ID 0x8B
  100. #define IA32_MISC_ENABLE 0x1A0
  101. #define IA32_RTIT_CTL 0x570
  102. #define MSR_SMI_COUNT 0x34
  103. #define IA32_MCG_CAP 0x179
  104. #define IA32_KERNEL_GS_BASE 0xC0000101
  105. #define MSR_PKG_C2_RESIDENCY 0x60D
  106. #define IA32_APIC_BASE_BSP (1 << 8)
  107. #define IA32_APIC_BASE_EXTD (1 << 10)
  108. #define IA32_APIC_BASE_EN (1 << 11)
  109. // Note: Duplicated in apic.js
  110. #define APIC_ADDRESS ((int32_t)0xFEE00000)
  111. // Segment prefixes must not collide with reg_*s variables
  112. // _ZERO is a special zero offset segment
  113. #define SEG_PREFIX_NONE (-1)
  114. #define SEG_PREFIX_ZERO 7
  115. #define PREFIX_MASK_REP 0b11000
  116. #define PREFIX_REPZ 0b01000
  117. #define PREFIX_REPNZ 0b10000
  118. #define PREFIX_MASK_SEGMENT 0b111
  119. #define PREFIX_MASK_OPSIZE 0b100000
  120. #define PREFIX_MASK_ADDRSIZE 0b1000000
  121. // aliases
  122. #define PREFIX_F2 PREFIX_REPNZ
  123. #define PREFIX_F3 PREFIX_REPZ
  124. #define PREFIX_66 PREFIX_MASK_OPSIZE
  125. /**
  126. * How many cycles the CPU does at a time before running hardware timers
  127. */
  128. #define LOOP_COUNTER 20011
  129. #define TSC_RATE (50 * 1000)
  130. #define LOG_CPU 0x000002
  131. #define CPU_LOG_VERBOSE false
  132. #define ENABLE_ACPI false
  133. #define A20_MASK (~(1 << 20))
  134. #define A20_MASK16 (~(1 << (20 - 1)))
  135. #define A20_MASK32 (~(1 << (20 - 2)))
  136. #define USE_A20 false
  137. #define MXCSR_MASK (0xFFFF & ~(1 << 6))
  138. #define WASM_TABLE_SIZE 0x10000
  139. // Mask used to map physical address to index in cache array
  140. #define JIT_PHYS_MASK (WASM_TABLE_SIZE - 1)
  141. #define HASH_PRIME 6151
  142. #define JIT_THRESHOLD 2500
  143. #define DIRTY_ARR_SHIFT 12
  144. #define MAX_INSTR_LEN 15
  145. #define MAX_BLOCK_LENGTH ((1 << DIRTY_ARR_SHIFT) - MAX_INSTR_LEN)
  146. #define GROUP_DIRTINESS_LENGTH (1 + (0xffffffff >> DIRTY_ARR_SHIFT))
  147. #define JIT_NEXT_BLOCK_BRANCHED "next_block_branched"
  148. #define JIT_NEXT_BLOCK_NOT_BRANCHED "next_block_not_branched"
  149. #define CHECK_TLB_INVARIANTS 0
  150. #define JIT_NEXT_BLOCK_BRANCHED_IDX 0
  151. #define JIT_NEXT_BLOCK_NOT_BRANCHED_IDX 1
  152. #define JIT_MAX_ITERATIONS_PER_FUNCTION 10000
  153. #define ENABLE_JIT 1
  154. #define ENABLE_JIT_NONFAULTING_OPTIMZATION 1
  155. #ifndef ENABLE_JIT_ALWAYS
  156. #define ENABLE_JIT_ALWAYS 0
  157. #endif
  158. #define ENABLE_PROFILER 0
  159. #define ENABLE_PROFILER_TIMES 0
  160. // Note: needs to be enabled here and in config.js
  161. #define DUMP_UNCOMPILED_ASSEMBLY 0
  162. #define LOG_PAGE_FAULTS 0