levelMemoryDefinition.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. /*
  2. NetWinder Floating Point Emulator
  3. (c) Rebel.COM, 1998,1999
  4. (c) Philip Blundell, 2001
  5. Direct questions, comments to Scott Bambrough <scottb@netwinder.org>
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. */
  18. #ifndef __FPOPCODE_H__
  19. #define __FPOPCODE_H__
  20. /*
  21. ARM Floating Point Instruction Classes
  22. | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
  23. |c o n d|1 1 0 P|U|u|W|L| Rn |v| Fd |0|0|0|1| o f f s e t | CPDT
  24. |c o n d|1 1 0 P|U|w|W|L| Rn |x| Fd |0|0|1|0| o f f s e t | CPDT (copro 2)
  25. | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
  26. |c o n d|1 1 1 0|a|b|c|d|e| Fn |j| Fd |0|0|0|1|f|g|h|0|i| Fm | CPDO
  27. |c o n d|1 1 1 0|a|b|c|L|e| Fn | Rd |0|0|0|1|f|g|h|1|i| Fm | CPRT
  28. |c o n d|1 1 1 0|a|b|c|1|e| Fn |1|1|1|1|0|0|0|1|f|g|h|1|i| Fm | comparisons
  29. | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
  30. CPDT data transfer instructions
  31. LDF, STF, LFM (copro 2), SFM (copro 2)
  32. CPDO dyadic arithmetic instructions
  33. ADF, MUF, SUF, RSF, DVF, RDF,
  34. POW, RPW, RMF, FML, FDV, FRD, POL
  35. CPDO monadic arithmetic instructions
  36. MVF, MNF, ABS, RND, SQT, LOG, LGN, EXP,
  37. SIN, COS, TAN, ASN, ACS, ATN, URD, NRM
  38. CPRT joint arithmetic/data transfer instructions
  39. FIX (arithmetic followed by load/store)
  40. FLT (load/store followed by arithmetic)
  41. CMF, CNF CMFE, CNFE (comparisons)
  42. WFS, RFS (write/read floating point status register)
  43. WFC, RFC (write/read floating point control register)
  44. cond condition codes
  45. P pre/post index bit: 0 = postindex, 1 = preindex
  46. U up/down bit: 0 = stack grows down, 1 = stack grows up
  47. W write back bit: 1 = update base register (Rn)
  48. L load/store bit: 0 = store, 1 = load
  49. Rn base register
  50. Rd destination/source register
  51. Fd floating point destination register
  52. Fn floating point source register
  53. Fm floating point source register or floating point constant
  54. uv transfer length (TABLE 1)
  55. wx register count (TABLE 2)
  56. abcd arithmetic opcode (TABLES 3 & 4)
  57. ef destination size (rounding precision) (TABLE 5)
  58. gh rounding mode (TABLE 6)
  59. j dyadic/monadic bit: 0 = dyadic, 1 = monadic
  60. i constant bit: 1 = constant (TABLE 6)
  61. */
  62. /*
  63. TABLE 1
  64. +-------------------------+---+---+---------+---------+
  65. | Precision | u | v | FPSR.EP | length |
  66. +-------------------------+---+---+---------+---------+
  67. | Single | 0 | 0 | x | 1 words |
  68. | Double | 1 | 1 | x | 2 words |
  69. | Extended | 1 | 1 | x | 3 words |
  70. | Packed decimal | 1 | 1 | 0 | 3 words |
  71. | Expanded packed decimal | 1 | 1 | 1 | 4 words |
  72. +-------------------------+---+---+---------+---------+
  73. Note: x = don't care
  74. */
  75. /*
  76. TABLE 2
  77. +---+---+---------------------------------+
  78. | w | x | Number of registers to transfer |
  79. +---+---+---------------------------------+
  80. | 0 | 1 | 1 |
  81. | 1 | 0 | 2 |
  82. | 1 | 1 | 3 |
  83. | 0 | 0 | 4 |
  84. +---+---+---------------------------------+
  85. */
  86. /*
  87. TABLE 3: Dyadic Floating Point Opcodes
  88. +---+---+---+---+----------+-----------------------+-----------------------+
  89. | a | b | c | d | Mnemonic | Description | Operation |
  90. +---+---+---+---+----------+-----------------------+-----------------------+
  91. | 0 | 0 | 0 | 0 | ADF | Add | Fd := Fn + Fm |
  92. | 0 | 0 | 0 | 1 | MUF | Multiply | Fd := Fn * Fm |
  93. | 0 | 0 | 1 | 0 | SUF | Subtract | Fd := Fn - Fm |
  94. | 0 | 0 | 1 | 1 | RSF | Reverse subtract | Fd := Fm - Fn |
  95. | 0 | 1 | 0 | 0 | DVF | Divide | Fd := Fn / Fm |
  96. | 0 | 1 | 0 | 1 | RDF | Reverse divide | Fd := Fm / Fn |
  97. | 0 | 1 | 1 | 0 | POW | Power | Fd := Fn ^ Fm |
  98. | 0 | 1 | 1 | 1 | RPW | Reverse power | Fd := Fm ^ Fn |
  99. | 1 | 0 | 0 | 0 | RMF | Remainder | Fd := IEEE rem(Fn/Fm) |
  100. | 1 | 0 | 0 | 1 | FML | Fast Multiply | Fd := Fn * Fm |
  101. | 1 | 0 | 1 | 0 | FDV | Fast Divide | Fd := Fn / Fm |
  102. | 1 | 0 | 1 | 1 | FRD | Fast reverse divide | Fd := Fm / Fn |
  103. | 1 | 1 | 0 | 0 | POL | Polar angle (ArcTan2) | Fd := arctan2(Fn,Fm) |
  104. | 1 | 1 | 0 | 1 | | undefined instruction | trap |
  105. | 1 | 1 | 1 | 0 | | undefined instruction | trap |
  106. | 1 | 1 | 1 | 1 | | undefined instruction | trap |
  107. +---+---+---+---+----------+-----------------------+-----------------------+
  108. Note: POW, RPW, POL are deprecated, and are available for backwards
  109. compatibility only.
  110. */
  111. /*
  112. TABLE 4: Monadic Floating Point Opcodes
  113. +---+---+---+---+----------+-----------------------+-----------------------+
  114. | a | b | c | d | Mnemonic | Description | Operation |
  115. +---+---+---+---+----------+-----------------------+-----------------------+
  116. | 0 | 0 | 0 | 0 | MVF | Move | Fd := Fm |
  117. | 0 | 0 | 0 | 1 | MNF | Move negated | Fd := - Fm |
  118. | 0 | 0 | 1 | 0 | ABS | Absolute value | Fd := abs(Fm) |
  119. | 0 | 0 | 1 | 1 | RND | Round to integer | Fd := int(Fm) |
  120. | 0 | 1 | 0 | 0 | SQT | Square root | Fd := sqrt(Fm) |
  121. | 0 | 1 | 0 | 1 | LOG | Log base 10 | Fd := log10(Fm) |
  122. | 0 | 1 | 1 | 0 | LGN | Log base e | Fd := ln(Fm) |
  123. | 0 | 1 | 1 | 1 | EXP | Exponent | Fd := e ^ Fm |
  124. | 1 | 0 | 0 | 0 | SIN | Sine | Fd := sin(Fm) |
  125. | 1 | 0 | 0 | 1 | COS | Cosine | Fd := cos(Fm) |
  126. | 1 | 0 | 1 | 0 | TAN | Tangent | Fd := tan(Fm) |
  127. | 1 | 0 | 1 | 1 | ASN | Arc Sine | Fd := arcsin(Fm) |
  128. | 1 | 1 | 0 | 0 | ACS | Arc Cosine | Fd := arccos(Fm) |
  129. | 1 | 1 | 0 | 1 | ATN | Arc Tangent | Fd := arctan(Fm) |
  130. | 1 | 1 | 1 | 0 | URD | Unnormalized round | Fd := int(Fm) |
  131. | 1 | 1 | 1 | 1 | NRM | Normalize | Fd := norm(Fm) |
  132. +---+---+---+---+----------+-----------------------+-----------------------+
  133. Note: LOG, LGN, EXP, SIN, COS, TAN, ASN, ACS, ATN are deprecated, and are
  134. available for backwards compatibility only.
  135. */
  136. /*
  137. TABLE 5
  138. +-------------------------+---+---+
  139. | Rounding Precision | e | f |
  140. +-------------------------+---+---+
  141. | IEEE Single precision | 0 | 0 |
  142. | IEEE Double precision | 0 | 1 |
  143. | IEEE Extended precision | 1 | 0 |
  144. | undefined (trap) | 1 | 1 |
  145. +-------------------------+---+---+
  146. */
  147. /*
  148. TABLE 5
  149. +---------------------------------+---+---+
  150. | Rounding Mode | g | h |
  151. +---------------------------------+---+---+
  152. | Round to nearest (default) | 0 | 0 |
  153. | Round toward plus infinity | 0 | 1 |
  154. | Round toward negative infinity | 1 | 0 |
  155. | Round toward zero | 1 | 1 |
  156. +---------------------------------+---+---+
  157. */
  158. /*
  159. ===
  160. === Definitions for load and store instructions
  161. ===
  162. */
  163. /* bit masks */
  164. #define BIT_PREINDEX 0x01000000
  165. #define BIT_UP 0x00800000
  166. #define BIT_WRITE_BACK 0x00200000
  167. #define BIT_LOAD 0x00100000
  168. /* masks for load/store */
  169. #define MASK_CPDT 0x0c000000 /* data processing opcode */
  170. #define MASK_OFFSET 0x000000ff
  171. #define MASK_TRANSFER_LENGTH 0x00408000
  172. #define MASK_REGISTER_COUNT MASK_TRANSFER_LENGTH
  173. #define MASK_COPROCESSOR 0x00000f00
  174. /* Tests for transfer length */
  175. #define TRANSFER_SINGLE 0x00000000
  176. #define TRANSFER_DOUBLE 0x00008000
  177. #define TRANSFER_EXTENDED 0x00400000
  178. #define TRANSFER_PACKED MASK_TRANSFER_LENGTH
  179. /* Get the coprocessor number from the opcode. */
  180. #define getCoprocessorNumber(opcode) ((opcode & MASK_COPROCESSOR) >> 8)
  181. /* Get the offset from the opcode. */
  182. #define getOffset(opcode) (opcode & MASK_OFFSET)
  183. /* Tests for specific data transfer load/store opcodes. */
  184. #define TEST_OPCODE(opcode,mask) (((opcode) & (mask)) == (mask))
  185. #define LOAD_OP(opcode) TEST_OPCODE((opcode),MASK_CPDT | BIT_LOAD)
  186. #define STORE_OP(opcode) ((opcode & (MASK_CPDT | BIT_LOAD)) == MASK_CPDT)
  187. #define LDF_OP(opcode) (LOAD_OP(opcode) && (getCoprocessorNumber(opcode) == 1))
  188. #define LFM_OP(opcode) (LOAD_OP(opcode) && (getCoprocessorNumber(opcode) == 2))
  189. #define STF_OP(opcode) (STORE_OP(opcode) && (getCoprocessorNumber(opcode) == 1))
  190. #define SFM_OP(opcode) (STORE_OP(opcode) && (getCoprocessorNumber(opcode) == 2))
  191. #define PREINDEXED(opcode) ((opcode & BIT_PREINDEX) != 0)
  192. #define POSTINDEXED(opcode) ((opcode & BIT_PREINDEX) == 0)
  193. #define BIT_UP_SET(opcode) ((opcode & BIT_UP) != 0)
  194. #define BIT_UP_CLEAR(opcode) ((opcode & BIT_DOWN) == 0)
  195. #define WRITE_BACK(opcode) ((opcode & BIT_WRITE_BACK) != 0)
  196. #define LOAD(opcode) ((opcode & BIT_LOAD) != 0)
  197. #define STORE(opcode) ((opcode & BIT_LOAD) == 0)
  198. /*
  199. ===
  200. === Definitions for arithmetic instructions
  201. ===
  202. */
  203. /* bit masks */
  204. #define BIT_MONADIC 0x00008000
  205. #define BIT_CONSTANT 0x00000008
  206. #define CONSTANT_FM(opcode) ((opcode & BIT_CONSTANT) != 0)
  207. #define MONADIC_INSTRUCTION(opcode) ((opcode & BIT_MONADIC) != 0)
  208. /* instruction identification masks */
  209. #define MASK_CPDO 0x0e000000 /* arithmetic opcode */
  210. #define MASK_ARITHMETIC_OPCODE 0x00f08000
  211. #define MASK_DESTINATION_SIZE 0x00080080
  212. /* dyadic arithmetic opcodes. */
  213. #define ADF_CODE 0x00000000
  214. #define MUF_CODE 0x00100000
  215. #define SUF_CODE 0x00200000
  216. #define RSF_CODE 0x00300000
  217. #define DVF_CODE 0x00400000
  218. #define RDF_CODE 0x00500000
  219. #define POW_CODE 0x00600000
  220. #define RPW_CODE 0x00700000
  221. #define RMF_CODE 0x00800000
  222. #define FML_CODE 0x00900000
  223. #define FDV_CODE 0x00a00000
  224. #define FRD_CODE 0x00b00000
  225. #define POL_CODE 0x00c00000
  226. /* 0x00d00000 is an invalid dyadic arithmetic opcode */
  227. /* 0x00e00000 is an invalid dyadic arithmetic opcode */
  228. /* 0x00f00000 is an invalid dyadic arithmetic opcode */
  229. /* monadic arithmetic opcodes. */
  230. #define MVF_CODE 0x00008000
  231. #define MNF_CODE 0x00108000
  232. #define ABS_CODE 0x00208000
  233. #define RND_CODE 0x00308000
  234. #define SQT_CODE 0x00408000
  235. #define LOG_CODE 0x00508000
  236. #define LGN_CODE 0x00608000
  237. #define EXP_CODE 0x00708000
  238. #define SIN_CODE 0x00808000
  239. #define COS_CODE 0x00908000
  240. #define TAN_CODE 0x00a08000
  241. #define ASN_CODE 0x00b08000
  242. #define ACS_CODE 0x00c08000
  243. #define ATN_CODE 0x00d08000
  244. #define URD_CODE 0x00e08000
  245. #define NRM_CODE 0x00f08000