00001 # 1 "src/net/ip.old.cpp" 00002 # 1 "<built-in>" 00003 # 1 "<command-line>" 00004 # 1 "src/net/ip.old.cpp" 00005 # 11 "src/net/ip.old.cpp" 00006 # 1 "./src/common/shared.hpp" 1 00007 # 15 "./src/common/shared.hpp" 00008 # 1 "./src/common/types.hpp" 1 00009 00010 00011 00012 00013 00014 00015 typedef unsigned long long uint64; 00016 typedef signed long long sint64; 00017 typedef signed long sint32; 00018 typedef unsigned int uint32; 00019 typedef unsigned short uint16; 00020 typedef unsigned char uint8; 00021 typedef unsigned char uchar; 00022 00023 typedef uint32 addr_t; 00024 typedef uint32 size_t; 00025 # 16 "./src/common/shared.hpp" 2 00026 # 1 "./src/common/errno.hpp" 1 00027 00028 00029 00030 00031 00032 00033 00034 const int ESUCCESS = 1; 00035 const int EFAIL = -1; 00036 const int EINVAL = -2; 00037 const int EOUTOFMEMORY = -3; 00038 const int ENOTIMPL = -4; 00039 const int ESANITY = -5; 00040 # 17 "./src/common/shared.hpp" 2 00041 # 1 "./src/common/error.hpp" 1 00042 # 22 "./src/common/error.hpp" 00043 void panic() __attribute__ ((noreturn)); 00044 00045 00046 00047 00048 00049 00050 const uint32 PORT_E9 = 0xe9; 00051 00052 00053 00054 00055 void init_dbg_val_map(); 00056 uint32 get_dbg_val(const char * key); 00057 uint32 set_dbg_val(const char * key, uint32 val); 00058 00059 struct eip_ebp { 00060 uint32 eip; 00061 uint32 ebp; 00062 }; 00063 00064 00065 # 1 "./src/tty/teletype.hpp" 1 00066 00067 00068 00069 00070 00071 # 1 "./src/ipc/lock.hpp" 1 00072 00073 00074 00075 00076 00077 # 1 "./src/common/error.hpp" 1 00078 # 7 "./src/ipc/lock.hpp" 2 00079 00080 00081 namespace IPC { 00082 namespace Lock { 00083 00084 extern volatile uint32 disable_all_locks; 00085 00086 const uint32 LOCK_NAME = 0x10; 00087 00088 class lock_t 00089 { 00090 public: 00091 char name[LOCK_NAME]; 00092 00093 uint32 state; 00094 struct eip_ebp eipebp; 00095 uint32 eflags; 00096 public: 00097 00098 00099 lock_t(const char *nam); 00100 lock_t(); 00101 void init(char *nam); 00102 uint32 locked(); 00103 void lock(); 00104 void lock(uint32 slp); 00105 void lock2(); 00106 void ulock(); 00107 }; 00108 00109 00110 }; 00111 }; 00112 00113 extern IPC::Lock::lock_t lock_system; 00114 # 7 "./src/tty/teletype.hpp" 2 00115 # 1 "./src/ipc/sem.hpp" 1 00116 00117 00118 00119 00120 00121 # 1 "./src/common/blist.hpp" 1 00122 # 10 "./src/common/blist.hpp" 00123 namespace Memory{namespace Heap{ 00124 class heapbox; } } 00125 00126 00127 00128 00129 struct blist_s 00130 { 00131 blist_s *prev; 00132 blist_s *next; 00133 class blist_t *tree; 00134 00135 uint32 size; 00136 void *data; 00137 00138 00139 const char *func, *file; 00140 uint32 line; 00141 }; 00142 # 70 "./src/common/blist.hpp" 00143 class blist_t 00144 { 00145 private: 00146 IPC::Lock::lock_t lock_blist; 00147 friend struct blist_s *blistsort_link(blist_t *list, blist_s *item, int(*compar)(const void*,const void*), blist_s *head); 00148 public: 00149 blist_s *head, *tail; 00150 uint32 facility; 00151 class Memory::Heap::heapbox *heap; 00152 00153 void init (uint32 fac); 00154 void init (uint32 fac, class Memory::Heap::heapbox *hp); 00155 void init (const char *name, class Memory::Heap::heapbox *hp); 00156 void done(); 00157 00158 blist_s *add(void *data, size_t size, blist_t *tree); 00159 blist_s *find(void *data); 00160 int del(blist_s *obj); 00161 00162 blist_s *move(blist_s *obj, blist_t *dest); 00163 blist_s *link(blist_s *obj); 00164 blist_s *unlink(blist_s *obj); 00165 00166 blist_s *ptr(void *data, blist_t *tree); 00167 }; 00168 # 7 "./src/ipc/sem.hpp" 2 00169 00170 00171 00172 00173 struct thread_t; 00174 00175 00176 00177 00178 00179 const uint32 SF_OPEN = 1; 00180 00181 00182 struct thwait_t 00183 { 00184 struct thread_t *thread; 00185 uint64 timestamp; 00186 }; 00187 00188 00189 struct sem_t 00190 { 00191 class blist_t wait_queue; 00192 class IPC::Lock::lock_t lock_sem; 00193 int volatile val; 00194 00195 uint32 flags; 00196 00197 const char *name; 00198 }; 00199 00200 int sem_init(sem_t *sem, unsigned int value, const char *name); 00201 int sem_destroy(sem_t *sem); 00202 int sem_getvalue(sem_t *sem, int *sval); 00203 int sem_wait(sem_t *sem); 00204 int sem_trywait(sem_t *sem); 00205 int sem_post(sem_t *sem); 00206 # 8 "./src/tty/teletype.hpp" 2 00207 00208 00209 struct ChCol 00210 { 00211 uint8 ch, col; 00212 }; 00213 00214 namespace Teletype { 00215 extern ChCol *vidmem; 00216 void init(); 00217 }; 00218 00219 00220 extern uint32 volatile TTYDisableLock; 00221 00222 00223 00224 class teletype 00225 { 00226 friend void Teletype::init(); 00227 friend void tty_switch(teletype*, char*); 00228 friend void coutnum(teletype *tty, uint32 n, uint32 radix, uint32 n_pos, char first_letter, char EmptyLetter); 00229 friend void poke_str(char *ch, uint8 color, int x, int y, uint32 limit); 00230 friend void poke_char(char ch, uint8 color, int x, int y); 00231 friend void writehere(char *ch, uint8 color, uint32 limit); 00232 friend void putch(char ch); 00233 friend void cout (char *ch, uint8 color); 00234 friend void cout(teletype *tty, char *ch); 00235 friend void coutnum(teletype *tty, uint32 n, uint32 radix, uint32 n_pos, char first_letter, uint8 col); 00236 00237 ChCol *video; 00238 int start, lgth; 00239 int x, y; 00240 int xsize, ysize, lines; 00241 int yoffset; 00242 int yfocus; 00243 uint8 color; 00244 00245 struct sem_t sem_tty; 00246 00247 teletype *HW; 00248 00249 int (*kbd_handler)(); 00250 00251 00252 int line (int n); 00253 ChCol *lineptr (int n); 00254 void movecurs(int n); 00255 00256 void llock(); 00257 void lulock(); 00258 00259 void repaint(teletype *tty); 00260 00261 void del_top(int n); 00262 public: 00263 teletype(ChCol *buffer, int _xsize, int _ysize, int _lines, teletype *vHW, int (*kbd_h)(), uint8 col); 00264 00265 private: 00266 void gotoxy(int px, int py); 00267 void showtop(int py); 00268 void setcol(uint8 col); 00269 void scroll(int i); 00270 00271 00272 00273 00274 void clrscr(); 00275 00276 void poke (char ch, int px, int py, uint8 col); 00277 void put(char ch, uint8 col); 00278 00279 void put(char ch); 00280 00281 void putch(char ch, uint8 col); 00282 00283 void putch(char ch); 00284 00285 void poke_str(char *ch, int px, int py, uint8 col, uint32 limit); 00286 00287 int getx(); int gety(); 00288 00289 int getxsize(); int getysize(); 00290 00291 void tab(int i); 00292 }; 00293 00294 00295 const uint32 VIRTCONS_LINES = 240; 00296 const uint32 CONSOLE_XSIZE = 80; 00297 const uint32 CONSOLE_YSIZE = 24; 00298 const uint32 VIRTCONS_COUNT = 10; 00299 const uint32 VIDEO_MEMORY = 0xB8000; 00300 const uint8 CONSOLE_COLOR = 7; 00301 const uint8 TTY_PANEL_COLOR = 7<<4; 00302 const uint8 LOGOUT_COLOR = 8; 00303 const uint32 TTY_NO_X = 12; 00304 const uint32 GOTOXY_ADDEND = CONSOLE_XSIZE; 00305 # 114 "./src/tty/teletype.hpp" 00306 extern teletype videoHW; 00307 extern teletype tty_panel; 00308 extern teletype tty1, tty2, tty3, tty4, tty5, tty6, tty7, tty8, tty9, tty0; 00309 extern teletype *active_console; 00310 00311 extern ChCol tty1_buf [VIRTCONS_LINES * CONSOLE_XSIZE]; 00312 extern ChCol tty2_buf [VIRTCONS_LINES * CONSOLE_XSIZE]; 00313 extern ChCol tty3_buf [VIRTCONS_LINES * CONSOLE_XSIZE]; 00314 extern ChCol tty4_buf [VIRTCONS_LINES * CONSOLE_XSIZE]; 00315 extern ChCol tty5_buf [VIRTCONS_LINES * CONSOLE_XSIZE]; 00316 extern ChCol tty6_buf [VIRTCONS_LINES * CONSOLE_XSIZE]; 00317 extern ChCol tty7_buf [VIRTCONS_LINES * CONSOLE_XSIZE]; 00318 extern ChCol tty8_buf [VIRTCONS_LINES * CONSOLE_XSIZE]; 00319 extern ChCol tty9_buf [VIRTCONS_LINES * CONSOLE_XSIZE]; 00320 extern ChCol tty0_buf [VIRTCONS_LINES * CONSOLE_XSIZE]; 00321 00322 00323 00324 00325 void cout (char const *ch); 00326 void cout(teletype *tty, char *ch); 00327 void cout (char *ch, uint8 color); 00328 void cout (uint32 i); 00329 void cout (uint32 i,uint8 col); 00330 void cout (teletype *tty, uint32 i); 00331 void coutnum(uint32 n, uint32 radix, uint32 n_pos, char first_letter); 00332 void coutnum(teletype *tty, uint32 n, uint32 radix, uint32 n_pos, char first_letter, char EmptyLetter); 00333 void coutnum(teletype *tty, uint32 n, uint32 radix, uint32 n_pos, char first_letter, uint8 col); 00334 void coutnum(teletype *tty, uint32 n, uint32 radix, uint32 n_pos, char first_letter); 00335 void coutDec(uint32 i); 00336 00337 void coutb(uint8 ch); 00338 void putch(char ch); 00339 void writehere(char *ch, uint8 color, uint32 limit); 00340 void poke_char(char ch, uint8 color, int x, int y); 00341 void poke_str(char *ch, uint8 color, int x, int y, uint32 limit); 00342 00343 void kprintf(const char *fmt, ...); 00344 void kprintf_alert(char *fmt, ...); 00345 void kprintf(teletype *tty, char *fmt, ...); 00346 void videoHW_gotoxy(int n); 00347 void videoHW_toggle_cursor(uint32 on); 00348 00349 00350 void ksnprintf(char *str, size_t size, char *format, ...); 00351 00352 00353 00354 int tui_kbd_handler(); 00355 void tty_switch(teletype *tty,char *name); 00356 # 45 "./src/common/error.hpp" 2 00357 00358 void debug_dump_call_trace(uint32 eip, uint32 addr); 00359 void debug_dump_call_trace(); 00360 00361 00362 00363 void put_bochs(char ch); 00364 void write_bochs(const char *text); 00365 void write_bochs(int i); 00366 void write_bochs_num(uint32 n, uint32 radix, uint32 n_pos, char first_letter); 00367 inline void alert(const char *text) 00368 { 00369 write_bochs(text); 00370 cout(const_cast<char*>(text)); 00371 } 00372 00373 inline void alert(int i) 00374 { 00375 write_bochs(i); 00376 cout(i); 00377 } 00378 inline void alert2(uint32 i) 00379 { 00380 write_bochs_num(i,10,1000000000,0); 00381 coutDec(i); 00382 } 00383 # 18 "./src/common/shared.hpp" 2 00384 # 1 "./src/common/profiler.hpp" 1 00385 00386 00387 00388 00389 00390 void *memset(void *buffer, int c, uint32 num); 00391 namespace Arch { 00392 namespace x86 { 00393 namespace RTC { 00394 extern uint64 volatile up_time; }}} 00395 00396 00397 00398 namespace Debug { 00399 namespace Profiler { 00400 00401 00402 inline uint64 rdtsc() 00403 { 00404 union 00405 { 00406 uint32 u32[2]; 00407 uint64 u64; 00408 }; 00409 asm volatile ("rdtsc" :"=a" (u32[0]), "=d"(u32[1])); 00410 return u64; 00411 } 00412 00413 00414 00415 00416 00417 struct profiling_s 00418 { 00419 uint64 volatile Time; 00420 uint32 volatile Calls; 00421 uint32 volatile Active; 00422 char *Name; 00423 }; 00424 00425 00426 00427 00428 extern uint32 ProfilerCount; 00429 extern struct profiling_s ProfilerBuf[200]; 00430 # 78 "./src/common/profiler.hpp" 00431 void stats(uint32 SortBySlowest); 00432 int ProfilingCompar(const void*,const void*); 00433 # 92 "./src/common/profiler.hpp" 00434 }; 00435 }; 00436 00437 00438 00439 inline uint64 rdtsc() 00440 { 00441 return Debug::Profiler::rdtsc(); 00442 } 00443 # 19 "./src/common/shared.hpp" 2 00444 # 1 "./src/sandbox.hpp" 1 00445 00446 00447 00448 00449 00450 namespace Sandbox { 00451 00452 00453 void sub_sand(); 00454 00455 00456 00457 00458 }; 00459 # 20 "./src/common/shared.hpp" 2 00460 # 37 "./src/common/shared.hpp" 00461 # 1 "./src/common/println.hpp" 1 00462 # 42 "./src/common/println.hpp" 00463 void print(char *n); 00464 void print(); 00465 # 38 "./src/common/shared.hpp" 2 00466 00467 00468 00469 inline void print() { } 00470 inline void print(char *n) { kprintf("%s", n); } 00471 00472 inline void print(uint32 v) { 00473 kprintf("0x%x", v); 00474 } 00475 # 100 "./src/common/shared.hpp" 00476 void dbPrintInt(uint32 n); 00477 void dbSetRow(uint32 n) ; 00478 char digitOfUint(uint32 n, uint32 div); 00479 # 12 "src/net/ip.old.cpp" 2 00480 # 1 "./src/memory/memset.hpp" 1 00481 00482 00483 00484 00485 00486 void *memmove(void *s1, void *s2, uint32 count); 00487 void *memset(void *buffer, int c, uint32 num); 00488 # 13 "src/net/ip.old.cpp" 2 00489 # 1 "./src/memory/align.hpp" 1 00490 00491 00492 00493 00494 const uint32 PAGE_ALIGN = 0x1000; 00495 const uint32 STACK_ALIGN = 4; 00496 const uint32 NO_ALIGN = 1; 00497 00498 uint32 align_up (uint32 addr, uint32 alignment); 00499 uint32 align_down (uint32 addr, uint32 alignment); 00500 # 14 "src/net/ip.old.cpp" 2 00501 # 1 "./src/memory/heap.hpp" 1 00502 # 9 "./src/memory/heap.hpp" 00503 # 1 "./src/memory/zone.hpp" 1 00504 00505 00506 00507 00508 00509 00510 # 1 "./src/common/stack.hpp" 1 00511 # 45 "./src/common/stack.hpp" 00512 class stack_t 00513 { 00514 public: 00515 uint32 *stack; 00516 uint32 volatile stack_ptr; 00517 uint32 volatile max_elems; 00518 00519 00520 00521 00522 void nw(char *buffer, uint32 elems); 00523 00524 00525 void inval(); 00526 void verify(); 00527 00528 uint32 expandable; 00529 void setExpandable(); 00530 00531 00532 00533 uint32 push(uint32 data); 00534 uint32 pop(); 00535 uint32 pop_value(uint32 val); 00536 uint32 push_top(uint32 val); 00537 uint32 find(uint32 val); 00538 00539 00540 uint32 lgth(); 00541 }; 00542 # 8 "./src/memory/zone.hpp" 2 00543 00544 namespace Memory { 00545 00546 00547 00548 class zone 00549 { 00550 public: 00551 stack_t page_list; 00552 size_t one_page; 00553 public: 00554 void init (uint32 *buf, size_t elems, size_t pg_siz); 00555 void done(); 00556 void set_length(size_t n); 00557 00558 addr_t alloc(size_t cnt); 00559 int free(addr_t addr); 00560 size_t length(); 00561 }; 00562 00563 00564 }; 00565 # 10 "./src/memory/heap.hpp" 2 00566 00567 00568 const uint32 FAC_OWN = 0x001f; 00569 const uint32 FAC_TYPE = 0x07e0; 00570 const uint32 FAC_MIDDLE = 0x7800; 00571 00572 const uint32 FAC_NULL = 0x0000; 00573 const uint32 FAC_UNDEF = 0x0001; 00574 const uint32 FAC_OTHER = 0x0002; 00575 const uint32 FAC_MEMORY = 0x0003; 00576 const uint32 FAC_INTERR = 0x0004; 00577 const uint32 FAC_THREAD = 0x0005; 00578 const uint32 FAC_MSG = 0x0006; 00579 const uint32 FAC_MMAP = 0x0007; 00580 const uint32 FAC_SYMS = 0x0008; 00581 00582 const uint32 FAC_VMEM = 0x0020; 00583 const uint32 FAC_USEDBLOCKS = 0x0020; 00584 const uint32 FAC_PGD = 0x0040; 00585 const uint32 FAC_IDT = 0x0020; 00586 const uint32 FAC_EXCLIST = 0x0040; 00587 const uint32 FAC_THRLIST = 0x0020; 00588 const uint32 FAC_TSP = 0x0040; 00589 const uint32 FAC_KSP = 0x0060; 00590 const uint32 FAC_ISP = 0x0080; 00591 const uint32 FAC_THRSLEEP = 0x00a0; 00592 const uint32 FAC_THRRAN = 0x00c0; 00593 const uint32 FAC_MESSAGE = 0x0020; 00594 const uint32 FAC_MSGLIST = 0x0040; 00595 const uint32 FAC_MEMREG = 0x0020; 00596 const uint32 FAC_SYMTAB = 0x0020; 00597 const uint32 FAC_STRTAB = 0x0040; 00598 const uint32 FAC_QSORTBUF = 0x0020; 00599 const uint32 FAC_MANGLE = 0x0040; 00600 const uint32 FAC_MANGLE2 = 0x0040; 00601 00602 const uint32 FAC_BLIST = 0x0800; 00603 const uint32 FAC_BLIST_BK = 0x1000; 00604 const uint32 FAC_BLIST_PTR = 0x1800; 00605 00606 namespace Memory { 00607 namespace Heap { 00608 00609 const uint32 heap_magic = 0xcafebabe; 00610 const uint32 HEAP_GRAN = 0x1; 00611 const uint32 HEAP_STACK_GRAN = 0x10000; 00612 const uint32 HEAP_TBLE = 0x20; 00613 const uint32 HEAP_TBLE_GRAN = 0x100; 00614 const uint32 HEAP_MIN_BLOCK = 0x10; 00615 const uint32 HEAPBOX_NAME = 0x10; 00616 00617 const uint32 MALLOC_NOLOCKS = 1; 00618 const uint32 MALLOC_NORESCUE = 2; 00619 00620 00621 00622 struct block_used 00623 { 00624 void *ptr; 00625 size_t size; 00626 union 00627 { 00628 uint32 facility; 00629 const char *name; 00630 }; 00631 int (*destruct)(class heapbox*,void*); 00632 }; 00633 00634 struct block_free 00635 { 00636 block_free *prev; 00637 block_free *next; 00638 size_t size; 00639 uint32 checksum; 00640 }; 00641 00642 extern class blist_t HeapList; 00643 00644 void init(); 00645 int allocate_heapbox(class heapbox *hbx, char *name); 00646 addr_t morecore(size_t cnt); 00647 void freecore(addr_t virt, size_t cnt); 00648 00649 int checkMagic(block_free *item); 00650 int checkMagic(block_used *item); 00651 int countMagic(block_free *item); 00652 int countMagic(block_used *item); 00653 00654 00655 00656 class heapbox 00657 { 00658 protected: 00659 public: 00660 class blist_t VirtAddrs; 00661 block_used *used; 00662 uint32 begin_search; 00663 size_t max_blocks; 00664 block_free *first; 00665 uint32 volatile NowResizingUsed; 00666 IPC::Lock::lock_t lock_heap; 00667 struct { 00668 uint32 volatile allocs; 00669 uint32 volatile max; 00670 uint32 volatile used; 00671 } stats; 00672 char name[HEAPBOX_NAME]; 00673 00674 void unAnchorBlock(block_free *item); 00675 void take_block (block_free *item, uint32 facility, int (*destruct)(class heapbox*,void*)); 00676 addr_t morecor(uint32 cnt, uint32 alloc_pgs); 00677 int knew_used(void *ptr, uint32 size, uint32 facility, int (destructor)(class heapbox*,void*)); 00678 block_free *klastfree(); 00679 uint32 blsize(char *ptr); 00680 block_used *kget_info(void *ptr); 00681 void kdefragment(void *ptr); 00682 int resize_used_blocks_table(); 00683 void *mallocFunc(size_t size, size_t alignment, uint32 facility, int (*destruct)(class heapbox*,void*), uint32 MallocState); 00684 int freeFunc(void *ptr, uint32 FreeState); 00685 public: 00686 heapbox(); 00687 void init(block_used *usd, size_t max_blcks, block_free *fir, char *nam); 00688 void destruct(); 00689 void *malloc(size_t size, size_t alignment, uint32 facility, int (*destruct)(class heapbox*,void*)); 00690 void *malloc(size_t size, size_t alignment, const char *name, int (*destruct)(class heapbox*,void*)); 00691 int free(void *ptr); 00692 00693 00694 uint32 allocated_count(); 00695 00696 }; 00697 00698 00699 extern class heapbox heap0; 00700 extern class ::Memory::zone virtual_pages; 00701 00702 }; 00703 }; 00704 00705 void debug_heap_stats(Memory::Heap::heapbox *hp); 00706 # 15 "src/net/ip.old.cpp" 2 00707 # 1 "./src/net/net.hpp" 1 00708 # 15 "./src/net/net.hpp" 00709 # 1 "./src/collection/list.hpp" 1 00710 # 15 "./src/collection/list.hpp" 00711 # 1 "./src/collection/collection.hpp" 1 00712 # 14 "./src/collection/collection.hpp" 00713 # 1 "./src/collection/option.hpp" 1 00714 # 14 "./src/collection/option.hpp" 00715 # 1 "./src/common/kmalloc.hpp" 1 00716 # 16 "./src/common/kmalloc.hpp" 00717 inline void * kmalloc ( uint32 size, const char * name ) { 00718 return ((void*)Memory::Heap::heap0.malloc(size, 1,name ,0)); 00719 } 00720 00721 00722 inline void kfree(void *ptr) 00723 { 00724 Memory::Heap::heap0.free(ptr); 00725 } 00726 # 15 "./src/collection/option.hpp" 2 00727 00728 00729 00730 00731 namespace Collection { 00732 00733 template <typename T> 00734 struct Option { 00735 private: 00736 uint32 isNonev; 00737 T v; 00738 public: 00739 void * operator new(size_t s) { 00740 return kmalloc(s, "option"); 00741 } 00742 struct Option & operator=(const struct Option &rhs) { 00743 this->isNonev = rhs.isNonev; 00744 this->v = rhs.v; 00745 return *this; 00746 } 00747 00748 00749 uint32 isNone() { 00750 return isNonev; 00751 } 00752 Option() { 00753 isNonev=true; 00754 } 00755 Option(T v) { 00756 this->v=v; 00757 isNonev=false; 00758 } 00759 T get() { 00760 if (isNone()) { 00761 debug_dump_call_trace(); 00762 do { alert("\n"); do { alert((char*)"./src/collection/option.hpp"); alert(": line "); alert2(50); alert(": "); alert("None.get()"); alert("\n"); } while (0); panic(); } while(0); 00763 } 00764 return v; 00765 } 00766 void set(T x) { 00767 v=x; isNonev=false; 00768 } 00769 void setNone() { 00770 isNonev=true; 00771 } 00772 }; 00773 } 00774 00775 template <typename T> 00776 inline void print(struct Collection::Option<T> v) { 00777 if (v.isNone()) print("None"); 00778 else do { print("Some ");print(v.get());print();print();print();print();print();print();print();print();print();print();print();print();print();print();print();print();print();print();print();print();;;;;;;;;;;;;;;;;;;;;; } while(0); 00779 } 00780 # 15 "./src/collection/collection.hpp" 2 00781 00782 namespace Collection { 00783 extern struct Memory::Heap::heapbox collection_heapbox; 00784 00785 void init(); 00786 namespace Mem { 00787 void *kmalloc(uint32 size, char *name); 00788 void kfree(void *ptr); 00789 } 00790 # 257 "./src/collection/collection.hpp" 00791 } 00792 # 16 "./src/collection/list.hpp" 2 00793 00794 namespace Collection { 00795 00796 00797 00798 00799 template <typename T> 00800 struct List { 00801 struct ListNode { 00802 struct ListNode *next; 00803 T v; 00804 }; 00805 struct ListNode *head, *tail; 00806 00807 List() : head((0)), tail((0)) { } 00808 00809 void push_front(T v) { 00810 struct ListNode *l = static_cast<struct ListNode*>(Collection::Mem::kmalloc(sizeof(struct ListNode), const_cast<char*>("listnode"))); 00811 l->next=head; 00812 l->v=v; 00813 head= l; 00814 if (tail == (0)) 00815 tail= l; 00816 } 00817 00818 void push_back(T v) { 00819 struct ListNode *l = static_cast<struct ListNode*>(Collection::Mem::kmalloc(sizeof(struct ListNode), "listnode")); 00820 l->next=(0); 00821 l->v=v; 00822 l->tail->next=l; 00823 tail= l; 00824 } 00825 00826 T get_front() { 00827 return head->v; 00828 } 00829 00830 T get_back() { 00831 return tail->v; 00832 } 00833 00834 T pop_front() { 00835 00836 T v = head->v; 00837 struct ListNode *l= head; 00838 head=head->next; 00839 if (head==(0)) 00840 tail=(0); 00841 Collection::Mem::kfree(l); 00842 return v; 00843 } 00844 00845 00846 00847 T pop_back() { 00848 struct ListNode *l; 00849 T v; 00850 if (head==tail) { 00851 v= head->v; 00852 Collection::Mem::kfree(head); 00853 head=tail=(0); 00854 return v; 00855 } 00856 for (l=head; l->next->next; l=l->next) ; 00857 v= l->next->v; 00858 l->next=(0); 00859 00860 Collection::Mem::kfree(tail); 00861 tail=l; 00862 return v; 00863 } 00864 00865 uint32 isEmpty() { 00866 return head==(0); 00867 } 00868 00869 }; 00870 } 00871 # 16 "./src/net/net.hpp" 2 00872 # 28 "./src/net/net.hpp" 00873 namespace Net { 00874 # 42 "./src/net/net.hpp" 00875 uint16 htons(uint16 hostshort); 00876 uint16 ntohs(uint16 netshort); 00877 uint32 htonl(uint32 hostlong); 00878 uint32 ntohl(uint32 netlong); 00879 00880 void init(); 00881 int init_3c556(); 00882 # 58 "./src/net/net.hpp" 00883 struct netbuf { 00884 uint32 len; 00885 uint8 *data; 00886 struct netbuf *next; 00887 struct netif *nif; 00888 netbuf(uint32 len, uint8 *data, struct netbuf *next, struct netif *nif) : len(len),data(data), next(next), nif(nif) { } 00889 00890 }; 00891 00892 struct netbuf *netbuf_alloc(uint32 datasize); 00893 void netbuf_free(struct netbuf *nb); 00894 void netbuf_push_front(struct netbuf *chain, struct netbuf *nb); 00895 void netbuf_push_back(struct netbuf *chain, struct netbuf *nb); 00896 00897 struct ethernet_address { 00898 uint8 d[6]; 00899 ethernet_address() { } 00900 ethernet_address(uint8 d[6]) { for (int i=0;i<6;i++) this->d[i]=d[i]; } 00901 ethernet_address(uint8 d0, uint8 d1,uint8 d2,uint8 d3,uint8 d4, uint8 d5) { d[0]=d0; d[1]=d1; d[2]=d2; d[3]=d3; d[4]=d4; d[5]=d5;} 00902 } __attribute__ ((packed)); 00903 00904 struct ip_address { 00905 uint32 ip; 00906 ip_address(uint32 v) { 00907 ip=htonl(v); 00908 } 00909 00910 ip_address() { } 00911 } __attribute__ ((packed)); 00912 00913 struct netmask_t { 00914 uint32 v; 00915 netmask_t() : v(0) { } 00916 netmask_t(uint32 v) : v(v) { } 00917 } ; 00918 00919 struct outbound_packet { 00920 struct ethernet_address eth_addr; 00921 uint32 t; 00922 struct netbuf *nb; 00923 00924 outbound_packet () { } 00925 outbound_packet(struct ethernet_address eth_addr, uint32 t, struct netbuf *nb) : eth_addr(eth_addr), t(t), nb(nb) { } 00926 }; 00927 00928 struct netif { 00929 char name[8]; 00930 struct ethernet_address eth_addr; 00931 struct ip_address ip_addr; 00932 struct netmask_t netmask; 00933 void (*transmit)(uint8 *, uint32, uint32, uint8 *); 00934 int (*poll)(uint8 *, uint32 *); 00935 struct netbuf *netbuf_curr; 00936 struct Collection::List<struct outbound_packet> outbound; 00937 class IPC::Lock::lock_t outbound_lock; 00938 00939 netif() : transmit((0)), poll((0)), outbound_lock(const_cast<char*>("outbound")) { netbuf_curr = netbuf_alloc(1518); netbuf_curr->nif=this; } 00940 00941 netif(struct netif &ni) : outbound_lock(const_cast<char*>("outbound")) { 00942 memmove(this, &ni, sizeof(struct netif)); 00943 netbuf_curr->nif=this; 00944 } 00945 00946 netif(char name[8], 00947 struct ethernet_address eth_addr, 00948 struct ip_address ip_addr, 00949 struct netmask_t netmask, 00950 void (*transmit)(uint8*, uint32, uint32, uint8*), 00951 int (*poll) (uint8 *, uint32 *)) 00952 : eth_addr(eth_addr), ip_addr(ip_addr), netmask(netmask), transmit(transmit), poll(poll), outbound_lock(const_cast<char*>("outbound")) { for (int i=0; i<8; i++) this->name[i]=name[i]; netbuf_curr = netbuf_alloc(1518); netbuf_curr->nif=this; } 00953 00954 }; 00955 00956 00957 00958 00959 00960 00961 struct netbuf * onFramesReceived (struct netif *nif ); 00962 void onFramesTransmitted(struct netif *nif); 00963 # 146 "./src/net/net.hpp" 00964 int eth_poll(struct netbuf **nb); 00965 void eth_transmit(struct netif *nif, struct ethernet_address eth_addr, unsigned int t, struct netbuf *nb); 00966 00967 void ip_transmit(struct ip_address addr, struct netbuf *nb); 00968 void ip_onNewArpEntry(struct ethernet_address eth_addr, struct ip_address ip_addr); 00969 00970 uint16 count_checksum16(uint16 *data, uint32 len); 00971 00972 00973 00974 } 00975 # 16 "src/net/ip.old.cpp" 2 00976 # 1 "./src/net/arp.hpp" 1 00977 # 17 "./src/net/arp.hpp" 00978 namespace Net { 00979 namespace Arp { 00980 struct arp_entry { 00981 struct netif *nif; 00982 struct ethernet_address eth_addr; 00983 struct ip_address ip_addr; 00984 00985 }; 00986 00987 void init(); 00988 00989 void processArpPacket(struct netbuf *nb); 00990 00991 struct Collection::Option<struct ethernet_address> arp_get_cached_ether(struct ip_address ip); 00992 struct Collection::Option<struct ethernet_address> arp_get_ether(struct ip_address ip); 00993 # 41 "./src/net/arp.hpp" 00994 void arp_cache_insert(struct netif *nif, struct ip_address ip_addr, struct ethernet_address eth_addr) ; 00995 00996 } 00997 } 00998 # 17 "src/net/ip.old.cpp" 2 00999 # 1 "./src/net/ip.hpp" 1 01000 # 14 "./src/net/ip.hpp" 01001 namespace Net { 01002 01003 namespace IP { 01004 01005 01006 struct ip_address my_ip_address(); 01007 struct netmask_t my_netmask(); 01008 01009 01010 01011 struct pbuf { 01012 uint8 *data; 01013 uint32 eth_off; 01014 uint32 ip_off; 01015 uint32 ip_data_off; 01016 uint32 end; 01017 uint32 len; 01018 }; 01019 01020 void onIpReception(struct netbuf *nb); 01021 void ip_onNewArpEntry(struct Net::Arp::arp_entry arp); 01022 int ip_poll(struct pbuf *& pb); 01023 enum route_flags {scope_link=0x01, scope_host=0x02}; 01024 01025 struct route_t { 01026 struct ip_address target; 01027 struct netmask_t netmask; 01028 struct ip_address gateway; 01029 struct netif *nif; 01030 uint32 flags; 01031 route_t(struct ip_address target, struct netmask_t netmask, struct ip_address gateway, struct netif *nif, uint32 flags) : target(target),netmask(netmask),gateway(gateway), 01032 nif(nif),flags(flags) { } 01033 }; 01034 01035 struct ip_header { 01036 uint8 hdr_len:4; 01037 uint8 version:4; 01038 uint8 tos; 01039 uint16 len; 01040 uint16 iden; 01041 uint16 offset:13; 01042 uint8 flags:3; 01043 uint8 ttl; 01044 uint8 prot; 01045 uint16 checksum; 01046 struct ip_address source_ip; 01047 struct ip_address target_ip; 01048 }; 01049 01050 void ip_transmit(struct netif *nif, struct ip_address ip_addr, uint8 tos, uint8 prot, struct pbuf *pb); 01051 void route_add(struct route_t); 01052 01053 struct netif_and_ip { 01054 struct netif nif; 01055 struct ip_address ip; 01056 }; 01057 uint32 route_find(struct ip_address ip, struct netif_and_ip &rt); 01058 01059 01060 void init(); 01061 01062 01063 01064 01065 01066 } 01067 } 01068 # 18 "src/net/ip.old.cpp" 2 01069 # 1 "./src/arch/x86/rtc.hpp" 1 01070 01071 01072 01073 01074 01075 01076 # 1 "./src/arch/x86/except_c.hpp" 1 01077 01078 01079 01080 01081 # 1 "./src/arch/x86/interr.hpp" 1 01082 01083 01084 01085 01086 01087 namespace Arch { 01088 namespace x86 { 01089 namespace Interr { 01090 01091 01092 01093 void init(); 01094 01095 const uint32 DEF_INTERRUPT_COUNT= 0x100; 01096 const uint32 DEF_INT_FLAGS = 0x8e00; 01097 const uint32 DEF_DOUBLE_FAULT = 0x08; 01098 01099 struct struct_idt 01100 { 01101 short s_offset0_15; 01102 short s_selector; 01103 short s_flags; 01104 short s_offset16_31; 01105 }; 01106 01107 struct struct_idtr 01108 { 01109 short s_limit; 01110 struct_idt *s_base; 01111 } __attribute__ ((packed)); 01112 01113 class idt_service 01114 { 01115 public: 01116 struct_idt *idt; 01117 struct_idtr *idtr; 01118 01119 01120 01121 01122 void set_int(char intno, void (offset)(), short select, short flags); 01123 void install_except(void (_exc)()); 01124 void lidt(); 01125 void sti(); 01126 void cli(); 01127 }; 01128 01129 extern class idt_service kernel_idt; 01130 01131 01132 struct reg_dump 01133 { 01134 uint32 r_gs; 01135 uint32 r_fs; 01136 uint32 r_es; 01137 uint32 r_ds; 01138 01139 uint32 r_edi; 01140 uint32 r_esi; 01141 uint32 r_ebp; 01142 uint32 r_temp_esp; 01143 uint32 r_ebx; 01144 uint32 r_edx; 01145 uint32 r_ecx; 01146 uint32 r_eax; 01147 }; 01148 01149 01150 01151 }; 01152 }; 01153 }; 01154 # 6 "./src/arch/x86/except_c.hpp" 2 01155 01156 extern void (*exc)(); 01157 extern void (*irq_h)(); 01158 01159 namespace Arch { 01160 namespace x86 { 01161 namespace Interr { 01162 01163 01164 01165 01166 01167 uint32 isInInterruptHandler(); 01168 01169 01170 01171 const uint32 CHAINHANDLERSTACKCOPY = sizeof(uint32) * 10 + 01172 sizeof(struct reg_dump); 01173 const uint32 CHAINREGCOPY = sizeof(uint32) * 3; 01174 01175 const uint32 STACKSZ = 0x4000; 01176 const uint32 STACKCNT = 16; 01177 01178 extern char *stackPtr[STACKCNT]; 01179 extern uint32 volatile stackVac; 01180 01181 01182 01183 struct except2_t 01184 { 01185 uint32 ebp; 01186 struct reg_dump r; 01187 uint32 c1, c2; 01188 uint32 cr2; 01189 uint32 eip,cs,eflags,esp,ss; 01190 char *stack; 01191 char *reta; 01192 }; 01193 01194 struct except_t 01195 { 01196 uint32 cr3, cr2, cr0; 01197 union 01198 { 01199 uint32 thread_esp; 01200 01201 struct { 01202 uint32 thread_ebp; 01203 reg_dump regs; 01204 uint32 code; 01205 uint32 val; 01206 uint32 thread_eip; 01207 uint32 thread_cs; 01208 uint32 thread_eflags; 01209 union 01210 { 01211 uint32 thread_3_esp; 01212 uint32 *stack; 01213 } uu; 01214 uint32 thread_3_ss; 01215 } *iret; 01216 01217 uint32 *stack; 01218 } uu; 01219 uint32 interrupt_stack_offset; 01220 }; 01221 01222 01223 extern char *except_names[0x20]; 01224 01225 01226 const uint32 INT_DIV0 = 0x00; 01227 const uint32 INT_OPCODE = 0x06; 01228 const uint32 INT_GPF = 0x0d; 01229 const uint32 INT_PF = 0x0e; 01230 const uint32 SYSENT = 0x30; 01231 01232 01233 struct list_t 01234 { 01235 list_t *next; 01236 int (*proc)(except2_t*); 01237 }; 01238 01239 01240 extern list_t* int_lists[0x31]; 01241 extern int (*first_routine[0x31])(except2_t*); 01242 01243 01244 int Exception(except2_t *code); 01245 int PageFault(except2_t *code); 01246 void double_fault() __attribute__ ((noreturn)); 01247 void stack_fault() __attribute__ ((noreturn)); 01248 int Irq_H(except2_t *code); 01249 01250 01251 struct chh_t 01252 { 01253 uint32 ebp; 01254 struct reg_dump r; 01255 uint32 c1,c2; 01256 uint32 eip; 01257 uint32 cs; 01258 uint32 eflags; 01259 }; 01260 01261 void chain_handler(struct chh_t code); 01262 extern uint32 add2interr_chain(uint32,int (*proc)(except2_t*)); 01263 void install_first_routine(uint32 n, uint32 (*proc)(except2_t*)); 01264 uint32 del_chainHdl(uint32 intno, uint32 ptr); 01265 void init_int_chains(idt_service *ptr); 01266 void done_int_chains(); 01267 01268 01269 01270 extern uint32 free_stacks[]; 01271 extern uint32 free_stacks_ptr; 01272 01273 extern void intr0x00() asm ("intr0x00"); 01274 extern void intr0x01() asm ("intr0x01"); 01275 extern void intr0x02() asm ("intr0x02"); 01276 extern void intr0x03() asm ("intr0x03"); 01277 extern void intr0x04() asm ("intr0x04"); 01278 extern void intr0x05() asm ("intr0x05"); 01279 extern void intr0x06() asm ("intr0x06"); 01280 extern void intr0x07() asm ("intr0x07"); 01281 extern void intr0x08() asm ("intr0x08"); 01282 extern void intr0x09() asm ("intr0x09"); 01283 extern void intr0x0a() asm ("intr0x0a"); 01284 extern void intr0x0b() asm ("intr0x0b"); 01285 extern void intr0x0c() asm ("intr0x0c"); 01286 extern void intr0x0d() asm ("intr0x0d"); 01287 extern void intr0x0e() asm ("intr0x0e"); 01288 extern void intr0x0f() asm ("intr0x0f"); 01289 extern void intr0x10() asm ("intr0x10"); 01290 extern void intr0x11() asm ("intr0x11"); 01291 extern void intr0x12() asm ("intr0x12"); 01292 extern void intr0x13() asm ("intr0x13"); 01293 extern void intr0x14() asm ("intr0x14"); 01294 extern void intr0x15() asm ("intr0x15"); 01295 extern void intr0x16() asm ("intr0x16"); 01296 extern void intr0x17() asm ("intr0x17"); 01297 extern void intr0x18() asm ("intr0x18"); 01298 extern void intr0x19() asm ("intr0x19"); 01299 extern void intr0x1a() asm ("intr0x1a"); 01300 extern void intr0x1b() asm ("intr0x1b"); 01301 extern void intr0x1c() asm ("intr0x1c"); 01302 extern void intr0x1d() asm ("intr0x1d"); 01303 extern void intr0x1e() asm ("intr0x1e"); 01304 extern void intr0x1f() asm ("intr0x1f"); 01305 01306 extern void intr0x20() asm ("intr0x20"); 01307 extern void intr0x21() asm ("intr0x21"); 01308 extern void intr0x22() asm ("intr0x22"); 01309 extern void intr0x23() asm ("intr0x23"); 01310 extern void intr0x24() asm ("intr0x24"); 01311 extern void intr0x25() asm ("intr0x25"); 01312 extern void intr0x26() asm ("intr0x26"); 01313 extern void intr0x27() asm ("intr0x27"); 01314 extern void intr0x28() asm ("intr0x28"); 01315 extern void intr0x29() asm ("intr0x29"); 01316 extern void intr0x2a() asm ("intr0x2a"); 01317 extern void intr0x2b() asm ("intr0x2b"); 01318 extern void intr0x2c() asm ("intr0x2c"); 01319 extern void intr0x2d() asm ("intr0x2d"); 01320 extern void intr0x2e() asm ("intr0x2e"); 01321 extern void intr0x2f() asm ("intr0x2f"); 01322 01323 01324 }; 01325 }; 01326 }; 01327 # 8 "./src/arch/x86/rtc.hpp" 2 01328 01329 01330 const char DEF_RTC_IRQ = 0x08; 01331 const char DEF_RTC_BASE = 0x70; 01332 const char DEF_RTC_ST_B = 0x0b; 01333 const char DEF_RTC_ST_C = 0x0c; 01334 const char DEF_RTC_PERIODIC = 0x40; 01335 const char DEF_RTC_NO_PERIODIC = 0xBF; 01336 const char DEF_RTC_PERIOD_INT = 0x40; 01337 01338 const uint32 RTC_NOT_ONE_SHOT = 0; 01339 const uint32 RTC_ONE_SHOT = 1; 01340 01341 const uint32 DEF_SECOND = 1024; 01342 typedef int (*RTC_proc) (int,int) ; 01343 typedef int rtc_handle; 01344 01345 namespace Arch { 01346 namespace x86 { 01347 namespace RTC { 01348 01349 01350 void init(); 01351 void done(); 01352 01353 void enable_rtc(); 01354 void disable_rtc(); 01355 01356 01357 struct rtc_list 01358 { 01359 RTC_proc proc; 01360 uint64 boom; 01361 uint64 ticks_def; 01362 uint32 one_shot; 01363 int arg1,arg2; 01364 }; 01365 01366 extern blist_t rtc_funcs; 01367 01368 rtc_handle add_proc(RTC_proc proc, uint32 ticks_def, uint32 one_shot, int arg1, int arg2); 01369 int rtccompar(const void *a, const void *b); 01370 int del_proc(rtc_handle handle); 01371 01372 01373 01374 01375 01376 extern uint64 volatile up_time; 01377 01378 extern class IPC::Lock::lock_t rtc_lock; 01379 01380 01381 01382 01383 01384 uint8 ack_rtc(); 01385 int rtc_handler(struct Interr::except2_t *code); 01386 01387 01388 void tdelay(uint32 ticks); 01389 01390 01391 }; 01392 }; 01393 }; 01394 # 19 "src/net/ip.old.cpp" 2 01395 # 1 "./src/thread/timer.hpp" 1 01396 # 14 "./src/thread/timer.hpp" 01397 # 1 "./src/collection/avltree.hpp" 1 01398 # 19 "./src/collection/avltree.hpp" 01399 namespace Collection { 01400 01401 template <typename T> 01402 int generic_cmp(T a, T b) { 01403 if (a>b) return 1; 01404 if (a<b) return -1; 01405 return 0; 01406 } 01407 01408 template <typename T> 01409 int pointer_cmp(T *a, T *b) { 01410 return generic_cmp<uint32>( reinterpret_cast<uint32>(a), reinterpret_cast<uint32>(b) ); 01411 } 01412 # 402 "./src/collection/avltree.hpp" 01413 template<typename T,int (*cmp)(T,T)> 01414 struct AvlTree { 01415 01416 struct AvlNode { 01417 struct AvlNode *l, *r; 01418 T key; 01419 uint32 ht; 01420 }; 01421 01422 struct AvlNode *nd; 01423 01424 AvlTree () : nd((0)) { } 01425 01426 void * operator new (size_t s) { 01427 return static_cast<struct AvlNode*> ( Collection::Mem::kmalloc(s , const_cast<char*>("avlnode")) ); 01428 } 01429 01430 void operator delete ( void * x ) { 01431 01432 do { do { alert("\n"); do { alert((char*)"./src/collection/avltree.hpp"); alert(": line "); alert2(421); alert(": "); alert("not implemented"); alert("\n"); } while (0); panic(); } while(0); return ; } while(0); 01433 Collection::Mem::kfree(x); 01434 } 01435 01436 void rotleft(struct AvlNode *&av) { 01437 do { if (!(av!=(0))) {do { alert((char*)"./src/collection/avltree.hpp"); alert(": line "); alert2(426); alert(": "); alert("tesif fail"); alert("\n"); } while (0); } } while(0); 01438 do { if (!(av->r != (0))) {do { alert((char*)"./src/collection/avltree.hpp"); alert(": line "); alert2(427); alert(": "); alert("tesif fail"); alert("\n"); } while (0); } } while(0); 01439 01440 struct AvlNode *v; 01441 01442 v= av->r; 01443 av->r = v->l; 01444 v->l = av; 01445 01446 av= v; 01447 01448 setHeight(av->l); 01449 setHeight(av); 01450 } 01451 01452 void rotright(struct AvlNode *&av) { 01453 do { if (!(av!=(0))) {do { alert((char*)"./src/collection/avltree.hpp"); alert(": line "); alert2(442); alert(": "); alert("tesif fail"); alert("\n"); } while (0); } } while(0); 01454 do { if (!(av->l!=(0))) {do { alert((char*)"./src/collection/avltree.hpp"); alert(": line "); alert2(443); alert(": "); alert("tesif fail"); alert("\n"); } while (0); } } while(0); 01455 01456 struct AvlNode *v; 01457 01458 v=av->l; 01459 av->l = av->l->r; 01460 v->r = av; 01461 01462 av= v; 01463 01464 setHeight(av->r); 01465 setHeight(av); 01466 } 01467 01468 void setHeight(struct AvlNode *&av) { 01469 uint32 ht=0; 01470 do { if (!(av!=(0))) {do { alert((char*)"./src/collection/avltree.hpp"); alert(": line "); alert2(459); alert(": "); alert("tesif fail"); alert("\n"); } while (0); } } while(0); 01471 if (av->l) 01472 ht=av->l->ht; 01473 if (av->r) 01474 ht=((ht) > (av->r->ht) ? (ht) : (av->r->ht)); 01475 av->ht= 1+ht; 01476 } 01477 01478 uint32 checkHt() { return checkHt(nd); } 01479 01480 uint32 checkHt(struct AvlNode *&av) { 01481 if (av == (0)) return false; 01482 uint32 lh=0,rh=0; 01483 if (av->l) 01484 lh= av->l->ht; 01485 if (av->r) 01486 rh= av->r->ht; 01487 01488 uint32 ret = checkHt(av->r) || checkHt(av->l); 01489 01490 if (av->ht != 1+((lh) > (rh) ? (lh) : (rh)) || lh > rh+1 || rh > lh+1) { 01491 kprintf("checkHt: "); 01492 write(av); 01493 kprintf("\n"); 01494 return true; 01495 } 01496 return ret; 01497 } 01498 01499 uint32 height(struct AvlNode *&av) { 01500 if (av==(0)) 01501 return 0; 01502 return av->ht; 01503 } 01504 01505 void bal(struct AvlNode *&av) { 01506 uint32 hl=height(av->l); 01507 uint32 hr=height(av->r); 01508 01509 if (hl > hr+1) { 01510 if (height(av->l->l) >= height(av->l->r)) 01511 rotright(av); 01512 else { 01513 rotleft(av->l); 01514 rotright(av); 01515 } 01516 } 01517 if (hr > hl+1) { 01518 if (height(av->r->r) >= height(av->r->l)) 01519 rotleft(av); 01520 else { 01521 rotright(av->r); 01522 rotleft(av); 01523 } 01524 } 01525 } 01526 01527 uint32 insert(T v) { 01528 uint32 ret= insert(nd, v); 01529 return ret; 01530 } 01531 01532 uint32 insert(struct AvlNode *&av, T v) { 01533 if (av==(0)) { 01534 av= static_cast<struct AvlNode*>(Collection::Mem::kmalloc(sizeof(struct AvlNode),const_cast<char*>("avl node"))); 01535 av->l=(0); 01536 av->r=(0); 01537 av->ht=1; 01538 av->key=v; 01539 return false; 01540 } 01541 int c= cmp(av->key,v); 01542 if (c==0) { 01543 av->key=v; 01544 return true; 01545 } 01546 if (c < 0) { 01547 uint32 ret=insert(av->r,v); 01548 setHeight(av); 01549 bal(av); 01550 return ret; 01551 } 01552 uint32 ret= insert(av->l,v); 01553 setHeight(av); 01554 bal(av); 01555 01556 return ret; 01557 } 01558 01559 uint32 remove(T v) { return remove(nd,v); } 01560 uint32 remove(struct AvlNode *&av, T v) { 01561 if (av==(0)) return false; 01562 int c = cmp(av->key,v); 01563 if (c==0) { 01564 if (av->r==(0)) { 01565 struct AvlNode *a=av; 01566 av=av->l; 01567 Collection::Mem::kfree(a); 01568 return true; 01569 } else { 01570 T a = removeMin(av->r); 01571 av->key=a; 01572 setHeight(av); 01573 bal(av); 01574 return true; 01575 } 01576 } 01577 uint32 ret; 01578 if (c < 0) { 01579 ret = remove(av->r,v); 01580 setHeight(av); 01581 bal(av); 01582 return ret; 01583 } else { 01584 ret= remove(av->l,v); 01585 setHeight(av); 01586 bal(av); 01587 } 01588 return ret; 01589 } 01590 01591 uint32 exists(T v) { return exists(nd,v); } 01592 uint32 exists(struct AvlNode *&av, T v) { 01593 if (av==(0)) return false; 01594 int c = cmp(av->key,v); 01595 if (c==0) return true; 01596 if (c<0) return exists(av->r,v); 01597 return exists(av->l,v); 01598 } 01599 01600 Collection::Option<T> find(T v) { return find(nd,v); } 01601 Collection::Option<T> find(struct AvlNode *&av, T v) { 01602 if (av==(0)) return Option<T>(); 01603 int c = cmp(av->key,v); 01604 if (c==0) return Option<T>(av->key); 01605 if (c<0) return find(av->r,v); 01606 return find(av->l,v); 01607 } 01608 01609 T removeMin(struct AvlNode *&av) { 01610 do { if (!(av!=(0))) {do { alert((char*)"./src/collection/avltree.hpp"); alert(": line "); alert2(599); alert(": "); alert("tesif fail"); alert("\n"); } while (0); } } while(0); 01611 if (av->l==(0)) { 01612 T ret= av->key; 01613 struct AvlNode *v=av->r; 01614 Collection::Mem::kfree(av); 01615 av= v; 01616 return ret; 01617 } else { 01618 T ret = removeMin(av->l); 01619 setHeight(av); 01620 return ret; 01621 } 01622 } 01623 01624 Option<T> findMin() { return findMin(nd); } 01625 Option<T> findMin(struct AvlNode *&av) { 01626 if (av==(0)) 01627 return Option<T> (); 01628 do { if (!(av!=(0))) {do { alert((char*)"./src/collection/avltree.hpp"); alert(": line "); alert2(617); alert(": "); alert("tesif fail"); alert("\n"); } while (0); } } while(0); 01629 if (av->l == (0)) 01630 return av->key; 01631 return findMin(av->l); 01632 } 01633 01634 uint32 isEmpty() { return isEmpty(nd); } 01635 uint32 isEmpty(struct AvlNode *&av) { 01636 return av==(0); 01637 } 01638 01639 void write() { write(nd); } 01640 void write(struct AvlNode *&av) { 01641 if (av == (0)) kprintf("-"); 01642 else { 01643 kprintf("("); 01644 write(av->l); 01645 kprintf(","); 01646 kprintf("%d",av->key); 01647 01648 kprintf(","); 01649 write(av->r); 01650 kprintf(",%d",av->ht); 01651 kprintf(")"); 01652 } 01653 } 01654 }; 01655 01656 01657 01658 01659 } 01660 # 15 "./src/thread/timer.hpp" 2 01661 01662 01663 namespace Thread { 01664 namespace Timer { 01665 struct timer_handle { 01666 uint32 d; 01667 timer_handle(uint32 d) : d(d) { } 01668 timer_handle() : d(0) { } 01669 }; 01670 01671 typedef int (*timer_proc)(int,int); 01672 01673 void initTimerThread(); 01674 01675 struct timer_handle add(timer_proc proc, uint32 interval, int arg1, int arg2); 01676 uint32 remove(struct timer_handle &hndl); 01677 01678 01679 using namespace Collection; 01680 01681 01682 01683 01684 01685 template <typename T,int (*cmp)(T,T)> 01686 uint32 avltree_insert_with_timer(uint32 ticks, struct AvlTree<T,cmp> *tr, T v); 01687 01688 01689 01690 template<typename T, int (*cmp)(T,T)> 01691 int avltree_remove_timer(struct AvlTree<T,cmp> *tr, T *v) { 01692 tr->remove(*v); 01693 kfree(v); 01694 return 0; 01695 } 01696 01697 01698 template <typename T,int (*cmp)(T,T)> 01699 uint32 avltree_insert_with_timer(uint32 ticks, struct AvlTree<T,cmp> *tr, T v) { 01700 T *vptr = static_cast<T*>(kmalloc(sizeof(T),"avl timer helper object")); 01701 memmove(vptr, &v, sizeof(T)); 01702 uint32 ret = tr->insert(v); 01703 int (*f)(struct AvlTree<T,cmp>*,T*)= &avltree_remove_timer<T,cmp>; 01704 add( 01705 01706 reinterpret_cast<int(*)(int,int)>(f), 01707 ticks, 01708 reinterpret_cast<int>(tr), 01709 reinterpret_cast<int>(vptr)); 01710 return ret; 01711 } 01712 # 102 "./src/thread/timer.hpp" 01713 } 01714 } 01715 # 20 "src/net/ip.old.cpp" 2 01716 01717 # 1 "./src/collection/avlmap.hpp" 1 01718 # 15 "./src/collection/avlmap.hpp" 01719 # 1 "./src/collection/tuple.hpp" 1 01720 # 17 "./src/collection/tuple.hpp" 01721 namespace Collection { 01722 template <typename A, typename B> 01723 class Tuple2 { 01724 public: 01725 A _1; 01726 B _2; 01727 01728 Tuple2() : _1((A)(0)),_2((B)(0)) { }; 01729 Tuple2(A a, B b) : _1(a), _2(b) { } 01730 01731 }; 01732 01733 template<typename A, typename B, typename C> 01734 class Tuple3 { 01735 public: 01736 A _1; 01737 B _2; 01738 C _3; 01739 01740 Tuple3() : _1((A)(0)), _2((B)(0)), _3((C)(0)) { }; 01741 Tuple3(A a, B b, C c) : _1(a), _2(b), _3(c) { }; 01742 }; 01743 01744 template<typename A, typename B, typename C, typename D> 01745 class Tuple4 { 01746 public: 01747 A _1; 01748 B _2; 01749 C _3; 01750 D _4; 01751 01752 Tuple4() : _1((A)(0)), _2((B)(0)), _3((C)(0)), _4((D)(0)) { }; 01753 Tuple4(A a, B b, C c, D d) : _1(a), _2(b), _3(c), _4(d) { }; 01754 }; 01755 01756 template<typename A, typename B, typename C, typename D, typename E> 01757 class Tuple5 { 01758 public: 01759 A _1; 01760 B _2; 01761 C _3; 01762 D _4; 01763 E _5; 01764 01765 Tuple5() : _1((A)(0)), _2((B)(0)), _3((C)(0)), _4((D)(0)), _5((E)(0)) { }; 01766 Tuple5(A a, B b, C c, D d, E e) : _1(a), _2(b), _3(c), _4(d), _5(e) { }; 01767 }; 01768 01769 } 01770 01771 01772 01773 01774 01775 template <typename A, typename B, typename C, typename D, typename E> 01776 void print(struct Collection::Tuple5<A,B,C,D,E> t) { 01777 do { print("(");print(t._1);print(",");print(t._2);print(",");print(t._3);print(",");print(t._4);print(",");print(t._5);print(")");print();print();print();print();print();print();print();print();print();print();print();;;;;;;;;;;;;;;;;;;;;; } while(0); 01778 } 01779 01780 template <typename A, typename B, typename C, typename D> 01781 void print(struct Collection::Tuple4<A,B,C,D> t) { 01782 do { print("(");print(t._1);print(",");print(t._2);print(",");print(t._3);print(",");print(t._4);print(")");print();print();print();print();print();print();print();print();print();print();print();print();print();;;;;;;;;;;;;;;;;;;;;; } while(0); 01783 } 01784 01785 template <typename A, typename B, typename C> 01786 void print(struct Collection::Tuple3<A,B,C> t) { 01787 do { print("(");print(t._1);print(",");print(t._2);print(",");print(t._3);print(")");print();print();print();print();print();print();print();print();print();print();print();print();print();print();print();;;;;;;;;;;;;;;;;;;;;; } while(0); 01788 } 01789 01790 template <typename A, typename B> 01791 void print(struct Collection::Tuple2<A,B> t) { 01792 do { print("(");print(t._1);print(",");print(t._2);print(")");print();print();print();print();print();print();print();print();print();print();print();print();print();print();print();print();print();;;;;;;;;;;;;;;;;;;;;; } while(0); 01793 } 01794 # 16 "./src/collection/avlmap.hpp" 2 01795 01796 namespace Collection { 01797 01798 template<typename A, typename B, int (*cmp)(A,A) > 01799 int tuple2_comparator(Tuple2<A,B> a1, Tuple2<A,B> a2) { 01800 return cmp(a1._1, a2._1); 01801 } 01802 01803 template <typename KeyT, typename DataT, int (*cmp) (KeyT, KeyT)> 01804 class AvlMap { 01805 private: 01806 AvlTree<Tuple2<KeyT,DataT>, tuple2_comparator<KeyT,DataT,cmp> > *tr; 01807 public: 01808 AvlMap() { 01809 tr= new AvlTree<Tuple2<KeyT,DataT>, tuple2_comparator<KeyT,DataT,cmp> >; 01810 01811 } 01812 ~AvlMap() { 01813 do { do { alert("\n"); do { alert((char*)"./src/collection/avlmap.hpp"); alert(": line "); alert2(34); alert(": "); alert("not implemented"); alert("\n"); } while (0); panic(); } while(0); return ; } while(0); 01814 } 01815 01816 uint32 update(KeyT key, DataT data) { 01817 return tr->insert(Tuple2<KeyT,DataT>(key,data)); 01818 } 01819 01820 uint32 remove(KeyT key) { 01821 return tr->remove(Tuple2<KeyT,DataT>(key,(DataT)(0))); 01822 } 01823 uint32 isEmpty() { 01824 return tr->isEmpty(); 01825 } 01826 01827 Option<Tuple2<KeyT, DataT> > find(KeyT key) { 01828 return tr->find(Tuple2<KeyT,DataT>(key,(DataT)(0))); 01829 } 01830 }; 01831 } 01832 # 22 "src/net/ip.old.cpp" 2 01833 # 32 "src/net/ip.old.cpp" 01834 namespace Net { 01835 namespace IP { 01836 01837 struct ip_address my_ip_address() { 01838 return ip_address(0x03000006); 01839 } 01840 01841 struct netmask_t my_netmask() { 01842 return netmask_t(0xffffff00); 01843 } 01844 01845 using namespace Collection; 01846 01847 int ip_outbound_cmp(struct Tuple2<struct ip_address, struct netbuf* > a, struct Tuple2<struct ip_address, struct netbuf*> b) { 01848 if (a._1.ip > b._1.ip) 01849 return 1; 01850 if (a._1.ip < b._1.ip) 01851 return -1; 01852 01853 return pointer_cmp<struct netbuf> (a._2, b._2); 01854 } 01855 01856 struct AvlTree<struct Tuple2<struct ip_address, struct netbuf*>, ip_outbound_cmp> *ip_outbound; 01857 struct IPC::Lock::lock_t ip_outbound_lock(const_cast<char*>("ip_outbound")); 01858 01859 void init() { 01860 ip_outbound= new AvlTree<struct Tuple2<struct ip_address, struct netbuf*>, ip_outbound_cmp>(); 01861 } 01862 01863 01864 void ip_onNewArpEntry(struct Net::Arp::arp_entry arp) { 01865 ip_outbound_lock.lock(); 01866 struct Option<struct Tuple2<struct ip_address,struct netbuf*> > opt; 01867 struct Tuple2<struct ip_address, struct netbuf*> templ = Tuple2<struct ip_address, struct netbuf*>(arp.ip_addr, (0)); 01868 01869 01870 do {do { print(opt);print();print();print();print();print();print();print();print();print();print();print();print();print();print();print();print();print();print();print();print();print();;;;;;;;;;;;;;;;;;;;;; } while(0); kprintf("\n");} while(0); 01871 while ( (opt = ip_outbound->find(templ)).isNone() == false) { 01872 struct Tuple2<struct ip_address, struct netbuf*> v= opt.get(); 01873 ip_outbound->remove(v); 01874 do {do { print(v);print();print();print();print();print();print();print();print();print();print();print();print();print();print();print();print();print();print();print();print();print();;;;;;;;;;;;;;;;;;;;;; } while(0); kprintf("\n");} while(0); 01875 } 01876 ip_outbound_lock.ulock(); 01877 } 01878 01879 void ip_transmit(struct netif *nif, struct ip_address ip_addr, uint8 tos, uint8 prot, struct pbuf *pb) { 01880 do { if (!(sizeof(struct ip_header)==20)) {do { alert((char*)"src/net/ip.old.cpp"); alert(": line "); alert2(78); alert(": "); alert("assertion fail"); alert("\n"); } while (0); for(;;);} } while (0); 01881 do { if (!(pb)) {do { alert((char*)"src/net/ip.old.cpp"); alert(": line "); alert2(79); alert(": "); alert("tesif fail"); alert("\n"); } while (0); } } while(0); 01882 if (pb->ip_data_off < sizeof(struct ip_header)) { 01883 do { alert((char*)"src/net/ip.old.cpp"); alert(": line "); alert2(81); alert(": "); alert("no space for ip header in packet buffer"); alert("\n"); } while (0); 01884 return ; 01885 } 01886 struct ip_header *ip; 01887 pb->ip_off=pb->ip_data_off - sizeof(struct ip_header); 01888 ip=reinterpret_cast<struct ip_header*>(&pb->data[pb->ip_off]); 01889 ip->version=4; 01890 ip->hdr_len=sizeof(struct ip_header)/sizeof(uint32); 01891 ip->tos=tos; 01892 ip->len=htons(pb->end - pb->ip_off); 01893 static uint16 ip_iden=0; 01894 ip->iden= htons(ip_iden++); 01895 ip->flags=0; 01896 ip->offset=htons(0); 01897 ip->ttl=32; 01898 ip->prot=prot; 01899 ip->checksum=0; 01900 ip->source_ip=nif->ip_addr; 01901 ip->target_ip=ip_addr; 01902 01903 ip->checksum= count_checksum16(reinterpret_cast<uint16*>(ip), sizeof(struct ip_header)/sizeof(uint16)); 01904 struct Option<struct ethernet_address> eth_addr = Net::Arp::arp_get_ether(ip_addr); 01905 if (eth_addr.isNone()) { 01906 ip_outbound_lock.lock(); 01907 Thread::Timer::avltree_insert_with_timer(DEF_SECOND*30, 01908 ip_outbound, 01909 Tuple2<struct ip_address, struct netbuf*>( 01910 ip_addr, 01911 new netbuf(pb->end - pb->ip_off, &pb->data[pb->ip_off], (0), nif) 01912 ) 01913 ); 01914 ip_outbound_lock.ulock(); 01915 } else { 01916 01917 eth_transmit(nif, eth_addr.get(), 0x0800, new netbuf(pb->end-pb->ip_off, &pb->data[pb->ip_off], (0), nif)); 01918 } 01919 } 01920 } 01921 }