Search code examples
trace32lauterbach

Trace32 practice script: DATA.SET how to use


What does the following command mean? What does EA mean?

&HEAD=0x146BF94C
DATA.SET  EA:&HEAD+0x4  %LONG  DATA.LONG(EA:&HEAD+0x4)&0xFFFFFF

Solution

  • The command Data.Set writes raw data to your target's memory at the given address.

    The command follows this schema:
      Data.Set <address> <access width> <data>
    where

    • <address> has the form <access class> : <address offset>
      where the "access class" are several letters specifying which memory is accessed in which way.
    • <access width> is %Byte for 8-bit, %Word for 16-bit, %Long for 32-bit or %Quad for 64-bit
    • <data> is the data you actually want to write.

    For the "access class" check the chapter Access Classes in your Processor Architecture Manual (menu → Help → Processor Architecture Manual). The types of available access classes vary from the used processor architecture. (e.g. different classes for ARM and PowerPC)

    The "access class" EA: means:

    • Access the memory while the CPU is running (E).
    • Access the memory via absolute (physical) memory addresses (A) bypassing the MMU.

    Finally the data (<data>) you want to write to the memory can be a fixed value (e.g. 0x42) or calculated via an expression (0x40+0x02). Such an expression can also use so called "PRACTICE functions". The function used in your example is Data.Long(<address>), which reads 32-bit from the given address. (Note: Expressions may not contain blanks.)

    And then you have a macro &HEAD= which contains the string "0x146BF94C". This means that any &HEAD appearing in any later command gets replaces by the content of the macro. This similar to the C-Preprossor.

    Thus, your commands

    &HEAD=0x146BF94C
    DATA.SET EA:&HEAD+0x4 %LONG DATA.LONG(EA:&HEAD+0x4)&0xFFFFFF
    

    have the same meaning than

    Data.Set  EA:0x146BF950  %LONG  Data.Long(EA:0x146BF950)&0x00FFFFFF
    

    and that defines actually a read-modify-write on the 32-bit value at address EA:0x146BF950: The value is read from memory, the upper 8-bit are set to zero and than the result gets written back to the same memory location.

    It has (almost) the same meaning than the C code expression

    *((volatile uint32_t*) 0x146BF950)  &=  0x00FFFFFF;
    

    It is just "almost the same" because the C code expression would not bypass the MMU, like your Data.Set command does, thanks to the "A" in the memory access class of the addresses.