fpu_system.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*---------------------------------------------------------------------------+
  3. | fpu_system.h |
  4. | |
  5. | Copyright (C) 1992,1994,1997 |
  6. | W. Metzenthen, 22 Parker St, Ormond, Vic 3163, |
  7. | Australia. E-mail billm@suburbia.net |
  8. | |
  9. +---------------------------------------------------------------------------*/
  10. #ifndef _FPU_SYSTEM_H
  11. #define _FPU_SYSTEM_H
  12. /* system dependent definitions */
  13. #include <linux/sched.h>
  14. #include <linux/kernel.h>
  15. #include <linux/mm.h>
  16. #include <asm/desc.h>
  17. #include <asm/mmu_context.h>
  18. static inline struct desc_struct FPU_get_ldt_descriptor(unsigned seg)
  19. {
  20. static struct desc_struct zero_desc;
  21. struct desc_struct ret = zero_desc;
  22. #ifdef CONFIG_MODIFY_LDT_SYSCALL
  23. seg >>= 3;
  24. mutex_lock(&current->mm->context.lock);
  25. if (current->mm->context.ldt && seg < current->mm->context.ldt->nr_entries)
  26. ret = current->mm->context.ldt->entries[seg];
  27. mutex_unlock(&current->mm->context.lock);
  28. #endif
  29. return ret;
  30. }
  31. #define SEG_TYPE_WRITABLE (1U << 1)
  32. #define SEG_TYPE_EXPANDS_DOWN (1U << 2)
  33. #define SEG_TYPE_EXECUTE (1U << 3)
  34. #define SEG_TYPE_EXPAND_MASK (SEG_TYPE_EXPANDS_DOWN | SEG_TYPE_EXECUTE)
  35. #define SEG_TYPE_EXECUTE_MASK (SEG_TYPE_WRITABLE | SEG_TYPE_EXECUTE)
  36. static inline unsigned long seg_get_base(struct desc_struct *d)
  37. {
  38. unsigned long base = (unsigned long)d->base2 << 24;
  39. return base | ((unsigned long)d->base1 << 16) | d->base0;
  40. }
  41. static inline unsigned long seg_get_limit(struct desc_struct *d)
  42. {
  43. return ((unsigned long)d->limit1 << 16) | d->limit0;
  44. }
  45. static inline unsigned long seg_get_granularity(struct desc_struct *d)
  46. {
  47. return d->g ? 4096 : 1;
  48. }
  49. static inline bool seg_expands_down(struct desc_struct *d)
  50. {
  51. return (d->type & SEG_TYPE_EXPAND_MASK) == SEG_TYPE_EXPANDS_DOWN;
  52. }
  53. static inline bool seg_execute_only(struct desc_struct *d)
  54. {
  55. return (d->type & SEG_TYPE_EXECUTE_MASK) == SEG_TYPE_EXECUTE;
  56. }
  57. static inline bool seg_writable(struct desc_struct *d)
  58. {
  59. return (d->type & SEG_TYPE_EXECUTE_MASK) == SEG_TYPE_WRITABLE;
  60. }
  61. #define I387 (&current->thread.fpu.state)
  62. #define FPU_info (I387->soft.info)
  63. #define FPU_CS (*(unsigned short *) &(FPU_info->regs->cs))
  64. #define FPU_SS (*(unsigned short *) &(FPU_info->regs->ss))
  65. #define FPU_DS (*(unsigned short *) &(FPU_info->regs->ds))
  66. #define FPU_EAX (FPU_info->regs->ax)
  67. #define FPU_EFLAGS (FPU_info->regs->flags)
  68. #define FPU_EIP (FPU_info->regs->ip)
  69. #define FPU_ORIG_EIP (FPU_info->___orig_eip)
  70. #define FPU_lookahead (I387->soft.lookahead)
  71. /* nz if ip_offset and cs_selector are not to be set for the current
  72. instruction. */
  73. #define no_ip_update (*(u_char *)&(I387->soft.no_update))
  74. #define FPU_rm (*(u_char *)&(I387->soft.rm))
  75. /* Number of bytes of data which can be legally accessed by the current
  76. instruction. This only needs to hold a number <= 108, so a byte will do. */
  77. #define access_limit (*(u_char *)&(I387->soft.alimit))
  78. #define partial_status (I387->soft.swd)
  79. #define control_word (I387->soft.cwd)
  80. #define fpu_tag_word (I387->soft.twd)
  81. #define registers (I387->soft.st_space)
  82. #define top (I387->soft.ftop)
  83. #define instruction_address (*(struct address *)&I387->soft.fip)
  84. #define operand_address (*(struct address *)&I387->soft.foo)
  85. #define FPU_access_ok(x,y,z) if ( !access_ok(x,y,z) ) \
  86. math_abort(FPU_info,SIGSEGV)
  87. #define FPU_abort math_abort(FPU_info, SIGSEGV)
  88. #undef FPU_IGNORE_CODE_SEGV
  89. #ifdef FPU_IGNORE_CODE_SEGV
  90. /* access_ok() is very expensive, and causes the emulator to run
  91. about 20% slower if applied to the code. Anyway, errors due to bad
  92. code addresses should be much rarer than errors due to bad data
  93. addresses. */
  94. #define FPU_code_access_ok(z)
  95. #else
  96. /* A simpler test than access_ok() can probably be done for
  97. FPU_code_access_ok() because the only possible error is to step
  98. past the upper boundary of a legal code area. */
  99. #define FPU_code_access_ok(z) FPU_access_ok(VERIFY_READ,(void __user *)FPU_EIP,z)
  100. #endif
  101. #define FPU_get_user(x,y) get_user((x),(y))
  102. #define FPU_put_user(x,y) put_user((x),(y))
  103. #endif