From patchwork Tue Jul 12 20:53:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 589802 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5817:0:0:0:0 with SMTP id j23csp675364max; Tue, 12 Jul 2022 13:58:51 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uSYAq72Jo2By/QmPa6bOJle58R3gxZwrmHaXD/wnPdeEurSZHYW3S0D8vWJ9mZRbL6VJwc X-Received: by 2002:a05:622a:24e:b0:31e:ba11:185b with SMTP id c14-20020a05622a024e00b0031eba11185bmr7322042qtx.595.1657659531734; Tue, 12 Jul 2022 13:58:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657659531; cv=none; d=google.com; s=arc-20160816; b=Tlm5/ZJwIkMTX1/oh3dktEHJK0zmUoQS6N+DrWrYfOH6EzlftB1oYVG/w0vkXxqMuL l2egPg7x6N0j1S/AOIDyuPumd7BO74aAl15lQdrRoBk7EW+rHdEUIDQwfKvxkrDbUCNP iRcVFohe8e93fMR9UL3DE/WnpfAp7EvMTS4AS+VvclbTDABpxSI1EOqyeKF1uhe0cgQe CDyErZTKZK969GZ7FVoyXzMMFSBI+UW7652GjEPxDBqyynp6kpDneUHI/4bNeKrnu92H HeDk7Ic9I5nn+icvJfZcdVZEmGpo2PSErkItDFTUHAtJNJv3JyGhEz48vtcs0paicAaZ b5HA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=from:reply-to:sender:errors-to: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:cc:to:dkim-signature; bh=n9WhOhgr7P/CViF7JEjJoV08CGw0IzkNTtlxYzXL+oY=; b=0GF2UJNUupNe9ll4Pe/yDDZIXZl5c23yFFK2Au4ltnhV87w4dx7ArbW+3tx4CyMVJV hKtCNIFNYrvk/EHYkrjNnJ+wY35zBioOxsML2q2TCT3zvLYZ8AL1Z1Z0Lbm8HATFpUNs 6Bc9+UT8dgxPAdHAFH7WytKkjCnrOaALDVBuXrzMe5Y7lUrX8pJ0UpEUFdVRDqjtmBbh qkYhKCXENeLXM19Vj7scX5FGqWbfMcUSHOcZadvmdnJ7PsoTG7TviyB6wb0C7gw/QM3j A2Pagt/Es5PD5N3JlC+EDNqzjats16BDGOBTh2+0yQ3juXx70Ysfx3PLqzls5Xq8EP1i gIBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20210112 header.b=XjvwqA+v; 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=nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id v21-20020a05620a0f1500b006b57959fea5si6353504qkl.650.2022.07.12.13.58.51 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 12 Jul 2022 13:58:51 -0700 (PDT) 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=fail header.i=@gmail.com header.s=20210112 header.b=XjvwqA+v; 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=nongnu.org Received: from localhost ([::1]:45268 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oBMy3-00037Q-9P for patch@linaro.org; Tue, 12 Jul 2022 16:58:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57946) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oBMth-00060w-K3 for qemu-devel@nongnu.org; Tue, 12 Jul 2022 16:54:21 -0400 Received: from mail-wm1-x32a.google.com ([2a00:1450:4864:20::32a]:54935) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oBMtd-0007El-Vg for qemu-devel@nongnu.org; Tue, 12 Jul 2022 16:54:19 -0400 Received: by mail-wm1-x32a.google.com with SMTP id n185so5402488wmn.4 for ; Tue, 12 Jul 2022 13:54:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=n9WhOhgr7P/CViF7JEjJoV08CGw0IzkNTtlxYzXL+oY=; b=XjvwqA+vRPcQbvZLC6tR4L3UqfSXl4KtVN2tbXKmSTWGpQpv8OrnQa4i/KWtUd5knb BTC+bQU+aufhep/Kyia/ZulZCgmprEGPsHkJa5FZzLYgIxeyNmGcSd4rnxxlqdH55HKx 2k+b+b8ew3SsSSDDMjrb4b3y0nyhKRi3Sew5AgGrJYOVOYwLjNjEhUAiHKbHsemgvATw D/iQuc6DOMxN3lXUKr9UnPPZBdghWfSy05iUKnpL5bQSxkYLjj2fVxkDyVqXRdyMluV5 ZPDMxvfUO0mKYvQbEEeWb4UZV9XWLayGChNCK0Fx2ukRZS+Zp3mbs4JN5ASTYh4ykkm/ uKUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=n9WhOhgr7P/CViF7JEjJoV08CGw0IzkNTtlxYzXL+oY=; b=N0Ymy9IenWyz+XYbVXfHC3mt5gkhchnA/omdIZikDhduxIJdeIzLXQB8Svh8n5HR9w CD5iQO57/D+AFaHEKiDV2ymxlmrFyzW744zTD38dA9tlnNai6Yo9ubQhITS9pNBKfYeI 1aCqHFMKy8+KNtWcSNk+PnovwhJz8e7Xage/01vxcA1Jr7+WYEcCCO2CBduD24KNsyqT 4wQJ/rhtRhDFGYBv+dGYYAmaCUb/E14ijlOovA1HGDURnxPamJ6BiZWEssKmYTPgOKDo g3eDhUYj67f+2193Q6Qq/kQnZp/IWDXd9qvi2GkKvNpNbCQUwd+DWCJoOIIUJ5WsTXQR d0Kw== X-Gm-Message-State: AJIora+PQDfgm/71b9JCb61FB3NltBAZCMUOrwcW6rIxhrcsUerqqBD8 8aw0Zs9aueu069l5LaPnZ9Ks4vJW8R6VO4qT X-Received: by 2002:a05:600c:4fd0:b0:3a2:b57b:2200 with SMTP id o16-20020a05600c4fd000b003a2b57b2200mr6047815wmq.197.1657659256362; Tue, 12 Jul 2022 13:54:16 -0700 (PDT) Received: from localhost.localdomain ([185.126.107.38]) by smtp.gmail.com with ESMTPSA id 3-20020a05600c024300b003a1a02c6d7bsm18938wmj.35.2022.07.12.13.54.15 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 12 Jul 2022 13:54:15 -0700 (PDT) To: qemu-devel@nongnu.org Cc: Aurelien Jarno , Jiaxun Yang , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= , =?utf-8?q?Alex_Benn=C3=A9e?= , Aleksandar Rikalo , Richard Henderson Subject: [PULL 05/12] target/mips: Create report_fault for semihosting Date: Tue, 12 Jul 2022 22:53:40 +0200 Message-Id: <20220712205347.58372-6-f4bug@amsat.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220712205347.58372-1-f4bug@amsat.org> References: <20220712205347.58372-1-f4bug@amsat.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32a; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wm1-x32a.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Reply-to: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Original-From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= via From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= From: Richard Henderson The UHI specification does not have an EFAULT value, and further specifies that "undefined UHI operations should not return control to the target". So, log the error and abort. Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé Message-Id: <20220628111701.677216-2-richard.henderson@linaro.org> Signed-off-by: Philippe Mathieu-Daudé --- target/mips/tcg/sysemu/mips-semi.c | 33 ++++++++++++++---------------- 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/target/mips/tcg/sysemu/mips-semi.c b/target/mips/tcg/sysemu/mips-semi.c index 67c35fe7f9..153df1fa15 100644 --- a/target/mips/tcg/sysemu/mips-semi.c +++ b/target/mips/tcg/sysemu/mips-semi.c @@ -114,6 +114,13 @@ enum UHIErrno { UHI_EXDEV = 18, }; +static void report_fault(CPUMIPSState *env) +{ + int op = env->active_tc.gpr[25]; + error_report("Fault during UHI operation %d", op); + abort(); +} + static int errno_mips(int host_errno) { /* Errno values taken from asm-mips/errno.h */ @@ -136,8 +143,7 @@ static int copy_stat_to_target(CPUMIPSState *env, const struct stat *src, hwaddr len = sizeof(struct UHIStat); UHIStat *dst = lock_user(VERIFY_WRITE, vaddr, len, 0); if (!dst) { - errno = EFAULT; - return -1; + report_fault(env); } dst->uhi_st_dev = tswap16(src->st_dev); @@ -188,8 +194,7 @@ static int write_to_file(CPUMIPSState *env, target_ulong fd, int num_of_bytes; void *dst = lock_user(VERIFY_READ, vaddr, len, 1); if (!dst) { - errno = EFAULT; - return -1; + report_fault(env); } num_of_bytes = write(fd, dst, len); @@ -204,8 +209,7 @@ static int read_from_file(CPUMIPSState *env, target_ulong fd, int num_of_bytes; void *dst = lock_user(VERIFY_WRITE, vaddr, len, 0); if (!dst) { - errno = EFAULT; - return -1; + report_fault(env); } num_of_bytes = read(fd, dst, len); @@ -220,7 +224,7 @@ static int copy_argn_to_target(CPUMIPSState *env, int arg_num, int strsize = strlen(semihosting_get_arg(arg_num)) + 1; char *dst = lock_user(VERIFY_WRITE, vaddr, strsize, 0); if (!dst) { - return -1; + report_fault(env); } strcpy(dst, semihosting_get_arg(arg_num)); @@ -233,9 +237,7 @@ static int copy_argn_to_target(CPUMIPSState *env, int arg_num, do { \ p = lock_user_string(addr); \ if (!p) { \ - gpr[2] = -1; \ - gpr[3] = EFAULT; \ - return; \ + report_fault(env); \ } \ } while (0) @@ -243,16 +245,11 @@ static int copy_argn_to_target(CPUMIPSState *env, int arg_num, do { \ p = lock_user_string(addr); \ if (!p) { \ - gpr[2] = -1; \ - gpr[3] = EFAULT; \ - return; \ + report_fault(env); \ } \ p2 = lock_user_string(addr2); \ if (!p2) { \ - unlock_user(p, addr, 0); \ - gpr[2] = -1; \ - gpr[3] = EFAULT; \ - return; \ + report_fault(env); \ } \ } while (0) @@ -375,7 +372,7 @@ void mips_semihosting(CPUMIPSState *env) break; #endif default: - fprintf(stderr, "Unknown UHI operation %d\n", op); + error_report("Unknown UHI operation %d", op); abort(); } return; From patchwork Tue Jul 12 20:53:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 589800 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5817:0:0:0:0 with SMTP id j23csp673619max; Tue, 12 Jul 2022 13:56:08 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vyW6jBIa+VP2nmZTFTpChLpUhY7+hJI41UbJRaKHNDF2UswNxIk55gcS6Bl2Re1vw+SH+C X-Received: by 2002:a05:6214:aca:b0:473:247c:6fde with SMTP id g10-20020a0562140aca00b00473247c6fdemr153613qvi.66.1657659368590; Tue, 12 Jul 2022 13:56:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657659368; cv=none; d=google.com; s=arc-20160816; b=ZBRaCWPnUI9HPsNjxdNYnU3tyRt4t6oYHMiAP2HCo/6KuJEq7pSnOisgz01jKR1vo+ XZiq+aWlOmSyN8fksTMD4sxP6PETMZw5c2DiRmd+4111OfU/pRAW/E/rFmGdykgIWU8e 8AZKlG1SBdOf1FvcfZumYYIdU6Al4N66zkk2RoXmGvh8Wd4DYiWuU3vck9FxSrufzO5V x4qEqFmOjtJgCmwjs5wPKkkRzmlfBSUqHx4KralFu084TFn7O/+JlTxEz9wouy4+Zyhz VAE9jwV4Sw12ecZaczCo8GiJwljWnuZXEjn7JIEiEas53/ZH0teFrNa3fmdt6YxYe4Sc 3flA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=from:reply-to:sender:errors-to: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:cc:to:dkim-signature; bh=wcyJ02wlNyzEg57m9Ur9GMAopAxBv6GVRoR8NlG5s+8=; b=ec8Zz2cemeAiUNzsyjBD2Gi6PMPxOEmhz2BoSrtC2PpwL0JBtp/wpOqs6XF0bBeiVp LSE5+mjiDqhXValKUw3Mg/ODFBKBBIj7CC94+gczJy2rKwIYOCC8SlNlYILpxVZUDXcz E1Ym315FohLStvITtCKErGBnlWC13YdpD51xLwKSMpwIcBOJF7eHCjMwWo+VGVhaSS+c EFtSnXU9KKZoIOR/EbwGYsmc4ze1dtTSpKg55ceGpT0NI1jBIZBY++zGip7LMQUMYNGN cDERoexQYP4X7VvpRwCJPDcERyYgbGu1mhXcDu0Jv5FQAJL3pJLIU7XcLcPcHUVffE0S w7fA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20210112 header.b=l3AlmzQN; 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=nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id f23-20020a05622a1a1700b0031d4757998dsi9176929qtb.299.2022.07.12.13.56.08 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 12 Jul 2022 13:56:08 -0700 (PDT) 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=fail header.i=@gmail.com header.s=20210112 header.b=l3AlmzQN; 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=nongnu.org Received: from localhost ([::1]:37340 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oBMvQ-00067O-74 for patch@linaro.org; Tue, 12 Jul 2022 16:56:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57968) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oBMtp-00065Z-DE for qemu-devel@nongnu.org; Tue, 12 Jul 2022 16:54:29 -0400 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]:44556) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oBMtj-0007FT-UH for qemu-devel@nongnu.org; Tue, 12 Jul 2022 16:54:26 -0400 Received: by mail-wm1-x334.google.com with SMTP id be14-20020a05600c1e8e00b003a04a458c54so89763wmb.3 for ; Tue, 12 Jul 2022 13:54:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=wcyJ02wlNyzEg57m9Ur9GMAopAxBv6GVRoR8NlG5s+8=; b=l3AlmzQNo2IvbDgrjZIM0XbSdZJYXe6f6WXMlkiDdvFML65QeUazNx6XgX6cAcpGnZ KNIF7mKszl68ZM22Socu7Lx5/OmKFIzTjBu/5gymO1ilmgUZsltC0jOTWGfkY1PGRiec xmrjmHhannmKsxJi/Eq/KRj5hqsZIaO3yikDuoPHtWrHVqb+bYnJ/AgO9FLnoksRnWNN I1yY8FevT5ctWx21v6kcPrcPPx7SoH5ATgnWNQ745UA5CXhtLtKGhjQrvnB4vSPduJXt DmGs/B/v35nxr+hIg7JzTS4nh8NLRNHhjavnsh0RPVTLb7nWD5T5BZqzn8HwU4nWPBPP 8nIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=wcyJ02wlNyzEg57m9Ur9GMAopAxBv6GVRoR8NlG5s+8=; b=JZSbkvNeojfeiqPdfPxamDQB8cPxmmSsN0YIaHFj5WeRiEm0kCys2bDRd6fyF96B1f XCpzliZwzt83Zslpsd8KR1N9Vm0Wafwh+M5HMniZ/ujSLn6keAPVydCJ7ru9VBoR63E/ w01Zsi8cyYqkTvq8XjvTUyYgo54QEOo4vdQ7whf2Te3imxvPK9+01JLeoZv54R9BgbN7 o7Lc4VjVhepwbLNM7o2s1XNWZlf9HGh2T59hff0/A4sXZrHSX9xiIJeRPmJyBmmG4bnj /1LT/tRIJReRhI4Yn0WuK+KerGkD5hZHAmXR7EfHyFDRJm8bSQfsOd02MZdwsEyIDNOl Yhdg== X-Gm-Message-State: AJIora9+5IrYsarMDo4tLPtkdoL6+FyeFMe2zyhi58oGFLYFiiGuvM/C a67eQntKc6f9GPU4RguPzmdOScsdHp0WGTE4 X-Received: by 2002:a05:600c:1992:b0:3a1:9252:c373 with SMTP id t18-20020a05600c199200b003a19252c373mr5848056wmq.140.1657659261978; Tue, 12 Jul 2022 13:54:21 -0700 (PDT) Received: from localhost.localdomain ([185.126.107.38]) by smtp.gmail.com with ESMTPSA id bj22-20020a0560001e1600b0021d60994b0asm9492207wrb.100.2022.07.12.13.54.20 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 12 Jul 2022 13:54:21 -0700 (PDT) To: qemu-devel@nongnu.org Cc: Aurelien Jarno , Jiaxun Yang , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= , =?utf-8?q?Alex_Benn=C3=A9e?= , Aleksandar Rikalo , Richard Henderson Subject: [PULL 06/12] target/mips: Drop link syscall from semihosting Date: Tue, 12 Jul 2022 22:53:41 +0200 Message-Id: <20220712205347.58372-7-f4bug@amsat.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220712205347.58372-1-f4bug@amsat.org> References: <20220712205347.58372-1-f4bug@amsat.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::334; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wm1-x334.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Reply-to: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Original-From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= via From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= From: Richard Henderson We don't implement it with _WIN32 hosts, and the syscall is missing from the gdb remote file i/o interface. Since we can't implement it universally, drop it. Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé Message-Id: <20220628111701.677216-3-richard.henderson@linaro.org> Signed-off-by: Philippe Mathieu-Daudé --- target/mips/tcg/sysemu/mips-semi.c | 9 --------- 1 file changed, 9 deletions(-) diff --git a/target/mips/tcg/sysemu/mips-semi.c b/target/mips/tcg/sysemu/mips-semi.c index 153df1fa15..93c9d3d0b3 100644 --- a/target/mips/tcg/sysemu/mips-semi.c +++ b/target/mips/tcg/sysemu/mips-semi.c @@ -362,15 +362,6 @@ void mips_semihosting(CPUMIPSState *env) FREE_TARGET_STRING(p, gpr[4]); abort(); break; -#ifndef _WIN32 - case UHI_link: - GET_TARGET_STRINGS_2(p, gpr[4], p2, gpr[5]); - gpr[2] = link(p, p2); - gpr[3] = errno_mips(errno); - FREE_TARGET_STRING(p2, gpr[5]); - FREE_TARGET_STRING(p, gpr[4]); - break; -#endif default: error_report("Unknown UHI operation %d", op); abort(); From patchwork Tue Jul 12 20:53:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 589805 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5817:0:0:0:0 with SMTP id j23csp681148max; Tue, 12 Jul 2022 14:06:02 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tdpRAXq4IT0b186dqQ68BfXNWZQJzhF0fQzH/AWnGo9HjJICymE4cAFEBmOtnYWKjMpJu/ X-Received: by 2002:a05:620a:d5b:b0:6b5:660b:2939 with SMTP id o27-20020a05620a0d5b00b006b5660b2939mr174954qkl.30.1657659962184; Tue, 12 Jul 2022 14:06:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657659962; cv=none; d=google.com; s=arc-20160816; b=I6h0QQ32na9tgM3PBXtx20I2LroxWYL2wWDjkkETMHiFZhLiQ+16dHE91phDoiNZon y7xA4jG4yPWoHJ8HAx4WDS3GCpIyRjyFSaPkZ2Ds6d6xB4Xe+3AKzC3SEERlOsrejaG5 HLbjdH233SZUiqYDzflST3gKy6Qsg2YFnpu6Szkk/JHCmLq5Hzfi9I7NALBKTnwPF8Ac WiiMmznmQ1v9Zg7hqMi8c4JStUtKmytjI/01KyyblVsNHWc4D1VRWLDIsf3fC8k8V0jG I8yEdvhLJ2T1+x+6xmCfCBTSrw3AnGAIhr2X+K5as32uy9FU4KHYyVRnHEOSvx3k/Nxd 6J3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=from:reply-to:sender:errors-to: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:cc:to:dkim-signature; bh=W+mE8FJOfqJaEWdE8/Viw//HmXoDfyVVL8rYwJv5DUM=; b=UumHTs454hK8hvuXvYnT+0Qfi9L0gq6m9gt1PoBA6Ll56854HOObfsphDghiLPFu6t O5wNEjmwjXapyLFpiyNk5ql2gObdfq9iRUGSriM26wMmGPTEqauKKtGZ/zbqoSSmSPG9 MvoAsnIv/yrnq2E2Yy7MC0IEnzrlpT4NABrsI7sFTrWnhHvtUXpSCwnGw8fuQCCVaWY2 JTB+6C1sHk+fD/Z8QtubjaR8HV7wuKOs2YsCbgHfRfS2/tq6Lp4KJy8vlsXXQTEbkjVr wTTa18HRK/xA8GCo8jmvs2RMiJanXYIbTn/eSButhWY9XaXmMdWsY8bA2/DTzY8ePHRo //nw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20210112 header.b=QOtcMkbb; 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=nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id br9-20020a05620a460900b006b5a9e5e380si1292797qkb.150.2022.07.12.14.06.02 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 12 Jul 2022 14:06:02 -0700 (PDT) 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=fail header.i=@gmail.com header.s=20210112 header.b=QOtcMkbb; 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=nongnu.org Received: from localhost ([::1]:58096 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oBN4z-0003T5-O1 for patch@linaro.org; Tue, 12 Jul 2022 17:06:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58006) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oBMtt-00066g-3H for qemu-devel@nongnu.org; Tue, 12 Jul 2022 16:54:33 -0400 Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]:40874) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oBMtp-0007Fc-AN for qemu-devel@nongnu.org; Tue, 12 Jul 2022 16:54:32 -0400 Received: by mail-wm1-x32f.google.com with SMTP id o19-20020a05600c511300b003a2de48b4bbso82474wms.5 for ; Tue, 12 Jul 2022 13:54:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=W+mE8FJOfqJaEWdE8/Viw//HmXoDfyVVL8rYwJv5DUM=; b=QOtcMkbbjbBCWX8wQERERh0PdhE/rWLjqvm+NVxTVi2kbS7mN8ttZfOERLzISi8OiS 4qgzIUKGqdxXqwTrF8uwuqfcgxk8wOe9W8R6AqawJEcAPpfM/VRxl0irCvcKbwNLEvPi 2T5qAI93tM8jIzBB6DjnDv3FswzsmJ1pAg+Y/u5hnA9VlHlNWJ6IlEaFuJclzzyDZbhM ENSk8bG1HL9DywL2HBqXFYda7wOrpFsRmGTS9wSiOUFItB+0f9vxjz5oONTNlvs7EF4S d3JupEPvXI2TagQeo/OnzVzeoQVKxtLLc5Pau8McsapqssZ1LoUUIGQS7O+RqF02EDjO sX1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=W+mE8FJOfqJaEWdE8/Viw//HmXoDfyVVL8rYwJv5DUM=; b=aGB9RtDTkBBMPUyPpy0CHCSucXSlYwsmn+ip6d6NlPGoX5qNvCk4+1G3yYC/I5WamR 7dQMIwHCgJI1evKrjjjr2JnuEp1k4V2EAw/VBvwcYwSbF2KJbk0vrZK2BLmKWN/fO4wF TN75OPgjPTBE1aqncWIUiMeUq0mK0oD1CvRMyWHbtwwOMRF8Aji1nBBaFjjzhZtVHt6Z z/n4O81PdeCXMEeT/Tuj90KUca58YzPD5QzUdCxwgNVhsqVbuqKgcADfy5sVv3kmdv5r dI4OMku/vSzOOZTudH6cEUtqg4DEDfHjFERdDjhTj515PlFFgluowiLI8s+uucN3NxnG XweA== X-Gm-Message-State: AJIora9sAhkdbHawpyREEgEdDem6FaCsIgDqzTzuotRfOkX/SGO26W5A DrAQbGWhRg3HvWvPcZuLbfB7ikA9avwIpRsK X-Received: by 2002:a05:600c:4ba9:b0:3a2:daf6:44f6 with SMTP id e41-20020a05600c4ba900b003a2daf644f6mr5957529wmp.52.1657659267607; Tue, 12 Jul 2022 13:54:27 -0700 (PDT) Received: from localhost.localdomain ([185.126.107.38]) by smtp.gmail.com with ESMTPSA id o38-20020a05600c512600b0039c5642e430sm63121wms.20.2022.07.12.13.54.26 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 12 Jul 2022 13:54:27 -0700 (PDT) To: qemu-devel@nongnu.org Cc: Aurelien Jarno , Jiaxun Yang , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= , =?utf-8?q?Alex_Benn=C3=A9e?= , Aleksandar Rikalo , Richard Henderson Subject: [PULL 07/12] target/mips: Use semihosting/syscalls.h Date: Tue, 12 Jul 2022 22:53:42 +0200 Message-Id: <20220712205347.58372-8-f4bug@amsat.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220712205347.58372-1-f4bug@amsat.org> References: <20220712205347.58372-1-f4bug@amsat.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32f; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wm1-x32f.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Reply-to: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Original-From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= via From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= From: Richard Henderson This separates guest file descriptors from host file descriptors, and utilizes shared infrastructure for integration with gdbstub. Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé Message-Id: <20220628111701.677216-4-richard.henderson@linaro.org> Signed-off-by: Philippe Mathieu-Daudé --- target/mips/tcg/sysemu/mips-semi.c | 219 +++++++++++++---------------- 1 file changed, 95 insertions(+), 124 deletions(-) diff --git a/target/mips/tcg/sysemu/mips-semi.c b/target/mips/tcg/sysemu/mips-semi.c index 93c9d3d0b3..5b78cf21a7 100644 --- a/target/mips/tcg/sysemu/mips-semi.c +++ b/target/mips/tcg/sysemu/mips-semi.c @@ -20,9 +20,11 @@ #include "qemu/osdep.h" #include "cpu.h" #include "qemu/log.h" +#include "exec/gdbstub.h" #include "semihosting/softmmu-uaccess.h" #include "semihosting/semihost.h" #include "semihosting/console.h" +#include "semihosting/syscalls.h" #include "internal.h" typedef enum UHIOp { @@ -121,101 +123,79 @@ static void report_fault(CPUMIPSState *env) abort(); } -static int errno_mips(int host_errno) +static void uhi_cb(CPUState *cs, uint64_t ret, int err) { - /* Errno values taken from asm-mips/errno.h */ - switch (host_errno) { - case 0: return 0; - case ENAMETOOLONG: return 78; -#ifdef EOVERFLOW - case EOVERFLOW: return 79; -#endif -#ifdef ELOOP - case ELOOP: return 90; -#endif - default: return EINVAL; - } -} + CPUMIPSState *env = cs->env_ptr; -static int copy_stat_to_target(CPUMIPSState *env, const struct stat *src, - target_ulong vaddr) -{ - hwaddr len = sizeof(struct UHIStat); - UHIStat *dst = lock_user(VERIFY_WRITE, vaddr, len, 0); - if (!dst) { +#define E(N) case E##N: err = UHI_E##N; break + + switch (err) { + case 0: + break; + E(PERM); + E(NOENT); + E(INTR); + E(BADF); + E(BUSY); + E(EXIST); + E(NOTDIR); + E(ISDIR); + E(INVAL); + E(NFILE); + E(MFILE); + E(FBIG); + E(NOSPC); + E(SPIPE); + E(ROFS); + E(NAMETOOLONG); + default: + err = UHI_EINVAL; + break; + case EFAULT: report_fault(env); } - dst->uhi_st_dev = tswap16(src->st_dev); - dst->uhi_st_ino = tswap16(src->st_ino); - dst->uhi_st_mode = tswap32(src->st_mode); - dst->uhi_st_nlink = tswap16(src->st_nlink); - dst->uhi_st_uid = tswap16(src->st_uid); - dst->uhi_st_gid = tswap16(src->st_gid); - dst->uhi_st_rdev = tswap16(src->st_rdev); - dst->uhi_st_size = tswap64(src->st_size); - dst->uhi_st_atime = tswap64(src->st_atime); - dst->uhi_st_mtime = tswap64(src->st_mtime); - dst->uhi_st_ctime = tswap64(src->st_ctime); -#ifdef _WIN32 - dst->uhi_st_blksize = 0; - dst->uhi_st_blocks = 0; -#else - dst->uhi_st_blksize = tswap64(src->st_blksize); - dst->uhi_st_blocks = tswap64(src->st_blocks); -#endif - unlock_user(dst, vaddr, len); - return 0; +#undef E + + env->active_tc.gpr[2] = ret; + env->active_tc.gpr[3] = err; } -static int get_open_flags(target_ulong target_flags) +static void uhi_fstat_cb(CPUState *cs, uint64_t ret, int err) { - int open_flags = 0; + QEMU_BUILD_BUG_ON(sizeof(UHIStat) < sizeof(struct gdb_stat)); - if (target_flags & UHIOpen_RDWR) { - open_flags |= O_RDWR; - } else if (target_flags & UHIOpen_WRONLY) { - open_flags |= O_WRONLY; - } else { - open_flags |= O_RDONLY; + if (!err) { + CPUMIPSState *env = cs->env_ptr; + target_ulong addr = env->active_tc.gpr[5]; + UHIStat *dst = lock_user(VERIFY_WRITE, addr, sizeof(UHIStat), 1); + struct gdb_stat s; + + if (!dst) { + report_fault(env); + } + + memcpy(&s, dst, sizeof(struct gdb_stat)); + memset(dst, 0, sizeof(UHIStat)); + + dst->uhi_st_dev = tswap16(be32_to_cpu(s.gdb_st_dev)); + dst->uhi_st_ino = tswap16(be32_to_cpu(s.gdb_st_ino)); + dst->uhi_st_mode = tswap32(be32_to_cpu(s.gdb_st_mode)); + dst->uhi_st_nlink = tswap16(be32_to_cpu(s.gdb_st_nlink)); + dst->uhi_st_uid = tswap16(be32_to_cpu(s.gdb_st_uid)); + dst->uhi_st_gid = tswap16(be32_to_cpu(s.gdb_st_gid)); + dst->uhi_st_rdev = tswap16(be32_to_cpu(s.gdb_st_rdev)); + dst->uhi_st_size = tswap64(be64_to_cpu(s.gdb_st_size)); + dst->uhi_st_atime = tswap64(be32_to_cpu(s.gdb_st_atime)); + dst->uhi_st_mtime = tswap64(be32_to_cpu(s.gdb_st_mtime)); + dst->uhi_st_ctime = tswap64(be32_to_cpu(s.gdb_st_ctime)); + dst->uhi_st_blksize = tswap64(be64_to_cpu(s.gdb_st_blksize)); + dst->uhi_st_blocks = tswap64(be64_to_cpu(s.gdb_st_blocks)); + + unlock_user(dst, addr, sizeof(UHIStat)); } - open_flags |= (target_flags & UHIOpen_APPEND) ? O_APPEND : 0; - open_flags |= (target_flags & UHIOpen_CREAT) ? O_CREAT : 0; - open_flags |= (target_flags & UHIOpen_TRUNC) ? O_TRUNC : 0; - open_flags |= (target_flags & UHIOpen_EXCL) ? O_EXCL : 0; - - return open_flags; -} - -static int write_to_file(CPUMIPSState *env, target_ulong fd, - target_ulong vaddr, target_ulong len) -{ - int num_of_bytes; - void *dst = lock_user(VERIFY_READ, vaddr, len, 1); - if (!dst) { - report_fault(env); - } - - num_of_bytes = write(fd, dst, len); - - unlock_user(dst, vaddr, 0); - return num_of_bytes; -} - -static int read_from_file(CPUMIPSState *env, target_ulong fd, - target_ulong vaddr, target_ulong len) -{ - int num_of_bytes; - void *dst = lock_user(VERIFY_WRITE, vaddr, len, 0); - if (!dst) { - report_fault(env); - } - - num_of_bytes = read(fd, dst, len); - - unlock_user(dst, vaddr, len); - return num_of_bytes; + uhi_cb(cs, ret, err); } static int copy_argn_to_target(CPUMIPSState *env, int arg_num, @@ -260,68 +240,59 @@ static int copy_argn_to_target(CPUMIPSState *env, int arg_num, void mips_semihosting(CPUMIPSState *env) { + CPUState *cs = env_cpu(env); target_ulong *gpr = env->active_tc.gpr; const UHIOp op = gpr[25]; char *p, *p2; switch (op) { case UHI_exit: - qemu_log("UHI(%d): exit(%d)\n", op, (int)gpr[4]); + gdb_exit(gpr[4]); exit(gpr[4]); + case UHI_open: - GET_TARGET_STRING(p, gpr[4]); - if (!strcmp("/dev/stdin", p)) { - gpr[2] = 0; - } else if (!strcmp("/dev/stdout", p)) { - gpr[2] = 1; - } else if (!strcmp("/dev/stderr", p)) { - gpr[2] = 2; - } else { - gpr[2] = open(p, get_open_flags(gpr[5]), gpr[6]); - gpr[3] = errno_mips(errno); + { + int ret = -1; + + GET_TARGET_STRING(p, gpr[4]); + if (!strcmp("/dev/stdin", p)) { + ret = 0; + } else if (!strcmp("/dev/stdout", p)) { + ret = 1; + } else if (!strcmp("/dev/stderr", p)) { + ret = 2; + } + FREE_TARGET_STRING(p, gpr[4]); + + /* FIXME: reusing a guest fd doesn't seem correct. */ + if (ret >= 0) { + gpr[2] = ret; + break; + } + + semihost_sys_open(cs, uhi_cb, gpr[4], 0, gpr[5], gpr[6]); } - FREE_TARGET_STRING(p, gpr[4]); break; + case UHI_close: - if (gpr[4] < 3) { - /* ignore closing stdin/stdout/stderr */ - gpr[2] = 0; - return; - } - gpr[2] = close(gpr[4]); - gpr[3] = errno_mips(errno); + semihost_sys_close(cs, uhi_cb, gpr[4]); break; case UHI_read: - gpr[2] = read_from_file(env, gpr[4], gpr[5], gpr[6]); - gpr[3] = errno_mips(errno); + semihost_sys_read(cs, uhi_cb, gpr[4], gpr[5], gpr[6]); break; case UHI_write: - gpr[2] = write_to_file(env, gpr[4], gpr[5], gpr[6]); - gpr[3] = errno_mips(errno); + semihost_sys_write(cs, uhi_cb, gpr[4], gpr[5], gpr[6]); break; case UHI_lseek: - gpr[2] = lseek(gpr[4], gpr[5], gpr[6]); - gpr[3] = errno_mips(errno); + semihost_sys_lseek(cs, uhi_cb, gpr[4], gpr[5], gpr[6]); break; case UHI_unlink: - GET_TARGET_STRING(p, gpr[4]); - gpr[2] = remove(p); - gpr[3] = errno_mips(errno); - FREE_TARGET_STRING(p, gpr[4]); + semihost_sys_remove(cs, uhi_cb, gpr[4], 0); break; case UHI_fstat: - { - struct stat sbuf; - memset(&sbuf, 0, sizeof(sbuf)); - gpr[2] = fstat(gpr[4], &sbuf); - gpr[3] = errno_mips(errno); - if (gpr[2]) { - return; - } - gpr[2] = copy_stat_to_target(env, &sbuf, gpr[5]); - gpr[3] = errno_mips(errno); - } + semihost_sys_fstat(cs, uhi_fstat_cb, gpr[4], gpr[5]); break; + case UHI_argc: gpr[2] = semihosting_get_argc(); break; From patchwork Tue Jul 12 20:53:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 589801 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5817:0:0:0:0 with SMTP id j23csp673658max; Tue, 12 Jul 2022 13:56:12 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vvJ+ySCYINg0FaxT4Wa9vw7BWw2JmrBOJKX3rdEL+HrVLXxe1CbAEPnVJKtHOT7p4k73WZ X-Received: by 2002:a05:620a:3725:b0:6af:4f5e:de00 with SMTP id de37-20020a05620a372500b006af4f5ede00mr117583qkb.754.1657659372677; Tue, 12 Jul 2022 13:56:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657659372; cv=none; d=google.com; s=arc-20160816; b=bkqlk7NMDt7eHiSZWrCgFEzvMCzz6GZRMJw66KapH0593jNLjqK4fqEd0mSZXHA7ly J1sKeiJAHkhpTPtJ3j7D4wxtHpvm6dOlrKTkGLwJ9E/kiKOspQ74tUMNH4B9I3X1PDBx CElYrmzxniB7SIMvWoVXpIR3ZuXKbG0upSykEw5d0iNtOGlJWr91+PTRFGBfpqp4Ypax Wz+1kYNpomAJNV3c04TxUgitSO5LQnGCzYMgqRoTN4Li+AJHQje6g9TeuTX87xwjUuxt PgikLK1pkLRY+mjJ9q4yjenQteE0fqpWaAxlA5QY9xWeEqy7V3OJ+GjqwpB4Mgbng8Ek UHOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=from:reply-to:sender:errors-to: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:cc:to:dkim-signature; bh=jkHITop9GlZLzDollgFX8D+ZcnqZzYe+NeYjkL5aFv4=; b=cwClyYrUiIZNVWKRfeK+PjsTk67NhQ2FX+8qxKipTbtn2U/GyWs4BycEqM0EwrAUZW 9IWWtJfIm7yGlksjm3o0UeMxEFIn4Lg680VHismF8VwZAZlD4muYNSijQBXbnh52VI8s bgvOeu/VX5R+KTaKFWDhjivi4LIHbDIiKmU3S1fP3gHKKdGMN5jee74hp5eVRwWWYgyL j+L2mpFzKDikOuNku4rh9MXyBTo/i3LEZiey/s6JfWrHZy68K45+fAdt+2XBbXuJgBeG z/NktuG06wga7w4JRHrXo5mHbv6j6sJdghssxepIvvhV3cZwLmKaBgMSZptNMaxqU/XC f1/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20210112 header.b=cgzyr9IR; 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=nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id k5-20020ac81405000000b0031e9aecc2fesi6097733qtj.672.2022.07.12.13.56.12 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 12 Jul 2022 13:56:12 -0700 (PDT) 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=fail header.i=@gmail.com header.s=20210112 header.b=cgzyr9IR; 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=nongnu.org Received: from localhost ([::1]:37544 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oBMvU-0006G6-87 for patch@linaro.org; Tue, 12 Jul 2022 16:56:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58028) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oBMtw-0006AW-Va for qemu-devel@nongnu.org; Tue, 12 Jul 2022 16:54:36 -0400 Received: from mail-wr1-x42c.google.com ([2a00:1450:4864:20::42c]:37876) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oBMtu-0007Cw-6P for qemu-devel@nongnu.org; Tue, 12 Jul 2022 16:54:35 -0400 Received: by mail-wr1-x42c.google.com with SMTP id r10so6669775wrv.4 for ; Tue, 12 Jul 2022 13:54:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=jkHITop9GlZLzDollgFX8D+ZcnqZzYe+NeYjkL5aFv4=; b=cgzyr9IR8kz7WfwftTT5XfynA3NoPljzKZqsqrx4iIkQvASso4DuOZnN0YVdX8f0uU cncxfbHgFQ0MO9wbGvvF7pKsb3kli7/3xfVQbZ/U4FrfKa2xAc3YcU28zqBaeJaoLcyo HHPrXMfl5/fQGQJUEBZR1necKKutEKvtOTiqmwr2qCMNp/T7AgP+d1v7CIZV/Yt1W8qD y051+l1Y+dwR6b6gvm+4BYZHHO7cLvgyGUZDx7LHrcECWOFa8hubMI5PxuFJ4W0fZvuf 6FlJENicNENz99f5blx7OJAq1gDc1o5aVDz2xLQKLQVNBCg7d2zRDk8jdjKS0hRqOxYX HNvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=jkHITop9GlZLzDollgFX8D+ZcnqZzYe+NeYjkL5aFv4=; b=mCQk6egE01mdCahbasQMA5fuKxmcqkQht33yUPXxi01qF3gAw2x6SnUt89drh6dzR8 DsofZKfJN+hNr70oFa2IZDPNke58o94J+OnB1SMOc5a3Y/x96AKFaiAskJ3qFG9LZ6SM w8c6eI185ka2662peJXqWWFZPmchrwtRDGxI50snxY5LRpNt2jcquMcZyUr5rdeI+H97 FR8NRF4LhF7AxN7rIT57qLpajLFC0yCa9mB96p9XMrAEqebqqcmKMIblbFKYoWblK1dE K67H3ikgdopVPyu3X6ZI5rgh82H/ipRlp7ZC7Tt7PcvmQ+rDVWgFL5hbcdpB7HI8zhtX c7pA== X-Gm-Message-State: AJIora9yA9BsXEtBVstLKqg+uoakOo3M783UWTXhlnJFvZ9mf4EclqAC eLPrOt0V2U+/pJs6p1PmsoKELPoeez6qcLLu X-Received: by 2002:a5d:4345:0:b0:21a:3b82:ad57 with SMTP id u5-20020a5d4345000000b0021a3b82ad57mr24301603wrr.176.1657659272999; Tue, 12 Jul 2022 13:54:32 -0700 (PDT) Received: from localhost.localdomain ([185.126.107.38]) by smtp.gmail.com with ESMTPSA id v6-20020adfe4c6000000b0021d7799cf4csm9124227wrm.61.2022.07.12.13.54.31 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 12 Jul 2022 13:54:32 -0700 (PDT) To: qemu-devel@nongnu.org Cc: Aurelien Jarno , Jiaxun Yang , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= , =?utf-8?q?Alex_Benn=C3=A9e?= , Aleksandar Rikalo , Richard Henderson Subject: [PULL 08/12] target/mips: Avoid qemu_semihosting_log_out for UHI_plog Date: Tue, 12 Jul 2022 22:53:43 +0200 Message-Id: <20220712205347.58372-9-f4bug@amsat.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220712205347.58372-1-f4bug@amsat.org> References: <20220712205347.58372-1-f4bug@amsat.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42c; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wr1-x42c.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Reply-to: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Original-From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= via From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= From: Richard Henderson Use semihost_sys_write and/or qemu_semihosting_console_write for implementing plog. When using gdbstub, copy the temp string below the stack so that gdb has a guest address from which to perform the log. Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé Message-Id: <20220628111701.677216-5-richard.henderson@linaro.org> Signed-off-by: Philippe Mathieu-Daudé --- target/mips/tcg/sysemu/mips-semi.c | 52 +++++++++++++++++++++++------- 1 file changed, 41 insertions(+), 11 deletions(-) diff --git a/target/mips/tcg/sysemu/mips-semi.c b/target/mips/tcg/sysemu/mips-semi.c index 5b78cf21a7..ad11a46820 100644 --- a/target/mips/tcg/sysemu/mips-semi.c +++ b/target/mips/tcg/sysemu/mips-semi.c @@ -310,20 +310,50 @@ void mips_semihosting(CPUMIPSState *env) } gpr[2] = copy_argn_to_target(env, gpr[4], gpr[5]); break; + case UHI_plog: - GET_TARGET_STRING(p, gpr[4]); - p2 = strstr(p, "%d"); - if (p2) { - int char_num = p2 - p; - GString *s = g_string_new_len(p, char_num); - g_string_append_printf(s, "%d%s", (int)gpr[5], p2 + 2); - gpr[2] = qemu_semihosting_log_out(s->str, s->len); - g_string_free(s, true); - } else { - gpr[2] = qemu_semihosting_log_out(p, strlen(p)); + { + target_ulong addr = gpr[4]; + ssize_t len = target_strlen(addr); + GString *str; + char *pct_d; + + if (len < 0) { + report_fault(env); + } + p = lock_user(VERIFY_READ, addr, len, 1); + if (!p) { + report_fault(env); + } + + pct_d = strstr(p, "%d"); + if (!pct_d) { + FREE_TARGET_STRING(p, addr); + semihost_sys_write(cs, uhi_cb, 2, addr, len); + break; + } + + str = g_string_new_len(p, pct_d - p); + g_string_append_printf(str, "%d%s", (int)gpr[5], pct_d + 2); + FREE_TARGET_STRING(p, addr); + + /* + * When we're using gdb, we need a guest address, so + * drop the string onto the stack below the stack pointer. + */ + if (use_gdb_syscalls()) { + addr = gpr[29] - str->len; + p = lock_user(VERIFY_WRITE, addr, str->len, 0); + memcpy(p, str->str, str->len); + unlock_user(p, addr, str->len); + semihost_sys_write(cs, uhi_cb, 2, addr, str->len); + } else { + gpr[2] = qemu_semihosting_console_write(str->str, str->len); + } + g_string_free(str, true); } - FREE_TARGET_STRING(p, gpr[4]); break; + case UHI_assert: GET_TARGET_STRINGS_2(p, gpr[4], p2, gpr[5]); printf("assertion '"); From patchwork Tue Jul 12 20:53:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 589804 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5817:0:0:0:0 with SMTP id j23csp678323max; Tue, 12 Jul 2022 14:02:37 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sLwtChL7G6fjvV4aO2zNrqhJIyjiMYx1Qwx2hR3Dcq14+GkfoCQv5swcxSm7zASq8KCHSi X-Received: by 2002:a05:620a:41:b0:6b5:5976:56e9 with SMTP id t1-20020a05620a004100b006b5597656e9mr123981qkt.199.1657659757382; Tue, 12 Jul 2022 14:02:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657659757; cv=none; d=google.com; s=arc-20160816; b=k6XfcYu88rmWK8Z55W5TUsZ55fncwCFqLOix1UH9MAb53mNEK9kOnJw7+j8n93utlq N/PkK3sXKs0zdgVuDinAH1VWkRn9Wxdls7NY25/l8lwd1UTgY4yh0PhOYh4/VLovAvhS 335WucFl2MC6k2lRESmCAARc2RPRSOXTlHdgdIhNxcviDS26zMXpHkAhuh4+w7HbfBTN yLvRY2arlL3h7MWrxtGW7eFOyxM6uRD5zOEtcvNsEluJE5FiejQCdVANwHnFSAC+wVOG uPdsrvdoS5hv6iDSAfnKeVSbggpuC8jRM1JJyctrQlzPPYk5qiX6WEPmYHiEORz4oFIB T5Fw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=from:reply-to:sender:errors-to: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:cc:to:dkim-signature; bh=a+TbjQCV2xLA3zQIhvHGy53Lrzpawukh7l0Zf+LYs0I=; b=or8AT48kEIh+dIHFBEPGbz3rIN+hCu6+JXBPQUn6Kiew/Js6mb0HFiJ36rXmFNC+E/ Z0uXN7a90J1bsQ5h+/+stXTWbwt1eO+a7/ybdBUwHIrjk2uZaen5GVC0gxLu9w4CwFBm vZdJ1UvIT+c3ddGT/RWDlA57LvKt9whS3YeYNIpRyK8TBcEYIWxU8nwxd5oKRcs0pDdz 3hP/WcQwM7V2e/GSG6zO8JPZ97jQwlU1ypK5XJls0/eonf8YSwhslc1K2yu2zTEf3+iB XIAmtC5B4nULiFtGeWmlF0G1sLC5Da/7Lr1S2C3yP6A5fIHCtLEUo0p+kRUZ2cek3087 YVyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20210112 header.b=gEXAqPV+; 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=nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id jl7-20020ad45e87000000b004704608181csi7110548qvb.363.2022.07.12.14.02.37 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 12 Jul 2022 14:02:37 -0700 (PDT) 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=fail header.i=@gmail.com header.s=20210112 header.b=gEXAqPV+; 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=nongnu.org Received: from localhost ([::1]:51796 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oBN1g-0007VL-W4 for patch@linaro.org; Tue, 12 Jul 2022 17:02:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58074) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oBMu1-0006Jm-VL for qemu-devel@nongnu.org; Tue, 12 Jul 2022 16:54:41 -0400 Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]:41521) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oBMu0-0007H5-FS for qemu-devel@nongnu.org; Tue, 12 Jul 2022 16:54:41 -0400 Received: by mail-wr1-x432.google.com with SMTP id q9so12826830wrd.8 for ; Tue, 12 Jul 2022 13:54:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=a+TbjQCV2xLA3zQIhvHGy53Lrzpawukh7l0Zf+LYs0I=; b=gEXAqPV+06vVfeG/juMBKje9J+k35r1OB9tC1z7sREhxx9HQKAjoZqHWLRFDBuWZr5 OnubCaL/sO06d7jJHipwGHKD5ydXU+0s/4f1OS+nA3jDOzmxdrdgJbBYXDl5gDXPFjaa VDr3tbSIwQqUVoGJ1DiN6jeVEnvHM0sbSd+hwCnCb4H+THBmkA5uka9sgz/KSm3w0ogO F4JBcP15kWR48HnBuKCNJrOYtT0H62m7kmuUrVBVAuDScS7jL551xxYsEo73JnBkz3Cd lkpOcAcm533Lm8HwKqMnIy5vbDqhJuO4xdPM/+fHg5Q1/YJTOJ9okvjORZ6lz6CV3Ho2 6nxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=a+TbjQCV2xLA3zQIhvHGy53Lrzpawukh7l0Zf+LYs0I=; b=WnuEvJYNeMNJd9G2mP64qTrYk2LRDC473+RZcnprJiW6W+HaOjzbcCOJuAvXEvtMfh 6x5aGJhOG3M15c6f0uXdW0VIwwx3WLCs6OXJQSyWLBEF8LARPoqeP2IMoBB9bBlNOlSh /2LbzDymfHAdqn1bjHDGZ7RzRlqQ/GZSc7PO6CpI8EIT2PzkUIQURxZ4IIAghmTd4I2A shmB1fGYUTeo6KAH+COhJxsGu11DT9AEZea2LFjeM+Gmn8N8puFAt/IsbYdviQmiwgyD fzFiyYV7K9RW9H1CCTWA2C87vBuP9j/eAk4cQBdBmcKIOTO37S+PutL1YnQTHMyZTEgy qfsw== X-Gm-Message-State: AJIora8qJuKeVhZAzusf+L18WPLsgN9K1vxZ3vuBB6pvDUguUY4FbAMe G6rolF2YwIBuT22QZNrMhye3y7533OLL64wP X-Received: by 2002:a5d:64ce:0:b0:21d:a952:31d5 with SMTP id f14-20020a5d64ce000000b0021da95231d5mr10013137wri.667.1657659278779; Tue, 12 Jul 2022 13:54:38 -0700 (PDT) Received: from localhost.localdomain ([185.126.107.38]) by smtp.gmail.com with ESMTPSA id n31-20020a05600c501f00b003a2c7bf0497sm82801wmr.16.2022.07.12.13.54.37 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 12 Jul 2022 13:54:38 -0700 (PDT) To: qemu-devel@nongnu.org Cc: Aurelien Jarno , Jiaxun Yang , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= , =?utf-8?q?Alex_Benn=C3=A9e?= , Aleksandar Rikalo , Richard Henderson Subject: [PULL 09/12] target/mips: Use error_report for UHI_assert Date: Tue, 12 Jul 2022 22:53:44 +0200 Message-Id: <20220712205347.58372-10-f4bug@amsat.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220712205347.58372-1-f4bug@amsat.org> References: <20220712205347.58372-1-f4bug@amsat.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::432; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wr1-x432.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Reply-to: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Original-From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= via From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= From: Richard Henderson Always log the assert locally. Do not report_fault, but instead include the fact of the fault in the assertion. Don't bother freeing allocated strings before the abort(). Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé Message-Id: <20220628111701.677216-6-richard.henderson@linaro.org> Signed-off-by: Philippe Mathieu-Daudé --- target/mips/tcg/sysemu/mips-semi.c | 39 ++++++++++++++---------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/target/mips/tcg/sysemu/mips-semi.c b/target/mips/tcg/sysemu/mips-semi.c index ad11a46820..ae4b8849b1 100644 --- a/target/mips/tcg/sysemu/mips-semi.c +++ b/target/mips/tcg/sysemu/mips-semi.c @@ -221,18 +221,6 @@ static int copy_argn_to_target(CPUMIPSState *env, int arg_num, } \ } while (0) -#define GET_TARGET_STRINGS_2(p, addr, p2, addr2) \ - do { \ - p = lock_user_string(addr); \ - if (!p) { \ - report_fault(env); \ - } \ - p2 = lock_user_string(addr2); \ - if (!p2) { \ - report_fault(env); \ - } \ - } while (0) - #define FREE_TARGET_STRING(p, gpr) \ do { \ unlock_user(p, gpr, 0); \ @@ -243,7 +231,7 @@ void mips_semihosting(CPUMIPSState *env) CPUState *cs = env_cpu(env); target_ulong *gpr = env->active_tc.gpr; const UHIOp op = gpr[25]; - char *p, *p2; + char *p; switch (op) { case UHI_exit: @@ -355,14 +343,23 @@ void mips_semihosting(CPUMIPSState *env) break; case UHI_assert: - GET_TARGET_STRINGS_2(p, gpr[4], p2, gpr[5]); - printf("assertion '"); - printf("\"%s\"", p); - printf("': file \"%s\", line %d\n", p2, (int)gpr[6]); - FREE_TARGET_STRING(p2, gpr[5]); - FREE_TARGET_STRING(p, gpr[4]); - abort(); - break; + { + const char *msg, *file; + + msg = lock_user_string(gpr[4]); + if (!msg) { + msg = ""; + } + file = lock_user_string(gpr[5]); + if (!file) { + file = ""; + } + + error_report("UHI assertion \"%s\": file \"%s\", line %d", + msg, file, (int)gpr[6]); + abort(); + } + default: error_report("Unknown UHI operation %d", op); abort(); From patchwork Tue Jul 12 20:53:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 589803 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5817:0:0:0:0 with SMTP id j23csp675376max; Tue, 12 Jul 2022 13:58:53 -0700 (PDT) X-Google-Smtp-Source: AGRyM1u00uc6n+62LBjQFH+8E4bVaR5DjKW6xqE7pM3D3i7i0vVAK5yzfYlQtVLF8kMnBLcR6z7z X-Received: by 2002:a05:622a:28c:b0:31b:f536:942b with SMTP id z12-20020a05622a028c00b0031bf536942bmr20151957qtw.654.1657659533175; Tue, 12 Jul 2022 13:58:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657659533; cv=none; d=google.com; s=arc-20160816; b=z5oaWXRm6wUpvWU+/+WualCk0K19EU+Vpfz8CHz//TU2eARDl/YTe6otuT4F46snIO MhAR44hux0TTPZAfV8AIUjXRKZNSN0FYAEO80BIdc5FaLusaLohapaWVaNUdqvk+W+WJ lk2nYjLJifkCP3Ol/ti931TINC1xQizUBqcJxwMqIlPN9OueGfF+78ndjye2Qut7c8wA XXRrl9iNx3QhfCdspDeY69+ImwjT03siQJ4jJPmg+k+UysAEmUEapqYCloyNrFzkhcju BmY7Q1+GcG5iiJ4D+ryAimVrU0ls6lLY76RwyW+kGkwFO3rBsSHAka+lEx33uSYvAVUg s7cA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=from:reply-to:sender:errors-to: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:cc:to:dkim-signature; bh=0pu9Y3XzRXbWbXaSGS52OJ20ieZtVBHvHSmSmKTWtx8=; b=bfsEW8Vs4+lD0aj/TdLhdOH+a0ggjMlP/eiKFHjIZMUXwR34Dx62ZkwLJK8HUp+drK IFXUCD7WmujZvJDw5KcfabnRo+eV6U5iXCK9wjiJiVcy8gRcyjS2L6mCwy7TVm9hGGxy Irtp2e7e9Yccb4vLMTn3tX14kF5tp2ddh9IIBx2i3flkC8l9qYNLALH4nbAtEYYlXbJC zGtpB7ZUxNg3ACOT7JF++N8T6CdkrFY0PUY4MJzGL+23K4kiU5Nv+czA7RZ+BLx7GXm5 19IwcfEzs/vUtqTP1uXLsL3Su7f11lreMbQW3PyrVCSvQyeFLU70j3asWzIvFdlphtXz X2fA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20210112 header.b="Vb/vDw/T"; 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=nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id bs12-20020ac86f0c000000b0031eba48ba42si3040975qtb.227.2022.07.12.13.58.53 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 12 Jul 2022 13:58:53 -0700 (PDT) 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=fail header.i=@gmail.com header.s=20210112 header.b="Vb/vDw/T"; 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=nongnu.org Received: from localhost ([::1]:45444 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oBMy4-0003EG-Oj for patch@linaro.org; Tue, 12 Jul 2022 16:58:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58098) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oBMu7-0006dP-3Y for qemu-devel@nongnu.org; Tue, 12 Jul 2022 16:54:47 -0400 Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]:37684) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oBMu5-0007HS-KN for qemu-devel@nongnu.org; Tue, 12 Jul 2022 16:54:46 -0400 Received: by mail-wm1-x32b.google.com with SMTP id c131-20020a1c3589000000b003a2cc290135so95269wma.2 for ; Tue, 12 Jul 2022 13:54:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0pu9Y3XzRXbWbXaSGS52OJ20ieZtVBHvHSmSmKTWtx8=; b=Vb/vDw/TuUH61UbGVx6e/2yAqiGSuSCKG6QkOPkXdDf94KdOGRFiBv69czy4Yo6x5V b9DVuW7duxlMTx9WvyNLKNzahnj7vFa8Zw/rT1BWJVUOqjZbKrg8EftOpg5P9JmgWD2p KRZet9ita5kYuUq6TB7UxvJtmzdFg1lqKuNLiM0Ht/ZzqxFdvjP022xhKoGEA3IHJbos UFr3M0NGEwdLJncZ1m9ANVLkkLorxYmdoqTH/QpKo2l6DwRNwdWhWJJiJovpbbClD5RR 0PoJqcCZtHizSsbFmkz2U3II9x02F6WktHCnBKuZDKFvsxsFdfZ9sCswTZVFtJ7b/FRR yDgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=0pu9Y3XzRXbWbXaSGS52OJ20ieZtVBHvHSmSmKTWtx8=; b=i1d5M/hbftnG4t98mMU9pX3K2XVEBv9wsHhsMV7BKcbCSLhoN9QdlbeVELz0cMYncY SUvwicr6X0kPxYwBKkVoZrXMCtxXm5d+3uan/7pgHq3k04BKuigXDckwMML04h1feSV1 tc9iNaSIMr3DDpk/dRH1+tFCPBWwoHa9cf2GfpCxFqZzxrpGOR5quDbHJX9u5AS58K57 2Y1abaBHLYUavCrghaADNDbh8ANWQxPJhusroamiPnAmYWaLbKtHmj2J4wsFnWLmVoFD 6PVfYIHMgB3MqeWEj+p40t3nkYRpR4Md4hku9Q1f7uqTteO8XiwkxfCvDF//qNGAUfVz JbYA== X-Gm-Message-State: AJIora8zrx7huN5rzRSPvVFjl4x1W1o3/zI2HQ0YuvlsA95idKE0EZYa adwwg/s4eSDuqaV8HG9MxJJX3fEOrZ3sN0og X-Received: by 2002:a05:600c:1c1a:b0:3a2:d8e7:c15b with SMTP id j26-20020a05600c1c1a00b003a2d8e7c15bmr6100469wms.45.1657659284038; Tue, 12 Jul 2022 13:54:44 -0700 (PDT) Received: from localhost.localdomain ([185.126.107.38]) by smtp.gmail.com with ESMTPSA id i4-20020a05600c480400b003a2eacc8179sm46176wmo.27.2022.07.12.13.54.42 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 12 Jul 2022 13:54:43 -0700 (PDT) To: qemu-devel@nongnu.org Cc: Aurelien Jarno , Jiaxun Yang , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= , =?utf-8?q?Alex_Benn=C3=A9e?= , Aleksandar Rikalo , Richard Henderson Subject: [PULL 10/12] semihosting: Remove qemu_semihosting_log_out Date: Tue, 12 Jul 2022 22:53:45 +0200 Message-Id: <20220712205347.58372-11-f4bug@amsat.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220712205347.58372-1-f4bug@amsat.org> References: <20220712205347.58372-1-f4bug@amsat.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32b; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wm1-x32b.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Reply-to: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Original-From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= via From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= From: Richard Henderson The function is no longer used. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson Message-Id: <20220628111701.677216-7-richard.henderson@linaro.org> Signed-off-by: Philippe Mathieu-Daudé --- include/semihosting/console.h | 13 ------------- semihosting/console.c | 9 --------- 2 files changed, 22 deletions(-) diff --git a/include/semihosting/console.h b/include/semihosting/console.h index 61b0cb3a94..bd78e5f03f 100644 --- a/include/semihosting/console.h +++ b/include/semihosting/console.h @@ -40,19 +40,6 @@ int qemu_semihosting_console_read(CPUState *cs, void *buf, int len); */ int qemu_semihosting_console_write(void *buf, int len); -/** - * qemu_semihosting_log_out: - * @s: pointer to string - * @len: length of string - * - * Send a string to the debug output. Unlike console_out these strings - * can't be sent to a remote gdb instance as they don't exist in guest - * memory. - * - * Returns: number of bytes written - */ -int qemu_semihosting_log_out(const char *s, int len); - /* * qemu_semihosting_console_block_until_ready: * @cs: CPUState diff --git a/semihosting/console.c b/semihosting/console.c index cda7cf1905..5b1ec0a1c3 100644 --- a/semihosting/console.c +++ b/semihosting/console.c @@ -38,15 +38,6 @@ typedef struct SemihostingConsole { static SemihostingConsole console; -int qemu_semihosting_log_out(const char *s, int len) -{ - if (console.chr) { - return qemu_chr_write_all(console.chr, (uint8_t *) s, len); - } else { - return write(STDERR_FILENO, s, len); - } -} - #define FIFO_SIZE 1024 static int console_can_read(void *opaque) From patchwork Tue Jul 12 20:53:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 589806 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5817:0:0:0:0 with SMTP id j23csp682390max; Tue, 12 Jul 2022 14:07:36 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sEgqQ8j5KTWrc04Diwra4vI3yUIwU7LMdCCoEiqhV0xPTScebLhx0QwGFi2tAMIX0Zy/Au X-Received: by 2002:a05:6214:4106:b0:473:399a:de6b with SMTP id kc6-20020a056214410600b00473399ade6bmr186340qvb.124.1657660055924; Tue, 12 Jul 2022 14:07:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657660055; cv=none; d=google.com; s=arc-20160816; b=oKB543F9uv/6x/eL4ng/uFPoOkEsrIF/dcBbas4yLOko+K2oksrsP6wKaeJP3ImU33 t0kAy630Al35toBA+5ioI9nh/ptshd5trZMMhjxjWnu8WySpmRlKfG0jwWPe44xhxqyV 7m4TyuK7qYNElrRbu8K3nouEYLUXdEx587IqdZAjoTeHTqOzsNCnLQ01aLt89+L25w73 FEAVDegpYXhvpY++AXLKtjDFvM/n2QcuBlxch/Xae8sm3VqA9XS2++bfkyHUVfk3qD9W V/8d1BVzdKTDaR2L5xw29+ldsjJfttdiYktSWH9X76HVFQ7A8ViXXsHfOLo7HL6Kvb0r FqUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=from:reply-to:sender:errors-to: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:cc:to:dkim-signature; bh=MkJbeZ2YzCPPLGp8kgmOOD9tSwj1sJlRAj5pJts4/Ms=; b=Ojaalk5MwxPNZD3p5BmMF/h8J1aoTAA/4yxu83LF5r5wI2Mtk3Gt5AZp6p2HnC8pzJ zhJj6C8P5y8MPOjDgDEp5GF2nY3Zq23gHwFEKVyCW4wwO0+24rW298mHorafvnYstJ0r 0ehBcRqMW+YfcW0XMfHtbf6S/W3fFHq1FQvBWdKPCb9TuoUH2gQRk378lDDtt2Ix5Qqi mxhsAZro0JJGKEwSi2lFiIlF367v1V8JGhPL18Gar8CVkohh+N8ohYQDm5ziDG0f9gZx GvER+IEjFdcAug0ivFLDRqU0oGZSGLgUz77zLsfqKLe9yXL9dfZJzjUy4wrfhTAwCS0i PAuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20210112 header.b=P1MxcxvG; 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=nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id dx14-20020a05620a608e00b006b5a6f9c226si1366897qkb.314.2022.07.12.14.07.35 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 12 Jul 2022 14:07:35 -0700 (PDT) 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=fail header.i=@gmail.com header.s=20210112 header.b=P1MxcxvG; 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=nongnu.org Received: from localhost ([::1]:60374 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oBN6V-00055Q-Ir for patch@linaro.org; Tue, 12 Jul 2022 17:07:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58134) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oBMuB-0006sa-K9 for qemu-devel@nongnu.org; Tue, 12 Jul 2022 16:54:51 -0400 Received: from mail-wr1-x42c.google.com ([2a00:1450:4864:20::42c]:37876) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oBMuA-0007Cw-5V for qemu-devel@nongnu.org; Tue, 12 Jul 2022 16:54:51 -0400 Received: by mail-wr1-x42c.google.com with SMTP id r10so6670483wrv.4 for ; Tue, 12 Jul 2022 13:54:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=MkJbeZ2YzCPPLGp8kgmOOD9tSwj1sJlRAj5pJts4/Ms=; b=P1MxcxvGewwYqY8CxeIi4RA8yTtuHJ0qoDjGLOcwx9QCguT1BteIfhIwZLLmLLZIEN rDMhjffbZe16wLsPouSqd3eB+fkr7GAdTscFM8byaxAOQSrw5WYT5k4nBu1UbGRloY+N t+XJMnDUek4ZBCLCN3Yqp9zNR3CXx4VsXHNdGWucdB7/eo0EXnEw+BsV3oxcQHs2vjg1 tGNbk7mvsNybNglMHwIw8eziKXDV8j+RdlDvWYbX9me1h9y4OUKIoOypzkuC47EL8nmZ ntv0x5rYDfqsV4vQfdmPS4qE/Es5BtIKAT1+aD/oK7yiMxdtCoLjbkh3wFIzCDY6aVdE zAHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=MkJbeZ2YzCPPLGp8kgmOOD9tSwj1sJlRAj5pJts4/Ms=; b=POx4nLW2+cmifmygPfWjzORx1nTpTwxZWW3sC2RmXqzOmVreriui2aS77rtmYFQIbc YQdtdyvdMP3oKYWPZ9D3ZbBrOp8O/kMOHqek9c2aXsespxbCRj2PmChlvya2EaBK/LoR XcAu0Qtqg629bpZ8VmdOBlYrbQZOAZk6Viln8YvIoO7CIi82AtUKtHg4e/6pqBw3G6Pc /iTYUPm5JV/DCPvo//HCJOg4wdlD1gvBhYnR3sQExxTaPwNQAUAm7jSn1o8FRXaE/bWI MSGAU6+59NdRaz3Wi+KGPzyS3oKxNCWgtbc4iKhrPCV4BwtNjbObNlFCoYjRIPDqzzZU 5VWA== X-Gm-Message-State: AJIora8cpqem4/fx6KCwuiKz2MopeEAJIzrqZbH2hLDbJKXjdHwjVtvZ RoTYpHTGl0pkfzT4q9tpsTbgWepzc/+lji4m X-Received: by 2002:a5d:5a9d:0:b0:21b:8247:7ec4 with SMTP id bp29-20020a5d5a9d000000b0021b82477ec4mr23461268wrb.561.1657659289195; Tue, 12 Jul 2022 13:54:49 -0700 (PDT) Received: from localhost.localdomain ([185.126.107.38]) by smtp.gmail.com with ESMTPSA id v130-20020a1cac88000000b003a046549a85sm14939wme.37.2022.07.12.13.54.48 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 12 Jul 2022 13:54:48 -0700 (PDT) To: qemu-devel@nongnu.org Cc: Aurelien Jarno , Jiaxun Yang , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= , =?utf-8?q?Alex_Benn=C3=A9e?= , Aleksandar Rikalo , Richard Henderson Subject: [PULL 11/12] target/mips: Simplify UHI_argnlen and UHI_argn Date: Tue, 12 Jul 2022 22:53:46 +0200 Message-Id: <20220712205347.58372-12-f4bug@amsat.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220712205347.58372-1-f4bug@amsat.org> References: <20220712205347.58372-1-f4bug@amsat.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42c; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wr1-x42c.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Reply-to: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Original-From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= via From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= From: Richard Henderson With semihosting_get_arg, we already have a check vs argc, so there's no point replicating it -- just check the result vs NULL. Merge copy_argn_to_target into its caller. Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé Message-Id: <20220628111701.677216-8-richard.henderson@linaro.org> Signed-off-by: Philippe Mathieu-Daudé --- target/mips/tcg/sysemu/mips-semi.c | 44 ++++++++++++++---------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/target/mips/tcg/sysemu/mips-semi.c b/target/mips/tcg/sysemu/mips-semi.c index ae4b8849b1..b54267681e 100644 --- a/target/mips/tcg/sysemu/mips-semi.c +++ b/target/mips/tcg/sysemu/mips-semi.c @@ -198,21 +198,6 @@ static void uhi_fstat_cb(CPUState *cs, uint64_t ret, int err) uhi_cb(cs, ret, err); } -static int copy_argn_to_target(CPUMIPSState *env, int arg_num, - target_ulong vaddr) -{ - int strsize = strlen(semihosting_get_arg(arg_num)) + 1; - char *dst = lock_user(VERIFY_WRITE, vaddr, strsize, 0); - if (!dst) { - report_fault(env); - } - - strcpy(dst, semihosting_get_arg(arg_num)); - - unlock_user(dst, vaddr, strsize); - return 0; -} - #define GET_TARGET_STRING(p, addr) \ do { \ p = lock_user_string(addr); \ @@ -285,18 +270,31 @@ void mips_semihosting(CPUMIPSState *env) gpr[2] = semihosting_get_argc(); break; case UHI_argnlen: - if (gpr[4] >= semihosting_get_argc()) { - gpr[2] = -1; - return; + { + const char *s = semihosting_get_arg(gpr[4]); + gpr[2] = s ? strlen(s) : -1; } - gpr[2] = strlen(semihosting_get_arg(gpr[4])); break; case UHI_argn: - if (gpr[4] >= semihosting_get_argc()) { - gpr[2] = -1; - return; + { + const char *s = semihosting_get_arg(gpr[4]); + target_ulong addr; + size_t len; + + if (!s) { + gpr[2] = -1; + break; + } + len = strlen(s) + 1; + addr = gpr[5]; + p = lock_user(VERIFY_WRITE, addr, len, 0); + if (!p) { + report_fault(env); + } + memcpy(p, s, len); + unlock_user(p, addr, len); + gpr[2] = 0; } - gpr[2] = copy_argn_to_target(env, gpr[4], gpr[5]); break; case UHI_plog: From patchwork Tue Jul 12 20:53:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 589807 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5817:0:0:0:0 with SMTP id j23csp683939max; Tue, 12 Jul 2022 14:09:16 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tvB0akySeZmZNDYGujYrxKVWN5T0GumZWOJ6WKqFn/xP74iavoQh1NBOQt8K7WBPSzJQLm X-Received: by 2002:a05:620a:2845:b0:6ab:8e0c:1938 with SMTP id h5-20020a05620a284500b006ab8e0c1938mr145698qkp.315.1657660156439; Tue, 12 Jul 2022 14:09:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657660156; cv=none; d=google.com; s=arc-20160816; b=J8miYVpClK2HBxH3H+TGJOnvv6NgJdJI6dDRlOoAAf8b2QWqCQJYGuOGsOL09PTZBz WTt5k78Y5h75Ddq94QcluuRb7RcwI8fKya3JCp/0GJVF9GhX39kRA6opBWrLnVGuV2T3 Vn75yF6Avoi+waLUoZB/fJRrOCI0onOeZhXMfUcbRa2XQmH/hc0MRc2Pc6HAqUOSX3l4 jki3e8XbMBuW/JqRizo/Ufxel2QaNH2eqNapc9WyyPtIyptjMPvxAanOA3c+b5wg7tiG yvO+MuV+DMWlTa1jJT3y3EM11etEr32JsgtvwTV05ztkz9jQtbk4Oc2sjoD14V7nETOL 3pAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=from:reply-to:sender:errors-to: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:cc:to:dkim-signature; bh=J+fYyUK4Wn/KdMxUP+5nF/zpMZEk/uz6FzEWPHrbQtQ=; b=0j5yr64aFONzyqjEAWNFpawD535w9hqAfnxBZ8ha5roIj7mJ26y+uh3rfiIF/gpX2Q C2L1dvQ5nB9YVEPZzhihDBduEIVp2gGuJdExhVgMg6qHBPaGTfhwFw+C7NX6OhnwHEN6 AIompC8mfSGbdJ+G9ub8SNKgpwZzx2mwzt9oPDo6XIFafgIciQGgqS7LDiDqXs8JFkiH X75l98L0pyKJ70u+89TYYfaBaXakCbL9ragl24cOdkjlywd15JvA+tlLDbNzTjN+C7Hn OwU21Df1HHCEueA2jmPrs/LlvaXHfxEzbJwbOVl6f3dZjYm+7te2w9w+Bq7S1B+f9mru Hz2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20210112 header.b=fLcXoP5n; 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=nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id m2-20020a05620a24c200b006af217e92cdsi7425779qkn.695.2022.07.12.14.09.16 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 12 Jul 2022 14:09:16 -0700 (PDT) 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=fail header.i=@gmail.com header.s=20210112 header.b=fLcXoP5n; 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=nongnu.org Received: from localhost ([::1]:34576 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oBN88-0006lJ-1c for patch@linaro.org; Tue, 12 Jul 2022 17:09:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58174) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oBMuH-00079e-Lt for qemu-devel@nongnu.org; Tue, 12 Jul 2022 16:54:57 -0400 Received: from mail-wr1-x433.google.com ([2a00:1450:4864:20::433]:39517) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oBMuG-0007IY-0k for qemu-devel@nongnu.org; Tue, 12 Jul 2022 16:54:57 -0400 Received: by mail-wr1-x433.google.com with SMTP id f2so12814627wrr.6 for ; Tue, 12 Jul 2022 13:54:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=J+fYyUK4Wn/KdMxUP+5nF/zpMZEk/uz6FzEWPHrbQtQ=; b=fLcXoP5nHs2nXupXU8cRkw1+IAK5146OcyGyGjC5xXkKLXFMhb4Zi3+GsZd8EFP9Nz 9+OLUPNG2St9HT4RilRdsxKVQJIu1CcL/T9FAxjDHr9UwBxTjQWNuh8pX3AWpCX0ryBI 7IUyFpmKQ2s6KK+A3YGvaBNOzoJI7+edGJxyCpfXmvTTYKc59at47NPwIzdTU5PWftAL /HbpfwSFm3DGQaWbdl1shq+1B9NzGVkJzKXRAVvB7BuKZDC/bY5ZVnRCzZcF8cH+xQBm 40Jw0X9l8goKIdU3wgQF0weRLL4t2vT1njtq6lpypqwDyZnPh9ag7pXMF8nIZxSK2CIJ 32Ug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=J+fYyUK4Wn/KdMxUP+5nF/zpMZEk/uz6FzEWPHrbQtQ=; b=QkmZL96XxgiapxgkNuJdtXvPPQtE/HGItGIxrmcV4u5EsqfzGLGGhLrzVefiz4qeCo Ns+h11dQpwjDdj6sIHXCFAmPVb5UFDWW/84Keq/mW4bfq/lm6I5KoCPYWmzu1+SgnBiz /ttcdMv7t85Rzd6ORFhpyFpEb2aKcMssbWbo5chhdNeLqdjVWJ6jsaNN7xpTDohprmsg JSMfs0/upPPfae0/VxwhqV8mPP1BWThTB27CPEhw6lvhuertZ1lXJaOV+AdwgGD+ul97 jqPyJSomIk7ElkoBYru+3hGSsHFtwV7Quk2gTkjxR4jr11zHbc7H2F3OgsgHkJr8Hejw qxDA== X-Gm-Message-State: AJIora9QKVoJnpY1vZzfIOE1cFQTwBKqBmGVSCwf1iu7pU6frx48WF6y cXF1lAq+KkcblN8HkYp1+T7tiEzp7prkaXAJ X-Received: by 2002:a5d:6c6b:0:b0:1ea:77ea:dde8 with SMTP id r11-20020a5d6c6b000000b001ea77eadde8mr24447112wrz.690.1657659294357; Tue, 12 Jul 2022 13:54:54 -0700 (PDT) Received: from localhost.localdomain ([185.126.107.38]) by smtp.gmail.com with ESMTPSA id l16-20020a7bc450000000b003a2d6f26babsm105028wmi.3.2022.07.12.13.54.53 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 12 Jul 2022 13:54:53 -0700 (PDT) To: qemu-devel@nongnu.org Cc: Aurelien Jarno , Jiaxun Yang , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= , =?utf-8?q?Alex_Benn=C3=A9e?= , Aleksandar Rikalo , Richard Henderson Subject: [PULL 12/12] target/mips: Remove GET_TARGET_STRING and FREE_TARGET_STRING Date: Tue, 12 Jul 2022 22:53:47 +0200 Message-Id: <20220712205347.58372-13-f4bug@amsat.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220712205347.58372-1-f4bug@amsat.org> References: <20220712205347.58372-1-f4bug@amsat.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::433; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wr1-x433.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Reply-to: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Original-From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= via From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= From: Richard Henderson Inline these macros into the only two callers. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson Message-Id: <20220628111701.677216-9-richard.henderson@linaro.org> Signed-off-by: Philippe Mathieu-Daudé --- target/mips/tcg/sysemu/mips-semi.c | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/target/mips/tcg/sysemu/mips-semi.c b/target/mips/tcg/sysemu/mips-semi.c index b54267681e..5fb1ad9092 100644 --- a/target/mips/tcg/sysemu/mips-semi.c +++ b/target/mips/tcg/sysemu/mips-semi.c @@ -198,19 +198,6 @@ static void uhi_fstat_cb(CPUState *cs, uint64_t ret, int err) uhi_cb(cs, ret, err); } -#define GET_TARGET_STRING(p, addr) \ - do { \ - p = lock_user_string(addr); \ - if (!p) { \ - report_fault(env); \ - } \ - } while (0) - -#define FREE_TARGET_STRING(p, gpr) \ - do { \ - unlock_user(p, gpr, 0); \ - } while (0) - void mips_semihosting(CPUMIPSState *env) { CPUState *cs = env_cpu(env); @@ -225,9 +212,13 @@ void mips_semihosting(CPUMIPSState *env) case UHI_open: { + target_ulong fname = gpr[4]; int ret = -1; - GET_TARGET_STRING(p, gpr[4]); + p = lock_user_string(fname); + if (!p) { + report_fault(env); + } if (!strcmp("/dev/stdin", p)) { ret = 0; } else if (!strcmp("/dev/stdout", p)) { @@ -235,7 +226,7 @@ void mips_semihosting(CPUMIPSState *env) } else if (!strcmp("/dev/stderr", p)) { ret = 2; } - FREE_TARGET_STRING(p, gpr[4]); + unlock_user(p, fname, 0); /* FIXME: reusing a guest fd doesn't seem correct. */ if (ret >= 0) { @@ -243,7 +234,7 @@ void mips_semihosting(CPUMIPSState *env) break; } - semihost_sys_open(cs, uhi_cb, gpr[4], 0, gpr[5], gpr[6]); + semihost_sys_open(cs, uhi_cb, fname, 0, gpr[5], gpr[6]); } break; @@ -314,14 +305,14 @@ void mips_semihosting(CPUMIPSState *env) pct_d = strstr(p, "%d"); if (!pct_d) { - FREE_TARGET_STRING(p, addr); + unlock_user(p, addr, 0); semihost_sys_write(cs, uhi_cb, 2, addr, len); break; } str = g_string_new_len(p, pct_d - p); g_string_append_printf(str, "%d%s", (int)gpr[5], pct_d + 2); - FREE_TARGET_STRING(p, addr); + unlock_user(p, addr, 0); /* * When we're using gdb, we need a guest address, so