source: trunk/kernel/kern/kdmsg.h @ 317

Last change on this file since 317 was 1, checked in by alain, 8 years ago

First import

File size: 7.4 KB
Line 
1/*
2 * kdmsg.h - printk like functions and trace messages
3 *
4 * authors     Ghassan Almaless (2008,2009,2010,2011,2012)
5 *             Mohamed Lamine Karaoui (2015)
6 *             Alain Greiner (2016)
7 *
8 * Copyright (c) UPMC Sorbonne Universites
9 * 
10 * This file is part of ALMOS-MKH.
11 *
12 * ALMOS-MKH is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; version 2.0 of the License.
15 *
16 * ALMOS-MKH is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19 * General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with ALMOS-MKH; if not, write to the Free Software Foundation,
23 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 */
25
26#ifndef _KDMSG_H_
27#define _KDMSG_H_
28
29#include <hal_types.h>
30#include <spinlock.h>
31#include <stdarg.h>
32
33#define ERROR     DMSG_ERROR
34#define WARNING   DMSG_WARNING
35#define INFO      DMSG_INFO
36#define DEBUG     DMSG_DEBUG
37#define BOOT      DMSG_BOOT
38#define ASSERT    DMSG_ASSERT
39
40#define LEVEL     CONFIG_DMSG_LEVEL
41
42typedef enum
43{
44        PRINTK_KTTY_LOCK,
45        ISR_KTTY_LOCK,
46        NO_KTTY_LOCK
47} 
48ktty_lock_t;
49
50typedef struct kdmsg_channel_s
51{
52        union
53        {
54                global_t val;
55                uint_t id;
56        };
57}
58kdmsg_channel_t;
59
60extern kdmsg_channel_t klog_tty;
61extern kdmsg_channel_t kisr_tty;
62extern kdmsg_channel_t kexcept_tty;
63
64#define printk(level, args...)                                          \
65        do{                                                             \
66                if((level) <= LEVEL)                                    \
67                        __fprintk(klog_tty.id, PRINTK_KTTY_LOCK, args); \
68        }while(0)
69
70
71#define isr_dmsg(level, args...)                                        \
72        do{                                                             \
73                if((level) <= LEVEL)                                    \
74                        __fprintk(kisr_tty.id, ISR_KTTY_LOCK, args);    \
75        }while(0)
76
77#define cpu_log_msg(...)                                        \
78        do{                                                     \
79                __fprintk(cpu_get_id(), NO_KTTY_LOCK, __VA_ARGS__);     \
80        }while(0)
81
82
83#if (ERROR <= LEVEL)
84#define except_dmsg(args...) do { __fprintk(kexcept_tty.id, NO_KTTY_LOCK, args); } while(0)
85#else
86#define except_dmsg(args...)
87#endif
88
89#if (BOOT <= LEVEL)
90#if CONFIG_SHOW_ALL_BOOT_MSG
91#define boot_dmsg(args...)   do { __arch_boot_dmsg(args); } while(0)
92#else
93#define boot_dmsg(args...)   do { if ( current_cid == 0 ) __arch_boot_dmsg(args); } while(0)
94#endif
95#else
96#define boot_dmsg(args...)
97#endif
98
99void kdmsg_init();
100void kboot_tty_init(boot_info_t *info);
101void bdump(uint8_t *buff, size_t count);
102
103int __perror (int fatal, const char *fmt, ...);
104int __fprintk (int tty, ktty_lock_t ktl, const char *fmt, ...);
105int __arch_boot_dmsg (const char *fmt, ...);
106
107#define PANIC(MSG, ...)                                         \
108        do{                                                             \
109                __perror(1,"PANIC at line: %d, file: %s , MSG: " MSG"\n", __LINE__,__FILE__, ##__VA_ARGS__);    \
110                while(1);                                                                                       \
111        } while(0)
112
113
114/* Assert are not executed if the __OPTIMIZE__ macro is defined *
115 * This mean no important code should be put inside an assert   */
116#if (ASSERT <= LEVEL) && (!defined (__OPTIMIZE__))
117//#if 1
118#define assert(expr) \
119(void) ((expr) ? 0 : __perror(0,"cpu %d: Assert "#expr" faild, line %d, file %s [%d]\n", cpu_get_id(), __LINE__, __FILE__, cpu_time_stamp()))
120#define bassert(expr) \
121(void) ((expr) ? 0 : __arch_boot_dmsg("Assert "#expr" faild, line %d, file %s [%d]\n", __LINE__, __FILE__, cpu_time_stamp()))
122#define assert2(_th,expr) \
123(void) ((expr) ? 0 : __perror(0,"[ %x ] Assert "#expr" faild, line %d, file %s, Thread [%x] on CPU [%d], Current Thread [%x] on CPU [%d], [%u]\n", cpu_time_stamp(), __LINE__,__FILE__, _th, thread_current_cpu((_th))->gid, current_thread, cpu_get_id(), cpu_time_stamp()))
124#else
125#define assert(expr) do{}while(0)
126#define assert2(_th,expr)do{}while(0)
127#define bassert(expr)do{}while(0)
128//#define full_assert(_th,expr)do{}while(0)
129#endif
130
131#define full_assert(_th,expr) \
132(void) ((expr) ? 0 : ({__perror(0,"[ %x ] Assert "#expr" faild, line %d, file %s, Thread [%x] on CPU [%d], Current Thread [%x] on CPU [%d], [%u]\n", cpu_time_stamp(), __LINE__,__FILE__, _th, thread_current_cpu((_th))->gid, current_thread, cpu_get_id(), cpu_time_stamp()); while(1);}))
133
134/////////////////////////////////////////////////////////////////////////
135//      per subsystem printk wrapper upon its debug configuration      //
136/////////////////////////////////////////////////////////////////////////
137
138#define dmsg(level, config, args...)            \
139        do                                      \
140        {                                       \
141                if((level) <= (config))         \
142                        printk(DEBUG, args);    \
143        } while(0)
144
145#if CONFIG_IOC_DEBUG
146#define ioc_dmsg( args... )   printk( args )
147#else
148#define ioc_dmsg( args... )
149#endif
150
151#if CONFIG_VFAT_DEBUG
152#define vfat_dmsg(level, args...)               \
153        dmsg(level, CONFIG_VFAT_DEBUG, args)
154#else
155#define vfat_dmsg(args...)
156#endif
157
158#if CONFIG_EXT2_DEBUG
159#define ext2_dmsg(level, args...)               \
160        dmsg(level, CONFIG_EXT2_DEBUG, args)
161#else
162#define ext2_dmsg(args...)
163#endif
164
165#if CONFIG_DEVFS_DEBUG
166#define devfs_dmsg(level, args...)              \
167        dmsg(level, CONFIG_DEVFS_DEBUG, args)
168#else
169#define devfs_dmsg(args...)
170#endif
171
172#if CONFIG_SYSFS_DEBUG
173#define sysfs_dmsg(level, args...)              \
174        dmsg(level, CONFIG_SYSFS_DEBUG, args)
175#else
176#define sysfs_dmsg(args...)
177#endif
178
179#if CONFIG_VFS_DEBUG
180#define vfs_dmsg(level, args...)                \
181        dmsg(level, CONFIG_VFS_DEBUG, args)
182#else
183#define vfs_dmsg(args...)
184#endif
185
186#if CONFIG_MAPPER_DEBUG
187#define mapper_dmsg(level, args...)             \
188        dmsg(level, CONFIG_MAPPER_DEBUG, args)
189#else
190#define mapper_dmsg(args...)
191#endif
192
193#if CONFIG_KMEM_DEBUG
194#define kmem_dmsg(args...) boot_dmsg(args)//printk(DEBUG, args)
195#else
196#define kmem_dmsg(args...)
197#endif
198
199#if CONFIG_KHM_DEBUG
200#define khm_dmsg(args...) boot_dmsg(args)//printk(DEBUG, args)
201#else
202#define khm_dmsg(args...)
203#endif
204
205#if CONFIG_KCM_DEBUG
206#define kcm_dmsg(args...) printk(DEBUG, args)
207#else
208#define kcm_dmsg(args...)
209#endif
210
211#if CONFIG_VMM_DEBUG
212#define vmm_dmsg(level, args...)                \
213        dmsg(level, CONFIG_VMM_DEBUG, args)
214#else
215#define vmm_dmsg(args...)
216#endif
217
218#if CONFIG_VMM_REGION_DEBUG
219#define vmm_reg_dmsg(level, args...)                    \
220        dmsg(level, CONFIG_VMM_REGION_DEBUG, args)
221#else
222#define vmm_reg_dmsg(args...)
223#endif
224
225#if CONFIG_DQDT_DEBUG
226#define dqdt_dmsg(level, args...)               \
227        dmsg(level, CONFIG_DQDT_DEBUG, args)
228#else
229#define dqdt_dmsg(args...)
230#endif
231
232#if CONFIG_KFIFO_DEBUG
233#define lffb_dmsg(level, args...)               \
234        dmsg(level, CONFIG_KFIFO_DEBUG, args)
235#else
236#define lffb_dmsg(args...)
237#endif
238
239#if CONFIG_FORK_DEBUG
240#define fork_dmsg(level, args...)               \
241        dmsg(level, CONFIG_FORK_DEBUG, args)
242#else
243#define fork_dmsg(args...)
244#endif
245
246#if CONFIG_SHOW_THREAD_MSG
247#define thread_dmsg(level, args...)             \
248        dmsg(level, CONFIG_SHOW_THREAD_MSG, args)
249#else
250#define thread_dmsg(args...)
251#endif
252
253#if CONFIG_ELF_DEBUG
254#define elf_dmsg(level, args...)                \
255        dmsg(level, CONFIG_ELF_DEBUG, args)
256#else
257#define elf_dmsg(args...)
258#endif
259
260
261#if CONFIG_PID_DEBUG
262#define pid_dmsg(level, args...)                \
263        dmsg(level, CONFIG_PID_DEBUG, args)
264#else
265#define pid_dmsg(args...)
266#endif
267
268#if CONFIG_SHOW_SIG_MSG
269#define sig_dmsg(level, args...)                \
270        dmsg(level, CONFIG_SHOW_SIG_MSG, args)
271#else
272#define sig_dmsg(args...)
273#endif
274
275#if CONFIG_HTBL_DEBUG
276#define htbl_dmsg(level, args...)                \
277        dmsg(level, CONFIG_HTBL_DEBUG, args)
278#else
279#define htbl_dmsg(args...)
280#endif
281
282#if CONFIG_SHOW_RPC_MSG
283#define rpc_dmsg(level, args...)                \
284        dmsg(level, CONFIG_SHOW_RPC_MSG, args)
285#else
286#define rpc_dmsg(args...)
287#endif
288
289#if CONFIG_EXEC_DEBUG
290#define exec_dmsg(level, args...)               \
291        dmsg(level, CONFIG_EXEC_DEBUG, args)
292#else
293#define exec_dmsg(args...)
294#endif
295/////////////////////////////////////////////////////////////
296
297#endif // _KDMSG_H_
Note: See TracBrowser for help on using the repository browser.