From patchwork Thu May 23 20:43:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jan Bobek X-Patchwork-Id: 10958769 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3750A13AD for ; Thu, 23 May 2019 20:45:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 24BEC28767 for ; Thu, 23 May 2019 20:45:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1764E285D8; Thu, 23 May 2019 20:45:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C2E6A28767 for ; Thu, 23 May 2019 20:45:48 +0000 (UTC) Received: from localhost ([127.0.0.1]:43091 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTuay-0007CY-1P for patchwork-qemu-devel@patchwork.kernel.org; Thu, 23 May 2019 16:45:48 -0400 Received: from eggs.gnu.org ([209.51.188.92]:37300) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTuZg-0005wM-PI for qemu-devel@nongnu.org; Thu, 23 May 2019 16:44:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hTuZf-0002wD-C2 for qemu-devel@nongnu.org; Thu, 23 May 2019 16:44:28 -0400 Received: from mail-yw1-xc2d.google.com ([2607:f8b0:4864:20::c2d]:35896) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hTuZf-0002tm-7I for qemu-devel@nongnu.org; Thu, 23 May 2019 16:44:27 -0400 Received: by mail-yw1-xc2d.google.com with SMTP id e68so2793885ywf.3 for ; Thu, 23 May 2019 13:44:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=APMSNSqtnnFNaM+yj1wHvrpXrKFzgMoEIGWJUZ5RW6k=; b=JV4g+Jd9G4uHzV8WwmEzYOVJwTMSC+dLPipIHVzoLm2jZE7f9P69rq6hAAnOEmDW8h pMPKjNKGZfvpJz/lFSw5kbY99DPpwxUI8Q0ygc12vgLg5AdmRJhYsCw/HA8kgzE9YKDO xNab/Q1pckAdd/3pDmyCExvJ2WMQVN+w78h1CwUOvr5SrFHNsb7+l0OCb0zuN32ae8PM 9TViObmDTBdI42QjRX45F8fTJ1t9XEVMbwjj0MOnyxiil9BUDCaRFTE5YdSVYXa7pf64 s/TJz/vFUqnEiYpLJ0aKK17gYwMKEWFvwb/1k0rVWYPkCd5iq7pbB+ixO3MmoPsfjyCw WjZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=APMSNSqtnnFNaM+yj1wHvrpXrKFzgMoEIGWJUZ5RW6k=; b=aSP0kn+HHqRtMa4nA5e0RsiCfrcBzoRwEU1E6nsOh5Z+u37++tmsekuvhpw4BmBzj9 rqNyb8GI/vy0EVbLOoJo31Z+M5orz7+mEWByJiMpX9J/uTJRxISBS1kH4JfQmkzu56By TyRJmlapE7JP44yp2bNA33WdrUjf/Mf595Fz1ib65wWsRo/bMDG2rbC0krBi+yPxOTNN pf601D8IAnX42nt4H+IGugxZqWKGQqMJNauKAfj5iKQBU6hyYmUsENGL4r8c3cKiZfVO 0Oonokvu7tl90SxNMGtof9lkit+wv5tj5CI3flmgcNzkDi4E10djm9nYOQ5Gc4q9pfR4 5oLw== X-Gm-Message-State: APjAAAUtvLxLcQypFD5IUEoeN3fjoemBW0lV2Om2YqEgAHaJmd9sZDEy GL0Wxjjjw31yLllriFixUvtCDcFt X-Google-Smtp-Source: APXvYqwZ7n9EdgML+6JYE4JFsm1aoRSS4H2W3v35gCM3dJVf/PvS0H4ElHywFrgnxczTc7F2tczpAA== X-Received: by 2002:a81:300c:: with SMTP id w12mr47550161yww.57.1558644266428; Thu, 23 May 2019 13:44:26 -0700 (PDT) Received: from dionysus.attlocal.net (69-222-133-165.lightspeed.tukrga.sbcglobal.net. [69.222.133.165]) by smtp.gmail.com with ESMTPSA id p12sm87590ywg.72.2019.05.23.13.44.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 May 2019 13:44:25 -0700 (PDT) From: Jan Bobek To: qemu-devel@nongnu.org Date: Thu, 23 May 2019 16:43:59 -0400 Message-Id: <20190523204409.21068-2-jan.bobek@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190523204409.21068-1-jan.bobek@gmail.com> References: <20190523204409.21068-1-jan.bobek@gmail.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::c2d Subject: [Qemu-devel] [RISU v3 01/11] Makefile: undefine the arch name symbol X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jan Bobek , =?utf-8?q?Alex_Benn=C3=A9e?= , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP At least GCC defines the symbol "i386" to 1 to signal the target platform. We need to use "i386" as an undefined symbol in order to correctly include risu_reginfo_i386.h from risu.h. Add an -U option to the build command to make sure the symbol remains undefined. Suggested-by: Richard Henderson Reviewed-by: Alex Bennée Reviewed-by: Richard Henderson Signed-off-by: Jan Bobek --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 4aad448..b362dbe 100644 --- a/Makefile +++ b/Makefile @@ -17,7 +17,7 @@ VPATH=$(SRCDIR) CFLAGS ?= -g -ALL_CFLAGS = -Wall -D_GNU_SOURCE -DARCH=$(ARCH) $(BUILD_INC) $(CFLAGS) $(EXTRA_CFLAGS) +ALL_CFLAGS = -Wall -D_GNU_SOURCE -DARCH=$(ARCH) -U$(ARCH) $(BUILD_INC) $(CFLAGS) $(EXTRA_CFLAGS) PROG=risu SRCS=risu.c comms.c reginfo.c risu_$(ARCH).c risu_reginfo_$(ARCH).c From patchwork Thu May 23 20:44:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jan Bobek X-Patchwork-Id: 10958775 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5622714B6 for ; Thu, 23 May 2019 20:48:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 43611200DF for ; Thu, 23 May 2019 20:48:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 37B5E26E56; Thu, 23 May 2019 20:48:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C0A3D200DF for ; Thu, 23 May 2019 20:48:57 +0000 (UTC) Received: from localhost ([127.0.0.1]:43113 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTue1-00010h-2Z for patchwork-qemu-devel@patchwork.kernel.org; Thu, 23 May 2019 16:48:57 -0400 Received: from eggs.gnu.org ([209.51.188.92]:37317) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTuZj-0005yJ-Ox for qemu-devel@nongnu.org; Thu, 23 May 2019 16:44:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hTuZh-0002y0-Gs for qemu-devel@nongnu.org; Thu, 23 May 2019 16:44:31 -0400 Received: from mail-yw1-xc42.google.com ([2607:f8b0:4864:20::c42]:45608) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hTuZh-0002xM-4H for qemu-devel@nongnu.org; Thu, 23 May 2019 16:44:29 -0400 Received: by mail-yw1-xc42.google.com with SMTP id w18so2772920ywa.12 for ; Thu, 23 May 2019 13:44:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=1BkgmbBnhQ3KAFq5DgAQAGgNp6ECl3V3D5Qd7pmmCaE=; b=Pj4foZ+/mtylVuJ+ZQh9biP5oJWScNf5UGRBhb+Z5FJN0LWvUBRMh0SLZ9y2gQ1cwS zuD+dobZy4FX6OqcjGdwSl2AIf4K25eDJPnvrxDV2kdv5saa6CV4of0AOndAb9/e5c+P O6y40lnAFvhI+PXHZHqYgmPI0aBFJeg+QLsAw90g4cR4rcoiZknuHz/Bu/Aa3pWBcP35 HgTRvwSISH7unaxfjV9k7jogPxiDfuYQHJ8KQfQeOce7TLVAl2c61hcLX42IRnkZkTHR orhvXo0d7yIIIaxkWyGj63H3Q3PpkamZitQi+k2TgHXizRYDUymuTPnB4ZI4BdglNJNx r7JQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=1BkgmbBnhQ3KAFq5DgAQAGgNp6ECl3V3D5Qd7pmmCaE=; b=aHswg/vUOjbOQJsYcbcVrRWz6yGhyle72C7aF2ycJSMaMw6cshC8eY4xTWnNxZBi2a BtytyqBZy7NnI4XCARuGiI+rCcwzHxOHp8bs72drvxwfUmpfWiTXYVz+nELHlh9f1cUV PK+ag6aeWzZhSRcIKgF29Oj3kYiZcLqndJwHQEWsWSJAU4EILzUJN7PvHhzuoFbe/vyV LSf/yHDuBJZuhERlQ3LV+mhT1lLpTT1DpHWgVYu0UE+lGy+Mpd0Lydf9G6eofGOBHz+B 5dhM3xDrGP7xCO+aD7YG2W9g4hwdhwsnJ5hoQGCcDn+ho251ggXsZ5o8aPhQbzXtVNpc cxvQ== X-Gm-Message-State: APjAAAUietTf/mvSz7IGlE2dG2Z0qLSqsHOVivM+k00pPubmBnCR13Zv TsG+knkxlmzrTg5c5sJFuEQ0DxS3 X-Google-Smtp-Source: APXvYqzbY56sIs/BNnlLHq423Gj5R+OjXObRFtoz8XXpJVtDtYfENmoDXLc9OepMeX3PSVHn2Go3YQ== X-Received: by 2002:a81:7cc5:: with SMTP id x188mr6215839ywc.381.1558644268147; Thu, 23 May 2019 13:44:28 -0700 (PDT) Received: from dionysus.attlocal.net (69-222-133-165.lightspeed.tukrga.sbcglobal.net. [69.222.133.165]) by smtp.gmail.com with ESMTPSA id p12sm87590ywg.72.2019.05.23.13.44.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 May 2019 13:44:27 -0700 (PDT) From: Jan Bobek To: qemu-devel@nongnu.org Date: Thu, 23 May 2019 16:44:00 -0400 Message-Id: <20190523204409.21068-3-jan.bobek@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190523204409.21068-1-jan.bobek@gmail.com> References: <20190523204409.21068-1-jan.bobek@gmail.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::c42 Subject: [Qemu-devel] [RISU v3 02/11] risu_i386: move reginfo_t and related defines to risu_reginfo_i386.h X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jan Bobek , =?utf-8?q?Alex_Benn=C3=A9e?= , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP In order to build risu successfully for i386, we need files risu_reginfo_i386.{h,c}; this patch adds the former by extracting the relevant code from risu_i386.c. This patch is pure code motion; no functional changes were made. Reviewed-by: Alex Bennée Reviewed-by: Richard Henderson Signed-off-by: Jan Bobek --- risu_reginfo_i386.h | 37 +++++++++++++++++++++++++++++++++++++ risu_i386.c | 23 +---------------------- 2 files changed, 38 insertions(+), 22 deletions(-) create mode 100644 risu_reginfo_i386.h diff --git a/risu_reginfo_i386.h b/risu_reginfo_i386.h new file mode 100644 index 0000000..5bba439 --- /dev/null +++ b/risu_reginfo_i386.h @@ -0,0 +1,37 @@ +/******************************************************************************* + * Copyright (c) 2010 Linaro Limited + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Peter Maydell (Linaro) - initial implementation + ******************************************************************************/ + +#ifndef RISU_REGINFO_I386_H +#define RISU_REGINFO_I386_H + +/* This is the data structure we pass over the socket. + * It is a simplified and reduced subset of what can + * be obtained with a ucontext_t* + */ +struct reginfo { + uint32_t faulting_insn; + gregset_t gregs; +}; + +#ifndef REG_GS +/* Assume that either we get all these defines or none */ +# define REG_GS 0 +# define REG_FS 1 +# define REG_ES 2 +# define REG_DS 3 +# define REG_ESP 7 +# define REG_TRAPNO 12 +# define REG_EIP 14 +# define REG_EFL 16 +# define REG_UESP 17 +#endif /* !defined(REG_GS) */ + +#endif /* RISU_REGINFO_I386_H */ diff --git a/risu_i386.c b/risu_i386.c index 5e7e01d..6798a78 100644 --- a/risu_i386.c +++ b/risu_i386.c @@ -14,28 +14,7 @@ #include #include "risu.h" - -/* This is the data structure we pass over the socket. - * It is a simplified and reduced subset of what can - * be obtained with a ucontext_t* - */ -struct reginfo { - uint32_t faulting_insn; - gregset_t gregs; -}; - -#ifndef REG_GS -/* Assume that either we get all these defines or none */ -#define REG_GS 0 -#define REG_FS 1 -#define REG_ES 2 -#define REG_DS 3 -#define REG_ESP 7 -#define REG_TRAPNO 12 -#define REG_EIP 14 -#define REG_EFL 16 -#define REG_UESP 17 -#endif +#include "risu_reginfo_i386.h" struct reginfo master_ri, apprentice_ri; From patchwork Thu May 23 20:44:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jan Bobek X-Patchwork-Id: 10958771 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F264F14B6 for ; Thu, 23 May 2019 20:46:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DEB0D2807B for ; Thu, 23 May 2019 20:46:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D1C8C284AF; Thu, 23 May 2019 20:46:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id AA3562807B for ; Thu, 23 May 2019 20:46:01 +0000 (UTC) Received: from localhost ([127.0.0.1]:43093 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTubA-0007PY-VA for patchwork-qemu-devel@patchwork.kernel.org; Thu, 23 May 2019 16:46:00 -0400 Received: from eggs.gnu.org ([209.51.188.92]:37332) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTuZn-00061J-IA for qemu-devel@nongnu.org; Thu, 23 May 2019 16:44:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hTuZj-0002zt-Q7 for qemu-devel@nongnu.org; Thu, 23 May 2019 16:44:33 -0400 Received: from mail-yb1-xb43.google.com ([2607:f8b0:4864:20::b43]:33774) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hTuZi-0002yQ-De for qemu-devel@nongnu.org; Thu, 23 May 2019 16:44:31 -0400 Received: by mail-yb1-xb43.google.com with SMTP id w127so923166yba.0 for ; Thu, 23 May 2019 13:44:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=LLAjkendyCCLXqfpTYsTCZfUvlnmPcJC9iKwt8jzfEU=; b=LaFtcPSz5Z7d4hOwdFL2n/TzIHXq5p+GaPfe0yaYBUzpPybqrLR0fGjaTayr2nLlvW TINZmupoiZV+6nIZiUO17KB1Dn8CGx1Qt7127YWYmOPeRFh+YX7kPib3A7y+NPC9b333 0QgEyyeVZn1bprty/7RgnBaJUWAKEe7Fr3Kg/gxW5zzqnCFg/pKgwqGxDJ2ubHwx34QC 325eVBnyilobLuqUe7BRiqr0ZPpWdjoIGlLDxTxFdpi4Yn49uEf1eERc3FtYvoiIBUFS 0Ebi/psNYxS+ND1dNU/kDiUbY9pokLmuu+IzmGkpfxL0ROcthVsbJ3x1UhJiyrFQMnR0 u2Ag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=LLAjkendyCCLXqfpTYsTCZfUvlnmPcJC9iKwt8jzfEU=; b=U7f5O3aV3TuJAQUaWvH5m745rIm8Qu+mBDkMdNGhFiiFwqi70YM//0IdcCJch2uj1H kf6Lw0pVNEqJ/bLh4Jp0dPAJncqKPSC2xsv/3EvARXzl8UeYhpVC2RP78/Swbn+idCaK ad8SbpfBrEFgbdjgdhUN7TnMKoSjZJopWXkNe9CR3bO7eHRpJZuc2tCOfmlrO2/gnAoO pXEKis32hNppAqgJAwF4gxeCZBxv0B8oDfozf9Mh5bcycVJDsy9IBth8hDJ/7YlMQEkn 4Ggt5l3kkCTl8ppHBDc/aXYzhTVvVk8rz7tXhwJiweE3ZUhbiekphTZc9d5NJY6RbSWo CmxQ== X-Gm-Message-State: APjAAAW3SDlteSgXz0CTc1El1LwUV5TIAsnjkEWXpPLOPUXS6qdxEzsx LIq+EdQbPwFrjxX5nmoaz3FVnMbR X-Google-Smtp-Source: APXvYqzALE5y5yGNAofxJf8PgYr8o7vfs37hmxplafbF8QNX+ay07rxUSYIj85cShjhAZ5HykEqpRw== X-Received: by 2002:a25:cac6:: with SMTP id a189mr1069901ybg.74.1558644269385; Thu, 23 May 2019 13:44:29 -0700 (PDT) Received: from dionysus.attlocal.net (69-222-133-165.lightspeed.tukrga.sbcglobal.net. [69.222.133.165]) by smtp.gmail.com with ESMTPSA id p12sm87590ywg.72.2019.05.23.13.44.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 May 2019 13:44:28 -0700 (PDT) From: Jan Bobek To: qemu-devel@nongnu.org Date: Thu, 23 May 2019 16:44:01 -0400 Message-Id: <20190523204409.21068-4-jan.bobek@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190523204409.21068-1-jan.bobek@gmail.com> References: <20190523204409.21068-1-jan.bobek@gmail.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::b43 Subject: [Qemu-devel] [RISU v3 03/11] risu_i386: move reginfo-related code to risu_reginfo_i386.c X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jan Bobek , =?utf-8?q?Alex_Benn=C3=A9e?= , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP In order to build risu successfully for i386, we need files risu_reginfo_i386.{h,c}; this patch adds the latter by extracting the relevant code from risu_i386.c. This patch is pure code motion; no functional changes were made. Reviewed-by: Alex Bennée Reviewed-by: Richard Henderson Signed-off-by: Jan Bobek --- risu_i386.c | 54 ----------------------------------- risu_reginfo_i386.c | 68 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 54 deletions(-) create mode 100644 risu_reginfo_i386.c diff --git a/risu_i386.c b/risu_i386.c index 6798a78..2d2f325 100644 --- a/risu_i386.c +++ b/risu_i386.c @@ -33,43 +33,6 @@ void advance_pc(void *vuc) uc->uc_mcontext.gregs[REG_EIP] += 2; } -static void fill_reginfo(struct reginfo *ri, ucontext_t * uc) -{ - int i; - for (i = 0; i < NGREG; i++) { - switch (i) { - case REG_ESP: - case REG_UESP: - case REG_GS: - case REG_FS: - case REG_ES: - case REG_DS: - case REG_TRAPNO: - case REG_EFL: - /* Don't store these registers as it results in mismatches. - * In particular valgrind has different values for some - * segment registers, and they're boring anyway. - * We really shouldn't be ignoring EFL but valgrind doesn't - * seem to set it right and I don't care to investigate. - */ - ri->gregs[i] = 0xDEADBEEF; - break; - case REG_EIP: - /* Store the offset from the start of the test image */ - ri->gregs[i] = uc->uc_mcontext.gregs[i] - image_start_address; - break; - default: - ri->gregs[i] = uc->uc_mcontext.gregs[i]; - break; - } - } - /* x86 insns aren't 32 bit but we're not really testing x86 so - * this is just to distinguish 'do compare' from 'stop' - */ - ri->faulting_insn = *((uint32_t *) uc->uc_mcontext.gregs[REG_EIP]); -} - - int send_register_info(int sock, void *uc) { struct reginfo ri; @@ -100,23 +63,6 @@ int recv_and_compare_register_info(int sock, void *uc) return resp; } -static char *regname[] = { - "GS", "FS", "ES", "DS", "EDI", "ESI", "EBP", "ESP", - "EBX", "EDX", "ECX", "EAX", "TRAPNO", "ERR", "EIP", - "CS", "EFL", "UESP", "SS", 0 -}; - -static void dump_reginfo(struct reginfo *ri) -{ - int i; - fprintf(stderr, " faulting insn %x\n", ri->faulting_insn); - for (i = 0; i < NGREG; i++) { - fprintf(stderr, " %s: %x\n", regname[i] ? regname[i] : "???", - ri->gregs[i]); - } -} - - /* Print a useful report on the status of the last comparison * done in recv_and_compare_register_info(). This is called on * exit, so need not restrict itself to signal-safe functions. diff --git a/risu_reginfo_i386.c b/risu_reginfo_i386.c new file mode 100644 index 0000000..e8d671f --- /dev/null +++ b/risu_reginfo_i386.c @@ -0,0 +1,68 @@ +/******************************************************************************* + * Copyright (c) 2010 Linaro Limited + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Peter Maydell (Linaro) - initial implementation + ******************************************************************************/ + +#include +#include + +#include "risu.h" +#include "risu_reginfo_i386.h" + +static void fill_reginfo(struct reginfo *ri, ucontext_t * uc) +{ + int i; + for (i = 0; i < NGREG; i++) { + switch (i) { + case REG_ESP: + case REG_UESP: + case REG_GS: + case REG_FS: + case REG_ES: + case REG_DS: + case REG_TRAPNO: + case REG_EFL: + /* Don't store these registers as it results in mismatches. + * In particular valgrind has different values for some + * segment registers, and they're boring anyway. + * We really shouldn't be ignoring EFL but valgrind doesn't + * seem to set it right and I don't care to investigate. + */ + ri->gregs[i] = 0xDEADBEEF; + break; + case REG_EIP: + /* Store the offset from the start of the test image */ + ri->gregs[i] = uc->uc_mcontext.gregs[i] - image_start_address; + break; + default: + ri->gregs[i] = uc->uc_mcontext.gregs[i]; + break; + } + } + /* x86 insns aren't 32 bit but we're not really testing x86 so + * this is just to distinguish 'do compare' from 'stop' + */ + ri->faulting_insn = *((uint32_t *) uc->uc_mcontext.gregs[REG_EIP]); +} + +static char *regname[] = { + "GS", "FS", "ES", "DS", "EDI", "ESI", "EBP", "ESP", + "EBX", "EDX", "ECX", "EAX", "TRAPNO", "ERR", "EIP", + "CS", "EFL", "UESP", "SS", 0 +}; + +static void dump_reginfo(struct reginfo *ri) +{ + int i; + fprintf(stderr, " faulting insn %x\n", ri->faulting_insn); + for (i = 0; i < NGREG; i++) { + fprintf(stderr, " %s: %x\n", regname[i] ? regname[i] : "???", + ri->gregs[i]); + } +} From patchwork Thu May 23 20:44:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jan Bobek X-Patchwork-Id: 10958781 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EA07713AD for ; Thu, 23 May 2019 20:49:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D78FF200DF for ; Thu, 23 May 2019 20:49:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CBD0A26E56; Thu, 23 May 2019 20:49:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 2E2D1200DF for ; Thu, 23 May 2019 20:49:24 +0000 (UTC) Received: from localhost ([127.0.0.1]:43119 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTueR-0001Lz-G0 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 23 May 2019 16:49:23 -0400 Received: from eggs.gnu.org ([209.51.188.92]:37381) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTuZr-00064W-FQ for qemu-devel@nongnu.org; Thu, 23 May 2019 16:44:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hTuZp-000362-Is for qemu-devel@nongnu.org; Thu, 23 May 2019 16:44:39 -0400 Received: from mail-yw1-xc43.google.com ([2607:f8b0:4864:20::c43]:42415) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hTuZp-00030k-63 for qemu-devel@nongnu.org; Thu, 23 May 2019 16:44:37 -0400 Received: by mail-yw1-xc43.google.com with SMTP id s5so2780904ywd.9 for ; Thu, 23 May 2019 13:44:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=aODOLM3NOnu56JKijoWk061uBitwLRabA4Po4UrCVRU=; b=ANYlbfUEWYQgbUCsFIcX4Vh0BrMTTf6WphjMjJN52U3v9s6w/PJWKYLBcQiO5Bm5W2 NpqH926IMiFjk0X0PcnaPktGVmbG1rb2IfFwdvyqV8AO4ax8CQVB169bjRdZQIsT5hD+ e1A3VrTwlk7EAwy3KiEUwuRFkpjYXtIx4Ni+7ahXR0uoiy34sbvElMcq1IgXEhUVNDz/ AskDVebsvEKcoBgbPO1VnsDwpmeqom/Jf1snlCmniADJgWC5NWes/IvNwy7qaW70Z6kd ditWTi15IyMwD481VTqUGPMNyvWU4joFxMzDzlk9jBObITDCJK/3pTYaOtAPdYBECMNQ 0q+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=aODOLM3NOnu56JKijoWk061uBitwLRabA4Po4UrCVRU=; b=YoQylO7HEKtWHWg/f0gbkgsuTxruvfLzCZL9Ho8SjUI5ZpU5hKPKsf07Olt3hmNW+Z q4miN0jCNhbHRqJtO48sxazlbHVsVx3VUOO7w95xdu2kx2lnC9iJ95Luxrq+AYaN1v8X ibK/Zig6CUZvom/RlqIojMyJddKNRublBikAYlvoRGML3IZkK8Bxx3wwB2Gi7nxHv0ps +K1J9tglq+N+/i3A5mpQIC/bTLXBNKtdMzc3VvBY4EOu6fa4h/k6enN4DYvkaArwl8rq 7cYymGVWFLuvYcg3gsyjARj8UHl2pGsBNmx/Mxw+thhOuBH71YfkgrXEZ5AUu8m39g4w +u5Q== X-Gm-Message-State: APjAAAVpuOnFp+aPngCVNWFNreXsjYPRPjadE+rYuYoBdtxO9EV3UoV2 Tyoc80waJ0DkHbEmnxAg/PNLsd50 X-Google-Smtp-Source: APXvYqwepg/w0SlHOAzbaYRP7cp+qwxdpnJxMAUq5QgI849Y+p2gN0l9cHTALhkeOxP4jZFhYv9G8g== X-Received: by 2002:a0d:db91:: with SMTP id d139mr25144807ywe.300.1558644272326; Thu, 23 May 2019 13:44:32 -0700 (PDT) Received: from dionysus.attlocal.net (69-222-133-165.lightspeed.tukrga.sbcglobal.net. [69.222.133.165]) by smtp.gmail.com with ESMTPSA id p12sm87590ywg.72.2019.05.23.13.44.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 May 2019 13:44:31 -0700 (PDT) From: Jan Bobek To: qemu-devel@nongnu.org Date: Thu, 23 May 2019 16:44:02 -0400 Message-Id: <20190523204409.21068-5-jan.bobek@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190523204409.21068-1-jan.bobek@gmail.com> References: <20190523204409.21068-1-jan.bobek@gmail.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::c43 Subject: [Qemu-devel] [RISU v3 04/11] risu_reginfo_i386: implement arch-specific reginfo interface X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jan Bobek , =?utf-8?q?Alex_Benn=C3=A9e?= , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP CPU-specific code in risu_reginfo_* is expected to define and export the following symbols: - arch_long_opts, arch_extra_help, process_arch_opt - reginfo_size - reginfo_init - reginfo_is_eq - reginfo_dump, reginfo_dump_mismatch Make risu_reginfo_i386.c implement this interface; and while we're at it, expand the support to x86_64 as well. Suggested-by: Richard Henderson Reviewed-by: Alex Bennée Reviewed-by: Richard Henderson Signed-off-by: Jan Bobek --- risu_reginfo_i386.h | 24 ++++---- risu_reginfo_i386.c | 147 ++++++++++++++++++++++++++++++++++---------- 2 files changed, 127 insertions(+), 44 deletions(-) diff --git a/risu_reginfo_i386.h b/risu_reginfo_i386.h index 5bba439..e350f01 100644 --- a/risu_reginfo_i386.h +++ b/risu_reginfo_i386.h @@ -12,7 +12,8 @@ #ifndef RISU_REGINFO_I386_H #define RISU_REGINFO_I386_H -/* This is the data structure we pass over the socket. +/* + * This is the data structure we pass over the socket. * It is a simplified and reduced subset of what can * be obtained with a ucontext_t* */ @@ -21,17 +22,14 @@ struct reginfo { gregset_t gregs; }; -#ifndef REG_GS -/* Assume that either we get all these defines or none */ -# define REG_GS 0 -# define REG_FS 1 -# define REG_ES 2 -# define REG_DS 3 -# define REG_ESP 7 -# define REG_TRAPNO 12 -# define REG_EIP 14 -# define REG_EFL 16 -# define REG_UESP 17 -#endif /* !defined(REG_GS) */ +/* + * For i386, the defines are named REG_EAX, etc. + * For x86_64, the defines are named REG_RAX, etc. + */ +#ifdef __x86_64__ +# define REG_E(X) REG_R##X +#else +# define REG_E(X) REG_E##X +#endif #endif /* RISU_REGINFO_I386_H */ diff --git a/risu_reginfo_i386.c b/risu_reginfo_i386.c index e8d671f..c4dc14a 100644 --- a/risu_reginfo_i386.c +++ b/risu_reginfo_i386.c @@ -10,59 +10,144 @@ ******************************************************************************/ #include +#include +#include #include +#include #include "risu.h" #include "risu_reginfo_i386.h" -static void fill_reginfo(struct reginfo *ri, ucontext_t * uc) +const struct option * const arch_long_opts; +const char * const arch_extra_help; + +void process_arch_opt(int opt, const char *arg) +{ + abort(); +} + +const int reginfo_size(void) +{ + return sizeof(struct reginfo); +} + +/* reginfo_init: initialize with a ucontext */ +void reginfo_init(struct reginfo *ri, ucontext_t *uc) { int i; + + memset(ri, 0, sizeof(*ri)); + for (i = 0; i < NGREG; i++) { switch (i) { - case REG_ESP: - case REG_UESP: - case REG_GS: - case REG_FS: - case REG_ES: - case REG_DS: - case REG_TRAPNO: - case REG_EFL: - /* Don't store these registers as it results in mismatches. - * In particular valgrind has different values for some - * segment registers, and they're boring anyway. - * We really shouldn't be ignoring EFL but valgrind doesn't - * seem to set it right and I don't care to investigate. - */ - ri->gregs[i] = 0xDEADBEEF; - break; - case REG_EIP: - /* Store the offset from the start of the test image */ + case REG_E(IP): + /* Store the offset from the start of the test image. */ ri->gregs[i] = uc->uc_mcontext.gregs[i] - image_start_address; break; - default: + case REG_EFL: + /* Store only the "flaggy" bits: SF, ZF, AF, PF, CF. */ + ri->gregs[i] = uc->uc_mcontext.gregs[i] & 0xd5; + break; + case REG_E(SP): + /* Ignore the stack. */ + ri->gregs[i] = 0xdeadbeef; + break; + case REG_E(AX): + case REG_E(BX): + case REG_E(CX): + case REG_E(DX): + case REG_E(DI): + case REG_E(SI): + case REG_E(BP): +#ifdef __x86_64__ + case REG_R8: + case REG_R9: + case REG_R10: + case REG_R11: + case REG_R12: + case REG_R13: + case REG_R14: + case REG_R15: +#endif ri->gregs[i] = uc->uc_mcontext.gregs[i]; break; } } - /* x86 insns aren't 32 bit but we're not really testing x86 so - * this is just to distinguish 'do compare' from 'stop' + + /* + * x86 insns aren't 32 bit but 3 bytes are sufficient to + * distinguish 'do compare' from 'stop'. */ - ri->faulting_insn = *((uint32_t *) uc->uc_mcontext.gregs[REG_EIP]); + ri->faulting_insn = *(uint32_t *)uc->uc_mcontext.gregs[REG_E(IP)]; } -static char *regname[] = { - "GS", "FS", "ES", "DS", "EDI", "ESI", "EBP", "ESP", - "EBX", "EDX", "ECX", "EAX", "TRAPNO", "ERR", "EIP", - "CS", "EFL", "UESP", "SS", 0 +/* reginfo_is_eq: compare the reginfo structs, returns nonzero if equal */ +int reginfo_is_eq(struct reginfo *m, struct reginfo *a) +{ + return 0 == memcmp(m, a, sizeof(*m)); +} + +static const char *const regname[NGREG] = { + [REG_EFL] = "eflags", +#ifdef __x86_64__ + [REG_RIP] = "rip", + [REG_RAX] = "rax", + [REG_RBX] = "rbx", + [REG_RCX] = "rcx", + [REG_RDX] = "rdx", + [REG_RDI] = "rdi", + [REG_RSI] = "rsi", + [REG_RBP] = "rbp", + [REG_RSP] = "rsp", + [REG_R8] = "r8", + [REG_R9] = "r9", + [REG_R10] = "r10", + [REG_R11] = "r11", + [REG_R12] = "r12", + [REG_R13] = "r13", + [REG_R14] = "r14", + [REG_R15] = "r15", +#else + [REG_EIP] = "eip", + [REG_EAX] = "eax", + [REG_EBX] = "ebx", + [REG_ECX] = "ecx", + [REG_EDX] = "edx", + [REG_EDI] = "edi", + [REG_ESI] = "esi", + [REG_EBP] = "ebp", + [REG_ESP] = "esp", +#endif }; -static void dump_reginfo(struct reginfo *ri) +#ifdef __x86_64__ +# define PRIxREG "%016llx" +#else +# define PRIxREG "%08x" +#endif + +/* reginfo_dump: print state to a stream, returns nonzero on success */ +int reginfo_dump(struct reginfo *ri, FILE *f) { int i; - fprintf(stderr, " faulting insn %x\n", ri->faulting_insn); + fprintf(f, " faulting insn %x\n", ri->faulting_insn); for (i = 0; i < NGREG; i++) { - fprintf(stderr, " %s: %x\n", regname[i] ? regname[i] : "???", - ri->gregs[i]); + if (regname[i]) { + fprintf(f, " %-6s: " PRIxREG "\n", regname[i], ri->gregs[i]); + } } + return !ferror(f); +} + +int reginfo_dump_mismatch(struct reginfo *m, struct reginfo *a, FILE *f) +{ + int i; + for (i = 0; i < NGREG; i++) { + if (m->gregs[i] != a->gregs[i]) { + assert(regname[i]); + fprintf(f, "Mismatch: %s: " PRIxREG " v " PRIxREG "\n", + regname[i], m->gregs[i], a->gregs[i]); + } + } + return !ferror(f); } From patchwork Thu May 23 20:44:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jan Bobek X-Patchwork-Id: 10958779 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D1F2013AD for ; Thu, 23 May 2019 20:49:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C0489200DF for ; Thu, 23 May 2019 20:49:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B4DF526E56; Thu, 23 May 2019 20:49:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 63A4F200DF for ; Thu, 23 May 2019 20:49:22 +0000 (UTC) Received: from localhost ([127.0.0.1]:43117 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTueP-0001Jp-O5 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 23 May 2019 16:49:21 -0400 Received: from eggs.gnu.org ([209.51.188.92]:37398) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTuZt-00066C-EI for qemu-devel@nongnu.org; Thu, 23 May 2019 16:44:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hTuZr-00039p-EB for qemu-devel@nongnu.org; Thu, 23 May 2019 16:44:41 -0400 Received: from mail-yb1-xb44.google.com ([2607:f8b0:4864:20::b44]:41858) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hTuZp-00031p-EX for qemu-devel@nongnu.org; Thu, 23 May 2019 16:44:37 -0400 Received: by mail-yb1-xb44.google.com with SMTP id d2so2783293ybh.8 for ; Thu, 23 May 2019 13:44:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=OnMHZ0fdYIXqikgMNKphGLIOokAtEwVDQyD+tAg9EUc=; b=FOpxkuiLmyiUfliFGoath1TzofiBGDO+2qccUdK2Mq+8TzGuYqAcBfE0JRXgmG3WBz Zxj+sOAc/Ndis9bhcGChu6NhwqhoEzXw2vMZQ8FKnIvX1PJuCvaTqxD+S+ypMjtNbFw0 p5SMMFtxEMMmYTJ+60T19DdXy7rvkmnwQSQqiCjLy9qJUx8M2drGNv++EO38x2d+Xgik WOQsPaY6yJ+nLoV2qyQdNsBpDuaa2ykWO40DZlhypPsrb95Jh0XPQWgij5zM/+68y/JF WGOIb+WHUKAsJHJKfgV9OmznUpFTFALjumZXt3HcXwbKQGfyYZIisHF4owdAWR8PII7n jEbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=OnMHZ0fdYIXqikgMNKphGLIOokAtEwVDQyD+tAg9EUc=; b=NgLWQaKgQvhtBTFdTxv1VYqkPUSG71rB+o6ycHmzKiJZAVgjkaRJzhpCpBobOdKAzv qKszdf7/MCb89eTS1FNruurrr19WKJNMAyQ7Wr/KV8O6JyEdizGUsokKSbh/4LAegd+e Q64I/bzgzOMDTJv6kwVTN9N+zEIU8FMhA7f7Aeic451Nv/nYT/y5VJAW4aOr3aqs636K 4f7Ti7Lmk2XoKPwDtn0na+/S3WM1zr6U+dclUhO1m6MvVMhKpZnoGmRtPvPt+HbC8Ts2 ie1IiFi8WsTUQtUC2w6H9bqYcyv0j3uB4Yed0Qo2cKEMY81E82T0lb83jDnJ9c10DesH 1b8g== X-Gm-Message-State: APjAAAWk7fqfeX5oNk1Jw0fDqAr3kLFUa04VI8Y+GP6tWX+UlY879s5Q Ax0EcBL2eAnH6KOFbsEwlSnezxCk X-Google-Smtp-Source: APXvYqxRPhec6oKkwVoPPUpAwDTWE7/4UBTRvgqZ+0HfsilI0Ger5lJl8O6oAOBUqnjsESYXh5lZJg== X-Received: by 2002:a5b:707:: with SMTP id g7mr45570918ybq.267.1558644272992; Thu, 23 May 2019 13:44:32 -0700 (PDT) Received: from dionysus.attlocal.net (69-222-133-165.lightspeed.tukrga.sbcglobal.net. [69.222.133.165]) by smtp.gmail.com with ESMTPSA id p12sm87590ywg.72.2019.05.23.13.44.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 May 2019 13:44:32 -0700 (PDT) From: Jan Bobek To: qemu-devel@nongnu.org Date: Thu, 23 May 2019 16:44:03 -0400 Message-Id: <20190523204409.21068-6-jan.bobek@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190523204409.21068-1-jan.bobek@gmail.com> References: <20190523204409.21068-1-jan.bobek@gmail.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::b44 Subject: [Qemu-devel] [RISU v3 05/11] risu_i386: implement missing CPU-specific functions X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jan Bobek , =?utf-8?q?Alex_Benn=C3=A9e?= , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP risu_i386.c is expected to implement the following functions: - advance_pc - get_reginfo_paramreg, set_ucontext_paramreg - get_risuop - get_pc This patch adds the necessary code. We use EAX as the parameter register and opcode "UD1 %xxx,%eax" for triggering RISU actions. Suggested-by: Richard Henderson Reviewed-by: Alex Bennée Reviewed-by: Richard Henderson Signed-off-by: Jan Bobek --- risu_i386.c | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/risu_i386.c b/risu_i386.c index 2d2f325..06d95e5 100644 --- a/risu_i386.c +++ b/risu_i386.c @@ -25,12 +25,37 @@ static int insn_is_ud2(uint32_t insn) void advance_pc(void *vuc) { - /* We assume that this is either UD1 or UD2. - * This would need tweaking if we want to test - * expected undefs on x86. + ucontext_t *uc = (ucontext_t *) vuc; + + /* + * We assume that this is UD1 as per get_risuop below. + * This would need tweaking if we want to test expected undefs. */ - ucontext_t *uc = vuc; - uc->uc_mcontext.gregs[REG_EIP] += 2; + uc->uc_mcontext.gregs[REG_E(IP)] += 3; +} + +void set_ucontext_paramreg(void *vuc, uint64_t value) +{ + ucontext_t *uc = (ucontext_t *) vuc; + uc->uc_mcontext.gregs[REG_E(AX)] = value; +} + +uint64_t get_reginfo_paramreg(struct reginfo *ri) +{ + return ri->gregs[REG_E(AX)]; +} + +int get_risuop(struct reginfo *ri) +{ + if ((ri->faulting_insn & 0xf8ffff) == 0xc0b90f) { /* UD1 %xxx,%eax */ + return (ri->faulting_insn >> 16) & 7; + } + return -1; +} + +uintptr_t get_pc(struct reginfo *ri) +{ + return ri->gregs[REG_E(IP)]; } int send_register_info(int sock, void *uc) From patchwork Thu May 23 20:44:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jan Bobek X-Patchwork-Id: 10958773 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5782014B6 for ; Thu, 23 May 2019 20:46:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 44D682807B for ; Thu, 23 May 2019 20:46:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 38F9E284AF; Thu, 23 May 2019 20:46:07 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 5EA472807B for ; Thu, 23 May 2019 20:46:05 +0000 (UTC) Received: from localhost ([127.0.0.1]:43095 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTubE-0007Rl-Md for patchwork-qemu-devel@patchwork.kernel.org; Thu, 23 May 2019 16:46:04 -0400 Received: from eggs.gnu.org ([209.51.188.92]:37379) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTuZr-00064V-Er for qemu-devel@nongnu.org; Thu, 23 May 2019 16:44:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hTuZp-00035s-It for qemu-devel@nongnu.org; Thu, 23 May 2019 16:44:39 -0400 Received: from mail-yb1-xb42.google.com ([2607:f8b0:4864:20::b42]:35350) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hTuZn-000333-KJ for qemu-devel@nongnu.org; Thu, 23 May 2019 16:44:37 -0400 Received: by mail-yb1-xb42.google.com with SMTP id s69so2620303ybi.2 for ; Thu, 23 May 2019 13:44:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=DWaxu9uiHa4VqUgpO4mPbqlseFRB8XqATreonAM1ocs=; b=omd2HmvHUWB31GaHLP728PLGg48qZ7ELwgtPgcYJXYiFNo97N0QqsmQEubo0DpUtqw WWa1jv1zeCpavvHRCHBbjK29hAf0fEqzCdJGb+wOoJyzkDBKj2FLrTLTMpRuYD/nelnf VHsscQ5hnrc8d6o8F/Yzq24apajNtgmSlsQRcBVw8xxrWYshQXNJLOcgy+2gbTJzNBPl BeKg95dtY3HS0yTU2a7XQL2r2CY0CzCygVBFHGBwCnQ43O0Jk2YP0m2Dyog+MklQ9q4n azOyJk/bzMMk7N5NJzBU+GE/cN24CpYkZprFZgR0g2kUPCOuXj8PfND8eS+GVrb7clxH myHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=DWaxu9uiHa4VqUgpO4mPbqlseFRB8XqATreonAM1ocs=; b=eS7oGA2KmDmznwaFRcbHzz8I936xUaevsA8MpmroQfdjX3vu3Ko16b/61GVyhShKE7 tXM0Pj2eGaCWDQrN069XazAVytD07Tzuj7NuWsRppxATcqWmvD4VwoRg8TDUA4QbgH8y doAI0gwQPoFwdqhP2mXrPD19F6yzSpjiyhNJHELHk2d6CZZrKNwQn3sczgclgcRv3Vwb Cb2pwj5yOIWSEUrkID3R/+rkhlRdsE9t/GdVBHyGzpTTGrWFGKGe4ejcYF+O4cmyBOPG aYUNzFvQWrFrFnjZvz7V8jMGpFZzDDkgS580CWC4hvFD7o+EoS1j2/fkvj/b+KqEBeAa Cnzw== X-Gm-Message-State: APjAAAXE04dfz49CqwWCFZdXb8nf4aydXi/JLSbfghYxEFJX2hBMaLGe siEp/Pe3EpytUOQHeOBidPFXWibl X-Google-Smtp-Source: APXvYqzntVuupXDMaMa1iu+UoYxRRIOmiHWXUfxIbYzIRk+GIObfiwnwuYPkXyT/G/XJwCldK1lLjw== X-Received: by 2002:a25:cb43:: with SMTP id b64mr24063415ybg.509.1558644273827; Thu, 23 May 2019 13:44:33 -0700 (PDT) Received: from dionysus.attlocal.net (69-222-133-165.lightspeed.tukrga.sbcglobal.net. [69.222.133.165]) by smtp.gmail.com with ESMTPSA id p12sm87590ywg.72.2019.05.23.13.44.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 May 2019 13:44:33 -0700 (PDT) From: Jan Bobek To: qemu-devel@nongnu.org Date: Thu, 23 May 2019 16:44:04 -0400 Message-Id: <20190523204409.21068-7-jan.bobek@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190523204409.21068-1-jan.bobek@gmail.com> References: <20190523204409.21068-1-jan.bobek@gmail.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::b42 Subject: [Qemu-devel] [RISU v3 06/11] risu_i386: remove old unused code X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jan Bobek , =?utf-8?q?Alex_Benn=C3=A9e?= , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP The code being removed is a remnant of the past implementation; it has since been replaced by its more powerful, architecture-independent counterpart in reginfo.c. Reviewed-by: Alex Bennée Reviewed-by: Richard Henderson Signed-off-by: Jan Bobek --- risu_i386.c | 58 ----------------------------------------------------- 1 file changed, 58 deletions(-) diff --git a/risu_i386.c b/risu_i386.c index 06d95e5..9962b8f 100644 --- a/risu_i386.c +++ b/risu_i386.c @@ -16,13 +16,6 @@ #include "risu.h" #include "risu_reginfo_i386.h" -struct reginfo master_ri, apprentice_ri; - -static int insn_is_ud2(uint32_t insn) -{ - return ((insn & 0xffff) == 0x0b0f); -} - void advance_pc(void *vuc) { ucontext_t *uc = (ucontext_t *) vuc; @@ -57,54 +50,3 @@ uintptr_t get_pc(struct reginfo *ri) { return ri->gregs[REG_E(IP)]; } - -int send_register_info(int sock, void *uc) -{ - struct reginfo ri; - fill_reginfo(&ri, uc); - return send_data_pkt(sock, &ri, sizeof(ri)); -} - -/* Read register info from the socket and compare it with that from the - * ucontext. Return 0 for match, 1 for end-of-test, 2 for mismatch. - * NB: called from a signal handler. - */ -int recv_and_compare_register_info(int sock, void *uc) -{ - int resp; - fill_reginfo(&master_ri, uc); - recv_data_pkt(sock, &apprentice_ri, sizeof(apprentice_ri)); - if (memcmp(&master_ri, &apprentice_ri, sizeof(master_ri)) != 0) { - /* mismatch */ - resp = 2; - } else if (insn_is_ud2(master_ri.faulting_insn)) { - /* end of test */ - resp = 1; - } else { - /* either successful match or expected undef */ - resp = 0; - } - send_response_byte(sock, resp); - return resp; -} - -/* Print a useful report on the status of the last comparison - * done in recv_and_compare_register_info(). This is called on - * exit, so need not restrict itself to signal-safe functions. - * Should return 0 if it was a good match (ie end of test) - * and 1 for a mismatch. - */ -int report_match_status(void) -{ - fprintf(stderr, "match status...\n"); - fprintf(stderr, "master reginfo:\n"); - dump_reginfo(&master_ri); - fprintf(stderr, "apprentice reginfo:\n"); - dump_reginfo(&apprentice_ri); - if (memcmp(&master_ri, &apprentice_ri, sizeof(master_ri)) == 0) { - fprintf(stderr, "match!\n"); - return 0; - } - fprintf(stderr, "mismatch!\n"); - return 1; -} From patchwork Thu May 23 20:44:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jan Bobek X-Patchwork-Id: 10958785 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EA1A9924 for ; Thu, 23 May 2019 20:52:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D88E5286F6 for ; Thu, 23 May 2019 20:52:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CA6C2286FD; Thu, 23 May 2019 20:52:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 5EB67286F6 for ; Thu, 23 May 2019 20:52:14 +0000 (UTC) Received: from localhost ([127.0.0.1]:43170 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTuhB-0004Bu-MV for patchwork-qemu-devel@patchwork.kernel.org; Thu, 23 May 2019 16:52:13 -0400 Received: from eggs.gnu.org ([209.51.188.92]:37456) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTuZz-0006CM-4A for qemu-devel@nongnu.org; Thu, 23 May 2019 16:44:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hTuZt-0003CZ-Gv for qemu-devel@nongnu.org; Thu, 23 May 2019 16:44:45 -0400 Received: from mail-yw1-xc43.google.com ([2607:f8b0:4864:20::c43]:39385) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hTuZr-00038v-LC for qemu-devel@nongnu.org; Thu, 23 May 2019 16:44:41 -0400 Received: by mail-yw1-xc43.google.com with SMTP id w21so2786526ywd.6 for ; Thu, 23 May 2019 13:44:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Wv0YAF1rZ6KrPU3tosAjlI/qAdfuoWauzAhliLX3BEs=; b=Sfs7P+1AxsKND4DQAlJwytdjXiqMzxGbiZcmdLnpm+Haqzc4uKX6sB5lerTw8VL0mR QiGXg8k/X6zsWUQs+8fHu8ohQcKRZqWd0lFzWl2kmKjJVJUSW4+T1eAXiQOjxznXlpc5 QwQM1BcUmTvqyr3mJ4EtBbtBb+G+2KajREVH+WtbXBHKHTCm4frcFNsUjgrkqiq8h5zE 4kiTSEl1UvgZF05MUpEDLJ3vGfBQNOBopxqJWH/Ng51TXSQdOi3ZSW1MadZABH6puxCV 5dERXMooTC7QhcXdbXqj2WVncA5VkCNOT3d38Pv8NZYRPKl3xgM/l1ve8Nive41q2tVf 7REA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Wv0YAF1rZ6KrPU3tosAjlI/qAdfuoWauzAhliLX3BEs=; b=AGMV6TarX10v3sUZBgsGj0zvKfPTavzr1aTZnKkDc8RKDLiYgZFEG6vkpNCmArsikt l2RvEi2c7+KjsAPdNQeEuLvcdak2d3apjELKYX/6Qoj2h+76Nh0BN7hQYDv0J8feTFc8 vXIDXY4tHALrRRTIuuLKlNoeZTZDKpuJfxFU4HEHtsKVjZ1m2E09LWMOr+kvMX34Wqnt 5ESZsFJenTFEXjy1a9R+WR6aOQHkrmabuPXo37ZATJUXTL79MIUVplMfv+eXm5QqbYl9 wyrdF/ynf6qEdXxl+t9725DbAd8Jn3DKZGwJGLt5xz/LPwFHUUffj0X6UIKxNjxcXsEQ QZcA== X-Gm-Message-State: APjAAAXYkgbsw4nBqrWjjV9Uc+BdAkE/MT/Qx8sdE1luxPv5kqehDImD jJGPjhqN1I8N5Artrorm+JCCio16 X-Google-Smtp-Source: APXvYqxVah+fMA7SaNhiHbvkHANBwiv0gcpjsAkLQsS6K/fWvYhk7U3wUwA0f+vQP+qr7lpPuVFK5Q== X-Received: by 2002:a81:b3c4:: with SMTP id r187mr19261194ywh.217.1558644278092; Thu, 23 May 2019 13:44:38 -0700 (PDT) Received: from dionysus.attlocal.net (69-222-133-165.lightspeed.tukrga.sbcglobal.net. [69.222.133.165]) by smtp.gmail.com with ESMTPSA id p12sm87590ywg.72.2019.05.23.13.44.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 May 2019 13:44:37 -0700 (PDT) From: Jan Bobek To: qemu-devel@nongnu.org Date: Thu, 23 May 2019 16:44:05 -0400 Message-Id: <20190523204409.21068-8-jan.bobek@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190523204409.21068-1-jan.bobek@gmail.com> References: <20190523204409.21068-1-jan.bobek@gmail.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::c43 Subject: [Qemu-devel] [RISU v3 07/11] test_i386: change syntax from nasm to gas X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jan Bobek , =?utf-8?q?Alex_Benn=C3=A9e?= , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP This allows us to drop dependency on NASM and build the test image with GCC only. Adds support for x86_64, too. Suggested-by: Richard Henderson Reviewed-by: Richard Henderson Signed-off-by: Jan Bobek Reviewed-by: Alex Bennée --- Makefile | 3 +++ test_i386.S | 41 +++++++++++++++++++++++++++++++++++++++++ test_i386.s | 27 --------------------------- 3 files changed, 44 insertions(+), 27 deletions(-) create mode 100644 test_i386.S delete mode 100644 test_i386.s diff --git a/Makefile b/Makefile index b362dbe..6ab014a 100644 --- a/Makefile +++ b/Makefile @@ -49,6 +49,9 @@ $(PROG): $(OBJS) %_$(ARCH).elf: %_$(ARCH).s $(AS) -o $@ $< +%_$(ARCH).elf: %_$(ARCH).S + $(CC) $(CPPFLAGS) -o $@ -c $< + clean: rm -f $(PROG) $(OBJS) $(BINS) diff --git a/test_i386.S b/test_i386.S new file mode 100644 index 0000000..456b99c --- /dev/null +++ b/test_i386.S @@ -0,0 +1,41 @@ +/*############################################################################# + * Copyright (c) 2010 Linaro Limited + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Peter Maydell (Linaro) - initial implementation + *###########################################################################*/ + +/* A trivial test image for x86 */ + +/* Initialise the registers to avoid spurious mismatches */ + xor %eax, %eax + sahf /* init eflags */ + + mov $0x12345678, %eax + mov $0x9abcdef0, %ebx + mov $0x97361234, %ecx + mov $0x84310284, %edx + mov $0x83624173, %edi + mov $0xfaebfaeb, %esi + mov $0x84610123, %ebp + +#ifdef __x86_64__ + movq $0x123456789abcdef0, %r8 + movq $0xaaaabbbbccccdddd, %r9 + movq $0x1010101010101010, %r10 + movq $0x1111111111111111, %r11 + movq $0x1212121212121212, %r12 + movq $0x1313131313131313, %r13 + movq $0x1414141414141414, %r14 + movq $0x1515151515151515, %r15 +#endif + +/* do compare */ + ud1 %eax, %eax + +/* exit test */ + ud1 %ecx, %eax diff --git a/test_i386.s b/test_i386.s deleted file mode 100644 index a2140a0..0000000 --- a/test_i386.s +++ /dev/null @@ -1,27 +0,0 @@ -;############################################################################### -;# Copyright (c) 2010 Linaro Limited -;# All rights reserved. This program and the accompanying materials -;# are made available under the terms of the Eclipse Public License v1.0 -;# which accompanies this distribution, and is available at -;# http://www.eclipse.org/legal/epl-v10.html -;# -;# Contributors: -;# Peter Maydell (Linaro) - initial implementation -;############################################################################### - -; A trivial test image for x86 - -BITS 32 -; Initialise the registers to avoid spurious mismatches -mov eax, 0x12345678 -mov ebx, 0x9abcdef0 -mov ecx, 0x97361234 -mov edx, 0x84310284 -mov edi, 0x83624173 -mov esi, 0xfaebfaeb -mov ebp, 0x84610123 -; UD1 : do compare -UD1 - -; UD2 : exit test -UD2 From patchwork Thu May 23 20:44:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jan Bobek X-Patchwork-Id: 10958777 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 29BF813AD for ; Thu, 23 May 2019 20:49:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 15FFD200DF for ; Thu, 23 May 2019 20:49:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0961026E56; Thu, 23 May 2019 20:49:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B0E23200DF for ; Thu, 23 May 2019 20:49:10 +0000 (UTC) Received: from localhost ([127.0.0.1]:43115 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTueE-00019j-17 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 23 May 2019 16:49:10 -0400 Received: from eggs.gnu.org ([209.51.188.92]:37421) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTuZv-00068T-GW for qemu-devel@nongnu.org; Thu, 23 May 2019 16:44:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hTuZt-0003Bx-Dd for qemu-devel@nongnu.org; Thu, 23 May 2019 16:44:43 -0400 Received: from mail-yb1-xb35.google.com ([2607:f8b0:4864:20::b35]:33080) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hTuZr-00039B-FI for qemu-devel@nongnu.org; Thu, 23 May 2019 16:44:39 -0400 Received: by mail-yb1-xb35.google.com with SMTP id w127so923288yba.0 for ; Thu, 23 May 2019 13:44:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0ilxUhOWtdPal8guoafu7uVUdV65rxKS1rgM4/OQmO8=; b=LzP7DIAH6TxVJw/RAarL1dKOcYuOiX+hKY3O1MbhUb4ASnwz6WNEtCGXyNEN3tfyHt 0MVr/wbodOMkUHADYui3do0igVL/R1b2kcSbl1vRPQxqv1HanXPZC3j+cqbC6LnSrIsM P+uQyhmcqpGsuefqY8VVpEhwKpZTkAXyWF4IEOl+cBAXL2ZK8pFkj9arCQQnW48pRWH0 vCulNdn7yeViSICbH181aG80/WL1FAVqnIyKjCVWWudYJkYZ+s5aY9OI3MRgtDoDiY6y 7l+qZQsndh+nHMAz9kLTQaXVAlxX655tgNejOxNLZzPj6Zcaw07JVfD4V5xKtOfEsPyT j8wQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0ilxUhOWtdPal8guoafu7uVUdV65rxKS1rgM4/OQmO8=; b=p3i//iMUbNOTlXeDnzx6kbKosZbBosgzD9AruOG7H+NbiIGDzpN4tjpBgmK/cN+/y4 V+v8oRiQvTs+scxigNyVK8zQQF8B+ng1gXhKGNuImYeaxR5XRrvkavWADRqcM+J6CZMh 0UfWOnnThU/heYYtskcVH03i1C97EviXDBRokRhMQbrVzlH1V5eGzGChTn/UVd2n7FRu DM12n4AJzFAbuBvfJBix37MCZRwXg6xPQ+CuiMc5w1223Be5uqE+iRrNFnLRMWEg3NoF 5z29AlMVfAAu4+1r5HBrpt9E4q6hDzR22p2sMn1yYaTeo5RQXv3Ymaf+OGQ1ggIfTR3X eY9Q== X-Gm-Message-State: APjAAAWSbhmgx6oGb5DteBqf93q0+8QVmE4VElPvlpk5gO2/IAlDxuW4 zV67wzz5cyY5a5DpML0XD5NfYeQS X-Google-Smtp-Source: APXvYqxPBDcpajJyswcRAX4EdZ2FVVxWMb1TAzYN9CCyvlVVj+GeEOLc26DxNNRVWd7xTi7Wg6uLYA== X-Received: by 2002:a25:b70c:: with SMTP id t12mr6654762ybj.67.1558644278596; Thu, 23 May 2019 13:44:38 -0700 (PDT) Received: from dionysus.attlocal.net (69-222-133-165.lightspeed.tukrga.sbcglobal.net. [69.222.133.165]) by smtp.gmail.com with ESMTPSA id p12sm87590ywg.72.2019.05.23.13.44.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 May 2019 13:44:38 -0700 (PDT) From: Jan Bobek To: qemu-devel@nongnu.org Date: Thu, 23 May 2019 16:44:06 -0400 Message-Id: <20190523204409.21068-9-jan.bobek@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190523204409.21068-1-jan.bobek@gmail.com> References: <20190523204409.21068-1-jan.bobek@gmail.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::b35 Subject: [Qemu-devel] [RISU v3 08/11] configure: add i386/x86_64 architectures X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jan Bobek , =?utf-8?q?Alex_Benn=C3=A9e?= , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Now that i386 and x86_64 architectures are supported by RISU, we want to detect them and build RISU for them automatically. Suggested-by: Richard Henderson Reviewed-by: Alex Bennée Reviewed-by: Richard Henderson Signed-off-by: Jan Bobek --- configure | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/configure b/configure index 65e1819..ca2d7db 100755 --- a/configure +++ b/configure @@ -48,12 +48,14 @@ EOF } guess_arch() { - if check_define __m68k__ ; then - ARCH="m68k" + if check_define __aarch64__ ; then + ARCH="aarch64" elif check_define __arm__ ; then ARCH="arm" - elif check_define __aarch64__ ; then - ARCH="aarch64" + elif check_define __i386__ || check_define __x86_64__ ; then + ARCH="i386" + elif check_define __m68k__ ; then + ARCH="m68k" elif check_define __powerpc64__ ; then ARCH="ppc64" else From patchwork Thu May 23 20:44:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jan Bobek X-Patchwork-Id: 10958789 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 06EFD76 for ; Thu, 23 May 2019 20:52:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E5C5528706 for ; Thu, 23 May 2019 20:52:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CFE372871C; Thu, 23 May 2019 20:52:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0EF1C28718 for ; Thu, 23 May 2019 20:52:32 +0000 (UTC) Received: from localhost ([127.0.0.1]:43174 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTuhT-0004PQ-BZ for patchwork-qemu-devel@patchwork.kernel.org; Thu, 23 May 2019 16:52:31 -0400 Received: from eggs.gnu.org ([209.51.188.92]:37454) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTuZz-0006CI-43 for qemu-devel@nongnu.org; Thu, 23 May 2019 16:44:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hTuZv-0003Fq-Ly for qemu-devel@nongnu.org; Thu, 23 May 2019 16:44:45 -0400 Received: from mail-yb1-xb43.google.com ([2607:f8b0:4864:20::b43]:33775) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hTuZv-0003Ef-FY for qemu-devel@nongnu.org; Thu, 23 May 2019 16:44:43 -0400 Received: by mail-yb1-xb43.google.com with SMTP id w127so923378yba.0 for ; Thu, 23 May 2019 13:44:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=dgGhNtzAW4e5HQFtFo/WG0Nzt03w15qZgzxKHgtzV9k=; b=afTeAsOng5t/U9KgXwNn8SNdgxrlcz32rmOoAY5Rw7sypF3FK6Vh837DkrxnxV9JES g1TZBHxj1n3gSWL5XLtLyRzJclK865j8wnJhMvMn4K+udFufJ6haYeGbszLt6o0Qlpps 245sqEaw7kNJ3GOAegxGFekNmrGl2b31lxJzPmcpmR89sqxZwtQ8a4HWDcxFaZj/iWBa CwTPJR5iWF9pXEz2wv+uZmqZ37WVvQj2KlMdAk2DjQx83Yf8HZejhtmCa2Gap1EBNY3y kuM/nUJfhJXxWMVABKd+4DdRl31+P2gRK1Dp8ZLHLaG2ViLkOTf6kryYjtN/wnKYKjgs Nfaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=dgGhNtzAW4e5HQFtFo/WG0Nzt03w15qZgzxKHgtzV9k=; b=LA3DfYDv7h2oNxaqk1TqY79l/QRqz0tDG4sJKbnXEB01FVlxXb8BTHQydqJHGG+KSs p4H/nDn7i/x8MA/CreLHoEnrAAhKpOMORr1xrR/Va8hN0Hz8Ude+31B31S3hxBKyJ/rm skT0uugqOsbwRxUunrJrl5NsM3AO4Inp/CsH5pLf73Vo7p7NZfIagF9Vfatioe0dUVJR ctpkFWlI8MZzJ9T75ZWfdG6FQ4avCQggZfxWPb3WjN5YIJM2sul3iSu5zbaCZFqM6gpj zz1HqeZLilhzAi+CnmQKVkbDr+fsPFyI8QeAFf2ARhR8wmeb/Ntl/kzJMmIiQc76zOmW 5YMQ== X-Gm-Message-State: APjAAAVriKZ7RbAot9zCRxyLf9K8GLvYDlgf4g06UhzvLf12fpzX/Xx/ Gea+QkIaPOUeIbtnseuQ/awn0WmK X-Google-Smtp-Source: APXvYqyzrtBYhwXaGqpxjszYpxIT3+HbFSJin6mxAfijYnYdTDY+cqsxthM0kTpjx2WLwPUm/5FP7w== X-Received: by 2002:a25:2487:: with SMTP id k129mr5834238ybk.91.1558644282316; Thu, 23 May 2019 13:44:42 -0700 (PDT) Received: from dionysus.attlocal.net (69-222-133-165.lightspeed.tukrga.sbcglobal.net. [69.222.133.165]) by smtp.gmail.com with ESMTPSA id p12sm87590ywg.72.2019.05.23.13.44.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 May 2019 13:44:41 -0700 (PDT) From: Jan Bobek To: qemu-devel@nongnu.org Date: Thu, 23 May 2019 16:44:07 -0400 Message-Id: <20190523204409.21068-10-jan.bobek@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190523204409.21068-1-jan.bobek@gmail.com> References: <20190523204409.21068-1-jan.bobek@gmail.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::b43 Subject: [Qemu-devel] [RISU v3 09/11] i386: Add avx512 state to reginfo_t X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Richard Henderson The state expected for a given test must be specifically requested with the --xfeatures=mask command-line argument. This is recorded with the saved state so that it is obvious if the apprentice is given a different argument. Any features beyond what are present on the running cpu will read as zero. Signed-off-by: Richard Henderson Reviewed-by: Alex Bennée --- risu_reginfo_i386.h | 14 +++ risu_reginfo_i386.c | 228 ++++++++++++++++++++++++++++++++++++++++++-- test_i386.S | 39 ++++++++ 3 files changed, 273 insertions(+), 8 deletions(-) diff --git a/risu_reginfo_i386.h b/risu_reginfo_i386.h index e350f01..b468f79 100644 --- a/risu_reginfo_i386.h +++ b/risu_reginfo_i386.h @@ -12,6 +12,10 @@ #ifndef RISU_REGINFO_I386_H #define RISU_REGINFO_I386_H +struct avx512_reg { + uint64_t q[8]; +}; + /* * This is the data structure we pass over the socket. * It is a simplified and reduced subset of what can @@ -19,7 +23,17 @@ */ struct reginfo { uint32_t faulting_insn; + uint32_t mxcsr; + uint64_t xfeatures; + gregset_t gregs; + +#ifdef __x86_64__ + struct avx512_reg vregs[32]; +#else + struct avx512_reg vregs[8]; +#endif + uint64_t kregs[8]; }; /* diff --git a/risu_reginfo_i386.c b/risu_reginfo_i386.c index c4dc14a..83f9541 100644 --- a/risu_reginfo_i386.c +++ b/risu_reginfo_i386.c @@ -11,19 +11,32 @@ #include #include +#include #include #include #include +#include #include "risu.h" #include "risu_reginfo_i386.h" -const struct option * const arch_long_opts; -const char * const arch_extra_help; +#include + +static uint64_t xfeatures = 3; /* SSE */ + +static const struct option extra_ops[] = { + {"xfeatures", required_argument, NULL, FIRST_ARCH_OPT }, + {0, 0, 0, 0} +}; + +const struct option * const arch_long_opts = extra_ops; +const char * const arch_extra_help + = " --xfeatures= Use features in mask for XSAVE\n"; void process_arch_opt(int opt, const char *arg) { - abort(); + assert(opt == FIRST_ARCH_OPT); + xfeatures = strtoull(arg, 0, 0); } const int reginfo_size(void) @@ -31,13 +44,37 @@ const int reginfo_size(void) return sizeof(struct reginfo); } +static void *xsave_feature_buf(struct _xstate *xs, int feature) +{ + unsigned int eax, ebx, ecx, edx; + int ok; + + /* + * Get the location of the XSAVE feature from the cpuid leaf. + * Given that we know the xfeature bit is set, this must succeed. + */ + ok = __get_cpuid_count(0xd, feature, &eax, &ebx, &ecx, &edx); + assert(ok); + + /* Sanity check that the frame stored by the kernel contains the data. */ + assert(xs->fpstate.sw_reserved.extended_size >= eax + ebx); + + return (void *)xs + ebx; +} + /* reginfo_init: initialize with a ucontext */ void reginfo_init(struct reginfo *ri, ucontext_t *uc) { - int i; + int i, nvecregs; + struct _fpstate *fp; + struct _xstate *xs; + uint64_t features; memset(ri, 0, sizeof(*ri)); + /* Require master and apprentice to be given the same arguments. */ + ri->xfeatures = xfeatures; + for (i = 0; i < NGREG; i++) { switch (i) { case REG_E(IP): @@ -79,12 +116,89 @@ void reginfo_init(struct reginfo *ri, ucontext_t *uc) * distinguish 'do compare' from 'stop'. */ ri->faulting_insn = *(uint32_t *)uc->uc_mcontext.gregs[REG_E(IP)]; + + /* + * FP state is omitted if unused (aka in init state). + * Use the struct for access to AVX state. + */ + + fp = (struct _fpstate *)uc->uc_mcontext.fpregs; + if (fp == NULL) { + return; + } + +#ifdef __x86_64__ + nvecregs = 16; +#else + /* We don't (currently) care about the 80387 state, only SSE+. */ + if (fp->magic != X86_FXSR_MAGIC) { + return; + } + nvecregs = 8; +#endif + + /* + * Now we know that _fpstate contains FXSAVE data. + */ + ri->mxcsr = fp->mxcsr; + + for (i = 0; i < nvecregs; ++i) { +#ifdef __x86_64__ + memcpy(&ri->vregs[i], &fp->xmm_space[i * 4], 16); +#else + memcpy(&ri->vregs[i], &fp->_xmm[i], 16); +#endif + } + + if (fp->sw_reserved.magic1 != FP_XSTATE_MAGIC1) { + return; + } + xs = (struct _xstate *)fp; + features = xfeatures & xs->xstate_hdr.xfeatures; + + /* + * Now we know that _fpstate contains XSAVE data. + */ + + if (features & (1 << 2)) { + /* YMM_Hi128 state */ + void *buf = xsave_feature_buf(xs, 2); + for (i = 0; i < nvecregs; ++i) { + memcpy(&ri->vregs[i].q[2], buf + 16 * i, 16); + } + } + + if (features & (1 << 5)) { + /* Opmask state */ + uint64_t *buf = xsave_feature_buf(xs, 5); + for (i = 0; i < 8; ++i) { + ri->kregs[i] = buf[i]; + } + } + + if (features & (1 << 6)) { + /* ZMM_Hi256 state */ + void *buf = xsave_feature_buf(xs, 6); + for (i = 0; i < nvecregs; ++i) { + memcpy(&ri->vregs[i].q[4], buf + 32 * i, 32); + } + } + +#ifdef __x86_64__ + if (features & (1 << 7)) { + /* Hi16_ZMM state */ + void *buf = xsave_feature_buf(xs, 7); + for (i = 0; i < 16; ++i) { + memcpy(&ri->vregs[i + 16], buf + 64 * i, 64); + } + } +#endif } /* reginfo_is_eq: compare the reginfo structs, returns nonzero if equal */ int reginfo_is_eq(struct reginfo *m, struct reginfo *a) { - return 0 == memcmp(m, a, sizeof(*m)); + return !memcmp(m, a, sizeof(*m)); } static const char *const regname[NGREG] = { @@ -126,28 +240,126 @@ static const char *const regname[NGREG] = { # define PRIxREG "%08x" #endif +static int get_nvecregs(uint64_t features) +{ +#ifdef __x86_64__ + return features & (1 << 7) ? 32 : 16; +#else + return 8; +#endif +} + +static int get_nvecquads(uint64_t features) +{ + if (features & (1 << 6)) { + return 8; + } else if (features & (1 << 2)) { + return 4; + } else { + return 2; + } +} + +static char get_vecletter(uint64_t features) +{ + if (features & (1 << 6 | 1 << 7)) { + return 'z'; + } else if (features & (1 << 2)) { + return 'y'; + } else { + return 'x'; + } +} + /* reginfo_dump: print state to a stream, returns nonzero on success */ int reginfo_dump(struct reginfo *ri, FILE *f) { - int i; + uint64_t features; + int i, j, n, w; + char r; + fprintf(f, " faulting insn %x\n", ri->faulting_insn); for (i = 0; i < NGREG; i++) { if (regname[i]) { fprintf(f, " %-6s: " PRIxREG "\n", regname[i], ri->gregs[i]); } } + + fprintf(f, " mxcsr : %x\n", ri->mxcsr); + fprintf(f, " xfeat : %" PRIx64 "\n", ri->xfeatures); + + features = ri->xfeatures; + n = get_nvecregs(features); + w = get_nvecquads(features); + r = get_vecletter(features); + + for (i = 0; i < n; i++) { + fprintf(f, " %cmm%-3d: ", r, i); + for (j = w - 1; j >= 0; j--) { + fprintf(f, "%016" PRIx64 "%c", + ri->vregs[i].q[j], j == 0 ? '\n' : ' '); + } + } + + if (features & (1 << 5)) { + for (i = 0; i < 8; i++) { + fprintf(f, " k%-5d: %016" PRIx64 "\n", i, ri->kregs[i]); + } + } + return !ferror(f); } int reginfo_dump_mismatch(struct reginfo *m, struct reginfo *a, FILE *f) { - int i; + int i, j, n, w; + uint64_t features; + char r; + + fprintf(f, "Mismatch (master v apprentice):\n"); + for (i = 0; i < NGREG; i++) { if (m->gregs[i] != a->gregs[i]) { assert(regname[i]); - fprintf(f, "Mismatch: %s: " PRIxREG " v " PRIxREG "\n", + fprintf(f, " %-6s: " PRIxREG " v " PRIxREG "\n", regname[i], m->gregs[i], a->gregs[i]); } } + + if (m->mxcsr != a->mxcsr) { + fprintf(f, " mxcsr : %x v %x\n", m->mxcsr, a->mxcsr); + } + if (m->xfeatures != a->xfeatures) { + fprintf(f, " xfeat : %" PRIx64 " v %" PRIx64 "\n", + m->xfeatures, a->xfeatures); + } + + features = m->xfeatures; + n = get_nvecregs(features); + w = get_nvecquads(features); + r = get_vecletter(features); + + for (i = 0; i < n; i++) { + if (memcmp(&m->vregs[i], &a->vregs[i], w * 8)) { + fprintf(f, " %cmm%-3d: ", r, i); + for (j = w - 1; j >= 0; j--) { + fprintf(f, "%016" PRIx64 "%c", + m->vregs[i].q[j], j == 0 ? '\n' : ' '); + } + fprintf(f, " v: "); + for (j = w - 1; j >= 0; j--) { + fprintf(f, "%016" PRIx64 "%c", + a->vregs[i].q[j], j == 0 ? '\n' : ' '); + } + } + } + + for (i = 0; i < 8; i++) { + if (m->kregs[i] != a->kregs[i]) { + fprintf(f, " k%-5d: %016" PRIx64 " v %016" PRIx64 "\n", + i, m->kregs[i], a->kregs[i]); + } + } + return !ferror(f); } diff --git a/test_i386.S b/test_i386.S index 456b99c..05344d7 100644 --- a/test_i386.S +++ b/test_i386.S @@ -12,6 +12,37 @@ /* A trivial test image for x86 */ /* Initialise the registers to avoid spurious mismatches */ + +#ifdef __x86_64__ +#define BASE %rax + lea 2f(%rip), BASE +#else +#define BASE %eax + call 1f +1: pop BASE + add $2f-1b, BASE +#endif + + movdqa 0(BASE), %xmm0 + movdqa 1*16(BASE), %xmm1 + movdqa 2*16(BASE), %xmm2 + movdqa 3*16(BASE), %xmm3 + movdqa 4*16(BASE), %xmm4 + movdqa 5*16(BASE), %xmm5 + movdqa 6*16(BASE), %xmm6 + movdqa 7*16(BASE), %xmm7 + +#ifdef __x86_64__ + movdqa 8*16(BASE), %xmm8 + movdqa 9*16(BASE), %xmm9 + movdqa 10*16(BASE), %xmm10 + movdqa 11*16(BASE), %xmm11 + movdqa 12*16(BASE), %xmm12 + movdqa 13*16(BASE), %xmm13 + movdqa 14*16(BASE), %xmm14 + movdqa 15*16(BASE), %xmm15 +#endif + xor %eax, %eax sahf /* init eflags */ @@ -39,3 +70,11 @@ /* exit test */ ud1 %ecx, %eax + + .p2align 16 +2: + .set i, 0 + .rept 256 + .byte i + .set i, i + 1 + .endr From patchwork Thu May 23 20:44:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jan Bobek X-Patchwork-Id: 10958783 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2E73816C1 for ; Thu, 23 May 2019 20:52:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1B482286F6 for ; Thu, 23 May 2019 20:52:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0DFB6286FD; Thu, 23 May 2019 20:52:07 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 83123286F6 for ; Thu, 23 May 2019 20:52:06 +0000 (UTC) Received: from localhost ([127.0.0.1]:43168 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTuh3-0003wm-H7 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 23 May 2019 16:52:05 -0400 Received: from eggs.gnu.org ([209.51.188.92]:37455) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTuZz-0006CL-4A for qemu-devel@nongnu.org; Thu, 23 May 2019 16:44:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hTuZw-0003Ho-1c for qemu-devel@nongnu.org; Thu, 23 May 2019 16:44:45 -0400 Received: from mail-yb1-xb2b.google.com ([2607:f8b0:4864:20::b2b]:42636) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hTuZv-0003Ff-SO for qemu-devel@nongnu.org; Thu, 23 May 2019 16:44:43 -0400 Received: by mail-yb1-xb2b.google.com with SMTP id a21so2782555ybg.9 for ; Thu, 23 May 2019 13:44:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=06P+BrsS8Wgfkpmivdl7rtQvDnn06OvuBRIH+NIQTdk=; b=iMn9KZ/dPRhsy0owQd++Y+KxKPwSakEro6GIGJ83BUKA+WiPhty6qjoA0qE29TsK3a dSetkpaw6o1evI4SA1IEFIdjSGCJj4Xbdv6Q1yQTRGAjSL++RLWj/7YlQa1ERjJ1GYXW 2A6zMR5rwO07Xuxqt9QvhsbjKXl6zwjfoZHh0hJmOUMc2WlRqlhwRNuGAukyKMt4kXTp IxV5eo+Uz91SmuDldM7IViYnjZ+H5q98ZnwCTMnBoKEsHF1KfaDKc6Sp2/OeHz88MxRo gNASwAYoTg8pCPPBCKC1eyZq2zmc4MJROdKfpQeY/OSuEuwMdLLEgr4N4f1x8WQIcGzt 54fQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=06P+BrsS8Wgfkpmivdl7rtQvDnn06OvuBRIH+NIQTdk=; b=ds3QKt4e5Ho9jchN5YNy+2dPIQcB7T+X/SY+vT2SL0vll36kMN8ELvuQ21MQ8km55e /15l/NLEVcCEZtb8UZIDYTR+Q4kENGdXKilu/OkC/4FXsm7DaV96PQKpTzjYePutJyP9 ah7lDJiQjIMoP0/gIsWd2aAUdqR6As28GVvUc7EHdK7TEiL6MDkJ8lPUv15CcNKnntBJ jXz3txtJZmGin02FdAqXcA/qmjfuB4ChfbeoGLcqikEk++vBIFdAcuomKcB0oZWYnLpX to7mcsTri37HwNJiz8ZP2Odb50S303jXsMRD4D2lUWTOZpCjjk+655adtfxeXzYdrdMY +wQA== X-Gm-Message-State: APjAAAUTOhaf1qjC4h4oMtTfE9fU39crX3rFLZPYIk8CdUKsJL5XitWK 1XTWWpulYv5R6l5/lrVu/slOXCF3 X-Google-Smtp-Source: APXvYqz1C2Id0Koqf+UbbDJjqnM3Pc0qym0TMk258BksGxRjlnNW80bBTo6VFuTTeDl1BR+KnMU8UA== X-Received: by 2002:a25:138a:: with SMTP id 132mr45212293ybt.127.1558644282987; Thu, 23 May 2019 13:44:42 -0700 (PDT) Received: from dionysus.attlocal.net (69-222-133-165.lightspeed.tukrga.sbcglobal.net. [69.222.133.165]) by smtp.gmail.com with ESMTPSA id p12sm87590ywg.72.2019.05.23.13.44.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 May 2019 13:44:42 -0700 (PDT) From: Jan Bobek To: qemu-devel@nongnu.org Date: Thu, 23 May 2019 16:44:08 -0400 Message-Id: <20190523204409.21068-11-jan.bobek@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190523204409.21068-1-jan.bobek@gmail.com> References: <20190523204409.21068-1-jan.bobek@gmail.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::b2b Subject: [Qemu-devel] [RISU v3 10/11] risu_reginfo_i386: replace xfeature constants with symbolic names X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jan Bobek , =?utf-8?q?Alex_Benn=C3=A9e?= , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP The original code used "magic numbers", which made it unclear in some places. Include a reference to the Intel manual where the constants' meaning is discussed. Reviewed-by: Alex Bennée Reviewed-by: Richard Henderson Signed-off-by: Jan Bobek --- risu_reginfo_i386.c | 48 +++++++++++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/risu_reginfo_i386.c b/risu_reginfo_i386.c index 83f9541..01ea179 100644 --- a/risu_reginfo_i386.c +++ b/risu_reginfo_i386.c @@ -22,7 +22,25 @@ #include -static uint64_t xfeatures = 3; /* SSE */ +/* + * Refer to "Intel(R) 64 and IA-32 Architectures Software Developer's + * Manual", Volume 1, Section 13.1 "XSAVE-Supported Features and + * State-Component Bitmaps" for detailed discussion of these constants + * and their meaning. + */ +enum { + XFEAT_X87 = 1 << 0, + XFEAT_SSE = 1 << 1, + XFEAT_AVX = 1 << 2, + XFEAT_AVX512_OPMASK = 1 << 5, + XFEAT_AVX512_ZMM_HI256 = 1 << 6, + XFEAT_AVX512_HI16_ZMM = 1 << 7, + XFEAT_AVX512 = XFEAT_AVX512_OPMASK + | XFEAT_AVX512_ZMM_HI256 + | XFEAT_AVX512_HI16_ZMM +}; + +static uint64_t xfeatures = XFEAT_X87 | XFEAT_SSE; static const struct option extra_ops[] = { {"xfeatures", required_argument, NULL, FIRST_ARCH_OPT }, @@ -160,34 +178,34 @@ void reginfo_init(struct reginfo *ri, ucontext_t *uc) * Now we know that _fpstate contains XSAVE data. */ - if (features & (1 << 2)) { + if (features & XFEAT_AVX) { /* YMM_Hi128 state */ - void *buf = xsave_feature_buf(xs, 2); + void *buf = xsave_feature_buf(xs, XFEAT_AVX); for (i = 0; i < nvecregs; ++i) { memcpy(&ri->vregs[i].q[2], buf + 16 * i, 16); } } - if (features & (1 << 5)) { + if (features & XFEAT_AVX512_OPMASK) { /* Opmask state */ - uint64_t *buf = xsave_feature_buf(xs, 5); + uint64_t *buf = xsave_feature_buf(xs, XFEAT_AVX512_OPMASK); for (i = 0; i < 8; ++i) { ri->kregs[i] = buf[i]; } } - if (features & (1 << 6)) { + if (features & XFEAT_AVX512_ZMM_HI256) { /* ZMM_Hi256 state */ - void *buf = xsave_feature_buf(xs, 6); + void *buf = xsave_feature_buf(xs, XFEAT_AVX512_ZMM_HI256); for (i = 0; i < nvecregs; ++i) { memcpy(&ri->vregs[i].q[4], buf + 32 * i, 32); } } #ifdef __x86_64__ - if (features & (1 << 7)) { + if (features & XFEAT_AVX512_HI16_ZMM) { /* Hi16_ZMM state */ - void *buf = xsave_feature_buf(xs, 7); + void *buf = xsave_feature_buf(xs, XFEAT_AVX512_HI16_ZMM); for (i = 0; i < 16; ++i) { memcpy(&ri->vregs[i + 16], buf + 64 * i, 64); } @@ -243,7 +261,7 @@ static const char *const regname[NGREG] = { static int get_nvecregs(uint64_t features) { #ifdef __x86_64__ - return features & (1 << 7) ? 32 : 16; + return features & XFEAT_AVX512_HI16_ZMM ? 32 : 16; #else return 8; #endif @@ -251,9 +269,9 @@ static int get_nvecregs(uint64_t features) static int get_nvecquads(uint64_t features) { - if (features & (1 << 6)) { + if (features & XFEAT_AVX512_ZMM_HI256) { return 8; - } else if (features & (1 << 2)) { + } else if (features & XFEAT_AVX) { return 4; } else { return 2; @@ -262,9 +280,9 @@ static int get_nvecquads(uint64_t features) static char get_vecletter(uint64_t features) { - if (features & (1 << 6 | 1 << 7)) { + if (features & (XFEAT_AVX512_ZMM_HI256 | XFEAT_AVX512_HI16_ZMM)) { return 'z'; - } else if (features & (1 << 2)) { + } else if (features & XFEAT_AVX) { return 'y'; } else { return 'x'; @@ -301,7 +319,7 @@ int reginfo_dump(struct reginfo *ri, FILE *f) } } - if (features & (1 << 5)) { + if (features & XFEAT_AVX512_OPMASK) { for (i = 0; i < 8; i++) { fprintf(f, " k%-5d: %016" PRIx64 "\n", i, ri->kregs[i]); } From patchwork Thu May 23 20:44:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jan Bobek X-Patchwork-Id: 10958787 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6AA7D76 for ; Thu, 23 May 2019 20:52:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 58DBB286FD for ; Thu, 23 May 2019 20:52:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4D2D328718; Thu, 23 May 2019 20:52:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E7AF3286FD for ; Thu, 23 May 2019 20:52:29 +0000 (UTC) Received: from localhost ([127.0.0.1]:43172 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTuhR-0004NQ-6v for patchwork-qemu-devel@patchwork.kernel.org; Thu, 23 May 2019 16:52:29 -0400 Received: from eggs.gnu.org ([209.51.188.92]:37477) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTua0-0006DQ-66 for qemu-devel@nongnu.org; Thu, 23 May 2019 16:44:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hTuZz-0003Pt-6F for qemu-devel@nongnu.org; Thu, 23 May 2019 16:44:48 -0400 Received: from mail-yb1-xb2e.google.com ([2607:f8b0:4864:20::b2e]:40884) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hTuZx-0003H7-H8 for qemu-devel@nongnu.org; Thu, 23 May 2019 16:44:45 -0400 Received: by mail-yb1-xb2e.google.com with SMTP id g62so2785714ybg.7 for ; Thu, 23 May 2019 13:44:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=yaZVlZDEXWfOSBbbJA3wQfauT8Jz80fWSW3uiWNB6mc=; b=YTesA8IY48HUlfRoiX1Ns79o4itVfEyRQzvF5xWbK2lBb/S1tdqwmOGsdrt1U765Yq CkqIQaWqD7/8L8dwou379tWjGbm14ttiauKwpXIgT5bEDhKqzsSHT8NyvA18++P01bo1 z2aTvKgasJkKrs0ltYaGqfHjjBvn547FuAEE0uTuIN0XWQ6cS+kW1z7LpcXNnm+ZLWtY EpqA4GvuiLaC9m8oWIWlJAaHBDu0pyGuv8MlyLVDXmvcVZuWSuYMUZjRByxSsWeHo72I zmR6K+R8muIZ92oLX/1JE3Qle/zmiw/Oh6AXX7Ua5E10DQysXFTul0ws6mn4u94cB6MZ D2nw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=yaZVlZDEXWfOSBbbJA3wQfauT8Jz80fWSW3uiWNB6mc=; b=bt230IPqQZ4tHLVha67D3hrDzkGTzRjKyA5PNcmq4R+lKYeMSn3Ib6ltW8/4s04UU+ C1y46HHh96X+KadLrBquOZThxjybx1AKULJNobxZm1ZrxGZ4LpeDe8WyW3X+/v7Z5Hbb BqJYAAlJ+/3yeofRI0xLlePk0L+Pes1dQELqw+KTOYmLil7WfRr+hcUOE49Bk1jeMDXC mhUvKnKrsjdxU9lSqexId+KR49eSEtt28EZDEEa0+FegfXUU4PkoUqQIxHir5slY0dbJ xB7iTeuSJ4MgSppitcG2ctwsYCbLnQ4SiqmMVIXfYw2zZvIoyxXr+p/as1J7QIub5yZL Cq/Q== X-Gm-Message-State: APjAAAWrxvYOARmyxtiLJAByj/Y4mFG3S2Og56YWvJ21NCRo3tyRLTix qRrNZr2AjI0XMV5gk77pJyLY2S6T X-Google-Smtp-Source: APXvYqzvnsYGcGrS8nYaQmH6KjJa7oRVBMPDhKGIAE+5/oBv/SkpmcF93owMKk9V8w9CdvLE9b8TWg== X-Received: by 2002:a25:5089:: with SMTP id e131mr7852663ybb.322.1558644283566; Thu, 23 May 2019 13:44:43 -0700 (PDT) Received: from dionysus.attlocal.net (69-222-133-165.lightspeed.tukrga.sbcglobal.net. [69.222.133.165]) by smtp.gmail.com with ESMTPSA id p12sm87590ywg.72.2019.05.23.13.44.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 May 2019 13:44:43 -0700 (PDT) From: Jan Bobek To: qemu-devel@nongnu.org Date: Thu, 23 May 2019 16:44:09 -0400 Message-Id: <20190523204409.21068-12-jan.bobek@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190523204409.21068-1-jan.bobek@gmail.com> References: <20190523204409.21068-1-jan.bobek@gmail.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::b2e Subject: [Qemu-devel] [RISU v3 11/11] risu_reginfo_i386: rework --xfeatures value parsing X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jan Bobek , =?utf-8?q?Alex_Benn=C3=A9e?= , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Have the --xfeatures option accept "sse", "avx" and "avx512" in addition to a plain numerical value, purely for users' convenience. Don't fail silently when an incorrect value is specified, to avoid confusion. Suggested-by: Richard Henderson Signed-off-by: Jan Bobek Reviewed-by: Alex Bennée Tested-by: Alex Bennée --- risu_reginfo_i386.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/risu_reginfo_i386.c b/risu_reginfo_i386.c index 01ea179..194e0ad 100644 --- a/risu_reginfo_i386.c +++ b/risu_reginfo_i386.c @@ -53,8 +53,25 @@ const char * const arch_extra_help void process_arch_opt(int opt, const char *arg) { + char *endptr; + assert(opt == FIRST_ARCH_OPT); - xfeatures = strtoull(arg, 0, 0); + + if (!strcmp(arg, "sse")) { + xfeatures = XFEAT_X87 | XFEAT_SSE; + } else if (!strcmp(arg, "avx")) { + xfeatures = XFEAT_X87 | XFEAT_SSE | XFEAT_AVX; + } else if (!strcmp(arg, "avx512")) { + xfeatures = XFEAT_X87 | XFEAT_SSE | XFEAT_AVX | XFEAT_AVX512; + } else { + xfeatures = strtoull(arg, &endptr, 0); + if (*endptr) { + fprintf(stderr, + "Unable to parse '%s' in '%s' into an xfeatures integer mask\n", + endptr, arg); + exit(1); + } + } } const int reginfo_size(void)