fpu.h 3.0 KB

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