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

Last change on this file since 423 was 415, checked in by alain, 7 years ago

Few bugs.

File size: 12.5 KB
Line 
1/*
2 * printk.h - Kernel Log & debug messages API definition.
3 *
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
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_types.h>
44#include <stdarg.h>
45
46
47/**********************************************************************************
48 * This function build a formatted string.
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 *********************************************************************************/
62uint32_t snprintf( char     * string,
63                   uint32_t   length,
64                   char     * format, ... );
65
66/**********************************************************************************
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,
69 * after taking the TXT0 lock.
70 **********************************************************************************
71 * @ format     : formatted string.
72 *********************************************************************************/
73void printk( char* format, ... );
74
75/**********************************************************************************
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,
78 * without taking the TXT0 lock.
79 **********************************************************************************
80 * @ format     : formatted string.
81 *********************************************************************************/
82void nolock_printk( char* format, ... );
83
84/**********************************************************************************
85 * This function displays a message and forces the calling core in sleeping mode.
86 **********************************************************************************
87 * @ format        : formatted string
88 *********************************************************************************/
89void _panic( char* format, ... );
90
91/**********************************************************************************
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...
95 **********************************************************************************
96 * @ condition     : condition that must be true.
97 * @ function_name : name of the calling function.
98 * @ format        : formatted string
99 *********************************************************************************/
100void assert( bool_t       condition,
101             const char * function_name,
102             char       * format , ... );
103
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 *********************************************************************************/
110void 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 *********************************************************************************/
118void 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 *********************************************************************************/
126void putl( uint64_t val );
127
128
129#define panic(fmt, ...)     _panic("\n[PANIC] %s(): " fmt "\n", __func__, ##__VA_ARGS__)
130
131///////////////////////////////////////////////////////////////////////////////////
132//       Conditional debug macros
133///////////////////////////////////////////////////////////////////////////////////
134
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
141#if CONFIG_CLUSTER_DEBUG
142#define cluster_dmsg(...)   if(hal_time_stamp() > CONFIG_CLUSTER_DEBUG) printk(__VA_ARGS__)
143#else
144#define cluster_dmsg(...)
145#endif
146
147#if CONFIG_CONTEXT_DEBUG
148#define context_dmsg(...)   if(hal_time_stamp() > CONFIG_CONTEXT_DEBUG) printk(__VA_ARGS__)
149#else
150#define context_dmsg(...)
151#endif
152
153#if CONFIG_CORE_DEBUG
154#define core_dmsg(...)   if(hal_time_stamp() > CONFIG_CORE_DEBUG) printk(__VA_ARGS__)
155#else
156#define core_dmsg(...)
157#endif
158
159#if CONFIG_DEVFS_DEBUG
160#define devfs_dmsg(...)   if(hal_time_stamp() > CONFIG_DEVFS_DEBUG) printk(__VA_ARGS__)
161#else
162#define devfs_dmsg(...)
163#endif
164
165#if CONFIG_DMA_DEBUG
166#define dma_dmsg(...)   if(hal_time_stamp() > CONFIG_DMA_DEBUG) printk(__VA_ARGS__)
167#else
168#define dma_dmsg(...)
169#endif
170
171#if CONFIG_DQDT_DEBUG
172#define dqdt_dmsg(...)   if(hal_time_stamp() > CONFIG_DQDT_DEBUG) printk(__VA_ARGS__)
173#else
174#define dqdt_dmsg(...)
175#endif
176
177#if CONFIG_ELF_DEBUG
178#define elf_dmsg(...)   if(hal_time_stamp() > CONFIG_ELF_DEBUG) printk(__VA_ARGS__)
179#else
180#define elf_dmsg(...)
181#endif
182
183#if CONFIG_EXEC_DEBUG
184#define exec_dmsg(...)   if(hal_time_stamp() > CONFIG_EXEC_DEBUG) printk(__VA_ARGS__)
185#else
186#define exec_dmsg(...)
187#endif
188
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
195#if CONFIG_FATFS_DEBUG
196#define fatfs_dmsg(...)   if(hal_time_stamp() > CONFIG_FATFS_DEBUG) printk(__VA_ARGS__)
197#else
198#define fatfs_dmsg(...)
199#endif
200
201#if CONFIG_FBF_DEBUG
202#define fbf_dmsg(...)   if(hal_time_stamp() > CONFIG_FBF_DEBUG) printk(__VA_ARGS__)
203#else
204#define fbf_dmsg(...)
205#endif
206
207#if CONFIG_FORK_DEBUG
208#define fork_dmsg(...)   if(hal_time_stamp() > CONFIG_FORK_DEBUG) printk(__VA_ARGS__)
209#else
210#define fork_dmsg(...)
211#endif
212
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
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
225#if CONFIG_IDLE_DEBUG
226#define idle_dmsg(...)   if(hal_time_stamp() > CONFIG_IDLE_DEBUG) printk(__VA_ARGS__)
227#else
228#define idle_dmsg(...)
229#endif
230
231#if CONFIG_IOC_DEBUG
232#define ioc_dmsg(...)   if(hal_time_stamp() > CONFIG_IOC_DEBUG) printk(__VA_ARGS__)
233#else
234#define ioc_dmsg(...)
235#endif
236
237#if CONFIG_IRQ_DEBUG
238#define irq_dmsg(...)   if(hal_time_stamp() > CONFIG_IRQ_DEBUG) printk(__VA_ARGS__)
239#else
240#define irq_dmsg(...)
241#endif
242
243#if CONFIG_KCM_DEBUG
244#define kcm_dmsg(...)   if(hal_time_stamp() > CONFIG_KCM_DEBUG) printk(__VA_ARGS__)
245#else
246#define kcm_dmsg(...)
247#endif
248
249#if CONFIG_KHM_DEBUG
250#define khm_dmsg(...)   if(hal_time_stamp() > CONFIG_KHM_DEBUG) printk(__VA_ARGS__)
251#else
252#define khm_dmsg(...)
253#endif
254
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
261#if CONFIG_KINIT_DEBUG
262#define kinit_dmsg(...)   if(hal_time_stamp() > CONFIG_KINIT_DEBUG) printk(__VA_ARGS__)
263#else
264#define kinit_dmsg(...)
265#endif
266
267#if CONFIG_KMEM_DEBUG
268#define kmem_dmsg(...)   if(hal_time_stamp() > CONFIG_KMEM_DEBUG) printk(__VA_ARGS__)
269#else
270#define kmem_dmsg(...)
271#endif
272
273#if CONFIG_MAPPER_DEBUG
274#define mapper_dmsg(...)   if(hal_time_stamp() > CONFIG_MAPPER_DEBUG) printk(__VA_ARGS__)
275#else
276#define mapper_dmsg(...)
277#endif
278
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
285#if CONFIG_MMC_DEBUG
286#define mmc_dmsg(...)   if(hal_time_stamp() > CONFIG_MMC_DEBUG) printk(__VA_ARGS__)
287#else
288#define mmc_dmsg(...)
289#endif
290
291#if CONFIG_NIC_DEBUG
292#define nic_dmsg(...)   if(hal_time_stamp() > CONFIG_NIC_DEBUG) printk(__VA_ARGS__)
293#else
294#define nic_dmsg(...)
295#endif
296
297#if CONFIG_PIC_DEBUG
298#define pic_dmsg(...)   if(hal_time_stamp() > CONFIG_PIC_DEBUG) printk(__VA_ARGS__)
299#else
300#define pic_dmsg(...)
301#endif
302
303#if CONFIG_PPM_DEBUG
304#define ppm_dmsg(...)   if(hal_time_stamp() > CONFIG_PPM_DEBUG) printk(__VA_ARGS__)
305#else
306#define ppm_dmsg(...)
307#endif
308
309#if CONFIG_PROCESS_DEBUG
310#define process_dmsg(...)   if(hal_time_stamp() > CONFIG_PROCESS_DEBUG) printk(__VA_ARGS__)
311#else
312#define process_dmsg(...)
313#endif
314
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
321#if CONFIG_RPC_DEBUG
322#define rpc_dmsg(...)   if(hal_time_stamp() > CONFIG_RPC_DEBUG) printk(__VA_ARGS__)
323#else
324#define rpc_dmsg(...)
325#endif
326
327#if CONFIG_SCHED_DEBUG
328#define sched_dmsg(...)   if(hal_time_stamp() > CONFIG_SCHED_DEBUG) printk(__VA_ARGS__)
329#else
330#define sched_dmsg(...)
331#endif
332
333#if CONFIG_SIGACTION_DEBUG
334#define sigaction_dmsg(...)   if(hal_time_stamp() > CONFIG_SIGACTION_DEBUG) printk(__VA_ARGS__)
335#else
336#define sigaction_dmsg(...)
337#endif
338
339#if CONFIG_SYSCALL_DEBUG
340#define syscall_dmsg(...)   if(hal_time_stamp() > CONFIG_SYSCALL_DEBUG) printk(__VA_ARGS__)
341#else
342#define syscall_dmsg(...)
343#endif
344
345#if CONFIG_THREAD_DEBUG
346#define thread_dmsg(...)   if(hal_time_stamp() > CONFIG_THREAD_DEBUG) printk(__VA_ARGS__)
347#else
348#define thread_dmsg(...)
349#endif
350
351#if CONFIG_TXT_DEBUG
352#define txt_dmsg(...)   if(hal_time_stamp() > CONFIG_TXT_DEBUG) printk(__VA_ARGS__)
353#else
354#define txt_dmsg(...)
355#endif
356
357#if CONFIG_VFS_DEBUG
358#define vfs_dmsg(...)   if(hal_time_stamp() > CONFIG_VFS_DEBUG) printk(__VA_ARGS__)
359#else
360#define vfs_dmsg(...)
361#endif
362
363#if CONFIG_VMM_DEBUG
364#define vmm_dmsg(...)   if(hal_time_stamp() > CONFIG_VMM_DEBUG) printk(__VA_ARGS__)
365#else
366#define vmm_dmsg(...)
367#endif
368
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
374
375
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
Note: See TracBrowser for help on using the repository browser.