*** 8bit AVR cores ***
v10 cover *** 8bit AVR cores ***
This series of patches adds 8bit AVR cores to QEMU.
All instruction, except BREAK/DES/SPM/SPMX, are implemented. Not fully tested yet. However I was able to execute simple code with functions. e.g fibonacci calculation. This series of patches include a non real, sample board.
No fuses support yet. PC is set to 0 at reset.
the patches include the following
1. just a basic 8bit AVR CPU, without instruction decoding or translation
2. CPU features which allow define the following 8bit AVR cores
avr1
avr2 avr25
avr3 avr31 avr35
avr4
avr5 avr51
avr6
xmega2 xmega4 xmega5 xmega6 xmega73. a definition of sample machine with SRAM, FLASH and CPU which allows to execute simple code
4. encoding for all AVR instructions
5. interrupt handling
6. helpers for IN, OUT, SLEEP, WBR & unsupported instructions
7. a decoder which given an opcode decides what istruction it is
8. translation of AVR instruction into TCG
9. all features together
changes since v3
1. rampD/X/Y/Z registers are encoded as 0x00ff0000 (instead of 0x000000ff) for faster address manipulaton
2. ffs changed to ctz32
3. duplicate code removed at avr_cpu_do_interrupt
4. using andc instead of not + and
5. fixing V flag calculation in varios instructions
6. freeing local variables in PUSH
7. tcg_const_local_i32 -> tcg_const_i32
8. using sextract32 instead of my implementation
9. fixing BLD instruction
10.xor(r) instead of 0xff - r at COM
11.fixing MULS/MULSU not to modify inputs' content
12.using SUB for NEG
13.fixing tcg_gen_qemu_ld/st call in XCH
changes since v4
1. target is now defined as big endian in order to optimize push_ret/pop_ret
2. all style warnings are fixed
3. adding cpu_set/get_sreg functions
4. simplifying gen_goto_tb as there is no real paging
5. env->pc -> env->pc_w
6. making flag dump more compact
7. more spacing
8. renaming CODE/DATA_INDEX -> MMU_CODE/DATA_IDX
9. removing avr_set_feature
10. SPL/SPH set bug fix
11. switching stb_phys to cpu_stb_data
12. cleaning up avr_decode
13. saving sreg, rampD/X/Y/Z, eind in HW format (savevm)
14. saving CPU features (savevm)
changes since v5
1. BLD bug fix
2. decoder generator is added
chages since v6
1. using cpu_get_sreg/cpu_set_sreg in avr_cpu_gdb_read_register/avr_cpu_gdb_write_register
2. configure the target as little endian because otherwise GDB does not work
3. fixing and testing gen_push_ret/gen_pop_ret
changes since v7
1. folding back v6
2. logging at helper_outb and helper_inb are done for non supported yet registers only
3. MAINTAINERS updated
changes since v8
1. removing hw/avr from hw/Makefile.obj as it should not be built for all
2. making linux compilable
3. testing on
a. Mac, Apple LLVM version 7.0.0
b. Ubuntu 12.04, gcc 4.9.2
c. Fedora 23, gcc 5.3.14. folding back some patches
5. translation bug fixes for ORI, CPI, XOR instructions
6. propper handling of cpu register writes though memory
changes since v9
1. removing forward declarations of static functions
2. disabling debug prints
3. switching to case range instead of if else if ...
4. LD/ST IN/OUT accessing CPU maintainder registers are not routed to any device
5. commenst about sample board and sample IO device added
6. sample board description is more descriptive now
7. memory_region_allocate_system_memory is used to create RAM
8. now there are helper_fullrd & helper_fullwr when LD/ST try to access registers
Michael Rolnik (10):
target-avr: AVR cores support is added.
target-avr: adding AVR CPU features/flavors
target-avr: adding a sample AVR board
target-avr: adding instructions encodings
target-avr: adding AVR interrupt handling
target-avr: adding helpers for IN, OUT, SLEEP, WBR & unsupported
instructions
target-avr: adding instruction decoder
target-avr: adding instruction translation
target-avr: updating translate.c to use instructions translation
target-avr: instruction decoder generator
MAINTAINERS | 6 + arch_init.c | 2 + configure | 5 + default-configs/avr-softmmu.mak | 21 + hw/avr/Makefile.objs | 21 + hw/avr/sample-io.c | 175 ++ hw/avr/sample.c | 136 ++ include/disas/bfd.h | 6 + include/sysemu/arch_init.h | 1 + target-avr/Makefile.objs | 25 + target-avr/cpu-qom.h | 84 + target-avr/cpu.c | 609 +++++++ target-avr/cpu.h | 229 +++ target-avr/cpugen/CMakeLists.txt | 38 + target-avr/cpugen/README.md | 17 + target-avr/cpugen/cpu/avr.yaml | 214 +++ target-avr/cpugen/src/CMakeLists.txt | 62 + target-avr/cpugen/src/cpugen.cpp | 460 +++++ target-avr/cpugen/src/utils.cpp | 27 + target-avr/cpugen/src/utils.h | 79 + target-avr/cpugen/xsl/decode.c.xsl | 103 ++ target-avr/cpugen/xsl/translate-inst.h.xsl | 118 ++ target-avr/cpugen/xsl/utils.xsl | 108 ++ target-avr/decode.c | 693 ++++++++ target-avr/gdbstub.c | 84 + target-avr/helper.c | 398 +++++ target-avr/helper.h | 28 + target-avr/machine.c | 117 ++ target-avr/machine.h | 21 + target-avr/translate-inst.c | 2621 ++++++++++++++++++++++++++++ target-avr/translate-inst.h | 762 ++++++++ target-avr/translate.c | 271 +++ target-avr/translate.h | 119 ++ 33 files changed, 7660 insertions(+) create mode 100644 default-configs/avr-softmmu.mak create mode 100644 hw/avr/Makefile.objs create mode 100644 hw/avr/sample-io.c create mode 100644 hw/avr/sample.c create mode 100644 target-avr/Makefile.objs create mode 100644 target-avr/cpu-qom.h create mode 100644 target-avr/cpu.c create mode 100644 target-avr/cpu.h create mode 100644 target-avr/cpugen/CMakeLists.txt create mode 100644 target-avr/cpugen/README.md create mode 100644 target-avr/cpugen/cpu/avr.yaml create mode 100644 target-avr/cpugen/src/CMakeLists.txt create mode 100644 target-avr/cpugen/src/cpugen.cpp create mode 100644 target-avr/cpugen/src/utils.cpp create mode 100644 target-avr/cpugen/src/utils.h create mode 100644 target-avr/cpugen/xsl/decode.c.xsl create mode 100644 target-avr/cpugen/xsl/translate-inst.h.xsl create mode 100644 target-avr/cpugen/xsl/utils.xsl create mode 100644 target-avr/decode.c create mode 100644 target-avr/gdbstub.c create mode 100644 target-avr/helper.c create mode 100644 target-avr/helper.h create mode 100644 target-avr/machine.c create mode 100644 target-avr/machine.h create mode 100644 target-avr/translate-inst.c create mode 100644 target-avr/translate-inst.h create mode 100644 target-avr/translate.c create mode 100644 target-avr/translate.h
Signature · 1 line
2.4.9 (Apple Git-60)
PATCH v10 2/10 target-avr: adding AVR CPU features/flavors
--- target-avr/cpu.c | 307 ++++++++++++++++++++++++++++++++++++++++++++++++++- target-avr/cpu.h | 49 ++++++++ target-avr/machine.c | 1 + 3 files changed, 356 insertions(+), 1 deletion(-)
target-avr/cpu.c +306 -1
@@ -203,6 +203,296 @@ static void avr_cpu_class_init(ObjectClass *oc, void *data) dc->cannot_destroy_with_object_finalize_yet = true; } +static void avr_avr1_initfn (Object *obj) +{ +AVRCPU *cpu =AVR_CPU (obj); +CPUAVRState *env = &cpu->env; + +avr_set_feature (env,AVR_FEATURE_LPM ); +avr_set_feature (env,AVR_FEATURE_2_BYTE_SP ); +avr_set_feature (env,AVR_FEATURE_2_BYTE_PC ); +} +static void avr_avr2_initfn (Object *obj) +{ +AVRCPU *cpu =AVR_CPU (obj); +CPUAVRState *env = &cpu->env; + +avr_set_feature (env,AVR_FEATURE_LPM ); +avr_set_feature (env,AVR_FEATURE_IJMP_ICALL ); +avr_set_feature (env,AVR_FEATURE_ADIW_SBIW ); +avr_set_feature (env,AVR_FEATURE_SRAM ); +avr_set_feature (env,AVR_FEATURE_BREAK ); + +avr_set_feature (env,AVR_FEATURE_2_BYTE_PC ); +avr_set_feature (env,AVR_FEATURE_2_BYTE_SP ); +} + +static void avr_avr25_initfn (Object *obj) +{ +AVRCPU *cpu =AVR_CPU (obj); +CPUAVRState *env = &cpu->env; + +avr_set_feature (env,AVR_FEATURE_LPM ); +avr_set_feature (env,AVR_FEATURE_IJMP_ICALL ); +avr_set_feature (env,AVR_FEATURE_ADIW_SBIW ); +avr_set_feature (env,AVR_FEATURE_SRAM ); +avr_set_feature (env,AVR_FEATURE_BREAK ); + +avr_set_feature (env,AVR_FEATURE_2_BYTE_PC ); +avr_set_feature (env,AVR_FEATURE_2_BYTE_SP ); +avr_set_feature (env,AVR_FEATURE_LPMX ); +avr_set_feature (env,AVR_FEATURE_MOVW ); +} + +static void avr_avr3_initfn (Object *obj) +{ +AVRCPU *cpu =AVR_CPU (obj); +CPUAVRState *env = &cpu->env; + +avr_set_feature (env,AVR_FEATURE_LPM ); +avr_set_feature (env,AVR_FEATURE_IJMP_ICALL ); +avr_set_feature (env,AVR_FEATURE_ADIW_SBIW ); +avr_set_feature (env,AVR_FEATURE_SRAM ); +avr_set_feature (env,AVR_FEATURE_BREAK ); + +avr_set_feature (env,AVR_FEATURE_2_BYTE_PC ); +avr_set_feature (env,AVR_FEATURE_2_BYTE_SP ); +avr_set_feature (env,AVR_FEATURE_JMP_CALL ); +} + +static void avr_avr31_initfn (Object *obj) +{ +AVRCPU *cpu =AVR_CPU (obj); +CPUAVRState *env = &cpu->env; + +avr_set_feature (env,AVR_FEATURE_LPM ); +avr_set_feature (env,AVR_FEATURE_IJMP_ICALL ); +avr_set_feature (env,AVR_FEATURE_ADIW_SBIW ); +avr_set_feature (env,AVR_FEATURE_SRAM ); +avr_set_feature (env,AVR_FEATURE_BREAK ); + +avr_set_feature (env,AVR_FEATURE_2_BYTE_PC ); +avr_set_feature (env,AVR_FEATURE_2_BYTE_SP ); +avr_set_feature (env,AVR_FEATURE_RAMPZ ); +avr_set_feature (env,AVR_FEATURE_ELPM ); +avr_set_feature (env,AVR_FEATURE_JMP_CALL ); +} + +static void avr_avr35_initfn (Object *obj) +{ +AVRCPU *cpu =AVR_CPU (obj); +CPUAVRState *env = &cpu->env; + +avr_set_feature (env,AVR_FEATURE_LPM ); +avr_set_feature (env,AVR_FEATURE_IJMP_ICALL ); +avr_set_feature (env,AVR_FEATURE_ADIW_SBIW ); +avr_set_feature (env,AVR_FEATURE_SRAM ); +avr_set_feature (env,AVR_FEATURE_BREAK ); + +avr_set_feature (env,AVR_FEATURE_2_BYTE_PC ); +avr_set_feature (env,AVR_FEATURE_2_BYTE_SP ); +avr_set_feature (env,AVR_FEATURE_JMP_CALL ); +avr_set_feature (env,AVR_FEATURE_LPMX ); +avr_set_feature (env,AVR_FEATURE_MOVW ); +} + +static void avr_avr4_initfn (Object *obj) +{ +AVRCPU *cpu =AVR_CPU (obj); +CPUAVRState *env = &cpu->env; + +avr_set_feature (env,AVR_FEATURE_LPM ); +avr_set_feature (env,AVR_FEATURE_IJMP_ICALL ); +avr_set_feature (env,AVR_FEATURE_ADIW_SBIW ); +avr_set_feature (env,AVR_FEATURE_SRAM ); +avr_set_feature (env,AVR_FEATURE_BREAK ); + +avr_set_feature (env,AVR_FEATURE_2_BYTE_PC ); +avr_set_feature (env,AVR_FEATURE_2_BYTE_SP ); +avr_set_feature (env,AVR_FEATURE_LPMX ); +avr_set_feature (env,AVR_FEATURE_MOVW ); +avr_set_feature (env,AVR_FEATURE_MUL ); +} + +static void avr_avr5_initfn (Object *obj) +{ +AVRCPU *cpu =AVR_CPU (obj); +CPUAVRState *env = &cpu->env; + +avr_set_feature (env,AVR_FEATURE_LPM ); +avr_set_feature (env,AVR_FEATURE_IJMP_ICALL ); +avr_set_feature (env,AVR_FEATURE_ADIW_SBIW ); +avr_set_feature (env,AVR_FEATURE_SRAM ); +avr_set_feature (env,AVR_FEATURE_BREAK ); + +avr_set_feature (env,AVR_FEATURE_2_BYTE_PC ); +avr_set_feature (env,AVR_FEATURE_2_BYTE_SP ); +avr_set_feature (env,AVR_FEATURE_JMP_CALL ); +avr_set_feature (env,AVR_FEATURE_LPMX ); +avr_set_feature (env,AVR_FEATURE_MOVW ); +avr_set_feature (env,AVR_FEATURE_MUL ); +} + +static void avr_avr51_initfn (Object *obj) +{ +AVRCPU *cpu =AVR_CPU (obj); +CPUAVRState *env = &cpu->env; + +avr_set_feature (env,AVR_FEATURE_LPM ); +avr_set_feature (env,AVR_FEATURE_IJMP_ICALL ); +avr_set_feature (env,AVR_FEATURE_ADIW_SBIW ); +avr_set_feature (env,AVR_FEATURE_SRAM ); +avr_set_feature (env,AVR_FEATURE_BREAK ); + +avr_set_feature (env,AVR_FEATURE_2_BYTE_PC ); +avr_set_feature (env,AVR_FEATURE_2_BYTE_SP ); +avr_set_feature (env,AVR_FEATURE_RAMPZ ); +avr_set_feature (env,AVR_FEATURE_ELPMX ); +avr_set_feature (env,AVR_FEATURE_ELPM ); +avr_set_feature (env,AVR_FEATURE_JMP_CALL ); +avr_set_feature (env,AVR_FEATURE_LPMX ); +avr_set_feature (env,AVR_FEATURE_MOVW ); +avr_set_feature (env,AVR_FEATURE_MUL ); +} +static void avr_avr6_initfn (Object *obj) +{ +AVRCPU *cpu =AVR_CPU (obj); +CPUAVRState *env = &cpu->env; + +avr_set_feature (env,AVR_FEATURE_LPM ); +avr_set_feature (env,AVR_FEATURE_IJMP_ICALL ); +avr_set_feature (env,AVR_FEATURE_ADIW_SBIW ); +avr_set_feature (env,AVR_FEATURE_SRAM ); +avr_set_feature (env,AVR_FEATURE_BREAK ); + +avr_set_feature (env,AVR_FEATURE_3_BYTE_PC ); +avr_set_feature (env,AVR_FEATURE_2_BYTE_SP ); +avr_set_feature (env,AVR_FEATURE_RAMPZ ); +avr_set_feature (env,AVR_FEATURE_EIJMP_EICALL ); +avr_set_feature (env,AVR_FEATURE_ELPMX ); +avr_set_feature (env,AVR_FEATURE_ELPM ); +avr_set_feature (env,AVR_FEATURE_JMP_CALL ); +avr_set_feature (env,AVR_FEATURE_LPMX ); +avr_set_feature (env,AVR_FEATURE_MOVW ); +avr_set_feature (env,AVR_FEATURE_MUL ); +} +static void avr_xmega2_initfn (Object *obj) +{ +AVRCPU *cpu =AVR_CPU (obj); +CPUAVRState *env = &cpu->env; + +avr_set_feature (env,AVR_FEATURE_LPM ); +avr_set_feature (env,AVR_FEATURE_IJMP_ICALL ); +avr_set_feature (env,AVR_FEATURE_ADIW_SBIW ); +avr_set_feature (env,AVR_FEATURE_SRAM ); +avr_set_feature (env,AVR_FEATURE_BREAK ); + +avr_set_feature (env,AVR_FEATURE_2_BYTE_PC ); +avr_set_feature (env,AVR_FEATURE_2_BYTE_SP ); +avr_set_feature (env,AVR_FEATURE_JMP_CALL ); +avr_set_feature (env,AVR_FEATURE_LPMX ); +avr_set_feature (env,AVR_FEATURE_MOVW ); +avr_set_feature (env,AVR_FEATURE_MUL ); +avr_set_feature (env,AVR_FEATURE_RMW ); +} +static void avr_xmega4_initfn (Object *obj) +{ +AVRCPU *cpu =AVR_CPU (obj); +CPUAVRState *env = &cpu->env; + +avr_set_feature (env,AVR_FEATURE_LPM ); +avr_set_feature (env,AVR_FEATURE_IJMP_ICALL ); +avr_set_feature (env,AVR_FEATURE_ADIW_SBIW ); +avr_set_feature (env,AVR_FEATURE_SRAM ); +avr_set_feature (env,AVR_FEATURE_BREAK ); + +avr_set_feature (env,AVR_FEATURE_2_BYTE_PC ); +avr_set_feature (env,AVR_FEATURE_2_BYTE_SP ); +avr_set_feature (env,AVR_FEATURE_RAMPZ ); +avr_set_feature (env,AVR_FEATURE_ELPMX ); +avr_set_feature (env,AVR_FEATURE_ELPM ); +avr_set_feature (env,AVR_FEATURE_JMP_CALL ); +avr_set_feature (env,AVR_FEATURE_LPMX ); +avr_set_feature (env,AVR_FEATURE_MOVW ); +avr_set_feature (env,AVR_FEATURE_MUL ); +avr_set_feature (env,AVR_FEATURE_RMW ); +} +static void avr_xmega5_initfn (Object *obj) +{ +AVRCPU *cpu =AVR_CPU (obj); +CPUAVRState *env = &cpu->env; + +avr_set_feature (env,AVR_FEATURE_LPM ); +avr_set_feature (env,AVR_FEATURE_IJMP_ICALL ); +avr_set_feature (env,AVR_FEATURE_ADIW_SBIW ); +avr_set_feature (env,AVR_FEATURE_SRAM ); +avr_set_feature (env,AVR_FEATURE_BREAK ); + +avr_set_feature (env,AVR_FEATURE_2_BYTE_PC ); +avr_set_feature (env,AVR_FEATURE_2_BYTE_SP ); +avr_set_feature (env,AVR_FEATURE_RAMPD ); +avr_set_feature (env,AVR_FEATURE_RAMPX ); +avr_set_feature (env,AVR_FEATURE_RAMPY ); +avr_set_feature (env,AVR_FEATURE_RAMPZ ); +avr_set_feature (env,AVR_FEATURE_ELPMX ); +avr_set_feature (env,AVR_FEATURE_ELPM ); +avr_set_feature (env,AVR_FEATURE_JMP_CALL ); +avr_set_feature (env,AVR_FEATURE_LPMX ); +avr_set_feature (env,AVR_FEATURE_MOVW ); +avr_set_feature (env,AVR_FEATURE_MUL ); +avr_set_feature (env,AVR_FEATURE_RMW ); +} + +static void avr_xmega6_initfn (Object *obj) +{ +AVRCPU *cpu =AVR_CPU (obj); +CPUAVRState *env = &cpu->env; + +avr_set_feature (env,AVR_FEATURE_LPM ); +avr_set_feature (env,AVR_FEATURE_IJMP_ICALL ); +avr_set_feature (env,AVR_FEATURE_ADIW_SBIW ); +avr_set_feature (env,AVR_FEATURE_SRAM ); +avr_set_feature (env,AVR_FEATURE_BREAK ); + +avr_set_feature (env,AVR_FEATURE_3_BYTE_PC ); +avr_set_feature (env,AVR_FEATURE_2_BYTE_SP ); +avr_set_feature (env,AVR_FEATURE_RAMPZ ); +avr_set_feature (env,AVR_FEATURE_EIJMP_EICALL ); +avr_set_feature (env,AVR_FEATURE_ELPMX ); +avr_set_feature (env,AVR_FEATURE_ELPM ); +avr_set_feature (env,AVR_FEATURE_JMP_CALL ); +avr_set_feature (env,AVR_FEATURE_LPMX ); +avr_set_feature (env,AVR_FEATURE_MOVW ); +avr_set_feature (env,AVR_FEATURE_MUL ); +avr_set_feature (env,AVR_FEATURE_RMW ); +} +static void avr_xmega7_initfn (Object *obj) +{ +AVRCPU *cpu =AVR_CPU (obj); +CPUAVRState *env = &cpu->env; + +avr_set_feature (env,AVR_FEATURE_LPM ); +avr_set_feature (env,AVR_FEATURE_IJMP_ICALL ); +avr_set_feature (env,AVR_FEATURE_ADIW_SBIW ); +avr_set_feature (env,AVR_FEATURE_SRAM ); +avr_set_feature (env,AVR_FEATURE_BREAK ); + +avr_set_feature (env,AVR_FEATURE_3_BYTE_PC ); +avr_set_feature (env,AVR_FEATURE_2_BYTE_SP ); +avr_set_feature (env,AVR_FEATURE_RAMPD ); +avr_set_feature (env,AVR_FEATURE_RAMPX ); +avr_set_feature (env,AVR_FEATURE_RAMPY ); +avr_set_feature (env,AVR_FEATURE_RAMPZ ); +avr_set_feature (env,AVR_FEATURE_EIJMP_EICALL ); +avr_set_feature (env,AVR_FEATURE_ELPMX ); +avr_set_feature (env,AVR_FEATURE_ELPM ); +avr_set_feature (env,AVR_FEATURE_JMP_CALL ); +avr_set_feature (env,AVR_FEATURE_LPMX ); +avr_set_feature (env,AVR_FEATURE_MOVW ); +avr_set_feature (env,AVR_FEATURE_MUL ); +avr_set_feature (env,AVR_FEATURE_RMW ); +} +static void avr_any_initfn (Object *obj) {/* Set cpu feature flags */
@@ -214,7 +504,22 @@ typedef struct AVRCPUInfo { } AVRCPUInfo;static const AVRCPUInfo avr_cpus[] = { - { .name ="any" , .initfn = avr_any_initfn }, + {.name ="avr1" , .initfn = avr_avr1_initfn}, + {.name ="avr2" , .initfn = avr_avr2_initfn}, + {.name ="avr25" , .initfn = avr_avr25_initfn}, + {.name ="avr3" , .initfn = avr_avr3_initfn}, + {.name ="avr31" , .initfn = avr_avr31_initfn}, + {.name ="avr35" , .initfn = avr_avr35_initfn}, + {.name ="avr4" , .initfn = avr_avr4_initfn}, + {.name ="avr5" , .initfn = avr_avr5_initfn}, + {.name ="avr51" , .initfn = avr_avr51_initfn}, + {.name ="avr6" , .initfn = avr_avr6_initfn}, + {.name ="xmega2" , .initfn = avr_xmega2_initfn}, + {.name ="xmega4" , .initfn = avr_xmega4_initfn}, + {.name ="xmega5" , .initfn = avr_xmega5_initfn}, + {.name ="xmega6" , .initfn = avr_xmega6_initfn}, + {.name ="xmega7" , .initfn = avr_xmega7_initfn}, + {.name ="any" , .initfn = avr_any_initfn }, };static gint avr_cpu_list_compare (gconstpointer a,gconstpointer b)
target-avr/cpu.h +49 -0
65 lines not on this page · raw message
target-avr/machine.c +1 -0
@@ -98,6 +98,7 @@ const VMStateDescription vms_avr_cpu = { .version_id = 0, .minimum_version_id = 0, .fields = (VMStateField []) { +VMSTATE_UINT32 (env.features,AVRCPU ),VMSTATE_UINT32 (env.pc_w,AVRCPU ),VMSTATE_UINT32 (env.sp,AVRCPU ),
Signature · 1 line
2.4.9 (Apple Git-60)
PATCH v10 3/10 target-avr: adding a sample AVR board
In reply to Michael Rolnik--- MAINTAINERS | 6 ++ hw/avr/Makefile.objs | 21 +++++++ hw/avr/sample-io.c | 175 +++++++++++++++++++++++++++++++++++++++++++++++++++ hw/avr/sample.c | 136 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 338 insertions(+) create mode 100644 hw/avr/Makefile.objs create mode 100644 hw/avr/sample-io.c create mode 100644 hw/avr/sample.c
MAINTAINERS +6 -0
@@ -110,6 +110,12 @@ F: disas/arm.c F: disas/arm-a64.cc F: disas/libvixl/ +AVR +M: Michael Rolnik <[email protected]> +S: Maintained +F: target-avr/ +F: hw/avr/ + CRIS M: Edgar E. Iglesias <[email protected]> S: Maintained
hw/avr/Makefile.objs new file +21 -0
@@ -0,0 +1,21 @@ +# +# QEMU AVR CPU +# +# Copyright (c) 2016 Michael Rolnik +# +# 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.1 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/lgpl-2.1.html> +# + +obj-y += sample.o sample-io.o
hw/avr/sample-io.c new file +175 -0
175 lines not on this page · raw message
hw/avr/sample.c new file +136 -0
136 lines not on this page · raw message
Signature · 1 line
2.4.9 (Apple Git-60)
PATCH v10 1/10 target-avr: AVR cores support is added.
In reply to Michael Rolnik 1. basic CPU structure
2. registers
3. no instructions
4. saving sreg, rampD, rampX, rampY, rampD, eind in HW representation saving cpu features
--- arch_init.c | 2 + configure | 5 + default-configs/avr-softmmu.mak | 21 +++ include/disas/bfd.h | 6 + include/sysemu/arch_init.h | 1 + target-avr/Makefile.objs | 23 +++ target-avr/cpu-qom.h | 84 +++++++++++ target-avr/cpu.c | 304 ++++++++++++++++++++++++++++++++++++++++ target-avr/cpu.h | 180 ++++++++++++++++++++++++ target-avr/gdbstub.c | 84 +++++++++++ target-avr/helper.c | 87 ++++++++++++ target-avr/helper.h | 21 +++ target-avr/machine.c | 116 +++++++++++++++ target-avr/machine.h | 21 +++ target-avr/translate.c | 291 ++++++++++++++++++++++++++++++++++++++ 15 files changed, 1246 insertions(+) create mode 100644 default-configs/avr-softmmu.mak create mode 100644 target-avr/Makefile.objs create mode 100644 target-avr/cpu-qom.h create mode 100644 target-avr/cpu.c create mode 100644 target-avr/cpu.h create mode 100644 target-avr/gdbstub.c create mode 100644 target-avr/helper.c create mode 100644 target-avr/helper.h create mode 100644 target-avr/machine.c create mode 100644 target-avr/machine.h create mode 100644 target-avr/translate.c
arch_init.c +2 -0
@@ -80,6 +80,8 @@ int graphic_depth = 32;#define QEMU_ARCH QEMU_ARCH_UNICORE32#elif defined(TARGET_TRICORE )#define QEMU_ARCH QEMU_ARCH_TRICORE +#elif defined(TARGET_AVR ) +#define QEMU_ARCH QEMU_ARCH_AVR#endif const uint32_t arch_type =QEMU_ARCH ;
configure +5 -0
@@ -5641,6 +5641,8 @@ case "$target_name" in x86_64) TARGET_BASE_ARCH=i386 ;; + avr) + ;; alpha) ;; arm|armeb)
@@ -5837,6 +5839,9 @@ disas_config() { for i in $ARCH $TARGET_BASE_ARCH ; do case "$i" in + avr) + disas_config "AVR" + ;; alpha) disas_config "ALPHA" ;;
default-configs/avr-softmmu.mak new file +21 -0
@@ -0,0 +1,21 @@ +# +# QEMU AVR CPU +# +# Copyright (c) 2016 Michael Rolnik +# +# 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.1 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/lgpl-2.1.html> +# + +# Default configuration for avr-softmmu
include/disas/bfd.h +6 -0
@@ -213,6 +213,12 @@ enum bfd_architecture#define bfd_mach_m32r 0/* backwards compatibility */ bfd_arch_mn10200, /* Matsushita MN10200 */ bfd_arch_mn10300, /* Matsushita MN10300 */ + bfd_arch_avr, /* Atmel AVR microcontrollers. */ +#define bfd_mach_avr1 1 +#define bfd_mach_avr2 2 +#define bfd_mach_avr3 3 +#define bfd_mach_avr4 4 +#define bfd_mach_avr5 5 bfd_arch_cris, /* Axis CRIS */#define bfd_mach_cris_v0_v10 255#define bfd_mach_cris_v32 32
include/sysemu/arch_init.h +1 -0
@@ -23,6 +23,7 @@ enum {QEMU_ARCH_UNICORE32 = (1 <<14 ),QEMU_ARCH_MOXIE = (1 <<15 ),QEMU_ARCH_TRICORE = (1 <<16 ), + QEMU_ARCH_AVR = (1 << 17), };extern const uint32_t arch_type;
target-avr/Makefile.objs new file +23 -0
@@ -0,0 +1,23 @@ +# +# QEMU AVR CPU +# +# Copyright (c) 2016 Michael Rolnik +# +# 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.1 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/lgpl-2.1.html> +# + +obj-y += translate.o cpu.o helper.o +obj-y += gdbstub.o +obj-$(CONFIG_SOFTMMU) += machine.o
target-avr/cpu-qom.h new file +84 -0
84 lines not on this page · raw message
target-avr/cpu.c new file +304 -0
304 lines not on this page · raw message
target-avr/cpu.h new file +180 -0
180 lines not on this page · raw message
target-avr/gdbstub.c new file +84 -0
84 lines not on this page · raw message
target-avr/helper.c new file +87 -0
87 lines not on this page · raw message
target-avr/helper.h new file +21 -0
@@ -0,0 +1,21 @@ +/* +* QEMU AVR CPU +* +* Copyright (c) 2016 Michael Rolnik +* +* 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.1 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/lgpl-2.1.html> +*/ + +DEF_HELPER_1 (debug, void, env)
target-avr/machine.c new file +116 -0
116 lines not on this page · raw message
target-avr/machine.h new file +21 -0
@@ -0,0 +1,21 @@ +/* +* QEMU AVR CPU +* +* Copyright (c) 2016 Michael Rolnik +* +* 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.1 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/lgpl-2.1.html> +*/ + +extern const VMStateDescription vmstate_avr_cpu;
target-avr/translate.c new file +291 -0
291 lines not on this page · raw message
Signature · 1 line
2.4.9 (Apple Git-60)
PATCH v10 4/10 target-avr: adding instructions encodings
In reply to Michael Rolnik--- target-avr/translate-inst.h | 762 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 762 insertions(+) create mode 100644 target-avr/translate-inst.h
target-avr/translate-inst.h new file +762 -0
@@ -0,0 +1,762 @@ +/* +* QEMU AVR CPU +* +* Copyright (c) 2016 Michael Rolnik +* +* 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.1 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/lgpl-2.1.html> +*/ + + +#ifndef AVR_TRANSLATE_INST_H_ +#define AVR_TRANSLATE_INST_H_ + +typedef struct DisasContext DisasContext ; + +int avr_translate_NOP (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); + +int avr_translate_MOVW (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); +static inline uint32_t MOVW_Rr (uint32_t opcode) +{ +return extract32 (opcode,0 ,4 ); +} +static inline uint32_t MOVW_Rd (uint32_t opcode) +{ +return extract32 (opcode,4 ,4 ); +} + +int avr_translate_MULS (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); +static inline uint32_t MULS_Rr (uint32_t opcode) +{ +return extract32 (opcode,0 ,4 ); +} +static inline uint32_t MULS_Rd (uint32_t opcode) +{ +return extract32 (opcode,4 ,4 ); +} + +int avr_translate_MULSU (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); +static inline uint32_t MULSU_Rr (uint32_t opcode) +{ +return extract32 (opcode,0 ,3 ); +} +static inline uint32_t MULSU_Rd (uint32_t opcode) +{ +return extract32 (opcode,4 ,3 ); +} + +int avr_translate_FMUL (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); +static inline uint32_t FMUL_Rr (uint32_t opcode) +{ +return extract32 (opcode,0 ,3 ); +} +static inline uint32_t FMUL_Rd (uint32_t opcode) +{ +return extract32 (opcode,4 ,3 ); +} + +int avr_translate_FMULS (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); +static inline uint32_t FMULS_Rr (uint32_t opcode) +{ +return extract32 (opcode,0 ,3 ); +} +static inline uint32_t FMULS_Rd (uint32_t opcode) +{ +return extract32 (opcode,4 ,3 ); +} + +int avr_translate_FMULSU (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); +static inline uint32_t FMULSU_Rr (uint32_t opcode) +{ +return extract32 (opcode,0 ,3 ); +} +static inline uint32_t FMULSU_Rd (uint32_t opcode) +{ +return extract32 (opcode,4 ,3 ); +} + +int avr_translate_CPC (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); +static inline uint32_t CPC_Rd (uint32_t opcode) +{ +return extract32 (opcode,4 ,5 ); +} +static inline uint32_t CPC_Rr (uint32_t opcode) +{ +return (extract32 (opcode,9 ,1 ) <<4 ) | + (extract32 (opcode,0 ,4 )); +} + +int avr_translate_SBC (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); +static inline uint32_t SBC_Rd (uint32_t opcode) +{ +return extract32 (opcode,4 ,5 ); +} +static inline uint32_t SBC_Rr (uint32_t opcode) +{ +return (extract32 (opcode,9 ,1 ) <<4 ) | + (extract32 (opcode,0 ,4 )); +} + +int avr_translate_ADD (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); +static inline uint32_t ADD_Rd (uint32_t opcode) +{ +return extract32 (opcode,4 ,5 ); +} +static inline uint32_t ADD_Rr (uint32_t opcode) +{ +return (extract32 (opcode,9 ,1 ) <<4 ) | + (extract32 (opcode,0 ,4 )); +} + +int avr_translate_AND (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); +static inline uint32_t AND_Rd (uint32_t opcode) +{ +return extract32 (opcode,4 ,5 ); +} +static inline uint32_t AND_Rr (uint32_t opcode) +{ +return (extract32 (opcode,9 ,1 ) <<4 ) | + (extract32 (opcode,0 ,4 )); +} + +int avr_translate_EOR (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); +static inline uint32_t EOR_Rd (uint32_t opcode) +{ +return extract32 (opcode,4 ,5 ); +} +static inline uint32_t EOR_Rr (uint32_t opcode) +{ +return (extract32 (opcode,9 ,1 ) <<4 ) | + (extract32 (opcode,0 ,4 )); +} + +int avr_translate_OR (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); +static inline uint32_t OR_Rd (uint32_t opcode) +{ +return extract32 (opcode,4 ,5 ); +} +static inline uint32_t OR_Rr (uint32_t opcode) +{ +return (extract32 (opcode,9 ,1 ) <<4 ) | + (extract32 (opcode,0 ,4 )); +} + +int avr_translate_MOV (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); +static inline uint32_t MOV_Rd (uint32_t opcode) +{ +return extract32 (opcode,4 ,5 ); +} +static inline uint32_t MOV_Rr (uint32_t opcode) +{ +return (extract32 (opcode,9 ,1 ) <<4 ) | + (extract32 (opcode,0 ,4 )); +} + +int avr_translate_CPSE (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); +static inline uint32_t CPSE_Rd (uint32_t opcode) +{ +return extract32 (opcode,4 ,5 ); +} +static inline uint32_t CPSE_Rr (uint32_t opcode) +{ +return (extract32 (opcode,9 ,1 ) <<4 ) | + (extract32 (opcode,0 ,4 )); +} + +int avr_translate_CP (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); +static inline uint32_t CP_Rd (uint32_t opcode) +{ +return extract32 (opcode,4 ,5 ); +} +static inline uint32_t CP_Rr (uint32_t opcode) +{ +return (extract32 (opcode,9 ,1 ) <<4 ) | + (extract32 (opcode,0 ,4 )); +} + +int avr_translate_SUB (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); +static inline uint32_t SUB_Rd (uint32_t opcode) +{ +return extract32 (opcode,4 ,5 ); +} +static inline uint32_t SUB_Rr (uint32_t opcode) +{ +return (extract32 (opcode,9 ,1 ) <<4 ) | + (extract32 (opcode,0 ,4 )); +} + +int avr_translate_ADC (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); +static inline uint32_t ADC_Rd (uint32_t opcode) +{ +return extract32 (opcode,4 ,5 ); +} +static inline uint32_t ADC_Rr (uint32_t opcode) +{ +return (extract32 (opcode,9 ,1 ) <<4 ) | + (extract32 (opcode,0 ,4 )); +} + +int avr_translate_CPI (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); +static inline uint32_t CPI_Rd (uint32_t opcode) +{ +return extract32 (opcode,4 ,4 ); +} +static inline uint32_t CPI_Imm (uint32_t opcode) +{ +return (extract32 (opcode,8 ,4 ) <<4 ) | + (extract32 (opcode,0 ,4 )); +} + +int avr_translate_SBCI (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); +static inline uint32_t SBCI_Rd (uint32_t opcode) +{ +return extract32 (opcode,4 ,4 ); +} +static inline uint32_t SBCI_Imm (uint32_t opcode) +{ +return (extract32 (opcode,8 ,4 ) <<4 ) | + (extract32 (opcode,0 ,4 )); +} + +int avr_translate_ORI (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); +static inline uint32_t ORI_Rd (uint32_t opcode) +{ +return extract32 (opcode,4 ,4 ); +} +static inline uint32_t ORI_Imm (uint32_t opcode) +{ +return (extract32 (opcode,8 ,4 ) <<4 ) | + (extract32 (opcode,0 ,4 )); +} + +int avr_translate_SUBI (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); +static inline uint32_t SUBI_Rd (uint32_t opcode) +{ +return extract32 (opcode,4 ,4 ); +} +static inline uint32_t SUBI_Imm (uint32_t opcode) +{ +return (extract32 (opcode,8 ,4 ) <<4 ) | + (extract32 (opcode,0 ,4 )); +} + +int avr_translate_ANDI (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); +static inline uint32_t ANDI_Rd (uint32_t opcode) +{ +return extract32 (opcode,4 ,4 ); +} +static inline uint32_t ANDI_Imm (uint32_t opcode) +{ +return (extract32 (opcode,8 ,4 ) <<4 ) | + (extract32 (opcode,0 ,4 )); +} + +int avr_translate_LDDZ (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); +static inline uint32_t LDDZ_Rd (uint32_t opcode) +{ +return extract32 (opcode,4 ,5 ); +} +static inline uint32_t LDDZ_Imm (uint32_t opcode) +{ +return (extract32 (opcode,13 ,1 ) <<5 ) | + (extract32 (opcode,10 ,2 ) <<3 ) | + (extract32 (opcode,0 ,3 )); +} + +int avr_translate_LDDY (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); +static inline uint32_t LDDY_Rd (uint32_t opcode) +{ +return extract32 (opcode,4 ,5 ); +} +static inline uint32_t LDDY_Imm (uint32_t opcode) +{ +return (extract32 (opcode,13 ,1 ) <<5 ) | + (extract32 (opcode,10 ,2 ) <<3 ) | + (extract32 (opcode,0 ,3 )); +} + +int avr_translate_STDZ (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); +static inline uint32_t STDZ_Rd (uint32_t opcode) +{ +return extract32 (opcode,4 ,5 ); +} +static inline uint32_t STDZ_Imm (uint32_t opcode) +{ +return (extract32 (opcode,13 ,1 ) <<5 ) | + (extract32 (opcode,10 ,2 ) <<3 ) | + (extract32 (opcode,0 ,3 )); +} + +int avr_translate_STDY (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); +static inline uint32_t STDY_Rd (uint32_t opcode) +{ +return extract32 (opcode,4 ,5 ); +} +static inline uint32_t STDY_Imm (uint32_t opcode) +{ +return (extract32 (opcode,13 ,1 ) <<5 ) | + (extract32 (opcode,10 ,2 ) <<3 ) | + (extract32 (opcode,0 ,3 )); +} + +int avr_translate_LDS (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); +static inline uint32_t LDS_Imm (uint32_t opcode) +{ +return extract32 (opcode,0 ,16 ); +} +static inline uint32_t LDS_Rd (uint32_t opcode) +{ +return extract32 (opcode,20 ,5 ); +} + +int avr_translate_LDZ2 (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); +static inline uint32_t LDZ2_Rd (uint32_t opcode) +{ +return extract32 (opcode,4 ,5 ); +} + +int avr_translate_LDZ3 (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); +static inline uint32_t LDZ3_Rd (uint32_t opcode) +{ +return extract32 (opcode,4 ,5 ); +} + +int avr_translate_LPM2 (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); +static inline uint32_t LPM2_Rd (uint32_t opcode) +{ +return extract32 (opcode,4 ,5 ); +} + +int avr_translate_LPMX (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); +static inline uint32_t LPMX_Rd (uint32_t opcode) +{ +return extract32 (opcode,4 ,5 ); +} + +int avr_translate_ELPM2 (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); +static inline uint32_t ELPM2_Rd (uint32_t opcode) +{ +return extract32 (opcode,4 ,5 ); +} + +int avr_translate_ELPMX (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); +static inline uint32_t ELPMX_Rd (uint32_t opcode) +{ +return extract32 (opcode,4 ,5 ); +} + +int avr_translate_LDY2 (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); +static inline uint32_t LDY2_Rd (uint32_t opcode) +{ +return extract32 (opcode,4 ,5 ); +} + +int avr_translate_LDY3 (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); +static inline uint32_t LDY3_Rd (uint32_t opcode) +{ +return extract32 (opcode,4 ,5 ); +} + +int avr_translate_LDX1 (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); +static inline uint32_t LDX1_Rd (uint32_t opcode) +{ +return extract32 (opcode,4 ,5 ); +} + +int avr_translate_LDX2 (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); +static inline uint32_t LDX2_Rd (uint32_t opcode) +{ +return extract32 (opcode,4 ,5 ); +} + +int avr_translate_LDX3 (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); +static inline uint32_t LDX3_Rd (uint32_t opcode) +{ +return extract32 (opcode,4 ,5 ); +} + +int avr_translate_POP (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); +static inline uint32_t POP_Rd (uint32_t opcode) +{ +return extract32 (opcode,4 ,5 ); +} + +int avr_translate_STS (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); +static inline uint32_t STS_Imm (uint32_t opcode) +{ +return extract32 (opcode,0 ,16 ); +} +static inline uint32_t STS_Rd (uint32_t opcode) +{ +return extract32 (opcode,20 ,5 ); +} + +int avr_translate_STZ2 (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); +static inline uint32_t STZ2_Rd (uint32_t opcode) +{ +return extract32 (opcode,4 ,5 ); +} + +int avr_translate_STZ3 (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); +static inline uint32_t STZ3_Rd (uint32_t opcode) +{ +return extract32 (opcode,4 ,5 ); +} + +int avr_translate_XCH (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); +static inline uint32_t XCH_Rd (uint32_t opcode) +{ +return extract32 (opcode,4 ,5 ); +} + +int avr_translate_LAS (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); +static inline uint32_t LAS_Rr (uint32_t opcode) +{ +return extract32 (opcode,4 ,5 ); +} + +int avr_translate_LAC (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); +static inline uint32_t LAC_Rr (uint32_t opcode) +{ +return extract32 (opcode,4 ,5 ); +} + +int avr_translate_LAT (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); +static inline uint32_t LAT_Rr (uint32_t opcode) +{ +return extract32 (opcode,4 ,5 ); +} + +int avr_translate_STY2 (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); +static inline uint32_t STY2_Rd (uint32_t opcode) +{ +return extract32 (opcode,4 ,5 ); +} + +int avr_translate_STY3 (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); +static inline uint32_t STY3_Rd (uint32_t opcode) +{ +return extract32 (opcode,4 ,5 ); +} + +int avr_translate_STX1 (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); +static inline uint32_t STX1_Rr (uint32_t opcode) +{ +return extract32 (opcode,4 ,5 ); +} + +int avr_translate_STX2 (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); +static inline uint32_t STX2_Rr (uint32_t opcode) +{ +return extract32 (opcode,4 ,5 ); +} + +int avr_translate_STX3 (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); +static inline uint32_t STX3_Rr (uint32_t opcode) +{ +return extract32 (opcode,4 ,5 ); +} + +int avr_translate_PUSH (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); +static inline uint32_t PUSH_Rd (uint32_t opcode) +{ +return extract32 (opcode,4 ,5 ); +} + +int avr_translate_COM (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); +static inline uint32_t COM_Rd (uint32_t opcode) +{ +return extract32 (opcode,4 ,5 ); +} + +int avr_translate_NEG (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); +static inline uint32_t NEG_Rd (uint32_t opcode) +{ +return extract32 (opcode,4 ,5 ); +} + +int avr_translate_SWAP (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); +static inline uint32_t SWAP_Rd (uint32_t opcode) +{ +return extract32 (opcode,4 ,5 ); +} + +int avr_translate_INC (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); +static inline uint32_t INC_Rd (uint32_t opcode) +{ +return extract32 (opcode,4 ,5 ); +} + +int avr_translate_ASR (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); +static inline uint32_t ASR_Rd (uint32_t opcode) +{ +return extract32 (opcode,4 ,5 ); +} + +int avr_translate_LSR (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); +static inline uint32_t LSR_Rd (uint32_t opcode) +{ +return extract32 (opcode,4 ,5 ); +} + +int avr_translate_ROR (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); +static inline uint32_t ROR_Rd (uint32_t opcode) +{ +return extract32 (opcode,4 ,5 ); +} + +int avr_translate_BSET (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); +static inline uint32_t BSET_Bit (uint32_t opcode) +{ +return extract32 (opcode,4 ,3 ); +} + +int avr_translate_IJMP (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); + +int avr_translate_EIJMP (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); + +int avr_translate_BCLR (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); +static inline uint32_t BCLR_Bit (uint32_t opcode) +{ +return extract32 (opcode,4 ,3 ); +} + +int avr_translate_RET (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); + +int avr_translate_RETI (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); + +int avr_translate_ICALL (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); + +int avr_translate_EICALL (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); + +int avr_translate_SLEEP (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); + +int avr_translate_BREAK (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); + +int avr_translate_WDR (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); + +int avr_translate_LPM1 (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); + +int avr_translate_ELPM1 (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); + +int avr_translate_SPM (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); + +int avr_translate_SPMX (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); + +int avr_translate_DEC (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); +static inline uint32_t DEC_Rd (uint32_t opcode) +{ +return extract32 (opcode,4 ,5 ); +} + +int avr_translate_DES (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); +static inline uint32_t DES_Imm (uint32_t opcode) +{ +return extract32 (opcode,4 ,4 ); +} + +int avr_translate_JMP (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); +static inline uint32_t JMP_Imm (uint32_t opcode) +{ +return (extract32 (opcode,20 ,5 ) <<17 ) | + (extract32 (opcode,0 ,17 )); +} + +int avr_translate_CALL (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); +static inline uint32_t CALL_Imm (uint32_t opcode) +{ +return (extract32 (opcode,20 ,5 ) <<17 ) | + (extract32 (opcode,0 ,17 )); +} + +int avr_translate_ADIW (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); +static inline uint32_t ADIW_Rd (uint32_t opcode) +{ +return extract32 (opcode,4 ,2 ); +} +static inline uint32_t ADIW_Imm (uint32_t opcode) +{ +return (extract32 (opcode,6 ,2 ) <<4 ) | + (extract32 (opcode,0 ,4 )); +} + +int avr_translate_SBIW (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); +static inline uint32_t SBIW_Rd (uint32_t opcode) +{ +return extract32 (opcode,4 ,2 ); +} +static inline uint32_t SBIW_Imm (uint32_t opcode) +{ +return (extract32 (opcode,6 ,2 ) <<4 ) | + (extract32 (opcode,0 ,4 )); +} + +int avr_translate_CBI (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); +static inline uint32_t CBI_Bit (uint32_t opcode) +{ +return extract32 (opcode,0 ,3 ); +} +static inline uint32_t CBI_Imm (uint32_t opcode) +{ +return extract32 (opcode,3 ,5 ); +} + +int avr_translate_SBIC (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); +static inline uint32_t SBIC_Bit (uint32_t opcode) +{ +return extract32 (opcode,0 ,3 ); +} +static inline uint32_t SBIC_Imm (uint32_t opcode) +{ +return extract32 (opcode,3 ,5 ); +} + +int avr_translate_SBI (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); +static inline uint32_t SBI_Bit (uint32_t opcode) +{ +return extract32 (opcode,0 ,3 ); +} +static inline uint32_t SBI_Imm (uint32_t opcode) +{ +return extract32 (opcode,3 ,5 ); +} + +int avr_translate_SBIS (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); +static inline uint32_t SBIS_Bit (uint32_t opcode) +{ +return extract32 (opcode,0 ,3 ); +} +static inline uint32_t SBIS_Imm (uint32_t opcode) +{ +return extract32 (opcode,3 ,5 ); +} + +int avr_translate_MUL (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); +static inline uint32_t MUL_Rd (uint32_t opcode) +{ +return extract32 (opcode,4 ,5 ); +} +static inline uint32_t MUL_Rr (uint32_t opcode) +{ +return (extract32 (opcode,9 ,1 ) <<4 ) | + (extract32 (opcode,0 ,4 )); +} + +int avr_translate_IN (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); +static inline uint32_t IN_Rd (uint32_t opcode) +{ +return extract32 (opcode,4 ,5 ); +} +static inline uint32_t IN_Imm (uint32_t opcode) +{ +return (extract32 (opcode,9 ,2 ) <<4 ) | + (extract32 (opcode,0 ,4 )); +} + +int avr_translate_OUT (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); +static inline uint32_t OUT_Rd (uint32_t opcode) +{ +return extract32 (opcode,4 ,5 ); +} +static inline uint32_t OUT_Imm (uint32_t opcode) +{ +return (extract32 (opcode,9 ,2 ) <<4 ) | + (extract32 (opcode,0 ,4 )); +} + +int avr_translate_RJMP (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); +static inline uint32_t RJMP_Imm (uint32_t opcode) +{ +return extract32 (opcode,0 ,12 ); +} + +int avr_translate_LDI (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); +static inline uint32_t LDI_Rd (uint32_t opcode) +{ +return extract32 (opcode,4 ,4 ); +} +static inline uint32_t LDI_Imm (uint32_t opcode) +{ +return (extract32 (opcode,8 ,4 ) <<4 ) | + (extract32 (opcode,0 ,4 )); +} + +int avr_translate_RCALL (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); +static inline uint32_t RCALL_Imm (uint32_t opcode) +{ +return extract32 (opcode,0 ,12 ); +} + +int avr_translate_BRBS (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); +static inline uint32_t BRBS_Bit (uint32_t opcode) +{ +return extract32 (opcode,0 ,3 ); +} +static inline uint32_t BRBS_Imm (uint32_t opcode) +{ +return extract32 (opcode,3 ,7 ); +} + +int avr_translate_BRBC (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); +static inline uint32_t BRBC_Bit (uint32_t opcode) +{ +return extract32 (opcode,0 ,3 ); +} +static inline uint32_t BRBC_Imm (uint32_t opcode) +{ +return extract32 (opcode,3 ,7 ); +} + +int avr_translate_BLD (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); +static inline uint32_t BLD_Bit (uint32_t opcode) +{ +return extract32 (opcode,0 ,3 ); +} +static inline uint32_t BLD_Rd (uint32_t opcode) +{ +return extract32 (opcode,4 ,5 ); +} + +int avr_translate_BST (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); +static inline uint32_t BST_Bit (uint32_t opcode) +{ +return extract32 (opcode,0 ,3 ); +} +static inline uint32_t BST_Rd (uint32_t opcode) +{ +return extract32 (opcode,4 ,5 ); +} + +int avr_translate_SBRC (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); +static inline uint32_t SBRC_Bit (uint32_t opcode) +{ +return extract32 (opcode,0 ,3 ); +} +static inline uint32_t SBRC_Rr (uint32_t opcode) +{ +return extract32 (opcode,4 ,5 ); +} + +int avr_translate_SBRS (CPUAVRState *env,DisasContext * ctx,uint32_t opcode); +static inline uint32_t SBRS_Bit (uint32_t opcode) +{ +return extract32 (opcode,0 ,3 ); +} +static inline uint32_t SBRS_Rr (uint32_t opcode) +{ +return extract32 (opcode,4 ,5 ); +} + + +#endif
Signature · 1 line
2.4.9 (Apple Git-60)
PATCH v10 5/10 target-avr: adding AVR interrupt handling
In reply to Michael Rolnik--- target-avr/helper.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-)
target-avr/helper.c +58 -1
@@ -31,11 +31,68 @@bool avr_cpu_exec_interrupt (CPUState *cs,int interrupt_request) { -return false; +CPUClass *cc =CPU_GET_CLASS (cs); +AVRCPU *cpu =AVR_CPU (cs); +CPUAVRState *env = &cpu->env; + +bool ret = false; + +if (interrupt_request &CPU_INTERRUPT_RESET ) { +if (cpu_interrupts_enabled (env)) { + cs->exception_index =EXCP_RESET ; + cc->do_interrupt (cs); + + cs->interrupt_request &= ~CPU_INTERRUPT_RESET ; + + ret = true; + } + } +if (interrupt_request &CPU_INTERRUPT_HARD ) { +if (cpu_interrupts_enabled (env) && env->intsrc !=0 ) { +int index =ctz32 (env->intsrc); + cs->exception_index =EXCP_INT (index); + cc->do_interrupt (cs); + + env->intsrc &= env->intsrc -1 ;/* clear the interrupt */ + cs->interrupt_request &= ~CPU_INTERRUPT_HARD ; + + ret = true; + } + } +return ret; }void avr_cpu_do_interrupt (CPUState *cs) { +AVRCPU *cpu =AVR_CPU (cs); +CPUAVRState *env = &cpu->env; + +uint32_t ret = env->pc_w; +int vector =0 ; +int size =avr_feature (env,AVR_FEATURE_JMP_CALL ) ?2 :1 ; +int base =0 ;/* TODO: where to get it */ + +if (cs->exception_index ==EXCP_RESET ) { + vector =0 ; + }else if (env->intsrc !=0 ) { + vector =ctz32 (env->intsrc) +1 ; + } + +if (avr_feature (env,AVR_FEATURE_3_BYTE_PC )) { +stb_phys (cs->as, env->sp--, (ret &0x0000ff )); +stb_phys (cs->as, env->sp--, (ret &0x00ff00 ) >>8 ); +stb_phys (cs->as, env->sp--, (ret &0xff0000 ) >>16 ); + }else if (avr_feature (env,AVR_FEATURE_2_BYTE_PC )) { +stb_phys (cs->as, env->sp--, (ret &0x0000ff )); +stb_phys (cs->as, env->sp--, (ret &0x00ff00 ) >>8 ); + }else { +stb_phys (cs->as, env->sp--, (ret &0x0000ff )); + } + + env->pc_w = base + vector * size; + env->sregI =0 ;/* clear Global Interrupt Flag */ + + cs->exception_index =-1 ; } int avr_cpu_memory_rw_debug(CPUState *cs, vaddr addr, uint8_t *buf,
Signature · 1 line
2.4.9 (Apple Git-60)
PATCH v10 6/10 target-avr: adding helpers for IN, OUT, SLEEP, WBR & unsupported instructions
In reply to Michael Rolnik--- target-avr/helper.c | 222 +++++++++++++++++++++++++++++++++++++++++++++++++--- target-avr/helper.h | 6 ++ 2 files changed, 215 insertions(+), 13 deletions(-)
target-avr/helper.c +209 -13
@@ -42,14 +42,14 @@ bool avr_cpu_exec_interrupt(CPUState *cs, int interrupt_request) cs->exception_index =EXCP_RESET ; cc->do_interrupt (cs); - cs->interrupt_request &= ~CPU_INTERRUPT_RESET ; + cs->interrupt_request &= ~CPU_INTERRUPT_RESET ; ret = true; } }if (interrupt_request &CPU_INTERRUPT_HARD ) {if (cpu_interrupts_enabled (env) && env->intsrc !=0 ) { -int index =ctz32 (env->intsrc); +int index =ctz32 (env->intsrc); cs->exception_index =EXCP_INT (index); cc->do_interrupt (cs);
@@ -64,8 +64,8 @@ bool avr_cpu_exec_interrupt(CPUState *cs, int interrupt_request)void avr_cpu_do_interrupt (CPUState *cs) { -AVRCPU *cpu =AVR_CPU (cs); -CPUAVRState *env = &cpu->env; +AVRCPU *cpu =AVR_CPU (cs); +CPUAVRState *env = &cpu->env;uint32_t ret = env->pc_w;int vector =0 ;
@@ -79,14 +79,14 @@ void avr_cpu_do_interrupt(CPUState *cs) }if (avr_feature (env,AVR_FEATURE_3_BYTE_PC )) { -stb_phys (cs->as, env->sp--, (ret &0x0000ff )); -stb_phys (cs->as, env->sp--, (ret &0x00ff00 ) >>8 ); -stb_phys (cs->as, env->sp--, (ret &0xff0000 ) >>16 ); +cpu_stb_data (env, env->sp--, (ret &0x0000ff )); +cpu_stb_data (env, env->sp--, (ret &0x00ff00 ) >>8 ); +cpu_stb_data (env, env->sp--, (ret &0xff0000 ) >>16 ); }else if (avr_feature (env,AVR_FEATURE_2_BYTE_PC )) { -stb_phys (cs->as, env->sp--, (ret &0x0000ff )); -stb_phys (cs->as, env->sp--, (ret &0x00ff00 ) >>8 ); +cpu_stb_data (env, env->sp--, (ret &0x0000ff )); +cpu_stb_data (env, env->sp--, (ret &0x00ff00 ) >>8 ); }else { -stb_phys (cs->as, env->sp--, (ret &0x0000ff )); +cpu_stb_data (env, env->sp--, (ret &0x0000ff )); } env->pc_w = base + vector * size;
@@ -124,15 +124,55 @@ void tlb_fill(CPUState *cs, target_ulong vaddr, int is_write, vaddr &=TARGET_PAGE_MASK ;if (mmu_idx ==MMU_CODE_IDX ) { - paddr =PHYS_BASE_CODE + vaddr; + paddr =PHYS_BASE_CODE + vaddr -VIRT_BASE_CODE ; prot =PAGE_READ |PAGE_EXEC ; }else { - paddr =PHYS_BASE_DATA + vaddr; - prot =PAGE_READ |PAGE_WRITE ; +#if VIRT_BASE_REGS ==0 +if (vaddr <VIRT_BASE_REGS +SIZE_REGS ) { +#else +if (VIRT_BASE_REGS <= vaddr && vaddr <VIRT_BASE_REGS +SIZE_REGS ) { +#endif +/* +this is a write into CPU registers, exit and rebuilt this TB +to use full write +*/ +AVRCPU *cpu =AVR_CPU (cs); +CPUAVRState *env = &cpu->env; + env->fullwr =1 ; +cpu_loop_exit_restore (cs, retaddr); + }else { +/* +this is a write into memory. nothing special +*/ + paddr =PHYS_BASE_DATA + vaddr -VIRT_BASE_DATA ; + prot =PAGE_READ |PAGE_WRITE ; + } } tlb_set_page_with_attrs(cs, vaddr, paddr, attrs, prot, mmu_idx, page_size); } +void helper_sleep (CPUAVRState *env) +{ +CPUState *cs =CPU (avr_env_get_cpu (env)); + + cs->exception_index =EXCP_HLT ; +cpu_loop_exit (cs); +} +void helper_unsupported (CPUAVRState *env) +{ +CPUState *cs =CPU (avr_env_get_cpu (env)); + +/* +I count not find what happens on the real platform, so +it's EXCP_DEBUG for meanwhile +*/ + cs->exception_index =EXCP_DEBUG ; +if (qemu_loglevel_mask (LOG_UNIMP )) { +qemu_log ("UNSUPPORTED\n" ); +cpu_dump_state (cs, qemu_logfile, fprintf,0 ); + } +cpu_loop_exit (cs); +}void helper_debug (CPUAVRState *env) {
@@ -142,3 +182,159 @@ void helper_debug(CPUAVRState *env)cpu_loop_exit (cs); } +void helper_wdr (CPUAVRState *env) +{ +CPUState *cs =CPU (avr_env_get_cpu (env)); + +/* +WD is not implemented yet, placeholder +*/ + cs->exception_index =EXCP_DEBUG ; +cpu_loop_exit (cs); +} + +target_ulong helper_inb (CPUAVRState *env,uint32_t port) +{ +target_ulong data =0 ; + +switch (port) { +case 0x38 : { + data =0xff & (env->rampD >>16 );/* RAMPD */ +break ; + } +case 0x39 : { + data =0xff & (env->rampX >>16 );/* RAMPX */ +break ; + } +case 0x3a : { + data =0xff & (env->rampY >>16 );/* RAMPY */ +break ; + } +case 0x3b : { + data =0xff & (env->rampZ >>16 );/* RAMPZ */ +break ; + } +case 0x3c : { + data =0xff & (env->eind >>16 );/* EIND */ +break ; + } +case 0x3d : {/* SPL */ + data = env->sp &0x00ff ; +break ; + } +case 0x3e : {/* SPH */ + data = env->sp >>8 ; +break ; + } +case 0x3f : {/* SREG */ + data =cpu_get_sreg (env); +break ; + } +default : { +/* +CPU does not know how to read this register, pass it to the +device/board +*/ + +cpu_physical_memory_read (PHYS_BASE_REGS + port +OFFS_IOREGS , + &data,1 ); + } + } + +if (port <IO_REGS ) { + env->io[port] = data;/* make a copy for SBI, SBIC, SBIS & CBI */ + } + +return data; +} + +void helper_fullwr (CPUAVRState *env,uint32_t data,uint32_t addr) +{ +#if VIRT_BASE_REGS ==0 +if (addr <=VIRT_BASE_REGS +SIZE_REGS ) { +#else +if (VIRT_BASE_REGS <= addr && addr <=VIRT_BASE_REGS +SIZE_REGS ) { +#endif +/* +write CPU REGS/IO REGS/EXT IO REGS +*/ +cpu_physical_memory_write (PHYS_BASE_REGS + addr -VIRT_BASE_REGS , + &data,1 ); + }else { +/* +write memory +*/ +cpu_physical_memory_write (PHYS_BASE_DATA + addr -VIRT_BASE_DATA , + &data,1 ); + } +} + +void helper_outb (CPUAVRState *env,uint32_t port,uint32_t data) +{ + data &=0x000000ff ; + +switch (port) { +case 0x04 : { +qemu_irq irq; +CPUState *cpu =CPU (avr_env_get_cpu (env)); + irq =qdev_get_gpio_in (DEVICE (cpu),3 ); +qemu_set_irq (irq,1 ); +break ; + } +case 0x38 : { +if (avr_feature (env,AVR_FEATURE_RAMPD )) { + env->rampD = (data &0xff ) <<16 ;/* RAMPD */ + } +break ; + } +case 0x39 : { +if (avr_feature (env,AVR_FEATURE_RAMPX )) { + env->rampX = (data &0xff ) <<16 ;/* RAMPX */ + } +break ; + } +case 0x3a : { +if (avr_feature (env,AVR_FEATURE_RAMPY )) { + env->rampY = (data &0xff ) <<16 ;/* RAMPY */ + } +break ; + } +case 0x3b : { +if (avr_feature (env,AVR_FEATURE_RAMPZ )) { + env->rampZ = (data &0xff ) <<16 ;/* RAMPZ */ + } +break ; + } +case 0x3c : { + env->eind = (data &0xff ) <<16 ;/* EIDN */ +break ; + } +case 0x3d : {/* SPL */ + env->sp = (env->sp &0xff00 ) | (data); +break ; + } +case 0x3e : {/* SPH */ +if (avr_feature (env,AVR_FEATURE_2_BYTE_SP )) { + env->sp = (env->sp &0x00ff ) | (data <<8 ); + } +break ; + } +case 0x3f : {/* SREG */ +cpu_set_sreg (env, data); +break ; + } +default : { +/* +CPU does not know how to write this register, pass it to the +device/board +*/ +cpu_physical_memory_write (PHYS_BASE_REGS + port +OFFS_IOREGS , + &data,1 ); + } + } + +if (port <IO_REGS ) { + env->io[port] = data;/* make a copy for SBI, SBIC, SBIS & CBI */ + } +} +
target-avr/helper.h +6 -0
@@ -18,4 +18,10 @@* <http://www.gnu.org/licenses/lgpl-2.1.html> */ +DEF_HELPER_1(wdr, void, env) DEF_HELPER_1(debug, void, env) +DEF_HELPER_1(sleep, void, env) +DEF_HELPER_1(unsupported, void, env) +DEF_HELPER_3(outb, void, env, i32, i32) +DEF_HELPER_2(inb, tl, env, i32) +DEF_HELPER_3 (fullwr, void, env, i32, i32)
Signature · 1 line
2.4.9 (Apple Git-60)
PATCH v10 7/10 target-avr: adding instruction decoder
In reply to Michael Rolnik--- target-avr/decode.c | 693 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 693 insertions(+) create mode 100644 target-avr/decode.c
target-avr/decode.c new file +693 -0
@@ -0,0 +1,693 @@ +/* +* QEMU AVR CPU +* +* Copyright (c) 2016 Michael Rolnik +* +* 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.1 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/lgpl-2.1.html> +*/ + + +#include <stdint.h> +#include "translate.h" + +void avr_decode (uint32_t pc,uint32_t *l,uint32_t c,translate_function_t *t) +{ +uint32_t opc =extract32 (c,0 ,16 ); +switch (opc &0x0000d000 ) { +case 0x00000000 : { +switch (opc &0x00002c00 ) { +case 0x00000000 : { +switch (opc &0x00000300 ) { +case 0x00000000 : { + *l =16 ; + *t = &avr_translate_NOP; +break ; + } +case 0x00000100 : { + *l =16 ; + *t = &avr_translate_MOVW; +break ; + } +case 0x00000200 : { + *l =16 ; + *t = &avr_translate_MULS; +break ; + } +case 0x00000300 : { +switch (opc &0x00000088 ) { +case 0x00000000 : { + *l =16 ; + *t = &avr_translate_MULSU; +break ; + } +case 0x00000008 : { + *l =16 ; + *t = &avr_translate_FMUL; +break ; + } +case 0x00000080 : { + *l =16 ; + *t = &avr_translate_FMULS; +break ; + } +case 0x00000088 : { + *l =16 ; + *t = &avr_translate_FMULSU; +break ; + } + } +break ; + } + } +break ; + } +case 0x00000400 : { + *l =16 ; + *t = &avr_translate_CPC; +break ; + } +case 0x00000800 : { + *l =16 ; + *t = &avr_translate_SBC; +break ; + } +case 0x00000c00 : { + *l =16 ; + *t = &avr_translate_ADD; +break ; + } +case 0x00002000 : { + *l =16 ; + *t = &avr_translate_AND; +break ; + } +case 0x00002400 : { + *l =16 ; + *t = &avr_translate_EOR; +break ; + } +case 0x00002800 : { + *l =16 ; + *t = &avr_translate_OR; +break ; + } +case 0x00002c00 : { + *l =16 ; + *t = &avr_translate_MOV; +break ; + } + } +break ; + } +case 0x00001000 : { +switch (opc &0x00002000 ) { +case 0x00000000 : { +switch (opc &0x00000c00 ) { +case 0x00000000 : { + *l =16 ; + *t = &avr_translate_CPSE; +break ; + } +case 0x00000400 : { + *l =16 ; + *t = &avr_translate_CP; +break ; + } +case 0x00000800 : { + *l =16 ; + *t = &avr_translate_SUB; +break ; + } +case 0x00000c00 : { + *l =16 ; + *t = &avr_translate_ADC; +break ; + } + } +break ; + } +case 0x00002000 : { + *l =16 ; + *t = &avr_translate_CPI; +break ; + } + } +break ; + } +case 0x00004000 : { +switch (opc &0x00002000 ) { +case 0x00000000 : { + *l =16 ; + *t = &avr_translate_SBCI; +break ; + } +case 0x00002000 : { + *l =16 ; + *t = &avr_translate_ORI; +break ; + } + } +break ; + } +case 0x00005000 : { +switch (opc &0x00002000 ) { +case 0x00000000 : { + *l =16 ; + *t = &avr_translate_SUBI; +break ; + } +case 0x00002000 : { + *l =16 ; + *t = &avr_translate_ANDI; +break ; + } + } +break ; + } +case 0x00008000 : { +switch (opc &0x00000208 ) { +case 0x00000000 : { + *l =16 ; + *t = &avr_translate_LDDZ; +break ; + } +case 0x00000008 : { + *l =16 ; + *t = &avr_translate_LDDY; +break ; + } +case 0x00000200 : { + *l =16 ; + *t = &avr_translate_STDZ; +break ; + } +case 0x00000208 : { + *l =16 ; + *t = &avr_translate_STDY; +break ; + } + } +break ; + } +case 0x00009000 : { +switch (opc &0x00002800 ) { +case 0x00000000 : { +switch (opc &0x00000600 ) { +case 0x00000000 : { +switch (opc &0x0000000f ) { +case 0x00000000 : { + *l =32 ; + *t = &avr_translate_LDS; +break ; + } +case 0x00000001 : { + *l =16 ; + *t = &avr_translate_LDZ2; +break ; + } +case 0x00000002 : { + *l =16 ; + *t = &avr_translate_LDZ3; +break ; + } +case 0x00000003 : { +break ; + } +case 0x00000004 : { + *l =16 ; + *t = &avr_translate_LPM2; +break ; + } +case 0x00000005 : { + *l =16 ; + *t = &avr_translate_LPMX; +break ; + } +case 0x00000006 : { + *l =16 ; + *t = &avr_translate_ELPM2; +break ; + } +case 0x00000007 : { + *l =16 ; + *t = &avr_translate_ELPMX; +break ; + } +case 0x00000008 : { +break ; + } +case 0x00000009 : { + *l =16 ; + *t = &avr_translate_LDY2; +break ; + } +case 0x0000000a : { + *l =16 ; + *t = &avr_translate_LDY3; +break ; + } +case 0x0000000b : { +break ; + } +case 0x0000000c : { + *l =16 ; + *t = &avr_translate_LDX1; +break ; + } +case 0x0000000d : { + *l =16 ; + *t = &avr_translate_LDX2; +break ; + } +case 0x0000000e : { + *l =16 ; + *t = &avr_translate_LDX3; +break ; + } +case 0x0000000f : { + *l =16 ; + *t = &avr_translate_POP; +break ; + } + } +break ; + } +case 0x00000200 : { +switch (opc &0x0000000f ) { +case 0x00000000 : { + *l =32 ; + *t = &avr_translate_STS; +break ; + } +case 0x00000001 : { + *l =16 ; + *t = &avr_translate_STZ2; +break ; + } +case 0x00000002 : { + *l =16 ; + *t = &avr_translate_STZ3; +break ; + } +case 0x00000003 : { +break ; + } +case 0x00000004 : { + *l =16 ; + *t = &avr_translate_XCH; +break ; + } +case 0x00000005 : { + *l =16 ; + *t = &avr_translate_LAS; +break ; + } +case 0x00000006 : { + *l =16 ; + *t = &avr_translate_LAC; +break ; + } +case 0x00000007 : { + *l =16 ; + *t = &avr_translate_LAT; +break ; + } +case 0x00000008 : { +break ; + } +case 0x00000009 : { + *l =16 ; + *t = &avr_translate_STY2; +break ; + } +case 0x0000000a : { + *l =16 ; + *t = &avr_translate_STY3; +break ; + } +case 0x0000000b : { +break ; + } +case 0x0000000c : { + *l =16 ; + *t = &avr_translate_STX1; +break ; + } +case 0x0000000d : { + *l =16 ; + *t = &avr_translate_STX2; +break ; + } +case 0x0000000e : { + *l =16 ; + *t = &avr_translate_STX3; +break ; + } +case 0x0000000f : { + *l =16 ; + *t = &avr_translate_PUSH; +break ; + } + } +break ; + } +case 0x00000400 : { +switch (opc &0x0000000e ) { +case 0x00000000 : { +switch (opc &0x00000001 ) { +case 0x00000000 : { + *l =16 ; + *t = &avr_translate_COM; +break ; + } +case 0x00000001 : { + *l =16 ; + *t = &avr_translate_NEG; +break ; + } + } +break ; + } +case 0x00000002 : { +switch (opc &0x00000001 ) { +case 0x00000000 : { + *l =16 ; + *t = &avr_translate_SWAP; +break ; + } +case 0x00000001 : { + *l =16 ; + *t = &avr_translate_INC; +break ; + } + } +break ; + } +case 0x00000004 : { + *l =16 ; + *t = &avr_translate_ASR; +break ; + } +case 0x00000006 : { +switch (opc &0x00000001 ) { +case 0x00000000 : { + *l =16 ; + *t = &avr_translate_LSR; +break ; + } +case 0x00000001 : { + *l =16 ; + *t = &avr_translate_ROR; +break ; + } + } +break ; + } +case 0x00000008 : { +switch (opc &0x00000181 ) { +case 0x00000000 : { + *l =16 ; + *t = &avr_translate_BSET; +break ; + } +case 0x00000001 : { +switch (opc &0x00000010 ) { +case 0x00000000 : { + *l =16 ; + *t = &avr_translate_IJMP; +break ; + } +case 0x00000010 : { + *l =16 ; + *t = &avr_translate_EIJMP; +break ; + } + } +break ; + } +case 0x00000080 : { + *l =16 ; + *t = &avr_translate_BCLR; +break ; + } +case 0x00000081 : { +break ; + } +case 0x00000100 : { +switch (opc &0x00000010 ) { +case 0x00000000 : { + *l =16 ; + *t = &avr_translate_RET; +break ; + } +case 0x00000010 : { + *l =16 ; + *t = &avr_translate_RETI; +break ; + } + } +break ; + } +case 0x00000101 : { +switch (opc &0x00000010 ) { +case 0x00000000 : { + *l =16 ; + *t = &avr_translate_ICALL; +break ; + } +case 0x00000010 : { + *l =16 ; + *t = &avr_translate_EICALL; +break ; + } + } +break ; + } +case 0x00000180 : { +switch (opc &0x00000070 ) { +case 0x00000000 : { + *l =16 ; + *t = &avr_translate_SLEEP; +break ; + } +case 0x00000010 : { + *l =16 ; + *t = &avr_translate_BREAK; +break ; + } +case 0x00000020 : { + *l =16 ; + *t = &avr_translate_WDR; +break ; + } +case 0x00000030 : { +break ; + } +case 0x00000040 : { + *l =16 ; + *t = &avr_translate_LPM1; +break ; + } +case 0x00000050 : { + *l =16 ; + *t = &avr_translate_ELPM1; +break ; + } +case 0x00000060 : { + *l =16 ; + *t = &avr_translate_SPM; +break ; + } +case 0x00000070 : { + *l =16 ; + *t = &avr_translate_SPMX; +break ; + } + } +break ; + } +case 0x00000181 : { +break ; + } + } +break ; + } +case 0x0000000a : { +switch (opc &0x00000001 ) { +case 0x00000000 : { + *l =16 ; + *t = &avr_translate_DEC; +break ; + } +case 0x00000001 : { + *l =16 ; + *t = &avr_translate_DES; +break ; + } + } +break ; + } +case 0x0000000c : { + *l =32 ; + *t = &avr_translate_JMP; +break ; + } +case 0x0000000e : { + *l =32 ; + *t = &avr_translate_CALL; +break ; + } + } +break ; + } +case 0x00000600 : { +switch (opc &0x00000100 ) { +case 0x00000000 : { + *l =16 ; + *t = &avr_translate_ADIW; +break ; + } +case 0x00000100 : { + *l =16 ; + *t = &avr_translate_SBIW; +break ; + } + } +break ; + } + } +break ; + } +case 0x00000800 : { +switch (opc &0x00000400 ) { +case 0x00000000 : { +switch (opc &0x00000300 ) { +case 0x00000000 : { + *l =16 ; + *t = &avr_translate_CBI; +break ; + } +case 0x00000100 : { + *l =16 ; + *t = &avr_translate_SBIC; +break ; + } +case 0x00000200 : { + *l =16 ; + *t = &avr_translate_SBI; +break ; + } +case 0x00000300 : { + *l =16 ; + *t = &avr_translate_SBIS; +break ; + } + } +break ; + } +case 0x00000400 : { + *l =16 ; + *t = &avr_translate_MUL; +break ; + } + } +break ; + } +case 0x00002000 : { + *l =16 ; + *t = &avr_translate_IN; +break ; + } +case 0x00002800 : { + *l =16 ; + *t = &avr_translate_OUT; +break ; + } + } +break ; + } +case 0x0000c000 : { +switch (opc &0x00002000 ) { +case 0x00000000 : { + *l =16 ; + *t = &avr_translate_RJMP; +break ; + } +case 0x00002000 : { + *l =16 ; + *t = &avr_translate_LDI; +break ; + } + } +break ; + } +case 0x0000d000 : { +switch (opc &0x00002000 ) { +case 0x00000000 : { + *l =16 ; + *t = &avr_translate_RCALL; +break ; + } +case 0x00002000 : { +switch (opc &0x00000c00 ) { +case 0x00000000 : { + *l =16 ; + *t = &avr_translate_BRBS; +break ; + } +case 0x00000400 : { + *l =16 ; + *t = &avr_translate_BRBC; +break ; + } +case 0x00000800 : { +switch (opc &0x00000200 ) { +case 0x00000000 : { + *l =16 ; + *t = &avr_translate_BLD; +break ; + } +case 0x00000200 : { + *l =16 ; + *t = &avr_translate_BST; +break ; + } + } +break ; + } +case 0x00000c00 : { +switch (opc &0x00000200 ) { +case 0x00000000 : { + *l =16 ; + *t = &avr_translate_SBRC; +break ; + } +case 0x00000200 : { + *l =16 ; + *t = &avr_translate_SBRS; +break ; + } + } +break ; + } + } +break ; + } + } +break ; + } + } + +}
Signature · 1 line
2.4.9 (Apple Git-60)
PATCH v10 9/10 target-avr: updating translate.c to use instructions translation
In reply to Michael Rolnik--- target-avr/Makefile.objs | 4 +- target-avr/translate.c | 142 ++++++++++++++++++++--------------------------- 2 files changed, 64 insertions(+), 82 deletions(-)
target-avr/Makefile.objs +3 -1
@@ -18,6 +18,8 @@ # <http://www.gnu.org/licenses/lgpl-2.1.html> # -obj-y += translate.o cpu.o helper.o +obj-y += translate.o helper.o cpu.o translate-inst.o obj-y += gdbstub.o obj-$(CONFIG_SOFTMMU) += machine.o + +obj-y += decode.o
target-avr/translate.c +61 -81
206 lines not on this page · raw message
Signature · 1 line
2.4.9 (Apple Git-60)
PATCH v10 10/10 target-avr: instruction decoder generator
In reply to Michael Rolnik--- target-avr/cpugen/CMakeLists.txt | 38 +++ target-avr/cpugen/README.md | 17 ++ target-avr/cpugen/cpu/avr.yaml | 214 ++++++++++++++ target-avr/cpugen/src/CMakeLists.txt | 62 ++++ target-avr/cpugen/src/cpugen.cpp | 460 +++++++++++++++++++++++++++++ target-avr/cpugen/src/utils.cpp | 27 ++ target-avr/cpugen/src/utils.h | 79 +++++ target-avr/cpugen/xsl/decode.c.xsl | 103 +++++++ target-avr/cpugen/xsl/translate-inst.h.xsl | 118 ++++++++ target-avr/cpugen/xsl/utils.xsl | 108 +++++++ 10 files changed, 1226 insertions(+) create mode 100644 target-avr/cpugen/CMakeLists.txt create mode 100644 target-avr/cpugen/README.md create mode 100644 target-avr/cpugen/cpu/avr.yaml create mode 100644 target-avr/cpugen/src/CMakeLists.txt create mode 100644 target-avr/cpugen/src/cpugen.cpp create mode 100644 target-avr/cpugen/src/utils.cpp create mode 100644 target-avr/cpugen/src/utils.h create mode 100644 target-avr/cpugen/xsl/decode.c.xsl create mode 100644 target-avr/cpugen/xsl/translate-inst.h.xsl create mode 100644 target-avr/cpugen/xsl/utils.xsl
target-avr/cpugen/CMakeLists.txt new file +38 -0
@@ -0,0 +1,38 @@ +cmake_minimum_required(VERSION 2.8) + +project(cpugen) + +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -ggdb -g3") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x") + +set(Boost_USE_STATIC_LIBS ON) +find_package( + Boost 1.60.0 + REQUIRED + COMPONENTS + system + regex) +#set(BUILD_SHARED_LIBS OFF) +#set(BUILD_STATIC_LIBS ON) +add_subdirectory(tinyxml2) +add_subdirectory(yaml-cpp) + +include_directories( + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/.. + ${CMAKE_CURRENT_SOURCE_DIR}/../yaml-cpp/include + ${Boost_INCLUDE_DIRS} +) + +add_executable( + cpugen + src/cpugen.cpp + src/utils.cpp +) + +target_link_libraries( + cpugen + yaml-cpp + tinyxml2 + ${Boost_LIBRARIES} +)
target-avr/cpugen/README.md new file +17 -0
@@ -0,0 +1,17 @@ +# CPUGEN +## How to build +within ```cpugen``` directory do +``` +git clone https://github.com/leethomason/tinyxml2 +git clone https://github.com/jbeder/yaml-cpp +mkdir build +cd build +cmake .. +make +``` +## How to use +``` +cpugen ../cpu/avr.yaml +xsltproc ../xsl/decode.c.xsl output.xml > ../../decode.c +xsltproc ../xsl/translate-inst.h.xsl output.xml > ../../translate-inst.h +```
target-avr/cpugen/cpu/avr.yaml new file +214 -0
214 lines not on this page · raw message
target-avr/cpugen/src/CMakeLists.txt new file +62 -0
62 lines not on this page · raw message
target-avr/cpugen/src/cpugen.cpp new file +460 -0
460 lines not on this page · raw message
target-avr/cpugen/src/utils.cpp new file +27 -0
@@ -0,0 +1,27 @@ +/* + * CPUGEN + * + * Copyright (c) 2016 Michael Rolnik + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "utils.h" +#include <sstream> +
target-avr/cpugen/src/utils.h new file +79 -0
79 lines not on this page · raw message
target-avr/cpugen/xsl/decode.c.xsl new file +103 -0
103 lines not on this page · raw message
target-avr/cpugen/xsl/translate-inst.h.xsl new file +118 -0
118 lines not on this page · raw message
target-avr/cpugen/xsl/utils.xsl new file +108 -0
108 lines not on this page · raw message
Signature · 1 line
2.4.9 (Apple Git-60)
PATCH v10 8/10 target-avr: adding instruction translation
In reply to Michael Rolnik--- target-avr/helper.c | 118 +- target-avr/helper.h | 1 + target-avr/translate-inst.c | 2621 +++++++++++++++++++++++++++++++++++++++++++ target-avr/translate.c | 2 +- target-avr/translate.h | 119 ++ 5 files changed, 2830 insertions(+), 31 deletions(-) create mode 100644 target-avr/translate-inst.c create mode 100644 target-avr/translate.h
target-avr/helper.c +88 -30
@@ -28,6 +28,7 @@#include "exec/cpu_ldst.h" #include "qemu/host-utils.h" #include "exec/helper-proto.h" +#include "exec/ioport.h" bool avr_cpu_exec_interrupt (CPUState *cs,int interrupt_request) {
@@ -128,7 +129,7 @@ void tlb_fill(CPUState *cs, target_ulong vaddr, int is_write, prot =PAGE_READ |PAGE_EXEC ; }else {#if VIRT_BASE_REGS ==0 -if (vaddr <VIRT_BASE_REGS +SIZE_REGS ) { +if (vaddr <VIRT_BASE_REGS +AVR_REGS ) {#else if (VIRT_BASE_REGS <= vaddr && vaddr <VIRT_BASE_REGS +SIZE_REGS ) {#endif
@@ -138,7 +139,7 @@ void tlb_fill(CPUState *cs, target_ulong vaddr, int is_write,*/ AVRCPU *cpu =AVR_CPU (cs);CPUAVRState *env = &cpu->env; - env->fullwr =1 ; + env->fullacc =1 ;cpu_loop_exit_restore (cs, retaddr); }else {/*
@@ -193,6 +194,16 @@ void helper_wdr(CPUAVRState *env)cpu_loop_exit (cs); } +/* +This function implements IN instruction + +It does the following +a. if an IO register belongs to CPU, its value is read and returned +b. otherwise io address is translated to mem address and physical memory +is read. +c. it caches the value for sake of SBI, SBIC, SBIS & CBI implementation + +*/ target_ulong helper_inb (CPUAVRState *env,uint32_t port) {target_ulong data =0 ;
@@ -236,39 +247,29 @@ target_ulong helper_inb(CPUAVRState *env, uint32_t port)device/board */ -cpu_physical_memory_read (PHYS_BASE_REGS + port +OFFS_IOREGS , - &data,1 ); +cpu_physical_memory_read (PHYS_BASE_REGS + port + +AVR_CPU_IO_REGS_BASE , &data,1 ); } } -if (port <IO_REGS ) { - env->io[port] = data;/* make a copy for SBI, SBIC, SBIS & CBI */ +/* make a copy */ +if (port <AVR_CPU_IO_REGS ) { + env->io[port] = data; }return data; } -void helper_fullwr (CPUAVRState *env,uint32_t data,uint32_t addr) -{ -#if VIRT_BASE_REGS ==0 -if (addr <=VIRT_BASE_REGS +SIZE_REGS ) { -#else -if (VIRT_BASE_REGS <= addr && addr <=VIRT_BASE_REGS +SIZE_REGS ) { -#endif -/* -write CPU REGS/IO REGS/EXT IO REGS -*/ -cpu_physical_memory_write (PHYS_BASE_REGS + addr -VIRT_BASE_REGS , - &data,1 ); - }else { -/* -write memory -*/ -cpu_physical_memory_write (PHYS_BASE_DATA + addr -VIRT_BASE_DATA , - &data,1 ); - } -} +/* +This function implements OUT instruction + +It does the following +a. if an IO register belongs to CPU, its value is written into the register +b. otherwise io address is translated to mem address and physical memory +is written. +c. it caches the value for sake of SBI, SBIC, SBIS & CBI implementation +*/ void helper_outb (CPUAVRState *env,uint32_t port,uint32_t data) { data &=0x000000ff ;
@@ -328,13 +329,70 @@ void helper_outb(CPUAVRState *env, uint32_t port, uint32_t data)CPU does not know how to write this register, pass it to the device/board */ -cpu_physical_memory_write (PHYS_BASE_REGS + port +OFFS_IOREGS , - &data,1 ); +cpu_physical_memory_write (PHYS_BASE_REGS + port + +AVR_CPU_IO_REGS_BASE , &data,1 ); } } -if (port <IO_REGS ) { - env->io[port] = data;/* make a copy for SBI, SBIC, SBIS & CBI */ +/* make a copy */ +if (port <AVR_CPU_IO_REGS ) { + env->io[port] = data; + } +} + +/* +this function implements LD instruction when there is a posibility to read +from a CPU register +*/ +target_ulong helper_fullrd (CPUAVRState *env,uint32_t addr) +{ +uint8_t data; +switch (addr) { +/* CPU registers */ + case AVR_CPU_REGS_BASE ... AVR_CPU_REGS_LAST: { + data = env->r[addr -AVR_CPU_REGS_BASE ]; +break ; + } +/* CPU IO registers & EXT IO registers */ + case AVR_CPU_IO_REGS_BASE ... AVR_EXT_IO_REGS_LAST: { + data =helper_inb (env, addr); +break ; + } + +/* memory */ +default : { +cpu_physical_memory_read (PHYS_BASE_DATA + addr -VIRT_BASE_DATA , + &data,1 ); + } + } + +return data; +} + +/* +this function implements LD instruction when there is a posibility to write +into a CPU register +*/ +void helper_fullwr (CPUAVRState *env,uint32_t data,uint32_t addr) +{ +switch (addr) { +/* CPU registers */ + case AVR_CPU_REGS_BASE ... AVR_CPU_REGS_LAST: { + env->r[addr -AVR_CPU_REGS_BASE ] = data; +break ; + } + +/* CPU IO registers & EXT IO registers */ + case AVR_CPU_IO_REGS_BASE ... AVR_EXT_IO_REGS_LAST: { +helper_outb (env, data, addr); +break ; + } + +/* memory */ +default : { +cpu_physical_memory_write (PHYS_BASE_DATA + addr -VIRT_BASE_DATA , + &data,1 ); + } } }
target-avr/helper.h +1 -0
@@ -25,3 +25,4 @@ DEF_HELPER_1(unsupported, void, env) DEF_HELPER_3(outb, void, env, i32, i32) DEF_HELPER_2(inb, tl, env, i32) DEF_HELPER_3(fullwr, void, env, i32, i32) +DEF_HELPER_2 (fullrd, tl, env, i32)
target-avr/translate-inst.c new file +2621 -0
2,621 lines not on this page · raw message
target-avr/translate.c +1 -1
@@ -231,7 +231,7 @@ void gen_intermediate_code(CPUAVRState *env, struct TranslationBlock *tb) } done_generating: - env->fullwr = false; + env->fullacc = false;gen_tb_end (tb, num_insns); tb->size = (npc - pc_start) *2 ;
target-avr/translate.h new file +119 -0
119 lines not on this page · raw message
Signature · 1 line
2.4.9 (Apple Git-60)
Re: [Qemu-devel] [PATCH v10 01/10] target-avr: AVR cores support is added.
In reply to Michael RolnikQuoted 7 lines · Michael Rolnik
target-avr/cpu.c new file +7
-0+static bool avr_cpu_has_work (CPUState *cs) +{ +AVRCPU *cpu =AVR_CPU (cs); +CPUAVRState *env = &cpu->env; + + return (cs->interrupt_request + & (CPU_INTERRUPT_HARD
target-avr/cpu.c line 51
Quoted 10 lines
target-avr/cpu.c new file +10
-0+ | CPU_INTERRUPT_RESET)) + &&cpu_interrupts_enabled (env); +} +static void avr_cpu_synchronize_from_tb (CPUState *cs,TranslationBlock *tb) +{ +AVRCPU *cpu =AVR_CPU (cs); +CPUAVRState *env = &cpu->env; + + env->pc_w = tb->pc /2 ;/* internally PC points to words */ +}
For the 4th time: missing spaces between functions. Lots of them. Please fix them all, without me having to repeat myself a 5th time.
Quoted 1 line
+ bool fullacc;/* CPU/MEM if true MEM only otherwise */
...
target-avr/cpu.h line 145
Quoted 7 lines
target-avr/cpu.h new file +7
-0+static inline void cpu_get_tb_cpu_state (CPUAVRState *env,target_ulong *pc, +target_ulong *cs_base,uint32_t *pflags) +{ + *pc = env->pc_w *2 ; + *cs_base =0 ; + *pflags =0 ; +}
The fullacc bit needs to be reflected in *pflags here. The way you are accessing env->fullacc from translate*.c is invalid.
r~
Re: [Qemu-devel] [PATCH v10 06/10] target-avr: adding helpers for IN, OUT, SLEEP, WBR & unsupported instructions
In reply to Michael RolnikQuoted 64 lines · Michael Rolnik
Signed-off-by Michael Rolnik <[email protected]>--- target-avr/helper.c | 222 +++++++++++++++++++++++++++++++++++++++++++++++++--- target-avr/helper.h | 6 ++ 2 files changed, 215 insertions(+), 13 deletions(-)target-avr/helper.c +10
-11@@ -42,14 +42,14 @@ bool avr_cpu_exec_interrupt(CPUState *cs, int interrupt_request) cs->exception_index =EXCP_RESET ; cc->do_interrupt (cs); - cs->interrupt_request &= ~CPU_INTERRUPT_RESET ; + cs->interrupt_request &= ~CPU_INTERRUPT_RESET ; ret = true; } }if (interrupt_request &CPU_INTERRUPT_HARD ) {if (cpu_interrupts_enabled (env) && env->intsrc !=0 ) { -int index =ctz32 (env->intsrc); +int index =ctz32 (env->intsrc); cs->exception_index =EXCP_INT (index); cc->do_interrupt (cs);@@ -64,8 +64,8 @@ bool avr_cpu_exec_interrupt(CPUState *cs, int interrupt_request)void avr_cpu_do_interrupt (CPUState *cs) { -AVRCPU *cpu =AVR_CPU (cs); -CPUAVRState *env = &cpu->env; +AVRCPU *cpu =AVR_CPU (cs); +CPUAVRState *env = &cpu->env;uint32_t ret = env->pc_w;int vector =0 ;@@ -79,14 +79,14 @@ void avr_cpu_do_interrupt(CPUState *cs) }if (avr_feature (env,AVR_FEATURE_3_BYTE_PC )) { -stb_phys (cs->as, env->sp--, (ret &0x0000ff )); -stb_phys (cs->as, env->sp--, (ret &0x00ff00 ) >>8 ); -stb_phys (cs->as, env->sp--, (ret &0xff0000 ) >>16 ); +cpu_stb_data (env, env->sp--, (ret &0x0000ff )); +cpu_stb_data (env, env->sp--, (ret &0x00ff00 ) >>8 ); +cpu_stb_data (env, env->sp--, (ret &0xff0000 ) >>16 ); }else if (avr_feature (env,AVR_FEATURE_2_BYTE_PC )) { -stb_phys (cs->as, env->sp--, (ret &0x0000ff )); -stb_phys (cs->as, env->sp--, (ret &0x00ff00 ) >>8 ); +cpu_stb_data (env, env->sp--, (ret &0x0000ff )); +cpu_stb_data (env, env->sp--, (ret &0x00ff00 ) >>8 ); }else { -stb_phys (cs->as, env->sp--, (ret &0x0000ff )); +cpu_stb_data (env, env->sp--, (ret &0x0000ff )); } env->pc_w = base + vector * size;@@ -124,15 +124,55 @@ void tlb_fill(CPUState *cs, target_ulong vaddr, int is_write, vaddr &=TARGET_PAGE_MASK ;if (mmu_idx ==MMU_CODE_IDX ) { - paddr =PHYS_BASE_CODE + vaddr;
target-avr/helper.c void tlb_fill(CPUState *cs, target_ulong vaddr, int is_write, · line 134
Quoted 10 lines
target-avr/helper.c +6
-2+ paddr =PHYS_BASE_CODE + vaddr -VIRT_BASE_CODE ; prot =PAGE_READ |PAGE_EXEC ; }else { - paddr =PHYS_BASE_DATA + vaddr; - prot =PAGE_READ |PAGE_WRITE ; +#if VIRT_BASE_REGS ==0 +if (vaddr <VIRT_BASE_REGS +SIZE_REGS ) { +#else +if (VIRT_BASE_REGS <= vaddr && vaddr <VIRT_BASE_REGS +SIZE_REGS ) { +#endif
if (vaddr - VIRT_BASE_REGS < SIZE_REGS)
Quoted 6 lines
target-avr/helper.c +6
-0+/* +this is a write into CPU registers, exit and rebuilt this TB +to use full write +*/ +AVRCPU *cpu =AVR_CPU (cs); +CPUAVRState *env = &cpu->env;
target-avr/helper.c void tlb_fill(CPUState *cs, target_ulong vaddr, int is_write, · line 150
Quoted 10 lines
target-avr/helper.c +9
-0+ env->fullwr =1 ; +cpu_loop_exit_restore (cs, retaddr); + }else { +/* +this is a write into memory. nothing special +*/ + paddr =PHYS_BASE_DATA + vaddr -VIRT_BASE_DATA ; + prot =PAGE_READ |PAGE_WRITE ; + } }
Everything above here should be folded back into a previous patch.
r~
Quoted 204 lines
target-avr/helper.c +178
-0tlb_set_page_with_attrs (cs, vaddr, paddr, attrs, prot, mmu_idx, page_size); } +void helper_sleep (CPUAVRState *env) +{ +CPUState *cs =CPU (avr_env_get_cpu (env)); + + cs->exception_index =EXCP_HLT ; +cpu_loop_exit (cs); +} +void helper_unsupported (CPUAVRState *env) +{ +CPUState *cs =CPU (avr_env_get_cpu (env)); + +/* +I count not find what happens on the real platform, so +it's EXCP_DEBUG for meanwhile +*/ + cs->exception_index =EXCP_DEBUG ; +if (qemu_loglevel_mask (LOG_UNIMP )) { +qemu_log ("UNSUPPORTED\n" ); +cpu_dump_state (cs, qemu_logfile, fprintf,0 ); + } +cpu_loop_exit (cs); +}void helper_debug (CPUAVRState *env) {@@ -142,3 +182,159 @@ void helper_debug(CPUAVRState *env)cpu_loop_exit (cs); } +void helper_wdr (CPUAVRState *env) +{ +CPUState *cs =CPU (avr_env_get_cpu (env)); + +/* +WD is not implemented yet, placeholder +*/ + cs->exception_index =EXCP_DEBUG ; +cpu_loop_exit (cs); +} + +target_ulong helper_inb (CPUAVRState *env,uint32_t port) +{ +target_ulong data =0 ; + +switch (port) { +case 0x38 : { + data =0xff & (env->rampD >>16 );/* RAMPD */ +break ; + } +case 0x39 : { + data =0xff & (env->rampX >>16 );/* RAMPX */ +break ; + } +case 0x3a : { + data =0xff & (env->rampY >>16 );/* RAMPY */ +break ; + } +case 0x3b : { + data =0xff & (env->rampZ >>16 );/* RAMPZ */ +break ; + } +case 0x3c : { + data =0xff & (env->eind >>16 );/* EIND */ +break ; + } +case 0x3d : {/* SPL */ + data = env->sp &0x00ff ; +break ; + } +case 0x3e : {/* SPH */ + data = env->sp >>8 ; +break ; + } +case 0x3f : {/* SREG */ + data =cpu_get_sreg (env); +break ; + } +default : { +/* +CPU does not know how to read this register, pass it to the +device/board +*/ + +cpu_physical_memory_read (PHYS_BASE_REGS + port +OFFS_IOREGS , + &data,1 ); + } + } + +if (port <IO_REGS ) { + env->io[port] = data;/* make a copy for SBI, SBIC, SBIS & CBI */ + } + +return data; +} + +void helper_fullwr (CPUAVRState *env,uint32_t data,uint32_t addr) +{ +#if VIRT_BASE_REGS ==0 +if (addr <=VIRT_BASE_REGS +SIZE_REGS ) { +#else +if (VIRT_BASE_REGS <= addr && addr <=VIRT_BASE_REGS +SIZE_REGS ) { +#endif +/* +write CPU REGS/IO REGS/EXT IO REGS +*/ +cpu_physical_memory_write (PHYS_BASE_REGS + addr -VIRT_BASE_REGS , + &data,1 ); + }else { +/* +write memory +*/ +cpu_physical_memory_write (PHYS_BASE_DATA + addr -VIRT_BASE_DATA , + &data,1 ); + } +} + +void helper_outb (CPUAVRState *env,uint32_t port,uint32_t data) +{ + data &=0x000000ff ; + +switch (port) { +case 0x04 : { +qemu_irq irq; +CPUState *cpu =CPU (avr_env_get_cpu (env)); + irq =qdev_get_gpio_in (DEVICE (cpu),3 ); +qemu_set_irq (irq,1 ); +break ; + } +case 0x38 : { +if (avr_feature (env,AVR_FEATURE_RAMPD )) { + env->rampD = (data &0xff ) <<16 ;/* RAMPD */ + } +break ; + } +case 0x39 : { +if (avr_feature (env,AVR_FEATURE_RAMPX )) { + env->rampX = (data &0xff ) <<16 ;/* RAMPX */ + } +break ; + } +case 0x3a : { +if (avr_feature (env,AVR_FEATURE_RAMPY )) { + env->rampY = (data &0xff ) <<16 ;/* RAMPY */ + } +break ; + } +case 0x3b : { +if (avr_feature (env,AVR_FEATURE_RAMPZ )) { + env->rampZ = (data &0xff ) <<16 ;/* RAMPZ */ + } +break ; + } +case 0x3c : { + env->eind = (data &0xff ) <<16 ;/* EIDN */ +break ; + } +case 0x3d : {/* SPL */ + env->sp = (env->sp &0xff00 ) | (data); +break ; + } +case 0x3e : {/* SPH */ +if (avr_feature (env,AVR_FEATURE_2_BYTE_SP )) { + env->sp = (env->sp &0x00ff ) | (data <<8 ); + } +break ; + } +case 0x3f : {/* SREG */ +cpu_set_sreg (env, data); +break ; + } +default : { +/* +CPU does not know how to write this register, pass it to the +device/board +*/ +cpu_physical_memory_write (PHYS_BASE_REGS + port +OFFS_IOREGS , + &data,1 ); + } + } + +if (port <IO_REGS ) { + env->io[port] = data;/* make a copy for SBI, SBIC, SBIS & CBI */ + } +} +target-avr/helper.h +6
-0@@ -18,4 +18,10 @@* <http://www.gnu.org/licenses/lgpl-2.1.html> */ +DEF_HELPER_1(wdr, void, env) DEF_HELPER_1(debug, void, env) +DEF_HELPER_1(sleep, void, env) +DEF_HELPER_1(unsupported, void, env) +DEF_HELPER_3(outb, void, env, i32, i32) +DEF_HELPER_2(inb, tl, env, i32) +DEF_HELPER_3 (fullwr, void, env, i32, i32)
Re: [Qemu-devel] [PATCH v10 08/10] target-avr: adding instruction translation
In reply to Michael RolnikQuoted 120 lines · Michael Rolnik
Signed-off-by Michael Rolnik <[email protected]>--- target-avr/helper.c | 118 +- target-avr/helper.h | 1 + target-avr/translate-inst.c | 2621 +++++++++++++++++++++++++++++++++++++++++++ target-avr/translate.c | 2 +- target-avr/translate.h | 119 ++ 5 files changed, 2830 insertions(+), 31 deletions(-) create mode 100644 target-avr/translate-inst.c create mode 100644 target-avr/translate.htarget-avr/helper.c +29
-28@@ -28,6 +28,7 @@#include "exec/cpu_ldst.h" #include "qemu/host-utils.h" #include "exec/helper-proto.h" +#include "exec/ioport.h" bool avr_cpu_exec_interrupt (CPUState *cs,int interrupt_request) {@@ -128,7 +129,7 @@ void tlb_fill(CPUState *cs, target_ulong vaddr, int is_write, prot =PAGE_READ |PAGE_EXEC ; }else {#if VIRT_BASE_REGS ==0 -if (vaddr <VIRT_BASE_REGS +SIZE_REGS ) { +if (vaddr <VIRT_BASE_REGS +AVR_REGS ) {#else if (VIRT_BASE_REGS <= vaddr && vaddr <VIRT_BASE_REGS +SIZE_REGS ) {#endif @@ -138,7 +139,7 @@ void tlb_fill(CPUState *cs, target_ulong vaddr, int is_write,*/ AVRCPU *cpu =AVR_CPU (cs);CPUAVRState *env = &cpu->env; - env->fullwr =1 ; + env->fullacc =1 ;cpu_loop_exit_restore (cs, retaddr); }else {/* @@ -193,6 +194,16 @@ void helper_wdr(CPUAVRState *env)cpu_loop_exit (cs); } +/* +This function implements IN instruction + +It does the following +a. if an IO register belongs to CPU, its value is read and returned +b. otherwise io address is translated to mem address and physical memory +is read. +c. it caches the value for sake of SBI, SBIC, SBIS & CBI implementation + +*/ target_ulong helper_inb (CPUAVRState *env,uint32_t port) {target_ulong data =0 ;@@ -236,39 +247,29 @@ target_ulong helper_inb(CPUAVRState *env, uint32_t port)device/board */ -cpu_physical_memory_read (PHYS_BASE_REGS + port +OFFS_IOREGS , - &data,1 ); +cpu_physical_memory_read (PHYS_BASE_REGS + port + +AVR_CPU_IO_REGS_BASE , &data,1 ); } } -if (port <IO_REGS ) { - env->io[port] = data;/* make a copy for SBI, SBIC, SBIS & CBI */ +/* make a copy */ +if (port <AVR_CPU_IO_REGS ) { + env->io[port] = data; }return data; } -void helper_fullwr (CPUAVRState *env,uint32_t data,uint32_t addr) -{ -#if VIRT_BASE_REGS ==0 -if (addr <=VIRT_BASE_REGS +SIZE_REGS ) { -#else -if (VIRT_BASE_REGS <= addr && addr <=VIRT_BASE_REGS +SIZE_REGS ) { -#endif -/* -write CPU REGS/IO REGS/EXT IO REGS -*/ -cpu_physical_memory_write (PHYS_BASE_REGS + addr -VIRT_BASE_REGS , - &data,1 ); - }else { -/* -write memory -*/ -cpu_physical_memory_write (PHYS_BASE_DATA + addr -VIRT_BASE_DATA , - &data,1 ); - } -} +/* +This function implements OUT instruction + +It does the following +a. if an IO register belongs to CPU, its value is written into the register +b. otherwise io address is translated to mem address and physical memory +is written. +c. it caches the value for sake of SBI, SBIC, SBIS & CBI implementation +*/ void helper_outb (CPUAVRState *env,uint32_t port,uint32_t data) { data &=0x000000ff ;@@ -328,13 +329,70 @@ void helper_outb(CPUAVRState *env, uint32_t port, uint32_t data)CPU does not know how to write this register, pass it to the device/board */ -cpu_physical_memory_write (PHYS_BASE_REGS + port +OFFS_IOREGS , - &data,1 ); +cpu_physical_memory_write (PHYS_BASE_REGS + port + +AVR_CPU_IO_REGS_BASE , &data,1 );
target-avr/helper.c void helper_outb(CPUAVRState *env, uint32_t port, uint32_t data) · line 341
Quoted 10 lines
target-avr/helper.c +5
-2} } -if (port <IO_REGS ) { - env->io[port] = data;/* make a copy for SBI, SBIC, SBIS & CBI */ +/* make a copy */ +if (port <AVR_CPU_IO_REGS ) { + env->io[port] = data; + } +}
Everything above here should be folded back to a previous patch.
Quoted 62 lines
target-avr/helper.c +54
-0+ +/* +this function implements LD instruction when there is a posibility to read +from a CPU register +*/ +target_ulong helper_fullrd (CPUAVRState *env,uint32_t addr) +{ +uint8_t data; +switch (addr) { +/* CPU registers */ + case AVR_CPU_REGS_BASE ... AVR_CPU_REGS_LAST: { + data = env->r[addr -AVR_CPU_REGS_BASE ]; +break ; + } +/* CPU IO registers & EXT IO registers */ + case AVR_CPU_IO_REGS_BASE ... AVR_EXT_IO_REGS_LAST: { + data =helper_inb (env, addr); +break ; + } + +/* memory */ +default : { +cpu_physical_memory_read (PHYS_BASE_DATA + addr -VIRT_BASE_DATA , + &data,1 ); + } + } + +return data; +} + +/* +this function implements LD instruction when there is a posibility to write +into a CPU register +*/ +void helper_fullwr (CPUAVRState *env,uint32_t data,uint32_t addr) +{ +switch (addr) { +/* CPU registers */ + case AVR_CPU_REGS_BASE ... AVR_CPU_REGS_LAST: { + env->r[addr -AVR_CPU_REGS_BASE ] = data; +break ; + } + +/* CPU IO registers & EXT IO registers */ + case AVR_CPU_IO_REGS_BASE ... AVR_EXT_IO_REGS_LAST: { +helper_outb (env, data, addr); +break ; + } + +/* memory */ +default : { +cpu_physical_memory_write (PHYS_BASE_DATA + addr -VIRT_BASE_DATA , + &data,1 ); + } } }target-avr/helper.h +0
-0
target-avr/helper.h DEF_HELPER_1(unsupported, void, env) · line 28
Quoted 4 lines
target-avr/helper.h +1
-0@@ -25,3 +25,4 @@ DEF_HELPER_1(unsupported, void, env) DEF_HELPER_3(outb, void, env, i32, i32) DEF_HELPER_2(inb, tl, env, i32) DEF_HELPER_3(fullwr, void, env, i32, i32) +DEF_HELPER_2 (fullrd, tl, env, i32)
You messed up in which patch you wanted to add fullwr. Either move the helpers back, or move the declaration forward.
r~
Re: [Qemu-devel] [PATCH v10 09/10] target-avr: updating translate.c to use instructions translation
In reply to Michael RolnikQuoted 231 lines · Michael Rolnik
Signed-off-by Michael Rolnik <[email protected]>--- target-avr/Makefile.objs | 4 +- target-avr/translate.c | 142 ++++++++++++++++++++--------------------------- 2 files changed, 64 insertions(+), 82 deletions(-)target-avr/Makefile.objs +3
-1@@ -18,6 +18,8 @@ # <http://www.gnu.org/licenses/lgpl-2.1.html> # -obj-y += translate.o cpu.o helper.o +obj-y += translate.o helper.o cpu.o translate-inst.o obj-y += gdbstub.o obj-$(CONFIG_SOFTMMU) += machine.o + +obj-y += decode.otarget-avr/translate.c +60
-80@@ -18,60 +18,30 @@* <http://www.gnu.org/licenses/lgpl-2.1.html> */ -#include "qemu/osdep.h" - -#include "cpu.h" -#include "exec/exec-all.h" -#include "disas/disas.h" -#include "tcg-op.h" -#include "exec/cpu_ldst.h" - -#include "exec/helper-proto.h" -#include "exec/helper-gen.h" -#include "exec/log.h" - -typedef struct DisasContext DisasContext ; -typedef struct InstInfo InstInfo ; - -/*This is the state at translation time. */ -struct DisasContext { -struct TranslationBlock *tb; - -/*Routine used to access memory */ -int memidx; -int bstate; -int singlestep; -}; - -enum { -BS_NONE =0 ,/* Nothing special (none of the below */ -BS_STOP =1 ,/* We want to stop translation for any reason */ -BS_BRANCH =2 ,/* A branch condition is reached */ -BS_EXCP =3 ,/* An exception condition is reached */ -}; - -static TCGv_env cpu_env; - -static TCGv cpu_pc; - -static TCGv cpu_Cf; -static TCGv cpu_Zf; -static TCGv cpu_Nf; -static TCGv cpu_Vf; -static TCGv cpu_Sf; -static TCGv cpu_Hf; -static TCGv cpu_Tf; -static TCGv cpu_If; - -static TCGv cpu_rampD; -static TCGv cpu_rampX; -static TCGv cpu_rampY; -static TCGv cpu_rampZ; - -static TCGv cpu_io[64 ]; -static TCGv cpu_r[32 ]; -static TCGv cpu_eind; -static TCGv cpu_sp; +#include "translate.h" + +TCGv_env cpu_env; + +TCGv cpu_pc; + +TCGv cpu_Cf; +TCGv cpu_Zf; +TCGv cpu_Nf; +TCGv cpu_Vf; +TCGv cpu_Sf; +TCGv cpu_Hf; +TCGv cpu_Tf; +TCGv cpu_If; + +TCGv cpu_rampD; +TCGv cpu_rampX; +TCGv cpu_rampY; +TCGv cpu_rampZ; + +TCGv cpu_io[64 ]; +TCGv cpu_r[32 ]; +TCGv cpu_eind; +TCGv cpu_sp;#include "exec/gen-icount.h" #define REG (x) (cpu_r[x])@@ -120,25 +90,27 @@ void avr_translate_init(void) done_init =1 ; } -static inline void gen_goto_tb (CPUAVRState *env,DisasContext *ctx,int n, -target_ulong dest) +static void decode_opc (AVRCPU *cpu,DisasContext *ctx,InstInfo *inst) { -TranslationBlock *tb; +CPUAVRState *env = &cpu->env; - tb = ctx->tb; + inst->opcode =cpu_ldl_code (env, inst->cpc *2 );/* pc points to words */ + inst->length =16 ; + inst->translate =NULL ; -if ((tb->pc &TARGET_PAGE_MASK ) == (dest &TARGET_PAGE_MASK ) - && (ctx->singlestep ==0 )) { -tcg_gen_goto_tb (n); -tcg_gen_movi_i32 (cpu_pc, dest); -tcg_gen_exit_tb ((uintptr_t )tb + n); - }else { -tcg_gen_movi_i32 (cpu_pc, dest); +/* the following function looks onto the opcode as a string of bytes */ +avr_decode (inst->cpc, &inst->length, inst->opcode, &inst->translate); -if (ctx->singlestep) { -gen_helper_debug (cpu_env); - } -tcg_gen_exit_tb (0 ); +if (inst->length ==16 ) { + inst->npc = inst->cpc +1 ; +/* get opcode as 16bit value */ + inst->opcode = inst->opcode &0x0000ffff ; + } +if (inst->length ==32 ) { + inst->npc = inst->cpc +2 ; +/* get opcode as 32bit value */ + inst->opcode = (inst->opcode <<16 ) + | (inst->opcode >>16 ); } }@@ -172,18 +144,21 @@ void gen_intermediate_code(CPUAVRState *env, struct TranslationBlock *tb)gen_tb_start (tb);/* decode first instruction */ - cpc = pc_start; - npc = cpc +1 ; + ctx.inst[0 ].cpc = pc_start; +decode_opc (cpu, &ctx, &ctx.inst[0 ]); do { - /* translate current instruction */ + /* set curr/next PCs */ + cpc = ctx.inst[0].cpc; + npc = ctx.inst[0].npc; + + /* decode next instruction */ + ctx.inst[1].cpc = ctx.inst[0].npc; + decode_opc(cpu, &ctx, &ctx.inst[1]); + + /* translate current instruction */ tcg_gen_insn_start(cpc); num_insns++; - /* just skip to next instruction */ - cpc++; - npc++; - ctx.bstate = BS_NONE; - if (unlikely(cpu_breakpoint_test(cs, cpc * 2, BP_ANY))) { tcg_gen_movi_i32(cpu_pc, cpc); gen_helper_debug(cpu_env);@@ -195,6 +170,8 @@ void gen_intermediate_code(CPUAVRState *env, struct TranslationBlock *tb) goto done_generating; } + ctx.bstate = ctx.inst[0 ].translate (env, &ctx, ctx.inst[0 ].opcode); +if (num_insns >= max_insns) {break ;/* max translated instructions limit reached */ }@@ -204,6 +181,8 @@ void gen_intermediate_code(CPUAVRState *env, struct TranslationBlock *tb)if ((cpc & (TARGET_PAGE_SIZE -1 )) ==0 ) {break ;/* page boundary */ } + + ctx.inst[0 ] = ctx.inst[1 ];/* make next inst curr */ }while (ctx.bstate ==BS_NONE && !tcg_op_buf_full ());if (tb->cflags &CF_LAST_IO ) {@@ -239,16 +218,17 @@ done_generating: }void restore_state_to_opc (CPUAVRState *env,TranslationBlock *tb, -target_ulong *data) +target_ulong *data) { env->pc_w = data[0 ]; }void avr_cpu_dump_state (CPUState *cs,FILE *f,fprintf_function cpu_fprintf, -int flags) +int flags) {AVRCPU *cpu =AVR_CPU (cs);CPUAVRState *env = &cpu->env; +int i;cpu_fprintf (f,"\n" );cpu_fprintf (f,"PC: %06x\n" , env->pc_w);@@ -272,7 +252,7 @@ void avr_cpu_dump_state(CPUState *cs, FILE *f, fprintf_function cpu_fprintf, env->sregC ? 'I' : '-');cpu_fprintf (f,"\n" ); -for (int i =0 ; i <ARRAY_SIZE (env->r); i++) { +for (i =0 ; i <ARRAY_SIZE (env->r); i++) {cpu_fprintf (f,"R[%02d]: %02x " , i, env->r[i]);if ((i %8 ) ==7 ) {
target-avr/translate.c void avr_cpu_dump_state(CPUState *cs, FILE *f, fprintf_function cpu_fprintf, · line 267
Quoted 8 lines
target-avr/translate.c +1
-1@@ -281,7 +261,7 @@ void avr_cpu_dump_state(CPUState *cs, FILE *f, fprintf_function cpu_fprintf, }cpu_fprintf (f,"\n" ); -for (int i =0 ; i <ARRAY_SIZE (env->io); i++) { +for (i =0 ; i <ARRAY_SIZE (env->io); i++) {cpu_fprintf (f,"IO[%02d]: %02x " , i, env->io[i]);if ((i %8 ) ==7 ) {
This entire patch should be folded back into previous patches.
r~
Re: [Qemu-devel] [PATCH v10 01/10] target-avr: AVR cores support is added.
In reply to Richard HendersonHi Richard,
Please explain why I am not accessing fullacc correctly.
Quoted 44 lines · Richard Henderson
target-avr/cpu.c
Quoted 11 lines · Michael Rolnik
target-avr/cpu.c new file +11
-0+static bool avr_cpu_has_work (CPUState *cs) +{ +AVRCPU *cpu =AVR_CPU (cs); +CPUAVRState *env = &cpu->env; + +return (cs->interrupt_request + & (CPU_INTERRUPT_HARD + |CPU_INTERRUPT_RESET )) + &&cpu_interrupts_enabled (env); +} +static void avr_cpu_synchronize_from_tb(CPUState *cs, TranslationBlock*tb)
target-avr/cpu.c line 51
Quoted 6 lines
target-avr/cpu.c new file +6
-0+{ +AVRCPU *cpu =AVR_CPU (cs); +CPUAVRState *env = &cpu->env; + + env->pc_w = tb->pc /2 ;/* internally PC points to words */ +}For the 4th time: missing spaces between functions. Lots of them. Please fix
them all, without me having to repeat myself a 5th time.Quoted 1 line
+ bool fullacc;/* CPU/MEM if true MEM only otherwise */
...
Quoted 1 line
+static inline void cpu_get_tb_cpu_state(CPUAVRState *env,
target_ulong*pc,
target-avr/cpu.h line 145
Quoted 6 lines
target-avr/cpu.h new file +6
-0+ target_ulong *cs_base, uint32_t *pflags) +{ + *pc = env->pc_w *2 ; + *cs_base =0 ; + *pflags =0 ; +}The fullacc bit needs to be reflected in *pflags here. The way you are accessing
env->fullaccfrom translate*.c is invalid.r~
Signature · 2 lines
Best Regards, Michael Rolnik
Re: [Qemu-devel] [PATCH v10 09/10] target-avr: updating translate.c to use instructions translation
In reply to Richard Hendersonif I fold this patch into previous ones, they will become non buildable, because this patch assumes existance of functions from the preceding patch. Is this acceptable?
Quoted 259 lines · Richard Henderson
Quoted 4 lines · Michael Rolnik
Signed-off-by Michael Rolnik <[email protected]>--- target-avr/Makefile.objs | 4 +- target-avr/translate.c | 142++++++++++++++++++++---------------------------
Quoted 106 lines
2 files changed, 64 insertions(+), 82 deletions(-)target-avr/Makefile.objs +3
-1@@ -18,6 +18,8 @@ # <http://www.gnu.org/licenses/lgpl-2.1.html> # -obj-y += translate.o cpu.o helper.o +obj-y += translate.o helper.o cpu.o translate-inst.o obj-y += gdbstub.o obj-$(CONFIG_SOFTMMU) += machine.o + +obj-y += decode.otarget-avr/translate.c +24
-54@@ -18,60 +18,30 @@* <http://www.gnu.org/licenses/lgpl-2.1.html> */ -#include "qemu/osdep.h" - -#include "cpu.h" -#include "exec/exec-all.h" -#include "disas/disas.h" -#include "tcg-op.h" -#include "exec/cpu_ldst.h" - -#include "exec/helper-proto.h" -#include "exec/helper-gen.h" -#include "exec/log.h" - -typedef struct DisasContext DisasContext ; -typedef struct InstInfo InstInfo ; - -/*This is the state at translation time. */ -struct DisasContext { -struct TranslationBlock *tb; - -/*Routine used to access memory */ -int memidx; -int bstate; -int singlestep; -}; - -enum { -BS_NONE =0 ,/* Nothing special (none of the below */ -BS_STOP =1 ,/* We want to stop translation for any reason */ -BS_BRANCH =2 ,/* A branch condition is reached */ -BS_EXCP =3 ,/* An exception condition is reached */ -}; - -static TCGv_env cpu_env; - -static TCGv cpu_pc; - -static TCGv cpu_Cf; -static TCGv cpu_Zf; -static TCGv cpu_Nf; -static TCGv cpu_Vf; -static TCGv cpu_Sf; -static TCGv cpu_Hf; -static TCGv cpu_Tf; -static TCGv cpu_If; - -static TCGv cpu_rampD; -static TCGv cpu_rampX; -static TCGv cpu_rampY; -static TCGv cpu_rampZ; - -static TCGv cpu_io[64 ]; -static TCGv cpu_r[32 ]; -static TCGv cpu_eind; -static TCGv cpu_sp; +#include "translate.h" + +TCGv_env cpu_env; + +TCGv cpu_pc; + +TCGv cpu_Cf; +TCGv cpu_Zf; +TCGv cpu_Nf; +TCGv cpu_Vf; +TCGv cpu_Sf; +TCGv cpu_Hf; +TCGv cpu_Tf; +TCGv cpu_If; + +TCGv cpu_rampD; +TCGv cpu_rampX; +TCGv cpu_rampY; +TCGv cpu_rampZ; + +TCGv cpu_io[64 ]; +TCGv cpu_r[32 ]; +TCGv cpu_eind; +TCGv cpu_sp;#include "exec/gen-icount.h" #define REG (x) (cpu_r[x])target-avr/translate.c void avr_translate_init(void) · line 123
Quoted 4 lines
target-avr/translate.c +0
-1@@ -120,25 +90,27 @@ void avr_translate_init(void) done_init =1 ; } -static inline void gen_goto_tb(CPUAVRState *env, DisasContext *ctx, intn,
target-avr/translate.c void avr_translate_init(void)
Quoted 8 lines
target-avr/translate.c +3
-3- target_ulong dest) +static void decode_opc (AVRCPU *cpu,DisasContext *ctx,InstInfo *inst) { -TranslationBlock *tb; +CPUAVRState *env = &cpu->env; - tb = ctx->tb; + inst->opcode =cpu_ldl_code (env, inst->cpc *2 );/* pc points to words */ > + inst->length = 16; > + inst->translate = NULL;target-avr/translate.c void avr_translate_init(void)
Quoted 9 lines
target-avr/translate.c +1
-7-if ((tb->pc &TARGET_PAGE_MASK ) == (dest &TARGET_PAGE_MASK ) - && (ctx->singlestep ==0 )) { -tcg_gen_goto_tb (n); -tcg_gen_movi_i32 (cpu_pc, dest); -tcg_gen_exit_tb ((uintptr_t )tb + n); - }else { -tcg_gen_movi_i32 (cpu_pc, dest); +/* the following function looks onto the opcode as a string of bytes */
target-avr/translate.c void avr_translate_init(void) · line 99
Quoted 1 line
target-avr/translate.c +1
-0+ avr_decode(inst->cpc, &inst->length, inst->opcode,
&inst->translate);target-avr/translate.c void gen_intermediate_code(CPUAVRState *env,
Quoted 19 lines
target-avr/translate.c +10
-4-if (ctx->singlestep) { -gen_helper_debug (cpu_env); - } -tcg_gen_exit_tb (0 ); +if (inst->length ==16 ) { + inst->npc = inst->cpc +1 ; +/* get opcode as 16bit value */ + inst->opcode = inst->opcode &0x0000ffff ; + } +if (inst->length ==32 ) { + inst->npc = inst->cpc +2 ; +/* get opcode as 32bit value */ + inst->opcode = (inst->opcode <<16 ) + | (inst->opcode >>16 ); } }@@ -172,18 +144,21 @@ void gen_intermediate_code(CPUAVRState *env,struct TranslationBlock *tb)
target-avr/translate.c void gen_intermediate_code(CPUAVRState *env, struct
Quoted 30 lines
target-avr/translate.c +11
-8gen_tb_start (tb);/* decode first instruction */ - cpc = pc_start; - npc = cpc +1 ; + ctx.inst[0 ].cpc = pc_start; +decode_opc (cpu, &ctx, &ctx.inst[0 ]); do { - /* translate current instruction */ + /* set curr/next PCs */ + cpc = ctx.inst[0].cpc; + npc = ctx.inst[0].npc; + + /* decode next instruction */ + ctx.inst[1].cpc = ctx.inst[0].npc; + decode_opc(cpu, &ctx, &ctx.inst[1]); + + /* translate current instruction */ tcg_gen_insn_start(cpc); num_insns++; - /* just skip to next instruction */ - cpc++; - npc++; - ctx.bstate = BS_NONE; - if (unlikely(cpu_breakpoint_test(cs, cpc * 2, BP_ANY))) { tcg_gen_movi_i32(cpu_pc, cpc); gen_helper_debug(cpu_env);@@ -195,6 +170,8 @@ void gen_intermediate_code(CPUAVRState *env, structTranslationBlock *tb)
target-avr/translate.c void gen_intermediate_code(CPUAVRState *env, struct TranslationBlock *tb)
Quoted 4 lines
target-avr/translate.c +1
-0goto done_generating; } + ctx.bstate = ctx.inst[0].translate(env, &ctx,ctx.inst[0].opcode);
target-avr/translate.c void gen_intermediate_code(CPUAVRState *env, struct
Quoted 5 lines
target-avr/translate.c +1
-0+if (num_insns >= max_insns) {break ;/* max translated instructions limit reached */ }@@ -204,6 +181,8 @@ void gen_intermediate_code(CPUAVRState *env, structTranslationBlock *tb)
Quoted 9 lines
target-avr/translate.c +2
-0if ((cpc & (TARGET_PAGE_SIZE -1 )) ==0 ) {break ;/* page boundary */ } + + ctx.inst[0 ] = ctx.inst[1 ];/* make next inst curr */ }while (ctx.bstate ==BS_NONE && !tcg_op_buf_full ());if (tb->cflags &CF_LAST_IO ) {target-avr/translate.c done_generating: · line 226
Quoted 10 lines
target-avr/translate.c +1
-1@@ -239,16 +218,17 @@ done_generating: }void restore_state_to_opc (CPUAVRState *env,TranslationBlock *tb, -target_ulong *data) +target_ulong *data) { env->pc_w = data[0 ]; } void avr_cpu_dump_state(CPUState *cs, FILE *f, fprintf_function
cpu_fprintf,target-avr/translate.c void avr_cpu_dump_state(CPUState *cs, FILE *f,
Quoted 10 lines
target-avr/translate.c +2
-1- int flags) + int flags) {AVRCPU *cpu =AVR_CPU (cs);CPUAVRState *env = &cpu->env; +int i;cpu_fprintf (f,"\n" );cpu_fprintf (f,"PC: %06x\n" , env->pc_w);@@ -272,7 +252,7 @@ void avr_cpu_dump_state(CPUState *cs, FILE *f,
fprintf_functioncpu_fprintf,target-avr/translate.c void avr_cpu_dump_state(CPUState *cs, FILE *f,
Quoted 9 lines
target-avr/translate.c +1
-1env->sregC ? 'I' : '-');cpu_fprintf (f,"\n" ); -for (int i =0 ; i <ARRAY_SIZE (env->r); i++) { +for (i =0 ; i <ARRAY_SIZE (env->r); i++) {cpu_fprintf (f,"R[%02d]: %02x " , i, env->r[i]);if ((i %8 ) ==7 ) {@@ -281,7 +261,7 @@ void avr_cpu_dump_state(CPUState *cs, FILE *f,
fprintf_functioncpu_fprintf,target-avr/translate.c void avr_cpu_dump_state(CPUState *cs, FILE *f, fprintf_function cpu_fprintf, · line 267
Quoted 9 lines
target-avr/translate.c +1
-1}cpu_fprintf (f,"\n" ); -for (int i =0 ; i <ARRAY_SIZE (env->io); i++) { +for (i =0 ; i <ARRAY_SIZE (env->io); i++) {cpu_fprintf (f,"IO[%02d]: %02x " , i, env->io[i]);if ((i %8 ) ==7 ) {This entire patch should be folded back into previous patches.
r~
Signature · 2 lines
Best Regards, Michael Rolnik
Re: [Qemu-devel] [PATCH v10 01/10] target-avr: AVR cores support is added.
In reply to Michael RolnikQuoted 3 lines · Michael Rolnik
Hi Richard,
Please explain why I am not accessing fullacc correctly.
You can't examine fields of env, which vary, during translate.c. You must only examine fields of TB, which are invariant.
r~
Re: [Qemu-devel] [PATCH v10 09/10] target-avr: updating translate.c to use instructions translation
In reply to Michael RolnikQuoted 3 lines · Michael Rolnik
if I fold this patch into previous ones, they will become non buildable, because this patch assumes existance of functions from the preceding patch. Is this acceptable?
All patches need to be buildable, so that git bisect works.
The previous patches are already (sort of) non-buildable, but you don't notice because you've not added translate-inst.o to obj-y until here. But there's certainly no reason to put code in translate.c in one patch, then move it to translate.h in another.
r~
Re: [Qemu-devel] [PATCH v10 01/10] target-avr: AVR cores support is added.
In reply to Richard HendersonSo how do I get this flag unset?
Quoted 11 lines · Richard Henderson
Quoted 3 lines · Michael Rolnik
Hi Richard,
Please explain why I am not accessing fullacc correctly.
You can't examine fields of env, which vary, during
translate.c. You must only examine fields of TB, which are invariant.r~
Re: [Qemu-devel] [PATCH v10 01/10] target-avr: AVR cores support is added.
a. a helper function sets a flag within env
b. cpu_get_tb_cpu_state introduces this flag, though tb.flags, for code generation by gen_intermediate_code
c. the code is generated
d. the flag remains to be set within env. Who clear it?
Quoted 16 lines · Michael Rolnik
So how do I get this flag unset?
Quoted 11 lines · Richard Henderson
Quoted 3 lines · Michael Rolnik
Hi Richard,
Please explain why I am not accessing fullacc correctly.
You can't examine fields of env, which vary, during
translate.c. You must only examine fields of TB, which are invariant.r~
Signature · 2 lines
Best Regards, Michael Rolnik
Re: [Qemu-devel] [PATCH v10 01/10] target-avr: AVR cores support is added.
Quoted 1 line · Michael Rolnik
a. a helper function sets a flag within env
... and exits the cpu loop.
Quoted 3 lines
b.
cpu_get_tb_cpu_stateintroduces this flag, though tb.flags, for code generation bygen_intermediate_code
c. the code is generated
Yep.
Quoted 1 line
d. the flag remains to be set within env. Who clear it?
Presumably this flag is only usefully set for one instruction, the one we've just determined accesses the registers. So I'd clear the flag within helper_fullwr / helper_fullrd.
In translate.c, when you notice tb->flags & HF_FULLACC is set, you'd interpret one instruction and then exit the TB. That way we'll start the next TB with HF_FULLACC cleared.
Thus for a series of instructions like
insn1
insn2
insn3 (writes to register)
insn4
branch
we will generate 3 TB:
TB1: (flags = 0)
insn1
insn2
insn3
insn4
branch
TB2: (flags = HF_FULLACC)
insn3
TB3: (flags = 0)
insn4
branch
Most importantly, when we come to execute TB1 for the second time, we will find TB2 and TB3 quickly, with the right set of flags.
r~
Re: [Qemu-devel] [PATCH v10 09/10] target-avr: updating translate.c to use instructions translation
In reply to Richard HendersonHello,
I fixed all the issue, the patches were sent last week (July 6th). Please have a look.
regards,
Michael
Quoted 18 lines · Richard Henderson
Quoted 5 lines · Michael Rolnik
if I fold this patch into previous ones, they will become non buildable, because this patch assumes existance of functions from the preceding patch.
Is this acceptable?All patches need to be buildable, so that git bisect works.
The previous patches are already (sort of) non-buildable, but you don't notice because you've not added translate-inst.o to obj-y until here. But there's certainly no reason to put code in
translate.cin one patch, then move it totranslate.hin another.r~
Signature · 2 lines
Best Regards, Michael Rolnik