comparison gdb_remote.c @ 2053:3414a4423de1 segacd

Merge from default
author Michael Pavone <pavone@retrodev.com>
date Sat, 15 Jan 2022 13:15:21 -0800
parents 3a46ff899fa6
children a7b753e260a2 f80c6111e1ae
comparison
equal deleted inserted replaced
1692:5dacaef602a7 2053:3414a4423de1
16 #else 16 #else
17 #define GDB_IN_FD STDIN_FILENO 17 #define GDB_IN_FD STDIN_FILENO
18 #define GDB_OUT_FD STDOUT_FILENO 18 #define GDB_OUT_FD STDOUT_FILENO
19 #define GDB_READ read 19 #define GDB_READ read
20 #define GDB_WRITE write 20 #define GDB_WRITE write
21 #include <unistd.h>
21 #endif 22 #endif
22 23
23 #include "gdb_remote.h" 24 #include "gdb_remote.h"
24 #include "68kinst.h" 25 #include "68kinst.h"
25 #include "debug.h" 26 #include "debug.h"
26 #include "util.h" 27 #include "util.h"
27 #include <unistd.h>
28 #include <fcntl.h> 28 #include <fcntl.h>
29 #include <stddef.h> 29 #include <stddef.h>
30 #include <stdlib.h> 30 #include <stdlib.h>
31 #include <stdio.h> 31 #include <stdio.h>
32 #include <string.h> 32 #include <string.h>
130 context->flags[i] = value & 1; 130 context->flags[i] = value & 1;
131 value >>= 1; 131 value >>= 1;
132 } 132 }
133 } 133 }
134 134
135 uint8_t read_byte(m68k_context * context, uint32_t address) 135 static uint8_t m68k_read_byte(m68k_context *context, uint32_t address)
136 { 136 {
137 137 //TODO: share this implementation with builtin debugger
138 genesis_context *gen = context->system; 138 return read_byte(address, (void **)context->mem_pointers, &context->options->gen, context);
139 //TODO: Use generated read/write functions to support access to hardware that is not ROM or RAM 139 }
140 uint16_t * word = get_native_pointer(address & 0xFFFFFFFE, (void **)context->mem_pointers, &context->options->gen); 140
141 if (word) { 141 void m68k_write_byte(m68k_context * context, uint32_t address, uint8_t value)
142 if (address & 1) {
143 return *word;
144 }
145 return *word >> 8;
146 }
147 if (address >= 0xA00000 && address < 0xA04000) {
148 return gen->zram[address & 0x1FFF];
149 }
150 return 0;
151 }
152
153 void write_byte(m68k_context * context, uint32_t address, uint8_t value)
154 { 142 {
155 genesis_context *gen = context->system; 143 genesis_context *gen = context->system;
156 //TODO: Use generated read/write functions so that memory map is properly respected 144 //TODO: Use generated read/write functions so that memory map is properly respected
157 uint16_t * word = get_native_pointer(address & 0xFFFFFFFE, (void **)context->mem_pointers, &context->options->gen); 145 uint16_t * word = get_native_pointer(address & 0xFFFFFFFE, (void **)context->mem_pointers, &context->options->gen);
158 if (word) { 146 if (word) {
168 return; 156 return;
169 } 157 }
170 if (address >= 0xA00000 && address < 0xA04000) { 158 if (address >= 0xA00000 && address < 0xA04000) {
171 gen->zram[address & 0x1FFF] = value; 159 gen->zram[address & 0x1FFF] = value;
172 genesis_context * gen = context->system; 160 genesis_context * gen = context->system;
173 #ifndef NO_Z80 161 #if !defined(NO_Z80) && !defined(NEW_CORE)
174 z80_handle_code_write(address & 0x1FFF, gen->z80); 162 z80_handle_code_write(address & 0x1FFF, gen->z80);
175 #endif 163 #endif
176 return; 164 return;
177 } else { 165 } else {
178 return; 166 return;
303 size = (sizeof(send_buf)-1)/2; 291 size = (sizeof(send_buf)-1)/2;
304 } 292 }
305 char *cur = send_buf; 293 char *cur = send_buf;
306 while (size) 294 while (size)
307 { 295 {
308 hex_8(read_byte(context, address), cur); 296 hex_8(m68k_read_byte(context, address), cur);
309 cur += 2; 297 cur += 2;
310 address++; 298 address++;
311 size--; 299 size--;
312 } 300 }
313 *cur = 0; 301 *cur = 0;
324 { 312 {
325 char tmp[3]; 313 char tmp[3];
326 tmp[0] = *(cur++); 314 tmp[0] = *(cur++);
327 tmp[1] = *(cur++); 315 tmp[1] = *(cur++);
328 tmp[2] = 0; 316 tmp[2] = 0;
329 write_byte(context, address, strtoul(tmp, NULL, 16)); 317 m68k_write_byte(context, address, strtoul(tmp, NULL, 16));
330 address++; 318 address++;
331 size--; 319 size--;
332 } 320 }
333 gdb_send_command("OK"); 321 gdb_send_command("OK");
334 break; 322 break;
399 } else if (!strcmp("fThreadInfo", command + 1)) { 387 } else if (!strcmp("fThreadInfo", command + 1)) {
400 //we only support a single thread currently, so send 1 388 //we only support a single thread currently, so send 1
401 gdb_send_command("m1"); 389 gdb_send_command("m1");
402 } else if (!strcmp("sThreadInfo", command + 1)) { 390 } else if (!strcmp("sThreadInfo", command + 1)) {
403 gdb_send_command("l"); 391 gdb_send_command("l");
392 } else if (!memcmp("ThreadExtraInfo", command+1, strlen("ThreadExtraInfo"))) {
393 gdb_send_command("");
394 } else if (command[1] == 'P') {
395 gdb_send_command("");
404 } else { 396 } else {
405 goto not_impl; 397 goto not_impl;
406 } 398 }
407 break; 399 break;
408 case 'v': 400 case 'v':
556 curbuf = NULL; 548 curbuf = NULL;
557 } 549 }
558 } 550 }
559 } 551 }
560 552
561 #ifdef _WIN32
562 void gdb_cleanup(void)
563 {
564 WSACleanup();
565 }
566 WSADATA wsa_data;
567 #endif
568
569 void gdb_remote_init(void) 553 void gdb_remote_init(void)
570 { 554 {
571 buf = malloc(INITIAL_BUFFER_SIZE); 555 buf = malloc(INITIAL_BUFFER_SIZE);
572 curbuf = NULL; 556 curbuf = NULL;
573 bufsize = INITIAL_BUFFER_SIZE; 557 bufsize = INITIAL_BUFFER_SIZE;
574 #ifdef _WIN32 558 #ifdef _WIN32
575 WSAStartup(MAKEWORD(2,2), &wsa_data); 559 socket_init();
576 560
577 struct addrinfo request, *result; 561 struct addrinfo request, *result;
578 memset(&request, 0, sizeof(request)); 562 memset(&request, 0, sizeof(request));
579 request.ai_family = AF_INET; 563 request.ai_family = AF_INET;
580 request.ai_socktype = SOCK_STREAM; 564 request.ai_socktype = SOCK_STREAM;
586 fatal_error("Failed to open GDB remote debugging socket"); 570 fatal_error("Failed to open GDB remote debugging socket");
587 } 571 }
588 if (bind(listen_sock, result->ai_addr, result->ai_addrlen) < 0) { 572 if (bind(listen_sock, result->ai_addr, result->ai_addrlen) < 0) {
589 fatal_error("Failed to bind GDB remote debugging socket"); 573 fatal_error("Failed to bind GDB remote debugging socket");
590 } 574 }
575 freeaddrinfo(result);
591 if (listen(listen_sock, 1) < 0) { 576 if (listen(listen_sock, 1) < 0) {
592 fatal_error("Failed to listen on GDB remote debugging socket"); 577 fatal_error("Failed to listen on GDB remote debugging socket");
593 } 578 }
594 gdb_sock = accept(listen_sock, NULL, NULL); 579 gdb_sock = accept(listen_sock, NULL, NULL);
595 if (gdb_sock < 0) { 580 if (gdb_sock < 0) {
596 fatal_error("accept returned an error while listening on GDB remote debugging socket"); 581 fatal_error("accept returned an error while listening on GDB remote debugging socket");
597 } 582 }
598 closesocket(listen_sock); 583 socket_close(listen_sock);
584 #else
585 disable_stdout_messages();
599 #endif 586 #endif
600 } 587 }