kernel_linkage.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. * Kevin D. Kissell, kevink@mips and Carsten Langgaard, carstenl@mips.com
  3. * Copyright (C) 2000 MIPS Technologies, Inc. All rights reserved.
  4. *
  5. * This program is free software; you can distribute it and/or modify it
  6. * under the terms of the GNU General Public License (Version 2) as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  12. * for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along
  15. * with this program; if not, write to the Free Software Foundation, Inc.,
  16. * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
  17. *
  18. * Routines corresponding to Linux kernel FP context
  19. * manipulation primitives for the Algorithmics MIPS
  20. * FPU Emulator
  21. */
  22. #include <linux/config.h>
  23. #include <linux/sched.h>
  24. #include <asm/processor.h>
  25. #include <asm/signal.h>
  26. #include <asm/uaccess.h>
  27. #include <asm/fpu_emulator.h>
  28. #define SIGNALLING_NAN 0x7ff800007ff80000LL
  29. void fpu_emulator_init_fpu(void)
  30. {
  31. static int first = 1;
  32. int i;
  33. if (first) {
  34. first = 0;
  35. printk("Algorithmics/MIPS FPU Emulator v1.5\n");
  36. }
  37. current->thread.fpu.soft.fcr31 = 0;
  38. for (i = 0; i < 32; i++) {
  39. current->thread.fpu.soft.fpr[i] = SIGNALLING_NAN;
  40. }
  41. }
  42. /*
  43. * Emulator context save/restore to/from a signal context
  44. * presumed to be on the user stack, and therefore accessed
  45. * with appropriate macros from uaccess.h
  46. */
  47. int fpu_emulator_save_context(struct sigcontext *sc)
  48. {
  49. int i;
  50. int err = 0;
  51. for (i = 0; i < 32; i++) {
  52. err |=
  53. __put_user(current->thread.fpu.soft.fpr[i],
  54. &sc->sc_fpregs[i]);
  55. }
  56. err |= __put_user(current->thread.fpu.soft.fcr31, &sc->sc_fpc_csr);
  57. return err;
  58. }
  59. int fpu_emulator_restore_context(struct sigcontext *sc)
  60. {
  61. int i;
  62. int err = 0;
  63. for (i = 0; i < 32; i++) {
  64. err |=
  65. __get_user(current->thread.fpu.soft.fpr[i],
  66. &sc->sc_fpregs[i]);
  67. }
  68. err |= __get_user(current->thread.fpu.soft.fcr31, &sc->sc_fpc_csr);
  69. return err;
  70. }
  71. #ifdef CONFIG_64BIT
  72. /*
  73. * This is the o32 version
  74. */
  75. int fpu_emulator_save_context32(struct sigcontext32 *sc)
  76. {
  77. int i;
  78. int err = 0;
  79. for (i = 0; i < 32; i+=2) {
  80. err |=
  81. __put_user(current->thread.fpu.soft.fpr[i],
  82. &sc->sc_fpregs[i]);
  83. }
  84. err |= __put_user(current->thread.fpu.soft.fcr31, &sc->sc_fpc_csr);
  85. return err;
  86. }
  87. int fpu_emulator_restore_context32(struct sigcontext32 *sc)
  88. {
  89. int i;
  90. int err = 0;
  91. for (i = 0; i < 32; i+=2) {
  92. err |=
  93. __get_user(current->thread.fpu.soft.fpr[i],
  94. &sc->sc_fpregs[i]);
  95. }
  96. err |= __get_user(current->thread.fpu.soft.fcr31, &sc->sc_fpc_csr);
  97. return err;
  98. }
  99. #endif