Пример #1
0
    def get_data_pm(self, address, length=0):
        """Get data from PM.

        This method works in the exactly the same way as method, but it
        returns data from PM region instead of DM.

        Args:
            address
            length (int, optional)
        """
        try:
            address = int(address, 16)
        except TypeError:
            pass
        address = cu.get_correct_addr(address, Arch.addr_per_word)
        if length == 0:
            return self.pm[address]

        # note: Even the PM RAM is saved in self.pm data section.
        rawdata = []
        length = cu.convert_byte_len_word(length, Arch.addr_per_word)
        for i in range(0, length, Arch.addr_per_word):
            if address + i in self.pm:
                rawdata.append(self.pm[address + i])
            else:
                if i == 0:
                    raise KeyError("Key " + hex(address + i) + " is invalid")
                else:
                    raise OutOfRangeError(
                        "Key " + hex(address + i) + " is invalid",
                        address + i - Arch.addr_per_word)
        return tuple(rawdata)
    def _call_debuginfo_pm_addr(self, address, function_name):
        """Invokes _call_debuginfo_elfid method.

        Decides if the address is part of a downlaodable bundle or not and
        calls _call_debuginfo_elfid with the elf id for further
        processing.  This is necessary because _call_debuginfo_elfid
        assumes that the address is in Kymera or patch elf.

        Args:
            @param[in] address Code address.

        Returns:
            function_name (str): Name of the function to call.
        """
        if Arch.get_pm_region(address, False) is None:
            raise InvalidPmAddressError("Key " + hex(address) +
                                        " is not in PM")

        if self._address_in_table(address):
            # elf_id_from_address should be different than None
            elf_id_from_address = self.table.get_elf_id_from_address(address)
            if elf_id_from_address not in self.debug_infos:
                # No bundles are loaded to ACAT at all
                raise BundleMissingError(
                    BUNDLE_ERROR_MSG.format(hex(elf_id_from_address)))
        else:
            # Use the main Kymera debug info and the patches.
            elf_id_from_address = None

        return self._call_debuginfo_elfid(elf_id_from_address, function_name,
                                          address)
    def get_data_pm(self, address, length=0):
        """Get data from PM.

        This method works in the exactly the same way as get_data(self,
        address, length = 0) method, but it returns data from PM region
        instead of DM.

        Args:
            address
            length (int, optional)
        """
        # We helpfully accept address as either a hex string or an integer
        try:
            # Try to convert address from a hex string to an integer
            address = int(address, 16)
        except TypeError:
            # Probably means address was already an integer
            pass

        address = cu.get_correct_addr(address, Arch.addr_per_word)

        if length == 0:
            mem_region = Arch.get_pm_region(address)
        else:
            mem_region = Arch.get_pm_region(
                address +
                cu.convert_byte_len_word(length, Arch.addr_per_word) -
                Arch.addr_per_word)
        try:
            if ('PMRAM' in mem_region or 'PMCACHE' in mem_region
                    or 'SLT' in mem_region):
                if length == 0:
                    return self.pm[address:address + Arch.addr_per_word][0]

                return tuple([
                    int(x) for x in self.
                    pm[address:address +
                       cu.convert_byte_len_word(length, Arch.addr_per_word)]
                ])
            else:
                if length == 0:
                    raise KeyError(
                        "Key " + hex(address + Arch.addr_per_word) +
                        " is not a valid PM RAM address",
                        address + Arch.addr_per_word)

                raise OutOfRangeError(
                    "Key " +
                    hex(address +
                        cu.convert_byte_len_word(length, Arch.addr_per_word) -
                        Arch.addr_per_word) + " is not a valid PM RAM address",
                    address +
                    cu.convert_byte_len_word(length, Arch.addr_per_word) -
                    Arch.addr_per_word)
        except Exception as exception:
            if "Transport failure (Unable to read)" in exception:
                sys.stderr.write(str(exception))
                raise ChipNotPoweredError
            else:
                raise exception
Пример #4
0
 def test_hex(self):
     self.assertEqual(hex(0), '0x0')
     self.assertEqual(hex(16), '0x10')
     self.assertEqual(hex(16L), '0x10')
     self.assertEqual(hex(-16), '-0x10')
     self.assertEqual(hex(-16L), '-0x10')
     self.assertRaises(TypeError, hex, {})
    def _value_to_hex(self):
        """Converts the value into hex and return it.
        
        The value of the Variable might be in different types. This method
        supports the conversion when the type is in Integer, list or tuple
        of Integers and None.

        When the value is a list of integers, each number will be
        converted into hex. Also, in case the value is None, the `None`
        string will be returned.

        Returns:
            str: A string representation of the Variable's value.
        """
        if isinstance(self.value, numbers.Integral):
            display_value = hex(self.value)

        elif isinstance(self.value, (list, tuple)):
            display_value = str([hex(val) for val in self.value])

        else:
            # Conversion to hex was unsuccessful.
            display_value = str(self.value)

        return display_value
Пример #6
0
    def read_kip_requests(self, display_all=False):
        """Shows kip request for ipc.

        If True is passed as an argument, all requests are displayed. If
        not, then only reasonable amount of them will be displayed.
        """
        # Look up the debug information, unless we already have.
        if self._do_debuginfo_lookup:
            self._lookup_debuginfo()
            self._do_debuginfo_lookup = False

        self.formatter.section_start('KIP requests')
        # kip requests are held in linked list, thus read these entries
        kip_requests = [
            req for req in self.parse_linked_list('L_kip_first_req', 'next')
        ]
        if not kip_requests:
            self.formatter.output('No KIP request present')
        else:
            # there might be lots of kip requests, thus display reasonable
            # number of them, unless ser asked to display all of them
            self.formatter.output('Pending KIP requests:\n')
            kip_str = ''
            max_to_display = 10
            displayed = 0
            apology = ''
            for req in kip_requests:
                kip_str += 'Connection ID: {0}\n'.format(
                    hex(req.get_member('con_id').value))
                msg = self.debuginfo.get_enum(
                    'KIP_MSG_ID',
                    req.get_member('msg_id').value)[0].replace(
                        'KIP_MSG_ID_', "")
                kip_str += 'Message ID: {0}\n'.format(msg)
                kip_str += 'Sequence number: {0}\n'.format(
                    hex(req.get_member('seq_nr').value))
                req_context = req.get_member('context').value
                if req_context != 0:
                    try:
                        module_name = self.debuginfo.get_source_info(
                            req_context).module_name
                    except BundleMissingError:
                        module_name = ("No source information. " +
                                       "Bundle is missing.")
                    kip_str += 'Context: {0}\n'.format(module_name)
                kip_str += '\n'
                displayed += 1
                if displayed == max_to_display and not display_all:
                    apology = (
                        '\n...\n{0} more requests. '
                        'Pass True to the method to display '
                        'all requests'.format(len(kip_requests) - displayed))

            self.formatter.output(kip_str + apology)

        self.formatter.section_end()

        if self.chipdata.is_volatile():
            self._do_debuginfo_lookup = True
 def __str__(self):
     # update the table before printing.
     self._update_table()
     out_str = '\nIdentify:  {0}  Entries: {1}\n'.format(
         hex(self.identify_field), self.num_of_entries)
     out_str += '{0:<20}{1:<10}{2:<15}{3:<15}\n'.format(
         'Device address', 'length', 'file address', 'file elf_id')
     for entry in self.entries:
         out_str += str(entry)
     out_str += 'Checksum: {0}\n'.format(hex(self.checksum))
     return out_str
Пример #8
0
    def print_message_queue(self, msg_queue_var, display_buffer,
                            display_messages):
        """Displays the message queue.

        Args:
            msg_queue_var: Pointer to a message queue variable.
            display_buffer (bool): Flag to indicate if the underlying
                buffer should be further analysed.
            display_messages (bool): Flag to indicate if message
                information is needed.
        """
        # buffers are used to store messages, this import buffer analysis for
        # analysing it
        if display_buffer:
            buffer_analysis = self.interpreter.get_analysis(
                "buffers", self.chipdata.processor)

        self.formatter.output('Queue ID: {0}'.format(
            msg_queue_var.get_member('queue_id').value))
        self.formatter.output('Read counter: {0}'.format(
            msg_queue_var.get_member('message_read_counter').value))
        self.formatter.output('Next message counter: {0}'.format(
            msg_queue_var.get_member('next_message_counter').value))
        try:
            module_name = self.debuginfo.get_source_info(
                msg_queue_var.get_member('callback').value).module_name
        except BundleMissingError:
            module_name = ("No source information. Bundle is missing.")
        self.formatter.output('Callback: {0}'.format(module_name))

        buffer_pointer = msg_queue_var.get_member('cbuffer').value
        buffer_var = self.chipdata.cast(buffer_pointer, 'tCbuffer')
        self.formatter.output('Messages are stored in buffer at: {0}\n'.format(
            hex(buffer_var.get_member('base_addr').value)))

        if display_messages:
            messages = self._get_buffer_messages(buffer_var)
            msg_str = 'Messages: \n'
            for (header, msg_id) in messages:
                if header == VALID_MSG_HEADER_EXT:
                    msg_str += ('  External message with ID: {0}\n'.format(
                        hex(msg_id)))
                elif header == VALID_MSG_HEADER_INT:
                    msg_str += ('  Internal message with ID: {0}\n'.format(
                        hex(msg_id)))
            self.formatter.output(msg_str + '\n')

        # if asked, print out the buffer associated with the queue
        if display_buffer:
            if msg_queue_var.get_member('cbuffer').value != 0:
                buffer_analysis.analyse_cbuffer(buffer_pointer)
            else:
                self.formatter.output('Message queue buffer is null \n')
Пример #9
0
    def output(self, string_to_output):
        """Normal body text. Lists/dictionaries will be compacted.

        Args:
            string_to_output (str)
        """
        with self.lock:
            if isinstance(string_to_output, (list, tuple)):
                self._log(str([hex(item) for item in string_to_output]))
            else:
                try:
                    self._log(hex(string_to_output))
                except TypeError:
                    self._log(str(string_to_output))
 def output(self, string_to_output):
     """
     @brief Normal body text. Lists/dictionaries will be compacted.
     @param[in] self Pointer to the current object
     @param[in] string_to_output
     """
     with self.lock:
         if isinstance(string_to_output, (list, tuple)):
             self._log(str([hex(item) for item in string_to_output]))
         else:
             try:
                 self._log(hex(string_to_output))
             except TypeError:
                 self._log(str(string_to_output))
Пример #11
0
    def desc_str(self):
        """Returns the description string of the endpoint."""
        ep_str = "Address: " + hex(self.address) + "\n"
        ep_str = ep_str + "Key: " + hex(self.key) + "\n"
        # it's enough to check with one variable that it's the AudioEP
        if self.instance is not None:
            ep_str += "Device: " + str(self.hardware) + "\n"
            ep_str += "Instance: " + str(self.instance) + "\n"
            ep_str += "Channel: " + str(self.channel) + "\n"

        ep_str = ep_str + "is_real: " + \
            str(self.is_real) + " can_be_closed: " + \
            str(self.can_be_closed) + "\n"
        ep_str = ep_str + "can_be_destroyed: " + \
            str(self.can_be_destroyed) + " destroy_on_disconnect: " + \
            str(self.destroy_on_disconnect) + "\n"
        if self.con_id is not None:
            ep_str = ep_str + "Connection ID: " + str(self.con_id) + "\n"

        ep_str = ep_str + "connected_to: "
        try:
            connected_to = self.connected_to
            if connected_to is None:
                ep_str += "NULL\n"
            else:
                ep_str += hex(connected_to.id) + \
                    "(" + connected_to.compact_name() + ") \n"
        except AttributeError:
            ep_str += ("0x%08x is not a valid endpoint address\n" %
                       self._connected_to)

        ep_str += "ep_to_kick: "
        try:
            endpoint_to_kick = self.ep_to_kick
            if endpoint_to_kick is None:
                ep_str += "NULL\n"
            else:
                ep_str += hex(endpoint_to_kick.id) + \
                    "(" + endpoint_to_kick.compact_name() + ") \n"
        except AttributeError:
            ep_str += ("0x%08x is not a valid endpoint address\n" %
                       self._ep_to_kick)
        ep_str = ep_str + str(self.cbops)

        if self.is_state_type_equal_to_name:
            ep_str = ep_str + \
                str(getattr(self, self.name))

        return ep_str
Пример #12
0
    def analyse_messages(self, display_buffer=True, display_messages=False):
        """Analyses information about messages of ipc.

        If True parameter is passed to the function, buffer containing
        messages is analysed as well.

        Args:
            display_buffer (bool, optional): Flag to indicate if the
                underlying buffer should be further analysed.
            display_messages (bool, optional): Flag to indicate if message
                information is needed.
        """
        # Look up the debug information, unless we already have.
        if self._do_debuginfo_lookup:
            self._lookup_debuginfo()
            self._do_debuginfo_lookup = False

        self.formatter.section_start('IPC Messages Information')
        if self.ipc_msg_block_p == 0:
            self.formatter.output('No message information')
            self.formatter.section_end()
            if self.chipdata.is_volatile():
                self._do_debuginfo_lookup = True
            return

        msg_block = self.chipdata.cast(self.ipc_msg_block_p,
                                       'IPC_MESSAGE_BLOCK')
        self.formatter.output('Number of message channels used: {0}'.format(
            msg_block.get_member('number_of_channels').value))
        self.formatter.output('Maximum message size: {0}'.format(
            msg_block.get_member('max_msg_sz').value))
        self.formatter.output('Maximum number of messages: {0}'.format(
            msg_block.get_member('max_msgs').value))

        # there will be array of msg channels, so read messages from them
        msg_cannel_p_array = msg_block.get_member('ipc_message_channel')
        self.formatter.output('IPC message channels:')
        # there might be more than one channel if more processors are used
        for msg_channel_p in msg_cannel_p_array:
            msg_channel = self.chipdata.cast(msg_channel_p.value,
                                             'IPC_MESSAGE_CHANNEL')
            self.formatter.output('  Channel ID: {0}\n'.format(
                hex(msg_channel.get_member('channel_id').value)))

            p0_to_px_msq_q = msg_channel.get_member('p0_2_px_message_queue')
            self.formatter.section_start('P0 to Px message queue:')
            self.print_message_queue(p0_to_px_msq_q, display_buffer,
                                     display_messages)
            self.formatter.section_end()

            px_to_p0_msg_q = msg_channel.get_member('px_2_p0_message_queue')
            self.formatter.section_start('Px to P0 message queue:')
            self.print_message_queue(px_to_p0_msg_q, display_buffer,
                                     display_messages)
            self.formatter.section_end()

        self.formatter.section_end()

        if self.chipdata.is_volatile():
            self._do_debuginfo_lookup = True
Пример #13
0
    def analyse_per_task(self, task_id=None):
        """Displays the scratch memory info per task.

        It can take one parameter that represents the task id and it will
        display the info for it.

        The function goes through the linked list and if no value is
        passed to it, it displays the complete list. Otherwise, it
        displays the info for the task with the id inputted or a message
        (if the task id is invalid).

        Args:
            task_id (int, optional)
        """
        per_task = self.chipdata.cast(
            self.chipdata.get_var_strict('$_first_scratch_mem').address,
            'scratch_per_task_data')
        matching_id = False
        for sc_table in self.parse_linked_list(per_task.address, 'next'):
            if (task_id is None) or (sc_table.value[0] is task_id):
                self.formatter.output(str(sc_table))
                matching_id = True
        if (task_id is not None) and (not matching_id):
            self.formatter.output('There is no task id = ' +
                                  str(hex(task_id)) + '!')
Пример #14
0
    def desc_str(self):
        """Returns the description string of the transform."""
        tf_str = "Address: " + hex(self.address) + "\n"
        tf_str = tf_str + "Source: " + self.source.compact_name() + "\n"
        tf_str = tf_str + "Sink: " + self.sink.compact_name() + "\n"
        if self.created_buffer:
            tf_str = tf_str + "The transform created the buffer \n"
        else:
            tf_str = tf_str + "The buffer was supplied by an endpoint \n"
        if self.shared_buffer:
            tf_str = tf_str + "The buffer shared \n"
        else:
            tf_str = tf_str + "The buffer is not shared \n"

        tf_str = tf_str + 'Buffer: ' + hex(self.buffer) + '\n'

        return tf_str
Пример #15
0
    def _analyse_fifo(self, signal_block):
        """Shows content of fifo, if any pending actions are stored.

        Args:
            signal_block: Signal block that this fifo belongs to.
        """

        self.formatter.section_start('FIFO information')
        fifo_p_array = signal_block.get_member('fifo').value
        # different fifo's are for different priority messages, but not all
        # of them might be  used, thus only display those which had messages
        # in them at some point, which is indicated by the counter of maximum
        # slots taken
        for fifo_p in fifo_p_array:
            priority = fifo_p_array.index(fifo_p)
            fifo = self.chipdata.cast(fifo_p, 'IPC_SIGNAL_FIFO')
            if fifo.get_member('max').value == 0:
                self.formatter.output(
                    'FIFO of priority {0} have not been used'.format(priority))
                # Nothing to do here anymore
                continue
            else:
                max_entries = fifo.get_member('entry').array_len
                self.formatter.output(
                    'FIFO of priority {0} information:\n'.format(priority))
                numelts = fifo.get_member('numelts').value
                self.formatter.output(
                    ' ' * 2 +
                    'Number of elements currently stored: {0}'.format(numelts))
                self.formatter.output(' ' * 2 +
                                      'Maximum number stored: {0}'.format(
                                          fifo.get_member('max').value))
                if numelts > 0:
                    # display pending elements
                    read_idx_initial = fifo.get_member('rdidx').value
                    for element_nr in range(numelts):
                        read_idx = (read_idx_initial +
                                    element_nr) % max_entries
                        element = fifo.get_member('entry').__getitem__(
                            read_idx)
                        self.formatter.output(
                            ' ' * 4 +
                            'Fifo entry at position: {0}'.format(read_idx))
                        self.formatter.output(
                            ' ' * 6 + 'Signal channel: {0}'.format(
                                element.get_member('sigchan').value))
                        self.formatter.output(' ' * 6 + 'Sender: {0}'.format(
                            element.get_member('sender').value))
                        self.formatter.output(
                            ' ' * 6 + 'Signal ID: {0}'.format(
                                element.get_member('sigid').value))
                        signal_ptr = element.get_member('sigreq').get_member(
                            'signal_ptr').value
                        self.formatter.output(
                            ' ' * 6 +
                            'Signal pointer: {0}'.format(hex(signal_ptr)))

        self.formatter.section_end()
Пример #16
0
 def test_hex(self):
     self.assertEqual(hex(0), '0x0')
     self.assertEqual(hex(16), '0x10')
     self.assertEqual(hex(16L), '0x10')
     self.assertEqual(hex(-16), '-0x10')
     self.assertEqual(hex(-16L), '-0x10')
     self.assertRaises(TypeError, hex, {})
Пример #17
0
    def get_banked_reg(self, address, bank=None):
        """Returns the value of a register in a specific bank.

        Args:
            address Address of the banked register.
            bank = None
        """
        if bank is not None:
            for member in self.banked_registers:
                if member.addr == address and member.bank == bank:
                    return member.value
            raise KeyError("Invalid register address " + hex(address) +
                           " or bank " + bank)
        else:
            for member in self.banked_registers:
                if member.addr == address:
                    return self.get_data(address)
            raise KeyError("Invalid banked register address " + hex(address))
    def __str__(self):
        # Special rule since you can't call hex() on None
        if self.address is not None:
            hex_addr = hex(self.address)
        else:
            hex_addr = 'None'

        return ('Name: ' + str(self.name) + '\n' + 'Address: ' + hex_addr +
                '\n' + 'Value: ' + self._value_to_hex() + '\n')
Пример #19
0
    def analyse_processor_regs(self):
        """Prints out all of the processor registers."""
        # Can't always work out the address of registers to sort them,
        # so they'll appear in some random dictionary order (sadly).

        self.formatter.section_start('Processor registers')
        # Sort by address
        for name, val in self.chipdata.get_all_proc_regs().items():
            self.formatter.output(name + "\t" + hex(val))
        self.formatter.section_end()
Пример #20
0
    def analyse_aux_states(self):
        """Analyses the stated at which processors are at the time."""
        # Look up the debug information, unless we already have.
        if self._do_debuginfo_lookup:
            self._lookup_debuginfo()
            self._do_debuginfo_lookup = False

        self.formatter.section_start('Aux states')

        if self.aux_states_p == 0:
            self.formatter.output('No aux states information')
            self.formatter.section_end()
            if self.chipdata.is_volatile():
                self._do_debuginfo_lookup = True
            return

        aux_states_array = self.chipdata.cast(
            self.aux_states_p, 'IPC_AUX_STATES').get_member('aux')
        all_states = self.debuginfo.get_enum('_IPC_SETUP_STATE', None)
        # This is states for every processor used, and it will be an array
        for processor in range(aux_states_array.array_len):
            aux_state = aux_states_array.__getitem__(processor)
            setup_state = aux_state.get_member('setup_state').value
            wakeup_time = aux_state.get_member('wakeup_time').value
            # Status state represents several possible flags. Find these flags
            # now
            if setup_state == 0x0000:
                active_states = ['SETUP_NONE']
            else:
                active_states = []
                for state, flag in all_states.items():
                    if state == 'IPC_SETUP_NONE':
                        continue
                    mask = 0x000F
                    for _ in range(4):
                        current_flag = setup_state & mask
                        if current_flag == flag:
                            active_states.append(state.replace("IPC_", ""))
                        mask = mask << 4

            state_str = ''
            for state in sorted(active_states):
                state_str += state + ', '
            state_str = state_str[:-2]  # remove last space and comma

            self.formatter.output(
                'Aux state for processor p{0}:'.format(processor))
            self.formatter.output('    Setup state: {0} - {1}'.format(
                hex(setup_state), state_str))
            self.formatter.output('    Wake-up time: {0}'.format(wakeup_time))

        self.formatter.section_end()

        if self.chipdata.is_volatile():
            self._do_debuginfo_lookup = True
    def _call_debuginfo_function(self, elf_id, function_name, *argv, **kwargs):
        """Invokes a function in debuginfo.

        Searches for the right debuginfo based on elf id (Kymera, patch or
        downloadable bundles) and call the function specified at the
        input.

        Args:
            elf_id (int): The Debug info elf id to call.
            function_name (str): Name of the function to call.
            *argv: Function unnamed input parameter.
            **kwargs: Function named input parameter.

        Returns:
            Value returned by the function call.
        """
        # convert addresses to the Bundle address if needed
        in_dm_pm = (function_name in self.dm_address_mappable_function
                    or function_name in self.pm_address_mappable_function)
        if (in_dm_pm and isinstance(argv[0], numbers.Integral)):
            address = argv[0]
            if self._address_in_table(address):
                # Get the elf ID from the address.
                elf_id = self.table.get_elf_id_from_address(address)
                address = self.table.convert_addr_to_download(address, elf_id)
                argv = (address, )

        # Access the debuginfo in the standard way. Do this after the proper
        # elf_id is selected.
        try:
            debug_info = self.debug_infos[elf_id]
        except KeyError:
            raise BundleMissingError(hex(elf_id))

        # get the function from the debuginfo which will be called.
        function_to_call = debug_info.__getattribute__(function_name)
        # todo: Make all adapted functions to accept elf_id as an input
        # kwargs["elf_id"] = elf_id
        # and call the function.
        return_val = function_to_call(*argv, **kwargs)

        # Remap the addresses from bundle to chip
        if debug_info.is_bundle():
            if function_name in self.dm_address_mappable_function:
                # Convert a variable to chip address
                return_val = self._map_data_from_file_to_build(
                    return_val, elf_id)
            if function_name in self.pm_address_mappable_function:
                if hasattr(return_val, "address"):
                    # Convert a code label to chip address.
                    return_val = copy.deepcopy(return_val)
                    return_val.address = self.table.convert_addr_to_build(
                        return_val.address, elf_id)
        return return_val
    def __str__(self):
        if self.nearest_label is None:
            nearest_label_str = "Uncalculated"
        else:
            nearest_label_str = str(self.nearest_label)

        # Using str(x) here since it copes with the value being None
        return ('Code address: ' + hex(self.address) + '\n' + 'Module name: ' +
                str(self.module_name) + '\n' + 'Found in: ' + self.src_file +
                ', line ' + str(self.line_number) + '\n' +
                'Nearest label is: ' + nearest_label_str)
Пример #23
0
    def __str__(self):
        """Returns a tidy string representation of a timer object."""
        tf_str = "Timer " + hex(self.id) + "\n"
        tf_str = tf_str + "Type: " + self.type + "\n"

        if self.type == 'strict':
            tf_str = tf_str + "Expiry time: " + hex(self.latest_time) + "\n"
        else:
            tf_str = tf_str + "Earliest expiry: " + hex(self.earliest_time)
            tf_str = tf_str + ", latest expiry: " + \
                hex(self.latest_time) + "\n"

        tf_str = tf_str + "Data pointer: " + hex(self.data_pointer) + "\n"

        if self.timed_event_function is not None:
            tf_str = tf_str + "EventFunction: \n"
            temp_str = '    ' + str(self.timed_event_function)  # Indent
            tf_str = tf_str + temp_str.replace('\n', '\n    ')  # Indent
            tf_str = tf_str[:-4]  # Remove indent from final newline

        return tf_str
Пример #24
0
    def analyse_wakeup_timer(self):
        """Outputs details of the wakeup timer."""
        self.formatter.section_start('Wakeup Timer')

        wakeup_timer_en = self.chipdata.get_reg_strict('$_TIMER2_EN').value
        wakeup_timer_time = self.chipdata.get_reg_strict(
            '$_TIMER2_TRIGGER').value
        if wakeup_timer_en is 1:
            self.formatter.output('Wakeup time is: ' + hex(wakeup_timer_time))
        else:
            self.formatter.output('No wakeup timer is configured.')

        self.formatter.section_end()
Пример #25
0
    def get_all_banked_regs(self, addr_bank_sel_reg):
        """Returns all the banked registers in string format.

        Args:
            addr_bank_sel_reg: The address of the bank select register
                that controls the bank.
        """
        banks = ''
        is_valid_bank_reg = False
        banks += 'Banks for BSR at address ' + \
            str(hex(addr_bank_sel_reg)) + ':\n'
        for member in self.banked_registers:
            if member.addr_bank_sel_reg == addr_bank_sel_reg:
                is_valid_bank_reg = True
                banks += 'Bank ' + str(member.bank) + ' address ' + str(
                    hex(member.addr)
                ) + ' value ' + str(hex(member.value)) + '.\n'
        if not is_valid_bank_reg:
            raise KeyError("Invalid address of a bank select register " +
                           hex(addr_bank_sel_reg))

        return banks
Пример #26
0
    def analyse_all_mmr(self):
        """Prints out all of the memory-mapped registers.

        Reg names are not precise (i.e. they are guesses), so this should
        only really be used in Interactive mode.
        """
        # The whole memory-mapped register range
        mmr_range = list(
            range(Arch.dRegions['MMR'][0], Arch.dRegions['MMR'][1]))
        mmr_list = []
        for i in mmr_range:
            try:
                # Tuple containing (address, register name, register contents)
                mmr_list.append((i, self.chipdata.get_reg_strict(i).name,
                                 self.chipdata.get_reg_strict(i).value))
            except BaseException:
                # Not found
                pass

        self.formatter.section_start('All memory-mapped registers')
        for i in mmr_list:
            self.formatter.output(hex(i[0]) + " " + i[1] + " " + hex(i[2]))
        self.formatter.section_end()
    def convert_addr_to_download(self, addr_in_build, cap_elf_id):
        """Converts chipdata's address to downloaded capability's.

        If conversion is not valid according to the table, None is
        returned.

        Args:
            addr_in_file: address we want to convert.
            cap_elf_id (int): id of capability we want to map.
        """
        self._update_table()
        entry = self.get_table_entry(addr_in_build, cap_elf_id, False)
        if entry is None:
            raise ValueError("Address " + hex(addr_in_build) +
                             " is not in any downloadable capability.")
        else:
            offset = addr_in_build - entry.device_address
            file_address = entry.file_address + offset
            return file_address
Пример #28
0
    def __str__(self):
        if len(self.args) == 1:
            apology = self.args[0]
        else:
            try:
                output_string = ""
                # Sort matches by name
                sorted_match = sorted(self.args[1],
                                      key=lambda match: match["name"])
                for match in sorted_match:
                    output_string += match["name"] + \
                        "\n\tElf id:" + hex(match["elf_id"])

                    filename = os.path.split(match["file_path"])[-1]
                    output_string += "\n\t%s\n" % filename
                apology = self.args[0] + "\n" + output_string
            except TypeError:
                apology = self.args[0] + "  " + str(self.args[1])

        return apology
    def _prepare_output(self, output):
        """
        Recursive method to prepare the given output

        @param[in]  output  This can be any type but ultimately it should be
                            possible to cast it to string.
        @param[out] String
        """
        if isinstance(output, (tuple, list)):
            prepared_output = []
            for item in output:
                prepared_output.append(self._prepare_output(item))

            return str(prepared_output)
        else:

            try:
                return hex(output)
            except TypeError:
                return str(output)
Пример #30
0
    def desc_str(self):
        """Returns the description string of the endpoint."""
        # Call the base class property function cannot be done otherwise
        ep_str = Endpoint.desc_str.fget(self)  # pylint: disable=no-member

        tp_ptr_var = self.audio.get_member("timed_playback")
        if tp_ptr_var:
            # timed playback is enabled in the build
            timed_playback_ptr = tp_ptr_var.value

            if timed_playback_ptr != 0:
                # the endpoint has a timed playback instance.
                timed_playback_var = self.stream.chipdata.cast(
                    addr=timed_playback_ptr,
                    type_def="TIMED_PLAYBACK",
                    elf_id=self.stream.debuginfo.get_kymera_debuginfo().elf_id)
                ep_str = ep_str.replace(
                    "timed_playback: " + hex(timed_playback_ptr),
                    str(timed_playback_var).replace("\n", "\n  "))

        return ep_str
Пример #31
0
    def get_banked_reg_strict(self, address, bank=None):
        """Looks up the values of a banked register.

        It takes the address of a banked register and the bank number
        (optional).

        Returns a ct.DataSym containing the bank select register name and
        address plus the values in the bank.

        Args:
            address: Address of the banked register.
            bank
        """
        reg = None
        if isinstance(address, numbers.Integral):
            if Arch.get_dm_region(address) == "MMR":
                val = self.get_banked_reg(address, bank)
                reg = self.get_reg_strict(address)
                return ct.DataSym(reg.name, address, val)
            else:
                raise ValueError("The address {} is not in MMR region.".format(
                    hex(address)))
Пример #32
0
from future_builtins import hex, oct, map, zip, filter
from itertools import imap, izip, ifilter

value_list1 = [0, 42, 42L, -42, -42L, "", (), {}, []]
value_list2 = [0, 100, 100L, -100, -100L]

for value1 in value_list1:
    try:
        print(hex(value1))
    except Exception as e:
        print(type(e), e.message)

for value2 in value_list2:
    try:
        print(oct(value2))
    except Exception as e:
        print(type(e), e.message)

print(map == imap)
print(zip == izip)
print(filter == ifilter)