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