target/mips: Report unimplemented cache() operations
v2 cover target/mips: Report unimplemented cache() operations
Few patches to improve the handling of the 'cache' opcode.
I'm not sure why helper_cache() is generated for user-only mode.
v1 was:
https://www.mail-archive.com/[email protected]/msg727959.html
Supersedes: <[email protected]>
Philippe Mathieu-Daudé (3):
target/mips/op_helper: Convert multiple if() to switch case target/mips/op_helper: Document Invalidate/Writeback opcodes as no-op target/mips/op_helper: Log unimplemented cache opcode
target/mips/op_helper.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-)
Signature · 1 line
2.21.3
RFC PATCH v2 1/3 target/mips/op_helper: Convert multiple if() to switch case
The cache operation is encoded in bits [20:18] of the instruction. The 'op' argument of helper_cache() contains the bits [20:16]. Extract the 3 bits and parse them using a switch case. This allow us to handle multiple cache types (the cache type is encoded in bits [17:16]).
Previously the if() block was only checking the D-Cache (Primary Data or Unified Primary). Now we also handle the I-Cache (Primary Instruction), S-Cache (Secondary) and T-Cache (Terciary).
--- target/mips/op_helper.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
target/mips/op_helper.c +9 -2
@@ -1574,15 +1574,22 @@ void helper_msa_st_d(CPUMIPSState *env, uint32_t wd,void helper_cache (CPUMIPSState *env,target_ulong addr,uint32_t op) {#ifndef CONFIG_USER_ONLY +uint32_t cache_operation =extract32 (op,2 ,3 );target_ulong index = addr &0x1fffffff ; -if (op ==9 ) { + +switch (cache_operation) { +case 0b010 :/* Index Store Tag */ memory_region_dispatch_write (env->itc_tag, index, env->CP0_TagLo,MO_64 ,MEMTXATTRS_UNSPECIFIED ); - }else if (op ==5 ) { +break ; +case 0b001 :/* Index Load Tag */ memory_region_dispatch_read (env->itc_tag, index, &env->CP0_TagLo,MO_64 ,MEMTXATTRS_UNSPECIFIED ); +break ; +default : +break ; }#endif }
Signature · 1 line
2.21.3
Re: [RFC PATCH v2 1/3] target/mips/op_helper: Convert multiple if() to switch case
Quoted 6 lines · Philippe Mathieu-Daudé
The cache operation is encoded in bits [20:18] of the instruction. The 'op' argument of
helper_cache()contains the bits [20:16]. Extract the 3 bits and parse them using a switch case. This allow us to handle multiple cache types (the cache type is encoded in bits [17:16]).
Quoted 6 lines
Previously the
if()block was only checking the D-Cache (Primary Data or Unified Primary). Now we also handle the I-Cache (Primary Instruction), S-Cache (Secondary) and T-Cache (Terciary).Reported-by Jiaxun Yang <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Thanks~
Quoted 33 lines
--- target/mips/op_helper.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)target/mips/op_helper.c +9
-2@@ -1574,15 +1574,22 @@ void helper_msa_st_d(CPUMIPSState *env, uint32_t wd,void helper_cache (CPUMIPSState *env,target_ulong addr,uint32_t op) {#ifndef CONFIG_USER_ONLY +uint32_t cache_operation =extract32 (op,2 ,3 );target_ulong index = addr &0x1fffffff ; -if (op ==9 ) { + +switch (cache_operation) { +case 0b010 :/* Index Store Tag */ memory_region_dispatch_write (env->itc_tag, index, env->CP0_TagLo,MO_64 ,MEMTXATTRS_UNSPECIFIED ); - }else if (op ==5 ) { +break ; +case 0b001 :/* Index Load Tag */ memory_region_dispatch_read (env->itc_tag, index, &env->CP0_TagLo,MO_64 ,MEMTXATTRS_UNSPECIFIED ); +break ; +default : +break ; }#endif }
RFC PATCH v2 2/3 target/mips/op_helper: Document Invalidate/Writeback opcodes as no-op
In reply to Philippe Mathieu-DaudéQEMU does not model caches, so there is not much to do with the Invalidate/Writeback opcodes. Make it explicit adding a comment.
--- target/mips/op_helper.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
target/mips/op_helper.c +7 -4
@@ -1578,16 +1578,19 @@ void helper_cache(CPUMIPSState *env, target_ulong addr, uint32_t op)target_ulong index = addr &0x1fffffff ;switch (cache_operation) { -case 0b010 : -/* Index Store Tag */ +case 0b010 :/* Index Store Tag */ memory_region_dispatch_write (env->itc_tag, index, env->CP0_TagLo,MO_64 ,MEMTXATTRS_UNSPECIFIED );break ; -case 0b001 : -/* Index Load Tag */ +case 0b001 :/* Index Load Tag */ memory_region_dispatch_read (env->itc_tag, index, &env->CP0_TagLo,MO_64 ,MEMTXATTRS_UNSPECIFIED );break ; +case 0b000 :/* Index Invalidate */ +case 0b100 :/* Hit Invalidate */ +case 0b110 :/* Hit Writeback */ +/* no-op */ +break ;default :break ; }
Signature · 1 line
2.21.3
Re: [RFC PATCH v2 2/3] target/mips/op_helper: Document Invalidate/Writeback opcodes as no-op
target/mips/op_helper.c void helper_cache(CPUMIPSState *env, target_ulong addr, uint32_t op) · line 1588
Quoted 13 lines · Philippe Mathieu-Daudé
switch (cache_operation) {target/mips/op_helper.c +2
-4-case 0b010 : -/* Index Store Tag */ +case 0b010 :/* Index Store Tag */ memory_region_dispatch_write (env->itc_tag, index, env->CP0_TagLo,MO_64 ,MEMTXATTRS_UNSPECIFIED );break ; -case 0b001 : -/* Index Load Tag */ +case 0b001 :/* Index Load Tag */ memory_region_dispatch_read (env->itc_tag, index, &env->CP0_TagLo,MO_64 ,MEMTXATTRS_UNSPECIFIED );break ;
Merge these lines back to patch 1. With that, both 1/ and 2/,
r~
Re: [RFC PATCH v2 2/3] target/mips/op_helper: Document Invalidate/Writeback opcodes as no-op
In reply to Philippe Mathieu-DaudéQuoted 5 lines · Philippe Mathieu-Daudé
QEMU does not model caches, so there is not much to do with the Invalidate/Writeback opcodes. Make it explicit adding a comment.
Suggested-by Jiaxun Yang <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Thanks~
Quoted 32 lines
--- target/mips/op_helper.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)target/mips/op_helper.c +7
-4@@ -1578,16 +1578,19 @@ void helper_cache(CPUMIPSState *env, target_ulong addr, uint32_t op)target_ulong index = addr &0x1fffffff ;switch (cache_operation) { -case 0b010 : -/* Index Store Tag */ +case 0b010 :/* Index Store Tag */ memory_region_dispatch_write (env->itc_tag, index, env->CP0_TagLo,MO_64 ,MEMTXATTRS_UNSPECIFIED );break ; -case 0b001 : -/* Index Load Tag */ +case 0b001 :/* Index Load Tag */ memory_region_dispatch_read (env->itc_tag, index, &env->CP0_TagLo,MO_64 ,MEMTXATTRS_UNSPECIFIED );break ; +case 0b000 :/* Index Invalidate */ +case 0b100 :/* Hit Invalidate */ +case 0b110 :/* Hit Writeback */ +/* no-op */ +break ;default :break ; }
RFC PATCH v2 3/3 target/mips/op_helper: Log unimplemented cache opcode
In reply to Philippe Mathieu-DaudéIn case the guest uses a cache opcode we are not expecting, log it to give us a chance to notice it, in case we should actually do something.
--- target/mips/op_helper.c | 9 +++++++++ 1 file changed, 9 insertions(+)
target/mips/op_helper.c +9 -0
@@ -1574,6 +1574,13 @@ void helper_msa_st_d(CPUMIPSState *env, uint32_t wd,void helper_cache (CPUMIPSState *env,target_ulong addr,uint32_t op) {#ifndef CONFIG_USER_ONLY +static const char *type_name[] = { +"Primary Instruction" , +"Primary Data or Unified Primary" , +"Tertiary" , +"Secondary" + }; +uint32_t cache_type =extract32 (op,0 ,2 );uint32_t cache_operation =extract32 (op,2 ,3 );target_ulong index = addr &0x1fffffff ;
@@ -1592,6 +1599,8 @@ void helper_cache(CPUMIPSState *env, target_ulong addr, uint32_t op)/* no-op */ break ;default : +qemu_log_mask (LOG_UNIMP ,"cache operation:%u (type: %s cache)\n" , + cache_operation, type_name[cache_type]); break; }#endif
Signature · 1 line
2.21.3
Re: [RFC PATCH v2 3/3] target/mips/op_helper: Log unimplemented cache opcode
Quoted 2 lines · Philippe Mathieu-Daudé
#ifndef
CONFIG_USER_ONLY
+ static const char *type_name[] = {
const char * const
Otherwise,
r~
Quoted 4 lines · Philippe Mathieu-Daudé
Few patches to improve the handling of the 'cache' opcode.
I'm not sure why
helper_cache()is generated for user-only mode.
Quoted 8 lines
v1 was:
https://www.mail-archive.com/[email protected]/msg727959.html
Supersedes: <[email protected]>Philippe Mathieu-Daudé (3):
target/mips/op_helper: Convert multipleif()to switch case target/mips/op_helper: Document Invalidate/Writeback opcodes as no-op target/mips/op_helper: Log unimplemented cache opcode
Thanks, added to mips-next (addressing Richard comments).