1171095Ssam/*- 2171095Ssam * Copyright (c) 2002-2007 Neterion, Inc. 3171095Ssam * All rights reserved. 4171095Ssam * 5171095Ssam * Redistribution and use in source and binary forms, with or without 6171095Ssam * modification, are permitted provided that the following conditions 7171095Ssam * are met: 8171095Ssam * 1. Redistributions of source code must retain the above copyright 9171095Ssam * notice, this list of conditions and the following disclaimer. 10171095Ssam * 2. Redistributions in binary form must reproduce the above copyright 11171095Ssam * notice, this list of conditions and the following disclaimer in the 12171095Ssam * documentation and/or other materials provided with the distribution. 13171095Ssam * 14171095Ssam * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15171095Ssam * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16171095Ssam * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17171095Ssam * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18171095Ssam * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19171095Ssam * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20171095Ssam * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21171095Ssam * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22171095Ssam * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23171095Ssam * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24171095Ssam * SUCH DAMAGE. 25171095Ssam * 26171095Ssam * $FreeBSD$ 27171095Ssam */ 28171095Ssam 29171095Ssam#ifndef XGE_OS_PAL_H 30171095Ssam#define XGE_OS_PAL_H 31171095Ssam 32171095Ssam#include <dev/nxge/include/xge-defs.h> 33171095Ssam 34171095Ssam__EXTERN_BEGIN_DECLS 35171095Ssam 36171095Ssam/*--------------------------- platform switch ------------------------------*/ 37171095Ssam 38171095Ssam/* platform specific header */ 39171095Ssam#include <dev/nxge/xge-osdep.h> 40171095Ssam 41171095Ssam#if !defined(XGE_OS_PLATFORM_64BIT) && !defined(XGE_OS_PLATFORM_32BIT) 42171095Ssam#error "either 32bit or 64bit switch must be defined!" 43171095Ssam#endif 44171095Ssam 45171095Ssam#if !defined(XGE_OS_HOST_BIG_ENDIAN) && !defined(XGE_OS_HOST_LITTLE_ENDIAN) 46171095Ssam#error "either little endian or big endian switch must be defined!" 47171095Ssam#endif 48171095Ssam 49171095Ssam#if defined(XGE_OS_PLATFORM_64BIT) 50173139Srwatson#define XGE_OS_MEMORY_DEADCODE_PAT 0x5a5a5a5a5a5a5a5a 51171095Ssam#else 52173139Srwatson#define XGE_OS_MEMORY_DEADCODE_PAT 0x5a5a5a5a 53171095Ssam#endif 54171095Ssam 55173139Srwatson#define XGE_OS_TRACE_MSGBUF_MAX 512 56171095Ssamtypedef struct xge_os_tracebuf_t { 57173139Srwatson int wrapped_once; /* circular buffer been wrapped */ 58173139Srwatson int timestamp; /* whether timestamps are enabled */ 59173139Srwatson volatile int offset; /* offset within the tracebuf */ 60173139Srwatson int size; /* total size of trace buffer */ 61173139Srwatson char msg[XGE_OS_TRACE_MSGBUF_MAX]; /* each individual buffer */ 62173139Srwatson int msgbuf_max; /* actual size of msg buffer */ 63173139Srwatson char *data; /* pointer to data buffer */ 64171095Ssam} xge_os_tracebuf_t; 65171095Ssamextern xge_os_tracebuf_t *g_xge_os_tracebuf; 66171095Ssam 67171095Ssam#ifdef XGE_TRACE_INTO_CIRCULAR_ARR 68171095Ssamextern xge_os_tracebuf_t *g_xge_os_tracebuf; 69171095Ssamextern char *dmesg_start; 70171095Ssam 71171095Ssam/* Calculate the size of the msg and copy it into the global buffer */ 72171095Ssam#define __xge_trace(tb) { \ 73171095Ssam int msgsize = xge_os_strlen(tb->msg) + 2; \ 74171095Ssam int offset = tb->offset; \ 75171095Ssam if (msgsize != 2 && msgsize < tb->msgbuf_max) { \ 76173139Srwatson int leftsize = tb->size - offset; \ 77173139Srwatson if ((msgsize + tb->msgbuf_max) > leftsize) { \ 78173139Srwatson xge_os_memzero(tb->data + offset, leftsize); \ 79173139Srwatson offset = 0; \ 80173139Srwatson tb->wrapped_once = 1; \ 81173139Srwatson } \ 82173139Srwatson xge_os_memcpy(tb->data + offset, tb->msg, msgsize-1); \ 83173139Srwatson *(tb->data + offset + msgsize-1) = '\n'; \ 84173139Srwatson *(tb->data + offset + msgsize) = 0; \ 85173139Srwatson offset += msgsize; \ 86173139Srwatson tb->offset = offset; \ 87173139Srwatson dmesg_start = tb->data + offset; \ 88173139Srwatson *tb->msg = 0; \ 89171095Ssam } \ 90171095Ssam} 91171095Ssam 92171095Ssam#define xge_os_vatrace(tb, fmt) { \ 93171095Ssam if (tb != NULL) { \ 94173139Srwatson char *_p = tb->msg; \ 95173139Srwatson if (tb->timestamp) { \ 96173139Srwatson xge_os_timestamp(tb->msg); \ 97173139Srwatson _p = tb->msg + xge_os_strlen(tb->msg); \ 98173139Srwatson } \ 99173139Srwatson xge_os_vasprintf(_p, fmt); \ 100173139Srwatson __xge_trace(tb); \ 101171095Ssam } \ 102171095Ssam} 103171095Ssam 104171095Ssam#ifdef __GNUC__ 105171095Ssam#define xge_os_trace(tb, fmt...) { \ 106171095Ssam if (tb != NULL) { \ 107173139Srwatson if (tb->timestamp) { \ 108173139Srwatson xge_os_timestamp(tb->msg); \ 109173139Srwatson } \ 110173139Srwatson xge_os_sprintf(tb->msg + xge_os_strlen(tb->msg), fmt); \ 111173139Srwatson __xge_trace(tb); \ 112171095Ssam } \ 113171095Ssam} 114171095Ssam#endif /* __GNUC__ */ 115171095Ssam 116171095Ssam#else 117171095Ssam#define xge_os_vatrace(tb, fmt) 118171095Ssam#ifdef __GNUC__ 119171095Ssam#define xge_os_trace(tb, fmt...) 120171095Ssam#endif /* __GNUC__ */ 121171095Ssam#endif 122171095Ssam 123171095Ssam__EXTERN_END_DECLS 124171095Ssam 125171095Ssam#endif /* XGE_OS_PAL_H */ 126