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.
31 * @mainpage Quarn OS Documentation
32 * @image html http://quarnos.org/img/qoslogo.png
35 #error Quarn OS is needed to be compiled on GCC 4 or later.
39 #include "services/kernel_state.h"
42 #include "manes/error.h"
43 #include "resources/stream.h"
44 #include "arch/low/general.h"
45 #include "resources/block.h"
47 #include "arch/low/launch.h"
48 #include "resources/fs.h"
49 #include "services/logger.h"
50 #include "services/dns_client.h"
51 #include "resources/bus.h"
52 #include "resources/net/ethernet.h"
53 #include "resources/fat.h"
54 #include "resources/pci.h"
55 #include "resources/isa.h"
56 #include "libs/delegate.h"
57 #include "libs/string.h"
58 #include "modules/loader.h"
59 #include "resources/file.h"
60 #include "services/ntp_client.h"
61 #include "services/unmangler.h"
62 #include "actors/actor.h"
63 #include "actors/director.h"
64 #include "modules/module.h"
65 #include "resources/pio.h"
66 #include "libs/setjmp.h"
67 #include "services/stats.h"
68 #include "libs/pointer.h"
69 #include "resources/keybscr.h"
71 #include "resources/ne2k.h"
72 #include "resources/net/ipv4.h"
73 #include "resources/net/arp.h"
74 #include "resources/net/udp.h"
75 #include "resources/net/icmp.h"
76 #include "resources/net/tcp.h"
78 using namespace services
;
79 using namespace modules
;
80 using namespace resources
;
81 using namespace manes
;
83 using namespace actors
;
88 void *operator new(unsigned int, int);
90 extern char *comp_vtable
;
95 extern "C" void jump_v86();
97 #include "arch/low/pit.h"
98 #if USE_MULTIBOOT == CONF_YES
99 extern "C" void start() {
101 extern "C" void _start() {
103 /* Prepare to execute C++ code */
109 catch (exception
*ex
) {
115 void launch_kernel() {
116 delegate
<void,const char> del
;
118 /* Launch Managed Execution System */
119 manei::get()->launch_manes();
121 manec::get()->connect_manes(manei::get()->get_root());
123 p
<manec
> main
= manec::get();
126 main
->register_abstract("device", "none");
127 main
->register_abstract("storage", "device");
128 main
->register_abstract("console", "device");
129 main
->register_abstract("nic", "device");
131 main
->register_abstract("allocator", "none");
133 main
->register_abstract("service", "none");
135 /* Run low-level procedures */
138 /* Register creators */
139 manei::get()->register_creators();
141 /* Register built in types */
142 manei::get()->register_builtin_types();
145 manei::get()->animate_creators();
147 /* Initialize clock */
150 /* Manes is ready to use */
151 p
<logger
> log
= main
->get
<logger
>("/early_logger");
155 log
->print("OK.\nStarting Quarn OS...",logger::log_critical
);
163 tty
= main
->get
<stream
>("/keybscr");
170 log
->print("cannot create tty", services::logger::log_info
);
174 p
<stats
> stat
= main
->get
<stats
>("/stats");
176 p
<logger
> tlog
= main
->get
<logger
>("/tty_logger");
177 tlog
->print((string
)"\n\nEFC caught so far " + stat
->get_value(services::stats::efc_calls
) + " function calls.", services::logger::log_info
);
179 p
<bus
> mainbus
= main
->get
<bus
>("/isa");
180 tlog
->print((string
)"\nFound ISA devices: " + mainbus
->get_count(), services::logger::log_info
);
182 p
<bus
> pbus
= main
->get
<bus
>("/pci");
183 tlog
->print((string
)"\nFound PCI devices: " + pbus
->get_count(), services::logger::log_info
);
185 tlog
->print((string
)"\nAvailable memory: " + manec::get()->state()->get_memory_size() / 1024 / 1024 + " MB\n\n", services::logger::log_info
);
192 ip
.set_link_layer(ð
);
193 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));
195 string str
= "GET / HTTP/1.1\r\n\r\n";
197 string qu
= "quarnos.org";
199 t.set_internet_layer(&ip);
200 p<client_socket> tcli = t.create_client();
201 tcli->connect(ipv4_addr::from_le(192 << 24 | 168 << 16 | 1 << 8 | 3), 80);
202 tcli->write(str.to_mem());
203 // tcli->write(str.to_mem());
207 u
.set_internet_layer(&ip
);
211 ipv4_addr addr
= dns
.get_ipv4(qu
);
212 asm("cli\nhlt"::"a"(addr
.to_le()));
219 ping
.set_internet_layer(&ip
);
220 ping
.ping(ipv4_addr::from_le(192 << 24 | 168 << 16 | 1 << 8 | 2));
222 ping
.ping(ipv4_addr::from_le(192 << 24 | 168 << 16 | 1 << 8 | 2));
224 while (true) asm("hlt");
227 p
<block
> floppy
= main
->get
<block
>("/fdc");
228 p
<fs
> fs_floppy
= main
->get
<fs
>("/fat");
230 fs_floppy
->mount(floppy
);
231 p
<file
> temp
= main
->get
<file
>("/file,authors");
233 tlog
->print((string
)(const char*)((const string
)*temp
), services::logger::log_warning
);
235 p
<module
> mod
= main
->get
<module
>("/module,rs232.ko");
237 mod
->place(module::module_kernel_space
);
238 mod
->get_delegate()();
240 p
<unmangler
> unman
= main
->get
<unmangler
>("/unmangler");
242 p
<stream
> serial
= main
->get
<stream
>("/console,1");
244 string name
= unman
->unmangle(typeid(*serial
).name());
245 serial
->write(name
.to_mem());
249 p
<director
> sched
= main
->get
<director
>("/director");
250 p
<actor
> proc
= sched
->new_component(cds::component_name::from_path("/type,actor")).cast
<actor
>();
252 proc
->set(delegate
<void>::function(next
));
254 for (int i = 0; i < 10000; i++)
255 for (int j = 0; j < 1000; j++)
256 stat->get_value(stats::ks_timeticks);
258 tlog
->print((string
)"EFC caught so far " + stat
->get_value(services::stats::efc_calls
) + " function calls.\n", services::logger::log_info
);
260 // string ss = stat->full_stats();
261 // serial->write(ss.to_mem());
267 p
<manec
> main
= manec::get();
269 // p<modules::module> mod = main->get<modules::module>("/module,shell.ko");
270 // mod->place(module::module_kernel_space);
272 p
<director
> sched
= main
->get
<director
>("/director");
273 // p<actor> proc = sched->new_component((type_name)"actor")->get<actor>();
274 // proc->set(mod->get_delegate());
275 // sched->start(proc);
278 p
<stream
> ttyS
= main
->get
<stream
>("/console,1");
280 p
<pio
> str
= new pio
;
282 string buf
= "\n\xdHello World!!!";
284 str
->send_packet(buf
.to_mem());
288 // str->start(false, nul);
292 while (1) __asm__("hlt");