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