Code structure and lookup routines
Draft. This page covers the 0110C6 program. The program area is byte-identical in all 16 public 0110C6 dumps. Most facts were read directly from the disassembly and are marked [verified]. Facts that come from data patterns or heuristics are marked [inferred]. Addresses are ECU bus addresses written as 24-bit hex. On the MS42 the bus address equals the file offset in the 512 KB image. See Memory map.
The disassembly was produced with an independent C166 disassembler (to be published separately), driven by tools/c166_analysis.py. The tool finds the disassembler through --c166dis DIR, the C166DIS environment variable, or ../c166dis. Its outputs are data/code_refs.json and data/coverage.json. See XDF coverage.
Address windows
| Bus address = file | Content | Status |
|---|---|---|
0x00000–0x0BFFF | Boot sector: trap vectors, reset code at 0x0660, serial boot loader at 0x8000 (magic 5AA5 56C9, checked at 0xBFFC) | verified |
0x0C000–0x0DFFF | External RAM, 8 KB (CS2, ADDRSEL2 = 0x00C1). Reached through DPP3 | verified (window), inferred (RAM) |
0x0E000–0x0E7FF, 0x0F600–0x0FDFF | XRAM and internal RAM (both RAM-tested at reset), SFRs | verified |
0x10000–0x10FFF | CS3 window (ADDRSEL3 = 0x0100). The flash underneath is erased | verified (window), inferred (peripheral chip) |
0x11000–0x3FFFF | Program code (segments 1–3) | verified |
0x48000–0x4FFFF | Calibration, 32 KB (data pages 0x12, 0x13; XDF BASEOFFSET 0x48000) | verified |
0x50000–0x53FFF | Program constants (DPP1 page 0x14): idents, application vectors, header, tables | verified |
0x60000–0x63FFF, 0x70000–0x7FFFF | Program code (segments 6, 7). The lookup library is at 0x060882 | verified |
0x40000–0x47FFF, 0x54000–0x5FFFF, 0x64000–0x6FFFF | Erased (0xFF) | verified |
There is no remapping. The C167 runs from flash on CS0 at bus 0, so all JMPS/CALLS targets and far pointers are file offsets. CS1 (ADDRSEL1 = 0x0807, 0x80000–0xFFFFF) is configured at reset, but the application does not use it [inferred].
Boot, vectors, application entry
- Reset [verified]. The reset vector (file
0x0000) goes to0x00:0660. The reset code setsCP=0xF600,DPP0/1/2 = 0x12/0x14/0x13,SYSCON,BUSCON0–4andADDRSEL1–4, then the stack. When the words at0x0BFFCareA55A C956, it jumps to the serial boot loader at0x00:8004. Otherwise it RAM-tests IRAM, XRAM and external RAM, sets the DPPs again (0x000AAA) and runs0x001D6A. That routine checks the program header and, if it is valid, enters the application throughPUSH R5; PUSH R4; RETSat0x0031BE. - Program header [verified]. The header is at file
0x502A4, in the constant page.0x502A4–0x502A9hold the upper limits for the RAM tests (0xFDFE,0xE642,0xD366). The reset code reads them and caps them at0xFDFE/0xE7FE/0xDFE2. The far pointer at0x502AA(offset, segment) is the application entry,0x03:FD4E(0110AD:0x03:FD62). The block from0x502EEholds seg:offset pointers to the calibration (0x048000,0x04FEE0,0x04800C,0x048010) and to the vector table. - Magic words [verified]. The program starts with
90 48 24 42at0x50000, and the calibration ends with42 24 48 90at0x4FFF0. The reset code checks both:0x0007CEchecks the first, and0x001368reads0x4FFF0–0x4FFF3. - Vectors [verified]. File
0x0000–0x01FFholds 128JMPSvectors. Vector 0 is the reset vector, and a few others go to boot handlers (for example vector 2 →0x00:320C). The rest areJMPS 0x05:(0x00A4 + 4n), so they forward to slot n of the application vector table at0x0500A4. There, used slots jump into segments 1, 2, 3 and 7, and unused slots jump to themselves. - Ident check [verified].
0x013390compares the calibration ident bytes0x48008–0x4800Dbyte by byte with the program ident at0x50036–0x5003B(0110C6in both).
Application DPPs
The reset code sets these DPPs, and the application keeps them [verified]. Across all 84,542 decoded instructions there are only two kinds of DPP write outside the boot sector. The diagnostic memory-access routines (0x0200F0–0x020CCA) save DPP0, load it with a page taken from the request bytes, and restore it after one access. 0x075E18 re-loads DPP0 = 0x12 before it calls back into the boot sector.
| DPP | Page | Window | Used for |
|---|---|---|---|
| DPP0 | 0x12 | 0x48000–0x4BFFF | Calibration, first 16 KB (near 0x0000–0x3FFF) |
| DPP1 | 0x14 | 0x50000–0x53FFF | Program constants (near 0x4000–0x7FFF) |
| DPP2 | 0x13 | 0x4C000–0x4FFFF | Calibration, second 16 KB (near 0x8000–0xBFFF) |
| DPP3 | 0x03 | 0x0C000–0x0FFFF | External RAM, XRAM, IRAM, SFRs (near 0xC000–0xFFFF) |
The whole calibration is therefore reachable through 16-bit near addresses. This is the main difference from the MS43, which uses far (offset, page) pointers. Scalars are plain mem operands. For example, MOVB RL4, 0x0008 reads file 0x48008, and MOV R13, 0x070C reads 0x4870C. Of the 1,258 scalar addresses read, 1,247 go through DPP0, 11 go through DPP2, and 2 use EXTS. All are reads. No copy of the calibration in RAM was found, and no code reads calibration data from RAM [inferred].
Task scheduler
These details were read at 0x076C9C, the last routine that the application entry calls [verified]:
- Tick. The tick is the CAPCOM compare interrupt CC26 (trap
0x3A, application vector0x05018C→0x0795DE). The handler re-arms the compare withADD CC26, #0xFAand sets the flag0xFD28.0at0x079620. The timer clock was not determined, so the tick period in time is not known. - Main loop (
0x076CA0). On each tick, the loop clears0xFD28.0, runs the fixed per-tick work, and steps the divider counters (for example0xFB6B, reloaded with 2). It services the watchdog and posts task IDs into ring buffers. - Background dispatch. Between ticks, the loop first serves a 16-bit request mask (
0xFDBA).PRIORpicks the highest set bit, and the far pointer comes from the table at DPP10x456E(file0x5056E). Then the loop drains a 32-entry FIFO of task IDs (0xE5D8, read/write indices0xE5D2/0xE5D3, overflow flag0xFD24.11). The far pointer comes from the table at DPP10x44C2(file0x504C2, 4 bytes per ID). Both dispatches call0x06002A(PUSH R5; PUSH R4; RETS, an indirect far call). A second FIFO (0xE5F8, indices0xE5D4/0xE5D5) is filled the same way.
Code discovery
The table shows the result of each discovery stage. The last column counts undecoded non-0xFF bytes in the code segments (0x10000–0x3FFFF and 0x54000–0x7FFFF).
| Stage | Instructions | Undecoded non-FF bytes | Evidence |
|---|---|---|---|
| Boot vectors, application vectors, application entry, switch tables | 23,120 | 196,599 | verified control flow |
+ code that follows a RET/RETS/JMP, kept only if it decodes cleanly | 84,541 | 12 | inferred |
| + tables of ≥2 far code pointers in the constant page | 84,542 | 12 | inferred |
No stage hits an invalid opcode. In the constant page only the vector table is decoded. The 0110AD program gives 80,388 instructions with 11 undecoded bytes.
Switch statements compile to two idioms. The first is MOV R0,[R0+#tab]; JMPI cc_UC,[R0]. The second, which is common in MS42, is CMPB RL4,#k; JMPA cc_UGT,default; …; SHL R4,#1; ADD R4,#tab; MOV R4,[R4]; JMPI cc_UC,[R4]. Both use 16-bit entries in the DPP1 page. 53 tables were resolved. The second idiom and the CMP(B)…; JMP cc_UGT range check were added to the disassembler's jump-table hook for this work. Without the range bound, unbounded tables produced bogus targets.
Lookup library (0x060882–0x060C43)
The library takes all arguments in registers. R12 is the near (DPP) address of the axis or table in the calibration, R13 is the input value, and the result comes back in R4. An axis search stores its result in shared RAM, and every table read that follows uses that result [verified]:
| RAM (0110C6) | Meaning |
|---|---|
0xFA0F | X index |
0xFA02 | X fraction (16 bit, from DIVLU) |
0xFA0E | Y index |
0xFA04 | Y fraction |
0xFA10 | Y-axis point count (the row stride) |
0xFD06.4 / 0xFD06.5 | X / Y "no interpolation" flag (input clamped to an axis end or exactly on a point) |
Axis format [verified]. The axis is a count N followed by N ascending values, both of the same width (u8 or u16). For example, 060882 reads RL2 = [R1+] (the count) and compares against the last value at R1 + N − 1. The XDF axis items start after the count: the axis at 0x488F3 has count 06 and the XDF item ldp_cam_av_in__eoi_ti_tra_ivvt starts at 0x488F4.
Map layout [verified], read from the MULU R13, R5 in 060A0C: element (ix, iy) is at table + (ix·Ny + iy)·elem. That is X-major, exactly as in MS43.
Example (0x070074): MOV R12,#0x08C8; MOVBZ R13,0xC424; CALLS 060882 searches the X axis at 0x488C8. Then MOV R12,#0xA523; CALLS 0609A4 reads a u8 curve at 0x4E523 (near 0xA523 → DPP2 → 0x4C000 + 0x2523).
| Routine | Role | Element | Interpolates | Objects |
|---|---|---|---|---|
060882 | X-axis search | u8 | yes | 170 |
0608CA | Y-axis search (also stores the count) | u8 | yes | 82 |
060916 | X-axis search | u16 | yes | 63 |
06095A | Y-axis search | u16 | yes | 36 |
060B40 / 060B66 | X / Y search, index only | u8 | no | 39 / 8 |
060B90 / 060BB4 | X / Y search, index only | u16 | no | 10 / 1 |
0609A4 | 1D curve | u8 | yes | 136 |
0609D8 | 1D curve | u16 | yes | 115 |
060A0C | 2D map | u8 | bilinear | 143 |
060AA4 | 2D map | u16 | bilinear | 82 |
060BDE / 060C2C | 1D, nearest point | u8 | no | 54 / 1 |
060BEA / 060C38 | 1D, nearest point | u16 | no | 34 / 2 |
060BF6 | 2D, nearest point | u8 | no | 20 |
060C10 | 2D, nearest point | u16 | no | 3 |
"Objects" is the number of distinct calibration objects passed to the routine. All 18 routines were read by hand. There are no descriptor routines like the MS43 ones. Axis and table element widths are independent, so any axis routine can be combined with any table routine. 0x060000–0x06087F holds the arithmetic helpers (multiply/divide with scaling, saturation, min/max). They take values, not calibration pointers.
Locating the library on other versions. The catalogue in tools/c166_analysis.py (LOOKUP_SIGS) stores, for each routine, its length and a SHA-256 of the instruction text with RAM, bit and jump addresses masked. The tool matches these signatures against every discovered function. On 0110AD the same 18 routines are found 0x24 bytes lower (06085E…). They use other RAM cells and flag bits, for example X index 0xFA0D and flag 0xFD06.2. research/2026-11-30/disasm/lookup_sigs.py re-checks this.
Other calibration access patterns
- Pointer arrays (per cylinder) [verified]. For example,
MOV R12,[R4+#0x6BBE]; CALLS 060BF6at0x02ECE8. The constant page holds arrays of near pointers indexed by cylinder: file0x52BBEhas 6 knock window startsid_knkwb_0..5,0x52BCAhas the endsid_knkwe_0..5, and0x52BD6has theip_fac_knk_0..5maps. The tool reads such an array up to the next constant-page address that the code names (18 objects). - Parameter records passed as arguments [verified].
0x02DFAAcopiesR13intoR6and readsR12from[R6+#4],[R6+#6]and so on. Its two callers passR13 = #0x6B4Eand#0x6B60. These are 18-byte VANOS records (intake and exhaust) in the constant page. Each holds near pointers to theip_t_fac_*_ivvt_*,ip_dly_*_ivvt_*,ip_t_ivvt_*andip_fac_ctl_ivvt_*tables. The tool resolves this case by finding the singleMOV Rk, R12..R15copy at the function entry and using the constant arguments at every call site (14 objects). - Fault-path records [inferred]. These are 16-byte records in the constant page (
0x528F4–0x52AC3and others):+0far pointer to a handler,+4id,+6near pointer to the u16 DTC code word in the calibration,+8..+Efour RAM pointers. The tool detects them by pattern (runs of ≥3) and finds 146 DTC code words. - Near-to-far idiom.
SHR Rx,#14on a known near address. The MAF tableid_maf_tab(0x497A6) is reached this way at0x075D80, andid_fac_ti_ris/rpl__cycnrat0x074B0E/0x074B2E. The extent is not known, so these count as weak references. - Checksum and monitor block.
0x4FEE0–0x4FEFFis read by the boot code (0x000AC2) and the monitor (0x01C1FE). It starts with the word0x27BE, then seg:offset0x048000, then0x04F843. It is probably a checksum and its range [inferred]. See Checksums.