]> git.proxmox.com Git - mirror_qemu.git/commit - target/sh4/translate.c
target/sh4: fix RTE instruction delay slot
authorAurelien Jarno <aurelien@aurel32.net>
Tue, 16 May 2017 22:48:18 +0000 (00:48 +0200)
committerAurelien Jarno <aurelien@aurel32.net>
Tue, 30 May 2017 19:00:56 +0000 (21:00 +0200)
commitbe53081a619443dc4512039d89345475ef7d9a46
tree9dce7b4becd3a8cf2ed86b627513817c87ebdb08
parent5c6f3eb7db478fe988d8419c191fe388c6cf5194
target/sh4: fix RTE instruction delay slot

The ReTurn from Exception (RTE) instruction loads the system register
(SR) with the saved system register (SSR). It has a delay slot, and
behaves specially according to the SH4 manual:

  The SR value accessed by the instruction in the RTE delay slot is the
  value restored from SSR by the RTE instruction. The SR and MD values
  defined prior to RTE execution are used to fetch the instruction in
  the RTE delay slot.

The instruction in the delay slot being often a NOP, it doesn't cause
any issue most of the time except in some rare cases where the NOP is
being splitted in a different TB (for example when the TCG op buffer
is full). In that case the NOP is fetched with the user permissions
and causes an instruction TLB protection violation exception.

This patches fixes that by introducing a new delay slot flag for the
RTE instruction. Given it's a privileged instruction, the RTE delay
slot instruction is always fetched in privileged mode. It is therefore
enough to to check for this flag in cpu_mmu_index.

Reviewed-by: Richard Henderson <rth@twiddle.net>
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
target/sh4/cpu.h
target/sh4/translate.c