Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1BE22CAC5B0 for ; Thu, 2 Oct 2025 11:30:07 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v4HRj-0006L5-3u; Thu, 02 Oct 2025 07:26:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v4HR1-00066e-Af for qemu-riscv@nongnu.org; Thu, 02 Oct 2025 07:25:20 -0400 Received: from mail-yw1-x1134.google.com ([2607:f8b0:4864:20::1134]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1v4HQ7-0005tL-3y for qemu-riscv@nongnu.org; Thu, 02 Oct 2025 07:25:15 -0400 Received: by mail-yw1-x1134.google.com with SMTP id 00721157ae682-71d60157747so10733167b3.0 for ; Thu, 02 Oct 2025 04:24:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1759404252; x=1760009052; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=WjI9dJxX94W6y/LElLrzjNkdEE1XUWa9/CAhU7PpN88=; b=QufWiOfW2GxwMdR360bRL+883dGxXTHlJ8aXOvWPagEA9VQwdEeIaSZfc+8swClt6v weT9J1/2Q2fIHhmh77D3IcCgs+qnBDGLN25Zp9SmaIy9awhOSxwvAAj5OoN04z6RcOvD zu5KApU+c3iv0Xrak/gv0HJRMGjIPZliRILhEYUdamZcyDjWKt07ZHX8BgzpgPpb1o4d p5GjqmmfpUkjm9GKmO99vEGmXB5XgSIq+hiR43jOZJjunqNWiGhoqbrdYbcpi+FUAjOf 9spUiJfBZBKQTPTsyjLHHGSNFFw2krYe/vP54OSQeyLi3b7zJmHtHD1yY+mnCjTKr56b e4hA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1759404252; x=1760009052; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=WjI9dJxX94W6y/LElLrzjNkdEE1XUWa9/CAhU7PpN88=; b=NPLlfRq2DL1KhCLEW7xR0zdp1/GFkfILDgvNsNvfMS3C5UVjww6++m8TmCsTdV89uQ 22xWcPc0CJ0YpbcOSuqKmFTNlyig9or2fsSnCi1a9ct7LzJTm51Ku6Sem31qyxU90e4Q HEJIyaMKUgCTY+SdecxFhE+JJskG4cmeR32uMj47YcRs9UdhrwGFM582dQD1Nliz8eR5 6iXRqx3HlNiU0e375BVG5jbg/hp8jL4PHjmAM6qjisuAMJ2I0PXtmDi2CvOk/yr2+LcT IbPQu0lmGkPcK2HpK6AH4cGIRNs6XEEdm92I8mWnH/vW69PmCSekZqxeg/oGU9/FsNUe pFpA== X-Gm-Message-State: AOJu0YzkPSKYm2FG0FkO+ZKQY3+b69Hkl2m4i9azgMMNGimti3+6itdr tnh2IrwVRFgzaj6vcAkqo6TqYtY74Er4dS2qrzHPhcu5QnGnyGzkCN+4AXfAr+Xf1Fs= X-Gm-Gg: ASbGncthlSLYOhRjVMggvQBJQeE8ft0oh2nXecp4iAeqy7QZ3o/bPs6OTOIQ+v1O4Jn SrHSYAU3CYReYTEhhX0s0K+dCi2L0eJzCHeUNqvErYx7Ffb0HRAhdtisSUL2a2r5vm3gFkBgno2 6gOt9lDyECvD1QHCH6g9OdKxGSUbtm5D8WT6aKEopbSdy5ALp5ktz2C4gAmsCGKMj8pZK6smOco VW5qCrV0TQOIPpoGvpWM7m5m4JjGsuTAcnLdkqNHQMa9bpKesru5pZ8BHUl7PqLNzZb+QP9/lm0 X3rVLLaaAY6NL2MK7hldM2Lqf2zy3MJMl2bjJaRHfayT33To6dnuX7nteiEUNvORqRO0TtrlOdr crLTFNNWGghWT1dAWAIVVby6dTzSAhwiDV4yFxu/LggDNfFdhIqGPIwE3u7jLG7dhPP7SYIMYjr cKouMiQbpKQg== X-Google-Smtp-Source: AGHT+IGQo06LyiYb2yPkhFVc/YlDGIiH9UGxZr9nts6qclBkbLalJ9SAo0nSBth89cI+TYWnMZH2tg== X-Received: by 2002:a0d:e7c5:0:b0:771:dda2:f1fd with SMTP id 00721157ae682-77f6f26efe1mr65948307b3.18.1759404251961; Thu, 02 Oct 2025 04:24:11 -0700 (PDT) Received: from grind.dc1.ventanamicro.com ([2804:7f0:bcc0:b174:a9af:8146:7deb:fbf3]) by smtp.gmail.com with ESMTPSA id 00721157ae682-77f81c068f6sm7331627b3.5.2025.10.02.04.24.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Oct 2025 04:24:11 -0700 (PDT) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, alistair.francis@wdc.com, liwei1518@gmail.com, zhiwei_liu@linux.alibaba.com, palmer@dabbelt.com, richard.henderson@linaro.org, Daniel Henrique Barboza Subject: [PATCH 13/17] hw/riscv/trace: add format2 msg helper Date: Thu, 2 Oct 2025 08:23:31 -0300 Message-ID: <20251002112335.2374517-14-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251002112335.2374517-1-dbarboza@ventanamicro.com> References: <20251002112335.2374517-1-dbarboza@ventanamicro.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2607:f8b0:4864:20::1134; envelope-from=dbarboza@ventanamicro.com; helo=mail-yw1-x1134.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, SPF_HELO_NONE=0.001, T_SPF_TEMPERROR=0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-riscv@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-riscv-bounces+qemu-riscv=archiver.kernel.org@nongnu.org Sender: qemu-riscv-bounces+qemu-riscv=archiver.kernel.org@nongnu.org Before handling updiscon (uninferable PC discontinuity) cases add the encoded message we're going to use, format 2. Format 1 will be added when we add the branch map. There are design decisions worth documenting in this patch. For irreport, the e-trace-encap spec [1] in section 7.6. "Format 2 packets", says that we should make this bit !updiscon if we're either: "following a return because its address differs from the predicted return address at the top of the implicit_return return address stack, or the last retired before an exception, interrupt, privilege change or resync because it is necessary to report the current address stack depth or nested call count." We do not implement any form of call/return prediction in the encoder, and TCG will always retire a single insn per cycle. This means that we'll never set irreport, i.e. irreport will always be equal to updiscon. If this interpretation turns out to be wrong we'll revisit this helper. Likewise, irdepth is also not implemented since we'll always return a package where irreport == updiscon. The size of the field is arbitrarily set to '3' to avoid adding padding in the end of the msg to complete an extra byte. [1] https://github.com/riscv-non-isa/e-trace-encap/releases/tag/v1.0 Signed-off-by: Daniel Henrique Barboza --- hw/riscv/rv-trace-messages.c | 59 ++++++++++++++++++++++++++++++++++++ hw/riscv/rv-trace-messages.h | 2 ++ 2 files changed, 61 insertions(+) diff --git a/hw/riscv/rv-trace-messages.c b/hw/riscv/rv-trace-messages.c index 3e9466633d..3fa70ba81c 100644 --- a/hw/riscv/rv-trace-messages.c +++ b/hw/riscv/rv-trace-messages.c @@ -53,6 +53,17 @@ typedef struct RVTraceTrapPayload { } RVTraceTrapPayload; #define TRAP_PAYLOAD_SIZE_64BITS 18 +typedef struct RVTraceFormat2Payload { + uint8_t format:2; + uint32_t addressLow; + uint32_t addressHigh; + uint8_t notify:1; + uint8_t updiscon:1; + uint8_t irreport:1; + uint8_t irdepth:3; +} RVTraceFormat2Payload; +#define FORMAT2_PAYLOAD_SIZE_64BITS 9 + static void rv_etrace_write_bits(uint8_t *bytes, uint32_t bit_pos, uint32_t num_bits, uint32_t val) { @@ -186,3 +197,51 @@ size_t rv_etrace_gen_encoded_trap_msg(uint8_t *buf, uint64_t trap_addr, out: return HEADER_SIZE + header.length; } + +/* + * Note: irreport and irdepth is always == updiscon. + * + * return_stack_size_p + call_counter_size_p is hardcoded + * to 3 since we don't implement neither ATM. + */ +size_t rv_etrace_gen_encoded_format2_msg(uint8_t *buf, uint64_t addr, + bool notify, bool updiscon) +{ + RVTraceFormat2Payload payload = {.format = 0b11, + .notify = notify, + .updiscon = updiscon}; + RVTraceMessageHeader header = {.flow = 0, .extend = 0, + .length = FORMAT2_PAYLOAD_SIZE_64BITS}; + uint8_t bit_pos; + + payload.addressLow = extract64(addr, 0, 32); + payload.addressHigh = extract64(addr, 32, 32); + + payload.irreport = updiscon; + if (updiscon) { + payload.irdepth = 0b111; + } else { + payload.irdepth = 0; + } + + rv_etrace_write_header(buf, header); + bit_pos = 8; + + rv_etrace_write_bits(buf, bit_pos, 2, payload.format); + bit_pos += 2; + + rv_etrace_write_bits(buf, bit_pos, 32, payload.addressLow); + bit_pos += 32; + rv_etrace_write_bits(buf, bit_pos, 32, payload.addressHigh); + bit_pos += 32; + + rv_etrace_write_bits(buf, bit_pos, 1, payload.notify); + bit_pos += 1; + rv_etrace_write_bits(buf, bit_pos, 1, payload.updiscon); + bit_pos += 1; + rv_etrace_write_bits(buf, bit_pos, 1, payload.irreport); + bit_pos += 1; + rv_etrace_write_bits(buf, bit_pos, 3, payload.irdepth); + + return HEADER_SIZE + header.length; +} diff --git a/hw/riscv/rv-trace-messages.h b/hw/riscv/rv-trace-messages.h index f3e38b571f..50a4a0ef19 100644 --- a/hw/riscv/rv-trace-messages.h +++ b/hw/riscv/rv-trace-messages.h @@ -26,5 +26,7 @@ size_t rv_etrace_gen_encoded_trap_msg(uint8_t *buf, uint64_t trap_addr, uint8_t ecause, bool is_interrupt, uint64_t tval); +size_t rv_etrace_gen_encoded_format2_msg(uint8_t *buf, uint64_t addr, + bool notify, bool updiscon); #endif -- 2.51.0