source: trunk/kernel/kern/printk.h @ 491

Last change on this file since 491 was 491, checked in by viala@…, 6 years ago

Change assert to be a macro

Ease using of static analyser and add debuging facility.

File size: 13.8 KB
RevLine 
[1]1/*
2 * printk.h - Kernel Log & debug messages API definition.
[372]3 *
[437]4 * authors  Alain Greiner (2016,2017,2018)
[1]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
[457]43#include <hal_kernel_types.h>
[5]44#include <stdarg.h>
[1]45
[491]46#include <hal_special.h> // hal_get_cycles()
[5]47
48/**********************************************************************************
[372]49 * This function build a formatted string.
[23]50 * The supported formats are defined below :
51 *   %c : single character
52 *   %d : signed decimal 32 bits integer
53 *   %u : unsigned decimal 32 bits integer
54 *   %x : hexadecimal 32 bits integer
55 *   %l : hexadecimal 64 bits integer
56 *   %s : NUL terminated character string
57 **********************************************************************************
58 * @ string     : pointer on target buffer (allocated by caller).
59 * @ length     : target buffer length (number of bytes).
60 * @ format     : format respecting the printf syntax.
61 * @ returns the string length (including NUL) if success / return -1 if error.
62 *********************************************************************************/
63uint32_t snprintf( char     * string,
64                   uint32_t   length,
65                   char     * format, ... );
66
67/**********************************************************************************
[372]68 * This function displays a formatted string on the kernel terminal TXT0,
69 * using a busy waiting policy: It calls directly the relevant TXT driver,
[296]70 * after taking the TXT0 lock.
[5]71 **********************************************************************************
[372]72 * @ format     : formatted string.
[5]73 *********************************************************************************/
[103]74void printk( char* format, ... );
[1]75
[5]76/**********************************************************************************
[372]77 * This function displays a formatted string on the kernel terminal TXT0,
78 * using a busy waiting policy: It calls directly the relevant TXT driver,
[296]79 * without taking the TXT0 lock.
80 **********************************************************************************
[372]81 * @ format     : formatted string.
[296]82 *********************************************************************************/
83void nolock_printk( char* format, ... );
84
[491]85
[296]86/**********************************************************************************
[491]87 * Private function designed to be called by the assert macro (below)
88 **********************************************************************************
89 * @ file_name     : File where the assert macro was invoked
90 * @ function_name : Name of the calling function.
91 * @ line          : Line number where the assert macro was invoked
92 * @ cycle         : Cycle where the macro was invoked
93 * @ format        : Formatted string
94 * ...             : arguments of the format string
95 *
96 * See assert macro documentation for information about printed information.
97 *********************************************************************************/
98void __panic( const char * file_name,
99              const char * function_name,
100              uint32_t     line,
101              cycle_t      cycle,
102              const char * format, ... )
103__attribute__((__noreturn__));
104
105/**********************************************************************************
106 * This macro displays a formated message on kernel TXT0 terminal,
[408]107 * and forces the calling core in sleeping mode if a Boolean condition is false.
[491]108 * Actually used to debug the kernel.
109 *
110 * Information printed by assert:
111 * Current running thread:
112 *   - thread descriptior adress
113 *   - thread id (trdid)
114 *
115 * Current Process:
116 *   - Process descriptor adress
117 *   - Process id (pid)
118 *
119 * Current Core:
120 *   - local cluster position (local_cxy)
121 *   - local core id (lid)
122 *
123 * File name (__FILE__) and were the assert is invoked.
124 * And the assert message.
125 *
126 * Cycle: before the assert branchment.
127 * Note: cycle may change due to compiler optimisation.
128 *
129 * Exemple:
130 * assert( my_ptr != NULL, "my_ptr should not be NULL")
[5]131 **********************************************************************************
132 * @ condition     : condition that must be true.
[372]133 * @ format        : formatted string
[5]134 *********************************************************************************/
[491]135#define assert( expr, format, ... ) { uint32_t __line_at_expansion = __LINE__;    \
136  const volatile cycle_t __assert_cycle = hal_get_cycles();                       \
137  if ( ( expr ) == false ) {                                                      \
138    __panic( __FILE__, __FUNCTION__,                                              \
139             __line_at_expansion, __assert_cycle,                                 \
140             ( format ), ##__VA_ARGS__ );                                         \
141  }                                                                               \
142}
[5]143
[408]144/**********************************************************************************
145 * This function displays a non-formated message on kernel TXT0 terminal.
146 * This function is actually used to debug the assembly level kernel functions.
147 **********************************************************************************
148 * @ string   : non-formatted string.
149 *********************************************************************************/
150void puts( char * string );
151
152/**********************************************************************************
153 * This function displays a 32 bits value in hexadecimal on kernel TXT0 terminal.
154 * This function is actually used to debug the assembly level kernel functions.
155 **********************************************************************************
156 * @ val   : 32 bits unsigned value.
157 *********************************************************************************/
158void putx( uint32_t val );
159
160/**********************************************************************************
161 * This function displays a 64 bits value in hexadecimal on kernel TXT0 terminal.
162 * This function is actually used to debug the assembly level kernel functions.
163 **********************************************************************************
164 * @ val   : 64 bits unsigned value.
165 *********************************************************************************/
166void putl( uint64_t val );
167
168
[1]169
[437]170/*  deprecated march 2018 [AG]
171
[407]172#if CONFIG_CHDEV_DEBUG
173#define chdev_dmsg(...)   if(hal_time_stamp() > CONFIG_CHDEV_DEBUG) printk(__VA_ARGS__)
174#else
175#define chdev_dmsg(...)
176#endif
177
[50]178#if CONFIG_CLUSTER_DEBUG
[406]179#define cluster_dmsg(...)   if(hal_time_stamp() > CONFIG_CLUSTER_DEBUG) printk(__VA_ARGS__)
[50]180#else
181#define cluster_dmsg(...)
182#endif
183
[5]184#if CONFIG_CONTEXT_DEBUG
[406]185#define context_dmsg(...)   if(hal_time_stamp() > CONFIG_CONTEXT_DEBUG) printk(__VA_ARGS__)
[5]186#else
187#define context_dmsg(...)
188#endif
189
[1]190#if CONFIG_CORE_DEBUG
[406]191#define core_dmsg(...)   if(hal_time_stamp() > CONFIG_CORE_DEBUG) printk(__VA_ARGS__)
[1]192#else
193#define core_dmsg(...)
194#endif
195
[50]196#if CONFIG_DEVFS_DEBUG
[406]197#define devfs_dmsg(...)   if(hal_time_stamp() > CONFIG_DEVFS_DEBUG) printk(__VA_ARGS__)
[50]198#else
199#define devfs_dmsg(...)
200#endif
201
202#if CONFIG_DMA_DEBUG
[406]203#define dma_dmsg(...)   if(hal_time_stamp() > CONFIG_DMA_DEBUG) printk(__VA_ARGS__)
[50]204#else
205#define dma_dmsg(...)
206#endif
207
[1]208#if CONFIG_DQDT_DEBUG
[406]209#define dqdt_dmsg(...)   if(hal_time_stamp() > CONFIG_DQDT_DEBUG) printk(__VA_ARGS__)
[1]210#else
211#define dqdt_dmsg(...)
212#endif
213
214#if CONFIG_ELF_DEBUG
[406]215#define elf_dmsg(...)   if(hal_time_stamp() > CONFIG_ELF_DEBUG) printk(__VA_ARGS__)
[1]216#else
217#define elf_dmsg(...)
218#endif
219
[5]220#if CONFIG_EXEC_DEBUG
[406]221#define exec_dmsg(...)   if(hal_time_stamp() > CONFIG_EXEC_DEBUG) printk(__VA_ARGS__)
[1]222#else
[5]223#define exec_dmsg(...)
[1]224#endif
225
[406]226#if CONFIG_EXCP_DEBUG
227#define excp_dmsg(...)   if(hal_time_stamp() > CONFIG_EXCP_DEBUG) printk(__VA_ARGS__)
228#else
229#define excp_dmsg(...)
230#endif
231
[50]232#if CONFIG_FATFS_DEBUG
[406]233#define fatfs_dmsg(...)   if(hal_time_stamp() > CONFIG_FATFS_DEBUG) printk(__VA_ARGS__)
[50]234#else
235#define fatfs_dmsg(...)
236#endif
237
[5]238#if CONFIG_FBF_DEBUG
[406]239#define fbf_dmsg(...)   if(hal_time_stamp() > CONFIG_FBF_DEBUG) printk(__VA_ARGS__)
[1]240#else
[5]241#define fbf_dmsg(...)
[1]242#endif
243
[5]244#if CONFIG_FORK_DEBUG
[406]245#define fork_dmsg(...)   if(hal_time_stamp() > CONFIG_FORK_DEBUG) printk(__VA_ARGS__)
[5]246#else
247#define fork_dmsg(...)
248#endif
249
[406]250#if CONFIG_GPT_DEBUG
251#define gpt_dmsg(...)   if(hal_time_stamp() > CONFIG_GPT_DEBUG) printk(__VA_ARGS__)
252#else
253#define gpt_dmsg(...)
254#endif
255
[407]256#if CONFIG_GRPC_DEBUG
257#define grpc_dmsg(...)   if(hal_time_stamp() > CONFIG_GRPC_DEBUG) printk(__VA_ARGS__)
258#else
259#define grpc_dmsg(...)
260#endif
261
[50]262#if CONFIG_IDLE_DEBUG
[406]263#define idle_dmsg(...)   if(hal_time_stamp() > CONFIG_IDLE_DEBUG) printk(__VA_ARGS__)
[50]264#else
265#define idle_dmsg(...)
266#endif
267
[1]268#if CONFIG_IOC_DEBUG
[389]269#define ioc_dmsg(...)   if(hal_time_stamp() > CONFIG_IOC_DEBUG) printk(__VA_ARGS__)
[1]270#else
271#define ioc_dmsg(...)
272#endif
273
[188]274#if CONFIG_IRQ_DEBUG
[406]275#define irq_dmsg(...)   if(hal_time_stamp() > CONFIG_IRQ_DEBUG) printk(__VA_ARGS__)
[188]276#else
277#define irq_dmsg(...)
278#endif
279
[5]280#if CONFIG_KCM_DEBUG
[406]281#define kcm_dmsg(...)   if(hal_time_stamp() > CONFIG_KCM_DEBUG) printk(__VA_ARGS__)
[5]282#else
283#define kcm_dmsg(...)
284#endif
285
286#if CONFIG_KHM_DEBUG
[406]287#define khm_dmsg(...)   if(hal_time_stamp() > CONFIG_KHM_DEBUG) printk(__VA_ARGS__)
[5]288#else
289#define khm_dmsg(...)
290#endif
291
[409]292#if CONFIG_KILL_DEBUG
293#define kill_dmsg(...)   if(hal_time_stamp() > CONFIG_KILL_DEBUG) printk(__VA_ARGS__)
294#else
295#define kill_dmsg(...)
296#endif
297
[1]298#if CONFIG_KINIT_DEBUG
[406]299#define kinit_dmsg(...)   if(hal_time_stamp() > CONFIG_KINIT_DEBUG) printk(__VA_ARGS__)
[1]300#else
301#define kinit_dmsg(...)
302#endif
303
304#if CONFIG_KMEM_DEBUG
[406]305#define kmem_dmsg(...)   if(hal_time_stamp() > CONFIG_KMEM_DEBUG) printk(__VA_ARGS__)
[1]306#else
307#define kmem_dmsg(...)
308#endif
309
[5]310#if CONFIG_MAPPER_DEBUG
[406]311#define mapper_dmsg(...)   if(hal_time_stamp() > CONFIG_MAPPER_DEBUG) printk(__VA_ARGS__)
[5]312#else
313#define mapper_dmsg(...)
314#endif
315
[407]316#if CONFIG_MMAP_DEBUG
317#define mmap_dmsg(...)   if(hal_time_stamp() > CONFIG_MMAP_DEBUG) printk(__VA_ARGS__)
318#else
319#define mmap_dmsg(...)
320#endif
321
[1]322#if CONFIG_MMC_DEBUG
[406]323#define mmc_dmsg(...)   if(hal_time_stamp() > CONFIG_MMC_DEBUG) printk(__VA_ARGS__)
[1]324#else
325#define mmc_dmsg(...)
326#endif
327
328#if CONFIG_NIC_DEBUG
[406]329#define nic_dmsg(...)   if(hal_time_stamp() > CONFIG_NIC_DEBUG) printk(__VA_ARGS__)
[1]330#else
331#define nic_dmsg(...)
332#endif
333
334#if CONFIG_PIC_DEBUG
[406]335#define pic_dmsg(...)   if(hal_time_stamp() > CONFIG_PIC_DEBUG) printk(__VA_ARGS__)
[1]336#else
337#define pic_dmsg(...)
338#endif
339
[5]340#if CONFIG_PPM_DEBUG
[406]341#define ppm_dmsg(...)   if(hal_time_stamp() > CONFIG_PPM_DEBUG) printk(__VA_ARGS__)
[5]342#else
343#define ppm_dmsg(...)
344#endif
345
[1]346#if CONFIG_PROCESS_DEBUG
[406]347#define process_dmsg(...)   if(hal_time_stamp() > CONFIG_PROCESS_DEBUG) printk(__VA_ARGS__)
[1]348#else
349#define process_dmsg(...)
350#endif
351
[407]352#if CONFIG_READ_DEBUG
353#define read_dmsg(...)   if(hal_time_stamp() > CONFIG_READ_DEBUG) printk(__VA_ARGS__)
354#else
355#define read_dmsg(...)
356#endif
357
[1]358#if CONFIG_RPC_DEBUG
[372]359#define rpc_dmsg(...)   if(hal_time_stamp() > CONFIG_RPC_DEBUG) printk(__VA_ARGS__)
[1]360#else
361#define rpc_dmsg(...)
362#endif
363
364#if CONFIG_SCHED_DEBUG
[406]365#define sched_dmsg(...)   if(hal_time_stamp() > CONFIG_SCHED_DEBUG) printk(__VA_ARGS__)
[1]366#else
367#define sched_dmsg(...)
368#endif
369
[415]370#if CONFIG_SIGACTION_DEBUG
371#define sigaction_dmsg(...)   if(hal_time_stamp() > CONFIG_SIGACTION_DEBUG) printk(__VA_ARGS__)
[23]372#else
[415]373#define sigaction_dmsg(...)
[23]374#endif
375
[16]376#if CONFIG_SYSCALL_DEBUG
[406]377#define syscall_dmsg(...)   if(hal_time_stamp() > CONFIG_SYSCALL_DEBUG) printk(__VA_ARGS__)
[16]378#else
379#define syscall_dmsg(...)
380#endif
381
[1]382#if CONFIG_THREAD_DEBUG
[406]383#define thread_dmsg(...)   if(hal_time_stamp() > CONFIG_THREAD_DEBUG) printk(__VA_ARGS__)
[1]384#else
385#define thread_dmsg(...)
386#endif
387
388#if CONFIG_TXT_DEBUG
[406]389#define txt_dmsg(...)   if(hal_time_stamp() > CONFIG_TXT_DEBUG) printk(__VA_ARGS__)
[1]390#else
391#define txt_dmsg(...)
392#endif
393
394#if CONFIG_VFS_DEBUG
[372]395#define vfs_dmsg(...)   if(hal_time_stamp() > CONFIG_VFS_DEBUG) printk(__VA_ARGS__)
[1]396#else
397#define vfs_dmsg(...)
398#endif
399
400#if CONFIG_VMM_DEBUG
[406]401#define vmm_dmsg(...)   if(hal_time_stamp() > CONFIG_VMM_DEBUG) printk(__VA_ARGS__)
[1]402#else
403#define vmm_dmsg(...)
404#endif
405
[407]406#if CONFIG_WRITE_DEBUG
407#define write_dmsg(...)   if(hal_time_stamp() > CONFIG_WRITE_DEBUG) printk(__VA_ARGS__)
408#else
409#define write_dmsg(...)
410#endif
[1]411
[437]412*/
[407]413
[1]414#endif  // _PRINTK_H
415
416// Local Variables:
417// tab-width: 4
418// c-basic-offset: 4
419// c-file-offsets:((innamespace . 0)(inline-open . 0))
420// indent-tabs-mode: nil
421// End:
422// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
423
Note: See TracBrowser for help on using the repository browser.