From: Avi Kivity Subject: [PATCH kvm-unit-tests 04/12] emulator: check for mov null, %ss Date: Wed, 27 Jun 2012 11:36:33 +0300 Message-ID: <1340786201-27881-5-git-send-email-avi@redhat.com> References: <1340786201-27881-1-git-send-email-avi@redhat.com> To: Marcelo Tosatti , kvm@vger.kernel.org Return-path: Received: from mx1.redhat.com ([209.132.183.28]:19285 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753877Ab2F0Igw (ORCPT ); Wed, 27 Jun 2012 04:36:52 -0400 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q5R8aqZu003504 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 27 Jun 2012 04:36:52 -0400 In-Reply-To: <1340786201-27881-1-git-send-email-avi@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: But check that rpl matches cpl. Signed-off-by: Avi Kivity --- x86/emulator.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/x86/emulator.c b/x86/emulator.c index 337429c..a18ba27 100644 --- a/x86/emulator.c +++ b/x86/emulator.c @@ -747,6 +747,33 @@ static void test_lgdt_lidt(volatile uint8_t *mem) report("lidt (long address)", orig.limit == fresh.limit && orig.base == fresh.base); } +static void ss_bad_rpl(struct ex_regs *regs) +{ + extern char ss_bad_rpl_cont; + + ++exceptions; + regs->rip = (ulong)&ss_bad_rpl_cont; +} + +static void test_sreg(volatile uint16_t *mem) +{ + u16 ss = read_ss(); + + // check for null segment load + *mem = 0; + asm volatile("mov %0, %%ss" : : "m"(*mem)); + report("mov null, %ss", read_ss() == 0); + + // check for exception when ss.rpl != cpl on null segment load + exceptions = 0; + handle_exception(GP_VECTOR, ss_bad_rpl); + *mem = 3; + asm volatile("mov %0, %%ss; ss_bad_rpl_cont:" : : "m"(*mem)); + report("mov null, %ss (with ss.rpl != cpl)", exceptions == 1 && read_ss() == 0); + handle_exception(GP_VECTOR, 0); + write_ss(ss); +} + int main() { void *mem; @@ -798,6 +825,7 @@ int main() test_rip_relative(mem, insn_ram); test_shld_shrd(mem); //test_lgdt_lidt(mem); + test_sreg(mem); test_mmx_movq_mf(mem, insn_page, alt_insn_page, insn_ram); -- 1.7.11