| 1 | /* |
|---|
| 2 | * printk.h - Kernel Log & debug messages API definition. |
|---|
| 3 | * |
|---|
| 4 | * authors Alain Greiner (2016) |
|---|
| 5 | * |
|---|
| 6 | * Copyright (c) UPMC Sorbonne Universites |
|---|
| 7 | * |
|---|
| 8 | * This file is part of ALMOS-MKH. |
|---|
| 9 | * |
|---|
| 10 | * ALMOS-MKH is free software; you can redistribute it and/or modify it |
|---|
| 11 | * under the terms of the GNU General Public License as published by |
|---|
| 12 | * the Free Software Foundation; version 2.0 of the License. |
|---|
| 13 | * |
|---|
| 14 | * ALMOS-MKH is distributed in the hope that it will be useful, but |
|---|
| 15 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|---|
| 17 | * General Public License for more details. |
|---|
| 18 | * |
|---|
| 19 | * You should have received a copy of the GNU General Public License |
|---|
| 20 | * along with ALMOS-MKH; if not, write to the Free Software Foundation, |
|---|
| 21 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
|---|
| 22 | */ |
|---|
| 23 | |
|---|
| 24 | /////////////////////////////////////////////////////////////////////////////////// |
|---|
| 25 | // The printk.c and printk.h files define the functions used by the kernel |
|---|
| 26 | // to display messages on a text terminal. |
|---|
| 27 | // Two access modes are supported: |
|---|
| 28 | // - The printk() function displays kernel messages on the kernel terminal TXT0, |
|---|
| 29 | // using a busy waiting policy: It calls directly the relevant TXT driver, |
|---|
| 30 | // after taking the TXT0 chdev lock for exclusive access to the TXT0 terminal. |
|---|
| 31 | // - The user_printk() function displays messages on the calling thread private |
|---|
| 32 | // terminal, using a descheduling policy: it register the request in the selected |
|---|
| 33 | // TXT chdev waiting queue and deschedule. The calling thread is reactivated by |
|---|
| 34 | // the IRQ signaling completion. |
|---|
| 35 | // Both functions use the generic TXT device to call the proper implementation |
|---|
| 36 | // dependant TXT driver. |
|---|
| 37 | // Finally these files define a set of conditionnal trace <***_dmsg> for debug. |
|---|
| 38 | /////////////////////////////////////////////////////////////////////////////////// |
|---|
| 39 | |
|---|
| 40 | #ifndef _PRINTK_H |
|---|
| 41 | #define _PRINTK_H |
|---|
| 42 | |
|---|
| 43 | #include <hal_types.h> |
|---|
| 44 | #include <stdarg.h> |
|---|
| 45 | |
|---|
| 46 | |
|---|
| 47 | /********************************************************************************** |
|---|
| 48 | * This function build a formated string. |
|---|
| 49 | * The supported formats are defined below : |
|---|
| 50 | * %c : single character |
|---|
| 51 | * %d : signed decimal 32 bits integer |
|---|
| 52 | * %u : unsigned decimal 32 bits integer |
|---|
| 53 | * %x : hexadecimal 32 bits integer |
|---|
| 54 | * %l : hexadecimal 64 bits integer |
|---|
| 55 | * %s : NUL terminated character string |
|---|
| 56 | ********************************************************************************** |
|---|
| 57 | * @ string : pointer on target buffer (allocated by caller). |
|---|
| 58 | * @ length : target buffer length (number of bytes). |
|---|
| 59 | * @ format : format respecting the printf syntax. |
|---|
| 60 | * @ returns the string length (including NUL) if success / return -1 if error. |
|---|
| 61 | *********************************************************************************/ |
|---|
| 62 | uint32_t snprintf( char * string, |
|---|
| 63 | uint32_t length, |
|---|
| 64 | char * format, ... ); |
|---|
| 65 | |
|---|
| 66 | /********************************************************************************** |
|---|
| 67 | * This function displays a formated string on the kernel terminal TXT0, |
|---|
| 68 | * using a busy waiting policy: It calls directly the relevant TXT driver, |
|---|
| 69 | * after taking the TXT0 chdev lock for exclusive access to the TXT0 terminal. |
|---|
| 70 | ********************************************************************************** |
|---|
| 71 | * @ format : formated string. |
|---|
| 72 | *********************************************************************************/ |
|---|
| 73 | void printk( char* format, ... ); |
|---|
| 74 | |
|---|
| 75 | /********************************************************************************** |
|---|
| 76 | * Display a formated string on the calling thread private terminal, using a |
|---|
| 77 | * descheduling policy: it register the request in the selected TXT chdev waiting |
|---|
| 78 | * queue and deschedule. IT is reactivated by the IRQ signaling completion. |
|---|
| 79 | * Not fully implemented yet ( use TXT0 in deschedling mode ). |
|---|
| 80 | ********************************************************************************** |
|---|
| 81 | * @ format : formated string. |
|---|
| 82 | *********************************************************************************/ |
|---|
| 83 | void user_printk( char* format, ... ); |
|---|
| 84 | |
|---|
| 85 | /********************************************************************************** |
|---|
| 86 | * This function displaya "PANIC" message and force the calling core in |
|---|
| 87 | * sleeping mode if a Boolean condition is false. |
|---|
| 88 | * These functions are actually used to debug the kernel... |
|---|
| 89 | ********************************************************************************** |
|---|
| 90 | * @ condition : condition that must be true. |
|---|
| 91 | * @ function_name : name of the calling function. |
|---|
| 92 | * @ string : error message if condition is false. |
|---|
| 93 | *********************************************************************************/ |
|---|
| 94 | inline void assert( bool_t condition, |
|---|
| 95 | const char * function_name, |
|---|
| 96 | char * string ); |
|---|
| 97 | |
|---|
| 98 | /////////////////////////////////////////////////////////////////////////////////// |
|---|
| 99 | // Conditionnal debug macros |
|---|
| 100 | /////////////////////////////////////////////////////////////////////////////////// |
|---|
| 101 | |
|---|
| 102 | #if CONFIG_CONTEXT_DEBUG |
|---|
| 103 | #define context_dmsg(...) printk(__VA_ARGS__) |
|---|
| 104 | #else |
|---|
| 105 | #define context_dmsg(...) |
|---|
| 106 | #endif |
|---|
| 107 | |
|---|
| 108 | #if CONFIG_CORE_DEBUG |
|---|
| 109 | #define core_dmsg(...) printk(__VA_ARGS__) |
|---|
| 110 | #else |
|---|
| 111 | #define core_dmsg(...) |
|---|
| 112 | #endif |
|---|
| 113 | |
|---|
| 114 | #if CONFIG_DQDT_DEBUG |
|---|
| 115 | #define dma_dmsg(...) printk(__VA_ARGS__) |
|---|
| 116 | #else |
|---|
| 117 | #define dma_dmsg(...) |
|---|
| 118 | #endif |
|---|
| 119 | |
|---|
| 120 | #if CONFIG_DQDT_DEBUG |
|---|
| 121 | #define dqdt_dmsg(...) printk(__VA_ARGS__) |
|---|
| 122 | #else |
|---|
| 123 | #define dqdt_dmsg(...) |
|---|
| 124 | #endif |
|---|
| 125 | |
|---|
| 126 | #if CONFIG_ELF_DEBUG |
|---|
| 127 | #define elf_dmsg(...) printk(__VA_ARGS__) |
|---|
| 128 | #else |
|---|
| 129 | #define elf_dmsg(...) |
|---|
| 130 | #endif |
|---|
| 131 | |
|---|
| 132 | #if CONFIG_EXEC_DEBUG |
|---|
| 133 | #define exec_dmsg(...) printk(__VA_ARGS__) |
|---|
| 134 | #else |
|---|
| 135 | #define exec_dmsg(...) |
|---|
| 136 | #endif |
|---|
| 137 | |
|---|
| 138 | #if CONFIG_FBF_DEBUG |
|---|
| 139 | #define fbf_dmsg(...) printk(__VA_ARGS__) |
|---|
| 140 | #else |
|---|
| 141 | #define fbf_dmsg(...) |
|---|
| 142 | #endif |
|---|
| 143 | |
|---|
| 144 | #if CONFIG_FORK_DEBUG |
|---|
| 145 | #define fork_dmsg(...) printk(__VA_ARGS__) |
|---|
| 146 | #else |
|---|
| 147 | #define fork_dmsg(...) |
|---|
| 148 | #endif |
|---|
| 149 | |
|---|
| 150 | #if CONFIG_ICU_DEBUG |
|---|
| 151 | #define icu_dmsg(...) printk(__VA_ARGS__) |
|---|
| 152 | #else |
|---|
| 153 | #define icu_dmsg(...) |
|---|
| 154 | #endif |
|---|
| 155 | |
|---|
| 156 | #if CONFIG_IOC_DEBUG |
|---|
| 157 | #define ioc_dmsg(...) printk(__VA_ARGS__) |
|---|
| 158 | #else |
|---|
| 159 | #define ioc_dmsg(...) |
|---|
| 160 | #endif |
|---|
| 161 | |
|---|
| 162 | #if CONFIG_KCM_DEBUG |
|---|
| 163 | #define kcm_dmsg(...) printk(__VA_ARGS__) |
|---|
| 164 | #else |
|---|
| 165 | #define kcm_dmsg(...) |
|---|
| 166 | #endif |
|---|
| 167 | |
|---|
| 168 | #if CONFIG_KHM_DEBUG |
|---|
| 169 | #define khm_dmsg(...) printk(__VA_ARGS__) |
|---|
| 170 | #else |
|---|
| 171 | #define khm_dmsg(...) |
|---|
| 172 | #endif |
|---|
| 173 | |
|---|
| 174 | #if CONFIG_KINIT_DEBUG |
|---|
| 175 | #define kinit_dmsg(...) printk(__VA_ARGS__) |
|---|
| 176 | #else |
|---|
| 177 | #define kinit_dmsg(...) |
|---|
| 178 | #endif |
|---|
| 179 | |
|---|
| 180 | #if CONFIG_KMEM_DEBUG |
|---|
| 181 | #define kmem_dmsg(...) printk(__VA_ARGS__) |
|---|
| 182 | #else |
|---|
| 183 | #define kmem_dmsg(...) |
|---|
| 184 | #endif |
|---|
| 185 | |
|---|
| 186 | #if CONFIG_MAPPER_DEBUG |
|---|
| 187 | #define mapper_dmsg(...) printk(__VA_ARGS__) |
|---|
| 188 | #else |
|---|
| 189 | #define mapper_dmsg(...) |
|---|
| 190 | #endif |
|---|
| 191 | |
|---|
| 192 | #if CONFIG_MMC_DEBUG |
|---|
| 193 | #define mmc_dmsg(...) printk(__VA_ARGS__) |
|---|
| 194 | #else |
|---|
| 195 | #define mmc_dmsg(...) |
|---|
| 196 | #endif |
|---|
| 197 | |
|---|
| 198 | #if CONFIG_NIC_DEBUG |
|---|
| 199 | #define nic_dmsg(...) printk(__VA_ARGS__) |
|---|
| 200 | #else |
|---|
| 201 | #define nic_dmsg(...) |
|---|
| 202 | #endif |
|---|
| 203 | |
|---|
| 204 | #if CONFIG_PIC_DEBUG |
|---|
| 205 | #define pic_dmsg(...) printk(__VA_ARGS__) |
|---|
| 206 | #else |
|---|
| 207 | #define pic_dmsg(...) |
|---|
| 208 | #endif |
|---|
| 209 | |
|---|
| 210 | #if CONFIG_PPM_DEBUG |
|---|
| 211 | #define ppm_dmsg(...) printk(__VA_ARGS__) |
|---|
| 212 | #else |
|---|
| 213 | #define ppm_dmsg(...) |
|---|
| 214 | #endif |
|---|
| 215 | |
|---|
| 216 | #if CONFIG_PROCESS_DEBUG |
|---|
| 217 | #define process_dmsg(...) printk(__VA_ARGS__) |
|---|
| 218 | #else |
|---|
| 219 | #define process_dmsg(...) |
|---|
| 220 | #endif |
|---|
| 221 | |
|---|
| 222 | #if CONFIG_RPC_DEBUG |
|---|
| 223 | #define rpc_dmsg(...) printk(__VA_ARGS__) |
|---|
| 224 | #else |
|---|
| 225 | #define rpc_dmsg(...) |
|---|
| 226 | #endif |
|---|
| 227 | |
|---|
| 228 | #if CONFIG_SCHED_DEBUG |
|---|
| 229 | #define sched_dmsg(...) printk(__VA_ARGS__) |
|---|
| 230 | #else |
|---|
| 231 | #define sched_dmsg(...) |
|---|
| 232 | #endif |
|---|
| 233 | |
|---|
| 234 | #if CONFIG_SIGNAL_DEBUG |
|---|
| 235 | #define signal_dmsg(...) printk(__VA_ARGS__) |
|---|
| 236 | #else |
|---|
| 237 | #define signal_dmsg(...) |
|---|
| 238 | #endif |
|---|
| 239 | |
|---|
| 240 | #if CONFIG_SYSCALL_DEBUG |
|---|
| 241 | #define syscall_dmsg(...) printk(__VA_ARGS__) |
|---|
| 242 | #else |
|---|
| 243 | #define syscall_dmsg(...) |
|---|
| 244 | #endif |
|---|
| 245 | |
|---|
| 246 | #if CONFIG_THREAD_DEBUG |
|---|
| 247 | #define thread_dmsg(...) printk(__VA_ARGS__) |
|---|
| 248 | #else |
|---|
| 249 | #define thread_dmsg(...) |
|---|
| 250 | #endif |
|---|
| 251 | |
|---|
| 252 | #if CONFIG_TXT_DEBUG |
|---|
| 253 | #define txt_dmsg(...) printk(__VA_ARGS__) |
|---|
| 254 | #else |
|---|
| 255 | #define txt_dmsg(...) |
|---|
| 256 | #endif |
|---|
| 257 | |
|---|
| 258 | #if CONFIG_VFS_DEBUG |
|---|
| 259 | #define vfs_dmsg(...) printk(__VA_ARGS__) |
|---|
| 260 | #else |
|---|
| 261 | #define vfs_dmsg(...) |
|---|
| 262 | #endif |
|---|
| 263 | |
|---|
| 264 | #if CONFIG_VMM_DEBUG |
|---|
| 265 | #define vmm_dmsg(...) printk(__VA_ARGS__) |
|---|
| 266 | #else |
|---|
| 267 | #define vmm_dmsg(...) |
|---|
| 268 | #endif |
|---|
| 269 | |
|---|
| 270 | |
|---|
| 271 | #endif // _PRINTK_H |
|---|
| 272 | |
|---|
| 273 | // Local Variables: |
|---|
| 274 | // tab-width: 4 |
|---|
| 275 | // c-basic-offset: 4 |
|---|
| 276 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
|---|
| 277 | // indent-tabs-mode: nil |
|---|
| 278 | // End: |
|---|
| 279 | // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
|---|
| 280 | |
|---|