public static unsafe void DumpElfInfo() { var secLength = OriginalKernelElf.SectionHeaderCount; KernelMessage.WriteLine("Found {0} Kernel Sections:", secLength); for (uint i = 0; i < secLength; i++) { var sec = OriginalKernelElf.GetSectionHeader(i); var name = OriginalKernelElf.GeSectionName(sec); var sb = new StringBuffer(name); KernelMessage.WriteLine(sb); } }
private static unsafe Process StartProcessFromElf(ElfSections elf, string path, uint argumentBufferSize = 0) { var proc = CreateEmptyProcess(new ProcessCreateOptions() { User = true }); KernelMessage.WriteLine("Create proc: {0}, PID: {1}", path, proc.ProcessID); proc.Path = path; proc.PageTable = PageTable.CreateInstance(); var allocator = new UserInitialPageAllocator() { DebugName = "UserInitial" }; allocator.Setup(new MemoryRegion(500 * 1024 * 1024, 60 * 1024 * 1014), AddressSpaceKind.Virtual); proc.UserPageAllocator = allocator; // Setup User PageTable proc.PageTableAllocAddr = VirtualPageManager.AllocatePages( KMath.DivCeil(proc.PageTable.InitalMemoryAllocationSize, 4096), new AllocatePageOptions { Pool = PageAllocationPool.Identity }); PageTable.KernelTable.SetWritable(proc.PageTableAllocAddr, proc.PageTable.InitalMemoryAllocationSize); proc.PageTable.UserProcSetup(proc.PageTableAllocAddr); proc.PageTable.Map(proc.PageTableAllocAddr, proc.PageTableAllocAddr, proc.PageTable.InitalMemoryAllocationSize); proc.PageTable.MapCopy(PageTable.KernelTable, BootInfoMemoryType.KernelTextSegment); proc.PageTable.SetExecutable(BootInfoMemoryType.KernelTextSegment); proc.PageTable.MapCopy(PageTable.KernelTable, Address.InterruptControlBlock, 4096); proc.PageTable.MapCopy(PageTable.KernelTable, KernelMemoryMapManager.Header->Used.GetMap(BootInfoMemoryType.GDT)); proc.PageTable.MapCopy(PageTable.KernelTable, KernelMemoryMapManager.Header->Used.GetMap(BootInfoMemoryType.IDT)); proc.PageTable.MapCopy(PageTable.KernelTable, KernelMemoryMapManager.Header->Used.GetMap(BootInfoMemoryType.TSS)); var tmpKernelElfHeaders = SetupElfHeader(proc, elf); // Setup ELF Sections for (uint i = 0; i < elf.SectionHeaderCount; i++) { var section = elf.GetSectionHeader(i); var name = elf.GeSectionName(section); var size = section->Size; var virtAddr = section->Addr; var srcAddr = elf.GetSectionPhysAddr(section); if (size == 0) { continue; } if (virtAddr == Addr.Zero) { var mem = allocator.AllocatePagesAddr(KMath.DivCeil(size, 4096)); tmpKernelElfHeaders[i].Addr = mem; virtAddr = mem; } var sb = new StringBuffer(); sb.Append("Map section "); sb.Append(name); sb.Append(" virt={0:X8} src={1:X8} size={2:X8}", virtAddr, srcAddr, size); KernelMessage.WriteLine(sb); //MemoryOperation.Copy4(elf.GetSectionPhysAddr(section), section->Addr, section->Size); // Map the Sections proc.PageTable.MapCopy(PageTable.KernelTable, srcAddr, virtAddr, size); if (name->Equals(".text")) { proc.PageTable.SetExecutable(virtAddr, size); } } KernelMessage.WriteLine("proc sections are ready"); // Detect Thread-Main var entryPoint = GetEntryPointFromElf(elf); KernelMessage.WriteLine("EntryPoint: {0:X8}", entryPoint); var mainThread = Scheduler.CreateThread(proc, new ThreadStartOptions(entryPoint) { ArgumentBufferSize = argumentBufferSize, AllowUserModeIOPort = true, DebugName = "UserProcMainThread", }); KernelMessage.WriteLine("Starting {0} on Thread {1}", path, mainThread.ThreadID); proc.Start(); return(proc); }