Skip to content

26. Action list opcode 0x7F is a call, and the operands prove it without the firmware

Section 17 left the opcode table as the most valuable thing to look for, and said the meanings had to be read out of the arch 14 firmware. One of them did not need to be.

The search that did not work, first

The plan was the obvious one: the compiler emits a switch as an XORLW chain, so the interpreter should be a chain whose case values are action list opcodes. A scan of the whole 700 image for chains of three or more cases, scored against the opcodes the configs actually use, returned eleven candidates and every one of them was the same chain read from a different starting offset: the USB state dispatch at 0x0C720, which harmony/pic18/chains.py already documents as 70 cases running to 0x0C8FE.

That is the trap the module's own docstring warns about, arriving exactly as described: "the value of a case depends on where the walk started, so starting one comparison too late shifts every case value, and both readings can look plausible". A scanner that starts a walk at every XORLW in the image finds one chain many times and calls it many chains.

So the interpreter is not an XORLW chain, or it dispatches on something derived from the opcode rather than on the opcode itself. Both remain open.

What worked instead

The operand is a u16 and the opcode is one byte, so every opcode has an operand distribution, and a distribution is testable against structures derived from elsewhere in the file.

700 600
0x7F uses 2795 1465
distinct operands 1576 834
operand range 52 to 7655 23 to 4755
action lists in the config 8037 4955

Every operand is a valid index into the action list table. That alone would be suggestive rather than conclusive, since the table is large and a range can fit by luck. The closure is where the range stops.

Section 17 established that the lists are packed into exactly five contiguous runs, which is why four consecutive table entries per config are not 1 + 3 * count apart. Those runs end at these indices:

700   17, 4323, 5147, 7655, 8036
600   11, 2721, 3154, 4755, 4954

0x7F's largest operand is 7655 on the 700 and 4755 on the 600. Both are exactly the last index before the final run, and not one operand in either config reaches past it.

The run boundaries come from the addresses in the pointer table and the counts inside the lists. The operand range comes from the instruction stream. Those are unrelated parts of the file, and the boundary lands on the same index in both configs at two different values. A range that fits by luck does not do that twice.

What it means, and what it leaves

0x7F takes an action list index and runs it: a call. That agrees with harmony-decompiler's arch 9 table, where 0x7F is "run an action list", so this meaning transfers across architectures even though the wider inventory does not. Per decision 7 the upstream table was a hypothesis to test rather than a fact to adopt, and this is one entry tested and held.

The final run is the interesting leftover. 381 lists on the 700 and 199 on the 600 are addressed by the table and never called by a 0x7F, so something else reaches them and it is not another action list. They are entry points. The key table has 163 and 162 records respectively, which does not match, so the obvious guess is ruled out. The next section finds what does.

Base slot 8 is what reaches the final run

If something names those lists, the indices are somewhere in the file, so the search is a sweep: read a u16 at every byte offset in the container and ask which section the hits fall in. One section answers.

700 600
final run indices 7656 to 8036, 381 lists indices 4756 to 4954, 199 lists
u16 readings inside base slot 8 3591 1962
hits in that index band, expected by chance 20.9 6.0
hits observed 384 199
distinct values among them 381 199
of the run they cover all of it, with nothing left over all of it

The band is 381 values of 65536, so a section of this size should contain about twenty by accident. It contains 384, they are 381 distinct values, and those 381 values are exactly the run: nothing missing, nothing outside. On the 600 it is cleaner still, 199 references for 199 lists, a bijection.

So base slot 8 owns the final run of action lists, one reference each. Two of the 700's values appear more than once, which accounts for 384 against 381 and is what you would expect of a structure where two entries share a list.

What this sweep cannot say is whether slot 8 also calls lists in the other four runs. Those span indices 0 to 7655, which is twelve percent of the u16 space, so the noise floor is high enough to swallow the signal: the same scan reports about a thousand such readings in the 700 and there is no way to tell a reference from a coincidence at that density. Answering it needs slot 8's record layout, not a wider sweep.

That layout is not established. The references are not on a fixed stride: the gaps between them are mostly four and five bytes with a long tail out to twenty two, so slot 8 holds variable length records rather than a table. Which is a useful thing to know before anyone tries to read it as one.

Slot 8 was already the section worth looking at. Section 16 records it as the only section whose size changed under the one documented edit in the 700 pair, and docs/decisions.md names it as the second target of step 6. It is now also the section that owns 381 action lists.

Two structural facts about operands, whatever the opcodes mean

Some operands are signed. 0x07 carries only 0xFFF2 to 0xFFFF, that is -14 to -1, and 0x1F only 0xE800 to 0xFF0A. Read as unsigned they are numbers with no referent anywhere in the file; read as signed they are small negative values.

Several carry bit 15 as a flag rather than as magnitude. 0x6C tops out at 0x8014 on both configs, which is itself odd for an index, and 0x71 at 0x833E on the 700 against 0x8336 on the 600. An index with a marker bit fits; a range does not.

Neither is claimed as a meaning. They are constraints on what the meanings can be.


Section 25 | the archive | section 27. Section 26 of the findings archive, which is frozen; the reference holds the current answer. The archive on GitHub.