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: 605733 Delivered-To: patch@linaro.org Received: by 2002:ab3:1c02:0:b0:1e7:4ce8:c350 with SMTP id u2csp746946lth; Wed, 14 Sep 2022 06:36:50 -0700 (PDT) X-Google-Smtp-Source: AA6agR6BT1CzrRtYexQSImPTVcL1a3yHPiOfx8kIXMs8AVzIWJNW/zo/cjdD/cv9c9MTgU3qAv1p X-Received: by 2002:ac8:5796:0:b0:344:9321:5e2c with SMTP id v22-20020ac85796000000b0034493215e2cmr33308218qta.249.1663162610057; Wed, 14 Sep 2022 06:36:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663162610; cv=none; d=google.com; s=arc-20160816; b=saMH6BSeQqCzLfcZEdioz6D7GSv+jG/midxlu1yQkFLWZ+Vk0X8R8ACXXVl13cyU20 xUJbnifI3hh6PRFI/yjuqVSJQQKit74JrrInCsfkszP1Up8Q5zqr2Iy11LM14FPf5QS/ orxIgSjlzEV1UWns+GxbrwKsbgeSYkrAJwpBofA1tzIDA0pPXQ4JHVAon/L8I/YRDl8E dGFVJfEO5YvSDhfc85YSMdKrQKPNFcYnDjV56ZqKyECB3Mp5Xl6oR27iP5K991R4xBsb AZkumjS8QAYsf1j3yuCxE4OBqISBkRIxDhUjT5WI64eAINfOwobExlqtaqviGFKr6t2X l3aA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=BOg1aEu3yBTI9dGIqi4jrE4GeTG3hleBbfwHOhDBa5c=; b=tfe6italMfBXGLNutQnZE7+tzs0vMPcpQ2osaQ3o6pC0LKfQe/YwVLl3bvaxnEHrWV q1rgwP2v5ml3CvpdTP8Qx6rk+N2uCL9bq33AJvtS4wrDQZ3KVPK7yiPBJSbA6JbaYq/t p4ujH+RAt9a0wvRTpoKthDgdyl1C4oydOg5uncc+pvy4c8k4EHdXjstMnhy3oNPgF4fh 3InrY8xgrXiN8rtVZ0EWD6owwuNWd9mA/Mu0sgJWIl06evMpzmj5eOfJblwwqpkWX7wP Xb6PxR8obBjkhHTjEIRqXxI4yyrLnh4LvLUtNF4nkmg02ZTvjLDXhGMG5PIVN3JhCsPk ws0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Ku4UUosT; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id fw10-20020a056214238a00b004aaa6ea08dbsi1336719qvb.39.2022.09.14.06.36.49 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 14 Sep 2022 06:36:50 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Ku4UUosT; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:48464 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oYSZN-0003Ze-Fr for patch@linaro.org; Wed, 14 Sep 2022 09:36:49 -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-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+patch=linaro.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: 605739 Delivered-To: patch@linaro.org Received: by 2002:ab3:1c02:0:b0:1e7:4ce8:c350 with SMTP id u2csp772896lth; Wed, 14 Sep 2022 07:14:28 -0700 (PDT) X-Google-Smtp-Source: AA6agR61sEl5XAz2KIrbT2+CSJ2ar0Q18I/KRZk302Bw6cvooq5ywGl+X+l46mjaTXpP7mNE2Rmw X-Received: by 2002:a05:620a:1a17:b0:6ce:7c1b:c27f with SMTP id bk23-20020a05620a1a1700b006ce7c1bc27fmr4901203qkb.42.1663164868275; Wed, 14 Sep 2022 07:14:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663164868; cv=none; d=google.com; s=arc-20160816; b=iLq6vv6PXXMP9fQDcel7aUFDyaj8vQ7Ebr+6DndigHCIgOwb8aEnIZxYoRKV7Du4kV F/OGWWpK/tOR8p0GopcB1gwERFC4iNhRR9APizYiV5RlmrWvQgA2hpz2RvFpMdmbJe/r wMGJEU7T6YYCzjlOAkBck1JJMBoYq/HJ+3m1Qsg97pCoreYOUQjyCC9VJyAZ31BCS9ta 1a6S4l3EiCoNbuKrxPV6lTyuZb7Y9xZzSf1Dql6I2THxHj67WN9+wh6A5/ZYOL7xELsM dh6dNJ0P3vLmiLsR5k5oYkKkBEpc2J5SBjxbuDDQxWlT3mYD2FUA0eXLqXWPhWg85N9S Pogg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=KfQlb4Kf/qCPlICOyHg/LYLEi3mUvRQuhI0h+42sfkk=; b=ox710UOYe0ePxfq/Ai2F7e1H14BjgwaDkCxRMGvprPoxhJV6IImo1hsPygSzpfp5r9 H7KIaA+uApv5iQpS9fNzCVpZk97mFuyNSCab850K8+LzishFdnVXR+98+QhEak8s0YHj wfKIXmoFedMPsHByWAsblDpfmXBABLz63PRbIg8UMISqm4cDoGEy7Jy0WiUtKHVsZExV fVyCg4HaG4qNCyzBDA6qj3iXx1htsoVhfr0svDurxuJtaXYts/zemNNeTQh5kBkjez1F wvRWayRuvc01vO5I8VUluXzvZF/NP3lHKwH3DhRnS0iUcbAxwHLzPr14rqNMzhaCNW17 ad0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jvpEOt99; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id f11-20020a05620a280b00b006b9524ce6c2si1581213qkp.61.2022.09.14.07.14.28 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 14 Sep 2022 07:14:28 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jvpEOt99; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:46060 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oYT9n-0005OZ-Oh for patch@linaro.org; Wed, 14 Sep 2022 10:14:27 -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-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+patch=linaro.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: 605742 Delivered-To: patch@linaro.org Received: by 2002:ab3:1c02:0:b0:1e7:4ce8:c350 with SMTP id u2csp775785lth; Wed, 14 Sep 2022 07:18:32 -0700 (PDT) X-Google-Smtp-Source: AA6agR4Z/GZwXbPG3IS9VEndHAZXznhW+FpeyaIaonhgCs25bg0NYvQOjFk6pkYl72Up2uBZhjdf X-Received: by 2002:ac8:7f04:0:b0:343:36d:9a1f with SMTP id f4-20020ac87f04000000b00343036d9a1fmr33272768qtk.566.1663165112118; Wed, 14 Sep 2022 07:18:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663165112; cv=none; d=google.com; s=arc-20160816; b=t58BNWDEMD8/mzEFA3WWcDjzA2TshJU2Qz9B7lv9/Ieo11xA1oUbl2SyPEabmUEeyg cQH/nyPnUArJSeyewt6LGJfX5A2+mir8aq+aN2dvLCsCGgROXi/JayTxyuzvjt3grnRO 45u9jUCrrRiZKEMvxk/zO/KlTlUwAoyVL28mLEo1T/DCpaV6n8VdCaYN7wCnE93xASY6 lueZyXBdAB+w93ICql4nZdmDQ9i9CSWYRmrzCpo6ts1i2elkBdvGUQdokqic+kQFYItJ OsP9QOD9SJ8EZp7qj/9qM3rzM93Nchg+E+df3H6YM5CUuBFpn/WIm9QhXZVNKK+1zCRn T8Iw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=114N/Vlw3BZhk8rKh2FZz62XHFpOWPD/xYj4W6zefEA=; b=MjSkDRXnq2J/zNaXDBk8UIprV5NYc0FQ0a04VsUnKn3KF963PX60y/z/hW9QDtYuQC Cwyco/k5OIwwwm7v1nH9thZ7kZ9aX8RJOB+wB1eyystbLUI8+cAoTtETH8k/FQ+6vwR7 W/T649VTW7JMLatfuEoaw70p2B83i9CxyYQyidGtaEIjfYjaAMTZmersk2o5cfDMNmKc Zl9vsmAqXm4QTQe/KiuRlLZCEBCZiiOVoMQWYZJNnYSs+dabyIT2amjQrTQyb2w82HTQ YvFE/aQamFWo+qmm/JycYN2VCr1xjraaDNnAv/4jgxb72daeSteFYIA6rFEn9avDvXN8 XVWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JAI6LLO9; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id y14-20020a05620a44ce00b006bb91e28915si1455950qkp.460.2022.09.14.07.18.31 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 14 Sep 2022 07:18:32 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JAI6LLO9; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:36142 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oYTDj-0002Qr-J4 for patch@linaro.org; Wed, 14 Sep 2022 10:18:31 -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-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+patch=linaro.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: 605734 Delivered-To: patch@linaro.org Received: by 2002:ab3:1c02:0:b0:1e7:4ce8:c350 with SMTP id u2csp748486lth; Wed, 14 Sep 2022 06:39:27 -0700 (PDT) X-Google-Smtp-Source: AA6agR6SAfJxZvp6Dvf7Eu6B+H8L+xEtp/skwwsdqe4RiqongH6OtplfPlHIoxxZ2ETUU9QrO0++ X-Received: by 2002:a05:6214:1c09:b0:4ac:9160:7484 with SMTP id u9-20020a0562141c0900b004ac91607484mr20057893qvc.13.1663162767124; Wed, 14 Sep 2022 06:39:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663162767; cv=none; d=google.com; s=arc-20160816; b=hg7b45dsajrbMy/lz8DKWSZGDCH9J6pzL5FlN1gEFWNQis94vIg1vmk3wWZEqyRKge 5PDaTf89cILtBlUPlfLZyrv+pjSItepnpftC/+RQr/EGW+kyxMpWRnCbfFlUL+NKBINU W2igqMz3nOuijz+DIhAohLGpsez9SJTI5vcRChq/kVlmJhZwtfsHREj3Ni5De8doCwtA 33pbyUtdkJNdi6InmwFgT/O/+jogRQ6P82RWBVZI1zy9fNtNmjpDp3J6X170/fBg3iPi SZJiRuUb9iFSRtk9Xo5K4Cn/REcgc8paasHUlz4ARsPp5bQeMXH9AnLcl5GOdPxcP4zO on5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=C+e+mVoscBWQrZpSL5BUOyirKvbRFo9Wu/wSgD1UkkU=; b=IN3p8dci9cbG3WKnFL1jFZmDyUZoITSnWjWXsXENKTCOZc+JE2BasG7tnAYdDuD9t4 pC5h7762NtjOc0IwM47Pe1+n9dyJk51VvSIYMuB9m/0SQD+OED7Na/Xr57W0xLZVlCRq FutnphySXzmdaeBS/AZ/leP16mlFttGdnoaI6oD48yvMXHl1KulC6HAGds8k778ECRKJ 19fq9eoXpEA7K1MhbQ3xGe6rxIFsNG1Bsd0yXYQR1fUmSOwiuTf0+lJiXYYupluiG/VX XJb4xb4sqQj3CIyfMTjL+We3uDtZymnyxXaK32Fdt6PRiQ5RO95zcMpNjYCXHhJMbJgy /9Ow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qvLhzmQ0; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id ez15-20020a05622a4c8f00b0035cb883994asi1257384qtb.41.2022.09.14.06.39.26 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 14 Sep 2022 06:39:27 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qvLhzmQ0; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:47100 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oYSbu-0007AU-Kr for patch@linaro.org; Wed, 14 Sep 2022 09:39:26 -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-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+patch=linaro.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: 605735 Delivered-To: patch@linaro.org Received: by 2002:ab3:1c02:0:b0:1e7:4ce8:c350 with SMTP id u2csp749994lth; Wed, 14 Sep 2022 06:42:08 -0700 (PDT) X-Google-Smtp-Source: AA6agR498e2Isxdmqz+DryyLYT97NDJZuVttCxVvLJP1gj3jYmsTjsf3IRMuwMca1Iod3OS/jjt9 X-Received: by 2002:a05:622a:104c:b0:343:587c:1bc8 with SMTP id f12-20020a05622a104c00b00343587c1bc8mr32943817qte.484.1663162927936; Wed, 14 Sep 2022 06:42:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663162927; cv=none; d=google.com; s=arc-20160816; b=BPeWu5+Vl061FDbJUkKiyNbBPKx6uZl411yD/xwaDKzS/da6TuiOVV+byUhJhN/QpL 2GHOCsZPj9e+WgZP7jqEnTFkqw2V5cji8bT3RK1auM7ryTPc+IdkLLYTsDH76nnhOPC6 R87BqXbp/E8Q0QLYRSkSEFbfSdqZXMjh62OHWOyERyUgm8Ea5oHWHJeGChUZLHwMPPDF jENclOZBslHTwhhg/RJbiZomJDtCe3ZN8VlI7i/2MOYEHb423DuCH1VPJlWyCmt4nAxE /9t/cwtTkGrKQrDVjk5aERADfUfxfOtgV6SmShUelQK7kfflVT5Xlq/RNNvzzBfbv/cl hzOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=x+pcPPFHal1ZQJ+2Orzyi/XOmnBS6T266QkUkL9sejs=; b=fBp4syyApWOKw06FL8zDM8dOOzGzm4C6fSGq3yAB+qym292VavHKVt9MQOM+8e3l43 N0Mh0zYwbUMXgbkcxb+Ql7VU6gxkk/1ZnKN42mXe4uMIv/Dh7WSGnW6AU5M/DgQVX8IU 7Jhzk9nRxmu5QDsfo2SvyofkiGCRRPb0gtBMd3EH1iQ+24A3d3sb5XndvBjTdpdNWDkV odOLjlAacLZc96QmQvpu9Po1WOeRZZMyawNzuuoSp+LDUgZxCUgPvp1YZI133lsOdhtC /GCCA6ZcQyzDUGCNKDQLcAnG1hj43Cc3AuA0SYHaYWTP0X/lReUaplteSFy4pGao4/X1 q99Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=C180wwal; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id bq18-20020a05620a469200b006ce8a7187d1si842966qkb.36.2022.09.14.06.42.07 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 14 Sep 2022 06:42:07 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=C180wwal; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:33854 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oYSeV-0001Lc-Cn for patch@linaro.org; Wed, 14 Sep 2022 09:42:07 -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-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+patch=linaro.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: 605743 Delivered-To: patch@linaro.org Received: by 2002:ab3:1c02:0:b0:1e7:4ce8:c350 with SMTP id u2csp778455lth; Wed, 14 Sep 2022 07:22:54 -0700 (PDT) X-Google-Smtp-Source: AA6agR6HShwJKxK7+mYIO22pibjthrP2gBLhjO+itqlMbVTWSL/sRjxaj9du5qWd5SCWnMn8wPJF X-Received: by 2002:a05:622a:182a:b0:35b:b0aa:f418 with SMTP id t42-20020a05622a182a00b0035bb0aaf418mr15190884qtc.379.1663165374350; Wed, 14 Sep 2022 07:22:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663165374; cv=none; d=google.com; s=arc-20160816; b=ysNYOWqKAUZ6exlkDnWx1nDVVIn8ok/OuzzXLNaHyj+294eUsmb4WiCpuJ0CIDQtNJ ZBawvj35keAJ2dpZ+MK0Ry/g6K06cv2D1SURYR68CprY1HraFsVhmlcUOwr22HhBU7fY eDeRaC5OgkzapcfZ6MtRFBHMZ3qxlKxe3p29ilimXbBUHBAkNADenPIgKdiTkel9G2kb ElUalFExLCuBOP+lIXWvl9j6sBnNNwGGReeDsVsqxKw/+q+RKluK0Fsx8v0Bzm5Tstff Bcw0hWmWVaSUtJd149WLMjSwaVyl1rvN6TnQp5kooFRn0Tjsys3vOp40YBBpVRgxNnQ/ 7whw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=udcxGrqKWJR20Uk0cyTbsUdJXJIm7W+gSlqAXkcUlZ0=; b=00lZBNIdkQAtZcawbS9xFCP6n+D57RNTEhjZj3UZRousN5b1AwAkWvRAoV/zIv/+nV qN6vOWMEujVJqHz7DiEfOfw8Y/pSUEifTbSJ15qzPsa0JUpJQsFy7E8UP4FRBIiuXToE OXb8ze8vx0IViYga+WxfmDBkLFfKaMsppEGPaTIVrjIrX+KfIXhFfh7mKVwNTAfG5XyV Nf7DCpYb4sSJhRd4vdNGZ75MaR1KK7G9BxERQ80vuwRuIVXajAKH+Sj5ect53gTWLpe/ 35O9iVC4wVhtPeHk/8kBPwcsaMcbJ8rGRyJ+GUS9OZMDfaITJDfR5ZlwoFg89i4wMWn3 HQ/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CFWNTdFl; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id bm1-20020a05620a198100b006cbbe2b8dfbsi1325309qkb.73.2022.09.14.07.22.54 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 14 Sep 2022 07:22:54 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CFWNTdFl; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:37184 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oYTHx-0005oL-Py for patch@linaro.org; Wed, 14 Sep 2022 10:22:53 -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-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+patch=linaro.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: 605737 Delivered-To: patch@linaro.org Received: by 2002:ab3:1c02:0:b0:1e7:4ce8:c350 with SMTP id u2csp752663lth; Wed, 14 Sep 2022 06:46:33 -0700 (PDT) X-Google-Smtp-Source: AA6agR4BWvFm7DlEnCLRy6MQbivc+gXjHezGlo0g1wLFw1e5JTQZ+RhpX76EZ1DbhuDEKEX5xHjm X-Received: by 2002:ad4:4eec:0:b0:4a5:52eb:5cbe with SMTP id dv12-20020ad44eec000000b004a552eb5cbemr31955109qvb.34.1663163193251; Wed, 14 Sep 2022 06:46:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663163193; cv=none; d=google.com; s=arc-20160816; b=m7ydmUpccIx86KW9cAiI5qO9CfG+Chnc0Key6OprUFm+BYIBaTJmuHxHm8H9dROXF4 IJ6zn9U+1odmj24YEmmkfPd+n3pdDs3FNPPSftrolJIbWTXa32hznQsJlv2t6tWBn9um 0V+4/TumAq92Gg9I33tQlJW6WX5EWx+t0fVp/iNdt5W/eTtAv2ZcubaEfuDuTkeCd7XS dV1jLhsFnctjKqltDJOotC2DYlSzxhQ/k6y+c/AAC5M+gLdLSDLlTYnuy1lhlWtKnUGA 7SasioFaj82sE/Z3qqouvOy5Ay38xfHqiAvAhW4aMmD1XYKLm0j4N7AFV+p9Yk5g6Cwy MujA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=rTB12Kd3V2NAFpRhE4AcHzoc+HouSttzxGrYvX7ucFI=; b=vy3fiUlEpa9BMEDxOx3mALaS/WV90Kx6z7r1E9kPGlOTl5UyJwTTPqSKPJXN1EUiT0 JQx0ecVHIV8+7yMWlgLb12ixBwQLfmE/tN0UHMPkdA0X0LkHTSJ7/f+MgAoIieiJ6iV9 kUOh3tfij6t76WGcWj3XZZORI7AW0/8DAKm5HkMqMdCEyQr0ZK5sToHgc6iTL3GxHVz5 j6/xSBS5CmlQU/c9uXNi8+pqa45f++GmxEN5sDbUn0b4wjelr8XvY6zoAg0+6PiIT2Cz f03yxIg1NI5u4/WLckTxy7XgxTthB7EJTjZOHi2jmQHaV+aNHLPiwnIAuoT8MU5HhoUd PNyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=tzYAvW5i; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id g7-20020a0562141cc700b0049729e5f831si1347496qvd.49.2022.09.14.06.46.33 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 14 Sep 2022 06:46:33 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=tzYAvW5i; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:47232 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oYSil-0006oa-NJ for patch@linaro.org; Wed, 14 Sep 2022 09:46:32 -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-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+patch=linaro.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: 605736 Delivered-To: patch@linaro.org Received: by 2002:ab3:1c02:0:b0:1e7:4ce8:c350 with SMTP id u2csp751426lth; Wed, 14 Sep 2022 06:44:37 -0700 (PDT) X-Google-Smtp-Source: AA6agR6ohYF491LJpKTWChv8ePzhgQufN5lAhNh13Ao/Jq0to8tbgcfmM6NQkLHva+5ynIZwGarI X-Received: by 2002:a05:620a:29c4:b0:6bc:638d:cf30 with SMTP id s4-20020a05620a29c400b006bc638dcf30mr25608857qkp.443.1663163077274; Wed, 14 Sep 2022 06:44:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663163077; cv=none; d=google.com; s=arc-20160816; b=XTRcMb321n1Z0gxTkBI94jK9E1TWVJVJTKfIfHxcSK3mvZ5CGVo/i/je8sMxaWW8pj 51NSWPYXO6gXkeeahTC49qTeIDetZUjbyqy2E2FNEuEEcwl+Ir7e1iKyFMGwsxKaRTqf iG5zY/QAKaA5V1ZGp21klyryEPKk02qjZ8+N0NEqafnkkosr6Efh3n440g7EgnWqzQHU gf0sy6E/lwVfwLnECFILxYyTq6XWh03iFsyejHDz8ptMUDY/JEBG1l5fCqfd0JzKt0z4 0YfAx28tI7t1ly2jzeGIhmd4ooeV9nBu0wwBorNU0WZn0ZhD8zPlAgI4qP0sQzKiZnBz f96g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=PXOhY/GLE5ushsuwq2usxIkhOBcQf53LWE9OWb978Zw=; b=MlSxRqQNO1YChqm7MKZP1MQ+1SeU1PRzTPdfIVA1t7Kr4/BtKGpBLlAsR2/Bxiipiw pQLWdavjo1nwRE1W6Hs9Nkhouhpd9ceRo0/Cpjdo/heBTv/xamd4v9plG3/lcbIR0wNq sYAIr8+yfjQtv9YH34wK1weetuvy8INFXQZVGN9ahevYkypDPjGPeFzaxJ3TFOaHzY5y ir990v4ALfoix6cpXLVBKnoU+t2S/qhAFiNnz2zTQAQTBQhM/VLfnBmTApdrKZYMF+K3 2A37lLo2LAZ35PxHO+9/OR+mYfjnQda8I4hkMq4x8WbMfoIOzalwwtJ7/uCN6IyYm+B9 Nd8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=v6z0wlGt; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id f7-20020a05620a408700b006ce194a3269si1338511qko.295.2022.09.14.06.44.37 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 14 Sep 2022 06:44:37 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=v6z0wlGt; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:60062 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oYSgu-0004JZ-PC for patch@linaro.org; Wed, 14 Sep 2022 09:44:36 -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-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+patch=linaro.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: 605741 Delivered-To: patch@linaro.org Received: by 2002:ab3:1c02:0:b0:1e7:4ce8:c350 with SMTP id u2csp775077lth; Wed, 14 Sep 2022 07:17:27 -0700 (PDT) X-Google-Smtp-Source: AA6agR63twpJIbCoPDRdn52APXaZjO3F9BffO6rKYDOoW+lx5Ya8lK1OrG+j3RHEpGlnc7oueAJR X-Received: by 2002:a05:620a:4155:b0:6ce:3e56:c1e5 with SMTP id k21-20020a05620a415500b006ce3e56c1e5mr10581887qko.350.1663165047042; Wed, 14 Sep 2022 07:17:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663165047; cv=none; d=google.com; s=arc-20160816; b=ac9MKeAmwXNmk9VcGHPQ8dF/k+Q8sPySRnuVzhtLANVQ6hD4QKQ75368VRjCVXRZnq VzcOXoO1R2hCtsnAsyoj2oMstiIYW05YqxGkhS/nf/r1Ca5tm8Gw1b7Kmqhb7+2PquT8 cIlkUAQqS3Ot7II49JGxajrMH1bodfghAZDGVrAxbKkD0vBbgrZEJ/XIfEAtj9GjNenp CjkmGeQ7YWgu2ejFploJW8FvjTJEAIfQxiHlYtxEHzRgHqUHjSVxwZuCzREJKol+4A9g 8eURHxBqCi/4MTRYIzg0JJNblV48aGlsAXyP3ZbkLfcW8Ohwg3l9jGAgQL6gdv+QA3C1 VTxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=+jD9lKzsh1CbGMDE7cH4Ty4evA7hw2r7Od0SGTHPpGM=; b=t/3BDCxxphrkCfqmQsjN3OHd0OXOiwxLNogDw22qbk1Lv5/kq82Hl8/DD2lZZg7QDl CfeXruXPp1bkAqPMm3qnlBwp6nYGO31jmZjePvmEtcPKq0l2qluPrQlHXZ9Y4MuQ2tyS XbtiCZNhU3uYatQG0d58B32hajpVxdaHcbH79u6U1IDmM+BbGq8u1jjOTQgCGd6nrMrs xp7kqAWpvnDKzNLBfWqL1XM/tXFGCxG+46vnk27streelWxKXvCY3sfuXEswMQfHnuNH xYadsRXKeL8NqRd4OqLbEaGsuw+VHn9VzWFMGPLOEe0Pwvw1S72P0SMkEm21lHNMQZ9F +Wpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kO9EoxQE; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id t10-20020a05620a450a00b006ce4c19d1aasi1448278qkp.35.2022.09.14.07.17.26 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 14 Sep 2022 07:17:27 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kO9EoxQE; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:36760 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oYTCg-0001Tj-HR for patch@linaro.org; Wed, 14 Sep 2022 10:17:26 -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-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+patch=linaro.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: 605738 Delivered-To: patch@linaro.org Received: by 2002:ab3:1c02:0:b0:1e7:4ce8:c350 with SMTP id u2csp754907lth; Wed, 14 Sep 2022 06:50:33 -0700 (PDT) X-Google-Smtp-Source: AA6agR6i3KAyCMAoAMfcspxGcEsI6k5OYKTAVyHGvR9/m/+AlL8azxOKJ9MDbLk9jIu1GZMTWXvz X-Received: by 2002:ae9:f810:0:b0:6ce:3cf5:42cc with SMTP id x16-20020ae9f810000000b006ce3cf542ccmr10073812qkh.216.1663163433188; Wed, 14 Sep 2022 06:50:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663163433; cv=none; d=google.com; s=arc-20160816; b=SJORlKD8CxscGuCGV9kILTWnuYHdTXyNQokc96595dtMPEahDHOZbZ0N3nvNch+zsV VbNqgsxQcxF05WuX/WFN8ItazAKfz3V/sV+oTsg1Sc3pvKyrhsAAXIe8xDHQ4YpqwGw7 iiqUv+Pz9dFkulbdL/fmU/Gi++OXn0DqkRJSZXRvzaB3cgpQEBU8iwMA4e8VLs13ue1A vu+Xr7B/i+uJ81pgpeHCpZKknI8ODZYz7wZ7Av8mvo/0EfYYUY8hbu+uJjerXMUnsL9o pTW0hkAFkPfvL1rJSG4k/P9cgvUIclec1e+ULJPldu9rXFoMtRTNFegjORanV8xt2dUQ 3vhw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Fst4x49rn2TZohR5patrgQl48OlHihnTjCr3gqAYNQs=; b=TwJCGa3L4TelFTGeRONzD6Gke73tzDfCobIiX3S1oWc0F/jv4nSWp7Ro1qM5XrS1dB 6gsJ9QeDgzEkhnLys4NbWZvPfDPh2Don5XAAYZDo6UrOmTJ5FOXaqDgv0YzO8/y/Ivgy BqE2Uiu3UBBBiWa6+xsW2S6ESK8wA39MAz27tRYgirtZ2f9E8IYzh+kVQcwgxOJsLMP+ qGuXL3NKYt4gzG4guDkugzXmIh3wbIs12k7bCNFxyixTPtx/6aPNI4q6F3HbG+bvea+J 7ki/FIQiKiUm99LoKuuhUtQ29Th6fq2eNhKLjpin+a2U0tUPkPKzqNQ8587dLmr/oCtl tKbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=n2hdNL0X; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d204-20020ae9efd5000000b006b5d3a6f1adsi1117986qkg.196.2022.09.14.06.50.33 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 14 Sep 2022 06:50:33 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=n2hdNL0X; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:52120 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oYSme-00047c-Lt for patch@linaro.org; Wed, 14 Sep 2022 09:50:32 -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-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+patch=linaro.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: 605744 Delivered-To: patch@linaro.org Received: by 2002:ab3:1c02:0:b0:1e7:4ce8:c350 with SMTP id u2csp780128lth; Wed, 14 Sep 2022 07:25:27 -0700 (PDT) X-Google-Smtp-Source: AA6agR7GF7B5XYhRY/2ZWMXmDQUvlFpxfGSYMHzoBaNh7PBnM+MTBhDH9x7ToSsDqUtkxwo761OS X-Received: by 2002:ae9:ef4f:0:b0:6cb:d294:3333 with SMTP id d76-20020ae9ef4f000000b006cbd2943333mr21900017qkg.511.1663165527745; Wed, 14 Sep 2022 07:25:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663165527; cv=none; d=google.com; s=arc-20160816; b=oKfEmuEvj24yfLTOKp5z3lztJYXUQBB+j2PURKfkbM/DaezB6WX+cEVCCgpoWcDuXZ TaDIQpz8LFaBZOHVbLiCgAch6b45qQ+eogj0+Iikg7650ypj9ZK+1rxUDbf/MI2Ki8n6 iHI6QGljg7CQzN68b+Sy7KlDSq8xHjaaRwoM0HXLmWmoC/PcWuxG3274im7L4ktX+R6l lCS0gllIM6aiS1tKCaO99ADRJaiUH+H6KF4oiBl/oisPc/RhnednhXpisiMypjifexdn apM9UoIL2u3pVSRyZkqCnTW+TbF8BwwTKKqVaccbtong2/7kjX+gV0wTlLkAyKLeQL1e H7zg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=5hn5ZCIWBTjKXNmV0CdKODbs07VBGmCbJWLiyFIEtk8=; b=jovD+Kkm0cQv7Xsp7pemSQ5FifbwquUnULb4CgM4Q+z6WVL//mPXKr5X2KQRvYJ2CE d12F1640/T659DZO1+Qn9AJ3mRmzSR1yHuv+NJKJZIxgpbc9Jbsd8esuZXCBRDTcivU1 qT8yHe7fgY2vtShHPkMukDid5yzNyERm4kPyC/ZkzxToVay79Sy6DSfsjv5ewH1TUzTi ooTPx78/fXJyXI3rmJ/zdFQI9ph0frIfqrfnV2OyNcXgJeS5BrJGOEqygdUuV/652Pk9 BYk+XzhaZMLCGIHsDWBb9kaEfWMOypzX/smX7TE/7Nw8H5OY3ynKuaNdfkAZg8/SVxTY h/2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=UT2iBFut; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id x8-20020a05620a258800b006ce7334ac99si1353321qko.636.2022.09.14.07.25.27 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 14 Sep 2022 07:25:27 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=UT2iBFut; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:42614 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oYTKR-0000ld-7O for patch@linaro.org; Wed, 14 Sep 2022 10:25:27 -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-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+patch=linaro.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);