From patchwork Wed Sep 14 13:22:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 1677876 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=Ku4UUosT; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MSLvW03n4z1yhR for ; Wed, 14 Sep 2022 23:36:05 +1000 (AEST) Received: from localhost ([::1]:48464 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oYSYb-0003Ze-IV for incoming@patchwork.ozlabs.org; Wed, 14 Sep 2022 09:36:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48354) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oYSMF-0007s1-MF for qemu-devel@nongnu.org; Wed, 14 Sep 2022 09:23:15 -0400 Received: from mail-wm1-x32a.google.com ([2a00:1450:4864:20::32a]:39753) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oYSMD-0000aT-KQ for qemu-devel@nongnu.org; Wed, 14 Sep 2022 09:23:15 -0400 Received: by mail-wm1-x32a.google.com with SMTP id bg5-20020a05600c3c8500b003a7b6ae4eb2so15484587wmb.4 for ; Wed, 14 Sep 2022 06:23:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date; bh=BOg1aEu3yBTI9dGIqi4jrE4GeTG3hleBbfwHOhDBa5c=; b=Ku4UUosT+wWF1FV6uA2Lr0oLbvKnNXoZdF3CQfgztKkSy+z0AIeEomHF0yUivNZ17E Tx6YCaIKXEwZodtUaoRWPl70HLwptcOz3W7bEPMioJEqwTsX6/HSEoR3WS5WglAaKrrW 246KTHY0o7PQSGHlKiorOyd2JeM5+ajrx+iFU39NXKVgO4XnUH53jSXiDJR4SYJ8C7mQ q/tGSwO0cgtb+E2w+H7ogdb81eeB8ToEQ1HuB1/QuMAii60K0hWDe+vALX9dTPXXwKx/ hWfASMfrZxoEWOgVm0W/th/932r8WcbjMMsVSaH6nC498/iKYryGLVD64A8XJeOVchBy mkfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date; bh=BOg1aEu3yBTI9dGIqi4jrE4GeTG3hleBbfwHOhDBa5c=; b=BctlWYn2xJ3EfzgxHGEBXIx9EsvaK76koRnHkSTVcrlBVABW8KMFyftWZok4wOLiag 9CZe+W3i+KW+sJSq5esisMln5FnqLmxYr+QWi8rMoRPQEdRcs5HEulifZWELQxykfLEl hNWDF4u5MfR29meVa5bKm7aQCfieh6Bptkzw6AB6KsOjQqmqQfQpBky80wix/BCT/W9C b/SVho/NwDTXPlJtQPWQPg0dx0umkbivvLs4Rk7JHoq8CAq97VegYF5Lkd8eBMkSeQkt b7ofewTVpocluqyAo8NpnOgGXPbFXtxG28tSlp3sx74VgXYqJ0Yv6Vcji7k8bCYvNi7A 2i2Q== X-Gm-Message-State: ACgBeo1EMEYveC46Ut8hm4dByNULzUA9qdT6VN58wGrE0jLYgdizpXd6 qCOHHLYEncZdVp9eylWWFLHFUsZ4mDy6zxZK X-Google-Smtp-Source: AA6agR5QRSKKrCbswt1zovTBqhdA8PXPxDbAVUfpKugvgsbvDfODxIOI84Vl/249iYt6t0GkY/8seA== X-Received: by 2002:a05:600c:6025:b0:3b4:8c0c:f3c9 with SMTP id az37-20020a05600c602500b003b48c0cf3c9mr3073809wmb.206.1663161791946; Wed, 14 Sep 2022 06:23:11 -0700 (PDT) Received: from stoup.. ([89.101.193.70]) by smtp.gmail.com with ESMTPSA id p15-20020a5d48cf000000b00226dedf1ab7sm13768244wrs.76.2022.09.14.06.23.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Sep 2022 06:23:11 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 01/11] target/nios2: Use semihosting/syscalls.h Date: Wed, 14 Sep 2022 14:22:58 +0100 Message-Id: <20220914132308.118495-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220914132308.118495-1-richard.henderson@linaro.org> References: <20220914132308.118495-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32a; envelope-from=richard.henderson@linaro.org; helo=mail-wm1-x32a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" This separates guest file descriptors from host file descriptors, and utilizes shared infrastructure for integration with gdbstub. Signed-off-by: Richard Henderson --- target/nios2/nios2-semi.c | 296 +++++++------------------------------- 1 file changed, 50 insertions(+), 246 deletions(-) diff --git a/target/nios2/nios2-semi.c b/target/nios2/nios2-semi.c index 55061bb2dc..614fd76695 100644 --- a/target/nios2/nios2-semi.c +++ b/target/nios2/nios2-semi.c @@ -24,6 +24,7 @@ #include "qemu/osdep.h" #include "cpu.h" #include "exec/gdbstub.h" +#include "semihosting/syscalls.h" #include "semihosting/softmmu-uaccess.h" #include "qemu/log.h" @@ -42,67 +43,6 @@ #define HOSTED_ISATTY 12 #define HOSTED_SYSTEM 13 -static int translate_openflags(int flags) -{ - int hf; - - if (flags & GDB_O_WRONLY) { - hf = O_WRONLY; - } else if (flags & GDB_O_RDWR) { - hf = O_RDWR; - } else { - hf = O_RDONLY; - } - - if (flags & GDB_O_APPEND) { - hf |= O_APPEND; - } - if (flags & GDB_O_CREAT) { - hf |= O_CREAT; - } - if (flags & GDB_O_TRUNC) { - hf |= O_TRUNC; - } - if (flags & GDB_O_EXCL) { - hf |= O_EXCL; - } - - return hf; -} - -static bool translate_stat(CPUNios2State *env, target_ulong addr, - struct stat *s) -{ - struct gdb_stat *p; - - p = lock_user(VERIFY_WRITE, addr, sizeof(struct gdb_stat), 0); - - if (!p) { - return false; - } - p->gdb_st_dev = cpu_to_be32(s->st_dev); - p->gdb_st_ino = cpu_to_be32(s->st_ino); - p->gdb_st_mode = cpu_to_be32(s->st_mode); - p->gdb_st_nlink = cpu_to_be32(s->st_nlink); - p->gdb_st_uid = cpu_to_be32(s->st_uid); - p->gdb_st_gid = cpu_to_be32(s->st_gid); - p->gdb_st_rdev = cpu_to_be32(s->st_rdev); - p->gdb_st_size = cpu_to_be64(s->st_size); -#ifdef _WIN32 - /* Windows stat is missing some fields. */ - p->gdb_st_blksize = 0; - p->gdb_st_blocks = 0; -#else - p->gdb_st_blksize = cpu_to_be64(s->st_blksize); - p->gdb_st_blocks = cpu_to_be64(s->st_blocks); -#endif - p->gdb_st_atime = cpu_to_be32(s->st_atime); - p->gdb_st_mtime = cpu_to_be32(s->st_mtime); - p->gdb_st_ctime = cpu_to_be32(s->st_ctime); - unlock_user(p, addr, sizeof(struct gdb_stat)); - return true; -} - static void nios2_semi_u32_cb(CPUState *cs, uint64_t ret, int err) { Nios2CPU *cpu = NIOS2_CPU(cs); @@ -142,22 +82,22 @@ static void nios2_semi_u64_cb(CPUState *cs, uint64_t ret, int err) */ #define GET_ARG(n) do { \ if (get_user_ual(arg ## n, args + (n) * 4)) { \ - result = -1; \ - errno = EFAULT; \ goto failed; \ } \ } while (0) +#define GET_ARG64(n) do { \ + if (get_user_ual(arg ## n, args + (n) * 4)) { \ + goto failed64; \ + } \ +} while (0) + void do_nios2_semihosting(CPUNios2State *env) { CPUState *cs = env_cpu(env); int nr; uint32_t args; target_ulong arg0, arg1, arg2, arg3; - void *p; - void *q; - uint32_t len; - uint32_t result; nr = env->regs[R_ARG0]; args = env->regs[R_ARG1]; @@ -165,234 +105,98 @@ void do_nios2_semihosting(CPUNios2State *env) case HOSTED_EXIT: gdb_exit(env->regs[R_ARG0]); exit(env->regs[R_ARG0]); + case HOSTED_OPEN: GET_ARG(0); GET_ARG(1); GET_ARG(2); GET_ARG(3); - if (use_gdb_syscalls()) { - gdb_do_syscall(nios2_semi_u32_cb, "open,%s,%x,%x", arg0, (int)arg1, - arg2, arg3); - return; - } else { - p = lock_user_string(arg0); - if (!p) { - result = -1; - errno = EFAULT; - } else { - result = open(p, translate_openflags(arg2), arg3); - unlock_user(p, arg0, 0); - } - } + semihost_sys_open(cs, nios2_semi_u32_cb, arg0, arg1, arg2, arg3); break; + case HOSTED_CLOSE: - { - /* Ignore attempts to close stdin/out/err. */ - GET_ARG(0); - int fd = arg0; - if (fd > 2) { - if (use_gdb_syscalls()) { - gdb_do_syscall(nios2_semi_u32_cb, "close,%x", arg0); - return; - } else { - result = close(fd); - } - } else { - result = 0; - } - break; - } + GET_ARG(0); + semihost_sys_close(cs, nios2_semi_u32_cb, arg0); + break; + case HOSTED_READ: GET_ARG(0); GET_ARG(1); GET_ARG(2); - len = arg2; - if (use_gdb_syscalls()) { - gdb_do_syscall(nios2_semi_u32_cb, "read,%x,%x,%x", - arg0, arg1, len); - return; - } else { - p = lock_user(VERIFY_WRITE, arg1, len, 0); - if (!p) { - result = -1; - errno = EFAULT; - } else { - result = read(arg0, p, len); - unlock_user(p, arg1, len); - } - } + semihost_sys_read(cs, nios2_semi_u32_cb, arg0, arg1, arg2); break; + case HOSTED_WRITE: GET_ARG(0); GET_ARG(1); GET_ARG(2); - len = arg2; - if (use_gdb_syscalls()) { - gdb_do_syscall(nios2_semi_u32_cb, "write,%x,%x,%x", - arg0, arg1, len); - return; - } else { - p = lock_user(VERIFY_READ, arg1, len, 1); - if (!p) { - result = -1; - errno = EFAULT; - } else { - result = write(arg0, p, len); - unlock_user(p, arg0, 0); - } - } + semihost_sys_write(cs, nios2_semi_u32_cb, arg0, arg1, arg2); break; + case HOSTED_LSEEK: - { - uint64_t off; - GET_ARG(0); - GET_ARG(1); - GET_ARG(2); - GET_ARG(3); - off = (uint32_t)arg2 | ((uint64_t)arg1 << 32); - if (use_gdb_syscalls()) { - gdb_do_syscall(nios2_semi_u64_cb, "lseek,%x,%lx,%x", - arg0, off, arg3); - } else { - off = lseek(arg0, off, arg3); - nios2_semi_u64_cb(cs, off, errno); - } - return; - } + GET_ARG64(0); + GET_ARG64(1); + GET_ARG64(2); + GET_ARG64(3); + semihost_sys_lseek(cs, nios2_semi_u64_cb, arg0, + deposit64(arg2, arg1, 32, 32), arg3); + break; + case HOSTED_RENAME: GET_ARG(0); GET_ARG(1); GET_ARG(2); GET_ARG(3); - if (use_gdb_syscalls()) { - gdb_do_syscall(nios2_semi_u32_cb, "rename,%s,%s", - arg0, (int)arg1, arg2, (int)arg3); - return; - } else { - p = lock_user_string(arg0); - q = lock_user_string(arg2); - if (!p || !q) { - result = -1; - errno = EFAULT; - } else { - result = rename(p, q); - } - unlock_user(p, arg0, 0); - unlock_user(q, arg2, 0); - } + semihost_sys_rename(cs, nios2_semi_u32_cb, arg0, arg1, arg2, arg3); break; + case HOSTED_UNLINK: GET_ARG(0); GET_ARG(1); - if (use_gdb_syscalls()) { - gdb_do_syscall(nios2_semi_u32_cb, "unlink,%s", - arg0, (int)arg1); - return; - } else { - p = lock_user_string(arg0); - if (!p) { - result = -1; - errno = EFAULT; - } else { - result = unlink(p); - unlock_user(p, arg0, 0); - } - } + semihost_sys_remove(cs, nios2_semi_u32_cb, arg0, arg1); break; + case HOSTED_STAT: GET_ARG(0); GET_ARG(1); GET_ARG(2); - if (use_gdb_syscalls()) { - gdb_do_syscall(nios2_semi_u32_cb, "stat,%s,%x", - arg0, (int)arg1, arg2); - return; - } else { - struct stat s; - p = lock_user_string(arg0); - if (!p) { - result = -1; - errno = EFAULT; - } else { - result = stat(p, &s); - unlock_user(p, arg0, 0); - } - if (result == 0 && !translate_stat(env, arg2, &s)) { - result = -1; - errno = EFAULT; - } - } + semihost_sys_stat(cs, nios2_semi_u32_cb, arg0, arg1, arg2); break; + case HOSTED_FSTAT: GET_ARG(0); GET_ARG(1); - if (use_gdb_syscalls()) { - gdb_do_syscall(nios2_semi_u32_cb, "fstat,%x,%x", - arg0, arg1); - return; - } else { - struct stat s; - result = fstat(arg0, &s); - if (result == 0 && !translate_stat(env, arg1, &s)) { - result = -1; - errno = EFAULT; - } - } + semihost_sys_fstat(cs, nios2_semi_u32_cb, arg0, arg1); break; + case HOSTED_GETTIMEOFDAY: - /* Only the tv parameter is used. tz is assumed NULL. */ GET_ARG(0); - if (use_gdb_syscalls()) { - gdb_do_syscall(nios2_semi_u32_cb, "gettimeofday,%x,%x", - arg0, 0); - return; - } else { - struct gdb_timeval *p; - int64_t rt = g_get_real_time(); - p = lock_user(VERIFY_WRITE, arg0, sizeof(struct gdb_timeval), 0); - if (!p) { - result = -1; - errno = EFAULT; - } else { - result = 0; - p->tv_sec = cpu_to_be32(rt / G_USEC_PER_SEC); - p->tv_usec = cpu_to_be64(rt % G_USEC_PER_SEC); - unlock_user(p, arg0, sizeof(struct gdb_timeval)); - } - } + GET_ARG(1); + semihost_sys_gettimeofday(cs, nios2_semi_u32_cb, arg0, arg1); break; + case HOSTED_ISATTY: GET_ARG(0); - if (use_gdb_syscalls()) { - gdb_do_syscall(nios2_semi_u32_cb, "isatty,%x", arg0); - return; - } else { - result = isatty(arg0); - } + semihost_sys_isatty(cs, nios2_semi_u32_cb, arg0); break; + case HOSTED_SYSTEM: GET_ARG(0); GET_ARG(1); - if (use_gdb_syscalls()) { - gdb_do_syscall(nios2_semi_u32_cb, "system,%s", - arg0, (int)arg1); - return; - } else { - p = lock_user_string(arg0); - if (!p) { - result = -1; - errno = EFAULT; - } else { - result = system(p); - unlock_user(p, arg0, 0); - } - } + semihost_sys_system(cs, nios2_semi_u32_cb, arg0, arg1); break; + default: qemu_log_mask(LOG_GUEST_ERROR, "nios2-semihosting: unsupported " "semihosting syscall %d\n", nr); - result = 0; + nios2_semi_u32_cb(cs, -1, ENOSYS); + break; + + failed: + nios2_semi_u32_cb(cs, -1, EFAULT); + break; + failed64: + nios2_semi_u64_cb(cs, -1, EFAULT); + break; } -failed: - nios2_semi_u32_cb(cs, result, errno); } From patchwork Wed Sep 14 13:22:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 1677909 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=jvpEOt99; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MSMlL0Q1Tz1ynm for ; Thu, 15 Sep 2022 00:14:04 +1000 (AEST) Received: from localhost ([::1]:46060 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oYT9N-0005OZ-9n for incoming@patchwork.ozlabs.org; Wed, 14 Sep 2022 10:14:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48356) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oYSMF-0007sP-QV for qemu-devel@nongnu.org; Wed, 14 Sep 2022 09:23:15 -0400 Received: from mail-wr1-x431.google.com ([2a00:1450:4864:20::431]:34397) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oYSME-0000aW-5k for qemu-devel@nongnu.org; Wed, 14 Sep 2022 09:23:15 -0400 Received: by mail-wr1-x431.google.com with SMTP id bo13so9176147wrb.1 for ; Wed, 14 Sep 2022 06:23:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date; bh=KfQlb4Kf/qCPlICOyHg/LYLEi3mUvRQuhI0h+42sfkk=; b=jvpEOt99C5m7h8E77uvE264WK2oedEd/sTUfW1MGIytU3fVdm0OmRrk9OTNR+Gu7x5 A11Kp32L354S7DWiCPrTEcHHAjwPXhsC9ffZzVMSvWwTaUqeupujsu7CLc09xKBlRZma vCGlQIHKPkntz5BvA0o3txCvgzvLqYhfZBrn2CkBoYSTHnoEj49F2zz1zWPRxFjim14N sHT1pjJuYFWA4faZG6tltGd8JmIR8ADODoiWPdszQX1kVShXSCKqIH9iTgc3E0fqI8o/ w+0FqeDBsgy2fuYhH52BR8+lWXlmA9M75Z50OH6J52VWafB6VKVogiU9E5tNpHoGyicG G9PA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date; bh=KfQlb4Kf/qCPlICOyHg/LYLEi3mUvRQuhI0h+42sfkk=; b=2W+zXrrOA486BebAP9gKsKIJYiY2TiyZwPB+hflGt2nHWCTvoGLxw313enKsKqrnZg ZHF1xD5Gpn1Ybu/6jhwu0aljjNKvFMQr4b4ZwlEJnCn5w9E1kGH/6c7qYwyi3dG8D4CY Jm3owfD40hnx7CThb2YX0Au/aE0T4nKXlCD3dX9t4e8nDz8S5t+gDvLmvAgo3C4Zi2L3 WfznuVXj2CtL5wQ9zj/+gNmxE7WV0dK6Ni161L+FBWv8pItsaaBEjnlAgpWUnPARo5Rt 3u2SzfIGlbvjkRyjzmlbhvUbje6gTjP1mj/wmPcpiElBdfw+pQ2k14pP1qd2ECVnaaAw cG2w== X-Gm-Message-State: ACgBeo0nRINrnlIwdIHZYi/CJwpqHXNh0SIynjz2IDWpWcJtZK+CL2U3 eG6QcqKn22WF+kfKZ1aoQoP9RPaCpRG4goW1 X-Google-Smtp-Source: AA6agR72m3jlsihLrj7xQyZiGIkPWhTy0S+uP2+T0jTsJq/75nbuWTjmUlMkthV9m8epXo3hOpw/+Q== X-Received: by 2002:a05:6000:1189:b0:228:62c7:7e6c with SMTP id g9-20020a056000118900b0022862c77e6cmr22490110wrx.716.1663161792683; Wed, 14 Sep 2022 06:23:12 -0700 (PDT) Received: from stoup.. ([89.101.193.70]) by smtp.gmail.com with ESMTPSA id p15-20020a5d48cf000000b00226dedf1ab7sm13768244wrs.76.2022.09.14.06.23.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Sep 2022 06:23:12 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 02/11] target/nios2: Convert semihosting errno to gdb remote errno Date: Wed, 14 Sep 2022 14:22:59 +0100 Message-Id: <20220914132308.118495-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220914132308.118495-1-richard.henderson@linaro.org> References: <20220914132308.118495-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::431; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x431.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" The semihosting abi used by nios2 uses the gdb remote protocol filesys errnos. Signed-off-by: Richard Henderson --- target/nios2/nios2-semi.c | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/target/nios2/nios2-semi.c b/target/nios2/nios2-semi.c index 614fd76695..f76e8588c5 100644 --- a/target/nios2/nios2-semi.c +++ b/target/nios2/nios2-semi.c @@ -43,6 +43,35 @@ #define HOSTED_ISATTY 12 #define HOSTED_SYSTEM 13 +static int host_to_gdb_errno(int err) +{ +#define E(X) case E##X: return GDB_E##X + switch (err) { + E(PERM); + E(NOENT); + E(INTR); + E(BADF); + E(ACCES); + E(FAULT); + E(BUSY); + E(EXIST); + E(NODEV); + E(NOTDIR); + E(ISDIR); + E(INVAL); + E(NFILE); + E(MFILE); + E(FBIG); + E(NOSPC); + E(SPIPE); + E(ROFS); + E(NAMETOOLONG); + default: + return GDB_EUNKNOWN; + } +#undef E +} + static void nios2_semi_u32_cb(CPUState *cs, uint64_t ret, int err) { Nios2CPU *cpu = NIOS2_CPU(cs); @@ -50,7 +79,7 @@ static void nios2_semi_u32_cb(CPUState *cs, uint64_t ret, int err) target_ulong args = env->regs[R_ARG1]; if (put_user_u32(ret, args) || - put_user_u32(err, args + 4)) { + put_user_u32(host_to_gdb_errno(err), args + 4)) { /* * The nios2 semihosting ABI does not provide any way to report this * error to the guest, so the best we can do is log it in qemu. @@ -69,7 +98,7 @@ static void nios2_semi_u64_cb(CPUState *cs, uint64_t ret, int err) if (put_user_u32(ret >> 32, args) || put_user_u32(ret, args + 4) || - put_user_u32(err, args + 8)) { + put_user_u32(host_to_gdb_errno(err), args + 8)) { /* No way to report this via nios2 semihosting ABI; just log it */ qemu_log_mask(LOG_GUEST_ERROR, "nios2-semihosting: return value " "discarded because argument block not writable\n"); From patchwork Wed Sep 14 13:23:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 1677912 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=JAI6LLO9; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MSMr70RLvz1yhR for ; Thu, 15 Sep 2022 00:18:15 +1000 (AEST) Received: from localhost ([::1]:36142 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oYTDR-0002Qr-0d for incoming@patchwork.ozlabs.org; Wed, 14 Sep 2022 10:18:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48358) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oYSMH-0007yb-PD for qemu-devel@nongnu.org; Wed, 14 Sep 2022 09:23:18 -0400 Received: from mail-wr1-x42e.google.com ([2a00:1450:4864:20::42e]:39581) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oYSMF-0000ae-4J for qemu-devel@nongnu.org; Wed, 14 Sep 2022 09:23:17 -0400 Received: by mail-wr1-x42e.google.com with SMTP id cc5so15852355wrb.6 for ; Wed, 14 Sep 2022 06:23:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=114N/Vlw3BZhk8rKh2FZz62XHFpOWPD/xYj4W6zefEA=; b=JAI6LLO9gfSPwV899uaVNQqAjn+qp13msvQgi7uP4XXSl4eEJadnaCz1g1UU2Mv5r8 IT95ll3eAIq98U+W2pCrXoSJ/94DCJ5DmWuAKVhQCjo7iCflkG1wr0Gf3UMncwhnAYov WQHMSPurfEP46KCPYgpgG8ucZpYF6+PPKJ6iqg2sriEod7UxdQTVjrNBCWy9vGFcQSVO RpXw33WWmxgJpelDcHIQ4hZhro0ppc9cbkMBb7tQOpwlSd1on3NX8AneVFmiAE6x81CI 0HsyoR9vzdW6UdyYv0JpWthAqgotkVKzv5WiwMcjHetvHQsFHJ27BAp6ONdB9hubUj/O OGFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=114N/Vlw3BZhk8rKh2FZz62XHFpOWPD/xYj4W6zefEA=; b=u4aoLM/iqPHwIWD3PiDjhmRu6YNBijhWpb1uwFXqQagfnGXUXTZKMWNN+PN6LO1AwK QuGpY/ugU/vja/1Xi3RCrrvds0b0FjlpUqv/+QwgDJeAqa7H6D/KMYu23iUaxHuZBM/P kJ6A/9CER0FNfOgaORfUTVt02AYPv/iaaZXs0p0eB35eIthmV3yqOuh0K6JTS+1gtad0 CWv/rBaRaxbxda2KsrM/gsqY0ENYwJlmplRWts8n0jhk/H6sdj9IDwm7j6+nKlmi6vK1 9WD8w+8QHf/Im3b9ICDt78oYDT2K0j3+aHdwvVnHHw5q/Qnse9YG+rqNyGDc0UjxJVgt quqg== X-Gm-Message-State: ACgBeo2+em4COY8NqouSAmTX2CsL9IsXY9J1VJuMPVOFZ7ggdqCj1cCs 4IyBwZfPIchuT/XaY6YKE0Lv/ZTc6ICKPwxZ X-Google-Smtp-Source: AA6agR7tcWsSwXkomi9XDAM/ej7jDu28w6ghqhj87MTAXnJw/dNBB0Q78MUuKH6bpKvUKB8tAZ+b1Q== X-Received: by 2002:adf:f2c9:0:b0:228:63f6:73c2 with SMTP id d9-20020adff2c9000000b0022863f673c2mr21484366wrp.554.1663161793582; Wed, 14 Sep 2022 06:23:13 -0700 (PDT) Received: from stoup.. ([89.101.193.70]) by smtp.gmail.com with ESMTPSA id p15-20020a5d48cf000000b00226dedf1ab7sm13768244wrs.76.2022.09.14.06.23.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Sep 2022 06:23:13 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Laurent Vivier Subject: [PULL 03/11] target/m68k: Use semihosting/syscalls.h Date: Wed, 14 Sep 2022 14:23:00 +0100 Message-Id: <20220914132308.118495-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220914132308.118495-1-richard.henderson@linaro.org> References: <20220914132308.118495-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42e; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x42e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" This separates guest file descriptors from host file descriptors, and utilizes shared infrastructure for integration with gdbstub. Acked-by: Laurent Vivier Signed-off-by: Richard Henderson --- target/m68k/m68k-semi.c | 281 +++++++--------------------------------- 1 file changed, 49 insertions(+), 232 deletions(-) diff --git a/target/m68k/m68k-semi.c b/target/m68k/m68k-semi.c index d0697ddbd1..586a801034 100644 --- a/target/m68k/m68k-semi.c +++ b/target/m68k/m68k-semi.c @@ -21,6 +21,7 @@ #include "cpu.h" #include "exec/gdbstub.h" +#include "semihosting/syscalls.h" #include "semihosting/softmmu-uaccess.h" #include "hw/boards.h" #include "qemu/log.h" @@ -40,56 +41,6 @@ #define HOSTED_ISATTY 12 #define HOSTED_SYSTEM 13 -static int translate_openflags(int flags) -{ - int hf; - - if (flags & GDB_O_WRONLY) - hf = O_WRONLY; - else if (flags & GDB_O_RDWR) - hf = O_RDWR; - else - hf = O_RDONLY; - - if (flags & GDB_O_APPEND) hf |= O_APPEND; - if (flags & GDB_O_CREAT) hf |= O_CREAT; - if (flags & GDB_O_TRUNC) hf |= O_TRUNC; - if (flags & GDB_O_EXCL) hf |= O_EXCL; - - return hf; -} - -static void translate_stat(CPUM68KState *env, target_ulong addr, struct stat *s) -{ - struct gdb_stat *p; - - p = lock_user(VERIFY_WRITE, addr, sizeof(struct gdb_stat), 0); - if (!p) { - /* FIXME - should this return an error code? */ - return; - } - p->gdb_st_dev = cpu_to_be32(s->st_dev); - p->gdb_st_ino = cpu_to_be32(s->st_ino); - p->gdb_st_mode = cpu_to_be32(s->st_mode); - p->gdb_st_nlink = cpu_to_be32(s->st_nlink); - p->gdb_st_uid = cpu_to_be32(s->st_uid); - p->gdb_st_gid = cpu_to_be32(s->st_gid); - p->gdb_st_rdev = cpu_to_be32(s->st_rdev); - p->gdb_st_size = cpu_to_be64(s->st_size); -#ifdef _WIN32 - /* Windows stat is missing some fields. */ - p->gdb_st_blksize = 0; - p->gdb_st_blocks = 0; -#else - p->gdb_st_blksize = cpu_to_be64(s->st_blksize); - p->gdb_st_blocks = cpu_to_be64(s->st_blocks); -#endif - p->gdb_st_atime = cpu_to_be32(s->st_atime); - p->gdb_st_mtime = cpu_to_be32(s->st_mtime); - p->gdb_st_ctime = cpu_to_be32(s->st_ctime); - unlock_user(p, addr, sizeof(struct gdb_stat)); -} - static void m68k_semi_u32_cb(CPUState *cs, uint64_t ret, int err) { M68kCPU *cpu = M68K_CPU(cs); @@ -129,248 +80,109 @@ static void m68k_semi_u64_cb(CPUState *cs, uint64_t ret, int err) */ #define GET_ARG(n) do { \ if (get_user_ual(arg ## n, args + (n) * 4)) { \ - result = -1; \ - errno = EFAULT; \ goto failed; \ } \ } while (0) +#define GET_ARG64(n) do { \ + if (get_user_ual(arg ## n, args + (n) * 4)) { \ + goto failed64; \ + } \ +} while (0) + + void do_m68k_semihosting(CPUM68KState *env, int nr) { CPUState *cs = env_cpu(env); uint32_t args; target_ulong arg0, arg1, arg2, arg3; - void *p; - void *q; - uint32_t len; - uint32_t result; args = env->dregs[1]; switch (nr) { case HOSTED_EXIT: gdb_exit(env->dregs[0]); exit(env->dregs[0]); + case HOSTED_OPEN: GET_ARG(0); GET_ARG(1); GET_ARG(2); GET_ARG(3); - if (use_gdb_syscalls()) { - gdb_do_syscall(m68k_semi_u32_cb, "open,%s,%x,%x", arg0, (int)arg1, - arg2, arg3); - return; - } else { - p = lock_user_string(arg0); - if (!p) { - /* FIXME - check error code? */ - result = -1; - } else { - result = open(p, translate_openflags(arg2), arg3); - unlock_user(p, arg0, 0); - } - } + semihost_sys_open(cs, m68k_semi_u32_cb, arg0, arg1, arg2, arg3); break; + case HOSTED_CLOSE: - { - /* Ignore attempts to close stdin/out/err. */ - GET_ARG(0); - int fd = arg0; - if (fd > 2) { - if (use_gdb_syscalls()) { - gdb_do_syscall(m68k_semi_u32_cb, "close,%x", arg0); - return; - } else { - result = close(fd); - } - } else { - result = 0; - } - break; - } + GET_ARG(0); + semihost_sys_close(cs, m68k_semi_u32_cb, arg0); + break; + case HOSTED_READ: GET_ARG(0); GET_ARG(1); GET_ARG(2); - len = arg2; - if (use_gdb_syscalls()) { - gdb_do_syscall(m68k_semi_u32_cb, "read,%x,%x,%x", - arg0, arg1, len); - return; - } else { - p = lock_user(VERIFY_WRITE, arg1, len, 0); - if (!p) { - /* FIXME - check error code? */ - result = -1; - } else { - result = read(arg0, p, len); - unlock_user(p, arg1, len); - } - } + semihost_sys_read(cs, m68k_semi_u32_cb, arg0, arg1, arg2); break; + case HOSTED_WRITE: GET_ARG(0); GET_ARG(1); GET_ARG(2); - len = arg2; - if (use_gdb_syscalls()) { - gdb_do_syscall(m68k_semi_u32_cb, "write,%x,%x,%x", - arg0, arg1, len); - return; - } else { - p = lock_user(VERIFY_READ, arg1, len, 1); - if (!p) { - /* FIXME - check error code? */ - result = -1; - } else { - result = write(arg0, p, len); - unlock_user(p, arg0, 0); - } - } + semihost_sys_write(cs, m68k_semi_u32_cb, arg0, arg1, arg2); break; + case HOSTED_LSEEK: - { - uint64_t off; - GET_ARG(0); - GET_ARG(1); - GET_ARG(2); - GET_ARG(3); - off = (uint32_t)arg2 | ((uint64_t)arg1 << 32); - if (use_gdb_syscalls()) { - gdb_do_syscall(m68k_semi_u64_cb, "fseek,%x,%lx,%x", - arg0, off, arg3); - } else { - off = lseek(arg0, off, arg3); - m68k_semi_u64_cb(cs, off, errno); - } - return; - } + GET_ARG64(0); + GET_ARG64(1); + GET_ARG64(2); + GET_ARG64(3); + semihost_sys_lseek(cs, m68k_semi_u64_cb, arg0, + deposit64(arg2, arg1, 32, 32), arg3); + break; + case HOSTED_RENAME: GET_ARG(0); GET_ARG(1); GET_ARG(2); GET_ARG(3); - if (use_gdb_syscalls()) { - gdb_do_syscall(m68k_semi_u32_cb, "rename,%s,%s", - arg0, (int)arg1, arg2, (int)arg3); - return; - } else { - p = lock_user_string(arg0); - q = lock_user_string(arg2); - if (!p || !q) { - /* FIXME - check error code? */ - result = -1; - } else { - result = rename(p, q); - } - unlock_user(p, arg0, 0); - unlock_user(q, arg2, 0); - } + semihost_sys_rename(cs, m68k_semi_u32_cb, arg0, arg1, arg2, arg3); break; + case HOSTED_UNLINK: GET_ARG(0); GET_ARG(1); - if (use_gdb_syscalls()) { - gdb_do_syscall(m68k_semi_u32_cb, "unlink,%s", - arg0, (int)arg1); - return; - } else { - p = lock_user_string(arg0); - if (!p) { - /* FIXME - check error code? */ - result = -1; - } else { - result = unlink(p); - unlock_user(p, arg0, 0); - } - } + semihost_sys_remove(cs, m68k_semi_u32_cb, arg0, arg1); break; + case HOSTED_STAT: GET_ARG(0); GET_ARG(1); GET_ARG(2); - if (use_gdb_syscalls()) { - gdb_do_syscall(m68k_semi_u32_cb, "stat,%s,%x", - arg0, (int)arg1, arg2); - return; - } else { - struct stat s; - p = lock_user_string(arg0); - if (!p) { - /* FIXME - check error code? */ - result = -1; - } else { - result = stat(p, &s); - unlock_user(p, arg0, 0); - } - if (result == 0) { - translate_stat(env, arg2, &s); - } - } + semihost_sys_stat(cs, m68k_semi_u32_cb, arg0, arg1, arg2); break; + case HOSTED_FSTAT: GET_ARG(0); GET_ARG(1); - if (use_gdb_syscalls()) { - gdb_do_syscall(m68k_semi_u32_cb, "fstat,%x,%x", - arg0, arg1); - return; - } else { - struct stat s; - result = fstat(arg0, &s); - if (result == 0) { - translate_stat(env, arg1, &s); - } - } + semihost_sys_fstat(cs, m68k_semi_u32_cb, arg0, arg1); break; + case HOSTED_GETTIMEOFDAY: GET_ARG(0); GET_ARG(1); - if (use_gdb_syscalls()) { - gdb_do_syscall(m68k_semi_u32_cb, "gettimeofday,%x,%x", - arg0, arg1); - return; - } else { - struct gdb_timeval *p; - int64_t rt = g_get_real_time(); - p = lock_user(VERIFY_WRITE, arg0, sizeof(struct gdb_timeval), 0); - if (!p) { - /* FIXME - check error code? */ - result = -1; - } else { - result = 0; - p->tv_sec = cpu_to_be32(rt / G_USEC_PER_SEC); - p->tv_usec = cpu_to_be64(rt % G_USEC_PER_SEC); - unlock_user(p, arg0, sizeof(struct gdb_timeval)); - } - } + semihost_sys_gettimeofday(cs, m68k_semi_u32_cb, arg0, arg1); break; + case HOSTED_ISATTY: GET_ARG(0); - if (use_gdb_syscalls()) { - gdb_do_syscall(m68k_semi_u32_cb, "isatty,%x", arg0); - return; - } else { - result = isatty(arg0); - } + semihost_sys_isatty(cs, m68k_semi_u32_cb, arg0); break; + case HOSTED_SYSTEM: GET_ARG(0); GET_ARG(1); - if (use_gdb_syscalls()) { - gdb_do_syscall(m68k_semi_u32_cb, "system,%s", - arg0, (int)arg1); - return; - } else { - p = lock_user_string(arg0); - if (!p) { - /* FIXME - check error code? */ - result = -1; - } else { - result = system(p); - unlock_user(p, arg0, 0); - } - } + semihost_sys_system(cs, m68k_semi_u32_cb, arg0, arg1); break; + case HOSTED_INIT_SIM: /* * FIXME: This is wrong for boards where RAM does not start at @@ -379,10 +191,15 @@ void do_m68k_semihosting(CPUM68KState *env, int nr) env->dregs[1] = current_machine->ram_size; env->aregs[7] = current_machine->ram_size; return; + default: cpu_abort(env_cpu(env), "Unsupported semihosting syscall %d\n", nr); - result = 0; + + failed: + m68k_semi_u32_cb(cs, -1, EFAULT); + break; + failed64: + m68k_semi_u64_cb(cs, -1, EFAULT); + break; } -failed: - m68k_semi_u32_cb(cs, result, errno); } From patchwork Wed Sep 14 13:23:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 1677878 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=qvLhzmQ0; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MSLz70gcfz1yhR for ; Wed, 14 Sep 2022 23:39:15 +1000 (AEST) Received: from localhost ([::1]:47100 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oYSbg-0007AU-KT for incoming@patchwork.ozlabs.org; Wed, 14 Sep 2022 09:39:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48360) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oYSMH-0007zE-PD for qemu-devel@nongnu.org; Wed, 14 Sep 2022 09:23:18 -0400 Received: from mail-wr1-x431.google.com ([2a00:1450:4864:20::431]:45970) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oYSMG-0000an-3y for qemu-devel@nongnu.org; Wed, 14 Sep 2022 09:23:17 -0400 Received: by mail-wr1-x431.google.com with SMTP id bj14so25650939wrb.12 for ; Wed, 14 Sep 2022 06:23:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=C+e+mVoscBWQrZpSL5BUOyirKvbRFo9Wu/wSgD1UkkU=; b=qvLhzmQ0Bb6I8ahjOwVaUusGAhHQ1kLqQ32dBJty4R/nVYVrHWsLKlD+icT3/nfUzr /bhQNcT/7ySLQaON3jnjDWIUlx8V/XwrZ3xN7O1e7DT7UmBvw0+DCQCIFX0tqU84RP3A ZKGnjl1K64QN60W341krE8gP3JCIIpG8YqigCdu8cdDfBmpivfuniuBKQPUS+bco2uUx xu5r8URtQA+YwYNN5JA6f+e7iMzmBwmYKb7wuDigS3abCAb0DRiIvZKtzHT40IMLzMK5 RMG4dX2H6PpuOCXh5G14mUhdvig0e1aeHEMUEZNmKiXHYWNadOpCHTUxhf5Evujsp8P6 +UAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=C+e+mVoscBWQrZpSL5BUOyirKvbRFo9Wu/wSgD1UkkU=; b=D0aseul52V3qJ92QDmwqXdBiy0FDTsGGxd1DJ2+O/wMzRbJPHHz9ZP+SO0H1aq4sAg oJRxI09bcvcSfCZHOoWNgzku53ewD4fXVtXljocaKZ94uR7x1H3sVdbw9bl93QRxyIhK orE3/zlRHicDTY9hklneFGScZD6DHQDmhI3NNrSfkI+Qy6uIa/AkWjWu/VWwWSUQLVcK 7rlyLMcBj3vremdFqgoXTfXEG4goSIApn2jfHgcLYiGP1D8myo+NKNhzNMRWMt5BaKCx sBLqsZYHzyV3sdVOTJSwVgw6xuZ2TiilCRZhThT7reEaj9Un/Yz27I0HbKJwv8NIsDnF bweQ== X-Gm-Message-State: ACgBeo294P7uaEcSbpK4PCwQn2ab3+vQH9n6kQsQIfuxX+NyrfStVyGl 9HJVBfU3WvqFlsUgQSVdfnXCryAWDtguGLQQ X-Google-Smtp-Source: AA6agR70dk1sYcyIodiTOkJA9br9W6Ddm7cn615wz+9gwSn0qq9V3gRfKp5nDiu/kI7nDlJPVMZOGQ== X-Received: by 2002:a05:6000:508:b0:22a:c5fd:1334 with SMTP id a8-20020a056000050800b0022ac5fd1334mr2574841wrf.636.1663161794432; Wed, 14 Sep 2022 06:23:14 -0700 (PDT) Received: from stoup.. ([89.101.193.70]) by smtp.gmail.com with ESMTPSA id p15-20020a5d48cf000000b00226dedf1ab7sm13768244wrs.76.2022.09.14.06.23.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Sep 2022 06:23:14 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Laurent Vivier Subject: [PULL 04/11] target/m68k: Convert semihosting errno to gdb remote errno Date: Wed, 14 Sep 2022 14:23:01 +0100 Message-Id: <20220914132308.118495-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220914132308.118495-1-richard.henderson@linaro.org> References: <20220914132308.118495-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::431; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x431.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" The semihosting abi used by m68k uses the gdb remote protocol filesys errnos. Acked-by: Laurent Vivier Signed-off-by: Richard Henderson --- target/m68k/m68k-semi.c | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/target/m68k/m68k-semi.c b/target/m68k/m68k-semi.c index 586a801034..87b1314925 100644 --- a/target/m68k/m68k-semi.c +++ b/target/m68k/m68k-semi.c @@ -41,6 +41,35 @@ #define HOSTED_ISATTY 12 #define HOSTED_SYSTEM 13 +static int host_to_gdb_errno(int err) +{ +#define E(X) case E##X: return GDB_E##X + switch (err) { + E(PERM); + E(NOENT); + E(INTR); + E(BADF); + E(ACCES); + E(FAULT); + E(BUSY); + E(EXIST); + E(NODEV); + E(NOTDIR); + E(ISDIR); + E(INVAL); + E(NFILE); + E(MFILE); + E(FBIG); + E(NOSPC); + E(SPIPE); + E(ROFS); + E(NAMETOOLONG); + default: + return GDB_EUNKNOWN; + } +#undef E +} + static void m68k_semi_u32_cb(CPUState *cs, uint64_t ret, int err) { M68kCPU *cpu = M68K_CPU(cs); @@ -48,7 +77,7 @@ static void m68k_semi_u32_cb(CPUState *cs, uint64_t ret, int err) target_ulong args = env->dregs[1]; if (put_user_u32(ret, args) || - put_user_u32(err, args + 4)) { + put_user_u32(host_to_gdb_errno(err), args + 4)) { /* * The m68k semihosting ABI does not provide any way to report this * error to the guest, so the best we can do is log it in qemu. @@ -67,7 +96,7 @@ static void m68k_semi_u64_cb(CPUState *cs, uint64_t ret, int err) target_ulong args = env->dregs[1]; if (put_user_u32(ret >> 32, args) || put_user_u32(ret, args + 4) || - put_user_u32(err, args + 8)) { + put_user_u32(host_to_gdb_errno(err), args + 8)) { /* No way to report this via m68k semihosting ABI; just log it */ qemu_log_mask(LOG_GUEST_ERROR, "m68k-semihosting: return value " "discarded because argument block not writable\n"); From patchwork Wed Sep 14 13:23:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 1677880 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=C180wwal; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MSM1W4cj7z1ypW for ; Wed, 14 Sep 2022 23:41:18 +1000 (AEST) Received: from localhost ([::1]:33854 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oYSde-0001Lc-4L for incoming@patchwork.ozlabs.org; Wed, 14 Sep 2022 09:41:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48364) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oYSML-00082w-8a for qemu-devel@nongnu.org; Wed, 14 Sep 2022 09:23:22 -0400 Received: from mail-wm1-x32d.google.com ([2a00:1450:4864:20::32d]:37595) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oYSMH-0000b1-1d for qemu-devel@nongnu.org; Wed, 14 Sep 2022 09:23:19 -0400 Received: by mail-wm1-x32d.google.com with SMTP id c2-20020a1c3502000000b003b2973dafb7so15494799wma.2 for ; Wed, 14 Sep 2022 06:23:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=x+pcPPFHal1ZQJ+2Orzyi/XOmnBS6T266QkUkL9sejs=; b=C180wwalcOZcYIcrbb0PQmbo/AYZJ2OnOP46caGDySCB5QefZL96tV6RDZ2PU8kM8w OCVFq8x0kBAyhG/XkY6kdH2Q18XPlsasc4HhbZB88SbSNybqNf46VQzwuqMS4DKPoCAm mAy0btyRnLU9qlC1mNjyA3cJ9ZtBv+0EMfIsGBHj8nznsXOJj7hT/ewSZ6r2OuJ0ghuc DwHIxEYgL8jNrlCldzI0neCKd0EFaCaK5voek1lf0LqxdZ6P5/RqqhRhU22N/rBak2dO xplDWyMjV0py95J6fcgjAZFzvgsF8z5blQQTAqt3G72ONi3j1QjDwE+mkzR9gvyKYuq9 NvPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=x+pcPPFHal1ZQJ+2Orzyi/XOmnBS6T266QkUkL9sejs=; b=ndvKG1ArmmTO8QNW7XBh2QUQAWM3ExsbC6TBZw1I0+mZZ4GgEdoTh8bDpTioCmuJQd usB2iiAikQGTLC0n/9PFwSsf8FdGAetdFLBBBZD0mIwdHM1pMxhGTiXuviRXHWn3/ORO aHkyrIsuGcIpFIElNaqhmRpRr2tXaJEsAPNH3vrDTu0vLJfA+QFepdFRVwmqulMi9KPQ dGhtQfIohIVldIzdIIeJWtPK4vVb0X+s5lEexHg1ZieLaNQnPHmZqnLVy//kXrqkzm9/ hzPirGpnnYiqbP7Uuvv9UUL48BfBKo8Da46EjJtmLs9B8mhHdogCHrf15W3e/QIf16AO QALw== X-Gm-Message-State: ACgBeo22h46Ag+eCUzR7nSANYed8Z8D/gz6CjYvd5Qq+t3j5f4MNUyRV NiMbFobOvjDbc0u8UOCEWYhygsYCXiM8e7Lw X-Google-Smtp-Source: AA6agR7ANMdQAAKk4rSB2y6UkAz6Ui/Lm6/AmUCcJs3M/ZY9Co79b50JdjZRYa6C/6I2iFKQwbqeXw== X-Received: by 2002:a7b:c7d8:0:b0:3b4:5c41:6a6c with SMTP id z24-20020a7bc7d8000000b003b45c416a6cmr3011211wmk.139.1663161795259; Wed, 14 Sep 2022 06:23:15 -0700 (PDT) Received: from stoup.. ([89.101.193.70]) by smtp.gmail.com with ESMTPSA id p15-20020a5d48cf000000b00226dedf1ab7sm13768244wrs.76.2022.09.14.06.23.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Sep 2022 06:23:14 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Peter Maydell , =?utf-8?q?Alex_Benn=C3=A9e?= , Alistair Francis , =?utf-8?q?Philippe_Mathieu-Dau?= =?utf-8?q?d=C3=A9?= Subject: [PULL 05/11] semihosting: Allow optional use of semihosting from userspace Date: Wed, 14 Sep 2022 14:23:02 +0100 Message-Id: <20220914132308.118495-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220914132308.118495-1-richard.henderson@linaro.org> References: <20220914132308.118495-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32d; envelope-from=richard.henderson@linaro.org; helo=mail-wm1-x32d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Peter Maydell Currently our semihosting implementations generally prohibit use of semihosting calls in system emulation from the guest userspace. This is a very long standing behaviour justified originally "to provide some semblance of security" (since code with access to the semihosting ABI can do things like read and write arbitrary files on the host system). However, it is sometimes useful to be able to run trusted guest code which performs semihosting calls from guest userspace, notably for test code. Add a command line suboption to the existing semihosting-config option group so that you can explicitly opt in to semihosting from guest userspace with -semihosting-config userspace=on (There is no equivalent option for the user-mode emulator, because there by definition all code runs in userspace and has access to semihosting already.) This commit adds the infrastructure for the command line option and adds a bool 'is_user' parameter to the function semihosting_userspace_enabled() that target code can use to check whether it should be permitting the semihosting call for userspace. It mechanically makes all the callsites pass 'false', so they continue checking "is semihosting enabled in general". Subsequent commits will make each target that implements semihosting honour the userspace=on option by passing the correct value and removing whatever "don't do this for userspace" checking they were doing by hand. Signed-off-by: Peter Maydell Acked-by: Alex Bennée Reviewed-by: Alistair Francis Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Richard Henderson Message-Id: <20220822141230.3658237-2-peter.maydell@linaro.org> Signed-off-by: Richard Henderson --- include/semihosting/semihost.h | 10 ++++++++-- semihosting/config.c | 10 ++++++++-- softmmu/vl.c | 2 +- stubs/semihost.c | 2 +- target/arm/translate-a64.c | 2 +- target/arm/translate.c | 6 +++--- target/m68k/op_helper.c | 2 +- target/nios2/translate.c | 2 +- target/xtensa/translate.c | 6 +++--- qemu-options.hx | 11 +++++++++-- 10 files changed, 36 insertions(+), 17 deletions(-) diff --git a/include/semihosting/semihost.h b/include/semihosting/semihost.h index 93a3c21b44..efd2efa25a 100644 --- a/include/semihosting/semihost.h +++ b/include/semihosting/semihost.h @@ -27,7 +27,7 @@ typedef enum SemihostingTarget { } SemihostingTarget; #ifdef CONFIG_USER_ONLY -static inline bool semihosting_enabled(void) +static inline bool semihosting_enabled(bool is_user) { return true; } @@ -52,7 +52,13 @@ static inline const char *semihosting_get_cmdline(void) return NULL; } #else /* !CONFIG_USER_ONLY */ -bool semihosting_enabled(void); +/** + * semihosting_enabled: + * @is_user: true if guest code is in usermode (i.e. not privileged) + * + * Return true if guest code is allowed to make semihosting calls. + */ +bool semihosting_enabled(bool is_user); SemihostingTarget semihosting_get_target(void); const char *semihosting_get_arg(int i); int semihosting_get_argc(void); diff --git a/semihosting/config.c b/semihosting/config.c index e171d4d6bc..89a1759687 100644 --- a/semihosting/config.c +++ b/semihosting/config.c @@ -34,6 +34,9 @@ QemuOptsList qemu_semihosting_config_opts = { { .name = "enable", .type = QEMU_OPT_BOOL, + }, { + .name = "userspace", + .type = QEMU_OPT_BOOL, }, { .name = "target", .type = QEMU_OPT_STRING, @@ -50,6 +53,7 @@ QemuOptsList qemu_semihosting_config_opts = { typedef struct SemihostingConfig { bool enabled; + bool userspace_enabled; SemihostingTarget target; char **argv; int argc; @@ -59,9 +63,9 @@ typedef struct SemihostingConfig { static SemihostingConfig semihosting; static const char *semihost_chardev; -bool semihosting_enabled(void) +bool semihosting_enabled(bool is_user) { - return semihosting.enabled; + return semihosting.enabled && (!is_user || semihosting.userspace_enabled); } SemihostingTarget semihosting_get_target(void) @@ -137,6 +141,8 @@ int qemu_semihosting_config_options(const char *optarg) if (opts != NULL) { semihosting.enabled = qemu_opt_get_bool(opts, "enable", true); + semihosting.userspace_enabled = qemu_opt_get_bool(opts, "userspace", + false); const char *target = qemu_opt_get(opts, "target"); /* setup of chardev is deferred until they are initialised */ semihost_chardev = qemu_opt_get(opts, "chardev"); diff --git a/softmmu/vl.c b/softmmu/vl.c index dea4005e47..263f029a8e 100644 --- a/softmmu/vl.c +++ b/softmmu/vl.c @@ -1822,7 +1822,7 @@ static void qemu_apply_machine_options(QDict *qdict) { object_set_properties_from_keyval(OBJECT(current_machine), qdict, false, &error_fatal); - if (semihosting_enabled() && !semihosting_get_argc()) { + if (semihosting_enabled(false) && !semihosting_get_argc()) { /* fall back to the -kernel/-append */ semihosting_arg_fallback(current_machine->kernel_filename, current_machine->kernel_cmdline); } diff --git a/stubs/semihost.c b/stubs/semihost.c index f486651afb..d65c9fd5dc 100644 --- a/stubs/semihost.c +++ b/stubs/semihost.c @@ -23,7 +23,7 @@ QemuOptsList qemu_semihosting_config_opts = { }; /* Queries to config status default to off */ -bool semihosting_enabled(void) +bool semihosting_enabled(bool is_user) { return false; } diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c index 163df8c615..3decc8da57 100644 --- a/target/arm/translate-a64.c +++ b/target/arm/translate-a64.c @@ -2219,7 +2219,7 @@ static void disas_exc(DisasContext *s, uint32_t insn) * it is required for halting debug disabled: it will UNDEF. * Secondly, "HLT 0xf000" is the A64 semihosting syscall instruction. */ - if (semihosting_enabled() && imm16 == 0xf000) { + if (semihosting_enabled(false) && imm16 == 0xf000) { #ifndef CONFIG_USER_ONLY /* In system mode, don't allow userspace access to semihosting, * to provide some semblance of security (and for consistency diff --git a/target/arm/translate.c b/target/arm/translate.c index 9474e4b44b..b1e013270d 100644 --- a/target/arm/translate.c +++ b/target/arm/translate.c @@ -1169,7 +1169,7 @@ static inline void gen_hlt(DisasContext *s, int imm) * semihosting, to provide some semblance of security * (and for consistency with our 32-bit semihosting). */ - if (semihosting_enabled() && + if (semihosting_enabled(false) && #ifndef CONFIG_USER_ONLY s->current_el != 0 && #endif @@ -6556,7 +6556,7 @@ static bool trans_BKPT(DisasContext *s, arg_BKPT *a) /* BKPT is OK with ECI set and leaves it untouched */ s->eci_handled = true; if (arm_dc_feature(s, ARM_FEATURE_M) && - semihosting_enabled() && + semihosting_enabled(false) && #ifndef CONFIG_USER_ONLY !IS_USER(s) && #endif @@ -8764,7 +8764,7 @@ static bool trans_SVC(DisasContext *s, arg_SVC *a) { const uint32_t semihost_imm = s->thumb ? 0xab : 0x123456; - if (!arm_dc_feature(s, ARM_FEATURE_M) && semihosting_enabled() && + if (!arm_dc_feature(s, ARM_FEATURE_M) && semihosting_enabled(false) && #ifndef CONFIG_USER_ONLY !IS_USER(s) && #endif diff --git a/target/m68k/op_helper.c b/target/m68k/op_helper.c index d9937ca8dc..4b3dfec130 100644 --- a/target/m68k/op_helper.c +++ b/target/m68k/op_helper.c @@ -203,7 +203,7 @@ static void cf_interrupt_all(CPUM68KState *env, int is_hw) cf_rte(env); return; case EXCP_HALT_INSN: - if (semihosting_enabled() + if (semihosting_enabled(false) && (env->sr & SR_S) != 0 && (env->pc & 3) == 0 && cpu_lduw_code(env, env->pc - 4) == 0x4e71 diff --git a/target/nios2/translate.c b/target/nios2/translate.c index c588e8e885..ff631a42f6 100644 --- a/target/nios2/translate.c +++ b/target/nios2/translate.c @@ -818,7 +818,7 @@ static void gen_break(DisasContext *dc, uint32_t code, uint32_t flags) #ifndef CONFIG_USER_ONLY /* The semihosting instruction is "break 1". */ R_TYPE(instr, code); - if (semihosting_enabled() && instr.imm5 == 1) { + if (semihosting_enabled(false) && instr.imm5 == 1) { t_gen_helper_raise_exception(dc, EXCP_SEMIHOST); return; } diff --git a/target/xtensa/translate.c b/target/xtensa/translate.c index 8b864ef925..afae8a1bea 100644 --- a/target/xtensa/translate.c +++ b/target/xtensa/translate.c @@ -2366,9 +2366,9 @@ static uint32_t test_exceptions_simcall(DisasContext *dc, bool ill = true; #else /* Between RE.2 and RE.3 simcall opcode's become nop for the hardware. */ - bool ill = dc->config->hw_version <= 250002 && !semihosting_enabled(); + bool ill = dc->config->hw_version <= 250002 && !semihosting_enabled(false); #endif - if (ill || !semihosting_enabled()) { + if (ill || !semihosting_enabled(false)) { qemu_log_mask(LOG_GUEST_ERROR, "SIMCALL but semihosting is disabled\n"); } return ill ? XTENSA_OP_ILL : 0; @@ -2378,7 +2378,7 @@ static void translate_simcall(DisasContext *dc, const OpcodeArg arg[], const uint32_t par[]) { #ifndef CONFIG_USER_ONLY - if (semihosting_enabled()) { + if (semihosting_enabled(false)) { gen_helper_simcall(cpu_env); } #endif diff --git a/qemu-options.hx b/qemu-options.hx index 31c04f7eea..1bb02363ab 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -4627,12 +4627,12 @@ SRST information about the facilities this enables. ERST DEF("semihosting-config", HAS_ARG, QEMU_OPTION_semihosting_config, - "-semihosting-config [enable=on|off][,target=native|gdb|auto][,chardev=id][,arg=str[,...]]\n" \ + "-semihosting-config [enable=on|off][,target=native|gdb|auto][,chardev=id][,userspace=on|off][,arg=str[,...]]\n" \ " semihosting configuration\n", QEMU_ARCH_ARM | QEMU_ARCH_M68K | QEMU_ARCH_XTENSA | QEMU_ARCH_MIPS | QEMU_ARCH_NIOS2 | QEMU_ARCH_RISCV) SRST -``-semihosting-config [enable=on|off][,target=native|gdb|auto][,chardev=id][,arg=str[,...]]`` +``-semihosting-config [enable=on|off][,target=native|gdb|auto][,chardev=id][,userspace=on|off][,arg=str[,...]]`` Enable and configure semihosting (ARM, M68K, Xtensa, MIPS, Nios II, RISC-V only). @@ -4659,6 +4659,13 @@ SRST Send the output to a chardev backend output for native or auto output when not in gdb + ``userspace=on|off`` + Allows code running in guest userspace to access the semihosting + interface. The default is that only privileged guest code can + make semihosting calls. Note that setting ``userspace=on`` should + only be used if all guest code is trusted (for example, in + bare-metal test case code). + ``arg=str1,arg=str2,...`` Allows the user to pass input arguments, and can be used multiple times to build up a list. The old-style From patchwork Wed Sep 14 13:23:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 1677916 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=CFWNTdFl; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MSMx55wNFz1ypW for ; Thu, 15 Sep 2022 00:22:32 +1000 (AEST) Received: from localhost ([::1]:37184 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oYTHY-0005oL-DK for incoming@patchwork.ozlabs.org; Wed, 14 Sep 2022 10:22:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48362) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oYSML-00081t-05 for qemu-devel@nongnu.org; Wed, 14 Sep 2022 09:23:21 -0400 Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]:51170) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oYSMH-0000b6-NR for qemu-devel@nongnu.org; Wed, 14 Sep 2022 09:23:19 -0400 Received: by mail-wm1-x332.google.com with SMTP id ay36so1983828wmb.0 for ; Wed, 14 Sep 2022 06:23:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=udcxGrqKWJR20Uk0cyTbsUdJXJIm7W+gSlqAXkcUlZ0=; b=CFWNTdFlBm9Tpf3eNqp1hBojEiMgoFPN9E997SH8FQUCZ+opyyrUDeqs3C+Ra4O7PF 0YmhEJXIp2YEHczjegatgiEQ05EllFv/14Rs1n4vjD+q6jgKm54N7qxJe+N+dwHq1UMS mc9S6xaIVbrV9Xdvwbsg+6qsza7f1J4K0vtp9n5mIPjM/7bXX/yGBroXQk6a+LjNtDCs DRwt73lISUihfj4ek2YFJh9RVLEU8z07hy6CDFA1Aihh0XQM17K044meNlInp0xt0xjg RlGFCK7aDsEnH9vnxK6amINuittI8mWXvuhTrbHyUwoa2QRMtq5Pr/momiWJKVlVxC6y TmIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=udcxGrqKWJR20Uk0cyTbsUdJXJIm7W+gSlqAXkcUlZ0=; b=6CB15NhpBFqNlhPlQ4Qd9GAfo7TSt2U+nr0XyM25k6s0/gE1H/z3RMMh+rYDPiZ8hg aD2sP0pITqSXeg9t65bgkO9dtPjW+7UiMOckM/Q24bMkpj1XAinxPSHGiYxvT6ImoIvs kcz74V1AGynkDh5ZN8uZ986eUqS8p1uQDppAUSD6Ph+LtDn9VOYY9OEeg2jJjcaBDp1+ z8IomQPMyxYtjtO7FhLt5/l0oXGXwSe71CxiR92l5A2fw8U4az+nkmCmnrcchs/UM33a /TAMo8QcPtizHQdDuoEIz2CXpxEZeVnB2SI36gH3wFHf8UdP3HAWeRrmdZNv1zlhzQZQ RH5w== X-Gm-Message-State: ACgBeo2mPbDmBNTY7nW3MKWNJx4ybyrTE3RYPIFDw+UhY8xzHOTF99H9 AEt0KSabQFr7a3xpfKFifEaa67ha1x6fBfG9 X-Google-Smtp-Source: AA6agR4Uv3/f4QCZWK+w83occXUwUkZw/Y590KGMB7M+mfbhIPPI/2mxl4q879TTRXGrwESrGQNoUg== X-Received: by 2002:a05:600c:2949:b0:3b4:85b2:c1d7 with SMTP id n9-20020a05600c294900b003b485b2c1d7mr3074528wmd.183.1663161796029; Wed, 14 Sep 2022 06:23:16 -0700 (PDT) Received: from stoup.. ([89.101.193.70]) by smtp.gmail.com with ESMTPSA id p15-20020a5d48cf000000b00226dedf1ab7sm13768244wrs.76.2022.09.14.06.23.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Sep 2022 06:23:15 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Peter Maydell Subject: [PULL 06/11] target/arm: Honour -semihosting-config userspace=on Date: Wed, 14 Sep 2022 14:23:03 +0100 Message-Id: <20220914132308.118495-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220914132308.118495-1-richard.henderson@linaro.org> References: <20220914132308.118495-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::332; envelope-from=richard.henderson@linaro.org; helo=mail-wm1-x332.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Peter Maydell Honour the commandline -semihosting-config userspace=on option, instead of never permitting userspace semihosting calls in system emulation mode, by passing the correct value to the is_userspace argument of semihosting_enabled(), instead of manually checking and always forbidding semihosting if the guest is in userspace and this isn't the linux-user build. Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson Message-Id: <20220822141230.3658237-3-peter.maydell@linaro.org> Signed-off-by: Richard Henderson --- target/arm/translate-a64.c | 12 +----------- target/arm/translate.c | 16 ++++------------ 2 files changed, 5 insertions(+), 23 deletions(-) diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c index 3decc8da57..9bed336b47 100644 --- a/target/arm/translate-a64.c +++ b/target/arm/translate-a64.c @@ -2219,17 +2219,7 @@ static void disas_exc(DisasContext *s, uint32_t insn) * it is required for halting debug disabled: it will UNDEF. * Secondly, "HLT 0xf000" is the A64 semihosting syscall instruction. */ - if (semihosting_enabled(false) && imm16 == 0xf000) { -#ifndef CONFIG_USER_ONLY - /* In system mode, don't allow userspace access to semihosting, - * to provide some semblance of security (and for consistency - * with our 32-bit semihosting). - */ - if (s->current_el == 0) { - unallocated_encoding(s); - break; - } -#endif + if (semihosting_enabled(s->current_el == 0) && imm16 == 0xf000) { gen_exception_internal_insn(s, s->pc_curr, EXCP_SEMIHOST); } else { unallocated_encoding(s); diff --git a/target/arm/translate.c b/target/arm/translate.c index b1e013270d..5aaccbbf71 100644 --- a/target/arm/translate.c +++ b/target/arm/translate.c @@ -1169,10 +1169,7 @@ static inline void gen_hlt(DisasContext *s, int imm) * semihosting, to provide some semblance of security * (and for consistency with our 32-bit semihosting). */ - if (semihosting_enabled(false) && -#ifndef CONFIG_USER_ONLY - s->current_el != 0 && -#endif + if (semihosting_enabled(s->current_el != 0) && (imm == (s->thumb ? 0x3c : 0xf000))) { gen_exception_internal_insn(s, s->pc_curr, EXCP_SEMIHOST); return; @@ -6556,10 +6553,7 @@ static bool trans_BKPT(DisasContext *s, arg_BKPT *a) /* BKPT is OK with ECI set and leaves it untouched */ s->eci_handled = true; if (arm_dc_feature(s, ARM_FEATURE_M) && - semihosting_enabled(false) && -#ifndef CONFIG_USER_ONLY - !IS_USER(s) && -#endif + semihosting_enabled(s->current_el == 0) && (a->imm == 0xab)) { gen_exception_internal_insn(s, s->pc_curr, EXCP_SEMIHOST); } else { @@ -8764,10 +8758,8 @@ static bool trans_SVC(DisasContext *s, arg_SVC *a) { const uint32_t semihost_imm = s->thumb ? 0xab : 0x123456; - if (!arm_dc_feature(s, ARM_FEATURE_M) && semihosting_enabled(false) && -#ifndef CONFIG_USER_ONLY - !IS_USER(s) && -#endif + if (!arm_dc_feature(s, ARM_FEATURE_M) && + semihosting_enabled(s->current_el == 0) && (a->imm == semihost_imm)) { gen_exception_internal_insn(s, s->pc_curr, EXCP_SEMIHOST); } else { From patchwork Wed Sep 14 13:23:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 1677888 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=tzYAvW5i; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MSM6V3cL9z1ynm for ; Wed, 14 Sep 2022 23:45:37 +1000 (AEST) Received: from localhost ([::1]:47232 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oYShr-0006oa-GV for incoming@patchwork.ozlabs.org; Wed, 14 Sep 2022 09:45:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48366) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oYSML-00082x-90 for qemu-devel@nongnu.org; Wed, 14 Sep 2022 09:23:22 -0400 Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]:35372) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oYSMI-0000bC-9E for qemu-devel@nongnu.org; Wed, 14 Sep 2022 09:23:20 -0400 Received: by mail-wr1-x432.google.com with SMTP id bz13so25705697wrb.2 for ; Wed, 14 Sep 2022 06:23:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=rTB12Kd3V2NAFpRhE4AcHzoc+HouSttzxGrYvX7ucFI=; b=tzYAvW5iYfZYsdDAych860+Uua6bGC02vEOexfyco/ScffNwMR+VMVlEsyoPMJ1g6I mOp0MSfk4EA7M9Z4k1jpslubtE+ZluqEYC/GrhgaCWMnrVH70IheJtXEMvWNpFAqtSg9 C6Ng+rkYn3I1WdNL9p8gC36XLPViVYodi6O2v61oX37vY9sbRz0kDsMwUXU8kCDKZBoY j6ViV7voN7Y/HZ1Imt7wtvZKHr9fQXT4hbx55gZYHPo0hxhekX0m9vkMp4avebu3pZGt Yq+7bjhYpUmCSpHMkFuhhm2BJcTbDvKF2t9hSpqklp0vVL8OjN8fjyDlSYKPS0yFrj+g dncw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=rTB12Kd3V2NAFpRhE4AcHzoc+HouSttzxGrYvX7ucFI=; b=H0jXpC0sEfNhlhDAjljLMItNdCuU3vcswJUnUOvBiTNLwtQa5smSlxcVIJbdzLNEVk q5PEOfz1TNhbILnd0sRkr1VAJ8RKFtoI4+Ux4qXULQHXjOf/km6UxCNLn2TC+1KXKJYn o4C98+HILDchmV2gFg9tsM8PrG2WE0fqCDmcRabUwQCjkTQhBESTpjeFtPURU0BchpLF 3TlJ3w/N0gnN331fFw+NewEjkXdr4D3zoCypDDV4ApWJTToTZzNPxcU1YvUzStMh6lMQ /rmi6e+NlIuM5JcX48FA6RPLPJi5Yn5qWonMd/en119N77DjU38hJLkz09bSXP3ageiM OLWg== X-Gm-Message-State: ACgBeo14H4sHxbgptOv951zM46P3qVD5iWb8qRI+EJNdtUbhtRGfr3YQ yZG3Ye8D/BKEuLmOhy/3F0xclVmJfHcT4MYd X-Google-Smtp-Source: AA6agR48CZZosf1OJmlCgtmgh8JYYIcRdZnpfzd8PmyDYAtf+p4zG9CqrTxiu9PitVpvEAqqVLyMwA== X-Received: by 2002:a05:6000:82:b0:228:db8c:5308 with SMTP id m2-20020a056000008200b00228db8c5308mr21088535wrx.164.1663161796915; Wed, 14 Sep 2022 06:23:16 -0700 (PDT) Received: from stoup.. ([89.101.193.70]) by smtp.gmail.com with ESMTPSA id p15-20020a5d48cf000000b00226dedf1ab7sm13768244wrs.76.2022.09.14.06.23.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Sep 2022 06:23:16 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Peter Maydell , Laurent Vivier Subject: [PULL 07/11] target/m68k: Honour -semihosting-config userspace=on Date: Wed, 14 Sep 2022 14:23:04 +0100 Message-Id: <20220914132308.118495-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220914132308.118495-1-richard.henderson@linaro.org> References: <20220914132308.118495-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::432; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x432.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Peter Maydell Honour the commandline -semihosting-config userspace=on option, instead of never permitting userspace semihosting calls in system emulation mode, by passing the correct value to the is_userspace argument of semihosting_enabled(), instead of manually checking and always forbidding semihosting if the guest is in userspace. (Note that target/m68k doesn't support semihosting at all in the linux-user build.) Signed-off-by: Peter Maydell Reviewed-by: Laurent Vivier Reviewed-by: Richard Henderson Message-Id: <20220822141230.3658237-4-peter.maydell@linaro.org> Signed-off-by: Richard Henderson --- target/m68k/op_helper.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/target/m68k/op_helper.c b/target/m68k/op_helper.c index 4b3dfec130..a96a034050 100644 --- a/target/m68k/op_helper.c +++ b/target/m68k/op_helper.c @@ -203,8 +203,7 @@ static void cf_interrupt_all(CPUM68KState *env, int is_hw) cf_rte(env); return; case EXCP_HALT_INSN: - if (semihosting_enabled(false) - && (env->sr & SR_S) != 0 + if (semihosting_enabled((env->sr & SR_S) == 0) && (env->pc & 3) == 0 && cpu_lduw_code(env, env->pc - 4) == 0x4e71 && cpu_ldl_code(env, env->pc) == 0x4e7bf000) { From patchwork Wed Sep 14 13:23:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 1677882 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=v6z0wlGt; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MSM4D2bLTz1ypW for ; Wed, 14 Sep 2022 23:43:40 +1000 (AEST) Received: from localhost ([::1]:60062 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oYSfy-0004JZ-8e for incoming@patchwork.ozlabs.org; Wed, 14 Sep 2022 09:43:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48370) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oYSMM-00085K-PR for qemu-devel@nongnu.org; Wed, 14 Sep 2022 09:23:23 -0400 Received: from mail-wm1-x331.google.com ([2a00:1450:4864:20::331]:45042) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oYSMK-0000bQ-Mh for qemu-devel@nongnu.org; Wed, 14 Sep 2022 09:23:22 -0400 Received: by mail-wm1-x331.google.com with SMTP id n17-20020a05600c501100b003a84bf9b68bso11509325wmr.3 for ; Wed, 14 Sep 2022 06:23:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=PXOhY/GLE5ushsuwq2usxIkhOBcQf53LWE9OWb978Zw=; b=v6z0wlGt0YEhK/ryaJgZNhWUPE3Ocs6fb53TvoXRubDYNLxIVvsYj1pHyLoBQTbtFq 8gVtPfxfKt6PCBcDDUhP+Lc87Vz/17S+y45OoekKns9afN6DdzyMHfOHo0XaPGH9SvlD 3jWFoQKJkJ2z80Rw3TDEAyVB5tHu2A5JNIKRh9RN0YgWjsPx59CByE/Wm6kNJ+4Zxmwt g53955GOAwLKHcyaxQAh1+5XWA8vL39tjISXYt0WQsu1SxOkTIau57REBST/aX4yc4M4 Ll8HiM8ldyWXm28fJ2g8D12x+hMpSeIuBqiHNv0SRblZmmXjA2bqYjwUJW+jgd5+/oN6 Ysww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=PXOhY/GLE5ushsuwq2usxIkhOBcQf53LWE9OWb978Zw=; b=7bBv+I7cFXLl/SAufUpXCB0RlWXR/g5hu9xxYNGd5XcAZYg3fhgFzCH002y6x+fVT4 eTJTgBiD5swBZKFhek9P+oQXvY3AtSZegkQ1K52pMFqV9H5dZx8SkpCAe5/i2ZfPe93o fmNedy+YR2QCstB77jiTUeg8+rdnlWcsxzRUZDuPfHetWeubkVdr29ganda0oQ9nS/Qk xYH0xIfBXkWw3wUDz7kxyg91PSrCEcSne4CZ1XCVPrMBGJeGj/KUh2parUzM0h0s/vk+ b3Wk/xIa6ueCk2wALtRL4bhuPPK1Rq2rOPWaKAgHLuMKPpywGyT7/Zrzaf+z+z6izcWX GS4Q== X-Gm-Message-State: ACgBeo2xOhRsaeQrTRb1X5zuiLGed22bkE1qzhuiuXl5Qc6RyEoQVE2y ShavSBs58FKfPx5DazK/7V9mPdpsp2VItEqs X-Google-Smtp-Source: AA6agR4cvwsqKxb6d+fbxqWzOARFxHnu2CutyxO/m5flDCQMa8RFPaZJV2uU0o4PeC2S0fhg/sNLRA== X-Received: by 2002:a1c:7905:0:b0:3b3:3fa9:4c3a with SMTP id l5-20020a1c7905000000b003b33fa94c3amr3211504wme.55.1663161797762; Wed, 14 Sep 2022 06:23:17 -0700 (PDT) Received: from stoup.. ([89.101.193.70]) by smtp.gmail.com with ESMTPSA id p15-20020a5d48cf000000b00226dedf1ab7sm13768244wrs.76.2022.09.14.06.23.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Sep 2022 06:23:17 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Peter Maydell , =?utf-8?q?Philippe_Mathieu-Dau?= =?utf-8?q?d=C3=A9?= Subject: [PULL 08/11] target/mips: Honour -semihosting-config userspace=on Date: Wed, 14 Sep 2022 14:23:05 +0100 Message-Id: <20220914132308.118495-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220914132308.118495-1-richard.henderson@linaro.org> References: <20220914132308.118495-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::331; envelope-from=richard.henderson@linaro.org; helo=mail-wm1-x331.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Peter Maydell Honour the commandline -semihosting-config userspace=on option, instead of always permitting userspace semihosting calls in system emulation mode, by passing the correct value to the is_userspace argument of semihosting_enabled(). Note that this is a behaviour change: if the user wants to do semihosting calls from userspace they must now specifically enable them on the command line. MIPS semihosting is not implemented for linux-user builds. Signed-off-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Richard Henderson Message-Id: <20220822141230.3658237-5-peter.maydell@linaro.org> Signed-off-by: Richard Henderson --- target/mips/tcg/translate.c | 9 +++++---- target/mips/tcg/micromips_translate.c.inc | 6 +++--- target/mips/tcg/mips16e_translate.c.inc | 2 +- target/mips/tcg/nanomips_translate.c.inc | 4 ++-- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/target/mips/tcg/translate.c b/target/mips/tcg/translate.c index 0d936e2648..c3f92ea652 100644 --- a/target/mips/tcg/translate.c +++ b/target/mips/tcg/translate.c @@ -12082,12 +12082,13 @@ static void gen_cache_operation(DisasContext *ctx, uint32_t op, int base, tcg_temp_free_i32(t0); } -static inline bool is_uhi(int sdbbp_code) +static inline bool is_uhi(DisasContext *ctx, int sdbbp_code) { #ifdef CONFIG_USER_ONLY return false; #else - return semihosting_enabled() && sdbbp_code == 1; + bool is_user = (ctx->hflags & MIPS_HFLAG_KSU) == MIPS_HFLAG_UM; + return semihosting_enabled(is_user) && sdbbp_code == 1; #endif } @@ -13898,7 +13899,7 @@ static void decode_opc_special_r6(CPUMIPSState *env, DisasContext *ctx) } break; case R6_OPC_SDBBP: - if (is_uhi(extract32(ctx->opcode, 6, 20))) { + if (is_uhi(ctx, extract32(ctx->opcode, 6, 20))) { ctx->base.is_jmp = DISAS_SEMIHOST; } else { if (ctx->hflags & MIPS_HFLAG_SBRI) { @@ -14310,7 +14311,7 @@ static void decode_opc_special2_legacy(CPUMIPSState *env, DisasContext *ctx) gen_cl(ctx, op1, rd, rs); break; case OPC_SDBBP: - if (is_uhi(extract32(ctx->opcode, 6, 20))) { + if (is_uhi(ctx, extract32(ctx->opcode, 6, 20))) { ctx->base.is_jmp = DISAS_SEMIHOST; } else { /* diff --git a/target/mips/tcg/micromips_translate.c.inc b/target/mips/tcg/micromips_translate.c.inc index b2c696f891..632895cc9e 100644 --- a/target/mips/tcg/micromips_translate.c.inc +++ b/target/mips/tcg/micromips_translate.c.inc @@ -825,7 +825,7 @@ static void gen_pool16c_insn(DisasContext *ctx) generate_exception_break(ctx, extract32(ctx->opcode, 0, 4)); break; case SDBBP16: - if (is_uhi(extract32(ctx->opcode, 0, 4))) { + if (is_uhi(ctx, extract32(ctx->opcode, 0, 4))) { ctx->base.is_jmp = DISAS_SEMIHOST; } else { /* @@ -941,7 +941,7 @@ static void gen_pool16c_r6_insn(DisasContext *ctx) break; case R6_SDBBP16: /* SDBBP16 */ - if (is_uhi(extract32(ctx->opcode, 6, 4))) { + if (is_uhi(ctx, extract32(ctx->opcode, 6, 4))) { ctx->base.is_jmp = DISAS_SEMIHOST; } else { if (ctx->hflags & MIPS_HFLAG_SBRI) { @@ -1310,7 +1310,7 @@ static void gen_pool32axf(CPUMIPSState *env, DisasContext *ctx, int rt, int rs) generate_exception_end(ctx, EXCP_SYSCALL); break; case SDBBP: - if (is_uhi(extract32(ctx->opcode, 16, 10))) { + if (is_uhi(ctx, extract32(ctx->opcode, 16, 10))) { ctx->base.is_jmp = DISAS_SEMIHOST; } else { check_insn(ctx, ISA_MIPS_R1); diff --git a/target/mips/tcg/mips16e_translate.c.inc b/target/mips/tcg/mips16e_translate.c.inc index 7568933e23..918b15d55c 100644 --- a/target/mips/tcg/mips16e_translate.c.inc +++ b/target/mips/tcg/mips16e_translate.c.inc @@ -951,7 +951,7 @@ static int decode_ase_mips16e(CPUMIPSState *env, DisasContext *ctx) } break; case RR_SDBBP: - if (is_uhi(extract32(ctx->opcode, 5, 6))) { + if (is_uhi(ctx, extract32(ctx->opcode, 5, 6))) { ctx->base.is_jmp = DISAS_SEMIHOST; } else { /* diff --git a/target/mips/tcg/nanomips_translate.c.inc b/target/mips/tcg/nanomips_translate.c.inc index b3aff22c18..812c111e3c 100644 --- a/target/mips/tcg/nanomips_translate.c.inc +++ b/target/mips/tcg/nanomips_translate.c.inc @@ -3694,7 +3694,7 @@ static int decode_nanomips_32_48_opc(CPUMIPSState *env, DisasContext *ctx) generate_exception_end(ctx, EXCP_BREAK); break; case NM_SDBBP: - if (is_uhi(extract32(ctx->opcode, 0, 19))) { + if (is_uhi(ctx, extract32(ctx->opcode, 0, 19))) { ctx->base.is_jmp = DISAS_SEMIHOST; } else { if (ctx->hflags & MIPS_HFLAG_SBRI) { @@ -4633,7 +4633,7 @@ static int decode_isa_nanomips(CPUMIPSState *env, DisasContext *ctx) generate_exception_end(ctx, EXCP_BREAK); break; case NM_SDBBP16: - if (is_uhi(extract32(ctx->opcode, 0, 3))) { + if (is_uhi(ctx, extract32(ctx->opcode, 0, 3))) { ctx->base.is_jmp = DISAS_SEMIHOST; } else { if (ctx->hflags & MIPS_HFLAG_SBRI) { From patchwork Wed Sep 14 13:23:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 1677911 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=kO9EoxQE; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MSMpm3zZHz1yhR for ; Thu, 15 Sep 2022 00:17:04 +1000 (AEST) Received: from localhost ([::1]:36760 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oYTCF-0001Tj-Vf for incoming@patchwork.ozlabs.org; Wed, 14 Sep 2022 10:16:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48368) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oYSMM-00084Z-In for qemu-devel@nongnu.org; Wed, 14 Sep 2022 09:23:22 -0400 Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]:43782) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oYSMK-0000ca-O9 for qemu-devel@nongnu.org; Wed, 14 Sep 2022 09:23:22 -0400 Received: by mail-wm1-x332.google.com with SMTP id z14-20020a05600c0a0e00b003b486df42a3so6403803wmp.2 for ; Wed, 14 Sep 2022 06:23:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=+jD9lKzsh1CbGMDE7cH4Ty4evA7hw2r7Od0SGTHPpGM=; b=kO9EoxQEqaWyJ/rQBz15iFnqQrip6/s4MRX4f5w4Qj9Yh5L+H2j3lm9pt+Ys27iafQ IkKj6GYa99K37Pn72sY+Ds1X22E2evcHcfpQKsMk3QJsDMQ/VIi5Hmh9CqJYNk/tho7T x+rJPpqzPGN6iiQDgB+qJozzf7DL601XMPe8NOQJqRi3DaZ49im0qY2PAHx8IHXrtlKw hFTbDfEz4pcxahYga/C6yd9lnmgeqIqk+eVSHvZ1EVWOaRFOxAyS44Cj93WSEHQMH9lY qh3VYZcGZdcCpLyqTxC5QiJUI+EIyMHY4dPf9t8mZ6pguq59IrB+CshIVrIHXhozQSv4 mTVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=+jD9lKzsh1CbGMDE7cH4Ty4evA7hw2r7Od0SGTHPpGM=; b=j3EL5i1MfaUwJK3tLPqjV77lGd+4FNTNAZyd+eoIDjPZuuh/cxadtxK41/oDkrffzt cpcjCMDvN5hHp9i8lqTD3qcu1+sx1lP7FU+a/hmSFwoTF/G+xc7mAMjRXBOqi+m9p8BD 6hb7aOxB5G8uGdI1ZzPHWSBOO8cHlswqSlUMCwl1WEiODbUqbhA06zvGdtuV9CnueO0G AAJWZKsxuKzEz+DLHAkqxz8A5ztoHgsvsMFhTLtSqauHzq97B7neM3Df7yhysWh5lwRh Jtbv69XEW1FVYxO6sIBGJIbr4+jXALhZlcWw7S6P6STESEGHzptKhST6QGsIohoZicf1 bRuQ== X-Gm-Message-State: ACgBeo0BzNEzZvgJDACid3mFuprANQg2qyg9YnfVpmwGc3bEXPvkYybq 7B8iuHlzat8lLOoXP+0CFHuWIgtazn80M09/ X-Google-Smtp-Source: AA6agR6Py3wcAU/o9RH9SB2EzKdpC8sjJ7qauKimnnDNfY20nYG/YKA1MCyNIejoadY7sdeY1Peg1g== X-Received: by 2002:a05:600c:2d09:b0:3b4:7ff0:ae89 with SMTP id x9-20020a05600c2d0900b003b47ff0ae89mr3073236wmf.163.1663161798630; Wed, 14 Sep 2022 06:23:18 -0700 (PDT) Received: from stoup.. ([89.101.193.70]) by smtp.gmail.com with ESMTPSA id p15-20020a5d48cf000000b00226dedf1ab7sm13768244wrs.76.2022.09.14.06.23.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Sep 2022 06:23:18 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Peter Maydell Subject: [PULL 09/11] target/nios2: Honour -semihosting-config userspace=on Date: Wed, 14 Sep 2022 14:23:06 +0100 Message-Id: <20220914132308.118495-10-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220914132308.118495-1-richard.henderson@linaro.org> References: <20220914132308.118495-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::332; envelope-from=richard.henderson@linaro.org; helo=mail-wm1-x332.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Peter Maydell Honour the commandline -semihosting-config userspace=on option, instead of always permitting userspace semihosting calls in system emulation mode, by passing the correct value to the is_userspace argument of semihosting_enabled(). Note that this is a behaviour change: if the user wants to do semihosting calls from userspace they must now specifically enable them on the command line. nios2 semihosting is not implemented for linux-user builds. Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson Message-Id: <20220822141230.3658237-6-peter.maydell@linaro.org> Signed-off-by: Richard Henderson --- target/nios2/translate.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/target/nios2/translate.c b/target/nios2/translate.c index ff631a42f6..8dc0a32c6c 100644 --- a/target/nios2/translate.c +++ b/target/nios2/translate.c @@ -817,8 +817,9 @@ static void gen_break(DisasContext *dc, uint32_t code, uint32_t flags) { #ifndef CONFIG_USER_ONLY /* The semihosting instruction is "break 1". */ + bool is_user = FIELD_EX32(dc->tb_flags, TBFLAGS, U); R_TYPE(instr, code); - if (semihosting_enabled(false) && instr.imm5 == 1) { + if (semihosting_enabled(is_user) && instr.imm5 == 1) { t_gen_helper_raise_exception(dc, EXCP_SEMIHOST); return; } From patchwork Wed Sep 14 13:23:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 1677889 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=n2hdNL0X; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MSMCq1qMmz1yhR for ; Wed, 14 Sep 2022 23:50:15 +1000 (AEST) Received: from localhost ([::1]:52120 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oYSmL-00047c-2L for incoming@patchwork.ozlabs.org; Wed, 14 Sep 2022 09:50:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48374) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oYSMO-00088E-22 for qemu-devel@nongnu.org; Wed, 14 Sep 2022 09:23:24 -0400 Received: from mail-wm1-x329.google.com ([2a00:1450:4864:20::329]:51162) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oYSML-0000ci-4c for qemu-devel@nongnu.org; Wed, 14 Sep 2022 09:23:23 -0400 Received: by mail-wm1-x329.google.com with SMTP id ay36so1983926wmb.0 for ; Wed, 14 Sep 2022 06:23:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=Fst4x49rn2TZohR5patrgQl48OlHihnTjCr3gqAYNQs=; b=n2hdNL0XAYIF6KU+WDutOS/sYWYvGx/kajB2zcxYR7PcJc55jIPdK32DtYKNlnBKti 9di48vukFIvkycrUErxhl22UnIH1QEKf8stf3dlrMuDGB5Px9dhMeZmtOx3A3fP0FM/K PSVuCEy5S4dXprRUrJCWFuLDUv15kkBd3OocknGtPkboXMraHX2wYVc0aWOEdqaj5rBj VYurw+5hTZKV6xeIY2v1KpwfhRbHkhdlUMqDoL+HN3HGODHsKJS4Ynm7gZk6BDUBLuzO tPYzIbzhvIKCBkV6Bco51h4F8i0woGwsr1jZdfOg3iFaEfMKb+nebBpd2LcmixiRXv/D 5PqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=Fst4x49rn2TZohR5patrgQl48OlHihnTjCr3gqAYNQs=; b=w+F82WCFHk4mburiQH14nuGYqfL/SoaVYcaIx1eLAq3Fq7uENR62vHBa00ctzBhGMJ X+OgleXwEu42IF4FdTQoM0LH7Ftrxc5IxOiQyo3DmyjSv5L9OWbkRjipCE44dx77hyZY 9qTneRj/KOJ3DQsi4bxLYEdxOmYZXlhf73hHqQsyS9Ma0VJnLMrHalhpnbS2EDRumRcP 5Ya7aL7AFosoJLxJRGzkDg3J9uqKRy8cCEWMjrCa8vxsI73C2qYDOaEHxjcuDPJicPIQ ropAGBOzWrZGMnWITO9u2Zs3eYfbaJM39ROiooKIqzDLJ0i1CHZLIS9vV5627vee5y1R UMNw== X-Gm-Message-State: ACgBeo3Sk84OjPtO6Z3bPxjh3cN7+lA9pm/EQqXCLZjtPUtGbMstLNku m4Jk6oltt2UljPoD97PK5ItkD1lVgqm2LUba X-Google-Smtp-Source: AA6agR64lv1OMuegYYb5qYbYv0ZAMGQ4rSa26ZwHA3nI2KZdnTu8/65dt/P0LGuogBOuxX1YmBBsvw== X-Received: by 2002:a05:600c:5486:b0:3b4:7e47:e19 with SMTP id iv6-20020a05600c548600b003b47e470e19mr3189672wmb.12.1663161799577; Wed, 14 Sep 2022 06:23:19 -0700 (PDT) Received: from stoup.. ([89.101.193.70]) by smtp.gmail.com with ESMTPSA id p15-20020a5d48cf000000b00226dedf1ab7sm13768244wrs.76.2022.09.14.06.23.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Sep 2022 06:23:19 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Peter Maydell , Max Filippov , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PULL 10/11] target/xtensa: Honour -semihosting-config userspace=on Date: Wed, 14 Sep 2022 14:23:07 +0100 Message-Id: <20220914132308.118495-11-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220914132308.118495-1-richard.henderson@linaro.org> References: <20220914132308.118495-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::329; envelope-from=richard.henderson@linaro.org; helo=mail-wm1-x329.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Peter Maydell Honour the commandline -semihosting-config userspace=on option, instead of always permitting userspace semihosting calls in system emulation mode, by passing the correct value to the is_userspace argument of semihosting_enabled(). Note that this is a behaviour change: if the user wants to do semihosting calls from userspace they must now specifically enable them on the command line. xtensa semihosting is not implemented for linux-user builds. Signed-off-by: Peter Maydell Acked-by: Max Filippov Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Richard Henderson Message-Id: <20220822141230.3658237-7-peter.maydell@linaro.org> Signed-off-by: Richard Henderson --- target/xtensa/translate.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/target/xtensa/translate.c b/target/xtensa/translate.c index afae8a1bea..bdd4690a5c 100644 --- a/target/xtensa/translate.c +++ b/target/xtensa/translate.c @@ -2362,13 +2362,14 @@ static uint32_t test_exceptions_simcall(DisasContext *dc, const OpcodeArg arg[], const uint32_t par[]) { + bool is_semi = semihosting_enabled(dc->cring != 0); #ifdef CONFIG_USER_ONLY bool ill = true; #else /* Between RE.2 and RE.3 simcall opcode's become nop for the hardware. */ - bool ill = dc->config->hw_version <= 250002 && !semihosting_enabled(false); + bool ill = dc->config->hw_version <= 250002 && !is_semi; #endif - if (ill || !semihosting_enabled(false)) { + if (ill || !is_semi) { qemu_log_mask(LOG_GUEST_ERROR, "SIMCALL but semihosting is disabled\n"); } return ill ? XTENSA_OP_ILL : 0; @@ -2378,7 +2379,7 @@ static void translate_simcall(DisasContext *dc, const OpcodeArg arg[], const uint32_t par[]) { #ifndef CONFIG_USER_ONLY - if (semihosting_enabled(false)) { + if (semihosting_enabled(dc->cring != 0)) { gen_helper_simcall(cpu_env); } #endif From patchwork Wed Sep 14 13:23:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 1677921 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=UT2iBFut; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MSMzv197pz1ypW for ; Thu, 15 Sep 2022 00:24:59 +1000 (AEST) Received: from localhost ([::1]:42614 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oYTJx-0000ld-32 for incoming@patchwork.ozlabs.org; Wed, 14 Sep 2022 10:24:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48376) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oYSMO-00088K-4l for qemu-devel@nongnu.org; Wed, 14 Sep 2022 09:23:24 -0400 Received: from mail-wr1-x42e.google.com ([2a00:1450:4864:20::42e]:39581) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oYSML-0000ae-F5 for qemu-devel@nongnu.org; Wed, 14 Sep 2022 09:23:23 -0400 Received: by mail-wr1-x42e.google.com with SMTP id cc5so15852870wrb.6 for ; Wed, 14 Sep 2022 06:23:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=5hn5ZCIWBTjKXNmV0CdKODbs07VBGmCbJWLiyFIEtk8=; b=UT2iBFutxaQZG3iau273rZQEnu9bwj2hVUgwj9atPhXvuLjzq38B+yh4zIxRRmNWY3 lTek+YRzjy964PBiL06pl51sGJmvHYweKkU++77WDgSYyA3gtgieTndhcWHbTj+WAB5m fSrhWxxvBNJeRs1moVLV9XWZAEtj9H3fgz5lBIQWhdRVL0pOGwrK2qD/3Skly+je8bOd PLYNv809mJBxUzuNCh5+q3OdI4BQS4ZoN/BTksjK4qLeCKznQFPAewyWBj44gsX0K5I3 lr4xWHmxdDiRkjZu1DnevjFzHh6azlWW604vuuZibXAXU2AEzpK16/eh2/XNPGzwJP46 /YVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=5hn5ZCIWBTjKXNmV0CdKODbs07VBGmCbJWLiyFIEtk8=; b=GqGND5F/84+SnPbvdRTuqzMpqHFKlPkipHhkg6g185DlEexlQR95CEIpWweM+IoGVF z6ddwKcswIlAcXb4J2PdLLZMNhQnX4YCadkZQHUXxXghBKkOJ6vJQRQciOur60yUzHCY y/vtyj+4sHdbA0k2WEEfVgyyDVhMPb6rTHo1P3hAzxI+EkRyA1Qycjic6QgA6jPeSxu/ A3699bFg3C01sVOMKekheT3izPL7p6cXKtUrkeq5JRYPUz85mbCpAP2Bgln1oPGDZEJo 3ChpHWXGJd8kBQa0+dj2suQ8UmGczth09HW6JRGau0ErdG8qP3fU54f0KOZ4Qvx3010P MpPA== X-Gm-Message-State: ACgBeo0gRCutCq1YE9SuuwDuamUDX0+uJhk8fpmNL4TR5cfLL1hxNsJ4 rU+ZgxmHqHr+dLtovdpDLgbFMwovii26QaVv X-Google-Smtp-Source: AA6agR64LE5V8zL57GsXZLjfOXvvZUJXo/aM3xvNW2VBYYSW/3CzpqUOaRKa6OAmIU5QE2/tQnbz2g== X-Received: by 2002:adf:e411:0:b0:226:d3f9:4a03 with SMTP id g17-20020adfe411000000b00226d3f94a03mr22967527wrm.673.1663161800516; Wed, 14 Sep 2022 06:23:20 -0700 (PDT) Received: from stoup.. ([89.101.193.70]) by smtp.gmail.com with ESMTPSA id p15-20020a5d48cf000000b00226dedf1ab7sm13768244wrs.76.2022.09.14.06.23.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Sep 2022 06:23:20 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Peter Maydell , Alistair Francis Subject: [PULL 11/11] target/riscv: Honour -semihosting-config userspace=on and enable=on Date: Wed, 14 Sep 2022 14:23:08 +0100 Message-Id: <20220914132308.118495-12-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220914132308.118495-1-richard.henderson@linaro.org> References: <20220914132308.118495-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42e; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x42e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Peter Maydell The riscv target incorrectly enabled semihosting always, whether the user asked for it or not. Call semihosting_enabled() passing the correct value to the is_userspace argument, which fixes this and also handles the userspace=on argument. Because we do this at translate time, we no longer need to check the privilege level in riscv_cpu_do_interrupt(). Note that this is a behaviour change: we used to default to semihosting being enabled, and now the user must pass "-semihosting-config enable=on" if they want it. Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson Reviewed-by: Alistair Francis Message-Id: <20220822141230.3658237-8-peter.maydell@linaro.org> Signed-off-by: Richard Henderson --- target/riscv/cpu_helper.c | 9 +++------ target/riscv/translate.c | 1 + target/riscv/insn_trans/trans_privileged.c.inc | 3 ++- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index 67e4c0efd2..278d163803 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -1589,12 +1589,9 @@ void riscv_cpu_do_interrupt(CPUState *cs) target_ulong mtval2 = 0; if (cause == RISCV_EXCP_SEMIHOST) { - if (env->priv >= PRV_S) { - do_common_semihosting(cs); - env->pc += 4; - return; - } - cause = RISCV_EXCP_BREAKPOINT; + do_common_semihosting(cs); + env->pc += 4; + return; } if (!async) { diff --git a/target/riscv/translate.c b/target/riscv/translate.c index 8925a44c6e..db123da5ec 100644 --- a/target/riscv/translate.c +++ b/target/riscv/translate.c @@ -28,6 +28,7 @@ #include "exec/translator.h" #include "exec/log.h" +#include "semihosting/semihost.h" #include "instmap.h" #include "internals.h" diff --git a/target/riscv/insn_trans/trans_privileged.c.inc b/target/riscv/insn_trans/trans_privileged.c.inc index 46f96ad74d..3281408a87 100644 --- a/target/riscv/insn_trans/trans_privileged.c.inc +++ b/target/riscv/insn_trans/trans_privileged.c.inc @@ -52,7 +52,8 @@ static bool trans_ebreak(DisasContext *ctx, arg_ebreak *a) * that no exception will be raised when fetching them. */ - if ((pre_addr & TARGET_PAGE_MASK) == (post_addr & TARGET_PAGE_MASK)) { + if (semihosting_enabled(ctx->mem_idx < PRV_S) && + (pre_addr & TARGET_PAGE_MASK) == (post_addr & TARGET_PAGE_MASK)) { pre = opcode_at(&ctx->base, pre_addr); ebreak = opcode_at(&ctx->base, ebreak_addr); post = opcode_at(&ctx->base, post_addr);