comparison m68k_core.c @ 2133:8554751f17b5

Remove use of get_native_pointer in 68K instruction decoding in preparation for word RAM interleaving
author Michael Pavone <pavone@retrodev.com>
date Thu, 17 Mar 2022 22:41:42 -0700
parents d59ace2d7a6a
children 01ad74197414
comparison
equal deleted inserted replaced
2132:7451f970ee66 2133:8554751f17b5
766 766
767 uint8_t m68k_is_terminal(m68kinst * inst) 767 uint8_t m68k_is_terminal(m68kinst * inst)
768 { 768 {
769 return inst->op == M68K_RTS || inst->op == M68K_RTE || inst->op == M68K_RTR || inst->op == M68K_JMP 769 return inst->op == M68K_RTS || inst->op == M68K_RTE || inst->op == M68K_RTR || inst->op == M68K_JMP
770 || inst->op == M68K_TRAP || inst->op == M68K_ILLEGAL || inst->op == M68K_INVALID 770 || inst->op == M68K_TRAP || inst->op == M68K_ILLEGAL || inst->op == M68K_INVALID
771 || inst->op == M68K_F_LINE_TRAP || inst->op == M68K_A_LINE_TRAP
771 || (inst->op == M68K_BCC && inst->extra.cond == COND_TRUE); 772 || (inst->op == M68K_BCC && inst->extra.cond == COND_TRUE);
772 } 773 }
773 774
774 static void m68k_handle_deferred(m68k_context * context) 775 static void m68k_handle_deferred(m68k_context * context)
775 { 776 {
1004 m68k_disasm(inst, disasm_buf); 1005 m68k_disasm(inst, disasm_buf);
1005 fatal_error("Stack offset is %X after %X: %s\n", opts->gen.code.stack_off, inst->address, disasm_buf); 1006 fatal_error("Stack offset is %X after %X: %s\n", opts->gen.code.stack_off, inst->address, disasm_buf);
1006 } 1007 }
1007 } 1008 }
1008 1009
1010 uint16_t m68k_instruction_fetch(uint32_t address, void *vcontext)
1011 {
1012 m68k_context *context = vcontext;
1013 return read_word(address, (void **)context->mem_pointers, &context->options->gen, context);
1014 }
1015
1009 void translate_m68k_stream(uint32_t address, m68k_context * context) 1016 void translate_m68k_stream(uint32_t address, m68k_context * context)
1010 { 1017 {
1011 m68kinst instbuf; 1018 m68kinst instbuf;
1012 m68k_options * opts = context->options; 1019 m68k_options * opts = context->options;
1013 code_info *code = &opts->gen.code; 1020 code_info *code = &opts->gen.code;
1014 if(get_native_address(opts, address)) { 1021 if(get_native_address(opts, address)) {
1015 return; 1022 return;
1016 } 1023 }
1017 uint16_t *encoded, *next; 1024 memmap_chunk const *starting_chunk = NULL;
1025 uint32_t next_address;
1018 do { 1026 do {
1019 if (opts->address_log) { 1027 if (opts->address_log) {
1020 fprintf(opts->address_log, "%X\n", address); 1028 fprintf(opts->address_log, "%X\n", address);
1021 fflush(opts->address_log); 1029 fflush(opts->address_log);
1022 } 1030 }
1023 do { 1031 do {
1024 encoded = get_native_pointer(address, (void **)context->mem_pointers, &opts->gen);
1025 if (!encoded) {
1026 code_ptr start = code->cur;
1027 translate_out_of_bounds(opts, address);
1028 code_ptr after = code->cur;
1029 map_native_address(context, address, start, 2, after-start);
1030 break;
1031 }
1032 code_ptr existing = get_native_address(opts, address); 1032 code_ptr existing = get_native_address(opts, address);
1033 if (existing) { 1033 if (existing) {
1034 jmp(code, existing); 1034 jmp(code, existing);
1035 break; 1035 break;
1036 } 1036 }
1037 next = m68k_decode(encoded, &instbuf, address); 1037 memmap_chunk const *chunk = find_map_chunk(address, &opts->gen, 0, NULL);
1038 if (instbuf.op == M68K_INVALID) { 1038 if (!starting_chunk) {
1039 instbuf.src.params.immed = *encoded; 1039 starting_chunk = chunk;
1040 } 1040 } else if (starting_chunk != chunk) {
1041 uint16_t m68k_size = (next-encoded)*2; 1041 if (chunk->flags & MMAP_CODE) {
1042 address += m68k_size; 1042 code_ptr start = code->cur;
1043 defer_translation(&opts->gen, address, opts->retrans_stub);
1044 code_ptr after = code->cur;
1045 map_native_address(context, address, start, 2, after-start);
1046 break;
1047 } else {
1048 starting_chunk = chunk;
1049 }
1050 }
1051 next_address = m68k_decode(m68k_instruction_fetch, context, &instbuf, address);
1052 uint16_t m68k_size = next_address - address;
1053 address = next_address;
1043 //char disbuf[1024]; 1054 //char disbuf[1024];
1044 //m68k_disasm(&instbuf, disbuf); 1055 //m68k_disasm(&instbuf, disbuf);
1045 //printf("%X: %s\n", instbuf.address, disbuf); 1056 //printf("%X: %s\n", instbuf.address, disbuf);
1046 1057
1047 //make sure the beginning of the code for an instruction is contiguous 1058 //make sure the beginning of the code for an instruction is contiguous
1064 code_info *code = &opts->gen.code; 1075 code_info *code = &opts->gen.code;
1065 uint8_t orig_size = get_native_inst_size(opts, address); 1076 uint8_t orig_size = get_native_inst_size(opts, address);
1066 code_ptr orig_start = get_native_address(context->options, address); 1077 code_ptr orig_start = get_native_address(context->options, address);
1067 uint32_t orig = address; 1078 uint32_t orig = address;
1068 code_info orig_code = {orig_start, orig_start + orig_size + 5, 0}; 1079 code_info orig_code = {orig_start, orig_start + orig_size + 5, 0};
1069 uint16_t *after, *inst = get_native_pointer(address, (void **)context->mem_pointers, &opts->gen);
1070 m68kinst instbuf; 1080 m68kinst instbuf;
1071 after = m68k_decode(inst, &instbuf, orig); 1081 uint32_t after_address = m68k_decode(m68k_instruction_fetch, context, &instbuf, orig);
1072 if (orig_size != MAX_NATIVE_SIZE) { 1082 if (orig_size != MAX_NATIVE_SIZE) {
1073 deferred_addr * orig_deferred = opts->gen.deferred; 1083 deferred_addr * orig_deferred = opts->gen.deferred;
1074 1084
1075 //make sure we have enough code space for the max size instruction 1085 //make sure we have enough code space for the max size instruction
1076 check_alloc_code(code, MAX_NATIVE_SIZE); 1086 check_alloc_code(code, MAX_NATIVE_SIZE);
1101 m68k_handle_deferred(context); 1111 m68k_handle_deferred(context);
1102 return orig_start; 1112 return orig_start;
1103 } 1113 }
1104 }*/ 1114 }*/
1105 1115
1106 map_native_address(context, instbuf.address, native_start, (after-inst)*2, MAX_NATIVE_SIZE); 1116 map_native_address(context, instbuf.address, native_start, after_address - orig, MAX_NATIVE_SIZE);
1107 1117
1108 jmp(&orig_code, native_start); 1118 jmp(&orig_code, native_start);
1109 if (!m68k_is_terminal(&instbuf)) { 1119 if (!m68k_is_terminal(&instbuf)) {
1110 code_ptr native_end = code->cur; 1120 code_ptr native_end = code->cur;
1111 code->cur = native_start + MAX_NATIVE_SIZE; 1121 code->cur = native_start + MAX_NATIVE_SIZE;
1112 code_ptr rest = get_native_address_trans(context, orig + (after-inst)*2); 1122 code_ptr rest = get_native_address_trans(context, after_address);
1113 code_info tmp_code = { 1123 code_info tmp_code = {
1114 .cur = native_end, 1124 .cur = native_end,
1115 .last = native_start + MAX_NATIVE_SIZE, 1125 .last = native_start + MAX_NATIVE_SIZE,
1116 .stack_off = code->stack_off 1126 .stack_off = code->stack_off
1117 }; 1127 };
1126 *code = orig_code; 1136 *code = orig_code;
1127 translate_m68k(context, &instbuf); 1137 translate_m68k(context, &instbuf);
1128 orig_code = *code; 1138 orig_code = *code;
1129 *code = tmp; 1139 *code = tmp;
1130 if (!m68k_is_terminal(&instbuf)) { 1140 if (!m68k_is_terminal(&instbuf)) {
1131 jmp(&orig_code, get_native_address_trans(context, orig + (after-inst)*2)); 1141 jmp(&orig_code, get_native_address_trans(context, after_address));
1132 } 1142 }
1133 m68k_handle_deferred(context); 1143 m68k_handle_deferred(context);
1134 return orig_start; 1144 return orig_start;
1135 } 1145 }
1136 } 1146 }