From nobody Sun Feb 8 18:29:22 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1636344100235397.7529333510722; Sun, 7 Nov 2021 20:01:40 -0800 (PST) Received: from [::1] (port=35016 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mjvql-00018B-6G for importer@patchew.org; Sun, 07 Nov 2021 23:01:39 -0500 Received: from eggs.gnu.org ([209.51.188.92]:48370) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mjvhw-0006kt-VT for qemu-devel@nongnu.org; Sun, 07 Nov 2021 22:52:34 -0500 Received: from [2607:f8b0:4864:20::133] (port=34374 helo=mail-il1-x133.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mjvhv-0002tr-18 for qemu-devel@nongnu.org; Sun, 07 Nov 2021 22:52:32 -0500 Received: by mail-il1-x133.google.com with SMTP id j28so15551727ila.1 for ; Sun, 07 Nov 2021 19:52:30 -0800 (PST) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id x15sm876909iob.8.2021.11.07.19.52.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Nov 2021 19:52:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=98BqBI8TmV8YvyFkZ3y+XgKQlmpyG8KzRCO1YXNy77I=; b=m2GUU55SRn7izQSOGfZhs5tHxX00bTz/xEf17iYq1jPVw+m6QZD3kofFabYA96lasQ DvMRq4KtjPrerKQl1f5JaOLrgcMpgM9fDnpl4HdYDrKLiyjOfgmgrGVbz6QAql57TVCx co5UcT6DyFO7jbJ3OHCA0zwvVIDLQ/ZZFkTmiI3aButqtMrSIc/wcBmCvZKdiBtbjWW8 vdHZ9piIBlHf9NIWJi5z0bHitLMOfgl2ENh57yQ7MFbYXZ4V/M2fFBQXNCn3OrXnJ2Yd 8hJkFdYHh4OdszAIy49jIE/mM7886+Hv0096vnJgITzQcf/Gzqq/iABSG825v0nGiebK YyTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=98BqBI8TmV8YvyFkZ3y+XgKQlmpyG8KzRCO1YXNy77I=; b=E6iF7gwn9QRTfMhkXbofHSb3iRfbAzNe0EvRBQ/42h5lSyhLMn6poQ6UJgg/zZjMVT TCxGEzG7IbVw3FYP52SEpEFe7HzKVqWo/xMewwyqHdVuTLZQiu0I/5bpZt6BkKC7UROZ DMcuPfu49JRO3BhPrMaGFhmlno5ieexV/2vBmQDSeBoVvf7U2jTwS8zwgfVI30BmKKsx 0rs97O3BzXo8odloO2OHk8HUS2t3YrOWJ/o84M/vm+vgSndwyeuK4JEUat9bZgXJvC2l fQuKj49LO694Ea2WCPVNe8monQ3dHL1PK85bdG188wgJQD7juFnnvd9UhzEmSKqT/g+e et4g== X-Gm-Message-State: AOAM531WtJ+bH0dLBvZVU/dFxB3MJFHf+kQK4VC+3wKh68JheU9JfKXe 15VDuYwvxUBfKghCy3EY9QQsm9X93J8WFA== X-Google-Smtp-Source: ABdhPJy+t1j0Okd4J9o0BDAMj6xolQTA/DGlL1kX9YOJoySpNpwpaCkYaXrkaOjG4JAZd92FIKNx4g== X-Received: by 2002:a05:6e02:20e4:: with SMTP id q4mr45550220ilv.71.1636343549810; Sun, 07 Nov 2021 19:52:29 -0800 (PST) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PATCH v5 21/37] bsd-user/arm/target_arch_cpu.h: Implement system call dispatch Date: Sun, 7 Nov 2021 20:51:20 -0700 Message-Id: <20211108035136.43687-22-imp@bsdimp.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211108035136.43687-1-imp@bsdimp.com> References: <20211108035136.43687-1-imp@bsdimp.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::133 (failed) Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::133; envelope-from=imp@bsdimp.com; helo=mail-il1-x133.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Stacey Son , qemu-trivial@nongnu.org, Kyle Evans , Michael Tokarev , Laurent Vivier , Philippe Mathieu-Daude , Richard Henderson , Warner Losh Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1636344102343100001 Content-Type: text/plain; charset="utf-8" Implement the system call dispatch. This implements all three kinds of system call: direct and the two indirect variants. It handles all the special cases for thumb as well. Signed-off-by: Stacey Son Signed-off-by: Kyle Evans Signed-off-by: Warner Losh Reviewed-by: Kyle Evans Reviewed-by: Richard Henderson --- bsd-user/arm/target_arch_cpu.h | 94 ++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) diff --git a/bsd-user/arm/target_arch_cpu.h b/bsd-user/arm/target_arch_cpu.h index 905a5ffaff..c675419c30 100644 --- a/bsd-user/arm/target_arch_cpu.h +++ b/bsd-user/arm/target_arch_cpu.h @@ -40,6 +40,7 @@ static inline void target_cpu_loop(CPUARMState *env) { int trapnr; target_siginfo_t info; + unsigned int n; CPUState *cs =3D env_cpu(env); =20 for (;;) { @@ -62,6 +63,99 @@ static inline void target_cpu_loop(CPUARMState *env) /* TODO: What about instruction emulation? */ } break; + case EXCP_SWI: + case EXCP_BKPT: + { + /* + * system call + * See arm/arm/trap.c cpu_fetch_syscall_args() + */ + if (trapnr =3D=3D EXCP_BKPT) { + if (env->thumb) { + env->regs[15] +=3D 2; + } else { + env->regs[15] +=3D 4; + } + } + n =3D env->regs[7]; + if (bsd_type =3D=3D target_freebsd) { + int ret; + abi_ulong params =3D get_sp_from_cpustate(env); + int32_t syscall_nr =3D n; + int32_t arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8; + + /* See arm/arm/trap.c cpu_fetch_syscall_args() */ + if (syscall_nr =3D=3D TARGET_FREEBSD_NR_syscall) { + syscall_nr =3D env->regs[0]; + arg1 =3D env->regs[1]; + arg2 =3D env->regs[2]; + arg3 =3D env->regs[3]; + get_user_s32(arg4, params); + params +=3D sizeof(int32_t); + get_user_s32(arg5, params); + params +=3D sizeof(int32_t); + get_user_s32(arg6, params); + params +=3D sizeof(int32_t); + get_user_s32(arg7, params); + arg8 =3D 0; + } else if (syscall_nr =3D=3D TARGET_FREEBSD_NR___sysca= ll) { + syscall_nr =3D env->regs[0]; + arg1 =3D env->regs[2]; + arg2 =3D env->regs[3]; + get_user_s32(arg3, params); + params +=3D sizeof(int32_t); + get_user_s32(arg4, params); + params +=3D sizeof(int32_t); + get_user_s32(arg5, params); + params +=3D sizeof(int32_t); + get_user_s32(arg6, params); + arg7 =3D 0; + arg8 =3D 0; + } else { + arg1 =3D env->regs[0]; + arg2 =3D env->regs[1]; + arg3 =3D env->regs[2]; + arg4 =3D env->regs[3]; + get_user_s32(arg5, params); + params +=3D sizeof(int32_t); + get_user_s32(arg6, params); + params +=3D sizeof(int32_t); + get_user_s32(arg7, params); + params +=3D sizeof(int32_t); + get_user_s32(arg8, params); + } + ret =3D do_freebsd_syscall(env, syscall_nr, arg1, arg2= , arg3, + arg4, arg5, arg6, arg7, arg8); + /* + * Compare to arm/arm/vm_machdep.c + * cpu_set_syscall_retval() + */ + if (-TARGET_EJUSTRETURN =3D=3D ret) { + /* + * Returning from a successful sigreturn syscall. + * Avoid clobbering register state. + */ + break; + } + if (-TARGET_ERESTART =3D=3D ret) { + env->regs[15] -=3D env->thumb ? 2 : 4; + break; + } + if ((unsigned int)ret >=3D (unsigned int)(-515)) { + ret =3D -ret; + cpsr_write(env, CPSR_C, CPSR_C, CPSRWriteByInstr); + env->regs[0] =3D ret; + } else { + cpsr_write(env, 0, CPSR_C, CPSRWriteByInstr); + env->regs[0] =3D ret; /* XXX need to handle lseek(= )? */ + /* env->regs[1] =3D 0; */ + } + } else { + fprintf(stderr, "qemu: bsd_type (=3D %d) syscall " + "not supported\n", bsd_type); + } + } + break; case EXCP_INTERRUPT: /* just indicate that signals should be handled asap */ break; --=20 2.33.0