If every chip on a JTAG chain receives the same TMS and TCK, how can the adapter talk to just one of them?
Every chip has an instruction register in the chain. The adapter loads a real command into the target chip's register and BYPASS into all the others, which shrinks each of them to a single pass-through bit.
TMS drives a small state machine (the TAP controller, 16 states) that is identical in every chip, so all chips on the chain are always in the same state. What differs is the data each one receives. The state machine has two shifting paths:
- Instruction path. In the instruction-shift states, the bits on TDI go into each chip's instruction register. The adapter shifts one long pattern that contains a separate instruction for each chip, in chain order.
- Data path. The instruction decides which data register each chip connects between its TDI and TDO in the data-shift states: the boundary-scan cells, a device ID register, a debug register, a flash programming register, and so on.
To talk to one chip, the adapter gives that chip the instruction it wants and gives every other chip BYPASS. BYPASS connects a one-bit register, so the uninteresting chips each add just one clock of delay instead of hundreds of boundary-scan bits. The adapter knows the order of the chips and pads its data with one bit per bypassed device.
This is also how a debugger finds out what is connected. At start-up it reads the IDCODE of every chip in the chain. The OpenOCD log for an ESP32 shows two of them: esp32.tap0 and esp32.tap1, one TAP (test access port) for each of the two processor cores, both reporting the Tensilica manufacturer code.
Go deeper:
Wikipedia — JTAG — the 16-state TAP controller, instruction and data registers, BYPASS and IDCODE.
OpenOCD — Debug Adapter Configuration — how a host tool describes the adapter that drives the chain.