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

Last change on this file since 501 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
Line 
1/*
2 * printk.h - Kernel Log & debug messages API definition.
3 *
4 * authors  Alain Greiner (2016,2017,2018)
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 signalling 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 conditional trace <***_dmsg> for debug.
38///////////////////////////////////////////////////////////////////////////////////
39
40#ifndef _PRINTK_H
41#define _PRINTK_H
42
43#include <hal_kernel_types.h>
44#include <stdarg.h>
45
46#include <hal_special.h> // hal_get_cycles()
47
48/**********************************************************************************
49 * This function build a formatted string.
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/**********************************************************************************
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,
70 * after taking the TXT0 lock.
71 **********************************************************************************
72 * @ format     : formatted string.
73 *********************************************************************************/
74void printk( char* format, ... );
75
76/**********************************************************************************
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,
79 * without taking the TXT0 lock.
80 **********************************************************************************
81 * @ format     : formatted string.
82 *********************************************************************************/
83void nolock_printk( char* format, ... );
84
85
86/**********************************************************************************
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,
107 * and forces the calling core in sleeping mode if a Boolean condition is false.
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")
131 **********************************************************************************
132 * @ condition     : condition that must be true.
133 * @ format        : formatted string
134 *********************************************************************************/
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}
143
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
169
170/*  deprecated march 2018 [AG]
171
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
178#if CONFIG_CLUSTER_DEBUG
179#define cluster_dmsg(...)   if(hal_time_stamp() > CONFIG_CLUSTER_DEBUG) printk(__VA_ARGS__)
180#else
181#define cluster_dmsg(...)
182#endif
183
184#if CONFIG_CONTEXT_DEBUG
185#define context_dmsg(...)   if(hal_time_stamp() > CONFIG_CONTEXT_DEBUG) printk(__VA_ARGS__)
186#else
187#define context_dmsg(...)
188#endif
189
190#if CONFIG_CORE_DEBUG
191#define core_dmsg(...)   if(hal_time_stamp() > CONFIG_CORE_DEBUG) printk(__VA_ARGS__)
192#else
193#define core_dmsg(...)
194#endif
195
196#if CONFIG_DEVFS_DEBUG
197#define devfs_dmsg(...)   if(hal_time_stamp() > CONFIG_DEVFS_DEBUG) printk(__VA_ARGS__)
198#else
199#define devfs_dmsg(...)
200#endif
201
202#if CONFIG_DMA_DEBUG
203#define dma_dmsg(...)   if(hal_time_stamp() > CONFIG_DMA_DEBUG) printk(__VA_ARGS__)
204#else
205#define dma_dmsg(...)
206#endif
207
208#if CONFIG_DQDT_DEBUG
209#define dqdt_dmsg(...)   if(hal_time_stamp() > CONFIG_DQDT_DEBUG) printk(__VA_ARGS__)
210#else
211#define dqdt_dmsg(...)
212#endif
213
214#if CONFIG_ELF_DEBUG
215#define elf_dmsg(...)   if(hal_time_stamp() > CONFIG_ELF_DEBUG) printk(__VA_ARGS__)
216#else
217#define elf_dmsg(...)
218#endif
219
220#if CONFIG_EXEC_DEBUG
221#define exec_dmsg(...)   if(hal_time_stamp() > CONFIG_EXEC_DEBUG) printk(__VA_ARGS__)
222#else
223#define exec_dmsg(...)
224#endif
225
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
232#if CONFIG_FATFS_DEBUG
233#define fatfs_dmsg(...)   if(hal_time_stamp() > CONFIG_FATFS_DEBUG) printk(__VA_ARGS__)
234#else
235#define fatfs_dmsg(...)
236#endif
237
238#if CONFIG_FBF_DEBUG
239#define fbf_dmsg(...)   if(hal_time_stamp() > CONFIG_FBF_DEBUG) printk(__VA_ARGS__)
240#else
241#define fbf_dmsg(...)
242#endif
243
244#if CONFIG_FORK_DEBUG
245#define fork_dmsg(...)   if(hal_time_stamp() > CONFIG_FORK_DEBUG) printk(__VA_ARGS__)
246#else
247#define fork_dmsg(...)
248#endif
249
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
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
262#if CONFIG_IDLE_DEBUG
263#define idle_dmsg(...)   if(hal_time_stamp() > CONFIG_IDLE_DEBUG) printk(__VA_ARGS__)
264#else
265#define idle_dmsg(...)
266#endif
267
268#if CONFIG_IOC_DEBUG
269#define ioc_dmsg(...)   if(hal_time_stamp() > CONFIG_IOC_DEBUG) printk(__VA_ARGS__)
270#else
271#define ioc_dmsg(...)
272#endif
273
274#if CONFIG_IRQ_DEBUG
275#define irq_dmsg(...)   if(hal_time_stamp() > CONFIG_IRQ_DEBUG) printk(__VA_ARGS__)
276#else
277#define irq_dmsg(...)
278#endif
279
280#if CONFIG_KCM_DEBUG
281#define kcm_dmsg(...)   if(hal_time_stamp() > CONFIG_KCM_DEBUG) printk(__VA_ARGS__)
282#else
283#define kcm_dmsg(...)
284#endif
285
286#if CONFIG_KHM_DEBUG
287#define khm_dmsg(...)   if(hal_time_stamp() > CONFIG_KHM_DEBUG) printk(__VA_ARGS__)
288#else
289#define khm_dmsg(...)
290#endif
291
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
298#if CONFIG_KINIT_DEBUG
299#define kinit_dmsg(...)   if(hal_time_stamp() > CONFIG_KINIT_DEBUG) printk(__VA_ARGS__)
300#else
301#define kinit_dmsg(...)
302#endif
303
304#if CONFIG_KMEM_DEBUG
305#define kmem_dmsg(...)   if(hal_time_stamp() > CONFIG_KMEM_DEBUG) printk(__VA_ARGS__)
306#else
307#define kmem_dmsg(...)
308#endif
309
310#if CONFIG_MAPPER_DEBUG
311#define mapper_dmsg(...)   if(hal_time_stamp() > CONFIG_MAPPER_DEBUG) printk(__VA_ARGS__)
312#else
313#define mapper_dmsg(...)
314#endif
315
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
322#if CONFIG_MMC_DEBUG
323#define mmc_dmsg(...)   if(hal_time_stamp() > CONFIG_MMC_DEBUG) printk(__VA_ARGS__)
324#else
325#define mmc_dmsg(...)
326#endif
327
328#if CONFIG_NIC_DEBUG
329#define nic_dmsg(...)   if(hal_time_stamp() > CONFIG_NIC_DEBUG) printk(__VA_ARGS__)
330#else
331#define nic_dmsg(...)
332#endif
333
334#if CONFIG_PIC_DEBUG
335#define pic_dmsg(...)   if(hal_time_stamp() > CONFIG_PIC_DEBUG) printk(__VA_ARGS__)
336#else
337#define pic_dmsg(...)
338#endif
339
340#if CONFIG_PPM_DEBUG
341#define ppm_dmsg(...)   if(hal_time_stamp() > CONFIG_PPM_DEBUG) printk(__VA_ARGS__)
342#else
343#define ppm_dmsg(...)
344#endif
345
346#if CONFIG_PROCESS_DEBUG
347#define process_dmsg(...)   if(hal_time_stamp() > CONFIG_PROCESS_DEBUG) printk(__VA_ARGS__)
348#else
349#define process_dmsg(...)
350#endif
351
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
358#if CONFIG_RPC_DEBUG
359#define rpc_dmsg(...)   if(hal_time_stamp() > CONFIG_RPC_DEBUG) printk(__VA_ARGS__)
360#else
361#define rpc_dmsg(...)
362#endif
363
364#if CONFIG_SCHED_DEBUG
365#define sched_dmsg(...)   if(hal_time_stamp() > CONFIG_SCHED_DEBUG) printk(__VA_ARGS__)
366#else
367#define sched_dmsg(...)
368#endif
369
370#if CONFIG_SIGACTION_DEBUG
371#define sigaction_dmsg(...)   if(hal_time_stamp() > CONFIG_SIGACTION_DEBUG) printk(__VA_ARGS__)
372#else
373#define sigaction_dmsg(...)
374#endif
375
376#if CONFIG_SYSCALL_DEBUG
377#define syscall_dmsg(...)   if(hal_time_stamp() > CONFIG_SYSCALL_DEBUG) printk(__VA_ARGS__)
378#else
379#define syscall_dmsg(...)
380#endif
381
382#if CONFIG_THREAD_DEBUG
383#define thread_dmsg(...)   if(hal_time_stamp() > CONFIG_THREAD_DEBUG) printk(__VA_ARGS__)
384#else
385#define thread_dmsg(...)
386#endif
387
388#if CONFIG_TXT_DEBUG
389#define txt_dmsg(...)   if(hal_time_stamp() > CONFIG_TXT_DEBUG) printk(__VA_ARGS__)
390#else
391#define txt_dmsg(...)
392#endif
393
394#if CONFIG_VFS_DEBUG
395#define vfs_dmsg(...)   if(hal_time_stamp() > CONFIG_VFS_DEBUG) printk(__VA_ARGS__)
396#else
397#define vfs_dmsg(...)
398#endif
399
400#if CONFIG_VMM_DEBUG
401#define vmm_dmsg(...)   if(hal_time_stamp() > CONFIG_VMM_DEBUG) printk(__VA_ARGS__)
402#else
403#define vmm_dmsg(...)
404#endif
405
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
411
412*/
413
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.