]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/l4sys/include/ARCH-ppc32/kdebug.h
update
[l4.git] / l4 / pkg / l4sys / include / ARCH-ppc32 / 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 #ifndef __L4SYS__INCLUDE__ARCH_PPC32__KDEBUG_H__
19 #define __L4SYS__INCLUDE__ARCH_PPC32__KDEBUG_H__
20
21 #include <l4/sys/compiler.h>
22 #include <l4/sys/consts.h>
23 #ifdef __GNUC__
24
25 #ifndef L4_SYSCALL_MAGIC_OFFSET
26 #  define L4_SYSCALL_MAGIC_OFFSET       8
27 #endif
28 #define L4_SYSCALL_ENTER_KDEBUG         (-0x00000020-L4_SYSCALL_MAGIC_OFFSET)
29
30
31 #define enter_kdebug(text...)                   \
32 __asm__ __volatile__ (                          \
33     "   mr      %%r3, %1        \n"             \
34     "   bla     %0              \n"             \
35     "   b       1f              \n"             \
36     "   .ascii  \"" text "\"    \n"             \
37     "   .byte   0               \n"             \
38     "   .align  4               \n"             \
39     "1:                         \n"             \
40     :                                           \
41     : "i" (L4_SYSCALL_ENTER_KDEBUG),            \
42       "r" (1 << 30)                             \
43     : "lr", "r3")
44
45 L4_INLINE void
46 outnstring(const char* x, unsigned len);
47
48 L4_INLINE void
49 outstring(const char *text);
50
51 L4_INLINE void
52 outchar(char c);
53
54 L4_INLINE void
55 outdec(int number);
56
57 L4_INLINE void
58 outhex32(int number);
59
60 L4_INLINE void
61 outhex20(int number);
62
63 L4_INLINE void
64 outhex16(int number);
65
66 L4_INLINE void
67 outhex12(int number);
68
69 L4_INLINE void
70 outhex8(int number);
71
72 L4_INLINE void
73 kd_display(char *text);
74
75 L4_INLINE int
76 l4kd_inchar(void);
77
78 L4_INLINE void
79 l4_sys_cli(void);
80
81 L4_INLINE void
82 l4_sys_sti(void);
83
84 L4_INLINE void
85 l4_kdebug_imb(void);
86
87 L4_INLINE int
88 l4_irq_enabled(void);
89
90 L4_INLINE void __touch_ro(const char *x, unsigned len);
91
92 L4_INLINE unsigned long
93 __kdebug_param(unsigned long nr, unsigned long p1, unsigned long p2);
94
95 L4_INLINE unsigned long
96 __kdebug_param_5(unsigned long nr, unsigned long p1, unsigned long p2,
97                  unsigned long p3, unsigned long p4, unsigned long p5);
98
99 L4_INLINE
100 unsigned long
101 __kdebug_param(unsigned long nr, unsigned long p1, unsigned long p2)
102 {
103   register unsigned long r3 asm("r3") = (nr) | (1 << 31);
104   register unsigned long r4 asm("r4") = (p1);
105   register unsigned long r5 asm("r5") = (p2);
106   asm volatile ( " bla  %1 \n"
107                  : "=r" (r4)
108                  : "i" (L4_SYSCALL_ENTER_KDEBUG),
109                    "0" (r4), "r" (r3), "r" (r5)
110                  : "lr"
111                );
112   return r4;
113 }
114
115 L4_INLINE
116 unsigned long
117 __kdebug_param_5(unsigned long nr, unsigned long p1, unsigned long p2,
118                  unsigned long p3, unsigned long p4, unsigned long p5)
119 {
120   register unsigned long r3 asm("r3") = (nr) | (1 << 31);
121   register unsigned long r4 asm("r4") = (p1);
122   register unsigned long r5 asm("r5") = (p2);
123   register unsigned long r6 asm("r6") = (p3);
124   register unsigned long r7 asm("r7") = (p4);
125   register unsigned long r8 asm("r8") = (p5);
126
127   asm volatile ( " bla %1 \n"
128                  : "=r" (r4)
129                  : "i" (L4_SYSCALL_ENTER_KDEBUG),
130                    "0" (r4), "r" (r3), "r" (r5),
131                    "r" (r6), "r" (r7), "r" (r8)
132                  : "lr"
133                );
134   return r4;
135 }
136
137 L4_INLINE void
138 __touch_ro(const char *x, unsigned len)
139 {
140    volatile const char *sptr, *eptr;
141    sptr = (const char*)((unsigned)x & L4_PAGEMASK);
142    eptr = (const char*)(((unsigned)x + len -1) & L4_PAGEMASK);
143
144    for(;sptr <= eptr; sptr += L4_PAGESIZE)
145      (void)(*sptr);
146 }
147
148 L4_INLINE void
149 outnstring(const char* x, unsigned len)
150 {
151   __touch_ro(x, len);
152   __kdebug_param(3, (unsigned long)x, (unsigned long)len);
153 }
154
155 L4_INLINE void
156 outstring(const char *text)
157 {
158   unsigned i = 0;
159   while(text[i++]) ;
160   outnstring(text, i);
161 }
162
163 L4_INLINE void
164 outchar(char c)
165 {
166   __kdebug_param(1, (unsigned long)c, 0);
167 }
168
169 L4_INLINE void
170 outdec(int number)
171 {
172   __kdebug_param(4, (unsigned long)number, 0);
173 }
174
175 L4_INLINE void
176 outhex32(int number)
177 {
178   __kdebug_param(5, (unsigned long)number, 0);
179 }
180
181 L4_INLINE void
182 outhex20(int number)
183 {
184   __kdebug_param(6, (unsigned long)number, 0);
185 }
186
187 L4_INLINE void
188 outhex16(int number)
189 {
190   __kdebug_param(7, (unsigned long)number, 0);
191 }
192
193 L4_INLINE void
194 outhex12(int number)
195 {
196   __kdebug_param(8, (unsigned long)number, 0);
197 }
198
199 L4_INLINE void
200 outhex8(int number)
201 {
202   __kdebug_param(9, (unsigned long)number, 0);
203 }
204
205 L4_INLINE void
206 kd_display(char *text)
207 {
208   outstring(text);
209 }
210
211 L4_INLINE int
212 l4kd_inchar(void)
213 {
214   return __kdebug_param(0xd, 0, 0);
215 }
216
217 L4_INLINE void
218 l4_sys_cli(void)
219 {
220   __kdebug_param(0x32, 0, 0);
221 }
222
223 L4_INLINE void
224 l4_sys_sti(void)
225 {
226   __kdebug_param(0x33, 0, 0);
227 }
228
229 L4_INLINE void
230 l4_kdebug_imb(void)
231 {
232  // __KDEBUG_ARM_PARAM_0(0x3f);
233 }
234 L4_INLINE int
235 l4_irq_enabled(void)
236 {
237   return __kdebug_param(0x34, 0, 0);
238 }
239 #endif //__GNUC__
240
241 #endif /* ! __L4SYS__INCLUDE__ARCH_PPC32__KDEBUG_H__ */