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

Last change on this file since 407 was 407, checked in by alain, 6 years ago

First implementation of fork/exec.

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