comparison gdb_remote.c @ 801:092524bb2e8f

Fix GDB remote debugging support
author Michael Pavone <pavone@retrodev.com>
date Sun, 26 Jul 2015 16:32:34 -0700
parents 724bbec47f86
children 236a184bf6f0
comparison
equal deleted inserted replaced
800:ec23202df6a6 801:092524bb2e8f
113 } 113 }
114 } 114 }
115 115
116 uint8_t read_byte(m68k_context * context, uint32_t address) 116 uint8_t read_byte(m68k_context * context, uint32_t address)
117 { 117 {
118 uint16_t * word; 118
119 genesis_context *gen = context->system;
120 //TODO: Use generated read/write functions to support access to hardware that is not ROM or RAM
121 uint16_t * word = get_native_pointer(address & 0xFFFFFFFE, (void **)context->mem_pointers, &context->options->gen);
122 if (word) {
123 if (address & 1) {
124 return *word;
125 }
126 return *word >> 8;
127 }
128 if (address >= 0xA00000 && address < 0xA04000) {
129 return gen->zram[address & 0x1FFF];
130 }
131 return 0;
132 }
133
134 void write_byte(m68k_context * context, uint32_t address, uint8_t value)
135 {
136 genesis_context *gen = context->system;
119 //TODO: Use generated read/write functions so that memory map is properly respected 137 //TODO: Use generated read/write functions so that memory map is properly respected
120 if (address < 0x400000) { 138 uint16_t * word = get_native_pointer(address & 0xFFFFFFFE, (void **)context->mem_pointers, &context->options->gen);
121 word = context->mem_pointers[0] + address/2; 139 if (word) {
122 } else if (address >= 0xE00000) { 140 if (address & 1) {
123 word = context->mem_pointers[1] + (address & 0xFFFF)/2; 141 *word = (*word & 0xFF00) | value;
124 } else if (address >= 0xA00000 && address < 0xA04000) { 142 } else {
125 return z80_ram[address & 0x1FFF]; 143 *word = (*word & 0xFF) | value << 8;
126 } else { 144 }
127 return 0; 145 //TODO: Deal with this more generally once m68k_handle_code_write can handle it
128 } 146 if (address >= 0xE00000) {
129 if (address & 1) { 147 m68k_handle_code_write(address, context);
130 return *word; 148 }
131 } 149 return;
132 return *word >> 8; 150 }
133 } 151 if (address >= 0xA00000 && address < 0xA04000) {
134
135 void write_byte(m68k_context * context, uint32_t address, uint8_t value)
136 {
137 uint16_t * word;
138 //TODO: Use generated read/write functions so that memory map is properly respected
139 if (address < 0x400000) {
140 //TODO: Invalidate translated code
141 word = context->mem_pointers[0] + address/2;
142 } else if (address >= 0xE00000) {
143 m68k_handle_code_write(address & 0xFFFF, context);
144 word = context->mem_pointers[1] + (address & 0xFFFF)/2;
145 } else if (address >= 0xA00000 && address < 0xA04000) {
146 z80_ram[address & 0x1FFF] = value; 152 z80_ram[address & 0x1FFF] = value;
147 genesis_context * gen = context->system; 153 genesis_context * gen = context->system;
148 #ifndef NO_Z80 154 #ifndef NO_Z80
149 z80_handle_code_write(address & 0x1FFF, gen->z80); 155 z80_handle_code_write(address & 0x1FFF, gen->z80);
150 #endif 156 #endif
151 return; 157 return;
152 } else { 158 } else {
153 return; 159 return;
154 } 160 }
155 if (address & 1) {
156 *word = (*word & 0xFF00) | value;
157 } else {
158 *word = (*word & 0xFF) | value << 8;
159 }
160 } 161 }
161 162
162 void gdb_run_command(m68k_context * context, uint32_t pc, char * command) 163 void gdb_run_command(m68k_context * context, uint32_t pc, char * command)
163 { 164 {
164 char send_buf[512]; 165 char send_buf[512];
178 if (*(command+1) != 0) { 179 if (*(command+1) != 0) {
179 //TODO: implement resuming at an arbitrary address 180 //TODO: implement resuming at an arbitrary address
180 goto not_impl; 181 goto not_impl;
181 } 182 }
182 m68kinst inst; 183 m68kinst inst;
183 uint16_t * pc_ptr; 184 genesis_context *gen = context->system;
184 if (pc < 0x400000) { 185 uint16_t * pc_ptr = get_native_pointer(pc, (void **)context->mem_pointers, &context->options->gen);
185 pc_ptr = cart + pc/2; 186 if (!pc_ptr) {
186 } else if(pc > 0xE00000) {
187 pc_ptr = ram + (pc & 0xFFFF)/2;
188 } else {
189 fatal_error("Entered gdb remote debugger stub at address %X\n", pc); 187 fatal_error("Entered gdb remote debugger stub at address %X\n", pc);
190 } 188 }
191 uint16_t * after_pc = m68k_decode(pc_ptr, &inst, pc & 0xFFFFFF); 189 uint16_t * after_pc = m68k_decode(pc_ptr, &inst, pc & 0xFFFFFF);
192 uint32_t after = pc + (after_pc-pc_ptr)*2; 190 uint32_t after = pc + (after_pc-pc_ptr)*2;
193 191
398 expect_break_response = 1; 396 expect_break_response = 1;
399 break; 397 break;
400 case 's': 398 case 's':
401 case 'S': { 399 case 'S': {
402 m68kinst inst; 400 m68kinst inst;
403 uint16_t * pc_ptr; 401 genesis_context *gen = context->system;
404 if (pc < 0x400000) { 402 uint16_t * pc_ptr = get_native_pointer(pc, (void **)context->mem_pointers, &context->options->gen);
405 pc_ptr = cart + pc/2; 403 if (!pc_ptr) {
406 } else if(pc > 0xE00000) {
407 pc_ptr = ram + (pc & 0xFFFF)/2;
408 } else {
409 fatal_error("Entered gdb remote debugger stub at address %X\n", pc); 404 fatal_error("Entered gdb remote debugger stub at address %X\n", pc);
410 } 405 }
411 uint16_t * after_pc = m68k_decode(pc_ptr, &inst, pc & 0xFFFFFF); 406 uint16_t * after_pc = m68k_decode(pc_ptr, &inst, pc & 0xFFFFFF);
412 uint32_t after = pc + (after_pc-pc_ptr)*2; 407 uint32_t after = pc + (after_pc-pc_ptr)*2;
413 408