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