From nobody Mon May 6 08:55:16 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1523474060960374.65087049526426; Wed, 11 Apr 2018 12:14:20 -0700 (PDT) Received: from localhost ([::1]:48847 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f6LCG-0004Hj-0g for importer@patchew.org; Wed, 11 Apr 2018 15:14:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37880) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f6Kvx-0005wX-3W for qemu-devel@nongnu.org; Wed, 11 Apr 2018 14:57:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f6Kvt-0007nB-8A for qemu-devel@nongnu.org; Wed, 11 Apr 2018 14:57:29 -0400 Received: from mout.kundenserver.de ([217.72.192.73]:55805) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1f6Kvs-0007mZ-Py; Wed, 11 Apr 2018 14:57:25 -0400 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue105 [212.227.15.183]) with ESMTPSA (Nemesis) id 0MLfrX-1f63oP30TL-000vMZ; Wed, 11 Apr 2018 20:57:07 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Date: Wed, 11 Apr 2018 20:56:33 +0200 Message-Id: <20180411185651.21351-2-laurent@vivier.eu> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180411185651.21351-1-laurent@vivier.eu> References: <20180411185651.21351-1-laurent@vivier.eu> X-Provags-ID: V03:K1:TdgEf5NdmMq3QVT9MYsvE7dehz4gRTN8ECYnjjRnYe9CRQVp6+r d5SGBznAgBnLhrcLFQ9b2Df384rLPP6IFtP6x0p82tpr68JKeipDXpdgOVduL0TV2416UWi s1fMWmZM56QXvvbbw6GvZ3RAW6JbPARZW6lcQ/6fACWBk4rlL1asVv3ILK/Tihn5FR8VPwu 7wXBzganAAZ2mKtDA4oeA== X-UI-Out-Filterresults: notjunk:1;V01:K0:6ymgDHopSVg=:KKD2E7ajtgkHgiVp0aBQeW KI/I1tbh4xWbhsum6a3l53FskhRqbElck973WUUNfSQKtd6yMNoR3DjWKvm0TlxMTUghNVnG2 MTDK5KFm6L4ItPGsLiOIhhixAFQra9BLbFyXmMAs1clcwivSTB/02jo2EQ4y3Hr/Y28mHPI67 i2wRBB3ZE1V2kxGzFflg7UzSzFKooa9RBBXiXtEcxeJV01HzQaVXfyBKM/uVpO4YL92aQKGEM j6DQawdRkn+w7rsZEIuI3HaZNrBFHvyJYxeXkVXJmWLFtmUZP+H2uVzGCnWBpkM7Eiel1bH0u 37EuuN8G23yvZrwRNzXI3WMZhEU+5i3/6BlqiebMyabObt1pm9u4o33y/5RelvJBULr0h0gk/ J/mYzcugiH7m/o7XfjCLGovOLxUwmCbPWo9/tSlgxELOHf45Rdw0Gl8jM6jjWsIOC7ytOZPG4 jjgg5evETCH6LUdIVlVKm2khnX4th7borQn5RKDLSbTNJWJUeJjn2LxwDbQ//kBJc0rdJBoFZ FvOqYN2peuLz6m2zkG8WyXHSZfhbKbUIet8Hcz4FVOBTj/7vSP2RmgQ2UuXZ3ZPzTJ18n+iCL DnywLNsTOOBo2Es3ywvroSEwaJewuJqjVDg/V1Nv0xcaMldirgO/wMRC0Bvnb9tPXrmAtMl2D XzgJE7okffWNVxnB9kUw7/GGnpTF/bkMSTvnFppR3ZHR3bmNsJvHPgaM9iqHsq5PZqYioMt8X Uq2+7BWoyVB8c8jZ4Rl6Vtj2Y8QJJuCrczAdvw== X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 217.72.192.73 Subject: [Qemu-devel] [PATCH for 2.13 v2 01/19] linux-user: create a dummy per arch cpu_loop.c X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Cornelia Huck , Riku Voipio , Richard Henderson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Laurent Vivier , qemu-s390x@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Create a cpu_loop-common.h for future use by these new files and use it in the existing main.c Introduce target_cpu_copy_regs(): declare the function in cpu_loop-common.h and an empty function for each target, to move all the cpu_loop prologues to this function. Signed-off-by: Laurent Vivier Reviewed-by: Richard Henderson --- linux-user/Makefile.objs | 3 ++- linux-user/aarch64/cpu_loop.c | 26 ++++++++++++++++++++++++++ linux-user/alpha/cpu_loop.c | 26 ++++++++++++++++++++++++++ linux-user/arm/cpu_loop.c | 26 ++++++++++++++++++++++++++ linux-user/cpu_loop-common.h | 37 +++++++++++++++++++++++++++++++++++++ linux-user/cris/cpu_loop.c | 26 ++++++++++++++++++++++++++ linux-user/hppa/cpu_loop.c | 26 ++++++++++++++++++++++++++ linux-user/i386/cpu_loop.c | 26 ++++++++++++++++++++++++++ linux-user/m68k/cpu_loop.c | 26 ++++++++++++++++++++++++++ linux-user/main.c | 17 +++-------------- linux-user/microblaze/cpu_loop.c | 26 ++++++++++++++++++++++++++ linux-user/mips/cpu_loop.c | 26 ++++++++++++++++++++++++++ linux-user/mips64/cpu_loop.c | 26 ++++++++++++++++++++++++++ linux-user/nios2/cpu_loop.c | 26 ++++++++++++++++++++++++++ linux-user/openrisc/cpu_loop.c | 26 ++++++++++++++++++++++++++ linux-user/ppc/cpu_loop.c | 26 ++++++++++++++++++++++++++ linux-user/riscv/cpu_loop.c | 26 ++++++++++++++++++++++++++ linux-user/s390x/cpu_loop.c | 26 ++++++++++++++++++++++++++ linux-user/sh4/cpu_loop.c | 26 ++++++++++++++++++++++++++ linux-user/sparc/cpu_loop.c | 26 ++++++++++++++++++++++++++ linux-user/sparc64/cpu_loop.c | 26 ++++++++++++++++++++++++++ linux-user/tilegx/cpu_loop.c | 26 ++++++++++++++++++++++++++ linux-user/x86_64/cpu_loop.c | 26 ++++++++++++++++++++++++++ linux-user/xtensa/cpu_loop.c | 26 ++++++++++++++++++++++++++ 24 files changed, 588 insertions(+), 15 deletions(-) create mode 100644 linux-user/aarch64/cpu_loop.c create mode 100644 linux-user/alpha/cpu_loop.c create mode 100644 linux-user/arm/cpu_loop.c create mode 100644 linux-user/cpu_loop-common.h create mode 100644 linux-user/cris/cpu_loop.c create mode 100644 linux-user/hppa/cpu_loop.c create mode 100644 linux-user/i386/cpu_loop.c create mode 100644 linux-user/m68k/cpu_loop.c create mode 100644 linux-user/microblaze/cpu_loop.c create mode 100644 linux-user/mips/cpu_loop.c create mode 100644 linux-user/mips64/cpu_loop.c create mode 100644 linux-user/nios2/cpu_loop.c create mode 100644 linux-user/openrisc/cpu_loop.c create mode 100644 linux-user/ppc/cpu_loop.c create mode 100644 linux-user/riscv/cpu_loop.c create mode 100644 linux-user/s390x/cpu_loop.c create mode 100644 linux-user/sh4/cpu_loop.c create mode 100644 linux-user/sparc/cpu_loop.c create mode 100644 linux-user/sparc64/cpu_loop.c create mode 100644 linux-user/tilegx/cpu_loop.c create mode 100644 linux-user/x86_64/cpu_loop.c create mode 100644 linux-user/xtensa/cpu_loop.c diff --git a/linux-user/Makefile.objs b/linux-user/Makefile.objs index 811a7f5ce5..59a5c17354 100644 --- a/linux-user/Makefile.objs +++ b/linux-user/Makefile.objs @@ -1,6 +1,7 @@ obj-y =3D main.o syscall.o strace.o mmap.o signal.o \ elfload.o linuxload.o uaccess.o uname.o \ - safe-syscall.o $(TARGET_ABI_DIR)/signal.o + safe-syscall.o $(TARGET_ABI_DIR)/signal.o \ + $(TARGET_ABI_DIR)/cpu_loop.o =20 obj-$(TARGET_HAS_BFLT) +=3D flatload.o obj-$(TARGET_I386) +=3D vm86.o diff --git a/linux-user/aarch64/cpu_loop.c b/linux-user/aarch64/cpu_loop.c new file mode 100644 index 0000000000..b7700a5561 --- /dev/null +++ b/linux-user/aarch64/cpu_loop.c @@ -0,0 +1,26 @@ +/* + * qemu user cpu loop + * + * Copyright (c) 2003-2008 Fabrice Bellard + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include "qemu/osdep.h" +#include "qemu.h" +#include "cpu_loop-common.h" + +void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs) +{ +} diff --git a/linux-user/alpha/cpu_loop.c b/linux-user/alpha/cpu_loop.c new file mode 100644 index 0000000000..b7700a5561 --- /dev/null +++ b/linux-user/alpha/cpu_loop.c @@ -0,0 +1,26 @@ +/* + * qemu user cpu loop + * + * Copyright (c) 2003-2008 Fabrice Bellard + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include "qemu/osdep.h" +#include "qemu.h" +#include "cpu_loop-common.h" + +void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs) +{ +} diff --git a/linux-user/arm/cpu_loop.c b/linux-user/arm/cpu_loop.c new file mode 100644 index 0000000000..b7700a5561 --- /dev/null +++ b/linux-user/arm/cpu_loop.c @@ -0,0 +1,26 @@ +/* + * qemu user cpu loop + * + * Copyright (c) 2003-2008 Fabrice Bellard + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include "qemu/osdep.h" +#include "qemu.h" +#include "cpu_loop-common.h" + +void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs) +{ +} diff --git a/linux-user/cpu_loop-common.h b/linux-user/cpu_loop-common.h new file mode 100644 index 0000000000..ffe3fe9ad5 --- /dev/null +++ b/linux-user/cpu_loop-common.h @@ -0,0 +1,37 @@ +/* + * qemu user cpu loop + * + * Copyright (c) 2003-2008 Fabrice Bellard + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#ifndef CPU_LOOP_COMMON_H +#define CPU_LOOP_COMMON_H + +#include "exec/log.h" + +#define EXCP_DUMP(env, fmt, ...) \ +do { \ + CPUState *cs =3D ENV_GET_CPU(env); \ + fprintf(stderr, fmt , ## __VA_ARGS__); \ + cpu_dump_state(cs, stderr, fprintf, 0); \ + if (qemu_log_separate()) { \ + qemu_log(fmt, ## __VA_ARGS__); \ + log_cpu_state(cs, 0); \ + } \ +} while (0) + +void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs); +#endif diff --git a/linux-user/cris/cpu_loop.c b/linux-user/cris/cpu_loop.c new file mode 100644 index 0000000000..b7700a5561 --- /dev/null +++ b/linux-user/cris/cpu_loop.c @@ -0,0 +1,26 @@ +/* + * qemu user cpu loop + * + * Copyright (c) 2003-2008 Fabrice Bellard + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include "qemu/osdep.h" +#include "qemu.h" +#include "cpu_loop-common.h" + +void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs) +{ +} diff --git a/linux-user/hppa/cpu_loop.c b/linux-user/hppa/cpu_loop.c new file mode 100644 index 0000000000..b7700a5561 --- /dev/null +++ b/linux-user/hppa/cpu_loop.c @@ -0,0 +1,26 @@ +/* + * qemu user cpu loop + * + * Copyright (c) 2003-2008 Fabrice Bellard + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include "qemu/osdep.h" +#include "qemu.h" +#include "cpu_loop-common.h" + +void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs) +{ +} diff --git a/linux-user/i386/cpu_loop.c b/linux-user/i386/cpu_loop.c new file mode 100644 index 0000000000..b7700a5561 --- /dev/null +++ b/linux-user/i386/cpu_loop.c @@ -0,0 +1,26 @@ +/* + * qemu user cpu loop + * + * Copyright (c) 2003-2008 Fabrice Bellard + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include "qemu/osdep.h" +#include "qemu.h" +#include "cpu_loop-common.h" + +void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs) +{ +} diff --git a/linux-user/m68k/cpu_loop.c b/linux-user/m68k/cpu_loop.c new file mode 100644 index 0000000000..b7700a5561 --- /dev/null +++ b/linux-user/m68k/cpu_loop.c @@ -0,0 +1,26 @@ +/* + * qemu user cpu loop + * + * Copyright (c) 2003-2008 Fabrice Bellard + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include "qemu/osdep.h" +#include "qemu.h" +#include "cpu_loop-common.h" + +void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs) +{ +} diff --git a/linux-user/main.c b/linux-user/main.c index 8907a84114..09045f877c 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -33,9 +33,9 @@ #include "qemu/timer.h" #include "qemu/envlist.h" #include "elf.h" -#include "exec/log.h" #include "trace/control.h" #include "target_elf.h" +#include "cpu_loop-common.h" =20 char *exec_path; =20 @@ -50,17 +50,6 @@ unsigned long mmap_min_addr; unsigned long guest_base; int have_guest_base; =20 -#define EXCP_DUMP(env, fmt, ...) \ -do { \ - CPUState *cs =3D ENV_GET_CPU(env); \ - fprintf(stderr, fmt , ## __VA_ARGS__); \ - cpu_dump_state(cs, stderr, fprintf, 0); \ - if (qemu_log_separate()) { \ - qemu_log(fmt, ## __VA_ARGS__); \ - log_cpu_state(cs, 0); \ - } \ -} while (0) - /* * When running 32-on-64 we should make sure we can fit all of the possible * guest address space into a contiguous chunk of virtual host memory. @@ -4736,6 +4725,8 @@ int main(int argc, char **argv, char **envp) tcg_prologue_init(tcg_ctx); tcg_region_init(); =20 + target_cpu_copy_regs(env, regs); + #if defined(TARGET_I386) env->cr[0] =3D CR0_PG_MASK | CR0_WP_MASK | CR0_PE_MASK; env->hflags |=3D HF_PE_MASK | HF_CPL_MASK; @@ -5125,8 +5116,6 @@ int main(int argc, char **argv, char **envp) env->sregs[WINDOW_START] =3D regs->windowstart; env->pc =3D regs->pc; } -#else -#error unsupported target CPU #endif =20 #if defined(TARGET_ARM) || defined(TARGET_M68K) diff --git a/linux-user/microblaze/cpu_loop.c b/linux-user/microblaze/cpu_l= oop.c new file mode 100644 index 0000000000..b7700a5561 --- /dev/null +++ b/linux-user/microblaze/cpu_loop.c @@ -0,0 +1,26 @@ +/* + * qemu user cpu loop + * + * Copyright (c) 2003-2008 Fabrice Bellard + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include "qemu/osdep.h" +#include "qemu.h" +#include "cpu_loop-common.h" + +void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs) +{ +} diff --git a/linux-user/mips/cpu_loop.c b/linux-user/mips/cpu_loop.c new file mode 100644 index 0000000000..b7700a5561 --- /dev/null +++ b/linux-user/mips/cpu_loop.c @@ -0,0 +1,26 @@ +/* + * qemu user cpu loop + * + * Copyright (c) 2003-2008 Fabrice Bellard + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include "qemu/osdep.h" +#include "qemu.h" +#include "cpu_loop-common.h" + +void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs) +{ +} diff --git a/linux-user/mips64/cpu_loop.c b/linux-user/mips64/cpu_loop.c new file mode 100644 index 0000000000..b7700a5561 --- /dev/null +++ b/linux-user/mips64/cpu_loop.c @@ -0,0 +1,26 @@ +/* + * qemu user cpu loop + * + * Copyright (c) 2003-2008 Fabrice Bellard + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include "qemu/osdep.h" +#include "qemu.h" +#include "cpu_loop-common.h" + +void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs) +{ +} diff --git a/linux-user/nios2/cpu_loop.c b/linux-user/nios2/cpu_loop.c new file mode 100644 index 0000000000..b7700a5561 --- /dev/null +++ b/linux-user/nios2/cpu_loop.c @@ -0,0 +1,26 @@ +/* + * qemu user cpu loop + * + * Copyright (c) 2003-2008 Fabrice Bellard + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include "qemu/osdep.h" +#include "qemu.h" +#include "cpu_loop-common.h" + +void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs) +{ +} diff --git a/linux-user/openrisc/cpu_loop.c b/linux-user/openrisc/cpu_loop.c new file mode 100644 index 0000000000..b7700a5561 --- /dev/null +++ b/linux-user/openrisc/cpu_loop.c @@ -0,0 +1,26 @@ +/* + * qemu user cpu loop + * + * Copyright (c) 2003-2008 Fabrice Bellard + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include "qemu/osdep.h" +#include "qemu.h" +#include "cpu_loop-common.h" + +void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs) +{ +} diff --git a/linux-user/ppc/cpu_loop.c b/linux-user/ppc/cpu_loop.c new file mode 100644 index 0000000000..b7700a5561 --- /dev/null +++ b/linux-user/ppc/cpu_loop.c @@ -0,0 +1,26 @@ +/* + * qemu user cpu loop + * + * Copyright (c) 2003-2008 Fabrice Bellard + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include "qemu/osdep.h" +#include "qemu.h" +#include "cpu_loop-common.h" + +void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs) +{ +} diff --git a/linux-user/riscv/cpu_loop.c b/linux-user/riscv/cpu_loop.c new file mode 100644 index 0000000000..b7700a5561 --- /dev/null +++ b/linux-user/riscv/cpu_loop.c @@ -0,0 +1,26 @@ +/* + * qemu user cpu loop + * + * Copyright (c) 2003-2008 Fabrice Bellard + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include "qemu/osdep.h" +#include "qemu.h" +#include "cpu_loop-common.h" + +void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs) +{ +} diff --git a/linux-user/s390x/cpu_loop.c b/linux-user/s390x/cpu_loop.c new file mode 100644 index 0000000000..b7700a5561 --- /dev/null +++ b/linux-user/s390x/cpu_loop.c @@ -0,0 +1,26 @@ +/* + * qemu user cpu loop + * + * Copyright (c) 2003-2008 Fabrice Bellard + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include "qemu/osdep.h" +#include "qemu.h" +#include "cpu_loop-common.h" + +void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs) +{ +} diff --git a/linux-user/sh4/cpu_loop.c b/linux-user/sh4/cpu_loop.c new file mode 100644 index 0000000000..b7700a5561 --- /dev/null +++ b/linux-user/sh4/cpu_loop.c @@ -0,0 +1,26 @@ +/* + * qemu user cpu loop + * + * Copyright (c) 2003-2008 Fabrice Bellard + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include "qemu/osdep.h" +#include "qemu.h" +#include "cpu_loop-common.h" + +void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs) +{ +} diff --git a/linux-user/sparc/cpu_loop.c b/linux-user/sparc/cpu_loop.c new file mode 100644 index 0000000000..b7700a5561 --- /dev/null +++ b/linux-user/sparc/cpu_loop.c @@ -0,0 +1,26 @@ +/* + * qemu user cpu loop + * + * Copyright (c) 2003-2008 Fabrice Bellard + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include "qemu/osdep.h" +#include "qemu.h" +#include "cpu_loop-common.h" + +void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs) +{ +} diff --git a/linux-user/sparc64/cpu_loop.c b/linux-user/sparc64/cpu_loop.c new file mode 100644 index 0000000000..b7700a5561 --- /dev/null +++ b/linux-user/sparc64/cpu_loop.c @@ -0,0 +1,26 @@ +/* + * qemu user cpu loop + * + * Copyright (c) 2003-2008 Fabrice Bellard + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include "qemu/osdep.h" +#include "qemu.h" +#include "cpu_loop-common.h" + +void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs) +{ +} diff --git a/linux-user/tilegx/cpu_loop.c b/linux-user/tilegx/cpu_loop.c new file mode 100644 index 0000000000..b7700a5561 --- /dev/null +++ b/linux-user/tilegx/cpu_loop.c @@ -0,0 +1,26 @@ +/* + * qemu user cpu loop + * + * Copyright (c) 2003-2008 Fabrice Bellard + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include "qemu/osdep.h" +#include "qemu.h" +#include "cpu_loop-common.h" + +void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs) +{ +} diff --git a/linux-user/x86_64/cpu_loop.c b/linux-user/x86_64/cpu_loop.c new file mode 100644 index 0000000000..b7700a5561 --- /dev/null +++ b/linux-user/x86_64/cpu_loop.c @@ -0,0 +1,26 @@ +/* + * qemu user cpu loop + * + * Copyright (c) 2003-2008 Fabrice Bellard + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include "qemu/osdep.h" +#include "qemu.h" +#include "cpu_loop-common.h" + +void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs) +{ +} diff --git a/linux-user/xtensa/cpu_loop.c b/linux-user/xtensa/cpu_loop.c new file mode 100644 index 0000000000..b7700a5561 --- /dev/null +++ b/linux-user/xtensa/cpu_loop.c @@ -0,0 +1,26 @@ +/* + * qemu user cpu loop + * + * Copyright (c) 2003-2008 Fabrice Bellard + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include "qemu/osdep.h" +#include "qemu.h" +#include "cpu_loop-common.h" + +void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs) +{ +} --=20 2.14.3 From nobody Mon May 6 08:55:16 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1523474849122945.2457565211691; Wed, 11 Apr 2018 12:27:29 -0700 (PDT) Received: from localhost ([::1]:49237 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f6LOu-0006gl-As for importer@patchew.org; Wed, 11 Apr 2018 15:27:24 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37883) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f6Kvx-0005wj-8n for qemu-devel@nongnu.org; Wed, 11 Apr 2018 14:57:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f6Kvu-0007nX-09 for qemu-devel@nongnu.org; Wed, 11 Apr 2018 14:57:29 -0400 Received: from mout.kundenserver.de ([212.227.17.13]:43055) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1f6Kvt-0007mq-HV; Wed, 11 Apr 2018 14:57:25 -0400 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue105 [212.227.15.183]) with ESMTPSA (Nemesis) id 0LyUFS-1eRB37454A-015pGQ; Wed, 11 Apr 2018 20:57:08 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Date: Wed, 11 Apr 2018 20:56:34 +0200 Message-Id: <20180411185651.21351-3-laurent@vivier.eu> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180411185651.21351-1-laurent@vivier.eu> References: <20180411185651.21351-1-laurent@vivier.eu> X-Provags-ID: V03:K1:moZ5Vn5grjDaxhHHDpJrRI1pkHWzVNF9gcVDCRa/T+9pWPApvP+ 9cLyE3JhjtyPBdu/FSJPq42IdvjJmVLimVJq/gxt8UIMM8uRd121GKJnpa7KFZGJhT4n2w2 bENPUiGpkrCt1eIgpPQMvbCnqKggnkmUrnX9n7hzeaX/91LmNEHFXOnsv2GNHyUMBtKTDXe e6lM0fRKEqZgluzBt+Kkw== X-UI-Out-Filterresults: notjunk:1;V01:K0:L6xVjYIPoWg=:ZX26YH+VgQIXcCXnBWD1q5 nWzlmF6wFlqWjw241vRVj7MmP2OR2SHPAHxgLioLOUGkVbG+lxqS1GdlcYIL4WytEHUxo+fp+ bMzRMPs3xUnaFBG2x3/IQ1xiQzebHu5j3KWgvGOg7qGQvOr/XrsI1R89Yhg92Cl0etKbrUfus N9QYuzgtOLO11IirQySUv+u2qvtkrmcwjYP80fyJfZdvpa04Wk9/PfAsb41I2OQzAJcflfV5H wFpvgKlWyPeojFjlx/p6yQAKu//jvarHbDlGvTsNJY8bwoVL8zzxUPTwRd2U881MxbxFg74Ux JiTsp2yx1Ru+MztKMTNL57mhXXfPYGYDHNmrO5n16X5HWNbUQvxe7Drq++FYM/w21qQ9ulAgr qNEIq26AA9Vd7KmfNX41RSGg8lM3ilzs24DdOM7kfYXe338WIkCLC5nMzq9yh3fWvIMovUzoE eZ5XHbJFNAaRK+WyF+9ZbtzVvd12a/VUH6EPC7wF6CbIH3IjvCl/qWlWbx0gVsnm7goN1qOBg Lg8YpS/hoDHD9VvZIEYRuDXF9cdzH1fhbUUs8SGW9+nF5COoIugvPv6r/Gl8pXTlxGvEPQ3s3 4ub+C+rUi1h/UpSHSknNZh6G0XFCPj8XlULPg9Gkz06n+lUqx5kad5vnGJVHc1QAKE+69FVrE bDfageDmN1hReLEXlk/eK/6yxoZbaD/s/cAG9vCqUYICG8sLYR0oTCpPyvb1cntR08QnCtM0i CgBLAWjMg7LwocrpWZeNBVA31xfKZIm+9wA1Ig== X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 212.227.17.13 Subject: [Qemu-devel] [PATCH for 2.13 v2 02/19] linux-user: move i386/x86_64 cpu loop to i386 directory X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Cornelia Huck , Riku Voipio , Richard Henderson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Laurent Vivier , qemu-s390x@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" No code change, only move code from main.c to i386/cpu_loop.c. Include i386/cpu_loop.c in x86_64/cpu_loop.c to avoid to duplicate code. Signed-off-by: Laurent Vivier Reviewed-by: Richard Henderson --- linux-user/i386/cpu_loop.c | 343 +++++++++++++++++++++++++++++++++++++++= +++ linux-user/main.c | 348 +--------------------------------------= ---- linux-user/x86_64/cpu_loop.c | 8 +- 3 files changed, 345 insertions(+), 354 deletions(-) diff --git a/linux-user/i386/cpu_loop.c b/linux-user/i386/cpu_loop.c index b7700a5561..2374abfd0b 100644 --- a/linux-user/i386/cpu_loop.c +++ b/linux-user/i386/cpu_loop.c @@ -21,6 +21,349 @@ #include "qemu.h" #include "cpu_loop-common.h" =20 +/***********************************************************/ +/* CPUX86 core interface */ + +uint64_t cpu_get_tsc(CPUX86State *env) +{ + return cpu_get_host_ticks(); +} + +static void write_dt(void *ptr, unsigned long addr, unsigned long limit, + int flags) +{ + unsigned int e1, e2; + uint32_t *p; + e1 =3D (addr << 16) | (limit & 0xffff); + e2 =3D ((addr >> 16) & 0xff) | (addr & 0xff000000) | (limit & 0x000f00= 00); + e2 |=3D flags; + p =3D ptr; + p[0] =3D tswap32(e1); + p[1] =3D tswap32(e2); +} + +static uint64_t *idt_table; +#ifdef TARGET_X86_64 +static void set_gate64(void *ptr, unsigned int type, unsigned int dpl, + uint64_t addr, unsigned int sel) +{ + uint32_t *p, e1, e2; + e1 =3D (addr & 0xffff) | (sel << 16); + e2 =3D (addr & 0xffff0000) | 0x8000 | (dpl << 13) | (type << 8); + p =3D ptr; + p[0] =3D tswap32(e1); + p[1] =3D tswap32(e2); + p[2] =3D tswap32(addr >> 32); + p[3] =3D 0; +} +/* only dpl matters as we do only user space emulation */ +static void set_idt(int n, unsigned int dpl) +{ + set_gate64(idt_table + n * 2, 0, dpl, 0, 0); +} +#else +static void set_gate(void *ptr, unsigned int type, unsigned int dpl, + uint32_t addr, unsigned int sel) +{ + uint32_t *p, e1, e2; + e1 =3D (addr & 0xffff) | (sel << 16); + e2 =3D (addr & 0xffff0000) | 0x8000 | (dpl << 13) | (type << 8); + p =3D ptr; + p[0] =3D tswap32(e1); + p[1] =3D tswap32(e2); +} + +/* only dpl matters as we do only user space emulation */ +static void set_idt(int n, unsigned int dpl) +{ + set_gate(idt_table + n, 0, dpl, 0, 0); +} +#endif + +void cpu_loop(CPUX86State *env) +{ + CPUState *cs =3D CPU(x86_env_get_cpu(env)); + int trapnr; + abi_ulong pc; + abi_ulong ret; + target_siginfo_t info; + + for(;;) { + cpu_exec_start(cs); + trapnr =3D cpu_exec(cs); + cpu_exec_end(cs); + process_queued_cpu_work(cs); + + switch(trapnr) { + case 0x80: + /* linux syscall from int $0x80 */ + ret =3D do_syscall(env, + env->regs[R_EAX], + env->regs[R_EBX], + env->regs[R_ECX], + env->regs[R_EDX], + env->regs[R_ESI], + env->regs[R_EDI], + env->regs[R_EBP], + 0, 0); + if (ret =3D=3D -TARGET_ERESTARTSYS) { + env->eip -=3D 2; + } else if (ret !=3D -TARGET_QEMU_ESIGRETURN) { + env->regs[R_EAX] =3D ret; + } + break; +#ifndef TARGET_ABI32 + case EXCP_SYSCALL: + /* linux syscall from syscall instruction */ + ret =3D do_syscall(env, + env->regs[R_EAX], + env->regs[R_EDI], + env->regs[R_ESI], + env->regs[R_EDX], + env->regs[10], + env->regs[8], + env->regs[9], + 0, 0); + if (ret =3D=3D -TARGET_ERESTARTSYS) { + env->eip -=3D 2; + } else if (ret !=3D -TARGET_QEMU_ESIGRETURN) { + env->regs[R_EAX] =3D ret; + } + break; +#endif + case EXCP0B_NOSEG: + case EXCP0C_STACK: + info.si_signo =3D TARGET_SIGBUS; + info.si_errno =3D 0; + info.si_code =3D TARGET_SI_KERNEL; + info._sifields._sigfault._addr =3D 0; + queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + break; + case EXCP0D_GPF: + /* XXX: potential problem if ABI32 */ +#ifndef TARGET_X86_64 + if (env->eflags & VM_MASK) { + handle_vm86_fault(env); + } else +#endif + { + info.si_signo =3D TARGET_SIGSEGV; + info.si_errno =3D 0; + info.si_code =3D TARGET_SI_KERNEL; + info._sifields._sigfault._addr =3D 0; + queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + } + break; + case EXCP0E_PAGE: + info.si_signo =3D TARGET_SIGSEGV; + info.si_errno =3D 0; + if (!(env->error_code & 1)) + info.si_code =3D TARGET_SEGV_MAPERR; + else + info.si_code =3D TARGET_SEGV_ACCERR; + info._sifields._sigfault._addr =3D env->cr[2]; + queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + break; + case EXCP00_DIVZ: +#ifndef TARGET_X86_64 + if (env->eflags & VM_MASK) { + handle_vm86_trap(env, trapnr); + } else +#endif + { + /* division by zero */ + info.si_signo =3D TARGET_SIGFPE; + info.si_errno =3D 0; + info.si_code =3D TARGET_FPE_INTDIV; + info._sifields._sigfault._addr =3D env->eip; + queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + } + break; + case EXCP01_DB: + case EXCP03_INT3: +#ifndef TARGET_X86_64 + if (env->eflags & VM_MASK) { + handle_vm86_trap(env, trapnr); + } else +#endif + { + info.si_signo =3D TARGET_SIGTRAP; + info.si_errno =3D 0; + if (trapnr =3D=3D EXCP01_DB) { + info.si_code =3D TARGET_TRAP_BRKPT; + info._sifields._sigfault._addr =3D env->eip; + } else { + info.si_code =3D TARGET_SI_KERNEL; + info._sifields._sigfault._addr =3D 0; + } + queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + } + break; + case EXCP04_INTO: + case EXCP05_BOUND: +#ifndef TARGET_X86_64 + if (env->eflags & VM_MASK) { + handle_vm86_trap(env, trapnr); + } else +#endif + { + info.si_signo =3D TARGET_SIGSEGV; + info.si_errno =3D 0; + info.si_code =3D TARGET_SI_KERNEL; + info._sifields._sigfault._addr =3D 0; + queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + } + break; + case EXCP06_ILLOP: + info.si_signo =3D TARGET_SIGILL; + info.si_errno =3D 0; + info.si_code =3D TARGET_ILL_ILLOPN; + info._sifields._sigfault._addr =3D env->eip; + queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + break; + case EXCP_INTERRUPT: + /* just indicate that signals should be handled asap */ + break; + case EXCP_DEBUG: + { + int sig; + + sig =3D gdb_handlesig(cs, TARGET_SIGTRAP); + if (sig) + { + info.si_signo =3D sig; + info.si_errno =3D 0; + info.si_code =3D TARGET_TRAP_BRKPT; + queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + } + } + break; + case EXCP_ATOMIC: + cpu_exec_step_atomic(cs); + break; + default: + pc =3D env->segs[R_CS].base + env->eip; + EXCP_DUMP(env, "qemu: 0x%08lx: unhandled CPU exception 0x%x - = aborting\n", + (long)pc, trapnr); + abort(); + } + process_pending_signals(env); + } +} + void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs) { + env->cr[0] =3D CR0_PG_MASK | CR0_WP_MASK | CR0_PE_MASK; + env->hflags |=3D HF_PE_MASK | HF_CPL_MASK; + if (env->features[FEAT_1_EDX] & CPUID_SSE) { + env->cr[4] |=3D CR4_OSFXSR_MASK; + env->hflags |=3D HF_OSFXSR_MASK; + } +#ifndef TARGET_ABI32 + /* enable 64 bit mode if possible */ + if (!(env->features[FEAT_8000_0001_EDX] & CPUID_EXT2_LM)) { + fprintf(stderr, "The selected x86 CPU does not support 64 bit mode= \n"); + exit(EXIT_FAILURE); + } + env->cr[4] |=3D CR4_PAE_MASK; + env->efer |=3D MSR_EFER_LMA | MSR_EFER_LME; + env->hflags |=3D HF_LMA_MASK; +#endif + + /* flags setup : we activate the IRQs by default as in user mode */ + env->eflags |=3D IF_MASK; + + /* linux register setup */ +#ifndef TARGET_ABI32 + env->regs[R_EAX] =3D regs->rax; + env->regs[R_EBX] =3D regs->rbx; + env->regs[R_ECX] =3D regs->rcx; + env->regs[R_EDX] =3D regs->rdx; + env->regs[R_ESI] =3D regs->rsi; + env->regs[R_EDI] =3D regs->rdi; + env->regs[R_EBP] =3D regs->rbp; + env->regs[R_ESP] =3D regs->rsp; + env->eip =3D regs->rip; +#else + env->regs[R_EAX] =3D regs->eax; + env->regs[R_EBX] =3D regs->ebx; + env->regs[R_ECX] =3D regs->ecx; + env->regs[R_EDX] =3D regs->edx; + env->regs[R_ESI] =3D regs->esi; + env->regs[R_EDI] =3D regs->edi; + env->regs[R_EBP] =3D regs->ebp; + env->regs[R_ESP] =3D regs->esp; + env->eip =3D regs->eip; +#endif + + /* linux interrupt setup */ +#ifndef TARGET_ABI32 + env->idt.limit =3D 511; +#else + env->idt.limit =3D 255; +#endif + env->idt.base =3D target_mmap(0, sizeof(uint64_t) * (env->idt.limit + = 1), + PROT_READ|PROT_WRITE, + MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); + idt_table =3D g2h(env->idt.base); + set_idt(0, 0); + set_idt(1, 0); + set_idt(2, 0); + set_idt(3, 3); + set_idt(4, 3); + set_idt(5, 0); + set_idt(6, 0); + set_idt(7, 0); + set_idt(8, 0); + set_idt(9, 0); + set_idt(10, 0); + set_idt(11, 0); + set_idt(12, 0); + set_idt(13, 0); + set_idt(14, 0); + set_idt(15, 0); + set_idt(16, 0); + set_idt(17, 0); + set_idt(18, 0); + set_idt(19, 0); + set_idt(0x80, 3); + + /* linux segment setup */ + { + uint64_t *gdt_table; + env->gdt.base =3D target_mmap(0, sizeof(uint64_t) * TARGET_GDT_ENT= RIES, + PROT_READ|PROT_WRITE, + MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); + env->gdt.limit =3D sizeof(uint64_t) * TARGET_GDT_ENTRIES - 1; + gdt_table =3D g2h(env->gdt.base); +#ifdef TARGET_ABI32 + write_dt(&gdt_table[__USER_CS >> 3], 0, 0xfffff, + DESC_G_MASK | DESC_B_MASK | DESC_P_MASK | DESC_S_MASK | + (3 << DESC_DPL_SHIFT) | (0xa << DESC_TYPE_SHIFT)); +#else + /* 64 bit code segment */ + write_dt(&gdt_table[__USER_CS >> 3], 0, 0xfffff, + DESC_G_MASK | DESC_B_MASK | DESC_P_MASK | DESC_S_MASK | + DESC_L_MASK | + (3 << DESC_DPL_SHIFT) | (0xa << DESC_TYPE_SHIFT)); +#endif + write_dt(&gdt_table[__USER_DS >> 3], 0, 0xfffff, + DESC_G_MASK | DESC_B_MASK | DESC_P_MASK | DESC_S_MASK | + (3 << DESC_DPL_SHIFT) | (0x2 << DESC_TYPE_SHIFT)); + } + cpu_x86_load_seg(env, R_CS, __USER_CS); + cpu_x86_load_seg(env, R_SS, __USER_DS); +#ifdef TARGET_ABI32 + cpu_x86_load_seg(env, R_DS, __USER_DS); + cpu_x86_load_seg(env, R_ES, __USER_DS); + cpu_x86_load_seg(env, R_FS, __USER_DS); + cpu_x86_load_seg(env, R_GS, __USER_DS); + /* This hack makes Wine work... */ + env->segs[R_FS].selector =3D 0; +#else + cpu_x86_load_seg(env, R_DS, 0); + cpu_x86_load_seg(env, R_ES, 0); + cpu_x86_load_seg(env, R_FS, 0); + cpu_x86_load_seg(env, R_GS, 0); +#endif } diff --git a/linux-user/main.c b/linux-user/main.c index 09045f877c..5271473d47 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -149,238 +149,6 @@ void fork_end(int child) } } =20 -#ifdef TARGET_I386 -/***********************************************************/ -/* CPUX86 core interface */ - -uint64_t cpu_get_tsc(CPUX86State *env) -{ - return cpu_get_host_ticks(); -} - -static void write_dt(void *ptr, unsigned long addr, unsigned long limit, - int flags) -{ - unsigned int e1, e2; - uint32_t *p; - e1 =3D (addr << 16) | (limit & 0xffff); - e2 =3D ((addr >> 16) & 0xff) | (addr & 0xff000000) | (limit & 0x000f00= 00); - e2 |=3D flags; - p =3D ptr; - p[0] =3D tswap32(e1); - p[1] =3D tswap32(e2); -} - -static uint64_t *idt_table; -#ifdef TARGET_X86_64 -static void set_gate64(void *ptr, unsigned int type, unsigned int dpl, - uint64_t addr, unsigned int sel) -{ - uint32_t *p, e1, e2; - e1 =3D (addr & 0xffff) | (sel << 16); - e2 =3D (addr & 0xffff0000) | 0x8000 | (dpl << 13) | (type << 8); - p =3D ptr; - p[0] =3D tswap32(e1); - p[1] =3D tswap32(e2); - p[2] =3D tswap32(addr >> 32); - p[3] =3D 0; -} -/* only dpl matters as we do only user space emulation */ -static void set_idt(int n, unsigned int dpl) -{ - set_gate64(idt_table + n * 2, 0, dpl, 0, 0); -} -#else -static void set_gate(void *ptr, unsigned int type, unsigned int dpl, - uint32_t addr, unsigned int sel) -{ - uint32_t *p, e1, e2; - e1 =3D (addr & 0xffff) | (sel << 16); - e2 =3D (addr & 0xffff0000) | 0x8000 | (dpl << 13) | (type << 8); - p =3D ptr; - p[0] =3D tswap32(e1); - p[1] =3D tswap32(e2); -} - -/* only dpl matters as we do only user space emulation */ -static void set_idt(int n, unsigned int dpl) -{ - set_gate(idt_table + n, 0, dpl, 0, 0); -} -#endif - -void cpu_loop(CPUX86State *env) -{ - CPUState *cs =3D CPU(x86_env_get_cpu(env)); - int trapnr; - abi_ulong pc; - abi_ulong ret; - target_siginfo_t info; - - for(;;) { - cpu_exec_start(cs); - trapnr =3D cpu_exec(cs); - cpu_exec_end(cs); - process_queued_cpu_work(cs); - - switch(trapnr) { - case 0x80: - /* linux syscall from int $0x80 */ - ret =3D do_syscall(env, - env->regs[R_EAX], - env->regs[R_EBX], - env->regs[R_ECX], - env->regs[R_EDX], - env->regs[R_ESI], - env->regs[R_EDI], - env->regs[R_EBP], - 0, 0); - if (ret =3D=3D -TARGET_ERESTARTSYS) { - env->eip -=3D 2; - } else if (ret !=3D -TARGET_QEMU_ESIGRETURN) { - env->regs[R_EAX] =3D ret; - } - break; -#ifndef TARGET_ABI32 - case EXCP_SYSCALL: - /* linux syscall from syscall instruction */ - ret =3D do_syscall(env, - env->regs[R_EAX], - env->regs[R_EDI], - env->regs[R_ESI], - env->regs[R_EDX], - env->regs[10], - env->regs[8], - env->regs[9], - 0, 0); - if (ret =3D=3D -TARGET_ERESTARTSYS) { - env->eip -=3D 2; - } else if (ret !=3D -TARGET_QEMU_ESIGRETURN) { - env->regs[R_EAX] =3D ret; - } - break; -#endif - case EXCP0B_NOSEG: - case EXCP0C_STACK: - info.si_signo =3D TARGET_SIGBUS; - info.si_errno =3D 0; - info.si_code =3D TARGET_SI_KERNEL; - info._sifields._sigfault._addr =3D 0; - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); - break; - case EXCP0D_GPF: - /* XXX: potential problem if ABI32 */ -#ifndef TARGET_X86_64 - if (env->eflags & VM_MASK) { - handle_vm86_fault(env); - } else -#endif - { - info.si_signo =3D TARGET_SIGSEGV; - info.si_errno =3D 0; - info.si_code =3D TARGET_SI_KERNEL; - info._sifields._sigfault._addr =3D 0; - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); - } - break; - case EXCP0E_PAGE: - info.si_signo =3D TARGET_SIGSEGV; - info.si_errno =3D 0; - if (!(env->error_code & 1)) - info.si_code =3D TARGET_SEGV_MAPERR; - else - info.si_code =3D TARGET_SEGV_ACCERR; - info._sifields._sigfault._addr =3D env->cr[2]; - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); - break; - case EXCP00_DIVZ: -#ifndef TARGET_X86_64 - if (env->eflags & VM_MASK) { - handle_vm86_trap(env, trapnr); - } else -#endif - { - /* division by zero */ - info.si_signo =3D TARGET_SIGFPE; - info.si_errno =3D 0; - info.si_code =3D TARGET_FPE_INTDIV; - info._sifields._sigfault._addr =3D env->eip; - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); - } - break; - case EXCP01_DB: - case EXCP03_INT3: -#ifndef TARGET_X86_64 - if (env->eflags & VM_MASK) { - handle_vm86_trap(env, trapnr); - } else -#endif - { - info.si_signo =3D TARGET_SIGTRAP; - info.si_errno =3D 0; - if (trapnr =3D=3D EXCP01_DB) { - info.si_code =3D TARGET_TRAP_BRKPT; - info._sifields._sigfault._addr =3D env->eip; - } else { - info.si_code =3D TARGET_SI_KERNEL; - info._sifields._sigfault._addr =3D 0; - } - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); - } - break; - case EXCP04_INTO: - case EXCP05_BOUND: -#ifndef TARGET_X86_64 - if (env->eflags & VM_MASK) { - handle_vm86_trap(env, trapnr); - } else -#endif - { - info.si_signo =3D TARGET_SIGSEGV; - info.si_errno =3D 0; - info.si_code =3D TARGET_SI_KERNEL; - info._sifields._sigfault._addr =3D 0; - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); - } - break; - case EXCP06_ILLOP: - info.si_signo =3D TARGET_SIGILL; - info.si_errno =3D 0; - info.si_code =3D TARGET_ILL_ILLOPN; - info._sifields._sigfault._addr =3D env->eip; - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); - break; - case EXCP_INTERRUPT: - /* just indicate that signals should be handled asap */ - break; - case EXCP_DEBUG: - { - int sig; - - sig =3D gdb_handlesig(cs, TARGET_SIGTRAP); - if (sig) - { - info.si_signo =3D sig; - info.si_errno =3D 0; - info.si_code =3D TARGET_TRAP_BRKPT; - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); - } - } - break; - case EXCP_ATOMIC: - cpu_exec_step_atomic(cs); - break; - default: - pc =3D env->segs[R_CS].base + env->eip; - EXCP_DUMP(env, "qemu: 0x%08lx: unhandled CPU exception 0x%x - = aborting\n", - (long)pc, trapnr); - abort(); - } - process_pending_signals(env); - } -} -#endif - #ifdef TARGET_ARM =20 #define get_user_code_u32(x, gaddr, env) \ @@ -4727,121 +4495,7 @@ int main(int argc, char **argv, char **envp) =20 target_cpu_copy_regs(env, regs); =20 -#if defined(TARGET_I386) - env->cr[0] =3D CR0_PG_MASK | CR0_WP_MASK | CR0_PE_MASK; - env->hflags |=3D HF_PE_MASK | HF_CPL_MASK; - if (env->features[FEAT_1_EDX] & CPUID_SSE) { - env->cr[4] |=3D CR4_OSFXSR_MASK; - env->hflags |=3D HF_OSFXSR_MASK; - } -#ifndef TARGET_ABI32 - /* enable 64 bit mode if possible */ - if (!(env->features[FEAT_8000_0001_EDX] & CPUID_EXT2_LM)) { - fprintf(stderr, "The selected x86 CPU does not support 64 bit mode= \n"); - exit(EXIT_FAILURE); - } - env->cr[4] |=3D CR4_PAE_MASK; - env->efer |=3D MSR_EFER_LMA | MSR_EFER_LME; - env->hflags |=3D HF_LMA_MASK; -#endif - - /* flags setup : we activate the IRQs by default as in user mode */ - env->eflags |=3D IF_MASK; - - /* linux register setup */ -#ifndef TARGET_ABI32 - env->regs[R_EAX] =3D regs->rax; - env->regs[R_EBX] =3D regs->rbx; - env->regs[R_ECX] =3D regs->rcx; - env->regs[R_EDX] =3D regs->rdx; - env->regs[R_ESI] =3D regs->rsi; - env->regs[R_EDI] =3D regs->rdi; - env->regs[R_EBP] =3D regs->rbp; - env->regs[R_ESP] =3D regs->rsp; - env->eip =3D regs->rip; -#else - env->regs[R_EAX] =3D regs->eax; - env->regs[R_EBX] =3D regs->ebx; - env->regs[R_ECX] =3D regs->ecx; - env->regs[R_EDX] =3D regs->edx; - env->regs[R_ESI] =3D regs->esi; - env->regs[R_EDI] =3D regs->edi; - env->regs[R_EBP] =3D regs->ebp; - env->regs[R_ESP] =3D regs->esp; - env->eip =3D regs->eip; -#endif - - /* linux interrupt setup */ -#ifndef TARGET_ABI32 - env->idt.limit =3D 511; -#else - env->idt.limit =3D 255; -#endif - env->idt.base =3D target_mmap(0, sizeof(uint64_t) * (env->idt.limit + = 1), - PROT_READ|PROT_WRITE, - MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); - idt_table =3D g2h(env->idt.base); - set_idt(0, 0); - set_idt(1, 0); - set_idt(2, 0); - set_idt(3, 3); - set_idt(4, 3); - set_idt(5, 0); - set_idt(6, 0); - set_idt(7, 0); - set_idt(8, 0); - set_idt(9, 0); - set_idt(10, 0); - set_idt(11, 0); - set_idt(12, 0); - set_idt(13, 0); - set_idt(14, 0); - set_idt(15, 0); - set_idt(16, 0); - set_idt(17, 0); - set_idt(18, 0); - set_idt(19, 0); - set_idt(0x80, 3); - - /* linux segment setup */ - { - uint64_t *gdt_table; - env->gdt.base =3D target_mmap(0, sizeof(uint64_t) * TARGET_GDT_ENT= RIES, - PROT_READ|PROT_WRITE, - MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); - env->gdt.limit =3D sizeof(uint64_t) * TARGET_GDT_ENTRIES - 1; - gdt_table =3D g2h(env->gdt.base); -#ifdef TARGET_ABI32 - write_dt(&gdt_table[__USER_CS >> 3], 0, 0xfffff, - DESC_G_MASK | DESC_B_MASK | DESC_P_MASK | DESC_S_MASK | - (3 << DESC_DPL_SHIFT) | (0xa << DESC_TYPE_SHIFT)); -#else - /* 64 bit code segment */ - write_dt(&gdt_table[__USER_CS >> 3], 0, 0xfffff, - DESC_G_MASK | DESC_B_MASK | DESC_P_MASK | DESC_S_MASK | - DESC_L_MASK | - (3 << DESC_DPL_SHIFT) | (0xa << DESC_TYPE_SHIFT)); -#endif - write_dt(&gdt_table[__USER_DS >> 3], 0, 0xfffff, - DESC_G_MASK | DESC_B_MASK | DESC_P_MASK | DESC_S_MASK | - (3 << DESC_DPL_SHIFT) | (0x2 << DESC_TYPE_SHIFT)); - } - cpu_x86_load_seg(env, R_CS, __USER_CS); - cpu_x86_load_seg(env, R_SS, __USER_DS); -#ifdef TARGET_ABI32 - cpu_x86_load_seg(env, R_DS, __USER_DS); - cpu_x86_load_seg(env, R_ES, __USER_DS); - cpu_x86_load_seg(env, R_FS, __USER_DS); - cpu_x86_load_seg(env, R_GS, __USER_DS); - /* This hack makes Wine work... */ - env->segs[R_FS].selector =3D 0; -#else - cpu_x86_load_seg(env, R_DS, 0); - cpu_x86_load_seg(env, R_ES, 0); - cpu_x86_load_seg(env, R_FS, 0); - cpu_x86_load_seg(env, R_GS, 0); -#endif -#elif defined(TARGET_AARCH64) +#if defined(TARGET_AARCH64) { int i; =20 diff --git a/linux-user/x86_64/cpu_loop.c b/linux-user/x86_64/cpu_loop.c index b7700a5561..8b5af8ea1f 100644 --- a/linux-user/x86_64/cpu_loop.c +++ b/linux-user/x86_64/cpu_loop.c @@ -17,10 +17,4 @@ * along with this program; if not, see . */ =20 -#include "qemu/osdep.h" -#include "qemu.h" -#include "cpu_loop-common.h" - -void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs) -{ -} +#include "../i386/cpu_loop.c" --=20 2.14.3 From nobody Mon May 6 08:55:16 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1523475039086673.2454623839742; Wed, 11 Apr 2018 12:30:39 -0700 (PDT) Received: from localhost ([::1]:49414 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f6LS2-0001C7-8E for importer@patchew.org; Wed, 11 Apr 2018 15:30:38 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38159) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f6KwC-0006BQ-E2 for qemu-devel@nongnu.org; Wed, 11 Apr 2018 14:57:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f6Kw7-0007vP-QE for qemu-devel@nongnu.org; Wed, 11 Apr 2018 14:57:44 -0400 Received: from mout.kundenserver.de ([217.72.192.73]:55823) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1f6Kw7-0007uf-Br; Wed, 11 Apr 2018 14:57:39 -0400 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue105 [212.227.15.183]) with ESMTPSA (Nemesis) id 0MC1E8-1fFAdJ0dto-008vzE; Wed, 11 Apr 2018 20:57:09 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Date: Wed, 11 Apr 2018 20:56:35 +0200 Message-Id: <20180411185651.21351-4-laurent@vivier.eu> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180411185651.21351-1-laurent@vivier.eu> References: <20180411185651.21351-1-laurent@vivier.eu> X-Provags-ID: V03:K1:yy/iiamuuxqKGNGg8U9rV7pyqlGsKp4hGLLRHDX37NkwpbY8anH KY9U6q/z+TCawvE2TBKldRbZ/Jd1LodkaCHtOi7iBqICwibBERlbOaDmbYbDoHmAGKVuymk BuDkb+xUq6WrIrZCSXverBnAuyZim05xYAQcxGefQC+pZ1bhXfHot9znzeQkgajctaMuRZb 8nlH4Od06F0ddHYFORelA== X-UI-Out-Filterresults: notjunk:1;V01:K0:oERZg3HEmKk=:93Tcx44Cjm5fegrBBsF+35 kyBId9n4dC8RlSSaPXGZET18f99ykOrYCHfdnUtCmbwq8lU7Cg+I4Go9MXqp5rnegj8to/X6f PFsMkXCmfB+Kn4iBjjnX8Glrmn7u3eFoSLKsV7V8nb9LhTlOgZXjkBHq4tsMN2DKM7jfe5fRz 4+sZjgLMDXc1blSVWFHNg1lWu1NLGBPde9WvNBBPdizPzkZo1Q265NN3eaeQuEZrD2S8fL5pd aBR9PNWDsA2aisO5BN61PNacev47G9WQO0BnW/PDyplOVrogoBC/GkgylFki3/VF4WrmCcJkr nmaSZ1KbJzgIqWc0h9cXKw20x0ceJvnYnhssKZ1DoEMvq1OMQBTCBnOrWYh2WzJ8u9mcGzSNn TpRtWh75Sj5s3JPLn59YbZF6br/pgkfuZ2/HSNu3nxD6g1csWUSa5+y5FS/auIH3ZGNXNV87V YWkubj+2bF5TINyPcJKaHu4wxDUnfn1Yz+wFEjkyZUKTm0uUvGjhwKDazxQBeWw76n3agO02k JAqC9tnWPM8lHtfa+7LZ39DFmEdSaIA0JuLZBG8v6019JbHCqG70COlkk9M7b926CrIgVIe0W WxFjGq9p09xMythdxDKfLTJPgNDcu5t68dkdZ4hHhpyKu/BeQGy8lwLxSv46p04g2RFWH60s+ klIGgf1kYyPDKljaUfRjnG9yKt9QGiLCA0o/hw5GmXf1/IZdCLBPrhlv9OnPTXLwjKuSHAvJV Zu0okS1dyK0suYLaxJbCsPCjmOSlN09DvddltA== X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 217.72.192.73 Subject: [Qemu-devel] [PATCH for 2.13 v2 03/19] linux-user: move aarch64 cpu loop to aarch64 directory X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Cornelia Huck , Riku Voipio , Richard Henderson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Laurent Vivier , qemu-s390x@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" No code change, only move code from main.c to aarch64/cpu_loop.c and duplicate some macro defined for both arm and aarch64. Signed-off-by: Laurent Vivier Reviewed-by: Richard Henderson --- linux-user/aarch64/cpu_loop.c | 156 ++++++++++++++++++++++++++++++++++++++= ++++ linux-user/main.c | 109 +---------------------------- 2 files changed, 158 insertions(+), 107 deletions(-) diff --git a/linux-user/aarch64/cpu_loop.c b/linux-user/aarch64/cpu_loop.c index b7700a5561..c97a646546 100644 --- a/linux-user/aarch64/cpu_loop.c +++ b/linux-user/aarch64/cpu_loop.c @@ -21,6 +21,162 @@ #include "qemu.h" #include "cpu_loop-common.h" =20 +#define get_user_code_u32(x, gaddr, env) \ + ({ abi_long __r =3D get_user_u32((x), (gaddr)); \ + if (!__r && bswap_code(arm_sctlr_b(env))) { \ + (x) =3D bswap32(x); \ + } \ + __r; \ + }) + +#define get_user_code_u16(x, gaddr, env) \ + ({ abi_long __r =3D get_user_u16((x), (gaddr)); \ + if (!__r && bswap_code(arm_sctlr_b(env))) { \ + (x) =3D bswap16(x); \ + } \ + __r; \ + }) + +#define get_user_data_u32(x, gaddr, env) \ + ({ abi_long __r =3D get_user_u32((x), (gaddr)); \ + if (!__r && arm_cpu_bswap_data(env)) { \ + (x) =3D bswap32(x); \ + } \ + __r; \ + }) + +#define get_user_data_u16(x, gaddr, env) \ + ({ abi_long __r =3D get_user_u16((x), (gaddr)); \ + if (!__r && arm_cpu_bswap_data(env)) { \ + (x) =3D bswap16(x); \ + } \ + __r; \ + }) + +#define put_user_data_u32(x, gaddr, env) \ + ({ typeof(x) __x =3D (x); \ + if (arm_cpu_bswap_data(env)) { \ + __x =3D bswap32(__x); \ + } \ + put_user_u32(__x, (gaddr)); \ + }) + +#define put_user_data_u16(x, gaddr, env) \ + ({ typeof(x) __x =3D (x); \ + if (arm_cpu_bswap_data(env)) { \ + __x =3D bswap16(__x); \ + } \ + put_user_u16(__x, (gaddr)); \ + }) + +/* AArch64 main loop */ +void cpu_loop(CPUARMState *env) +{ + CPUState *cs =3D CPU(arm_env_get_cpu(env)); + int trapnr, sig; + abi_long ret; + target_siginfo_t info; + + for (;;) { + cpu_exec_start(cs); + trapnr =3D cpu_exec(cs); + cpu_exec_end(cs); + process_queued_cpu_work(cs); + + switch (trapnr) { + case EXCP_SWI: + ret =3D do_syscall(env, + env->xregs[8], + env->xregs[0], + env->xregs[1], + env->xregs[2], + env->xregs[3], + env->xregs[4], + env->xregs[5], + 0, 0); + if (ret =3D=3D -TARGET_ERESTARTSYS) { + env->pc -=3D 4; + } else if (ret !=3D -TARGET_QEMU_ESIGRETURN) { + env->xregs[0] =3D ret; + } + break; + case EXCP_INTERRUPT: + /* just indicate that signals should be handled asap */ + break; + case EXCP_UDEF: + info.si_signo =3D TARGET_SIGILL; + info.si_errno =3D 0; + info.si_code =3D TARGET_ILL_ILLOPN; + info._sifields._sigfault._addr =3D env->pc; + queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + break; + case EXCP_PREFETCH_ABORT: + case EXCP_DATA_ABORT: + info.si_signo =3D TARGET_SIGSEGV; + info.si_errno =3D 0; + /* XXX: check env->error_code */ + info.si_code =3D TARGET_SEGV_MAPERR; + info._sifields._sigfault._addr =3D env->exception.vaddress; + queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + break; + case EXCP_DEBUG: + case EXCP_BKPT: + sig =3D gdb_handlesig(cs, TARGET_SIGTRAP); + if (sig) { + info.si_signo =3D sig; + info.si_errno =3D 0; + info.si_code =3D TARGET_TRAP_BRKPT; + queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + } + break; + case EXCP_SEMIHOST: + env->xregs[0] =3D do_arm_semihosting(env); + break; + case EXCP_YIELD: + /* nothing to do here for user-mode, just resume guest code */ + break; + case EXCP_ATOMIC: + cpu_exec_step_atomic(cs); + break; + default: + EXCP_DUMP(env, "qemu: unhandled CPU exception 0x%x - aborting\= n", trapnr); + abort(); + } + process_pending_signals(env); + /* Exception return on AArch64 always clears the exclusive monitor, + * so any return to running guest code implies this. + */ + env->exclusive_addr =3D -1; + } +} + void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs) { + CPUState *cpu =3D ENV_GET_CPU(env); + TaskState *ts =3D cpu->opaque; + struct image_info *info =3D ts->info; + int i; + + if (!(arm_feature(env, ARM_FEATURE_AARCH64))) { + fprintf(stderr, + "The selected ARM CPU does not support 64 bit mode\n"); + exit(EXIT_FAILURE); + } + + for (i =3D 0; i < 31; i++) { + env->xregs[i] =3D regs->regs[i]; + } + env->pc =3D regs->pc; + env->xregs[31] =3D regs->sp; +#ifdef TARGET_WORDS_BIGENDIAN + env->cp15.sctlr_el[1] |=3D SCTLR_E0E; + for (i =3D 1; i < 4; ++i) { + env->cp15.sctlr_el[i] |=3D SCTLR_EE; + } +#endif + + ts->stack_base =3D info->start_stack; + ts->heap_base =3D info->brk; + /* This will be filled in on the first SYS_HEAPINFO call. */ + ts->heap_limit =3D 0; } diff --git a/linux-user/main.c b/linux-user/main.c index 5271473d47..b4f08b226c 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -555,89 +555,6 @@ void cpu_loop(CPUARMState *env) process_pending_signals(env); } } - -#else - -/* AArch64 main loop */ -void cpu_loop(CPUARMState *env) -{ - CPUState *cs =3D CPU(arm_env_get_cpu(env)); - int trapnr, sig; - abi_long ret; - target_siginfo_t info; - - for (;;) { - cpu_exec_start(cs); - trapnr =3D cpu_exec(cs); - cpu_exec_end(cs); - process_queued_cpu_work(cs); - - switch (trapnr) { - case EXCP_SWI: - ret =3D do_syscall(env, - env->xregs[8], - env->xregs[0], - env->xregs[1], - env->xregs[2], - env->xregs[3], - env->xregs[4], - env->xregs[5], - 0, 0); - if (ret =3D=3D -TARGET_ERESTARTSYS) { - env->pc -=3D 4; - } else if (ret !=3D -TARGET_QEMU_ESIGRETURN) { - env->xregs[0] =3D ret; - } - break; - case EXCP_INTERRUPT: - /* just indicate that signals should be handled asap */ - break; - case EXCP_UDEF: - info.si_signo =3D TARGET_SIGILL; - info.si_errno =3D 0; - info.si_code =3D TARGET_ILL_ILLOPN; - info._sifields._sigfault._addr =3D env->pc; - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); - break; - case EXCP_PREFETCH_ABORT: - case EXCP_DATA_ABORT: - info.si_signo =3D TARGET_SIGSEGV; - info.si_errno =3D 0; - /* XXX: check env->error_code */ - info.si_code =3D TARGET_SEGV_MAPERR; - info._sifields._sigfault._addr =3D env->exception.vaddress; - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); - break; - case EXCP_DEBUG: - case EXCP_BKPT: - sig =3D gdb_handlesig(cs, TARGET_SIGTRAP); - if (sig) { - info.si_signo =3D sig; - info.si_errno =3D 0; - info.si_code =3D TARGET_TRAP_BRKPT; - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); - } - break; - case EXCP_SEMIHOST: - env->xregs[0] =3D do_arm_semihosting(env); - break; - case EXCP_YIELD: - /* nothing to do here for user-mode, just resume guest code */ - break; - case EXCP_ATOMIC: - cpu_exec_step_atomic(cs); - break; - default: - EXCP_DUMP(env, "qemu: unhandled CPU exception 0x%x - aborting\= n", trapnr); - abort(); - } - process_pending_signals(env); - /* Exception return on AArch64 always clears the exclusive monitor, - * so any return to running guest code implies this. - */ - env->exclusive_addr =3D -1; - } -} #endif /* ndef TARGET_ABI32 */ =20 #endif @@ -4495,29 +4412,7 @@ int main(int argc, char **argv, char **envp) =20 target_cpu_copy_regs(env, regs); =20 -#if defined(TARGET_AARCH64) - { - int i; - - if (!(arm_feature(env, ARM_FEATURE_AARCH64))) { - fprintf(stderr, - "The selected ARM CPU does not support 64 bit mode\n"); - exit(EXIT_FAILURE); - } - - for (i =3D 0; i < 31; i++) { - env->xregs[i] =3D regs->regs[i]; - } - env->pc =3D regs->pc; - env->xregs[31] =3D regs->sp; -#ifdef TARGET_WORDS_BIGENDIAN - env->cp15.sctlr_el[1] |=3D SCTLR_E0E; - for (i =3D 1; i < 4; ++i) { - env->cp15.sctlr_el[i] |=3D SCTLR_EE; - } -#endif - } -#elif defined(TARGET_ARM) +#if defined(TARGET_ARM) && !defined(TARGET_AARCH64) { int i; cpsr_write(env, regs->uregs[16], CPSR_USER | CPSR_EXEC, @@ -4772,7 +4667,7 @@ int main(int argc, char **argv, char **envp) } #endif =20 -#if defined(TARGET_ARM) || defined(TARGET_M68K) +#if (defined(TARGET_ARM) && !defined(TARGET_AARCH64)) || defined(TARGET_M6= 8K) ts->stack_base =3D info->start_stack; ts->heap_base =3D info->brk; /* This will be filled in on the first SYS_HEAPINFO call. */ --=20 2.14.3 From nobody Mon May 6 08:55:16 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1523475547942979.426673907961; Wed, 11 Apr 2018 12:39:07 -0700 (PDT) Received: from localhost ([::1]:50089 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f6LaE-0008RE-R8 for importer@patchew.org; Wed, 11 Apr 2018 15:39:06 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38324) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f6KwK-0006NJ-Ee for qemu-devel@nongnu.org; Wed, 11 Apr 2018 14:57:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f6KwE-00083E-Ez for qemu-devel@nongnu.org; Wed, 11 Apr 2018 14:57:52 -0400 Received: from mout.kundenserver.de ([217.72.192.74]:54209) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1f6Kw0-0007pp-G2; Wed, 11 Apr 2018 14:57:32 -0400 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue105 [212.227.15.183]) with ESMTPSA (Nemesis) id 0ML7th-1f6c2p0IJV-000NOj; Wed, 11 Apr 2018 20:57:10 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Date: Wed, 11 Apr 2018 20:56:36 +0200 Message-Id: <20180411185651.21351-5-laurent@vivier.eu> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180411185651.21351-1-laurent@vivier.eu> References: <20180411185651.21351-1-laurent@vivier.eu> X-Provags-ID: V03:K1:QA5DAsL3KcnaQpG6XGkHWg3L/kCDudv38UvPuegnlZvKJDarfKP 9L4CmnIIxZU7JNjKHWggtfINzO4zB5ClG8rcZHY271k3u7Cy/2ZWx/zexM01AyVezB0BlA6 RDpMNI6D4K8MwHiy4V/GY24H2V4tg116eyWNah82ijkrT5ikYQgW3x4P8WBZuQQRCmOQze8 CauTnDNiCu8BjCVkd7mHA== X-UI-Out-Filterresults: notjunk:1;V01:K0:BnGgc7Upswc=:1lxddF9GUZKoPxE/yUmssq Z77MbfHG8qFAS75U7uqKwno121IOAwLTfR4ii8bIRYHLWxUy/ONjb85IK/aQXWEsogyjRbGBG 3hZdA4Z4bFvDIjdZjg2uSa3bg2vVbl8qzgGWEzyR53aSoyfELURy0UdwI30/wuRc2YobvWp72 5bKwnR7UxVL2AasDIj+fw7IjoL3t7zuG4FkT6l1Q0KmsRdQSOjQ5a6nzj9ShIgPlMzpjbi60+ acBB3Puu5Umf1pIb0opn/DrC4SJhw9gdAqBZDS2EodrPgXNXTGdeaTT3WE36bYo3LU97JdgMJ nFB+wpE2OdScv8UeQEbGc/ElSlA7NQ+vjfXL4Y8peX0FK1lLxtd+3AgnCSVd+B6zZMseC+OTh oMarmSTm1FwDnXH8buZHtuTdycCkN9IQTWW78GqJ+5RRxRE691LtK3djPLE54cRWcnBcuGTYV I+cZ3iDw30vJJwl0FQ9ACsTFsDHue8V9yLHEOPtxIuzV+fZDViCKhd7R+peELq1E83jfgSzgC HY8HRANNSoBGtNLJ2+Ht4Pt5l8e/sEtPsMfUS1yaeVBcTjbHFBwvpccHW+YYGi2tQb9XtgnK0 qXeq8prik00dikyTWdPE7t8zj+UBME1QtKQCt7QqXsmKEa78QbpQHwc3MBFbZ3jHY+jLEz/0p Ft6Zj9PrDyU+4SvI0gK0PObGsi0QpP79Qh7/UhRHgZu5kM3HvhHZhQo1Tcn0alQDijdbAR1Pq c6a6y1WRpYZ2/K4ABIoCj4CNcWaDoHmynYGKlg== X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 217.72.192.74 Subject: [Qemu-devel] [PATCH for 2.13 v2 04/19] linux-user: move arm cpu loop to arm directory X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Cornelia Huck , Riku Voipio , Richard Henderson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Laurent Vivier , qemu-s390x@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" No code change, only move code from main.c to arm/cpu_loop.c and duplicate some macro defined for both arm and aarch64. Signed-off-by: Laurent Vivier Reviewed-by: Richard Henderson --- linux-user/arm/cpu_loop.c | 430 ++++++++++++++++++++++++++++++++++++++++++= +++ linux-user/main.c | 433 +-----------------------------------------= ---- 2 files changed, 432 insertions(+), 431 deletions(-) diff --git a/linux-user/arm/cpu_loop.c b/linux-user/arm/cpu_loop.c index b7700a5561..d911929bf6 100644 --- a/linux-user/arm/cpu_loop.c +++ b/linux-user/arm/cpu_loop.c @@ -19,8 +19,438 @@ =20 #include "qemu/osdep.h" #include "qemu.h" +#include "elf.h" #include "cpu_loop-common.h" =20 +#define get_user_code_u32(x, gaddr, env) \ + ({ abi_long __r =3D get_user_u32((x), (gaddr)); \ + if (!__r && bswap_code(arm_sctlr_b(env))) { \ + (x) =3D bswap32(x); \ + } \ + __r; \ + }) + +#define get_user_code_u16(x, gaddr, env) \ + ({ abi_long __r =3D get_user_u16((x), (gaddr)); \ + if (!__r && bswap_code(arm_sctlr_b(env))) { \ + (x) =3D bswap16(x); \ + } \ + __r; \ + }) + +#define get_user_data_u32(x, gaddr, env) \ + ({ abi_long __r =3D get_user_u32((x), (gaddr)); \ + if (!__r && arm_cpu_bswap_data(env)) { \ + (x) =3D bswap32(x); \ + } \ + __r; \ + }) + +#define get_user_data_u16(x, gaddr, env) \ + ({ abi_long __r =3D get_user_u16((x), (gaddr)); \ + if (!__r && arm_cpu_bswap_data(env)) { \ + (x) =3D bswap16(x); \ + } \ + __r; \ + }) + +#define put_user_data_u32(x, gaddr, env) \ + ({ typeof(x) __x =3D (x); \ + if (arm_cpu_bswap_data(env)) { \ + __x =3D bswap32(__x); \ + } \ + put_user_u32(__x, (gaddr)); \ + }) + +#define put_user_data_u16(x, gaddr, env) \ + ({ typeof(x) __x =3D (x); \ + if (arm_cpu_bswap_data(env)) { \ + __x =3D bswap16(__x); \ + } \ + put_user_u16(__x, (gaddr)); \ + }) + +/* Commpage handling -- there is no commpage for AArch64 */ + +/* + * See the Linux kernel's Documentation/arm/kernel_user_helpers.txt + * Input: + * r0 =3D pointer to oldval + * r1 =3D pointer to newval + * r2 =3D pointer to target value + * + * Output: + * r0 =3D 0 if *ptr was changed, non-0 if no exchange happened + * C set if *ptr was changed, clear if no exchange happened + * + * Note segv's in kernel helpers are a bit tricky, we can set the + * data address sensibly but the PC address is just the entry point. + */ +static void arm_kernel_cmpxchg64_helper(CPUARMState *env) +{ + uint64_t oldval, newval, val; + uint32_t addr, cpsr; + target_siginfo_t info; + + /* Based on the 32 bit code in do_kernel_trap */ + + /* XXX: This only works between threads, not between processes. + It's probably possible to implement this with native host + operations. However things like ldrex/strex are much harder so + there's not much point trying. */ + start_exclusive(); + cpsr =3D cpsr_read(env); + addr =3D env->regs[2]; + + if (get_user_u64(oldval, env->regs[0])) { + env->exception.vaddress =3D env->regs[0]; + goto segv; + }; + + if (get_user_u64(newval, env->regs[1])) { + env->exception.vaddress =3D env->regs[1]; + goto segv; + }; + + if (get_user_u64(val, addr)) { + env->exception.vaddress =3D addr; + goto segv; + } + + if (val =3D=3D oldval) { + val =3D newval; + + if (put_user_u64(val, addr)) { + env->exception.vaddress =3D addr; + goto segv; + }; + + env->regs[0] =3D 0; + cpsr |=3D CPSR_C; + } else { + env->regs[0] =3D -1; + cpsr &=3D ~CPSR_C; + } + cpsr_write(env, cpsr, CPSR_C, CPSRWriteByInstr); + end_exclusive(); + return; + +segv: + end_exclusive(); + /* We get the PC of the entry address - which is as good as anything, + on a real kernel what you get depends on which mode it uses. */ + info.si_signo =3D TARGET_SIGSEGV; + info.si_errno =3D 0; + /* XXX: check env->error_code */ + info.si_code =3D TARGET_SEGV_MAPERR; + info._sifields._sigfault._addr =3D env->exception.vaddress; + queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); +} + +/* Handle a jump to the kernel code page. */ +static int +do_kernel_trap(CPUARMState *env) +{ + uint32_t addr; + uint32_t cpsr; + uint32_t val; + + switch (env->regs[15]) { + case 0xffff0fa0: /* __kernel_memory_barrier */ + /* ??? No-op. Will need to do better for SMP. */ + break; + case 0xffff0fc0: /* __kernel_cmpxchg */ + /* XXX: This only works between threads, not between processes. + It's probably possible to implement this with native host + operations. However things like ldrex/strex are much harder so + there's not much point trying. */ + start_exclusive(); + cpsr =3D cpsr_read(env); + addr =3D env->regs[2]; + /* FIXME: This should SEGV if the access fails. */ + if (get_user_u32(val, addr)) + val =3D ~env->regs[0]; + if (val =3D=3D env->regs[0]) { + val =3D env->regs[1]; + /* FIXME: Check for segfaults. */ + put_user_u32(val, addr); + env->regs[0] =3D 0; + cpsr |=3D CPSR_C; + } else { + env->regs[0] =3D -1; + cpsr &=3D ~CPSR_C; + } + cpsr_write(env, cpsr, CPSR_C, CPSRWriteByInstr); + end_exclusive(); + break; + case 0xffff0fe0: /* __kernel_get_tls */ + env->regs[0] =3D cpu_get_tls(env); + break; + case 0xffff0f60: /* __kernel_cmpxchg64 */ + arm_kernel_cmpxchg64_helper(env); + break; + + default: + return 1; + } + /* Jump back to the caller. */ + addr =3D env->regs[14]; + if (addr & 1) { + env->thumb =3D 1; + addr &=3D ~1; + } + env->regs[15] =3D addr; + + return 0; +} + +void cpu_loop(CPUARMState *env) +{ + CPUState *cs =3D CPU(arm_env_get_cpu(env)); + int trapnr; + unsigned int n, insn; + target_siginfo_t info; + uint32_t addr; + abi_ulong ret; + + for(;;) { + cpu_exec_start(cs); + trapnr =3D cpu_exec(cs); + cpu_exec_end(cs); + process_queued_cpu_work(cs); + + switch(trapnr) { + case EXCP_UDEF: + case EXCP_NOCP: + case EXCP_INVSTATE: + { + TaskState *ts =3D cs->opaque; + uint32_t opcode; + int rc; + + /* we handle the FPU emulation here, as Linux */ + /* we get the opcode */ + /* FIXME - what to do if get_user() fails? */ + get_user_code_u32(opcode, env->regs[15], env); + + rc =3D EmulateAll(opcode, &ts->fpa, env); + if (rc =3D=3D 0) { /* illegal instruction */ + info.si_signo =3D TARGET_SIGILL; + info.si_errno =3D 0; + info.si_code =3D TARGET_ILL_ILLOPN; + info._sifields._sigfault._addr =3D env->regs[15]; + queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + } else if (rc < 0) { /* FP exception */ + int arm_fpe=3D0; + + /* translate softfloat flags to FPSR flags */ + if (-rc & float_flag_invalid) + arm_fpe |=3D BIT_IOC; + if (-rc & float_flag_divbyzero) + arm_fpe |=3D BIT_DZC; + if (-rc & float_flag_overflow) + arm_fpe |=3D BIT_OFC; + if (-rc & float_flag_underflow) + arm_fpe |=3D BIT_UFC; + if (-rc & float_flag_inexact) + arm_fpe |=3D BIT_IXC; + + FPSR fpsr =3D ts->fpa.fpsr; + //printf("fpsr 0x%x, arm_fpe 0x%x\n",fpsr,arm_fpe); + + if (fpsr & (arm_fpe << 16)) { /* exception enabled? */ + info.si_signo =3D TARGET_SIGFPE; + info.si_errno =3D 0; + + /* ordered by priority, least first */ + if (arm_fpe & BIT_IXC) info.si_code =3D TARGET_FPE_F= LTRES; + if (arm_fpe & BIT_UFC) info.si_code =3D TARGET_FPE_F= LTUND; + if (arm_fpe & BIT_OFC) info.si_code =3D TARGET_FPE_F= LTOVF; + if (arm_fpe & BIT_DZC) info.si_code =3D TARGET_FPE_F= LTDIV; + if (arm_fpe & BIT_IOC) info.si_code =3D TARGET_FPE_F= LTINV; + + info._sifields._sigfault._addr =3D env->regs[15]; + queue_signal(env, info.si_signo, QEMU_SI_FAULT, &inf= o); + } else { + env->regs[15] +=3D 4; + } + + /* accumulate unenabled exceptions */ + if ((!(fpsr & BIT_IXE)) && (arm_fpe & BIT_IXC)) + fpsr |=3D BIT_IXC; + if ((!(fpsr & BIT_UFE)) && (arm_fpe & BIT_UFC)) + fpsr |=3D BIT_UFC; + if ((!(fpsr & BIT_OFE)) && (arm_fpe & BIT_OFC)) + fpsr |=3D BIT_OFC; + if ((!(fpsr & BIT_DZE)) && (arm_fpe & BIT_DZC)) + fpsr |=3D BIT_DZC; + if ((!(fpsr & BIT_IOE)) && (arm_fpe & BIT_IOC)) + fpsr |=3D BIT_IOC; + ts->fpa.fpsr=3Dfpsr; + } else { /* everything OK */ + /* increment PC */ + env->regs[15] +=3D 4; + } + } + break; + case EXCP_SWI: + case EXCP_BKPT: + { + env->eabi =3D 1; + /* system call */ + if (trapnr =3D=3D EXCP_BKPT) { + if (env->thumb) { + /* FIXME - what to do if get_user() fails? */ + get_user_code_u16(insn, env->regs[15], env); + n =3D insn & 0xff; + env->regs[15] +=3D 2; + } else { + /* FIXME - what to do if get_user() fails? */ + get_user_code_u32(insn, env->regs[15], env); + n =3D (insn & 0xf) | ((insn >> 4) & 0xff0); + env->regs[15] +=3D 4; + } + } else { + if (env->thumb) { + /* FIXME - what to do if get_user() fails? */ + get_user_code_u16(insn, env->regs[15] - 2, env); + n =3D insn & 0xff; + } else { + /* FIXME - what to do if get_user() fails? */ + get_user_code_u32(insn, env->regs[15] - 4, env); + n =3D insn & 0xffffff; + } + } + + if (n =3D=3D ARM_NR_cacheflush) { + /* nop */ + } else if (n =3D=3D ARM_NR_semihosting + || n =3D=3D ARM_NR_thumb_semihosting) { + env->regs[0] =3D do_arm_semihosting (env); + } else if (n =3D=3D 0 || n >=3D ARM_SYSCALL_BASE || env->t= humb) { + /* linux syscall */ + if (env->thumb || n =3D=3D 0) { + n =3D env->regs[7]; + } else { + n -=3D ARM_SYSCALL_BASE; + env->eabi =3D 0; + } + if ( n > ARM_NR_BASE) { + switch (n) { + case ARM_NR_cacheflush: + /* nop */ + break; + case ARM_NR_set_tls: + cpu_set_tls(env, env->regs[0]); + env->regs[0] =3D 0; + break; + case ARM_NR_breakpoint: + env->regs[15] -=3D env->thumb ? 2 : 4; + goto excp_debug; + default: + gemu_log("qemu: Unsupported ARM syscall: 0x%x\= n", + n); + env->regs[0] =3D -TARGET_ENOSYS; + break; + } + } else { + ret =3D do_syscall(env, + n, + env->regs[0], + env->regs[1], + env->regs[2], + env->regs[3], + env->regs[4], + env->regs[5], + 0, 0); + if (ret =3D=3D -TARGET_ERESTARTSYS) { + env->regs[15] -=3D env->thumb ? 2 : 4; + } else if (ret !=3D -TARGET_QEMU_ESIGRETURN) { + env->regs[0] =3D ret; + } + } + } else { + goto error; + } + } + break; + case EXCP_SEMIHOST: + env->regs[0] =3D do_arm_semihosting(env); + break; + case EXCP_INTERRUPT: + /* just indicate that signals should be handled asap */ + break; + case EXCP_PREFETCH_ABORT: + case EXCP_DATA_ABORT: + addr =3D env->exception.vaddress; + { + info.si_signo =3D TARGET_SIGSEGV; + info.si_errno =3D 0; + /* XXX: check env->error_code */ + info.si_code =3D TARGET_SEGV_MAPERR; + info._sifields._sigfault._addr =3D addr; + queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + } + break; + case EXCP_DEBUG: + excp_debug: + { + int sig; + + sig =3D gdb_handlesig(cs, TARGET_SIGTRAP); + if (sig) + { + info.si_signo =3D sig; + info.si_errno =3D 0; + info.si_code =3D TARGET_TRAP_BRKPT; + queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + } + } + break; + case EXCP_KERNEL_TRAP: + if (do_kernel_trap(env)) + goto error; + break; + case EXCP_YIELD: + /* nothing to do here for user-mode, just resume guest code */ + break; + case EXCP_ATOMIC: + cpu_exec_step_atomic(cs); + break; + default: + error: + EXCP_DUMP(env, "qemu: unhandled CPU exception 0x%x - aborting\= n", trapnr); + abort(); + } + process_pending_signals(env); + } +} + void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs) { + CPUState *cpu =3D ENV_GET_CPU(env); + TaskState *ts =3D cpu->opaque; + struct image_info *info =3D ts->info; + int i; + + cpsr_write(env, regs->uregs[16], CPSR_USER | CPSR_EXEC, + CPSRWriteByInstr); + for(i =3D 0; i < 16; i++) { + env->regs[i] =3D regs->uregs[i]; + } +#ifdef TARGET_WORDS_BIGENDIAN + /* Enable BE8. */ + if (EF_ARM_EABI_VERSION(info->elf_flags) >=3D EF_ARM_EABI_VER4 + && (info->elf_flags & EF_ARM_BE8)) { + env->uncached_cpsr |=3D CPSR_E; + env->cp15.sctlr_el[1] |=3D SCTLR_E0E; + } else { + env->cp15.sctlr_el[1] |=3D SCTLR_B; + } +#endif + + ts->stack_base =3D info->start_stack; + ts->heap_base =3D info->brk; + /* This will be filled in on the first SYS_HEAPINFO call. */ + ts->heap_limit =3D 0; } diff --git a/linux-user/main.c b/linux-user/main.c index b4f08b226c..45d1588958 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -149,416 +149,6 @@ void fork_end(int child) } } =20 -#ifdef TARGET_ARM - -#define get_user_code_u32(x, gaddr, env) \ - ({ abi_long __r =3D get_user_u32((x), (gaddr)); \ - if (!__r && bswap_code(arm_sctlr_b(env))) { \ - (x) =3D bswap32(x); \ - } \ - __r; \ - }) - -#define get_user_code_u16(x, gaddr, env) \ - ({ abi_long __r =3D get_user_u16((x), (gaddr)); \ - if (!__r && bswap_code(arm_sctlr_b(env))) { \ - (x) =3D bswap16(x); \ - } \ - __r; \ - }) - -#define get_user_data_u32(x, gaddr, env) \ - ({ abi_long __r =3D get_user_u32((x), (gaddr)); \ - if (!__r && arm_cpu_bswap_data(env)) { \ - (x) =3D bswap32(x); \ - } \ - __r; \ - }) - -#define get_user_data_u16(x, gaddr, env) \ - ({ abi_long __r =3D get_user_u16((x), (gaddr)); \ - if (!__r && arm_cpu_bswap_data(env)) { \ - (x) =3D bswap16(x); \ - } \ - __r; \ - }) - -#define put_user_data_u32(x, gaddr, env) \ - ({ typeof(x) __x =3D (x); \ - if (arm_cpu_bswap_data(env)) { \ - __x =3D bswap32(__x); \ - } \ - put_user_u32(__x, (gaddr)); \ - }) - -#define put_user_data_u16(x, gaddr, env) \ - ({ typeof(x) __x =3D (x); \ - if (arm_cpu_bswap_data(env)) { \ - __x =3D bswap16(__x); \ - } \ - put_user_u16(__x, (gaddr)); \ - }) - -#ifdef TARGET_ABI32 -/* Commpage handling -- there is no commpage for AArch64 */ - -/* - * See the Linux kernel's Documentation/arm/kernel_user_helpers.txt - * Input: - * r0 =3D pointer to oldval - * r1 =3D pointer to newval - * r2 =3D pointer to target value - * - * Output: - * r0 =3D 0 if *ptr was changed, non-0 if no exchange happened - * C set if *ptr was changed, clear if no exchange happened - * - * Note segv's in kernel helpers are a bit tricky, we can set the - * data address sensibly but the PC address is just the entry point. - */ -static void arm_kernel_cmpxchg64_helper(CPUARMState *env) -{ - uint64_t oldval, newval, val; - uint32_t addr, cpsr; - target_siginfo_t info; - - /* Based on the 32 bit code in do_kernel_trap */ - - /* XXX: This only works between threads, not between processes. - It's probably possible to implement this with native host - operations. However things like ldrex/strex are much harder so - there's not much point trying. */ - start_exclusive(); - cpsr =3D cpsr_read(env); - addr =3D env->regs[2]; - - if (get_user_u64(oldval, env->regs[0])) { - env->exception.vaddress =3D env->regs[0]; - goto segv; - }; - - if (get_user_u64(newval, env->regs[1])) { - env->exception.vaddress =3D env->regs[1]; - goto segv; - }; - - if (get_user_u64(val, addr)) { - env->exception.vaddress =3D addr; - goto segv; - } - - if (val =3D=3D oldval) { - val =3D newval; - - if (put_user_u64(val, addr)) { - env->exception.vaddress =3D addr; - goto segv; - }; - - env->regs[0] =3D 0; - cpsr |=3D CPSR_C; - } else { - env->regs[0] =3D -1; - cpsr &=3D ~CPSR_C; - } - cpsr_write(env, cpsr, CPSR_C, CPSRWriteByInstr); - end_exclusive(); - return; - -segv: - end_exclusive(); - /* We get the PC of the entry address - which is as good as anything, - on a real kernel what you get depends on which mode it uses. */ - info.si_signo =3D TARGET_SIGSEGV; - info.si_errno =3D 0; - /* XXX: check env->error_code */ - info.si_code =3D TARGET_SEGV_MAPERR; - info._sifields._sigfault._addr =3D env->exception.vaddress; - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); -} - -/* Handle a jump to the kernel code page. */ -static int -do_kernel_trap(CPUARMState *env) -{ - uint32_t addr; - uint32_t cpsr; - uint32_t val; - - switch (env->regs[15]) { - case 0xffff0fa0: /* __kernel_memory_barrier */ - /* ??? No-op. Will need to do better for SMP. */ - break; - case 0xffff0fc0: /* __kernel_cmpxchg */ - /* XXX: This only works between threads, not between processes. - It's probably possible to implement this with native host - operations. However things like ldrex/strex are much harder so - there's not much point trying. */ - start_exclusive(); - cpsr =3D cpsr_read(env); - addr =3D env->regs[2]; - /* FIXME: This should SEGV if the access fails. */ - if (get_user_u32(val, addr)) - val =3D ~env->regs[0]; - if (val =3D=3D env->regs[0]) { - val =3D env->regs[1]; - /* FIXME: Check for segfaults. */ - put_user_u32(val, addr); - env->regs[0] =3D 0; - cpsr |=3D CPSR_C; - } else { - env->regs[0] =3D -1; - cpsr &=3D ~CPSR_C; - } - cpsr_write(env, cpsr, CPSR_C, CPSRWriteByInstr); - end_exclusive(); - break; - case 0xffff0fe0: /* __kernel_get_tls */ - env->regs[0] =3D cpu_get_tls(env); - break; - case 0xffff0f60: /* __kernel_cmpxchg64 */ - arm_kernel_cmpxchg64_helper(env); - break; - - default: - return 1; - } - /* Jump back to the caller. */ - addr =3D env->regs[14]; - if (addr & 1) { - env->thumb =3D 1; - addr &=3D ~1; - } - env->regs[15] =3D addr; - - return 0; -} - -void cpu_loop(CPUARMState *env) -{ - CPUState *cs =3D CPU(arm_env_get_cpu(env)); - int trapnr; - unsigned int n, insn; - target_siginfo_t info; - uint32_t addr; - abi_ulong ret; - - for(;;) { - cpu_exec_start(cs); - trapnr =3D cpu_exec(cs); - cpu_exec_end(cs); - process_queued_cpu_work(cs); - - switch(trapnr) { - case EXCP_UDEF: - case EXCP_NOCP: - case EXCP_INVSTATE: - { - TaskState *ts =3D cs->opaque; - uint32_t opcode; - int rc; - - /* we handle the FPU emulation here, as Linux */ - /* we get the opcode */ - /* FIXME - what to do if get_user() fails? */ - get_user_code_u32(opcode, env->regs[15], env); - - rc =3D EmulateAll(opcode, &ts->fpa, env); - if (rc =3D=3D 0) { /* illegal instruction */ - info.si_signo =3D TARGET_SIGILL; - info.si_errno =3D 0; - info.si_code =3D TARGET_ILL_ILLOPN; - info._sifields._sigfault._addr =3D env->regs[15]; - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); - } else if (rc < 0) { /* FP exception */ - int arm_fpe=3D0; - - /* translate softfloat flags to FPSR flags */ - if (-rc & float_flag_invalid) - arm_fpe |=3D BIT_IOC; - if (-rc & float_flag_divbyzero) - arm_fpe |=3D BIT_DZC; - if (-rc & float_flag_overflow) - arm_fpe |=3D BIT_OFC; - if (-rc & float_flag_underflow) - arm_fpe |=3D BIT_UFC; - if (-rc & float_flag_inexact) - arm_fpe |=3D BIT_IXC; - - FPSR fpsr =3D ts->fpa.fpsr; - //printf("fpsr 0x%x, arm_fpe 0x%x\n",fpsr,arm_fpe); - - if (fpsr & (arm_fpe << 16)) { /* exception enabled? */ - info.si_signo =3D TARGET_SIGFPE; - info.si_errno =3D 0; - - /* ordered by priority, least first */ - if (arm_fpe & BIT_IXC) info.si_code =3D TARGET_FPE_F= LTRES; - if (arm_fpe & BIT_UFC) info.si_code =3D TARGET_FPE_F= LTUND; - if (arm_fpe & BIT_OFC) info.si_code =3D TARGET_FPE_F= LTOVF; - if (arm_fpe & BIT_DZC) info.si_code =3D TARGET_FPE_F= LTDIV; - if (arm_fpe & BIT_IOC) info.si_code =3D TARGET_FPE_F= LTINV; - - info._sifields._sigfault._addr =3D env->regs[15]; - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &inf= o); - } else { - env->regs[15] +=3D 4; - } - - /* accumulate unenabled exceptions */ - if ((!(fpsr & BIT_IXE)) && (arm_fpe & BIT_IXC)) - fpsr |=3D BIT_IXC; - if ((!(fpsr & BIT_UFE)) && (arm_fpe & BIT_UFC)) - fpsr |=3D BIT_UFC; - if ((!(fpsr & BIT_OFE)) && (arm_fpe & BIT_OFC)) - fpsr |=3D BIT_OFC; - if ((!(fpsr & BIT_DZE)) && (arm_fpe & BIT_DZC)) - fpsr |=3D BIT_DZC; - if ((!(fpsr & BIT_IOE)) && (arm_fpe & BIT_IOC)) - fpsr |=3D BIT_IOC; - ts->fpa.fpsr=3Dfpsr; - } else { /* everything OK */ - /* increment PC */ - env->regs[15] +=3D 4; - } - } - break; - case EXCP_SWI: - case EXCP_BKPT: - { - env->eabi =3D 1; - /* system call */ - if (trapnr =3D=3D EXCP_BKPT) { - if (env->thumb) { - /* FIXME - what to do if get_user() fails? */ - get_user_code_u16(insn, env->regs[15], env); - n =3D insn & 0xff; - env->regs[15] +=3D 2; - } else { - /* FIXME - what to do if get_user() fails? */ - get_user_code_u32(insn, env->regs[15], env); - n =3D (insn & 0xf) | ((insn >> 4) & 0xff0); - env->regs[15] +=3D 4; - } - } else { - if (env->thumb) { - /* FIXME - what to do if get_user() fails? */ - get_user_code_u16(insn, env->regs[15] - 2, env); - n =3D insn & 0xff; - } else { - /* FIXME - what to do if get_user() fails? */ - get_user_code_u32(insn, env->regs[15] - 4, env); - n =3D insn & 0xffffff; - } - } - - if (n =3D=3D ARM_NR_cacheflush) { - /* nop */ - } else if (n =3D=3D ARM_NR_semihosting - || n =3D=3D ARM_NR_thumb_semihosting) { - env->regs[0] =3D do_arm_semihosting (env); - } else if (n =3D=3D 0 || n >=3D ARM_SYSCALL_BASE || env->t= humb) { - /* linux syscall */ - if (env->thumb || n =3D=3D 0) { - n =3D env->regs[7]; - } else { - n -=3D ARM_SYSCALL_BASE; - env->eabi =3D 0; - } - if ( n > ARM_NR_BASE) { - switch (n) { - case ARM_NR_cacheflush: - /* nop */ - break; - case ARM_NR_set_tls: - cpu_set_tls(env, env->regs[0]); - env->regs[0] =3D 0; - break; - case ARM_NR_breakpoint: - env->regs[15] -=3D env->thumb ? 2 : 4; - goto excp_debug; - default: - gemu_log("qemu: Unsupported ARM syscall: 0x%x\= n", - n); - env->regs[0] =3D -TARGET_ENOSYS; - break; - } - } else { - ret =3D do_syscall(env, - n, - env->regs[0], - env->regs[1], - env->regs[2], - env->regs[3], - env->regs[4], - env->regs[5], - 0, 0); - if (ret =3D=3D -TARGET_ERESTARTSYS) { - env->regs[15] -=3D env->thumb ? 2 : 4; - } else if (ret !=3D -TARGET_QEMU_ESIGRETURN) { - env->regs[0] =3D ret; - } - } - } else { - goto error; - } - } - break; - case EXCP_SEMIHOST: - env->regs[0] =3D do_arm_semihosting(env); - break; - case EXCP_INTERRUPT: - /* just indicate that signals should be handled asap */ - break; - case EXCP_PREFETCH_ABORT: - case EXCP_DATA_ABORT: - addr =3D env->exception.vaddress; - { - info.si_signo =3D TARGET_SIGSEGV; - info.si_errno =3D 0; - /* XXX: check env->error_code */ - info.si_code =3D TARGET_SEGV_MAPERR; - info._sifields._sigfault._addr =3D addr; - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); - } - break; - case EXCP_DEBUG: - excp_debug: - { - int sig; - - sig =3D gdb_handlesig(cs, TARGET_SIGTRAP); - if (sig) - { - info.si_signo =3D sig; - info.si_errno =3D 0; - info.si_code =3D TARGET_TRAP_BRKPT; - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); - } - } - break; - case EXCP_KERNEL_TRAP: - if (do_kernel_trap(env)) - goto error; - break; - case EXCP_YIELD: - /* nothing to do here for user-mode, just resume guest code */ - break; - case EXCP_ATOMIC: - cpu_exec_step_atomic(cs); - break; - default: - error: - EXCP_DUMP(env, "qemu: unhandled CPU exception 0x%x - aborting\= n", trapnr); - abort(); - } - process_pending_signals(env); - } -} -#endif /* ndef TARGET_ABI32 */ - -#endif - #ifdef TARGET_SPARC #define SPARC64_STACK_BIAS 2047 =20 @@ -4412,26 +4002,7 @@ int main(int argc, char **argv, char **envp) =20 target_cpu_copy_regs(env, regs); =20 -#if defined(TARGET_ARM) && !defined(TARGET_AARCH64) - { - int i; - cpsr_write(env, regs->uregs[16], CPSR_USER | CPSR_EXEC, - CPSRWriteByInstr); - for(i =3D 0; i < 16; i++) { - env->regs[i] =3D regs->uregs[i]; - } -#ifdef TARGET_WORDS_BIGENDIAN - /* Enable BE8. */ - if (EF_ARM_EABI_VERSION(info->elf_flags) >=3D EF_ARM_EABI_VER4 - && (info->elf_flags & EF_ARM_BE8)) { - env->uncached_cpsr |=3D CPSR_E; - env->cp15.sctlr_el[1] |=3D SCTLR_E0E; - } else { - env->cp15.sctlr_el[1] |=3D SCTLR_B; - } -#endif - } -#elif defined(TARGET_SPARC) +#if defined(TARGET_SPARC) { int i; env->pc =3D regs->pc; @@ -4667,7 +4238,7 @@ int main(int argc, char **argv, char **envp) } #endif =20 -#if (defined(TARGET_ARM) && !defined(TARGET_AARCH64)) || defined(TARGET_M6= 8K) +#if defined(TARGET_M68K) ts->stack_base =3D info->start_stack; ts->heap_base =3D info->brk; /* This will be filled in on the first SYS_HEAPINFO call. */ --=20 2.14.3 From nobody Mon May 6 08:55:16 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 15234754332507.96942966856102; Wed, 11 Apr 2018 12:37:13 -0700 (PDT) Received: from localhost ([::1]:49855 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f6LYO-0006Ur-7t for importer@patchew.org; Wed, 11 Apr 2018 15:37:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38374) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f6KwN-0006QT-GM for qemu-devel@nongnu.org; Wed, 11 Apr 2018 14:57:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f6KwJ-00085n-UL for qemu-devel@nongnu.org; Wed, 11 Apr 2018 14:57:55 -0400 Received: from mout.kundenserver.de ([217.72.192.75]:37715) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1f6Kw6-0007tb-Tu; Wed, 11 Apr 2018 14:57:39 -0400 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue105 [212.227.15.183]) with ESMTPSA (Nemesis) id 0MPGl6-1fAieN1U6i-004Tzk; Wed, 11 Apr 2018 20:57:11 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Date: Wed, 11 Apr 2018 20:56:37 +0200 Message-Id: <20180411185651.21351-6-laurent@vivier.eu> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180411185651.21351-1-laurent@vivier.eu> References: <20180411185651.21351-1-laurent@vivier.eu> X-Provags-ID: V03:K1:gdsC189G3TEKmOhCVUPOqG76qrp4SygVkUEa6OrYRBGZtHhM2YX j+gAdX3uCETYNWV35DrkZK89abtC77fqi/brDuNt/VL+YJUo3LL6X1KV2y0ZJ/snYcdxchX nB7bAUkTasXB/JeuE30ktSO2IShJwPmLHxmrCisjIGHxbNfOhQU7hfXRO4/XLIfffUckzBA rwGGXgNWk+117fBlBArjA== X-UI-Out-Filterresults: notjunk:1;V01:K0:fS0EM4KcljE=:UTanTQ1QnFqkw+UHJOkSxb Sy8TZVpAk5RzXsl7uZvOA847Yn+BoJlfIs5WNN3a1UglndI2mVMBjFQ6+jsLeDnmZHjU11915 pa6qbS5ATDbGinM/Ib4nRakHSUoyyh6kqpT7WcJlOrLaXUDoOe61dgFVOG6mfLUvYb3ogipzk +UDxa3w335sUUDeNwH4T6p9g6eTt7OW1gyOQU9pX4Pblfil3L3zx3lvC6pJIIXrOlHz2y4RYq WUdTefT8Too7gGAa82GfjWRGS/coINJw1nL9yw0wUUNgszxu9R7AypFQeDCuax0FJDMWRKUva zPDhfMUM4ZtIdjt6y85hkqzH6hkPzSipmflW0InHiP0eIZ8wvzsD255vxdLfnUcXZlttPUGKv HyPlJO/fYYqy+SP9e6EcUPG/inEhuAYqSaDQhcNEWxgiq6ZJdgSfU+s+w1OpbTalvEWyBJNdC NLw4LIk771VtDQfu6CcoPetXGzxF+sXKiAeaMbedinnuQJ7I+rNCoM3j55Wa0BueEl8l3UipS rIep2HE2J1p8xmOdAsux5wvJB18zFEDtYKzDHpKWMIWtEwAcdLSRtNzJA/HFKDB8RiyXowLGU ceCMz9b/jlu0o1547z5ImE4jPBHPTqaxAkwlMgNfoysQnZ7Cl871UyYOyDlhq6tSPE35AiB/P KHtMqF+clDyqp9pdZdZ3iAgUbyBsj084ZE84sRdOvAbgLUN+W42FXpxz4haNlc92D4L8M3ek3 5QsFrn4vQBlWz+0VLnApCOSEC0AZ3BEAhJFY4g== X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 217.72.192.75 Subject: [Qemu-devel] [PATCH for 2.13 v2 05/19] linux-user: move sparc/sparc64 cpu loop to sparc directory X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Cornelia Huck , Riku Voipio , Richard Henderson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Laurent Vivier , qemu-s390x@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" No code change, only move code from main.c to sparc/cpu_loop.c. Include sparc/cpu_loop.c in sparc64/cpu_loop.c to avoid to duplicate code. Signed-off-by: Laurent Vivier Reviewed-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- linux-user/main.c | 288 +-------------------------------------= ---- linux-user/sparc/cpu_loop.c | 280 ++++++++++++++++++++++++++++++++++++++= ++ linux-user/sparc64/cpu_loop.c | 8 +- 3 files changed, 282 insertions(+), 294 deletions(-) diff --git a/linux-user/main.c b/linux-user/main.c index 45d1588958..4816ec54bb 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -149,281 +149,6 @@ void fork_end(int child) } } =20 -#ifdef TARGET_SPARC -#define SPARC64_STACK_BIAS 2047 - -//#define DEBUG_WIN - -/* WARNING: dealing with register windows _is_ complicated. More info - can be found at http://www.sics.se/~psm/sparcstack.html */ -static inline int get_reg_index(CPUSPARCState *env, int cwp, int index) -{ - index =3D (index + cwp * 16) % (16 * env->nwindows); - /* wrap handling : if cwp is on the last window, then we use the - registers 'after' the end */ - if (index < 8 && env->cwp =3D=3D env->nwindows - 1) - index +=3D 16 * env->nwindows; - return index; -} - -/* save the register window 'cwp1' */ -static inline void save_window_offset(CPUSPARCState *env, int cwp1) -{ - unsigned int i; - abi_ulong sp_ptr; - - sp_ptr =3D env->regbase[get_reg_index(env, cwp1, 6)]; -#ifdef TARGET_SPARC64 - if (sp_ptr & 3) - sp_ptr +=3D SPARC64_STACK_BIAS; -#endif -#if defined(DEBUG_WIN) - printf("win_overflow: sp_ptr=3D0x" TARGET_ABI_FMT_lx " save_cwp=3D%d\n= ", - sp_ptr, cwp1); -#endif - for(i =3D 0; i < 16; i++) { - /* FIXME - what to do if put_user() fails? */ - put_user_ual(env->regbase[get_reg_index(env, cwp1, 8 + i)], sp_ptr= ); - sp_ptr +=3D sizeof(abi_ulong); - } -} - -static void save_window(CPUSPARCState *env) -{ -#ifndef TARGET_SPARC64 - unsigned int new_wim; - new_wim =3D ((env->wim >> 1) | (env->wim << (env->nwindows - 1))) & - ((1LL << env->nwindows) - 1); - save_window_offset(env, cpu_cwp_dec(env, env->cwp - 2)); - env->wim =3D new_wim; -#else - save_window_offset(env, cpu_cwp_dec(env, env->cwp - 2)); - env->cansave++; - env->canrestore--; -#endif -} - -static void restore_window(CPUSPARCState *env) -{ -#ifndef TARGET_SPARC64 - unsigned int new_wim; -#endif - unsigned int i, cwp1; - abi_ulong sp_ptr; - -#ifndef TARGET_SPARC64 - new_wim =3D ((env->wim << 1) | (env->wim >> (env->nwindows - 1))) & - ((1LL << env->nwindows) - 1); -#endif - - /* restore the invalid window */ - cwp1 =3D cpu_cwp_inc(env, env->cwp + 1); - sp_ptr =3D env->regbase[get_reg_index(env, cwp1, 6)]; -#ifdef TARGET_SPARC64 - if (sp_ptr & 3) - sp_ptr +=3D SPARC64_STACK_BIAS; -#endif -#if defined(DEBUG_WIN) - printf("win_underflow: sp_ptr=3D0x" TARGET_ABI_FMT_lx " load_cwp=3D%d\= n", - sp_ptr, cwp1); -#endif - for(i =3D 0; i < 16; i++) { - /* FIXME - what to do if get_user() fails? */ - get_user_ual(env->regbase[get_reg_index(env, cwp1, 8 + i)], sp_ptr= ); - sp_ptr +=3D sizeof(abi_ulong); - } -#ifdef TARGET_SPARC64 - env->canrestore++; - if (env->cleanwin < env->nwindows - 1) - env->cleanwin++; - env->cansave--; -#else - env->wim =3D new_wim; -#endif -} - -static void flush_windows(CPUSPARCState *env) -{ - int offset, cwp1; - - offset =3D 1; - for(;;) { - /* if restore would invoke restore_window(), then we can stop */ - cwp1 =3D cpu_cwp_inc(env, env->cwp + offset); -#ifndef TARGET_SPARC64 - if (env->wim & (1 << cwp1)) - break; -#else - if (env->canrestore =3D=3D 0) - break; - env->cansave++; - env->canrestore--; -#endif - save_window_offset(env, cwp1); - offset++; - } - cwp1 =3D cpu_cwp_inc(env, env->cwp + 1); -#ifndef TARGET_SPARC64 - /* set wim so that restore will reload the registers */ - env->wim =3D 1 << cwp1; -#endif -#if defined(DEBUG_WIN) - printf("flush_windows: nb=3D%d\n", offset - 1); -#endif -} - -void cpu_loop (CPUSPARCState *env) -{ - CPUState *cs =3D CPU(sparc_env_get_cpu(env)); - int trapnr; - abi_long ret; - target_siginfo_t info; - - while (1) { - cpu_exec_start(cs); - trapnr =3D cpu_exec(cs); - cpu_exec_end(cs); - process_queued_cpu_work(cs); - - /* Compute PSR before exposing state. */ - if (env->cc_op !=3D CC_OP_FLAGS) { - cpu_get_psr(env); - } - - switch (trapnr) { -#ifndef TARGET_SPARC64 - case 0x88: - case 0x90: -#else - case 0x110: - case 0x16d: -#endif - ret =3D do_syscall (env, env->gregs[1], - env->regwptr[0], env->regwptr[1], - env->regwptr[2], env->regwptr[3], - env->regwptr[4], env->regwptr[5], - 0, 0); - if (ret =3D=3D -TARGET_ERESTARTSYS || ret =3D=3D -TARGET_QEMU_= ESIGRETURN) { - break; - } - if ((abi_ulong)ret >=3D (abi_ulong)(-515)) { -#if defined(TARGET_SPARC64) && !defined(TARGET_ABI32) - env->xcc |=3D PSR_CARRY; -#else - env->psr |=3D PSR_CARRY; -#endif - ret =3D -ret; - } else { -#if defined(TARGET_SPARC64) && !defined(TARGET_ABI32) - env->xcc &=3D ~PSR_CARRY; -#else - env->psr &=3D ~PSR_CARRY; -#endif - } - env->regwptr[0] =3D ret; - /* next instruction */ - env->pc =3D env->npc; - env->npc =3D env->npc + 4; - break; - case 0x83: /* flush windows */ -#ifdef TARGET_ABI32 - case 0x103: -#endif - flush_windows(env); - /* next instruction */ - env->pc =3D env->npc; - env->npc =3D env->npc + 4; - break; -#ifndef TARGET_SPARC64 - case TT_WIN_OVF: /* window overflow */ - save_window(env); - break; - case TT_WIN_UNF: /* window underflow */ - restore_window(env); - break; - case TT_TFAULT: - case TT_DFAULT: - { - info.si_signo =3D TARGET_SIGSEGV; - info.si_errno =3D 0; - /* XXX: check env->error_code */ - info.si_code =3D TARGET_SEGV_MAPERR; - info._sifields._sigfault._addr =3D env->mmuregs[4]; - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); - } - break; -#else - case TT_SPILL: /* window overflow */ - save_window(env); - break; - case TT_FILL: /* window underflow */ - restore_window(env); - break; - case TT_TFAULT: - case TT_DFAULT: - { - info.si_signo =3D TARGET_SIGSEGV; - info.si_errno =3D 0; - /* XXX: check env->error_code */ - info.si_code =3D TARGET_SEGV_MAPERR; - if (trapnr =3D=3D TT_DFAULT) - info._sifields._sigfault._addr =3D env->dmmu.mmuregs[4= ]; - else - info._sifields._sigfault._addr =3D cpu_tsptr(env)->tpc; - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); - } - break; -#ifndef TARGET_ABI32 - case 0x16e: - flush_windows(env); - sparc64_get_context(env); - break; - case 0x16f: - flush_windows(env); - sparc64_set_context(env); - break; -#endif -#endif - case EXCP_INTERRUPT: - /* just indicate that signals should be handled asap */ - break; - case TT_ILL_INSN: - { - info.si_signo =3D TARGET_SIGILL; - info.si_errno =3D 0; - info.si_code =3D TARGET_ILL_ILLOPC; - info._sifields._sigfault._addr =3D env->pc; - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); - } - break; - case EXCP_DEBUG: - { - int sig; - - sig =3D gdb_handlesig(cs, TARGET_SIGTRAP); - if (sig) - { - info.si_signo =3D sig; - info.si_errno =3D 0; - info.si_code =3D TARGET_TRAP_BRKPT; - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); - } - } - break; - case EXCP_ATOMIC: - cpu_exec_step_atomic(cs); - break; - default: - printf ("Unhandled trap: 0x%x\n", trapnr); - cpu_dump_state(cs, stderr, fprintf, 0); - exit(EXIT_FAILURE); - } - process_pending_signals (env); - } -} - -#endif - #ifdef TARGET_PPC static inline uint64_t cpu_ppc_get_tb(CPUPPCState *env) { @@ -4002,18 +3727,7 @@ int main(int argc, char **argv, char **envp) =20 target_cpu_copy_regs(env, regs); =20 -#if defined(TARGET_SPARC) - { - int i; - env->pc =3D regs->pc; - env->npc =3D regs->npc; - env->y =3D regs->y; - for(i =3D 0; i < 8; i++) - env->gregs[i] =3D regs->u_regs[i]; - for(i =3D 0; i < 8; i++) - env->regwptr[i] =3D regs->u_regs[i + 8]; - } -#elif defined(TARGET_PPC) +#if defined(TARGET_PPC) { int i; =20 diff --git a/linux-user/sparc/cpu_loop.c b/linux-user/sparc/cpu_loop.c index b7700a5561..7c4796ca23 100644 --- a/linux-user/sparc/cpu_loop.c +++ b/linux-user/sparc/cpu_loop.c @@ -21,6 +21,286 @@ #include "qemu.h" #include "cpu_loop-common.h" =20 +#define SPARC64_STACK_BIAS 2047 + +//#define DEBUG_WIN + +/* WARNING: dealing with register windows _is_ complicated. More info + can be found at http://www.sics.se/~psm/sparcstack.html */ +static inline int get_reg_index(CPUSPARCState *env, int cwp, int index) +{ + index =3D (index + cwp * 16) % (16 * env->nwindows); + /* wrap handling : if cwp is on the last window, then we use the + registers 'after' the end */ + if (index < 8 && env->cwp =3D=3D env->nwindows - 1) + index +=3D 16 * env->nwindows; + return index; +} + +/* save the register window 'cwp1' */ +static inline void save_window_offset(CPUSPARCState *env, int cwp1) +{ + unsigned int i; + abi_ulong sp_ptr; + + sp_ptr =3D env->regbase[get_reg_index(env, cwp1, 6)]; +#ifdef TARGET_SPARC64 + if (sp_ptr & 3) + sp_ptr +=3D SPARC64_STACK_BIAS; +#endif +#if defined(DEBUG_WIN) + printf("win_overflow: sp_ptr=3D0x" TARGET_ABI_FMT_lx " save_cwp=3D%d\n= ", + sp_ptr, cwp1); +#endif + for(i =3D 0; i < 16; i++) { + /* FIXME - what to do if put_user() fails? */ + put_user_ual(env->regbase[get_reg_index(env, cwp1, 8 + i)], sp_ptr= ); + sp_ptr +=3D sizeof(abi_ulong); + } +} + +static void save_window(CPUSPARCState *env) +{ +#ifndef TARGET_SPARC64 + unsigned int new_wim; + new_wim =3D ((env->wim >> 1) | (env->wim << (env->nwindows - 1))) & + ((1LL << env->nwindows) - 1); + save_window_offset(env, cpu_cwp_dec(env, env->cwp - 2)); + env->wim =3D new_wim; +#else + save_window_offset(env, cpu_cwp_dec(env, env->cwp - 2)); + env->cansave++; + env->canrestore--; +#endif +} + +static void restore_window(CPUSPARCState *env) +{ +#ifndef TARGET_SPARC64 + unsigned int new_wim; +#endif + unsigned int i, cwp1; + abi_ulong sp_ptr; + +#ifndef TARGET_SPARC64 + new_wim =3D ((env->wim << 1) | (env->wim >> (env->nwindows - 1))) & + ((1LL << env->nwindows) - 1); +#endif + + /* restore the invalid window */ + cwp1 =3D cpu_cwp_inc(env, env->cwp + 1); + sp_ptr =3D env->regbase[get_reg_index(env, cwp1, 6)]; +#ifdef TARGET_SPARC64 + if (sp_ptr & 3) + sp_ptr +=3D SPARC64_STACK_BIAS; +#endif +#if defined(DEBUG_WIN) + printf("win_underflow: sp_ptr=3D0x" TARGET_ABI_FMT_lx " load_cwp=3D%d\= n", + sp_ptr, cwp1); +#endif + for(i =3D 0; i < 16; i++) { + /* FIXME - what to do if get_user() fails? */ + get_user_ual(env->regbase[get_reg_index(env, cwp1, 8 + i)], sp_ptr= ); + sp_ptr +=3D sizeof(abi_ulong); + } +#ifdef TARGET_SPARC64 + env->canrestore++; + if (env->cleanwin < env->nwindows - 1) + env->cleanwin++; + env->cansave--; +#else + env->wim =3D new_wim; +#endif +} + +static void flush_windows(CPUSPARCState *env) +{ + int offset, cwp1; + + offset =3D 1; + for(;;) { + /* if restore would invoke restore_window(), then we can stop */ + cwp1 =3D cpu_cwp_inc(env, env->cwp + offset); +#ifndef TARGET_SPARC64 + if (env->wim & (1 << cwp1)) + break; +#else + if (env->canrestore =3D=3D 0) + break; + env->cansave++; + env->canrestore--; +#endif + save_window_offset(env, cwp1); + offset++; + } + cwp1 =3D cpu_cwp_inc(env, env->cwp + 1); +#ifndef TARGET_SPARC64 + /* set wim so that restore will reload the registers */ + env->wim =3D 1 << cwp1; +#endif +#if defined(DEBUG_WIN) + printf("flush_windows: nb=3D%d\n", offset - 1); +#endif +} + +void cpu_loop (CPUSPARCState *env) +{ + CPUState *cs =3D CPU(sparc_env_get_cpu(env)); + int trapnr; + abi_long ret; + target_siginfo_t info; + + while (1) { + cpu_exec_start(cs); + trapnr =3D cpu_exec(cs); + cpu_exec_end(cs); + process_queued_cpu_work(cs); + + /* Compute PSR before exposing state. */ + if (env->cc_op !=3D CC_OP_FLAGS) { + cpu_get_psr(env); + } + + switch (trapnr) { +#ifndef TARGET_SPARC64 + case 0x88: + case 0x90: +#else + case 0x110: + case 0x16d: +#endif + ret =3D do_syscall (env, env->gregs[1], + env->regwptr[0], env->regwptr[1], + env->regwptr[2], env->regwptr[3], + env->regwptr[4], env->regwptr[5], + 0, 0); + if (ret =3D=3D -TARGET_ERESTARTSYS || ret =3D=3D -TARGET_QEMU_= ESIGRETURN) { + break; + } + if ((abi_ulong)ret >=3D (abi_ulong)(-515)) { +#if defined(TARGET_SPARC64) && !defined(TARGET_ABI32) + env->xcc |=3D PSR_CARRY; +#else + env->psr |=3D PSR_CARRY; +#endif + ret =3D -ret; + } else { +#if defined(TARGET_SPARC64) && !defined(TARGET_ABI32) + env->xcc &=3D ~PSR_CARRY; +#else + env->psr &=3D ~PSR_CARRY; +#endif + } + env->regwptr[0] =3D ret; + /* next instruction */ + env->pc =3D env->npc; + env->npc =3D env->npc + 4; + break; + case 0x83: /* flush windows */ +#ifdef TARGET_ABI32 + case 0x103: +#endif + flush_windows(env); + /* next instruction */ + env->pc =3D env->npc; + env->npc =3D env->npc + 4; + break; +#ifndef TARGET_SPARC64 + case TT_WIN_OVF: /* window overflow */ + save_window(env); + break; + case TT_WIN_UNF: /* window underflow */ + restore_window(env); + break; + case TT_TFAULT: + case TT_DFAULT: + { + info.si_signo =3D TARGET_SIGSEGV; + info.si_errno =3D 0; + /* XXX: check env->error_code */ + info.si_code =3D TARGET_SEGV_MAPERR; + info._sifields._sigfault._addr =3D env->mmuregs[4]; + queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + } + break; +#else + case TT_SPILL: /* window overflow */ + save_window(env); + break; + case TT_FILL: /* window underflow */ + restore_window(env); + break; + case TT_TFAULT: + case TT_DFAULT: + { + info.si_signo =3D TARGET_SIGSEGV; + info.si_errno =3D 0; + /* XXX: check env->error_code */ + info.si_code =3D TARGET_SEGV_MAPERR; + if (trapnr =3D=3D TT_DFAULT) + info._sifields._sigfault._addr =3D env->dmmu.mmuregs[4= ]; + else + info._sifields._sigfault._addr =3D cpu_tsptr(env)->tpc; + queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + } + break; +#ifndef TARGET_ABI32 + case 0x16e: + flush_windows(env); + sparc64_get_context(env); + break; + case 0x16f: + flush_windows(env); + sparc64_set_context(env); + break; +#endif +#endif + case EXCP_INTERRUPT: + /* just indicate that signals should be handled asap */ + break; + case TT_ILL_INSN: + { + info.si_signo =3D TARGET_SIGILL; + info.si_errno =3D 0; + info.si_code =3D TARGET_ILL_ILLOPC; + info._sifields._sigfault._addr =3D env->pc; + queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + } + break; + case EXCP_DEBUG: + { + int sig; + + sig =3D gdb_handlesig(cs, TARGET_SIGTRAP); + if (sig) + { + info.si_signo =3D sig; + info.si_errno =3D 0; + info.si_code =3D TARGET_TRAP_BRKPT; + queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + } + } + break; + case EXCP_ATOMIC: + cpu_exec_step_atomic(cs); + break; + default: + printf ("Unhandled trap: 0x%x\n", trapnr); + cpu_dump_state(cs, stderr, fprintf, 0); + exit(EXIT_FAILURE); + } + process_pending_signals (env); + } +} + void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs) { + int i; + env->pc =3D regs->pc; + env->npc =3D regs->npc; + env->y =3D regs->y; + for(i =3D 0; i < 8; i++) + env->gregs[i] =3D regs->u_regs[i]; + for(i =3D 0; i < 8; i++) + env->regwptr[i] =3D regs->u_regs[i + 8]; } diff --git a/linux-user/sparc64/cpu_loop.c b/linux-user/sparc64/cpu_loop.c index b7700a5561..4fd44e1b1e 100644 --- a/linux-user/sparc64/cpu_loop.c +++ b/linux-user/sparc64/cpu_loop.c @@ -17,10 +17,4 @@ * along with this program; if not, see . */ =20 -#include "qemu/osdep.h" -#include "qemu.h" -#include "cpu_loop-common.h" - -void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs) -{ -} +#include "../sparc/cpu_loop.c" --=20 2.14.3 From nobody Mon May 6 08:55:16 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1523475278483161.44616468522452; Wed, 11 Apr 2018 12:34:38 -0700 (PDT) Received: from localhost ([::1]:49681 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f6LVp-0004Dp-4I for importer@patchew.org; Wed, 11 Apr 2018 15:34:33 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37962) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f6Kw2-00062S-Rn for qemu-devel@nongnu.org; Wed, 11 Apr 2018 14:57:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f6Kvy-0007p7-Q9 for qemu-devel@nongnu.org; Wed, 11 Apr 2018 14:57:34 -0400 Received: from mout.kundenserver.de ([217.72.192.74]:50653) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1f6Kvy-0007oY-7z; Wed, 11 Apr 2018 14:57:30 -0400 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue105 [212.227.15.183]) with ESMTPSA (Nemesis) id 0MasOo-1eluOg1iZe-00KMxG; Wed, 11 Apr 2018 20:57:13 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Date: Wed, 11 Apr 2018 20:56:38 +0200 Message-Id: <20180411185651.21351-7-laurent@vivier.eu> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180411185651.21351-1-laurent@vivier.eu> References: <20180411185651.21351-1-laurent@vivier.eu> X-Provags-ID: V03:K1:xHo4UmfzxSAuXBZIcSE6yb0vYAAqGjsGqqpY5jyOwn0YnHjZn85 9HP3Z8g0lP8lHuRrH7i1gec8Rv1B3jQ6zKhfpoWpj1IFXKwcWslu063d19T6w5PniHCZ2FI qcZRuAeHJIPeBhsx+eXu8wNg73nAbyYA2lpJCajv43Ggj3akWg+9YqWiyIM0aW98HsYeWbv SfQYDC3hkvVG9EVmMEAVw== X-UI-Out-Filterresults: notjunk:1;V01:K0:NGcgB9bo/0o=:Ra/laEH7pMNag4KFvOCgyu vUW3bKcjTtq1FzNSgspckXAgkB4PCRMlBZ9eBGinE1ZE9wURyO0cPbttXg8qMKRfxalo80eO8 w7uF9E/jBZ8MiFbZS+VWyvohPx0hqJQofWLBrnojFyEDRm1tGT5BaCmGO0/TyoZvReEuP1UIC sJpGIheA1iIcIVmI5IuAYmnjfBQkEgqLbQAmB871nblfRE4ofuyF/kd5mRcCVwMEwmqaH39UR N2B/z14os+WB4d+vXsa/LATbc19yK+xaJBCr2utLPT3TVmI726xMEsTx6eNk6c8AaSXHUn75m x1VXBcNBRo64L3iHjk2JEU46/231ao3ENNavZEpAPWWFSrvsbXy/20po2sS1MDeI+GCWZhEMA F37dzg2biqPXmyRCKWhJjw4tAlsszVKEBlihIueYtU3U0F0JcM79na7CQRr5uygt4SBGCHZ5j nBDhXQFRT93lV0kKt2pPLiD4r9qfYjK8G9cX4mQ/fiCo7mAkuTtwZIC0N3kZ0+BqI+/PjWWdJ WEqW6ff+WPLuiZNl+0t6j8yur/F3zMWvYERsxss3qY+w57Ca4aaK+puOgY676mw2blR8Pew7J mKDK9ULUKecu7+HN5F6FRKZ+xd0ZUueUCSrJU70nEZRk9bi7GopPrC7e67UyDGm6dKq8YI+Ym TtFFo1HB21fHKmVmOPPUCxDAiGXPCp2zqHyBpJUxeDME7ku2PCH+bFP3kkk9c1agNyM90OyF0 BKhtETJwskkVKDZZSnV5QOcS/CqC3VlM5xEEfw== X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 217.72.192.74 Subject: [Qemu-devel] [PATCH for 2.13 v2 06/19] linux-user: move ppc/ppc64 cpu loop to ppc directory X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Cornelia Huck , Riku Voipio , Richard Henderson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Laurent Vivier , qemu-s390x@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" No code change, only move code from main.c to ppc/cpu_loop.c. Signed-off-by: Laurent Vivier Reviewed-by: Richard Henderson --- linux-user/main.c | 560 +-----------------------------------------= ---- linux-user/ppc/cpu_loop.c | 553 ++++++++++++++++++++++++++++++++++++++++++= +++ 2 files changed, 554 insertions(+), 559 deletions(-) diff --git a/linux-user/main.c b/linux-user/main.c index 4816ec54bb..2340320818 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -149,547 +149,6 @@ void fork_end(int child) } } =20 -#ifdef TARGET_PPC -static inline uint64_t cpu_ppc_get_tb(CPUPPCState *env) -{ - return cpu_get_host_ticks(); -} - -uint64_t cpu_ppc_load_tbl(CPUPPCState *env) -{ - return cpu_ppc_get_tb(env); -} - -uint32_t cpu_ppc_load_tbu(CPUPPCState *env) -{ - return cpu_ppc_get_tb(env) >> 32; -} - -uint64_t cpu_ppc_load_atbl(CPUPPCState *env) -{ - return cpu_ppc_get_tb(env); -} - -uint32_t cpu_ppc_load_atbu(CPUPPCState *env) -{ - return cpu_ppc_get_tb(env) >> 32; -} - -uint32_t cpu_ppc601_load_rtcu(CPUPPCState *env) -__attribute__ (( alias ("cpu_ppc_load_tbu") )); - -uint32_t cpu_ppc601_load_rtcl(CPUPPCState *env) -{ - return cpu_ppc_load_tbl(env) & 0x3FFFFF80; -} - -/* XXX: to be fixed */ -int ppc_dcr_read (ppc_dcr_t *dcr_env, int dcrn, uint32_t *valp) -{ - return -1; -} - -int ppc_dcr_write (ppc_dcr_t *dcr_env, int dcrn, uint32_t val) -{ - return -1; -} - -static int do_store_exclusive(CPUPPCState *env) -{ - target_ulong addr; - target_ulong page_addr; - target_ulong val, val2 __attribute__((unused)) =3D 0; - int flags; - int segv =3D 0; - - addr =3D env->reserve_ea; - page_addr =3D addr & TARGET_PAGE_MASK; - start_exclusive(); - mmap_lock(); - flags =3D page_get_flags(page_addr); - if ((flags & PAGE_READ) =3D=3D 0) { - segv =3D 1; - } else { - int reg =3D env->reserve_info & 0x1f; - int size =3D env->reserve_info >> 5; - int stored =3D 0; - - if (addr =3D=3D env->reserve_addr) { - switch (size) { - case 1: segv =3D get_user_u8(val, addr); break; - case 2: segv =3D get_user_u16(val, addr); break; - case 4: segv =3D get_user_u32(val, addr); break; -#if defined(TARGET_PPC64) - case 8: segv =3D get_user_u64(val, addr); break; - case 16: { - segv =3D get_user_u64(val, addr); - if (!segv) { - segv =3D get_user_u64(val2, addr + 8); - } - break; - } -#endif - default: abort(); - } - if (!segv && val =3D=3D env->reserve_val) { - val =3D env->gpr[reg]; - switch (size) { - case 1: segv =3D put_user_u8(val, addr); break; - case 2: segv =3D put_user_u16(val, addr); break; - case 4: segv =3D put_user_u32(val, addr); break; -#if defined(TARGET_PPC64) - case 8: segv =3D put_user_u64(val, addr); break; - case 16: { - if (val2 =3D=3D env->reserve_val2) { - if (msr_le) { - val2 =3D val; - val =3D env->gpr[reg+1]; - } else { - val2 =3D env->gpr[reg+1]; - } - segv =3D put_user_u64(val, addr); - if (!segv) { - segv =3D put_user_u64(val2, addr + 8); - } - } - break; - } -#endif - default: abort(); - } - if (!segv) { - stored =3D 1; - } - } - } - env->crf[0] =3D (stored << 1) | xer_so; - env->reserve_addr =3D (target_ulong)-1; - } - if (!segv) { - env->nip +=3D 4; - } - mmap_unlock(); - end_exclusive(); - return segv; -} - -void cpu_loop(CPUPPCState *env) -{ - CPUState *cs =3D CPU(ppc_env_get_cpu(env)); - target_siginfo_t info; - int trapnr; - target_ulong ret; - - for(;;) { - cpu_exec_start(cs); - trapnr =3D cpu_exec(cs); - cpu_exec_end(cs); - process_queued_cpu_work(cs); - - switch(trapnr) { - case POWERPC_EXCP_NONE: - /* Just go on */ - break; - case POWERPC_EXCP_CRITICAL: /* Critical input = */ - cpu_abort(cs, "Critical interrupt while in user mode. " - "Aborting\n"); - break; - case POWERPC_EXCP_MCHECK: /* Machine check exception = */ - cpu_abort(cs, "Machine check exception while in user mode. " - "Aborting\n"); - break; - case POWERPC_EXCP_DSI: /* Data storage exception = */ - /* XXX: check this. Seems bugged */ - switch (env->error_code & 0xFF000000) { - case 0x40000000: - case 0x42000000: - info.si_signo =3D TARGET_SIGSEGV; - info.si_errno =3D 0; - info.si_code =3D TARGET_SEGV_MAPERR; - break; - case 0x04000000: - info.si_signo =3D TARGET_SIGILL; - info.si_errno =3D 0; - info.si_code =3D TARGET_ILL_ILLADR; - break; - case 0x08000000: - info.si_signo =3D TARGET_SIGSEGV; - info.si_errno =3D 0; - info.si_code =3D TARGET_SEGV_ACCERR; - break; - default: - /* Let's send a regular segfault... */ - EXCP_DUMP(env, "Invalid segfault errno (%02x)\n", - env->error_code); - info.si_signo =3D TARGET_SIGSEGV; - info.si_errno =3D 0; - info.si_code =3D TARGET_SEGV_MAPERR; - break; - } - info._sifields._sigfault._addr =3D env->spr[SPR_DAR]; - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); - break; - case POWERPC_EXCP_ISI: /* Instruction storage exception = */ - /* XXX: check this */ - switch (env->error_code & 0xFF000000) { - case 0x40000000: - info.si_signo =3D TARGET_SIGSEGV; - info.si_errno =3D 0; - info.si_code =3D TARGET_SEGV_MAPERR; - break; - case 0x10000000: - case 0x08000000: - info.si_signo =3D TARGET_SIGSEGV; - info.si_errno =3D 0; - info.si_code =3D TARGET_SEGV_ACCERR; - break; - default: - /* Let's send a regular segfault... */ - EXCP_DUMP(env, "Invalid segfault errno (%02x)\n", - env->error_code); - info.si_signo =3D TARGET_SIGSEGV; - info.si_errno =3D 0; - info.si_code =3D TARGET_SEGV_MAPERR; - break; - } - info._sifields._sigfault._addr =3D env->nip - 4; - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); - break; - case POWERPC_EXCP_EXTERNAL: /* External input = */ - cpu_abort(cs, "External interrupt while in user mode. " - "Aborting\n"); - break; - case POWERPC_EXCP_ALIGN: /* Alignment exception = */ - /* XXX: check this */ - info.si_signo =3D TARGET_SIGBUS; - info.si_errno =3D 0; - info.si_code =3D TARGET_BUS_ADRALN; - info._sifields._sigfault._addr =3D env->nip; - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); - break; - case POWERPC_EXCP_PROGRAM: /* Program exception = */ - case POWERPC_EXCP_HV_EMU: /* HV emulation = */ - /* XXX: check this */ - switch (env->error_code & ~0xF) { - case POWERPC_EXCP_FP: - info.si_signo =3D TARGET_SIGFPE; - info.si_errno =3D 0; - switch (env->error_code & 0xF) { - case POWERPC_EXCP_FP_OX: - info.si_code =3D TARGET_FPE_FLTOVF; - break; - case POWERPC_EXCP_FP_UX: - info.si_code =3D TARGET_FPE_FLTUND; - break; - case POWERPC_EXCP_FP_ZX: - case POWERPC_EXCP_FP_VXZDZ: - info.si_code =3D TARGET_FPE_FLTDIV; - break; - case POWERPC_EXCP_FP_XX: - info.si_code =3D TARGET_FPE_FLTRES; - break; - case POWERPC_EXCP_FP_VXSOFT: - info.si_code =3D TARGET_FPE_FLTINV; - break; - case POWERPC_EXCP_FP_VXSNAN: - case POWERPC_EXCP_FP_VXISI: - case POWERPC_EXCP_FP_VXIDI: - case POWERPC_EXCP_FP_VXIMZ: - case POWERPC_EXCP_FP_VXVC: - case POWERPC_EXCP_FP_VXSQRT: - case POWERPC_EXCP_FP_VXCVI: - info.si_code =3D TARGET_FPE_FLTSUB; - break; - default: - EXCP_DUMP(env, "Unknown floating point exception (%02x= )\n", - env->error_code); - break; - } - break; - case POWERPC_EXCP_INVAL: - info.si_signo =3D TARGET_SIGILL; - info.si_errno =3D 0; - switch (env->error_code & 0xF) { - case POWERPC_EXCP_INVAL_INVAL: - info.si_code =3D TARGET_ILL_ILLOPC; - break; - case POWERPC_EXCP_INVAL_LSWX: - info.si_code =3D TARGET_ILL_ILLOPN; - break; - case POWERPC_EXCP_INVAL_SPR: - info.si_code =3D TARGET_ILL_PRVREG; - break; - case POWERPC_EXCP_INVAL_FP: - info.si_code =3D TARGET_ILL_COPROC; - break; - default: - EXCP_DUMP(env, "Unknown invalid operation (%02x)\n", - env->error_code & 0xF); - info.si_code =3D TARGET_ILL_ILLADR; - break; - } - break; - case POWERPC_EXCP_PRIV: - info.si_signo =3D TARGET_SIGILL; - info.si_errno =3D 0; - switch (env->error_code & 0xF) { - case POWERPC_EXCP_PRIV_OPC: - info.si_code =3D TARGET_ILL_PRVOPC; - break; - case POWERPC_EXCP_PRIV_REG: - info.si_code =3D TARGET_ILL_PRVREG; - break; - default: - EXCP_DUMP(env, "Unknown privilege violation (%02x)\n", - env->error_code & 0xF); - info.si_code =3D TARGET_ILL_PRVOPC; - break; - } - break; - case POWERPC_EXCP_TRAP: - cpu_abort(cs, "Tried to call a TRAP\n"); - break; - default: - /* Should not happen ! */ - cpu_abort(cs, "Unknown program exception (%02x)\n", - env->error_code); - break; - } - info._sifields._sigfault._addr =3D env->nip; - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); - break; - case POWERPC_EXCP_FPU: /* Floating-point unavailable exceptio= n */ - info.si_signo =3D TARGET_SIGILL; - info.si_errno =3D 0; - info.si_code =3D TARGET_ILL_COPROC; - info._sifields._sigfault._addr =3D env->nip; - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); - break; - case POWERPC_EXCP_SYSCALL: /* System call exception = */ - cpu_abort(cs, "Syscall exception while in user mode. " - "Aborting\n"); - break; - case POWERPC_EXCP_APU: /* Auxiliary processor unavailable = */ - info.si_signo =3D TARGET_SIGILL; - info.si_errno =3D 0; - info.si_code =3D TARGET_ILL_COPROC; - info._sifields._sigfault._addr =3D env->nip; - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); - break; - case POWERPC_EXCP_DECR: /* Decrementer exception = */ - cpu_abort(cs, "Decrementer interrupt while in user mode. " - "Aborting\n"); - break; - case POWERPC_EXCP_FIT: /* Fixed-interval timer interrupt = */ - cpu_abort(cs, "Fix interval timer interrupt while in user mode= . " - "Aborting\n"); - break; - case POWERPC_EXCP_WDT: /* Watchdog timer interrupt = */ - cpu_abort(cs, "Watchdog timer interrupt while in user mode. " - "Aborting\n"); - break; - case POWERPC_EXCP_DTLB: /* Data TLB error = */ - cpu_abort(cs, "Data TLB exception while in user mode. " - "Aborting\n"); - break; - case POWERPC_EXCP_ITLB: /* Instruction TLB error = */ - cpu_abort(cs, "Instruction TLB exception while in user mode. " - "Aborting\n"); - break; - case POWERPC_EXCP_SPEU: /* SPE/embedded floating-point unavail= . */ - info.si_signo =3D TARGET_SIGILL; - info.si_errno =3D 0; - info.si_code =3D TARGET_ILL_COPROC; - info._sifields._sigfault._addr =3D env->nip; - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); - break; - case POWERPC_EXCP_EFPDI: /* Embedded floating-point data IRQ = */ - cpu_abort(cs, "Embedded floating-point data IRQ not handled\n"= ); - break; - case POWERPC_EXCP_EFPRI: /* Embedded floating-point round IRQ = */ - cpu_abort(cs, "Embedded floating-point round IRQ not handled\n= "); - break; - case POWERPC_EXCP_EPERFM: /* Embedded performance monitor IRQ = */ - cpu_abort(cs, "Performance monitor exception not handled\n"); - break; - case POWERPC_EXCP_DOORI: /* Embedded doorbell interrupt = */ - cpu_abort(cs, "Doorbell interrupt while in user mode. " - "Aborting\n"); - break; - case POWERPC_EXCP_DOORCI: /* Embedded doorbell critical interrup= t */ - cpu_abort(cs, "Doorbell critical interrupt while in user mode.= " - "Aborting\n"); - break; - case POWERPC_EXCP_RESET: /* System reset exception = */ - cpu_abort(cs, "Reset interrupt while in user mode. " - "Aborting\n"); - break; - case POWERPC_EXCP_DSEG: /* Data segment exception = */ - cpu_abort(cs, "Data segment exception while in user mode. " - "Aborting\n"); - break; - case POWERPC_EXCP_ISEG: /* Instruction segment exception = */ - cpu_abort(cs, "Instruction segment exception " - "while in user mode. Aborting\n"); - break; - /* PowerPC 64 with hypervisor mode support */ - case POWERPC_EXCP_HDECR: /* Hypervisor decrementer exception = */ - cpu_abort(cs, "Hypervisor decrementer interrupt " - "while in user mode. Aborting\n"); - break; - case POWERPC_EXCP_TRACE: /* Trace exception = */ - /* Nothing to do: - * we use this exception to emulate step-by-step execution mod= e. - */ - break; - /* PowerPC 64 with hypervisor mode support */ - case POWERPC_EXCP_HDSI: /* Hypervisor data storage exception = */ - cpu_abort(cs, "Hypervisor data storage exception " - "while in user mode. Aborting\n"); - break; - case POWERPC_EXCP_HISI: /* Hypervisor instruction storage excp= */ - cpu_abort(cs, "Hypervisor instruction storage exception " - "while in user mode. Aborting\n"); - break; - case POWERPC_EXCP_HDSEG: /* Hypervisor data segment exception = */ - cpu_abort(cs, "Hypervisor data segment exception " - "while in user mode. Aborting\n"); - break; - case POWERPC_EXCP_HISEG: /* Hypervisor instruction segment excp= */ - cpu_abort(cs, "Hypervisor instruction segment exception " - "while in user mode. Aborting\n"); - break; - case POWERPC_EXCP_VPU: /* Vector unavailable exception = */ - info.si_signo =3D TARGET_SIGILL; - info.si_errno =3D 0; - info.si_code =3D TARGET_ILL_COPROC; - info._sifields._sigfault._addr =3D env->nip; - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); - break; - case POWERPC_EXCP_PIT: /* Programmable interval timer IRQ = */ - cpu_abort(cs, "Programmable interval timer interrupt " - "while in user mode. Aborting\n"); - break; - case POWERPC_EXCP_IO: /* IO error exception = */ - cpu_abort(cs, "IO error exception while in user mode. " - "Aborting\n"); - break; - case POWERPC_EXCP_RUNM: /* Run mode exception = */ - cpu_abort(cs, "Run mode exception while in user mode. " - "Aborting\n"); - break; - case POWERPC_EXCP_EMUL: /* Emulation trap exception = */ - cpu_abort(cs, "Emulation trap exception not handled\n"); - break; - case POWERPC_EXCP_IFTLB: /* Instruction fetch TLB error = */ - cpu_abort(cs, "Instruction fetch TLB exception " - "while in user-mode. Aborting"); - break; - case POWERPC_EXCP_DLTLB: /* Data load TLB miss = */ - cpu_abort(cs, "Data load TLB exception while in user-mode. " - "Aborting"); - break; - case POWERPC_EXCP_DSTLB: /* Data store TLB miss = */ - cpu_abort(cs, "Data store TLB exception while in user-mode. " - "Aborting"); - break; - case POWERPC_EXCP_FPA: /* Floating-point assist exception = */ - cpu_abort(cs, "Floating-point assist exception not handled\n"); - break; - case POWERPC_EXCP_IABR: /* Instruction address breakpoint = */ - cpu_abort(cs, "Instruction address breakpoint exception " - "not handled\n"); - break; - case POWERPC_EXCP_SMI: /* System management interrupt = */ - cpu_abort(cs, "System management interrupt while in user mode.= " - "Aborting\n"); - break; - case POWERPC_EXCP_THERM: /* Thermal interrupt = */ - cpu_abort(cs, "Thermal interrupt interrupt while in user mode.= " - "Aborting\n"); - break; - case POWERPC_EXCP_PERFM: /* Embedded performance monitor IRQ = */ - cpu_abort(cs, "Performance monitor exception not handled\n"); - break; - case POWERPC_EXCP_VPUA: /* Vector assist exception = */ - cpu_abort(cs, "Vector assist exception not handled\n"); - break; - case POWERPC_EXCP_SOFTP: /* Soft patch exception = */ - cpu_abort(cs, "Soft patch exception not handled\n"); - break; - case POWERPC_EXCP_MAINT: /* Maintenance exception = */ - cpu_abort(cs, "Maintenance exception while in user mode. " - "Aborting\n"); - break; - case POWERPC_EXCP_STOP: /* stop translation = */ - /* We did invalidate the instruction cache. Go on */ - break; - case POWERPC_EXCP_BRANCH: /* branch instruction: = */ - /* We just stopped because of a branch. Go on */ - break; - case POWERPC_EXCP_SYSCALL_USER: - /* system call in user-mode emulation */ - /* WARNING: - * PPC ABI uses overflow flag in cr0 to signal an error - * in syscalls. - */ - env->crf[0] &=3D ~0x1; - env->nip +=3D 4; - ret =3D do_syscall(env, env->gpr[0], env->gpr[3], env->gpr[4], - env->gpr[5], env->gpr[6], env->gpr[7], - env->gpr[8], 0, 0); - if (ret =3D=3D -TARGET_ERESTARTSYS) { - env->nip -=3D 4; - break; - } - if (ret =3D=3D (target_ulong)(-TARGET_QEMU_ESIGRETURN)) { - /* Returning from a successful sigreturn syscall. - Avoid corrupting register state. */ - break; - } - if (ret > (target_ulong)(-515)) { - env->crf[0] |=3D 0x1; - ret =3D -ret; - } - env->gpr[3] =3D ret; - break; - case POWERPC_EXCP_STCX: - if (do_store_exclusive(env)) { - info.si_signo =3D TARGET_SIGSEGV; - info.si_errno =3D 0; - info.si_code =3D TARGET_SEGV_MAPERR; - info._sifields._sigfault._addr =3D env->nip; - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); - } - break; - case EXCP_DEBUG: - { - int sig; - - sig =3D gdb_handlesig(cs, TARGET_SIGTRAP); - if (sig) { - info.si_signo =3D sig; - info.si_errno =3D 0; - info.si_code =3D TARGET_TRAP_BRKPT; - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); - } - } - break; - case EXCP_INTERRUPT: - /* just indicate that signals should be handled asap */ - break; - case EXCP_ATOMIC: - cpu_exec_step_atomic(cs); - break; - default: - cpu_abort(cs, "Unknown exception 0x%x. Aborting\n", trapnr); - break; - } - process_pending_signals(env); - } -} -#endif - #ifdef TARGET_MIPS =20 # ifdef TARGET_ABI_MIPSO32 @@ -3727,24 +3186,7 @@ int main(int argc, char **argv, char **envp) =20 target_cpu_copy_regs(env, regs); =20 -#if defined(TARGET_PPC) - { - int i; - -#if defined(TARGET_PPC64) - int flag =3D (env->insns_flags2 & PPC2_BOOKE206) ? MSR_CM : MSR_SF; -#if defined(TARGET_ABI32) - env->msr &=3D ~((target_ulong)1 << flag); -#else - env->msr |=3D (target_ulong)1 << flag; -#endif -#endif - env->nip =3D regs->nip; - for(i =3D 0; i < 32; i++) { - env->gpr[i] =3D regs->gpr[i]; - } - } -#elif defined(TARGET_M68K) +#if defined(TARGET_M68K) { env->pc =3D regs->pc; env->dregs[0] =3D regs->d0; diff --git a/linux-user/ppc/cpu_loop.c b/linux-user/ppc/cpu_loop.c index b7700a5561..2fb516cb00 100644 --- a/linux-user/ppc/cpu_loop.c +++ b/linux-user/ppc/cpu_loop.c @@ -21,6 +21,559 @@ #include "qemu.h" #include "cpu_loop-common.h" =20 +static inline uint64_t cpu_ppc_get_tb(CPUPPCState *env) +{ + return cpu_get_host_ticks(); +} + +uint64_t cpu_ppc_load_tbl(CPUPPCState *env) +{ + return cpu_ppc_get_tb(env); +} + +uint32_t cpu_ppc_load_tbu(CPUPPCState *env) +{ + return cpu_ppc_get_tb(env) >> 32; +} + +uint64_t cpu_ppc_load_atbl(CPUPPCState *env) +{ + return cpu_ppc_get_tb(env); +} + +uint32_t cpu_ppc_load_atbu(CPUPPCState *env) +{ + return cpu_ppc_get_tb(env) >> 32; +} + +uint32_t cpu_ppc601_load_rtcu(CPUPPCState *env) +__attribute__ (( alias ("cpu_ppc_load_tbu") )); + +uint32_t cpu_ppc601_load_rtcl(CPUPPCState *env) +{ + return cpu_ppc_load_tbl(env) & 0x3FFFFF80; +} + +/* XXX: to be fixed */ +int ppc_dcr_read (ppc_dcr_t *dcr_env, int dcrn, uint32_t *valp) +{ + return -1; +} + +int ppc_dcr_write (ppc_dcr_t *dcr_env, int dcrn, uint32_t val) +{ + return -1; +} + +static int do_store_exclusive(CPUPPCState *env) +{ + target_ulong addr; + target_ulong page_addr; + target_ulong val, val2 __attribute__((unused)) =3D 0; + int flags; + int segv =3D 0; + + addr =3D env->reserve_ea; + page_addr =3D addr & TARGET_PAGE_MASK; + start_exclusive(); + mmap_lock(); + flags =3D page_get_flags(page_addr); + if ((flags & PAGE_READ) =3D=3D 0) { + segv =3D 1; + } else { + int reg =3D env->reserve_info & 0x1f; + int size =3D env->reserve_info >> 5; + int stored =3D 0; + + if (addr =3D=3D env->reserve_addr) { + switch (size) { + case 1: segv =3D get_user_u8(val, addr); break; + case 2: segv =3D get_user_u16(val, addr); break; + case 4: segv =3D get_user_u32(val, addr); break; +#if defined(TARGET_PPC64) + case 8: segv =3D get_user_u64(val, addr); break; + case 16: { + segv =3D get_user_u64(val, addr); + if (!segv) { + segv =3D get_user_u64(val2, addr + 8); + } + break; + } +#endif + default: abort(); + } + if (!segv && val =3D=3D env->reserve_val) { + val =3D env->gpr[reg]; + switch (size) { + case 1: segv =3D put_user_u8(val, addr); break; + case 2: segv =3D put_user_u16(val, addr); break; + case 4: segv =3D put_user_u32(val, addr); break; +#if defined(TARGET_PPC64) + case 8: segv =3D put_user_u64(val, addr); break; + case 16: { + if (val2 =3D=3D env->reserve_val2) { + if (msr_le) { + val2 =3D val; + val =3D env->gpr[reg+1]; + } else { + val2 =3D env->gpr[reg+1]; + } + segv =3D put_user_u64(val, addr); + if (!segv) { + segv =3D put_user_u64(val2, addr + 8); + } + } + break; + } +#endif + default: abort(); + } + if (!segv) { + stored =3D 1; + } + } + } + env->crf[0] =3D (stored << 1) | xer_so; + env->reserve_addr =3D (target_ulong)-1; + } + if (!segv) { + env->nip +=3D 4; + } + mmap_unlock(); + end_exclusive(); + return segv; +} + +void cpu_loop(CPUPPCState *env) +{ + CPUState *cs =3D CPU(ppc_env_get_cpu(env)); + target_siginfo_t info; + int trapnr; + target_ulong ret; + + for(;;) { + cpu_exec_start(cs); + trapnr =3D cpu_exec(cs); + cpu_exec_end(cs); + process_queued_cpu_work(cs); + + switch(trapnr) { + case POWERPC_EXCP_NONE: + /* Just go on */ + break; + case POWERPC_EXCP_CRITICAL: /* Critical input = */ + cpu_abort(cs, "Critical interrupt while in user mode. " + "Aborting\n"); + break; + case POWERPC_EXCP_MCHECK: /* Machine check exception = */ + cpu_abort(cs, "Machine check exception while in user mode. " + "Aborting\n"); + break; + case POWERPC_EXCP_DSI: /* Data storage exception = */ + /* XXX: check this. Seems bugged */ + switch (env->error_code & 0xFF000000) { + case 0x40000000: + case 0x42000000: + info.si_signo =3D TARGET_SIGSEGV; + info.si_errno =3D 0; + info.si_code =3D TARGET_SEGV_MAPERR; + break; + case 0x04000000: + info.si_signo =3D TARGET_SIGILL; + info.si_errno =3D 0; + info.si_code =3D TARGET_ILL_ILLADR; + break; + case 0x08000000: + info.si_signo =3D TARGET_SIGSEGV; + info.si_errno =3D 0; + info.si_code =3D TARGET_SEGV_ACCERR; + break; + default: + /* Let's send a regular segfault... */ + EXCP_DUMP(env, "Invalid segfault errno (%02x)\n", + env->error_code); + info.si_signo =3D TARGET_SIGSEGV; + info.si_errno =3D 0; + info.si_code =3D TARGET_SEGV_MAPERR; + break; + } + info._sifields._sigfault._addr =3D env->spr[SPR_DAR]; + queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + break; + case POWERPC_EXCP_ISI: /* Instruction storage exception = */ + /* XXX: check this */ + switch (env->error_code & 0xFF000000) { + case 0x40000000: + info.si_signo =3D TARGET_SIGSEGV; + info.si_errno =3D 0; + info.si_code =3D TARGET_SEGV_MAPERR; + break; + case 0x10000000: + case 0x08000000: + info.si_signo =3D TARGET_SIGSEGV; + info.si_errno =3D 0; + info.si_code =3D TARGET_SEGV_ACCERR; + break; + default: + /* Let's send a regular segfault... */ + EXCP_DUMP(env, "Invalid segfault errno (%02x)\n", + env->error_code); + info.si_signo =3D TARGET_SIGSEGV; + info.si_errno =3D 0; + info.si_code =3D TARGET_SEGV_MAPERR; + break; + } + info._sifields._sigfault._addr =3D env->nip - 4; + queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + break; + case POWERPC_EXCP_EXTERNAL: /* External input = */ + cpu_abort(cs, "External interrupt while in user mode. " + "Aborting\n"); + break; + case POWERPC_EXCP_ALIGN: /* Alignment exception = */ + /* XXX: check this */ + info.si_signo =3D TARGET_SIGBUS; + info.si_errno =3D 0; + info.si_code =3D TARGET_BUS_ADRALN; + info._sifields._sigfault._addr =3D env->nip; + queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + break; + case POWERPC_EXCP_PROGRAM: /* Program exception = */ + case POWERPC_EXCP_HV_EMU: /* HV emulation = */ + /* XXX: check this */ + switch (env->error_code & ~0xF) { + case POWERPC_EXCP_FP: + info.si_signo =3D TARGET_SIGFPE; + info.si_errno =3D 0; + switch (env->error_code & 0xF) { + case POWERPC_EXCP_FP_OX: + info.si_code =3D TARGET_FPE_FLTOVF; + break; + case POWERPC_EXCP_FP_UX: + info.si_code =3D TARGET_FPE_FLTUND; + break; + case POWERPC_EXCP_FP_ZX: + case POWERPC_EXCP_FP_VXZDZ: + info.si_code =3D TARGET_FPE_FLTDIV; + break; + case POWERPC_EXCP_FP_XX: + info.si_code =3D TARGET_FPE_FLTRES; + break; + case POWERPC_EXCP_FP_VXSOFT: + info.si_code =3D TARGET_FPE_FLTINV; + break; + case POWERPC_EXCP_FP_VXSNAN: + case POWERPC_EXCP_FP_VXISI: + case POWERPC_EXCP_FP_VXIDI: + case POWERPC_EXCP_FP_VXIMZ: + case POWERPC_EXCP_FP_VXVC: + case POWERPC_EXCP_FP_VXSQRT: + case POWERPC_EXCP_FP_VXCVI: + info.si_code =3D TARGET_FPE_FLTSUB; + break; + default: + EXCP_DUMP(env, "Unknown floating point exception (%02x= )\n", + env->error_code); + break; + } + break; + case POWERPC_EXCP_INVAL: + info.si_signo =3D TARGET_SIGILL; + info.si_errno =3D 0; + switch (env->error_code & 0xF) { + case POWERPC_EXCP_INVAL_INVAL: + info.si_code =3D TARGET_ILL_ILLOPC; + break; + case POWERPC_EXCP_INVAL_LSWX: + info.si_code =3D TARGET_ILL_ILLOPN; + break; + case POWERPC_EXCP_INVAL_SPR: + info.si_code =3D TARGET_ILL_PRVREG; + break; + case POWERPC_EXCP_INVAL_FP: + info.si_code =3D TARGET_ILL_COPROC; + break; + default: + EXCP_DUMP(env, "Unknown invalid operation (%02x)\n", + env->error_code & 0xF); + info.si_code =3D TARGET_ILL_ILLADR; + break; + } + break; + case POWERPC_EXCP_PRIV: + info.si_signo =3D TARGET_SIGILL; + info.si_errno =3D 0; + switch (env->error_code & 0xF) { + case POWERPC_EXCP_PRIV_OPC: + info.si_code =3D TARGET_ILL_PRVOPC; + break; + case POWERPC_EXCP_PRIV_REG: + info.si_code =3D TARGET_ILL_PRVREG; + break; + default: + EXCP_DUMP(env, "Unknown privilege violation (%02x)\n", + env->error_code & 0xF); + info.si_code =3D TARGET_ILL_PRVOPC; + break; + } + break; + case POWERPC_EXCP_TRAP: + cpu_abort(cs, "Tried to call a TRAP\n"); + break; + default: + /* Should not happen ! */ + cpu_abort(cs, "Unknown program exception (%02x)\n", + env->error_code); + break; + } + info._sifields._sigfault._addr =3D env->nip; + queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + break; + case POWERPC_EXCP_FPU: /* Floating-point unavailable exceptio= n */ + info.si_signo =3D TARGET_SIGILL; + info.si_errno =3D 0; + info.si_code =3D TARGET_ILL_COPROC; + info._sifields._sigfault._addr =3D env->nip; + queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + break; + case POWERPC_EXCP_SYSCALL: /* System call exception = */ + cpu_abort(cs, "Syscall exception while in user mode. " + "Aborting\n"); + break; + case POWERPC_EXCP_APU: /* Auxiliary processor unavailable = */ + info.si_signo =3D TARGET_SIGILL; + info.si_errno =3D 0; + info.si_code =3D TARGET_ILL_COPROC; + info._sifields._sigfault._addr =3D env->nip; + queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + break; + case POWERPC_EXCP_DECR: /* Decrementer exception = */ + cpu_abort(cs, "Decrementer interrupt while in user mode. " + "Aborting\n"); + break; + case POWERPC_EXCP_FIT: /* Fixed-interval timer interrupt = */ + cpu_abort(cs, "Fix interval timer interrupt while in user mode= . " + "Aborting\n"); + break; + case POWERPC_EXCP_WDT: /* Watchdog timer interrupt = */ + cpu_abort(cs, "Watchdog timer interrupt while in user mode. " + "Aborting\n"); + break; + case POWERPC_EXCP_DTLB: /* Data TLB error = */ + cpu_abort(cs, "Data TLB exception while in user mode. " + "Aborting\n"); + break; + case POWERPC_EXCP_ITLB: /* Instruction TLB error = */ + cpu_abort(cs, "Instruction TLB exception while in user mode. " + "Aborting\n"); + break; + case POWERPC_EXCP_SPEU: /* SPE/embedded floating-point unavail= . */ + info.si_signo =3D TARGET_SIGILL; + info.si_errno =3D 0; + info.si_code =3D TARGET_ILL_COPROC; + info._sifields._sigfault._addr =3D env->nip; + queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + break; + case POWERPC_EXCP_EFPDI: /* Embedded floating-point data IRQ = */ + cpu_abort(cs, "Embedded floating-point data IRQ not handled\n"= ); + break; + case POWERPC_EXCP_EFPRI: /* Embedded floating-point round IRQ = */ + cpu_abort(cs, "Embedded floating-point round IRQ not handled\n= "); + break; + case POWERPC_EXCP_EPERFM: /* Embedded performance monitor IRQ = */ + cpu_abort(cs, "Performance monitor exception not handled\n"); + break; + case POWERPC_EXCP_DOORI: /* Embedded doorbell interrupt = */ + cpu_abort(cs, "Doorbell interrupt while in user mode. " + "Aborting\n"); + break; + case POWERPC_EXCP_DOORCI: /* Embedded doorbell critical interrup= t */ + cpu_abort(cs, "Doorbell critical interrupt while in user mode.= " + "Aborting\n"); + break; + case POWERPC_EXCP_RESET: /* System reset exception = */ + cpu_abort(cs, "Reset interrupt while in user mode. " + "Aborting\n"); + break; + case POWERPC_EXCP_DSEG: /* Data segment exception = */ + cpu_abort(cs, "Data segment exception while in user mode. " + "Aborting\n"); + break; + case POWERPC_EXCP_ISEG: /* Instruction segment exception = */ + cpu_abort(cs, "Instruction segment exception " + "while in user mode. Aborting\n"); + break; + /* PowerPC 64 with hypervisor mode support */ + case POWERPC_EXCP_HDECR: /* Hypervisor decrementer exception = */ + cpu_abort(cs, "Hypervisor decrementer interrupt " + "while in user mode. Aborting\n"); + break; + case POWERPC_EXCP_TRACE: /* Trace exception = */ + /* Nothing to do: + * we use this exception to emulate step-by-step execution mod= e. + */ + break; + /* PowerPC 64 with hypervisor mode support */ + case POWERPC_EXCP_HDSI: /* Hypervisor data storage exception = */ + cpu_abort(cs, "Hypervisor data storage exception " + "while in user mode. Aborting\n"); + break; + case POWERPC_EXCP_HISI: /* Hypervisor instruction storage excp= */ + cpu_abort(cs, "Hypervisor instruction storage exception " + "while in user mode. Aborting\n"); + break; + case POWERPC_EXCP_HDSEG: /* Hypervisor data segment exception = */ + cpu_abort(cs, "Hypervisor data segment exception " + "while in user mode. Aborting\n"); + break; + case POWERPC_EXCP_HISEG: /* Hypervisor instruction segment excp= */ + cpu_abort(cs, "Hypervisor instruction segment exception " + "while in user mode. Aborting\n"); + break; + case POWERPC_EXCP_VPU: /* Vector unavailable exception = */ + info.si_signo =3D TARGET_SIGILL; + info.si_errno =3D 0; + info.si_code =3D TARGET_ILL_COPROC; + info._sifields._sigfault._addr =3D env->nip; + queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + break; + case POWERPC_EXCP_PIT: /* Programmable interval timer IRQ = */ + cpu_abort(cs, "Programmable interval timer interrupt " + "while in user mode. Aborting\n"); + break; + case POWERPC_EXCP_IO: /* IO error exception = */ + cpu_abort(cs, "IO error exception while in user mode. " + "Aborting\n"); + break; + case POWERPC_EXCP_RUNM: /* Run mode exception = */ + cpu_abort(cs, "Run mode exception while in user mode. " + "Aborting\n"); + break; + case POWERPC_EXCP_EMUL: /* Emulation trap exception = */ + cpu_abort(cs, "Emulation trap exception not handled\n"); + break; + case POWERPC_EXCP_IFTLB: /* Instruction fetch TLB error = */ + cpu_abort(cs, "Instruction fetch TLB exception " + "while in user-mode. Aborting"); + break; + case POWERPC_EXCP_DLTLB: /* Data load TLB miss = */ + cpu_abort(cs, "Data load TLB exception while in user-mode. " + "Aborting"); + break; + case POWERPC_EXCP_DSTLB: /* Data store TLB miss = */ + cpu_abort(cs, "Data store TLB exception while in user-mode. " + "Aborting"); + break; + case POWERPC_EXCP_FPA: /* Floating-point assist exception = */ + cpu_abort(cs, "Floating-point assist exception not handled\n"); + break; + case POWERPC_EXCP_IABR: /* Instruction address breakpoint = */ + cpu_abort(cs, "Instruction address breakpoint exception " + "not handled\n"); + break; + case POWERPC_EXCP_SMI: /* System management interrupt = */ + cpu_abort(cs, "System management interrupt while in user mode.= " + "Aborting\n"); + break; + case POWERPC_EXCP_THERM: /* Thermal interrupt = */ + cpu_abort(cs, "Thermal interrupt interrupt while in user mode.= " + "Aborting\n"); + break; + case POWERPC_EXCP_PERFM: /* Embedded performance monitor IRQ = */ + cpu_abort(cs, "Performance monitor exception not handled\n"); + break; + case POWERPC_EXCP_VPUA: /* Vector assist exception = */ + cpu_abort(cs, "Vector assist exception not handled\n"); + break; + case POWERPC_EXCP_SOFTP: /* Soft patch exception = */ + cpu_abort(cs, "Soft patch exception not handled\n"); + break; + case POWERPC_EXCP_MAINT: /* Maintenance exception = */ + cpu_abort(cs, "Maintenance exception while in user mode. " + "Aborting\n"); + break; + case POWERPC_EXCP_STOP: /* stop translation = */ + /* We did invalidate the instruction cache. Go on */ + break; + case POWERPC_EXCP_BRANCH: /* branch instruction: = */ + /* We just stopped because of a branch. Go on */ + break; + case POWERPC_EXCP_SYSCALL_USER: + /* system call in user-mode emulation */ + /* WARNING: + * PPC ABI uses overflow flag in cr0 to signal an error + * in syscalls. + */ + env->crf[0] &=3D ~0x1; + env->nip +=3D 4; + ret =3D do_syscall(env, env->gpr[0], env->gpr[3], env->gpr[4], + env->gpr[5], env->gpr[6], env->gpr[7], + env->gpr[8], 0, 0); + if (ret =3D=3D -TARGET_ERESTARTSYS) { + env->nip -=3D 4; + break; + } + if (ret =3D=3D (target_ulong)(-TARGET_QEMU_ESIGRETURN)) { + /* Returning from a successful sigreturn syscall. + Avoid corrupting register state. */ + break; + } + if (ret > (target_ulong)(-515)) { + env->crf[0] |=3D 0x1; + ret =3D -ret; + } + env->gpr[3] =3D ret; + break; + case POWERPC_EXCP_STCX: + if (do_store_exclusive(env)) { + info.si_signo =3D TARGET_SIGSEGV; + info.si_errno =3D 0; + info.si_code =3D TARGET_SEGV_MAPERR; + info._sifields._sigfault._addr =3D env->nip; + queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + } + break; + case EXCP_DEBUG: + { + int sig; + + sig =3D gdb_handlesig(cs, TARGET_SIGTRAP); + if (sig) { + info.si_signo =3D sig; + info.si_errno =3D 0; + info.si_code =3D TARGET_TRAP_BRKPT; + queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + } + } + break; + case EXCP_INTERRUPT: + /* just indicate that signals should be handled asap */ + break; + case EXCP_ATOMIC: + cpu_exec_step_atomic(cs); + break; + default: + cpu_abort(cs, "Unknown exception 0x%x. Aborting\n", trapnr); + break; + } + process_pending_signals(env); + } +} + void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs) { + int i; + +#if defined(TARGET_PPC64) + int flag =3D (env->insns_flags2 & PPC2_BOOKE206) ? MSR_CM : MSR_SF; +#if defined(TARGET_ABI32) + env->msr &=3D ~((target_ulong)1 << flag); +#else + env->msr |=3D (target_ulong)1 << flag; +#endif +#endif + env->nip =3D regs->nip; + for(i =3D 0; i < 32; i++) { + env->gpr[i] =3D regs->gpr[i]; + } } --=20 2.14.3 From nobody Mon May 6 08:55:16 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1523475609205137.777408904288; Wed, 11 Apr 2018 12:40:09 -0700 (PDT) Received: from localhost ([::1]:50113 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f6LbD-0000qL-Sg for importer@patchew.org; Wed, 11 Apr 2018 15:40:07 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38412) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f6KwS-0006Vh-4V for qemu-devel@nongnu.org; Wed, 11 Apr 2018 14:58:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f6KwN-000872-CK for qemu-devel@nongnu.org; Wed, 11 Apr 2018 14:58:00 -0400 Received: from mout.kundenserver.de ([212.227.17.24]:43305) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1f6Kw6-0007td-Oe; Wed, 11 Apr 2018 14:57:39 -0400 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue105 [212.227.15.183]) with ESMTPSA (Nemesis) id 0MasOo-1eluOh3v22-00KMxG; Wed, 11 Apr 2018 20:57:15 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Date: Wed, 11 Apr 2018 20:56:39 +0200 Message-Id: <20180411185651.21351-8-laurent@vivier.eu> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180411185651.21351-1-laurent@vivier.eu> References: <20180411185651.21351-1-laurent@vivier.eu> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:1uL13/ICYrjjFFRLuAxAvylsVIERsOOlXRmy9hL2CF0Qm0a1fuj rtEA2q0aF4vw4Iz1PzwZwYC64CJbS/kSD226k3QHP8/szLiK4nzHxvF6NEaE/u880FTWq8c gSacMh0KRBh9u+Xalx8LWRRYCPBoBxa+y1ogbn7oBhNimtSJPZgPtmme9nYlST5PPfZvKH7 fsO/yoQR7nb2X9EGAZ50Q== X-UI-Out-Filterresults: notjunk:1;V01:K0:tHEAJKdxOko=:tpYLhKu9h5+q9o3hDNWVUu gQWldkk650cE3jlOshn/hwOxHJBZ82ytoAfJ3bgcF3+9N4WKwMtzX4hBM6hFRoVQ1L2DUT1qk cY70nIZ/J9ygJ6AVvMQP/8afQj+Pn/9Ln5N0FpSpIu3bLU9JPGXC8lmokqwOw9Tw7oY1y4f4Y VOiryiRHGmaiupqk6t1u4KN7hb6WR7lRxfKelmmtiaQ2wnIckekoxIooreivFRYjLf84ohxSR ADTse+VgBn+EPu4Tqc9Dw6noOODKGU7GTTdAFaj2XEH/wh5eJ/vnFY3tSdpNXA0nA9mtk72vQ S9oRY72P1U7fKBPINEA7fvLEScoNwL4CTa5PuiZZT1DmFQ/u62P4wJuVMQ7EiHUNvXeRvcwvC bMtLq68sMePzTJzctQUpQr+Wy/P6NRBlVqsUpgsNzhWYB7YENAFhvnxfRkbet/0hafFCtVx1Z MyUAZ7Wol/4jjFpTV8xWqCcGsEBojkD069vc9DMKRmhEev5FgHDsSbbwLdzZKjSDmpc7SoUk/ SCeDBog4BafzSb9cJgIkZYZ5C6oQnOIBeqpL22d1rcgXmP3PwmpjTRwfLxB8owRDelmdowfo8 ceImDdw+9x4oNsY4l5ExKqk5L7+psUQM8O0kjHCGF4IdYefWa99GlRL6cM3jL5OtRZwHQZ0Fu 4XhqqdC0vO6iClLw0G6u0mIr0QR99IX/4PKxzE+2QkCfetgYJjgCtN3bdHZTy2RZg/zVon+ez xse6azXq+qAx1PCa75kfM1HxY0tQxdHUaP5yJI37jW/Rxb77rwfd+nESo1M= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 212.227.17.24 Subject: [Qemu-devel] [PATCH for 2.13 v2 07/19] linux-user: move mips/mips64 cpu loop to mips directory X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Cornelia Huck , Riku Voipio , Richard Henderson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Laurent Vivier , qemu-s390x@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 No code change, only move code from main.c to mips/cpu_loop.c. Include mips/cpu_loop.c in mips64/cpu_loop.c to avoid to duplicate code. Signed-off-by: Laurent Vivier Reviewed-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- Notes: v2: expand tabs linux-user/main.c | 725 ---------------------------------------= ---- linux-user/mips/cpu_loop.c | 723 +++++++++++++++++++++++++++++++++++++++= +++ linux-user/mips64/cpu_loop.c | 8 +- 3 files changed, 724 insertions(+), 732 deletions(-) diff --git a/linux-user/main.c b/linux-user/main.c index 2340320818..a760c19379 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -149,705 +149,6 @@ void fork_end(int child) } } =20 -#ifdef TARGET_MIPS - -# ifdef TARGET_ABI_MIPSO32 -# define MIPS_SYS(name, args) args, -static const uint8_t mips_syscall_args[] =3D { - MIPS_SYS(sys_syscall , 8) /* 4000 */ - MIPS_SYS(sys_exit , 1) - MIPS_SYS(sys_fork , 0) - MIPS_SYS(sys_read , 3) - MIPS_SYS(sys_write , 3) - MIPS_SYS(sys_open , 3) /* 4005 */ - MIPS_SYS(sys_close , 1) - MIPS_SYS(sys_waitpid , 3) - MIPS_SYS(sys_creat , 2) - MIPS_SYS(sys_link , 2) - MIPS_SYS(sys_unlink , 1) /* 4010 */ - MIPS_SYS(sys_execve , 0) - MIPS_SYS(sys_chdir , 1) - MIPS_SYS(sys_time , 1) - MIPS_SYS(sys_mknod , 3) - MIPS_SYS(sys_chmod , 2) /* 4015 */ - MIPS_SYS(sys_lchown , 3) - MIPS_SYS(sys_ni_syscall , 0) - MIPS_SYS(sys_ni_syscall , 0) /* was sys_stat */ - MIPS_SYS(sys_lseek , 3) - MIPS_SYS(sys_getpid , 0) /* 4020 */ - MIPS_SYS(sys_mount , 5) - MIPS_SYS(sys_umount , 1) - MIPS_SYS(sys_setuid , 1) - MIPS_SYS(sys_getuid , 0) - MIPS_SYS(sys_stime , 1) /* 4025 */ - MIPS_SYS(sys_ptrace , 4) - MIPS_SYS(sys_alarm , 1) - MIPS_SYS(sys_ni_syscall , 0) /* was sys_fstat */ - MIPS_SYS(sys_pause , 0) - MIPS_SYS(sys_utime , 2) /* 4030 */ - MIPS_SYS(sys_ni_syscall , 0) - MIPS_SYS(sys_ni_syscall , 0) - MIPS_SYS(sys_access , 2) - MIPS_SYS(sys_nice , 1) - MIPS_SYS(sys_ni_syscall , 0) /* 4035 */ - MIPS_SYS(sys_sync , 0) - MIPS_SYS(sys_kill , 2) - MIPS_SYS(sys_rename , 2) - MIPS_SYS(sys_mkdir , 2) - MIPS_SYS(sys_rmdir , 1) /* 4040 */ - MIPS_SYS(sys_dup , 1) - MIPS_SYS(sys_pipe , 0) - MIPS_SYS(sys_times , 1) - MIPS_SYS(sys_ni_syscall , 0) - MIPS_SYS(sys_brk , 1) /* 4045 */ - MIPS_SYS(sys_setgid , 1) - MIPS_SYS(sys_getgid , 0) - MIPS_SYS(sys_ni_syscall , 0) /* was signal(2) */ - MIPS_SYS(sys_geteuid , 0) - MIPS_SYS(sys_getegid , 0) /* 4050 */ - MIPS_SYS(sys_acct , 0) - MIPS_SYS(sys_umount2 , 2) - MIPS_SYS(sys_ni_syscall , 0) - MIPS_SYS(sys_ioctl , 3) - MIPS_SYS(sys_fcntl , 3) /* 4055 */ - MIPS_SYS(sys_ni_syscall , 2) - MIPS_SYS(sys_setpgid , 2) - MIPS_SYS(sys_ni_syscall , 0) - MIPS_SYS(sys_olduname , 1) - MIPS_SYS(sys_umask , 1) /* 4060 */ - MIPS_SYS(sys_chroot , 1) - MIPS_SYS(sys_ustat , 2) - MIPS_SYS(sys_dup2 , 2) - MIPS_SYS(sys_getppid , 0) - MIPS_SYS(sys_getpgrp , 0) /* 4065 */ - MIPS_SYS(sys_setsid , 0) - MIPS_SYS(sys_sigaction , 3) - MIPS_SYS(sys_sgetmask , 0) - MIPS_SYS(sys_ssetmask , 1) - MIPS_SYS(sys_setreuid , 2) /* 4070 */ - MIPS_SYS(sys_setregid , 2) - MIPS_SYS(sys_sigsuspend , 0) - MIPS_SYS(sys_sigpending , 1) - MIPS_SYS(sys_sethostname , 2) - MIPS_SYS(sys_setrlimit , 2) /* 4075 */ - MIPS_SYS(sys_getrlimit , 2) - MIPS_SYS(sys_getrusage , 2) - MIPS_SYS(sys_gettimeofday, 2) - MIPS_SYS(sys_settimeofday, 2) - MIPS_SYS(sys_getgroups , 2) /* 4080 */ - MIPS_SYS(sys_setgroups , 2) - MIPS_SYS(sys_ni_syscall , 0) /* old_select */ - MIPS_SYS(sys_symlink , 2) - MIPS_SYS(sys_ni_syscall , 0) /* was sys_lstat */ - MIPS_SYS(sys_readlink , 3) /* 4085 */ - MIPS_SYS(sys_uselib , 1) - MIPS_SYS(sys_swapon , 2) - MIPS_SYS(sys_reboot , 3) - MIPS_SYS(old_readdir , 3) - MIPS_SYS(old_mmap , 6) /* 4090 */ - MIPS_SYS(sys_munmap , 2) - MIPS_SYS(sys_truncate , 2) - MIPS_SYS(sys_ftruncate , 2) - MIPS_SYS(sys_fchmod , 2) - MIPS_SYS(sys_fchown , 3) /* 4095 */ - MIPS_SYS(sys_getpriority , 2) - MIPS_SYS(sys_setpriority , 3) - MIPS_SYS(sys_ni_syscall , 0) - MIPS_SYS(sys_statfs , 2) - MIPS_SYS(sys_fstatfs , 2) /* 4100 */ - MIPS_SYS(sys_ni_syscall , 0) /* was ioperm(2) */ - MIPS_SYS(sys_socketcall , 2) - MIPS_SYS(sys_syslog , 3) - MIPS_SYS(sys_setitimer , 3) - MIPS_SYS(sys_getitimer , 2) /* 4105 */ - MIPS_SYS(sys_newstat , 2) - MIPS_SYS(sys_newlstat , 2) - MIPS_SYS(sys_newfstat , 2) - MIPS_SYS(sys_uname , 1) - MIPS_SYS(sys_ni_syscall , 0) /* 4110 was iopl(2) */ - MIPS_SYS(sys_vhangup , 0) - MIPS_SYS(sys_ni_syscall , 0) /* was sys_idle() */ - MIPS_SYS(sys_ni_syscall , 0) /* was sys_vm86 */ - MIPS_SYS(sys_wait4 , 4) - MIPS_SYS(sys_swapoff , 1) /* 4115 */ - MIPS_SYS(sys_sysinfo , 1) - MIPS_SYS(sys_ipc , 6) - MIPS_SYS(sys_fsync , 1) - MIPS_SYS(sys_sigreturn , 0) - MIPS_SYS(sys_clone , 6) /* 4120 */ - MIPS_SYS(sys_setdomainname, 2) - MIPS_SYS(sys_newuname , 1) - MIPS_SYS(sys_ni_syscall , 0) /* sys_modify_ldt */ - MIPS_SYS(sys_adjtimex , 1) - MIPS_SYS(sys_mprotect , 3) /* 4125 */ - MIPS_SYS(sys_sigprocmask , 3) - MIPS_SYS(sys_ni_syscall , 0) /* was create_module */ - MIPS_SYS(sys_init_module , 5) - MIPS_SYS(sys_delete_module, 1) - MIPS_SYS(sys_ni_syscall , 0) /* 4130 was get_kernel_syms */ - MIPS_SYS(sys_quotactl , 0) - MIPS_SYS(sys_getpgid , 1) - MIPS_SYS(sys_fchdir , 1) - MIPS_SYS(sys_bdflush , 2) - MIPS_SYS(sys_sysfs , 3) /* 4135 */ - MIPS_SYS(sys_personality , 1) - MIPS_SYS(sys_ni_syscall , 0) /* for afs_syscall */ - MIPS_SYS(sys_setfsuid , 1) - MIPS_SYS(sys_setfsgid , 1) - MIPS_SYS(sys_llseek , 5) /* 4140 */ - MIPS_SYS(sys_getdents , 3) - MIPS_SYS(sys_select , 5) - MIPS_SYS(sys_flock , 2) - MIPS_SYS(sys_msync , 3) - MIPS_SYS(sys_readv , 3) /* 4145 */ - MIPS_SYS(sys_writev , 3) - MIPS_SYS(sys_cacheflush , 3) - MIPS_SYS(sys_cachectl , 3) - MIPS_SYS(sys_sysmips , 4) - MIPS_SYS(sys_ni_syscall , 0) /* 4150 */ - MIPS_SYS(sys_getsid , 1) - MIPS_SYS(sys_fdatasync , 0) - MIPS_SYS(sys_sysctl , 1) - MIPS_SYS(sys_mlock , 2) - MIPS_SYS(sys_munlock , 2) /* 4155 */ - MIPS_SYS(sys_mlockall , 1) - MIPS_SYS(sys_munlockall , 0) - MIPS_SYS(sys_sched_setparam, 2) - MIPS_SYS(sys_sched_getparam, 2) - MIPS_SYS(sys_sched_setscheduler, 3) /* 4160 */ - MIPS_SYS(sys_sched_getscheduler, 1) - MIPS_SYS(sys_sched_yield , 0) - MIPS_SYS(sys_sched_get_priority_max, 1) - MIPS_SYS(sys_sched_get_priority_min, 1) - MIPS_SYS(sys_sched_rr_get_interval, 2) /* 4165 */ - MIPS_SYS(sys_nanosleep, 2) - MIPS_SYS(sys_mremap , 5) - MIPS_SYS(sys_accept , 3) - MIPS_SYS(sys_bind , 3) - MIPS_SYS(sys_connect , 3) /* 4170 */ - MIPS_SYS(sys_getpeername , 3) - MIPS_SYS(sys_getsockname , 3) - MIPS_SYS(sys_getsockopt , 5) - MIPS_SYS(sys_listen , 2) - MIPS_SYS(sys_recv , 4) /* 4175 */ - MIPS_SYS(sys_recvfrom , 6) - MIPS_SYS(sys_recvmsg , 3) - MIPS_SYS(sys_send , 4) - MIPS_SYS(sys_sendmsg , 3) - MIPS_SYS(sys_sendto , 6) /* 4180 */ - MIPS_SYS(sys_setsockopt , 5) - MIPS_SYS(sys_shutdown , 2) - MIPS_SYS(sys_socket , 3) - MIPS_SYS(sys_socketpair , 4) - MIPS_SYS(sys_setresuid , 3) /* 4185 */ - MIPS_SYS(sys_getresuid , 3) - MIPS_SYS(sys_ni_syscall , 0) /* was sys_query_module */ - MIPS_SYS(sys_poll , 3) - MIPS_SYS(sys_nfsservctl , 3) - MIPS_SYS(sys_setresgid , 3) /* 4190 */ - MIPS_SYS(sys_getresgid , 3) - MIPS_SYS(sys_prctl , 5) - MIPS_SYS(sys_rt_sigreturn, 0) - MIPS_SYS(sys_rt_sigaction, 4) - MIPS_SYS(sys_rt_sigprocmask, 4) /* 4195 */ - MIPS_SYS(sys_rt_sigpending, 2) - MIPS_SYS(sys_rt_sigtimedwait, 4) - MIPS_SYS(sys_rt_sigqueueinfo, 3) - MIPS_SYS(sys_rt_sigsuspend, 0) - MIPS_SYS(sys_pread64 , 6) /* 4200 */ - MIPS_SYS(sys_pwrite64 , 6) - MIPS_SYS(sys_chown , 3) - MIPS_SYS(sys_getcwd , 2) - MIPS_SYS(sys_capget , 2) - MIPS_SYS(sys_capset , 2) /* 4205 */ - MIPS_SYS(sys_sigaltstack , 2) - MIPS_SYS(sys_sendfile , 4) - MIPS_SYS(sys_ni_syscall , 0) - MIPS_SYS(sys_ni_syscall , 0) - MIPS_SYS(sys_mmap2 , 6) /* 4210 */ - MIPS_SYS(sys_truncate64 , 4) - MIPS_SYS(sys_ftruncate64 , 4) - MIPS_SYS(sys_stat64 , 2) - MIPS_SYS(sys_lstat64 , 2) - MIPS_SYS(sys_fstat64 , 2) /* 4215 */ - MIPS_SYS(sys_pivot_root , 2) - MIPS_SYS(sys_mincore , 3) - MIPS_SYS(sys_madvise , 3) - MIPS_SYS(sys_getdents64 , 3) - MIPS_SYS(sys_fcntl64 , 3) /* 4220 */ - MIPS_SYS(sys_ni_syscall , 0) - MIPS_SYS(sys_gettid , 0) - MIPS_SYS(sys_readahead , 5) - MIPS_SYS(sys_setxattr , 5) - MIPS_SYS(sys_lsetxattr , 5) /* 4225 */ - MIPS_SYS(sys_fsetxattr , 5) - MIPS_SYS(sys_getxattr , 4) - MIPS_SYS(sys_lgetxattr , 4) - MIPS_SYS(sys_fgetxattr , 4) - MIPS_SYS(sys_listxattr , 3) /* 4230 */ - MIPS_SYS(sys_llistxattr , 3) - MIPS_SYS(sys_flistxattr , 3) - MIPS_SYS(sys_removexattr , 2) - MIPS_SYS(sys_lremovexattr, 2) - MIPS_SYS(sys_fremovexattr, 2) /* 4235 */ - MIPS_SYS(sys_tkill , 2) - MIPS_SYS(sys_sendfile64 , 5) - MIPS_SYS(sys_futex , 6) - MIPS_SYS(sys_sched_setaffinity, 3) - MIPS_SYS(sys_sched_getaffinity, 3) /* 4240 */ - MIPS_SYS(sys_io_setup , 2) - MIPS_SYS(sys_io_destroy , 1) - MIPS_SYS(sys_io_getevents, 5) - MIPS_SYS(sys_io_submit , 3) - MIPS_SYS(sys_io_cancel , 3) /* 4245 */ - MIPS_SYS(sys_exit_group , 1) - MIPS_SYS(sys_lookup_dcookie, 3) - MIPS_SYS(sys_epoll_create, 1) - MIPS_SYS(sys_epoll_ctl , 4) - MIPS_SYS(sys_epoll_wait , 3) /* 4250 */ - MIPS_SYS(sys_remap_file_pages, 5) - MIPS_SYS(sys_set_tid_address, 1) - MIPS_SYS(sys_restart_syscall, 0) - MIPS_SYS(sys_fadvise64_64, 7) - MIPS_SYS(sys_statfs64 , 3) /* 4255 */ - MIPS_SYS(sys_fstatfs64 , 2) - MIPS_SYS(sys_timer_create, 3) - MIPS_SYS(sys_timer_settime, 4) - MIPS_SYS(sys_timer_gettime, 2) - MIPS_SYS(sys_timer_getoverrun, 1) /* 4260 */ - MIPS_SYS(sys_timer_delete, 1) - MIPS_SYS(sys_clock_settime, 2) - MIPS_SYS(sys_clock_gettime, 2) - MIPS_SYS(sys_clock_getres, 2) - MIPS_SYS(sys_clock_nanosleep, 4) /* 4265 */ - MIPS_SYS(sys_tgkill , 3) - MIPS_SYS(sys_utimes , 2) - MIPS_SYS(sys_mbind , 4) - MIPS_SYS(sys_ni_syscall , 0) /* sys_get_mempolicy */ - MIPS_SYS(sys_ni_syscall , 0) /* 4270 sys_set_mempolicy */ - MIPS_SYS(sys_mq_open , 4) - MIPS_SYS(sys_mq_unlink , 1) - MIPS_SYS(sys_mq_timedsend, 5) - MIPS_SYS(sys_mq_timedreceive, 5) - MIPS_SYS(sys_mq_notify , 2) /* 4275 */ - MIPS_SYS(sys_mq_getsetattr, 3) - MIPS_SYS(sys_ni_syscall , 0) /* sys_vserver */ - MIPS_SYS(sys_waitid , 4) - MIPS_SYS(sys_ni_syscall , 0) /* available, was setaltroot */ - MIPS_SYS(sys_add_key , 5) - MIPS_SYS(sys_request_key, 4) - MIPS_SYS(sys_keyctl , 5) - MIPS_SYS(sys_set_thread_area, 1) - MIPS_SYS(sys_inotify_init, 0) - MIPS_SYS(sys_inotify_add_watch, 3) /* 4285 */ - MIPS_SYS(sys_inotify_rm_watch, 2) - MIPS_SYS(sys_migrate_pages, 4) - MIPS_SYS(sys_openat, 4) - MIPS_SYS(sys_mkdirat, 3) - MIPS_SYS(sys_mknodat, 4) /* 4290 */ - MIPS_SYS(sys_fchownat, 5) - MIPS_SYS(sys_futimesat, 3) - MIPS_SYS(sys_fstatat64, 4) - MIPS_SYS(sys_unlinkat, 3) - MIPS_SYS(sys_renameat, 4) /* 4295 */ - MIPS_SYS(sys_linkat, 5) - MIPS_SYS(sys_symlinkat, 3) - MIPS_SYS(sys_readlinkat, 4) - MIPS_SYS(sys_fchmodat, 3) - MIPS_SYS(sys_faccessat, 3) /* 4300 */ - MIPS_SYS(sys_pselect6, 6) - MIPS_SYS(sys_ppoll, 5) - MIPS_SYS(sys_unshare, 1) - MIPS_SYS(sys_splice, 6) - MIPS_SYS(sys_sync_file_range, 7) /* 4305 */ - MIPS_SYS(sys_tee, 4) - MIPS_SYS(sys_vmsplice, 4) - MIPS_SYS(sys_move_pages, 6) - MIPS_SYS(sys_set_robust_list, 2) - MIPS_SYS(sys_get_robust_list, 3) /* 4310 */ - MIPS_SYS(sys_kexec_load, 4) - MIPS_SYS(sys_getcpu, 3) - MIPS_SYS(sys_epoll_pwait, 6) - MIPS_SYS(sys_ioprio_set, 3) - MIPS_SYS(sys_ioprio_get, 2) - MIPS_SYS(sys_utimensat, 4) - MIPS_SYS(sys_signalfd, 3) - MIPS_SYS(sys_ni_syscall, 0) /* was timerfd */ - MIPS_SYS(sys_eventfd, 1) - MIPS_SYS(sys_fallocate, 6) /* 4320 */ - MIPS_SYS(sys_timerfd_create, 2) - MIPS_SYS(sys_timerfd_gettime, 2) - MIPS_SYS(sys_timerfd_settime, 4) - MIPS_SYS(sys_signalfd4, 4) - MIPS_SYS(sys_eventfd2, 2) /* 4325 */ - MIPS_SYS(sys_epoll_create1, 1) - MIPS_SYS(sys_dup3, 3) - MIPS_SYS(sys_pipe2, 2) - MIPS_SYS(sys_inotify_init1, 1) - MIPS_SYS(sys_preadv, 5) /* 4330 */ - MIPS_SYS(sys_pwritev, 5) - MIPS_SYS(sys_rt_tgsigqueueinfo, 4) - MIPS_SYS(sys_perf_event_open, 5) - MIPS_SYS(sys_accept4, 4) - MIPS_SYS(sys_recvmmsg, 5) /* 4335 */ - MIPS_SYS(sys_fanotify_init, 2) - MIPS_SYS(sys_fanotify_mark, 6) - MIPS_SYS(sys_prlimit64, 4) - MIPS_SYS(sys_name_to_handle_at, 5) - MIPS_SYS(sys_open_by_handle_at, 3) /* 4340 */ - MIPS_SYS(sys_clock_adjtime, 2) - MIPS_SYS(sys_syncfs, 1) - MIPS_SYS(sys_sendmmsg, 4) - MIPS_SYS(sys_setns, 2) - MIPS_SYS(sys_process_vm_readv, 6) /* 345 */ - MIPS_SYS(sys_process_vm_writev, 6) - MIPS_SYS(sys_kcmp, 5) - MIPS_SYS(sys_finit_module, 3) - MIPS_SYS(sys_sched_setattr, 2) - MIPS_SYS(sys_sched_getattr, 3) /* 350 */ - MIPS_SYS(sys_renameat2, 5) - MIPS_SYS(sys_seccomp, 3) - MIPS_SYS(sys_getrandom, 3) - MIPS_SYS(sys_memfd_create, 2) - MIPS_SYS(sys_bpf, 3) /* 355 */ - MIPS_SYS(sys_execveat, 5) - MIPS_SYS(sys_userfaultfd, 1) - MIPS_SYS(sys_membarrier, 2) - MIPS_SYS(sys_mlock2, 3) - MIPS_SYS(sys_copy_file_range, 6) /* 360 */ - MIPS_SYS(sys_preadv2, 6) - MIPS_SYS(sys_pwritev2, 6) -}; -# undef MIPS_SYS -# endif /* O32 */ - -static int do_store_exclusive(CPUMIPSState *env) -{ - target_ulong addr; - target_ulong page_addr; - target_ulong val; - int flags; - int segv =3D 0; - int reg; - int d; - - addr =3D env->lladdr; - page_addr =3D addr & TARGET_PAGE_MASK; - start_exclusive(); - mmap_lock(); - flags =3D page_get_flags(page_addr); - if ((flags & PAGE_READ) =3D=3D 0) { - segv =3D 1; - } else { - reg =3D env->llreg & 0x1f; - d =3D (env->llreg & 0x20) !=3D 0; - if (d) { - segv =3D get_user_s64(val, addr); - } else { - segv =3D get_user_s32(val, addr); - } - if (!segv) { - if (val !=3D env->llval) { - env->active_tc.gpr[reg] =3D 0; - } else { - if (d) { - segv =3D put_user_u64(env->llnewval, addr); - } else { - segv =3D put_user_u32(env->llnewval, addr); - } - if (!segv) { - env->active_tc.gpr[reg] =3D 1; - } - } - } - } - env->lladdr =3D -1; - if (!segv) { - env->active_tc.PC +=3D 4; - } - mmap_unlock(); - end_exclusive(); - return segv; -} - -/* Break codes */ -enum { - BRK_OVERFLOW =3D 6, - BRK_DIVZERO =3D 7 -}; - -static int do_break(CPUMIPSState *env, target_siginfo_t *info, - unsigned int code) -{ - int ret =3D -1; - - switch (code) { - case BRK_OVERFLOW: - case BRK_DIVZERO: - info->si_signo =3D TARGET_SIGFPE; - info->si_errno =3D 0; - info->si_code =3D (code =3D=3D BRK_OVERFLOW) ? FPE_INTOVF : FPE_IN= TDIV; - queue_signal(env, info->si_signo, QEMU_SI_FAULT, &*info); - ret =3D 0; - break; - default: - info->si_signo =3D TARGET_SIGTRAP; - info->si_errno =3D 0; - queue_signal(env, info->si_signo, QEMU_SI_FAULT, &*info); - ret =3D 0; - break; - } - - return ret; -} - -void cpu_loop(CPUMIPSState *env) -{ - CPUState *cs =3D CPU(mips_env_get_cpu(env)); - target_siginfo_t info; - int trapnr; - abi_long ret; -# ifdef TARGET_ABI_MIPSO32 - unsigned int syscall_num; -# endif - - for(;;) { - cpu_exec_start(cs); - trapnr =3D cpu_exec(cs); - cpu_exec_end(cs); - process_queued_cpu_work(cs); - - switch(trapnr) { - case EXCP_SYSCALL: - env->active_tc.PC +=3D 4; -# ifdef TARGET_ABI_MIPSO32 - syscall_num =3D env->active_tc.gpr[2] - 4000; - if (syscall_num >=3D sizeof(mips_syscall_args)) { - ret =3D -TARGET_ENOSYS; - } else { - int nb_args; - abi_ulong sp_reg; - abi_ulong arg5 =3D 0, arg6 =3D 0, arg7 =3D 0, arg8 =3D 0; - - nb_args =3D mips_syscall_args[syscall_num]; - sp_reg =3D env->active_tc.gpr[29]; - switch (nb_args) { - /* these arguments are taken from the stack */ - case 8: - if ((ret =3D get_user_ual(arg8, sp_reg + 28)) !=3D 0) { - goto done_syscall; - } - case 7: - if ((ret =3D get_user_ual(arg7, sp_reg + 24)) !=3D 0) { - goto done_syscall; - } - case 6: - if ((ret =3D get_user_ual(arg6, sp_reg + 20)) !=3D 0) { - goto done_syscall; - } - case 5: - if ((ret =3D get_user_ual(arg5, sp_reg + 16)) !=3D 0) { - goto done_syscall; - } - default: - break; - } - ret =3D do_syscall(env, env->active_tc.gpr[2], - env->active_tc.gpr[4], - env->active_tc.gpr[5], - env->active_tc.gpr[6], - env->active_tc.gpr[7], - arg5, arg6, arg7, arg8); - } -done_syscall: -# else - ret =3D do_syscall(env, env->active_tc.gpr[2], - env->active_tc.gpr[4], env->active_tc.gpr[5], - env->active_tc.gpr[6], env->active_tc.gpr[7], - env->active_tc.gpr[8], env->active_tc.gpr[9], - env->active_tc.gpr[10], env->active_tc.gpr[11= ]); -# endif /* O32 */ - if (ret =3D=3D -TARGET_ERESTARTSYS) { - env->active_tc.PC -=3D 4; - break; - } - if (ret =3D=3D -TARGET_QEMU_ESIGRETURN) { - /* Returning from a successful sigreturn syscall. - Avoid clobbering register state. */ - break; - } - if ((abi_ulong)ret >=3D (abi_ulong)-1133) { - env->active_tc.gpr[7] =3D 1; /* error flag */ - ret =3D -ret; - } else { - env->active_tc.gpr[7] =3D 0; /* error flag */ - } - env->active_tc.gpr[2] =3D ret; - break; - case EXCP_TLBL: - case EXCP_TLBS: - case EXCP_AdEL: - case EXCP_AdES: - info.si_signo =3D TARGET_SIGSEGV; - info.si_errno =3D 0; - /* XXX: check env->error_code */ - info.si_code =3D TARGET_SEGV_MAPERR; - info._sifields._sigfault._addr =3D env->CP0_BadVAddr; - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); - break; - case EXCP_CpU: - case EXCP_RI: - info.si_signo =3D TARGET_SIGILL; - info.si_errno =3D 0; - info.si_code =3D 0; - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); - break; - case EXCP_INTERRUPT: - /* just indicate that signals should be handled asap */ - break; - case EXCP_DEBUG: - { - int sig; - - sig =3D gdb_handlesig(cs, TARGET_SIGTRAP); - if (sig) - { - info.si_signo =3D sig; - info.si_errno =3D 0; - info.si_code =3D TARGET_TRAP_BRKPT; - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); - } - } - break; - case EXCP_SC: - if (do_store_exclusive(env)) { - info.si_signo =3D TARGET_SIGSEGV; - info.si_errno =3D 0; - info.si_code =3D TARGET_SEGV_MAPERR; - info._sifields._sigfault._addr =3D env->active_tc.PC; - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); - } - break; - case EXCP_DSPDIS: - info.si_signo =3D TARGET_SIGILL; - info.si_errno =3D 0; - info.si_code =3D TARGET_ILL_ILLOPC; - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); - break; - /* The code below was inspired by the MIPS Linux kernel trap - * handling code in arch/mips/kernel/traps.c. - */ - case EXCP_BREAK: - { - abi_ulong trap_instr; - unsigned int code; - - if (env->hflags & MIPS_HFLAG_M16) { - if (env->insn_flags & ASE_MICROMIPS) { - /* microMIPS mode */ - ret =3D get_user_u16(trap_instr, env->active_tc.PC= ); - if (ret !=3D 0) { - goto error; - } - - if ((trap_instr >> 10) =3D=3D 0x11) { - /* 16-bit instruction */ - code =3D trap_instr & 0xf; - } else { - /* 32-bit instruction */ - abi_ulong instr_lo; - - ret =3D get_user_u16(instr_lo, - env->active_tc.PC + 2); - if (ret !=3D 0) { - goto error; - } - trap_instr =3D (trap_instr << 16) | instr_lo; - code =3D ((trap_instr >> 6) & ((1 << 20) - 1)); - /* Unfortunately, microMIPS also suffers from - the old assembler bug... */ - if (code >=3D (1 << 10)) { - code >>=3D 10; - } - } - } else { - /* MIPS16e mode */ - ret =3D get_user_u16(trap_instr, env->active_tc.PC= ); - if (ret !=3D 0) { - goto error; - } - code =3D (trap_instr >> 6) & 0x3f; - } - } else { - ret =3D get_user_u32(trap_instr, env->active_tc.PC); - if (ret !=3D 0) { - goto error; - } - - /* As described in the original Linux kernel code, the - * below checks on 'code' are to work around an old - * assembly bug. - */ - code =3D ((trap_instr >> 6) & ((1 << 20) - 1)); - if (code >=3D (1 << 10)) { - code >>=3D 10; - } - } - - if (do_break(env, &info, code) !=3D 0) { - goto error; - } - } - break; - case EXCP_TRAP: - { - abi_ulong trap_instr; - unsigned int code =3D 0; - - if (env->hflags & MIPS_HFLAG_M16) { - /* microMIPS mode */ - abi_ulong instr[2]; - - ret =3D get_user_u16(instr[0], env->active_tc.PC) || - get_user_u16(instr[1], env->active_tc.PC + 2); - - trap_instr =3D (instr[0] << 16) | instr[1]; - } else { - ret =3D get_user_u32(trap_instr, env->active_tc.PC); - } - - if (ret !=3D 0) { - goto error; - } - - /* The immediate versions don't provide a code. */ - if (!(trap_instr & 0xFC000000)) { - if (env->hflags & MIPS_HFLAG_M16) { - /* microMIPS mode */ - code =3D ((trap_instr >> 12) & ((1 << 4) - 1)); - } else { - code =3D ((trap_instr >> 6) & ((1 << 10) - 1)); - } - } - - if (do_break(env, &info, code) !=3D 0) { - goto error; - } - } - break; - case EXCP_ATOMIC: - cpu_exec_step_atomic(cs); - break; - default: -error: - EXCP_DUMP(env, "qemu: unhandled CPU exception 0x%x - aborting\= n", trapnr); - abort(); - } - process_pending_signals(env); - } -} -#endif - #ifdef TARGET_NIOS2 =20 void cpu_loop(CPUNios2State *env) @@ -3244,32 +2545,6 @@ int main(int argc, char **argv, char **envp) env->regs[31] =3D regs->r31; =20 env->sregs[SR_PC] =3D regs->pc; } -#elif defined(TARGET_MIPS) - { - int i; - - for(i =3D 0; i < 32; i++) { - env->active_tc.gpr[i] =3D regs->regs[i]; - } - env->active_tc.PC =3D regs->cp0_epc & ~(target_ulong)1; - if (regs->cp0_epc & 1) { - env->hflags |=3D MIPS_HFLAG_M16; - } - if (((info->elf_flags & EF_MIPS_NAN2008) !=3D 0) !=3D - ((env->active_fpu.fcr31 & (1 << FCR31_NAN2008)) !=3D 0)) { - if ((env->active_fpu.fcr31_rw_bitmask & - (1 << FCR31_NAN2008)) =3D=3D 0) { - fprintf(stderr, "ELF binary's NaN mode not supported by CP= U\n"); - exit(1); - } - if ((info->elf_flags & EF_MIPS_NAN2008) !=3D 0) { - env->active_fpu.fcr31 |=3D (1 << FCR31_NAN2008); - } else { - env->active_fpu.fcr31 &=3D ~(1 << FCR31_NAN2008); - } - restore_snan_bit_mode(env); - } - } #elif defined(TARGET_NIOS2) { env->regs[0] =3D 0; diff --git a/linux-user/mips/cpu_loop.c b/linux-user/mips/cpu_loop.c index b7700a5561..084ad6a041 100644 --- a/linux-user/mips/cpu_loop.c +++ b/linux-user/mips/cpu_loop.c @@ -20,7 +20,730 @@ #include "qemu/osdep.h" #include "qemu.h" #include "cpu_loop-common.h" +#include "elf.h" + +# ifdef TARGET_ABI_MIPSO32 +# define MIPS_SYS(name, args) args, +static const uint8_t mips_syscall_args[] =3D { + MIPS_SYS(sys_syscall , 8) /* 4000 */ + MIPS_SYS(sys_exit , 1) + MIPS_SYS(sys_fork , 0) + MIPS_SYS(sys_read , 3) + MIPS_SYS(sys_write , 3) + MIPS_SYS(sys_open , 3) /* 4005 */ + MIPS_SYS(sys_close , 1) + MIPS_SYS(sys_waitpid , 3) + MIPS_SYS(sys_creat , 2) + MIPS_SYS(sys_link , 2) + MIPS_SYS(sys_unlink , 1) /* 4010 */ + MIPS_SYS(sys_execve , 0) + MIPS_SYS(sys_chdir , 1) + MIPS_SYS(sys_time , 1) + MIPS_SYS(sys_mknod , 3) + MIPS_SYS(sys_chmod , 2) /* 4015 */ + MIPS_SYS(sys_lchown , 3) + MIPS_SYS(sys_ni_syscall , 0) + MIPS_SYS(sys_ni_syscall , 0) /* was sys_stat */ + MIPS_SYS(sys_lseek , 3) + MIPS_SYS(sys_getpid , 0) /* 4020 */ + MIPS_SYS(sys_mount , 5) + MIPS_SYS(sys_umount , 1) + MIPS_SYS(sys_setuid , 1) + MIPS_SYS(sys_getuid , 0) + MIPS_SYS(sys_stime , 1) /* 4025 */ + MIPS_SYS(sys_ptrace , 4) + MIPS_SYS(sys_alarm , 1) + MIPS_SYS(sys_ni_syscall , 0) /* was sys_fstat */ + MIPS_SYS(sys_pause , 0) + MIPS_SYS(sys_utime , 2) /* 4030 */ + MIPS_SYS(sys_ni_syscall , 0) + MIPS_SYS(sys_ni_syscall , 0) + MIPS_SYS(sys_access , 2) + MIPS_SYS(sys_nice , 1) + MIPS_SYS(sys_ni_syscall , 0) /* 4035 */ + MIPS_SYS(sys_sync , 0) + MIPS_SYS(sys_kill , 2) + MIPS_SYS(sys_rename , 2) + MIPS_SYS(sys_mkdir , 2) + MIPS_SYS(sys_rmdir , 1) /* 4040 */ + MIPS_SYS(sys_dup , 1) + MIPS_SYS(sys_pipe , 0) + MIPS_SYS(sys_times , 1) + MIPS_SYS(sys_ni_syscall , 0) + MIPS_SYS(sys_brk , 1) /* 4045 */ + MIPS_SYS(sys_setgid , 1) + MIPS_SYS(sys_getgid , 0) + MIPS_SYS(sys_ni_syscall , 0) /* was signal(2) */ + MIPS_SYS(sys_geteuid , 0) + MIPS_SYS(sys_getegid , 0) /* 4050 */ + MIPS_SYS(sys_acct , 0) + MIPS_SYS(sys_umount2 , 2) + MIPS_SYS(sys_ni_syscall , 0) + MIPS_SYS(sys_ioctl , 3) + MIPS_SYS(sys_fcntl , 3) /* 4055 */ + MIPS_SYS(sys_ni_syscall , 2) + MIPS_SYS(sys_setpgid , 2) + MIPS_SYS(sys_ni_syscall , 0) + MIPS_SYS(sys_olduname , 1) + MIPS_SYS(sys_umask , 1) /* 4060 */ + MIPS_SYS(sys_chroot , 1) + MIPS_SYS(sys_ustat , 2) + MIPS_SYS(sys_dup2 , 2) + MIPS_SYS(sys_getppid , 0) + MIPS_SYS(sys_getpgrp , 0) /* 4065 */ + MIPS_SYS(sys_setsid , 0) + MIPS_SYS(sys_sigaction , 3) + MIPS_SYS(sys_sgetmask , 0) + MIPS_SYS(sys_ssetmask , 1) + MIPS_SYS(sys_setreuid , 2) /* 4070 */ + MIPS_SYS(sys_setregid , 2) + MIPS_SYS(sys_sigsuspend , 0) + MIPS_SYS(sys_sigpending , 1) + MIPS_SYS(sys_sethostname , 2) + MIPS_SYS(sys_setrlimit , 2) /* 4075 */ + MIPS_SYS(sys_getrlimit , 2) + MIPS_SYS(sys_getrusage , 2) + MIPS_SYS(sys_gettimeofday, 2) + MIPS_SYS(sys_settimeofday, 2) + MIPS_SYS(sys_getgroups , 2) /* 4080 */ + MIPS_SYS(sys_setgroups , 2) + MIPS_SYS(sys_ni_syscall , 0) /* old_select */ + MIPS_SYS(sys_symlink , 2) + MIPS_SYS(sys_ni_syscall , 0) /* was sys_lstat */ + MIPS_SYS(sys_readlink , 3) /* 4085 */ + MIPS_SYS(sys_uselib , 1) + MIPS_SYS(sys_swapon , 2) + MIPS_SYS(sys_reboot , 3) + MIPS_SYS(old_readdir , 3) + MIPS_SYS(old_mmap , 6) /* 4090 */ + MIPS_SYS(sys_munmap , 2) + MIPS_SYS(sys_truncate , 2) + MIPS_SYS(sys_ftruncate , 2) + MIPS_SYS(sys_fchmod , 2) + MIPS_SYS(sys_fchown , 3) /* 4095 */ + MIPS_SYS(sys_getpriority , 2) + MIPS_SYS(sys_setpriority , 3) + MIPS_SYS(sys_ni_syscall , 0) + MIPS_SYS(sys_statfs , 2) + MIPS_SYS(sys_fstatfs , 2) /* 4100 */ + MIPS_SYS(sys_ni_syscall , 0) /* was ioperm(2) */ + MIPS_SYS(sys_socketcall , 2) + MIPS_SYS(sys_syslog , 3) + MIPS_SYS(sys_setitimer , 3) + MIPS_SYS(sys_getitimer , 2) /* 4105 */ + MIPS_SYS(sys_newstat , 2) + MIPS_SYS(sys_newlstat , 2) + MIPS_SYS(sys_newfstat , 2) + MIPS_SYS(sys_uname , 1) + MIPS_SYS(sys_ni_syscall , 0) /* 4110 was iopl(2) */ + MIPS_SYS(sys_vhangup , 0) + MIPS_SYS(sys_ni_syscall , 0) /* was sys_idle() */ + MIPS_SYS(sys_ni_syscall , 0) /* was sys_vm86 */ + MIPS_SYS(sys_wait4 , 4) + MIPS_SYS(sys_swapoff , 1) /* 4115 */ + MIPS_SYS(sys_sysinfo , 1) + MIPS_SYS(sys_ipc , 6) + MIPS_SYS(sys_fsync , 1) + MIPS_SYS(sys_sigreturn , 0) + MIPS_SYS(sys_clone , 6) /* 4120 */ + MIPS_SYS(sys_setdomainname, 2) + MIPS_SYS(sys_newuname , 1) + MIPS_SYS(sys_ni_syscall , 0) /* sys_modify_ldt */ + MIPS_SYS(sys_adjtimex , 1) + MIPS_SYS(sys_mprotect , 3) /* 4125 */ + MIPS_SYS(sys_sigprocmask , 3) + MIPS_SYS(sys_ni_syscall , 0) /* was create_module */ + MIPS_SYS(sys_init_module , 5) + MIPS_SYS(sys_delete_module, 1) + MIPS_SYS(sys_ni_syscall , 0) /* 4130 was get_kernel_syms */ + MIPS_SYS(sys_quotactl , 0) + MIPS_SYS(sys_getpgid , 1) + MIPS_SYS(sys_fchdir , 1) + MIPS_SYS(sys_bdflush , 2) + MIPS_SYS(sys_sysfs , 3) /* 4135 */ + MIPS_SYS(sys_personality , 1) + MIPS_SYS(sys_ni_syscall , 0) /* for afs_syscall */ + MIPS_SYS(sys_setfsuid , 1) + MIPS_SYS(sys_setfsgid , 1) + MIPS_SYS(sys_llseek , 5) /* 4140 */ + MIPS_SYS(sys_getdents , 3) + MIPS_SYS(sys_select , 5) + MIPS_SYS(sys_flock , 2) + MIPS_SYS(sys_msync , 3) + MIPS_SYS(sys_readv , 3) /* 4145 */ + MIPS_SYS(sys_writev , 3) + MIPS_SYS(sys_cacheflush , 3) + MIPS_SYS(sys_cachectl , 3) + MIPS_SYS(sys_sysmips , 4) + MIPS_SYS(sys_ni_syscall , 0) /* 4150 */ + MIPS_SYS(sys_getsid , 1) + MIPS_SYS(sys_fdatasync , 0) + MIPS_SYS(sys_sysctl , 1) + MIPS_SYS(sys_mlock , 2) + MIPS_SYS(sys_munlock , 2) /* 4155 */ + MIPS_SYS(sys_mlockall , 1) + MIPS_SYS(sys_munlockall , 0) + MIPS_SYS(sys_sched_setparam, 2) + MIPS_SYS(sys_sched_getparam, 2) + MIPS_SYS(sys_sched_setscheduler, 3) /* 4160 */ + MIPS_SYS(sys_sched_getscheduler, 1) + MIPS_SYS(sys_sched_yield , 0) + MIPS_SYS(sys_sched_get_priority_max, 1) + MIPS_SYS(sys_sched_get_priority_min, 1) + MIPS_SYS(sys_sched_rr_get_interval, 2) /* 4165 */ + MIPS_SYS(sys_nanosleep, 2) + MIPS_SYS(sys_mremap , 5) + MIPS_SYS(sys_accept , 3) + MIPS_SYS(sys_bind , 3) + MIPS_SYS(sys_connect , 3) /* 4170 */ + MIPS_SYS(sys_getpeername , 3) + MIPS_SYS(sys_getsockname , 3) + MIPS_SYS(sys_getsockopt , 5) + MIPS_SYS(sys_listen , 2) + MIPS_SYS(sys_recv , 4) /* 4175 */ + MIPS_SYS(sys_recvfrom , 6) + MIPS_SYS(sys_recvmsg , 3) + MIPS_SYS(sys_send , 4) + MIPS_SYS(sys_sendmsg , 3) + MIPS_SYS(sys_sendto , 6) /* 4180 */ + MIPS_SYS(sys_setsockopt , 5) + MIPS_SYS(sys_shutdown , 2) + MIPS_SYS(sys_socket , 3) + MIPS_SYS(sys_socketpair , 4) + MIPS_SYS(sys_setresuid , 3) /* 4185 */ + MIPS_SYS(sys_getresuid , 3) + MIPS_SYS(sys_ni_syscall , 0) /* was sys_query_module */ + MIPS_SYS(sys_poll , 3) + MIPS_SYS(sys_nfsservctl , 3) + MIPS_SYS(sys_setresgid , 3) /* 4190 */ + MIPS_SYS(sys_getresgid , 3) + MIPS_SYS(sys_prctl , 5) + MIPS_SYS(sys_rt_sigreturn, 0) + MIPS_SYS(sys_rt_sigaction, 4) + MIPS_SYS(sys_rt_sigprocmask, 4) /* 4195 */ + MIPS_SYS(sys_rt_sigpending, 2) + MIPS_SYS(sys_rt_sigtimedwait, 4) + MIPS_SYS(sys_rt_sigqueueinfo, 3) + MIPS_SYS(sys_rt_sigsuspend, 0) + MIPS_SYS(sys_pread64 , 6) /* 4200 */ + MIPS_SYS(sys_pwrite64 , 6) + MIPS_SYS(sys_chown , 3) + MIPS_SYS(sys_getcwd , 2) + MIPS_SYS(sys_capget , 2) + MIPS_SYS(sys_capset , 2) /* 4205 */ + MIPS_SYS(sys_sigaltstack , 2) + MIPS_SYS(sys_sendfile , 4) + MIPS_SYS(sys_ni_syscall , 0) + MIPS_SYS(sys_ni_syscall , 0) + MIPS_SYS(sys_mmap2 , 6) /* 4210 */ + MIPS_SYS(sys_truncate64 , 4) + MIPS_SYS(sys_ftruncate64 , 4) + MIPS_SYS(sys_stat64 , 2) + MIPS_SYS(sys_lstat64 , 2) + MIPS_SYS(sys_fstat64 , 2) /* 4215 */ + MIPS_SYS(sys_pivot_root , 2) + MIPS_SYS(sys_mincore , 3) + MIPS_SYS(sys_madvise , 3) + MIPS_SYS(sys_getdents64 , 3) + MIPS_SYS(sys_fcntl64 , 3) /* 4220 */ + MIPS_SYS(sys_ni_syscall , 0) + MIPS_SYS(sys_gettid , 0) + MIPS_SYS(sys_readahead , 5) + MIPS_SYS(sys_setxattr , 5) + MIPS_SYS(sys_lsetxattr , 5) /* 4225 */ + MIPS_SYS(sys_fsetxattr , 5) + MIPS_SYS(sys_getxattr , 4) + MIPS_SYS(sys_lgetxattr , 4) + MIPS_SYS(sys_fgetxattr , 4) + MIPS_SYS(sys_listxattr , 3) /* 4230 */ + MIPS_SYS(sys_llistxattr , 3) + MIPS_SYS(sys_flistxattr , 3) + MIPS_SYS(sys_removexattr , 2) + MIPS_SYS(sys_lremovexattr, 2) + MIPS_SYS(sys_fremovexattr, 2) /* 4235 */ + MIPS_SYS(sys_tkill , 2) + MIPS_SYS(sys_sendfile64 , 5) + MIPS_SYS(sys_futex , 6) + MIPS_SYS(sys_sched_setaffinity, 3) + MIPS_SYS(sys_sched_getaffinity, 3) /* 4240 */ + MIPS_SYS(sys_io_setup , 2) + MIPS_SYS(sys_io_destroy , 1) + MIPS_SYS(sys_io_getevents, 5) + MIPS_SYS(sys_io_submit , 3) + MIPS_SYS(sys_io_cancel , 3) /* 4245 */ + MIPS_SYS(sys_exit_group , 1) + MIPS_SYS(sys_lookup_dcookie, 3) + MIPS_SYS(sys_epoll_create, 1) + MIPS_SYS(sys_epoll_ctl , 4) + MIPS_SYS(sys_epoll_wait , 3) /* 4250 */ + MIPS_SYS(sys_remap_file_pages, 5) + MIPS_SYS(sys_set_tid_address, 1) + MIPS_SYS(sys_restart_syscall, 0) + MIPS_SYS(sys_fadvise64_64, 7) + MIPS_SYS(sys_statfs64 , 3) /* 4255 */ + MIPS_SYS(sys_fstatfs64 , 2) + MIPS_SYS(sys_timer_create, 3) + MIPS_SYS(sys_timer_settime, 4) + MIPS_SYS(sys_timer_gettime, 2) + MIPS_SYS(sys_timer_getoverrun, 1) /* 4260 */ + MIPS_SYS(sys_timer_delete, 1) + MIPS_SYS(sys_clock_settime, 2) + MIPS_SYS(sys_clock_gettime, 2) + MIPS_SYS(sys_clock_getres, 2) + MIPS_SYS(sys_clock_nanosleep, 4) /* 4265 */ + MIPS_SYS(sys_tgkill , 3) + MIPS_SYS(sys_utimes , 2) + MIPS_SYS(sys_mbind , 4) + MIPS_SYS(sys_ni_syscall , 0) /* sys_get_mempolicy */ + MIPS_SYS(sys_ni_syscall , 0) /* 4270 sys_set_mempolicy */ + MIPS_SYS(sys_mq_open , 4) + MIPS_SYS(sys_mq_unlink , 1) + MIPS_SYS(sys_mq_timedsend, 5) + MIPS_SYS(sys_mq_timedreceive, 5) + MIPS_SYS(sys_mq_notify , 2) /* 4275 */ + MIPS_SYS(sys_mq_getsetattr, 3) + MIPS_SYS(sys_ni_syscall , 0) /* sys_vserver */ + MIPS_SYS(sys_waitid , 4) + MIPS_SYS(sys_ni_syscall , 0) /* available, was setaltroot */ + MIPS_SYS(sys_add_key , 5) + MIPS_SYS(sys_request_key, 4) + MIPS_SYS(sys_keyctl , 5) + MIPS_SYS(sys_set_thread_area, 1) + MIPS_SYS(sys_inotify_init, 0) + MIPS_SYS(sys_inotify_add_watch, 3) /* 4285 */ + MIPS_SYS(sys_inotify_rm_watch, 2) + MIPS_SYS(sys_migrate_pages, 4) + MIPS_SYS(sys_openat, 4) + MIPS_SYS(sys_mkdirat, 3) + MIPS_SYS(sys_mknodat, 4) /* 4290 */ + MIPS_SYS(sys_fchownat, 5) + MIPS_SYS(sys_futimesat, 3) + MIPS_SYS(sys_fstatat64, 4) + MIPS_SYS(sys_unlinkat, 3) + MIPS_SYS(sys_renameat, 4) /* 4295 */ + MIPS_SYS(sys_linkat, 5) + MIPS_SYS(sys_symlinkat, 3) + MIPS_SYS(sys_readlinkat, 4) + MIPS_SYS(sys_fchmodat, 3) + MIPS_SYS(sys_faccessat, 3) /* 4300 */ + MIPS_SYS(sys_pselect6, 6) + MIPS_SYS(sys_ppoll, 5) + MIPS_SYS(sys_unshare, 1) + MIPS_SYS(sys_splice, 6) + MIPS_SYS(sys_sync_file_range, 7) /* 4305 */ + MIPS_SYS(sys_tee, 4) + MIPS_SYS(sys_vmsplice, 4) + MIPS_SYS(sys_move_pages, 6) + MIPS_SYS(sys_set_robust_list, 2) + MIPS_SYS(sys_get_robust_list, 3) /* 4310 */ + MIPS_SYS(sys_kexec_load, 4) + MIPS_SYS(sys_getcpu, 3) + MIPS_SYS(sys_epoll_pwait, 6) + MIPS_SYS(sys_ioprio_set, 3) + MIPS_SYS(sys_ioprio_get, 2) + MIPS_SYS(sys_utimensat, 4) + MIPS_SYS(sys_signalfd, 3) + MIPS_SYS(sys_ni_syscall, 0) /* was timerfd */ + MIPS_SYS(sys_eventfd, 1) + MIPS_SYS(sys_fallocate, 6) /* 4320 */ + MIPS_SYS(sys_timerfd_create, 2) + MIPS_SYS(sys_timerfd_gettime, 2) + MIPS_SYS(sys_timerfd_settime, 4) + MIPS_SYS(sys_signalfd4, 4) + MIPS_SYS(sys_eventfd2, 2) /* 4325 */ + MIPS_SYS(sys_epoll_create1, 1) + MIPS_SYS(sys_dup3, 3) + MIPS_SYS(sys_pipe2, 2) + MIPS_SYS(sys_inotify_init1, 1) + MIPS_SYS(sys_preadv, 5) /* 4330 */ + MIPS_SYS(sys_pwritev, 5) + MIPS_SYS(sys_rt_tgsigqueueinfo, 4) + MIPS_SYS(sys_perf_event_open, 5) + MIPS_SYS(sys_accept4, 4) + MIPS_SYS(sys_recvmmsg, 5) /* 4335 */ + MIPS_SYS(sys_fanotify_init, 2) + MIPS_SYS(sys_fanotify_mark, 6) + MIPS_SYS(sys_prlimit64, 4) + MIPS_SYS(sys_name_to_handle_at, 5) + MIPS_SYS(sys_open_by_handle_at, 3) /* 4340 */ + MIPS_SYS(sys_clock_adjtime, 2) + MIPS_SYS(sys_syncfs, 1) + MIPS_SYS(sys_sendmmsg, 4) + MIPS_SYS(sys_setns, 2) + MIPS_SYS(sys_process_vm_readv, 6) /* 345 */ + MIPS_SYS(sys_process_vm_writev, 6) + MIPS_SYS(sys_kcmp, 5) + MIPS_SYS(sys_finit_module, 3) + MIPS_SYS(sys_sched_setattr, 2) + MIPS_SYS(sys_sched_getattr, 3) /* 350 */ + MIPS_SYS(sys_renameat2, 5) + MIPS_SYS(sys_seccomp, 3) + MIPS_SYS(sys_getrandom, 3) + MIPS_SYS(sys_memfd_create, 2) + MIPS_SYS(sys_bpf, 3) /* 355 */ + MIPS_SYS(sys_execveat, 5) + MIPS_SYS(sys_userfaultfd, 1) + MIPS_SYS(sys_membarrier, 2) + MIPS_SYS(sys_mlock2, 3) + MIPS_SYS(sys_copy_file_range, 6) /* 360 */ + MIPS_SYS(sys_preadv2, 6) + MIPS_SYS(sys_pwritev2, 6) +}; +# undef MIPS_SYS +# endif /* O32 */ + +static int do_store_exclusive(CPUMIPSState *env) +{ + target_ulong addr; + target_ulong page_addr; + target_ulong val; + int flags; + int segv =3D 0; + int reg; + int d; + + addr =3D env->lladdr; + page_addr =3D addr & TARGET_PAGE_MASK; + start_exclusive(); + mmap_lock(); + flags =3D page_get_flags(page_addr); + if ((flags & PAGE_READ) =3D=3D 0) { + segv =3D 1; + } else { + reg =3D env->llreg & 0x1f; + d =3D (env->llreg & 0x20) !=3D 0; + if (d) { + segv =3D get_user_s64(val, addr); + } else { + segv =3D get_user_s32(val, addr); + } + if (!segv) { + if (val !=3D env->llval) { + env->active_tc.gpr[reg] =3D 0; + } else { + if (d) { + segv =3D put_user_u64(env->llnewval, addr); + } else { + segv =3D put_user_u32(env->llnewval, addr); + } + if (!segv) { + env->active_tc.gpr[reg] =3D 1; + } + } + } + } + env->lladdr =3D -1; + if (!segv) { + env->active_tc.PC +=3D 4; + } + mmap_unlock(); + end_exclusive(); + return segv; +} + +/* Break codes */ +enum { + BRK_OVERFLOW =3D 6, + BRK_DIVZERO =3D 7 +}; + +static int do_break(CPUMIPSState *env, target_siginfo_t *info, + unsigned int code) +{ + int ret =3D -1; + + switch (code) { + case BRK_OVERFLOW: + case BRK_DIVZERO: + info->si_signo =3D TARGET_SIGFPE; + info->si_errno =3D 0; + info->si_code =3D (code =3D=3D BRK_OVERFLOW) ? FPE_INTOVF : FPE_IN= TDIV; + queue_signal(env, info->si_signo, QEMU_SI_FAULT, &*info); + ret =3D 0; + break; + default: + info->si_signo =3D TARGET_SIGTRAP; + info->si_errno =3D 0; + queue_signal(env, info->si_signo, QEMU_SI_FAULT, &*info); + ret =3D 0; + break; + } + + return ret; +} + +void cpu_loop(CPUMIPSState *env) +{ + CPUState *cs =3D CPU(mips_env_get_cpu(env)); + target_siginfo_t info; + int trapnr; + abi_long ret; +# ifdef TARGET_ABI_MIPSO32 + unsigned int syscall_num; +# endif + + for(;;) { + cpu_exec_start(cs); + trapnr =3D cpu_exec(cs); + cpu_exec_end(cs); + process_queued_cpu_work(cs); + + switch(trapnr) { + case EXCP_SYSCALL: + env->active_tc.PC +=3D 4; +# ifdef TARGET_ABI_MIPSO32 + syscall_num =3D env->active_tc.gpr[2] - 4000; + if (syscall_num >=3D sizeof(mips_syscall_args)) { + ret =3D -TARGET_ENOSYS; + } else { + int nb_args; + abi_ulong sp_reg; + abi_ulong arg5 =3D 0, arg6 =3D 0, arg7 =3D 0, arg8 =3D 0; + + nb_args =3D mips_syscall_args[syscall_num]; + sp_reg =3D env->active_tc.gpr[29]; + switch (nb_args) { + /* these arguments are taken from the stack */ + case 8: + if ((ret =3D get_user_ual(arg8, sp_reg + 28)) !=3D 0) { + goto done_syscall; + } + case 7: + if ((ret =3D get_user_ual(arg7, sp_reg + 24)) !=3D 0) { + goto done_syscall; + } + case 6: + if ((ret =3D get_user_ual(arg6, sp_reg + 20)) !=3D 0) { + goto done_syscall; + } + case 5: + if ((ret =3D get_user_ual(arg5, sp_reg + 16)) !=3D 0) { + goto done_syscall; + } + default: + break; + } + ret =3D do_syscall(env, env->active_tc.gpr[2], + env->active_tc.gpr[4], + env->active_tc.gpr[5], + env->active_tc.gpr[6], + env->active_tc.gpr[7], + arg5, arg6, arg7, arg8); + } +done_syscall: +# else + ret =3D do_syscall(env, env->active_tc.gpr[2], + env->active_tc.gpr[4], env->active_tc.gpr[5], + env->active_tc.gpr[6], env->active_tc.gpr[7], + env->active_tc.gpr[8], env->active_tc.gpr[9], + env->active_tc.gpr[10], env->active_tc.gpr[11= ]); +# endif /* O32 */ + if (ret =3D=3D -TARGET_ERESTARTSYS) { + env->active_tc.PC -=3D 4; + break; + } + if (ret =3D=3D -TARGET_QEMU_ESIGRETURN) { + /* Returning from a successful sigreturn syscall. + Avoid clobbering register state. */ + break; + } + if ((abi_ulong)ret >=3D (abi_ulong)-1133) { + env->active_tc.gpr[7] =3D 1; /* error flag */ + ret =3D -ret; + } else { + env->active_tc.gpr[7] =3D 0; /* error flag */ + } + env->active_tc.gpr[2] =3D ret; + break; + case EXCP_TLBL: + case EXCP_TLBS: + case EXCP_AdEL: + case EXCP_AdES: + info.si_signo =3D TARGET_SIGSEGV; + info.si_errno =3D 0; + /* XXX: check env->error_code */ + info.si_code =3D TARGET_SEGV_MAPERR; + info._sifields._sigfault._addr =3D env->CP0_BadVAddr; + queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + break; + case EXCP_CpU: + case EXCP_RI: + info.si_signo =3D TARGET_SIGILL; + info.si_errno =3D 0; + info.si_code =3D 0; + queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + break; + case EXCP_INTERRUPT: + /* just indicate that signals should be handled asap */ + break; + case EXCP_DEBUG: + { + int sig; + + sig =3D gdb_handlesig(cs, TARGET_SIGTRAP); + if (sig) + { + info.si_signo =3D sig; + info.si_errno =3D 0; + info.si_code =3D TARGET_TRAP_BRKPT; + queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + } + } + break; + case EXCP_SC: + if (do_store_exclusive(env)) { + info.si_signo =3D TARGET_SIGSEGV; + info.si_errno =3D 0; + info.si_code =3D TARGET_SEGV_MAPERR; + info._sifields._sigfault._addr =3D env->active_tc.PC; + queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + } + break; + case EXCP_DSPDIS: + info.si_signo =3D TARGET_SIGILL; + info.si_errno =3D 0; + info.si_code =3D TARGET_ILL_ILLOPC; + queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + break; + /* The code below was inspired by the MIPS Linux kernel trap + * handling code in arch/mips/kernel/traps.c. + */ + case EXCP_BREAK: + { + abi_ulong trap_instr; + unsigned int code; + + if (env->hflags & MIPS_HFLAG_M16) { + if (env->insn_flags & ASE_MICROMIPS) { + /* microMIPS mode */ + ret =3D get_user_u16(trap_instr, env->active_tc.PC= ); + if (ret !=3D 0) { + goto error; + } + + if ((trap_instr >> 10) =3D=3D 0x11) { + /* 16-bit instruction */ + code =3D trap_instr & 0xf; + } else { + /* 32-bit instruction */ + abi_ulong instr_lo; + + ret =3D get_user_u16(instr_lo, + env->active_tc.PC + 2); + if (ret !=3D 0) { + goto error; + } + trap_instr =3D (trap_instr << 16) | instr_lo; + code =3D ((trap_instr >> 6) & ((1 << 20) - 1)); + /* Unfortunately, microMIPS also suffers from + the old assembler bug... */ + if (code >=3D (1 << 10)) { + code >>=3D 10; + } + } + } else { + /* MIPS16e mode */ + ret =3D get_user_u16(trap_instr, env->active_tc.PC= ); + if (ret !=3D 0) { + goto error; + } + code =3D (trap_instr >> 6) & 0x3f; + } + } else { + ret =3D get_user_u32(trap_instr, env->active_tc.PC); + if (ret !=3D 0) { + goto error; + } + + /* As described in the original Linux kernel code, the + * below checks on 'code' are to work around an old + * assembly bug. + */ + code =3D ((trap_instr >> 6) & ((1 << 20) - 1)); + if (code >=3D (1 << 10)) { + code >>=3D 10; + } + } + + if (do_break(env, &info, code) !=3D 0) { + goto error; + } + } + break; + case EXCP_TRAP: + { + abi_ulong trap_instr; + unsigned int code =3D 0; + + if (env->hflags & MIPS_HFLAG_M16) { + /* microMIPS mode */ + abi_ulong instr[2]; + + ret =3D get_user_u16(instr[0], env->active_tc.PC) || + get_user_u16(instr[1], env->active_tc.PC + 2); + + trap_instr =3D (instr[0] << 16) | instr[1]; + } else { + ret =3D get_user_u32(trap_instr, env->active_tc.PC); + } + + if (ret !=3D 0) { + goto error; + } + + /* The immediate versions don't provide a code. */ + if (!(trap_instr & 0xFC000000)) { + if (env->hflags & MIPS_HFLAG_M16) { + /* microMIPS mode */ + code =3D ((trap_instr >> 12) & ((1 << 4) - 1)); + } else { + code =3D ((trap_instr >> 6) & ((1 << 10) - 1)); + } + } + + if (do_break(env, &info, code) !=3D 0) { + goto error; + } + } + break; + case EXCP_ATOMIC: + cpu_exec_step_atomic(cs); + break; + default: +error: + EXCP_DUMP(env, "qemu: unhandled CPU exception 0x%x - aborting\= n", trapnr); + abort(); + } + process_pending_signals(env); + } +} =20 void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs) { + CPUState *cpu =3D ENV_GET_CPU(env); + TaskState *ts =3D cpu->opaque; + struct image_info *info =3D ts->info; + int i; + + for(i =3D 0; i < 32; i++) { + env->active_tc.gpr[i] =3D regs->regs[i]; + } + env->active_tc.PC =3D regs->cp0_epc & ~(target_ulong)1; + if (regs->cp0_epc & 1) { + env->hflags |=3D MIPS_HFLAG_M16; + } + if (((info->elf_flags & EF_MIPS_NAN2008) !=3D 0) !=3D + ((env->active_fpu.fcr31 & (1 << FCR31_NAN2008)) !=3D 0)) { + if ((env->active_fpu.fcr31_rw_bitmask & + (1 << FCR31_NAN2008)) =3D=3D 0) { + fprintf(stderr, "ELF binary's NaN mode not supported by CPU\n"= ); + exit(1); + } + if ((info->elf_flags & EF_MIPS_NAN2008) !=3D 0) { + env->active_fpu.fcr31 |=3D (1 << FCR31_NAN2008); + } else { + env->active_fpu.fcr31 &=3D ~(1 << FCR31_NAN2008); + } + restore_snan_bit_mode(env); + } } diff --git a/linux-user/mips64/cpu_loop.c b/linux-user/mips64/cpu_loop.c index b7700a5561..858bc5be78 100644 --- a/linux-user/mips64/cpu_loop.c +++ b/linux-user/mips64/cpu_loop.c @@ -17,10 +17,4 @@ * along with this program; if not, see . */ =20 -#include "qemu/osdep.h" -#include "qemu.h" -#include "cpu_loop-common.h" - -void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs) -{ -} +#include "../mips/cpu_loop.c" --=20 2.14.3 From nobody Mon May 6 08:55:16 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1523475639507632.6570756532857; Wed, 11 Apr 2018 12:40:39 -0700 (PDT) Received: from localhost ([::1]:50170 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f6Lbi-0001Jx-Eu for importer@patchew.org; Wed, 11 Apr 2018 15:40:38 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38184) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f6KwD-0006CU-9o for qemu-devel@nongnu.org; Wed, 11 Apr 2018 14:57:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f6Kw9-0007ww-64 for qemu-devel@nongnu.org; Wed, 11 Apr 2018 14:57:45 -0400 Received: from mout.kundenserver.de ([212.227.17.10]:50769) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1f6Kw0-0007px-UM; Wed, 11 Apr 2018 14:57:33 -0400 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue105 [212.227.15.183]) with ESMTPSA (Nemesis) id 0MYePa-1f1KkT2VT0-00VOW2; Wed, 11 Apr 2018 20:57:15 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Date: Wed, 11 Apr 2018 20:56:40 +0200 Message-Id: <20180411185651.21351-9-laurent@vivier.eu> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180411185651.21351-1-laurent@vivier.eu> References: <20180411185651.21351-1-laurent@vivier.eu> X-Provags-ID: V03:K1:VOzj2YIdELOPhwlght7TvHqfeUH7N67S/WARfAsIHmnP0GN4r7s ZFzLVsBbaxnxvTncGDsl83Iq0nAVkZrTbzv2OSM9WUBLAPK4eFSP0SQ1VRrbsuZYlKnl2gc yOuNV4ZlsMZyHVnIzq5bRx5sjIueYcNEBrtleIT6Z5ewqIWMruWUJxmaMfvrUKDA96Sxhea Lj6454pN0nZM8kS1ium1A== X-UI-Out-Filterresults: notjunk:1;V01:K0:vGO3qN0RTls=:DWZ37bMwhcA5Z1tGg2SC5y 6Nhc9ypejraYmCsgLXaF/ZRbXvyt/V49mv/HLb5WhUYmIGVsNju2tLYRSyWOGcojNsaQflT3t ZWN5cU1qbq4ewDq9+qqT53RTyjlyafv188UcHjR/uLFPgfK7NHu2t0hwpB2LYCgo6r4w2IWpO IQL35V3j+FNjgUUhTqNLohakYdAwAkw3nneDCbwX1sWXY8uNpo1RCGoP9GbxU2Dg1jBSDcfI1 knIlnhRoODChqyl4u35wbE0SJiyeUJjrQslA2brGjEQgdLAEsxIg3vqHTUs4lRqhrO6+KCwJh WqBrCPKwcnVee1NbDRpV4rbWVykIPHdLSt9IaWLWTt03bvmJaoj7EDc5WjmYLxyOOaleOE8L+ b1uNOD5x7uWOJx5GW/x/BlKG51YF/0D5vxSGL3VDtQxc859s5zljIjK5a7teJ1fX92GSijdWd J6OfLcgmv4yKD2ongTneUbF+aPORFdS3Cwk0LHG1dwmuNxek8G0RNQN0ZZU4hzQ8dkwDAKifh LpgJWFYwiNkbdn0AYZuoeF4YDHobjhNmaX2RU8Lr7lh3tN2O+wxly6c6/VneNxU/W+tjviNcM Ab2dorwKJcj65vEJp6aMhObXj/5d596CaWBTl1bh2MBBOTIe+AD3FXcOjGk9Rs5kfM7vQFEIP OgyLIQ0lkQlwpGmDbtPknDKDvaBb2odK/Vox4f9Aahoiie1C9v4vFInibeuoQT0nJzokiDQ80 WXx2VHYOPcNc9LiYrwzFPKtcWJpWbx4aWwAcRg== X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 212.227.17.10 Subject: [Qemu-devel] [PATCH for 2.13 v2 08/19] linux-user: move nios2 cpu loop to nios2 directory X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Cornelia Huck , Riku Voipio , Richard Henderson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Laurent Vivier , qemu-s390x@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" No code change, only move code from main.c to nios2/cpu_loop.c. Signed-off-by: Laurent Vivier Reviewed-by: Richard Henderson --- linux-user/main.c | 133 ----------------------------------------= ---- linux-user/nios2/cpu_loop.c | 126 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 126 insertions(+), 133 deletions(-) diff --git a/linux-user/main.c b/linux-user/main.c index a760c19379..88f807549f 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -149,109 +149,6 @@ void fork_end(int child) } } =20 -#ifdef TARGET_NIOS2 - -void cpu_loop(CPUNios2State *env) -{ - CPUState *cs =3D ENV_GET_CPU(env); - Nios2CPU *cpu =3D NIOS2_CPU(cs); - target_siginfo_t info; - int trapnr, gdbsig, ret; - - for (;;) { - cpu_exec_start(cs); - trapnr =3D cpu_exec(cs); - cpu_exec_end(cs); - gdbsig =3D 0; - - switch (trapnr) { - case EXCP_INTERRUPT: - /* just indicate that signals should be handled asap */ - break; - case EXCP_TRAP: - if (env->regs[R_AT] =3D=3D 0) { - abi_long ret; - qemu_log_mask(CPU_LOG_INT, "\nSyscall\n"); - - ret =3D do_syscall(env, env->regs[2], - env->regs[4], env->regs[5], env->regs[6], - env->regs[7], env->regs[8], env->regs[9], - 0, 0); - - if (env->regs[2] =3D=3D 0) { /* FIXME: syscall 0 workar= ound */ - ret =3D 0; - } - - env->regs[2] =3D abs(ret); - /* Return value is 0..4096 */ - env->regs[7] =3D (ret > 0xfffffffffffff000ULL); - env->regs[CR_ESTATUS] =3D env->regs[CR_STATUS]; - env->regs[CR_STATUS] &=3D ~0x3; - env->regs[R_EA] =3D env->regs[R_PC] + 4; - env->regs[R_PC] +=3D 4; - break; - } else { - qemu_log_mask(CPU_LOG_INT, "\nTrap\n"); - - env->regs[CR_ESTATUS] =3D env->regs[CR_STATUS]; - env->regs[CR_STATUS] &=3D ~0x3; - env->regs[R_EA] =3D env->regs[R_PC] + 4; - env->regs[R_PC] =3D cpu->exception_addr; - - gdbsig =3D TARGET_SIGTRAP; - break; - } - case 0xaa: - switch (env->regs[R_PC]) { - /*case 0x1000:*/ /* TODO:__kuser_helper_version */ - case 0x1004: /* __kuser_cmpxchg */ - start_exclusive(); - if (env->regs[4] & 0x3) { - goto kuser_fail; - } - ret =3D get_user_u32(env->regs[2], env->regs[4]); - if (ret) { - end_exclusive(); - goto kuser_fail; - } - env->regs[2] -=3D env->regs[5]; - if (env->regs[2] =3D=3D 0) { - put_user_u32(env->regs[6], env->regs[4]); - } - end_exclusive(); - env->regs[R_PC] =3D env->regs[R_RA]; - break; - /*case 0x1040:*/ /* TODO:__kuser_sigtramp */ - default: - ; -kuser_fail: - info.si_signo =3D TARGET_SIGSEGV; - info.si_errno =3D 0; - /* TODO: check env->error_code */ - info.si_code =3D TARGET_SEGV_MAPERR; - info._sifields._sigfault._addr =3D env->regs[R_PC]; - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); - } - break; - default: - EXCP_DUMP(env, "\nqemu: unhandled CPU exception %#x - aborting= \n", - trapnr); - gdbsig =3D TARGET_SIGILL; - break; - } - if (gdbsig) { - gdb_handlesig(cs, gdbsig); - if (gdbsig !=3D TARGET_SIGTRAP) { - exit(EXIT_FAILURE); - } - } - - process_pending_signals(env); - } -} - -#endif /* TARGET_NIOS2 */ - #ifdef TARGET_OPENRISC =20 void cpu_loop(CPUOpenRISCState *env) @@ -2545,36 +2442,6 @@ int main(int argc, char **argv, char **envp) env->regs[31] =3D regs->r31; =20 env->sregs[SR_PC] =3D regs->pc; } -#elif defined(TARGET_NIOS2) - { - env->regs[0] =3D 0; - env->regs[1] =3D regs->r1; - env->regs[2] =3D regs->r2; - env->regs[3] =3D regs->r3; - env->regs[4] =3D regs->r4; - env->regs[5] =3D regs->r5; - env->regs[6] =3D regs->r6; - env->regs[7] =3D regs->r7; - env->regs[8] =3D regs->r8; - env->regs[9] =3D regs->r9; - env->regs[10] =3D regs->r10; - env->regs[11] =3D regs->r11; - env->regs[12] =3D regs->r12; - env->regs[13] =3D regs->r13; - env->regs[14] =3D regs->r14; - env->regs[15] =3D regs->r15; - /* TODO: unsigned long orig_r2; */ - env->regs[R_RA] =3D regs->ra; - env->regs[R_FP] =3D regs->fp; - env->regs[R_SP] =3D regs->sp; - env->regs[R_GP] =3D regs->gp; - env->regs[CR_ESTATUS] =3D regs->estatus; - env->regs[R_EA] =3D regs->ea; - /* TODO: unsigned long orig_r7; */ - - /* Emulate eret when starting thread. */ - env->regs[R_PC] =3D regs->ea; - } #elif defined(TARGET_OPENRISC) { int i; diff --git a/linux-user/nios2/cpu_loop.c b/linux-user/nios2/cpu_loop.c index b7700a5561..dac7a06181 100644 --- a/linux-user/nios2/cpu_loop.c +++ b/linux-user/nios2/cpu_loop.c @@ -21,6 +21,132 @@ #include "qemu.h" #include "cpu_loop-common.h" =20 +void cpu_loop(CPUNios2State *env) +{ + CPUState *cs =3D ENV_GET_CPU(env); + Nios2CPU *cpu =3D NIOS2_CPU(cs); + target_siginfo_t info; + int trapnr, gdbsig, ret; + + for (;;) { + cpu_exec_start(cs); + trapnr =3D cpu_exec(cs); + cpu_exec_end(cs); + gdbsig =3D 0; + + switch (trapnr) { + case EXCP_INTERRUPT: + /* just indicate that signals should be handled asap */ + break; + case EXCP_TRAP: + if (env->regs[R_AT] =3D=3D 0) { + abi_long ret; + qemu_log_mask(CPU_LOG_INT, "\nSyscall\n"); + + ret =3D do_syscall(env, env->regs[2], + env->regs[4], env->regs[5], env->regs[6], + env->regs[7], env->regs[8], env->regs[9], + 0, 0); + + if (env->regs[2] =3D=3D 0) { /* FIXME: syscall 0 workar= ound */ + ret =3D 0; + } + + env->regs[2] =3D abs(ret); + /* Return value is 0..4096 */ + env->regs[7] =3D (ret > 0xfffffffffffff000ULL); + env->regs[CR_ESTATUS] =3D env->regs[CR_STATUS]; + env->regs[CR_STATUS] &=3D ~0x3; + env->regs[R_EA] =3D env->regs[R_PC] + 4; + env->regs[R_PC] +=3D 4; + break; + } else { + qemu_log_mask(CPU_LOG_INT, "\nTrap\n"); + + env->regs[CR_ESTATUS] =3D env->regs[CR_STATUS]; + env->regs[CR_STATUS] &=3D ~0x3; + env->regs[R_EA] =3D env->regs[R_PC] + 4; + env->regs[R_PC] =3D cpu->exception_addr; + + gdbsig =3D TARGET_SIGTRAP; + break; + } + case 0xaa: + switch (env->regs[R_PC]) { + /*case 0x1000:*/ /* TODO:__kuser_helper_version */ + case 0x1004: /* __kuser_cmpxchg */ + start_exclusive(); + if (env->regs[4] & 0x3) { + goto kuser_fail; + } + ret =3D get_user_u32(env->regs[2], env->regs[4]); + if (ret) { + end_exclusive(); + goto kuser_fail; + } + env->regs[2] -=3D env->regs[5]; + if (env->regs[2] =3D=3D 0) { + put_user_u32(env->regs[6], env->regs[4]); + } + end_exclusive(); + env->regs[R_PC] =3D env->regs[R_RA]; + break; + /*case 0x1040:*/ /* TODO:__kuser_sigtramp */ + default: + ; +kuser_fail: + info.si_signo =3D TARGET_SIGSEGV; + info.si_errno =3D 0; + /* TODO: check env->error_code */ + info.si_code =3D TARGET_SEGV_MAPERR; + info._sifields._sigfault._addr =3D env->regs[R_PC]; + queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + } + break; + default: + EXCP_DUMP(env, "\nqemu: unhandled CPU exception %#x - aborting= \n", + trapnr); + gdbsig =3D TARGET_SIGILL; + break; + } + if (gdbsig) { + gdb_handlesig(cs, gdbsig); + if (gdbsig !=3D TARGET_SIGTRAP) { + exit(EXIT_FAILURE); + } + } + + process_pending_signals(env); + } +} + void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs) { + env->regs[0] =3D 0; + env->regs[1] =3D regs->r1; + env->regs[2] =3D regs->r2; + env->regs[3] =3D regs->r3; + env->regs[4] =3D regs->r4; + env->regs[5] =3D regs->r5; + env->regs[6] =3D regs->r6; + env->regs[7] =3D regs->r7; + env->regs[8] =3D regs->r8; + env->regs[9] =3D regs->r9; + env->regs[10] =3D regs->r10; + env->regs[11] =3D regs->r11; + env->regs[12] =3D regs->r12; + env->regs[13] =3D regs->r13; + env->regs[14] =3D regs->r14; + env->regs[15] =3D regs->r15; + /* TODO: unsigned long orig_r2; */ + env->regs[R_RA] =3D regs->ra; + env->regs[R_FP] =3D regs->fp; + env->regs[R_SP] =3D regs->sp; + env->regs[R_GP] =3D regs->gp; + env->regs[CR_ESTATUS] =3D regs->estatus; + env->regs[R_EA] =3D regs->ea; + /* TODO: unsigned long orig_r7; */ + + /* Emulate eret when starting thread. */ + env->regs[R_PC] =3D regs->ea; } --=20 2.14.3 From nobody Mon May 6 08:55:16 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1523474657956216.90396915580004; Wed, 11 Apr 2018 12:24:17 -0700 (PDT) Received: from localhost ([::1]:49111 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f6LLq-0003wE-WD for importer@patchew.org; Wed, 11 Apr 2018 15:24:15 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37956) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f6Kw2-00061t-Ao for qemu-devel@nongnu.org; Wed, 11 Apr 2018 14:57:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f6Kw0-0007qG-O5 for qemu-devel@nongnu.org; Wed, 11 Apr 2018 14:57:34 -0400 Received: from mout.kundenserver.de ([217.72.192.74]:42339) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1f6Kw0-0007pY-EX; Wed, 11 Apr 2018 14:57:32 -0400 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue105 [212.227.15.183]) with ESMTPSA (Nemesis) id 0MEnBC-1fGnCQ1yx8-00G3WM; Wed, 11 Apr 2018 20:57:16 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Date: Wed, 11 Apr 2018 20:56:41 +0200 Message-Id: <20180411185651.21351-10-laurent@vivier.eu> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180411185651.21351-1-laurent@vivier.eu> References: <20180411185651.21351-1-laurent@vivier.eu> X-Provags-ID: V03:K1:fIx3Vlil/5Cexy5juhTusbFmhZ4xmWTXucLPPq5eDQ4g7WihQ/v vs5sJjvEpW05R4z6SKtDzjbtcShWwTL392sY7lUKAni+awYlj0rT816Bxc/2MnF5Kn5X5kW zWTOAqe3mZmnDe+vSOwjKSA29O900CxDB7uTKWCYJbnUErfjIModBc5iF40ZjP7TnwjfJAU /vWKAkPxL18iIeYFiYN0g== X-UI-Out-Filterresults: notjunk:1;V01:K0:M/brnzRr8B4=:ygnW0pszOheIzx+63JvtEh g0+uMB/jfINHRzbJ9xaciyN4OgwufX2oPrgAq/SLl6kI+LX2nU6LVet5CY0PxIreEi2U2T5YU Zfw9680ggr4t8jVyzm3DJlLvy+jEU9ugJ4u4FssZiXnqtL+J7CdtCGmexnPsySlJwVvWopGgI kP9MHo2t/UqOVd45juxw5wT6UMJ2PiUdi6QPLbBJDYtQH9/KZ9e2SSAUdCFIJYrjNhHAAq20U aMxgewkwJTVAEw4wlh3rV+WHrYqo/orrJHCKW1IZTLsB61mrn9VKX4p7eEY8qC/EHp3f9GCEz FGfzorsEA5NmWiFxWdQxBbSlqGy7jnqWyOLPBHhpLe5KQqiPMYMiwQjbN2r+Q/e1UVkMZPki5 aO5Fc8vP+1VBYknkTNCQ02u28gmNPjZkO8ZbeoL/aQEB64mmI5e9OpiwMpZ0Vn7j+ZQxRbuoq KPL07H5b+HWLkF73qS/Whu14Zj155rg5E+dcAOGoshwtCiGYtIjqRi6qyB+QSlQGR2YjSQeax ppfKB9zSO9hZm3FPeR12BpTCqBA4NwqJLA3PrHM3nUG5czEWYuVqaqb+Z1mO+A9qwpb5LTEbB +v8rTySkBtmJ4riBG4Lt0T5JVKO0hRlu5gMEwhW01ML6AQ3b0Dig1j/mPTitugwVeRuBD8Ah4 Hg7iCTl1gtjbl3igeegn2gTvr7JdBGlN0AIwiYbLqAZO6qyTK1xv8Kk6NOhMObE95OPetJ4m0 FErJ00V8+r2yQs9LfeZuIklyI0nsjipsOOnszg== X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 217.72.192.74 Subject: [Qemu-devel] [PATCH for 2.13 v2 09/19] linux-user: move openrisc cpu loop to openrisc directory X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Cornelia Huck , Riku Voipio , Richard Henderson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Laurent Vivier , qemu-s390x@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" No code change, only move code from main.c to openrisc/cpu_loop.c. Signed-off-by: Laurent Vivier Reviewed-by: Richard Henderson --- linux-user/main.c | 96 --------------------------------------= ---- linux-user/openrisc/cpu_loop.c | 89 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+), 96 deletions(-) diff --git a/linux-user/main.c b/linux-user/main.c index 88f807549f..af26a17c46 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -149,92 +149,6 @@ void fork_end(int child) } } =20 -#ifdef TARGET_OPENRISC - -void cpu_loop(CPUOpenRISCState *env) -{ - CPUState *cs =3D CPU(openrisc_env_get_cpu(env)); - int trapnr; - abi_long ret; - target_siginfo_t info; - - for (;;) { - cpu_exec_start(cs); - trapnr =3D cpu_exec(cs); - cpu_exec_end(cs); - process_queued_cpu_work(cs); - - switch (trapnr) { - case EXCP_SYSCALL: - env->pc +=3D 4; /* 0xc00; */ - ret =3D do_syscall(env, - cpu_get_gpr(env, 11), /* return value */ - cpu_get_gpr(env, 3), /* r3 - r7 are params */ - cpu_get_gpr(env, 4), - cpu_get_gpr(env, 5), - cpu_get_gpr(env, 6), - cpu_get_gpr(env, 7), - cpu_get_gpr(env, 8), 0, 0); - if (ret =3D=3D -TARGET_ERESTARTSYS) { - env->pc -=3D 4; - } else if (ret !=3D -TARGET_QEMU_ESIGRETURN) { - cpu_set_gpr(env, 11, ret); - } - break; - case EXCP_DPF: - case EXCP_IPF: - case EXCP_RANGE: - info.si_signo =3D TARGET_SIGSEGV; - info.si_errno =3D 0; - info.si_code =3D TARGET_SEGV_MAPERR; - info._sifields._sigfault._addr =3D env->pc; - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); - break; - case EXCP_ALIGN: - info.si_signo =3D TARGET_SIGBUS; - info.si_errno =3D 0; - info.si_code =3D TARGET_BUS_ADRALN; - info._sifields._sigfault._addr =3D env->pc; - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); - break; - case EXCP_ILLEGAL: - info.si_signo =3D TARGET_SIGILL; - info.si_errno =3D 0; - info.si_code =3D TARGET_ILL_ILLOPC; - info._sifields._sigfault._addr =3D env->pc; - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); - break; - case EXCP_FPE: - info.si_signo =3D TARGET_SIGFPE; - info.si_errno =3D 0; - info.si_code =3D 0; - info._sifields._sigfault._addr =3D env->pc; - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); - break; - case EXCP_INTERRUPT: - /* We processed the pending cpu work above. */ - break; - case EXCP_DEBUG: - trapnr =3D gdb_handlesig(cs, TARGET_SIGTRAP); - if (trapnr) { - info.si_signo =3D trapnr; - info.si_errno =3D 0; - info.si_code =3D TARGET_TRAP_BRKPT; - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); - } - break; - case EXCP_ATOMIC: - cpu_exec_step_atomic(cs); - break; - default: - g_assert_not_reached(); - } - process_pending_signals(env); - } -} - -#endif /* TARGET_OPENRISC */ - #ifdef TARGET_SH4 void cpu_loop(CPUSH4State *env) { @@ -2442,16 +2356,6 @@ int main(int argc, char **argv, char **envp) env->regs[31] =3D regs->r31; =20 env->sregs[SR_PC] =3D regs->pc; } -#elif defined(TARGET_OPENRISC) - { - int i; - - for (i =3D 0; i < 32; i++) { - cpu_set_gpr(env, i, regs->gpr[i]); - } - env->pc =3D regs->pc; - cpu_set_sr(env, regs->sr); - } #elif defined(TARGET_RISCV) { env->pc =3D regs->sepc; diff --git a/linux-user/openrisc/cpu_loop.c b/linux-user/openrisc/cpu_loop.c index b7700a5561..6c6ea871e1 100644 --- a/linux-user/openrisc/cpu_loop.c +++ b/linux-user/openrisc/cpu_loop.c @@ -21,6 +21,95 @@ #include "qemu.h" #include "cpu_loop-common.h" =20 +void cpu_loop(CPUOpenRISCState *env) +{ + CPUState *cs =3D CPU(openrisc_env_get_cpu(env)); + int trapnr; + abi_long ret; + target_siginfo_t info; + + for (;;) { + cpu_exec_start(cs); + trapnr =3D cpu_exec(cs); + cpu_exec_end(cs); + process_queued_cpu_work(cs); + + switch (trapnr) { + case EXCP_SYSCALL: + env->pc +=3D 4; /* 0xc00; */ + ret =3D do_syscall(env, + cpu_get_gpr(env, 11), /* return value */ + cpu_get_gpr(env, 3), /* r3 - r7 are params */ + cpu_get_gpr(env, 4), + cpu_get_gpr(env, 5), + cpu_get_gpr(env, 6), + cpu_get_gpr(env, 7), + cpu_get_gpr(env, 8), 0, 0); + if (ret =3D=3D -TARGET_ERESTARTSYS) { + env->pc -=3D 4; + } else if (ret !=3D -TARGET_QEMU_ESIGRETURN) { + cpu_set_gpr(env, 11, ret); + } + break; + case EXCP_DPF: + case EXCP_IPF: + case EXCP_RANGE: + info.si_signo =3D TARGET_SIGSEGV; + info.si_errno =3D 0; + info.si_code =3D TARGET_SEGV_MAPERR; + info._sifields._sigfault._addr =3D env->pc; + queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + break; + case EXCP_ALIGN: + info.si_signo =3D TARGET_SIGBUS; + info.si_errno =3D 0; + info.si_code =3D TARGET_BUS_ADRALN; + info._sifields._sigfault._addr =3D env->pc; + queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + break; + case EXCP_ILLEGAL: + info.si_signo =3D TARGET_SIGILL; + info.si_errno =3D 0; + info.si_code =3D TARGET_ILL_ILLOPC; + info._sifields._sigfault._addr =3D env->pc; + queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + break; + case EXCP_FPE: + info.si_signo =3D TARGET_SIGFPE; + info.si_errno =3D 0; + info.si_code =3D 0; + info._sifields._sigfault._addr =3D env->pc; + queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + break; + case EXCP_INTERRUPT: + /* We processed the pending cpu work above. */ + break; + case EXCP_DEBUG: + trapnr =3D gdb_handlesig(cs, TARGET_SIGTRAP); + if (trapnr) { + info.si_signo =3D trapnr; + info.si_errno =3D 0; + info.si_code =3D TARGET_TRAP_BRKPT; + queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + } + break; + case EXCP_ATOMIC: + cpu_exec_step_atomic(cs); + break; + default: + g_assert_not_reached(); + } + process_pending_signals(env); + } +} + void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs) { + int i; + + for (i =3D 0; i < 32; i++) { + cpu_set_gpr(env, i, regs->gpr[i]); + } + env->pc =3D regs->pc; + cpu_set_sr(env, regs->sr); } --=20 2.14.3 From nobody Mon May 6 08:55:16 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1523474855980796.4064381379804; Wed, 11 Apr 2018 12:27:35 -0700 (PDT) Received: from localhost ([::1]:49258 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f6LOw-0006kb-VV for importer@patchew.org; Wed, 11 Apr 2018 15:27:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38016) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f6Kw5-00064s-AQ for qemu-devel@nongnu.org; Wed, 11 Apr 2018 14:57:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f6Kw1-0007qq-GR for qemu-devel@nongnu.org; Wed, 11 Apr 2018 14:57:37 -0400 Received: from mout.kundenserver.de ([217.72.192.73]:44925) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1f6Kw1-0007pz-5q; Wed, 11 Apr 2018 14:57:33 -0400 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue105 [212.227.15.183]) with ESMTPSA (Nemesis) id 0LqU2T-1ebvzw1J1F-00e5vd; Wed, 11 Apr 2018 20:57:17 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Date: Wed, 11 Apr 2018 20:56:42 +0200 Message-Id: <20180411185651.21351-11-laurent@vivier.eu> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180411185651.21351-1-laurent@vivier.eu> References: <20180411185651.21351-1-laurent@vivier.eu> X-Provags-ID: V03:K1:pCUYlM3sHg/Y69zXS2PBjRm9QP6J18YRPI5mZnY3D47NTm8y/dW SMp/laVZTkC7LhawlTdVZ+K4xY4YW0gOVgqljD4ZPigP49PuBqY60b25t7RhgE7xh/jkd12 TMuNCj/5WC4s1v802X8P1wVdDUFPVOUoBfoQ3A9HIZiJFox1qgtmrkoWlw5gVmGzU4MB35H 8ph7NLiwi5syxlYdq5lMA== X-UI-Out-Filterresults: notjunk:1;V01:K0:VGA5rC7EVlk=:NssLh5KwsHnA2uRkt2NKd3 XbNDka3ardyaqg/8ynAh1O5Ke4Gmzin0TuC/e2ayqrbAKO6bJPDO0Mc3K6FkvXoECW8EiejAf L9lvzUkE0VHXc3K6hyzlPsVphy1pcfxr+6I/JGjaJUqFca2r/2MCUSCFFqnDqlmqSY67m3U1r 8Ra+vyLg/NjUvkdsydXzCFMJdvdRGgv4qU1wFJWLCzyRO1Q7Edzt7Ovsj2QIWV4wXoaBHoCz6 IgOJQ4fXnzV6srFw/gq3LWvphCzVzyccvY6TkeRA8/08Apw/ia1sMiw4cbU0UBl6+mI26+Ivf 7YqDguaK4I4mqA8ssSYJ+R7OcJcxY7PpoLyCRIyAsHoENrBT7H/uedjqyU8754Mc1i1PJj5Ep Zgt1mgnPiGN1KD6A5rwwdOl1VJL6jpiJWj8dGZNYRMqIRz/ATYTkEI5AAQTu2eHS7OjNb2m4D CYrdbwxjmNWPjUlpp0GE2dZve+9faZOJ4Mc+u5QWVsFlbTS8kTH9cY8NEdoqwLsXPc4hAoFCS ILWHjW1Tnqhq2TXaZO+HIU1cOHTfrCtlJiDI4Y0ZLfNe+Ax4N8Q5ezPj3eDWrVCQPutLWSfEb 0+JEfcRIIHIW+mOBXhSI3N/obPNKkBPhitOFnn52ZbOyF8ru/6HW17Aki3pSQ2LFKXr9Y6ADA 34Sdm1h/b87m4HIyQiTj3Bb/E54c4BJUbTtqDV5bYm2K0wdu6XHZPU+Vdqf9PFDdkgnJOp2UB xSJVt/quwFlbSmFWv3wJMCFJH3SmwWLXZuGgIQ== X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 217.72.192.73 Subject: [Qemu-devel] [PATCH for 2.13 v2 10/19] linux-user: move sh4 cpu loop to sh4 directory X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Cornelia Huck , Riku Voipio , Richard Henderson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Laurent Vivier , qemu-s390x@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" No code change, only move code from main.c to sh4/cpu_loop.c. Signed-off-by: Laurent Vivier Reviewed-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- Notes: v2: expand tabs linux-user/main.c | 90 -------------------------------------------= ---- linux-user/sh4/cpu_loop.c | 85 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+), 90 deletions(-) diff --git a/linux-user/main.c b/linux-user/main.c index af26a17c46..d7fee3e3db 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -149,87 +149,6 @@ void fork_end(int child) } } =20 -#ifdef TARGET_SH4 -void cpu_loop(CPUSH4State *env) -{ - CPUState *cs =3D CPU(sh_env_get_cpu(env)); - int trapnr, ret; - target_siginfo_t info; - - while (1) { - bool arch_interrupt =3D true; - - cpu_exec_start(cs); - trapnr =3D cpu_exec(cs); - cpu_exec_end(cs); - process_queued_cpu_work(cs); - - switch (trapnr) { - case 0x160: - env->pc +=3D 2; - ret =3D do_syscall(env, - env->gregs[3], - env->gregs[4], - env->gregs[5], - env->gregs[6], - env->gregs[7], - env->gregs[0], - env->gregs[1], - 0, 0); - if (ret =3D=3D -TARGET_ERESTARTSYS) { - env->pc -=3D 2; - } else if (ret !=3D -TARGET_QEMU_ESIGRETURN) { - env->gregs[0] =3D ret; - } - break; - case EXCP_INTERRUPT: - /* just indicate that signals should be handled asap */ - break; - case EXCP_DEBUG: - { - int sig; - - sig =3D gdb_handlesig(cs, TARGET_SIGTRAP); - if (sig) { - info.si_signo =3D sig; - info.si_errno =3D 0; - info.si_code =3D TARGET_TRAP_BRKPT; - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); - } else { - arch_interrupt =3D false; - } - } - break; - case 0xa0: - case 0xc0: - info.si_signo =3D TARGET_SIGSEGV; - info.si_errno =3D 0; - info.si_code =3D TARGET_SEGV_MAPERR; - info._sifields._sigfault._addr =3D env->tea; - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); - break; - case EXCP_ATOMIC: - cpu_exec_step_atomic(cs); - arch_interrupt =3D false; - break; - default: - printf ("Unhandled trap: 0x%x\n", trapnr); - cpu_dump_state(cs, stderr, fprintf, 0); - exit(EXIT_FAILURE); - } - process_pending_signals (env); - - /* Most of the traps imply an exception or interrupt, which - implies an REI instruction has been executed. Which means - that LDST (aka LOK_ADDR) should be cleared. But there are - a few exceptions for traps internal to QEMU. */ - if (arch_interrupt) { - env->lock_addr =3D -1; - } - } -} -#endif - #ifdef TARGET_CRIS void cpu_loop(CPUCRISState *env) { @@ -2361,15 +2280,6 @@ int main(int argc, char **argv, char **envp) env->pc =3D regs->sepc; env->gpr[xSP] =3D regs->sp; } -#elif defined(TARGET_SH4) - { - int i; - - for(i =3D 0; i < 16; i++) { - env->gregs[i] =3D regs->regs[i]; - } - env->pc =3D regs->pc; - } #elif defined(TARGET_ALPHA) { int i; diff --git a/linux-user/sh4/cpu_loop.c b/linux-user/sh4/cpu_loop.c index b7700a5561..418833ea25 100644 --- a/linux-user/sh4/cpu_loop.c +++ b/linux-user/sh4/cpu_loop.c @@ -21,6 +21,91 @@ #include "qemu.h" #include "cpu_loop-common.h" =20 +void cpu_loop(CPUSH4State *env) +{ + CPUState *cs =3D CPU(sh_env_get_cpu(env)); + int trapnr, ret; + target_siginfo_t info; + + while (1) { + bool arch_interrupt =3D true; + + cpu_exec_start(cs); + trapnr =3D cpu_exec(cs); + cpu_exec_end(cs); + process_queued_cpu_work(cs); + + switch (trapnr) { + case 0x160: + env->pc +=3D 2; + ret =3D do_syscall(env, + env->gregs[3], + env->gregs[4], + env->gregs[5], + env->gregs[6], + env->gregs[7], + env->gregs[0], + env->gregs[1], + 0, 0); + if (ret =3D=3D -TARGET_ERESTARTSYS) { + env->pc -=3D 2; + } else if (ret !=3D -TARGET_QEMU_ESIGRETURN) { + env->gregs[0] =3D ret; + } + break; + case EXCP_INTERRUPT: + /* just indicate that signals should be handled asap */ + break; + case EXCP_DEBUG: + { + int sig; + + sig =3D gdb_handlesig(cs, TARGET_SIGTRAP); + if (sig) { + info.si_signo =3D sig; + info.si_errno =3D 0; + info.si_code =3D TARGET_TRAP_BRKPT; + queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + } else { + arch_interrupt =3D false; + } + } + break; + case 0xa0: + case 0xc0: + info.si_signo =3D TARGET_SIGSEGV; + info.si_errno =3D 0; + info.si_code =3D TARGET_SEGV_MAPERR; + info._sifields._sigfault._addr =3D env->tea; + queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + break; + case EXCP_ATOMIC: + cpu_exec_step_atomic(cs); + arch_interrupt =3D false; + break; + default: + printf ("Unhandled trap: 0x%x\n", trapnr); + cpu_dump_state(cs, stderr, fprintf, 0); + exit(EXIT_FAILURE); + } + process_pending_signals (env); + + /* Most of the traps imply an exception or interrupt, which + implies an REI instruction has been executed. Which means + that LDST (aka LOK_ADDR) should be cleared. But there are + a few exceptions for traps internal to QEMU. */ + if (arch_interrupt) { + env->lock_addr =3D -1; + } + } +} + void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs) { + int i; + + for(i =3D 0; i < 16; i++) { + env->gregs[i] =3D regs->regs[i]; + } + env->pc =3D regs->pc; } --=20 2.14.3 From nobody Mon May 6 08:55:16 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1523475477203772.3782662678609; Wed, 11 Apr 2018 12:37:57 -0700 (PDT) Received: from localhost ([::1]:50056 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f6LZ6-0007P9-BR for importer@patchew.org; Wed, 11 Apr 2018 15:37:56 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38053) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f6Kw8-00066f-NB for qemu-devel@nongnu.org; Wed, 11 Apr 2018 14:57:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f6Kw5-0007t3-Fe for qemu-devel@nongnu.org; Wed, 11 Apr 2018 14:57:39 -0400 Received: from mout.kundenserver.de ([212.227.17.10]:55401) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1f6Kvz-0007oz-BY; Wed, 11 Apr 2018 14:57:31 -0400 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue105 [212.227.15.183]) with ESMTPSA (Nemesis) id 0MINXr-1f2kxV0Vpv-004D9L; Wed, 11 Apr 2018 20:57:18 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Date: Wed, 11 Apr 2018 20:56:43 +0200 Message-Id: <20180411185651.21351-12-laurent@vivier.eu> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180411185651.21351-1-laurent@vivier.eu> References: <20180411185651.21351-1-laurent@vivier.eu> X-Provags-ID: V03:K1:hihjSc31/+33Nm9CjANxTNKN/bAIDKpfyMPWsPjYaQRufBDXRdY NUhAPl18Ph6tUCn1wuLMmDpBH+4L2+HV4VbQ3fnsaT8+plq2qmmVf7zlKQOR7FlZwF2YKej Om8TDfyEjXDEW2Vted4blN6R7mH3wEgbWHnL6+ByO9VWgY17/hcLfvcWYxantxusbW+QjbP PJxAoOHykgLXa4o0EJsGg== X-UI-Out-Filterresults: notjunk:1;V01:K0:KRAIthwPe7s=:GUUiHRXWx3rGbYW/2of4D7 ROzLnMtz7wrsR/dVVNJOxjNFGpNCkw9c8iE2PLB7OrWAzDGxczs13O3Z2yK+d0r9KgLNXr00T bK1/RVxs+5oqXDyvAV5/nHpWNnKL7zEqIfIyipey50Ke7CuTevQa7NTGb0+mWEI3neUN9PWoH y9OF4H2/OETCT4EifXygsRHyUKLtC1WtFQQ0RQ9oBT3Fa2nCULlJRoaMnzTX1oJaCYvhywQ8n INCWcXiQDjiqTjlC+oRZ8lUbwxK6oMLjHrh6BeJaaw7cBgQqXhRpC5nUdC1/Nq7GNAFG+l0xF jZ9AvPRLhGr8BPBZkjqr20U7KD19Qi7xBJGtBmvlOgYe86xq/MegSEozLk4LnzaZTKX3RhBH4 XV2t8qJhZsBcYGlCkjEAiKKIhzXyFWeyUyoqeZnqD94WCwZs9RMmfa0V9CroiZKzsaXEvSwEb e/6Wyz2DxBiz/y6QWewlcVcsP+Ikg8LQGPNsENRiqBMRL5e204/jKsZry+Xm6Gkwau0HMpW12 HzFIiaLIE7c1EKXSVrE7bQtidH8jRrw06/qDxzLvyf5yug5rcUJ4b6+7C11lQKqzhVhAZRUeq hj39r01rfU9Te7dYszeLzsGlGeNOEKaJp8T/77xYfBlmzHhRh2ei0x92zKL9kUx4h6nCsqdfp MRxu821DihU6rv8qtyB81SbHrU+Nz3+aCOpQWOr7SJ3+ADoLekN7TIwqiqupPD3gr2JlnCR2R +db4t8d2TmBCFMX/JALkx6Owb3FXZ276vhssAg== X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 212.227.17.10 Subject: [Qemu-devel] [PATCH for 2.13 v2 11/19] linux-user: move cris cpu loop to cris directory X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Cornelia Huck , Riku Voipio , Richard Henderson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Laurent Vivier , qemu-s390x@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" No code change, only move code from main.c to cris/cpu_loop.c. Signed-off-by: Laurent Vivier Reviewed-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- Notes: v2: expand tabs linux-user/cris/cpu_loop.c | 89 ++++++++++++++++++++++++++++++++++++++++++= +++ linux-user/main.c | 90 ------------------------------------------= ---- 2 files changed, 89 insertions(+), 90 deletions(-) diff --git a/linux-user/cris/cpu_loop.c b/linux-user/cris/cpu_loop.c index b7700a5561..1c5eca9f83 100644 --- a/linux-user/cris/cpu_loop.c +++ b/linux-user/cris/cpu_loop.c @@ -21,6 +21,95 @@ #include "qemu.h" #include "cpu_loop-common.h" =20 +void cpu_loop(CPUCRISState *env) +{ + CPUState *cs =3D CPU(cris_env_get_cpu(env)); + int trapnr, ret; + target_siginfo_t info; + =20 + while (1) { + cpu_exec_start(cs); + trapnr =3D cpu_exec(cs); + cpu_exec_end(cs); + process_queued_cpu_work(cs); + + switch (trapnr) { + case 0xaa: + { + info.si_signo =3D TARGET_SIGSEGV; + info.si_errno =3D 0; + /* XXX: check env->error_code */ + info.si_code =3D TARGET_SEGV_MAPERR; + info._sifields._sigfault._addr =3D env->pregs[PR_EDA]; + queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + } + break; + case EXCP_INTERRUPT: + /* just indicate that signals should be handled asap */ + break; + case EXCP_BREAK: + ret =3D do_syscall(env,=20 + env->regs[9],=20 + env->regs[10],=20 + env->regs[11],=20 + env->regs[12],=20 + env->regs[13],=20 + env->pregs[7],=20 + env->pregs[11], + 0, 0); + if (ret =3D=3D -TARGET_ERESTARTSYS) { + env->pc -=3D 2; + } else if (ret !=3D -TARGET_QEMU_ESIGRETURN) { + env->regs[10] =3D ret; + } + break; + case EXCP_DEBUG: + { + int sig; + + sig =3D gdb_handlesig(cs, TARGET_SIGTRAP); + if (sig) + { + info.si_signo =3D sig; + info.si_errno =3D 0; + info.si_code =3D TARGET_TRAP_BRKPT; + queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + } + } + break; + case EXCP_ATOMIC: + cpu_exec_step_atomic(cs); + break; + default: + printf ("Unhandled trap: 0x%x\n", trapnr); + cpu_dump_state(cs, stderr, fprintf, 0); + exit(EXIT_FAILURE); + } + process_pending_signals (env); + } +} + void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs) { + CPUState *cpu =3D ENV_GET_CPU(env); + TaskState *ts =3D cpu->opaque; + struct image_info *info =3D ts->info; + + env->regs[0] =3D regs->r0; + env->regs[1] =3D regs->r1; + env->regs[2] =3D regs->r2; + env->regs[3] =3D regs->r3; + env->regs[4] =3D regs->r4; + env->regs[5] =3D regs->r5; + env->regs[6] =3D regs->r6; + env->regs[7] =3D regs->r7; + env->regs[8] =3D regs->r8; + env->regs[9] =3D regs->r9; + env->regs[10] =3D regs->r10; + env->regs[11] =3D regs->r11; + env->regs[12] =3D regs->r12; + env->regs[13] =3D regs->r13; + env->regs[14] =3D info->start_stack; + env->regs[15] =3D regs->acr; + env->pc =3D regs->erp; } diff --git a/linux-user/main.c b/linux-user/main.c index d7fee3e3db..9e01325d6a 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -149,76 +149,6 @@ void fork_end(int child) } } =20 -#ifdef TARGET_CRIS -void cpu_loop(CPUCRISState *env) -{ - CPUState *cs =3D CPU(cris_env_get_cpu(env)); - int trapnr, ret; - target_siginfo_t info; - =20 - while (1) { - cpu_exec_start(cs); - trapnr =3D cpu_exec(cs); - cpu_exec_end(cs); - process_queued_cpu_work(cs); - - switch (trapnr) { - case 0xaa: - { - info.si_signo =3D TARGET_SIGSEGV; - info.si_errno =3D 0; - /* XXX: check env->error_code */ - info.si_code =3D TARGET_SEGV_MAPERR; - info._sifields._sigfault._addr =3D env->pregs[PR_EDA]; - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); - } - break; - case EXCP_INTERRUPT: - /* just indicate that signals should be handled asap */ - break; - case EXCP_BREAK: - ret =3D do_syscall(env,=20 - env->regs[9],=20 - env->regs[10],=20 - env->regs[11],=20 - env->regs[12],=20 - env->regs[13],=20 - env->pregs[7],=20 - env->pregs[11], - 0, 0); - if (ret =3D=3D -TARGET_ERESTARTSYS) { - env->pc -=3D 2; - } else if (ret !=3D -TARGET_QEMU_ESIGRETURN) { - env->regs[10] =3D ret; - } - break; - case EXCP_DEBUG: - { - int sig; - - sig =3D gdb_handlesig(cs, TARGET_SIGTRAP); - if (sig) - { - info.si_signo =3D sig; - info.si_errno =3D 0; - info.si_code =3D TARGET_TRAP_BRKPT; - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); - } - } - break; - case EXCP_ATOMIC: - cpu_exec_step_atomic(cs); - break; - default: - printf ("Unhandled trap: 0x%x\n", trapnr); - cpu_dump_state(cs, stderr, fprintf, 0); - exit(EXIT_FAILURE); - } - process_pending_signals (env); - } -} -#endif - #ifdef TARGET_MICROBLAZE void cpu_loop(CPUMBState *env) { @@ -2290,26 +2220,6 @@ int main(int argc, char **argv, char **envp) env->ir[IR_SP] =3D regs->usp; env->pc =3D regs->pc; } -#elif defined(TARGET_CRIS) - { - env->regs[0] =3D regs->r0; - env->regs[1] =3D regs->r1; - env->regs[2] =3D regs->r2; - env->regs[3] =3D regs->r3; - env->regs[4] =3D regs->r4; - env->regs[5] =3D regs->r5; - env->regs[6] =3D regs->r6; - env->regs[7] =3D regs->r7; - env->regs[8] =3D regs->r8; - env->regs[9] =3D regs->r9; - env->regs[10] =3D regs->r10; - env->regs[11] =3D regs->r11; - env->regs[12] =3D regs->r12; - env->regs[13] =3D regs->r13; - env->regs[14] =3D info->start_stack; - env->regs[15] =3D regs->acr; =20 - env->pc =3D regs->erp; - } #elif defined(TARGET_S390X) { int i; --=20 2.14.3 From nobody Mon May 6 08:55:16 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1523474276609793.3530753664942; Wed, 11 Apr 2018 12:17:56 -0700 (PDT) Received: from localhost ([::1]:48875 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f6LFj-0007Af-LW for importer@patchew.org; Wed, 11 Apr 2018 15:17:55 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38009) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f6Kw5-00064g-6V for qemu-devel@nongnu.org; Wed, 11 Apr 2018 14:57:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f6Kw1-0007r7-RE for qemu-devel@nongnu.org; Wed, 11 Apr 2018 14:57:37 -0400 Received: from mout.kundenserver.de ([217.72.192.74]:53685) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1f6Kw1-0007qC-Bi; Wed, 11 Apr 2018 14:57:33 -0400 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue105 [212.227.15.183]) with ESMTPSA (Nemesis) id 0M89Pl-1eKGch3vjV-00vcmP; Wed, 11 Apr 2018 20:57:19 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Date: Wed, 11 Apr 2018 20:56:44 +0200 Message-Id: <20180411185651.21351-13-laurent@vivier.eu> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180411185651.21351-1-laurent@vivier.eu> References: <20180411185651.21351-1-laurent@vivier.eu> X-Provags-ID: V03:K1:M5sjx9I8WXpNp53OPBsbS/bK5ZmuQ3fZWIOcRUmQutLtcjNgPHm HODstVTIVzkYFegT5zXjguqU28K0r4ikNN+libS61ARV81mwoDLm6eZzFzCcJSoJgBaBRwJ ADg7g+K4iPCBjk54IXx682KImFIpkyXBbrGDqBj2nETy7qG23S7CsRNlsXLFOXduKkmmNpN 1KjVWCU3BMXqOGBIoKNuQ== X-UI-Out-Filterresults: notjunk:1;V01:K0:mpaTYz1TUtY=:N8kG3UNFgbEfF6S1GZEj/v H3dgZVBOV8uL0g7lw5GINI435dIY2ARZPSj3RVmxyqcwBa06jwBg2A8EN0wEGfd8MoVk+NRDI zx7LZgSv88nfTPje3aWCs5qZYYc1Jephsa7Q+iL4mXRAzhpnpFGAMWUEm1kXrE/8w5ZRmAoXJ D4SgCWCQFvkFRfY5CbGU5dICBv1HH7gRsenB/rWW9W9T7YdAdzhjxQ0y56S5kBKUGk+BUa6GJ wYrHIvSAbnP9PYSy9Ajtl8w+JBNVy7yjWl7rb4R6QDlyT9ukQr4oAkwz9H1MHoJngxFsxq1Aj FbH1Wf2d9kck0PZHBpMp1xPtbpmXFaafQBGqeIY3tTpjQ2eImVZgxIOHVhBZ2pKiLzR8na55U vbH3H37Exx0NEptqytIewn3+wnlRmx7XYJAOnty5gwg7K88WJaGozCF7PXm1UoqN3qtpygCpS QCE1Avq3sVYEoo0zgdTzEf643bSL9vxTa8kwhh6yjtWsIKC6EniQTgK3a+r4iByjCO5Ekv8A3 IP3JgXzP+KHoSTtaEjj6Xt4yJVZOCmczo6IeWZU9nfC9Lkw+CezEye7N0ii+kqh2GrLM86wOs d5dBg61A/79UWIt7LcWwpG2q168aiWOOmxf2rRAy8sMCcdZZblNwt0zMfut1Dc5u7Az4cRV9k p22Qdsk3E/44nuiF72QxVWOWKHz2VyzBrrnAemNlayntXV1qc+uRSEGlj7RQ82f3cb0BT3IZ0 wosHijp+VIcfPYxG/mMYt/SfrOFEDMY37S98Zg== X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 217.72.192.74 Subject: [Qemu-devel] [PATCH for 2.13 v2 12/19] linux-user: move microblaze cpu loop to microblaze directory X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Cornelia Huck , Riku Voipio , Richard Henderson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Laurent Vivier , qemu-s390x@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" No code change, only move code from main.c to microblaze/cpu_loop.c. Signed-off-by: Laurent Vivier Reviewed-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- Notes: v2: expand tabs linux-user/main.c | 155 -----------------------------------= ---- linux-user/microblaze/cpu_loop.c | 150 +++++++++++++++++++++++++++++++++++= ++ 2 files changed, 150 insertions(+), 155 deletions(-) diff --git a/linux-user/main.c b/linux-user/main.c index 9e01325d6a..9e49c8a30c 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -149,125 +149,6 @@ void fork_end(int child) } } =20 -#ifdef TARGET_MICROBLAZE -void cpu_loop(CPUMBState *env) -{ - CPUState *cs =3D CPU(mb_env_get_cpu(env)); - int trapnr, ret; - target_siginfo_t info; - =20 - while (1) { - cpu_exec_start(cs); - trapnr =3D cpu_exec(cs); - cpu_exec_end(cs); - process_queued_cpu_work(cs); - - switch (trapnr) { - case 0xaa: - { - info.si_signo =3D TARGET_SIGSEGV; - info.si_errno =3D 0; - /* XXX: check env->error_code */ - info.si_code =3D TARGET_SEGV_MAPERR; - info._sifields._sigfault._addr =3D 0; - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); - } - break; - case EXCP_INTERRUPT: - /* just indicate that signals should be handled asap */ - break; - case EXCP_BREAK: - /* Return address is 4 bytes after the call. */ - env->regs[14] +=3D 4; - env->sregs[SR_PC] =3D env->regs[14]; - ret =3D do_syscall(env,=20 - env->regs[12],=20 - env->regs[5],=20 - env->regs[6],=20 - env->regs[7],=20 - env->regs[8],=20 - env->regs[9],=20 - env->regs[10], - 0, 0); - if (ret =3D=3D -TARGET_ERESTARTSYS) { - /* Wind back to before the syscall. */ - env->sregs[SR_PC] -=3D 4; - } else if (ret !=3D -TARGET_QEMU_ESIGRETURN) { - env->regs[3] =3D ret; - } - /* All syscall exits result in guest r14 being equal to the - * PC we return to, because the kernel syscall exit "rtbd" does - * this. (This is true even for sigreturn(); note that r14 is - * not a userspace-usable register, as the kernel may clobber = it - * at any point.) - */ - env->regs[14] =3D env->sregs[SR_PC]; - break; - case EXCP_HW_EXCP: - env->regs[17] =3D env->sregs[SR_PC] + 4; - if (env->iflags & D_FLAG) { - env->sregs[SR_ESR] |=3D 1 << 12; - env->sregs[SR_PC] -=3D 4; - /* FIXME: if branch was immed, replay the imm as well. */ - } - - env->iflags &=3D ~(IMM_FLAG | D_FLAG); - - switch (env->sregs[SR_ESR] & 31) { - case ESR_EC_DIVZERO: - info.si_signo =3D TARGET_SIGFPE; - info.si_errno =3D 0; - info.si_code =3D TARGET_FPE_FLTDIV; - info._sifields._sigfault._addr =3D 0; - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); - break; - case ESR_EC_FPU: - info.si_signo =3D TARGET_SIGFPE; - info.si_errno =3D 0; - if (env->sregs[SR_FSR] & FSR_IO) { - info.si_code =3D TARGET_FPE_FLTINV; - } - if (env->sregs[SR_FSR] & FSR_DZ) { - info.si_code =3D TARGET_FPE_FLTDIV; - } - info._sifields._sigfault._addr =3D 0; - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); - break; - default: - printf ("Unhandled hw-exception: 0x%x\n", - env->sregs[SR_ESR] & ESR_EC_MASK); - cpu_dump_state(cs, stderr, fprintf, 0); - exit(EXIT_FAILURE); - break; - } - break; - case EXCP_DEBUG: - { - int sig; - - sig =3D gdb_handlesig(cs, TARGET_SIGTRAP); - if (sig) - { - info.si_signo =3D sig; - info.si_errno =3D 0; - info.si_code =3D TARGET_TRAP_BRKPT; - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); - } - } - break; - case EXCP_ATOMIC: - cpu_exec_step_atomic(cs); - break; - default: - printf ("Unhandled trap: 0x%x\n", trapnr); - cpu_dump_state(cs, stderr, fprintf, 0); - exit(EXIT_FAILURE); - } - process_pending_signals (env); - } -} -#endif - #ifdef TARGET_M68K =20 void cpu_loop(CPUM68KState *env) @@ -2169,42 +2050,6 @@ int main(int argc, char **argv, char **envp) env->sr =3D regs->sr; ts->sim_syscalls =3D 1; } -#elif defined(TARGET_MICROBLAZE) - { - env->regs[0] =3D regs->r0; - env->regs[1] =3D regs->r1; - env->regs[2] =3D regs->r2; - env->regs[3] =3D regs->r3; - env->regs[4] =3D regs->r4; - env->regs[5] =3D regs->r5; - env->regs[6] =3D regs->r6; - env->regs[7] =3D regs->r7; - env->regs[8] =3D regs->r8; - env->regs[9] =3D regs->r9; - env->regs[10] =3D regs->r10; - env->regs[11] =3D regs->r11; - env->regs[12] =3D regs->r12; - env->regs[13] =3D regs->r13; - env->regs[14] =3D regs->r14; - env->regs[15] =3D regs->r15; =20 - env->regs[16] =3D regs->r16; =20 - env->regs[17] =3D regs->r17; =20 - env->regs[18] =3D regs->r18; =20 - env->regs[19] =3D regs->r19; =20 - env->regs[20] =3D regs->r20; =20 - env->regs[21] =3D regs->r21; =20 - env->regs[22] =3D regs->r22; =20 - env->regs[23] =3D regs->r23; =20 - env->regs[24] =3D regs->r24; =20 - env->regs[25] =3D regs->r25; =20 - env->regs[26] =3D regs->r26; =20 - env->regs[27] =3D regs->r27; =20 - env->regs[28] =3D regs->r28; =20 - env->regs[29] =3D regs->r29; =20 - env->regs[30] =3D regs->r30; =20 - env->regs[31] =3D regs->r31; =20 - env->sregs[SR_PC] =3D regs->pc; - } #elif defined(TARGET_RISCV) { env->pc =3D regs->sepc; diff --git a/linux-user/microblaze/cpu_loop.c b/linux-user/microblaze/cpu_l= oop.c index b7700a5561..5ffb83dea2 100644 --- a/linux-user/microblaze/cpu_loop.c +++ b/linux-user/microblaze/cpu_loop.c @@ -21,6 +21,156 @@ #include "qemu.h" #include "cpu_loop-common.h" =20 +void cpu_loop(CPUMBState *env) +{ + CPUState *cs =3D CPU(mb_env_get_cpu(env)); + int trapnr, ret; + target_siginfo_t info; + =20 + while (1) { + cpu_exec_start(cs); + trapnr =3D cpu_exec(cs); + cpu_exec_end(cs); + process_queued_cpu_work(cs); + + switch (trapnr) { + case 0xaa: + { + info.si_signo =3D TARGET_SIGSEGV; + info.si_errno =3D 0; + /* XXX: check env->error_code */ + info.si_code =3D TARGET_SEGV_MAPERR; + info._sifields._sigfault._addr =3D 0; + queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + } + break; + case EXCP_INTERRUPT: + /* just indicate that signals should be handled asap */ + break; + case EXCP_BREAK: + /* Return address is 4 bytes after the call. */ + env->regs[14] +=3D 4; + env->sregs[SR_PC] =3D env->regs[14]; + ret =3D do_syscall(env,=20 + env->regs[12],=20 + env->regs[5],=20 + env->regs[6],=20 + env->regs[7],=20 + env->regs[8],=20 + env->regs[9],=20 + env->regs[10], + 0, 0); + if (ret =3D=3D -TARGET_ERESTARTSYS) { + /* Wind back to before the syscall. */ + env->sregs[SR_PC] -=3D 4; + } else if (ret !=3D -TARGET_QEMU_ESIGRETURN) { + env->regs[3] =3D ret; + } + /* All syscall exits result in guest r14 being equal to the + * PC we return to, because the kernel syscall exit "rtbd" does + * this. (This is true even for sigreturn(); note that r14 is + * not a userspace-usable register, as the kernel may clobber = it + * at any point.) + */ + env->regs[14] =3D env->sregs[SR_PC]; + break; + case EXCP_HW_EXCP: + env->regs[17] =3D env->sregs[SR_PC] + 4; + if (env->iflags & D_FLAG) { + env->sregs[SR_ESR] |=3D 1 << 12; + env->sregs[SR_PC] -=3D 4; + /* FIXME: if branch was immed, replay the imm as well. */ + } + + env->iflags &=3D ~(IMM_FLAG | D_FLAG); + + switch (env->sregs[SR_ESR] & 31) { + case ESR_EC_DIVZERO: + info.si_signo =3D TARGET_SIGFPE; + info.si_errno =3D 0; + info.si_code =3D TARGET_FPE_FLTDIV; + info._sifields._sigfault._addr =3D 0; + queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + break; + case ESR_EC_FPU: + info.si_signo =3D TARGET_SIGFPE; + info.si_errno =3D 0; + if (env->sregs[SR_FSR] & FSR_IO) { + info.si_code =3D TARGET_FPE_FLTINV; + } + if (env->sregs[SR_FSR] & FSR_DZ) { + info.si_code =3D TARGET_FPE_FLTDIV; + } + info._sifields._sigfault._addr =3D 0; + queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + break; + default: + printf ("Unhandled hw-exception: 0x%x\n", + env->sregs[SR_ESR] & ESR_EC_MASK); + cpu_dump_state(cs, stderr, fprintf, 0); + exit(EXIT_FAILURE); + break; + } + break; + case EXCP_DEBUG: + { + int sig; + + sig =3D gdb_handlesig(cs, TARGET_SIGTRAP); + if (sig) + { + info.si_signo =3D sig; + info.si_errno =3D 0; + info.si_code =3D TARGET_TRAP_BRKPT; + queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + } + } + break; + case EXCP_ATOMIC: + cpu_exec_step_atomic(cs); + break; + default: + printf ("Unhandled trap: 0x%x\n", trapnr); + cpu_dump_state(cs, stderr, fprintf, 0); + exit(EXIT_FAILURE); + } + process_pending_signals (env); + } +} + void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs) { + env->regs[0] =3D regs->r0; + env->regs[1] =3D regs->r1; + env->regs[2] =3D regs->r2; + env->regs[3] =3D regs->r3; + env->regs[4] =3D regs->r4; + env->regs[5] =3D regs->r5; + env->regs[6] =3D regs->r6; + env->regs[7] =3D regs->r7; + env->regs[8] =3D regs->r8; + env->regs[9] =3D regs->r9; + env->regs[10] =3D regs->r10; + env->regs[11] =3D regs->r11; + env->regs[12] =3D regs->r12; + env->regs[13] =3D regs->r13; + env->regs[14] =3D regs->r14; + env->regs[15] =3D regs->r15; + env->regs[16] =3D regs->r16; + env->regs[17] =3D regs->r17; + env->regs[18] =3D regs->r18; + env->regs[19] =3D regs->r19; + env->regs[20] =3D regs->r20; + env->regs[21] =3D regs->r21; + env->regs[22] =3D regs->r22; + env->regs[23] =3D regs->r23; + env->regs[24] =3D regs->r24; + env->regs[25] =3D regs->r25; + env->regs[26] =3D regs->r26; + env->regs[27] =3D regs->r27; + env->regs[28] =3D regs->r28; + env->regs[29] =3D regs->r29; + env->regs[30] =3D regs->r30; + env->regs[31] =3D regs->r31; + env->sregs[SR_PC] =3D regs->pc; } --=20 2.14.3 From nobody Mon May 6 08:55:16 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1523475208370892.8677490960816; Wed, 11 Apr 2018 12:33:28 -0700 (PDT) Received: from localhost ([::1]:49678 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f6LUl-0003Ua-Cw for importer@patchew.org; Wed, 11 Apr 2018 15:33:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38209) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f6KwF-0006EP-20 for qemu-devel@nongnu.org; Wed, 11 Apr 2018 14:57:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f6KwA-0007zb-P7 for qemu-devel@nongnu.org; Wed, 11 Apr 2018 14:57:47 -0400 Received: from mout.kundenserver.de ([212.227.17.10]:43849) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1f6Kw3-0007rK-7E; Wed, 11 Apr 2018 14:57:35 -0400 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue105 [212.227.15.183]) with ESMTPSA (Nemesis) id 0LiUtY-1eTyJ13qBg-00cit2; Wed, 11 Apr 2018 20:57:20 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Date: Wed, 11 Apr 2018 20:56:45 +0200 Message-Id: <20180411185651.21351-14-laurent@vivier.eu> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180411185651.21351-1-laurent@vivier.eu> References: <20180411185651.21351-1-laurent@vivier.eu> X-Provags-ID: V03:K1:1Ci0RsOKdmQGaA+TkXvZPdpz0aBhjUcVRby7ewdTKWgq9pSHUVB w0Mex0kM2nnlVlN8xmMwzG5R20NaEvVpL7VFSJ7x7i8Zvtmpt0ZhdY2nbEHuP9jprRhQ1gk Ua6lUAbCFgn5T5JQUm/vL6qV009sVTmap17tfQAyzXinjWsSF0OuWozlikLD82GM8DJBSzU I5dovIhwMxRq9S0rfgZlA== X-UI-Out-Filterresults: notjunk:1;V01:K0:f0uEtalXY8g=:AtSVhfof0A817jVZRbpnhJ eMsgLKWKG/ZyNN6Pka9tof4nyYmUYkczV0EEamkaKNCfvxcMMK+As1QkIWOBTm+LhmHZ+y/kA /YgI5pBH2WdA/C7yyfZbH4alYzyxkh3DsdAEi6w1Gy58lHNQwtxEUIDlKZaoQLctZ/u/jEFRY FFtxYKqzyxsX66nu4NI07E73C1MQ+hrFLA+jzAVY70zAF4I96qn5YJm22v7AOwzRtsuiKVGmk 4+HBs7X0fkra+GL2f6tR07QnOElxhtFhvH1tReZfn05L9rUAKp1Qt9UFnLW33XbimHopczxYG 1HEc75Sm7yOyNfSwo7rP75mn8WhwvuRm9Yxj8tymv7YiA5r2tRmrDhm43ZFzPVz9vNmXjOWgm 8eWNnUq3WKj49b+wJVImgpw5Co2SdrjVkjQZHxKtCE64N6pySy4cNRnptvLxgGoPKLA2zMEtC ehrf9oPWU0hWu2hW/o6fXjMBtOKlAdv0bjXXDWG4z+tTuI+mVEEDhRzxi1XwUEozE6dgVH6bA U/zizxqTdAARqiNAx/aYravMGsTkEB2cMv5qus2ueAFyk8FAI0ssRMAlYBmVYTCjQlgdLZyXb VhoPq2jMXliLAEM31QKg39T+8HagbLaiLA20gVu4LtDkMux8HeJUrV7lIuHcuOtykyBt2mv3o vdl74nnYoNVKyLn6tVA+mIb2IXSq3L5Sqe+18UGArMjv25hkwGeEUt4WRKuoyKz1kzPGBBm2M fKYHYCrMQXcShwks81iBToDnzTxXIJiqVOnK6A== X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 212.227.17.10 Subject: [Qemu-devel] [PATCH for 2.13 v2 13/19] linux-user: move m68k cpu loop to m68k directory X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Cornelia Huck , Riku Voipio , Richard Henderson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Laurent Vivier , qemu-s390x@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" No code change, only move code from main.c to m68k/cpu_loop.c. Signed-off-by: Laurent Vivier Reviewed-by: Richard Henderson --- linux-user/m68k/cpu_loop.c | 144 +++++++++++++++++++++++++++++++++++++++++= ++ linux-user/main.c | 150 +----------------------------------------= ---- 2 files changed, 145 insertions(+), 149 deletions(-) diff --git a/linux-user/m68k/cpu_loop.c b/linux-user/m68k/cpu_loop.c index b7700a5561..b4d3d8af3d 100644 --- a/linux-user/m68k/cpu_loop.c +++ b/linux-user/m68k/cpu_loop.c @@ -21,6 +21,150 @@ #include "qemu.h" #include "cpu_loop-common.h" =20 +void cpu_loop(CPUM68KState *env) +{ + CPUState *cs =3D CPU(m68k_env_get_cpu(env)); + int trapnr; + unsigned int n; + target_siginfo_t info; + TaskState *ts =3D cs->opaque; + + for(;;) { + cpu_exec_start(cs); + trapnr =3D cpu_exec(cs); + cpu_exec_end(cs); + process_queued_cpu_work(cs); + + switch(trapnr) { + case EXCP_ILLEGAL: + { + if (ts->sim_syscalls) { + uint16_t nr; + get_user_u16(nr, env->pc + 2); + env->pc +=3D 4; + do_m68k_simcall(env, nr); + } else { + goto do_sigill; + } + } + break; + case EXCP_HALT_INSN: + /* Semihosing syscall. */ + env->pc +=3D 4; + do_m68k_semihosting(env, env->dregs[0]); + break; + case EXCP_LINEA: + case EXCP_LINEF: + case EXCP_UNSUPPORTED: + do_sigill: + info.si_signo =3D TARGET_SIGILL; + info.si_errno =3D 0; + info.si_code =3D TARGET_ILL_ILLOPN; + info._sifields._sigfault._addr =3D env->pc; + queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + break; + case EXCP_CHK: + info.si_signo =3D TARGET_SIGFPE; + info.si_errno =3D 0; + info.si_code =3D TARGET_FPE_INTOVF; + info._sifields._sigfault._addr =3D env->pc; + queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + break; + case EXCP_DIV0: + info.si_signo =3D TARGET_SIGFPE; + info.si_errno =3D 0; + info.si_code =3D TARGET_FPE_INTDIV; + info._sifields._sigfault._addr =3D env->pc; + queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + break; + case EXCP_TRAP0: + { + abi_long ret; + ts->sim_syscalls =3D 0; + n =3D env->dregs[0]; + env->pc +=3D 2; + ret =3D do_syscall(env, + n, + env->dregs[1], + env->dregs[2], + env->dregs[3], + env->dregs[4], + env->dregs[5], + env->aregs[0], + 0, 0); + if (ret =3D=3D -TARGET_ERESTARTSYS) { + env->pc -=3D 2; + } else if (ret !=3D -TARGET_QEMU_ESIGRETURN) { + env->dregs[0] =3D ret; + } + } + break; + case EXCP_INTERRUPT: + /* just indicate that signals should be handled asap */ + break; + case EXCP_ACCESS: + { + info.si_signo =3D TARGET_SIGSEGV; + info.si_errno =3D 0; + /* XXX: check env->error_code */ + info.si_code =3D TARGET_SEGV_MAPERR; + info._sifields._sigfault._addr =3D env->mmu.ar; + queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + } + break; + case EXCP_DEBUG: + { + int sig; + + sig =3D gdb_handlesig(cs, TARGET_SIGTRAP); + if (sig) + { + info.si_signo =3D sig; + info.si_errno =3D 0; + info.si_code =3D TARGET_TRAP_BRKPT; + queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + } + } + break; + case EXCP_ATOMIC: + cpu_exec_step_atomic(cs); + break; + default: + EXCP_DUMP(env, "qemu: unhandled CPU exception 0x%x - aborting\= n", trapnr); + abort(); + } + process_pending_signals(env); + } +} + void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs) { + CPUState *cpu =3D ENV_GET_CPU(env); + TaskState *ts =3D cpu->opaque; + struct image_info *info =3D ts->info; + + env->pc =3D regs->pc; + env->dregs[0] =3D regs->d0; + env->dregs[1] =3D regs->d1; + env->dregs[2] =3D regs->d2; + env->dregs[3] =3D regs->d3; + env->dregs[4] =3D regs->d4; + env->dregs[5] =3D regs->d5; + env->dregs[6] =3D regs->d6; + env->dregs[7] =3D regs->d7; + env->aregs[0] =3D regs->a0; + env->aregs[1] =3D regs->a1; + env->aregs[2] =3D regs->a2; + env->aregs[3] =3D regs->a3; + env->aregs[4] =3D regs->a4; + env->aregs[5] =3D regs->a5; + env->aregs[6] =3D regs->a6; + env->aregs[7] =3D regs->usp; + env->sr =3D regs->sr; + + ts->sim_syscalls =3D 1; + ts->stack_base =3D info->start_stack; + ts->heap_base =3D info->brk; + /* This will be filled in on the first SYS_HEAPINFO call. */ + ts->heap_limit =3D 0; } diff --git a/linux-user/main.c b/linux-user/main.c index 9e49c8a30c..7c223a5629 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -149,125 +149,6 @@ void fork_end(int child) } } =20 -#ifdef TARGET_M68K - -void cpu_loop(CPUM68KState *env) -{ - CPUState *cs =3D CPU(m68k_env_get_cpu(env)); - int trapnr; - unsigned int n; - target_siginfo_t info; - TaskState *ts =3D cs->opaque; - - for(;;) { - cpu_exec_start(cs); - trapnr =3D cpu_exec(cs); - cpu_exec_end(cs); - process_queued_cpu_work(cs); - - switch(trapnr) { - case EXCP_ILLEGAL: - { - if (ts->sim_syscalls) { - uint16_t nr; - get_user_u16(nr, env->pc + 2); - env->pc +=3D 4; - do_m68k_simcall(env, nr); - } else { - goto do_sigill; - } - } - break; - case EXCP_HALT_INSN: - /* Semihosing syscall. */ - env->pc +=3D 4; - do_m68k_semihosting(env, env->dregs[0]); - break; - case EXCP_LINEA: - case EXCP_LINEF: - case EXCP_UNSUPPORTED: - do_sigill: - info.si_signo =3D TARGET_SIGILL; - info.si_errno =3D 0; - info.si_code =3D TARGET_ILL_ILLOPN; - info._sifields._sigfault._addr =3D env->pc; - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); - break; - case EXCP_CHK: - info.si_signo =3D TARGET_SIGFPE; - info.si_errno =3D 0; - info.si_code =3D TARGET_FPE_INTOVF; - info._sifields._sigfault._addr =3D env->pc; - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); - break; - case EXCP_DIV0: - info.si_signo =3D TARGET_SIGFPE; - info.si_errno =3D 0; - info.si_code =3D TARGET_FPE_INTDIV; - info._sifields._sigfault._addr =3D env->pc; - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); - break; - case EXCP_TRAP0: - { - abi_long ret; - ts->sim_syscalls =3D 0; - n =3D env->dregs[0]; - env->pc +=3D 2; - ret =3D do_syscall(env, - n, - env->dregs[1], - env->dregs[2], - env->dregs[3], - env->dregs[4], - env->dregs[5], - env->aregs[0], - 0, 0); - if (ret =3D=3D -TARGET_ERESTARTSYS) { - env->pc -=3D 2; - } else if (ret !=3D -TARGET_QEMU_ESIGRETURN) { - env->dregs[0] =3D ret; - } - } - break; - case EXCP_INTERRUPT: - /* just indicate that signals should be handled asap */ - break; - case EXCP_ACCESS: - { - info.si_signo =3D TARGET_SIGSEGV; - info.si_errno =3D 0; - /* XXX: check env->error_code */ - info.si_code =3D TARGET_SEGV_MAPERR; - info._sifields._sigfault._addr =3D env->mmu.ar; - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); - } - break; - case EXCP_DEBUG: - { - int sig; - - sig =3D gdb_handlesig(cs, TARGET_SIGTRAP); - if (sig) - { - info.si_signo =3D sig; - info.si_errno =3D 0; - info.si_code =3D TARGET_TRAP_BRKPT; - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); - } - } - break; - case EXCP_ATOMIC: - cpu_exec_step_atomic(cs); - break; - default: - EXCP_DUMP(env, "qemu: unhandled CPU exception 0x%x - aborting\= n", trapnr); - abort(); - } - process_pending_signals(env); - } -} -#endif /* TARGET_M68K */ - #ifdef TARGET_ALPHA void cpu_loop(CPUAlphaState *env) { @@ -2028,29 +1909,7 @@ int main(int argc, char **argv, char **envp) =20 target_cpu_copy_regs(env, regs); =20 -#if defined(TARGET_M68K) - { - env->pc =3D regs->pc; - env->dregs[0] =3D regs->d0; - env->dregs[1] =3D regs->d1; - env->dregs[2] =3D regs->d2; - env->dregs[3] =3D regs->d3; - env->dregs[4] =3D regs->d4; - env->dregs[5] =3D regs->d5; - env->dregs[6] =3D regs->d6; - env->dregs[7] =3D regs->d7; - env->aregs[0] =3D regs->a0; - env->aregs[1] =3D regs->a1; - env->aregs[2] =3D regs->a2; - env->aregs[3] =3D regs->a3; - env->aregs[4] =3D regs->a4; - env->aregs[5] =3D regs->a5; - env->aregs[6] =3D regs->a6; - env->aregs[7] =3D regs->usp; - env->sr =3D regs->sr; - ts->sim_syscalls =3D 1; - } -#elif defined(TARGET_RISCV) +#if defined(TARGET_RISCV) { env->pc =3D regs->sepc; env->gpr[xSP] =3D regs->sp; @@ -2105,13 +1964,6 @@ int main(int argc, char **argv, char **envp) } #endif =20 -#if defined(TARGET_M68K) - ts->stack_base =3D info->start_stack; - ts->heap_base =3D info->brk; - /* This will be filled in on the first SYS_HEAPINFO call. */ - ts->heap_limit =3D 0; -#endif - if (gdbstub_port) { if (gdbserver_start(gdbstub_port) < 0) { fprintf(stderr, "qemu: could not open gdbserver on port %d\n", --=20 2.14.3 From nobody Mon May 6 08:55:16 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1523476283974456.88107583594933; Wed, 11 Apr 2018 12:51:23 -0700 (PDT) Received: from localhost ([::1]:52347 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f6Lm6-00040U-T1 for importer@patchew.org; Wed, 11 Apr 2018 15:51:22 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40899) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f6L15-0002YW-Ux for qemu-devel@nongnu.org; Wed, 11 Apr 2018 15:02:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f6L14-00024s-7E for qemu-devel@nongnu.org; Wed, 11 Apr 2018 15:02:48 -0400 Received: from mout.kundenserver.de ([217.72.192.75]:54191) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1f6L0y-0001z0-BC; Wed, 11 Apr 2018 15:02:40 -0400 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue105 [212.227.15.183]) with ESMTPSA (Nemesis) id 0MHYb6-1f32563U2m-003O4K; Wed, 11 Apr 2018 20:57:21 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Date: Wed, 11 Apr 2018 20:56:46 +0200 Message-Id: <20180411185651.21351-15-laurent@vivier.eu> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180411185651.21351-1-laurent@vivier.eu> References: <20180411185651.21351-1-laurent@vivier.eu> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:jp/ezdpKrABPXrEz90kJCKy80Jqg7nwnu5hmjHTO/DkKUaMnrUc 6dZNefW35Gu9AgKgbnD1mC2uRgDVyEvU0Zhtqkg94EpT5+zsD8oFAd/8+9C743kCDoedU8q qoRwrhKmiQof4wzw5fTY0KJMGHFXWIEcyudqhWpTVMJlXqxqNntJ5BLlVxSLd7kwTCcYA10 +z2qxkJ6XZ4xic4HMg3EA== X-UI-Out-Filterresults: notjunk:1;V01:K0:p+KKbmZ4v3w=:imdb16bYMw6lIxE2v7e2qB NjmG2ByG0ttT+laGlpVvz5jtuXV0VGJWYLjDHseRP0qTCh28izKYTmA7xEcb/anoTLG4sYFBN 5fRyVegGo/rq9kfPlfB9Tit3eFjf4R8sR2ij5+gdG5GxCwIo34do/Je74+hLZNkj2ipE83M+D BIKnsh7di+FJcLev5a6yEqACm1RnajE/491ThEFQUDbvL4SLxUJO03aQF+5BMA0K8oVZ6kVeU heC3mGE/gdEcA20o5k+p2/W4RzFNaXelVE1oLKwLueVXY88SQFbhq6R8yC204ptHuBpfbXa7M Aa+P36khe/IIipbSmWtbP2BSMFuccSRMncWaqSa1paP08EzZiGfXp5oq184c1gWwB1N7piwun W0QrVImAbZ/OLPPRiwFcwVu+mTC3BR8DuL+1GmBywcvY1CbLyqDGaozRjUQflcaMhOHVWiK0J tdR6BuvfLAEWhX23ehM0IAmrkfiYy0uSlfeCt83C/o1IP7NWQnoUYPdyN6VDdK556VjL0Jt9d j+L077LywhdWbrTVcwZrc+UZ9S3ktW5MrpGmiymEMQREGrdjCCiu9TO6KDC27/+ywZrIaYTC4 ++1wQxT5PIWv3JkoGbQwjwK3x4TgdQID3hL+RE3PSQo24DVE3FiunVWXJTgz0pv5Vv7Nza5mB pM3aCo4dNKNZGCL4/CXbf8m467I8T4oGtKYi8G0QN+RbGJzAe4FcNmUa8vqxFBdoA/4bYhC+j XktGYCglFXabxgFoMAN22tIWHwBn38bPSzizEAP9tUWDrfrr+jh7jhk9Wew= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 217.72.192.75 Subject: [Qemu-devel] [PATCH for 2.13 v2 14/19] linux-user: move alpha cpu loop to alpha directory X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Cornelia Huck , Riku Voipio , Richard Henderson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Laurent Vivier , qemu-s390x@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 No code change, only move code from main.c to alpha/cpu_loop.c. Signed-off-by: Laurent Vivier Reviewed-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- linux-user/alpha/cpu_loop.c | 199 ++++++++++++++++++++++++++++++++++++++++= ++ linux-user/main.c | 204 ----------------------------------------= ---- 2 files changed, 199 insertions(+), 204 deletions(-) diff --git a/linux-user/alpha/cpu_loop.c b/linux-user/alpha/cpu_loop.c index b7700a5561..b87fcaea87 100644 --- a/linux-user/alpha/cpu_loop.c +++ b/linux-user/alpha/cpu_loop.c @@ -21,6 +21,205 @@ #include "qemu.h" #include "cpu_loop-common.h" =20 +void cpu_loop(CPUAlphaState *env) +{ + CPUState *cs =3D CPU(alpha_env_get_cpu(env)); + int trapnr; + target_siginfo_t info; + abi_long sysret; + + while (1) { + bool arch_interrupt =3D true; + + cpu_exec_start(cs); + trapnr =3D cpu_exec(cs); + cpu_exec_end(cs); + process_queued_cpu_work(cs); + + switch (trapnr) { + case EXCP_RESET: + fprintf(stderr, "Reset requested. Exit\n"); + exit(EXIT_FAILURE); + break; + case EXCP_MCHK: + fprintf(stderr, "Machine check exception. Exit\n"); + exit(EXIT_FAILURE); + break; + case EXCP_SMP_INTERRUPT: + case EXCP_CLK_INTERRUPT: + case EXCP_DEV_INTERRUPT: + fprintf(stderr, "External interrupt. Exit\n"); + exit(EXIT_FAILURE); + break; + case EXCP_MMFAULT: + info.si_signo =3D TARGET_SIGSEGV; + info.si_errno =3D 0; + info.si_code =3D (page_get_flags(env->trap_arg0) & PAGE_VALID + ? TARGET_SEGV_ACCERR : TARGET_SEGV_MAPERR); + info._sifields._sigfault._addr =3D env->trap_arg0; + queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + break; + case EXCP_UNALIGN: + info.si_signo =3D TARGET_SIGBUS; + info.si_errno =3D 0; + info.si_code =3D TARGET_BUS_ADRALN; + info._sifields._sigfault._addr =3D env->trap_arg0; + queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + break; + case EXCP_OPCDEC: + do_sigill: + info.si_signo =3D TARGET_SIGILL; + info.si_errno =3D 0; + info.si_code =3D TARGET_ILL_ILLOPC; + info._sifields._sigfault._addr =3D env->pc; + queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + break; + case EXCP_ARITH: + info.si_signo =3D TARGET_SIGFPE; + info.si_errno =3D 0; + info.si_code =3D TARGET_FPE_FLTINV; + info._sifields._sigfault._addr =3D env->pc; + queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + break; + case EXCP_FEN: + /* No-op. Linux simply re-enables the FPU. */ + break; + case EXCP_CALL_PAL: + switch (env->error_code) { + case 0x80: + /* BPT */ + info.si_signo =3D TARGET_SIGTRAP; + info.si_errno =3D 0; + info.si_code =3D TARGET_TRAP_BRKPT; + info._sifields._sigfault._addr =3D env->pc; + queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + break; + case 0x81: + /* BUGCHK */ + info.si_signo =3D TARGET_SIGTRAP; + info.si_errno =3D 0; + info.si_code =3D 0; + info._sifields._sigfault._addr =3D env->pc; + queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + break; + case 0x83: + /* CALLSYS */ + trapnr =3D env->ir[IR_V0]; + sysret =3D do_syscall(env, trapnr, + env->ir[IR_A0], env->ir[IR_A1], + env->ir[IR_A2], env->ir[IR_A3], + env->ir[IR_A4], env->ir[IR_A5], + 0, 0); + if (sysret =3D=3D -TARGET_ERESTARTSYS) { + env->pc -=3D 4; + break; + } + if (sysret =3D=3D -TARGET_QEMU_ESIGRETURN) { + break; + } + /* Syscall writes 0 to V0 to bypass error check, similar + to how this is handled internal to Linux kernel. + (Ab)use trapnr temporarily as boolean indicating error.= */ + trapnr =3D (env->ir[IR_V0] !=3D 0 && sysret < 0); + env->ir[IR_V0] =3D (trapnr ? -sysret : sysret); + env->ir[IR_A3] =3D trapnr; + break; + case 0x86: + /* IMB */ + /* ??? We can probably elide the code using page_unprotect + that is checking for self-modifying code. Instead we + could simply call tb_flush here. Until we work out the + changes required to turn off the extra write protection, + this can be a no-op. */ + break; + case 0x9E: + /* RDUNIQUE */ + /* Handled in the translator for usermode. */ + abort(); + case 0x9F: + /* WRUNIQUE */ + /* Handled in the translator for usermode. */ + abort(); + case 0xAA: + /* GENTRAP */ + info.si_signo =3D TARGET_SIGFPE; + switch (env->ir[IR_A0]) { + case TARGET_GEN_INTOVF: + info.si_code =3D TARGET_FPE_INTOVF; + break; + case TARGET_GEN_INTDIV: + info.si_code =3D TARGET_FPE_INTDIV; + break; + case TARGET_GEN_FLTOVF: + info.si_code =3D TARGET_FPE_FLTOVF; + break; + case TARGET_GEN_FLTUND: + info.si_code =3D TARGET_FPE_FLTUND; + break; + case TARGET_GEN_FLTINV: + info.si_code =3D TARGET_FPE_FLTINV; + break; + case TARGET_GEN_FLTINE: + info.si_code =3D TARGET_FPE_FLTRES; + break; + case TARGET_GEN_ROPRAND: + info.si_code =3D 0; + break; + default: + info.si_signo =3D TARGET_SIGTRAP; + info.si_code =3D 0; + break; + } + info.si_errno =3D 0; + info._sifields._sigfault._addr =3D env->pc; + queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + break; + default: + goto do_sigill; + } + break; + case EXCP_DEBUG: + info.si_signo =3D gdb_handlesig(cs, TARGET_SIGTRAP); + if (info.si_signo) { + info.si_errno =3D 0; + info.si_code =3D TARGET_TRAP_BRKPT; + queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + } else { + arch_interrupt =3D false; + } + break; + case EXCP_INTERRUPT: + /* Just indicate that signals should be handled asap. */ + break; + case EXCP_ATOMIC: + cpu_exec_step_atomic(cs); + arch_interrupt =3D false; + break; + default: + printf ("Unhandled trap: 0x%x\n", trapnr); + cpu_dump_state(cs, stderr, fprintf, 0); + exit(EXIT_FAILURE); + } + process_pending_signals (env); + + /* Most of the traps imply a transition through PALcode, which + implies an REI instruction has been executed. Which means + that RX and LOCK_ADDR should be cleared. But there are a + few exceptions for traps internal to QEMU. */ + if (arch_interrupt) { + env->flags &=3D ~ENV_FLAG_RX_FLAG; + env->lock_addr =3D -1; + } + } +} + void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs) { + int i; + + for(i =3D 0; i < 28; i++) { + env->ir[i] =3D ((abi_ulong *)regs)[i]; + } + env->ir[IR_SP] =3D regs->usp; + env->pc =3D regs->pc; } diff --git a/linux-user/main.c b/linux-user/main.c index 7c223a5629..37cf3a7d6f 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -149,200 +149,6 @@ void fork_end(int child) } } =20 -#ifdef TARGET_ALPHA -void cpu_loop(CPUAlphaState *env) -{ - CPUState *cs =3D CPU(alpha_env_get_cpu(env)); - int trapnr; - target_siginfo_t info; - abi_long sysret; - - while (1) { - bool arch_interrupt =3D true; - - cpu_exec_start(cs); - trapnr =3D cpu_exec(cs); - cpu_exec_end(cs); - process_queued_cpu_work(cs); - - switch (trapnr) { - case EXCP_RESET: - fprintf(stderr, "Reset requested. Exit\n"); - exit(EXIT_FAILURE); - break; - case EXCP_MCHK: - fprintf(stderr, "Machine check exception. Exit\n"); - exit(EXIT_FAILURE); - break; - case EXCP_SMP_INTERRUPT: - case EXCP_CLK_INTERRUPT: - case EXCP_DEV_INTERRUPT: - fprintf(stderr, "External interrupt. Exit\n"); - exit(EXIT_FAILURE); - break; - case EXCP_MMFAULT: - info.si_signo =3D TARGET_SIGSEGV; - info.si_errno =3D 0; - info.si_code =3D (page_get_flags(env->trap_arg0) & PAGE_VALID - ? TARGET_SEGV_ACCERR : TARGET_SEGV_MAPERR); - info._sifields._sigfault._addr =3D env->trap_arg0; - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); - break; - case EXCP_UNALIGN: - info.si_signo =3D TARGET_SIGBUS; - info.si_errno =3D 0; - info.si_code =3D TARGET_BUS_ADRALN; - info._sifields._sigfault._addr =3D env->trap_arg0; - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); - break; - case EXCP_OPCDEC: - do_sigill: - info.si_signo =3D TARGET_SIGILL; - info.si_errno =3D 0; - info.si_code =3D TARGET_ILL_ILLOPC; - info._sifields._sigfault._addr =3D env->pc; - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); - break; - case EXCP_ARITH: - info.si_signo =3D TARGET_SIGFPE; - info.si_errno =3D 0; - info.si_code =3D TARGET_FPE_FLTINV; - info._sifields._sigfault._addr =3D env->pc; - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); - break; - case EXCP_FEN: - /* No-op. Linux simply re-enables the FPU. */ - break; - case EXCP_CALL_PAL: - switch (env->error_code) { - case 0x80: - /* BPT */ - info.si_signo =3D TARGET_SIGTRAP; - info.si_errno =3D 0; - info.si_code =3D TARGET_TRAP_BRKPT; - info._sifields._sigfault._addr =3D env->pc; - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); - break; - case 0x81: - /* BUGCHK */ - info.si_signo =3D TARGET_SIGTRAP; - info.si_errno =3D 0; - info.si_code =3D 0; - info._sifields._sigfault._addr =3D env->pc; - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); - break; - case 0x83: - /* CALLSYS */ - trapnr =3D env->ir[IR_V0]; - sysret =3D do_syscall(env, trapnr, - env->ir[IR_A0], env->ir[IR_A1], - env->ir[IR_A2], env->ir[IR_A3], - env->ir[IR_A4], env->ir[IR_A5], - 0, 0); - if (sysret =3D=3D -TARGET_ERESTARTSYS) { - env->pc -=3D 4; - break; - } - if (sysret =3D=3D -TARGET_QEMU_ESIGRETURN) { - break; - } - /* Syscall writes 0 to V0 to bypass error check, similar - to how this is handled internal to Linux kernel. - (Ab)use trapnr temporarily as boolean indicating error.= */ - trapnr =3D (env->ir[IR_V0] !=3D 0 && sysret < 0); - env->ir[IR_V0] =3D (trapnr ? -sysret : sysret); - env->ir[IR_A3] =3D trapnr; - break; - case 0x86: - /* IMB */ - /* ??? We can probably elide the code using page_unprotect - that is checking for self-modifying code. Instead we - could simply call tb_flush here. Until we work out the - changes required to turn off the extra write protection, - this can be a no-op. */ - break; - case 0x9E: - /* RDUNIQUE */ - /* Handled in the translator for usermode. */ - abort(); - case 0x9F: - /* WRUNIQUE */ - /* Handled in the translator for usermode. */ - abort(); - case 0xAA: - /* GENTRAP */ - info.si_signo =3D TARGET_SIGFPE; - switch (env->ir[IR_A0]) { - case TARGET_GEN_INTOVF: - info.si_code =3D TARGET_FPE_INTOVF; - break; - case TARGET_GEN_INTDIV: - info.si_code =3D TARGET_FPE_INTDIV; - break; - case TARGET_GEN_FLTOVF: - info.si_code =3D TARGET_FPE_FLTOVF; - break; - case TARGET_GEN_FLTUND: - info.si_code =3D TARGET_FPE_FLTUND; - break; - case TARGET_GEN_FLTINV: - info.si_code =3D TARGET_FPE_FLTINV; - break; - case TARGET_GEN_FLTINE: - info.si_code =3D TARGET_FPE_FLTRES; - break; - case TARGET_GEN_ROPRAND: - info.si_code =3D 0; - break; - default: - info.si_signo =3D TARGET_SIGTRAP; - info.si_code =3D 0; - break; - } - info.si_errno =3D 0; - info._sifields._sigfault._addr =3D env->pc; - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); - break; - default: - goto do_sigill; - } - break; - case EXCP_DEBUG: - info.si_signo =3D gdb_handlesig(cs, TARGET_SIGTRAP); - if (info.si_signo) { - info.si_errno =3D 0; - info.si_code =3D TARGET_TRAP_BRKPT; - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); - } else { - arch_interrupt =3D false; - } - break; - case EXCP_INTERRUPT: - /* Just indicate that signals should be handled asap. */ - break; - case EXCP_ATOMIC: - cpu_exec_step_atomic(cs); - arch_interrupt =3D false; - break; - default: - printf ("Unhandled trap: 0x%x\n", trapnr); - cpu_dump_state(cs, stderr, fprintf, 0); - exit(EXIT_FAILURE); - } - process_pending_signals (env); - - /* Most of the traps imply a transition through PALcode, which - implies an REI instruction has been executed. Which means - that RX and LOCK_ADDR should be cleared. But there are a - few exceptions for traps internal to QEMU. */ - if (arch_interrupt) { - env->flags &=3D ~ENV_FLAG_RX_FLAG; - env->lock_addr =3D -1; - } - } -} -#endif /* TARGET_ALPHA */ - #ifdef TARGET_S390X =20 /* s390x masks the fault address it reports in si_addr for SIGSEGV and SIG= BUS */ @@ -1914,16 +1720,6 @@ int main(int argc, char **argv, char **envp) env->pc =3D regs->sepc; env->gpr[xSP] =3D regs->sp; } -#elif defined(TARGET_ALPHA) - { - int i; - - for(i =3D 0; i < 28; i++) { - env->ir[i] =3D ((abi_ulong *)regs)[i]; - } - env->ir[IR_SP] =3D regs->usp; - env->pc =3D regs->pc; - } #elif defined(TARGET_S390X) { int i; --=20 2.14.3 From nobody Mon May 6 08:55:16 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1523474488610209.81387679091517; Wed, 11 Apr 2018 12:21:28 -0700 (PDT) Received: from localhost ([::1]:48975 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f6LJ9-0001cC-Km for importer@patchew.org; Wed, 11 Apr 2018 15:21:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38225) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f6KwF-0006GF-N7 for qemu-devel@nongnu.org; Wed, 11 Apr 2018 14:57:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f6KwD-00082N-5Q for qemu-devel@nongnu.org; Wed, 11 Apr 2018 14:57:47 -0400 Received: from mout.kundenserver.de ([217.72.192.74]:52063) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1f6Kw5-0007sV-D6; Wed, 11 Apr 2018 14:57:37 -0400 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue105 [212.227.15.183]) with ESMTPSA (Nemesis) id 0Lp6ay-1eaYwn3RkS-00euk8; Wed, 11 Apr 2018 20:57:22 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Date: Wed, 11 Apr 2018 20:56:47 +0200 Message-Id: <20180411185651.21351-16-laurent@vivier.eu> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180411185651.21351-1-laurent@vivier.eu> References: <20180411185651.21351-1-laurent@vivier.eu> X-Provags-ID: V03:K1:H2/GhzeZaEoyIb/556hMmEUadGr6CK5PVPhFdG2KrEwfk7ICxpy iJU4DvPluJLP7PMVDWa4ZclL4PUizWBzyZvCXGd6/PlQSsqQdrzP2hyixKLh6LISsJwu/+b QQUU03GR2DSXUQF4fCwCuC8hZYuZ/OSc5lqbxZrVmBPv5savAvzqE7kaE6w7IBpeXfAMHFE 8XBHNlC3Fmij3vESN2RcQ== X-UI-Out-Filterresults: notjunk:1;V01:K0:XylAZH4r1Dg=:16tWAtgMJplw9Y6MgrxKLZ CzUnj3eCoGOn6DIbRnOgJuw7C/j5+K9DPN3EWg1haHbUteaqACq3o6FBxsgdi4ftcY+ec5fxM WXrNk9asQr+5IEaYj7m2QTVCjgEHJl/3agvBipUkVDb7wJu3MQawMwXa6QKiaR2iuKioNbf+l /ukHMAbdXUTmgsUUVEdV/f2yjMSORBxhexYlhGEEGJC1MZRQNyVdD8QPVacMn0JLfM9UJT0L3 /BVejl3XFBgid44sC2p8FN0zOm+d2+Evex9qJqSGyUrBD1IG86Ygaf4XuEqZ50gocMe2NKWtk ZyB/mN+WCxuwAq5IE9WqsQZmR2hPx3ENVg0WbGFVyUBT9Drji7PZ/a4rH++rNBTZGlMbMYhmx EU6OEioDDxtHw/eBzXVvtz7sm8/5oY9wNOK9pkkNm6CRR4dgaD+N+Qm5BKwHL7GnjEDCLFD/N rRsLnB0mxqDRPbuH644t4zUAJbPvZ7ZRuPBybqlLZ02HVN96Stmyg0LgdXYFeBx2yTDJsbtQp lukLU2lon0jxVSf2RRYN025e/E5rHUx231v4XvvwDOJcfTZ74hG0VwwZJ/sHDWjmLp3jXXC1r tUEfBZj7yDDGmeBUx1DVjhywaQdx6ccDBXAq68xAttxmFZcmJi3A2GnAUPlcpoOxdQqIJGcnH 3h3nNLYw1aUI/zAKHpDbAfBG35Xowpx4FOin9jL8W0tQlDwhx6dkEjoeioHWNo74ZNSLbBp5q /uRBYuo6YQKMxXZ7HVCRP/wyGx+2erGmrtEJXQ== X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 217.72.192.74 Subject: [Qemu-devel] [PATCH for 2.13 v2 15/19] linux-user: move s390x cpu loop to s390x directory X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Cornelia Huck , Riku Voipio , Richard Henderson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Laurent Vivier , qemu-s390x@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" No code change, only move code from main.c to s390x/cpu_loop.c. Signed-off-by: Laurent Vivier Reviewed-by: Richard Henderson Acked-by: Cornelia Huck Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- linux-user/main.c | 146 ----------------------------------------= ---- linux-user/s390x/cpu_loop.c | 139 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 139 insertions(+), 146 deletions(-) diff --git a/linux-user/main.c b/linux-user/main.c index 37cf3a7d6f..7f6cfa5548 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -149,143 +149,6 @@ void fork_end(int child) } } =20 -#ifdef TARGET_S390X - -/* s390x masks the fault address it reports in si_addr for SIGSEGV and SIG= BUS */ -#define S390X_FAIL_ADDR_MASK -4096LL - -void cpu_loop(CPUS390XState *env) -{ - CPUState *cs =3D CPU(s390_env_get_cpu(env)); - int trapnr, n, sig; - target_siginfo_t info; - target_ulong addr; - abi_long ret; - - while (1) { - cpu_exec_start(cs); - trapnr =3D cpu_exec(cs); - cpu_exec_end(cs); - process_queued_cpu_work(cs); - - switch (trapnr) { - case EXCP_INTERRUPT: - /* Just indicate that signals should be handled asap. */ - break; - - case EXCP_SVC: - n =3D env->int_svc_code; - if (!n) { - /* syscalls > 255 */ - n =3D env->regs[1]; - } - env->psw.addr +=3D env->int_svc_ilen; - ret =3D do_syscall(env, n, env->regs[2], env->regs[3], - env->regs[4], env->regs[5], - env->regs[6], env->regs[7], 0, 0); - if (ret =3D=3D -TARGET_ERESTARTSYS) { - env->psw.addr -=3D env->int_svc_ilen; - } else if (ret !=3D -TARGET_QEMU_ESIGRETURN) { - env->regs[2] =3D ret; - } - break; - - case EXCP_DEBUG: - sig =3D gdb_handlesig(cs, TARGET_SIGTRAP); - if (sig) { - n =3D TARGET_TRAP_BRKPT; - goto do_signal_pc; - } - break; - case EXCP_PGM: - n =3D env->int_pgm_code; - switch (n) { - case PGM_OPERATION: - case PGM_PRIVILEGED: - sig =3D TARGET_SIGILL; - n =3D TARGET_ILL_ILLOPC; - goto do_signal_pc; - case PGM_PROTECTION: - case PGM_ADDRESSING: - sig =3D TARGET_SIGSEGV; - /* XXX: check env->error_code */ - n =3D TARGET_SEGV_MAPERR; - addr =3D env->__excp_addr & S390X_FAIL_ADDR_MASK; - goto do_signal; - case PGM_EXECUTE: - case PGM_SPECIFICATION: - case PGM_SPECIAL_OP: - case PGM_OPERAND: - do_sigill_opn: - sig =3D TARGET_SIGILL; - n =3D TARGET_ILL_ILLOPN; - goto do_signal_pc; - - case PGM_FIXPT_OVERFLOW: - sig =3D TARGET_SIGFPE; - n =3D TARGET_FPE_INTOVF; - goto do_signal_pc; - case PGM_FIXPT_DIVIDE: - sig =3D TARGET_SIGFPE; - n =3D TARGET_FPE_INTDIV; - goto do_signal_pc; - - case PGM_DATA: - n =3D (env->fpc >> 8) & 0xff; - if (n =3D=3D 0xff) { - /* compare-and-trap */ - goto do_sigill_opn; - } else { - /* An IEEE exception, simulated or otherwise. */ - if (n & 0x80) { - n =3D TARGET_FPE_FLTINV; - } else if (n & 0x40) { - n =3D TARGET_FPE_FLTDIV; - } else if (n & 0x20) { - n =3D TARGET_FPE_FLTOVF; - } else if (n & 0x10) { - n =3D TARGET_FPE_FLTUND; - } else if (n & 0x08) { - n =3D TARGET_FPE_FLTRES; - } else { - /* ??? Quantum exception; BFP, DFP error. */ - goto do_sigill_opn; - } - sig =3D TARGET_SIGFPE; - goto do_signal_pc; - } - - default: - fprintf(stderr, "Unhandled program exception: %#x\n", n); - cpu_dump_state(cs, stderr, fprintf, 0); - exit(EXIT_FAILURE); - } - break; - - do_signal_pc: - addr =3D env->psw.addr; - do_signal: - info.si_signo =3D sig; - info.si_errno =3D 0; - info.si_code =3D n; - info._sifields._sigfault._addr =3D addr; - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); - break; - - case EXCP_ATOMIC: - cpu_exec_step_atomic(cs); - break; - default: - fprintf(stderr, "Unhandled trap: 0x%x\n", trapnr); - cpu_dump_state(cs, stderr, fprintf, 0); - exit(EXIT_FAILURE); - } - process_pending_signals (env); - } -} - -#endif /* TARGET_S390X */ - #ifdef TARGET_TILEGX =20 static void gen_sigill_reg(CPUTLGState *env) @@ -1720,15 +1583,6 @@ int main(int argc, char **argv, char **envp) env->pc =3D regs->sepc; env->gpr[xSP] =3D regs->sp; } -#elif defined(TARGET_S390X) - { - int i; - for (i =3D 0; i < 16; i++) { - env->regs[i] =3D regs->gprs[i]; - } - env->psw.mask =3D regs->psw.mask; - env->psw.addr =3D regs->psw.addr; - } #elif defined(TARGET_TILEGX) { int i; diff --git a/linux-user/s390x/cpu_loop.c b/linux-user/s390x/cpu_loop.c index b7700a5561..99f5f1594f 100644 --- a/linux-user/s390x/cpu_loop.c +++ b/linux-user/s390x/cpu_loop.c @@ -21,6 +21,145 @@ #include "qemu.h" #include "cpu_loop-common.h" =20 +/* s390x masks the fault address it reports in si_addr for SIGSEGV and SIG= BUS */ +#define S390X_FAIL_ADDR_MASK -4096LL + +void cpu_loop(CPUS390XState *env) +{ + CPUState *cs =3D CPU(s390_env_get_cpu(env)); + int trapnr, n, sig; + target_siginfo_t info; + target_ulong addr; + abi_long ret; + + while (1) { + cpu_exec_start(cs); + trapnr =3D cpu_exec(cs); + cpu_exec_end(cs); + process_queued_cpu_work(cs); + + switch (trapnr) { + case EXCP_INTERRUPT: + /* Just indicate that signals should be handled asap. */ + break; + + case EXCP_SVC: + n =3D env->int_svc_code; + if (!n) { + /* syscalls > 255 */ + n =3D env->regs[1]; + } + env->psw.addr +=3D env->int_svc_ilen; + ret =3D do_syscall(env, n, env->regs[2], env->regs[3], + env->regs[4], env->regs[5], + env->regs[6], env->regs[7], 0, 0); + if (ret =3D=3D -TARGET_ERESTARTSYS) { + env->psw.addr -=3D env->int_svc_ilen; + } else if (ret !=3D -TARGET_QEMU_ESIGRETURN) { + env->regs[2] =3D ret; + } + break; + + case EXCP_DEBUG: + sig =3D gdb_handlesig(cs, TARGET_SIGTRAP); + if (sig) { + n =3D TARGET_TRAP_BRKPT; + goto do_signal_pc; + } + break; + case EXCP_PGM: + n =3D env->int_pgm_code; + switch (n) { + case PGM_OPERATION: + case PGM_PRIVILEGED: + sig =3D TARGET_SIGILL; + n =3D TARGET_ILL_ILLOPC; + goto do_signal_pc; + case PGM_PROTECTION: + case PGM_ADDRESSING: + sig =3D TARGET_SIGSEGV; + /* XXX: check env->error_code */ + n =3D TARGET_SEGV_MAPERR; + addr =3D env->__excp_addr & S390X_FAIL_ADDR_MASK; + goto do_signal; + case PGM_EXECUTE: + case PGM_SPECIFICATION: + case PGM_SPECIAL_OP: + case PGM_OPERAND: + do_sigill_opn: + sig =3D TARGET_SIGILL; + n =3D TARGET_ILL_ILLOPN; + goto do_signal_pc; + + case PGM_FIXPT_OVERFLOW: + sig =3D TARGET_SIGFPE; + n =3D TARGET_FPE_INTOVF; + goto do_signal_pc; + case PGM_FIXPT_DIVIDE: + sig =3D TARGET_SIGFPE; + n =3D TARGET_FPE_INTDIV; + goto do_signal_pc; + + case PGM_DATA: + n =3D (env->fpc >> 8) & 0xff; + if (n =3D=3D 0xff) { + /* compare-and-trap */ + goto do_sigill_opn; + } else { + /* An IEEE exception, simulated or otherwise. */ + if (n & 0x80) { + n =3D TARGET_FPE_FLTINV; + } else if (n & 0x40) { + n =3D TARGET_FPE_FLTDIV; + } else if (n & 0x20) { + n =3D TARGET_FPE_FLTOVF; + } else if (n & 0x10) { + n =3D TARGET_FPE_FLTUND; + } else if (n & 0x08) { + n =3D TARGET_FPE_FLTRES; + } else { + /* ??? Quantum exception; BFP, DFP error. */ + goto do_sigill_opn; + } + sig =3D TARGET_SIGFPE; + goto do_signal_pc; + } + + default: + fprintf(stderr, "Unhandled program exception: %#x\n", n); + cpu_dump_state(cs, stderr, fprintf, 0); + exit(EXIT_FAILURE); + } + break; + + do_signal_pc: + addr =3D env->psw.addr; + do_signal: + info.si_signo =3D sig; + info.si_errno =3D 0; + info.si_code =3D n; + info._sifields._sigfault._addr =3D addr; + queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + break; + + case EXCP_ATOMIC: + cpu_exec_step_atomic(cs); + break; + default: + fprintf(stderr, "Unhandled trap: 0x%x\n", trapnr); + cpu_dump_state(cs, stderr, fprintf, 0); + exit(EXIT_FAILURE); + } + process_pending_signals (env); + } +} + void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs) { + int i; + for (i =3D 0; i < 16; i++) { + env->regs[i] =3D regs->gprs[i]; + } + env->psw.mask =3D regs->psw.mask; + env->psw.addr =3D regs->psw.addr; } --=20 2.14.3 From nobody Mon May 6 08:55:16 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1523475845563201.65913521744426; Wed, 11 Apr 2018 12:44:05 -0700 (PDT) Received: from localhost ([::1]:51073 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f6Lex-0005aV-GJ for importer@patchew.org; Wed, 11 Apr 2018 15:43:59 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38196) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f6KwD-0006D7-Su for qemu-devel@nongnu.org; Wed, 11 Apr 2018 14:57:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f6Kw8-0007vX-29 for qemu-devel@nongnu.org; Wed, 11 Apr 2018 14:57:45 -0400 Received: from mout.kundenserver.de ([212.227.17.10]:40231) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1f6Kw7-0007ue-DL; Wed, 11 Apr 2018 14:57:39 -0400 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue105 [212.227.15.183]) with ESMTPSA (Nemesis) id 0LoIBN-1eZj4N2zmL-00gHmj; Wed, 11 Apr 2018 20:57:23 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Date: Wed, 11 Apr 2018 20:56:48 +0200 Message-Id: <20180411185651.21351-17-laurent@vivier.eu> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180411185651.21351-1-laurent@vivier.eu> References: <20180411185651.21351-1-laurent@vivier.eu> X-Provags-ID: V03:K1:JpyLnEuPI3q6xbPk92FD6zxoaOMElG0wmMiVcmLl4P5HSV0DSb5 8yowvch9tFOOWsTWEVDSKL/PFyI7plm4IsbkDkW9QfYo9ylKvY50ps/9BZQZNaLUVJvpNrL fsozFCrJMIrQWK8NuDG1ZAaLC/+B8MNIqZFc/u+KxrnBfRHPOx2UbHG1RtRYLLZHdrgy2ZV AZ7PcBJ/kuM/tVuQIaRTg== X-UI-Out-Filterresults: notjunk:1;V01:K0:A3KvpyyP9VI=:FlXEimwB+1llyy8mClKx8M 6aw2aB4a4xUH5aE0pkfTe1VIeHQvwNdG861zeQcTOyw9c/MfKK2d/HEdn9VKGKflvYTn1zlar Iap3JQTb/j7lH072KqqTjJYGFabPLYHr7LfoP2DBjU8sXz0ziOGo5V6gKAYwgyiYJtnSR4K01 9wJambrU5oc2GwSolgCM1K1sTRyNIoYs735B+UDS2/36/sbLvcsgoZIHrkbPqXn1bfrusQwNh FXlcLOwAnubQAfBmv+cZxK4BV5pQ+JWZ0gV9/S+h74wVHUhHMpSb6Ai0tOWSgzyWnJXtoEXzz 2NX7sdZ6f9+/LirtTHZLmEKryP3UdIltGgoYtFWEetBh9c+nL06/WcvyYrbCsJVAnr8N9ua7Z pf1vgV+eeFm/G89FxIw8RU2Z1tc8iIZIJ5kAzjiB1BdBGaeWQUWtHqwq0MY51jGclACI3Cqq1 +02MKzuyWjfdN06a+P97QRXfubBPWx61/KEi/INYIqHMIYF4aXJ7E0yx4PhBtFJ5jAqS+7HR4 N1Mm5I0DbBYZAaaateRDwpjI6DzvJ9qGlyBMBhwTM5P0VM2MhJP96Fdi0CxTNLJc8+g0munmc Zhi99T5BE/AlYshoKe3sWE1raUOkkEpi7lbSaAi8quD/yDhNXfA0GdQ7Cs2G+nnVuPdlxGuMW SWzkU0o0/Nz0klHZ0G8oQs4Z4KjRDsrFFNxjVqCQVbwS5CDUo38t6m61GZAg+afzGOAHs7XMw L5zNEliTbjVdUI6I5SXzCocYUZMPRTRHvd+ygw== X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 212.227.17.10 Subject: [Qemu-devel] [PATCH for 2.13 v2 16/19] linux-user: move tilegx cpu loop to tilegx directory X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Cornelia Huck , Riku Voipio , Richard Henderson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Laurent Vivier , qemu-s390x@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" No code change, only move code from main.c to tilegx/cpu_loop.c. Signed-off-by: Laurent Vivier Reviewed-by: Richard Henderson --- linux-user/main.c | 267 ---------------------------------------= ---- linux-user/tilegx/cpu_loop.c | 260 +++++++++++++++++++++++++++++++++++++++= ++ 2 files changed, 260 insertions(+), 267 deletions(-) diff --git a/linux-user/main.c b/linux-user/main.c index 7f6cfa5548..32922110f1 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -149,262 +149,6 @@ void fork_end(int child) } } =20 -#ifdef TARGET_TILEGX - -static void gen_sigill_reg(CPUTLGState *env) -{ - target_siginfo_t info; - - info.si_signo =3D TARGET_SIGILL; - info.si_errno =3D 0; - info.si_code =3D TARGET_ILL_PRVREG; - info._sifields._sigfault._addr =3D env->pc; - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); -} - -static void do_signal(CPUTLGState *env, int signo, int sigcode) -{ - target_siginfo_t info; - - info.si_signo =3D signo; - info.si_errno =3D 0; - info._sifields._sigfault._addr =3D env->pc; - - if (signo =3D=3D TARGET_SIGSEGV) { - /* The passed in sigcode is a dummy; check for a page mapping - and pass either MAPERR or ACCERR. */ - target_ulong addr =3D env->excaddr; - info._sifields._sigfault._addr =3D addr; - if (page_check_range(addr, 1, PAGE_VALID) < 0) { - sigcode =3D TARGET_SEGV_MAPERR; - } else { - sigcode =3D TARGET_SEGV_ACCERR; - } - } - info.si_code =3D sigcode; - - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); -} - -static void gen_sigsegv_maperr(CPUTLGState *env, target_ulong addr) -{ - env->excaddr =3D addr; - do_signal(env, TARGET_SIGSEGV, 0); -} - -static void set_regval(CPUTLGState *env, uint8_t reg, uint64_t val) -{ - if (unlikely(reg >=3D TILEGX_R_COUNT)) { - switch (reg) { - case TILEGX_R_SN: - case TILEGX_R_ZERO: - return; - case TILEGX_R_IDN0: - case TILEGX_R_IDN1: - case TILEGX_R_UDN0: - case TILEGX_R_UDN1: - case TILEGX_R_UDN2: - case TILEGX_R_UDN3: - gen_sigill_reg(env); - return; - default: - g_assert_not_reached(); - } - } - env->regs[reg] =3D val; -} - -/* - * Compare the 8-byte contents of the CmpValue SPR with the 8-byte value in - * memory at the address held in the first source register. If the values = are - * not equal, then no memory operation is performed. If the values are equ= al, - * the 8-byte quantity from the second source register is written into mem= ory - * at the address held in the first source register. In either case, the r= esult - * of the instruction is the value read from memory. The compare and write= to - * memory are atomic and thus can be used for synchronization purposes. Th= is - * instruction only operates for addresses aligned to a 8-byte boundary. - * Unaligned memory access causes an Unaligned Data Reference interrupt. - * - * Functional Description (64-bit) - * uint64_t memVal =3D memoryReadDoubleWord (rf[SrcA]); - * rf[Dest] =3D memVal; - * if (memVal =3D=3D SPR[CmpValueSPR]) - * memoryWriteDoubleWord (rf[SrcA], rf[SrcB]); - * - * Functional Description (32-bit) - * uint64_t memVal =3D signExtend32 (memoryReadWord (rf[SrcA])); - * rf[Dest] =3D memVal; - * if (memVal =3D=3D signExtend32 (SPR[CmpValueSPR])) - * memoryWriteWord (rf[SrcA], rf[SrcB]); - * - * - * This function also processes exch and exch4 which need not process SPR. - */ -static void do_exch(CPUTLGState *env, bool quad, bool cmp) -{ - target_ulong addr; - target_long val, sprval; - - start_exclusive(); - - addr =3D env->atomic_srca; - if (quad ? get_user_s64(val, addr) : get_user_s32(val, addr)) { - goto sigsegv_maperr; - } - - if (cmp) { - if (quad) { - sprval =3D env->spregs[TILEGX_SPR_CMPEXCH]; - } else { - sprval =3D sextract64(env->spregs[TILEGX_SPR_CMPEXCH], 0, 32); - } - } - - if (!cmp || val =3D=3D sprval) { - target_long valb =3D env->atomic_srcb; - if (quad ? put_user_u64(valb, addr) : put_user_u32(valb, addr)) { - goto sigsegv_maperr; - } - } - - set_regval(env, env->atomic_dstr, val); - end_exclusive(); - return; - - sigsegv_maperr: - end_exclusive(); - gen_sigsegv_maperr(env, addr); -} - -static void do_fetch(CPUTLGState *env, int trapnr, bool quad) -{ - int8_t write =3D 1; - target_ulong addr; - target_long val, valb; - - start_exclusive(); - - addr =3D env->atomic_srca; - valb =3D env->atomic_srcb; - if (quad ? get_user_s64(val, addr) : get_user_s32(val, addr)) { - goto sigsegv_maperr; - } - - switch (trapnr) { - case TILEGX_EXCP_OPCODE_FETCHADD: - case TILEGX_EXCP_OPCODE_FETCHADD4: - valb +=3D val; - break; - case TILEGX_EXCP_OPCODE_FETCHADDGEZ: - valb +=3D val; - if (valb < 0) { - write =3D 0; - } - break; - case TILEGX_EXCP_OPCODE_FETCHADDGEZ4: - valb +=3D val; - if ((int32_t)valb < 0) { - write =3D 0; - } - break; - case TILEGX_EXCP_OPCODE_FETCHAND: - case TILEGX_EXCP_OPCODE_FETCHAND4: - valb &=3D val; - break; - case TILEGX_EXCP_OPCODE_FETCHOR: - case TILEGX_EXCP_OPCODE_FETCHOR4: - valb |=3D val; - break; - default: - g_assert_not_reached(); - } - - if (write) { - if (quad ? put_user_u64(valb, addr) : put_user_u32(valb, addr)) { - goto sigsegv_maperr; - } - } - - set_regval(env, env->atomic_dstr, val); - end_exclusive(); - return; - - sigsegv_maperr: - end_exclusive(); - gen_sigsegv_maperr(env, addr); -} - -void cpu_loop(CPUTLGState *env) -{ - CPUState *cs =3D CPU(tilegx_env_get_cpu(env)); - int trapnr; - - while (1) { - cpu_exec_start(cs); - trapnr =3D cpu_exec(cs); - cpu_exec_end(cs); - process_queued_cpu_work(cs); - - switch (trapnr) { - case TILEGX_EXCP_SYSCALL: - { - abi_ulong ret =3D do_syscall(env, env->regs[TILEGX_R_NR], - env->regs[0], env->regs[1], - env->regs[2], env->regs[3], - env->regs[4], env->regs[5], - env->regs[6], env->regs[7]); - if (ret =3D=3D -TARGET_ERESTARTSYS) { - env->pc -=3D 8; - } else if (ret !=3D -TARGET_QEMU_ESIGRETURN) { - env->regs[TILEGX_R_RE] =3D ret; - env->regs[TILEGX_R_ERR] =3D TILEGX_IS_ERRNO(ret) ? -ret : = 0; - } - break; - } - case TILEGX_EXCP_OPCODE_EXCH: - do_exch(env, true, false); - break; - case TILEGX_EXCP_OPCODE_EXCH4: - do_exch(env, false, false); - break; - case TILEGX_EXCP_OPCODE_CMPEXCH: - do_exch(env, true, true); - break; - case TILEGX_EXCP_OPCODE_CMPEXCH4: - do_exch(env, false, true); - break; - case TILEGX_EXCP_OPCODE_FETCHADD: - case TILEGX_EXCP_OPCODE_FETCHADDGEZ: - case TILEGX_EXCP_OPCODE_FETCHAND: - case TILEGX_EXCP_OPCODE_FETCHOR: - do_fetch(env, trapnr, true); - break; - case TILEGX_EXCP_OPCODE_FETCHADD4: - case TILEGX_EXCP_OPCODE_FETCHADDGEZ4: - case TILEGX_EXCP_OPCODE_FETCHAND4: - case TILEGX_EXCP_OPCODE_FETCHOR4: - do_fetch(env, trapnr, false); - break; - case TILEGX_EXCP_SIGNAL: - do_signal(env, env->signo, env->sigcode); - break; - case TILEGX_EXCP_REG_IDN_ACCESS: - case TILEGX_EXCP_REG_UDN_ACCESS: - gen_sigill_reg(env); - break; - case EXCP_ATOMIC: - cpu_exec_step_atomic(cs); - break; - default: - fprintf(stderr, "trapnr is %d[0x%x].\n", trapnr, trapnr); - g_assert_not_reached(); - } - process_pending_signals(env); - } -} - -#endif - #ifdef TARGET_RISCV =20 void cpu_loop(CPURISCVState *env) @@ -1583,17 +1327,6 @@ int main(int argc, char **argv, char **envp) env->pc =3D regs->sepc; env->gpr[xSP] =3D regs->sp; } -#elif defined(TARGET_TILEGX) - { - int i; - for (i =3D 0; i < TILEGX_R_COUNT; i++) { - env->regs[i] =3D regs->regs[i]; - } - for (i =3D 0; i < TILEGX_SPR_COUNT; i++) { - env->spregs[i] =3D 0; - } - env->pc =3D regs->pc; - } #elif defined(TARGET_HPPA) { int i; diff --git a/linux-user/tilegx/cpu_loop.c b/linux-user/tilegx/cpu_loop.c index b7700a5561..4f39eb9ad3 100644 --- a/linux-user/tilegx/cpu_loop.c +++ b/linux-user/tilegx/cpu_loop.c @@ -21,6 +21,266 @@ #include "qemu.h" #include "cpu_loop-common.h" =20 +static void gen_sigill_reg(CPUTLGState *env) +{ + target_siginfo_t info; + + info.si_signo =3D TARGET_SIGILL; + info.si_errno =3D 0; + info.si_code =3D TARGET_ILL_PRVREG; + info._sifields._sigfault._addr =3D env->pc; + queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); +} + +static void do_signal(CPUTLGState *env, int signo, int sigcode) +{ + target_siginfo_t info; + + info.si_signo =3D signo; + info.si_errno =3D 0; + info._sifields._sigfault._addr =3D env->pc; + + if (signo =3D=3D TARGET_SIGSEGV) { + /* The passed in sigcode is a dummy; check for a page mapping + and pass either MAPERR or ACCERR. */ + target_ulong addr =3D env->excaddr; + info._sifields._sigfault._addr =3D addr; + if (page_check_range(addr, 1, PAGE_VALID) < 0) { + sigcode =3D TARGET_SEGV_MAPERR; + } else { + sigcode =3D TARGET_SEGV_ACCERR; + } + } + info.si_code =3D sigcode; + + queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); +} + +static void gen_sigsegv_maperr(CPUTLGState *env, target_ulong addr) +{ + env->excaddr =3D addr; + do_signal(env, TARGET_SIGSEGV, 0); +} + +static void set_regval(CPUTLGState *env, uint8_t reg, uint64_t val) +{ + if (unlikely(reg >=3D TILEGX_R_COUNT)) { + switch (reg) { + case TILEGX_R_SN: + case TILEGX_R_ZERO: + return; + case TILEGX_R_IDN0: + case TILEGX_R_IDN1: + case TILEGX_R_UDN0: + case TILEGX_R_UDN1: + case TILEGX_R_UDN2: + case TILEGX_R_UDN3: + gen_sigill_reg(env); + return; + default: + g_assert_not_reached(); + } + } + env->regs[reg] =3D val; +} + +/* + * Compare the 8-byte contents of the CmpValue SPR with the 8-byte value in + * memory at the address held in the first source register. If the values = are + * not equal, then no memory operation is performed. If the values are equ= al, + * the 8-byte quantity from the second source register is written into mem= ory + * at the address held in the first source register. In either case, the r= esult + * of the instruction is the value read from memory. The compare and write= to + * memory are atomic and thus can be used for synchronization purposes. Th= is + * instruction only operates for addresses aligned to a 8-byte boundary. + * Unaligned memory access causes an Unaligned Data Reference interrupt. + * + * Functional Description (64-bit) + * uint64_t memVal =3D memoryReadDoubleWord (rf[SrcA]); + * rf[Dest] =3D memVal; + * if (memVal =3D=3D SPR[CmpValueSPR]) + * memoryWriteDoubleWord (rf[SrcA], rf[SrcB]); + * + * Functional Description (32-bit) + * uint64_t memVal =3D signExtend32 (memoryReadWord (rf[SrcA])); + * rf[Dest] =3D memVal; + * if (memVal =3D=3D signExtend32 (SPR[CmpValueSPR])) + * memoryWriteWord (rf[SrcA], rf[SrcB]); + * + * + * This function also processes exch and exch4 which need not process SPR. + */ +static void do_exch(CPUTLGState *env, bool quad, bool cmp) +{ + target_ulong addr; + target_long val, sprval; + + start_exclusive(); + + addr =3D env->atomic_srca; + if (quad ? get_user_s64(val, addr) : get_user_s32(val, addr)) { + goto sigsegv_maperr; + } + + if (cmp) { + if (quad) { + sprval =3D env->spregs[TILEGX_SPR_CMPEXCH]; + } else { + sprval =3D sextract64(env->spregs[TILEGX_SPR_CMPEXCH], 0, 32); + } + } + + if (!cmp || val =3D=3D sprval) { + target_long valb =3D env->atomic_srcb; + if (quad ? put_user_u64(valb, addr) : put_user_u32(valb, addr)) { + goto sigsegv_maperr; + } + } + + set_regval(env, env->atomic_dstr, val); + end_exclusive(); + return; + + sigsegv_maperr: + end_exclusive(); + gen_sigsegv_maperr(env, addr); +} + +static void do_fetch(CPUTLGState *env, int trapnr, bool quad) +{ + int8_t write =3D 1; + target_ulong addr; + target_long val, valb; + + start_exclusive(); + + addr =3D env->atomic_srca; + valb =3D env->atomic_srcb; + if (quad ? get_user_s64(val, addr) : get_user_s32(val, addr)) { + goto sigsegv_maperr; + } + + switch (trapnr) { + case TILEGX_EXCP_OPCODE_FETCHADD: + case TILEGX_EXCP_OPCODE_FETCHADD4: + valb +=3D val; + break; + case TILEGX_EXCP_OPCODE_FETCHADDGEZ: + valb +=3D val; + if (valb < 0) { + write =3D 0; + } + break; + case TILEGX_EXCP_OPCODE_FETCHADDGEZ4: + valb +=3D val; + if ((int32_t)valb < 0) { + write =3D 0; + } + break; + case TILEGX_EXCP_OPCODE_FETCHAND: + case TILEGX_EXCP_OPCODE_FETCHAND4: + valb &=3D val; + break; + case TILEGX_EXCP_OPCODE_FETCHOR: + case TILEGX_EXCP_OPCODE_FETCHOR4: + valb |=3D val; + break; + default: + g_assert_not_reached(); + } + + if (write) { + if (quad ? put_user_u64(valb, addr) : put_user_u32(valb, addr)) { + goto sigsegv_maperr; + } + } + + set_regval(env, env->atomic_dstr, val); + end_exclusive(); + return; + + sigsegv_maperr: + end_exclusive(); + gen_sigsegv_maperr(env, addr); +} + +void cpu_loop(CPUTLGState *env) +{ + CPUState *cs =3D CPU(tilegx_env_get_cpu(env)); + int trapnr; + + while (1) { + cpu_exec_start(cs); + trapnr =3D cpu_exec(cs); + cpu_exec_end(cs); + process_queued_cpu_work(cs); + + switch (trapnr) { + case TILEGX_EXCP_SYSCALL: + { + abi_ulong ret =3D do_syscall(env, env->regs[TILEGX_R_NR], + env->regs[0], env->regs[1], + env->regs[2], env->regs[3], + env->regs[4], env->regs[5], + env->regs[6], env->regs[7]); + if (ret =3D=3D -TARGET_ERESTARTSYS) { + env->pc -=3D 8; + } else if (ret !=3D -TARGET_QEMU_ESIGRETURN) { + env->regs[TILEGX_R_RE] =3D ret; + env->regs[TILEGX_R_ERR] =3D TILEGX_IS_ERRNO(ret) ? -ret : = 0; + } + break; + } + case TILEGX_EXCP_OPCODE_EXCH: + do_exch(env, true, false); + break; + case TILEGX_EXCP_OPCODE_EXCH4: + do_exch(env, false, false); + break; + case TILEGX_EXCP_OPCODE_CMPEXCH: + do_exch(env, true, true); + break; + case TILEGX_EXCP_OPCODE_CMPEXCH4: + do_exch(env, false, true); + break; + case TILEGX_EXCP_OPCODE_FETCHADD: + case TILEGX_EXCP_OPCODE_FETCHADDGEZ: + case TILEGX_EXCP_OPCODE_FETCHAND: + case TILEGX_EXCP_OPCODE_FETCHOR: + do_fetch(env, trapnr, true); + break; + case TILEGX_EXCP_OPCODE_FETCHADD4: + case TILEGX_EXCP_OPCODE_FETCHADDGEZ4: + case TILEGX_EXCP_OPCODE_FETCHAND4: + case TILEGX_EXCP_OPCODE_FETCHOR4: + do_fetch(env, trapnr, false); + break; + case TILEGX_EXCP_SIGNAL: + do_signal(env, env->signo, env->sigcode); + break; + case TILEGX_EXCP_REG_IDN_ACCESS: + case TILEGX_EXCP_REG_UDN_ACCESS: + gen_sigill_reg(env); + break; + case EXCP_ATOMIC: + cpu_exec_step_atomic(cs); + break; + default: + fprintf(stderr, "trapnr is %d[0x%x].\n", trapnr, trapnr); + g_assert_not_reached(); + } + process_pending_signals(env); + } +} + void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs) { + int i; + for (i =3D 0; i < TILEGX_R_COUNT; i++) { + env->regs[i] =3D regs->regs[i]; + } + for (i =3D 0; i < TILEGX_SPR_COUNT; i++) { + env->spregs[i] =3D 0; + } + env->pc =3D regs->pc; } --=20 2.14.3 From nobody Mon May 6 08:55:16 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1523476010967598.2075620799442; Wed, 11 Apr 2018 12:46:50 -0700 (PDT) Received: from localhost ([::1]:51267 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f6LhZ-00084R-Ay for importer@patchew.org; Wed, 11 Apr 2018 15:46:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38254) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f6KwG-0006If-Si for qemu-devel@nongnu.org; Wed, 11 Apr 2018 14:57:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f6KwD-00082q-VF for qemu-devel@nongnu.org; Wed, 11 Apr 2018 14:57:48 -0400 Received: from mout.kundenserver.de ([217.72.192.74]:47917) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1f6Kw6-0007sk-1k; Wed, 11 Apr 2018 14:57:38 -0400 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue105 [212.227.15.183]) with ESMTPSA (Nemesis) id 0MXXx0-1f0EoX35EM-00WURi; Wed, 11 Apr 2018 20:57:24 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Date: Wed, 11 Apr 2018 20:56:49 +0200 Message-Id: <20180411185651.21351-18-laurent@vivier.eu> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180411185651.21351-1-laurent@vivier.eu> References: <20180411185651.21351-1-laurent@vivier.eu> X-Provags-ID: V03:K1:l4qdRb9BXhWZoMzHSSXml+zMZ0b9Pyr2FEuYmuJUDlBvTvR+3LB Pz/87GVFM8/boA5fhiZhboI5Awzs8W/aonJLmojAz4KwcQKWxRGS4WZvsNjHr9yibnM+l2N DjSr8KCn2vaqdwhXJnFdHTfpDCulTkoKbVUh+RWWLZ7/ASg7Qp5ZaYGx4uCuOaFsALwNKLi h1a6McfkOaLRpLdH+q1cA== X-UI-Out-Filterresults: notjunk:1;V01:K0:6UcSnwSgOAI=:aO2ahn8NZu8JG8Km+2Adtq rhNpJrEX6e1gXj99JNOVY5Px2HcC+SKXc3GzKODkfbMvg8KBYSwAT+hwSLpvFs5Uh9jkGpYQd RouPZSG04O4AcnTA8tFus+A6egN4EEbTmF3Ol4+/l2WiqWaCLUsGCY8QjsRlhUvgTQcklAeMR KDDSQx2kQrnBiOGLvXIxKEd/PNoqGIBXJx3aPGVOEL+6Qk+6A7sHjvTemunnjk4w+sNA0NJEP bzgiTE0RKjYgQrWcIn6L+UPTbz2K2nNvTJrd9u5GQ6KtSHlLSW00qFAarcyBpLgP2ovRW/NZ6 PshYps8S4PHv746ESZRR2Wyp9NJj1r86QLpBsDELyVfaAlosTDGnSVWHDXbLL0ID583oj6Nx4 b5Ub+PVuRR5D8bAxDTCJ0LMIgf6Q+5cuEG/NQyxXRaBrR052v9ODkPmpztHXpY98pDrLPZj8O s9TMwxRCtwwhQdpjpsWPRD4uY2hxK2w2GXMNsnCbp0fspgdtGzcSWngrhcinLhh+uMt94Tp1T E1DhQrZ7+mbKAkYakfspB+k8vcq7kvt8PpOs21HkVzMhvXD0bw3d6njtdaoJZUmBYgpDTqspD UjG60O+/PRG1d36fxh+o3FrELGeG+F1xzMSMC6eGdImiv+zTKKcA40BYHzWqg/BOVdM/GOWit /FGRT1Wsw8fY3nAlwk8XOzZBI58bH1p2TNDhEc6Qbc+khZk+LzDK0gXMVwDi+y1mKUvVXUNcy K5cg1uNNM1ClLcyVkwdXORL/TzWqPA4jLJtrug== X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 217.72.192.74 Subject: [Qemu-devel] [PATCH for 2.13 v2 17/19] linux-user: move riscv cpu loop to riscv directory X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Cornelia Huck , Riku Voipio , Richard Henderson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Laurent Vivier , qemu-s390x@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" No code change, only move code from main.c to riscv/cpu_loop.c. Signed-off-by: Laurent Vivier Reviewed-by: Richard Henderson Reviewed-by: Michael Clark Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- linux-user/main.c | 101 +---------------------------------------= ---- linux-user/riscv/cpu_loop.c | 92 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+), 100 deletions(-) diff --git a/linux-user/main.c b/linux-user/main.c index 32922110f1..834ec0bfe5 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -149,100 +149,6 @@ void fork_end(int child) } } =20 -#ifdef TARGET_RISCV - -void cpu_loop(CPURISCVState *env) -{ - CPUState *cs =3D CPU(riscv_env_get_cpu(env)); - int trapnr, signum, sigcode; - target_ulong sigaddr; - target_ulong ret; - - for (;;) { - cpu_exec_start(cs); - trapnr =3D cpu_exec(cs); - cpu_exec_end(cs); - process_queued_cpu_work(cs); - - signum =3D 0; - sigcode =3D 0; - sigaddr =3D 0; - - switch (trapnr) { - case EXCP_INTERRUPT: - /* just indicate that signals should be handled asap */ - break; - case EXCP_ATOMIC: - cpu_exec_step_atomic(cs); - break; - case RISCV_EXCP_U_ECALL: - env->pc +=3D 4; - if (env->gpr[xA7] =3D=3D TARGET_NR_arch_specific_syscall + 15)= { - /* riscv_flush_icache_syscall is a no-op in QEMU as - self-modifying code is automatically detected */ - ret =3D 0; - } else { - ret =3D do_syscall(env, - env->gpr[xA7], - env->gpr[xA0], - env->gpr[xA1], - env->gpr[xA2], - env->gpr[xA3], - env->gpr[xA4], - env->gpr[xA5], - 0, 0); - } - if (ret =3D=3D -TARGET_ERESTARTSYS) { - env->pc -=3D 4; - } else if (ret !=3D -TARGET_QEMU_ESIGRETURN) { - env->gpr[xA0] =3D ret; - } - if (cs->singlestep_enabled) { - goto gdbstep; - } - break; - case RISCV_EXCP_ILLEGAL_INST: - signum =3D TARGET_SIGILL; - sigcode =3D TARGET_ILL_ILLOPC; - break; - case RISCV_EXCP_BREAKPOINT: - signum =3D TARGET_SIGTRAP; - sigcode =3D TARGET_TRAP_BRKPT; - sigaddr =3D env->pc; - break; - case RISCV_EXCP_INST_PAGE_FAULT: - case RISCV_EXCP_LOAD_PAGE_FAULT: - case RISCV_EXCP_STORE_PAGE_FAULT: - signum =3D TARGET_SIGSEGV; - sigcode =3D TARGET_SEGV_MAPERR; - break; - case EXCP_DEBUG: - gdbstep: - signum =3D gdb_handlesig(cs, TARGET_SIGTRAP); - sigcode =3D TARGET_TRAP_BRKPT; - break; - default: - EXCP_DUMP(env, "\nqemu: unhandled CPU exception %#x - aborting= \n", - trapnr); - exit(EXIT_FAILURE); - } - - if (signum) { - target_siginfo_t info =3D { - .si_signo =3D signum, - .si_errno =3D 0, - .si_code =3D sigcode, - ._sifields._sigfault._addr =3D sigaddr - }; - queue_signal(env, info.si_signo, QEMU_SI_KILL, &info); - } - - process_pending_signals(env); - } -} - -#endif /* TARGET_RISCV */ - #ifdef TARGET_HPPA =20 static abi_ulong hppa_lws(CPUHPPAState *env) @@ -1322,12 +1228,7 @@ int main(int argc, char **argv, char **envp) =20 target_cpu_copy_regs(env, regs); =20 -#if defined(TARGET_RISCV) - { - env->pc =3D regs->sepc; - env->gpr[xSP] =3D regs->sp; - } -#elif defined(TARGET_HPPA) +#if defined(TARGET_HPPA) { int i; for (i =3D 1; i < 32; i++) { diff --git a/linux-user/riscv/cpu_loop.c b/linux-user/riscv/cpu_loop.c index b7700a5561..f137d39d7e 100644 --- a/linux-user/riscv/cpu_loop.c +++ b/linux-user/riscv/cpu_loop.c @@ -21,6 +21,98 @@ #include "qemu.h" #include "cpu_loop-common.h" =20 +void cpu_loop(CPURISCVState *env) +{ + CPUState *cs =3D CPU(riscv_env_get_cpu(env)); + int trapnr, signum, sigcode; + target_ulong sigaddr; + target_ulong ret; + + for (;;) { + cpu_exec_start(cs); + trapnr =3D cpu_exec(cs); + cpu_exec_end(cs); + process_queued_cpu_work(cs); + + signum =3D 0; + sigcode =3D 0; + sigaddr =3D 0; + + switch (trapnr) { + case EXCP_INTERRUPT: + /* just indicate that signals should be handled asap */ + break; + case EXCP_ATOMIC: + cpu_exec_step_atomic(cs); + break; + case RISCV_EXCP_U_ECALL: + env->pc +=3D 4; + if (env->gpr[xA7] =3D=3D TARGET_NR_arch_specific_syscall + 15)= { + /* riscv_flush_icache_syscall is a no-op in QEMU as + self-modifying code is automatically detected */ + ret =3D 0; + } else { + ret =3D do_syscall(env, + env->gpr[xA7], + env->gpr[xA0], + env->gpr[xA1], + env->gpr[xA2], + env->gpr[xA3], + env->gpr[xA4], + env->gpr[xA5], + 0, 0); + } + if (ret =3D=3D -TARGET_ERESTARTSYS) { + env->pc -=3D 4; + } else if (ret !=3D -TARGET_QEMU_ESIGRETURN) { + env->gpr[xA0] =3D ret; + } + if (cs->singlestep_enabled) { + goto gdbstep; + } + break; + case RISCV_EXCP_ILLEGAL_INST: + signum =3D TARGET_SIGILL; + sigcode =3D TARGET_ILL_ILLOPC; + break; + case RISCV_EXCP_BREAKPOINT: + signum =3D TARGET_SIGTRAP; + sigcode =3D TARGET_TRAP_BRKPT; + sigaddr =3D env->pc; + break; + case RISCV_EXCP_INST_PAGE_FAULT: + case RISCV_EXCP_LOAD_PAGE_FAULT: + case RISCV_EXCP_STORE_PAGE_FAULT: + signum =3D TARGET_SIGSEGV; + sigcode =3D TARGET_SEGV_MAPERR; + break; + case EXCP_DEBUG: + gdbstep: + signum =3D gdb_handlesig(cs, TARGET_SIGTRAP); + sigcode =3D TARGET_TRAP_BRKPT; + break; + default: + EXCP_DUMP(env, "\nqemu: unhandled CPU exception %#x - aborting= \n", + trapnr); + exit(EXIT_FAILURE); + } + + if (signum) { + target_siginfo_t info =3D { + .si_signo =3D signum, + .si_errno =3D 0, + .si_code =3D sigcode, + ._sifields._sigfault._addr =3D sigaddr + }; + queue_signal(env, info.si_signo, QEMU_SI_KILL, &info); + } + + process_pending_signals(env); + } +} + void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs) { + env->pc =3D regs->sepc; + env->gpr[xSP] =3D regs->sp; } --=20 2.14.3 From nobody Mon May 6 08:55:16 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1523475037296606.991311568131; Wed, 11 Apr 2018 12:30:37 -0700 (PDT) Received: from localhost ([::1]:49413 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f6LS0-0001A8-FG for importer@patchew.org; Wed, 11 Apr 2018 15:30:36 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38024) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f6Kw5-00065L-Qu for qemu-devel@nongnu.org; Wed, 11 Apr 2018 14:57:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f6Kw2-0007rX-Os for qemu-devel@nongnu.org; Wed, 11 Apr 2018 14:57:37 -0400 Received: from mout.kundenserver.de ([212.227.17.10]:39287) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1f6Kw2-0007qm-8Y; Wed, 11 Apr 2018 14:57:34 -0400 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue105 [212.227.15.183]) with ESMTPSA (Nemesis) id 0LkQIt-1eUn7v2Nwp-00cS2N; Wed, 11 Apr 2018 20:57:25 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Date: Wed, 11 Apr 2018 20:56:50 +0200 Message-Id: <20180411185651.21351-19-laurent@vivier.eu> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180411185651.21351-1-laurent@vivier.eu> References: <20180411185651.21351-1-laurent@vivier.eu> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:lMxU0AzJiBnwpNapLANHzLyyBfBGM8WzRaZ6+jrhEEPzDWcpIbk F4j2qlKfUhF5uvp5UCGMNCfzQMhHWfvUq2Wc7wBaD6XSw7gmKebb5axYIVz/uxmf5FFFaFi BT8Zyw3RbYCSj/NlhleVPNVYE+NbU0Gc8ptsmjQJ+7YMfFv2hqetWbxZE0Mf4I9WKq5C6SK wD/QLY3f5Qnmz9lFrnJfA== X-UI-Out-Filterresults: notjunk:1;V01:K0:pseWA0w6mRE=:zNeZnsjozNFOzd1acNWtbC pD0l7LpfetYyVgsObJHZj7WuRtF+eHYtaadumjGE6MWRq9kk+w5me8kZrvxjv3KlvUTOeG0Pp t9jmUa8IX8WPfJ9VAZ5Hq1MRsx57gSabQDLQqLz6qKXOtDlpPOukntwNChyXCeBXc1xFbmy1+ XrFrTVqEYcSJVDoUmJ7iOutOAy9iD36TeL6nCcVsK2D2FMQrOiGn0MrigqK1MbVo/cJ+oyNn0 RuSPdsulGn75Gg2wC2s8XrNZudNbZCfGLCQDkBeggtTld3qSzbqwNS3MqmdKDvdW8dBBXRH1l 5ARwciOZiFq5Cme+xIfDFR/QOrToGy/kRAYqu06b3BLYimZC8E/3hLYfyFiks+hJB9HJv2NY9 n8Xdh7H3X21T0ueWCwdWKZ9mtxawb1S7uVTU1GtvitG+8mFpYkXOji+qILJsxdh/gNYkY6gYy 7hDUOEcHYz1NCdJrIFlKu0wIhbHcQybjWjQPzHN3qk5+7nAOwVQ0w3nDwr8CcZZQlxc/DIoie hzcxBorNS5tSbqmqd7NN45JE+8yHq8daMwV5Wxx52XEETs2GLN+tvSmPHwtZiMNiokGY+RMq2 GlY0+DU/uW9HaIEClrbOo73RMS/oC8udG6Q9i7pCTUxwEJciginzmx2p3a5DpwMcI3g+zT8iz sRnOyWWEtO1Lr2lbh8Jys/wt5MLZ8jFfpQ1tJTFtDBXbHTlVpLbzFs8tbRRPzcmYED+6ZEDZE xCMDGlfPCuE2PfIXwNmFFDMGX8cHOM/U1u/CXMH1WBg3zpPiZRoYh1B3I48= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 212.227.17.10 Subject: [Qemu-devel] [PATCH for 2.13 v2 18/19] linux-user: move hppa cpu loop to hppa directory X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Cornelia Huck , Riku Voipio , Richard Henderson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Laurent Vivier , qemu-s390x@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 No code change, only move code from main.c to hppa/cpu_loop.c. Signed-off-by: Laurent Vivier Reviewed-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- linux-user/hppa/cpu_loop.c | 185 ++++++++++++++++++++++++++++++++++++++++++ linux-user/main.c | 194 +----------------------------------------= ---- 2 files changed, 186 insertions(+), 193 deletions(-) diff --git a/linux-user/hppa/cpu_loop.c b/linux-user/hppa/cpu_loop.c index b7700a5561..0301c766c6 100644 --- a/linux-user/hppa/cpu_loop.c +++ b/linux-user/hppa/cpu_loop.c @@ -21,6 +21,191 @@ #include "qemu.h" #include "cpu_loop-common.h" =20 +static abi_ulong hppa_lws(CPUHPPAState *env) +{ + uint32_t which =3D env->gr[20]; + abi_ulong addr =3D env->gr[26]; + abi_ulong old =3D env->gr[25]; + abi_ulong new =3D env->gr[24]; + abi_ulong size, ret; + + switch (which) { + default: + return -TARGET_ENOSYS; + + case 0: /* elf32 atomic 32bit cmpxchg */ + if ((addr & 3) || !access_ok(VERIFY_WRITE, addr, 4)) { + return -TARGET_EFAULT; + } + old =3D tswap32(old); + new =3D tswap32(new); + ret =3D atomic_cmpxchg((uint32_t *)g2h(addr), old, new); + ret =3D tswap32(ret); + break; + + case 2: /* elf32 atomic "new" cmpxchg */ + size =3D env->gr[23]; + if (size >=3D 4) { + return -TARGET_ENOSYS; + } + if (((addr | old | new) & ((1 << size) - 1)) + || !access_ok(VERIFY_WRITE, addr, 1 << size) + || !access_ok(VERIFY_READ, old, 1 << size) + || !access_ok(VERIFY_READ, new, 1 << size)) { + return -TARGET_EFAULT; + } + /* Note that below we use host-endian loads so that the cmpxchg + can be host-endian as well. */ + switch (size) { + case 0: + old =3D *(uint8_t *)g2h(old); + new =3D *(uint8_t *)g2h(new); + ret =3D atomic_cmpxchg((uint8_t *)g2h(addr), old, new); + ret =3D ret !=3D old; + break; + case 1: + old =3D *(uint16_t *)g2h(old); + new =3D *(uint16_t *)g2h(new); + ret =3D atomic_cmpxchg((uint16_t *)g2h(addr), old, new); + ret =3D ret !=3D old; + break; + case 2: + old =3D *(uint32_t *)g2h(old); + new =3D *(uint32_t *)g2h(new); + ret =3D atomic_cmpxchg((uint32_t *)g2h(addr), old, new); + ret =3D ret !=3D old; + break; + case 3: + { + uint64_t o64, n64, r64; + o64 =3D *(uint64_t *)g2h(old); + n64 =3D *(uint64_t *)g2h(new); +#ifdef CONFIG_ATOMIC64 + r64 =3D atomic_cmpxchg__nocheck((uint64_t *)g2h(addr), o64= , n64); + ret =3D r64 !=3D o64; +#else + start_exclusive(); + r64 =3D *(uint64_t *)g2h(addr); + ret =3D 1; + if (r64 =3D=3D o64) { + *(uint64_t *)g2h(addr) =3D n64; + ret =3D 0; + } + end_exclusive(); +#endif + } + break; + } + break; + } + + env->gr[28] =3D ret; + return 0; +} + +void cpu_loop(CPUHPPAState *env) +{ + CPUState *cs =3D CPU(hppa_env_get_cpu(env)); + target_siginfo_t info; + abi_ulong ret; + int trapnr; + + while (1) { + cpu_exec_start(cs); + trapnr =3D cpu_exec(cs); + cpu_exec_end(cs); + process_queued_cpu_work(cs); + + switch (trapnr) { + case EXCP_SYSCALL: + ret =3D do_syscall(env, env->gr[20], + env->gr[26], env->gr[25], + env->gr[24], env->gr[23], + env->gr[22], env->gr[21], 0, 0); + switch (ret) { + default: + env->gr[28] =3D ret; + /* We arrived here by faking the gateway page. Return. */ + env->iaoq_f =3D env->gr[31]; + env->iaoq_b =3D env->gr[31] + 4; + break; + case -TARGET_ERESTARTSYS: + case -TARGET_QEMU_ESIGRETURN: + break; + } + break; + case EXCP_SYSCALL_LWS: + env->gr[21] =3D hppa_lws(env); + /* We arrived here by faking the gateway page. Return. */ + env->iaoq_f =3D env->gr[31]; + env->iaoq_b =3D env->gr[31] + 4; + break; + case EXCP_ITLB_MISS: + case EXCP_DTLB_MISS: + case EXCP_NA_ITLB_MISS: + case EXCP_NA_DTLB_MISS: + case EXCP_IMP: + case EXCP_DMP: + case EXCP_DMB: + case EXCP_PAGE_REF: + case EXCP_DMAR: + case EXCP_DMPI: + info.si_signo =3D TARGET_SIGSEGV; + info.si_errno =3D 0; + info.si_code =3D TARGET_SEGV_ACCERR; + info._sifields._sigfault._addr =3D env->cr[CR_IOR]; + queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + break; + case EXCP_UNALIGN: + info.si_signo =3D TARGET_SIGBUS; + info.si_errno =3D 0; + info.si_code =3D 0; + info._sifields._sigfault._addr =3D env->cr[CR_IOR]; + queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + break; + case EXCP_ILL: + case EXCP_PRIV_OPR: + case EXCP_PRIV_REG: + info.si_signo =3D TARGET_SIGILL; + info.si_errno =3D 0; + info.si_code =3D TARGET_ILL_ILLOPN; + info._sifields._sigfault._addr =3D env->iaoq_f; + queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + break; + case EXCP_OVERFLOW: + case EXCP_COND: + case EXCP_ASSIST: + info.si_signo =3D TARGET_SIGFPE; + info.si_errno =3D 0; + info.si_code =3D 0; + info._sifields._sigfault._addr =3D env->iaoq_f; + queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + break; + case EXCP_DEBUG: + trapnr =3D gdb_handlesig(cs, TARGET_SIGTRAP); + if (trapnr) { + info.si_signo =3D trapnr; + info.si_errno =3D 0; + info.si_code =3D TARGET_TRAP_BRKPT; + queue_signal(env, trapnr, QEMU_SI_FAULT, &info); + } + break; + case EXCP_INTERRUPT: + /* just indicate that signals should be handled asap */ + break; + default: + g_assert_not_reached(); + } + process_pending_signals(env); + } +} + void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs) { + int i; + for (i =3D 1; i < 32; i++) { + env->gr[i] =3D regs->gr[i]; + } + env->iaoq_f =3D regs->iaoq[0]; + env->iaoq_b =3D regs->iaoq[1]; } diff --git a/linux-user/main.c b/linux-user/main.c index 834ec0bfe5..aa48b048a7 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -149,189 +149,6 @@ void fork_end(int child) } } =20 -#ifdef TARGET_HPPA - -static abi_ulong hppa_lws(CPUHPPAState *env) -{ - uint32_t which =3D env->gr[20]; - abi_ulong addr =3D env->gr[26]; - abi_ulong old =3D env->gr[25]; - abi_ulong new =3D env->gr[24]; - abi_ulong size, ret; - - switch (which) { - default: - return -TARGET_ENOSYS; - - case 0: /* elf32 atomic 32bit cmpxchg */ - if ((addr & 3) || !access_ok(VERIFY_WRITE, addr, 4)) { - return -TARGET_EFAULT; - } - old =3D tswap32(old); - new =3D tswap32(new); - ret =3D atomic_cmpxchg((uint32_t *)g2h(addr), old, new); - ret =3D tswap32(ret); - break; - - case 2: /* elf32 atomic "new" cmpxchg */ - size =3D env->gr[23]; - if (size >=3D 4) { - return -TARGET_ENOSYS; - } - if (((addr | old | new) & ((1 << size) - 1)) - || !access_ok(VERIFY_WRITE, addr, 1 << size) - || !access_ok(VERIFY_READ, old, 1 << size) - || !access_ok(VERIFY_READ, new, 1 << size)) { - return -TARGET_EFAULT; - } - /* Note that below we use host-endian loads so that the cmpxchg - can be host-endian as well. */ - switch (size) { - case 0: - old =3D *(uint8_t *)g2h(old); - new =3D *(uint8_t *)g2h(new); - ret =3D atomic_cmpxchg((uint8_t *)g2h(addr), old, new); - ret =3D ret !=3D old; - break; - case 1: - old =3D *(uint16_t *)g2h(old); - new =3D *(uint16_t *)g2h(new); - ret =3D atomic_cmpxchg((uint16_t *)g2h(addr), old, new); - ret =3D ret !=3D old; - break; - case 2: - old =3D *(uint32_t *)g2h(old); - new =3D *(uint32_t *)g2h(new); - ret =3D atomic_cmpxchg((uint32_t *)g2h(addr), old, new); - ret =3D ret !=3D old; - break; - case 3: - { - uint64_t o64, n64, r64; - o64 =3D *(uint64_t *)g2h(old); - n64 =3D *(uint64_t *)g2h(new); -#ifdef CONFIG_ATOMIC64 - r64 =3D atomic_cmpxchg__nocheck((uint64_t *)g2h(addr), o64= , n64); - ret =3D r64 !=3D o64; -#else - start_exclusive(); - r64 =3D *(uint64_t *)g2h(addr); - ret =3D 1; - if (r64 =3D=3D o64) { - *(uint64_t *)g2h(addr) =3D n64; - ret =3D 0; - } - end_exclusive(); -#endif - } - break; - } - break; - } - - env->gr[28] =3D ret; - return 0; -} - -void cpu_loop(CPUHPPAState *env) -{ - CPUState *cs =3D CPU(hppa_env_get_cpu(env)); - target_siginfo_t info; - abi_ulong ret; - int trapnr; - - while (1) { - cpu_exec_start(cs); - trapnr =3D cpu_exec(cs); - cpu_exec_end(cs); - process_queued_cpu_work(cs); - - switch (trapnr) { - case EXCP_SYSCALL: - ret =3D do_syscall(env, env->gr[20], - env->gr[26], env->gr[25], - env->gr[24], env->gr[23], - env->gr[22], env->gr[21], 0, 0); - switch (ret) { - default: - env->gr[28] =3D ret; - /* We arrived here by faking the gateway page. Return. */ - env->iaoq_f =3D env->gr[31]; - env->iaoq_b =3D env->gr[31] + 4; - break; - case -TARGET_ERESTARTSYS: - case -TARGET_QEMU_ESIGRETURN: - break; - } - break; - case EXCP_SYSCALL_LWS: - env->gr[21] =3D hppa_lws(env); - /* We arrived here by faking the gateway page. Return. */ - env->iaoq_f =3D env->gr[31]; - env->iaoq_b =3D env->gr[31] + 4; - break; - case EXCP_ITLB_MISS: - case EXCP_DTLB_MISS: - case EXCP_NA_ITLB_MISS: - case EXCP_NA_DTLB_MISS: - case EXCP_IMP: - case EXCP_DMP: - case EXCP_DMB: - case EXCP_PAGE_REF: - case EXCP_DMAR: - case EXCP_DMPI: - info.si_signo =3D TARGET_SIGSEGV; - info.si_errno =3D 0; - info.si_code =3D TARGET_SEGV_ACCERR; - info._sifields._sigfault._addr =3D env->cr[CR_IOR]; - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); - break; - case EXCP_UNALIGN: - info.si_signo =3D TARGET_SIGBUS; - info.si_errno =3D 0; - info.si_code =3D 0; - info._sifields._sigfault._addr =3D env->cr[CR_IOR]; - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); - break; - case EXCP_ILL: - case EXCP_PRIV_OPR: - case EXCP_PRIV_REG: - info.si_signo =3D TARGET_SIGILL; - info.si_errno =3D 0; - info.si_code =3D TARGET_ILL_ILLOPN; - info._sifields._sigfault._addr =3D env->iaoq_f; - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); - break; - case EXCP_OVERFLOW: - case EXCP_COND: - case EXCP_ASSIST: - info.si_signo =3D TARGET_SIGFPE; - info.si_errno =3D 0; - info.si_code =3D 0; - info._sifields._sigfault._addr =3D env->iaoq_f; - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); - break; - case EXCP_DEBUG: - trapnr =3D gdb_handlesig(cs, TARGET_SIGTRAP); - if (trapnr) { - info.si_signo =3D trapnr; - info.si_errno =3D 0; - info.si_code =3D TARGET_TRAP_BRKPT; - queue_signal(env, trapnr, QEMU_SI_FAULT, &info); - } - break; - case EXCP_INTERRUPT: - /* just indicate that signals should be handled asap */ - break; - default: - g_assert_not_reached(); - } - process_pending_signals(env); - } -} - -#endif /* TARGET_HPPA */ - #ifdef TARGET_XTENSA =20 static void xtensa_rfw(CPUXtensaState *env) @@ -1228,16 +1045,7 @@ int main(int argc, char **argv, char **envp) =20 target_cpu_copy_regs(env, regs); =20 -#if defined(TARGET_HPPA) - { - int i; - for (i =3D 1; i < 32; i++) { - env->gr[i] =3D regs->gr[i]; - } - env->iaoq_f =3D regs->iaoq[0]; - env->iaoq_b =3D regs->iaoq[1]; - } -#elif defined(TARGET_XTENSA) +#if defined(TARGET_XTENSA) { int i; for (i =3D 0; i < 16; ++i) { --=20 2.14.3 From nobody Mon May 6 08:55:16 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1523475280301400.311598707755; Wed, 11 Apr 2018 12:34:40 -0700 (PDT) Received: from localhost ([::1]:49682 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f6LVr-0004I1-M5 for importer@patchew.org; Wed, 11 Apr 2018 15:34:35 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38230) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f6KwF-0006GM-Sj for qemu-devel@nongnu.org; Wed, 11 Apr 2018 14:57:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f6KwA-0007zU-Ml for qemu-devel@nongnu.org; Wed, 11 Apr 2018 14:57:47 -0400 Received: from mout.kundenserver.de ([217.72.192.73]:58757) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1f6Kw0-0007pt-TF; Wed, 11 Apr 2018 14:57:33 -0400 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue105 [212.227.15.183]) with ESMTPSA (Nemesis) id 0M5850-1eG8Pz2D30-00zBPq; Wed, 11 Apr 2018 20:57:26 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Date: Wed, 11 Apr 2018 20:56:51 +0200 Message-Id: <20180411185651.21351-20-laurent@vivier.eu> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180411185651.21351-1-laurent@vivier.eu> References: <20180411185651.21351-1-laurent@vivier.eu> X-Provags-ID: V03:K1:kbMVddC8c9E6tufMggKLeoFYgomIsrfZxguu4xKm8SADkms+4XI XISpWdEefTDqKbJtpE/9kYepo7xoB9vd76xD66a+plkMQOHtYgCUkVd5Aw42L9XI1R9hzxr hWM6xBkePTmlJBgeF7ASMbhoBsGtYu02rhaKrA2xxtcOsCiYfarAWLrSfXruOX5gWlXTt+o c4ziQXYHD4VWjkBRmANqA== X-UI-Out-Filterresults: notjunk:1;V01:K0:DVuGLILxkKg=:R4SycZLNvbnTdga/vlSFbk 7jKviJE/EJGzNboXpHTsDwIAbKUQOkiSNGntTnoYisg9Dgqf8TPOgNiHXPWeq8UALyHbL4O3a rFaVlehIhSp9eZM4Oa8gmMwK6J42aUiVOgtwn7+4/2OPI8emjiSYezZCuisaOxcpI4r4o2Oln ZFUl7LkXomuLyU9IMFhtXnyisIuAkfcDR3wjCw2pD9w3eCupVQWFUwOC4HIJ1jskCWvTNWQcx BKJphxcHEgnNrMNyeDRebB1IM/T7/brxLlmpbleRQZfv9IcTf4KfAvJPNXTxFKD8PWdhAdLAT pnDYaKW0pLCymj1LRuGt0JBHJpIpxc5oC+oofKgWAw6OUPnCNB/gfbQ0BAfIy2PT1Ina2fQI+ F5EoTveYiPBQ+Nsxw2k57i3Ea9fw/+nYsZNIQKd6/2t+upLc4nnHE/y5KE348qeLtjgBuCJKz eV+L9ohuXwQg2prSXpqkPqt8J8uDK0g2FyHb4Hjs6IjuKX4lbBpsMF05Jez5M5aX83djeBYB+ eaaYE7hI8Na728BFDble4wqo8/dhpJE3pHy6dGPZUmAgUaGh1wR+0vdolFHySBJ046x3CyNc5 tSCFpmMME5hFVqIAGU+L/758u7jyvnBlhsEJl/XZ/0xATLHw3SiJxANdAujR9PBb57X0lulkB jqHbzvNQP+IyhbyPvWv5zcpalBx/6A0b+lfgjaPL3MhX+NnX+1OIvYAPDeGIT5kGfN3m3q6XE Ol+v9kqqbP/zLmS0ik2whJ7nFOibJQpQTF0PCg== X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 217.72.192.73 Subject: [Qemu-devel] [PATCH for 2.13 v2 19/19] linux-user: move xtensa cpu loop to xtensa directory X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Cornelia Huck , Riku Voipio , Richard Henderson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Laurent Vivier , qemu-s390x@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" No code change, only move code from main.c to xtensa/cpu_loop.c. Signed-off-by: Laurent Vivier Reviewed-by: Richard Henderson --- Notes: v2: report changes introduced by 4a6bf7adb9 target/xtensa: linux-user: rewind pc for restarted sysca= ll linux-user/main.c | 250 ---------------------------------------= ---- linux-user/xtensa/cpu_loop.c | 241 +++++++++++++++++++++++++++++++++++++++= ++ 2 files changed, 241 insertions(+), 250 deletions(-) diff --git a/linux-user/main.c b/linux-user/main.c index aa48b048a7..32347545c9 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -149,245 +149,6 @@ void fork_end(int child) } } =20 -#ifdef TARGET_XTENSA - -static void xtensa_rfw(CPUXtensaState *env) -{ - xtensa_restore_owb(env); - env->pc =3D env->sregs[EPC1]; -} - -static void xtensa_rfwu(CPUXtensaState *env) -{ - env->sregs[WINDOW_START] |=3D (1 << env->sregs[WINDOW_BASE]); - xtensa_rfw(env); -} - -static void xtensa_rfwo(CPUXtensaState *env) -{ - env->sregs[WINDOW_START] &=3D ~(1 << env->sregs[WINDOW_BASE]); - xtensa_rfw(env); -} - -static void xtensa_overflow4(CPUXtensaState *env) -{ - put_user_ual(env->regs[0], env->regs[5] - 16); - put_user_ual(env->regs[1], env->regs[5] - 12); - put_user_ual(env->regs[2], env->regs[5] - 8); - put_user_ual(env->regs[3], env->regs[5] - 4); - xtensa_rfwo(env); -} - -static void xtensa_underflow4(CPUXtensaState *env) -{ - get_user_ual(env->regs[0], env->regs[5] - 16); - get_user_ual(env->regs[1], env->regs[5] - 12); - get_user_ual(env->regs[2], env->regs[5] - 8); - get_user_ual(env->regs[3], env->regs[5] - 4); - xtensa_rfwu(env); -} - -static void xtensa_overflow8(CPUXtensaState *env) -{ - put_user_ual(env->regs[0], env->regs[9] - 16); - get_user_ual(env->regs[0], env->regs[1] - 12); - put_user_ual(env->regs[1], env->regs[9] - 12); - put_user_ual(env->regs[2], env->regs[9] - 8); - put_user_ual(env->regs[3], env->regs[9] - 4); - put_user_ual(env->regs[4], env->regs[0] - 32); - put_user_ual(env->regs[5], env->regs[0] - 28); - put_user_ual(env->regs[6], env->regs[0] - 24); - put_user_ual(env->regs[7], env->regs[0] - 20); - xtensa_rfwo(env); -} - -static void xtensa_underflow8(CPUXtensaState *env) -{ - get_user_ual(env->regs[0], env->regs[9] - 16); - get_user_ual(env->regs[1], env->regs[9] - 12); - get_user_ual(env->regs[2], env->regs[9] - 8); - get_user_ual(env->regs[7], env->regs[1] - 12); - get_user_ual(env->regs[3], env->regs[9] - 4); - get_user_ual(env->regs[4], env->regs[7] - 32); - get_user_ual(env->regs[5], env->regs[7] - 28); - get_user_ual(env->regs[6], env->regs[7] - 24); - get_user_ual(env->regs[7], env->regs[7] - 20); - xtensa_rfwu(env); -} - -static void xtensa_overflow12(CPUXtensaState *env) -{ - put_user_ual(env->regs[0], env->regs[13] - 16); - get_user_ual(env->regs[0], env->regs[1] - 12); - put_user_ual(env->regs[1], env->regs[13] - 12); - put_user_ual(env->regs[2], env->regs[13] - 8); - put_user_ual(env->regs[3], env->regs[13] - 4); - put_user_ual(env->regs[4], env->regs[0] - 48); - put_user_ual(env->regs[5], env->regs[0] - 44); - put_user_ual(env->regs[6], env->regs[0] - 40); - put_user_ual(env->regs[7], env->regs[0] - 36); - put_user_ual(env->regs[8], env->regs[0] - 32); - put_user_ual(env->regs[9], env->regs[0] - 28); - put_user_ual(env->regs[10], env->regs[0] - 24); - put_user_ual(env->regs[11], env->regs[0] - 20); - xtensa_rfwo(env); -} - -static void xtensa_underflow12(CPUXtensaState *env) -{ - get_user_ual(env->regs[0], env->regs[13] - 16); - get_user_ual(env->regs[1], env->regs[13] - 12); - get_user_ual(env->regs[2], env->regs[13] - 8); - get_user_ual(env->regs[11], env->regs[1] - 12); - get_user_ual(env->regs[3], env->regs[13] - 4); - get_user_ual(env->regs[4], env->regs[11] - 48); - get_user_ual(env->regs[5], env->regs[11] - 44); - get_user_ual(env->regs[6], env->regs[11] - 40); - get_user_ual(env->regs[7], env->regs[11] - 36); - get_user_ual(env->regs[8], env->regs[11] - 32); - get_user_ual(env->regs[9], env->regs[11] - 28); - get_user_ual(env->regs[10], env->regs[11] - 24); - get_user_ual(env->regs[11], env->regs[11] - 20); - xtensa_rfwu(env); -} - -void cpu_loop(CPUXtensaState *env) -{ - CPUState *cs =3D CPU(xtensa_env_get_cpu(env)); - target_siginfo_t info; - abi_ulong ret; - int trapnr; - - while (1) { - cpu_exec_start(cs); - trapnr =3D cpu_exec(cs); - cpu_exec_end(cs); - process_queued_cpu_work(cs); - - env->sregs[PS] &=3D ~PS_EXCM; - switch (trapnr) { - case EXCP_INTERRUPT: - break; - - case EXC_WINDOW_OVERFLOW4: - xtensa_overflow4(env); - break; - case EXC_WINDOW_UNDERFLOW4: - xtensa_underflow4(env); - break; - case EXC_WINDOW_OVERFLOW8: - xtensa_overflow8(env); - break; - case EXC_WINDOW_UNDERFLOW8: - xtensa_underflow8(env); - break; - case EXC_WINDOW_OVERFLOW12: - xtensa_overflow12(env); - break; - case EXC_WINDOW_UNDERFLOW12: - xtensa_underflow12(env); - break; - - case EXC_USER: - switch (env->sregs[EXCCAUSE]) { - case ILLEGAL_INSTRUCTION_CAUSE: - case PRIVILEGED_CAUSE: - info.si_signo =3D TARGET_SIGILL; - info.si_errno =3D 0; - info.si_code =3D - env->sregs[EXCCAUSE] =3D=3D ILLEGAL_INSTRUCTION_CAUSE ? - TARGET_ILL_ILLOPC : TARGET_ILL_PRVOPC; - info._sifields._sigfault._addr =3D env->sregs[EPC1]; - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); - break; - - case SYSCALL_CAUSE: - env->pc +=3D 3; - ret =3D do_syscall(env, env->regs[2], - env->regs[6], env->regs[3], - env->regs[4], env->regs[5], - env->regs[8], env->regs[9], 0, 0); - switch (ret) { - default: - env->regs[2] =3D ret; - break; - - case -TARGET_ERESTARTSYS: - env->pc -=3D 3; - break; - - case -TARGET_QEMU_ESIGRETURN: - break; - } - break; - - case ALLOCA_CAUSE: - env->sregs[PS] =3D deposit32(env->sregs[PS], - PS_OWB_SHIFT, - PS_OWB_LEN, - env->sregs[WINDOW_BASE]); - - switch (env->regs[0] & 0xc0000000) { - case 0x00000000: - case 0x40000000: - xtensa_rotate_window(env, -1); - xtensa_underflow4(env); - break; - - case 0x80000000: - xtensa_rotate_window(env, -2); - xtensa_underflow8(env); - break; - - case 0xc0000000: - xtensa_rotate_window(env, -3); - xtensa_underflow12(env); - break; - } - break; - - case INTEGER_DIVIDE_BY_ZERO_CAUSE: - info.si_signo =3D TARGET_SIGFPE; - info.si_errno =3D 0; - info.si_code =3D TARGET_FPE_INTDIV; - info._sifields._sigfault._addr =3D env->sregs[EPC1]; - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); - break; - - case LOAD_PROHIBITED_CAUSE: - case STORE_PROHIBITED_CAUSE: - info.si_signo =3D TARGET_SIGSEGV; - info.si_errno =3D 0; - info.si_code =3D TARGET_SEGV_ACCERR; - info._sifields._sigfault._addr =3D env->sregs[EXCVADDR]; - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); - break; - - default: - fprintf(stderr, "exccause =3D %d\n", env->sregs[EXCCAUSE]); - g_assert_not_reached(); - } - break; - case EXCP_DEBUG: - trapnr =3D gdb_handlesig(cs, TARGET_SIGTRAP); - if (trapnr) { - info.si_signo =3D trapnr; - info.si_errno =3D 0; - info.si_code =3D TARGET_TRAP_BRKPT; - queue_signal(env, trapnr, QEMU_SI_FAULT, &info); - } - break; - case EXC_DEBUG: - default: - fprintf(stderr, "trapnr =3D %d\n", trapnr); - g_assert_not_reached(); - } - process_pending_signals(env); - } -} - -#endif /* TARGET_XTENSA */ - __thread CPUState *thread_cpu; =20 bool qemu_cpu_is_self(CPUState *cpu) @@ -1045,17 +806,6 @@ int main(int argc, char **argv, char **envp) =20 target_cpu_copy_regs(env, regs); =20 -#if defined(TARGET_XTENSA) - { - int i; - for (i =3D 0; i < 16; ++i) { - env->regs[i] =3D regs->areg[i]; - } - env->sregs[WINDOW_START] =3D regs->windowstart; - env->pc =3D regs->pc; - } -#endif - if (gdbstub_port) { if (gdbserver_start(gdbstub_port) < 0) { fprintf(stderr, "qemu: could not open gdbserver on port %d\n", diff --git a/linux-user/xtensa/cpu_loop.c b/linux-user/xtensa/cpu_loop.c index b7700a5561..d142988ebe 100644 --- a/linux-user/xtensa/cpu_loop.c +++ b/linux-user/xtensa/cpu_loop.c @@ -21,6 +21,247 @@ #include "qemu.h" #include "cpu_loop-common.h" =20 +static void xtensa_rfw(CPUXtensaState *env) +{ + xtensa_restore_owb(env); + env->pc =3D env->sregs[EPC1]; +} + +static void xtensa_rfwu(CPUXtensaState *env) +{ + env->sregs[WINDOW_START] |=3D (1 << env->sregs[WINDOW_BASE]); + xtensa_rfw(env); +} + +static void xtensa_rfwo(CPUXtensaState *env) +{ + env->sregs[WINDOW_START] &=3D ~(1 << env->sregs[WINDOW_BASE]); + xtensa_rfw(env); +} + +static void xtensa_overflow4(CPUXtensaState *env) +{ + put_user_ual(env->regs[0], env->regs[5] - 16); + put_user_ual(env->regs[1], env->regs[5] - 12); + put_user_ual(env->regs[2], env->regs[5] - 8); + put_user_ual(env->regs[3], env->regs[5] - 4); + xtensa_rfwo(env); +} + +static void xtensa_underflow4(CPUXtensaState *env) +{ + get_user_ual(env->regs[0], env->regs[5] - 16); + get_user_ual(env->regs[1], env->regs[5] - 12); + get_user_ual(env->regs[2], env->regs[5] - 8); + get_user_ual(env->regs[3], env->regs[5] - 4); + xtensa_rfwu(env); +} + +static void xtensa_overflow8(CPUXtensaState *env) +{ + put_user_ual(env->regs[0], env->regs[9] - 16); + get_user_ual(env->regs[0], env->regs[1] - 12); + put_user_ual(env->regs[1], env->regs[9] - 12); + put_user_ual(env->regs[2], env->regs[9] - 8); + put_user_ual(env->regs[3], env->regs[9] - 4); + put_user_ual(env->regs[4], env->regs[0] - 32); + put_user_ual(env->regs[5], env->regs[0] - 28); + put_user_ual(env->regs[6], env->regs[0] - 24); + put_user_ual(env->regs[7], env->regs[0] - 20); + xtensa_rfwo(env); +} + +static void xtensa_underflow8(CPUXtensaState *env) +{ + get_user_ual(env->regs[0], env->regs[9] - 16); + get_user_ual(env->regs[1], env->regs[9] - 12); + get_user_ual(env->regs[2], env->regs[9] - 8); + get_user_ual(env->regs[7], env->regs[1] - 12); + get_user_ual(env->regs[3], env->regs[9] - 4); + get_user_ual(env->regs[4], env->regs[7] - 32); + get_user_ual(env->regs[5], env->regs[7] - 28); + get_user_ual(env->regs[6], env->regs[7] - 24); + get_user_ual(env->regs[7], env->regs[7] - 20); + xtensa_rfwu(env); +} + +static void xtensa_overflow12(CPUXtensaState *env) +{ + put_user_ual(env->regs[0], env->regs[13] - 16); + get_user_ual(env->regs[0], env->regs[1] - 12); + put_user_ual(env->regs[1], env->regs[13] - 12); + put_user_ual(env->regs[2], env->regs[13] - 8); + put_user_ual(env->regs[3], env->regs[13] - 4); + put_user_ual(env->regs[4], env->regs[0] - 48); + put_user_ual(env->regs[5], env->regs[0] - 44); + put_user_ual(env->regs[6], env->regs[0] - 40); + put_user_ual(env->regs[7], env->regs[0] - 36); + put_user_ual(env->regs[8], env->regs[0] - 32); + put_user_ual(env->regs[9], env->regs[0] - 28); + put_user_ual(env->regs[10], env->regs[0] - 24); + put_user_ual(env->regs[11], env->regs[0] - 20); + xtensa_rfwo(env); +} + +static void xtensa_underflow12(CPUXtensaState *env) +{ + get_user_ual(env->regs[0], env->regs[13] - 16); + get_user_ual(env->regs[1], env->regs[13] - 12); + get_user_ual(env->regs[2], env->regs[13] - 8); + get_user_ual(env->regs[11], env->regs[1] - 12); + get_user_ual(env->regs[3], env->regs[13] - 4); + get_user_ual(env->regs[4], env->regs[11] - 48); + get_user_ual(env->regs[5], env->regs[11] - 44); + get_user_ual(env->regs[6], env->regs[11] - 40); + get_user_ual(env->regs[7], env->regs[11] - 36); + get_user_ual(env->regs[8], env->regs[11] - 32); + get_user_ual(env->regs[9], env->regs[11] - 28); + get_user_ual(env->regs[10], env->regs[11] - 24); + get_user_ual(env->regs[11], env->regs[11] - 20); + xtensa_rfwu(env); +} + +void cpu_loop(CPUXtensaState *env) +{ + CPUState *cs =3D CPU(xtensa_env_get_cpu(env)); + target_siginfo_t info; + abi_ulong ret; + int trapnr; + + while (1) { + cpu_exec_start(cs); + trapnr =3D cpu_exec(cs); + cpu_exec_end(cs); + process_queued_cpu_work(cs); + + env->sregs[PS] &=3D ~PS_EXCM; + switch (trapnr) { + case EXCP_INTERRUPT: + break; + + case EXC_WINDOW_OVERFLOW4: + xtensa_overflow4(env); + break; + case EXC_WINDOW_UNDERFLOW4: + xtensa_underflow4(env); + break; + case EXC_WINDOW_OVERFLOW8: + xtensa_overflow8(env); + break; + case EXC_WINDOW_UNDERFLOW8: + xtensa_underflow8(env); + break; + case EXC_WINDOW_OVERFLOW12: + xtensa_overflow12(env); + break; + case EXC_WINDOW_UNDERFLOW12: + xtensa_underflow12(env); + break; + + case EXC_USER: + switch (env->sregs[EXCCAUSE]) { + case ILLEGAL_INSTRUCTION_CAUSE: + case PRIVILEGED_CAUSE: + info.si_signo =3D TARGET_SIGILL; + info.si_errno =3D 0; + info.si_code =3D + env->sregs[EXCCAUSE] =3D=3D ILLEGAL_INSTRUCTION_CAUSE ? + TARGET_ILL_ILLOPC : TARGET_ILL_PRVOPC; + info._sifields._sigfault._addr =3D env->sregs[EPC1]; + queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + break; + + case SYSCALL_CAUSE: + env->pc +=3D 3; + ret =3D do_syscall(env, env->regs[2], + env->regs[6], env->regs[3], + env->regs[4], env->regs[5], + env->regs[8], env->regs[9], 0, 0); + switch (ret) { + default: + env->regs[2] =3D ret; + break; + + case -TARGET_ERESTARTSYS: + env->pc -=3D 3; + break; + + case -TARGET_QEMU_ESIGRETURN: + break; + } + break; + + case ALLOCA_CAUSE: + env->sregs[PS] =3D deposit32(env->sregs[PS], + PS_OWB_SHIFT, + PS_OWB_LEN, + env->sregs[WINDOW_BASE]); + + switch (env->regs[0] & 0xc0000000) { + case 0x00000000: + case 0x40000000: + xtensa_rotate_window(env, -1); + xtensa_underflow4(env); + break; + + case 0x80000000: + xtensa_rotate_window(env, -2); + xtensa_underflow8(env); + break; + + case 0xc0000000: + xtensa_rotate_window(env, -3); + xtensa_underflow12(env); + break; + } + break; + + case INTEGER_DIVIDE_BY_ZERO_CAUSE: + info.si_signo =3D TARGET_SIGFPE; + info.si_errno =3D 0; + info.si_code =3D TARGET_FPE_INTDIV; + info._sifields._sigfault._addr =3D env->sregs[EPC1]; + queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + break; + + case LOAD_PROHIBITED_CAUSE: + case STORE_PROHIBITED_CAUSE: + info.si_signo =3D TARGET_SIGSEGV; + info.si_errno =3D 0; + info.si_code =3D TARGET_SEGV_ACCERR; + info._sifields._sigfault._addr =3D env->sregs[EXCVADDR]; + queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + break; + + default: + fprintf(stderr, "exccause =3D %d\n", env->sregs[EXCCAUSE]); + g_assert_not_reached(); + } + break; + case EXCP_DEBUG: + trapnr =3D gdb_handlesig(cs, TARGET_SIGTRAP); + if (trapnr) { + info.si_signo =3D trapnr; + info.si_errno =3D 0; + info.si_code =3D TARGET_TRAP_BRKPT; + queue_signal(env, trapnr, QEMU_SI_FAULT, &info); + } + break; + case EXC_DEBUG: + default: + fprintf(stderr, "trapnr =3D %d\n", trapnr); + g_assert_not_reached(); + } + process_pending_signals(env); + } +} + void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs) { + int i; + for (i =3D 0; i < 16; ++i) { + env->regs[i] =3D regs->areg[i]; + } + env->sregs[WINDOW_START] =3D regs->windowstart; + env->pc =3D regs->pc; } --=20 2.14.3