fpu.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /*
  2. * Copyright (C) 2002 MontaVista Software Inc.
  3. * Author: Jun Sun, jsun@mvista.com or jsun@junsun.net
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License as published by the
  7. * Free Software Foundation; either version 2 of the License, or (at your
  8. * option) any later version.
  9. */
  10. #ifndef _ASM_FPU_H
  11. #define _ASM_FPU_H
  12. #include <linux/sched.h>
  13. #include <linux/thread_info.h>
  14. #include <asm/mipsregs.h>
  15. #include <asm/cpu.h>
  16. #include <asm/cpu-features.h>
  17. #include <asm/bitops.h>
  18. #include <asm/processor.h>
  19. #include <asm/current.h>
  20. #ifdef CONFIG_MIPS_MT_FPAFF
  21. #include <asm/mips_mt.h>
  22. #endif
  23. struct sigcontext;
  24. struct sigcontext32;
  25. extern asmlinkage int (*save_fp_context)(struct sigcontext *sc);
  26. extern asmlinkage int (*restore_fp_context)(struct sigcontext *sc);
  27. extern asmlinkage int (*save_fp_context32)(struct sigcontext32 *sc);
  28. extern asmlinkage int (*restore_fp_context32)(struct sigcontext32 *sc);
  29. extern void fpu_emulator_init_fpu(void);
  30. extern void _init_fpu(void);
  31. extern void _save_fp(struct task_struct *);
  32. extern void _restore_fp(struct task_struct *);
  33. #if defined(CONFIG_CPU_SB1)
  34. #define __enable_fpu_hazard() \
  35. do { \
  36. asm(".set push \n\t" \
  37. ".set mips64 \n\t" \
  38. ".set noreorder \n\t" \
  39. "ssnop \n\t" \
  40. "bnezl $0, .+4 \n\t" \
  41. "ssnop \n\t" \
  42. ".set pop"); \
  43. } while (0)
  44. #else
  45. #define __enable_fpu_hazard() \
  46. do { \
  47. asm("nop;nop;nop;nop"); /* max. hazard */ \
  48. } while (0)
  49. #endif
  50. #define __enable_fpu() \
  51. do { \
  52. set_c0_status(ST0_CU1); \
  53. __enable_fpu_hazard(); \
  54. } while (0)
  55. #define __disable_fpu() \
  56. do { \
  57. clear_c0_status(ST0_CU1); \
  58. /* We don't care about the c0 hazard here */ \
  59. } while (0)
  60. #define enable_fpu() \
  61. do { \
  62. if (cpu_has_fpu) \
  63. __enable_fpu(); \
  64. } while (0)
  65. #define disable_fpu() \
  66. do { \
  67. if (cpu_has_fpu) \
  68. __disable_fpu(); \
  69. } while (0)
  70. #define clear_fpu_owner() clear_thread_flag(TIF_USEDFPU)
  71. static inline int __is_fpu_owner(void)
  72. {
  73. return test_thread_flag(TIF_USEDFPU);
  74. }
  75. static inline int is_fpu_owner(void)
  76. {
  77. return cpu_has_fpu && __is_fpu_owner();
  78. }
  79. static inline void own_fpu(void)
  80. {
  81. if (cpu_has_fpu) {
  82. __enable_fpu();
  83. KSTK_STATUS(current) |= ST0_CU1;
  84. set_thread_flag(TIF_USEDFPU);
  85. }
  86. }
  87. static inline void lose_fpu(void)
  88. {
  89. if (cpu_has_fpu) {
  90. KSTK_STATUS(current) &= ~ST0_CU1;
  91. clear_thread_flag(TIF_USEDFPU);
  92. __disable_fpu();
  93. }
  94. }
  95. static inline void init_fpu(void)
  96. {
  97. if (cpu_has_fpu) {
  98. _init_fpu();
  99. } else {
  100. fpu_emulator_init_fpu();
  101. }
  102. }
  103. static inline void save_fp(struct task_struct *tsk)
  104. {
  105. if (cpu_has_fpu)
  106. _save_fp(tsk);
  107. }
  108. static inline void restore_fp(struct task_struct *tsk)
  109. {
  110. if (cpu_has_fpu)
  111. _restore_fp(tsk);
  112. }
  113. static inline fpureg_t *get_fpu_regs(struct task_struct *tsk)
  114. {
  115. if (cpu_has_fpu) {
  116. if ((tsk == current) && __is_fpu_owner())
  117. _save_fp(current);
  118. }
  119. return tsk->thread.fpu.fpr;
  120. }
  121. #endif /* _ASM_FPU_H */