unicorn-engine / unicorn

Unicorn CPU emulator framework (ARM, AArch64, M68K, Mips, Sparc, PowerPC, RiscV, S390x, TriCore, X86)
http://www.unicorn-engine.org
GNU General Public License v2.0
7.68k stars 1.35k forks source link

(Tricore) emu_start: pc don't move #1663

Closed coc-cyqh closed 2 years ago

coc-cyqh commented 2 years ago
from unicorn import *
from unicorn.tricore_const import *
tricore_code = b"\x91\x10\x01\xf8\xd9\xff\xa0\x2f" #movh.a a15,#0x8011;lea a15,[a15]-0x760
ADDRESS = 0x4000
mu = Uc(UC_ARCH_TRICORE,UC_MODE_LITTLE_ENDIAN)
mu.mem_map(ADDRESS, 0x4000,7)
mu.mem_write(ADDRESS,tricore_code)
mu.emu_start(ADDRESS,0,count=2) # pc don't move
r_pc = mu.reg_read(UC_TRICORE_REG_PC)
print(f"after pc {hex(r_pc)}") # pc 0x4000

After mu.emu_start, pc is 0x4000 but should be 0x4008.

zachsez commented 2 years ago

This is also an issue with the C library. But PC is stuck at 0x60. One thing I noticed is that A11 was updated with the correct PC value, which according to ABI/ISA manuals is the return address for a function call i.e. after ever instruction the link register is updated to current PC.

coc-cyqh commented 2 years ago

I found that A11 register was only updated when emu_start was given until and count = 0. I guess that A11 was assigned the value of unitl. And it is not helpful for me. I want to execute my tricore code step by step. But I can not know the address of next instruction because of the instruction size and jump instruction.

wtdcode commented 2 years ago

Closed due to PR merged.