Skip to content

274. The state variable seeder on three architectures, and where arch 9 differs

Danny asked whether section 138's seeder was checked against the other firmwares, after the question of how a remote knows which activity value means "nothing is running" was answered with "it does not work it out, the record states it and the firmware seeds the variable from it". That answer was read on the Harmony One (arch 12) alone and the section did not say so.

It holds on all three architectures whose firmware is in hand. Arch 9 gets there differently in two ways, and one of them is a behavioural difference rather than a spelling.

The shape, which is common to all three

Each firmware, at boot, asks its section seeker for raw slot 13, reads the header, and walks the records writing each one's first into the state variable it belongs to. The store is the same rule everywhere: below the table's own narrow count one byte, at or above it index -= narrow, doubled, += narrow, two bytes.

arch 12 (Harmony One) arch 14 (Harmony 700 reference image) arch 9 (Harmony 525)
section seeker 0x2BA76 0x10B92 0x066A8
the seeding loop 0x2A2DE 0x179F0 0x047D6
the store 0x2A6A2 0x17DD8 0x04B40
header fields read count, narrow, wide count, narrow, wide count, narrow, wide, narrowAgain

The closure, and it is a census rather than an argument

A seeker takes its raw slot in a register that every caller loads with a literal, so one scan of an image names every slot that firmware ever fetches. Scanned independently here, and the two published site counts come back exactly:

architecture call sites slots fetched
12 24 2 to 19 except 8
14 19 3 to 17
9 17 2 to 17

Three things follow. Slot 13 is on all three lists, which is what makes the loops above the state table's readers rather than something that resembles one. Raw slots 0 and 1 are on none of them, so section 47's finding that the name tree and the architecture record are host side is reproduced on a third architecture by a route that had nothing to do with it. And arch 12's hole at raw slot 8 is its NULL slot, which the published range wording hid; a range is the wrong shape for this claim and the test asserts the set.

The first difference: arch 9 has no "no initial value" marker

Arch 12 and arch 14 compare the record's first against 0xFEFE, a byte at a time, and skip the store when it matches. That is how a record says the variable has no initial value.

Arch 9's loop has no such comparison. It fills the array's unused tail with 0xFE after the loop instead, from the real size, narrow + 2 * wide, up to 64, and there is a second entry that fills from 13 up to 64 when there is nothing to seed from. So 0xFE is the same "no value" convention on all three and arch 9 applies it as a default rather than testing for it.

The second difference: the guard is per variable on arch 9 and all or nothing elsewhere

Arch 12 and arch 14 carry one byte which, when nonzero, skips the store for every variable. On arch 12 section 138 traced what sets it: a checksum over 109 bytes of data memory, so a warm start preserves every variable including the clock and a power cycle reseeds them all.

Arch 9's loop reads its guard and, when it is nonzero, stores unconditionally. When it is zero it compares the index against a literal 13 and skips everything below it. Thirteen is the count of variables the firmware owns, section 138, the clock among them. So on that architecture the two paths are "seed everything" and "seed the configuration's variables but leave the firmware's alone", where on the other two they are "seed everything" and "seed nothing".

What sets arch 9's guard, which is the startup path and a runtime one

Traced, and it is two call sites with a literal each. The guard at 0x1A2 has exactly one reader, the loop, and one writer, 0x07930, which copies it from 0x101 and then calls the seeder. 0x101 in turn has two writers and both are immediately followed by that call:

flag what it does
0x04C72 MOVLW 0x01 seeds every variable, the firmware's thirteen included
0x02498 CLRF seeds the configuration's variables and leaves 0 to 12 alone

The flag 1 site is the application's own startup. Its enclosing routine is called from 0x07FB4, which sets FSR1 and FSR2 to 0x300, clears TBLPTRU and then calls it in an endless loop, which is a C runtime entering main. 0x07FB4 is reached by a single GOTO from 0x01008, and the reset vector's own target at 0x00EF6 is a different routine of the same shape one page lower, which is the bootloader's. That split is corroborated from outside the disassembly: the external flash copy of this firmware is this image from 0x1000 onward, so 0x1000 is where the application starts and the page below it is the bootloader's.

So on a Harmony 525 a startup seeds the clock from the configuration, exactly as a power cycle does on a Harmony One, and the two architectures agree about the case that matters most.

The flag 0 site is a runtime path and this section stops short of naming it. It sits under a small state machine on 0x3DC, whose two cases decode to 1 and 2 through the running XOR that an XORLW chain requires, and 0x3DC is the low nibble of a byte the code has just required to be 0xC0 or above. What that byte is, is not established here, so what the reseed is a response to is open. What is established is the half the question needed: it is not the startup path, so the design is "seed everything at boot, and reseed the configuration's variables without disturbing the clock at some later moment", where arch 12's is "seed everything on a cold boot and nothing on a warm one".

What it means for the question that prompted it

Nothing changes. The value meaning "no activity is running" is the activity counter's first, it is stated rather than inferred, and every architecture in hand seeds the variable from it. Section 273's numbering rule rests on the field and not on the seeder, so it is unaffected either way.

What would falsify it

An image whose slot 13 fetch is absent from its seeker census. A store that reads a width from anywhere but the table's own narrow. An arch 9 path that compares a record against 0xFEFE, or an arch 12 or arch 14 loop that compares an index against 13. A third writer of arch 9's guard, or a reader of it outside the loop.

Where it lands

  • docs/config-format.md, base slot 13's record, beside first.
  • tests/test_state_seeder.py, which pins the census, the site counts, the marker on the two that have it and the index rule on the one that does not.

Section 273 | the archive | section 275. Section 274 of the findings archive, which is frozen; the reference holds the current answer. The archive on GitHub.