]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/cxx/lib/be/kdebug/iostream.cc
update
[l4.git] / l4 / pkg / cxx / lib / be / kdebug / iostream.cc
1 /*
2  * (c) 2004-2009 Alexander Warg <warg@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 #include <l4/cxx/basic_ostream>
20 #include <l4/sys/kdebug.h>
21 #include <l4/sys/l4int.h>
22 #include <l4/util/atomic.h>
23
24 #include <stddef.h>
25
26 inline void *operator new (size_t, void *p) { return p; }
27
28 namespace L4 {
29
30   class KdbgIOBackend : public IOBackend
31   {
32   protected:
33     void write(char const *str, unsigned len);
34   };
35
36   void KdbgIOBackend::write(char const *str, unsigned len)
37   {
38     outnstring(str,len);
39   }
40
41   typedef char Fake_iobackend[sizeof(KdbgIOBackend)]
42     __attribute__((aligned(__alignof__(KdbgIOBackend))));
43   typedef char Fake_ostream[sizeof(BasicOStream)]
44     __attribute__((aligned(__alignof__(BasicOStream))));
45
46   Fake_ostream cout;
47   Fake_ostream cerr;
48
49   static Fake_iobackend _iob;
50
51   void iostream_init()
52   {
53     static l4_umword_t _initialized;
54     if (l4util_xchg(&_initialized, 1) == 0)
55       {
56         KdbgIOBackend *iob = new (&_iob) KdbgIOBackend();
57         new (&cerr) BasicOStream(iob);
58         new (&cout) BasicOStream(iob);
59       }
60   }
61
62 };