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 "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"
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
;
79 using namespace actors
;
84 void *operator new(unsigned int, int);
86 extern char *comp_vtable
;
89 extern "C" void jump_v86();
90 #include "arch/low/pit.h"
91 #if USE_MULTIBOOT == CONF_YES
92 extern "C" void start() {
94 extern "C" void _start() {
96 delegate
<void,const char> del
;
98 /* Prepare to execute C++ code */
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();
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 */
121 /* Register creators */
122 manei::get()->register_creators();
124 /* Register built in types */
125 manei::get()->register_builtin_types();
128 manei::get()->animate_creators();
130 /* Initialize clock */
133 /* Manes is ready to use */
134 p
<logger
> log
= main
->get
<logger
>("/early_logger");
138 log
->print("OK.\nStarting Quarn OS...",logger::log_critical
);
146 tty
= main
->get
<stream
>("/keybscr");
153 log
->print("cannot create tty", services::logger::log_info
);
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
);
175 ip
.set_link_layer(ð
);
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));
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());
184 ping
.set_internet_layer(&ip
);
185 ping
.ping(ipv4_addr::from_le(192 << 24 | 168 << 16 | 1 << 8 | 1));
187 ping
.ping(ipv4_addr::from_le(192 << 24 | 168 << 16 | 1 << 8 | 3));
189 while (true) asm("cli\nhlt");
190 p
<block
> floppy
= main
->get
<block
>("/fdc");
191 p
<fs
> fs_floppy
= main
->get
<fs
>("/fat");
193 fs_floppy
->mount(floppy
);
194 p
<file
> temp
= main
->get
<file
>("/file,authors");
196 tlog
->print((string
)(const char*)((const string
)*temp
), services::logger::log_warning
);
198 p
<module
> mod
= main
->get
<module
>("/module,rs232.ko");
200 mod
->place(module::module_kernel_space
);
201 mod
->get_delegate()();
203 p
<unmangler
> unman
= main
->get
<unmangler
>("/unmangler");
205 p
<stream
> serial
= main
->get
<stream
>("/console,1");
207 string name
= unman
->unmangle(typeid(*serial
).name());
208 serial
->write(name
.to_mem());
212 p
<director
> sched
= main
->get
<director
>("/director");
213 p
<actor
> proc
= sched
->new_component(cds::component_name::from_path("/type,actor")).cast
<actor
>();
215 proc
->set(delegate
<void>::function(next
));
217 for (int i = 0; i < 10000; i++)
218 for (int j = 0; j < 1000; j++)
219 stat->get_value(stats::ks_timeticks);
221 tlog
->print((string
)"EFC caught so far " + stat
->get_value(services::stats::efc_calls
) + " function calls.\n", services::logger::log_info
);
223 // string ss = stat->full_stats();
224 // serial->write(ss.to_mem());
230 p
<manec
> main
= manec::get();
232 // p<modules::module> mod = main->get<modules::module>("/module,shell.ko");
233 // mod->place(module::module_kernel_space);
235 p
<director
> sched
= main
->get
<director
>("/director");
236 // p<actor> proc = sched->new_component((type_name)"actor")->get<actor>();
237 // proc->set(mod->get_delegate());
238 // sched->start(proc);
241 p
<stream
> ttyS
= main
->get
<stream
>("/console,1");
243 p
<pio
> str
= new pio
;
245 string buf
= "\n\xdHello World!!!";
247 str
->send_packet(buf
.to_mem());
251 // str->start(false, nul);
255 while (1) __asm__("hlt");