| 1 | /*\r |
| 2 | * Dos/PC Emulator\r |
| 3 | * Copyright (C) 1991 Jim Hudgens\r |
| 4 | *\r |
| 5 | *\r |
| 6 | * The file is part of GDE.\r |
| 7 | *\r |
| 8 | * GDE is free software; you can redistribute it and/or modify\r |
| 9 | * it under the terms of the GNU General Public License as published by\r |
| 10 | * the Free Software Foundation; either version 1, or (at your option)\r |
| 11 | * any later version.\r |
| 12 | *\r |
| 13 | * GDE is distributed in the hope that it will be useful,\r |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of\r |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r |
| 16 | * GNU General Public License for more details.\r |
| 17 | *\r |
| 18 | * You should have received a copy of the GNU General Public License\r |
| 19 | * along with GDE; see the file COPYING. If not, write to\r |
| 20 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.\r |
| 21 | *\r |
| 22 | */\r |
| 23 | \r |
| 24 | #include "altairz80_defs.h"\r |
| 25 | #include "i86.h"\r |
| 26 | \r |
| 27 | extern void out(const uint32 Port, const uint32 Value);\r |
| 28 | extern uint32 in(const uint32 Port);\r |
| 29 | \r |
| 30 | /* $Log: i86_ops.c,v $\r |
| 31 | * Revision 0.11 1991/07/30 02:02:04 hudgens\r |
| 32 | * added copyright.\r |
| 33 | *\r |
| 34 | * Revision 0.10 1991/07/21 18:22:08 hudgens\r |
| 35 | * Fixed problem with scans, which was the result of the loop break\r |
| 36 | * condition being incorrect when used in conjunction with the repe\r |
| 37 | * or repne prefixes. Eureka. pkzip/pkunzip now compress/decompress\r |
| 38 | * correctly.\r |
| 39 | *\r |
| 40 | * Revision 0.9 1991/07/21 03:33:18 hudgens\r |
| 41 | * fixed popf so that it appears to be the same as an 8088 popf, and always\r |
| 42 | * sets the high 4 bits of the flags.\r |
| 43 | *\r |
| 44 | * Revision 0.8 1991/07/21 01:44:11 hudgens\r |
| 45 | * fixed aad and aam instructions.\r |
| 46 | *\r |
| 47 | * Revision 0.7 1991/07/21 00:31:24 hudgens\r |
| 48 | * Fixed iret so that it works correctly.\r |
| 49 | *\r |
| 50 | * Revision 0.6 1991/07/20 16:54:50 hudgens\r |
| 51 | * removed the 8087 coprocessor operations. Moved to i87_ops.c\r |
| 52 | *\r |
| 53 | * Revision 0.5 1991/07/17 03:50:10 hudgens\r |
| 54 | * Minor modifications.\r |
| 55 | *\r |
| 56 | * Revision 0.4 1991/06/18 02:48:41 hudgens\r |
| 57 | * Fixed a problem with scasb and scasw.\r |
| 58 | *\r |
| 59 | * Revision 0.3 1991/06/03 01:01:10 hudgens\r |
| 60 | * fixed minor problems due to unsigned to signed short integer\r |
| 61 | * promotions.\r |
| 62 | *\r |
| 63 | * Revision 0.2 1991/03/31 01:32:10 hudgens\r |
| 64 | * fixed segment handling. Added calls to DECODE_CLEAR_SEGOVR in\r |
| 65 | * many places in the code. Should work much better now.\r |
| 66 | *\r |
| 67 | * Revision 0.1 1991/03/30 21:15:48 hudgens\r |
| 68 | * Initial checkin to RCS.\r |
| 69 | *\r |
| 70 | *\r |
| 71 | */\r |
| 72 | \r |
| 73 | /* 2/23/91 fixed decode for operand x87. */\r |
| 74 | \r |
| 75 | /* partially mechanically generated file....(based on the optable) */\r |
| 76 | /*\r |
| 77 | There are approximately 250 subroutines in here, which correspond\r |
| 78 | to the 256 byte-"opcodes" found on the 8086. The table which\r |
| 79 | dispatches this is found in the files optab.[ch].\r |
| 80 | \r |
| 81 | Each opcode proc has a comment preceeding it which gives it's table\r |
| 82 | address. Several opcodes are missing (undefined) in the table.\r |
| 83 | \r |
| 84 | Each proc includes information for decoding (DECODE_PRINTF and\r |
| 85 | and misc functions (\r |
| 86 | Many of the procedures are *VERY* similar in coding. This has\r |
| 87 | allowed for a very large amount of code to be generated in a fairly\r |
| 88 | short amount of time (i.e. cut, paste, and modify).\r |
| 89 | The result is that much of the code below could\r |
| 90 | have been folded into subroutines for a large reduction in size of\r |
| 91 | this file. The downside would be that there would be a penalty in\r |
| 92 | execution speed. The file could also have been *MUCH* larger by\r |
| 93 | inlining certain functions which were called. This could have\r |
| 94 | resulted even faster execution. The prime directive I used to decide\r |
| 95 | whether to inline the code or to modularize it, was basically: 1) no\r |
| 96 | unnecessary subroutine calls, 2) no routines more than about 200 lines\r |
| 97 | in size, and 3) modularize any code that I might not get right the first\r |
| 98 | time. The fetch_* subroutines fall into the latter category. The\r |
| 99 | The decode_* fall into the second category. The coding of the\r |
| 100 | "switch(mod){ .... }" in many of the subroutines below falls into the\r |
| 101 | first category. Especially, the coding of {add,and,or,sub,...}_{byte,word}\r |
| 102 | subroutines are an especially glaring case of the third guideline.\r |
| 103 | Since so much of the code is cloned from other modules (compare\r |
| 104 | opcode #00 to opcode #01), making the basic operations subroutine calls\r |
| 105 | is especially important; otherwise mistakes in coding an "add"\r |
| 106 | would represent a nightmare in maintenance.\r |
| 107 | \r |
| 108 | So, without further ado, ...\r |
| 109 | */\r |
| 110 | \r |
| 111 | extern char parity_tab[];\r |
| 112 | \r |
| 113 | static void i86op_illegal_op(PC_ENV *m)\r |
| 114 | {\r |
| 115 | intr |= INTR_ILLEGAL_OPCODE;\r |
| 116 | }\r |
| 117 | \r |
| 118 | /*opcode=0x00*/\r |
| 119 | static void i86op_add_byte_RM_R(PC_ENV *m)\r |
| 120 | {\r |
| 121 | uint16 mod,rl,rh;\r |
| 122 | uint8 *destreg,*srcreg;\r |
| 123 | uint16 destoffset;\r |
| 124 | uint8 destval;\r |
| 125 | FETCH_DECODE_MODRM(m,mod,rh,rl);\r |
| 126 | switch (mod)\r |
| 127 | {\r |
| 128 | case 0:\r |
| 129 | destoffset=decode_rm00_address(m,rl);\r |
| 130 | destval = fetch_data_byte(m,destoffset);\r |
| 131 | srcreg = DECODE_RM_BYTE_REGISTER(m,rh);\r |
| 132 | destval = add_byte(m, destval, *srcreg);\r |
| 133 | store_data_byte(m,destoffset,destval);\r |
| 134 | break;\r |
| 135 | case 1:\r |
| 136 | destoffset=decode_rm01_address(m,rl);\r |
| 137 | destval = fetch_data_byte(m,destoffset);\r |
| 138 | srcreg = DECODE_RM_BYTE_REGISTER(m,rh);\r |
| 139 | destval = add_byte(m, destval, *srcreg);\r |
| 140 | store_data_byte(m,destoffset,destval);\r |
| 141 | break;\r |
| 142 | case 2:\r |
| 143 | destoffset=decode_rm10_address(m,rl);\r |
| 144 | destval = fetch_data_byte(m,destoffset);\r |
| 145 | srcreg = DECODE_RM_BYTE_REGISTER(m,rh);\r |
| 146 | destval = add_byte(m, destval, *srcreg);\r |
| 147 | store_data_byte(m,destoffset,destval);\r |
| 148 | break;\r |
| 149 | case 3: /* register to register */\r |
| 150 | destreg = DECODE_RM_BYTE_REGISTER(m,rl);\r |
| 151 | srcreg = DECODE_RM_BYTE_REGISTER(m,rh);\r |
| 152 | *destreg = add_byte(m, *destreg, *srcreg);\r |
| 153 | break;\r |
| 154 | }\r |
| 155 | DECODE_CLEAR_SEGOVR(m);\r |
| 156 | }\r |
| 157 | \r |
| 158 | /*opcode=0x01*/\r |
| 159 | static void i86op_add_word_RM_R(PC_ENV *m)\r |
| 160 | {\r |
| 161 | uint16 mod,rl,rh;\r |
| 162 | uint16 *destreg,*srcreg;\r |
| 163 | uint16 destoffset;\r |
| 164 | uint16 destval;\r |
| 165 | FETCH_DECODE_MODRM(m,mod,rh,rl);\r |
| 166 | switch (mod)\r |
| 167 | {\r |
| 168 | case 0:\r |
| 169 | destoffset=decode_rm00_address(m,rl);\r |
| 170 | destval = fetch_data_word(m,destoffset);\r |
| 171 | srcreg = DECODE_RM_WORD_REGISTER(m,rh);\r |
| 172 | destval = add_word(m, destval, *srcreg);\r |
| 173 | store_data_word(m,destoffset,destval);\r |
| 174 | break;\r |
| 175 | case 1:\r |
| 176 | destoffset=decode_rm01_address(m,rl);\r |
| 177 | destval = fetch_data_word(m,destoffset);\r |
| 178 | srcreg = DECODE_RM_WORD_REGISTER(m,rh);\r |
| 179 | destval = add_word(m, destval, *srcreg);\r |
| 180 | store_data_word(m,destoffset,destval);\r |
| 181 | break;\r |
| 182 | case 2:\r |
| 183 | destoffset=decode_rm10_address(m,rl);\r |
| 184 | destval = fetch_data_word(m,destoffset);\r |
| 185 | srcreg = DECODE_RM_WORD_REGISTER(m,rh);\r |
| 186 | destval = add_word(m, destval, *srcreg);\r |
| 187 | store_data_word(m,destoffset,destval);\r |
| 188 | break;\r |
| 189 | case 3: /* register to register */\r |
| 190 | destreg = DECODE_RM_WORD_REGISTER(m,rl);\r |
| 191 | srcreg = DECODE_RM_WORD_REGISTER(m,rh);\r |
| 192 | *destreg = add_word(m, *destreg, *srcreg);\r |
| 193 | break;\r |
| 194 | }\r |
| 195 | DECODE_CLEAR_SEGOVR(m);\r |
| 196 | }\r |
| 197 | \r |
| 198 | /*opcode=0x02*/\r |
| 199 | static void i86op_add_byte_R_RM(PC_ENV *m)\r |
| 200 | {\r |
| 201 | uint16 mod,rl,rh;\r |
| 202 | uint8 *destreg,*srcreg;\r |
| 203 | uint16 srcoffset;\r |
| 204 | uint8 srcval;\r |
| 205 | FETCH_DECODE_MODRM(m,mod,rh,rl);\r |
| 206 | switch (mod)\r |
| 207 | {\r |
| 208 | case 0:\r |
| 209 | destreg = DECODE_RM_BYTE_REGISTER(m,rh);\r |
| 210 | srcoffset=decode_rm00_address(m,rl);\r |
| 211 | srcval = fetch_data_byte(m,srcoffset);\r |
| 212 | *destreg = add_byte(m, *destreg, srcval);\r |
| 213 | break;\r |
| 214 | case 1:\r |
| 215 | destreg = DECODE_RM_BYTE_REGISTER(m,rh);\r |
| 216 | srcoffset=decode_rm01_address(m,rl);\r |
| 217 | srcval = fetch_data_byte(m,srcoffset);\r |
| 218 | *destreg = add_byte(m, *destreg, srcval);\r |
| 219 | break;\r |
| 220 | case 2:\r |
| 221 | destreg = DECODE_RM_BYTE_REGISTER(m,rh);\r |
| 222 | srcoffset=decode_rm10_address(m,rl);\r |
| 223 | srcval = fetch_data_byte(m,srcoffset);\r |
| 224 | *destreg = add_byte(m, * destreg, srcval);\r |
| 225 | break;\r |
| 226 | case 3: /* register to register */\r |
| 227 | destreg = DECODE_RM_BYTE_REGISTER(m,rh);\r |
| 228 | srcreg = DECODE_RM_BYTE_REGISTER(m,rl);\r |
| 229 | *destreg = add_byte(m, *destreg, *srcreg);\r |
| 230 | break;\r |
| 231 | }\r |
| 232 | DECODE_CLEAR_SEGOVR(m);\r |
| 233 | }\r |
| 234 | \r |
| 235 | /*opcode=0x03*/\r |
| 236 | static void i86op_add_word_R_RM(PC_ENV *m)\r |
| 237 | {\r |
| 238 | uint16 mod,rl,rh;\r |
| 239 | uint16 *destreg,*srcreg;\r |
| 240 | uint16 srcoffset;\r |
| 241 | uint16 srcval;\r |
| 242 | FETCH_DECODE_MODRM(m,mod,rh,rl);\r |
| 243 | switch (mod)\r |
| 244 | {\r |
| 245 | case 0:\r |
| 246 | destreg = DECODE_RM_WORD_REGISTER(m,rh);\r |
| 247 | srcoffset=decode_rm00_address(m,rl);\r |
| 248 | srcval = fetch_data_word(m,srcoffset);\r |
| 249 | *destreg = add_word(m, *destreg, srcval);\r |
| 250 | break;\r |
| 251 | case 1:\r |
| 252 | destreg = DECODE_RM_WORD_REGISTER(m,rh);\r |
| 253 | srcoffset=decode_rm01_address(m,rl);\r |
| 254 | srcval = fetch_data_word(m,srcoffset);\r |
| 255 | *destreg = add_word(m, *destreg, srcval);\r |
| 256 | break;\r |
| 257 | case 2:\r |
| 258 | destreg = DECODE_RM_WORD_REGISTER(m,rh);\r |
| 259 | srcoffset=decode_rm10_address(m,rl);\r |
| 260 | srcval = fetch_data_word(m,srcoffset);\r |
| 261 | *destreg = add_word(m, *destreg, srcval);\r |
| 262 | break;\r |
| 263 | case 3: /* register to register */\r |
| 264 | destreg = DECODE_RM_WORD_REGISTER(m,rh);\r |
| 265 | srcreg = DECODE_RM_WORD_REGISTER(m,rl);\r |
| 266 | *destreg = add_word(m, *destreg, *srcreg);\r |
| 267 | break;\r |
| 268 | }\r |
| 269 | DECODE_CLEAR_SEGOVR(m);\r |
| 270 | }\r |
| 271 | \r |
| 272 | /*opcode=0x04*/\r |
| 273 | static void i86op_add_byte_AL_IMM(PC_ENV *m)\r |
| 274 | {\r |
| 275 | uint8 srcval;\r |
| 276 | srcval = fetch_byte_imm(m);\r |
| 277 | m->R_AL = add_byte(m, m->R_AL, srcval);\r |
| 278 | DECODE_CLEAR_SEGOVR(m);\r |
| 279 | }\r |
| 280 | \r |
| 281 | /*opcode=0x05*/\r |
| 282 | static void i86op_add_word_AX_IMM(PC_ENV *m)\r |
| 283 | {\r |
| 284 | uint16 srcval;\r |
| 285 | srcval = fetch_word_imm(m);\r |
| 286 | m->R_AX = add_word(m, m->R_AX, srcval);\r |
| 287 | DECODE_CLEAR_SEGOVR(m);\r |
| 288 | }\r |
| 289 | \r |
| 290 | /*opcode=0x06*/\r |
| 291 | static void i86op_push_ES(PC_ENV *m)\r |
| 292 | {\r |
| 293 | push_word(m,m->R_ES);\r |
| 294 | DECODE_CLEAR_SEGOVR(m);\r |
| 295 | }\r |
| 296 | \r |
| 297 | /*opcode=0x07*/\r |
| 298 | static void i86op_pop_ES(PC_ENV *m)\r |
| 299 | {\r |
| 300 | m->R_ES = pop_word(m);\r |
| 301 | DECODE_CLEAR_SEGOVR(m);\r |
| 302 | }\r |
| 303 | \r |
| 304 | /*opcode=0x08*/\r |
| 305 | static void i86op_or_byte_RM_R(PC_ENV *m)\r |
| 306 | {\r |
| 307 | uint16 mod,rl,rh;\r |
| 308 | uint8 *destreg,*srcreg;\r |
| 309 | uint16 destoffset;\r |
| 310 | uint8 destval;\r |
| 311 | FETCH_DECODE_MODRM(m,mod,rh,rl);\r |
| 312 | switch (mod)\r |
| 313 | {\r |
| 314 | case 0:\r |
| 315 | destoffset=decode_rm00_address(m,rl);\r |
| 316 | destval = fetch_data_byte(m,destoffset);\r |
| 317 | srcreg = DECODE_RM_BYTE_REGISTER(m,rh);\r |
| 318 | destval = or_byte(m, destval, *srcreg);\r |
| 319 | store_data_byte(m,destoffset,destval);\r |
| 320 | break;\r |
| 321 | case 1:\r |
| 322 | destoffset=decode_rm01_address(m,rl);\r |
| 323 | destval = fetch_data_byte(m,destoffset);\r |
| 324 | srcreg = DECODE_RM_BYTE_REGISTER(m,rh);\r |
| 325 | destval = or_byte(m, destval, *srcreg);\r |
| 326 | store_data_byte(m,destoffset,destval);\r |
| 327 | break;\r |
| 328 | case 2:\r |
| 329 | destoffset=decode_rm10_address(m,rl);\r |
| 330 | destval = fetch_data_byte(m,destoffset);\r |
| 331 | srcreg = DECODE_RM_BYTE_REGISTER(m,rh);\r |
| 332 | destval = or_byte(m, destval, *srcreg);\r |
| 333 | store_data_byte(m,destoffset,destval);\r |
| 334 | break;\r |
| 335 | case 3: /* register to register */\r |
| 336 | destreg = DECODE_RM_BYTE_REGISTER(m,rl);\r |
| 337 | srcreg = DECODE_RM_BYTE_REGISTER(m,rh);\r |
| 338 | *destreg = or_byte(m, *destreg, *srcreg);\r |
| 339 | break;\r |
| 340 | }\r |
| 341 | DECODE_CLEAR_SEGOVR(m);\r |
| 342 | }\r |
| 343 | \r |
| 344 | /*opcode=0x09*/\r |
| 345 | static void i86op_or_word_RM_R(PC_ENV *m)\r |
| 346 | {\r |
| 347 | uint16 mod,rl,rh;\r |
| 348 | uint16 *destreg,*srcreg;\r |
| 349 | uint16 destoffset;\r |
| 350 | uint16 destval;\r |
| 351 | FETCH_DECODE_MODRM(m,mod,rh,rl);\r |
| 352 | switch (mod)\r |
| 353 | {\r |
| 354 | case 0:\r |
| 355 | destoffset=decode_rm00_address(m,rl);\r |
| 356 | destval = fetch_data_word(m,destoffset);\r |
| 357 | srcreg = DECODE_RM_WORD_REGISTER(m,rh);\r |
| 358 | destval = or_word(m, destval, *srcreg);\r |
| 359 | store_data_word(m,destoffset,destval);\r |
| 360 | break;\r |
| 361 | case 1:\r |
| 362 | destoffset=decode_rm01_address(m,rl);\r |
| 363 | destval = fetch_data_word(m,destoffset);\r |
| 364 | srcreg = DECODE_RM_WORD_REGISTER(m,rh);\r |
| 365 | destval = or_word(m, destval, *srcreg);\r |
| 366 | store_data_word(m,destoffset,destval);\r |
| 367 | break;\r |
| 368 | case 2:\r |
| 369 | destoffset=decode_rm10_address(m,rl);\r |
| 370 | destval = fetch_data_word(m,destoffset);\r |
| 371 | srcreg = DECODE_RM_WORD_REGISTER(m,rh);\r |
| 372 | destval = or_word(m, destval, *srcreg);\r |
| 373 | store_data_word(m,destoffset,destval);\r |
| 374 | break;\r |
| 375 | case 3: /* register to register */\r |
| 376 | destreg = DECODE_RM_WORD_REGISTER(m,rl);\r |
| 377 | srcreg = DECODE_RM_WORD_REGISTER(m,rh);\r |
| 378 | *destreg = or_word(m, *destreg, *srcreg);\r |
| 379 | break;\r |
| 380 | }\r |
| 381 | DECODE_CLEAR_SEGOVR(m);\r |
| 382 | }\r |
| 383 | \r |
| 384 | /*opcode=0x0a*/\r |
| 385 | static void i86op_or_byte_R_RM(PC_ENV *m)\r |
| 386 | {\r |
| 387 | uint16 mod,rl,rh;\r |
| 388 | uint8 *destreg,*srcreg;\r |
| 389 | uint16 srcoffset;\r |
| 390 | uint8 srcval;\r |
| 391 | FETCH_DECODE_MODRM(m,mod,rh,rl);\r |
| 392 | switch (mod)\r |
| 393 | {\r |
| 394 | case 0:\r |
| 395 | destreg = DECODE_RM_BYTE_REGISTER(m,rh);\r |
| 396 | srcoffset=decode_rm00_address(m,rl);\r |
| 397 | srcval = fetch_data_byte(m,srcoffset);\r |
| 398 | *destreg = or_byte(m, *destreg, srcval);\r |
| 399 | break;\r |
| 400 | case 1:\r |
| 401 | destreg = DECODE_RM_BYTE_REGISTER(m,rh);\r |
| 402 | srcoffset=decode_rm01_address(m,rl);\r |
| 403 | srcval = fetch_data_byte(m,srcoffset);\r |
| 404 | *destreg = or_byte(m, *destreg, srcval);\r |
| 405 | break;\r |
| 406 | case 2:\r |
| 407 | destreg = DECODE_RM_BYTE_REGISTER(m,rh);\r |
| 408 | srcoffset=decode_rm10_address(m,rl);\r |
| 409 | srcval = fetch_data_byte(m,srcoffset);\r |
| 410 | *destreg = or_byte(m, * destreg, srcval);\r |
| 411 | break;\r |
| 412 | case 3: /* register to register */\r |
| 413 | destreg = DECODE_RM_BYTE_REGISTER(m,rh);\r |
| 414 | srcreg = DECODE_RM_BYTE_REGISTER(m,rl);\r |
| 415 | *destreg = or_byte(m, *destreg, *srcreg);\r |
| 416 | break;\r |
| 417 | }\r |
| 418 | DECODE_CLEAR_SEGOVR(m);\r |
| 419 | }\r |
| 420 | \r |
| 421 | /*opcode=0x0b*/\r |
| 422 | static void i86op_or_word_R_RM(PC_ENV *m)\r |
| 423 | {\r |
| 424 | uint16 mod,rl,rh;\r |
| 425 | uint16 *destreg,*srcreg;\r |
| 426 | uint16 srcoffset;\r |
| 427 | uint16 srcval;\r |
| 428 | FETCH_DECODE_MODRM(m,mod,rh,rl);\r |
| 429 | switch (mod)\r |
| 430 | {\r |
| 431 | case 0:\r |
| 432 | destreg = DECODE_RM_WORD_REGISTER(m,rh);\r |
| 433 | srcoffset=decode_rm00_address(m,rl);\r |
| 434 | srcval = fetch_data_word(m,srcoffset);\r |
| 435 | *destreg = or_word(m, *destreg, srcval);\r |
| 436 | break;\r |
| 437 | case 1:\r |
| 438 | destreg = DECODE_RM_WORD_REGISTER(m,rh);\r |
| 439 | srcoffset=decode_rm01_address(m,rl);\r |
| 440 | srcval = fetch_data_word(m,srcoffset);\r |
| 441 | *destreg = or_word(m, *destreg, srcval);\r |
| 442 | break;\r |
| 443 | case 2:\r |
| 444 | destreg = DECODE_RM_WORD_REGISTER(m,rh);\r |
| 445 | srcoffset=decode_rm10_address(m,rl);\r |
| 446 | srcval = fetch_data_word(m,srcoffset);\r |
| 447 | *destreg = or_word(m, *destreg, srcval);\r |
| 448 | break;\r |
| 449 | case 3: /* register to register */\r |
| 450 | destreg = DECODE_RM_WORD_REGISTER(m,rh);\r |
| 451 | srcreg = DECODE_RM_WORD_REGISTER(m,rl);\r |
| 452 | *destreg = or_word(m, *destreg, *srcreg);\r |
| 453 | break;\r |
| 454 | }\r |
| 455 | DECODE_CLEAR_SEGOVR(m);\r |
| 456 | }\r |
| 457 | \r |
| 458 | /*opcode=0x0c*/\r |
| 459 | static void i86op_or_byte_AL_IMM(PC_ENV *m)\r |
| 460 | {\r |
| 461 | uint8 srcval;\r |
| 462 | srcval = fetch_byte_imm(m);\r |
| 463 | m->R_AL = or_byte(m, m->R_AL, srcval);\r |
| 464 | DECODE_CLEAR_SEGOVR(m);\r |
| 465 | }\r |
| 466 | \r |
| 467 | /*opcode=0x0d*/\r |
| 468 | static void i86op_or_word_AX_IMM(PC_ENV *m)\r |
| 469 | {\r |
| 470 | uint16 srcval;\r |
| 471 | srcval = fetch_word_imm(m);\r |
| 472 | m->R_AX = or_word(m, m->R_AX, srcval);\r |
| 473 | DECODE_CLEAR_SEGOVR(m);\r |
| 474 | }\r |
| 475 | \r |
| 476 | /*opcode=0x0e*/\r |
| 477 | static void i86op_push_CS(PC_ENV *m)\r |
| 478 | {\r |
| 479 | push_word(m,m->R_CS);\r |
| 480 | DECODE_CLEAR_SEGOVR(m);\r |
| 481 | }\r |
| 482 | \r |
| 483 | /*opcode=0x0f === ILLEGAL OP*/\r |
| 484 | \r |
| 485 | /*opcode=0x10*/\r |
| 486 | static void i86op_adc_byte_RM_R(PC_ENV *m)\r |
| 487 | {\r |
| 488 | uint16 mod,rl,rh;\r |
| 489 | uint8 *destreg,*srcreg;\r |
| 490 | uint16 destoffset;\r |
| 491 | uint8 destval;\r |
| 492 | FETCH_DECODE_MODRM(m,mod,rh,rl);\r |
| 493 | switch (mod)\r |
| 494 | {\r |
| 495 | case 0:\r |
| 496 | destoffset=decode_rm00_address(m,rl);\r |
| 497 | destval = fetch_data_byte(m,destoffset);\r |
| 498 | srcreg = DECODE_RM_BYTE_REGISTER(m,rh);\r |
| 499 | destval = adc_byte(m, destval, *srcreg);\r |
| 500 | store_data_byte(m,destoffset,destval);\r |
| 501 | break;\r |
| 502 | case 1:\r |
| 503 | destoffset=decode_rm01_address(m,rl);\r |
| 504 | destval = fetch_data_byte(m,destoffset);\r |
| 505 | srcreg = DECODE_RM_BYTE_REGISTER(m,rh);\r |
| 506 | destval = adc_byte(m, destval, *srcreg);\r |
| 507 | store_data_byte(m,destoffset,destval);\r |
| 508 | break;\r |
| 509 | case 2:\r |
| 510 | destoffset=decode_rm10_address(m,rl);\r |
| 511 | destval = fetch_data_byte(m,destoffset);\r |
| 512 | srcreg = DECODE_RM_BYTE_REGISTER(m,rh);\r |
| 513 | destval = adc_byte(m, destval, *srcreg);\r |
| 514 | store_data_byte(m,destoffset,destval);\r |
| 515 | break;\r |
| 516 | case 3: /* register to register */\r |
| 517 | destreg = DECODE_RM_BYTE_REGISTER(m,rl);\r |
| 518 | srcreg = DECODE_RM_BYTE_REGISTER(m,rh);\r |
| 519 | *destreg = adc_byte(m, *destreg, *srcreg);\r |
| 520 | break;\r |
| 521 | }\r |
| 522 | DECODE_CLEAR_SEGOVR(m);\r |
| 523 | }\r |
| 524 | \r |
| 525 | /*opcode=0x11*/\r |
| 526 | static void i86op_adc_word_RM_R(PC_ENV *m)\r |
| 527 | {\r |
| 528 | uint16 mod,rl,rh;\r |
| 529 | uint16 *destreg,*srcreg;\r |
| 530 | uint16 destoffset;\r |
| 531 | uint16 destval;\r |
| 532 | FETCH_DECODE_MODRM(m,mod,rh,rl);\r |
| 533 | switch (mod)\r |
| 534 | {\r |
| 535 | case 0:\r |
| 536 | destoffset=decode_rm00_address(m,rl);\r |
| 537 | destval = fetch_data_word(m,destoffset);\r |
| 538 | srcreg = DECODE_RM_WORD_REGISTER(m,rh);\r |
| 539 | destval = adc_word(m, destval, *srcreg);\r |
| 540 | store_data_word(m,destoffset,destval);\r |
| 541 | break;\r |
| 542 | case 1:\r |
| 543 | destoffset=decode_rm01_address(m,rl);\r |
| 544 | destval = fetch_data_word(m,destoffset);\r |
| 545 | srcreg = DECODE_RM_WORD_REGISTER(m,rh);\r |
| 546 | destval = adc_word(m, destval, *srcreg);\r |
| 547 | store_data_word(m,destoffset,destval);\r |
| 548 | break;\r |
| 549 | case 2:\r |
| 550 | destoffset=decode_rm10_address(m,rl);\r |
| 551 | destval = fetch_data_word(m,destoffset);\r |
| 552 | srcreg = DECODE_RM_WORD_REGISTER(m,rh);\r |
| 553 | destval = adc_word(m, destval, *srcreg);\r |
| 554 | store_data_word(m,destoffset,destval);\r |
| 555 | break;\r |
| 556 | case 3: /* register to register */\r |
| 557 | destreg = DECODE_RM_WORD_REGISTER(m,rl);\r |
| 558 | srcreg = DECODE_RM_WORD_REGISTER(m,rh);\r |
| 559 | *destreg = adc_word(m, *destreg, *srcreg);\r |
| 560 | break;\r |
| 561 | }\r |
| 562 | DECODE_CLEAR_SEGOVR(m);\r |
| 563 | }\r |
| 564 | \r |
| 565 | /*opcode=0x12*/\r |
| 566 | static void i86op_adc_byte_R_RM(PC_ENV *m)\r |
| 567 | {\r |
| 568 | uint16 mod,rl,rh;\r |
| 569 | uint8 *destreg,*srcreg;\r |
| 570 | uint16 srcoffset;\r |
| 571 | uint8 srcval;\r |
| 572 | FETCH_DECODE_MODRM(m,mod,rh,rl);\r |
| 573 | switch (mod)\r |
| 574 | {\r |
| 575 | case 0:\r |
| 576 | destreg = DECODE_RM_BYTE_REGISTER(m,rh);\r |
| 577 | srcoffset=decode_rm00_address(m,rl);\r |
| 578 | srcval = fetch_data_byte(m,srcoffset);\r |
| 579 | *destreg = adc_byte(m, *destreg, srcval);\r |
| 580 | break;\r |
| 581 | case 1:\r |
| 582 | destreg = DECODE_RM_BYTE_REGISTER(m,rh);\r |
| 583 | srcoffset=decode_rm01_address(m,rl);\r |
| 584 | srcval = fetch_data_byte(m,srcoffset);\r |
| 585 | *destreg = adc_byte(m, *destreg, srcval);\r |
| 586 | break;\r |
| 587 | case 2:\r |
| 588 | destreg = DECODE_RM_BYTE_REGISTER(m,rh);\r |
| 589 | srcoffset=decode_rm10_address(m,rl);\r |
| 590 | srcval = fetch_data_byte(m,srcoffset);\r |
| 591 | *destreg = adc_byte(m, * destreg, srcval);\r |
| 592 | break;\r |
| 593 | case 3: /* register to register */\r |
| 594 | destreg = DECODE_RM_BYTE_REGISTER(m,rh);\r |
| 595 | srcreg = DECODE_RM_BYTE_REGISTER(m,rl);\r |
| 596 | *destreg = adc_byte(m, *destreg, *srcreg);\r |
| 597 | break;\r |
| 598 | }\r |
| 599 | DECODE_CLEAR_SEGOVR(m);\r |
| 600 | }\r |
| 601 | \r |
| 602 | /*opcode=0x13*/\r |
| 603 | static void i86op_adc_word_R_RM(PC_ENV *m)\r |
| 604 | {\r |
| 605 | uint16 mod,rl,rh;\r |
| 606 | uint16 *destreg,*srcreg;\r |
| 607 | uint16 srcoffset;\r |
| 608 | uint16 srcval;\r |
| 609 | FETCH_DECODE_MODRM(m,mod,rh,rl);\r |
| 610 | switch (mod)\r |
| 611 | {\r |
| 612 | case 0:\r |
| 613 | destreg = DECODE_RM_WORD_REGISTER(m,rh);\r |
| 614 | srcoffset=decode_rm00_address(m,rl);\r |
| 615 | srcval = fetch_data_word(m,srcoffset);\r |
| 616 | *destreg = adc_word(m, *destreg, srcval);\r |
| 617 | break;\r |
| 618 | case 1:\r |
| 619 | destreg = DECODE_RM_WORD_REGISTER(m,rh);\r |
| 620 | srcoffset=decode_rm01_address(m,rl);\r |
| 621 | srcval = fetch_data_word(m,srcoffset);\r |
| 622 | *destreg = adc_word(m, *destreg, srcval);\r |
| 623 | break;\r |
| 624 | case 2:\r |
| 625 | destreg = DECODE_RM_WORD_REGISTER(m,rh);\r |
| 626 | srcoffset=decode_rm10_address(m,rl);\r |
| 627 | srcval = fetch_data_word(m,srcoffset);\r |
| 628 | *destreg = adc_word(m, *destreg, srcval);\r |
| 629 | break;\r |
| 630 | case 3: /* register to register */\r |
| 631 | destreg = DECODE_RM_WORD_REGISTER(m,rh);\r |
| 632 | srcreg = DECODE_RM_WORD_REGISTER(m,rl);\r |
| 633 | *destreg = adc_word(m, *destreg, *srcreg);\r |
| 634 | break;\r |
| 635 | }\r |
| 636 | DECODE_CLEAR_SEGOVR(m);\r |
| 637 | }\r |
| 638 | \r |
| 639 | /*opcode=0x14*/\r |
| 640 | static void i86op_adc_byte_AL_IMM(PC_ENV *m)\r |
| 641 | {\r |
| 642 | uint8 srcval;\r |
| 643 | srcval = fetch_byte_imm(m);\r |
| 644 | m->R_AL = adc_byte(m, m->R_AL, srcval);\r |
| 645 | DECODE_CLEAR_SEGOVR(m);\r |
| 646 | }\r |
| 647 | \r |
| 648 | /*opcode=0x15*/\r |
| 649 | static void i86op_adc_word_AX_IMM(PC_ENV *m)\r |
| 650 | {\r |
| 651 | uint16 srcval;\r |
| 652 | srcval = fetch_word_imm(m);\r |
| 653 | m->R_AX = adc_word(m, m->R_AX, srcval);\r |
| 654 | DECODE_CLEAR_SEGOVR(m);\r |
| 655 | }\r |
| 656 | \r |
| 657 | /*opcode=0x16*/\r |
| 658 | static void i86op_push_SS(PC_ENV *m)\r |
| 659 | {\r |
| 660 | push_word(m,m->R_SS);\r |
| 661 | DECODE_CLEAR_SEGOVR(m);\r |
| 662 | }\r |
| 663 | \r |
| 664 | /*opcode=0x17*/\r |
| 665 | static void i86op_pop_SS(PC_ENV *m)\r |
| 666 | {\r |
| 667 | m->R_SS = pop_word(m);\r |
| 668 | DECODE_CLEAR_SEGOVR(m);\r |
| 669 | }\r |
| 670 | \r |
| 671 | /*opcode=0x18*/\r |
| 672 | static void i86op_sbb_byte_RM_R(PC_ENV *m)\r |
| 673 | {\r |
| 674 | uint16 mod,rl,rh;\r |
| 675 | uint8 *destreg,*srcreg;\r |
| 676 | uint16 destoffset;\r |
| 677 | uint8 destval;\r |
| 678 | FETCH_DECODE_MODRM(m,mod,rh,rl);\r |
| 679 | switch (mod)\r |
| 680 | {\r |
| 681 | case 0:\r |
| 682 | destoffset=decode_rm00_address(m,rl);\r |
| 683 | destval = fetch_data_byte(m,destoffset);\r |
| 684 | srcreg = DECODE_RM_BYTE_REGISTER(m,rh);\r |
| 685 | destval = sbb_byte(m, destval, *srcreg);\r |
| 686 | store_data_byte(m,destoffset,destval);\r |
| 687 | break;\r |
| 688 | case 1:\r |
| 689 | destoffset=decode_rm01_address(m,rl);\r |
| 690 | destval = fetch_data_byte(m,destoffset);\r |
| 691 | srcreg = DECODE_RM_BYTE_REGISTER(m,rh);\r |
| 692 | destval = sbb_byte(m, destval, *srcreg);\r |
| 693 | store_data_byte(m,destoffset,destval);\r |
| 694 | break;\r |
| 695 | case 2:\r |
| 696 | destoffset=decode_rm10_address(m,rl);\r |
| 697 | destval = fetch_data_byte(m,destoffset);\r |
| 698 | srcreg = DECODE_RM_BYTE_REGISTER(m,rh);\r |
| 699 | destval = sbb_byte(m, destval, *srcreg);\r |
| 700 | store_data_byte(m,destoffset,destval);\r |
| 701 | break;\r |
| 702 | case 3: /* register to register */\r |
| 703 | destreg = DECODE_RM_BYTE_REGISTER(m,rl);\r |
| 704 | srcreg = DECODE_RM_BYTE_REGISTER(m,rh);\r |
| 705 | *destreg = sbb_byte(m, *destreg, *srcreg);\r |
| 706 | break;\r |
| 707 | }\r |
| 708 | DECODE_CLEAR_SEGOVR(m);\r |
| 709 | }\r |
| 710 | \r |
| 711 | /*opcode=0x19*/\r |
| 712 | static void i86op_sbb_word_RM_R(PC_ENV *m)\r |
| 713 | {\r |
| 714 | uint16 mod,rl,rh;\r |
| 715 | uint16 *destreg,*srcreg;\r |
| 716 | uint16 destoffset;\r |
| 717 | uint16 destval;\r |
| 718 | FETCH_DECODE_MODRM(m,mod,rh,rl);\r |
| 719 | switch (mod)\r |
| 720 | {\r |
| 721 | case 0:\r |
| 722 | destoffset=decode_rm00_address(m,rl);\r |
| 723 | destval = fetch_data_word(m,destoffset);\r |
| 724 | srcreg = DECODE_RM_WORD_REGISTER(m,rh);\r |
| 725 | destval = sbb_word(m, destval, *srcreg);\r |
| 726 | store_data_word(m,destoffset,destval);\r |
| 727 | break;\r |
| 728 | case 1:\r |
| 729 | destoffset=decode_rm01_address(m,rl);\r |
| 730 | destval = fetch_data_word(m,destoffset);\r |
| 731 | srcreg = DECODE_RM_WORD_REGISTER(m,rh);\r |
| 732 | destval = sbb_word(m, destval, *srcreg);\r |
| 733 | store_data_word(m,destoffset,destval);\r |
| 734 | break;\r |
| 735 | case 2:\r |
| 736 | destoffset=decode_rm10_address(m,rl);\r |
| 737 | destval = fetch_data_word(m,destoffset);\r |
| 738 | srcreg = DECODE_RM_WORD_REGISTER(m,rh);\r |
| 739 | destval = sbb_word(m, destval, *srcreg);\r |
| 740 | store_data_word(m,destoffset,destval);\r |
| 741 | break;\r |
| 742 | case 3: /* register to register */\r |
| 743 | destreg = DECODE_RM_WORD_REGISTER(m,rl);\r |
| 744 | srcreg = DECODE_RM_WORD_REGISTER(m,rh);\r |
| 745 | *destreg = sbb_word(m, *destreg, *srcreg);\r |
| 746 | break;\r |
| 747 | }\r |
| 748 | DECODE_CLEAR_SEGOVR(m);\r |
| 749 | }\r |
| 750 | \r |
| 751 | /*opcode=0x1a*/\r |
| 752 | static void i86op_sbb_byte_R_RM(PC_ENV *m)\r |
| 753 | {\r |
| 754 | uint16 mod,rl,rh;\r |
| 755 | uint8 *destreg,*srcreg;\r |
| 756 | uint16 srcoffset;\r |
| 757 | uint8 srcval;\r |
| 758 | FETCH_DECODE_MODRM(m,mod,rh,rl);\r |
| 759 | switch (mod)\r |
| 760 | {\r |
| 761 | case 0:\r |
| 762 | destreg = DECODE_RM_BYTE_REGISTER(m,rh);\r |
| 763 | srcoffset=decode_rm00_address(m,rl);\r |
| 764 | srcval = fetch_data_byte(m,srcoffset);\r |
| 765 | *destreg = sbb_byte(m, *destreg, srcval);\r |
| 766 | break;\r |
| 767 | case 1:\r |
| 768 | destreg = DECODE_RM_BYTE_REGISTER(m,rh);\r |
| 769 | srcoffset=decode_rm01_address(m,rl);\r |
| 770 | srcval = fetch_data_byte(m,srcoffset);\r |
| 771 | *destreg = sbb_byte(m, *destreg, srcval);\r |
| 772 | break;\r |
| 773 | case 2:\r |
| 774 | destreg = DECODE_RM_BYTE_REGISTER(m,rh);\r |
| 775 | srcoffset=decode_rm10_address(m,rl);\r |
| 776 | srcval = fetch_data_byte(m,srcoffset);\r |
| 777 | *destreg = sbb_byte(m, * destreg, srcval);\r |
| 778 | break;\r |
| 779 | case 3: /* register to register */\r |
| 780 | destreg = DECODE_RM_BYTE_REGISTER(m,rh);\r |
| 781 | srcreg = DECODE_RM_BYTE_REGISTER(m,rl);\r |
| 782 | *destreg = sbb_byte(m, *destreg, *srcreg);\r |
| 783 | break;\r |
| 784 | }\r |
| 785 | DECODE_CLEAR_SEGOVR(m);\r |
| 786 | }\r |
| 787 | \r |
| 788 | /*opcode=0x1b*/\r |
| 789 | static void i86op_sbb_word_R_RM(PC_ENV *m)\r |
| 790 | {\r |
| 791 | uint16 mod,rl,rh;\r |
| 792 | uint16 *destreg,*srcreg;\r |
| 793 | uint16 srcoffset;\r |
| 794 | uint16 srcval;\r |
| 795 | FETCH_DECODE_MODRM(m,mod,rh,rl);\r |
| 796 | switch (mod)\r |
| 797 | {\r |
| 798 | case 0:\r |
| 799 | destreg = DECODE_RM_WORD_REGISTER(m,rh);\r |
| 800 | srcoffset=decode_rm00_address(m,rl);\r |
| 801 | srcval = fetch_data_word(m,srcoffset);\r |
| 802 | *destreg = sbb_word(m, *destreg, srcval);\r |
| 803 | break;\r |
| 804 | case 1:\r |
| 805 | destreg = DECODE_RM_WORD_REGISTER(m,rh);\r |
| 806 | srcoffset=decode_rm01_address(m,rl);\r |
| 807 | srcval = fetch_data_word(m,srcoffset);\r |
| 808 | *destreg = sbb_word(m, *destreg, srcval);\r |
| 809 | break;\r |
| 810 | case 2:\r |
| 811 | destreg = DECODE_RM_WORD_REGISTER(m,rh);\r |
| 812 | srcoffset=decode_rm10_address(m,rl);\r |
| 813 | srcval = fetch_data_word(m,srcoffset);\r |
| 814 | *destreg = sbb_word(m, *destreg, srcval);\r |
| 815 | break;\r |
| 816 | case 3: /* register to register */\r |
| 817 | destreg = DECODE_RM_WORD_REGISTER(m,rh);\r |
| 818 | srcreg = DECODE_RM_WORD_REGISTER(m,rl);\r |
| 819 | *destreg = sbb_word(m, *destreg, *srcreg);\r |
| 820 | break;\r |
| 821 | }\r |
| 822 | DECODE_CLEAR_SEGOVR(m);\r |
| 823 | }\r |
| 824 | \r |
| 825 | /*opcode=0x1c*/\r |
| 826 | static void i86op_sbb_byte_AL_IMM(PC_ENV *m)\r |
| 827 | {\r |
| 828 | uint8 srcval;\r |
| 829 | srcval = fetch_byte_imm(m);\r |
| 830 | m->R_AL = sbb_byte(m, m->R_AL, srcval);\r |
| 831 | DECODE_CLEAR_SEGOVR(m);\r |
| 832 | }\r |
| 833 | \r |
| 834 | /*opcode=0x1d*/\r |
| 835 | static void i86op_sbb_word_AX_IMM(PC_ENV *m)\r |
| 836 | {\r |
| 837 | uint16 srcval;\r |
| 838 | srcval = fetch_word_imm(m);\r |
| 839 | m->R_AX = sbb_word(m, m->R_AX, srcval);\r |
| 840 | DECODE_CLEAR_SEGOVR(m);\r |
| 841 | }\r |
| 842 | \r |
| 843 | /*opcode=0x1e*/\r |
| 844 | static void i86op_push_DS(PC_ENV *m)\r |
| 845 | {\r |
| 846 | push_word(m,m->R_DS);\r |
| 847 | DECODE_CLEAR_SEGOVR(m);\r |
| 848 | }\r |
| 849 | \r |
| 850 | /*opcode=0x1f*/\r |
| 851 | static void i86op_pop_DS(PC_ENV *m)\r |
| 852 | {\r |
| 853 | m->R_DS = pop_word(m);\r |
| 854 | DECODE_CLEAR_SEGOVR(m);\r |
| 855 | }\r |
| 856 | \r |
| 857 | /*opcode=0x20*/\r |
| 858 | static void i86op_and_byte_RM_R(PC_ENV *m)\r |
| 859 | {\r |
| 860 | uint16 mod,rl,rh;\r |
| 861 | uint8 *destreg,*srcreg;\r |
| 862 | uint16 destoffset;\r |
| 863 | uint8 destval;\r |
| 864 | FETCH_DECODE_MODRM(m,mod,rh,rl);\r |
| 865 | switch (mod)\r |
| 866 | {\r |
| 867 | case 0:\r |
| 868 | destoffset=decode_rm00_address(m,rl);\r |
| 869 | destval = fetch_data_byte(m,destoffset);\r |
| 870 | srcreg = DECODE_RM_BYTE_REGISTER(m,rh);\r |
| 871 | destval = and_byte(m, destval, *srcreg);\r |
| 872 | store_data_byte(m,destoffset,destval);\r |
| 873 | break;\r |
| 874 | case 1:\r |
| 875 | destoffset=decode_rm01_address(m,rl);\r |
| 876 | destval = fetch_data_byte(m,destoffset);\r |
| 877 | srcreg = DECODE_RM_BYTE_REGISTER(m,rh);\r |
| 878 | destval = and_byte(m, destval, *srcreg);\r |
| 879 | store_data_byte(m,destoffset,destval);\r |
| 880 | break;\r |
| 881 | case 2:\r |
| 882 | destoffset=decode_rm10_address(m,rl);\r |
| 883 | destval = fetch_data_byte(m,destoffset);\r |
| 884 | srcreg = DECODE_RM_BYTE_REGISTER(m,rh);\r |
| 885 | destval = and_byte(m, destval, *srcreg);\r |
| 886 | store_data_byte(m,destoffset,destval);\r |
| 887 | break;\r |
| 888 | case 3: /* register to register */\r |
| 889 | destreg = DECODE_RM_BYTE_REGISTER(m,rl);\r |
| 890 | srcreg = DECODE_RM_BYTE_REGISTER(m,rh);\r |
| 891 | *destreg = and_byte(m, *destreg, *srcreg);\r |
| 892 | break;\r |
| 893 | }\r |
| 894 | DECODE_CLEAR_SEGOVR(m);\r |
| 895 | }\r |
| 896 | \r |
| 897 | /*opcode=0x21*/\r |
| 898 | static void i86op_and_word_RM_R(PC_ENV *m)\r |
| 899 | {\r |
| 900 | uint16 mod,rl,rh;\r |
| 901 | uint16 *destreg,*srcreg;\r |
| 902 | uint16 destoffset;\r |
| 903 | uint16 destval;\r |
| 904 | FETCH_DECODE_MODRM(m,mod,rh,rl);\r |
| 905 | switch (mod)\r |
| 906 | {\r |
| 907 | case 0:\r |
| 908 | destoffset=decode_rm00_address(m,rl);\r |
| 909 | destval = fetch_data_word(m,destoffset);\r |
| 910 | srcreg = DECODE_RM_WORD_REGISTER(m,rh);\r |
| 911 | destval = and_word(m, destval, *srcreg);\r |
| 912 | store_data_word(m,destoffset,destval);\r |
| 913 | break;\r |
| 914 | case 1:\r |
| 915 | destoffset=decode_rm01_address(m,rl);\r |
| 916 | destval = fetch_data_word(m,destoffset);\r |
| 917 | srcreg = DECODE_RM_WORD_REGISTER(m,rh);\r |
| 918 | destval = and_word(m, destval, *srcreg);\r |
| 919 | store_data_word(m,destoffset,destval);\r |
| 920 | break;\r |
| 921 | case 2:\r |
| 922 | destoffset=decode_rm10_address(m,rl);\r |
| 923 | destval = fetch_data_word(m,destoffset);\r |
| 924 | srcreg = DECODE_RM_WORD_REGISTER(m,rh);\r |
| 925 | destval = and_word(m, destval, *srcreg);\r |
| 926 | store_data_word(m,destoffset,destval);\r |
| 927 | break;\r |
| 928 | case 3: /* register to register */\r |
| 929 | destreg = DECODE_RM_WORD_REGISTER(m,rl);\r |
| 930 | srcreg = DECODE_RM_WORD_REGISTER(m,rh);\r |
| 931 | *destreg = and_word(m, *destreg, *srcreg);\r |
| 932 | break;\r |
| 933 | }\r |
| 934 | DECODE_CLEAR_SEGOVR(m);\r |
| 935 | }\r |
| 936 | \r |
| 937 | /*opcode=0x22*/\r |
| 938 | static void i86op_and_byte_R_RM(PC_ENV *m)\r |
| 939 | {\r |
| 940 | uint16 mod,rl,rh;\r |
| 941 | uint8 *destreg,*srcreg;\r |
| 942 | uint16 srcoffset;\r |
| 943 | uint8 srcval;\r |
| 944 | FETCH_DECODE_MODRM(m,mod,rh,rl);\r |
| 945 | switch (mod)\r |
| 946 | {\r |
| 947 | case 0:\r |
| 948 | destreg = DECODE_RM_BYTE_REGISTER(m,rh);\r |
| 949 | srcoffset=decode_rm00_address(m,rl);\r |
| 950 | srcval = fetch_data_byte(m,srcoffset);\r |
| 951 | *destreg = and_byte(m, *destreg, srcval);\r |
| 952 | break;\r |
| 953 | case 1:\r |
| 954 | destreg = DECODE_RM_BYTE_REGISTER(m,rh);\r |
| 955 | srcoffset=decode_rm01_address(m,rl);\r |
| 956 | srcval = fetch_data_byte(m,srcoffset);\r |
| 957 | *destreg = and_byte(m, *destreg, srcval);\r |
| 958 | break;\r |
| 959 | case 2:\r |
| 960 | destreg = DECODE_RM_BYTE_REGISTER(m,rh);\r |
| 961 | srcoffset=decode_rm10_address(m,rl);\r |
| 962 | srcval = fetch_data_byte(m,srcoffset);\r |
| 963 | *destreg = and_byte(m, * destreg, srcval);\r |
| 964 | break;\r |
| 965 | case 3: /* register to register */\r |
| 966 | destreg = DECODE_RM_BYTE_REGISTER(m,rh);\r |
| 967 | srcreg = DECODE_RM_BYTE_REGISTER(m,rl);\r |
| 968 | *destreg = and_byte(m, *destreg, *srcreg);\r |
| 969 | break;\r |
| 970 | }\r |
| 971 | DECODE_CLEAR_SEGOVR(m);\r |
| 972 | }\r |
| 973 | \r |
| 974 | /*opcode=0x23*/\r |
| 975 | static void i86op_and_word_R_RM(PC_ENV *m)\r |
| 976 | {\r |
| 977 | uint16 mod,rl,rh;\r |
| 978 | uint16 *destreg,*srcreg;\r |
| 979 | uint16 srcoffset;\r |
| 980 | uint16 srcval;\r |
| 981 | FETCH_DECODE_MODRM(m,mod,rh,rl);\r |
| 982 | switch (mod)\r |
| 983 | {\r |
| 984 | case 0:\r |
| 985 | destreg = DECODE_RM_WORD_REGISTER(m,rh);\r |
| 986 | srcoffset=decode_rm00_address(m,rl);\r |
| 987 | srcval = fetch_data_word(m,srcoffset);\r |
| 988 | *destreg = and_word(m, *destreg, srcval);\r |
| 989 | break;\r |
| 990 | case 1:\r |
| 991 | destreg = DECODE_RM_WORD_REGISTER(m,rh);\r |
| 992 | srcoffset=decode_rm01_address(m,rl);\r |
| 993 | srcval = fetch_data_word(m,srcoffset);\r |
| 994 | *destreg = and_word(m, *destreg, srcval);\r |
| 995 | break;\r |
| 996 | case 2:\r |
| 997 | destreg = DECODE_RM_WORD_REGISTER(m,rh);\r |
| 998 | srcoffset=decode_rm10_address(m,rl);\r |
| 999 | srcval = fetch_data_word(m,srcoffset);\r |
| 1000 | *destreg = and_word(m, *destreg, srcval);\r |
| 1001 | break;\r |
| 1002 | case 3: /* register to register */\r |
| 1003 | destreg = DECODE_RM_WORD_REGISTER(m,rh);\r |
| 1004 | srcreg = DECODE_RM_WORD_REGISTER(m,rl);\r |
| 1005 | *destreg = and_word(m, *destreg, *srcreg);\r |
| 1006 | break;\r |
| 1007 | }\r |
| 1008 | DECODE_CLEAR_SEGOVR(m);\r |
| 1009 | }\r |
| 1010 | \r |
| 1011 | /*opcode=0x24*/\r |
| 1012 | static void i86op_and_byte_AL_IMM(PC_ENV *m)\r |
| 1013 | {\r |
| 1014 | uint8 srcval;\r |
| 1015 | srcval = fetch_byte_imm(m);\r |
| 1016 | m->R_AL = and_byte(m, m->R_AL, srcval);\r |
| 1017 | DECODE_CLEAR_SEGOVR(m);\r |
| 1018 | }\r |
| 1019 | \r |
| 1020 | /*opcode=0x25*/\r |
| 1021 | static void i86op_and_word_AX_IMM(PC_ENV *m)\r |
| 1022 | {\r |
| 1023 | uint16 srcval;\r |
| 1024 | srcval = fetch_word_imm(m);\r |
| 1025 | m->R_AX = and_word(m, m->R_AX, srcval);\r |
| 1026 | DECODE_CLEAR_SEGOVR(m);\r |
| 1027 | }\r |
| 1028 | \r |
| 1029 | /*opcode=0x26*/\r |
| 1030 | static void i86op_segovr_ES(PC_ENV *m)\r |
| 1031 | {\r |
| 1032 | m->sysmode |= SYSMODE_SEGOVR_ES;\r |
| 1033 | /* note the lack of DECODE_CLEAR_SEGOVR(r)\r |
| 1034 | since, here is one of 4 opcode subroutines we do not\r |
| 1035 | want to do this.\r |
| 1036 | */\r |
| 1037 | }\r |
| 1038 | \r |
| 1039 | /*opcode=0x27*/\r |
| 1040 | static void i86op_daa(PC_ENV *m)\r |
| 1041 | {\r |
| 1042 | uint16 dbyte;\r |
| 1043 | dbyte = m->R_AL;\r |
| 1044 | if (ACCESS_FLAG(m,F_AF)|| (dbyte&0xf) > 9)\r |
| 1045 | {\r |
| 1046 | dbyte += 6;\r |
| 1047 | if (dbyte&0x100)\r |
| 1048 | SET_FLAG(m, F_CF);\r |
| 1049 | SET_FLAG(m, F_AF);\r |
| 1050 | }\r |
| 1051 | else\r |
| 1052 | CLEAR_FLAG(m, F_AF);\r |
| 1053 | if (ACCESS_FLAG(m,F_CF) || (dbyte&0xf0) > 0x90)\r |
| 1054 | {\r |
| 1055 | dbyte += 0x60;\r |
| 1056 | SET_FLAG(m, F_CF);\r |
| 1057 | }\r |
| 1058 | else\r |
| 1059 | CLEAR_FLAG(m, F_CF);\r |
| 1060 | m->R_AL = (uint8) dbyte;\r |
| 1061 | CONDITIONAL_SET_FLAG((m->R_AL & 0x80),m,F_SF);\r |
| 1062 | CONDITIONAL_SET_FLAG((m->R_AL == 0), m,F_ZF);\r |
| 1063 | CONDITIONAL_SET_FLAG((parity_tab[m->R_AL]),m,F_PF);\r |
| 1064 | DECODE_CLEAR_SEGOVR(m);\r |
| 1065 | }\r |
| 1066 | \r |
| 1067 | /*opcode=0x28*/\r |
| 1068 | static void i86op_sub_byte_RM_R(PC_ENV *m)\r |
| 1069 | {\r |
| 1070 | uint16 mod,rl,rh;\r |
| 1071 | uint8 *destreg,*srcreg;\r |
| 1072 | uint16 destoffset;\r |
| 1073 | uint8 destval;\r |
| 1074 | FETCH_DECODE_MODRM(m,mod,rh,rl);\r |
| 1075 | switch (mod)\r |
| 1076 | {\r |
| 1077 | case 0:\r |
| 1078 | destoffset=decode_rm00_address(m,rl);\r |
| 1079 | destval = fetch_data_byte(m,destoffset);\r |
| 1080 | srcreg = DECODE_RM_BYTE_REGISTER(m,rh);\r |
| 1081 | destval = sub_byte(m, destval, *srcreg);\r |
| 1082 | store_data_byte(m,destoffset,destval);\r |
| 1083 | break;\r |
| 1084 | case 1:\r |
| 1085 | destoffset=decode_rm01_address(m,rl);\r |
| 1086 | destval = fetch_data_byte(m,destoffset);\r |
| 1087 | srcreg = DECODE_RM_BYTE_REGISTER(m,rh);\r |
| 1088 | destval = sub_byte(m, destval, *srcreg);\r |
| 1089 | store_data_byte(m,destoffset,destval);\r |
| 1090 | break;\r |
| 1091 | case 2:\r |
| 1092 | destoffset=decode_rm10_address(m,rl);\r |
| 1093 | destval = fetch_data_byte(m,destoffset);\r |
| 1094 | srcreg = DECODE_RM_BYTE_REGISTER(m,rh);\r |
| 1095 | destval = sub_byte(m, destval, *srcreg);\r |
| 1096 | store_data_byte(m,destoffset,destval);\r |
| 1097 | break;\r |
| 1098 | case 3: /* register to register */\r |
| 1099 | destreg = DECODE_RM_BYTE_REGISTER(m,rl);\r |
| 1100 | srcreg = DECODE_RM_BYTE_REGISTER(m,rh);\r |
| 1101 | *destreg = sub_byte(m, *destreg, *srcreg);\r |
| 1102 | break;\r |
| 1103 | }\r |
| 1104 | DECODE_CLEAR_SEGOVR(m);\r |
| 1105 | }\r |
| 1106 | \r |
| 1107 | /*opcode=0x29*/\r |
| 1108 | static void i86op_sub_word_RM_R(PC_ENV *m)\r |
| 1109 | {\r |
| 1110 | uint16 mod,rl,rh;\r |
| 1111 | uint16 *destreg,*srcreg;\r |
| 1112 | uint16 destoffset;\r |
| 1113 | uint16 destval;\r |
| 1114 | FETCH_DECODE_MODRM(m,mod,rh,rl);\r |
| 1115 | switch (mod)\r |
| 1116 | {\r |
| 1117 | case 0:\r |
| 1118 | destoffset=decode_rm00_address(m,rl);\r |
| 1119 | destval = fetch_data_word(m,destoffset);\r |
| 1120 | srcreg = DECODE_RM_WORD_REGISTER(m,rh);\r |
| 1121 | destval = sub_word(m, destval, *srcreg);\r |
| 1122 | store_data_word(m,destoffset,destval);\r |
| 1123 | break;\r |
| 1124 | case 1:\r |
| 1125 | destoffset=decode_rm01_address(m,rl);\r |
| 1126 | destval = fetch_data_word(m,destoffset);\r |
| 1127 | srcreg = DECODE_RM_WORD_REGISTER(m,rh);\r |
| 1128 | destval = sub_word(m, destval, *srcreg);\r |
| 1129 | store_data_word(m,destoffset,destval);\r |
| 1130 | break;\r |
| 1131 | case 2:\r |
| 1132 | destoffset=decode_rm10_address(m,rl);\r |
| 1133 | destval = fetch_data_word(m,destoffset);\r |
| 1134 | srcreg = DECODE_RM_WORD_REGISTER(m,rh);\r |
| 1135 | destval = sub_word(m, destval, *srcreg);\r |
| 1136 | store_data_word(m,destoffset,destval);\r |
| 1137 | break;\r |
| 1138 | case 3: /* register to register */\r |
| 1139 | destreg = DECODE_RM_WORD_REGISTER(m,rl);\r |
| 1140 | srcreg = DECODE_RM_WORD_REGISTER(m,rh);\r |
| 1141 | *destreg = sub_word(m, *destreg, *srcreg);\r |
| 1142 | break;\r |
| 1143 | }\r |
| 1144 | DECODE_CLEAR_SEGOVR(m);\r |
| 1145 | }\r |
| 1146 | \r |
| 1147 | /*opcode=0x2a*/\r |
| 1148 | static void i86op_sub_byte_R_RM(PC_ENV *m)\r |
| 1149 | {\r |
| 1150 | uint16 mod,rl,rh;\r |
| 1151 | uint8 *destreg,*srcreg;\r |
| 1152 | uint16 srcoffset;\r |
| 1153 | uint8 srcval;\r |
| 1154 | FETCH_DECODE_MODRM(m,mod,rh,rl);\r |
| 1155 | switch (mod)\r |
| 1156 | {\r |
| 1157 | case 0:\r |
| 1158 | destreg = DECODE_RM_BYTE_REGISTER(m,rh);\r |
| 1159 | srcoffset=decode_rm00_address(m,rl);\r |
| 1160 | srcval = fetch_data_byte(m,srcoffset);\r |
| 1161 | *destreg = sub_byte(m, *destreg, srcval);\r |
| 1162 | break;\r |
| 1163 | case 1:\r |
| 1164 | destreg = DECODE_RM_BYTE_REGISTER(m,rh);\r |
| 1165 | srcoffset=decode_rm01_address(m,rl);\r |
| 1166 | srcval = fetch_data_byte(m,srcoffset);\r |
| 1167 | *destreg = sub_byte(m, *destreg, srcval);\r |
| 1168 | break;\r |
| 1169 | case 2:\r |
| 1170 | destreg = DECODE_RM_BYTE_REGISTER(m,rh);\r |
| 1171 | srcoffset=decode_rm10_address(m,rl);\r |
| 1172 | srcval = fetch_data_byte(m,srcoffset);\r |
| 1173 | *destreg = sub_byte(m, * destreg, srcval);\r |
| 1174 | break;\r |
| 1175 | case 3: /* register to register */\r |
| 1176 | destreg = DECODE_RM_BYTE_REGISTER(m,rh);\r |
| 1177 | srcreg = DECODE_RM_BYTE_REGISTER(m,rl);\r |
| 1178 | *destreg = sub_byte(m, *destreg, *srcreg);\r |
| 1179 | break;\r |
| 1180 | }\r |
| 1181 | DECODE_CLEAR_SEGOVR(m);\r |
| 1182 | }\r |
| 1183 | \r |
| 1184 | /*opcode=0x2b*/\r |
| 1185 | static void i86op_sub_word_R_RM(PC_ENV *m)\r |
| 1186 | {\r |
| 1187 | uint16 mod,rl,rh;\r |
| 1188 | uint16 *destreg,*srcreg;\r |
| 1189 | uint16 srcoffset;\r |
| 1190 | uint16 srcval;\r |
| 1191 | FETCH_DECODE_MODRM(m,mod,rh,rl);\r |
| 1192 | switch (mod)\r |
| 1193 | {\r |
| 1194 | case 0:\r |
| 1195 | destreg = DECODE_RM_WORD_REGISTER(m,rh);\r |
| 1196 | srcoffset=decode_rm00_address(m,rl);\r |
| 1197 | srcval = fetch_data_word(m,srcoffset);\r |
| 1198 | *destreg = sub_word(m, *destreg, srcval);\r |
| 1199 | break;\r |
| 1200 | case 1:\r |
| 1201 | destreg = DECODE_RM_WORD_REGISTER(m,rh);\r |
| 1202 | srcoffset=decode_rm01_address(m,rl);\r |
| 1203 | srcval = fetch_data_word(m,srcoffset);\r |
| 1204 | *destreg = sub_word(m, *destreg, srcval);\r |
| 1205 | break;\r |
| 1206 | case 2:\r |
| 1207 | destreg = DECODE_RM_WORD_REGISTER(m,rh);\r |
| 1208 | srcoffset=decode_rm10_address(m,rl);\r |
| 1209 | srcval = fetch_data_word(m,srcoffset);\r |
| 1210 | *destreg = sub_word(m, *destreg, srcval);\r |
| 1211 | break;\r |
| 1212 | case 3: /* register to register */\r |
| 1213 | destreg = DECODE_RM_WORD_REGISTER(m,rh);\r |
| 1214 | srcreg = DECODE_RM_WORD_REGISTER(m,rl);\r |
| 1215 | *destreg = sub_word(m, *destreg, *srcreg);\r |
| 1216 | break;\r |
| 1217 | }\r |
| 1218 | DECODE_CLEAR_SEGOVR(m);\r |
| 1219 | }\r |
| 1220 | \r |
| 1221 | /*opcode=0x2c*/\r |
| 1222 | static void i86op_sub_byte_AL_IMM(PC_ENV *m)\r |
| 1223 | {\r |
| 1224 | uint8 srcval;\r |
| 1225 | srcval = fetch_byte_imm(m);\r |
| 1226 | m->R_AL = sub_byte(m, m->R_AL, srcval);\r |
| 1227 | DECODE_CLEAR_SEGOVR(m);\r |
| 1228 | }\r |
| 1229 | \r |
| 1230 | /*opcode=0x2d*/\r |
| 1231 | static void i86op_sub_word_AX_IMM(PC_ENV *m)\r |
| 1232 | {\r |
| 1233 | uint16 srcval;\r |
| 1234 | srcval = fetch_word_imm(m);\r |
| 1235 | m->R_AX = sub_word(m, m->R_AX, srcval);\r |
| 1236 | DECODE_CLEAR_SEGOVR(m);\r |
| 1237 | }\r |
| 1238 | \r |
| 1239 | /*opcode=0x2e*/\r |
| 1240 | static void i86op_segovr_CS(PC_ENV *m)\r |
| 1241 | {\r |
| 1242 | m->sysmode |= SYSMODE_SEGOVR_CS;\r |
| 1243 | /* note no DECODE_CLEAR_SEGOVER here. */\r |
| 1244 | }\r |
| 1245 | \r |
| 1246 | /*opcode=0x2f*/\r |
| 1247 | static void i86op_das(PC_ENV *m)\r |
| 1248 | {\r |
| 1249 | uint16 dbyte;\r |
| 1250 | dbyte = m->R_AL;\r |
| 1251 | if ( ACCESS_FLAG(m,F_AF) || (dbyte&0xf) > 9)\r |
| 1252 | {\r |
| 1253 | dbyte -= 6;\r |
| 1254 | if (dbyte&0x100) /* XXXXX --- this is WRONG */\r |
| 1255 | SET_FLAG(m, F_CF);\r |
| 1256 | SET_FLAG(m, F_AF);\r |
| 1257 | }\r |
| 1258 | else\r |
| 1259 | CLEAR_FLAG(m, F_AF);\r |
| 1260 | if (ACCESS_FLAG(m,F_CF) || (dbyte&0xf0) > 0x90)\r |
| 1261 | {\r |
| 1262 | dbyte -= 0x60;\r |
| 1263 | SET_FLAG(m, F_CF);\r |
| 1264 | }\r |
| 1265 | else\r |
| 1266 | CLEAR_FLAG(m, F_CF);\r |
| 1267 | m->R_AL = (uint8) dbyte;\r |
| 1268 | CONDITIONAL_SET_FLAG(m->R_AL & 0x80,m,F_SF);\r |
| 1269 | CONDITIONAL_SET_FLAG(m->R_AL == 0,m,F_ZF);\r |
| 1270 | CONDITIONAL_SET_FLAG(parity_tab[m->R_AL],m,F_PF);\r |
| 1271 | DECODE_CLEAR_SEGOVR(m);\r |
| 1272 | }\r |
| 1273 | \r |
| 1274 | /*opcode=0x30*/\r |
| 1275 | static void i86op_xor_byte_RM_R(PC_ENV *m)\r |
| 1276 | {\r |
| 1277 | uint16 mod,rl,rh;\r |
| 1278 | uint8 *destreg,*srcreg;\r |
| 1279 | uint16 destoffset;\r |
| 1280 | uint8 destval;\r |
| 1281 | FETCH_DECODE_MODRM(m,mod,rh,rl);\r |
| 1282 | switch (mod)\r |
| 1283 | {\r |
| 1284 | case 0:\r |
| 1285 | destoffset=decode_rm00_address(m,rl);\r |
| 1286 | destval = fetch_data_byte(m,destoffset);\r |
| 1287 | srcreg = DECODE_RM_BYTE_REGISTER(m,rh);\r |
| 1288 | destval = xor_byte(m, destval, *srcreg);\r |
| 1289 | store_data_byte(m,destoffset,destval);\r |
| 1290 | break;\r |
| 1291 | case 1:\r |
| 1292 | destoffset=decode_rm01_address(m,rl);\r |
| 1293 | destval = fetch_data_byte(m,destoffset);\r |
| 1294 | srcreg = DECODE_RM_BYTE_REGISTER(m,rh);\r |
| 1295 | destval = xor_byte(m, destval, *srcreg);\r |
| 1296 | store_data_byte(m,destoffset,destval);\r |
| 1297 | break;\r |
| 1298 | case 2:\r |
| 1299 | destoffset=decode_rm10_address(m,rl);\r |
| 1300 | destval = fetch_data_byte(m,destoffset);\r |
| 1301 | srcreg = DECODE_RM_BYTE_REGISTER(m,rh);\r |
| 1302 | destval = xor_byte(m, destval, *srcreg);\r |
| 1303 | store_data_byte(m,destoffset,destval);\r |
| 1304 | break;\r |
| 1305 | case 3: /* register to register */\r |
| 1306 | destreg = DECODE_RM_BYTE_REGISTER(m,rl);\r |
| 1307 | srcreg = DECODE_RM_BYTE_REGISTER(m,rh);\r |
| 1308 | *destreg = xor_byte(m, *destreg, *srcreg);\r |
| 1309 | break;\r |
| 1310 | }\r |
| 1311 | DECODE_CLEAR_SEGOVR(m);\r |
| 1312 | }\r |
| 1313 | \r |
| 1314 | /*opcode=0x31*/\r |
| 1315 | static void i86op_xor_word_RM_R(PC_ENV *m)\r |
| 1316 | {\r |
| 1317 | uint16 mod,rl,rh;\r |
| 1318 | uint16 *destreg,*srcreg;\r |
| 1319 | uint16 destoffset;\r |
| 1320 | uint16 destval;\r |
| 1321 | FETCH_DECODE_MODRM(m,mod,rh,rl);\r |
| 1322 | switch (mod)\r |
| 1323 | {\r |
| 1324 | case 0:\r |
| 1325 | destoffset=decode_rm00_address(m,rl);\r |
| 1326 | destval = fetch_data_word(m,destoffset);\r |
| 1327 | srcreg = DECODE_RM_WORD_REGISTER(m,rh);\r |
| 1328 | destval = xor_word(m, destval, *srcreg);\r |
| 1329 | store_data_word(m,destoffset,destval);\r |
| 1330 | break;\r |
| 1331 | case 1:\r |
| 1332 | destoffset=decode_rm01_address(m,rl);\r |
| 1333 | destval = fetch_data_word(m,destoffset);\r |
| 1334 | srcreg = DECODE_RM_WORD_REGISTER(m,rh);\r |
| 1335 | destval = xor_word(m, destval, *srcreg);\r |
| 1336 | store_data_word(m,destoffset,destval);\r |
| 1337 | break;\r |
| 1338 | case 2:\r |
| 1339 | destoffset=decode_rm10_address(m,rl);\r |
| 1340 | destval = fetch_data_word(m,destoffset);\r |
| 1341 | srcreg = DECODE_RM_WORD_REGISTER(m,rh);\r |
| 1342 | destval = xor_word(m, destval, *srcreg);\r |
| 1343 | store_data_word(m,destoffset,destval);\r |
| 1344 | break;\r |
| 1345 | case 3: /* register to register */\r |
| 1346 | destreg = DECODE_RM_WORD_REGISTER(m,rl);\r |
| 1347 | srcreg = DECODE_RM_WORD_REGISTER(m,rh);\r |
| 1348 | *destreg = xor_word(m, *destreg, *srcreg);\r |
| 1349 | break;\r |
| 1350 | }\r |
| 1351 | DECODE_CLEAR_SEGOVR(m);\r |
| 1352 | }\r |
| 1353 | \r |
| 1354 | /*opcode=0x32*/\r |
| 1355 | static void i86op_xor_byte_R_RM(PC_ENV *m)\r |
| 1356 | {\r |
| 1357 | uint16 mod,rl,rh;\r |
| 1358 | uint8 *destreg,*srcreg;\r |
| 1359 | uint16 srcoffset;\r |
| 1360 | uint8 srcval;\r |
| 1361 | FETCH_DECODE_MODRM(m,mod,rh,rl);\r |
| 1362 | switch (mod)\r |
| 1363 | {\r |
| 1364 | case 0:\r |
| 1365 | destreg = DECODE_RM_BYTE_REGISTER(m,rh);\r |
| 1366 | srcoffset=decode_rm00_address(m,rl);\r |
| 1367 | srcval = fetch_data_byte(m,srcoffset);\r |
| 1368 | *destreg = xor_byte(m, *destreg, srcval);\r |
| 1369 | break;\r |
| 1370 | case 1:\r |
| 1371 | destreg = DECODE_RM_BYTE_REGISTER(m,rh);\r |
| 1372 | srcoffset=decode_rm01_address(m,rl);\r |
| 1373 | srcval = fetch_data_byte(m,srcoffset);\r |
| 1374 | *destreg = xor_byte(m, *destreg, srcval);\r |
| 1375 | break;\r |
| 1376 | case 2:\r |
| 1377 | destreg = DECODE_RM_BYTE_REGISTER(m,rh);\r |
| 1378 | srcoffset=decode_rm10_address(m,rl);\r |
| 1379 | srcval = fetch_data_byte(m,srcoffset);\r |
| 1380 | *destreg = xor_byte(m, *destreg, srcval);\r |
| 1381 | break;\r |
| 1382 | case 3: /* register to register */\r |
| 1383 | destreg = DECODE_RM_BYTE_REGISTER(m,rh);\r |
| 1384 | srcreg = DECODE_RM_BYTE_REGISTER(m,rl);\r |
| 1385 | *destreg = xor_byte(m, *destreg, *srcreg);\r |
| 1386 | break;\r |
| 1387 | }\r |
| 1388 | DECODE_CLEAR_SEGOVR(m);\r |
| 1389 | }\r |
| 1390 | \r |
| 1391 | /*opcode=0x33*/\r |
| 1392 | static void i86op_xor_word_R_RM(PC_ENV *m)\r |
| 1393 | {\r |
| 1394 | uint16 mod,rl,rh;\r |
| 1395 | uint16 *destreg,*srcreg;\r |
| 1396 | uint16 srcoffset;\r |
| 1397 | uint16 srcval;\r |
| 1398 | FETCH_DECODE_MODRM(m,mod,rh,rl);\r |
| 1399 | switch (mod)\r |
| 1400 | {\r |
| 1401 | case 0:\r |
| 1402 | destreg = DECODE_RM_WORD_REGISTER(m,rh);\r |
| 1403 | srcoffset=decode_rm00_address(m,rl);\r |
| 1404 | srcval = fetch_data_word(m,srcoffset);\r |
| 1405 | *destreg = xor_word(m, *destreg, srcval);\r |
| 1406 | break;\r |
| 1407 | case 1:\r |
| 1408 | destreg = DECODE_RM_WORD_REGISTER(m,rh);\r |
| 1409 | srcoffset=decode_rm01_address(m,rl);\r |
| 1410 | srcval = fetch_data_word(m,srcoffset);\r |
| 1411 | *destreg = xor_word(m, *destreg, srcval);\r |
| 1412 | break;\r |
| 1413 | case 2:\r |
| 1414 | destreg = DECODE_RM_WORD_REGISTER(m,rh);\r |
| 1415 | srcoffset=decode_rm10_address(m,rl);\r |
| 1416 | srcval = fetch_data_word(m,srcoffset);\r |
| 1417 | *destreg = xor_word(m, *destreg, srcval);\r |
| 1418 | break;\r |
| 1419 | case 3: /* register to register */\r |
| 1420 | destreg = DECODE_RM_WORD_REGISTER(m,rh);\r |
| 1421 | srcreg = DECODE_RM_WORD_REGISTER(m,rl);\r |
| 1422 | *destreg = xor_word(m, *destreg, *srcreg);\r |
| 1423 | break;\r |
| 1424 | }\r |
| 1425 | DECODE_CLEAR_SEGOVR(m);\r |
| 1426 | }\r |
| 1427 | \r |
| 1428 | /*opcode=0x34*/\r |
| 1429 | static void i86op_xor_byte_AL_IMM(PC_ENV *m)\r |
| 1430 | {\r |
| 1431 | uint8 srcval;\r |
| 1432 | srcval = fetch_byte_imm(m);\r |
| 1433 | m->R_AL = xor_byte(m, m->R_AL, srcval);\r |
| 1434 | DECODE_CLEAR_SEGOVR(m);\r |
| 1435 | }\r |
| 1436 | \r |
| 1437 | /*opcode=0x35*/\r |
| 1438 | static void i86op_xor_word_AX_IMM(PC_ENV *m)\r |
| 1439 | {\r |
| 1440 | uint16 srcval;\r |
| 1441 | srcval = fetch_word_imm(m);\r |
| 1442 | m->R_AX = xor_word(m, m->R_AX, srcval);\r |
| 1443 | DECODE_CLEAR_SEGOVR(m);\r |
| 1444 | }\r |
| 1445 | \r |
| 1446 | /*opcode=0x36*/\r |
| 1447 | static void i86op_segovr_SS(PC_ENV *m)\r |
| 1448 | {\r |
| 1449 | m->sysmode |= SYSMODE_SEGOVR_SS;\r |
| 1450 | /* no DECODE_CLEAR_SEGOVER ! */\r |
| 1451 | }\r |
| 1452 | \r |
| 1453 | /*opcode=0x37*/\r |
| 1454 | static void i86op_aaa(PC_ENV *m)\r |
| 1455 | {\r |
| 1456 | if ( (m->R_AL & 0xf) > 0x9 || ACCESS_FLAG(m,F_AF))\r |
| 1457 | {\r |
| 1458 | m->R_AL += 0x6;\r |
| 1459 | m->R_AH += 1;\r |
| 1460 | SET_FLAG(m, F_AF);\r |
| 1461 | SET_FLAG(m, F_CF);\r |
| 1462 | }\r |
| 1463 | else\r |
| 1464 | {\r |
| 1465 | CLEAR_FLAG(m, F_CF);\r |
| 1466 | CLEAR_FLAG(m, F_AF);\r |
| 1467 | }\r |
| 1468 | m->R_AL &= 0xf;\r |
| 1469 | DECODE_CLEAR_SEGOVR(m);\r |
| 1470 | }\r |
| 1471 | \r |
| 1472 | /*opcode=0x38*/\r |
| 1473 | static void i86op_cmp_byte_RM_R(PC_ENV *m)\r |
| 1474 | {\r |
| 1475 | uint16 mod,rl,rh;\r |
| 1476 | uint8 *destreg,*srcreg;\r |
| 1477 | uint16 destoffset;\r |
| 1478 | uint8 destval;\r |
| 1479 | FETCH_DECODE_MODRM(m,mod,rh,rl);\r |
| 1480 | switch (mod)\r |
| 1481 | {\r |
| 1482 | case 0:\r |
| 1483 | destoffset=decode_rm00_address(m,rl);\r |
| 1484 | destval = fetch_data_byte(m,destoffset);\r |
| 1485 | srcreg = DECODE_RM_BYTE_REGISTER(m,rh);\r |
| 1486 | cmp_byte(m, destval, *srcreg);\r |
| 1487 | break;\r |
| 1488 | case 1:\r |
| 1489 | destoffset=decode_rm01_address(m,rl);\r |
| 1490 | destval = fetch_data_byte(m,destoffset);\r |
| 1491 | srcreg = DECODE_RM_BYTE_REGISTER(m,rh);\r |
| 1492 | cmp_byte(m, destval, *srcreg);\r |
| 1493 | break;\r |
| 1494 | case 2:\r |
| 1495 | destoffset=decode_rm10_address(m,rl);\r |
| 1496 | destval = fetch_data_byte(m,destoffset);\r |
| 1497 | srcreg = DECODE_RM_BYTE_REGISTER(m,rh);\r |
| 1498 | cmp_byte(m, destval, *srcreg);\r |
| 1499 | break;\r |
| 1500 | case 3: /* register to register */\r |
| 1501 | destreg = DECODE_RM_BYTE_REGISTER(m,rl);\r |
| 1502 | srcreg = DECODE_RM_BYTE_REGISTER(m,rh);\r |
| 1503 | cmp_byte(m, *destreg, *srcreg);\r |
| 1504 | break;\r |
| 1505 | }\r |
| 1506 | DECODE_CLEAR_SEGOVR(m);\r |
| 1507 | }\r |
| 1508 | \r |
| 1509 | /*opcode=0x39*/\r |
| 1510 | static void i86op_cmp_word_RM_R(PC_ENV *m)\r |
| 1511 | {\r |
| 1512 | uint16 mod,rl,rh;\r |
| 1513 | uint16 *destreg,*srcreg;\r |
| 1514 | uint16 destoffset;\r |
| 1515 | uint16 destval;\r |
| 1516 | FETCH_DECODE_MODRM(m,mod,rh,rl);\r |
| 1517 | switch (mod)\r |
| 1518 | {\r |
| 1519 | case 0:\r |
| 1520 | destoffset=decode_rm00_address(m,rl);\r |
| 1521 | destval = fetch_data_word(m,destoffset);\r |
| 1522 | srcreg = DECODE_RM_WORD_REGISTER(m,rh);\r |
| 1523 | cmp_word(m, destval, *srcreg);\r |
| 1524 | break;\r |
| 1525 | case 1:\r |
| 1526 | destoffset=decode_rm01_address(m,rl);\r |
| 1527 | destval = fetch_data_word(m,destoffset);\r |
| 1528 | srcreg = DECODE_RM_WORD_REGISTER(m,rh);\r |
| 1529 | cmp_word(m, destval, *srcreg);\r |
| 1530 | break;\r |
| 1531 | case 2:\r |
| 1532 | destoffset=decode_rm10_address(m,rl);\r |
| 1533 | destval = fetch_data_word(m,destoffset);\r |
| 1534 | srcreg = DECODE_RM_WORD_REGISTER(m,rh);\r |
| 1535 | cmp_word(m, destval, *srcreg);\r |
| 1536 | break;\r |
| 1537 | case 3: /* register to register */\r |
| 1538 | destreg = DECODE_RM_WORD_REGISTER(m,rl);\r |
| 1539 | srcreg = DECODE_RM_WORD_REGISTER(m,rh);\r |
| 1540 | cmp_word(m, *destreg, *srcreg);\r |
| 1541 | break;\r |
| 1542 | }\r |
| 1543 | DECODE_CLEAR_SEGOVR(m);\r |
| 1544 | }\r |
| 1545 | \r |
| 1546 | /*opcode=0x3a*/\r |
| 1547 | static void i86op_cmp_byte_R_RM(PC_ENV *m)\r |
| 1548 | {\r |
| 1549 | uint16 mod,rl,rh;\r |
| 1550 | uint8 *destreg,*srcreg;\r |
| 1551 | uint16 srcoffset;\r |
| 1552 | uint8 srcval;\r |
| 1553 | FETCH_DECODE_MODRM(m,mod,rh,rl);\r |
| 1554 | switch (mod)\r |
| 1555 | {\r |
| 1556 | case 0:\r |
| 1557 | destreg = DECODE_RM_BYTE_REGISTER(m,rh);\r |
| 1558 | srcoffset=decode_rm00_address(m,rl);\r |
| 1559 | srcval = fetch_data_byte(m,srcoffset);\r |
| 1560 | cmp_byte(m, *destreg, srcval);\r |
| 1561 | break;\r |
| 1562 | case 1:\r |
| 1563 | destreg = DECODE_RM_BYTE_REGISTER(m,rh);\r |
| 1564 | srcoffset=decode_rm01_address(m,rl);\r |
| 1565 | srcval = fetch_data_byte(m,srcoffset);\r |
| 1566 | cmp_byte(m, *destreg, srcval);\r |
| 1567 | break;\r |
| 1568 | case 2:\r |
| 1569 | destreg = DECODE_RM_BYTE_REGISTER(m,rh);\r |
| 1570 | srcoffset=decode_rm10_address(m,rl);\r |
| 1571 | srcval = fetch_data_byte(m,srcoffset);\r |
| 1572 | cmp_byte(m, * destreg, srcval);\r |
| 1573 | break;\r |
| 1574 | case 3: /* register to register */\r |
| 1575 | destreg = DECODE_RM_BYTE_REGISTER(m,rh);\r |
| 1576 | srcreg = DECODE_RM_BYTE_REGISTER(m,rl);\r |
| 1577 | cmp_byte(m, *destreg, *srcreg);\r |
| 1578 | break;\r |
| 1579 | }\r |
| 1580 | DECODE_CLEAR_SEGOVR(m);\r |
| 1581 | }\r |
| 1582 | \r |
| 1583 | /*opcode=0x3b*/\r |
| 1584 | static void i86op_cmp_word_R_RM(PC_ENV *m)\r |
| 1585 | {\r |
| 1586 | uint16 mod,rl,rh;\r |
| 1587 | uint16 *destreg,*srcreg;\r |
| 1588 | uint16 srcoffset;\r |
| 1589 | uint16 srcval;\r |
| 1590 | FETCH_DECODE_MODRM(m,mod,rh,rl);\r |
| 1591 | switch (mod)\r |
| 1592 | {\r |
| 1593 | case 0:\r |
| 1594 | destreg = DECODE_RM_WORD_REGISTER(m,rh);\r |
| 1595 | srcoffset=decode_rm00_address(m,rl);\r |
| 1596 | srcval = fetch_data_word(m,srcoffset);\r |
| 1597 | cmp_word(m, *destreg, srcval);\r |
| 1598 | break;\r |
| 1599 | case 1:\r |
| 1600 | destreg = DECODE_RM_WORD_REGISTER(m,rh);\r |
| 1601 | srcoffset=decode_rm01_address(m,rl);\r |
| 1602 | srcval = fetch_data_word(m,srcoffset);\r |
| 1603 | cmp_word(m, *destreg, srcval);\r |
| 1604 | break;\r |
| 1605 | case 2:\r |
| 1606 | destreg = DECODE_RM_WORD_REGISTER(m,rh);\r |
| 1607 | srcoffset=decode_rm10_address(m,rl);\r |
| 1608 | srcval = fetch_data_word(m,srcoffset);\r |
| 1609 | cmp_word(m, *destreg, srcval);\r |
| 1610 | break;\r |
| 1611 | case 3: /* register to register */\r |
| 1612 | destreg = DECODE_RM_WORD_REGISTER(m,rh);\r |
| 1613 | srcreg = DECODE_RM_WORD_REGISTER(m,rl);\r |
| 1614 | cmp_word(m, *destreg, *srcreg);\r |
| 1615 | break;\r |
| 1616 | }\r |
| 1617 | DECODE_CLEAR_SEGOVR(m);\r |
| 1618 | }\r |
| 1619 | \r |
| 1620 | /*opcode=0x3c*/\r |
| 1621 | static void i86op_cmp_byte_AL_IMM(PC_ENV *m)\r |
| 1622 | {\r |
| 1623 | uint8 srcval;\r |
| 1624 | srcval = fetch_byte_imm(m);\r |
| 1625 | cmp_byte(m, m->R_AL, srcval);\r |
| 1626 | DECODE_CLEAR_SEGOVR(m);\r |
| 1627 | }\r |
| 1628 | \r |
| 1629 | /*opcode=0x3d*/\r |
| 1630 | static void i86op_cmp_word_AX_IMM(PC_ENV *m)\r |
| 1631 | {\r |
| 1632 | uint16 srcval;\r |
| 1633 | srcval = fetch_word_imm(m);\r |
| 1634 | cmp_word(m, m->R_AX, srcval);\r |
| 1635 | DECODE_CLEAR_SEGOVR(m);\r |
| 1636 | }\r |
| 1637 | \r |
| 1638 | /*opcode=0x3e*/\r |
| 1639 | static void i86op_segovr_DS(PC_ENV *m)\r |
| 1640 | {\r |
| 1641 | m->sysmode |= SYSMODE_SEGOVR_DS;\r |
| 1642 | /* NO DECODE_CLEAR_SEGOVR! */\r |
| 1643 | }\r |
| 1644 | \r |
| 1645 | /*opcode=0x3f*/\r |
| 1646 | static void i86op_aas(PC_ENV *m)\r |
| 1647 | {\r |
| 1648 | /* ???? Check out the subtraction here. Will this ?ever? cause\r |
| 1649 | the contents of R_AL or R_AH to be affected incorrectly since\r |
| 1650 | they are being subtracted from *and* are unsigned.\r |
| 1651 | Should put an assertion in here.\r |
| 1652 | */\r |
| 1653 | if ( (m->R_AL & 0xf) > 0x9 || ACCESS_FLAG(m,F_AF))\r |
| 1654 | {\r |
| 1655 | m->R_AL -= 0x6;\r |
| 1656 | m->R_AH -= 1;\r |
| 1657 | SET_FLAG(m, F_AF);\r |
| 1658 | SET_FLAG(m, F_CF);\r |
| 1659 | }\r |
| 1660 | else\r |
| 1661 | {\r |
| 1662 | CLEAR_FLAG(m, F_CF);\r |
| 1663 | CLEAR_FLAG(m, F_AF);\r |
| 1664 | }\r |
| 1665 | m->R_AL &= 0xf;\r |
| 1666 | DECODE_CLEAR_SEGOVR(m);\r |
| 1667 | }\r |
| 1668 | \r |
| 1669 | /*opcode=0x40*/\r |
| 1670 | static void i86op_inc_AX(PC_ENV *m)\r |
| 1671 | {\r |
| 1672 | m->R_AX = inc_word(m,m->R_AX);\r |
| 1673 | DECODE_CLEAR_SEGOVR(m);\r |
| 1674 | }\r |
| 1675 | \r |
| 1676 | /*opcode=0x41*/\r |
| 1677 | static void i86op_inc_CX(PC_ENV *m)\r |
| 1678 | {\r |
| 1679 | m->R_CX = inc_word(m,m->R_CX);\r |
| 1680 | DECODE_CLEAR_SEGOVR(m);\r |
| 1681 | }\r |
| 1682 | \r |
| 1683 | /*opcode=0x42*/\r |
| 1684 | static void i86op_inc_DX(PC_ENV *m)\r |
| 1685 | {\r |
| 1686 | m->R_DX = inc_word(m,m->R_DX);\r |
| 1687 | DECODE_CLEAR_SEGOVR(m);\r |
| 1688 | }\r |
| 1689 | \r |
| 1690 | /*opcode=0x43*/\r |
| 1691 | static void i86op_inc_BX(PC_ENV *m)\r |
| 1692 | {\r |
| 1693 | m->R_BX = inc_word(m,m->R_BX);\r |
| 1694 | DECODE_CLEAR_SEGOVR(m);\r |
| 1695 | }\r |
| 1696 | \r |
| 1697 | /*opcode=0x44*/\r |
| 1698 | static void i86op_inc_SP(PC_ENV *m)\r |
| 1699 | {\r |
| 1700 | m->R_SP = inc_word(m,m->R_SP);\r |
| 1701 | DECODE_CLEAR_SEGOVR(m);\r |
| 1702 | }\r |
| 1703 | \r |
| 1704 | /*opcode=0x45*/\r |
| 1705 | static void i86op_inc_BP(PC_ENV *m)\r |
| 1706 | {\r |
| 1707 | m->R_BP = inc_word(m,m->R_BP);\r |
| 1708 | DECODE_CLEAR_SEGOVR(m);\r |
| 1709 | }\r |
| 1710 | \r |
| 1711 | /*opcode=0x46*/\r |
| 1712 | static void i86op_inc_SI(PC_ENV *m)\r |
| 1713 | {\r |
| 1714 | m->R_SI = inc_word(m,m->R_SI);\r |
| 1715 | DECODE_CLEAR_SEGOVR(m);\r |
| 1716 | }\r |
| 1717 | \r |
| 1718 | /*opcode=0x47*/\r |
| 1719 | static void i86op_inc_DI(PC_ENV *m)\r |
| 1720 | {\r |
| 1721 | m->R_DI = inc_word(m,m->R_DI);\r |
| 1722 | DECODE_CLEAR_SEGOVR(m);\r |
| 1723 | }\r |
| 1724 | \r |
| 1725 | /*opcode=0x48*/\r |
| 1726 | static void i86op_dec_AX(PC_ENV *m)\r |
| 1727 | {\r |
| 1728 | m->R_AX = dec_word(m,m->R_AX);\r |
| 1729 | DECODE_CLEAR_SEGOVR(m);\r |
| 1730 | }\r |
| 1731 | \r |
| 1732 | /*opcode=0x49*/\r |
| 1733 | static void i86op_dec_CX(PC_ENV *m)\r |
| 1734 | {\r |
| 1735 | m->R_CX = dec_word(m,m->R_CX);\r |
| 1736 | DECODE_CLEAR_SEGOVR(m);\r |
| 1737 | }\r |
| 1738 | \r |
| 1739 | /*opcode=0x4a*/\r |
| 1740 | static void i86op_dec_DX(PC_ENV *m)\r |
| 1741 | {\r |
| 1742 | m->R_DX = dec_word(m,m->R_DX);\r |
| 1743 | DECODE_CLEAR_SEGOVR(m);\r |
| 1744 | }\r |
| 1745 | \r |
| 1746 | /*opcode=0x4b*/\r |
| 1747 | static void i86op_dec_BX(PC_ENV *m)\r |
| 1748 | {\r |
| 1749 | m->R_BX = dec_word(m,m->R_BX);\r |
| 1750 | DECODE_CLEAR_SEGOVR(m);\r |
| 1751 | }\r |
| 1752 | \r |
| 1753 | /*opcode=0x4c*/\r |
| 1754 | static void i86op_dec_SP(PC_ENV *m)\r |
| 1755 | {\r |
| 1756 | m->R_SP = dec_word(m,m->R_SP);\r |
| 1757 | DECODE_CLEAR_SEGOVR(m);\r |
| 1758 | }\r |
| 1759 | \r |
| 1760 | /*opcode=0x4d*/\r |
| 1761 | static void i86op_dec_BP(PC_ENV *m)\r |
| 1762 | {\r |
| 1763 | m->R_BP = dec_word(m,m->R_BP);\r |
| 1764 | DECODE_CLEAR_SEGOVR(m);\r |
| 1765 | }\r |
| 1766 | \r |
| 1767 | /*opcode=0x4e*/\r |
| 1768 | static void i86op_dec_SI(PC_ENV *m)\r |
| 1769 | {\r |
| 1770 | m->R_SI = dec_word(m,m->R_SI);\r |
| 1771 | DECODE_CLEAR_SEGOVR(m);\r |
| 1772 | }\r |
| 1773 | \r |
| 1774 | /*opcode=0x4f*/\r |
| 1775 | static void i86op_dec_DI(PC_ENV *m)\r |
| 1776 | {\r |
| 1777 | m->R_DI = dec_word(m,m->R_DI);\r |
| 1778 | DECODE_CLEAR_SEGOVR(m);\r |
| 1779 | }\r |
| 1780 | \r |
| 1781 | /*opcode=0x50*/\r |
| 1782 | static void i86op_push_AX(PC_ENV *m)\r |
| 1783 | {\r |
| 1784 | push_word(m,m->R_AX);\r |
| 1785 | DECODE_CLEAR_SEGOVR(m);\r |
| 1786 | }\r |
| 1787 | \r |
| 1788 | /*opcode=0x51*/\r |
| 1789 | static void i86op_push_CX(PC_ENV *m)\r |
| 1790 | {\r |
| 1791 | push_word(m,m->R_CX);\r |
| 1792 | DECODE_CLEAR_SEGOVR(m);\r |
| 1793 | }\r |
| 1794 | \r |
| 1795 | /*opcode=0x52*/\r |
| 1796 | static void i86op_push_DX(PC_ENV *m)\r |
| 1797 | {\r |
| 1798 | push_word(m,m->R_DX);\r |
| 1799 | DECODE_CLEAR_SEGOVR(m);\r |
| 1800 | }\r |
| 1801 | \r |
| 1802 | /*opcode=0x53*/\r |
| 1803 | static void i86op_push_BX(PC_ENV *m)\r |
| 1804 | {\r |
| 1805 | push_word(m,m->R_BX);\r |
| 1806 | DECODE_CLEAR_SEGOVR(m);\r |
| 1807 | }\r |
| 1808 | \r |
| 1809 | /*opcode=0x54*/\r |
| 1810 | static void i86op_push_SP(PC_ENV *m)\r |
| 1811 | {\r |
| 1812 | /* .... Note this weirdness: One book I have access to\r |
| 1813 | claims that the value pushed here is actually sp-2. I.e.\r |
| 1814 | it decrements the stackpointer, and then pushes it. The 286\r |
| 1815 | I have does it this way. Changing this causes many problems.*/\r |
| 1816 | /* changed to push SP-2, since this *IS* how a 8088 does this */\r |
| 1817 | push_word(m,m->R_SP-2);\r |
| 1818 | DECODE_CLEAR_SEGOVR(m);\r |
| 1819 | }\r |
| 1820 | \r |
| 1821 | /*opcode=0x55*/\r |
| 1822 | static void i86op_push_BP(PC_ENV *m)\r |
| 1823 | {\r |
| 1824 | push_word(m,m->R_BP);\r |
| 1825 | DECODE_CLEAR_SEGOVR(m);\r |
| 1826 | }\r |
| 1827 | \r |
| 1828 | /*opcode=0x56*/\r |
| 1829 | static void i86op_push_SI(PC_ENV *m)\r |
| 1830 | {\r |
| 1831 | push_word(m,m->R_SI);\r |
| 1832 | DECODE_CLEAR_SEGOVR(m);\r |
| 1833 | }\r |
| 1834 | \r |
| 1835 | /*opcode=0x57*/\r |
| 1836 | static void i86op_push_DI(PC_ENV *m)\r |
| 1837 | {\r |
| 1838 | push_word(m,m->R_DI);\r |
| 1839 | DECODE_CLEAR_SEGOVR(m);\r |
| 1840 | }\r |
| 1841 | \r |
| 1842 | /*opcode=0x58*/\r |
| 1843 | static void i86op_pop_AX(PC_ENV *m)\r |
| 1844 | {\r |
| 1845 | m->R_AX = pop_word(m);\r |
| 1846 | DECODE_CLEAR_SEGOVR(m);\r |
| 1847 | }\r |
| 1848 | \r |
| 1849 | /*opcode=0x59*/\r |
| 1850 | static void i86op_pop_CX(PC_ENV *m)\r |
| 1851 | {\r |
| 1852 | m->R_CX = pop_word(m);\r |
| 1853 | DECODE_CLEAR_SEGOVR(m);\r |
| 1854 | }\r |
| 1855 | \r |
| 1856 | /*opcode=0x5a*/\r |
| 1857 | static void i86op_pop_DX(PC_ENV *m)\r |
| 1858 | {\r |
| 1859 | m->R_DX = pop_word(m);\r |
| 1860 | DECODE_CLEAR_SEGOVR(m);\r |
| 1861 | }\r |
| 1862 | \r |
| 1863 | /*opcode=0x5b*/\r |
| 1864 | static void i86op_pop_BX(PC_ENV *m)\r |
| 1865 | {\r |
| 1866 | m->R_BX = pop_word(m);\r |
| 1867 | DECODE_CLEAR_SEGOVR(m);\r |
| 1868 | }\r |
| 1869 | \r |
| 1870 | /*opcode=0x5c*/\r |
| 1871 | static void i86op_pop_SP(PC_ENV *m)\r |
| 1872 | {\r |
| 1873 | m->R_SP = pop_word(m);\r |
| 1874 | DECODE_CLEAR_SEGOVR(m);\r |
| 1875 | }\r |
| 1876 | \r |
| 1877 | /*opcode=0x5d*/\r |
| 1878 | static void i86op_pop_BP(PC_ENV *m)\r |
| 1879 | {\r |
| 1880 | m->R_BP = pop_word(m);\r |
| 1881 | DECODE_CLEAR_SEGOVR(m);\r |
| 1882 | }\r |
| 1883 | \r |
| 1884 | /*opcode=0x5e*/\r |
| 1885 | static void i86op_pop_SI(PC_ENV *m)\r |
| 1886 | {\r |
| 1887 | m->R_SI = pop_word(m);\r |
| 1888 | DECODE_CLEAR_SEGOVR(m);\r |
| 1889 | }\r |
| 1890 | \r |
| 1891 | /*opcode=0x5f*/\r |
| 1892 | static void i86op_pop_DI(PC_ENV *m)\r |
| 1893 | {\r |
| 1894 | m->R_DI = pop_word(m);\r |
| 1895 | DECODE_CLEAR_SEGOVR(m);\r |
| 1896 | }\r |
| 1897 | \r |
| 1898 | /*opcode=0x60 ILLEGAL OP, calls i86op_illegal_op() */\r |
| 1899 | /*opcode=0x61 ILLEGAL OP, calls i86op_illegal_op() */\r |
| 1900 | /*opcode=0x62 ILLEGAL OP, calls i86op_illegal_op() */\r |
| 1901 | /*opcode=0x63 ILLEGAL OP, calls i86op_illegal_op() */\r |
| 1902 | /*opcode=0x64 ILLEGAL OP, calls i86op_illegal_op() */\r |
| 1903 | /*opcode=0x65 ILLEGAL OP, calls i86op_illegal_op() */\r |
| 1904 | /*opcode=0x66 ILLEGAL OP, calls i86op_illegal_op() */\r |
| 1905 | /*opcode=0x67 ILLEGAL OP, calls i86op_illegal_op() */\r |
| 1906 | /*opcode=0x68 ILLEGAL OP, calls i86op_illegal_op() */\r |
| 1907 | /*opcode=0x69 ILLEGAL OP, calls i86op_illegal_op() */\r |
| 1908 | /*opcode=0x6a ILLEGAL OP, calls i86op_illegal_op() */\r |
| 1909 | /*opcode=0x6b ILLEGAL OP, calls i86op_illegal_op() */\r |
| 1910 | /*opcode=0x6c ILLEGAL OP, calls i86op_illegal_op() */\r |
| 1911 | /*opcode=0x6d ILLEGAL OP, calls i86op_illegal_op() */\r |
| 1912 | /*opcode=0x6e ILLEGAL OP, calls i86op_illegal_op() */\r |
| 1913 | /*opcode=0x6f ILLEGAL OP, calls i86op_illegal_op() */\r |
| 1914 | \r |
| 1915 | /*opcode=0x70*/\r |
| 1916 | static void i86op_jump_near_O(PC_ENV *m)\r |
| 1917 | {\r |
| 1918 | int8 offset;\r |
| 1919 | uint16 target;\r |
| 1920 | /* jump to byte offset if overflow flag is set */\r |
| 1921 | offset = (int8) fetch_byte_imm(m);\r |
| 1922 | target = (int16)(m->R_IP) + offset;\r |
| 1923 | if (ACCESS_FLAG(m,F_OF))\r |
| 1924 | m->R_IP = target;\r |
| 1925 | DECODE_CLEAR_SEGOVR(m);\r |
| 1926 | }\r |
| 1927 | \r |
| 1928 | /*opcode=0x71*/\r |
| 1929 | static void i86op_jump_near_NO(PC_ENV *m)\r |
| 1930 | {\r |
| 1931 | int8 offset;\r |
| 1932 | uint16 target;\r |
| 1933 | /* jump to byte offset if overflow is not set */\r |
| 1934 | offset = (int8) fetch_byte_imm(m);\r |
| 1935 | target = (int16)(m->R_IP) + offset;\r |
| 1936 | if (!ACCESS_FLAG(m,F_OF))\r |
| 1937 | m->R_IP = target;\r |
| 1938 | DECODE_CLEAR_SEGOVR(m);\r |
| 1939 | }\r |
| 1940 | \r |
| 1941 | /*opcode=0x72*/\r |
| 1942 | static void i86op_jump_near_B(PC_ENV *m)\r |
| 1943 | {\r |
| 1944 | int8 offset;\r |
| 1945 | uint16 target;\r |
| 1946 | /* jump to byte offset if carry flag is set. */\r |
| 1947 | offset = (int8)fetch_byte_imm(m); /* sign extended ??? */\r |
| 1948 | target = (int16)(m->R_IP) + offset;\r |
| 1949 | if (ACCESS_FLAG(m, F_CF))\r |
| 1950 | m->R_IP = target;\r |
| 1951 | DECODE_CLEAR_SEGOVR(m);\r |
| 1952 | }\r |
| 1953 | \r |
| 1954 | /*opcode=0x73*/\r |
| 1955 | static void i86op_jump_near_NB(PC_ENV *m)\r |
| 1956 | {\r |
| 1957 | int8 offset;\r |
| 1958 | uint16 target;\r |
| 1959 | /* jump to byte offset if carry flag is clear. */\r |
| 1960 | offset = (int8)fetch_byte_imm(m); /* sign extended ??? */\r |
| 1961 | target = (int16)(m->R_IP) + offset;\r |
| 1962 | if (!ACCESS_FLAG(m,F_CF))\r |
| 1963 | m->R_IP = target;\r |
| 1964 | DECODE_CLEAR_SEGOVR(m);\r |
| 1965 | }\r |
| 1966 | \r |
| 1967 | /*opcode=0x74*/\r |
| 1968 | static void i86op_jump_near_Z(PC_ENV *m)\r |
| 1969 | {\r |
| 1970 | int8 offset;\r |
| 1971 | uint16 target;\r |
| 1972 | /* jump to byte offset if zero flag is set. */\r |
| 1973 | offset = (int8)fetch_byte_imm(m);\r |
| 1974 | target = (int16)(m->R_IP) + offset;\r |
| 1975 | if (ACCESS_FLAG(m, F_ZF))\r |
| 1976 | m->R_IP = target;\r |
| 1977 | DECODE_CLEAR_SEGOVR(m);\r |
| 1978 | }\r |
| 1979 | \r |
| 1980 | /*opcode=0x75*/\r |
| 1981 | static void i86op_jump_near_NZ(PC_ENV *m)\r |
| 1982 | {\r |
| 1983 | int8 offset;\r |
| 1984 | uint16 target;\r |
| 1985 | /* jump to byte offset if zero flag is clear. */\r |
| 1986 | offset = (int8)fetch_byte_imm(m);\r |
| 1987 | target = (int16)(m->R_IP) + offset;\r |
| 1988 | if (!ACCESS_FLAG(m, F_ZF))\r |
| 1989 | m->R_IP = target;\r |
| 1990 | DECODE_CLEAR_SEGOVR(m);\r |
| 1991 | }\r |
| 1992 | \r |
| 1993 | /*opcode=0x76*/\r |
| 1994 | static void i86op_jump_near_BE(PC_ENV *m)\r |
| 1995 | {\r |
| 1996 | int8 offset;\r |
| 1997 | uint16 target;\r |
| 1998 | /* jump to byte offset if carry flag is set or if the zero\r |
| 1999 | flag is set. */\r |
| 2000 | offset = (int8)fetch_byte_imm(m);\r |
| 2001 | target = (int16)(m->R_IP) + offset;\r |
| 2002 | if (ACCESS_FLAG(m,F_CF) || ACCESS_FLAG(m,F_ZF))\r |
| 2003 | m->R_IP = target;\r |
| 2004 | DECODE_CLEAR_SEGOVR(m);\r |
| 2005 | }\r |
| 2006 | \r |
| 2007 | /*opcode=0x77*/\r |
| 2008 | static void i86op_jump_near_NBE(PC_ENV *m)\r |
| 2009 | {\r |
| 2010 | int8 offset;\r |
| 2011 | uint16 target;\r |
| 2012 | /* jump to byte offset if carry flag is clear and if the zero\r |
| 2013 | flag is clear */\r |
| 2014 | offset = (int8)fetch_byte_imm(m);\r |
| 2015 | target = (int16)(m->R_IP) + offset;\r |
| 2016 | if (!(ACCESS_FLAG(m,F_CF)||ACCESS_FLAG(m,F_ZF)))\r |
| 2017 | m->R_IP = target;\r |
| 2018 | DECODE_CLEAR_SEGOVR(m);\r |
| 2019 | }\r |
| 2020 | \r |
| 2021 | /*opcode=0x78*/\r |
| 2022 | static void i86op_jump_near_S(PC_ENV *m)\r |
| 2023 | {\r |
| 2024 | int8 offset;\r |
| 2025 | uint16 target;\r |
| 2026 | /* jump to byte offset if sign flag is set */\r |
| 2027 | offset = (int8)fetch_byte_imm(m);\r |
| 2028 | target = (int16)(m->R_IP) + offset;\r |
| 2029 | if (ACCESS_FLAG(m,F_SF))\r |
| 2030 | m->R_IP = target;\r |
| 2031 | DECODE_CLEAR_SEGOVR(m);\r |
| 2032 | }\r |
| 2033 | \r |
| 2034 | /*opcode=0x79*/\r |
| 2035 | static void i86op_jump_near_NS(PC_ENV *m)\r |
| 2036 | {\r |
| 2037 | int8 offset;\r |
| 2038 | uint16 target;\r |
| 2039 | /* jump to byte offset if sign flag is clear */\r |
| 2040 | offset = (int8)fetch_byte_imm(m);\r |
| 2041 | target = (int16)(m->R_IP) + offset;\r |
| 2042 | if (!ACCESS_FLAG(m,F_SF))\r |
| 2043 | m->R_IP = target;\r |
| 2044 | DECODE_CLEAR_SEGOVR(m);\r |
| 2045 | }\r |
| 2046 | \r |
| 2047 | /*opcode=0x7a*/\r |
| 2048 | static void i86op_jump_near_P(PC_ENV *m)\r |
| 2049 | {\r |
| 2050 | int8 offset;\r |
| 2051 | uint16 target;\r |
| 2052 | /* jump to byte offset if parity flag is set (even parity) */\r |
| 2053 | offset = (int8)fetch_byte_imm(m);\r |
| 2054 | target = (int16)(m->R_IP) + offset;\r |
| 2055 | if (ACCESS_FLAG(m, F_PF))\r |
| 2056 | m->R_IP = target;\r |
| 2057 | DECODE_CLEAR_SEGOVR(m);\r |
| 2058 | }\r |
| 2059 | \r |
| 2060 | /*opcode=0x7b*/\r |
| 2061 | static void i86op_jump_near_NP(PC_ENV *m)\r |
| 2062 | {\r |
| 2063 | int8 offset;\r |
| 2064 | uint16 target;\r |
| 2065 | /* jump to byte offset if parity flag is clear (odd parity) */\r |
| 2066 | offset = (int8)fetch_byte_imm(m);\r |
| 2067 | target = (int16)(m->R_IP) + offset;\r |
| 2068 | if (!ACCESS_FLAG(m, F_PF))\r |
| 2069 | m->R_IP = target;\r |
| 2070 | DECODE_CLEAR_SEGOVR(m);\r |
| 2071 | }\r |
| 2072 | \r |
| 2073 | /* JHH fixed till here... */\r |
| 2074 | \r |
| 2075 | /*opcode=0x7c*/\r |
| 2076 | static void i86op_jump_near_L(PC_ENV *m)\r |
| 2077 | {\r |
| 2078 | int8 offset;\r |
| 2079 | uint16 target;\r |
| 2080 | int sf,of;\r |
| 2081 | /* jump to byte offset if sign flag not equal to overflow flag. */\r |
| 2082 | offset = (int8)fetch_byte_imm(m);\r |
| 2083 | target = (int16)(m->R_IP) + offset;\r |
| 2084 | /* note:\r |
| 2085 | * this is the simplest expression i could think of which\r |
| 2086 | * expresses SF != OF. m->R_FLG&F_SF either equals x80 or x00.\r |
| 2087 | * Similarly m->R_FLG&F_OF either equals x800 or x000.\r |
| 2088 | * The former shifted right by 7 puts a 1 or 0 in bit 0.\r |
| 2089 | * The latter shifter right by 11 puts a 1 or 0 in bit 0.\r |
| 2090 | * if the two expressions are the same, i.e. equal, then\r |
| 2091 | * a zero results from the xor. If they are not equal,\r |
| 2092 | * then a 1 results, and the jump is taken.\r |
| 2093 | */\r |
| 2094 | sf = ACCESS_FLAG(m,F_SF) != 0;\r |
| 2095 | of = ACCESS_FLAG(m,F_OF) != 0;\r |
| 2096 | /* was: if ( ((m->R_FLG & F_SF)>>7) ^ ((m->R_FLG & F_OF) >> 11))*/\r |
| 2097 | if (sf ^ of)\r |
| 2098 | m->R_IP = target;\r |
| 2099 | DECODE_CLEAR_SEGOVR(m);\r |
| 2100 | }\r |
| 2101 | \r |
| 2102 | /*opcode=0x7d*/\r |
| 2103 | static void i86op_jump_near_NL(PC_ENV *m)\r |
| 2104 | {\r |
| 2105 | int8 offset;\r |
| 2106 | uint16 target;\r |
| 2107 | int sf,of;\r |
| 2108 | /* jump to byte offset if sign flag not equal to overflow flag. */\r |
| 2109 | offset = (int8)fetch_byte_imm(m);\r |
| 2110 | target = (int16)(m->R_IP) + offset;\r |
| 2111 | sf = ACCESS_FLAG(m,F_SF) != 0;\r |
| 2112 | of = ACCESS_FLAG(m,F_OF) != 0;\r |
| 2113 | /* note: inverse of above, but using == instead of xor. */\r |
| 2114 | /* was: if (((m->R_FLG & F_SF)>>7) == ((m->R_FLG & F_OF) >> 11))*/\r |
| 2115 | if (sf == of)\r |
| 2116 | m->R_IP = target;\r |
| 2117 | DECODE_CLEAR_SEGOVR(m);\r |
| 2118 | }\r |
| 2119 | \r |
| 2120 | /*opcode=0x7e*/\r |
| 2121 | static void i86op_jump_near_LE(PC_ENV *m)\r |
| 2122 | {\r |
| 2123 | int8 offset;\r |
| 2124 | uint16 target;\r |
| 2125 | int sf,of;\r |
| 2126 | /* jump to byte offset if sign flag not equal to overflow flag\r |
| 2127 | or the zero flag is set */\r |
| 2128 | offset = (int8)fetch_byte_imm(m);\r |
| 2129 | target = (int16)(m->R_IP) + offset;\r |
| 2130 | sf = ACCESS_FLAG(m,F_SF) != 0;\r |
| 2131 | of = ACCESS_FLAG(m,F_OF) != 0;\r |
| 2132 | /* note: modification of JL */\r |
| 2133 | /* sf != of */\r |
| 2134 | /* was: if ((((m->R_FLG & F_SF)>>7) ^ ((m->R_FLG & F_OF) >> 11))\r |
| 2135 | || (m->R_FLG & F_ZF) ) */\r |
| 2136 | if ( (sf ^ of) || ACCESS_FLAG(m,F_ZF))\r |
| 2137 | m->R_IP = target;\r |
| 2138 | DECODE_CLEAR_SEGOVR(m);\r |
| 2139 | }\r |
| 2140 | \r |
| 2141 | /*opcode=0x7f*/\r |
| 2142 | static void i86op_jump_near_NLE(PC_ENV *m)\r |
| 2143 | {\r |
| 2144 | int8 offset;\r |
| 2145 | uint16 target;\r |
| 2146 | int sf,of;\r |
| 2147 | /* jump to byte offset if sign flag equal to overflow flag.\r |
| 2148 | and the zero flag is clear*/\r |
| 2149 | offset = (int8)fetch_byte_imm(m);\r |
| 2150 | target = (int16)(m->R_IP) + offset;\r |
| 2151 | sf = ACCESS_FLAG(m,F_SF) != 0;\r |
| 2152 | of = ACCESS_FLAG(m,F_OF) != 0;\r |
| 2153 | \r |
| 2154 | /* if (((m->R_FLG & F_SF)>>7) == ((m->R_FLG & F_OF) >> 11)\r |
| 2155 | && (!(m->R_FLG & F_ZF))) */\r |
| 2156 | if ( ( sf == of ) && !ACCESS_FLAG(m,F_ZF))\r |
| 2157 | m->R_IP = target;\r |
| 2158 | DECODE_CLEAR_SEGOVR(m);\r |
| 2159 | }\r |
| 2160 | \r |
| 2161 | static uint8 (*opc80_byte_operation[])(PC_ENV *m,uint8 d,uint8 s) =\r |
| 2162 | {\r |
| 2163 | add_byte,/*00*/\r |
| 2164 | or_byte, /*01*/\r |
| 2165 | adc_byte,/*02*/\r |
| 2166 | sbb_byte,/*03*/\r |
| 2167 | and_byte,/*04*/\r |
| 2168 | sub_byte,/*05*/\r |
| 2169 | xor_byte,/*06*/\r |
| 2170 | cmp_byte,/*07*/\r |
| 2171 | };\r |
| 2172 | \r |
| 2173 | /*opcode=0x80*/\r |
| 2174 | static void i86op_opc80_byte_RM_IMM(PC_ENV *m)\r |
| 2175 | {\r |
| 2176 | uint16 mod,rl,rh;\r |
| 2177 | uint8 *destreg;\r |
| 2178 | uint16 destoffset;\r |
| 2179 | uint8 imm;\r |
| 2180 | uint8 destval;\r |
| 2181 | /* weirdo special case instruction format. Part of the\r |
| 2182 | opcode held below in "RH". Doubly nested case would\r |
| 2183 | result, except that the decoded instruction\r |
| 2184 | */\r |
| 2185 | FETCH_DECODE_MODRM(m,mod,rh,rl);\r |
| 2186 | /* know operation, decode the mod byte to find the addressing\r |
| 2187 | mode. */\r |
| 2188 | switch (mod)\r |
| 2189 | {\r |
| 2190 | case 0:\r |
| 2191 | destoffset=decode_rm00_address(m,rl);\r |
| 2192 | destval = fetch_data_byte(m,destoffset);\r |
| 2193 | imm = fetch_byte_imm(m);\r |
| 2194 | destval = (*opc80_byte_operation[rh])(m, destval, imm);\r |
| 2195 | if (rh != 7) store_data_byte(m,destoffset,destval);\r |
| 2196 | break;\r |
| 2197 | case 1:\r |
| 2198 | destoffset=decode_rm01_address(m,rl);\r |
| 2199 | destval = fetch_data_byte(m,destoffset);\r |
| 2200 | imm = fetch_byte_imm(m);\r |
| 2201 | destval = (*opc80_byte_operation[rh])(m, destval, imm);\r |
| 2202 | if (rh != 7) store_data_byte(m,destoffset,destval);\r |
| 2203 | break;\r |
| 2204 | case 2:\r |
| 2205 | destoffset=decode_rm10_address(m,rl);\r |
| 2206 | destval = fetch_data_byte(m,destoffset);\r |
| 2207 | imm = fetch_byte_imm(m);\r |
| 2208 | destval = (*opc80_byte_operation[rh])(m, destval, imm);\r |
| 2209 | if (rh != 7) store_data_byte(m,destoffset,destval);\r |
| 2210 | break;\r |
| 2211 | case 3: /* register to register */\r |
| 2212 | destreg = DECODE_RM_BYTE_REGISTER(m,rl);\r |
| 2213 | imm = fetch_byte_imm(m);\r |
| 2214 | destval = (*opc80_byte_operation[rh])(m, *destreg, imm);\r |
| 2215 | if (rh != 7) *destreg = destval;\r |
| 2216 | break;\r |
| 2217 | }\r |
| 2218 | DECODE_CLEAR_SEGOVR(m);\r |
| 2219 | }\r |
| 2220 | \r |
| 2221 | static uint16 (*opc81_word_operation[])(PC_ENV *m,uint16 d,uint16 s) =\r |
| 2222 | { add_word,/*00*/\r |
| 2223 | or_word, /*01*/\r |
| 2224 | adc_word,/*02*/\r |
| 2225 | sbb_word,/*03*/\r |
| 2226 | and_word,/*04*/\r |
| 2227 | sub_word,/*05*/\r |
| 2228 | xor_word,/*06*/\r |
| 2229 | cmp_word,/*07*/\r |
| 2230 | };\r |
| 2231 | \r |
| 2232 | /*opcode=0x81*/\r |
| 2233 | static void i86op_opc81_word_RM_IMM(PC_ENV *m)\r |
| 2234 | {\r |
| 2235 | uint16 mod,rl,rh;\r |
| 2236 | uint16 *destreg;\r |
| 2237 | uint16 destoffset;\r |
| 2238 | uint16 imm;\r |
| 2239 | uint16 destval;\r |
| 2240 | /* weirdo special case instruction format. Part of the\r |
| 2241 | opcode held below in "RH". Doubly nested case would\r |
| 2242 | result, except that the decoded instruction\r |
| 2243 | */\r |
| 2244 | FETCH_DECODE_MODRM(m,mod,rh,rl);\r |
| 2245 | /* know operation, decode the mod byte to find the addressing\r |
| 2246 | mode. */\r |
| 2247 | switch (mod)\r |
| 2248 | {\r |
| 2249 | case 0:\r |
| 2250 | destoffset=decode_rm00_address(m,rl);\r |
| 2251 | destval = fetch_data_word(m,destoffset);\r |
| 2252 | imm = fetch_word_imm(m);\r |
| 2253 | destval = (*opc81_word_operation[rh])(m, destval, imm);\r |
| 2254 | if (rh != 7) store_data_word(m,destoffset,destval);\r |
| 2255 | break;\r |
| 2256 | case 1:\r |
| 2257 | destoffset=decode_rm01_address(m,rl);\r |
| 2258 | destval = fetch_data_word(m,destoffset);\r |
| 2259 | imm = fetch_word_imm(m);\r |
| 2260 | destval = (*opc81_word_operation[rh])(m, destval, imm);\r |
| 2261 | if (rh != 7) store_data_word(m,destoffset,destval);\r |
| 2262 | break;\r |
| 2263 | case 2:\r |
| 2264 | destoffset=decode_rm10_address(m,rl);\r |
| 2265 | destval = fetch_data_word(m,destoffset);\r |
| 2266 | imm = fetch_word_imm(m);\r |
| 2267 | destval = (*opc81_word_operation[rh])(m, destval, imm);\r |
| 2268 | if (rh != 7) store_data_word(m,destoffset,destval);\r |
| 2269 | break;\r |
| 2270 | case 3: /* register to register */\r |
| 2271 | destreg = DECODE_RM_WORD_REGISTER(m,rl);\r |
| 2272 | imm = fetch_word_imm(m);\r |
| 2273 | destval = (*opc81_word_operation[rh])(m, *destreg, imm);\r |
| 2274 | if (rh != 7) *destreg = destval;\r |
| 2275 | break;\r |
| 2276 | }\r |
| 2277 | DECODE_CLEAR_SEGOVR(m);\r |
| 2278 | }\r |
| 2279 | \r |
| 2280 | static uint8 (*opc82_byte_operation[])(PC_ENV *m,uint8 s,uint8 d) =\r |
| 2281 | {\r |
| 2282 | add_byte,/*00*/\r |
| 2283 | or_byte, /*01*/ /*YYY UNUSED ????*/\r |
| 2284 | adc_byte,/*02*/\r |
| 2285 | sbb_byte,/*03*/\r |
| 2286 | and_byte,/*04*/ /*YYY UNUSED ????*/\r |
| 2287 | sub_byte,/*05*/\r |
| 2288 | xor_byte,/*06*/ /*YYY UNUSED ????*/\r |
| 2289 | cmp_byte,/*07*/\r |
| 2290 | };\r |
| 2291 | \r |
| 2292 | /*opcode=0x82*/\r |
| 2293 | static void i86op_opc82_byte_RM_IMM(PC_ENV *m)\r |
| 2294 | {\r |
| 2295 | uint16 mod,rl,rh;\r |
| 2296 | uint8 *destreg;\r |
| 2297 | uint16 destoffset;\r |
| 2298 | uint8 imm;\r |
| 2299 | uint8 destval;\r |
| 2300 | /* weirdo special case instruction format. Part of the\r |
| 2301 | opcode held below in "RH". Doubly nested case would\r |
| 2302 | result, except that the decoded instruction\r |
| 2303 | Similar to opcode 81, except that the immediate byte\r |
| 2304 | is sign extended to a word length.\r |
| 2305 | */\r |
| 2306 | FETCH_DECODE_MODRM(m,mod,rh,rl);\r |
| 2307 | /* know operation, decode the mod byte to find the addressing\r |
| 2308 | mode. */\r |
| 2309 | switch (mod)\r |
| 2310 | {\r |
| 2311 | case 0:\r |
| 2312 | destoffset=decode_rm00_address(m,rl);\r |
| 2313 | destval = fetch_data_byte(m,destoffset);\r |
| 2314 | imm = fetch_byte_imm(m);\r |
| 2315 | destval = (*opc82_byte_operation[rh])(m, destval, imm);\r |
| 2316 | if (rh != 7) store_data_byte(m,destoffset,destval);\r |
| 2317 | break;\r |
| 2318 | case 1:\r |
| 2319 | destoffset=decode_rm01_address(m,rl);\r |
| 2320 | destval = fetch_data_byte(m,destoffset);\r |
| 2321 | imm = fetch_byte_imm(m);\r |
| 2322 | destval = (*opc82_byte_operation[rh])(m, destval, imm);\r |
| 2323 | if (rh != 7) store_data_byte(m,destoffset,destval);\r |
| 2324 | break;\r |
| 2325 | case 2:\r |
| 2326 | destoffset=decode_rm10_address(m,rl);\r |
| 2327 | destval = fetch_data_byte(m,destoffset);\r |
| 2328 | imm = fetch_byte_imm(m);\r |
| 2329 | destval = (*opc82_byte_operation[rh])(m, destval, imm);\r |
| 2330 | if (rh != 7) store_data_byte(m,destoffset,destval);\r |
| 2331 | break;\r |
| 2332 | case 3: /* register to register */\r |
| 2333 | destreg = DECODE_RM_BYTE_REGISTER(m,rl);\r |
| 2334 | imm = fetch_byte_imm(m);\r |
| 2335 | destval = (*opc82_byte_operation[rh])(m, *destreg, imm);\r |
| 2336 | if (rh != 7) *destreg = destval;\r |
| 2337 | break;\r |
| 2338 | }\r |
| 2339 | DECODE_CLEAR_SEGOVR(m);\r |
| 2340 | }\r |
| 2341 | \r |
| 2342 | static uint16 (*opc83_word_operation[])(PC_ENV *m,uint16 s,uint16 d) =\r |
| 2343 | {\r |
| 2344 | add_word,/*00*/\r |
| 2345 | or_word, /*01*/ /*YYY UNUSED ????*/\r |
| 2346 | adc_word,/*02*/\r |
| 2347 | sbb_word,/*03*/\r |
| 2348 | and_word,/*04*/ /*YYY UNUSED ????*/\r |
| 2349 | sub_word,/*05*/\r |
| 2350 | xor_word,/*06*/ /*YYY UNUSED ????*/\r |
| 2351 | cmp_word,/*07*/\r |
| 2352 | };\r |
| 2353 | \r |
| 2354 | /*opcode=0x83*/\r |
| 2355 | static void i86op_opc83_word_RM_IMM(PC_ENV *m)\r |
| 2356 | {\r |
| 2357 | uint16 mod,rl,rh;\r |
| 2358 | uint16 *destreg;\r |
| 2359 | uint16 destoffset;\r |
| 2360 | uint16 imm;\r |
| 2361 | uint16 destval;\r |
| 2362 | /* weirdo special case instruction format. Part of the\r |
| 2363 | opcode held below in "RH". Doubly nested case would\r |
| 2364 | result, except that the decoded instruction\r |
| 2365 | Similar to opcode 81, except that the immediate byte\r |
| 2366 | is sign extended to a word length.\r |
| 2367 | */\r |
| 2368 | FETCH_DECODE_MODRM(m,mod,rh,rl);\r |
| 2369 | /* know operation, decode the mod byte to find the addressing\r |
| 2370 | mode. */\r |
| 2371 | switch (mod)\r |
| 2372 | {\r |
| 2373 | case 0:\r |
| 2374 | destoffset=decode_rm00_address(m,rl);\r |
| 2375 | destval = fetch_data_word(m,destoffset);\r |
| 2376 | imm = (int8)fetch_byte_imm(m);\r |
| 2377 | destval = (*opc83_word_operation[rh])(m, destval, imm);\r |
| 2378 | if (rh != 7) store_data_word(m,destoffset,destval);\r |
| 2379 | break;\r |
| 2380 | case 1:\r |
| 2381 | destoffset=decode_rm01_address(m,rl);\r |
| 2382 | destval = fetch_data_word(m,destoffset);\r |
| 2383 | imm = (int8)fetch_byte_imm(m);\r |
| 2384 | destval = (*opc83_word_operation[rh])(m, destval, imm);\r |
| 2385 | if (rh != 7) store_data_word(m,destoffset,destval);\r |
| 2386 | break;\r |
| 2387 | case 2:\r |
| 2388 | destoffset=decode_rm10_address(m,rl);\r |
| 2389 | destval = fetch_data_word(m,destoffset);\r |
| 2390 | imm = (int8) fetch_byte_imm(m);\r |
| 2391 | destval = (*opc83_word_operation[rh])(m, destval, imm);\r |
| 2392 | if (rh != 7) store_data_word(m,destoffset,destval);\r |
| 2393 | break;\r |
| 2394 | case 3: /* register to register */\r |
| 2395 | destreg = DECODE_RM_WORD_REGISTER(m,rl);\r |
| 2396 | imm = (int8) fetch_byte_imm(m);\r |
| 2397 | destval = (*opc83_word_operation[rh])(m, *destreg, imm);\r |
| 2398 | if (rh != 7) *destreg = destval;\r |
| 2399 | break;\r |
| 2400 | }\r |
| 2401 | DECODE_CLEAR_SEGOVR(m);\r |
| 2402 | }\r |
| 2403 | \r |
| 2404 | /*opcode=0x84*/\r |
| 2405 | static void i86op_test_byte_RM_R(PC_ENV *m)\r |
| 2406 | {\r |
| 2407 | uint16 mod,rl,rh;\r |
| 2408 | uint8 *destreg,*srcreg;\r |
| 2409 | uint16 destoffset;\r |
| 2410 | uint8 destval;\r |
| 2411 | FETCH_DECODE_MODRM(m,mod,rh,rl);\r |
| 2412 | switch (mod)\r |
| 2413 | {\r |
| 2414 | case 0:\r |
| 2415 | destoffset=decode_rm00_address(m,rl);\r |
| 2416 | destval = fetch_data_byte(m,destoffset);\r |
| 2417 | srcreg = DECODE_RM_BYTE_REGISTER(m,rh);\r |
| 2418 | test_byte(m, destval, *srcreg);\r |
| 2419 | break;\r |
| 2420 | case 1:\r |
| 2421 | destoffset=decode_rm01_address(m,rl);\r |
| 2422 | destval = fetch_data_byte(m,destoffset);\r |
| 2423 | srcreg = DECODE_RM_BYTE_REGISTER(m,rh);\r |
| 2424 | test_byte(m, destval, *srcreg);\r |
| 2425 | break;\r |
| 2426 | case 2:\r |
| 2427 | destoffset=decode_rm10_address(m,rl);\r |
| 2428 | destval = fetch_data_byte(m,destoffset);\r |
| 2429 | srcreg = DECODE_RM_BYTE_REGISTER(m,rh);\r |
| 2430 | test_byte(m, destval, *srcreg);\r |
| 2431 | break;\r |
| 2432 | case 3: /* register to register */\r |
| 2433 | destreg = DECODE_RM_BYTE_REGISTER(m,rl);\r |
| 2434 | srcreg = DECODE_RM_BYTE_REGISTER(m,rh);\r |
| 2435 | test_byte(m, *destreg, *srcreg);\r |
| 2436 | break;\r |
| 2437 | }\r |
| 2438 | DECODE_CLEAR_SEGOVR(m);\r |
| 2439 | }\r |
| 2440 | \r |
| 2441 | /*opcode=0x85*/\r |
| 2442 | static void i86op_test_word_RM_R(PC_ENV *m)\r |
| 2443 | {\r |
| 2444 | uint16 mod,rl,rh;\r |
| 2445 | uint16 *destreg,*srcreg;\r |
| 2446 | uint16 destoffset;\r |
| 2447 | uint16 destval;\r |
| 2448 | FETCH_DECODE_MODRM(m,mod,rh,rl);\r |
| 2449 | switch (mod)\r |
| 2450 | {\r |
| 2451 | case 0:\r |
| 2452 | destoffset=decode_rm00_address(m,rl);\r |
| 2453 | destval = fetch_data_word(m,destoffset);\r |
| 2454 | srcreg = DECODE_RM_WORD_REGISTER(m,rh);\r |
| 2455 | test_word(m, destval, *srcreg);\r |
| 2456 | break;\r |
| 2457 | case 1:\r |
| 2458 | destoffset=decode_rm01_address(m,rl);\r |
| 2459 | destval = fetch_data_word(m,destoffset);\r |
| 2460 | srcreg = DECODE_RM_WORD_REGISTER(m,rh);\r |
| 2461 | test_word(m, destval, *srcreg);\r |
| 2462 | break;\r |
| 2463 | case 2:\r |
| 2464 | destoffset=decode_rm10_address(m,rl);\r |
| 2465 | destval = fetch_data_word(m,destoffset);\r |
| 2466 | srcreg = DECODE_RM_WORD_REGISTER(m,rh);\r |
| 2467 | test_word(m, destval, *srcreg);\r |
| 2468 | break;\r |
| 2469 | case 3: /* register to register */\r |
| 2470 | destreg = DECODE_RM_WORD_REGISTER(m,rl);\r |
| 2471 | srcreg = DECODE_RM_WORD_REGISTER(m,rh);\r |
| 2472 | test_word(m, *destreg, *srcreg);\r |
| 2473 | break;\r |
| 2474 | }\r |
| 2475 | DECODE_CLEAR_SEGOVR(m);\r |
| 2476 | }\r |
| 2477 | \r |
| 2478 | /*opcode=0x86*/\r |
| 2479 | static void i86op_xchg_byte_RM_R(PC_ENV *m)\r |
| 2480 | {\r |
| 2481 | uint16 mod,rl,rh;\r |
| 2482 | uint8 *destreg,*srcreg;\r |
| 2483 | uint16 destoffset;\r |
| 2484 | uint8 destval;\r |
| 2485 | uint8 tmp;\r |
| 2486 | FETCH_DECODE_MODRM(m,mod,rh,rl);\r |
| 2487 | switch (mod)\r |
| 2488 | {\r |
| 2489 | case 0:\r |
| 2490 | destoffset=decode_rm00_address(m,rl);\r |
| 2491 | destval = fetch_data_byte(m,destoffset);\r |
| 2492 | srcreg = DECODE_RM_BYTE_REGISTER(m,rh);\r |
| 2493 | tmp = *srcreg;\r |
| 2494 | *srcreg = destval;\r |
| 2495 | destval = tmp;\r |
| 2496 | store_data_byte(m,destoffset,destval);\r |
| 2497 | break;\r |
| 2498 | case 1:\r |
| 2499 | destoffset=decode_rm01_address(m,rl);\r |
| 2500 | destval = fetch_data_byte(m,destoffset);\r |
| 2501 | srcreg = DECODE_RM_BYTE_REGISTER(m,rh);\r |
| 2502 | tmp = *srcreg;\r |
| 2503 | *srcreg = destval;\r |
| 2504 | destval = tmp;\r |
| 2505 | store_data_byte(m,destoffset,destval);\r |
| 2506 | break;\r |
| 2507 | case 2:\r |
| 2508 | destoffset=decode_rm10_address(m,rl);\r |
| 2509 | destval = fetch_data_byte(m,destoffset);\r |
| 2510 | srcreg = DECODE_RM_BYTE_REGISTER(m,rh);\r |
| 2511 | tmp = *srcreg;\r |
| 2512 | *srcreg = destval;\r |
| 2513 | destval = tmp;\r |
| 2514 | store_data_byte(m,destoffset,destval);\r |
| 2515 | break;\r |
| 2516 | case 3: /* register to register */\r |
| 2517 | destreg = DECODE_RM_BYTE_REGISTER(m,rl);\r |
| 2518 | srcreg = DECODE_RM_BYTE_REGISTER(m,rh);\r |
| 2519 | tmp = *srcreg;\r |
| 2520 | *srcreg = *destreg;\r |
| 2521 | *destreg = tmp;\r |
| 2522 | break;\r |
| 2523 | }\r |
| 2524 | DECODE_CLEAR_SEGOVR(m);\r |
| 2525 | }\r |
| 2526 | \r |
| 2527 | /*opcode=0x87*/\r |
| 2528 | static void i86op_xchg_word_RM_R(PC_ENV *m)\r |
| 2529 | {\r |
| 2530 | uint16 mod,rl,rh;\r |
| 2531 | uint16 *destreg,*srcreg;\r |
| 2532 | uint16 destoffset;\r |
| 2533 | uint16 destval;\r |
| 2534 | uint16 tmp;\r |
| 2535 | FETCH_DECODE_MODRM(m,mod,rh,rl);\r |
| 2536 | switch (mod)\r |
| 2537 | {\r |
| 2538 | case 0:\r |
| 2539 | destoffset=decode_rm00_address(m,rl);\r |
| 2540 | destval = fetch_data_word(m,destoffset);\r |
| 2541 | srcreg = DECODE_RM_WORD_REGISTER(m,rh);\r |
| 2542 | tmp = *srcreg;\r |
| 2543 | *srcreg = destval;\r |
| 2544 | destval = tmp;\r |
| 2545 | store_data_word(m,destoffset,destval);\r |
| 2546 | break;\r |
| 2547 | case 1:\r |
| 2548 | destoffset=decode_rm01_address(m,rl);\r |
| 2549 | destval = fetch_data_word(m,destoffset);\r |
| 2550 | srcreg = DECODE_RM_WORD_REGISTER(m,rh);\r |
| 2551 | tmp = *srcreg;\r |
| 2552 | *srcreg = destval;\r |
| 2553 | destval = tmp;\r |
| 2554 | store_data_word(m,destoffset,destval);\r |
| 2555 | break;\r |
| 2556 | case 2:\r |
| 2557 | destoffset=decode_rm10_address(m,rl);\r |
| 2558 | destval = fetch_data_word(m,destoffset);\r |
| 2559 | srcreg = DECODE_RM_WORD_REGISTER(m,rh);\r |
| 2560 | tmp = *srcreg;\r |
| 2561 | *srcreg = destval;\r |
| 2562 | destval = tmp;\r |
| 2563 | store_data_word(m,destoffset,destval);\r |
| 2564 | break;\r |
| 2565 | case 3: /* register to register */\r |
| 2566 | destreg = DECODE_RM_WORD_REGISTER(m,rl);\r |
| 2567 | srcreg = DECODE_RM_WORD_REGISTER(m,rh);\r |
| 2568 | tmp = *srcreg;\r |
| 2569 | *srcreg = *destreg;\r |
| 2570 | *destreg = tmp;\r |
| 2571 | break;\r |
| 2572 | }\r |
| 2573 | DECODE_CLEAR_SEGOVR(m);\r |
| 2574 | }\r |
| 2575 | \r |
| 2576 | /*opcode=0x88*/\r |
| 2577 | static void i86op_mov_byte_RM_R(PC_ENV *m)\r |
| 2578 | {\r |
| 2579 | uint16 mod,rl,rh;\r |
| 2580 | uint8 *destreg,*srcreg;\r |
| 2581 | uint16 destoffset;\r |
| 2582 | FETCH_DECODE_MODRM(m,mod,rh,rl);\r |
| 2583 | switch (mod)\r |
| 2584 | {\r |
| 2585 | case 0:\r |
| 2586 | destoffset=decode_rm00_address(m,rl);\r |
| 2587 | srcreg = DECODE_RM_BYTE_REGISTER(m,rh);\r |
| 2588 | store_data_byte(m,destoffset,*srcreg);\r |
| 2589 | break;\r |
| 2590 | case 1:\r |
| 2591 | destoffset=decode_rm01_address(m,rl);\r |
| 2592 | srcreg = DECODE_RM_BYTE_REGISTER(m,rh);\r |
| 2593 | store_data_byte(m,destoffset,*srcreg);\r |
| 2594 | break;\r |
| 2595 | case 2:\r |
| 2596 | destoffset=decode_rm10_address(m,rl);\r |
| 2597 | srcreg = DECODE_RM_BYTE_REGISTER(m,rh);\r |
| 2598 | store_data_byte(m,destoffset,*srcreg);\r |
| 2599 | break;\r |
| 2600 | case 3: /* register to register */\r |
| 2601 | destreg = DECODE_RM_BYTE_REGISTER(m,rl);\r |
| 2602 | srcreg = DECODE_RM_BYTE_REGISTER(m,rh);\r |
| 2603 | *destreg = *srcreg;\r |
| 2604 | break;\r |
| 2605 | }\r |
| 2606 | DECODE_CLEAR_SEGOVR(m);\r |
| 2607 | }\r |
| 2608 | \r |
| 2609 | /*opcode=0x89*/\r |
| 2610 | static void i86op_mov_word_RM_R(PC_ENV *m)\r |
| 2611 | {\r |
| 2612 | uint16 mod,rl,rh;\r |
| 2613 | uint16 *destreg,*srcreg;\r |
| 2614 | uint16 destoffset;\r |
| 2615 | FETCH_DECODE_MODRM(m,mod,rh,rl);\r |
| 2616 | switch (mod)\r |
| 2617 | {\r |
| 2618 | case 0:\r |
| 2619 | destoffset=decode_rm00_address(m,rl);\r |
| 2620 | srcreg = DECODE_RM_WORD_REGISTER(m,rh);\r |
| 2621 | store_data_word(m,destoffset,*srcreg);\r |
| 2622 | break;\r |
| 2623 | case 1:\r |
| 2624 | destoffset=decode_rm01_address(m,rl);\r |
| 2625 | srcreg = DECODE_RM_WORD_REGISTER(m,rh);\r |
| 2626 | store_data_word(m,destoffset,*srcreg);\r |
| 2627 | break;\r |
| 2628 | case 2:\r |
| 2629 | destoffset=decode_rm10_address(m,rl);\r |
| 2630 | srcreg = DECODE_RM_WORD_REGISTER(m,rh);\r |
| 2631 | store_data_word(m,destoffset,*srcreg);\r |
| 2632 | break;\r |
| 2633 | case 3: /* register to register */\r |
| 2634 | destreg = DECODE_RM_WORD_REGISTER(m,rl);\r |
| 2635 | srcreg = DECODE_RM_WORD_REGISTER(m,rh);\r |
| 2636 | *destreg = *srcreg;\r |
| 2637 | break;\r |
| 2638 | }\r |
| 2639 | DECODE_CLEAR_SEGOVR(m);\r |
| 2640 | }\r |
| 2641 | \r |
| 2642 | /*opcode=0x8a*/\r |
| 2643 | static void i86op_mov_byte_R_RM(PC_ENV *m)\r |
| 2644 | {\r |
| 2645 | uint16 mod,rl,rh;\r |
| 2646 | uint8 *destreg,*srcreg;\r |
| 2647 | uint16 srcoffset;\r |
| 2648 | uint8 srcval;\r |
| 2649 | FETCH_DECODE_MODRM(m,mod,rh,rl);\r |
| 2650 | switch (mod)\r |
| 2651 | {\r |
| 2652 | case 0:\r |
| 2653 | destreg = DECODE_RM_BYTE_REGISTER(m,rh);\r |
| 2654 | srcoffset=decode_rm00_address(m,rl);\r |
| 2655 | srcval = fetch_data_byte(m,srcoffset);\r |
| 2656 | *destreg = srcval;\r |
| 2657 | break;\r |
| 2658 | case 1:\r |
| 2659 | destreg = DECODE_RM_BYTE_REGISTER(m,rh);\r |
| 2660 | srcoffset=decode_rm01_address(m,rl);\r |
| 2661 | srcval = fetch_data_byte(m,srcoffset);\r |
| 2662 | *destreg = srcval;\r |
| 2663 | break;\r |
| 2664 | case 2:\r |
| 2665 | destreg = DECODE_RM_BYTE_REGISTER(m,rh);\r |
| 2666 | srcoffset=decode_rm10_address(m,rl);\r |
| 2667 | srcval = fetch_data_byte(m,srcoffset);\r |
| 2668 | *destreg = srcval;\r |
| 2669 | break;\r |
| 2670 | case 3: /* register to register */\r |
| 2671 | destreg = DECODE_RM_BYTE_REGISTER(m,rh);\r |
| 2672 | srcreg = DECODE_RM_BYTE_REGISTER(m,rl);\r |
| 2673 | *destreg = *srcreg;\r |
| 2674 | break;\r |
| 2675 | }\r |
| 2676 | DECODE_CLEAR_SEGOVR(m);\r |
| 2677 | }\r |
| 2678 | \r |
| 2679 | /*opcode=0x8b*/\r |
| 2680 | static void i86op_mov_word_R_RM(PC_ENV *m)\r |
| 2681 | {\r |
| 2682 | uint16 mod,rl,rh;\r |
| 2683 | uint16 *destreg,*srcreg;\r |
| 2684 | uint16 srcoffset;\r |
| 2685 | uint16 srcval;\r |
| 2686 | FETCH_DECODE_MODRM(m,mod,rh,rl);\r |
| 2687 | switch (mod)\r |
| 2688 | {\r |
| 2689 | case 0:\r |
| 2690 | destreg = DECODE_RM_WORD_REGISTER(m,rh);\r |
| 2691 | srcoffset=decode_rm00_address(m,rl);\r |
| 2692 | srcval = fetch_data_word(m,srcoffset);\r |
| 2693 | *destreg = srcval;\r |
| 2694 | break;\r |
| 2695 | case 1:\r |
| 2696 | destreg = DECODE_RM_WORD_REGISTER(m,rh);\r |
| 2697 | srcoffset=decode_rm01_address(m,rl);\r |
| 2698 | srcval = fetch_data_word(m,srcoffset);\r |
| 2699 | *destreg = srcval;\r |
| 2700 | break;\r |
| 2701 | case 2:\r |
| 2702 | destreg = DECODE_RM_WORD_REGISTER(m,rh);\r |
| 2703 | srcoffset=decode_rm10_address(m,rl);\r |
| 2704 | srcval = fetch_data_word(m,srcoffset);\r |
| 2705 | *destreg = srcval;\r |
| 2706 | break;\r |
| 2707 | case 3: /* register to register */\r |
| 2708 | destreg = DECODE_RM_WORD_REGISTER(m,rh);\r |
| 2709 | srcreg = DECODE_RM_WORD_REGISTER(m,rl);\r |
| 2710 | *destreg = *srcreg;\r |
| 2711 | break;\r |
| 2712 | }\r |
| 2713 | DECODE_CLEAR_SEGOVR(m);\r |
| 2714 | }\r |
| 2715 | \r |
| 2716 | /*opcode=0x8c*/\r |
| 2717 | static void i86op_mov_word_RM_SR(PC_ENV *m)\r |
| 2718 | {\r |
| 2719 | uint16 mod,rl,rh;\r |
| 2720 | uint16 *destreg,*srcreg;\r |
| 2721 | uint16 destoffset;\r |
| 2722 | uint16 destval;\r |
| 2723 | FETCH_DECODE_MODRM(m,mod,rh,rl);\r |
| 2724 | switch (mod)\r |
| 2725 | {\r |
| 2726 | case 0:\r |
| 2727 | destoffset=decode_rm00_address(m,rl);\r |
| 2728 | srcreg = decode_rm_seg_register(m,rh);\r |
| 2729 | destval = *srcreg;\r |
| 2730 | store_data_word(m,destoffset,destval);\r |
| 2731 | break;\r |
| 2732 | case 1:\r |
| 2733 | destoffset=decode_rm01_address(m,rl);\r |
| 2734 | srcreg = decode_rm_seg_register(m,rh);\r |
| 2735 | destval = *srcreg;\r |
| 2736 | store_data_word(m,destoffset,destval);\r |
| 2737 | break;\r |
| 2738 | case 2:\r |
| 2739 | destoffset=decode_rm10_address(m,rl);\r |
| 2740 | srcreg = decode_rm_seg_register(m,rh);\r |
| 2741 | destval = *srcreg;\r |
| 2742 | store_data_word(m,destoffset,destval);\r |
| 2743 | break;\r |
| 2744 | case 3: /* register to register */\r |
| 2745 | destreg = DECODE_RM_WORD_REGISTER(m,rl);\r |
| 2746 | srcreg = decode_rm_seg_register(m,rh);\r |
| 2747 | *destreg = *srcreg;\r |
| 2748 | break;\r |
| 2749 | }\r |
| 2750 | DECODE_CLEAR_SEGOVR(m);\r |
| 2751 | }\r |
| 2752 | \r |
| 2753 | /*opcode=0x8d*/\r |
| 2754 | static void i86op_lea_word_R_M(PC_ENV *m)\r |
| 2755 | {\r |
| 2756 | uint16 mod,rl,rh;\r |
| 2757 | uint16 *srcreg;\r |
| 2758 | uint16 destoffset;\r |
| 2759 | FETCH_DECODE_MODRM(m,mod,rh,rl);\r |
| 2760 | switch (mod)\r |
| 2761 | {\r |
| 2762 | case 0:\r |
| 2763 | srcreg = DECODE_RM_WORD_REGISTER(m,rh);\r |
| 2764 | destoffset=decode_rm00_address(m,rl);\r |
| 2765 | *srcreg = destoffset;\r |
| 2766 | break;\r |
| 2767 | case 1:\r |
| 2768 | srcreg = DECODE_RM_WORD_REGISTER(m,rh);\r |
| 2769 | destoffset=decode_rm01_address(m,rl);\r |
| 2770 | *srcreg = destoffset;\r |
| 2771 | break;\r |
| 2772 | case 2:\r |
| 2773 | srcreg = DECODE_RM_WORD_REGISTER(m,rh);\r |
| 2774 | destoffset=decode_rm10_address(m,rl);\r |
| 2775 | *srcreg = destoffset;\r |
| 2776 | break;\r |
| 2777 | case 3: /* register to register */\r |
| 2778 | /* undefined. Do nothing. */\r |
| 2779 | break;\r |
| 2780 | }\r |
| 2781 | DECODE_CLEAR_SEGOVR(m);\r |
| 2782 | }\r |
| 2783 | \r |
| 2784 | /*opcode=0x8e*/\r |
| 2785 | static void i86op_mov_word_SR_RM(PC_ENV *m)\r |
| 2786 | {\r |
| 2787 | uint16 mod,rl,rh;\r |
| 2788 | uint16 *destreg,*srcreg;\r |
| 2789 | uint16 srcoffset;\r |
| 2790 | uint16 srcval;\r |
| 2791 | FETCH_DECODE_MODRM(m,mod,rh,rl);\r |
| 2792 | switch (mod)\r |
| 2793 | {\r |
| 2794 | case 0:\r |
| 2795 | destreg = decode_rm_seg_register(m,rh);\r |
| 2796 | srcoffset=decode_rm00_address(m,rl);\r |
| 2797 | srcval = fetch_data_word(m,srcoffset);\r |
| 2798 | *destreg = srcval;\r |
| 2799 | break;\r |
| 2800 | case 1:\r |
| 2801 | destreg = decode_rm_seg_register(m,rh);\r |
| 2802 | srcoffset=decode_rm01_address(m,rl);\r |
| 2803 | srcval = fetch_data_word(m,srcoffset);\r |
| 2804 | *destreg = srcval;\r |
| 2805 | break;\r |
| 2806 | case 2:\r |
| 2807 | destreg = decode_rm_seg_register(m,rh);\r |
| 2808 | srcoffset = decode_rm10_address(m,rl);\r |
| 2809 | srcval = fetch_data_word(m,srcoffset);\r |
| 2810 | *destreg = srcval;\r |
| 2811 | break;\r |
| 2812 | case 3: /* register to register */\r |
| 2813 | destreg = decode_rm_seg_register(m,rh);\r |
| 2814 | srcreg = DECODE_RM_WORD_REGISTER(m,rl);\r |
| 2815 | *destreg = *srcreg;\r |
| 2816 | break;\r |
| 2817 | }\r |
| 2818 | /*\\r |
| 2819 | * clean up, and reset all the R_xSP pointers to the correct\r |
| 2820 | * locations. This is about 3x too much overhead (doing all the\r |
| 2821 | * segreg ptrs when only one is needed, but this instruction\r |
| 2822 | * *cannot* be that common, and this isn't too much work anyway.\r |
| 2823 | \*/\r |
| 2824 | DECODE_CLEAR_SEGOVR(m);\r |
| 2825 | }\r |
| 2826 | \r |
| 2827 | /*opcode=0x8f*/\r |
| 2828 | static void i86op_pop_RM(PC_ENV *m)\r |
| 2829 | {\r |
| 2830 | uint16 mod,rl,rh;\r |
| 2831 | uint16 *destreg;\r |
| 2832 | uint16 destoffset;\r |
| 2833 | uint16 destval;\r |
| 2834 | FETCH_DECODE_MODRM(m,mod,rh,rl);\r |
| 2835 | if (rh != 0)\r |
| 2836 | {\r |
| 2837 | halt_sys(m);\r |
| 2838 | }\r |
| 2839 | switch (mod)\r |
| 2840 | {\r |
| 2841 | case 0:\r |
| 2842 | destoffset=decode_rm00_address(m,rl);\r |
| 2843 | destval = pop_word( m);\r |
| 2844 | store_data_word(m,destoffset,destval);\r |
| 2845 | break;\r |
| 2846 | case 1:\r |
| 2847 | destoffset=decode_rm01_address(m,rl);\r |
| 2848 | destval = pop_word(m);\r |
| 2849 | store_data_word(m,destoffset,destval);\r |
| 2850 | break;\r |
| 2851 | case 2:\r |
| 2852 | destoffset=decode_rm10_address(m,rl);\r |
| 2853 | destval = pop_word(m);\r |
| 2854 | store_data_word(m,destoffset,destval);\r |
| 2855 | break;\r |
| 2856 | case 3: /* register to register */\r |
| 2857 | destreg = DECODE_RM_WORD_REGISTER(m,rl);\r |
| 2858 | *destreg = pop_word(m);\r |
| 2859 | break;\r |
| 2860 | }\r |
| 2861 | DECODE_CLEAR_SEGOVR(m);\r |
| 2862 | }\r |
| 2863 | \r |
| 2864 | /*opcode=0x90*/\r |
| 2865 | static void i86op_nop(PC_ENV *m)\r |
| 2866 | {\r |
| 2867 | DECODE_CLEAR_SEGOVR(m);\r |
| 2868 | }\r |
| 2869 | \r |
| 2870 | /*opcode=0x91*/\r |
| 2871 | static void i86op_xchg_word_AX_CX(PC_ENV *m)\r |
| 2872 | {\r |
| 2873 | uint16 tmp;\r |
| 2874 | tmp = m->R_AX;\r |
| 2875 | m->R_AX = m->R_CX;\r |
| 2876 | m->R_CX = tmp;\r |
| 2877 | DECODE_CLEAR_SEGOVR(m);\r |
| 2878 | }\r |
| 2879 | \r |
| 2880 | /*opcode=0x92*/\r |
| 2881 | static void i86op_xchg_word_AX_DX(PC_ENV *m)\r |
| 2882 | {\r |
| 2883 | uint16 tmp;\r |
| 2884 | tmp = m->R_AX;\r |
| 2885 | m->R_AX = m->R_DX;\r |
| 2886 | m->R_DX = tmp;\r |
| 2887 | DECODE_CLEAR_SEGOVR(m);\r |
| 2888 | }\r |
| 2889 | \r |
| 2890 | /*opcode=0x93*/\r |
| 2891 | static void i86op_xchg_word_AX_BX(PC_ENV *m)\r |
| 2892 | {\r |
| 2893 | uint16 tmp;\r |
| 2894 | tmp = m->R_AX;\r |
| 2895 | m->R_AX = m->R_BX;\r |
| 2896 | m->R_BX = tmp;\r |
| 2897 | DECODE_CLEAR_SEGOVR(m);\r |
| 2898 | }\r |
| 2899 | \r |
| 2900 | /*opcode=0x94*/\r |
| 2901 | static void i86op_xchg_word_AX_SP(PC_ENV *m)\r |
| 2902 | {\r |
| 2903 | uint16 tmp;\r |
| 2904 | tmp = m->R_AX;\r |
| 2905 | m->R_AX = m->R_SP;\r |
| 2906 | m->R_SP = tmp;\r |
| 2907 | DECODE_CLEAR_SEGOVR(m);\r |
| 2908 | }\r |
| 2909 | \r |
| 2910 | /*opcode=0x95*/\r |
| 2911 | static void i86op_xchg_word_AX_BP(PC_ENV *m)\r |
| 2912 | {\r |
| 2913 | uint16 tmp;\r |
| 2914 | tmp = m->R_AX;\r |
| 2915 | m->R_AX = m->R_BP;\r |
| 2916 | m->R_BP = tmp;\r |
| 2917 | DECODE_CLEAR_SEGOVR(m);\r |
| 2918 | }\r |
| 2919 | \r |
| 2920 | /*opcode=0x96*/\r |
| 2921 | static void i86op_xchg_word_AX_SI(PC_ENV *m)\r |
| 2922 | {\r |
| 2923 | uint16 tmp;\r |
| 2924 | tmp = m->R_AX;\r |
| 2925 | m->R_AX = m->R_SI;\r |
| 2926 | m->R_SI = tmp;\r |
| 2927 | DECODE_CLEAR_SEGOVR(m);\r |
| 2928 | }\r |
| 2929 | \r |
| 2930 | /*opcode=0x97*/\r |
| 2931 | static void i86op_xchg_word_AX_DI(PC_ENV *m)\r |
| 2932 | {\r |
| 2933 | uint16 tmp;\r |
| 2934 | tmp = m->R_AX;\r |
| 2935 | m->R_AX = m->R_DI;\r |
| 2936 | m->R_DI = tmp;\r |
| 2937 | DECODE_CLEAR_SEGOVR(m);\r |
| 2938 | }\r |
| 2939 | \r |
| 2940 | /*opcode=0x98*/\r |
| 2941 | static void i86op_cbw(PC_ENV *m)\r |
| 2942 | {\r |
| 2943 | if (m->R_AL & 0x80)\r |
| 2944 | {\r |
| 2945 | m->R_AH = 0xff;\r |
| 2946 | }\r |
| 2947 | else\r |
| 2948 | {\r |
| 2949 | m->R_AH = 0x0;\r |
| 2950 | }\r |
| 2951 | DECODE_CLEAR_SEGOVR(m);\r |
| 2952 | }\r |
| 2953 | \r |
| 2954 | /*opcode=0x99*/\r |
| 2955 | static void i86op_cwd(PC_ENV *m)\r |
| 2956 | {\r |
| 2957 | if (m->R_AX & 0x8000)\r |
| 2958 | {\r |
| 2959 | m->R_DX = 0xffff;\r |
| 2960 | }\r |
| 2961 | else\r |
| 2962 | {\r |
| 2963 | m->R_DX = 0x0;\r |
| 2964 | }\r |
| 2965 | DECODE_CLEAR_SEGOVR(m);\r |
| 2966 | }\r |
| 2967 | \r |
| 2968 | /*opcode=0x9a*/\r |
| 2969 | static void i86op_call_far_IMM(PC_ENV *m)\r |
| 2970 | {\r |
| 2971 | uint16 farseg,faroff;\r |
| 2972 | faroff = fetch_word_imm(m);\r |
| 2973 | farseg = fetch_word_imm(m);\r |
| 2974 | /* XXX\r |
| 2975 | HOOKED INTERRUPT VECTORS CALLING INTO OUR "BIOS"\r |
| 2976 | WILL CAUSE PROBLEMS UNLESS ALL INTERSEGMENT STUFF IS\r |
| 2977 | CHECKED FOR BIOS ACCESS. CHECK NEEDED HERE.\r |
| 2978 | FOR MOMENT, LET IT ALONE.\r |
| 2979 | */\r |
| 2980 | push_word(m,m->R_CS);\r |
| 2981 | m->R_CS = farseg;\r |
| 2982 | push_word(m,m->R_IP);\r |
| 2983 | m->R_IP = faroff;\r |
| 2984 | DECODE_CLEAR_SEGOVR(m);\r |
| 2985 | }\r |
| 2986 | \r |
| 2987 | /*opcode=0x9b*/\r |
| 2988 | static void i86op_wait(PC_ENV *m)\r |
| 2989 | {\r |
| 2990 | /* NADA. */\r |
| 2991 | DECODE_CLEAR_SEGOVR(m);\r |
| 2992 | }\r |
| 2993 | \r |
| 2994 | /*opcode=0x9c*/\r |
| 2995 | static void i86op_pushf_word(PC_ENV *m)\r |
| 2996 | {\r |
| 2997 | uint16 flags;\r |
| 2998 | flags = m->R_FLG;\r |
| 2999 | /* clear out *all* bits not representing flags */\r |
| 3000 | flags &= F_MSK;\r |
| 3001 | /* TURN ON CHARACTERISTIC BITS OF FLAG FOR 8088 */\r |
| 3002 | flags |= F_ALWAYS_ON;\r |
| 3003 | push_word(m,flags);\r |
| 3004 | DECODE_CLEAR_SEGOVR(m);\r |
| 3005 | }\r |
| 3006 | \r |
| 3007 | /*opcode=0x9d*/\r |
| 3008 | static void i86op_popf_word(PC_ENV *m)\r |
| 3009 | {\r |
| 3010 | m->R_FLG = pop_word(m);\r |
| 3011 | DECODE_CLEAR_SEGOVR(m);\r |
| 3012 | }\r |
| 3013 | \r |
| 3014 | /*opcode=0x9e*/\r |
| 3015 | static void i86op_sahf(PC_ENV *m)\r |
| 3016 | {\r |
| 3017 | /* clear the lower bits of the flag register */\r |
| 3018 | m->R_FLG &= 0xffffff00;\r |
| 3019 | /* or in the AH register into the flags register */\r |
| 3020 | m->R_FLG |= m->R_AH;\r |
| 3021 | DECODE_CLEAR_SEGOVR(m);\r |
| 3022 | }\r |
| 3023 | \r |
| 3024 | /*opcode=0x9f*/\r |
| 3025 | static void i86op_lahf(PC_ENV *m)\r |
| 3026 | {\r |
| 3027 | m->R_AH = m->R_FLG & 0xff;\r |
| 3028 | /*undocumented TC++ behavior??? Nope. It's documented, but\r |
| 3029 | you have too look real hard to notice it. */\r |
| 3030 | m->R_AH |= 0x2;\r |
| 3031 | DECODE_CLEAR_SEGOVR(m);\r |
| 3032 | }\r |
| 3033 | \r |
| 3034 | /*opcode=0xa0*/\r |
| 3035 | static void i86op_mov_AL_M_IMM(PC_ENV *m)\r |
| 3036 | {\r |
| 3037 | uint16 offset;\r |
| 3038 | uint8 destval;\r |
| 3039 | offset = fetch_word_imm(m);\r |
| 3040 | destval = fetch_data_byte(m,offset);\r |
| 3041 | m->R_AL = destval;\r |
| 3042 | DECODE_CLEAR_SEGOVR(m);\r |
| 3043 | }\r |
| 3044 | \r |
| 3045 | /*opcode=0xa1*/\r |
| 3046 | static void i86op_mov_AX_M_IMM(PC_ENV *m)\r |
| 3047 | {\r |
| 3048 | uint16 offset;\r |
| 3049 | uint16 destval;\r |
| 3050 | offset = fetch_word_imm(m);\r |
| 3051 | destval = fetch_data_word(m,offset);\r |
| 3052 | m->R_AX = destval;\r |
| 3053 | DECODE_CLEAR_SEGOVR(m);\r |
| 3054 | }\r |
| 3055 | \r |
| 3056 | /*opcode=0xa2*/\r |
| 3057 | static void i86op_mov_M_AL_IMM(PC_ENV *m)\r |
| 3058 | {\r |
| 3059 | uint16 offset;\r |
| 3060 | offset = fetch_word_imm(m);\r |
| 3061 | store_data_byte(m,offset,m->R_AL);\r |
| 3062 | DECODE_CLEAR_SEGOVR(m);\r |
| 3063 | }\r |
| 3064 | \r |
| 3065 | /*opcode=0xa3*/\r |
| 3066 | static void i86op_mov_M_AX_IMM(PC_ENV *m)\r |
| 3067 | {\r |
| 3068 | uint16 offset;\r |
| 3069 | offset = fetch_word_imm(m);\r |
| 3070 | store_data_word(m,offset,m->R_AX);\r |
| 3071 | DECODE_CLEAR_SEGOVR(m);\r |
| 3072 | }\r |
| 3073 | \r |
| 3074 | /* JHH CLEANED */\r |
| 3075 | \r |
| 3076 | /*opcode=0xa4*/\r |
| 3077 | static void i86op_movs_byte(PC_ENV *m)\r |
| 3078 | {\r |
| 3079 | uint8 val;\r |
| 3080 | int inc;\r |
| 3081 | if (ACCESS_FLAG(m,F_DF)) /* down */\r |
| 3082 | inc = -1;\r |
| 3083 | else\r |
| 3084 | inc = 1;\r |
| 3085 | if (m->sysmode & (SYSMODE_PREFIX_REPE | SYSMODE_PREFIX_REPNE))\r |
| 3086 | {\r |
| 3087 | /* dont care whether REPE or REPNE */\r |
| 3088 | /* move them until CX is ZERO. */\r |
| 3089 | while (m->R_CX != 0)\r |
| 3090 | {\r |
| 3091 | val = fetch_data_byte(m,m->R_SI);\r |
| 3092 | store_data_byte_abs(m,m->R_ES,m->R_DI,val);\r |
| 3093 | m->R_CX -= 1;\r |
| 3094 | m->R_SI += inc;\r |
| 3095 | m->R_DI += inc;\r |
| 3096 | }\r |
| 3097 | m->sysmode &= ~(SYSMODE_PREFIX_REPE | SYSMODE_PREFIX_REPNE);\r |
| 3098 | }\r |
| 3099 | else\r |
| 3100 | {\r |
| 3101 | val = fetch_data_byte(m,m->R_SI);\r |
| 3102 | store_data_byte_abs(m,m->R_ES,m->R_DI,val);\r |
| 3103 | m->R_SI += inc;\r |
| 3104 | m->R_DI += inc;\r |
| 3105 | }\r |
| 3106 | DECODE_CLEAR_SEGOVR(m);\r |
| 3107 | }\r |
| 3108 | \r |
| 3109 | /*opcode=0xa5*/\r |
| 3110 | static void i86op_movs_word(PC_ENV *m)\r |
| 3111 | {\r |
| 3112 | int16 val;\r |
| 3113 | int inc;\r |
| 3114 | if (ACCESS_FLAG(m, F_DF)) /* down */\r |
| 3115 | inc = -2;\r |
| 3116 | else\r |
| 3117 | inc = 2;\r |
| 3118 | if (m->sysmode & (SYSMODE_PREFIX_REPE | SYSMODE_PREFIX_REPNE))\r |
| 3119 | {\r |
| 3120 | /* dont care whether REPE or REPNE */\r |
| 3121 | /* move them until CX is ZERO. */\r |
| 3122 | while (m->R_CX != 0)\r |
| 3123 | {\r |
| 3124 | val = fetch_data_word(m,m->R_SI);\r |
| 3125 | store_data_word_abs(m,m->R_ES,m->R_DI,val);\r |
| 3126 | m->R_CX -= 1;\r |
| 3127 | m->R_SI += inc;\r |
| 3128 | m->R_DI += inc;\r |
| 3129 | }\r |
| 3130 | m->sysmode &= ~(SYSMODE_PREFIX_REPE | SYSMODE_PREFIX_REPNE);\r |
| 3131 | }\r |
| 3132 | else\r |
| 3133 | {\r |
| 3134 | val = fetch_data_word(m,m->R_SI);\r |
| 3135 | store_data_word_abs(m,m->R_ES,m->R_DI,val);\r |
| 3136 | m->R_SI += inc;\r |
| 3137 | m->R_DI += inc;\r |
| 3138 | }\r |
| 3139 | DECODE_CLEAR_SEGOVR(m);\r |
| 3140 | }\r |
| 3141 | \r |
| 3142 | /*opcode=0xa6*/\r |
| 3143 | static void i86op_cmps_byte(PC_ENV *m)\r |
| 3144 | {\r |
| 3145 | int8 val1,val2;\r |
| 3146 | int inc;\r |
| 3147 | if (ACCESS_FLAG(m,F_DF)) /* down */\r |
| 3148 | inc = -1;\r |
| 3149 | else\r |
| 3150 | inc = 1;\r |
| 3151 | if (m->sysmode & SYSMODE_PREFIX_REPE)\r |
| 3152 | {\r |
| 3153 | /* REPE */\r |
| 3154 | /* move them until CX is ZERO. */\r |
| 3155 | while (m->R_CX != 0)\r |
| 3156 | {\r |
| 3157 | val1 = fetch_data_byte(m,m->R_SI);\r |
| 3158 | val2 = fetch_data_byte_abs(m,m->R_ES,m->R_DI);\r |
| 3159 | cmp_byte(m, val1,val2);\r |
| 3160 | m->R_CX -= 1;\r |
| 3161 | m->R_SI += inc;\r |
| 3162 | m->R_DI += inc;\r |
| 3163 | if (ACCESS_FLAG(m,F_ZF)==0) break;\r |
| 3164 | }\r |
| 3165 | m->sysmode &= ~SYSMODE_PREFIX_REPE;\r |
| 3166 | }\r |
| 3167 | else if (m->sysmode & SYSMODE_PREFIX_REPNE)\r |
| 3168 | {\r |
| 3169 | /* REPNE */\r |
| 3170 | /* move them until CX is ZERO. */\r |
| 3171 | while (m->R_CX != 0)\r |
| 3172 | {\r |
| 3173 | val1 = fetch_data_byte(m,m->R_SI);\r |
| 3174 | val2 = fetch_data_byte_abs(m,m->R_ES,m->R_DI);\r |
| 3175 | cmp_byte(m, val1,val2);\r |
| 3176 | m->R_CX -= 1;\r |
| 3177 | m->R_SI += inc;\r |
| 3178 | m->R_DI += inc;\r |
| 3179 | if (ACCESS_FLAG(m,F_ZF)) break; /* zero flag set means equal */\r |
| 3180 | }\r |
| 3181 | m->sysmode &= ~SYSMODE_PREFIX_REPNE;\r |
| 3182 | }\r |
| 3183 | else\r |
| 3184 | {\r |
| 3185 | val1 = fetch_data_byte(m,m->R_SI);\r |
| 3186 | val2 = fetch_data_byte_abs(m,m->R_ES,m->R_DI);\r |
| 3187 | cmp_byte(m, val1,val2);\r |
| 3188 | m->R_SI += inc;\r |
| 3189 | m->R_DI += inc;\r |
| 3190 | }\r |
| 3191 | DECODE_CLEAR_SEGOVR(m);\r |
| 3192 | }\r |
| 3193 | \r |
| 3194 | /*opcode=0xa7*/\r |
| 3195 | static void i86op_cmps_word(PC_ENV *m)\r |
| 3196 | {\r |
| 3197 | int16 val1,val2;\r |
| 3198 | int inc;\r |
| 3199 | if (ACCESS_FLAG(m,F_DF)) /* down */\r |
| 3200 | inc = -2;\r |
| 3201 | else\r |
| 3202 | inc = 2;\r |
| 3203 | if (m->sysmode & SYSMODE_PREFIX_REPE)\r |
| 3204 | {\r |
| 3205 | /* REPE */\r |
| 3206 | /* move them until CX is ZERO. */\r |
| 3207 | while (m->R_CX != 0)\r |
| 3208 | {\r |
| 3209 | val1 = fetch_data_word(m,m->R_SI);\r |
| 3210 | val2 = fetch_data_word_abs(m,m->R_ES,m->R_DI);\r |
| 3211 | cmp_word(m, val1,val2);\r |
| 3212 | m->R_CX -= 1;\r |
| 3213 | m->R_SI += inc;\r |
| 3214 | m->R_DI += inc;\r |
| 3215 | if (ACCESS_FLAG(m,F_ZF)==0) break;\r |
| 3216 | }\r |
| 3217 | m->sysmode &= ~SYSMODE_PREFIX_REPE;\r |
| 3218 | }\r |
| 3219 | else if (m->sysmode & SYSMODE_PREFIX_REPNE)\r |
| 3220 | {\r |
| 3221 | /* REPNE */\r |
| 3222 | /* move them until CX is ZERO. */\r |
| 3223 | while (m->R_CX != 0)\r |
| 3224 | {\r |
| 3225 | val1 = fetch_data_word(m,m->R_SI);\r |
| 3226 | val2 = fetch_data_word_abs(m,m->R_ES,m->R_DI);\r |
| 3227 | cmp_word(m, val1,val2);\r |
| 3228 | m->R_CX -= 1;\r |
| 3229 | m->R_SI += inc;\r |
| 3230 | m->R_DI += inc;\r |
| 3231 | if (ACCESS_FLAG(m,F_ZF)) break; /* zero flag set means equal */\r |
| 3232 | }\r |
| 3233 | m->sysmode &= ~SYSMODE_PREFIX_REPNE;\r |
| 3234 | }\r |
| 3235 | else\r |
| 3236 | {\r |
| 3237 | val1 = fetch_data_word(m,m->R_SI);\r |
| 3238 | val2 = fetch_data_word_abs(m,m->R_ES,m->R_DI);\r |
| 3239 | cmp_word(m, val1,val2);\r |
| 3240 | m->R_SI += inc;\r |
| 3241 | m->R_DI += inc;\r |
| 3242 | }\r |
| 3243 | DECODE_CLEAR_SEGOVR(m);\r |
| 3244 | }\r |
| 3245 | \r |
| 3246 | /*opcode=0xa8*/\r |
| 3247 | static void i86op_test_AL_IMM(PC_ENV *m)\r |
| 3248 | {\r |
| 3249 | int imm;\r |
| 3250 | imm = fetch_byte_imm(m);\r |
| 3251 | test_byte(m, m->R_AL, imm);\r |
| 3252 | DECODE_CLEAR_SEGOVR(m);\r |
| 3253 | }\r |
| 3254 | \r |
| 3255 | /*opcode=0xa9*/\r |
| 3256 | static void i86op_test_AX_IMM(PC_ENV *m)\r |
| 3257 | {\r |
| 3258 | int imm;\r |
| 3259 | imm = fetch_word_imm(m);\r |
| 3260 | test_word(m, m->R_AX, imm);\r |
| 3261 | DECODE_CLEAR_SEGOVR(m);\r |
| 3262 | }\r |
| 3263 | \r |
| 3264 | /*opcode=0xaa*/\r |
| 3265 | static void i86op_stos_byte(PC_ENV *m)\r |
| 3266 | {\r |
| 3267 | int inc;\r |
| 3268 | if (ACCESS_FLAG(m, F_DF)) /* down */\r |
| 3269 | inc = -1;\r |
| 3270 | else\r |
| 3271 | inc = 1;\r |
| 3272 | if (m->sysmode & (SYSMODE_PREFIX_REPE | SYSMODE_PREFIX_REPNE))\r |
| 3273 | {\r |
| 3274 | /* dont care whether REPE or REPNE */\r |
| 3275 | /* move them until CX is ZERO. */\r |
| 3276 | while (m->R_CX != 0)\r |
| 3277 | {\r |
| 3278 | store_data_byte_abs(m,m->R_ES,m->R_DI,m->R_AL);\r |
| 3279 | m->R_CX -= 1;\r |
| 3280 | m->R_DI += inc;\r |
| 3281 | }\r |
| 3282 | m->sysmode &= ~(SYSMODE_PREFIX_REPE | SYSMODE_PREFIX_REPNE);\r |
| 3283 | }\r |
| 3284 | else\r |
| 3285 | {\r |
| 3286 | store_data_byte_abs(m,m->R_ES,m->R_DI,m->R_AL);\r |
| 3287 | m->R_DI += inc;\r |
| 3288 | }\r |
| 3289 | DECODE_CLEAR_SEGOVR(m);\r |
| 3290 | }\r |
| 3291 | \r |
| 3292 | /*opcode=0xab*/\r |
| 3293 | static void i86op_stos_word(PC_ENV *m)\r |
| 3294 | {\r |
| 3295 | int inc;\r |
| 3296 | if (ACCESS_FLAG(m, F_DF)) /* down */\r |
| 3297 | inc = -2;\r |
| 3298 | else\r |
| 3299 | inc = 2;\r |
| 3300 | if (m->sysmode & (SYSMODE_PREFIX_REPE | SYSMODE_PREFIX_REPNE))\r |
| 3301 | {\r |
| 3302 | /* dont care whether REPE or REPNE */\r |
| 3303 | /* move them until CX is ZERO. */\r |
| 3304 | while (m->R_CX != 0)\r |
| 3305 | {\r |
| 3306 | store_data_word_abs(m,m->R_ES,m->R_DI,m->R_AX);\r |
| 3307 | m->R_CX -= 1;\r |
| 3308 | m->R_DI += inc;\r |
| 3309 | }\r |
| 3310 | m->sysmode &= ~(SYSMODE_PREFIX_REPE | SYSMODE_PREFIX_REPNE);\r |
| 3311 | }\r |
| 3312 | else\r |
| 3313 | {\r |
| 3314 | store_data_word_abs(m,m->R_ES,m->R_DI,m->R_AX);\r |
| 3315 | m->R_DI += inc;\r |
| 3316 | }\r |
| 3317 | DECODE_CLEAR_SEGOVR(m);\r |
| 3318 | }\r |
| 3319 | \r |
| 3320 | /*opcode=0xac*/\r |
| 3321 | static void i86op_lods_byte(PC_ENV *m)\r |
| 3322 | {\r |
| 3323 | int inc;\r |
| 3324 | if (ACCESS_FLAG(m,F_DF)) /* down */\r |
| 3325 | inc = -1;\r |
| 3326 | else\r |
| 3327 | inc = 1;\r |
| 3328 | if (m->sysmode & (SYSMODE_PREFIX_REPE | SYSMODE_PREFIX_REPNE))\r |
| 3329 | {\r |
| 3330 | /* dont care whether REPE or REPNE */\r |
| 3331 | /* move them until CX is ZERO. */\r |
| 3332 | while (m->R_CX != 0)\r |
| 3333 | {\r |
| 3334 | m->R_AL = fetch_data_byte(m,m->R_SI);\r |
| 3335 | m->R_CX -= 1;\r |
| 3336 | m->R_SI += inc;\r |
| 3337 | }\r |
| 3338 | m->sysmode &= ~(SYSMODE_PREFIX_REPE | SYSMODE_PREFIX_REPNE);\r |
| 3339 | }\r |
| 3340 | else\r |
| 3341 | {\r |
| 3342 | m->R_AL = fetch_data_byte(m,m->R_SI);\r |
| 3343 | m->R_SI += inc;\r |
| 3344 | }\r |
| 3345 | DECODE_CLEAR_SEGOVR(m);\r |
| 3346 | }\r |
| 3347 | \r |
| 3348 | /*opcode=0xad*/\r |
| 3349 | static void i86op_lods_word(PC_ENV *m)\r |
| 3350 | {\r |
| 3351 | int inc;\r |
| 3352 | if (ACCESS_FLAG(m,F_DF)) /* down */\r |
| 3353 | inc = -2;\r |
| 3354 | else\r |
| 3355 | inc = 2;\r |
| 3356 | if (m->sysmode & (SYSMODE_PREFIX_REPE | SYSMODE_PREFIX_REPNE))\r |
| 3357 | {\r |
| 3358 | /* dont care whether REPE or REPNE */\r |
| 3359 | /* move them until CX is ZERO. */\r |
| 3360 | while (m->R_CX != 0)\r |
| 3361 | {\r |
| 3362 | m->R_AX = fetch_data_word(m,m->R_SI);\r |
| 3363 | m->R_CX -= 1;\r |
| 3364 | m->R_SI += inc;\r |
| 3365 | }\r |
| 3366 | m->sysmode &= ~(SYSMODE_PREFIX_REPE | SYSMODE_PREFIX_REPNE);\r |
| 3367 | }\r |
| 3368 | else\r |
| 3369 | {\r |
| 3370 | m->R_AX = fetch_data_word(m,m->R_SI);\r |
| 3371 | m->R_SI += inc;\r |
| 3372 | }\r |
| 3373 | DECODE_CLEAR_SEGOVR(m);\r |
| 3374 | }\r |
| 3375 | \r |
| 3376 | /*opcode=0xae*/\r |
| 3377 | static void i86op_scas_byte(PC_ENV *m)\r |
| 3378 | {\r |
| 3379 | int8 val2;\r |
| 3380 | int inc;\r |
| 3381 | if (ACCESS_FLAG(m,F_DF)) /* down */\r |
| 3382 | inc = -1;\r |
| 3383 | else\r |
| 3384 | inc = 1;\r |
| 3385 | if (m->sysmode & SYSMODE_PREFIX_REPE)\r |
| 3386 | {\r |
| 3387 | /* REPE */\r |
| 3388 | /* move them until CX is ZERO. */\r |
| 3389 | while (m->R_CX != 0)\r |
| 3390 | {\r |
| 3391 | val2 = fetch_data_byte_abs(m,m->R_ES,m->R_DI);\r |
| 3392 | cmp_byte(m, m->R_AL,val2);\r |
| 3393 | m->R_CX -= 1;\r |
| 3394 | m->R_DI += inc;\r |
| 3395 | if (ACCESS_FLAG(m,F_ZF)==0) break;\r |
| 3396 | }\r |
| 3397 | m->sysmode &= ~SYSMODE_PREFIX_REPE;\r |
| 3398 | }\r |
| 3399 | else if (m->sysmode & SYSMODE_PREFIX_REPNE)\r |
| 3400 | {\r |
| 3401 | /* REPNE */\r |
| 3402 | /* move them until CX is ZERO. */\r |
| 3403 | while (m->R_CX != 0)\r |
| 3404 | {\r |
| 3405 | val2 = fetch_data_byte_abs(m,m->R_ES,m->R_DI);\r |
| 3406 | cmp_byte(m, m->R_AL,val2);\r |
| 3407 | m->R_CX -= 1;\r |
| 3408 | m->R_DI += inc;\r |
| 3409 | if (ACCESS_FLAG(m,F_ZF)) break; /* zero flag set means equal */\r |
| 3410 | }\r |
| 3411 | m->sysmode &= ~SYSMODE_PREFIX_REPNE;\r |
| 3412 | }\r |
| 3413 | else\r |
| 3414 | {\r |
| 3415 | val2 = fetch_data_byte_abs(m,m->R_ES,m->R_DI);\r |
| 3416 | cmp_byte(m, m->R_AL,val2);\r |
| 3417 | m->R_DI += inc;\r |
| 3418 | }\r |
| 3419 | DECODE_CLEAR_SEGOVR(m);\r |
| 3420 | }\r |
| 3421 | \r |
| 3422 | /*opcode=0xaf*/\r |
| 3423 | static void i86op_scas_word(PC_ENV *m)\r |
| 3424 | {\r |
| 3425 | int16 val2;\r |
| 3426 | int inc;\r |
| 3427 | if (ACCESS_FLAG(m, F_DF)) /* down */\r |
| 3428 | inc = -2;\r |
| 3429 | else\r |
| 3430 | inc = 2;\r |
| 3431 | if (m->sysmode & SYSMODE_PREFIX_REPE)\r |
| 3432 | {\r |
| 3433 | /* REPE */\r |
| 3434 | /* move them until CX is ZERO. */\r |
| 3435 | while (m->R_CX != 0)\r |
| 3436 | {\r |
| 3437 | val2 = fetch_data_word_abs(m,m->R_ES,m->R_DI);\r |
| 3438 | cmp_word(m,m->R_AX,val2);\r |
| 3439 | m->R_CX -= 1;\r |
| 3440 | m->R_DI += inc;\r |
| 3441 | if (ACCESS_FLAG(m,F_ZF)==0) break;\r |
| 3442 | }\r |
| 3443 | m->sysmode &= ~SYSMODE_PREFIX_REPE;\r |
| 3444 | }\r |
| 3445 | else if (m->sysmode & SYSMODE_PREFIX_REPNE)\r |
| 3446 | {\r |
| 3447 | /* REPNE */\r |
| 3448 | /* move them until CX is ZERO. */\r |
| 3449 | while (m->R_CX != 0)\r |
| 3450 | {\r |
| 3451 | val2 = fetch_data_word_abs(m,m->R_ES,m->R_DI);\r |
| 3452 | cmp_word(m, m->R_AX,val2);\r |
| 3453 | m->R_CX -= 1;\r |
| 3454 | m->R_DI += inc;\r |
| 3455 | if (ACCESS_FLAG(m,F_ZF)) break; /* zero flag set means equal */\r |
| 3456 | }\r |
| 3457 | m->sysmode &= ~SYSMODE_PREFIX_REPNE;\r |
| 3458 | }\r |
| 3459 | else\r |
| 3460 | {\r |
| 3461 | val2 = fetch_data_word_abs(m,m->R_ES,m->R_DI);\r |
| 3462 | cmp_word(m, m->R_AX,val2);\r |
| 3463 | m->R_DI += inc;\r |
| 3464 | }\r |
| 3465 | DECODE_CLEAR_SEGOVR(m);\r |
| 3466 | }\r |
| 3467 | \r |
| 3468 | /*opcode=0xb0*/\r |
| 3469 | static void i86op_mov_byte_AL_IMM(PC_ENV *m)\r |
| 3470 | {\r |
| 3471 | uint8 imm;\r |
| 3472 | imm = fetch_byte_imm(m);\r |
| 3473 | m->R_AL = imm;\r |
| 3474 | DECODE_CLEAR_SEGOVR(m);\r |
| 3475 | }\r |
| 3476 | \r |
| 3477 | /*opcode=0xb1*/\r |
| 3478 | static void i86op_mov_byte_CL_IMM(PC_ENV *m)\r |
| 3479 | {\r |
| 3480 | uint8 imm;\r |
| 3481 | imm = fetch_byte_imm(m);\r |
| 3482 | m->R_CL = imm;\r |
| 3483 | DECODE_CLEAR_SEGOVR(m);\r |
| 3484 | }\r |
| 3485 | \r |
| 3486 | /*opcode=0xb2*/\r |
| 3487 | static void i86op_mov_byte_DL_IMM(PC_ENV *m)\r |
| 3488 | {\r |
| 3489 | uint8 imm;\r |
| 3490 | imm = fetch_byte_imm(m);\r |
| 3491 | m->R_DL = imm;\r |
| 3492 | DECODE_CLEAR_SEGOVR(m);\r |
| 3493 | }\r |
| 3494 | \r |
| 3495 | /*opcode=0xb3*/\r |
| 3496 | static void i86op_mov_byte_BL_IMM(PC_ENV *m)\r |
| 3497 | {\r |
| 3498 | uint8 imm;\r |
| 3499 | imm = fetch_byte_imm(m);\r |
| 3500 | m->R_BL = imm;\r |
| 3501 | DECODE_CLEAR_SEGOVR(m);\r |
| 3502 | }\r |
| 3503 | \r |
| 3504 | /*opcode=0xb4*/\r |
| 3505 | static void i86op_mov_byte_AH_IMM(PC_ENV *m)\r |
| 3506 | {\r |
| 3507 | uint8 imm;\r |
| 3508 | imm = fetch_byte_imm(m);\r |
| 3509 | m->R_AH = imm;\r |
| 3510 | DECODE_CLEAR_SEGOVR(m);\r |
| 3511 | }\r |
| 3512 | \r |
| 3513 | /*opcode=0xb5*/\r |
| 3514 | static void i86op_mov_byte_CH_IMM(PC_ENV *m)\r |
| 3515 | {\r |
| 3516 | uint8 imm;\r |
| 3517 | imm = fetch_byte_imm(m);\r |
| 3518 | m->R_CH = imm;\r |
| 3519 | DECODE_CLEAR_SEGOVR(m);\r |
| 3520 | }\r |
| 3521 | \r |
| 3522 | /*opcode=0xb6*/\r |
| 3523 | static void i86op_mov_byte_DH_IMM(PC_ENV *m)\r |
| 3524 | {\r |
| 3525 | uint8 imm;\r |
| 3526 | imm = fetch_byte_imm(m);\r |
| 3527 | m->R_DH = imm;\r |
| 3528 | DECODE_CLEAR_SEGOVR(m);\r |
| 3529 | }\r |
| 3530 | \r |
| 3531 | /*opcode=0xb7*/\r |
| 3532 | static void i86op_mov_byte_BH_IMM(PC_ENV *m)\r |
| 3533 | {\r |
| 3534 | uint8 imm;\r |
| 3535 | imm = fetch_byte_imm(m);\r |
| 3536 | m->R_BH = imm;\r |
| 3537 | DECODE_CLEAR_SEGOVR(m);\r |
| 3538 | }\r |
| 3539 | \r |
| 3540 | /*opcode=0xb8*/\r |
| 3541 | static void i86op_mov_word_AX_IMM(PC_ENV *m)\r |
| 3542 | {\r |
| 3543 | uint16 imm;\r |
| 3544 | imm = fetch_word_imm(m);\r |
| 3545 | m->R_AX = imm;\r |
| 3546 | DECODE_CLEAR_SEGOVR(m);\r |
| 3547 | }\r |
| 3548 | \r |
| 3549 | /*opcode=0xb9*/\r |
| 3550 | static void i86op_mov_word_CX_IMM(PC_ENV *m)\r |
| 3551 | {\r |
| 3552 | uint16 imm;\r |
| 3553 | imm = fetch_word_imm(m);\r |
| 3554 | m->R_CX = imm;\r |
| 3555 | DECODE_CLEAR_SEGOVR(m);\r |
| 3556 | }\r |
| 3557 | \r |
| 3558 | /*opcode=0xba*/\r |
| 3559 | static void i86op_mov_word_DX_IMM(PC_ENV *m)\r |
| 3560 | {\r |
| 3561 | uint16 imm;\r |
| 3562 | imm = fetch_word_imm(m);\r |
| 3563 | m->R_DX = imm;\r |
| 3564 | DECODE_CLEAR_SEGOVR(m);\r |
| 3565 | }\r |
| 3566 | \r |
| 3567 | /*opcode=0xbb*/\r |
| 3568 | static void i86op_mov_word_BX_IMM(PC_ENV *m)\r |
| 3569 | {\r |
| 3570 | uint16 imm;\r |
| 3571 | imm = fetch_word_imm(m);\r |
| 3572 | m->R_BX = imm;\r |
| 3573 | DECODE_CLEAR_SEGOVR(m);\r |
| 3574 | }\r |
| 3575 | \r |
| 3576 | /*opcode=0xbc*/\r |
| 3577 | static void i86op_mov_word_SP_IMM(PC_ENV *m)\r |
| 3578 | {\r |
| 3579 | uint16 imm;\r |
| 3580 | imm = fetch_word_imm(m);\r |
| 3581 | m->R_SP = imm;\r |
| 3582 | DECODE_CLEAR_SEGOVR(m);\r |
| 3583 | }\r |
| 3584 | \r |
| 3585 | /*opcode=0xbd*/\r |
| 3586 | static void i86op_mov_word_BP_IMM(PC_ENV *m)\r |
| 3587 | {\r |
| 3588 | uint16 imm;\r |
| 3589 | imm = fetch_word_imm(m);\r |
| 3590 | m->R_BP = imm;\r |
| 3591 | DECODE_CLEAR_SEGOVR(m);\r |
| 3592 | }\r |
| 3593 | \r |
| 3594 | /*opcode=0xbe*/\r |
| 3595 | static void i86op_mov_word_SI_IMM(PC_ENV *m)\r |
| 3596 | {\r |
| 3597 | uint16 imm;\r |
| 3598 | imm = fetch_word_imm(m);\r |
| 3599 | m->R_SI = imm;\r |
| 3600 | DECODE_CLEAR_SEGOVR(m);\r |
| 3601 | }\r |
| 3602 | \r |
| 3603 | /*opcode=0xbf*/\r |
| 3604 | static void i86op_mov_word_DI_IMM(PC_ENV *m)\r |
| 3605 | {\r |
| 3606 | uint16 imm;\r |
| 3607 | imm = fetch_word_imm(m);\r |
| 3608 | m->R_DI = imm;\r |
| 3609 | DECODE_CLEAR_SEGOVR(m);\r |
| 3610 | }\r |
| 3611 | \r |
| 3612 | /* c0 === ILLEGAL OPERAND */\r |
| 3613 | /* c1 === ILLEGAL OPERAND */\r |
| 3614 | \r |
| 3615 | /*opcode=0xc2*/\r |
| 3616 | static void i86op_ret_near_IMM(PC_ENV *m)\r |
| 3617 | {\r |
| 3618 | uint16 imm;\r |
| 3619 | imm = fetch_word_imm(m);\r |
| 3620 | m->R_IP = pop_word(m);\r |
| 3621 | m->R_SP += imm;\r |
| 3622 | DECODE_CLEAR_SEGOVR(m);\r |
| 3623 | }\r |
| 3624 | \r |
| 3625 | /*opcode=0xc3*/\r |
| 3626 | static void i86op_ret_near(PC_ENV *m)\r |
| 3627 | {\r |
| 3628 | m->R_IP = pop_word(m);\r |
| 3629 | DECODE_CLEAR_SEGOVR(m);\r |
| 3630 | }\r |
| 3631 | \r |
| 3632 | /*opcode=0xc4*/\r |
| 3633 | static void i86op_les_R_IMM(PC_ENV *m)\r |
| 3634 | {\r |
| 3635 | uint16 mod,rh,rl;\r |
| 3636 | uint16 *dstreg;\r |
| 3637 | uint16 srcoffset;\r |
| 3638 | FETCH_DECODE_MODRM(m,mod,rh,rl);\r |
| 3639 | switch (mod)\r |
| 3640 | {\r |
| 3641 | case 0:\r |
| 3642 | dstreg = DECODE_RM_WORD_REGISTER(m,rh);\r |
| 3643 | srcoffset=decode_rm00_address(m,rl);\r |
| 3644 | *dstreg = fetch_data_word(m,srcoffset);\r |
| 3645 | m->R_ES = fetch_data_word(m,srcoffset+2);\r |
| 3646 | break;\r |
| 3647 | case 1:\r |
| 3648 | dstreg = DECODE_RM_WORD_REGISTER(m,rh);\r |
| 3649 | srcoffset=decode_rm01_address(m,rl);\r |
| 3650 | *dstreg = fetch_data_word(m,srcoffset);\r |
| 3651 | m->R_ES = fetch_data_word(m,srcoffset+2);\r |
| 3652 | break;\r |
| 3653 | case 2:\r |
| 3654 | dstreg = DECODE_RM_WORD_REGISTER(m,rh);\r |
| 3655 | srcoffset=decode_rm10_address(m,rl);\r |
| 3656 | *dstreg = fetch_data_word(m,srcoffset);\r |
| 3657 | m->R_ES = fetch_data_word(m,srcoffset+2);\r |
| 3658 | break;\r |
| 3659 | case 3: /* register to register */\r |
| 3660 | /* UNDEFINED! */\r |
| 3661 | ;\r |
| 3662 | }\r |
| 3663 | DECODE_CLEAR_SEGOVR(m);\r |
| 3664 | }\r |
| 3665 | \r |
| 3666 | /*opcode=0xc5*/\r |
| 3667 | static void i86op_lds_R_IMM(PC_ENV *m)\r |
| 3668 | {\r |
| 3669 | uint16 mod,rh,rl;\r |
| 3670 | uint16 *dstreg;\r |
| 3671 | uint16 srcoffset;\r |
| 3672 | FETCH_DECODE_MODRM(m,mod,rh,rl);\r |
| 3673 | switch (mod)\r |
| 3674 | {\r |
| 3675 | case 0:\r |
| 3676 | dstreg = DECODE_RM_WORD_REGISTER(m,rh);\r |
| 3677 | srcoffset=decode_rm00_address(m,rl);\r |
| 3678 | *dstreg = fetch_data_word(m,srcoffset);\r |
| 3679 | m->R_DS = fetch_data_word(m,srcoffset+2);\r |
| 3680 | break;\r |
| 3681 | case 1:\r |
| 3682 | dstreg = DECODE_RM_WORD_REGISTER(m,rh);\r |
| 3683 | srcoffset=decode_rm01_address(m,rl);\r |
| 3684 | *dstreg = fetch_data_word(m,srcoffset);\r |
| 3685 | m->R_DS = fetch_data_word(m,srcoffset+2);\r |
| 3686 | break;\r |
| 3687 | case 2:\r |
| 3688 | dstreg = DECODE_RM_WORD_REGISTER(m,rh);\r |
| 3689 | srcoffset=decode_rm10_address(m,rl);\r |
| 3690 | *dstreg = fetch_data_word(m,srcoffset);\r |
| 3691 | m->R_DS = fetch_data_word(m,srcoffset+2);\r |
| 3692 | break;\r |
| 3693 | case 3: /* register to register */\r |
| 3694 | /* UNDEFINED! */\r |
| 3695 | ;\r |
| 3696 | }\r |
| 3697 | DECODE_CLEAR_SEGOVR(m);\r |
| 3698 | }\r |
| 3699 | \r |
| 3700 | /*opcode=0xc6*/\r |
| 3701 | static void i86op_mov_byte_RM_IMM(PC_ENV *m)\r |
| 3702 | {\r |
| 3703 | uint16 mod,rl,rh;\r |
| 3704 | uint8 *destreg;\r |
| 3705 | uint16 destoffset;\r |
| 3706 | uint8 imm;\r |
| 3707 | FETCH_DECODE_MODRM(m,mod,rh,rl);\r |
| 3708 | if (rh != 0)\r |
| 3709 | {\r |
| 3710 | halt_sys(m);\r |
| 3711 | }\r |
| 3712 | switch (mod)\r |
| 3713 | {\r |
| 3714 | case 0:\r |
| 3715 | destoffset=decode_rm00_address(m,rl);\r |
| 3716 | imm = fetch_byte_imm(m);\r |
| 3717 | store_data_byte(m,destoffset,imm);\r |
| 3718 | break;\r |
| 3719 | case 1:\r |
| 3720 | destoffset=decode_rm01_address(m,rl);\r |
| 3721 | imm = fetch_byte_imm(m);\r |
| 3722 | store_data_byte(m,destoffset,imm);\r |
| 3723 | break;\r |
| 3724 | case 2:\r |
| 3725 | destoffset=decode_rm10_address(m,rl);\r |
| 3726 | imm = fetch_byte_imm(m);\r |
| 3727 | store_data_byte(m,destoffset,imm);\r |
| 3728 | break;\r |
| 3729 | case 3: /* register to register */\r |
| 3730 | destreg = DECODE_RM_BYTE_REGISTER(m,rl);\r |
| 3731 | imm = fetch_byte_imm(m);\r |
| 3732 | *destreg = imm;\r |
| 3733 | break;\r |
| 3734 | }\r |
| 3735 | DECODE_CLEAR_SEGOVR(m);\r |
| 3736 | }\r |
| 3737 | \r |
| 3738 | /*opcode=0xc7*/\r |
| 3739 | static void i86op_mov_word_RM_IMM(PC_ENV *m)\r |
| 3740 | {\r |
| 3741 | uint16 mod,rl,rh;\r |
| 3742 | uint16 *destreg;\r |
| 3743 | uint16 destoffset;\r |
| 3744 | uint16 imm;\r |
| 3745 | FETCH_DECODE_MODRM(m,mod,rh,rl);\r |
| 3746 | if (rh != 0)\r |
| 3747 | {\r |
| 3748 | halt_sys(m);\r |
| 3749 | }\r |
| 3750 | switch (mod)\r |
| 3751 | {\r |
| 3752 | case 0:\r |
| 3753 | destoffset=decode_rm00_address(m,rl);\r |
| 3754 | imm = fetch_word_imm(m);\r |
| 3755 | store_data_word(m,destoffset,imm);\r |
| 3756 | break;\r |
| 3757 | case 1:\r |
| 3758 | destoffset=decode_rm01_address(m,rl);\r |
| 3759 | imm = fetch_word_imm(m);\r |
| 3760 | store_data_word(m,destoffset,imm);\r |
| 3761 | break;\r |
| 3762 | case 2:\r |
| 3763 | destoffset=decode_rm10_address(m,rl);\r |
| 3764 | imm = fetch_word_imm(m);\r |
| 3765 | store_data_word(m,destoffset,imm);\r |
| 3766 | break;\r |
| 3767 | case 3: /* register to register */\r |
| 3768 | destreg = DECODE_RM_WORD_REGISTER(m,rl);\r |
| 3769 | imm = fetch_word_imm(m);\r |
| 3770 | *destreg = imm;\r |
| 3771 | break;\r |
| 3772 | }\r |
| 3773 | DECODE_CLEAR_SEGOVR(m);\r |
| 3774 | }\r |
| 3775 | \r |
| 3776 | /*opcode=0xc8 ILLEGAL OP*/\r |
| 3777 | /*opcode=0xc9 ILLEGAL OP*/\r |
| 3778 | \r |
| 3779 | /*opcode=0xca*/\r |
| 3780 | static void i86op_ret_far_IMM(PC_ENV *m)\r |
| 3781 | {\r |
| 3782 | uint16 imm;\r |
| 3783 | imm = fetch_word_imm(m);\r |
| 3784 | m->R_IP = pop_word(m);\r |
| 3785 | m->R_CS = pop_word(m);\r |
| 3786 | m->R_SP += imm;\r |
| 3787 | DECODE_CLEAR_SEGOVR(m);\r |
| 3788 | }\r |
| 3789 | \r |
| 3790 | /*opcode=0xcb*/\r |
| 3791 | static void i86op_ret_far(PC_ENV *m)\r |
| 3792 | {\r |
| 3793 | m->R_IP = pop_word(m);\r |
| 3794 | m->R_CS = pop_word(m);\r |
| 3795 | DECODE_CLEAR_SEGOVR(m);\r |
| 3796 | }\r |
| 3797 | \r |
| 3798 | /* opcode=0xcc*/\r |
| 3799 | static void i86op_int3(PC_ENV *m)\r |
| 3800 | {\r |
| 3801 | uint16 tmp;\r |
| 3802 | tmp = (uint16) mem_access_word(m, 3 * 4);\r |
| 3803 | /* access the segment register */\r |
| 3804 | {\r |
| 3805 | tmp = m->R_FLG;\r |
| 3806 | push_word(m, tmp);\r |
| 3807 | CLEAR_FLAG(m, F_IF);\r |
| 3808 | CLEAR_FLAG(m, F_TF);\r |
| 3809 | /* [JCE] If we're interrupting between a segment override (or REP override)\r |
| 3810 | * and the following instruction, decrease IP to get back to the prefix */\r |
| 3811 | if (m->sysmode & (SYSMODE_SEGMASK |\r |
| 3812 | SYSMODE_PREFIX_REPE |\r |
| 3813 | SYSMODE_PREFIX_REPNE))\r |
| 3814 | {\r |
| 3815 | --m->R_IP;\r |
| 3816 | }\r |
| 3817 | push_word(m, m->R_CS);\r |
| 3818 | push_word(m, m->R_IP);\r |
| 3819 | /* [JCE] CS and IP were the wrong way round... */\r |
| 3820 | tmp = mem_access_word(m, 3 * 4);\r |
| 3821 | m->R_IP = tmp;\r |
| 3822 | tmp = mem_access_word(m, 3 * 4 + 2);\r |
| 3823 | m->R_CS = tmp;\r |
| 3824 | }\r |
| 3825 | DECODE_CLEAR_SEGOVR(m);\r |
| 3826 | }\r |
| 3827 | \r |
| 3828 | /* opcode=0xcd*/\r |
| 3829 | static void i86op_int_IMM(PC_ENV *m)\r |
| 3830 | {\r |
| 3831 | uint16 tmp;\r |
| 3832 | uint8 intnum;\r |
| 3833 | intnum = fetch_byte_imm(m);\r |
| 3834 | tmp = mem_access_word(m, intnum * 4);\r |
| 3835 | {\r |
| 3836 | tmp = m->R_FLG;\r |
| 3837 | push_word(m, tmp);\r |
| 3838 | CLEAR_FLAG(m, F_IF);\r |
| 3839 | CLEAR_FLAG(m, F_TF);\r |
| 3840 | /* [JCE] If we're interrupting between a segment override (or REP override)\r |
| 3841 | * and the following instruction, decrease IP to get back to the prefix */\r |
| 3842 | if (m->sysmode & (SYSMODE_SEGMASK |\r |
| 3843 | SYSMODE_PREFIX_REPE |\r |
| 3844 | SYSMODE_PREFIX_REPNE))\r |
| 3845 | {\r |
| 3846 | --m->R_IP;\r |
| 3847 | }\r |
| 3848 | push_word(m, m->R_CS);\r |
| 3849 | push_word(m, m->R_IP);\r |
| 3850 | /* [JCE] CS and IP were the wrong way round... */\r |
| 3851 | tmp = mem_access_word(m, intnum * 4);\r |
| 3852 | m->R_IP = tmp;\r |
| 3853 | tmp = mem_access_word(m, intnum * 4 + 2);\r |
| 3854 | m->R_CS = tmp;\r |
| 3855 | }\r |
| 3856 | DECODE_CLEAR_SEGOVR(m);\r |
| 3857 | }\r |
| 3858 | \r |
| 3859 | /* opcode=0xce*/\r |
| 3860 | static void i86op_into(PC_ENV *m)\r |
| 3861 | {\r |
| 3862 | uint16 tmp;\r |
| 3863 | if (ACCESS_FLAG(m,F_OF))\r |
| 3864 | {\r |
| 3865 | tmp = mem_access_word(m, 4 * 4);\r |
| 3866 | {\r |
| 3867 | tmp = m->R_FLG;\r |
| 3868 | push_word(m, tmp);\r |
| 3869 | CLEAR_FLAG(m, F_IF);\r |
| 3870 | CLEAR_FLAG(m, F_TF);\r |
| 3871 | /* [JCE] If we're interrupting between a segment override (or REP override)\r |
| 3872 | * and the following instruction, decrease IP to get back to the prefix */\r |
| 3873 | if (m->sysmode & (SYSMODE_SEGMASK |\r |
| 3874 | SYSMODE_PREFIX_REPE |\r |
| 3875 | SYSMODE_PREFIX_REPNE))\r |
| 3876 | {\r |
| 3877 | --m->R_IP;\r |
| 3878 | }\r |
| 3879 | push_word(m, m->R_CS);\r |
| 3880 | push_word(m, m->R_IP);\r |
| 3881 | /* [JCE] CS and IP were the wrong way round... */\r |
| 3882 | tmp = mem_access_word(m, 4 * 4);\r |
| 3883 | m->R_IP = tmp;\r |
| 3884 | tmp = mem_access_word(m, 4 * 4 + 2);\r |
| 3885 | m->R_CS = tmp;\r |
| 3886 | }\r |
| 3887 | }\r |
| 3888 | DECODE_CLEAR_SEGOVR(m);\r |
| 3889 | }\r |
| 3890 | \r |
| 3891 | /* opcode=0xcf*/\r |
| 3892 | static void i86op_iret(PC_ENV *m)\r |
| 3893 | {\r |
| 3894 | m->R_IP = pop_word(m);\r |
| 3895 | m->R_CS = pop_word(m);\r |
| 3896 | m->R_FLG = pop_word(m);\r |
| 3897 | DECODE_CLEAR_SEGOVR(m);\r |
| 3898 | }\r |
| 3899 | \r |
| 3900 | static uint8 (*opcD0_byte_operation[])(PC_ENV *m,uint8 d, uint8 s) =\r |
| 3901 | /* used by opcodes d0 and d2. */\r |
| 3902 | {\r |
| 3903 | rol_byte,\r |
| 3904 | ror_byte,\r |
| 3905 | rcl_byte,\r |
| 3906 | rcr_byte,\r |
| 3907 | shl_byte,\r |
| 3908 | shr_byte,\r |
| 3909 | shl_byte, /* sal_byte === shl_byte by definition */\r |
| 3910 | sar_byte,\r |
| 3911 | };\r |
| 3912 | \r |
| 3913 | /* opcode=0xd0*/\r |
| 3914 | static void i86op_opcD0_byte_RM_1(PC_ENV *m)\r |
| 3915 | {\r |
| 3916 | uint16 mod,rl,rh;\r |
| 3917 | uint8 *destreg;\r |
| 3918 | uint16 destoffset;\r |
| 3919 | uint8 destval;\r |
| 3920 | /* Yet another weirdo special case instruction format. Part of the\r |
| 3921 | opcode held below in "RH". Doubly nested case would\r |
| 3922 | result, except that the decoded instruction\r |
| 3923 | */\r |
| 3924 | FETCH_DECODE_MODRM(m,mod,rh,rl);\r |
| 3925 | /* know operation, decode the mod byte to find the addressing\r |
| 3926 | mode. */\r |
| 3927 | switch (mod)\r |
| 3928 | {\r |
| 3929 | case 0:\r |
| 3930 | destoffset=decode_rm00_address(m,rl);\r |
| 3931 | destval = fetch_data_byte(m,destoffset);\r |
| 3932 | destval = (*opcD0_byte_operation[rh])(m, destval,1);\r |
| 3933 | store_data_byte(m,destoffset,destval);\r |
| 3934 | break;\r |
| 3935 | case 1:\r |
| 3936 | destoffset=decode_rm01_address(m,rl);\r |
| 3937 | destval = fetch_data_byte(m,destoffset);\r |
| 3938 | destval = (*opcD0_byte_operation[rh])(m, destval, 1);\r |
| 3939 | store_data_byte(m,destoffset,destval);\r |
| 3940 | break;\r |
| 3941 | case 2:\r |
| 3942 | destoffset=decode_rm10_address(m,rl);\r |
| 3943 | destval = fetch_data_byte(m,destoffset);\r |
| 3944 | destval = (*opcD0_byte_operation[rh])(m, destval, 1);\r |
| 3945 | store_data_byte(m,destoffset,destval);\r |
| 3946 | break;\r |
| 3947 | case 3: /* register to register */\r |
| 3948 | destreg = DECODE_RM_BYTE_REGISTER(m,rl);\r |
| 3949 | destval = (*opcD0_byte_operation[rh])(m, *destreg, 1);\r |
| 3950 | *destreg = destval;\r |
| 3951 | break;\r |
| 3952 | }\r |
| 3953 | DECODE_CLEAR_SEGOVR(m);\r |
| 3954 | }\r |
| 3955 | \r |
| 3956 | static uint16 (*opcD1_word_operation[])(PC_ENV *m,uint16 s,uint16 d) =\r |
| 3957 | /* used by opcodes d1 and d3. */\r |
| 3958 | { rol_word,\r |
| 3959 | ror_word,\r |
| 3960 | rcl_word,\r |
| 3961 | rcr_word,\r |
| 3962 | shl_word,\r |
| 3963 | shr_word,\r |
| 3964 | shl_word, /* sal_byte === shl_byte by definition */\r |
| 3965 | sar_word,\r |
| 3966 | };\r |
| 3967 | \r |
| 3968 | /* opcode=0xd1*/\r |
| 3969 | static void i86op_opcD1_word_RM_1(PC_ENV *m)\r |
| 3970 | {\r |
| 3971 | uint16 mod,rl,rh;\r |
| 3972 | uint16 *destreg;\r |
| 3973 | uint16 destoffset;\r |
| 3974 | uint16 destval;\r |
| 3975 | /* Yet another weirdo special case instruction format. Part of the\r |
| 3976 | opcode held below in "RH". Doubly nested case would\r |
| 3977 | result, except that the decoded instruction\r |
| 3978 | */\r |
| 3979 | FETCH_DECODE_MODRM(m,mod,rh,rl);\r |
| 3980 | /* know operation, decode the mod byte to find the addressing\r |
| 3981 | mode. */\r |
| 3982 | switch (mod)\r |
| 3983 | {\r |
| 3984 | case 0:\r |
| 3985 | destoffset=decode_rm00_address(m,rl);\r |
| 3986 | destval = fetch_data_word(m,destoffset);\r |
| 3987 | destval = (*opcD1_word_operation[rh])(m, destval,1);\r |
| 3988 | store_data_word(m,destoffset,destval);\r |
| 3989 | break;\r |
| 3990 | case 1:\r |
| 3991 | destoffset=decode_rm01_address(m,rl);\r |
| 3992 | destval = fetch_data_word(m,destoffset);\r |
| 3993 | destval = (*opcD1_word_operation[rh])(m, destval, 1);\r |
| 3994 | store_data_word(m,destoffset,destval);\r |
| 3995 | break;\r |
| 3996 | case 2:\r |
| 3997 | destoffset=decode_rm10_address(m,rl);\r |
| 3998 | destval = fetch_data_word(m,destoffset);\r |
| 3999 | destval = (*opcD1_word_operation[rh])(m, destval, 1);\r |
| 4000 | store_data_word(m,destoffset,destval);\r |
| 4001 | break;\r |
| 4002 | case 3: /* register to register */\r |
| 4003 | destreg = DECODE_RM_WORD_REGISTER(m,rl);\r |
| 4004 | destval = (*opcD1_word_operation[rh])(m, *destreg, 1);\r |
| 4005 | *destreg = destval;\r |
| 4006 | break;\r |
| 4007 | }\r |
| 4008 | DECODE_CLEAR_SEGOVR(m);\r |
| 4009 | }\r |
| 4010 | \r |
| 4011 | /* opcode=0xd2*/\r |
| 4012 | static void i86op_opcD2_byte_RM_CL(PC_ENV *m)\r |
| 4013 | {\r |
| 4014 | uint16 mod,rl,rh;\r |
| 4015 | uint8 *destreg;\r |
| 4016 | uint16 destoffset;\r |
| 4017 | uint8 destval;\r |
| 4018 | uint8 amt;\r |
| 4019 | /* Yet another weirdo special case instruction format. Part of the\r |
| 4020 | opcode held below in "RH". Doubly nested case would\r |
| 4021 | result, except that the decoded instruction\r |
| 4022 | */\r |
| 4023 | FETCH_DECODE_MODRM(m,mod,rh,rl);\r |
| 4024 | amt = m->R_CL;\r |
| 4025 | /* know operation, decode the mod byte to find the addressing\r |
| 4026 | mode. */\r |
| 4027 | switch (mod)\r |
| 4028 | {\r |
| 4029 | case 0:\r |
| 4030 | destoffset=decode_rm00_address(m,rl);\r |
| 4031 | destval = fetch_data_byte(m,destoffset);\r |
| 4032 | destval = (*opcD0_byte_operation[rh])(m, destval,amt);\r |
| 4033 | store_data_byte(m,destoffset,destval);\r |
| 4034 | break;\r |
| 4035 | case 1:\r |
| 4036 | destoffset=decode_rm01_address(m,rl);\r |
| 4037 | destval = fetch_data_byte(m,destoffset);\r |
| 4038 | destval = (*opcD0_byte_operation[rh])(m, destval, amt);\r |
| 4039 | store_data_byte(m,destoffset,destval);\r |
| 4040 | break;\r |
| 4041 | case 2:\r |
| 4042 | destoffset=decode_rm10_address(m,rl);\r |
| 4043 | destval = fetch_data_byte(m,destoffset);\r |
| 4044 | destval = (*opcD0_byte_operation[rh])(m, destval, amt);\r |
| 4045 | store_data_byte(m,destoffset,destval);\r |
| 4046 | break;\r |
| 4047 | case 3: /* register to register */\r |
| 4048 | destreg = DECODE_RM_BYTE_REGISTER(m,rl);\r |
| 4049 | destval = (*opcD0_byte_operation[rh])(m, *destreg, amt);\r |
| 4050 | *destreg = destval;\r |
| 4051 | break;\r |
| 4052 | }\r |
| 4053 | DECODE_CLEAR_SEGOVR(m);\r |
| 4054 | }\r |
| 4055 | \r |
| 4056 | /* opcode=0xd3*/\r |
| 4057 | static void i86op_opcD3_word_RM_CL(PC_ENV *m)\r |
| 4058 | {\r |
| 4059 | uint16 mod,rl,rh;\r |
| 4060 | uint16 *destreg;\r |
| 4061 | uint16 destoffset;\r |
| 4062 | uint16 destval;\r |
| 4063 | uint8 amt;\r |
| 4064 | /* Yet another weirdo special case instruction format. Part of the\r |
| 4065 | opcode held below in "RH". Doubly nested case would\r |
| 4066 | result, except that the decoded instruction\r |
| 4067 | */\r |
| 4068 | FETCH_DECODE_MODRM(m,mod,rh,rl);\r |
| 4069 | amt = m->R_CL;\r |
| 4070 | /* know operation, decode the mod byte to find the addressing\r |
| 4071 | mode. */\r |
| 4072 | switch (mod)\r |
| 4073 | {\r |
| 4074 | case 0:\r |
| 4075 | destoffset=decode_rm00_address(m,rl);\r |
| 4076 | destval = fetch_data_word(m,destoffset);\r |
| 4077 | destval = (*opcD1_word_operation[rh])(m, destval, amt);\r |
| 4078 | store_data_word(m,destoffset,destval);\r |
| 4079 | break;\r |
| 4080 | case 1:\r |
| 4081 | destoffset=decode_rm01_address(m,rl);\r |
| 4082 | destval = fetch_data_word(m,destoffset);\r |
| 4083 | destval = (*opcD1_word_operation[rh])(m, destval, amt);\r |
| 4084 | store_data_word(m,destoffset,destval);\r |
| 4085 | break;\r |
| 4086 | case 2:\r |
| 4087 | destoffset=decode_rm10_address(m,rl);\r |
| 4088 | destval = fetch_data_word(m,destoffset);\r |
| 4089 | destval = (*opcD1_word_operation[rh])(m, destval, amt);\r |
| 4090 | store_data_word(m,destoffset,destval);\r |
| 4091 | break;\r |
| 4092 | case 3: /* register to register */\r |
| 4093 | destreg = DECODE_RM_WORD_REGISTER(m,rl);\r |
| 4094 | *destreg = (*opcD1_word_operation[rh])(m, *destreg, amt);\r |
| 4095 | break;\r |
| 4096 | }\r |
| 4097 | DECODE_CLEAR_SEGOVR(m);\r |
| 4098 | }\r |
| 4099 | \r |
| 4100 | static void sys_fatal(int error, char *fmt, ...)\r |
| 4101 | {\r |
| 4102 | va_list p;\r |
| 4103 | va_start(p, fmt);\r |
| 4104 | fprintf(stderr, "Fatal error: ");\r |
| 4105 | if (error != 0)\r |
| 4106 | {\r |
| 4107 | fprintf(stderr, "<%d>",error);\r |
| 4108 | fprintf(stderr,"%s",strerror(error));\r |
| 4109 | }\r |
| 4110 | vfprintf(stderr, fmt, p);\r |
| 4111 | va_end(p);\r |
| 4112 | fprintf(stderr, NLP "Exiting..." NLP);\r |
| 4113 | exit(1);\r |
| 4114 | }\r |
| 4115 | \r |
| 4116 | /* opcode=0xd4*/\r |
| 4117 | static void i86op_aam(PC_ENV *m)\r |
| 4118 | { uint8 a;\r |
| 4119 | a = fetch_byte_imm(m); /* this is a stupid encoding. */\r |
| 4120 | if (a != 10) sys_fatal(0,"error decoding aam" NLP);\r |
| 4121 | /* note the type change here --- returning AL and AH in AX. */\r |
| 4122 | m->R_AX = aam_word(m,m->R_AL);\r |
| 4123 | DECODE_CLEAR_SEGOVR(m);\r |
| 4124 | }\r |
| 4125 | \r |
| 4126 | /* opcode=0xd5*/\r |
| 4127 | static void i86op_aad(PC_ENV *m)\r |
| 4128 | { uint8 a;\r |
| 4129 | a = fetch_byte_imm(m);\r |
| 4130 | m->R_AX = aad_word(m,m->R_AX);\r |
| 4131 | DECODE_CLEAR_SEGOVR(m);\r |
| 4132 | }\r |
| 4133 | \r |
| 4134 | /* opcode=0xd6 ILLEGAL OPCODE */\r |
| 4135 | \r |
| 4136 | /* opcode=0xd7 */\r |
| 4137 | static void i86op_xlat(PC_ENV *m)\r |
| 4138 | {\r |
| 4139 | uint16 addr;\r |
| 4140 | addr = m->R_BX + (uint8)m->R_AL;\r |
| 4141 | m->R_AL = fetch_data_byte(m,addr);\r |
| 4142 | DECODE_CLEAR_SEGOVR(m);\r |
| 4143 | }\r |
| 4144 | \r |
| 4145 | /*opcode=0xe0*/\r |
| 4146 | static void i86op_loopne(PC_ENV *m)\r |
| 4147 | {\r |
| 4148 | int16 ip;\r |
| 4149 | ip = (int8)fetch_byte_imm(m);\r |
| 4150 | ip += (int16)m->R_IP;\r |
| 4151 | m->R_CX -= 1;\r |
| 4152 | if (m->R_CX != 0 && !ACCESS_FLAG(m,F_ZF)) /* CX != 0 and !ZF */\r |
| 4153 | m->R_IP = ip;\r |
| 4154 | DECODE_CLEAR_SEGOVR(m);\r |
| 4155 | }\r |
| 4156 | \r |
| 4157 | /*opcode=0xe1*/\r |
| 4158 | static void i86op_loope(PC_ENV *m)\r |
| 4159 | {\r |
| 4160 | int16 ip;\r |
| 4161 | ip = (int8)fetch_byte_imm(m);\r |
| 4162 | ip += (int16)m->R_IP;\r |
| 4163 | m->R_CX -= 1;\r |
| 4164 | if (m->R_CX != 0 && ACCESS_FLAG(m,F_ZF)) /* CX != 0 and ZF */\r |
| 4165 | m->R_IP = ip;\r |
| 4166 | DECODE_CLEAR_SEGOVR(m);\r |
| 4167 | }\r |
| 4168 | \r |
| 4169 | /*opcode=0xe2*/\r |
| 4170 | static void i86op_loop(PC_ENV *m)\r |
| 4171 | {\r |
| 4172 | int16 ip;\r |
| 4173 | ip = (int8)fetch_byte_imm(m);\r |
| 4174 | ip += (int16)m->R_IP;\r |
| 4175 | m->R_CX -= 1;\r |
| 4176 | if (m->R_CX != 0)\r |
| 4177 | m->R_IP = ip;\r |
| 4178 | DECODE_CLEAR_SEGOVR(m);\r |
| 4179 | }\r |
| 4180 | \r |
| 4181 | /*opcode=0xe3*/\r |
| 4182 | static void i86op_jcxz(PC_ENV *m)\r |
| 4183 | {\r |
| 4184 | int16 offset,target;\r |
| 4185 | /* jump to byte offset if overflow flag is set */\r |
| 4186 | offset = (int8)fetch_byte_imm(m); /* sign extended ??? */\r |
| 4187 | target = (int16)m->R_IP + offset;\r |
| 4188 | if (m->R_CX == 0)\r |
| 4189 | m->R_IP = target;\r |
| 4190 | DECODE_CLEAR_SEGOVR(m);\r |
| 4191 | }\r |
| 4192 | \r |
| 4193 | /*opcode=0xe4*/\r |
| 4194 | static void i86op_in_byte_AL_IMM(PC_ENV *m)\r |
| 4195 | {\r |
| 4196 | uint8 port;\r |
| 4197 | port = (uint8)fetch_byte_imm(m);\r |
| 4198 | m->R_AL = in(port);\r |
| 4199 | DECODE_CLEAR_SEGOVR(m);\r |
| 4200 | }\r |
| 4201 | \r |
| 4202 | /*opcode=0xe5*/\r |
| 4203 | static void i86op_in_word_AX_IMM(PC_ENV *m)\r |
| 4204 | {\r |
| 4205 | uint8 port;\r |
| 4206 | port = (uint8)fetch_byte_imm(m);\r |
| 4207 | m->R_AX = in(port);\r |
| 4208 | DECODE_CLEAR_SEGOVR(m);\r |
| 4209 | }\r |
| 4210 | \r |
| 4211 | /*opcode=0xe6*/\r |
| 4212 | static void i86op_out_byte_IMM_AL(PC_ENV *m)\r |
| 4213 | {\r |
| 4214 | uint8 port;\r |
| 4215 | port = (uint8)fetch_byte_imm(m);\r |
| 4216 | out(port, m->R_AL);\r |
| 4217 | DECODE_CLEAR_SEGOVR(m);\r |
| 4218 | }\r |
| 4219 | \r |
| 4220 | /*opcode=0xe7*/\r |
| 4221 | static void i86op_out_word_IMM_AX(PC_ENV *m)\r |
| 4222 | {\r |
| 4223 | uint8 port;\r |
| 4224 | port = (uint8)fetch_byte_imm(m);\r |
| 4225 | out(port, m->R_AX);\r |
| 4226 | DECODE_CLEAR_SEGOVR(m);\r |
| 4227 | }\r |
| 4228 | \r |
| 4229 | /*opcode=0xe8*/\r |
| 4230 | static void i86op_call_near_IMM(PC_ENV *m)\r |
| 4231 | {\r |
| 4232 | int16 ip;\r |
| 4233 | /* weird. Thought this was a signed disp! */\r |
| 4234 | ip = (int16)fetch_word_imm(m);\r |
| 4235 | ip += (int16)m->R_IP; /* CHECK SIGN */\r |
| 4236 | push_word(m,m->R_IP);\r |
| 4237 | m->R_IP = ip;\r |
| 4238 | DECODE_CLEAR_SEGOVR(m);\r |
| 4239 | }\r |
| 4240 | \r |
| 4241 | /*opcode=0xe9*/\r |
| 4242 | static void i86op_jump_near_IMM(PC_ENV *m)\r |
| 4243 | {\r |
| 4244 | int ip;\r |
| 4245 | /* weird. Thought this was a signed disp too! */\r |
| 4246 | ip = (int16)fetch_word_imm(m);\r |
| 4247 | ip += (int16)m->R_IP; /* CHECK SIGN */\r |
| 4248 | m->R_IP = ip;\r |
| 4249 | DECODE_CLEAR_SEGOVR(m);\r |
| 4250 | }\r |
| 4251 | \r |
| 4252 | /*opcode=0xea*/\r |
| 4253 | static void i86op_jump_far_IMM(PC_ENV *m)\r |
| 4254 | {\r |
| 4255 | uint16 cs,ip;\r |
| 4256 | ip = fetch_word_imm(m);\r |
| 4257 | cs = fetch_word_imm(m);\r |
| 4258 | m->R_IP = ip;\r |
| 4259 | m->R_CS = cs;\r |
| 4260 | DECODE_CLEAR_SEGOVR(m);\r |
| 4261 | }\r |
| 4262 | \r |
| 4263 | /*opcode=0xeb*/\r |
| 4264 | static void i86op_jump_byte_IMM(PC_ENV *m)\r |
| 4265 | {\r |
| 4266 | int8 offset;\r |
| 4267 | uint16 target;\r |
| 4268 | offset = (int8) fetch_byte_imm(m); /* CHECK */\r |
| 4269 | /* printf("jump byte imm offset=%d\n",offset);*/\r |
| 4270 | target = (int16) m->R_IP + offset;\r |
| 4271 | m->R_IP = target;\r |
| 4272 | DECODE_CLEAR_SEGOVR(m);\r |
| 4273 | }\r |
| 4274 | \r |
| 4275 | /*opcode=0xec*/\r |
| 4276 | static void i86op_in_byte_AL_DX(PC_ENV *m)\r |
| 4277 | {\r |
| 4278 | m->R_AL = in(m->R_DX);\r |
| 4279 | DECODE_CLEAR_SEGOVR(m);\r |
| 4280 | }\r |
| 4281 | \r |
| 4282 | /*opcode=0xed*/\r |
| 4283 | static void i86op_in_word_AX_DX(PC_ENV *m)\r |
| 4284 | {\r |
| 4285 | m->R_AX = in(m->R_DX);\r |
| 4286 | DECODE_CLEAR_SEGOVR(m);\r |
| 4287 | }\r |
| 4288 | \r |
| 4289 | /*opcode=0xee*/\r |
| 4290 | static void i86op_out_byte_DX_AL(PC_ENV *m)\r |
| 4291 | {\r |
| 4292 | out(m->R_DX, m->R_AL);\r |
| 4293 | DECODE_CLEAR_SEGOVR(m);\r |
| 4294 | }\r |
| 4295 | \r |
| 4296 | /*opcode=0xef*/\r |
| 4297 | static void i86op_out_word_DX_AX(PC_ENV *m)\r |
| 4298 | {\r |
| 4299 | out(m->R_DX, m->R_AX);\r |
| 4300 | DECODE_CLEAR_SEGOVR(m);\r |
| 4301 | }\r |
| 4302 | \r |
| 4303 | /*opcode=0xf0*/\r |
| 4304 | static void i86op_lock(PC_ENV *m)\r |
| 4305 | {\r |
| 4306 | DECODE_CLEAR_SEGOVR(m);\r |
| 4307 | }\r |
| 4308 | \r |
| 4309 | /*opcode=0xf1 ILLEGAL OPERATION*/\r |
| 4310 | \r |
| 4311 | /*opcode=0xf2*/\r |
| 4312 | static void i86op_repne(PC_ENV *m)\r |
| 4313 | {\r |
| 4314 | m->sysmode |= SYSMODE_PREFIX_REPNE;\r |
| 4315 | DECODE_CLEAR_SEGOVR(m);\r |
| 4316 | }\r |
| 4317 | \r |
| 4318 | /*opcode=0xf3*/\r |
| 4319 | static void i86op_repe(PC_ENV *m)\r |
| 4320 | {\r |
| 4321 | m->sysmode |= SYSMODE_PREFIX_REPE;\r |
| 4322 | DECODE_CLEAR_SEGOVR(m);\r |
| 4323 | }\r |
| 4324 | \r |
| 4325 | /*opcode=0xf4*/\r |
| 4326 | static void i86op_halt(PC_ENV *m)\r |
| 4327 | {\r |
| 4328 | halt_sys(m);\r |
| 4329 | DECODE_CLEAR_SEGOVR(m);\r |
| 4330 | }\r |
| 4331 | \r |
| 4332 | /*opcode=0xf5*/\r |
| 4333 | static void i86op_cmc(PC_ENV *m)\r |
| 4334 | {\r |
| 4335 | /* complement the carry flag. */\r |
| 4336 | TOGGLE_FLAG(m,F_CF);\r |
| 4337 | DECODE_CLEAR_SEGOVR(m);\r |
| 4338 | }\r |
| 4339 | \r |
| 4340 | /*opcode=0xf6*/\r |
| 4341 | static void i86op_opcF6_byte_RM(PC_ENV *m)\r |
| 4342 | {\r |
| 4343 | uint16 mod,rl,rh;\r |
| 4344 | uint8 *destreg;\r |
| 4345 | uint16 destoffset;\r |
| 4346 | uint8 destval,srcval;\r |
| 4347 | /* long, drawn out code follows. Double switch for a total\r |
| 4348 | of 32 cases. */\r |
| 4349 | FETCH_DECODE_MODRM(m,mod,rh,rl);\r |
| 4350 | switch (mod)\r |
| 4351 | {\r |
| 4352 | case 0: /* mod=00 */\r |
| 4353 | switch(rh)\r |
| 4354 | {\r |
| 4355 | case 0: /* test byte imm */\r |
| 4356 | destoffset=decode_rm00_address(m,rl);\r |
| 4357 | srcval = fetch_byte_imm(m);\r |
| 4358 | destval = fetch_data_byte(m,destoffset);\r |
| 4359 | test_byte(m, destval, srcval);\r |
| 4360 | break;\r |
| 4361 | case 1:\r |
| 4362 | halt_sys(m);\r |
| 4363 | break;\r |
| 4364 | case 2:\r |
| 4365 | destoffset=decode_rm00_address(m,rl);\r |
| 4366 | destval = fetch_data_byte(m,destoffset);\r |
| 4367 | destval = not_byte(m, destval);\r |
| 4368 | store_data_byte(m,destoffset,destval);\r |
| 4369 | break;\r |
| 4370 | case 3:\r |
| 4371 | destoffset=decode_rm00_address(m,rl);\r |
| 4372 | destval = fetch_data_byte(m,destoffset);\r |
| 4373 | destval = neg_byte(m, destval);\r |
| 4374 | store_data_byte(m,destoffset,destval);\r |
| 4375 | break;\r |
| 4376 | case 4:\r |
| 4377 | destoffset=decode_rm00_address(m,rl);\r |
| 4378 | destval = fetch_data_byte(m,destoffset);\r |
| 4379 | mul_byte(m, destval);\r |
| 4380 | break;\r |
| 4381 | case 5:\r |
| 4382 | destoffset=decode_rm00_address(m,rl);\r |
| 4383 | destval = fetch_data_byte(m,destoffset);\r |
| 4384 | imul_byte(m, destval);\r |
| 4385 | break;\r |
| 4386 | case 6:\r |
| 4387 | destoffset=decode_rm00_address(m,rl);\r |
| 4388 | destval = fetch_data_byte(m,destoffset);\r |
| 4389 | div_byte(m, destval);\r |
| 4390 | break;\r |
| 4391 | case 7:\r |
| 4392 | destoffset=decode_rm00_address(m,rl);\r |
| 4393 | destval = fetch_data_byte(m,destoffset);\r |
| 4394 | idiv_byte(m, destval);\r |
| 4395 | break;\r |
| 4396 | }\r |
| 4397 | break; /* end mod==00 */\r |
| 4398 | case 1: /* mod=01 */\r |
| 4399 | switch(rh)\r |
| 4400 | {\r |
| 4401 | case 0: /* test byte imm */\r |
| 4402 | destoffset=decode_rm01_address(m,rl);\r |
| 4403 | srcval = fetch_byte_imm(m);\r |
| 4404 | destval = fetch_data_byte(m,destoffset);\r |
| 4405 | test_byte(m, destval, srcval);\r |
| 4406 | break;\r |
| 4407 | case 1:\r |
| 4408 | halt_sys(m);\r |
| 4409 | break;\r |
| 4410 | case 2:\r |
| 4411 | destoffset=decode_rm01_address(m,rl);\r |
| 4412 | destval = fetch_data_byte(m,destoffset);\r |
| 4413 | destval = not_byte(m, destval);\r |
| 4414 | store_data_byte(m,destoffset,destval);\r |
| 4415 | break;\r |
| 4416 | case 3:\r |
| 4417 | destoffset=decode_rm01_address(m,rl);\r |
| 4418 | destval = fetch_data_byte(m,destoffset);\r |
| 4419 | destval = neg_byte(m, destval);\r |
| 4420 | store_data_byte(m,destoffset,destval);\r |
| 4421 | break;\r |
| 4422 | case 4:\r |
| 4423 | destoffset=decode_rm01_address(m,rl);\r |
| 4424 | destval = fetch_data_byte(m,destoffset);\r |
| 4425 | mul_byte(m, destval);\r |
| 4426 | break;\r |
| 4427 | case 5:\r |
| 4428 | destoffset=decode_rm01_address(m,rl);\r |
| 4429 | destval = fetch_data_byte(m,destoffset);\r |
| 4430 | imul_byte(m, destval);\r |
| 4431 | break;\r |
| 4432 | case 6:\r |
| 4433 | destoffset=decode_rm01_address(m,rl);\r |
| 4434 | destval = fetch_data_byte(m,destoffset);\r |
| 4435 | div_byte(m, destval);\r |
| 4436 | break;\r |
| 4437 | case 7:\r |
| 4438 | destoffset=decode_rm01_address(m,rl);\r |
| 4439 | destval = fetch_data_byte(m,destoffset);\r |
| 4440 | idiv_byte(m, destval);\r |
| 4441 | break;\r |
| 4442 | }\r |
| 4443 | break; /* end mod==01 */\r |
| 4444 | case 2: /* mod=10 */\r |
| 4445 | switch(rh)\r |
| 4446 | {\r |
| 4447 | case 0: /* test byte imm */\r |
| 4448 | destoffset=decode_rm10_address(m,rl);\r |
| 4449 | srcval = fetch_byte_imm(m);\r |
| 4450 | destval = fetch_data_byte(m,destoffset);\r |
| 4451 | test_byte(m, destval, srcval);\r |
| 4452 | break;\r |
| 4453 | case 1:\r |
| 4454 | halt_sys(m);\r |
| 4455 | break;\r |
| 4456 | case 2:\r |
| 4457 | destoffset=decode_rm10_address(m,rl);\r |
| 4458 | destval = fetch_data_byte(m,destoffset);\r |
| 4459 | destval = not_byte(m, destval);\r |
| 4460 | store_data_byte(m,destoffset,destval);\r |
| 4461 | break;\r |
| 4462 | case 3:\r |
| 4463 | destoffset=decode_rm10_address(m,rl);\r |
| 4464 | destval = fetch_data_byte(m,destoffset);\r |
| 4465 | destval = neg_byte(m, destval);\r |
| 4466 | store_data_byte(m,destoffset,destval);\r |
| 4467 | break;\r |
| 4468 | case 4:\r |
| 4469 | destoffset=decode_rm10_address(m,rl);\r |
| 4470 | destval = fetch_data_byte(m,destoffset);\r |
| 4471 | mul_byte(m, destval);\r |
| 4472 | break;\r |
| 4473 | case 5:\r |
| 4474 | destoffset=decode_rm10_address(m,rl);\r |
| 4475 | destval = fetch_data_byte(m,destoffset);\r |
| 4476 | imul_byte(m, destval);\r |
| 4477 | break;\r |
| 4478 | case 6:\r |
| 4479 | destoffset=decode_rm10_address(m,rl);\r |
| 4480 | destval = fetch_data_byte(m,destoffset);\r |
| 4481 | div_byte(m, destval);\r |
| 4482 | break;\r |
| 4483 | case 7:\r |
| 4484 | destoffset=decode_rm10_address(m,rl);\r |
| 4485 | destval = fetch_data_byte(m,destoffset);\r |
| 4486 | idiv_byte(m, destval);\r |
| 4487 | break;\r |
| 4488 | }\r |
| 4489 | break; /* end mod==10 */\r |
| 4490 | case 3: /* mod=11 */\r |
| 4491 | switch(rh)\r |
| 4492 | {\r |
| 4493 | case 0: /* test byte imm */\r |
| 4494 | destreg=DECODE_RM_BYTE_REGISTER(m,rl);\r |
| 4495 | srcval = fetch_byte_imm(m);\r |
| 4496 | test_byte(m, *destreg, srcval);\r |
| 4497 | break;\r |
| 4498 | case 1:\r |
| 4499 | halt_sys(m);\r |
| 4500 | break;\r |
| 4501 | case 2:\r |
| 4502 | destreg=DECODE_RM_BYTE_REGISTER(m,rl);\r |
| 4503 | *destreg = not_byte(m, *destreg);\r |
| 4504 | break;\r |
| 4505 | case 3:\r |
| 4506 | destreg=DECODE_RM_BYTE_REGISTER(m,rl);\r |
| 4507 | *destreg = neg_byte(m, *destreg);\r |
| 4508 | break;\r |
| 4509 | case 4:\r |
| 4510 | destreg=DECODE_RM_BYTE_REGISTER(m,rl);\r |
| 4511 | mul_byte(m, *destreg); /*!!! */\r |
| 4512 | break;\r |
| 4513 | case 5:\r |
| 4514 | destreg=DECODE_RM_BYTE_REGISTER(m,rl);\r |
| 4515 | imul_byte(m, *destreg);\r |
| 4516 | break;\r |
| 4517 | case 6:\r |
| 4518 | destreg=DECODE_RM_BYTE_REGISTER(m,rl);\r |
| 4519 | div_byte(m, *destreg);\r |
| 4520 | break;\r |
| 4521 | case 7:\r |
| 4522 | destreg=DECODE_RM_BYTE_REGISTER(m,rl);\r |
| 4523 | idiv_byte(m, *destreg);\r |
| 4524 | break;\r |
| 4525 | }\r |
| 4526 | break; /* end mod==11 */\r |
| 4527 | }\r |
| 4528 | DECODE_CLEAR_SEGOVR(m);\r |
| 4529 | }\r |
| 4530 | \r |
| 4531 | /*opcode=0xf7*/\r |
| 4532 | static void i86op_opcF7_word_RM(PC_ENV *m)\r |
| 4533 | {\r |
| 4534 | uint16 mod,rl,rh;\r |
| 4535 | uint16 *destreg;\r |
| 4536 | uint16 destoffset;\r |
| 4537 | uint16 destval,srcval;\r |
| 4538 | /* long, drawn out code follows. Double switch for a total\r |
| 4539 | of 32 cases. */\r |
| 4540 | FETCH_DECODE_MODRM(m,mod,rh,rl);\r |
| 4541 | switch (mod)\r |
| 4542 | {\r |
| 4543 | case 0: /* mod=00 */\r |
| 4544 | switch(rh)\r |
| 4545 | {\r |
| 4546 | case 0: /* test word imm */\r |
| 4547 | destoffset=decode_rm00_address(m,rl);\r |
| 4548 | srcval = fetch_word_imm(m);\r |
| 4549 | destval = fetch_data_word(m,destoffset);\r |
| 4550 | test_word(m, destval, srcval);\r |
| 4551 | break;\r |
| 4552 | case 1:\r |
| 4553 | halt_sys(m);\r |
| 4554 | break;\r |
| 4555 | case 2:\r |
| 4556 | destoffset=decode_rm00_address(m,rl);\r |
| 4557 | destval = fetch_data_word(m,destoffset);\r |
| 4558 | destval = not_word(m, destval);\r |
| 4559 | store_data_word(m,destoffset,destval);\r |
| 4560 | break;\r |
| 4561 | case 3:\r |
| 4562 | destoffset=decode_rm00_address(m,rl);\r |
| 4563 | destval = fetch_data_word(m,destoffset);\r |
| 4564 | destval = neg_word(m, destval);\r |
| 4565 | store_data_word(m,destoffset,destval);\r |
| 4566 | break;\r |
| 4567 | case 4:\r |
| 4568 | destoffset=decode_rm00_address(m,rl);\r |
| 4569 | destval = fetch_data_word(m,destoffset);\r |
| 4570 | mul_word(m, destval);\r |
| 4571 | break;\r |
| 4572 | case 5:\r |
| 4573 | destoffset=decode_rm00_address(m,rl);\r |
| 4574 | destval = fetch_data_word(m,destoffset);\r |
| 4575 | imul_word(m, destval);\r |
| 4576 | break;\r |
| 4577 | case 6:\r |
| 4578 | destoffset=decode_rm00_address(m,rl);\r |
| 4579 | destval = fetch_data_word(m,destoffset);\r |
| 4580 | div_word(m, destval);\r |
| 4581 | break;\r |
| 4582 | case 7:\r |
| 4583 | destoffset=decode_rm00_address(m,rl);\r |
| 4584 | destval = fetch_data_word(m,destoffset);\r |
| 4585 | idiv_word(m, destval);\r |
| 4586 | break;\r |
| 4587 | }\r |
| 4588 | break; /* end mod==00 */\r |
| 4589 | case 1: /* mod=01 */\r |
| 4590 | switch(rh)\r |
| 4591 | {\r |
| 4592 | case 0: /* test word imm */\r |
| 4593 | destoffset=decode_rm01_address(m,rl);\r |
| 4594 | srcval = fetch_word_imm(m);\r |
| 4595 | destval = fetch_data_word(m,destoffset);\r |
| 4596 | test_word(m, destval, srcval);\r |
| 4597 | break;\r |
| 4598 | case 1:\r |
| 4599 | halt_sys(m);\r |
| 4600 | break;\r |
| 4601 | case 2:\r |
| 4602 | destoffset=decode_rm01_address(m,rl);\r |
| 4603 | destval = fetch_data_word(m,destoffset);\r |
| 4604 | destval = not_word(m, destval);\r |
| 4605 | store_data_word(m,destoffset,destval);\r |
| 4606 | break;\r |
| 4607 | case 3:\r |
| 4608 | destoffset=decode_rm01_address(m,rl);\r |
| 4609 | destval = fetch_data_word(m,destoffset);\r |
| 4610 | destval = neg_word(m, destval);\r |
| 4611 | store_data_word(m,destoffset,destval);\r |
| 4612 | break;\r |
| 4613 | case 4:\r |
| 4614 | destoffset=decode_rm01_address(m,rl);\r |
| 4615 | destval = fetch_data_word(m,destoffset);\r |
| 4616 | mul_word(m, destval);\r |
| 4617 | break;\r |
| 4618 | case 5:\r |
| 4619 | destoffset=decode_rm01_address(m,rl);\r |
| 4620 | destval = fetch_data_word(m,destoffset);\r |
| 4621 | imul_word(m, destval);\r |
| 4622 | break;\r |
| 4623 | case 6:\r |
| 4624 | destoffset=decode_rm01_address(m,rl);\r |
| 4625 | destval = fetch_data_word(m,destoffset);\r |
| 4626 | div_word(m, destval);\r |
| 4627 | break;\r |
| 4628 | case 7:\r |
| 4629 | destoffset=decode_rm01_address(m,rl);\r |
| 4630 | destval = fetch_data_word(m,destoffset);\r |
| 4631 | idiv_word(m, destval);\r |
| 4632 | break;\r |
| 4633 | }\r |
| 4634 | break; /* end mod==01 */\r |
| 4635 | case 2: /* mod=10 */\r |
| 4636 | switch(rh)\r |
| 4637 | {\r |
| 4638 | case 0: /* test word imm */\r |
| 4639 | destoffset=decode_rm10_address(m,rl);\r |
| 4640 | srcval = fetch_word_imm(m);\r |
| 4641 | destval = fetch_data_word(m,destoffset);\r |
| 4642 | test_word(m, destval, srcval);\r |
| 4643 | break;\r |
| 4644 | case 1:\r |
| 4645 | halt_sys(m);\r |
| 4646 | break;\r |
| 4647 | case 2:\r |
| 4648 | destoffset=decode_rm10_address(m,rl);\r |
| 4649 | destval = fetch_data_word(m,destoffset);\r |
| 4650 | destval = not_word(m, destval);\r |
| 4651 | store_data_word(m,destoffset,destval);\r |
| 4652 | break;\r |
| 4653 | case 3:\r |
| 4654 | destoffset=decode_rm10_address(m,rl);\r |
| 4655 | destval = fetch_data_word(m,destoffset);\r |
| 4656 | destval = neg_word(m, destval);\r |
| 4657 | store_data_word(m,destoffset,destval);\r |
| 4658 | break;\r |
| 4659 | case 4:\r |
| 4660 | destoffset=decode_rm10_address(m,rl);\r |
| 4661 | destval = fetch_data_word(m,destoffset);\r |
| 4662 | mul_word(m, destval);\r |
| 4663 | break;\r |
| 4664 | case 5:\r |
| 4665 | destoffset=decode_rm10_address(m,rl);\r |
| 4666 | destval = fetch_data_word(m,destoffset);\r |
| 4667 | imul_word(m, destval);\r |
| 4668 | break;\r |
| 4669 | case 6:\r |
| 4670 | destoffset=decode_rm10_address(m,rl);\r |
| 4671 | destval = fetch_data_word(m,destoffset);\r |
| 4672 | div_word(m, destval);\r |
| 4673 | break;\r |
| 4674 | case 7:\r |
| 4675 | destoffset=decode_rm10_address(m,rl);\r |
| 4676 | destval = fetch_data_word(m,destoffset);\r |
| 4677 | idiv_word(m, destval);\r |
| 4678 | break;\r |
| 4679 | }\r |
| 4680 | break; /* end mod==10 */\r |
| 4681 | case 3: /* mod=11 */\r |
| 4682 | switch(rh)\r |
| 4683 | {\r |
| 4684 | case 0: /* test word imm */\r |
| 4685 | destreg=DECODE_RM_WORD_REGISTER(m,rl);\r |
| 4686 | srcval = fetch_word_imm(m);\r |
| 4687 | test_word(m, *destreg, srcval);\r |
| 4688 | break;\r |
| 4689 | case 1:\r |
| 4690 | halt_sys(m);\r |
| 4691 | break;\r |
| 4692 | case 2:\r |
| 4693 | destreg=DECODE_RM_WORD_REGISTER(m,rl);\r |
| 4694 | *destreg = not_word(m, *destreg);\r |
| 4695 | break;\r |
| 4696 | case 3:\r |
| 4697 | destreg=DECODE_RM_WORD_REGISTER(m,rl);\r |
| 4698 | *destreg = neg_word(m, *destreg);\r |
| 4699 | break;\r |
| 4700 | case 4:\r |
| 4701 | destreg=DECODE_RM_WORD_REGISTER(m,rl);\r |
| 4702 | mul_word(m, *destreg); /*!!! */\r |
| 4703 | break;\r |
| 4704 | case 5:\r |
| 4705 | destreg=DECODE_RM_WORD_REGISTER(m,rl);\r |
| 4706 | imul_word(m, *destreg);\r |
| 4707 | break;\r |
| 4708 | case 6:\r |
| 4709 | destreg=DECODE_RM_WORD_REGISTER(m,rl);\r |
| 4710 | div_word(m, *destreg);\r |
| 4711 | break;\r |
| 4712 | case 7:\r |
| 4713 | destreg=DECODE_RM_WORD_REGISTER(m,rl);\r |
| 4714 | idiv_word(m, *destreg);\r |
| 4715 | break;\r |
| 4716 | }\r |
| 4717 | break; /* end mod==11 */\r |
| 4718 | }\r |
| 4719 | DECODE_CLEAR_SEGOVR(m);\r |
| 4720 | }\r |
| 4721 | \r |
| 4722 | /*opcode=0xf8*/\r |
| 4723 | static void i86op_clc(PC_ENV *m)\r |
| 4724 | {\r |
| 4725 | /* clear the carry flag. */\r |
| 4726 | CLEAR_FLAG(m, F_CF);\r |
| 4727 | DECODE_CLEAR_SEGOVR(m);\r |
| 4728 | }\r |
| 4729 | \r |
| 4730 | /*opcode=0xf9*/\r |
| 4731 | static void i86op_stc(PC_ENV *m)\r |
| 4732 | {\r |
| 4733 | /* set the carry flag. */\r |
| 4734 | SET_FLAG(m, F_CF);\r |
| 4735 | DECODE_CLEAR_SEGOVR(m);\r |
| 4736 | }\r |
| 4737 | \r |
| 4738 | /*opcode=0xfa*/\r |
| 4739 | static void i86op_cli(PC_ENV *m)\r |
| 4740 | {\r |
| 4741 | /* clear interrupts. */\r |
| 4742 | CLEAR_FLAG(m, F_IF);\r |
| 4743 | DECODE_CLEAR_SEGOVR(m);\r |
| 4744 | }\r |
| 4745 | \r |
| 4746 | /*opcode=0xfb*/\r |
| 4747 | static void i86op_sti(PC_ENV *m)\r |
| 4748 | {\r |
| 4749 | /* enable interrupts. */\r |
| 4750 | SET_FLAG(m, F_IF);\r |
| 4751 | DECODE_CLEAR_SEGOVR(m);\r |
| 4752 | }\r |
| 4753 | \r |
| 4754 | /*opcode=0xfc*/\r |
| 4755 | static void i86op_cld(PC_ENV *m)\r |
| 4756 | {\r |
| 4757 | /* clear interrupts. */\r |
| 4758 | CLEAR_FLAG(m, F_DF);\r |
| 4759 | DECODE_CLEAR_SEGOVR(m);\r |
| 4760 | }\r |
| 4761 | \r |
| 4762 | /*opcode=0xfd*/\r |
| 4763 | static void i86op_std(PC_ENV *m)\r |
| 4764 | {\r |
| 4765 | /* clear interrupts. */\r |
| 4766 | SET_FLAG(m, F_DF);\r |
| 4767 | DECODE_CLEAR_SEGOVR(m);\r |
| 4768 | }\r |
| 4769 | \r |
| 4770 | /*opcode=0xfe*/\r |
| 4771 | static void i86op_opcFE_byte_RM(PC_ENV *m)\r |
| 4772 | {\r |
| 4773 | /* Yet another damned special case instruction. */\r |
| 4774 | uint16 mod,rh,rl;\r |
| 4775 | uint8 destval;\r |
| 4776 | uint16 destoffset;\r |
| 4777 | uint8 *destreg;\r |
| 4778 | /* ARRGH, ANOTHER GODDAMN SPECIAL CASE INSTRUCTION!!! */\r |
| 4779 | FETCH_DECODE_MODRM(m,mod,rh,rl);\r |
| 4780 | switch (mod)\r |
| 4781 | {\r |
| 4782 | case 0:\r |
| 4783 | destoffset=decode_rm00_address(m,rl);\r |
| 4784 | switch (rh)\r |
| 4785 | {\r |
| 4786 | case 0: /* inc word ptr ... */\r |
| 4787 | destval = fetch_data_byte(m,destoffset);\r |
| 4788 | destval = inc_byte(m,destval);\r |
| 4789 | store_data_byte(m,destoffset,destval);\r |
| 4790 | break;\r |
| 4791 | case 1: /* dec word ptr ... */\r |
| 4792 | destval = fetch_data_byte(m,destoffset);\r |
| 4793 | destval = dec_byte(m,destval);\r |
| 4794 | store_data_byte(m,destoffset,destval);\r |
| 4795 | break;\r |
| 4796 | }\r |
| 4797 | break;\r |
| 4798 | case 1:\r |
| 4799 | destoffset=decode_rm01_address(m,rl);\r |
| 4800 | switch (rh)\r |
| 4801 | {\r |
| 4802 | case 0:\r |
| 4803 | destval = fetch_data_byte(m,destoffset);\r |
| 4804 | destval = inc_byte(m,destval);\r |
| 4805 | store_data_byte(m,destoffset,destval);\r |
| 4806 | break;\r |
| 4807 | case 1:\r |
| 4808 | destval = fetch_data_byte(m,destoffset);\r |
| 4809 | destval = dec_byte(m,destval);\r |
| 4810 | store_data_byte(m,destoffset,destval);\r |
| 4811 | break;\r |
| 4812 | }\r |
| 4813 | break;\r |
| 4814 | case 2:\r |
| 4815 | destoffset=decode_rm10_address(m,rl);\r |
| 4816 | switch (rh)\r |
| 4817 | {\r |
| 4818 | case 0:\r |
| 4819 | destval = fetch_data_byte(m,destoffset);\r |
| 4820 | destval = inc_byte(m,destval);\r |
| 4821 | store_data_byte(m,destoffset,destval);\r |
| 4822 | break;\r |
| 4823 | case 1:\r |
| 4824 | destval = fetch_data_byte(m,destoffset);\r |
| 4825 | destval = dec_byte(m,destval);\r |
| 4826 | store_data_byte(m,destoffset,destval);\r |
| 4827 | break;\r |
| 4828 | }\r |
| 4829 | break;\r |
| 4830 | case 3:\r |
| 4831 | destreg = DECODE_RM_BYTE_REGISTER(m,rl);\r |
| 4832 | switch (rh)\r |
| 4833 | {\r |
| 4834 | case 0:\r |
| 4835 | *destreg = inc_byte(m,*destreg);\r |
| 4836 | break;\r |
| 4837 | case 1:\r |
| 4838 | *destreg = dec_byte(m,*destreg);\r |
| 4839 | break;\r |
| 4840 | }\r |
| 4841 | break;\r |
| 4842 | }\r |
| 4843 | DECODE_CLEAR_SEGOVR(m);\r |
| 4844 | }\r |
| 4845 | \r |
| 4846 | /*opcode=0xff*/\r |
| 4847 | static void i86op_opcFF_word_RM(PC_ENV *m)\r |
| 4848 | {\r |
| 4849 | uint16 mod,rh,rl;\r |
| 4850 | uint16 destval,destval2;\r |
| 4851 | uint16 destoffset;\r |
| 4852 | uint16 *destreg;\r |
| 4853 | /* ANOTHER DAMN SPECIAL CASE INSTRUCTION!!! */\r |
| 4854 | FETCH_DECODE_MODRM(m,mod,rh,rl);\r |
| 4855 | switch (mod)\r |
| 4856 | {\r |
| 4857 | case 0:\r |
| 4858 | destoffset=decode_rm00_address(m,rl);\r |
| 4859 | switch (rh)\r |
| 4860 | {\r |
| 4861 | case 0: /* inc word ptr ... */\r |
| 4862 | destval = fetch_data_word(m,destoffset);\r |
| 4863 | destval = inc_word(m,destval);\r |
| 4864 | store_data_word(m,destoffset,destval);\r |
| 4865 | break;\r |
| 4866 | case 1: /* dec word ptr ... */\r |
| 4867 | destval = fetch_data_word(m,destoffset);\r |
| 4868 | destval = dec_word(m,destval);\r |
| 4869 | store_data_word(m,destoffset,destval);\r |
| 4870 | break;\r |
| 4871 | case 2: /* call word ptr ... */\r |
| 4872 | destval = fetch_data_word(m,destoffset);\r |
| 4873 | push_word(m,m->R_IP);\r |
| 4874 | m->R_IP = destval;\r |
| 4875 | break;\r |
| 4876 | case 3: /* call far ptr ... */\r |
| 4877 | destval = fetch_data_word(m,destoffset);\r |
| 4878 | destval2 = fetch_data_word(m,destoffset+2);\r |
| 4879 | push_word(m,m->R_CS);\r |
| 4880 | m->R_CS = destval2;\r |
| 4881 | push_word(m,m->R_IP);\r |
| 4882 | m->R_IP = destval;\r |
| 4883 | break;\r |
| 4884 | case 4: /* jmp word ptr ... */\r |
| 4885 | destval = fetch_data_word(m,destoffset);\r |
| 4886 | m->R_IP = destval;\r |
| 4887 | break;\r |
| 4888 | case 5: /* jmp far ptr ... */\r |
| 4889 | destval = fetch_data_word(m,destoffset);\r |
| 4890 | destval2 = fetch_data_word(m,destoffset+2);\r |
| 4891 | m->R_IP = destval;\r |
| 4892 | m->R_CS = destval2;\r |
| 4893 | break;\r |
| 4894 | case 6: /* push word ptr ... */\r |
| 4895 | destval = fetch_data_word(m,destoffset);\r |
| 4896 | push_word(m,destval);\r |
| 4897 | break;\r |
| 4898 | }\r |
| 4899 | break;\r |
| 4900 | case 1:\r |
| 4901 | destoffset=decode_rm01_address(m,rl);\r |
| 4902 | switch (rh)\r |
| 4903 | {\r |
| 4904 | case 0:\r |
| 4905 | destval = fetch_data_word(m,destoffset);\r |
| 4906 | destval = inc_word(m,destval);\r |
| 4907 | store_data_word(m,destoffset,destval);\r |
| 4908 | break;\r |
| 4909 | case 1:\r |
| 4910 | destval = fetch_data_word(m,destoffset);\r |
| 4911 | destval = dec_word(m,destval);\r |
| 4912 | store_data_word(m,destoffset,destval);\r |
| 4913 | break;\r |
| 4914 | case 2: /* call word ptr ... */\r |
| 4915 | destval = fetch_data_word(m,destoffset);\r |
| 4916 | push_word(m,m->R_IP);\r |
| 4917 | m->R_IP = destval;\r |
| 4918 | break;\r |
| 4919 | case 3: /* call far ptr ... */\r |
| 4920 | destval = fetch_data_word(m,destoffset);\r |
| 4921 | destval2 = fetch_data_word(m,destoffset+2);\r |
| 4922 | push_word(m,m->R_CS);\r |
| 4923 | m->R_CS = destval2;\r |
| 4924 | push_word(m,m->R_IP);\r |
| 4925 | m->R_IP = destval;\r |
| 4926 | break;\r |
| 4927 | case 4: /* jmp word ptr ... */\r |
| 4928 | destval = fetch_data_word(m,destoffset);\r |
| 4929 | m->R_IP = destval;\r |
| 4930 | break;\r |
| 4931 | case 5: /* jmp far ptr ... */\r |
| 4932 | destval = fetch_data_word(m,destoffset);\r |
| 4933 | destval2 = fetch_data_word(m,destoffset+2);\r |
| 4934 | m->R_IP = destval;\r |
| 4935 | m->R_CS = destval2;\r |
| 4936 | break;\r |
| 4937 | case 6: /* push word ptr ... */\r |
| 4938 | destval = fetch_data_word(m,destoffset);\r |
| 4939 | push_word(m,destval);\r |
| 4940 | break;\r |
| 4941 | }\r |
| 4942 | break;\r |
| 4943 | case 2:\r |
| 4944 | destoffset=decode_rm10_address(m,rl);\r |
| 4945 | switch (rh)\r |
| 4946 | {\r |
| 4947 | case 0:\r |
| 4948 | destval = fetch_data_word(m,destoffset);\r |
| 4949 | destval = inc_word(m,destval);\r |
| 4950 | store_data_word(m,destoffset,destval);\r |
| 4951 | break;\r |
| 4952 | case 1:\r |
| 4953 | destval = fetch_data_word(m,destoffset);\r |
| 4954 | destval = dec_word(m,destval);\r |
| 4955 | store_data_word(m,destoffset,destval);\r |
| 4956 | break;\r |
| 4957 | case 2: /* call word ptr ... */\r |
| 4958 | destval = fetch_data_word(m,destoffset);\r |
| 4959 | push_word(m,m->R_IP);\r |
| 4960 | m->R_IP = destval;\r |
| 4961 | break;\r |
| 4962 | case 3: /* call far ptr ... */\r |
| 4963 | destval = fetch_data_word(m,destoffset);\r |
| 4964 | destval2 = fetch_data_word(m,destoffset+2);\r |
| 4965 | push_word(m,m->R_CS);\r |
| 4966 | m->R_CS = destval2;\r |
| 4967 | push_word(m,m->R_IP);\r |
| 4968 | m->R_IP = destval;\r |
| 4969 | break;\r |
| 4970 | case 4: /* jmp word ptr ... */\r |
| 4971 | destval = fetch_data_word(m,destoffset);\r |
| 4972 | m->R_IP = destval;\r |
| 4973 | break;\r |
| 4974 | case 5: /* jmp far ptr ... */\r |
| 4975 | destval = fetch_data_word(m,destoffset);\r |
| 4976 | destval2 = fetch_data_word(m,destoffset+2);\r |
| 4977 | m->R_IP = destval;\r |
| 4978 | m->R_CS = destval2;\r |
| 4979 | break;\r |
| 4980 | case 6: /* push word ptr ... */\r |
| 4981 | destval = fetch_data_word(m,destoffset);\r |
| 4982 | push_word(m,destval);\r |
| 4983 | break;\r |
| 4984 | }\r |
| 4985 | break;\r |
| 4986 | case 3:\r |
| 4987 | destreg = DECODE_RM_WORD_REGISTER(m,rl);\r |
| 4988 | switch (rh)\r |
| 4989 | {\r |
| 4990 | case 0:\r |
| 4991 | *destreg = inc_word(m,*destreg);\r |
| 4992 | break;\r |
| 4993 | case 1:\r |
| 4994 | *destreg = dec_word(m,*destreg);\r |
| 4995 | break;\r |
| 4996 | case 2: /* call word ptr ... */\r |
| 4997 | push_word(m,m->R_IP);\r |
| 4998 | m->R_IP = *destreg;\r |
| 4999 | break;\r |
| 5000 | case 3: /* jmp far ptr ... */\r |
| 5001 | halt_sys(m);\r |
| 5002 | break;\r |
| 5003 | case 4: /* jmp ... */\r |
| 5004 | m->R_IP = (uint16)(*destreg);\r |
| 5005 | break;\r |
| 5006 | case 5: /* jmp far ptr ... */\r |
| 5007 | halt_sys(m);\r |
| 5008 | break;\r |
| 5009 | case 6:\r |
| 5010 | push_word(m,*destreg);\r |
| 5011 | break;\r |
| 5012 | }\r |
| 5013 | break;\r |
| 5014 | }\r |
| 5015 | DECODE_CLEAR_SEGOVR(m);\r |
| 5016 | }\r |
| 5017 | \r |
| 5018 | /* opcode=0xd8*/\r |
| 5019 | static void i86op_esc_coprocess_d8(PC_ENV *m)\r |
| 5020 | {\r |
| 5021 | DECODE_CLEAR_SEGOVR(m);\r |
| 5022 | }\r |
| 5023 | \r |
| 5024 | /* opcode=0xd9*/\r |
| 5025 | static void i86op_esc_coprocess_d9(PC_ENV *m)\r |
| 5026 | {\r |
| 5027 | uint16 mod,rl,rh;\r |
| 5028 | uint16 destoffset;\r |
| 5029 | uint8 stkelem;\r |
| 5030 | FETCH_DECODE_MODRM(m,mod,rh,rl);\r |
| 5031 | switch (mod)\r |
| 5032 | {\r |
| 5033 | case 0:\r |
| 5034 | destoffset=decode_rm00_address(m,rl);\r |
| 5035 | break;\r |
| 5036 | case 1:\r |
| 5037 | destoffset=decode_rm01_address(m,rl);\r |
| 5038 | break;\r |
| 5039 | case 2:\r |
| 5040 | destoffset=decode_rm10_address(m,rl);\r |
| 5041 | break;\r |
| 5042 | case 3: /* register to register */\r |
| 5043 | stkelem = (uint8) rl;\r |
| 5044 | break;\r |
| 5045 | }\r |
| 5046 | DECODE_CLEAR_SEGOVR(m);\r |
| 5047 | }\r |
| 5048 | \r |
| 5049 | /* opcode=0xda*/\r |
| 5050 | static void i86op_esc_coprocess_da(PC_ENV *m)\r |
| 5051 | {\r |
| 5052 | uint16 mod,rl,rh;\r |
| 5053 | uint16 destoffset;\r |
| 5054 | uint8 stkelem;\r |
| 5055 | FETCH_DECODE_MODRM(m,mod,rh,rl);\r |
| 5056 | switch (mod)\r |
| 5057 | {\r |
| 5058 | case 0:\r |
| 5059 | destoffset=decode_rm00_address(m,rl);\r |
| 5060 | break;\r |
| 5061 | case 1:\r |
| 5062 | destoffset=decode_rm01_address(m,rl);\r |
| 5063 | break;\r |
| 5064 | case 2:\r |
| 5065 | destoffset=decode_rm10_address(m,rl);\r |
| 5066 | break;\r |
| 5067 | case 3: /* register to register */\r |
| 5068 | stkelem = (uint8) rl;\r |
| 5069 | break;\r |
| 5070 | }\r |
| 5071 | DECODE_CLEAR_SEGOVR(m);\r |
| 5072 | }\r |
| 5073 | \r |
| 5074 | /* opcode=0xdb*/\r |
| 5075 | static void i86op_esc_coprocess_db(PC_ENV *m)\r |
| 5076 | {\r |
| 5077 | uint16 mod,rl,rh;\r |
| 5078 | uint16 destoffset;\r |
| 5079 | /* uint8 stkelem;*/\r |
| 5080 | FETCH_DECODE_MODRM(m,mod,rh,rl);\r |
| 5081 | switch (mod)\r |
| 5082 | {\r |
| 5083 | case 0:\r |
| 5084 | destoffset=decode_rm00_address(m,rl);\r |
| 5085 | break;\r |
| 5086 | case 1:\r |
| 5087 | destoffset=decode_rm01_address(m,rl);\r |
| 5088 | break;\r |
| 5089 | case 2:\r |
| 5090 | destoffset=decode_rm10_address(m,rl);\r |
| 5091 | break;\r |
| 5092 | case 3: /* register to register */\r |
| 5093 | break;\r |
| 5094 | }\r |
| 5095 | DECODE_CLEAR_SEGOVR(m);\r |
| 5096 | }\r |
| 5097 | \r |
| 5098 | /* opcode=0xdc*/\r |
| 5099 | static void i86op_esc_coprocess_dc(PC_ENV *m)\r |
| 5100 | {\r |
| 5101 | uint16 mod,rl,rh;\r |
| 5102 | uint16 destoffset;\r |
| 5103 | uint8 stkelem;\r |
| 5104 | FETCH_DECODE_MODRM(m,mod,rh,rl);\r |
| 5105 | switch (mod)\r |
| 5106 | {\r |
| 5107 | case 0:\r |
| 5108 | destoffset=decode_rm00_address(m,rl);\r |
| 5109 | break;\r |
| 5110 | case 1:\r |
| 5111 | destoffset=decode_rm01_address(m,rl);\r |
| 5112 | break;\r |
| 5113 | case 2:\r |
| 5114 | destoffset=decode_rm10_address(m,rl);\r |
| 5115 | break;\r |
| 5116 | case 3: /* register to register */\r |
| 5117 | stkelem = (uint8) rl;\r |
| 5118 | break;\r |
| 5119 | }\r |
| 5120 | DECODE_CLEAR_SEGOVR(m);\r |
| 5121 | }\r |
| 5122 | \r |
| 5123 | /* opcode=0xdd*/\r |
| 5124 | static void i86op_esc_coprocess_dd(PC_ENV *m)\r |
| 5125 | {\r |
| 5126 | uint16 mod,rl,rh;\r |
| 5127 | uint16 destoffset;\r |
| 5128 | uint8 stkelem;\r |
| 5129 | FETCH_DECODE_MODRM(m,mod,rh,rl);\r |
| 5130 | switch (mod)\r |
| 5131 | {\r |
| 5132 | case 0:\r |
| 5133 | destoffset=decode_rm00_address(m,rl);\r |
| 5134 | break;\r |
| 5135 | case 1:\r |
| 5136 | destoffset=decode_rm01_address(m,rl);\r |
| 5137 | break;\r |
| 5138 | case 2:\r |
| 5139 | destoffset=decode_rm10_address(m,rl);\r |
| 5140 | break;\r |
| 5141 | case 3: /* register to register */\r |
| 5142 | stkelem = (uint8) rl;\r |
| 5143 | break;\r |
| 5144 | }\r |
| 5145 | DECODE_CLEAR_SEGOVR(m);\r |
| 5146 | }\r |
| 5147 | \r |
| 5148 | /* opcode=0xde*/\r |
| 5149 | static void i86op_esc_coprocess_de(PC_ENV *m)\r |
| 5150 | {\r |
| 5151 | uint16 mod,rl,rh;\r |
| 5152 | uint16 destoffset;\r |
| 5153 | uint8 stkelem;\r |
| 5154 | FETCH_DECODE_MODRM(m,mod,rh,rl);\r |
| 5155 | switch (mod)\r |
| 5156 | {\r |
| 5157 | case 0:\r |
| 5158 | destoffset=decode_rm00_address(m,rl);\r |
| 5159 | break;\r |
| 5160 | case 1:\r |
| 5161 | destoffset=decode_rm01_address(m,rl);\r |
| 5162 | break;\r |
| 5163 | case 2:\r |
| 5164 | destoffset=decode_rm10_address(m,rl);\r |
| 5165 | break;\r |
| 5166 | case 3: /* register to register */\r |
| 5167 | stkelem = (uint8) rl;\r |
| 5168 | break;\r |
| 5169 | }\r |
| 5170 | DECODE_CLEAR_SEGOVR(m);\r |
| 5171 | }\r |
| 5172 | \r |
| 5173 | /* opcode=0xdf*/\r |
| 5174 | static void i86op_esc_coprocess_df(PC_ENV *m)\r |
| 5175 | {\r |
| 5176 | uint16 mod,rl,rh;\r |
| 5177 | uint16 destoffset;\r |
| 5178 | uint8 stkelem;\r |
| 5179 | FETCH_DECODE_MODRM(m,mod,rh,rl);\r |
| 5180 | switch (mod)\r |
| 5181 | {\r |
| 5182 | case 0:\r |
| 5183 | destoffset=decode_rm00_address(m,rl);\r |
| 5184 | break;\r |
| 5185 | case 1:\r |
| 5186 | destoffset=decode_rm01_address(m,rl);\r |
| 5187 | break;\r |
| 5188 | case 2:\r |
| 5189 | destoffset=decode_rm10_address(m,rl);\r |
| 5190 | break;\r |
| 5191 | case 3: /* register to register */\r |
| 5192 | stkelem = (uint8) rl;\r |
| 5193 | break;\r |
| 5194 | }\r |
| 5195 | DECODE_CLEAR_SEGOVR(m);\r |
| 5196 | }\r |
| 5197 | \r |
| 5198 | /* OPERAND TABLE */\r |
| 5199 | \r |
| 5200 | OP i86_optab[256] = {\r |
| 5201 | \r |
| 5202 | /* 0x00 */ i86op_add_byte_RM_R,\r |
| 5203 | /* 0x01 */ i86op_add_word_RM_R,\r |
| 5204 | /* 0x02 */ i86op_add_byte_R_RM,\r |
| 5205 | /* 0x03 */ i86op_add_word_R_RM,\r |
| 5206 | /* 0x04 */ i86op_add_byte_AL_IMM,\r |
| 5207 | /* 0x05 */ i86op_add_word_AX_IMM,\r |
| 5208 | /* 0x06 */ i86op_push_ES,\r |
| 5209 | /* 0x07 */ i86op_pop_ES,\r |
| 5210 | \r |
| 5211 | /* 0x08 */ i86op_or_byte_RM_R,\r |
| 5212 | /* 0x09 */ i86op_or_word_RM_R,\r |
| 5213 | /* 0x0a */ i86op_or_byte_R_RM,\r |
| 5214 | /* 0x0b */ i86op_or_word_R_RM,\r |
| 5215 | /* 0x0c */ i86op_or_byte_AL_IMM,\r |
| 5216 | /* 0x0d */ i86op_or_word_AX_IMM,\r |
| 5217 | /* 0x0e */ i86op_push_CS,\r |
| 5218 | /* 0x0f */ i86op_illegal_op,\r |
| 5219 | \r |
| 5220 | /* 0x10 */ i86op_adc_byte_RM_R,\r |
| 5221 | /* 0x11 */ i86op_adc_word_RM_R,\r |
| 5222 | /* 0x12 */ i86op_adc_byte_R_RM,\r |
| 5223 | /* 0x13 */ i86op_adc_word_R_RM,\r |
| 5224 | /* 0x14 */ i86op_adc_byte_AL_IMM,\r |
| 5225 | /* 0x15 */ i86op_adc_word_AX_IMM,\r |
| 5226 | /* 0x16 */ i86op_push_SS,\r |
| 5227 | /* 0x17 */ i86op_pop_SS,\r |
| 5228 | \r |
| 5229 | /* 0x18 */ i86op_sbb_byte_RM_R,\r |
| 5230 | /* 0x19 */ i86op_sbb_word_RM_R,\r |
| 5231 | /* 0x1a */ i86op_sbb_byte_R_RM,\r |
| 5232 | /* 0x1b */ i86op_sbb_word_R_RM,\r |
| 5233 | /* 0x1c */ i86op_sbb_byte_AL_IMM,\r |
| 5234 | /* 0x1d */ i86op_sbb_word_AX_IMM,\r |
| 5235 | /* 0x1e */ i86op_push_DS,\r |
| 5236 | /* 0x1f */ i86op_pop_DS,\r |
| 5237 | \r |
| 5238 | /* 0x20 */ i86op_and_byte_RM_R,\r |
| 5239 | /* 0x21 */ i86op_and_word_RM_R,\r |
| 5240 | /* 0x22 */ i86op_and_byte_R_RM,\r |
| 5241 | /* 0x23 */ i86op_and_word_R_RM,\r |
| 5242 | /* 0x24 */ i86op_and_byte_AL_IMM,\r |
| 5243 | /* 0x25 */ i86op_and_word_AX_IMM,\r |
| 5244 | /* 0x26 */ i86op_segovr_ES,\r |
| 5245 | /* 0x27 */ i86op_daa,\r |
| 5246 | \r |
| 5247 | /* 0x28 */ i86op_sub_byte_RM_R,\r |
| 5248 | /* 0x29 */ i86op_sub_word_RM_R,\r |
| 5249 | /* 0x2a */ i86op_sub_byte_R_RM,\r |
| 5250 | /* 0x2b */ i86op_sub_word_R_RM,\r |
| 5251 | /* 0x2c */ i86op_sub_byte_AL_IMM,\r |
| 5252 | /* 0x2d */ i86op_sub_word_AX_IMM,\r |
| 5253 | /* 0x2e */ i86op_segovr_CS,\r |
| 5254 | /* 0x2f */ i86op_das,\r |
| 5255 | \r |
| 5256 | /* 0x30 */ i86op_xor_byte_RM_R,\r |
| 5257 | /* 0x31 */ i86op_xor_word_RM_R,\r |
| 5258 | /* 0x32 */ i86op_xor_byte_R_RM,\r |
| 5259 | /* 0x33 */ i86op_xor_word_R_RM,\r |
| 5260 | /* 0x34 */ i86op_xor_byte_AL_IMM,\r |
| 5261 | /* 0x35 */ i86op_xor_word_AX_IMM,\r |
| 5262 | /* 0x36 */ i86op_segovr_SS,\r |
| 5263 | /* 0x37 */ i86op_aaa,\r |
| 5264 | \r |
| 5265 | /* 0x38 */ i86op_cmp_byte_RM_R,\r |
| 5266 | /* 0x39 */ i86op_cmp_word_RM_R,\r |
| 5267 | /* 0x3a */ i86op_cmp_byte_R_RM,\r |
| 5268 | /* 0x3b */ i86op_cmp_word_R_RM,\r |
| 5269 | /* 0x3c */ i86op_cmp_byte_AL_IMM,\r |
| 5270 | /* 0x3d */ i86op_cmp_word_AX_IMM,\r |
| 5271 | /* 0x3e */ i86op_segovr_DS,\r |
| 5272 | /* 0x3f */ i86op_aas,\r |
| 5273 | \r |
| 5274 | /* 0x40 */ i86op_inc_AX,\r |
| 5275 | /* 0x41 */ i86op_inc_CX,\r |
| 5276 | /* 0x42 */ i86op_inc_DX,\r |
| 5277 | /* 0x43 */ i86op_inc_BX,\r |
| 5278 | /* 0x44 */ i86op_inc_SP,\r |
| 5279 | /* 0x45 */ i86op_inc_BP,\r |
| 5280 | /* 0x46 */ i86op_inc_SI,\r |
| 5281 | /* 0x47 */ i86op_inc_DI,\r |
| 5282 | \r |
| 5283 | /* 0x48 */ i86op_dec_AX,\r |
| 5284 | /* 0x49 */ i86op_dec_CX,\r |
| 5285 | /* 0x4a */ i86op_dec_DX,\r |
| 5286 | /* 0x4b */ i86op_dec_BX,\r |
| 5287 | /* 0x4c */ i86op_dec_SP,\r |
| 5288 | /* 0x4d */ i86op_dec_BP,\r |
| 5289 | /* 0x4e */ i86op_dec_SI,\r |
| 5290 | /* 0x4f */ i86op_dec_DI,\r |
| 5291 | \r |
| 5292 | /* 0x50 */ i86op_push_AX,\r |
| 5293 | /* 0x51 */ i86op_push_CX,\r |
| 5294 | /* 0x52 */ i86op_push_DX,\r |
| 5295 | /* 0x53 */ i86op_push_BX,\r |
| 5296 | /* 0x54 */ i86op_push_SP,\r |
| 5297 | /* 0x55 */ i86op_push_BP,\r |
| 5298 | /* 0x56 */ i86op_push_SI,\r |
| 5299 | /* 0x57 */ i86op_push_DI,\r |
| 5300 | \r |
| 5301 | /* 0x58 */ i86op_pop_AX,\r |
| 5302 | /* 0x59 */ i86op_pop_CX,\r |
| 5303 | /* 0x5a */ i86op_pop_DX,\r |
| 5304 | /* 0x5b */ i86op_pop_BX,\r |
| 5305 | /* 0x5c */ i86op_pop_SP,\r |
| 5306 | /* 0x5d */ i86op_pop_BP,\r |
| 5307 | /* 0x5e */ i86op_pop_SI,\r |
| 5308 | /* 0x5f */ i86op_pop_DI,\r |
| 5309 | \r |
| 5310 | /* 0x60 */ i86op_illegal_op,\r |
| 5311 | /* 0x61 */ i86op_illegal_op,\r |
| 5312 | /* 0x62 */ i86op_illegal_op,\r |
| 5313 | /* 0x63 */ i86op_illegal_op,\r |
| 5314 | /* 0x64 */ i86op_illegal_op,\r |
| 5315 | /* 0x65 */ i86op_illegal_op,\r |
| 5316 | /* 0x66 */ i86op_illegal_op,\r |
| 5317 | /* 0x67 */ i86op_illegal_op,\r |
| 5318 | \r |
| 5319 | /* 0x68 */ i86op_illegal_op,\r |
| 5320 | /* 0x69 */ i86op_illegal_op,\r |
| 5321 | /* 0x6a */ i86op_illegal_op,\r |
| 5322 | /* 0x6b */ i86op_illegal_op,\r |
| 5323 | /* 0x6c */ i86op_illegal_op,\r |
| 5324 | /* 0x6d */ i86op_illegal_op,\r |
| 5325 | /* 0x6e */ i86op_illegal_op,\r |
| 5326 | /* 0x6f */ i86op_illegal_op,\r |
| 5327 | \r |
| 5328 | /* 0x70 */ i86op_jump_near_O,\r |
| 5329 | /* 0x71 */ i86op_jump_near_NO,\r |
| 5330 | /* 0x72 */ i86op_jump_near_B,\r |
| 5331 | /* 0x73 */ i86op_jump_near_NB,\r |
| 5332 | /* 0x74 */ i86op_jump_near_Z,\r |
| 5333 | /* 0x75 */ i86op_jump_near_NZ,\r |
| 5334 | /* 0x76 */ i86op_jump_near_BE,\r |
| 5335 | /* 0x77 */ i86op_jump_near_NBE,\r |
| 5336 | \r |
| 5337 | /* 0x78 */ i86op_jump_near_S,\r |
| 5338 | /* 0x79 */ i86op_jump_near_NS,\r |
| 5339 | /* 0x7a */ i86op_jump_near_P,\r |
| 5340 | /* 0x7b */ i86op_jump_near_NP,\r |
| 5341 | /* 0x7c */ i86op_jump_near_L,\r |
| 5342 | /* 0x7d */ i86op_jump_near_NL,\r |
| 5343 | /* 0x7e */ i86op_jump_near_LE,\r |
| 5344 | /* 0x7f */ i86op_jump_near_NLE,\r |
| 5345 | \r |
| 5346 | /* 0x80 */ i86op_opc80_byte_RM_IMM,\r |
| 5347 | /* 0x81 */ i86op_opc81_word_RM_IMM,\r |
| 5348 | /* 0x82 */ i86op_opc82_byte_RM_IMM,\r |
| 5349 | /* 0x83 */ i86op_opc83_word_RM_IMM,\r |
| 5350 | /* 0x84 */ i86op_test_byte_RM_R,\r |
| 5351 | /* 0x85 */ i86op_test_word_RM_R,\r |
| 5352 | /* 0x86 */ i86op_xchg_byte_RM_R,\r |
| 5353 | /* 0x87 */ i86op_xchg_word_RM_R,\r |
| 5354 | \r |
| 5355 | /* 0x88 */ i86op_mov_byte_RM_R,\r |
| 5356 | /* 0x89 */ i86op_mov_word_RM_R,\r |
| 5357 | /* 0x8a */ i86op_mov_byte_R_RM,\r |
| 5358 | /* 0x8b */ i86op_mov_word_R_RM,\r |
| 5359 | /* 0x8c */ i86op_mov_word_RM_SR,\r |
| 5360 | /* 0x8d */ i86op_lea_word_R_M,\r |
| 5361 | /* 0x8e */ i86op_mov_word_SR_RM,\r |
| 5362 | /* 0x8f */ i86op_pop_RM,\r |
| 5363 | \r |
| 5364 | /* 0x90 */ i86op_nop,\r |
| 5365 | /* 0x91 */ i86op_xchg_word_AX_CX,\r |
| 5366 | /* 0x92 */ i86op_xchg_word_AX_DX,\r |
| 5367 | /* 0x93 */ i86op_xchg_word_AX_BX,\r |
| 5368 | /* 0x94 */ i86op_xchg_word_AX_SP,\r |
| 5369 | /* 0x95 */ i86op_xchg_word_AX_BP ,\r |
| 5370 | /* 0x96 */ i86op_xchg_word_AX_SI ,\r |
| 5371 | /* 0x97 */ i86op_xchg_word_AX_DI ,\r |
| 5372 | \r |
| 5373 | /* 0x98 */ i86op_cbw,\r |
| 5374 | /* 0x99 */ i86op_cwd,\r |
| 5375 | /* 0x9a */ i86op_call_far_IMM,\r |
| 5376 | /* 0x9b */ i86op_wait,\r |
| 5377 | /* 0x9c */ i86op_pushf_word,\r |
| 5378 | /* 0x9d */ i86op_popf_word,\r |
| 5379 | /* 0x9e */ i86op_sahf,\r |
| 5380 | /* 0x9f */ i86op_lahf,\r |
| 5381 | \r |
| 5382 | /* 0xa0 */ i86op_mov_AL_M_IMM,\r |
| 5383 | /* 0xa1 */ i86op_mov_AX_M_IMM,\r |
| 5384 | /* 0xa2 */ i86op_mov_M_AL_IMM,\r |
| 5385 | /* 0xa3 */ i86op_mov_M_AX_IMM,\r |
| 5386 | /* 0xa4 */ i86op_movs_byte,\r |
| 5387 | /* 0xa5 */ i86op_movs_word,\r |
| 5388 | /* 0xa6 */ i86op_cmps_byte,\r |
| 5389 | /* 0xa7 */ i86op_cmps_word,\r |
| 5390 | /* 0xa8 */ i86op_test_AL_IMM,\r |
| 5391 | /* 0xa9 */ i86op_test_AX_IMM,\r |
| 5392 | /* 0xaa */ i86op_stos_byte,\r |
| 5393 | /* 0xab */ i86op_stos_word,\r |
| 5394 | /* 0xac */ i86op_lods_byte,\r |
| 5395 | /* 0xad */ i86op_lods_word,\r |
| 5396 | /* 0xac */ i86op_scas_byte,\r |
| 5397 | /* 0xad */ i86op_scas_word,\r |
| 5398 | \r |
| 5399 | /* 0xb0 */ i86op_mov_byte_AL_IMM,\r |
| 5400 | /* 0xb1 */ i86op_mov_byte_CL_IMM,\r |
| 5401 | /* 0xb2 */ i86op_mov_byte_DL_IMM,\r |
| 5402 | /* 0xb3 */ i86op_mov_byte_BL_IMM,\r |
| 5403 | /* 0xb4 */ i86op_mov_byte_AH_IMM,\r |
| 5404 | /* 0xb5 */ i86op_mov_byte_CH_IMM,\r |
| 5405 | /* 0xb6 */ i86op_mov_byte_DH_IMM,\r |
| 5406 | /* 0xb7 */ i86op_mov_byte_BH_IMM,\r |
| 5407 | \r |
| 5408 | /* 0xb8 */ i86op_mov_word_AX_IMM,\r |
| 5409 | /* 0xb9 */ i86op_mov_word_CX_IMM,\r |
| 5410 | /* 0xba */ i86op_mov_word_DX_IMM,\r |
| 5411 | /* 0xbb */ i86op_mov_word_BX_IMM,\r |
| 5412 | /* 0xbc */ i86op_mov_word_SP_IMM,\r |
| 5413 | /* 0xbd */ i86op_mov_word_BP_IMM,\r |
| 5414 | /* 0xbe */ i86op_mov_word_SI_IMM,\r |
| 5415 | /* 0xbf */ i86op_mov_word_DI_IMM,\r |
| 5416 | \r |
| 5417 | /* 0xc0 */ i86op_illegal_op,\r |
| 5418 | /* 0xc1 */ i86op_illegal_op,\r |
| 5419 | /* 0xc2 */ i86op_ret_near_IMM,\r |
| 5420 | /* 0xc3 */ i86op_ret_near,\r |
| 5421 | /* 0xc4 */ i86op_les_R_IMM,\r |
| 5422 | /* 0xc5 */ i86op_lds_R_IMM,\r |
| 5423 | /* 0xc6 */ i86op_mov_byte_RM_IMM,\r |
| 5424 | /* 0xc7 */ i86op_mov_word_RM_IMM,\r |
| 5425 | /* 0xc8 */ i86op_illegal_op,\r |
| 5426 | /* 0xc9 */ i86op_illegal_op,\r |
| 5427 | /* 0xca */ i86op_ret_far_IMM,\r |
| 5428 | /* 0xcb */ i86op_ret_far,\r |
| 5429 | /* 0xcc */ i86op_int3,\r |
| 5430 | /* 0xcd */ i86op_int_IMM,\r |
| 5431 | /* 0xce */ i86op_into,\r |
| 5432 | /* 0xcf */ i86op_iret,\r |
| 5433 | \r |
| 5434 | /* 0xd0 */ i86op_opcD0_byte_RM_1,\r |
| 5435 | /* 0xd1 */ i86op_opcD1_word_RM_1,\r |
| 5436 | /* 0xd2 */ i86op_opcD2_byte_RM_CL,\r |
| 5437 | /* 0xd3 */ i86op_opcD3_word_RM_CL,\r |
| 5438 | /* 0xd4 */ i86op_aam,\r |
| 5439 | /* 0xd5 */ i86op_aad,\r |
| 5440 | /* 0xd6 */ i86op_illegal_op,\r |
| 5441 | /* 0xd7 */ i86op_xlat,\r |
| 5442 | /* 0xd8 */ i86op_esc_coprocess_d8,\r |
| 5443 | /* 0xd9 */ i86op_esc_coprocess_d9,\r |
| 5444 | /* 0xda */ i86op_esc_coprocess_da,\r |
| 5445 | /* 0xdb */ i86op_esc_coprocess_db,\r |
| 5446 | /* 0xdc */ i86op_esc_coprocess_dc,\r |
| 5447 | /* 0xdd */ i86op_esc_coprocess_dd,\r |
| 5448 | /* 0xde */ i86op_esc_coprocess_de,\r |
| 5449 | /* 0xdf */ i86op_esc_coprocess_df,\r |
| 5450 | \r |
| 5451 | /* 0xe0 */ i86op_loopne,\r |
| 5452 | /* 0xe1 */ i86op_loope,\r |
| 5453 | /* 0xe2 */ i86op_loop,\r |
| 5454 | /* 0xe3 */ i86op_jcxz,\r |
| 5455 | /* 0xe4 */ i86op_in_byte_AL_IMM,\r |
| 5456 | /* 0xe5 */ i86op_in_word_AX_IMM,\r |
| 5457 | /* 0xe6 */ i86op_out_byte_IMM_AL,\r |
| 5458 | /* 0xe7 */ i86op_out_word_IMM_AX,\r |
| 5459 | \r |
| 5460 | /* 0xe8 */ i86op_call_near_IMM,\r |
| 5461 | /* 0xe9 */ i86op_jump_near_IMM,\r |
| 5462 | /* 0xea */ i86op_jump_far_IMM,\r |
| 5463 | /* 0xeb */ i86op_jump_byte_IMM,\r |
| 5464 | /* 0xec */ i86op_in_byte_AL_DX,\r |
| 5465 | /* 0xed */ i86op_in_word_AX_DX,\r |
| 5466 | /* 0xee */ i86op_out_byte_DX_AL,\r |
| 5467 | /* 0xef */ i86op_out_word_DX_AX,\r |
| 5468 | \r |
| 5469 | /* 0xf0 */ i86op_lock,\r |
| 5470 | /* 0xf1 */ i86op_illegal_op,\r |
| 5471 | /* 0xf2 */ i86op_repne,\r |
| 5472 | /* 0xf3 */ i86op_repe,\r |
| 5473 | /* 0xf4 */ i86op_halt,\r |
| 5474 | /* 0xf5 */ i86op_cmc,\r |
| 5475 | /* 0xf6 */ i86op_opcF6_byte_RM,\r |
| 5476 | /* 0xf7 */ i86op_opcF7_word_RM,\r |
| 5477 | \r |
| 5478 | /* 0xf8 */ i86op_clc,\r |
| 5479 | /* 0xf9 */ i86op_stc,\r |
| 5480 | /* 0xfa */ i86op_cli,\r |
| 5481 | /* 0xfb */ i86op_sti,\r |
| 5482 | /* 0xfc */ i86op_cld,\r |
| 5483 | /* 0xfd */ i86op_std,\r |
| 5484 | /* 0xfe */ i86op_opcFE_byte_RM,\r |
| 5485 | /* 0xff */ i86op_opcFF_word_RM,\r |
| 5486 | \r |
| 5487 | };\r |