Commit | Line | Data |
---|---|---|
c906108c SS |
1 | /* |
2 | * Copyright (C) 1995 Advanced RISC Machines Limited. All rights reserved. | |
3 | * | |
4 | * This software may be freely used, copied, modified, and distributed | |
5 | * provided that the above copyright notice is preserved in all copies of the | |
6 | * software. | |
7 | */ | |
8 | ||
9 | /* | |
10 | * ARDI.c | |
11 | * Angel Remote Debug Interface | |
12 | * | |
13 | * | |
14 | * $Revision$ | |
15 | * $Date$ | |
16 | * | |
17 | * This file is based on /plg/pisd/rdi.c, but instead of using RDP it uses | |
18 | * ADP messages. | |
19 | */ | |
20 | ||
21 | #include <stdarg.h> | |
22 | #include <stdio.h> | |
23 | #include <stdlib.h> | |
24 | #include <string.h> | |
25 | #define uint HIDE_HPs_uint | |
26 | #include <signal.h> | |
27 | #undef uint | |
28 | ||
29 | ||
5c44784c | 30 | #include "angel_endian.h" |
c906108c SS |
31 | #include "ardi.h" |
32 | #include "buffers.h" | |
33 | #include "channels.h" | |
34 | #include "hostchan.h" | |
35 | #include "host.h" | |
5c44784c | 36 | #include "angel_bytesex.h" |
c906108c SS |
37 | #include "dbg_cp.h" |
38 | #include "adp.h" | |
39 | #include "hsys.h" | |
40 | #include "logging.h" | |
41 | #include "msgbuild.h" | |
42 | #include "rxtx.h" | |
43 | #include "devsw.h" | |
44 | #include "params.h" | |
45 | ||
46 | #ifdef COMPILING_ON_WINDOWS | |
47 | # define IGNORE(x) (x = x) /* must go after #includes to work on Windows */ | |
48 | #endif | |
49 | #define NOT(x) (!(x)) | |
50 | ||
51 | #define ADP_INITIAL_TIMEOUT_PERIOD 5 | |
52 | ||
53 | static volatile int executing; | |
54 | static int rdi_log = 0 ; /* debugging ? */ | |
55 | ||
56 | /* we need a starting point for our first buffers, this is a safe one */ | |
57 | int Armsd_BufferSize = ADP_BUFFER_MIN_SIZE; | |
58 | int Armsd_LongBufSize = ADP_BUFFER_MIN_SIZE; | |
59 | ||
60 | #ifdef WIN32 | |
61 | extern int interrupted; | |
62 | extern int swiprocessing; | |
63 | #endif | |
64 | ||
65 | static char dummycline = 0; | |
66 | char *ardi_commandline = &dummycline ; /* exported in ardi.h */ | |
67 | ||
68 | extern unsigned int heartbeat_enabled; | |
69 | ||
70 | static unsigned char *cpwords[16]; | |
71 | ||
72 | typedef struct stoppedProcListElement { | |
73 | struct stoppedProcListElement *next; | |
74 | angel_RDI_TargetStoppedProc *fn; | |
75 | void *arg; | |
76 | } stoppedProcListElement; | |
77 | ||
78 | static stoppedProcListElement *stopped_proc_list=NULL; | |
79 | ||
80 | const struct Dbg_HostosInterface *angel_hostif; | |
81 | static hsys_state *hstate; | |
82 | ||
83 | static void angel_DebugPrint(const char *format, ...) | |
84 | { va_list ap; | |
85 | va_start(ap, format); | |
86 | angel_hostif->dbgprint(angel_hostif->dbgarg, format, ap); | |
87 | va_end(ap); | |
88 | } | |
89 | ||
90 | #ifdef RDI_VERBOSE | |
91 | #define TracePrint(s) \ | |
92 | if (rdi_log & 2) angel_DebugPrint("\n"); \ | |
93 | if (rdi_log & 1) angel_DebugPrint s | |
94 | #else | |
95 | #define TracePrint(s) | |
96 | #endif | |
97 | ||
98 | typedef struct receive_dbgmsg_state { | |
99 | volatile int received; | |
100 | Packet *packet; | |
101 | } receive_dbgmsg_state; | |
102 | ||
103 | static receive_dbgmsg_state dbgmsg_state; | |
104 | ||
105 | static void receive_debug_packet(Packet *packet, void *stateptr) | |
106 | { | |
107 | receive_dbgmsg_state *state = stateptr; | |
108 | ||
109 | state->packet = packet; | |
110 | state->received = 1; | |
111 | } | |
112 | ||
113 | static int register_debug_message_handler(void) | |
114 | { | |
115 | int err; | |
116 | dbgmsg_state.received = 0; | |
117 | ||
118 | err = Adp_ChannelRegisterRead(CI_HADP, receive_debug_packet, &dbgmsg_state); | |
119 | #ifdef DEBUG | |
120 | if (err!=adp_ok) angel_DebugPrint("register_debug_message_handler failed %i\n", err); | |
121 | #endif | |
122 | return err; | |
123 | } | |
124 | ||
125 | ||
126 | static int wait_for_debug_message(int *rcode, int *debugID, | |
127 | int *OSinfo1, int *OSinfo2, | |
128 | int *status, Packet **packet) | |
129 | { | |
130 | unsigned int reason; | |
131 | ||
132 | #ifdef DEBUG | |
133 | angel_DebugPrint("wait_for_debug_message waiting for %X\n", *rcode); | |
134 | #endif | |
135 | ||
136 | for ( ; dbgmsg_state.received == 0 ; ) | |
137 | Adp_AsynchronousProcessing(async_block_on_read); | |
138 | ||
139 | #ifdef DEBUG | |
140 | angel_DebugPrint("wait_for_debug_message got packet\n"); | |
141 | #endif | |
142 | ||
143 | *packet = dbgmsg_state.packet; | |
144 | ||
145 | Adp_ChannelRegisterRead(CI_HADP, NULL, NULL); | |
146 | ||
147 | /* | |
148 | * TODO: | |
149 | * If ADP_Unrecognised return error. | |
150 | * If ADP_Acknowledge - handle appropriately. | |
151 | * If expected message read arguments and return RDIError_NoError. | |
152 | * Note: if RDIError occurs then the data values returned are junk | |
153 | */ | |
154 | ||
155 | unpack_message(BUFFERDATA((*packet)->pk_buffer), "%w%w%w%w%w", &reason, debugID, | |
156 | OSinfo1, OSinfo2, status); | |
157 | if (reason&0xffffff == ADP_HADPUnrecognised) | |
158 | return RDIError_UnimplementedMessage; | |
159 | if (reason != (unsigned ) *rcode) { | |
160 | if((reason&0xffffff) == ADP_HADPUnrecognised) | |
161 | return RDIError_UnimplementedMessage; | |
162 | else { | |
163 | angel_DebugPrint("ARDI ERROR: Expected reasoncode %x got reasoncode %x.\n", | |
164 | *rcode, reason); | |
165 | return RDIError_Error; | |
166 | } | |
167 | } | |
168 | else | |
169 | return RDIError_NoError; | |
170 | return RDIError_Error; /* stop a pesky ANSI compiler warning */ | |
171 | } | |
172 | ||
173 | ||
174 | /* | |
175 | * Handler and registration for logging messages from target | |
176 | */ | |
177 | static void TargetLogCallback( Packet *packet, void *state ) | |
178 | { | |
179 | p_Buffer reply = BUFFERDATA(packet->pk_buffer); | |
180 | unsigned int len = packet->pk_length; | |
181 | IGNORE(state); | |
182 | angel_hostif->write(angel_hostif->hostosarg, | |
183 | (char *)reply, len - CHAN_HEADER_SIZE); | |
184 | DevSW_FreePacket(packet); | |
185 | ||
186 | packet = DevSW_AllocatePacket(4); /* better not ask for 0 */ | |
187 | /* the reply is the ACK - any contents are ignored */ | |
188 | if (packet != NULL) | |
189 | Adp_ChannelWrite( CI_TLOG, packet ); | |
190 | } | |
191 | ||
192 | static void TargetLogInit( void ) | |
193 | { | |
194 | AdpErrs err = Adp_ChannelRegisterRead( CI_TLOG, TargetLogCallback, NULL ); | |
195 | ||
196 | #ifdef DEBUG | |
197 | if (err != adp_ok) | |
198 | angel_DebugPrint("CI_TLOG RegisterRead failed %d\n", err); | |
199 | #else | |
200 | IGNORE(err); | |
201 | #endif | |
202 | } | |
203 | ||
204 | /*----------------------------------------------------------------------*/ | |
205 | /*----angel_RDI_open-----------------------------------------------------*/ | |
206 | /*----------------------------------------------------------------------*/ | |
207 | ||
208 | typedef struct NegotiateState { | |
209 | bool negotiate_resp; | |
210 | bool negotiate_ack; | |
211 | bool link_check_resp; | |
212 | ParameterConfig *accepted_config; | |
213 | } NegotiateState; | |
214 | ||
215 | static void receive_negotiate(Packet *packet, void *stateptr) | |
216 | { | |
217 | unsigned reason, debugID, OSinfo1, OSinfo2, status; | |
218 | NegotiateState *n_state = (NegotiateState *)stateptr; | |
219 | p_Buffer reply = BUFFERDATA(packet->pk_buffer); | |
220 | ||
221 | unpack_message( reply, "%w%w%w%w", | |
222 | &reason, &debugID, &OSinfo1, &OSinfo2 ); | |
223 | reply += ADP_DEFAULT_HEADER_SIZE; | |
224 | ||
225 | #ifdef DEBUG | |
226 | angel_DebugPrint( "receive_negotiate: reason %x\n", reason ); | |
227 | #endif | |
228 | ||
229 | switch ( reason ) | |
230 | { | |
231 | case ADP_ParamNegotiate | TtoH: | |
232 | { | |
233 | n_state->negotiate_resp = TRUE; | |
234 | ||
235 | status = GET32LE( reply ); | |
236 | reply += sizeof(word); | |
237 | #ifdef DEBUG | |
238 | angel_DebugPrint( "ParamNegotiate status %u\n", status ); | |
239 | #endif | |
240 | if ( status == RDIError_NoError ) | |
241 | { | |
242 | if ( Angel_ReadParamConfigMessage( | |
243 | reply, n_state->accepted_config ) ) | |
244 | n_state->negotiate_ack = TRUE; | |
245 | } | |
246 | break; | |
247 | } | |
248 | ||
249 | case ADP_LinkCheck | TtoH: | |
250 | { | |
251 | #ifdef DEBUG | |
252 | angel_DebugPrint( "PONG!\n" ); | |
253 | #endif | |
254 | n_state->link_check_resp = TRUE; | |
255 | break; | |
256 | } | |
257 | ||
258 | default: | |
259 | { | |
260 | #ifdef DEBUG | |
261 | angel_DebugPrint( "Unexpected!\n" ); | |
262 | #endif | |
263 | break; | |
264 | } | |
265 | } | |
266 | DevSW_FreePacket( packet ); | |
267 | } | |
268 | ||
269 | # include <sys/types.h> | |
270 | #ifdef __unix | |
271 | # include <sys/time.h> | |
272 | #else | |
273 | # include <time.h> | |
274 | #endif | |
275 | ||
276 | /* | |
277 | * convert a config into a single-valued options list | |
278 | */ | |
279 | static ParameterOptions *config_to_options( const ParameterConfig *config ) | |
280 | { | |
281 | unsigned int num_params; | |
282 | size_t size; | |
283 | ParameterOptions *base_p; | |
284 | ||
285 | num_params = config->num_parameters; | |
286 | size = | |
287 | sizeof(ParameterOptions) | |
288 | + num_params*(sizeof(ParameterList) + sizeof(unsigned int)); | |
289 | base_p = malloc( size ); | |
290 | ||
291 | if ( base_p != NULL ) | |
292 | { | |
293 | unsigned int u; | |
294 | ParameterList *list_p = | |
295 | (ParameterList *)((char *)base_p + sizeof(ParameterOptions)); | |
296 | unsigned int *option_p = | |
297 | (unsigned int *)(list_p + num_params); | |
298 | ||
299 | base_p->num_param_lists = num_params; | |
300 | base_p->param_list = list_p; | |
301 | ||
302 | for ( u = 0; u < num_params; ++u ) | |
303 | { | |
304 | option_p[u] = config->param[u].value; | |
305 | list_p[u].type = config->param[u].type; | |
306 | list_p[u].num_options = 1; | |
307 | list_p[u].option = &option_p[u]; | |
308 | } | |
309 | } | |
310 | ||
311 | return base_p; | |
312 | } | |
313 | ||
314 | static AdpErrs negotiate_params( const ParameterOptions *user_options ) | |
315 | { | |
316 | Packet *packet; | |
317 | unsigned int count; | |
318 | static Parameter params[AP_NUM_PARAMS]; | |
319 | static ParameterConfig accepted_config = { AP_NUM_PARAMS, params }; | |
320 | ||
321 | time_t t; | |
322 | ||
323 | static volatile NegotiateState n_state = { | |
324 | FALSE, FALSE, FALSE, &accepted_config }; | |
325 | ||
326 | #ifdef DEBUG | |
327 | angel_DebugPrint( "negotiate_params\n" ); | |
328 | #endif | |
329 | ||
330 | Adp_ChannelRegisterRead( CI_HBOOT, receive_negotiate, (void *)&n_state ); | |
331 | ||
332 | packet = (Packet *)DevSW_AllocatePacket(Armsd_BufferSize); | |
333 | count = msgbuild( BUFFERDATA(packet->pk_buffer), "%w%w%w%w", | |
334 | ADP_ParamNegotiate | HtoT, 0, | |
335 | ADP_HandleUnknown, ADP_HandleUnknown ); | |
336 | count += Angel_BuildParamOptionsMessage( | |
337 | BUFFERDATA(packet->pk_buffer) + count, user_options ); | |
338 | packet->pk_length = count; | |
339 | Adp_ChannelWriteAsync( CI_HBOOT, packet ); | |
340 | ||
341 | #ifdef DEBUG | |
342 | angel_DebugPrint( "sent negotiate packet\n" ); | |
343 | #endif | |
344 | ||
345 | t=time(NULL); | |
346 | ||
347 | do { | |
348 | Adp_AsynchronousProcessing(async_block_on_nothing); | |
349 | ||
350 | if ((time(NULL)-t) > ADP_INITIAL_TIMEOUT_PERIOD) { | |
351 | return adp_timeout_on_open; | |
352 | } | |
353 | } while ( ! n_state.negotiate_resp ); | |
354 | ||
355 | if ( n_state.negotiate_ack ) | |
356 | { | |
357 | /* select accepted config */ | |
358 | Adp_Ioctl( DC_SET_PARAMS, (void *)n_state.accepted_config ); | |
359 | ||
360 | /* | |
361 | * 960430 KWelton | |
362 | * | |
363 | * There is a race in the renegotiation protocol: the | |
364 | * target has to have had time to load new config before | |
365 | * we send the link check packet - insert a deliberate | |
366 | * pause (100ms) to give the target some time | |
367 | */ | |
368 | Adp_delay(100000); | |
369 | ||
370 | /* do link check */ | |
371 | msgsend( CI_HBOOT, "%w%w%w%w", ADP_LinkCheck | HtoT, 0, | |
372 | ADP_HandleUnknown, ADP_HandleUnknown ); | |
373 | #ifdef DEBUG | |
374 | angel_DebugPrint("sent link check\n"); | |
375 | #endif | |
376 | ||
377 | do { | |
378 | Adp_AsynchronousProcessing(async_block_on_read); | |
379 | } while ( ! n_state.link_check_resp ); | |
380 | Adp_initSeq(); | |
381 | } | |
382 | return adp_ok; | |
383 | } | |
384 | ||
385 | static int late_booted = FALSE; | |
386 | static bool ardi_handler_installed = FALSE; | |
387 | ||
388 | #ifdef __unix | |
389 | static struct sigaction old_action; | |
390 | #else | |
391 | static void (*old_handler)(); | |
392 | #endif | |
393 | ||
394 | static bool boot_interrupted = FALSE; | |
c3f6f71d | 395 | static volatile bool interrupt_request = FALSE; |
c906108c SS |
396 | |
397 | static void ardi_sigint_handler(int sig) { | |
398 | #ifdef DEBUG | |
399 | if (sig != SIGINT) | |
400 | angel_DebugPrint("Expecting SIGINT got %d.\n", sig); | |
401 | #else | |
402 | IGNORE(sig); | |
403 | #endif | |
404 | boot_interrupted = TRUE; | |
c3f6f71d | 405 | interrupt_request = TRUE; |
c906108c SS |
406 | #ifndef __unix |
407 | signal(SIGINT, ardi_sigint_handler); | |
408 | #endif | |
409 | } | |
410 | ||
411 | static void install_ardi_handler( void ) { | |
412 | if (!ardi_handler_installed) { | |
413 | /* install a new Ctrl-C handler so we can abandon waiting */ | |
414 | #ifdef __unix | |
415 | struct sigaction new_action; | |
416 | sigemptyset(&new_action.sa_mask); | |
417 | new_action.sa_handler = ardi_sigint_handler; | |
418 | new_action.sa_flags = 0; | |
419 | sigaction(SIGINT, &new_action, &old_action); | |
420 | #else | |
421 | old_handler = signal(SIGINT, ardi_sigint_handler); | |
422 | #endif | |
423 | ardi_handler_installed = TRUE; | |
424 | } | |
425 | } | |
426 | ||
427 | static int angel_RDI_errmess(char *buf, int blen, int errnum); | |
428 | ||
429 | static void receive_reset_acknowledge(Packet *packet, void *stateptr) { | |
430 | unsigned reason, debugID, OSinfo1, OSinfo2, status; | |
431 | IGNORE(stateptr); | |
432 | ||
433 | unpack_message(BUFFERDATA(packet->pk_buffer), "%w%w%w%w%w", &reason, &debugID, | |
434 | &OSinfo1, &OSinfo2, &status); | |
435 | if (reason==(ADP_Reset | TtoH) && status==AB_NORMAL_ACK) { | |
436 | #ifdef DEBUG | |
437 | angel_DebugPrint("DEBUG: Successfully received normal reset acknowledgement\n"); | |
438 | late_booted = FALSE; | |
439 | #endif | |
440 | } else if (reason==(ADP_Reset | TtoH) && status==AB_LATE_ACK) { | |
441 | char late_msg[AdpMessLen_LateStartup]; | |
442 | int late_len; | |
443 | #ifdef DEBUG | |
444 | angel_DebugPrint("DEBUG: Successfully received LATE reset acknowledgement\n"); | |
445 | #endif | |
446 | late_booted = TRUE; | |
447 | install_ardi_handler(); | |
448 | late_len = angel_RDI_errmess(late_msg, | |
449 | AdpMessLen_LateStartup, adp_late_startup); | |
450 | angel_hostif->write(angel_hostif->hostosarg, late_msg, late_len); | |
451 | } else { | |
452 | #ifdef DEBUG | |
453 | angel_DebugPrint("DEBUG: Bad reset ack: reason=%8X, status=%8X\n", reason, status); | |
454 | #endif | |
455 | } | |
456 | DevSW_FreePacket(packet); | |
457 | } | |
458 | ||
459 | static int booted_not_received; | |
460 | static unsigned int angel_version; | |
461 | static unsigned int adp_version; | |
462 | static unsigned int arch_info; | |
463 | static unsigned int cpu_info; | |
464 | static unsigned int hw_status; | |
465 | ||
466 | static void receive_booted(Packet *packet, void *stateptr) { | |
467 | unsigned reason, debugID, OSinfo1, OSinfo2, banner_length, bufsiz, longsiz; | |
468 | unsigned i, count; | |
469 | ||
470 | IGNORE(stateptr); | |
471 | ||
472 | count = unpack_message(BUFFERDATA(packet->pk_buffer), | |
473 | "%w%w%w%w%w%w%w%w%w%w%w%w", | |
474 | &reason, &debugID, &OSinfo1, &OSinfo2, &bufsiz, &longsiz, | |
475 | &angel_version, &adp_version, | |
476 | &arch_info, &cpu_info, &hw_status, &banner_length); | |
477 | if (reason==(ADP_Booted | TtoH)) { | |
478 | #ifdef MONITOR_DOWNLOAD_PACKETS | |
479 | angel_DebugPrint("DEBUG: Successfully received Booted\n"); | |
480 | angel_DebugPrint(" cpu_info=%8X, hw_status=%8X, bufsiz=%d, longsiz=%d\n", | |
481 | cpu_info, hw_status, bufsiz, longsiz); | |
482 | #endif | |
483 | /* Get the banner from the booted message */ | |
484 | for (i=0; i<banner_length; i++) | |
485 | angel_hostif->writec(angel_hostif->hostosarg, | |
486 | (BUFFERDATA(packet->pk_buffer)+count)[i]); | |
487 | ||
488 | booted_not_received=0; | |
489 | #ifndef NO_HEARTBEAT | |
490 | heartbeat_enabled = TRUE; | |
491 | #endif | |
492 | Armsd_BufferSize = bufsiz + CHAN_HEADER_SIZE; | |
493 | Armsd_LongBufSize = longsiz + CHAN_HEADER_SIZE; | |
494 | } else { | |
495 | #ifdef DEBUG | |
496 | angel_DebugPrint("DEBUG: Bad Booted msg: reason=%8X\n", reason); | |
497 | #endif | |
498 | } | |
499 | DevSW_FreePacket(packet); | |
500 | } | |
501 | ||
502 | ||
503 | /* forward declaration */ | |
504 | static int angel_negotiate_defaults( void ); | |
505 | ||
506 | /* Open communications. */ | |
507 | int angel_RDI_open( | |
508 | unsigned type, Dbg_ConfigBlock const *config, | |
509 | Dbg_HostosInterface const *hostif, struct Dbg_MCState *dbg_state) | |
510 | { | |
511 | Packet *packet; | |
512 | int status, reasoncode, debugID, OSinfo1, OSinfo2, err; | |
513 | ParameterOptions *user_options = NULL; | |
514 | ||
515 | time_t t; | |
516 | ||
517 | IGNORE( dbg_state ); | |
518 | ||
519 | if ((type & 1) == 0) { | |
520 | /* cold start */ | |
521 | if (hostif != NULL) { | |
522 | angel_hostif = hostif; | |
523 | err = HostSysInit(hostif, &ardi_commandline, &hstate); | |
524 | if (err != RDIError_NoError) { | |
525 | #ifdef DEBUG | |
526 | angel_DebugPrint("DEBUG: HostSysInit error %i\n",err); | |
527 | #endif | |
528 | return err; | |
529 | } | |
530 | } | |
531 | TargetLogInit(); | |
532 | } | |
533 | ||
534 | #ifdef DEBUG | |
535 | angel_DebugPrint("DEBUG: Buffer allocated in angel_RDI_open(type=%i).\n",type); | |
536 | #endif | |
537 | ||
538 | if ((type & 1) == 0) { | |
539 | /* cold start */ | |
540 | unsigned endian; | |
541 | Adp_Ioctl( DC_GET_USER_PARAMS, (void *)&user_options ); | |
542 | if ( user_options != NULL ) { | |
543 | err = negotiate_params( user_options ); | |
544 | if (err != adp_ok) return err; | |
545 | } | |
546 | else { | |
547 | ParameterConfig *default_config = NULL; | |
548 | Adp_Ioctl( DC_GET_DEFAULT_PARAMS, (void *)&default_config ); | |
549 | if ( default_config != NULL ) { | |
550 | ParameterOptions *default_options = config_to_options(default_config); | |
551 | err = negotiate_params( default_options ); | |
552 | if (err != adp_ok) return err; | |
553 | } | |
554 | } | |
555 | ||
556 | /* Register handlers before sending any messages */ | |
557 | booted_not_received=1; | |
558 | Adp_ChannelRegisterRead(CI_HBOOT, receive_reset_acknowledge, NULL); | |
559 | Adp_ChannelRegisterRead(CI_TBOOT, receive_booted, NULL); | |
560 | endian = 0; | |
561 | if (config!=NULL) { | |
562 | if (config->bytesex & RDISex_Little) endian |= ADP_BootHostFeature_LittleEnd; | |
563 | if (config->bytesex & RDISex_Big) endian |= ADP_BootHostFeature_BigEnd; | |
564 | } | |
565 | msgsend(CI_HBOOT,"%w%w%w%w%w", ADP_Reset | HtoT, 0, | |
566 | ADP_HandleUnknown, ADP_HandleUnknown, endian); | |
567 | #ifdef DEBUG | |
568 | angel_DebugPrint("DEBUG: Transmitted Reset message in angel_RDI_open.\n"); | |
569 | #endif | |
570 | ||
571 | /* We will now either get an acknowledgement for the Reset message | |
572 | * or if the target was started after the host, we will get a | |
573 | * rebooted message first. | |
574 | */ | |
575 | ||
576 | #ifdef DEBUG | |
577 | angel_DebugPrint("DEBUG: waiting for a booted message\n"); | |
578 | #endif | |
579 | ||
580 | { | |
581 | boot_interrupted = FALSE; | |
582 | ||
583 | if (late_booted) | |
584 | install_ardi_handler(); | |
585 | ||
586 | t=time(NULL); | |
587 | ||
588 | do { | |
589 | Adp_AsynchronousProcessing(async_block_on_nothing); | |
590 | if ((time(NULL)-t) > ADP_INITIAL_TIMEOUT_PERIOD && !late_booted) { | |
591 | return adp_timeout_on_open; | |
592 | } | |
593 | } while (booted_not_received && !boot_interrupted); | |
594 | ||
595 | if (ardi_handler_installed) | |
596 | { | |
597 | /* uninstall our Ctrl-C handler */ | |
598 | #ifdef __unix | |
599 | sigaction(SIGINT, &old_action, NULL); | |
600 | #else | |
601 | signal(SIGINT, old_handler); | |
602 | #endif | |
603 | } | |
604 | ||
605 | if (boot_interrupted) { | |
606 | angel_negotiate_defaults(); | |
607 | return adp_abandon_boot_wait; | |
608 | } | |
609 | } | |
610 | ||
611 | booted_not_received=1; | |
612 | Adp_ChannelRegisterRead(CI_HBOOT, NULL, NULL); | |
613 | ||
614 | /* Leave the booted handler installed */ | |
615 | msgsend(CI_TBOOT, "%w%w%w%w%w", ADP_Booted | HtoT, 0, | |
616 | ADP_HandleUnknown, ADP_HandleUnknown, 0); | |
617 | Adp_initSeq(); | |
618 | #ifdef DEBUG | |
619 | angel_DebugPrint("DEBUG: Transmitted ADP_Booted acknowledgement.\n"); | |
620 | angel_DebugPrint("DEBUG: Boot sequence completed, leaving angel_RDI_open.\n"); | |
621 | #endif | |
622 | ||
623 | return (hw_status & ADP_CPU_BigEndian )? RDIError_BigEndian : | |
624 | RDIError_LittleEndian; | |
625 | } | |
626 | else { | |
627 | /* warm start */ | |
628 | register_debug_message_handler(); | |
629 | ||
630 | msgsend(CI_HADP, "%w%w%w%w", | |
631 | ADP_InitialiseApplication | HtoT, 0, | |
632 | ADP_HandleUnknown, ADP_HandleUnknown); | |
633 | #ifdef DEBUG | |
634 | angel_DebugPrint("DEBUG: Transmitted Initialise Application\n"); | |
635 | #endif | |
636 | reasoncode=ADP_InitialiseApplication | TtoH; | |
637 | err = wait_for_debug_message(&reasoncode, &debugID, &OSinfo1, &OSinfo2, | |
638 | &status, &packet); | |
639 | if (err != RDIError_NoError) return err; | |
640 | return status; | |
641 | } | |
642 | return -1; | |
643 | } | |
644 | ||
645 | ||
646 | /*----------------------------------------------------------------------*/ | |
647 | /*----angel_RDI_close----------------------------------------------------*/ | |
648 | /*----------------------------------------------------------------------*/ | |
649 | ||
650 | static int angel_negotiate_defaults( void ) { | |
651 | int err = adp_ok; | |
652 | ParameterConfig *default_config = NULL; | |
653 | Adp_Ioctl( DC_GET_DEFAULT_PARAMS, (void *)&default_config ); | |
654 | if ( default_config != NULL ) { | |
655 | ParameterOptions *default_options = config_to_options(default_config); | |
656 | err = negotiate_params( default_options ); | |
657 | free( default_options ); | |
658 | } | |
659 | return err; | |
660 | } | |
661 | ||
662 | int angel_RDI_close(void) { | |
663 | /*Angel host exit */ | |
664 | int err; | |
665 | int status,debugID, OSinfo1,OSinfo2; | |
666 | int reason; | |
667 | Packet *packet = NULL;; | |
668 | #ifdef DEBUG | |
669 | angel_DebugPrint("DEBUG: Entered angel_RDI_Close.\n"); | |
670 | #endif | |
671 | ||
672 | register_debug_message_handler(); | |
673 | ||
674 | heartbeat_enabled = FALSE; | |
675 | ||
676 | err = msgsend(CI_HADP,"%w%w%w%w",ADP_End | HtoT,0, | |
677 | ADP_HandleUnknown, ADP_HandleUnknown); | |
678 | if (err != RDIError_NoError) return err; | |
679 | reason = ADP_End | TtoH; | |
680 | err = wait_for_debug_message(&reason, &debugID, &OSinfo1, &OSinfo2, | |
681 | &status, &packet); | |
682 | DevSW_FreePacket(packet); | |
683 | if (err != RDIError_NoError) return err; | |
684 | if (status == RDIError_NoError) { | |
685 | err = angel_negotiate_defaults(); | |
686 | if (err != adp_ok) return err; | |
687 | Adp_Ioctl( DC_RESET, NULL ); /* just to be safe */ | |
688 | return HostSysExit(hstate); | |
689 | } | |
690 | else | |
691 | return status; | |
692 | } | |
693 | ||
694 | ||
695 | /*----------------------------------------------------------------------*/ | |
696 | /*----angel_RDI_read-----------------------------------------------------*/ | |
697 | /*----------------------------------------------------------------------*/ | |
698 | ||
699 | /* Read memory contents from target to host: use ADP_Read */ | |
700 | int angel_RDI_read(ARMword source, void *dest, unsigned *nbytes) | |
701 | { | |
702 | Packet *packet=NULL; | |
703 | int len; /* Integer to hold message length. */ | |
704 | unsigned int nbtogo = *nbytes, nbinpacket, nbdone=0; | |
705 | int rnbytes = 0, status, reason, debugID, OSinfo1, OSinfo2, err; | |
706 | unsigned int maxlen = Armsd_BufferSize-CHAN_HEADER_SIZE-ADP_ReadHeaderSize; | |
707 | ||
708 | /* Print debug trace information, this is just copied straight from rdi.c | |
709 | and I can see no reason why it should have to be changed. */ | |
710 | TracePrint(("angel_RDI_read: source=%.8lx dest=%p nbytes=%.8x\n", | |
711 | (unsigned long)source, dest, *nbytes)); | |
712 | if (*nbytes == 0) return RDIError_NoError; /* Read nothing - easy! */ | |
713 | /* check the buffer size */ | |
714 | while (nbtogo >0) { | |
715 | register_debug_message_handler(); | |
716 | ||
717 | nbinpacket = (nbtogo <= maxlen) ? nbtogo : maxlen; | |
718 | len = msgsend(CI_HADP, "%w%w%w%w%w%w", ADP_Read | HtoT, 0, | |
719 | ADP_HandleUnknown, ADP_HandleUnknown, source+nbdone, | |
720 | nbinpacket); | |
721 | reason=ADP_Read | TtoH; | |
722 | err = wait_for_debug_message(&reason, &debugID, &OSinfo1, &OSinfo2, | |
723 | &status, &packet); | |
724 | TracePrint(("angel_RDI_read: nbinpacket =%d status=%08x err = %d\n", | |
725 | nbinpacket,status,err)); | |
726 | if (err != RDIError_NoError) return err; /* Was there an error? */ | |
727 | if (status == RDIError_NoError){ | |
728 | rnbytes += PREAD(LE,(unsigned int *)(BUFFERDATA(packet->pk_buffer)+20)); | |
729 | TracePrint(("angel_RDI_read: rnbytes = %d\n",rnbytes)); | |
730 | memcpy(((unsigned char *)dest)+nbdone, BUFFERDATA(packet->pk_buffer)+24, | |
731 | nbinpacket); | |
732 | } | |
733 | nbdone += nbinpacket; | |
734 | nbtogo -= nbinpacket; | |
735 | } | |
736 | *nbytes -= rnbytes; | |
737 | return status; | |
738 | } | |
739 | ||
740 | ||
741 | /*----------------------------------------------------------------------*/ | |
742 | /*----angel_RDI_write----------------------------------------------------*/ | |
743 | /*----------------------------------------------------------------------*/ | |
744 | ||
745 | /* Transfer memory block from host to target. Use ADP_Write>. */ | |
746 | int angel_RDI_write(const void *source, ARMword dest, unsigned *nbytes) | |
747 | { | |
748 | Packet *packet;/* Message buffers. */ | |
749 | unsigned int len, nbtogo = *nbytes, nboffset = 0, nbinpacket; | |
750 | int status, reason, debugID, OSinfo1, OSinfo2, err; | |
751 | unsigned int maxlen = Armsd_LongBufSize-CHAN_HEADER_SIZE-ADP_WriteHeaderSize; | |
752 | ||
753 | TracePrint(("angel_RDI_write: source=%p dest=%.8lx nbytes=%.8x\n", | |
754 | source, (unsigned long)dest, *nbytes)); | |
755 | ||
756 | if (*nbytes == 0) return RDIError_NoError; | |
757 | ||
758 | *nbytes = 0; | |
759 | while (nbtogo > 0) { | |
760 | packet = (Packet *) DevSW_AllocatePacket(Armsd_LongBufSize); | |
761 | nbinpacket = (nbtogo <= maxlen) ? nbtogo : maxlen; | |
762 | len = msgbuild(BUFFERDATA(packet->pk_buffer), "%w%w%w%w%w%w", | |
763 | ADP_Write | HtoT, 0, ADP_HandleUnknown, | |
764 | ADP_HandleUnknown, dest+nboffset, nbinpacket); | |
765 | /* Copy the data into the packet. */ | |
766 | ||
767 | memcpy(BUFFERDATA(packet->pk_buffer)+len, | |
768 | ((const unsigned char *) source)+nboffset, nbinpacket); | |
769 | nboffset += nbinpacket; | |
770 | packet->pk_length = nbinpacket+len; | |
771 | ||
772 | #ifdef MONITOR_DOWNLOAD_PACKETS | |
773 | angel_DebugPrint("angel_RDI_write packet size=%i, bytes done=%i\n", | |
774 | nbinpacket, nboffset); | |
775 | #endif | |
776 | ||
777 | register_debug_message_handler(); | |
778 | Adp_ChannelWrite(CI_HADP, packet); | |
779 | reason=ADP_Write | TtoH; | |
780 | err = wait_for_debug_message(&reason, &debugID, &OSinfo1, &OSinfo2, | |
781 | &status, &packet); | |
782 | nbtogo -= nbinpacket; | |
783 | if (err != RDIError_NoError) return err; | |
784 | if (status == RDIError_NoError) | |
785 | *nbytes += nbinpacket; | |
786 | ||
787 | DevSW_FreePacket(packet); | |
788 | } | |
789 | return status; | |
790 | } | |
791 | ||
792 | ||
793 | /*----------------------------------------------------------------------*/ | |
794 | /*----angel_RDI_CPUread--------------------------------------------------*/ | |
795 | /*----------------------------------------------------------------------*/ | |
796 | ||
797 | /* Reads the values of registers in the CPU, uses ADP_CPUwrite. */ | |
798 | int angel_RDI_CPUread(unsigned mode, unsigned long mask, ARMword *buffer) | |
799 | { | |
800 | unsigned int i, j; | |
801 | Packet *packet = NULL; | |
802 | int err, status, reason, debugID, OSinfo1, OSinfo2; | |
803 | #ifdef DEBUG | |
804 | angel_DebugPrint("DEBUG: Entered angel_RDI_CPUread.\n"); | |
805 | #endif | |
806 | for (i=0, j=0 ; i < RDINumCPURegs ; i++) | |
807 | if (mask & (1L << i)) j++; /* Count the number of registers. */ | |
808 | ||
809 | register_debug_message_handler(); | |
810 | msgsend(CI_HADP, "%w%w%w%w%c%w", ADP_CPUread | HtoT, 0, | |
811 | ADP_HandleUnknown, ADP_HandleUnknown, mode, mask); | |
812 | reason = ADP_CPUread | TtoH; | |
813 | err = wait_for_debug_message(&reason, &debugID, &OSinfo1, &OSinfo2, | |
814 | &status, &packet); | |
815 | if (err != RDIError_NoError) { | |
816 | DevSW_FreePacket(packet); | |
817 | return err; | |
818 | } | |
819 | if(status == RDIError_NoError) { | |
820 | for (i=0; i<j; i++) | |
821 | buffer[i] = GET32LE(BUFFERDATA(packet->pk_buffer)+20+(i*4)); | |
822 | TracePrint(("angel_RDI_CPUread: mode=%.8x mask=%.8lx", mode, mask)); | |
823 | DevSW_FreePacket(packet); | |
824 | #ifdef RDI_VERBOSE | |
825 | if (rdi_log & 1) { | |
826 | unsigned k; | |
827 | for (k = 0, j = 0 ; j <= 20 ; j++) | |
828 | if (mask & (1L << j)) { | |
829 | angel_DebugPrint("%c%.8lx",k%4==0?'\n':' ', | |
830 | (unsigned long)buffer[k]); | |
831 | k++ ; | |
832 | } | |
833 | angel_DebugPrint("\n") ; | |
834 | } | |
835 | #endif | |
836 | ||
837 | } | |
838 | return status; | |
839 | } | |
840 | ||
841 | /*----------------------------------------------------------------------*/ | |
842 | /*----angel_RDI_CPUwrite-------------------------------------------------*/ | |
843 | /*----------------------------------------------------------------------*/ | |
844 | ||
845 | /* Write CPU registers: use ADP_CPUwrite. */ | |
846 | int angel_RDI_CPUwrite(unsigned mode, unsigned long mask, | |
847 | ARMword const *buffer){ | |
848 | ||
849 | unsigned i, j, c; | |
850 | Packet *packet; | |
851 | int status, reason, debugID, OSinfo1, OSinfo2, err, len; | |
852 | ||
853 | TracePrint(("angel_RDI_CPUwrite: mode=%.8x mask=%.8lx", mode, mask)); | |
854 | #ifdef RDI_VERBOSE | |
855 | if (rdi_log & 1) { | |
856 | for (j = 0, i = 0 ; i <= 20 ; i++) | |
857 | if (mask & (1L << i)) { | |
858 | angel_DebugPrint("%c%.8lx",j%4==0?'\n':' ', | |
859 | (unsigned long)buffer[j]); | |
860 | j++ ; | |
861 | } | |
862 | angel_DebugPrint("\n") ; | |
863 | } | |
864 | #endif | |
865 | packet = (Packet *)DevSW_AllocatePacket(Armsd_BufferSize); | |
866 | for (i=0, j=0; i < RDINumCPURegs ; i++) | |
867 | if (mask & (1L << i)) j++; /* count the number of registers */ | |
868 | ||
869 | len = msgbuild(BUFFERDATA(packet->pk_buffer), "%w%w%w%w%b%w", | |
870 | ADP_CPUwrite | HtoT, 0, | |
871 | ADP_HandleUnknown, ADP_HandleUnknown, mode, mask); | |
872 | for(c=0; c<j; c++) | |
873 | PUT32LE(BUFFERDATA(packet->pk_buffer)+len+(c*4), buffer[c]); | |
874 | packet->pk_length = len+(j*4); | |
875 | register_debug_message_handler(); | |
876 | ||
877 | Adp_ChannelWrite(CI_HADP, packet); | |
878 | reason = ADP_CPUwrite | TtoH; | |
879 | err = wait_for_debug_message(&reason, &debugID, &OSinfo1, &OSinfo2, | |
880 | &status, &packet); | |
881 | unpack_message(BUFFERDATA(packet->pk_buffer), "%w%w%w%w%w", &reason, &debugID, | |
882 | &OSinfo1, &OSinfo2, &status); | |
883 | DevSW_FreePacket(packet); | |
884 | if (err != RDIError_NoError) | |
885 | return err; /* Was there an error? */ | |
886 | else | |
887 | return status; | |
888 | } | |
889 | ||
890 | ||
891 | /*----------------------------------------------------------------------*/ | |
892 | /*----angel_RDI_CPread---------------------------------------------------*/ | |
893 | /*----------------------------------------------------------------------*/ | |
894 | ||
895 | /* Read coprocessor's internal state. See dbg_cp.h for help. | |
896 | * Use ADP_CPRead. | |
897 | * It would appear that the correct behaviour at this point is to leave | |
898 | * the unpacking to a the caller and to simply copy the stream of data | |
899 | * words into the buffer | |
900 | */ | |
901 | ||
902 | int angel_RDI_CPread(unsigned CPnum, unsigned long mask, ARMword *buffer){ | |
903 | Packet *packet = NULL; | |
904 | int i, j, status, reasoncode, OSinfo1, OSinfo2, err, debugID; | |
905 | unsigned char *rmap = cpwords[CPnum]; | |
906 | int n; | |
907 | #ifdef DEBUG | |
908 | angel_DebugPrint("DEBUG: Entered angel_RDI_CPread.\n"); | |
909 | #endif | |
910 | if (rmap == NULL) return RDIError_UnknownCoPro; | |
911 | ||
912 | register_debug_message_handler(); | |
913 | n = rmap[-1]; | |
914 | msgsend(CI_HADP, "%w%w%w%w%b%w", ADP_CPread | HtoT, 0, | |
915 | ADP_HandleUnknown, ADP_HandleUnknown, CPnum, mask); | |
916 | reasoncode=ADP_CPread | TtoH; | |
917 | err = wait_for_debug_message(&reasoncode, &debugID, &OSinfo1, &OSinfo2, | |
918 | &status, &packet); | |
919 | if (err != RDIError_NoError) { | |
920 | DevSW_FreePacket(packet); | |
921 | return err; /* Was there an error? */ | |
922 | } | |
923 | for (j=i=0; i < n ; i++) /* count the number of registers */ | |
924 | if (mask & (1L << i)) { | |
925 | j++; | |
926 | } | |
927 | for (i=0; i<j; i++) | |
928 | buffer[i] = PREAD32(LE, BUFFERDATA(packet->pk_buffer) + 20 + (i*4)); | |
929 | DevSW_FreePacket(packet); | |
930 | TracePrint(("angel_RDI_CPread: CPnum=%.8x mask=%.8lx\n", CPnum, mask)); | |
931 | #ifdef RDI_VERBOSE | |
932 | if (rdi_log & 1) { | |
933 | for (i = 0, j = 0; j < n ; j++) { | |
934 | if (mask & (1L << j)) { | |
935 | int nw = rmap[j]; | |
936 | angel_DebugPrint("%2d ", j); | |
937 | while (--nw > 0) | |
938 | angel_DebugPrint("%.8lx ", (unsigned long)buffer[i++]); | |
939 | angel_DebugPrint("%.8lx\n", (unsigned long)buffer[i++]); | |
940 | } | |
941 | } | |
942 | } | |
943 | #endif | |
944 | return status; | |
945 | } | |
946 | ||
947 | ||
948 | /*----------------------------------------------------------------------*/ | |
949 | /*----angel_RDI_CPwrite--------------------------------------------------*/ | |
950 | /*----------------------------------------------------------------------*/ | |
951 | ||
952 | /* Write coprocessor's internal state. See dbg_cp.h for help. Use | |
953 | * ADP_CPwrite. | |
954 | */ | |
955 | ||
956 | int angel_RDI_CPwrite(unsigned CPnum, unsigned long mask, | |
957 | ARMword const *buffer) | |
958 | { | |
959 | Packet *packet = NULL; | |
960 | int i, j, len, status, reason, OSinfo1, OSinfo2, err, debugID; | |
961 | unsigned char *rmap = cpwords[CPnum]; | |
962 | int n; | |
963 | ||
964 | if (rmap == NULL) return RDIError_UnknownCoPro; | |
965 | n = rmap[-1]; | |
966 | ||
967 | TracePrint(("angel_RDI_CPwrite: CPnum=%d mask=%.8lx\n", CPnum, mask)); | |
968 | ||
969 | #ifdef RDI_VERBOSE | |
970 | if (rdi_log & 1) { | |
971 | for (i = 0, j = 0; j < n ; j++) | |
972 | if (mask & (1L << j)) { | |
973 | int nw = rmap[j]; | |
974 | angel_DebugPrint("%2d ", j); | |
975 | while (--nw > 0) | |
976 | angel_DebugPrint("%.8lx ", (unsigned long)buffer[i++]); | |
977 | angel_DebugPrint("%.8lx\n", (unsigned long)buffer[i++]); | |
978 | } | |
979 | } | |
980 | #endif | |
981 | ||
982 | for (j=i=0; i < n ; i++) /* Count the number of registers. */ | |
983 | if (mask & (1L << i)) j++; | |
984 | packet = DevSW_AllocatePacket(Armsd_BufferSize); | |
985 | len = msgbuild(BUFFERDATA(packet->pk_buffer), "%w%w%w%w%c%w", | |
986 | ADP_CPwrite | HtoT, 0, | |
987 | ADP_HandleUnknown, ADP_HandleUnknown, CPnum, mask); | |
988 | for(i=0; i<j; i++) | |
989 | len+=msgbuild(BUFFERDATA(packet->pk_buffer) + len, "%w", buffer[i]); | |
990 | packet->pk_length = len; | |
991 | register_debug_message_handler(); | |
992 | Adp_ChannelWrite(CI_HADP, packet); /* Transmit message. */ | |
993 | reason=ADP_CPwrite | TtoH; | |
994 | err = wait_for_debug_message(&reason, &debugID, &OSinfo1, &OSinfo2, | |
995 | &status, &packet); | |
996 | DevSW_FreePacket(packet); | |
997 | if (err != RDIError_NoError) | |
998 | return err; | |
999 | else | |
1000 | return status; | |
1001 | } | |
1002 | ||
1003 | ||
1004 | /*----------------------------------------------------------------------*/ | |
1005 | /*----angel_RDI_pointinq-------------------------------------------------*/ | |
1006 | /*----------------------------------------------------------------------*/ | |
1007 | ||
1008 | /* Do test calls to ADP_SetBreak/ADP_SetWatch to see if resources exist to | |
1009 | carry out request. */ | |
1010 | int angel_RDI_pointinq(ARMword *address, unsigned type, unsigned datatype, | |
1011 | ARMword *bound) | |
1012 | { | |
1013 | Packet *packet = NULL; | |
1014 | int len, status, reason, OSinfo1, OSinfo2, err=RDIError_NoError; | |
1015 | /* stop a compiler warning */ | |
1016 | int debugID, pointhandle; | |
1017 | TracePrint( | |
1018 | ("angel_RDI_pointinq: address=%.8lx type=%d datatype=%d bound=%.8lx ", | |
1019 | (unsigned long)*address, type, datatype, (unsigned long)*bound)); | |
1020 | /* for a buffer. */ | |
1021 | packet = DevSW_AllocatePacket(Armsd_BufferSize); | |
1022 | len = msgbuild(BUFFERDATA(packet->pk_buffer), "%w%w%w%w%w%b", | |
1023 | ((datatype == 0) ? ADP_SetBreak : ADP_SetWatch) | HtoT, 0, | |
1024 | ADP_HandleUnknown, ADP_HandleUnknown, address, type); | |
1025 | if (datatype == 0) | |
1026 | len += msgbuild(BUFFERDATA(packet->pk_buffer) + 21, "%w", bound); | |
1027 | else | |
1028 | len += msgbuild(BUFFERDATA(packet->pk_buffer) + 21, "%b%w", datatype, bound); | |
1029 | ||
1030 | register_debug_message_handler(); | |
1031 | packet->pk_length = len; | |
1032 | Adp_ChannelWrite(CI_HADP, packet); | |
1033 | reason = ((datatype == 0) ? ADP_SetBreak : ADP_SetWatch | TtoH); | |
1034 | err = wait_for_debug_message(&reason, &debugID, &OSinfo1, &OSinfo2, | |
1035 | &status, &packet); | |
1036 | if (err != RDIError_NoError) { | |
1037 | DevSW_FreePacket(packet); | |
1038 | return err; /* Was there an error? */ | |
1039 | } | |
1040 | unpack_message(BUFFERDATA(packet->pk_buffer), "%w%w%w%w%w%w%w%w", | |
1041 | &reason, &debugID, &OSinfo1, &OSinfo2, &status, | |
1042 | &pointhandle, &address, &bound); | |
1043 | DevSW_FreePacket(packet); | |
1044 | return err; | |
1045 | } | |
1046 | ||
1047 | ||
1048 | /*----------------------------------------------------------------------*/ | |
1049 | /*----angel_RDI_setbreak-------------------------------------------------*/ | |
1050 | /*----------------------------------------------------------------------*/ | |
1051 | ||
1052 | /* Set a breakpoint: Use ADP_SetBreak */ | |
1053 | int angel_RDI_setbreak(ARMword address, unsigned type, ARMword bound, | |
1054 | PointHandle *handle) | |
1055 | { | |
1056 | int status, reason, OSinfo1, OSinfo2, err, debugID; | |
1057 | int tmpval, tmpaddr, tmpbnd; | |
1058 | Packet *packet; | |
1059 | TracePrint(("angel_RDI_setbreak address=%.8lx type=%d bound=%.8lx \n", | |
1060 | (unsigned long)address, type, (unsigned long)bound)); | |
1061 | ||
1062 | register_debug_message_handler(); | |
1063 | msgsend(CI_HADP, "%w%w%w%w%w%b%w", | |
1064 | ADP_SetBreak| HtoT, 0, ADP_HandleUnknown, | |
1065 | ADP_HandleUnknown, address, type, bound); | |
1066 | reason = ADP_SetBreak |TtoH; | |
1067 | err = wait_for_debug_message(&reason, &debugID, &OSinfo1, &OSinfo2, | |
1068 | &status, &packet); | |
1069 | if (err != RDIError_NoError) { | |
1070 | DevSW_FreePacket(packet); | |
1071 | return err; /* Was there an error? */ | |
1072 | } | |
1073 | /* Work around varargs problem... -sts */ | |
1074 | unpack_message(BUFFERDATA(packet->pk_buffer), "%w%w%w%w%w%w%w%w", | |
1075 | &reason, &debugID, &OSinfo1, &OSinfo2, &status, | |
1076 | &tmpval, &tmpaddr, &tmpbnd); | |
1077 | *handle = tmpval; | |
1078 | address = tmpaddr; | |
1079 | bound = tmpbnd; | |
1080 | DevSW_FreePacket(packet); | |
1081 | if (status != RDIError_NoError) return status; | |
1082 | TracePrint(("returns handle %.8lx\n", (unsigned long)*handle)); | |
1083 | return RDIError_NoError; | |
1084 | } | |
1085 | ||
1086 | ||
1087 | /*----------------------------------------------------------------------*/ | |
1088 | /*----angel_RDI_clearbreak-----------------------------------------------*/ | |
1089 | /*----------------------------------------------------------------------*/ | |
1090 | ||
1091 | /* Clear a breakpoint: Use ADP_ClearBreak. */ | |
1092 | int angel_RDI_clearbreak(PointHandle handle) | |
1093 | { | |
1094 | Packet *packet = NULL; | |
1095 | int status, reason, OSinfo1, OSinfo2, err, debugID; | |
1096 | ||
1097 | TracePrint(("angel_RDI_clearbreak: handle=%.8lx\n", (unsigned long)handle)); | |
1098 | ||
1099 | register_debug_message_handler(); | |
1100 | msgsend(CI_HADP, "%w%w%w%w%w", | |
1101 | ADP_ClearBreak| HtoT, 0, ADP_HandleUnknown, | |
1102 | ADP_HandleUnknown, handle); | |
1103 | reason = ADP_ClearBreak|TtoH; | |
1104 | err = wait_for_debug_message(&reason, &debugID, &OSinfo1, &OSinfo2, | |
1105 | &status, &packet); | |
1106 | if (err != RDIError_NoError) { | |
1107 | DevSW_FreePacket(packet); | |
1108 | angel_DebugPrint("***RECEIVE DEBUG MESSAGE RETURNED ERR = %d.\n", err); | |
1109 | return err; /* Was there an error? */ | |
1110 | } | |
1111 | unpack_message(BUFFERDATA(packet->pk_buffer), "%w%w%w%w%w", &reason, | |
1112 | &debugID, &OSinfo1, &OSinfo2, &status); | |
1113 | DevSW_FreePacket(packet); | |
1114 | #ifdef DEBUG | |
1115 | angel_DebugPrint("DEBUG: Clear Break completed OK.\n"); | |
1116 | #endif | |
1117 | return RDIError_NoError; | |
1118 | } | |
1119 | ||
1120 | ||
1121 | /*----------------------------------------------------------------------*/ | |
1122 | /*----angel_RDI_setwatch-------------------------------------------------*/ | |
1123 | /*----------------------------------------------------------------------*/ | |
1124 | ||
1125 | /* Set a watchpoint: use ADP_SetWatch. */ | |
1126 | int angel_RDI_setwatch(ARMword address, unsigned type, unsigned datatype, | |
1127 | ARMword bound, PointHandle *handle) | |
1128 | { | |
1129 | Packet *packet = NULL; | |
1130 | int status, reason, OSinfo1, OSinfo2, err, debugID; | |
1131 | ||
1132 | TracePrint(("angel_RDI_setwatch: address=%.8lx type=%d bound=%.8lx ", | |
1133 | (unsigned long)address, type, (unsigned long)bound)); | |
1134 | ||
1135 | register_debug_message_handler(); | |
1136 | msgsend(CI_HADP, "%w%w%w%w%w%b%b%w", | |
1137 | ADP_SetWatch| HtoT, 0, ADP_HandleUnknown, | |
1138 | ADP_HandleUnknown, address, type, datatype, bound); | |
1139 | ||
1140 | reason = ADP_SetWatch | TtoH; | |
1141 | err = wait_for_debug_message(&reason, &debugID, &OSinfo1, &OSinfo2, | |
1142 | &status, &packet); | |
1143 | if (err != RDIError_NoError) { | |
1144 | DevSW_FreePacket(packet); | |
1145 | return err; /* Was there an error? */ | |
1146 | } | |
1147 | unpack_message(BUFFERDATA(packet->pk_buffer), "%w%w%w%w%w%w%w%w", | |
1148 | &reason, &debugID, &OSinfo1, &OSinfo2, &status, | |
1149 | handle, &address, &bound); | |
1150 | DevSW_FreePacket(packet); | |
1151 | TracePrint(("returns handle %.8lx\n", (unsigned long)*handle)); | |
1152 | return RDIError_NoError; | |
1153 | } | |
1154 | ||
1155 | /*----------------------------------------------------------------------*/ | |
1156 | /*----angel_RDI_clearwatch-----------------------------------------------*/ | |
1157 | /*----------------------------------------------------------------------*/ | |
1158 | ||
1159 | /* Clear a watchpoint: use ADP_ClearWatch. */ | |
1160 | int angel_RDI_clearwatch(PointHandle handle) { | |
1161 | ||
1162 | int status, reason, OSinfo1, OSinfo2, err, debugID; | |
1163 | Packet *packet = NULL; | |
1164 | ||
1165 | TracePrint(("angel_RDI_clearwatch: handle=%.8lx\n", (unsigned long)handle)); | |
1166 | ||
1167 | register_debug_message_handler(); | |
1168 | msgsend(CI_HADP, "%w%w%w%w%w", | |
1169 | ADP_ClearWatch| HtoT, 0, ADP_HandleUnknown, | |
1170 | ADP_HandleUnknown, handle); | |
1171 | reason = ADP_ClearWatch|TtoH; | |
1172 | err = wait_for_debug_message(&reason, &debugID, &OSinfo1, &OSinfo2, | |
1173 | &status, &packet); | |
1174 | if (err != RDIError_NoError) { | |
1175 | DevSW_FreePacket(packet); | |
1176 | return err; /* Was there an error? */ | |
1177 | } | |
1178 | unpack_message(BUFFERDATA(packet->pk_buffer), "%w%w%w%w%w", &reason, &debugID, | |
1179 | &OSinfo1, &OSinfo2, &status); | |
1180 | DevSW_FreePacket(packet); | |
1181 | return RDIError_NoError; | |
1182 | } | |
1183 | ||
1184 | typedef struct { | |
1185 | unsigned stopped_reason; | |
1186 | int stopped_status; | |
1187 | int data; | |
1188 | } adp_stopped_struct; | |
1189 | ||
1190 | ||
1191 | int angel_RDI_OnTargetStopping(angel_RDI_TargetStoppedProc *fn, | |
1192 | void *arg) | |
1193 | { | |
1194 | stoppedProcListElement **lptr = &stopped_proc_list; | |
1195 | ||
1196 | /* Find the address of the NULL ptr at the end of the list */ | |
1197 | for (; *lptr!=NULL ; lptr = &((*lptr)->next)) | |
1198 | ; /* Do nothing */ | |
1199 | ||
1200 | *lptr = (stoppedProcListElement *) malloc(sizeof(stoppedProcListElement)); | |
1201 | if (*lptr == NULL) return RDIError_OutOfStore; | |
1202 | (*lptr)->fn = fn; | |
1203 | (*lptr)->arg = arg; | |
1204 | ||
1205 | return RDIError_NoError; | |
1206 | } | |
1207 | ||
1208 | static int CallStoppedProcs(unsigned reason) | |
1209 | { | |
1210 | stoppedProcListElement *p = stopped_proc_list; | |
1211 | int err=RDIError_NoError; | |
1212 | ||
1213 | for (; p!=NULL ; p=p->next) { | |
1214 | int local_err = p->fn(reason, p->arg); | |
1215 | if (local_err != RDIError_NoError) err=local_err; | |
1216 | } | |
1217 | ||
1218 | return err; | |
1219 | } | |
1220 | ||
1221 | /*----------------------------------------------------------------------*/ | |
1222 | /*----angel_RDI_execute--------------------------------------------------*/ | |
1223 | /*----------------------------------------------------------------------*/ | |
1224 | ||
1225 | static int HandleStoppedMessage(Packet *packet, void *stateptr) { | |
1226 | unsigned int err, reason, debugID, OSinfo1, OSinfo2, count; | |
1227 | adp_stopped_struct *stopped_info; | |
1228 | stopped_info = (adp_stopped_struct *) stateptr; | |
1229 | IGNORE(stateptr); | |
1230 | count = unpack_message(BUFFERDATA(packet->pk_buffer), "%w%w%w%w%w%w", | |
1231 | &reason, &debugID, | |
1232 | &OSinfo1, &OSinfo2, | |
1233 | &stopped_info->stopped_reason, &stopped_info->data); | |
1234 | DevSW_FreePacket(packet); | |
1235 | ||
1236 | if (reason != (ADP_Stopped | TtoH)) { | |
1237 | #ifdef DEBUG | |
1238 | angel_DebugPrint("Expecting stopped message, got %x", reason); | |
1239 | #endif | |
1240 | return RDIError_Error; | |
1241 | } | |
1242 | else { | |
1243 | executing = FALSE; | |
1244 | #ifdef DEBUG | |
1245 | angel_DebugPrint("Received stopped message.\n"); | |
1246 | #endif | |
1247 | } | |
1248 | ||
1249 | err = msgsend(CI_TADP, "%w%w%w%w%w", (ADP_Stopped | HtoT), 0, | |
1250 | ADP_HandleUnknown, ADP_HandleUnknown, RDIError_NoError); | |
1251 | #ifdef DEBUG | |
1252 | angel_DebugPrint("Transmiting stopped acknowledge.\n"); | |
1253 | #endif | |
1254 | if (err != RDIError_NoError) angel_DebugPrint("Transmit failed.\n"); | |
1255 | #ifdef DEBUG | |
1256 | angel_DebugPrint("DEBUG: Stopped reason : %x\n", stopped_info->stopped_reason); | |
1257 | #endif | |
1258 | switch (stopped_info->stopped_reason) { | |
1259 | case ADP_Stopped_BranchThroughZero: | |
1260 | stopped_info->stopped_status = RDIError_BranchThrough0; | |
1261 | break; | |
1262 | case ADP_Stopped_UndefinedInstr: | |
1263 | stopped_info->stopped_status = RDIError_UndefinedInstruction; | |
1264 | break; | |
1265 | case ADP_Stopped_SoftwareInterrupt: | |
1266 | stopped_info->stopped_status = RDIError_SoftwareInterrupt; | |
1267 | break; | |
1268 | case ADP_Stopped_PrefetchAbort: | |
1269 | stopped_info->stopped_status = RDIError_PrefetchAbort; | |
1270 | break; | |
1271 | case ADP_Stopped_DataAbort: | |
1272 | stopped_info->stopped_status = RDIError_DataAbort; | |
1273 | break; | |
1274 | case ADP_Stopped_AddressException: | |
1275 | stopped_info->stopped_status = RDIError_AddressException; | |
1276 | break; | |
1277 | case ADP_Stopped_IRQ: | |
1278 | stopped_info->stopped_status = RDIError_IRQ; | |
1279 | break; | |
1280 | case ADP_Stopped_BreakPoint: | |
1281 | stopped_info->stopped_status = RDIError_BreakpointReached; | |
1282 | break; | |
1283 | case ADP_Stopped_WatchPoint: | |
1284 | stopped_info->stopped_status = RDIError_WatchpointAccessed; | |
1285 | break; | |
1286 | case ADP_Stopped_StepComplete: | |
1287 | stopped_info->stopped_status = RDIError_ProgramFinishedInStep; | |
1288 | break; | |
1289 | case ADP_Stopped_RunTimeErrorUnknown: | |
1290 | case ADP_Stopped_StackOverflow: | |
1291 | case ADP_Stopped_DivisionByZero: | |
1292 | stopped_info->stopped_status = RDIError_Error; | |
1293 | break; | |
1294 | case ADP_Stopped_FIQ: | |
1295 | stopped_info->stopped_status = RDIError_FIQ; | |
1296 | break; | |
1297 | case ADP_Stopped_UserInterruption: | |
1298 | case ADP_Stopped_OSSpecific: | |
1299 | stopped_info->stopped_status = RDIError_UserInterrupt; | |
1300 | break; | |
1301 | case ADP_Stopped_ApplicationExit: | |
1302 | stopped_info->stopped_status = RDIError_NoError; | |
1303 | break; | |
1304 | default: | |
5c44784c | 1305 | stopped_info->stopped_status = RDIError_Error; |
c906108c SS |
1306 | break; |
1307 | } | |
1308 | return RDIError_NoError; | |
1309 | } | |
1310 | ||
c906108c SS |
1311 | |
1312 | static void interrupt_target( void ) | |
1313 | { | |
1314 | Packet *packet = NULL; | |
1315 | int err; | |
1316 | int reason, debugID, OSinfo1, OSinfo2, status; | |
1317 | ||
1318 | #ifdef DEBUG | |
1319 | angel_DebugPrint("DEBUG: interrupt_target.\n"); | |
1320 | #endif | |
1321 | ||
1322 | register_debug_message_handler(); | |
1323 | msgsend(CI_HADP, "%w%w%w%w", ADP_InterruptRequest | HtoT, 0, | |
1324 | ADP_HandleUnknown, ADP_HandleUnknown); | |
1325 | ||
1326 | reason = ADP_InterruptRequest |TtoH; | |
1327 | err = wait_for_debug_message(&reason, &debugID, &OSinfo1, &OSinfo2, | |
1328 | &status, &packet); | |
1329 | DevSW_FreePacket(packet); | |
1330 | #ifdef DEBUG | |
1331 | angel_DebugPrint("DEBUG: got interrupt ack ok err = %d, status=%i\n", | |
1332 | err, status); | |
1333 | #endif | |
1334 | ||
1335 | return; | |
1336 | } | |
1337 | ||
1338 | #ifdef TEST_DC_APPL | |
1339 | extern void test_dc_appl_handler( const DeviceDescr *device, | |
1340 | Packet *packet ); | |
1341 | #endif | |
1342 | ||
1343 | /* Core functionality for execute and step */ | |
1344 | static int angel_RDI_ExecuteOrStep(PointHandle *handle, word type, | |
1345 | unsigned ninstr) | |
1346 | { | |
1347 | int err; | |
1348 | adp_stopped_struct stopped_info; | |
1349 | void* stateptr = (void *)&stopped_info; | |
1350 | ChannelCallback HandleStoppedMessageFPtr=(ChannelCallback) HandleStoppedMessage; | |
1351 | int status, reasoncode, debugID, OSinfo1, OSinfo2; | |
1352 | Packet *packet = NULL; | |
1353 | ||
1354 | TracePrint(("angel_RDI_ExecuteOrStep\n")); | |
1355 | ||
1356 | err = Adp_ChannelRegisterRead(CI_TADP, | |
1357 | HandleStoppedMessageFPtr, stateptr); | |
1358 | if (err != RDIError_NoError) { | |
1359 | #ifdef DEBUG | |
1360 | angel_DebugPrint("TADP Register failed.\n"); | |
1361 | #endif | |
1362 | return err; | |
1363 | } | |
1364 | /* Set executing TRUE here, as it must be set up before the target has | |
1365 | * had any chance at all to execute, or it may send its stopped message | |
1366 | * before we get round to setting executing = TRUE !!! | |
1367 | */ | |
1368 | executing = TRUE; | |
1369 | ||
1370 | register_debug_message_handler(); | |
1371 | ||
1372 | #ifdef TEST_DC_APPL | |
1373 | Adp_Install_DC_Appl_Handler( test_dc_appl_handler ); | |
1374 | #endif | |
1375 | ||
1376 | #ifdef DEBUG | |
1377 | angel_DebugPrint("Transmiting %s message.\n", | |
1378 | type == ADP_Execute ? "execute": "step"); | |
1379 | #endif | |
1380 | ||
1381 | register_debug_message_handler(); | |
1382 | /* Extra ninstr parameter for execute message will simply be ignored */ | |
1383 | err = msgsend(CI_HADP,"%w%w%w%w%w", type | HtoT, 0, | |
1384 | ADP_HandleUnknown, ADP_HandleUnknown, ninstr); | |
1385 | #if DEBUG | |
1386 | if (err != RDIError_NoError) angel_DebugPrint("Transmit failed.\n"); | |
1387 | #endif | |
1388 | ||
1389 | reasoncode = type | TtoH; | |
1390 | err = wait_for_debug_message( &reasoncode, &debugID, &OSinfo1, &OSinfo2, | |
1391 | &status, &packet ); | |
1392 | if (err != RDIError_NoError) | |
1393 | return err; | |
1394 | else if (status != RDIError_NoError) | |
1395 | return status; | |
1396 | ||
1397 | #ifdef DEBUG | |
1398 | angel_DebugPrint("Waiting for program to finish...\n"); | |
1399 | #endif | |
1400 | ||
c3f6f71d | 1401 | signal(SIGINT, ardi_sigint_handler); |
c906108c SS |
1402 | while( executing ) |
1403 | { | |
1404 | if (interrupt_request) | |
1405 | { | |
1406 | interrupt_target(); | |
1407 | interrupt_request = FALSE; | |
1408 | } | |
1409 | Adp_AsynchronousProcessing( async_block_on_nothing ); | |
1410 | } | |
c3f6f71d JM |
1411 | signal(SIGINT, SIG_IGN); |
1412 | ||
c906108c SS |
1413 | |
1414 | #ifdef TEST_DC_APPL | |
1415 | Adp_Install_DC_Appl_Handler( NULL ); | |
1416 | #endif | |
1417 | ||
1418 | (void)Adp_ChannelRegisterRead(CI_TADP, NULL, NULL); | |
1419 | ||
1420 | *handle = (PointHandle)stopped_info.data; | |
1421 | ||
1422 | CallStoppedProcs(stopped_info.stopped_reason); | |
1423 | ||
1424 | return stopped_info.stopped_status; | |
1425 | } | |
1426 | ||
1427 | /* Request that the target starts executing from the stored CPU state: use | |
1428 | ADP_Execute. */ | |
1429 | int angel_RDI_execute(PointHandle *handle) | |
1430 | { | |
1431 | return angel_RDI_ExecuteOrStep(handle, ADP_Execute, 0); | |
1432 | } | |
1433 | ||
1434 | #ifdef __WATCOMC__ | |
1435 | typedef void handlertype(int); | |
1436 | ||
1437 | static int interrupted=0; | |
1438 | ||
1439 | static void myhandler(int sig) { | |
1440 | IGNORE(sig); | |
1441 | interrupted=1; | |
1442 | signal(SIGINT, myhandler); | |
1443 | } | |
1444 | #endif | |
1445 | ||
1446 | /*----------------------------------------------------------------------*/ | |
1447 | /*----angel_RDI_step-----------------------------------------------------*/ | |
1448 | /*----------------------------------------------------------------------*/ | |
1449 | ||
1450 | /* Step 'ninstr' through the code: use ADP_Step. */ | |
1451 | int angel_RDI_step(unsigned ninstr, PointHandle *handle) | |
1452 | { | |
1453 | int err = angel_RDI_ExecuteOrStep(handle, ADP_Step, ninstr); | |
1454 | if (err == RDIError_ProgramFinishedInStep) | |
1455 | return RDIError_NoError; | |
1456 | else | |
1457 | return err; | |
1458 | } | |
1459 | ||
1460 | ||
1461 | static void SetCPWords(int cpnum, struct Dbg_CoProDesc const *cpd) { | |
1462 | int i, rmax = 0; | |
1463 | for (i = 0; i < cpd->entries; i++) | |
1464 | if (cpd->regdesc[i].rmax > rmax) | |
1465 | rmax = cpd->regdesc[i].rmax; | |
1466 | ||
1467 | { unsigned char *rmap = (unsigned char *)malloc(rmax + 2); | |
1468 | *rmap++ = rmax + 1; | |
1469 | for (i = 0; i < cpd->entries; i++) { | |
1470 | int r; | |
1471 | for (r = cpd->regdesc[i].rmin; r <= cpd->regdesc[i].rmax; r++) | |
1472 | rmap[r] = (cpd->regdesc[i].nbytes+3) / 4; | |
1473 | } | |
1474 | /* if (cpwords[cpnum] != NULL) free(cpwords[cpnum]); */ | |
1475 | cpwords[cpnum] = rmap; | |
1476 | } | |
1477 | } | |
1478 | ||
1479 | /*----------------------------------------------------------------------*/ | |
1480 | /*----angel_RDI_info-----------------------------------------------------*/ | |
1481 | /*----------------------------------------------------------------------*/ | |
1482 | ||
1483 | /* Use ADP_Info, ADP_Ctrl and ADP_Profile calls to implement these, | |
1484 | see adp.h for more details. */ | |
1485 | ||
1486 | static int angel_cc_exists( void ) | |
1487 | { | |
1488 | Packet *packet = NULL; | |
1489 | int err; | |
1490 | int reason, debugID, OSinfo1, OSinfo2, subreason, status; | |
1491 | ||
1492 | #ifdef DEBUG | |
1493 | angel_DebugPrint("DEBUG: ADP_ICEB_CC_Exists.\n"); | |
1494 | #endif | |
1495 | ||
1496 | if ( angel_RDI_info( RDIInfo_Icebreaker, NULL, NULL ) == RDIError_NoError ) { | |
1497 | register_debug_message_handler(); | |
1498 | msgsend(CI_HADP, "%w%w%w%w%w", ADP_ICEbreakerHADP | HtoT, 0, | |
1499 | ADP_HandleUnknown, ADP_HandleUnknown, | |
1500 | ADP_ICEB_CC_Exists ); | |
1501 | reason = ADP_ICEbreakerHADP |TtoH; | |
1502 | err = wait_for_debug_message(&reason, &debugID, &OSinfo1, &OSinfo2, | |
1503 | &status, &packet); | |
1504 | if (err != RDIError_NoError) { | |
1505 | DevSW_FreePacket(packet); | |
1506 | return err; | |
1507 | } | |
1508 | unpack_message(BUFFERDATA(packet->pk_buffer), "%w%w%w%w%w%w", &reason, | |
1509 | &debugID, &OSinfo1, &OSinfo2, &subreason, &status); | |
1510 | if (subreason != ADP_ICEB_CC_Exists) { | |
1511 | DevSW_FreePacket(packet); | |
1512 | return RDIError_Error; | |
1513 | } | |
1514 | else | |
1515 | return status; | |
1516 | } | |
1517 | else | |
1518 | return RDIError_UnimplementedMessage; | |
1519 | } | |
1520 | ||
1521 | typedef struct { | |
1522 | RDICCProc_ToHost *tohost; void *tohostarg; | |
1523 | RDICCProc_FromHost *fromhost; void *fromhostarg; | |
1524 | bool registered; | |
1525 | } CCState; | |
1526 | static CCState ccstate = { NULL, NULL, NULL, NULL, FALSE }; | |
1527 | ||
1528 | static void HandleDCCMessage( Packet *packet, void *stateptr ) | |
1529 | { | |
1530 | unsigned int reason, debugID, OSinfo1, OSinfo2; | |
1531 | int count; | |
1532 | CCState *ccstate_p = (CCState *)stateptr; | |
1533 | ||
1534 | count = unpack_message( BUFFERDATA(packet->pk_buffer), "%w%w%w%w", | |
1535 | &reason, &debugID, &OSinfo1, &OSinfo2 ); | |
1536 | switch ( reason ) | |
1537 | { | |
1538 | case ADP_TDCC_ToHost | TtoH: | |
1539 | { | |
1540 | /* only handles a single word of data, for now */ | |
1541 | ||
1542 | unsigned int nbytes, data; | |
1543 | ||
1544 | unpack_message( BUFFERDATA(packet->pk_buffer)+count, "%w%w", | |
1545 | &nbytes, &data ); | |
1546 | #ifdef DEBUG | |
1547 | angel_DebugPrint( "DEBUG: received CC_ToHost message: nbytes %d data %08x.\n", | |
1548 | nbytes, data ); | |
1549 | #endif | |
1550 | ccstate_p->tohost( ccstate_p->tohostarg, data ); | |
1551 | msgsend(CI_TTDCC, "%w%w%w%w%w", | |
1552 | ADP_TDCC_ToHost | HtoT, debugID, OSinfo1, OSinfo2, | |
1553 | RDIError_NoError ); | |
1554 | break; | |
1555 | } | |
1556 | ||
1557 | case ADP_TDCC_FromHost | TtoH: | |
1558 | { | |
1559 | /* only handles a single word of data, for now */ | |
1560 | ||
1561 | int valid; | |
1562 | ARMword data; | |
1563 | ||
1564 | ccstate_p->fromhost( ccstate_p->fromhostarg, &data, &valid ); | |
1565 | #ifdef DEBUG | |
1566 | angel_DebugPrint( "DEBUG: received CC_FromHost message, returning: %08x %s.\n", | |
1567 | data, valid ? "VALID" : "INvalid" ); | |
1568 | #endif | |
1569 | msgsend(CI_TTDCC, "%w%w%w%w%w%w%w", | |
1570 | ADP_TDCC_FromHost | HtoT, debugID, OSinfo1, OSinfo2, | |
1571 | RDIError_NoError, valid ? 1 : 0, data ); | |
1572 | break; | |
1573 | } | |
1574 | ||
1575 | default: | |
1576 | #ifdef DEBUG | |
1577 | angel_DebugPrint( "Unexpected TDCC message %08x received\n", reason ); | |
1578 | #endif | |
1579 | break; | |
1580 | } | |
1581 | DevSW_FreePacket(packet); | |
1582 | return; | |
1583 | } | |
1584 | ||
1585 | static void angel_check_DCC_handler( CCState *ccstate_p ) | |
1586 | { | |
1587 | int err; | |
1588 | ||
1589 | if ( ccstate_p->tohost != NULL || ccstate_p->fromhost != NULL ) | |
1590 | { | |
1591 | /* doing DCC, so need a handler */ | |
1592 | if ( ! ccstate_p->registered ) | |
1593 | { | |
1594 | #ifdef DEBUG | |
1595 | angel_DebugPrint( "Registering handler for TTDCC channel.\n" ); | |
1596 | #endif | |
1597 | err = Adp_ChannelRegisterRead( CI_TTDCC, HandleDCCMessage, | |
1598 | ccstate_p ); | |
1599 | if ( err == adp_ok ) | |
1600 | ccstate_p->registered = TRUE; | |
1601 | #ifdef DEBUG | |
1602 | else | |
1603 | angel_DebugPrint( "angel_check_DCC_handler: register failed!\n" ); | |
1604 | #endif | |
1605 | } | |
1606 | } | |
1607 | else | |
1608 | { | |
1609 | /* not doing DCC, so don't need a handler */ | |
1610 | if ( ccstate_p->registered ) | |
1611 | { | |
1612 | #ifdef DEBUG | |
1613 | angel_DebugPrint( "Unregistering handler for TTDCC channel.\n" ); | |
1614 | #endif | |
1615 | err = Adp_ChannelRegisterRead( CI_TTDCC, NULL, NULL ); | |
1616 | if ( err == adp_ok ) | |
1617 | ccstate_p->registered = FALSE; | |
1618 | #ifdef DEBUG | |
1619 | else | |
1620 | angel_DebugPrint( "angel_check_DCC_handler: unregister failed!\n" ); | |
1621 | #endif | |
1622 | } | |
1623 | } | |
1624 | } | |
1625 | ||
1626 | ||
1627 | static int CheckSubMessageReply(int reason, int subreason) { | |
1628 | Packet *packet = NULL; | |
1629 | int status, debugID, OSinfo1, OSinfo2; | |
1630 | int err = RDIError_NoError; | |
1631 | reason |= TtoH; | |
1632 | err = wait_for_debug_message(&reason, &debugID, &OSinfo1, &OSinfo2, | |
1633 | &status, &packet); | |
1634 | if (err != RDIError_NoError) { | |
1635 | status = err; | |
1636 | } else { | |
1637 | int sr; | |
1638 | unpack_message(BUFFERDATA(packet->pk_buffer), "%w%w%w%w%w%w", &reason, &debugID, | |
1639 | &OSinfo1, &OSinfo2, &sr, &status); | |
1640 | if (subreason != sr) status = RDIError_Error; | |
1641 | } | |
1642 | DevSW_FreePacket(packet); | |
1643 | return status; | |
1644 | } | |
1645 | ||
1646 | static int SendSubMessageAndCheckReply(int reason, int subreason) { | |
1647 | register_debug_message_handler(); | |
1648 | msgsend(CI_HADP, "%w%w%w%w%w", reason | HtoT, 0, | |
1649 | ADP_HandleUnknown, ADP_HandleUnknown, | |
1650 | subreason); | |
1651 | return CheckSubMessageReply(reason, subreason); | |
1652 | } | |
1653 | ||
1654 | static int SendSubMessageWordAndCheckReply(int reason, int subreason, ARMword word) { | |
1655 | register_debug_message_handler(); | |
1656 | msgsend(CI_HADP, "%w%w%w%w%w%w", reason | HtoT, 0, | |
1657 | ADP_HandleUnknown, ADP_HandleUnknown, | |
1658 | subreason, word); | |
1659 | return CheckSubMessageReply(reason, subreason); | |
1660 | } | |
1661 | ||
1662 | static int SendSubMessageGetWordAndCheckReply(int reason, int subreason, ARMword *resp) { | |
1663 | Packet *packet = NULL; | |
1664 | int status, debugID, OSinfo1, OSinfo2; | |
1665 | int err = RDIError_NoError; | |
1666 | ||
1667 | register_debug_message_handler(); | |
1668 | msgsend(CI_HADP, "%w%w%w%w%w", reason | HtoT, 0, | |
1669 | ADP_HandleUnknown, ADP_HandleUnknown, | |
1670 | subreason); | |
1671 | reason |= TtoH; | |
1672 | err = wait_for_debug_message(&reason, &debugID, &OSinfo1, &OSinfo2, | |
1673 | &status, &packet); | |
1674 | if (err != RDIError_NoError) { | |
1675 | status = err; | |
1676 | } else { | |
1677 | int sr; | |
1678 | unpack_message(BUFFERDATA(packet->pk_buffer), "%w%w%w%w%w%w%w", &reason, &debugID, | |
1679 | &OSinfo1, &OSinfo2, &sr, &status, resp); | |
1680 | if (subreason != sr) status = RDIError_Error; | |
1681 | } | |
1682 | DevSW_FreePacket(packet); | |
1683 | return status; | |
1684 | } | |
1685 | ||
1686 | static int const hostsex = 1; | |
1687 | ||
1688 | int angel_RDI_info(unsigned type, ARMword *arg1, ARMword *arg2) { | |
1689 | Packet *packet = NULL; | |
1690 | int len, status, c, reason, subreason, debugID, OSinfo1, OSinfo2; | |
1691 | int err=RDIError_NoError, cpnum=0; | |
1692 | struct Dbg_CoProDesc *cpd; | |
1693 | int count, i; | |
1694 | unsigned char *bp; | |
1695 | ||
1696 | #ifdef DEBUG | |
1697 | angel_DebugPrint("DEBUG: Entered angel_RDI_info.\n"); | |
1698 | #endif | |
1699 | switch (type) { | |
1700 | case RDIInfo_Target: | |
1701 | #ifdef DEBUG | |
1702 | angel_DebugPrint("DEBUG: RDIInfo_Target.\n"); | |
1703 | #endif | |
1704 | ||
1705 | register_debug_message_handler(); | |
1706 | msgsend(CI_HADP, "%w%w%w%w%w", ADP_Info | HtoT, 0, | |
1707 | ADP_HandleUnknown, ADP_HandleUnknown, ADP_Info_Target); | |
1708 | reason = ADP_Info |TtoH; | |
1709 | err = wait_for_debug_message(&reason, &debugID, &OSinfo1, &OSinfo2, | |
1710 | &status, &packet); | |
1711 | if (err != RDIError_NoError) { | |
1712 | DevSW_FreePacket(packet); | |
1713 | return err; | |
1714 | } | |
1715 | unpack_message(BUFFERDATA(packet->pk_buffer), "%w%w%w%w%w%w%w%w", &reason, | |
1716 | &debugID, &OSinfo1, &OSinfo2, &subreason, &status, | |
1717 | arg1, arg2); | |
1718 | DevSW_FreePacket(packet); | |
1719 | ||
1720 | if (subreason != ADP_Info_Target) | |
1721 | return RDIError_Error; | |
1722 | else | |
1723 | return status; | |
1724 | ||
1725 | case RDISignal_Stop: | |
1726 | #ifdef DEBUG | |
1727 | angel_DebugPrint("DEBUG: RDISignal_Stop.\n"); | |
1728 | if (interrupt_request) | |
1729 | angel_DebugPrint(" STILL WAITING to send previous interrupt request\n"); | |
1730 | #endif | |
1731 | interrupt_request = TRUE; | |
1732 | return RDIError_NoError; | |
1733 | ||
1734 | case RDIInfo_Points: | |
1735 | #ifdef DEBUG | |
1736 | angel_DebugPrint("DEBUG: RDIInfo_Points.\n"); | |
1737 | #endif | |
1738 | return SendSubMessageGetWordAndCheckReply(ADP_Info, ADP_Info_Points, arg1); | |
1739 | ||
1740 | case RDIInfo_Step: | |
1741 | #ifdef DEBUG | |
1742 | angel_DebugPrint("DEBUG: RDIInfo_Step.\n"); | |
1743 | #endif | |
1744 | return SendSubMessageGetWordAndCheckReply(ADP_Info, ADP_Info_Step, arg1); | |
1745 | ||
1746 | case RDISet_Cmdline: | |
1747 | #ifdef DEBUG | |
1748 | angel_DebugPrint("DEBUG: RDISet_Cmdline.\n"); | |
1749 | #endif | |
1750 | if (ardi_commandline != &dummycline) | |
1751 | free(ardi_commandline); | |
1752 | ardi_commandline = (char *)malloc(strlen((char*)arg1) + 1) ; | |
1753 | (void)strcpy(ardi_commandline, (char *)arg1) ; | |
1754 | return RDIError_NoError; | |
1755 | ||
1756 | case RDIInfo_SetLog: | |
1757 | #ifdef DEBUG | |
1758 | angel_DebugPrint("DEBUG: RDIInfo_SetLog.\n"); | |
1759 | #endif | |
1760 | rdi_log = (int) *arg1; | |
1761 | return RDIError_NoError; | |
1762 | ||
1763 | case RDIInfo_Log: | |
1764 | #ifdef DEBUG | |
1765 | angel_DebugPrint("DEBUG: RDIInfo_Log.\n"); | |
1766 | #endif | |
1767 | *arg1 = rdi_log; | |
1768 | return RDIError_NoError; | |
1769 | ||
1770 | ||
1771 | case RDIInfo_MMU: | |
1772 | #ifdef DEBUG | |
1773 | angel_DebugPrint("DEBUG: RDIInfo_MMU.\n"); | |
1774 | #endif | |
1775 | return SendSubMessageGetWordAndCheckReply(ADP_Info, ADP_Info_MMU, arg1); | |
1776 | ||
1777 | case RDIInfo_SemiHosting: | |
1778 | #ifdef DEBUG | |
1779 | angel_DebugPrint("DEBUG: RDIInfo_SemiHosting.\n"); | |
1780 | #endif | |
1781 | return SendSubMessageAndCheckReply(ADP_Info, ADP_Info_SemiHosting); | |
1782 | ||
1783 | case RDIInfo_CoPro: | |
1784 | #ifdef DEBUG | |
1785 | angel_DebugPrint("DEBUG: RDIInfo_CoPro.\n"); | |
1786 | #endif | |
1787 | return SendSubMessageAndCheckReply(ADP_Info, ADP_Info_CoPro); | |
1788 | ||
1789 | case RDICycles: | |
1790 | #ifdef DEBUG | |
1791 | angel_DebugPrint("DEBUG: RDICycles.\n"); | |
1792 | #endif | |
1793 | register_debug_message_handler(); | |
1794 | msgsend(CI_HADP, "%w%w%w%w%w", ADP_Info | HtoT, 0, | |
1795 | ADP_HandleUnknown, ADP_HandleUnknown, ADP_Info_Cycles); | |
1796 | reason = ADP_Info |TtoH; | |
1797 | err = wait_for_debug_message(&reason, &debugID, &OSinfo1, &OSinfo2, | |
1798 | &status, &packet); | |
1799 | if (err != RDIError_NoError) { | |
1800 | DevSW_FreePacket(packet); | |
1801 | return err; | |
1802 | } | |
1803 | unpack_message(BUFFERDATA(packet->pk_buffer), "%w%w%w%w%w%w", &reason, &debugID, | |
1804 | &OSinfo1, &OSinfo2, &subreason, &status); | |
1805 | DevSW_FreePacket(packet); | |
1806 | if (subreason != ADP_Info_Cycles) | |
1807 | return RDIError_Error; | |
1808 | if (status != RDIError_NoError) return status; | |
1809 | for (c=0; c<12; c++) | |
1810 | arg1[c]=GET32LE(BUFFERDATA(packet->pk_buffer)+24+(c*4)); | |
1811 | return status; | |
1812 | ||
1813 | case RDIInfo_DescribeCoPro: | |
1814 | #ifdef DEBUG | |
1815 | angel_DebugPrint("DEBUG: RDIInfo_DescribeCoPro.\n"); | |
1816 | #endif | |
1817 | cpnum = *(int *)arg1; | |
1818 | cpd = (struct Dbg_CoProDesc *)arg2; | |
1819 | packet = DevSW_AllocatePacket(Armsd_BufferSize); | |
1820 | if (angel_RDI_info(ADP_Info_CoPro, NULL, NULL) != RDIError_NoError) | |
1821 | return RDIError_Error; | |
1822 | len = msgbuild(BUFFERDATA(packet->pk_buffer), "%w%w%w%w%w", ADP_Info | HtoT, 0, | |
1823 | ADP_HandleUnknown, ADP_HandleUnknown, | |
1824 | ADP_Info_DescribeCoPro); | |
1825 | len +=msgbuild(BUFFERDATA(packet->pk_buffer)+20, "%b%b%b%b%b", cpnum, | |
1826 | cpd->regdesc[cpnum].rmin, cpd->regdesc[cpnum].rmax, | |
1827 | cpd->regdesc[cpnum].nbytes, cpd->regdesc[cpnum].access); | |
1828 | if (cpd->regdesc[cpnum].access&0x3 == 0x3){ | |
1829 | len += msgbuild(BUFFERDATA(packet->pk_buffer)+25, "%b%b%b%b%b", | |
1830 | cpd->regdesc[cpnum].accessinst.cprt.read_b0, | |
1831 | cpd->regdesc[cpnum].accessinst.cprt.read_b1, | |
1832 | cpd->regdesc[cpnum].accessinst.cprt.write_b0, | |
1833 | cpd->regdesc[cpnum].accessinst.cprt.write_b1, 0xff); | |
1834 | } | |
1835 | else { | |
1836 | len += msgbuild(BUFFERDATA(packet->pk_buffer)+25, "%b%b%b%b%b%", | |
1837 | cpd->regdesc[cpnum].accessinst.cpdt.rdbits, | |
1838 | cpd->regdesc[cpnum].accessinst.cpdt.nbit,0,0, 0xff); | |
1839 | } | |
1840 | register_debug_message_handler(); | |
1841 | packet->pk_length = len; | |
1842 | Adp_ChannelWrite(CI_HADP, packet); /* Transmit message. */ | |
1843 | reason = ADP_Info |TtoH; | |
1844 | err = wait_for_debug_message(&reason, &debugID, &OSinfo1, &OSinfo2, | |
1845 | &status, &packet); | |
1846 | if (err != RDIError_NoError) { | |
1847 | DevSW_FreePacket(packet); | |
1848 | return err; | |
1849 | } | |
1850 | unpack_message(BUFFERDATA(packet->pk_buffer), "%w%w%w%w%w%w", &reason, &debugID, | |
1851 | &OSinfo1, &OSinfo2, &subreason, &status); | |
1852 | DevSW_FreePacket(packet); | |
1853 | if (subreason != ADP_Info_DescribeCoPro) | |
1854 | return RDIError_Error; | |
1855 | else | |
1856 | return status; | |
1857 | ||
1858 | case RDIInfo_RequestCoProDesc: | |
1859 | #ifdef DEBUG | |
1860 | angel_DebugPrint("DEBUG: RDIInfo_RequestCoProDesc.\n"); | |
1861 | #endif | |
1862 | cpnum = *(int *)arg1; | |
1863 | cpd = (struct Dbg_CoProDesc *)arg2; | |
1864 | packet = DevSW_AllocatePacket(Armsd_BufferSize); | |
1865 | len = msgbuild(BUFFERDATA(packet->pk_buffer), "%w%w%w%w%w", ADP_Info | HtoT, 0, | |
1866 | ADP_HandleUnknown, ADP_HandleUnknown, | |
1867 | ADP_Info_RequestCoProDesc); | |
1868 | len += msgbuild(BUFFERDATA(packet->pk_buffer)+20, "%b", *(int *)arg1); | |
1869 | packet->pk_length = len; | |
1870 | register_debug_message_handler(); | |
1871 | Adp_ChannelWrite(CI_HADP, packet); /* Transmit message. */ | |
1872 | reason = ADP_Info |TtoH; | |
1873 | err = wait_for_debug_message(&reason, &debugID, &OSinfo1, &OSinfo2, | |
1874 | &status, &packet); | |
1875 | if (err != RDIError_NoError) { | |
1876 | DevSW_FreePacket(packet); | |
1877 | return err; | |
1878 | } | |
1879 | count = unpack_message(BUFFERDATA(packet->pk_buffer), "%w%w%w%w%w%w", &reason, | |
1880 | &debugID, &OSinfo1, &OSinfo2, &subreason, &status); | |
1881 | if (subreason != ADP_Info_RequestCoProDesc) { | |
1882 | DevSW_FreePacket(packet); | |
1883 | return RDIError_Error; | |
1884 | } else if ( status != RDIError_NoError ) { | |
1885 | DevSW_FreePacket(packet); | |
1886 | return status; | |
1887 | } else { | |
1888 | bp = BUFFERDATA(packet->pk_buffer)+count; | |
1889 | for ( i = 0; *bp != 0xFF && i < cpd->entries; ++i ) { | |
1890 | cpd->regdesc[i].rmin = *bp++; | |
1891 | cpd->regdesc[i].rmax = *bp++; | |
1892 | cpd->regdesc[i].nbytes = *bp++; | |
1893 | cpd->regdesc[i].access = *bp++; | |
1894 | } | |
1895 | cpd->entries = i; | |
1896 | if ( *bp != 0xFF ) | |
1897 | status = RDIError_BufferFull; | |
1898 | else | |
1899 | SetCPWords( cpnum, cpd ); | |
1900 | DevSW_FreePacket(packet); | |
1901 | return status; | |
1902 | } | |
1903 | ||
1904 | case RDIInfo_GetLoadSize: | |
1905 | #ifdef DEBUG | |
1906 | angel_DebugPrint("DEBUG: ADP_Info_AngelBufferSize.\n"); | |
1907 | #endif | |
1908 | register_debug_message_handler(); | |
1909 | msgsend(CI_HADP, "%w%w%w%w%w", ADP_Info | HtoT, 0, | |
1910 | ADP_HandleUnknown, ADP_HandleUnknown, | |
1911 | ADP_Info_AngelBufferSize); | |
1912 | reason = ADP_Info |TtoH; | |
1913 | err = wait_for_debug_message(&reason, &debugID, &OSinfo1, &OSinfo2, | |
1914 | &status, &packet); | |
1915 | if (err != RDIError_NoError) { | |
1916 | DevSW_FreePacket(packet); | |
1917 | return err; | |
1918 | } | |
1919 | unpack_message(BUFFERDATA(packet->pk_buffer), "%w%w%w%w%w%w", &reason, | |
1920 | &debugID, &OSinfo1, &OSinfo2, &subreason, &status); | |
1921 | if (subreason != ADP_Info_AngelBufferSize) { | |
1922 | DevSW_FreePacket(packet); | |
1923 | return RDIError_Error; | |
1924 | } | |
1925 | else { | |
1926 | word defaultsize, longsize; | |
1927 | unpack_message(BUFFERDATA(packet->pk_buffer)+24, "%w%w", | |
1928 | &defaultsize, &longsize); | |
1929 | *arg1 = longsize - ADP_WriteHeaderSize; /* space for ADP header */ | |
1930 | #ifdef MONITOR_DOWNLOAD_PACKETS | |
1931 | angel_DebugPrint("DEBUG: ADP_Info_AngelBufferSize: got (%d, %d), returning %d.\n", | |
1932 | defaultsize, longsize, *arg1); | |
1933 | #endif | |
1934 | DevSW_FreePacket(packet); | |
1935 | return status; | |
1936 | } | |
1937 | ||
1938 | case RDIVector_Catch: | |
1939 | #ifdef DEBUG | |
1940 | angel_DebugPrint("DEBUG: ADP_Ctrl_VectorCatch %lx.\n", *arg1); | |
1941 | #endif | |
1942 | return SendSubMessageWordAndCheckReply(ADP_Control, ADP_Ctrl_VectorCatch, *arg1); | |
1943 | ||
1944 | case RDISemiHosting_SetState: | |
1945 | #ifdef DEBUG | |
1946 | angel_DebugPrint("DEBUG: ADP_Ctrl_SemiHosting_SetState %lx.\n", *arg1); | |
1947 | #endif | |
1948 | return SendSubMessageWordAndCheckReply(ADP_Control, ADP_Ctrl_SemiHosting_SetState, *arg1); | |
1949 | ||
1950 | case RDISemiHosting_GetState: | |
1951 | #ifdef DEBUG | |
1952 | angel_DebugPrint("DEBUG: ADP_Ctrl_SemiHosting_GetState.\n"); | |
1953 | #endif | |
1954 | return SendSubMessageGetWordAndCheckReply(ADP_Control, ADP_Ctrl_SemiHosting_GetState, arg1); | |
1955 | ||
1956 | case RDISemiHosting_SetVector: | |
1957 | #ifdef DEBUG | |
1958 | angel_DebugPrint("DEBUG: ADP_Ctrl_SemiHosting_SetVector %lx.\n", *arg1); | |
1959 | #endif | |
1960 | return SendSubMessageWordAndCheckReply(ADP_Control, ADP_Ctrl_SemiHosting_SetVector, *arg1); | |
1961 | ||
1962 | case RDISemiHosting_GetVector: | |
1963 | #ifdef DEBUG | |
1964 | angel_DebugPrint("DEBUG: ADP_Ctrl_SemiHosting_GetVector.\n"); | |
1965 | #endif | |
1966 | return SendSubMessageGetWordAndCheckReply(ADP_Control, ADP_Ctrl_SemiHosting_GetVector, arg1); | |
1967 | ||
1968 | case RDISemiHosting_SetARMSWI: | |
1969 | #ifdef DEBUG | |
1970 | angel_DebugPrint("DEBUG: ADP_Ctrl_SemiHosting_SetARMSWI.\n"); | |
1971 | #endif | |
1972 | return SendSubMessageWordAndCheckReply(ADP_Control, ADP_Ctrl_SemiHosting_SetARMSWI, *arg1); | |
1973 | ||
1974 | case RDISemiHosting_GetARMSWI: | |
1975 | #ifdef DEBUG | |
1976 | angel_DebugPrint("DEBUG: ADP_Ctrl_SemiHosting_GetARMSWI.\n"); | |
1977 | #endif | |
1978 | return SendSubMessageGetWordAndCheckReply(ADP_Control, ADP_Ctrl_SemiHosting_GetARMSWI, arg1); | |
1979 | ||
1980 | case RDISemiHosting_SetThumbSWI: | |
1981 | #ifdef DEBUG | |
1982 | angel_DebugPrint("DEBUG: ADP_Ctrl_SemiHosting_SetThumbSWI.\n"); | |
1983 | #endif | |
1984 | return SendSubMessageWordAndCheckReply(ADP_Control, ADP_Ctrl_SemiHosting_SetThumbSWI, *arg1); | |
1985 | ||
1986 | case RDISemiHosting_GetThumbSWI: | |
1987 | #ifdef DEBUG | |
1988 | angel_DebugPrint("DEBUG: ADP_Ctrl_SemiHosting_GetThumbSWI.\n"); | |
1989 | #endif | |
1990 | return SendSubMessageGetWordAndCheckReply(ADP_Control, ADP_Ctrl_SemiHosting_GetThumbSWI, arg1); | |
1991 | ||
1992 | case RDIInfo_SetTopMem: | |
1993 | #ifdef DEBUG | |
1994 | angel_DebugPrint("DEBUG: ADP_Ctrl_SetTopMem.\n"); | |
1995 | #endif | |
1996 | return SendSubMessageWordAndCheckReply(ADP_Control, ADP_Ctrl_SetTopMem, *arg1); | |
1997 | ||
1998 | case RDIPointStatus_Watch: | |
1999 | #ifdef DEBUG | |
2000 | angel_DebugPrint("DEBUG: ADP_Ctrl_PointStatus_Watch.\n"); | |
2001 | #endif | |
2002 | register_debug_message_handler(); | |
2003 | msgsend(CI_HADP, "%w%w%w%w%w%w", ADP_Control | HtoT, 0, | |
2004 | ADP_HandleUnknown, ADP_HandleUnknown, | |
2005 | ADP_Ctrl_PointStatus_Watch, *arg1 ); | |
2006 | reason = ADP_Control |TtoH; | |
2007 | err = wait_for_debug_message(&reason, &debugID, &OSinfo1, &OSinfo2, | |
2008 | &status, &packet); | |
2009 | if (err != RDIError_NoError) { | |
2010 | DevSW_FreePacket(packet); | |
2011 | return err; | |
2012 | } | |
2013 | unpack_message(BUFFERDATA(packet->pk_buffer), "%w%w%w%w%w%w%w%w", &reason, | |
2014 | &debugID, &OSinfo1, &OSinfo2, &subreason, &status, | |
2015 | arg1, arg2); | |
2016 | if (subreason != ADP_Ctrl_PointStatus_Watch) { | |
2017 | DevSW_FreePacket(packet); | |
2018 | return RDIError_Error; | |
2019 | } | |
2020 | else | |
2021 | return status; | |
2022 | ||
2023 | case RDIPointStatus_Break: | |
2024 | #ifdef DEBUG | |
2025 | angel_DebugPrint("DEBUG: ADP_Ctrl_PointStatus_Break.\n"); | |
2026 | #endif | |
2027 | register_debug_message_handler(); | |
2028 | msgsend(CI_HADP, "%w%w%w%w%w%w", ADP_Control | HtoT, 0, | |
2029 | ADP_HandleUnknown, ADP_HandleUnknown, | |
2030 | ADP_Ctrl_PointStatus_Break, *arg1 ); | |
2031 | reason = ADP_Control |TtoH; | |
2032 | err = wait_for_debug_message(&reason, &debugID, &OSinfo1, &OSinfo2, | |
2033 | &status, &packet); | |
2034 | if (err != RDIError_NoError) { | |
2035 | DevSW_FreePacket(packet); | |
2036 | return err; | |
2037 | } | |
2038 | unpack_message(BUFFERDATA(packet->pk_buffer), "%w%w%w%w%w%w%w%w", &reason, | |
2039 | &debugID, &OSinfo1, &OSinfo2, &subreason, &status, | |
2040 | arg1, arg2); | |
2041 | if (subreason != ADP_Ctrl_PointStatus_Break) { | |
2042 | DevSW_FreePacket(packet); | |
2043 | return RDIError_Error; | |
2044 | } | |
2045 | else | |
2046 | return status; | |
2047 | ||
2048 | case RDIInfo_DownLoad: | |
2049 | #ifdef DEBUG | |
2050 | angel_DebugPrint("DEBUG: ADP_Ctrl_Download_Supported.\n"); | |
2051 | #endif | |
2052 | return SendSubMessageAndCheckReply(ADP_Control, ADP_Ctrl_Download_Supported); | |
2053 | ||
2054 | case RDIConfig_Count: | |
2055 | #ifdef DEBUG | |
2056 | angel_DebugPrint("DEBUG: ADP_ICEM_ConfigCount.\n"); | |
2057 | #endif | |
2058 | return SendSubMessageGetWordAndCheckReply(ADP_ICEman, ADP_ICEM_ConfigCount, arg1); | |
2059 | ||
2060 | case RDIConfig_Nth: | |
2061 | #ifdef DEBUG | |
2062 | angel_DebugPrint("DEBUG: ADP_ICEM_ConfigNth.\n"); | |
2063 | #endif | |
2064 | register_debug_message_handler(); | |
2065 | msgsend(CI_HADP, "%w%w%w%w%w%w", ADP_ICEman | HtoT, 0, | |
2066 | ADP_HandleUnknown, ADP_HandleUnknown, | |
2067 | ADP_ICEM_ConfigNth, *arg1 ); | |
2068 | reason = ADP_ICEman |TtoH; | |
2069 | err = wait_for_debug_message(&reason, &debugID, &OSinfo1, &OSinfo2, | |
2070 | &status, &packet); | |
2071 | if (err != RDIError_NoError) { | |
2072 | DevSW_FreePacket(packet); | |
2073 | return err; | |
2074 | } else { | |
2075 | RDI_ConfigDesc *cd = (RDI_ConfigDesc *)arg2; | |
2076 | unsigned char n; | |
2077 | len = unpack_message(BUFFERDATA(packet->pk_buffer), "%w%w%w%w%w%w%w%b", | |
2078 | &reason, &debugID, | |
2079 | &OSinfo1, &OSinfo2, &subreason, &status, | |
2080 | &cd->version, &n); | |
2081 | if (subreason != ADP_ICEM_ConfigNth) { | |
2082 | DevSW_FreePacket(packet); | |
2083 | return RDIError_Error; | |
2084 | } | |
2085 | else { | |
2086 | memcpy( cd->name, BUFFERDATA(packet->pk_buffer)+len, n+1 ); | |
2087 | cd->name[n] = 0; | |
2088 | return status; | |
2089 | } | |
2090 | } | |
2091 | ||
2092 | case RDIInfo_Icebreaker: | |
2093 | #ifdef DEBUG | |
2094 | angel_DebugPrint("DEBUG: ADP_ICEB_Exists.\n"); | |
2095 | #endif | |
2096 | return SendSubMessageAndCheckReply(ADP_ICEbreakerHADP, ADP_ICEB_Exists); | |
2097 | ||
2098 | case RDIIcebreaker_GetLocks: | |
2099 | #ifdef DEBUG | |
2100 | angel_DebugPrint("DEBUG: ADP_ICEB_GetLocks.\n"); | |
2101 | #endif | |
2102 | return SendSubMessageGetWordAndCheckReply(ADP_ICEbreakerHADP, ADP_ICEB_GetLocks, arg1); | |
2103 | ||
2104 | case RDIIcebreaker_SetLocks: | |
2105 | #ifdef DEBUG | |
2106 | angel_DebugPrint("DEBUG: ADP_ICEB_SetLocks.\n"); | |
2107 | #endif | |
2108 | return SendSubMessageWordAndCheckReply(ADP_ICEbreakerHADP, ADP_ICEB_SetLocks, *arg1); | |
2109 | ||
2110 | case RDICommsChannel_ToHost: | |
2111 | #ifdef DEBUG | |
2112 | angel_DebugPrint("DEBUG: ADP_ICEB_CC_Connect_ToHost.\n"); | |
2113 | #endif | |
2114 | if ( angel_cc_exists() == RDIError_NoError ) { | |
2115 | ||
2116 | /* | |
2117 | * The following three lines of code have to be removed in order to get | |
2118 | * the Windows Angel Channel Viewer working with the Thumb comms channel. | |
2119 | * At the moment it allows the ARMSD command line to register a CCIN/CCOUT | |
2120 | * callback which stops the ACV working! | |
2121 | */ | |
2122 | #ifdef __unix | |
2123 | ccstate.tohost = (RDICCProc_ToHost *)arg1; | |
2124 | ccstate.tohostarg = arg2; | |
2125 | angel_check_DCC_handler( &ccstate ); | |
2126 | #endif | |
2127 | #ifdef _WIN32 | |
2128 | ||
2129 | #endif | |
2130 | ||
2131 | register_debug_message_handler(); | |
2132 | msgsend(CI_HADP, "%w%w%w%w%w%b", ADP_ICEbreakerHADP | HtoT, 0, | |
2133 | ADP_HandleUnknown, ADP_HandleUnknown, | |
2134 | ADP_ICEB_CC_Connect_ToHost, (arg1 != NULL) ); | |
2135 | return CheckSubMessageReply(ADP_ICEbreakerHADP, ADP_ICEB_CC_Connect_ToHost); | |
2136 | } else { | |
2137 | return RDIError_UnimplementedMessage; | |
2138 | } | |
2139 | ||
2140 | case RDICommsChannel_FromHost: | |
2141 | #ifdef DEBUG | |
2142 | angel_DebugPrint("DEBUG: ADP_ICEB_CC_Connect_FromHost.\n"); | |
2143 | #endif | |
2144 | if ( angel_cc_exists() == RDIError_NoError ) { | |
2145 | ||
2146 | ccstate.fromhost = (RDICCProc_FromHost *)arg1; | |
2147 | ccstate.fromhostarg = arg2; | |
2148 | angel_check_DCC_handler( &ccstate ); | |
2149 | ||
2150 | register_debug_message_handler(); | |
2151 | msgsend(CI_HADP, "%w%w%w%w%w%b", ADP_ICEbreakerHADP | HtoT, 0, | |
2152 | ADP_HandleUnknown, ADP_HandleUnknown, | |
2153 | ADP_ICEB_CC_Connect_FromHost, (arg1 != NULL) ); | |
2154 | return CheckSubMessageReply(ADP_ICEbreakerHADP, ADP_ICEB_CC_Connect_FromHost); | |
2155 | } else { | |
2156 | return RDIError_UnimplementedMessage; | |
2157 | } | |
2158 | ||
2159 | case RDIProfile_Stop: | |
2160 | return SendSubMessageAndCheckReply(ADP_Profile, ADP_Profile_Stop); | |
2161 | ||
2162 | case RDIProfile_ClearCounts: | |
2163 | return SendSubMessageAndCheckReply(ADP_Profile, ADP_Profile_ClearCounts); | |
2164 | ||
2165 | case RDIProfile_Start: | |
2166 | #ifdef DEBUG | |
2167 | angel_DebugPrint("DEBUG: ADP_Profile_Start %ld.\n", (long)*arg1); | |
2168 | #endif | |
2169 | return SendSubMessageWordAndCheckReply(ADP_Profile, ADP_Profile_Start, *arg1); | |
2170 | ||
2171 | case RDIProfile_WriteMap: | |
2172 | { RDI_ProfileMap *map = (RDI_ProfileMap *)arg1; | |
2173 | int32 maplen = map->len, | |
2174 | offset, | |
2175 | size; | |
2176 | int32 chunk = (Armsd_LongBufSize-CHAN_HEADER_SIZE-ADP_ProfileWriteHeaderSize) / sizeof(ARMword); | |
2177 | /* Maximum number of words sendable in one message */ | |
2178 | int oldrev = bytesex_reversing(); | |
2179 | int host_little = *(uint8 const *)&hostsex; | |
2180 | #ifdef DEBUG | |
2181 | angel_DebugPrint("DEBUG: ADP_Profile_WriteMap %ld.\n", maplen); | |
2182 | #endif | |
2183 | status = RDIError_NoError; | |
2184 | if (!host_little) { | |
2185 | bytesex_reverse(1); | |
2186 | for (offset = 0; offset < maplen; offset++) | |
2187 | map->map[offset] = bytesex_hostval(map->map[offset]); | |
2188 | } | |
2189 | for (offset = 0; offset < maplen; offset += size) { | |
2190 | unsigned hdrlen; | |
2191 | size = maplen - offset; | |
2192 | packet = (Packet *)DevSW_AllocatePacket(Armsd_LongBufSize); | |
2193 | if (size > chunk) size = chunk; | |
2194 | hdrlen = msgbuild(BUFFERDATA(packet->pk_buffer), "%w%w%w%w%w%w%w%w", | |
2195 | ADP_Profile | HtoT, 0, ADP_HandleUnknown, | |
2196 | ADP_HandleUnknown, ADP_Profile_WriteMap, | |
2197 | maplen, size, offset); | |
2198 | ||
2199 | /* Copy the data into the packet. */ | |
2200 | memcpy(BUFFERDATA(packet->pk_buffer)+hdrlen, | |
2201 | &map->map[offset], (size_t)size * sizeof(ARMword)); | |
2202 | packet->pk_length = size * sizeof(ARMword) + hdrlen; | |
2203 | register_debug_message_handler(); | |
2204 | Adp_ChannelWrite(CI_HADP, packet); | |
2205 | reason = ADP_Profile | TtoH; | |
2206 | err = wait_for_debug_message(&reason, &debugID, &OSinfo1, &OSinfo2, | |
2207 | &status, &packet); | |
2208 | if (err == RDIError_NoError) { | |
2209 | unpack_message(BUFFERDATA(packet->pk_buffer), "%w%w%w%w%w%w", &reason, | |
2210 | &debugID, &OSinfo1, &OSinfo2, &subreason, &status); | |
2211 | if (subreason != ADP_Profile_WriteMap) { | |
2212 | err = RDIError_Error; | |
2213 | } | |
2214 | DevSW_FreePacket(packet); | |
2215 | } | |
2216 | if (err != RDIError_NoError) { status = err; break; } | |
2217 | } | |
2218 | if (!host_little) { | |
2219 | for (offset = 0; offset < maplen; offset++) | |
2220 | map->map[offset] = bytesex_hostval(map->map[offset]); | |
2221 | bytesex_reverse(oldrev); | |
2222 | } | |
2223 | return status; | |
2224 | } | |
2225 | ||
2226 | case RDIProfile_ReadMap: | |
2227 | { int32 maplen = *(int32 *)arg1, | |
2228 | offset = 0, | |
2229 | size; | |
2230 | int32 chunk = (Armsd_BufferSize-CHAN_HEADER_SIZE-ADP_ProfileReadHeaderSize) / sizeof(ARMword); | |
2231 | #ifdef DEBUG | |
2232 | angel_DebugPrint("DEBUG: ADP_Profile_ReadMap %ld.\n", maplen); | |
2233 | #endif | |
2234 | status = RDIError_NoError; | |
2235 | for (offset = 0; offset < maplen; offset += size) { | |
2236 | size = maplen - offset; | |
2237 | if (size > chunk) size = chunk; | |
2238 | register_debug_message_handler(); | |
2239 | msgsend(CI_HADP, "%w%w%w%w%w%w%w", ADP_Profile | HtoT, 0, | |
2240 | ADP_HandleUnknown, ADP_HandleUnknown, | |
2241 | ADP_Profile_ReadMap, offset, size); | |
2242 | reason = ADP_Profile | TtoH; | |
2243 | err = wait_for_debug_message(&reason, &debugID, &OSinfo1, &OSinfo2, | |
2244 | &status, &packet); | |
2245 | if (err != RDIError_NoError) return err; | |
2246 | unpack_message(BUFFERDATA(packet->pk_buffer), "%w%w%w%w%w%w", &reason, | |
2247 | &debugID, &OSinfo1, &OSinfo2, &subreason, &status); | |
2248 | memcpy(&arg2[offset], BUFFERDATA(packet->pk_buffer)+ADP_ProfileReadHeaderSize, | |
2249 | size * sizeof(ARMword)); | |
2250 | DevSW_FreePacket(packet); | |
2251 | if (status != RDIError_NoError) break; | |
2252 | } | |
2253 | { int oldrev = bytesex_reversing(); | |
2254 | int host_little = *(uint8 const *)&hostsex; | |
2255 | if (!host_little) { | |
2256 | bytesex_reverse(1); | |
2257 | for (offset = 0; offset < maplen; offset++) | |
2258 | arg2[offset] = bytesex_hostval(arg2[offset]); | |
2259 | } | |
2260 | bytesex_reverse(oldrev); | |
2261 | } | |
2262 | return status; | |
2263 | } | |
2264 | ||
2265 | case RDIInfo_CanTargetExecute: | |
2266 | #ifdef DEBUG | |
2267 | printf("DEBUG: RDIInfo_CanTargetExecute.\n"); | |
2268 | #endif | |
2269 | return SendSubMessageAndCheckReply(ADP_Info, ADP_Info_CanTargetExecute); | |
2270 | ||
2271 | case RDIInfo_AgentEndianess: | |
2272 | return SendSubMessageAndCheckReply(ADP_Info, ADP_Info_AgentEndianess); | |
2273 | ||
2274 | default: | |
2275 | #ifdef DEBUG | |
2276 | angel_DebugPrint("DEBUG: Fell through ADP_Info, default case taken.\n"); | |
2277 | angel_DebugPrint("DEBUG: type = 0x%x.\n", type); | |
2278 | #endif | |
2279 | if (type & RDIInfo_CapabilityRequest) { | |
2280 | switch (type & ~RDIInfo_CapabilityRequest) { | |
2281 | case RDISemiHosting_SetARMSWI: | |
2282 | return SendSubMessageAndCheckReply(ADP_Info, ADP_Info_ChangeableSHSWI); | |
2283 | default: | |
2284 | #ifdef DEBUG | |
2285 | angel_DebugPrint( | |
2286 | "DEBUG: ADP_Info - Capability Request(%d) - reporting unimplemented \n", | |
2287 | type & ~RDIInfo_CapabilityRequest); | |
2288 | #endif | |
2289 | break; | |
2290 | } | |
2291 | } | |
2292 | return RDIError_UnimplementedMessage; | |
2293 | } | |
2294 | } | |
2295 | ||
2296 | ||
2297 | /*----------------------------------------------------------------------*/ | |
2298 | /*----angel_RDI_AddConfig------------------------------------------------*/ | |
2299 | /*----------------------------------------------------------------------*/ | |
2300 | ||
2301 | /* Add a configuration: use ADP_ICEM_AddConfig. */ | |
2302 | int angel_RDI_AddConfig(unsigned long nbytes) { | |
2303 | Packet *packet = NULL; | |
2304 | int status, reason, subreason, debugID, OSinfo1, OSinfo2, err; | |
2305 | ||
2306 | #ifdef DEBUG | |
2307 | angel_DebugPrint("DEBUG: Entered angel_RDI_AddConfig.\n"); | |
2308 | #endif | |
2309 | register_debug_message_handler(); | |
2310 | msgsend(CI_HADP, "%w%w%w%w%w%w", ADP_ICEman | HtoT, | |
2311 | 0, ADP_HandleUnknown, ADP_HandleUnknown, | |
2312 | ADP_ICEM_AddConfig, nbytes); | |
2313 | reason=ADP_ICEman | TtoH; | |
2314 | err = wait_for_debug_message(&reason, &debugID, &OSinfo1, &OSinfo2, | |
2315 | &status, &packet); | |
2316 | if (err != RDIError_NoError) { | |
2317 | DevSW_FreePacket(packet); | |
2318 | return -1; | |
2319 | } | |
2320 | unpack_message(BUFFERDATA(packet->pk_buffer), "%w%w%w%w%w%w", &reason, &debugID, | |
2321 | &OSinfo1, &OSinfo2, &subreason, &status); | |
2322 | DevSW_FreePacket(packet); | |
2323 | if ( subreason != ADP_ICEM_AddConfig ) | |
2324 | return RDIError_Error; | |
2325 | else | |
2326 | return status; | |
2327 | } | |
2328 | ||
2329 | ||
2330 | /*----------------------------------------------------------------------*/ | |
2331 | /*----angel_RDI_LoadConfigData-------------------------------------------*/ | |
2332 | /*----------------------------------------------------------------------*/ | |
2333 | ||
2334 | /* Load configuration data: use ADP_Ctrl_Download_Data. */ | |
2335 | int angel_RDI_LoadConfigData(unsigned long nbytes, char const *data) { | |
2336 | Packet *packet = NULL; | |
2337 | int len, status, reason, subreason, debugID, OSinfo1, OSinfo2, err; | |
2338 | ||
2339 | #ifdef DEBUG | |
2340 | angel_DebugPrint("DEBUG: Entered angel_RDI_LoadConfigData (%d bytes)\n", nbytes); | |
2341 | #endif | |
2342 | #if 0 | |
2343 | if (err = angel_RDI_AddConfig(nbytes) != RDIError_NoError) | |
2344 | return err; | |
2345 | #endif | |
2346 | packet = DevSW_AllocatePacket(Armsd_LongBufSize); | |
2347 | len = msgbuild(BUFFERDATA(packet->pk_buffer), "%w%w%w%w%w%w", | |
2348 | ADP_Control | HtoT, 0, | |
2349 | ADP_HandleUnknown, ADP_HandleUnknown, | |
2350 | ADP_Ctrl_Download_Data, nbytes); | |
2351 | memcpy(BUFFERDATA(packet->pk_buffer)+len, data, nbytes); | |
2352 | len += nbytes; | |
2353 | packet->pk_length = len; | |
2354 | #ifdef DEBUG | |
2355 | angel_DebugPrint("DEBUG: packet len %d.\n", len); | |
2356 | #endif | |
2357 | register_debug_message_handler(); | |
2358 | Adp_ChannelWrite(CI_HADP, packet); | |
2359 | reason=ADP_Control | TtoH; | |
2360 | err = wait_for_debug_message(&reason, &debugID, &OSinfo1, &OSinfo2, | |
2361 | &status, &packet); | |
2362 | if (err != RDIError_NoError) { | |
2363 | DevSW_FreePacket(packet); | |
2364 | return -1; | |
2365 | } | |
2366 | unpack_message(BUFFERDATA(packet->pk_buffer), "%w%w%w%w%w%w", &reason, &debugID, | |
2367 | &OSinfo1, &OSinfo2, &subreason, &status); | |
2368 | DevSW_FreePacket(packet); | |
2369 | if ( subreason != ADP_Ctrl_Download_Data ) | |
2370 | return RDIError_Error; | |
2371 | else | |
2372 | return status; | |
2373 | } | |
2374 | ||
2375 | ||
2376 | /*----------------------------------------------------------------------*/ | |
2377 | /*----angel_RDI_SelectConfig---------------------------------------------*/ | |
2378 | /*----------------------------------------------------------------------*/ | |
2379 | ||
2380 | /* Select a configuration: use ADP_ICEM_SelecConfig.*/ | |
2381 | int angel_RDI_SelectConfig(RDI_ConfigAspect aspect, char const *name, | |
2382 | RDI_ConfigMatchType matchtype, unsigned versionreq, | |
2383 | unsigned *versionp) | |
2384 | { | |
2385 | Packet *packet = NULL; | |
2386 | int len, status, reason, subreason, debugID, OSinfo1, OSinfo2, err; | |
2387 | ||
2388 | #ifdef DEBUG | |
2389 | angel_DebugPrint("DEBUG: Entered angel_RDI_SelectConfig.\n"); | |
2390 | #endif | |
2391 | packet = DevSW_AllocatePacket(Armsd_BufferSize); | |
2392 | len = msgbuild(BUFFERDATA(packet->pk_buffer), "%w%w%w%w%w%b%b%b%w", | |
2393 | ADP_ICEman | HtoT, 0, | |
2394 | ADP_HandleUnknown, ADP_HandleUnknown, | |
2395 | ADP_ICEM_SelectConfig, aspect, strlen(name), | |
2396 | matchtype, versionreq); | |
2397 | /* copy the name into the buffer */ | |
2398 | memcpy(BUFFERDATA(packet->pk_buffer)+len, name, strlen(name)); | |
2399 | len += strlen(name); | |
2400 | packet->pk_length = len; | |
2401 | register_debug_message_handler(); | |
2402 | Adp_ChannelWrite(CI_HADP, packet); | |
2403 | reason=ADP_ICEman | TtoH; | |
2404 | err = wait_for_debug_message(&reason, &debugID, &OSinfo1, &OSinfo2, | |
2405 | &status, &packet); | |
2406 | if (err != RDIError_NoError) { | |
2407 | DevSW_FreePacket(packet); | |
2408 | return err; | |
2409 | } | |
2410 | unpack_message(BUFFERDATA(packet->pk_buffer), "%w%w%w%w%w%w%w", | |
2411 | &reason, &debugID, &OSinfo1, &OSinfo2, | |
2412 | &subreason, &status, versionp); | |
2413 | DevSW_FreePacket(packet); | |
2414 | if ( subreason != ADP_ICEM_SelectConfig ) | |
2415 | return RDIError_Error; | |
2416 | else | |
2417 | return status; | |
2418 | } | |
2419 | ||
2420 | ||
2421 | /*----------------------------------------------------------------------*/ | |
2422 | /*----angel_RDI_LoadAgent------------------------------------------------*/ | |
2423 | /*----------------------------------------------------------------------*/ | |
2424 | ||
2425 | /* Load a new debug agent: use ADP_Ctrl_Download_Agent. */ | |
2426 | int angel_RDI_LoadAgent(ARMword dest, unsigned long size, | |
2427 | getbufferproc *getb, void *getbarg) | |
2428 | { | |
2429 | Packet *packet = NULL; | |
2430 | int status, reason, subreason, debugID, OSinfo1, OSinfo2, err; | |
2431 | time_t t; | |
2432 | ||
2433 | #if defined(DEBUG) || defined(DEBUG_LOADAGENT) | |
2434 | angel_DebugPrint("DEBUG: Entered angel_RDI_LoadAgent.\n"); | |
2435 | #endif | |
2436 | register_debug_message_handler(); | |
2437 | msgsend(CI_HADP, "%w%w%w%w%w%w%w", ADP_Control | HtoT, | |
2438 | 0, ADP_HandleUnknown, ADP_HandleUnknown, | |
2439 | ADP_Ctrl_Download_Agent, dest, size); | |
2440 | reason=ADP_Control | TtoH; | |
2441 | err = wait_for_debug_message(&reason, &debugID, &OSinfo1, &OSinfo2, | |
2442 | &status, &packet); | |
2443 | if (err != RDIError_NoError) { | |
2444 | DevSW_FreePacket(packet); | |
2445 | return -1; | |
2446 | } | |
2447 | unpack_message(BUFFERDATA(packet->pk_buffer), "%w%w%w%w%w%w", &reason, &debugID, | |
2448 | &OSinfo1, &OSinfo2, &subreason, &status); | |
2449 | DevSW_FreePacket(packet); | |
2450 | if ( subreason != ADP_Ctrl_Download_Agent ) | |
2451 | return RDIError_Error; | |
2452 | if ( status != RDIError_NoError ) | |
2453 | return status; | |
2454 | ||
2455 | #if defined(DEBUG) || defined(DEBUG_LOADAGENT) | |
2456 | angel_DebugPrint("DEBUG: starting agent data download.\n"); | |
2457 | #endif | |
2458 | { unsigned long pos = 0, segsize; | |
2459 | for (; pos < size; pos += segsize) { | |
2460 | char *b = getb(getbarg, &segsize); | |
2461 | if (b == NULL) return RDIError_NoError; | |
2462 | err = angel_RDI_LoadConfigData( segsize, b ); | |
2463 | if (err != RDIError_NoError) return err; | |
2464 | } | |
2465 | } | |
2466 | #if defined(DEBUG) || defined(DEBUG_LOADAGENT) | |
2467 | angel_DebugPrint("DEBUG: finished downloading new agent.\n"); | |
2468 | #endif | |
2469 | ||
2470 | /* renegotiate back down */ | |
2471 | err = angel_negotiate_defaults(); | |
2472 | if (err != adp_ok) | |
2473 | return err; | |
2474 | ||
2475 | /* Output a message to tell the user what is going on. This is vital | |
2476 | * when switching from ADP EICE to ADP over JTAG, as then the user | |
2477 | * has to reset the target board ! | |
2478 | */ | |
2479 | { char msg[256]; | |
2480 | int len=angel_RDI_errmess(msg, 256, adp_new_agent_starting); | |
2481 | angel_hostif->write(angel_hostif->hostosarg, msg, len); | |
2482 | } | |
2483 | ||
2484 | /* get new image started */ | |
2485 | #if defined(DEBUG) || defined(DEBUG_LOADAGENT) | |
2486 | angel_DebugPrint("DEBUG: sending start message for new agent.\n"); | |
2487 | #endif | |
2488 | ||
2489 | register_debug_message_handler(); | |
2490 | msgsend(CI_HADP, "%w%w%w%w%w%w", ADP_Control | HtoT, | |
2491 | 0, ADP_HandleUnknown, ADP_HandleUnknown, | |
2492 | ADP_Ctrl_Start_Agent, dest); | |
2493 | reason=ADP_Control | TtoH; | |
2494 | err = wait_for_debug_message(&reason, &debugID, &OSinfo1, &OSinfo2, | |
2495 | &status, &packet); | |
2496 | if (err != RDIError_NoError) { | |
2497 | DevSW_FreePacket(packet); | |
2498 | return -1; | |
2499 | } | |
2500 | unpack_message(BUFFERDATA(packet->pk_buffer), "%w%w%w%w%w%w", &reason, | |
2501 | &debugID, &OSinfo1, &OSinfo2, &subreason, &status); | |
2502 | DevSW_FreePacket(packet); | |
2503 | if ( subreason != ADP_Ctrl_Start_Agent ) | |
2504 | return RDIError_Error; | |
2505 | if ( status != RDIError_NoError ) | |
2506 | return status; | |
2507 | ||
2508 | /* wait for image to start up */ | |
2509 | heartbeat_enabled = FALSE; | |
2510 | t=time(NULL); | |
2511 | do { | |
2512 | Adp_AsynchronousProcessing(async_block_on_nothing); | |
2513 | if ((time(NULL)-t) > 2) { | |
2514 | #ifdef DEBUG | |
2515 | angel_DebugPrint("DEBUG: no booted message from new image yet.\n"); | |
2516 | #endif | |
2517 | break; | |
2518 | } | |
2519 | } while (booted_not_received); | |
2520 | booted_not_received=1; | |
2521 | ||
2522 | /* Give device driver a chance to do any necessary resyncing with new agent. | |
2523 | * Only used by etherdrv.c at the moment. | |
2524 | */ | |
2525 | (void)Adp_Ioctl( DC_RESYNC, NULL ); | |
2526 | ||
2527 | #if defined(DEBUG) || defined(DEBUG_LOADAGENT) | |
2528 | angel_DebugPrint("DEBUG: reopening to new agent.\n"); | |
2529 | #endif | |
2530 | err = angel_RDI_open(0, NULL, NULL, NULL); | |
2531 | switch ( err ) | |
2532 | { | |
2533 | case RDIError_NoError: | |
2534 | { | |
2535 | #if defined(DEBUG) || defined(DEBUG_LOADAGENT) | |
2536 | angel_DebugPrint( "LoadAgent: Open returned RDIError_NoError\n" ); | |
2537 | #endif | |
2538 | break; | |
2539 | } | |
2540 | ||
2541 | case RDIError_LittleEndian: | |
2542 | { | |
2543 | #if defined(DEBUG) || defined(DEBUG_LOADAGENT) | |
2544 | angel_DebugPrint( "LoadAgent: Open returned RDIError_LittleEndian (OK)\n" ); | |
2545 | #endif | |
2546 | err = RDIError_NoError; | |
2547 | break; | |
2548 | } | |
2549 | ||
2550 | case RDIError_BigEndian: | |
2551 | { | |
2552 | #if defined(DEBUG) || defined(DEBUG_LOADAGENT) | |
2553 | angel_DebugPrint( "LoadAgent: Open returned RDIError_BigEndian (OK)\n" ); | |
2554 | #endif | |
2555 | err = RDIError_NoError; | |
2556 | break; | |
2557 | } | |
2558 | ||
2559 | default: | |
2560 | { | |
2561 | #if defined(DEBUG) || defined(DEBUG_LOADAGENT) | |
2562 | angel_DebugPrint( "LoadAgent: Open returned %d - unexpected!\n", err ); | |
2563 | #endif | |
2564 | break; | |
2565 | } | |
2566 | } | |
2567 | #ifndef NO_HEARTBEAT | |
2568 | heartbeat_enabled = TRUE; | |
2569 | #endif | |
2570 | return err; | |
2571 | } | |
2572 | ||
2573 | static int angel_RDI_errmess(char *buf, int blen, int errnum) { | |
2574 | char *s=NULL; | |
2575 | int n; | |
2576 | ||
2577 | switch (errnum) { | |
2578 | case adp_malloc_failure: | |
2579 | s=AdpMess_MallocFailed; break; | |
2580 | case adp_illegal_args: | |
2581 | s=AdpMess_IllegalArgs; break; | |
2582 | case adp_device_not_found: | |
2583 | s=AdpMess_DeviceNotFound; break; | |
2584 | case adp_device_open_failed: | |
2585 | s=AdpMess_DeviceOpenFailed; break; | |
2586 | case adp_device_already_open: | |
2587 | s=AdpMess_DeviceAlreadyOpen; break; | |
2588 | case adp_device_not_open: | |
2589 | s=AdpMess_DeviceNotOpen; break; | |
2590 | case adp_bad_channel_id: | |
2591 | s=AdpMess_BadChannelId; break; | |
2592 | case adp_callback_already_registered: | |
2593 | s=AdpMess_CBAlreadyRegd; break; | |
2594 | case adp_write_busy: | |
2595 | s=AdpMess_WriteBusy; break; | |
2596 | case adp_bad_packet: | |
2597 | s=AdpMess_BadPacket; break; | |
2598 | case adp_seq_high: | |
2599 | s=AdpMess_SeqHigh; break; | |
2600 | case adp_seq_low: | |
2601 | s=AdpMess_SeqLow; break; | |
2602 | case adp_timeout_on_open: | |
2603 | s=AdpMess_TimeoutOnOpen; break; | |
2604 | case adp_failed: | |
2605 | s=AdpMess_Failed; break; | |
2606 | case adp_abandon_boot_wait: | |
2607 | s=AdpMess_AbandonBootWait; break; | |
2608 | case adp_late_startup: | |
2609 | s=AdpMess_LateStartup; break; | |
2610 | case adp_new_agent_starting: | |
2611 | s=AdpMess_NewAgentStarting; break; | |
2612 | default: return 0; | |
2613 | } | |
2614 | n=strlen(s); | |
2615 | if (n>blen-1) n=blen-1; | |
2616 | memcpy(buf, s, n); | |
2617 | buf[n++]=0; | |
2618 | return n; | |
2619 | } | |
2620 | ||
2621 | extern const struct RDIProcVec angel_rdi; | |
2622 | const struct RDIProcVec angel_rdi = { | |
2623 | "ADP", | |
2624 | angel_RDI_open, | |
2625 | angel_RDI_close, | |
2626 | angel_RDI_read, | |
2627 | angel_RDI_write, | |
2628 | angel_RDI_CPUread, | |
2629 | angel_RDI_CPUwrite, | |
2630 | angel_RDI_CPread, | |
2631 | angel_RDI_CPwrite, | |
2632 | angel_RDI_setbreak, | |
2633 | angel_RDI_clearbreak, | |
2634 | angel_RDI_setwatch, | |
2635 | angel_RDI_clearwatch, | |
2636 | angel_RDI_execute, | |
2637 | angel_RDI_step, | |
2638 | angel_RDI_info, | |
2639 | angel_RDI_pointinq, | |
2640 | ||
2641 | angel_RDI_AddConfig, | |
2642 | angel_RDI_LoadConfigData, | |
2643 | angel_RDI_SelectConfig, | |
2644 | ||
2645 | 0, /*angel_RDI_drivernames,*/ | |
2646 | 0, /* cpunames */ | |
2647 | ||
2648 | angel_RDI_errmess, | |
2649 | ||
2650 | angel_RDI_LoadAgent | |
2651 | }; | |
2652 | ||
2653 | /* EOF ardi.c */ | |
2654 | ||
2655 | /* Not strictly necessary, but allows linking this code into armsd. */ | |
2656 | ||
2657 | struct foo { | |
2658 | char *name; | |
2659 | int (*action)(); | |
2660 | char *syntax; | |
2661 | char **helpmessage; | |
2662 | int doafterend; | |
2663 | int dobeforestart; | |
2664 | int doinmidline; | |
2665 | } hostappl_CmdTable[1] = {{"", NULL}}; | |
2666 | ||
2667 | void | |
2668 | hostappl_Init() | |
2669 | { | |
2670 | } | |
2671 | ||
2672 | int | |
2673 | hostappl_Backstop() | |
2674 | { | |
2675 | return -30; | |
2676 | } |