xref: /titanic_51/usr/src/lib/libbsm/common/adrm.c (revision 672986541be54a7a471bb088e60780c37e371d7e)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #pragma ident	"%Z%%M%	%I%	%E% SMI"
27 
28 /*
29  * Adr memory based translations
30  */
31 
32 #include <stdio.h>
33 #include <sys/types.h>
34 #include <bsm/audit.h>
35 #include <bsm/audit_record.h>
36 
37 void
38 adrm_start(adr_t *adr, char *p)
39 {
40 	adr->adr_stream = p;
41 	adr->adr_now = p;
42 }
43 
44 /*
45  * adrm_char - pull out characters
46  */
47 void
48 adrm_char(adr_t *adr, char *cp, int count)
49 {
50 	while (count-- > 0)
51 		*cp++ = *adr->adr_now++;
52 }
53 
54 /*
55  * adrm_short - pull out shorts
56  */
57 void
58 adrm_short(adr_t *adr, short *sp, int count)
59 {
60 	while (count-- > 0) {
61 		*sp = *adr->adr_now++ << 8;
62 		*sp++ += ((short)*adr->adr_now++) & 0x00ff;
63 	}
64 }
65 
66 /*
67  * adrm_int32 - pull out int
68  */
69 void adrm_int(adr_t *adr, int32_t *lp, int count);
70 void adrm_long(adr_t *adr, int32_t *lp, int count);
71 #pragma weak adrm_int = adrm_int32
72 #pragma weak adrm_long = adrm_int32
73 
74 void
75 adrm_int32(adr_t *adr, int32_t *lp, int count)
76 {
77 	int i;
78 
79 	for (; count-- > 0; lp++) {
80 		*lp = 0;
81 		for (i = 0; i < 4; i++) {
82 			*lp <<= 8;
83 			*lp += ((int32_t)*adr->adr_now++) & 0x000000ff;
84 		}
85 	}
86 }
87 
88 void
89 adrm_int64(adr_t *adr, int64_t *lp, int count)
90 {
91 	int i;
92 
93 	for (; count-- > 0; lp++) {
94 		*lp = 0;
95 		for (i = 0; i < 8; i++) {
96 			*lp <<= 8;
97 			*lp += ((int64_t)*adr->adr_now++) & 0x00000000000000ff;
98 		}
99 	}
100 }
101 
102 void adrm_u_int(adr_t *adr, uint32_t *cp, int count);
103 void adrm_u_long(adr_t *adr, uint32_t *cp, int count);
104 #pragma weak adrm_u_int = adrm_u_int32
105 #pragma weak adrm_u_long = adrm_u_int32
106 
107 void
108 adrm_u_int32(adr_t *adr, uint32_t *cp, int count)
109 {
110 	adrm_int32(adr, (int32_t *)cp, count);
111 }
112 
113 void
114 adrm_u_char(adr_t *adr, uchar_t *cp, int count)
115 {
116 	adrm_char(adr, (char *)cp, count);
117 }
118 
119 void
120 adrm_u_int64(adr_t *adr, uint64_t *lp, int count)
121 {
122 	adrm_int64(adr, (int64_t *)lp, count);
123 }
124 
125 void
126 adrm_u_short(adr_t *adr, ushort_t *sp, int count)
127 {
128 	adrm_short(adr, (short *)sp, count);
129 }
130 
131 /*
132  * adrm_putint32 - pack in int32
133  */
134 #pragma weak adrm_putint = adrm_putint32
135 #pragma weak adrm_putlong = adrm_putint32
136 void
137 adrm_putint32(adr_t *adr, int32_t *lp, int count)
138 {
139 	int i;		/* index for counting */
140 	int32_t l;	/* value for shifting */
141 
142 	for (; count-- > 0; lp++) {
143 		for (i = 0, l = *lp; i < 4; i++) {
144 			*adr->adr_now++ = (char)((l & (int32_t)0xff000000) >>
145 				(int)24);
146 			l <<= (int)8;
147 		}
148 	}
149 }
150