Moxie CPU port
v6 cover Moxie CPU port
Here's the latest incarnation of the moxie patch set. I believe I've addressed all of the major concerns and then some.
I ended up implementing moxie's new exception semantics so now division by zero and illegal instructions both trap to an exception handler routine. I was able to test this with a little C/asm code and it works nicely.
Thanks!
AG
Anthony Green (4):
Add moxie target code
Add moxie disassembler
Add sample moxie system
Add top level changes for moxie
MAINTAINERS | 5 + arch_init.c | 2 + configure | 9 +- cpu-exec.c | 2 + default-configs/moxie-softmmu.mak | 2 + disas.c | 6 + disas/Makefile.objs | 1 + disas/moxie.c | 360 +++++++++++++ hw/moxie/Makefile.objs | 6 + hw/moxie/moxiesim.c | 174 +++++++ include/disas/bfd.h | 2 + include/sysemu/arch_init.h | 1 + qapi-schema.json | 6 +- target-moxie/Makefile.objs | 2 + target-moxie/cpu.c | 172 +++++++ target-moxie/cpu.h | 170 +++++++ target-moxie/helper.c | 97 ++++ target-moxie/helper.h | 9 + target-moxie/machine.c | 27 + target-moxie/machine.h | 2 + target-moxie/mmu.c | 36 ++ target-moxie/mmu.h | 19 + target-moxie/op_helper.c | 90 ++++ target-moxie/translate.c | 1003 +++++++++++++++++++++++++++++++++++++ 24 files changed, 2199 insertions(+), 4 deletions(-) create mode 100644 default-configs/moxie-softmmu.mak create mode 100644 disas/moxie.c create mode 100644 hw/moxie/Makefile.objs create mode 100644 hw/moxie/moxiesim.c create mode 100644 target-moxie/Makefile.objs create mode 100644 target-moxie/cpu.c create mode 100644 target-moxie/cpu.h create mode 100644 target-moxie/helper.c create mode 100644 target-moxie/helper.h create mode 100644 target-moxie/machine.c create mode 100644 target-moxie/machine.h create mode 100644 target-moxie/mmu.c create mode 100644 target-moxie/mmu.h create mode 100644 target-moxie/op_helper.c create mode 100644 target-moxie/translate.c
Signature · 1 line
1.8.1.2
PATCH v6 1/4 Add moxie target code
--- target-moxie/Makefile.objs | 2 + target-moxie/cpu.c | 172 ++++++++ target-moxie/cpu.h | 170 ++++++++ target-moxie/helper.c | 97 +++++ target-moxie/helper.h | 9 + target-moxie/machine.c | 27 ++ target-moxie/machine.h | 2 + target-moxie/mmu.c | 36 ++ target-moxie/mmu.h | 19 + target-moxie/op_helper.c | 90 ++++ target-moxie/translate.c | 1003 ++++++++++++++++++++++++++++++++++++++++++++ 11 files changed, 1627 insertions(+) create mode 100644 target-moxie/Makefile.objs create mode 100644 target-moxie/cpu.c create mode 100644 target-moxie/cpu.h create mode 100644 target-moxie/helper.c create mode 100644 target-moxie/helper.h create mode 100644 target-moxie/machine.c create mode 100644 target-moxie/machine.h create mode 100644 target-moxie/mmu.c create mode 100644 target-moxie/mmu.h create mode 100644 target-moxie/op_helper.c create mode 100644 target-moxie/translate.c
target-moxie/Makefile.objs new file +2 -0
@@ -0,0 +1,2 @@ +obj-y += translate.o op_helper.o helper.o machine.o cpu.o machine.o +obj-$(CONFIG_SOFTMMU) += mmu.o
target-moxie/cpu.c new file +172 -0
172 lines not on this page · raw message
target-moxie/cpu.h new file +170 -0
170 lines not on this page · raw message
target-moxie/helper.c new file +97 -0
97 lines not on this page · raw message
target-moxie/helper.h new file +9 -0
@@ -0,0 +1,9 @@ +#include "exec/def-helper.h" + +DEF_HELPER_3(raise_exception, void, env, i32, int) +DEF_HELPER_1(debug, void, env) +DEF_HELPER_4(div, i32, env, i32, i32, i32) +DEF_HELPER_4(udiv, i32, env, i32, i32, i32) + +#include "exec/def-helper.h" +
target-moxie/machine.c new file +27 -0
@@ -0,0 +1,27 @@ +#include "hw/hw.h" +#include "hw/boards.h" + +const VMStateDescription vmstate_moxie_cpu = { + .name ="cpu" , + .version_id =CPU_SAVE_VERSION , + .minimum_version_id =1 , + .minimum_version_id_old =1 , + .fields = (VMStateField []) { +VMSTATE_UINT32 (flags, CPUMoxieState), +VMSTATE_UINT32_ARRAY (gregs, CPUMoxieState,16 ), +VMSTATE_UINT32_ARRAY (sregs, CPUMoxieState,256 ), +VMSTATE_UINT32 (pc, CPUMoxieState), +VMSTATE_UINT32 (cc, CPUMoxieState), +VMSTATE_END_OF_LIST () + } +}; + +void cpu_save (QEMUFile *f,void *opaque) +{ +vmstate_save_state (f, &vmstate_moxie_cpu, opaque); +} + +int cpu_load (QEMUFile *f,void *opaque,int version_id) +{ +return vmstate_load_state (f, &vmstate_moxie_cpu, opaque, version_id); +}
target-moxie/machine.h new file +2 -0
@@ -0,0 +1,2 @@ +extern const VMStateDescription vmstate_moxie_cpu; +
target-moxie/mmu.c new file +36 -0
@@ -0,0 +1,36 @@ +/* +* Moxie mmu emulation. +* +* Copyright (c) 2008, 2013 Anthony Green +* +* 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 General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> + +#include "config.h" +#include "cpu.h" +#include "mmu.h" +#include "exec/exec-all.h" + +int moxie_mmu_translate (MoxieMMUResult *res, +CPUMoxieState *env,uint32_t vaddr, +int rw,int mmu_idx) +{ +/* Perform no translation yet. */ + res->phy = vaddr; +return 0 ; +}
target-moxie/mmu.h new file +19 -0
@@ -0,0 +1,19 @@ +#define MOXIE_MMU_ERR_EXEC 0 +#define MOXIE_MMU_ERR_READ 1 +#define MOXIE_MMU_ERR_WRITE 2 +#define MOXIE_MMU_ERR_FLUSH 3 + +typedef struct moxie_mmu_result_t { +uint32_t phy; +uint32_t pfn; +int g:1 ; +int v:1 ; +int k:1 ; +int w:1 ; +int e:1 ; +int cause_op; +}MoxieMMUResult ; + +int moxie_mmu_translate (MoxieMMUResult *res, +CPUMoxieState *env,uint32_t vaddr, +int rw,int mmu_idx);
target-moxie/op_helper.c new file +90 -0
90 lines not on this page · raw message
target-moxie/translate.c new file +1003 -0
1,003 lines not on this page · raw message
Signature · 1 line
1.8.1.2
Re: [Qemu-devel] [PATCH v6 1/4] Add moxie target code
target-moxie/op_helper.c line 70
Quoted 4 lines · Anthony Green
target-moxie/op_helper.c new file +4
-0+uint32_t helper_div (CPUMoxieState *env,uint32_t pc,uint32_t a,uint32_t b) +{ +if (unlikely (b ==0 )) { +helper_raise_exception (env, pc,MOXIE_EX_DIV0 );
This never returns, so the following 'return' is unreachable.
target-moxie/op_helper.c line 74
Quoted 4 lines
target-moxie/op_helper.c new file +4
-0+return 0 ; + } +return (int32_t )a / (int32_t )b; +}
You need to handle MININT / -1 too, because MININT idiv -1 is undefined behaviour in C, and we mustn't allow the guest to cause us to do that. (Does the Moxie architecture spec specify the result here or does it say it's an unknown value, or does it cause an exception, or is it genuinely unpredictable?)
Do you have a coherent rationale for what code you are putting into op_helper.c and what into helper.c? (In most of QEMU's existing targets the split is purely for historical reasons since these files used to be compiled differently.)
-- PMM
PATCH v6 2/4 Add moxie disassembler
In reply to Anthony Green--- disas.c | 6 + disas/Makefile.objs | 1 + disas/moxie.c | 360 ++++++++++++++++++++++++++++++++++++++++++++++++++++ include/disas/bfd.h | 2 + 4 files changed, 369 insertions(+) create mode 100644 disas/moxie.c
disas.c +6 -0
@@ -256,6 +256,9 @@ void target_disas(FILE *out, CPUArchState *env, target_ulong code,#elif defined(TARGET_MICROBLAZE ) s.info.mach = bfd_arch_microblaze; print_insn = print_insn_microblaze; +#elif defined(TARGET_MOXIE ) + s.info.mach = bfd_arch_moxie; + print_insn = print_insn_moxie;#elif defined(TARGET_LM32 ) s.info.mach = bfd_mach_lm32; print_insn = print_insn_lm32;
@@ -462,6 +465,9 @@ void monitor_disas(Monitor *mon, CPUArchState *env,#elif defined(TARGET_S390X ) s.info.mach = bfd_mach_s390_64; print_insn = print_insn_s390; +#elif defined(TARGET_MOXIE ) + s.info.mach = bfd_arch_moxie; + print_insn = print_insn_moxie;#elif defined(TARGET_LM32 ) s.info.mach = bfd_mach_lm32; print_insn = print_insn_lm32;
disas/Makefile.objs +1 -0
@@ -7,6 +7,7 @@ common-obj-$(CONFIG_IA64_DIS) += ia64.o common-obj-$(CONFIG_M68K_DIS) += m68k.o common-obj-$(CONFIG_MICROBLAZE_DIS) += microblaze.o common-obj-$(CONFIG_MIPS_DIS) += mips.o +common-obj-$(CONFIG_MOXIE_DIS) += moxie.o common-obj-$(CONFIG_PPC_DIS) += ppc.o common-obj-$(CONFIG_S390_DIS) += s390.o common-obj-$(CONFIG_SH4_DIS) += sh4.o
disas/moxie.c new file +360 -0
360 lines not on this page · raw message
include/disas/bfd.h +2 -0
@@ -218,6 +218,7 @@ enum bfd_architecture#define bfd_mach_cris_v32 32#define bfd_mach_cris_v10_v32 1032 bfd_arch_microblaze, /* Xilinx MicroBlaze. */ + bfd_arch_moxie,/* The Moxie core. */ bfd_arch_ia64,/* HP/Intel ia64 */ #define bfd_mach_ia64_elf64 64 #define bfd_mach_ia64_elf32 32
@@ -392,6 +393,7 @@ int print_insn_m32r (bfd_vma, disassemble_info*);int print_insn_m88k (bfd_vma ,disassemble_info *);int print_insn_mn10200 (bfd_vma ,disassemble_info *);int print_insn_mn10300 (bfd_vma ,disassemble_info *); +int print_insn_moxie (bfd_vma ,disassemble_info *);int print_insn_ns32k (bfd_vma ,disassemble_info *);int print_insn_big_powerpc (bfd_vma ,disassemble_info *);int print_insn_little_powerpc (bfd_vma ,disassemble_info *);
Signature · 1 line
1.8.1.2
PATCH v6 3/4 Add sample moxie system
In reply to Anthony Green--- hw/moxie/Makefile.objs | 6 ++ hw/moxie/moxiesim.c | 174 +++++++++++++++++++++++++++++++++++++++++++++ include/sysemu/arch_init.h | 1 + 3 files changed, 181 insertions(+) create mode 100644 hw/moxie/Makefile.objs create mode 100644 hw/moxie/moxiesim.c
hw/moxie/Makefile.objs new file +6 -0
@@ -0,0 +1,6 @@ +# moxie boards +obj-y = serial.o mc146818rtc.o vga.o +obj-$(CONFIG_FDT) += device_tree.o + +obj-y := $(addprefix ../,$(obj-y)) +obj-y += moxiesim.o
hw/moxie/moxiesim.c new file +174 -0
174 lines not on this page · raw message
include/sysemu/arch_init.h +1 -0
@@ -20,6 +20,7 @@ enum {QEMU_ARCH_XTENSA =4096 ,QEMU_ARCH_OPENRISC =8192 ,QEMU_ARCH_UNICORE32 =0x4000 , + QEMU_ARCH_MOXIE = 0x8000, };extern const uint32_t arch_type;
Signature · 1 line
1.8.1.2
PATCH v6 4/4 Add top level changes for moxie
In reply to Anthony Green--- MAINTAINERS | 5 +++++ arch_init.c | 2 ++ configure | 9 ++++++++- cpu-exec.c | 2 ++ default-configs/moxie-softmmu.mak | 2 ++ qapi-schema.json | 6 +++--- 6 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 default-configs/moxie-softmmu.mak
MAINTAINERS +5 -0
@@ -91,6 +91,11 @@ M: Aurelien Jarno <[email protected]> S: Odd Fixes F: target-mips/ +Moxie +M: Anthony Green <[email protected]> +S: Maintained +F: target-moxie/ + PowerPC M: Alexander Graf <[email protected]> L: [email protected]
arch_init.c +2 -0
@@ -85,6 +85,8 @@ int graphic_depth = 15;#define QEMU_ARCH QEMU_ARCH_MICROBLAZE#elif defined(TARGET_MIPS )#define QEMU_ARCH QEMU_ARCH_MIPS +#elif defined(TARGET_MOXIE ) +#define QEMU_ARCH QEMU_ARCH_MOXIE#elif defined(TARGET_OPENRISC )#define QEMU_ARCH QEMU_ARCH_OPENRISC#elif defined(TARGET_PPC )
configure +8 -1
@@ -958,6 +958,7 @@ mips-softmmu \ mipsel-softmmu \ mips64-softmmu \ mips64el-softmmu \ +moxie-softmmu \ or32-softmmu \ ppc-softmmu \ ppcemb-softmmu \
@@ -3913,7 +3914,7 @@ target_arch2=`echo $target | cut -d '-' -f 1` target_bigendian="no" case "$target_arch2" in - armeb|lm32|m68k|microblaze|mips|mipsn32|mips64|or32|ppc|ppcemb|ppc64|ppc64abi32|s390x|sh4eb|sparc|sparc64|sparc32plus|xtensaeb) + armeb|lm32|m68k|microblaze|mips|mipsn32|mips64|moxie|or32|ppc|ppcemb|ppc64|ppc64abi32|s390x|sh4eb|sparc|sparc64|sparc32plus|xtensaeb) target_bigendian=yes ;; esac
@@ -4018,6 +4019,8 @@ case "$target_arch2" in echo "TARGET_ABI_MIPSN64=y" >> $config_target_mak target_long_alignment=8 ;; + moxie) + ;; or32) TARGET_ARCH=openrisc TARGET_BASE_ARCH=openrisc
@@ -4262,6 +4265,10 @@ for i in $ARCH $TARGET_BASE_ARCH ; do echo "CONFIG_MIPS_DIS=y" >> $config_target_mak echo "CONFIG_MIPS_DIS=y" >> config-all-disas.mak ;; + moxie*) + echo "CONFIG_MOXIE_DIS=y" >> $config_target_mak + echo "CONFIG_MOXIE_DIS=y" >> config-all-disas.mak + ;; or32) echo "CONFIG_OPENRISC_DIS=y" >> $config_target_mak echo "CONFIG_OPENRISC_DIS=y" >> config-all-disas.mak
cpu-exec.c +2 -0
@@ -221,6 +221,7 @@ int cpu_exec(CPUArchState *env)#elif defined(TARGET_LM32 )#elif defined(TARGET_MICROBLAZE )#elif defined(TARGET_MIPS ) +#elif defined(TARGET_MOXIE )#elif defined(TARGET_OPENRISC )#elif defined(TARGET_SH4 )#elif defined(TARGET_CRIS )
@@ -655,6 +656,7 @@ int cpu_exec(CPUArchState *env) | env->cc_dest | (env->cc_x << 4);#elif defined(TARGET_MICROBLAZE )#elif defined(TARGET_MIPS ) +#elif defined(TARGET_MOXIE )#elif defined(TARGET_OPENRISC )#elif defined(TARGET_SH4 )#elif defined(TARGET_ALPHA )
default-configs/moxie-softmmu.mak new file +2 -0
@@ -0,0 +1,2 @@ +# Default configuration for moxie-softmmu +
qapi-schema.json +3 -3
@@ -2994,9 +2994,9 @@ ## { 'enum': 'TargetType', 'data': [ 'alpha', 'arm', 'cris', 'i386', 'lm32', 'm68k', 'microblazeel', - 'microblaze', 'mips64el', 'mips64', 'mipsel', 'mips', 'or32', - 'ppc64', 'ppcemb', 'ppc', 's390x', 'sh4eb', 'sh4', 'sparc64', - 'sparc', 'unicore32', 'x86_64', 'xtensaeb', 'xtensa' ] } + 'microblaze', 'mips64el', 'mips64', 'mipsel', 'mips', 'moxie', + 'or32', 'ppc64', 'ppcemb', 'ppc', 's390x', 'sh4eb', 'sh4', + 'sparc64', 'sparc', 'unicore32', 'x86_64', 'xtensaeb', 'xtensa' ] } ## # @TargetInfo:
Signature · 1 line
1.8.1.2