]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/plr/server/src/main.cc
ace20eb8fd21ef45789683290c1ae429e6087122
[l4.git] / l4 / pkg / plr / server / src / main.cc
1 /*
2  * main.cc --
3  * 
4  *     Main program entry point.
5  *
6  * (c) 2011 Björn Döbel <doebel@os.inf.tu-dresden.de>,
7  *     economic rights: Technische Universität Dresden (Germany)
8  * This file is part of TUD:OS and distributed under the terms of the
9  * GNU General Public License 2.
10  * Please see the COPYING-GPL-2 file for details.
11  */
12
13 #include <cstdio>
14 #include <cstring>
15
16 #include "exceptions"
17 #include "log"
18 #include "manager"
19
20 #include <l4/re/l4aux.h>
21 #include <l4/util/util.h>
22 #include <l4/sys/debugger.h>
23
24 using L4Re::chksys;
25 using L4Re::chkcap;
26
27 Romain::Log::LogLevel Romain::Log::maxLog = Romain::Log::INFO;
28 l4_umword_t Romain::Log::logFlags         = Romain::Log::None;
29 bool Romain::Log::withtime                = false;
30
31 namespace Romain {
32         l4re_aux_t* l4re_aux;
33 }
34
35 static void setup_aux(int argc, const char **argv)
36 {
37         l4_umword_t *auxp = (l4_umword_t*)&argv[argc] + 1;
38         while (*auxp) {
39                 ++auxp;
40         }
41         ++auxp;
42         Romain::l4re_aux = 0;
43         while (*auxp) {
44                 if (*auxp == 0xf0) {
45                         Romain::l4re_aux = (l4re_aux_t*)auxp[1];
46                 }
47                 auxp += 2;
48         }
49 }
50
51 namespace Romain {
52 Romain::InstanceManager *_the_instance_manager = NULL;
53 }
54
55 static int _main(int argc, char const **argv)
56 {
57         (void)argc; (void)argv;
58         INFO() << "FILE: " << argv[1];
59
60         setup_aux(argc, argv);
61
62         Romain::_the_instance_manager = new Romain::InstanceManager(argc-1, &argv[1]);
63         Romain::_the_instance_manager->create_instances();
64         Romain::_the_instance_manager->run_instances();
65
66         l4_sleep_forever();
67
68         return 0;
69 }
70
71
72 static void sanity_check_cmdline(int argc, char const **argv)
73 {
74         (void)argv;
75         _check( argc < 2, "No file name given.");
76 }
77
78
79 int main(int argc, char const**argv)
80 {
81         INFO() << std::hex << &argc;
82         INFO() << "startup";
83         int err = -1;
84         try {
85                 DEBUG() << "argc " << argc;
86                 sanity_check_cmdline(argc, argv);
87                 err = _main(argc, argv);
88         }
89         catch (Argument_error &e) {
90                 std::cerr << "Argument error: " << e.str() << "\n";
91         }
92         catch (L4::Runtime_error& e) {
93                 std::cerr << "Uncaught exception: " << e.str() << "\n";
94         }
95         catch (...) {
96                 std::cerr << "FATAL uncaught exception of unknown type\n";
97         }
98         std::cerr << "Terminating.\n";
99         return err;
100 }