Mercurial > repos > blastem
comparison m68k_core.c @ 653:a18e3923481e
Remove some of the hard coded assumptions about the memory map from the CPU cores
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Thu, 01 Jan 2015 14:36:55 -0800 |
parents | 60a06c025103 |
children | 98927f1b005b |
comparison
equal
deleted
inserted
replaced
652:f822d9216968 | 653:a18e3923481e |
---|---|
752 void translate_m68k_stream(uint32_t address, m68k_context * context) | 752 void translate_m68k_stream(uint32_t address, m68k_context * context) |
753 { | 753 { |
754 m68kinst instbuf; | 754 m68kinst instbuf; |
755 m68k_options * opts = context->options; | 755 m68k_options * opts = context->options; |
756 code_info *code = &opts->gen.code; | 756 code_info *code = &opts->gen.code; |
757 address &= 0xFFFFFF; | |
758 if(get_native_address(opts->gen.native_code_map, address)) { | 757 if(get_native_address(opts->gen.native_code_map, address)) { |
759 return; | 758 return; |
760 } | 759 } |
761 char disbuf[1024]; | |
762 uint16_t *encoded, *next; | 760 uint16_t *encoded, *next; |
763 if ((address & 0xFFFFFF) < 0x400000) { | |
764 encoded = context->mem_pointers[0] + (address & 0xFFFFFF)/2; | |
765 } else if ((address & 0xFFFFFF) > 0xE00000) { | |
766 encoded = context->mem_pointers[1] + (address & 0xFFFF)/2; | |
767 } else { | |
768 printf("attempt to translate non-memory address: %X\n", address); | |
769 exit(1); | |
770 } | |
771 do { | 761 do { |
772 if (opts->address_log) { | 762 if (opts->address_log) { |
773 fprintf(opts->address_log, "%X\n", address); | 763 fprintf(opts->address_log, "%X\n", address); |
774 } | 764 } |
775 do { | 765 do { |
776 if (address >= 0x400000 && address < 0xE00000) { | 766 encoded = get_native_pointer(address, (void **)context->mem_pointers, &opts->gen); |
767 if (!encoded) { | |
777 translate_out_of_bounds(code); | 768 translate_out_of_bounds(code); |
778 break; | 769 break; |
779 } | 770 } |
780 code_ptr existing = get_native_address(opts->gen.native_code_map, address); | 771 code_ptr existing = get_native_address(opts->gen.native_code_map, address); |
781 if (existing) { | 772 if (existing) { |
786 if (instbuf.op == M68K_INVALID) { | 777 if (instbuf.op == M68K_INVALID) { |
787 instbuf.src.params.immed = *encoded; | 778 instbuf.src.params.immed = *encoded; |
788 } | 779 } |
789 uint16_t m68k_size = (next-encoded)*2; | 780 uint16_t m68k_size = (next-encoded)*2; |
790 address += m68k_size; | 781 address += m68k_size; |
791 encoded = next; | 782 //char disbuf[1024]; |
792 //m68k_disasm(&instbuf, disbuf); | 783 //m68k_disasm(&instbuf, disbuf); |
793 //printf("%X: %s\n", instbuf.address, disbuf); | 784 //printf("%X: %s\n", instbuf.address, disbuf); |
794 | 785 |
795 //make sure the beginning of the code for an instruction is contiguous | 786 //make sure the beginning of the code for an instruction is contiguous |
796 check_code_prologue(code); | 787 check_code_prologue(code); |
800 map_native_address(context, instbuf.address, start, m68k_size, after-start); | 791 map_native_address(context, instbuf.address, start, m68k_size, after-start); |
801 } while(!m68k_is_terminal(&instbuf)); | 792 } while(!m68k_is_terminal(&instbuf)); |
802 process_deferred(&opts->gen.deferred, context, (native_addr_func)get_native_from_context); | 793 process_deferred(&opts->gen.deferred, context, (native_addr_func)get_native_from_context); |
803 if (opts->gen.deferred) { | 794 if (opts->gen.deferred) { |
804 address = opts->gen.deferred->address; | 795 address = opts->gen.deferred->address; |
805 if ((address & 0xFFFFFF) < 0x400000) { | 796 } |
806 encoded = context->mem_pointers[0] + (address & 0xFFFFFF)/2; | 797 } while(opts->gen.deferred); |
807 } else if ((address & 0xFFFFFF) > 0xE00000) { | |
808 encoded = context->mem_pointers[1] + (address & 0xFFFF)/2; | |
809 } else { | |
810 printf("attempt to translate non-memory address: %X\n", address); | |
811 exit(1); | |
812 } | |
813 } else { | |
814 encoded = NULL; | |
815 } | |
816 } while(encoded != NULL); | |
817 } | 798 } |
818 | 799 |
819 void * m68k_retranslate_inst(uint32_t address, m68k_context * context) | 800 void * m68k_retranslate_inst(uint32_t address, m68k_context * context) |
820 { | 801 { |
821 m68k_options * opts = context->options; | 802 m68k_options * opts = context->options; |
824 code_ptr orig_start = get_native_address(context->native_code_map, address); | 805 code_ptr orig_start = get_native_address(context->native_code_map, address); |
825 uint32_t orig = address; | 806 uint32_t orig = address; |
826 code_info orig_code; | 807 code_info orig_code; |
827 orig_code.cur = orig_start; | 808 orig_code.cur = orig_start; |
828 orig_code.last = orig_start + orig_size + 5; | 809 orig_code.last = orig_start + orig_size + 5; |
829 address &= 0xFFFF; | 810 uint16_t *after, *inst = get_native_pointer(address, (void **)context->mem_pointers, &opts->gen); |
830 uint16_t *after, *inst = context->mem_pointers[1] + address/2; | |
831 m68kinst instbuf; | 811 m68kinst instbuf; |
832 after = m68k_decode(inst, &instbuf, orig); | 812 after = m68k_decode(inst, &instbuf, orig); |
833 if (orig_size != MAX_NATIVE_SIZE) { | 813 if (orig_size != MAX_NATIVE_SIZE) { |
834 deferred_addr * orig_deferred = opts->gen.deferred; | 814 deferred_addr * orig_deferred = opts->gen.deferred; |
835 | 815 |
908 } | 888 } |
909 | 889 |
910 void remove_breakpoint(m68k_context * context, uint32_t address) | 890 void remove_breakpoint(m68k_context * context, uint32_t address) |
911 { | 891 { |
912 code_ptr native = get_native_address(context->native_code_map, address); | 892 code_ptr native = get_native_address(context->native_code_map, address); |
913 check_cycles_int(context->options, address); | 893 check_cycles_int(&context->options->gen, address); |
914 } | 894 } |
915 | 895 |
916 void start_68k_context(m68k_context * context, uint32_t address) | 896 void start_68k_context(m68k_context * context, uint32_t address) |
917 { | 897 { |
918 code_ptr addr = get_native_address_trans(context, address); | 898 code_ptr addr = get_native_address_trans(context, address); |
920 options->start_context(addr, context); | 900 options->start_context(addr, context); |
921 } | 901 } |
922 | 902 |
923 void m68k_reset(m68k_context * context) | 903 void m68k_reset(m68k_context * context) |
924 { | 904 { |
925 //TODO: Make this actually use the normal read functions | 905 //TODO: Actually execute the M68K reset vector rather than simulating some of its behavior |
926 context->aregs[7] = context->mem_pointers[0][0] << 16 | context->mem_pointers[0][1]; | 906 uint16_t *reset_vec = get_native_pointer(0, (void **)context->mem_pointers, &context->options->gen); |
927 uint32_t address = context->mem_pointers[0][2] << 16 | context->mem_pointers[0][3]; | 907 context->aregs[7] = reset_vec[0] << 16 | reset_vec[1]; |
908 uint32_t address = reset_vec[2] << 16 | reset_vec[3]; | |
928 start_68k_context(context, address); | 909 start_68k_context(context, address); |
929 } | 910 } |
930 | 911 |
931 | 912 |
932 void init_68k_context(m68k_context * context, native_map_slot * native_code_map, void * opts) | 913 void init_68k_context(m68k_context * context, native_map_slot * native_code_map, void * opts) |