fpu.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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_init_state(void);
  48. extern asmlinkage void fpu_save(struct fpu_state_struct *);
  49. extern int fpu_setup_sigcontext(struct fpucontext *buf);
  50. extern int fpu_restore_sigcontext(struct fpucontext *buf);
  51. static inline void unlazy_fpu(struct task_struct *tsk)
  52. {
  53. preempt_disable();
  54. #ifndef CONFIG_LAZY_SAVE_FPU
  55. if (tsk->thread.fpu_flags & THREAD_HAS_FPU) {
  56. fpu_save(&tsk->thread.fpu_state);
  57. tsk->thread.fpu_flags &= ~THREAD_HAS_FPU;
  58. tsk->thread.uregs->epsw &= ~EPSW_FE;
  59. }
  60. #else
  61. if (fpu_state_owner == tsk)
  62. fpu_save(&tsk->thread.fpu_state);
  63. #endif
  64. preempt_enable();
  65. }
  66. static inline void exit_fpu(void)
  67. {
  68. #ifdef CONFIG_LAZY_SAVE_FPU
  69. struct task_struct *tsk = current;
  70. preempt_disable();
  71. if (fpu_state_owner == tsk)
  72. fpu_state_owner = NULL;
  73. preempt_enable();
  74. #endif
  75. }
  76. static inline void flush_fpu(void)
  77. {
  78. struct task_struct *tsk = current;
  79. preempt_disable();
  80. #ifndef CONFIG_LAZY_SAVE_FPU
  81. if (tsk->thread.fpu_flags & THREAD_HAS_FPU) {
  82. tsk->thread.fpu_flags &= ~THREAD_HAS_FPU;
  83. tsk->thread.uregs->epsw &= ~EPSW_FE;
  84. }
  85. #else
  86. if (fpu_state_owner == tsk) {
  87. fpu_state_owner = NULL;
  88. tsk->thread.uregs->epsw &= ~EPSW_FE;
  89. }
  90. #endif
  91. preempt_enable();
  92. clear_using_fpu(tsk);
  93. }
  94. #else /* CONFIG_FPU */
  95. extern asmlinkage
  96. void unexpected_fpu_exception(struct pt_regs *, enum exception_code);
  97. #define fpu_exception unexpected_fpu_exception
  98. struct task_struct;
  99. struct fpu_state_struct;
  100. static inline bool is_using_fpu(struct task_struct *tsk) { return false; }
  101. static inline void set_using_fpu(struct task_struct *tsk) {}
  102. static inline void clear_using_fpu(struct task_struct *tsk) {}
  103. static inline void fpu_init_state(void) {}
  104. static inline void fpu_save(struct fpu_state_struct *s) {}
  105. static inline void fpu_kill_state(struct task_struct *tsk) {}
  106. static inline void unlazy_fpu(struct task_struct *tsk) {}
  107. static inline void exit_fpu(void) {}
  108. static inline void flush_fpu(void) {}
  109. static inline int fpu_setup_sigcontext(struct fpucontext *buf) { return 0; }
  110. static inline int fpu_restore_sigcontext(struct fpucontext *buf) { return 0; }
  111. #endif /* CONFIG_FPU */
  112. #endif /* __KERNEL__ */
  113. #endif /* !__ASSEMBLY__ */
  114. #endif /* _ASM_FPU_H */