comparison m68k_core.c @ 654:98927f1b005b

Fix some issues with 68K instruction retranslation
author Michael Pavone <pavone@retrodev.com>
date Thu, 01 Jan 2015 17:31:59 -0800
parents a18e3923481e
children 7f1b5570b2a1
comparison
equal deleted inserted replaced
653:a18e3923481e 654:98927f1b005b
759 } 759 }
760 uint16_t *encoded, *next; 760 uint16_t *encoded, *next;
761 do { 761 do {
762 if (opts->address_log) { 762 if (opts->address_log) {
763 fprintf(opts->address_log, "%X\n", address); 763 fprintf(opts->address_log, "%X\n", address);
764 fflush(opts->address_log);
764 } 765 }
765 do { 766 do {
766 encoded = get_native_pointer(address, (void **)context->mem_pointers, &opts->gen); 767 encoded = get_native_pointer(address, (void **)context->mem_pointers, &opts->gen);
767 if (!encoded) { 768 if (!encoded) {
768 translate_out_of_bounds(code); 769 translate_out_of_bounds(code);
811 m68kinst instbuf; 812 m68kinst instbuf;
812 after = m68k_decode(inst, &instbuf, orig); 813 after = m68k_decode(inst, &instbuf, orig);
813 if (orig_size != MAX_NATIVE_SIZE) { 814 if (orig_size != MAX_NATIVE_SIZE) {
814 deferred_addr * orig_deferred = opts->gen.deferred; 815 deferred_addr * orig_deferred = opts->gen.deferred;
815 816
816 //make sure the beginning of the code for an instruction is contiguous 817 //make sure we have enough code space for the max size instruction
817 check_code_prologue(code); 818 check_alloc_code(code, MAX_NATIVE_SIZE);
818 code_ptr native_start = code->cur; 819 code_ptr native_start = code->cur;
819 translate_m68k(opts, &instbuf); 820 translate_m68k(opts, &instbuf);
820 code_ptr native_end = code->cur; 821 code_ptr native_end = code->cur;
821 uint8_t is_terminal = m68k_is_terminal(&instbuf); 822 /*uint8_t is_terminal = m68k_is_terminal(&instbuf);
822 if ((native_end - native_start) <= orig_size) { 823 if ((native_end - native_start) <= orig_size) {
823 code_ptr native_next; 824 code_ptr native_next;
824 if (!is_terminal) { 825 if (!is_terminal) {
825 native_next = get_native_address(context->native_code_map, orig + (after-inst)*2); 826 native_next = get_native_address(context->native_code_map, orig + (after-inst)*2);
826 } 827 }
827 if (is_terminal || (native_next && ((native_next == orig_start + orig_size) || (orig_size - (native_end - native_start)) > 5))) { 828 if (is_terminal || (native_next && ((native_next == orig_start + orig_size) || (orig_size - (native_end - native_start)) > 5))) {
829 printf("Using original location: %p\n", orig_code.cur);
828 remove_deferred_until(&opts->gen.deferred, orig_deferred); 830 remove_deferred_until(&opts->gen.deferred, orig_deferred);
829 code_info tmp; 831 code_info tmp;
830 tmp.cur = code->cur; 832 tmp.cur = code->cur;
831 tmp.last = code->last; 833 tmp.last = code->last;
832 code->cur = orig_code.cur; 834 code->cur = orig_code.cur;
839 nop_fill_or_jmp_next(&orig_code, orig_start + orig_size, native_next); 841 nop_fill_or_jmp_next(&orig_code, orig_start + orig_size, native_next);
840 } 842 }
841 m68k_handle_deferred(context); 843 m68k_handle_deferred(context);
842 return orig_start; 844 return orig_start;
843 } 845 }
844 } 846 }*/
845 847
846 map_native_address(context, instbuf.address, native_start, (after-inst)*2, MAX_NATIVE_SIZE); 848 map_native_address(context, instbuf.address, native_start, (after-inst)*2, MAX_NATIVE_SIZE);
847 849
848 jmp(&orig_code, native_start); 850 jmp(&orig_code, native_start);
849 if (!m68k_is_terminal(&instbuf)) { 851 if (!m68k_is_terminal(&instbuf)) {
858 code->cur = native_start + MAX_NATIVE_SIZE; 860 code->cur = native_start + MAX_NATIVE_SIZE;
859 } 861 }
860 m68k_handle_deferred(context); 862 m68k_handle_deferred(context);
861 return native_start; 863 return native_start;
862 } else { 864 } else {
863 code_info tmp; 865 code_info tmp = *code;
864 tmp.cur = code->cur; 866 *code = orig_code;
865 tmp.last = code->last;
866 code->cur = orig_code.cur;
867 code->last = orig_code.last;
868 translate_m68k(opts, &instbuf); 867 translate_m68k(opts, &instbuf);
868 orig_code = *code;
869 *code = tmp;
869 if (!m68k_is_terminal(&instbuf)) { 870 if (!m68k_is_terminal(&instbuf)) {
870 jmp(code, get_native_address_trans(context, orig + (after-inst)*2)); 871 jmp(&orig_code, get_native_address_trans(context, orig + (after-inst)*2));
871 } 872 }
872 code->cur = tmp.cur;
873 code->last = tmp.last;
874 m68k_handle_deferred(context); 873 m68k_handle_deferred(context);
875 return orig_start; 874 return orig_start;
876 } 875 }
877 } 876 }
878 877