SPRAB89A September 2011 – March 2014
Personality routines PR0, PR1, and PR2 use a byte-encoded sequence of instructions to describe how to unwind the frame. The first few instructions are packed into the three remaining bytes of the first word of the EXTAB; additional instructions are packed into subsequent words. Unused bytes in the last word are filled with “RET B3” instructions.
Although the instructions are byte-encoded, they are always packed into 32-bit words starting at the MSB. As a consequence, the first unwinding instruction will not be at the lowest-addressed byte in little-endian mode.
Personality routine PR0 allows at most three unwinding instructions, all of which are stored in the first EXTAB word. If there are more than three unwinding instructions, one of the other personality routines must be used.
For PR1 and PR2, bits 23-16 encode the number of extra 32-bit words of unwinding instructions, which can be 0.
Table 11-2 summarizes the unwinding instruction set. Each instruction is described in more detail after the table.
Encoding | Instruction | Description |
---|---|---|
00kk kkkk | SP += (k << 3) + 8 | Increment SP by a small constant |
1101 0010 kkkk kkkk . . . | SP += (ULEB128 << 3) + 0x408 | Increment SP by a ULEB128-encoded constant |
1000 0000 0000 0000 | CANTUNWIND | Function cannot be unwound, but might catch exceptions |
100x xxxx xxxx xxxx | POP bitmask | POP one or more registers [x != 0] |
101x xxxx xxxx xxxx | POP bitmask | POP one or more registers from a C64x+ compact frame [x != 0] |
1100 nnnn xxxx xxxx . . . | POP register | n represents the number of registers to be popped, which are encoded in the following 4-bit nibbles |
1101 0000 | MV FP, SP | Restore SP from FP instead of incrementing SP |
1101 0001 | _ _C6000_pop_rts | Simulate a call to _ _C6000_pop_rts |
1110 0111 | RET B3 | Unwinding complete for this frame |
1110 xxxx | RETURN or restore B3 | B3 := register x (x != B3) |
All other bit patterns are reserved.
The following paragraphs detail the interpretation of the unwinding instructions.
Small Increment
The value of k is extracted from the lower 6 bits of the encoding. This instruction can increment the SP by a value in the range 0x8 to 0x200, inclusive. Increments in the range 0x208 to 0x400 should be done with two of these instructions.
Large Increment
The value ULEB128 is ULEB128-encoded in the bytes following the 8-bit opcode. This instruction can increment the SP by a value of 0x408 or greater. Increments less than 0x408 should be done with one or two Small Increment instructions.
CANTUNWIND
This instruction indicates that the function cannot be unwound, usually because it is an interrupt function. However, an interrupt function can still have try/catch code, so EXIDX_CANTUNWIND is not appropriate.
POP Bitmask
This two-byte instruction indicates that up to thirteen callee-saved registers should be popped from the virtual stack, as specified by the bitmask. Registers must be restored in the same order they appear in the safe debug ordering.
When any registers are popped using the "POP bitmask" instruction, the SP is first implicitly incremented by the size of the callee-saved register area, rounded up to 8 bytes. This is in addition to any explicit SP increment instructions. However, if the "MV FP, SP" instruction has been used, "POP bitmask" does not implicitly increment SP.
POP Bitmask; C64x+ Compact Frame
The same as POP Bitmask, but indicates the use of C64x+ compact frame layout, which may leave holes on the stack in order to favor the use of SP-autodecrementing stores. The unwinder must be aware of the algorithm used to place the holes and compensate accordingly.
POP Register
In cases where the compiler was unable to maintain safe debug order, or for compilers which choose different layouts, each callee-saved register can be popped individually. The first four bits after the 4-bit opcode indicate the number of registers to be popped. Each subsequent 4-bit nibble represents the encoding of a callee-saved register, or the special value 0xF, which represents a hole. If a hole is indicated, the virtual SP should be decremented but no register should be popped.
The 4-bit register encoding is as follows:
Encoding | Register | Encoding | Register |
---|---|---|---|
0000 | A15 | 1000 | A14 |
0001 | B15 | 1001 | A13 |
0010 | B14 | 1010 | A12 |
0011 | B13 | 1011 | A11 |
0100 | B12 | 1100 | A10 |
0101 | B11 | 1101 | Reserved |
0110 | B10 | 1110 | Reserved |
0111 | B3 | 1111 | "hole" |
MV FP, SP
This instruction restores SP from FP (A15) instead of incrementing SP. When an FP is available, it is easier to just restore the SP value from the FP. For the DATA_MEM_BANK layout, this may be the only way to restore SP.
_ _C6000_pop_rts
This instruction indicates that all of the register restoring is done by a call to _ _C6000_pop_rts. The behavior of this function should be simulated by the unwinder. _ _C6000_pop_rts implicitly restores B3 and does a RET B3.
Restore B3
If r represents any register other than B3, this instruction encodes "MV reg, B3", which restores B3 from “reg”. This must be performed before any POP instruction in case the POP overwrites the register.
RET B3
This instruction encodes a simulated return, indicating that unwinding is complete for this frame. Note that the encoding is the same as “Restore B3” but with the source register indicated as B3 itself.
Every sequence of unwinding instructions ends with an explicit or an implicit "RET B3". This instruction can be omitted from the explicit unwinding instructions, and the unwinder will implicitly add it.