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 * init.cpp, version 1.0 * 00009 ************************************************************ 00010 * * 00011 *gives the startup/done functions for static class * 00012 *for static class initialisation, etc. * 00013 * * 00014 *18'04'04- first revision (1.0) * 00015 * * 00016 *based on cpprtl.cpp from panalix 0.05; * 00017 *based heavily on "Writing a kernel in C++", * 00018 *Invalid Software * 00019 *http://www.invalidsoftware.net/os/?the_id=11 * 00020 ***********************************************************/ 00021 00022 #include "src/common/shared.hpp" 00023 #include "src/init.hpp" 00024 00025 /*call all static classes constructors*/ 00026 void init_class() 00027 { 00028 extern void (*__CTOR_LIST__) (); //get constructor list 00029 void (**constructor)() = &__CTOR_LIST__; //(*constructor) will point at each list item 00030 00031 int total = (int) *constructor; //first item is constructor count 00032 00033 constructor++; //move to first constructor 00034 while (total) 00035 { 00036 (*constructor)(); //let's call it! 00037 total--; 00038 constructor++; 00039 } 00040 00041 } 00042 00043 /*call all the handy destructors*/ 00044 void done_class() 00045 { 00046 extern void (*__DTOR_LIST__) (); //get destructor list 00047 void (**destructor)() = &__DTOR_LIST__; //(*destructor) will point at each list item 00048 00049 int total = (int) *destructor; //first item is destructor count 00050 00051 destructor += total; //we have to destruct classes in opposite manner than we constructed them 00052 00053 while (total) 00054 { 00055 (*destructor)(); //let's call it! 00056 total--; 00057 destructor--; 00058 } 00059 } 00060 00061 /*other inits*/ 00062 void pre_init() 00063 { 00064 } 00065 00066 void post_done() 00067 { 00068 } 00069 00070 /*********************************************************** 00071 * * 00072 *panalix 0.06 (c) Adrian Panasiuk 2002-4 * 00073 *adek336[at]o2.pl, panalix.prv.pl * 00074 * * 00075 ***********************************************************/