PostHeaderIcon Read PLD Code in an MCU System: You Are Recovering a Memory Map

A microcontroller board with a small programmable logic device on it invites an assumption: the PLD must be doing something interesting, since otherwise why is it there. In practice the answer is usually that it is doing something boring and essential. It is decoding addresses, gating chip selects, and inserting wait states for slow peripherals.

That makes reading it unexpectedly valuable, because the decode logic is a complete specification of how the microcontroller sees the rest of the board. Address ranges, chip select polarities, bus width, and the mapping between physical devices and memory regions are all in those few dozen product terms.

What a decoder actually looks like

A decoder takes address lines and produces select signals. In a PLD, that means product terms that match address ranges and outputs that drive the select pins.

Product term pattern Function
A set of address lines ANDed with fixed polarities An address range match
Several such terms ORed together A non-contiguous range
The match ANDed with a read or write strobe Direction-qualified select
The match ANDed with a qualifier from another device Arbitration or banking
Register output feeding back A latched or delayed select

The fifth row is the interesting one, because a latched select implies a timing requirement. Something in the system needed a select to stay asserted longer than the address remained valid, or needed it asserted earlier, and the PLD provides that.

Recovering the map from the terms

The conversion is direct once the pin assignment is known. Each input pin corresponds to a signal, and the pin assignment is a property of the device and the board, not of the design.

Step Output
Map pins to signals Which pin is A15, which is CS, which is RD
Read each output’s terms Range expressions
Resolve don’t-cares Ranges with unmapped bits become blocks
Order by address A memory map
Cross-check with the MCU firmware Confirmation

The third step is where a decoder differs from general logic. An address decoder deliberately ignores some address lines, and those ignored lines define the block size. A term that matches A15 through A12 and ignores A11 through A0 defines a four-kilobyte window mirrored throughout a larger range — which is either intentional aliasing or a bug that the firmware never noticed.

Why the map is worth having

A memory map is the interface between hardware and firmware, and on undocumented boards it exists nowhere. Recovering it answers questions that otherwise require probing every device on the bus.

Question Answer comes from
What address does this peripheral appear at Decode term for its chip select
How large is the window Which address lines the term ignores
Is the window mirrored Whether upper lines are also decoded
What polarity does the select have Whether the term is inverted
Are there gaps Ranges with no term matching

The fourth row matters when a bus analyser capture has to be interpreted: a capture showing activity at an address is meaningless if the select is active low and the analyst assumed active high.

Where the PLD is not a decoder

Sometimes the assumption is wrong, and the device really is doing something else. Three patterns are worth distinguishing before spending effort on decode reconstruction.

Observation Likely function
Most terms reference address lines Decoder
Terms reference clock and data, with registers Serial interface or shift register
Terms reference a small number of signals, deeply registered State machine
Terms combine timer outputs and enables Pulse generation
Terms include many feedback paths between cells Counter or sequencer

The third row is the one that changes the deliverable from a map to a transition table, which is covered in attacking CPLD source code.

The timing constants in the firmware

One of the more satisfying cross-checks is to compare the decode logic against the firmware’s assumptions. A firmware that inserts three wait states before accessing a peripheral is asserting that the peripheral needs three cycles, and that assertion is testable against the board.

Firmware constant Hardware counterpart
Wait state count Bus cycle timing and PLD delay
Bus width setting Data line connections and decode
Address of a peripheral Decode term
Access order at init Reset and enable sequencing
Polling loop length Ready signal timing

A discrepancy between a firmware constant and the hardware is a real finding. It usually means the firmware was written for a different board revision, and it explains intermittent failures that appear only on some units.

Reading the device

The read itself follows the same path as any other programmable logic device, and on these parts it is usually simple because the devices are small and their arrays are easy to access. The array content and its conversion into equations are covered in reading PLD binary into equations, and the container in reading the JED format.

Whichever order the two devices are read in, the bus topology decides what is possible, and that constraint is set out in extracting PLD and MCU code.

Device state Route
Unprotected Session read
Read inhibited Physical readout
Removed from the board Read in a programmer
Failed Behavioural reconstruction from the bus

The fourth row is the fallback and it is genuinely workable for a decoder: a bus capture during normal operation reveals which addresses produce which selects, and that is the memory map observed rather than inferred.

Services at this boundary

Work covers pin and signal mapping, decode term extraction, memory map reconstruction including aliasing and gaps, cross-checking against firmware constants, and behavioural confirmation from bus captures. It does not cover producing a program listing, because a decoder has no program, and it does not cover recovering the schematic that the decoder originally came from.

The reframing worth offering a customer is that reading this device is not about recovering code; it is about recovering the contract between the processor and the board.

Comments are closed.