Пример #1
0
def collect_memsection_element(ms_el, ignore_name, namespace, image, machine,
                               pools):
    """Collect the details of a memsection, or other mem obj, element."""
    attrs = collect_memobj_attrs(ms_el, namespace, image, machine)

    # New namespace for objects living in the memsection.
    ms_namespace = attrs.ns_node

    memsect = \
            weaver.cells.iguana.bootinfo.MemSection(image, machine,
                                                    pools, attrs = attrs)

    # Add the standard caps for the memsection.
    create_standard_caps(memsect, ms_namespace)

    # Collect any custom caps for the memsection.
    for cap_el in ms_el.find_children("cap"):
        if not ignore_name.match(cap_el.name):
            cap = weaver.cells.iguana.bootinfo.Cap(cap_el.name)

            for right in cap_el.find_children("right"):
                cap.add_right(right.value)

            memsect.add_cap(cap)
            ms_namespace.add(cap.get_name(), cap)

    return memsect
Пример #2
0
def collect_memsection_element(ms_el, ignore_name, namespace, image,
                               machine, pools):
    """Collect the details of a memsection, or other mem obj, element."""
    attrs = collect_memobj_attrs(ms_el, namespace, image, machine)

    # New namespace for objects living in the memsection.
    ms_namespace = attrs.ns_node

    memsect = \
            weaver.cells.iguana.bootinfo.MemSection(image, machine,
                                                    pools, attrs = attrs)

    # Add the standard caps for the memsection.
    create_standard_caps(memsect, ms_namespace)

    # Collect any custom caps for the memsection.
    for cap_el in ms_el.find_children("cap"):
        if not ignore_name.match(cap_el.name):
            cap = weaver.cells.iguana.bootinfo.Cap(cap_el.name)
    
            for right in cap_el.find_children("right"):
                cap.add_right(right.value)

            memsect.add_cap(cap)
            ms_namespace.add(cap.get_name(), cap)

    return memsect
Пример #3
0
    def collect_memsections(self, el, space, namespace, image, machine, pools):

        memsection_objs = []

        for memsection_el in el.find_children('memsection'):
            memsection_attr = \
                        collect_memobj_attrs(memsection_el, namespace,
                                             image, machine)
            memsection_ns = memsection_attr.ns_node
            memsection_ms = image.add_memsection(memsection_attr, machine,
                                                 pools)
            memsection_objs.append(memsection_ms)
            mapping = space.register_mapping(memsection_ms.attrs)
            self.add_standard_mem_caps(memsection_ns, mapping,
                                       memsection_ms.attrs)

        return memsection_objs
Пример #4
0
    def collect_memsections(self, el, space, namespace, image, machine,
                            pools):

        memsection_objs = []

        for memsection_el in el.find_children('memsection'):
            memsection_attr = \
                        collect_memobj_attrs(memsection_el, namespace,
                                             image, machine)
            memsection_ns = memsection_attr.ns_node
            memsection_ms = image.add_memsection(memsection_attr, machine,
                                                 pools)
            memsection_objs.append(memsection_ms)
            mapping = space.register_mapping(memsection_ms.attrs)
            self.add_standard_mem_caps(memsection_ns, mapping,
                                       memsection_ms.attrs)

        return memsection_objs
Пример #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
Пример #6
0
    def collect_xml(self, okl4_el, ignore_name, namespace, machine, pools,
                    kernel, image):
        """Handle an Iguana Server Compound Object"""
        self.cell = \
             kernel.register_cell(okl4_el.name,
                                  okl4_el.kernel_heap,
                                  max_caps = getattr(okl4_el, "caps", None),
                                  max_priority = getattr(okl4_el, "max_priority", None))
        self.name = okl4_el.name
        self.namespace = namespace.add_namespace(self.name)
        self.space = \
                   self.cell.register_space(self.namespace, "MAIN",
                                is_privileged = True,
                                max_clists = getattr(okl4_el,
                                                     "clists", None),
                                max_spaces = getattr(okl4_el,
                                                     "spaces", None),
                                max_mutexes = getattr(okl4_el,
                                                      "mutexes", None),
                                max_threads = getattr(okl4_el,
                                                      "threads", None),
                                max_priority = getattr(okl4_el,
                                                       "max_priority", None),
                                plat_control = \
                                            getattr(okl4_el,
                                                    "platform_control", False))

        image.push_attrs(virtual=getattr(okl4_el, "virtpool", None),
                         physical=getattr(okl4_el, "physpool", None),
                         pager=make_pager_attr(getattr(okl4_el, "pager",
                                                       None)),
                         direct=getattr(okl4_el, "direct", None))

        (self.def_virtpool, self.def_physpool) = image.current_pools()

        self.collect_mutexes(okl4_el, self.namespace, self.space)

        env_el = okl4_el.find_child("environment")
        self.env = CellEnvironment(okl4_el.name, self.namespace, machine,
                                   image, kernel, self.space.mappings)

        if env_el != None:
            self._collect_environment(env_el, self.env)

        # Set these up now even though we can't actually assign values
        # till later
        self.phys_attrs = image.new_attrs(
            self.namespace.add_namespace("default_physpool"))
        self.phys_attrs.attach = PF_R | PF_W | PF_X
        self.phys_attrs.mem_type = self.phys_attrs.unmapped
        mapping = self.space.register_mapping(self.phys_attrs)
        self.env.add_physmem_segpool_entry("MAIN_PHYSMEM_SEGPOOL", mapping)

        self.virt_attrs = image.new_attrs(
            self.namespace.add_namespace("default_virtpool"))
        self.env.add_virtmem_pool_entry("MAIN_VIRTMEM_POOL", self.virt_attrs)

        self.space.utcb = image.new_attrs(
            self.namespace.add_namespace("main_utcb_area"))
        self.space.utcb.attach = PF_R

        filename = os.path.join(okl4_el._path, okl4_el.file)
        self.elf = UnpreparedElfFile(filename=filename)

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

        # Find out which version of libokl4 that the cell was built
        # against
        sym = self.elf.find_symbol("okl4_api_version")
        if sym == None:
            raise MergeError(
                "Unable to locate the symbol 'okl4_api_version' in file \"%s\".  Cells must link with libokl4."
                % filename)

        self.api_version = self.elf.get_value(sym.value, sym.size,
                                              self.elf.endianess)
        if self.api_version == None:
            raise MergeError(
                "Unable to read the symbol 'okl4_api_version' in file \"%s\".  Cells must link with libokl4."
                % filename)

        self.env.add_elf_info_entry(os.path.basename(okl4_el.file),
                                    image.PROGRAM, self.elf.entry_point)

        segment_els = okl4_el.find_children("segment")
        segs = collect_elf_segments(self.elf, image.PROGRAM, segment_els,
                                    filename, [], self.namespace, image,
                                    machine, pools)
        self.elf_prog_segments = segs

        for seg in segs:
            self.env.add_elf_segment_entry(
                okl4_el.name + '.' + seg.attrs.ns_node.name, seg.segment)
            seg_ns = seg.attrs.ns_node
            mapping = self.space.register_mapping(seg.attrs)
            self.add_standard_mem_caps(seg_ns, mapping, seg.attrs)

        patch_els = okl4_el.find_children("patch")
        collect_patches(self.elf, patch_els, filename, image)

        # Record any IRQs that are assigned to the initial program.
        for irq_el in okl4_el.find_children("irq"):
            self.space.register_irq(irq_el.value)
        self.env.add_device_irq_list("NO_DEVICE",
                                     [irq_el.value for irq_el \
                                      in okl4_el.find_children("irq")])

        # Collect the implicit thread
        if not hasattr(okl4_el, 'priority'):
            okl4_el.priority = kernel.kernel.MAX_PRIORITY

        threads = []
        threads.append(
            self.collect_thread(self.elf, okl4_el, self.namespace, image,
                                machine, pools, kernel, self.space,
                                self.elf.entry_point, "main", True))

        # FIXME: Need to check up on actual entry point's
        for thread_el in okl4_el.find_children("thread"):
            threads.append(
                self.collect_thread(self.elf,
                                    thread_el,
                                    self.namespace,
                                    image,
                                    machine,
                                    pools,
                                    kernel,
                                    self.space,
                                    "thread_start",
                                    cell_create_thread=True))

        device_mem = \
                   self.collect_use_devices(okl4_el, self.space,
                                            self.namespace, image,
                                            machine, pools)

        memsection_objs = \
                    self.collect_memsections(okl4_el, self.space,
                            self.namespace, image, machine, pools)

        # Collect all data for any extra spaces defined in the XML
        for space_el in okl4_el.find_children("space"):
            space_ns = self.namespace.add_namespace(space_el.name)
            space = self.cell.register_space(space_ns, space_el.name,
                        max_priority = getattr(space_el, "max_priority", \
                                       getattr(okl4_el, "max_priority", None)))

            image.push_attrs(virtual=getattr(space_el, "virtpool", None),
                             physical=getattr(space_el, "physpool", None),
                             pager=make_pager_attr(
                                 getattr(space_el, "pager", None)),
                             direct=getattr(space_el, "direct", None))

            for thread_el in space_el.find_children("thread"):
                threads.append(
                    self.collect_thread(self.elf,
                                        thread_el,
                                        space_ns,
                                        image,
                                        machine,
                                        pools,
                                        kernel,
                                        space,
                                        "thread_start",
                                        cell_create_thread=True))

            self.collect_mutexes(space_el, space_ns, space)

            device_mem.extend(
                self.collect_use_devices(space_el, space, space_ns, image,
                                         machine, pools))

            memsection_objs.extend(
                self.collect_memsections(space_el, space, space_ns, image,
                                         machine, pools))

            self.env.add_kspace_entry(space_el.name + "_KSPACE", space)

            space.utcb = image.new_attrs(
                space_ns.add_namespace(space_el.name + "_utcb_area"))
            space.utcb.attach = PF_R

        # Weave a kclist for the main space.
        main_kclist = self.env.add_kclist_entry("MAIN_KCLIST", self.cell)

        # Weave the root kspace object.
        main_kspace = self.env.add_kspace_entry("MAIN_KSPACE", self.space)

        # Weave the root protection domain object.
        self.env.add_pd_entry("MAIN_PD", self.space, main_kspace, 32,
                              machine.min_page_size(), self.elf)

        # Find heap and add it
        heap_el = okl4_el.find_child('heap')
        if heap_el is None:
            heap_el = ParsedElement('heap')

        heap_attr = collect_memobj_attrs(heap_el, self.namespace, image,
                                         machine)

        if heap_attr.size == None:
            heap_attr.size = DEFAULT_HEAP_SIZE

        self.heap_ms = image.add_memsection(heap_attr, machine, pools)
        self.cell.heap = self.heap_ms.attrs
        mapping = self.space.register_mapping(self.heap_ms.attrs)

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

        self.elf_segments = \
                [thread.get_stack_ms() for thread in threads] + \
                [self.heap_ms] + memsection_objs + device_mem

        self.env.add_kernel_info_entry(0, 0, kernel)

        # Add command line arguments
        commandline_el = okl4_el.find_child("commandline")

        if commandline_el is not None:
            args = [
                arg_el.value for arg_el in commandline_el.find_children("arg")
            ]
        else:
            args = []

        self.env.add_arg_list(args)

        self.cell.env = self.env
Пример #7
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
Пример #8
0
    def collect_xml(self, okl4_el, ignore_name, namespace, machine,
                    pools, kernel, image):
        """Handle an Iguana Server Compound Object"""
        self.cell = \
             kernel.register_cell(okl4_el.name,
                                  okl4_el.kernel_heap,
                                  max_caps = getattr(okl4_el, "caps", None),
                                  max_priority = getattr(okl4_el, "max_priority", None))
        self.name = okl4_el.name
        self.namespace = namespace.add_namespace(self.name)
        self.space = \
                   self.cell.register_space(self.namespace, "MAIN",
                                is_privileged = True,
                                max_clists = getattr(okl4_el,
                                                     "clists", None),
                                max_spaces = getattr(okl4_el,
                                                     "spaces", None),
                                max_mutexes = getattr(okl4_el,
                                                      "mutexes", None),
                                max_threads = getattr(okl4_el,
                                                      "threads", None),
                                max_priority = getattr(okl4_el,
                                                       "max_priority", None),
                                plat_control = \
                                            getattr(okl4_el,
                                                    "platform_control", False))

        image.push_attrs(
            virtual  = getattr(okl4_el, "virtpool", None),
            physical = getattr(okl4_el, "physpool", None),
            pager    = make_pager_attr(getattr(okl4_el, "pager", None)),
            direct   = getattr(okl4_el, "direct", None))

        (self.def_virtpool, self.def_physpool) = image.current_pools()

        self.collect_mutexes(okl4_el, self.namespace, self.space)

        env_el = okl4_el.find_child("environment")
        self.env = CellEnvironment(okl4_el.name, self.namespace,
                                   machine, image, kernel, self.space.mappings)

        if env_el != None:
            self._collect_environment(env_el, self.env)

        # Set these up now even though we can't actually assign values
        # till later
        self.phys_attrs = image.new_attrs(self.namespace.add_namespace("default_physpool"))
        self.phys_attrs.attach = PF_R | PF_W | PF_X
        self.phys_attrs.mem_type = self.phys_attrs.unmapped
        mapping = self.space.register_mapping(self.phys_attrs)
        self.env.add_physmem_segpool_entry("MAIN_PHYSMEM_SEGPOOL", mapping)

        self.virt_attrs = image.new_attrs(self.namespace.add_namespace("default_virtpool"))
        self.env.add_virtmem_pool_entry("MAIN_VIRTMEM_POOL", self.virt_attrs)

        self.space.utcb = image.new_attrs(self.namespace.add_namespace("main_utcb_area"))
        self.space.utcb.attach = PF_R

        filename = os.path.join(okl4_el._path, okl4_el.file)
        self.elf = UnpreparedElfFile(filename=filename)

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

        # Find out which version of libokl4 that the cell was built
        # against
        sym = self.elf.find_symbol("okl4_api_version")
        if sym == None:
            raise MergeError("Unable to locate the symbol 'okl4_api_version' in file \"%s\".  Cells must link with libokl4." % filename)

        self.api_version = self.elf.get_value(sym.value, sym.size,
                                              self.elf.endianess)
        if self.api_version == None:
            raise MergeError("Unable to read the symbol 'okl4_api_version' in file \"%s\".  Cells must link with libokl4." % filename)

        self.env.add_elf_info_entry(os.path.basename(okl4_el.file),
                image.PROGRAM, self.elf.entry_point)

        segment_els = okl4_el.find_children("segment")
        segs = collect_elf_segments(self.elf, image.PROGRAM, segment_els,
                                    filename, [], self.namespace, image,
                                    machine, pools)
        self.elf_prog_segments = segs

        for seg in segs:
            self.env.add_elf_segment_entry(okl4_el.name + '.' + seg.attrs.ns_node.name,
                    seg.segment)
            seg_ns = seg.attrs.ns_node
            mapping = self.space.register_mapping(seg.attrs)
            self.add_standard_mem_caps(seg_ns, mapping, seg.attrs)

        patch_els = okl4_el.find_children("patch")
        collect_patches(self.elf, patch_els, filename, image)

        # Record any IRQs that are assigned to the initial program.
        for irq_el in okl4_el.find_children("irq"):
            self.space.register_irq(irq_el.value)
        self.env.add_device_irq_list("NO_DEVICE",
                                     [irq_el.value for irq_el \
                                      in okl4_el.find_children("irq")])

        # Collect the implicit thread
        if not hasattr(okl4_el, 'priority'):
            okl4_el.priority = kernel.kernel.MAX_PRIORITY

        threads = []
        threads.append(self.collect_thread(self.elf, okl4_el, self.namespace,
                image, machine, pools, kernel, self.space, self.elf.entry_point,
                "main", True))

        # FIXME: Need to check up on actual entry point's
        for thread_el in okl4_el.find_children("thread"):
            threads.append(self.collect_thread(self.elf, thread_el,
                    self.namespace, image, machine, pools, kernel,
                    self.space, "thread_start", cell_create_thread = True))

        device_mem = \
                   self.collect_use_devices(okl4_el, self.space,
                                            self.namespace, image,
                                            machine, pools)

        memsection_objs = \
                    self.collect_memsections(okl4_el, self.space,
                            self.namespace, image, machine, pools)

        # Collect all data for any extra spaces defined in the XML
        for space_el in okl4_el.find_children("space"):
            space_ns = self.namespace.add_namespace(space_el.name)
            space = self.cell.register_space(space_ns, space_el.name,
                        max_priority = getattr(space_el, "max_priority", \
                                       getattr(okl4_el, "max_priority", None)))

            image.push_attrs(
                virtual  = getattr(space_el, "virtpool", None),
                physical = getattr(space_el, "physpool", None),
                pager    = make_pager_attr(getattr(space_el, "pager", None)),
                direct   = getattr(space_el, "direct", None))

            for thread_el in space_el.find_children("thread"):
                threads.append(self.collect_thread(self.elf, thread_el,
                        space_ns, image, machine, pools, kernel, space,
                        "thread_start", cell_create_thread = True))

            self.collect_mutexes(space_el, space_ns, space)

            device_mem.extend(
                self.collect_use_devices(space_el, space,
                                         space_ns, image, machine, pools))

            memsection_objs.extend(
                self.collect_memsections(space_el, space, space_ns, image,
                                    machine, pools))

            self.env.add_kspace_entry(space_el.name + "_KSPACE", space)

            space.utcb = image.new_attrs(space_ns.add_namespace(space_el.name + "_utcb_area"))
            space.utcb.attach = PF_R

        # Weave a kclist for the main space.
        main_kclist = self.env.add_kclist_entry("MAIN_KCLIST", self.cell)

        # Weave the root kspace object.
        main_kspace = self.env.add_kspace_entry("MAIN_KSPACE", self.space)

        # Weave the root protection domain object.
        self.env.add_pd_entry("MAIN_PD", self.space, main_kspace, 32,
                machine.min_page_size(), self.elf)

        # Find heap and add it
        heap_el = okl4_el.find_child('heap')
        if heap_el is None:
            heap_el = ParsedElement('heap')

        heap_attr = collect_memobj_attrs(heap_el, self.namespace,
                                         image, machine)

        if heap_attr.size == None:
            heap_attr.size = DEFAULT_HEAP_SIZE

        self.heap_ms = image.add_memsection(heap_attr, machine, pools)
        self.cell.heap = self.heap_ms.attrs
        mapping = self.space.register_mapping(self.heap_ms.attrs)

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

        self.elf_segments = \
                [thread.get_stack_ms() for thread in threads] + \
                [self.heap_ms] + memsection_objs + device_mem

        self.env.add_kernel_info_entry(0, 0, kernel)

        # Add command line arguments
        commandline_el = okl4_el.find_child("commandline")

        if commandline_el is not None:
            args = [arg_el.value for arg_el in commandline_el.find_children("arg")]
        else:
            args = []

        self.env.add_arg_list(args)

        self.cell.env = self.env