From nobody Sun Jul 26 14:10:19 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=1781155901; cv=none; d=zohomail.com; s=zohoarc; b=GQLPIVPk1Kq8PdNlQ/NHLGAbGDpAlKAOGqcIrx+mCr4g8M87x3wgQcTgb/DhhM24bV9FCQ6u4H5Xc2doic71cUJL38aJdXRWvBbyi4PL3tl8Pzc/1LhFXQfWdAmKxltUNTPJhhHVD9zbug3PnnUYYh57tbKdlqRu/GK7YbydBNI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1781155901; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=2J2ABcJjVPtkiBhxpWjWNGoytTE2wjslipK0f9+9n/s=; b=LXYixMpaRjr8wD5yaLzFLkJ0fIyK0O5cvPOBkH6O3U7YPm48JJxDYgUQlDCulLBa51228I3rcx9VvJLMMAGC8O3hJCOn+PueB9SPM1db7uM0EXUVFfcRz0KNDODK3TAcMhkcYeMJ35uttmmhPcPHTH1SBh3M275yCYbol96mH10= 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 178115590100291.80717895207954; Wed, 10 Jun 2026 22:31:41 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wXXzR-00083D-BE; Thu, 11 Jun 2026 01:30:07 -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 1wXXzO-00082o-64 for qemu-devel@nongnu.org; Thu, 11 Jun 2026 01:30:02 -0400 Received: from mx0a-0031df01.pphosted.com ([205.220.168.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wXXzK-0000xK-KL for qemu-devel@nongnu.org; Thu, 11 Jun 2026 01:30:01 -0400 Received: from pps.filterd (m0279863.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 65B5GPuI3817102 for ; Thu, 11 Jun 2026 05:29:47 GMT Received: from mail-dy1-f199.google.com (mail-dy1-f199.google.com [74.125.82.199]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4eqe6usrrt-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Thu, 11 Jun 2026 05:29:47 +0000 (GMT) Received: by mail-dy1-f199.google.com with SMTP id 5a478bee46e88-304c652be4eso425875eec.1 for ; Wed, 10 Jun 2026 22:29:47 -0700 (PDT) Received: from hu-bcain-lv.qualcomm.com (Global_NAT1.qualcomm.com. [129.46.96.20]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-30806e8a402sm880475eec.17.2026.06.10.22.29.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jun 2026 22:29:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= 2J2ABcJjVPtkiBhxpWjWNGoytTE2wjslipK0f9+9n/s=; b=TCl46VaJTv1f549h Oz5MGjC+lhw5D2FH9IU/iYgFGzwM14HVsRCDSdh/Qw4geurDlPNyV9B4y9OJOaKi +zUOspEjr0pA7xmo9OYLEK4F4qJyBOVkIw+/LRiIfvKXBSbyAMiUv7BQvWybe5q/ 2ClHXSNdZZiNI2IrcJ9K0/NifSp/OqZtGvP0AcWxaKEXo+LK4+FFNwzQ8cucMr/a mXAPI2MIoIaD2hMbGQh7KGv5TlVLQnz6P4QID5Hqd3O9WjxoBKqFP0H+CCK1XBvt KXENRJ4eAPdVW21+JZtRlJMC7HTcZS7fvQVJuMAuNdQ14t73CX9ts6YkuFwpJKmU j0pPxQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1781155787; x=1781760587; 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=2J2ABcJjVPtkiBhxpWjWNGoytTE2wjslipK0f9+9n/s=; b=Vd0vVbxvF/c2GR7nCYlI7Ms78736/fWMgDmdMN9d9ggzEO3xzmS5WczRkO2/OChuhE PmjFBfZCuYipEa4FnakPgBJlIYJVJGQSS07MGlwuY8pAQB9NqWrOOU5iuDg/KZDjgztA Nc8FWly3lG4uJlFLV1fdLKhhRpo5TqbG6lkdUpvwNtVey6P6Yr5EWD18dyDMHuDc5VZH JzqpJQvshKxBSyrtRNHpbp9BjrzZFzvxmnSkChMxJmPGkizYAypi4gvkarr3jAescKuB WA/GyUGe6xZ6XTX1WsIJexAJXIcatSlBcXEQvsLrPWrc6D98HYSaYXB+B8sSjAply2Os ShRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781155787; x=1781760587; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=2J2ABcJjVPtkiBhxpWjWNGoytTE2wjslipK0f9+9n/s=; b=GZZo+5B0Ej1nxAh/+UZbACoAqZnwmIoellNchfej6ffrQs/mQDqgSXRV4LT66b5ctM 5q0+QSgFb/WMGDSZz+xdouwdk37UGAHN9qrAMwgSd9SaGgmKKfp9UFyjcwWe+rJV838f 1BP4cqlG137WRYgYQfCl1Uup8vuv9k/eRr/APc+LkBxAdMzGSJblf3Ml0IQn6UVgrvym XUdj81UH8ty7OtQLixThoiDnMzGI8l8EgiorbKA2i/PNsCD53eyE7dW/oeeaLV4SDHVc dD/+sXC8kzaf9m1HnvYF77nqSyO0PHoCfquqsN1xHXU6RnZxMsQXcTH6SA6xi0p++XXp 0TIg== X-Gm-Message-State: AOJu0Yw3qOizjDQ4QNDaABjHgrAn0sWQ0WPwfs/AhpeiTQJdZ4ymYjwA VnTHqLcWNVzul5Uby/T33ekBl2jxnh/FA//P4t0W4LT0BXpG5trHhQUDV1gNLxkBDBVYxITgW4W +eKLBIaaoUXri2+t/w1W3286/ueMQVEZvXXCjhzwu+OdOjtnO8VQ1ZSDzPPkcEpfihQ== X-Gm-Gg: Acq92OH3nQsE0G/Pv/MG2YKM/i/SCUlZI20RtZ05cgn+ENXxUS3eSrFh8wfOtByJta2 DvoilKGcl5/YS1oAj0On3bVLs/jATzVGYnU0depDg1rjJH4dpkvSToL3ng8qkClaqO+t0MUpuKs udNYlu/HSjU0773Huf0ovwAeue6tNY9UzOLqIjM7DBvITpEYGn6lN1bCGcw4i9KLA+MhF74fcdE i1a5T8/XNDiNQW3kZ+F0nO0+w9S4uav/FCIiv7r93YDdqsNzrJT922sCNW7gao2IBzdpfHbfl7a 96lv5bUb/wphtPUcUzUPn93cvvf2gLRMU8TvihYu1nEHbH8J4WQsesmZanRAuvaeciRjioLjM9d N1tKdokEWWqxpafa7yoL+O6SkKORlxbyHnB/CD9sH9edi/D1JH4tesghrdNg7wHTJOgruYEBHLC nNEy3p X-Received: by 2002:a05:7022:f99:b0:12d:b8e5:5e2 with SMTP id a92af1059eb24-13842ec3600mr630274c88.23.1781155786575; Wed, 10 Jun 2026 22:29:46 -0700 (PDT) X-Received: by 2002:a05:7022:f99:b0:12d:b8e5:5e2 with SMTP id a92af1059eb24-13842ec3600mr630241c88.23.1781155786007; Wed, 10 Jun 2026 22:29:46 -0700 (PDT) From: Brian Cain To: qemu-devel@nongnu.org Cc: brian.cain@oss.qualcomm.com, matheus.bernardino@oss.qualcomm.com, pierrick.bouvier@oss.qualcomm.com, ltaylorsimpson@gmail.com, philmd@mailo.org, philmd@oss.qualcomm.com, Brian Cain , Sid Manning Subject: [PATCH v8] target/hexagon: Add sreg_{read,write} helpers Date: Wed, 10 Jun 2026 22:28:49 -0700 Message-Id: <20260611052857.3911981-29-brian.cain@oss.qualcomm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260611052857.3911981-1-brian.cain@oss.qualcomm.com> References: <20260611052857.3911981-1-brian.cain@oss.qualcomm.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Authority-Analysis: v=2.4 cv=FJ8rAeos c=1 sm=1 tr=0 ts=6a2a47cb cx=c_pps a=cFYjgdjTJScbgFmBucgdfQ==:117 a=ouPCqIW2jiPt+lZRy3xVPw==:17 a=IkcTkHD0fZMA:10 a=FelO9ux0wxsA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=yOCtJkima9RkubShWh1s:22 a=COk6AnOGAAAA:8 a=pGLkceISAAAA:8 a=EUspDBNiAAAA:8 a=rqZXtLhFGwB6yMrbUaoA:9 a=QEXdDO2ut3YA:10 a=scEy_gLbYbu1JhEsrz4S:22 a=TjNXssC_j7lpFel5tvFf:22 X-Proofpoint-Spam-Info: AW1haW4tMjYwNjExMDA1MSBTYWx0ZWRfX31VDxzaVCbr3 FRIkuynnDHxUJh9jet1L142qqwv/Gj6ugbm8ksnIgtnuKEZL5Rp4DdRkjidzitw82Cf92IV262n 8JhiOdQ4PZRiBl2y9M26nOejZu1ihCg= X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNjExMDA1MSBTYWx0ZWRfX1tm9zCuUxnzn bBwtzpjY0EVQwY5AgtiPxF6/YYADR3Ktr+dFd5VSL0Ijgq6w1ltaxp6O580sxNwlVEzcxc+N7O9 S6WeWkQxVkXKiSnLwMQ/0FCcNq7s32VpnFoh1eu+FDo0kX5kXuEH1GXgiaqjglJjyD5/kfVCCQ+ g+lMt/EQmFnoo6S1iGWHkf4sfUdWO+5shJEJy74mPMCllp1VMuStRH6ps5pkV1ygirw8OIY+EPJ /jAU/peemGhXo6UTq5HeR2rPUP/NEHtAxsYsmM2+jf3LRppJPIW3785BDAIQiX29c830nVcH58t p8eD4vmnqUjKOm8d0o4Jjcz8nkdh+GBYXsuC1YNCUkAt50ZE5M3K7FprZjoXGu/vbgtLk1iMlHv fQxAjbls+rtzvA0xtNe3pOm+xTD2GJaWWrZ3dziPPN/YsUn/xtXJH1e2/S1NrppQ6NK0u56j79a BnMvc24VVzXHF6ju9nQ== X-Proofpoint-GUID: y2A0GP91KJmXbPShiIAhqz2I3mHH75H6 X-Proofpoint-ORIG-GUID: y2A0GP91KJmXbPShiIAhqz2I3mHH75H6 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.125,FMLib:17.12.100.49 definitions=2026-06-11_01,2026-06-09_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 clxscore=1015 adultscore=0 lowpriorityscore=0 bulkscore=0 impostorscore=0 priorityscore=1501 spamscore=0 phishscore=0 suspectscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606040000 definitions=main-2606110051 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.168.131; envelope-from=brian.cain@oss.qualcomm.com; helo=mx0a-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, RCVD_IN_MSPIKE_H2=0.001, 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: 1781155903054158500 From: Brian Cain Co-authored-by: Sid Manning Reviewed-by: Taylor Simpson Signed-off-by: Brian Cain --- target/hexagon/cpu.c | 1 - target/hexagon/cpu_helper.c | 354 ++++++++++++++++++++++++++++++++++++ target/hexagon/op_helper.c | 33 +++- 3 files changed, 384 insertions(+), 4 deletions(-) create mode 100644 target/hexagon/cpu_helper.c diff --git a/target/hexagon/cpu.c b/target/hexagon/cpu.c index 3059196bcac..a08083ea290 100644 --- a/target/hexagon/cpu.c +++ b/target/hexagon/cpu.c @@ -334,7 +334,6 @@ static void hexagon_cpu_realize(DeviceState *dev, Error= **errp) =20 qemu_init_vcpu(cs); cpu_reset(cs); - mcc->parent_realize(dev, errp); } =20 diff --git a/target/hexagon/cpu_helper.c b/target/hexagon/cpu_helper.c new file mode 100644 index 00000000000..a2b486f4bb5 --- /dev/null +++ b/target/hexagon/cpu_helper.c @@ -0,0 +1,354 @@ +/* + * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "cpu.h" +#include "cpu_helper.h" +#include "system/cpus.h" +#include "hw/core/boards.h" +#include "hw/hexagon/hexagon.h" +#include "hw/hexagon/hexagon_globalreg.h" +#include "hex_interrupts.h" +#include "hex_mmu.h" +#include "system/runstate.h" +#include "exec/cpu-interrupt.h" +#include "exec/target_page.h" +#include "accel/tcg/cpu-ldst.h" +#include "exec/cputlb.h" +#include "qemu/log.h" +#include "tcg/tcg-op.h" +#include "internal.h" +#include "macros.h" +#include "sys_macros.h" +#include "arch.h" + + +uint32_t hexagon_get_pmu_counter(CPUHexagonState *cur_env, int index) +{ + g_assert_not_reached(); +} + +uint64_t hexagon_get_sys_pcycle_count(CPUHexagonState *env) +{ + g_assert_not_reached(); +} + +uint32_t hexagon_get_sys_pcycle_count_high(CPUHexagonState *env) +{ + g_assert_not_reached(); +} + +uint32_t hexagon_get_sys_pcycle_count_low(CPUHexagonState *env) +{ + g_assert_not_reached(); +} + +void hexagon_set_sys_pcycle_count_high(CPUHexagonState *env, uint32_t val) +{ + g_assert_not_reached(); +} + +void hexagon_set_sys_pcycle_count_low(CPUHexagonState *env, uint32_t val) +{ + g_assert_not_reached(); +} + +void hexagon_set_sys_pcycle_count(CPUHexagonState *env, uint64_t val) +{ + g_assert_not_reached(); +} + +static void hexagon_resume_thread(CPUHexagonState *env) +{ + CPUState *cs =3D env_cpu(env); + clear_wait_mode(env); + /* + * The wait instruction keeps the PC pointing to itself + * so that it has an opportunity to check for interrupts. + * + * When we come out of wait mode, adjust the PC to the + * next executable instruction. + */ + env->gpr[HEX_REG_PC] =3D env->wait_next_pc; + cs =3D env_cpu(env); + ASSERT_DIRECT_TO_GUEST_UNSET(env, cs->exception_index); + cs->halted =3D false; + cs->exception_index =3D HEX_EVENT_NONE; + qemu_cpu_kick(cs); +} + +void hexagon_resume_threads(CPUHexagonState *current_env, uint32_t mask) +{ + CPUState *cs; + CPUHexagonState *env; + + g_assert(bql_locked()); + CPU_FOREACH(cs) { + env =3D cpu_env(cs); + g_assert(env->threadId < THREADS_MAX); + if ((mask & (0x1 << env->threadId))) { + if (get_exe_mode(env) =3D=3D HEX_EXE_MODE_WAIT) { + hexagon_resume_thread(env); + } + } + } +} + +void hexagon_modify_ssr(CPUHexagonState *env, uint32_t new, uint32_t old) +{ + bool old_EX, old_UM, old_GM, old_IE; + bool new_EX, new_UM, new_GM, new_IE; + uint8_t old_asid, new_asid; + + g_assert(bql_locked()); + + old_EX =3D GET_SSR_FIELD(SSR_EX, old); + old_UM =3D GET_SSR_FIELD(SSR_UM, old); + old_GM =3D GET_SSR_FIELD(SSR_GM, old); + old_IE =3D GET_SSR_FIELD(SSR_IE, old); + new_EX =3D GET_SSR_FIELD(SSR_EX, new); + new_UM =3D GET_SSR_FIELD(SSR_UM, new); + new_GM =3D GET_SSR_FIELD(SSR_GM, new); + new_IE =3D GET_SSR_FIELD(SSR_IE, new); + + if ((old_EX !=3D new_EX) || + (old_UM !=3D new_UM) || + (old_GM !=3D new_GM)) { + hex_mmu_mode_change(env); + } + + old_asid =3D GET_SSR_FIELD(SSR_ASID, old); + new_asid =3D GET_SSR_FIELD(SSR_ASID, new); + if (new_asid !=3D old_asid) { + CPUState *cs =3D env_cpu(env); + tlb_flush(cs); + } + + /* See if the interrupts have been enabled or we have exited EX mode */ + if ((new_IE && !old_IE) || + (!new_EX && old_EX)) { + hex_interrupt_update(env); + } +} + +void clear_wait_mode(CPUHexagonState *env) +{ + HexagonCPU *cpu; + uint32_t modectl, thread_wait_mask; + + g_assert(bql_locked()); + + cpu =3D env_archcpu(env); + if (cpu->globalregs) { + modectl =3D + hexagon_globalreg_read(cpu->globalregs, HEX_SREG_MODECTL, + env->threadId); + thread_wait_mask =3D GET_FIELD(MODECTL_W, modectl); + thread_wait_mask &=3D ~(0x1 << env->threadId); + SET_SYSTEM_FIELD(env, HEX_SREG_MODECTL, MODECTL_W, thread_wait_mas= k); + } +} + +void hexagon_ssr_set_cause(CPUHexagonState *env, uint32_t cause) +{ + uint32_t old, new; + + g_assert(bql_locked()); + + old =3D env->t_sreg[HEX_SREG_SSR]; + SET_SYSTEM_FIELD(env, HEX_SREG_SSR, SSR_EX, 1); + SET_SYSTEM_FIELD(env, HEX_SREG_SSR, SSR_CAUSE, cause); + new =3D env->t_sreg[HEX_SREG_SSR]; + + hexagon_modify_ssr(env, new, old); +} + + +int get_exe_mode(CPUHexagonState *env) +{ + HexagonCPU *cpu; + uint32_t modectl, thread_enabled_mask, thread_wait_mask; + uint32_t isdbst, debugmode; + bool E_bit, W_bit, D_bit; + + g_assert(bql_locked()); + + cpu =3D env_archcpu(env); + modectl =3D cpu->globalregs ? + hexagon_globalreg_read(cpu->globalregs, HEX_SREG_MODECTL, + env->threadId) : 0; + thread_enabled_mask =3D GET_FIELD(MODECTL_E, modectl); + E_bit =3D thread_enabled_mask & (0x1 << env->threadId); + thread_wait_mask =3D GET_FIELD(MODECTL_W, modectl); + W_bit =3D thread_wait_mask & (0x1 << env->threadId); + isdbst =3D cpu->globalregs ? + hexagon_globalreg_read(cpu->globalregs, HEX_SREG_ISDBST, + env->threadId) : 0; + debugmode =3D GET_FIELD(ISDBST_DEBUGMODE, isdbst); + D_bit =3D debugmode & (0x1 << env->threadId); + + if (!D_bit && !W_bit && !E_bit) { + return HEX_EXE_MODE_OFF; + } + if (!D_bit && !W_bit && E_bit) { + return HEX_EXE_MODE_RUN; + } + if (!D_bit && W_bit && E_bit) { + return HEX_EXE_MODE_WAIT; + } + if (D_bit && !W_bit && E_bit) { + return HEX_EXE_MODE_DEBUG; + } + g_assert_not_reached(); +} + +static uint32_t set_enable_mask(CPUHexagonState *env) +{ + HexagonCPU *cpu; + uint32_t modectl, thread_enabled_mask; + + g_assert(bql_locked()); + + cpu =3D env_archcpu(env); + if (!cpu->globalregs) { + return 0; + } + modectl =3D + hexagon_globalreg_read(cpu->globalregs, HEX_SREG_MODECTL, + env->threadId); + thread_enabled_mask =3D GET_FIELD(MODECTL_E, modectl); + thread_enabled_mask |=3D 0x1 << env->threadId; + SET_SYSTEM_FIELD(env, HEX_SREG_MODECTL, MODECTL_E, thread_enabled_mask= ); + return thread_enabled_mask; +} + +static uint32_t clear_enable_mask(CPUHexagonState *env) +{ + HexagonCPU *cpu; + uint32_t modectl, thread_enabled_mask; + + g_assert(bql_locked()); + + cpu =3D env_archcpu(env); + if (!cpu->globalregs) { + return 0; + } + modectl =3D + hexagon_globalreg_read(cpu->globalregs, HEX_SREG_MODECTL, + env->threadId); + thread_enabled_mask =3D GET_FIELD(MODECTL_E, modectl); + thread_enabled_mask &=3D ~(0x1 << env->threadId); + SET_SYSTEM_FIELD(env, HEX_SREG_MODECTL, MODECTL_E, thread_enabled_mask= ); + return thread_enabled_mask; +} +static void do_start_thread(CPUState *cs, run_on_cpu_data tbd) +{ + CPUHexagonState *env; + + BQL_LOCK_GUARD(); + + env =3D cpu_env(cs); + + hexagon_cpu_soft_reset(env); + + set_enable_mask(env); + + cs->halted =3D 0; + cs->exception_index =3D HEX_EVENT_NONE; + cpu_resume(cs); +} + +void hexagon_start_threads(CPUHexagonState *current_env, uint32_t mask) +{ + CPUState *cs; + CPU_FOREACH(cs) { + CPUHexagonState *env =3D cpu_env(cs); + if (!(mask & (0x1 << env->threadId))) { + continue; + } + + if (current_env->threadId !=3D env->threadId) { + async_safe_run_on_cpu(cs, do_start_thread, RUN_ON_CPU_NULL); + } + } +} + +/* + * When we have all threads stopped, the return + * value to the shell is register 2 from thread 0. + */ +static uint32_t get_thread0_r2(void) +{ + CPUState *cs; + CPU_FOREACH(cs) { + CPUHexagonState *thread =3D cpu_env(cs); + if (thread->threadId =3D=3D 0) { + return thread->gpr[2]; + } + } + g_assert_not_reached(); +} + +void hexagon_stop_thread(CPUHexagonState *env) +{ + uint32_t thread_enabled_mask; + CPUState *cs; + + BQL_LOCK_GUARD(); + + thread_enabled_mask =3D clear_enable_mask(env); + cs =3D env_cpu(env); + cpu_interrupt(cs, CPU_INTERRUPT_HALT); + if (!thread_enabled_mask) { + /* All threads are stopped, request shutdown */ + qemu_system_shutdown_request_with_code( + SHUTDOWN_CAUSE_GUEST_SHUTDOWN, get_thread0_r2()); + } +} + +static int sys_in_monitor_mode_ssr(uint32_t ssr) +{ + if ((GET_SSR_FIELD(SSR_EX, ssr) !=3D 0) || + ((GET_SSR_FIELD(SSR_EX, ssr) =3D=3D 0) && + (GET_SSR_FIELD(SSR_UM, ssr) =3D=3D 0))) { + return 1; + } + return 0; +} + +static int sys_in_guest_mode_ssr(uint32_t ssr) +{ + if ((GET_SSR_FIELD(SSR_EX, ssr) =3D=3D 0) && + (GET_SSR_FIELD(SSR_UM, ssr) !=3D 0) && + (GET_SSR_FIELD(SSR_GM, ssr) !=3D 0)) { + return 1; + } + return 0; +} + +static int sys_in_user_mode_ssr(uint32_t ssr) +{ + if ((GET_SSR_FIELD(SSR_EX, ssr) =3D=3D 0) && + (GET_SSR_FIELD(SSR_UM, ssr) !=3D 0) && + (GET_SSR_FIELD(SSR_GM, ssr) =3D=3D 0)) { + return 1; + } + return 0; +} + +int get_cpu_mode(CPUHexagonState *env) +{ + uint32_t ssr =3D env->t_sreg[HEX_SREG_SSR]; + + if (sys_in_monitor_mode_ssr(ssr)) { + return HEX_CPU_MODE_MONITOR; + } else if (sys_in_guest_mode_ssr(ssr)) { + return HEX_CPU_MODE_GUEST; + } else if (sys_in_user_mode_ssr(ssr)) { + return HEX_CPU_MODE_USER; + } + return HEX_CPU_MODE_MONITOR; +} diff --git a/target/hexagon/op_helper.c b/target/hexagon/op_helper.c index 82d016196df..706cb0a5d9f 100644 --- a/target/hexagon/op_helper.c +++ b/target/hexagon/op_helper.c @@ -19,6 +19,7 @@ #include "qemu/log.h" #include "accel/tcg/cpu-ldst.h" #include "accel/tcg/probe.h" +#include "qemu/main-loop.h" #include "cpu.h" #include "exec/helper-proto.h" #include "fpu/softfloat.h" @@ -1451,17 +1452,43 @@ void HELPER(setimask)(CPUHexagonState *env, uint32_= t tid, uint32_t imask) =20 void HELPER(sreg_write_masked)(CPUHexagonState *env, uint32_t reg, uint32_= t val) { - g_assert_not_reached(); + BQL_LOCK_GUARD(); + if (reg < HEX_SREG_GLB_START) { + env->t_sreg[reg] =3D val; + } else { + HexagonCPU *cpu =3D env_archcpu(env); + if (cpu->globalregs) { + hexagon_globalreg_write_masked(cpu->globalregs, reg, val); + } + } +} + +static inline QEMU_ALWAYS_INLINE uint32_t sreg_read(CPUHexagonState *env, + uint32_t reg) +{ + HexagonCPU *cpu; + + g_assert(bql_locked()); + if (reg < HEX_SREG_GLB_START) { + return env->t_sreg[reg]; + } + cpu =3D env_archcpu(env); + return cpu->globalregs ? + hexagon_globalreg_read(cpu->globalregs, reg, env->threadId) : 0; } =20 uint32_t HELPER(sreg_read)(CPUHexagonState *env, uint32_t reg) { - g_assert_not_reached(); + BQL_LOCK_GUARD(); + return sreg_read(env, reg); } =20 uint64_t HELPER(sreg_read_pair)(CPUHexagonState *env, uint32_t reg) { - g_assert_not_reached(); + BQL_LOCK_GUARD(); + + return deposit64((uint64_t) sreg_read(env, reg), 32, 32, + sreg_read(env, reg + 1)); } =20 uint32_t HELPER(greg_read)(CPUHexagonState *env, uint32_t reg) --=20 2.34.1