]> 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_kdebug_imb(void);
80
81 L4_INLINE void __touch_ro(const char *x, unsigned len);
82
83 L4_INLINE unsigned long
84 __kdebug_param(unsigned long nr, unsigned long p1, unsigned long p2);
85
86 L4_INLINE unsigned long
87 __kdebug_param_5(unsigned long nr, unsigned long p1, unsigned long p2,
88                  unsigned long p3, unsigned long p4, unsigned long p5);
89
90 L4_INLINE
91 unsigned long
92 __kdebug_param(unsigned long nr, unsigned long p1, unsigned long p2)
93 {
94   register unsigned long r3 __asm__ ("r3") = (nr) | (1 << 31);
95   register unsigned long r4 __asm__ ("r4") = (p1);
96   register unsigned long r5 __asm__ ("r5") = (p2);
97   asm volatile ( " bla  %1 \n"
98                  : "=r" (r4)
99                  : "i" (L4_SYSCALL_ENTER_KDEBUG),
100                    "0" (r4), "r" (r3), "r" (r5)
101                  : "lr"
102                );
103   return r4;
104 }
105
106 L4_INLINE
107 unsigned long
108 __kdebug_param_5(unsigned long nr, unsigned long p1, unsigned long p2,
109                  unsigned long p3, unsigned long p4, unsigned long p5)
110 {
111   register unsigned long r3 __asm__ ("r3") = (nr) | (1 << 31);
112   register unsigned long r4 __asm__ ("r4") = (p1);
113   register unsigned long r5 __asm__ ("r5") = (p2);
114   register unsigned long r6 __asm__ ("r6") = (p3);
115   register unsigned long r7 __asm__ ("r7") = (p4);
116   register unsigned long r8 __asm__ ("r8") = (p5);
117
118   asm volatile ( " bla %1 \n"
119                  : "=r" (r4)
120                  : "i" (L4_SYSCALL_ENTER_KDEBUG),
121                    "0" (r4), "r" (r3), "r" (r5),
122                    "r" (r6), "r" (r7), "r" (r8)
123                  : "lr"
124                );
125   return r4;
126 }
127
128 L4_INLINE void
129 __touch_ro(const char *x, unsigned len)
130 {
131    volatile const char *sptr, *eptr;
132    sptr = (const char*)((unsigned)x & L4_PAGEMASK);
133    eptr = (const char*)(((unsigned)x + len -1) & L4_PAGEMASK);
134
135    for(;sptr <= eptr; sptr += L4_PAGESIZE)
136      (void)(*sptr);
137 }
138
139 L4_INLINE void
140 outnstring(const char* x, unsigned len)
141 {
142   __touch_ro(x, len);
143   __kdebug_param(3, (unsigned long)x, (unsigned long)len);
144 }
145
146 L4_INLINE void
147 outstring(const char *text)
148 {
149   unsigned i = 0;
150   while(text[i++]) ;
151   outnstring(text, i);
152 }
153
154 L4_INLINE void
155 outchar(char c)
156 {
157   __kdebug_param(1, (unsigned long)c, 0);
158 }
159
160 L4_INLINE void
161 outdec(int number)
162 {
163   __kdebug_param(4, (unsigned long)number, 0);
164 }
165
166 L4_INLINE void
167 outhex32(int number)
168 {
169   __kdebug_param(5, (unsigned long)number, 0);
170 }
171
172 L4_INLINE void
173 outhex20(int number)
174 {
175   __kdebug_param(6, (unsigned long)number, 0);
176 }
177
178 L4_INLINE void
179 outhex16(int number)
180 {
181   __kdebug_param(7, (unsigned long)number, 0);
182 }
183
184 L4_INLINE void
185 outhex12(int number)
186 {
187   __kdebug_param(8, (unsigned long)number, 0);
188 }
189
190 L4_INLINE void
191 outhex8(int number)
192 {
193   __kdebug_param(9, (unsigned long)number, 0);
194 }
195
196 L4_INLINE void
197 kd_display(char *text)
198 {
199   outstring(text);
200 }
201
202 L4_INLINE int
203 l4kd_inchar(void)
204 {
205   return __kdebug_param(0xd, 0, 0);
206 }
207
208 L4_INLINE void
209 l4_kdebug_imb(void)
210 {
211  // __KDEBUG_ARM_PARAM_0(0x3f);
212 }
213 #endif //__GNUC__
214
215 #endif /* ! __L4SYS__INCLUDE__ARCH_PPC32__KDEBUG_H__ */