00001 /*********************************************************** 00002 *PANALIX 0.06, (c) Adrian Panasiuk 2002-4 * 00003 *adek336[at]o2.pl, panalix.prv.pl * 00004 *under GPLv3 license * 00005 * * 00006 *panalix - small osdev project * 00007 ************************************************************ 00008 * shared.cpp, version 1.0 * 00009 ************************************************************ 00010 * * 00011 *shared code, which is used by a vast majority of all * 00012 *source files. * 00013 * * 00014 *17'04'04- first revision (1.0) * 00015 * * 00016 ***********************************************************/ 00017 00018 #include "src/common/shared.hpp" 00019 #include "src/common/kmalloc.hpp" 00020 #include "src/memory/memset.hpp" 00021 00022 void dso_handle() asm ("__dso_handle"); 00023 void cxa_atexit() asm ("__cxa_atexit"); 00024 00025 extern "C" { 00026 void *memcpy (void *dest, void *src, uint32 size) { 00027 memmove(dest,src,size); 00028 return dest; 00029 } 00030 } 00031 00032 #if 0 00033 void print(char n[]) { 00034 kprintf("%s", n); 00035 } 00036 #endif 00037 00038 00039 00040 void dso_handle() { 00041 sysfail("dso_handle: fatal"); 00042 } 00043 00044 void cxa_atexit() { 00045 sysfail("cxa_atexit: fatal"); 00046 } 00047 00049 void * operator new(size_t s) { 00050 void * p = kmalloc(s,"new"); 00051 if (p==0) 00052 sysfail("new: failure"); 00053 return p; 00054 } 00055 00056 void reboot() { 00057 lnDbg ; 00058 asm volatile("cli"); 00060 while (1) 00061 asm volatile("lidt 0x100000 \nint $0"); 00062 } 00063 00069 char digitOfUint(uint32 n, uint32 div) { 00070 char *l = const_cast<char*>("0123456789abcdef"); 00071 return l[ (n/div) % 16 ]; 00072 } 00073 00074 static int dbPrintIntRow = 0; 00076 void dbPrintInt(uint32 n) { 00077 char *ptr = (char*)0xb8000; 00078 for (uint32 offset=24, div=1; offset >= 10; offset-=2, div*=0x10) { 00079 ptr[offset+dbPrintIntRow*160]=digitOfUint( n, div ); 00080 ptr[offset+dbPrintIntRow*160+1]=' '; 00081 } 00082 dbPrintIntRow++; 00083 if (dbPrintIntRow >= 25) 00084 dbPrintIntRow = 0; 00085 } 00086 void dbSetRow(uint32 n) { 00087 assert(n < 25); 00088 dbPrintIntRow=n; 00089 } 00090 00091 // #ifdef DISCARD_BOOT 00092 // /*data. returns count of pages freed*/ 00093 // DISCARDABLE_CODE ( uint32 discard_ddata() ) 00094 // { 00095 // uint32 i; 00096 // /*first page of the d_data section*/ 00097 // /*physical addr of d_data's first page, masek with 0xffff_f000 to discard 00098 // paging flags. shr 12 to convert a phys addr into page number*/ 00099 // uint32 d_data_page = ((kmem.virt2phys((uint32)d_data)) & 0xFFFFF000) >> 12; 00100 // /*first page of the bss section*/ 00101 // uint32 bss_page = ((kmem.virt2phys((uint32)bss)) & 0xFFFFF000) >> 12; 00102 // 00103 // // unalloc all pages in the range of (uint32)d_data to (uint32)bss, where we store discardable data*/ 00104 // for (i=d_data_page; i < bss_page; i++) 00105 // disalloc4k(i); 00106 // 00107 // /*return discarded page count*/ 00108 // return bss_page - d_data_page; 00109 // } 00110 // 00111 // /*code. returns count of pages freed*/ 00112 // uint32 discard_dcode() 00113 // { 00114 // uint32 i; 00115 // /*first page of the d_code section*/ 00116 // /*physical addr of d_code's first page, masek with 0xffff_f000 to discard 00117 // paging flags. shr 12 to convert a phys addr into page number*/ 00118 // uint32 d_code_page = ((kmem.virt2phys((uint32)d_code)) & 0xFFFFF000) >> 12; 00119 // /*first page of the data section*/ 00120 // uint32 data_page = ((kmem.virt2phys((uint32)data)) & 0xFFFFF000) >> 12; 00121 // 00122 // // unalloc all pages in the range of (uint32)d_code to (uint32)data, where we store discardable code*/ 00123 // for (i=d_code_page; i < data_page; i++) 00124 // disalloc4k(i); 00125 // 00126 // /*return discarded page count*/ 00127 // return data_page - d_code_page; 00128 // } 00129 // #endif 00130 // 00131 // /*data + code*/ 00132 // void discard_mem() 00133 // { 00134 // #ifdef DISCARD_BOOT 00135 // 00136 // uint32 count = 0; 00137 // /*discard data and code and count how much pages discarded*/ 00138 // count += discard_ddata(); 00139 // count += discard_dcode(); 00140 // 00141 // /*message for user*/ 00142 // kprintf("Freeing unused kernel memory: %dkb freed\n\n", count * 4); /*1 page == 4 kb*/ 00143 // 00144 // #endif 00145 // } 00146 00147 /*********************************************************** 00148 * * 00149 *panalix 0.06 (c) Adrian Panasiuk 2002-4 * 00150 *adek336[at]o2.pl, panalix.prv.pl * 00151 * * 00152 ***********************************************************/