8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / uts / common / c2 / adr.c
blob25973e09f39dfbfc9fff8dab068e4f08c81b6903
1 /*
2 * CDDL HEADER START
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.
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.
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]
19 * CDDL HEADER END
22 * Copyright (c) 1992, 2010, Oracle and/or its affiliates. All rights reserved.
26 * Adr memory based encoding
29 #include <sys/feature_tests.h>
31 #pragma weak adr_ushort = adr_short
32 #pragma weak adr_uint32 = adr_int32
33 #pragma weak adr_uint64 = adr_int64
34 #pragma weak adr_getushort = adr_getshort
35 #pragma weak adr_getuint32 = adr_getint32
36 #pragma weak adr_getuint64 = adr_getint64
38 #include <sys/types.h>
39 #include <sys/t_lock.h>
40 #include <sys/systm.h>
41 #include <sys/mutex.h>
42 #include <sys/thread.h>
43 #include <c2/audit.h>
44 #include <c2/audit_kernel.h>
45 #include <c2/audit_record.h>
47 void
48 adr_start(adr_t *adr, char *p)
50 adr->adr_stream = p;
51 adr->adr_now = p;
54 int
55 adr_count(adr_t *adr)
57 return ((int)((uintptr_t)adr->adr_now - (uintptr_t)adr->adr_stream));
62 * adr_char - pull out characters
64 void
65 adr_char(adr_t *adr, char *cp, int count)
67 while (count-- > 0)
68 *adr->adr_now++ = *cp++;
72 * adr_short - pull out shorts
74 void
75 adr_short(adr_t *adr, short *sp, int count)
78 for (; count-- > 0; sp++) {
79 *adr->adr_now++ = (char)((*sp >> (int)8) & 0x00ff);
80 *adr->adr_now++ = (char)(*sp & 0x00ff);
85 * adr_int32 - pull out int32
87 void
88 adr_int32(adr_t *adr, int32_t *lp, int count)
90 int i; /* index for counting */
91 int32_t l; /* value for shifting */
93 for (; count-- > 0; lp++) {
94 for (i = 0, l = *lp; i < 4; i++) {
95 *adr->adr_now++ = (char)((l & (int32_t)0xff000000) >>
96 (int)24);
97 l <<= (int)8;
103 * adr_int64 - pull out int64
105 void
106 adr_int64(adr_t *adr, int64_t *lp, int count)
108 int i; /* index for counting */
109 int64_t l; /* value for shifting */
111 for (; count-- > 0; lp++) {
112 for (i = 0, l = *lp; i < 8; i++) {
113 *adr->adr_now++ =
114 (char)((l & (int64_t)0xff00000000000000) >>
115 (int)56);
116 l <<= (int)8;
122 char *
123 adr_getchar(adr_t *adr, char *cp)
125 char *old;
127 old = adr->adr_now;
128 *cp = *adr->adr_now++;
129 return (old);
132 char *
133 adr_getshort(adr_t *adr, short *sp)
135 char *old;
137 old = adr->adr_now;
138 *sp = *adr->adr_now++;
139 *sp >>= (int)8;
140 *sp = *adr->adr_now++;
141 *sp >>= (int)8;
142 return (old);
145 char *
146 adr_getint32(adr_t *adr, int32_t *lp)
148 char *old;
149 int i;
151 old = adr->adr_now;
152 for (i = 0; i < 4; i++) {
153 *lp <<= 8;
154 *lp += ((int32_t)*adr->adr_now++) & 0x000000ff;
157 return (old);
160 char *
161 adr_getint64(adr_t *adr, int64_t *lp)
163 char *old;
164 int i;
166 old = adr->adr_now;
167 for (i = 0; i < 8; i++) {
168 *lp <<= 8;
169 *lp += ((int64_t)*adr->adr_now++) & 0x00000000000000ff;
171 return (old);