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