skeleton.S 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514
  1. |
  2. | skeleton.sa 3.2 4/26/91
  3. |
  4. | This file contains code that is system dependent and will
  5. | need to be modified to install the FPSP.
  6. |
  7. | Each entry point for exception 'xxxx' begins with a 'jmp fpsp_xxxx'.
  8. | Put any target system specific handling that must be done immediately
  9. | before the jump instruction. If there no handling necessary, then
  10. | the 'fpsp_xxxx' handler entry point should be placed in the exception
  11. | table so that the 'jmp' can be eliminated. If the FPSP determines that the
  12. | exception is one that must be reported then there will be a
  13. | return from the package by a 'jmp real_xxxx'. At that point
  14. | the machine state will be identical to the state before
  15. | the FPSP was entered. In particular, whatever condition
  16. | that caused the exception will still be pending when the FPSP
  17. | package returns. Thus, there will be system specific code
  18. | to handle the exception.
  19. |
  20. | If the exception was completely handled by the package, then
  21. | the return will be via a 'jmp fpsp_done'. Unless there is
  22. | OS specific work to be done (such as handling a context switch or
  23. | interrupt) the user program can be resumed via 'rte'.
  24. |
  25. | In the following skeleton code, some typical 'real_xxxx' handling
  26. | code is shown. This code may need to be moved to an appropriate
  27. | place in the target system, or rewritten.
  28. |
  29. | Copyright (C) Motorola, Inc. 1990
  30. | All Rights Reserved
  31. |
  32. | THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF MOTOROLA
  33. | The copyright notice above does not evidence any
  34. | actual or intended publication of such source code.
  35. |
  36. | Modified for Linux-1.3.x by Jes Sorensen (jds@kom.auc.dk)
  37. |
  38. #include <linux/linkage.h>
  39. #include <asm/entry.h>
  40. #include <asm/asm-offsets.h>
  41. |SKELETON idnt 2,1 | Motorola 040 Floating Point Software Package
  42. |section 15
  43. |
  44. | The following counters are used for standalone testing
  45. |
  46. |section 8
  47. #include "fpsp.h"
  48. |xref b1238_fix
  49. |
  50. | Divide by Zero exception
  51. |
  52. | All dz exceptions are 'real', hence no fpsp_dz entry point.
  53. |
  54. .global dz
  55. .global real_dz
  56. dz:
  57. real_dz:
  58. link %a6,#-LOCAL_SIZE
  59. fsave -(%sp)
  60. bclrb #E1,E_BYTE(%a6)
  61. frestore (%sp)+
  62. unlk %a6
  63. SAVE_ALL_INT
  64. GET_CURRENT(%d0)
  65. movel %sp,%sp@- | stack frame pointer argument
  66. bsrl trap_c
  67. addql #4,%sp
  68. bral ret_from_exception
  69. |
  70. | Inexact exception
  71. |
  72. | All inexact exceptions are real, but the 'real' handler
  73. | will probably want to clear the pending exception.
  74. | The provided code will clear the E3 exception (if pending),
  75. | otherwise clear the E1 exception. The frestore is not really
  76. | necessary for E1 exceptions.
  77. |
  78. | Code following the 'inex' label is to handle bug #1232. In this
  79. | bug, if an E1 snan, ovfl, or unfl occurred, and the process was
  80. | swapped out before taking the exception, the exception taken on
  81. | return was inex, rather than the correct exception. The snan, ovfl,
  82. | and unfl exception to be taken must not have been enabled. The
  83. | fix is to check for E1, and the existence of one of snan, ovfl,
  84. | or unfl bits set in the fpsr. If any of these are set, branch
  85. | to the appropriate handler for the exception in the fpsr. Note
  86. | that this fix is only for d43b parts, and is skipped if the
  87. | version number is not $40.
  88. |
  89. |
  90. .global real_inex
  91. .global inex
  92. inex:
  93. link %a6,#-LOCAL_SIZE
  94. fsave -(%sp)
  95. cmpib #VER_40,(%sp) |test version number
  96. bnes not_fmt40
  97. fmovel %fpsr,-(%sp)
  98. btstb #E1,E_BYTE(%a6) |test for E1 set
  99. beqs not_b1232
  100. btstb #snan_bit,2(%sp) |test for snan
  101. beq inex_ckofl
  102. addl #4,%sp
  103. frestore (%sp)+
  104. unlk %a6
  105. bra snan
  106. inex_ckofl:
  107. btstb #ovfl_bit,2(%sp) |test for ovfl
  108. beq inex_ckufl
  109. addl #4,%sp
  110. frestore (%sp)+
  111. unlk %a6
  112. bra ovfl
  113. inex_ckufl:
  114. btstb #unfl_bit,2(%sp) |test for unfl
  115. beq not_b1232
  116. addl #4,%sp
  117. frestore (%sp)+
  118. unlk %a6
  119. bra unfl
  120. |
  121. | We do not have the bug 1232 case. Clean up the stack and call
  122. | real_inex.
  123. |
  124. not_b1232:
  125. addl #4,%sp
  126. frestore (%sp)+
  127. unlk %a6
  128. real_inex:
  129. link %a6,#-LOCAL_SIZE
  130. fsave -(%sp)
  131. not_fmt40:
  132. bclrb #E3,E_BYTE(%a6) |clear and test E3 flag
  133. beqs inex_cke1
  134. |
  135. | Clear dirty bit on dest resister in the frame before branching
  136. | to b1238_fix.
  137. |
  138. moveml %d0/%d1,USER_DA(%a6)
  139. bfextu CMDREG1B(%a6){#6:#3},%d0 |get dest reg no
  140. bclrb %d0,FPR_DIRTY_BITS(%a6) |clr dest dirty bit
  141. bsrl b1238_fix |test for bug1238 case
  142. moveml USER_DA(%a6),%d0/%d1
  143. bras inex_done
  144. inex_cke1:
  145. bclrb #E1,E_BYTE(%a6)
  146. inex_done:
  147. frestore (%sp)+
  148. unlk %a6
  149. SAVE_ALL_INT
  150. GET_CURRENT(%d0)
  151. movel %sp,%sp@- | stack frame pointer argument
  152. bsrl trap_c
  153. addql #4,%sp
  154. bral ret_from_exception
  155. |
  156. | Overflow exception
  157. |
  158. |xref fpsp_ovfl
  159. .global real_ovfl
  160. .global ovfl
  161. ovfl:
  162. jmp fpsp_ovfl
  163. real_ovfl:
  164. link %a6,#-LOCAL_SIZE
  165. fsave -(%sp)
  166. bclrb #E3,E_BYTE(%a6) |clear and test E3 flag
  167. bnes ovfl_done
  168. bclrb #E1,E_BYTE(%a6)
  169. ovfl_done:
  170. frestore (%sp)+
  171. unlk %a6
  172. SAVE_ALL_INT
  173. GET_CURRENT(%d0)
  174. movel %sp,%sp@- | stack frame pointer argument
  175. bsrl trap_c
  176. addql #4,%sp
  177. bral ret_from_exception
  178. |
  179. | Underflow exception
  180. |
  181. |xref fpsp_unfl
  182. .global real_unfl
  183. .global unfl
  184. unfl:
  185. jmp fpsp_unfl
  186. real_unfl:
  187. link %a6,#-LOCAL_SIZE
  188. fsave -(%sp)
  189. bclrb #E3,E_BYTE(%a6) |clear and test E3 flag
  190. bnes unfl_done
  191. bclrb #E1,E_BYTE(%a6)
  192. unfl_done:
  193. frestore (%sp)+
  194. unlk %a6
  195. SAVE_ALL_INT
  196. GET_CURRENT(%d0)
  197. movel %sp,%sp@- | stack frame pointer argument
  198. bsrl trap_c
  199. addql #4,%sp
  200. bral ret_from_exception
  201. |
  202. | Signalling NAN exception
  203. |
  204. |xref fpsp_snan
  205. .global real_snan
  206. .global snan
  207. snan:
  208. jmp fpsp_snan
  209. real_snan:
  210. link %a6,#-LOCAL_SIZE
  211. fsave -(%sp)
  212. bclrb #E1,E_BYTE(%a6) |snan is always an E1 exception
  213. frestore (%sp)+
  214. unlk %a6
  215. SAVE_ALL_INT
  216. GET_CURRENT(%d0)
  217. movel %sp,%sp@- | stack frame pointer argument
  218. bsrl trap_c
  219. addql #4,%sp
  220. bral ret_from_exception
  221. |
  222. | Operand Error exception
  223. |
  224. |xref fpsp_operr
  225. .global real_operr
  226. .global operr
  227. operr:
  228. jmp fpsp_operr
  229. real_operr:
  230. link %a6,#-LOCAL_SIZE
  231. fsave -(%sp)
  232. bclrb #E1,E_BYTE(%a6) |operr is always an E1 exception
  233. frestore (%sp)+
  234. unlk %a6
  235. SAVE_ALL_INT
  236. GET_CURRENT(%d0)
  237. movel %sp,%sp@- | stack frame pointer argument
  238. bsrl trap_c
  239. addql #4,%sp
  240. bral ret_from_exception
  241. |
  242. | BSUN exception
  243. |
  244. | This sample handler simply clears the nan bit in the FPSR.
  245. |
  246. |xref fpsp_bsun
  247. .global real_bsun
  248. .global bsun
  249. bsun:
  250. jmp fpsp_bsun
  251. real_bsun:
  252. link %a6,#-LOCAL_SIZE
  253. fsave -(%sp)
  254. bclrb #E1,E_BYTE(%a6) |bsun is always an E1 exception
  255. fmovel %FPSR,-(%sp)
  256. bclrb #nan_bit,(%sp)
  257. fmovel (%sp)+,%FPSR
  258. frestore (%sp)+
  259. unlk %a6
  260. SAVE_ALL_INT
  261. GET_CURRENT(%d0)
  262. movel %sp,%sp@- | stack frame pointer argument
  263. bsrl trap_c
  264. addql #4,%sp
  265. bral ret_from_exception
  266. |
  267. | F-line exception
  268. |
  269. | A 'real' F-line exception is one that the FPSP isn't supposed to
  270. | handle. E.g. an instruction with a co-processor ID that is not 1.
  271. |
  272. |
  273. |xref fpsp_fline
  274. .global real_fline
  275. .global fline
  276. fline:
  277. jmp fpsp_fline
  278. real_fline:
  279. SAVE_ALL_INT
  280. GET_CURRENT(%d0)
  281. movel %sp,%sp@- | stack frame pointer argument
  282. bsrl trap_c
  283. addql #4,%sp
  284. bral ret_from_exception
  285. |
  286. | Unsupported data type exception
  287. |
  288. |xref fpsp_unsupp
  289. .global real_unsupp
  290. .global unsupp
  291. unsupp:
  292. jmp fpsp_unsupp
  293. real_unsupp:
  294. link %a6,#-LOCAL_SIZE
  295. fsave -(%sp)
  296. bclrb #E1,E_BYTE(%a6) |unsupp is always an E1 exception
  297. frestore (%sp)+
  298. unlk %a6
  299. SAVE_ALL_INT
  300. GET_CURRENT(%d0)
  301. movel %sp,%sp@- | stack frame pointer argument
  302. bsrl trap_c
  303. addql #4,%sp
  304. bral ret_from_exception
  305. |
  306. | Trace exception
  307. |
  308. .global real_trace
  309. real_trace:
  310. |
  311. bral trap
  312. |
  313. | fpsp_fmt_error --- exit point for frame format error
  314. |
  315. | The fpu stack frame does not match the frames existing
  316. | or planned at the time of this writing. The fpsp is
  317. | unable to handle frame sizes not in the following
  318. | version:size pairs:
  319. |
  320. | {4060, 4160} - busy frame
  321. | {4028, 4130} - unimp frame
  322. | {4000, 4100} - idle frame
  323. |
  324. | This entry point simply holds an f-line illegal value.
  325. | Replace this with a call to your kernel panic code or
  326. | code to handle future revisions of the fpu.
  327. |
  328. .global fpsp_fmt_error
  329. fpsp_fmt_error:
  330. .long 0xf27f0000 |f-line illegal
  331. |
  332. | fpsp_done --- FPSP exit point
  333. |
  334. | The exception has been handled by the package and we are ready
  335. | to return to user mode, but there may be OS specific code
  336. | to execute before we do. If there is, do it now.
  337. |
  338. |
  339. .global fpsp_done
  340. fpsp_done:
  341. btst #0x5,%sp@ | supervisor bit set in saved SR?
  342. beq .Lnotkern
  343. rte
  344. .Lnotkern:
  345. SAVE_ALL_INT
  346. GET_CURRENT(%d0)
  347. | deliver signals, reschedule etc..
  348. jra ret_from_exception
  349. |
  350. | mem_write --- write to user or supervisor address space
  351. |
  352. | Writes to memory while in supervisor mode. copyout accomplishes
  353. | this via a 'moves' instruction. copyout is a UNIX SVR3 (and later) function.
  354. | If you don't have copyout, use the local copy of the function below.
  355. |
  356. | a0 - supervisor source address
  357. | a1 - user destination address
  358. | d0 - number of bytes to write (maximum count is 12)
  359. |
  360. | The supervisor source address is guaranteed to point into the supervisor
  361. | stack. The result is that a UNIX
  362. | process is allowed to sleep as a consequence of a page fault during
  363. | copyout. The probability of a page fault is exceedingly small because
  364. | the 68040 always reads the destination address and thus the page
  365. | faults should have already been handled.
  366. |
  367. | If the EXC_SR shows that the exception was from supervisor space,
  368. | then just do a dumb (and slow) memory move. In a UNIX environment
  369. | there shouldn't be any supervisor mode floating point exceptions.
  370. |
  371. .global mem_write
  372. mem_write:
  373. btstb #5,EXC_SR(%a6) |check for supervisor state
  374. beqs user_write
  375. super_write:
  376. moveb (%a0)+,(%a1)+
  377. subql #1,%d0
  378. bnes super_write
  379. rts
  380. user_write:
  381. movel %d1,-(%sp) |preserve d1 just in case
  382. movel %d0,-(%sp)
  383. movel %a1,-(%sp)
  384. movel %a0,-(%sp)
  385. jsr copyout
  386. addw #12,%sp
  387. movel (%sp)+,%d1
  388. rts
  389. |
  390. | mem_read --- read from user or supervisor address space
  391. |
  392. | Reads from memory while in supervisor mode. copyin accomplishes
  393. | this via a 'moves' instruction. copyin is a UNIX SVR3 (and later) function.
  394. | If you don't have copyin, use the local copy of the function below.
  395. |
  396. | The FPSP calls mem_read to read the original F-line instruction in order
  397. | to extract the data register number when the 'Dn' addressing mode is
  398. | used.
  399. |
  400. |Input:
  401. | a0 - user source address
  402. | a1 - supervisor destination address
  403. | d0 - number of bytes to read (maximum count is 12)
  404. |
  405. | Like mem_write, mem_read always reads with a supervisor
  406. | destination address on the supervisor stack. Also like mem_write,
  407. | the EXC_SR is checked and a simple memory copy is done if reading
  408. | from supervisor space is indicated.
  409. |
  410. .global mem_read
  411. mem_read:
  412. btstb #5,EXC_SR(%a6) |check for supervisor state
  413. beqs user_read
  414. super_read:
  415. moveb (%a0)+,(%a1)+
  416. subql #1,%d0
  417. bnes super_read
  418. rts
  419. user_read:
  420. movel %d1,-(%sp) |preserve d1 just in case
  421. movel %d0,-(%sp)
  422. movel %a1,-(%sp)
  423. movel %a0,-(%sp)
  424. jsr copyin
  425. addw #12,%sp
  426. movel (%sp)+,%d1
  427. rts
  428. |
  429. | Use these routines if your kernel doesn't have copyout/copyin equivalents.
  430. | Assumes that D0/D1/A0/A1 are scratch registers. copyout overwrites DFC,
  431. | and copyin overwrites SFC.
  432. |
  433. copyout:
  434. movel 4(%sp),%a0 | source
  435. movel 8(%sp),%a1 | destination
  436. movel 12(%sp),%d0 | count
  437. subl #1,%d0 | dec count by 1 for dbra
  438. movel #1,%d1
  439. | DFC is already set
  440. | movec %d1,%DFC | set dfc for user data space
  441. moreout:
  442. moveb (%a0)+,%d1 | fetch supervisor byte
  443. out_ea:
  444. movesb %d1,(%a1)+ | write user byte
  445. dbf %d0,moreout
  446. rts
  447. copyin:
  448. movel 4(%sp),%a0 | source
  449. movel 8(%sp),%a1 | destination
  450. movel 12(%sp),%d0 | count
  451. subl #1,%d0 | dec count by 1 for dbra
  452. movel #1,%d1
  453. | SFC is already set
  454. | movec %d1,%SFC | set sfc for user space
  455. morein:
  456. in_ea:
  457. movesb (%a0)+,%d1 | fetch user byte
  458. moveb %d1,(%a1)+ | write supervisor byte
  459. dbf %d0,morein
  460. rts
  461. .section .fixup,#alloc,#execinstr
  462. .even
  463. 1:
  464. jbra fpsp040_die
  465. .section __ex_table,#alloc
  466. .align 4
  467. .long in_ea,1b
  468. .long out_ea,1b
  469. |end