]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/l4sys/include/ARCH-x86/kdebug.h
2532a24e297aecb4aa4bcdd1f62f7f33dce3dc91
[l4.git] / l4 / pkg / l4sys / include / ARCH-x86 / kdebug.h
1 /*****************************************************************************/
2 /**
3  * \file
4  * \brief   Kernel debugger macros
5  * \ingroup api_calls
6  */
7 /*
8  * (c) 2008-2009 Technische Universität Dresden
9  * This file is part of TUD:OS and distributed under the terms of the
10  * GNU General Public License 2.
11  * Please see the COPYING-GPL-2 file for details.
12  *
13  * As a special exception, you may use this file as part of a free software
14  * library without restriction.  Specifically, if other files instantiate
15  * templates or use macros or inline functions from this file, or you compile
16  * this file and link it with other files to produce an executable, this
17  * file does not by itself cause the resulting executable to be covered by
18  * the GNU General Public License.  This exception does not however
19  * invalidate any other reasons why the executable file might be covered by
20  * the GNU General Public License.
21  */
22 /*****************************************************************************/
23 #ifndef __L4_KDEBUG_H__
24 #define __L4_KDEBUG_H__
25
26 #include <l4/sys/compiler.h>
27
28 /**
29  * Enter L4 kernel debugger
30  * \ingroup l4_debugger_api
31  * \hideinitializer
32  *
33  * \param   text         Text to be shown at kernel debugger prompt
34  */
35 #ifndef __ASSEMBLER__
36 #define enter_kdebug(text) \
37 asm(\
38     "int        $3      \n\t"\
39     "jmp        1f      \n\t"\
40     ".ascii     \""text "\"\n\t"\
41     "1:                 \n\t"\
42     )
43 #else
44 #define enter_kdebug(text)   \
45     int $3            ;\
46     jmp 1f            ;\
47     .ascii      text  ;\
48     1:
49 #endif
50
51 /**
52  * Enter L4 kernel debugger (plain assembler version)
53  * \ingroup l4_debugger_api
54  * \hideinitializer
55  *
56  * \param   text         Text to be shown at kernel debugger prompt
57  */
58 #define asm_enter_kdebug(text) \
59     "int        $3      \n\t"\
60     "jmp        1f      \n\t"\
61     ".ascii     \""text "\"\n\t"\
62     "1:                 \n\t"
63
64 /**
65  * Show message with L4 kernel debugger, but do not enter debugger
66  * \ingroup l4_debugger_api
67  * \hideinitializer
68  *
69  * \param   text         Text to be shown
70  */
71 #define kd_display(text) \
72 asm(\
73     "int        $3      \n\t"\
74     "nop                \n\t"\
75     "jmp        1f      \n\t"\
76     ".ascii     \""text "\"\n\t"\
77     "1:                 \n\t"\
78     )
79
80 /**
81  * Output character with L4 kernel debugger
82  * \ingroup l4_debugger_api
83  * \hideinitializer
84  *
85  * \param   c            Character to be shown
86  */
87 #define ko(c)                                   \
88   asm(                                          \
89       "int      $3      \n\t"                   \
90       "cmpb     %0,%%al \n\t"                   \
91       : /* No output */                         \
92       : "N" (c)                                 \
93       )
94
95 /*****************************************************************************
96  *** Prototypes
97  *****************************************************************************/
98
99 #ifndef __ASSEMBLER__
100
101 /**
102  * Print character
103  * \ingroup l4_debugger_api
104  *
105  * \param   c            Character
106  */
107 L4_INLINE void
108 outchar(char c) L4_NOTHROW;
109
110 /**
111  * Print character string
112  * \ingroup l4_debugger_api
113  *
114  * \param   text         String
115  */
116 L4_INLINE void
117 outstring(const char * text) L4_NOTHROW;
118
119 /**
120  * Print character string
121  * \ingroup l4_debugger_api
122  *
123  * \param   text         String
124  * \param   len          Number of characters
125  */
126 L4_INLINE void
127 outnstring(char const *text, unsigned len) L4_NOTHROW;
128
129 /**
130  * Print 32 bit number (hexadecimal)
131  * \ingroup l4_debugger_api
132  *
133  * \param   number       32 bit number
134  */
135 L4_INLINE void
136 outhex32(int number) L4_NOTHROW;
137
138 /**
139  * Print 20 bit number (hexadecimal)
140  * \ingroup l4_debugger_api
141  *
142  * \param   number       20 bit number
143  */
144 L4_INLINE void
145 outhex20(int number) L4_NOTHROW;
146
147 /**
148  * Print 16 bit number (hexadecimal)
149  * \ingroup l4_debugger_api
150  *
151  * \param   number       16 bit number
152  */
153 L4_INLINE void
154 outhex16(int number) L4_NOTHROW;
155
156 /**
157  * Print 12 bit number (hexadecimal)
158  * \ingroup l4_debugger_api
159  *
160  * \param   number       12 bit number
161  */
162 L4_INLINE void
163 outhex12(int number) L4_NOTHROW;
164
165 /**
166  * Print 8 bit number (hexadecimal)
167  * \ingroup l4_debugger_api
168  *
169  * \param   number       8 bit number
170  */
171 L4_INLINE void
172 outhex8(int number) L4_NOTHROW;
173
174 /**
175  * Print number (decimal)
176  * \ingroup l4_debugger_api
177  *
178  * \param   number       Number
179  */
180 L4_INLINE void
181 outdec(int number) L4_NOTHROW;
182
183 /**
184  * Read character from console, non blocking
185  * \ingroup l4_debugger_api
186  *
187  * \return Input character, -1 if no character to read
188  */
189 L4_INLINE char
190 l4kd_inchar(void) L4_NOTHROW;
191
192 /**
193  * Start profiling
194  * \ingroup api_calls_fiasco
195  */
196 L4_INLINE void
197 fiasco_profile_start(void) L4_NOTHROW;
198
199 /**
200  * Stop profiling and dump result to console
201  * \ingroup api_calls_fiasco
202  */
203 L4_INLINE void
204 fiasco_profile_stop_and_dump(void) L4_NOTHROW;
205
206 /**
207  * Stop profiling
208  * \ingroup api_calls_fiasco
209  */
210 L4_INLINE void
211 fiasco_profile_stop(void) L4_NOTHROW;
212
213 /**
214  * Enable Fiasco watchdog
215  * \ingroup api_calls_fiasco
216  */
217 L4_INLINE void
218 fiasco_watchdog_enable(void) L4_NOTHROW;
219
220 /**
221  * Disable Fiasco watchdog
222  * \ingroup api_calls_fiasco
223  */
224 L4_INLINE void
225 fiasco_watchdog_disable(void) L4_NOTHROW;
226
227 /**
228  * Disable automatic resetting of watchdog. User is responsible to call
229  * \c fiasco_watchdog_touch from time to time to ensure that the watchdog
230  * does not trigger.
231  * \ingroup api_calls_fiasco
232  */
233 L4_INLINE void
234 fiasco_watchdog_takeover(void) L4_NOTHROW;
235
236 /**
237  * Reenable automatic resetting of watchdog.
238  * \ingroup api_calls_fiasco
239  */
240 L4_INLINE void
241 fiasco_watchdog_giveback(void) L4_NOTHROW;
242
243 /**
244  * Reset watchdog from user land. This function \b must be called from time
245  * to time to prevent the watchdog from triggering if the watchdog is
246  * activated and if \c fiasco_watchdog_takeover was performed.
247  * \ingroup api_calls_fiasco
248  */
249 L4_INLINE void
250 fiasco_watchdog_touch(void) L4_NOTHROW;
251
252
253 /*****************************************************************************
254  *** Implementation
255  *****************************************************************************/
256
257 L4_INLINE void
258 outchar(char c) L4_NOTHROW
259 {
260   asm(
261       "int      $3      \n\t"
262       "cmpb     $0,%%al \n\t"
263       : /* No output */
264       : "a" (c)
265       );
266 }
267
268 /* actually outstring is outcstring */
269 L4_INLINE void
270 outstring(const char *text) L4_NOTHROW
271 {
272   asm volatile (
273       "int      $3      \n\t"
274       "cmpb     $2,%%al \n\t"
275       : /* No output */
276       : "a" (text)
277       : "memory"
278       );
279 }
280
281 /* actually outstring is outcstring */
282 L4_INLINE void
283 outnstring(char const *text, unsigned len) L4_NOTHROW
284 {
285   asm volatile (
286       "pushl    %%ebx        \n\t"
287       "movl     %%ecx, %%ebx \n\t"
288       "int      $3           \n\t"
289       "cmpb     $1,%%al      \n\t"
290       "popl     %%ebx        \n\t"
291       : /* No output */
292       : "a" (text), "c"(len)
293       : "memory"
294       );
295 }
296
297 L4_INLINE void
298 outhex32(int number) L4_NOTHROW
299 {
300   asm(
301       "int      $3      \n\t"
302       "cmpb     $5,%%al \n\t"
303       : /* No output */
304       : "a" (number)
305       );
306 }
307
308 L4_INLINE void
309 outhex20(int number) L4_NOTHROW
310 {
311   asm(
312       "int      $3      \n\t"
313       "cmpb     $6,%%al \n\t"
314       : /* No output */
315       : "a" (number)
316       );
317 }
318
319 L4_INLINE void
320 outhex16(int number) L4_NOTHROW
321 {
322   asm(
323       "int      $3      \n\t"
324       "cmpb     $7, %%al\n\t"
325       : /* No output */
326       : "a" (number)
327       );
328 }
329
330 L4_INLINE void
331 outhex12(int number) L4_NOTHROW
332 {
333   asm(
334       "int      $3      \n\t"
335       "cmpb     $8, %%al\n\t"
336       : /* No output */
337       : "a" (number)
338       );
339 }
340
341 L4_INLINE void
342 outhex8(int number) L4_NOTHROW
343 {
344   asm(
345       "int      $3      \n\t"
346       "cmpb     $9, %%al\n\t"
347       : /* No output */
348       : "a" (number)
349       );
350 }
351
352 L4_INLINE void
353 outdec(int number) L4_NOTHROW
354 {
355   asm(
356       "int      $3      \n\t"
357       "cmpb     $11, %%al\n\t"
358       : /* No output */
359       : "a" (number)
360       );
361 }
362
363 L4_INLINE char
364 l4kd_inchar(void) L4_NOTHROW
365 {
366   char c;
367   asm volatile ("int $3; cmpb $13, %%al" : "=a" (c));
368   return c;
369 }
370
371 L4_INLINE void
372 fiasco_profile_start(void) L4_NOTHROW
373 {
374   asm("int $3; cmpb $24, %al");
375 }
376
377 L4_INLINE void
378 fiasco_profile_stop_and_dump(void) L4_NOTHROW
379 {
380   asm("int $3; cmpb $25, %al");
381 }
382
383 L4_INLINE void
384 fiasco_profile_stop(void) L4_NOTHROW
385 {
386   asm("int $3; cmpb $26, %al");
387 }
388
389 L4_INLINE void
390 fiasco_watchdog_enable(void) L4_NOTHROW
391 {
392   asm("int $3; cmpb $31, %%al" : : "c" (1));
393 }
394
395 L4_INLINE void
396 fiasco_watchdog_disable(void) L4_NOTHROW
397 {
398   asm("int $3; cmpb $31, %%al" : : "c" (2));
399 }
400
401 L4_INLINE void
402 fiasco_watchdog_takeover(void) L4_NOTHROW
403 {
404   asm("int $3; cmpb $31, %%al" : : "c" (3));
405 }
406
407 L4_INLINE void
408 fiasco_watchdog_giveback(void) L4_NOTHROW
409 {
410   asm("int $3; cmpb $31, %%al" : : "c" (4));
411 }
412
413 L4_INLINE void
414 fiasco_watchdog_touch(void) L4_NOTHROW
415 {
416   asm("int $3; cmpb $31, %%al" : : "c" (5));
417 }
418
419 #endif /* __ASSEMBLER__ */
420
421 #endif /* __L4_KDEBUG_H__ */