Code structure and lookup routines
Draft. This page covers the 430069 program. Most facts were read directly from the disassembly. A few were inferred from data patterns and are marked as such. Addresses are ECU bus addresses (seg:offset, written as 24-bit hex) unless they say file. File offset = bus address − 0x80000 for segments 9–14, and is 1:1 for the boot segment and the calibration. See Memory map.
The disassembly was produced with an independent C166 disassembler (to be published separately), driven by tools/c166_analysis.py. That tool locates the disassembler through --c166dis DIR, the C166DIS environment variable, or ../c166dis by default. The committed outputs are data/code_refs.json and data/coverage.json.
Address windows
| Bus address | File | Content | Status |
|---|---|---|---|
0x000000–0x00BFFF | 0x00000 | Boot sector (reset/trap vectors, boot code at 0x2D06, 0x8000–0xBFFF) | verified |
0x070000–0x07FFFF | 0x70000 | Calibration (data pages 0x1C–0x1F) | verified |
0x090000–0x0EFFFF | 0x10000 | Program (segments 9–14) | verified |
0x0EC000–0x0EFFFF | 0x6C000 | Program constants (DPP1 page 0x3B): lookup descriptors, fault-path records, pointer tables, app vectors | verified |
0x040000–0x05FFFF | none | External RAM (ADDRSEL2 = 0x0405). 0x50000–0x5EFFF receives a copy of the calibration | verified (copy), inferred (purpose) |
Boot, vectors, application entry
- Boot vectors. File
0x0000–0x01FFholds 128JMPSvectors. Reset goes to0x00:2D06, which is boot init: it setsCP=0xF600,DPP0/1/2 = 0x1C/0x3B/0x10,SYSCON,BUSCON0–4andADDRSEL1–4. The other 127 vectors go to0x0E:EExx. - Application vectors. File
0x6EE00(0x0EEE00) is the application's own vector table, alsoJMPS. Unused slots jump to themselves. - Program header. The header is at file
0x6ED00. The far pointer at+0x06is the application entry,0x0E:366A. - Init. The entry calls
0x0E2EBA. When the flag0xF8DCbit 14 is clear, that routine runs0x0E2FAE, which copies the calibration (0x70000–0x7EFFF) into RAM at0x50000in 16 KB slices by switchingDPP1/DPP2. It then restores the static application DPPs:
| DPP | Page | Window | Used for |
|---|---|---|---|
| DPP0 | 0x1C | 0x70000–0x73FFF | Calibration scalars (mem operands 0x0000–0x3FFF) |
| DPP1 | 0x3B | 0x0EC000–0x0EFFFF | Program constants (0x4000–0x7FFF) |
| DPP2 | 0x10 | 0x40000–0x43FFF | External RAM (0x8000–0xBFFF) |
| DPP3 | 0x03 | 0x0C000–0x0FFFF | Internal RAM, SFRs (0xC000–0xFFFF) |
Calibration pages 0x1D–0x1F (0x74000–0x7FFFF, the axes and maps) are never reached through a static DPP. They are reached only through far pointers (offset, page), which the lookup library loads into DPP0 or applies with EXTP. All 1,635 scalar reads found in the code go through DPP0 to flash page 0x1C. None go to the RAM copy. In stock code the RAM copy is never read directly, so it is probably used for calibration emulation or online tuning (inferred).
Code discovery
The code area was discovered in four stages. All percentages are of the non-0xFF bytes in file 0x10000–0x6FFFF.
| Stage | Instructions | Functions | Decoded | Evidence |
|---|---|---|---|---|
| Vectors + application entry + switch tables | 20,406 | 331 | 16.7 % | Verified control flow |
+ code that follows a RET/RETS/JMPS (speculative, kept only if it decodes cleanly) | 111,190 | 1,712 | 97.4 % | Inferred |
+ tables of ≥2 far code pointers (lo16, seg16, for example file 0x6E286) | 111,668 | 1,752 | 97.9 % | Inferred |
| + isolated far pointers | 111,690 | 1,763 | 97.9 % | Inferred |
No stage hits an invalid opcode. The constant page 0x6C000–0x6FFFF stays undecoded apart from the vector table.
Switch statements compile to MOVBZ R0,RLx; MOV R0,[R0+#tab]; JMPI cc_UC,[R0], with 16-bit entries in the DPP1 page. There are 27 such tables, for example at 0x0EE68A (resolved by the tool).
Lookup library (0x0D0002–0x0D10EB)
The library uses Tasking-style register parameters. Arguments go in R12–R15 and the result comes back in R4. Axis-search results are shared through RAM:
| RAM | Meaning |
|---|---|
0xFB6B | X index |
0xE390 | X fraction (16-bit, from DIVLU) |
0xFB6C | Y index |
0xE392 | Y fraction |
0xFB6D | Y axis count (row stride) |
Axis format (verified): a count N (u8 or u16, the same width as the values) followed by N ascending values. The XDF axis tables start after the count. For example, the axis at file 0x74209 has count 04 and its values 00 10 20 48 start at XDF 0x420A.
Map layout (verified, from the MULU in 0x0D0168): element (ix, iy) is at table + (ix·Ny + iy)·elem. That is, X-major: the X-axis index selects a row of Ny consecutive values.
Direct routines: far pointer in R13:R12 (page:offset)
An axis search is followed by a table read. For example, at 0x0B14B2: R12=#0x0209, R13=#0x1D → CALLS 0D0060, then R12=#0x28CC, R13=#0x1F → CALLS 0D022A. The axis is at 0x74209 and the curve at 0x7E8CC.
| Routine | Role | Element | Interpolates | Items |
|---|---|---|---|---|
0D0060 | X-axis search, input R14 (u8) | u8 | yes | 151 |
0D0002 | Y-axis search | u8 | yes | 73 |
0D0114 | X-axis search | u16 | yes | 63 |
0D00B6 | Y-axis search | u16 | yes | 31 |
0D0462 / 0D03EE | X / Y search, index only | u8 | no | 33 / 6 |
0D039A / 0D0358 | X / Y search, index only | u16 | no | 6 / 1 |
0D022A | 1D curve | u16 | yes | 125 |
0D0262 | 1D curve | u8 | yes | 126 |
0D0168 | 2D map | u16 | bilinear | 104 |
0D029A | 2D map | u8 | bilinear | 126 |
0D0454 / 0D042E | 1D, nearest | u16 / u8 | no | 23 / 60 |
0D03D2 / 0D043A | 2D, nearest | u16 / u8 | no | 2 / 8 |
"Items" is the number of distinct calibration objects passed to each routine (from data/code_refs.json).
Descriptor routines: R12 = near (DPP1) pointer to a descriptor, R13 = X input, R14 = Y input
Descriptors are in the program-constant page and are 8 bytes (1D) or 12 bytes (2D). For example, at file 0x6C910: 0021 1E00 DC0D 1D00 E60D 1D00.
| Offset | Field |
|---|---|
| +0 / +2 | Table offset / page |
| +4 / +6 | X-axis offset / page |
| +8 / +A | Y-axis offset / page (2D only) |
| Routine | Dims | X | Y | Table | Interpolates | Items |
|---|---|---|---|---|---|---|
0D049A | 2D | u16 | u16 | u16 | yes | 136 |
0D05B2 | 2D | u8 | u8 | u8 | yes | 100 |
0D0760 | 2D | u8 | u16 | u8 | yes | 12 |
0D0888 | 2D | u8 | u16 | u16 | yes | 40 |
0D09A6 | 2D | u16 | u8 | u16 | yes | 22 |
0D0B4A | 2D | u8 | u8 | u16 | yes | 52 |
0D0C72 | 2D | u16 | u8 | u8 | yes | 35 |
0D0EAC | 2D | u16 | u16 | u8 | yes | 60 |
0D107C | 2D | u8 | u8 | u16 | no | 6 |
0D06D6 | 1D | u8 | u8 | yes | 76 | |
0D0AC8 | 1D | u16 | u16 | yes | 50 | |
0D0D96 | 1D | u8 | u16 | yes | 96 | |
0D0E22 | 1D | u16 | u8 | yes | 88 | |
0D0FD4 | 1D | u16 | u8 | no | 10 | |
0D100A | 1D | u8 | u16 | no | 11 | |
0D1044 | 1D | u8 | u8 | no | 18 |
How the widths were classified:
- Element widths: taken from the
CMPversusCMPBaxis compares and from theMOVversusMOVBthat follows eachEXTP R12, in every routine. Checked by hand on0D049Aand0D06D6(verified). The rest were classified by tool from the instruction mix (inferred, high confidence). - Library location: the 4,352 bytes of the library (file
0x50000–0x510FF) are byte-identical in 430066 and 430069.tools/c166_analysis.pychecks this before it applies the catalogue.
Other calibration access patterns
- Scalars. Direct
memoperands through DPP0, for exampleMOVB RL4, 0x0B2Breads file0x70B2B. There are 1,635 distinct addresses: 1,059 byte and 576 word. All of them are reads. - Fault-path records (inferred). These are 22-byte records in the constant page, for example at file
0x6D5A0. Fields+2..+8hold four consecutive DPP0 pointers to the u16 DTC wordsc_dtc_<path>_0..3. The DTC handlers0x0AB27C,0x0AB46Eand0x0AB666receive the record inR13. They were detected by pattern: 644 words in 161 records. - Far-pointer tables. The constant page holds tables of far data pointers (
offset,page) into pages0x1D–0x1F. Examples are file0x6CAB8, which points at the knock windowsid_knkwb_*, and file0x6CAE8, which points atip_fac_knk_*(apparently one entry per cylinder). In total, 573 pointers into the calibration were found (descriptor fields included). There are also 16 lookup calls in0x0B5004–0x0B5F36that loadR12/R13from such records ([R6+#0x0E]); the tool cannot resolve those statically. - Near-to-far idiom.
MOV R5,#a; AND R4,#0x3FFF; SHR R2,#14; MOV R2,[R2+#0xFE00]builds a far pointer from a near address. The MAF and SAF linearisation tables at0x70EC6and0x710C6are reached this way, at0x0DE272and0x0DE516.