From 89e3472178c53d680912918d9f2d2c0b396a9807 Mon Sep 17 00:00:00 2001 From: Stanislav Shwartsman Date: Mon, 9 Jan 2006 19:34:52 +0000 Subject: [PATCH] Fix validate_seg_regs check --- bochs/cpu/cpu.h | 3 ++- bochs/cpu/segment_ctrl_pro.cc | 42 +++++++++++++++++------------------ 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/bochs/cpu/cpu.h b/bochs/cpu/cpu.h index 839f61d41..63197a2f5 100644 --- a/bochs/cpu/cpu.h +++ b/bochs/cpu/cpu.h @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: cpu.h,v 1.250 2005-12-19 17:58:08 sshwarts Exp $ +// $Id: cpu.h,v 1.251 2006-01-09 19:34:52 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2001 MandrakeSoft S.A. @@ -2754,6 +2754,7 @@ public: // for now... #if BX_SUPPORT_X86_64 BX_SMF void long_iret(bxInstruction_c *) BX_CPP_AttrRegparmN(1); #endif + BX_SMF void validate_seg_reg(unsigned seg); BX_SMF void validate_seg_regs(void); BX_SMF void stack_return_to_v86(Bit32u new_eip, Bit32u raw_cs_selector, Bit32u flags32); BX_SMF void iret16_stack_return_from_v86(bxInstruction_c *); diff --git a/bochs/cpu/segment_ctrl_pro.cc b/bochs/cpu/segment_ctrl_pro.cc index bc5cb2b47..e64ec474e 100644 --- a/bochs/cpu/segment_ctrl_pro.cc +++ b/bochs/cpu/segment_ctrl_pro.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: segment_ctrl_pro.cc,v 1.50 2005-12-12 19:44:06 sshwarts Exp $ +// $Id: segment_ctrl_pro.cc,v 1.51 2006-01-09 19:34:52 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2001 MandrakeSoft S.A. @@ -268,10 +268,8 @@ void BX_CPU_C::loadSRegLMNominal(unsigned segI, unsigned selector, bx_address ba } #endif -void BX_CPU_C::validate_seg_regs(void) +void BX_CPU_C::validate_seg_reg(unsigned seg) { - Bit8u cs_dpl = BX_CPU_THIS_PTR sregs[BX_SEG_REG_CS].cache.dpl; - /* FOR (seg = ES, DS, FS, GS) DO @@ -283,28 +281,28 @@ void BX_CPU_C::validate_seg_regs(void) END */ - if (BX_CPU_THIS_PTR sregs[BX_SEG_REG_ES].cache.dpl < cs_dpl) + bx_segment_reg_t *segment = &BX_CPU_THIS_PTR sregs[seg]; + + if (segment->cache.dpl < CPL) { - BX_CPU_THIS_PTR sregs[BX_SEG_REG_ES].cache.valid = 0; - BX_CPU_THIS_PTR sregs[BX_SEG_REG_ES].selector.value = 0; - } - if (BX_CPU_THIS_PTR sregs[BX_SEG_REG_DS].cache.dpl< cs_dpl) - { - BX_CPU_THIS_PTR sregs[BX_SEG_REG_DS].cache.valid = 0; - BX_CPU_THIS_PTR sregs[BX_SEG_REG_DS].selector.value = 0; - } - if (BX_CPU_THIS_PTR sregs[BX_SEG_REG_FS].cache.dpl < cs_dpl) - { - BX_CPU_THIS_PTR sregs[BX_SEG_REG_FS].cache.valid = 0; - BX_CPU_THIS_PTR sregs[BX_SEG_REG_FS].selector.value = 0; - } - if (BX_CPU_THIS_PTR sregs[BX_SEG_REG_GS].cache.dpl < cs_dpl) - { - BX_CPU_THIS_PTR sregs[BX_SEG_REG_GS].cache.valid = 0; - BX_CPU_THIS_PTR sregs[BX_SEG_REG_GS].selector.value = 0; + // invalidate if data or non-conforming code segment + if ((segment->cache.valid==0) || (segment->cache.segment==0) || + (segment->cache.u.segment.executable==0) || (segment->cache.u.segment.c_ed==0)) + { + segment->selector.value = 0; + segment->cache.valid = 0; + } } } +void BX_CPU_C::validate_seg_regs(void) +{ + validate_seg_reg(BX_SEG_REG_ES); + validate_seg_reg(BX_SEG_REG_DS); + validate_seg_reg(BX_SEG_REG_FS); + validate_seg_reg(BX_SEG_REG_GS); +} + #if BX_CPU_LEVEL >= 2 void BX_CPP_AttrRegparmN(2) BX_CPU_C::parse_selector(Bit16u raw_selector, bx_selector_t *selector)