Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /*---------------------------------------------------------------------------+ |
| 3 | | get_address.c | |
| 4 | | | |
| 5 | | Get the effective address from an FPU instruction. | |
| 6 | | | |
| 7 | | Copyright (C) 1992,1993,1994,1997 | |
| 8 | | W. Metzenthen, 22 Parker St, Ormond, Vic 3163, | |
| 9 | | Australia. E-mail billm@suburbia.net | |
| 10 | | | |
| 11 | | | |
| 12 | +---------------------------------------------------------------------------*/ |
| 13 | |
| 14 | /*---------------------------------------------------------------------------+ |
| 15 | | Note: | |
| 16 | | The file contains code which accesses user memory. | |
| 17 | | Emulator static data may change when user memory is accessed, due to | |
| 18 | | other processes using the emulator while swapping is in progress. | |
| 19 | +---------------------------------------------------------------------------*/ |
| 20 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #include <linux/stddef.h> |
| 22 | |
Linus Torvalds | 7c0f6ba | 2016-12-24 11:46:01 -0800 | [diff] [blame] | 23 | #include <linux/uaccess.h> |
Brian Gerst | ba3e127 | 2015-07-29 01:41:21 -0400 | [diff] [blame] | 24 | #include <asm/vm86.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | |
| 26 | #include "fpu_system.h" |
| 27 | #include "exception.h" |
| 28 | #include "fpu_emu.h" |
| 29 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #define FPU_WRITE_BIT 0x10 |
| 31 | |
| 32 | static int reg_offset[] = { |
Tejun Heo | d315760 | 2009-02-09 22:17:39 +0900 | [diff] [blame] | 33 | offsetof(struct pt_regs, ax), |
| 34 | offsetof(struct pt_regs, cx), |
| 35 | offsetof(struct pt_regs, dx), |
| 36 | offsetof(struct pt_regs, bx), |
| 37 | offsetof(struct pt_regs, sp), |
| 38 | offsetof(struct pt_regs, bp), |
| 39 | offsetof(struct pt_regs, si), |
| 40 | offsetof(struct pt_regs, di) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | }; |
| 42 | |
Tejun Heo | d315760 | 2009-02-09 22:17:39 +0900 | [diff] [blame] | 43 | #define REG_(x) (*(long *)(reg_offset[(x)] + (u_char *)FPU_info->regs)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | |
| 45 | static int reg_offset_vm86[] = { |
Tejun Heo | d315760 | 2009-02-09 22:17:39 +0900 | [diff] [blame] | 46 | offsetof(struct pt_regs, cs), |
| 47 | offsetof(struct kernel_vm86_regs, ds), |
| 48 | offsetof(struct kernel_vm86_regs, es), |
| 49 | offsetof(struct kernel_vm86_regs, fs), |
| 50 | offsetof(struct kernel_vm86_regs, gs), |
| 51 | offsetof(struct pt_regs, ss), |
| 52 | offsetof(struct kernel_vm86_regs, ds) |
Ingo Molnar | 3d0d14f | 2008-01-30 13:30:11 +0100 | [diff] [blame] | 53 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | |
| 55 | #define VM86_REG_(x) (*(unsigned short *) \ |
Tejun Heo | d315760 | 2009-02-09 22:17:39 +0900 | [diff] [blame] | 56 | (reg_offset_vm86[((unsigned)x)] + (u_char *)FPU_info->regs)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | static int reg_offset_pm[] = { |
Tejun Heo | d315760 | 2009-02-09 22:17:39 +0900 | [diff] [blame] | 59 | offsetof(struct pt_regs, cs), |
| 60 | offsetof(struct pt_regs, ds), |
| 61 | offsetof(struct pt_regs, es), |
| 62 | offsetof(struct pt_regs, fs), |
| 63 | offsetof(struct pt_regs, ds), /* dummy, not saved on stack */ |
| 64 | offsetof(struct pt_regs, ss), |
| 65 | offsetof(struct pt_regs, ds) |
Ingo Molnar | 3d0d14f | 2008-01-30 13:30:11 +0100 | [diff] [blame] | 66 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | |
| 68 | #define PM_REG_(x) (*(unsigned short *) \ |
Tejun Heo | d315760 | 2009-02-09 22:17:39 +0900 | [diff] [blame] | 69 | (reg_offset_pm[((unsigned)x)] + (u_char *)FPU_info->regs)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | /* Decode the SIB byte. This function assumes mod != 0 */ |
| 72 | static int sib(int mod, unsigned long *fpu_eip) |
| 73 | { |
Ingo Molnar | 3d0d14f | 2008-01-30 13:30:11 +0100 | [diff] [blame] | 74 | u_char ss, index, base; |
| 75 | long offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | |
Ingo Molnar | 3d0d14f | 2008-01-30 13:30:11 +0100 | [diff] [blame] | 77 | RE_ENTRANT_CHECK_OFF; |
| 78 | FPU_code_access_ok(1); |
| 79 | FPU_get_user(base, (u_char __user *) (*fpu_eip)); /* The SIB byte */ |
| 80 | RE_ENTRANT_CHECK_ON; |
| 81 | (*fpu_eip)++; |
| 82 | ss = base >> 6; |
| 83 | index = (base >> 3) & 7; |
| 84 | base &= 7; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | |
Ingo Molnar | 3d0d14f | 2008-01-30 13:30:11 +0100 | [diff] [blame] | 86 | if ((mod == 0) && (base == 5)) |
| 87 | offset = 0; /* No base register */ |
| 88 | else |
| 89 | offset = REG_(base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | |
Ingo Molnar | 3d0d14f | 2008-01-30 13:30:11 +0100 | [diff] [blame] | 91 | if (index == 4) { |
| 92 | /* No index register */ |
| 93 | /* A non-zero ss is illegal */ |
| 94 | if (ss) |
| 95 | EXCEPTION(EX_Invalid); |
| 96 | } else { |
| 97 | offset += (REG_(index)) << ss; |
| 98 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | |
Ingo Molnar | 3d0d14f | 2008-01-30 13:30:11 +0100 | [diff] [blame] | 100 | if (mod == 1) { |
| 101 | /* 8 bit signed displacement */ |
| 102 | long displacement; |
| 103 | RE_ENTRANT_CHECK_OFF; |
| 104 | FPU_code_access_ok(1); |
| 105 | FPU_get_user(displacement, (signed char __user *)(*fpu_eip)); |
| 106 | offset += displacement; |
| 107 | RE_ENTRANT_CHECK_ON; |
| 108 | (*fpu_eip)++; |
| 109 | } else if (mod == 2 || base == 5) { /* The second condition also has mod==0 */ |
| 110 | /* 32 bit displacement */ |
| 111 | long displacement; |
| 112 | RE_ENTRANT_CHECK_OFF; |
| 113 | FPU_code_access_ok(4); |
| 114 | FPU_get_user(displacement, (long __user *)(*fpu_eip)); |
| 115 | offset += displacement; |
| 116 | RE_ENTRANT_CHECK_ON; |
| 117 | (*fpu_eip) += 4; |
| 118 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | |
Ingo Molnar | 3d0d14f | 2008-01-30 13:30:11 +0100 | [diff] [blame] | 120 | return offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | } |
| 122 | |
Ingo Molnar | 3d0d14f | 2008-01-30 13:30:11 +0100 | [diff] [blame] | 123 | static unsigned long vm86_segment(u_char segment, struct address *addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | { |
Ingo Molnar | 3d0d14f | 2008-01-30 13:30:11 +0100 | [diff] [blame] | 125 | segment--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | #ifdef PARANOID |
Ingo Molnar | 3d0d14f | 2008-01-30 13:30:11 +0100 | [diff] [blame] | 127 | if (segment > PREFIX_SS_) { |
| 128 | EXCEPTION(EX_INTERNAL | 0x130); |
| 129 | math_abort(FPU_info, SIGSEGV); |
| 130 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | #endif /* PARANOID */ |
Ingo Molnar | 3d0d14f | 2008-01-30 13:30:11 +0100 | [diff] [blame] | 132 | addr->selector = VM86_REG_(segment); |
| 133 | return (unsigned long)VM86_REG_(segment) << 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | } |
| 135 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | /* This should work for 16 and 32 bit protected mode. */ |
| 137 | static long pm_address(u_char FPU_modrm, u_char segment, |
| 138 | struct address *addr, long offset) |
Ingo Molnar | 3d0d14f | 2008-01-30 13:30:11 +0100 | [diff] [blame] | 139 | { |
| 140 | struct desc_struct descriptor; |
| 141 | unsigned long base_address, limit, address, seg_top; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | |
Ingo Molnar | 3d0d14f | 2008-01-30 13:30:11 +0100 | [diff] [blame] | 143 | segment--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | |
| 145 | #ifdef PARANOID |
Ingo Molnar | 3d0d14f | 2008-01-30 13:30:11 +0100 | [diff] [blame] | 146 | /* segment is unsigned, so this also detects if segment was 0: */ |
| 147 | if (segment > PREFIX_SS_) { |
| 148 | EXCEPTION(EX_INTERNAL | 0x132); |
| 149 | math_abort(FPU_info, SIGSEGV); |
| 150 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | #endif /* PARANOID */ |
| 152 | |
Ingo Molnar | 3d0d14f | 2008-01-30 13:30:11 +0100 | [diff] [blame] | 153 | switch (segment) { |
Ingo Molnar | 3d0d14f | 2008-01-30 13:30:11 +0100 | [diff] [blame] | 154 | case PREFIX_GS_ - 1: |
Tejun Heo | d9a89a2 | 2009-02-09 22:17:40 +0900 | [diff] [blame] | 155 | /* user gs handling can be lazy, use special accessors */ |
| 156 | addr->selector = get_user_gs(FPU_info->regs); |
Ingo Molnar | 3d0d14f | 2008-01-30 13:30:11 +0100 | [diff] [blame] | 157 | break; |
| 158 | default: |
| 159 | addr->selector = PM_REG_(segment); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | |
Andy Lutomirski | 12e244f | 2015-08-14 15:02:55 -0700 | [diff] [blame] | 162 | descriptor = FPU_get_ldt_descriptor(addr->selector); |
Thomas Gleixner | 718f5d0 | 2017-08-28 08:47:39 +0200 | [diff] [blame] | 163 | base_address = seg_get_base(&descriptor); |
Ingo Molnar | 3d0d14f | 2008-01-30 13:30:11 +0100 | [diff] [blame] | 164 | address = base_address + offset; |
Thomas Gleixner | 718f5d0 | 2017-08-28 08:47:39 +0200 | [diff] [blame] | 165 | limit = seg_get_limit(&descriptor) + 1; |
| 166 | limit *= seg_get_granularity(&descriptor); |
| 167 | limit += base_address - 1; |
Ingo Molnar | 3d0d14f | 2008-01-30 13:30:11 +0100 | [diff] [blame] | 168 | if (limit < base_address) |
| 169 | limit = 0xffffffff; |
| 170 | |
Thomas Gleixner | 718f5d0 | 2017-08-28 08:47:39 +0200 | [diff] [blame] | 171 | if (seg_expands_down(&descriptor)) { |
| 172 | if (descriptor.g) { |
Ingo Molnar | 3d0d14f | 2008-01-30 13:30:11 +0100 | [diff] [blame] | 173 | seg_top = 0xffffffff; |
Thomas Gleixner | 718f5d0 | 2017-08-28 08:47:39 +0200 | [diff] [blame] | 174 | } else { |
Ingo Molnar | 3d0d14f | 2008-01-30 13:30:11 +0100 | [diff] [blame] | 175 | seg_top = base_address + (1 << 20); |
| 176 | if (seg_top < base_address) |
| 177 | seg_top = 0xffffffff; |
| 178 | } |
| 179 | access_limit = |
| 180 | (address <= limit) || (address >= seg_top) ? 0 : |
| 181 | ((seg_top - address) >= 255 ? 255 : seg_top - address); |
| 182 | } else { |
| 183 | access_limit = |
| 184 | (address > limit) || (address < base_address) ? 0 : |
| 185 | ((limit - address) >= 254 ? 255 : limit - address + 1); |
| 186 | } |
Thomas Gleixner | 718f5d0 | 2017-08-28 08:47:39 +0200 | [diff] [blame] | 187 | if (seg_execute_only(&descriptor) || |
| 188 | (!seg_writable(&descriptor) && (FPU_modrm & FPU_WRITE_BIT))) { |
Ingo Molnar | 3d0d14f | 2008-01-30 13:30:11 +0100 | [diff] [blame] | 189 | access_limit = 0; |
| 190 | } |
| 191 | return address; |
| 192 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | |
| 194 | /* |
| 195 | MOD R/M byte: MOD == 3 has a special use for the FPU |
| 196 | SIB byte used iff R/M = 100b |
| 197 | |
| 198 | 7 6 5 4 3 2 1 0 |
| 199 | ..... ......... ......... |
| 200 | MOD OPCODE(2) R/M |
| 201 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | SIB byte |
| 203 | |
| 204 | 7 6 5 4 3 2 1 0 |
| 205 | ..... ......... ......... |
| 206 | SS INDEX BASE |
| 207 | |
| 208 | */ |
| 209 | |
| 210 | void __user *FPU_get_address(u_char FPU_modrm, unsigned long *fpu_eip, |
Ingo Molnar | 3d0d14f | 2008-01-30 13:30:11 +0100 | [diff] [blame] | 211 | struct address *addr, fpu_addr_modes addr_modes) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | { |
Ingo Molnar | 3d0d14f | 2008-01-30 13:30:11 +0100 | [diff] [blame] | 213 | u_char mod; |
| 214 | unsigned rm = FPU_modrm & 7; |
| 215 | long *cpu_reg_ptr; |
| 216 | int address = 0; /* Initialized just to stop compiler warnings. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | |
Ingo Molnar | 3d0d14f | 2008-01-30 13:30:11 +0100 | [diff] [blame] | 218 | /* Memory accessed via the cs selector is write protected |
| 219 | in `non-segmented' 32 bit protected mode. */ |
| 220 | if (!addr_modes.default_mode && (FPU_modrm & FPU_WRITE_BIT) |
| 221 | && (addr_modes.override.segment == PREFIX_CS_)) { |
| 222 | math_abort(FPU_info, SIGSEGV); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | |
Ingo Molnar | 3d0d14f | 2008-01-30 13:30:11 +0100 | [diff] [blame] | 225 | addr->selector = FPU_DS; /* Default, for 32 bit non-segmented mode. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | |
Ingo Molnar | 3d0d14f | 2008-01-30 13:30:11 +0100 | [diff] [blame] | 227 | mod = (FPU_modrm >> 6) & 3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | |
Ingo Molnar | 3d0d14f | 2008-01-30 13:30:11 +0100 | [diff] [blame] | 229 | if (rm == 4 && mod != 3) { |
| 230 | address = sib(mod, fpu_eip); |
| 231 | } else { |
| 232 | cpu_reg_ptr = ®_(rm); |
| 233 | switch (mod) { |
| 234 | case 0: |
| 235 | if (rm == 5) { |
| 236 | /* Special case: disp32 */ |
| 237 | RE_ENTRANT_CHECK_OFF; |
| 238 | FPU_code_access_ok(4); |
| 239 | FPU_get_user(address, |
| 240 | (unsigned long __user |
| 241 | *)(*fpu_eip)); |
| 242 | (*fpu_eip) += 4; |
| 243 | RE_ENTRANT_CHECK_ON; |
| 244 | addr->offset = address; |
| 245 | return (void __user *)address; |
| 246 | } else { |
| 247 | address = *cpu_reg_ptr; /* Just return the contents |
| 248 | of the cpu register */ |
| 249 | addr->offset = address; |
| 250 | return (void __user *)address; |
| 251 | } |
| 252 | case 1: |
| 253 | /* 8 bit signed displacement */ |
| 254 | RE_ENTRANT_CHECK_OFF; |
| 255 | FPU_code_access_ok(1); |
| 256 | FPU_get_user(address, (signed char __user *)(*fpu_eip)); |
| 257 | RE_ENTRANT_CHECK_ON; |
| 258 | (*fpu_eip)++; |
| 259 | break; |
| 260 | case 2: |
| 261 | /* 32 bit displacement */ |
| 262 | RE_ENTRANT_CHECK_OFF; |
| 263 | FPU_code_access_ok(4); |
| 264 | FPU_get_user(address, (long __user *)(*fpu_eip)); |
| 265 | (*fpu_eip) += 4; |
| 266 | RE_ENTRANT_CHECK_ON; |
| 267 | break; |
| 268 | case 3: |
| 269 | /* Not legal for the FPU */ |
| 270 | EXCEPTION(EX_Invalid); |
| 271 | } |
| 272 | address += *cpu_reg_ptr; |
| 273 | } |
| 274 | |
| 275 | addr->offset = address; |
| 276 | |
| 277 | switch (addr_modes.default_mode) { |
| 278 | case 0: |
| 279 | break; |
| 280 | case VM86: |
| 281 | address += vm86_segment(addr_modes.override.segment, addr); |
| 282 | break; |
| 283 | case PM16: |
| 284 | case SEG32: |
| 285 | address = pm_address(FPU_modrm, addr_modes.override.segment, |
| 286 | addr, address); |
| 287 | break; |
| 288 | default: |
| 289 | EXCEPTION(EX_INTERNAL | 0x133); |
| 290 | } |
| 291 | |
| 292 | return (void __user *)address; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | } |
| 294 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | void __user *FPU_get_address_16(u_char FPU_modrm, unsigned long *fpu_eip, |
Ingo Molnar | 3d0d14f | 2008-01-30 13:30:11 +0100 | [diff] [blame] | 296 | struct address *addr, fpu_addr_modes addr_modes) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | { |
Ingo Molnar | 3d0d14f | 2008-01-30 13:30:11 +0100 | [diff] [blame] | 298 | u_char mod; |
| 299 | unsigned rm = FPU_modrm & 7; |
| 300 | int address = 0; /* Default used for mod == 0 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | |
Ingo Molnar | 3d0d14f | 2008-01-30 13:30:11 +0100 | [diff] [blame] | 302 | /* Memory accessed via the cs selector is write protected |
| 303 | in `non-segmented' 32 bit protected mode. */ |
| 304 | if (!addr_modes.default_mode && (FPU_modrm & FPU_WRITE_BIT) |
| 305 | && (addr_modes.override.segment == PREFIX_CS_)) { |
| 306 | math_abort(FPU_info, SIGSEGV); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | |
Ingo Molnar | 3d0d14f | 2008-01-30 13:30:11 +0100 | [diff] [blame] | 309 | addr->selector = FPU_DS; /* Default, for 32 bit non-segmented mode. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | |
Ingo Molnar | 3d0d14f | 2008-01-30 13:30:11 +0100 | [diff] [blame] | 311 | mod = (FPU_modrm >> 6) & 3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | |
Ingo Molnar | 3d0d14f | 2008-01-30 13:30:11 +0100 | [diff] [blame] | 313 | switch (mod) { |
| 314 | case 0: |
| 315 | if (rm == 6) { |
| 316 | /* Special case: disp16 */ |
| 317 | RE_ENTRANT_CHECK_OFF; |
| 318 | FPU_code_access_ok(2); |
| 319 | FPU_get_user(address, |
| 320 | (unsigned short __user *)(*fpu_eip)); |
| 321 | (*fpu_eip) += 2; |
| 322 | RE_ENTRANT_CHECK_ON; |
| 323 | goto add_segment; |
| 324 | } |
| 325 | break; |
| 326 | case 1: |
| 327 | /* 8 bit signed displacement */ |
| 328 | RE_ENTRANT_CHECK_OFF; |
| 329 | FPU_code_access_ok(1); |
| 330 | FPU_get_user(address, (signed char __user *)(*fpu_eip)); |
| 331 | RE_ENTRANT_CHECK_ON; |
| 332 | (*fpu_eip)++; |
| 333 | break; |
| 334 | case 2: |
| 335 | /* 16 bit displacement */ |
| 336 | RE_ENTRANT_CHECK_OFF; |
| 337 | FPU_code_access_ok(2); |
| 338 | FPU_get_user(address, (unsigned short __user *)(*fpu_eip)); |
| 339 | (*fpu_eip) += 2; |
| 340 | RE_ENTRANT_CHECK_ON; |
| 341 | break; |
| 342 | case 3: |
| 343 | /* Not legal for the FPU */ |
| 344 | EXCEPTION(EX_Invalid); |
| 345 | break; |
| 346 | } |
| 347 | switch (rm) { |
| 348 | case 0: |
Tejun Heo | d315760 | 2009-02-09 22:17:39 +0900 | [diff] [blame] | 349 | address += FPU_info->regs->bx + FPU_info->regs->si; |
Ingo Molnar | 3d0d14f | 2008-01-30 13:30:11 +0100 | [diff] [blame] | 350 | break; |
| 351 | case 1: |
Tejun Heo | d315760 | 2009-02-09 22:17:39 +0900 | [diff] [blame] | 352 | address += FPU_info->regs->bx + FPU_info->regs->di; |
Ingo Molnar | 3d0d14f | 2008-01-30 13:30:11 +0100 | [diff] [blame] | 353 | break; |
| 354 | case 2: |
Tejun Heo | d315760 | 2009-02-09 22:17:39 +0900 | [diff] [blame] | 355 | address += FPU_info->regs->bp + FPU_info->regs->si; |
Ingo Molnar | 3d0d14f | 2008-01-30 13:30:11 +0100 | [diff] [blame] | 356 | if (addr_modes.override.segment == PREFIX_DEFAULT) |
| 357 | addr_modes.override.segment = PREFIX_SS_; |
| 358 | break; |
| 359 | case 3: |
Tejun Heo | d315760 | 2009-02-09 22:17:39 +0900 | [diff] [blame] | 360 | address += FPU_info->regs->bp + FPU_info->regs->di; |
Ingo Molnar | 3d0d14f | 2008-01-30 13:30:11 +0100 | [diff] [blame] | 361 | if (addr_modes.override.segment == PREFIX_DEFAULT) |
| 362 | addr_modes.override.segment = PREFIX_SS_; |
| 363 | break; |
| 364 | case 4: |
Tejun Heo | d315760 | 2009-02-09 22:17:39 +0900 | [diff] [blame] | 365 | address += FPU_info->regs->si; |
Ingo Molnar | 3d0d14f | 2008-01-30 13:30:11 +0100 | [diff] [blame] | 366 | break; |
| 367 | case 5: |
Tejun Heo | d315760 | 2009-02-09 22:17:39 +0900 | [diff] [blame] | 368 | address += FPU_info->regs->di; |
Ingo Molnar | 3d0d14f | 2008-01-30 13:30:11 +0100 | [diff] [blame] | 369 | break; |
| 370 | case 6: |
Tejun Heo | d315760 | 2009-02-09 22:17:39 +0900 | [diff] [blame] | 371 | address += FPU_info->regs->bp; |
Ingo Molnar | 3d0d14f | 2008-01-30 13:30:11 +0100 | [diff] [blame] | 372 | if (addr_modes.override.segment == PREFIX_DEFAULT) |
| 373 | addr_modes.override.segment = PREFIX_SS_; |
| 374 | break; |
| 375 | case 7: |
Tejun Heo | d315760 | 2009-02-09 22:17:39 +0900 | [diff] [blame] | 376 | address += FPU_info->regs->bx; |
Ingo Molnar | 3d0d14f | 2008-01-30 13:30:11 +0100 | [diff] [blame] | 377 | break; |
| 378 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | |
Ingo Molnar | 3d0d14f | 2008-01-30 13:30:11 +0100 | [diff] [blame] | 380 | add_segment: |
| 381 | address &= 0xffff; |
| 382 | |
| 383 | addr->offset = address; |
| 384 | |
| 385 | switch (addr_modes.default_mode) { |
| 386 | case 0: |
| 387 | break; |
| 388 | case VM86: |
| 389 | address += vm86_segment(addr_modes.override.segment, addr); |
| 390 | break; |
| 391 | case PM16: |
| 392 | case SEG32: |
| 393 | address = pm_address(FPU_modrm, addr_modes.override.segment, |
| 394 | addr, address); |
| 395 | break; |
| 396 | default: |
| 397 | EXCEPTION(EX_INTERNAL | 0x131); |
| 398 | } |
| 399 | |
| 400 | return (void __user *)address; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | } |