From nobody Sat Oct 24 00:32:59 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=oss.qualcomm.com ARC-Seal: i=1; a=rsa-sha256; t=1790790948; cv=none; d=zohomail.com; s=zohoarc; b=j25iHiZNIQySgjfcT8Q5T/6eNeIZ+evXlLePP7O32znI+PgpAmJsZAnz2qIBwXRYKH+nT1U1ZMGFLKjNYwHobq/PSlNSfhiMVly/tVkxQWYUYD2MfM5IlLUjvuAy55ngTeP8BO9tv8ROyqRsN2NwSORp6dpNkusKxCx/ebbm5kY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1790790948; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=ZL+P5t8+YVthSqcIpyQ/Kog6Z3XOt7NK/ouC31bEcpA=; b=nb/CSIP0UChViSgt4PhO4Vojg4RKYgdTW/q2/uWqEjjOfGmlAtUiqWe90yp2zPgz6nDvPA/1yBIKtZeDsszCGng7Hf0tJlejMG0YQOdVpbMwYuPSyGMqCIbpP2TdfW8zf637p2e2ONoHBPQv/yv7xYjW/xZFBxPqJu4zdkxdU+M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1790790948276762.8651974226563; Wed, 30 Sep 2026 10:55:48 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xByWh-00076K-Aj; Wed, 30 Sep 2026 13:55:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xByWc-00075I-N6 for qemu-devel@nongnu.org; Wed, 30 Sep 2026 13:55:28 -0400 Received: from mx0b-0031df01.pphosted.com ([205.220.180.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xByWa-0001zx-No for qemu-devel@nongnu.org; Wed, 30 Sep 2026 13:55:26 -0400 Received: from pps.filterd (m0279872.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 68UHeq963464018 for ; Wed, 30 Sep 2026 17:55:23 GMT Received: from mail-dl1-f69.google.com (mail-dl1-f69.google.com [74.125.82.69]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4h16wcr3bq-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Wed, 30 Sep 2026 17:55:23 +0000 (GMT) Received: by mail-dl1-f69.google.com with SMTP id a92af1059eb24-147be78cd56so404421c88.1 for ; Wed, 30 Sep 2026 10:55:23 -0700 (PDT) Received: from hu-bcain-lv.qualcomm.com (Global_NAT1.qualcomm.com. [129.46.96.20]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-14d08fb50f1sm8595791c88.13.2026.09.30.10.55.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Sep 2026 10:55:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:content-type:date:from:message-id :mime-version:subject:to; s=qcppdkim1; bh=ZL+P5t8+YVthSqcIpyQ/Ko g6Z3XOt7NK/ouC31bEcpA=; b=BS8IPi30EMSf8swIQSEwNykFUpzBVTQr4kHeqA 7aXJm2t3INiWUFgsSvWD7jv2an3CkQQjjjjAULMy6fad2jScml6R6hZf31aAJHOi kmG07+lXsHZTUoc/KPhPMv07PwPklHkSjUURtfiQ7fXCI8+/23kFbRvWkpLO46O7 RrfjZgkqZQcS7dv/Nq7mSnZTvDSfIe31c+PIoDW/vY1/TMU8WuPUzMMOqGRBJQiW 1kHznFhVn1Ws7KhF/3K9efZIbfa14zEW9lCp51VaBw5XDkcaAoo8qNk32Y+OPK+c PGQc9QaUAAGp4lGw43OwMK/n1nyd7uX2pHqYVXxb6CSSpOQA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1790790922; x=1791395722; darn=nongnu.org; h=content-transfer-encoding:content-type:mime-version:message-id:date :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to :content-type; bh=ZL+P5t8+YVthSqcIpyQ/Kog6Z3XOt7NK/ouC31bEcpA=; b=LS4n2aDBrFORQIW+6+9aYe51zq+JoMxEcdZ5IAltkl/l8RDpJ0XFvMPD57NK5o9HQu Mw+4erXA+0voyWVi3EZ4vMmQ5xhcZXaBjgzu6XyWBvzR41xke8MgOzbBPsc+eF27ob65 ZaS0+m553oVTjct/asaraUsBFMiqIm5SZEMVn9HJHCofT9+Yr+JC1sWYJRqJOemI2kAU fv/rcwV/RSx8rIHpBXCMB9MjSp7s26UDBSMS1oVKeMVWzgfgB7ruSpJVDNyF8g8zUgG/ aMX9nj7896ZwykVivkoBaQMKWxVI2LlqcfFxbQiLvztA9NNF4xD93nQvf4IcPsfZB4C7 vIow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790790922; x=1791395722; h=content-transfer-encoding:content-type:mime-version:message-id:date :subject:cc:to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to:content-type; bh=ZL+P5t8+YVthSqcIpyQ/Kog6Z3XOt7NK/ouC31bEcpA=; b=TIjj+6IiIUDOZL9dVIwtDaJpc96jfjqYXj0vS5iFP17rj5lE4v1sgzSzL/zubLBWoT BAPIYndNea3SRw4wyAK1C1RvGdgoPiejpBQGKZmSRuXVZObs1NzH2odxskLIfoz/iS/4 rfFAkbIBO9aqR2qgUUEKmYEpvGUHPH3vomm5tNWmmiIoDQyS959TsX9Qrf5yH2nIMrxY ydORllXE5eFmlaIOs4mPp5isnCU55/8oUNpdD+hcihb83AxN3304qTNQoCAE2WfxCKwX E+ebWwWMGVKcebC1vhT943E0rAOLqSV+uL26QqfKpGHxhjTg2og4TTuC90P1rKsbVzYr byiA== X-Gm-Message-State: AFuF++kKKesSKUciwbAHWcPdW+k0QmiJX8Y+dVdAk5hBzOxB5pWi/YCP YQYXxB11OWJ0/48/VFy+BK3owFeNEyQqw1GzNr944Vv6c3sFqK/52pTvgpwptEjrtnw0GzNJeJl +C2IArcaZeaa2KsPY/li//Loxwf0KMVyRzY10jyebr/YbkGDNOjAcdKMIDjOKrkv8hA== X-Gm-Gg: AYBFou1zHxu98soucpe/sgknDTivif6nck/ofeW5Ax1mV0mytRJfQLe2BTahFLCLzp5 iuHcWvCB65YauX/SrQkYqM74V+nfM1ygAiAnPK3g+KrBBYKh+iiVC/1Xyi7gD+GM/bMFhNWQH6H hcEX0yKxuo0DkCJAqSkol6QaNxJD2Wjq8wZNKaBu3AsfQwZKkgOqd39JsKGFrBCuqA2KwgX8pFV mX9YwzAiSIPkbQ2CajpuG5aQzHMLtBcNHTGJf2362HTF1dJ0z0DOehjkgP61Eyu/3GVXU/6gYWJ mj/FZD/DNQit6wUBfCK6A72gKP747wx6I6nWbnW5V0JvbLMmyRSAFRfkIaW9ab1ecpLN+GCC9kS +ppA+rcVVxOpJX5+aiqpFM7dGi28CiPxkQTctCopDZHKm1jY= X-Received: by 2002:a05:7022:239a:b0:145:3a5:d918 with SMTP id a92af1059eb24-14d3348fdb8mr2500439c88.33.1790790921770; Wed, 30 Sep 2026 10:55:21 -0700 (PDT) X-Received: by 2002:a05:7022:239a:b0:145:3a5:d918 with SMTP id a92af1059eb24-14d3348fdb8mr2500406c88.33.1790790921181; Wed, 30 Sep 2026 10:55:21 -0700 (PDT) From: Brian Cain To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Alexandre Iooss , Pierrick Bouvier , Matheus Tavares Bernardino , Brian Cain Subject: [PATCH] contrib/plugins/uftrace: add support for Hexagon Date: Wed, 30 Sep 2026 10:55:19 -0700 Message-Id: <20260930175519.3601312-1-brian.cain@oss.qualcomm.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwOTMwMDA3MiBTYWx0ZWRfX74Rq6EGmYYXH t8GQGn5Lmglb2zCfZsfW1EcTwAB2tzD+QxLGYtomBOR3NPKtlkG3tpblXoXyuXi9xF9QygusUgH rxu/7HA3bEKW9heX9ws7D0vdpSWP1AarFB21997qxZRimU29pJX1LihwLK92Jc/pDZ7k/ZEh3zP j7Z5np1LaCldh0NrekANJZeCrLC7oWHmlGIqtIJGTMN810UNHMo5Jpir7RnK8R6+vvdVvvj42Cu 82gU3H/jIrHU7jtFowlM1CbqN+2MRijIxwpWKIOnt4zm4FBlKBnRP7OID9S0jrLvuA5k0yQFZjo 38Pm+8P02Ak3JPSMl97cpKr6flWLt1y162g8FFBqyD0MD3uBZRWrxh0Skyq5zqyILNFu4pojXob nNpjcNe+jfH+ajRxzbVvLtmNNoaxVPqdN+zBUnga5tvUu8vJFb19SO3F0llI91wlPD0GgV/oHkO wYJqas3dRh8gkZel0yg== X-Proofpoint-GUID: lpaM5gPaMljtoJ0V-6o8KkUX5qeMAA5V X-Proofpoint-Spam-Info: AW1haW4tMjYwOTMwMDA3MiBTYWx0ZWRfX1MYcE26w1bZ5 oJsqOV+YPSEEMm9VcX5pj7VBjVF8TLCBevbhpIe+v4qq1jiG+Bb2al4L7Cd0R/eZVLNtmdqXH42 1J8Szy+GNXVf2YP3sBVyJ0US6vbwV1s= X-Authority-Analysis: v=2.4 cv=S51MU4sP c=1 sm=1 tr=0 ts=6abd4d0b cx=c_pps a=kVLUcbK0zfr7ocalXnG1qA==:117 a=ouPCqIW2jiPt+lZRy3xVPw==:17 a=IkcTkHD0fZMA:10 a=VdqzKS8jKosA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=yx91gb_oNiZeI1HMLzn7:22 a=NEAV23lmAAAA:8 a=EUspDBNiAAAA:8 a=xgyr-5ruijG_Iadbgw4A:9 a=QEXdDO2ut3YA:10 a=vr4QvYf-bLy2KjpDp97w:22 X-Proofpoint-ORIG-GUID: lpaM5gPaMljtoJ0V-6o8KkUX5qeMAA5V X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.134,FMLib:17.12.100.49 definitions=2026-09-30_04,2026-09-21_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 phishscore=0 priorityscore=1501 clxscore=1015 impostorscore=0 lowpriorityscore=0 spamscore=0 adultscore=0 bulkscore=0 malwarescore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2609040000 definitions=main-2609300072 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=205.220.180.131; envelope-from=brian.cain@oss.qualcomm.com; helo=mx0b-0031df01.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @qualcomm.com) X-ZM-MESSAGEID: 1790790949387158500 From: Matheus Tavares Bernardino Signed-off-by: Matheus Tavares Bernardino Signed-off-by: Brian Cain Acked-by: Alex Benn=C3=A9e Reviewed-by: Pierrick Bouvier --- docs/about/emulation.rst | 2 +- contrib/plugins/uftrace.c | 130 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 131 insertions(+), 1 deletion(-) diff --git a/docs/about/emulation.rst b/docs/about/emulation.rst index c58149086cd..b404c5c5e8e 100644 --- a/docs/about/emulation.rst +++ b/docs/about/emulation.rst @@ -836,7 +836,7 @@ Uftrace This plugin generates a binary trace compatible with `uftrace `_. =20 -Plugin supports aarch64, x64 and riscv64, and works in user and system mod= e, +Plugin supports aarch64, x64, riscv64, and Hexagon, and works in user and = system mode, allowing to trace a system boot, which is not something possible usually. =20 In user mode, the memory mapping is directly copied from ``/proc/self/maps= `` at diff --git a/contrib/plugins/uftrace.c b/contrib/plugins/uftrace.c index 063e32220b1..bf4ca7c6894 100644 --- a/contrib/plugins/uftrace.c +++ b/contrib/plugins/uftrace.c @@ -99,6 +99,19 @@ typedef struct { struct qemu_plugin_register *reg_cr0; } X64Cpu; =20 +typedef enum { + HEX_MONITOR, + HEX_GUEST, + HEX_USER, + HEX_PRIVILEGE_LEVEL_MAX, +} HexagonPrivilegeLevel; + +typedef struct { + struct qemu_plugin_register *reg_fp; + struct qemu_plugin_register *reg_ssr; + struct qemu_plugin_register *reg_framekey; +} HexagonCPU; + typedef struct { struct qemu_plugin_register *reg_fp; struct qemu_plugin_register *reg_priv; @@ -453,6 +466,21 @@ static uint64_t cpu_read_memory64(Cpu *cpu, uint64_t a= ddr) return *((uint64_t *) buf->data); } =20 +static uint32_t cpu_read_memory32(Cpu *cpu, uint64_t addr) +{ + if (!addr) { + return 0; + } + GByteArray *buf =3D cpu->buf; + g_byte_array_set_size(buf, 0); + bool read =3D qemu_plugin_read_memory_vaddr(addr, buf, 4); + if (!read) { + return 0; + } + g_assert(buf->len =3D=3D 4); + return *((uint32_t *) buf->data); +} + static void cpu_unwind_stack(Cpu *cpu, uint64_t frame_pointer, uint64_t pc) { g_assert(callstack_empty(cpu->cs)); @@ -698,6 +726,106 @@ static CpuOps x64_ops =3D { .does_insn_modify_frame_pointer =3D x64_does_insn_modify_frame_pointer, }; =20 +static uint8_t hexagon_num_privilege_levels(void) +{ + return HEX_PRIVILEGE_LEVEL_MAX; +} + +static const char *hexagon_get_privilege_level_name(uint8_t pl) +{ + switch (pl) { + case HEX_MONITOR: return "monitor"; + case HEX_GUEST: return "guest"; + case HEX_USER: return "user"; + default: + g_assert_not_reached(); + } +} + +#define HEX_SSR_FIELD_UM 16 +#define HEX_SSR_FIELD_EX 17 +#define HEX_SSR_FIELD_GM 19 + +static uint8_t hexagon_get_privilege_level(Cpu *cpu_) +{ + HexagonCPU *cpu =3D cpu_->arch; + uint32_t ssr =3D cpu_read_register32(cpu_, cpu->reg_ssr); + bool ex =3D (ssr >> HEX_SSR_FIELD_EX) & 1; + bool um =3D (ssr >> HEX_SSR_FIELD_UM) & 1; + bool gm =3D (ssr >> HEX_SSR_FIELD_GM) & 1; + + if (ex || !um) { + return HEX_MONITOR; + } else if (!ex && um) { + return gm ? HEX_GUEST : HEX_USER; + } + g_assert_not_reached(); +} + +static uint64_t hexagon_get_frame_pointer(Cpu *cpu_) +{ + HexagonCPU *cpu =3D cpu_->arch; + return cpu_read_register32(cpu_, cpu->reg_fp); +} + +static uint64_t hexagon_get_next_frame_pointer(Cpu *cpu_, uint64_t fp) +{ + return cpu_read_memory32(cpu_, fp); +} + +static uint64_t hexagon_get_next_return_address(Cpu *cpu_, + uint64_t frame_pointer) +{ + HexagonCPU *cpu =3D cpu_->arch; + uint64_t framekey =3D cpu_read_register32(cpu_, cpu->reg_framekey); + uint64_t scrambled_lr =3D cpu_read_memory32(cpu_, frame_pointer + 4); + uint64_t lr =3D scrambled_lr ^ framekey; + return lr; +} + +static void hexagon_init(Cpu *cpu_) +{ + HexagonCPU *cpu =3D g_new0(HexagonCPU, 1); + cpu_->arch =3D cpu; + cpu->reg_fp =3D plugin_find_register("r30"); + if (!cpu->reg_fp) { + fprintf(stderr, "uftrace plugin: frame pointer register (R30) is n= ot " + "available.\n"); + g_abort(); + } + cpu->reg_ssr =3D plugin_find_register("ssr"); + if (trace_privilege_level && !cpu->reg_ssr) { + fprintf(stderr, "uftrace plugin: trace-privilege-level is not " + "supported for hexagon-linux-user.\n"); + g_abort(); + } + cpu->reg_framekey =3D plugin_find_register("framekey"); + g_assert(cpu->reg_framekey); +} + +static void hexagon_end(Cpu *cpu) +{ + g_free(cpu->arch); +} + +static bool hexagon_does_insn_modify_frame_pointer(const char *disas) +{ + return strstr(disas, "alloc") || + strstr(disas, "R30") || strstr(disas, "R31:30"); +} + +static CpuOps hexagon_ops =3D { + .init =3D hexagon_init, + .end =3D hexagon_end, + .get_frame_pointer =3D hexagon_get_frame_pointer, + .get_next_frame_pointer =3D hexagon_get_next_frame_pointer, + .get_next_return_address =3D hexagon_get_next_return_address, + .get_privilege_level =3D hexagon_get_privilege_level, + .num_privilege_levels =3D hexagon_num_privilege_levels, + .get_privilege_level_name =3D hexagon_get_privilege_level_name, + .does_insn_modify_frame_pointer =3D hexagon_does_insn_modify_frame_poi= nter, +}; + static uint8_t riscv64_num_privilege_levels(void) { return RISCV64_PRIVILEGE_LEVEL_MAX; @@ -984,6 +1112,8 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin= _id_t id, arch_ops =3D x64_ops; } else if (!strcmp(info->target_name, "riscv64")) { arch_ops =3D riscv64_ops; + } else if (!strcmp(info->target_name, "hexagon")) { + arch_ops =3D hexagon_ops; } else { fprintf(stderr, "plugin uftrace: %s target is not supported\n", info->target_name); --=20 2.34.1