comparison gdb_remote.c @ 530:92606a032d56

Implement memory writes in GDB remote debugging stub
author Mike Pavone <pavone@retrodev.com>
date Wed, 12 Feb 2014 23:22:02 -0800
parents 6fe73296938a
children a3afee2271ce
comparison
equal deleted inserted replaced
529:6a648d944311 530:92606a032d56
119 //TODO: Use generated read/write functions so that memory map is properly respected 119 //TODO: Use generated read/write functions so that memory map is properly respected
120 if (address < 0x400000) { 120 if (address < 0x400000) {
121 word = context->mem_pointers[0] + address/2; 121 word = context->mem_pointers[0] + address/2;
122 } else if (address >= 0xE00000) { 122 } else if (address >= 0xE00000) {
123 word = context->mem_pointers[1] + (address & 0xFFFF)/2; 123 word = context->mem_pointers[1] + (address & 0xFFFF)/2;
124 } else if (address >= 0xA00000 && address < 0xA04000) {
125 return z80_ram[address & 0x1FFF];
124 } else { 126 } else {
125 return 0; 127 return 0;
126 } 128 }
127 if (address & 1) { 129 if (address & 1) {
128 return *word; 130 return *word;
129 } 131 }
130 return *word >> 8; 132 return *word >> 8;
133 }
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;
147 genesis_context * gen = context->system;
148 z80_handle_code_write(address & 0x1FFF, gen->z80);
149 return;
150 } else {
151 return;
152 }
153 if (address & 1) {
154 *word = (*word & 0xFF00) | value;
155 } else {
156 *word = (*word & 0xFF) | value << 8;
157 }
131 } 158 }
132 159
133 void gdb_run_command(m68k_context * context, uint32_t pc, char * command) 160 void gdb_run_command(m68k_context * context, uint32_t pc, char * command)
134 { 161 {
135 char send_buf[512]; 162 char send_buf[512];
267 } 294 }
268 *cur = 0; 295 *cur = 0;
269 gdb_send_command(send_buf); 296 gdb_send_command(send_buf);
270 break; 297 break;
271 } 298 }
299 case 'M': {
300 char * rest;
301 uint32_t address = strtoul(command+1, &rest, 16);
302 uint32_t size = strtoul(rest+1, &rest, 16);
303
304 char *cur = rest+1;
305 while (size)
306 {
307 char tmp[3];
308 tmp[0] = *(cur++);
309 tmp[1] = *(cur++);
310 tmp[2] = 0;
311 write_byte(context, address, strtoul(tmp, NULL, 16));
312 address++;
313 size--;
314 }
315 gdb_send_command("OK");
316 break;
317 }
318 case 'X':
319 //binary transfers aren't supported currently as I don't feel like dealing with the escaping
320 gdb_send_command("");
321 break;
272 case 'p': { 322 case 'p': {
273 unsigned long reg = strtoul(command+1, NULL, 16); 323 unsigned long reg = strtoul(command+1, NULL, 16);
274 324
275 if (reg < 8) { 325 if (reg < 8) {
276 hex_32(context->dregs[reg], send_buf); 326 hex_32(context->dregs[reg], send_buf);