Posts Tagged ‘read dsp chip heximal content’

PostHeaderIcon Read DSP Chip Program: Harvard Memory Means Half an Image

A request to read a DSP’s program is a request for half of what the customer needs, and the half that is missing is often the more valuable one. The reason is architectural: DSPs separate program memory from data memory so that an instruction fetch and a data access can happen in the same cycle. That separation is the defining feature of the class, and it means the address spaces are distinct.

On a von Neumann machine, reading memory returns everything, because instructions and data share an address space. On a DSP, reading the program space returns instructions. The tables those instructions operate on — filter coefficients, window functions, lookup tables, calibration constants — live in the data space, at different addresses, reachable by different instructions.

What lives where

Content Space Accessed by
Instructions Program Instruction fetch
Immediate constants Inside the instruction Nothing; they are part of the opcode
Coefficient tables Data Load instructions
Delay lines and state Data Load and store
Stack Data, usually Push and pop
Memory-mapped registers Data Load and store

The third row is where the money is. A finite impulse response filter is a loop over a coefficient array, and the loop is generic while the coefficients define the product. An extracted program with no coefficients describes an algorithm; an extracted program with its coefficients reproduces the device.

Why the tables are not in the program space

Some DSP architectures allow constants to be stored in program memory and read as data through a special addressing mode. This is a real feature and it is used, because it keeps constants out of the smaller data space and lets them be fetched in parallel with instruction fetch.

Storage choice Where the table goes Consequence for extraction
Table in data space Initialised data region Requires a data-space read
Table in program space, read as data Program memory, at a data address Captured by a program read
Table in external memory Off chip Requires reading the external device
Table computed at runtime Nowhere; generated by code Recoverable by running the code

The fourth row describes designs that store a formula rather than a table. Those are the easiest to reproduce and the hardest to notice: the extracted image contains a short routine and no table, and the coefficients only exist while the device runs.

Reading the data space

The data space is harder to read than the program space for a mundane reason: it is partly volatile. A read of data memory returns whatever the program had put there at the moment of the read, not the initialised values the linker placed in the image.

Data region Content at rest How to recover initial values
Initialised data Values copied from a load image at boot Read the load image, not the RAM
Zero-initialised data Zeros Nothing to recover
Stack and heap Transient Nothing useful, usually
Persistent state Last written values A read at the right moment

The first row is the important one and it is frequently misunderstood. The initial values of initialised data are stored in the program image, in a section that the startup code copies to RAM. So a program-space read does capture the initial tables, provided the tool includes that section.

Tool behaviour Result
Program read includes initialised data section Tables recovered
Program read excludes it Only the copy routine is present
Tool reads both spaces Complete image
Tool reads program only, and the table is in data Coefficients missing

Recognising a missing table

The symptom of an incomplete read is a filter loop that is correct and an output that is wrong. In the extracted code, the loop loads from an address that is inside the data space and unremarkable; nothing about the instruction says what should be there.

Clue in the code What it implies
Loop with a pointer into high data addresses Coefficient table expected there
Immediate value used as a table length Table size is known to the code
Address computed from a base register set at startup The base is a section address
No writes to the table region anywhere The table is initialised from a load image

The fourth row is the diagnostic: if nothing in the program ever writes to the region being read, the values must have been placed there by the loader, which means they are in the image and the extraction missed them.

The wider consequence for reconstruction

An incomplete image produces a reconstruction that compiles and does not match. The usual response is to spend time on the algorithm, looking for a bug that is not there, when the actual problem is that a constant is zero.

Deliverable Complete image Program-only image
Disassembly Full Full, for instructions
Coefficient tables Present Missing
Behavioural match Achievable Not achievable for filters
Rebuild on new hardware Possible Needs re-derivation of coefficients

The last row is the practical cost. Re-deriving coefficients is possible when the filter specification is known and impossible when it was tuned empirically, which is common in audio and motor control.

On a device with two cores sharing memory, the data space is not private to the DSP, and a table that appears to be missing may simply be living where the other core can see it. That case is treated in reading a DSP plus MCU program.

Where the other half comes from

The segment-level view of a DSP image, which is what tells you whether the initialised data section was included, is in reading DSP embedded source code. Where the device also has a companion logic device on the bus, the joint read is covered in reading DSP and CPLD dump information, and where the tables live in an external memory, attacking DSP flash content covers reading it.

The two general approaches to a DSP’s protection, intrusive and non-intrusive, are summarised under crack DSP; the choice between them is usually settled by whether the device still runs.

Services at this boundary

Work covers both address spaces, identification of whether a given read included initialised data, coefficient table recovery, and reconstruction of tables that are generated at runtime by executing the code in an instrumented environment. It does not cover recovering coefficients that were never stored anywhere, and it does not cover reconstructing a filter specification from an incomplete table.

The question to ask before any DSP read is which spaces the tool covers, because a program-only read is a real result and an incomplete one at the same time.