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  (len + sizeof(l4_umword_t) -1)
80  / sizeof(l4_umword_t) + 2,
81  0, 0),
82  L4_IPC_NEVER);
83  __builtin_memcpy(mr, &store, sizeof(*mr));
84  return res;
85 }
86 
87 L4_INLINE l4_msgtag_t
88 __kdebug_3_text(unsigned op, char const *text, unsigned len,
90 {
91  l4_msg_regs_t store;
92  l4_msgtag_t res;
93  l4_utcb_t *u = l4_utcb();
94  l4_msg_regs_t *mr = l4_utcb_mr_u(u);
95 
96  if (len > (sizeof(store) - (5 * sizeof(l4_umword_t))))
97  len = sizeof(store) - (5 * sizeof(l4_umword_t));
98 
99  __builtin_memcpy(&store, mr, sizeof(store));
100  mr->mr[0] = op;
101  mr->mr[1] = v1;
102  mr->mr[2] = v2;
103  mr->mr[3] = v3;
104  mr->mr[4] = len;
105  __builtin_memcpy(&mr->mr[5], text, len);
108  (len + sizeof(l4_umword_t) -1)
109  / sizeof(l4_umword_t) + 5,
110  0, 0),
111  L4_IPC_NEVER);
112  __builtin_memcpy(mr, &store, sizeof(*mr));
113  return res;
114 }
115 
116 L4_INLINE l4_msgtag_t
117 __kdebug_op_1(unsigned op, l4_mword_t val) L4_NOTHROW
118 {
119  l4_umword_t m[2];
120  l4_msgtag_t res;
121  l4_utcb_t *u = l4_utcb();
122  l4_msg_regs_t *mr = l4_utcb_mr_u(u);
123 
124  m[0] = mr->mr[0];
125  m[1] = mr->mr[1];
126  mr->mr[0] = op;
127  mr->mr[1] = val;
129  l4_msgtag(L4_PROTO_DEBUGGER, 2, 0, 0),
130  L4_IPC_NEVER);
131  mr->mr[0] = m[0];
132  mr->mr[1] = m[1];
133  return res;
134 }
135 
136 L4_INLINE void enter_kdebug(char const *text) L4_NOTHROW
137 {
138  /* special case, enter without any text and use of the UTCB */
139  if (!text)
140  {
142  l4_msgtag(L4_PROTO_DEBUGGER, 0, 0, 0),
143  L4_IPC_NEVER);
144  return;
145  }
146 
147  __kdebug_text(L4_KDEBUG_ENTER, text, __builtin_strlen(text));
148 }
149 
150 L4_INLINE void outnstring(char const *text, unsigned len)
151 { __kdebug_text(L4_KDEBUG_OUTNSTRING, text, len); }
152 
153 L4_INLINE void outstring(char const *text)
154 { outnstring(text, __builtin_strlen(text)); }
155 
156 
157 L4_INLINE void outchar(char c)
158 {
159  __kdebug_op_1(L4_KDEBUG_OUTCHAR, c);
160 }
161 
162 L4_INLINE void outhex32(l4_uint32_t number)
163 {
164  __kdebug_op_1(L4_KDEBUG_OUTHEX32, number);
165 }
166 
167 L4_INLINE void outhex20(l4_uint32_t number)
168 {
169  __kdebug_op_1(L4_KDEBUG_OUTHEX20, number);
170 }
171 
172 L4_INLINE void outhex16(l4_uint16_t number)
173 {
174  __kdebug_op_1(L4_KDEBUG_OUTHEX16, number);
175 }
176 
177 L4_INLINE void outhex12(l4_uint16_t number)
178 {
179  __kdebug_op_1(L4_KDEBUG_OUTHEX12, number);
180 }
181 
182 L4_INLINE void outhex8(l4_uint8_t number)
183 {
184  __kdebug_op_1(L4_KDEBUG_OUTHEX8, number);
185 }
186 
187 L4_INLINE void outdec(l4_mword_t number)
188 {
189  __kdebug_op_1(L4_KDEBUG_OUTDEC, number);
190 }
191 
192 #endif //__KDEBUG_H__
Encapsulation of the message-register block in the UTCB.
Definition: utcb.h:78
Protocol ID for the debugger.
Definition: types.h:75
unsigned short int l4_uint16_t
Unsigned 16bit value.
Definition: l4int.h:38
signed long l4_mword_t
Signed machine word.
Definition: l4int.h:49
l4_umword_t mr[L4_UTCB_GENERIC_DATA_SIZE]
Message registers.
Definition: utcb.h:80
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:445
struct l4_utcb_t l4_utcb_t
Opaque type for the UTCB.
Definition: utcb.h:67
#define L4_IPC_NEVER
never timeout
Definition: __timeout.h:80
L4 compiler related defines.
Capability selector for the debugger cap.
Definition: consts.h:282
unsigned long l4_umword_t
Unsigned machine word.
Definition: l4int.h:52
l4_utcb_t * l4_utcb(void) L4_NOTHROW L4_PURE
Get the UTCB address.
Definition: utcb.h:340
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
unsigned char l4_uint8_t
Unsigned 8bit value.
Definition: l4int.h:36
Message tag data structure.
Definition: types.h:159
unsigned int l4_uint32_t
Unsigned 32bit value.
Definition: l4int.h:40
#define L4_NOTHROW
Mark a function declaration and definition as never throwing an exception.
Definition: compiler.h:185