[1] | 1 | /* |
---|
| 2 | * printk.h - Kernel Log & debug messages API definition. |
---|
[372] | 3 | * |
---|
[1] | 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 |
---|
[372] | 26 | // to display messages on a text terminal. |
---|
[5] | 27 | // Two access modes are supported: |
---|
| 28 | // - The printk() function displays kernel messages on the kernel terminal TXT0, |
---|
[372] | 29 | // using a busy waiting policy: It calls directly the relevant TXT driver, |
---|
[5] | 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 |
---|
[372] | 33 | // TXT chdev waiting queue and deschedule. The calling thread is reactivated by |
---|
| 34 | // the IRQ signalling completion. |
---|
[5] | 35 | // Both functions use the generic TXT device to call the proper implementation |
---|
[1] | 36 | // dependant TXT driver. |
---|
[372] | 37 | // Finally these files define a set of conditional trace <***_dmsg> for debug. |
---|
[1] | 38 | /////////////////////////////////////////////////////////////////////////////////// |
---|
| 39 | |
---|
| 40 | #ifndef _PRINTK_H |
---|
| 41 | #define _PRINTK_H |
---|
| 42 | |
---|
[5] | 43 | #include <hal_types.h> |
---|
| 44 | #include <stdarg.h> |
---|
[1] | 45 | |
---|
[5] | 46 | |
---|
| 47 | /********************************************************************************** |
---|
[372] | 48 | * This function build a formatted string. |
---|
[23] | 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 | /********************************************************************************** |
---|
[372] | 67 | * This function displays a formatted string on the kernel terminal TXT0, |
---|
| 68 | * using a busy waiting policy: It calls directly the relevant TXT driver, |
---|
[296] | 69 | * after taking the TXT0 lock. |
---|
[5] | 70 | ********************************************************************************** |
---|
[372] | 71 | * @ format : formatted string. |
---|
[5] | 72 | *********************************************************************************/ |
---|
[103] | 73 | void printk( char* format, ... ); |
---|
[1] | 74 | |
---|
[5] | 75 | /********************************************************************************** |
---|
[372] | 76 | * This function displays a formatted string on the kernel terminal TXT0, |
---|
| 77 | * using a busy waiting policy: It calls directly the relevant TXT driver, |
---|
[296] | 78 | * without taking the TXT0 lock. |
---|
| 79 | ********************************************************************************** |
---|
[372] | 80 | * @ format : formatted string. |
---|
[296] | 81 | *********************************************************************************/ |
---|
| 82 | void nolock_printk( char* format, ... ); |
---|
| 83 | |
---|
| 84 | /********************************************************************************** |
---|
[372] | 85 | * This function displays a message and forces the calling core in sleeping mode. |
---|
| 86 | ********************************************************************************** |
---|
| 87 | * @ format : formatted string |
---|
| 88 | *********************************************************************************/ |
---|
| 89 | void _panic( char* format, ... ); |
---|
| 90 | |
---|
| 91 | /********************************************************************************** |
---|
[408] | 92 | * This function displays a formated message on kernel TXT0 terminal, |
---|
| 93 | * and forces the calling core in sleeping mode if a Boolean condition is false. |
---|
| 94 | * This function is actually used to debug the kernel... |
---|
[5] | 95 | ********************************************************************************** |
---|
| 96 | * @ condition : condition that must be true. |
---|
| 97 | * @ function_name : name of the calling function. |
---|
[372] | 98 | * @ format : formatted string |
---|
[5] | 99 | *********************************************************************************/ |
---|
[337] | 100 | void assert( bool_t condition, |
---|
| 101 | const char * function_name, |
---|
| 102 | char * format , ... ); |
---|
[5] | 103 | |
---|
[408] | 104 | /********************************************************************************** |
---|
| 105 | * This function displays a non-formated message on kernel TXT0 terminal. |
---|
| 106 | * This function is actually used to debug the assembly level kernel functions. |
---|
| 107 | ********************************************************************************** |
---|
| 108 | * @ string : non-formatted string. |
---|
| 109 | *********************************************************************************/ |
---|
| 110 | void puts( char * string ); |
---|
| 111 | |
---|
| 112 | /********************************************************************************** |
---|
| 113 | * This function displays a 32 bits value in hexadecimal on kernel TXT0 terminal. |
---|
| 114 | * This function is actually used to debug the assembly level kernel functions. |
---|
| 115 | ********************************************************************************** |
---|
| 116 | * @ val : 32 bits unsigned value. |
---|
| 117 | *********************************************************************************/ |
---|
| 118 | void putx( uint32_t val ); |
---|
| 119 | |
---|
| 120 | /********************************************************************************** |
---|
| 121 | * This function displays a 64 bits value in hexadecimal on kernel TXT0 terminal. |
---|
| 122 | * This function is actually used to debug the assembly level kernel functions. |
---|
| 123 | ********************************************************************************** |
---|
| 124 | * @ val : 64 bits unsigned value. |
---|
| 125 | *********************************************************************************/ |
---|
| 126 | void putl( uint64_t val ); |
---|
| 127 | |
---|
| 128 | |
---|
[407] | 129 | #define panic(fmt, ...) _panic("\n[PANIC] %s(): " fmt "\n", __func__, ##__VA_ARGS__) |
---|
[372] | 130 | |
---|
[1] | 131 | /////////////////////////////////////////////////////////////////////////////////// |
---|
[372] | 132 | // Conditional debug macros |
---|
[1] | 133 | /////////////////////////////////////////////////////////////////////////////////// |
---|
| 134 | |
---|
[407] | 135 | #if CONFIG_CHDEV_DEBUG |
---|
| 136 | #define chdev_dmsg(...) if(hal_time_stamp() > CONFIG_CHDEV_DEBUG) printk(__VA_ARGS__) |
---|
| 137 | #else |
---|
| 138 | #define chdev_dmsg(...) |
---|
| 139 | #endif |
---|
| 140 | |
---|
[50] | 141 | #if CONFIG_CLUSTER_DEBUG |
---|
[406] | 142 | #define cluster_dmsg(...) if(hal_time_stamp() > CONFIG_CLUSTER_DEBUG) printk(__VA_ARGS__) |
---|
[50] | 143 | #else |
---|
| 144 | #define cluster_dmsg(...) |
---|
| 145 | #endif |
---|
| 146 | |
---|
[5] | 147 | #if CONFIG_CONTEXT_DEBUG |
---|
[406] | 148 | #define context_dmsg(...) if(hal_time_stamp() > CONFIG_CONTEXT_DEBUG) printk(__VA_ARGS__) |
---|
[5] | 149 | #else |
---|
| 150 | #define context_dmsg(...) |
---|
| 151 | #endif |
---|
| 152 | |
---|
[1] | 153 | #if CONFIG_CORE_DEBUG |
---|
[406] | 154 | #define core_dmsg(...) if(hal_time_stamp() > CONFIG_CORE_DEBUG) printk(__VA_ARGS__) |
---|
[1] | 155 | #else |
---|
| 156 | #define core_dmsg(...) |
---|
| 157 | #endif |
---|
| 158 | |
---|
[50] | 159 | #if CONFIG_DEVFS_DEBUG |
---|
[406] | 160 | #define devfs_dmsg(...) if(hal_time_stamp() > CONFIG_DEVFS_DEBUG) printk(__VA_ARGS__) |
---|
[50] | 161 | #else |
---|
| 162 | #define devfs_dmsg(...) |
---|
| 163 | #endif |
---|
| 164 | |
---|
| 165 | #if CONFIG_DMA_DEBUG |
---|
[406] | 166 | #define dma_dmsg(...) if(hal_time_stamp() > CONFIG_DMA_DEBUG) printk(__VA_ARGS__) |
---|
[50] | 167 | #else |
---|
| 168 | #define dma_dmsg(...) |
---|
| 169 | #endif |
---|
| 170 | |
---|
[1] | 171 | #if CONFIG_DQDT_DEBUG |
---|
[406] | 172 | #define dqdt_dmsg(...) if(hal_time_stamp() > CONFIG_DQDT_DEBUG) printk(__VA_ARGS__) |
---|
[1] | 173 | #else |
---|
| 174 | #define dqdt_dmsg(...) |
---|
| 175 | #endif |
---|
| 176 | |
---|
| 177 | #if CONFIG_ELF_DEBUG |
---|
[406] | 178 | #define elf_dmsg(...) if(hal_time_stamp() > CONFIG_ELF_DEBUG) printk(__VA_ARGS__) |
---|
[1] | 179 | #else |
---|
| 180 | #define elf_dmsg(...) |
---|
| 181 | #endif |
---|
| 182 | |
---|
[5] | 183 | #if CONFIG_EXEC_DEBUG |
---|
[406] | 184 | #define exec_dmsg(...) if(hal_time_stamp() > CONFIG_EXEC_DEBUG) printk(__VA_ARGS__) |
---|
[1] | 185 | #else |
---|
[5] | 186 | #define exec_dmsg(...) |
---|
[1] | 187 | #endif |
---|
| 188 | |
---|
[406] | 189 | #if CONFIG_EXCP_DEBUG |
---|
| 190 | #define excp_dmsg(...) if(hal_time_stamp() > CONFIG_EXCP_DEBUG) printk(__VA_ARGS__) |
---|
| 191 | #else |
---|
| 192 | #define excp_dmsg(...) |
---|
| 193 | #endif |
---|
| 194 | |
---|
[50] | 195 | #if CONFIG_FATFS_DEBUG |
---|
[406] | 196 | #define fatfs_dmsg(...) if(hal_time_stamp() > CONFIG_FATFS_DEBUG) printk(__VA_ARGS__) |
---|
[50] | 197 | #else |
---|
| 198 | #define fatfs_dmsg(...) |
---|
| 199 | #endif |
---|
| 200 | |
---|
[5] | 201 | #if CONFIG_FBF_DEBUG |
---|
[406] | 202 | #define fbf_dmsg(...) if(hal_time_stamp() > CONFIG_FBF_DEBUG) printk(__VA_ARGS__) |
---|
[1] | 203 | #else |
---|
[5] | 204 | #define fbf_dmsg(...) |
---|
[1] | 205 | #endif |
---|
| 206 | |
---|
[5] | 207 | #if CONFIG_FORK_DEBUG |
---|
[406] | 208 | #define fork_dmsg(...) if(hal_time_stamp() > CONFIG_FORK_DEBUG) printk(__VA_ARGS__) |
---|
[5] | 209 | #else |
---|
| 210 | #define fork_dmsg(...) |
---|
| 211 | #endif |
---|
| 212 | |
---|
[406] | 213 | #if CONFIG_GPT_DEBUG |
---|
| 214 | #define gpt_dmsg(...) if(hal_time_stamp() > CONFIG_GPT_DEBUG) printk(__VA_ARGS__) |
---|
| 215 | #else |
---|
| 216 | #define gpt_dmsg(...) |
---|
| 217 | #endif |
---|
| 218 | |
---|
[407] | 219 | #if CONFIG_GRPC_DEBUG |
---|
| 220 | #define grpc_dmsg(...) if(hal_time_stamp() > CONFIG_GRPC_DEBUG) printk(__VA_ARGS__) |
---|
| 221 | #else |
---|
| 222 | #define grpc_dmsg(...) |
---|
| 223 | #endif |
---|
| 224 | |
---|
[50] | 225 | #if CONFIG_IDLE_DEBUG |
---|
[406] | 226 | #define idle_dmsg(...) if(hal_time_stamp() > CONFIG_IDLE_DEBUG) printk(__VA_ARGS__) |
---|
[50] | 227 | #else |
---|
| 228 | #define idle_dmsg(...) |
---|
| 229 | #endif |
---|
| 230 | |
---|
[1] | 231 | #if CONFIG_IOC_DEBUG |
---|
[389] | 232 | #define ioc_dmsg(...) if(hal_time_stamp() > CONFIG_IOC_DEBUG) printk(__VA_ARGS__) |
---|
[1] | 233 | #else |
---|
| 234 | #define ioc_dmsg(...) |
---|
| 235 | #endif |
---|
| 236 | |
---|
[188] | 237 | #if CONFIG_IRQ_DEBUG |
---|
[406] | 238 | #define irq_dmsg(...) if(hal_time_stamp() > CONFIG_IRQ_DEBUG) printk(__VA_ARGS__) |
---|
[188] | 239 | #else |
---|
| 240 | #define irq_dmsg(...) |
---|
| 241 | #endif |
---|
| 242 | |
---|
[5] | 243 | #if CONFIG_KCM_DEBUG |
---|
[406] | 244 | #define kcm_dmsg(...) if(hal_time_stamp() > CONFIG_KCM_DEBUG) printk(__VA_ARGS__) |
---|
[5] | 245 | #else |
---|
| 246 | #define kcm_dmsg(...) |
---|
| 247 | #endif |
---|
| 248 | |
---|
| 249 | #if CONFIG_KHM_DEBUG |
---|
[406] | 250 | #define khm_dmsg(...) if(hal_time_stamp() > CONFIG_KHM_DEBUG) printk(__VA_ARGS__) |
---|
[5] | 251 | #else |
---|
| 252 | #define khm_dmsg(...) |
---|
| 253 | #endif |
---|
| 254 | |
---|
[409] | 255 | #if CONFIG_KILL_DEBUG |
---|
| 256 | #define kill_dmsg(...) if(hal_time_stamp() > CONFIG_KILL_DEBUG) printk(__VA_ARGS__) |
---|
| 257 | #else |
---|
| 258 | #define kill_dmsg(...) |
---|
| 259 | #endif |
---|
| 260 | |
---|
[1] | 261 | #if CONFIG_KINIT_DEBUG |
---|
[406] | 262 | #define kinit_dmsg(...) if(hal_time_stamp() > CONFIG_KINIT_DEBUG) printk(__VA_ARGS__) |
---|
[1] | 263 | #else |
---|
| 264 | #define kinit_dmsg(...) |
---|
| 265 | #endif |
---|
| 266 | |
---|
| 267 | #if CONFIG_KMEM_DEBUG |
---|
[406] | 268 | #define kmem_dmsg(...) if(hal_time_stamp() > CONFIG_KMEM_DEBUG) printk(__VA_ARGS__) |
---|
[1] | 269 | #else |
---|
| 270 | #define kmem_dmsg(...) |
---|
| 271 | #endif |
---|
| 272 | |
---|
[5] | 273 | #if CONFIG_MAPPER_DEBUG |
---|
[406] | 274 | #define mapper_dmsg(...) if(hal_time_stamp() > CONFIG_MAPPER_DEBUG) printk(__VA_ARGS__) |
---|
[5] | 275 | #else |
---|
| 276 | #define mapper_dmsg(...) |
---|
| 277 | #endif |
---|
| 278 | |
---|
[407] | 279 | #if CONFIG_MMAP_DEBUG |
---|
| 280 | #define mmap_dmsg(...) if(hal_time_stamp() > CONFIG_MMAP_DEBUG) printk(__VA_ARGS__) |
---|
| 281 | #else |
---|
| 282 | #define mmap_dmsg(...) |
---|
| 283 | #endif |
---|
| 284 | |
---|
[1] | 285 | #if CONFIG_MMC_DEBUG |
---|
[406] | 286 | #define mmc_dmsg(...) if(hal_time_stamp() > CONFIG_MMC_DEBUG) printk(__VA_ARGS__) |
---|
[1] | 287 | #else |
---|
| 288 | #define mmc_dmsg(...) |
---|
| 289 | #endif |
---|
| 290 | |
---|
| 291 | #if CONFIG_NIC_DEBUG |
---|
[406] | 292 | #define nic_dmsg(...) if(hal_time_stamp() > CONFIG_NIC_DEBUG) printk(__VA_ARGS__) |
---|
[1] | 293 | #else |
---|
| 294 | #define nic_dmsg(...) |
---|
| 295 | #endif |
---|
| 296 | |
---|
| 297 | #if CONFIG_PIC_DEBUG |
---|
[406] | 298 | #define pic_dmsg(...) if(hal_time_stamp() > CONFIG_PIC_DEBUG) printk(__VA_ARGS__) |
---|
[1] | 299 | #else |
---|
| 300 | #define pic_dmsg(...) |
---|
| 301 | #endif |
---|
| 302 | |
---|
[5] | 303 | #if CONFIG_PPM_DEBUG |
---|
[406] | 304 | #define ppm_dmsg(...) if(hal_time_stamp() > CONFIG_PPM_DEBUG) printk(__VA_ARGS__) |
---|
[5] | 305 | #else |
---|
| 306 | #define ppm_dmsg(...) |
---|
| 307 | #endif |
---|
| 308 | |
---|
[1] | 309 | #if CONFIG_PROCESS_DEBUG |
---|
[406] | 310 | #define process_dmsg(...) if(hal_time_stamp() > CONFIG_PROCESS_DEBUG) printk(__VA_ARGS__) |
---|
[1] | 311 | #else |
---|
| 312 | #define process_dmsg(...) |
---|
| 313 | #endif |
---|
| 314 | |
---|
[407] | 315 | #if CONFIG_READ_DEBUG |
---|
| 316 | #define read_dmsg(...) if(hal_time_stamp() > CONFIG_READ_DEBUG) printk(__VA_ARGS__) |
---|
| 317 | #else |
---|
| 318 | #define read_dmsg(...) |
---|
| 319 | #endif |
---|
| 320 | |
---|
[1] | 321 | #if CONFIG_RPC_DEBUG |
---|
[372] | 322 | #define rpc_dmsg(...) if(hal_time_stamp() > CONFIG_RPC_DEBUG) printk(__VA_ARGS__) |
---|
[1] | 323 | #else |
---|
| 324 | #define rpc_dmsg(...) |
---|
| 325 | #endif |
---|
| 326 | |
---|
| 327 | #if CONFIG_SCHED_DEBUG |
---|
[406] | 328 | #define sched_dmsg(...) if(hal_time_stamp() > CONFIG_SCHED_DEBUG) printk(__VA_ARGS__) |
---|
[1] | 329 | #else |
---|
| 330 | #define sched_dmsg(...) |
---|
| 331 | #endif |
---|
| 332 | |
---|
[415] | 333 | #if CONFIG_SIGACTION_DEBUG |
---|
| 334 | #define sigaction_dmsg(...) if(hal_time_stamp() > CONFIG_SIGACTION_DEBUG) printk(__VA_ARGS__) |
---|
[23] | 335 | #else |
---|
[415] | 336 | #define sigaction_dmsg(...) |
---|
[23] | 337 | #endif |
---|
| 338 | |
---|
[16] | 339 | #if CONFIG_SYSCALL_DEBUG |
---|
[406] | 340 | #define syscall_dmsg(...) if(hal_time_stamp() > CONFIG_SYSCALL_DEBUG) printk(__VA_ARGS__) |
---|
[16] | 341 | #else |
---|
| 342 | #define syscall_dmsg(...) |
---|
| 343 | #endif |
---|
| 344 | |
---|
[1] | 345 | #if CONFIG_THREAD_DEBUG |
---|
[406] | 346 | #define thread_dmsg(...) if(hal_time_stamp() > CONFIG_THREAD_DEBUG) printk(__VA_ARGS__) |
---|
[1] | 347 | #else |
---|
| 348 | #define thread_dmsg(...) |
---|
| 349 | #endif |
---|
| 350 | |
---|
| 351 | #if CONFIG_TXT_DEBUG |
---|
[406] | 352 | #define txt_dmsg(...) if(hal_time_stamp() > CONFIG_TXT_DEBUG) printk(__VA_ARGS__) |
---|
[1] | 353 | #else |
---|
| 354 | #define txt_dmsg(...) |
---|
| 355 | #endif |
---|
| 356 | |
---|
| 357 | #if CONFIG_VFS_DEBUG |
---|
[372] | 358 | #define vfs_dmsg(...) if(hal_time_stamp() > CONFIG_VFS_DEBUG) printk(__VA_ARGS__) |
---|
[1] | 359 | #else |
---|
| 360 | #define vfs_dmsg(...) |
---|
| 361 | #endif |
---|
| 362 | |
---|
| 363 | #if CONFIG_VMM_DEBUG |
---|
[406] | 364 | #define vmm_dmsg(...) if(hal_time_stamp() > CONFIG_VMM_DEBUG) printk(__VA_ARGS__) |
---|
[1] | 365 | #else |
---|
| 366 | #define vmm_dmsg(...) |
---|
| 367 | #endif |
---|
| 368 | |
---|
[407] | 369 | #if CONFIG_WRITE_DEBUG |
---|
| 370 | #define write_dmsg(...) if(hal_time_stamp() > CONFIG_WRITE_DEBUG) printk(__VA_ARGS__) |
---|
| 371 | #else |
---|
| 372 | #define write_dmsg(...) |
---|
| 373 | #endif |
---|
[1] | 374 | |
---|
[407] | 375 | |
---|
[1] | 376 | #endif // _PRINTK_H |
---|
| 377 | |
---|
| 378 | // Local Variables: |
---|
| 379 | // tab-width: 4 |
---|
| 380 | // c-basic-offset: 4 |
---|
| 381 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
---|
| 382 | // indent-tabs-mode: nil |
---|
| 383 | // End: |
---|
| 384 | // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
| 385 | |
---|