Leaked source code of windows server 2003
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.

501 lines
14 KiB

  1. /*++ BUILD Version: 0001 // Increment this if a change has global effects
  2. Copyright (c) 1993-1997 Microsoft Corporation
  3. Module Name:
  4. arminst.h
  5. Abstract:
  6. ARM instruction definitions.
  7. Author:
  8. Janet Schneider 31-March-1997
  9. Revision History:
  10. --*/
  11. #ifndef _ARMINST_
  12. #define _ARMINST_
  13. //
  14. // Define ARM instruction format structures.
  15. //
  16. #define COND_EQ 0x00000000L // Z set
  17. #define COND_NE 0x10000000L // Z clear
  18. #define COND_CS 0x20000000L // C set // aka HS
  19. #define COND_CC 0x30000000L // C clear // aka LO
  20. #define COND_MI 0x40000000L // N set
  21. #define COND_PL 0x50000000L // N clear
  22. #define COND_VS 0x60000000L // V set
  23. #define COND_VC 0x70000000L // V clear
  24. #define COND_HI 0x80000000L // C set and Z clear
  25. #define COND_LS 0x90000000L // C clear or Z set
  26. #define COND_GE 0xa0000000L // N == V
  27. #define COND_LT 0xb0000000L // N != V
  28. #define COND_GT 0xc0000000L // Z clear, and N == V
  29. #define COND_LE 0xd0000000L // Z set, and N != V
  30. #define COND_AL 0xe0000000L // Always execute
  31. #define COND_NV 0xf0000000L // Never - undefined
  32. #define COND_MASK COND_NV
  33. #define COND_SHIFT 28
  34. #define OP_AND 0x0 // 0000
  35. #define OP_EOR 0x1 // 0001
  36. #define OP_SUB 0x2 // 0010
  37. #define OP_RSB 0x3 // 0011
  38. #define OP_ADD 0x4 // 0100
  39. #define OP_ADC 0x5 // 0101
  40. #define OP_SBC 0x6 // 0110
  41. #define OP_RSC 0x7 // 0111
  42. #define OP_TST 0x8 // 1000
  43. #define OP_TEQ 0x9 // 1001
  44. #define OP_CMP 0xa // 1010
  45. #define OP_CMN 0xb // 1011
  46. #define OP_ORR 0xc // 1100
  47. #define OP_MOV 0xd // 1101
  48. #define OP_BIC 0xe // 1110
  49. #define OP_MVN 0xf // 1111
  50. #define MOV_PC_LR_MASK 0x0de0f00eL // All types of mov - i, is, rs
  51. #define MOV_PC_LR 0x01a0f00eL
  52. #define MOV_PC_X_MASK 0x0de0f000L
  53. #define MOV_PC_X 0x01a0f000L
  54. #define DATA_PROC_MASK 0x0c00f000L
  55. #define DP_PC_INSTR 0x0000f000L // Data process instr w/PC as destination
  56. #define DP_R11_INSTR 0x0000b000L // Data process instr w/R11 as destination
  57. #define ADD_SP_MASK 0x0de0f000L
  58. #define ADD_SP_INSTR 0x0080d000L // Add instr with SP as destination
  59. #define SUB_SP_MASK 0x0de0f000L
  60. #define SUB_SP_INSTR 0x0040d000L // Sub instr with SP as destination
  61. #define BX_MASK 0x0ffffff0L // Branch and exchange instr sets
  62. #define BX_INSTR 0x012fff10L // return (LR) or call (Rn != LR)
  63. #define LDM_PC_MASK 0x0e108000L
  64. #define LDM_PC_INSTR 0x08108000L // Load multiple with PC bit set
  65. #define LDM_LR_MASK 0x0e104000L
  66. #define LDM_LR_INSTR 0x08104000L // Load multiple with LR bit set
  67. #define STRI_LR_SPU_MASK 0x073de000L // Load or Store of LR with stack update
  68. #define STRI_LR_SPU_INSTR 0x052de000L // Store LR (with immediate offset, update SP)
  69. #define STM_MASK 0x0e100000L
  70. #define STM_INSTR 0x08000000L // Store multiple instruction
  71. #define B_BL_MASK 0x0f000000L // Regular branches
  72. #define B_INSTR 0x0a000000L
  73. #define BL_INSTR 0x0b000000L
  74. #define LDR_MASK 0x0f3ff000L
  75. #define LDR_PC_INSTR 0x051fc000L // Load an address from PC + offset to R12
  76. #define LDR_THUNK_1 0xe59fc000L // ldr r12, [pc]
  77. #define LDR_THUNK_2 0xe59cf000L // ldr pc, [r12]
  78. typedef union _ARMI {
  79. struct {
  80. ULONG operand2 : 12;
  81. ULONG rd : 4;
  82. ULONG rn : 4;
  83. ULONG s : 1;
  84. ULONG opcode : 4;
  85. ULONG bits : 3; // Specifies immediate (001) or register (000)
  86. ULONG cond : 4;
  87. } dataproc; // Data processing, PSR transfer
  88. struct {
  89. //
  90. // Type 1 - Immediate
  91. //
  92. ULONG immediate : 8;
  93. ULONG rotate : 4;
  94. ULONG dpbits : 20;
  95. } dpi;
  96. struct {
  97. //
  98. // Form: Shift or rotate by immediate
  99. //
  100. // Type bits Name
  101. //
  102. // 2 (000) Register (Shift is 0)
  103. // 3 (000) Logical shift left by immediate
  104. // 5 (010) Logical shift right by immediate
  105. // 7 (100) Arithmetic shift right by immediate
  106. // 9 (110) Rotate right by immediate
  107. //
  108. ULONG rm : 4;
  109. ULONG bits : 3;
  110. ULONG shift : 5;
  111. ULONG dpbits : 20;
  112. } dpshi;
  113. struct {
  114. //
  115. // Form: Shift or rotate by register
  116. //
  117. // Type bits Name
  118. // 4 (0001) Logical shift left by register
  119. // 6 (0011) Logical shift right by register
  120. // 8 (0101) Arithmetic shift right by register
  121. // 10 (0111) Rotate right by register
  122. //
  123. ULONG rm : 4;
  124. ULONG bits : 4;
  125. ULONG rs : 4;
  126. ULONG dpbits : 20;
  127. } dpshr;
  128. struct {
  129. //
  130. // Type 11 - Rotate right with extended
  131. //
  132. ULONG rm : 4;
  133. ULONG bits : 8; // (00000110)
  134. ULONG dpbits : 20;
  135. } dprre;
  136. struct {
  137. ULONG bits1 : 12; // (000000000000)
  138. ULONG rd : 4;
  139. ULONG bits2 : 6; // (001111)
  140. ULONG ps : 1; // spsr = 1, cpsr = 0
  141. ULONG bits3 : 5; // (00010)
  142. ULONG cond : 4;
  143. } dpmrs;
  144. struct {
  145. ULONG operand : 12;
  146. ULONG bits1 : 4; // (1111)
  147. ULONG fc : 1; // control fields = 1
  148. ULONG fx : 1; // extension fields = 1
  149. ULONG fs : 1; // status fields = 1
  150. ULONG ff : 1; // flags fields = 1
  151. ULONG bits2 : 2; // (10)
  152. ULONG pd : 1; // spsr = 1, cpsr = 0
  153. ULONG bits3 : 2; // (10)
  154. ULONG i : 1; // immedate = 1, register = 0
  155. ULONG bits4 : 2; // (00)
  156. ULONG cond : 4;
  157. } dpmsr;
  158. struct {
  159. ULONG rm : 4;
  160. ULONG bits1 : 8; // (00001001)
  161. ULONG rd : 4;
  162. ULONG rn : 4;
  163. ULONG bits2 : 2; // (00)
  164. ULONG b : 1;
  165. ULONG bits3 : 5; // (00010)
  166. ULONG cond : 4;
  167. } swp; // Swap instructions
  168. struct {
  169. ULONG rm : 4;
  170. ULONG bits1 : 4; // (1001)
  171. ULONG rs : 4;
  172. ULONG rn : 4;
  173. ULONG rd : 4;
  174. ULONG s : 1;
  175. ULONG a : 1;
  176. ULONG sgn : 1;
  177. ULONG lng : 1;
  178. ULONG bits2 : 4; // (0000)
  179. ULONG cond : 4;
  180. } mul; // Multiply and multiply-accumulate
  181. struct {
  182. ULONG rn : 4;
  183. ULONG bits : 24;
  184. ULONG cond : 4;
  185. } bx; // Branch and exchange instruction sets
  186. struct {
  187. ULONG offset : 24;
  188. ULONG h : 1;
  189. ULONG bits : 7; // (1111101)
  190. } blxi; // blx immediate
  191. struct {
  192. ULONG immed1 : 4;
  193. ULONG bits1 : 4; // (0111)
  194. ULONG immed2 : 12;
  195. ULONG bits2 : 12; // (111000010010)
  196. } bkpt;
  197. struct {
  198. ULONG any1 : 4;
  199. ULONG bits1 : 1; // (1)
  200. ULONG any2 : 20;
  201. ULONG bits2 : 3; // (011)
  202. ULONG cond : 4;
  203. } ud; // Undefined instruction
  204. struct {
  205. ULONG operand1 : 4;
  206. ULONG bits1 : 1; // (1)
  207. ULONG h : 1; // halfword = 1, byte = 0
  208. ULONG s : 1; // signed = 1, unsigned = 0
  209. ULONG bits2 : 1; // (1)
  210. ULONG operand2 : 4;
  211. ULONG rd : 4;
  212. ULONG rn : 4;
  213. ULONG l : 1; // load = 1, store = 0
  214. ULONG w : 1; // update base register bit
  215. ULONG i : 1; // immediate = 1, register = 0
  216. ULONG u : 1; // increment = 1, decrement = 0
  217. ULONG p : 1; // pre-indexing = 1, post-indexing = 0
  218. ULONG bits3 : 3; // (000)
  219. ULONG cond : 4;
  220. } miscdt; // Misc data transfer
  221. struct {
  222. ULONG offset : 12;
  223. ULONG rd : 4;
  224. ULONG rn : 4;
  225. ULONG l : 1; // load = 1, store = 0
  226. ULONG w : 1; // update base register bit
  227. ULONG b : 1; // unsigned byte = 1, word = 0
  228. ULONG u : 1; // increment = 1, decrement = 0
  229. ULONG p : 1; // pre-indexing = 1, post-indexing = 0
  230. ULONG i : 1; // immediate = 1, register = 0
  231. ULONG bits : 2;
  232. ULONG cond : 4;
  233. } ldr; // Load register
  234. struct {
  235. ULONG reglist : 16;
  236. ULONG rn : 4;
  237. ULONG l : 1; // load = 1, store = 0
  238. ULONG w : 1; // update base register after transfer
  239. ULONG s : 1;
  240. ULONG u : 1; // increment = 1, decrement = 0
  241. ULONG p : 1; // before = 1, after = 0
  242. ULONG bits : 3;
  243. ULONG cond : 4;
  244. } ldm; // Load multiple
  245. struct {
  246. ULONG offset : 24;
  247. ULONG link : 1;
  248. ULONG bits : 3;
  249. ULONG cond : 4;
  250. } bl; // Branch, Branch and link
  251. struct {
  252. ULONG rm : 4;
  253. ULONG bits1 : 8; // (11110001)
  254. ULONG rd : 4;
  255. ULONG bits2 : 12; // (000101101111)
  256. ULONG cond : 4;
  257. } clz;
  258. struct {
  259. ULONG crm : 4;
  260. ULONG bits1 : 1; // (0)
  261. ULONG cp : 3;
  262. ULONG cpn : 4;
  263. ULONG crd : 4;
  264. ULONG crn : 4;
  265. ULONG cpop : 4;
  266. ULONG bits2 : 4; // (1110)
  267. ULONG cond : 4;
  268. } cpdo;
  269. struct {
  270. ULONG crm : 4;
  271. ULONG bits1 : 1; // (1)
  272. ULONG cp : 3;
  273. ULONG cpn : 4;
  274. ULONG rd : 4;
  275. ULONG crn : 4;
  276. ULONG l : 1; // load = 1, store = 0
  277. ULONG cpop : 3;
  278. ULONG bits2 : 4; // (1110)
  279. ULONG cond : 4;
  280. } cprt;
  281. struct {
  282. ULONG offset : 8;
  283. ULONG cpn : 4;
  284. ULONG crd : 4;
  285. ULONG rn : 4;
  286. ULONG l : 1; // load = 1, store = 0
  287. ULONG w : 1; // write back = 1, no write back = 0
  288. ULONG n : 1; // long = 1, short = 0
  289. ULONG u : 1; // up = 1, down = 0
  290. ULONG p : 1; // pre = 1, post = 0
  291. ULONG bits : 3; // (011)
  292. ULONG cond : 4;
  293. } cpdt;
  294. struct {
  295. ULONG crm : 4;
  296. ULONG cpop : 4;
  297. ULONG cpn : 4;
  298. ULONG rd : 4;
  299. ULONG rn : 4;
  300. ULONG bits : 8;
  301. ULONG cond : 4;
  302. } mcrr;
  303. struct {
  304. ULONG rm : 4;
  305. ULONG bits1 : 8; // (00000101)
  306. ULONG rd : 4;
  307. ULONG rn : 4;
  308. ULONG bits2 : 8; // (00010010)
  309. ULONG cond : 4;
  310. } qadd;
  311. struct {
  312. ULONG rm : 4;
  313. ULONG bits1 : 1; // (0)
  314. ULONG x : 1; // T = 1, B = 0
  315. ULONG y : 1; // T = 1, B = 0
  316. ULONG bits2 : 1; // (1)
  317. ULONG rs : 4;
  318. ULONG rn : 4;
  319. ULONG rd : 4;
  320. ULONG bits3 : 8; // (00010000)
  321. ULONG cond : 4;
  322. } smla;
  323. struct {
  324. ULONG rm : 4;
  325. ULONG bits1 : 1; // (0)
  326. ULONG x : 1; // T = 1, B = 0
  327. ULONG y : 1; // T = 1, B = 0
  328. ULONG bits2 : 1; // (1)
  329. ULONG rs : 4;
  330. ULONG rdlo : 4;
  331. ULONG rdhi : 4;
  332. ULONG bits3 : 8; // (00010000)
  333. ULONG cond : 4;
  334. } smlal;
  335. struct {
  336. ULONG rm : 4;
  337. ULONG bits1 : 1; // (0)
  338. ULONG x : 1; // T = 1, B = 0
  339. ULONG y : 1; // T = 1, B = 0
  340. ULONG bits2 : 1; // (1)
  341. ULONG rs : 4;
  342. ULONG bits3 : 4; // (0000)
  343. ULONG rd : 4;
  344. ULONG bits4 : 8; // (00010010)
  345. ULONG cond : 4;
  346. } smul;
  347. struct {
  348. ULONG comment : 24;
  349. ULONG bits : 4; // (1111)
  350. ULONG cond : 4;
  351. } swi;
  352. ULONG instruction;
  353. } ARMI, *PARMI;
  354. // Thumb instruction descriptions follow.
  355. #define THUMB_B_COND_MASK 0xf000
  356. #define THUMB_B_COND_INSTR 0xd000
  357. #define THUMB_B_MASK 0xf800
  358. #define THUMB_B_INSTR 0xe000
  359. #define THUMB_BL_MASK 0xf000
  360. #define THUMB_BL_INSTR 0xf000
  361. #define THUMB_BX_MASK 0xff80
  362. #define THUMB_BX_INSTR 0x4700
  363. #define THUMB_ADD_HI_MASK 0xff00
  364. #define THUMB_ADD_HI_INSTR 0x4400
  365. #define THUMB_MOV_HI_MASK 0xff00
  366. #define THUMB_MOV_HI_INSTR 0x4600
  367. #define THUMB_POP_MASK 0xfe00
  368. #define THUMB_POP_INSTR 0xbc00
  369. typedef union _THUMBI {
  370. struct {
  371. USHORT reg_list:8;
  372. USHORT pc:1; // pc==1 -> pop pc from list
  373. USHORT Op:7;
  374. USHORT Next:16;
  375. } pop_instr;
  376. struct {
  377. USHORT reg_list:8;
  378. USHORT lr:1; // lr==1 -> push lr to list
  379. USHORT Op:7;
  380. USHORT Next:16;
  381. } push_instr;
  382. struct {
  383. USHORT target:8; // sign-extend
  384. USHORT cond:4;
  385. USHORT Op:4;
  386. USHORT Next:16;
  387. } b_cond_instr;
  388. struct {
  389. USHORT target:11; // sign-extend
  390. USHORT op:5;
  391. USHORT Next:16;
  392. } b_instr;
  393. struct {
  394. USHORT SBZ:3;
  395. USHORT Rm:3;
  396. USHORT hi_reg:1; // hi_reg==1 -> use high register for Rm
  397. USHORT op:9;
  398. USHORT Next:16;
  399. } bx_instr;
  400. struct {
  401. USHORT target22_12:11; // will not be sign-extended
  402. USHORT not_the_prefix:1; // should be 0: is the prefix
  403. USHORT prefix_op:4;
  404. USHORT target11_1:11; // will be sign-extended
  405. USHORT not_the_prefix2:1; // should be 1: not the prefix
  406. USHORT main_op:4;
  407. } bl_instr;
  408. struct {
  409. USHORT Rd:3;
  410. USHORT Rm:3;
  411. USHORT hi_m:1; // Rm is high register
  412. USHORT hi_d:1; // Rd is high register
  413. USHORT func:2; // 00->AddHi, 01->CmpHi, 10->MovHi, 11->Bx
  414. USHORT op:6; // 010001 = 0x11
  415. USHORT Next:16;
  416. } spx_dp_instr;
  417. struct {
  418. USHORT imm:8;
  419. USHORT Rd:3;
  420. USHORT sp:1; // 0-> rd = pc+imm, 1-> rd=sp+imm.
  421. USHORT op:4;
  422. USHORT Next:16;
  423. } add_sp_pc_instr;
  424. struct {
  425. USHORT imm:7;
  426. USHORT op:9;
  427. USHORT Next:16;
  428. } incr_sp_instr;
  429. ULONG instruction;
  430. } THUMB_INSTRUCTION, *PTHUMB_INSTRUCTION;
  431. #endif // _ARMINST_