Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*---------------------------------------------------------------------------+
0003  |  fpu_system.h                                                             |
0004  |                                                                           |
0005  | Copyright (C) 1992,1994,1997                                              |
0006  |                       W. Metzenthen, 22 Parker St, Ormond, Vic 3163,      |
0007  |                       Australia.  E-mail   billm@suburbia.net             |
0008  |                                                                           |
0009  +---------------------------------------------------------------------------*/
0010 
0011 #ifndef _FPU_SYSTEM_H
0012 #define _FPU_SYSTEM_H
0013 
0014 /* system dependent definitions */
0015 
0016 #include <linux/sched.h>
0017 #include <linux/kernel.h>
0018 #include <linux/mm.h>
0019 
0020 #include <asm/desc.h>
0021 #include <asm/mmu_context.h>
0022 
0023 static inline struct desc_struct FPU_get_ldt_descriptor(unsigned seg)
0024 {
0025     static struct desc_struct zero_desc;
0026     struct desc_struct ret = zero_desc;
0027 
0028 #ifdef CONFIG_MODIFY_LDT_SYSCALL
0029     seg >>= 3;
0030     mutex_lock(&current->mm->context.lock);
0031     if (current->mm->context.ldt && seg < current->mm->context.ldt->nr_entries)
0032         ret = current->mm->context.ldt->entries[seg];
0033     mutex_unlock(&current->mm->context.lock);
0034 #endif
0035     return ret;
0036 }
0037 
0038 #define SEG_TYPE_WRITABLE   (1U << 1)
0039 #define SEG_TYPE_EXPANDS_DOWN   (1U << 2)
0040 #define SEG_TYPE_EXECUTE    (1U << 3)
0041 #define SEG_TYPE_EXPAND_MASK    (SEG_TYPE_EXPANDS_DOWN | SEG_TYPE_EXECUTE)
0042 #define SEG_TYPE_EXECUTE_MASK   (SEG_TYPE_WRITABLE | SEG_TYPE_EXECUTE)
0043 
0044 static inline unsigned long seg_get_base(struct desc_struct *d)
0045 {
0046     unsigned long base = (unsigned long)d->base2 << 24;
0047 
0048     return base | ((unsigned long)d->base1 << 16) | d->base0;
0049 }
0050 
0051 static inline unsigned long seg_get_limit(struct desc_struct *d)
0052 {
0053     return ((unsigned long)d->limit1 << 16) | d->limit0;
0054 }
0055 
0056 static inline unsigned long seg_get_granularity(struct desc_struct *d)
0057 {
0058     return d->g ? 4096 : 1;
0059 }
0060 
0061 static inline bool seg_expands_down(struct desc_struct *d)
0062 {
0063     return (d->type & SEG_TYPE_EXPAND_MASK) == SEG_TYPE_EXPANDS_DOWN;
0064 }
0065 
0066 static inline bool seg_execute_only(struct desc_struct *d)
0067 {
0068     return (d->type & SEG_TYPE_EXECUTE_MASK) == SEG_TYPE_EXECUTE;
0069 }
0070 
0071 static inline bool seg_writable(struct desc_struct *d)
0072 {
0073     return (d->type & SEG_TYPE_EXECUTE_MASK) == SEG_TYPE_WRITABLE;
0074 }
0075 
0076 #define I387            (&current->thread.fpu.fpstate->regs)
0077 #define FPU_info        (I387->soft.info)
0078 
0079 #define FPU_CS          (*(unsigned short *) &(FPU_info->regs->cs))
0080 #define FPU_SS          (*(unsigned short *) &(FPU_info->regs->ss))
0081 #define FPU_DS          (*(unsigned short *) &(FPU_info->regs->ds))
0082 #define FPU_EAX         (FPU_info->regs->ax)
0083 #define FPU_EFLAGS      (FPU_info->regs->flags)
0084 #define FPU_EIP         (FPU_info->regs->ip)
0085 #define FPU_ORIG_EIP        (FPU_info->___orig_eip)
0086 
0087 #define FPU_lookahead           (I387->soft.lookahead)
0088 
0089 /* nz if ip_offset and cs_selector are not to be set for the current
0090    instruction. */
0091 #define no_ip_update        (*(u_char *)&(I387->soft.no_update))
0092 #define FPU_rm          (*(u_char *)&(I387->soft.rm))
0093 
0094 /* Number of bytes of data which can be legally accessed by the current
0095    instruction. This only needs to hold a number <= 108, so a byte will do. */
0096 #define access_limit        (*(u_char *)&(I387->soft.alimit))
0097 
0098 #define partial_status      (I387->soft.swd)
0099 #define control_word        (I387->soft.cwd)
0100 #define fpu_tag_word        (I387->soft.twd)
0101 #define registers       (I387->soft.st_space)
0102 #define top         (I387->soft.ftop)
0103 
0104 #define instruction_address (*(struct address *)&I387->soft.fip)
0105 #define operand_address     (*(struct address *)&I387->soft.foo)
0106 
0107 #define FPU_access_ok(y,z)  if ( !access_ok(y,z) ) \
0108                 math_abort(FPU_info,SIGSEGV)
0109 #define FPU_abort       math_abort(FPU_info, SIGSEGV)
0110 #define FPU_copy_from_user(to, from, n) \
0111         do { if (copy_from_user(to, from, n)) FPU_abort; } while (0)
0112 
0113 #undef FPU_IGNORE_CODE_SEGV
0114 #ifdef FPU_IGNORE_CODE_SEGV
0115 /* access_ok() is very expensive, and causes the emulator to run
0116    about 20% slower if applied to the code. Anyway, errors due to bad
0117    code addresses should be much rarer than errors due to bad data
0118    addresses. */
0119 #define FPU_code_access_ok(z)
0120 #else
0121 /* A simpler test than access_ok() can probably be done for
0122    FPU_code_access_ok() because the only possible error is to step
0123    past the upper boundary of a legal code area. */
0124 #define FPU_code_access_ok(z) FPU_access_ok((void __user *)FPU_EIP,z)
0125 #endif
0126 
0127 #define FPU_get_user(x,y) do { if (get_user((x),(y))) FPU_abort; } while (0)
0128 #define FPU_put_user(x,y) do { if (put_user((x),(y))) FPU_abort; } while (0)
0129 
0130 #endif