4 * Written by Eryk Vershen
8 * Copyright 1996,1997 by Apple Computer, Inc.
11 * Permission to use, copy, modify, and distribute this software and
12 * its documentation for any purpose and without fee is hereby granted,
13 * provided that the above copyright notice appears in all copies and
14 * that both the copyright notice and this permission notice appear in
15 * supporting documentation.
17 * APPLE COMPUTER DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE
18 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
19 * FOR A PARTICULAR PURPOSE.
21 * IN NO EVENT SHALL APPLE COMPUTER BE LIABLE FOR ANY SPECIAL, INDIRECT, OR
22 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
23 * LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT,
24 * NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
25 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
32 #include "layout_dump.h"
48 unsigned char bitmasks
[] = {
49 0x01, 0x03, 0x07, 0x0F,
50 0x1F, 0x3F, 0x7F, 0xFF
60 * Forward declarations
68 dump_using_layout(void *buffer
, layout
*desc
)
77 for (entry
= desc
; entry
->format
!= kEnd
; entry
++) {
78 value
= strlen(entry
->name
);
79 if (value
> max_name
) {
85 for (entry
= desc
; entry
->format
!= kEnd
; entry
++) {
87 if (entry
->format
!= kBit
) {
88 printf("%*s: ", max_name
, entry
->name
);
90 byte_length
= entry
->bit_length
/ 8;
92 if (entry
->bit_offset
!= 0 || (entry
->bit_length
% 8) != 0) {
93 printf("entry %d, can't handle bitfields yet.\n", entry
- desc
);
98 for (i
= entry
->byte_offset
; byte_length
> 0;i
++) {
100 value
|= ((unsigned char *)buffer
)[i
];
104 if (entry
->bit_offset
< 0 || entry
->bit_offset
> 8) {
105 printf("entry %d, bad bit offset (%d).\n", entry
- desc
, entry
->bit_offset
);
107 } else if (entry
->bit_length
<= 0
108 || entry
->bit_length
> (entry
->bit_offset
+ 1)) {
109 printf("entry %d, bad bit length (%d,%d).\n", entry
- desc
,
110 entry
->bit_offset
, entry
->bit_length
);
113 value
= (((unsigned char *)buffer
)[entry
->byte_offset
]
114 & bitmasks
[entry
->bit_offset
])
115 >> ((entry
->bit_offset
+ 1) - entry
->bit_length
);
118 switch (entry
->format
) {
120 printf("0x%x\n", (unsigned int) value
);
123 byte_length
= entry
->bit_length
/ 8;
124 switch (byte_length
) {
125 case 4: printf("%ld\n", (signed long)value
); break;
126 case 2: printf("%d\n", (signed short)value
); break;
127 case 1: printf("%d\n", (signed char)value
); break;
131 byte_length
= entry
->bit_length
/ 8;
132 switch (byte_length
) {
133 case 4: printf("%lu\n", (unsigned long)value
); break;
134 case 2: printf("%u\n", (unsigned short)value
); break;
135 case 1: printf("%u\n", (unsigned char)value
); break;
140 printf("%*s %s\n", max_name
, "", entry
->name
);
144 printf("entry %d, unknown format (%d).\n", entry
- desc
, entry
->format
);
152 DumpRawBuffer(unsigned char *bufferPtr
, int length
)
160 for (lineStart
= 0; lineStart
< length
; lineStart
+= lineLength
) {
161 lineLength
= kLineSize
;
162 if (lineStart
+ lineLength
> length
)
163 lineLength
= length
- lineStart
;
164 printf("%03x %3d:", lineStart
, lineStart
);
165 for (i
= 0; i
< lineLength
; i
++)
166 printf(" %02x", bufferPtr
[lineStart
+ i
] & 0xFF);
167 for (; i
< kLineSize
; i
++)
170 for (i
= 0; i
< lineLength
; i
++) {
171 c
= bufferPtr
[lineStart
+ i
] & 0xFF;
172 if (c
> ' ' && c
< '~')