1 /****************************************************************************
3 * Realmode X86 Emulator Library
5 * Copyright (C) 1991-2004 SciTech Software, Inc.
6 * Copyright (C) David Mosberger-Tang
7 * Copyright (C) 1999 Egbert Eich
9 * ========================================================================
11 * Permission to use, copy, modify, distribute, and sell this software and
12 * its documentation for any purpose is hereby granted without fee,
13 * provided that the above copyright notice appear in all copies and that
14 * both that copyright notice and this permission notice appear in
15 * supporting documentation, and that the name of the authors not be used
16 * in advertising or publicity pertaining to distribution of the software
17 * without specific, written prior permission. The authors makes no
18 * representations about the suitability of this software for any purpose.
19 * It is provided "as is" without express or implied warranty.
21 * THE AUTHORS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
22 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
23 * EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
24 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
25 * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
26 * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
27 * PERFORMANCE OF THIS SOFTWARE.
29 * ========================================================================
33 * Developer: Kendall Bennett
35 * Description: This file includes subroutines which are related to
36 * instruction decoding and accesses of immediate data via IP. etc.
38 ****************************************************************************/
42 /*----------------------------- Implementation ----------------------------*/
44 /****************************************************************************
46 Handles any pending asynchronous interrupts.
47 ****************************************************************************/
48 static void x86emu_intr_handle(void)
52 if (M
.x86
.intr
& INTR_SYNCH
) {
54 if (_X86EMU_intrTab
[intno
]) {
55 (*_X86EMU_intrTab
[intno
])(intno
);
57 push_word((u16
)M
.x86
.R_FLG
);
60 push_word(M
.x86
.R_CS
);
61 M
.x86
.R_CS
= mem_access_word(intno
* 4 + 2);
62 push_word(M
.x86
.R_IP
);
63 M
.x86
.R_IP
= mem_access_word(intno
* 4);
69 /****************************************************************************
71 intrnum - Interrupt number to raise
74 Raise the specified interrupt to be handled before the execution of the
76 ****************************************************************************/
77 void x86emu_intr_raise(
80 printf("%s, raising exception %x\n", __func__
, intrnum
);
82 M
.x86
.intno
= intrnum
;
83 M
.x86
.intr
|= INTR_SYNCH
;
86 /****************************************************************************
88 Main execution loop for the emulator. We return from here when the system
89 halts, which is normally caused by a stack fault when we return from the
90 original real mode call.
91 ****************************************************************************/
92 void X86EMU_exec(void)
97 DB(x86emu_end_instr();)
100 DB( if (CHECK_IP_FETCH())
101 x86emu_check_ip_access();)
102 /* If debugging, save the IP and CS values. */
103 SAVE_IP_CS(M
.x86
.R_CS
, M
.x86
.R_IP
);
104 INC_DECODED_INST_LEN(1);
106 if (M
.x86
.intr
& INTR_HALTED
) {
107 DB( if (M
.x86
.R_SP
!= 0) {
113 printf("Service completed successfully\n");
117 if (((M
.x86
.intr
& INTR_SYNCH
) && (M
.x86
.intno
== 0 || M
.x86
.intno
== 2)) ||
118 !ACCESS_FLAG(F_IF
)) {
119 x86emu_intr_handle();
122 op1
= (*sys_rdb
)(((u32
)M
.x86
.R_CS
<< 4) + (M
.x86
.R_IP
++));
123 (*x86emu_optab
[op1
])(op1
);
124 //if (M.x86.debug & DEBUG_EXIT) {
125 // M.x86.debug &= ~DEBUG_EXIT;
131 /****************************************************************************
133 Halts the system by setting the halted system flag.
134 ****************************************************************************/
135 void X86EMU_halt_sys(void)
137 M
.x86
.intr
|= INTR_HALTED
;
140 /****************************************************************************
142 mod - Mod value from decoded byte
143 regh - Reg h value from decoded byte
144 regl - Reg l value from decoded byte
147 Raise the specified interrupt to be handled before the execution of the
150 NOTE: Do not inline this function, as (*sys_rdb) is already inline!
151 ****************************************************************************/
152 void fetch_decode_modrm(
159 DB( if (CHECK_IP_FETCH())
160 x86emu_check_ip_access();)
161 fetched
= (*sys_rdb
)(((u32
)M
.x86
.R_CS
<< 4) + (M
.x86
.R_IP
++));
162 INC_DECODED_INST_LEN(1);
163 *mod
= (fetched
>> 6) & 0x03;
164 *regh
= (fetched
>> 3) & 0x07;
165 *regl
= (fetched
>> 0) & 0x07;
168 /****************************************************************************
170 Immediate byte value read from instruction queue
173 This function returns the immediate byte from the instruction queue, and
174 moves the instruction pointer to the next value.
176 NOTE: Do not inline this function, as (*sys_rdb) is already inline!
177 ****************************************************************************/
178 u8
fetch_byte_imm(void)
182 DB( if (CHECK_IP_FETCH())
183 x86emu_check_ip_access();)
184 fetched
= (*sys_rdb
)(((u32
)M
.x86
.R_CS
<< 4) + (M
.x86
.R_IP
++));
185 INC_DECODED_INST_LEN(1);
189 /****************************************************************************
191 Immediate word value read from instruction queue
194 This function returns the immediate byte from the instruction queue, and
195 moves the instruction pointer to the next value.
197 NOTE: Do not inline this function, as (*sys_rdw) is already inline!
198 ****************************************************************************/
199 u16
fetch_word_imm(void)
203 DB( if (CHECK_IP_FETCH())
204 x86emu_check_ip_access();)
205 fetched
= (*sys_rdw
)(((u32
)M
.x86
.R_CS
<< 4) + (M
.x86
.R_IP
));
207 INC_DECODED_INST_LEN(2);
211 /****************************************************************************
213 Immediate lone value read from instruction queue
216 This function returns the immediate byte from the instruction queue, and
217 moves the instruction pointer to the next value.
219 NOTE: Do not inline this function, as (*sys_rdw) is already inline!
220 ****************************************************************************/
221 u32
fetch_long_imm(void)
225 DB( if (CHECK_IP_FETCH())
226 x86emu_check_ip_access();)
227 fetched
= (*sys_rdl
)(((u32
)M
.x86
.R_CS
<< 4) + (M
.x86
.R_IP
));
229 INC_DECODED_INST_LEN(4);
233 /****************************************************************************
235 Value of the default data segment
238 Inline function that returns the default data segment for the current
241 On the x86 processor, the default segment is not always DS if there is
242 no segment override. Address modes such as -3[BP] or 10[BP+SI] all refer to
243 addresses relative to SS (ie: on the stack). So, at the minimum, all
244 decodings of addressing modes would have to set/clear a bit describing
245 whether the access is relative to DS or SS. That is the function of the
246 cpu-state-variable M.x86.mode. There are several potential states:
248 repe prefix seen (handled elsewhere)
249 repne prefix seen (ditto)
258 ds/ss select (in absence of override)
260 Each of the above 7 items are handled with a bit in the mode field.
261 ****************************************************************************/
262 _INLINE u32
get_data_segment(void)
264 #define GET_SEGMENT(segment)
265 switch (M
.x86
.mode
& SYSMODE_SEGMASK
) {
266 case 0: /* default case: use ds register */
267 case SYSMODE_SEGOVR_DS
:
268 case SYSMODE_SEGOVR_DS
| SYSMODE_SEG_DS_SS
:
270 case SYSMODE_SEG_DS_SS
: /* non-overridden, use ss register */
272 case SYSMODE_SEGOVR_CS
:
273 case SYSMODE_SEGOVR_CS
| SYSMODE_SEG_DS_SS
:
275 case SYSMODE_SEGOVR_ES
:
276 case SYSMODE_SEGOVR_ES
| SYSMODE_SEG_DS_SS
:
278 case SYSMODE_SEGOVR_FS
:
279 case SYSMODE_SEGOVR_FS
| SYSMODE_SEG_DS_SS
:
281 case SYSMODE_SEGOVR_GS
:
282 case SYSMODE_SEGOVR_GS
| SYSMODE_SEG_DS_SS
:
284 case SYSMODE_SEGOVR_SS
:
285 case SYSMODE_SEGOVR_SS
| SYSMODE_SEG_DS_SS
:
289 printf("error: should not happen: multiple overrides.\n");
296 /****************************************************************************
298 offset - Offset to load data from
301 Byte value read from the absolute memory location.
303 NOTE: Do not inline this function as (*sys_rdX) is already inline!
304 ****************************************************************************/
309 if (CHECK_DATA_ACCESS())
310 x86emu_check_data_access((u16
)get_data_segment(), offset
);
312 return (*sys_rdb
)((get_data_segment() << 4) + offset
);
315 /****************************************************************************
317 offset - Offset to load data from
320 Word value read from the absolute memory location.
322 NOTE: Do not inline this function as (*sys_rdX) is already inline!
323 ****************************************************************************/
328 if (CHECK_DATA_ACCESS())
329 x86emu_check_data_access((u16
)get_data_segment(), offset
);
331 return (*sys_rdw
)((get_data_segment() << 4) + offset
);
334 /****************************************************************************
336 offset - Offset to load data from
339 Long value read from the absolute memory location.
341 NOTE: Do not inline this function as (*sys_rdX) is already inline!
342 ****************************************************************************/
347 if (CHECK_DATA_ACCESS())
348 x86emu_check_data_access((u16
)get_data_segment(), offset
);
350 return (*sys_rdl
)((get_data_segment() << 4) + offset
);
353 /****************************************************************************
355 segment - Segment to load data from
356 offset - Offset to load data from
359 Byte value read from the absolute memory location.
361 NOTE: Do not inline this function as (*sys_rdX) is already inline!
362 ****************************************************************************/
363 u8
fetch_data_byte_abs(
368 if (CHECK_DATA_ACCESS())
369 x86emu_check_data_access(segment
, offset
);
371 return (*sys_rdb
)(((u32
)segment
<< 4) + offset
);
374 /****************************************************************************
376 segment - Segment to load data from
377 offset - Offset to load data from
380 Word value read from the absolute memory location.
382 NOTE: Do not inline this function as (*sys_rdX) is already inline!
383 ****************************************************************************/
384 u16
fetch_data_word_abs(
389 if (CHECK_DATA_ACCESS())
390 x86emu_check_data_access(segment
, offset
);
392 return (*sys_rdw
)(((u32
)segment
<< 4) + offset
);
395 /****************************************************************************
397 segment - Segment to load data from
398 offset - Offset to load data from
401 Long value read from the absolute memory location.
403 NOTE: Do not inline this function as (*sys_rdX) is already inline!
404 ****************************************************************************/
405 u32
fetch_data_long_abs(
410 if (CHECK_DATA_ACCESS())
411 x86emu_check_data_access(segment
, offset
);
413 return (*sys_rdl
)(((u32
)segment
<< 4) + offset
);
416 /****************************************************************************
418 offset - Offset to store data at
422 Writes a word value to an segmented memory location. The segment used is
423 the current 'default' segment, which may have been overridden.
425 NOTE: Do not inline this function as (*sys_wrX) is already inline!
426 ****************************************************************************/
427 void store_data_byte(
432 if (CHECK_DATA_ACCESS())
433 x86emu_check_data_access((u16
)get_data_segment(), offset
);
435 (*sys_wrb
)((get_data_segment() << 4) + offset
, val
);
438 /****************************************************************************
440 offset - Offset to store data at
444 Writes a word value to an segmented memory location. The segment used is
445 the current 'default' segment, which may have been overridden.
447 NOTE: Do not inline this function as (*sys_wrX) is already inline!
448 ****************************************************************************/
449 void store_data_word(
454 if (CHECK_DATA_ACCESS())
455 x86emu_check_data_access((u16
)get_data_segment(), offset
);
457 (*sys_wrw
)((get_data_segment() << 4) + offset
, val
);
460 /****************************************************************************
462 offset - Offset to store data at
466 Writes a long value to an segmented memory location. The segment used is
467 the current 'default' segment, which may have been overridden.
469 NOTE: Do not inline this function as (*sys_wrX) is already inline!
470 ****************************************************************************/
471 void store_data_long(
476 if (CHECK_DATA_ACCESS())
477 x86emu_check_data_access((u16
)get_data_segment(), offset
);
479 (*sys_wrl
)((get_data_segment() << 4) + offset
, val
);
482 /****************************************************************************
484 segment - Segment to store data at
485 offset - Offset to store data at
489 Writes a byte value to an absolute memory location.
491 NOTE: Do not inline this function as (*sys_wrX) is already inline!
492 ****************************************************************************/
493 void store_data_byte_abs(
499 if (CHECK_DATA_ACCESS())
500 x86emu_check_data_access(segment
, offset
);
502 (*sys_wrb
)(((u32
)segment
<< 4) + offset
, val
);
505 /****************************************************************************
507 segment - Segment to store data at
508 offset - Offset to store data at
512 Writes a word value to an absolute memory location.
514 NOTE: Do not inline this function as (*sys_wrX) is already inline!
515 ****************************************************************************/
516 void store_data_word_abs(
522 if (CHECK_DATA_ACCESS())
523 x86emu_check_data_access(segment
, offset
);
525 (*sys_wrw
)(((u32
)segment
<< 4) + offset
, val
);
528 /****************************************************************************
530 segment - Segment to store data at
531 offset - Offset to store data at
535 Writes a long value to an absolute memory location.
537 NOTE: Do not inline this function as (*sys_wrX) is already inline!
538 ****************************************************************************/
539 void store_data_long_abs(
545 if (CHECK_DATA_ACCESS())
546 x86emu_check_data_access(segment
, offset
);
548 (*sys_wrl
)(((u32
)segment
<< 4) + offset
, val
);
551 /****************************************************************************
553 reg - Register to decode
556 Pointer to the appropriate register
559 Return a pointer to the register given by the R/RM field of the
560 modrm byte, for byte operands. Also enables the decoding of instructions.
561 ****************************************************************************/
562 u8
* decode_rm_byte_register(
592 return NULL
; /* NOT REACHED OR REACHED ON ERROR */
595 /****************************************************************************
597 reg - Register to decode
600 Pointer to the appropriate register
603 Return a pointer to the register given by the R/RM field of the
604 modrm byte, for word operands. Also enables the decoding of instructions.
605 ****************************************************************************/
606 u16
* decode_rm_word_register(
636 return NULL
; /* NOTREACHED OR REACHED ON ERROR */
639 /****************************************************************************
641 reg - Register to decode
644 Pointer to the appropriate register
647 Return a pointer to the register given by the R/RM field of the
648 modrm byte, for dword operands. Also enables the decoding of instructions.
649 ****************************************************************************/
650 u32
* decode_rm_long_register(
655 DECODE_PRINTF("EAX");
658 DECODE_PRINTF("ECX");
661 DECODE_PRINTF("EDX");
664 DECODE_PRINTF("EBX");
667 DECODE_PRINTF("ESP");
670 DECODE_PRINTF("EBP");
673 DECODE_PRINTF("ESI");
676 DECODE_PRINTF("EDI");
680 return NULL
; /* NOTREACHED OR REACHED ON ERROR */
683 /****************************************************************************
685 reg - Register to decode
688 Pointer to the appropriate register
691 Return a pointer to the register given by the R/RM field of the
692 modrm byte, for word operands, modified from above for the weirdo
693 special case of segreg operands. Also enables the decoding of instructions.
694 ****************************************************************************/
695 u16
* decode_rm_seg_register(
719 DECODE_PRINTF("ILLEGAL SEGREG");
723 return NULL
; /* NOT REACHED OR REACHED ON ERROR */
726 /****************************************************************************
728 scale - scale value of SIB byte
729 index - index value of SIB byte
732 Value of scale * index
735 Decodes scale/index of SIB byte and returns relevant offset part of
737 ****************************************************************************/
738 static unsigned int decode_sib_si(
744 DECODE_PRINTF2("[%d*", scale
);
750 DECODE_PRINTF("EAX]");
751 return M
.x86
.R_EAX
* index
;
753 DECODE_PRINTF("ECX]");
754 return M
.x86
.R_ECX
* index
;
756 DECODE_PRINTF("EDX]");
757 return M
.x86
.R_EDX
* index
;
759 DECODE_PRINTF("EBX]");
760 return M
.x86
.R_EBX
* index
;
765 DECODE_PRINTF("EBP]");
766 return M
.x86
.R_EBP
* index
;
768 DECODE_PRINTF("ESI]");
769 return M
.x86
.R_ESI
* index
;
771 DECODE_PRINTF("EDI]");
772 return M
.x86
.R_EDI
* index
;
775 return 0; /* NOT REACHED OR REACHED ON ERROR */
778 /****************************************************************************
780 mod - MOD value of preceding ModR/M byte
783 Offset in memory for the address decoding
786 Decodes SIB addressing byte and returns calculated effective address.
787 ****************************************************************************/
788 static unsigned int decode_sib_address(
791 int sib
= fetch_byte_imm();
792 int ss
= (sib
>> 6) & 0x03;
793 int index
= (sib
>> 3) & 0x07;
794 int base
= sib
& 0x07;
800 DECODE_PRINTF("[EAX]");
801 offset
= M
.x86
.R_EAX
;
804 DECODE_PRINTF("[ECX]");
805 offset
= M
.x86
.R_ECX
;
808 DECODE_PRINTF("[EDX]");
809 offset
= M
.x86
.R_EDX
;
812 DECODE_PRINTF("[EBX]");
813 offset
= M
.x86
.R_EBX
;
816 DECODE_PRINTF("[ESP]");
817 offset
= M
.x86
.R_ESP
;
822 displacement
= (s32
)fetch_long_imm();
823 DECODE_PRINTF2("[%d]", displacement
);
824 offset
= displacement
;
827 displacement
= (s8
)fetch_byte_imm();
828 DECODE_PRINTF2("[%d][EBP]", displacement
);
829 offset
= M
.x86
.R_EBP
+ displacement
;
832 displacement
= (s32
)fetch_long_imm();
833 DECODE_PRINTF2("[%d][EBP]", displacement
);
834 offset
= M
.x86
.R_EBP
+ displacement
;
839 DECODE_PRINTF("[EAX]");
840 offset
= M
.x86
.R_EAX
;
843 DECODE_PRINTF("[ESI]");
844 offset
= M
.x86
.R_ESI
;
847 DECODE_PRINTF("[EDI]");
848 offset
= M
.x86
.R_EDI
;
853 offset
+= decode_sib_si(ss
, index
);
857 /****************************************************************************
859 rm - RM value to decode
862 Offset in memory for the address decoding
865 Return the offset given by mod=00 addressing. Also enables the
866 decoding of instructions.
868 NOTE: The code which specifies the corresponding segment (ds vs ss)
869 below in the case of [BP+..]. The assumption here is that at the
870 point that this subroutine is called, the bit corresponding to
871 SYSMODE_SEG_DS_SS will be zero. After every instruction
872 except the segment override instructions, this bit (as well
873 as any bits indicating segment overrides) will be clear. So
874 if a SS access is needed, set this bit. Otherwise, DS access
875 occurs (unless any of the segment override bits are set).
876 ****************************************************************************/
877 unsigned int decode_rm00_address(
882 if (M
.x86
.mode
& SYSMODE_PREFIX_ADDR
) {
883 /* 32-bit addressing */
886 DECODE_PRINTF("[EAX]");
889 DECODE_PRINTF("[ECX]");
892 DECODE_PRINTF("[EDX]");
895 DECODE_PRINTF("[EBX]");
898 return decode_sib_address(0);
900 offset
= fetch_long_imm();
901 DECODE_PRINTF2("[%08x]", offset
);
904 DECODE_PRINTF("[ESI]");
907 DECODE_PRINTF("[EDI]");
911 /* 16-bit addressing */
914 DECODE_PRINTF("[BX+SI]");
915 return (M
.x86
.R_BX
+ M
.x86
.R_SI
) & 0xffff;
917 DECODE_PRINTF("[BX+DI]");
918 return (M
.x86
.R_BX
+ M
.x86
.R_DI
) & 0xffff;
920 DECODE_PRINTF("[BP+SI]");
921 M
.x86
.mode
|= SYSMODE_SEG_DS_SS
;
922 return (M
.x86
.R_BP
+ M
.x86
.R_SI
) & 0xffff;
924 DECODE_PRINTF("[BP+DI]");
925 M
.x86
.mode
|= SYSMODE_SEG_DS_SS
;
926 return (M
.x86
.R_BP
+ M
.x86
.R_DI
) & 0xffff;
928 DECODE_PRINTF("[SI]");
931 DECODE_PRINTF("[DI]");
934 offset
= fetch_word_imm();
935 DECODE_PRINTF2("[%04x]", offset
);
938 DECODE_PRINTF("[BX]");
946 /****************************************************************************
948 rm - RM value to decode
951 Offset in memory for the address decoding
954 Return the offset given by mod=01 addressing. Also enables the
955 decoding of instructions.
956 ****************************************************************************/
957 unsigned int decode_rm01_address(
962 if (M
.x86
.mode
& SYSMODE_PREFIX_ADDR
) {
963 /* 32-bit addressing */
965 displacement
= (s8
)fetch_byte_imm();
971 DECODE_PRINTF2("%d[EAX]", displacement
);
972 return M
.x86
.R_EAX
+ displacement
;
974 DECODE_PRINTF2("%d[ECX]", displacement
);
975 return M
.x86
.R_ECX
+ displacement
;
977 DECODE_PRINTF2("%d[EDX]", displacement
);
978 return M
.x86
.R_EDX
+ displacement
;
980 DECODE_PRINTF2("%d[EBX]", displacement
);
981 return M
.x86
.R_EBX
+ displacement
;
983 int offset
= decode_sib_address(1);
984 displacement
= (s8
)fetch_byte_imm();
985 DECODE_PRINTF2("[%d]", displacement
);
986 return offset
+ displacement
;
989 DECODE_PRINTF2("%d[EBP]", displacement
);
990 return M
.x86
.R_EBP
+ displacement
;
992 DECODE_PRINTF2("%d[ESI]", displacement
);
993 return M
.x86
.R_ESI
+ displacement
;
995 DECODE_PRINTF2("%d[EDI]", displacement
);
996 return M
.x86
.R_EDI
+ displacement
;
999 /* 16-bit addressing */
1000 displacement
= (s8
)fetch_byte_imm();
1003 DECODE_PRINTF2("%d[BX+SI]", displacement
);
1004 return (M
.x86
.R_BX
+ M
.x86
.R_SI
+ displacement
) & 0xffff;
1006 DECODE_PRINTF2("%d[BX+DI]", displacement
);
1007 return (M
.x86
.R_BX
+ M
.x86
.R_DI
+ displacement
) & 0xffff;
1009 DECODE_PRINTF2("%d[BP+SI]", displacement
);
1010 M
.x86
.mode
|= SYSMODE_SEG_DS_SS
;
1011 return (M
.x86
.R_BP
+ M
.x86
.R_SI
+ displacement
) & 0xffff;
1013 DECODE_PRINTF2("%d[BP+DI]", displacement
);
1014 M
.x86
.mode
|= SYSMODE_SEG_DS_SS
;
1015 return (M
.x86
.R_BP
+ M
.x86
.R_DI
+ displacement
) & 0xffff;
1017 DECODE_PRINTF2("%d[SI]", displacement
);
1018 return (M
.x86
.R_SI
+ displacement
) & 0xffff;
1020 DECODE_PRINTF2("%d[DI]", displacement
);
1021 return (M
.x86
.R_DI
+ displacement
) & 0xffff;
1023 DECODE_PRINTF2("%d[BP]", displacement
);
1024 M
.x86
.mode
|= SYSMODE_SEG_DS_SS
;
1025 return (M
.x86
.R_BP
+ displacement
) & 0xffff;
1027 DECODE_PRINTF2("%d[BX]", displacement
);
1028 return (M
.x86
.R_BX
+ displacement
) & 0xffff;
1032 return 0; /* SHOULD NOT HAPPEN */
1035 /****************************************************************************
1037 rm - RM value to decode
1040 Offset in memory for the address decoding
1043 Return the offset given by mod=10 addressing. Also enables the
1044 decoding of instructions.
1045 ****************************************************************************/
1046 unsigned int decode_rm10_address(
1049 if (M
.x86
.mode
& SYSMODE_PREFIX_ADDR
) {
1052 /* 32-bit addressing */
1054 displacement
= (s32
)fetch_long_imm();
1060 DECODE_PRINTF2("%d[EAX]", displacement
);
1061 return M
.x86
.R_EAX
+ displacement
;
1063 DECODE_PRINTF2("%d[ECX]", displacement
);
1064 return M
.x86
.R_ECX
+ displacement
;
1066 DECODE_PRINTF2("%d[EDX]", displacement
);
1067 return M
.x86
.R_EDX
+ displacement
;
1069 DECODE_PRINTF2("%d[EBX]", displacement
);
1070 return M
.x86
.R_EBX
+ displacement
;
1072 int offset
= decode_sib_address(2);
1073 displacement
= (s32
)fetch_long_imm();
1074 DECODE_PRINTF2("[%d]", displacement
);
1075 return offset
+ displacement
;
1078 DECODE_PRINTF2("%d[EBP]", displacement
);
1079 return M
.x86
.R_EBP
+ displacement
;
1081 DECODE_PRINTF2("%d[ESI]", displacement
);
1082 return M
.x86
.R_ESI
+ displacement
;
1084 DECODE_PRINTF2("%d[EDI]", displacement
);
1085 return M
.x86
.R_EDI
+ displacement
;
1088 int displacement
= (s16
)fetch_word_imm();
1090 /* 16-bit addressing */
1093 DECODE_PRINTF2("%d[BX+SI]", displacement
);
1094 return (M
.x86
.R_BX
+ M
.x86
.R_SI
+ displacement
) & 0xffff;
1096 DECODE_PRINTF2("%d[BX+DI]", displacement
);
1097 return (M
.x86
.R_BX
+ M
.x86
.R_DI
+ displacement
) & 0xffff;
1099 DECODE_PRINTF2("%d[BP+SI]", displacement
);
1100 M
.x86
.mode
|= SYSMODE_SEG_DS_SS
;
1101 return (M
.x86
.R_BP
+ M
.x86
.R_SI
+ displacement
) & 0xffff;
1103 DECODE_PRINTF2("%d[BP+DI]", displacement
);
1104 M
.x86
.mode
|= SYSMODE_SEG_DS_SS
;
1105 return (M
.x86
.R_BP
+ M
.x86
.R_DI
+ displacement
) & 0xffff;
1107 DECODE_PRINTF2("%d[SI]", displacement
);
1108 return (M
.x86
.R_SI
+ displacement
) & 0xffff;
1110 DECODE_PRINTF2("%d[DI]", displacement
);
1111 return (M
.x86
.R_DI
+ displacement
) & 0xffff;
1113 DECODE_PRINTF2("%d[BP]", displacement
);
1114 M
.x86
.mode
|= SYSMODE_SEG_DS_SS
;
1115 return (M
.x86
.R_BP
+ displacement
) & 0xffff;
1117 DECODE_PRINTF2("%d[BX]", displacement
);
1118 return (M
.x86
.R_BX
+ displacement
) & 0xffff;
1122 return 0; /* SHOULD NOT HAPPEN */
1125 /****************************************************************************
1128 rm - RM value to decode
1131 Offset in memory for the address decoding, multiplexing calls to
1132 the decode_rmXX_address functions
1135 Return the offset given by "mod" addressing.
1136 ****************************************************************************/
1138 unsigned int decode_rmXX_address(int mod
, int rm
)
1141 return decode_rm00_address(rm
);
1143 return decode_rm01_address(rm
);
1144 return decode_rm10_address(rm
);