📄 ardi.c
字号:
adp_stopped_struct *stopped_info; stopped_info = (adp_stopped_struct *) stateptr; IGNORE(stateptr); count = unpack_message(BUFFERDATA(packet->pk_buffer), "%w%w%w%w%w%w", &reason, &debugID, &OSinfo1, &OSinfo2, &stopped_info->stopped_reason, &stopped_info->data); DevSW_FreePacket(packet); if (reason != (ADP_Stopped | TtoH)) {#ifdef DEBUG angel_DebugPrint("Expecting stopped message, got %x", reason);#endif return RDIError_Error; } else { executing = FALSE;#ifdef DEBUG angel_DebugPrint("Received stopped message.\n");#endif } err = msgsend(CI_TADP, "%w%w%w%w%w", (ADP_Stopped | HtoT), 0, ADP_HandleUnknown, ADP_HandleUnknown, RDIError_NoError);#ifdef DEBUG angel_DebugPrint("Transmiting stopped acknowledge.\n");#endif if (err != RDIError_NoError) angel_DebugPrint("Transmit failed.\n");#ifdef DEBUG angel_DebugPrint("DEBUG: Stopped reason : %x\n", stopped_info->stopped_reason);#endif switch (stopped_info->stopped_reason) { case ADP_Stopped_BranchThroughZero: stopped_info->stopped_status = RDIError_BranchThrough0; break; case ADP_Stopped_UndefinedInstr: stopped_info->stopped_status = RDIError_UndefinedInstruction; break; case ADP_Stopped_SoftwareInterrupt: stopped_info->stopped_status = RDIError_SoftwareInterrupt; break; case ADP_Stopped_PrefetchAbort: stopped_info->stopped_status = RDIError_PrefetchAbort; break; case ADP_Stopped_DataAbort: stopped_info->stopped_status = RDIError_DataAbort; break; case ADP_Stopped_AddressException: stopped_info->stopped_status = RDIError_AddressException; break; case ADP_Stopped_IRQ: stopped_info->stopped_status = RDIError_IRQ; break; case ADP_Stopped_BreakPoint: stopped_info->stopped_status = RDIError_BreakpointReached; break; case ADP_Stopped_WatchPoint: stopped_info->stopped_status = RDIError_WatchpointAccessed; break; case ADP_Stopped_StepComplete: stopped_info->stopped_status = RDIError_ProgramFinishedInStep; break; case ADP_Stopped_RunTimeErrorUnknown: case ADP_Stopped_StackOverflow: case ADP_Stopped_DivisionByZero: stopped_info->stopped_status = RDIError_Error; break; case ADP_Stopped_FIQ: stopped_info->stopped_status = RDIError_FIQ; break; case ADP_Stopped_UserInterruption: case ADP_Stopped_OSSpecific: stopped_info->stopped_status = RDIError_UserInterrupt; break; case ADP_Stopped_ApplicationExit: stopped_info->stopped_status = RDIError_NoError; break; default: stopped_info->stopped_status = RDIError_Error; break; } return RDIError_NoError;}static void interrupt_target( void ){ Packet *packet = NULL; int err; int reason, debugID, OSinfo1, OSinfo2, status;#ifdef DEBUG angel_DebugPrint("DEBUG: interrupt_target.\n");#endif register_debug_message_handler(); msgsend(CI_HADP, "%w%w%w%w", ADP_InterruptRequest | HtoT, 0, ADP_HandleUnknown, ADP_HandleUnknown); reason = ADP_InterruptRequest |TtoH; err = wait_for_debug_message(&reason, &debugID, &OSinfo1, &OSinfo2, &status, &packet); DevSW_FreePacket(packet);#ifdef DEBUG angel_DebugPrint("DEBUG: got interrupt ack ok err = %d, status=%i\n", err, status);#endif return;}#ifdef TEST_DC_APPL extern void test_dc_appl_handler( const DeviceDescr *device, Packet *packet );#endifvoid angel_RDI_stop_request(void){ stop_request = 1;}/* Core functionality for execute and step */static int angel_RDI_ExecuteOrStep(PointHandle *handle, word type, unsigned ninstr){ extern int (*deprecated_ui_loop_hook) (int); int err; adp_stopped_struct stopped_info; void* stateptr = (void *)&stopped_info; ChannelCallback HandleStoppedMessageFPtr=(ChannelCallback) HandleStoppedMessage; int status, reasoncode, debugID, OSinfo1, OSinfo2; Packet *packet = NULL; TracePrint(("angel_RDI_ExecuteOrStep\n")); err = Adp_ChannelRegisterRead(CI_TADP, HandleStoppedMessageFPtr, stateptr); if (err != RDIError_NoError) {#ifdef DEBUG angel_DebugPrint("TADP Register failed.\n");#endif return err; } /* Set executing TRUE here, as it must be set up before the target has * had any chance at all to execute, or it may send its stopped message * before we get round to setting executing = TRUE !!! */ executing = TRUE; register_debug_message_handler();#ifdef TEST_DC_APPL Adp_Install_DC_Appl_Handler( test_dc_appl_handler );#endif#ifdef DEBUG angel_DebugPrint("Transmiting %s message.\n", type == ADP_Execute ? "execute": "step");#endif register_debug_message_handler(); /* Extra ninstr parameter for execute message will simply be ignored */ err = msgsend(CI_HADP,"%w%w%w%w%w", type | HtoT, 0, ADP_HandleUnknown, ADP_HandleUnknown, ninstr);#if DEBUG if (err != RDIError_NoError) angel_DebugPrint("Transmit failed.\n");#endif reasoncode = type | TtoH; err = wait_for_debug_message( &reasoncode, &debugID, &OSinfo1, &OSinfo2, &status, &packet ); if (err != RDIError_NoError) return err; else if (status != RDIError_NoError) return status;#ifdef DEBUG angel_DebugPrint("Waiting for program to finish...\n");#endif interrupt_request = FALSE; stop_request = FALSE; signal(SIGINT, ardi_sigint_handler); while( executing ) { if (deprecated_ui_loop_hook) deprecated_ui_loop_hook(0); if (interrupt_request || stop_request) { interrupt_target(); interrupt_request = FALSE; stop_request = FALSE; } Adp_AsynchronousProcessing( async_block_on_nothing ); } signal(SIGINT, SIG_IGN);#ifdef TEST_DC_APPL Adp_Install_DC_Appl_Handler( NULL );#endif (void)Adp_ChannelRegisterRead(CI_TADP, NULL, NULL); *handle = (PointHandle)stopped_info.data; CallStoppedProcs(stopped_info.stopped_reason); return stopped_info.stopped_status;}/* Request that the target starts executing from the stored CPU state: use ADP_Execute. */int angel_RDI_execute(PointHandle *handle){ return angel_RDI_ExecuteOrStep(handle, ADP_Execute, 0);}#ifdef __WATCOMC__typedef void handlertype(int);static int interrupted=0;static void myhandler(int sig) { IGNORE(sig); interrupted=1; signal(SIGINT, myhandler);}#endif/*----------------------------------------------------------------------*//*----angel_RDI_step-----------------------------------------------------*//*----------------------------------------------------------------------*//* Step 'ninstr' through the code: use ADP_Step. */int angel_RDI_step(unsigned ninstr, PointHandle *handle){ int err = angel_RDI_ExecuteOrStep(handle, ADP_Step, ninstr); if (err == RDIError_ProgramFinishedInStep) return RDIError_NoError; else return err;}static void SetCPWords(int cpnum, struct Dbg_CoProDesc const *cpd) { int i, rmax = 0; for (i = 0; i < cpd->entries; i++) if (cpd->regdesc[i].rmax > rmax) rmax = cpd->regdesc[i].rmax; { unsigned char *rmap = (unsigned char *)malloc(rmax + 2); *rmap++ = rmax + 1; for (i = 0; i < cpd->entries; i++) { int r; for (r = cpd->regdesc[i].rmin; r <= cpd->regdesc[i].rmax; r++) rmap[r] = (cpd->regdesc[i].nbytes+3) / 4; }/* if (cpwords[cpnum] != NULL) free(cpwords[cpnum]); */ cpwords[cpnum] = rmap; }}/*----------------------------------------------------------------------*//*----angel_RDI_info-----------------------------------------------------*//*----------------------------------------------------------------------*//* Use ADP_Info, ADP_Ctrl and ADP_Profile calls to implement these, see adp.h for more details. */static int angel_cc_exists( void ){ Packet *packet = NULL; int err; int reason, debugID, OSinfo1, OSinfo2, subreason, status;#ifdef DEBUG angel_DebugPrint("DEBUG: ADP_ICEB_CC_Exists.\n");#endif if ( angel_RDI_info( RDIInfo_Icebreaker, NULL, NULL ) == RDIError_NoError ) { register_debug_message_handler(); msgsend(CI_HADP, "%w%w%w%w%w", ADP_ICEbreakerHADP | HtoT, 0, ADP_HandleUnknown, ADP_HandleUnknown, ADP_ICEB_CC_Exists ); reason = ADP_ICEbreakerHADP |TtoH; err = wait_for_debug_message(&reason, &debugID, &OSinfo1, &OSinfo2, &status, &packet); if (err != RDIError_NoError) { DevSW_FreePacket(packet); return err; } unpack_message(BUFFERDATA(packet->pk_buffer), "%w%w%w%w%w%w", &reason, &debugID, &OSinfo1, &OSinfo2, &subreason, &status); if (subreason != ADP_ICEB_CC_Exists) { DevSW_FreePacket(packet); return RDIError_Error; } else return status; } else return RDIError_UnimplementedMessage;}typedef struct { RDICCProc_ToHost *tohost; void *tohostarg; RDICCProc_FromHost *fromhost; void *fromhostarg; bool registered;} CCState;static CCState ccstate = { NULL, NULL, NULL, NULL, FALSE };static void HandleDCCMessage( Packet *packet, void *stateptr ){ unsigned int reason, debugID, OSinfo1, OSinfo2; int count; CCState *ccstate_p = (CCState *)stateptr; count = unpack_message( BUFFERDATA(packet->pk_buffer), "%w%w%w%w", &reason, &debugID, &OSinfo1, &OSinfo2 ); switch ( reason ) { case ADP_TDCC_ToHost | TtoH: { /* only handles a single word of data, for now */ unsigned int nbytes, data; unpack_message( BUFFERDATA(packet->pk_buffer)+count, "%w%w", &nbytes, &data );#ifdef DEBUG angel_DebugPrint( "DEBUG: received CC_ToHost message: nbytes %d data %08x.\n", nbytes, data );#endif ccstate_p->tohost( ccstate_p->tohostarg, data ); msgsend(CI_TTDCC, "%w%w%w%w%w", ADP_TDCC_ToHost | HtoT, debugID, OSinfo1, OSinfo2, RDIError_NoError ); break; } case ADP_TDCC_FromHost | TtoH: { /* only handles a single word of data, for now */ int valid; ARMword data; ccstate_p->fromhost( ccstate_p->fromhostarg, &data, &valid );#ifdef DEBUG angel_DebugPrint( "DEBUG: received CC_FromHost message, returning: %08x %s.\n", data, valid ? "VALID" : "INvalid" );#endif msgsend(CI_TTDCC, "%w%w%w%w%w%w%w", ADP_TDCC_FromHost | HtoT, debugID, OSinfo1, OSinfo2, RDIError_NoError, valid ? 1 : 0, data ); break; } default:#ifdef DEBUG angel_DebugPrint( "Unexpected TDCC message %08x received\n", reason );#endif break; } DevSW_FreePacket(packet); return;}static void angel_check_DCC_handler( CCState *ccstate_p ){ int err; if ( ccstate_p->tohost != NULL || ccstate_p->fromhost != NULL ) { /* doing DCC, so need a handler */ if ( ! ccstate_p->registered ) {#ifdef DEBUG angel_DebugPrint( "Registering handler for TTDCC channel.\n" );#endif err = Adp_ChannelRegisterRead( CI_TTDCC, HandleDCCMessage, ccstate_p ); if ( err == adp_ok ) ccstate_p->registered = TRUE;#ifdef DEBUG else angel_DebugPrint( "angel_check_DCC_handler: register failed!\n" );#endif } } else { /* not doing DCC, so don't need a handler */ if ( ccstate_p->registered ) {#ifdef DEBUG angel_DebugPrint( "Unregistering handler for TTDCC channel.\n" );#endif err = Adp_ChannelRegisterRead( CI_TTDCC, NULL, NULL ); if ( err == adp_ok ) ccstate_p->registered = FALSE;#ifdef DEBUG else angel_DebugPrint( "angel_check_DCC_handler: unregister failed!\n" );#endif } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -