QEMU OpenRISC support
v5 cover QEMU OpenRISC support
This is the OpenCores OpenRISC 1200 support for QEMU.
Full implementation of the system-model and linux-user-model support.
OpenRISC 1200 is a OpenCores open source CPU,
its architecture manual can be found at
http://opencores.org/svnget,or1k?file=/trunk/docs/openrisc_arch.pdf
A OpenRISC Linux kernel contain initramfs for qemu-system-or32 testing can be found at
https://docs.google.com/file/d/0BxeTrz3x0CBLSjR3Sk5Vd3h1eDA/edit?pli=1
A OpenRISC hello-world program for qemu-or32 testing can be found at
https://docs.google.com/file/d/0BxeTrz3x0CBLN3RSWUFNYktrU2M/edit?pli=1
---
Version History:
V5:
Addressed Blue's review comments:
- reimplement l.mul* l.mfspr l.add* l.sub* and more.
- shoot bugs with "--enable-debug-tcg"
V4:
Addressed Max's review comments:
- fix l.div l.mac* l.mul*, and more.
Addressed Richard, Wei-Ren and Andreas's review comments:
- replace tcg_temp_new_i32 with tcg_temp_local_new_i32 in l.div translation.
Addressed Andreas's review comments:
- update to suit Makefile system.
- add UPR CPUCFGR and MMUCFGR impelement.
- add instruction check functions.
Version History:
V3:
Addressed Stefan and Andreas's review comments:
- use QEMU and OpenRISC's official name.
Addressed Andreas's review comments:
- reimplement cpu QOM.
- combine target stubs and QOM implement.
- use new commit message and subject.
Addressed Max's review comments:
- handle div zero exception.
- reimplement float point instructions.
- fix l.mac*, l.mul*, and more.
V2:
Addressed Malc, Weiren, Andreas and Blue's review comments:
- reimplement cpu QOM.
Addressed Andreas's review comments:
- reimplement machine.
- rewrite the Copyright Notice using better format.
Addressed Blue and Weiren's review comments:
- compiling with AREG0 and remove global env, no dyngen-exe longer.
Addressed Max, Blue and Weiren's review comments:
- handle div zero exception.
- handle illegal instruction.
Addressed Blue's review comments:
- separate do_interrupt into intrpt.c form intrpt_helper.c.
- add QEMU_NORETURN to raise_exception.
- reimplement float instrutions.
- fix type of linux syscall and termbits.
- reimplement sim board.
- use the LGPL web URL in Copyright Notice.
- reimplemt branch instructions.
- split taregt stubs, QOM and machine.
V1:
- add QEMU OpenRISC support.
- well tested on x64 machine, and final tested x86 machine.
Jia Liu (16):
target-or32: Add target stubs and cpu support
target-or32: Add target machine
target-or32: Add MMU support
target-or32: Add interrupt support
target-or32: Add exception support
target-or32: Add int instruction helpers
target-or32: Add float instruction helpers
target-or32: Add translation routines
target-or32: Add PIC support
target-or32: Add timer support
target-or32: Add a IIS dummy board
target-or32: Add system instructions
target-or32: Add gdb stub support
target-or32: Add linux syscall, signal and termbits
target-or32: Add linux user support
target-or32: Add testcases
arch_init.c | 2 + arch_init.h | 1 + configure | 15 +- cpu-exec.c | 19 + default-configs/or32-linux-user.mak | 2 + default-configs/or32-softmmu.mak | 6 + elf.h | 2 + gdbstub.c | 64 ++ hw/openrisc/Makefile.objs | 3 + hw/openrisc_cpudev.h | 29 + hw/openrisc_pic.c | 78 ++ hw/openrisc_sim.c | 145 +++ hw/openrisc_timer.c | 160 +++ linux-user/elfload.c | 41 + linux-user/main.c | 100 ++ linux-user/openrisc/syscall.h | 24 + linux-user/openrisc/syscall_nr.h | 506 +++++++++ linux-user/openrisc/target_signal.h | 26 + linux-user/openrisc/termbits.h | 294 +++++ linux-user/signal.c | 229 ++++ linux-user/syscall.c | 2 +- linux-user/syscall_defs.h | 40 +- poison.h | 1 + target-openrisc/Makefile.objs | 4 + target-openrisc/cpu.c | 240 +++++ target-openrisc/cpu.h | 445 ++++++++ target-openrisc/excp.c | 27 + target-openrisc/excp.h | 28 + target-openrisc/excp_helper.c | 27 + target-openrisc/fpu_helper.c | 275 +++++ target-openrisc/helper.h | 69 ++ target-openrisc/int_helper.c | 51 + target-openrisc/intrpt.c | 74 ++ target-openrisc/intrpt_helper.c | 52 + target-openrisc/machine.c | 50 + target-openrisc/mmu.c | 236 ++++ target-openrisc/mmu_helper.c | 63 ++ target-openrisc/sys_helper.c | 233 ++++ target-openrisc/translate.c | 2036 +++++++++++++++++++++++++++++++++++ tests/tcg/openrisc/Makefile | 71 ++ tests/tcg/openrisc/test_add.c | 34 + tests/tcg/openrisc/test_addc.c | 39 + tests/tcg/openrisc/test_addi.c | 31 + tests/tcg/openrisc/test_addic.c | 33 + tests/tcg/openrisc/test_and_or.c | 61 ++ tests/tcg/openrisc/test_bf.c | 46 + tests/tcg/openrisc/test_bnf.c | 50 + tests/tcg/openrisc/test_div.c | 32 + tests/tcg/openrisc/test_divu.c | 32 + tests/tcg/openrisc/test_extx.c | 72 ++ tests/tcg/openrisc/test_fx.c | 53 + tests/tcg/openrisc/test_j.c | 26 + tests/tcg/openrisc/test_jal.c | 26 + tests/tcg/openrisc/test_lf_add.c | 39 + tests/tcg/openrisc/test_lf_div.c | 34 + tests/tcg/openrisc/test_lf_eqs.c | 84 ++ tests/tcg/openrisc/test_lf_ges.c | 84 ++ tests/tcg/openrisc/test_lf_gts.c | 84 ++ tests/tcg/openrisc/test_lf_les.c | 84 ++ tests/tcg/openrisc/test_lf_lts.c | 91 ++ tests/tcg/openrisc/test_lf_mul.c | 22 + tests/tcg/openrisc/test_lf_nes.c | 87 ++ tests/tcg/openrisc/test_lf_rem.c | 32 + tests/tcg/openrisc/test_lf_sub.c | 33 + tests/tcg/openrisc/test_logic.c | 100 ++ tests/tcg/openrisc/test_lx.c | 78 ++ tests/tcg/openrisc/test_movhi.c | 30 + tests/tcg/openrisc/test_mul.c | 47 + tests/tcg/openrisc/test_muli.c | 47 + tests/tcg/openrisc/test_mulu.c | 47 + tests/tcg/openrisc/test_sfeq.c | 44 + tests/tcg/openrisc/test_sfeqi.c | 39 + tests/tcg/openrisc/test_sfges.c | 44 + tests/tcg/openrisc/test_sfgesi.c | 40 + tests/tcg/openrisc/test_sfgeu.c | 44 + tests/tcg/openrisc/test_sfgeui.c | 41 + tests/tcg/openrisc/test_sfgts.c | 45 + tests/tcg/openrisc/test_sfgtsi.c | 41 + tests/tcg/openrisc/test_sfgtu.c | 43 + tests/tcg/openrisc/test_sfgtui.c | 42 + tests/tcg/openrisc/test_sfles.c | 26 + tests/tcg/openrisc/test_sflesi.c | 39 + tests/tcg/openrisc/test_sfleu.c | 43 + tests/tcg/openrisc/test_sfleui.c | 39 + tests/tcg/openrisc/test_sflts.c | 43 + tests/tcg/openrisc/test_sfltsi.c | 38 + tests/tcg/openrisc/test_sfltu.c | 41 + tests/tcg/openrisc/test_sfltui.c | 39 + tests/tcg/openrisc/test_sfne.c | 43 + tests/tcg/openrisc/test_sfnei.c | 38 + tests/tcg/openrisc/test_sub.c | 34 + 91 files changed, 8168 insertions(+), 6 deletions(-) create mode 100644 default-configs/or32-linux-user.mak create mode 100644 default-configs/or32-softmmu.mak create mode 100644 hw/openrisc/Makefile.objs create mode 100644 hw/openrisc_cpudev.h create mode 100644 hw/openrisc_pic.c create mode 100644 hw/openrisc_sim.c create mode 100644 hw/openrisc_timer.c create mode 100644 linux-user/openrisc/syscall.h create mode 100644 linux-user/openrisc/syscall_nr.h create mode 100644 linux-user/openrisc/target_signal.h create mode 100644 linux-user/openrisc/termbits.h create mode 100644 target-openrisc/Makefile.objs create mode 100644 target-openrisc/cpu.c create mode 100644 target-openrisc/cpu.h create mode 100644 target-openrisc/excp.c create mode 100644 target-openrisc/excp.h create mode 100644 target-openrisc/excp_helper.c create mode 100644 target-openrisc/fpu_helper.c create mode 100644 target-openrisc/helper.h create mode 100644 target-openrisc/int_helper.c create mode 100644 target-openrisc/intrpt.c create mode 100644 target-openrisc/intrpt_helper.c create mode 100644 target-openrisc/machine.c create mode 100644 target-openrisc/mmu.c create mode 100644 target-openrisc/mmu_helper.c create mode 100644 target-openrisc/sys_helper.c create mode 100644 target-openrisc/translate.c create mode 100644 tests/tcg/openrisc/Makefile create mode 100644 tests/tcg/openrisc/test_add.c create mode 100644 tests/tcg/openrisc/test_addc.c create mode 100644 tests/tcg/openrisc/test_addi.c create mode 100644 tests/tcg/openrisc/test_addic.c create mode 100644 tests/tcg/openrisc/test_and_or.c create mode 100644 tests/tcg/openrisc/test_bf.c create mode 100644 tests/tcg/openrisc/test_bnf.c create mode 100644 tests/tcg/openrisc/test_div.c create mode 100644 tests/tcg/openrisc/test_divu.c create mode 100644 tests/tcg/openrisc/test_extx.c create mode 100644 tests/tcg/openrisc/test_fx.c create mode 100644 tests/tcg/openrisc/test_j.c create mode 100644 tests/tcg/openrisc/test_jal.c create mode 100644 tests/tcg/openrisc/test_lf_add.c create mode 100644 tests/tcg/openrisc/test_lf_div.c create mode 100644 tests/tcg/openrisc/test_lf_eqs.c create mode 100644 tests/tcg/openrisc/test_lf_ges.c create mode 100644 tests/tcg/openrisc/test_lf_gts.c create mode 100644 tests/tcg/openrisc/test_lf_les.c create mode 100644 tests/tcg/openrisc/test_lf_lts.c create mode 100644 tests/tcg/openrisc/test_lf_mul.c create mode 100644 tests/tcg/openrisc/test_lf_nes.c create mode 100644 tests/tcg/openrisc/test_lf_rem.c create mode 100644 tests/tcg/openrisc/test_lf_sub.c create mode 100644 tests/tcg/openrisc/test_logic.c create mode 100644 tests/tcg/openrisc/test_lx.c create mode 100644 tests/tcg/openrisc/test_movhi.c create mode 100644 tests/tcg/openrisc/test_mul.c create mode 100644 tests/tcg/openrisc/test_muli.c create mode 100644 tests/tcg/openrisc/test_mulu.c create mode 100644 tests/tcg/openrisc/test_sfeq.c create mode 100644 tests/tcg/openrisc/test_sfeqi.c create mode 100644 tests/tcg/openrisc/test_sfges.c create mode 100644 tests/tcg/openrisc/test_sfgesi.c create mode 100644 tests/tcg/openrisc/test_sfgeu.c create mode 100644 tests/tcg/openrisc/test_sfgeui.c create mode 100644 tests/tcg/openrisc/test_sfgts.c create mode 100644 tests/tcg/openrisc/test_sfgtsi.c create mode 100644 tests/tcg/openrisc/test_sfgtu.c create mode 100644 tests/tcg/openrisc/test_sfgtui.c create mode 100644 tests/tcg/openrisc/test_sfles.c create mode 100644 tests/tcg/openrisc/test_sflesi.c create mode 100644 tests/tcg/openrisc/test_sfleu.c create mode 100644 tests/tcg/openrisc/test_sfleui.c create mode 100644 tests/tcg/openrisc/test_sflts.c create mode 100644 tests/tcg/openrisc/test_sfltsi.c create mode 100644 tests/tcg/openrisc/test_sfltu.c create mode 100644 tests/tcg/openrisc/test_sfltui.c create mode 100644 tests/tcg/openrisc/test_sfne.c create mode 100644 tests/tcg/openrisc/test_sfnei.c create mode 100644 tests/tcg/openrisc/test_sub.c
Signature · 1 line
1.7.9.5
PATCH v5 1/16 target-or32: Add target stubs and cpu support
Add OpenRISC target stubs and basic cpu support.
--- arch_init.c | 2 + arch_init.h | 1 + configure | 14 +- cpu-exec.c | 2 + default-configs/or32-softmmu.mak | 6 + elf.h | 2 + hw/openrisc/Makefile.objs | 3 + hw/openrisc_cpudev.h | 29 ++++ hw/openrisc_pic.c | 30 ++++ hw/openrisc_timer.c | 30 ++++ poison.h | 1 + target-openrisc/Makefile.objs | 3 + target-openrisc/cpu.c | 240 +++++++++++++++++++++++++++++++ target-openrisc/cpu.h | 288 ++++++++++++++++++++++++++++++++++++++ target-openrisc/intrpt.c | 30 ++++ target-openrisc/machine.c | 30 ++++ target-openrisc/mmu.c | 39 ++++++ target-openrisc/mmu_helper.c | 43 ++++++ target-openrisc/translate.c | 75 ++++++++++ 19 files changed, 866 insertions(+), 2 deletions(-) create mode 100644 default-configs/or32-softmmu.mak create mode 100644 hw/openrisc/Makefile.objs create mode 100644 hw/openrisc_cpudev.h create mode 100644 hw/openrisc_pic.c create mode 100644 hw/openrisc_timer.c create mode 100644 target-openrisc/Makefile.objs create mode 100644 target-openrisc/cpu.c create mode 100644 target-openrisc/cpu.h create mode 100644 target-openrisc/intrpt.c create mode 100644 target-openrisc/machine.c create mode 100644 target-openrisc/mmu.c create mode 100644 target-openrisc/mmu_helper.c create mode 100644 target-openrisc/translate.c
arch_init.c +2 -0
@@ -71,6 +71,8 @@ int graphic_depth = 15;#define QEMU_ARCH QEMU_ARCH_MICROBLAZE#elif defined(TARGET_MIPS )#define QEMU_ARCH QEMU_ARCH_MIPS +#elif defined(TARGET_OPENRISC ) +#define QEMU_ARCH QEMU_ARCH_OPENRISC#elif defined(TARGET_PPC )#define QEMU_ARCH QEMU_ARCH_PPC#elif defined(TARGET_S390X )
arch_init.h +1 -0
@@ -16,6 +16,7 @@ enum {QEMU_ARCH_SH4 =1024 ,QEMU_ARCH_SPARC =2048 ,QEMU_ARCH_XTENSA =4096 , + QEMU_ARCH_OPENRISC = 8192, };extern const uint32_t arch_type;
configure +12 -2
@@ -925,6 +925,7 @@ mips-softmmu \ mipsel-softmmu \ mips64-softmmu \ mips64el-softmmu \ +or32-softmmu \ ppc-softmmu \ ppcemb-softmmu \ ppc64-softmmu \
@@ -3482,7 +3483,7 @@ target_arch2=`echo $target | cut -d '-' -f 1` target_bigendian="no" case "$target_arch2" in - armeb|lm32|m68k|microblaze|mips|mipsn32|mips64|ppc|ppcemb|ppc64|ppc64abi32|s390x|sh4eb|sparc|sparc64|sparc32plus|xtensaeb) + armeb|lm32|m68k|microblaze|mips|mipsn32|mips64|or32|ppc|ppcemb|ppc64|ppc64abi32|s390x|sh4eb|sparc|sparc64|sparc32plus|xtensaeb) target_bigendian=yes ;; esac
@@ -3598,6 +3599,11 @@ case "$target_arch2" in target_phys_bits=64 target_long_alignment=8 ;; + or32) + TARGET_ARCH=openrisc + TARGET_BASE_ARCH=openrisc + target_phys_bits=32 + ;; ppc) gdb_xml_files="power-core.xml power-fpu.xml power-altivec.xml power-spe.xml" target_phys_bits=64
@@ -3676,7 +3682,7 @@ symlink "$source_path/Makefile.target" "$target_dir/Makefile" case "$target_arch2" in - alpha | sparc* | xtensa*) + alpha | or32 | sparc* | xtensa*) echo "CONFIG_TCG_PASS_AREG0=y" >> $config_target_mak ;; esac
@@ -3847,6 +3853,10 @@ for i in $ARCH $TARGET_BASE_ARCH ; do echo "CONFIG_MIPS_DIS=y" >> $config_target_mak echo "CONFIG_MIPS_DIS=y" >> $libdis_config_mak ;; + or32) + echo "CONFIG_OPENRISC_DIS=y" >> $config_target_mak + echo "CONFIG_OPENRISC_DIS=y" >> $libdis_config_mak + ;; ppc*) echo "CONFIG_PPC_DIS=y" >> $config_target_mak echo "CONFIG_PPC_DIS=y" >> $libdis_config_mak
cpu-exec.c +2 -0
@@ -225,6 +225,7 @@ int cpu_exec(CPUArchState *env)#elif defined(TARGET_LM32 )#elif defined(TARGET_MICROBLAZE )#elif defined(TARGET_MIPS ) +#elif defined(TARGET_OPENRISC )#elif defined(TARGET_SH4 )#elif defined(TARGET_CRIS )#elif defined(TARGET_S390X )
@@ -630,6 +631,7 @@ int cpu_exec(CPUArchState *env) | env->cc_dest | (env->cc_x << 4);#elif defined(TARGET_MICROBLAZE )#elif defined(TARGET_MIPS ) +#elif defined(TARGET_OPENRISC )#elif defined(TARGET_SH4 )#elif defined(TARGET_ALPHA )#elif defined(TARGET_CRIS )
default-configs/or32-softmmu.mak new file +6 -0
@@ -0,0 +1,6 @@ +# Default configuration for or32-softmmu + +include pci.mak +CONFIG_SERIAL=y +CONFIG_NE2000_ISA=y +CONFIG_I8259=y
elf.h +2 -0
@@ -106,6 +106,8 @@ typedef int64_t Elf64_Sxword;#define EM_H8S 48/* Hitachi H8S */ #define EM_LATTICEMICO32 138/* LatticeMico32 */ +#define EM_OPENRISC 92/* OpenCores OpenRISC */ +#define EM_UNICORE32 110/* UniCore32 */ /*
hw/openrisc/Makefile.objs new file +3 -0
@@ -0,0 +1,3 @@ +obj-y = openrisc_pic.o openrisc_timer.o + +obj-y := $(addprefix ../,$(obj-y))
hw/openrisc_cpudev.h new file +29 -0
@@ -0,0 +1,29 @@ +/* +* QEMU OpenRISC CPU device support. +* +* Copyright (c) 2011-2012 Jia Liu <[email protected]> +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2 of the License, or (at your option) any later version. +* +* This library 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 +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef HW_OPENRISC_CPUDEV_H +#define HW_OPENRISC_CPUDEV_H + +/* openrisc_pic.c */ +void cpu_openrisc_pic_init (CPUOpenRISCState *env); + +/* openrisc_timer.c*/ +void cpu_openrisc_clock_init (CPUOpenRISCState *env); + +#endif
hw/openrisc_pic.c new file +30 -0
@@ -0,0 +1,30 @@ +/* +* OpenRISC Programmable Interrupt Controller support. +* +* Copyright (c) 2011-2012 Jia Liu <[email protected]> +* Feng Gao <[email protected]> +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2 of the License, or (at your option) any later version. +* +* This library 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 +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, see <http://www.gnu.org/licenses/>. +*/ + +#include "hw.h" +#include "openrisc_cpudev.h" +#include "cpu.h" + +/* Reset PIC */ +void cpu_openrisc_pic_reset (CPUOpenRISCState *env) +{ + env->picmr =0x00000000 ; + env->picsr =0x00000000 ; +}
hw/openrisc_timer.c new file +30 -0
@@ -0,0 +1,30 @@ +/* +* QEMU OpenRISC timer support +* +* Copyright (c) 2011-2012 Jia Liu <[email protected]> +* Zhizhou Zhang <[email protected]> +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2 of the License, or (at your option) any later version. +* +* This library 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 +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, see <http://www.gnu.org/licenses/>. +*/ + +#include "hw.h" +#include "openrisc_cpudev.h" +#include "qemu-timer.h" + +/* Reset Timer */ +void cpu_openrisc_timer_reset (CPUOpenRISCState *env) +{ + env->ttmr =0x00000000 ; + env->ttcr =0x00000000 ; +}
poison.h +1 -0
@@ -14,6 +14,7 @@#pragma GCC poison TARGET_M68K#pragma GCC poison TARGET_MIPS#pragma GCC poison TARGET_MIPS64 +#pragma GCC poison TARGET_OPENRISC#pragma GCC poison TARGET_PPC#pragma GCC poison TARGET_PPCEMB#pragma GCC poison TARGET_PPC64
target-openrisc/Makefile.objs new file +3 -0
@@ -0,0 +1,3 @@ +obj-$(CONFIG_SOFTMMU) += machine.o +obj-y += cpu.o intrpt.o mmu.o translate.o +obj-y += mmu_helper.o
target-openrisc/cpu.c new file +240 -0
240 lines not on this page · raw message
target-openrisc/cpu.h new file +288 -0
288 lines not on this page · raw message
target-openrisc/intrpt.c new file +30 -0
@@ -0,0 +1,30 @@ +/* +* OpenRISC interrupt. +* +* Copyright (c) 2011-2012 Jia Liu <[email protected]> +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2 of the License, or (at your option) any later version. +* +* This library 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 +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, see <http://www.gnu.org/licenses/>. +*/ + +#include "cpu.h" +#include "qemu-common.h" +#include "gdbstub.h" +#include "host-utils.h" +#if !defined(CONFIG_USER_ONLY ) +#include "hw/loader.h" +#endif + +void do_interrupt (CPUOpenRISCState *env) +{ +}
target-openrisc/machine.c new file +30 -0
@@ -0,0 +1,30 @@ +/* +* OpenRISC Machine +* +* Copyright (c) 2011-2012 Jia Liu <[email protected]> +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2 of the License, or (at your option) any later version. +* +* This library 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 +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, see <http://www.gnu.org/licenses/>. +*/ + +#include "hw/hw.h" +#include "hw/boards.h" + +void cpu_save (QEMUFile *f,void *opaque) +{ +} + +int cpu_load (QEMUFile *f,void *opaque,int version_id) +{ +return 0 ; +}
target-openrisc/mmu.c new file +39 -0
@@ -0,0 +1,39 @@ +/* +* OpenRISC MMU. +* +* Copyright (c) 2011-2012 Jia Liu <[email protected]> +* Zhizhou Zhang <[email protected]> +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2 of the License, or (at your option) any later version. +* +* This library 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 +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, see <http://www.gnu.org/licenses/>. +*/ + +#include "cpu.h" +#include "qemu-common.h" +#include "gdbstub.h" +#include "host-utils.h" +#if !defined(CONFIG_USER_ONLY ) +#include "hw/loader.h" +#endif + +#if !defined(CONFIG_USER_ONLY ) +target_phys_addr_t cpu_get_phys_page_debug (CPUOpenRISCState *env, +target_ulong addr) +{ +return addr; +} + +void openrisc_mmu_init (CPUOpenRISCState *env) +{ +} +#endif
target-openrisc/mmu_helper.c new file +43 -0
43 lines not on this page · raw message
target-openrisc/translate.c new file +75 -0
75 lines not on this page · raw message
Signature · 1 line
1.7.9.5
PATCH v5 2/16 target-or32: Add target machine
In reply to Jia LiuAdd OpenRISC target machine.
--- target-openrisc/cpu.h | 67 ++++++++++++++++++++++++++++++++++++++++++++- target-openrisc/machine.c | 22 ++++++++++++++- 2 files changed, 87 insertions(+), 2 deletions(-)
target-openrisc/cpu.h +66 -1
@@ -44,6 +44,15 @@ struct CPUOpenRISCState;#define TARGET_PHYS_ADDR_SPACE_BITS 32#define TARGET_VIRT_ADDR_SPACE_BITS 32 +#define SET_FP_CAUSE (reg, v) do {\ + (reg) = ((reg) & ~(0x3f << 12)) | \ + ((v & 0x3f) << 12);\ + } while (0) +#define GET_FP_ENABLE (reg) (((reg) >> 7) & 0x1f) +#define UPDATE_FP_FLAGS (reg, v) do {\ + (reg) |= ((v & 0x1f) << 2);\ + } while (0) +/* Internel flags, delay slot flag */ #define D_FLAG 1
@@ -117,6 +126,40 @@ enum { IMMUCFGR_HTR = (1 << 11), }; +/* Float piont control status register */ +enum { +FPCSR_FPEE =1 , +FPCSR_RM = (3 <<1 ), +FPCSR_OVF = (1 <<3 ), +FPCSR_UNF = (1 <<4 ), +FPCSR_SNF = (1 <<5 ), +FPCSR_QNF = (1 <<6 ), +FPCSR_ZF = (1 <<7 ), +FPCSR_IXF = (1 <<8 ), +FPCSR_IVF = (1 <<9 ), +FPCSR_INF = (1 <<10 ), +FPCSR_DZF = (1 <<11 ), +}; + +/* Exceptions indices */ +enum { +EXCP_RESET =0x1 , +EXCP_BUSERR =0x2 , +EXCP_DPF =0x3 , +EXCP_IPF =0x4 , +EXCP_TICK =0x5 , +EXCP_ALIGN =0x6 , +EXCP_ILLEGAL =0x7 , +EXCP_INT =0x8 , +EXCP_DTLBMISS =0x9 , +EXCP_ITLBMISS =0xa , +EXCP_RANGE =0xb , +EXCP_SYSCALL =0xc , +EXCP_FPE =0xd , +EXCP_TRAP =0xe , +EXCP_NR , +}; +/* Supervisor register */ enum {SR_SM =1 ,
@@ -151,6 +194,14 @@ enum { OPENRISC_FEATURE_OR1200, }; +/* Tick Timer Mode Register */ +enum { +TTMR_TP = (0xfffffff ), +TTMR_IP = (1 <<28 ), +TTMR_IE = (1 <<29 ), +TTMR_M = (3 <<30 ), +}; +typedef struct CPUOpenRISCState CPUOpenRISCState ;struct CPUOpenRISCState {target_ulong gpr[32 ];/* General registers */
@@ -159,12 +210,25 @@ struct CPUOpenRISCState {target_ulong ppc;/* Prev PC */ target_ulong jmp_pc;/* Jump PC */ +target_ulong machi;/* Multiply register MACHI */ +target_ulong maclo;/* Multiply register MACLO */ + +target_ulong fpmaddhi;/* Multiply and add float register FPMADDHI */ +target_ulong fpmaddlo;/* Multiply and add float register FPMADDLO */ + +target_ulong epcr;/* Exception PC register */ +target_ulong eear;/* Exception EA register */ +uint32_t sr;/* Supervisor register */ uint32_t vr;/* Version register */ uint32_t upr;/* Unit presence register */ uint32_t cpucfgr;/* CPU configure register */ uint32_t dmmucfgr;/* DMMU configure register */ uint32_t immucfgr;/* IMMU configure register */ +uint32_t esr;/* Exception supervisor register */ +uint32_t fpcsr;/* Float register */ +float_status fp_status; +uint32_t flags;/* cpu_flags, we only use it for exception in solt so far. */ uint32_t btaken;/* the SR_F bit */
@@ -265,7 +329,8 @@ static inline void cpu_get_tb_cpu_state(CPUOpenRISCState *env, { *pc = env->pc; *cs_base =0 ; - *flags =0 ; +/* D_FLAG -- branch insrtuction exception */ + *flags = (env->flags&D_FLAG ); }static inline int cpu_mmu_index (CPUOpenRISCState *env)
target-openrisc/machine.c +21 -1
@@ -20,11 +20,31 @@#include "hw/hw.h" #include "hw/boards.h" +static const VMStateDescription vmstate_cpu = { + .name ="cpu" , + .version_id =CPU_SAVE_VERSION , + .minimum_version_id =1 , + .minimum_version_id_old =1 , + .fields = (VMStateField []) { +VMSTATE_UINT32_ARRAY (gpr, CPUOpenRISCState,32 ), +VMSTATE_UINT32 (sr, CPUOpenRISCState), +VMSTATE_UINT32 (epcr, CPUOpenRISCState), +VMSTATE_UINT32 (eear, CPUOpenRISCState), +VMSTATE_UINT32 (esr, CPUOpenRISCState), +VMSTATE_UINT32 (fpcsr, CPUOpenRISCState), +VMSTATE_UINT32 (pc, CPUOpenRISCState), +VMSTATE_UINT32 (npc, CPUOpenRISCState), +VMSTATE_UINT32 (ppc, CPUOpenRISCState), +VMSTATE_END_OF_LIST () + } +}; +void cpu_save (QEMUFile *f,void *opaque) { +vmstate_save_state (f, &vmstate_cpu, opaque); }int cpu_load (QEMUFile *f,void *opaque,int version_id) { -return 0 ; +return vmstate_load_state (f, &vmstate_cpu, opaque, version_id); }
Signature · 1 line
1.7.9.5
PATCH v5 3/16 target-or32: Add MMU support
In reply to Jia LiuAdd OpenRISC MMU support.
--- target-openrisc/cpu.h | 75 +++++++++++++++- target-openrisc/mmu.c | 199 +++++++++++++++++++++++++++++++++++++++++- target-openrisc/mmu_helper.c | 20 +++++ 3 files changed, 292 insertions(+), 2 deletions(-)
target-openrisc/cpu.h +74 -1
@@ -39,6 +39,12 @@ struct CPUOpenRISCState;#define NB_MMU_MODES 3 +enum { +MMU_NOMMU_IDX =0 , +MMU_SUPERVISOR_IDX =1 , +MMU_USER_IDX =2 , +}; +#define TARGET_PAGE_BITS 13#define TARGET_PHYS_ADDR_SPACE_BITS 32
@@ -202,6 +208,54 @@ enum { TTMR_M = (3 << 30), }; +/* TLB size */ +enum { +DTLB_WAYS =1 , +DTLB_SIZE =64 , +DTLB_MASK = (DTLB_SIZE -1 ), +ITLB_WAYS =1 , +ITLB_SIZE =64 , +ITLB_MASK = (ITLB_SIZE -1 ), +}; + +/* TLB prot */ +enum { +URE = (1 <<6 ), +UWE = (1 <<7 ), +SRE = (1 <<8 ), +SWE = (1 <<9 ), + +SXE = (1 <<6 ), +UXE = (1 <<7 ), +}; + +/* check if tlb available */ +enum { +TLBRET_INVALID =-3 , +TLBRET_NOMATCH =-2 , +TLBRET_BADADDR =-1 , +TLBRET_MATCH =0 +}; + +typedef struct OpenRISCTLBEntry { +uint32_t mr; +uint32_t tr; +}OpenRISCTLBEntry ; + +#if !defined(CONFIG_USER_ONLY ) +typedef struct CPUOpenRISCTLBContext { +OpenRISCTLBEntry itlb[ITLB_WAYS ][ITLB_SIZE ]; +OpenRISCTLBEntry dtlb[DTLB_WAYS ][DTLB_SIZE ]; + +int (*map_address_code)(struct CPUOpenRISCState *env, +target_phys_addr_t *physical,int *prot, +target_ulong address,int rw); +int (*map_address_data)(struct CPUOpenRISCState *env, +target_phys_addr_t *physical,int *prot, +target_ulong address,int rw); +}CPUOpenRISCTLBContext ; +#endif +typedef struct CPUOpenRISCState CPUOpenRISCState ;struct CPUOpenRISCState {target_ulong gpr[32 ];/* General registers */
@@ -236,6 +290,8 @@ struct CPUOpenRISCState { CPU_COMMON#if !defined(CONFIG_USER_ONLY ) +CPUOpenRISCTLBContext * tlb; +struct QEMUTimer *timer;uint32_t ttmr;/* Timer tick mode register */ uint32_t ttcr;/* Timer tick count register */
@@ -297,19 +353,33 @@ OpenRISCCPU *cpu_openrisc_init(const char *cpu_model);int cpu_openrisc_exec (CPUOpenRISCState *s);void do_interrupt (CPUOpenRISCState *env);void openrisc_translate_init (void ); +int cpu_openrisc_handle_mmu_fault (CPUOpenRISCState *env,target_ulong address, +int rw,int mmu_idx);#define cpu_list cpu_openrisc_list#define cpu_exec cpu_openrisc_exec#define cpu_gen_code cpu_openrisc_gen_code +#define cpu_handle_mmu_fault cpu_openrisc_handle_mmu_fault#define CPU_SAVE_VERSION 1#if !defined(CONFIG_USER_ONLY )void cpu_openrisc_pic_reset (CPUOpenRISCState *env); +void cpu_openrisc_store_picsr (CPUOpenRISCState *env,uint32_t value); +void cpu_openrisc_store_picmr (CPUOpenRISCState *env,uint32_t value);void cpu_openrisc_timer_reset (CPUOpenRISCState *env); +void cpu_openrisc_store_count (CPUOpenRISCState *env,target_ulong count); +void cpu_openrisc_store_compare (CPUOpenRISCState *env,target_ulong value); +uint32_t cpu_openrisc_get_count (CPUOpenRISCState *env);void openrisc_mmu_init (CPUOpenRISCState *env); +int get_phys_nommu (CPUOpenRISCState *env,target_phys_addr_t *physical, +int *prot,target_ulong address,int rw); +int get_phys_code (CPUOpenRISCState *env,target_phys_addr_t *physical, +int *prot,target_ulong address,int rw); +int get_phys_data (CPUOpenRISCState *env,target_phys_addr_t *physical, +int *prot,target_ulong address,int rw);#endif static inline CPUOpenRISCState *cpu_init (const char *cpu_model)
@@ -335,7 +405,10 @@ static inline void cpu_get_tb_cpu_state(CPUOpenRISCState *env,static inline int cpu_mmu_index (CPUOpenRISCState *env) { -return 0 ; +if (!(env->sr &SR_IME )) { +return MMU_NOMMU_IDX ; + } +return (env->sr &SR_SM ) ==0 ?MMU_USER_IDX :MMU_SUPERVISOR_IDX ; }static inline bool cpu_has_work (CPUOpenRISCState *env)
target-openrisc/mmu.c +198 -1
211 lines not on this page · raw message
target-openrisc/mmu_helper.c +20 -0
@@ -39,5 +39,25 @@void tlb_fill (CPUOpenRISCState *env,target_ulong addr,int is_write,int mmu_idx,uintptr_t retaddr) { +TranslationBlock *tb; +unsigned long pc; +int ret; + + ret =cpu_openrisc_handle_mmu_fault (env, addr, is_write, mmu_idx); + +if (ret) { +if (retaddr) { +/* now we have a real cpu fault. */ + pc = (unsigned long )retaddr; + tb =tb_find_pc (pc); +if (tb) { +/* the PC is inside the translated code. It means that we +have a virtual CPU fault. */ +cpu_restore_state (tb, env, pc); + } + } +/* Raise Exception. */ +cpu_loop_exit (env); + } }#endif
Signature · 1 line
1.7.9.5
PATCH v5 4/16 target-or32: Add interrupt support
In reply to Jia LiuAdd OpenRISC interrupt support.
--- cpu-exec.c | 17 +++++++++++++ target-openrisc/Makefile.objs | 2 +- target-openrisc/cpu.h | 9 ++++++- target-openrisc/helper.h | 25 +++++++++++++++++++ target-openrisc/intrpt.c | 44 +++++++++++++++++++++++++++++++++ target-openrisc/intrpt_helper.c | 52 +++++++++++++++++++++++++++++++++++++++ 6 files changed, 147 insertions(+), 2 deletions(-) create mode 100644 target-openrisc/helper.h create mode 100644 target-openrisc/intrpt_helper.c
cpu-exec.c +17 -0
@@ -378,6 +378,23 @@ int cpu_exec(CPUArchState *env)do_interrupt (env); next_tb =0 ; } +#elif defined(TARGET_OPENRISC ) + { +int idx =-1 ; +if ((interrupt_request &CPU_INTERRUPT_HARD ) + && (env->sr &SR_IEE )) { + idx =EXCP_INT ; + } +if ((interrupt_request &CPU_INTERRUPT_TIMER ) + && (env->sr &SR_TEE )) { + idx =EXCP_TICK ; + } +if (idx >=0 ) { + env->exception_index = idx; +do_interrupt (env); + next_tb =0 ; + } + }#elif defined(TARGET_SPARC )if (interrupt_request &CPU_INTERRUPT_HARD ) { if (cpu_interrupts_enabled(env) &&
target-openrisc/Makefile.objs +1 -1
@@ -1,3 +1,3 @@ obj-$(CONFIG_SOFTMMU) += machine.o obj-y += cpu.o intrpt.o mmu.o translate.o -obj-y += mmu_helper.o +obj-y += intrpt_helper.o mmu_helper.o
target-openrisc/cpu.h +8 -1
@@ -62,6 +62,10 @@ enum {/* Internel flags, delay slot flag */ #define D_FLAG 1 +/* Interrupt */ +#define NR_IRQS 32 +#define PIC_MASK 0xFFFFFFFF +/* Verison Register */ #define SPR_VR 0xFFFF003F
@@ -300,6 +304,7 @@ struct CPUOpenRISCState {uint32_t picsr;/* Interrupt contrl register*/ #endif uint32_t feature;/* CPU Capabilities */ +void *irq[32 ];/* Interrupt irq input */ };#define TYPE_OPENRISC_CPU "or32-cpu"
@@ -411,9 +416,11 @@ static inline int cpu_mmu_index(CPUOpenRISCState *env)return (env->sr &SR_SM ) ==0 ?MMU_USER_IDX :MMU_SUPERVISOR_IDX ; } +#define CPU_INTERRUPT_TIMER CPU_INTERRUPT_TGT_INT_0static inline bool cpu_has_work (CPUOpenRISCState *env) { -return true; +return env->interrupt_request & (CPU_INTERRUPT_HARD | +CPU_INTERRUPT_TIMER ); }#include "exec-all.h"
target-openrisc/helper.h new file +25 -0
@@ -0,0 +1,25 @@ +/* +* OpenRISC helper defines +* +* Copyright (c) 2011-2012 Jia Liu <[email protected]> +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2 of the License, or (at your option) any later version. +* +* This library 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 +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, see <http://www.gnu.org/licenses/>. +*/ + +#include "def-helper.h" + +/* interrupt */ +DEF_HELPER_FLAGS_1(rfe, 0, void, env) + +#include "def-helper.h"
target-openrisc/intrpt.c +44 -0
48 lines not on this page · raw message
target-openrisc/intrpt_helper.c new file +52 -0
52 lines not on this page · raw message
Signature · 1 line
1.7.9.5
PATCH v5 5/16 target-or32: Add exception support
In reply to Jia LiuAdd OpenRISC exception support.
--- target-openrisc/Makefile.objs | 4 ++-- target-openrisc/excp.c | 27 +++++++++++++++++++++++++++ target-openrisc/excp.h | 28 ++++++++++++++++++++++++++++ target-openrisc/excp_helper.c | 27 +++++++++++++++++++++++++++ target-openrisc/helper.h | 3 +++ 5 files changed, 87 insertions(+), 2 deletions(-) create mode 100644 target-openrisc/excp.c create mode 100644 target-openrisc/excp.h create mode 100644 target-openrisc/excp_helper.c
target-openrisc/Makefile.objs +2 -2
@@ -1,3 +1,3 @@ obj-$(CONFIG_SOFTMMU) += machine.o -obj-y += cpu.o intrpt.o mmu.o translate.o -obj-y += intrpt_helper.o mmu_helper.o +obj-y += cpu.o excp.o intrpt.o mmu.o translate.o +obj-y += excp_helper.o intrpt_helper.o mmu_helper.o
target-openrisc/excp.c new file +27 -0
@@ -0,0 +1,27 @@ +/* +* OpenRISC exception. +* +* Copyright (c) 2011-2012 Jia Liu <[email protected]> +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2 of the License, or (at your option) any later version. +* +* This library 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 +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, see <http://www.gnu.org/licenses/>. +*/ + +#include "cpu.h" +#include "excp.h" + +void QEMU_NORETURN raise_exception(CPUOpenRISCState *env, uint32_t excp) +{ + env->exception_index = excp; +cpu_loop_exit (env); +}
target-openrisc/excp.h new file +28 -0
@@ -0,0 +1,28 @@ +/* +* OpenRISC exception header. +* +* Copyright (c) 2011-2012 Jia Liu <[email protected]> +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2 of the License, or (at your option) any later version. +* +* This library 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 +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef QEMU_OPENRISC_EXCP_H +#define QEMU_OPENRISC_EXCP_H + +#include "cpu.h" +#include "qemu-common.h" + +void QEMU_NORETURN raise_exception(CPUOpenRISCState *env, uint32_t excp); + +#endif /* QEMU_OPENRISC_EXCP_H */
target-openrisc/excp_helper.c new file +27 -0
@@ -0,0 +1,27 @@ +/* +* OpenRISC exception helper routines +* +* Copyright (c) 2011-2012 Jia Liu <[email protected]> +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2 of the License, or (at your option) any later version. +* +* This library 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 +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, see <http://www.gnu.org/licenses/>. +*/ + +#include "cpu.h" +#include "helper.h" +#include "excp.h" + +void HELPER (exception )(CPUOpenRISCState *env,uint32_t excp) +{ +raise_exception (env, excp); +}
target-openrisc/helper.h +3 -0
@@ -19,6 +19,9 @@#include "def-helper.h" +/* exception */ +DEF_HELPER_FLAGS_2 (exception,0 , void, env, i32) + /* interrupt */DEF_HELPER_FLAGS_1 (rfe,0 , void, env)
Signature · 1 line
1.7.9.5
PATCH v5 6/16 target-or32: Add int instruction helpers
In reply to Jia LiuAdd OpenRISC int instruction helpers.
--- target-openrisc/Makefile.objs | 2 +- target-openrisc/helper.h | 4 ++++ target-openrisc/int_helper.c | 51 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 target-openrisc/int_helper.c
target-openrisc/Makefile.objs +1 -1
@@ -1,3 +1,3 @@ obj-$(CONFIG_SOFTMMU) += machine.o obj-y += cpu.o excp.o intrpt.o mmu.o translate.o -obj-y += excp_helper.o intrpt_helper.o mmu_helper.o +obj-y += excp_helper.o int_helper.o intrpt_helper.o mmu_helper.o
target-openrisc/helper.h +4 -0
@@ -22,6 +22,10 @@/* exception */ DEF_HELPER_FLAGS_2 (exception,0 , void, env, i32) +/* int */ +DEF_HELPER_FLAGS_1(ff1, 0, tl, tl) +DEF_HELPER_FLAGS_1 (fl1,0 , tl, tl) + /* interrupt */DEF_HELPER_FLAGS_1 (rfe,0 , void, env)
target-openrisc/int_helper.c new file +51 -0
51 lines not on this page · raw message
Signature · 1 line
1.7.9.5
PATCH v5 7/16 target-or32: Add float instruction helpers
In reply to Jia LiuAdd OpenRISC float instruction helpers.
--- target-openrisc/Makefile.objs | 2 +- target-openrisc/fpu_helper.c | 275 +++++++++++++++++++++++++++++++++++++++++ target-openrisc/helper.h | 33 +++++ 3 files changed, 309 insertions(+), 1 deletion(-) create mode 100644 target-openrisc/fpu_helper.c
target-openrisc/Makefile.objs +1 -1
@@ -1,3 +1,3 @@ obj-$(CONFIG_SOFTMMU) += machine.o obj-y += cpu.o excp.o intrpt.o mmu.o translate.o -obj-y += excp_helper.o int_helper.o intrpt_helper.o mmu_helper.o +obj-y += excp_helper.o fpu_helper.o int_helper.o intrpt_helper.o mmu_helper.o
target-openrisc/fpu_helper.c new file +275 -0
275 lines not on this page · raw message
target-openrisc/helper.h +33 -0
@@ -22,6 +22,39 @@/* exception */ DEF_HELPER_FLAGS_2 (exception,0 , void, env, i32) +/* float */ +DEF_HELPER_FLAGS_2(itofd, 0, i64, env, i64) +DEF_HELPER_FLAGS_2(itofs, 0, i32, env, i32) +DEF_HELPER_FLAGS_2(ftoid, 0, i64, env, i64) +DEF_HELPER_FLAGS_2(ftois, 0, i32, env, i32) + +#define FOP_MADD (op) \ +DEF_HELPER_FLAGS_3(float_ ## op ## _s, 0, i32, env, i32, i32) \ +DEF_HELPER_FLAGS_3(float_ ## op ## _d, 0, i64, env, i64, i64) +FOP_MADD(muladd) +#undef FOP_MADD + +#define FOP_CALC (op) \ +DEF_HELPER_FLAGS_3(float_ ## op ## _s, 0, i32, env, i32, i32) \ +DEF_HELPER_FLAGS_3(float_ ## op ## _d, 0, i64, env, i64, i64) +FOP_CALC(add) +FOP_CALC(sub) +FOP_CALC(mul) +FOP_CALC(div) +FOP_CALC(rem) +#undef FOP_CALC + +#define FOP_CMP(op) \ +DEF_HELPER_FLAGS_3(float_ ## op ## _s, 0, i32, env, i32, i32) \ +DEF_HELPER_FLAGS_3(float_ ## op ## _d, 0, i64, env, i64, i64) +FOP_CMP(eq) +FOP_CMP(lt) +FOP_CMP(le) +FOP_CMP(ne) +FOP_CMP(gt) +FOP_CMP(ge) +#undef FOP_CMP + /* int */ DEF_HELPER_FLAGS_1(ff1, 0, tl, tl) DEF_HELPER_FLAGS_1(fl1, 0, tl, tl)
Signature · 1 line
1.7.9.5
PATCH v5 9/16 target-or32: Add PIC support
In reply to Jia LiuAdd OpenRISC Programmable Interrupt Controller.
--- hw/openrisc_pic.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+)
hw/openrisc_pic.c +48 -0
@@ -28,3 +28,51 @@ void cpu_openrisc_pic_reset(CPUOpenRISCState *env) env->picmr =0x00000000 ; env->picsr =0x00000000 ; } + +/* OpenRISC pic handler */ +static void openrisc_pic_cpu_handler (void *opaque,int irq,int level) +{ +CPUOpenRISCState *env = (CPUOpenRISCState *)opaque; +int i; +uint32_t irq_bit =1 << irq; + +if (irq >31 || irq <0 ) { +return ; + } + +if (level) { + env->picsr |= irq_bit; + }else { + env->picsr &= ~irq_bit; + } + +for (i =0 ; i <32 ; i++) { +if ((env->picsr && (1 << i)) && (env->picmr && (1 << i))) { +cpu_interrupt (env,CPU_INTERRUPT_HARD ); + }else { +cpu_reset_interrupt (env,CPU_INTERRUPT_HARD ); + env->picsr &= ~(1 << i); + } + } +} + +void cpu_openrisc_pic_init (CPUOpenRISCState *env) +{ +int i; +qemu_irq *qi; + qi =qemu_allocate_irqs (openrisc_pic_cpu_handler, env,NR_IRQS ); + +for (i =0 ; i <NR_IRQS ; i++) { + env->irq[i] = qi[i]; + } +} + +void cpu_openrisc_store_picmr (CPUOpenRISCState *env,uint32_t value) +{ + env->picmr |= value; +} + +void cpu_openrisc_store_picsr (CPUOpenRISCState *env,uint32_t value) +{ + env->picsr &= ~value; +}
Signature · 1 line
1.7.9.5
PATCH v5 8/16 target-or32: Add translation routines
In reply to Jia LiuAdd OpenRISC translation routines.
--- target-openrisc/translate.c | 1941 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 1941 insertions(+)
target-openrisc/translate.c +1941 -0
@@ -26,6 +26,10 @@#include "qemu-log.h" #include "config.h" +#include "helper.h" +#define GEN_HELPER 1 +#include "helper.h" +#define OPENRISC_DISAS #ifdef OPENRISC_DISAS
@@ -34,14 +38,1951 @@# define LOG_DIS (...) do { } while (0)#endif +typedef struct DisasContext { +CPUOpenRISCState *env; +TranslationBlock *tb; +target_ulong pc, ppc, npc; +uint32_t tb_flags, synced_flags, flags; +uint32_t is_jmp; +uint32_t mem_idx; +int singlestep_enabled; +uint32_t delayed_branch; +}DisasContext ; + +static TCGv_ptr cpu_env; +static TCGv cpu_sr; +static TCGv cpu_R[32 ]; +static TCGv cpu_pc; +static TCGv jmp_pc;/* l.jr/l.jalr temp pc */ +static TCGv cpu_npc; +static TCGv cpu_ppc; +static TCGv_i32 env_btaken;/* bf/bnf , F flag taken */ +static TCGv_i32 fpcsr; +static TCGv machi, maclo; +static TCGv fpmaddhi, fpmaddlo; +static TCGv_i32 env_flags; +#include "gen-icount.h" +void openrisc_translate_init (void ) { +static const char *const regnames[] = { +"r0" ,"r1" ,"r2" ,"r3" ,"r4" ,"r5" ,"r6" ,"r7" , +"r8" ,"r9" ,"r10" ,"r11" ,"r12" ,"r13" ,"r14" ,"r15" , +"r16" ,"r17" ,"r18" ,"r19" ,"r20" ,"r21" ,"r22" ,"r23" , +"r24" ,"r25" ,"r26" ,"r27" ,"r28" ,"r29" ,"r30" ,"r31" , + }; +int i; + + cpu_env =tcg_global_reg_new_ptr (TCG_AREG0 ,"env" ); + cpu_sr =tcg_global_mem_new (TCG_AREG0 , + offsetof(CPUOpenRISCState , sr),"sr" ); + env_flags =tcg_global_mem_new_i32 (TCG_AREG0 , + offsetof(CPUOpenRISCState , flags), +"flags" ); + cpu_pc =tcg_global_mem_new (TCG_AREG0 , + offsetof(CPUOpenRISCState , pc),"pc" ); + cpu_npc =tcg_global_mem_new (TCG_AREG0 , + offsetof(CPUOpenRISCState , npc),"npc" ); + cpu_ppc =tcg_global_mem_new (TCG_AREG0 , + offsetof(CPUOpenRISCState , ppc),"ppc" ); + jmp_pc =tcg_global_mem_new (TCG_AREG0 , + offsetof(CPUOpenRISCState , jmp_pc),"jmp_pc" ); + env_btaken =tcg_global_mem_new_i32 (TCG_AREG0 , + offsetof(CPUOpenRISCState , btaken), +"btaken" ); + fpcsr =tcg_global_mem_new_i32 (TCG_AREG0 , + offsetof(CPUOpenRISCState , fpcsr), +"fpcsr" ); + machi =tcg_global_mem_new (TCG_AREG0 , + offsetof(CPUOpenRISCState , machi), +"machi" ); + maclo =tcg_global_mem_new (TCG_AREG0 , + offsetof(CPUOpenRISCState , maclo), +"maclo" ); + fpmaddhi =tcg_global_mem_new (TCG_AREG0 , + offsetof(CPUOpenRISCState , fpmaddhi), +"fpmaddhi" ); + fpmaddlo =tcg_global_mem_new (TCG_AREG0 , + offsetof(CPUOpenRISCState , fpmaddlo), +"fpmaddlo" ); +for (i =0 ; i <32 ; i++) { + cpu_R[i] =tcg_global_mem_new (TCG_AREG0 , + offsetof(CPUOpenRISCState, gpr[i]), + regnames[i]); + } +#define GEN_HELPER 2 +#include "helper.h" +} + +/* Writeback SR_F transaltion-space to execution-space. */ +static inline void wb_SR_F (void ) +{ +int label; + + label =gen_new_label (); +tcg_gen_andi_tl (cpu_sr, cpu_sr, ~SR_F ); +tcg_gen_brcondi_tl (TCG_COND_EQ , env_btaken,0 , label); +tcg_gen_ori_tl (cpu_sr, cpu_sr,SR_F ); +gen_set_label (label); +} + +static inline int zero_extend (unsigned int val,int width) +{ +return val & ((1 << width) -1 ); +} + +static inline int sign_extend (unsigned int val,int width) +{ +int sval; + +/* LSL */ + val <<=TARGET_LONG_BITS - width; + sval = val; +/* ASR. */ + sval >>=TARGET_LONG_BITS - width; +return sval; +} + +static inline void gen_sync_flags (DisasContext *dc) +{ +/* Sync the tb dependent flag between translate and runtime. */ +if (dc->tb_flags != dc->synced_flags) { +tcg_gen_movi_tl (env_flags, dc->tb_flags); + dc->synced_flags = dc->tb_flags; + } +} + +static void gen_exception (DisasContext *dc,unsigned int excp) +{ +TCGv_i32 tmp =tcg_const_i32 (excp); +gen_helper_exception (cpu_env, tmp); +tcg_temp_free_i32 (tmp); +} + +static void gen_illegal_exception (DisasContext *dc) +{ +tcg_gen_movi_tl (cpu_pc, dc->pc); +gen_exception (dc,EXCP_ILLEGAL ); + dc->is_jmp =DISAS_UPDATE ; +} + +#ifdef TARGET_OPENRISC64 +static void check_ob64s (DisasContext *dc) +{ +if (!(dc->flags &CPUCFGR_OB64S )) { +gen_illegal_exception (dc); + } +} + +static void check_of64s (DisasContext *dc) +{ +if (!(dc->flags &CPUCFGR_OF64S )) { +gen_illegal_exception (dc); + } +} + +/* not used yet, open it when we need or64. */ +/*static void check_ov64s(DisasContext *dc) +{ +if (!(dc->flags & CPUCFGR_OV64S)) { +gen_illegal_exception(dc); +} +}*/ +#endif + +static void gen_goto_tb (DisasContext *dc,int n,target_ulong dest) +{ +TranslationBlock *tb; + tb = dc->tb; +if ((tb->pc &TARGET_PAGE_MASK ) == (dest &TARGET_PAGE_MASK ) && +likely (!dc->singlestep_enabled)) { +tcg_gen_movi_tl (cpu_pc, dest); +tcg_gen_goto_tb (n); +tcg_gen_exit_tb ((tcg_target_long )tb + n); + }else { +tcg_gen_movi_tl (cpu_pc, dest); +if (dc->singlestep_enabled) { +gen_exception (dc,EXCP_DEBUG ); + } +tcg_gen_exit_tb (0 ); + } +} + +static void gen_jump (DisasContext *dc,uint32_t imm,uint32_t reg,uint32_t op0) +{ +target_ulong tmp_pc; +int lab =gen_new_label (); +TCGv sr_f =tcg_temp_new (); +/* N26, 26bits imm */ + tmp_pc =sign_extend ((imm<<2 ),26 ) + dc->pc; +tcg_gen_andi_tl (sr_f, cpu_sr,SR_F ); + +if (op0 ==0x00 ) {/*l.j*/ +tcg_gen_movi_tl (jmp_pc, tmp_pc); + }else if (op0 ==0x01 ) {/*l.jal*/ +tcg_gen_movi_tl (cpu_R[9 ], (dc->pc +8 )); +tcg_gen_movi_tl (jmp_pc, tmp_pc); + }else if (op0 ==0x03 ) {/*l.bnf*/ +tcg_gen_movi_tl (jmp_pc, dc->pc+8 ); +tcg_gen_brcondi_i32 (TCG_COND_EQ , sr_f,SR_F , lab); +tcg_gen_movi_tl (jmp_pc, tmp_pc); +gen_set_label (lab); + }else if (op0 ==0x04 ) {/*l.bf*/ +tcg_gen_movi_tl (jmp_pc, dc->pc+8 ); +tcg_gen_brcondi_i32 (TCG_COND_NE , sr_f,SR_F , lab); +tcg_gen_movi_tl (jmp_pc, tmp_pc); +gen_set_label (lab); + }else if (op0 ==0x11 ) {/*l.jr*/ +tcg_gen_mov_tl (jmp_pc, cpu_R[reg]); + }else if (op0 ==0x12 ) {/*l.jalr*/ +tcg_gen_movi_tl (cpu_R[9 ], (dc->pc +8 )); +tcg_gen_mov_tl (jmp_pc, cpu_R[reg]); + }else { +gen_illegal_exception (dc); + } + +tcg_temp_free (sr_f); + dc->delayed_branch =2 ; + dc->tb_flags |=D_FLAG ; +gen_sync_flags (dc); +} + +static inline uint32_t field (uint32_t val,int start,int length) +{ + val >>= start; + val &= ~(~0 << length); +return val; +} + +static void dec_calc (DisasContext *dc,CPUOpenRISCState *env,uint32_t insn) +{ +uint32_t op0, op1, op2; +uint32_t ra, rb, rd; + op0 =field (insn,0 ,4 ); + op1 =field (insn,8 ,2 ); + op2 =field (insn,6 ,2 ); + ra =field (insn,16 ,5 ); + rb =field (insn,11 ,5 ); + rd =field (insn,21 ,5 ); + +switch (op0) { +case 0x0000 : +switch (op1) { +case 0x00 :/*l.add*/ +LOG_DIS ("l.add r%d, r%d, r%d\n" , rd, ra, rb); + { +int lab =gen_new_label (); +TCGv_i64 ta =tcg_temp_new_i64 (); +TCGv_i64 tb =tcg_temp_new_i64 (); +TCGv_i64 td =tcg_temp_local_new_i64 (); +TCGv_i32 res =tcg_temp_local_new_i32 (); +TCGv_i32 sr_ove =tcg_temp_local_new_i32 (); +tcg_gen_extu_i32_i64 (ta, cpu_R[ra]); +tcg_gen_extu_i32_i64 (tb, cpu_R[rb]); +tcg_gen_add_i64 (td, ta, tb); +tcg_gen_trunc_i64_i32 (res, td); +tcg_gen_shri_i64 (td, td,31 ); +tcg_gen_andi_i64 (td, td,0x3 ); +/* Jump to lab when no overflow. */ +tcg_gen_brcondi_i64 (TCG_COND_EQ , td,0x0 , lab); +tcg_gen_brcondi_i64 (TCG_COND_EQ , td,0x3 , lab); +tcg_gen_ori_i32 (cpu_sr, cpu_sr, (SR_OV |SR_CY )); +tcg_gen_andi_i32 (sr_ove, cpu_sr,SR_OVE ); +tcg_gen_brcondi_i32 (TCG_COND_NE , sr_ove,SR_OVE , lab); +gen_exception (dc,EXCP_RANGE ); +gen_set_label (lab); +tcg_gen_mov_i32 (cpu_R[rd], res); +tcg_temp_free_i64 (ta); +tcg_temp_free_i64 (tb); +tcg_temp_free_i64 (td); +tcg_temp_free_i32 (res); +tcg_temp_free_i32 (sr_ove); + } +break ; +default : +gen_illegal_exception (dc); +break ; + } +break ; + +case 0x0001 :/*l.addc*/ +switch (op1) { +case 0x00 : +LOG_DIS ("l.addc r%d, r%d, r%d\n" , rd, ra, rb); + { +int lab =gen_new_label (); +TCGv_i64 ta =tcg_temp_new_i64 (); +TCGv_i64 tb =tcg_temp_new_i64 (); +TCGv_i64 tcy =tcg_temp_local_new_i64 (); +TCGv_i64 td =tcg_temp_local_new_i64 (); +TCGv_i32 res =tcg_temp_local_new_i32 (); +TCGv_i32 sr_cy =tcg_temp_local_new_i32 (); +TCGv_i32 sr_ove =tcg_temp_local_new_i32 (); +tcg_gen_extu_i32_i64 (ta, cpu_R[ra]); +tcg_gen_extu_i32_i64 (tb, cpu_R[rb]); +tcg_gen_andi_i32 (sr_cy, cpu_sr,SR_CY ); +tcg_gen_extu_i32_i64 (tcy, sr_cy); +tcg_gen_shri_i64 (tcy, tcy,10 ); +tcg_gen_add_i64 (td, ta, tb); +tcg_gen_add_i64 (td, td, tcy); +tcg_gen_trunc_i64_i32 (res, td); +tcg_gen_shri_i64 (td, td,32 ); +tcg_gen_andi_i64 (td, td,0x3 ); +/* Jump to lab when no overflow. */ +tcg_gen_brcondi_i64 (TCG_COND_EQ , td,0x0 , lab); +tcg_gen_brcondi_i64 (TCG_COND_EQ , td,0x3 , lab); +tcg_gen_ori_i32 (cpu_sr, cpu_sr, (SR_OV |SR_CY )); +tcg_gen_andi_i32 (sr_ove, cpu_sr,SR_OVE ); +tcg_gen_brcondi_i32 (TCG_COND_NE , sr_ove,SR_OVE , lab); +gen_exception (dc,EXCP_RANGE ); +gen_set_label (lab); +tcg_gen_mov_i32 (cpu_R[rd], res); +tcg_temp_free_i64 (ta); +tcg_temp_free_i64 (tb); +tcg_temp_free_i64 (tcy); +tcg_temp_free_i64 (td); +tcg_temp_free_i32 (res); +tcg_temp_free_i32 (sr_cy); +tcg_temp_free_i32 (sr_ove); + } +break ; +default : +gen_illegal_exception (dc); +break ; + } +break ; + +case 0x0002 :/*l.sub*/ +switch (op1) { +case 0x00 : +LOG_DIS ("l.sub r%d, r%d, r%d\n" , rd, ra, rb); + { + + + +int lab =gen_new_label (); +TCGv_i64 ta =tcg_temp_new_i64 (); +TCGv_i64 tb =tcg_temp_new_i64 (); +TCGv_i64 td =tcg_temp_local_new_i64 (); +TCGv_i32 res =tcg_temp_local_new_i32 (); +TCGv_i32 sr_ove =tcg_temp_local_new_i32 (); +tcg_gen_extu_i32_i64 (ta, cpu_R[ra]); +tcg_gen_extu_i32_i64 (tb, cpu_R[rb]); +tcg_gen_sub_i64 (td, ta, tb); +tcg_gen_trunc_i64_i32 (res, td); +tcg_gen_shri_i64 (td, td,31 ); +tcg_gen_andi_i64 (td, td,0x3 ); +/* Jump to lab when no overflow. */ +tcg_gen_brcondi_i64 (TCG_COND_EQ , td,0x0 , lab); +tcg_gen_brcondi_i64 (TCG_COND_EQ , td,0x3 , lab); +tcg_gen_ori_i32 (cpu_sr, cpu_sr, (SR_OV |SR_CY )); +tcg_gen_andi_i32 (sr_ove, cpu_sr,SR_OVE ); +tcg_gen_brcondi_i32 (TCG_COND_NE , sr_ove,SR_OVE , lab); +gen_exception (dc,EXCP_RANGE ); +gen_set_label (lab); +tcg_gen_mov_i32 (cpu_R[rd], res); +tcg_temp_free_i64 (ta); +tcg_temp_free_i64 (tb); +tcg_temp_free_i64 (td); +tcg_temp_free_i32 (res); +tcg_temp_free_i32 (sr_ove); + } +break ; +default : +gen_illegal_exception (dc); +break ; + } +break ; + +case 0x0003 :/*l.and*/ +switch (op1) { +case 0x00 : +LOG_DIS ("l.and r%d, r%d, r%d\n" , rd, ra, rb); +tcg_gen_and_tl (cpu_R[rd], cpu_R[ra], cpu_R[rb]); +break ; +default : +gen_illegal_exception (dc); +break ; + } +break ; + +case 0x0004 :/*l.or*/ +switch (op1) { +case 0x00 : +LOG_DIS ("l.or r%d, r%d, r%d\n" , rd, ra, rb); +tcg_gen_or_tl (cpu_R[rd], cpu_R[ra], cpu_R[rb]); +break ; +default : +gen_illegal_exception (dc); +break ; + } +break ; + +case 0x0005 : +switch (op1) { +case 0x00 :/*l.xor*/ +LOG_DIS ("l.xor r%d, r%d, r%d\n" , rd, ra, rb); +tcg_gen_xor_tl (cpu_R[rd], cpu_R[ra], cpu_R[rb]); +break ; +default : +gen_illegal_exception (dc); +break ; + } +break ; + +case 0x0006 : +switch (op1) { +case 0x03 :/*l.mul*/ +LOG_DIS ("l.mul r%d, r%d, r%d\n" , rd, ra, rb); + { +if (ra !=0 && rb !=0 ) { +int lab1 =gen_new_label (); +int lab2 =gen_new_label (); +int lab3 =gen_new_label (); +TCGv_i64 tmp0 =tcg_temp_local_new_i64 (); +TCGv_i64 tmp1 =tcg_temp_local_new_i64 (); +TCGv_i64 t0 =tcg_temp_local_new_i64 (); +TCGv_i32 res =tcg_temp_local_new_i32 (); +TCGv_i32 rs =tcg_temp_local_new_i32 (); +TCGv_i32 rt =tcg_temp_local_new_i32 (); +TCGv_i32 sr_ove =tcg_temp_local_new_i32 (); +/* Calculate the result. */ +tcg_gen_extu_i32_i64 (tmp0, cpu_R[ra]); +tcg_gen_extu_i32_i64 (tmp1, cpu_R[rb]); +tcg_gen_mul_i64 (t0, tmp0, tmp1); +tcg_gen_trunc_i64_i32 (res, t0); +tcg_gen_shri_i32 (rs, res,31 ); +tcg_gen_andi_i32 (rs, rs,0x1 ); +tcg_gen_shri_i64 (t0, t0,32 ); +tcg_gen_trunc_i64_i32 (rt, t0); +/* Overflow or not. */ +tcg_gen_brcondi_i32 (TCG_COND_EQ , rs,0x1 , lab1); +tcg_gen_brcondi_i32 (TCG_COND_EQ , rt,0x0 , lab2); +tcg_gen_brcondi_i32 (TCG_COND_NE , rt,0x0 , lab3); +gen_set_label (lab1); +tcg_gen_brcondi_i32 (TCG_COND_EQ , rt,0xffffffff , lab2); +/* Handle overflow exception. */ +gen_set_label (lab3); +tcg_gen_ori_tl (cpu_sr, cpu_sr,SR_OV ); +tcg_gen_ori_tl (cpu_sr, cpu_sr,SR_CY ); +tcg_gen_andi_tl (sr_ove, cpu_sr,SR_OVE ); +tcg_gen_brcondi_i32 (TCG_COND_NE , sr_ove,SR_OVE , lab2); +gen_exception (dc,EXCP_RANGE ); +/* Store result. */ +gen_set_label (lab2); +tcg_gen_mov_i32 (cpu_R[rd], res); +tcg_temp_free_i32 (res); +tcg_temp_free_i64 (t0); +tcg_temp_free_i32 (rs); +tcg_temp_free_i32 (rt); +tcg_temp_free_i64 (tmp0); +tcg_temp_free_i64 (tmp1); +tcg_temp_free_i32 (sr_ove); +#ifdef TARGET_OPENRISC64 +int lab4 =gen_new_label (); +int lab5 =gen_new_label (); +int lab6 =gen_new_label (); +TCGv_i64 t3 =tcg_temp_local_new_i64 (); +TCGv_i64 t4 =tcg_temp_local_new_i64 (); +TCGv_i64 t5 =tcg_temp_local_new_i64 (); +TCGv_i64 t6 =tcg_temp_local_new_i64 (); +TCGv_i64 r1 =tcg_temp_local_new_i64 (); +TCGv_i64 r2 =tcg_temp_local_new_i64 (); +TCGv_i64 r3 =tcg_temp_local_new_i64 (); +TCGv_i64 r4 =tcg_temp_local_new_i64 (); +TCGv_i32 tp0 =tcg_temp_local_new_i64 (); +TCGv_i32 tp1 =tcg_temp_local_new_i64 (); +TCGv_i64 t2h =tcg_temp_local_new_i64 (); +TCGv_i64 t2l =tcg_temp_local_new_i64 (); +TCGv_i64 t3h =tcg_temp_local_new_i64 (); +TCGv_i64 t3l =tcg_temp_local_new_i64 (); +TCGv_i64 res1 =tcg_temp_local_new_i64 (); +TCGv_i64 res0 =tcg_temp_local_new_i64 (); +TCGv_i32 sr_ove64 =tcg_temp_local_new_i32 (); +/* Calculate the each result, and HIGH. */ +tcg_gen_trunc_i64_i32 (tp0, cpu_R[ra]); +tcg_gen_trunc_i64_i32 (tp1, cpu_R[rb]); +tcg_gen_shri_i64 (t3, cpu_R[ra],32 ); +tcg_gen_extu_i32_i64 (t4, tp0); +tcg_gen_shri_i64 (t5, cpu_R[rb],32 ); +tcg_gen_extu_i32_i64 (t6, tp1); +tcg_gen_mul_i64 (r1, t3, t5); +tcg_gen_mul_i64 (r2, t3, t6); +tcg_gen_mul_i64 (r3, t5, t5); +tcg_gen_mul_i64 (r4, t3, t4); +tcg_gen_shri_i64 (t2h, r2,32 ); +tcg_gen_shri_i64 (t3h, r3,32 ); +tcg_gen_trunc_i64_i32 (tp0, r2); +tcg_gen_trunc_i64_i32 (tp1, r3); +tcg_gen_extu_i32_i64 (t2l, tp0); +tcg_gen_extu_i32_i64 (t3l, tp1); +tcg_gen_shri_i64 (res0, r4); +tcg_gen_add_i64 (t2l, t2l, t3l); +tcg_gen_add_i64 (res1, t2l, res1); +/* Overflow or not, by t2l CY. */ +tcg_gen_shri_i64 (t2l, res1,32 ); +tcg_gen_add_i64 (r1, t2h, r1); +tcg_gen_add_i64 (r1, r1, t3h); +tcg_gen_add_i64 (r1, r1, t2l); +tcg_gen_shri_i64 (res0, res1,31 ); +tcg_gen_andi_i64 (res0, res0,0x1 ); +tcg_gen_brcondi_i64 (TCG_COND_EQ , res0,0x1 , lab4); +tcg_gen_brcondi_i64 (TCG_COND_EQ , r1,0x0 , lab5); +tcg_gen_brcondi_i64 (TCG_COND_NE , r1,0x0 , lab6); +gen_set_label (lab4); +tcg_gen_brcondi_i64 (TCG_COND_EQ , r1, +0xffffffffffffffff , lab5); +/* Handle overflow exception. */ +gen_set_label (lab6); +tcg_gen_andi_tl (cpu_sr, cpu_sr,SR_OV ); +tcg_gen_andi_tl (cpu_sr, cpu_sr,SR_CY ); +tcg_gen_addi_i32 (sr_ove64, cpu_SR,SR_OVE ); +tcg_gen_brcondi_i32 (TCG_COND_NE , sr_ove64,0x1 , lab5); +gen_exeception (dc,EXCP_RANGE ); +/* Store result. */ +gen_set_label (lab5); +tcg_gen_shli_i64 (res1, res1,32 ); +tcg_gen_addi_i64 (r4, r4,0xffffffff ); +tcg_gen_add_i64 (res1, r4, res1); +tcg_gen_mov_i64 (cpu_R[rd], res1); +tcg_temp_free_i64 (t3); +tcg_temp_free_i64 (t4); +tcg_temp_free_i64 (t5); +tcg_temp_free_i64 (t6); +tcg_temp_free_i64 (r1); +tcg_temp_free_i64 (r2); +tcg_temp_free_i64 (r3); +tcg_temp_free_i64 (r4); +tcg_temp_free_i32 (tp0); +tcg_temp_free_i32 (tp1); +tcg_temp_free_i64 (t2h); +tcg_temp_free_i64 (t2l); +tcg_temp_free_i64 (t3h); +tcg_temp_free_i64 (t3l); +tcg_temp_free_i64 (res1); +tcg_temp_free_i64 (res0); +tcg_temp_free_i32 (sr_ove64); +#endif + }else { +tcg_gen_movi_tl (cpu_R[rd],0x0 ); + } + } +break ; +default : +gen_illegal_exception (dc); +break ; + } +break ; + +case 0x0009 : +switch (op1) { +case 0x03 :/*l.div*/ +LOG_DIS ("l.div r%d, r%d, r%d\n" , rd, ra, rb); + { +int lab0 =gen_new_label (); +int lab1 =gen_new_label (); +int lab2 =gen_new_label (); +TCGv_i32 sr_ove =tcg_temp_local_new_i32 (); +if (rb ==0 ) { +tcg_gen_ori_tl (cpu_sr, cpu_sr,SR_OV |SR_CY ); +tcg_gen_brcondi_tl (TCG_COND_NE , sr_ove,SR_OVE , lab0); +tcg_gen_andi_tl (sr_ove, cpu_sr,SR_OVE ); +gen_exception (dc,EXCP_RANGE ); +gen_set_label (lab0); + }else { +tcg_gen_brcondi_tl (TCG_COND_EQ , cpu_R[rb], +0x00000000 , lab1); +tcg_gen_brcondi_tl (TCG_COND_NE , cpu_R[ra], +0xffffffff , lab2); +tcg_gen_brcondi_tl (TCG_COND_NE , cpu_R[rb], +0x80000000 , lab2); +gen_set_label (lab1); +tcg_gen_ori_tl (cpu_sr, cpu_sr,SR_OV |SR_CY ); +tcg_gen_andi_tl (sr_ove, cpu_sr,SR_OVE ); +tcg_gen_brcondi_tl (TCG_COND_NE , sr_ove,SR_OVE , lab2); +gen_exception (dc,EXCP_RANGE ); +gen_set_label (lab2); +tcg_gen_div_tl (cpu_R[rd], cpu_R[ra], cpu_R[rb]); + } +tcg_temp_free_i32 (sr_ove); + } +break ; + +default : +gen_illegal_exception (dc); +break ; + } +break ; + +case 0x000a : +switch (op1) { +case 0x03 :/*l.divu*/ +LOG_DIS ("l.divu r%d, r%d, r%d\n" , rd, ra, rb); + { +int lab0 =gen_new_label (); +int lab1 =gen_new_label (); +TCGv_i32 sr_ove =tcg_temp_local_new_i32 (); +if (rb ==0 ) { +tcg_gen_ori_tl (cpu_sr, cpu_sr,SR_OV |SR_CY ); +tcg_gen_andi_tl (sr_ove, cpu_sr,SR_OVE ); +tcg_gen_brcondi_tl (TCG_COND_NE , sr_ove,SR_OVE , lab0); +gen_exception (dc,EXCP_RANGE ); +gen_set_label (lab0); + }else { +tcg_gen_brcondi_tl (TCG_COND_NE , cpu_R[rb], +0x00000000 , lab1); +tcg_gen_ori_tl (cpu_sr, cpu_sr,SR_OV |SR_CY ); +tcg_gen_andi_tl (sr_ove, cpu_sr,SR_OVE ); +tcg_gen_brcondi_tl (TCG_COND_NE , sr_ove,SR_OVE , lab1); +gen_exception (dc,EXCP_RANGE ); +gen_set_label (lab1); +tcg_gen_divu_tl (cpu_R[rd], cpu_R[ra], cpu_R[rb]); + } +tcg_temp_free_i32 (sr_ove); + } +break ; + +default : +gen_illegal_exception (dc); +break ; + } +break ; + +case 0x000b : +switch (op1) { +case 0x03 :/*l.mulu*/ +LOG_DIS ("l.mulu r%d, r%d, r%d\n" , rd, ra, rb); +if (rb !=0 && ra !=0 ) { +TCGv_i64 result =tcg_temp_local_new_i64 (); +TCGv_i64 tra =tcg_temp_local_new_i64 (); +TCGv_i64 trb =tcg_temp_local_new_i64 (); +TCGv_i64 high =tcg_temp_new_i64 (); +TCGv_i32 sr_ove =tcg_temp_local_new_i32 (); +int lab =gen_new_label (); +/* Calculate the each result. */ +tcg_gen_extu_i32_i64 (tra, cpu_R[ra]); +tcg_gen_extu_i32_i64 (trb, cpu_R[rb]); +tcg_gen_mul_i64 (result, tra, trb); +tcg_temp_free_i64 (tra); +tcg_temp_free_i64 (trb); +tcg_gen_shri_i64 (high, result,TARGET_LONG_BITS ); +/* Overflow or not. */ +tcg_gen_brcondi_i64 (TCG_COND_EQ , high,0x00000000 , lab); +tcg_gen_ori_tl (cpu_sr, cpu_sr,SR_OV |SR_CY ); +tcg_gen_andi_tl (sr_ove, cpu_sr,SR_OVE ); +tcg_gen_brcondi_tl (TCG_COND_NE , sr_ove,SR_OVE , lab); +gen_exception (dc,EXCP_RANGE ); +gen_set_label (lab); +tcg_temp_free_i64 (high); +tcg_gen_trunc_i64_tl (cpu_R[rd], result); +tcg_temp_free_i64 (result); +tcg_temp_free_i32 (sr_ove); +#ifdef TARGET_OPENRISC64 +int lab1 =gen_new_label (); +TCGv_i32 r1 =tcg_temp_loacl_new_i64 (); +TCGv_i32 r2 =tcg_temp_loacl_new_i64 (); +TCGv_i64 r3 =tcg_temp_loacl_new_i64 (); +TCGv_i64 r4 =tcg_temp_loacl_new_i64 (); +TCGv_i64 r5 =tcg_temp_loacl_new_i64 (); +TCGv_i64 r6 =tcg_temp_loacl_new_i64 (); +TCGv_i64 tr1 =tcg_temp_loacl_new_i64 (); +TCGv_i64 tr2 =tcg_temp_loacl_new_i64 (); +TCGv_i64 tr3 =tcg_temp_loacl_new_i64 (); +TCGv_i64 tr4 =tcg_temp_loacl_new_i64 (); +TCGv_i64 rs1 =tcg_temp_loacl_new_i64 (); +TCGv_i64 rs2 =tcg_temp_loacl_new_i64 (); +TCGV_i32 sr_ove64 =tcg_temp_local_new_i32 (); +/* Calculate the each result. */ +tcg_gen_trunc_i64_i32 (r1, cpu_R[ra]); +tcg_gen_trunc_i64_i32 (r2, cpu_R[rb]); +tcg_gen_extu_i32_i64 (r3, r1); +tcg_gen_extu_i32_i64 (r4, r2); +tcg_gen_shri_i64 (r5, cpu_R[ra],32 ); +tcg_gen_shri_i64 (r6, cpu_R[rb],32 ); +tcg_gen_mul_i64 (tr1, r5, r6); +tcg_gen_mul_i64 (tr2, r5, r4); +tcg_gen_mul_i64 (tr3, r3, r6); +tcg_gen_mul_i64 (tr4, r3, r4); +tcg_gen_trunc_i64_i32 (r1, tr2); +tcg_gen_trunc_i64_i32 (r2, tr3); +tcg_gen_extu_i32_i64 (r3, r1); +tcg_gen_extu_i32_i64 (r4, r2); +tcg_gen_shri_i64 (rs1, tr4,32 ); +tcg_gen_add_i64 (r3, r3, r4); +tcg_gen_add_i64 (rs2, rs1, r3); +/* Overflow or not, by r3 CY. */ +tcg_gen_shri_i64 (r3, rs2,32 ); +tcg_gen_shri_i64 (tr3, tr3,32 ); +tcg_gen_shri_i64 (tr2, tr2,32 ); +tcg_gen_add_i64 (tr1, tr1, tr2); +tcg_gen_add_i64 (tr1, tr1, tr3); +tcg_gen_add_i64 (tr1, tr1, r3); +tcg_gen_brcondi_i64 (TCGV_COND_EQ , tr1,0x0 , lab1); +tcg_gen_andi_tl (cpu_sr, cpu_sr,SR_OV ); +tcg_gen_andi_tl (cpu_sr, cpu_sr,SR_CY ); +tcg_gen_addi_i32 (sr_ove64, cpu_SR,SR_OVE ); +tcg_gen_brcondi_i32 (TCG_COND_NE , sr_ove64,0x1 , lab1); +gen_exeception (dc,EXCP_RANGE ); +/* Store result. */ +gen_set_label (lab1); +tcg_gen_andi_i64 (tr4, tr4,0xffffffff ); +tcg_gen_shli_i64 (rs2, rs2,32 ); +tcg_gen_add_i64 (rs2, rs2, tr4); +tcg_gen_mov_i64 (cpu_R[rd], rs2); +tcg_temp_free_i32 (r1); +tcg_temp_free_i32 (r2); +tcg_temp_free_i64 (r3); +tcg_temp_free_i64 (r4); +tcg_temp_free_i64 (r5); +tcg_temp_free_i64 (r6); +tcg_temp_free_i64 (tr1); +tcg_temp_free_i64 (tr2); +tcg_temp_free_i64 (tr3); +tcg_temp_free_i64 (tr4); +tcg_temp_free_i64 (rs1); +tcg_temp_free_i64 (rs2); +tcg_temp_free_i64 (sr_ove); +#endif + }else { +tcg_gen_movi_tl (cpu_R[rd],0 ); + } +break ; + +default : +gen_illegal_exception (dc); +break ; + } +break ; + +case 0x000e : +switch (op1) { +case 0x00 :/*l.cmov*/ +LOG_DIS ("l.cmov r%d, r%d, r%d\n" , rd, ra, rb); + { +int lab =gen_new_label (); +TCGv res =tcg_temp_new (); +TCGv sr_f =tcg_temp_new (); +tcg_gen_andi_tl (sr_f, cpu_sr,SR_F ); +tcg_gen_mov_tl (res, cpu_R[rb]); +tcg_gen_brcondi_tl (TCG_COND_NE , sr_f,SR_F , lab); +tcg_gen_mov_tl (res, cpu_R[ra]); +gen_set_label (lab); +tcg_gen_mov_tl (cpu_R[rd], res); +tcg_temp_free (sr_f); +tcg_temp_free (res); + } +break ; + +default : +gen_illegal_exception (dc); +break ; + } +break ; + +case 0x000f : +switch (op1) { +case 0x00 :/*l.ff1*/ +LOG_DIS ("l.ff1 r%d, r%d, r%d\n" , rd, ra, rb); +gen_helper_ff1 (cpu_R[rd], cpu_R[ra]); +break ; +case 0x01 :/*l.fl1*/ +LOG_DIS ("l.fl1 r%d, r%d, r%d\n" , rd, ra, rb); +gen_helper_fl1 (cpu_R[rd], cpu_R[ra]); +break ; + +default : +gen_illegal_exception (dc); +break ; + } +break ; + +case 0x0008 : +switch (op1) { +case 0x00 : +switch (op2) { +case 0x00 :/*l.sll*/ +LOG_DIS ("l.sll r%d, r%d, r%d\n" , rd, ra, rb); +tcg_gen_shl_tl (cpu_R[rd], cpu_R[ra], cpu_R[rb]); +break ; +case 0x01 :/*l.srl*/ +LOG_DIS ("l.srl r%d, r%d, r%d\n" , rd, ra, rb); +tcg_gen_shr_tl (cpu_R[rd], cpu_R[ra], cpu_R[rb]); +break ; +case 0x02 :/*l.sra*/ +LOG_DIS ("l.sra r%d, r%d, r%d\n" , rd, ra, rb); +tcg_gen_sar_tl (cpu_R[rd], cpu_R[ra], cpu_R[rb]); +break ; +case 0x03 :/*l.ror*/ +LOG_DIS ("l.ror r%d, r%d, r%d\n" , rd, ra, rb); +tcg_gen_rotr_tl (cpu_R[rd], cpu_R[ra], cpu_R[rb]); +break ; + +default : +gen_illegal_exception (dc); +break ; + } +break ; + +default : +gen_illegal_exception (dc); +break ; + } +break ; + +case 0x000c : +switch (op1) { +case 0x00 : +switch (op2) { +case 0x00 :/*l.exths*/ +LOG_DIS ("l.exths r%d, r%d\n" , rd, ra); +tcg_gen_ext16s_tl (cpu_R[rd], cpu_R[ra]); +break ; +case 0x01 :/*l.extbs*/ +LOG_DIS ("l.extbs r%d, r%d\n" , rd, ra); +tcg_gen_ext8s_tl (cpu_R[rd], cpu_R[ra]); +break ; +case 0x02 :/*l.exthz*/ +LOG_DIS ("l.exthz r%d, r%d\n" , rd, ra); +tcg_gen_ext16u_tl (cpu_R[rd], cpu_R[ra]); +break ; +case 0x03 :/*l.extbz*/ +LOG_DIS ("l.extbz r%d, r%d\n" , rd, ra); +tcg_gen_ext8u_tl (cpu_R[rd], cpu_R[ra]); +break ; + +default : +gen_illegal_exception (dc); +break ; + } +break ; + +default : +gen_illegal_exception (dc); +break ; + } +break ; + +case 0x000d : +switch (op1) { +case 0x00 : +switch (op2) { +case 0x00 :/*l.extws*/ +LOG_DIS ("l.extws r%d, r%d\n" , rd, ra); +tcg_gen_ext32s_tl (cpu_R[rd], cpu_R[ra]); +break ; +case 0x01 :/*l.extwz*/ +LOG_DIS ("l.extwz r%d, r%d\n" , rd, ra); +tcg_gen_ext32u_tl (cpu_R[rd], cpu_R[ra]); +break ; + +default : +gen_illegal_exception (dc); +break ; + } +break ; + +default : +gen_illegal_exception (dc); +break ; + } +break ; + +default : +gen_illegal_exception (dc); +break ; + } +} + +static void dec_misc (DisasContext *dc,CPUOpenRISCState *env,uint32_t insn) +{ +uint32_t op0, op1; +uint32_t ra, rb, rd; +uint32_t /*L6, K5, */ I16 ,I5 ,I11 ,N26 , tmp; + op0 =field (insn,26 ,6 ); + op1 =field (insn,24 ,2 ); + ra =field (insn,16 ,5 ); + rb =field (insn,11 ,5 ); + rd =field (insn,21 ,5 ); +/*L6 = field(insn, 5, 6); +K5 = field(insn, 0, 5);*/ +I16 =field (insn,0 ,16 ); +I5 =field (insn,21 ,5 ); +I11 =field (insn,0 ,11 ); +N26 =field (insn,0 ,26 ); + tmp = (I5 <<11 ) +I11 ; + +switch (op0) { +case 0x00 :/*l.j*/ +LOG_DIS ("l.j %d\n" ,N26 ); +case 0x01 :/*l.jal*/ +LOG_DIS ("l.jal %d\n" ,N26 ); +case 0x03 :/*l.bnf*/ +LOG_DIS ("l.bnf %d\n" ,N26 ); +case 0x04 :/*l.bf*/ +LOG_DIS ("l.bf %d\n" ,N26 ); + +gen_jump (dc,N26 ,0 , op0); +break ; + +case 0x05 : +switch (op1) { +case 0x01 :/*l.nop*/ +LOG_DIS ("l.nop %d\n" ,I16 ); +break ; + +default : +gen_illegal_exception (dc); +break ; + } +break ; + +case 0x11 :/*l.jr*/ +LOG_DIS ("l.jr r%d\n" , rb); +case 0x12 :/*l.jalr*/ +LOG_DIS ("l.jalr r%d\n" , rb); + +gen_jump (dc,0 , rb, op0); +break ; + +case 0x13 :/*l.maci*/ +LOG_DIS ("l.maci %d, r%d, %d\n" ,I5 , ra,I11 ); + { +TCGv_i64 t1 =tcg_temp_new_i64 (); +TCGv_i64 t2 =tcg_temp_new_i64 (); +TCGv_i32 dst =tcg_temp_new_i32 (); +TCGv ttmp =tcg_const_tl (tmp); +tcg_gen_mul_tl (dst, cpu_R[ra], ttmp); +tcg_gen_ext_i32_i64 (t1, dst); +tcg_gen_concat_i32_i64 (t2, maclo, machi); +tcg_gen_add_i64 (t2, t2, t1); +tcg_gen_trunc_i64_i32 (maclo, t2); +tcg_gen_shri_i64 (t2, t2,32 ); +tcg_gen_trunc_i64_i32 (machi, t2); +tcg_temp_free_i32 (dst); +tcg_temp_free (ttmp); +tcg_temp_free_i64 (t1); +tcg_temp_free_i64 (t2); + } +break ; + +case 0x09 :/*l.rfe*/ +LOG_DIS ("l.rfe\n" ); + { +gen_helper_rfe (cpu_env); + dc->is_jmp =DISAS_UPDATE ; + } +break ; + +case 0x1c :/*l.cust1*/ +LOG_DIS ("l.cust1\n" ); +break ; + +case 0x1d :/*l.cust2*/ +LOG_DIS ("l.cust2\n" ); +break ; + +case 0x1e :/*l.cust3*/ +LOG_DIS ("l.cust3\n" ); +break ; + +case 0x1f :/*l.cust4*/ +LOG_DIS ("l.cust4\n" ); +break ; + +case 0x3c :/*l.cust5*/ +/*LOG_DIS("l.cust5 r%d, r%d, r%d, %d, %d\n", rd, ra, rb, L6, K5);*/ +break ; + +case 0x3d :/*l.cust6*/ +LOG_DIS ("l.cust6\n" ); +break ; + +case 0x3e :/*l.cust7*/ +LOG_DIS ("l.cust7\n" ); +break ; + +case 0x3f :/*l.cust8*/ +LOG_DIS ("l.cust8\n" ); +break ; + +case 0x20 :/*l.ld*/ +LOG_DIS ("l.ld r%d, r%d, %d\n" , rd, ra,I16 ); + { +#ifdef TARGET_OPENRISC64 +check_ob64s (dc); +TCGv_i64 t0 =tcg_temp_new_i64 (); +tcg_gen_addi_i64 (t0, cpu_R[ra],sign_extend (I16 ,16 )); +tcg_gen_qemu_ld64 (cpu_R[rd], t0, dc->mem_idx); +tcg_temp_free_i64 (t0); +#endif + } +break ; + +case 0x21 :/*l.lwz*/ +LOG_DIS ("l.lwz r%d, r%d, %d\n" , rd, ra,I16 ); + { +TCGv t0 =tcg_temp_new (); +tcg_gen_addi_tl (t0, cpu_R[ra],sign_extend (I16 ,16 )); +tcg_gen_qemu_ld32u (cpu_R[rd], t0, dc->mem_idx); +tcg_temp_free (t0); + } +break ; + +case 0x22 :/*l.lws*/ +LOG_DIS ("l.lws r%d, r%d, %d\n" , rd, ra,I16 ); + { +TCGv t0 =tcg_temp_new (); +tcg_gen_addi_tl (t0, cpu_R[ra],sign_extend (I16 ,16 )); +tcg_gen_qemu_ld32s (cpu_R[rd], t0, dc->mem_idx); +tcg_temp_free (t0); + } +break ; + +case 0x23 :/*l.lbz*/ +LOG_DIS ("l.lbz r%d, r%d, %d\n" , rd, ra,I16 ); + { +TCGv t0 =tcg_temp_new (); +tcg_gen_addi_tl (t0, cpu_R[ra],sign_extend (I16 ,16 )); +tcg_gen_qemu_ld8u (cpu_R[rd], t0, dc->mem_idx); +tcg_temp_free (t0); + } +break ; + +case 0x24 :/*l.lbs*/ +LOG_DIS ("l.lbs r%d, r%d, %d\n" , rd, ra,I16 ); + { +TCGv t0 =tcg_temp_new (); +tcg_gen_addi_tl (t0, cpu_R[ra],sign_extend (I16 ,16 )); +tcg_gen_qemu_ld8s (cpu_R[rd], t0, dc->mem_idx); +tcg_temp_free (t0); + } +break ; + +case 0x25 :/*l.lhz*/ +LOG_DIS ("l.lhz r%d, r%d, %d\n" , rd, ra,I16 ); + { +TCGv t0 =tcg_temp_new (); +tcg_gen_addi_tl (t0, cpu_R[ra],sign_extend (I16 ,16 )); +tcg_gen_qemu_ld16u (cpu_R[rd], t0, dc->mem_idx); +tcg_temp_free (t0); + } +break ; + +case 0x26 :/*l.lhs*/ +LOG_DIS ("l.lhs r%d, r%d, %d\n" , rd, ra,I16 ); + { +TCGv t0 =tcg_temp_new (); +tcg_gen_addi_tl (t0, cpu_R[ra],sign_extend (I16 ,16 )); +tcg_gen_qemu_ld16s (cpu_R[rd], t0, dc->mem_idx); +tcg_temp_free (t0); + } +break ; + +case 0x27 :/*l.addi*/ +LOG_DIS ("l.addi r%d, r%d, %d\n" , rd, ra,I16 ); + { +int lab =gen_new_label (); +TCGv_i64 ta =tcg_temp_new_i64 (); +TCGv_i64 td =tcg_temp_local_new_i64 (); +TCGv_i32 res =tcg_temp_local_new_i32 (); +TCGv_i32 sr_ove =tcg_temp_local_new_i32 (); +tcg_gen_extu_i32_i64 (ta, cpu_R[ra]); +tcg_gen_addi_i64 (td, ta,sign_extend (I16 ,16 )); +tcg_gen_trunc_i64_i32 (res, td); +tcg_gen_shri_i64 (td, td,32 ); +tcg_gen_andi_i64 (td, td,0x3 ); +/* Jump to lab when no overflow. */ +tcg_gen_brcondi_i64 (TCG_COND_EQ , td,0x0 , lab); +tcg_gen_brcondi_i64 (TCG_COND_EQ , td,0x3 , lab); +tcg_gen_ori_i32 (cpu_sr, cpu_sr, (SR_OV |SR_CY )); +tcg_gen_andi_i32 (sr_ove, cpu_sr,SR_OVE ); +tcg_gen_brcondi_i32 (TCG_COND_NE , sr_ove,SR_OVE , lab); +gen_exception (dc,EXCP_RANGE ); +gen_set_label (lab); +tcg_gen_mov_i32 (cpu_R[rd], res); +tcg_temp_free_i64 (ta); +tcg_temp_free_i64 (td); +tcg_temp_free_i32 (res); +tcg_temp_free_i32 (sr_ove); + } +break ; + +case 0x28 :/*l.addic*/ +LOG_DIS ("l.addic r%d, r%d, %d\n" , rd, ra,I16 ); + { +int lab =gen_new_label (); +TCGv_i64 ta =tcg_temp_new_i64 (); +TCGv_i64 td =tcg_temp_local_new_i64 (); +TCGv_i64 tcy =tcg_temp_local_new_i64 (); +TCGv_i32 res =tcg_temp_local_new_i32 (); +TCGv_i32 sr_cy =tcg_temp_local_new_i32 (); +TCGv_i32 sr_ove =tcg_temp_local_new_i32 (); +tcg_gen_extu_i32_i64 (ta, cpu_R[ra]); +tcg_gen_andi_i32 (sr_cy, cpu_sr,SR_CY ); +tcg_gen_shri_i32 (sr_cy, sr_cy,10 ); +tcg_gen_extu_i32_i64 (tcy, sr_cy); +tcg_gen_addi_i64 (td, ta,sign_extend (I16 ,16 )); +tcg_gen_add_i64 (td, td, tcy); +tcg_gen_trunc_i64_i32 (res, td); +tcg_gen_shri_i64 (td, td,32 ); +tcg_gen_andi_i64 (td, td,0x3 ); +/* Jump to lab when no overflow. */ +tcg_gen_brcondi_i64 (TCG_COND_EQ , td,0x0 , lab); +tcg_gen_brcondi_i64 (TCG_COND_EQ , td,0x3 , lab); +tcg_gen_ori_i32 (cpu_sr, cpu_sr, (SR_OV |SR_CY )); +tcg_gen_andi_i32 (sr_ove, cpu_sr,SR_OVE ); +tcg_gen_brcondi_i32 (TCG_COND_NE , sr_ove,SR_OVE , lab); +gen_exception (dc,EXCP_RANGE ); +gen_set_label (lab); +tcg_gen_mov_i32 (cpu_R[rd], res); +tcg_temp_free_i64 (ta); +tcg_temp_free_i64 (td); +tcg_temp_free_i64 (tcy); +tcg_temp_free_i32 (res); +tcg_temp_free_i32 (sr_cy); +tcg_temp_free_i32 (sr_ove); + } +break ; + +case 0x29 :/*l.andi*/ +LOG_DIS ("l.andi r%d, r%d, %d\n" , rd, ra,I16 ); +tcg_gen_andi_tl (cpu_R[rd], cpu_R[ra],zero_extend (I16 ,16 )); +break ; + +case 0x2a :/*l.ori*/ +LOG_DIS ("l.ori r%d, r%d, %d\n" , rd, ra,I16 ); +tcg_gen_ori_tl (cpu_R[rd], cpu_R[ra],zero_extend (I16 ,16 )); +break ; + +case 0x2b :/*l.xori*/ +LOG_DIS ("l.xori r%d, r%d, %d\n" , rd, ra,I16 ); +tcg_gen_xori_tl (cpu_R[rd], cpu_R[ra],sign_extend (I16 ,16 )); +break ; + +case 0x2c :/*l.muli*/ +LOG_DIS ("l.muli r%d, r%d, %d\n" , rd, ra,I16 ); +if (ra !=0 &&I16 !=0 ) { +int lab1 =gen_new_label (); +TCGv_i64 t0 =tcg_temp_local_new_i64 (); +TCGv_i32 t1 =tcg_temp_local_new_i32 (); +TCGv_i32 t2 =tcg_temp_local_new_i32 (); +TCGv_i64 tmp0 =tcg_temp_local_new_i64 (); +TCGv_i32 res =tcg_temp_local_new_i32 (); +TCGv_i32 sr_ove =tcg_temp_local_new_i32 (); +uint64_t i16 = (uint64_t )I16 ; +/* Calculate the result. */ +tcg_gen_extu_i32_i64 (tmp0, cpu_R[ra]); +tcg_gen_muli_i64 (t0, tmp0, i16); +tcg_gen_trunc_i64_i32 (t1, t0); +tcg_gen_mov_tl (res, t1); +tcg_gen_shri_i32 (t1, t1,31 ); +/* Overflow or not. */ +tcg_gen_brcondi_tl (TCG_COND_NE , t1,0x0 , lab1); +tcg_gen_brcondi_tl (TCG_COND_EQ , t1,0x1ffff , lab1); +tcg_gen_ori_tl (cpu_sr, cpu_sr,SR_OV ); +tcg_gen_ori_tl (cpu_sr, cpu_sr,SR_CY ); +tcg_gen_andi_tl (sr_ove, cpu_sr,SR_OVE ); +tcg_gen_brcondi_tl (TCG_COND_NE , sr_ove,SR_OVE , lab1); +gen_exception (dc,EXCP_RANGE ); +/* Store result. */ +gen_set_label (lab1); +tcg_gen_mov_i32 (cpu_R[rd], res); +tcg_temp_free_i64 (t0); +tcg_temp_free_i32 (t1); +tcg_temp_free_i32 (t2); +tcg_temp_free_i64 (tmp0); +tcg_temp_free_i32 (res); +tcg_temp_free_i32 (sr_ove); +#ifdef TARGET_OPENRISC64 +int lab2 =gen_new_label (); +TCGv_i64 tmp1 =tcg_temp_local_new_i64 (); +TCGv_i64 tmp2 =tcg_temp_local_new_i64 (); +TCGv_i64 tr =tcg_temp_local_new_i64 (); +TCGv_i32 t3 =tcg_temp_local_new_i64 (); +TCGv_i32 t4 =tcg_temp_local_new_i64 (); +TCGv_i64 t5 =tcg_temp_local_new_i64 (); +TCGv_i64 res1 =tcg_temp_local_new_i64 (); +TCGv_i32 sr_ove64 =tcg_temp_local_new_i32 (); +/* Calculate the result. */ +tcg_gen_trunc_i64_i32 (t3, cpu_R[ra]); +tcg_gen_shri_i64 (cpu_R[ra], cpu_R[ra],32 ); +tcg_gen_trunc_i64_i32 (t5, cpu_R[ra]); +tcg_gen_muli_i64 (tr, t3,I16 ); +tcg_gen_muli_i64 (t4, t5,I16 ); +tcg_gen_shri_i64 (tmp2, tr,32 ); +tcg_gen_add_i64 (res1, tmp2, t4); +tcg_gen_shri_i64 (tmp1, res1,31 ); +/* Overflow or not. */ +tcg_gen_brcondi_tl (TCG_COND_NE , tmp1,0x0 , lab2); +tcg_gen_brcondi_tl (TCG_COND_EQ , tmp1,0x1ffff , lab2); +tcg_gen_ori_tl (cpu_sr, cpu_sr,SR_OV ); +tcg_gen_ori_tl (cpu_sr, cpu_sr,SR_CY ); +tcg_gen_andi_tl (sr_ove64, cpu_sr,SR_OVE ); +tcg_gen_brcondi_tl (TCG_COND_EQ , sr_ove64,SR_OVE , lab2); +gen_exeception (dc,EXCP_RANGE ); +/* Store result. */ +gen_set_label (lab2); +tcg_gen_andi_i64 (tr, tr,0xffffffff ); +tcg_gen_shli_i64 (res1, res1,32 ); +tcg_gen_add_i64 (cpu_R[rd], res1, tr); +tcg_temp_free_i64 (tmp1); +tcg_temp_free_i64 (tmp2); +tcg_temp_free_i64 (t3); +tcg_temp_free_i64 (t4); +tcg_temp_free_i64 (t5); +tcg_temp_free_i64 (tr); +tcg_temp_free_i64 (res1); +tcg_temp_free_i64 (sr_ove64); +#endif + }else { +tcg_gen_movi_tl (cpu_R[rd],0x0 ); + } +break ; + +case 0x2d :/*l.mfspr*/ +LOG_DIS ("l.mfspr r%d, r%d, %d\n" , rd, ra,I16 ); +break ; + +case 0x30 :/*l.mtspr*/ +LOG_DIS ("l.mtspr %d, r%d, r%d, %d\n" ,I5 , ra, rb,I11 ); +break ; + +case 0x34 :/*l.sd*/ +LOG_DIS ("l.sd %d, r%d, r%d, %d\n" ,I5 , ra, rb,I11 ); + { +#ifdef TARGET_OPENRISC64 +check_ob64s (dc); +TCGv_i64 t0 =tcg_temp_new_i64 (); +tcg_gen_addi_tl (t0, cpu_R[ra],sign_extend (tmp,16 )); +tcg_gen_qemu_st64 (cpu_R[rb], t0, dc->mem_idx); +tcg_temp_free_i64 (t0); +#endif + } +break ; + +case 0x35 :/*l.sw*/ +LOG_DIS ("l.sw %d, r%d, r%d, %d\n" ,I5 , ra, rb,I11 ); + { +TCGv t0 =tcg_temp_new (); +tcg_gen_addi_tl (t0, cpu_R[ra],sign_extend (tmp,16 )); +tcg_gen_qemu_st32 (cpu_R[rb], t0, dc->mem_idx); +tcg_temp_free (t0); + } +break ; + +case 0x36 :/*l.sb*/ +LOG_DIS ("l.sb %d, r%d, r%d, %d\n" ,I5 , ra, rb,I11 ); + { +TCGv t0 =tcg_temp_new (); +tcg_gen_addi_tl (t0, cpu_R[ra],sign_extend (tmp,16 )); +tcg_gen_qemu_st8 (cpu_R[rb], t0, dc->mem_idx); +tcg_temp_free (t0); + } +break ; + +case 0x37 :/*l.sh*/ +LOG_DIS ("l.sh %d, r%d, r%d, %d\n" ,I5 , ra, rb,I11 ); + { +TCGv t0 =tcg_temp_new (); +tcg_gen_addi_tl (t0, cpu_R[ra],sign_extend (tmp,16 )); +tcg_gen_qemu_st16 (cpu_R[rb], t0, dc->mem_idx); +tcg_temp_free (t0); + } +break ; + +default : +gen_illegal_exception (dc); +break ; + } +} + +static void dec_mac (DisasContext *dc,CPUOpenRISCState *env,uint32_t insn) +{ +uint32_t op0; +uint32_t ra, rb; + op0 =field (insn,0 ,4 ); + ra =field (insn,16 ,5 ); + rb =field (insn,11 ,5 ); + +switch (op0) { +case 0x0001 :/*l.mac*/ +LOG_DIS ("l.mac r%d, r%d\n" , ra, rb); + { +TCGv_i32 t0 =tcg_temp_new_i32 (); +TCGv_i64 t1 =tcg_temp_new_i64 (); +TCGv_i64 t2 =tcg_temp_new_i64 (); +tcg_gen_mul_tl (t0, cpu_R[ra], cpu_R[rb]); +tcg_gen_ext_i32_i64 (t1, t0); +tcg_gen_concat_i32_i64 (t2, maclo, machi); +tcg_gen_add_i64 (t2, t2, t1); +tcg_gen_trunc_i64_i32 (maclo, t2); +tcg_gen_shri_i64 (t2, t2,32 ); +tcg_gen_trunc_i64_i32 (machi, t2); +tcg_temp_free_i32 (t0); +tcg_temp_free_i64 (t1); +tcg_temp_free_i64 (t2); + } +break ; + +case 0x0002 :/*l.msb*/ +LOG_DIS ("l.msb r%d, r%d\n" , ra, rb); + { +TCGv_i32 t0 =tcg_temp_new_i32 (); +TCGv_i64 t1 =tcg_temp_new_i64 (); +TCGv_i64 t2 =tcg_temp_new_i64 (); +tcg_gen_mul_tl (t0, cpu_R[ra], cpu_R[rb]); +tcg_gen_ext_i32_i64 (t1, t0); +tcg_gen_concat_i32_i64 (t2, maclo, machi); +tcg_gen_sub_i64 (t2, t2, t1); +tcg_gen_trunc_i64_i32 (maclo, t2); +tcg_gen_shri_i64 (t2, t2,32 ); +tcg_gen_trunc_i64_i32 (machi, t2); +tcg_temp_free_i32 (t0); +tcg_temp_free_i64 (t1); +tcg_temp_free_i64 (t2); + } +break ; + +default : +gen_illegal_exception (dc); +break ; + } +} + +static void dec_logic (DisasContext *dc,CPUOpenRISCState *env,uint32_t insn) +{ +uint32_t op0; +uint32_t rd, ra,L6 ; + op0 =field (insn,6 ,2 ); + rd =field (insn,21 ,5 ); + ra =field (insn,16 ,5 ); +L6 =field (insn,0 ,6 ); + +switch (op0) { +case 0x00 :/*l.slli*/ +LOG_DIS ("l.slli r%d, r%d, %d\n" , rd, ra,L6 ); +tcg_gen_shli_tl (cpu_R[rd], cpu_R[ra], (L6 &0x1f )); +break ; + +case 0x01 :/*l.srli*/ +LOG_DIS ("l.srli r%d, r%d, %d\n" , rd, ra,L6 ); +tcg_gen_shri_tl (cpu_R[rd], cpu_R[ra], (L6 &0x1f )); +break ; + +case 0x02 :/*l.srai*/ +LOG_DIS ("l.srai r%d, r%d, %d\n" , rd, ra,L6 ); +tcg_gen_sari_tl (cpu_R[rd], cpu_R[ra], (L6 &0x1f ));break ; + +case 0x03 :/*l.rori*/ +LOG_DIS ("l.rori r%d, r%d, %d\n" , rd, ra,L6 ); +tcg_gen_rotri_tl (cpu_R[rd], cpu_R[ra], (L6 &0x1f )); +break ; + +default : +gen_illegal_exception (dc); +break ; + } +} + +static void dec_M (DisasContext *dc,CPUOpenRISCState *env,uint32_t insn) +{ +uint32_t op0; +uint32_t rd; +uint32_t K16 ; + op0 =field (insn,16 ,1 ); + rd =field (insn,21 ,5 ); +K16 =field (insn,0 ,16 ); + +switch (op0) { +case 0x0 :/*l.movhi*/ +LOG_DIS ("l.movhi r%d, %d\n" , rd,K16 ); +tcg_gen_movi_tl (cpu_R[rd], (K16 <<16 )); +break ; + +case 0x1 :/*l.macrc*/ +LOG_DIS ("l.macrc r%d\n" , rd); +tcg_gen_mov_tl (cpu_R[rd], maclo); +tcg_gen_movi_tl (maclo,0x0 ); +tcg_gen_movi_tl (machi,0x0 ); +break ; + +default : +gen_illegal_exception (dc); +break ; + } +} + +static void dec_comp (DisasContext *dc,CPUOpenRISCState *env,uint32_t insn) +{ +uint32_t op0; +uint32_t ra, rb; + + op0 =field (insn,21 ,5 ); + ra =field (insn,16 ,5 ); + rb =field (insn,11 ,5 ); + +tcg_gen_movi_i32 (env_btaken,0x0 ); +/* unsigned integers */ +tcg_gen_ext32u_tl (cpu_R[ra], cpu_R[ra]); +tcg_gen_ext32u_tl (cpu_R[rb], cpu_R[rb]); + +switch (op0) { +case 0x0 :/*l.sfeq*/ +LOG_DIS ("l.sfeq r%d, r%d\n" , ra, rb); +tcg_gen_setcond_tl (TCG_COND_EQ , env_btaken, cpu_R[ra], cpu_R[rb]); +break ; + +case 0x1 :/*l.sfne*/ +LOG_DIS ("l.sfne r%d, r%d\n" , ra, rb); +tcg_gen_setcond_tl (TCG_COND_NE , env_btaken, cpu_R[ra], cpu_R[rb]); +break ; + +case 0x2 :/*l.sfgtu*/ +LOG_DIS ("l.sfgtu r%d, r%d\n" , ra, rb); +tcg_gen_setcond_tl (TCG_COND_GTU , env_btaken, cpu_R[ra], cpu_R[rb]); +break ; + +case 0x3 :/*l.sfgeu*/ +LOG_DIS ("l.sfgeu r%d, r%d\n" , ra, rb); +tcg_gen_setcond_tl (TCG_COND_GEU , env_btaken, cpu_R[ra], cpu_R[rb]); +break ; + +case 0x4 :/*l.sfltu*/ +LOG_DIS ("l.sfltu r%d, r%d\n" , ra, rb); +tcg_gen_setcond_tl (TCG_COND_LTU , env_btaken, cpu_R[ra], cpu_R[rb]); +break ; + +case 0x5 :/*l.sfleu*/ +LOG_DIS ("l.sfleu r%d, r%d\n" , ra, rb); +tcg_gen_setcond_tl (TCG_COND_LEU , env_btaken, cpu_R[ra], cpu_R[rb]); +break ; + +case 0xa :/*l.sfgts*/ +LOG_DIS ("l.sfgts r%d, r%d\n" , ra, rb); +tcg_gen_setcond_tl (TCG_COND_GT , env_btaken, cpu_R[ra], cpu_R[rb]); +break ; + +case 0xb :/*l.sfges*/ +LOG_DIS ("l.sfges r%d, r%d\n" , ra, rb); +tcg_gen_setcond_tl (TCG_COND_GE , env_btaken, cpu_R[ra], cpu_R[rb]); +break ; + +case 0xc :/*l.sflts*/ +LOG_DIS ("l.sflts r%d, r%d\n" , ra, rb); +tcg_gen_setcond_tl (TCG_COND_LT , env_btaken, cpu_R[ra], cpu_R[rb]); +break ; + +case 0xd :/*l.sfles*/ +LOG_DIS ("l.sfles r%d, r%d\n" , ra, rb); +tcg_gen_setcond_tl (TCG_COND_LE , env_btaken, cpu_R[ra], cpu_R[rb]); +break ; + +default : +gen_illegal_exception (dc); +break ; + } +wb_SR_F (); +} + +static void dec_compi (DisasContext *dc,CPUOpenRISCState *env,uint32_t insn) +{ +uint32_t op0; +uint32_t ra,I16 ; + + op0 =field (insn,21 ,5 ); + ra =field (insn,16 ,5 ); +I16 =field (insn,0 ,16 ); + +tcg_gen_movi_i32 (env_btaken,0x0 ); +I16 =sign_extend (I16 ,16 ); + +switch (op0) { +case 0x0 :/*l.sfeqi*/ +LOG_DIS ("l.sfeqi r%d, %d\n" , ra,I16 ); +tcg_gen_setcondi_tl (TCG_COND_EQ , env_btaken, cpu_R[ra],I16 ); +break ; + +case 0x1 :/*l.sfnei*/ +LOG_DIS ("l.sfnei r%d, %d\n" , ra,I16 ); +tcg_gen_setcondi_tl (TCG_COND_NE , env_btaken, cpu_R[ra],I16 ); +break ; + +case 0x2 :/*l.sfgtui*/ +LOG_DIS ("l.sfgtui r%d, %d\n" , ra,I16 ); +tcg_gen_setcondi_tl (TCG_COND_GTU , env_btaken, cpu_R[ra],I16 ); +break ; + +case 0x3 :/*l.sfgeui*/ +LOG_DIS ("l.sfgeui r%d, %d\n" , ra,I16 ); +tcg_gen_setcondi_tl (TCG_COND_GEU , env_btaken, cpu_R[ra],I16 ); +break ; + +case 0x4 :/*l.sfltui*/ +LOG_DIS ("l.sfltui r%d, %d\n" , ra,I16 ); +tcg_gen_setcondi_tl (TCG_COND_LTU , env_btaken, cpu_R[ra],I16 ); +break ; + +case 0x5 :/*l.sfleui*/ +LOG_DIS ("l.sfleui r%d, %d\n" , ra,I16 ); +tcg_gen_setcondi_tl (TCG_COND_LEU , env_btaken, cpu_R[ra],I16 ); +break ; + +case 0xa :/*l.sfgtsi*/ +LOG_DIS ("l.sfgtsi r%d, %d\n" , ra,I16 ); +tcg_gen_setcondi_tl (TCG_COND_GT , env_btaken, cpu_R[ra],I16 ); +break ; + +case 0xb :/*l.sfgesi*/ +LOG_DIS ("l.sfgesi r%d, %d\n" , ra,I16 ); +tcg_gen_setcondi_tl (TCG_COND_GE , env_btaken, cpu_R[ra],I16 ); +break ; + +case 0xc :/*l.sfltsi*/ +LOG_DIS ("l.sfltsi r%d, %d\n" , ra,I16 ); +tcg_gen_setcondi_tl (TCG_COND_LT , env_btaken, cpu_R[ra],I16 ); +break ; + +case 0xd :/*l.sflesi*/ +LOG_DIS ("l.sflesi r%d, %d\n" , ra,I16 ); +tcg_gen_setcondi_tl (TCG_COND_LE , env_btaken, cpu_R[ra],I16 ); +break ; + +default : +gen_illegal_exception (dc); +break ; + } +wb_SR_F (); +} + +static void dec_sys (DisasContext *dc,CPUOpenRISCState *env,uint32_t insn) +{ +uint32_t op0; +/*uint32_t K16;*/ + op0 =field (insn,16 ,8 ); +/*K16 = field(insn, 0, 16);*/ + +switch (op0) { +case 0x000 :/*l.sys*/ +/*LOG_DIS("l.sys %d\n", K16);*/ +tcg_gen_movi_tl (cpu_pc, dc->pc); +gen_exception (dc,EXCP_SYSCALL ); + dc->is_jmp =DISAS_UPDATE ; +break ; + +case 0x100 :/*l.trap*/ +/*LOG_DIS("l.trap %d\n", K16);*/ +tcg_gen_movi_tl (cpu_pc, dc->pc); +gen_exception (dc,EXCP_TRAP ); +break ; + +case 0x300 :/*l.csync*/ +LOG_DIS ("l.csync\n" ); +break ; + +case 0x200 :/*l.msync*/ +LOG_DIS ("l.msync\n" ); +break ; + +case 0x270 :/*l.psync*/ +LOG_DIS ("l.psync\n" ); +break ; + +default : +gen_illegal_exception (dc); +break ; + } +} + +static void dec_float (DisasContext *dc,CPUOpenRISCState *env,uint32_t insn) +{ +uint32_t op0; +uint32_t ra, rb, rd; + op0 =field (insn,0 ,8 ); + ra =field (insn,16 ,5 ); + rb =field (insn,11 ,5 ); + rd =field (insn,21 ,5 ); + +switch (op0) { +case 0x00 :/*lf.add.s*/ +LOG_DIS ("lf.add.s r%d, r%d, r%d\n" , rd, ra, rb); +gen_helper_float_add_s (cpu_R[rd], cpu_env, cpu_R[ra], cpu_R[rb]); +break ; + +case 0x01 :/*lf.sub.s*/ +LOG_DIS ("lf.sub.s r%d, r%d, r%d\n" , rd, ra, rb); +gen_helper_float_sub_s (cpu_R[rd], cpu_env, cpu_R[ra], cpu_R[rb]); +break ; + + +case 0x02 :/*lf.mul.s*/ +LOG_DIS ("lf.mul.s r%d, r%d, r%d\n" , rd, ra, rb); +if (ra !=0 && rb !=0 ) { +gen_helper_float_mul_s (cpu_R[rd], cpu_env, cpu_R[ra], cpu_R[rb]); + }else { +tcg_gen_ori_tl (fpcsr, fpcsr,FPCSR_ZF ); +tcg_gen_movi_i32 (cpu_R[rd],0x0 ); + } +break ; + +case 0x03 :/*lf.div.s*/ +LOG_DIS ("lf.div.s r%d, r%d, r%d\n" , rd, ra, rb); +gen_helper_float_div_s (cpu_R[rd], cpu_env, cpu_R[ra], cpu_R[rb]); +break ; + +case 0x04 :/*lf.itof.s*/ +LOG_DIS ("lf.itof r%d, r%d\n" , rd, ra); +gen_helper_itofs (cpu_R[rd], cpu_env, cpu_R[ra]); +break ; + +case 0x05 :/*lf.ftoi.s*/ +LOG_DIS ("lf.ftoi r%d, r%d\n" , rd, ra); +gen_helper_ftois (cpu_R[rd], cpu_env, cpu_R[ra]); +break ; + +case 0x06 :/*lf.rem.s*/ +LOG_DIS ("lf.rem.s r%d, r%d, r%d\n" , rd, ra, rb); +gen_helper_float_rem_s (cpu_R[rd], cpu_env, cpu_R[ra], cpu_R[rb]); +break ; + +case 0x07 :/*lf.madd.s*/ +LOG_DIS ("lf.madd.s r%d, r%d, r%d\n" , rd, ra, rb); +gen_helper_float_muladd_s (cpu_R[rd], cpu_env, cpu_R[ra], cpu_R[rb]); +break ; + +case 0x08 :/*lf.sfeq.s*/ +LOG_DIS ("lf.sfeq.s r%d, r%d\n" , ra, rb); +gen_helper_float_eq_s (env_btaken, cpu_env, cpu_R[ra], cpu_R[rb]); +break ; + +case 0x09 :/*lf.sfne.s*/ +LOG_DIS ("lf.sfne.s r%d, r%d\n" , ra, rb); +gen_helper_float_ne_s (env_btaken, cpu_env, cpu_R[ra], cpu_R[rb]); +break ; + +case 0x0a :/*lf.sfgt.s*/ +LOG_DIS ("lf.sfgt.s r%d, r%d\n" , ra, rb); +gen_helper_float_gt_s (env_btaken, cpu_env, cpu_R[ra], cpu_R[rb]); +break ; + +case 0x0b :/*lf.sfge.s*/ +LOG_DIS ("lf.sfge.s r%d, r%d\n" , ra, rb); +gen_helper_float_ge_s (env_btaken, cpu_env, cpu_R[ra], cpu_R[rb]); +break ; + +case 0x0c :/*lf.sflt.s*/ +LOG_DIS ("lf.sflt.s r%d, r%d\n" , ra, rb); +gen_helper_float_lt_s (env_btaken, cpu_env, cpu_R[ra], cpu_R[rb]); +break ; + +case 0x0d :/*lf.sfle.s*/ +LOG_DIS ("lf.sfle.s r%d, r%d\n" , ra, rb); +gen_helper_float_le_s (env_btaken, cpu_env, cpu_R[ra], cpu_R[rb]); +break ; + +#ifdef TARGET_OPENRISC64 +case 0x10 :/*lf.add.d*/ +LOG_DIS ("lf.add.d r%d, r%d, r%d\n" , rd, ra, rb); +check_of64s (dc); +gen_helper_float_add_d (cpu_R[rd], cpu_env, cpu_R[ra], cpu_R[rb]); +break ; + +case 0x11 :/*lf.sub.d*/ +LOG_DIS ("lf.sub.d r%d, r%d, r%d\n" , rd, ra, rb); +check_of64s (dc); +gen_helper_float_sub_d (cpu_R[rd], cpu_env, cpu_R[ra], cpu_R[rb]); +break ; + +case 0x12 :/*lf.mul.d*/ +LOG_DIS ("lf.mul.d r%d, r%d, r%d\n" , rd, ra, rb); +check_of64s (dc); +if (ra !=0 && rb !=0 ) { +gen_helper_float_mul_d (cpu_R[rd], cpu_env, cpu_R[ra], cpu_R[rb]); + }else { +tcg_gen_ori_tl (fpcsr, fpcsr,FPCSR_ZF ); +tcg_gen_movi_i64 (cpu_R[rd],0x0 ); + } +break ; + +case 0x13 :/*lf.div.d*/ +LOG_DIS ("lf.div.d r%d, r%d, r%d\n" , rd, ra, rb); +check_of64s (dc); +gen_helper_float_div_d (cpu_R[rd], cpu_env, cpu_R[ra], cpu_R[rb]); +break ; + +case 0x14 :/*lf.itof.d*/ +LOG_DIS ("lf.itof r%d, r%d\n" , rd, ra); +check_of64s (dc); +gen_helper_itofd (cpu_R[rd], cpu_env, cpu_R[ra]); +break ; + +case 0x15 :/*lf.ftoi.d*/ +LOG_DIS ("lf.ftoi r%d, r%d\n" , rd, ra); +check_of64s (dc); +gen_helper_ftoid (cpu_R[rd], cpu_env, cpu_R[ra]); +break ; + +case 0x16 :/*lf.rem.d*/ +LOG_DIS ("lf.rem.d r%d, r%d, r%d\n" , rd, ra, rb); +check_of64s (dc); +gen_helper_float_rem_d (cpu_R[rd], cpu_env, cpu_R[ra], cpu_R[rb]); +break ; + +case 0x17 :/*lf.madd.d*/ +LOG_DIS ("lf.madd.d r%d, r%d, r%d\n" , rd, ra, rb); +check_of64s (dc); +gen_helper_float_muladd_d (cpu_R[rd], cpu_env, cpu_R[ra], cpu_R[rb]); +break ; + +case 0x18 :/*lf.sfeq.d*/ +LOG_DIS ("lf.sfeq.d r%d, r%d\n" , ra, rb); +check_of64s (dc); +gen_helper_float_eq_d (env_btaken, cpu_env, cpu_R[ra], cpu_R[rb]); +break ; + +case 0x1a :/*lf.sfgt.d*/ +LOG_DIS ("lf.sfgt.d r%d, r%d\n" , ra, rb); +check_of64s (dc); +gen_helper_float_gt_d (env_btaken, cpu_env, cpu_R[ra], cpu_R[rb]); +break ; + +case 0x1b :/*lf.sfge.d*/ +LOG_DIS ("lf.sfge.d r%d, r%d\n" , ra, rb); +check_of64s (dc); +gen_helper_float_ge_d (env_btaken, cpu_env, cpu_R[ra], cpu_R[rb]); +break ; + +case 0x19 :/*lf.sfne.d*/ +LOG_DIS ("lf.sfne.d r%d, r%d\n" , ra, rb); +check_of64s (dc); +gen_helper_float_ne_d (env_btaken, cpu_env, cpu_R[ra], cpu_R[rb]); +break ; + +case 0x1c :/*lf.sflt.d*/ +LOG_DIS ("lf.sflt.d r%d, r%d\n" , ra, rb); +check_of64s (dc); +gen_helper_float_lt_d (env_btaken, cpu_env, cpu_R[ra], cpu_R[rb]); +break ; + +case 0x1d :/*lf.sfle.d*/ +LOG_DIS ("lf.sfle.d r%d, r%d\n" , ra, rb); +check_of64s (dc); +gen_helper_float_le_d (env_btaken, cpu_env, cpu_R[ra], cpu_R[rb]); +break ; +#endif + +default : +gen_illegal_exception (dc); +break ; + } +wb_SR_F (); +} + +static void disas_openrisc_insn (DisasContext *dc,CPUOpenRISCState *env) +{ +uint32_t op0; +uint32_t insn; + insn =cpu_ldl_code (env, dc->pc); + op0 =field (insn,26 ,6 ); + +switch (op0) { +case 0x06 : +dec_M (dc, env, insn); +break ; + +case 0x08 : +dec_sys (dc, env, insn); +break ; + +case 0x2e : +dec_logic (dc, env, insn); +break ; + +case 0x2f : +dec_compi (dc, env, insn); +break ; + +case 0x31 : +dec_mac (dc, env, insn); +break ; + +case 0x32 : +dec_float (dc, env, insn); +break ; + +case 0x38 : +dec_calc (dc, env, insn); +break ; + +case 0x39 : +dec_comp (dc, env, insn); +break ; + +default : +dec_misc (dc, env, insn); +break ; + } +} + +static void check_breakpoint (CPUOpenRISCState *env,DisasContext *dc) +{ +CPUBreakpoint *bp; + +if (unlikely (!QTAILQ_EMPTY (&env->breakpoints))) { + QTAILQ_FOREACH(bp, &env->breakpoints, entry) { +if (bp->pc == dc->pc) { +tcg_gen_movi_tl (cpu_pc, dc->pc); +gen_exception (dc,EXCP_DEBUG ); + dc->is_jmp =DISAS_UPDATE ; + } + } + } }static inline void gen_intermediate_code_internal (CPUOpenRISCState *env,TranslationBlock *tb,int search_pc) { +struct DisasContext ctx, *dc = &ctx; +uint16_t *gen_opc_end; +uint32_t pc_start; +int j, k; +uint32_t next_page_start; +int num_insns; +int max_insns; + +qemu_log_try_set_file (stderr); + + pc_start = tb->pc; + dc->env = env; + dc->tb = tb; + + gen_opc_end = gen_opc_buf +OPC_MAX_SIZE ; + dc->is_jmp =DISAS_NEXT ; + dc->ppc = pc_start; + dc->pc = pc_start; + dc->flags = env->cpucfgr; + dc->mem_idx =cpu_mmu_index (env); + dc->synced_flags = dc->tb_flags = tb->flags; + dc->delayed_branch = !!(dc->tb_flags &D_FLAG ); + dc->singlestep_enabled = env->singlestep_enabled; +if (qemu_loglevel_mask (CPU_LOG_TB_IN_ASM )) { +qemu_log ("-----------------------------------------\n" ); +log_cpu_state (env,0 ); + } + + next_page_start = (pc_start &TARGET_PAGE_MASK ) +TARGET_PAGE_SIZE ; + k =-1 ; + num_insns =0 ; + max_insns = tb->cflags &CF_COUNT_MASK ; + +if (max_insns ==0 ) { + max_insns =CF_COUNT_MASK ; + } + +gen_icount_start (); + +do { +check_breakpoint (env, dc); +if (search_pc) { + j = gen_opc_ptr - gen_opc_buf; +if (k < j) { + k++; +while (k < j) { + gen_opc_instr_start[k++] =0 ; + } + } + gen_opc_pc[k] = dc->pc; + gen_opc_instr_start[k] =1 ; + gen_opc_icount[k] = num_insns; + } + +if (unlikely (qemu_loglevel_mask (CPU_LOG_TB_OP ))) { +tcg_gen_debug_insn_start (dc->pc); + } + +if (num_insns +1 == max_insns && (tb->cflags &CF_LAST_IO )) { +gen_io_start (); + } + dc->ppc = dc->pc -4 ; + dc->npc = dc->pc +4 ; +tcg_gen_movi_tl (cpu_ppc, dc->ppc); +tcg_gen_movi_tl (cpu_npc, dc->npc); +disas_openrisc_insn (dc, env); + dc->pc = dc->npc; + num_insns++; +/* delay slot */ +if (dc->delayed_branch) { + dc->delayed_branch--; +if (!dc->delayed_branch) { + dc->tb_flags &= ~D_FLAG ; +gen_sync_flags (dc); +tcg_gen_mov_tl (cpu_pc, jmp_pc); +tcg_gen_mov_tl (cpu_npc, jmp_pc); +tcg_gen_movi_tl (jmp_pc,0 ); +tcg_gen_exit_tb (0 ); + dc->is_jmp =DISAS_JUMP ; +break ; + } + } + }while (!dc->is_jmp + && gen_opc_ptr < gen_opc_end + && !env->singlestep_enabled + && !singlestep + && (dc->pc < next_page_start) + && num_insns < max_insns); + +if (tb->cflags &CF_LAST_IO ) { +gen_io_end (); + } +if (dc->is_jmp ==DISAS_NEXT ) { + dc->is_jmp =DISAS_UPDATE ; +tcg_gen_movi_tl (cpu_pc, dc->pc); + } +if (unlikely (env->singlestep_enabled)) { +if (dc->is_jmp ==DISAS_NEXT ) { +tcg_gen_movi_tl (cpu_pc, dc->pc); + } +gen_exception (dc,EXCP_DEBUG ); + }else { +switch (dc->is_jmp) { +case DISAS_NEXT : +gen_goto_tb (dc,0 , dc->pc); +break ; +default : +case DISAS_JUMP : +break ; +case DISAS_UPDATE : +/* indicate that the hash table must be used +to find the next TB */ +tcg_gen_exit_tb (0 ); +break ; +case DISAS_TB_JUMP : +/* nothing more to generate */ +break ; + } + } + +gen_icount_end (tb, num_insns); + *gen_opc_ptr = INDEX_op_end; +if (search_pc) { + j = gen_opc_ptr - gen_opc_buf; + k++; +while (k <= j) { + gen_opc_instr_start[k++] =0 ; + } + }else { + tb->size = dc->pc - pc_start; + tb->icount = num_insns; + } + +#ifdef DEBUG_DISAS +if (qemu_loglevel_mask (CPU_LOG_TB_IN_ASM )) { +qemu_log ("\n" ); +log_target_disas (pc_start, dc->pc - pc_start,0 ); +qemu_log ("\nisize=%d osize=%td\n" , + dc->pc - pc_start, gen_opc_ptr - gen_opc_buf); + } +#endif }void gen_intermediate_code (CPUOpenRISCState *env,struct TranslationBlock *tb)
Signature · 1 line
1.7.9.5
PATCH v5 10/16 target-or32: Add timer support
In reply to Jia LiuAdd OpenRISC timer support.
--- hw/openrisc_timer.c | 130 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+)
hw/openrisc_timer.c +130 -0
@@ -22,9 +22,139 @@#include "openrisc_cpudev.h" #include "qemu-timer.h" +#define TIMER_FREQ (20 * 1000 * 1000)/* 20MHz */ + +/* The time when TTCR changes */ +static uint64_t last_clk; +static int is_counting; + +/* Timer Mode */ +enum { +TIMER_NONE = (0 <<30 ), +TIMER_INTR = (1 <<30 ), +TIMER_SHOT = (2 <<30 ), +TIMER_CONT = (3 <<30 ), +}; +/* Reset Timer */ void cpu_openrisc_timer_reset (CPUOpenRISCState *env) { env->ttmr =0x00000000 ; env->ttcr =0x00000000 ; } + +static void count_update (CPUOpenRISCState *env) +{ +uint64_t now, next; +uint32_t wait; + + now =qemu_get_clock_ns (vm_clock); +if (!is_counting) { +qemu_del_timer (env->timer); + last_clk = now; +return ; + } + + env->ttcr += (uint32_t )muldiv64 (now - last_clk,TIMER_FREQ , +get_ticks_per_sec ()); + last_clk = now; + +if ((env->ttmr &TTMR_TP ) <= (env->ttcr &TTMR_TP )) { + wait =TTMR_TP - (env->ttcr &TTMR_TP ) +1 ; + wait += env->ttmr &TTMR_TP ; + }else { + wait = (env->ttmr &TTMR_TP ) - (env->ttcr &TTMR_TP ); + } + + next = now +muldiv64 (wait,get_ticks_per_sec (),TIMER_FREQ ); +qemu_mod_timer (env->timer, next); +} + +static void count_start (CPUOpenRISCState *env) +{ + is_counting =1 ; +count_update (env); +} + +static void count_stop (CPUOpenRISCState *env) +{ + is_counting =0 ; +count_update (env); +} + +uint32_t cpu_openrisc_get_count (CPUOpenRISCState *env) +{ +count_update (env); +return env->ttcr; +} + +void cpu_openrisc_store_count (CPUOpenRISCState *env,uint32_t count) +{ +/* Store new count register */ + env->ttcr = count; +if (env->ttmr &TIMER_NONE ) { +return ; + } +count_start (env); +} + +void cpu_openrisc_store_compare (CPUOpenRISCState *env,uint32_t value) +{ +int ip = env->ttmr &TTMR_IP ; + +if (value &TTMR_IP ) {/* Keep IP bit */ + env->ttmr = (value & ~TTMR_IP ) + ip; + }else {/* Clear IP bit */ + env->ttmr = value & ~TTMR_IP ; + env->interrupt_request &= ~CPU_INTERRUPT_TIMER ; + } +count_update (env); + +switch (env->ttmr &TTMR_M ) { +case TIMER_NONE : +count_stop (env); +break ; +case TIMER_INTR : +count_start (env); +break ; +case TIMER_SHOT : +count_start (env); +break ; +case TIMER_CONT : +count_start (env); +break ; + } +} + +static void openrisc_timer_cb (void *opaque) +{ +CPUOpenRISCState *env = opaque; + +if ((env->ttmr &TTMR_IE ) && +qemu_timer_expired (env->timer,qemu_get_clock_ns (vm_clock))) { + env->ttmr |=TTMR_IP ; + env->interrupt_request |=CPU_INTERRUPT_TIMER ; + } + +switch (env->ttmr &TTMR_M ) { +case TIMER_NONE : +break ; +case TIMER_INTR : + env->ttcr =0 ; +count_start (env); +break ; +case TIMER_SHOT : +count_stop (env); +break ; +case TIMER_CONT : +count_start (env); +break ; + } +} + +void cpu_openrisc_clock_init (CPUOpenRISCState *env) +{ + env->timer =qemu_new_timer_ns (vm_clock, &openrisc_timer_cb, env); + env->ttmr =0 ; + env->ttcr =0 ; +}
Signature · 1 line
1.7.9.5
PATCH v5 11/16 target-or32: Add a IIS dummy board
In reply to Jia LiuAdd a dummy board for IIS.
--- hw/openrisc/Makefile.objs | 2 +- hw/openrisc_sim.c | 145 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 146 insertions(+), 1 deletion(-) create mode 100644 hw/openrisc_sim.c
hw/openrisc/Makefile.objs +1 -1
@@ -1,3 +1,3 @@ -obj-y = openrisc_pic.o openrisc_timer.o +obj-y = openrisc_pic.o openrisc_sim.o openrisc_timer.o obj-y := $(addprefix ../,$(obj-y))
hw/openrisc_sim.c new file +145 -0
145 lines not on this page · raw message
Signature · 1 line
1.7.9.5
PATCH v5 12/16 target-or32: Add system instructions
In reply to Jia LiuAdd OpenRISC system instruction support.
--- target-openrisc/Makefile.objs | 3 +- target-openrisc/helper.h | 4 + target-openrisc/sys_helper.c | 233 +++++++++++++++++++++++++++++++++++++++++ target-openrisc/translate.c | 20 ++++ 4 files changed, 259 insertions(+), 1 deletion(-) create mode 100644 target-openrisc/sys_helper.c
target-openrisc/Makefile.objs +2 -1
@@ -1,3 +1,4 @@ obj-$(CONFIG_SOFTMMU) += machine.o obj-y += cpu.o excp.o intrpt.o mmu.o translate.o -obj-y += excp_helper.o fpu_helper.o int_helper.o intrpt_helper.o mmu_helper.o +obj-y += excp_helper.o fpu_helper.o int_helper.o intrpt_helper.o \ + mmu_helper.o sys_helper.o
target-openrisc/helper.h +4 -0
@@ -62,4 +62,8 @@ DEF_HELPER_FLAGS_1(fl1, 0, tl, tl)/* interrupt */ DEF_HELPER_FLAGS_1 (rfe,0 , void, env) +/* sys */ +DEF_HELPER_FLAGS_4(mtspr, 0, void, env, tl, tl, tl) +DEF_HELPER_FLAGS_4(mfspr, 0, void, env, tl, tl, tl) +#include "def-helper.h"
target-openrisc/sys_helper.c new file +233 -0
233 lines not on this page · raw message
target-openrisc/translate.c +20 -0
@@ -1241,10 +1241,30 @@ static void dec_misc(DisasContext *dc, CPUOpenRISCState *env, uint32_t insn)case 0x2d :/*l.mfspr*/ LOG_DIS ("l.mfspr r%d, r%d, %d\n" , rd, ra,I16 ); + { +TCGv_i32 ti =tcg_const_i32 (I16 ); +TCGv td =tcg_const_tl (rd); +TCGv ta =tcg_const_tl (ra); +gen_helper_mfspr (cpu_env, td, ta, ti); +tcg_temp_free_i32 (ti); +tcg_temp_free (td); +tcg_temp_free (ta); + }break ;case 0x30 :/*l.mtspr*/ LOG_DIS ("l.mtspr %d, r%d, r%d, %d\n" ,I5 , ra, rb,I11 ); + { +TCGv_i32 im =tcg_const_i32 (tmp); +TCGv ta =tcg_temp_new (); +TCGv tb =tcg_temp_new (); +tcg_gen_mov_tl (ta, cpu_R[ra]); +tcg_gen_mov_tl (tb, cpu_R[rb]); +gen_helper_mtspr (cpu_env, ta, tb, im); +tcg_temp_free_i32 (im); +tcg_temp_free (ta); +tcg_temp_free (tb); + }break ;case 0x34 :/*l.sd*/
Signature · 1 line
1.7.9.5
PATCH v5 13/16 target-or32: Add gdb stub support
In reply to Jia LiuAdd QEMU OpenRISC gdb stub support.
--- gdbstub.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+)
gdbstub.c +64 -0
@@ -1155,6 +1155,68 @@ static int cpu_gdb_write_register(CPUMIPSState *env, uint8_t *mem_buf, int n)return sizeof (target_ulong); } +#elif defined(TARGET_OPENRISC ) + +#define NUM_CORE_REGS (32 + 3) + +static int cpu_gdb_read_register (CPUOpenRISCState *env,uint8_t *mem_buf,int n) +{ +if (n <32 ) { +GET_REG32 (env->gpr[n]); + }else { +switch (n) { +case 32 :/* PPC */ +GET_REG32 (env->ppc); +break ; + +case 33 :/* NPC */ +GET_REG32 (env->npc); +break ; + +case 34 :/* SR */ +GET_REG32 (env->sr); +break ; + +default : +break ; + } + } +return 0 ; +} + +static int cpu_gdb_write_register (CPUOpenRISCState *env, +uint8_t *mem_buf,int n) +{ +uint32_t tmp; + +if (n >NUM_CORE_REGS ) { +return 0 ; + } + + tmp =ldl_p (mem_buf); + +if (n <32 ) { + env->gpr[n] = tmp; + }else { +switch (n) { +case 32 :/* PPC */ + env->ppc = tmp; +break ; + +case 33 :/* NPC */ + env->npc = tmp; +break ; + +case 34 :/* SR */ + env->sr = tmp; +break ; + +default : +break ; + } + } +return 4 ; +}#elif defined (TARGET_SH4 )/* Hint: Use "set architecture sh4" in GDB to see fpu registers */
@@ -1924,6 +1986,8 @@ static void gdb_set_cpu_pc(GDBState *s, target_ulong pc) }#elif defined (TARGET_MICROBLAZE) s->c_cpu->sregs[SR_PC ] = pc; +#elif defined(TARGET_OPENRISC) + s->c_cpu->pc = pc;#elif defined (TARGET_CRIS) s->c_cpu->pc = pc;#elif defined (TARGET_ALPHA)
Signature · 1 line
1.7.9.5
PATCH v5 14/16 target-or32: Add linux syscall, signal and termbits
In reply to Jia LiuAdd linux syscall, signal and termbits.
--- linux-user/openrisc/syscall.h | 24 ++ linux-user/openrisc/syscall_nr.h | 506 +++++++++++++++++++++++++++++++++++ linux-user/openrisc/target_signal.h | 26 ++ linux-user/openrisc/termbits.h | 294 ++++++++++++++++++++ 4 files changed, 850 insertions(+) create mode 100644 linux-user/openrisc/syscall.h create mode 100644 linux-user/openrisc/syscall_nr.h create mode 100644 linux-user/openrisc/target_signal.h create mode 100644 linux-user/openrisc/termbits.h
linux-user/openrisc/syscall.h new file +24 -0
@@ -0,0 +1,24 @@ +struct target_pt_regs { +union { +struct { +/* Named registers */ +uint32_t sr;/* Stored in place of r0 */ +target_ulong sp;/* r1 */ + }; +struct { +/* Old style */ +target_ulong offset[2 ]; +target_ulong gprs[30 ]; + }; +struct { +/* New style */ +target_ulong gpr[32 ]; + }; + }; +target_ulong pc; +target_ulong orig_gpr11;/* For restarting system calls */ +uint32_t syscallno;/* Syscall number (used by strace) */ +target_ulong dummy;/* Cheap alignment fix */ +}; + +#define UNAME_MACHINE "openrisc"
linux-user/openrisc/syscall_nr.h new file +506 -0
506 lines not on this page · raw message
linux-user/openrisc/target_signal.h new file +26 -0
@@ -0,0 +1,26 @@ +#ifndef TARGET_SIGNAL_H +#define TARGET_SIGNAL_H + +#include "cpu.h" + +/* this struct defines a stack used during syscall handling */ + +typedef struct target_sigaltstack { +abi_long ss_sp; +abi_ulong ss_size; +abi_long ss_flags; +}target_stack_t ; + +/* sigaltstack controls */ +#define TARGET_SS_ONSTACK 1 +#define TARGET_SS_DISABLE 2 + +#define TARGET_MINSIGSTKSZ 2048 +#define TARGET_SIGSTKSZ 8192 + +static inline abi_ulong get_sp_from_cpustate (CPUOpenRISCState *state) +{ +return state->gpr[1 ]; +} + +#endif /* TARGET_SIGNAL_H */
linux-user/openrisc/termbits.h new file +294 -0
294 lines not on this page · raw message
Signature · 1 line
1.7.9.5
PATCH v5 15/16 target-or32: Add linux user support
In reply to Jia LiuAdd OpenRISC linux user support.
--- configure | 1 + default-configs/or32-linux-user.mak | 2 + linux-user/elfload.c | 41 +++++++ linux-user/main.c | 100 +++++++++++++++ linux-user/signal.c | 229 +++++++++++++++++++++++++++++++++++ linux-user/syscall.c | 2 +- linux-user/syscall_defs.h | 40 +++++- target-openrisc/cpu.h | 12 ++ 8 files changed, 423 insertions(+), 4 deletions(-) create mode 100644 default-configs/or32-linux-user.mak
configure +1 -0
@@ -952,6 +952,7 @@ microblaze-linux-user \ microblazeel-linux-user \ mips-linux-user \ mipsel-linux-user \ +or32-linux-user \ ppc-linux-user \ ppc64-linux-user \ ppc64abi32-linux-user \
default-configs/or32-linux-user.mak new file +2 -0
@@ -0,0 +1,2 @@ +# Default configuration for or32-linux-user +
linux-user/elfload.c +41 -0
47 lines not on this page · raw message
linux-user/main.c +100 -0
118 lines not on this page · raw message
linux-user/signal.c +229 -0
235 lines not on this page · raw message
linux-user/syscall.c +1 -1
@@ -7377,7 +7377,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,case TARGET_NR_sigaltstack:#if defined(TARGET_I386 ) || defined(TARGET_ARM ) || defined(TARGET_MIPS ) || \ defined(TARGET_SPARC ) || defined(TARGET_PPC ) || defined(TARGET_ALPHA ) || \ - defined(TARGET_M68K ) || defined(TARGET_S390X ) + defined(TARGET_M68K ) || defined(TARGET_S390X ) || defined(TARGET_OPENRISC ) ret =do_sigaltstack (arg1, arg2,get_sp_from_cpustate ((CPUArchState *)cpu_env));break ;#else
linux-user/syscall_defs.h +37 -3
@@ -59,7 +59,7 @@#if defined(TARGET_I386 ) || defined(TARGET_ARM ) || defined(TARGET_SH4 ) \ || defined(TARGET_M68K ) || defined(TARGET_CRIS ) || defined(TARGET_UNICORE32 ) \ - || defined(TARGET_S390X ) + || defined(TARGET_S390X ) || defined(TARGET_OPENRISC )#define TARGET_IOC_SIZEBITS 14#define TARGET_IOC_DIRBITS 2
@@ -323,7 +323,7 @@ int do_sigaction(int sig, const struct target_sigaction *act, ||defined (TARGET_PPC ) ||defined (TARGET_MIPS ) ||defined (TARGET_SH4 ) \ ||defined (TARGET_M68K ) ||defined (TARGET_ALPHA ) ||defined (TARGET_CRIS ) \ ||defined (TARGET_MICROBLAZE ) ||defined (TARGET_UNICORE32 ) \ - || defined(TARGET_S390X) + || defined(TARGET_S390X) || defined(TARGET_OPENRISC)#if defined(TARGET_SPARC )#define TARGET_SA_NOCLDSTOP 8u
@@ -344,6 +344,14 @@ int do_sigaction(int sig, const struct target_sigaction *act,#if !defined(TARGET_ABI_MIPSN32 ) && !defined(TARGET_ABI_MIPSN64 )#define TARGET_SA_RESTORER 0x04000000/* Only for O32 */ #endif +#elif defined(TARGET_OPENRISC ) +#define TARGET_SA_NOCLDSTOP 0x00000001 +#define TARGET_SA_NOCLDWAIT 0x00000002 +#define TARGET_SA_SIGINFO 0x00000004 +#define TARGET_SA_ONSTACK 0x08000000 +#define TARGET_SA_RESTART 0x10000000 +#define TARGET_SA_NODEFER 0x40000000 +#define TARGET_SA_RESETHAND 0x80000000#elif defined(TARGET_ALPHA )#define TARGET_SA_ONSTACK 0x00000001#define TARGET_SA_RESTART 0x00000002
@@ -448,6 +456,7 @@ int do_sigaction(int sig, const struct target_sigaction *act,#else +/* OpenRISC Using the general signals */ #define TARGET_SIGHUP 1#define TARGET_SIGINT 2#define TARGET_SIGQUIT 3
@@ -1086,7 +1095,8 @@ struct target_winsize {#endif #if (defined(TARGET_I386) && defined(TARGET_ABI32)) || defined(TARGET_ARM) \ - || defined(TARGET_CRIS) || defined(TARGET_UNICORE32) + || defined(TARGET_CRIS) || defined(TARGET_UNICORE32) \ + || defined(TARGET_OPENRISC) struct target_stat { unsigned short st_dev; unsigned short __pad1;
@@ -1783,6 +1793,30 @@ struct target_stat {abi_long st_blocks; abi_ulong __unused[3]; }; +#elif defined(TARGET_OPENRISC) +struct target_stat { +abi_ulong st_dev; +abi_ulong st_ino; +abi_ulong st_nlink; + +unsigned int st_mode; +unsigned int st_uid; +unsigned int st_gid; +unsigned int __pad0; +abi_ulong st_rdev; +abi_long st_size; +abi_long st_blksize; +abi_long st_blocks;/* Number 512-byte blocks allocated. */ + +abi_ulong target_st_atime; +abi_ulong target_st_atime_nsec; +abi_ulong target_st_mtime; +abi_ulong target_st_mtime_nsec; +abi_ulong target_st_ctime; +abi_ulong target_st_ctime_nsec; + +abi_long __unused[3 ]; +};#else #error unsupported CPU#endif
target-openrisc/cpu.h +12 -0
@@ -360,11 +360,13 @@ void do_interrupt(CPUOpenRISCState *env);void openrisc_translate_init (void );int cpu_openrisc_handle_mmu_fault (CPUOpenRISCState *env,target_ulong address,int rw,int mmu_idx); +int cpu_openrisc_signal_handler (int host_signum,void *pinfo,void *puc);#define cpu_list cpu_openrisc_list#define cpu_exec cpu_openrisc_exec#define cpu_gen_code cpu_openrisc_gen_code#define cpu_handle_mmu_fault cpu_openrisc_handle_mmu_fault +#define cpu_signal_handler cpu_openrisc_signal_handler#define CPU_SAVE_VERSION 1
@@ -396,6 +398,16 @@ static inline CPUOpenRISCState *cpu_init(const char *cpu_model)return NULL ; } +#if defined(CONFIG_USER_ONLY ) +static inline void cpu_clone_regs (CPUOpenRISCState *env,target_ulong newsp) +{ +if (newsp) { + env->gpr[1 ] = newsp; + } + env->gpr[2 ] =0 ; +} +#endif +#include "cpu-all.h" static inline void cpu_get_tb_cpu_state(CPUOpenRISCState *env,
Signature · 1 line
1.7.9.5
PATCH v5 16/16 target-or32: Add testcases
In reply to Jia LiuAdd testcases.
--- tests/tcg/openrisc/Makefile | 71 +++++++++++++++++++++++++++ tests/tcg/openrisc/test_add.c | 34 +++++++++++++ tests/tcg/openrisc/test_addc.c | 39 +++++++++++++++ tests/tcg/openrisc/test_addi.c | 31 ++++++++++++ tests/tcg/openrisc/test_addic.c | 33 +++++++++++++ tests/tcg/openrisc/test_and_or.c | 61 +++++++++++++++++++++++ tests/tcg/openrisc/test_bf.c | 46 ++++++++++++++++++ tests/tcg/openrisc/test_bnf.c | 50 +++++++++++++++++++ tests/tcg/openrisc/test_div.c | 32 ++++++++++++ tests/tcg/openrisc/test_divu.c | 32 ++++++++++++ tests/tcg/openrisc/test_extx.c | 72 +++++++++++++++++++++++++++ tests/tcg/openrisc/test_fx.c | 53 ++++++++++++++++++++ tests/tcg/openrisc/test_j.c | 26 ++++++++++ tests/tcg/openrisc/test_jal.c | 26 ++++++++++ tests/tcg/openrisc/test_lf_add.c | 39 +++++++++++++++ tests/tcg/openrisc/test_lf_div.c | 34 +++++++++++++ tests/tcg/openrisc/test_lf_eqs.c | 84 ++++++++++++++++++++++++++++++++ tests/tcg/openrisc/test_lf_ges.c | 84 ++++++++++++++++++++++++++++++++ tests/tcg/openrisc/test_lf_gts.c | 84 ++++++++++++++++++++++++++++++++ tests/tcg/openrisc/test_lf_les.c | 84 ++++++++++++++++++++++++++++++++ tests/tcg/openrisc/test_lf_lts.c | 91 ++++++++++++++++++++++++++++++++++ tests/tcg/openrisc/test_lf_mul.c | 22 +++++++++ tests/tcg/openrisc/test_lf_nes.c | 87 +++++++++++++++++++++++++++++++++ tests/tcg/openrisc/test_lf_rem.c | 32 ++++++++++++ tests/tcg/openrisc/test_lf_sub.c | 33 +++++++++++++ tests/tcg/openrisc/test_logic.c | 100 ++++++++++++++++++++++++++++++++++++++ tests/tcg/openrisc/test_lx.c | 78 +++++++++++++++++++++++++++++ tests/tcg/openrisc/test_movhi.c | 30 ++++++++++++ tests/tcg/openrisc/test_mul.c | 47 ++++++++++++++++++ tests/tcg/openrisc/test_muli.c | 47 ++++++++++++++++++ tests/tcg/openrisc/test_mulu.c | 47 ++++++++++++++++++ tests/tcg/openrisc/test_sfeq.c | 44 +++++++++++++++++ tests/tcg/openrisc/test_sfeqi.c | 39 +++++++++++++++ tests/tcg/openrisc/test_sfges.c | 44 +++++++++++++++++ tests/tcg/openrisc/test_sfgesi.c | 40 +++++++++++++++ tests/tcg/openrisc/test_sfgeu.c | 44 +++++++++++++++++ tests/tcg/openrisc/test_sfgeui.c | 41 ++++++++++++++++ tests/tcg/openrisc/test_sfgts.c | 45 +++++++++++++++++ tests/tcg/openrisc/test_sfgtsi.c | 41 ++++++++++++++++ tests/tcg/openrisc/test_sfgtu.c | 43 ++++++++++++++++ tests/tcg/openrisc/test_sfgtui.c | 42 ++++++++++++++++ tests/tcg/openrisc/test_sfles.c | 26 ++++++++++ tests/tcg/openrisc/test_sflesi.c | 39 +++++++++++++++ tests/tcg/openrisc/test_sfleu.c | 43 ++++++++++++++++ tests/tcg/openrisc/test_sfleui.c | 39 +++++++++++++++ tests/tcg/openrisc/test_sflts.c | 43 ++++++++++++++++ tests/tcg/openrisc/test_sfltsi.c | 38 +++++++++++++++ tests/tcg/openrisc/test_sfltu.c | 41 ++++++++++++++++ tests/tcg/openrisc/test_sfltui.c | 39 +++++++++++++++ tests/tcg/openrisc/test_sfne.c | 43 ++++++++++++++++ tests/tcg/openrisc/test_sfnei.c | 38 +++++++++++++++ tests/tcg/openrisc/test_sub.c | 34 +++++++++++++ 52 files changed, 2475 insertions(+) create mode 100644 tests/tcg/openrisc/Makefile create mode 100644 tests/tcg/openrisc/test_add.c create mode 100644 tests/tcg/openrisc/test_addc.c create mode 100644 tests/tcg/openrisc/test_addi.c create mode 100644 tests/tcg/openrisc/test_addic.c create mode 100644 tests/tcg/openrisc/test_and_or.c create mode 100644 tests/tcg/openrisc/test_bf.c create mode 100644 tests/tcg/openrisc/test_bnf.c create mode 100644 tests/tcg/openrisc/test_div.c create mode 100644 tests/tcg/openrisc/test_divu.c create mode 100644 tests/tcg/openrisc/test_extx.c create mode 100644 tests/tcg/openrisc/test_fx.c create mode 100644 tests/tcg/openrisc/test_j.c create mode 100644 tests/tcg/openrisc/test_jal.c create mode 100644 tests/tcg/openrisc/test_lf_add.c create mode 100644 tests/tcg/openrisc/test_lf_div.c create mode 100644 tests/tcg/openrisc/test_lf_eqs.c create mode 100644 tests/tcg/openrisc/test_lf_ges.c create mode 100644 tests/tcg/openrisc/test_lf_gts.c create mode 100644 tests/tcg/openrisc/test_lf_les.c create mode 100644 tests/tcg/openrisc/test_lf_lts.c create mode 100644 tests/tcg/openrisc/test_lf_mul.c create mode 100644 tests/tcg/openrisc/test_lf_nes.c create mode 100644 tests/tcg/openrisc/test_lf_rem.c create mode 100644 tests/tcg/openrisc/test_lf_sub.c create mode 100644 tests/tcg/openrisc/test_logic.c create mode 100644 tests/tcg/openrisc/test_lx.c create mode 100644 tests/tcg/openrisc/test_movhi.c create mode 100644 tests/tcg/openrisc/test_mul.c create mode 100644 tests/tcg/openrisc/test_muli.c create mode 100644 tests/tcg/openrisc/test_mulu.c create mode 100644 tests/tcg/openrisc/test_sfeq.c create mode 100644 tests/tcg/openrisc/test_sfeqi.c create mode 100644 tests/tcg/openrisc/test_sfges.c create mode 100644 tests/tcg/openrisc/test_sfgesi.c create mode 100644 tests/tcg/openrisc/test_sfgeu.c create mode 100644 tests/tcg/openrisc/test_sfgeui.c create mode 100644 tests/tcg/openrisc/test_sfgts.c create mode 100644 tests/tcg/openrisc/test_sfgtsi.c create mode 100644 tests/tcg/openrisc/test_sfgtu.c create mode 100644 tests/tcg/openrisc/test_sfgtui.c create mode 100644 tests/tcg/openrisc/test_sfles.c create mode 100644 tests/tcg/openrisc/test_sflesi.c create mode 100644 tests/tcg/openrisc/test_sfleu.c create mode 100644 tests/tcg/openrisc/test_sfleui.c create mode 100644 tests/tcg/openrisc/test_sflts.c create mode 100644 tests/tcg/openrisc/test_sfltsi.c create mode 100644 tests/tcg/openrisc/test_sfltu.c create mode 100644 tests/tcg/openrisc/test_sfltui.c create mode 100644 tests/tcg/openrisc/test_sfne.c create mode 100644 tests/tcg/openrisc/test_sfnei.c create mode 100644 tests/tcg/openrisc/test_sub.c
tests/tcg/openrisc/Makefile new file +71 -0
@@ -0,0 +1,71 @@ +-include ../../config-host.mak + +CROSS = or32-linux- + +SIM = qemu-or32 + +CC = $(CROSS)gcc + +TESTCASES = test_add.tst +TESTCASES = test_sub.tst +TESTCASES += test_addc.tst +TESTCASES += test_addi.tst +TESTCASES += test_addic.tst +TESTCASES += test_and_or.tst +TESTCASES += test_bf.tst +TESTCASES += test_bnf.tst +TESTCASES += test_div.tst +TESTCASES += test_divu.tst +TESTCASES += test_extx.tst +TESTCASES += test_fx.tst +TESTCASES += test_jal.tst +TESTCASES += test_j.tst +TESTCASES += test_lf_div.tst +TESTCASES += test_lf_eqs.tst +TESTCASES += test_lf_ges.tst +TESTCASES += test_lf_gts.tst +TESTCASES += test_lf_les.tst +TESTCASES += test_lf_lts.tst +TESTCASES += test_lf_mul.tst +TESTCASES += test_lf_nes.tst +TESTCASES += test_lf_rem.tst +TESTCASES += test_lf_sub.tst +TESTCASES += test_lf_add.tst +TESTCASES += test_logic.tst +TESTCASES += test_lx.tst +TESTCASES += test_movhi.tst +TESTCASES += test_mul.tst +TESTCASES += test_mulu.tst +TESTCASES += test_muli.tst +TESTCASES += test_sfeq.tst +TESTCASES += test_sfeqi.tst +TESTCASES += test_sfges.tst +TESTCASES += test_sfgesi.tst +TESTCASES += test_sfgeu.tst +TESTCASES += test_sfgeui.tst +TESTCASES += test_sfgts.tst +TESTCASES += test_sfgtsi.tst +TESTCASES += test_sfgtu.tst +TESTCASES += test_sfgtui.tst +TESTCASES += test_sfles.tst +TESTCASES += test_sflesi.tst +TESTCASES += test_sfleu.tst +TESTCASES += test_sfleui.tst +TESTCASES += test_sflts.tst +TESTCASES += test_sfltsi.tst +TESTCASES += test_sfltu.tst +TESTCASES += test_sfltui.tst +TESTCASES += test_sfne.tst +TESTCASES += test_sfnei.tst + +all: $(TESTCASES) + +%.tst: %.c + $(CC) -static $< -o $@ + + +check: $(TESTCASES) + @for case in $(TESTCASES); do $(SIM) $$case; echo $$case pass!; sleep 0.2; done + +clean: + $(RM) -rf $(TESTCASES)
tests/tcg/openrisc/test_add.c new file +34 -0
@@ -0,0 +1,34 @@ +#include <stdio.h> + +int main (void ) +{ +int a, b; +int result; + + a =0x100 ; + b =0x100 ; + result =0x200 ; + + __asm + ("l.add %0, %0, %1\n\t" + :"+r" (a) + :"r" (b) + ); +if (a != result) { +printf ("add error\n" ); + } + + a =0xffff ; + b =0x1 ; + result =0x10000 ; + __asm + ("l.add %0, %0, %1\n\t" + :"+r" (a) + :"r" (b) + ); +if (a != result) { +printf ("add error\n" ); + } + +return 0 ; +}
tests/tcg/openrisc/test_addc.c new file +39 -0
@@ -0,0 +1,39 @@ +#include <stdio.h> + +int main (void ) +{ +int a, b, c; +int result; + + b =0x01 ; + c =0xffffffff ; + result =1 ; + + __asm + ("l.addc %0, %1, %2\n\t" + :"=r" (a) + :"r" (b),"r" (c) + ); + +if (a != result) { +printf ("first addc error\n" ); + } + + b =0x01 ; + c =0xffffffff ; + result =0x80000001 ; + __asm + ("l.addc %0, %1, %2\n\t" +"l.movhi %2, 0x7fff\n\t" +"l.ori %2, %2, 0xffff\n\t" +"l.addc %0, %1, %2\n\t" + :"=r" (a) + :"r" (b),"r" (c) + ); + +if (a != result) { +printf ("addc error\n" ); + } + +return 0 ; +}
tests/tcg/openrisc/test_addi.c new file +31 -0
@@ -0,0 +1,31 @@ +#include <stdio.h> + +int main (void ) +{ +int a, b; +int result; + + b =0x01 ; + result =0x00 ; + __asm + ("l.addi %0, %1, 0xffff\n\t" + :"=r" (a) + :"r" (b) + ); +if (a != result) { +printf ("addi error\n\t" ); + } + + b =0x010000 ; + result =0xffff ; + __asm + ("l.addi %0, %1, 0xffff\n\t" + :"=r" (a) + :"r" (b) + ); +if (a != result) { +printf ("addi error\n" ); + } + +return 0 ; +}
tests/tcg/openrisc/test_addic.c new file +33 -0
@@ -0,0 +1,33 @@ +#include <stdio.h> + +int main (void ) +{ +int a, b, c; +int result; + + a =1 ; + result =0x1 ; + + __asm + ("l.addic %0, %0, 0xffff\n\t" + :"+r" (a) + ); +if (a != result) { +printf ("first addic error\n" ); + } + + a =0x1 ; + result =0x201 ; + __asm + ("l.addic %0, %0, 0xffff\n\t" +"l.ori %0, r0, 0x100\n\t" +"l.addic %0, %0, 0x100\n\t" + :"+r" (a) + ); + +if (a != result) { +printf ("second addic error\n" ); + } + +return 0 ; +}
tests/tcg/openrisc/test_and_or.c new file +61 -0
61 lines not on this page · raw message
tests/tcg/openrisc/test_bf.c new file +46 -0
46 lines not on this page · raw message
tests/tcg/openrisc/test_bnf.c new file +50 -0
50 lines not on this page · raw message
tests/tcg/openrisc/test_div.c new file +32 -0
@@ -0,0 +1,32 @@ +#include <stdio.h> + +int main (void ) +{ +int a, b, c; +int result; + + b =0x120 ; + c =0x4 ; + result =0x48 ; + + __asm + ("l.div %0, %1, %2\n\t" + :"=r" (a) + :"r" (b),"r" (c) + ); +if (a != result) { +printf ("div error\n" ); + } + + result =0x4 ; + __asm + ("l.div %0, %1, %0\n\t" + :"+r" (a) + :"r" (b) + ); +if (a != result) { +printf ("div error\n" ); + } + +return 0 ; +}
tests/tcg/openrisc/test_divu.c new file +32 -0
@@ -0,0 +1,32 @@ +#include <stdio.h> + +int main (void ) +{ +int a, b, c; +int result; + + b =0x120 ; + c =0x4 ; + result =0x48 ; + + __asm + ("l.divu %0, %1, %2\n\t" + :"=r" (a) + :"r" (b),"r" (c) + ); +if (a != result) { +printf ("divu error\n" ); + } + + result =0x4 ; + __asm + ("l.divu %0, %1, %0\n\t" + :"+r" (a) + :"r" (b) + ); +if (a != result) { +printf ("divu error\n" ); + } + +return 0 ; +}
tests/tcg/openrisc/test_extx.c new file +72 -0
72 lines not on this page · raw message
tests/tcg/openrisc/test_fx.c new file +53 -0
53 lines not on this page · raw message
tests/tcg/openrisc/test_j.c new file +26 -0
@@ -0,0 +1,26 @@ +#include <stdio.h> + +int main (void ) +{ +int a; +int result; + + a =0 ; + result =2 ; + + __asm + ("l.addi %0, %0, 1\n\t" +"l.j j\n\t" +"l.nop\n\t" +"l.addi %0, %0, 1\n\t" +"l.nop\n\t" +"j:\n\t" +"l.addi %0, %0, 1\n\t" + :"+r" (a) + ); +if (a != result) { +printf ("j error\n" ); + } + +return 0 ; +}
tests/tcg/openrisc/test_jal.c new file +26 -0
@@ -0,0 +1,26 @@ +#include <stdio.h> + +int main (void ) +{ +int a; +int result; + + a =0 ; + result =2 ; + + __asm + ("l.addi %0, %0, 1\n\t" +"l.jal jal\n\t" +"l.nop\n\t" +"l.addi %0, %0, 1\n\t" +"l.nop\n\t" +"jal:\n\t" +"l.addi %0, %0, 1\n\t" + :"+r" (a) + ); +if (a != result) { +printf ("jal error\n" ); + } + +return 0 ; +}
tests/tcg/openrisc/test_lf_add.c new file +39 -0
@@ -0,0 +1,39 @@ +#include <stdio.h> + +int main (void ) +{ +float a, b; +float res2; + a =1.5 ; + b =2.5 ; + res2 =4.0 ; + + __asm + ("lf.add.s %0, %0, %1\n\t" + :"+r" (a) + :"r" (b) + ); + +if (a != res2) { +printf ("lf.add.s error, %f\n" , a); + } + +/* double c, d; +double res1; + +c = 1.5; +d = 1.5; +res1 = 3.00; + +__asm +("lf.add.d %0, %1, %2\n\t" +: "+r"(c) +: "r"(d) +); + +if ((e - res1) > 0.002) { +printf("lf.add.d error, %f\n", e - res1); +}*/ + +return 0 ; +}
tests/tcg/openrisc/test_lf_div.c new file +34 -0
@@ -0,0 +1,34 @@ +#include <stdio.h> + +int main (void ) +{ +float a, b, c; +float result; + b =1.5 ; + c =0.5 ; + result =3.0 ; + __asm + ("lf.div.s %0, %1, %2\n\t" + :"=r" (a) + :"r" (b),"r" (c) + ); +if (a != result) { +printf ("lf.div.s error\n" ); + } + +/* double a, b, c, res; + +b = 0x80000000; +c = 0x40; +result = 0x2000000; +__asm +("lf.div.d %0, %1, %2\n\t" +: "=r"(a) +: "r"(b), "r"(c) +); +if (a != result) { +printf("lf.div.d error\n"); +}*/ + +return 0 ; +}
tests/tcg/openrisc/test_lf_eqs.c new file +84 -0
84 lines not on this page · raw message
tests/tcg/openrisc/test_lf_ges.c new file +84 -0
84 lines not on this page · raw message
tests/tcg/openrisc/test_lf_gts.c new file +84 -0
84 lines not on this page · raw message
tests/tcg/openrisc/test_lf_les.c new file +84 -0
84 lines not on this page · raw message
tests/tcg/openrisc/test_lf_lts.c new file +91 -0
91 lines not on this page · raw message
tests/tcg/openrisc/test_lf_mul.c new file +22 -0
@@ -0,0 +1,22 @@ +#include <stdio.h> + +int main (void ) +{ +float a, b, c; +float result; + + b =1.5 ; + c =4.0 ; + result =6.0 ; + + __asm + ("lf.mul.s %0, %1, %2\n\t" + :"=r" (a) + :"r" (b),"r" (c) + ); +if (a != result) { +printf ("lf.mul.s error\n" ); + } + +return 0 ; +}
tests/tcg/openrisc/test_lf_nes.c new file +87 -0
87 lines not on this page · raw message
tests/tcg/openrisc/test_lf_rem.c new file +32 -0
@@ -0,0 +1,32 @@ +#include <stdio.h> + +int main (void ) +{ +float a, b, c; +float result; + + b =101.5 ; + c =10 ; + result =1.5 ; + +/* __asm +("lf.rem.d %0, %1, %2\n\t" +: "=r"(a) +: "r"(b), "r"(c) +); +if (a != result) { +printf("lf.rem.d error\n"); +}*/ + + __asm + ("lf.rem.s %0, %1, %2\n\t" + :"=r" (a) + :"r" (b),"r" (c) + ); + +if (a != result) { +printf ("lf.rem.s error\n" ); + } + +return 0 ; +}
tests/tcg/openrisc/test_lf_sub.c new file +33 -0
@@ -0,0 +1,33 @@ +#include <stdio.h> + +int main (void ) +{ +float a, b, c; +float result; + b =10.5 ; + c =1.5 ; + result =9.0 ; + __asm + ("lf.sub.s %0, %1, %2\n\t" + :"=r" (a) + :"r" (b),"r" (c) + ); +if (a != result) { +printf ("lf.sub.s error\n" ); + } + +/* b = 0x999; +c = 0x654; +result = 0x345; + +__asm +("lf.sub.d %0, %1, %2\n\t" +: "=r"(a) +: "r"(b), "r"(c) +); +if (a != result) { +printf("lf.sub.d error\n"); +}*/ + +return 0 ; +}
tests/tcg/openrisc/test_logic.c new file +100 -0
100 lines not on this page · raw message
tests/tcg/openrisc/test_lx.c new file +78 -0
78 lines not on this page · raw message
tests/tcg/openrisc/test_movhi.c new file +30 -0
@@ -0,0 +1,30 @@ +#include <stdio.h> + +int main (void ) +{ +int a; +int result; + + result =0x1222 ; + + __asm + ("l.movhi r3, 0x1222\n\t" +"l.srli %0, r3, 16\n\t" + :"=r" (a) + ); +if (a != result) { +printf ("movhi error\n" ); + } + + result =0x1111 ; + __asm + ("l.movhi r8, 0x1111\n\t" +"l.srli %0, r8, 16\n\t" + :"=r" (a) + ); +if (a != result) { +printf ("movhi error\n" ); + } + +return 0 ; +}
tests/tcg/openrisc/test_mul.c new file +47 -0
47 lines not on this page · raw message
tests/tcg/openrisc/test_muli.c new file +47 -0
47 lines not on this page · raw message
tests/tcg/openrisc/test_mulu.c new file +47 -0
47 lines not on this page · raw message
tests/tcg/openrisc/test_sfeq.c new file +44 -0
44 lines not on this page · raw message
tests/tcg/openrisc/test_sfeqi.c new file +39 -0
@@ -0,0 +1,39 @@ +#include <stdio.h> + +int main (void ) +{ +int a; +int result; + + a =1 ; + result =2 ; + + __asm + ("1:\n\t" +"l.addi %0, %0, 0x1\n\t" +"l.sfeqi %0, 0x80\n\t" +"l.bf 1b\n\t" +"l.nop\n\t" + :"+r" (a) + ); +if (a != result) { +printf ("sfeqi error\n" ); + } + + a =0x7f ; + result =0x81 ; + + __asm + ("2:\n\t" +"l.addi %0, %0, 0x1\n\t" +"l.sfeqi %0, 0x80\n\t" +"l.bf 2b\n\t" +"l.nop\n\t" + :"+r" (a) + ); +if (a != result) { +printf ("sfeqi error\n" ); + } + +return 0 ; +}
tests/tcg/openrisc/test_sfges.c new file +44 -0
44 lines not on this page · raw message
tests/tcg/openrisc/test_sfgesi.c new file +40 -0
@@ -0,0 +1,40 @@ +#include <stdio.h> +int main (void ) +{ +int a, b; +int result; + + a =0 ; + result =1 ; + + __asm + ("1:\n\t" +"l.addi %0, %0, 1\n\t" +"l.sfgesi %0, 0x3\n\t" +"l.bf 1b\n\t" +"l.nop\n\t" + :"+r" (a) + ); +if (a != result) { +printf ("sfgesi error\n" ); + } + + a =0xff ; + b =1 ; + result =2 ; + + __asm + ("1:\n\t" +"l.sub %0, %0, %1\n\t" +"l.sfgesi %0, 0x3\n\t" +"l.bf 1b\n\t" +"l.nop\n\t" + :"+r" (a) + :"r" (b) + ); +if (a != result) { +printf ("sfgesi error\n" ); + } + +return 0 ; +}
tests/tcg/openrisc/test_sfgeu.c new file +44 -0
44 lines not on this page · raw message
tests/tcg/openrisc/test_sfgeui.c new file +41 -0
41 lines not on this page · raw message
tests/tcg/openrisc/test_sfgts.c new file +45 -0
45 lines not on this page · raw message
tests/tcg/openrisc/test_sfgtsi.c new file +41 -0
41 lines not on this page · raw message
tests/tcg/openrisc/test_sfgtu.c new file +43 -0
43 lines not on this page · raw message
tests/tcg/openrisc/test_sfgtui.c new file +42 -0
42 lines not on this page · raw message
tests/tcg/openrisc/test_sfles.c new file +26 -0
@@ -0,0 +1,26 @@ +#include <stdio.h> + +int main (void ) +{ +int a, b; +int result; + + a =0 ; + b =3 ; + result =4 ; + + __asm + ("1:\n\t" +"l.addi %0, %0, 4\n\t" +"l.sfles %0, %1\n\t" +"l.bf 1b\n\t" +"l.nop\n\t" + :"+r" (a) + :"r" (b) + ); +if (a != result) { +printf ("sfles error\n" ); + } + +return 0 ; +}
tests/tcg/openrisc/test_sflesi.c new file +39 -0
@@ -0,0 +1,39 @@ +#include <stdio.h> + +int main (void ) +{ +int a; +int result; + + a =0 ; + result =4 ; + + __asm + ("1:\n\t" +"l.addi %0, %0, 4\n\t" +"l.sflesi %0, 0x3\n\t" +"l.bf 1b\n\t" +"l.nop\n\t" + :"+r" (a) + ); +if (a != result) { +printf ("sflesi error\n" ); + } + + a =0 ; + result =4 ; + + __asm + ("1:\n\t" +"l.addi %0, %0, 1\n\t" +"l.sflesi %0, 0x3\n\t" +"l.bf 1b\n\t" +"l.nop\n\t" + :"+r" (a) + ); +if (a != result) { +printf ("sflesi error\n" ); + } + +return 0 ; +}
tests/tcg/openrisc/test_sfleu.c new file +43 -0
43 lines not on this page · raw message
tests/tcg/openrisc/test_sfleui.c new file +39 -0
@@ -0,0 +1,39 @@ +#include <stdio.h> + +int main (void ) +{ +int a; +int result; + + a =0 ; + result =4 ; + + __asm + ("1:\n\t" +"l.addi %0, %0, 4\n\t" +"l.sfleui %0, 0x3\n\t" +"l.bf 1b\n\t" +"l.nop\n\t" + :"+r" (a) + ); +if (a != result) { +printf ("sfleui error\n" ); + } + + a =0 ; + result =4 ; + + __asm + ("1:\n\t" +"l.addi %0, %0, 1\n\t" +"l.sfleui %0, 0x3\n\t" +"l.bf 1b\n\t" +"l.nop\n\t" + :"+r" (a) + ); +if (a != result) { +printf ("sfleui error\n" ); + } + +return 0 ; +}
tests/tcg/openrisc/test_sflts.c new file +43 -0
43 lines not on this page · raw message
tests/tcg/openrisc/test_sfltsi.c new file +38 -0
@@ -0,0 +1,38 @@ +#include <stdio.h> + +int main (void ) +{ +int a; +int result; + + a =0 ; + result =4 ; + __asm + ("1:\n\t" +"l.addi %0, %0, 4\n\t" +"l.sfltsi %0, 0x3\n\t" +"l.bf 1b\n\t" +"l.nop\n\t" + :"+r" (a) + ); +if (a != result) { +printf ("sfltsi error\n" ); + } + + a =0 ; + result =3 ; + + __asm + ("1:\n\t" +"l.addi %0, %0, 1\n\t" +"l.sfltsi %0, 0x3\n\t" +"l.bf 1b\n\t" +"l.nop\n\t" + :"+r" (a) + ); +if (a != result) { +printf ("sfltsi error\n" ); + } + +return 0 ; +}
tests/tcg/openrisc/test_sfltu.c new file +41 -0
41 lines not on this page · raw message
tests/tcg/openrisc/test_sfltui.c new file +39 -0
@@ -0,0 +1,39 @@ +#include <stdio.h> + +int main (void ) +{ +int a; +int result; + + a =0 ; + result =4 ; + + __asm + ("1:\n\t" +"l.addi %0, %0, 4\n\t" +"l.sfltsi %0, 0x3\n\t" +"l.bf 1b\n\t" +"l.nop\n\t" + :"+r" (a) + ); +if (a != result) { +printf ("sfltui error\n" ); + } + + a =0 ; + result =3 ; + + __asm + ("1:\n\t" +"l.addi %0, %0, 1\n\t" +"l.sfltsi %0, 0x3\n\t" +"l.bf 1b\n\t" +"l.nop\n\t" + :"+r" (a) + ); +if (a != result) { +printf ("sfltui error\n" ); + } + +return 0 ; +}
tests/tcg/openrisc/test_sfne.c new file +43 -0
43 lines not on this page · raw message
tests/tcg/openrisc/test_sfnei.c new file +38 -0
@@ -0,0 +1,38 @@ +#include <stdio.h> + +int main (void ) +{ +int a; +int result; + + a =0 ; + result =3 ; + + __asm + ("1:\n\t" +"l.addi %0, %0, 3\n\t" +"l.sfnei %0, 0x3\n\t" +"l.bf 1b\n\t" +"l.nop\n\t" + :"+r" (a) + ); +if (a != result) { +printf ("sfnei error\n" ); + } + + a =0 ; + result =3 ; + __asm + ("1:\n\t" +"l.addi %0, %0, 1\n\t" +"l.sfnei %0, 0x3\n\t" +"l.bf 1b\n\t" +"l.nop\n\t" + :"+r" (a) + ); +if (a != result) { +printf ("sfnei error\n" ); + } + +return 0 ; +}
tests/tcg/openrisc/test_sub.c new file +34 -0
@@ -0,0 +1,34 @@ +#include <stdio.h> + +int main (void ) +{ +int a, b; +int result; + + a =0x100 ; + b =0x100 ; + result =0x0 ; + + __asm + ("l.sub %0, %0, %1\n\t" + :"+r" (a) + :"r" (b) + ); +if (a != result) { +printf ("sub error\n" ); + } + + a =0xffff ; + b =0x1 ; + result =0xfffe ; + __asm + ("l.sub %0, %0, %1\n\t" + :"+r" (a) + :"r" (b) + ); +if (a != result) { +printf ("sub error\n" ); + } + +return 0 ; +}
Signature · 1 line
1.7.9.5
Re: [Qemu-devel] [PATCH v5 02/16] target-or32: Add target machine
In reply to Jia LiuQuoted 16 lines · Jia Liu
Add OpenRISC target machine.
Signed-off-by Jia Liu <[email protected]>---
target-openrisc/cpu.h | 67 ++++++++++++++++++++++++++++++++++++++++++++-target-openrisc/machine.c| 22 ++++++++++++++-2 files changed, 87 insertions(+), 2 deletions(-)target-openrisc/cpu.h +0
-0@@ -44,6 +44,15 @@ struct CPUOpenRISCState; #define TARGET_PHYS_ADDR_SPACE_BITS 32 #define TARGET_VIRT_ADDR_SPACE_BITS 32
target-openrisc/cpu.h struct CPUOpenRISCState; · line 56
Quoted 10 lines
target-openrisc/cpu.h +9
-0+#define SET_FP_CAUSE (reg, v) do {\ + (reg) = ((reg) & ~(0x3f << 12)) | \ + ((v & 0x3f) << 12);\ + } while (0) +#define GET_FP_ENABLE (reg) (((reg) >> 7) & 0x1f) +#define UPDATE_FP_FLAGS (reg, v) do {\ + (reg) |= ((v & 0x1f) << 2);\ + } while (0) + /* Internel flags, delay slot flag */
Internal
target-openrisc/cpu.h enum { · line 129
Quoted 7 lines
target-openrisc/cpu.h +1
-0#define D_FLAG 1@@ -117,6 +126,40 @@ enum { IMMUCFGR_HTR = (1 << 11), }; +/* Float piont control status register */
point
Quoted 78 lines
target-openrisc/cpu.h +41
-0+enum { + FPCSR_FPEE = 1, + FPCSR_RM = (3 << 1), + FPCSR_OVF = (1 << 3), + FPCSR_UNF = (1 << 4), + FPCSR_SNF = (1 << 5), + FPCSR_QNF = (1 << 6), + FPCSR_ZF = (1 << 7), + FPCSR_IXF = (1 << 8), + FPCSR_IVF = (1 << 9), + FPCSR_INF = (1 << 10), + FPCSR_DZF = (1 << 11), +}; + +/* Exceptions indices */ +enum { + EXCP_RESET = 0x1, + EXCP_BUSERR = 0x2, + EXCP_DPF = 0x3, + EXCP_IPF = 0x4, + EXCP_TICK = 0x5, + EXCP_ALIGN = 0x6, + EXCP_ILLEGAL = 0x7, + EXCP_INT = 0x8, + EXCP_DTLBMISS = 0x9, + EXCP_ITLBMISS = 0xa, + EXCP_RANGE = 0xb, + EXCP_SYSCALL = 0xc, + EXCP_FPE = 0xd, + EXCP_TRAP = 0xe, + EXCP_NR, +}; + /* Supervisor register */ enum { SR_SM = 1,@@ -151,6 +194,14 @@ enum { OPENRISC_FEATURE_OR1200, }; +/* Tick Timer Mode Register */ +enum { + TTMR_TP = (0xfffffff), + TTMR_IP = (1 << 28), + TTMR_IE = (1 << 29), + TTMR_M = (3 << 30), +}; + typedef struct CPUOpenRISCState CPUOpenRISCState; struct CPUOpenRISCState {
target_ulonggpr[32]; /* General registers */target-openrisc/cpu.h +0
-0@@ -159,12 +210,25 @@ struct CPUOpenRISCState {
target_ulongppc; /* Prev PC */
target_ulongjmp_pc; /* Jump PC */+ target_ulong machi; /* Multiply register MACHI */
+ target_ulong maclo; /* Multiply register MACLO */target-openrisc/cpu.h +7
-0+ + target_ulong fpmaddhi; /* Multiply and add float register FPMADDHI */ + target_ulong fpmaddlo; /* Multiply and add float register FPMADDLO */ + + target_ulong epcr; /* Exception PC register */ + target_ulong eear; /* Exception EA register */ +
uint32_tsr; /* Supervisor register */uint32_tvr; /* Version register */uint32_tupr; /* Unit presence register */uint32_tcpucfgr; /* CPU configure register */uint32_tdmmucfgr; /* DMMU configure register */uint32_timmucfgr; /* IMMU configure register */
+ uint32_t esr; /* Exception supervisor register */
+ uint32_t fpcsr; /* Float register */
+ float_statusfp_status;
+
uint32_tflags; /*cpu_flags, we only use it for exception in solt so far. */uint32_tbtaken; /* theSR_Fbit */
target-openrisc/cpu.h static inline void cpu_get_tb_cpu_state(CPUOpenRISCState *env, · line 332
Quoted 5 lines
target-openrisc/cpu.h +1
-1@@ -265,7 +329,8 @@ static inline void cpu_get_tb_cpu_state(CPUOpenRISCState *env, { *pc = env->pc; *cs_base = 0; - *flags = 0; + /* D_FLAG -- branch insrtuction exception */
instruction
target-openrisc/cpu.h static inline void cpu_get_tb_cpu_state(CPUOpenRISCState *env, · line 333
Quoted 1 line
target-openrisc/cpu.h +1
-0+ *flags = (env->flags&D_FLAG);
Please add spaces around '&'. Also the parentheses are not necessary.
Quoted 44 lines
target-openrisc/cpu.h +0
-0} static inline int cpu_mmu_index(CPUOpenRISCState *env)target-openrisc/machine.c +21
-2@@ -20,11 +20,31 @@ #include "hw/hw.h" #include "hw/boards.h" +static const VMStateDescription vmstate_cpu = { + .name = "cpu", + .version_id = CPU_SAVE_VERSION, + .minimum_version_id = 1, + .minimum_version_id_old = 1, + .fields = (VMStateField[]) { + VMSTATE_UINT32_ARRAY(gpr, CPUOpenRISCState, 32), + VMSTATE_UINT32(sr, CPUOpenRISCState), + VMSTATE_UINT32(epcr, CPUOpenRISCState), + VMSTATE_UINT32(eear, CPUOpenRISCState), + VMSTATE_UINT32(esr, CPUOpenRISCState), + VMSTATE_UINT32(fpcsr, CPUOpenRISCState), + VMSTATE_UINT32(pc, CPUOpenRISCState), + VMSTATE_UINT32(npc, CPUOpenRISCState), + VMSTATE_UINT32(ppc, CPUOpenRISCState), + VMSTATE_END_OF_LIST() + } +}; + void cpu_save(QEMUFile *f, void *opaque) { + vmstate_save_state(f, &vmstate_cpu, opaque); } int cpu_load(QEMUFile *f, void *opaque, int version_id) { - return 0; + return vmstate_load_state(f, &vmstate_cpu, opaque, version_id); } --1.7.9.5
Re: [Qemu-devel] [PATCH v5 01/16] target-or32: Add target stubs and cpu support
In reply to Jia LiuQuoted 994 lines · Jia Liu
Add OpenRISC target stubs and basic cpu support.
Signed-off-by Jia Liu <[email protected]>---
arch_init.c | 2 +
arch_init.h | 1 +
configure | 14 +-
cpu-exec.c | 2 + default-configs/or32-softmmu.mak | 6 +
elf.h | 2 + hw/openrisc/Makefile.objs | 3 +
hw/openrisc_cpudev.h | 29 ++++
hw/openrisc_pic.c | 30 ++++
hw/openrisc_timer.c | 30 ++++
poison.h | 1 + target-openrisc/Makefile.objs | 3 +
target-openrisc/cpu.c | 240 +++++++++++++++++++++++++++++++target-openrisc/cpu.h| 288 ++++++++++++++++++++++++++++++++++++++target-openrisc/intrpt.c| 30 ++++target-openrisc/machine.c| 30 ++++target-openrisc/mmu.c| 39 ++++++target-openrisc/mmu_helper.c| 43 ++++++target-openrisc/translate.c| 75 ++++++++++19 files changed, 866 insertions(+), 2 deletions(-)create mode 100644 default-configs/or32-softmmu.mak create mode 100644 hw/openrisc/Makefile.objs create mode 100644
hw/openrisc_cpudev.hcreate mode 100644hw/openrisc_pic.c
create mode 100644hw/openrisc_timer.ccreate mode 100644 target-openrisc/Makefile.objs create mode 100644target-openrisc/cpu.ccreate mode 100644target-openrisc/cpu.hcreate mode 100644target-openrisc/intrpt.ccreate mode 100644target-openrisc/machine.ccreate mode 100644target-openrisc/mmu.ccreate mode 100644target-openrisc/mmu_helper.ccreate mode 100644target-openrisc/translate.carch_init.c +2
-0@@ -71,6 +71,8 @@ int graphic_depth = 15; #define QEMU_ARCH QEMU_ARCH_MICROBLAZE #elif defined(TARGET_MIPS) #define QEMU_ARCH QEMU_ARCH_MIPS +#elif defined(TARGET_OPENRISC ) +#define QEMU_ARCH QEMU_ARCH_OPENRISC #elif defined(TARGET_PPC) #define QEMU_ARCH QEMU_ARCH_PPC #elif defined(TARGET_S390X)arch_init.h +1
-0@@ -16,6 +16,7 @@ enum { QEMU_ARCH_SH4 = 1024, QEMU_ARCH_SPARC = 2048, QEMU_ARCH_XTENSA = 4096, + QEMU_ARCH_OPENRISC = 8192, }; extern const uint32_t arch_type;configure +1
-0@@ -925,6 +925,7 @@ mips-softmmu \ mipsel-softmmu \ mips64-softmmu \ mips64el-softmmu \ +or32-softmmu \ ppc-softmmu \ ppcemb-softmmu \ ppc64-softmmu \@@ -3482,7 +3483,7 @@ target_arch2=`echo $target | cut -d '-' -f 1`target_bigendian="no"
case "$target_arch2" in
- armeb|lm32|m68k|microblaze|mips|mipsn32|mips64|ppc|ppcemb|ppc64|ppc64abi32|s390x|sh4eb|sparc|sparc64|sparc32plus|xtensaeb) + armeb|lm32|m68k|microblaze|mips|mipsn32|mips64|or32|ppc|ppcemb|ppc64|ppc64abi32|s390x|sh4eb|sparc|sparc64|sparc32plus|xtensaeb)target_bigendian=yes
;;
esacconfigure +0
-0@@ -3598,6 +3599,11 @@ case "$target_arch2" intarget_phys_bits=64
target_long_alignment=8
;;
+ or32)
+ TARGET_ARCH=openrisc
+ TARGET_BASE_ARCH=openrisc
+ target_phys_bits=32
+ ;;
ppc)
gdb_xml_files="power-core.xml power-fpu.xml power-altivec.xml power-spe.xml" target_phys_bits=64configure +0
-0@@ -3676,7 +3682,7 @@ symlink "$source_path/Makefile.target" "$target_dir/Makefile"case "$target_arch2" in
- alpha | sparc* | xtensa*)
+ alpha | or32 | sparc* | xtensa*)
echo "CONFIG_TCG_PASS_AREG0=y" >> $config_target_mak ;;
esacconfigure +0
-0@@ -3847,6 +3853,10 @@ for i in $ARCH $TARGET_BASE_ARCH ; doecho "
CONFIG_MIPS_DIS=y" >> $config_target_mak echo "CONFIG_MIPS_DIS=y" >> $libdis_config_mak ;;
+ or32)
+ echo "CONFIG_OPENRISC_DIS=y" >> $config_target_mak
+ echo "CONFIG_OPENRISC_DIS=y" >> $libdis_config_mak
+ ;;
ppc*)
echo "CONFIG_PPC_DIS=y" >> $config_target_mak echo "CONFIG_PPC_DIS=y" >> $libdis_config_makcpu-exec.c +2
-0@@ -225,6 +225,7 @@ int cpu_exec(CPUArchState *env) #elif defined(TARGET_LM32) #elif defined(TARGET_MICROBLAZE) #elif defined(TARGET_MIPS) +#elif defined(TARGET_OPENRISC ) #elif defined(TARGET_SH4) #elif defined(TARGET_CRIS) #elif defined(TARGET_S390X)@@ -630,6 +631,7 @@ int cpu_exec(CPUArchState *env) | env->cc_dest | (env->cc_x << 4); #elif defined(TARGET_MICROBLAZE) #elif defined(TARGET_MIPS) +#elif defined(TARGET_OPENRISC ) #elif defined(TARGET_SH4) #elif defined(TARGET_ALPHA) #elif defined(TARGET_CRIS)default-configs/or32-softmmu.mak new file +6
-0@@ -0,0 +1,6 @@ +# Default configuration for or32-softmmu + +include pci.mak +CONFIG_SERIAL=y +CONFIG_NE2000_ISA=y +CONFIG_I8259=yelf.h +2
-0@@ -106,6 +106,8 @@ typedef int64_t Elf64_Sxword; #define EM_H8S 48 /* Hitachi H8S */ #define EM_LATTICEMICO32 138 /* LatticeMico32 */ +#define EM_OPENRISC 92/* OpenCores OpenRISC */ + #define EM_UNICORE32 110 /* UniCore32 */ /*hw/openrisc/Makefile.objs new file +3
-0@@ -0,0 +1,3 @@ +obj-y = openrisc_pic.o openrisc_timer.o + +obj-y := $(addprefix ../,$(obj-y))hw/openrisc_cpudev.h new file +29
-0@@ -0,0 +1,29 @@ +/* +* QEMU OpenRISC CPU device support. +* +* Copyright (c) 2011-2012 Jia Liu <[email protected]> +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2 of the License, or (at your option) any later version. +* +* This library 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 +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef HW_OPENRISC_CPUDEV_H +#define HW_OPENRISC_CPUDEV_H + +/* openrisc_pic.c */ +void cpu_openrisc_pic_init (CPUOpenRISCState *env); + +/* openrisc_timer.c*/ +void cpu_openrisc_clock_init (CPUOpenRISCState *env); + +#endif hw/openrisc_pic.c new file +30
-0@@ -0,0 +1,30 @@ +/* +* OpenRISC Programmable Interrupt Controller support. +* +* Copyright (c) 2011-2012 Jia Liu <[email protected]> +* Feng Gao <[email protected]> +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2 of the License, or (at your option) any later version. +* +* This library 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 +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, see <http://www.gnu.org/licenses/>. +*/ + +#include "hw.h" +#include "openrisc_cpudev.h" +#include "cpu.h" + +/* Reset PIC */ +void cpu_openrisc_pic_reset (CPUOpenRISCState *env) +{ + env->picmr = 0x00000000; + env->picsr = 0x00000000; +}hw/openrisc_timer.c new file +30
-0@@ -0,0 +1,30 @@ +/* +* QEMU OpenRISC timer support +* +* Copyright (c) 2011-2012 Jia Liu <[email protected]> +* Zhizhou Zhang <[email protected]> +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2 of the License, or (at your option) any later version. +* +* This library 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 +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, see <http://www.gnu.org/licenses/>. +*/ + +#include "hw.h" +#include "openrisc_cpudev.h" +#include "qemu-timer.h" + +/* Reset Timer */ +void cpu_openrisc_timer_reset (CPUOpenRISCState *env) +{ + env->ttmr = 0x00000000; + env->ttcr = 0x00000000; +}poison.h +1
-0@@ -14,6 +14,7 @@ #pragma GCC poison TARGET_M68K #pragma GCC poison TARGET_MIPS #pragma GCC poison TARGET_MIPS64 +#pragma GCC poison TARGET_OPENRISC #pragma GCC poison TARGET_PPC #pragma GCC poison TARGET_PPCEMB #pragma GCC poison TARGET_PPC64target-openrisc/Makefile.objs new file +3
-0@@ -0,0 +1,3 @@ +obj-$(CONFIG_SOFTMMU) += machine.o +obj-y += cpu.o intrpt.o mmu.o translate.o +obj-y += mmu_helper.otarget-openrisc/cpu.c new file +240
-0@@ -0,0 +1,240 @@ +/* +* QEMU OpenRISC CPU +* +* Copyright (c) 2012 Jia Liu <[email protected]> +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2 of the License, or (at your option) any later version. +* +* This library 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 +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, see <http://www.gnu.org/licenses/>. +*/ + +#include "cpu.h" +#include "qemu-common.h" +#if !defined(CONFIG_USER_ONLY ) +#include "hw/loader.h" +#endif + +/* CPUClass::reset() */ +static void openrisc_cpu_reset (CPUState *s) +{ + OpenRISCCPU *cpu = OPENRISC_CPU(s); + OpenRISCCPUClass *occ = OPENRISC_CPU_GET_CLASS(cpu); + CPUOpenRISCState *env = &cpu->env; + + if (qemu_loglevel_mask(CPU_LOG_RESET)) { + qemu_log("CPU Reset (CPU %d)\n", env->cpu_index); + log_cpu_state(env, 0); + } + + occ->parent_reset(s); + + memset(env, 0, offsetof(CPUOpenRISCState, breakpoints)); + + tlb_flush(env, 1); + /*tb_flush(env); FIXME: Do we need it? */ + + env->pc = 0x100; + env->sr = SR_FO | SR_SM; + env->exception_index = -1; + + env->upr = UPR_UP | UPR_DMP | UPR_IMP | UPR_PICP | UPR_TTP; + env->cpucfgr = CPUCFGR_OB32S | CPUCFGR_OF32S; + env->dmmucfgr = (DMMUCFGR_NTW & (0 << 2)) | (DMMUCFGR_NTS & (6 << 2)); + env->immucfgr = (IMMUCFGR_NTW & (0 << 2)) | (IMMUCFGR_NTS & (6 << 2)); + +#if !defined(CONFIG_USER_ONLY ) + cpu_openrisc_timer_reset(env); + cpu_openrisc_pic_reset(env); +#endif +} + +static inline int openrisc_feature (CPUOpenRISCState *env,int feature) +{ + return (env->feature & (1u << feature)) != 0; +} + +static inline void set_feature (CPUOpenRISCState *env,int feature) +{ + env->feature |= 1u << feature; +} + +void openrisc_cpu_realize (Object *obj,Error **errp) +{ + OpenRISCCPU *cpu = OPENRISC_CPU(obj); + CPUOpenRISCState *env = &cpu->env; + if (openrisc_feature(env, OPENRISC_FEATURE_OR1200)) { + set_feature(env, OPENRISC_FEATURE_OB32S); + set_feature(env, OPENRISC_FEATURE_OF32S); + } + + qemu_init_vcpu(&cpu->env); +} + +static void openrisc_cpu_initfn (Object *obj) +{ + OpenRISCCPU *cpu = OPENRISC_CPU(obj); + cpu_exec_init(&cpu->env); +} + +/* CPU models */ +static void or1200_initfn (Object *obj) +{ + OpenRISCCPU *cpu = OPENRISC_CPU(obj); + CPUOpenRISCState *env = &cpu->env; + + set_feature(env, OPENRISC_FEATURE_OR1200); + + cpu_reset(CPU(cpu)); + +} + +static void openrisc_any_initfn (Object *obj) +{ + OpenRISCCPU *cpu = OPENRISC_CPU(obj); + CPUOpenRISCState *env = &cpu->env; + + set_feature(env, OPENRISC_FEATURE_OB32S); + set_feature(env, OPENRISC_FEATURE_OF32S); + + cpu_reset(CPU(cpu)); +} + +typedef struct OpenRISCCPUInfo { + const char *name; + void (*initfn)(Object *obj); +}OpenRISCCPUInfo ; + +static const OpenRISCCPUInfo openrisc_cpus[] = { + { .name = "or1200", .initfn = or1200_initfn }, + { .name = "any", .initfn = openrisc_any_initfn }, +}; + +static void openrisc_cpu_class_init (ObjectClass *oc,void *data) +{ + OpenRISCCPUClass *occ = OPENRISC_CPU_CLASS(oc); + CPUClass *cc = CPU_CLASS(occ); + + occ->parent_reset = cc->reset; + cc->reset = openrisc_cpu_reset; +} + +static void cpu_register (const OpenRISCCPUInfo *info) +{ + TypeInfo type_info = { + .name = info->name, + .parent = TYPE_OPENRISC_CPU, + .instance_size = sizeof(OpenRISCCPU), + .instance_init = info->initfn, + .class_size = sizeof(OpenRISCCPUClass), + }; + + type_register_static(&type_info); +} + +static const TypeInfo openrisc_cpu_type_info = { + .name = TYPE_OPENRISC_CPU, + .parent = TYPE_CPU, + .instance_size = sizeof(OpenRISCCPU), + .instance_init = openrisc_cpu_initfn, + .abstract = false, + .class_size = sizeof(OpenRISCCPUClass), + .class_init = openrisc_cpu_class_init, +}; + +static void openrisc_cpu_register_types (void ) +{ + int i; + + type_register_static(&openrisc_cpu_type_info); + for (i = 0; i < ARRAY_SIZE(openrisc_cpus); i++) { + cpu_register(&openrisc_cpus[i]); + } +} + +OpenRISCCPU *cpu_openrisc_init (const char *cpu_model) +{ + OpenRISCCPU *cpu; + CPUOpenRISCState *env; + static int inited; + inited = 0; + + if (!object_class_by_name(cpu_model)) { + return NULL; + } + cpu = OPENRISC_CPU(object_new(cpu_model)); + env = &cpu->env; + env->cpu_model_str = cpu_model; + + openrisc_cpu_realize(OBJECT(cpu), NULL); + +#if !defined(CONFIG_USER_ONLY ) + openrisc_mmu_init(env); +#endif + + if (tcg_enabled() && !inited) { + inited = 1; + openrisc_translate_init(); + } + + cpu_reset(CPU(cpu)); + + return cpu; +} + +typedef struct OpenRISCCPUListState { + fprintf_function cpu_fprintf; + FILE *file; +}OpenRISCCPUListState ; + +/* Sort alphabetically by type name, except for "any". */ +static gint openrisc_cpu_list_compare (gconstpointer a,gconstpointer b) +{ + ObjectClass *class_a = (ObjectClass *)a; + ObjectClass *class_b = (ObjectClass *)b; + const char *name_a, *name_b; + + name_a = object_class_get_name(class_a); + name_b = object_class_get_name(class_b); + if (strcmp(name_a, "any") == 0) { + return 1; + } else if (strcmp(name_b, "any") == 0) { + return -1; + } else { + return strcmp(name_a, name_b); + } +} + +static void openrisc_cpu_list_entry (gpointer data,gpointer user_data) +{ + ObjectClass *oc = data; + OpenRISCCPUListState *s = user_data; + + (*s->cpu_fprintf)(s->file, " %s\n", + object_class_get_name(oc)); +} + +void cpu_openrisc_list (FILE *f,fprintf_function cpu_fprintf) +{ + OpenRISCCPUListState s = { + .file = f, + .cpu_fprintf = cpu_fprintf, + }; + GSList *list; + + list = object_class_get_list(TYPE_OPENRISC_CPU, false); + list = g_slist_sort(list, openrisc_cpu_list_compare); + (*cpu_fprintf)(f, "Available CPUs:\n"); + g_slist_foreach(list, openrisc_cpu_list_entry, &s); + g_slist_free(list); +} + +type_init (openrisc_cpu_register_types)target-openrisc/cpu.h new file +288
-0@@ -0,0 +1,288 @@ +/* +* OpenRISC virtual CPU header. +* +* Copyright (c) 2011-2012 Jia Liu <[email protected]> +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2 of the License, or (at your option) any later version. +* +* This library 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 +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef CPU_OPENRISC_H +#define CPU_OPENRISC_H + +#define TARGET_HAS_ICE 1 + +#define ELF_MACHINE EM_OPENRISC + +#define CPUArchState struct CPUOpenRISCState + +#define TARGET_LONG_BITS 32 + +#include "config.h" +#include "qemu-common.h" +#include "cpu-defs.h" +#include "softfloat.h" +#include "qemu/cpu.h" +#include "error.h" + +struct CPUOpenRISCState ; + +#define NB_MMU_MODES 3 + +#define TARGET_PAGE_BITS 13 + +#define TARGET_PHYS_ADDR_SPACE_BITS 32 +#define TARGET_VIRT_ADDR_SPACE_BITS 32 + +/* Internel flags, delay slot flag */ +#define D_FLAG 1 + +/* Verison Register */ +#define SPR_VR 0xFFFF003F + +/* Registers */ +enum { + R0 = 0, R1, R2, R3, R4, R5, R6, R7, R8, R9, R10, + R11, R12, R13, R14, R15, R16, R17, R18, R19, R20, + R21, R22, R23, R24, R25, R26, R27, R28, R29, R30, + R31 +}; + +/* Register aliases */ +enum { + R_ZERO = R0, + R_SP = R1, + R_FP = R2, + R_LR = R9, + R_RV = R11, + R_RVH = R12 +}; + +/* Unit presece register */ +enum { + UPR_UP = (1 << 0), + UPR_DCP = (1 << 1), + UPR_ICP = (1 << 2), + UPR_DMP = (1 << 3), + UPR_IMP = (1 << 4), + UPR_MP = (1 << 5), + UPR_DUP = (1 << 6), + UPR_PCUR = (1 << 7), + UPR_PMP = (1 << 8), + UPR_PICP = (1 << 9), + UPR_TTP = (1 << 10), + UPR_CUP = (255 << 24), +}; + +/* CPU configure register */ +enum { + CPUCFGR_NSGF = (15 << 0), + CPUCFGR_CGF = (1 << 4), + CPUCFGR_OB32S = (1 << 5), + CPUCFGR_OB64S = (1 << 6), + CPUCFGR_OF32S = (1 << 7), + CPUCFGR_OF64S = (1 << 8), + CPUCFGR_OV64S = (1 << 9), +}; + +/* DMMU configure register */ +enum { + DMMUCFGR_NTW = (3 << 0), + DMMUCFGR_NTS = (7 << 2), + DMMUCFGR_NAE = (7 << 5), + DMMUCFGR_CRI = (1 << 8), + DMMUCFGR_PRI = (1 << 9), + DMMUCFGR_TEIRI = (1 << 10), + DMMUCFGR_HTR = (1 << 11), +}; + +/* IMMU configure register */ +enum { + IMMUCFGR_NTW = (3 << 0), + IMMUCFGR_NTS = (7 << 2), + IMMUCFGR_NAE = (7 << 5), + IMMUCFGR_CRI = (1 << 8), + IMMUCFGR_PRI = (1 << 9), + IMMUCFGR_TEIRI = (1 << 10), + IMMUCFGR_HTR = (1 << 11), +}; + +/* Supervisor register */ +enum { + SR_SM = 1, + SR_TEE = (1 << 1), + SR_IEE = (1 << 2), + SR_DCE = (1 << 3), + SR_ICE = (1 << 4), + SR_DME = (1 << 5), + SR_IME = (1 << 6), + SR_LEE = (1 << 7), + SR_CE = (1 << 8), + SR_F = (1 << 9), + SR_CY = (1 << 10), + SR_OV = (1 << 11), + SR_OVE = (1 << 12), + SR_DSX = (1 << 13), + SR_EPH = (1 << 14), + SR_FO = (1 << 15), + SR_SUMRA = (1 << 16), + SR_SCE = (1 << 17), +}; + +/* OpenRISC Hardware Capabilities */ +enum { + OPENRISC_FEATURE_NSGF, + OPENRISC_FEATURE_CGF, + OPENRISC_FEATURE_OB32S, + OPENRISC_FEATURE_OB64S, + OPENRISC_FEATURE_OF32S, + OPENRISC_FEATURE_OF64S, + OPENRISC_FEATURE_OV64S, + OPENRISC_FEATURE_OR1200, +}; + +typedef struct CPUOpenRISCState CPUOpenRISCState ; +struct CPUOpenRISCState { + target_ulong gpr[32]; /* General registers */ + target_ulong pc; /* Program counter */ + target_ulong npc; /* Next PC */ + target_ulong ppc; /* Prev PC */ + target_ulong jmp_pc; /* Jump PC */ + + uint32_t sr; /* Supervisor register */ + uint32_t vr; /* Version register */ + uint32_t upr; /* Unit presence register */ + uint32_t cpucfgr; /* CPU configure register */ + uint32_t dmmucfgr; /* DMMU configure register */ + uint32_t immucfgr; /* IMMU configure register */ + uint32_t flags; /* cpu_flags, we only use it for exception + in solt so far. */ + uint32_t btaken; /* the SR_F bit */ + + CPU_COMMON + +#if !defined(CONFIG_USER_ONLY ) + struct QEMUTimer *timer; + uint32_t ttmr; /* Timer tick mode register */ + uint32_t ttcr; /* Timer tick count register */ + + uint32_t picmr; /* Interrupt mask register */ + uint32_t picsr; /* Interrupt contrl register*/ +#endif + uint32_t feature; /* CPU Capabilities */ +}; + +#define TYPE_OPENRISC_CPU "or32-cpu" + +#define OPENRISC_CPU_CLASS (klass) \ + OBJECT_CLASS_CHECK(OpenRISCCPUClass, (klass), TYPE_OPENRISC_CPU) +#define OPENRISC_CPU (obj) \ + OBJECT_CHECK(OpenRISCCPU, (obj), TYPE_OPENRISC_CPU) +#define OPENRISC_CPU_GET_CLASS (obj) \ + OBJECT_GET_CLASS(OpenRISCCPUClass, (obj), TYPE_OPENRISC_CPU) + +/** +* OpenRISCCPUClass: +* @parent_reset: The parent class' reset handler. +* +* A OpenRISC CPU model. +*/ +typedef struct OpenRISCCPUClass { + /*< private >*/ + CPUClass parent_class; + /*< public >*/ + + void (*parent_reset)(CPUState *cpu); +}OpenRISCCPUClass ; + +/** +* OpenRISCCPU: +* @env: #CPUOpenRISCState +* +* A OpenRISC CPU. +*/ +typedef struct OpenRISCCPU { + /*< private >*/ + CPUState parent_obj; + /*< public >*/ + + CPUOpenRISCState env; +}OpenRISCCPU ; + +static inline OpenRISCCPU *openrisc_env_get_cpu (CPUOpenRISCState *env) +{ + return OPENRISC_CPU(container_of(env, OpenRISCCPU, env)); +} + +#define ENV_GET_CPU (e) CPU(openrisc_env_get_cpu(e)) + +void openrisc_cpu_realize (Object *obj,Error **errp); + +void cpu_openrisc_list (FILE *f,fprintf_function cpu_fprintf); +OpenRISCCPU *cpu_openrisc_init (const char *cpu_model); +int cpu_openrisc_exec (CPUOpenRISCState *s); +void do_interrupt (CPUOpenRISCState *env); +void openrisc_translate_init (void ); + +#define cpu_list cpu_openrisc_list +#define cpu_exec cpu_openrisc_exec +#define cpu_gen_code cpu_openrisc_gen_code + +#define CPU_SAVE_VERSION 1 + +#if !defined(CONFIG_USER_ONLY ) +void cpu_openrisc_pic_reset (CPUOpenRISCState *env); + +void cpu_openrisc_timer_reset (CPUOpenRISCState *env); + +void openrisc_mmu_init (CPUOpenRISCState *env); +#endif + +static inline CPUOpenRISCState *cpu_init (const char *cpu_model) +{ + OpenRISCCPU *cpu = cpu_openrisc_init(cpu_model); + if (cpu) { + return &cpu->env; + } + return NULL; +} + +#include "cpu-all.h" + +static inline void cpu_get_tb_cpu_state (CPUOpenRISCState *env, + target_ulong *pc, + target_ulong *cs_base, int *flags) +{ + *pc = env->pc; + *cs_base = 0; + *flags = 0; +} + +static inline int cpu_mmu_index (CPUOpenRISCState *env) +{ + return 0; +} + +static inline bool cpu_has_work (CPUOpenRISCState *env) +{ + return true; +} + +#include "exec-all.h" + +static inline void cpu_pc_from_tb (CPUOpenRISCState *env,TranslationBlock *tb) +{ + env->pc = tb->pc; +} + +#endif /* CPU_OPENRISC_H */ target-openrisc/intrpt.c new file +30
-0@@ -0,0 +1,30 @@ +/* +* OpenRISC interrupt. +* +* Copyright (c) 2011-2012 Jia Liu <[email protected]> +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2 of the License, or (at your option) any later version. +* +* This library 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 +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, see <http://www.gnu.org/licenses/>. +*/ + +#include "cpu.h" +#include "qemu-common.h" +#include "gdbstub.h" +#include "host-utils.h" +#if !defined(CONFIG_USER_ONLY ) +#include "hw/loader.h" +#endif + +void do_interrupt (CPUOpenRISCState *env) +{ +}target-openrisc/machine.c new file +30
-0@@ -0,0 +1,30 @@ +/* +* OpenRISC Machine +* +* Copyright (c) 2011-2012 Jia Liu <[email protected]> +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2 of the License, or (at your option) any later version. +* +* This library 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 +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, see <http://www.gnu.org/licenses/>. +*/ + +#include "hw/hw.h" +#include "hw/boards.h" + +void cpu_save (QEMUFile *f,void *opaque) +{ +} + +int cpu_load (QEMUFile *f,void *opaque,int version_id) +{ + return 0; +}target-openrisc/mmu.c new file +39
-0@@ -0,0 +1,39 @@ +/* +* OpenRISC MMU. +* +* Copyright (c) 2011-2012 Jia Liu <[email protected]> +* Zhizhou Zhang <[email protected]> +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2 of the License, or (at your option) any later version. +* +* This library 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 +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, see <http://www.gnu.org/licenses/>. +*/ + +#include "cpu.h" +#include "qemu-common.h" +#include "gdbstub.h" +#include "host-utils.h" +#if !defined(CONFIG_USER_ONLY ) +#include "hw/loader.h" +#endif + +#if !defined(CONFIG_USER_ONLY ) +target_phys_addr_t cpu_get_phys_page_debug (CPUOpenRISCState *env, + target_ulong addr) +{ + return addr; +} + +void openrisc_mmu_init (CPUOpenRISCState *env) +{ +} +#endif target-openrisc/mmu_helper.c new file +33
-0@@ -0,0 +1,43 @@ +/* +* OpenRISC MMU helper routines +* +* Copyright (c) 2011-2012 Jia Liu <[email protected]> +* Zhizhou Zhang <[email protected]> +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2 of the License, or (at your option) any later version. +* +* This library 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 +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, see <http://www.gnu.org/licenses/>. +*/ + +#include "cpu.h" + +#if !defined(CONFIG_USER_ONLY ) +#include "softmmu_exec.h" +#define MMUSUFFIX _mmu + +#define SHIFT 0 +#include "softmmu_template.h" + +#define SHIFT 1 +#include "softmmu_template.h" + +#define SHIFT 2
target-openrisc/mmu_helper.c line 43
Quoted 10 lines
target-openrisc/mmu_helper.c new file +10
-0+#include "softmmu_template.h" + +#define SHIFT 3 +#include "softmmu_template.h" + +void tlb_fill (CPUOpenRISCState *env,target_ulong addr,int is_write, + int mmu_idx, uintptr_t retaddr) +{ +} +#endif
Since there is no code for user emulator case, you could try to avoid compiling this file and also mmu.c if possible. This can be done later though.
Quoted 85 lines
target-openrisc/translate.c new file +75
-1@@ -0,0 +1,75 @@ +/* +* OpenRISC translation +* +* Copyright (c) 2011-2012 Jia Liu <[email protected]> +* Feng Gao <[email protected]> +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2 of the License, or (at your option) any later version. +* +* This library 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 +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, see <http://www.gnu.org/licenses/>. +*/ + +#include "cpu.h" +#include "exec-all.h" +#include "disas.h" +#include "tcg-op.h" +#include "qemu-common.h" +#include "qemu-log.h" +#include "config.h" + +#define OPENRISC_DISAS + +#ifdef OPENRISC_DISAS +# define LOG_DIS(...) qemu_log_mask(CPU_LOG_TB_IN_ASM, ## __VA_ARGS__) +#else +# define LOG_DIS(...) do { } while (0) +#endif + +void openrisc_translate_init (void ) +{ +} + +static inline void gen_intermediate_code_internal (CPUOpenRISCState *env, + TranslationBlock *tb, + int search_pc) +{ +} + +void gen_intermediate_code (CPUOpenRISCState *env,struct TranslationBlock *tb) +{ + gen_intermediate_code_internal(env, tb, 0); +} + +void gen_intermediate_code_pc (CPUOpenRISCState *env, + struct TranslationBlock *tb) +{ + gen_intermediate_code_internal(env, tb, 1); +} + +void cpu_dump_state (CPUOpenRISCState *env,FILE *f, + fprintf_function cpu_fprintf, + int flags) +{ + int i; + uint32_t *regs = env->gpr; + cpu_fprintf(f, "PC=%08x\n", env->pc); + for (i = 0; i < 32; ++i) { + cpu_fprintf(f, "R%02d=%08x%c", i, regs[i], + (i % 4) == 3 ? '\n' : ' '); + } +} + +void restore_state_to_opc (CPUOpenRISCState *env,TranslationBlock *tb, + int pc_pos) +{ + env->pc = gen_opc_pc[pc_pos]; +} --1.7.9.5
Re: [Qemu-devel] [PATCH v5 08/16] target-or32: Add translation routines
In reply to Jia LiuQuoted 338 lines · Jia Liu
Add OpenRISC translation routines.
Signed-off-by Jia Liu <[email protected]>---
target-openrisc/translate.c | 1941 +++++++++++++++++++++++++++++++++++++++++++1 file changed, 1941 insertions(+)target-openrisc/translate.c +314
-0@@ -26,6 +26,10 @@ #include "qemu-log.h" #include "config.h" +#include "helper.h" +#define GEN_HELPER 1 +#include "helper.h" + #define OPENRISC_DISAS #ifdef OPENRISC_DISAS@@ -34,14 +38,1951 @@ # define LOG_DIS(...) do { } while (0) #endif +typedef struct DisasContext { + CPUOpenRISCState *env; + TranslationBlock *tb; + target_ulong pc, ppc, npc; + uint32_t tb_flags, synced_flags, flags; + uint32_t is_jmp; + uint32_t mem_idx; + int singlestep_enabled; + uint32_t delayed_branch; +}DisasContext ; + +static TCGv_ptr cpu_env; +static TCGv cpu_sr; +static TCGv cpu_R[32 ]; +static TCGv cpu_pc; +static TCGv jmp_pc; /* l.jr/l.jalr temp pc */ +static TCGv cpu_npc; +static TCGv cpu_ppc; +static TCGv_i32 env_btaken; /* bf/bnf , F flag taken */ +static TCGv_i32 fpcsr; +static TCGv machi, maclo; +static TCGv fpmaddhi, fpmaddlo; +static TCGv_i32 env_flags; +#include "gen-icount.h" + void openrisc_translate_init(void) { + static const char * const regnames[] = { + "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", + "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", + "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23", + "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31", + }; + int i; + + cpu_env = tcg_global_reg_new_ptr(TCG_AREG0, "env"); + cpu_sr = tcg_global_mem_new(TCG_AREG0, + offsetof(CPUOpenRISCState, sr), "sr"); + env_flags = tcg_global_mem_new_i32(TCG_AREG0, + offsetof(CPUOpenRISCState, flags), + "flags"); + cpu_pc = tcg_global_mem_new(TCG_AREG0, + offsetof(CPUOpenRISCState, pc), "pc"); + cpu_npc = tcg_global_mem_new(TCG_AREG0, + offsetof(CPUOpenRISCState, npc), "npc"); + cpu_ppc = tcg_global_mem_new(TCG_AREG0, + offsetof(CPUOpenRISCState, ppc), "ppc"); + jmp_pc = tcg_global_mem_new(TCG_AREG0, + offsetof(CPUOpenRISCState, jmp_pc), "jmp_pc"); + env_btaken = tcg_global_mem_new_i32(TCG_AREG0, + offsetof(CPUOpenRISCState, btaken), + "btaken"); + fpcsr = tcg_global_mem_new_i32(TCG_AREG0, + offsetof(CPUOpenRISCState, fpcsr), + "fpcsr"); + machi = tcg_global_mem_new(TCG_AREG0, + offsetof(CPUOpenRISCState, machi), + "machi"); + maclo = tcg_global_mem_new(TCG_AREG0, + offsetof(CPUOpenRISCState, maclo), + "maclo"); + fpmaddhi = tcg_global_mem_new(TCG_AREG0, + offsetof(CPUOpenRISCState, fpmaddhi), + "fpmaddhi"); + fpmaddlo = tcg_global_mem_new(TCG_AREG0, + offsetof(CPUOpenRISCState, fpmaddlo), + "fpmaddlo"); + for (i = 0; i < 32; i++) { + cpu_R[i] = tcg_global_mem_new(TCG_AREG0, + offsetof(CPUOpenRISCState, gpr[i]), + regnames[i]); + } +#define GEN_HELPER 2 +#include "helper.h" +} + +/* Writeback SR_F transaltion-space to execution-space. */ +static inline void wb_SR_F (void ) +{ + int label; + + label = gen_new_label(); + tcg_gen_andi_tl(cpu_sr, cpu_sr, ~SR_F); + tcg_gen_brcondi_tl(TCG_COND_EQ, env_btaken, 0, label); + tcg_gen_ori_tl(cpu_sr, cpu_sr, SR_F); + gen_set_label(label); +} + +static inline int zero_extend (unsigned int val,int width) +{ + return val & ((1 << width) - 1); +} + +static inline int sign_extend (unsigned int val,int width) +{ + int sval; + + /* LSL */ + val <<= TARGET_LONG_BITS - width; + sval = val; + /* ASR. */ + sval >>= TARGET_LONG_BITS - width; + return sval; +} + +static inline void gen_sync_flags (DisasContext *dc) +{ + /* Sync the tb dependent flag between translate and runtime. */ + if (dc->tb_flags != dc->synced_flags) { + tcg_gen_movi_tl(env_flags, dc->tb_flags); + dc->synced_flags = dc->tb_flags; + } +} + +static void gen_exception (DisasContext *dc,unsigned int excp) +{ + TCGv_i32 tmp = tcg_const_i32(excp); + gen_helper_exception(cpu_env, tmp); + tcg_temp_free_i32(tmp); +} + +static void gen_illegal_exception (DisasContext *dc) +{ + tcg_gen_movi_tl(cpu_pc, dc->pc); + gen_exception(dc, EXCP_ILLEGAL); + dc->is_jmp = DISAS_UPDATE; +} + +#ifdef TARGET_OPENRISC64 +static void check_ob64s (DisasContext *dc) +{ + if (!(dc->flags & CPUCFGR_OB64S)) { + gen_illegal_exception(dc); + } +} + +static void check_of64s (DisasContext *dc) +{ + if (!(dc->flags & CPUCFGR_OF64S)) { + gen_illegal_exception(dc); + } +} + +/* not used yet, open it when we need or64. */ +/*static void check_ov64s(DisasContext *dc) +{ +if (!(dc->flags & CPUCFGR_OV64S)) { +gen_illegal_exception(dc); +} +}*/ +#endif + +static void gen_goto_tb (DisasContext *dc,int n,target_ulong dest) +{ + TranslationBlock *tb; + tb = dc->tb; + if ((tb->pc & TARGET_PAGE_MASK) == (dest & TARGET_PAGE_MASK) && + likely(!dc->singlestep_enabled)) { + tcg_gen_movi_tl(cpu_pc, dest); + tcg_gen_goto_tb(n); + tcg_gen_exit_tb((tcg_target_long)tb + n); + } else { + tcg_gen_movi_tl(cpu_pc, dest); + if (dc->singlestep_enabled) { + gen_exception(dc, EXCP_DEBUG); + } + tcg_gen_exit_tb(0); + } +} + +static void gen_jump (DisasContext *dc,uint32_t imm,uint32_t reg,uint32_t op0) +{ + target_ulong tmp_pc; + int lab = gen_new_label(); + TCGv sr_f = tcg_temp_new(); + /* N26, 26bits imm */ + tmp_pc = sign_extend((imm<<2), 26) + dc->pc; + tcg_gen_andi_tl(sr_f, cpu_sr, SR_F); + + if (op0 == 0x00) { /*l.j*/ + tcg_gen_movi_tl(jmp_pc, tmp_pc); + } else if (op0 == 0x01) { /*l.jal*/ + tcg_gen_movi_tl(cpu_R[9], (dc->pc + 8)); + tcg_gen_movi_tl(jmp_pc, tmp_pc); + } else if (op0 == 0x03) { /*l.bnf*/ + tcg_gen_movi_tl(jmp_pc, dc->pc+8); + tcg_gen_brcondi_i32(TCG_COND_EQ, sr_f, SR_F, lab); + tcg_gen_movi_tl(jmp_pc, tmp_pc); + gen_set_label(lab); + } else if (op0 == 0x04) { /*l.bf*/ + tcg_gen_movi_tl(jmp_pc, dc->pc+8); + tcg_gen_brcondi_i32(TCG_COND_NE, sr_f, SR_F, lab); + tcg_gen_movi_tl(jmp_pc, tmp_pc); + gen_set_label(lab); + } else if (op0 == 0x11) { /*l.jr*/ + tcg_gen_mov_tl(jmp_pc, cpu_R[reg]); + } else if (op0 == 0x12) { /*l.jalr*/ + tcg_gen_movi_tl(cpu_R[9], (dc->pc + 8)); + tcg_gen_mov_tl(jmp_pc, cpu_R[reg]); + } else { + gen_illegal_exception(dc); + } + + tcg_temp_free(sr_f); + dc->delayed_branch = 2; + dc->tb_flags |= D_FLAG; + gen_sync_flags(dc); +} + +static inline uint32_t field (uint32_t val,int start,int length) +{ + val >>= start; + val &= ~(~0 << length); + return val; +} + +static void dec_calc (DisasContext *dc,CPUOpenRISCState *env,uint32_t insn) +{ + uint32_t op0, op1, op2; + uint32_t ra, rb, rd; + op0 = field(insn, 0, 4); + op1 = field(insn, 8, 2); + op2 = field(insn, 6, 2); + ra = field(insn, 16, 5); + rb = field(insn, 11, 5); + rd = field(insn, 21, 5); + + switch (op0) { + case 0x0000: + switch (op1) { + case 0x00: /*l.add*/ + LOG_DIS("l.add r%d, r%d, r%d\n", rd, ra, rb); + { + int lab = gen_new_label(); + TCGv_i64 ta = tcg_temp_new_i64(); + TCGv_i64 tb = tcg_temp_new_i64(); + TCGv_i64 td = tcg_temp_local_new_i64(); + TCGv_i32 res = tcg_temp_local_new_i32(); + TCGv_i32 sr_ove = tcg_temp_local_new_i32(); + tcg_gen_extu_i32_i64(ta, cpu_R[ra]); + tcg_gen_extu_i32_i64(tb, cpu_R[rb]); + tcg_gen_add_i64(td, ta, tb); + tcg_gen_trunc_i64_i32(res, td); + tcg_gen_shri_i64(td, td, 31); + tcg_gen_andi_i64(td, td, 0x3); + /* Jump to lab when no overflow. */ + tcg_gen_brcondi_i64(TCG_COND_EQ, td, 0x0, lab); + tcg_gen_brcondi_i64(TCG_COND_EQ, td, 0x3, lab); + tcg_gen_ori_i32(cpu_sr, cpu_sr, (SR_OV | SR_CY)); + tcg_gen_andi_i32(sr_ove, cpu_sr, SR_OVE); + tcg_gen_brcondi_i32(TCG_COND_NE, sr_ove, SR_OVE, lab); + gen_exception(dc, EXCP_RANGE); + gen_set_label(lab); + tcg_gen_mov_i32(cpu_R[rd], res); + tcg_temp_free_i64(ta); + tcg_temp_free_i64(tb); + tcg_temp_free_i64(td); + tcg_temp_free_i32(res); + tcg_temp_free_i32(sr_ove); + } + break; + default: + gen_illegal_exception(dc); + break; + } + break; + + case 0x0001: /*l.addc*/ + switch (op1) { + case 0x00: + LOG_DIS("l.addc r%d, r%d, r%d\n", rd, ra, rb); + { + int lab = gen_new_label(); + TCGv_i64 ta = tcg_temp_new_i64(); + TCGv_i64 tb = tcg_temp_new_i64(); + TCGv_i64 tcy = tcg_temp_local_new_i64(); + TCGv_i64 td = tcg_temp_local_new_i64(); + TCGv_i32 res = tcg_temp_local_new_i32(); + TCGv_i32 sr_cy = tcg_temp_local_new_i32(); + TCGv_i32 sr_ove = tcg_temp_local_new_i32(); + tcg_gen_extu_i32_i64(ta, cpu_R[ra]); + tcg_gen_extu_i32_i64(tb, cpu_R[rb]); + tcg_gen_andi_i32(sr_cy, cpu_sr, SR_CY); + tcg_gen_extu_i32_i64(tcy, sr_cy); + tcg_gen_shri_i64(tcy, tcy, 10); + tcg_gen_add_i64(td, ta, tb); + tcg_gen_add_i64(td, td, tcy); + tcg_gen_trunc_i64_i32(res, td); + tcg_gen_shri_i64(td, td, 32); + tcg_gen_andi_i64(td, td, 0x3); + /* Jump to lab when no overflow. */ + tcg_gen_brcondi_i64(TCG_COND_EQ, td, 0x0, lab); + tcg_gen_brcondi_i64(TCG_COND_EQ, td, 0x3, lab); + tcg_gen_ori_i32(cpu_sr, cpu_sr, (SR_OV | SR_CY)); + tcg_gen_andi_i32(sr_ove, cpu_sr, SR_OVE); + tcg_gen_brcondi_i32(TCG_COND_NE, sr_ove, SR_OVE, lab); + gen_exception(dc, EXCP_RANGE); + gen_set_label(lab); + tcg_gen_mov_i32(cpu_R[rd], res); + tcg_temp_free_i64(ta); + tcg_temp_free_i64(tb); + tcg_temp_free_i64(tcy); + tcg_temp_free_i64(td); + tcg_temp_free_i32(res); + tcg_temp_free_i32(sr_cy); + tcg_temp_free_i32(sr_ove); + } + break; + default: + gen_illegal_exception(dc); + break; + }
target-openrisc/translate.c line 362
Quoted 10 lines
target-openrisc/translate.c +10
-0+ break; + + case 0x0002: /*l.sub*/ + switch (op1) { + case 0x00: + LOG_DIS("l.sub r%d, r%d, r%d\n", rd, ra, rb); + { + + +
Please trim the above lines.
target-openrisc/translate.c line 279
Quoted 6 lines
target-openrisc/translate.c +6
-0+ int lab = gen_new_label(); + TCGv_i64 ta = tcg_temp_new_i64(); + TCGv_i64 tb = tcg_temp_new_i64(); + TCGv_i64 td = tcg_temp_local_new_i64(); + TCGv_i32 res = tcg_temp_local_new_i32(); + TCGv_i32 sr_ove = tcg_temp_local_new_i32();
It's usual to put an empty line between variable declarations and code for clarity.
Quoted 106 lines
target-openrisc/translate.c +106
-0+ tcg_gen_extu_i32_i64(ta, cpu_R[ra]); + tcg_gen_extu_i32_i64(tb, cpu_R[rb]); + tcg_gen_sub_i64(td, ta, tb); + tcg_gen_trunc_i64_i32(res, td); + tcg_gen_shri_i64(td, td, 31); + tcg_gen_andi_i64(td, td, 0x3); + /* Jump to lab when no overflow. */ + tcg_gen_brcondi_i64(TCG_COND_EQ, td, 0x0, lab); + tcg_gen_brcondi_i64(TCG_COND_EQ, td, 0x3, lab); + tcg_gen_ori_i32(cpu_sr, cpu_sr, (SR_OV | SR_CY)); + tcg_gen_andi_i32(sr_ove, cpu_sr, SR_OVE); + tcg_gen_brcondi_i32(TCG_COND_NE, sr_ove, SR_OVE, lab); + gen_exception(dc, EXCP_RANGE); + gen_set_label(lab); + tcg_gen_mov_i32(cpu_R[rd], res); + tcg_temp_free_i64(ta); + tcg_temp_free_i64(tb); + tcg_temp_free_i64(td); + tcg_temp_free_i32(res); + tcg_temp_free_i32(sr_ove); + } + break; + default: + gen_illegal_exception(dc); + break; + } + break; + + case 0x0003: /*l.and*/ + switch (op1) { + case 0x00: + LOG_DIS("l.and r%d, r%d, r%d\n", rd, ra, rb); + tcg_gen_and_tl(cpu_R[rd], cpu_R[ra], cpu_R[rb]); + break; + default: + gen_illegal_exception(dc); + break; + } + break; + + case 0x0004: /*l.or*/ + switch (op1) { + case 0x00: + LOG_DIS("l.or r%d, r%d, r%d\n", rd, ra, rb); + tcg_gen_or_tl(cpu_R[rd], cpu_R[ra], cpu_R[rb]); + break; + default: + gen_illegal_exception(dc); + break; + } + break; + + case 0x0005: + switch (op1) { + case 0x00: /*l.xor*/ + LOG_DIS("l.xor r%d, r%d, r%d\n", rd, ra, rb); + tcg_gen_xor_tl(cpu_R[rd], cpu_R[ra], cpu_R[rb]); + break; + default: + gen_illegal_exception(dc); + break; + } + break; + + case 0x0006: + switch (op1) { + case 0x03: /*l.mul*/ + LOG_DIS("l.mul r%d, r%d, r%d\n", rd, ra, rb); + { + if (ra != 0 && rb != 0) { + int lab1 = gen_new_label(); + int lab2 = gen_new_label(); + int lab3 = gen_new_label(); + TCGv_i64 tmp0 = tcg_temp_local_new_i64(); + TCGv_i64 tmp1 = tcg_temp_local_new_i64(); + TCGv_i64 t0 = tcg_temp_local_new_i64(); + TCGv_i32 res = tcg_temp_local_new_i32(); + TCGv_i32 rs = tcg_temp_local_new_i32(); + TCGv_i32 rt = tcg_temp_local_new_i32(); + TCGv_i32 sr_ove = tcg_temp_local_new_i32(); + /* Calculate the result. */ + tcg_gen_extu_i32_i64(tmp0, cpu_R[ra]); + tcg_gen_extu_i32_i64(tmp1, cpu_R[rb]); + tcg_gen_mul_i64(t0, tmp0, tmp1); + tcg_gen_trunc_i64_i32(res, t0); + tcg_gen_shri_i32(rs, res, 31); + tcg_gen_andi_i32(rs, rs, 0x1); + tcg_gen_shri_i64(t0, t0, 32); + tcg_gen_trunc_i64_i32(rt, t0); + /* Overflow or not. */ + tcg_gen_brcondi_i32(TCG_COND_EQ, rs, 0x1, lab1); + tcg_gen_brcondi_i32(TCG_COND_EQ, rt, 0x0, lab2); + tcg_gen_brcondi_i32(TCG_COND_NE, rt, 0x0, lab3); + gen_set_label(lab1); + tcg_gen_brcondi_i32(TCG_COND_EQ, rt, 0xffffffff, lab2); + /* Handle overflow exception. */ + gen_set_label(lab3); + tcg_gen_ori_tl(cpu_sr, cpu_sr, SR_OV); + tcg_gen_ori_tl(cpu_sr, cpu_sr, SR_CY); + tcg_gen_andi_tl(sr_ove, cpu_sr, SR_OVE); + tcg_gen_brcondi_i32(TCG_COND_NE, sr_ove, SR_OVE, lab2); + gen_exception(dc, EXCP_RANGE); + /* Store result. */ + gen_set_label(lab2); + tcg_gen_mov_i32(cpu_R[rd], res); + tcg_temp_free_i32(res);
target-openrisc/translate.c line 484
Quoted 10 lines
target-openrisc/translate.c +10
-0+ tcg_temp_free_i64(t0); + tcg_temp_free_i32(rs); + tcg_temp_free_i32(rt); + tcg_temp_free_i64(tmp0); + tcg_temp_free_i64(tmp1); + tcg_temp_free_i32(sr_ove); +#ifdef TARGET_OPENRISC64 + int lab4 = gen_new_label(); + int lab5 = gen_new_label(); + int lab6 = gen_new_label();
But here you add variables after code which is not OK (C99 style). Please put them earlier.
Quoted 70 lines
target-openrisc/translate.c +70
-0+ TCGv_i64 t3 = tcg_temp_local_new_i64(); + TCGv_i64 t4 = tcg_temp_local_new_i64(); + TCGv_i64 t5 = tcg_temp_local_new_i64(); + TCGv_i64 t6 = tcg_temp_local_new_i64(); + TCGv_i64 r1 = tcg_temp_local_new_i64(); + TCGv_i64 r2 = tcg_temp_local_new_i64(); + TCGv_i64 r3 = tcg_temp_local_new_i64(); + TCGv_i64 r4 = tcg_temp_local_new_i64(); + TCGv_i32 tp0 = tcg_temp_local_new_i64(); + TCGv_i32 tp1 = tcg_temp_local_new_i64(); + TCGv_i64 t2h = tcg_temp_local_new_i64(); + TCGv_i64 t2l = tcg_temp_local_new_i64(); + TCGv_i64 t3h = tcg_temp_local_new_i64(); + TCGv_i64 t3l = tcg_temp_local_new_i64(); + TCGv_i64 res1 = tcg_temp_local_new_i64(); + TCGv_i64 res0 = tcg_temp_local_new_i64(); + TCGv_i32 sr_ove64 = tcg_temp_local_new_i32(); + /* Calculate the each result, and HIGH. */ + tcg_gen_trunc_i64_i32(tp0, cpu_R[ra]); + tcg_gen_trunc_i64_i32(tp1, cpu_R[rb]); + tcg_gen_shri_i64(t3, cpu_R[ra], 32); + tcg_gen_extu_i32_i64(t4, tp0); + tcg_gen_shri_i64(t5, cpu_R[rb], 32); + tcg_gen_extu_i32_i64(t6, tp1); + tcg_gen_mul_i64(r1, t3, t5); + tcg_gen_mul_i64(r2, t3, t6); + tcg_gen_mul_i64(r3, t5, t5); + tcg_gen_mul_i64(r4, t3, t4); + tcg_gen_shri_i64(t2h, r2, 32); + tcg_gen_shri_i64(t3h, r3, 32); + tcg_gen_trunc_i64_i32(tp0, r2); + tcg_gen_trunc_i64_i32(tp1, r3); + tcg_gen_extu_i32_i64(t2l, tp0); + tcg_gen_extu_i32_i64(t3l, tp1); + tcg_gen_shri_i64(res0, r4); + tcg_gen_add_i64(t2l, t2l, t3l); + tcg_gen_add_i64(res1, t2l, res1); + /* Overflow or not, by t2l CY. */ + tcg_gen_shri_i64(t2l, res1, 32); + tcg_gen_add_i64(r1, t2h, r1); + tcg_gen_add_i64(r1, r1, t3h); + tcg_gen_add_i64(r1, r1, t2l); + tcg_gen_shri_i64(res0, res1, 31); + tcg_gen_andi_i64(res0, res0, 0x1); + tcg_gen_brcondi_i64(TCG_COND_EQ, res0, 0x1, lab4); + tcg_gen_brcondi_i64(TCG_COND_EQ, r1, 0x0, lab5); + tcg_gen_brcondi_i64(TCG_COND_NE, r1, 0x0, lab6); + gen_set_label(lab4); + tcg_gen_brcondi_i64(TCG_COND_EQ, r1, + 0xffffffffffffffff, lab5); + /* Handle overflow exception. */ + gen_set_label(lab6); + tcg_gen_andi_tl(cpu_sr, cpu_sr, SR_OV); + tcg_gen_andi_tl(cpu_sr, cpu_sr, SR_CY); + tcg_gen_addi_i32(sr_ove64, cpu_SR, SR_OVE); + tcg_gen_brcondi_i32(TCG_COND_NE, sr_ove64, 0x1, lab5); + gen_exeception(dc, EXCP_RANGE); + /* Store result. */ + gen_set_label(lab5); + tcg_gen_shli_i64(res1, res1, 32); + tcg_gen_addi_i64(r4, r4, 0xffffffff); + tcg_gen_add_i64(res1, r4, res1); + tcg_gen_mov_i64(cpu_R[rd], res1); + tcg_temp_free_i64(t3); + tcg_temp_free_i64(t4); + tcg_temp_free_i64(t5); + tcg_temp_free_i64(t6); + tcg_temp_free_i64(r1); + tcg_temp_free_i64(r2); + tcg_temp_free_i64(r3);
target-openrisc/translate.c line 564
Quoted 10 lines
target-openrisc/translate.c +10
-0+ tcg_temp_free_i64(r4); + tcg_temp_free_i32(tp0); + tcg_temp_free_i32(tp1); + tcg_temp_free_i64(t2h); + tcg_temp_free_i64(t2l); + tcg_temp_free_i64(t3h); + tcg_temp_free_i64(t3l); + tcg_temp_free_i64(res1); + tcg_temp_free_i64(res0); + tcg_temp_free_i32(sr_ove64);
Overall the instruction is pretty long, maybe a helper would be in order. There are limits on how long the TCG sequences can become (see tcg/README).
Quoted 1,428 lines
target-openrisc/translate.c +1415
-1+#endif + } else { + tcg_gen_movi_tl(cpu_R[rd], 0x0); + } + } + break; + default: + gen_illegal_exception(dc); + break; + } + break; + + case 0x0009: + switch (op1) { + case 0x03: /*l.div*/ + LOG_DIS("l.div r%d, r%d, r%d\n", rd, ra, rb); + { + int lab0 = gen_new_label(); + int lab1 = gen_new_label(); + int lab2 = gen_new_label(); + TCGv_i32 sr_ove = tcg_temp_local_new_i32(); + if (rb == 0) { + tcg_gen_ori_tl(cpu_sr, cpu_sr, SR_OV | SR_CY); + tcg_gen_brcondi_tl(TCG_COND_NE, sr_ove, SR_OVE, lab0); + tcg_gen_andi_tl(sr_ove, cpu_sr, SR_OVE); + gen_exception(dc, EXCP_RANGE); + gen_set_label(lab0); + } else { + tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_R[rb], + 0x00000000, lab1); + tcg_gen_brcondi_tl(TCG_COND_NE, cpu_R[ra], + 0xffffffff, lab2); + tcg_gen_brcondi_tl(TCG_COND_NE, cpu_R[rb], + 0x80000000, lab2); + gen_set_label(lab1); + tcg_gen_ori_tl(cpu_sr, cpu_sr, SR_OV | SR_CY); + tcg_gen_andi_tl(sr_ove, cpu_sr, SR_OVE); + tcg_gen_brcondi_tl(TCG_COND_NE, sr_ove, SR_OVE, lab2); + gen_exception(dc, EXCP_RANGE); + gen_set_label(lab2); + tcg_gen_div_tl(cpu_R[rd], cpu_R[ra], cpu_R[rb]); + } + tcg_temp_free_i32(sr_ove); + } + break; + + default: + gen_illegal_exception(dc); + break; + } + break; + + case 0x000a: + switch (op1) { + case 0x03: /*l.divu*/ + LOG_DIS("l.divu r%d, r%d, r%d\n", rd, ra, rb); + { + int lab0 = gen_new_label(); + int lab1 = gen_new_label(); + TCGv_i32 sr_ove = tcg_temp_local_new_i32(); + if (rb == 0) { + tcg_gen_ori_tl(cpu_sr, cpu_sr, SR_OV | SR_CY); + tcg_gen_andi_tl(sr_ove, cpu_sr, SR_OVE); + tcg_gen_brcondi_tl(TCG_COND_NE, sr_ove, SR_OVE, lab0); + gen_exception(dc, EXCP_RANGE); + gen_set_label(lab0); + } else { + tcg_gen_brcondi_tl(TCG_COND_NE, cpu_R[rb], + 0x00000000, lab1); + tcg_gen_ori_tl(cpu_sr, cpu_sr, SR_OV | SR_CY); + tcg_gen_andi_tl(sr_ove, cpu_sr, SR_OVE); + tcg_gen_brcondi_tl(TCG_COND_NE, sr_ove, SR_OVE, lab1); + gen_exception(dc, EXCP_RANGE); + gen_set_label(lab1); + tcg_gen_divu_tl(cpu_R[rd], cpu_R[ra], cpu_R[rb]); + } + tcg_temp_free_i32(sr_ove); + } + break; + + default: + gen_illegal_exception(dc); + break; + } + break; + + case 0x000b: + switch (op1) { + case 0x03: /*l.mulu*/ + LOG_DIS("l.mulu r%d, r%d, r%d\n", rd, ra, rb); + if (rb != 0 && ra != 0) { + TCGv_i64 result = tcg_temp_local_new_i64(); + TCGv_i64 tra = tcg_temp_local_new_i64(); + TCGv_i64 trb = tcg_temp_local_new_i64(); + TCGv_i64 high = tcg_temp_new_i64(); + TCGv_i32 sr_ove = tcg_temp_local_new_i32(); + int lab = gen_new_label(); + /* Calculate the each result. */ + tcg_gen_extu_i32_i64(tra, cpu_R[ra]); + tcg_gen_extu_i32_i64(trb, cpu_R[rb]); + tcg_gen_mul_i64(result, tra, trb); + tcg_temp_free_i64(tra); + tcg_temp_free_i64(trb); + tcg_gen_shri_i64(high, result, TARGET_LONG_BITS); + /* Overflow or not. */ + tcg_gen_brcondi_i64(TCG_COND_EQ, high, 0x00000000, lab); + tcg_gen_ori_tl(cpu_sr, cpu_sr, SR_OV | SR_CY); + tcg_gen_andi_tl(sr_ove, cpu_sr, SR_OVE); + tcg_gen_brcondi_tl(TCG_COND_NE, sr_ove, SR_OVE, lab); + gen_exception(dc, EXCP_RANGE); + gen_set_label(lab); + tcg_temp_free_i64(high); + tcg_gen_trunc_i64_tl(cpu_R[rd], result); + tcg_temp_free_i64(result); + tcg_temp_free_i32(sr_ove); +#ifdef TARGET_OPENRISC64 + int lab1 = gen_new_label(); + TCGv_i32 r1 = tcg_temp_loacl_new_i64(); + TCGv_i32 r2 = tcg_temp_loacl_new_i64(); + TCGv_i64 r3 = tcg_temp_loacl_new_i64(); + TCGv_i64 r4 = tcg_temp_loacl_new_i64(); + TCGv_i64 r5 = tcg_temp_loacl_new_i64(); + TCGv_i64 r6 = tcg_temp_loacl_new_i64(); + TCGv_i64 tr1 = tcg_temp_loacl_new_i64(); + TCGv_i64 tr2 = tcg_temp_loacl_new_i64(); + TCGv_i64 tr3 = tcg_temp_loacl_new_i64(); + TCGv_i64 tr4 = tcg_temp_loacl_new_i64(); + TCGv_i64 rs1 = tcg_temp_loacl_new_i64(); + TCGv_i64 rs2 = tcg_temp_loacl_new_i64(); + TCGV_i32 sr_ove64 = tcg_temp_local_new_i32(); + /* Calculate the each result. */ + tcg_gen_trunc_i64_i32(r1, cpu_R[ra]); + tcg_gen_trunc_i64_i32(r2, cpu_R[rb]); + tcg_gen_extu_i32_i64(r3, r1); + tcg_gen_extu_i32_i64(r4, r2); + tcg_gen_shri_i64(r5, cpu_R[ra], 32); + tcg_gen_shri_i64(r6, cpu_R[rb], 32); + tcg_gen_mul_i64(tr1, r5, r6); + tcg_gen_mul_i64(tr2, r5, r4); + tcg_gen_mul_i64(tr3, r3, r6); + tcg_gen_mul_i64(tr4, r3, r4); + tcg_gen_trunc_i64_i32(r1, tr2); + tcg_gen_trunc_i64_i32(r2, tr3); + tcg_gen_extu_i32_i64(r3, r1); + tcg_gen_extu_i32_i64(r4, r2); + tcg_gen_shri_i64(rs1, tr4, 32); + tcg_gen_add_i64(r3, r3, r4); + tcg_gen_add_i64(rs2, rs1, r3); + /* Overflow or not, by r3 CY. */ + tcg_gen_shri_i64(r3, rs2, 32); + tcg_gen_shri_i64(tr3, tr3, 32); + tcg_gen_shri_i64(tr2, tr2, 32); + tcg_gen_add_i64(tr1, tr1, tr2); + tcg_gen_add_i64(tr1, tr1, tr3); + tcg_gen_add_i64(tr1, tr1, r3); + tcg_gen_brcondi_i64(TCGV_COND_EQ, tr1, 0x0, lab1); + tcg_gen_andi_tl(cpu_sr, cpu_sr, SR_OV); + tcg_gen_andi_tl(cpu_sr, cpu_sr, SR_CY); + tcg_gen_addi_i32(sr_ove64, cpu_SR, SR_OVE); + tcg_gen_brcondi_i32(TCG_COND_NE, sr_ove64, 0x1, lab1); + gen_exeception(dc, EXCP_RANGE); + /* Store result. */ + gen_set_label(lab1); + tcg_gen_andi_i64(tr4, tr4, 0xffffffff); + tcg_gen_shli_i64(rs2, rs2, 32); + tcg_gen_add_i64(rs2, rs2, tr4); + tcg_gen_mov_i64(cpu_R[rd], rs2); + tcg_temp_free_i32(r1); + tcg_temp_free_i32(r2); + tcg_temp_free_i64(r3); + tcg_temp_free_i64(r4); + tcg_temp_free_i64(r5); + tcg_temp_free_i64(r6); + tcg_temp_free_i64(tr1); + tcg_temp_free_i64(tr2); + tcg_temp_free_i64(tr3); + tcg_temp_free_i64(tr4); + tcg_temp_free_i64(rs1); + tcg_temp_free_i64(rs2); + tcg_temp_free_i64(sr_ove); +#endif + } else { + tcg_gen_movi_tl(cpu_R[rd], 0); + } + break; + + default: + gen_illegal_exception(dc); + break; + } + break; + + case 0x000e: + switch (op1) { + case 0x00: /*l.cmov*/ + LOG_DIS("l.cmov r%d, r%d, r%d\n", rd, ra, rb); + { + int lab = gen_new_label(); + TCGv res = tcg_temp_new(); + TCGv sr_f = tcg_temp_new(); + tcg_gen_andi_tl(sr_f, cpu_sr, SR_F); + tcg_gen_mov_tl(res, cpu_R[rb]); + tcg_gen_brcondi_tl(TCG_COND_NE, sr_f, SR_F, lab); + tcg_gen_mov_tl(res, cpu_R[ra]); + gen_set_label(lab); + tcg_gen_mov_tl(cpu_R[rd], res); + tcg_temp_free(sr_f); + tcg_temp_free(res); + } + break; + + default: + gen_illegal_exception(dc); + break; + } + break; + + case 0x000f: + switch (op1) { + case 0x00: /*l.ff1*/ + LOG_DIS("l.ff1 r%d, r%d, r%d\n", rd, ra, rb); + gen_helper_ff1(cpu_R[rd], cpu_R[ra]); + break; + case 0x01: /*l.fl1*/ + LOG_DIS("l.fl1 r%d, r%d, r%d\n", rd, ra, rb); + gen_helper_fl1(cpu_R[rd], cpu_R[ra]); + break; + + default: + gen_illegal_exception(dc); + break; + } + break; + + case 0x0008: + switch (op1) { + case 0x00: + switch (op2) { + case 0x00: /*l.sll*/ + LOG_DIS("l.sll r%d, r%d, r%d\n", rd, ra, rb); + tcg_gen_shl_tl(cpu_R[rd], cpu_R[ra], cpu_R[rb]); + break; + case 0x01: /*l.srl*/ + LOG_DIS("l.srl r%d, r%d, r%d\n", rd, ra, rb); + tcg_gen_shr_tl(cpu_R[rd], cpu_R[ra], cpu_R[rb]); + break; + case 0x02: /*l.sra*/ + LOG_DIS("l.sra r%d, r%d, r%d\n", rd, ra, rb); + tcg_gen_sar_tl(cpu_R[rd], cpu_R[ra], cpu_R[rb]); + break; + case 0x03: /*l.ror*/ + LOG_DIS("l.ror r%d, r%d, r%d\n", rd, ra, rb); + tcg_gen_rotr_tl(cpu_R[rd], cpu_R[ra], cpu_R[rb]); + break; + + default: + gen_illegal_exception(dc); + break; + } + break; + + default: + gen_illegal_exception(dc); + break; + } + break; + + case 0x000c: + switch (op1) { + case 0x00: + switch (op2) { + case 0x00: /*l.exths*/ + LOG_DIS("l.exths r%d, r%d\n", rd, ra); + tcg_gen_ext16s_tl(cpu_R[rd], cpu_R[ra]); + break; + case 0x01: /*l.extbs*/ + LOG_DIS("l.extbs r%d, r%d\n", rd, ra); + tcg_gen_ext8s_tl(cpu_R[rd], cpu_R[ra]); + break; + case 0x02: /*l.exthz*/ + LOG_DIS("l.exthz r%d, r%d\n", rd, ra); + tcg_gen_ext16u_tl(cpu_R[rd], cpu_R[ra]); + break; + case 0x03: /*l.extbz*/ + LOG_DIS("l.extbz r%d, r%d\n", rd, ra); + tcg_gen_ext8u_tl(cpu_R[rd], cpu_R[ra]); + break; + + default: + gen_illegal_exception(dc); + break; + } + break; + + default: + gen_illegal_exception(dc); + break; + } + break; + + case 0x000d: + switch (op1) { + case 0x00: + switch (op2) { + case 0x00: /*l.extws*/ + LOG_DIS("l.extws r%d, r%d\n", rd, ra); + tcg_gen_ext32s_tl(cpu_R[rd], cpu_R[ra]); + break; + case 0x01: /*l.extwz*/ + LOG_DIS("l.extwz r%d, r%d\n", rd, ra); + tcg_gen_ext32u_tl(cpu_R[rd], cpu_R[ra]); + break; + + default: + gen_illegal_exception(dc); + break; + } + break; + + default: + gen_illegal_exception(dc); + break; + } + break; + + default: + gen_illegal_exception(dc); + break; + } +} + +static void dec_misc(DisasContext *dc, CPUOpenRISCState *env, uint32_t insn) +{ + uint32_t op0, op1; + uint32_t ra, rb, rd; + uint32_t /*L6, K5, */I16, I5, I11, N26, tmp; + op0 = field(insn, 26, 6); + op1 = field(insn, 24, 2); + ra = field(insn, 16, 5); + rb = field(insn, 11, 5); + rd = field(insn, 21, 5); + /*L6 = field(insn, 5, 6); + K5 = field(insn, 0, 5);*/ + I16 = field(insn, 0, 16); + I5 = field(insn, 21, 5); + I11 = field(insn, 0, 11); + N26 = field(insn, 0, 26); + tmp = (I5<<11) + I11; + + switch (op0) { + case 0x00: /*l.j*/ + LOG_DIS("l.j %d\n", N26); + case 0x01: /*l.jal*/ + LOG_DIS("l.jal %d\n", N26); + case 0x03: /*l.bnf*/ + LOG_DIS("l.bnf %d\n", N26); + case 0x04: /*l.bf*/ + LOG_DIS("l.bf %d\n", N26); + + gen_jump(dc, N26, 0, op0); + break; + + case 0x05: + switch (op1) { + case 0x01: /*l.nop*/ + LOG_DIS("l.nop %d\n", I16); + break; + + default: + gen_illegal_exception(dc); + break; + } + break; + + case 0x11: /*l.jr*/ + LOG_DIS("l.jr r%d\n", rb); + case 0x12: /*l.jalr*/ + LOG_DIS("l.jalr r%d\n", rb); + + gen_jump(dc, 0, rb, op0); + break; + + case 0x13: /*l.maci*/ + LOG_DIS("l.maci %d, r%d, %d\n", I5, ra, I11); + { + TCGv_i64 t1 = tcg_temp_new_i64(); + TCGv_i64 t2 = tcg_temp_new_i64(); + TCGv_i32 dst = tcg_temp_new_i32(); + TCGv ttmp = tcg_const_tl(tmp); + tcg_gen_mul_tl(dst, cpu_R[ra], ttmp); + tcg_gen_ext_i32_i64(t1, dst); + tcg_gen_concat_i32_i64(t2, maclo, machi); + tcg_gen_add_i64(t2, t2, t1); + tcg_gen_trunc_i64_i32(maclo, t2); + tcg_gen_shri_i64(t2, t2, 32); + tcg_gen_trunc_i64_i32(machi, t2); + tcg_temp_free_i32(dst); + tcg_temp_free(ttmp); + tcg_temp_free_i64(t1); + tcg_temp_free_i64(t2); + } + break; + + case 0x09: /*l.rfe*/ + LOG_DIS("l.rfe\n"); + { + gen_helper_rfe(cpu_env); + dc->is_jmp = DISAS_UPDATE; + } + break; + + case 0x1c: /*l.cust1*/ + LOG_DIS("l.cust1\n"); + break; + + case 0x1d: /*l.cust2*/ + LOG_DIS("l.cust2\n"); + break; + + case 0x1e: /*l.cust3*/ + LOG_DIS("l.cust3\n"); + break; + + case 0x1f: /*l.cust4*/ + LOG_DIS("l.cust4\n"); + break; + + case 0x3c: /*l.cust5*/ + /*LOG_DIS("l.cust5 r%d, r%d, r%d, %d, %d\n", rd, ra, rb, L6, K5);*/ + break; + + case 0x3d: /*l.cust6*/ + LOG_DIS("l.cust6\n"); + break; + + case 0x3e: /*l.cust7*/ + LOG_DIS("l.cust7\n"); + break; + + case 0x3f: /*l.cust8*/ + LOG_DIS("l.cust8\n"); + break; + + case 0x20: /*l.ld*/ + LOG_DIS("l.ld r%d, r%d, %d\n", rd, ra, I16); + { +#ifdef TARGET_OPENRISC64 + check_ob64s(dc); + TCGv_i64 t0 = tcg_temp_new_i64(); + tcg_gen_addi_i64(t0, cpu_R[ra], sign_extend(I16, 16)); + tcg_gen_qemu_ld64(cpu_R[rd], t0, dc->mem_idx); + tcg_temp_free_i64(t0); +#endif + } + break; + + case 0x21: /*l.lwz*/ + LOG_DIS("l.lwz r%d, r%d, %d\n", rd, ra, I16); + { + TCGv t0 = tcg_temp_new(); + tcg_gen_addi_tl(t0, cpu_R[ra], sign_extend(I16, 16)); + tcg_gen_qemu_ld32u(cpu_R[rd], t0, dc->mem_idx); + tcg_temp_free(t0); + } + break; + + case 0x22: /*l.lws*/ + LOG_DIS("l.lws r%d, r%d, %d\n", rd, ra, I16); + { + TCGv t0 = tcg_temp_new(); + tcg_gen_addi_tl(t0, cpu_R[ra], sign_extend(I16, 16)); + tcg_gen_qemu_ld32s(cpu_R[rd], t0, dc->mem_idx); + tcg_temp_free(t0); + } + break; + + case 0x23: /*l.lbz*/ + LOG_DIS("l.lbz r%d, r%d, %d\n", rd, ra, I16); + { + TCGv t0 = tcg_temp_new(); + tcg_gen_addi_tl(t0, cpu_R[ra], sign_extend(I16, 16)); + tcg_gen_qemu_ld8u(cpu_R[rd], t0, dc->mem_idx); + tcg_temp_free(t0); + } + break; + + case 0x24: /*l.lbs*/ + LOG_DIS("l.lbs r%d, r%d, %d\n", rd, ra, I16); + { + TCGv t0 = tcg_temp_new(); + tcg_gen_addi_tl(t0, cpu_R[ra], sign_extend(I16, 16)); + tcg_gen_qemu_ld8s(cpu_R[rd], t0, dc->mem_idx); + tcg_temp_free(t0); + } + break; + + case 0x25: /*l.lhz*/ + LOG_DIS("l.lhz r%d, r%d, %d\n", rd, ra, I16); + { + TCGv t0 = tcg_temp_new(); + tcg_gen_addi_tl(t0, cpu_R[ra], sign_extend(I16, 16)); + tcg_gen_qemu_ld16u(cpu_R[rd], t0, dc->mem_idx); + tcg_temp_free(t0); + } + break; + + case 0x26: /*l.lhs*/ + LOG_DIS("l.lhs r%d, r%d, %d\n", rd, ra, I16); + { + TCGv t0 = tcg_temp_new(); + tcg_gen_addi_tl(t0, cpu_R[ra], sign_extend(I16, 16)); + tcg_gen_qemu_ld16s(cpu_R[rd], t0, dc->mem_idx); + tcg_temp_free(t0); + } + break; + + case 0x27: /*l.addi*/ + LOG_DIS("l.addi r%d, r%d, %d\n", rd, ra, I16); + { + int lab = gen_new_label(); + TCGv_i64 ta = tcg_temp_new_i64(); + TCGv_i64 td = tcg_temp_local_new_i64(); + TCGv_i32 res = tcg_temp_local_new_i32(); + TCGv_i32 sr_ove = tcg_temp_local_new_i32(); + tcg_gen_extu_i32_i64(ta, cpu_R[ra]); + tcg_gen_addi_i64(td, ta, sign_extend(I16, 16)); + tcg_gen_trunc_i64_i32(res, td); + tcg_gen_shri_i64(td, td, 32); + tcg_gen_andi_i64(td, td, 0x3); + /* Jump to lab when no overflow. */ + tcg_gen_brcondi_i64(TCG_COND_EQ, td, 0x0, lab); + tcg_gen_brcondi_i64(TCG_COND_EQ, td, 0x3, lab); + tcg_gen_ori_i32(cpu_sr, cpu_sr, (SR_OV | SR_CY)); + tcg_gen_andi_i32(sr_ove, cpu_sr, SR_OVE); + tcg_gen_brcondi_i32(TCG_COND_NE, sr_ove, SR_OVE, lab); + gen_exception(dc, EXCP_RANGE); + gen_set_label(lab); + tcg_gen_mov_i32(cpu_R[rd], res); + tcg_temp_free_i64(ta); + tcg_temp_free_i64(td); + tcg_temp_free_i32(res); + tcg_temp_free_i32(sr_ove); + } + break; + + case 0x28: /*l.addic*/ + LOG_DIS("l.addic r%d, r%d, %d\n", rd, ra, I16); + { + int lab = gen_new_label(); + TCGv_i64 ta = tcg_temp_new_i64(); + TCGv_i64 td = tcg_temp_local_new_i64(); + TCGv_i64 tcy = tcg_temp_local_new_i64(); + TCGv_i32 res = tcg_temp_local_new_i32(); + TCGv_i32 sr_cy = tcg_temp_local_new_i32(); + TCGv_i32 sr_ove = tcg_temp_local_new_i32(); + tcg_gen_extu_i32_i64(ta, cpu_R[ra]); + tcg_gen_andi_i32(sr_cy, cpu_sr, SR_CY); + tcg_gen_shri_i32(sr_cy, sr_cy, 10); + tcg_gen_extu_i32_i64(tcy, sr_cy); + tcg_gen_addi_i64(td, ta, sign_extend(I16, 16)); + tcg_gen_add_i64(td, td, tcy); + tcg_gen_trunc_i64_i32(res, td); + tcg_gen_shri_i64(td, td, 32); + tcg_gen_andi_i64(td, td, 0x3); + /* Jump to lab when no overflow. */ + tcg_gen_brcondi_i64(TCG_COND_EQ, td, 0x0, lab); + tcg_gen_brcondi_i64(TCG_COND_EQ, td, 0x3, lab); + tcg_gen_ori_i32(cpu_sr, cpu_sr, (SR_OV | SR_CY)); + tcg_gen_andi_i32(sr_ove, cpu_sr, SR_OVE); + tcg_gen_brcondi_i32(TCG_COND_NE, sr_ove, SR_OVE, lab); + gen_exception(dc, EXCP_RANGE); + gen_set_label(lab); + tcg_gen_mov_i32(cpu_R[rd], res); + tcg_temp_free_i64(ta); + tcg_temp_free_i64(td); + tcg_temp_free_i64(tcy); + tcg_temp_free_i32(res); + tcg_temp_free_i32(sr_cy); + tcg_temp_free_i32(sr_ove); + } + break; + + case 0x29: /*l.andi*/ + LOG_DIS("l.andi r%d, r%d, %d\n", rd, ra, I16); + tcg_gen_andi_tl(cpu_R[rd], cpu_R[ra], zero_extend(I16, 16)); + break; + + case 0x2a: /*l.ori*/ + LOG_DIS("l.ori r%d, r%d, %d\n", rd, ra, I16); + tcg_gen_ori_tl(cpu_R[rd], cpu_R[ra], zero_extend(I16, 16)); + break; + + case 0x2b: /*l.xori*/ + LOG_DIS("l.xori r%d, r%d, %d\n", rd, ra, I16); + tcg_gen_xori_tl(cpu_R[rd], cpu_R[ra], sign_extend(I16, 16)); + break; + + case 0x2c: /*l.muli*/ + LOG_DIS("l.muli r%d, r%d, %d\n", rd, ra, I16); + if (ra != 0 && I16 != 0) { + int lab1 = gen_new_label(); + TCGv_i64 t0 = tcg_temp_local_new_i64(); + TCGv_i32 t1 = tcg_temp_local_new_i32(); + TCGv_i32 t2 = tcg_temp_local_new_i32(); + TCGv_i64 tmp0 = tcg_temp_local_new_i64(); + TCGv_i32 res = tcg_temp_local_new_i32(); + TCGv_i32 sr_ove = tcg_temp_local_new_i32(); + uint64_t i16 = (uint64_t)I16; + /* Calculate the result. */ + tcg_gen_extu_i32_i64(tmp0, cpu_R[ra]); + tcg_gen_muli_i64(t0, tmp0, i16); + tcg_gen_trunc_i64_i32(t1, t0); + tcg_gen_mov_tl(res, t1); + tcg_gen_shri_i32(t1, t1, 31); + /* Overflow or not. */ + tcg_gen_brcondi_tl(TCG_COND_NE, t1, 0x0, lab1); + tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0x1ffff, lab1); + tcg_gen_ori_tl(cpu_sr, cpu_sr, SR_OV); + tcg_gen_ori_tl(cpu_sr, cpu_sr, SR_CY); + tcg_gen_andi_tl(sr_ove, cpu_sr, SR_OVE); + tcg_gen_brcondi_tl(TCG_COND_NE, sr_ove, SR_OVE, lab1); + gen_exception(dc, EXCP_RANGE); + /* Store result. */ + gen_set_label(lab1); + tcg_gen_mov_i32(cpu_R[rd], res); + tcg_temp_free_i64(t0); + tcg_temp_free_i32(t1); + tcg_temp_free_i32(t2); + tcg_temp_free_i64(tmp0); + tcg_temp_free_i32(res); + tcg_temp_free_i32(sr_ove); +#ifdef TARGET_OPENRISC64 + int lab2 = gen_new_label(); + TCGv_i64 tmp1 = tcg_temp_local_new_i64(); + TCGv_i64 tmp2 = tcg_temp_local_new_i64(); + TCGv_i64 tr = tcg_temp_local_new_i64(); + TCGv_i32 t3 = tcg_temp_local_new_i64(); + TCGv_i32 t4 = tcg_temp_local_new_i64(); + TCGv_i64 t5 = tcg_temp_local_new_i64(); + TCGv_i64 res1 = tcg_temp_local_new_i64(); + TCGv_i32 sr_ove64 = tcg_temp_local_new_i32(); + /* Calculate the result. */ + tcg_gen_trunc_i64_i32(t3, cpu_R[ra]); + tcg_gen_shri_i64(cpu_R[ra], cpu_R[ra], 32); + tcg_gen_trunc_i64_i32(t5, cpu_R[ra]); + tcg_gen_muli_i64(tr, t3, I16); + tcg_gen_muli_i64(t4, t5, I16); + tcg_gen_shri_i64(tmp2, tr, 32); + tcg_gen_add_i64(res1, tmp2, t4); + tcg_gen_shri_i64(tmp1, res1, 31); + /* Overflow or not. */ + tcg_gen_brcondi_tl(TCG_COND_NE, tmp1, 0x0, lab2); + tcg_gen_brcondi_tl(TCG_COND_EQ, tmp1, 0x1ffff, lab2); + tcg_gen_ori_tl(cpu_sr, cpu_sr, SR_OV); + tcg_gen_ori_tl(cpu_sr, cpu_sr, SR_CY); + tcg_gen_andi_tl(sr_ove64, cpu_sr, SR_OVE); + tcg_gen_brcondi_tl(TCG_COND_EQ, sr_ove64, SR_OVE, lab2); + gen_exeception(dc, EXCP_RANGE); + /* Store result. */ + gen_set_label(lab2); + tcg_gen_andi_i64(tr, tr, 0xffffffff); + tcg_gen_shli_i64(res1, res1, 32); + tcg_gen_add_i64(cpu_R[rd], res1, tr); + tcg_temp_free_i64(tmp1); + tcg_temp_free_i64(tmp2); + tcg_temp_free_i64(t3); + tcg_temp_free_i64(t4); + tcg_temp_free_i64(t5); + tcg_temp_free_i64(tr); + tcg_temp_free_i64(res1); + tcg_temp_free_i64(sr_ove64); +#endif + } else { + tcg_gen_movi_tl(cpu_R[rd], 0x0); + } + break; + + case 0x2d: /*l.mfspr*/ + LOG_DIS("l.mfspr r%d, r%d, %d\n", rd, ra, I16); + break; + + case 0x30: /*l.mtspr*/ + LOG_DIS("l.mtspr %d, r%d, r%d, %d\n", I5, ra, rb, I11); + break; + + case 0x34: /*l.sd*/ + LOG_DIS("l.sd %d, r%d, r%d, %d\n", I5, ra, rb, I11); + { +#ifdef TARGET_OPENRISC64 + check_ob64s(dc); + TCGv_i64 t0 = tcg_temp_new_i64(); + tcg_gen_addi_tl(t0, cpu_R[ra], sign_extend(tmp, 16)); + tcg_gen_qemu_st64(cpu_R[rb], t0, dc->mem_idx); + tcg_temp_free_i64(t0); +#endif + } + break; + + case 0x35: /*l.sw*/ + LOG_DIS("l.sw %d, r%d, r%d, %d\n", I5, ra, rb, I11); + { + TCGv t0 = tcg_temp_new(); + tcg_gen_addi_tl(t0, cpu_R[ra], sign_extend(tmp, 16)); + tcg_gen_qemu_st32(cpu_R[rb], t0, dc->mem_idx); + tcg_temp_free(t0); + } + break; + + case 0x36: /*l.sb*/ + LOG_DIS("l.sb %d, r%d, r%d, %d\n", I5, ra, rb, I11); + { + TCGv t0 = tcg_temp_new(); + tcg_gen_addi_tl(t0, cpu_R[ra], sign_extend(tmp, 16)); + tcg_gen_qemu_st8(cpu_R[rb], t0, dc->mem_idx); + tcg_temp_free(t0); + } + break; + + case 0x37: /*l.sh*/ + LOG_DIS("l.sh %d, r%d, r%d, %d\n", I5, ra, rb, I11); + { + TCGv t0 = tcg_temp_new(); + tcg_gen_addi_tl(t0, cpu_R[ra], sign_extend(tmp, 16)); + tcg_gen_qemu_st16(cpu_R[rb], t0, dc->mem_idx); + tcg_temp_free(t0); + } + break; + + default: + gen_illegal_exception(dc); + break; + } +} + +static void dec_mac(DisasContext *dc, CPUOpenRISCState *env, uint32_t insn) +{ + uint32_t op0; + uint32_t ra, rb; + op0 = field(insn, 0, 4); + ra = field(insn, 16, 5); + rb = field(insn, 11, 5); + + switch (op0) { + case 0x0001: /*l.mac*/ + LOG_DIS("l.mac r%d, r%d\n", ra, rb); + { + TCGv_i32 t0 = tcg_temp_new_i32(); + TCGv_i64 t1 = tcg_temp_new_i64(); + TCGv_i64 t2 = tcg_temp_new_i64(); + tcg_gen_mul_tl(t0, cpu_R[ra], cpu_R[rb]); + tcg_gen_ext_i32_i64(t1, t0); + tcg_gen_concat_i32_i64(t2, maclo, machi); + tcg_gen_add_i64(t2, t2, t1); + tcg_gen_trunc_i64_i32(maclo, t2); + tcg_gen_shri_i64(t2, t2, 32); + tcg_gen_trunc_i64_i32(machi, t2); + tcg_temp_free_i32(t0); + tcg_temp_free_i64(t1); + tcg_temp_free_i64(t2); + } + break; + + case 0x0002: /*l.msb*/ + LOG_DIS("l.msb r%d, r%d\n", ra, rb); + { + TCGv_i32 t0 = tcg_temp_new_i32(); + TCGv_i64 t1 = tcg_temp_new_i64(); + TCGv_i64 t2 = tcg_temp_new_i64(); + tcg_gen_mul_tl(t0, cpu_R[ra], cpu_R[rb]); + tcg_gen_ext_i32_i64(t1, t0); + tcg_gen_concat_i32_i64(t2, maclo, machi); + tcg_gen_sub_i64(t2, t2, t1); + tcg_gen_trunc_i64_i32(maclo, t2); + tcg_gen_shri_i64(t2, t2, 32); + tcg_gen_trunc_i64_i32(machi, t2); + tcg_temp_free_i32(t0); + tcg_temp_free_i64(t1); + tcg_temp_free_i64(t2); + } + break; + + default: + gen_illegal_exception(dc); + break; + } +} + +static void dec_logic(DisasContext *dc, CPUOpenRISCState *env, uint32_t insn) +{ + uint32_t op0; + uint32_t rd, ra, L6; + op0 = field(insn, 6, 2); + rd = field(insn, 21, 5); + ra = field(insn, 16, 5); + L6 = field(insn, 0, 6); + + switch (op0) { + case 0x00: /*l.slli*/ + LOG_DIS("l.slli r%d, r%d, %d\n", rd, ra, L6); + tcg_gen_shli_tl(cpu_R[rd], cpu_R[ra], (L6 & 0x1f)); + break; + + case 0x01: /*l.srli*/ + LOG_DIS("l.srli r%d, r%d, %d\n", rd, ra, L6); + tcg_gen_shri_tl(cpu_R[rd], cpu_R[ra], (L6 & 0x1f)); + break; + + case 0x02: /*l.srai*/ + LOG_DIS("l.srai r%d, r%d, %d\n", rd, ra, L6); + tcg_gen_sari_tl(cpu_R[rd], cpu_R[ra], (L6 & 0x1f)); break; + + case 0x03: /*l.rori*/ + LOG_DIS("l.rori r%d, r%d, %d\n", rd, ra, L6); + tcg_gen_rotri_tl(cpu_R[rd], cpu_R[ra], (L6 & 0x1f)); + break; + + default: + gen_illegal_exception(dc); + break; + } +} + +static void dec_M(DisasContext *dc, CPUOpenRISCState *env, uint32_t insn) +{ + uint32_t op0; + uint32_t rd; + uint32_t K16; + op0 = field(insn, 16, 1); + rd = field(insn, 21, 5); + K16 = field(insn, 0, 16); + + switch (op0) { + case 0x0: /*l.movhi*/ + LOG_DIS("l.movhi r%d, %d\n", rd, K16); + tcg_gen_movi_tl(cpu_R[rd], (K16 << 16)); + break; + + case 0x1: /*l.macrc*/ + LOG_DIS("l.macrc r%d\n", rd); + tcg_gen_mov_tl(cpu_R[rd], maclo); + tcg_gen_movi_tl(maclo, 0x0); + tcg_gen_movi_tl(machi, 0x0); + break; + + default: + gen_illegal_exception(dc); + break; + } +} + +static void dec_comp(DisasContext *dc, CPUOpenRISCState *env, uint32_t insn) +{ + uint32_t op0; + uint32_t ra, rb; + + op0 = field(insn, 21, 5); + ra = field(insn, 16, 5); + rb = field(insn, 11, 5); + + tcg_gen_movi_i32(env_btaken, 0x0); + /* unsigned integers */ + tcg_gen_ext32u_tl(cpu_R[ra], cpu_R[ra]); + tcg_gen_ext32u_tl(cpu_R[rb], cpu_R[rb]); + + switch (op0) { + case 0x0: /*l.sfeq*/ + LOG_DIS("l.sfeq r%d, r%d\n", ra, rb); + tcg_gen_setcond_tl(TCG_COND_EQ, env_btaken, cpu_R[ra], cpu_R[rb]); + break; + + case 0x1: /*l.sfne*/ + LOG_DIS("l.sfne r%d, r%d\n", ra, rb); + tcg_gen_setcond_tl(TCG_COND_NE, env_btaken, cpu_R[ra], cpu_R[rb]); + break; + + case 0x2: /*l.sfgtu*/ + LOG_DIS("l.sfgtu r%d, r%d\n", ra, rb); + tcg_gen_setcond_tl(TCG_COND_GTU, env_btaken, cpu_R[ra], cpu_R[rb]); + break; + + case 0x3: /*l.sfgeu*/ + LOG_DIS("l.sfgeu r%d, r%d\n", ra, rb); + tcg_gen_setcond_tl(TCG_COND_GEU, env_btaken, cpu_R[ra], cpu_R[rb]); + break; + + case 0x4: /*l.sfltu*/ + LOG_DIS("l.sfltu r%d, r%d\n", ra, rb); + tcg_gen_setcond_tl(TCG_COND_LTU, env_btaken, cpu_R[ra], cpu_R[rb]); + break; + + case 0x5: /*l.sfleu*/ + LOG_DIS("l.sfleu r%d, r%d\n", ra, rb); + tcg_gen_setcond_tl(TCG_COND_LEU, env_btaken, cpu_R[ra], cpu_R[rb]); + break; + + case 0xa: /*l.sfgts*/ + LOG_DIS("l.sfgts r%d, r%d\n", ra, rb); + tcg_gen_setcond_tl(TCG_COND_GT, env_btaken, cpu_R[ra], cpu_R[rb]); + break; + + case 0xb: /*l.sfges*/ + LOG_DIS("l.sfges r%d, r%d\n", ra, rb); + tcg_gen_setcond_tl(TCG_COND_GE, env_btaken, cpu_R[ra], cpu_R[rb]); + break; + + case 0xc: /*l.sflts*/ + LOG_DIS("l.sflts r%d, r%d\n", ra, rb); + tcg_gen_setcond_tl(TCG_COND_LT, env_btaken, cpu_R[ra], cpu_R[rb]); + break; + + case 0xd: /*l.sfles*/ + LOG_DIS("l.sfles r%d, r%d\n", ra, rb); + tcg_gen_setcond_tl(TCG_COND_LE, env_btaken, cpu_R[ra], cpu_R[rb]); + break; + + default: + gen_illegal_exception(dc); + break; + } + wb_SR_F(); +} + +static void dec_compi(DisasContext *dc, CPUOpenRISCState *env, uint32_t insn) +{ + uint32_t op0; + uint32_t ra, I16; + + op0 = field(insn, 21, 5); + ra = field(insn, 16, 5); + I16 = field(insn, 0, 16); + + tcg_gen_movi_i32(env_btaken, 0x0); + I16 = sign_extend(I16, 16); + + switch (op0) { + case 0x0: /*l.sfeqi*/ + LOG_DIS("l.sfeqi r%d, %d\n", ra, I16); + tcg_gen_setcondi_tl(TCG_COND_EQ, env_btaken, cpu_R[ra], I16); + break; + + case 0x1: /*l.sfnei*/ + LOG_DIS("l.sfnei r%d, %d\n", ra, I16); + tcg_gen_setcondi_tl(TCG_COND_NE, env_btaken, cpu_R[ra], I16); + break; + + case 0x2: /*l.sfgtui*/ + LOG_DIS("l.sfgtui r%d, %d\n", ra, I16); + tcg_gen_setcondi_tl(TCG_COND_GTU, env_btaken, cpu_R[ra], I16); + break; + + case 0x3: /*l.sfgeui*/ + LOG_DIS("l.sfgeui r%d, %d\n", ra, I16); + tcg_gen_setcondi_tl(TCG_COND_GEU, env_btaken, cpu_R[ra], I16); + break; + + case 0x4: /*l.sfltui*/ + LOG_DIS("l.sfltui r%d, %d\n", ra, I16); + tcg_gen_setcondi_tl(TCG_COND_LTU, env_btaken, cpu_R[ra], I16); + break; + + case 0x5: /*l.sfleui*/ + LOG_DIS("l.sfleui r%d, %d\n", ra, I16); + tcg_gen_setcondi_tl(TCG_COND_LEU, env_btaken, cpu_R[ra], I16); + break; + + case 0xa: /*l.sfgtsi*/ + LOG_DIS("l.sfgtsi r%d, %d\n", ra, I16); + tcg_gen_setcondi_tl(TCG_COND_GT, env_btaken, cpu_R[ra], I16); + break; + + case 0xb: /*l.sfgesi*/ + LOG_DIS("l.sfgesi r%d, %d\n", ra, I16); + tcg_gen_setcondi_tl(TCG_COND_GE, env_btaken, cpu_R[ra], I16); + break; + + case 0xc: /*l.sfltsi*/ + LOG_DIS("l.sfltsi r%d, %d\n", ra, I16); + tcg_gen_setcondi_tl(TCG_COND_LT, env_btaken, cpu_R[ra], I16); + break; + + case 0xd: /*l.sflesi*/ + LOG_DIS("l.sflesi r%d, %d\n", ra, I16); + tcg_gen_setcondi_tl(TCG_COND_LE, env_btaken, cpu_R[ra], I16); + break; + + default: + gen_illegal_exception(dc); + break; + } + wb_SR_F(); +} + +static void dec_sys(DisasContext *dc, CPUOpenRISCState *env, uint32_t insn) +{ + uint32_t op0; + /*uint32_t K16;*/ + op0 = field(insn, 16, 8); + /*K16 = field(insn, 0, 16);*/ + + switch (op0) { + case 0x000: /*l.sys*/ + /*LOG_DIS("l.sys %d\n", K16);*/ + tcg_gen_movi_tl(cpu_pc, dc->pc); + gen_exception(dc, EXCP_SYSCALL); + dc->is_jmp = DISAS_UPDATE; + break; + + case 0x100: /*l.trap*/ + /*LOG_DIS("l.trap %d\n", K16);*/ + tcg_gen_movi_tl(cpu_pc, dc->pc); + gen_exception(dc, EXCP_TRAP); + break; + + case 0x300: /*l.csync*/ + LOG_DIS("l.csync\n"); + break; + + case 0x200: /*l.msync*/ + LOG_DIS("l.msync\n"); + break; + + case 0x270: /*l.psync*/ + LOG_DIS("l.psync\n"); + break; + + default: + gen_illegal_exception(dc); + break; + } +} + +static void dec_float(DisasContext *dc, CPUOpenRISCState *env, uint32_t insn) +{ + uint32_t op0; + uint32_t ra, rb, rd; + op0 = field(insn, 0, 8); + ra = field(insn, 16, 5); + rb = field(insn, 11, 5); + rd = field(insn, 21, 5); + + switch (op0) { + case 0x00: /*lf.add.s*/ + LOG_DIS("lf.add.s r%d, r%d, r%d\n", rd, ra, rb); + gen_helper_float_add_s(cpu_R[rd], cpu_env, cpu_R[ra], cpu_R[rb]); + break; + + case 0x01: /*lf.sub.s*/ + LOG_DIS("lf.sub.s r%d, r%d, r%d\n", rd, ra, rb); + gen_helper_float_sub_s(cpu_R[rd], cpu_env, cpu_R[ra], cpu_R[rb]); + break; + + + case 0x02: /*lf.mul.s*/ + LOG_DIS("lf.mul.s r%d, r%d, r%d\n", rd, ra, rb); + if (ra != 0 && rb != 0) { + gen_helper_float_mul_s(cpu_R[rd], cpu_env, cpu_R[ra], cpu_R[rb]); + } else { + tcg_gen_ori_tl(fpcsr, fpcsr, FPCSR_ZF); + tcg_gen_movi_i32(cpu_R[rd], 0x0); + } + break; + + case 0x03: /*lf.div.s*/ + LOG_DIS("lf.div.s r%d, r%d, r%d\n", rd, ra, rb); + gen_helper_float_div_s(cpu_R[rd], cpu_env, cpu_R[ra], cpu_R[rb]); + break; + + case 0x04: /*lf.itof.s*/ + LOG_DIS("lf.itof r%d, r%d\n", rd, ra); + gen_helper_itofs(cpu_R[rd], cpu_env, cpu_R[ra]); + break; + + case 0x05: /*lf.ftoi.s*/ + LOG_DIS("lf.ftoi r%d, r%d\n", rd, ra); + gen_helper_ftois(cpu_R[rd], cpu_env, cpu_R[ra]); + break; + + case 0x06: /*lf.rem.s*/ + LOG_DIS("lf.rem.s r%d, r%d, r%d\n", rd, ra, rb); + gen_helper_float_rem_s(cpu_R[rd], cpu_env, cpu_R[ra], cpu_R[rb]); + break; + + case 0x07: /*lf.madd.s*/ + LOG_DIS("lf.madd.s r%d, r%d, r%d\n", rd, ra, rb); + gen_helper_float_muladd_s(cpu_R[rd], cpu_env, cpu_R[ra], cpu_R[rb]); + break; + + case 0x08: /*lf.sfeq.s*/ + LOG_DIS("lf.sfeq.s r%d, r%d\n", ra, rb); + gen_helper_float_eq_s(env_btaken, cpu_env, cpu_R[ra], cpu_R[rb]); + break; + + case 0x09: /*lf.sfne.s*/ + LOG_DIS("lf.sfne.s r%d, r%d\n", ra, rb); + gen_helper_float_ne_s(env_btaken, cpu_env, cpu_R[ra], cpu_R[rb]); + break; + + case 0x0a: /*lf.sfgt.s*/ + LOG_DIS("lf.sfgt.s r%d, r%d\n", ra, rb); + gen_helper_float_gt_s(env_btaken, cpu_env, cpu_R[ra], cpu_R[rb]); + break; + + case 0x0b: /*lf.sfge.s*/ + LOG_DIS("lf.sfge.s r%d, r%d\n", ra, rb); + gen_helper_float_ge_s(env_btaken, cpu_env, cpu_R[ra], cpu_R[rb]); + break; + + case 0x0c: /*lf.sflt.s*/ + LOG_DIS("lf.sflt.s r%d, r%d\n", ra, rb); + gen_helper_float_lt_s(env_btaken, cpu_env, cpu_R[ra], cpu_R[rb]); + break; + + case 0x0d: /*lf.sfle.s*/ + LOG_DIS("lf.sfle.s r%d, r%d\n", ra, rb); + gen_helper_float_le_s(env_btaken, cpu_env, cpu_R[ra], cpu_R[rb]); + break; + +#ifdef TARGET_OPENRISC64 + case 0x10: /*lf.add.d*/ + LOG_DIS("lf.add.d r%d, r%d, r%d\n", rd, ra, rb); + check_of64s(dc); + gen_helper_float_add_d(cpu_R[rd], cpu_env, cpu_R[ra], cpu_R[rb]); + break; + + case 0x11: /*lf.sub.d*/ + LOG_DIS("lf.sub.d r%d, r%d, r%d\n", rd, ra, rb); + check_of64s(dc); + gen_helper_float_sub_d(cpu_R[rd], cpu_env, cpu_R[ra], cpu_R[rb]); + break; + + case 0x12: /*lf.mul.d*/ + LOG_DIS("lf.mul.d r%d, r%d, r%d\n", rd, ra, rb); + check_of64s(dc); + if (ra != 0 && rb != 0) { + gen_helper_float_mul_d(cpu_R[rd], cpu_env, cpu_R[ra], cpu_R[rb]); + } else { + tcg_gen_ori_tl(fpcsr, fpcsr, FPCSR_ZF); + tcg_gen_movi_i64(cpu_R[rd], 0x0); + } + break; + + case 0x13: /*lf.div.d*/ + LOG_DIS("lf.div.d r%d, r%d, r%d\n", rd, ra, rb); + check_of64s(dc); + gen_helper_float_div_d(cpu_R[rd], cpu_env, cpu_R[ra], cpu_R[rb]); + break; + + case 0x14: /*lf.itof.d*/ + LOG_DIS("lf.itof r%d, r%d\n", rd, ra); + check_of64s(dc); + gen_helper_itofd(cpu_R[rd], cpu_env, cpu_R[ra]); + break; + + case 0x15: /*lf.ftoi.d*/ + LOG_DIS("lf.ftoi r%d, r%d\n", rd, ra); + check_of64s(dc); + gen_helper_ftoid(cpu_R[rd], cpu_env, cpu_R[ra]); + break; + + case 0x16: /*lf.rem.d*/ + LOG_DIS("lf.rem.d r%d, r%d, r%d\n", rd, ra, rb); + check_of64s(dc); + gen_helper_float_rem_d(cpu_R[rd], cpu_env, cpu_R[ra], cpu_R[rb]); + break; + + case 0x17: /*lf.madd.d*/ + LOG_DIS("lf.madd.d r%d, r%d, r%d\n", rd, ra, rb); + check_of64s(dc); + gen_helper_float_muladd_d(cpu_R[rd], cpu_env, cpu_R[ra], cpu_R[rb]); + break; + + case 0x18: /*lf.sfeq.d*/ + LOG_DIS("lf.sfeq.d r%d, r%d\n", ra, rb); + check_of64s(dc); + gen_helper_float_eq_d(env_btaken, cpu_env, cpu_R[ra], cpu_R[rb]); + break; + + case 0x1a: /*lf.sfgt.d*/ + LOG_DIS("lf.sfgt.d r%d, r%d\n", ra, rb); + check_of64s(dc); + gen_helper_float_gt_d(env_btaken, cpu_env, cpu_R[ra], cpu_R[rb]); + break; + + case 0x1b: /*lf.sfge.d*/ + LOG_DIS("lf.sfge.d r%d, r%d\n", ra, rb); + check_of64s(dc); + gen_helper_float_ge_d(env_btaken, cpu_env, cpu_R[ra], cpu_R[rb]); + break; + + case 0x19: /*lf.sfne.d*/ + LOG_DIS("lf.sfne.d r%d, r%d\n", ra, rb); + check_of64s(dc); + gen_helper_float_ne_d(env_btaken, cpu_env, cpu_R[ra], cpu_R[rb]); + break; + + case 0x1c: /*lf.sflt.d*/ + LOG_DIS("lf.sflt.d r%d, r%d\n", ra, rb); + check_of64s(dc); + gen_helper_float_lt_d(env_btaken, cpu_env, cpu_R[ra], cpu_R[rb]); + break; + + case 0x1d: /*lf.sfle.d*/ + LOG_DIS("lf.sfle.d r%d, r%d\n", ra, rb); + check_of64s(dc); + gen_helper_float_le_d(env_btaken, cpu_env, cpu_R[ra], cpu_R[rb]); + break; +#endif + + default: + gen_illegal_exception(dc); + break; + } + wb_SR_F(); +} + +static void disas_openrisc_insn(DisasContext *dc, CPUOpenRISCState *env) +{ + uint32_t op0; + uint32_t insn; + insn = cpu_ldl_code(env, dc->pc); + op0 = field(insn, 26, 6); + + switch (op0) { + case 0x06: + dec_M(dc, env, insn); + break; + + case 0x08: + dec_sys(dc, env, insn); + break; + + case 0x2e: + dec_logic(dc, env, insn); + break; + + case 0x2f: + dec_compi(dc, env, insn); + break; + + case 0x31: + dec_mac(dc, env, insn); + break; + + case 0x32: + dec_float(dc, env, insn); + break; + + case 0x38: + dec_calc(dc, env, insn); + break; + + case 0x39: + dec_comp(dc, env, insn); + break; + + default: + dec_misc(dc, env, insn); + break; + } +} + +static void check_breakpoint(CPUOpenRISCState *env, DisasContext *dc) +{ + CPUBreakpoint *bp; + + if (unlikely(!QTAILQ_EMPTY(&env->breakpoints))) { + QTAILQ_FOREACH(bp, &env->breakpoints, entry) { + if (bp->pc == dc->pc) { + tcg_gen_movi_tl(cpu_pc, dc->pc); + gen_exception(dc, EXCP_DEBUG); + dc->is_jmp = DISAS_UPDATE; + } + } + } } static inline void gen_intermediate_code_internal(CPUOpenRISCState *env, TranslationBlock *tb, int search_pc) { + struct DisasContext ctx, *dc = &ctx; + uint16_t *gen_opc_end; + uint32_t pc_start; + int j, k; + uint32_t next_page_start; + int num_insns; + int max_insns; + + qemu_log_try_set_file(stderr); + + pc_start = tb->pc; + dc->env = env; + dc->tb = tb; + + gen_opc_end = gen_opc_buf + OPC_MAX_SIZE; + dc->is_jmp = DISAS_NEXT; + dc->ppc = pc_start; + dc->pc = pc_start; + dc->flags = env->cpucfgr; + dc->mem_idx = cpu_mmu_index(env); + dc->synced_flags = dc->tb_flags = tb->flags; + dc->delayed_branch = !!(dc->tb_flags & D_FLAG); + dc->singlestep_enabled = env->singlestep_enabled; + if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) { + qemu_log("-----------------------------------------\n"); + log_cpu_state(env, 0); + } + + next_page_start = (pc_start & TARGET_PAGE_MASK) + TARGET_PAGE_SIZE; + k = -1; + num_insns = 0; + max_insns = tb->cflags & CF_COUNT_MASK; + + if (max_insns == 0) { + max_insns = CF_COUNT_MASK; + } + + gen_icount_start(); + + do { + check_breakpoint(env, dc); + if (search_pc) { + j = gen_opc_ptr - gen_opc_buf; + if (k < j) { + k++; + while (k < j) { + gen_opc_instr_start[k++] = 0; + } + } + gen_opc_pc[k] = dc->pc; + gen_opc_instr_start[k] = 1; + gen_opc_icount[k] = num_insns; + } + + if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP))) { + tcg_gen_debug_insn_start(dc->pc); + } + + if (num_insns + 1 == max_insns && (tb->cflags & CF_LAST_IO)) { + gen_io_start(); + } + dc->ppc = dc->pc - 4; + dc->npc = dc->pc + 4; + tcg_gen_movi_tl(cpu_ppc, dc->ppc); + tcg_gen_movi_tl(cpu_npc, dc->npc); + disas_openrisc_insn(dc, env); + dc->pc = dc->npc; + num_insns++; + /* delay slot */ + if (dc->delayed_branch) { + dc->delayed_branch--; + if (!dc->delayed_branch) { + dc->tb_flags &= ~D_FLAG; + gen_sync_flags(dc); + tcg_gen_mov_tl(cpu_pc, jmp_pc); + tcg_gen_mov_tl(cpu_npc, jmp_pc); + tcg_gen_movi_tl(jmp_pc, 0); + tcg_gen_exit_tb(0); + dc->is_jmp = DISAS_JUMP; + break; + } + } + } while (!dc->is_jmp + && gen_opc_ptr < gen_opc_end + && !env->singlestep_enabled + && !singlestep + && (dc->pc < next_page_start) + && num_insns < max_insns); + + if (tb->cflags & CF_LAST_IO) { + gen_io_end(); + } + if (dc->is_jmp == DISAS_NEXT) { + dc->is_jmp = DISAS_UPDATE; + tcg_gen_movi_tl(cpu_pc, dc->pc); + } + if (unlikely(env->singlestep_enabled)) { + if (dc->is_jmp == DISAS_NEXT) { + tcg_gen_movi_tl(cpu_pc, dc->pc); + } + gen_exception(dc, EXCP_DEBUG); + } else { + switch (dc->is_jmp) { + case DISAS_NEXT: + gen_goto_tb(dc, 0, dc->pc); + break; + default: + case DISAS_JUMP: + break; + case DISAS_UPDATE: + /* indicate that the hash table must be used + to find the next TB */ + tcg_gen_exit_tb(0); + break; + case DISAS_TB_JUMP: + /* nothing more to generate */ + break; + } + } + + gen_icount_end(tb, num_insns); + *gen_opc_ptr = INDEX_op_end; + if (search_pc) { + j = gen_opc_ptr - gen_opc_buf; + k++; + while (k <= j) { + gen_opc_instr_start[k++] = 0; + } + } else { + tb->size = dc->pc - pc_start; + tb->icount = num_insns; + } + +#ifdef DEBUG_DISAS + if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) { + qemu_log("\n"); + log_target_disas(pc_start, dc->pc - pc_start, 0); + qemu_log("\nisize=%d osize=%td\n", + dc->pc - pc_start, gen_opc_ptr - gen_opc_buf); + } +#endif } void gen_intermediate_code(CPUOpenRISCState *env, struct TranslationBlock *tb) --1.7.9.5
Re: [Qemu-devel] [PATCH v5 12/16] target-or32: Add system instructions
In reply to Jia LiuQuoted 167 lines · Jia Liu
Add OpenRISC system instruction support.
Signed-off-by Jia Liu <[email protected]>---
target-openrisc/Makefile.objs | 3 +-
target-openrisc/helper.h | 4 +target-openrisc/sys_helper.c| 233 +++++++++++++++++++++++++++++++++++++++++target-openrisc/translate.c| 20 ++++4 files changed, 259 insertions(+), 1 deletion(-)create mode 100644
target-openrisc/sys_helper.ctarget-openrisc/Makefile.objs +0
-0@@ -1,3 +1,4 @@obj-$(CONFIG_SOFTMMU) += machine.o
obj-y += cpu.o excp.o intrpt.o mmu.o translate.otarget-openrisc/Makefile.objs +2
-1-obj-y += excp_helper.o fpu_helper.o int_helper.o intrpt_helper.o mmu_helper.o +obj-y += excp_helper.o fpu_helper.o int_helper.o intrpt_helper.o \ + mmu_helper.o sys_helper.otarget-openrisc/helper.h +4
-0@@ -62,4 +62,8 @@ DEF_HELPER_FLAGS_1(fl1, 0, tl, tl) /* interrupt */ DEF_HELPER_FLAGS_1(rfe, 0, void, env) +/* sys */ +DEF_HELPER_FLAGS_4(mtspr, 0, void, env, tl, tl, tl) +DEF_HELPER_FLAGS_4(mfspr, 0, void, env, tl, tl, tl) + #include "def-helper.h"target-openrisc/sys_helper.c new file +127
-0@@ -0,0 +1,233 @@ +/* +* OpenRISC system instructions helper routines +* +* Copyright (c) 2011-2012 Jia Liu <[email protected]> +* Zhizhou Zhang <[email protected]> +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2 of the License, or (at your option) any later version. +* +* This library 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 +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, see <http://www.gnu.org/licenses/>. +*/ + +#include "cpu.h" +#include "helper.h" + +#define TO_SPR (group, number) (((group) << 11) + (number)) + +void HELPER (mtspr )(CPUOpenRISCState * env, + target_ulong ra, target_ulong rb, target_ulong offset) +{ +#if !defined(CONFIG_USER_ONLY ) + int spr = (ra | offset); + int idx; + + switch (spr) { + case TO_SPR(0, 0): /* VR */ + env->vr = rb; + break; + + case TO_SPR(0, 16): /* NPC */ + env->npc = rb; + break; + + case TO_SPR(0, 17): /* SR */ + if ((env->sr & (SR_IME | SR_DME | SR_SM)) ^ + (rb & (SR_IME | SR_DME | SR_SM))) { + tlb_flush(env, 1); + } + env->sr = rb; + env->sr |= SR_FO; /* FO is const equal to 1 */ + if (env->sr & SR_DME) { + env->tlb->map_address_data = &get_phys_data; + } else { + env->tlb->map_address_data = &get_phys_nommu; + } + + if (env->sr & SR_IME) { + env->tlb->map_address_code = &get_phys_code; + } else { + env->tlb->map_address_code = &get_phys_nommu; + } + break; + + case TO_SPR(0, 18): /* PPC */ + env->ppc = rb; + break; + + case TO_SPR(0, 32): /* EPCR */ + env->epcr = rb; + break; + + case TO_SPR(0, 48): /* EEAR */ + env->eear = rb; + break; + + case TO_SPR(0, 64): /* ESR */ + env->esr = rb; + break; + case TO_SPR(1, 512) ... TO_SPR(1, 639): /* DTLBW0MR 0-127 */ + idx = spr - TO_SPR(1, 512); + if (!(rb & 1)) { + tlb_flush_page(env, env->tlb->dtlb[0][idx].mr & TARGET_PAGE_MASK); + } + env->tlb->dtlb[0][idx].mr = rb; + break; + + case TO_SPR(1, 640) ... TO_SPR(1, 767): /* DTLBW0TR 0-127 */ + idx = spr - TO_SPR(1, 640); + env->tlb->dtlb[0][idx].tr = rb; + break; + case TO_SPR(1, 768) ... TO_SPR(1, 895): /* DTLBW1MR 0-127 */ + case TO_SPR(1, 896) ... TO_SPR(1, 1023): /* DTLBW1TR 0-127 */ + case TO_SPR(1, 1024) ... TO_SPR(1, 1151): /* DTLBW2MR 0-127 */ + case TO_SPR(1, 1152) ... TO_SPR(1, 1279): /* DTLBW2TR 0-127 */ + case TO_SPR(1, 1280) ... TO_SPR(1, 1407): /* DTLBW3MR 0-127 */ + case TO_SPR(1, 1408) ... TO_SPR(1, 1535): /* DTLBW3TR 0-127 */ + break; + case TO_SPR(2, 512) ... TO_SPR(2, 639): /* ITLBW0MR 0-127 */ + idx = spr - TO_SPR(2, 512); + if (!(rb & 1)) { + tlb_flush_page(env, env->tlb->itlb[0][idx].mr & TARGET_PAGE_MASK); + } + env->tlb->itlb[0][idx].mr = rb; + break; + + case TO_SPR(2, 640) ... TO_SPR(2, 767): /* ITLBW0TR 0-127 */ + idx = spr - TO_SPR(2, 640); + env->tlb->itlb[0][idx].tr = rb; + break; + case TO_SPR(2, 768) ... TO_SPR(2, 895): /* ITLBW1MR 0-127 */ + case TO_SPR(2, 896) ... TO_SPR(2, 1023): /* ITLBW1TR 0-127 */ + case TO_SPR(2, 1024) ... TO_SPR(2, 1151): /* ITLBW2MR 0-127 */ + case TO_SPR(2, 1152) ... TO_SPR(2, 1279): /* ITLBW2TR 0-127 */ + case TO_SPR(2, 1280) ... TO_SPR(2, 1407): /* ITLBW3MR 0-127 */ + case TO_SPR(2, 1408) ... TO_SPR(2, 1535): /* ITLBW3TR 0-127 */ + break; + case TO_SPR(9, 0): /* PICMR */ + cpu_openrisc_store_picmr(env, rb); + break; + case TO_SPR(9, 2): /* PICSR */ + cpu_openrisc_store_picsr(env, rb); + break; + case TO_SPR(10, 0): /* TTMR */ + cpu_openrisc_store_compare(env, rb); + break; + case TO_SPR(10, 1): /* TTCR */ + cpu_openrisc_store_count(env, rb); + break; + default:
target-openrisc/sys_helper.c line 137
Quoted 10 lines
target-openrisc/sys_helper.c new file +10
-0+ break; + } +#endif +} + +void HELPER (mfspr )(CPUOpenRISCState * env, + target_ulong rd, target_ulong ra, uint32_t offset) +{ +#if !defined(CONFIG_USER_ONLY ) + int spr = env->gpr[ra] | offset;
[1]
Quoted 80 lines
target-openrisc/sys_helper.c new file +80
-0+ int idx; + + switch (spr) { + case TO_SPR(0, 0): /* VR */ + env->gpr[rd] = (env->vr & SPR_VR); + break; + + case TO_SPR(0, 1): /* UPR */ + env->gpr[rd] = env->upr; /* TT, DM, IM, UP present */ + break; + + case TO_SPR(0, 2): /* CPUCFGR */ + env->gpr[rd] = env->cpucfgr; + break; + + case TO_SPR(0, 3): /* DMMUCFGR */ + env->gpr[rd] = env->dmmucfgr; /* 1Way, 64 entries */ + break; + case TO_SPR(0, 4): /* IMMUCFGR */ + env->gpr[rd] = env->immucfgr; + break; + + case TO_SPR(0, 16): /* NPC */ + env->gpr[rd] = env->npc; + break; + + case TO_SPR(0, 17): /* SR */ + env->gpr[rd] = env->sr; + break; + + case TO_SPR(0, 18): /* PPC */ + env->gpr[rd] = env->ppc; + break; + + case TO_SPR(0, 32): /* EPCR */ + env->gpr[rd] = env->epcr; + break; + + case TO_SPR(0, 48): /* EEAR */ + env->gpr[rd] = env->eear; + break; + + case TO_SPR(0, 64): /* ESR */ + env->gpr[rd] = env->esr; + break; + + case TO_SPR(1, 512) ... TO_SPR(1, 639): /* DTLBW0MR 0-127 */ + idx = spr - TO_SPR(1, 512); + env->gpr[rd] = env->tlb->dtlb[0][idx].mr; + break; + + case TO_SPR(1, 640) ... TO_SPR(1, 767): /* DTLBW0TR 0-127 */ + idx = spr - TO_SPR(1, 640); + env->gpr[rd] = env->tlb->dtlb[0][idx].tr; + break; + case TO_SPR(1, 768) ... TO_SPR(1, 895): /* DTLBW1MR 0-127 */ + case TO_SPR(1, 896) ... TO_SPR(1, 1023): /* DTLBW1TR 0-127 */ + case TO_SPR(1, 1024) ... TO_SPR(1, 1151): /* DTLBW2MR 0-127 */ + case TO_SPR(1, 1152) ... TO_SPR(1, 1279): /* DTLBW2TR 0-127 */ + case TO_SPR(1, 1280) ... TO_SPR(1, 1407): /* DTLBW3MR 0-127 */ + case TO_SPR(1, 1408) ... TO_SPR(1, 1535): /* DTLBW3TR 0-127 */ + break; + + case TO_SPR(2, 512) ... TO_SPR(2, 639): /* ITLBW0MR 0-127 */ + idx = spr - TO_SPR(2, 512); + env->gpr[rd] = env->tlb->itlb[0][idx].mr; + break; + + case TO_SPR(2, 640) ... TO_SPR(2, 767): /* ITLBW0TR 0-127 */ + idx = spr - TO_SPR(2, 640); + env->gpr[rd] = env->tlb->itlb[0][idx].tr; + break; + case TO_SPR(2, 768) ... TO_SPR(2, 895): /* ITLBW1MR 0-127 */ + case TO_SPR(2, 896) ... TO_SPR(2, 1023): /* ITLBW1TR 0-127 */ + case TO_SPR(2, 1024) ... TO_SPR(2, 1151): /* ITLBW2MR 0-127 */ + case TO_SPR(2, 1152) ... TO_SPR(2, 1279): /* ITLBW2TR 0-127 */ + case TO_SPR(2, 1280) ... TO_SPR(2, 1407): /* ITLBW3MR 0-127 */ + case TO_SPR(2, 1408) ... TO_SPR(2, 1535): /* ITLBW3TR 0-127 */ + break; + case TO_SPR(9, 0): /* PICMR */
target-openrisc/sys_helper.c line 227
Quoted 10 lines
target-openrisc/sys_helper.c new file +10
-0+ env->gpr[rd] = env->picmr; + break; + case TO_SPR(9, 2): /* PICSR */ + env->gpr[rd] = env->picsr; + break; + case TO_SPR(10, 0): /* TTMR */ + env->gpr[rd] = env->ttmr; + break; + case TO_SPR(10, 1): /* TTCR */ + env->gpr[rd] = cpu_openrisc_get_count(env);
[2]
Quoted 12 lines
target-openrisc/sys_helper.c new file +6
-0+ break; + default: + break; + } +#endif +}target-openrisc/translate.c +0
-0@@ -1241,10 +1241,30 @@ static void dec_misc(DisasContext *dc, CPUOpenRISCState *env, uint32_t insn)
Quoted 7 lines
case
0x2d: /*l.mfspr*/
LOG_DIS("l.mfspr r%d, r%d, %d\n", rd, ra, I16);
+ {
+ TCGv_i32 ti =tcg_const_i32(I16);
+ TCGv td =tcg_const_tl(rd);
+ TCGv ta =tcg_const_tl(ra);
+ gen_helper_mfspr(cpu_env, td, ta, ti);
The helper should a return target_ulong, so the line would become gen_helper_mfspr(cpu_R[rd], cpu_env, td, cpu_R[ra], ti);
Then the register moves inside the mfspr helper could be avoided:
[1]
Quoted 1 line
+ int spr = env->gpr[ra] | offset;
int spr = ra | offset;
As an example [2]:
Quoted 1 line
+ env->gpr[rd] =
cpu_openrisc_get_count(env);
return cpu_openrisc_get_count(env);
Quoted 4 lines
+ tcg_temp_free_i32(ti);
+ tcg_temp_free(td);
+ tcg_temp_free(ta);
+ }
Also here you could try later to avoid to compile sys_helper.c for user emulator by surrounding the previous block by #ifndef CONFIG_USER_ONLY/#endif (ditto for mtspr).
Quoted 11 lines
break;
case
0x30: /*l.mtspr*/
LOG_DIS("l.mtspr %d, r%d, r%d, %d\n", I5, ra, rb, I11);
+ {
+ TCGv_i32 im =tcg_const_i32(tmp);
+ TCGv ta =tcg_temp_new();
+ TCGv tb =tcg_temp_new();
+ tcg_gen_mov_tl(ta, cpu_R[ra]);
+ tcg_gen_mov_tl(tb, cpu_R[rb]);
+ gen_helper_mtspr(cpu_env, ta, tb, im);
Simplygen_helper_mtspr(cpu_env, cpu_R[ra], cpu_R[rb], im);
Quoted 11 lines
+ tcg_temp_free_i32(im);
+ tcg_temp_free(ta);
+ tcg_temp_free(tb);
+ }
break;case
0x34: /*l.sd*/
--
1.7.9.5
Quoted 7 lines · Jia Liu
This is the OpenCores OpenRISC 1200 support for QEMU.
Full implementation of the system-model and linux-user-model support.OpenRISC 1200 is a OpenCores open source CPU,
its architecture manual can be found at
http://opencores.org/svnget,or1k?file=/trunk/docs/openrisc_arch.pdf
Quoted 8 lines
A OpenRISC Linux kernel contain initramfs for qemu-system-or32 testing can be found at
https://docs.google.com/file/d/0BxeTrz3x0CBLSjR3Sk5Vd3h1eDA/edit?pli=1A OpenRISC hello-world program for qemu-or32 testing can be found at
https://docs.google.com/file/d/0BxeTrz3x0CBLN3RSWUFNYktrU2M/edit?pli=1Signed-off-by Jia Liu <[email protected]>
I had minor comments to a few patches, others looked ready. Please still check the patches with scripts/checkpatch.pl.
Quoted 260 lines
---
Version History:
V5:
Addressed Blue's review comments:
- reimplement l.mul* l.mfspr l.add* l.sub* and more.
- shoot bugs with "--enable-debug-tcg"V4:
Addressed Max's review comments:
- fix l.div l.mac* l.mul*, and more.Addressed Richard, Wei-Ren and Andreas's review comments:
- replacetcg_temp_new_i32withtcg_temp_local_new_i32in l.div translation.Addressed Andreas's review comments:
- update to suitMakefilesystem.- add UPR CPUCFGR and MMUCFGR impelement.
- add instruction check functions.Version History:
V3:
Addressed Stefan and Andreas's review comments:
- use QEMU and OpenRISC's official name.Addressed Andreas's review comments:
- reimplement cpu QOM.
- combine target stubs and QOM implement.
- use new commit message and subject.Addressed Max's review comments:
- handle div zero exception.
- reimplement float point instructions.
- fix l.mac*, l.mul*, and more.V2:
Addressed Malc, Weiren, Andreas and Blue's review comments:
- reimplement cpu QOM.Addressed Andreas's review comments:
- reimplement machine.
- rewrite the Copyright Notice using better format.Addressed Blue and Weiren's review comments:
- compiling with AREG0 and remove global env, no dyngen-exe longer.Addressed Max, Blue and Weiren's review comments:
- handle div zero exception.
- handle illegal instruction.Addressed Blue's review comments:
- separatedo_interruptintointrpt.cformintrpt_helper.c.
- addQEMU_NORETURNtoraise_exception.
- reimplement float instrutions.
- fix type of linux syscall and termbits.
- reimplement sim board.
- use the LGPL web URL in Copyright Notice.
- reimplemt branch instructions.- split taregt stubs, QOM and machine.
V1:
- add QEMU OpenRISC support.
- well tested on x64 machine, and final tested x86 machine.Jia Liu (16):
target-or32: Add target stubs and cpu support
target-or32: Add target machine
target-or32: Add MMU support
target-or32: Add interrupt support
target-or32: Add exception support
target-or32: Add int instruction helpers
target-or32: Add float instruction helpers
target-or32: Add translation routines
target-or32: Add PIC support
target-or32: Add timer support
target-or32: Add a IIS dummy board
target-or32: Add system instructions
target-or32: Add gdb stub support
target-or32: Add linux syscall, signal and termbits
target-or32: Add linux user support
target-or32: Add testcasesarch_init.c | 2 +
arch_init.h| 1 + configure | 15 +-cpu-exec.c| 19 + default-configs/or32-linux-user.mak | 2 + default-configs/or32-softmmu.mak | 6 +elf.h| 2 +gdbstub.c| 64 ++ hw/openrisc/Makefile.objs | 3 +hw/openrisc_cpudev.h| 29 +hw/openrisc_pic.c| 78 ++hw/openrisc_sim.c| 145 +++hw/openrisc_timer.c| 160 +++linux-user/elfload.c| 41 +linux-user/main.c| 100 ++linux-user/openrisc/syscall.h| 24 +linux-user/openrisc/syscall_nr.h| 506 +++++++++linux-user/openrisc/target_signal.h| 26 +linux-user/openrisc/termbits.h| 294 +++++linux-user/signal.c| 229 ++++linux-user/syscall.c| 2 +-linux-user/syscall_defs.h| 40 +-poison.h| 1 + target-openrisc/Makefile.objs | 4 +target-openrisc/cpu.c | 240 +++++ target-openrisc/cpu.h | 445 ++++++++ target-openrisc/excp.c | 27 + target-openrisc/excp.h | 28 +target-openrisc/excp_helper.c | 27 +
target-openrisc/fpu_helper.c | 275 +++++
target-openrisc/helper.h | 69 ++
target-openrisc/int_helper.c | 51 +
target-openrisc/intrpt.c | 74 ++
target-openrisc/intrpt_helper.c | 52 +
target-openrisc/machine.c | 50 +
target-openrisc/mmu.c | 236 ++++target-openrisc/mmu_helper.c | 63 ++ target-openrisc/sys_helper.c | 233 ++++ target-openrisc/translate.c | 2036 +++++++++++++++++++++++++++++++++++ tests/tcg/openrisc/Makefile | 71 ++ tests/tcg/openrisc/test_add.c | 34 + tests/tcg/openrisc/test_addc.c | 39 + tests/tcg/openrisc/test_addi.c | 31 + tests/tcg/openrisc/test_addic.c | 33 + tests/tcg/openrisc/test_and_or.c | 61 ++ tests/tcg/openrisc/test_bf.c | 46 + tests/tcg/openrisc/test_bnf.c | 50 + tests/tcg/openrisc/test_div.c | 32 + tests/tcg/openrisc/test_divu.c | 32 + tests/tcg/openrisc/test_extx.c | 72 ++ tests/tcg/openrisc/test_fx.c | 53 + tests/tcg/openrisc/test_j.c | 26 + tests/tcg/openrisc/test_jal.c | 26 + tests/tcg/openrisc/test_lf_add.c | 39 + tests/tcg/openrisc/test_lf_div.c | 34 + tests/tcg/openrisc/test_lf_eqs.c | 84 ++ tests/tcg/openrisc/test_lf_ges.c | 84 ++ tests/tcg/openrisc/test_lf_gts.c | 84 ++ tests/tcg/openrisc/test_lf_les.c | 84 ++ tests/tcg/openrisc/test_lf_lts.c | 91 ++ tests/tcg/openrisc/test_lf_mul.c | 22 + tests/tcg/openrisc/test_lf_nes.c | 87 ++ tests/tcg/openrisc/test_lf_rem.c | 32 + tests/tcg/openrisc/test_lf_sub.c | 33 + tests/tcg/openrisc/test_logic.c | 100 ++ tests/tcg/openrisc/test_lx.c | 78 ++ tests/tcg/openrisc/test_movhi.c | 30 + tests/tcg/openrisc/test_mul.c | 47 + tests/tcg/openrisc/test_muli.c | 47 + tests/tcg/openrisc/test_mulu.c | 47 + tests/tcg/openrisc/test_sfeq.c | 44 + tests/tcg/openrisc/test_sfeqi.c | 39 + tests/tcg/openrisc/test_sfges.c | 44 + tests/tcg/openrisc/test_sfgesi.c | 40 + tests/tcg/openrisc/test_sfgeu.c | 44 + tests/tcg/openrisc/test_sfgeui.c | 41 + tests/tcg/openrisc/test_sfgts.c | 45 + tests/tcg/openrisc/test_sfgtsi.c | 41 + tests/tcg/openrisc/test_sfgtu.c | 43 + tests/tcg/openrisc/test_sfgtui.c | 42 + tests/tcg/openrisc/test_sfles.c | 26 + tests/tcg/openrisc/test_sflesi.c | 39 + tests/tcg/openrisc/test_sfleu.c | 43 + tests/tcg/openrisc/test_sfleui.c | 39 + tests/tcg/openrisc/test_sflts.c | 43 + tests/tcg/openrisc/test_sfltsi.c | 38 + tests/tcg/openrisc/test_sfltu.c | 41 + tests/tcg/openrisc/test_sfltui.c | 39 + tests/tcg/openrisc/test_sfne.c | 43 + tests/tcg/openrisc/test_sfnei.c | 38 + tests/tcg/openrisc/test_sub.c | 34 + 91 files changed, 8168 insertions(+), 6 deletions(-)create mode 100644 default-configs/or32-linux-user.mak create mode 100644 default-configs/or32-softmmu.mak create mode 100644 hw/openrisc/Makefile.objs create mode 100644
hw/openrisc_cpudev.hcreate mode 100644hw/openrisc_pic.c
create mode 100644hw/openrisc_sim.c
create mode 100644hw/openrisc_timer.c
create mode 100644linux-user/openrisc/syscall.hcreate mode 100644linux-user/openrisc/syscall_nr.hcreate mode 100644linux-user/openrisc/target_signal.hcreate mode 100644linux-user/openrisc/termbits.hcreate mode 100644 target-openrisc/Makefile.objs create mode 100644target-openrisc/cpu.ccreate mode 100644target-openrisc/cpu.hcreate mode 100644target-openrisc/excp.ccreate mode 100644target-openrisc/excp.hcreate mode 100644target-openrisc/excp_helper.ccreate mode 100644target-openrisc/fpu_helper.ccreate mode 100644target-openrisc/helper.hcreate mode 100644target-openrisc/int_helper.ccreate mode 100644target-openrisc/intrpt.ccreate mode 100644target-openrisc/intrpt_helper.ccreate mode 100644target-openrisc/machine.ccreate mode 100644target-openrisc/mmu.ccreate mode 100644target-openrisc/mmu_helper.ccreate mode 100644target-openrisc/sys_helper.ccreate mode 100644target-openrisc/translate.ccreate mode 100644 tests/tcg/openrisc/Makefile create mode 100644tests/tcg/openrisc/test_add.ccreate mode 100644tests/tcg/openrisc/test_addc.ccreate mode 100644tests/tcg/openrisc/test_addi.ccreate mode 100644tests/tcg/openrisc/test_addic.ccreate mode 100644tests/tcg/openrisc/test_and_or.ccreate mode 100644tests/tcg/openrisc/test_bf.ccreate mode 100644tests/tcg/openrisc/test_bnf.ccreate mode 100644tests/tcg/openrisc/test_div.ccreate mode 100644tests/tcg/openrisc/test_divu.ccreate mode 100644tests/tcg/openrisc/test_extx.ccreate mode 100644tests/tcg/openrisc/test_fx.ccreate mode 100644tests/tcg/openrisc/test_j.ccreate mode 100644tests/tcg/openrisc/test_jal.ccreate mode 100644tests/tcg/openrisc/test_lf_add.ccreate mode 100644tests/tcg/openrisc/test_lf_div.ccreate mode 100644tests/tcg/openrisc/test_lf_eqs.ccreate mode 100644tests/tcg/openrisc/test_lf_ges.ccreate mode 100644tests/tcg/openrisc/test_lf_gts.ccreate mode 100644tests/tcg/openrisc/test_lf_les.ccreate mode 100644tests/tcg/openrisc/test_lf_lts.ccreate mode 100644tests/tcg/openrisc/test_lf_mul.ccreate mode 100644tests/tcg/openrisc/test_lf_nes.ccreate mode 100644tests/tcg/openrisc/test_lf_rem.ccreate mode 100644tests/tcg/openrisc/test_lf_sub.ccreate mode 100644tests/tcg/openrisc/test_logic.ccreate mode 100644tests/tcg/openrisc/test_lx.ccreate mode 100644tests/tcg/openrisc/test_movhi.ccreate mode 100644tests/tcg/openrisc/test_mul.ccreate mode 100644tests/tcg/openrisc/test_muli.ccreate mode 100644tests/tcg/openrisc/test_mulu.ccreate mode 100644tests/tcg/openrisc/test_sfeq.ccreate mode 100644tests/tcg/openrisc/test_sfeqi.ccreate mode 100644tests/tcg/openrisc/test_sfges.ccreate mode 100644tests/tcg/openrisc/test_sfgesi.ccreate mode 100644tests/tcg/openrisc/test_sfgeu.ccreate mode 100644tests/tcg/openrisc/test_sfgeui.ccreate mode 100644tests/tcg/openrisc/test_sfgts.ccreate mode 100644tests/tcg/openrisc/test_sfgtsi.ccreate mode 100644tests/tcg/openrisc/test_sfgtu.ccreate mode 100644tests/tcg/openrisc/test_sfgtui.ccreate mode 100644tests/tcg/openrisc/test_sfles.ccreate mode 100644tests/tcg/openrisc/test_sflesi.ccreate mode 100644tests/tcg/openrisc/test_sfleu.ccreate mode 100644tests/tcg/openrisc/test_sfleui.ccreate mode 100644tests/tcg/openrisc/test_sflts.ccreate mode 100644tests/tcg/openrisc/test_sfltsi.ccreate mode 100644tests/tcg/openrisc/test_sfltu.ccreate mode 100644tests/tcg/openrisc/test_sfltui.ccreate mode 100644tests/tcg/openrisc/test_sfne.ccreate mode 100644tests/tcg/openrisc/test_sfnei.ccreate mode 100644tests/tcg/openrisc/test_sub.c--
1.7.9.5
Re: [Qemu-devel] [PATCH v5 12/16] target-or32: Add system instructions
In reply to Blue SwirlHi Blue,
Thank you for review.
Is this code OK?
void HELPER(mtspr)(CPUOpenRISCState * env,
target_ulong ra, target_ulong rb, target_ulong offset)
{
#ifndef CONFIG_USER_ONLY
int spr = (ra | offset);
int idx;
switch (spr) {
case TO_SPR(0, 0): /* VR */
env->vr = rb;
break;
case TO_SPR(0, 16): /* NPC */
env->npc = rb;
break;
case TO_SPR(0, 17): /* SR */
if ((env->sr & (SR_IME | SR_DME | SR_SM)) ^
(rb & (SR_IME | SR_DME | SR_SM))) {
tlb_flush(env, 1);
}
env->sr = rb;
env->sr |= SR_FO; /* FO is const equal to 1 */
if (env->sr & SR_DME) {
env->tlb->map_address_data = &get_phys_data;
} else {
env->tlb->map_address_data = &get_phys_nommu;
}
if (env->sr & SR_IME) {
env->tlb->map_address_code = &get_phys_code;
} else {
env->tlb->map_address_code = &get_phys_nommu;
}
break;
case TO_SPR(0, 18): /* PPC */
env->ppc = rb;
break;
case TO_SPR(0, 32): /* EPCR */
env->epcr = rb;
break;
case TO_SPR(0, 48): /* EEAR */
env->eear = rb;
break;
case TO_SPR(0, 64): /* ESR */
env->esr = rb;
break;
case TO_SPR(1, 512) ... TO_SPR(1, 639): /* DTLBW0MR 0-127 */
idx = spr - TO_SPR(1, 512);
if (!(rb & 1)) {
tlb_flush_page(env, env->tlb->dtlb[0][idx].mr & TARGET_PAGE_MASK);
}
env->tlb->dtlb[0][idx].mr = rb;
break;
case TO_SPR(1, 640) ... TO_SPR(1, 767): /* DTLBW0TR 0-127 */
idx = spr - TO_SPR(1, 640);
env->tlb->dtlb[0][idx].tr = rb;
break;
case TO_SPR(1, 768) ... TO_SPR(1, 895): /* DTLBW1MR 0-127 */
case TO_SPR(1, 896) ... TO_SPR(1, 1023): /* DTLBW1TR 0-127 */
case TO_SPR(1, 1024) ... TO_SPR(1, 1151): /* DTLBW2MR 0-127 */
case TO_SPR(1, 1152) ... TO_SPR(1, 1279): /* DTLBW2TR 0-127 */
case TO_SPR(1, 1280) ... TO_SPR(1, 1407): /* DTLBW3MR 0-127 */
case TO_SPR(1, 1408) ... TO_SPR(1, 1535): /* DTLBW3TR 0-127 */
break;
case TO_SPR(2, 512) ... TO_SPR(2, 639): /* ITLBW0MR 0-127 */
idx = spr - TO_SPR(2, 512);
if (!(rb & 1)) {
tlb_flush_page(env, env->tlb->itlb[0][idx].mr & TARGET_PAGE_MASK);
}
env->tlb->itlb[0][idx].mr = rb;
break;
case TO_SPR(2, 640) ... TO_SPR(2, 767): /* ITLBW0TR 0-127 */
idx = spr - TO_SPR(2, 640);
env->tlb->itlb[0][idx].tr = rb;
break;
case TO_SPR(2, 768) ... TO_SPR(2, 895): /* ITLBW1MR 0-127 */
case TO_SPR(2, 896) ... TO_SPR(2, 1023): /* ITLBW1TR 0-127 */
case TO_SPR(2, 1024) ... TO_SPR(2, 1151): /* ITLBW2MR 0-127 */
case TO_SPR(2, 1152) ... TO_SPR(2, 1279): /* ITLBW2TR 0-127 */
case TO_SPR(2, 1280) ... TO_SPR(2, 1407): /* ITLBW3MR 0-127 */
case TO_SPR(2, 1408) ... TO_SPR(2, 1535): /* ITLBW3TR 0-127 */
break;
case TO_SPR(9, 0): /* PICMR */
cpu_openrisc_store_picmr(env, rb);
break;
case TO_SPR(9, 2): /* PICSR */
cpu_openrisc_store_picsr(env, rb);
break;
case TO_SPR(10, 0): /* TTMR */
cpu_openrisc_store_compare(env, rb);
break;
case TO_SPR(10, 1): /* TTCR */
cpu_openrisc_store_count(env, rb);
break;
default:
break;
}#endif
}
target_ulong HELPER(mfspr)(CPUOpenRISCState * env,
target_ulong rd, target_ulong ra, uint32_t offset)
{
#ifndef CONFIG_USER_ONLY
int spr = (ra | offset);
int idx;
switch (spr) {
case TO_SPR(0, 0): /* VR */
return (env->vr & SPR_VR);
case TO_SPR(0, 1): /* UPR */
return (env->upr); /* TT, DM, IM, UP present */
case TO_SPR(0, 2): /* CPUCFGR */
return (env->cpucfgr);
case TO_SPR(0, 3): /* DMMUCFGR */
return (env->dmmucfgr); /* 1Way, 64 entries */
case TO_SPR(0, 4): /* IMMUCFGR */
return (env->immucfgr);
case TO_SPR(0, 16): /* NPC */
return (env->npc);
case TO_SPR(0, 17): /* SR */
return (env->sr);
case TO_SPR(0, 18): /* PPC */
return (env->ppc);
case TO_SPR(0, 32): /* EPCR */
return (env->epcr);
case TO_SPR(0, 48): /* EEAR */
return (env->eear);
case TO_SPR(0, 64): /* ESR */
return (env->esr);
case TO_SPR(1, 512) ... TO_SPR(1, 639): /* DTLBW0MR 0-127 */
idx = spr - TO_SPR(1, 512);
return (env->tlb->dtlb[0][idx].mr);
case TO_SPR(1, 640) ... TO_SPR(1, 767): /* DTLBW0TR 0-127 */
idx = spr - TO_SPR(1, 640);
return (env->tlb->dtlb[0][idx].tr);
case TO_SPR(1, 768) ... TO_SPR(1, 895): /* DTLBW1MR 0-127 */
case TO_SPR(1, 896) ... TO_SPR(1, 1023): /* DTLBW1TR 0-127 */
case TO_SPR(1, 1024) ... TO_SPR(1, 1151): /* DTLBW2MR 0-127 */
case TO_SPR(1, 1152) ... TO_SPR(1, 1279): /* DTLBW2TR 0-127 */
case TO_SPR(1, 1280) ... TO_SPR(1, 1407): /* DTLBW3MR 0-127 */
case TO_SPR(1, 1408) ... TO_SPR(1, 1535): /* DTLBW3TR 0-127 */
break;
case TO_SPR(2, 512) ... TO_SPR(2, 639): /* ITLBW0MR 0-127 */
idx = spr - TO_SPR(2, 512);
return (env->tlb->itlb[0][idx].mr);
case TO_SPR(2, 640) ... TO_SPR(2, 767): /* ITLBW0TR 0-127 */
idx = spr - TO_SPR(2, 640);
return (env->tlb->itlb[0][idx].tr);
case TO_SPR(2, 768) ... TO_SPR(2, 895): /* ITLBW1MR 0-127 */
case TO_SPR(2, 896) ... TO_SPR(2, 1023): /* ITLBW1TR 0-127 */
case TO_SPR(2, 1024) ... TO_SPR(2, 1151): /* ITLBW2MR 0-127 */
case TO_SPR(2, 1152) ... TO_SPR(2, 1279): /* ITLBW2TR 0-127 */
case TO_SPR(2, 1280) ... TO_SPR(2, 1407): /* ITLBW3MR 0-127 */
case TO_SPR(2, 1408) ... TO_SPR(2, 1535): /* ITLBW3TR 0-127 */
break;
case TO_SPR(9, 0): /* PICMR */
return (env->picmr);
case TO_SPR(9, 2): /* PICSR */
return (env->picsr);
case TO_SPR(10, 0): /* TTMR */
return (env->ttmr);
case TO_SPR(10, 1): /* TTCR */
return cpu_openrisc_get_count(env);
default:
break;
}
#endif
return rd;
} case 0x2d: /*l.mfspr*/
LOG_DIS("l.mfspr r%d, r%d, %d\n", rd, ra, I16);
{
TCGv_i32 ti = tcg_const_i32(I16);
gen_helper_mfspr(cpu_R[rd], cpu_env, cpu_R[rd], cpu_R[ra], ti);
tcg_temp_free_i32(ti);
}
break;
case 0x30: /*l.mtspr*/
LOG_DIS("l.mtspr %d, r%d, r%d, %d\n", I5, ra, rb, I11);
{
TCGv_i32 im = tcg_const_i32(tmp);
gen_helper_mtspr(cpu_env, cpu_R[ra], cpu_R[rb], im);
tcg_temp_free_i32(im);
}
break;Quoted 327 lines · Blue Swirl
Quoted 167 lines · Jia Liu
Add OpenRISC system instruction support.
Signed-off-by Jia Liu <[email protected]>---
target-openrisc/Makefile.objs | 3 +-
target-openrisc/helper.h | 4 +target-openrisc/sys_helper.c| 233 +++++++++++++++++++++++++++++++++++++++++target-openrisc/translate.c| 20 ++++4 files changed, 259 insertions(+), 1 deletion(-)create mode 100644
target-openrisc/sys_helper.ctarget-openrisc/Makefile.objs +0
-0@@ -1,3 +1,4 @@obj-$(CONFIG_SOFTMMU) += machine.o
obj-y += cpu.o excp.o intrpt.o mmu.o translate.otarget-openrisc/Makefile.objs +2
-1-obj-y += excp_helper.o fpu_helper.o int_helper.o intrpt_helper.o mmu_helper.o +obj-y += excp_helper.o fpu_helper.o int_helper.o intrpt_helper.o \ + mmu_helper.o sys_helper.otarget-openrisc/helper.h +4
-0@@ -62,4 +62,8 @@ DEF_HELPER_FLAGS_1(fl1, 0, tl, tl) /* interrupt */ DEF_HELPER_FLAGS_1(rfe, 0, void, env) +/* sys */ +DEF_HELPER_FLAGS_4(mtspr, 0, void, env, tl, tl, tl) +DEF_HELPER_FLAGS_4(mfspr, 0, void, env, tl, tl, tl) + #include "def-helper.h"target-openrisc/sys_helper.c new file +127
-0@@ -0,0 +1,233 @@ +/* +* OpenRISC system instructions helper routines +* +* Copyright (c) 2011-2012 Jia Liu <[email protected]> +* Zhizhou Zhang <[email protected]> +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2 of the License, or (at your option) any later version. +* +* This library 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 +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, see <http://www.gnu.org/licenses/>. +*/ + +#include "cpu.h" +#include "helper.h" + +#define TO_SPR (group, number) (((group) << 11) + (number)) + +void HELPER (mtspr )(CPUOpenRISCState * env, + target_ulong ra, target_ulong rb, target_ulong offset) +{ +#if !defined(CONFIG_USER_ONLY ) + int spr = (ra | offset); + int idx; + + switch (spr) { + case TO_SPR(0, 0): /* VR */ + env->vr = rb; + break; + + case TO_SPR(0, 16): /* NPC */ + env->npc = rb; + break; + + case TO_SPR(0, 17): /* SR */ + if ((env->sr & (SR_IME | SR_DME | SR_SM)) ^ + (rb & (SR_IME | SR_DME | SR_SM))) { + tlb_flush(env, 1); + } + env->sr = rb; + env->sr |= SR_FO; /* FO is const equal to 1 */ + if (env->sr & SR_DME) { + env->tlb->map_address_data = &get_phys_data; + } else { + env->tlb->map_address_data = &get_phys_nommu; + } + + if (env->sr & SR_IME) { + env->tlb->map_address_code = &get_phys_code; + } else { + env->tlb->map_address_code = &get_phys_nommu; + } + break; + + case TO_SPR(0, 18): /* PPC */ + env->ppc = rb; + break; + + case TO_SPR(0, 32): /* EPCR */ + env->epcr = rb; + break; + + case TO_SPR(0, 48): /* EEAR */ + env->eear = rb; + break; + + case TO_SPR(0, 64): /* ESR */ + env->esr = rb; + break; + case TO_SPR(1, 512) ... TO_SPR(1, 639): /* DTLBW0MR 0-127 */ + idx = spr - TO_SPR(1, 512); + if (!(rb & 1)) { + tlb_flush_page(env, env->tlb->dtlb[0][idx].mr & TARGET_PAGE_MASK); + } + env->tlb->dtlb[0][idx].mr = rb; + break; + + case TO_SPR(1, 640) ... TO_SPR(1, 767): /* DTLBW0TR 0-127 */ + idx = spr - TO_SPR(1, 640); + env->tlb->dtlb[0][idx].tr = rb; + break; + case TO_SPR(1, 768) ... TO_SPR(1, 895): /* DTLBW1MR 0-127 */ + case TO_SPR(1, 896) ... TO_SPR(1, 1023): /* DTLBW1TR 0-127 */ + case TO_SPR(1, 1024) ... TO_SPR(1, 1151): /* DTLBW2MR 0-127 */ + case TO_SPR(1, 1152) ... TO_SPR(1, 1279): /* DTLBW2TR 0-127 */ + case TO_SPR(1, 1280) ... TO_SPR(1, 1407): /* DTLBW3MR 0-127 */ + case TO_SPR(1, 1408) ... TO_SPR(1, 1535): /* DTLBW3TR 0-127 */ + break; + case TO_SPR(2, 512) ... TO_SPR(2, 639): /* ITLBW0MR 0-127 */ + idx = spr - TO_SPR(2, 512); + if (!(rb & 1)) { + tlb_flush_page(env, env->tlb->itlb[0][idx].mr & TARGET_PAGE_MASK); + } + env->tlb->itlb[0][idx].mr = rb; + break; + + case TO_SPR(2, 640) ... TO_SPR(2, 767): /* ITLBW0TR 0-127 */ + idx = spr - TO_SPR(2, 640); + env->tlb->itlb[0][idx].tr = rb; + break; + case TO_SPR(2, 768) ... TO_SPR(2, 895): /* ITLBW1MR 0-127 */ + case TO_SPR(2, 896) ... TO_SPR(2, 1023): /* ITLBW1TR 0-127 */ + case TO_SPR(2, 1024) ... TO_SPR(2, 1151): /* ITLBW2MR 0-127 */ + case TO_SPR(2, 1152) ... TO_SPR(2, 1279): /* ITLBW2TR 0-127 */ + case TO_SPR(2, 1280) ... TO_SPR(2, 1407): /* ITLBW3MR 0-127 */ + case TO_SPR(2, 1408) ... TO_SPR(2, 1535): /* ITLBW3TR 0-127 */ + break; + case TO_SPR(9, 0): /* PICMR */ + cpu_openrisc_store_picmr(env, rb); + break; + case TO_SPR(9, 2): /* PICSR */ + cpu_openrisc_store_picsr(env, rb); + break; + case TO_SPR(10, 0): /* TTMR */ + cpu_openrisc_store_compare(env, rb); + break; + case TO_SPR(10, 1): /* TTCR */ + cpu_openrisc_store_count(env, rb); + break; + default:target-openrisc/sys_helper.c line 137
Quoted 10 lines
target-openrisc/sys_helper.c new file +10
-0+ break; + } +#endif +} + +void HELPER (mfspr )(CPUOpenRISCState * env, + target_ulong rd, target_ulong ra, uint32_t offset) +{ +#if !defined(CONFIG_USER_ONLY ) + int spr = env->gpr[ra] | offset;[1]
Quoted 80 lines
target-openrisc/sys_helper.c new file +80
-0+ int idx; + + switch (spr) { + case TO_SPR(0, 0): /* VR */ + env->gpr[rd] = (env->vr & SPR_VR); + break; + + case TO_SPR(0, 1): /* UPR */ + env->gpr[rd] = env->upr; /* TT, DM, IM, UP present */ + break; + + case TO_SPR(0, 2): /* CPUCFGR */ + env->gpr[rd] = env->cpucfgr; + break; + + case TO_SPR(0, 3): /* DMMUCFGR */ + env->gpr[rd] = env->dmmucfgr; /* 1Way, 64 entries */ + break; + case TO_SPR(0, 4): /* IMMUCFGR */ + env->gpr[rd] = env->immucfgr; + break; + + case TO_SPR(0, 16): /* NPC */ + env->gpr[rd] = env->npc; + break; + + case TO_SPR(0, 17): /* SR */ + env->gpr[rd] = env->sr; + break; + + case TO_SPR(0, 18): /* PPC */ + env->gpr[rd] = env->ppc; + break; + + case TO_SPR(0, 32): /* EPCR */ + env->gpr[rd] = env->epcr; + break; + + case TO_SPR(0, 48): /* EEAR */ + env->gpr[rd] = env->eear; + break; + + case TO_SPR(0, 64): /* ESR */ + env->gpr[rd] = env->esr; + break; + + case TO_SPR(1, 512) ... TO_SPR(1, 639): /* DTLBW0MR 0-127 */ + idx = spr - TO_SPR(1, 512); + env->gpr[rd] = env->tlb->dtlb[0][idx].mr; + break; + + case TO_SPR(1, 640) ... TO_SPR(1, 767): /* DTLBW0TR 0-127 */ + idx = spr - TO_SPR(1, 640); + env->gpr[rd] = env->tlb->dtlb[0][idx].tr; + break; + case TO_SPR(1, 768) ... TO_SPR(1, 895): /* DTLBW1MR 0-127 */ + case TO_SPR(1, 896) ... TO_SPR(1, 1023): /* DTLBW1TR 0-127 */ + case TO_SPR(1, 1024) ... TO_SPR(1, 1151): /* DTLBW2MR 0-127 */ + case TO_SPR(1, 1152) ... TO_SPR(1, 1279): /* DTLBW2TR 0-127 */ + case TO_SPR(1, 1280) ... TO_SPR(1, 1407): /* DTLBW3MR 0-127 */ + case TO_SPR(1, 1408) ... TO_SPR(1, 1535): /* DTLBW3TR 0-127 */ + break; + + case TO_SPR(2, 512) ... TO_SPR(2, 639): /* ITLBW0MR 0-127 */ + idx = spr - TO_SPR(2, 512); + env->gpr[rd] = env->tlb->itlb[0][idx].mr; + break; + + case TO_SPR(2, 640) ... TO_SPR(2, 767): /* ITLBW0TR 0-127 */ + idx = spr - TO_SPR(2, 640); + env->gpr[rd] = env->tlb->itlb[0][idx].tr; + break; + case TO_SPR(2, 768) ... TO_SPR(2, 895): /* ITLBW1MR 0-127 */ + case TO_SPR(2, 896) ... TO_SPR(2, 1023): /* ITLBW1TR 0-127 */ + case TO_SPR(2, 1024) ... TO_SPR(2, 1151): /* ITLBW2MR 0-127 */ + case TO_SPR(2, 1152) ... TO_SPR(2, 1279): /* ITLBW2TR 0-127 */ + case TO_SPR(2, 1280) ... TO_SPR(2, 1407): /* ITLBW3MR 0-127 */ + case TO_SPR(2, 1408) ... TO_SPR(2, 1535): /* ITLBW3TR 0-127 */ + break; + case TO_SPR(9, 0): /* PICMR */target-openrisc/sys_helper.c line 227
Quoted 10 lines
target-openrisc/sys_helper.c new file +10
-0+ env->gpr[rd] = env->picmr; + break; + case TO_SPR(9, 2): /* PICSR */ + env->gpr[rd] = env->picsr; + break; + case TO_SPR(10, 0): /* TTMR */ + env->gpr[rd] = env->ttmr; + break; + case TO_SPR(10, 1): /* TTCR */ + env->gpr[rd] = cpu_openrisc_get_count(env);[2]
Quoted 12 lines
target-openrisc/sys_helper.c new file +6
-0+ break; + default: + break; + } +#endif +}target-openrisc/translate.c +0
-0@@ -1241,10 +1241,30 @@ static void dec_misc(DisasContext *dc, CPUOpenRISCState *env, uint32_t insn)Quoted 7 lines
case
0x2d: /*l.mfspr*/
LOG_DIS("l.mfspr r%d, r%d, %d\n", rd, ra, I16);
+ {
+ TCGv_i32 ti =tcg_const_i32(I16);
+ TCGv td =tcg_const_tl(rd);
+ TCGv ta =tcg_const_tl(ra);
+ gen_helper_mfspr(cpu_env, td, ta, ti);The helper should a return
target_ulong, so the line would becomegen_helper_mfspr(cpu_R[rd], cpu_env, td, cpu_R[ra], ti);Then the register moves inside the mfspr helper could be avoided:
[1]Quoted 1 line
+ int spr = env->gpr[ra] | offset;
int spr = ra | offset;
As an example [2]:
Quoted 1 line
+ env->gpr[rd] =
cpu_openrisc_get_count(env);return
cpu_openrisc_get_count(env);Quoted 4 lines
+ tcg_temp_free_i32(ti);
+ tcg_temp_free(td);
+ tcg_temp_free(ta);
+ }Also here you could try later to avoid to compile
sys_helper.cfor user emulator by surrounding the previous block by #ifndef CONFIG_USER_ONLY/#endif (ditto for mtspr).Quoted 11 lines
break;
case
0x30: /*l.mtspr*/
LOG_DIS("l.mtspr %d, r%d, r%d, %d\n", I5, ra, rb, I11);
+ {
+ TCGv_i32 im =tcg_const_i32(tmp);
+ TCGv ta =tcg_temp_new();
+ TCGv tb =tcg_temp_new();
+ tcg_gen_mov_tl(ta, cpu_R[ra]);
+ tcg_gen_mov_tl(tb, cpu_R[rb]);
+ gen_helper_mtspr(cpu_env, ta, tb, im);
Quoted 14 lines
Simply
gen_helper_mtspr(cpu_env, cpu_R[ra], cpu_R[rb], im);Quoted 11 lines
+ tcg_temp_free_i32(im);
+ tcg_temp_free(ta);
+ tcg_temp_free(tb);
+ }
break;case
0x34: /*l.sd*/
--
1.7.9.5
Regards,
Jia.
Re: [Qemu-devel] [PATCH v5 08/16] target-or32: Add translation routines
In reply to Blue SwirlHi Blue,
Thanks.
Quoted 342 lines · Blue Swirl
Quoted 341 lines · Jia Liu
Add OpenRISC translation routines.
Signed-off-by Jia Liu <[email protected]>---
target-openrisc/translate.c | 1941 +++++++++++++++++++++++++++++++++++++++++++1 file changed, 1941 insertions(+)target-openrisc/translate.c +317
-0@@ -26,6 +26,10 @@ #include "qemu-log.h" #include "config.h" +#include "helper.h" +#define GEN_HELPER 1 +#include "helper.h" + #define OPENRISC_DISAS #ifdef OPENRISC_DISAS@@ -34,14 +38,1951 @@ # define LOG_DIS(...) do { } while (0) #endif +typedef struct DisasContext { + CPUOpenRISCState *env; + TranslationBlock *tb; + target_ulong pc, ppc, npc; + uint32_t tb_flags, synced_flags, flags; + uint32_t is_jmp; + uint32_t mem_idx; + int singlestep_enabled; + uint32_t delayed_branch; +}DisasContext ; + +static TCGv_ptr cpu_env; +static TCGv cpu_sr; +static TCGv cpu_R[32 ]; +static TCGv cpu_pc; +static TCGv jmp_pc; /* l.jr/l.jalr temp pc */ +static TCGv cpu_npc; +static TCGv cpu_ppc; +static TCGv_i32 env_btaken; /* bf/bnf , F flag taken */ +static TCGv_i32 fpcsr; +static TCGv machi, maclo; +static TCGv fpmaddhi, fpmaddlo; +static TCGv_i32 env_flags; +#include "gen-icount.h" + void openrisc_translate_init(void) { + static const char * const regnames[] = { + "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", + "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", + "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23", + "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31", + }; + int i; + + cpu_env = tcg_global_reg_new_ptr(TCG_AREG0, "env"); + cpu_sr = tcg_global_mem_new(TCG_AREG0, + offsetof(CPUOpenRISCState, sr), "sr"); + env_flags = tcg_global_mem_new_i32(TCG_AREG0, + offsetof(CPUOpenRISCState, flags), + "flags"); + cpu_pc = tcg_global_mem_new(TCG_AREG0, + offsetof(CPUOpenRISCState, pc), "pc"); + cpu_npc = tcg_global_mem_new(TCG_AREG0, + offsetof(CPUOpenRISCState, npc), "npc"); + cpu_ppc = tcg_global_mem_new(TCG_AREG0, + offsetof(CPUOpenRISCState, ppc), "ppc"); + jmp_pc = tcg_global_mem_new(TCG_AREG0, + offsetof(CPUOpenRISCState, jmp_pc), "jmp_pc"); + env_btaken = tcg_global_mem_new_i32(TCG_AREG0, + offsetof(CPUOpenRISCState, btaken), + "btaken"); + fpcsr = tcg_global_mem_new_i32(TCG_AREG0, + offsetof(CPUOpenRISCState, fpcsr), + "fpcsr"); + machi = tcg_global_mem_new(TCG_AREG0, + offsetof(CPUOpenRISCState, machi), + "machi"); + maclo = tcg_global_mem_new(TCG_AREG0, + offsetof(CPUOpenRISCState, maclo), + "maclo"); + fpmaddhi = tcg_global_mem_new(TCG_AREG0, + offsetof(CPUOpenRISCState, fpmaddhi), + "fpmaddhi"); + fpmaddlo = tcg_global_mem_new(TCG_AREG0, + offsetof(CPUOpenRISCState, fpmaddlo), + "fpmaddlo"); + for (i = 0; i < 32; i++) { + cpu_R[i] = tcg_global_mem_new(TCG_AREG0, + offsetof(CPUOpenRISCState, gpr[i]), + regnames[i]); + } +#define GEN_HELPER 2 +#include "helper.h" +} + +/* Writeback SR_F transaltion-space to execution-space. */ +static inline void wb_SR_F (void ) +{ + int label; + + label = gen_new_label(); + tcg_gen_andi_tl(cpu_sr, cpu_sr, ~SR_F); + tcg_gen_brcondi_tl(TCG_COND_EQ, env_btaken, 0, label); + tcg_gen_ori_tl(cpu_sr, cpu_sr, SR_F); + gen_set_label(label); +} + +static inline int zero_extend (unsigned int val,int width) +{ + return val & ((1 << width) - 1); +} + +static inline int sign_extend (unsigned int val,int width) +{ + int sval; + + /* LSL */ + val <<= TARGET_LONG_BITS - width; + sval = val; + /* ASR. */ + sval >>= TARGET_LONG_BITS - width; + return sval; +} + +static inline void gen_sync_flags (DisasContext *dc) +{ + /* Sync the tb dependent flag between translate and runtime. */ + if (dc->tb_flags != dc->synced_flags) { + tcg_gen_movi_tl(env_flags, dc->tb_flags); + dc->synced_flags = dc->tb_flags; + } +} + +static void gen_exception (DisasContext *dc,unsigned int excp) +{ + TCGv_i32 tmp = tcg_const_i32(excp); + gen_helper_exception(cpu_env, tmp); + tcg_temp_free_i32(tmp); +} + +static void gen_illegal_exception (DisasContext *dc) +{ + tcg_gen_movi_tl(cpu_pc, dc->pc); + gen_exception(dc, EXCP_ILLEGAL); + dc->is_jmp = DISAS_UPDATE; +} + +#ifdef TARGET_OPENRISC64 +static void check_ob64s (DisasContext *dc) +{ + if (!(dc->flags & CPUCFGR_OB64S)) { + gen_illegal_exception(dc); + } +} + +static void check_of64s (DisasContext *dc) +{ + if (!(dc->flags & CPUCFGR_OF64S)) { + gen_illegal_exception(dc); + } +} + +/* not used yet, open it when we need or64. */ +/*static void check_ov64s(DisasContext *dc) +{ +if (!(dc->flags & CPUCFGR_OV64S)) { +gen_illegal_exception(dc); +} +}*/ +#endif + +static void gen_goto_tb (DisasContext *dc,int n,target_ulong dest) +{ + TranslationBlock *tb; + tb = dc->tb; + if ((tb->pc & TARGET_PAGE_MASK) == (dest & TARGET_PAGE_MASK) && + likely(!dc->singlestep_enabled)) { + tcg_gen_movi_tl(cpu_pc, dest); + tcg_gen_goto_tb(n); + tcg_gen_exit_tb((tcg_target_long)tb + n); + } else { + tcg_gen_movi_tl(cpu_pc, dest); + if (dc->singlestep_enabled) { + gen_exception(dc, EXCP_DEBUG); + } + tcg_gen_exit_tb(0); + } +} + +static void gen_jump (DisasContext *dc,uint32_t imm,uint32_t reg,uint32_t op0) +{ + target_ulong tmp_pc; + int lab = gen_new_label(); + TCGv sr_f = tcg_temp_new(); + /* N26, 26bits imm */ + tmp_pc = sign_extend((imm<<2), 26) + dc->pc; + tcg_gen_andi_tl(sr_f, cpu_sr, SR_F); + + if (op0 == 0x00) { /*l.j*/ + tcg_gen_movi_tl(jmp_pc, tmp_pc); + } else if (op0 == 0x01) { /*l.jal*/ + tcg_gen_movi_tl(cpu_R[9], (dc->pc + 8)); + tcg_gen_movi_tl(jmp_pc, tmp_pc); + } else if (op0 == 0x03) { /*l.bnf*/ + tcg_gen_movi_tl(jmp_pc, dc->pc+8); + tcg_gen_brcondi_i32(TCG_COND_EQ, sr_f, SR_F, lab); + tcg_gen_movi_tl(jmp_pc, tmp_pc); + gen_set_label(lab); + } else if (op0 == 0x04) { /*l.bf*/ + tcg_gen_movi_tl(jmp_pc, dc->pc+8); + tcg_gen_brcondi_i32(TCG_COND_NE, sr_f, SR_F, lab); + tcg_gen_movi_tl(jmp_pc, tmp_pc); + gen_set_label(lab); + } else if (op0 == 0x11) { /*l.jr*/ + tcg_gen_mov_tl(jmp_pc, cpu_R[reg]); + } else if (op0 == 0x12) { /*l.jalr*/ + tcg_gen_movi_tl(cpu_R[9], (dc->pc + 8)); + tcg_gen_mov_tl(jmp_pc, cpu_R[reg]); + } else { + gen_illegal_exception(dc); + } + + tcg_temp_free(sr_f); + dc->delayed_branch = 2; + dc->tb_flags |= D_FLAG; + gen_sync_flags(dc); +} + +static inline uint32_t field (uint32_t val,int start,int length) +{ + val >>= start; + val &= ~(~0 << length); + return val; +} + +static void dec_calc (DisasContext *dc,CPUOpenRISCState *env,uint32_t insn) +{ + uint32_t op0, op1, op2; + uint32_t ra, rb, rd; + op0 = field(insn, 0, 4); + op1 = field(insn, 8, 2); + op2 = field(insn, 6, 2); + ra = field(insn, 16, 5); + rb = field(insn, 11, 5); + rd = field(insn, 21, 5); + + switch (op0) { + case 0x0000: + switch (op1) { + case 0x00: /*l.add*/ + LOG_DIS("l.add r%d, r%d, r%d\n", rd, ra, rb); + { + int lab = gen_new_label(); + TCGv_i64 ta = tcg_temp_new_i64(); + TCGv_i64 tb = tcg_temp_new_i64(); + TCGv_i64 td = tcg_temp_local_new_i64(); + TCGv_i32 res = tcg_temp_local_new_i32(); + TCGv_i32 sr_ove = tcg_temp_local_new_i32(); + tcg_gen_extu_i32_i64(ta, cpu_R[ra]); + tcg_gen_extu_i32_i64(tb, cpu_R[rb]); + tcg_gen_add_i64(td, ta, tb); + tcg_gen_trunc_i64_i32(res, td); + tcg_gen_shri_i64(td, td, 31); + tcg_gen_andi_i64(td, td, 0x3); + /* Jump to lab when no overflow. */ + tcg_gen_brcondi_i64(TCG_COND_EQ, td, 0x0, lab); + tcg_gen_brcondi_i64(TCG_COND_EQ, td, 0x3, lab); + tcg_gen_ori_i32(cpu_sr, cpu_sr, (SR_OV | SR_CY)); + tcg_gen_andi_i32(sr_ove, cpu_sr, SR_OVE); + tcg_gen_brcondi_i32(TCG_COND_NE, sr_ove, SR_OVE, lab); + gen_exception(dc, EXCP_RANGE); + gen_set_label(lab); + tcg_gen_mov_i32(cpu_R[rd], res); + tcg_temp_free_i64(ta); + tcg_temp_free_i64(tb); + tcg_temp_free_i64(td); + tcg_temp_free_i32(res); + tcg_temp_free_i32(sr_ove); + } + break; + default: + gen_illegal_exception(dc); + break; + } + break; + + case 0x0001: /*l.addc*/ + switch (op1) { + case 0x00: + LOG_DIS("l.addc r%d, r%d, r%d\n", rd, ra, rb); + { + int lab = gen_new_label(); + TCGv_i64 ta = tcg_temp_new_i64(); + TCGv_i64 tb = tcg_temp_new_i64(); + TCGv_i64 tcy = tcg_temp_local_new_i64(); + TCGv_i64 td = tcg_temp_local_new_i64(); + TCGv_i32 res = tcg_temp_local_new_i32(); + TCGv_i32 sr_cy = tcg_temp_local_new_i32(); + TCGv_i32 sr_ove = tcg_temp_local_new_i32(); + tcg_gen_extu_i32_i64(ta, cpu_R[ra]); + tcg_gen_extu_i32_i64(tb, cpu_R[rb]); + tcg_gen_andi_i32(sr_cy, cpu_sr, SR_CY); + tcg_gen_extu_i32_i64(tcy, sr_cy); + tcg_gen_shri_i64(tcy, tcy, 10); + tcg_gen_add_i64(td, ta, tb); + tcg_gen_add_i64(td, td, tcy); + tcg_gen_trunc_i64_i32(res, td); + tcg_gen_shri_i64(td, td, 32); + tcg_gen_andi_i64(td, td, 0x3); + /* Jump to lab when no overflow. */ + tcg_gen_brcondi_i64(TCG_COND_EQ, td, 0x0, lab); + tcg_gen_brcondi_i64(TCG_COND_EQ, td, 0x3, lab); + tcg_gen_ori_i32(cpu_sr, cpu_sr, (SR_OV | SR_CY)); + tcg_gen_andi_i32(sr_ove, cpu_sr, SR_OVE); + tcg_gen_brcondi_i32(TCG_COND_NE, sr_ove, SR_OVE, lab); + gen_exception(dc, EXCP_RANGE); + gen_set_label(lab); + tcg_gen_mov_i32(cpu_R[rd], res); + tcg_temp_free_i64(ta); + tcg_temp_free_i64(tb); + tcg_temp_free_i64(tcy); + tcg_temp_free_i64(td); + tcg_temp_free_i32(res); + tcg_temp_free_i32(sr_cy); + tcg_temp_free_i32(sr_ove); + } + break; + default: + gen_illegal_exception(dc); + break; + } + break; + + case 0x0002: /*l.sub*/
Quoted 8 lines
target-openrisc/translate.c line 362
Quoted 7 lines
target-openrisc/translate.c +7
-0+ switch (op1) { + case 0x00: + LOG_DIS("l.sub r%d, r%d, r%d\n", rd, ra, rb); + { + + +Please trim the above lines.
done.
Quoted 11 lines
target-openrisc/translate.c line 279
Quoted 7 lines
target-openrisc/translate.c +6
-0+ int lab = gen_new_label(); + TCGv_i64 ta = tcg_temp_new_i64(); + TCGv_i64 tb = tcg_temp_new_i64(); + TCGv_i64 td = tcg_temp_local_new_i64(); + TCGv_i32 res = tcg_temp_local_new_i32(); + TCGv_i32 sr_ove = tcg_temp_local_new_i32();It's usual to put an empty line between variable declarations and code for clarity.
added.
Quoted 201 lines
Quoted 106 lines
target-openrisc/translate.c +106
-0+ tcg_gen_extu_i32_i64(ta, cpu_R[ra]); + tcg_gen_extu_i32_i64(tb, cpu_R[rb]); + tcg_gen_sub_i64(td, ta, tb); + tcg_gen_trunc_i64_i32(res, td); + tcg_gen_shri_i64(td, td, 31); + tcg_gen_andi_i64(td, td, 0x3); + /* Jump to lab when no overflow. */ + tcg_gen_brcondi_i64(TCG_COND_EQ, td, 0x0, lab); + tcg_gen_brcondi_i64(TCG_COND_EQ, td, 0x3, lab); + tcg_gen_ori_i32(cpu_sr, cpu_sr, (SR_OV | SR_CY)); + tcg_gen_andi_i32(sr_ove, cpu_sr, SR_OVE); + tcg_gen_brcondi_i32(TCG_COND_NE, sr_ove, SR_OVE, lab); + gen_exception(dc, EXCP_RANGE); + gen_set_label(lab); + tcg_gen_mov_i32(cpu_R[rd], res); + tcg_temp_free_i64(ta); + tcg_temp_free_i64(tb); + tcg_temp_free_i64(td); + tcg_temp_free_i32(res); + tcg_temp_free_i32(sr_ove); + } + break; + default: + gen_illegal_exception(dc); + break; + } + break; + + case 0x0003: /*l.and*/ + switch (op1) { + case 0x00: + LOG_DIS("l.and r%d, r%d, r%d\n", rd, ra, rb); + tcg_gen_and_tl(cpu_R[rd], cpu_R[ra], cpu_R[rb]); + break; + default: + gen_illegal_exception(dc); + break; + } + break; + + case 0x0004: /*l.or*/ + switch (op1) { + case 0x00: + LOG_DIS("l.or r%d, r%d, r%d\n", rd, ra, rb); + tcg_gen_or_tl(cpu_R[rd], cpu_R[ra], cpu_R[rb]); + break; + default: + gen_illegal_exception(dc); + break; + } + break; + + case 0x0005: + switch (op1) { + case 0x00: /*l.xor*/ + LOG_DIS("l.xor r%d, r%d, r%d\n", rd, ra, rb); + tcg_gen_xor_tl(cpu_R[rd], cpu_R[ra], cpu_R[rb]); + break; + default: + gen_illegal_exception(dc); + break; + } + break; + + case 0x0006: + switch (op1) { + case 0x03: /*l.mul*/ + LOG_DIS("l.mul r%d, r%d, r%d\n", rd, ra, rb); + { + if (ra != 0 && rb != 0) { + int lab1 = gen_new_label(); + int lab2 = gen_new_label(); + int lab3 = gen_new_label(); + TCGv_i64 tmp0 = tcg_temp_local_new_i64(); + TCGv_i64 tmp1 = tcg_temp_local_new_i64(); + TCGv_i64 t0 = tcg_temp_local_new_i64(); + TCGv_i32 res = tcg_temp_local_new_i32(); + TCGv_i32 rs = tcg_temp_local_new_i32(); + TCGv_i32 rt = tcg_temp_local_new_i32(); + TCGv_i32 sr_ove = tcg_temp_local_new_i32(); + /* Calculate the result. */ + tcg_gen_extu_i32_i64(tmp0, cpu_R[ra]); + tcg_gen_extu_i32_i64(tmp1, cpu_R[rb]); + tcg_gen_mul_i64(t0, tmp0, tmp1); + tcg_gen_trunc_i64_i32(res, t0); + tcg_gen_shri_i32(rs, res, 31); + tcg_gen_andi_i32(rs, rs, 0x1); + tcg_gen_shri_i64(t0, t0, 32); + tcg_gen_trunc_i64_i32(rt, t0); + /* Overflow or not. */ + tcg_gen_brcondi_i32(TCG_COND_EQ, rs, 0x1, lab1); + tcg_gen_brcondi_i32(TCG_COND_EQ, rt, 0x0, lab2); + tcg_gen_brcondi_i32(TCG_COND_NE, rt, 0x0, lab3); + gen_set_label(lab1); + tcg_gen_brcondi_i32(TCG_COND_EQ, rt, 0xffffffff, lab2); + /* Handle overflow exception. */ + gen_set_label(lab3); + tcg_gen_ori_tl(cpu_sr, cpu_sr, SR_OV); + tcg_gen_ori_tl(cpu_sr, cpu_sr, SR_CY); + tcg_gen_andi_tl(sr_ove, cpu_sr, SR_OVE); + tcg_gen_brcondi_i32(TCG_COND_NE, sr_ove, SR_OVE, lab2); + gen_exception(dc, EXCP_RANGE); + /* Store result. */ + gen_set_label(lab2); + tcg_gen_mov_i32(cpu_R[rd], res); + tcg_temp_free_i32(res);target-openrisc/translate.c line 484
Quoted 10 lines
target-openrisc/translate.c +10
-0+ tcg_temp_free_i64(t0); + tcg_temp_free_i32(rs); + tcg_temp_free_i32(rt); + tcg_temp_free_i64(tmp0); + tcg_temp_free_i64(tmp1); + tcg_temp_free_i32(sr_ove); +#ifdef TARGET_OPENRISC64 + int lab4 = gen_new_label(); + int lab5 = gen_new_label(); + int lab6 = gen_new_label();But here you add variables after code which is not OK (C99 style). Please put them earlier.
Quoted 70 lines
target-openrisc/translate.c +70
-0+ TCGv_i64 t3 = tcg_temp_local_new_i64(); + TCGv_i64 t4 = tcg_temp_local_new_i64(); + TCGv_i64 t5 = tcg_temp_local_new_i64(); + TCGv_i64 t6 = tcg_temp_local_new_i64(); + TCGv_i64 r1 = tcg_temp_local_new_i64(); + TCGv_i64 r2 = tcg_temp_local_new_i64(); + TCGv_i64 r3 = tcg_temp_local_new_i64(); + TCGv_i64 r4 = tcg_temp_local_new_i64(); + TCGv_i32 tp0 = tcg_temp_local_new_i64(); + TCGv_i32 tp1 = tcg_temp_local_new_i64(); + TCGv_i64 t2h = tcg_temp_local_new_i64(); + TCGv_i64 t2l = tcg_temp_local_new_i64(); + TCGv_i64 t3h = tcg_temp_local_new_i64(); + TCGv_i64 t3l = tcg_temp_local_new_i64(); + TCGv_i64 res1 = tcg_temp_local_new_i64(); + TCGv_i64 res0 = tcg_temp_local_new_i64(); + TCGv_i32 sr_ove64 = tcg_temp_local_new_i32(); + /* Calculate the each result, and HIGH. */ + tcg_gen_trunc_i64_i32(tp0, cpu_R[ra]); + tcg_gen_trunc_i64_i32(tp1, cpu_R[rb]); + tcg_gen_shri_i64(t3, cpu_R[ra], 32); + tcg_gen_extu_i32_i64(t4, tp0); + tcg_gen_shri_i64(t5, cpu_R[rb], 32); + tcg_gen_extu_i32_i64(t6, tp1); + tcg_gen_mul_i64(r1, t3, t5); + tcg_gen_mul_i64(r2, t3, t6); + tcg_gen_mul_i64(r3, t5, t5); + tcg_gen_mul_i64(r4, t3, t4); + tcg_gen_shri_i64(t2h, r2, 32); + tcg_gen_shri_i64(t3h, r3, 32); + tcg_gen_trunc_i64_i32(tp0, r2); + tcg_gen_trunc_i64_i32(tp1, r3); + tcg_gen_extu_i32_i64(t2l, tp0); + tcg_gen_extu_i32_i64(t3l, tp1); + tcg_gen_shri_i64(res0, r4); + tcg_gen_add_i64(t2l, t2l, t3l); + tcg_gen_add_i64(res1, t2l, res1); + /* Overflow or not, by t2l CY. */ + tcg_gen_shri_i64(t2l, res1, 32); + tcg_gen_add_i64(r1, t2h, r1); + tcg_gen_add_i64(r1, r1, t3h); + tcg_gen_add_i64(r1, r1, t2l); + tcg_gen_shri_i64(res0, res1, 31); + tcg_gen_andi_i64(res0, res0, 0x1); + tcg_gen_brcondi_i64(TCG_COND_EQ, res0, 0x1, lab4); + tcg_gen_brcondi_i64(TCG_COND_EQ, r1, 0x0, lab5); + tcg_gen_brcondi_i64(TCG_COND_NE, r1, 0x0, lab6); + gen_set_label(lab4); + tcg_gen_brcondi_i64(TCG_COND_EQ, r1, + 0xffffffffffffffff, lab5); + /* Handle overflow exception. */ + gen_set_label(lab6); + tcg_gen_andi_tl(cpu_sr, cpu_sr, SR_OV); + tcg_gen_andi_tl(cpu_sr, cpu_sr, SR_CY); + tcg_gen_addi_i32(sr_ove64, cpu_SR, SR_OVE); + tcg_gen_brcondi_i32(TCG_COND_NE, sr_ove64, 0x1, lab5); + gen_exeception(dc, EXCP_RANGE); + /* Store result. */ + gen_set_label(lab5); + tcg_gen_shli_i64(res1, res1, 32); + tcg_gen_addi_i64(r4, r4, 0xffffffff); + tcg_gen_add_i64(res1, r4, res1); + tcg_gen_mov_i64(cpu_R[rd], res1); + tcg_temp_free_i64(t3); + tcg_temp_free_i64(t4); + tcg_temp_free_i64(t5); + tcg_temp_free_i64(t6); + tcg_temp_free_i64(r1); + tcg_temp_free_i64(r2); + tcg_temp_free_i64(r3);target-openrisc/translate.c line 564
Quoted 10 lines
target-openrisc/translate.c +10
-0+ tcg_temp_free_i64(r4); + tcg_temp_free_i32(tp0); + tcg_temp_free_i32(tp1); + tcg_temp_free_i64(t2h); + tcg_temp_free_i64(t2l); + tcg_temp_free_i64(t3h); + tcg_temp_free_i64(t3l); + tcg_temp_free_i64(res1); + tcg_temp_free_i64(res0); + tcg_temp_free_i32(sr_ove64);
Quoted 4 lines
Overall the instruction is pretty long, maybe a helper would be in order. There are limits on how long the TCG sequences can become (see tcg/README).
is this looks OK?
target_ulong HELPER(mul32)(CPUOpenRISCState *env,
target_ulong ra, target_ulong rb)
{
uint64_t result;
target_ulong high, cy;
result = ra * rb;
high = result >> TARGET_LONG_BITS;
cy = result >> (TARGET_LONG_BITS - 1);
if ((cy & 0x1) == 0x0) {
if (high == 0x0) {
return result;
}
}
if ((cy & 0x1) == 0x1) {
if (high == 0xffffffff) {
return result;
}
}
env->sr |= (SR_OV | SR_CY);
if (env->sr & SR_OVE) {
raise_exception(env, EXCP_RANGE);
}
return result;
} case 0x03: /*l.mul*/
LOG_DIS("l.mul r%d, r%d, r%d\n", rd, ra, rb);
if (ra != 0 && rb != 0) {
gen_helper_mul32(cpu_R[rd], cpu_env, cpu_R[ra], cpu_R[rb]);
} else {
tcg_gen_movi_tl(cpu_R[rd], 0x0);
}
break;
case 0x2c: /*l.muli*/
LOG_DIS("l.muli r%d, r%d, %d\n", rd, ra, I16);
if (ra != 0 && I16 != 0) {
TCGv_i32 im = tcg_const_i32(I16);
gen_helper_mul32(cpu_R[rd], cpu_env, cpu_R[ra], im);
tcg_temp_free_i32(im);
} else {
tcg_gen_movi_tl(cpu_R[rd], 0x0);
}
break;Quoted 1,423 lines
Quoted 1,423 lines
target-openrisc/translate.c +1415
-0+#endif + } else { + tcg_gen_movi_tl(cpu_R[rd], 0x0); + } + } + break; + default: + gen_illegal_exception(dc); + break; + } + break; + + case 0x0009: + switch (op1) { + case 0x03: /*l.div*/ + LOG_DIS("l.div r%d, r%d, r%d\n", rd, ra, rb); + { + int lab0 = gen_new_label(); + int lab1 = gen_new_label(); + int lab2 = gen_new_label(); + TCGv_i32 sr_ove = tcg_temp_local_new_i32(); + if (rb == 0) { + tcg_gen_ori_tl(cpu_sr, cpu_sr, SR_OV | SR_CY); + tcg_gen_brcondi_tl(TCG_COND_NE, sr_ove, SR_OVE, lab0); + tcg_gen_andi_tl(sr_ove, cpu_sr, SR_OVE); + gen_exception(dc, EXCP_RANGE); + gen_set_label(lab0); + } else { + tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_R[rb], + 0x00000000, lab1); + tcg_gen_brcondi_tl(TCG_COND_NE, cpu_R[ra], + 0xffffffff, lab2); + tcg_gen_brcondi_tl(TCG_COND_NE, cpu_R[rb], + 0x80000000, lab2); + gen_set_label(lab1); + tcg_gen_ori_tl(cpu_sr, cpu_sr, SR_OV | SR_CY); + tcg_gen_andi_tl(sr_ove, cpu_sr, SR_OVE); + tcg_gen_brcondi_tl(TCG_COND_NE, sr_ove, SR_OVE, lab2); + gen_exception(dc, EXCP_RANGE); + gen_set_label(lab2); + tcg_gen_div_tl(cpu_R[rd], cpu_R[ra], cpu_R[rb]); + } + tcg_temp_free_i32(sr_ove); + } + break; + + default: + gen_illegal_exception(dc); + break; + } + break; + + case 0x000a: + switch (op1) { + case 0x03: /*l.divu*/ + LOG_DIS("l.divu r%d, r%d, r%d\n", rd, ra, rb); + { + int lab0 = gen_new_label(); + int lab1 = gen_new_label(); + TCGv_i32 sr_ove = tcg_temp_local_new_i32(); + if (rb == 0) { + tcg_gen_ori_tl(cpu_sr, cpu_sr, SR_OV | SR_CY); + tcg_gen_andi_tl(sr_ove, cpu_sr, SR_OVE); + tcg_gen_brcondi_tl(TCG_COND_NE, sr_ove, SR_OVE, lab0); + gen_exception(dc, EXCP_RANGE); + gen_set_label(lab0); + } else { + tcg_gen_brcondi_tl(TCG_COND_NE, cpu_R[rb], + 0x00000000, lab1); + tcg_gen_ori_tl(cpu_sr, cpu_sr, SR_OV | SR_CY); + tcg_gen_andi_tl(sr_ove, cpu_sr, SR_OVE); + tcg_gen_brcondi_tl(TCG_COND_NE, sr_ove, SR_OVE, lab1); + gen_exception(dc, EXCP_RANGE); + gen_set_label(lab1); + tcg_gen_divu_tl(cpu_R[rd], cpu_R[ra], cpu_R[rb]); + } + tcg_temp_free_i32(sr_ove); + } + break; + + default: + gen_illegal_exception(dc); + break; + } + break; + + case 0x000b: + switch (op1) { + case 0x03: /*l.mulu*/ + LOG_DIS("l.mulu r%d, r%d, r%d\n", rd, ra, rb); + if (rb != 0 && ra != 0) { + TCGv_i64 result = tcg_temp_local_new_i64(); + TCGv_i64 tra = tcg_temp_local_new_i64(); + TCGv_i64 trb = tcg_temp_local_new_i64(); + TCGv_i64 high = tcg_temp_new_i64(); + TCGv_i32 sr_ove = tcg_temp_local_new_i32(); + int lab = gen_new_label(); + /* Calculate the each result. */ + tcg_gen_extu_i32_i64(tra, cpu_R[ra]); + tcg_gen_extu_i32_i64(trb, cpu_R[rb]); + tcg_gen_mul_i64(result, tra, trb); + tcg_temp_free_i64(tra); + tcg_temp_free_i64(trb); + tcg_gen_shri_i64(high, result, TARGET_LONG_BITS); + /* Overflow or not. */ + tcg_gen_brcondi_i64(TCG_COND_EQ, high, 0x00000000, lab); + tcg_gen_ori_tl(cpu_sr, cpu_sr, SR_OV | SR_CY); + tcg_gen_andi_tl(sr_ove, cpu_sr, SR_OVE); + tcg_gen_brcondi_tl(TCG_COND_NE, sr_ove, SR_OVE, lab); + gen_exception(dc, EXCP_RANGE); + gen_set_label(lab); + tcg_temp_free_i64(high); + tcg_gen_trunc_i64_tl(cpu_R[rd], result); + tcg_temp_free_i64(result); + tcg_temp_free_i32(sr_ove); +#ifdef TARGET_OPENRISC64 + int lab1 = gen_new_label(); + TCGv_i32 r1 = tcg_temp_loacl_new_i64(); + TCGv_i32 r2 = tcg_temp_loacl_new_i64(); + TCGv_i64 r3 = tcg_temp_loacl_new_i64(); + TCGv_i64 r4 = tcg_temp_loacl_new_i64(); + TCGv_i64 r5 = tcg_temp_loacl_new_i64(); + TCGv_i64 r6 = tcg_temp_loacl_new_i64(); + TCGv_i64 tr1 = tcg_temp_loacl_new_i64(); + TCGv_i64 tr2 = tcg_temp_loacl_new_i64(); + TCGv_i64 tr3 = tcg_temp_loacl_new_i64(); + TCGv_i64 tr4 = tcg_temp_loacl_new_i64(); + TCGv_i64 rs1 = tcg_temp_loacl_new_i64(); + TCGv_i64 rs2 = tcg_temp_loacl_new_i64(); + TCGV_i32 sr_ove64 = tcg_temp_local_new_i32(); + /* Calculate the each result. */ + tcg_gen_trunc_i64_i32(r1, cpu_R[ra]); + tcg_gen_trunc_i64_i32(r2, cpu_R[rb]); + tcg_gen_extu_i32_i64(r3, r1); + tcg_gen_extu_i32_i64(r4, r2); + tcg_gen_shri_i64(r5, cpu_R[ra], 32); + tcg_gen_shri_i64(r6, cpu_R[rb], 32); + tcg_gen_mul_i64(tr1, r5, r6); + tcg_gen_mul_i64(tr2, r5, r4); + tcg_gen_mul_i64(tr3, r3, r6); + tcg_gen_mul_i64(tr4, r3, r4); + tcg_gen_trunc_i64_i32(r1, tr2); + tcg_gen_trunc_i64_i32(r2, tr3); + tcg_gen_extu_i32_i64(r3, r1); + tcg_gen_extu_i32_i64(r4, r2); + tcg_gen_shri_i64(rs1, tr4, 32); + tcg_gen_add_i64(r3, r3, r4); + tcg_gen_add_i64(rs2, rs1, r3); + /* Overflow or not, by r3 CY. */ + tcg_gen_shri_i64(r3, rs2, 32); + tcg_gen_shri_i64(tr3, tr3, 32); + tcg_gen_shri_i64(tr2, tr2, 32); + tcg_gen_add_i64(tr1, tr1, tr2); + tcg_gen_add_i64(tr1, tr1, tr3); + tcg_gen_add_i64(tr1, tr1, r3); + tcg_gen_brcondi_i64(TCGV_COND_EQ, tr1, 0x0, lab1); + tcg_gen_andi_tl(cpu_sr, cpu_sr, SR_OV); + tcg_gen_andi_tl(cpu_sr, cpu_sr, SR_CY); + tcg_gen_addi_i32(sr_ove64, cpu_SR, SR_OVE); + tcg_gen_brcondi_i32(TCG_COND_NE, sr_ove64, 0x1, lab1); + gen_exeception(dc, EXCP_RANGE); + /* Store result. */ + gen_set_label(lab1); + tcg_gen_andi_i64(tr4, tr4, 0xffffffff); + tcg_gen_shli_i64(rs2, rs2, 32); + tcg_gen_add_i64(rs2, rs2, tr4); + tcg_gen_mov_i64(cpu_R[rd], rs2); + tcg_temp_free_i32(r1); + tcg_temp_free_i32(r2); + tcg_temp_free_i64(r3); + tcg_temp_free_i64(r4); + tcg_temp_free_i64(r5); + tcg_temp_free_i64(r6); + tcg_temp_free_i64(tr1); + tcg_temp_free_i64(tr2); + tcg_temp_free_i64(tr3); + tcg_temp_free_i64(tr4); + tcg_temp_free_i64(rs1); + tcg_temp_free_i64(rs2); + tcg_temp_free_i64(sr_ove); +#endif + } else { + tcg_gen_movi_tl(cpu_R[rd], 0); + } + break; + + default: + gen_illegal_exception(dc); + break; + } + break; + + case 0x000e: + switch (op1) { + case 0x00: /*l.cmov*/ + LOG_DIS("l.cmov r%d, r%d, r%d\n", rd, ra, rb); + { + int lab = gen_new_label(); + TCGv res = tcg_temp_new(); + TCGv sr_f = tcg_temp_new(); + tcg_gen_andi_tl(sr_f, cpu_sr, SR_F); + tcg_gen_mov_tl(res, cpu_R[rb]); + tcg_gen_brcondi_tl(TCG_COND_NE, sr_f, SR_F, lab); + tcg_gen_mov_tl(res, cpu_R[ra]); + gen_set_label(lab); + tcg_gen_mov_tl(cpu_R[rd], res); + tcg_temp_free(sr_f); + tcg_temp_free(res); + } + break; + + default: + gen_illegal_exception(dc); + break; + } + break; + + case 0x000f: + switch (op1) { + case 0x00: /*l.ff1*/ + LOG_DIS("l.ff1 r%d, r%d, r%d\n", rd, ra, rb); + gen_helper_ff1(cpu_R[rd], cpu_R[ra]); + break; + case 0x01: /*l.fl1*/ + LOG_DIS("l.fl1 r%d, r%d, r%d\n", rd, ra, rb); + gen_helper_fl1(cpu_R[rd], cpu_R[ra]); + break; + + default: + gen_illegal_exception(dc); + break; + } + break; + + case 0x0008: + switch (op1) { + case 0x00: + switch (op2) { + case 0x00: /*l.sll*/ + LOG_DIS("l.sll r%d, r%d, r%d\n", rd, ra, rb); + tcg_gen_shl_tl(cpu_R[rd], cpu_R[ra], cpu_R[rb]); + break; + case 0x01: /*l.srl*/ + LOG_DIS("l.srl r%d, r%d, r%d\n", rd, ra, rb); + tcg_gen_shr_tl(cpu_R[rd], cpu_R[ra], cpu_R[rb]); + break; + case 0x02: /*l.sra*/ + LOG_DIS("l.sra r%d, r%d, r%d\n", rd, ra, rb); + tcg_gen_sar_tl(cpu_R[rd], cpu_R[ra], cpu_R[rb]); + break; + case 0x03: /*l.ror*/ + LOG_DIS("l.ror r%d, r%d, r%d\n", rd, ra, rb); + tcg_gen_rotr_tl(cpu_R[rd], cpu_R[ra], cpu_R[rb]); + break; + + default: + gen_illegal_exception(dc); + break; + } + break; + + default: + gen_illegal_exception(dc); + break; + } + break; + + case 0x000c: + switch (op1) { + case 0x00: + switch (op2) { + case 0x00: /*l.exths*/ + LOG_DIS("l.exths r%d, r%d\n", rd, ra); + tcg_gen_ext16s_tl(cpu_R[rd], cpu_R[ra]); + break; + case 0x01: /*l.extbs*/ + LOG_DIS("l.extbs r%d, r%d\n", rd, ra); + tcg_gen_ext8s_tl(cpu_R[rd], cpu_R[ra]); + break; + case 0x02: /*l.exthz*/ + LOG_DIS("l.exthz r%d, r%d\n", rd, ra); + tcg_gen_ext16u_tl(cpu_R[rd], cpu_R[ra]); + break; + case 0x03: /*l.extbz*/ + LOG_DIS("l.extbz r%d, r%d\n", rd, ra); + tcg_gen_ext8u_tl(cpu_R[rd], cpu_R[ra]); + break; + + default: + gen_illegal_exception(dc); + break; + } + break; + + default: + gen_illegal_exception(dc); + break; + } + break; + + case 0x000d: + switch (op1) { + case 0x00: + switch (op2) { + case 0x00: /*l.extws*/ + LOG_DIS("l.extws r%d, r%d\n", rd, ra); + tcg_gen_ext32s_tl(cpu_R[rd], cpu_R[ra]); + break; + case 0x01: /*l.extwz*/ + LOG_DIS("l.extwz r%d, r%d\n", rd, ra); + tcg_gen_ext32u_tl(cpu_R[rd], cpu_R[ra]); + break; + + default: + gen_illegal_exception(dc); + break; + } + break; + + default: + gen_illegal_exception(dc); + break; + } + break; + + default: + gen_illegal_exception(dc); + break; + } +} + +static void dec_misc(DisasContext *dc, CPUOpenRISCState *env, uint32_t insn) +{ + uint32_t op0, op1; + uint32_t ra, rb, rd; + uint32_t /*L6, K5, */I16, I5, I11, N26, tmp; + op0 = field(insn, 26, 6); + op1 = field(insn, 24, 2); + ra = field(insn, 16, 5); + rb = field(insn, 11, 5); + rd = field(insn, 21, 5); + /*L6 = field(insn, 5, 6); + K5 = field(insn, 0, 5);*/ + I16 = field(insn, 0, 16); + I5 = field(insn, 21, 5); + I11 = field(insn, 0, 11); + N26 = field(insn, 0, 26); + tmp = (I5<<11) + I11; + + switch (op0) { + case 0x00: /*l.j*/ + LOG_DIS("l.j %d\n", N26); + case 0x01: /*l.jal*/ + LOG_DIS("l.jal %d\n", N26); + case 0x03: /*l.bnf*/ + LOG_DIS("l.bnf %d\n", N26); + case 0x04: /*l.bf*/ + LOG_DIS("l.bf %d\n", N26); + + gen_jump(dc, N26, 0, op0); + break; + + case 0x05: + switch (op1) { + case 0x01: /*l.nop*/ + LOG_DIS("l.nop %d\n", I16); + break; + + default: + gen_illegal_exception(dc); + break; + } + break; + + case 0x11: /*l.jr*/ + LOG_DIS("l.jr r%d\n", rb); + case 0x12: /*l.jalr*/ + LOG_DIS("l.jalr r%d\n", rb); + + gen_jump(dc, 0, rb, op0); + break; + + case 0x13: /*l.maci*/ + LOG_DIS("l.maci %d, r%d, %d\n", I5, ra, I11); + { + TCGv_i64 t1 = tcg_temp_new_i64(); + TCGv_i64 t2 = tcg_temp_new_i64(); + TCGv_i32 dst = tcg_temp_new_i32(); + TCGv ttmp = tcg_const_tl(tmp); + tcg_gen_mul_tl(dst, cpu_R[ra], ttmp); + tcg_gen_ext_i32_i64(t1, dst); + tcg_gen_concat_i32_i64(t2, maclo, machi); + tcg_gen_add_i64(t2, t2, t1); + tcg_gen_trunc_i64_i32(maclo, t2); + tcg_gen_shri_i64(t2, t2, 32); + tcg_gen_trunc_i64_i32(machi, t2); + tcg_temp_free_i32(dst); + tcg_temp_free(ttmp); + tcg_temp_free_i64(t1); + tcg_temp_free_i64(t2); + } + break; + + case 0x09: /*l.rfe*/ + LOG_DIS("l.rfe\n"); + { + gen_helper_rfe(cpu_env); + dc->is_jmp = DISAS_UPDATE; + } + break; + + case 0x1c: /*l.cust1*/ + LOG_DIS("l.cust1\n"); + break; + + case 0x1d: /*l.cust2*/ + LOG_DIS("l.cust2\n"); + break; + + case 0x1e: /*l.cust3*/ + LOG_DIS("l.cust3\n"); + break; + + case 0x1f: /*l.cust4*/ + LOG_DIS("l.cust4\n"); + break; + + case 0x3c: /*l.cust5*/ + /*LOG_DIS("l.cust5 r%d, r%d, r%d, %d, %d\n", rd, ra, rb, L6, K5);*/ + break; + + case 0x3d: /*l.cust6*/ + LOG_DIS("l.cust6\n"); + break; + + case 0x3e: /*l.cust7*/ + LOG_DIS("l.cust7\n"); + break; + + case 0x3f: /*l.cust8*/ + LOG_DIS("l.cust8\n"); + break; + + case 0x20: /*l.ld*/ + LOG_DIS("l.ld r%d, r%d, %d\n", rd, ra, I16); + { +#ifdef TARGET_OPENRISC64 + check_ob64s(dc); + TCGv_i64 t0 = tcg_temp_new_i64(); + tcg_gen_addi_i64(t0, cpu_R[ra], sign_extend(I16, 16)); + tcg_gen_qemu_ld64(cpu_R[rd], t0, dc->mem_idx); + tcg_temp_free_i64(t0); +#endif + } + break; + + case 0x21: /*l.lwz*/ + LOG_DIS("l.lwz r%d, r%d, %d\n", rd, ra, I16); + { + TCGv t0 = tcg_temp_new(); + tcg_gen_addi_tl(t0, cpu_R[ra], sign_extend(I16, 16)); + tcg_gen_qemu_ld32u(cpu_R[rd], t0, dc->mem_idx); + tcg_temp_free(t0); + } + break; + + case 0x22: /*l.lws*/ + LOG_DIS("l.lws r%d, r%d, %d\n", rd, ra, I16); + { + TCGv t0 = tcg_temp_new(); + tcg_gen_addi_tl(t0, cpu_R[ra], sign_extend(I16, 16)); + tcg_gen_qemu_ld32s(cpu_R[rd], t0, dc->mem_idx); + tcg_temp_free(t0); + } + break; + + case 0x23: /*l.lbz*/ + LOG_DIS("l.lbz r%d, r%d, %d\n", rd, ra, I16); + { + TCGv t0 = tcg_temp_new(); + tcg_gen_addi_tl(t0, cpu_R[ra], sign_extend(I16, 16)); + tcg_gen_qemu_ld8u(cpu_R[rd], t0, dc->mem_idx); + tcg_temp_free(t0); + } + break; + + case 0x24: /*l.lbs*/ + LOG_DIS("l.lbs r%d, r%d, %d\n", rd, ra, I16); + { + TCGv t0 = tcg_temp_new(); + tcg_gen_addi_tl(t0, cpu_R[ra], sign_extend(I16, 16)); + tcg_gen_qemu_ld8s(cpu_R[rd], t0, dc->mem_idx); + tcg_temp_free(t0); + } + break; + + case 0x25: /*l.lhz*/ + LOG_DIS("l.lhz r%d, r%d, %d\n", rd, ra, I16); + { + TCGv t0 = tcg_temp_new(); + tcg_gen_addi_tl(t0, cpu_R[ra], sign_extend(I16, 16)); + tcg_gen_qemu_ld16u(cpu_R[rd], t0, dc->mem_idx); + tcg_temp_free(t0); + } + break; + + case 0x26: /*l.lhs*/ + LOG_DIS("l.lhs r%d, r%d, %d\n", rd, ra, I16); + { + TCGv t0 = tcg_temp_new(); + tcg_gen_addi_tl(t0, cpu_R[ra], sign_extend(I16, 16)); + tcg_gen_qemu_ld16s(cpu_R[rd], t0, dc->mem_idx); + tcg_temp_free(t0); + } + break; + + case 0x27: /*l.addi*/ + LOG_DIS("l.addi r%d, r%d, %d\n", rd, ra, I16); + { + int lab = gen_new_label(); + TCGv_i64 ta = tcg_temp_new_i64(); + TCGv_i64 td = tcg_temp_local_new_i64(); + TCGv_i32 res = tcg_temp_local_new_i32(); + TCGv_i32 sr_ove = tcg_temp_local_new_i32(); + tcg_gen_extu_i32_i64(ta, cpu_R[ra]); + tcg_gen_addi_i64(td, ta, sign_extend(I16, 16)); + tcg_gen_trunc_i64_i32(res, td); + tcg_gen_shri_i64(td, td, 32); + tcg_gen_andi_i64(td, td, 0x3); + /* Jump to lab when no overflow. */ + tcg_gen_brcondi_i64(TCG_COND_EQ, td, 0x0, lab); + tcg_gen_brcondi_i64(TCG_COND_EQ, td, 0x3, lab); + tcg_gen_ori_i32(cpu_sr, cpu_sr, (SR_OV | SR_CY)); + tcg_gen_andi_i32(sr_ove, cpu_sr, SR_OVE); + tcg_gen_brcondi_i32(TCG_COND_NE, sr_ove, SR_OVE, lab); + gen_exception(dc, EXCP_RANGE); + gen_set_label(lab); + tcg_gen_mov_i32(cpu_R[rd], res); + tcg_temp_free_i64(ta); + tcg_temp_free_i64(td); + tcg_temp_free_i32(res); + tcg_temp_free_i32(sr_ove); + } + break; + + case 0x28: /*l.addic*/ + LOG_DIS("l.addic r%d, r%d, %d\n", rd, ra, I16); + { + int lab = gen_new_label(); + TCGv_i64 ta = tcg_temp_new_i64(); + TCGv_i64 td = tcg_temp_local_new_i64(); + TCGv_i64 tcy = tcg_temp_local_new_i64(); + TCGv_i32 res = tcg_temp_local_new_i32(); + TCGv_i32 sr_cy = tcg_temp_local_new_i32(); + TCGv_i32 sr_ove = tcg_temp_local_new_i32(); + tcg_gen_extu_i32_i64(ta, cpu_R[ra]); + tcg_gen_andi_i32(sr_cy, cpu_sr, SR_CY); + tcg_gen_shri_i32(sr_cy, sr_cy, 10); + tcg_gen_extu_i32_i64(tcy, sr_cy); + tcg_gen_addi_i64(td, ta, sign_extend(I16, 16)); + tcg_gen_add_i64(td, td, tcy); + tcg_gen_trunc_i64_i32(res, td); + tcg_gen_shri_i64(td, td, 32); + tcg_gen_andi_i64(td, td, 0x3); + /* Jump to lab when no overflow. */ + tcg_gen_brcondi_i64(TCG_COND_EQ, td, 0x0, lab); + tcg_gen_brcondi_i64(TCG_COND_EQ, td, 0x3, lab); + tcg_gen_ori_i32(cpu_sr, cpu_sr, (SR_OV | SR_CY)); + tcg_gen_andi_i32(sr_ove, cpu_sr, SR_OVE); + tcg_gen_brcondi_i32(TCG_COND_NE, sr_ove, SR_OVE, lab); + gen_exception(dc, EXCP_RANGE); + gen_set_label(lab); + tcg_gen_mov_i32(cpu_R[rd], res); + tcg_temp_free_i64(ta); + tcg_temp_free_i64(td); + tcg_temp_free_i64(tcy); + tcg_temp_free_i32(res); + tcg_temp_free_i32(sr_cy); + tcg_temp_free_i32(sr_ove); + } + break; + + case 0x29: /*l.andi*/ + LOG_DIS("l.andi r%d, r%d, %d\n", rd, ra, I16); + tcg_gen_andi_tl(cpu_R[rd], cpu_R[ra], zero_extend(I16, 16)); + break; + + case 0x2a: /*l.ori*/ + LOG_DIS("l.ori r%d, r%d, %d\n", rd, ra, I16); + tcg_gen_ori_tl(cpu_R[rd], cpu_R[ra], zero_extend(I16, 16)); + break; + + case 0x2b: /*l.xori*/ + LOG_DIS("l.xori r%d, r%d, %d\n", rd, ra, I16); + tcg_gen_xori_tl(cpu_R[rd], cpu_R[ra], sign_extend(I16, 16)); + break; + + case 0x2c: /*l.muli*/ + LOG_DIS("l.muli r%d, r%d, %d\n", rd, ra, I16); + if (ra != 0 && I16 != 0) { + int lab1 = gen_new_label(); + TCGv_i64 t0 = tcg_temp_local_new_i64(); + TCGv_i32 t1 = tcg_temp_local_new_i32(); + TCGv_i32 t2 = tcg_temp_local_new_i32(); + TCGv_i64 tmp0 = tcg_temp_local_new_i64(); + TCGv_i32 res = tcg_temp_local_new_i32(); + TCGv_i32 sr_ove = tcg_temp_local_new_i32(); + uint64_t i16 = (uint64_t)I16; + /* Calculate the result. */ + tcg_gen_extu_i32_i64(tmp0, cpu_R[ra]); + tcg_gen_muli_i64(t0, tmp0, i16); + tcg_gen_trunc_i64_i32(t1, t0); + tcg_gen_mov_tl(res, t1); + tcg_gen_shri_i32(t1, t1, 31); + /* Overflow or not. */ + tcg_gen_brcondi_tl(TCG_COND_NE, t1, 0x0, lab1); + tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0x1ffff, lab1); + tcg_gen_ori_tl(cpu_sr, cpu_sr, SR_OV); + tcg_gen_ori_tl(cpu_sr, cpu_sr, SR_CY); + tcg_gen_andi_tl(sr_ove, cpu_sr, SR_OVE); + tcg_gen_brcondi_tl(TCG_COND_NE, sr_ove, SR_OVE, lab1); + gen_exception(dc, EXCP_RANGE); + /* Store result. */ + gen_set_label(lab1); + tcg_gen_mov_i32(cpu_R[rd], res); + tcg_temp_free_i64(t0); + tcg_temp_free_i32(t1); + tcg_temp_free_i32(t2); + tcg_temp_free_i64(tmp0); + tcg_temp_free_i32(res); + tcg_temp_free_i32(sr_ove); +#ifdef TARGET_OPENRISC64 + int lab2 = gen_new_label(); + TCGv_i64 tmp1 = tcg_temp_local_new_i64(); + TCGv_i64 tmp2 = tcg_temp_local_new_i64(); + TCGv_i64 tr = tcg_temp_local_new_i64(); + TCGv_i32 t3 = tcg_temp_local_new_i64(); + TCGv_i32 t4 = tcg_temp_local_new_i64(); + TCGv_i64 t5 = tcg_temp_local_new_i64(); + TCGv_i64 res1 = tcg_temp_local_new_i64(); + TCGv_i32 sr_ove64 = tcg_temp_local_new_i32(); + /* Calculate the result. */ + tcg_gen_trunc_i64_i32(t3, cpu_R[ra]); + tcg_gen_shri_i64(cpu_R[ra], cpu_R[ra], 32); + tcg_gen_trunc_i64_i32(t5, cpu_R[ra]); + tcg_gen_muli_i64(tr, t3, I16); + tcg_gen_muli_i64(t4, t5, I16); + tcg_gen_shri_i64(tmp2, tr, 32); + tcg_gen_add_i64(res1, tmp2, t4); + tcg_gen_shri_i64(tmp1, res1, 31); + /* Overflow or not. */ + tcg_gen_brcondi_tl(TCG_COND_NE, tmp1, 0x0, lab2); + tcg_gen_brcondi_tl(TCG_COND_EQ, tmp1, 0x1ffff, lab2); + tcg_gen_ori_tl(cpu_sr, cpu_sr, SR_OV); + tcg_gen_ori_tl(cpu_sr, cpu_sr, SR_CY); + tcg_gen_andi_tl(sr_ove64, cpu_sr, SR_OVE); + tcg_gen_brcondi_tl(TCG_COND_EQ, sr_ove64, SR_OVE, lab2); + gen_exeception(dc, EXCP_RANGE); + /* Store result. */ + gen_set_label(lab2); + tcg_gen_andi_i64(tr, tr, 0xffffffff); + tcg_gen_shli_i64(res1, res1, 32); + tcg_gen_add_i64(cpu_R[rd], res1, tr); + tcg_temp_free_i64(tmp1); + tcg_temp_free_i64(tmp2); + tcg_temp_free_i64(t3); + tcg_temp_free_i64(t4); + tcg_temp_free_i64(t5); + tcg_temp_free_i64(tr); + tcg_temp_free_i64(res1); + tcg_temp_free_i64(sr_ove64); +#endif + } else { + tcg_gen_movi_tl(cpu_R[rd], 0x0); + } + break; + + case 0x2d: /*l.mfspr*/ + LOG_DIS("l.mfspr r%d, r%d, %d\n", rd, ra, I16); + break; + + case 0x30: /*l.mtspr*/ + LOG_DIS("l.mtspr %d, r%d, r%d, %d\n", I5, ra, rb, I11); + break; + + case 0x34: /*l.sd*/ + LOG_DIS("l.sd %d, r%d, r%d, %d\n", I5, ra, rb, I11); + { +#ifdef TARGET_OPENRISC64 + check_ob64s(dc); + TCGv_i64 t0 = tcg_temp_new_i64(); + tcg_gen_addi_tl(t0, cpu_R[ra], sign_extend(tmp, 16)); + tcg_gen_qemu_st64(cpu_R[rb], t0, dc->mem_idx); + tcg_temp_free_i64(t0); +#endif + } + break; + + case 0x35: /*l.sw*/ + LOG_DIS("l.sw %d, r%d, r%d, %d\n", I5, ra, rb, I11); + { + TCGv t0 = tcg_temp_new(); + tcg_gen_addi_tl(t0, cpu_R[ra], sign_extend(tmp, 16)); + tcg_gen_qemu_st32(cpu_R[rb], t0, dc->mem_idx); + tcg_temp_free(t0); + } + break; + + case 0x36: /*l.sb*/ + LOG_DIS("l.sb %d, r%d, r%d, %d\n", I5, ra, rb, I11); + { + TCGv t0 = tcg_temp_new(); + tcg_gen_addi_tl(t0, cpu_R[ra], sign_extend(tmp, 16)); + tcg_gen_qemu_st8(cpu_R[rb], t0, dc->mem_idx); + tcg_temp_free(t0); + } + break; + + case 0x37: /*l.sh*/ + LOG_DIS("l.sh %d, r%d, r%d, %d\n", I5, ra, rb, I11); + { + TCGv t0 = tcg_temp_new(); + tcg_gen_addi_tl(t0, cpu_R[ra], sign_extend(tmp, 16)); + tcg_gen_qemu_st16(cpu_R[rb], t0, dc->mem_idx); + tcg_temp_free(t0); + } + break; + + default: + gen_illegal_exception(dc); + break; + } +} + +static void dec_mac(DisasContext *dc, CPUOpenRISCState *env, uint32_t insn) +{ + uint32_t op0; + uint32_t ra, rb; + op0 = field(insn, 0, 4); + ra = field(insn, 16, 5); + rb = field(insn, 11, 5); + + switch (op0) { + case 0x0001: /*l.mac*/ + LOG_DIS("l.mac r%d, r%d\n", ra, rb); + { + TCGv_i32 t0 = tcg_temp_new_i32(); + TCGv_i64 t1 = tcg_temp_new_i64(); + TCGv_i64 t2 = tcg_temp_new_i64(); + tcg_gen_mul_tl(t0, cpu_R[ra], cpu_R[rb]); + tcg_gen_ext_i32_i64(t1, t0); + tcg_gen_concat_i32_i64(t2, maclo, machi); + tcg_gen_add_i64(t2, t2, t1); + tcg_gen_trunc_i64_i32(maclo, t2); + tcg_gen_shri_i64(t2, t2, 32); + tcg_gen_trunc_i64_i32(machi, t2); + tcg_temp_free_i32(t0); + tcg_temp_free_i64(t1); + tcg_temp_free_i64(t2); + } + break; + + case 0x0002: /*l.msb*/ + LOG_DIS("l.msb r%d, r%d\n", ra, rb); + { + TCGv_i32 t0 = tcg_temp_new_i32(); + TCGv_i64 t1 = tcg_temp_new_i64(); + TCGv_i64 t2 = tcg_temp_new_i64(); + tcg_gen_mul_tl(t0, cpu_R[ra], cpu_R[rb]); + tcg_gen_ext_i32_i64(t1, t0); + tcg_gen_concat_i32_i64(t2, maclo, machi); + tcg_gen_sub_i64(t2, t2, t1); + tcg_gen_trunc_i64_i32(maclo, t2); + tcg_gen_shri_i64(t2, t2, 32); + tcg_gen_trunc_i64_i32(machi, t2); + tcg_temp_free_i32(t0); + tcg_temp_free_i64(t1); + tcg_temp_free_i64(t2); + } + break; + + default: + gen_illegal_exception(dc); + break; + } +} + +static void dec_logic(DisasContext *dc, CPUOpenRISCState *env, uint32_t insn) +{ + uint32_t op0; + uint32_t rd, ra, L6; + op0 = field(insn, 6, 2); + rd = field(insn, 21, 5); + ra = field(insn, 16, 5); + L6 = field(insn, 0, 6); + + switch (op0) { + case 0x00: /*l.slli*/ + LOG_DIS("l.slli r%d, r%d, %d\n", rd, ra, L6); + tcg_gen_shli_tl(cpu_R[rd], cpu_R[ra], (L6 & 0x1f)); + break; + + case 0x01: /*l.srli*/ + LOG_DIS("l.srli r%d, r%d, %d\n", rd, ra, L6); + tcg_gen_shri_tl(cpu_R[rd], cpu_R[ra], (L6 & 0x1f)); + break; + + case 0x02: /*l.srai*/ + LOG_DIS("l.srai r%d, r%d, %d\n", rd, ra, L6); + tcg_gen_sari_tl(cpu_R[rd], cpu_R[ra], (L6 & 0x1f)); break; + + case 0x03: /*l.rori*/ + LOG_DIS("l.rori r%d, r%d, %d\n", rd, ra, L6); + tcg_gen_rotri_tl(cpu_R[rd], cpu_R[ra], (L6 & 0x1f)); + break; + + default: + gen_illegal_exception(dc); + break; + } +} + +static void dec_M(DisasContext *dc, CPUOpenRISCState *env, uint32_t insn) +{ + uint32_t op0; + uint32_t rd; + uint32_t K16; + op0 = field(insn, 16, 1); + rd = field(insn, 21, 5); + K16 = field(insn, 0, 16); + + switch (op0) { + case 0x0: /*l.movhi*/ + LOG_DIS("l.movhi r%d, %d\n", rd, K16); + tcg_gen_movi_tl(cpu_R[rd], (K16 << 16)); + break; + + case 0x1: /*l.macrc*/ + LOG_DIS("l.macrc r%d\n", rd); + tcg_gen_mov_tl(cpu_R[rd], maclo); + tcg_gen_movi_tl(maclo, 0x0); + tcg_gen_movi_tl(machi, 0x0); + break; + + default: + gen_illegal_exception(dc); + break; + } +} + +static void dec_comp(DisasContext *dc, CPUOpenRISCState *env, uint32_t insn) +{ + uint32_t op0; + uint32_t ra, rb; + + op0 = field(insn, 21, 5); + ra = field(insn, 16, 5); + rb = field(insn, 11, 5); + + tcg_gen_movi_i32(env_btaken, 0x0); + /* unsigned integers */ + tcg_gen_ext32u_tl(cpu_R[ra], cpu_R[ra]); + tcg_gen_ext32u_tl(cpu_R[rb], cpu_R[rb]); + + switch (op0) { + case 0x0: /*l.sfeq*/ + LOG_DIS("l.sfeq r%d, r%d\n", ra, rb); + tcg_gen_setcond_tl(TCG_COND_EQ, env_btaken, cpu_R[ra], cpu_R[rb]); + break; + + case 0x1: /*l.sfne*/ + LOG_DIS("l.sfne r%d, r%d\n", ra, rb); + tcg_gen_setcond_tl(TCG_COND_NE, env_btaken, cpu_R[ra], cpu_R[rb]); + break; + + case 0x2: /*l.sfgtu*/ + LOG_DIS("l.sfgtu r%d, r%d\n", ra, rb); + tcg_gen_setcond_tl(TCG_COND_GTU, env_btaken, cpu_R[ra], cpu_R[rb]); + break; + + case 0x3: /*l.sfgeu*/ + LOG_DIS("l.sfgeu r%d, r%d\n", ra, rb); + tcg_gen_setcond_tl(TCG_COND_GEU, env_btaken, cpu_R[ra], cpu_R[rb]); + break; + + case 0x4: /*l.sfltu*/ + LOG_DIS("l.sfltu r%d, r%d\n", ra, rb); + tcg_gen_setcond_tl(TCG_COND_LTU, env_btaken, cpu_R[ra], cpu_R[rb]); + break; + + case 0x5: /*l.sfleu*/ + LOG_DIS("l.sfleu r%d, r%d\n", ra, rb); + tcg_gen_setcond_tl(TCG_COND_LEU, env_btaken, cpu_R[ra], cpu_R[rb]); + break; + + case 0xa: /*l.sfgts*/ + LOG_DIS("l.sfgts r%d, r%d\n", ra, rb); + tcg_gen_setcond_tl(TCG_COND_GT, env_btaken, cpu_R[ra], cpu_R[rb]); + break; + + case 0xb: /*l.sfges*/ + LOG_DIS("l.sfges r%d, r%d\n", ra, rb); + tcg_gen_setcond_tl(TCG_COND_GE, env_btaken, cpu_R[ra], cpu_R[rb]); + break; + + case 0xc: /*l.sflts*/ + LOG_DIS("l.sflts r%d, r%d\n", ra, rb); + tcg_gen_setcond_tl(TCG_COND_LT, env_btaken, cpu_R[ra], cpu_R[rb]); + break; + + case 0xd: /*l.sfles*/ + LOG_DIS("l.sfles r%d, r%d\n", ra, rb); + tcg_gen_setcond_tl(TCG_COND_LE, env_btaken, cpu_R[ra], cpu_R[rb]); + break; + + default: + gen_illegal_exception(dc); + break; + } + wb_SR_F(); +} + +static void dec_compi(DisasContext *dc, CPUOpenRISCState *env, uint32_t insn) +{ + uint32_t op0; + uint32_t ra, I16; + + op0 = field(insn, 21, 5); + ra = field(insn, 16, 5); + I16 = field(insn, 0, 16); + + tcg_gen_movi_i32(env_btaken, 0x0); + I16 = sign_extend(I16, 16); + + switch (op0) { + case 0x0: /*l.sfeqi*/ + LOG_DIS("l.sfeqi r%d, %d\n", ra, I16); + tcg_gen_setcondi_tl(TCG_COND_EQ, env_btaken, cpu_R[ra], I16); + break; + + case 0x1: /*l.sfnei*/ + LOG_DIS("l.sfnei r%d, %d\n", ra, I16); + tcg_gen_setcondi_tl(TCG_COND_NE, env_btaken, cpu_R[ra], I16); + break; + + case 0x2: /*l.sfgtui*/ + LOG_DIS("l.sfgtui r%d, %d\n", ra, I16); + tcg_gen_setcondi_tl(TCG_COND_GTU, env_btaken, cpu_R[ra], I16); + break; + + case 0x3: /*l.sfgeui*/ + LOG_DIS("l.sfgeui r%d, %d\n", ra, I16); + tcg_gen_setcondi_tl(TCG_COND_GEU, env_btaken, cpu_R[ra], I16); + break; + + case 0x4: /*l.sfltui*/ + LOG_DIS("l.sfltui r%d, %d\n", ra, I16); + tcg_gen_setcondi_tl(TCG_COND_LTU, env_btaken, cpu_R[ra], I16); + break; + + case 0x5: /*l.sfleui*/ + LOG_DIS("l.sfleui r%d, %d\n", ra, I16); + tcg_gen_setcondi_tl(TCG_COND_LEU, env_btaken, cpu_R[ra], I16); + break; + + case 0xa: /*l.sfgtsi*/ + LOG_DIS("l.sfgtsi r%d, %d\n", ra, I16); + tcg_gen_setcondi_tl(TCG_COND_GT, env_btaken, cpu_R[ra], I16); + break; + + case 0xb: /*l.sfgesi*/ + LOG_DIS("l.sfgesi r%d, %d\n", ra, I16); + tcg_gen_setcondi_tl(TCG_COND_GE, env_btaken, cpu_R[ra], I16); + break; + + case 0xc: /*l.sfltsi*/ + LOG_DIS("l.sfltsi r%d, %d\n", ra, I16); + tcg_gen_setcondi_tl(TCG_COND_LT, env_btaken, cpu_R[ra], I16); + break; + + case 0xd: /*l.sflesi*/ + LOG_DIS("l.sflesi r%d, %d\n", ra, I16); + tcg_gen_setcondi_tl(TCG_COND_LE, env_btaken, cpu_R[ra], I16); + break; + + default: + gen_illegal_exception(dc); + break; + } + wb_SR_F(); +} + +static void dec_sys(DisasContext *dc, CPUOpenRISCState *env, uint32_t insn) +{ + uint32_t op0; + /*uint32_t K16;*/ + op0 = field(insn, 16, 8); + /*K16 = field(insn, 0, 16);*/ + + switch (op0) { + case 0x000: /*l.sys*/ + /*LOG_DIS("l.sys %d\n", K16);*/ + tcg_gen_movi_tl(cpu_pc, dc->pc); + gen_exception(dc, EXCP_SYSCALL); + dc->is_jmp = DISAS_UPDATE; + break; + + case 0x100: /*l.trap*/ + /*LOG_DIS("l.trap %d\n", K16);*/ + tcg_gen_movi_tl(cpu_pc, dc->pc); + gen_exception(dc, EXCP_TRAP); + break; + + case 0x300: /*l.csync*/ + LOG_DIS("l.csync\n"); + break; + + case 0x200: /*l.msync*/ + LOG_DIS("l.msync\n"); + break; + + case 0x270: /*l.psync*/ + LOG_DIS("l.psync\n"); + break; + + default: + gen_illegal_exception(dc); + break; + } +} + +static void dec_float(DisasContext *dc, CPUOpenRISCState *env, uint32_t insn) +{ + uint32_t op0; + uint32_t ra, rb, rd; + op0 = field(insn, 0, 8); + ra = field(insn, 16, 5); + rb = field(insn, 11, 5); + rd = field(insn, 21, 5); + + switch (op0) { + case 0x00: /*lf.add.s*/ + LOG_DIS("lf.add.s r%d, r%d, r%d\n", rd, ra, rb); + gen_helper_float_add_s(cpu_R[rd], cpu_env, cpu_R[ra], cpu_R[rb]); + break; + + case 0x01: /*lf.sub.s*/ + LOG_DIS("lf.sub.s r%d, r%d, r%d\n", rd, ra, rb); + gen_helper_float_sub_s(cpu_R[rd], cpu_env, cpu_R[ra], cpu_R[rb]); + break; + + + case 0x02: /*lf.mul.s*/ + LOG_DIS("lf.mul.s r%d, r%d, r%d\n", rd, ra, rb); + if (ra != 0 && rb != 0) { + gen_helper_float_mul_s(cpu_R[rd], cpu_env, cpu_R[ra], cpu_R[rb]); + } else { + tcg_gen_ori_tl(fpcsr, fpcsr, FPCSR_ZF); + tcg_gen_movi_i32(cpu_R[rd], 0x0); + } + break; + + case 0x03: /*lf.div.s*/ + LOG_DIS("lf.div.s r%d, r%d, r%d\n", rd, ra, rb); + gen_helper_float_div_s(cpu_R[rd], cpu_env, cpu_R[ra], cpu_R[rb]); + break; + + case 0x04: /*lf.itof.s*/ + LOG_DIS("lf.itof r%d, r%d\n", rd, ra); + gen_helper_itofs(cpu_R[rd], cpu_env, cpu_R[ra]); + break; + + case 0x05: /*lf.ftoi.s*/ + LOG_DIS("lf.ftoi r%d, r%d\n", rd, ra); + gen_helper_ftois(cpu_R[rd], cpu_env, cpu_R[ra]); + break; + + case 0x06: /*lf.rem.s*/ + LOG_DIS("lf.rem.s r%d, r%d, r%d\n", rd, ra, rb); + gen_helper_float_rem_s(cpu_R[rd], cpu_env, cpu_R[ra], cpu_R[rb]); + break; + + case 0x07: /*lf.madd.s*/ + LOG_DIS("lf.madd.s r%d, r%d, r%d\n", rd, ra, rb); + gen_helper_float_muladd_s(cpu_R[rd], cpu_env, cpu_R[ra], cpu_R[rb]); + break; + + case 0x08: /*lf.sfeq.s*/ + LOG_DIS("lf.sfeq.s r%d, r%d\n", ra, rb); + gen_helper_float_eq_s(env_btaken, cpu_env, cpu_R[ra], cpu_R[rb]); + break; + + case 0x09: /*lf.sfne.s*/ + LOG_DIS("lf.sfne.s r%d, r%d\n", ra, rb); + gen_helper_float_ne_s(env_btaken, cpu_env, cpu_R[ra], cpu_R[rb]); + break; + + case 0x0a: /*lf.sfgt.s*/ + LOG_DIS("lf.sfgt.s r%d, r%d\n", ra, rb); + gen_helper_float_gt_s(env_btaken, cpu_env, cpu_R[ra], cpu_R[rb]); + break; + + case 0x0b: /*lf.sfge.s*/ + LOG_DIS("lf.sfge.s r%d, r%d\n", ra, rb); + gen_helper_float_ge_s(env_btaken, cpu_env, cpu_R[ra], cpu_R[rb]); + break; + + case 0x0c: /*lf.sflt.s*/ + LOG_DIS("lf.sflt.s r%d, r%d\n", ra, rb); + gen_helper_float_lt_s(env_btaken, cpu_env, cpu_R[ra], cpu_R[rb]); + break; + + case 0x0d: /*lf.sfle.s*/ + LOG_DIS("lf.sfle.s r%d, r%d\n", ra, rb); + gen_helper_float_le_s(env_btaken, cpu_env, cpu_R[ra], cpu_R[rb]); + break; + +#ifdef TARGET_OPENRISC64 + case 0x10: /*lf.add.d*/ + LOG_DIS("lf.add.d r%d, r%d, r%d\n", rd, ra, rb); + check_of64s(dc); + gen_helper_float_add_d(cpu_R[rd], cpu_env, cpu_R[ra], cpu_R[rb]); + break; + + case 0x11: /*lf.sub.d*/ + LOG_DIS("lf.sub.d r%d, r%d, r%d\n", rd, ra, rb); + check_of64s(dc); + gen_helper_float_sub_d(cpu_R[rd], cpu_env, cpu_R[ra], cpu_R[rb]); + break; + + case 0x12: /*lf.mul.d*/ + LOG_DIS("lf.mul.d r%d, r%d, r%d\n", rd, ra, rb); + check_of64s(dc); + if (ra != 0 && rb != 0) { + gen_helper_float_mul_d(cpu_R[rd], cpu_env, cpu_R[ra], cpu_R[rb]); + } else { + tcg_gen_ori_tl(fpcsr, fpcsr, FPCSR_ZF); + tcg_gen_movi_i64(cpu_R[rd], 0x0); + } + break; + + case 0x13: /*lf.div.d*/ + LOG_DIS("lf.div.d r%d, r%d, r%d\n", rd, ra, rb); + check_of64s(dc); + gen_helper_float_div_d(cpu_R[rd], cpu_env, cpu_R[ra], cpu_R[rb]); + break; + + case 0x14: /*lf.itof.d*/ + LOG_DIS("lf.itof r%d, r%d\n", rd, ra); + check_of64s(dc); + gen_helper_itofd(cpu_R[rd], cpu_env, cpu_R[ra]); + break; + + case 0x15: /*lf.ftoi.d*/ + LOG_DIS("lf.ftoi r%d, r%d\n", rd, ra); + check_of64s(dc); + gen_helper_ftoid(cpu_R[rd], cpu_env, cpu_R[ra]); + break; + + case 0x16: /*lf.rem.d*/ + LOG_DIS("lf.rem.d r%d, r%d, r%d\n", rd, ra, rb); + check_of64s(dc); + gen_helper_float_rem_d(cpu_R[rd], cpu_env, cpu_R[ra], cpu_R[rb]); + break; + + case 0x17: /*lf.madd.d*/ + LOG_DIS("lf.madd.d r%d, r%d, r%d\n", rd, ra, rb); + check_of64s(dc); + gen_helper_float_muladd_d(cpu_R[rd], cpu_env, cpu_R[ra], cpu_R[rb]); + break; + + case 0x18: /*lf.sfeq.d*/ + LOG_DIS("lf.sfeq.d r%d, r%d\n", ra, rb); + check_of64s(dc); + gen_helper_float_eq_d(env_btaken, cpu_env, cpu_R[ra], cpu_R[rb]); + break; + + case 0x1a: /*lf.sfgt.d*/ + LOG_DIS("lf.sfgt.d r%d, r%d\n", ra, rb); + check_of64s(dc); + gen_helper_float_gt_d(env_btaken, cpu_env, cpu_R[ra], cpu_R[rb]); + break; + + case 0x1b: /*lf.sfge.d*/ + LOG_DIS("lf.sfge.d r%d, r%d\n", ra, rb); + check_of64s(dc); + gen_helper_float_ge_d(env_btaken, cpu_env, cpu_R[ra], cpu_R[rb]); + break; + + case 0x19: /*lf.sfne.d*/ + LOG_DIS("lf.sfne.d r%d, r%d\n", ra, rb); + check_of64s(dc); + gen_helper_float_ne_d(env_btaken, cpu_env, cpu_R[ra], cpu_R[rb]); + break; + + case 0x1c: /*lf.sflt.d*/ + LOG_DIS("lf.sflt.d r%d, r%d\n", ra, rb); + check_of64s(dc); + gen_helper_float_lt_d(env_btaken, cpu_env, cpu_R[ra], cpu_R[rb]); + break; + + case 0x1d: /*lf.sfle.d*/ + LOG_DIS("lf.sfle.d r%d, r%d\n", ra, rb); + check_of64s(dc); + gen_helper_float_le_d(env_btaken, cpu_env, cpu_R[ra], cpu_R[rb]); + break; +#endif + + default: + gen_illegal_exception(dc); + break; + } + wb_SR_F(); +} + +static void disas_openrisc_insn(DisasContext *dc, CPUOpenRISCState *env) +{ + uint32_t op0; + uint32_t insn; + insn = cpu_ldl_code(env, dc->pc); + op0 = field(insn, 26, 6); + + switch (op0) { + case 0x06: + dec_M(dc, env, insn); + break; + + case 0x08: + dec_sys(dc, env, insn); + break; + + case 0x2e: + dec_logic(dc, env, insn); + break; + + case 0x2f: + dec_compi(dc, env, insn); + break; + + case 0x31: + dec_mac(dc, env, insn); + break; + + case 0x32: + dec_float(dc, env, insn); + break; + + case 0x38: + dec_calc(dc, env, insn); + break; + + case 0x39: + dec_comp(dc, env, insn); + break; + + default: + dec_misc(dc, env, insn); + break; + } +} + +static void check_breakpoint(CPUOpenRISCState *env, DisasContext *dc) +{ + CPUBreakpoint *bp; + + if (unlikely(!QTAILQ_EMPTY(&env->breakpoints))) { + QTAILQ_FOREACH(bp, &env->breakpoints, entry) { + if (bp->pc == dc->pc) { + tcg_gen_movi_tl(cpu_pc, dc->pc); + gen_exception(dc, EXCP_DEBUG); + dc->is_jmp = DISAS_UPDATE; + } + } + } } static inline void gen_intermediate_code_internal(CPUOpenRISCState *env, TranslationBlock *tb, int search_pc) { + struct DisasContext ctx, *dc = &ctx; + uint16_t *gen_opc_end; + uint32_t pc_start; + int j, k; + uint32_t next_page_start; + int num_insns; + int max_insns; + + qemu_log_try_set_file(stderr); + + pc_start = tb->pc; + dc->env = env; + dc->tb = tb; + + gen_opc_end = gen_opc_buf + OPC_MAX_SIZE; + dc->is_jmp = DISAS_NEXT; + dc->ppc = pc_start; + dc->pc = pc_start; + dc->flags = env->cpucfgr; + dc->mem_idx = cpu_mmu_index(env); + dc->synced_flags = dc->tb_flags = tb->flags; + dc->delayed_branch = !!(dc->tb_flags & D_FLAG); + dc->singlestep_enabled = env->singlestep_enabled; + if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) { + qemu_log("-----------------------------------------\n"); + log_cpu_state(env, 0); + } + + next_page_start = (pc_start & TARGET_PAGE_MASK) + TARGET_PAGE_SIZE; + k = -1; + num_insns = 0; + max_insns = tb->cflags & CF_COUNT_MASK; + + if (max_insns == 0) { + max_insns = CF_COUNT_MASK; + } + + gen_icount_start(); + + do { + check_breakpoint(env, dc); + if (search_pc) { + j = gen_opc_ptr - gen_opc_buf; + if (k < j) { + k++; + while (k < j) { + gen_opc_instr_start[k++] = 0; + } + } + gen_opc_pc[k] = dc->pc; + gen_opc_instr_start[k] = 1; + gen_opc_icount[k] = num_insns; + } + + if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP))) { + tcg_gen_debug_insn_start(dc->pc); + } + + if (num_insns + 1 == max_insns && (tb->cflags & CF_LAST_IO)) { + gen_io_start(); + } + dc->ppc = dc->pc - 4; + dc->npc = dc->pc + 4; + tcg_gen_movi_tl(cpu_ppc, dc->ppc); + tcg_gen_movi_tl(cpu_npc, dc->npc); + disas_openrisc_insn(dc, env); + dc->pc = dc->npc; + num_insns++; + /* delay slot */ + if (dc->delayed_branch) { + dc->delayed_branch--; + if (!dc->delayed_branch) { + dc->tb_flags &= ~D_FLAG; + gen_sync_flags(dc); + tcg_gen_mov_tl(cpu_pc, jmp_pc); + tcg_gen_mov_tl(cpu_npc, jmp_pc); + tcg_gen_movi_tl(jmp_pc, 0); + tcg_gen_exit_tb(0); + dc->is_jmp = DISAS_JUMP; + break; + } + } + } while (!dc->is_jmp + && gen_opc_ptr < gen_opc_end + && !env->singlestep_enabled + && !singlestep + && (dc->pc < next_page_start) + && num_insns < max_insns); + + if (tb->cflags & CF_LAST_IO) { + gen_io_end(); + } + if (dc->is_jmp == DISAS_NEXT) { + dc->is_jmp = DISAS_UPDATE; + tcg_gen_movi_tl(cpu_pc, dc->pc); + } + if (unlikely(env->singlestep_enabled)) { + if (dc->is_jmp == DISAS_NEXT) { + tcg_gen_movi_tl(cpu_pc, dc->pc); + } + gen_exception(dc, EXCP_DEBUG); + } else { + switch (dc->is_jmp) { + case DISAS_NEXT: + gen_goto_tb(dc, 0, dc->pc); + break; + default: + case DISAS_JUMP: + break; + case DISAS_UPDATE: + /* indicate that the hash table must be used + to find the next TB */ + tcg_gen_exit_tb(0); + break; + case DISAS_TB_JUMP: + /* nothing more to generate */ + break; + } + } + + gen_icount_end(tb, num_insns); + *gen_opc_ptr = INDEX_op_end; + if (search_pc) { + j = gen_opc_ptr - gen_opc_buf; + k++; + while (k <= j) { + gen_opc_instr_start[k++] = 0; + } + } else { + tb->size = dc->pc - pc_start; + tb->icount = num_insns; + } + +#ifdef DEBUG_DISAS + if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) { + qemu_log("\n"); + log_target_disas(pc_start, dc->pc - pc_start, 0); + qemu_log("\nisize=%d osize=%td\n", + dc->pc - pc_start, gen_opc_ptr - gen_opc_buf); + } +#endif }
Quoted 5 lines
Quoted 5 lines
target-openrisc/translate.c +0
-1void gen_intermediate_code(CPUOpenRISCState *env, struct TranslationBlock *tb) --1.7.9.5
Regards,
Jia.
Re: [Qemu-devel] [PATCH v5 12/16] target-or32: Add system instructions
In reply to Jia LiuQuoted 103 lines · Jia Liu
Hi Blue,
Thank you for review.
Is this code OK?void HELPER(mtspr)(CPUOpenRISCState * env,
target_ulongra,target_ulongrb,target_ulongoffset) {
#ifndefCONFIG_USER_ONLY
int spr = (ra | offset);
int idx;switch (spr) {
caseTO_SPR(0, 0): /* VR */
env->vr = rb;
break;case
TO_SPR(0, 16): /* NPC */
env->npc = rb;
break;case
TO_SPR(0, 17): /* SR */
if ((env->sr& (SR_IME|SR_DME|SR_SM)) ^ (rb & (SR_IME|SR_DME|SR_SM))) {tlb_flush(env, 1);
}
env->sr = rb;
env->sr |=SR_FO; /* FO is const equal to 1 */ if (env->sr&SR_DME) {env->tlb->map_address_data=&get_phys_data; } else {
env->tlb->map_address_data =&get_phys_nommu; }if (
env->sr&SR_IME) {env->tlb->map_address_code=&get_phys_code; } else {
env->tlb->map_address_code =&get_phys_nommu; }
break;case
TO_SPR(0, 18): /* PPC */
env->ppc = rb;
break;case
TO_SPR(0, 32): /* EPCR */
env->epcr = rb;
break;case
TO_SPR(0, 48): /* EEAR */
env->eear = rb;
break;case
TO_SPR(0, 64): /* ESR */
env->esr = rb;
break;
caseTO_SPR(1, 512)...TO_SPR(1, 639): /* DTLBW0MR 0-127 */ idx = spr -TO_SPR(1, 512);
if (!(rb & 1)) {
tlb_flush_page(env, env->tlb->dtlb[0][idx].mr &TARGET_PAGE_MASK); }
env->tlb->dtlb[0][idx].mr = rb;
break;case
TO_SPR(1, 640)...TO_SPR(1, 767): /* DTLBW0TR 0-127 */ idx = spr -TO_SPR(1, 640);
env->tlb->dtlb[0][idx].tr = rb;
break;
caseTO_SPR(1, 768)...TO_SPR(1, 895): /* DTLBW1MR 0-127 */ caseTO_SPR(1, 896)...TO_SPR(1, 1023): /* DTLBW1TR 0-127 */ caseTO_SPR(1, 1024)...TO_SPR(1, 1151): /* DTLBW2MR 0-127 */ caseTO_SPR(1, 1152)...TO_SPR(1, 1279): /* DTLBW2TR 0-127 */ caseTO_SPR(1, 1280)...TO_SPR(1, 1407): /* DTLBW3MR 0-127 */ caseTO_SPR(1, 1408)...TO_SPR(1, 1535): /* DTLBW3TR 0-127 */ break;
caseTO_SPR(2, 512)...TO_SPR(2, 639): /* ITLBW0MR 0-127 */ idx = spr -TO_SPR(2, 512);
if (!(rb & 1)) {
tlb_flush_page(env, env->tlb->itlb[0][idx].mr &TARGET_PAGE_MASK); }
env->tlb->itlb[0][idx].mr = rb;
break;case
TO_SPR(2, 640)...TO_SPR(2, 767): /* ITLBW0TR 0-127 */ idx = spr -TO_SPR(2, 640); env->tlb->itlb[0][idx].tr = rb;
break;
caseTO_SPR(2, 768)...TO_SPR(2, 895): /* ITLBW1MR 0-127 */ caseTO_SPR(2, 896)...TO_SPR(2, 1023): /* ITLBW1TR 0-127 */ caseTO_SPR(2, 1024)...TO_SPR(2, 1151): /* ITLBW2MR 0-127 */ caseTO_SPR(2, 1152)...TO_SPR(2, 1279): /* ITLBW2TR 0-127 */ caseTO_SPR(2, 1280)...TO_SPR(2, 1407): /* ITLBW3MR 0-127 */ caseTO_SPR(2, 1408)...TO_SPR(2, 1535): /* ITLBW3TR 0-127 */ break;
caseTO_SPR(9, 0): /* PICMR */cpu_openrisc_store_picmr(env, rb);
break;
caseTO_SPR(9, 2): /* PICSR */cpu_openrisc_store_picsr(env, rb);
break;
caseTO_SPR(10, 0): /* TTMR */cpu_openrisc_store_compare(env, rb);
break;
Quoted 8 lines
case
TO_SPR(10, 1): /* TTCR */
cpu_openrisc_store_count(env, rb);
break;
default:
break;
}
#endif
}
OK
Quoted 11 lines
target_ulongHELPER(mfspr)(CPUOpenRISCState * env,
target_ulongrd,target_ulongra,uint32_toffset) {
#ifndefCONFIG_USER_ONLY
int spr = (ra | offset);
int idx;switch (spr) {
caseTO_SPR(0, 0): /* VR */
return (env->vr&SPR_VR);
Parentheses are not necessary.
Quoted 72 lines
case
TO_SPR(0, 1): /* UPR */
return (env->upr); /* TT, DM, IM, UP present */case
TO_SPR(0, 2): /* CPUCFGR */
return (env->cpucfgr);case
TO_SPR(0, 3): /* DMMUCFGR */
return (env->dmmucfgr); /* 1Way, 64 entries */case
TO_SPR(0, 4): /* IMMUCFGR */
return (env->immucfgr);case
TO_SPR(0, 16): /* NPC */
return (env->npc);case
TO_SPR(0, 17): /* SR */
return (env->sr);case
TO_SPR(0, 18): /* PPC */
return (env->ppc);case
TO_SPR(0, 32): /* EPCR */
return (env->epcr);case
TO_SPR(0, 48): /* EEAR */
return (env->eear);case
TO_SPR(0, 64): /* ESR */
return (env->esr);case
TO_SPR(1, 512)...TO_SPR(1, 639): /* DTLBW0MR 0-127 */ idx = spr -TO_SPR(1, 512);
return (env->tlb->dtlb[0][idx].mr);case
TO_SPR(1, 640)...TO_SPR(1, 767): /* DTLBW0TR 0-127 */ idx = spr -TO_SPR(1, 640);
return (env->tlb->dtlb[0][idx].tr);case
TO_SPR(1, 768)...TO_SPR(1, 895): /* DTLBW1MR 0-127 */ caseTO_SPR(1, 896)...TO_SPR(1, 1023): /* DTLBW1TR 0-127 */ caseTO_SPR(1, 1024)...TO_SPR(1, 1151): /* DTLBW2MR 0-127 */ caseTO_SPR(1, 1152)...TO_SPR(1, 1279): /* DTLBW2TR 0-127 */ caseTO_SPR(1, 1280)...TO_SPR(1, 1407): /* DTLBW3MR 0-127 */ caseTO_SPR(1, 1408)...TO_SPR(1, 1535): /* DTLBW3TR 0-127 */ break;case
TO_SPR(2, 512)...TO_SPR(2, 639): /* ITLBW0MR 0-127 */ idx = spr -TO_SPR(2, 512);
return (env->tlb->itlb[0][idx].mr);case
TO_SPR(2, 640)...TO_SPR(2, 767): /* ITLBW0TR 0-127 */ idx = spr -TO_SPR(2, 640);
return (env->tlb->itlb[0][idx].tr);case
TO_SPR(2, 768)...TO_SPR(2, 895): /* ITLBW1MR 0-127 */ caseTO_SPR(2, 896)...TO_SPR(2, 1023): /* ITLBW1TR 0-127 */ caseTO_SPR(2, 1024)...TO_SPR(2, 1151): /* ITLBW2MR 0-127 */ caseTO_SPR(2, 1152)...TO_SPR(2, 1279): /* ITLBW2TR 0-127 */ caseTO_SPR(2, 1280)...TO_SPR(2, 1407): /* ITLBW3MR 0-127 */ caseTO_SPR(2, 1408)...TO_SPR(2, 1535): /* ITLBW3TR 0-127 */ break;case
TO_SPR(9, 0): /* PICMR */
return (env->picmr);case
TO_SPR(9, 2): /* PICSR */
return (env->picsr);case
TO_SPR(10, 0): /* TTMR */
return (env->ttmr);
Quoted 8 lines
case
TO_SPR(10, 1): /* TTCR */
returncpu_openrisc_get_count(env);default:
break;
}
#endif
return rd;
Is this correct, maybe 0 would be a nice value for unknown SPRs, or is rd the default value?
If you later need to add tracepoints (or debug printfs) for the return value, it may be useful to structure the code like this:target_ulong ret = 0;
switch() {
case x:
ret = y;
break;
case z:
ret = 42;
break;
...
}
/* later something like trace_spr_read(ret); */
return ret;
Quoted 12 lines
}
case
0x2d: /*l.mfspr*/
LOG_DIS("l.mfspr r%d, r%d, %d\n", rd, ra, I16);
{
TCGv_i32 ti =tcg_const_i32(I16);gen_helper_mfspr(cpu_R[rd], cpu_env, cpu_R[rd], cpu_R[ra], ti);tcg_temp_free_i32(ti);
}
break;
Quoted 8 lines
case
0x30: /*l.mtspr*/
LOG_DIS("l.mtspr %d, r%d, r%d, %d\n", I5, ra, rb, I11); {
TCGv_i32 im =tcg_const_i32(tmp);gen_helper_mtspr(cpu_env, cpu_R[ra], cpu_R[rb], im);tcg_temp_free_i32(im);
}
break;
OK
Quoted 347 lines · Blue Swirl
Quoted 327 lines · Jia Liu
Quoted 167 lines
Add OpenRISC system instruction support.
Signed-off-by Jia Liu <[email protected]>---
target-openrisc/Makefile.objs | 3 +-
target-openrisc/helper.h | 4 +target-openrisc/sys_helper.c| 233 +++++++++++++++++++++++++++++++++++++++++target-openrisc/translate.c| 20 ++++4 files changed, 259 insertions(+), 1 deletion(-)create mode 100644
target-openrisc/sys_helper.ctarget-openrisc/Makefile.objs +0
-0@@ -1,3 +1,4 @@obj-$(CONFIG_SOFTMMU) += machine.o
obj-y += cpu.o excp.o intrpt.o mmu.o translate.otarget-openrisc/Makefile.objs +2
-1-obj-y += excp_helper.o fpu_helper.o int_helper.o intrpt_helper.o mmu_helper.o +obj-y += excp_helper.o fpu_helper.o int_helper.o intrpt_helper.o \ + mmu_helper.o sys_helper.otarget-openrisc/helper.h +4
-0@@ -62,4 +62,8 @@ DEF_HELPER_FLAGS_1(fl1, 0, tl, tl) /* interrupt */ DEF_HELPER_FLAGS_1(rfe, 0, void, env) +/* sys */ +DEF_HELPER_FLAGS_4(mtspr, 0, void, env, tl, tl, tl) +DEF_HELPER_FLAGS_4(mfspr, 0, void, env, tl, tl, tl) + #include "def-helper.h"target-openrisc/sys_helper.c new file +127
-0@@ -0,0 +1,233 @@ +/* +* OpenRISC system instructions helper routines +* +* Copyright (c) 2011-2012 Jia Liu <[email protected]> +* Zhizhou Zhang <[email protected]> +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2 of the License, or (at your option) any later version. +* +* This library 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 +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, see <http://www.gnu.org/licenses/>. +*/ + +#include "cpu.h" +#include "helper.h" + +#define TO_SPR (group, number) (((group) << 11) + (number)) + +void HELPER (mtspr )(CPUOpenRISCState * env, + target_ulong ra, target_ulong rb, target_ulong offset) +{ +#if !defined(CONFIG_USER_ONLY ) + int spr = (ra | offset); + int idx; + + switch (spr) { + case TO_SPR(0, 0): /* VR */ + env->vr = rb; + break; + + case TO_SPR(0, 16): /* NPC */ + env->npc = rb; + break; + + case TO_SPR(0, 17): /* SR */ + if ((env->sr & (SR_IME | SR_DME | SR_SM)) ^ + (rb & (SR_IME | SR_DME | SR_SM))) { + tlb_flush(env, 1); + } + env->sr = rb; + env->sr |= SR_FO; /* FO is const equal to 1 */ + if (env->sr & SR_DME) { + env->tlb->map_address_data = &get_phys_data; + } else { + env->tlb->map_address_data = &get_phys_nommu; + } + + if (env->sr & SR_IME) { + env->tlb->map_address_code = &get_phys_code; + } else { + env->tlb->map_address_code = &get_phys_nommu; + } + break; + + case TO_SPR(0, 18): /* PPC */ + env->ppc = rb; + break; + + case TO_SPR(0, 32): /* EPCR */ + env->epcr = rb; + break; + + case TO_SPR(0, 48): /* EEAR */ + env->eear = rb; + break; + + case TO_SPR(0, 64): /* ESR */ + env->esr = rb; + break; + case TO_SPR(1, 512) ... TO_SPR(1, 639): /* DTLBW0MR 0-127 */ + idx = spr - TO_SPR(1, 512); + if (!(rb & 1)) { + tlb_flush_page(env, env->tlb->dtlb[0][idx].mr & TARGET_PAGE_MASK); + } + env->tlb->dtlb[0][idx].mr = rb; + break; + + case TO_SPR(1, 640) ... TO_SPR(1, 767): /* DTLBW0TR 0-127 */ + idx = spr - TO_SPR(1, 640); + env->tlb->dtlb[0][idx].tr = rb; + break; + case TO_SPR(1, 768) ... TO_SPR(1, 895): /* DTLBW1MR 0-127 */ + case TO_SPR(1, 896) ... TO_SPR(1, 1023): /* DTLBW1TR 0-127 */ + case TO_SPR(1, 1024) ... TO_SPR(1, 1151): /* DTLBW2MR 0-127 */ + case TO_SPR(1, 1152) ... TO_SPR(1, 1279): /* DTLBW2TR 0-127 */ + case TO_SPR(1, 1280) ... TO_SPR(1, 1407): /* DTLBW3MR 0-127 */ + case TO_SPR(1, 1408) ... TO_SPR(1, 1535): /* DTLBW3TR 0-127 */ + break; + case TO_SPR(2, 512) ... TO_SPR(2, 639): /* ITLBW0MR 0-127 */ + idx = spr - TO_SPR(2, 512); + if (!(rb & 1)) { + tlb_flush_page(env, env->tlb->itlb[0][idx].mr & TARGET_PAGE_MASK); + } + env->tlb->itlb[0][idx].mr = rb; + break; + + case TO_SPR(2, 640) ... TO_SPR(2, 767): /* ITLBW0TR 0-127 */ + idx = spr - TO_SPR(2, 640); + env->tlb->itlb[0][idx].tr = rb; + break; + case TO_SPR(2, 768) ... TO_SPR(2, 895): /* ITLBW1MR 0-127 */ + case TO_SPR(2, 896) ... TO_SPR(2, 1023): /* ITLBW1TR 0-127 */ + case TO_SPR(2, 1024) ... TO_SPR(2, 1151): /* ITLBW2MR 0-127 */ + case TO_SPR(2, 1152) ... TO_SPR(2, 1279): /* ITLBW2TR 0-127 */ + case TO_SPR(2, 1280) ... TO_SPR(2, 1407): /* ITLBW3MR 0-127 */ + case TO_SPR(2, 1408) ... TO_SPR(2, 1535): /* ITLBW3TR 0-127 */ + break; + case TO_SPR(9, 0): /* PICMR */ + cpu_openrisc_store_picmr(env, rb); + break; + case TO_SPR(9, 2): /* PICSR */ + cpu_openrisc_store_picsr(env, rb); + break; + case TO_SPR(10, 0): /* TTMR */ + cpu_openrisc_store_compare(env, rb); + break; + case TO_SPR(10, 1): /* TTCR */ + cpu_openrisc_store_count(env, rb); + break; + default:target-openrisc/sys_helper.c line 137
Quoted 10 lines
target-openrisc/sys_helper.c new file +10
-0+ break; + } +#endif +} + +void HELPER (mfspr )(CPUOpenRISCState * env, + target_ulong rd, target_ulong ra, uint32_t offset) +{ +#if !defined(CONFIG_USER_ONLY ) + int spr = env->gpr[ra] | offset;[1]
Quoted 80 lines
target-openrisc/sys_helper.c new file +80
-0+ int idx; + + switch (spr) { + case TO_SPR(0, 0): /* VR */ + env->gpr[rd] = (env->vr & SPR_VR); + break; + + case TO_SPR(0, 1): /* UPR */ + env->gpr[rd] = env->upr; /* TT, DM, IM, UP present */ + break; + + case TO_SPR(0, 2): /* CPUCFGR */ + env->gpr[rd] = env->cpucfgr; + break; + + case TO_SPR(0, 3): /* DMMUCFGR */ + env->gpr[rd] = env->dmmucfgr; /* 1Way, 64 entries */ + break; + case TO_SPR(0, 4): /* IMMUCFGR */ + env->gpr[rd] = env->immucfgr; + break; + + case TO_SPR(0, 16): /* NPC */ + env->gpr[rd] = env->npc; + break; + + case TO_SPR(0, 17): /* SR */ + env->gpr[rd] = env->sr; + break; + + case TO_SPR(0, 18): /* PPC */ + env->gpr[rd] = env->ppc; + break; + + case TO_SPR(0, 32): /* EPCR */ + env->gpr[rd] = env->epcr; + break; + + case TO_SPR(0, 48): /* EEAR */ + env->gpr[rd] = env->eear; + break; + + case TO_SPR(0, 64): /* ESR */ + env->gpr[rd] = env->esr; + break; + + case TO_SPR(1, 512) ... TO_SPR(1, 639): /* DTLBW0MR 0-127 */ + idx = spr - TO_SPR(1, 512); + env->gpr[rd] = env->tlb->dtlb[0][idx].mr; + break; + + case TO_SPR(1, 640) ... TO_SPR(1, 767): /* DTLBW0TR 0-127 */ + idx = spr - TO_SPR(1, 640); + env->gpr[rd] = env->tlb->dtlb[0][idx].tr; + break; + case TO_SPR(1, 768) ... TO_SPR(1, 895): /* DTLBW1MR 0-127 */ + case TO_SPR(1, 896) ... TO_SPR(1, 1023): /* DTLBW1TR 0-127 */ + case TO_SPR(1, 1024) ... TO_SPR(1, 1151): /* DTLBW2MR 0-127 */ + case TO_SPR(1, 1152) ... TO_SPR(1, 1279): /* DTLBW2TR 0-127 */ + case TO_SPR(1, 1280) ... TO_SPR(1, 1407): /* DTLBW3MR 0-127 */ + case TO_SPR(1, 1408) ... TO_SPR(1, 1535): /* DTLBW3TR 0-127 */ + break; + + case TO_SPR(2, 512) ... TO_SPR(2, 639): /* ITLBW0MR 0-127 */ + idx = spr - TO_SPR(2, 512); + env->gpr[rd] = env->tlb->itlb[0][idx].mr; + break; + + case TO_SPR(2, 640) ... TO_SPR(2, 767): /* ITLBW0TR 0-127 */ + idx = spr - TO_SPR(2, 640); + env->gpr[rd] = env->tlb->itlb[0][idx].tr; + break; + case TO_SPR(2, 768) ... TO_SPR(2, 895): /* ITLBW1MR 0-127 */ + case TO_SPR(2, 896) ... TO_SPR(2, 1023): /* ITLBW1TR 0-127 */ + case TO_SPR(2, 1024) ... TO_SPR(2, 1151): /* ITLBW2MR 0-127 */ + case TO_SPR(2, 1152) ... TO_SPR(2, 1279): /* ITLBW2TR 0-127 */ + case TO_SPR(2, 1280) ... TO_SPR(2, 1407): /* ITLBW3MR 0-127 */ + case TO_SPR(2, 1408) ... TO_SPR(2, 1535): /* ITLBW3TR 0-127 */ + break; + case TO_SPR(9, 0): /* PICMR */target-openrisc/sys_helper.c line 227
Quoted 10 lines
target-openrisc/sys_helper.c new file +10
-0+ env->gpr[rd] = env->picmr; + break; + case TO_SPR(9, 2): /* PICSR */ + env->gpr[rd] = env->picsr; + break; + case TO_SPR(10, 0): /* TTMR */ + env->gpr[rd] = env->ttmr; + break; + case TO_SPR(10, 1): /* TTCR */ + env->gpr[rd] = cpu_openrisc_get_count(env);[2]
Quoted 12 lines
target-openrisc/sys_helper.c new file +6
-0+ break; + default: + break; + } +#endif +}target-openrisc/translate.c +0
-0@@ -1241,10 +1241,30 @@ static void dec_misc(DisasContext *dc, CPUOpenRISCState *env, uint32_t insn)Quoted 7 lines
case
0x2d: /*l.mfspr*/
LOG_DIS("l.mfspr r%d, r%d, %d\n", rd, ra, I16);
+ {
+ TCGv_i32 ti =tcg_const_i32(I16);
+ TCGv td =tcg_const_tl(rd);
+ TCGv ta =tcg_const_tl(ra);
+ gen_helper_mfspr(cpu_env, td, ta, ti);The helper should a return
target_ulong, so the line would becomegen_helper_mfspr(cpu_R[rd], cpu_env, td, cpu_R[ra], ti);Then the register moves inside the mfspr helper could be avoided:
[1]Quoted 1 line
+ int spr = env->gpr[ra] | offset;
int spr = ra | offset;
As an example [2]:
Quoted 1 line
+ env->gpr[rd] =
cpu_openrisc_get_count(env);return
cpu_openrisc_get_count(env);Quoted 4 lines
+ tcg_temp_free_i32(ti);
+ tcg_temp_free(td);
+ tcg_temp_free(ta);
+ }Also here you could try later to avoid to compile
sys_helper.cfor user emulator by surrounding the previous block by #ifndef CONFIG_USER_ONLY/#endif (ditto for mtspr).Quoted 11 lines
break;
case
0x30: /*l.mtspr*/
LOG_DIS("l.mtspr %d, r%d, r%d, %d\n", I5, ra, rb, I11);
+ {
+ TCGv_i32 im =tcg_const_i32(tmp);
+ TCGv ta =tcg_temp_new();
+ TCGv tb =tcg_temp_new();
+ tcg_gen_mov_tl(ta, cpu_R[ra]);
+ tcg_gen_mov_tl(tb, cpu_R[rb]);
+ gen_helper_mtspr(cpu_env, ta, tb, im);Quoted 14 lines
Simply
gen_helper_mtspr(cpu_env, cpu_R[ra], cpu_R[rb], im);Quoted 11 lines
+ tcg_temp_free_i32(im);
+ tcg_temp_free(ta);
+ tcg_temp_free(tb);
+ }
break;case
0x34: /*l.sd*/
--
1.7.9.5Regards,
Jia.
Re: [Qemu-devel] [PATCH v5 08/16] target-or32: Add translation routines
In reply to Jia LiuQuoted 587 lines · Jia Liu
Hi Blue,
Thanks.
Quoted 342 lines · Blue Swirl
Quoted 341 lines · Jia Liu
Add OpenRISC translation routines.
Signed-off-by Jia Liu <[email protected]>---
target-openrisc/translate.c | 1941 +++++++++++++++++++++++++++++++++++++++++++1 file changed, 1941 insertions(+)target-openrisc/translate.c +317
-0@@ -26,6 +26,10 @@ #include "qemu-log.h" #include "config.h" +#include "helper.h" +#define GEN_HELPER 1 +#include "helper.h" + #define OPENRISC_DISAS #ifdef OPENRISC_DISAS@@ -34,14 +38,1951 @@ # define LOG_DIS(...) do { } while (0) #endif +typedef struct DisasContext { + CPUOpenRISCState *env; + TranslationBlock *tb; + target_ulong pc, ppc, npc; + uint32_t tb_flags, synced_flags, flags; + uint32_t is_jmp; + uint32_t mem_idx; + int singlestep_enabled; + uint32_t delayed_branch; +}DisasContext ; + +static TCGv_ptr cpu_env; +static TCGv cpu_sr; +static TCGv cpu_R[32 ]; +static TCGv cpu_pc; +static TCGv jmp_pc; /* l.jr/l.jalr temp pc */ +static TCGv cpu_npc; +static TCGv cpu_ppc; +static TCGv_i32 env_btaken; /* bf/bnf , F flag taken */ +static TCGv_i32 fpcsr; +static TCGv machi, maclo; +static TCGv fpmaddhi, fpmaddlo; +static TCGv_i32 env_flags; +#include "gen-icount.h" + void openrisc_translate_init(void) { + static const char * const regnames[] = { + "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", + "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", + "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23", + "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31", + }; + int i; + + cpu_env = tcg_global_reg_new_ptr(TCG_AREG0, "env"); + cpu_sr = tcg_global_mem_new(TCG_AREG0, + offsetof(CPUOpenRISCState, sr), "sr"); + env_flags = tcg_global_mem_new_i32(TCG_AREG0, + offsetof(CPUOpenRISCState, flags), + "flags"); + cpu_pc = tcg_global_mem_new(TCG_AREG0, + offsetof(CPUOpenRISCState, pc), "pc"); + cpu_npc = tcg_global_mem_new(TCG_AREG0, + offsetof(CPUOpenRISCState, npc), "npc"); + cpu_ppc = tcg_global_mem_new(TCG_AREG0, + offsetof(CPUOpenRISCState, ppc), "ppc"); + jmp_pc = tcg_global_mem_new(TCG_AREG0, + offsetof(CPUOpenRISCState, jmp_pc), "jmp_pc"); + env_btaken = tcg_global_mem_new_i32(TCG_AREG0, + offsetof(CPUOpenRISCState, btaken), + "btaken"); + fpcsr = tcg_global_mem_new_i32(TCG_AREG0, + offsetof(CPUOpenRISCState, fpcsr), + "fpcsr"); + machi = tcg_global_mem_new(TCG_AREG0, + offsetof(CPUOpenRISCState, machi), + "machi"); + maclo = tcg_global_mem_new(TCG_AREG0, + offsetof(CPUOpenRISCState, maclo), + "maclo"); + fpmaddhi = tcg_global_mem_new(TCG_AREG0, + offsetof(CPUOpenRISCState, fpmaddhi), + "fpmaddhi"); + fpmaddlo = tcg_global_mem_new(TCG_AREG0, + offsetof(CPUOpenRISCState, fpmaddlo), + "fpmaddlo"); + for (i = 0; i < 32; i++) { + cpu_R[i] = tcg_global_mem_new(TCG_AREG0, + offsetof(CPUOpenRISCState, gpr[i]), + regnames[i]); + } +#define GEN_HELPER 2 +#include "helper.h" +} + +/* Writeback SR_F transaltion-space to execution-space. */ +static inline void wb_SR_F (void ) +{ + int label; + + label = gen_new_label(); + tcg_gen_andi_tl(cpu_sr, cpu_sr, ~SR_F); + tcg_gen_brcondi_tl(TCG_COND_EQ, env_btaken, 0, label); + tcg_gen_ori_tl(cpu_sr, cpu_sr, SR_F); + gen_set_label(label); +} + +static inline int zero_extend (unsigned int val,int width) +{ + return val & ((1 << width) - 1); +} + +static inline int sign_extend (unsigned int val,int width) +{ + int sval; + + /* LSL */ + val <<= TARGET_LONG_BITS - width; + sval = val; + /* ASR. */ + sval >>= TARGET_LONG_BITS - width; + return sval; +} + +static inline void gen_sync_flags (DisasContext *dc) +{ + /* Sync the tb dependent flag between translate and runtime. */ + if (dc->tb_flags != dc->synced_flags) { + tcg_gen_movi_tl(env_flags, dc->tb_flags); + dc->synced_flags = dc->tb_flags; + } +} + +static void gen_exception (DisasContext *dc,unsigned int excp) +{ + TCGv_i32 tmp = tcg_const_i32(excp); + gen_helper_exception(cpu_env, tmp); + tcg_temp_free_i32(tmp); +} + +static void gen_illegal_exception (DisasContext *dc) +{ + tcg_gen_movi_tl(cpu_pc, dc->pc); + gen_exception(dc, EXCP_ILLEGAL); + dc->is_jmp = DISAS_UPDATE; +} + +#ifdef TARGET_OPENRISC64 +static void check_ob64s (DisasContext *dc) +{ + if (!(dc->flags & CPUCFGR_OB64S)) { + gen_illegal_exception(dc); + } +} + +static void check_of64s (DisasContext *dc) +{ + if (!(dc->flags & CPUCFGR_OF64S)) { + gen_illegal_exception(dc); + } +} + +/* not used yet, open it when we need or64. */ +/*static void check_ov64s(DisasContext *dc) +{ +if (!(dc->flags & CPUCFGR_OV64S)) { +gen_illegal_exception(dc); +} +}*/ +#endif + +static void gen_goto_tb (DisasContext *dc,int n,target_ulong dest) +{ + TranslationBlock *tb; + tb = dc->tb; + if ((tb->pc & TARGET_PAGE_MASK) == (dest & TARGET_PAGE_MASK) && + likely(!dc->singlestep_enabled)) { + tcg_gen_movi_tl(cpu_pc, dest); + tcg_gen_goto_tb(n); + tcg_gen_exit_tb((tcg_target_long)tb + n); + } else { + tcg_gen_movi_tl(cpu_pc, dest); + if (dc->singlestep_enabled) { + gen_exception(dc, EXCP_DEBUG); + } + tcg_gen_exit_tb(0); + } +} + +static void gen_jump (DisasContext *dc,uint32_t imm,uint32_t reg,uint32_t op0) +{ + target_ulong tmp_pc; + int lab = gen_new_label(); + TCGv sr_f = tcg_temp_new(); + /* N26, 26bits imm */ + tmp_pc = sign_extend((imm<<2), 26) + dc->pc; + tcg_gen_andi_tl(sr_f, cpu_sr, SR_F); + + if (op0 == 0x00) { /*l.j*/ + tcg_gen_movi_tl(jmp_pc, tmp_pc); + } else if (op0 == 0x01) { /*l.jal*/ + tcg_gen_movi_tl(cpu_R[9], (dc->pc + 8)); + tcg_gen_movi_tl(jmp_pc, tmp_pc); + } else if (op0 == 0x03) { /*l.bnf*/ + tcg_gen_movi_tl(jmp_pc, dc->pc+8); + tcg_gen_brcondi_i32(TCG_COND_EQ, sr_f, SR_F, lab); + tcg_gen_movi_tl(jmp_pc, tmp_pc); + gen_set_label(lab); + } else if (op0 == 0x04) { /*l.bf*/ + tcg_gen_movi_tl(jmp_pc, dc->pc+8); + tcg_gen_brcondi_i32(TCG_COND_NE, sr_f, SR_F, lab); + tcg_gen_movi_tl(jmp_pc, tmp_pc); + gen_set_label(lab); + } else if (op0 == 0x11) { /*l.jr*/ + tcg_gen_mov_tl(jmp_pc, cpu_R[reg]); + } else if (op0 == 0x12) { /*l.jalr*/ + tcg_gen_movi_tl(cpu_R[9], (dc->pc + 8)); + tcg_gen_mov_tl(jmp_pc, cpu_R[reg]); + } else { + gen_illegal_exception(dc); + } + + tcg_temp_free(sr_f); + dc->delayed_branch = 2; + dc->tb_flags |= D_FLAG; + gen_sync_flags(dc); +} + +static inline uint32_t field (uint32_t val,int start,int length) +{ + val >>= start; + val &= ~(~0 << length); + return val; +} + +static void dec_calc (DisasContext *dc,CPUOpenRISCState *env,uint32_t insn) +{ + uint32_t op0, op1, op2; + uint32_t ra, rb, rd; + op0 = field(insn, 0, 4); + op1 = field(insn, 8, 2); + op2 = field(insn, 6, 2); + ra = field(insn, 16, 5); + rb = field(insn, 11, 5); + rd = field(insn, 21, 5); + + switch (op0) { + case 0x0000: + switch (op1) { + case 0x00: /*l.add*/ + LOG_DIS("l.add r%d, r%d, r%d\n", rd, ra, rb); + { + int lab = gen_new_label(); + TCGv_i64 ta = tcg_temp_new_i64(); + TCGv_i64 tb = tcg_temp_new_i64(); + TCGv_i64 td = tcg_temp_local_new_i64(); + TCGv_i32 res = tcg_temp_local_new_i32(); + TCGv_i32 sr_ove = tcg_temp_local_new_i32(); + tcg_gen_extu_i32_i64(ta, cpu_R[ra]); + tcg_gen_extu_i32_i64(tb, cpu_R[rb]); + tcg_gen_add_i64(td, ta, tb); + tcg_gen_trunc_i64_i32(res, td); + tcg_gen_shri_i64(td, td, 31); + tcg_gen_andi_i64(td, td, 0x3); + /* Jump to lab when no overflow. */ + tcg_gen_brcondi_i64(TCG_COND_EQ, td, 0x0, lab); + tcg_gen_brcondi_i64(TCG_COND_EQ, td, 0x3, lab); + tcg_gen_ori_i32(cpu_sr, cpu_sr, (SR_OV | SR_CY)); + tcg_gen_andi_i32(sr_ove, cpu_sr, SR_OVE); + tcg_gen_brcondi_i32(TCG_COND_NE, sr_ove, SR_OVE, lab); + gen_exception(dc, EXCP_RANGE); + gen_set_label(lab); + tcg_gen_mov_i32(cpu_R[rd], res); + tcg_temp_free_i64(ta); + tcg_temp_free_i64(tb); + tcg_temp_free_i64(td); + tcg_temp_free_i32(res); + tcg_temp_free_i32(sr_ove); + } + break; + default: + gen_illegal_exception(dc); + break; + } + break; + + case 0x0001: /*l.addc*/ + switch (op1) { + case 0x00: + LOG_DIS("l.addc r%d, r%d, r%d\n", rd, ra, rb); + { + int lab = gen_new_label(); + TCGv_i64 ta = tcg_temp_new_i64(); + TCGv_i64 tb = tcg_temp_new_i64(); + TCGv_i64 tcy = tcg_temp_local_new_i64(); + TCGv_i64 td = tcg_temp_local_new_i64(); + TCGv_i32 res = tcg_temp_local_new_i32(); + TCGv_i32 sr_cy = tcg_temp_local_new_i32(); + TCGv_i32 sr_ove = tcg_temp_local_new_i32(); + tcg_gen_extu_i32_i64(ta, cpu_R[ra]); + tcg_gen_extu_i32_i64(tb, cpu_R[rb]); + tcg_gen_andi_i32(sr_cy, cpu_sr, SR_CY); + tcg_gen_extu_i32_i64(tcy, sr_cy); + tcg_gen_shri_i64(tcy, tcy, 10); + tcg_gen_add_i64(td, ta, tb); + tcg_gen_add_i64(td, td, tcy); + tcg_gen_trunc_i64_i32(res, td); + tcg_gen_shri_i64(td, td, 32); + tcg_gen_andi_i64(td, td, 0x3); + /* Jump to lab when no overflow. */ + tcg_gen_brcondi_i64(TCG_COND_EQ, td, 0x0, lab); + tcg_gen_brcondi_i64(TCG_COND_EQ, td, 0x3, lab); + tcg_gen_ori_i32(cpu_sr, cpu_sr, (SR_OV | SR_CY)); + tcg_gen_andi_i32(sr_ove, cpu_sr, SR_OVE); + tcg_gen_brcondi_i32(TCG_COND_NE, sr_ove, SR_OVE, lab); + gen_exception(dc, EXCP_RANGE); + gen_set_label(lab); + tcg_gen_mov_i32(cpu_R[rd], res); + tcg_temp_free_i64(ta); + tcg_temp_free_i64(tb); + tcg_temp_free_i64(tcy); + tcg_temp_free_i64(td); + tcg_temp_free_i32(res); + tcg_temp_free_i32(sr_cy); + tcg_temp_free_i32(sr_ove); + } + break; + default: + gen_illegal_exception(dc); + break; + } + break; + + case 0x0002: /*l.sub*/Quoted 8 lines
target-openrisc/translate.c line 362
Quoted 7 lines
target-openrisc/translate.c +7
-0+ switch (op1) { + case 0x00: + LOG_DIS("l.sub r%d, r%d, r%d\n", rd, ra, rb); + { + + +Please trim the above lines.
done.
Quoted 11 lines
target-openrisc/translate.c line 279
Quoted 7 lines
target-openrisc/translate.c +6
-0+ int lab = gen_new_label(); + TCGv_i64 ta = tcg_temp_new_i64(); + TCGv_i64 tb = tcg_temp_new_i64(); + TCGv_i64 td = tcg_temp_local_new_i64(); + TCGv_i32 res = tcg_temp_local_new_i32(); + TCGv_i32 sr_ove = tcg_temp_local_new_i32();It's usual to put an empty line between variable declarations and code for clarity.
added.
Quoted 201 lines
Quoted 106 lines
target-openrisc/translate.c +106
-0+ tcg_gen_extu_i32_i64(ta, cpu_R[ra]); + tcg_gen_extu_i32_i64(tb, cpu_R[rb]); + tcg_gen_sub_i64(td, ta, tb); + tcg_gen_trunc_i64_i32(res, td); + tcg_gen_shri_i64(td, td, 31); + tcg_gen_andi_i64(td, td, 0x3); + /* Jump to lab when no overflow. */ + tcg_gen_brcondi_i64(TCG_COND_EQ, td, 0x0, lab); + tcg_gen_brcondi_i64(TCG_COND_EQ, td, 0x3, lab); + tcg_gen_ori_i32(cpu_sr, cpu_sr, (SR_OV | SR_CY)); + tcg_gen_andi_i32(sr_ove, cpu_sr, SR_OVE); + tcg_gen_brcondi_i32(TCG_COND_NE, sr_ove, SR_OVE, lab); + gen_exception(dc, EXCP_RANGE); + gen_set_label(lab); + tcg_gen_mov_i32(cpu_R[rd], res); + tcg_temp_free_i64(ta); + tcg_temp_free_i64(tb); + tcg_temp_free_i64(td); + tcg_temp_free_i32(res); + tcg_temp_free_i32(sr_ove); + } + break; + default: + gen_illegal_exception(dc); + break; + } + break; + + case 0x0003: /*l.and*/ + switch (op1) { + case 0x00: + LOG_DIS("l.and r%d, r%d, r%d\n", rd, ra, rb); + tcg_gen_and_tl(cpu_R[rd], cpu_R[ra], cpu_R[rb]); + break; + default: + gen_illegal_exception(dc); + break; + } + break; + + case 0x0004: /*l.or*/ + switch (op1) { + case 0x00: + LOG_DIS("l.or r%d, r%d, r%d\n", rd, ra, rb); + tcg_gen_or_tl(cpu_R[rd], cpu_R[ra], cpu_R[rb]); + break; + default: + gen_illegal_exception(dc); + break; + } + break; + + case 0x0005: + switch (op1) { + case 0x00: /*l.xor*/ + LOG_DIS("l.xor r%d, r%d, r%d\n", rd, ra, rb); + tcg_gen_xor_tl(cpu_R[rd], cpu_R[ra], cpu_R[rb]); + break; + default: + gen_illegal_exception(dc); + break; + } + break; + + case 0x0006: + switch (op1) { + case 0x03: /*l.mul*/ + LOG_DIS("l.mul r%d, r%d, r%d\n", rd, ra, rb); + { + if (ra != 0 && rb != 0) { + int lab1 = gen_new_label(); + int lab2 = gen_new_label(); + int lab3 = gen_new_label(); + TCGv_i64 tmp0 = tcg_temp_local_new_i64(); + TCGv_i64 tmp1 = tcg_temp_local_new_i64(); + TCGv_i64 t0 = tcg_temp_local_new_i64(); + TCGv_i32 res = tcg_temp_local_new_i32(); + TCGv_i32 rs = tcg_temp_local_new_i32(); + TCGv_i32 rt = tcg_temp_local_new_i32(); + TCGv_i32 sr_ove = tcg_temp_local_new_i32(); + /* Calculate the result. */ + tcg_gen_extu_i32_i64(tmp0, cpu_R[ra]); + tcg_gen_extu_i32_i64(tmp1, cpu_R[rb]); + tcg_gen_mul_i64(t0, tmp0, tmp1); + tcg_gen_trunc_i64_i32(res, t0); + tcg_gen_shri_i32(rs, res, 31); + tcg_gen_andi_i32(rs, rs, 0x1); + tcg_gen_shri_i64(t0, t0, 32); + tcg_gen_trunc_i64_i32(rt, t0); + /* Overflow or not. */ + tcg_gen_brcondi_i32(TCG_COND_EQ, rs, 0x1, lab1); + tcg_gen_brcondi_i32(TCG_COND_EQ, rt, 0x0, lab2); + tcg_gen_brcondi_i32(TCG_COND_NE, rt, 0x0, lab3); + gen_set_label(lab1); + tcg_gen_brcondi_i32(TCG_COND_EQ, rt, 0xffffffff, lab2); + /* Handle overflow exception. */ + gen_set_label(lab3); + tcg_gen_ori_tl(cpu_sr, cpu_sr, SR_OV); + tcg_gen_ori_tl(cpu_sr, cpu_sr, SR_CY); + tcg_gen_andi_tl(sr_ove, cpu_sr, SR_OVE); + tcg_gen_brcondi_i32(TCG_COND_NE, sr_ove, SR_OVE, lab2); + gen_exception(dc, EXCP_RANGE); + /* Store result. */ + gen_set_label(lab2); + tcg_gen_mov_i32(cpu_R[rd], res); + tcg_temp_free_i32(res);target-openrisc/translate.c line 484
Quoted 10 lines
target-openrisc/translate.c +10
-0+ tcg_temp_free_i64(t0); + tcg_temp_free_i32(rs); + tcg_temp_free_i32(rt); + tcg_temp_free_i64(tmp0); + tcg_temp_free_i64(tmp1); + tcg_temp_free_i32(sr_ove); +#ifdef TARGET_OPENRISC64 + int lab4 = gen_new_label(); + int lab5 = gen_new_label(); + int lab6 = gen_new_label();But here you add variables after code which is not OK (C99 style). Please put them earlier.
Quoted 70 lines
target-openrisc/translate.c +70
-0+ TCGv_i64 t3 = tcg_temp_local_new_i64(); + TCGv_i64 t4 = tcg_temp_local_new_i64(); + TCGv_i64 t5 = tcg_temp_local_new_i64(); + TCGv_i64 t6 = tcg_temp_local_new_i64(); + TCGv_i64 r1 = tcg_temp_local_new_i64(); + TCGv_i64 r2 = tcg_temp_local_new_i64(); + TCGv_i64 r3 = tcg_temp_local_new_i64(); + TCGv_i64 r4 = tcg_temp_local_new_i64(); + TCGv_i32 tp0 = tcg_temp_local_new_i64(); + TCGv_i32 tp1 = tcg_temp_local_new_i64(); + TCGv_i64 t2h = tcg_temp_local_new_i64(); + TCGv_i64 t2l = tcg_temp_local_new_i64(); + TCGv_i64 t3h = tcg_temp_local_new_i64(); + TCGv_i64 t3l = tcg_temp_local_new_i64(); + TCGv_i64 res1 = tcg_temp_local_new_i64(); + TCGv_i64 res0 = tcg_temp_local_new_i64(); + TCGv_i32 sr_ove64 = tcg_temp_local_new_i32(); + /* Calculate the each result, and HIGH. */ + tcg_gen_trunc_i64_i32(tp0, cpu_R[ra]); + tcg_gen_trunc_i64_i32(tp1, cpu_R[rb]); + tcg_gen_shri_i64(t3, cpu_R[ra], 32); + tcg_gen_extu_i32_i64(t4, tp0); + tcg_gen_shri_i64(t5, cpu_R[rb], 32); + tcg_gen_extu_i32_i64(t6, tp1); + tcg_gen_mul_i64(r1, t3, t5); + tcg_gen_mul_i64(r2, t3, t6); + tcg_gen_mul_i64(r3, t5, t5); + tcg_gen_mul_i64(r4, t3, t4); + tcg_gen_shri_i64(t2h, r2, 32); + tcg_gen_shri_i64(t3h, r3, 32); + tcg_gen_trunc_i64_i32(tp0, r2); + tcg_gen_trunc_i64_i32(tp1, r3); + tcg_gen_extu_i32_i64(t2l, tp0); + tcg_gen_extu_i32_i64(t3l, tp1); + tcg_gen_shri_i64(res0, r4); + tcg_gen_add_i64(t2l, t2l, t3l); + tcg_gen_add_i64(res1, t2l, res1); + /* Overflow or not, by t2l CY. */ + tcg_gen_shri_i64(t2l, res1, 32); + tcg_gen_add_i64(r1, t2h, r1); + tcg_gen_add_i64(r1, r1, t3h); + tcg_gen_add_i64(r1, r1, t2l); + tcg_gen_shri_i64(res0, res1, 31); + tcg_gen_andi_i64(res0, res0, 0x1); + tcg_gen_brcondi_i64(TCG_COND_EQ, res0, 0x1, lab4); + tcg_gen_brcondi_i64(TCG_COND_EQ, r1, 0x0, lab5); + tcg_gen_brcondi_i64(TCG_COND_NE, r1, 0x0, lab6); + gen_set_label(lab4); + tcg_gen_brcondi_i64(TCG_COND_EQ, r1, + 0xffffffffffffffff, lab5); + /* Handle overflow exception. */ + gen_set_label(lab6); + tcg_gen_andi_tl(cpu_sr, cpu_sr, SR_OV); + tcg_gen_andi_tl(cpu_sr, cpu_sr, SR_CY); + tcg_gen_addi_i32(sr_ove64, cpu_SR, SR_OVE); + tcg_gen_brcondi_i32(TCG_COND_NE, sr_ove64, 0x1, lab5); + gen_exeception(dc, EXCP_RANGE); + /* Store result. */ + gen_set_label(lab5); + tcg_gen_shli_i64(res1, res1, 32); + tcg_gen_addi_i64(r4, r4, 0xffffffff); + tcg_gen_add_i64(res1, r4, res1); + tcg_gen_mov_i64(cpu_R[rd], res1); + tcg_temp_free_i64(t3); + tcg_temp_free_i64(t4); + tcg_temp_free_i64(t5); + tcg_temp_free_i64(t6); + tcg_temp_free_i64(r1); + tcg_temp_free_i64(r2); + tcg_temp_free_i64(r3);target-openrisc/translate.c line 564
Quoted 10 lines
target-openrisc/translate.c +10
-0+ tcg_temp_free_i64(r4); + tcg_temp_free_i32(tp0); + tcg_temp_free_i32(tp1); + tcg_temp_free_i64(t2h); + tcg_temp_free_i64(t2l); + tcg_temp_free_i64(t3h); + tcg_temp_free_i64(t3l); + tcg_temp_free_i64(res1); + tcg_temp_free_i64(res0); + tcg_temp_free_i32(sr_ove64);Quoted 4 lines
Overall the instruction is pretty long, maybe a helper would be in order. There are limits on how long the TCG sequences can become (see tcg/README).
is this looks OK?
target_ulongHELPER(mul32)(CPUOpenRISCState *env,target_ulongra,target_ulongrb) {
uint64_t result;
target_ulong high, cy;
Quoted 3 lines
result = ra * rb;
high = result >>TARGET_LONG_BITS;
cy = result >> (TARGET_LONG_BITS- 1);
This does not work if TARGET_LONG_BITS is 64. If that is not an immediate concern, just add a comment with XXX to remind.
Quoted 30 lines
if ((cy &
0x1) ==0x0) {
if (high ==0x0) {
return result;
}
}if ((cy &
0x1) ==0x1) {
if (high ==0xffffffff) {
return result;
}
}env->sr |= (
SR_OV|SR_CY);
if (env->sr&SR_OVE) {
raise_exception(env,EXCP_RANGE);
}return result;
}case
0x03: /*l.mul*/
LOG_DIS("l.mul r%d, r%d, r%d\n", rd, ra, rb);
if (ra != 0 && rb != 0) {gen_helper_mul32(cpu_R[rd], cpu_env, cpu_R[ra], cpu_R[rb]); } else {
tcg_gen_movi_tl(cpu_R[rd],0x0);
}
break;
Quoted 10 lines
case
0x2c: /*l.muli*/
LOG_DIS("l.muli r%d, r%d, %d\n", rd, ra, I16); if (ra != 0 && I16 != 0) {
TCGv_i32 im =tcg_const_i32(I16);gen_helper_mul32(cpu_R[rd], cpu_env, cpu_R[ra], im);tcg_temp_free_i32(im);
} else {
tcg_gen_movi_tl(cpu_R[rd],0x0);
}
break;
OK
Quoted 1,433 lines
Quoted 1,424 lines
Quoted 1,424 lines
target-openrisc/translate.c +1415
-0+#endif + } else { + tcg_gen_movi_tl(cpu_R[rd], 0x0); + } + } + break; + default: + gen_illegal_exception(dc); + break; + } + break; + + case 0x0009: + switch (op1) { + case 0x03: /*l.div*/ + LOG_DIS("l.div r%d, r%d, r%d\n", rd, ra, rb); + { + int lab0 = gen_new_label(); + int lab1 = gen_new_label(); + int lab2 = gen_new_label(); + TCGv_i32 sr_ove = tcg_temp_local_new_i32(); + if (rb == 0) { + tcg_gen_ori_tl(cpu_sr, cpu_sr, SR_OV | SR_CY); + tcg_gen_brcondi_tl(TCG_COND_NE, sr_ove, SR_OVE, lab0); + tcg_gen_andi_tl(sr_ove, cpu_sr, SR_OVE); + gen_exception(dc, EXCP_RANGE); + gen_set_label(lab0); + } else { + tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_R[rb], + 0x00000000, lab1); + tcg_gen_brcondi_tl(TCG_COND_NE, cpu_R[ra], + 0xffffffff, lab2); + tcg_gen_brcondi_tl(TCG_COND_NE, cpu_R[rb], + 0x80000000, lab2); + gen_set_label(lab1); + tcg_gen_ori_tl(cpu_sr, cpu_sr, SR_OV | SR_CY); + tcg_gen_andi_tl(sr_ove, cpu_sr, SR_OVE); + tcg_gen_brcondi_tl(TCG_COND_NE, sr_ove, SR_OVE, lab2); + gen_exception(dc, EXCP_RANGE); + gen_set_label(lab2); + tcg_gen_div_tl(cpu_R[rd], cpu_R[ra], cpu_R[rb]); + } + tcg_temp_free_i32(sr_ove); + } + break; + + default: + gen_illegal_exception(dc); + break; + } + break; + + case 0x000a: + switch (op1) { + case 0x03: /*l.divu*/ + LOG_DIS("l.divu r%d, r%d, r%d\n", rd, ra, rb); + { + int lab0 = gen_new_label(); + int lab1 = gen_new_label(); + TCGv_i32 sr_ove = tcg_temp_local_new_i32(); + if (rb == 0) { + tcg_gen_ori_tl(cpu_sr, cpu_sr, SR_OV | SR_CY); + tcg_gen_andi_tl(sr_ove, cpu_sr, SR_OVE); + tcg_gen_brcondi_tl(TCG_COND_NE, sr_ove, SR_OVE, lab0); + gen_exception(dc, EXCP_RANGE); + gen_set_label(lab0); + } else { + tcg_gen_brcondi_tl(TCG_COND_NE, cpu_R[rb], + 0x00000000, lab1); + tcg_gen_ori_tl(cpu_sr, cpu_sr, SR_OV | SR_CY); + tcg_gen_andi_tl(sr_ove, cpu_sr, SR_OVE); + tcg_gen_brcondi_tl(TCG_COND_NE, sr_ove, SR_OVE, lab1); + gen_exception(dc, EXCP_RANGE); + gen_set_label(lab1); + tcg_gen_divu_tl(cpu_R[rd], cpu_R[ra], cpu_R[rb]); + } + tcg_temp_free_i32(sr_ove); + } + break; + + default: + gen_illegal_exception(dc); + break; + } + break; + + case 0x000b: + switch (op1) { + case 0x03: /*l.mulu*/ + LOG_DIS("l.mulu r%d, r%d, r%d\n", rd, ra, rb); + if (rb != 0 && ra != 0) { + TCGv_i64 result = tcg_temp_local_new_i64(); + TCGv_i64 tra = tcg_temp_local_new_i64(); + TCGv_i64 trb = tcg_temp_local_new_i64(); + TCGv_i64 high = tcg_temp_new_i64(); + TCGv_i32 sr_ove = tcg_temp_local_new_i32(); + int lab = gen_new_label(); + /* Calculate the each result. */ + tcg_gen_extu_i32_i64(tra, cpu_R[ra]); + tcg_gen_extu_i32_i64(trb, cpu_R[rb]); + tcg_gen_mul_i64(result, tra, trb); + tcg_temp_free_i64(tra); + tcg_temp_free_i64(trb); + tcg_gen_shri_i64(high, result, TARGET_LONG_BITS); + /* Overflow or not. */ + tcg_gen_brcondi_i64(TCG_COND_EQ, high, 0x00000000, lab); + tcg_gen_ori_tl(cpu_sr, cpu_sr, SR_OV | SR_CY); + tcg_gen_andi_tl(sr_ove, cpu_sr, SR_OVE); + tcg_gen_brcondi_tl(TCG_COND_NE, sr_ove, SR_OVE, lab); + gen_exception(dc, EXCP_RANGE); + gen_set_label(lab); + tcg_temp_free_i64(high); + tcg_gen_trunc_i64_tl(cpu_R[rd], result); + tcg_temp_free_i64(result); + tcg_temp_free_i32(sr_ove); +#ifdef TARGET_OPENRISC64 + int lab1 = gen_new_label(); + TCGv_i32 r1 = tcg_temp_loacl_new_i64(); + TCGv_i32 r2 = tcg_temp_loacl_new_i64(); + TCGv_i64 r3 = tcg_temp_loacl_new_i64(); + TCGv_i64 r4 = tcg_temp_loacl_new_i64(); + TCGv_i64 r5 = tcg_temp_loacl_new_i64(); + TCGv_i64 r6 = tcg_temp_loacl_new_i64(); + TCGv_i64 tr1 = tcg_temp_loacl_new_i64(); + TCGv_i64 tr2 = tcg_temp_loacl_new_i64(); + TCGv_i64 tr3 = tcg_temp_loacl_new_i64(); + TCGv_i64 tr4 = tcg_temp_loacl_new_i64(); + TCGv_i64 rs1 = tcg_temp_loacl_new_i64(); + TCGv_i64 rs2 = tcg_temp_loacl_new_i64(); + TCGV_i32 sr_ove64 = tcg_temp_local_new_i32(); + /* Calculate the each result. */ + tcg_gen_trunc_i64_i32(r1, cpu_R[ra]); + tcg_gen_trunc_i64_i32(r2, cpu_R[rb]); + tcg_gen_extu_i32_i64(r3, r1); + tcg_gen_extu_i32_i64(r4, r2); + tcg_gen_shri_i64(r5, cpu_R[ra], 32); + tcg_gen_shri_i64(r6, cpu_R[rb], 32); + tcg_gen_mul_i64(tr1, r5, r6); + tcg_gen_mul_i64(tr2, r5, r4); + tcg_gen_mul_i64(tr3, r3, r6); + tcg_gen_mul_i64(tr4, r3, r4); + tcg_gen_trunc_i64_i32(r1, tr2); + tcg_gen_trunc_i64_i32(r2, tr3); + tcg_gen_extu_i32_i64(r3, r1); + tcg_gen_extu_i32_i64(r4, r2); + tcg_gen_shri_i64(rs1, tr4, 32); + tcg_gen_add_i64(r3, r3, r4); + tcg_gen_add_i64(rs2, rs1, r3); + /* Overflow or not, by r3 CY. */ + tcg_gen_shri_i64(r3, rs2, 32); + tcg_gen_shri_i64(tr3, tr3, 32); + tcg_gen_shri_i64(tr2, tr2, 32); + tcg_gen_add_i64(tr1, tr1, tr2); + tcg_gen_add_i64(tr1, tr1, tr3); + tcg_gen_add_i64(tr1, tr1, r3); + tcg_gen_brcondi_i64(TCGV_COND_EQ, tr1, 0x0, lab1); + tcg_gen_andi_tl(cpu_sr, cpu_sr, SR_OV); + tcg_gen_andi_tl(cpu_sr, cpu_sr, SR_CY); + tcg_gen_addi_i32(sr_ove64, cpu_SR, SR_OVE); + tcg_gen_brcondi_i32(TCG_COND_NE, sr_ove64, 0x1, lab1); + gen_exeception(dc, EXCP_RANGE); + /* Store result. */ + gen_set_label(lab1); + tcg_gen_andi_i64(tr4, tr4, 0xffffffff); + tcg_gen_shli_i64(rs2, rs2, 32); + tcg_gen_add_i64(rs2, rs2, tr4); + tcg_gen_mov_i64(cpu_R[rd], rs2); + tcg_temp_free_i32(r1); + tcg_temp_free_i32(r2); + tcg_temp_free_i64(r3); + tcg_temp_free_i64(r4); + tcg_temp_free_i64(r5); + tcg_temp_free_i64(r6); + tcg_temp_free_i64(tr1); + tcg_temp_free_i64(tr2); + tcg_temp_free_i64(tr3); + tcg_temp_free_i64(tr4); + tcg_temp_free_i64(rs1); + tcg_temp_free_i64(rs2); + tcg_temp_free_i64(sr_ove); +#endif + } else { + tcg_gen_movi_tl(cpu_R[rd], 0); + } + break; + + default: + gen_illegal_exception(dc); + break; + } + break; + + case 0x000e: + switch (op1) { + case 0x00: /*l.cmov*/ + LOG_DIS("l.cmov r%d, r%d, r%d\n", rd, ra, rb); + { + int lab = gen_new_label(); + TCGv res = tcg_temp_new(); + TCGv sr_f = tcg_temp_new(); + tcg_gen_andi_tl(sr_f, cpu_sr, SR_F); + tcg_gen_mov_tl(res, cpu_R[rb]); + tcg_gen_brcondi_tl(TCG_COND_NE, sr_f, SR_F, lab); + tcg_gen_mov_tl(res, cpu_R[ra]); + gen_set_label(lab); + tcg_gen_mov_tl(cpu_R[rd], res); + tcg_temp_free(sr_f); + tcg_temp_free(res); + } + break; + + default: + gen_illegal_exception(dc); + break; + } + break; + + case 0x000f: + switch (op1) { + case 0x00: /*l.ff1*/ + LOG_DIS("l.ff1 r%d, r%d, r%d\n", rd, ra, rb); + gen_helper_ff1(cpu_R[rd], cpu_R[ra]); + break; + case 0x01: /*l.fl1*/ + LOG_DIS("l.fl1 r%d, r%d, r%d\n", rd, ra, rb); + gen_helper_fl1(cpu_R[rd], cpu_R[ra]); + break; + + default: + gen_illegal_exception(dc); + break; + } + break; + + case 0x0008: + switch (op1) { + case 0x00: + switch (op2) { + case 0x00: /*l.sll*/ + LOG_DIS("l.sll r%d, r%d, r%d\n", rd, ra, rb); + tcg_gen_shl_tl(cpu_R[rd], cpu_R[ra], cpu_R[rb]); + break; + case 0x01: /*l.srl*/ + LOG_DIS("l.srl r%d, r%d, r%d\n", rd, ra, rb); + tcg_gen_shr_tl(cpu_R[rd], cpu_R[ra], cpu_R[rb]); + break; + case 0x02: /*l.sra*/ + LOG_DIS("l.sra r%d, r%d, r%d\n", rd, ra, rb); + tcg_gen_sar_tl(cpu_R[rd], cpu_R[ra], cpu_R[rb]); + break; + case 0x03: /*l.ror*/ + LOG_DIS("l.ror r%d, r%d, r%d\n", rd, ra, rb); + tcg_gen_rotr_tl(cpu_R[rd], cpu_R[ra], cpu_R[rb]); + break; + + default: + gen_illegal_exception(dc); + break; + } + break; + + default: + gen_illegal_exception(dc); + break; + } + break; + + case 0x000c: + switch (op1) { + case 0x00: + switch (op2) { + case 0x00: /*l.exths*/ + LOG_DIS("l.exths r%d, r%d\n", rd, ra); + tcg_gen_ext16s_tl(cpu_R[rd], cpu_R[ra]); + break; + case 0x01: /*l.extbs*/ + LOG_DIS("l.extbs r%d, r%d\n", rd, ra); + tcg_gen_ext8s_tl(cpu_R[rd], cpu_R[ra]); + break; + case 0x02: /*l.exthz*/ + LOG_DIS("l.exthz r%d, r%d\n", rd, ra); + tcg_gen_ext16u_tl(cpu_R[rd], cpu_R[ra]); + break; + case 0x03: /*l.extbz*/ + LOG_DIS("l.extbz r%d, r%d\n", rd, ra); + tcg_gen_ext8u_tl(cpu_R[rd], cpu_R[ra]); + break; + + default: + gen_illegal_exception(dc); + break; + } + break; + + default: + gen_illegal_exception(dc); + break; + } + break; + + case 0x000d: + switch (op1) { + case 0x00: + switch (op2) { + case 0x00: /*l.extws*/ + LOG_DIS("l.extws r%d, r%d\n", rd, ra); + tcg_gen_ext32s_tl(cpu_R[rd], cpu_R[ra]); + break; + case 0x01: /*l.extwz*/ + LOG_DIS("l.extwz r%d, r%d\n", rd, ra); + tcg_gen_ext32u_tl(cpu_R[rd], cpu_R[ra]); + break; + + default: + gen_illegal_exception(dc); + break; + } + break; + + default: + gen_illegal_exception(dc); + break; + } + break; + + default: + gen_illegal_exception(dc); + break; + } +} + +static void dec_misc(DisasContext *dc, CPUOpenRISCState *env, uint32_t insn) +{ + uint32_t op0, op1; + uint32_t ra, rb, rd; + uint32_t /*L6, K5, */I16, I5, I11, N26, tmp; + op0 = field(insn, 26, 6); + op1 = field(insn, 24, 2); + ra = field(insn, 16, 5); + rb = field(insn, 11, 5); + rd = field(insn, 21, 5); + /*L6 = field(insn, 5, 6); + K5 = field(insn, 0, 5);*/ + I16 = field(insn, 0, 16); + I5 = field(insn, 21, 5); + I11 = field(insn, 0, 11); + N26 = field(insn, 0, 26); + tmp = (I5<<11) + I11; + + switch (op0) { + case 0x00: /*l.j*/ + LOG_DIS("l.j %d\n", N26); + case 0x01: /*l.jal*/ + LOG_DIS("l.jal %d\n", N26); + case 0x03: /*l.bnf*/ + LOG_DIS("l.bnf %d\n", N26); + case 0x04: /*l.bf*/ + LOG_DIS("l.bf %d\n", N26); + + gen_jump(dc, N26, 0, op0); + break; + + case 0x05: + switch (op1) { + case 0x01: /*l.nop*/ + LOG_DIS("l.nop %d\n", I16); + break; + + default: + gen_illegal_exception(dc); + break; + } + break; + + case 0x11: /*l.jr*/ + LOG_DIS("l.jr r%d\n", rb); + case 0x12: /*l.jalr*/ + LOG_DIS("l.jalr r%d\n", rb); + + gen_jump(dc, 0, rb, op0); + break; + + case 0x13: /*l.maci*/ + LOG_DIS("l.maci %d, r%d, %d\n", I5, ra, I11); + { + TCGv_i64 t1 = tcg_temp_new_i64(); + TCGv_i64 t2 = tcg_temp_new_i64(); + TCGv_i32 dst = tcg_temp_new_i32(); + TCGv ttmp = tcg_const_tl(tmp); + tcg_gen_mul_tl(dst, cpu_R[ra], ttmp); + tcg_gen_ext_i32_i64(t1, dst); + tcg_gen_concat_i32_i64(t2, maclo, machi); + tcg_gen_add_i64(t2, t2, t1); + tcg_gen_trunc_i64_i32(maclo, t2); + tcg_gen_shri_i64(t2, t2, 32); + tcg_gen_trunc_i64_i32(machi, t2); + tcg_temp_free_i32(dst); + tcg_temp_free(ttmp); + tcg_temp_free_i64(t1); + tcg_temp_free_i64(t2); + } + break; + + case 0x09: /*l.rfe*/ + LOG_DIS("l.rfe\n"); + { + gen_helper_rfe(cpu_env); + dc->is_jmp = DISAS_UPDATE; + } + break; + + case 0x1c: /*l.cust1*/ + LOG_DIS("l.cust1\n"); + break; + + case 0x1d: /*l.cust2*/ + LOG_DIS("l.cust2\n"); + break; + + case 0x1e: /*l.cust3*/ + LOG_DIS("l.cust3\n"); + break; + + case 0x1f: /*l.cust4*/ + LOG_DIS("l.cust4\n"); + break; + + case 0x3c: /*l.cust5*/ + /*LOG_DIS("l.cust5 r%d, r%d, r%d, %d, %d\n", rd, ra, rb, L6, K5);*/ + break; + + case 0x3d: /*l.cust6*/ + LOG_DIS("l.cust6\n"); + break; + + case 0x3e: /*l.cust7*/ + LOG_DIS("l.cust7\n"); + break; + + case 0x3f: /*l.cust8*/ + LOG_DIS("l.cust8\n"); + break; + + case 0x20: /*l.ld*/ + LOG_DIS("l.ld r%d, r%d, %d\n", rd, ra, I16); + { +#ifdef TARGET_OPENRISC64 + check_ob64s(dc); + TCGv_i64 t0 = tcg_temp_new_i64(); + tcg_gen_addi_i64(t0, cpu_R[ra], sign_extend(I16, 16)); + tcg_gen_qemu_ld64(cpu_R[rd], t0, dc->mem_idx); + tcg_temp_free_i64(t0); +#endif + } + break; + + case 0x21: /*l.lwz*/ + LOG_DIS("l.lwz r%d, r%d, %d\n", rd, ra, I16); + { + TCGv t0 = tcg_temp_new(); + tcg_gen_addi_tl(t0, cpu_R[ra], sign_extend(I16, 16)); + tcg_gen_qemu_ld32u(cpu_R[rd], t0, dc->mem_idx); + tcg_temp_free(t0); + } + break; + + case 0x22: /*l.lws*/ + LOG_DIS("l.lws r%d, r%d, %d\n", rd, ra, I16); + { + TCGv t0 = tcg_temp_new(); + tcg_gen_addi_tl(t0, cpu_R[ra], sign_extend(I16, 16)); + tcg_gen_qemu_ld32s(cpu_R[rd], t0, dc->mem_idx); + tcg_temp_free(t0); + } + break; + + case 0x23: /*l.lbz*/ + LOG_DIS("l.lbz r%d, r%d, %d\n", rd, ra, I16); + { + TCGv t0 = tcg_temp_new(); + tcg_gen_addi_tl(t0, cpu_R[ra], sign_extend(I16, 16)); + tcg_gen_qemu_ld8u(cpu_R[rd], t0, dc->mem_idx); + tcg_temp_free(t0); + } + break; + + case 0x24: /*l.lbs*/ + LOG_DIS("l.lbs r%d, r%d, %d\n", rd, ra, I16); + { + TCGv t0 = tcg_temp_new(); + tcg_gen_addi_tl(t0, cpu_R[ra], sign_extend(I16, 16)); + tcg_gen_qemu_ld8s(cpu_R[rd], t0, dc->mem_idx); + tcg_temp_free(t0); + } + break; + + case 0x25: /*l.lhz*/ + LOG_DIS("l.lhz r%d, r%d, %d\n", rd, ra, I16); + { + TCGv t0 = tcg_temp_new(); + tcg_gen_addi_tl(t0, cpu_R[ra], sign_extend(I16, 16)); + tcg_gen_qemu_ld16u(cpu_R[rd], t0, dc->mem_idx); + tcg_temp_free(t0); + } + break; + + case 0x26: /*l.lhs*/ + LOG_DIS("l.lhs r%d, r%d, %d\n", rd, ra, I16); + { + TCGv t0 = tcg_temp_new(); + tcg_gen_addi_tl(t0, cpu_R[ra], sign_extend(I16, 16)); + tcg_gen_qemu_ld16s(cpu_R[rd], t0, dc->mem_idx); + tcg_temp_free(t0); + } + break; + + case 0x27: /*l.addi*/ + LOG_DIS("l.addi r%d, r%d, %d\n", rd, ra, I16); + { + int lab = gen_new_label(); + TCGv_i64 ta = tcg_temp_new_i64(); + TCGv_i64 td = tcg_temp_local_new_i64(); + TCGv_i32 res = tcg_temp_local_new_i32(); + TCGv_i32 sr_ove = tcg_temp_local_new_i32(); + tcg_gen_extu_i32_i64(ta, cpu_R[ra]); + tcg_gen_addi_i64(td, ta, sign_extend(I16, 16)); + tcg_gen_trunc_i64_i32(res, td); + tcg_gen_shri_i64(td, td, 32); + tcg_gen_andi_i64(td, td, 0x3); + /* Jump to lab when no overflow. */ + tcg_gen_brcondi_i64(TCG_COND_EQ, td, 0x0, lab); + tcg_gen_brcondi_i64(TCG_COND_EQ, td, 0x3, lab); + tcg_gen_ori_i32(cpu_sr, cpu_sr, (SR_OV | SR_CY)); + tcg_gen_andi_i32(sr_ove, cpu_sr, SR_OVE); + tcg_gen_brcondi_i32(TCG_COND_NE, sr_ove, SR_OVE, lab); + gen_exception(dc, EXCP_RANGE); + gen_set_label(lab); + tcg_gen_mov_i32(cpu_R[rd], res); + tcg_temp_free_i64(ta); + tcg_temp_free_i64(td); + tcg_temp_free_i32(res); + tcg_temp_free_i32(sr_ove); + } + break; + + case 0x28: /*l.addic*/ + LOG_DIS("l.addic r%d, r%d, %d\n", rd, ra, I16); + { + int lab = gen_new_label(); + TCGv_i64 ta = tcg_temp_new_i64(); + TCGv_i64 td = tcg_temp_local_new_i64(); + TCGv_i64 tcy = tcg_temp_local_new_i64(); + TCGv_i32 res = tcg_temp_local_new_i32(); + TCGv_i32 sr_cy = tcg_temp_local_new_i32(); + TCGv_i32 sr_ove = tcg_temp_local_new_i32(); + tcg_gen_extu_i32_i64(ta, cpu_R[ra]); + tcg_gen_andi_i32(sr_cy, cpu_sr, SR_CY); + tcg_gen_shri_i32(sr_cy, sr_cy, 10); + tcg_gen_extu_i32_i64(tcy, sr_cy); + tcg_gen_addi_i64(td, ta, sign_extend(I16, 16)); + tcg_gen_add_i64(td, td, tcy); + tcg_gen_trunc_i64_i32(res, td); + tcg_gen_shri_i64(td, td, 32); + tcg_gen_andi_i64(td, td, 0x3); + /* Jump to lab when no overflow. */ + tcg_gen_brcondi_i64(TCG_COND_EQ, td, 0x0, lab); + tcg_gen_brcondi_i64(TCG_COND_EQ, td, 0x3, lab); + tcg_gen_ori_i32(cpu_sr, cpu_sr, (SR_OV | SR_CY)); + tcg_gen_andi_i32(sr_ove, cpu_sr, SR_OVE); + tcg_gen_brcondi_i32(TCG_COND_NE, sr_ove, SR_OVE, lab); + gen_exception(dc, EXCP_RANGE); + gen_set_label(lab); + tcg_gen_mov_i32(cpu_R[rd], res); + tcg_temp_free_i64(ta); + tcg_temp_free_i64(td); + tcg_temp_free_i64(tcy); + tcg_temp_free_i32(res); + tcg_temp_free_i32(sr_cy); + tcg_temp_free_i32(sr_ove); + } + break; + + case 0x29: /*l.andi*/ + LOG_DIS("l.andi r%d, r%d, %d\n", rd, ra, I16); + tcg_gen_andi_tl(cpu_R[rd], cpu_R[ra], zero_extend(I16, 16)); + break; + + case 0x2a: /*l.ori*/ + LOG_DIS("l.ori r%d, r%d, %d\n", rd, ra, I16); + tcg_gen_ori_tl(cpu_R[rd], cpu_R[ra], zero_extend(I16, 16)); + break; + + case 0x2b: /*l.xori*/ + LOG_DIS("l.xori r%d, r%d, %d\n", rd, ra, I16); + tcg_gen_xori_tl(cpu_R[rd], cpu_R[ra], sign_extend(I16, 16)); + break; + + case 0x2c: /*l.muli*/ + LOG_DIS("l.muli r%d, r%d, %d\n", rd, ra, I16); + if (ra != 0 && I16 != 0) { + int lab1 = gen_new_label(); + TCGv_i64 t0 = tcg_temp_local_new_i64(); + TCGv_i32 t1 = tcg_temp_local_new_i32(); + TCGv_i32 t2 = tcg_temp_local_new_i32(); + TCGv_i64 tmp0 = tcg_temp_local_new_i64(); + TCGv_i32 res = tcg_temp_local_new_i32(); + TCGv_i32 sr_ove = tcg_temp_local_new_i32(); + uint64_t i16 = (uint64_t)I16; + /* Calculate the result. */ + tcg_gen_extu_i32_i64(tmp0, cpu_R[ra]); + tcg_gen_muli_i64(t0, tmp0, i16); + tcg_gen_trunc_i64_i32(t1, t0); + tcg_gen_mov_tl(res, t1); + tcg_gen_shri_i32(t1, t1, 31); + /* Overflow or not. */ + tcg_gen_brcondi_tl(TCG_COND_NE, t1, 0x0, lab1); + tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0x1ffff, lab1); + tcg_gen_ori_tl(cpu_sr, cpu_sr, SR_OV); + tcg_gen_ori_tl(cpu_sr, cpu_sr, SR_CY); + tcg_gen_andi_tl(sr_ove, cpu_sr, SR_OVE); + tcg_gen_brcondi_tl(TCG_COND_NE, sr_ove, SR_OVE, lab1); + gen_exception(dc, EXCP_RANGE); + /* Store result. */ + gen_set_label(lab1); + tcg_gen_mov_i32(cpu_R[rd], res); + tcg_temp_free_i64(t0); + tcg_temp_free_i32(t1); + tcg_temp_free_i32(t2); + tcg_temp_free_i64(tmp0); + tcg_temp_free_i32(res); + tcg_temp_free_i32(sr_ove); +#ifdef TARGET_OPENRISC64 + int lab2 = gen_new_label(); + TCGv_i64 tmp1 = tcg_temp_local_new_i64(); + TCGv_i64 tmp2 = tcg_temp_local_new_i64(); + TCGv_i64 tr = tcg_temp_local_new_i64(); + TCGv_i32 t3 = tcg_temp_local_new_i64(); + TCGv_i32 t4 = tcg_temp_local_new_i64(); + TCGv_i64 t5 = tcg_temp_local_new_i64(); + TCGv_i64 res1 = tcg_temp_local_new_i64(); + TCGv_i32 sr_ove64 = tcg_temp_local_new_i32(); + /* Calculate the result. */ + tcg_gen_trunc_i64_i32(t3, cpu_R[ra]); + tcg_gen_shri_i64(cpu_R[ra], cpu_R[ra], 32); + tcg_gen_trunc_i64_i32(t5, cpu_R[ra]); + tcg_gen_muli_i64(tr, t3, I16); + tcg_gen_muli_i64(t4, t5, I16); + tcg_gen_shri_i64(tmp2, tr, 32); + tcg_gen_add_i64(res1, tmp2, t4); + tcg_gen_shri_i64(tmp1, res1, 31); + /* Overflow or not. */ + tcg_gen_brcondi_tl(TCG_COND_NE, tmp1, 0x0, lab2); + tcg_gen_brcondi_tl(TCG_COND_EQ, tmp1, 0x1ffff, lab2); + tcg_gen_ori_tl(cpu_sr, cpu_sr, SR_OV); + tcg_gen_ori_tl(cpu_sr, cpu_sr, SR_CY); + tcg_gen_andi_tl(sr_ove64, cpu_sr, SR_OVE); + tcg_gen_brcondi_tl(TCG_COND_EQ, sr_ove64, SR_OVE, lab2); + gen_exeception(dc, EXCP_RANGE); + /* Store result. */ + gen_set_label(lab2); + tcg_gen_andi_i64(tr, tr, 0xffffffff); + tcg_gen_shli_i64(res1, res1, 32); + tcg_gen_add_i64(cpu_R[rd], res1, tr); + tcg_temp_free_i64(tmp1); + tcg_temp_free_i64(tmp2); + tcg_temp_free_i64(t3); + tcg_temp_free_i64(t4); + tcg_temp_free_i64(t5); + tcg_temp_free_i64(tr); + tcg_temp_free_i64(res1); + tcg_temp_free_i64(sr_ove64); +#endif + } else { + tcg_gen_movi_tl(cpu_R[rd], 0x0); + } + break; + + case 0x2d: /*l.mfspr*/ + LOG_DIS("l.mfspr r%d, r%d, %d\n", rd, ra, I16); + break; + + case 0x30: /*l.mtspr*/ + LOG_DIS("l.mtspr %d, r%d, r%d, %d\n", I5, ra, rb, I11); + break; + + case 0x34: /*l.sd*/ + LOG_DIS("l.sd %d, r%d, r%d, %d\n", I5, ra, rb, I11); + { +#ifdef TARGET_OPENRISC64 + check_ob64s(dc); + TCGv_i64 t0 = tcg_temp_new_i64(); + tcg_gen_addi_tl(t0, cpu_R[ra], sign_extend(tmp, 16)); + tcg_gen_qemu_st64(cpu_R[rb], t0, dc->mem_idx); + tcg_temp_free_i64(t0); +#endif + } + break; + + case 0x35: /*l.sw*/ + LOG_DIS("l.sw %d, r%d, r%d, %d\n", I5, ra, rb, I11); + { + TCGv t0 = tcg_temp_new(); + tcg_gen_addi_tl(t0, cpu_R[ra], sign_extend(tmp, 16)); + tcg_gen_qemu_st32(cpu_R[rb], t0, dc->mem_idx); + tcg_temp_free(t0); + } + break; + + case 0x36: /*l.sb*/ + LOG_DIS("l.sb %d, r%d, r%d, %d\n", I5, ra, rb, I11); + { + TCGv t0 = tcg_temp_new(); + tcg_gen_addi_tl(t0, cpu_R[ra], sign_extend(tmp, 16)); + tcg_gen_qemu_st8(cpu_R[rb], t0, dc->mem_idx); + tcg_temp_free(t0); + } + break; + + case 0x37: /*l.sh*/ + LOG_DIS("l.sh %d, r%d, r%d, %d\n", I5, ra, rb, I11); + { + TCGv t0 = tcg_temp_new(); + tcg_gen_addi_tl(t0, cpu_R[ra], sign_extend(tmp, 16)); + tcg_gen_qemu_st16(cpu_R[rb], t0, dc->mem_idx); + tcg_temp_free(t0); + } + break; + + default: + gen_illegal_exception(dc); + break; + } +} + +static void dec_mac(DisasContext *dc, CPUOpenRISCState *env, uint32_t insn) +{ + uint32_t op0; + uint32_t ra, rb; + op0 = field(insn, 0, 4); + ra = field(insn, 16, 5); + rb = field(insn, 11, 5); + + switch (op0) { + case 0x0001: /*l.mac*/ + LOG_DIS("l.mac r%d, r%d\n", ra, rb); + { + TCGv_i32 t0 = tcg_temp_new_i32(); + TCGv_i64 t1 = tcg_temp_new_i64(); + TCGv_i64 t2 = tcg_temp_new_i64(); + tcg_gen_mul_tl(t0, cpu_R[ra], cpu_R[rb]); + tcg_gen_ext_i32_i64(t1, t0); + tcg_gen_concat_i32_i64(t2, maclo, machi); + tcg_gen_add_i64(t2, t2, t1); + tcg_gen_trunc_i64_i32(maclo, t2); + tcg_gen_shri_i64(t2, t2, 32); + tcg_gen_trunc_i64_i32(machi, t2); + tcg_temp_free_i32(t0); + tcg_temp_free_i64(t1); + tcg_temp_free_i64(t2); + } + break; + + case 0x0002: /*l.msb*/ + LOG_DIS("l.msb r%d, r%d\n", ra, rb); + { + TCGv_i32 t0 = tcg_temp_new_i32(); + TCGv_i64 t1 = tcg_temp_new_i64(); + TCGv_i64 t2 = tcg_temp_new_i64(); + tcg_gen_mul_tl(t0, cpu_R[ra], cpu_R[rb]); + tcg_gen_ext_i32_i64(t1, t0); + tcg_gen_concat_i32_i64(t2, maclo, machi); + tcg_gen_sub_i64(t2, t2, t1); + tcg_gen_trunc_i64_i32(maclo, t2); + tcg_gen_shri_i64(t2, t2, 32); + tcg_gen_trunc_i64_i32(machi, t2); + tcg_temp_free_i32(t0); + tcg_temp_free_i64(t1); + tcg_temp_free_i64(t2); + } + break; + + default: + gen_illegal_exception(dc); + break; + } +} + +static void dec_logic(DisasContext *dc, CPUOpenRISCState *env, uint32_t insn) +{ + uint32_t op0; + uint32_t rd, ra, L6; + op0 = field(insn, 6, 2); + rd = field(insn, 21, 5); + ra = field(insn, 16, 5); + L6 = field(insn, 0, 6); + + switch (op0) { + case 0x00: /*l.slli*/ + LOG_DIS("l.slli r%d, r%d, %d\n", rd, ra, L6); + tcg_gen_shli_tl(cpu_R[rd], cpu_R[ra], (L6 & 0x1f)); + break; + + case 0x01: /*l.srli*/ + LOG_DIS("l.srli r%d, r%d, %d\n", rd, ra, L6); + tcg_gen_shri_tl(cpu_R[rd], cpu_R[ra], (L6 & 0x1f)); + break; + + case 0x02: /*l.srai*/ + LOG_DIS("l.srai r%d, r%d, %d\n", rd, ra, L6); + tcg_gen_sari_tl(cpu_R[rd], cpu_R[ra], (L6 & 0x1f)); break; + + case 0x03: /*l.rori*/ + LOG_DIS("l.rori r%d, r%d, %d\n", rd, ra, L6); + tcg_gen_rotri_tl(cpu_R[rd], cpu_R[ra], (L6 & 0x1f)); + break; + + default: + gen_illegal_exception(dc); + break; + } +} + +static void dec_M(DisasContext *dc, CPUOpenRISCState *env, uint32_t insn) +{ + uint32_t op0; + uint32_t rd; + uint32_t K16; + op0 = field(insn, 16, 1); + rd = field(insn, 21, 5); + K16 = field(insn, 0, 16); + + switch (op0) { + case 0x0: /*l.movhi*/ + LOG_DIS("l.movhi r%d, %d\n", rd, K16); + tcg_gen_movi_tl(cpu_R[rd], (K16 << 16)); + break; + + case 0x1: /*l.macrc*/ + LOG_DIS("l.macrc r%d\n", rd); + tcg_gen_mov_tl(cpu_R[rd], maclo); + tcg_gen_movi_tl(maclo, 0x0); + tcg_gen_movi_tl(machi, 0x0); + break; + + default: + gen_illegal_exception(dc); + break; + } +} + +static void dec_comp(DisasContext *dc, CPUOpenRISCState *env, uint32_t insn) +{ + uint32_t op0; + uint32_t ra, rb; + + op0 = field(insn, 21, 5); + ra = field(insn, 16, 5); + rb = field(insn, 11, 5); + + tcg_gen_movi_i32(env_btaken, 0x0); + /* unsigned integers */ + tcg_gen_ext32u_tl(cpu_R[ra], cpu_R[ra]); + tcg_gen_ext32u_tl(cpu_R[rb], cpu_R[rb]); + + switch (op0) { + case 0x0: /*l.sfeq*/ + LOG_DIS("l.sfeq r%d, r%d\n", ra, rb); + tcg_gen_setcond_tl(TCG_COND_EQ, env_btaken, cpu_R[ra], cpu_R[rb]); + break; + + case 0x1: /*l.sfne*/ + LOG_DIS("l.sfne r%d, r%d\n", ra, rb); + tcg_gen_setcond_tl(TCG_COND_NE, env_btaken, cpu_R[ra], cpu_R[rb]); + break; + + case 0x2: /*l.sfgtu*/ + LOG_DIS("l.sfgtu r%d, r%d\n", ra, rb); + tcg_gen_setcond_tl(TCG_COND_GTU, env_btaken, cpu_R[ra], cpu_R[rb]); + break; + + case 0x3: /*l.sfgeu*/ + LOG_DIS("l.sfgeu r%d, r%d\n", ra, rb); + tcg_gen_setcond_tl(TCG_COND_GEU, env_btaken, cpu_R[ra], cpu_R[rb]); + break; + + case 0x4: /*l.sfltu*/ + LOG_DIS("l.sfltu r%d, r%d\n", ra, rb); + tcg_gen_setcond_tl(TCG_COND_LTU, env_btaken, cpu_R[ra], cpu_R[rb]); + break; + + case 0x5: /*l.sfleu*/ + LOG_DIS("l.sfleu r%d, r%d\n", ra, rb); + tcg_gen_setcond_tl(TCG_COND_LEU, env_btaken, cpu_R[ra], cpu_R[rb]); + break; + + case 0xa: /*l.sfgts*/ + LOG_DIS("l.sfgts r%d, r%d\n", ra, rb); + tcg_gen_setcond_tl(TCG_COND_GT, env_btaken, cpu_R[ra], cpu_R[rb]); + break; + + case 0xb: /*l.sfges*/ + LOG_DIS("l.sfges r%d, r%d\n", ra, rb); + tcg_gen_setcond_tl(TCG_COND_GE, env_btaken, cpu_R[ra], cpu_R[rb]); + break; + + case 0xc: /*l.sflts*/ + LOG_DIS("l.sflts r%d, r%d\n", ra, rb); + tcg_gen_setcond_tl(TCG_COND_LT, env_btaken, cpu_R[ra], cpu_R[rb]); + break; + + case 0xd: /*l.sfles*/ + LOG_DIS("l.sfles r%d, r%d\n", ra, rb); + tcg_gen_setcond_tl(TCG_COND_LE, env_btaken, cpu_R[ra], cpu_R[rb]); + break; + + default: + gen_illegal_exception(dc); + break; + } + wb_SR_F(); +} + +static void dec_compi(DisasContext *dc, CPUOpenRISCState *env, uint32_t insn) +{ + uint32_t op0; + uint32_t ra, I16; + + op0 = field(insn, 21, 5); + ra = field(insn, 16, 5); + I16 = field(insn, 0, 16); + + tcg_gen_movi_i32(env_btaken, 0x0); + I16 = sign_extend(I16, 16); + + switch (op0) { + case 0x0: /*l.sfeqi*/ + LOG_DIS("l.sfeqi r%d, %d\n", ra, I16); + tcg_gen_setcondi_tl(TCG_COND_EQ, env_btaken, cpu_R[ra], I16); + break; + + case 0x1: /*l.sfnei*/ + LOG_DIS("l.sfnei r%d, %d\n", ra, I16); + tcg_gen_setcondi_tl(TCG_COND_NE, env_btaken, cpu_R[ra], I16); + break; + + case 0x2: /*l.sfgtui*/ + LOG_DIS("l.sfgtui r%d, %d\n", ra, I16); + tcg_gen_setcondi_tl(TCG_COND_GTU, env_btaken, cpu_R[ra], I16); + break; + + case 0x3: /*l.sfgeui*/ + LOG_DIS("l.sfgeui r%d, %d\n", ra, I16); + tcg_gen_setcondi_tl(TCG_COND_GEU, env_btaken, cpu_R[ra], I16); + break; + + case 0x4: /*l.sfltui*/ + LOG_DIS("l.sfltui r%d, %d\n", ra, I16); + tcg_gen_setcondi_tl(TCG_COND_LTU, env_btaken, cpu_R[ra], I16); + break; + + case 0x5: /*l.sfleui*/ + LOG_DIS("l.sfleui r%d, %d\n", ra, I16); + tcg_gen_setcondi_tl(TCG_COND_LEU, env_btaken, cpu_R[ra], I16); + break; + + case 0xa: /*l.sfgtsi*/ + LOG_DIS("l.sfgtsi r%d, %d\n", ra, I16); + tcg_gen_setcondi_tl(TCG_COND_GT, env_btaken, cpu_R[ra], I16); + break; + + case 0xb: /*l.sfgesi*/ + LOG_DIS("l.sfgesi r%d, %d\n", ra, I16); + tcg_gen_setcondi_tl(TCG_COND_GE, env_btaken, cpu_R[ra], I16); + break; + + case 0xc: /*l.sfltsi*/ + LOG_DIS("l.sfltsi r%d, %d\n", ra, I16); + tcg_gen_setcondi_tl(TCG_COND_LT, env_btaken, cpu_R[ra], I16); + break; + + case 0xd: /*l.sflesi*/ + LOG_DIS("l.sflesi r%d, %d\n", ra, I16); + tcg_gen_setcondi_tl(TCG_COND_LE, env_btaken, cpu_R[ra], I16); + break; + + default: + gen_illegal_exception(dc); + break; + } + wb_SR_F(); +} + +static void dec_sys(DisasContext *dc, CPUOpenRISCState *env, uint32_t insn) +{ + uint32_t op0; + /*uint32_t K16;*/ + op0 = field(insn, 16, 8); + /*K16 = field(insn, 0, 16);*/ + + switch (op0) { + case 0x000: /*l.sys*/ + /*LOG_DIS("l.sys %d\n", K16);*/ + tcg_gen_movi_tl(cpu_pc, dc->pc); + gen_exception(dc, EXCP_SYSCALL); + dc->is_jmp = DISAS_UPDATE; + break; + + case 0x100: /*l.trap*/ + /*LOG_DIS("l.trap %d\n", K16);*/ + tcg_gen_movi_tl(cpu_pc, dc->pc); + gen_exception(dc, EXCP_TRAP); + break; + + case 0x300: /*l.csync*/ + LOG_DIS("l.csync\n"); + break; + + case 0x200: /*l.msync*/ + LOG_DIS("l.msync\n"); + break; + + case 0x270: /*l.psync*/ + LOG_DIS("l.psync\n"); + break; + + default: + gen_illegal_exception(dc); + break; + } +} + +static void dec_float(DisasContext *dc, CPUOpenRISCState *env, uint32_t insn) +{ + uint32_t op0; + uint32_t ra, rb, rd; + op0 = field(insn, 0, 8); + ra = field(insn, 16, 5); + rb = field(insn, 11, 5); + rd = field(insn, 21, 5); + + switch (op0) { + case 0x00: /*lf.add.s*/ + LOG_DIS("lf.add.s r%d, r%d, r%d\n", rd, ra, rb); + gen_helper_float_add_s(cpu_R[rd], cpu_env, cpu_R[ra], cpu_R[rb]); + break; + + case 0x01: /*lf.sub.s*/ + LOG_DIS("lf.sub.s r%d, r%d, r%d\n", rd, ra, rb); + gen_helper_float_sub_s(cpu_R[rd], cpu_env, cpu_R[ra], cpu_R[rb]); + break; + + + case 0x02: /*lf.mul.s*/ + LOG_DIS("lf.mul.s r%d, r%d, r%d\n", rd, ra, rb); + if (ra != 0 && rb != 0) { + gen_helper_float_mul_s(cpu_R[rd], cpu_env, cpu_R[ra], cpu_R[rb]); + } else { + tcg_gen_ori_tl(fpcsr, fpcsr, FPCSR_ZF); + tcg_gen_movi_i32(cpu_R[rd], 0x0); + } + break; + + case 0x03: /*lf.div.s*/ + LOG_DIS("lf.div.s r%d, r%d, r%d\n", rd, ra, rb); + gen_helper_float_div_s(cpu_R[rd], cpu_env, cpu_R[ra], cpu_R[rb]); + break; + + case 0x04: /*lf.itof.s*/ + LOG_DIS("lf.itof r%d, r%d\n", rd, ra); + gen_helper_itofs(cpu_R[rd], cpu_env, cpu_R[ra]); + break; + + case 0x05: /*lf.ftoi.s*/ + LOG_DIS("lf.ftoi r%d, r%d\n", rd, ra); + gen_helper_ftois(cpu_R[rd], cpu_env, cpu_R[ra]); + break; + + case 0x06: /*lf.rem.s*/ + LOG_DIS("lf.rem.s r%d, r%d, r%d\n", rd, ra, rb); + gen_helper_float_rem_s(cpu_R[rd], cpu_env, cpu_R[ra], cpu_R[rb]); + break; + + case 0x07: /*lf.madd.s*/ + LOG_DIS("lf.madd.s r%d, r%d, r%d\n", rd, ra, rb); + gen_helper_float_muladd_s(cpu_R[rd], cpu_env, cpu_R[ra], cpu_R[rb]); + break; + + case 0x08: /*lf.sfeq.s*/ + LOG_DIS("lf.sfeq.s r%d, r%d\n", ra, rb); + gen_helper_float_eq_s(env_btaken, cpu_env, cpu_R[ra], cpu_R[rb]); + break; + + case 0x09: /*lf.sfne.s*/ + LOG_DIS("lf.sfne.s r%d, r%d\n", ra, rb); + gen_helper_float_ne_s(env_btaken, cpu_env, cpu_R[ra], cpu_R[rb]); + break; + + case 0x0a: /*lf.sfgt.s*/ + LOG_DIS("lf.sfgt.s r%d, r%d\n", ra, rb); + gen_helper_float_gt_s(env_btaken, cpu_env, cpu_R[ra], cpu_R[rb]); + break; + + case 0x0b: /*lf.sfge.s*/ + LOG_DIS("lf.sfge.s r%d, r%d\n", ra, rb); + gen_helper_float_ge_s(env_btaken, cpu_env, cpu_R[ra], cpu_R[rb]); + break; + + case 0x0c: /*lf.sflt.s*/ + LOG_DIS("lf.sflt.s r%d, r%d\n", ra, rb); + gen_helper_float_lt_s(env_btaken, cpu_env, cpu_R[ra], cpu_R[rb]); + break; + + case 0x0d: /*lf.sfle.s*/ + LOG_DIS("lf.sfle.s r%d, r%d\n", ra, rb); + gen_helper_float_le_s(env_btaken, cpu_env, cpu_R[ra], cpu_R[rb]); + break; + +#ifdef TARGET_OPENRISC64 + case 0x10: /*lf.add.d*/ + LOG_DIS("lf.add.d r%d, r%d, r%d\n", rd, ra, rb); + check_of64s(dc); + gen_helper_float_add_d(cpu_R[rd], cpu_env, cpu_R[ra], cpu_R[rb]); + break; + + case 0x11: /*lf.sub.d*/ + LOG_DIS("lf.sub.d r%d, r%d, r%d\n", rd, ra, rb); + check_of64s(dc); + gen_helper_float_sub_d(cpu_R[rd], cpu_env, cpu_R[ra], cpu_R[rb]); + break; + + case 0x12: /*lf.mul.d*/ + LOG_DIS("lf.mul.d r%d, r%d, r%d\n", rd, ra, rb); + check_of64s(dc); + if (ra != 0 && rb != 0) { + gen_helper_float_mul_d(cpu_R[rd], cpu_env, cpu_R[ra], cpu_R[rb]); + } else { + tcg_gen_ori_tl(fpcsr, fpcsr, FPCSR_ZF); + tcg_gen_movi_i64(cpu_R[rd], 0x0); + } + break; + + case 0x13: /*lf.div.d*/ + LOG_DIS("lf.div.d r%d, r%d, r%d\n", rd, ra, rb); + check_of64s(dc); + gen_helper_float_div_d(cpu_R[rd], cpu_env, cpu_R[ra], cpu_R[rb]); + break; + + case 0x14: /*lf.itof.d*/ + LOG_DIS("lf.itof r%d, r%d\n", rd, ra); + check_of64s(dc); + gen_helper_itofd(cpu_R[rd], cpu_env, cpu_R[ra]); + break; + + case 0x15: /*lf.ftoi.d*/ + LOG_DIS("lf.ftoi r%d, r%d\n", rd, ra); + check_of64s(dc); + gen_helper_ftoid(cpu_R[rd], cpu_env, cpu_R[ra]); + break; + + case 0x16: /*lf.rem.d*/ + LOG_DIS("lf.rem.d r%d, r%d, r%d\n", rd, ra, rb); + check_of64s(dc); + gen_helper_float_rem_d(cpu_R[rd], cpu_env, cpu_R[ra], cpu_R[rb]); + break; + + case 0x17: /*lf.madd.d*/ + LOG_DIS("lf.madd.d r%d, r%d, r%d\n", rd, ra, rb); + check_of64s(dc); + gen_helper_float_muladd_d(cpu_R[rd], cpu_env, cpu_R[ra], cpu_R[rb]); + break; + + case 0x18: /*lf.sfeq.d*/ + LOG_DIS("lf.sfeq.d r%d, r%d\n", ra, rb); + check_of64s(dc); + gen_helper_float_eq_d(env_btaken, cpu_env, cpu_R[ra], cpu_R[rb]); + break; + + case 0x1a: /*lf.sfgt.d*/ + LOG_DIS("lf.sfgt.d r%d, r%d\n", ra, rb); + check_of64s(dc); + gen_helper_float_gt_d(env_btaken, cpu_env, cpu_R[ra], cpu_R[rb]); + break; + + case 0x1b: /*lf.sfge.d*/ + LOG_DIS("lf.sfge.d r%d, r%d\n", ra, rb); + check_of64s(dc); + gen_helper_float_ge_d(env_btaken, cpu_env, cpu_R[ra], cpu_R[rb]); + break; + + case 0x19: /*lf.sfne.d*/ + LOG_DIS("lf.sfne.d r%d, r%d\n", ra, rb); + check_of64s(dc); + gen_helper_float_ne_d(env_btaken, cpu_env, cpu_R[ra], cpu_R[rb]); + break; + + case 0x1c: /*lf.sflt.d*/ + LOG_DIS("lf.sflt.d r%d, r%d\n", ra, rb); + check_of64s(dc); + gen_helper_float_lt_d(env_btaken, cpu_env, cpu_R[ra], cpu_R[rb]); + break; + + case 0x1d: /*lf.sfle.d*/ + LOG_DIS("lf.sfle.d r%d, r%d\n", ra, rb); + check_of64s(dc); + gen_helper_float_le_d(env_btaken, cpu_env, cpu_R[ra], cpu_R[rb]); + break; +#endif + + default: + gen_illegal_exception(dc); + break; + } + wb_SR_F(); +} + +static void disas_openrisc_insn(DisasContext *dc, CPUOpenRISCState *env) +{ + uint32_t op0; + uint32_t insn; + insn = cpu_ldl_code(env, dc->pc); + op0 = field(insn, 26, 6); + + switch (op0) { + case 0x06: + dec_M(dc, env, insn); + break; + + case 0x08: + dec_sys(dc, env, insn); + break; + + case 0x2e: + dec_logic(dc, env, insn); + break; + + case 0x2f: + dec_compi(dc, env, insn); + break; + + case 0x31: + dec_mac(dc, env, insn); + break; + + case 0x32: + dec_float(dc, env, insn); + break; + + case 0x38: + dec_calc(dc, env, insn); + break; + + case 0x39: + dec_comp(dc, env, insn); + break; + + default: + dec_misc(dc, env, insn); + break; + } +} + +static void check_breakpoint(CPUOpenRISCState *env, DisasContext *dc) +{ + CPUBreakpoint *bp; + + if (unlikely(!QTAILQ_EMPTY(&env->breakpoints))) { + QTAILQ_FOREACH(bp, &env->breakpoints, entry) { + if (bp->pc == dc->pc) { + tcg_gen_movi_tl(cpu_pc, dc->pc); + gen_exception(dc, EXCP_DEBUG); + dc->is_jmp = DISAS_UPDATE; + } + } + } } static inline void gen_intermediate_code_internal(CPUOpenRISCState *env, TranslationBlock *tb, int search_pc) { + struct DisasContext ctx, *dc = &ctx; + uint16_t *gen_opc_end; + uint32_t pc_start; + int j, k; + uint32_t next_page_start; + int num_insns; + int max_insns; + + qemu_log_try_set_file(stderr); + + pc_start = tb->pc; + dc->env = env; + dc->tb = tb; + + gen_opc_end = gen_opc_buf + OPC_MAX_SIZE; + dc->is_jmp = DISAS_NEXT; + dc->ppc = pc_start; + dc->pc = pc_start; + dc->flags = env->cpucfgr; + dc->mem_idx = cpu_mmu_index(env); + dc->synced_flags = dc->tb_flags = tb->flags; + dc->delayed_branch = !!(dc->tb_flags & D_FLAG); + dc->singlestep_enabled = env->singlestep_enabled; + if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) { + qemu_log("-----------------------------------------\n"); + log_cpu_state(env, 0); + } + + next_page_start = (pc_start & TARGET_PAGE_MASK) + TARGET_PAGE_SIZE; + k = -1; + num_insns = 0; + max_insns = tb->cflags & CF_COUNT_MASK; + + if (max_insns == 0) { + max_insns = CF_COUNT_MASK; + } + + gen_icount_start(); + + do { + check_breakpoint(env, dc); + if (search_pc) { + j = gen_opc_ptr - gen_opc_buf; + if (k < j) { + k++; + while (k < j) { + gen_opc_instr_start[k++] = 0; + } + } + gen_opc_pc[k] = dc->pc; + gen_opc_instr_start[k] = 1; + gen_opc_icount[k] = num_insns; + } + + if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP))) { + tcg_gen_debug_insn_start(dc->pc); + } + + if (num_insns + 1 == max_insns && (tb->cflags & CF_LAST_IO)) { + gen_io_start(); + } + dc->ppc = dc->pc - 4; + dc->npc = dc->pc + 4; + tcg_gen_movi_tl(cpu_ppc, dc->ppc); + tcg_gen_movi_tl(cpu_npc, dc->npc); + disas_openrisc_insn(dc, env); + dc->pc = dc->npc; + num_insns++; + /* delay slot */ + if (dc->delayed_branch) { + dc->delayed_branch--; + if (!dc->delayed_branch) { + dc->tb_flags &= ~D_FLAG; + gen_sync_flags(dc); + tcg_gen_mov_tl(cpu_pc, jmp_pc); + tcg_gen_mov_tl(cpu_npc, jmp_pc); + tcg_gen_movi_tl(jmp_pc, 0); + tcg_gen_exit_tb(0); + dc->is_jmp = DISAS_JUMP; + break; + } + } + } while (!dc->is_jmp + && gen_opc_ptr < gen_opc_end + && !env->singlestep_enabled + && !singlestep + && (dc->pc < next_page_start) + && num_insns < max_insns); + + if (tb->cflags & CF_LAST_IO) { + gen_io_end(); + } + if (dc->is_jmp == DISAS_NEXT) { + dc->is_jmp = DISAS_UPDATE; + tcg_gen_movi_tl(cpu_pc, dc->pc); + } + if (unlikely(env->singlestep_enabled)) { + if (dc->is_jmp == DISAS_NEXT) { + tcg_gen_movi_tl(cpu_pc, dc->pc); + } + gen_exception(dc, EXCP_DEBUG); + } else { + switch (dc->is_jmp) { + case DISAS_NEXT: + gen_goto_tb(dc, 0, dc->pc); + break; + default: + case DISAS_JUMP: + break; + case DISAS_UPDATE: + /* indicate that the hash table must be used + to find the next TB */ + tcg_gen_exit_tb(0); + break; + case DISAS_TB_JUMP: + /* nothing more to generate */ + break; + } + } + + gen_icount_end(tb, num_insns); + *gen_opc_ptr = INDEX_op_end; + if (search_pc) { + j = gen_opc_ptr - gen_opc_buf; + k++; + while (k <= j) { + gen_opc_instr_start[k++] = 0; + } + } else { + tb->size = dc->pc - pc_start; + tb->icount = num_insns; + } + +#ifdef DEBUG_DISAS + if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) { + qemu_log("\n"); + log_target_disas(pc_start, dc->pc - pc_start, 0); + qemu_log("\nisize=%d osize=%td\n", + dc->pc - pc_start, gen_opc_ptr - gen_opc_buf); + } +#endif }Quoted 5 lines
Quoted 5 lines
target-openrisc/translate.c +0
-1void gen_intermediate_code(CPUOpenRISCState *env, struct TranslationBlock *tb) --1.7.9.5
Regards,
Jia.