fpu.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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/config.h>
  13. #include <linux/sched.h>
  14. #include <linux/thread_info.h>
  15. #include <asm/mipsregs.h>
  16. #include <asm/cpu.h>
  17. #include <asm/cpu-features.h>
  18. #include <asm/bitops.h>
  19. #include <asm/processor.h>
  20. #include <asm/current.h>
  21. #ifdef CONFIG_MIPS_MT_FPAFF
  22. #include <asm/mips_mt.h>
  23. #endif
  24. struct sigcontext;
  25. struct sigcontext32;
  26. extern asmlinkage int (*save_fp_context)(struct sigcontext *sc);
  27. extern asmlinkage int (*restore_fp_context)(struct sigcontext *sc);
  28. extern asmlinkage int (*save_fp_context32)(struct sigcontext32 *sc);
  29. extern asmlinkage int (*restore_fp_context32)(struct sigcontext32 *sc);
  30. extern void fpu_emulator_init_fpu(void);
  31. extern void _init_fpu(void);
  32. extern void _save_fp(struct task_struct *);
  33. extern void _restore_fp(struct task_struct *);
  34. #if defined(CONFIG_CPU_SB1)
  35. #define __enable_fpu_hazard() \
  36. do { \
  37. asm(".set push \n\t" \
  38. ".set mips64 \n\t" \
  39. ".set noreorder \n\t" \
  40. "ssnop \n\t" \
  41. "bnezl $0, .+4 \n\t" \
  42. "ssnop \n\t" \
  43. ".set pop"); \
  44. } while (0)
  45. #else
  46. #define __enable_fpu_hazard() \
  47. do { \
  48. asm("nop;nop;nop;nop"); /* max. hazard */ \
  49. } while (0)
  50. #endif
  51. #define __enable_fpu() \
  52. do { \
  53. set_c0_status(ST0_CU1); \
  54. __enable_fpu_hazard(); \
  55. } while (0)
  56. #define __disable_fpu() \
  57. do { \
  58. clear_c0_status(ST0_CU1); \
  59. /* We don't care about the c0 hazard here */ \
  60. } while (0)
  61. #define enable_fpu() \
  62. do { \
  63. if (cpu_has_fpu) \
  64. __enable_fpu(); \
  65. } while (0)
  66. #define disable_fpu() \
  67. do { \
  68. if (cpu_has_fpu) \
  69. __disable_fpu(); \
  70. } while (0)
  71. #define clear_fpu_owner() clear_thread_flag(TIF_USEDFPU)
  72. static inline int __is_fpu_owner(void)
  73. {
  74. return test_thread_flag(TIF_USEDFPU);
  75. }
  76. static inline int is_fpu_owner(void)
  77. {
  78. return cpu_has_fpu && __is_fpu_owner();
  79. }
  80. static inline void own_fpu(void)
  81. {
  82. if (cpu_has_fpu) {
  83. __enable_fpu();
  84. KSTK_STATUS(current) |= ST0_CU1;
  85. set_thread_flag(TIF_USEDFPU);
  86. }
  87. }
  88. static inline void lose_fpu(void)
  89. {
  90. if (cpu_has_fpu) {
  91. KSTK_STATUS(current) &= ~ST0_CU1;
  92. clear_thread_flag(TIF_USEDFPU);
  93. __disable_fpu();
  94. }
  95. }
  96. static inline void init_fpu(void)
  97. {
  98. if (cpu_has_fpu) {
  99. _init_fpu();
  100. } else {
  101. fpu_emulator_init_fpu();
  102. }
  103. }
  104. static inline void save_fp(struct task_struct *tsk)
  105. {
  106. if (cpu_has_fpu)
  107. _save_fp(tsk);
  108. }
  109. static inline void restore_fp(struct task_struct *tsk)
  110. {
  111. if (cpu_has_fpu)
  112. _restore_fp(tsk);
  113. }
  114. static inline fpureg_t *get_fpu_regs(struct task_struct *tsk)
  115. {
  116. if (cpu_has_fpu) {
  117. if ((tsk == current) && __is_fpu_owner())
  118. _save_fp(current);
  119. return tsk->thread.fpu.hard.fpr;
  120. }
  121. return tsk->thread.fpu.soft.fpr;
  122. }
  123. #endif /* _ASM_FPU_H */