uhci: get device descriptor, mem_alloc: aligned addresses
[quarnos.git] / manes / start.cpp
blob8b1bb45fcf26370e2ded2de94c1af19fde0297d0
1 /* Quarn OS
3 * Startup code
5 * Copyright (C) 2008-2009 Pawel Dziepak
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 /* This file consist of functions that are called in order to run Manes. It
25 * includes initialization of hardware and internal kernel data structures.
26 * After this operation kernel can change to the standard way of working witch
27 * preemption, resources, actors and so on.
30 /**
31 * @mainpage Quarn OS Documentation
32 * @image html http://quarnos.org/img/qoslogo.png
34 #if __GNUC__ < 4
35 #error Quarn OS is needed to be compiled on GCC 4 or later.
36 #endif
38 #include "runtime.h"
39 #include "services/kernel_state.h"
40 #include "manec.h"
41 #include "manei.h"
42 #include "resources/stream.h"
43 #include "arch/low/general.h"
44 #include "resources/block.h"
46 #include "arch/low/launch.h"
47 #include "arch/low/pci.h"
48 #include "arch/low/console.h"
49 #include "resources/fs.h"
50 #include "services/logger.h"
51 #include "resources/bus.h"
52 #include "resources/fat.h"
53 #include "resources/pci.h"
54 #include "libs/delegate.h"
55 #include "libs/string.h"
56 #include "modules/loader.h"
57 #include "resources/file.h"
58 #include "services/unmangler.h"
59 #include "actors/actor.h"
60 #include "actors/director.h"
61 #include "modules/module.h"
62 #include "resources/pio.h"
63 #include "libs/setjmp.h"
64 #include "services/stats.h"
65 #include "libs/pointer.h"
66 #include "typeinfo"
68 using namespace services;
69 using namespace modules;
70 using namespace resources;
71 using namespace manes;
72 using namespace arch;
73 using namespace actors;
75 void next();
77 void *operator new(unsigned int, int);
79 extern "C" void jump_v86();
80 #include "arch/low/pit.h"
81 #if USE_MULTIBOOT == CONF_YES
82 extern "C" void start() {
83 #else
84 extern "C" void _start() {
85 #endif
86 delegate<void,const char> del;
87 /* Prepare to execute C++ code */
88 runtime_start();
90 /* Launch Managed Execution System */
91 manei::launch_manes();
93 manec::connect_manes((component*)manei::get_comp());
95 p<manager> main = manec::get();
97 main->initialize();
99 /* Run low-level procedures */
100 arch::launch();
102 /* Register creators */
103 manei::register_creators();
105 /* Register built in types */
106 manei::register_builtin_types();
108 /* Run creators */
109 manei::animate_creators();
111 /* Initialize clock */
112 arch::pit_init();
114 /* Manes is ready to use */
115 p<logger> log = main->get<logger>("/early_logger");
117 jmp_buf ab;
118 if (!setjmp(ab)) {
119 log->print("OK.\nStarting Quarn OS...",logger::log_critical);
120 longjmp(ab,1);
123 p<stream> tty;
125 /*try {
126 throw 5;
127 tty = main->get<stream>("/keybscr");
129 catch (int) {
131 log->print("cannot create tty", services::logger::log_info);
132 while(1);
135 p<stats> stat = main->get<stats>("/stats");
137 p<logger> tlog = main->get<logger>("/tty_logger");
138 tlog->print((string)"EFC caught so far " + stat->get_value(services::stats::efc_calls) + " function calls.", services::logger::log_info);
140 p<bus> mainbus = main->get<bus>("/isa");
141 tlog->print((string)"\nFound ISA devices: " + mainbus->get_count(), services::logger::log_info);
143 p<bus> pbus = main->get<bus>("/pci");
144 tlog->print((string)"\nFound PCI devices: " + pbus->get_count(), services::logger::log_info);
146 tlog->print((string)"\nAvailable memory: " + manec::state()->get_memory_size() / 1024 / 1024 + " MB\n\n", services::logger::log_info);
148 p<block> floppy = main->get<block>("/fdc");
149 p<fs> fs_floppy = main->get<fs>("/fat");
150 fs_floppy->mount(floppy);
151 p<file> temp = main->get_component(component_name((type_name)"file","authors"))->get<file>();
153 tlog->print((string)(const char*)((const string)*temp), services::logger::log_warning);
155 p<modules::module> mod = main->get_component(component_name((type_name)"loader",0))->get<loader>()->get_component(component_name((type_name)"module","rs232.ko"))->get<modules::module>();
156 mod->place(module::module_kernel_space);
157 mod->get_delegate()();
159 u16 *com1_base_port = (u16*)0x400;
160 resources::device::isa_address com1_addr;
161 com1_addr.irq = 0x24;
162 com1_addr.ioport_base = (int)*com1_base_port;
164 // stream *serial = dynamic_cast<stream*>(main->new_component((type_name)"rs232")->get<implementation>());
165 // serial->init_device(com1_addr);
167 p<unmangler> unman = main->get<unmangler>("/unmangler");
168 p<implementation> iimpl = unman.cast<implementation>();
169 iimpl->get_parent();
171 // string name = unman->unmangle(typeid(*serial).name());
172 //serial->write_bytes(name, name.length());
174 delegate<void> del_next;
175 del_next.function(next);
177 //jump_v86();
179 p<director> sched = main->get_component(component_name((type_name)"director",0))->get<director>();
180 p<actor> proc = sched->new_component((type_name)"actor")->get<actor>();
181 proc->set(del_next);
182 /* Benchmark
183 for (int i = 0; i < 10000; i++)
184 for (int j = 0; j < 1000; j++)
185 stat->get_value(stats::ks_timeticks);
187 tlog->print((string)"EFC caught so far " + stat->get_value(services::stats::efc_calls) + " function calls.\n", services::logger::log_info);
189 //string ss = stat->full_stats();
190 //serial->write_bytes(ss, ss.length());
192 sched->launch(proc);
195 void next() {
196 p<manager> main = manec::get();
198 p<modules::module> mod = main->get_component(component_name((type_name)"module","shell.ko"))->get<module>();
199 mod->place(module::module_user_space);
201 p<director> sched = main->get_component(component_name((type_name)"director",0))->get<director>();
202 p<actor> proc = sched->new_component((type_name)"actor")->get<actor>();
203 proc->set(mod->get_delegate());
204 sched->start(proc);
206 /* PIO */
207 /* stream *ttyS = main->get<stream>("/rs232");
209 pio *str = main->get<pio>("/pio");
211 char buffer[] = "\n\xdHello World!!!";
212 str->set_dep(ttyS);
213 str->send_packet(buffer,strlen(buffer));
214 str->set_speed(3);
215 delegate<void> nul;*/
216 // str->start(false, nul);
218 while (1) __asm__("hlt");