00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00066
00067
00068 #include "src/common/shared.hpp"
00069 #include "src/common/blist.hpp"
00070 #include "src/common/blistsort.hpp"
00071 #include "src/common/qsort.hpp"
00072 #include "src/common/error.hpp"
00073 #include "src/common/string.hpp"
00074 #include "src/common/kmalloc.hpp"
00075 #include "src/common/prng.hpp"
00076 #include "src/common/profiler.hpp"
00077 #include "src/collection/avltree.hpp"
00078 #include "src/collection/avlmap.hpp"
00079 #include "src/collection/collection.hpp"
00080 #include "src/mboot.hpp"
00081 #include "src/module/coresyms.hpp"
00082 #include "src/module/elf.hpp"
00083 #include "src/module/mods.hpp"
00084 #include "src/arch/x86/cpuid.hpp"
00085 #include "src/arch/x86/gdt.hpp"
00086 #include "src/arch/x86/interr.hpp"
00087 #include "src/arch/x86/rtc.hpp"
00088 #include "src/arch/x86/context.hpp"
00089 #include "src/arch/x86/sysenter.hpp"
00090 #include "src/arch/x86/wp.hpp"
00091 #include "src/arch/x86/pcibios.hpp"
00092 #include "src/memory/memset.hpp"
00093 #include "src/memory/align.hpp"
00094 #include "src/memory/alloc4k.hpp"
00095 #include "src/memory/pager.hpp"
00096 #include "src/memory/zone.hpp"
00097 #include "src/memory/heap.hpp"
00098 #include "src/tty/teletype.hpp"
00099 #include "src/thread/scheduler.hpp"
00100 #include "src/thread/process.hpp"
00101 #include "src/thread/timer.hpp"
00102 #include "src/net/net.hpp"
00103 #include "src/net/arp.hpp"
00104 #include "src/net/ip.hpp"
00105 #include "src/sandbox.hpp"
00106 #include "src/ata.hpp"
00107 #include "src/fat.hpp"
00108 #include "src/main.hpp"
00109
00115
00116 int main() {
00117 Teletype:: init();
00118 Mboot:: init();
00119 Arch::x86::GDT:: init();
00120 Memory::Pager:: init();
00121 Memory::Physical:: init();
00122 Memory::Heap:: init();
00123 Collection:: init();
00124 Arch::x86::Interr:: init();
00125 Arch::x86:: init();
00126 Arch::x86::Sysenter:: init();
00127 Memory::Pager:: init_pf();
00128 Arch::x86::RTC:: init();
00129 Arch::x86::WProtect:: init();
00130 PRNG:: init();
00131 init_dbg_val_map();
00132 set_dbg_val(0x71,1);
00133 #ifndef _BOCHS
00134 Syms:: init();
00135 #endif
00136
00137
00138
00139
00140 Thread:: init();
00141 Thread::Timer::initTimerThread();
00142
00143 Net:: init();
00144 Net::Arp:: init();
00145 Net::IP:: init();
00146 Module:: init();
00147 Thread::kernel_process.create_thread(true, (uint32)&VarieteThread, 15, 15, "variete");
00148 Arch::x86::Thread:: init(Thread::Scheduler::SCHEDULER_FREQUENCY);
00149 }
00150
00151
00152 #include "src/net/3c556.hpp"
00153
00154
00155
00156 #if 0
00157 template <int padbits>
00158 inline void print(struct pr::sint<padbits> l) {
00159 uint64 li= static_cast<uint64>(l.s);
00160 char ltrs[] = {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
00161 int pd = (padbits>>2)<<2;
00162 if (padbits == 0 && li == 0) {
00163 putch('0');
00164 return;
00165 }
00166 pd-=4;
00167 while ((li >> pd) == 0) {
00168 putch('0');
00169 pd-=4;
00170 }
00171 bool fl=false;
00172 for (int i=60;i>=0;i-=4) {
00173 if (fl)
00174 putch(ltrs[ ((li>>i)&0xf) ]);
00175 fl = fl || ( ((li >> i)&0xF) );
00176 }
00177 }
00178 #endif
00179
00180
00181
00182 #if 0
00183 void a(int x) {
00184 debug_dump_call_trace();
00185 freeze();
00186 }
00187 void b(int x,int y,int z) {
00188 a(x+1);
00189 a(y+z);
00190 }
00191 void c() {
00192 b(0x22334455, 0x99887766, 0x13579);
00193 }
00194 #endif
00195 void VarieteThread() {
00196
00197 #if 0
00198 c();
00199 #endif
00200
00201 #if 0
00202 println(pr::sint<16>(0)," ", pr::sint<16>(1)," ", pr::sint<16>(0x10));
00203 ," ", pr::sint<16>(0x1c)," ", pr::sint<16>(0xfe)," ");
00204 , pr::sint<16>(0x100)," ", pr::sint<16>(0x101)," ", pr::sint<16>(0x110)," ",pr::sint<16>(0x503));
00205 #endif
00206
00207 #if 0
00208 char **tabl;
00209 int N=1000;
00210 print('-');
00211 tabl = static_cast<char**>(kmalloc(sizeof(char*)*N,"tabl"));
00212 print('-');
00213 uint64 t= up_time;
00214 for (int i=0;i<N;i++) {
00215 tabl[i] = static_cast<char*>(kmalloc(sizeof(char),"x"));
00216 }
00217 println(up_time-t);
00218
00219 Thread::ThreadKill((Thread::thread_t*)current_thread);
00220 #endif
00221
00222 #if 0
00223
00224 char *x;
00225 int i;
00226 uint64 t = Arch::x86::RTC::up_time;
00227 println(0);
00228 for (i=0;i<100000;i++) {
00229 x= static_cast<char*>(Memory::Heap::heap0.malloc(256, 1,"a",null));
00230 Memory::Heap::heap0.free(x);
00231 }
00232 println(1);
00233 println(Arch::x86::RTC::up_time - t);
00234 asm volatile("sti");
00235 #endif
00236
00237 #if 0
00238 Debug::Profiler::stats(false);
00239 #endif
00240
00241 #if 0
00242 struct Net::IP::pbuf p;
00243 p.data=static_cast<uint8*>(kmalloc(1000,"abc"));
00244 p.end=800;
00245 p.ip_data_off=700;
00246 for (uint32 i=p.ip_data_off; i<p.end; i++)
00247 p.data[i]=PRNG::nextUint32(15);
00248 while(1) {
00249 Net::IP::ip_transmit(0x03000002, 0, 253, &p);
00250 Net::Arp::arp_cache_insert(e3c556_nif, 0x03000002, Net::ethernet_address(0x1,0x2,0x4,0x5,0x7,0x8));
00251 Thread::sleep(0);
00252 }
00253
00254 #endif
00255
00256 #if 0
00257 using namespace Collection;
00258 struct AvlTree_2::AvlTree<uint32, generic_cmp<uint32> > av;
00259 av.insert(16);
00260 av.insert(73);
00261 av.insert(50);
00262 av.insert(25);
00263 av.insert(35);
00264 av.write();kprintf("\n");av.checkHt();
00265 av.remove(24);
00266 av.remove(15);
00267 av.remove(45);
00268 kprintf("%d\n",av.exists(35));
00269 kprintf("%d\n",av.exists(1001));
00270 kprintf("%d\n", av.find(35).isNone());
00271 kprintf("%d\n", av.find(1001).isNone());
00272 av.write();kprintf("\n");av.checkHt();
00273 av.remove(35);
00274 av.write();kprintf("\n");av.checkHt();
00275 av.remove(73);
00276 av.write();kprintf("\n");av.checkHt();
00277 av.remove(50);
00278
00279
00280 av.write();kprintf("\n");av.checkHt();
00281 av.removeMin(av.nd);
00282 av.write();kprintf("\n");av.checkHt();
00283
00284 av.removeMin(av.nd);
00285
00286 av.write();kprintf("\n");av.checkHt();
00287 kprintf("%d\n", av.findMin());
00288
00289 #endif
00290
00291 #if 0
00292 kfree(0);
00293 kfree(reinterpret_cast<void*>(0x123aabbc));
00294 Thread::ThreadKill((struct Thread::thread_t*)current_thread);
00295 #endif
00296
00297 #if 0
00298 using namespace Collection;
00299 while (1) {
00300 struct Collection::AvlTree<uint32, generic_cmp<uint32> > av;
00301
00302 uint64 t= Arch::x86::RTC::up_time;
00303 println("-");
00304 int N = 10000;
00305 uint32 cnt=0;
00306 for (int i=0;i<N;i++) {
00307 set_dbg_val(0x72,i);
00308 cnt += 1-av.insert(PRNG::nextUint32(10000000));
00309 }
00310 println("insert ", N, ": ", Arch::x86::RTC::up_time-t);
00311
00312 t= up_time;
00313 av.checkHt();
00314 println("checkHt with ", cnt, " nodes: ", up_time-t);
00315
00316 t= up_time;
00317 for (int i=0; i<N; i++) {
00318 av.isEmpty();
00319 }
00320 println("isEmpty ",N,": ", up_time-t);
00321
00322 #if 0
00323 t= up_time;
00324 uint32 k=0;
00325 for (int i=0; i<N; i++)
00326 for (int j=0; j<N; j++) {
00327 k++;
00328 }
00329 println("inc k ", N, "*", N, ": ", up_time-t);
00330 #endif
00331
00332
00333 t=up_time;
00334 for (int i=0;i<N;i++) {
00335 av.findMin();
00336 }
00337 println("findMin ", N, ": ", up_time-t);
00338
00339 t= up_time;
00340 for (int i=0;i<N; i++) {
00341 av.findMin().get();
00342 }
00343 println ("findMin().get() ", N, ": ", up_time-t);
00344
00345 t= up_time;
00346 for (int i=0;i<N; i++) {
00347 }
00348 println (" ", N, ": ", up_time-t);
00349
00350
00351 t= up_time;
00352 while (av.isEmpty()==false)
00353 av.remove2(av.findMin().get());
00354 println("remove ", N, ": ", Arch::x86::RTC::up_time-t);
00355
00356 t= up_time;
00357 av.write();
00358 println("av.write on empty: ", up_time-t);
00359 kprintf("ble");
00360 println();println();
00361 Thread::sleep(0);
00362 }
00363 #endif
00364
00365 #if 0
00366 using namespace Collection;
00367
00368 struct AvlTree_2::AvlTree<uint32,generic_cmp<uint32> > av;
00369 av.insert(10);
00370 av.insert(5);
00371 av.insert(15);
00372 av.insert(4);
00373 av.insert(13);
00374 av.insert(20);
00375 av.insert(14);
00376 av.write();
00377
00378
00379 Thread::sleep(0);
00380 #endif
00381
00382 #if 0
00383 while (1) {
00384 struct blist_s *item;
00385 for (item=Memory::Heap::HeapList.head;item;item=item->next) {
00386 struct Memory::Heap::heapbox *v = static_cast<struct Memory::Heap::heapbox*>(item->data);
00387 kprintf("%s;\t%d\n", v->name, v->allocated_count());
00388 for (int i=0; i<Thread::heap.max_blocks;i++) {
00389 if (Thread::heap.used)
00390 if (Thread::heap.used[i].ptr)
00391 if ((uint32)Thread::heap.used[i].name > 0xc0000000)
00392 cout(Thread::heap.used[i].name);
00393 }
00394 println();
00395
00396 }
00397 Thread::sleep(1000);
00398 }
00399 #endif
00400
00401 #if 0
00402 using namespace Collection;
00403 struct AvlTree<uint32, generic_cmp<uint32> > av;
00404 av.insert(15680); av.insert(17186); av.insert(17187); av.checkHt(); av.write();
00405 av.insert(17186); av.insert(15680); av.insert(17187); av.checkHt(); av.write();
00406 av.insert(17186); av.insert(17187); av.insert(15680); av.checkHt(); av.write();
00407 av.insert(15680); av.insert(17187); av.insert(17186); av.checkHt(); av.write();
00408 av.insert(17187); av.insert(17186); av.insert(15680); av.checkHt(); av.write();
00409 av.insert(17187); av.insert(15680); av.insert(17186); av.checkHt(); av.write();
00410 #endif
00411
00412 #if 0
00413 using namespace Collection;
00414 struct AvlTree<uint32,generic_cmp<uint32> > av;
00415 for (int i=0;i<100000;i++) {
00416 av.insert(PRNG::nextUint32(100000));
00417 }
00418 av.checkHt();
00419 kprintf("!");
00420 #endif
00421
00422 #if 0
00423 uint32 fl;
00424 uint64 t;
00425 t=rdtsc();
00426 kprintf(".");
00427 Thread::sleep(DEF_SECOND);
00428 kprintf(".");
00429 uint32 tm=rdtsc()-t;
00430 ENTER_CRITICAL(fl);
00431 using namespace Collection;
00432 struct AvlTree<uint32,generic_cmp<uint32> > av;
00433 while(1) {
00434 t=rdtsc();
00435 for (int i=0;i<10000;i++)
00436 av.insert(PRNG::nextUint32(100000));
00437 av.checkHt();
00438 while(1) {
00439 struct Option<uint32> opt= av.findMin();
00440 if (opt.isNone()) break;
00441 av.remove(opt.get());
00442 }
00443 kprintf("%x %x\n",tm, rdtsc()-t);
00444
00445 }
00446
00447 #endif
00448
00449 #if 0
00450 for (int i=0; i<20000; i++) {
00451 char *c = reinterpret_cast<char*>(kmalloc(500,"c"));
00452 }
00453 #endif
00454
00455 #if 0
00456 while (1) {
00457 Net::Arp::resolv_get_ether(Net::ip_address(0x03000001));
00458 Thread::sleep(10000);
00459 }
00460 #endif
00461
00462 #if 0
00463 for (int i=0;i<1000;i++)
00464 while(1) {
00465 Net::Arp::resolv_get_ether(Net::ip_address(0x03000007));
00466 Thread::sleep(100);
00467 }
00468 #endif
00469
00470 #if 0
00471 for (int i=0; i<1000;i++)
00472 Thread::Timer::add(abc,1,reinterpret_cast<int>("a"),0);
00473 #endif
00474 #if 0
00475 char *z[]={"aaaaaaaaaaaaa","bbbbbbbbbbbb","ccccccccccc","ddddddddddd","eeeeeeeeeeee","ffffffffffff","ggggggggg","hhhhhhhhhh","iiiiiiiiii","jjjjjjjjjj"};
00476 for (int i=0;i<10;i++) {
00477 Thread::Timer::add(abc,1,reinterpret_cast<int>(z[i]),0);
00478 }
00479 while(1) {
00480 cout("A");
00481 }
00482 #endif
00483
00484 Thread::sleep(500);
00485 Thread::ThreadKill((Thread::thread_t*)current_thread);
00486 }
00487
00488
00489
00490
00491
00492
00493