const.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. #pragma once
  2. #define FLAG_CARRY 1
  3. #define FLAG_PARITY 4
  4. #define FLAG_ADJUST 16
  5. #define FLAG_ZERO 64
  6. #define FLAG_SIGN 128
  7. #define FLAG_TRAP 256
  8. #define FLAG_INTERRUPT 512
  9. #define FLAG_DIRECTION 1024
  10. #define FLAG_OVERFLOW 2048
  11. #define FLAG_IOPL (1 << 12 | 1 << 13)
  12. #define FLAG_NT (1 << 14)
  13. #define FLAG_RF (1 << 16)
  14. #define FLAG_VM (1 << 17)
  15. #define FLAG_AC (1 << 18)
  16. #define FLAG_VIF (1 << 19)
  17. #define FLAG_VIP (1 << 20)
  18. #define FLAG_ID (1 << 21)
  19. #define FLAGS_DEFAULT (1 << 1)
  20. #define FLAGS_MASK ( \
  21. FLAG_CARRY | FLAG_PARITY | FLAG_ADJUST | FLAG_ZERO | FLAG_SIGN | FLAG_TRAP | FLAG_INTERRUPT | \
  22. FLAG_DIRECTION | FLAG_OVERFLOW | FLAG_IOPL | FLAG_NT | FLAG_RF | FLAG_VM | FLAG_AC | \
  23. FLAG_VIF | FLAG_VIP | FLAG_ID)
  24. #define FLAGS_ALL (FLAG_CARRY | FLAG_PARITY | FLAG_ADJUST | FLAG_ZERO | FLAG_SIGN | FLAG_OVERFLOW)
  25. #define OPSIZE_8 7
  26. #define OPSIZE_16 15
  27. #define OPSIZE_32 31
  28. #define EAX 0
  29. #define ECX 1
  30. #define EDX 2
  31. #define EBX 3
  32. #define ESP 4
  33. #define EBP 5
  34. #define ESI 6
  35. #define EDI 7
  36. #define AX 0
  37. #define CX 2
  38. #define DX 4
  39. #define BX 6
  40. #define SP 8
  41. #define BP 10
  42. #define SI 12
  43. #define DI 14
  44. #define AL 0
  45. #define CL 4
  46. #define DL 8
  47. #define BL 12
  48. #define AH 1
  49. #define CH 5
  50. #define DH 9
  51. #define BH 13
  52. #define ES 0
  53. #define CS 1
  54. #define SS 2
  55. #define DS 3
  56. #define FS 4
  57. #define GS 5
  58. #define TR 6
  59. #define LDTR 7
  60. #define PSE_ENABLED 128
  61. #define PAGE_TABLE_PRESENT_MASK (1 << 0)
  62. #define PAGE_TABLE_RW_MASK (1 << 1)
  63. #define PAGE_TABLE_USER_MASK (1 << 2)
  64. #define PAGE_TABLE_ACCESSED_MASK (1 << 5)
  65. #define PAGE_TABLE_DIRTY_MASK (1 << 6)
  66. #define PAGE_TABLE_PSE_MASK (1 << 7)
  67. #define PAGE_TABLE_GLOBAL_MASK (1 << 8)
  68. #define MMAP_BLOCK_BITS 17
  69. #define MMAP_BLOCK_SIZE = (1 << MMAP_BLOCK_BITS)
  70. #define CR0_PE 1
  71. #define CR0_MP (1 << 1)
  72. #define CR0_EM (1 << 2)
  73. #define CR0_TS (1 << 3)
  74. #define CR0_ET (1 << 4)
  75. #define CR0_WP (1 << 16)
  76. #define CR0_NW (1 << 29)
  77. #define CR0_CD (1 << 30)
  78. #define CR0_PG (1 << 31)
  79. #define CR4_VME (1)
  80. #define CR4_PVI (1 << 1)
  81. #define CR4_TSD (1 << 2)
  82. #define CR4_PSE (1 << 4)
  83. #define CR4_DE (1 << 3)
  84. #define CR4_PAE (1 << 5)
  85. #define CR4_PGE (1 << 7)
  86. #define IA32_SYSENTER_CS 0x174
  87. #define IA32_SYSENTER_ESP 0x175
  88. #define IA32_SYSENTER_EIP 0x176
  89. #define IA32_TIME_STAMP_COUNTER 0x10
  90. #define IA32_PLATFORM_ID 0x17
  91. #define IA32_APIC_BASE_MSR 0x1B
  92. #define IA32_BIOS_SIGN_ID 0x8B
  93. #define MSR_PLATFORM_INFO 0xCE
  94. #define MSR_MISC_FEATURE_ENABLES 0x140
  95. #define IA32_MISC_ENABLE 0x1A0
  96. #define IA32_RTIT_CTL 0x570
  97. #define MSR_SMI_COUNT 0x34
  98. #define IA32_MCG_CAP 0x179
  99. #define IA32_KERNEL_GS_BASE 0xC0000101
  100. #define MSR_PKG_C2_RESIDENCY 0x60D
  101. #define IA32_APIC_BASE_BSP (1 << 8)
  102. #define IA32_APIC_BASE_EXTD (1 << 10)
  103. #define IA32_APIC_BASE_EN (1 << 11)
  104. // Note: Duplicated in apic.js
  105. #define APIC_ADDRESS ((int32_t)0xFEE00000)
  106. // Segment prefixes must not collide with reg_*s variables
  107. // _ZERO is a special zero offset segment
  108. #define SEG_PREFIX_NONE (-1)
  109. #define SEG_PREFIX_ZERO 7
  110. #define PREFIX_MASK_REP 0b11000
  111. #define PREFIX_REPZ 0b01000
  112. #define PREFIX_REPNZ 0b10000
  113. #define PREFIX_MASK_SEGMENT 0b111
  114. #define PREFIX_MASK_OPSIZE 0b100000
  115. #define PREFIX_MASK_ADDRSIZE 0b1000000
  116. // aliases
  117. #define PREFIX_F2 PREFIX_REPNZ
  118. #define PREFIX_F3 PREFIX_REPZ
  119. #define PREFIX_66 PREFIX_MASK_OPSIZE
  120. #define LOG_CPU 0x000002
  121. #define A20_MASK (~(1 << 20))
  122. #define A20_MASK16 (~(1 << (20 - 1)))
  123. #define A20_MASK32 (~(1 << (20 - 2)))
  124. #define MXCSR_MASK (0xFFFF & ~(1 << 6))