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