From patchwork Tue Dec 21 16:47:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 526598 Delivered-To: patch@linaro.org Received: by 2002:a05:6e04:2287:0:0:0:0 with SMTP id bl7csp5222882imb; Tue, 21 Dec 2021 08:49:12 -0800 (PST) X-Google-Smtp-Source: ABdhPJyI1mhqngsK0l+K9HM4FtFtYMdZ7J3VLAh1No590lF4Fl/S8LEnQcdrVRnIPrcsygdwXwnI X-Received: by 2002:a25:d98d:: with SMTP id q135mr5214598ybg.731.1640105352344; Tue, 21 Dec 2021 08:49:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1640105352; cv=none; d=google.com; s=arc-20160816; b=zfCsQTyULhCNixfcWvPDbezVc8KJ0sLWpP6BwUgl8ye0ZySzHdvqtU8/fn7v/bGTnA ifVbpsMJwv0stJcgiefa+6mq2OP81D0FsP0qeZE+MWeFv1P+Yqa1yYlt3mMG9Z1xzIYA HHZ6s/SUWSr9BaHBrPXmwu341DBSLN99iZgZHy6PcIkerzFpOPmadUe8oCyB6uhD5bXS X8xHU6AFRG9psnYpBWq79RO/Ch6iG/dwZD6ESnvRwa+fsxmsKzD7Q3vk7OCTElD5AE9t 02yNsIFh1s6JKO/3jz8RwOIvMyYTQifedhfsgewgYilf3A+lZb/WwfGJWAm2gjxxiaT1 K5RQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=zUDP7FmcR1rHD0pS6HJ64HKaD5yQmCsg2nMq4yKO5cY=; b=K+lOO7X2JUxoz9IXEUMlw7idTZKpERjb/6pEUXrS+NyrUdusajk9/nsXOYTI2/8PYh O3aHtlQvELG7lYLX1YjM8acRqd5MLNBbCr/c9SYz1AYOPDgrfpueWqwSgFOUG+keylxd xMXRkRFQbLWpK9t+INXic+yzbcMekyI4vT2PwZIUic540/VGdL1hzxFvHY18KP227zpB nDprYlI6FqfiAb03pa38WXn8Sb6s5fDwTb3z3PbIZLzlCgv/hDTLDALWWyJTyHGXxCVH e3dmkJFEmB3OxRlPgso7mam3iJLW9ZDsIpKWyTRa3ykP26k4/owDw3kpD+BaUFipKo0q Ey8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=VvxR0yI7; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id n136si20592506yba.80.2021.12.21.08.49.12 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 21 Dec 2021 08:49:12 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=VvxR0yI7; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:37772 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mziK7-0000Ah-JU for patch@linaro.org; Tue, 21 Dec 2021 11:49:11 -0500 Received: from eggs.gnu.org ([209.51.188.92]:55774) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mziIs-00005Y-Pt for qemu-devel@nongnu.org; Tue, 21 Dec 2021 11:47:54 -0500 Received: from [2607:f8b0:4864:20::102d] (port=52974 helo=mail-pj1-x102d.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mziIo-0007bA-Oa for qemu-devel@nongnu.org; Tue, 21 Dec 2021 11:47:54 -0500 Received: by mail-pj1-x102d.google.com with SMTP id co15so13019696pjb.2 for ; Tue, 21 Dec 2021 08:47:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=zUDP7FmcR1rHD0pS6HJ64HKaD5yQmCsg2nMq4yKO5cY=; b=VvxR0yI78aINeYBYI8Fwm3IgvypmRxbbe4JcW/IuYtTKRQvmJTxCYoE4vKePPcmBJS hZ3/feiJWiWg+MRjhRE18tF8sId+dJIamtL4Vb+n9tQDbjj4JVT3eySfb4eBwMlWmny+ 6JgzFAADuEGVtpkF94ztTTXtF6qIMJyGQoWz98w2iHXdmmhhhMEXBqBzV8rPwx/GmxSe 5+I8iVcRHIt7bwWUPWBIx5BGMoZ1NkhTvyvVoUr1XB1rbZwaO8DUB6VPfL4Q7QNBWJ9b iF45sm/qvn7C2zdkvj6olL6eiyJZBwHEvdMMhj8kkhTSnt9tikOQTgvWWp7xfLPi86Mb t2BA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=zUDP7FmcR1rHD0pS6HJ64HKaD5yQmCsg2nMq4yKO5cY=; b=aVNfh+TzLwf5oqWKnvR1Z4K+N/ViSBBsdVEjZeXjh1GZk6nBDjxe1GhLsjVy6p3+mP dyeHDNwp0InvkGjIa39VHy5I/CxKwHPCTiMxRaGszEp6CK88ymIBU/Pk8Fi7eRt8sktj 8SBhvnmP9LiswZ2iyhabgz/s/sL7vgnyTzKCJg6Ce39qlgBhuAmuoNbiAJM5zB8UFrTQ si5IHozMT7Wzq9BpeSWAEb4pMU+XuHUJSd8fOZdH4U3K4ask6v76oWC0mUZuS3ZaAhya rU+dQjzMYRtQX4UCNfVm4pb5SeOQK9UNdMP1dgjiNeY8G6ArgiVVimwaqlqkCK0Crvfm UI8w== X-Gm-Message-State: AOAM532iucpHOFX8Ubui66xL3AwBeaDPbrzPTPDcd8KDSWnn6CXNLJjW r0/HHHJHVqLM80BtlZYwM4NW6bAuv9D2uA== X-Received: by 2002:a17:902:c193:b0:149:b6f:4e65 with SMTP id d19-20020a170902c19300b001490b6f4e65mr3871039pld.81.1640105265693; Tue, 21 Dec 2021 08:47:45 -0800 (PST) Received: from localhost.localdomain ([156.19.246.20]) by smtp.gmail.com with ESMTPSA id b192sm2256818pga.35.2021.12.21.08.47.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Dec 2021 08:47:45 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 07/31] tcg/loongarch64: Implement necessary relocation operations Date: Tue, 21 Dec 2021 08:47:13 -0800 Message-Id: <20211221164737.1076007-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211221164737.1076007-1-richard.henderson@linaro.org> References: <20211221164737.1076007-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::102d (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::102d; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102d.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: WANG Xuerui , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: WANG Xuerui Signed-off-by: WANG Xuerui Reviewed-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé Message-Id: <20211221054105.178795-8-git@xen0n.name> Signed-off-by: Richard Henderson --- tcg/loongarch64/tcg-target.c.inc | 66 ++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/tcg/loongarch64/tcg-target.c.inc b/tcg/loongarch64/tcg-target.c.inc index 1c1b798c06..a88ba9a253 100644 --- a/tcg/loongarch64/tcg-target.c.inc +++ b/tcg/loongarch64/tcg-target.c.inc @@ -168,3 +168,69 @@ static bool tcg_target_const_match(int64_t val, TCGType type, int ct) } return false; } + +/* + * Relocations + */ + +/* + * Relocation records defined in LoongArch ELF psABI v1.00 is way too + * complicated; a whopping stack machine is needed to stuff the fields, at + * the very least one SOP_PUSH and one SOP_POP (of the correct format) are + * needed. + * + * Hence, define our own simpler relocation types. Numbers are chosen as to + * not collide with potential future additions to the true ELF relocation + * type enum. + */ + +/* Field Sk16, shifted right by 2; suitable for conditional jumps */ +#define R_LOONGARCH_BR_SK16 256 +/* Field Sd10k16, shifted right by 2; suitable for B and BL */ +#define R_LOONGARCH_BR_SD10K16 257 + +static bool reloc_br_sk16(tcg_insn_unit *src_rw, const tcg_insn_unit *target) +{ + const tcg_insn_unit *src_rx = tcg_splitwx_to_rx(src_rw); + intptr_t offset = (intptr_t)target - (intptr_t)src_rx; + + tcg_debug_assert((offset & 3) == 0); + offset >>= 2; + if (offset == sextreg(offset, 0, 16)) { + *src_rw = deposit64(*src_rw, 10, 16, offset); + return true; + } + + return false; +} + +static bool reloc_br_sd10k16(tcg_insn_unit *src_rw, + const tcg_insn_unit *target) +{ + const tcg_insn_unit *src_rx = tcg_splitwx_to_rx(src_rw); + intptr_t offset = (intptr_t)target - (intptr_t)src_rx; + + tcg_debug_assert((offset & 3) == 0); + offset >>= 2; + if (offset == sextreg(offset, 0, 26)) { + *src_rw = deposit64(*src_rw, 0, 10, offset >> 16); /* slot d10 */ + *src_rw = deposit64(*src_rw, 10, 16, offset); /* slot k16 */ + return true; + } + + return false; +} + +static bool patch_reloc(tcg_insn_unit *code_ptr, int type, + intptr_t value, intptr_t addend) +{ + tcg_debug_assert(addend == 0); + switch (type) { + case R_LOONGARCH_BR_SK16: + return reloc_br_sk16(code_ptr, (tcg_insn_unit *)value); + case R_LOONGARCH_BR_SD10K16: + return reloc_br_sd10k16(code_ptr, (tcg_insn_unit *)value); + default: + g_assert_not_reached(); + } +}