📄 ardi.c
字号:
signal(SIGINT, ardi_sigint_handler);#endif}static void install_ardi_handler( void ) { if (!ardi_handler_installed) { /* install a new Ctrl-C handler so we can abandon waiting */#ifdef __unix struct sigaction new_action; sigemptyset(&new_action.sa_mask); new_action.sa_handler = ardi_sigint_handler; new_action.sa_flags = 0; sigaction(SIGINT, &new_action, &old_action);#else old_handler = signal(SIGINT, ardi_sigint_handler);#endif ardi_handler_installed = TRUE; }}static int angel_RDI_errmess(char *buf, int blen, int errnum);static void receive_reset_acknowledge(Packet *packet, void *stateptr) { unsigned reason, debugID, OSinfo1, OSinfo2, status; IGNORE(stateptr); unpack_message(BUFFERDATA(packet->pk_buffer), "%w%w%w%w%w", &reason, &debugID, &OSinfo1, &OSinfo2, &status); if (reason==(ADP_Reset | TtoH) && status==AB_NORMAL_ACK) {#ifdef DEBUG angel_DebugPrint("DEBUG: Successfully received normal reset acknowledgement\n"); late_booted = FALSE;#endif } else if (reason==(ADP_Reset | TtoH) && status==AB_LATE_ACK) { char late_msg[AdpMessLen_LateStartup]; int late_len;#ifdef DEBUG angel_DebugPrint("DEBUG: Successfully received LATE reset acknowledgement\n");#endif late_booted = TRUE; install_ardi_handler(); late_len = angel_RDI_errmess(late_msg, AdpMessLen_LateStartup, adp_late_startup); angel_hostif->write(angel_hostif->hostosarg, late_msg, late_len); } else {#ifdef DEBUG angel_DebugPrint("DEBUG: Bad reset ack: reason=%8X, status=%8X\n", reason, status);#endif } DevSW_FreePacket(packet);}static int booted_not_received;static unsigned int angel_version;static unsigned int adp_version;static unsigned int arch_info;static unsigned int cpu_info;static unsigned int hw_status;static void receive_booted(Packet *packet, void *stateptr) { unsigned reason, debugID, OSinfo1, OSinfo2, banner_length, bufsiz, longsiz; unsigned i, count; IGNORE(stateptr); count = unpack_message(BUFFERDATA(packet->pk_buffer), "%w%w%w%w%w%w%w%w%w%w%w%w", &reason, &debugID, &OSinfo1, &OSinfo2, &bufsiz, &longsiz, &angel_version, &adp_version, &arch_info, &cpu_info, &hw_status, &banner_length); if (reason==(ADP_Booted | TtoH)) {#ifdef MONITOR_DOWNLOAD_PACKETS angel_DebugPrint("DEBUG: Successfully received Booted\n"); angel_DebugPrint(" cpu_info=%8X, hw_status=%8X, bufsiz=%d, longsiz=%d\n", cpu_info, hw_status, bufsiz, longsiz);#endif /* Get the banner from the booted message */ for (i=0; i<banner_length; i++) angel_hostif->writec(angel_hostif->hostosarg, (BUFFERDATA(packet->pk_buffer)+count)[i]); booted_not_received=0;#ifndef NO_HEARTBEAT heartbeat_enabled = TRUE;#endif Armsd_BufferSize = bufsiz + CHAN_HEADER_SIZE; Armsd_LongBufSize = longsiz + CHAN_HEADER_SIZE; } else {#ifdef DEBUG angel_DebugPrint("DEBUG: Bad Booted msg: reason=%8X\n", reason);#endif } DevSW_FreePacket(packet);}/* forward declaration */static int angel_negotiate_defaults( void );/* Open communications. */int angel_RDI_open( unsigned type, Dbg_ConfigBlock const *config, Dbg_HostosInterface const *hostif, struct Dbg_MCState *dbg_state){ Packet *packet; int status, reasoncode, debugID, OSinfo1, OSinfo2, err; ParameterOptions *user_options = NULL; time_t t; IGNORE( dbg_state ); if ((type & 1) == 0) { /* cold start */ if (hostif != NULL) { angel_hostif = hostif; err = HostSysInit(hostif, &ardi_commandline, &hstate); if (err != RDIError_NoError) {#ifdef DEBUG angel_DebugPrint("DEBUG: HostSysInit error %i\n",err);#endif return err; } } TargetLogInit(); }#ifdef DEBUG angel_DebugPrint("DEBUG: Buffer allocated in angel_RDI_open(type=%i).\n",type);#endif if ((type & 1) == 0) { /* cold start */ unsigned endian; Adp_Ioctl( DC_GET_USER_PARAMS, (void *)&user_options ); if ( user_options != NULL ) { err = negotiate_params( user_options ); if (err != adp_ok) return err; } else { ParameterConfig *default_config = NULL; Adp_Ioctl( DC_GET_DEFAULT_PARAMS, (void *)&default_config ); if ( default_config != NULL ) { ParameterOptions *default_options = config_to_options(default_config); err = negotiate_params( default_options ); if (err != adp_ok) return err; } } /* Register handlers before sending any messages */ booted_not_received=1; Adp_ChannelRegisterRead(CI_HBOOT, receive_reset_acknowledge, NULL); Adp_ChannelRegisterRead(CI_TBOOT, receive_booted, NULL); endian = 0; if (config!=NULL) { if (config->bytesex & RDISex_Little) endian |= ADP_BootHostFeature_LittleEnd; if (config->bytesex & RDISex_Big) endian |= ADP_BootHostFeature_BigEnd; } msgsend(CI_HBOOT,"%w%w%w%w%w", ADP_Reset | HtoT, 0, ADP_HandleUnknown, ADP_HandleUnknown, endian);#ifdef DEBUG angel_DebugPrint("DEBUG: Transmitted Reset message in angel_RDI_open.\n");#endif /* We will now either get an acknowledgement for the Reset message * or if the target was started after the host, we will get a * rebooted message first. */#ifdef DEBUG angel_DebugPrint("DEBUG: waiting for a booted message\n");#endif { boot_interrupted = FALSE; if (late_booted) install_ardi_handler(); t=time(NULL); do { Adp_AsynchronousProcessing(async_block_on_nothing); if ((time(NULL)-t) > ADP_INITIAL_TIMEOUT_PERIOD && !late_booted) { return adp_timeout_on_open; } } while (booted_not_received && !boot_interrupted); if (ardi_handler_installed) { /* uninstall our Ctrl-C handler */#ifdef __unix sigaction(SIGINT, &old_action, NULL);#else signal(SIGINT, old_handler);#endif } if (boot_interrupted) { angel_negotiate_defaults(); return adp_abandon_boot_wait; } } booted_not_received=1; Adp_ChannelRegisterRead(CI_HBOOT, NULL, NULL); /* Leave the booted handler installed */ msgsend(CI_TBOOT, "%w%w%w%w%w", ADP_Booted | HtoT, 0, ADP_HandleUnknown, ADP_HandleUnknown, 0); Adp_initSeq();#ifdef DEBUG angel_DebugPrint("DEBUG: Transmitted ADP_Booted acknowledgement.\n"); angel_DebugPrint("DEBUG: Boot sequence completed, leaving angel_RDI_open.\n");#endif return (hw_status & ADP_CPU_BigEndian )? RDIError_BigEndian : RDIError_LittleEndian; } else { /* warm start */ register_debug_message_handler(); msgsend(CI_HADP, "%w%w%w%w", ADP_InitialiseApplication | HtoT, 0, ADP_HandleUnknown, ADP_HandleUnknown);#ifdef DEBUG angel_DebugPrint("DEBUG: Transmitted Initialise Application\n");#endif reasoncode=ADP_InitialiseApplication | TtoH; err = wait_for_debug_message(&reasoncode, &debugID, &OSinfo1, &OSinfo2, &status, &packet); if (err != RDIError_NoError) return err; return status; } return -1;}/*----------------------------------------------------------------------*//*----angel_RDI_close----------------------------------------------------*//*----------------------------------------------------------------------*/static int angel_negotiate_defaults( void ) { int err = adp_ok; ParameterConfig *default_config = NULL; Adp_Ioctl( DC_GET_DEFAULT_PARAMS, (void *)&default_config ); if ( default_config != NULL ) { ParameterOptions *default_options = config_to_options(default_config); err = negotiate_params( default_options ); free( default_options ); } return err;}int angel_RDI_close(void) {/*Angel host exit */ int err; int status,debugID, OSinfo1,OSinfo2; int reason; Packet *packet = NULL;;#ifdef DEBUG angel_DebugPrint("DEBUG: Entered angel_RDI_Close.\n");#endif register_debug_message_handler(); heartbeat_enabled = FALSE; err = msgsend(CI_HADP,"%w%w%w%w",ADP_End | HtoT,0, ADP_HandleUnknown, ADP_HandleUnknown); if (err != RDIError_NoError) return err; reason = ADP_End | TtoH; err = wait_for_debug_message(&reason, &debugID, &OSinfo1, &OSinfo2, &status, &packet); DevSW_FreePacket(packet); if (err != RDIError_NoError) return err; if (status == RDIError_NoError) { err = angel_negotiate_defaults(); if (err != adp_ok) return err; Adp_Ioctl( DC_RESET, NULL ); /* just to be safe */ return HostSysExit(hstate); } else return status;}/*----------------------------------------------------------------------*//*----angel_RDI_read-----------------------------------------------------*//*----------------------------------------------------------------------*//* Read memory contents from target to host: use ADP_Read */int angel_RDI_read(ARMword source, void *dest, unsigned *nbytes){ Packet *packet=NULL; int len; /* Integer to hold message length. */ unsigned int nbtogo = *nbytes, nbinpacket, nbdone=0; int rnbytes = 0, status, reason, debugID, OSinfo1, OSinfo2, err; unsigned int maxlen = Armsd_BufferSize-CHAN_HEADER_SIZE-ADP_ReadHeaderSize; /* Print debug trace information, this is just copied straight from rdi.c and I can see no reason why it should have to be changed. */ TracePrint(("angel_RDI_read: source=%.8lx dest=%p nbytes=%.8x\n", (unsigned long)source, dest, *nbytes)); if (*nbytes == 0) return RDIError_NoError; /* Read nothing - easy! */ /* check the buffer size */ while (nbtogo >0) { register_debug_message_handler(); nbinpacket = (nbtogo <= maxlen) ? nbtogo : maxlen; len = msgsend(CI_HADP, "%w%w%w%w%w%w", ADP_Read | HtoT, 0, ADP_HandleUnknown, ADP_HandleUnknown, source+nbdone, nbinpacket); reason=ADP_Read | TtoH; err = wait_for_debug_message(&reason, &debugID, &OSinfo1, &OSinfo2, &status, &packet); TracePrint(("angel_RDI_read: nbinpacket =%d status=%08x err = %d\n", nbinpacket,status,err)); if (err != RDIError_NoError) return err; /* Was there an error? */ if (status == RDIError_NoError){ rnbytes += PREAD(LE,(unsigned int *)(BUFFERDATA(packet->pk_buffer)+20)); TracePrint(("angel_RDI_read: rnbytes = %d\n",rnbytes)); memcpy(((unsigned char *)dest)+nbdone, BUFFERDATA(packet->pk_buffer)+24, nbinpacket); } nbdone += nbinpacket; nbtogo -= nbinpacket; } *nbytes -= rnbytes; return status;}/*----------------------------------------------------------------------*//*----angel_RDI_write----------------------------------------------------*//*----------------------------------------------------------------------*//* Transfer memory block from host to target. Use ADP_Write>. */int angel_RDI_write(const void *source, ARMword dest, unsigned *nbytes){ Packet *packet;/* Message buffers. */ unsigned int len, nbtogo = *nbytes, nboffset = 0, nbinpacket; int status, reason, debugID, OSinfo1, OSinfo2, err; unsigned int maxlen = Armsd_LongBufSize-CHAN_HEADER_SIZE-ADP_WriteHeaderSize; TracePrint(("angel_RDI_write: source=%p dest=%.8lx nbytes=%.8x\n", source, (unsigned long)dest, *nbytes)); if (*nbytes == 0) return RDIError_NoError; *nbytes = 0; while (nbtogo > 0) { packet = (Packet *) DevSW_AllocatePacket(Armsd_LongBufSize); nbinpacket = (nbtogo <= maxlen) ? nbtogo : maxlen; len = msgbuild(BUFFERDATA(packet->pk_buffer), "%w%w%w%w%w%w", ADP_Write | HtoT, 0, ADP_HandleUnknown, ADP_HandleUnknown, dest+nboffset, nbinpacket); /* Copy the data into the packet. */ memcpy(BUFFERDATA(packet->pk_buffer)+len, ((const unsigned char *) source)+nboffset, nbinpacket); nboffset += nbinpacket; packet->pk_length = nbinpacket+len;#ifdef MONITOR_DOWNLOAD_PACKETS angel_DebugPrint("angel_RDI_write packet size=%i, bytes done=%i\n", nbinpacket, nboffset);#endif register_debug_message_handler(); Adp_ChannelWrite(CI_HADP, packet); reason=ADP_Write | TtoH; err = wait_for_debug_message(&reason, &debugID, &OSinfo1, &OSinfo2, &status, &packet); nbtogo -= nbinpacket; if (err != RDIError_NoError) return err; if (status == RDIError_NoError) *nbytes += nbinpacket; DevSW_FreePacket(packet); } return status;}/*----------------------------------------------------------------------*//*----angel_RDI_CPUread--------------------------------------------------*//*----------------------------------------------------------------------*//* Reads the values of registers in the CPU, uses ADP_CPUwrite. */int angel_RDI_CPUread(unsigned mode, unsigned long mask, ARMword *buffer){ unsigned int i, j; Packet *packet = NULL; int err, status, reason, debugID, OSinfo1, OSinfo2;#ifdef DEBUG angel_DebugPrint("DEBUG: Entered angel_RDI_CPUread.\n");#endif for (i=0, j=0 ; i < RDINumCPURegs ; i++) if (mask & (1L << i)) j++; /* Count the number of registers. */ register_debug_message_handler(); msgsend(CI_HADP, "%w%w%w%w%c%w", ADP_CPUread | HtoT, 0, ADP_HandleUnknown, ADP_HandleUnknown, mode, mask); reason = ADP_CPUread | TtoH; err = wait_for_debug_message(&reason, &debugID, &OSinfo1, &OSinfo2, &status, &packet); if (err != RDIError_NoError) { DevSW_FreePacket(packet);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -