KVM-PR: issue with PC/LR when MSR_DR is set?
I'm trying to get Mac OS 9 to boot within QEMU+KVM-PR, but I'm running into an odd interaction with relocation during early startup that I can't figure out. Here is the disassembly of what KVM is executing. All of this is in supervisor mode.
0x00f154e0: mtlr r22 0x00f154e4: mtsprg 3,r23 0x00f154e8: mtmsr r15 ; r15 = 0x10, MSR is now 0x10
At this point KVM_PR changes the PC to 0xfbf154e8, but execution continues at the same "address" (I'll use the original addresses for continuity).
0x00f154ec: isync 0x00f154f0: rlwimi r25,r26,2,22,29 0x00f154f4: bnelr 0x00f154f8: b 0xf15524 0x00f15524: bl 0xf13180
Note that LR gets set to 0xfbf15528, since KVM thinks that's its address.
0x00f13180: hwsync
0x00f13184: mtmsr r14 ; r14 = 0x00, MSR is now 0x00
PC is now back to 0xf13188, but LR is still 0xfbf15528.
0x00f13188: isync 0x00f1318c: mflr r23 => 0x00f13190: icbi 0,r23
r23 is 0xfbf15528, which causes a page fault. This falls through into MMIO, which doesn't know what to do with the icbi, and EMULATE_FAIL results.
I added some debugging to KVM-PR and this is what results to prove that the PC is altered in the way it appears above. You can see the result of kvmppc_get_pc switching addresses back and forth as relocation changes. "now" is the new value of the MSR.
[ 6334.613981] mtmsr pc: 00f12fb8 lr: 00000324 now: 00000010 [ 6334.614056] mtmsr pc: fbf12fc4 lr: 00000324 now: 00000000 [ 6334.614124] mtmsr pc: 00f154e8 lr: 00f15bbc now: 00000010 [ 6334.614234] mtmsr pc: fbf13184 lr: fbf15528 now: 00000000 [ 6334.614295] icbi (00f13190: fbf15528 fbf15528 7c00bfac (msrdr 0 msrir 0) detected, failure imminent
It seems like there needs to be a shadow PC for handling this situation so that the LR can be set correctly (or, failing that, some way of patching up PC/LR when relocation changes state). Does anyone have a suggestion about how I could implement this?
Signature · 3 lines
------------------------------------ personal: http://www.cameronkaiser.com/ -- Cameron Kaiser * Floodgap Systems * www.floodgap.com * [email protected] -- Get out of the road if you want to grow old -- Pink Floyd ------------------