# What actually is a shadow register?

I noticed the term Shadow Register while going through a datasheet of a TMS320F28335 DSP. What does it actually mean? Does it have a physical location in the CPU as the general purpose registers have?

• Which micro-controller? – Leon Heller Oct 21 '13 at 9:20
• @LeonHellersorry for the mistake.. its a dsp... TMS320F28335 – noufal Oct 21 '13 at 9:26

I'm guessing you've encountered this in terms of PIC programming. PICs originally had I/O ports handled in a very direct manner - you could read what values they had externally, or write what values you output, both on the same address. The downside of this was that the value you were trying to output might not match the state on the pin - something else could be driving it more strongly, or it might just not have finished the change yet. This meant that a separate variable was needed to track what state you intended, rather than got, if you wanted to update only parts of a port. As I recall that separate variable is what is usually referred to as a shadow register, since you always used it to store a copy of the (invisible) output register. More recent PICs avoid this by adding the "latch" addresses, where the output register can be read. This is common in other microcontrollers as well, such as the port vs pin addresses on AVR.

There's a similar term in PC architecture for shadow memory; in that case, it usually means a section of RAM used to store a copy of a slower ROM, and mapped to the same address. Again it stores a copy of some other storage, which is hidden because the copy replaces it in the address space.

Edit: Seeing it's a TMS320, the shadow register provides a double buffer; this technique is used to ensure updates happen at a proper time. Compare the use of frame buffer swaps in graphics. The Data Manual shows shadow and active versions of several registers. Consider for instance a register indicating the end of a pulse; if you were to alter it to a shorter pulse, doing so when the pulse has not yet finished might cause one pulse never to finish at all (since it never was equal to the end value in that cycle). But if you write to the shadow register, the hardware can copy it into the active register at a point known to be safe - for instance, exactly when the timer wraps around. This isn't described in the Data Manual, which covers particular parameters for a given chip; knowing TI, there is likely a separate manual describing the function of each block; this one has a mention of Shadow Mode in section 2.2.

• Another use of of the term "shadow" applied particularly to registers is the mapping of architectural register names to different physical registers to allow a fast full or partial context switch. ("Banked register" is sometimes used as a synonym.) Such is typically intended to accelerate interrupts. – Paul A. Clayton Oct 21 '13 at 13:44

Simply put, shadow register is a register devised within the microcontroller for purpose of holding certain data to be used later. The name "Shadow" implies to duplicate some value and use it again - so it wont get lost.

shadow and mirror registers all refer to registers that can be accessed from multiple addresses. For example, in the hardware, a given register has one instance located at F00h. However, if it has an alias at 1F00h, reading or writing to F00h is the same as reading or writing to 1F00h and vice versa.

• It would be a nice addition if explain what the purpose of those shadow registers is. – Rev Aug 20 '14 at 11:15