2 * \file bootstrap/server/src/libc_support.c
3 * \brief Support for C library
6 * \author Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
7 * Frank Mehnert <fm3@os.inf.tu-dresden.de> */
10 * (c) 2005-2009 Author(s)
11 * economic rights: Technische Universität Dresden (Germany)
13 * This file is part of TUD:OS and distributed under the terms of the
14 * GNU General Public License 2.
15 * Please see the COPYING-GPL-2 file for details.
25 #include <sys/types.h>
28 #include <l4/cxx/basic_ostream>
32 Platform_base *Platform_base::platform;
34 static L4::Uart *stdio_uart;
37 { return stdio_uart; }
39 void set_stdio_uart(L4::Uart *uart)
40 { stdio_uart = uart; }
43 inline void *operator new (size_t, void *p) { return p; }
47 class BootstrapIOBackend : public L4::IOBackend
50 void write(char const *str, unsigned len);
53 void BootstrapIOBackend::write(char const *str, unsigned len)
55 ::write(STDOUT_FILENO, str, len);
61 typedef char Fake_iobackend[sizeof(BootstrapIOBackend)]
62 __attribute__((aligned(__alignof__(BootstrapIOBackend))));
63 typedef char Fake_ostream[sizeof(BasicOStream)]
64 __attribute__((aligned(__alignof__(BasicOStream))));
69 static Fake_iobackend _iob;
74 static int _initialized;
78 BootstrapIOBackend *iob = new (&_iob) BootstrapIOBackend();
79 new (&cerr) BasicOStream(iob);
80 new (&cout) BasicOStream(iob);
87 static void call_ctors(Ctor **start, Ctor **end)
89 for (; start < end; ++start)
97 extern Ctor *__CTORS_BEGIN[];
98 extern Ctor *__CTORS_END[];
99 extern Ctor *__init_array_start[];
100 extern Ctor *__init_array_end[];
101 extern Ctor *__preinit_array_start[];
102 extern Ctor *__preinit_array_end[];
104 call_ctors(__preinit_array_start, __preinit_array_end);
105 call_ctors(__CTORS_BEGIN, __CTORS_END);
106 call_ctors(__init_array_start, __init_array_end);
110 void exit(int c) throw()
115 void (*__exit_cleanup) (int) = 0;
117 extern "C" void __attribute__((noreturn))
118 __assert(const char *, const char *, int, register const char *);
120 extern "C" void __attribute__((noreturn))
121 __assert(const char *assertion, const char * filename,
122 int linenumber, register const char * function)
124 printf("%s:%d: %s: Assertion `%s' failed.\n",
127 ((function == NULL) ? "?function?" : function),
136 write(int fd, const void *buf, size_t count)
141 if (fd == STDOUT_FILENO || fd == STDERR_FILENO)
143 char *b = (char *)buf;
149 uart()->write("\r", 1);
150 uart()->write(&c, 1);
169 c = uart()->get_char(0);
174 off_t lseek(int /*fd*/, off_t /*offset*/, int /*whence*/)
179 void *__dso_handle = &__dso_handle;
181 extern "C" void reboot(void) __attribute__((noreturn));
184 void reboot_arch() __attribute__((noreturn));
188 extern "C" void __attribute__((noreturn))
191 printf("\n\033[1mKey press reboots...\033[m\n");
193 printf("Rebooting.\n\n");
205 panic(const char *fmt, ...)