1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030
|
/* -*- mode: C++; tab-width: 4 -*- */
/* ================================================================================== */
/* Copyright (c) 1998-1999 3Com Corporation or its subsidiaries. All rights reserved. */
/* ================================================================================== */
#include "EmulatorCommon.h"
#include "SystemPacket.h"
#include "ATraps.h" // ATrap
#include "DebugMgr.h" // Debug::
#include "HostControl.h" // hostSelectorWaitForIdle
#include "Logging.h" // LogAppendMsg
#include "EmRPC.h" // slkSocketRPC
#include "SLP.h" // SLP
#include "UAE_Utils.h" // uae_memcpy
/*
Crib notes on the supported packets:
+- Called by Debugger
| +- Implemented
| | Command
| | Command name Number Sent to
------- --------------------------- ----------- -----------------
* * sysPktStateCmd 0x00 slkSocketDebugger SysPktStateCmdType SysPktStateRspType
* * sysPktReadMemCmd 0x01 slkSocketDebugger SysPktReadMemCmdType SysPktReadMemRspType
* * sysPktWriteMemCmd 0x02 slkSocketDebugger SysPktWriteMemCmdType SysPktWriteMemRspType
* . sysPktSingleStepCmd 0x03
* * sysPktGetRtnNameCmd 0x04 slkSocketDebugger SysPktRtnNameCmdType SysPktRtnNameRspType
* * sysPktReadRegsCmd 0x05 slkSocketDebugger SysPktReadRegsCmdType SysPktReadRegsRspType
* * sysPktWriteRegsCmd 0x06 slkSocketDebugger SysPktWriteRegsCmdType SysPktWriteRegsRspType
* * sysPktContinueCmd 0x07 slkSocketDebugger SysPktContinueCmdType <no response>
* * sysPktRPCCmd 0x0A both* SysPktRPCType
* sysPktGetBreakpointsCmd 0x0B SysPktGetBreakpointsCmdType SysPktGetBreakpointsRspType
* * sysPktSetBreakpointsCmd 0x0C slkSocketDebugger SysPktSetBreakpointsCmdType SysPktSetBreakpointsRspType
. sysPktRemoteUIUpdCmd 0x0C SysPktRemoteUIUpdCmdType
. sysPktRemoteEvtCmd 0x0D SysPktRemoteEvtCmdType
* * sysPktDbgBreakToggleCmd 0x0D slkSocketDebugger SysPktDbgBreakToggleCmdType SysPktDbgBreakToggleRspType
* . sysPktFlashCmd 0x0E SysPktFlashWriteType
* . sysPktCommCmd 0x0F both* SysPktCommCmdType SysPktCommRspType
* * sysPktGetTrapBreaksCmd 0x10 slkSocketDebugger SysPktGetTrapBreaksCmdType SysPktGetTrapBreaksRspType
* * sysPktSetTrapBreaksCmd 0x11 slkSocketDebugger SysPktSetTrapBreaksCmdType SysPktSetTrapBreaksRspType
+ sysPktGremlinsCmd 0x12 slkSocketConsole SysPktGremlinsCmdType
* * sysPktFindCmd 0x13 slkSocketDebugger SysPktFindCmdType SysPktFindRspType
* sysPktGetTrapConditionsCmd 0x14 slkSocketDebugger SysPktGetTrapConditionsCmdType SysPktGetTrapConditionsRspType
* sysPktSetTrapConditionsCmd 0x15 slkSocketDebugger SysPktSetTrapConditionsCmdType SysPktSetTrapConditionsRspType
. sysPktChecksumCmd 0x16 slkSocketDebugger SysPktChecksumType
. sysPktExecFlashCmd 0x17 slkSocketDebugger sysPktExecFlashType
* * sysPktRemoteMsgCmd 0x7f both SysPktRemoteMsgCmdType
"both*" = if attached, sent to slkSocketDebugger, else slkSocketConsole
*/
#define sysPktBadFormatRsp 0xFF
#define ENTER_CODE(fnName, cmdType, rspType) \
PRINTF ("Entering SystemPacket::" fnName "."); \
cmdType& packet = (cmdType&) slp.Body ()
#define ENTER_PACKET(fnName, cmdType, rspType) \
PRINTF ("Entering SystemPacket::" fnName "."); \
cmdType& packet = (cmdType&) slp.Body (); \
rspType response
#define EXIT_PACKET(fnName, code, bodySize) \
response.command = code; \
response._filler = 0; \
ErrCode result = SystemPacket::SendPacket (slp, &response, bodySize); \
PRINTF ("Exiting SystemPacket::" fnName "."); \
return result
#define EXIT_CODE(fnName, code) \
ErrCode result = SystemPacket::SendResponse (slp, code); \
PRINTF ("Exiting SystemPacket::" fnName "."); \
return result
#define PRINTF if (!LogHLDebugger ()) ; else LogAppendMsg
/***********************************************************************
*
* FUNCTION: SystemPacket::SendState
*
* DESCRIPTION: .
*
* PARAMETERS: None.
*
* RETURNED: Nothing.
*
***********************************************************************/
ErrCode SystemPacket::SendState (SLP& slp)
{
// Do this function entry by hand instead of using the ENTER_PACKET macro.
// That macro will call SLP::Body, which returns a reference to the
// packet body that was sent to us. However, SendState (a) doesn't
// need the body reference, so there's no need to set it up, and (b)
// isn't necessarily called in response to a "SendState" command,
// and so the reference may be NULL.
PRINTF ("Entering SystemPacket::SendState.");
SysPktStateRspType response;
// Get the resetted boolean. This flag is true if the "device" has
// been resetted since the last time we sent a packet. The debugger
// needs to know this in order to update its notion of the device's
// state (like, for instance, if breakpoints are installed).
response.resetted = gDebuggerGlobals.firstEntrance;
gDebuggerGlobals.firstEntrance = false;
// Get the exception id.
response.exceptionId = gDebuggerGlobals.excType;
// Get the registers.
SystemPacket::GetRegs (response.reg);
// Get the breakpoints.
for (int i = 0; i < dbgTotalBreakpoints; i++)
{
response.bp[i] = gDebuggerGlobals.bp[i];
}
// Get some code beginning at PC.
for (int ii = 0; ii < sysPktStateRspInstWords; ++ii)
{
// Do this as two fetches in case the PC is odd.
response.inst[ii] = get_byte (m68k_getpc () + ii * 2) * 256 +
get_byte (m68k_getpc () + ii * 2 + 1);
}
// Get the routine name and address range info.
memset (response.name, 0, sizeof (response.name));
::FindFunctionName ( m68k_getpc () & 0xFFFFFFF0, // Protect against odd addresses.
response.name,
(uaecptr*) &response.startAddr,
(uaecptr*) &response.endAddr);
// Send the rev of the trap table.
response.trapTableRev = LowMem_GetGlobal (sysDispatchTableRev);
EXIT_PACKET ("SendState", sysPktStateRsp, sizeof (response));
}
/***********************************************************************
*
* FUNCTION: SystemPacket::ReadMem
*
* DESCRIPTION: .
*
* PARAMETERS: None.
*
* RETURNED: Nothing.
*
***********************************************************************/
ErrCode SystemPacket::ReadMem (SLP& slp)
{
ENTER_PACKET ("ReadMem", SysPktReadMemCmdType, SysPktReadMemRspType2);
uae_memcpy ((void*) (&response.data), (uaecptr) packet.address,
packet.numBytes);
EXIT_PACKET ("ReadMem", sysPktReadMemRsp, sizeof (SysPktReadMemRspType) + packet.numBytes);
}
/***********************************************************************
*
* FUNCTION: SystemPacket::WriteMem
*
* DESCRIPTION: .
*
* PARAMETERS: None.
*
* RETURNED: Nothing.
*
***********************************************************************/
ErrCode SystemPacket::WriteMem (SLP& slp)
{
ENTER_CODE ("WriteMem", SysPktWriteMemCmdType, SysPktWriteMemRspType);
uae_memcpy ((uaecptr) packet.address, (const void*) ((&packet) + 1),
packet.numBytes);
// If we just altered low memory, recalculate the low-memory checksum.
// Make sure we're on a ROM that has this field! Determine this by
// seeing that the address of sysLowMemChecksum is below the memCardInfo
// fields that come after the FixedGlobals.
//
// !!! This chunk of code should be in some more generally accessible location.
if (LowMem_Location (sysLowMemChecksum) < LowMem_GetGlobal (memCardInfoP))
{
if (packet.address < (void*) 0x100)
{
DWord checksum = 0;
uaecptr csP = UAE_NULL;
// First, calculate the checksum
while (csP < (uaecptr) 0x100)
{
DWord data = get_long (csP);
// Don't do these trap vectors since they change whenever the
// debugger is set to break on any a-trap or breakpoint.
if (csP == offsetof (M68KExcTableType, trapN[sysDispatchTrapNum]))
data = 0;
if (csP == offsetof (M68KExcTableType, trapN[sysDbgBreakpointTrapNum]))
data = 0;
if (csP == offsetof (M68KExcTableType, trace))
data = 0;
checksum += data;
csP += 4;
}
// Save new checksum
LowMem_SetGlobal (sysLowMemChecksum, checksum);
}
}
EXIT_CODE ("WriteMem", sysPktWriteMemRsp);
}
/***********************************************************************
*
* FUNCTION: SystemPacket::SendRoutineName
*
* DESCRIPTION: .
*
* PARAMETERS: None.
*
* RETURNED: Nothing.
*
***********************************************************************/
ErrCode SystemPacket::SendRoutineName (SLP& slp)
{
ENTER_PACKET ("SendRoutineName", SysPktRtnNameCmdType, SysPktRtnNameRspType);
response.address = (void*) (((uae_u32) packet.address) & ~1); // Protect against odd address.
response.startAddr = NULL;
response.endAddr = NULL;
response.name[0] = 0;
::FindFunctionName( (uaecptr) response.address,
response.name,
(uaecptr*) &response.startAddr,
(uaecptr*) &response.endAddr);
EXIT_PACKET ("SendRoutineName", sysPktGetRtnNameRsp, sizeof (response));
}
/***********************************************************************
*
* FUNCTION: SystemPacket::ReadRegs
*
* DESCRIPTION: .
*
* PARAMETERS: None.
*
* RETURNED: Nothing.
*
***********************************************************************/
ErrCode SystemPacket::ReadRegs (SLP& slp)
{
ENTER_PACKET ("ReadRegs", SysPktReadRegsCmdType, SysPktReadRegsRspType2);
SystemPacket::GetRegs (response.reg);
EXIT_PACKET ("ReadRegs", sysPktReadRegsRsp, sizeof (response));
}
/***********************************************************************
*
* FUNCTION: SystemPacket::WriteRegs
*
* DESCRIPTION: .
*
* PARAMETERS: None.
*
* RETURNED: Nothing.
*
***********************************************************************/
ErrCode SystemPacket::WriteRegs (SLP& slp)
{
ENTER_CODE ("WriteRegs", SysPktWriteRegsCmdType, SysPktWriteRegsRspType);
SystemPacket::SetRegs (packet.reg);
EXIT_CODE ("ReadRegs", sysPktWriteRegsRsp);
}
/***********************************************************************
*
* FUNCTION: SystemPacket::Continue
*
* DESCRIPTION: .
*
* PARAMETERS: None.
*
* RETURNED: Nothing.
*
***********************************************************************/
ErrCode SystemPacket::Continue (SLP& slp)
{
ENTER_CODE ("Continue", SysPktContinueCmdType, SysPktContinueCmdType);
SystemPacket::SetRegs (packet.regs);
gDebuggerGlobals.stepSpy = packet.stepSpy != 0;
gDebuggerGlobals.ssAddr = packet.ssAddr;
// ssCount is ignored?
gDebuggerGlobals.ssValue = packet.ssCheckSum;
ErrCode result = Debug::ExitDebugger ();
// Perform any platform-specific actions.
if (result == errNone)
{
Platform::ExitDebugger ();
}
// No reply...
PRINTF ("Exiting SystemPacket::Continue.");
return result;
}
/***********************************************************************
*
* FUNCTION: SystemPacket::RPC
*
* DESCRIPTION: .
*
* PARAMETERS: None.
*
* RETURNED: Nothing.
*
***********************************************************************/
ErrCode SystemPacket::RPC (SLP& slp)
{
ENTER_PACKET ("RPC", SysPktRPCType2, SysPktRPCType2);
ATrap trap;
SysPktRPCParamInfo* param = (SysPktRPCParamInfo*) &packet.param;
for (Word ii = 0; ii < packet.numParams; ++ii)
{
if (param->byRef)
{
trap.PushLong ((uae_u32) (¶m->data));
}
else
{
if (param->size == 1)
{
uae_u8 value = *(uae_u8*) param->data;
Canonical (value);
trap.PushByte (value);
}
else if (param->size == 2)
{
uae_u16 value = *(uae_u16*) param->data;
Canonical (value);
trap.PushWord (value);
}
else if (param->size == 4)
{
uae_u32 value = *(uae_u32*) param->data;
Canonical (value);
trap.PushLong (value);
}
}
param = (SysPktRPCParamInfo*) (((char*) param) + offsetof (SysPktRPCParamInfo, data) +
((param->size + 1) & ~1));
}
// Map in the memory pointed to by the reference parameters
StMemoryMapper mapper (&packet, ((char*) param) - ((char*) &packet));
// Call the trap. Special case the call to SysReset, as merely calling
// that function will not return from it.
if (packet.trapWord == sysTrapSysReset)
{
// Set flags that we're no longer in the debugger. This is the same
// as the last few steps of ExitDebugger.
gDebuggerGlobals.excType = 0;
LowMem_SetGlobal (dbgInDebugger, false);
gDebuggerGlobals.inDebugger = false;
// Reset the emulator (causes it to "reboot")
Emulator::Reset();
// That's it! No reply!
return kError_NoError;
}
trap.Call (packet.trapWord);
response = packet;
response.resultD0 = trap.GetD0 ();
response.resultA0 = trap.GetA0 ();
long numBytes = ((char*) param) - ((char*) &packet); // or get from header...
EXIT_PACKET ("RPC", sysPktRPCRsp, numBytes);
}
/***********************************************************************
*
* FUNCTION: SystemPacket::RPC2
*
* DESCRIPTION: .
*
* PARAMETERS: None.
*
* RETURNED: Nothing.
*
***********************************************************************/
ErrCode SystemPacket::RPC2 (SLP& slp)
{
ENTER_PACKET ("RPC2", SysPktRPC2Type, SysPktRPC2Type);
ATrap trap;
// Extract any D-registers from the packet.
UInt32* regs = packet.Regs;
int mask = 0x01;
int regNum = 0;
while (mask < 0x100)
{
if ((mask & packet.DRegMask) != 0)
{
UInt32 reg = *regs++;
trap.SetNewDReg (regNum, reg);
}
++regNum;
mask <<= 1;
}
// Extract any A-registers from the packet.
mask = 0x01;
regNum = 0;
while (mask < 0x100)
{
if ((mask & packet.ARegMask) != 0)
{
UInt32 reg = *regs++;
trap.SetNewAReg (regNum, reg);
}
++regNum;
mask <<= 1;
}
// Extract any stack-based parameters from the packet.
UInt16* numParams = (UInt16*) regs;
SysPktRPCParamInfo* param = (SysPktRPCParamInfo*) (numParams + 1);
for (Word ii = 0; ii < *numParams; ++ii)
{
if (param->byRef)
{
trap.PushLong ((uae_u32) (¶m->data));
}
else
{
if (param->size == 1)
{
uae_u8 value = *(uae_u8*) param->data;
Canonical (value);
trap.PushByte (value);
}
else if (param->size == 2)
{
uae_u16 value = *(uae_u16*) param->data;
Canonical (value);
trap.PushWord (value);
}
else if (param->size == 4)
{
uae_u32 value = *(uae_u32*) param->data;
Canonical (value);
trap.PushLong (value);
}
}
param = (SysPktRPCParamInfo*) (((char*) param) + offsetof (SysPktRPCParamInfo, data) +
((param->size + 1) & ~1));
}
// Map in the memory pointed to by the reference parameters
StMemoryMapper mapper (&packet, ((char*) param) - ((char*) &packet));
// Call the trap. Special case the call to SysReset, as merely calling
// that function will not return from it.
if (packet.trapWord == sysTrapSysReset)
{
// Set flags that we're no longer in the debugger. This is the same
// as the last few steps of ExitDebugger.
gDebuggerGlobals.excType = 0;
LowMem_SetGlobal (dbgInDebugger, false);
gDebuggerGlobals.inDebugger = false;
// Reset the emulator (causes it to "reboot")
Emulator::Reset();
// That's it! No reply!
return kError_NoError;
}
trap.Call (packet.trapWord);
response = packet;
response.resultD0 = trap.GetD0 ();
response.resultA0 = trap.GetA0 ();
response.resultException = 0;
long numBytes = ((char*) param) - ((char*) &packet); // or get from header...
EXIT_PACKET ("RPC2", sysPktRPC2Rsp, numBytes);
}
/***********************************************************************
*
* FUNCTION: SystemPacket::GetBreakpoints
*
* DESCRIPTION: .
*
* PARAMETERS: None.
*
* RETURNED: Nothing.
*
***********************************************************************/
ErrCode SystemPacket::GetBreakpoints (SLP& slp)
{
ENTER_PACKET ("GetBreakpoints", SysPktGetBreakpointsCmdType, SysPktGetBreakpointsRspType2);
memcpy (response.bp, gDebuggerGlobals.bp, sizeof (gDebuggerGlobals.bp));
EXIT_PACKET ("GetBreakpoints", sysPktGetBreakpointsRsp, sizeof (response));
}
/***********************************************************************
*
* FUNCTION: SystemPacket::SetBreakpoints
*
* DESCRIPTION: .
*
* PARAMETERS: None.
*
* RETURNED: Nothing.
*
***********************************************************************/
ErrCode SystemPacket::SetBreakpoints (SLP& slp)
{
ENTER_CODE ("SetBreakpoints", SysPktSetBreakpointsCmdType2, SysPktSetBreakpointsRspType);
for (int ii = 0; ii < dbgTotalBreakpoints; ++ii)
{
if (packet.bp[ii].enabled)
{
Debug::SetBreakpoint (ii, (uaecptr) packet.bp[ii].addr, NULL);
}
else
{
Debug::ClearBreakpoint (ii);
}
}
EXIT_CODE ("GetBreakpoints", sysPktSetBreakpointsRsp);
}
/***********************************************************************
*
* FUNCTION: SystemPacket::ToggleBreak
*
* DESCRIPTION: .
*
* PARAMETERS: None.
*
* RETURNED: Nothing.
*
***********************************************************************/
ErrCode SystemPacket::ToggleBreak (SLP& slp)
{
ENTER_PACKET ("ToggleBreak", SysPktDbgBreakToggleCmdType, SysPktDbgBreakToggleRspType);
gDebuggerGlobals.ignoreDbgBreaks = !gDebuggerGlobals.ignoreDbgBreaks;
response.newState = gDebuggerGlobals.ignoreDbgBreaks;
EXIT_PACKET ("ToggleBreak", sysPktDbgBreakToggleRsp, sizeof (response));
}
/***********************************************************************
*
* FUNCTION: SystemPacket::GetTrapBreaks
*
* DESCRIPTION: .
*
* PARAMETERS: None.
*
* RETURNED: Nothing.
*
***********************************************************************/
ErrCode SystemPacket::GetTrapBreaks (SLP& slp)
{
ENTER_PACKET ("GetTrapBreaks", SysPktGetTrapBreaksCmdType, SysPktGetTrapBreaksRspType2);
memcpy (response.trapBP, gDebuggerGlobals.trapBreak,
sizeof (gDebuggerGlobals.trapBreak));
EXIT_PACKET ("GetTrapBreaks", sysPktGetTrapBreaksRsp, sizeof (response));
}
/***********************************************************************
*
* FUNCTION: SystemPacket::SetTrapBreaks
*
* DESCRIPTION: .
*
* PARAMETERS: None.
*
* RETURNED: Nothing.
*
***********************************************************************/
ErrCode SystemPacket::SetTrapBreaks (SLP& slp)
{
ENTER_CODE ("SetTrapBreaks", SysPktSetTrapBreaksCmdType2, SysPktSetTrapBreaksRspType);
memcpy (gDebuggerGlobals.trapBreak, packet.trapBP,
sizeof (gDebuggerGlobals.trapBreak));
gDebuggerGlobals.breakingOnATrap = false;
for (int ii = 0; ii < dbgTotalTrapBreaks; ++ii)
{
if (gDebuggerGlobals.trapBreak[ii])
{
gDebuggerGlobals.breakingOnATrap = true;
break;
}
}
EXIT_CODE ("SetTrapBreaks", sysPktSetTrapBreaksRsp);
}
/***********************************************************************
*
* FUNCTION: SystemPacket::Find
*
* DESCRIPTION: .
*
* PARAMETERS: None.
*
* RETURNED: Nothing.
*
***********************************************************************/
ErrCode SystemPacket::Find (SLP& slp)
{
ENTER_PACKET ("Find", SysPktFindCmdType, SysPktFindRspType);
response.addr = (DWord) NULL;
response.found = false;
{
BytePtr dataP = (BytePtr) (&packet + 1);
DWord startP = packet.firstAddr;
while (startP <= packet.lastAddr)
{
Word ii;
for (ii = 0; ii < packet.numBytes; ++ii)
{
Byte b1 = get_byte(startP + ii);
Byte b2 = dataP[ii];
// Handle caseless conversion
if (packet.caseInsensitive)
{
if (isalpha (b1))
b1 = tolower (b1);
if (isalpha (b2))
b2 = tolower (b2);
}
if (b1 != b2) // if different -->
break;
}
// Check if matched
if (ii >= packet.numBytes)
{
response.addr = startP;
response.found = true;
break;
}
startP++; // advance start of search pointer
}
}
EXIT_PACKET ("Find", sysPktFindRsp, sizeof (response));
}
/***********************************************************************
*
* FUNCTION: SystemPacket::GetTrapConditions
*
* DESCRIPTION: .
*
* PARAMETERS: None.
*
* RETURNED: Nothing.
*
***********************************************************************/
ErrCode SystemPacket::GetTrapConditions (SLP& slp)
{
ENTER_PACKET ("GetTrapConditions", SysPktGetTrapConditionsCmdType, SysPktGetTrapConditionsRspType2);
memcpy (response.trapParam, gDebuggerGlobals.trapParam,
sizeof (gDebuggerGlobals.trapParam));
EXIT_PACKET ("GetTrapConditions", sysPktGetTrapConditionsRsp, sizeof (response));
}
/***********************************************************************
*
* FUNCTION: SystemPacket::SetTrapConditions
*
* DESCRIPTION: .
*
* PARAMETERS: None.
*
* RETURNED: Nothing.
*
***********************************************************************/
ErrCode SystemPacket::SetTrapConditions (SLP& slp)
{
ENTER_CODE ("SetTrapConditions", SysPktSetTrapConditionsCmdType2, SysPktSetTrapConditionsRspType);
memcpy (gDebuggerGlobals.trapParam, packet.trapParam,
sizeof (gDebuggerGlobals.trapParam));
EXIT_CODE ("SetTrapConditions", sysPktSetTrapConditionsRsp);
}
/***********************************************************************
*
* FUNCTION: SystemPacket::SendMessage
*
* DESCRIPTION: Sends a text string to the external client.
*
* PARAMETERS: None.
*
* RETURNED: Nothing.
*
***********************************************************************/
ErrCode SystemPacket::SendMessage (SLP& slp, const char* msg)
{
// ENTER_PACKET ("SendMessage", SysPktBodyType, SysPktBodyType);
// Do this function entry by hand instead of using the ENTER_PACKET macro.
// That macro will call SLP::Body, which returns a reference to the
// packet body that was sent to us. However, SendMessage (a) doesn't
// need the body reference, so there's no need to set it up, and (b)
// isn't necessarily called in response to a "SendMessage" command,
// and so the reference may be NULL.
PRINTF ("Entering SystemPacket::SendMessage.");
SysPktBodyType response;
size_t len = strlen (msg) + 1;
strcpy ((char*) &response.data[0], msg);
EXIT_PACKET ("SendMessage", sysPktRemoteMsgCmd,
sizeof (SysPktRemoteMsgCmdType) + len);
}
/***********************************************************************
*
* FUNCTION: SystemPacket::SendResponse
*
* DESCRIPTION: Sends a simple null-body message to the external debugger.
*
* PARAMETERS: None.
*
* RETURNED: Nothing.
*
***********************************************************************/
ErrCode SystemPacket::SendResponse (SLP& slp, Byte code)
{
SysPktEmptyRspType response;
response.command = code;
response._filler = 0;
return SystemPacket::SendPacket (slp, &response, sizeof (response));
}
/***********************************************************************
*
* FUNCTION: SystemPacket::SendPacket
*
* DESCRIPTION: Sends the given packet to the external client.
*
* PARAMETERS: None.
*
* RETURNED: Nothing.
*
***********************************************************************/
ErrCode SystemPacket::SendPacket (SLP& slp, const void* body, long bodySize)
{
PRINTF ("Entering SystemPacket::SendPacket.");
ErrCode result = slp.SendPacket (body, bodySize);
PRINTF ("Exiting SystemPacket::SendPacket.");
return result;
}
/***********************************************************************
*
* FUNCTION: SystemPacket::GetRegs
*
* DESCRIPTION: .
*
* PARAMETERS: None.
*
* RETURNED: Nothing.
*
***********************************************************************/
void SystemPacket::GetRegs (M68KRegsType& debuggerRegs)
{
debuggerRegs.d[0] = m68k_dreg (regs, 0);
debuggerRegs.d[1] = m68k_dreg (regs, 1);
debuggerRegs.d[2] = m68k_dreg (regs, 2);
debuggerRegs.d[3] = m68k_dreg (regs, 3);
debuggerRegs.d[4] = m68k_dreg (regs, 4);
debuggerRegs.d[5] = m68k_dreg (regs, 5);
debuggerRegs.d[6] = m68k_dreg (regs, 6);
debuggerRegs.d[7] = m68k_dreg (regs, 7);
debuggerRegs.a[0] = m68k_areg (regs, 0);
debuggerRegs.a[1] = m68k_areg (regs, 1);
debuggerRegs.a[2] = m68k_areg (regs, 2);
debuggerRegs.a[3] = m68k_areg (regs, 3);
debuggerRegs.a[4] = m68k_areg (regs, 4);
debuggerRegs.a[5] = m68k_areg (regs, 5);
debuggerRegs.a[6] = m68k_areg (regs, 6);
// debuggerRegs.a[7] = m68k_areg (regs, 7);
// Update the usp, isp, and/or msp before returning it.
// (from m68k_dumpstate() in newcpu.c)
if (regs.s == 0)
regs.usp = m68k_areg (regs, 7);
else
regs.isp = m68k_areg (regs, 7);
// Make sure the Status Register is up-to-date before moving it
// into the debugger register set.
Registers::UpdateSRFromRegisters ();
// Copy the remaining registers from the UAE register set to the
// debugger's register set.
debuggerRegs.usp = regs.usp;
debuggerRegs.ssp = regs.isp;
debuggerRegs.sr = regs.sr;
debuggerRegs.pc = m68k_getpc ();
}
/***********************************************************************
*
* FUNCTION: Debug::SetRegs
*
* DESCRIPTION: .
*
* PARAMETERS: None.
*
* RETURNED: Nothing.
*
***********************************************************************/
void SystemPacket::SetRegs (const M68KRegsType& debuggerRegs)
{
m68k_dreg (regs, 0) = debuggerRegs.d[0];
m68k_dreg (regs, 1) = debuggerRegs.d[1];
m68k_dreg (regs, 2) = debuggerRegs.d[2];
m68k_dreg (regs, 3) = debuggerRegs.d[3];
m68k_dreg (regs, 4) = debuggerRegs.d[4];
m68k_dreg (regs, 5) = debuggerRegs.d[5];
m68k_dreg (regs, 6) = debuggerRegs.d[6];
m68k_dreg (regs, 7) = debuggerRegs.d[7];
m68k_areg (regs, 0) = debuggerRegs.a[0];
m68k_areg (regs, 1) = debuggerRegs.a[1];
m68k_areg (regs, 2) = debuggerRegs.a[2];
m68k_areg (regs, 3) = debuggerRegs.a[3];
m68k_areg (regs, 4) = debuggerRegs.a[4];
m68k_areg (regs, 5) = debuggerRegs.a[5];
m68k_areg (regs, 6) = debuggerRegs.a[6];
// m68k_areg (regs, 7) = debuggerRegs.a[7];
regs.usp = debuggerRegs.usp;
regs.isp = debuggerRegs.ssp;
regs.sr = debuggerRegs.sr;
m68k_setpc (debuggerRegs.pc);
// Make sure 's' bit is correct. This will also set SPCFLAG_INT, and
// if either the t0 or t1 bits are set, SPCFLAG_TRACE, too.
Registers::UpdateRegistersFromSR ();
// I think we need to do a little extra handling here of the TRACE
// mode. If the TRACE mode bit is set, UpdateRegistersFromSR will
// set its SPCFLAG_TRACE flag, which tells the CPU loop to finish
// executing the current instruction, and then set the SPCFLAG_DOTRACE
// flag afterwards, which will then cause execution to stop after
// the NEXT instruction. We have a bit of an edge condition here
// when we set the SPCFLAG_TRACE flag BETWEEN instructions. Doing it
// this way will cause the next instruction to be treated as the
// "current" instruction, and so execution will stop after executing
// the second opcode. We want execution to stop with the first
// opcode, so fix up the flags here. This code is the same as in
// Emulator::ExecuteSpecial for managing this stuff.
if (regs.spcflags & SPCFLAG_TRACE)
{
regs.spcflags &= ~SPCFLAG_TRACE;
regs.spcflags |= SPCFLAG_DOTRACE;
}
// Finally, update the stack pointer from the usp or ssp,
// as appropriate.
if (regs.s == 0)
m68k_areg (regs, 7) = debuggerRegs.usp;
else
m68k_areg (regs, 7) = debuggerRegs.ssp;
}
|