1a23fd118Syl /*
2a23fd118Syl  * CDDL HEADER START
3a23fd118Syl  *
4a23fd118Syl  * The contents of this file are subject to the terms of the
5a23fd118Syl  * Common Development and Distribution License (the "License").
6a23fd118Syl  * You may not use this file except in compliance with the License.
7a23fd118Syl  *
8a23fd118Syl  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9a23fd118Syl  * or http://www.opensolaris.org/os/licensing.
10a23fd118Syl  * See the License for the specific language governing permissions
11a23fd118Syl  * and limitations under the License.
12a23fd118Syl  *
13a23fd118Syl  * When distributing Covered Code, include this CDDL HEADER in each
14a23fd118Syl  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15a23fd118Syl  * If applicable, add the following below this CDDL HEADER, with the
16a23fd118Syl  * fields enclosed by brackets "[]" replaced with your own identifying
17a23fd118Syl  * information: Portions Copyright [yyyy] [name of copyright owner]
18a23fd118Syl  *
19a23fd118Syl  * CDDL HEADER END
20a23fd118Syl  *
218347601bSyl  * Copyright (c) 2002-2006 Neterion, Inc.
22a23fd118Syl  */
23a23fd118Syl 
24a23fd118Syl #ifndef XGE_OS_PAL_H
25a23fd118Syl #define XGE_OS_PAL_H
26a23fd118Syl 
27a23fd118Syl #include "xge-defs.h"
28a23fd118Syl 
298347601bSyl __EXTERN_BEGIN_DECLS
308347601bSyl 
31a23fd118Syl /*--------------------------- platform switch ------------------------------*/
32a23fd118Syl 
33a23fd118Syl /* platform specific header */
34a23fd118Syl #include "xge_osdep.h"
35a23fd118Syl 
36a23fd118Syl #if !defined(XGE_OS_PLATFORM_64BIT) && !defined(XGE_OS_PLATFORM_32BIT)
37a23fd118Syl #error "either 32bit or 64bit switch must be defined!"
38a23fd118Syl #endif
39a23fd118Syl 
40a23fd118Syl #if !defined(XGE_OS_HOST_BIG_ENDIAN) && !defined(XGE_OS_HOST_LITTLE_ENDIAN)
41a23fd118Syl #error "either little endian or big endian switch must be defined!"
42a23fd118Syl #endif
43a23fd118Syl 
44a23fd118Syl #if defined(XGE_OS_PLATFORM_64BIT)
45a23fd118Syl #define XGE_OS_MEMORY_DEADCODE_PAT	0x5a5a5a5a5a5a5a5a
46a23fd118Syl #else
47a23fd118Syl #define XGE_OS_MEMORY_DEADCODE_PAT	0x5a5a5a5a
48a23fd118Syl #endif
49a23fd118Syl 
50a23fd118Syl #define XGE_OS_TRACE_MSGBUF_MAX		512
51a23fd118Syl typedef struct xge_os_tracebuf_t {
527eced415Sxw 	int		wrapped_once;     /* circular buffer been wrapped */
537eced415Sxw 	int		timestamp;        /* whether timestamps are enabled */
547eced415Sxw 	volatile int	offset;           /* offset within the tracebuf */
557eced415Sxw 	int		size;             /* total size of trace buffer */
567eced415Sxw 	char		msg[XGE_OS_TRACE_MSGBUF_MAX]; /* each individual buffer */
577eced415Sxw 	int		msgbuf_max;	  /* actual size of msg buffer */
587eced415Sxw 	char		*data;            /* pointer to data buffer */
59a23fd118Syl } xge_os_tracebuf_t;
60a23fd118Syl extern xge_os_tracebuf_t *g_xge_os_tracebuf;
61a23fd118Syl 
62a23fd118Syl #ifdef XGE_TRACE_INTO_CIRCULAR_ARR
63a23fd118Syl extern xge_os_tracebuf_t *g_xge_os_tracebuf;
64a23fd118Syl extern char *dmesg_start;
65a23fd118Syl 
66*55fea89dSDan Cross /* Calculate the size of the msg and copy it into the global buffer */
67a23fd118Syl #define __xge_trace(tb) { \
687eced415Sxw 	int msgsize = xge_os_strlen(tb->msg) + 2; \
69a23fd118Syl 	int offset = tb->offset; \
707eced415Sxw 	if (msgsize != 2 && msgsize < tb->msgbuf_max) { \
71a23fd118Syl 		int leftsize =  tb->size - offset; \
727eced415Sxw 		if ((msgsize + tb->msgbuf_max) > leftsize) { \
73a23fd118Syl 			xge_os_memzero(tb->data + offset, leftsize); \
74a23fd118Syl 			offset = 0; \
75a23fd118Syl 			tb->wrapped_once = 1; \
76a23fd118Syl 		} \
777eced415Sxw 		xge_os_memcpy(tb->data + offset, tb->msg, msgsize-1); \
787eced415Sxw 		*(tb->data + offset + msgsize-1) = '\n'; \
797eced415Sxw 		*(tb->data + offset + msgsize) = 0; \
80a23fd118Syl 		offset += msgsize; \
81a23fd118Syl 		tb->offset = offset; \
82a23fd118Syl 		dmesg_start = tb->data + offset; \
83a23fd118Syl 		*tb->msg = 0; \
84a23fd118Syl 	} \
85a23fd118Syl }
86a23fd118Syl 
87a23fd118Syl #define xge_os_vatrace(tb, fmt) { \
88a23fd118Syl 	if (tb != NULL) { \
89a23fd118Syl 		char *_p = tb->msg; \
90a23fd118Syl 		if (tb->timestamp) { \
91a23fd118Syl 			xge_os_timestamp(tb->msg); \
92a23fd118Syl 			_p = tb->msg + xge_os_strlen(tb->msg); \
93a23fd118Syl 		} \
94a23fd118Syl 		xge_os_vasprintf(_p, fmt); \
95a23fd118Syl 		__xge_trace(tb); \
96a23fd118Syl 	} \
97a23fd118Syl }
98a23fd118Syl 
99a23fd118Syl #ifdef __GNUC__
100a23fd118Syl #define xge_os_trace(tb, fmt...) { \
1017eced415Sxw 	int msgsize = xge_os_strlen(tb->msg); \
102a23fd118Syl 	if (tb != NULL) { \
103a23fd118Syl 		if (tb->timestamp) { \
104a23fd118Syl 			xge_os_timestamp(tb->msg); \
105a23fd118Syl 		} \
1067eced415Sxw 		xge_os_snprintf(tb->msg + msgsize, \
1077eced415Sxw 		    (sizeof(tb->msg) - msgsize)), \
1087eced415Sxw 		    fmt); \
109a23fd118Syl 		__xge_trace(tb); \
110a23fd118Syl 	} \
111a23fd118Syl }
112a23fd118Syl #endif /* __GNUC__ */
113a23fd118Syl 
114a23fd118Syl #else
115a23fd118Syl #define xge_os_vatrace(tb, fmt)
116a23fd118Syl #ifdef __GNUC__
117a23fd118Syl #define xge_os_trace(tb, fmt...)
118a23fd118Syl #endif /* __GNUC__ */
119a23fd118Syl #endif
120a23fd118Syl 
1218347601bSyl __EXTERN_END_DECLS
1228347601bSyl 
123a23fd118Syl #endif /* XGE_OS_PAL_H */
124