1 /*
2  * (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
3  *               Alexander Warg <warg@os.inf.tu-dresden.de>
4  *     economic rights: Technische Universität Dresden (Germany)
5  *
6  * This file is part of TUD:OS and distributed under the terms of the
7  * GNU General Public License 2.
8  * Please see the COPYING-GPL-2 file for details.
9  */
10 /* startup stuff */
11 
12 /* it should be possible to throw away the text/data/bss of the object
13    file resulting from this source -- so, we don't define here
14    anything we could still use at a later time.  instead, globals are
15    defined in globals.c */
16 
17 #include <l4/sys/ipc.h>
18 
19 #include <l4/cxx/iostream>
20 
21 #include "globals.h"
22 #include "mem_man.h"
23 #include "page_alloc.h"
24 #include "memmap.h"
25 #include "init.h"
26 #include "init_mem.h"
27 #include "ioports.h"
28 #include "mem_man_test.h"
29 #include <l4/sys/debugger.h>
30 
31 /* started as the L4 sigma0 task from crt0.S */
32 
33 extern "C" void _init(void);
34 
35 typedef void Ctor();
36 extern Ctor *__preinit_array_start[];
37 extern Ctor *__preinit_array_end [];
38 extern Ctor *__init_array_start [];
39 extern Ctor *__init_array_end [];
40 
call_init_array(Ctor ** start,Ctor ** end)41 static void call_init_array(Ctor **start, Ctor **end)
42 {
43   for (; start < end; ++start)
44     if (*start)
45       (*start)();
46 }
47 
48 void
init(l4_kernel_info_t * info)49 init(l4_kernel_info_t *info)
50 {
51   call_init_array(__preinit_array_start, __preinit_array_end);
52   _init();
53   call_init_array(__init_array_start, __init_array_end);
54 
55   l4_info = info;
56 
57   L4::cout << PROG_NAME": Hello!\n";
58   L4::cout << "  KIP @ " << info << '\n';
59 
60   l4_debugger_set_object_name(L4_BASE_TASK_CAP,    "sigma0");
61   l4_debugger_set_object_name(L4_BASE_FACTORY_CAP, "root factory");
62   l4_debugger_set_object_name(L4_BASE_THREAD_CAP,  "sigma0");
63 
64   Page_alloc_base::init();
65 
66   init_memory(info);
67   init_io_ports();
68 
69   //mem_man_test();
70 
71   L4::cout << "  allocated " << Page_alloc_base::total()/1024
72            << "KB for maintenance structures\n";
73 
74   if (debug_memory_maps)
75     dump_all();
76 
77   /* now start the memory manager */
78   pager();
79 }
80