net: data reception system, fixed bugs in rtl8139
[quarnos.git] / manes / start.cpp
blob30f1352fdc1d5046f66bda4acdf658cd6a800bad
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 "resources/fs.h"
48 #include "services/logger.h"
49 #include "resources/bus.h"
50 #include "resources/net/ethernet.h"
51 #include "resources/fat.h"
52 #include "resources/pci.h"
53 #include "resources/isa.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 "resources/keybscr.h"
67 #include "typeinfo"
68 #include "resources/ne2k.h"
69 #include "resources/net/ipv4.h"
70 #include "resources/net/arp.h"
71 #include "resources/net/udp.h"
72 #include "resources/net/icmp.h"
74 using namespace services;
75 using namespace modules;
76 using namespace resources;
77 using namespace manes;
78 using namespace arch;
79 using namespace actors;
80 using namespace net;
82 void next();
84 void *operator new(unsigned int, int);
86 extern char *comp_vtable;
87 extern p<nic> faar;
89 extern "C" void jump_v86();
90 #include "arch/low/pit.h"
91 #if USE_MULTIBOOT == CONF_YES
92 extern "C" void start() {
93 #else
94 extern "C" void _start() {
95 #endif
96 delegate<void,const char> del;
98 /* Prepare to execute C++ code */
99 runtime_start();
101 /* Launch Managed Execution System */
102 manei::get()->launch_manes();
104 manec::get()->connect_manes(manei::get()->get_root());
106 p<manec> main = manec::get();
108 /* Abstract types */
109 main->register_abstract("device", "none");
110 main->register_abstract("storage", "device");
111 main->register_abstract("console", "device");
112 main->register_abstract("nic", "device");
114 main->register_abstract("allocator", "none");
116 main->register_abstract("service", "none");
118 /* Run low-level procedures */
119 arch::launch();
121 /* Register creators */
122 manei::get()->register_creators();
124 /* Register built in types */
125 manei::get()->register_builtin_types();
127 /* Run creators */
128 manei::get()->animate_creators();
130 /* Initialize clock */
131 arch::pit_init();
133 /* Manes is ready to use */
134 p<logger> log = main->get<logger>("/early_logger");
136 jmp_buf ab;
137 if (!setjmp(ab)) {
138 log->print("OK.\nStarting Quarn OS...",logger::log_critical);
139 longjmp(ab,1);
142 p<stream> tty;
144 try {
145 // throw 5;
146 tty = main->get<stream>("/keybscr");
148 catch (char) {
149 while(1);
151 catch (int) {
153 log->print("cannot create tty", services::logger::log_info);
154 //while(1);
157 p<stats> stat = main->get<stats>("/stats");
159 p<logger> tlog = main->get<logger>("/tty_logger");
160 tlog->print((string)"\n\nEFC caught so far " + stat->get_value(services::stats::efc_calls) + " function calls.", services::logger::log_info);
162 p<bus> mainbus = main->get<bus>("/isa");
163 tlog->print((string)"\nFound ISA devices: " + mainbus->get_count(), services::logger::log_info);
165 p<bus> pbus = main->get<bus>("/pci");
166 tlog->print((string)"\nFound PCI devices: " + pbus->get_count(), services::logger::log_info);
168 tlog->print((string)"\nAvailable memory: " + manec::get()->state()->get_memory_size() / 1024 / 1024 + " MB\n\n", services::logger::log_info);
170 if (faar.valid()) {
171 ethernet eth;
172 eth.set_nic(faar);
174 ipv4 ip;
175 ip.set_link_layer(&eth);
176 ip.configure_ipv4(ipv4_addr::from_le(192 << 24 | 168 << 16 | 1 << 8 | 50), ipv4_addr::from_le(255 << 24 | 255 << 16 | 255 << 8), ipv4_addr::from_le(192 << 24 | 168 << 16 | 1 << 8 | 1));
178 udp u;
179 u.set_internet_layer(&ip);
180 string str = "zuooooooooooooooooooooooooooooooooooooooooooa";
181 u.send(ipv4_addr::from_le(192 << 24 | 168 << 16 | 1 << 8 | 3), 41300, 47438, str.to_mem());
183 icmp ping;
184 ping.set_internet_layer(&ip);
185 ping.ping(ipv4_addr::from_le(192 << 24 | 168 << 16 | 1 << 8 | 2));
187 ping.ping(ipv4_addr::from_le(192 << 24 | 168 << 16 | 1 << 8 | 2));
189 while (true) asm("hlt");
192 p<block> floppy = main->get<block>("/fdc");
193 p<fs> fs_floppy = main->get<fs>("/fat");
195 fs_floppy->mount(floppy);
196 p<file> temp = main->get<file>("/file,authors");
198 tlog->print((string)(const char*)((const string)*temp), services::logger::log_warning);
200 p<module> mod = main->get<module>("/module,rs232.ko");
202 mod->place(module::module_kernel_space);
203 mod->get_delegate()();
205 p<unmangler> unman = main->get<unmangler>("/unmangler");
207 p<stream> serial = main->get<stream>("/console,1");
209 string name = unman->unmangle(typeid(*serial).name());
210 serial->write(name.to_mem());
212 //jump_v86();
214 p<director> sched = main->get<director>("/director");
215 p<actor> proc = sched->new_component(cds::component_name::from_path("/type,actor")).cast<actor>();
217 proc->set(delegate<void>::function(next));
218 /* Benchmark
219 for (int i = 0; i < 10000; i++)
220 for (int j = 0; j < 1000; j++)
221 stat->get_value(stats::ks_timeticks);
222 //*/
223 tlog->print((string)"EFC caught so far " + stat->get_value(services::stats::efc_calls) + " function calls.\n", services::logger::log_info);
225 // string ss = stat->full_stats();
226 // serial->write(ss.to_mem());
228 sched->launch(proc);
231 void next() {
232 p<manec> main = manec::get();
234 // p<modules::module> mod = main->get<modules::module>("/module,shell.ko");
235 // mod->place(module::module_kernel_space);
237 p<director> sched = main->get<director>("/director");
238 // p<actor> proc = sched->new_component((type_name)"actor")->get<actor>();
239 // proc->set(mod->get_delegate());
240 // sched->start(proc);
242 /* PIO */
243 p<stream> ttyS = main->get<stream>("/console,1");
245 p<pio> str = new pio;
247 string buf = "\n\xdHello World!!!";
248 str->set_dep(ttyS);
249 str->send_packet(buf.to_mem());
250 str->set_speed(3);
251 delegate<void> nul;
253 // str->start(false, nul);
255 str.dispose();
257 while (1) __asm__("hlt");