risu: refactor and reduce CPU-specific code
cover risu: refactor and reduce CPU-specific code
This patchset refactors the risu C code to reduce the significant amount of duplicated and duplicated-but-not-quite-the-same code in the per-CPU files.
I've compile tested this for all architectures, but I'm not in a position to do runtime tests for non-ARM (my attempt to use the ppc64le risu under QEMU gives mismatch errors even without these patches, and the m68k risu makes QEMU crash, presumably because our m68k support isn't complete yet). So I wasn't quite prepared to just push it straight out to master the way I've done with previous changes I've been making.
Nikunj, Laurent: if you have time to test this patchset to confirm that it hasn't broken anything for you that would be great. If not, no problem; I'll probably push it to master in a week or so and we can sort any issues with it out later as separate patches.
You can find a git branch with these changes at
https://git.linaro.org/people/peter.maydell/risu-dev.git cpu-refactor
(nb that's not the official risu upstream repo, but a different one on the same server that I'm using for development/testing).
My motivation for all this, incidentally, is that I wanted to have a go at resurrecting the x86 backend as a test case for how we should support variable-length instruction sets. I got distracted by how much duplicate code we were dealing with both in risugen and in risu itself...
thanks
-- PMM
Peter Maydell (9):
Drop the weird modification of a ucontext in the ppc reginfo_is_eq() Abstract out getting and setting parameter register
Make get_risuop() a formal part of the CPU interface ppc64le, m68k: Make reginfo_dump() API match arm, aarch64
m68k: Drop unused ucontext_t* argument to reginfo_is_eq() Make reginfo_{init,is_eq,dump,dump_mismatch} official per-CPU API Move send_register_info() to reginfo.c
Move recv_and_compare_register_info() and report_match_status() to
reginfo.c
Tidy up #include lines
Makefile | 4 +- reginfo.c | 151 ++++++++++++++++++++++++++++++++++++++++++++++ risu.h | 43 ++++++++++++- risu_aarch64.c | 152 +++------------------------------------------- risu_arm.c | 159 ++++--------------------------------------------- risu_m68k.c | 136 +++--------------------------------------- risu_ppc64le.c | 136 +++--------------------------------------- risu_reginfo_aarch64.h | 12 ---- risu_reginfo_arm.h | 12 ---- risu_reginfo_m68k.c | 23 +++---- risu_reginfo_m68k.h | 12 ---- risu_reginfo_ppc64le.c | 59 ++++++++---------- risu_reginfo_ppc64le.h | 12 ---- 13 files changed, 271 insertions(+), 640 deletions(-) create mode 100644 reginfo.c
Signature · 1 line
2.7.4
PATCH 1/9 Drop the weird modification of a ucontext in the ppc reginfo_is_eq()
From: Peter Maydell <[email protected]>
The PPC reginfo_is_eq() has some weird code which tries to modify a ucontext_t in the middle of comparing the two registers. I don't understand this, but this is definitely not the right place to do anything like this. Drop the weird code.
--- risu_ppc64le.c | 4 ++-- risu_reginfo_ppc64le.c | 10 +--------- risu_reginfo_ppc64le.h | 2 +- 3 files changed, 4 insertions(+), 12 deletions(-)
risu_ppc64le.c +2 -2
@@ -89,7 +89,7 @@ int recv_and_compare_register_info(int sock, void *uc)if (recv_data_pkt (sock, &apprentice_ri,sizeof (apprentice_ri))) { packet_mismatch =1 ; resp =2 ; - }else if (!reginfo_is_eq (&master_ri, &apprentice_ri, uc)) { + }else if (!reginfo_is_eq (&master_ri, &apprentice_ri)) { resp =2 ; }else if (op ==OP_TESTEND ) {
@@ -134,7 +134,7 @@ int report_match_status(void)fprintf (stderr,"master reginfo:\n" );reginfo_dump (&master_ri,0 ); } -if (!reginfo_is_eq (&master_ri, &apprentice_ri,NULL )) { +if (!reginfo_is_eq (&master_ri, &apprentice_ri)) {fprintf (stderr,"mismatch on regs!\n" ); resp =1 ; }
risu_reginfo_ppc64le.c +1 -9
@@ -50,7 +50,7 @@ void reginfo_init(struct reginfo *ri, ucontext_t *uc) }/* reginfo_is_eq: compare the reginfo structs, returns nonzero if equal */ -int reginfo_is_eq (struct reginfo *m,struct reginfo *a,ucontext_t *uc) +int reginfo_is_eq (struct reginfo *m,struct reginfo *a) {int i;for (i =0 ; i <32 ; i++) {
@@ -86,14 +86,6 @@ int reginfo_is_eq(struct reginfo *m, struct reginfo *a, ucontext_t *uc) m->vrregs.vrregs[i][1] != a->vrregs.vrregs[i][1] || m->vrregs.vrregs[i][2] != a->vrregs.vrregs[i][2] || m->vrregs.vrregs[i][3] != a->vrregs.vrregs[i][3]) { - - if (uc != NULL && (m->gregs[CCR] & 0x10)) { - uc->uc_mcontext.v_regs->vrregs[i][0 ] = a->vrregs.vrregs[i][0 ]; - uc->uc_mcontext.v_regs->vrregs[i][1 ] = a->vrregs.vrregs[i][1 ]; - uc->uc_mcontext.v_regs->vrregs[i][2 ] = a->vrregs.vrregs[i][2 ]; - uc->uc_mcontext.v_regs->vrregs[i][3 ] = a->vrregs.vrregs[i][3 ]; -return 1 ; - }return 0 ; } }
risu_reginfo_ppc64le.h +1 -1
@@ -29,7 +29,7 @@ struct reginfovoid reginfo_init (struct reginfo *ri,ucontext_t *uc);/* return 1 if structs are equal, 0 otherwise. */ -int reginfo_is_eq (struct reginfo *r1,struct reginfo *r2,ucontext_t *uc); +int reginfo_is_eq (struct reginfo *r1,struct reginfo *r2);/* print reginfo state to a stream */ void reginfo_dump (struct reginfo *ri,int is_master);
Signature · 1 line
2.7.4
PATCH 2/9 Abstract out getting and setting parameter register
In reply to Peter MaydellFrom: Peter Maydell <[email protected]>
The SETMEMBLOCK operation takes a parameter in a register, and GETMEMBLOCK returns a result in a register. Abstract these out into functions provided by the backend, so we can use common code for send_register_info() and recv_and_compare_register_info().
--- risu.h | 11 +++++++++++ risu_aarch64.c | 19 +++++++++++++------ risu_arm.c | 20 ++++++++++++++------ risu_m68k.c | 19 +++++++++++++------ risu_ppc64le.c | 19 +++++++++++++------ 5 files changed, 64 insertions(+), 24 deletions(-)
risu.h +11 -0
@@ -37,6 +37,8 @@ extern int test_fp_exc;/* The memory block should be this long */ #define MEMBLOCKLEN 8192 +struct reginfo ; +/* Interface provided by CPU-specific code: */ /* Send the register information from the struct ucontext down the socket.
@@ -63,4 +65,13 @@ int report_match_status(void);*/ void advance_pc (void *uc); +/* Set the parameter register in a ucontext_t to the specified value. +* (32-bit targets can ignore high 32 bits.) +* vuc is a ucontext_t* cast to void*. +*/ +void set_ucontext_paramreg (void *vuc,uint64_t value); + +/* Return the value of the parameter register from a reginfo. */ +uint64_t get_reginfo_paramreg (struct reginfo *ri); +#endif /* RISU_H */
risu_aarch64.c +13 -6
@@ -30,10 +30,15 @@ void advance_pc(void *vuc) uc->uc_mcontext.pc +=4 ; } -static void set_x0 (void *vuc,uint64_t x0) +void set_ucontext_paramreg (void *vuc,uint64_t value) {ucontext_t *uc = vuc; - uc->uc_mcontext.regs[0 ] = x0; + uc->uc_mcontext.regs[0 ] = value; +} + +uint64_t get_reginfo_paramreg (struct reginfo *ri) +{ +return ri->regs[0 ]; }static int get_risuop (uint32_t insn)
@@ -63,10 +68,11 @@ int send_register_info(int sock, void *uc)*/ return send_data_pkt (sock, &ri,sizeof (ri));case OP_SETMEMBLOCK : - memblock = (void *)ri.regs[0 ]; + memblock = (void *)get_reginfo_paramreg (&ri);break ;case OP_GETMEMBLOCK : -set_x0 (uc, ri.regs[0 ] + (uintptr_t )memblock); +set_ucontext_paramreg (uc, +get_reginfo_paramreg (&ri) + (uintptr_t )memblock);break ;case OP_COMPAREMEM :return send_data_pkt (sock, memblock,MEMBLOCKLEN );
@@ -111,10 +117,11 @@ int recv_and_compare_register_info(int sock, void *uc)send_response_byte (sock, resp);break ;case OP_SETMEMBLOCK : - memblock = (void *)master_ri.regs[0 ]; + memblock = (void *)get_reginfo_paramreg (&master_ri);break ;case OP_GETMEMBLOCK : -set_x0 (uc, master_ri.regs[0 ] + (uintptr_t )memblock); +set_ucontext_paramreg (uc,get_reginfo_paramreg (&master_ri) + + (uintptr_t )memblock);break ;case OP_COMPAREMEM : mem_used =1 ;
risu_arm.c +14 -6
@@ -52,10 +52,16 @@ void advance_pc(void *vuc) uc->uc_mcontext.arm_pc +=insnsize (uc); } -static void set_r0 (void *vuc,uint32_t r0) + +void set_ucontext_paramreg (void *vuc,uint64_t value) {ucontext_t *uc = vuc; - uc->uc_mcontext.arm_r0 = r0; + uc->uc_mcontext.arm_r0 = value; +} + +uint64_t get_reginfo_paramreg (struct reginfo *ri) +{ +return ri->gpreg[0 ]; }static int get_risuop (uint32_t insn,int isz)
@@ -87,10 +93,11 @@ int send_register_info(int sock, void *uc)*/ return send_data_pkt (sock, &ri,sizeof (ri));case OP_SETMEMBLOCK : - memblock = (void *)ri.gpreg[0 ]; + memblock = (void *)(uintptr_t )get_reginfo_paramreg (&ri);break ;case OP_GETMEMBLOCK : -set_r0 (uc, ri.gpreg[0 ] + (uintptr_t )memblock); +set_ucontext_paramreg (uc, +get_reginfo_paramreg (&ri) + (uintptr_t )memblock);break ;case OP_COMPAREMEM :return send_data_pkt (sock, memblock,MEMBLOCKLEN );
@@ -139,10 +146,11 @@ int recv_and_compare_register_info(int sock, void *uc)send_response_byte (sock, resp);break ;case OP_SETMEMBLOCK : - memblock = (void *)master_ri.gpreg[0 ]; + memblock = (void *)(uintptr_t )get_reginfo_paramreg (&master_ri);break ;case OP_GETMEMBLOCK : -set_r0 (uc, master_ri.gpreg[0 ] + (uintptr_t )memblock); +set_ucontext_paramreg (uc,get_reginfo_paramreg (&master_ri) + + (uintptr_t )memblock);break ;case OP_COMPAREMEM : mem_used =1 ;
risu_m68k.c +13 -6
@@ -25,10 +25,15 @@ void advance_pc(void *vuc) uc->uc_mcontext.gregs[R_PC ] +=4 ; } -void set_a0 (void *vuc,uint32_t a0) +void set_ucontext_paramreg (void *vuc,uint64_t value) {ucontext_t *uc = vuc; - uc->uc_mcontext.gregs[R_A0 ] = a0; + uc->uc_mcontext.gregs[R_A0 ] = value; +} + +uint64_t get_reginfo_paramreg (struct reginfo *ri) +{ +return ri->gregs[R_A0 ]; }static int get_risuop (uint32_t insn)
@@ -53,10 +58,11 @@ int send_register_info(int sock, void *uc)default :return send_data_pkt (sock, &ri,sizeof (ri));case OP_SETMEMBLOCK : - memblock = (void *)ri.gregs[R_A0 ]; + memblock = (void *)(uintptr_t )get_reginfo_paramreg (&ri);break ;case OP_GETMEMBLOCK : -set_a0 (uc, ri.gregs[R_A0 ] + (uintptr_t )memblock); +set_ucontext_paramreg (uc, +get_reginfo_paramreg (&ri) + (uintptr_t )memblock);break ;case OP_COMPAREMEM :return send_data_pkt (sock, memblock,MEMBLOCKLEN );
@@ -93,10 +99,11 @@ int recv_and_compare_register_info(int sock, void *uc)send_response_byte (sock, resp);break ;case OP_SETMEMBLOCK : - memblock = (void *)master_ri.gregs[R_A0 ]; + memblock = (void *)(uintptr_t )get_reginfo_paramreg (&master_ri);break ;case OP_GETMEMBLOCK : -set_a0 (uc, master_ri.gregs[R_A0 ] + (uintptr_t )memblock); +set_ucontext_paramreg (uc,get_reginfo_paramreg (&master_ri) + + (uintptr_t )memblock);break ;case OP_COMPAREMEM : mem_used =1 ;
risu_ppc64le.c +13 -6
@@ -30,10 +30,15 @@ void advance_pc(void *vuc) uc->uc_mcontext.regs->nip +=4 ; } -void set_x0 (void *vuc,uint64_t x0) +void set_ucontext_paramreg (void *vuc,uint64_t value) {ucontext_t *uc = vuc; - uc->uc_mcontext.gp_regs[0 ] = x0; + uc->uc_mcontext.gp_regs[0 ] = value; +} + +uint64_t get_reginfo_paramreg (struct reginfo *ri) +{ +return ri->gregs[0 ]; }static int get_risuop (uint32_t insn)
@@ -58,10 +63,11 @@ int send_register_info(int sock, void *uc)default :return send_data_pkt (sock, &ri,sizeof (ri));case OP_SETMEMBLOCK : - memblock = (void *)ri.gregs[0 ]; + memblock = (void *)get_reginfo_paramreg (&ri);break ;case OP_GETMEMBLOCK : -set_x0 (uc, ri.gregs[0 ] + (uintptr_t )memblock); +set_ucontext_paramreg (uc, +get_reginfo_paramreg (&ri) + (uintptr_t )memblock);break ;case OP_COMPAREMEM :return send_data_pkt (sock, memblock,MEMBLOCKLEN );
@@ -98,10 +104,11 @@ int recv_and_compare_register_info(int sock, void *uc)send_response_byte (sock, resp);break ;case OP_SETMEMBLOCK : - memblock = (void *)master_ri.gregs[0 ]; + memblock = (void *)get_reginfo_paramreg (&master_ri);break ;case OP_GETMEMBLOCK : -set_x0 (uc, master_ri.gregs[0 ] + (uintptr_t )memblock); +set_ucontext_paramreg (uc,get_reginfo_paramreg (&master_ri) + + (uintptr_t )memblock);break ;case OP_COMPAREMEM : mem_used =1 ;
Signature · 1 line
2.7.4
PATCH 3/9 Make get_risuop() a formal part of the CPU interface
In reply to Peter MaydellFrom: Peter Maydell <[email protected]>
Make get_risuop() a formal part of the CPU interface rather than just a de-facto common routine.
--- risu.h | 5 +++++ risu_aarch64.c | 7 ++++--- risu_arm.c | 9 +++++---- risu_m68k.c | 7 ++++--- risu_ppc64le.c | 7 ++++--- 5 files changed, 22 insertions(+), 13 deletions(-)
risu.h +5 -0
@@ -74,4 +74,9 @@ void set_ucontext_paramreg(void *vuc, uint64_t value);/* Return the value of the parameter register from a reginfo. */ uint64_t get_reginfo_paramreg (struct reginfo *ri); +/* Return the risu operation number we have been asked to do, +* or -1 if this was a SIGILL for a non-risuop insn. +*/ +int get_risuop (struct reginfo *ri); +#endif /* RISU_H */
risu_aarch64.c +4 -3
@@ -41,11 +41,12 @@ uint64_t get_reginfo_paramreg(struct reginfo *ri)return ri->regs[0 ]; } -static int get_risuop (uint32_t insn) +int get_risuop (struct reginfo *ri) {/* Return the risuop we have been asked to do * (or -1 if this was a SIGILL for a non-risuop insn) */ +uint32_t insn = ri->faulting_insn;uint32_t op = insn &0xf ;uint32_t key = insn & ~0xf ;uint32_t risukey =0x00005af0 ;
@@ -57,7 +58,7 @@ int send_register_info(int sock, void *uc)struct reginfo ri;int op;reginfo_init (&ri, uc); - op =get_risuop (ri.faulting_insn); + op =get_risuop (&ri);switch (op) {case OP_COMPARE :
@@ -94,7 +95,7 @@ int recv_and_compare_register_info(int sock, void *uc)int resp =0 , op;reginfo_init (&master_ri, uc); - op =get_risuop (master_ri.faulting_insn); + op =get_risuop (&master_ri);switch (op) {case OP_COMPARE :
risu_arm.c +5 -4
@@ -64,24 +64,25 @@ uint64_t get_reginfo_paramreg(struct reginfo *ri)return ri->gpreg[0 ]; } -static int get_risuop (uint32_t insn,int isz) +int get_risuop (struct reginfo *ri) {/* Return the risuop we have been asked to do * (or -1 if this was a SIGILL for a non-risuop insn) */ +uint32_t insn = ri->faulting_insn; +int isz = ri->faulting_insn_size;uint32_t op = insn &0xf ;uint32_t key = insn & ~0xf ;uint32_t risukey = (isz ==2 ) ?0xdee0 :0xe7fe5af0 ;return (key != risukey) ?-1 : op; } -int send_register_info (int sock,void *uc) {struct reginfo ri;int op;reginfo_init (&ri, uc); - op =get_risuop (ri.faulting_insn, ri.faulting_insn_size); + op =get_risuop (&ri);switch (op) {
@@ -119,7 +120,7 @@ int recv_and_compare_register_info(int sock, void *uc)int resp =0 , op;reginfo_init (&master_ri, uc); - op =get_risuop (master_ri.faulting_insn, master_ri.faulting_insn_size); + op =get_risuop (&master_ri);switch (op) {
risu_m68k.c +4 -3
@@ -36,8 +36,9 @@ uint64_t get_reginfo_paramreg(struct reginfo *ri)return ri->gregs[R_A0 ]; } -static int get_risuop (uint32_t insn) +int get_risuop (struct reginfo *ri) { +uint32_t insn = ri->faulting_insn;uint32_t op = insn &0xf ;uint32_t key = insn & ~0xf ;uint32_t risukey =0x4afc7000 ;
@@ -50,7 +51,7 @@ int send_register_info(int sock, void *uc)int op;reginfo_init (&ri, uc); - op =get_risuop (ri.faulting_insn); + op =get_risuop (&ri);switch (op) {case OP_COMPARE :
@@ -81,7 +82,7 @@ int recv_and_compare_register_info(int sock, void *uc)int op;reginfo_init (&master_ri, uc); - op =get_risuop (master_ri.faulting_insn); + op =get_risuop (&master_ri);switch (op) {case OP_COMPARE :
risu_ppc64le.c +4 -3
@@ -41,8 +41,9 @@ uint64_t get_reginfo_paramreg(struct reginfo *ri)return ri->gregs[0 ]; } -static int get_risuop (uint32_t insn) +int get_risuop (struct reginfo *ri) { +uint32_t insn = ri->faulting_insn;uint32_t op = insn &0xf ;uint32_t key = insn & ~0xf ;uint32_t risukey =0x00005af0 ;
@@ -55,7 +56,7 @@ int send_register_info(int sock, void *uc)int op;reginfo_init (&ri, uc); - op =get_risuop (ri.faulting_insn); + op =get_risuop (&ri);switch (op) {case OP_COMPARE :
@@ -86,7 +87,7 @@ int recv_and_compare_register_info(int sock, void *uc)int op;reginfo_init (&master_ri, uc); - op =get_risuop (master_ri.faulting_insn); + op =get_risuop (&master_ri);switch (op) {case OP_COMPARE :
Signature · 1 line
2.7.4
PATCH 4/9 ppc64le, m68k: Make reginfo_dump() API match arm, aarch64
In reply to Peter MaydellMake the reginfo_dump() API for ppc64le and m68k match the one used for ARM and AArch64, which takes a FILE*, doesn't have a flag for is_master, and returns a success indication.
--- risu_m68k.c | 6 +++--- risu_ppc64le.c | 6 +++--- risu_reginfo_m68k.c | 21 +++++++++++---------- risu_reginfo_m68k.h | 4 ++-- risu_reginfo_ppc64le.c | 49 +++++++++++++++++++++++++------------------------ risu_reginfo_ppc64le.h | 4 ++-- 6 files changed, 46 insertions(+), 44 deletions(-)
risu_m68k.c +3 -3
@@ -135,7 +135,7 @@ int report_match_status(void)fprintf (stderr,"packet mismatch (probably disagreement " "about UNDEF on load/store)\n" );fprintf (stderr,"master reginfo:\n" ); -reginfo_dump (&master_ri,0 ); +reginfo_dump (&master_ri, stderr); }if (!reginfo_is_eq (&master_ri, &apprentice_ri,NULL )) {fprintf (stderr,"mismatch on regs!\n" );
@@ -151,10 +151,10 @@ int report_match_status(void) }fprintf (stderr,"master reginfo:\n" ); -reginfo_dump (&master_ri,1 ); +reginfo_dump (&master_ri, stderr);fprintf (stderr,"apprentice reginfo:\n" ); -reginfo_dump (&apprentice_ri,0 ); +reginfo_dump (&apprentice_ri, stderr);reginfo_dump_mismatch (&master_ri, &apprentice_ri, stderr);return resp;
risu_ppc64le.c +3 -3
@@ -140,7 +140,7 @@ int report_match_status(void)fprintf (stderr,"packet mismatch (probably disagreement " "about UNDEF on load/store)\n" );fprintf (stderr,"master reginfo:\n" ); -reginfo_dump (&master_ri,0 ); +reginfo_dump (&master_ri, stderr); }if (!reginfo_is_eq (&master_ri, &apprentice_ri)) {fprintf (stderr,"mismatch on regs!\n" );
@@ -156,10 +156,10 @@ int report_match_status(void) }fprintf (stderr,"master reginfo:\n" ); -reginfo_dump (&master_ri,1 ); +reginfo_dump (&master_ri, stderr);fprintf (stderr,"apprentice reginfo:\n" ); -reginfo_dump (&apprentice_ri,0 ); +reginfo_dump (&apprentice_ri, stderr);reginfo_dump_mismatch (&master_ri, &apprentice_ri, stderr);return resp;
risu_reginfo_m68k.c +11 -10
@@ -75,29 +75,30 @@ int reginfo_is_eq(struct reginfo *m, struct reginfo *a, ucontext_t *uc) }/* reginfo_dump: print state to a stream, returns nonzero on success */ -void reginfo_dump (struct reginfo *ri,int is_master) +int reginfo_dump (struct reginfo *ri,FILE *f) {int i; -if (is_master) { -fprintf (stderr," pc \e[1;101;37m0x%08x\e[0m\n" , - ri->pc); - } -fprintf (stderr,"\tPC: %08x\n" , ri->gregs[R_PC ]); -fprintf (stderr,"\tPS: %04x\n" , ri->gregs[R_PS ]); +fprintf (f," pc \e[1;101;37m0x%08x\e[0m\n" , + ri->pc); + +fprintf (f,"\tPC: %08x\n" , ri->gregs[R_PC ]); +fprintf (f,"\tPS: %04x\n" , ri->gregs[R_PS ]);for (i =0 ; i <8 ; i++) { -fprintf (stderr,"\tD%d: %8x\tA%d: %8x\n" , i, ri->gregs[i], +fprintf (f,"\tD%d: %8x\tA%d: %8x\n" , i, ri->gregs[i], i, ri->gregs[i +8 ]); }for (i =0 ; i <8 ; i++) { -fprintf (stderr,"\tFP%d: %08x %08x %08x\n" , i, +fprintf (f,"\tFP%d: %08x %08x %08x\n" , i, ri->fpregs.f_fpregs[i][0 ], ri->fpregs.f_fpregs[i][1 ], ri->fpregs.f_fpregs[i][2 ]); } -fprintf (stderr,"\n" ); +fprintf (f,"\n" ); + +return !ferror (f); }int reginfo_dump_mismatch (struct reginfo *m,struct reginfo *a,FILE *f)
risu_reginfo_m68k.h +2 -2
@@ -23,8 +23,8 @@ void reginfo_init(struct reginfo *ri, ucontext_t *uc);/* return 1 if structs are equal, 0 otherwise. */ int reginfo_is_eq (struct reginfo *r1,struct reginfo *r2,ucontext_t *uc); -/* print reginfo state to a stream */ -void reginfo_dump (struct reginfo *ri,int is_master); +/* print reginfo state to a stream, returns 1 on success, 0 on failure */ +int reginfo_dump (struct reginfo *ri,FILE *f);/* reginfo_dump_mismatch: print mismatch details to a stream, ret nonzero=ok */ int reginfo_dump_mismatch (struct reginfo *m,struct reginfo *a,FILE *f);
risu_reginfo_ppc64le.c +25 -24
71 lines not on this page · raw message
risu_reginfo_ppc64le.h +2 -2
@@ -31,8 +31,8 @@ void reginfo_init(struct reginfo *ri, ucontext_t *uc);/* return 1 if structs are equal, 0 otherwise. */ int reginfo_is_eq (struct reginfo *r1,struct reginfo *r2); -/* print reginfo state to a stream */ -void reginfo_dump (struct reginfo *ri,int is_master); +/* print reginfo state to a stream, returns 1 on success, 0 on failure */ +int reginfo_dump (struct reginfo *ri,FILE *f);/* reginfo_dump_mismatch: print mismatch details to a stream, ret nonzero=ok */ int reginfo_dump_mismatch (struct reginfo *m,struct reginfo *a,FILE *f);
Signature · 1 line
2.7.4
PATCH 5/9 m68k: Drop unused ucontext_t* argument to reginfo_is_eq()
In reply to Peter MaydellDrop the ucontext*t argument to reginfo_is_eq(); we don't use it.
--- risu_m68k.c | 4 ++-- risu_reginfo_m68k.c | 2 +- risu_reginfo_m68k.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-)
risu_m68k.c +2 -2
@@ -91,7 +91,7 @@ int recv_and_compare_register_info(int sock, void *uc)if (recv_data_pkt (sock, &apprentice_ri,sizeof (apprentice_ri))) { packet_mismatch =1 ; resp =2 ; - }else if (!reginfo_is_eq (&master_ri, &apprentice_ri, uc)) { + }else if (!reginfo_is_eq (&master_ri, &apprentice_ri)) { resp =2 ; }else if (op ==OP_TESTEND ) {
@@ -137,7 +137,7 @@ int report_match_status(void)fprintf (stderr,"master reginfo:\n" );reginfo_dump (&master_ri, stderr); } -if (!reginfo_is_eq (&master_ri, &apprentice_ri,NULL )) { +if (!reginfo_is_eq (&master_ri, &apprentice_ri)) {fprintf (stderr,"mismatch on regs!\n" ); resp =1 ; }
risu_reginfo_m68k.c +1 -1
@@ -38,7 +38,7 @@ void reginfo_init(struct reginfo *ri, ucontext_t *uc) }/* reginfo_is_eq: compare the reginfo structs, returns nonzero if equal */ -int reginfo_is_eq (struct reginfo *m,struct reginfo *a,ucontext_t *uc) +int reginfo_is_eq (struct reginfo *m,struct reginfo *a) {int i;
risu_reginfo_m68k.h +1 -1
@@ -21,7 +21,7 @@ struct reginfovoid reginfo_init (struct reginfo *ri,ucontext_t *uc);/* return 1 if structs are equal, 0 otherwise. */ -int reginfo_is_eq (struct reginfo *r1,struct reginfo *r2,ucontext_t *uc); +int reginfo_is_eq (struct reginfo *r1,struct reginfo *r2);/* print reginfo state to a stream, returns 1 on success, 0 on failure */ int reginfo_dump (struct reginfo *ri,FILE *f);
Signature · 1 line
2.7.4
PATCH 6/9 Make reginfo_{init, is_eq, dump, dump_mismatch} official per-CPU API
In reply to Peter MaydellAll CPUs now implement reginfo_{init,is_eq,dump,dump_mismatch} with the same API and semantics. Make this official by moving the prototypes into risu.h.
--- risu.h | 13 +++++++++++++ risu_reginfo_aarch64.h | 12 ------------ risu_reginfo_arm.h | 12 ------------ risu_reginfo_m68k.h | 12 ------------ risu_reginfo_ppc64le.h | 12 ------------ 5 files changed, 13 insertions(+), 48 deletions(-)
risu.h +13 -0
@@ -14,6 +14,7 @@#include <inttypes.h> #include <stdint.h> +#include <ucontext.h> /* Socket related routines */ int master_connect (int port);
@@ -79,4 +80,16 @@ uint64_t get_reginfo_paramreg(struct reginfo *ri);*/ int get_risuop (struct reginfo *ri); +/* initialize structure from a ucontext */ +void reginfo_init (struct reginfo *ri,ucontext_t *uc); + +/* return 1 if structs are equal, 0 otherwise. */ +int reginfo_is_eq (struct reginfo *r1,struct reginfo *r2); + +/* print reginfo state to a stream, returns 1 on success, 0 on failure */ +int reginfo_dump (struct reginfo *ri,FILE *f); + +/* reginfo_dump_mismatch: print mismatch details to a stream, ret nonzero=ok */ +int reginfo_dump_mismatch (struct reginfo *m,struct reginfo *a,FILE *f); +#endif /* RISU_H */
risu_reginfo_aarch64.h +0 -12
@@ -28,16 +28,4 @@ struct reginfo __uint128_t vregs[32]; }; -/* initialize structure from a ucontext */ -void reginfo_init (struct reginfo *ri,ucontext_t *uc); - -/* return 1 if structs are equal, 0 otherwise. */ -int reginfo_is_eq (struct reginfo *r1,struct reginfo *r2); - -/* print reginfo state to a stream, returns 1 on success, 0 on failure */ -int reginfo_dump (struct reginfo *ri,FILE *f); - -/* reginfo_dump_mismatch: print mismatch details to a stream, ret nonzero=ok */ -int reginfo_dump_mismatch (struct reginfo *m,struct reginfo *a,FILE *f); -#endif /* RISU_REGINFO_AARCH64_H */
risu_reginfo_arm.h +0 -12
@@ -23,16 +23,4 @@ struct reginfo uint32_t fpscr; }; -/* initialize a reginfo structure with data from uc */ -void reginfo_init (struct reginfo *ri,ucontext_t *uc); - -/* returns 1 if structs are equal, zero otherwise */ -int reginfo_is_eq (struct reginfo *r1,struct reginfo *r2); - -/* print struct values to a stream, return 0 on stream err, 1 on success */ -int reginfo_dump (struct reginfo *ri,FILE *f); - -/* print a detailed mismatch report, return 0 on stream err, 1 on success */ -int reginfo_dump_mismatch (struct reginfo *m,struct reginfo *a,FILE *f); -#endif /* RISU_REGINFO_ARM_H */
risu_reginfo_m68k.h +0 -12
@@ -17,16 +17,4 @@ struct reginfo fpregset_t fpregs; }; -/* initialize structure from a ucontext */ -void reginfo_init (struct reginfo *ri,ucontext_t *uc); - -/* return 1 if structs are equal, 0 otherwise. */ -int reginfo_is_eq (struct reginfo *r1,struct reginfo *r2); - -/* print reginfo state to a stream, returns 1 on success, 0 on failure */ -int reginfo_dump (struct reginfo *ri,FILE *f); - -/* reginfo_dump_mismatch: print mismatch details to a stream, ret nonzero=ok */ -int reginfo_dump_mismatch (struct reginfo *m,struct reginfo *a,FILE *f); -#endif /* RISU_REGINFO_M68K_H */
risu_reginfo_ppc64le.h +0 -12
@@ -25,16 +25,4 @@ struct reginfo vrregset_t vrregs; }; -/* initialize structure from a ucontext */ -void reginfo_init (struct reginfo *ri,ucontext_t *uc); - -/* return 1 if structs are equal, 0 otherwise. */ -int reginfo_is_eq (struct reginfo *r1,struct reginfo *r2); - -/* print reginfo state to a stream, returns 1 on success, 0 on failure */ -int reginfo_dump (struct reginfo *ri,FILE *f); - -/* reginfo_dump_mismatch: print mismatch details to a stream, ret nonzero=ok */ -int reginfo_dump_mismatch (struct reginfo *m,struct reginfo *a,FILE *f); -#endif /* RISU_REGINFO_PPC64LE_H */
Signature · 1 line
2.7.4
PATCH 7/9 Move send_register_info() to reginfo.c
In reply to Peter Maydellsend_register_info() is now essentially the same code for all target CPUs, so move it into reginfo.c rather than having duplicated code.
--- Makefile | 4 ++-- reginfo.c | 43 +++++++++++++++++++++++++++++++++++++++++++ risu.h | 13 ++++++++++++- risu_aarch64.c | 29 ----------------------------- risu_arm.c | 30 ------------------------------ risu_m68k.c | 27 --------------------------- risu_ppc64le.c | 27 --------------------------- 7 files changed, 57 insertions(+), 116 deletions(-) create mode 100644 reginfo.c
Makefile +2 -2
@@ -17,10 +17,10 @@ VPATH=$(SRCDIR) CFLAGS ?= -g -ALL_CFLAGS = -Wall -D_GNU_SOURCE $(CFLAGS) $(EXTRA_CFLAGS) +ALL_CFLAGS = -Wall -D_GNU_SOURCE -DARCH=$(ARCH) $(CFLAGS) $(EXTRA_CFLAGS) PROG=risu -SRCS=risu.c comms.c risu_$(ARCH).c risu_reginfo_$(ARCH).c +SRCS=risu.c comms.c reginfo.c risu_$(ARCH).c risu_reginfo_$(ARCH).c HDRS=risu.h BINS=test_$(ARCH).bin
reginfo.c new file +43 -0
43 lines not on this page · raw message
risu.h +12 -1
@@ -16,6 +16,15 @@#include <stdint.h> #include <ucontext.h> +/* GCC computed include to pull in the correct risu_reginfo_*.h for +* the architecture. +*/ +#define REGINFO_HEADER2 (X ) #X +#define REGINFO_HEADER1 (ARCHNAME ) REGINFO_HEADER2(risu_reginfo_ ## ARCHNAME.h) +#define REGINFO_HEADER (ARCH ) REGINFO_HEADER1(ARCH) + +#include REGINFO_HEADER (ARCH ) +/* Socket related routines */ int master_connect (int port);int apprentice_connect (const char *hostname,int port);
@@ -40,7 +49,7 @@ extern int test_fp_exc;struct reginfo ; -/* Interface provided by CPU-specific code: */ +/* Functions operating on reginfo */ /* Send the register information from the struct ucontext down the socket. * Return the response code from the master.
@@ -48,6 +57,8 @@ struct reginfo;*/ int send_register_info (int sock,void *uc); +/* Interface provided by CPU-specific code: */ +/* Read register info from the socket and compare it with that from the * ucontext. Return 0 for match, 1 for end-of-test, 2 for mismatch. * NB: called from a signal handler.
risu_aarch64.c +0 -29
@@ -53,35 +53,6 @@ int get_risuop(struct reginfo *ri)return (key != risukey) ?-1 : op; } -int send_register_info (int sock,void *uc) -{ -struct reginfo ri; -int op; -reginfo_init (&ri, uc); - op =get_risuop (&ri); - -switch (op) { -case OP_COMPARE : -case OP_TESTEND : -default : -/* Do a simple register compare on (a) explicit request -* (b) end of test (c) a non-risuop UNDEF -*/ -return send_data_pkt (sock, &ri,sizeof (ri)); -case OP_SETMEMBLOCK : - memblock = (void *)get_reginfo_paramreg (&ri); -break ; -case OP_GETMEMBLOCK : -set_ucontext_paramreg (uc, -get_reginfo_paramreg (&ri) + (uintptr_t )memblock); -break ; -case OP_COMPAREMEM : -return send_data_pkt (sock, memblock,MEMBLOCKLEN ); -break ; - } -return 0 ; -} -/* Read register info from the socket and compare it with that from the * ucontext. Return 0 for match, 1 for end-of-test, 2 for mismatch. * NB: called from a signal handler.
risu_arm.c +0 -30
@@ -77,36 +77,6 @@ int get_risuop(struct reginfo *ri)return (key != risukey) ?-1 : op; } -int send_register_info (int sock,void *uc) -{ -struct reginfo ri; -int op; -reginfo_init (&ri, uc); - op =get_risuop (&ri); - -switch (op) - { -case OP_COMPARE : -case OP_TESTEND : -default : -/* Do a simple register compare on (a) explicit request -* (b) end of test (c) a non-risuop UNDEF -*/ -return send_data_pkt (sock, &ri,sizeof (ri)); -case OP_SETMEMBLOCK : - memblock = (void *)(uintptr_t )get_reginfo_paramreg (&ri); -break ; -case OP_GETMEMBLOCK : -set_ucontext_paramreg (uc, -get_reginfo_paramreg (&ri) + (uintptr_t )memblock); -break ; -case OP_COMPAREMEM : -return send_data_pkt (sock, memblock,MEMBLOCKLEN ); -break ; - } -return 0 ; -} -/* Read register info from the socket and compare it with that from the * ucontext. Return 0 for match, 1 for end-of-test, 2 for mismatch. * NB: called from a signal handler.
risu_m68k.c +0 -27
@@ -45,33 +45,6 @@ int get_risuop(struct reginfo *ri)return (key != risukey) ?-1 : op; } -int send_register_info (int sock,void *uc) -{ -struct reginfo ri; -int op; - -reginfo_init (&ri, uc); - op =get_risuop (&ri); - -switch (op) { -case OP_COMPARE : -case OP_TESTEND : -default : -return send_data_pkt (sock, &ri,sizeof (ri)); -case OP_SETMEMBLOCK : - memblock = (void *)(uintptr_t )get_reginfo_paramreg (&ri); -break ; -case OP_GETMEMBLOCK : -set_ucontext_paramreg (uc, -get_reginfo_paramreg (&ri) + (uintptr_t )memblock); -break ; -case OP_COMPAREMEM : -return send_data_pkt (sock, memblock,MEMBLOCKLEN ); -break ; - } -return 0 ; -} -/* Read register info from the socket and compare it with that from the * ucontext. Return 0 for match, 1 for end-of-test, 2 for mismatch. * NB: called from a signal handler.
risu_ppc64le.c +0 -27
@@ -50,33 +50,6 @@ int get_risuop(struct reginfo *ri)return (key != risukey) ?-1 : op; } -int send_register_info (int sock,void *uc) -{ -struct reginfo ri; -int op; - -reginfo_init (&ri, uc); - op =get_risuop (&ri); - -switch (op) { -case OP_COMPARE : -case OP_TESTEND : -default : -return send_data_pkt (sock, &ri,sizeof (ri)); -case OP_SETMEMBLOCK : - memblock = (void *)get_reginfo_paramreg (&ri); -break ; -case OP_GETMEMBLOCK : -set_ucontext_paramreg (uc, -get_reginfo_paramreg (&ri) + (uintptr_t )memblock); -break ; -case OP_COMPAREMEM : -return send_data_pkt (sock, memblock,MEMBLOCKLEN ); -break ; - } -return 0 ; -} -/* Read register info from the socket and compare it with that from the * ucontext. Return 0 for match, 1 for end-of-test, 2 for mismatch. * NB: called from a signal handler.
Signature · 1 line
2.7.4
PATCH 8/9 Move recv_and_compare_register_info() and report_match_status() to reginfo.c
In reply to Peter MaydellMove recv_and_compare_register_info() and report_match_status() to reginfo.c -- they are essentially the same for all targets so can be common code. The shared variables they use come with them.
--- reginfo.c | 108 +++++++++++++++++++++++++++++++++++++++++++++++++++++ risu.h | 4 +- risu_aarch64.c | 108 ----------------------------------------------------- risu_arm.c | 116 --------------------------------------------------------- risu_m68k.c | 94 ---------------------------------------------- risu_ppc64le.c | 94 ---------------------------------------------- 6 files changed, 110 insertions(+), 414 deletions(-)
reginfo.c +108 -0
@@ -10,9 +10,17 @@*****************************************************************************/ #include <stdio.h> +#include <string.h> #include "risu.h" +struct reginfo master_ri, apprentice_ri; + +uint8_t apprentice_memblock[MEMBLOCKLEN ]; + +static int mem_used =0 ; +static int packet_mismatch =0 ; +int send_register_info (int sock,void *uc) {struct reginfo ri;
@@ -41,3 +49,103 @@ int send_register_info(int sock, void *uc) }return 0 ; } + +/* Read register info from the socket and compare it with that from the +* ucontext. Return 0 for match, 1 for end-of-test, 2 for mismatch. +* NB: called from a signal handler. +* +* We don't have any kind of identifying info in the incoming data +* that says whether it is register or memory data, so if the two +* sides get out of sync then we will fail obscurely. +*/ +int recv_and_compare_register_info (int sock,void *uc) +{ +int resp =0 , op; + +reginfo_init (&master_ri, uc); + op =get_risuop (&master_ri); + +switch (op) { +case OP_COMPARE : +case OP_TESTEND : +default : +/* Do a simple register compare on (a) explicit request +* (b) end of test (c) a non-risuop UNDEF +*/ +if (recv_data_pkt (sock, &apprentice_ri,sizeof (apprentice_ri))) { + packet_mismatch =1 ; + resp =2 ; + + }else if (!reginfo_is_eq (&master_ri, &apprentice_ri)) { +/* register mismatch */ + resp =2 ; + + }else if (op ==OP_TESTEND ) { + resp =1 ; + } +send_response_byte (sock, resp); +break ; +case OP_SETMEMBLOCK : + memblock = (void *)(uintptr_t )get_reginfo_paramreg (&master_ri); +break ; +case OP_GETMEMBLOCK : +set_ucontext_paramreg (uc,get_reginfo_paramreg (&master_ri) + + (uintptr_t )memblock); +break ; +case OP_COMPAREMEM : + mem_used =1 ; +if (recv_data_pkt (sock, apprentice_memblock,MEMBLOCKLEN )) { + packet_mismatch =1 ; + resp =2 ; + }else if (memcmp (memblock, apprentice_memblock,MEMBLOCKLEN ) !=0 ) { +/* memory mismatch */ + resp =2 ; + } +send_response_byte (sock, resp); +break ; + } + +return resp; +} + +/* Print a useful report on the status of the last comparison +* done in recv_and_compare_register_info(). This is called on +* exit, so need not restrict itself to signal-safe functions. +* Should return 0 if it was a good match (ie end of test) +* and 1 for a mismatch. +*/ +int report_match_status (void ) +{ +int resp =0 ; +fprintf (stderr,"match status...\n" ); +if (packet_mismatch) { +fprintf (stderr,"packet mismatch (probably disagreement " +"about UNDEF on load/store)\n" ); +/* We don't have valid reginfo from the apprentice side +* so stop now rather than printing anything about it. +*/ +fprintf (stderr,"master reginfo:\n" ); +reginfo_dump (&master_ri, stderr); +return 1 ; + } +if (!reginfo_is_eq (&master_ri, &apprentice_ri)) { +fprintf (stderr,"mismatch on regs!\n" ); + resp =1 ; + } +if (mem_used &&memcmp (memblock, &apprentice_memblock,MEMBLOCKLEN ) !=0 ) { +fprintf (stderr,"mismatch on memory!\n" ); + resp =1 ; + } +if (!resp) { +fprintf (stderr,"match!\n" ); +return 0 ; + } + +fprintf (stderr,"master reginfo:\n" ); +reginfo_dump (&master_ri, stderr); +fprintf (stderr,"apprentice reginfo:\n" ); +reginfo_dump (&apprentice_ri, stderr); + +reginfo_dump_mismatch (&master_ri, &apprentice_ri, stderr); +return resp; +}
risu.h +2 -2
@@ -57,8 +57,6 @@ struct reginfo;*/ int send_register_info (int sock,void *uc); -/* Interface provided by CPU-specific code: */ -/* Read register info from the socket and compare it with that from the * ucontext. Return 0 for match, 1 for end-of-test, 2 for mismatch. * NB: called from a signal handler.
@@ -73,6 +71,8 @@ int recv_and_compare_register_info(int sock, void *uc);*/ int report_match_status (void ); +/* Interface provided by CPU-specific code: */ +/* Move the PC past this faulting insn by adjusting ucontext */ void advance_pc (void *uc);
risu_aarch64.c +0 -108
117 lines not on this page · raw message
risu_arm.c +0 -116
125 lines not on this page · raw message
risu_m68k.c +0 -94
103 lines not on this page · raw message
risu_ppc64le.c +0 -94
103 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH 9/9 Tidy up #include lines
In reply to Peter MaydellTidy up unnecessary #includes that risu.h provides.
--- risu.h | 1 + risu_aarch64.c | 5 ----- risu_m68k.c | 5 ----- risu_ppc64le.c | 5 ----- 4 files changed, 1 insertion(+), 15 deletions(-)
risu.h +1 -0
@@ -15,6 +15,7 @@#include <inttypes.h> #include <stdint.h> #include <ucontext.h> +#include <stdio.h> /* GCC computed include to pull in the correct risu_reginfo_*.h for * the architecture.
risu_aarch64.c +0 -5
@@ -10,12 +10,7 @@* based on Peter Maydell's risu_arm.c *****************************************************************************/ -#include <stdio.h> -#include <ucontext.h> -#include <string.h> -#include "risu.h" -#include "risu_reginfo_aarch64.h" void advance_pc (void *vuc) {
risu_m68k.c +0 -5
@@ -6,12 +6,7 @@* http://www.eclipse.org/legal/epl-v10.html ******************************************************************************/ -#include <stdio.h> -#include <ucontext.h> -#include <string.h> -#include "risu.h" -#include "risu_reginfo_m68k.h" void advance_pc (void *vuc) {
risu_ppc64le.c +0 -5
@@ -11,12 +11,7 @@* based on Peter Maydell's risu_arm.c *****************************************************************************/ -#include <stdio.h> -#include <ucontext.h> -#include <string.h> -#include "risu.h" -#include "risu_reginfo_ppc64le.h" void advance_pc (void *vuc) {
Signature · 1 line
2.7.4
Quoted 9 lines · Peter Maydell
This patchset refactors the risu C code to reduce the significant amount of duplicated and duplicated-but-not-quite-the-same code in the per-CPU files.
I've compile tested this for all architectures, but I'm not in a position to do runtime tests for non-ARM (my attempt to use the ppc64le risu under QEMU gives mismatch errors even without these patches, and the m68k risu makes QEMU crash, presumably because our m68k support isn't complete yet). So I wasn't quite prepared to just
Yes, the FPU part is missing.
Quoted 5 lines
push it straight out to master the way I've done with previous changes I've been making.
Nikunj, Laurent: if you have time to test this patchset to confirm that it hasn't broken anything for you that would be great.
for m68k
Quoted 4 lines
My motivation for all this, incidentally, is that I wanted to have a go at resurrecting the x86 backend as a test case for how we should support variable-length instruction sets.
I think m68k is needing that too.
Thanks,
Laurent
Quoted 6 lines · Laurent Vivier
Quoted 3 lines · Peter Maydell
My motivation for all this, incidentally, is that I wanted to have a go at resurrecting the x86 backend as a test case for how we should support variable-length instruction sets.
I think m68k is needing that too.
Yep; but I don't have an m68k to hand, whereas I do have x86-64 ;-)
thanks
-- PMM
Quoted 13 lines · Laurent Vivier
Quoted 9 lines · Peter Maydell
This patchset refactors the risu C code to reduce the significant amount of duplicated and duplicated-but-not-quite-the-same code in the per-CPU files.
I've compile tested this for all architectures, but I'm not in a position to do runtime tests for non-ARM (my attempt to use the ppc64le risu under QEMU gives mismatch errors even without these patches, and the m68k risu makes QEMU crash, presumably because our m68k support isn't complete yet). So I wasn't quite prepared to just
Yes, the FPU part is missing.
Quoted 8 lines
Quoted 5 lines
push it straight out to master the way I've done with previous changes I've been making.
Nikunj, Laurent: if you have time to test this patchset to confirm that it hasn't broken anything for you that would be great.
for m68k
Tested-by Laurent Vivier <[email protected]>
Thanks; I've gone ahead and pushed this series to risu master.
-- PMM