fpu.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * arch/sh64/kernel/fpu.c
  7. *
  8. * Copyright (C) 2001 Manuela Cirronis, Paolo Alberelli
  9. * Copyright (C) 2002 STMicroelectronics Limited
  10. * Author : Stuart Menefy
  11. *
  12. * Started from SH4 version:
  13. * Copyright (C) 1999, 2000 Kaz Kojima & Niibe Yutaka
  14. *
  15. */
  16. #include <linux/sched.h>
  17. #include <linux/signal.h>
  18. #include <asm/processor.h>
  19. #include <asm/user.h>
  20. #include <asm/io.h>
  21. /*
  22. * Initially load the FPU with signalling NANS. This bit pattern
  23. * has the property that no matter whether considered as single or as
  24. * double precision, it still represents a signalling NAN.
  25. */
  26. #define sNAN64 0xFFFFFFFFFFFFFFFFULL
  27. #define sNAN32 0xFFFFFFFFUL
  28. static union sh_fpu_union init_fpuregs = {
  29. .hard = {
  30. .fp_regs = { [0 ... 63] = sNAN32 },
  31. .fpscr = FPSCR_INIT
  32. }
  33. };
  34. inline void fpsave(struct sh_fpu_hard_struct *fpregs)
  35. {
  36. asm volatile("fst.p %0, (0*8), fp0\n\t"
  37. "fst.p %0, (1*8), fp2\n\t"
  38. "fst.p %0, (2*8), fp4\n\t"
  39. "fst.p %0, (3*8), fp6\n\t"
  40. "fst.p %0, (4*8), fp8\n\t"
  41. "fst.p %0, (5*8), fp10\n\t"
  42. "fst.p %0, (6*8), fp12\n\t"
  43. "fst.p %0, (7*8), fp14\n\t"
  44. "fst.p %0, (8*8), fp16\n\t"
  45. "fst.p %0, (9*8), fp18\n\t"
  46. "fst.p %0, (10*8), fp20\n\t"
  47. "fst.p %0, (11*8), fp22\n\t"
  48. "fst.p %0, (12*8), fp24\n\t"
  49. "fst.p %0, (13*8), fp26\n\t"
  50. "fst.p %0, (14*8), fp28\n\t"
  51. "fst.p %0, (15*8), fp30\n\t"
  52. "fst.p %0, (16*8), fp32\n\t"
  53. "fst.p %0, (17*8), fp34\n\t"
  54. "fst.p %0, (18*8), fp36\n\t"
  55. "fst.p %0, (19*8), fp38\n\t"
  56. "fst.p %0, (20*8), fp40\n\t"
  57. "fst.p %0, (21*8), fp42\n\t"
  58. "fst.p %0, (22*8), fp44\n\t"
  59. "fst.p %0, (23*8), fp46\n\t"
  60. "fst.p %0, (24*8), fp48\n\t"
  61. "fst.p %0, (25*8), fp50\n\t"
  62. "fst.p %0, (26*8), fp52\n\t"
  63. "fst.p %0, (27*8), fp54\n\t"
  64. "fst.p %0, (28*8), fp56\n\t"
  65. "fst.p %0, (29*8), fp58\n\t"
  66. "fst.p %0, (30*8), fp60\n\t"
  67. "fst.p %0, (31*8), fp62\n\t"
  68. "fgetscr fr63\n\t"
  69. "fst.s %0, (32*8), fr63\n\t"
  70. : /* no output */
  71. : "r" (fpregs)
  72. : "memory");
  73. }
  74. static inline void
  75. fpload(struct sh_fpu_hard_struct *fpregs)
  76. {
  77. asm volatile("fld.p %0, (0*8), fp0\n\t"
  78. "fld.p %0, (1*8), fp2\n\t"
  79. "fld.p %0, (2*8), fp4\n\t"
  80. "fld.p %0, (3*8), fp6\n\t"
  81. "fld.p %0, (4*8), fp8\n\t"
  82. "fld.p %0, (5*8), fp10\n\t"
  83. "fld.p %0, (6*8), fp12\n\t"
  84. "fld.p %0, (7*8), fp14\n\t"
  85. "fld.p %0, (8*8), fp16\n\t"
  86. "fld.p %0, (9*8), fp18\n\t"
  87. "fld.p %0, (10*8), fp20\n\t"
  88. "fld.p %0, (11*8), fp22\n\t"
  89. "fld.p %0, (12*8), fp24\n\t"
  90. "fld.p %0, (13*8), fp26\n\t"
  91. "fld.p %0, (14*8), fp28\n\t"
  92. "fld.p %0, (15*8), fp30\n\t"
  93. "fld.p %0, (16*8), fp32\n\t"
  94. "fld.p %0, (17*8), fp34\n\t"
  95. "fld.p %0, (18*8), fp36\n\t"
  96. "fld.p %0, (19*8), fp38\n\t"
  97. "fld.p %0, (20*8), fp40\n\t"
  98. "fld.p %0, (21*8), fp42\n\t"
  99. "fld.p %0, (22*8), fp44\n\t"
  100. "fld.p %0, (23*8), fp46\n\t"
  101. "fld.p %0, (24*8), fp48\n\t"
  102. "fld.p %0, (25*8), fp50\n\t"
  103. "fld.p %0, (26*8), fp52\n\t"
  104. "fld.p %0, (27*8), fp54\n\t"
  105. "fld.p %0, (28*8), fp56\n\t"
  106. "fld.p %0, (29*8), fp58\n\t"
  107. "fld.p %0, (30*8), fp60\n\t"
  108. "fld.s %0, (32*8), fr63\n\t"
  109. "fputscr fr63\n\t"
  110. "fld.p %0, (31*8), fp62\n\t"
  111. : /* no output */
  112. : "r" (fpregs) );
  113. }
  114. void fpinit(struct sh_fpu_hard_struct *fpregs)
  115. {
  116. *fpregs = init_fpuregs.hard;
  117. }
  118. asmlinkage void
  119. do_fpu_error(unsigned long ex, struct pt_regs *regs)
  120. {
  121. struct task_struct *tsk = current;
  122. regs->pc += 4;
  123. tsk->thread.trap_no = 11;
  124. tsk->thread.error_code = 0;
  125. force_sig(SIGFPE, tsk);
  126. }
  127. asmlinkage void
  128. do_fpu_state_restore(unsigned long ex, struct pt_regs *regs)
  129. {
  130. void die(const char *str, struct pt_regs *regs, long err);
  131. if (! user_mode(regs))
  132. die("FPU used in kernel", regs, ex);
  133. regs->sr &= ~SR_FD;
  134. if (last_task_used_math == current)
  135. return;
  136. grab_fpu();
  137. if (last_task_used_math != NULL) {
  138. /* Other processes fpu state, save away */
  139. fpsave(&last_task_used_math->thread.fpu.hard);
  140. }
  141. last_task_used_math = current;
  142. if (used_math()) {
  143. fpload(&current->thread.fpu.hard);
  144. } else {
  145. /* First time FPU user. */
  146. fpload(&init_fpuregs.hard);
  147. set_used_math();
  148. }
  149. release_fpu();
  150. }