Always add the segment base when an override prefix is specified in segmented
mode. Otherwise the generated address is calculated incorrectly when an override
prefix is specified and HF_ADDSEG_MASK is not set.
Fixes: 55a15eb3504 ("target/i386/tcg: simplify effective address calculation")
Signed-off-by: Mark Cave-Ayland <[email protected]>
---
target/i386/tcg/translate.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
Paolo/Richard: I'm not sure if this patch is exactly correct, however it fixes
a regression when launching the OpenWatcom installer under MS-DOS. Current
git master aborts the installer with a GPF error in the guest caused by this
instruction:
0x0041e0b5: 66 2e 8e 1d 0c 00 00 00 movw %cs:0xc, %ds
where def_seg == 3, ovr_seg == 1 and ADDSEG(s) is 0. Without this fix the target
address is calculated as 0xc instead of 0x41e00c.
diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c
index 192cf43215e..323beec656b 100644
--- a/target/i386/tcg/translate.c
+++ b/target/i386/tcg/translate.c
@@ -600,12 +600,15 @@ static void gen_lea_v_seg_dest(DisasContext *s, MemOp
aflag, TCGv dest, TCGv a0,
{
int easize;
bool has_base;
+ bool addseg = ADDSEG(s);
if (ovr_seg < 0) {
ovr_seg = def_seg;
+ } else if (!CODE64(s)) {
+ addseg = true;
}
- has_base = ovr_seg >= R_FS || (ovr_seg >= 0 && ADDSEG(s));
+ has_base = ovr_seg >= R_FS || (ovr_seg >= 0 && addseg);
easize = CODE64(s) ? MO_64 : MO_32;
if (has_base) {
--
2.47.3