[444] | 1 | /* |
---|
| 2 | * Copyright (c) 2011 Aeroflex Gaisler |
---|
| 3 | * |
---|
| 4 | * BSD license: |
---|
| 5 | * |
---|
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
---|
| 7 | * of this software and associated documentation files (the "Software"), to deal |
---|
| 8 | * in the Software without restriction, including without limitation the rights |
---|
| 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
---|
| 10 | * copies of the Software, and to permit persons to whom the Software is |
---|
| 11 | * furnished to do so, subject to the following conditions: |
---|
| 12 | * |
---|
| 13 | * The above copyright notice and this permission notice shall be included in |
---|
| 14 | * all copies or substantial portions of the Software. |
---|
| 15 | * |
---|
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
---|
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
---|
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
---|
| 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
---|
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
---|
| 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
---|
| 22 | * THE SOFTWARE. |
---|
| 23 | */ |
---|
| 24 | |
---|
| 25 | |
---|
| 26 | #ifndef __LEONBARE_KERNEL_DEBUG_H__ |
---|
| 27 | #define __LEONBARE_KERNEL_DEBUG_H__ |
---|
| 28 | |
---|
| 29 | #include <asm-leon/leondbg.h> |
---|
| 30 | |
---|
| 31 | /* |
---|
| 32 | #define LBDEBUG_DO_DEBUG |
---|
| 33 | #define LBDEBUG_DO_ASSERT |
---|
| 34 | */ |
---|
| 35 | |
---|
| 36 | #define LBDEBUG_ALWAYS_NR (1<<0) |
---|
| 37 | #define LBDEBUG_ASSERT_NR (1<<1) |
---|
| 38 | #define LBDEBUG_FNCALL_NR (1<<2) |
---|
| 39 | #define LBDEBUG_FNEXIT_NR (1<<3) |
---|
| 40 | #define LBDEBUG_SCHED_NR (1<<4) |
---|
| 41 | #define LBDEBUG_QUEUE_NR (1<<5) |
---|
| 42 | #define LBDEBUG_THREAD_NR (1<<6) |
---|
| 43 | |
---|
| 44 | #define LBDEBUG_PRINTF dbgleon_printf /*leonbare_debug_printf */ |
---|
| 45 | |
---|
| 46 | #ifdef LBDEBUG_DO_DEBUG |
---|
| 47 | #ifndef __ASSEMBLER__ |
---|
| 48 | extern int leonbare_debug; |
---|
| 49 | #endif |
---|
| 50 | # define PDEBUG_FLAGS_CHECK(c) ((c)&leonbare_debug) |
---|
| 51 | # define PDEBUG_FLAGS_SET(c) leonbare_debug |= c |
---|
| 52 | #else |
---|
| 53 | # define PDEBUG_FLAGS_CHECK(c) 0 |
---|
| 54 | # define PDEBUG_FLAGS_SET(c) |
---|
| 55 | #endif |
---|
| 56 | |
---|
| 57 | #ifdef LBDEBUG_DO_DEBUG |
---|
| 58 | # define LBDEBUG(x, fmt, args...) do { if (PDEBUG_FLAGS_CHECK(x)) { LBDEBUG_PRINTF(fmt,args); } } while(0) |
---|
| 59 | #else |
---|
| 60 | # define LBDEBUG(x, fmt, args...) |
---|
| 61 | #endif |
---|
| 62 | |
---|
| 63 | #ifdef LBDEBUG_DO_ASSERT |
---|
| 64 | # define LBPASSERT(x, fmt, args...) if (!(x)) { LBDEBUG_PRINTF(fmt,args); while(1); } |
---|
| 65 | #else |
---|
| 66 | # define LBPASSERT(x, fmt, args...) |
---|
| 67 | #endif |
---|
| 68 | |
---|
| 69 | #ifndef LBDEBUG___FUNCTION__ |
---|
| 70 | #define LBDEBUG___FUNCTION__ __FUNCTION__ |
---|
| 71 | #endif |
---|
| 72 | |
---|
| 73 | #ifndef LBDEBUG___FUNCTION_WIDTH__ |
---|
| 74 | #define LBDEBUG___FUNCTION_WIDTH__ "28" |
---|
| 75 | #endif |
---|
| 76 | |
---|
| 77 | #ifdef LBDEBUG_DO_FILE |
---|
| 78 | #ifndef LBDEBUG___FILE__ |
---|
| 79 | #define LBDEBUG___FILE__ __FILE__ |
---|
| 80 | #endif |
---|
| 81 | #ifndef LBDEBUG___FILE_WIDTH__ |
---|
| 82 | #define LBDEBUG___FILE_WIDTH__ "28" |
---|
| 83 | #endif |
---|
| 84 | #define LBDEBUG___FILE_APPEND ,__FILE__ |
---|
| 85 | #define LBDEBUG___FILE_FMT_APPEND ":%" LBDEBUG___FILE_WIDTH__ "s" |
---|
| 86 | #else |
---|
| 87 | #define LBDEBUG___FILE_APPEND |
---|
| 88 | #define LBDEBUG___FILE_FMT_APPEND |
---|
| 89 | #endif |
---|
| 90 | |
---|
| 91 | #ifdef LBDEBUG_DO_DEBUG |
---|
| 92 | # define LBDEBUG_HEADER(code) \ |
---|
| 93 | if (PDEBUG_FLAGS_CHECK(code)) { \ |
---|
| 94 | register unsigned int _GETSP asm("sp"); \ |
---|
| 95 | LBDEBUG_PRINTF("[sp:%08x self(%08x):", _GETSP, LEONBARE_KR_CURRENT); \ |
---|
| 96 | LBDEBUG_PRINTF("%10s",LEONBARE_TH_NAME_DBG(LEONBARE_KR_CURRENT)); \ |
---|
| 97 | LBDEBUG_PRINTF(" %03d @ %" LBDEBUG___FUNCTION_WIDTH__ "s()" LBDEBUG___FILE_FMT_APPEND "]:" , __LINE__,LBDEBUG___FUNCTION__ LBDEBUG___FILE_APPEND); \ |
---|
| 98 | } |
---|
| 99 | |
---|
| 100 | # define LBDEBUG_HEADER_PRINTF(code,fmt,args...) \ |
---|
| 101 | if (PDEBUG_FLAGS_CHECK(code)) { \ |
---|
| 102 | LBDEBUG_HEADER(code); \ |
---|
| 103 | LBDEBUG_PRINTF(fmt,args); \ |
---|
| 104 | } |
---|
| 105 | |
---|
| 106 | # define LBDEBUG_CODE_PRINTF(code,fmt,args...) \ |
---|
| 107 | if (PDEBUG_FLAGS_CHECK(code)) { \ |
---|
| 108 | LBDEBUG_PRINTF(fmt,args); \ |
---|
| 109 | } |
---|
| 110 | #else |
---|
| 111 | # define LBDEBUG_HEADER(code) |
---|
| 112 | # define LBDEBUG_HEADER_PRINTF(code,fmt,args...) |
---|
| 113 | # define LBDEBUG_CODE_PRINTF(code,fmt,args...) |
---|
| 114 | #endif |
---|
| 115 | |
---|
| 116 | #define LBDEBUG_FNCALL LBDEBUG_HEADER_PRINTF(LBDEBUG_FNCALL_NR,"enter\n",0) |
---|
| 117 | #define LBDEBUG_FNEXIT LBDEBUG_HEADER_PRINTF(LBDEBUG_FNEXIT_NR,"exit\n",0) |
---|
| 118 | |
---|
| 119 | #ifndef __ASSEMBLER__ |
---|
| 120 | |
---|
| 121 | int leonbare_debug_printf (const char *fmt, ...); |
---|
| 122 | |
---|
| 123 | #endif |
---|
| 124 | |
---|
| 125 | #endif |
---|