fpu.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /* MN10300 FPU definitions
  2. *
  3. * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
  4. * Written by David Howells (dhowells@redhat.com)
  5. * Derived from include/asm-i386/i387.h: Copyright (C) 1994 Linus Torvalds
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public Licence
  9. * as published by the Free Software Foundation; either version
  10. * 2 of the Licence, or (at your option) any later version.
  11. */
  12. #ifndef _ASM_FPU_H
  13. #define _ASM_FPU_H
  14. #ifndef __ASSEMBLY__
  15. #include <linux/sched.h>
  16. #include <asm/exceptions.h>
  17. #include <asm/sigcontext.h>
  18. #ifdef __KERNEL__
  19. extern asmlinkage void fpu_disabled(void);
  20. #ifdef CONFIG_FPU
  21. #ifdef CONFIG_LAZY_SAVE_FPU
  22. /* the task that currently owns the FPU state */
  23. extern struct task_struct *fpu_state_owner;
  24. #endif
  25. #if (THREAD_USING_FPU & ~0xff)
  26. #error THREAD_USING_FPU must be smaller than 0x100.
  27. #endif
  28. static inline void set_using_fpu(struct task_struct *tsk)
  29. {
  30. asm volatile(
  31. "bset %0,(0,%1)"
  32. :
  33. : "i"(THREAD_USING_FPU), "a"(&tsk->thread.fpu_flags)
  34. : "memory", "cc");
  35. }
  36. static inline void clear_using_fpu(struct task_struct *tsk)
  37. {
  38. asm volatile(
  39. "bclr %0,(0,%1)"
  40. :
  41. : "i"(THREAD_USING_FPU), "a"(&tsk->thread.fpu_flags)
  42. : "memory", "cc");
  43. }
  44. #define is_using_fpu(tsk) ((tsk)->thread.fpu_flags & THREAD_USING_FPU)
  45. extern asmlinkage void fpu_kill_state(struct task_struct *);
  46. extern asmlinkage void fpu_exception(struct pt_regs *, enum exception_code);
  47. extern asmlinkage void fpu_invalid_op(struct pt_regs *, enum exception_code);
  48. extern asmlinkage void fpu_init_state(void);
  49. extern asmlinkage void fpu_save(struct fpu_state_struct *);
  50. extern int fpu_setup_sigcontext(struct fpucontext *buf);
  51. extern int fpu_restore_sigcontext(struct fpucontext *buf);
  52. static inline void unlazy_fpu(struct task_struct *tsk)
  53. {
  54. preempt_disable();
  55. #ifndef CONFIG_LAZY_SAVE_FPU
  56. if (tsk->thread.fpu_flags & THREAD_HAS_FPU) {
  57. fpu_save(&tsk->thread.fpu_state);
  58. tsk->thread.fpu_flags &= ~THREAD_HAS_FPU;
  59. tsk->thread.uregs->epsw &= ~EPSW_FE;
  60. }
  61. #else
  62. if (fpu_state_owner == tsk)
  63. fpu_save(&tsk->thread.fpu_state);
  64. #endif
  65. preempt_enable();
  66. }
  67. static inline void exit_fpu(void)
  68. {
  69. #ifdef CONFIG_LAZY_SAVE_FPU
  70. struct task_struct *tsk = current;
  71. preempt_disable();
  72. if (fpu_state_owner == tsk)
  73. fpu_state_owner = NULL;
  74. preempt_enable();
  75. #endif
  76. }
  77. static inline void flush_fpu(void)
  78. {
  79. struct task_struct *tsk = current;
  80. preempt_disable();
  81. #ifndef CONFIG_LAZY_SAVE_FPU
  82. if (tsk->thread.fpu_flags & THREAD_HAS_FPU) {
  83. tsk->thread.fpu_flags &= ~THREAD_HAS_FPU;
  84. tsk->thread.uregs->epsw &= ~EPSW_FE;
  85. }
  86. #else
  87. if (fpu_state_owner == tsk) {
  88. fpu_state_owner = NULL;
  89. tsk->thread.uregs->epsw &= ~EPSW_FE;
  90. }
  91. #endif
  92. preempt_enable();
  93. clear_using_fpu(tsk);
  94. }
  95. #else /* CONFIG_FPU */
  96. extern asmlinkage
  97. void unexpected_fpu_exception(struct pt_regs *, enum exception_code);
  98. #define fpu_invalid_op unexpected_fpu_exception
  99. #define fpu_exception unexpected_fpu_exception
  100. struct task_struct;
  101. struct fpu_state_struct;
  102. static inline bool is_using_fpu(struct task_struct *tsk) { return false; }
  103. static inline void set_using_fpu(struct task_struct *tsk) {}
  104. static inline void clear_using_fpu(struct task_struct *tsk) {}
  105. static inline void fpu_init_state(void) {}
  106. static inline void fpu_save(struct fpu_state_struct *s) {}
  107. static inline void fpu_kill_state(struct task_struct *tsk) {}
  108. static inline void unlazy_fpu(struct task_struct *tsk) {}
  109. static inline void exit_fpu(void) {}
  110. static inline void flush_fpu(void) {}
  111. static inline int fpu_setup_sigcontext(struct fpucontext *buf) { return 0; }
  112. static inline int fpu_restore_sigcontext(struct fpucontext *buf) { return 0; }
  113. #endif /* CONFIG_FPU */
  114. #endif /* __KERNEL__ */
  115. #endif /* !__ASSEMBLY__ */
  116. #endif /* _ASM_FPU_H */