fp_scan.S 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478
  1. /*
  2. * fp_scan.S
  3. *
  4. * Copyright Roman Zippel, 1997. All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice, and the entire permission notice in its entirety,
  11. * including the disclaimer of warranties.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. * 3. The name of the author may not be used to endorse or promote
  16. * products derived from this software without specific prior
  17. * written permission.
  18. *
  19. * ALTERNATIVELY, this product may be distributed under the terms of
  20. * the GNU General Public License, in which case the provisions of the GPL are
  21. * required INSTEAD OF the above restrictions. (This clause is
  22. * necessary due to a potential bad interaction between the GPL and
  23. * the restrictions contained in a BSD-style copyright.)
  24. *
  25. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  26. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  27. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  28. * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
  29. * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  30. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  31. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  32. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  33. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  34. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  35. * OF THE POSSIBILITY OF SUCH DAMAGE.
  36. */
  37. #include "fp_emu.h"
  38. #include "fp_decode.h"
  39. .globl fp_scan, fp_datasize
  40. .data
  41. | %d2 - first two instr words
  42. | %d1 - operand size
  43. /* operand formats are:
  44. Long = 0, i.e. fmove.l
  45. Single, i.e. fmove.s
  46. Extended, i.e. fmove.x
  47. Packed-BCD, i.e. fmove.p
  48. Word, i.e. fmove.w
  49. Double, i.e. fmove.d
  50. */
  51. .text
  52. | On entry:
  53. | FPDATA - base of emulated FPU registers
  54. fp_scan:
  55. | normal fpu instruction? (this excludes fsave/frestore)
  56. fp_get_pc %a0
  57. printf PDECODE,"%08x: ",1,%a0
  58. getuser.b (%a0),%d0,fp_err_ua1,%a0
  59. #if 1
  60. cmp.b #0xf2,%d0 | cpid = 1
  61. #else
  62. cmp.b #0xfc,%d0 | cpid = 6
  63. #endif
  64. jne fp_nonstd
  65. | first two instruction words are kept in %d2
  66. getuser.l (%a0)+,%d2,fp_err_ua1,%a0
  67. fp_put_pc %a0
  68. fp_decode_cond: | separate conditional instr
  69. fp_decode_cond_instr_type
  70. .long fp_decode_move, fp_fscc
  71. .long fp_fbccw, fp_fbccl
  72. fp_decode_move: | separate move instr
  73. fp_decode_move_instr_type
  74. .long fp_fgen_fp, fp_ill
  75. .long fp_fgen_ea, fp_fmove_fp2mem
  76. .long fp_fmovem_cr, fp_fmovem_cr
  77. .long fp_fmovem_fp, fp_fmovem_fp
  78. | now all arithmetic instr and a few move instr are left
  79. fp_fgen_fp: | source is a fpu register
  80. clr.b (FPD_FPSR+2,FPDATA) | clear the exception byte
  81. fp_decode_sourcespec
  82. printf PDECODE,"f<op>.x fp%d",1,%d0
  83. fp_get_fp_reg
  84. lea (FPD_TEMPFP1,FPDATA),%a1 | copy src into a temp location
  85. move.l (%a0)+,(%a1)+
  86. move.l (%a0)+,(%a1)+
  87. move.l (%a0),(%a1)
  88. lea (-8,%a1),%a0
  89. jra fp_getdest
  90. fp_fgen_ea: | source is <ea>
  91. clr.b (FPD_FPSR+2,FPDATA) | clear the exception byte
  92. | sort out fmovecr, keep data size in %d1
  93. fp_decode_sourcespec
  94. cmp.w #7,%d0
  95. jeq fp_fmovecr
  96. move.w %d0,%d1 | store data size twice in %d1
  97. swap %d1 | one can be trashed below
  98. move.w %d0,%d1
  99. #ifdef FPU_EMU_DEBUG
  100. lea 0f,%a0
  101. clr.l %d0
  102. move.b (%a0,%d1.w),%d0
  103. printf PDECODE,"f<op>.%c ",1,%d0
  104. .data
  105. 0: .byte 'l','s','x','p','w','d','b',0
  106. .previous
  107. #endif
  108. /*
  109. fp_getsource, fp_getdest
  110. basically, we end up with a pointer to the source operand in
  111. %a1, and a pointer to the destination operand in %a0. both
  112. are, of course, 96-bit extended floating point numbers.
  113. */
  114. fp_getsource:
  115. | decode addressing mode for source
  116. fp_decode_addr_mode
  117. .long fp_data, fp_ill
  118. .long fp_indirect, fp_postinc
  119. .long fp_predecr, fp_disp16
  120. .long fp_extmode0, fp_extmode1
  121. | addressing mode: data register direct
  122. fp_data:
  123. fp_mode_data_direct
  124. jsr fp_get_data_reg
  125. lea (FPD_TEMPFP1,FPDATA),%a0
  126. jmp ([0f:w,%pc,%d1.w*4])
  127. .align 4
  128. 0:
  129. .long fp_data_long, fp_data_single
  130. .long fp_ill, fp_ill
  131. .long fp_data_word, fp_ill
  132. .long fp_data_byte, fp_ill
  133. | data types that fit in an integer data register
  134. fp_data_byte:
  135. extb.l %d0
  136. jra fp_data_long
  137. fp_data_word:
  138. ext.l %d0
  139. fp_data_long:
  140. jsr fp_conv_long2ext
  141. jra fp_getdest
  142. fp_data_single:
  143. jsr fp_conv_single2ext
  144. jra fp_getdest
  145. | addressing mode: address register indirect
  146. fp_indirect:
  147. fp_mode_addr_indirect
  148. jra fp_fetchsource
  149. | addressing mode: address register indirect with postincrement
  150. fp_postinc:
  151. fp_mode_addr_indirect_postinc
  152. jra fp_fetchsource
  153. | addressing mode: address register indirect with predecrement
  154. fp_predecr:
  155. fp_mode_addr_indirect_predec
  156. jra fp_fetchsource
  157. | addressing mode: address register/programm counter indirect
  158. | with 16bit displacement
  159. fp_disp16:
  160. fp_mode_addr_indirect_disp16
  161. jra fp_fetchsource
  162. | all other indirect addressing modes will finally end up here
  163. fp_extmode0:
  164. fp_mode_addr_indirect_extmode0
  165. jra fp_fetchsource
  166. | all pc relative addressing modes and immediate/absolute modes end up here
  167. | the first ones are sent to fp_extmode0 or fp_disp16
  168. | and only the latter are handled here
  169. fp_extmode1:
  170. fp_decode_addr_reg
  171. jmp ([0f:w,%pc,%d0*4])
  172. .align 4
  173. 0:
  174. .long fp_abs_short, fp_abs_long
  175. .long fp_disp16, fp_extmode0
  176. .long fp_immediate, fp_ill
  177. .long fp_ill, fp_ill
  178. | addressing mode: absolute short
  179. fp_abs_short:
  180. fp_mode_abs_short
  181. jra fp_fetchsource
  182. | addressing mode: absolute long
  183. fp_abs_long:
  184. fp_mode_abs_long
  185. jra fp_fetchsource
  186. | addressing mode: immediate data
  187. fp_immediate:
  188. printf PDECODE,"#"
  189. fp_get_pc %a0
  190. move.w (fp_datasize,%d1.w*2),%d0
  191. addq.w #1,%d0
  192. and.w #-2,%d0
  193. #ifdef FPU_EMU_DEBUG
  194. movem.l %d0/%d1,-(%sp)
  195. movel %a0,%a1
  196. clr.l %d1
  197. jra 2f
  198. 1: getuser.b (%a1)+,%d1,fp_err_ua1,%a1
  199. printf PDECODE,"%02x",1,%d1
  200. 2: dbra %d0,1b
  201. movem.l (%sp)+,%d0/%d1
  202. #endif
  203. lea (%a0,%d0.w),%a1
  204. fp_put_pc %a1
  205. | jra fp_fetchsource
  206. fp_fetchsource:
  207. move.l %a0,%a1
  208. swap %d1
  209. lea (FPD_TEMPFP1,FPDATA),%a0
  210. jmp ([0f:w,%pc,%d1.w*4])
  211. .align 4
  212. 0: .long fp_long, fp_single
  213. .long fp_ext, fp_pack
  214. .long fp_word, fp_double
  215. .long fp_byte, fp_ill
  216. fp_long:
  217. getuser.l (%a1),%d0,fp_err_ua1,%a1
  218. jsr fp_conv_long2ext
  219. jra fp_getdest
  220. fp_single:
  221. getuser.l (%a1),%d0,fp_err_ua1,%a1
  222. jsr fp_conv_single2ext
  223. jra fp_getdest
  224. fp_ext:
  225. getuser.l (%a1)+,%d0,fp_err_ua1,%a1
  226. lsr.l #8,%d0
  227. lsr.l #7,%d0
  228. lsr.w #1,%d0
  229. move.l %d0,(%a0)+
  230. getuser.l (%a1)+,%d0,fp_err_ua1,%a1
  231. move.l %d0,(%a0)+
  232. getuser.l (%a1),%d0,fp_err_ua1,%a1
  233. move.l %d0,(%a0)
  234. subq.l #8,%a0
  235. jra fp_getdest
  236. fp_pack:
  237. /* not supported yet */
  238. jra fp_ill
  239. fp_word:
  240. getuser.w (%a1),%d0,fp_err_ua1,%a1
  241. ext.l %d0
  242. jsr fp_conv_long2ext
  243. jra fp_getdest
  244. fp_double:
  245. jsr fp_conv_double2ext
  246. jra fp_getdest
  247. fp_byte:
  248. getuser.b (%a1),%d0,fp_err_ua1,%a1
  249. extb.l %d0
  250. jsr fp_conv_long2ext
  251. | jra fp_getdest
  252. fp_getdest:
  253. move.l %a0,%a1
  254. bfextu %d2{#22,#3},%d0
  255. printf PDECODE,",fp%d\n",1,%d0
  256. fp_get_fp_reg
  257. movem.l %a0/%a1,-(%sp)
  258. pea fp_finalrounding
  259. bfextu %d2{#25,#7},%d0
  260. jmp ([0f:w,%pc,%d0*4])
  261. .align 4
  262. 0:
  263. .long fp_fmove_mem2fp, fp_fint, fp_fsinh, fp_fintrz
  264. .long fp_fsqrt, fp_ill, fp_flognp1, fp_ill
  265. .long fp_fetoxm1, fp_ftanh, fp_fatan, fp_ill
  266. .long fp_fasin, fp_fatanh, fp_fsin, fp_ftan
  267. .long fp_fetox, fp_ftwotox, fp_ftentox, fp_ill
  268. .long fp_flogn, fp_flog10, fp_flog2, fp_ill
  269. .long fp_fabs, fp_fcosh, fp_fneg, fp_ill
  270. .long fp_facos, fp_fcos, fp_fgetexp, fp_fgetman
  271. .long fp_fdiv, fp_fmod, fp_fadd, fp_fmul
  272. .long fpa_fsgldiv, fp_frem, fp_fscale, fpa_fsglmul
  273. .long fp_fsub, fp_ill, fp_ill, fp_ill
  274. .long fp_ill, fp_ill, fp_ill, fp_ill
  275. .long fp_fsincos0, fp_fsincos1, fp_fsincos2, fp_fsincos3
  276. .long fp_fsincos4, fp_fsincos5, fp_fsincos6, fp_fsincos7
  277. .long fp_fcmp, fp_ill, fp_ftst, fp_ill
  278. .long fp_ill, fp_ill, fp_ill, fp_ill
  279. .long fp_fsmove, fp_fssqrt, fp_ill, fp_ill
  280. .long fp_fdmove, fp_fdsqrt, fp_ill, fp_ill
  281. .long fp_ill, fp_ill, fp_ill, fp_ill
  282. .long fp_ill, fp_ill, fp_ill, fp_ill
  283. .long fp_ill, fp_ill, fp_ill, fp_ill
  284. .long fp_ill, fp_ill, fp_ill, fp_ill
  285. .long fp_fsabs, fp_ill, fp_fsneg, fp_ill
  286. .long fp_fdabs, fp_ill, fp_fdneg, fp_ill
  287. .long fp_fsdiv, fp_ill, fp_fsadd, fp_fsmul
  288. .long fp_fddiv, fp_ill, fp_fdadd, fp_fdmul
  289. .long fp_fssub, fp_ill, fp_ill, fp_ill
  290. .long fp_fdsub, fp_ill, fp_ill, fp_ill
  291. .long fp_ill, fp_ill, fp_ill, fp_ill
  292. .long fp_ill, fp_ill, fp_ill, fp_ill
  293. .long fp_ill, fp_ill, fp_ill, fp_ill
  294. .long fp_ill, fp_ill, fp_ill, fp_ill
  295. | Instructions follow
  296. | Move an (emulated) ROM constant
  297. fp_fmovecr:
  298. bfextu %d2{#27,#5},%d0
  299. printf PINSTR,"fp_fmovecr #%d",1,%d0
  300. move.l %d0,%d1
  301. add.l %d0,%d0
  302. add.l %d1,%d0
  303. lea (fp_constants,%d0*4),%a0
  304. move.l #0x801cc0ff,%d0
  305. addq.l #1,%d1
  306. lsl.l %d1,%d0
  307. jcc 1f
  308. fp_set_sr FPSR_EXC_INEX2 | INEX2 exception
  309. 1: moveq #-128,%d0 | continue with fmove
  310. and.l %d0,%d2
  311. jra fp_getdest
  312. .data
  313. .align 4
  314. fp_constants:
  315. .long 0x00004000,0xc90fdaa2,0x2168c235 | pi
  316. .extend 0,0,0,0,0,0,0,0,0,0
  317. .long 0x00003ffd,0x9a209a84,0xfbcff798 | log10(2)
  318. .long 0x00004000,0xadf85458,0xa2bb4a9a | e
  319. .long 0x00003fff,0xb8aa3b29,0x5c17f0bc | log2(e)
  320. .long 0x00003ffd,0xde5bd8a9,0x37287195 | log10(e)
  321. .long 0x00000000,0x00000000,0x00000000 | 0.0
  322. .long 0x00003ffe,0xb17217f7,0xd1cf79ac | 1n(2)
  323. .long 0x00004000,0x935d8ddd,0xaaa8ac17 | 1n(10)
  324. | read this as "1.0 * 2^0" - note the high bit in the mantissa
  325. .long 0x00003fff,0x80000000,0x00000000 | 10^0
  326. .long 0x00004002,0xa0000000,0x00000000 | 10^1
  327. .long 0x00004005,0xc8000000,0x00000000 | 10^2
  328. .long 0x0000400c,0x9c400000,0x00000000 | 10^4
  329. .long 0x00004019,0xbebc2000,0x00000000 | 10^8
  330. .long 0x00004034,0x8e1bc9bf,0x04000000 | 10^16
  331. .long 0x00004069,0x9dc5ada8,0x2b70b59e | 10^32
  332. .long 0x000040d3,0xc2781f49,0xffcfa6d5 | 10^64
  333. .long 0x000041a8,0x93ba47c9,0x80e98ce0 | 10^128
  334. .long 0x00004351,0xaa7eebfb,0x9df9de8e | 10^256
  335. .long 0x000046a3,0xe319a0ae,0xa60e91c7 | 10^512
  336. .long 0x00004d48,0xc9767586,0x81750c17 | 10^1024
  337. .long 0x00005a92,0x9e8b3b5d,0xc53d5de5 | 10^2048
  338. .long 0x00007525,0xc4605202,0x8a20979b | 10^4096
  339. .previous
  340. fp_fmove_mem2fp:
  341. printf PINSTR,"fmove %p,%p\n",2,%a0,%a1
  342. move.l (%a1)+,(%a0)+
  343. move.l (%a1)+,(%a0)+
  344. move.l (%a1),(%a0)
  345. subq.l #8,%a0
  346. rts
  347. fpa_fsglmul:
  348. move.l #fp_finalrounding_single_fast,(%sp)
  349. jra fp_fsglmul
  350. fpa_fsgldiv:
  351. move.l #fp_finalrounding_single_fast,(%sp)
  352. jra fp_fsgldiv
  353. .macro fp_dosingleprec instr
  354. printf PINSTR,"single "
  355. move.l #fp_finalrounding_single,(%sp)
  356. jra \instr
  357. .endm
  358. .macro fp_dodoubleprec instr
  359. printf PINSTR,"double "
  360. move.l #fp_finalrounding_double,(%sp)
  361. jra \instr
  362. .endm
  363. fp_fsmove:
  364. fp_dosingleprec fp_fmove_mem2fp
  365. fp_fssqrt:
  366. fp_dosingleprec fp_fsqrt
  367. fp_fdmove:
  368. fp_dodoubleprec fp_fmove_mem2fp
  369. fp_fdsqrt:
  370. fp_dodoubleprec fp_fsqrt
  371. fp_fsabs:
  372. fp_dosingleprec fp_fabs
  373. fp_fsneg:
  374. fp_dosingleprec fp_fneg
  375. fp_fdabs:
  376. fp_dodoubleprec fp_fabs
  377. fp_fdneg:
  378. fp_dodoubleprec fp_fneg
  379. fp_fsdiv:
  380. fp_dosingleprec fp_fdiv
  381. fp_fsadd:
  382. fp_dosingleprec fp_fadd
  383. fp_fsmul:
  384. fp_dosingleprec fp_fmul
  385. fp_fddiv:
  386. fp_dodoubleprec fp_fdiv
  387. fp_fdadd:
  388. fp_dodoubleprec fp_fadd
  389. fp_fdmul:
  390. fp_dodoubleprec fp_fmul
  391. fp_fssub:
  392. fp_dosingleprec fp_fsub
  393. fp_fdsub:
  394. fp_dodoubleprec fp_fsub
  395. fp_nonstd:
  396. fp_get_pc %a0
  397. getuser.l (%a0),%d0,fp_err_ua1,%a0
  398. printf ,"nonstd ((%08x)=%08x)\n",2,%a0,%d0
  399. moveq #-1,%d0
  400. rts
  401. .data
  402. .align 4
  403. | data sizes corresponding to the operand formats
  404. fp_datasize:
  405. .word 4, 4, 12, 12, 2, 8, 1, 0