Exemplo n.º 1
0
    def read_memory(self,
                    address,
                    memory_space=None,
                    size=1,
                    count=1,
                    do_side_effects=False):
        """
        :param address:
            Address to begin reading from.

        :param memory_space:
            Name of the memory space to read or None which will read the core's current memory space.

        :param size:
            Size of memory access unit in bytes. Must be one of 1, 2, 4 or 8.
            Note that not all values are supported by all models.
            Note that the data is always returned as bytes, so calling with
            size=4, count=1 will return a byte array of length 4.

        :param count:
            Number of units to read.

        :param do_side_effects:
            If True, the target must perform any side-effects normally triggered
            by the read, for example clear-on-read.

        Returns an integer if count is 1, otherwise returns a bytearray of length size*count

        """

        space = self._get_address_space(memory_space)

        if address < space.minAddress:
            raise ValueError(
                "Address is below minimum address of memory space '%s'" %
                space.memSpaceName)

        if address > space.maxAddress:
            raise ValueError(
                "Address is above maximum address of memory space '%s'" %
                space.memSpaceName)

        if size not in [1, 2, 4, 8]:
            raise ValueError("'size' must be 1, 2, 4 or 8")

        if count is None:
            count = len(data) / size
            if len(data) % size != 0:
                raise ValueError("len(data) must be a multiple of size")

        cadi_address = CADI.CADIAddrComplete(
            CADI.CADI_NO_OVERLAY, CADI.CADIAddr(space.memSpaceId, address))

        data = self.__cadi.CADIMemRead(cadi_address, count, size,
                                       do_side_effects)

        return data
Exemplo n.º 2
0
    def add_bpt_mem(self,
                    address,
                    memory_space=None,
                    on_read=True,
                    on_write=True,
                    on_modify=True):
        """
        Set a new breakpoint, which will be hit when a memory location is accessed

        :param address:
            The address to set the breakpoint on

        :param memory_space:
            The name of the memory space that ``address`` is in.
            If None, the current memory space of the core is used

        :param on_read:
            If True, the breakpoint will be triggered when the memory location
            is read from.

        :param on_write:
            If True, the breakpoint will be triggered when the memory location
            is written to.

        :param on_modify:
            If True, the breakpoint will be triggered when the memory location
            is modified.
        """

        space = self._get_address_space(memory_space)

        cadi_address = CADI.CADIAddrComplete(
            CADI.CADI_NO_OVERLAY, CADI.CADIAddr(space.memSpaceId, address))

        trigger_type = 0
        if on_read:
            trigger_type |= CADI.CADI_BPT_TRIGGER_ON_READ
        if on_write:
            trigger_type |= CADI.CADI_BPT_TRIGGER_ON_WRITE
        if on_modify:
            trigger_type |= CADI.CADI_BPT_TRIGGER_ON_MODIFY

        if trigger_type == 0:
            raise ValueError(
                "At least one of on_read, on_write and on_modify must be True")

        request = CADI.CADIBptRequest(enabled_par=1,
                                      type_par=CADI.CADI_BPT_MEMORY,
                                      address_par=cadi_address,
                                      triggerType_par=trigger_type)
        bpt = Breakpoint(self, self.__cadi, request)
        self.breakpoints[bpt.number] = bpt
        return self.breakpoints[bpt.number]
Exemplo n.º 3
0
    def add_bpt_prog(self, address, memory_space=None):
        """
        Set a new breakpoint, which will be hit when program execution reaches a memory address

        :param address:
            The address to set the breakpoint on

        :param memory_space:
            The name of the memory space that ``address`` is in.
            If None, the current memory space of the core is used
        """

        space = self._get_address_space(memory_space)

        cadi_address = CADI.CADIAddrComplete(
            CADI.CADI_NO_OVERLAY, CADI.CADIAddr(space.memSpaceId, address))
        request = CADI.CADIBptRequest(enabled_par=1,
                                      type_par=CADI.CADI_BPT_PROGRAM,
                                      address_par=cadi_address)
        bpt = Breakpoint(self, self.__cadi, request)
        self.breakpoints[bpt.number] = bpt
        return self.breakpoints[bpt.number]
Exemplo n.º 4
0
    def write_memory(self,
                     address,
                     data,
                     memory_space=None,
                     size=1,
                     count=None,
                     do_side_effects=False):
        """
        :param address:
            Address to begin reading from

        :param data:
            The data to write.
            If count is 1, this must be an integer
            Otherwise it must be a bytearray with length >= size*count

        :param memory_space:
            memory space to read.
            Default is None which will read the core's current memory space.

        :param size:
            Size of memory access unit in bytes. Must be one of 1, 2, 4 or 8.
            Note that not all values are supported by all models.

        :param count:
            Number of units to write. If None, count is automatically calculated
            such that all data from the array is written to the target

        :param do_side_effects:
            If True, the target must perform any side-effects normally triggered
            by the write, for example triggering an interrupt.
        """

        space = self._get_address_space(memory_space)

        if address < space.minAddress:
            raise ValueError(
                "Address is below minimum address of memory space '%s'" %
                space.memSpaceName)

        if address > space.maxAddress:
            raise ValueError(
                "Address is above maximum address of memory space '%s'" %
                space.memSpaceName)

        if size not in [1, 2, 4, 8]:
            raise ValueError("'size' must be 1, 2, 4 or 8")

        if isinstance(data, Integral):
            data = bytearray([data])

        if count is None:
            count = len(data) / size
            if len(data) % size != 0:
                raise ValueError("len(data) must be a multiple of size")

        if isinstance(data, bytearray) and len(data) < size * count:
            raise ValueError(
                "'data' must be either an integer, or a bytearray with length >= size*count"
            )

        cadi_address = CADI.CADIAddrComplete(
            CADI.CADI_NO_OVERLAY, CADI.CADIAddr(space.memSpaceId, address))

        self.__cadi.CADIMemWrite(cadi_address, count, size, data,
                                 do_side_effects)