def collect_rootprogram_element(parsed, ignore_name, namespace, image, machine, bootinfo, pools): """Handle an Iguana Server Compound Object""" # Find the tag root_program_el = parsed.find_child("rootprogram") assert(root_program_el is not None) # New namespace for objects living in the root program's PD. rp_namespace = namespace.add_namespace('rootprogram') pd = weaver.bootinfo.RootServerPD('rootserver', rp_namespace, image, machine, pools) # Declare the default memory pools. def_virtpool = getattr(root_program_el, "virtpool", None) def_physpool = getattr(root_program_el, "physpool", None) def_pager = getattr(root_program_el, "pager", None) def_direct = getattr(root_program_el, "direct", None) bootinfo.set_system_default_attrs(def_virtpool, def_physpool, image, def_pager, def_direct) elf = UnpreparedElfFile(filename=root_program_el.file) if elf.elf_type != ET_EXEC: raise MergeError, "All the merged ELF files must be of EXEC type." # Record the entry point of the root program so that the kernel # can start it. image.kconfig.set_rootserver_entry(elf.entry_point) pd.set_default_pools(image, bootinfo) # Collect the object environment env = collect_environment_element(root_program_el.find_child('environment'), rp_namespace, machine, pools, image, bootinfo) segment_els = root_program_el.find_children("segment") collect_elf_segments(elf, image.ROOT_PROGRAM, segment_els, root_program_el.file, rp_namespace, image, machine, pools) # Record any patches being made to the program. patch_els = root_program_el.find_children("patch") for p in getattr(RootProgram_el, "extra_patches", []): addr = get_symbol(elf, p[0], True) if addr == None: continue addr = int(addr[0])+ int(p[1]) new_patch = Patch_el(address=hex(addr), bytes=p[2], value=p[3]) patch_els.append(new_patch) collect_patches(elf, patch_els, root_program_el.file, image) for extension_el in root_program_el.find_children("extension"): if not ignore_name.match(extension_el.name): collect_extension_element(extension_el, pd, rp_namespace, elf, image, machine, bootinfo, pools) # Collect the main thread. The root program can only have one # thread, so this call chiefly is used to collect information # about the stack. # # The stack is not set up as a memsection, so it is not put in the # object environment. thread = collect_thread(elf, root_program_el, ignore_name, rp_namespace, image, machine, pools, entry = elf.entry_point, name = 'rootprogram', namespace_thread_name = "main") pd.add_thread(thread) # Collect the heap. Is there no element, create a fake one for # the collection code to use. # # The heap is not set up as a memsection, so it is not put in the # object environment. heap_el = root_program_el.find_child('heap') if heap_el is None: heap_el = ParsedElement('heap') heap_ms = collect_memsection_element(heap_el, ignore_name, rp_namespace, image, machine, pools) pd.attach_heap(heap_ms) image.add_group(0, [heap_ms.get_ms()]) pd.add_environment(env) bootinfo.add_rootserver_pd(pd)
def collect_rootprogram_element(parsed, ignore_name, namespace, image, machine, bootinfo, pools): """Handle an Iguana Server Compound Object""" # Find the tag root_program_el = parsed.find_child("rootprogram") assert (root_program_el is not None) # New namespace for objects living in the root program's PD. rp_namespace = namespace.add_namespace('rootprogram') pd = weaver.bootinfo.RootServerPD('rootserver', rp_namespace, image, machine, pools) # Declare the default memory pools. def_virtpool = getattr(root_program_el, "virtpool", None) def_physpool = getattr(root_program_el, "physpool", None) def_pager = getattr(root_program_el, "pager", None) def_direct = getattr(root_program_el, "direct", None) bootinfo.set_system_default_attrs(def_virtpool, def_physpool, image, def_pager, def_direct) elf = UnpreparedElfFile(filename=root_program_el.file) if elf.elf_type != ET_EXEC: raise MergeError, "All the merged ELF files must be of EXEC type." # Record the entry point of the root program so that the kernel # can start it. image.kconfig.set_rootserver_entry(elf.entry_point) pd.set_default_pools(image, bootinfo) # Collect the object environment env = collect_environment_element( root_program_el.find_child('environment'), rp_namespace, machine, pools, image, bootinfo) segment_els = root_program_el.find_children("segment") collect_elf_segments(elf, image.ROOT_PROGRAM, segment_els, root_program_el.file, rp_namespace, image, machine, pools) # Record any patches being made to the program. patch_els = root_program_el.find_children("patch") for p in getattr(RootProgram_el, "extra_patches", []): addr = get_symbol(elf, p[0], True) if addr == None: continue addr = int(addr[0]) + int(p[1]) new_patch = Patch_el(address=hex(addr), bytes=p[2], value=p[3]) patch_els.append(new_patch) collect_patches(elf, patch_els, root_program_el.file, image) for extension_el in root_program_el.find_children("extension"): if not ignore_name.match(extension_el.name): collect_extension_element(extension_el, pd, rp_namespace, elf, image, machine, bootinfo, pools) # Collect the main thread. The root program can only have one # thread, so this call chiefly is used to collect information # about the stack. # # The stack is not set up as a memsection, so it is not put in the # object environment. thread = collect_thread(elf, root_program_el, ignore_name, rp_namespace, image, machine, pools, entry=elf.entry_point, name='rootprogram', namespace_thread_name="main") pd.add_thread(thread) # Collect the heap. Is there no element, create a fake one for # the collection code to use. # # The heap is not set up as a memsection, so it is not put in the # object environment. heap_el = root_program_el.find_child('heap') if heap_el is None: heap_el = ParsedElement('heap') heap_ms = collect_memsection_element(heap_el, ignore_name, rp_namespace, image, machine, pools) pd.attach_heap(heap_ms) image.add_group(0, [heap_ms.get_ms()]) pd.add_environment(env) bootinfo.add_rootserver_pd(pd)