From patchwork Wed Dec 19 19:19:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Francis X-Patchwork-Id: 1016292 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=wdc.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=wdc.com header.i=@wdc.com header.b="XcJw+CfO"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=sharedspace.onmicrosoft.com header.i=@sharedspace.onmicrosoft.com header.b="ZseeC66R"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 43KlKx0psTz9s1c for ; Thu, 20 Dec 2018 06:28:21 +1100 (AEDT) Received: from localhost ([::1]:33778 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gZhVy-0000vk-PC for incoming@patchwork.ozlabs.org; Wed, 19 Dec 2018 14:28:18 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46188) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gZhNj-0002s4-Iz for qemu-devel@nongnu.org; Wed, 19 Dec 2018 14:19:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gZhNf-0001ky-Ho for qemu-devel@nongnu.org; Wed, 19 Dec 2018 14:19:47 -0500 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:29352) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gZhNf-0001h7-8K; Wed, 19 Dec 2018 14:19:43 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1545247183; x=1576783183; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=3vPFoJPNQi/eJF2e40JeKIaLPr+hYoPgfhUwDa1mM/4=; b=XcJw+CfOb4Z6jpdEvT3HGh397slEEeTuNWoypgwDq/v11vpMOTXvXmqs NakJmOODNiQtsQPuaMxPzL5BSJWVI92kIZLf8Ws9kLDhM8ewTi4qNmZ56 YFkkd50844S3VtQt5k8ZKgc5pxOFBaZpJksgNnw2cCVGAisvxtJrIj0cB USrhM08vj9IWA8aBkTKOvDtKkAyenoTrxPAxdahJvf5PKryRsjodW4HvQ kV2aqjJxhwm3+VPVtc+2dHSBqigHCBUbddF8wVtV3FpLEfDKUiNVqBOgs qKsEcabXQJJPgb6qA6y2P42y8D92uFvQI1/H3UyujBDZGBMyQU8ZiPX3p A==; X-IronPort-AV: E=Sophos;i="5.56,373,1539619200"; d="scan'208";a="97004266" Received: from mail-bn3nam01lp2053.outbound.protection.outlook.com (HELO NAM01-BN3-obe.outbound.protection.outlook.com) ([104.47.33.53]) by ob1.hgst.iphmx.com with ESMTP; 20 Dec 2018 03:19:41 +0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sharedspace.onmicrosoft.com; s=selector1-wdc-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=jFTwdiIXyeMSeUDmBBDIXrTwF2YlYI4NVSZIsK4aSdw=; b=ZseeC66RaxeNufKiAURPiKIATZGj+1YMUqmlUI2QQXwwJRtJ8BwBTwmYdbyLOqzhedn8WadHVs00si0+lzbv6rKdYvknx19ny7LKiTXoeqc0c0GmlEUJGoZzqo84dVBm92LJAVFBW/CDKYwcOfK9TwRtbXky5sNmg5V0b4UUdsE= Received: from MWHPR04MB0401.namprd04.prod.outlook.com (10.173.48.18) by MWHPR04MB0832.namprd04.prod.outlook.com (10.172.168.142) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1425.22; Wed, 19 Dec 2018 19:19:40 +0000 Received: from MWHPR04MB0401.namprd04.prod.outlook.com ([fe80::9067:fb44:66b2:7604]) by MWHPR04MB0401.namprd04.prod.outlook.com ([fe80::9067:fb44:66b2:7604%4]) with mapi id 15.20.1446.018; Wed, 19 Dec 2018 19:19:40 +0000 From: Alistair Francis To: "qemu-devel@nongnu.org" , "qemu-riscv@nongnu.org" Thread-Topic: [PATCH v2 19/23] riscv: tcg-target: Add the prologue generation and register the JIT Thread-Index: AQHUl8/J3Aj/E5/ipECw4D5l9EIGrw== Date: Wed, 19 Dec 2018 19:19:39 +0000 Message-ID: References: In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.19.1 x-clientproxiedby: BYAPR02CA0008.namprd02.prod.outlook.com (2603:10b6:a02:ee::21) To MWHPR04MB0401.namprd04.prod.outlook.com (2603:10b6:300:70::18) x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [199.255.44.171] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; MWHPR04MB0832; 6:XRHZr3sG314sU4LJSft1mISlndNZxOboy93cPoekzUFhURN7aTwLH8Ank+Ryxc3SD26mgweXD/mLXg24bue2dy8GPlJQVm4Jhkg2NrYxX8NJvDtbRaUDgU+dwfMuFm86Y8Js2nYVg7+B31PnvGUz9OhbAWYYJmikWWvPFzEsqNzTsbQAbiw36MeSAsgNwpr+sgo/lxrdOfI6NcLkK/BCAFmyyqS/sRFo0zoIf+6Rr4xk/nv1IF9uaxAEOJu75kJC1ue0TuIpxkyD/9Rhohdm6nL1CRr+Qgbr+oGprC/H6ZjMNu7WJQUe0rZSzwER5eDMqM9ueZD6XFKPAkBkur0CZZXW1VH434BTxHxXvhUpXKlOXHdJvNGpe282gJPEFOdnsQjQYpXz9qzAdqPGFgmyCt4E8d2qgCKFZ+7ocyUFEZEUvGHDjETTRFrN5OtiyO3z6h5/zUQtSmkP+HiCyNB8ng==; 5:uryDswWfFh4mWsol80vLBpItPMrW4NNwEauKyNsVhGQe28EwgHPD1TaraNS9o+IrtwXTwPwUYISn694XnXirtBNL0OAKJNvZ7YFQStt07oT45le7goJTXc+NWDnuuWnEkHlUTAYmZ/2UtWHoWVFwsXIkVzyerZCLxWoLhfrU0XA=; 7:JF+ClrXQptELI0JPzWSRUxYxlg+PxqT8LW3Al3ZKfb4xsNVLcH186tvcc/JURhNXWLRc4cXxTHvrrrhK9RDsj1ie4MIsSPKIwljksxqe2dOlVcRClzBHbuo136+Iq1asQuNZQoFZQBv2lVI7zQBZhA== x-ms-office365-filtering-correlation-id: 6ca16d60-fd5c-4b3b-22db-08d665e6ec0d x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(4618075)(2017052603328)(7153060)(7193020); SRVR:MWHPR04MB0832; x-ms-traffictypediagnostic: MWHPR04MB0832: wdcipoutbound: EOP-TRUE x-microsoft-antispam-prvs: x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(3230021)(999002)(5005020)(6040522)(2401047)(8121501046)(3231475)(944501520)(52105112)(93006095)(93001095)(3002001)(10201501046)(6055026)(149066)(150057)(6041310)(20161123560045)(20161123562045)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(201708071742011)(7699051)(76991095); SRVR:MWHPR04MB0832; BCL:0; PCL:0; RULEID:; SRVR:MWHPR04MB0832; x-forefront-prvs: 0891BC3F3D x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(376002)(39860400002)(366004)(396003)(346002)(136003)(189003)(199004)(6506007)(68736007)(76176011)(386003)(102836004)(476003)(2616005)(44832011)(486006)(97736004)(118296001)(478600001)(316002)(26005)(6346003)(4326008)(110136005)(54906003)(186003)(39060400002)(8676002)(50226002)(81166006)(86362001)(6512007)(52116002)(81156014)(53936002)(71200400001)(99286004)(256004)(71190400001)(8936002)(446003)(11346002)(305945005)(7736002)(106356001)(6486002)(3846002)(6116002)(66066001)(25786009)(5660300001)(2906002)(72206003)(2501003)(14454004)(36756003)(6436002)(105586002); DIR:OUT; SFP:1102; SCL:1; SRVR:MWHPR04MB0832; H:MWHPR04MB0401.namprd04.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alistair.Francis@wdc.com; x-microsoft-antispam-message-info: 21QxAJjtFtLXdWArCIifIy4dK9mJjl8mrkohEIG2yzsS7tJ623pOtUfi7w6MkFB6E0JZ6ac6HStASETkhBsceu1HBXsdGqSv+l03fqPUikk9E28DYpIIC2V2ap0t1M+CTaTlXI6hke46hUi0ruC6Ht0wlbejdLLckeWDqwNpvqoIWNWLNiJWe/CwDHJL0z0qjrlAtjz0gC+/zvvpDq3k6NZHORXoDwgyLqFy9UxI75ksfIHFLQo/9OzWOGRQYkYCAoEZno/Q2o0VxKcvnn/yy/ITCKQAySlZDUV101/XnLycURCfnSVVV7lEyeh1WNIA spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6ca16d60-fd5c-4b3b-22db-08d665e6ec0d X-MS-Exchange-CrossTenant-originalarrivaltime: 19 Dec 2018 19:19:39.9003 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: b61c8803-16f3-4c35-9b17-6f65f441df86 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR04MB0832 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 216.71.154.42 Subject: [Qemu-devel] [PATCH v2 19/23] riscv: tcg-target: Add the prologue generation and register the JIT 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: "alistair23@gmail.com" , "richard.henderson@linaro.org" , Alistair Francis Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Alistair Francis Signed-off-by: Michael Clark Reviewed-by: Richard Henderson --- tcg/riscv/tcg-target.inc.c | 111 +++++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) diff --git a/tcg/riscv/tcg-target.inc.c b/tcg/riscv/tcg-target.inc.c index bab3d1e6d2..bc1a2bc4ab 100644 --- a/tcg/riscv/tcg-target.inc.c +++ b/tcg/riscv/tcg-target.inc.c @@ -1802,3 +1802,114 @@ static const TCGTargetOpDef *tcg_target_op_def(TCGOpcode op) return NULL; } } + +static const int tcg_target_callee_save_regs[] = { + TCG_REG_S0, /* used for the global env (TCG_AREG0) */ + TCG_REG_S1, + TCG_REG_S2, + TCG_REG_S3, + TCG_REG_S4, + TCG_REG_S5, + TCG_REG_S6, + TCG_REG_S7, + TCG_REG_S8, + TCG_REG_S9, + TCG_REG_S10, + TCG_REG_S11, + TCG_REG_RA, /* should be last for ABI compliance */ +}; + +/* Stack frame parameters. */ +#define REG_SIZE (TCG_TARGET_REG_BITS / 8) +#define SAVE_SIZE ((int)ARRAY_SIZE(tcg_target_callee_save_regs) * REG_SIZE) +#define TEMP_SIZE (CPU_TEMP_BUF_NLONGS * (int)sizeof(long)) +#define FRAME_SIZE ((TCG_STATIC_CALL_ARGS_SIZE + TEMP_SIZE + SAVE_SIZE \ + + TCG_TARGET_STACK_ALIGN - 1) \ + & -TCG_TARGET_STACK_ALIGN) +#define SAVE_OFS (TCG_STATIC_CALL_ARGS_SIZE + TEMP_SIZE) + +/* We're expecting to be able to use an immediate for frame allocation. */ +QEMU_BUILD_BUG_ON(FRAME_SIZE > 0x7ff); + +/* Generate global QEMU prologue and epilogue code */ +static void tcg_target_qemu_prologue(TCGContext *s) +{ + int i; + + tcg_set_frame(s, TCG_REG_SP, TCG_STATIC_CALL_ARGS_SIZE, TEMP_SIZE); + + /* TB prologue */ + tcg_out_opc_imm(s, OPC_ADDI, TCG_REG_SP, TCG_REG_SP, -FRAME_SIZE); + for (i = 0; i < ARRAY_SIZE(tcg_target_callee_save_regs); i++) { + tcg_out_st(s, TCG_TYPE_REG, tcg_target_callee_save_regs[i], + TCG_REG_SP, SAVE_OFS + i * REG_SIZE); + } + +#if !defined(CONFIG_SOFTMMU) + tcg_out_movi(s, TCG_TYPE_PTR, TCG_GUEST_BASE_REG, guest_base); + tcg_regset_set_reg(s->reserved_regs, TCG_GUEST_BASE_REG); +#endif + + /* Call generated code */ + tcg_out_mov(s, TCG_TYPE_PTR, TCG_AREG0, tcg_target_call_iarg_regs[0]); + tcg_out_opc_imm(s, OPC_JALR, TCG_REG_ZERO, tcg_target_call_iarg_regs[1], 0); + + /* Return path for goto_ptr. Set return value to 0 */ + s->code_gen_epilogue = s->code_ptr; + tcg_out_mov(s, TCG_TYPE_REG, TCG_REG_A0, TCG_REG_ZERO); + + /* TB epilogue */ + tb_ret_addr = s->code_ptr; + for (i = 0; i < ARRAY_SIZE(tcg_target_callee_save_regs); i++) { + tcg_out_ld(s, TCG_TYPE_REG, tcg_target_callee_save_regs[i], + TCG_REG_SP, SAVE_OFS + i * REG_SIZE); + } + + tcg_out_opc_imm(s, OPC_ADDI, TCG_REG_SP, TCG_REG_SP, FRAME_SIZE); + tcg_out_opc_imm(s, OPC_JALR, TCG_REG_ZERO, TCG_REG_RA, 0); +} + +typedef struct { + DebugFrameHeader h; + uint8_t fde_def_cfa[4]; + uint8_t fde_reg_ofs[ARRAY_SIZE(tcg_target_callee_save_regs) * 2]; +} DebugFrame; + +#define ELF_HOST_MACHINE EM_RISCV + +static const DebugFrame debug_frame = { + .h.cie.len = sizeof(DebugFrameCIE) - 4, /* length after .len member */ + .h.cie.id = -1, + .h.cie.version = 1, + .h.cie.code_align = 1, + .h.cie.data_align = -(TCG_TARGET_REG_BITS / 8) & 0x7f, /* sleb128 */ + .h.cie.return_column = TCG_REG_RA, + + /* Total FDE size does not include the "len" member. */ + .h.fde.len = sizeof(DebugFrame) - offsetof(DebugFrame, h.fde.cie_offset), + + .fde_def_cfa = { + 12, TCG_REG_SP, /* DW_CFA_def_cfa sp, ... */ + (FRAME_SIZE & 0x7f) | 0x80, /* ... uleb128 FRAME_SIZE */ + (FRAME_SIZE >> 7) + }, + .fde_reg_ofs = { + 0x80 + 9, 12, /* DW_CFA_offset, s1, -96 */ + 0x80 + 18, 11, /* DW_CFA_offset, s2, -88 */ + 0x80 + 19, 10, /* DW_CFA_offset, s3, -80 */ + 0x80 + 20, 9, /* DW_CFA_offset, s4, -72 */ + 0x80 + 21, 8, /* DW_CFA_offset, s5, -64 */ + 0x80 + 22, 7, /* DW_CFA_offset, s6, -56 */ + 0x80 + 23, 6, /* DW_CFA_offset, s7, -48 */ + 0x80 + 24, 5, /* DW_CFA_offset, s8, -40 */ + 0x80 + 25, 4, /* DW_CFA_offset, s9, -32 */ + 0x80 + 26, 3, /* DW_CFA_offset, s10, -24 */ + 0x80 + 27, 2, /* DW_CFA_offset, s11, -16 */ + 0x80 + 1 , 1, /* DW_CFA_offset, ra, -8 */ + } +}; + +void tcg_register_jit(void *buf, size_t buf_size) +{ + tcg_register_jit_int(buf, buf_size, &debug_frame, sizeof(debug_frame)); +}