| | 911 | int getpctest(int n) |
|---|
| | 912 | { |
|---|
| | 913 | int i=0; |
|---|
| | 914 | struct emu *e = emu_new(); |
|---|
| | 915 | struct emu_cpu *cpu = emu_cpu_get(e); |
|---|
| | 916 | struct emu_memory *mem = emu_memory_get(e); |
|---|
| | 917 | struct emu_env_w32 *env = emu_env_w32_new(e); |
|---|
| | 918 | |
|---|
| | 919 | |
|---|
| | 920 | if (env == 0) |
|---|
| | 921 | { |
|---|
| | 922 | printf("%s \n", emu_strerror(e)); |
|---|
| | 923 | printf("%s \n", strerror(emu_errno(e))); |
|---|
| | 924 | return -1; |
|---|
| | 925 | } |
|---|
| | 926 | |
|---|
| | 927 | /* uint32_t x; |
|---|
| | 928 | for (x=0x7c800000;x<0x7c902400;x++) |
|---|
| | 929 | { |
|---|
| | 930 | uint8_t b; |
|---|
| | 931 | emu_memory_read_byte(mem,x,&b); |
|---|
| | 932 | printf("%02x ",b); |
|---|
| | 933 | if (x % 16 == 0) |
|---|
| | 934 | { |
|---|
| | 935 | printf("\n"); |
|---|
| | 936 | } |
|---|
| | 937 | } |
|---|
| | 938 | return 0; |
|---|
| | 939 | */ |
|---|
| | 940 | |
|---|
| | 941 | |
|---|
| | 942 | for (i=0;i<sizeof(tests)/sizeof(struct instr_test);i++) |
|---|
| | 943 | { |
|---|
| | 944 | if ( n != -1 && i != n ) |
|---|
| | 945 | continue; |
|---|
| | 946 | |
|---|
| | 947 | uint32_t offset; |
|---|
| | 948 | for (offset=0; offset<tests[i].codesize;offset++) |
|---|
| | 949 | { |
|---|
| | 950 | |
|---|
| | 951 | if ( emu_getpc_check(e, (uint8_t *)tests[i].code, tests[i].codesize, offset) == 1) |
|---|
| | 952 | { |
|---|
| | 953 | int failed = 0; |
|---|
| | 954 | |
|---|
| | 955 | |
|---|
| | 956 | printf("testing (#%d) '%s' \t", i, tests[i].instr); |
|---|
| | 957 | int j=0; |
|---|
| | 958 | |
|---|
| | 959 | /* set the registers to the initial values */ |
|---|
| | 960 | for ( j=0;j<8;j++ ) |
|---|
| | 961 | { |
|---|
| | 962 | emu_cpu_reg32_set(cpu,j ,tests[i].in_state.reg[j]); |
|---|
| | 963 | } |
|---|
| | 964 | |
|---|
| | 965 | |
|---|
| | 966 | /* set the flags */ |
|---|
| | 967 | emu_cpu_eflags_set(cpu,tests[i].in_state.eflags); |
|---|
| | 968 | |
|---|
| | 969 | |
|---|
| | 970 | /* write the code to the offset */ |
|---|
| | 971 | int static_offset = CODE_OFFSET; |
|---|
| | 972 | for ( j = 0; j < tests[i].codesize; j++ ) |
|---|
| | 973 | { |
|---|
| | 974 | emu_memory_write_byte(mem, static_offset+j, tests[i].code[j]); |
|---|
| | 975 | } |
|---|
| | 976 | |
|---|
| | 977 | |
|---|
| | 978 | |
|---|
| | 979 | /* set eip to the code */ |
|---|
| | 980 | emu_cpu_eip_set(emu_cpu_get(e), static_offset); |
|---|
| | 981 | |
|---|
| | 982 | /* run the code */ |
|---|
| | 983 | if (opts.verbose == 1 ) |
|---|
| | 984 | { |
|---|
| | 985 | emu_log_level_set(emu_logging_get(e),EMU_LOG_DEBUG); |
|---|
| | 986 | emu_cpu_debug_print(cpu); |
|---|
| | 987 | emu_log_level_set(emu_logging_get(e),EMU_LOG_NONE); |
|---|
| | 988 | } |
|---|
| | 989 | |
|---|
| | 990 | int ret; //= emu_cpu_run(emu_cpu_get(e)); |
|---|
| | 991 | |
|---|
| | 992 | for (j=0;j<opts.steps;j++) |
|---|
| | 993 | { |
|---|
| | 994 | |
|---|
| | 995 | if (opts.verbose == 1) |
|---|
| | 996 | { |
|---|
| | 997 | emu_log_level_set(emu_logging_get(e),EMU_LOG_DEBUG); |
|---|
| | 998 | emu_cpu_debug_print(cpu); |
|---|
| | 999 | emu_log_level_set(emu_logging_get(e),EMU_LOG_NONE); |
|---|
| | 1000 | } |
|---|
| | 1001 | |
|---|
| | 1002 | |
|---|
| | 1003 | ret = emu_env_w32_eip_check(env); |
|---|
| | 1004 | if (ret == 1) |
|---|
| | 1005 | continue; |
|---|
| | 1006 | else if (ret == 0) |
|---|
| | 1007 | ret = emu_cpu_parse(emu_cpu_get(e)); |
|---|
| | 1008 | |
|---|
| | 1009 | |
|---|
| | 1010 | |
|---|
| | 1011 | if (ret != -1) |
|---|
| | 1012 | { |
|---|
| | 1013 | ret = emu_cpu_step(emu_cpu_get(e)); |
|---|
| | 1014 | } |
|---|
| | 1015 | |
|---|
| | 1016 | if ( ret == -1 ) |
|---|
| | 1017 | { |
|---|
| | 1018 | printf("cpu error %s\n", emu_strerror(e)); |
|---|
| | 1019 | break; |
|---|
| | 1020 | } |
|---|
| | 1021 | |
|---|
| | 1022 | |
|---|
| | 1023 | |
|---|
| | 1024 | printf("\n"); |
|---|
| | 1025 | } |
|---|
| | 1026 | |
|---|
| | 1027 | printf("stepcount %i\n",j); |
|---|
| | 1028 | |
|---|
| | 1029 | |
|---|
| | 1030 | if (opts.verbose == 1) |
|---|
| | 1031 | { |
|---|
| | 1032 | emu_log_level_set(emu_logging_get(e),EMU_LOG_DEBUG); |
|---|
| | 1033 | emu_cpu_debug_print(cpu); |
|---|
| | 1034 | emu_log_level_set(emu_logging_get(e),EMU_LOG_NONE); |
|---|
| | 1035 | } |
|---|
| | 1036 | |
|---|
| | 1037 | |
|---|
| | 1038 | /* check the registers for the exptected values */ |
|---|
| | 1039 | |
|---|
| | 1040 | for ( j=0;j<8;j++ ) |
|---|
| | 1041 | { |
|---|
| | 1042 | if ( emu_cpu_reg32_get(cpu, j) == tests[i].out_state.reg[j] ) |
|---|
| | 1043 | { |
|---|
| | 1044 | if (opts.verbose == 1) |
|---|
| | 1045 | printf("\t %s "SUCCESS"\n",regm[j]); |
|---|
| | 1046 | } |
|---|
| | 1047 | else |
|---|
| | 1048 | { |
|---|
| | 1049 | printf("\t %s "FAILED" got 0x%08x expected 0x%08x\n",regm[j],emu_cpu_reg32_get(cpu, j),tests[i].out_state.reg[j]); |
|---|
| | 1050 | failed = 1; |
|---|
| | 1051 | } |
|---|
| | 1052 | } |
|---|
| | 1053 | |
|---|
| | 1054 | |
|---|
| | 1055 | /* check the memory for expected values */ |
|---|
| | 1056 | uint32_t value; |
|---|
| | 1057 | |
|---|
| | 1058 | if ( tests[i].out_state.mem_state[0] != 0 || tests[i].out_state.mem_state[1] != 0) |
|---|
| | 1059 | { |
|---|
| | 1060 | if ( emu_memory_read_dword(mem,tests[i].out_state.mem_state[0],&value) == 0 ) |
|---|
| | 1061 | { |
|---|
| | 1062 | if ( value == tests[i].out_state.mem_state[1] ) |
|---|
| | 1063 | { |
|---|
| | 1064 | if (opts.verbose == 1) |
|---|
| | 1065 | printf("\t memory "SUCCESS" 0x%08x = 0x%08x\n",tests[i].out_state.mem_state[0], tests[i].out_state.mem_state[1]); |
|---|
| | 1066 | } |
|---|
| | 1067 | else |
|---|
| | 1068 | { |
|---|
| | 1069 | printf("\t memory "FAILED" at 0x%08x got 0x%08x expected 0x%08x\n",tests[i].out_state.mem_state[0],value, tests[i].out_state.mem_state[1]); |
|---|
| | 1070 | failed = 1; |
|---|
| | 1071 | } |
|---|
| | 1072 | |
|---|
| | 1073 | } |
|---|
| | 1074 | else |
|---|
| | 1075 | { |
|---|
| | 1076 | printf("\tmemory "FAILED" emu says: '%s' when accessing %08x\n", strerror(emu_errno(e)),tests[i].out_state.mem_state[0]); |
|---|
| | 1077 | failed = 1; |
|---|
| | 1078 | } |
|---|
| | 1079 | |
|---|
| | 1080 | } |
|---|
| | 1081 | |
|---|
| | 1082 | /* check the cpu flags for expected values */ |
|---|
| | 1083 | if ( tests[i].out_state.eflags != emu_cpu_eflags_get(cpu) ) |
|---|
| | 1084 | { |
|---|
| | 1085 | printf("\t flags "FAILED" got %08x expected %08x\n",emu_cpu_eflags_get(cpu),tests[i].out_state.eflags); |
|---|
| | 1086 | for (j=0;j<32;j++) |
|---|
| | 1087 | { |
|---|
| | 1088 | uint32_t f = emu_cpu_eflags_get(cpu); |
|---|
| | 1089 | if ( (tests[i].out_state.eflags & (1 << j)) != (f & (1 <<j))) |
|---|
| | 1090 | printf("\t flag %s (bit %i) failed, expected %i is %i\n",flags[j], j, |
|---|
| | 1091 | (tests[i].out_state.eflags & (1 << j)), |
|---|
| | 1092 | (f & (1 <<j))); |
|---|
| | 1093 | } |
|---|
| | 1094 | |
|---|
| | 1095 | failed = 1; |
|---|
| | 1096 | } |
|---|
| | 1097 | else |
|---|
| | 1098 | { |
|---|
| | 1099 | if (opts.verbose == 1) |
|---|
| | 1100 | printf("\t flags "SUCCESS"\n"); |
|---|
| | 1101 | } |
|---|
| | 1102 | |
|---|
| | 1103 | |
|---|
| | 1104 | if ( tests[i].out_state.eip != 0 && tests[i].out_state.eip != emu_cpu_eip_get(cpu) ) |
|---|
| | 1105 | { |
|---|
| | 1106 | printf("\t %s "FAILED" got 0x%08x expected 0x%08x\n", "eip", emu_cpu_eip_get(cpu), tests[i].out_state.eip); |
|---|
| | 1107 | failed = 1; |
|---|
| | 1108 | } |
|---|
| | 1109 | |
|---|
| | 1110 | |
|---|
| | 1111 | /* bail out on *any* error */ |
|---|
| | 1112 | if (failed == 0) |
|---|
| | 1113 | { |
|---|
| | 1114 | printf(SUCCESS"\n"); |
|---|
| | 1115 | } |
|---|
| | 1116 | else |
|---|
| | 1117 | { |
|---|
| | 1118 | return -1; |
|---|
| | 1119 | } |
|---|
| | 1120 | |
|---|
| | 1121 | |
|---|
| | 1122 | } |
|---|
| | 1123 | } |
|---|
| | 1124 | |
|---|
| | 1125 | } |
|---|
| | 1126 | emu_free(e); |
|---|
| | 1127 | return 0; |
|---|
| | 1128 | } |
|---|
| | 1129 | |
|---|