annotate src/gba/remote.cpp @ 1:f9f4f1b99eed

importing src directory
author Robert McIntyre <rlm@mit.edu>
date Sat, 03 Mar 2012 10:31:27 -0600
parents
children ecd30c5e2f5a
rev   line source
rlm@1 1 #include <cstdlib>
rlm@1 2 #include <cstdio>
rlm@1 3 #include <cstring>
rlm@1 4
rlm@1 5 #ifndef WIN32
rlm@1 6 # include <unistd.h>
rlm@1 7 # include <sys/socket.h>
rlm@1 8 # include <netdb.h>
rlm@1 9 # ifdef HAVE_NETINET_IN_H
rlm@1 10 # include <netinet/in.h>
rlm@1 11 # endif // HAVE_NETINET_IN_H
rlm@1 12 # ifdef HAVE_ARPA_INET_H
rlm@1 13 # include <arpa/inet.h>
rlm@1 14 # else // ! HAVE_ARPA_INET_H
rlm@1 15 # define socklen_t int
rlm@1 16 # endif // ! HAVE_ARPA_INET_H
rlm@1 17 #else // WIN32
rlm@1 18 # include "../win32/stdafx.h"
rlm@1 19 # include <winsock.h>
rlm@1 20 # include <io.h>
rlm@1 21 # define socklen_t int
rlm@1 22 # define close closesocket
rlm@1 23 # define read _read
rlm@1 24 # define write _write
rlm@1 25 #endif // WIN32
rlm@1 26
rlm@1 27 #include "GBA.h"
rlm@1 28 #include "GBAGlobals.h"
rlm@1 29
rlm@1 30 extern bool debugger;
rlm@1 31 extern void CPUUpdateCPSR();
rlm@1 32 #ifdef SDL
rlm@1 33 extern void (*dbgMain)();
rlm@1 34 extern void (*dbgSignal)(int, int);
rlm@1 35 extern void debuggerMain();
rlm@1 36 extern void debuggerSignal(int, int);
rlm@1 37 #endif
rlm@1 38
rlm@1 39 int remotePort = 55555;
rlm@1 40 int remoteSignal = 5;
rlm@1 41 int remoteSocket = -1;
rlm@1 42 int remoteListenSocket = -1;
rlm@1 43 bool remoteConnected = false;
rlm@1 44 bool remoteResumed = false;
rlm@1 45
rlm@1 46 int (*remoteSendFnc)(char *, int) = NULL;
rlm@1 47 int (*remoteRecvFnc)(char *, int) = NULL;
rlm@1 48 bool (*remoteInitFnc)() = NULL;
rlm@1 49 void (*remoteCleanUpFnc)() = NULL;
rlm@1 50
rlm@1 51 #if (defined WIN32 && !defined SDL)
rlm@1 52 void remoteSetSockets(SOCKET l, SOCKET r)
rlm@1 53 {
rlm@1 54 remoteSocket = r;
rlm@1 55 remoteListenSocket = l;
rlm@1 56 }
rlm@1 57
rlm@1 58 #endif
rlm@1 59
rlm@1 60 int remoteTcpSend(char *data, int len)
rlm@1 61 {
rlm@1 62 return send(remoteSocket, data, len, 0);
rlm@1 63 }
rlm@1 64
rlm@1 65 int remoteTcpRecv(char *data, int len)
rlm@1 66 {
rlm@1 67 return recv(remoteSocket, data, len, 0);
rlm@1 68 }
rlm@1 69
rlm@1 70 bool remoteTcpInit()
rlm@1 71 {
rlm@1 72 if (remoteSocket == -1)
rlm@1 73 {
rlm@1 74 #ifdef WIN32
rlm@1 75 WSADATA wsaData;
rlm@1 76 int error = WSAStartup(MAKEWORD(1, 1), &wsaData);
rlm@1 77 #endif // WIN32
rlm@1 78 int s = socket(PF_INET, SOCK_STREAM, 0);
rlm@1 79
rlm@1 80 remoteListenSocket = s;
rlm@1 81
rlm@1 82 if (s < 0)
rlm@1 83 {
rlm@1 84 fprintf(stderr, "Error opening socket\n");
rlm@1 85 exit(-1);
rlm@1 86 }
rlm@1 87 int tmp = 1;
rlm@1 88 setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char *) &tmp, sizeof(tmp));
rlm@1 89
rlm@1 90 // char hostname[256];
rlm@1 91 // gethostname(hostname, 256);
rlm@1 92
rlm@1 93 // hostent *ent = gethostbyname(hostname);
rlm@1 94 // unsigned long a = *((unsigned long *)ent->h_addr);
rlm@1 95
rlm@1 96 sockaddr_in addr;
rlm@1 97 addr.sin_family = AF_INET;
rlm@1 98 addr.sin_port = htons(remotePort);
rlm@1 99 addr.sin_addr.s_addr = htonl(0);
rlm@1 100 int count = 0;
rlm@1 101 while (count < 3)
rlm@1 102 {
rlm@1 103 if (bind(s, (sockaddr *)&addr, sizeof(addr)))
rlm@1 104 {
rlm@1 105 addr.sin_port = htons(ntohs(addr.sin_port)+1);
rlm@1 106 }
rlm@1 107 else
rlm@1 108 break;
rlm@1 109 }
rlm@1 110 if (count == 3)
rlm@1 111 {
rlm@1 112 fprintf(stderr, "Error binding \n");
rlm@1 113 exit(-1);
rlm@1 114 }
rlm@1 115
rlm@1 116 fprintf(stderr, "Listening for a connection at port %d\n",
rlm@1 117 ntohs(addr.sin_port));
rlm@1 118
rlm@1 119 if (listen(s, 1))
rlm@1 120 {
rlm@1 121 fprintf(stderr, "Error listening\n");
rlm@1 122 exit(-1);
rlm@1 123 }
rlm@1 124 socklen_t len = sizeof(addr);
rlm@1 125
rlm@1 126 #ifdef WIN32
rlm@1 127 int flag = 0;
rlm@1 128 ioctlsocket(s, FIONBIO, (unsigned long *)&flag);
rlm@1 129 #endif // WIN32
rlm@1 130 int s2 = accept(s, (sockaddr *)&addr, &len);
rlm@1 131 if (s2 > 0)
rlm@1 132 {
rlm@1 133 fprintf(stderr, "Got a connection from %s %d\n",
rlm@1 134 inet_ntoa((in_addr)addr.sin_addr),
rlm@1 135 ntohs(addr.sin_port));
rlm@1 136 }
rlm@1 137 else
rlm@1 138 {
rlm@1 139 #ifdef WIN32
rlm@1 140 int error = WSAGetLastError();
rlm@1 141 #endif // WIN32
rlm@1 142 }
rlm@1 143 char dummy;
rlm@1 144 recv(s2, &dummy, 1, 0);
rlm@1 145 if (dummy != '+')
rlm@1 146 {
rlm@1 147 fprintf(stderr, "ACK not received\n");
rlm@1 148 exit(-1);
rlm@1 149 }
rlm@1 150 remoteSocket = s2;
rlm@1 151 // close(s);
rlm@1 152 }
rlm@1 153 return true;
rlm@1 154 }
rlm@1 155
rlm@1 156 void remoteTcpCleanUp()
rlm@1 157 {
rlm@1 158 if (remoteSocket > 0)
rlm@1 159 {
rlm@1 160 fprintf(stderr, "Closing remote socket\n");
rlm@1 161 close(remoteSocket);
rlm@1 162 remoteSocket = -1;
rlm@1 163 }
rlm@1 164 if (remoteListenSocket > 0)
rlm@1 165 {
rlm@1 166 fprintf(stderr, "Closing listen socket\n");
rlm@1 167 close(remoteListenSocket);
rlm@1 168 remoteListenSocket = -1;
rlm@1 169 }
rlm@1 170 }
rlm@1 171
rlm@1 172 int remotePipeSend(char *data, int len)
rlm@1 173 {
rlm@1 174 int res = write(1, data, len);
rlm@1 175 return res;
rlm@1 176 }
rlm@1 177
rlm@1 178 int remotePipeRecv(char *data, int len)
rlm@1 179 {
rlm@1 180 int res = read(0, data, len);
rlm@1 181 return res;
rlm@1 182 }
rlm@1 183
rlm@1 184 bool remotePipeInit()
rlm@1 185 {
rlm@1 186 char dummy;
rlm@1 187 read(0, &dummy, 1);
rlm@1 188 if (dummy != '+')
rlm@1 189 {
rlm@1 190 fprintf(stderr, "ACK not received\n");
rlm@1 191 exit(-1);
rlm@1 192 }
rlm@1 193
rlm@1 194 return true;
rlm@1 195 }
rlm@1 196
rlm@1 197 void remotePipeCleanUp()
rlm@1 198 {}
rlm@1 199
rlm@1 200 void remoteSetPort(int port)
rlm@1 201 {
rlm@1 202 remotePort = port;
rlm@1 203 }
rlm@1 204
rlm@1 205 void remoteSetProtocol(int p)
rlm@1 206 {
rlm@1 207 if (p == 0)
rlm@1 208 {
rlm@1 209 remoteSendFnc = remoteTcpSend;
rlm@1 210 remoteRecvFnc = remoteTcpRecv;
rlm@1 211 remoteInitFnc = remoteTcpInit;
rlm@1 212 remoteCleanUpFnc = remoteTcpCleanUp;
rlm@1 213 }
rlm@1 214 else
rlm@1 215 {
rlm@1 216 remoteSendFnc = remotePipeSend;
rlm@1 217 remoteRecvFnc = remotePipeRecv;
rlm@1 218 remoteInitFnc = remotePipeInit;
rlm@1 219 remoteCleanUpFnc = remotePipeCleanUp;
rlm@1 220 }
rlm@1 221 }
rlm@1 222
rlm@1 223 void remoteInit()
rlm@1 224 {
rlm@1 225 if (remoteInitFnc)
rlm@1 226 remoteInitFnc();
rlm@1 227 }
rlm@1 228
rlm@1 229 void remotePutPacket(char *packet)
rlm@1 230 {
rlm@1 231 char *hex = "0123456789abcdef";
rlm@1 232 char buffer[1024];
rlm@1 233
rlm@1 234 int count = strlen(packet);
rlm@1 235
rlm@1 236 unsigned char csum = 0;
rlm@1 237
rlm@1 238 char *p = buffer;
rlm@1 239 *p++ = '$';
rlm@1 240
rlm@1 241 for (int i = 0; i < count; i++)
rlm@1 242 {
rlm@1 243 csum += packet[i];
rlm@1 244 *p++ = packet[i];
rlm@1 245 }
rlm@1 246 *p++ = '#';
rlm@1 247 *p++ = hex[csum>>4];
rlm@1 248 *p++ = hex[csum & 15];
rlm@1 249 *p++ = 0;
rlm@1 250 // printf("Sending %s\n", buffer);
rlm@1 251 remoteSendFnc(buffer, count + 4);
rlm@1 252
rlm@1 253 char c = 0;
rlm@1 254 remoteRecvFnc(&c, 1);
rlm@1 255 /*
rlm@1 256 if(c == '+')
rlm@1 257 printf("ACK\n");
rlm@1 258 else if(c=='-')
rlm@1 259 printf("NACK\n");
rlm@1 260 */
rlm@1 261 }
rlm@1 262
rlm@1 263 void remoteOutput(char *s, u32 addr)
rlm@1 264 {
rlm@1 265 char buffer[16384];
rlm@1 266
rlm@1 267 char *d = buffer;
rlm@1 268 *d++ = 'O';
rlm@1 269
rlm@1 270 if (s)
rlm@1 271 {
rlm@1 272 char c = *s++;
rlm@1 273 while (c)
rlm@1 274 {
rlm@1 275 sprintf(d, "%02x", c);
rlm@1 276 d += 2;
rlm@1 277 c = *s++;
rlm@1 278 }
rlm@1 279 }
rlm@1 280 else
rlm@1 281 {
rlm@1 282 char c = debuggerReadByte(addr);
rlm@1 283 addr++;
rlm@1 284 while (c)
rlm@1 285 {
rlm@1 286 sprintf(d, "%02x", c);
rlm@1 287 d += 2;
rlm@1 288 c = debuggerReadByte(addr);
rlm@1 289 addr++;
rlm@1 290 }
rlm@1 291 }
rlm@1 292 remotePutPacket(buffer);
rlm@1 293 // fprintf(stderr, "Output sent %s\n", buffer);
rlm@1 294 }
rlm@1 295
rlm@1 296 void remoteSendSignal()
rlm@1 297 {
rlm@1 298 char buffer[1024];
rlm@1 299 sprintf(buffer, "S%02x", remoteSignal);
rlm@1 300 remotePutPacket(buffer);
rlm@1 301 }
rlm@1 302
rlm@1 303 void remoteSendStatus()
rlm@1 304 {
rlm@1 305 char buffer[1024];
rlm@1 306 sprintf(buffer, "T%02x", remoteSignal);
rlm@1 307 char *s = buffer;
rlm@1 308 s += 3;
rlm@1 309 for (int i = 0; i < 15; i++)
rlm@1 310 {
rlm@1 311 u32 v = reg[i].I;
rlm@1 312 sprintf(s, "%02x:%02x%02x%02x%02x;", i,
rlm@1 313 (v & 255),
rlm@1 314 (v >> 8) & 255,
rlm@1 315 (v >> 16) & 255,
rlm@1 316 (v >> 24) & 255);
rlm@1 317 s += 12;
rlm@1 318 }
rlm@1 319 u32 v = armNextPC;
rlm@1 320 sprintf(s, "0f:%02x%02x%02x%02x;", (v & 255),
rlm@1 321 (v >> 8) & 255,
rlm@1 322 (v >> 16) & 255,
rlm@1 323 (v >> 24) & 255);
rlm@1 324 s += 12;
rlm@1 325 CPUUpdateCPSR();
rlm@1 326 v = reg[16].I;
rlm@1 327 sprintf(s, "19:%02x%02x%02x%02x;", (v & 255),
rlm@1 328 (v >> 8) & 255,
rlm@1 329 (v >> 16) & 255,
rlm@1 330 (v >> 24) & 255);
rlm@1 331 s += 12;
rlm@1 332 *s = 0;
rlm@1 333 // printf("Sending %s\n", buffer);
rlm@1 334 remotePutPacket(buffer);
rlm@1 335 }
rlm@1 336
rlm@1 337 void remoteBinaryWrite(char *p)
rlm@1 338 {
rlm@1 339 u32 address;
rlm@1 340 int count;
rlm@1 341 sscanf(p, "%x,%x:", &address, &count);
rlm@1 342 // printf("Binary write for %08x %d\n", address, count);
rlm@1 343
rlm@1 344 p = strchr(p, ':');
rlm@1 345 p++;
rlm@1 346 for (int i = 0; i < count; i++)
rlm@1 347 {
rlm@1 348 u8 b = *p++;
rlm@1 349 switch (b)
rlm@1 350 {
rlm@1 351 case 0x7d:
rlm@1 352 b = *p++;
rlm@1 353 debuggerWriteByte(address, (b^0x20));
rlm@1 354 address++;
rlm@1 355 break;
rlm@1 356 default:
rlm@1 357 debuggerWriteByte(address, b);
rlm@1 358 address++;
rlm@1 359 break;
rlm@1 360 }
rlm@1 361 }
rlm@1 362 // printf("ROM is %08x\n", debuggerReadMemory(0x8000254));
rlm@1 363 remotePutPacket("OK");
rlm@1 364 }
rlm@1 365
rlm@1 366 void remoteMemoryWrite(char *p)
rlm@1 367 {
rlm@1 368 u32 address;
rlm@1 369 int count;
rlm@1 370 sscanf(p, "%x,%x:", &address, &count);
rlm@1 371 // printf("Memory write for %08x %d\n", address, count);
rlm@1 372
rlm@1 373 p = strchr(p, ':');
rlm@1 374 p++;
rlm@1 375 for (int i = 0; i < count; i++)
rlm@1 376 {
rlm@1 377 u8 v = 0;
rlm@1 378 char c = *p++;
rlm@1 379 if (c <= '9')
rlm@1 380 v = (c - '0') << 4;
rlm@1 381 else
rlm@1 382 v = (c + 10 - 'a') << 4;
rlm@1 383 c = *p++;
rlm@1 384 if (c <= '9')
rlm@1 385 v += (c - '0');
rlm@1 386 else
rlm@1 387 v += (c + 10 - 'a');
rlm@1 388 debuggerWriteByte(address, v);
rlm@1 389 address++;
rlm@1 390 }
rlm@1 391 // printf("ROM is %08x\n", debuggerReadMemory(0x8000254));
rlm@1 392 remotePutPacket("OK");
rlm@1 393 }
rlm@1 394
rlm@1 395 void remoteMemoryRead(char *p)
rlm@1 396 {
rlm@1 397 u32 address;
rlm@1 398 int count;
rlm@1 399 sscanf(p, "%x,%x:", &address, &count);
rlm@1 400 // printf("Memory read for %08x %d\n", address, count);
rlm@1 401
rlm@1 402 char buffer[1024];
rlm@1 403
rlm@1 404 char *s = buffer;
rlm@1 405 for (int i = 0; i < count; i++)
rlm@1 406 {
rlm@1 407 u8 b = debuggerReadByte(address);
rlm@1 408 sprintf(s, "%02x", b);
rlm@1 409 address++;
rlm@1 410 s += 2;
rlm@1 411 }
rlm@1 412 *s = 0;
rlm@1 413 remotePutPacket(buffer);
rlm@1 414 }
rlm@1 415
rlm@1 416 void remoteStepOverRange(char *p)
rlm@1 417 {
rlm@1 418 u32 address;
rlm@1 419 u32 final;
rlm@1 420 sscanf(p, "%x,%x", &address, &final);
rlm@1 421
rlm@1 422 remotePutPacket("OK");
rlm@1 423
rlm@1 424 remoteResumed = true;
rlm@1 425 do
rlm@1 426 {
rlm@1 427 CPULoop(1);
rlm@1 428 if (debugger)
rlm@1 429 break;
rlm@1 430 }
rlm@1 431 while (armNextPC >= address && armNextPC < final);
rlm@1 432
rlm@1 433 remoteResumed = false;
rlm@1 434
rlm@1 435 remoteSendStatus();
rlm@1 436 }
rlm@1 437
rlm@1 438 void remoteWriteWatch(char *p, bool active)
rlm@1 439 {
rlm@1 440 u32 address;
rlm@1 441 int count;
rlm@1 442 sscanf(p, ",%x,%x#", &address, &count);
rlm@1 443
rlm@1 444 fprintf(stderr, "Write watch for %08x %d\n", address, count);
rlm@1 445
rlm@1 446 if (address < 0x2000000 || address > 0x3007fff)
rlm@1 447 {
rlm@1 448 remotePutPacket("E01");
rlm@1 449 return;
rlm@1 450 }
rlm@1 451
rlm@1 452 if (address > 0x203ffff && address < 0x3000000)
rlm@1 453 {
rlm@1 454 remotePutPacket("E01");
rlm@1 455 return;
rlm@1 456 }
rlm@1 457
rlm@1 458 u32 final = address + count;
rlm@1 459
rlm@1 460 if (address < 0x2040000 && final > 0x2040000)
rlm@1 461 {
rlm@1 462 remotePutPacket("E01");
rlm@1 463 return;
rlm@1 464 }
rlm@1 465 else if (address < 0x3008000 && final > 0x3008000)
rlm@1 466 {
rlm@1 467 remotePutPacket("E01");
rlm@1 468 return;
rlm@1 469 }
rlm@1 470
rlm@1 471 for (int i = 0; i < count; i++)
rlm@1 472 {
rlm@1 473 if ((address >> 24) == 2)
rlm@1 474 freezeWorkRAM[address & 0x3ffff] = active;
rlm@1 475 else
rlm@1 476 freezeInternalRAM[address & 0x7fff] = active;
rlm@1 477 address++;
rlm@1 478 }
rlm@1 479
rlm@1 480 remotePutPacket("OK");
rlm@1 481 }
rlm@1 482
rlm@1 483 void remoteReadRegisters(char *p)
rlm@1 484 {
rlm@1 485 char buffer[1024];
rlm@1 486
rlm@1 487 char *s = buffer;
rlm@1 488 int i;
rlm@1 489 // regular registers
rlm@1 490 for (i = 0; i < 15; i++)
rlm@1 491 {
rlm@1 492 u32 v = reg[i].I;
rlm@1 493 sprintf(s, "%02x%02x%02x%02x", v & 255, (v >> 8) & 255,
rlm@1 494 (v >> 16) & 255, (v >> 24) & 255);
rlm@1 495 s += 8;
rlm@1 496 }
rlm@1 497 // PC
rlm@1 498 u32 pc = armNextPC;
rlm@1 499 sprintf(s, "%02x%02x%02x%02x", pc & 255, (pc >> 8) & 255,
rlm@1 500 (pc >> 16) & 255, (pc >> 24) & 255);
rlm@1 501 s += 8;
rlm@1 502
rlm@1 503 // floating point registers (24-bit)
rlm@1 504 for (i = 0; i < 8; i++)
rlm@1 505 {
rlm@1 506 sprintf(s, "000000000000000000000000");
rlm@1 507 s += 24;
rlm@1 508 }
rlm@1 509
rlm@1 510 // FP status register
rlm@1 511 sprintf(s, "00000000");
rlm@1 512 s += 8;
rlm@1 513 // CPSR
rlm@1 514 CPUUpdateCPSR();
rlm@1 515 u32 v = reg[16].I;
rlm@1 516 sprintf(s, "%02x%02x%02x%02x", v & 255, (v >> 8) & 255,
rlm@1 517 (v >> 16) & 255, (v >> 24) & 255);
rlm@1 518 s += 8;
rlm@1 519 *s = 0;
rlm@1 520 remotePutPacket(buffer);
rlm@1 521 }
rlm@1 522
rlm@1 523 void remoteWriteRegister(char *p)
rlm@1 524 {
rlm@1 525 int r;
rlm@1 526
rlm@1 527 sscanf(p, "%x=", &r);
rlm@1 528
rlm@1 529 p = strchr(p, '=');
rlm@1 530 p++;
rlm@1 531
rlm@1 532 char c = *p++;
rlm@1 533
rlm@1 534 u32 v = 0;
rlm@1 535
rlm@1 536 u8 data[4] = {0, 0, 0, 0};
rlm@1 537
rlm@1 538 int i = 0;
rlm@1 539
rlm@1 540 while (c != '#')
rlm@1 541 {
rlm@1 542 u8 b = 0;
rlm@1 543 if (c <= '9')
rlm@1 544 b = (c - '0') << 4;
rlm@1 545 else
rlm@1 546 b = (c + 10 - 'a') << 4;
rlm@1 547 c = *p++;
rlm@1 548 if (c <= '9')
rlm@1 549 b += (c - '0');
rlm@1 550 else
rlm@1 551 b += (c + 10 - 'a');
rlm@1 552 data[i++] = b;
rlm@1 553 c = *p++;
rlm@1 554 }
rlm@1 555
rlm@1 556 v = data[0] | (data[1] << 8) | (data[2] << 16) | (data[3] << 24);
rlm@1 557
rlm@1 558 // printf("Write register %d=%08x\n", r, v);
rlm@1 559 reg[r].I = v;
rlm@1 560 if (r == 15)
rlm@1 561 {
rlm@1 562 armNextPC = v;
rlm@1 563 if (armState)
rlm@1 564 reg[15].I = v + 4;
rlm@1 565 else
rlm@1 566 reg[15].I = v + 2;
rlm@1 567 }
rlm@1 568 remotePutPacket("OK");
rlm@1 569 }
rlm@1 570
rlm@1 571 void remoteStubMain()
rlm@1 572 {
rlm@1 573 if (!debugger)
rlm@1 574 return;
rlm@1 575
rlm@1 576 if (remoteResumed)
rlm@1 577 {
rlm@1 578 remoteSendStatus();
rlm@1 579 remoteResumed = false;
rlm@1 580 }
rlm@1 581
rlm@1 582 while (true)
rlm@1 583 {
rlm@1 584 char buffer[1024];
rlm@1 585 int res = remoteRecvFnc(buffer, 1024);
rlm@1 586
rlm@1 587 if (res == -1)
rlm@1 588 {
rlm@1 589 fprintf(stderr, "GDB connection lost\n");
rlm@1 590 #ifdef SDL
rlm@1 591 dbgMain = debuggerMain;
rlm@1 592 dbgSignal = debuggerSignal;
rlm@1 593 #endif
rlm@1 594 debugger = false;
rlm@1 595 break;
rlm@1 596 }
rlm@1 597
rlm@1 598 // fprintf(stderr, "Received %s\n", buffer);
rlm@1 599 char *p = buffer;
rlm@1 600 char c = *p++;
rlm@1 601 char pp = '+';
rlm@1 602 remoteSendFnc(&pp, 1);
rlm@1 603
rlm@1 604 if (c != '$')
rlm@1 605 continue;
rlm@1 606 c = *p++;
rlm@1 607 switch (c)
rlm@1 608 {
rlm@1 609 case '?':
rlm@1 610 remoteSendSignal();
rlm@1 611 break;
rlm@1 612 case 'D':
rlm@1 613 remotePutPacket("OK");
rlm@1 614 #ifdef SDL
rlm@1 615 dbgMain = debuggerMain;
rlm@1 616 dbgSignal = debuggerSignal;
rlm@1 617 #endif
rlm@1 618 remoteResumed = true;
rlm@1 619 debugger = false;
rlm@1 620 return;
rlm@1 621 case 'e':
rlm@1 622 remoteStepOverRange(p);
rlm@1 623 break;
rlm@1 624 case 'k':
rlm@1 625 remotePutPacket("OK");
rlm@1 626 #ifdef SDL
rlm@1 627 dbgMain = debuggerMain;
rlm@1 628 dbgSignal = debuggerSignal;
rlm@1 629 #endif
rlm@1 630 debugger = false;
rlm@1 631 emulating = false;
rlm@1 632 return;
rlm@1 633 case 'C':
rlm@1 634 remoteResumed = true;
rlm@1 635 debugger = false;
rlm@1 636 return;
rlm@1 637 case 'c':
rlm@1 638 remoteResumed = true;
rlm@1 639 debugger = false;
rlm@1 640 return;
rlm@1 641 case 's':
rlm@1 642 remoteResumed = true;
rlm@1 643 remoteSignal = 5;
rlm@1 644 CPULoop(1);
rlm@1 645 if (remoteResumed)
rlm@1 646 {
rlm@1 647 remoteResumed = false;
rlm@1 648 remoteSendStatus();
rlm@1 649 }
rlm@1 650 break;
rlm@1 651 case 'g':
rlm@1 652 remoteReadRegisters(p);
rlm@1 653 break;
rlm@1 654 case 'P':
rlm@1 655 remoteWriteRegister(p);
rlm@1 656 break;
rlm@1 657 case 'M':
rlm@1 658 remoteMemoryWrite(p);
rlm@1 659 break;
rlm@1 660 case 'm':
rlm@1 661 remoteMemoryRead(p);
rlm@1 662 break;
rlm@1 663 case 'X':
rlm@1 664 remoteBinaryWrite(p);
rlm@1 665 break;
rlm@1 666 case 'H':
rlm@1 667 remotePutPacket("OK");
rlm@1 668 break;
rlm@1 669 case 'q':
rlm@1 670 remotePutPacket("");
rlm@1 671 break;
rlm@1 672 case 'Z':
rlm@1 673 if (*p++ == '2')
rlm@1 674 {
rlm@1 675 remoteWriteWatch(p, true);
rlm@1 676 }
rlm@1 677 else
rlm@1 678 remotePutPacket("");
rlm@1 679 break;
rlm@1 680 case 'z':
rlm@1 681 if (*p++ == '2')
rlm@1 682 {
rlm@1 683 remoteWriteWatch(p, false);
rlm@1 684 }
rlm@1 685 else
rlm@1 686 remotePutPacket("");
rlm@1 687 break;
rlm@1 688 default:
rlm@1 689 {
rlm@1 690 *(strchr(p, '#') + 3) = 0;
rlm@1 691 fprintf(stderr, "Unknown packet %s\n", --p);
rlm@1 692 remotePutPacket("");
rlm@1 693 break;
rlm@1 694 }
rlm@1 695 }
rlm@1 696 }
rlm@1 697 }
rlm@1 698
rlm@1 699 void remoteStubSignal(int sig, int number)
rlm@1 700 {
rlm@1 701 remoteSignal = sig;
rlm@1 702 remoteResumed = false;
rlm@1 703 remoteSendStatus();
rlm@1 704 debugger = true;
rlm@1 705 }
rlm@1 706
rlm@1 707 void remoteCleanUp()
rlm@1 708 {
rlm@1 709 if (remoteCleanUpFnc)
rlm@1 710 remoteCleanUpFnc();
rlm@1 711 }
rlm@1 712