target-ppc: fix RFI by clearing some bits of MSR

Since commit 2ada0ed, "Return From Interrupt" is broken for PPC processors
because some interrupt specifics bits of SRR1 are copied to MSR.

SRR1 is a save of MSR during interrupt.
During RFI, MSR must be restored from SRR1.
But some bits of SRR1 are interrupt-specific and are not used for MSR saving.

This is the specification (ISA 2.06) at chapter 6.4.3 (Interrupt Processing):
"2. Bits 33:36 and 42:47 of SRR1 or HSRR1 are loaded with information specific
    to the interrupt type.
 3. Bits 0:32, 37:41, and 48:63 of SRR1 or HSRR1 are loaded with a copy of the
    corresponding bits of the MSR."

Below is a representation of MSR bits which are not saved:
0:15 16:31 32  33:36    37:41      42:47     48:63
——— | ——— | — X X X X — — — — — X X X X X X | ————
0000 0000 |    7   |   8   |   3   |   F    | 0000

History:
In the initial Qemu implementation (e1833e1), the mask 0x783F0000 was used for
saving MSR in SRR1. But all the bits 32:47 were cleared during RFI restoring.
This was wrong. The commit 2ada0ed explains that this breaks Altivec.
Indeed, bit 38 (for Altivec support) must be saved and restored.
The change of 2ada0ed was to restore all the bits of SRR1 to MSR.
But it's also wrong.

Explanation:
As an example, let's see what's happening after a TLB miss.
According to the e300 manual (E300CORERM table 5-6), the TLB miss interrupts
set the bits 44-47 for KEY, I/D, WAY and S/L. These bits are specifics to the
interrupt and must not be copied into MSR at the end of the interrupt.
With the current implementation, a TLB miss overwrite bits POW, TGPR and ILE.

Fix:
It shouldn't be needed to filter-out bits on MSR saving when interrupt occurs.
Specific bits overwrite MSR ones in SRR1.
But at the end of interrupt (RFI), specifics bits must be cleared before
restoring MSR from SRR1. The mask 0x783F0000 apply here.

Discussion:
The bits of the mask 0x783F0000 are cleared after an interrupt.
I cannot find a specification which talks about this
but I assume it is the truth since Linux can run this way.
Maybe it's not perfect but it's better (works for e300).

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
Acked-by: Alexander Graf <agraf@suse.de>
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2 files changed
tree: 118d91e17d0ad82269d9c02e6ee47cfb473ead5b
  1. audio/
  2. block/
  3. bsd-user/
  4. darwin-user/
  5. default-configs/
  6. docs/
  7. fpu/
  8. fsdev/
  9. gdb-xml/
  10. hw/
  11. linux-user/
  12. net/
  13. pc-bios/
  14. QMP/
  15. roms/
  16. slirp/
  17. sysconfigs/
  18. target-alpha/
  19. target-arm/
  20. target-cris/
  21. target-i386/
  22. target-m68k/
  23. target-microblaze/
  24. target-mips/
  25. target-ppc/
  26. target-s390x/
  27. target-sh4/
  28. target-sparc/
  29. tcg/
  30. tests/
  31. .gitignore
  32. .gitmodules
  33. a.out.h
  34. acl.c
  35. acl.h
  36. aes.c
  37. aes.h
  38. aio.c
  39. alpha-dis.c
  40. alpha.ld
  41. arch_init.c
  42. arch_init.h
  43. arm-dis.c
  44. arm-semi.c
  45. arm.ld
  46. async.c
  47. balloon.c
  48. balloon.h
  49. block-migration.c
  50. block-migration.h
  51. block.c
  52. block.h
  53. block_int.h
  54. bswap.h
  55. bt-host.c
  56. bt-host.h
  57. bt-vhci.c
  58. buffered_file.c
  59. buffered_file.h
  60. cache-utils.c
  61. cache-utils.h
  62. Changelog
  63. check-qdict.c
  64. check-qfloat.c
  65. check-qint.c
  66. check-qjson.c
  67. check-qlist.c
  68. check-qstring.c
  69. cmd.c
  70. cmd.h
  71. cocoa.m
  72. CODING_STYLE
  73. config.h
  74. configure
  75. console.c
  76. console.h
  77. COPYING
  78. COPYING.LIB
  79. cpu-all.h
  80. cpu-common.h
  81. cpu-defs.h
  82. cpu-exec.c
  83. cpus.c
  84. cpus.h
  85. create_config
  86. cris-dis.c
  87. curses.c
  88. curses_keys.h
  89. cursor.c
  90. cursor_hidden.xpm
  91. cursor_left_ptr.xpm
  92. cutils.c
  93. d3des.c
  94. d3des.h
  95. def-helper.h
  96. device_tree.c
  97. device_tree.h
  98. dis-asm.h
  99. disas.c
  100. disas.h
  101. dma-helpers.c
  102. dma.h
  103. dyngen-exec.h
  104. elf.h
  105. envlist.c
  106. envlist.h
  107. exec-all.h
  108. exec.c
  109. feature_to_c.sh
  110. gdbstub.c
  111. gdbstub.h
  112. gen-icount.h
  113. host-utils.c
  114. host-utils.h
  115. hpet.h
  116. hppa-dis.c
  117. hppa.ld
  118. hxtool
  119. i386-dis.c
  120. i386.ld
  121. ia64-dis.c
  122. ia64.ld
  123. input.c
  124. ioport-user.c
  125. ioport.c
  126. ioport.h
  127. iov.c
  128. iov.h
  129. json-lexer.c
  130. json-lexer.h
  131. json-parser.c
  132. json-parser.h
  133. json-streamer.c
  134. json-streamer.h
  135. keymaps.c
  136. keymaps.h
  137. kvm-all.c
  138. kvm-stub.c
  139. kvm.h
  140. libfdt_env.h
  141. LICENSE
  142. linux-aio.c
  143. m68k-dis.c
  144. m68k-semi.c
  145. m68k.ld
  146. MAINTAINERS
  147. Makefile
  148. Makefile.dis
  149. Makefile.hw
  150. Makefile.objs
  151. Makefile.target
  152. Makefile.user
  153. microblaze-dis.c
  154. migration-exec.c
  155. migration-fd.c
  156. migration-tcp.c
  157. migration-unix.c
  158. migration.c
  159. migration.h
  160. mips-dis.c
  161. mips.ld
  162. module.c
  163. module.h
  164. monitor.c
  165. monitor.h
  166. nbd.c
  167. nbd.h
  168. net-checksum.c
  169. net.c
  170. net.h
  171. notify.c
  172. notify.h
  173. osdep.c
  174. osdep.h
  175. path.c
  176. pci-ids.txt
  177. poison.h
  178. posix-aio-compat.c
  179. ppc-dis.c
  180. ppc.ld
  181. ppc64.ld
  182. qbool.c
  183. qbool.h
  184. qdict-test-data.txt
  185. qdict.c
  186. qdict.h
  187. qemu-aio.h
  188. qemu-barrier.h
  189. qemu-binfmt-conf.sh
  190. qemu-char.c
  191. qemu-char.h
  192. qemu-common.h
  193. qemu-config.c
  194. qemu-config.h
  195. qemu-doc.texi
  196. qemu-error.c
  197. qemu-error.h
  198. qemu-img-cmds.hx
  199. qemu-img.c
  200. qemu-img.texi
  201. qemu-io.c
  202. qemu-lock.h
  203. qemu-log.h
  204. qemu-malloc.c
  205. qemu-monitor.hx
  206. qemu-nbd.c
  207. qemu-nbd.texi
  208. qemu-objects.h
  209. qemu-option.c
  210. qemu-option.h
  211. qemu-options.hx
  212. qemu-queue.h
  213. qemu-sockets.c
  214. qemu-tech.texi
  215. qemu-thread.c
  216. qemu-thread.h
  217. qemu-timer.c
  218. qemu-timer.h
  219. qemu-tool.c
  220. qemu-x509.h
  221. qemu.sasl
  222. qemu_socket.h
  223. qerror.c
  224. qerror.h
  225. qfloat.c
  226. qfloat.h
  227. qint.c
  228. qint.h
  229. qjson.c
  230. qjson.h
  231. qlist.c
  232. qlist.h
  233. qobject.h
  234. qstring.c
  235. qstring.h
  236. readline.c
  237. readline.h
  238. README
  239. rules.mak
  240. rwhandler.c
  241. rwhandler.h
  242. s390-dis.c
  243. s390.ld
  244. savevm.c
  245. sdl.c
  246. sdl_keysym.h
  247. sdl_zoom.c
  248. sdl_zoom.h
  249. sdl_zoom_template.h
  250. sh4-dis.c
  251. softmmu-semi.h
  252. softmmu_defs.h
  253. softmmu_exec.h
  254. softmmu_header.h
  255. softmmu_template.h
  256. sparc-dis.c
  257. sparc.ld
  258. sparc64.ld
  259. sysemu.h
  260. targphys.h
  261. tcg-runtime.c
  262. texi2pod.pl
  263. thunk.c
  264. thunk.h
  265. TODO
  266. translate-all.c
  267. uboot_image.h
  268. usb-bsd.c
  269. usb-linux.c
  270. usb-stub.c
  271. VERSION
  272. vgafont.h
  273. vl.c
  274. vnc-auth-sasl.c
  275. vnc-auth-sasl.h
  276. vnc-auth-vencrypt.c
  277. vnc-auth-vencrypt.h
  278. vnc-encoding-hextile.c
  279. vnc-encoding-zlib.c
  280. vnc-tls.c
  281. vnc-tls.h
  282. vnc.c
  283. vnc.h
  284. vnc_keysym.h
  285. vnchextile.h
  286. x86_64.ld
  287. x_keymap.c
  288. x_keymap.h