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

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

assert: Fix signature mismatch.

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,
[502]102              const char * format,
103              ... )
[491]104__attribute__((__noreturn__));
105
106/**********************************************************************************
107 * This macro displays a formated message on kernel TXT0 terminal,
[408]108 * and forces the calling core in sleeping mode if a Boolean condition is false.
[491]109 * Actually used to debug the kernel.
110 *
111 * Information printed by assert:
112 * Current running thread:
113 *   - thread descriptior adress
114 *   - thread id (trdid)
115 *
116 * Current Process:
117 *   - Process descriptor adress
118 *   - Process id (pid)
119 *
120 * Current Core:
121 *   - local cluster position (local_cxy)
122 *   - local core id (lid)
123 *
124 * File name (__FILE__) and were the assert is invoked.
125 * And the assert message.
126 *
127 * Cycle: before the assert branchment.
128 * Note: cycle may change due to compiler optimisation.
129 *
130 * Exemple:
131 * assert( my_ptr != NULL, "my_ptr should not be NULL")
[5]132 **********************************************************************************
133 * @ condition     : condition that must be true.
[372]134 * @ format        : formatted string
[5]135 *********************************************************************************/
[491]136#define assert( expr, format, ... ) { uint32_t __line_at_expansion = __LINE__;    \
137  const volatile cycle_t __assert_cycle = hal_get_cycles();                       \
138  if ( ( expr ) == false ) {                                                      \
139    __panic( __FILE__, __FUNCTION__,                                              \
140             __line_at_expansion, __assert_cycle,                                 \
141             ( format ), ##__VA_ARGS__ );                                         \
142  }                                                                               \
143}
[5]144
[408]145/**********************************************************************************
146 * This function displays a non-formated message on kernel TXT0 terminal.
147 * This function is actually used to debug the assembly level kernel functions.
148 **********************************************************************************
149 * @ string   : non-formatted string.
150 *********************************************************************************/
151void puts( char * string );
152
153/**********************************************************************************
154 * This function displays a 32 bits value in hexadecimal on kernel TXT0 terminal.
155 * This function is actually used to debug the assembly level kernel functions.
156 **********************************************************************************
157 * @ val   : 32 bits unsigned value.
158 *********************************************************************************/
159void putx( uint32_t val );
160
161/**********************************************************************************
162 * This function displays a 64 bits value in hexadecimal on kernel TXT0 terminal.
163 * This function is actually used to debug the assembly level kernel functions.
164 **********************************************************************************
165 * @ val   : 64 bits unsigned value.
166 *********************************************************************************/
167void putl( uint64_t val );
168
169
[1]170
[437]171/*  deprecated march 2018 [AG]
172
[407]173#if CONFIG_CHDEV_DEBUG
174#define chdev_dmsg(...)   if(hal_time_stamp() > CONFIG_CHDEV_DEBUG) printk(__VA_ARGS__)
175#else
176#define chdev_dmsg(...)
177#endif
178
[50]179#if CONFIG_CLUSTER_DEBUG
[406]180#define cluster_dmsg(...)   if(hal_time_stamp() > CONFIG_CLUSTER_DEBUG) printk(__VA_ARGS__)
[50]181#else
182#define cluster_dmsg(...)
183#endif
184
[5]185#if CONFIG_CONTEXT_DEBUG
[406]186#define context_dmsg(...)   if(hal_time_stamp() > CONFIG_CONTEXT_DEBUG) printk(__VA_ARGS__)
[5]187#else
188#define context_dmsg(...)
189#endif
190
[1]191#if CONFIG_CORE_DEBUG
[406]192#define core_dmsg(...)   if(hal_time_stamp() > CONFIG_CORE_DEBUG) printk(__VA_ARGS__)
[1]193#else
194#define core_dmsg(...)
195#endif
196
[50]197#if CONFIG_DEVFS_DEBUG
[406]198#define devfs_dmsg(...)   if(hal_time_stamp() > CONFIG_DEVFS_DEBUG) printk(__VA_ARGS__)
[50]199#else
200#define devfs_dmsg(...)
201#endif
202
203#if CONFIG_DMA_DEBUG
[406]204#define dma_dmsg(...)   if(hal_time_stamp() > CONFIG_DMA_DEBUG) printk(__VA_ARGS__)
[50]205#else
206#define dma_dmsg(...)
207#endif
208
[1]209#if CONFIG_DQDT_DEBUG
[406]210#define dqdt_dmsg(...)   if(hal_time_stamp() > CONFIG_DQDT_DEBUG) printk(__VA_ARGS__)
[1]211#else
212#define dqdt_dmsg(...)
213#endif
214
215#if CONFIG_ELF_DEBUG
[406]216#define elf_dmsg(...)   if(hal_time_stamp() > CONFIG_ELF_DEBUG) printk(__VA_ARGS__)
[1]217#else
218#define elf_dmsg(...)
219#endif
220
[5]221#if CONFIG_EXEC_DEBUG
[406]222#define exec_dmsg(...)   if(hal_time_stamp() > CONFIG_EXEC_DEBUG) printk(__VA_ARGS__)
[1]223#else
[5]224#define exec_dmsg(...)
[1]225#endif
226
[406]227#if CONFIG_EXCP_DEBUG
228#define excp_dmsg(...)   if(hal_time_stamp() > CONFIG_EXCP_DEBUG) printk(__VA_ARGS__)
229#else
230#define excp_dmsg(...)
231#endif
232
[50]233#if CONFIG_FATFS_DEBUG
[406]234#define fatfs_dmsg(...)   if(hal_time_stamp() > CONFIG_FATFS_DEBUG) printk(__VA_ARGS__)
[50]235#else
236#define fatfs_dmsg(...)
237#endif
238
[5]239#if CONFIG_FBF_DEBUG
[406]240#define fbf_dmsg(...)   if(hal_time_stamp() > CONFIG_FBF_DEBUG) printk(__VA_ARGS__)
[1]241#else
[5]242#define fbf_dmsg(...)
[1]243#endif
244
[5]245#if CONFIG_FORK_DEBUG
[406]246#define fork_dmsg(...)   if(hal_time_stamp() > CONFIG_FORK_DEBUG) printk(__VA_ARGS__)
[5]247#else
248#define fork_dmsg(...)
249#endif
250
[406]251#if CONFIG_GPT_DEBUG
252#define gpt_dmsg(...)   if(hal_time_stamp() > CONFIG_GPT_DEBUG) printk(__VA_ARGS__)
253#else
254#define gpt_dmsg(...)
255#endif
256
[407]257#if CONFIG_GRPC_DEBUG
258#define grpc_dmsg(...)   if(hal_time_stamp() > CONFIG_GRPC_DEBUG) printk(__VA_ARGS__)
259#else
260#define grpc_dmsg(...)
261#endif
262
[50]263#if CONFIG_IDLE_DEBUG
[406]264#define idle_dmsg(...)   if(hal_time_stamp() > CONFIG_IDLE_DEBUG) printk(__VA_ARGS__)
[50]265#else
266#define idle_dmsg(...)
267#endif
268
[1]269#if CONFIG_IOC_DEBUG
[389]270#define ioc_dmsg(...)   if(hal_time_stamp() > CONFIG_IOC_DEBUG) printk(__VA_ARGS__)
[1]271#else
272#define ioc_dmsg(...)
273#endif
274
[188]275#if CONFIG_IRQ_DEBUG
[406]276#define irq_dmsg(...)   if(hal_time_stamp() > CONFIG_IRQ_DEBUG) printk(__VA_ARGS__)
[188]277#else
278#define irq_dmsg(...)
279#endif
280
[5]281#if CONFIG_KCM_DEBUG
[406]282#define kcm_dmsg(...)   if(hal_time_stamp() > CONFIG_KCM_DEBUG) printk(__VA_ARGS__)
[5]283#else
284#define kcm_dmsg(...)
285#endif
286
287#if CONFIG_KHM_DEBUG
[406]288#define khm_dmsg(...)   if(hal_time_stamp() > CONFIG_KHM_DEBUG) printk(__VA_ARGS__)
[5]289#else
290#define khm_dmsg(...)
291#endif
292
[409]293#if CONFIG_KILL_DEBUG
294#define kill_dmsg(...)   if(hal_time_stamp() > CONFIG_KILL_DEBUG) printk(__VA_ARGS__)
295#else
296#define kill_dmsg(...)
297#endif
298
[1]299#if CONFIG_KINIT_DEBUG
[406]300#define kinit_dmsg(...)   if(hal_time_stamp() > CONFIG_KINIT_DEBUG) printk(__VA_ARGS__)
[1]301#else
302#define kinit_dmsg(...)
303#endif
304
305#if CONFIG_KMEM_DEBUG
[406]306#define kmem_dmsg(...)   if(hal_time_stamp() > CONFIG_KMEM_DEBUG) printk(__VA_ARGS__)
[1]307#else
308#define kmem_dmsg(...)
309#endif
310
[5]311#if CONFIG_MAPPER_DEBUG
[406]312#define mapper_dmsg(...)   if(hal_time_stamp() > CONFIG_MAPPER_DEBUG) printk(__VA_ARGS__)
[5]313#else
314#define mapper_dmsg(...)
315#endif
316
[407]317#if CONFIG_MMAP_DEBUG
318#define mmap_dmsg(...)   if(hal_time_stamp() > CONFIG_MMAP_DEBUG) printk(__VA_ARGS__)
319#else
320#define mmap_dmsg(...)
321#endif
322
[1]323#if CONFIG_MMC_DEBUG
[406]324#define mmc_dmsg(...)   if(hal_time_stamp() > CONFIG_MMC_DEBUG) printk(__VA_ARGS__)
[1]325#else
326#define mmc_dmsg(...)
327#endif
328
329#if CONFIG_NIC_DEBUG
[406]330#define nic_dmsg(...)   if(hal_time_stamp() > CONFIG_NIC_DEBUG) printk(__VA_ARGS__)
[1]331#else
332#define nic_dmsg(...)
333#endif
334
335#if CONFIG_PIC_DEBUG
[406]336#define pic_dmsg(...)   if(hal_time_stamp() > CONFIG_PIC_DEBUG) printk(__VA_ARGS__)
[1]337#else
338#define pic_dmsg(...)
339#endif
340
[5]341#if CONFIG_PPM_DEBUG
[406]342#define ppm_dmsg(...)   if(hal_time_stamp() > CONFIG_PPM_DEBUG) printk(__VA_ARGS__)
[5]343#else
344#define ppm_dmsg(...)
345#endif
346
[1]347#if CONFIG_PROCESS_DEBUG
[406]348#define process_dmsg(...)   if(hal_time_stamp() > CONFIG_PROCESS_DEBUG) printk(__VA_ARGS__)
[1]349#else
350#define process_dmsg(...)
351#endif
352
[407]353#if CONFIG_READ_DEBUG
354#define read_dmsg(...)   if(hal_time_stamp() > CONFIG_READ_DEBUG) printk(__VA_ARGS__)
355#else
356#define read_dmsg(...)
357#endif
358
[1]359#if CONFIG_RPC_DEBUG
[372]360#define rpc_dmsg(...)   if(hal_time_stamp() > CONFIG_RPC_DEBUG) printk(__VA_ARGS__)
[1]361#else
362#define rpc_dmsg(...)
363#endif
364
365#if CONFIG_SCHED_DEBUG
[406]366#define sched_dmsg(...)   if(hal_time_stamp() > CONFIG_SCHED_DEBUG) printk(__VA_ARGS__)
[1]367#else
368#define sched_dmsg(...)
369#endif
370
[415]371#if CONFIG_SIGACTION_DEBUG
372#define sigaction_dmsg(...)   if(hal_time_stamp() > CONFIG_SIGACTION_DEBUG) printk(__VA_ARGS__)
[23]373#else
[415]374#define sigaction_dmsg(...)
[23]375#endif
376
[16]377#if CONFIG_SYSCALL_DEBUG
[406]378#define syscall_dmsg(...)   if(hal_time_stamp() > CONFIG_SYSCALL_DEBUG) printk(__VA_ARGS__)
[16]379#else
380#define syscall_dmsg(...)
381#endif
382
[1]383#if CONFIG_THREAD_DEBUG
[406]384#define thread_dmsg(...)   if(hal_time_stamp() > CONFIG_THREAD_DEBUG) printk(__VA_ARGS__)
[1]385#else
386#define thread_dmsg(...)
387#endif
388
389#if CONFIG_TXT_DEBUG
[406]390#define txt_dmsg(...)   if(hal_time_stamp() > CONFIG_TXT_DEBUG) printk(__VA_ARGS__)
[1]391#else
392#define txt_dmsg(...)
393#endif
394
395#if CONFIG_VFS_DEBUG
[372]396#define vfs_dmsg(...)   if(hal_time_stamp() > CONFIG_VFS_DEBUG) printk(__VA_ARGS__)
[1]397#else
398#define vfs_dmsg(...)
399#endif
400
401#if CONFIG_VMM_DEBUG
[406]402#define vmm_dmsg(...)   if(hal_time_stamp() > CONFIG_VMM_DEBUG) printk(__VA_ARGS__)
[1]403#else
404#define vmm_dmsg(...)
405#endif
406
[407]407#if CONFIG_WRITE_DEBUG
408#define write_dmsg(...)   if(hal_time_stamp() > CONFIG_WRITE_DEBUG) printk(__VA_ARGS__)
409#else
410#define write_dmsg(...)
411#endif
[1]412
[437]413*/
[407]414
[1]415#endif  // _PRINTK_H
416
417// Local Variables:
418// tab-width: 4
419// c-basic-offset: 4
420// c-file-offsets:((innamespace . 0)(inline-open . 0))
421// indent-tabs-mode: nil
422// End:
423// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
424
Note: See TracBrowser for help on using the repository browser.