Skip to content

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 addressFileContentStatus
0x000000–0x00BFFF0x00000Boot sector (reset/trap vectors, boot code at 0x2D06, 0x8000–0xBFFF)verified
0x070000–0x07FFFF0x70000Calibration (data pages 0x1C–0x1F)verified
0x090000–0x0EFFFF0x10000Program (segments 9–14)verified
0x0EC000–0x0EFFFF0x6C000Program constants (DPP1 page 0x3B): lookup descriptors, fault-path records, pointer tables, app vectorsverified
0x040000–0x05FFFFnoneExternal RAM (ADDRSEL2 = 0x0405). 0x50000–0x5EFFF receives a copy of the calibrationverified (copy), inferred (purpose)

Boot, vectors, application entry ​

  • Boot vectors. File 0x0000–0x01FF holds 128 JMPS vectors. Reset goes to 0x00:2D06, which is boot init: it sets CP=0xF600, DPP0/1/2 = 0x1C/0x3B/0x10, SYSCON, BUSCON0–4 and ADDRSEL1–4. The other 127 vectors go to 0x0E:EExx.
  • Application vectors. File 0x6EE00 (0x0EEE00) is the application's own vector table, also JMPS. Unused slots jump to themselves.
  • Program header. The header is at file 0x6ED00. The far pointer at +0x06 is the application entry, 0x0E:366A.
  • Init. The entry calls 0x0E2EBA. When the flag 0xF8DC bit 14 is clear, that routine runs 0x0E2FAE, which copies the calibration (0x70000–0x7EFFF) into RAM at 0x50000 in 16 KB slices by switching DPP1/DPP2. It then restores the static application DPPs:
DPPPageWindowUsed for
DPP00x1C0x70000–0x73FFFCalibration scalars (mem operands 0x0000–0x3FFF)
DPP10x3B0x0EC000–0x0EFFFFProgram constants (0x4000–0x7FFF)
DPP20x100x40000–0x43FFFExternal RAM (0x8000–0xBFFF)
DPP30x030x0C000–0x0FFFFInternal 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.

StageInstructionsFunctionsDecodedEvidence
Vectors + application entry + switch tables20,40633116.7 %Verified control flow
+ code that follows a RET/RETS/JMPS (speculative, kept only if it decodes cleanly)111,1901,71297.4 %Inferred
+ tables of ≥2 far code pointers (lo16, seg16, for example file 0x6E286)111,6681,75297.9 %Inferred
+ isolated far pointers111,6901,76397.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:

RAMMeaning
0xFB6BX index
0xE390X fraction (16-bit, from DIVLU)
0xFB6CY index
0xE392Y fraction
0xFB6DY 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.

RoutineRoleElementInterpolatesItems
0D0060X-axis search, input R14 (u8)u8yes151
0D0002Y-axis searchu8yes73
0D0114X-axis searchu16yes63
0D00B6Y-axis searchu16yes31
0D0462 / 0D03EEX / Y search, index onlyu8no33 / 6
0D039A / 0D0358X / Y search, index onlyu16no6 / 1
0D022A1D curveu16yes125
0D02621D curveu8yes126
0D01682D mapu16bilinear104
0D029A2D mapu8bilinear126
0D0454 / 0D042E1D, nearestu16 / u8no23 / 60
0D03D2 / 0D043A2D, nearestu16 / u8no2 / 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.

OffsetField
+0 / +2Table offset / page
+4 / +6X-axis offset / page
+8 / +AY-axis offset / page (2D only)
RoutineDimsXYTableInterpolatesItems
0D049A2Du16u16u16yes136
0D05B22Du8u8u8yes100
0D07602Du8u16u8yes12
0D08882Du8u16u16yes40
0D09A62Du16u8u16yes22
0D0B4A2Du8u8u16yes52
0D0C722Du16u8u8yes35
0D0EAC2Du16u16u8yes60
0D107C2Du8u8u16no6
0D06D61Du8u8yes76
0D0AC81Du16u16yes50
0D0D961Du8u16yes96
0D0E221Du16u8yes88
0D0FD41Du16u8no10
0D100A1Du8u16no11
0D10441Du8u8no18

How the widths were classified:

  • Element widths: taken from the CMP versus CMPB axis compares and from the MOV versus MOVB that follows each EXTP R12, in every routine. Checked by hand on 0D049A and 0D06D6 (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.py checks this before it applies the catalogue.

Other calibration access patterns ​

  • Scalars. Direct mem operands through DPP0, for example MOVB RL4, 0x0B2B reads file 0x70B2B. 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..+8 hold four consecutive DPP0 pointers to the u16 DTC words c_dtc_<path>_0..3. The DTC handlers 0x0AB27C, 0x0AB46E and 0x0AB666 receive the record in R13. 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 pages 0x1D–0x1F. Examples are file 0x6CAB8, which points at the knock windows id_knkwb_*, and file 0x6CAE8, which points at ip_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 in 0x0B5004–0x0B5F36 that load R12/R13 from 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 at 0x70EC6 and 0x710C6 are reached this way, at 0x0DE272 and 0x0DE516.