Example #1
0
def collect_extension_element(extension_el, pd, namespace, rp_elf, image,
                              machine, bootinfo, pools):
    # New namespace for objects living in the extension.
    extn_namespace = namespace.add_namespace(extension_el.name)

    elf = None
    start = None
    name = None
    physpool = getattr(extension_el, 'physpool', None)
    pager = getattr(extension_el, 'pager', None)
    direct = getattr(extension_el, 'direct', None)

    # Push the overriding pools for the extension.
    image.push_attrs(physical=physpool, pager=pager, direct=direct)

    if hasattr(extension_el, "file"):
        elf = UnpreparedElfFile(filename=extension_el.file)

        if elf.elf_type != ET_EXEC:
            raise MergeError, "All the merged ELF files must be of EXEC type."

        segment_els = extension_el.find_children("segment")
        segs = collect_elf_segments(elf, image.EXTENSION, segment_els,
                                    extension_el.name, extn_namespace, image,
                                    machine, pools)

        segs_ms = [
            bootinfo.record_segment_info(extension_el.name, seg, image,
                                         machine, pools) for seg in segs
        ]
        for seg_ms in segs_ms:
            pd.attach_memsection(seg_ms)

        # Record any patches being made to the program.
        patch_els = extension_el.find_children("patch")
        collect_patches(elf, patch_els, extension_el.file, image)

        start = elf.entry_point
        name = extension_el.file

    if hasattr(extension_el, "start"):
        start = extension_el.start
        name = extension_el.name

        # If no file is supplied, look for symbols in the root
        # program.
        if elf is None:
            elf = rp_elf

    elf = elf.prepare(elf.wordsize, elf.endianess)
    start = start_to_value(start, elf)

    bootinfo.add_elf_info(name=name,
                          elf_type=image.EXTENSION,
                          entry_point=start)

    image.pop_attrs()
Example #2
0
def collect_thread(elf, el, ignore_name, namespace, image, machine,
                   pools, space, entry, name = None,
                   namespace_thread_name = None, cell_create_thread = False):
    """Collect the attributes of a thread element."""
    if entry is None:
        raise MergeError, "No entry point specified for thread %s" % name

    # el can be a program element or a thread element.
    if name is None:
        name = el.name

    user_main = getattr(el, 'start', None)

    # HACK:  There is no easy way for a PD to specify the main thread,
    # so is the user entry point is '_start' (the traditional entry
    # point symbol), then start there rather then the thread entry
    # point.
    if user_main == "_start":
        user_main = None

    entry = start_to_value(entry, elf)
    user_main = start_to_value(user_main, elf)

    # XXX: Iguana only runs on Micro, so default prio is 100!
    priority = getattr(el, 'priority', 100)
    physpool = getattr(el, 'physpool', None)
    virtpool = getattr(el, 'virtpool', None)

    # New namespace for objects living in the thread.
    if namespace_thread_name is None:
        namespace_thread_name = name
    new_namespace = namespace.add_namespace(namespace_thread_name)

    # Push the overriding pools for the thread.
    image.push_attrs(virtual = virtpool,
                     physical = physpool)

    # Create the thread desription object.
    thread = Thread(name, entry, user_main, priority)

    utcb = image.new_attrs(new_namespace.add_namespace("utcb"))
    # Create the cell thread and assign the entry point
    cell_thread = space.register_thread(entry, user_main, utcb,
                                        priority,
                                        create = cell_create_thread)
    cell_thread.ip = entry

    # Add the standard caps for the thread.
    create_standard_caps(thread, new_namespace)

    # Collect the stack.  Is there no element, create a fake one for
    # the collection code to use.
    stack_el = el.find_child('stack')

    if stack_el is None:
        stack_el = ParsedElement('stack')

    stack_ms = collect_memsection_element(stack_el, ignore_name,
                                          new_namespace, image,
                                          machine, pools)
    thread.attach_stack(stack_ms)
    # Setup the stack for the new cell thread
    cell_thread.stack = stack_ms.get_ms().attrs

    # Collect any command line arguments.
    commandline_el = el.find_child('commandline')

    if commandline_el is not None:
        for arg_el in commandline_el.find_children("arg"):
            thread.add_argv(arg_el.value)

    image.pop_attrs()

    return thread
Example #3
0
def collect_thread(elf, el, ignore_name, namespace, image, machine,
                   pools, entry, name = None,
                   namespace_thread_name = None):
    """Collect the attributes of a thread element."""
    if entry is None:
        raise MergeError, "No entry point specified for thread %s" % name

    # el can be a program element or a thread element.
    if name is None:
        name = el.name

    user_main = getattr(el, 'start', None)

    # HACK:  There is no easy way for a PD to specify the main thread,
    # so is the user entry point is '_start' (the traditional entry
    # point symbol), then start there rather then the thread entry
    # point.
    if user_main == "_start":
        start = "_start"
        user_main = None

    entry = start_to_value(entry, elf)
    user_main = start_to_value(user_main, elf)

    priority = getattr(el, 'priority', None)
    physpool = getattr(el, 'physpool', None)
    virtpool = getattr(el, 'virtpool', None)

    # New namespace for objects living in the thread.
    if namespace_thread_name is None:
        namespace_thread_name = name
    new_namespace = namespace.add_namespace(namespace_thread_name)

    # Push the overriding pools for the thread.
    image.push_attrs(virtual = virtpool,
                     physical = physpool)

    # Create the thread desription object.
    thread = weaver.bootinfo.Thread(name, entry, user_main, priority)

    # Add the standard caps for the thread.
    create_standard_caps(thread, new_namespace)

    # Collect the stack.  Is there no element, create a fake one for
    # the collection code to use.
    stack_el = el.find_child('stack')

    if stack_el is None:
        stack_el = ParsedElement('stack')

    stack_ms = collect_memsection_element(stack_el, ignore_name,
                                          new_namespace, image,
                                          machine, pools)
    thread.attach_stack(stack_ms)
    image.add_group(0, [stack_ms.get_ms()])

    # Collect any command line arguments.
    commandline_el = el.find_child('commandline')

    if commandline_el is not None:
        for arg_el in commandline_el.find_children("arg"):
            thread.add_argv(arg_el.value)

    image.pop_attrs()

    return thread
Example #4
0
def collect_extension_element(extension_el, pd, namespace, rp_elf, image, machine, bootinfo, pools):
    # New namespace for objects living in the extension.
    extn_namespace = namespace.add_namespace(extension_el.name)

    elf   = None
    start = None
    name  = None
    physpool = getattr(extension_el, 'physpool', None)
    pager    = getattr(extension_el, 'pager', None)
    direct   = getattr(extension_el, 'direct', None)

    # Push the overriding pools for the extension.
    image.push_attrs(physical = physpool,
                                  pager    = pager,
                                  direct   = direct)

    if hasattr(extension_el, "file"):
        elf = UnpreparedElfFile(filename=extension_el.file)

        if elf.elf_type != ET_EXEC:
            raise MergeError, "All the merged ELF files must be of EXEC type."

        segment_els = extension_el.find_children("segment")
        segs = collect_elf_segments(elf,
                                    image.EXTENSION,
                                    segment_els,
                                    extension_el.name,
                                    extn_namespace,
                                    image,
                                    machine,
                                    pools)

        segs_ms = [bootinfo.record_segment_info(extension_el.name,
                                                seg, image, machine, pools) for seg in segs]
        for seg_ms in segs_ms:
            pd.attach_memsection(seg_ms)

        # Record any patches being made to the program.
        patch_els   = extension_el.find_children("patch")
        collect_patches(elf, patch_els, extension_el.file, image)

        start = elf.entry_point
        name  = extension_el.file

    if hasattr(extension_el, "start"):
        start = extension_el.start
        name  = extension_el.name

        # If no file is supplied, look for symbols in the root
        # program.
        if elf is None:
            elf = rp_elf

    elf = elf.prepare(elf.wordsize, elf.endianess)
    start = start_to_value(start, elf)

    bootinfo.add_elf_info(name = name,
                          elf_type = image.EXTENSION,
                          entry_point = start)

    image.pop_attrs()
Example #5
0
    def collect_thread(self,
                       elf,
                       el,
                       namespace,
                       image,
                       machine,
                       pools,
                       kernel,
                       space,
                       entry,
                       thread_name=None,
                       cell_create_thread=False):
        """Collect the attributes of a thread element."""
        if entry is None:
            raise MergeError, "No entry point specified for thread %s" % el.name

        user_main = getattr(el, 'start', entry)

        entry = start_to_value(entry, elf)
        user_main = start_to_value(user_main, elf)

        priority = getattr(el, 'priority', kernel.kernel.DEFAULT_PRIORITY)
        physpool = getattr(el, 'physpool', None)
        virtpool = getattr(el, 'virtpool', None)

        # New namespace for objects living in the thread.
        if thread_name == None:
            thread_name = el.name
        thread_namespace = namespace.add_namespace(thread_name)

        # Push the overriding pools for the thread.
        image.push_attrs(virtual=virtpool, physical=physpool)

        utcb = image.new_attrs(thread_namespace.add_namespace("utcb"))
        # Create the cell thread and assign the entry point
        thread = space.register_thread(entry,
                                       user_main,
                                       utcb,
                                       priority,
                                       create=cell_create_thread)

        thread_namespace.add('master', ThreadCellCap('master', thread))

        # Collect the stack.  Is there no element, create a fake one for
        # the collection code to use.
        stack_el = el.find_child('stack')
        if stack_el is None:
            stack_el = ParsedElement('stack')

        stack_attr = collect_memobj_attrs(stack_el, thread_namespace, image,
                                          machine)

        if stack_attr.size == None:
            stack_attr.size = DEFAULT_STACK_SIZE

        stack_ms = image.add_memsection(stack_attr, machine, pools)
        mapping = space.register_mapping(stack_ms.attrs)

        self.add_standard_mem_caps(stack_attr.ns_node, mapping, stack_attr)

        # Setup the stack for the new cell thread
        thread.stack = stack_ms.attrs
        thread.stack_ms = stack_ms

        # If this is the very first collect_thread call, we assume it is
        # the cell's main thread and we set the stack_ms accordingly.
        if self.stack_ms is None:
            self.stack_ms = stack_ms

        image.pop_attrs()

        return thread
Example #6
0
    def collect_thread(self, elf, el, namespace, image, machine,
                       pools, kernel, space, entry,
                       thread_name = None,
                       cell_create_thread = False):
        """Collect the attributes of a thread element."""
        if entry is None:
            raise MergeError, "No entry point specified for thread %s" % el.name

        user_main = getattr(el, 'start', entry)

        entry = start_to_value(entry, elf)
        user_main = start_to_value(user_main, elf)

        priority = getattr(el, 'priority', kernel.kernel.DEFAULT_PRIORITY)
        physpool = getattr(el, 'physpool', None)
        virtpool = getattr(el, 'virtpool', None)

        # New namespace for objects living in the thread.
        if thread_name == None:
            thread_name = el.name
        thread_namespace = namespace.add_namespace(thread_name)

        # Push the overriding pools for the thread.
        image.push_attrs(virtual = virtpool,
                         physical = physpool)

        utcb = image.new_attrs(thread_namespace.add_namespace("utcb"))
        # Create the cell thread and assign the entry point
        thread = space.register_thread(entry, user_main, utcb,
                                       priority,
                                       create = cell_create_thread)

        thread_namespace.add('master', ThreadCellCap('master', thread))

        # Collect the stack.  Is there no element, create a fake one for
        # the collection code to use.
        stack_el = el.find_child('stack')
        if stack_el is None:
            stack_el = ParsedElement('stack')

        stack_attr = collect_memobj_attrs(stack_el, thread_namespace,
                                          image, machine)

        if stack_attr.size == None:
            stack_attr.size = DEFAULT_STACK_SIZE

        stack_ms = image.add_memsection(stack_attr, machine, pools)
        mapping = space.register_mapping(stack_ms.attrs)

        self.add_standard_mem_caps(stack_attr.ns_node,
                                   mapping, stack_attr)

        # Setup the stack for the new cell thread
        thread.stack = stack_ms.attrs
        thread.stack_ms = stack_ms

        # If this is the very first collect_thread call, we assume it is
        # the cell's main thread and we set the stack_ms accordingly.
        if self.stack_ms is None:
            self.stack_ms = stack_ms

        image.pop_attrs()

        return thread