xref: /illumos-gate/usr/src/uts/common/io/xge/hal/include/xge-os-pal.h (revision a07094369b21309434206d9b3601d162693466fc)
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 /*
23  *  Copyright (c) 2002-2005 Neterion, Inc.
24  *  All right Reserved.
25  *
26  *  FileName :    xge-os-pal.h
27  *
28  *  Description:  top-level header file. works just like switching between
29  *                os-depndent parts
30  *
31  *  Created:      6st May 2004
32  */
33 
34 #ifndef XGE_OS_PAL_H
35 #define XGE_OS_PAL_H
36 
37 #include "xge-defs.h"
38 
39 /*--------------------------- platform switch ------------------------------*/
40 
41 /* platform specific header */
42 #include "xge_osdep.h"
43 
44 #if !defined(XGE_OS_PLATFORM_64BIT) && !defined(XGE_OS_PLATFORM_32BIT)
45 #error "either 32bit or 64bit switch must be defined!"
46 #endif
47 
48 #if !defined(XGE_OS_HOST_BIG_ENDIAN) && !defined(XGE_OS_HOST_LITTLE_ENDIAN)
49 #error "either little endian or big endian switch must be defined!"
50 #endif
51 
52 #if defined(XGE_OS_PLATFORM_64BIT)
53 #define XGE_OS_MEMORY_DEADCODE_PAT	0x5a5a5a5a5a5a5a5a
54 #else
55 #define XGE_OS_MEMORY_DEADCODE_PAT	0x5a5a5a5a
56 #endif
57 
58 #define XGE_OS_TRACE_MSGBUF_MAX		512
59 typedef struct xge_os_tracebuf_t {
60 	int		wrapped_once;
61 	int		timestamp;
62 	volatile int	offset;
63 	int		size;
64 	char		msg[XGE_OS_TRACE_MSGBUF_MAX];
65 	char		*data;
66 } xge_os_tracebuf_t;
67 extern xge_os_tracebuf_t *g_xge_os_tracebuf;
68 
69 #ifdef XGE_TRACE_INTO_CIRCULAR_ARR
70 extern xge_os_tracebuf_t *g_xge_os_tracebuf;
71 extern char *dmesg_start;
72 
73 #define __xge_trace(tb) { \
74 	int msgsize = xge_os_strlen(tb->msg) + 1; \
75 	int offset = tb->offset; \
76 	if (msgsize != 1 && msgsize < XGE_OS_TRACE_MSGBUF_MAX) { \
77 		int leftsize =  tb->size - offset; \
78 		if ((msgsize + XGE_OS_TRACE_MSGBUF_MAX) > leftsize) { \
79 			xge_os_memzero(tb->data + offset, leftsize); \
80 			offset = 0; \
81 			tb->wrapped_once = 1; \
82 		} \
83 		xge_os_memcpy(tb->data + offset, tb->msg, msgsize); \
84 		offset += msgsize; \
85 		tb->offset = offset; \
86 		dmesg_start = tb->data + offset; \
87 		*tb->msg = 0; \
88 	} \
89 }
90 
91 #define xge_os_vatrace(tb, fmt) { \
92 	if (tb != NULL) { \
93 		char *_p = tb->msg; \
94 		if (tb->timestamp) { \
95 			xge_os_timestamp(tb->msg); \
96 			_p = tb->msg + xge_os_strlen(tb->msg); \
97 		} \
98 		xge_os_vasprintf(_p, fmt); \
99 		__xge_trace(tb); \
100 	} \
101 }
102 
103 #ifdef __GNUC__
104 #define xge_os_trace(tb, fmt...) { \
105 	if (tb != NULL) { \
106 		if (tb->timestamp) { \
107 			xge_os_timestamp(tb->msg); \
108 		} \
109 		xge_os_sprintf(tb->msg + xge_os_strlen(tb->msg), fmt); \
110 		__xge_trace(tb); \
111 	} \
112 }
113 #endif /* __GNUC__ */
114 
115 #else
116 #define xge_os_vatrace(tb, fmt)
117 #ifdef __GNUC__
118 #define xge_os_trace(tb, fmt...)
119 #endif /* __GNUC__ */
120 #endif
121 
122 #endif /* XGE_OS_PAL_H */
123