unicore32: add softmmu support and puv3 machine
PATCH v3 2/14 unicore32-softmmu: Add coprocessor 0(sysctrl) and 1(ocd) instruction support
In reply to Guan XuetaoCoprocessor 0 is system control coprocessor, and we need get/set its contents. Also, all cache/tlb ops shoule be implemented here, but just ignored with no harm.
Coprocessor 1 is OCD (on-chip-debugger), which is used for faked console, so we could output chars to this console without graphic card.
--- target-unicore32/helper.c | 177 +++++++++++++++++++++++++++++++++--------- target-unicore32/helper.h | 17 ++--- target-unicore32/translate.c | 75 ++++++++++++++++++- 3 files changed, 221 insertions(+), 48 deletions(-)
target-unicore32/helper.c +140 -37
@@ -14,6 +14,14 @@#include "helper.h" #include "host-utils.h" +#undef DEBUG_UC32 + +#ifdef DEBUG_UC32 +#define DPRINTF (fmt, ...) printf("%s: " fmt , __func__, ## __VA_ARGS__) +#else +#define DPRINTF (fmt, ...) do {} while (0) +#endif +CPUUniCore32State *uc32_cpu_init (const char *cpu_model) {UniCore32CPU *cpu;
@@ -45,6 +53,138 @@ uint32_t HELPER(clz)(uint32_t x)return clz32 (x); } +#ifndef CONFIG_USER_ONLY +void helper_cp0_set (CPUUniCore32State *env,uint32_t val,uint32_t creg, +uint32_t cop) +{ +/* +* movc pp.nn, rn, #imm9 +* rn: UCOP_REG_D +* nn: UCOP_REG_N +* 1: sys control reg. +* 2: page table base reg. +* 3: data fault status reg. +* 4: insn fault status reg. +* 5: cache op. reg. +* 6: tlb op. reg. +* imm9: split UCOP_IMM10 with bit5 is 0 +*/ +switch (creg) { +case 1 : +if (cop !=0 ) goto unrecognized; + env->cp0.c1_sys = val; +break ; +case 2 : +if (cop !=0 ) goto unrecognized; + env->cp0.c2_base = val; +break ; +case 3 : +if (cop !=0 ) goto unrecognized; + env->cp0.c3_faultstatus = val; +break ; +case 4 : +if (cop !=0 ) goto unrecognized; + env->cp0.c4_faultaddr = val; +break ; +case 5 : +switch (cop) { +case 28 : +DPRINTF ("Invalidate Entire I&D cache\n" ); +return ; +case 20 : +DPRINTF ("Invalidate Entire Icache\n" ); +return ; +case 12 : +DPRINTF ("Invalidate Entire Dcache\n" ); +return ; +case 10 : +DPRINTF ("Clean Entire Dcache\n" ); +return ; +case 14 : +DPRINTF ("Flush Entire Dcache\n" ); +return ; +case 13 : +DPRINTF ("Invalidate Dcache line\n" ); +return ; +case 11 : +DPRINTF ("Clean Dcache line\n" ); +return ; +case 15 : +DPRINTF ("Flush Dcache line\n" ); +return ; + } +break ; +case 6 : +if ((cop <=6 ) && (cop >=2 )) { +/* invalid all tlb */ +tlb_flush (env,1 ); +return ; + } +break ; +default : + goto unrecognized; + } +return ; +unrecognized: +cpu_abort (env,"Wrong register (%d) or wrong operation (%d) in cp0_set!\n" , + creg, cop); +} + +uint32_t helper_cp0_get (CPUUniCore32State *env,uint32_t creg,uint32_t cop) +{ +/* +* movc rd, pp.nn, #imm9 +* rd: UCOP_REG_D +* nn: UCOP_REG_N +* 0: cpuid and cachetype +* 1: sys control reg. +* 2: page table base reg. +* 3: data fault status reg. +* 4: insn fault status reg. +* imm9: split UCOP_IMM10 with bit5 is 0 +*/ +switch (creg) { +case 0 : +switch (cop) { +case 0 : +return env->cp0.c0_cpuid; +case 1 : +return env->cp0.c0_cachetype; + } +break ; +case 1 : +if (cop ==0 ) { +return env->cp0.c1_sys; + } +break ; +case 2 : +if (cop ==0 ) { +return env->cp0.c2_base; + } +break ; +case 3 : +if (cop ==0 ) { +return env->cp0.c3_faultstatus; + } +break ; +case 4 : +if (cop ==0 ) { +return env->cp0.c4_faultaddr; + } +break ; + } +cpu_abort (env,"Wrong register (%d) or wrong operation (%d) in cp0_set!\n" , + creg, cop); +} + +void helper_cp1_putc (target_ulong x) +{ +printf ("%c" , x); +fflush (NULL ); +return ; +} +#endif +#ifdef CONFIG_USER_ONLY void switch_mode (CPUUniCore32State *env,int mode) {
@@ -66,43 +206,6 @@ int uc32_cpu_handle_mmu_fault(CPUUniCore32State *env, target_ulong address, }#endif -/* These should probably raise undefined insn exceptions. */ -void HELPER (set_cp )(CPUUniCore32State *env,uint32_t insn,uint32_t val) -{ -int op1 = (insn >>8 ) &0xf ; -cpu_abort (env,"cp%i insn %08x\n" , op1, insn); -return ; -} - -uint32_t HELPER (get_cp )(CPUUniCore32State *env,uint32_t insn) -{ -int op1 = (insn >>8 ) &0xf ; -cpu_abort (env,"cp%i insn %08x\n" , op1, insn); -return 0 ; -} - -void HELPER (set_cp0 )(CPUUniCore32State *env,uint32_t insn,uint32_t val) -{ -cpu_abort (env,"cp0 insn %08x\n" , insn); -} - -uint32_t HELPER (get_cp0 )(CPUUniCore32State *env,uint32_t insn) -{ -cpu_abort (env,"cp0 insn %08x\n" , insn); -return 0 ; -} - -void HELPER (set_r29_banked )(CPUUniCore32State *env,uint32_t mode,uint32_t val) -{ -cpu_abort (env,"banked r29 write\n" ); -} - -uint32_t HELPER (get_r29_banked )(CPUUniCore32State *env,uint32_t mode) -{ -cpu_abort (env,"banked r29 read\n" ); -return 0 ; -} -/* UniCore-F64 support. We follow the convention used for F64 instrunctions: Single precition routines have a "s" suffix, double precision a "d" suffix. */
target-unicore32/helper.h +7 -10
@@ -1,5 +1,5 @@/* -* Copyright (C) 2010-2011 GUAN Xue-tao +* Copyright (C) 2010-2012 Guan Xuetao * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as
@@ -8,6 +8,12 @@*/ #include "def-helper.h" +#ifndef CONFIG_USER_ONLY +DEF_HELPER_4(cp0_set, void, env, i32, i32, i32) +DEF_HELPER_3(cp0_get, i32, env, i32, i32) +DEF_HELPER_1(cp1_putc, void, i32) +#endif + DEF_HELPER_1(clz, i32, i32)DEF_HELPER_1 (clo, i32, i32)
@@ -16,12 +22,6 @@ DEF_HELPER_1(exception, void, i32) DEF_HELPER_2(asr_write, void, i32, i32) DEF_HELPER_0(asr_read, i32) -DEF_HELPER_3(set_cp0, void, env, i32, i32) -DEF_HELPER_2(get_cp0, i32, env, i32) - -DEF_HELPER_3(set_cp, void, env, i32, i32) -DEF_HELPER_2(get_cp, i32, env, i32) - DEF_HELPER_1(get_user_reg, i32, i32)DEF_HELPER_2 (set_user_reg, void, i32, i32)
@@ -38,9 +38,6 @@ DEF_HELPER_2(shr_cc, i32, i32, i32) DEF_HELPER_2(sar_cc, i32, i32, i32) DEF_HELPER_2(ror_cc, i32, i32, i32) -DEF_HELPER_2(get_r29_banked, i32, env, i32) -DEF_HELPER_3(set_r29_banked, void, env, i32, i32) - DEF_HELPER_1(ucf64_get_fpscr, i32, env)DEF_HELPER_2 (ucf64_set_fpscr, void, env, i32)
target-unicore32/translate.c +74 -1
93 lines not on this page · raw message
Signature · 1 line
1.7.0.4
PATCH v3 1/14 unicore32-softmmu: Add unicore32-softmmu build support
In reply to Guan XuetaoThis patch adds unicore32-softmmu build support, include configure, makefile, arch_init, and all missing functions needed by softmmu. Although all missing functions are empty, unicore32-softmmu could be build successfully.
--- arch_init.c | 2 + arch_init.h | 1 + configure | 1 + default-configs/unicore32-softmmu.mak | 1 + hw/unicore32/Makefile.objs | 1 + target-unicore32/Makefile.objs | 2 +- target-unicore32/helper.c | 27 +++++++++++----------- target-unicore32/machine.c | 23 +++++++++++++++++++ target-unicore32/op_helper.c | 24 +++++++++++++++++++- target-unicore32/softmmu.c | 39 +++++++++++++++++++++++++++++++++ 10 files changed, 106 insertions(+), 15 deletions(-) create mode 100644 default-configs/unicore32-softmmu.mak create mode 100644 hw/unicore32/Makefile.objs create mode 100644 target-unicore32/machine.c create mode 100644 target-unicore32/softmmu.c
arch_init.c +2 -0
@@ -81,6 +81,8 @@ int graphic_depth = 15;#define QEMU_ARCH QEMU_ARCH_SPARC#elif defined(TARGET_XTENSA )#define QEMU_ARCH QEMU_ARCH_XTENSA +#elif defined(TARGET_UNICORE32 ) +#define QEMU_ARCH QEMU_ARCH_UNICORE32#endif const uint32_t arch_type =QEMU_ARCH ;
arch_init.h +1 -0
@@ -16,6 +16,7 @@ enum {QEMU_ARCH_SH4 =1024 ,QEMU_ARCH_SPARC =2048 ,QEMU_ARCH_XTENSA =4096 , + QEMU_ARCH_UNICORE32 = 8192, };extern const uint32_t arch_type;
configure +1 -0
@@ -935,6 +935,7 @@ sparc64-softmmu \ s390x-softmmu \ xtensa-softmmu \ xtensaeb-softmmu \ +unicore32-softmmu \ " fi # the following are Linux specific
default-configs/unicore32-softmmu.mak new file +1 -0
@@ -0,0 +1 @@ +# Default configuration for unicore32-softmmu
hw/unicore32/Makefile.objs new file +1 -0
@@ -0,0 +1 @@ +# For UniCore32 machines and boards
target-unicore32/Makefile.objs +1 -1
@@ -1,4 +1,4 @@ obj-y += translate.o op_helper.o helper.o cpu.o -obj-$(CONFIG_SOFTMMU) += machine.o +obj-$(CONFIG_SOFTMMU) += machine.o softmmu.o $(obj)/op_helper.o: QEMU_CFLAGS += $(HELPER_CFLAGS)
target-unicore32/helper.c +14 -13
@@ -1,5 +1,5 @@/* -* Copyright (C) 2010-2011 GUAN Xue-tao +* Copyright (C) 2010-2012 Guan Xuetao * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as
@@ -45,18 +45,26 @@ uint32_t HELPER(clz)(uint32_t x)return clz32 (x); } +#ifdef CONFIG_USER_ONLY +void switch_mode (CPUUniCore32State *env,int mode) +{ +if (mode !=ASR_MODE_USER ) { +cpu_abort (env,"Tried to switch out of user mode\n" ); + } +} +void do_interrupt (CPUUniCore32State *env) { - env->exception_index =-1 ; +cpu_abort (env,"NO interrupt in user mode\n" ); } -int uc32_cpu_handle_mmu_fault (CPUUniCore32State *env,target_ulong address,int rw, -int mmu_idx) +int uc32_cpu_handle_mmu_fault (CPUUniCore32State *env,target_ulong address, +int access_type,int mmu_idx) { - env->exception_index =UC32_EXCP_TRAP ; - env->cp0.c4_faultaddr = address; +cpu_abort (env,"NO mmu fault in user mode\n" );return 1 ; } +#endif /* These should probably raise undefined insn exceptions. */ void HELPER (set_cp )(CPUUniCore32State *env,uint32_t insn,uint32_t val)
@@ -84,13 +92,6 @@ uint32_t HELPER(get_cp0)(CPUUniCore32State *env, uint32_t insn)return 0 ; } -void switch_mode (CPUUniCore32State *env,int mode) -{ -if (mode !=ASR_MODE_USER ) { -cpu_abort (env,"Tried to switch out of user mode\n" ); - } -} -void HELPER (set_r29_banked )(CPUUniCore32State *env,uint32_t mode,uint32_t val) {cpu_abort (env,"banked r29 write\n" );
target-unicore32/machine.c new file +23 -0
@@ -0,0 +1,23 @@ +/* +* Generic machine functions for UniCore32 ISA +* +* Copyright (C) 2010-2012 Guan Xuetao +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation, or any later version. +* See the COPYING file in the top-level directory. +*/ +#include "hw/hw.h" + +void cpu_save (QEMUFile *f,void *opaque) +{ +hw_error ("%s not supported yet.\n" , __func__); +} + +int cpu_load (QEMUFile *f,void *opaque,int version_id) +{ +hw_error ("%s not supported yet.\n" , __func__); + +return 0 ; +}
target-unicore32/op_helper.c +23 -1
@@ -1,7 +1,7 @@/* * UniCore32 helper routines * -* Copyright (C) 2010-2011 GUAN Xue-tao +* Copyright (C) 2010-2012 Guan Xuetao * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as
@@ -248,3 +248,25 @@ uint32_t HELPER(ror_cc)(uint32_t x, uint32_t i)return ((uint32_t )x >> shift) | (x << (32 - shift)); } } + +#ifndef CONFIG_USER_ONLY +#define MMUSUFFIX _mmu + +#define SHIFT 0 +#include "softmmu_template.h" + +#define SHIFT 1 +#include "softmmu_template.h" + +#define SHIFT 2 +#include "softmmu_template.h" + +#define SHIFT 3 +#include "softmmu_template.h" + +void tlb_fill (CPUUniCore32State *env1,target_ulong addr,int is_write,int mmu_idx, +uintptr_t retaddr) +{ +cpu_abort (env,"%s not supported yet\n" , __func__); +} +#endif
target-unicore32/softmmu.c new file +39 -0
@@ -0,0 +1,39 @@ +/* +* Softmmu related functions +* +* Copyright (C) 2010-2012 Guan Xuetao +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation, or any later version. +* See the COPYING file in the top-level directory. +*/ +#ifdef CONFIG_USER_ONLY +#error This file only exist under softmmu circumstance +#endif + +#include <cpu.h> + +void switch_mode (CPUUniCore32State *env,int mode) +{ +cpu_abort (env,"%s not supported yet\n" , __func__); +} + +void do_interrupt (CPUUniCore32State *env) +{ +cpu_abort (env,"%s not supported yet\n" , __func__); +} + +int uc32_cpu_handle_mmu_fault (CPUUniCore32State *env,target_ulong address, +int access_type,int mmu_idx) +{ +cpu_abort (env,"%s not supported yet\n" , __func__); +return 1 ; +} + +target_phys_addr_t cpu_get_phys_page_debug (CPUUniCore32State *env, +target_ulong addr) +{ +cpu_abort (env,"%s not supported yet\n" , __func__); +return addr; +}
Signature · 1 line
1.7.0.4
PATCH v3 4/14 target-unicore32: Drop UC32_CPUID macros
In reply to Guan XuetaoFrom: Andreas Färber <[email protected]>
Any code that depends on a particular CPU type can now go through callbacks on the QOM UniCore32CPUClass.
--- target-unicore32/cpu.h | 4 ---- 1 files changed, 0 insertions(+), 4 deletions(-)
target-unicore32/cpu.h +0 -4
@@ -122,10 +122,6 @@ void cpu_asr_write(CPUUniCore32State *env1, target_ulong val, target_ulong mask)#define UC32_HWCAP_CMOV 4/* 1 << 2 */ #define UC32_HWCAP_UCF64 8/* 1 << 3 */ -#define UC32_CPUID (env) (env->cp0.c0_cpuid) -#define UC32_CPUID_UCV2 0x40010863 -#define UC32_CPUID_ANY 0xffffffff -#define cpu_init uc32_cpu_init#define cpu_exec uc32_cpu_exec#define cpu_signal_handler uc32_cpu_signal_handler
Signature · 1 line
1.7.0.4
PATCH v3 3/14 unicore32-softmmu: Make UniCore32 cpuid & exceptions correct and runable
In reply to Guan XuetaoThis patch initializes the cpuid to exactly correct value because linux kernel will check it.
In addition, the exception types are specified in proper situations. Then it could make exceptions generated correctly and timely.
--- cpu-exec.c | 1 + linux-user/main.c | 3 ++- target-unicore32/cpu.c | 19 ++++++++++++++----- target-unicore32/cpu.h | 8 +++++--- 4 files changed, 22 insertions(+), 9 deletions(-)
cpu-exec.c +1 -0
@@ -419,6 +419,7 @@ int cpu_exec(CPUArchState *env)#elif defined(TARGET_UNICORE32 )if (interrupt_request &CPU_INTERRUPT_HARD && !(env->uncached_asr &ASR_I )) { + env->exception_index =UC32_EXCP_INTR ;do_interrupt (env); next_tb =0 ; }
linux-user/main.c +2 -1
@@ -958,7 +958,8 @@ void cpu_loop(CPUUniCore32State *env) } }break ; -case UC32_EXCP_TRAP : +case UC32_EXCP_DTRAP : +case UC32_EXCP_ITRAP : info.si_signo =SIGSEGV ; info.si_errno =0 ;/* XXX: check env->error_code */
target-unicore32/cpu.c +14 -5
@@ -1,7 +1,7 @@/* * QEMU UniCore32 CPU * -* Copyright (c) 2010-2011 GUAN Xue-tao +* Copyright (c) 2010-2012 Guan Xuetao * Copyright (c) 2012 SUSE LINUX Products GmbH * * This program is free software; you can redistribute it and/or modify
@@ -32,13 +32,16 @@ static void unicore_ii_cpu_initfn(Object *obj)UniCore32CPU *cpu =UNICORE32_CPU (obj);CPUUniCore32State *env = &cpu->env; - env->cp0.c0_cpuid =0x40010863 ; + env->cp0.c0_cpuid =0x4d000863 ; + env->cp0.c0_cachetype =0x0d152152 ; + env->cp0.c1_sys =0x2000 ; + env->cp0.c2_base =0x0 ; + env->cp0.c3_faultstatus =0x0 ; + env->cp0.c4_faultaddr =0x0 ; + env->ucf64.xregs[UC32_UCF64_FPSCR ] =0 ;set_feature (env,UC32_HWCAP_CMOV );set_feature (env,UC32_HWCAP_UCF64 ); - env->ucf64.xregs[UC32_UCF64_FPSCR ] =0 ; - env->cp0.c0_cachetype =0x1dd20d2 ; - env->cp0.c1_sys =0x00090078 ; }static void uc32_any_cpu_initfn (Object *obj)
@@ -47,6 +50,7 @@ static void uc32_any_cpu_initfn(Object *obj)CPUUniCore32State *env = &cpu->env; env->cp0.c0_cpuid =0xffffffff ; + env->ucf64.xregs[UC32_UCF64_FPSCR ] =0 ;set_feature (env,UC32_HWCAP_CMOV );set_feature (env,UC32_HWCAP_UCF64 );
@@ -65,8 +69,13 @@ static void uc32_cpu_initfn(Object *obj)cpu_exec_init (env); env->cpu_model_str =object_get_typename (obj); +#ifdef CONFIG_USER_ONLY env->uncached_asr =ASR_MODE_USER ; env->regs[31 ] =0 ; +#else + env->uncached_asr =ASR_MODE_PRIV ; + env->regs[31 ] =0x03000000 ; +#endif tlb_flush (env,1 ); }
target-unicore32/cpu.h +5 -3
@@ -1,7 +1,7 @@/* * UniCore32 virtual CPU header * -* Copyright (C) 2010-2011 GUAN Xue-tao +* Copyright (C) 2010-2012 Guan Xuetao * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as
@@ -89,8 +89,10 @@ typedef struct CPUUniCore32State {#define ASR_NZCV (ASR_N | ASR_Z | ASR_C | ASR_V)#define ASR_RESERVED (~(ASR_M | ASR_I | ASR_NZCV)) -#define UC32_EXCP_PRIV (ASR_MODE_PRIV) -#define UC32_EXCP_TRAP (ASR_MODE_TRAP) +#define UC32_EXCP_PRIV (1) +#define UC32_EXCP_ITRAP (2) +#define UC32_EXCP_DTRAP (3) +#define UC32_EXCP_INTR (4)/* Return the current ASR value. */ target_ulong cpu_asr_read (CPUUniCore32State *env1);
Signature · 1 line
1.7.0.4
v3 cover unicore32: add softmmu support and puv3 machine
These patches implement softmmu support on unicore32 architecture. Based on master branch of qemu, the patches can be fetched from:
git://github.com/gxt/QEMU.git unicore32
UniCore32 CPU is embedded in PKUnity-3 SoC, so we add necessary puv3 devices simulation codes together.
Only minimal system control modules are simulated, to make linux kernel boot and busybox run in initramfs.
Any advice is greatly appreciated.
Thanks,
Guan Xuetao
Andreas Färber (1):
target-unicore32: Drop UC32_CPUID macros
Guan Xuetao (13):
unicore32-softmmu: Add unicore32-softmmu build support
unicore32-softmmu: Add coprocessor 0(sysctrl) and 1(ocd) instruction
support
unicore32-softmmu: Make UniCore32 cpuid & exceptions correct and
runable
unicore32-softmmu: Implement softmmu specific functions
unicore32-softmmu: Make sure that kernel can access user space
unicore32-softmmu: Add puv3 soc/board support
unicore32-softmmu: Add puv3 interrupt support
unicore32-softmmu: Add puv3 ostimer support
unicore32-softmmu: Add puv3 gpio support
unicore32-softmmu: Add puv3 pm support
unicore32-softmmu: Add puv3 dma support
unicore32-softmmu: Add ps2 support
unicore32-softmmu: Add maintainer information for UniCore32 machine
MAINTAINERS | 7 + arch_init.c | 2 + arch_init.h | 1 + configure | 1 + cpu-exec.c | 1 + default-configs/unicore32-softmmu.mak | 4 + hw/Makefile.objs | 7 + hw/puv3.c | 130 ++++++++++++++++ hw/puv3.h | 49 ++++++ hw/puv3_dma.c | 109 +++++++++++++ hw/puv3_gpio.c | 141 +++++++++++++++++ hw/puv3_intc.c | 135 +++++++++++++++++ hw/puv3_ost.c | 151 +++++++++++++++++++ hw/puv3_pm.c | 148 ++++++++++++++++++ hw/unicore32/Makefile.objs | 6 + linux-user/main.c | 3 +- target-unicore32/Makefile.objs | 2 +- target-unicore32/cpu.c | 19 ++- target-unicore32/cpu.h | 12 +- target-unicore32/helper.c | 174 +++++++++++++++++----- target-unicore32/helper.h | 17 +-- target-unicore32/machine.c | 23 +++ target-unicore32/op_helper.c | 44 ++++++- target-unicore32/softmmu.c | 267 +++++++++++++++++++++++++++++++++ target-unicore32/translate.c | 111 ++++++++++++-- 25 files changed, 1493 insertions(+), 71 deletions(-) create mode 100644 default-configs/unicore32-softmmu.mak create mode 100644 hw/puv3.c create mode 100644 hw/puv3.h create mode 100644 hw/puv3_dma.c create mode 100644 hw/puv3_gpio.c create mode 100644 hw/puv3_intc.c create mode 100644 hw/puv3_ost.c create mode 100644 hw/puv3_pm.c create mode 100644 hw/unicore32/Makefile.objs create mode 100644 target-unicore32/machine.c create mode 100644 target-unicore32/softmmu.c
PATCH v3 6/14 unicore32-softmmu: Make sure that kernel can access user space
As a matter of course, we need to access user space in kernel code, so we need to correct load/store decoders to indicate correct memory region.
--- target-unicore32/translate.c | 36 ++++++++++++++++++++++++++---------- 1 files changed, 26 insertions(+), 10 deletions(-)
target-unicore32/translate.c +26 -10
@@ -33,9 +33,16 @@ typedef struct DisasContext {int condlabel;struct TranslationBlock *tb;int singlestep_enabled; +#ifndef CONFIG_USER_ONLY +int user; +#endif } DisasContext; -#define IS_USER (s) 1 +#ifndef CONFIG_USER_ONLY +#define IS_USER (s) (s->user) +#else +#define IS_USER (s) 1 +#endif /* These instructions trap after executing, so defer them until after the conditional executions state has been updated. */
@@ -1551,12 +1558,12 @@ static void do_misc(CPUUniCore32State *env, DisasContext *s, uint32_t insn)/* load/store I_offset and R_offset */ static void do_ldst_ir (CPUUniCore32State *env,DisasContext *s,uint32_t insn) { -unsigned int i; +unsigned int mmu_idx;TCGv tmp;TCGv tmp2; tmp2 =load_reg (s,UCOP_REG_N ); - i = (IS_USER (s) || (!UCOP_SET_P &&UCOP_SET_W )); + mmu_idx = (IS_USER (s) || (!UCOP_SET_P &&UCOP_SET_W ));/* immediate */ if (UCOP_SET_P ) {
@@ -1566,17 +1573,17 @@ static void do_ldst_ir(CPUUniCore32State *env, DisasContext *s, uint32_t insn)if (UCOP_SET_L ) {/* load */ if (UCOP_SET_B ) { - tmp =gen_ld8u (tmp2, i); + tmp =gen_ld8u (tmp2, mmu_idx); }else { - tmp =gen_ld32 (tmp2, i); + tmp =gen_ld32 (tmp2, mmu_idx); } }else {/* store */ tmp =load_reg (s,UCOP_REG_D );if (UCOP_SET_B ) { -gen_st8 (tmp, tmp2, i); +gen_st8 (tmp, tmp2, mmu_idx); }else { -gen_st32 (tmp, tmp2, i); +gen_st32 (tmp, tmp2, mmu_idx); } }if (!UCOP_SET_P ) {
@@ -1679,7 +1686,7 @@ static void do_ldst_hwsb(CPUUniCore32State *env, DisasContext *s, uint32_t insn)/* load/store multiple words */ static void do_ldst_m (CPUUniCore32State *env,DisasContext *s,uint32_t insn) { -unsigned int val, i; +unsigned int val, i, mmu_idx;int j, n, reg, user, loaded_base;TCGv tmp;TCGv tmp2;
@@ -1700,6 +1707,7 @@ static void do_ldst_m(CPUUniCore32State *env, DisasContext *s, uint32_t insn) } } + mmu_idx = (IS_USER (s) || (!UCOP_SET_P &&UCOP_SET_W )); addr =load_reg (s,UCOP_REG_N );/* compute total size */
@@ -1744,7 +1752,7 @@ static void do_ldst_m(CPUUniCore32State *env, DisasContext *s, uint32_t insn) }if (UCOP_SET (i)) {if (UCOP_SET_L ) {/* load */ - tmp =gen_ld32 (addr,IS_USER (s)); + tmp =gen_ld32 (addr, mmu_idx);if (reg ==31 ) {gen_bx (s, tmp); }else if (user) {
@@ -1772,7 +1780,7 @@ static void do_ldst_m(CPUUniCore32State *env, DisasContext *s, uint32_t insn) }else { tmp =load_reg (s, reg); } -gen_st32 (tmp, addr,IS_USER (s)); +gen_st32 (tmp, addr, mmu_idx); } j++;/* no need to add after the last transfer */
@@ -1961,6 +1969,14 @@ static inline void gen_intermediate_code_internal(CPUUniCore32State *env, max_insns =CF_COUNT_MASK ; } +#ifndef CONFIG_USER_ONLY +if ((env->uncached_asr &ASR_M ) ==ASR_MODE_USER ) { + dc->user =1 ; + }else { + dc->user =0 ; + } +#endif +gen_icount_start (); do { if (unlikely(!QTAILQ_EMPTY(&env->breakpoints))) {
Signature · 1 line
1.7.0.4
PATCH v3 12/14 unicore32-softmmu: Add puv3 dma support
In reply to Guan XuetaoThis patch adds puv3 dma (Direct Memory Access) support, include dma device simulation for kernel booting.
--- hw/Makefile.objs | 1 + hw/puv3.c | 1 + hw/puv3_dma.c | 109 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 111 insertions(+), 0 deletions(-) create mode 100644 hw/puv3_dma.c
hw/Makefile.objs +1 -0
@@ -71,6 +71,7 @@ hw-obj-$(CONFIG_PUV3) += puv3_intc.o hw-obj-$(CONFIG_PUV3) += puv3_ost.o hw-obj-$(CONFIG_PUV3) += puv3_gpio.o hw-obj-$(CONFIG_PUV3) += puv3_pm.o +hw-obj-$(CONFIG_PUV3) += puv3_dma.o # PCI watchdog devices hw-obj-$(CONFIG_PCI) += wdt_i6300esb.o
hw/puv3.c +1 -0
@@ -49,6 +49,7 @@ static void puv3_soc_init(CPUUniCore32State *env)/* Initialize minimal necessary devices for kernel booting */ sysbus_create_simple ("puv3_pm" ,PUV3_PM_BASE ,NULL ); +sysbus_create_simple ("puv3_dma" ,PUV3_DMA_BASE ,NULL );sysbus_create_simple ("puv3_ost" ,PUV3_OST_BASE , irqs[PUV3_IRQS_OST0 ]); sysbus_create_varargs("puv3_gpio", PUV3_GPIO_BASE, irqs[PUV3_IRQS_GPIOLOW0], irqs[PUV3_IRQS_GPIOLOW1],
hw/puv3_dma.c new file +109 -0
109 lines not on this page · raw message
Signature · 1 line
1.7.0.4
PATCH v3 10/14 unicore32-softmmu: Add puv3 gpio support
In reply to Guan XuetaoThis patch adds puv3 gpio (General Purpose Input/Output) support, include gpio device simulation and its interrupt support.
--- hw/Makefile.objs | 1 + hw/puv3.c | 6 ++ hw/puv3_gpio.c | 141 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 148 insertions(+), 0 deletions(-) create mode 100644 hw/puv3_gpio.c
hw/Makefile.objs +1 -0
@@ -69,6 +69,7 @@ hw-obj-$(CONFIG_XILINX_AXI) += xilinx_axienet.o # PKUnity SoC devices hw-obj-$(CONFIG_PUV3) += puv3_intc.o hw-obj-$(CONFIG_PUV3) += puv3_ost.o +hw-obj-$(CONFIG_PUV3) += puv3_gpio.o # PCI watchdog devices hw-obj-$(CONFIG_PCI) += wdt_i6300esb.o
hw/puv3.c +6 -0
@@ -49,6 +49,12 @@ static void puv3_soc_init(CPUUniCore32State *env)/* Initialize minimal necessary devices for kernel booting */ sysbus_create_simple ("puv3_ost" ,PUV3_OST_BASE , irqs[PUV3_IRQS_OST0 ]); +sysbus_create_varargs ("puv3_gpio" ,PUV3_GPIO_BASE , + irqs[PUV3_IRQS_GPIOLOW0 ], irqs[PUV3_IRQS_GPIOLOW1 ], + irqs[PUV3_IRQS_GPIOLOW2 ], irqs[PUV3_IRQS_GPIOLOW3 ], + irqs[PUV3_IRQS_GPIOLOW4 ], irqs[PUV3_IRQS_GPIOLOW5 ], + irqs[PUV3_IRQS_GPIOLOW6 ], irqs[PUV3_IRQS_GPIOLOW7 ], + irqs[PUV3_IRQS_GPIOHIGH ],NULL ); }static void puv3_board_init (CPUUniCore32State *env,ram_addr_t ram_size)
hw/puv3_gpio.c new file +141 -0
141 lines not on this page · raw message
Signature · 1 line
1.7.0.4
PATCH v3 7/14 unicore32-softmmu: Add puv3 soc/board support
In reply to Guan XuetaoThis patch only add puv3 soc/board support, which introduces puv3 machine description, and specifies console type.
--- default-configs/unicore32-softmmu.mak | 1 + hw/puv3.c | 93 +++++++++++++++++++++++++++++++++ hw/puv3.h | 49 +++++++++++++++++ hw/unicore32/Makefile.objs | 5 ++ 4 files changed, 148 insertions(+), 0 deletions(-) create mode 100644 hw/puv3.c create mode 100644 hw/puv3.h
default-configs/unicore32-softmmu.mak +1 -0
@@ -1 +1,2 @@ # Default configuration for unicore32-softmmu +CONFIG_PUV3=y
hw/puv3.c new file +93 -0
93 lines not on this page · raw message
hw/puv3.h new file +49 -0
49 lines not on this page · raw message
hw/unicore32/Makefile.objs +5 -0
@@ -1 +1,6 @@ # For UniCore32 machines and boards + +# PKUnity-v3 SoC and board information +obj-${CONFIG_PUV3} += puv3.o + +obj-y := $(addprefix ../,$(obj-y))
Signature · 1 line
1.7.0.4
PATCH v3 8/14 unicore32-softmmu: Add puv3 interrupt support
In reply to Guan XuetaoThis patch adds puv3 interrupt support, include interrupt controler device simulation and interrupt handler in puv3 machine.
--- hw/Makefile.objs | 3 + hw/puv3.c | 23 +++++++++- hw/puv3_intc.c | 135 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 160 insertions(+), 1 deletions(-) create mode 100644 hw/puv3_intc.c
hw/Makefile.objs +3 -0
@@ -66,6 +66,9 @@ hw-obj-$(CONFIG_XILINX) += xilinx_uartlite.o hw-obj-$(CONFIG_XILINX_AXI) += xilinx_axidma.o hw-obj-$(CONFIG_XILINX_AXI) += xilinx_axienet.o +# PKUnity SoC devices +hw-obj-$(CONFIG_PUV3) += puv3_intc.o + # PCI watchdog devices hw-obj-$(CONFIG_PCI) += wdt_i6300esb.o
hw/puv3.c +22 -1
@@ -22,9 +22,30 @@#define KERNEL_LOAD_ADDR 0x03000000#define KERNEL_MAX_SIZE 0x00800000/* Just a guess */ +static void puv3_intc_cpu_handler (void *opaque,int irq,int level) +{ +CPUUniCore32State *env = (CPUUniCore32State *)opaque; + +assert (irq ==0 ); +if (level) { +cpu_interrupt (env,CPU_INTERRUPT_HARD ); + }else { +cpu_reset_interrupt (env,CPU_INTERRUPT_HARD ); + } +} +static void puv3_soc_init (CPUUniCore32State *env) { -/* TODO */ +qemu_irq *cpu_intc, irqs[PUV3_IRQS_NR ]; +DeviceState *dev; +int i; + +/* Initialize interrupt controller */ + cpu_intc =qemu_allocate_irqs (puv3_intc_cpu_handler, env,1 ); + dev =sysbus_create_simple ("puv3_intc" ,PUV3_INTC_BASE , *cpu_intc); +for (i =0 ; i <PUV3_IRQS_NR ; i++) { + irqs[i] =qdev_get_gpio_in (dev, i); + } }static void puv3_board_init (CPUUniCore32State *env,ram_addr_t ram_size)
hw/puv3_intc.c new file +135 -0
135 lines not on this page · raw message
Signature · 1 line
1.7.0.4
PATCH v3 5/14 unicore32-softmmu: Implement softmmu specific functions
In reply to Guan XuetaoThis patch implements softmmu specific functions, include tlb_fill, switch_mode, do_interrupt and uc32_cpu_handle_mmu_fault. So the full exception handlers and page table walking could work now.
--- target-unicore32/op_helper.c | 22 ++++- target-unicore32/softmmu.c | 236 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 253 insertions(+), 5 deletions(-)
target-unicore32/op_helper.c +21 -1
@@ -267,6 +267,26 @@ uint32_t HELPER(ror_cc)(uint32_t x, uint32_t i)void tlb_fill (CPUUniCore32State *env1,target_ulong addr,int is_write,int mmu_idx,uintptr_t retaddr) { -cpu_abort (env,"%s not supported yet\n" , __func__); +TranslationBlock *tb; +CPUUniCore32State *saved_env; +unsigned long pc; +int ret; + + saved_env = env; + env = env1; + ret =uc32_cpu_handle_mmu_fault (env, addr, is_write, mmu_idx); +if (unlikely (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); + } + } +cpu_loop_exit (env); + } + env = saved_env; }#endif
target-unicore32/softmmu.c +232 -4
253 lines not on this page · raw message
Signature · 1 line
1.7.0.4
PATCH v3 9/14 unicore32-softmmu: Add puv3 ostimer support
In reply to Guan XuetaoThis patch adds puv3 ostimer support, include os timer device simulation and ptimer support in puv3 machine.
--- default-configs/unicore32-softmmu.mak | 1 + hw/Makefile.objs | 1 + hw/puv3.c | 3 + hw/puv3_ost.c | 151 +++++++++++++++++++++++++++++++++ 4 files changed, 156 insertions(+), 0 deletions(-) create mode 100644 hw/puv3_ost.c
default-configs/unicore32-softmmu.mak +1 -0
@@ -1,2 +1,3 @@ # Default configuration for unicore32-softmmu CONFIG_PUV3=y +CONFIG_PTIMER=y
hw/Makefile.objs +1 -0
@@ -68,6 +68,7 @@ hw-obj-$(CONFIG_XILINX_AXI) += xilinx_axienet.o # PKUnity SoC devices hw-obj-$(CONFIG_PUV3) += puv3_intc.o +hw-obj-$(CONFIG_PUV3) += puv3_ost.o # PCI watchdog devices hw-obj-$(CONFIG_PCI) += wdt_i6300esb.o
hw/puv3.c +3 -0
@@ -46,6 +46,9 @@ static void puv3_soc_init(CPUUniCore32State *env)for (i =0 ; i <PUV3_IRQS_NR ; i++) { irqs[i] =qdev_get_gpio_in (dev, i); } + +/* Initialize minimal necessary devices for kernel booting */ +sysbus_create_simple ("puv3_ost" ,PUV3_OST_BASE , irqs[PUV3_IRQS_OST0 ]); }static void puv3_board_init (CPUUniCore32State *env,ram_addr_t ram_size)
hw/puv3_ost.c new file +151 -0
151 lines not on this page · raw message
Signature · 1 line
1.7.0.4
PATCH v3 14/14 unicore32-softmmu: Add maintainer information for UniCore32 machine
In reply to Guan Xuetao--- MAINTAINERS | 7 +++++++ 1 files changed, 7 insertions(+), 0 deletions(-)
MAINTAINERS +7 -0
@@ -394,6 +394,13 @@ M: Alexander Graf <[email protected]> S: Maintained F: hw/s390-*.c +UniCore32 Machines +------------- +PKUnity-3 SoC initramfs-with-busybox +M: Guan Xuetao <[email protected]> +S: Maintained +F: hw/puv3* + X86 Machines ------------ PC
Signature · 1 line
1.7.0.4
PATCH v3 11/14 unicore32-softmmu: Add puv3 pm support
In reply to Guan XuetaoThis patch adds puv3 pm (power management) support, include pm device simulation for kernel booting.
--- hw/Makefile.objs | 1 + hw/puv3.c | 1 + hw/puv3_pm.c | 148 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 150 insertions(+), 0 deletions(-) create mode 100644 hw/puv3_pm.c
hw/Makefile.objs +1 -0
@@ -70,6 +70,7 @@ hw-obj-$(CONFIG_XILINX_AXI) += xilinx_axienet.o hw-obj-$(CONFIG_PUV3) += puv3_intc.o hw-obj-$(CONFIG_PUV3) += puv3_ost.o hw-obj-$(CONFIG_PUV3) += puv3_gpio.o +hw-obj-$(CONFIG_PUV3) += puv3_pm.o # PCI watchdog devices hw-obj-$(CONFIG_PCI) += wdt_i6300esb.o
hw/puv3.c +1 -0
@@ -48,6 +48,7 @@ static void puv3_soc_init(CPUUniCore32State *env) }/* Initialize minimal necessary devices for kernel booting */ +sysbus_create_simple ("puv3_pm" ,PUV3_PM_BASE ,NULL );sysbus_create_simple ("puv3_ost" ,PUV3_OST_BASE , irqs[PUV3_IRQS_OST0 ]); sysbus_create_varargs("puv3_gpio", PUV3_GPIO_BASE, irqs[PUV3_IRQS_GPIOLOW0], irqs[PUV3_IRQS_GPIOLOW1],
hw/puv3_pm.c new file +148 -0
148 lines not on this page · raw message
Signature · 1 line
1.7.0.4
PATCH v3 13/14 unicore32-softmmu: Add ps2 support
In reply to Guan XuetaoThis patch adds ps2/keyboard support, and enables CONFIG_PCKBD.
--- default-configs/unicore32-softmmu.mak | 1 + hw/puv3.c | 5 +++++ 2 files changed, 6 insertions(+), 0 deletions(-)
default-configs/unicore32-softmmu.mak +1 -0
@@ -1,3 +1,4 @@ # Default configuration for unicore32-softmmu CONFIG_PUV3=y CONFIG_PTIMER=y +CONFIG_PCKBD=y
hw/puv3.c +5 -0
@@ -38,6 +38,7 @@ static void puv3_soc_init(CPUUniCore32State *env) {qemu_irq *cpu_intc, irqs[PUV3_IRQS_NR ];DeviceState *dev; +MemoryRegion *i8042 =g_new (MemoryRegion,1 );int i;/* Initialize interrupt controller */
@@ -57,6 +58,10 @@ static void puv3_soc_init(CPUUniCore32State *env) irqs[PUV3_IRQS_GPIOLOW4 ], irqs[PUV3_IRQS_GPIOLOW5 ], irqs[PUV3_IRQS_GPIOLOW6 ], irqs[PUV3_IRQS_GPIOLOW7 ], irqs[PUV3_IRQS_GPIOHIGH], NULL); + +/* Keyboard (i8042), mouse disabled for nographic */ +i8042_mm_init (irqs[PUV3_IRQS_PS2_KBD ],NULL , i8042,PUV3_REGS_OFFSET ,4 ); +memory_region_add_subregion (get_system_memory (),PUV3_PS2_BASE , i8042); }static void puv3_board_init (CPUUniCore32State *env,ram_addr_t ram_size)
Signature · 1 line
1.7.0.4
Re: [Qemu-devel] [PATCHv3 02/14] unicore32-softmmu: Add coprocessor 0(sysctrl) and 1(ocd) instruction support
In reply to Guan XuetaoQuoted 45 lines · Guan Xuetao
Coprocessor 0 is system control coprocessor, and we need get/set its contents. Also, all cache/tlb ops shoule be implemented here, but just ignored with no harm.
Coprocessor 1 is OCD (on-chip-debugger), which is used for faked console, so we could output chars to this console without graphic card.
Signed-off-by Guan Xuetao <[email protected]>---
target-unicore32/helper.c | 177 +++++++++++++++++++++++++++++++++---------target-unicore32/helper.h| 17 ++---target-unicore32/translate.c| 75 ++++++++++++++++++-3 files changed, 221 insertions(+), 48 deletions(-)target-unicore32/helper.c +17
-0@@ -14,6 +14,14 @@ #include "helper.h" #include "host-utils.h" +#undef DEBUG_UC32 + +#ifdef DEBUG_UC32 +#define DPRINTF (fmt, ...) printf("%s: " fmt , __func__, ## __VA_ARGS__) +#else +#define DPRINTF (fmt, ...) do {} while (0) +#endif + CPUUniCore32State *uc32_cpu_init(const char *cpu_model) { UniCore32CPU *cpu;@@ -45,6 +53,138 @@ uint32_t HELPER(clz)(uint32_t x) return clz32(x); } +#ifndef CONFIG_USER_ONLY +void helper_cp0_set (CPUUniCore32State *env,uint32_t val,uint32_t creg, + uint32_t cop) +{ + /* +* movc pp.nn, rn, #imm9 +* rn: UCOP_REG_D +* nn: UCOP_REG_N +* 1: sys control reg.
target-unicore32/helper.c uint32_t HELPER(clz)(uint32_t x) · line 74
Quoted 10 lines
target-unicore32/helper.c +10
-0+* 2: page table base reg. +* 3: data fault status reg. +* 4: insn fault status reg. +* 5: cache op. reg. +* 6: tlb op. reg. +* imm9: split UCOP_IMM10 with bit5 is 0 +*/ + switch (creg) { + case 1: + if (cop != 0) goto unrecognized;
Does this pass scripts/checkpatch.pl? These should become
if (cop != 0) {
goto unrecognized;
}Quoted 46 lines
target-unicore32/helper.c +46
-0+ env->cp0.c1_sys = val; + break; + case 2: + if (cop != 0) goto unrecognized; + env->cp0.c2_base = val; + break; + case 3: + if (cop != 0) goto unrecognized; + env->cp0.c3_faultstatus = val; + break; + case 4: + if (cop != 0) goto unrecognized; + env->cp0.c4_faultaddr = val; + break; + case 5: + switch(cop) { + case 28: + DPRINTF("Invalidate Entire I&D cache\n"); + return; + case 20: + DPRINTF("Invalidate Entire Icache\n"); + return; + case 12: + DPRINTF("Invalidate Entire Dcache\n"); + return; + case 10: + DPRINTF("Clean Entire Dcache\n"); + return; + case 14: + DPRINTF("Flush Entire Dcache\n"); + return; + case 13: + DPRINTF("Invalidate Dcache line\n"); + return; + case 11: + DPRINTF("Clean Dcache line\n"); + return; + case 15: + DPRINTF("Flush Dcache line\n"); + return; + } + break; + case 6: + if ((cop <= 6) && (cop >=2)) { + /* invalid all tlb */ + tlb_flush(env, 1);
target-unicore32/helper.c uint32_t HELPER(clz)(uint32_t x) · line 130
Quoted 10 lines
target-unicore32/helper.c +10
-0+ return; + } + break; + default: + goto unrecognized; + } + return; +unrecognized: + cpu_abort(env, "Wrong register (%d) or wrong operation (%d) in cp0_set!\n", + creg, cop);
The call to cpu_abort() would mean that the guest is able to terminate QEMU at will, which is not OK. What does real HW do?
Quoted 44 lines
target-unicore32/helper.c +44
-0+} + +uint32_t helper_cp0_get (CPUUniCore32State *env,uint32_t creg,uint32_t cop) +{ + /* + * movc rd, pp.nn, #imm9 + * rd: UCOP_REG_D + * nn: UCOP_REG_N + * 0: cpuid and cachetype + * 1: sys control reg. + * 2: page table base reg. + * 3: data fault status reg. + * 4: insn fault status reg. + * imm9: split UCOP_IMM10 with bit5 is 0 + */ + switch (creg) { + case 0: + switch (cop) { + case 0: + return env->cp0.c0_cpuid; + case 1: + return env->cp0.c0_cachetype; + } + break; + case 1: + if (cop == 0) { + return env->cp0.c1_sys; + } + break; + case 2: + if (cop == 0) { + return env->cp0.c2_base; + } + break; + case 3: + if (cop == 0) { + return env->cp0.c3_faultstatus; + } + break; + case 4: + if (cop == 0) { + return env->cp0.c4_faultaddr; + } + break;
target-unicore32/helper.c uint32_t HELPER(clz)(uint32_t x) · line 184
Quoted 10 lines
target-unicore32/helper.c +10
-0+ } + cpu_abort(env, "Wrong register (%d) or wrong operation (%d) in cp0_set!\n", + creg, cop); +} + +void helper_cp1_putc (target_ulong x) +{ + printf("%c", x); + fflush(NULL); + return;
Useless return.
The printout should be enabled only for DEBUG_UC32.
Quoted 200 lines
target-unicore32/helper.c +3
-37+} +#endif + #ifdef CONFIG_USER_ONLY void switch_mode(CPUUniCore32State *env, int mode) {@@ -66,43 +206,6 @@ int uc32_cpu_handle_mmu_fault(CPUUniCore32State *env, target_ulong address, } #endif -/* These should probably raise undefined insn exceptions. */ -void HELPER (set_cp )(CPUUniCore32State *env,uint32_t insn,uint32_t val) -{ - int op1 = (insn >> 8) & 0xf; - cpu_abort(env, "cp%i insn %08x\n", op1, insn); - return; -} - -uint32_t HELPER (get_cp )(CPUUniCore32State *env,uint32_t insn) -{ - int op1 = (insn >> 8) & 0xf; - cpu_abort(env, "cp%i insn %08x\n", op1, insn); - return 0; -} - -void HELPER (set_cp0 )(CPUUniCore32State *env,uint32_t insn,uint32_t val) -{ - cpu_abort(env, "cp0 insn %08x\n", insn); -} - -uint32_t HELPER (get_cp0 )(CPUUniCore32State *env,uint32_t insn) -{ - cpu_abort(env, "cp0 insn %08x\n", insn); - return 0; -} - -void HELPER (set_r29_banked )(CPUUniCore32State *env,uint32_t mode,uint32_t val) -{ - cpu_abort(env, "banked r29 write\n"); -} - -uint32_t HELPER (get_r29_banked )(CPUUniCore32State *env,uint32_t mode) -{ - cpu_abort(env, "banked r29 read\n"); - return 0; -} - /* UniCore-F64 support. We follow the convention used for F64 instrunctions:Single precition routines have a "s" suffix, double precision a "d" suffix. */
target-unicore32/helper.h +7
-10@@ -1,5 +1,5 @@ /* -* Copyright (C) 2010-2011 GUAN Xue-tao +* Copyright (C) 2010-2012 Guan Xuetao * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as @@ -8,6 +8,12 @@*/ #include "def-helper.h" +#ifndef CONFIG_USER_ONLY +DEF_HELPER_4(cp0_set, void, env, i32, i32, i32) +DEF_HELPER_3(cp0_get, i32, env, i32, i32) +DEF_HELPER_1(cp1_putc, void, i32) +#endif + DEF_HELPER_1(clz, i32, i32) DEF_HELPER_1(clo, i32, i32)@@ -16,12 +22,6 @@ DEF_HELPER_1(exception, void, i32) DEF_HELPER_2(asr_write, void, i32, i32) DEF_HELPER_0(asr_read, i32) -DEF_HELPER_3(set_cp0, void, env, i32, i32) -DEF_HELPER_2(get_cp0, i32, env, i32) - -DEF_HELPER_3(set_cp, void, env, i32, i32) -DEF_HELPER_2(get_cp, i32, env, i32) - DEF_HELPER_1(get_user_reg, i32, i32) DEF_HELPER_2(set_user_reg, void, i32, i32)@@ -38,9 +38,6 @@ DEF_HELPER_2(shr_cc, i32, i32, i32) DEF_HELPER_2(sar_cc, i32, i32, i32) DEF_HELPER_2(ror_cc, i32, i32, i32) -DEF_HELPER_2(get_r29_banked, i32, env, i32) -DEF_HELPER_3(set_r29_banked, void, env, i32, i32) - DEF_HELPER_1(ucf64_get_fpscr, i32, env) DEF_HELPER_2(ucf64_set_fpscr, void, env, i32)target-unicore32/translate.c +74
-1@@ -1,7 +1,7 @@ /** UniCore32 translation * -* Copyright (C) 2010-2011 GUAN Xue-tao +* Copyright (C) 2010-2012 Guan Xuetao * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as @@ -176,6 +176,71 @@ static void store_reg(DisasContext *s, int reg, TCGv var) "Illegal UniCore32 instruction %x at line %d!", \ insn, __LINE__) +#ifndef CONFIG_USER_ONLY +static void disas_cp0_insn (CPUUniCore32State *env,DisasContext *s,uint32_t insn) +{ + TCGv tmp, tmp2, tmp3; + if ((insn & 0xfe000000) == 0xe0000000) { + tmp2 = new_tmp(); + tmp3 = new_tmp(); + tcg_gen_movi_i32(tmp2, UCOP_REG_N); + tcg_gen_movi_i32(tmp3, UCOP_IMM10); + if (UCOP_SET_L) { + tmp = new_tmp(); + gen_helper_cp0_get(tmp, cpu_env, tmp2, tmp3); + store_reg(s, UCOP_REG_D, tmp); + } else { + tmp = load_reg(s, UCOP_REG_D); + gen_helper_cp0_set(cpu_env, tmp, tmp2, tmp3); + dead_tmp(tmp); + } + dead_tmp(tmp2); + dead_tmp(tmp3); + return; + } + ILLEGAL; +} + +static void disas_ocd_insn (CPUUniCore32State *env,DisasContext *s,uint32_t insn) +{ + TCGv tmp; + + if ((insn & 0xff003fff) == 0xe1000400) { + /* + * movc rd, pp.nn, #imm9 + * rd: UCOP_REG_D + * nn: UCOP_REG_N (must be 0) + * imm9: 0 + */ + if (UCOP_REG_N == 0) { + tmp = new_tmp(); + tcg_gen_movi_i32(tmp, 0); + store_reg(s, UCOP_REG_D, tmp); + return; + } else { + ILLEGAL; + } + } + if ((insn & 0xff003fff) == 0xe0000401) { + /* + * movc pp.nn, rn, #imm9 + * rn: UCOP_REG_D + * nn: UCOP_REG_N (must be 1) + * imm9: 1 + */ + if (UCOP_REG_N == 1) { + tmp = load_reg(s, UCOP_REG_D); + gen_helper_cp1_putc(tmp); + dead_tmp(tmp); + return; + } else { + ILLEGAL; + } + } + ILLEGAL; +} +#endif + static inline void gen_set_asr(TCGv var, uint32_t mask) { TCGv tmp_mask = tcg_const_i32(mask);@@ -1127,6 +1192,14 @@ static void gen_exception_return(DisasContext *s, TCGv pc) static void disas_coproc_insn(CPUUniCore32State *env, DisasContext *s, uint32_t insn) { switch (UCOP_CPNUM) { +#ifndef CONFIG_USER_ONLY + case 0: + disas_cp0_insn(env, s, insn); + break; + case 1: + disas_ocd_insn(env, s, insn); + break; +#endif case 2:
disas_ucf64_insn(env, s, insn);
break;
--
1.7.0.4
Re: [Qemu-devel] [PATCHv3 12/14] unicore32-softmmu: Add puv3 dma support
In reply to Guan XuetaoQuoted 61 lines · Guan Xuetao
This patch adds puv3 dma (Direct Memory Access) support, include dma device simulation for kernel booting.
Signed-off-by Guan Xuetao <[email protected]>---
hw/Makefile.objs | 1 +
hw/puv3.c | 1 +
hw/puv3_dma.c | 109 ++++++++++++++++++++++++++++++++++++++++++++++++++++++3 files changed, 111 insertions(+), 0 deletions(-)create mode 100644
hw/puv3_dma.chw/Makefile.objs +0
-0@@ -71,6 +71,7 @@ hw-obj-$(CONFIG_PUV3) += puv3_intc.ohw-obj-$(CONFIG_PUV3) += puv3_ost.o
hw-obj-$(CONFIG_PUV3) += puv3_gpio.o
hw-obj-$(CONFIG_PUV3) += puv3_pm.o
+hw-obj-$(CONFIG_PUV3) += puv3_dma.o# PCI watchdog devices
hw-obj-$(CONFIG_PCI) += wdt_i6300esb.ohw/puv3.c +1
-0@@ -49,6 +49,7 @@ static void puv3_soc_init(CPUUniCore32State *env) /* Initialize minimal necessary devices for kernel booting */ sysbus_create_simple("puv3_pm", PUV3_PM_BASE, NULL); + sysbus_create_simple("puv3_dma", PUV3_DMA_BASE, NULL); sysbus_create_simple("puv3_ost", PUV3_OST_BASE, irqs[PUV3_IRQS_OST0]); sysbus_create_varargs("puv3_gpio", PUV3_GPIO_BASE, irqs[PUV3_IRQS_GPIOLOW0], irqs[PUV3_IRQS_GPIOLOW1],hw/puv3_dma.c new file +20
-0@@ -0,0 +1,109 @@ +/* +* DMA device simulation in PKUnity SoC +* +* Copyright (C) 2010-2012 Guan Xuetao +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation, or any later version. +* See the COPYING file in the top-level directory. +*/ +#include "hw.h" +#include "sysbus.h" + +#undef DEBUG_PUV3 +#include "puv3.h" + +#define PUV3_DMA_CH_NR (6) +#define PUV3_DMA_CH_MASK (0xff) +#define PUV3_DMA_CH (offset) ((offset) >> 8) +
hw/puv3_dma.c line 30
Quoted 10 lines
hw/puv3_dma.c new file +10
-0+typedef struct { + SysBusDevice busdev; + MemoryRegion iomem; + uint32_t reg_CFG[PUV3_DMA_CH_NR]; +}PUV3DMAState ; + +static uint64_t puv3_dma_read (void *opaque,target_phys_addr_t offset, + unsigned size) +{ + PUV3DMAState *s = (PUV3DMAState *) opaque;
These casts from void pointer are not needed in C.
hw/puv3_dma.c line 40
Quoted 10 lines
hw/puv3_dma.c new file +10
-0+ uint32_t ret; + + assert(PUV3_DMA_CH(offset) < PUV3_DMA_CH_NR); + + switch (offset & PUV3_DMA_CH_MASK) { + case 0x10: + ret = s->reg_CFG[PUV3_DMA_CH(offset)]; + break; + default: + hw_error("%s: Bad offset 0x%x\n", __func__, offset);
hw_error() also aborts, it would be nice to avoid that. However, the situation is somewhat different from the instruction case, since only privileged guest code (kernel) can write to hardware. The kernel can also for example power off the machine.
Quoted 72 lines
hw/puv3_dma.c new file +69
-1+ } + DPRINTF("offset 0x%x, value 0x%x\n", offset, ret); + + return ret; +} + +static void puv3_dma_write (void *opaque,target_phys_addr_t offset, + uint64_t value, unsigned size) +{ + PUV3DMAState *s = (PUV3DMAState *) opaque; + + assert(PUV3_DMA_CH(offset) < PUV3_DMA_CH_NR); + + switch (offset & PUV3_DMA_CH_MASK) { + case 0x10: + s->reg_CFG[PUV3_DMA_CH(offset)] = value; + break; + default: + hw_error("%s: Bad offset 0x%x\n", __func__, offset); + } + DPRINTF("offset 0x%x, value 0x%x\n", offset, value); +} + +static const MemoryRegionOps puv3_dma_ops = { + .read = puv3_dma_read, + .write = puv3_dma_write, + .impl = { + .min_access_size = 4, + .max_access_size = 4, + }, + .endianness = DEVICE_NATIVE_ENDIAN, +}; + +static int puv3_dma_init (SysBusDevice *dev) +{ + PUV3DMAState *s = FROM_SYSBUS(PUV3DMAState, dev); + int i; + + for (i = 0; i < PUV3_DMA_CH_NR; i++) { + s->reg_CFG[i] = 0x0; + } + + memory_region_init_io(&s->iomem, &puv3_dma_ops, s, "puv3_dma", + PUV3_REGS_OFFSET); + sysbus_init_mmio(dev, &s->iomem); + + return 0; +} + +static void puv3_dma_class_init (ObjectClass *klass,void *data) +{ + SysBusDeviceClass *sdc = SYS_BUS_DEVICE_CLASS(klass); + + sdc->init = puv3_dma_init; +} + +static const TypeInfo puv3_dma_info = { + .name = "puv3_dma", + .parent = TYPE_SYS_BUS_DEVICE, + .instance_size = sizeof(PUV3DMAState), + .class_init = puv3_dma_class_init, +}; + +static void puv3_dma_register_type (void ) +{ + type_register_static(&puv3_dma_info); +} + +type_init (puv3_dma_register_type) --1.7.0.4
Re: [Qemu-devel] [PATCHv3 07/14] unicore32-softmmu: Add puv3 soc/board support
In reply to Guan XuetaoQuoted 66 lines · Guan Xuetao
This patch only add puv3 soc/board support, which introduces puv3 machine description, and specifies console type.
Signed-off-by Guan Xuetao <[email protected]>---
default-configs/unicore32-softmmu.mak | 1 +
hw/puv3.c | 93 +++++++++++++++++++++++++++++++++hw/puv3.h| 49 +++++++++++++++++ hw/unicore32/Makefile.objs | 5 ++4 files changed, 148 insertions(+), 0 deletions(-)create mode 100644
hw/puv3.c
create mode 100644hw/puv3.hdefault-configs/unicore32-softmmu.mak +1
-0@@ -1 +1,2 @@ # Default configuration for unicore32-softmmu +CONFIG_PUV3=yhw/puv3.c new file +40
-0@@ -0,0 +1,93 @@ +/* +* Generic PKUnity SoC machine and board descriptor +* +* Copyright (C) 2010-2012 Guan Xuetao +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation, or any later version. +* See the COPYING file in the top-level directory. +*/ +#include "console.h" +#include "elf.h" +#include "exec-memory.h" +#include "sysbus.h" +#include "boards.h" +#include "loader.h" +#include "pc.h" + +#undef DEBUG_PUV3 +#include "puv3.h" + +#define KERNEL_LOAD_ADDR 0x03000000 +#define KERNEL_MAX_SIZE 0x00800000/* Just a guess */ + +static void puv3_soc_init (CPUUniCore32State *env) +{ + /* TODO */ +} + +static void puv3_board_init (CPUUniCore32State *env,ram_addr_t ram_size) +{ + MemoryRegion *ram_memory = g_new(MemoryRegion, 1); + + /* SDRAM at address zero. */ + memory_region_init_ram(ram_memory, "puv3.ram", ram_size); + vmstate_register_ram_global(ram_memory); + memory_region_add_subregion(get_system_memory(), 0, ram_memory); +} + +static void puv3_load_kernel (const char *kernel_filename)
hw/puv3.c line 50
Quoted 10 lines
hw/puv3.c new file +10
-0+{ + int size; + + assert(kernel_filename != NULL); + + /* only zImage format supported */ + size = load_image_targphys(kernel_filename, KERNEL_LOAD_ADDR, + KERNEL_MAX_SIZE); + if (size < 0) { + hw_error("Load kernel error: '%s'\n", kernel_filename);
BTW, here hw_error() is OK, this is probably due to QEMU user error.
Quoted 50 lines
hw/puv3.c new file +43
-0+ } + + /* cheat curses that we have a graphic console, only under ocd console */ + graphic_console_init(NULL, NULL, NULL, NULL, NULL); +} + +static void puv3_init (ram_addr_t ram_size,const char *boot_device, + const char *kernel_filename, const char *kernel_cmdline, + const char *initrd_filename, const char *cpu_model) +{ + CPUUniCore32State *env; + + if (initrd_filename) { + hw_error("Please use kernel built-in initramdisk.\n"); + } + + if (!cpu_model) { + cpu_model = "UniCore-II"; + } + + env = cpu_init(cpu_model); + if (!env) { + hw_error("Unable to find CPU definition\n"); + } + + puv3_soc_init(env); + puv3_board_init(env, ram_size); + puv3_load_kernel(kernel_filename); +} + +static QEMUMachine puv3_machine = { + .name = "puv3", + .desc = "PKUnity Version-3 based on UniCore32", + .init = puv3_init, + .use_scsi = 0, +}; + +static void puv3_machine_init (void ) +{ + qemu_register_machine(&puv3_machine); +} + +machine_init (puv3_machine_init)hw/puv3.h new file +1
-0@@ -0,0 +1,49 @@ +/*
hw/puv3.h line 11
Quoted 10 lines
hw/puv3.h new file +10
-0+* Misc PKUnity SoC declarations +* +* Copyright (C) 2010-2012 Guan Xuetao +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation, or any later version. +* See the COPYING file in the top-level directory. +*/ +#ifndef __PUV3_H__
Use of leading underscores is reserved to Posix, please use for example HW_PUV3_H.
Quoted 52 lines
hw/puv3.h new file +38
-0+#define __PUV3_H__ + +#define PUV3_REGS_OFFSET (0x1000)/* 4K is reasonable */ + +/* PKUnity System bus (AHB): 0xc0000000 - 0xedffffff (640MB) */ +#define PUV3_DMA_BASE (0xc0200000)/* AHB-4 */ + +/* PKUnity Peripheral bus (APB): 0xee000000 - 0xefffffff (128MB) */ +#define PUV3_GPIO_BASE (0xee500000)/* APB-5 */ +#define PUV3_INTC_BASE (0xee600000)/* APB-6 */ +#define PUV3_OST_BASE (0xee800000)/* APB-8 */ +#define PUV3_PM_BASE (0xeea00000)/* APB-10 */ +#define PUV3_PS2_BASE (0xeeb00000)/* APB-11 */ + +/* Hardware interrupts */ +#define PUV3_IRQS_NR (32) + +#define PUV3_IRQS_GPIOLOW0 (0) +#define PUV3_IRQS_GPIOLOW1 (1) +#define PUV3_IRQS_GPIOLOW2 (2) +#define PUV3_IRQS_GPIOLOW3 (3) +#define PUV3_IRQS_GPIOLOW4 (4) +#define PUV3_IRQS_GPIOLOW5 (5) +#define PUV3_IRQS_GPIOLOW6 (6) +#define PUV3_IRQS_GPIOLOW7 (7) +#define PUV3_IRQS_GPIOHIGH (8) +#define PUV3_IRQS_PS2_KBD (22) +#define PUV3_IRQS_PS2_AUX (23) +#define PUV3_IRQS_OST0 (26) + +/* All puv3_*.c use DPRINTF for debug. */ +#ifdef DEBUG_PUV3 +#define DPRINTF (fmt, ...) printf("%s: " fmt , __func__, ## __VA_ARGS__) +#else +#define DPRINTF (fmt, ...) do {} while (0) +#endif + +#endif /* !__PUV3_H__ */ hw/unicore32/Makefile.objs +5
-1@@ -1 +1,6 @@ # For UniCore32 machines and boards + +# PKUnity-v3 SoC and board information +obj-${CONFIG_PUV3} += puv3.o + +obj-y := $(addprefix ../,$(obj-y)) --1.7.0.4
Re: [Qemu-devel] [PATCHv3 11/14] unicore32-softmmu: Add puv3 pm support
In reply to Guan XuetaoQuoted 115 lines · Guan Xuetao
This patch adds puv3 pm (power management) support, include pm device simulation for kernel booting.
Signed-off-by Guan Xuetao <[email protected]>---
hw/Makefile.objs | 1 +
hw/puv3.c | 1 +
hw/puv3_pm.c | 148 ++++++++++++++++++++++++++++++++++++++++++++++++++++++3 files changed, 150 insertions(+), 0 deletions(-)create mode 100644
hw/puv3_pm.chw/Makefile.objs +0
-0@@ -70,6 +70,7 @@ hw-obj-$(CONFIG_XILINX_AXI) += xilinx_axienet.ohw-obj-$(CONFIG_PUV3) += puv3_intc.o
hw-obj-$(CONFIG_PUV3) += puv3_ost.o
hw-obj-$(CONFIG_PUV3) += puv3_gpio.o
+hw-obj-$(CONFIG_PUV3) += puv3_pm.o# PCI watchdog devices
hw-obj-$(CONFIG_PCI) += wdt_i6300esb.ohw/puv3.c +1
-0@@ -48,6 +48,7 @@ static void puv3_soc_init(CPUUniCore32State *env) } /* Initialize minimal necessary devices for kernel booting */ + sysbus_create_simple("puv3_pm", PUV3_PM_BASE, NULL); sysbus_create_simple("puv3_ost", PUV3_OST_BASE, irqs[PUV3_IRQS_OST0]); sysbus_create_varargs("puv3_gpio", PUV3_GPIO_BASE, irqs[PUV3_IRQS_GPIOLOW0], irqs[PUV3_IRQS_GPIOLOW1],hw/puv3_pm.c new file +74
-0@@ -0,0 +1,148 @@ +/* +* Power Management device simulation in PKUnity SoC +* +* Copyright (C) 2010-2012 Guan Xuetao +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation, or any later version. +* See the COPYING file in the top-level directory. +*/ +#include "hw.h" +#include "sysbus.h" + +#undef DEBUG_PUV3 +#include "puv3.h" + +typedef struct { + SysBusDevice busdev; + MemoryRegion iomem; + + uint32_t reg_PMCR; + uint32_t reg_PCGR; + uint32_t reg_PLL_SYS_CFG; + uint32_t reg_PLL_DDR_CFG; + uint32_t reg_PLL_VGA_CFG; + uint32_t reg_DIVCFG; +}PUV3PMState ; + +static uint64_t puv3_pm_read (void *opaque,target_phys_addr_t offset, + unsigned size) +{ + PUV3PMState *s = (PUV3PMState *) opaque; + uint32_t ret; + + switch (offset) { + case 0x14: + ret = s->reg_PCGR; + break; + case 0x18: + ret = s->reg_PLL_SYS_CFG; + break; + case 0x1c: + ret = s->reg_PLL_DDR_CFG; + break; + case 0x20: + ret = s->reg_PLL_VGA_CFG; + break; + case 0x24: + ret = s->reg_DIVCFG; + break; + case 0x28: /* PLL SYS STATUS */ + ret = 0x00002401; + break; + case 0x2c: /* PLL DDR STATUS */ + ret = 0x00100c00; + break; + case 0x30: /* PLL VGA STATUS */ + ret = 0x00003801; + break; + case 0x34: /* DIV STATUS */ + ret = 0x22f52015; + break; + case 0x38: /* SW RESET */ + ret = 0x0; + break; + case 0x44: /* PLL DFC DONE */ + ret = 0x7; + break; + default: + hw_error("%s: Bad offset 0x%x\n", __func__, offset); + } + DPRINTF("offset 0x%x, value 0x%x\n", offset, ret); + + return ret;
hw/puv3_pm.c line 84
Quoted 10 lines
hw/puv3_pm.c new file +10
-0+} + +static void puv3_pm_write (void *opaque,target_phys_addr_t offset, + uint64_t value, unsigned size) +{ + PUV3PMState *s = (PUV3PMState *) opaque; + + switch (offset) { + case 0x0: + s->reg_PMCR = value;
Missing 'break' or a comment about fall through.
Quoted 67 lines
hw/puv3_pm.c new file +64
-1+ case 0x14: + s->reg_PCGR = value; + break; + case 0x18: + s->reg_PLL_SYS_CFG = value; + break; + case 0x1c: + s->reg_PLL_DDR_CFG = value; + break; + case 0x20: + s->reg_PLL_VGA_CFG = value; + break; + case 0x24: + case 0x38: + break; + default: + hw_error("%s: Bad offset 0x%x\n", __func__, offset); + } + DPRINTF("offset 0x%x, value 0x%x\n", offset, value); +} + +static const MemoryRegionOps puv3_pm_ops = { + .read = puv3_pm_read, + .write = puv3_pm_write, + .impl = { + .min_access_size = 4, + .max_access_size = 4, + }, + .endianness = DEVICE_NATIVE_ENDIAN, +}; + +static int puv3_pm_init (SysBusDevice *dev) +{ + PUV3PMState *s = FROM_SYSBUS(PUV3PMState, dev); + + s->reg_PCGR = 0x0; + + memory_region_init_io(&s->iomem, &puv3_pm_ops, s, "puv3_pm", + PUV3_REGS_OFFSET); + sysbus_init_mmio(dev, &s->iomem); + + return 0; +} + +static void puv3_pm_class_init (ObjectClass *klass,void *data) +{ + SysBusDeviceClass *sdc = SYS_BUS_DEVICE_CLASS(klass); + + sdc->init = puv3_pm_init; +} + +static const TypeInfo puv3_pm_info = { + .name = "puv3_pm", + .parent = TYPE_SYS_BUS_DEVICE, + .instance_size = sizeof(PUV3PMState), + .class_init = puv3_pm_class_init, +}; + +static void puv3_pm_register_type (void ) +{ + type_register_static(&puv3_pm_info); +} + +type_init (puv3_pm_register_type) --1.7.0.4
Re: [Qemu-devel] [PATCHv3 02/14] unicore32-softmmu: Add coprocessor 0(sysctrl) and 1(ocd) instruction support
In reply to Blue SwirlQuoted 58 lines · Blue Swirl
Quoted 45 lines · Guan Xuetao
Coprocessor 0 is system control coprocessor, and we need get/set its contents. Also, all cache/tlb ops shoule be implemented here, but just ignored with no harm.
Coprocessor 1 is OCD (on-chip-debugger), which is used for faked console, so we could output chars to this console without graphic card.
Signed-off-by Guan Xuetao <[email protected]>--- target-unicore32/helper.c | 177 +++++++++++++++++++++++++++++++++--------- target-unicore32/helper.h | 17 ++--- target-unicore32/translate.c | 75 ++++++++++++++++++- 3 files changed, 221 insertions(+), 48 deletions(-)target-unicore32/helper.c +17
-0@@ -14,6 +14,14 @@#include "helper.h" #include "host-utils.h" +#undef DEBUG_UC32 + +#ifdef DEBUG_UC32 +#define DPRINTF (fmt, ...) printf("%s: " fmt , __func__, ## __VA_ARGS__) +#else +#define DPRINTF (fmt, ...) do {} while (0) +#endif +CPUUniCore32State *uc32_cpu_init (const char *cpu_model) {UniCore32CPU *cpu;@@ -45,6 +53,138 @@ uint32_t HELPER(clz)(uint32_t x)return clz32 (x); } +#ifndef CONFIG_USER_ONLY +void helper_cp0_set (CPUUniCore32State *env,uint32_t val,uint32_t creg, +uint32_t cop) +{ +/* +* movc pp.nn, rn, #imm9 +* rn: UCOP_REG_D +* nn: UCOP_REG_N +* 1: sys control reg. target-unicore32/helper.c uint32_t HELPER(clz)(uint32_t x) · line 74
Quoted 10 lines
target-unicore32/helper.c +10
-0+* 2: page table base reg. +* 3: data fault status reg. +* 4: insn fault status reg. +* 5: cache op. reg. +* 6: tlb op. reg. +* imm9: split UCOP_IMM10 with bit5 is 0 +*/ +switch (creg) { +case 1 : +if (cop !=0 ) goto unrecognized;Does this pass
scripts/checkpatch.pl? These should become
Quoted 3 lines
if (cop != 0) {
goto unrecognized;
}Thanks for pointing it out, and sorry for that.
I will correct it in next version.
Quoted 58 lines
Quoted 47 lines
target-unicore32/helper.c +46
-0+ env->cp0.c1_sys = val; +break ; +case 2 : +if (cop !=0 ) goto unrecognized; + env->cp0.c2_base = val; +break ; +case 3 : +if (cop !=0 ) goto unrecognized; + env->cp0.c3_faultstatus = val; +break ; +case 4 : +if (cop !=0 ) goto unrecognized; + env->cp0.c4_faultaddr = val; +break ; +case 5 : +switch (cop) { +case 28 : +DPRINTF ("Invalidate Entire I&D cache\n" ); +return ; +case 20 : +DPRINTF ("Invalidate Entire Icache\n" ); +return ; +case 12 : +DPRINTF ("Invalidate Entire Dcache\n" ); +return ; +case 10 : +DPRINTF ("Clean Entire Dcache\n" ); +return ; +case 14 : +DPRINTF ("Flush Entire Dcache\n" ); +return ; +case 13 : +DPRINTF ("Invalidate Dcache line\n" ); +return ; +case 11 : +DPRINTF ("Clean Dcache line\n" ); +return ; +case 15 : +DPRINTF ("Flush Dcache line\n" ); +return ; + } +break ; +case 6 : +if ((cop <=6 ) && (cop >=2 )) { +/* invalid all tlb */ +tlb_flush (env,1 );target-unicore32/helper.c uint32_t HELPER(clz)(uint32_t x) · line 130
Quoted 10 lines
target-unicore32/helper.c +10
-0+return ; + } +break ; +default : + goto unrecognized; + } +return ; +unrecognized: +cpu_abort (env,"Wrong register (%d) or wrong operation (%d) in cp0_set!\n" , + creg, cop);
Quoted 2 lines
The call to
cpu_abort()would mean that the guest is able to terminate QEMU at will, which is not OK. What does real HW do?
In my opinion, I just want to terminate qemu when any unhandled or unknown operations happen.
Quoted 49 lines
Quoted 49 lines
target-unicore32/helper.c +48
-0+} + +uint32_t helper_cp0_get (CPUUniCore32State *env,uint32_t creg,uint32_t cop) +{ +/* +* movc rd, pp.nn, #imm9 +* rd: UCOP_REG_D +* nn: UCOP_REG_N +* 0: cpuid and cachetype +* 1: sys control reg. +* 2: page table base reg. +* 3: data fault status reg. +* 4: insn fault status reg. +* imm9: split UCOP_IMM10 with bit5 is 0 +*/ +switch (creg) { +case 0 : +switch (cop) { +case 0 : +return env->cp0.c0_cpuid; +case 1 : +return env->cp0.c0_cachetype; + } +break ; +case 1 : +if (cop ==0 ) { +return env->cp0.c1_sys; + } +break ; +case 2 : +if (cop ==0 ) { +return env->cp0.c2_base; + } +break ; +case 3 : +if (cop ==0 ) { +return env->cp0.c3_faultstatus; + } +break ; +case 4 : +if (cop ==0 ) { +return env->cp0.c4_faultaddr; + } +break ; + } +cpu_abort (env,"Wrong register (%d) or wrong operation (%d) in cp0_set!\n" , + creg, cop); +}
Quoted 8 lines
target-unicore32/helper.c uint32_t HELPER(clz)(uint32_t x) · line 184
Quoted 6 lines
target-unicore32/helper.c +6
-0+ +void helper_cp1_putc (target_ulong x) +{ +printf ("%c" , x); +fflush (NULL ); +return ;Useless return.
Yes, thanks.
Quoted 2 lines
The printout should be enabled only for
DEBUG_UC32.
Here, I just want to print a char in the text console.
I tried printw and addch under curses environment, but their color schemes had some problems in my server, and I must call scrollok() at every new-line. (scrl() didn't work) So, I left printf here to output a character from ocd_console in kernel, and it works.
Thanks & Regards,
Guan Xuetao
Re: [Qemu-devel] [PATCHv3 07/14] unicore32-softmmu: Add puv3 soc/board support
In reply to Blue SwirlOn Mon, 2012-06-18 at 20:02 +0000, Blue Swirl wrote:
[snip]
Quoted 12 lines
Quoted 12 lines
hw/puv3.h new file +6
-0@@ -0,0 +1,49 @@ +/* +* Misc PKUnity SoC declarations +* +* Copyright (C) 2010-2012 Guan Xuetao +* +* This program is free software; you can redistribute it and/or modify
Quoted 8 lines
hw/puv3.h line 11
Quoted 5 lines
hw/puv3.h new file +5
-0+* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation, or any later version. +* See the COPYING file in the top-level directory. +*/ +#ifndef __PUV3_H__Use of leading underscores is reserved to Posix, please use for example
HW_PUV3_H.
Ok, I will change it.
Perhaps I'm wrong, but IMHO, leading underscores are used pervasively for headers protection and low-level definitions.
Guan Xuetao
Re: [Qemu-devel] [PATCHv3 11/14] unicore32-softmmu: Add puv3 pm support
In reply to Blue SwirlOn Mon, 2012-06-18 at 20:05 +0000, Blue Swirl wrote:
[snip]
Quoted 10 lines
hw/puv3_pm.c line 84
Quoted 8 lines
hw/puv3_pm.c new file +8
-0+static void puv3_pm_write (void *opaque,target_phys_addr_t offset, +uint64_t value,unsigned size) +{ +PUV3PMState *s = (PUV3PMState *) opaque; + +switch (offset) { +case 0x0 : + s->reg_PMCR = value;Missing 'break' or a comment about fall through.
Yes, 'break' is missed here.
Thanks ever so much.
Guan Xuetao
Re: [Qemu-devel] [PATCHv3 12/14] unicore32-softmmu: Add puv3 dma support
In reply to Blue SwirlOn Mon, 2012-06-18 at 19:59 +0000, Blue Swirl wrote:
[snip]
Quoted 9 lines
Quoted 9 lines
hw/puv3_dma.c new file +9
-0+ +#define PUV3_DMA_CH_NR (6) +#define PUV3_DMA_CH_MASK (0xff) +#define PUV3_DMA_CH (offset) ((offset) >> 8) + +typedef struct { + SysBusDevice busdev; + MemoryRegion iomem; + uint32_t reg_CFG[PUV3_DMA_CH_NR];
Quoted 8 lines
hw/puv3_dma.c line 30
Quoted 6 lines
hw/puv3_dma.c new file +6
-0+} PUV3DMAState; + +static uint64_t puv3_dma_read (void *opaque,target_phys_addr_t offset, +unsigned size) +{ +PUV3DMAState *s = (PUV3DMAState *) opaque;These casts from void pointer are not needed in C.
I see. Thanks.
Quoted 7 lines
Quoted 7 lines
hw/puv3_dma.c new file +7
-0+uint32_t ret; + +assert (PUV3_DMA_CH (offset) <PUV3_DMA_CH_NR ); + +switch (offset &PUV3_DMA_CH_MASK ) { +case 0x10 : + ret = s->reg_CFG[PUV3_DMA_CH (offset)];
Quoted 8 lines
hw/puv3_dma.c line 40
Quoted 3 lines
hw/puv3_dma.c new file +3
-0+break ; +default : +hw_error ("%s: Bad offset 0x%x\n" , __func__, offset);
hw_error()also aborts, it would be nice to avoid that. However, the situation is somewhat different from the instruction case, since only privileged guest code (kernel) can write to hardware. The kernel can also for example power off the machine.
It's the same problem as cpu_abort. Warning information is enough here. Is there a global and simple way to do it, g_warning()?
Guan Xuetao
Re: [Qemu-devel] [PATCHv3 02/14] unicore32-softmmu: Add coprocessor 0(sysctrl) and 1(ocd) instruction support
In reply to Guan XuetaoQuoted 6 lines
Quoted 4 lines
Does this pass
scripts/checkpatch.pl? These should becomeif (cop != 0) { goto unrecognized; }Thanks for pointing it out, and sorry for that.
I will correct it in next version.
You can run scripts/checkpatch.pl before you submit the patch.
Regards,
chenwj
Signature · 5 lines
Wei-Ren Chen (陳韋任) Computer Systems Lab, Institute of Information Science, Academia Sinica, Taiwan (R.O.C.) Tel:886-2-2788-3799 #1667 Homepage: http://people.cs.nctu.edu.tw/~chenwj
Re: [Qemu-devel] [PATCHv3 07/14] unicore32-softmmu: Add puv3 soc/board support
In reply to Guan XuetaoQuoted 22 lines · Guan Xuetao
On Mon, 2012-06-18 at 20:02 +0000, Blue Swirl wrote:
[snip]Quoted 12 lines
Quoted 12 lines
hw/puv3.h new file +6
-0@@ -0,0 +1,49 @@ +/* +* Misc PKUnity SoC declarations +* +* Copyright (C) 2010-2012 Guan Xuetao +* +* This program is free software; you can redistribute it and/or modify Quoted 8 lines
hw/puv3.h line 11
Quoted 5 lines
hw/puv3.h new file +5
-0+* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation, or any later version. +* See the COPYING file in the top-level directory. +*/ +#ifndef __PUV3_H__Use of leading underscores is reserved to Posix, please use for example
HW_PUV3_H.
Quoted 3 lines
Ok, I will change it.
Perhaps I'm wrong, but IMHO, leading underscores are used pervasively for headers protection and low-level definitions.
It's unfortunately common, but as mentioned in HACKING file, those are reserved to C and POSIX use. For example Linux kernel can disregard this, because it doesn't use libc and GCC does not exercise the right to use the reserved prefixes. I guess some people copy this style to applications where it's no longer correct.
Quoted 5 lines
Guan Xuetao
Re: [Qemu-devel] [PATCHv3 12/14] unicore32-softmmu: Add puv3 dma support
In reply to Guan XuetaoQuoted 37 lines · Guan Xuetao
On Mon, 2012-06-18 at 19:59 +0000, Blue Swirl wrote:
[snip]Quoted 9 lines
Quoted 9 lines
hw/puv3_dma.c new file +9
-0+ +#define PUV3_DMA_CH_NR (6) +#define PUV3_DMA_CH_MASK (0xff) +#define PUV3_DMA_CH (offset) ((offset) >> 8) + +typedef struct { + SysBusDevice busdev; + MemoryRegion iomem; + uint32_t reg_CFG[PUV3_DMA_CH_NR];Quoted 8 lines
hw/puv3_dma.c line 30
Quoted 6 lines
hw/puv3_dma.c new file +6
-0+} PUV3DMAState; + +static uint64_t puv3_dma_read (void *opaque,target_phys_addr_t offset, + unsigned size) +{ + PUV3DMAState *s = (PUV3DMAState *) opaque;These casts from void pointer are not needed in C.
I see. Thanks.
Quoted 7 lines
Quoted 7 lines
+ uint32_t ret;
hw/puv3_dma.c new file +6
-0+ + assert(PUV3_DMA_CH(offset) < PUV3_DMA_CH_NR); + + switch (offset & PUV3_DMA_CH_MASK) { + case 0x10: + ret = s->reg_CFG[PUV3_DMA_CH(offset)];Quoted 8 lines
Quoted 3 lines
+ break;
+ default:
+ hw_error("%s: Bad offset 0x%x\n",__func__, offset);
hw_error()also aborts, it would be nice to avoid that. However, the situation is somewhat different from the instruction case, since only privileged guest code (kernel) can write to hardware. The kernel can also for example power off the machine.
Quoted 2 lines
It's the same problem as
cpu_abort. Warning information is enough here. Is there a global and simple way to do it,g_warning()?
The users will probably not be very interested about any debugging messages. In cases like this, two common ways are to use trace points or debugging printf macros.
Quoted 3 lines
Guan Xuetao
Re: [Qemu-devel] [PATCHv3 02/14] unicore32-softmmu: Add coprocessor 0(sysctrl) and 1(ocd) instruction support
In reply to Guan XuetaoQuoted 123 lines · Guan Xuetao
Quoted 53 lines · Blue Swirl
Quoted 52 lines · Guan Xuetao
Coprocessor 0 is system control coprocessor, and we need get/set its contents. Also, all cache/tlb ops shoule be implemented here, but just ignored with no harm.
Coprocessor 1 is OCD (on-chip-debugger), which is used for faked console, so we could output chars to this console without graphic card.
Signed-off-by Guan Xuetao <[email protected]>---
target-unicore32/helper.c | 177 +++++++++++++++++++++++++++++++++---------target-unicore32/helper.h| 17 ++---target-unicore32/translate.c| 75 ++++++++++++++++++-3 files changed, 221 insertions(+), 48 deletions(-)target-unicore32/helper.c +24
-0@@ -14,6 +14,14 @@ #include "helper.h" #include "host-utils.h" +#undef DEBUG_UC32 + +#ifdef DEBUG_UC32 +#define DPRINTF (fmt, ...) printf("%s: " fmt , __func__, ## __VA_ARGS__) +#else +#define DPRINTF (fmt, ...) do {} while (0) +#endif + CPUUniCore32State *uc32_cpu_init(const char *cpu_model) { UniCore32CPU *cpu;@@ -45,6 +53,138 @@ uint32_t HELPER(clz)(uint32_t x) return clz32(x); } +#ifndef CONFIG_USER_ONLY +void helper_cp0_set (CPUUniCore32State *env,uint32_t val,uint32_t creg, + uint32_t cop) +{ + /* +* movc pp.nn, rn, #imm9 +* rn: UCOP_REG_D +* nn: UCOP_REG_N +* 1: sys control reg. +* 2: page table base reg. +* 3: data fault status reg. +* 4: insn fault status reg. +* 5: cache op. reg. +* 6: tlb op. reg. +* imm9: split UCOP_IMM10 with bit5 is 0 +*/ Quoted 8 lines
target-unicore32/helper.c uint32_t HELPER(clz)(uint32_t x) · line 74
Quoted 3 lines
target-unicore32/helper.c +3
-0+ switch (creg) { + case 1: + if (cop != 0) goto unrecognized;Does this pass
scripts/checkpatch.pl? These should become if (cop != 0) {
goto unrecognized;
}Thanks for pointing it out, and sorry for that.
I will correct it in next version.Quoted 58 lines
Quoted 57 lines
target-unicore32/helper.c +56
-0+ env->cp0.c1_sys = val; + break; + case 2: + if (cop != 0) goto unrecognized; + env->cp0.c2_base = val; + break; + case 3: + if (cop != 0) goto unrecognized; + env->cp0.c3_faultstatus = val; + break; + case 4: + if (cop != 0) goto unrecognized; + env->cp0.c4_faultaddr = val; + break; + case 5: + switch(cop) { + case 28: + DPRINTF("Invalidate Entire I&D cache\n"); + return; + case 20: + DPRINTF("Invalidate Entire Icache\n"); + return; + case 12: + DPRINTF("Invalidate Entire Dcache\n"); + return; + case 10: + DPRINTF("Clean Entire Dcache\n"); + return; + case 14: + DPRINTF("Flush Entire Dcache\n"); + return; + case 13: + DPRINTF("Invalidate Dcache line\n"); + return; + case 11: + DPRINTF("Clean Dcache line\n"); + return; + case 15: + DPRINTF("Flush Dcache line\n"); + return; + } + break; + case 6: + if ((cop <= 6) && (cop >=2)) { + /* invalid all tlb */ + tlb_flush(env, 1); + return; + } + break; + default: + goto unrecognized; + } + return; +unrecognized: + cpu_abort(env, "Wrong register (%d) or wrong operation (%d) in cp0_set!\n", + creg, cop);
Quoted 4 lines
Quoted 2 lines
The call to
cpu_abort()would mean that the guest is able to terminate QEMU at will, which is not OK. What does real HW do?In my opinion, I just want to terminate qemu when any unhandled or unknown operations happen.
This can make the emulator vulnerable in the security sense. Probably Unicore CPUs are not used now in an environment where the guest can not be trusted (like cloud computing), but who knows the future?
Quoted 61 lines
Quoted 50 lines
Quoted 50 lines
target-unicore32/helper.c +48
-0+} + +uint32_t helper_cp0_get (CPUUniCore32State *env,uint32_t creg,uint32_t cop) +{ + /* + * movc rd, pp.nn, #imm9 + * rd: UCOP_REG_D + * nn: UCOP_REG_N + * 0: cpuid and cachetype + * 1: sys control reg. + * 2: page table base reg. + * 3: data fault status reg. + * 4: insn fault status reg. + * imm9: split UCOP_IMM10 with bit5 is 0 + */ + switch (creg) { + case 0: + switch (cop) { + case 0: + return env->cp0.c0_cpuid; + case 1: + return env->cp0.c0_cachetype; + } + break; + case 1: + if (cop == 0) { + return env->cp0.c1_sys; + } + break; + case 2: + if (cop == 0) { + return env->cp0.c2_base; + } + break; + case 3: + if (cop == 0) { + return env->cp0.c3_faultstatus; + } + break; + case 4: + if (cop == 0) { + return env->cp0.c4_faultaddr; + } + break; + } + cpu_abort(env, "Wrong register (%d) or wrong operation (%d) in cp0_set!\n", + creg, cop); +}Quoted 8 lines
target-unicore32/helper.c uint32_t HELPER(clz)(uint32_t x) · line 184
Quoted 6 lines
target-unicore32/helper.c +6
-0+ +void helper_cp1_putc (target_ulong x) +{ + printf("%c", x); + fflush(NULL); + return;Useless return.
Yes, thanks.
Quoted 1 line
Quoted 6 lines
Quoted 1 line
The printout should be enabled only for
DEBUG_UC32.Here, I just want to print a char in the text console.
I tried printw and addch under curses environment, but their color schemes had some problems in my server, and I must callscrollok()at every new-line. (scrl()didn't work) So, I left printf here to output a character fromocd_consolein kernel, and it works.
It breaks the abstraction layer. CPUs very rarely have any direct instructions for high level I/O (like console output), instead I/O is handled via devices which are accessible via MMIO (or I/O ports for x86).
For debugging, anything can be possible, but that's why I suggested using DEBUG_UC32.
Quoted 5 lines
Thanks & Regards,
Guan Xuetao
Re: [Qemu-devel] [PATCHv3 07/14] unicore32-softmmu: Add puv3 soc/board support
In reply to Blue SwirlQuoted 28 lines · Guan Xuetao
Quoted 21 lines · Blue Swirl
[snip]
Quoted 19 lines
hw/puv3.h line 6
Quoted 12 lines
hw/puv3.h new file +6
-0@@ -0,0 +1,49 @@ +/* +* Misc PKUnity SoC declarations +* +* Copyright (C) 2010-2012 Guan Xuetao +* +* This program is free software; you can redistribute it and/or modify
Quoted 5 lines
hw/puv3.h new file +5
-0+* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation, or any later version. +* See the COPYING file in the top-level directory. +*/ +#ifndef __PUV3_H__Quoted 5 lines
Quoted 2 lines
Use of leading underscores is reserved to Posix, please use for example
HW_PUV3_H.Ok, I will change it.
Perhaps I'm wrong, but IMHO, leading underscores are used pervasively for headers protection and low-level definitions.
Quoted 6 lines
It's unfortunately common, but as mentioned in HACKING file, those are reserved to C and POSIX use. For example Linux kernel can disregard this, because it doesn't use libc and GCC does not exercise the right to use the reserved prefixes. I guess some people copy this style to applications where it's no longer correct.
I see. Thanks for your explanation.
Guan Xuetao
Re: [Qemu-devel] [PATCHv3 12/14] unicore32-softmmu: Add puv3 dma support
In reply to Blue SwirlQuoted 9 lines · Guan Xuetao
Quoted 8 lines · Blue Swirl
[snip]
Quoted 5 lines
hw_error()also aborts, it would be nice to avoid that. However, the situation is somewhat different from the instruction case, since only privileged guest code (kernel) can write to hardware. The kernel can also for example power off the machine.
Quoted 7 lines
Quoted 2 lines
It's the same problem as
cpu_abort. Warning information is enough here. Is there a global and simple way to do it,g_warning()?The users will probably not be very interested about any debugging messages. In cases like this, two common ways are to use trace points or debugging printf macros.
I see. I will re-consider all cpu_abort and hw_error calls.
Thanks & Regards.
Guan Xuetao
Re: [Qemu-devel] [PATCHv3 02/14] unicore32-softmmu: Add coprocessor 0(sysctrl) and 1(ocd) instruction support
In reply to Blue Swirl[snip]
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines
+unrecognized:
+ 聽 聽cpu_abort(env, "Wrong register (%d) or wrong operation (%d) incp0_set!\n",
Quoted 1 line
+ 聽 聽 聽 聽 聽 聽creg, cop);
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
The call to
cpu_abort()would mean that the guest is able to terminate QEMU at will, which is not OK. What does real HW do?In my opinion, I just want to terminate qemu when any unhandled or unknown operations happen.
This can make the emulator vulnerable in the security sense. Probably Unicore CPUs are not used now in an environment where the guest can not be trusted (like cloud computing), but who knows the future?
Is it proper to print such information to monitor? by using monitor_printf().
[snip]
Quoted 9 lines
Quoted 8 lines
Quoted 3 lines
The printout should be enabled only for
DEBUG_UC32.Here, I just want to print a char in the text console.
I tried printw and addch under curses environment, but their color schemes had some problems in my server, and I must callscrollok()at every new-line. (scrl()didn't work) So, I left printf here to output a character fromocd_consolein kernel, and it works.
Quoted 8 lines
It breaks the abstraction layer. CPUs very rarely have any direct instructions for high level I/O (like console output), instead I/O is handled via devices which are accessible via MMIO (or I/O ports for x86).
For debugging, anything can be possible, but that's why I suggested using
DEBUG_UC32.
I've found my errors. I'm going to use waddch() here. Please see my next version.
Thanks & Regards,
Guan Xuetao