@@ -861,6 +861,74 @@ static void test_arm_mem_hook_read_write(void)
861
861
OK (uc_close (uc ));
862
862
}
863
863
864
+ typedef struct {
865
+ uint64_t v0 ;
866
+ uint64_t v1 ;
867
+ uint64_t size ;
868
+ uint64_t pc ;
869
+ } _last_cmp_info ;
870
+
871
+ static void _uc_hook_sub_cmp (uc_engine * uc , uint64_t address , uint64_t arg1 ,
872
+ uint64_t arg2 , uint32_t size ,
873
+ _last_cmp_info * user_data )
874
+ {
875
+ user_data -> pc = address ;
876
+ user_data -> size = size ;
877
+ user_data -> v0 = arg1 ;
878
+ user_data -> v1 = arg2 ;
879
+ }
880
+
881
+ static void test_arm_tcg_opcode_cmp (void )
882
+ {
883
+ uc_engine * uc ;
884
+ const char code [] = "\x04\x00\x9f\xe5" // ldr r0, [pc, #4]
885
+ "\x04\x10\x9f\xe5" // ldr r1, [pc, #4]
886
+ "\x01\x00\x50\xe1" // cmp r0, r1
887
+ "\x05\x00\x00\x00" // (5)
888
+ "\x03\x00\x00\x00" // (3)
889
+ ;
890
+
891
+ uc_common_setup (& uc , UC_ARCH_ARM , UC_MODE_ARM , code , sizeof (code ) - 1 ,
892
+ UC_CPU_ARM_CORTEX_A15 );
893
+
894
+ uc_hook hook ;
895
+ _last_cmp_info cmp_info = {0 };
896
+
897
+ OK (uc_hook_add (uc , & hook , UC_HOOK_TCG_OPCODE , (void * )_uc_hook_sub_cmp ,
898
+ (void * )& cmp_info , 1 , 0 , UC_TCG_OP_SUB , UC_TCG_OP_FLAG_CMP ));
899
+
900
+ OK (uc_emu_start (uc , code_start , code_start + sizeof (code ) - 1 , 0 , 3 ));
901
+ TEST_CHECK (cmp_info .v0 == 5 && cmp_info .v1 == 3 );
902
+ TEST_CHECK (cmp_info .pc == code_start );
903
+ TEST_CHECK (cmp_info .size == 32 );
904
+ }
905
+
906
+ static void test_arm_thumb_tcg_opcode_cmn (void )
907
+ {
908
+ uc_engine * uc ;
909
+ const char code [] = "\x01\x48" // ldr r0, [pc, #4]
910
+ "\x02\x49" // ldr r1, [pc, #8]
911
+ "\x00\xbf" // nop
912
+ "\xc8\x42" // cmn r0, r1
913
+ "\x05\x00\x00\x00" // (5)
914
+ "\x03\x00\x00\x00" // (3)
915
+ ;
916
+
917
+ uc_common_setup (& uc , UC_ARCH_ARM , UC_MODE_THUMB , code , sizeof (code ) - 1 ,
918
+ UC_CPU_ARM_CORTEX_A15 );
919
+
920
+ uc_hook hook ;
921
+ _last_cmp_info cmp_info = {0 };
922
+
923
+ OK (uc_hook_add (uc , & hook , UC_HOOK_TCG_OPCODE , (void * )_uc_hook_sub_cmp ,
924
+ (void * )& cmp_info , 1 , 0 , UC_TCG_OP_SUB , UC_TCG_OP_FLAG_CMP ));
925
+
926
+ OK (uc_emu_start (uc , code_start | 1 , code_start + sizeof (code ) - 1 , 0 , 4 ));
927
+ TEST_CHECK (cmp_info .v0 == 5 && cmp_info .v1 == 3 );
928
+ TEST_CHECK (cmp_info .pc == (code_start | 1 ));
929
+ TEST_CHECK (cmp_info .size == 32 );
930
+ }
931
+
864
932
TEST_LIST = {{"test_arm_nop" , test_arm_nop },
865
933
{"test_arm_thumb_sub" , test_arm_thumb_sub },
866
934
{"test_armeb_sub" , test_armeb_sub },
@@ -887,4 +955,6 @@ TEST_LIST = {{"test_arm_nop", test_arm_nop},
887
955
{"test_arm_thumb2" , test_arm_thumb2 },
888
956
{"test_armeb_be32_thumb2" , test_armeb_be32_thumb2 },
889
957
{"test_arm_mem_hook_read_write" , test_arm_mem_hook_read_write },
958
+ {"test_arm_tcg_opcode_cmp" , test_arm_tcg_opcode_cmp },
959
+ {"test_arm_thumb_tcg_opcode_cmn" , test_arm_thumb_tcg_opcode_cmn },
890
960
{NULL , NULL }};
0 commit comments