2 * Copyright (C) 1995 Advanced RISC Machines Limited. All rights reserved.
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
15 * msgbuild.c - utilities for assembling and interpreting ADP messages
19 #include <stdarg.h> /* ANSI varargs support */
26 # include "hostchan.h"
31 #include "angel_endian.h" /* Endianness support macros */
32 #include "msgbuild.h" /* Header file for this source code */
35 # define UNUSED(x) ((x)=(x))
40 extern unsigned int Armsd_BufferSize
;
42 #endif /* ndef TARGET */
45 unsigned int vmsgbuild(unsigned char *buffer
, const char *format
, va_list args
)
47 unsigned int blen
= 0;
50 /* Step through the format string */
51 while ((ch
= *format
++) != '\0')
56 *buffer
++ = (unsigned char)ch
;
62 switch (ch
= *format
++)
70 /* 32bit word / 32bit pointer */
71 unsigned int na
= va_arg(args
, unsigned int);
76 buffer
+= sizeof(unsigned int);
79 blen
+= sizeof(unsigned int);
88 unsigned int na
= va_arg(args
, unsigned int);
93 buffer
+= sizeof(unsigned short);
96 blen
+= sizeof(unsigned short);
105 /* 8bit character / 8bit byte */
106 ch
= va_arg(args
, int);
111 * fall through to the normal character processing
116 /* normal '%' character, or a different normal character */
118 *buffer
++ = (unsigned char)ch
;
132 * Simple routine to aid in construction of Angel messages. See the
133 * "msgbuild.h" header file for a detailed description of the operation
136 unsigned int msgbuild(unsigned char *buffer
, const char *format
, ...)
141 va_start(args
, format
);
142 blen
= vmsgbuild(buffer
, format
, args
);
148 #if !defined(JTAG_ADP_SUPPORTED) && !defined(MSG_UTILS_ONLY)
150 * This routine allocates a buffer, puts the data supplied as
151 * parameters into the buffer and sends the message. It does *NOT*
154 extern int msgsend(ChannelID chan
, const char *format
,...)
162 packet
= DevSW_AllocatePacket(Armsd_BufferSize
);
163 buffer
= packet
->pk_buffer
;
165 buffer
= angel_ChannelAllocBuffer(Angel_ChanBuffSize
);
170 va_start(args
, format
);
172 length
= vmsgbuild(BUFFERDATA(buffer
), format
, args
);
175 angel_ChannelSend(CH_DEFAULT_DEV
, chan
, buffer
, length
);
177 packet
->pk_length
= length
;
178 Adp_ChannelWrite(chan
, packet
);
188 #endif /* ndef JTAG_ADP_SUPPORTED && ndef MSG_UTILS_ONLY */
194 extern unsigned int unpack_message(unsigned char *buffer
, const char *format
, ...)
197 unsigned int blen
= 0;
201 va_start(args
, format
);
203 /* Step through the format string. */
204 while ((ch
= *format
++) != '\0')
209 ch
= (unsigned char)*buffer
++;
215 switch (ch
= *format
++)
221 unsigned int *nap
= va_arg(args
, unsigned int*);
225 *nap
= PREAD32(LE
, buffer
);
226 buffer
+= sizeof(unsigned int);
229 blen
+= sizeof(unsigned int);
238 unsigned int *nap
= va_arg(args
, unsigned int*);
242 *nap
= PREAD16(LE
,buffer
);
243 buffer
+= sizeof(unsigned short);
246 blen
+= sizeof(unsigned short);
255 /* 8-bit character, or 8-bit byte */
256 chp
= va_arg(args
, char*);
261 * fall through to the normal character processing.
266 /* normal '%' character, or a different normal character */
268 *chp
= (unsigned char)*buffer
++;