skeleton.S 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516
  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/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. tstb %curptr@(TASK_NEEDRESCHED)
  348. jne ret_from_exception | deliver signals,
  349. | reschedule etc..
  350. RESTORE_ALL
  351. |
  352. | mem_write --- write to user or supervisor address space
  353. |
  354. | Writes to memory while in supervisor mode. copyout accomplishes
  355. | this via a 'moves' instruction. copyout is a UNIX SVR3 (and later) function.
  356. | If you don't have copyout, use the local copy of the function below.
  357. |
  358. | a0 - supervisor source address
  359. | a1 - user destination address
  360. | d0 - number of bytes to write (maximum count is 12)
  361. |
  362. | The supervisor source address is guaranteed to point into the supervisor
  363. | stack. The result is that a UNIX
  364. | process is allowed to sleep as a consequence of a page fault during
  365. | copyout. The probability of a page fault is exceedingly small because
  366. | the 68040 always reads the destination address and thus the page
  367. | faults should have already been handled.
  368. |
  369. | If the EXC_SR shows that the exception was from supervisor space,
  370. | then just do a dumb (and slow) memory move. In a UNIX environment
  371. | there shouldn't be any supervisor mode floating point exceptions.
  372. |
  373. .global mem_write
  374. mem_write:
  375. btstb #5,EXC_SR(%a6) |check for supervisor state
  376. beqs user_write
  377. super_write:
  378. moveb (%a0)+,(%a1)+
  379. subql #1,%d0
  380. bnes super_write
  381. rts
  382. user_write:
  383. movel %d1,-(%sp) |preserve d1 just in case
  384. movel %d0,-(%sp)
  385. movel %a1,-(%sp)
  386. movel %a0,-(%sp)
  387. jsr copyout
  388. addw #12,%sp
  389. movel (%sp)+,%d1
  390. rts
  391. |
  392. | mem_read --- read from user or supervisor address space
  393. |
  394. | Reads from memory while in supervisor mode. copyin accomplishes
  395. | this via a 'moves' instruction. copyin is a UNIX SVR3 (and later) function.
  396. | If you don't have copyin, use the local copy of the function below.
  397. |
  398. | The FPSP calls mem_read to read the original F-line instruction in order
  399. | to extract the data register number when the 'Dn' addressing mode is
  400. | used.
  401. |
  402. |Input:
  403. | a0 - user source address
  404. | a1 - supervisor destination address
  405. | d0 - number of bytes to read (maximum count is 12)
  406. |
  407. | Like mem_write, mem_read always reads with a supervisor
  408. | destination address on the supervisor stack. Also like mem_write,
  409. | the EXC_SR is checked and a simple memory copy is done if reading
  410. | from supervisor space is indicated.
  411. |
  412. .global mem_read
  413. mem_read:
  414. btstb #5,EXC_SR(%a6) |check for supervisor state
  415. beqs user_read
  416. super_read:
  417. moveb (%a0)+,(%a1)+
  418. subql #1,%d0
  419. bnes super_read
  420. rts
  421. user_read:
  422. movel %d1,-(%sp) |preserve d1 just in case
  423. movel %d0,-(%sp)
  424. movel %a1,-(%sp)
  425. movel %a0,-(%sp)
  426. jsr copyin
  427. addw #12,%sp
  428. movel (%sp)+,%d1
  429. rts
  430. |
  431. | Use these routines if your kernel doesn't have copyout/copyin equivalents.
  432. | Assumes that D0/D1/A0/A1 are scratch registers. copyout overwrites DFC,
  433. | and copyin overwrites SFC.
  434. |
  435. copyout:
  436. movel 4(%sp),%a0 | source
  437. movel 8(%sp),%a1 | destination
  438. movel 12(%sp),%d0 | count
  439. subl #1,%d0 | dec count by 1 for dbra
  440. movel #1,%d1
  441. | DFC is already set
  442. | movec %d1,%DFC | set dfc for user data space
  443. moreout:
  444. moveb (%a0)+,%d1 | fetch supervisor byte
  445. out_ea:
  446. movesb %d1,(%a1)+ | write user byte
  447. dbf %d0,moreout
  448. rts
  449. copyin:
  450. movel 4(%sp),%a0 | source
  451. movel 8(%sp),%a1 | destination
  452. movel 12(%sp),%d0 | count
  453. subl #1,%d0 | dec count by 1 for dbra
  454. movel #1,%d1
  455. | SFC is already set
  456. | movec %d1,%SFC | set sfc for user space
  457. morein:
  458. in_ea:
  459. movesb (%a0)+,%d1 | fetch user byte
  460. moveb %d1,(%a1)+ | write supervisor byte
  461. dbf %d0,morein
  462. rts
  463. .section .fixup,#alloc,#execinstr
  464. .even
  465. 1:
  466. jbra fpsp040_die
  467. .section __ex_table,#alloc
  468. .align 4
  469. .long in_ea,1b
  470. .long out_ea,1b
  471. |end