From patchwork Sun Aug 8 02:28:27 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mohammed Gamal X-Patchwork-Id: 118214 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.4/8.14.3) with ESMTP id o782Sr9q011964 for ; Sun, 8 Aug 2010 02:28:53 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751959Ab0HHC2v (ORCPT ); Sat, 7 Aug 2010 22:28:51 -0400 Received: from mail-wy0-f174.google.com ([74.125.82.174]:48351 "EHLO mail-wy0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750699Ab0HHC2u (ORCPT ); Sat, 7 Aug 2010 22:28:50 -0400 Received: by wyb39 with SMTP id 39so8954441wyb.19 for ; Sat, 07 Aug 2010 19:28:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:from:to:cc:subject:date :message-id:x-mailer:in-reply-to:references; bh=acg8qEAL+MeQYfbTKJLH0W3aFWKdsPeE+LgK5DlU+fw=; b=vn7J28o0FuqeSelmb7TmN2Hv5Y7k0O/9XjKogGDg5ct/XB+NayWdofR4H0wY+02ANO 3UVqYU0XK2zxAufu5PTf+saQK/tqBGtBexCBbbaDUAA2cvOCl728thIkl43oqPTVG2Yn /i7pC/zwQdEYOZWBBgDlI4/3VoiFTjMp3LRLQ= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; b=orV+A+3lOwRlFfocOEgUtJoJLv7W8/6fGLz3Scl9Nv/tf3Bi7ShbNiDxqUsY7aXIIi 3KRL4g0oBTOyR/2rirXsIZvYeDs0RaBRQO/0Vkl9bA+kB+ofIhgkCUgeXoWh6B1u76kL Z/8iPMZ/TsgV6f7C9BSE3vcg50TIcd4+iMtg0= Received: by 10.227.141.146 with SMTP id m18mr12144183wbu.34.1281234529585; Sat, 07 Aug 2010 19:28:49 -0700 (PDT) Received: from localhost.localdomain ([188.53.16.202]) by mx.google.com with ESMTPS id b18sm2888499wbb.13.2010.08.07.19.28.46 (version=TLSv1/SSLv3 cipher=RC4-MD5); Sat, 07 Aug 2010 19:28:49 -0700 (PDT) From: Mohammed Gamal To: avi@redhat.com Cc: mtosatti@redhat.com, kvm@vger.kernel.org, Mohammed Gamal Subject: [PATCH 3/3] test: Add real mode tests for div and idiv Date: Sun, 8 Aug 2010 05:28:27 +0300 Message-Id: <1281234507-9281-3-git-send-email-m.gamal005@gmail.com> X-Mailer: git-send-email 1.7.0.4 In-Reply-To: <1281234507-9281-1-git-send-email-m.gamal005@gmail.com> References: <1281234507-9281-1-git-send-email-m.gamal005@gmail.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Sun, 08 Aug 2010 02:28:53 +0000 (UTC) diff --git a/x86/realmode.c b/x86/realmode.c index 2ca2831..7b9fabe 100644 --- a/x86/realmode.c +++ b/x86/realmode.c @@ -1103,6 +1103,96 @@ void test_mul() print_serial("mul Test 3: PASS\n"); } +void test_div() +{ + struct regs inregs = { 0 }, outregs; + + MK_INSN(div8, "mov $257, %ax\n\t" + "mov $2, %cl\n\t" + "div %cl\n\t"); + + MK_INSN(div16, "mov $512, %ax\n\t" + "mov $5, %cx\n\t" + "div %cx\n\t"); + + MK_INSN(div32, "mov $512, %eax\n\t" + "mov $5, %ecx\n\t" + "div %ecx\n\t"); + + exec_in_big_real_mode(&inregs, &outregs, + insn_div8, + insn_div8_end - insn_div8); + + if (!regs_equal(&inregs, &outregs, R_AX | R_CX | R_DX) || outregs.eax != 384) + print_serial("div Test 1: FAIL\n"); + else + print_serial("div Test 1: PASS\n"); + + exec_in_big_real_mode(&inregs, &outregs, + insn_div16, + insn_div16_end - insn_div16); + + if (!regs_equal(&inregs, &outregs, R_AX | R_CX | R_DX) || outregs.eax != 102 || + outregs.edx != 2) + print_serial("div Test 2: FAIL\n"); + else + print_serial("div Test 2: PASS\n"); + + exec_in_big_real_mode(&inregs, &outregs, + insn_div32, + insn_div32_end - insn_div32); + + if (!regs_equal(&inregs, &outregs, R_AX | R_CX | R_DX) || outregs.eax != 102 || + outregs.edx != 2) + print_serial("div Test 3: FAIL\n"); + else + print_serial("div Test 3: PASS\n"); +} + +void test_idiv() +{ + struct regs inregs = { 0 }, outregs; + + MK_INSN(idiv8, "mov $256, %ax\n\t" + "mov $-2, %cl\n\t" + "idiv %cl\n\t"); + + MK_INSN(idiv16, "mov $512, %ax\n\t" + "mov $-2, %cx\n\t" + "idiv %cx\n\t"); + + MK_INSN(idiv32, "mov $512, %eax\n\t" + "mov $-2, %ecx\n\t" + "idiv %ecx\n\t"); + + exec_in_big_real_mode(&inregs, &outregs, + insn_idiv8, + insn_idiv8_end - insn_idiv8); + + if (!regs_equal(&inregs, &outregs, R_AX | R_CX | R_DX) || outregs.eax != (u8)-128) + print_serial("idiv Test 1: FAIL\n"); + else + print_serial("idiv Test 1: PASS\n"); + + exec_in_big_real_mode(&inregs, &outregs, + insn_idiv16, + insn_idiv16_end - insn_idiv16); + + if (!regs_equal(&inregs, &outregs, R_AX | R_CX | R_DX) || outregs.eax != (u16)-256) + print_serial("idiv Test 2: FAIL\n"); + else + print_serial("idiv Test 2: PASS\n"); + + exec_in_big_real_mode(&inregs, &outregs, + insn_idiv32, + insn_idiv32_end - insn_idiv32); + + if (!regs_equal(&inregs, &outregs, R_AX | R_CX | R_DX) || outregs.eax != (u32)-256) + print_serial("idiv Test 3: FAIL\n"); + else + print_serial("idiv Test 3: PASS\n"); +} + void realmode_start(void) { test_null(); @@ -1128,6 +1218,8 @@ void realmode_start(void) test_int(); test_imul(); test_mul(); + test_div(); + test_idiv(); exit(0); }