00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "src/common/shared.hpp"
00019 #include "src/mboot.hpp"
00020 #include "src/memory/memset.hpp"
00021 #include "src/memory/alloc4k.hpp"
00022 #include "src/memory/align.hpp"
00023 #include "src/memory/pager.hpp"
00024 #include "src/memory/heap.hpp"
00025 #include "src/thread/thread.hpp"
00026 #include "src/thread/scheduler.hpp"
00027 #include "src/thread/process.hpp"
00028 #include "src/module/elf.hpp"
00029 #include "src/module/mods.hpp"
00030
00031 namespace Module {
00032
00033
00034 void init()
00035 {
00036
00037 int i, mcnt= Mboot::mods_count();
00038 uint32 x,n;
00039 static class Memory::Pager::memtree *mtree;
00040 class elf_t elf;
00041 class Memory::Heap::heapbox *hp;
00042 struct Mboot::mod_info *m;
00043 struct Elf32_shdr *sect;
00044 Thread::process_t *p;
00045 bool supervisor;
00046
00047
00048 for(i=0;i<mcnt;i++)
00049 {
00050 supervisor= false;
00051
00052 p= (Thread::process_t*)Memory::Heap::heap0.malloc(sizeof(Thread::process_t),NO_ALIGN,"proc",NULL);
00053 hp= &p->heap;
00054
00055 allocate_heapbox(hp, "proc");
00056
00057 m= Mboot::mods_info(i);
00058 mtree= (class Memory::Pager::memtree*)hp->malloc(sizeof(class Memory::Pager::memtree), NO_ALIGN, "mtree", NULL);
00059 Memory::Pager::allocate_memtree(mtree, supervisor, hp);
00060
00061 p->InitKeepHeap("p0", mtree);
00062
00063 elf.init((char*)m->mod_start,m->mod_end-m->mod_start);
00064
00065
00066 for (x=0;x<elf.ehdr->e_shnum;x++)
00067 {
00068 if ((sect=elf.section(x))->sh_type!=SHT_NOBITS)
00069 continue;
00070
00071 if (sect->sh_size == 0)
00072 continue;
00073
00074 if ((sect->sh_addr > mem_user_end)||
00075 (sect->sh_addr+sect->sh_size > mem_user_end))
00076 { complain("elf: bss section to overlap kernel space"); break; }
00077 for (n=sect->sh_addr;n<sect->sh_addr+sect->sh_size;n+=4096)
00078 mtree->pte_map(n,alloc4k(1,true)|PTE_PRESENT|PTE_WRITEABLE|(supervisor?NULL:PTE_USER));
00079 }
00080
00081 for (x=0;x<elf.ehdr->e_shnum;x++)
00082 {
00083
00084 if ((sect=elf.section(x))->sh_type!=SHT_PROGBITS)
00085 continue;
00086
00087 if (sect->sh_size == 0)
00088 continue;
00089 if (sect->sh_addr==0)
00090 continue;
00091 if ((sect->sh_addr > mem_user_end)||
00092 (sect->sh_addr+sect->sh_size > mem_user_end))
00093 { complain("progbits: section to overlap kernel space"); break; }
00094 for (n=sect->sh_addr;n<sect->sh_addr+sect->sh_size;n+=4096)
00095 if (mtree->pte_val(n)==NULL)
00096 mtree->pte_map(n,alloc4k(1,true)|PTE_PRESENT|PTE_WRITEABLE|(supervisor?NULL:PTE_USER));
00097
00098
00099 memmove2(mtree, (void*)sect->sh_addr, &Memory::Pager::kmem, &elf.image[sect->sh_offset], sect->sh_size);
00100 }
00101
00102 elf.done();
00103
00104
00105 p->create_thread(supervisor, mem_exec, 10, 3, "user0");
00106 mtree->pte_map(0, 0xb8007);
00107
00108 ProcessRegister(p);
00109 }
00110 }
00111
00112
00113 };
00114
00115
00116
00117
00118
00119
00120
00121