Skip to contentSkip to conversation

Emulating lwz instruction powerpc e500

DISCUSSION Aashish Mittal 3 participants 5 messages Jul 8, 2011 – Jul 18, 2011

lore
Share & tools
lore
#0 lore raw

Hi

I'm trying to emulate the lwz instruction in powerpc e500 kvm for my project . And the instruction can modify any of the 32 gpr's . So i'm resuming the guest using RESUME_GUEST_NV Flag so that all the gpr's can be updated . But somehow the the guest OS doesn't boots after that. I took the vcpu dump before emulating the instruction and after emulating it . Also i took the vcpu dump without emulating the instruction just before and just after the emulation . And i'm surprised to see that while lwz should have changed only one gpr instrction which i'm doing and is getting correctly emulated but int he original dump there are more then 1 gpr is modified and this problem only arrives when i use RESUME_GUEST_NV but if i use RESUME_GUEST all other registers get modified correctly while the one which lwz should have modified if it belongs to gpr15-31 then the change doesn't reflects there. I'm attaching the vcpu dump

Inst=0x8249a0e0, opcode:32 xop:112
RT: 18 , RA: 9, D: 0xa0e0 Data (to be written in RT) 0x20000000 (VCPU Dump just before the instruction is executed)

pc:   c055f518 msr:  00021002
lr:   c055f710 ctr:  00000001
srr0: c0548560 srr1: 00021002
exceptions: 00000000
gpr00: 00000000 c05b3ee0 c05872e0 00000000
gpr04: 00000ae7 00000000 00000004 00000000
gpr08: 00000000 c05c0000 0000005b c0a0073b
gpr12: 88000082 00000000 00000000 00000000
gpr16: 00000000 00000000 00000000 00000000
gpr20: 00000000 00000000 00000000 00000000
gpr24: 00000000 00000000 00001620 00000000
gpr28: c05c0000 00000adf c05c0000 c05b3f68

(VCPU DUMP just at the next instruction if i don't emulate the instruction )

pc:   c055f51c msr:  00021002
lr:   c055f710 ctr:  00000001
srr0: c0548560 srr1: 00021002
exceptions: 00000000
gpr00: 00000000 c05b3ee0 c05872e0 00000000
gpr04: 00000ae7 00000000 00000004 00000000
gpr08: 00000000 c05c0000 0000005b c0a0073b
gpr12: 88000082 00000000 00000000 00000000
gpr16: 00000000 00000000 20000000 00000000
gpr20: 00000000 00000000 00000000 00000000
gpr24: ffffffff fffffffc 00001620 00000000
gpr28: 00000000 00000ae4 00000000 00000000

(VCPU DUMP if i emulate the instruction manually and resume the guest using RESUME_GUEST_NV flag)

pc:   c055f51c msr:  00021002
lr:   c055f710 ctr:  00000001
srr0: c0548560 srr1: 00021002
exceptions: 00000000
gpr00: 00000000 c05b3ee0 c05872e0 00000000
gpr04: 00000ae7 00000000 00000004 00000000
gpr08: 00000000 c05c0000 0000005b c0a0073b
gpr12: 88000082 00000000 00000000 00000000
gpr16: 00000000 00000000 20000000 00000000
gpr20: 00000000 00000000 00000000 00000000
gpr24: 00000000 00000000 00001620 00000000
gpr28: c05c0000 00000adf c05c0000 c05b3f68

Thanks in advance .

#1 lore raw
Quoted 5 lines · On Fri, 8 Jul 2011 20:33:18 +0000 Aashish Mittal <[email protected]>…

Hi

I'm trying to emulate the lwz instruction in powerpc e500 kvm for my project . And the instruction can modify any of the 32 gpr's . So i'm resuming the guest using RESUME_GUEST_NV Flag so that all the gpr's can be updated .

Were they saved in the first place? What trap type did you enter on -- is it listed in NEED_INST_MASK? What kernel version?

Any reason not to use the existing MMIO emulation mechanisms?

-Scott

#2 lore raw
In reply to Aashish Mittal
Quoted 9 lines · On Sat, 9 Jul 2011 02:54:21 +0530 Aashish Mittal <[email protected]>…

Hi Scot
I'm working on kvm version 2.6.39 . So my project requires that i put a trace on a page in booke architecture (i.e removing the read and write privileges of that page) which causes all the instructions that try to read or write to this page to trap under DATA_STORAGE exit where i'm emulating them. Also the same problem appears when i try to use the existing MMIO mechnism since it resumes with the flag RESUME_HOST_NV . And iam saving the register using kvmppc_set_gpr(vcpu,register # ) and the DATA_STORAGE exit is listed in NEED_ESR_MASK .

You'll need to add DATA_STORAGE to NEED_INST_MASK -- or just invalidate the TLB entry rather than clear read/write, so you take a DTLB miss instead.

-Scott

#3 lore raw
In reply to Aashish Mittal
Quoted 9 lines · Scott Wood <scottwood <at> freescale.com> writes:

On Fri, 8 Jul 2011 20:33:18 +0000
Aashish Mittal <aashish.mittal4u <at> gmail.com> wrote:

Were they saved in the first place? What trap type did you enter on -- is it listed in NEED_INST_MASK? What kernel version?

Any reason not to use the existing MMIO emulation mechanisms?

-Scott

Hi Scot

I'm working on kvm version 2.6.39 . So my project requires that i put a trace on a page in booke architecture (i.e removing the read and write privileges of that page) which causes all the instructions that try to read or write to this page to trap under DATA_STORAGE exit where i'm emulating them. Also the same problem appears when i try to use the existing MMIO mechnism since it resumes with the flag RESUME_HOST_NV . And iam saving the register using kvmppc_set_gpr(vcpu,register # ) and the DATA_STORAGE exit is listed in NEED_ESR_MASK

#4 lore raw
In reply to Aashish Mittal
Quoted 17 lines · Aashish Mittal
Quoted 9 lines · Scott Wood <scottwood <at> freescale.com> writes:

On Fri, 8 Jul 2011 20:33:18 +0000
Aashish Mittal <aashish.mittal4u <at> gmail.com> wrote:

Were they saved in the first place? What trap type did you enter on -- is it listed in NEED_INST_MASK? What kernel version?

Any reason not to use the existing MMIO emulation mechanisms?

-Scott

Hi Scot

Quoted 8 lines

I'm working on kvm version 2.6.39 . So my project requires that i put a trace on a page in booke architecture (i.e removing the read and write privileges of that page) which causes all the instructions that try to read or write to this page to trap under DATA_STORAGE exit where i'm emulating them. Also the same problem appears when i try to use the existing MMIO mechnism since it resumes with the flag RESUME_HOST_NV . And iam saving the register using kvmppc_set_gpr(vcpu,register # ) and the DATA_STORAGE exit is listed in NEED_ESR_MASK

Just do everything in user space: Map two memory regions that exclude your page from the map and handle all reads+writes in user space by reading the registers out there. It'll be slightly slower, but give you an easy trace.

Alex