L4Re – L4 Runtime Environment
kdebug.h
1 /*
2  * (c) 2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>
3  * economic rights: Technische Universität Dresden (Germany)
4  *
5  * This file is part of TUD:OS and distributed under the terms of the
6  * GNU General Public License 2.
7  * Please see the COPYING-GPL-2 file for details.
8  *
9  * As a special exception, you may use this file as part of a free software
10  * library without restriction. Specifically, if other files instantiate
11  * templates or use macros or inline functions from this file, or you compile
12  * this file and link it with other files to produce an executable, this
13  * file does not by itself cause the resulting executable to be covered by
14  * the GNU General Public License. This exception does not however
15  * invalidate any other reasons why the executable file might be covered by
16  * the GNU General Public License.
17  */
18 
19 #pragma once
20 
21 #ifndef __KDEBUG_H__
22 #define __KDEBUG_H__
23 
24 #include <l4/sys/compiler.h>
25 #include <l4/sys/consts.h>
26 #include <l4/sys/ipc.h>
27 
28 
29 L4_INLINE void
30 enter_kdebug(char const *text) L4_NOTHROW;
31 
32 enum l4_kdebug_ops_t
33 {
34  L4_KDEBUG_ENTER = 0,
35  L4_KDEBUG_OUTCHAR = 1,
36  L4_KDEBUG_OUTNSTRING = 2,
37  L4_KDEBUG_OUTHEX32 = 3,
38  L4_KDEBUG_OUTHEX20 = 4,
39  L4_KDEBUG_OUTHEX16 = 5,
40  L4_KDEBUG_OUTHEX12 = 6,
41  L4_KDEBUG_OUTHEX8 = 7,
42  L4_KDEBUG_OUTDEC = 8,
43 };
44 
45 
46 L4_INLINE l4_msgtag_t
47 __kdebug_op(unsigned op) L4_NOTHROW
48 {
49  l4_msgtag_t res;
50  l4_utcb_t *u = l4_utcb();
51  l4_msg_regs_t *mr = l4_utcb_mr_u(u);
52  l4_umword_t mr0 = mr->mr[0];
53 
54  mr->mr[0] = op;
56  l4_msgtag(L4_PROTO_DEBUGGER, 1, 0, 0),
57  L4_IPC_NEVER);
58  mr->mr[0] = mr0;
59  return res;
60 }
61 
62 L4_INLINE l4_msgtag_t
63 __kdebug_text(unsigned op, char const *text, unsigned len) L4_NOTHROW
64 {
65  l4_msg_regs_t store;
66  l4_msgtag_t res;
67  l4_utcb_t *u = l4_utcb();
68  l4_msg_regs_t *mr = l4_utcb_mr_u(u);
69 
70  if (len > (sizeof(store) - (2 * sizeof(l4_umword_t))))
71  len = sizeof(store) - (2 * sizeof(l4_umword_t));
72 
73  __builtin_memcpy(&store, mr, sizeof(store));
74  mr->mr[0] = op;
75  mr->mr[1] = len;
76  __builtin_memcpy(&mr->mr[2], text, len);
79  l4_bytes_to_mwords(len) + 2, 0, 0),
80  L4_IPC_NEVER);
81  __builtin_memcpy(mr, &store, sizeof(*mr));
82  return res;
83 }
84 
85 L4_INLINE l4_msgtag_t
86 __kdebug_3_text(unsigned op, char const *text, unsigned len,
88 {
89  l4_msg_regs_t store;
90  l4_msgtag_t res;
91  l4_utcb_t *u = l4_utcb();
92  l4_msg_regs_t *mr = l4_utcb_mr_u(u);
93 
94  if (len > (sizeof(store) - (5 * sizeof(l4_umword_t))))
95  len = sizeof(store) - (5 * sizeof(l4_umword_t));
96 
97  __builtin_memcpy(&store, mr, sizeof(store));
98  mr->mr[0] = op;
99  mr->mr[1] = v1;
100  mr->mr[2] = v2;
101  mr->mr[3] = v3;
102  mr->mr[4] = len;
103  __builtin_memcpy(&mr->mr[5], text, len);
106  l4_bytes_to_mwords(len) + 5, 0, 0),
107  L4_IPC_NEVER);
108  __builtin_memcpy(mr, &store, sizeof(*mr));
109  return res;
110 }
111 
112 L4_INLINE l4_msgtag_t
113 __kdebug_op_1(unsigned op, l4_mword_t val) L4_NOTHROW
114 {
115  l4_umword_t m[2];
116  l4_msgtag_t res;
117  l4_utcb_t *u = l4_utcb();
118  l4_msg_regs_t *mr = l4_utcb_mr_u(u);
119 
120  m[0] = mr->mr[0];
121  m[1] = mr->mr[1];
122  mr->mr[0] = op;
123  mr->mr[1] = val;
125  l4_msgtag(L4_PROTO_DEBUGGER, 2, 0, 0),
126  L4_IPC_NEVER);
127  mr->mr[0] = m[0];
128  mr->mr[1] = m[1];
129  return res;
130 }
131 
132 L4_INLINE void enter_kdebug(char const *text) L4_NOTHROW
133 {
134  /* special case, enter without any text and use of the UTCB */
135  if (!text)
136  {
138  l4_msgtag(L4_PROTO_DEBUGGER, 0, 0, 0),
139  L4_IPC_NEVER);
140  return;
141  }
142 
143  __kdebug_text(L4_KDEBUG_ENTER, text, __builtin_strlen(text));
144 }
145 
146 L4_INLINE void outnstring(char const *text, unsigned len)
147 { __kdebug_text(L4_KDEBUG_OUTNSTRING, text, len); }
148 
149 L4_INLINE void outstring(char const *text)
150 { outnstring(text, __builtin_strlen(text)); }
151 
152 
153 L4_INLINE void outchar(char c)
154 {
155  __kdebug_op_1(L4_KDEBUG_OUTCHAR, c);
156 }
157 
158 L4_INLINE void outumword(l4_umword_t number)
159 {
160  if (sizeof(l4_umword_t) == sizeof(l4_uint64_t))
161  __kdebug_op_1(L4_KDEBUG_OUTHEX32, (l4_uint64_t)number >> 32);
162 
163  __kdebug_op_1(L4_KDEBUG_OUTHEX32, number);
164 }
165 
166 L4_INLINE void outhex64(l4_uint64_t number)
167 {
168  __kdebug_op_1(L4_KDEBUG_OUTHEX32, number >> 32);
169  __kdebug_op_1(L4_KDEBUG_OUTHEX32, number);
170 }
171 
172 L4_INLINE void outhex32(l4_uint32_t number)
173 {
174  __kdebug_op_1(L4_KDEBUG_OUTHEX32, number);
175 }
176 
177 L4_INLINE void outhex20(l4_uint32_t number)
178 {
179  __kdebug_op_1(L4_KDEBUG_OUTHEX20, number);
180 }
181 
182 L4_INLINE void outhex16(l4_uint16_t number)
183 {
184  __kdebug_op_1(L4_KDEBUG_OUTHEX16, number);
185 }
186 
187 L4_INLINE void outhex12(l4_uint16_t number)
188 {
189  __kdebug_op_1(L4_KDEBUG_OUTHEX12, number);
190 }
191 
192 L4_INLINE void outhex8(l4_uint8_t number)
193 {
194  __kdebug_op_1(L4_KDEBUG_OUTHEX8, number);
195 }
196 
197 L4_INLINE void outdec(l4_mword_t number)
198 {
199  __kdebug_op_1(L4_KDEBUG_OUTDEC, number);
200 }
201 
202 #endif //__KDEBUG_H__
L4 compiler related defines.
#define L4_NOTHROW
Mark a function declaration and definition as never throwing an exception.
Definition: compiler.h:186
unsigned long l4_umword_t
Unsigned machine word.
Definition: l4int.h:51
signed long l4_mword_t
Signed machine word.
Definition: l4int.h:48
unsigned char l4_uint8_t
Unsigned 8bit value.
Definition: l4int.h:36
unsigned int l4_uint32_t
Unsigned 32bit value.
Definition: l4int.h:40
unsigned short int l4_uint16_t
Unsigned 16bit value.
Definition: l4int.h:38
unsigned long long l4_uint64_t
Unsigned 64bit value.
Definition: l4int.h:42
@ L4_BASE_DEBUGGER_CAP
Capability selector for the debugger cap.
Definition: consts.h:282
l4_msgtag_t l4_ipc_call(l4_cap_idx_t object, l4_utcb_t *utcb, l4_msgtag_t tag, l4_timeout_t timeout) L4_NOTHROW
Object call (usual invocation).
Definition: ipc.h:463
unsigned l4_bytes_to_mwords(unsigned size) L4_NOTHROW
Determine how many machine words (l4_umword_t) are required to store a buffer of 'size' bytes.
Definition: consts.h:412
l4_msgtag_t l4_msgtag(long label, unsigned words, unsigned items, unsigned flags) L4_NOTHROW
Create a message tag from the specified values.
Definition: types.h:408
@ L4_PROTO_DEBUGGER
Protocol ID for the debugger.
Definition: types.h:75
struct l4_utcb_t l4_utcb_t
Opaque type for the UTCB.
Definition: utcb.h:67
l4_utcb_t * l4_utcb(void) L4_NOTHROW L4_PURE
Get the UTCB address.
Definition: utcb.h:340
Message tag data structure.
Definition: types.h:160
Encapsulation of the message-register block in the UTCB.
Definition: utcb.h:79
l4_umword_t mr[L4_UTCB_GENERIC_DATA_SIZE]
Message registers.
Definition: utcb.h:80