]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/l4sys/include/ARCH-ppc32/kdebug.h
83d52c7beee8ae1e73b07b1a319169031851db23
[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 EXTERN_C long int
88 l4_atomic_add(volatile long int* mem, long int offset) L4_NOTHROW;
89
90 EXTERN_C long int
91 l4_atomic_cmpxchg(volatile long int* mem, long int oldval, long int newval) L4_NOTHROW;
92
93 EXTERN_C long int
94 l4_atomic_xchg(volatile long int* mem, long int newval) L4_NOTHROW;
95
96 L4_INLINE int
97 l4_irq_enabled(void);
98
99 L4_INLINE void __touch_ro(const char *x, unsigned len);
100
101 L4_INLINE unsigned long
102 __kdebug_param(unsigned long nr, unsigned long p1, unsigned long p2);
103
104 L4_INLINE unsigned long
105 __kdebug_param_5(unsigned long nr, unsigned long p1, unsigned long p2,
106                  unsigned long p3, unsigned long p4, unsigned long p5);
107
108 L4_INLINE
109 unsigned long
110 __kdebug_param(unsigned long nr, unsigned long p1, unsigned long p2)
111 {
112   register unsigned long r3 asm("r3") = (nr) | (1 << 31);
113   register unsigned long r4 asm("r4") = (p1);
114   register unsigned long r5 asm("r5") = (p2);
115   asm volatile ( " bla  %1 \n"
116                  : "=r" (r4)
117                  : "i" (L4_SYSCALL_ENTER_KDEBUG),
118                    "0" (r4), "r" (r3), "r" (r5)
119                  : "lr"
120                );
121   return r4;
122 }
123
124 L4_INLINE
125 unsigned long
126 __kdebug_param_5(unsigned long nr, unsigned long p1, unsigned long p2,
127                  unsigned long p3, unsigned long p4, unsigned long p5)
128 {
129   register unsigned long r3 asm("r3") = (nr) | (1 << 31);
130   register unsigned long r4 asm("r4") = (p1);
131   register unsigned long r5 asm("r5") = (p2);
132   register unsigned long r6 asm("r6") = (p3);
133   register unsigned long r7 asm("r7") = (p4);
134   register unsigned long r8 asm("r8") = (p5);
135
136   asm volatile ( " bla %1 \n"
137                  : "=r" (r4)
138                  : "i" (L4_SYSCALL_ENTER_KDEBUG),
139                    "0" (r4), "r" (r3), "r" (r5),
140                    "r" (r6), "r" (r7), "r" (r8)
141                  : "lr"
142                );
143   return r4;
144 }
145
146 L4_INLINE void
147 __touch_ro(const char *x, unsigned len)
148 {
149    volatile const char *sptr, *eptr;
150    sptr = (const char*)((unsigned)x & L4_PAGEMASK);
151    eptr = (const char*)(((unsigned)x + len -1) & L4_PAGEMASK);
152
153    for(;sptr <= eptr; sptr += L4_PAGESIZE)
154      (void)(*sptr);
155 }
156
157 L4_INLINE void
158 outnstring(const char* x, unsigned len)
159 {
160   __touch_ro(x, len);
161   __kdebug_param(3, (unsigned long)x, (unsigned long)len);
162 }
163
164 L4_INLINE void
165 outstring(const char *text)
166 {
167   unsigned i = 0;
168   while(text[i++]) ;
169   outnstring(text, i);
170 }
171
172 L4_INLINE void
173 outchar(char c)
174 {
175   __kdebug_param(1, (unsigned long)c, 0);
176 }
177
178 L4_INLINE void
179 outdec(int number)
180 {
181   __kdebug_param(4, (unsigned long)number, 0);
182 }
183
184 L4_INLINE void
185 outhex32(int number)
186 {
187   __kdebug_param(5, (unsigned long)number, 0);
188 }
189
190 L4_INLINE void
191 outhex20(int number)
192 {
193   __kdebug_param(6, (unsigned long)number, 0);
194 }
195
196 L4_INLINE void
197 outhex16(int number)
198 {
199   __kdebug_param(7, (unsigned long)number, 0);
200 }
201
202 L4_INLINE void
203 outhex12(int number)
204 {
205   __kdebug_param(8, (unsigned long)number, 0);
206 }
207
208 L4_INLINE void
209 outhex8(int number)
210 {
211   __kdebug_param(9, (unsigned long)number, 0);
212 }
213
214 L4_INLINE void
215 kd_display(char *text)
216 {
217   outstring(text);
218 }
219
220 L4_INLINE int
221 l4kd_inchar(void)
222 {
223   return __kdebug_param(0xd, 0, 0);
224 }
225
226 L4_INLINE void
227 l4_sys_cli(void)
228 {
229   __kdebug_param(0x32, 0, 0);
230 }
231
232 L4_INLINE void
233 l4_sys_sti(void)
234 {
235   __kdebug_param(0x33, 0, 0);
236 }
237
238 L4_INLINE void
239 l4_kdebug_imb(void)
240 {
241  // __KDEBUG_ARM_PARAM_0(0x3f);
242 }
243 L4_INLINE int
244 l4_irq_enabled(void)
245 {
246   return __kdebug_param(0x34, 0, 0);
247 }
248 #endif //__GNUC__
249
250 #endif /* ! __L4SYS__INCLUDE__ARCH_PPC32__KDEBUG_H__ */