Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 1 | /**************************************************************************** |
| 2 | * |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 3 | * Realmode X86 Emulator Library |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 4 | * |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 5 | * Copyright (C) 1991-2004 SciTech Software, Inc. |
| 6 | * Copyright (C) David Mosberger-Tang |
| 7 | * Copyright (C) 1999 Egbert Eich |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 8 | * |
| 9 | * ======================================================================== |
| 10 | * |
| 11 | * Permission to use, copy, modify, distribute, and sell this software and |
| 12 | * its documentation for any purpose is hereby granted without fee, |
| 13 | * provided that the above copyright notice appear in all copies and that |
| 14 | * both that copyright notice and this permission notice appear in |
| 15 | * supporting documentation, and that the name of the authors not be used |
| 16 | * in advertising or publicity pertaining to distribution of the software |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 17 | * without specific, written prior permission. The authors makes no |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 18 | * representations about the suitability of this software for any purpose. |
| 19 | * It is provided "as is" without express or implied warranty. |
| 20 | * |
| 21 | * THE AUTHORS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, |
| 22 | * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO |
| 23 | * EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR |
| 24 | * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF |
| 25 | * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR |
| 26 | * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
| 27 | * PERFORMANCE OF THIS SOFTWARE. |
| 28 | * |
| 29 | * ======================================================================== |
| 30 | * |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 31 | * Language: ANSI C |
| 32 | * Environment: Any |
| 33 | * Developer: Kendall Bennett |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 34 | * |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 35 | * Description: This file includes subroutines which are related to |
| 36 | * instruction decoding and accessess of immediate data via IP. etc. |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 37 | * |
| 38 | ****************************************************************************/ |
Michal Simek | c73a477 | 2007-08-16 10:46:28 +0200 | [diff] [blame] | 39 | #include <common.h> |
Simon Glass | bdd5f81 | 2023-09-14 18:21:46 -0600 | [diff] [blame] | 40 | #include <linux/printk.h> |
Michal Simek | 952d861 | 2007-08-15 21:15:05 +0200 | [diff] [blame] | 41 | #include "x86emu/x86emui.h" |
| 42 | |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 43 | /*----------------------------- Implementation ----------------------------*/ |
| 44 | |
| 45 | /**************************************************************************** |
| 46 | REMARKS: |
| 47 | Handles any pending asychronous interrupts. |
| 48 | ****************************************************************************/ |
| 49 | static void x86emu_intr_handle(void) |
| 50 | { |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 51 | u8 intno; |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 52 | |
| 53 | if (M.x86.intr & INTR_SYNCH) { |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 54 | intno = M.x86.intno; |
| 55 | if (_X86EMU_intrTab[intno]) { |
| 56 | (*_X86EMU_intrTab[intno])(intno); |
| 57 | } else { |
| 58 | push_word((u16)M.x86.R_FLG); |
| 59 | CLEAR_FLAG(F_IF); |
| 60 | CLEAR_FLAG(F_TF); |
| 61 | push_word(M.x86.R_CS); |
| 62 | M.x86.R_CS = mem_access_word(intno * 4 + 2); |
| 63 | push_word(M.x86.R_IP); |
| 64 | M.x86.R_IP = mem_access_word(intno * 4); |
| 65 | M.x86.intr = 0; |
| 66 | } |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 67 | } |
| 68 | } |
| 69 | |
| 70 | /**************************************************************************** |
| 71 | PARAMETERS: |
| 72 | intrnum - Interrupt number to raise |
| 73 | |
| 74 | REMARKS: |
| 75 | Raise the specified interrupt to be handled before the execution of the |
| 76 | next instruction. |
| 77 | ****************************************************************************/ |
| 78 | void x86emu_intr_raise( |
| 79 | u8 intrnum) |
| 80 | { |
| 81 | M.x86.intno = intrnum; |
| 82 | M.x86.intr |= INTR_SYNCH; |
| 83 | } |
| 84 | |
| 85 | /**************************************************************************** |
| 86 | REMARKS: |
| 87 | Main execution loop for the emulator. We return from here when the system |
| 88 | halts, which is normally caused by a stack fault when we return from the |
| 89 | original real mode call. |
| 90 | ****************************************************************************/ |
| 91 | void X86EMU_exec(void) |
| 92 | { |
| 93 | u8 op1; |
| 94 | |
| 95 | M.x86.intr = 0; |
| 96 | DB(x86emu_end_instr();) |
| 97 | |
| 98 | for (;;) { |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 99 | DB( if (CHECK_IP_FETCH()) |
| 100 | x86emu_check_ip_access();) |
| 101 | /* If debugging, save the IP and CS values. */ |
| 102 | SAVE_IP_CS(M.x86.R_CS, M.x86.R_IP); |
| 103 | INC_DECODED_INST_LEN(1); |
| 104 | if (M.x86.intr) { |
| 105 | if (M.x86.intr & INTR_HALTED) { |
| 106 | DB( if (M.x86.R_SP != 0) { |
| 107 | printk("halted\n"); |
| 108 | X86EMU_trace_regs(); |
| 109 | } |
| 110 | else { |
| 111 | if (M.x86.debug) |
| 112 | printk("Service completed successfully\n"); |
| 113 | }) |
| 114 | return; |
| 115 | } |
| 116 | if (((M.x86.intr & INTR_SYNCH) && (M.x86.intno == 0 || M.x86.intno == 2)) || |
| 117 | !ACCESS_FLAG(F_IF)) { |
| 118 | x86emu_intr_handle(); |
| 119 | } |
| 120 | } |
| 121 | op1 = (*sys_rdb)(((u32)M.x86.R_CS << 4) + (M.x86.R_IP++)); |
| 122 | (*x86emu_optab[op1])(op1); |
| 123 | if (M.x86.debug & DEBUG_EXIT) { |
| 124 | M.x86.debug &= ~DEBUG_EXIT; |
| 125 | return; |
| 126 | } |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 127 | } |
| 128 | } |
| 129 | |
| 130 | /**************************************************************************** |
| 131 | REMARKS: |
| 132 | Halts the system by setting the halted system flag. |
| 133 | ****************************************************************************/ |
| 134 | void X86EMU_halt_sys(void) |
| 135 | { |
| 136 | M.x86.intr |= INTR_HALTED; |
| 137 | } |
| 138 | |
| 139 | /**************************************************************************** |
| 140 | PARAMETERS: |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 141 | mod - Mod value from decoded byte |
| 142 | regh - Reg h value from decoded byte |
| 143 | regl - Reg l value from decoded byte |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 144 | |
| 145 | REMARKS: |
| 146 | Raise the specified interrupt to be handled before the execution of the |
| 147 | next instruction. |
| 148 | |
| 149 | NOTE: Do not inline this function, as (*sys_rdb) is already inline! |
| 150 | ****************************************************************************/ |
| 151 | void fetch_decode_modrm( |
| 152 | int *mod, |
| 153 | int *regh, |
| 154 | int *regl) |
| 155 | { |
| 156 | int fetched; |
| 157 | |
| 158 | DB( if (CHECK_IP_FETCH()) |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 159 | x86emu_check_ip_access();) |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 160 | fetched = (*sys_rdb)(((u32)M.x86.R_CS << 4) + (M.x86.R_IP++)); |
| 161 | INC_DECODED_INST_LEN(1); |
| 162 | *mod = (fetched >> 6) & 0x03; |
| 163 | *regh = (fetched >> 3) & 0x07; |
| 164 | *regl = (fetched >> 0) & 0x07; |
| 165 | } |
| 166 | |
| 167 | /**************************************************************************** |
| 168 | RETURNS: |
| 169 | Immediate byte value read from instruction queue |
| 170 | |
| 171 | REMARKS: |
| 172 | This function returns the immediate byte from the instruction queue, and |
| 173 | moves the instruction pointer to the next value. |
| 174 | |
| 175 | NOTE: Do not inline this function, as (*sys_rdb) is already inline! |
| 176 | ****************************************************************************/ |
| 177 | u8 fetch_byte_imm(void) |
| 178 | { |
| 179 | u8 fetched; |
| 180 | |
| 181 | DB( if (CHECK_IP_FETCH()) |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 182 | x86emu_check_ip_access();) |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 183 | fetched = (*sys_rdb)(((u32)M.x86.R_CS << 4) + (M.x86.R_IP++)); |
| 184 | INC_DECODED_INST_LEN(1); |
| 185 | return fetched; |
| 186 | } |
| 187 | |
| 188 | /**************************************************************************** |
| 189 | RETURNS: |
| 190 | Immediate word value read from instruction queue |
| 191 | |
| 192 | REMARKS: |
| 193 | This function returns the immediate byte from the instruction queue, and |
| 194 | moves the instruction pointer to the next value. |
| 195 | |
| 196 | NOTE: Do not inline this function, as (*sys_rdw) is already inline! |
| 197 | ****************************************************************************/ |
| 198 | u16 fetch_word_imm(void) |
| 199 | { |
| 200 | u16 fetched; |
| 201 | |
| 202 | DB( if (CHECK_IP_FETCH()) |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 203 | x86emu_check_ip_access();) |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 204 | fetched = (*sys_rdw)(((u32)M.x86.R_CS << 4) + (M.x86.R_IP)); |
| 205 | M.x86.R_IP += 2; |
| 206 | INC_DECODED_INST_LEN(2); |
| 207 | return fetched; |
| 208 | } |
| 209 | |
| 210 | /**************************************************************************** |
| 211 | RETURNS: |
| 212 | Immediate lone value read from instruction queue |
| 213 | |
| 214 | REMARKS: |
| 215 | This function returns the immediate byte from the instruction queue, and |
| 216 | moves the instruction pointer to the next value. |
| 217 | |
| 218 | NOTE: Do not inline this function, as (*sys_rdw) is already inline! |
| 219 | ****************************************************************************/ |
| 220 | u32 fetch_long_imm(void) |
| 221 | { |
| 222 | u32 fetched; |
| 223 | |
| 224 | DB( if (CHECK_IP_FETCH()) |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 225 | x86emu_check_ip_access();) |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 226 | fetched = (*sys_rdl)(((u32)M.x86.R_CS << 4) + (M.x86.R_IP)); |
| 227 | M.x86.R_IP += 4; |
| 228 | INC_DECODED_INST_LEN(4); |
| 229 | return fetched; |
| 230 | } |
| 231 | |
| 232 | /**************************************************************************** |
| 233 | RETURNS: |
| 234 | Value of the default data segment |
| 235 | |
| 236 | REMARKS: |
| 237 | Inline function that returns the default data segment for the current |
| 238 | instruction. |
| 239 | |
| 240 | On the x86 processor, the default segment is not always DS if there is |
| 241 | no segment override. Address modes such as -3[BP] or 10[BP+SI] all refer to |
| 242 | addresses relative to SS (ie: on the stack). So, at the minimum, all |
| 243 | decodings of addressing modes would have to set/clear a bit describing |
| 244 | whether the access is relative to DS or SS. That is the function of the |
Robert P. J. Day | 8c60f92 | 2016-05-04 04:47:31 -0400 | [diff] [blame] | 245 | cpu-state-variable M.x86.mode. There are several potential states: |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 246 | |
| 247 | repe prefix seen (handled elsewhere) |
| 248 | repne prefix seen (ditto) |
| 249 | |
| 250 | cs segment override |
| 251 | ds segment override |
| 252 | es segment override |
| 253 | fs segment override |
| 254 | gs segment override |
| 255 | ss segment override |
| 256 | |
| 257 | ds/ss select (in absense of override) |
| 258 | |
| 259 | Each of the above 7 items are handled with a bit in the mode field. |
| 260 | ****************************************************************************/ |
| 261 | _INLINE u32 get_data_segment(void) |
| 262 | { |
| 263 | #define GET_SEGMENT(segment) |
| 264 | switch (M.x86.mode & SYSMODE_SEGMASK) { |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 265 | case 0: /* default case: use ds register */ |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 266 | case SYSMODE_SEGOVR_DS: |
| 267 | case SYSMODE_SEGOVR_DS | SYSMODE_SEG_DS_SS: |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 268 | return M.x86.R_DS; |
| 269 | case SYSMODE_SEG_DS_SS: /* non-overridden, use ss register */ |
| 270 | return M.x86.R_SS; |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 271 | case SYSMODE_SEGOVR_CS: |
| 272 | case SYSMODE_SEGOVR_CS | SYSMODE_SEG_DS_SS: |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 273 | return M.x86.R_CS; |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 274 | case SYSMODE_SEGOVR_ES: |
| 275 | case SYSMODE_SEGOVR_ES | SYSMODE_SEG_DS_SS: |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 276 | return M.x86.R_ES; |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 277 | case SYSMODE_SEGOVR_FS: |
| 278 | case SYSMODE_SEGOVR_FS | SYSMODE_SEG_DS_SS: |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 279 | return M.x86.R_FS; |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 280 | case SYSMODE_SEGOVR_GS: |
| 281 | case SYSMODE_SEGOVR_GS | SYSMODE_SEG_DS_SS: |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 282 | return M.x86.R_GS; |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 283 | case SYSMODE_SEGOVR_SS: |
| 284 | case SYSMODE_SEGOVR_SS | SYSMODE_SEG_DS_SS: |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 285 | return M.x86.R_SS; |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 286 | default: |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 287 | #ifdef DEBUG |
| 288 | printk("error: should not happen: multiple overrides.\n"); |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 289 | #endif |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 290 | HALT_SYS(); |
| 291 | return 0; |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 292 | } |
| 293 | } |
| 294 | |
| 295 | /**************************************************************************** |
| 296 | PARAMETERS: |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 297 | offset - Offset to load data from |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 298 | |
| 299 | RETURNS: |
| 300 | Byte value read from the absolute memory location. |
| 301 | |
| 302 | NOTE: Do not inline this function as (*sys_rdX) is already inline! |
| 303 | ****************************************************************************/ |
| 304 | u8 fetch_data_byte( |
| 305 | uint offset) |
| 306 | { |
Simon Glass | d8414fc | 2014-11-14 20:56:42 -0700 | [diff] [blame] | 307 | #ifdef CONFIG_X86EMU_DEBUG |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 308 | if (CHECK_DATA_ACCESS()) |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 309 | x86emu_check_data_access((u16)get_data_segment(), offset); |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 310 | #endif |
| 311 | return (*sys_rdb)((get_data_segment() << 4) + offset); |
| 312 | } |
| 313 | |
| 314 | /**************************************************************************** |
| 315 | PARAMETERS: |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 316 | offset - Offset to load data from |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 317 | |
| 318 | RETURNS: |
| 319 | Word value read from the absolute memory location. |
| 320 | |
| 321 | NOTE: Do not inline this function as (*sys_rdX) is already inline! |
| 322 | ****************************************************************************/ |
| 323 | u16 fetch_data_word( |
| 324 | uint offset) |
| 325 | { |
Simon Glass | d8414fc | 2014-11-14 20:56:42 -0700 | [diff] [blame] | 326 | #ifdef CONFIG_X86EMU_DEBUG |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 327 | if (CHECK_DATA_ACCESS()) |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 328 | x86emu_check_data_access((u16)get_data_segment(), offset); |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 329 | #endif |
| 330 | return (*sys_rdw)((get_data_segment() << 4) + offset); |
| 331 | } |
| 332 | |
| 333 | /**************************************************************************** |
| 334 | PARAMETERS: |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 335 | offset - Offset to load data from |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 336 | |
| 337 | RETURNS: |
| 338 | Long value read from the absolute memory location. |
| 339 | |
| 340 | NOTE: Do not inline this function as (*sys_rdX) is already inline! |
| 341 | ****************************************************************************/ |
| 342 | u32 fetch_data_long( |
| 343 | uint offset) |
| 344 | { |
Simon Glass | d8414fc | 2014-11-14 20:56:42 -0700 | [diff] [blame] | 345 | #ifdef CONFIG_X86EMU_DEBUG |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 346 | if (CHECK_DATA_ACCESS()) |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 347 | x86emu_check_data_access((u16)get_data_segment(), offset); |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 348 | #endif |
| 349 | return (*sys_rdl)((get_data_segment() << 4) + offset); |
| 350 | } |
| 351 | |
| 352 | /**************************************************************************** |
| 353 | PARAMETERS: |
| 354 | segment - Segment to load data from |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 355 | offset - Offset to load data from |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 356 | |
| 357 | RETURNS: |
| 358 | Byte value read from the absolute memory location. |
| 359 | |
| 360 | NOTE: Do not inline this function as (*sys_rdX) is already inline! |
| 361 | ****************************************************************************/ |
| 362 | u8 fetch_data_byte_abs( |
| 363 | uint segment, |
| 364 | uint offset) |
| 365 | { |
Simon Glass | d8414fc | 2014-11-14 20:56:42 -0700 | [diff] [blame] | 366 | #ifdef CONFIG_X86EMU_DEBUG |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 367 | if (CHECK_DATA_ACCESS()) |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 368 | x86emu_check_data_access(segment, offset); |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 369 | #endif |
| 370 | return (*sys_rdb)(((u32)segment << 4) + offset); |
| 371 | } |
| 372 | |
| 373 | /**************************************************************************** |
| 374 | PARAMETERS: |
| 375 | segment - Segment to load data from |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 376 | offset - Offset to load data from |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 377 | |
| 378 | RETURNS: |
| 379 | Word value read from the absolute memory location. |
| 380 | |
| 381 | NOTE: Do not inline this function as (*sys_rdX) is already inline! |
| 382 | ****************************************************************************/ |
| 383 | u16 fetch_data_word_abs( |
| 384 | uint segment, |
| 385 | uint offset) |
| 386 | { |
Simon Glass | d8414fc | 2014-11-14 20:56:42 -0700 | [diff] [blame] | 387 | #ifdef CONFIG_X86EMU_DEBUG |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 388 | if (CHECK_DATA_ACCESS()) |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 389 | x86emu_check_data_access(segment, offset); |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 390 | #endif |
| 391 | return (*sys_rdw)(((u32)segment << 4) + offset); |
| 392 | } |
| 393 | |
| 394 | /**************************************************************************** |
| 395 | PARAMETERS: |
| 396 | segment - Segment to load data from |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 397 | offset - Offset to load data from |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 398 | |
| 399 | RETURNS: |
| 400 | Long value read from the absolute memory location. |
| 401 | |
| 402 | NOTE: Do not inline this function as (*sys_rdX) is already inline! |
| 403 | ****************************************************************************/ |
| 404 | u32 fetch_data_long_abs( |
| 405 | uint segment, |
| 406 | uint offset) |
| 407 | { |
Simon Glass | d8414fc | 2014-11-14 20:56:42 -0700 | [diff] [blame] | 408 | #ifdef CONFIG_X86EMU_DEBUG |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 409 | if (CHECK_DATA_ACCESS()) |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 410 | x86emu_check_data_access(segment, offset); |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 411 | #endif |
| 412 | return (*sys_rdl)(((u32)segment << 4) + offset); |
| 413 | } |
| 414 | |
| 415 | /**************************************************************************** |
| 416 | PARAMETERS: |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 417 | offset - Offset to store data at |
| 418 | val - Value to store |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 419 | |
| 420 | REMARKS: |
| 421 | Writes a word value to an segmented memory location. The segment used is |
| 422 | the current 'default' segment, which may have been overridden. |
| 423 | |
| 424 | NOTE: Do not inline this function as (*sys_wrX) is already inline! |
| 425 | ****************************************************************************/ |
| 426 | void store_data_byte( |
| 427 | uint offset, |
| 428 | u8 val) |
| 429 | { |
Simon Glass | d8414fc | 2014-11-14 20:56:42 -0700 | [diff] [blame] | 430 | #ifdef CONFIG_X86EMU_DEBUG |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 431 | if (CHECK_DATA_ACCESS()) |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 432 | x86emu_check_data_access((u16)get_data_segment(), offset); |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 433 | #endif |
| 434 | (*sys_wrb)((get_data_segment() << 4) + offset, val); |
| 435 | } |
| 436 | |
| 437 | /**************************************************************************** |
| 438 | PARAMETERS: |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 439 | offset - Offset to store data at |
| 440 | val - Value to store |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 441 | |
| 442 | REMARKS: |
| 443 | Writes a word value to an segmented memory location. The segment used is |
| 444 | the current 'default' segment, which may have been overridden. |
| 445 | |
| 446 | NOTE: Do not inline this function as (*sys_wrX) is already inline! |
| 447 | ****************************************************************************/ |
| 448 | void store_data_word( |
| 449 | uint offset, |
| 450 | u16 val) |
| 451 | { |
Simon Glass | d8414fc | 2014-11-14 20:56:42 -0700 | [diff] [blame] | 452 | #ifdef CONFIG_X86EMU_DEBUG |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 453 | if (CHECK_DATA_ACCESS()) |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 454 | x86emu_check_data_access((u16)get_data_segment(), offset); |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 455 | #endif |
| 456 | (*sys_wrw)((get_data_segment() << 4) + offset, val); |
| 457 | } |
| 458 | |
| 459 | /**************************************************************************** |
| 460 | PARAMETERS: |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 461 | offset - Offset to store data at |
| 462 | val - Value to store |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 463 | |
| 464 | REMARKS: |
| 465 | Writes a long value to an segmented memory location. The segment used is |
| 466 | the current 'default' segment, which may have been overridden. |
| 467 | |
| 468 | NOTE: Do not inline this function as (*sys_wrX) is already inline! |
| 469 | ****************************************************************************/ |
| 470 | void store_data_long( |
| 471 | uint offset, |
| 472 | u32 val) |
| 473 | { |
Simon Glass | d8414fc | 2014-11-14 20:56:42 -0700 | [diff] [blame] | 474 | #ifdef CONFIG_X86EMU_DEBUG |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 475 | if (CHECK_DATA_ACCESS()) |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 476 | x86emu_check_data_access((u16)get_data_segment(), offset); |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 477 | #endif |
| 478 | (*sys_wrl)((get_data_segment() << 4) + offset, val); |
| 479 | } |
| 480 | |
| 481 | /**************************************************************************** |
| 482 | PARAMETERS: |
| 483 | segment - Segment to store data at |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 484 | offset - Offset to store data at |
| 485 | val - Value to store |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 486 | |
| 487 | REMARKS: |
| 488 | Writes a byte value to an absolute memory location. |
| 489 | |
| 490 | NOTE: Do not inline this function as (*sys_wrX) is already inline! |
| 491 | ****************************************************************************/ |
| 492 | void store_data_byte_abs( |
| 493 | uint segment, |
| 494 | uint offset, |
| 495 | u8 val) |
| 496 | { |
Simon Glass | d8414fc | 2014-11-14 20:56:42 -0700 | [diff] [blame] | 497 | #ifdef CONFIG_X86EMU_DEBUG |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 498 | if (CHECK_DATA_ACCESS()) |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 499 | x86emu_check_data_access(segment, offset); |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 500 | #endif |
| 501 | (*sys_wrb)(((u32)segment << 4) + offset, val); |
| 502 | } |
| 503 | |
| 504 | /**************************************************************************** |
| 505 | PARAMETERS: |
| 506 | segment - Segment to store data at |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 507 | offset - Offset to store data at |
| 508 | val - Value to store |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 509 | |
| 510 | REMARKS: |
| 511 | Writes a word value to an absolute memory location. |
| 512 | |
| 513 | NOTE: Do not inline this function as (*sys_wrX) is already inline! |
| 514 | ****************************************************************************/ |
| 515 | void store_data_word_abs( |
| 516 | uint segment, |
| 517 | uint offset, |
| 518 | u16 val) |
| 519 | { |
Simon Glass | d8414fc | 2014-11-14 20:56:42 -0700 | [diff] [blame] | 520 | #ifdef CONFIG_X86EMU_DEBUG |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 521 | if (CHECK_DATA_ACCESS()) |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 522 | x86emu_check_data_access(segment, offset); |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 523 | #endif |
| 524 | (*sys_wrw)(((u32)segment << 4) + offset, val); |
| 525 | } |
| 526 | |
| 527 | /**************************************************************************** |
| 528 | PARAMETERS: |
| 529 | segment - Segment to store data at |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 530 | offset - Offset to store data at |
| 531 | val - Value to store |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 532 | |
| 533 | REMARKS: |
| 534 | Writes a long value to an absolute memory location. |
| 535 | |
| 536 | NOTE: Do not inline this function as (*sys_wrX) is already inline! |
| 537 | ****************************************************************************/ |
| 538 | void store_data_long_abs( |
| 539 | uint segment, |
| 540 | uint offset, |
| 541 | u32 val) |
| 542 | { |
Simon Glass | d8414fc | 2014-11-14 20:56:42 -0700 | [diff] [blame] | 543 | #ifdef CONFIG_X86EMU_DEBUG |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 544 | if (CHECK_DATA_ACCESS()) |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 545 | x86emu_check_data_access(segment, offset); |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 546 | #endif |
| 547 | (*sys_wrl)(((u32)segment << 4) + offset, val); |
| 548 | } |
| 549 | |
| 550 | /**************************************************************************** |
| 551 | PARAMETERS: |
| 552 | reg - Register to decode |
| 553 | |
| 554 | RETURNS: |
| 555 | Pointer to the appropriate register |
| 556 | |
| 557 | REMARKS: |
| 558 | Return a pointer to the register given by the R/RM field of the |
| 559 | modrm byte, for byte operands. Also enables the decoding of instructions. |
| 560 | ****************************************************************************/ |
| 561 | u8* decode_rm_byte_register( |
| 562 | int reg) |
| 563 | { |
| 564 | switch (reg) { |
| 565 | case 0: |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 566 | DECODE_PRINTF("AL"); |
| 567 | return &M.x86.R_AL; |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 568 | case 1: |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 569 | DECODE_PRINTF("CL"); |
| 570 | return &M.x86.R_CL; |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 571 | case 2: |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 572 | DECODE_PRINTF("DL"); |
| 573 | return &M.x86.R_DL; |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 574 | case 3: |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 575 | DECODE_PRINTF("BL"); |
| 576 | return &M.x86.R_BL; |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 577 | case 4: |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 578 | DECODE_PRINTF("AH"); |
| 579 | return &M.x86.R_AH; |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 580 | case 5: |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 581 | DECODE_PRINTF("CH"); |
| 582 | return &M.x86.R_CH; |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 583 | case 6: |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 584 | DECODE_PRINTF("DH"); |
| 585 | return &M.x86.R_DH; |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 586 | case 7: |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 587 | DECODE_PRINTF("BH"); |
| 588 | return &M.x86.R_BH; |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 589 | } |
| 590 | HALT_SYS(); |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 591 | return NULL; /* NOT REACHED OR REACHED ON ERROR */ |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 592 | } |
| 593 | |
| 594 | /**************************************************************************** |
| 595 | PARAMETERS: |
| 596 | reg - Register to decode |
| 597 | |
| 598 | RETURNS: |
| 599 | Pointer to the appropriate register |
| 600 | |
| 601 | REMARKS: |
| 602 | Return a pointer to the register given by the R/RM field of the |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 603 | modrm byte, for word operands. Also enables the decoding of instructions. |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 604 | ****************************************************************************/ |
| 605 | u16* decode_rm_word_register( |
| 606 | int reg) |
| 607 | { |
| 608 | switch (reg) { |
| 609 | case 0: |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 610 | DECODE_PRINTF("AX"); |
| 611 | return &M.x86.R_AX; |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 612 | case 1: |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 613 | DECODE_PRINTF("CX"); |
| 614 | return &M.x86.R_CX; |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 615 | case 2: |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 616 | DECODE_PRINTF("DX"); |
| 617 | return &M.x86.R_DX; |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 618 | case 3: |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 619 | DECODE_PRINTF("BX"); |
| 620 | return &M.x86.R_BX; |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 621 | case 4: |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 622 | DECODE_PRINTF("SP"); |
| 623 | return &M.x86.R_SP; |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 624 | case 5: |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 625 | DECODE_PRINTF("BP"); |
| 626 | return &M.x86.R_BP; |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 627 | case 6: |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 628 | DECODE_PRINTF("SI"); |
| 629 | return &M.x86.R_SI; |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 630 | case 7: |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 631 | DECODE_PRINTF("DI"); |
| 632 | return &M.x86.R_DI; |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 633 | } |
| 634 | HALT_SYS(); |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 635 | return NULL; /* NOTREACHED OR REACHED ON ERROR */ |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 636 | } |
| 637 | |
| 638 | /**************************************************************************** |
| 639 | PARAMETERS: |
| 640 | reg - Register to decode |
| 641 | |
| 642 | RETURNS: |
| 643 | Pointer to the appropriate register |
| 644 | |
| 645 | REMARKS: |
| 646 | Return a pointer to the register given by the R/RM field of the |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 647 | modrm byte, for dword operands. Also enables the decoding of instructions. |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 648 | ****************************************************************************/ |
| 649 | u32* decode_rm_long_register( |
| 650 | int reg) |
| 651 | { |
| 652 | switch (reg) { |
| 653 | case 0: |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 654 | DECODE_PRINTF("EAX"); |
| 655 | return &M.x86.R_EAX; |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 656 | case 1: |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 657 | DECODE_PRINTF("ECX"); |
| 658 | return &M.x86.R_ECX; |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 659 | case 2: |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 660 | DECODE_PRINTF("EDX"); |
| 661 | return &M.x86.R_EDX; |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 662 | case 3: |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 663 | DECODE_PRINTF("EBX"); |
| 664 | return &M.x86.R_EBX; |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 665 | case 4: |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 666 | DECODE_PRINTF("ESP"); |
| 667 | return &M.x86.R_ESP; |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 668 | case 5: |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 669 | DECODE_PRINTF("EBP"); |
| 670 | return &M.x86.R_EBP; |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 671 | case 6: |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 672 | DECODE_PRINTF("ESI"); |
| 673 | return &M.x86.R_ESI; |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 674 | case 7: |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 675 | DECODE_PRINTF("EDI"); |
| 676 | return &M.x86.R_EDI; |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 677 | } |
| 678 | HALT_SYS(); |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 679 | return NULL; /* NOTREACHED OR REACHED ON ERROR */ |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 680 | } |
| 681 | |
| 682 | /**************************************************************************** |
| 683 | PARAMETERS: |
| 684 | reg - Register to decode |
| 685 | |
| 686 | RETURNS: |
| 687 | Pointer to the appropriate register |
| 688 | |
| 689 | REMARKS: |
| 690 | Return a pointer to the register given by the R/RM field of the |
| 691 | modrm byte, for word operands, modified from above for the weirdo |
| 692 | special case of segreg operands. Also enables the decoding of instructions. |
| 693 | ****************************************************************************/ |
| 694 | u16* decode_rm_seg_register( |
| 695 | int reg) |
| 696 | { |
| 697 | switch (reg) { |
| 698 | case 0: |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 699 | DECODE_PRINTF("ES"); |
| 700 | return &M.x86.R_ES; |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 701 | case 1: |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 702 | DECODE_PRINTF("CS"); |
| 703 | return &M.x86.R_CS; |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 704 | case 2: |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 705 | DECODE_PRINTF("SS"); |
| 706 | return &M.x86.R_SS; |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 707 | case 3: |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 708 | DECODE_PRINTF("DS"); |
| 709 | return &M.x86.R_DS; |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 710 | case 4: |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 711 | DECODE_PRINTF("FS"); |
| 712 | return &M.x86.R_FS; |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 713 | case 5: |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 714 | DECODE_PRINTF("GS"); |
| 715 | return &M.x86.R_GS; |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 716 | case 6: |
| 717 | case 7: |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 718 | DECODE_PRINTF("ILLEGAL SEGREG"); |
| 719 | break; |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 720 | } |
| 721 | HALT_SYS(); |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 722 | return NULL; /* NOT REACHED OR REACHED ON ERROR */ |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 723 | } |
| 724 | |
| 725 | /**************************************************************************** |
| 726 | PARAMETERS: |
| 727 | scale - scale value of SIB byte |
| 728 | index - index value of SIB byte |
| 729 | |
| 730 | RETURNS: |
| 731 | Value of scale * index |
| 732 | |
| 733 | REMARKS: |
| 734 | Decodes scale/index of SIB byte and returns relevant offset part of |
| 735 | effective address. |
| 736 | ****************************************************************************/ |
| 737 | unsigned decode_sib_si( |
| 738 | int scale, |
| 739 | int index) |
| 740 | { |
| 741 | scale = 1 << scale; |
| 742 | if (scale > 1) { |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 743 | DECODE_PRINTF2("[%d*", scale); |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 744 | } else { |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 745 | DECODE_PRINTF("["); |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 746 | } |
| 747 | switch (index) { |
| 748 | case 0: |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 749 | DECODE_PRINTF("EAX]"); |
| 750 | return M.x86.R_EAX * index; |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 751 | case 1: |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 752 | DECODE_PRINTF("ECX]"); |
| 753 | return M.x86.R_ECX * index; |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 754 | case 2: |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 755 | DECODE_PRINTF("EDX]"); |
| 756 | return M.x86.R_EDX * index; |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 757 | case 3: |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 758 | DECODE_PRINTF("EBX]"); |
| 759 | return M.x86.R_EBX * index; |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 760 | case 4: |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 761 | DECODE_PRINTF("0]"); |
| 762 | return 0; |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 763 | case 5: |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 764 | DECODE_PRINTF("EBP]"); |
| 765 | return M.x86.R_EBP * index; |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 766 | case 6: |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 767 | DECODE_PRINTF("ESI]"); |
| 768 | return M.x86.R_ESI * index; |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 769 | case 7: |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 770 | DECODE_PRINTF("EDI]"); |
| 771 | return M.x86.R_EDI * index; |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 772 | } |
| 773 | HALT_SYS(); |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 774 | return 0; /* NOT REACHED OR REACHED ON ERROR */ |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 775 | } |
| 776 | |
| 777 | /**************************************************************************** |
| 778 | PARAMETERS: |
| 779 | mod - MOD value of preceding ModR/M byte |
| 780 | |
| 781 | RETURNS: |
| 782 | Offset in memory for the address decoding |
| 783 | |
| 784 | REMARKS: |
| 785 | Decodes SIB addressing byte and returns calculated effective address. |
| 786 | ****************************************************************************/ |
| 787 | unsigned decode_sib_address( |
| 788 | int mod) |
| 789 | { |
| 790 | int sib = fetch_byte_imm(); |
| 791 | int ss = (sib >> 6) & 0x03; |
| 792 | int index = (sib >> 3) & 0x07; |
| 793 | int base = sib & 0x07; |
| 794 | int offset = 0; |
| 795 | int displacement; |
| 796 | |
| 797 | switch (base) { |
| 798 | case 0: |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 799 | DECODE_PRINTF("[EAX]"); |
| 800 | offset = M.x86.R_EAX; |
| 801 | break; |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 802 | case 1: |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 803 | DECODE_PRINTF("[ECX]"); |
| 804 | offset = M.x86.R_ECX; |
| 805 | break; |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 806 | case 2: |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 807 | DECODE_PRINTF("[EDX]"); |
| 808 | offset = M.x86.R_EDX; |
| 809 | break; |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 810 | case 3: |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 811 | DECODE_PRINTF("[EBX]"); |
| 812 | offset = M.x86.R_EBX; |
| 813 | break; |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 814 | case 4: |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 815 | DECODE_PRINTF("[ESP]"); |
| 816 | offset = M.x86.R_ESP; |
| 817 | break; |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 818 | case 5: |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 819 | switch (mod) { |
| 820 | case 0: |
| 821 | displacement = (s32)fetch_long_imm(); |
| 822 | DECODE_PRINTF2("[%d]", displacement); |
| 823 | offset = displacement; |
| 824 | break; |
| 825 | case 1: |
| 826 | displacement = (s8)fetch_byte_imm(); |
| 827 | DECODE_PRINTF2("[%d][EBP]", displacement); |
| 828 | offset = M.x86.R_EBP + displacement; |
| 829 | break; |
| 830 | case 2: |
| 831 | displacement = (s32)fetch_long_imm(); |
| 832 | DECODE_PRINTF2("[%d][EBP]", displacement); |
| 833 | offset = M.x86.R_EBP + displacement; |
| 834 | break; |
| 835 | default: |
| 836 | HALT_SYS(); |
| 837 | } |
| 838 | DECODE_PRINTF("[EAX]"); |
| 839 | offset = M.x86.R_EAX; |
| 840 | break; |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 841 | case 6: |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 842 | DECODE_PRINTF("[ESI]"); |
| 843 | offset = M.x86.R_ESI; |
| 844 | break; |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 845 | case 7: |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 846 | DECODE_PRINTF("[EDI]"); |
| 847 | offset = M.x86.R_EDI; |
| 848 | break; |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 849 | default: |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 850 | HALT_SYS(); |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 851 | } |
| 852 | offset += decode_sib_si(ss, index); |
| 853 | return offset; |
| 854 | |
| 855 | } |
| 856 | |
| 857 | /**************************************************************************** |
| 858 | PARAMETERS: |
| 859 | rm - RM value to decode |
| 860 | |
| 861 | RETURNS: |
| 862 | Offset in memory for the address decoding |
| 863 | |
| 864 | REMARKS: |
| 865 | Return the offset given by mod=00 addressing. Also enables the |
| 866 | decoding of instructions. |
| 867 | |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 868 | NOTE: The code which specifies the corresponding segment (ds vs ss) |
| 869 | below in the case of [BP+..]. The assumption here is that at the |
| 870 | point that this subroutine is called, the bit corresponding to |
| 871 | SYSMODE_SEG_DS_SS will be zero. After every instruction |
| 872 | except the segment override instructions, this bit (as well |
| 873 | as any bits indicating segment overrides) will be clear. So |
| 874 | if a SS access is needed, set this bit. Otherwise, DS access |
| 875 | occurs (unless any of the segment override bits are set). |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 876 | ****************************************************************************/ |
| 877 | unsigned decode_rm00_address( |
| 878 | int rm) |
| 879 | { |
| 880 | unsigned offset; |
| 881 | |
| 882 | if (M.x86.mode & SYSMODE_PREFIX_ADDR) { |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 883 | /* 32-bit addressing */ |
| 884 | switch (rm) { |
| 885 | case 0: |
| 886 | DECODE_PRINTF("[EAX]"); |
| 887 | return M.x86.R_EAX; |
| 888 | case 1: |
| 889 | DECODE_PRINTF("[ECX]"); |
| 890 | return M.x86.R_ECX; |
| 891 | case 2: |
| 892 | DECODE_PRINTF("[EDX]"); |
| 893 | return M.x86.R_EDX; |
| 894 | case 3: |
| 895 | DECODE_PRINTF("[EBX]"); |
| 896 | return M.x86.R_EBX; |
| 897 | case 4: |
| 898 | return decode_sib_address(0); |
| 899 | case 5: |
| 900 | offset = fetch_long_imm(); |
| 901 | DECODE_PRINTF2("[%08x]", offset); |
| 902 | return offset; |
| 903 | case 6: |
| 904 | DECODE_PRINTF("[ESI]"); |
| 905 | return M.x86.R_ESI; |
| 906 | case 7: |
| 907 | DECODE_PRINTF("[EDI]"); |
| 908 | return M.x86.R_EDI; |
| 909 | } |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 910 | } else { |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 911 | /* 16-bit addressing */ |
| 912 | switch (rm) { |
| 913 | case 0: |
| 914 | DECODE_PRINTF("[BX+SI]"); |
| 915 | return (M.x86.R_BX + M.x86.R_SI) & 0xffff; |
| 916 | case 1: |
| 917 | DECODE_PRINTF("[BX+DI]"); |
| 918 | return (M.x86.R_BX + M.x86.R_DI) & 0xffff; |
| 919 | case 2: |
| 920 | DECODE_PRINTF("[BP+SI]"); |
| 921 | M.x86.mode |= SYSMODE_SEG_DS_SS; |
| 922 | return (M.x86.R_BP + M.x86.R_SI) & 0xffff; |
| 923 | case 3: |
| 924 | DECODE_PRINTF("[BP+DI]"); |
| 925 | M.x86.mode |= SYSMODE_SEG_DS_SS; |
| 926 | return (M.x86.R_BP + M.x86.R_DI) & 0xffff; |
| 927 | case 4: |
| 928 | DECODE_PRINTF("[SI]"); |
| 929 | return M.x86.R_SI; |
| 930 | case 5: |
| 931 | DECODE_PRINTF("[DI]"); |
| 932 | return M.x86.R_DI; |
| 933 | case 6: |
| 934 | offset = fetch_word_imm(); |
| 935 | DECODE_PRINTF2("[%04x]", offset); |
| 936 | return offset; |
| 937 | case 7: |
| 938 | DECODE_PRINTF("[BX]"); |
| 939 | return M.x86.R_BX; |
| 940 | } |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 941 | } |
| 942 | HALT_SYS(); |
| 943 | return 0; |
| 944 | } |
| 945 | |
| 946 | /**************************************************************************** |
| 947 | PARAMETERS: |
| 948 | rm - RM value to decode |
| 949 | |
| 950 | RETURNS: |
| 951 | Offset in memory for the address decoding |
| 952 | |
| 953 | REMARKS: |
| 954 | Return the offset given by mod=01 addressing. Also enables the |
| 955 | decoding of instructions. |
| 956 | ****************************************************************************/ |
| 957 | unsigned decode_rm01_address( |
| 958 | int rm) |
| 959 | { |
| 960 | int displacement; |
| 961 | |
| 962 | if (M.x86.mode & SYSMODE_PREFIX_ADDR) { |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 963 | /* 32-bit addressing */ |
| 964 | if (rm != 4) |
| 965 | displacement = (s8)fetch_byte_imm(); |
| 966 | else |
| 967 | displacement = 0; |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 968 | |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 969 | switch (rm) { |
| 970 | case 0: |
| 971 | DECODE_PRINTF2("%d[EAX]", displacement); |
| 972 | return M.x86.R_EAX + displacement; |
| 973 | case 1: |
| 974 | DECODE_PRINTF2("%d[ECX]", displacement); |
| 975 | return M.x86.R_ECX + displacement; |
| 976 | case 2: |
| 977 | DECODE_PRINTF2("%d[EDX]", displacement); |
| 978 | return M.x86.R_EDX + displacement; |
| 979 | case 3: |
| 980 | DECODE_PRINTF2("%d[EBX]", displacement); |
| 981 | return M.x86.R_EBX + displacement; |
| 982 | case 4: { |
| 983 | int offset = decode_sib_address(1); |
| 984 | displacement = (s8)fetch_byte_imm(); |
| 985 | DECODE_PRINTF2("[%d]", displacement); |
| 986 | return offset + displacement; |
| 987 | } |
| 988 | case 5: |
| 989 | DECODE_PRINTF2("%d[EBP]", displacement); |
| 990 | return M.x86.R_EBP + displacement; |
| 991 | case 6: |
| 992 | DECODE_PRINTF2("%d[ESI]", displacement); |
| 993 | return M.x86.R_ESI + displacement; |
| 994 | case 7: |
| 995 | DECODE_PRINTF2("%d[EDI]", displacement); |
| 996 | return M.x86.R_EDI + displacement; |
| 997 | } |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 998 | } else { |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 999 | /* 16-bit addressing */ |
| 1000 | displacement = (s8)fetch_byte_imm(); |
| 1001 | switch (rm) { |
| 1002 | case 0: |
| 1003 | DECODE_PRINTF2("%d[BX+SI]", displacement); |
| 1004 | return (M.x86.R_BX + M.x86.R_SI + displacement) & 0xffff; |
| 1005 | case 1: |
| 1006 | DECODE_PRINTF2("%d[BX+DI]", displacement); |
| 1007 | return (M.x86.R_BX + M.x86.R_DI + displacement) & 0xffff; |
| 1008 | case 2: |
| 1009 | DECODE_PRINTF2("%d[BP+SI]", displacement); |
| 1010 | M.x86.mode |= SYSMODE_SEG_DS_SS; |
| 1011 | return (M.x86.R_BP + M.x86.R_SI + displacement) & 0xffff; |
| 1012 | case 3: |
| 1013 | DECODE_PRINTF2("%d[BP+DI]", displacement); |
| 1014 | M.x86.mode |= SYSMODE_SEG_DS_SS; |
| 1015 | return (M.x86.R_BP + M.x86.R_DI + displacement) & 0xffff; |
| 1016 | case 4: |
| 1017 | DECODE_PRINTF2("%d[SI]", displacement); |
| 1018 | return (M.x86.R_SI + displacement) & 0xffff; |
| 1019 | case 5: |
| 1020 | DECODE_PRINTF2("%d[DI]", displacement); |
| 1021 | return (M.x86.R_DI + displacement) & 0xffff; |
| 1022 | case 6: |
| 1023 | DECODE_PRINTF2("%d[BP]", displacement); |
| 1024 | M.x86.mode |= SYSMODE_SEG_DS_SS; |
| 1025 | return (M.x86.R_BP + displacement) & 0xffff; |
| 1026 | case 7: |
| 1027 | DECODE_PRINTF2("%d[BX]", displacement); |
| 1028 | return (M.x86.R_BX + displacement) & 0xffff; |
| 1029 | } |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 1030 | } |
| 1031 | HALT_SYS(); |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 1032 | return 0; /* SHOULD NOT HAPPEN */ |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 1033 | } |
| 1034 | |
| 1035 | /**************************************************************************** |
| 1036 | PARAMETERS: |
| 1037 | rm - RM value to decode |
| 1038 | |
| 1039 | RETURNS: |
| 1040 | Offset in memory for the address decoding |
| 1041 | |
| 1042 | REMARKS: |
| 1043 | Return the offset given by mod=10 addressing. Also enables the |
| 1044 | decoding of instructions. |
| 1045 | ****************************************************************************/ |
| 1046 | unsigned decode_rm10_address( |
| 1047 | int rm) |
| 1048 | { |
| 1049 | if (M.x86.mode & SYSMODE_PREFIX_ADDR) { |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 1050 | int displacement; |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 1051 | |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 1052 | /* 32-bit addressing */ |
| 1053 | if (rm != 4) |
| 1054 | displacement = (s32)fetch_long_imm(); |
| 1055 | else |
| 1056 | displacement = 0; |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 1057 | |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 1058 | switch (rm) { |
| 1059 | case 0: |
| 1060 | DECODE_PRINTF2("%d[EAX]", displacement); |
| 1061 | return M.x86.R_EAX + displacement; |
| 1062 | case 1: |
| 1063 | DECODE_PRINTF2("%d[ECX]", displacement); |
| 1064 | return M.x86.R_ECX + displacement; |
| 1065 | case 2: |
| 1066 | DECODE_PRINTF2("%d[EDX]", displacement); |
| 1067 | return M.x86.R_EDX + displacement; |
| 1068 | case 3: |
| 1069 | DECODE_PRINTF2("%d[EBX]", displacement); |
| 1070 | return M.x86.R_EBX + displacement; |
| 1071 | case 4: { |
| 1072 | int offset = decode_sib_address(2); |
| 1073 | displacement = (s32)fetch_long_imm(); |
| 1074 | DECODE_PRINTF2("[%d]", displacement); |
| 1075 | return offset + displacement; |
| 1076 | } |
| 1077 | case 5: |
| 1078 | DECODE_PRINTF2("%d[EBP]", displacement); |
| 1079 | return M.x86.R_EBP + displacement; |
| 1080 | case 6: |
| 1081 | DECODE_PRINTF2("%d[ESI]", displacement); |
| 1082 | return M.x86.R_ESI + displacement; |
| 1083 | case 7: |
| 1084 | DECODE_PRINTF2("%d[EDI]", displacement); |
| 1085 | return M.x86.R_EDI + displacement; |
| 1086 | } |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 1087 | } else { |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 1088 | int displacement = (s16)fetch_word_imm(); |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 1089 | |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 1090 | /* 16-bit addressing */ |
| 1091 | switch (rm) { |
| 1092 | case 0: |
| 1093 | DECODE_PRINTF2("%d[BX+SI]", displacement); |
| 1094 | return (M.x86.R_BX + M.x86.R_SI + displacement) & 0xffff; |
| 1095 | case 1: |
| 1096 | DECODE_PRINTF2("%d[BX+DI]", displacement); |
| 1097 | return (M.x86.R_BX + M.x86.R_DI + displacement) & 0xffff; |
| 1098 | case 2: |
| 1099 | DECODE_PRINTF2("%d[BP+SI]", displacement); |
| 1100 | M.x86.mode |= SYSMODE_SEG_DS_SS; |
| 1101 | return (M.x86.R_BP + M.x86.R_SI + displacement) & 0xffff; |
| 1102 | case 3: |
| 1103 | DECODE_PRINTF2("%d[BP+DI]", displacement); |
| 1104 | M.x86.mode |= SYSMODE_SEG_DS_SS; |
| 1105 | return (M.x86.R_BP + M.x86.R_DI + displacement) & 0xffff; |
| 1106 | case 4: |
| 1107 | DECODE_PRINTF2("%d[SI]", displacement); |
| 1108 | return (M.x86.R_SI + displacement) & 0xffff; |
| 1109 | case 5: |
| 1110 | DECODE_PRINTF2("%d[DI]", displacement); |
| 1111 | return (M.x86.R_DI + displacement) & 0xffff; |
| 1112 | case 6: |
| 1113 | DECODE_PRINTF2("%d[BP]", displacement); |
| 1114 | M.x86.mode |= SYSMODE_SEG_DS_SS; |
| 1115 | return (M.x86.R_BP + displacement) & 0xffff; |
| 1116 | case 7: |
| 1117 | DECODE_PRINTF2("%d[BX]", displacement); |
| 1118 | return (M.x86.R_BX + displacement) & 0xffff; |
| 1119 | } |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 1120 | } |
| 1121 | HALT_SYS(); |
Wolfgang Denk | 96bb2e0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 1122 | return 0; /* SHOULD NOT HAPPEN */ |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 1123 | } |
| 1124 | |
Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 1125 | /**************************************************************************** |
| 1126 | PARAMETERS: |
| 1127 | mod - modifier |
| 1128 | rm - RM value to decode |
| 1129 | |
| 1130 | RETURNS: |
| 1131 | Offset in memory for the address decoding, multiplexing calls to |
| 1132 | the decode_rmXX_address functions |
| 1133 | |
| 1134 | REMARKS: |
| 1135 | Return the offset given by "mod" addressing. |
| 1136 | ****************************************************************************/ |
| 1137 | |
| 1138 | unsigned decode_rmXX_address(int mod, int rm) |
| 1139 | { |
| 1140 | if(mod == 0) |
| 1141 | return decode_rm00_address(rm); |
| 1142 | if(mod == 1) |
| 1143 | return decode_rm01_address(rm); |
| 1144 | return decode_rm10_address(rm); |
| 1145 | } |