00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include <utility/elf.h>
00014 #include <utility/debug.h>
00015 #include <system/kmalloc.h>
00016 #include <system/initializer.h>
00017 #include <machine.h>
00018 #include <address_space.h>
00019 #include <segment.h>
00020 #include <mutex.h>
00021 #include <semaphore.h>
00022 #include <condition.h>
00023 #include <alarm.h>
00024 #include <clock.h>
00025 #include <chronometer.h>
00026 #include <thread.h>
00027 #include <utility/malloc.h>
00028
00029 extern "C" { void __epos_library_app_entry(void); }
00030
00031 __BEGIN_SYS
00032
00033 extern System_Info * si;
00034 extern char * _sys_heap;
00035
00036 Initializer::Dispatcher * Initializer::init_table[] = INIT_TABLE;
00037
00038 Initializer::Initializer(System_Info * si)
00039 {
00040 db<Init>(INF) << "si(" << (void *)si << ")={msize=" << si->mem_size
00041 << ",free=" << si->mem_free << "}\n";
00042
00043
00044 db<Init>(INF) << "iomm_size = " << (void*)si->iomm_size << "\n";
00045 for(unsigned int i = 0; i < si->iomm_size; i++)
00046 db<Init>(INF) << "iomm[" << i
00047 << "]={loc=" << (void *)si->iomm[i].locator
00048 << ",phy=" << (void *)si->iomm[i].phy_addr
00049 << ",log=" << (void *)si->iomm[i].log_addr
00050 << ",size=" << si->iomm[i].size << "}\n";
00051
00052 // Double check if we have a heap
00053 sys_heap.free(&_sys_heap, Traits<Machine>::SYSTEM_HEAP_SIZE);
00054 int * tmp = (int *)kmalloc(sizeof(int));
00055 if(!tmp) {
00056 db<Init>(ERR) << "It won't work: we don't have a heap!\n";
00057 CPU::halt();
00058 } else
00059 db<Init>(INF) << "heap=" << (void *)tmp << "\n";
00060 kfree(tmp);
00061
00062 if(si->bm.system_off == -1) // EPOS is a library
00063 si->lmm.app_entry =
00064 reinterpret_cast<unsigned int>(__epos_library_app_entry);
00065
00066 // Initialize EPOS abstractions
00067 db<Init>(INF) << "Initializing EPOS abstractions: \n";
00068 for(unsigned int i = 0; init_table[i] != __LAST_INIT; i++)
00069 init_table[i](si);
00070 db<Init>(INF) << "done! \n";
00071
00072 // Initialize the application's heap
00073 app_heap.free(
00074 MMU::alloc(MMU::pages(Traits<Machine>::APPLICATION_HEAP_SIZE)),
00075 Traits<Machine>::APPLICATION_HEAP_SIZE);
00076
00077 // Initialize the Thread abstraction, thus creating the first thread
00078 db<Init>(INF) << "Starting first process ...\n";
00079 Thread::init(si);
00080
00081 // This point won't be reached if a member of the Thread family was
00082 // selected, since the cooresponding initialization will activate the
00083 // first thread
00084 reinterpret_cast<Function *>(si->lmm.app_entry)();
00085 }
00086
00087 // Global object initializer
00088 Initializer initializer(si);
00089
00090 __END_SYS