comparison debug.c @ 1313:b27d7bf1107e

Improved printing of word at absolute address to support reading from all address types. Implemented support for printing the value pointed to by a register. Removed abuse of read_dma_value in internal debugger.
author Michael Pavone <pavone@retrodev.com>
date Mon, 03 Apr 2017 20:48:13 -0700
parents 9ab3f6781202
children ae932ca28282
comparison
equal deleted inserted replaced
1312:9ab3f6781202 1313:b27d7bf1107e
86 return; 86 return;
87 } 87 }
88 } 88 }
89 } 89 }
90 90
91 uint16_t m68k_read_word(uint32_t address, m68k_context *context)
92 {
93 return read_word(address, (void **)context->mem_pointers, &context->options->gen, context);
94 }
95
96 uint32_t m68k_read_long(uint32_t address, m68k_context *context)
97 {
98 return m68k_read_word(address, context) << 16 | m68k_read_word(address + 2, context);
99 }
100
91 void debugger_print(m68k_context *context, char format_char, char *param) 101 void debugger_print(m68k_context *context, char format_char, char *param)
92 { 102 {
93 uint32_t value; 103 uint32_t value;
94 char format[8]; 104 char format[8];
95 strcpy(format, "%s: %d\n"); 105 strcpy(format, "%s: %d\n");
134 } else if(param[0] == 'f') { 144 } else if(param[0] == 'f') {
135 genesis_context *gen = context->system; 145 genesis_context *gen = context->system;
136 value = gen->vdp->frame; 146 value = gen->vdp->frame;
137 } else if ((param[0] == '0' && param[1] == 'x') || param[0] == '$') { 147 } else if ((param[0] == '0' && param[1] == 'x') || param[0] == '$') {
138 uint32_t p_addr = strtol(param+(param[0] == '0' ? 2 : 1), NULL, 16); 148 uint32_t p_addr = strtol(param+(param[0] == '0' ? 2 : 1), NULL, 16);
139 if ((p_addr & 0xFFFFFF) == 0xC00004) { 149 value = m68k_read_word(p_addr, context);
140 genesis_context * gen = context->system; 150 } else if(param[0] == '(' && (param[1] == 'a' || param[1] == 'd') && param[2] >= '0' && param[2] <= '7' && param[3] == ')') {
141 value = vdp_hv_counter_read(gen->vdp); 151 uint8_t reg = param[2] - '0';
142 } else { 152 uint32_t p_addr = param[1] == 'a' ? context->aregs[reg] : context->dregs[reg];
143 uint16_t *word = get_native_pointer(p_addr & 0xFFFFFE, (void **)context->mem_pointers, &context->options->gen); 153 value = m68k_read_word(p_addr, context);
144 value = *word;
145 }
146 } else { 154 } else {
147 fprintf(stderr, "Unrecognized parameter to p: %s\n", param); 155 fprintf(stderr, "Unrecognized parameter to p: %s\n", param);
148 return; 156 return;
149 } 157 }
150 printf(format, param, value); 158 printf(format, param, value);
712 } 720 }
713 debugger_print(context, format_char, param); 721 debugger_print(context, format_char, param);
714 break; 722 break;
715 case 'n': 723 case 'n':
716 if (inst.op == M68K_RTS) { 724 if (inst.op == M68K_RTS) {
717 after = (read_dma_value(context->aregs[7]/2) << 16) | read_dma_value(context->aregs[7]/2 + 1); 725 after = m68k_read_long(context->aregs[7], context);
718 } else if (inst.op == M68K_RTE || inst.op == M68K_RTR) { 726 } else if (inst.op == M68K_RTE || inst.op == M68K_RTR) {
719 after = (read_dma_value((context->aregs[7]+2)/2) << 16) | read_dma_value((context->aregs[7]+2)/2 + 1); 727 after = m68k_read_long(context->aregs[7] + 2, context);
720 } else if(m68k_is_noncall_branch(&inst)) { 728 } else if(m68k_is_noncall_branch(&inst)) {
721 if (inst.op == M68K_BCC && inst.extra.cond != COND_TRUE) { 729 if (inst.op == M68K_BCC && inst.extra.cond != COND_TRUE) {
722 branch_f = after; 730 branch_f = after;
723 branch_t = m68k_branch_target(&inst, context->dregs, context->aregs); 731 branch_t = m68k_branch_target(&inst, context->dregs, context->aregs);
724 insert_breakpoint(context, branch_t, debugger); 732 insert_breakpoint(context, branch_t, debugger);
738 } 746 }
739 insert_breakpoint(context, after, debugger); 747 insert_breakpoint(context, after, debugger);
740 return 0; 748 return 0;
741 case 'o': 749 case 'o':
742 if (inst.op == M68K_RTS) { 750 if (inst.op == M68K_RTS) {
743 after = (read_dma_value(context->aregs[7]/2) << 16) | read_dma_value(context->aregs[7]/2 + 1); 751 after = m68k_read_long(context->aregs[7], context);
744 } else if (inst.op == M68K_RTE || inst.op == M68K_RTR) { 752 } else if (inst.op == M68K_RTE || inst.op == M68K_RTR) {
745 after = (read_dma_value((context->aregs[7]+2)/2) << 16) | read_dma_value((context->aregs[7]+2)/2 + 1); 753 after = m68k_read_long(context->aregs[7] + 2, context);
746 } else if(m68k_is_noncall_branch(&inst)) { 754 } else if(m68k_is_noncall_branch(&inst)) {
747 if (inst.op == M68K_BCC && inst.extra.cond != COND_TRUE) { 755 if (inst.op == M68K_BCC && inst.extra.cond != COND_TRUE) {
748 branch_t = m68k_branch_target(&inst, context->dregs, context->aregs) & 0xFFFFFF; 756 branch_t = m68k_branch_target(&inst, context->dregs, context->aregs) & 0xFFFFFF;
749 if (branch_t < after) { 757 if (branch_t < after) {
750 branch_t = 0; 758 branch_t = 0;
769 } 777 }
770 insert_breakpoint(context, after, debugger); 778 insert_breakpoint(context, after, debugger);
771 return 0; 779 return 0;
772 case 's': 780 case 's':
773 if (inst.op == M68K_RTS) { 781 if (inst.op == M68K_RTS) {
774 after = (read_dma_value(context->aregs[7]/2) << 16) | read_dma_value(context->aregs[7]/2 + 1); 782 after = m68k_read_long(context->aregs[7], context);
775 } else if (inst.op == M68K_RTE || inst.op == M68K_RTR) { 783 } else if (inst.op == M68K_RTE || inst.op == M68K_RTR) {
776 after = (read_dma_value((context->aregs[7]+2)/2) << 16) | read_dma_value((context->aregs[7]+2)/2 + 1); 784 after = m68k_read_long(context->aregs[7] + 2, context);
777 } else if(m68k_is_branch(&inst)) { 785 } else if(m68k_is_branch(&inst)) {
778 if (inst.op == M68K_BCC && inst.extra.cond != COND_TRUE) { 786 if (inst.op == M68K_BCC && inst.extra.cond != COND_TRUE) {
779 branch_f = after; 787 branch_f = after;
780 branch_t = m68k_branch_target(&inst, context->dregs, context->aregs) & 0xFFFFFF; 788 branch_t = m68k_branch_target(&inst, context->dregs, context->aregs) & 0xFFFFFF;
781 insert_breakpoint(context, branch_t, debugger); 789 insert_breakpoint(context, branch_t, debugger);