cpu > asic > dsp work

This commit is contained in:
Cryan209 committed 2026-09-14 00:39:33 +12:00
1 parent c8b4195fb1
commit 0c43c564a4
10 files changed
+312 -24

No files matched your search

+66 -10
View File
@@ -386,6 +386,9 @@ class CourierDspBridge:
self.core = NativeC5x(image)
self._configure_boot_rom()
self._configure_frame_interrupt()
self._reset_asserted = True
self._loader_started = False
self._download_destination = image.dsp_program_segments()[0][0]
if dsp_trace_range is not None and hasattr(self.core, "set_pc_trace_range"):
# A third C50 trace window, for a handler the two compiled-in
# ranges do not cover.
@@ -898,9 +901,62 @@ class CourierDspBridge:
origin, resident = self.image.dsp_program_segments()[0]
# The boot loader must write the resident, not execute a preloaded copy.
self.core.load_program(bytes(len(resident)), origin)
self.core.host_write(0xFFFF, 4) # ASIC's 16-bit serial boot strap.
self.core.set_pc(0)
def set_reset(self, asserted: bool) -> None:
"""Drive the shared C51/codec reset net at its real board level."""
asserted = bool(asserted)
if asserted:
window = self._windows[self.transfer.first_strobe]
self._download_destination = window[0] | (window[1] << 8)
if asserted and not self._reset_asserted:
self.float_runtime_bus()
self.core.reset()
self._configure_frame_interrupt()
self._loader_started = False
self.launched = False
self.active = False
self.bootstrap = bytearray()
self.bootstrap_match = None
self._reset_asserted = asserted
def _start_rom_loader(self) -> None:
if not self.boot_rom_enabled or self._loader_started:
return
# Standalone bridge users have no 80186 latch; their first transfer
# edge implies the reset release that the complete machine models.
if self._reset_asserted:
self.set_reset(False)
for _ in range(32):
if self.core.io(0x6A) == 0x0610:
break
self.core.step(1)
self.core.set_io(0x58, self._download_destination)
self.core.nmi()
for _ in range(4096):
if self.core.state()["pc"] in (0x0638, 0x0639, 0x063B):
break
self.core.step(1)
else:
raise RuntimeError("C51 ROM loader did not reach its ASIC poll")
self._loader_started = True
def _commit_rom_group(self, strobe: int) -> None:
self._start_rom_loader()
before = self.core.io_port_stats([0x56]).get("0x56", {}).get("writes", 0)
if strobe in self._windows:
window = self._windows[strobe]
for index in range(0, 8, 2):
self.core.set_io(0x58 + index // 2,
window[index] | (window[index + 1] << 8))
self.core.set_io(0x56, strobe)
for _ in range(4096):
self.core.step(1)
writes = self.core.io_port_stats([0x56]).get("0x56", {}).get("writes", 0)
if writes > before:
return
raise RuntimeError(f"C51 ROM loader did not acknowledge strobe {strobe}")
def _configure_frame_interrupt(self) -> None:
if self.boot_rom_enabled:
# 0xffff selects hardware vectoring through PMST.IPTR and the ROM.
@@ -1526,23 +1582,23 @@ class CourierDspBridge:
# The ASIC accepts the supervisor's transfer and serializes its
# destination, length and program for the DSP's mask-ROM loader.
self.checksum_submits += 1
if self.active and not self.launched and hasattr(self.core, "set_pc"):
if self.boot_rom_enabled:
payload = self.bootstrap[:self.bootstrap_target_size]
words = [int.from_bytes(payload[i:i + 2], "little")
for i in range(0, len(payload), 2)]
# One trailing word clocks the loader's final comparison.
self.core.queue_codec_boot([self.entry_word, len(words), *words, 0])
else:
self.core.set_pc(self.entry_word)
if self.boot_rom_enabled:
self._commit_rom_group(strobe)
self._configure_frame_interrupt()
self.launched = True
elif self.active and not self.launched and hasattr(self.core, "set_pc"):
self.core.set_pc(self.entry_word)
self.launched = True
return
if strobe not in self._windows:
return
window = self._windows[strobe]
if self.boot_rom_enabled:
self._commit_rom_group(strobe)
if (
strobe == self.transfer.first_strobe
and self.active
and not self.boot_rom_enabled
and bytes(window) == self.expected_bootstrap[:8]
):
# The supervisor re-enters its DSP download routine for a line
+10
View File
@@ -180,6 +180,7 @@ class NativeC5x:
lib = self.library
lib.courier_c5x_create.restype = ctypes.c_void_p
lib.courier_c5x_destroy.argtypes = [ctypes.c_void_p]
lib.courier_c5x_reset.argtypes = [ctypes.c_void_p]
lib.courier_c5x_load_program.argtypes = [
ctypes.c_void_p, ctypes.c_uint16, ctypes.POINTER(ctypes.c_uint8),
ctypes.c_size_t, ctypes.c_char_p, ctypes.c_size_t,
@@ -266,6 +267,8 @@ class NativeC5x:
lib.courier_c5x_get_data_write_count.argtypes = [ctypes.c_void_p, ctypes.c_uint16]
lib.courier_c5x_get_data_write_count.restype = ctypes.c_uint64
lib.courier_c5x_interrupt.argtypes = [ctypes.c_void_p, ctypes.c_uint]
lib.courier_c5x_nmi.argtypes = [ctypes.c_void_p]
lib.courier_c5x_nmi.restype = None
lib.courier_c5x_configure_line_frame_interrupt.argtypes = [
ctypes.c_void_p, ctypes.c_uint, ctypes.c_uint16
]
@@ -330,6 +333,10 @@ class NativeC5x:
self.library.courier_c5x_destroy(self._handle)
self._handle = None
def reset(self) -> None:
"""Assert the C5x reset input without replacing its attached memory."""
self.library.courier_c5x_reset(self.handle)
def step(self, count: int) -> None:
error = ctypes.create_string_buffer(512)
result = self.library.courier_c5x_step(self.handle, count, error, len(error))
@@ -497,6 +504,9 @@ class NativeC5x:
def interrupt(self, irq: int) -> None:
self.library.courier_c5x_interrupt(self.handle, irq)
def nmi(self) -> None:
self.library.courier_c5x_nmi(self.handle)
def configure_line_frame_interrupt(self, irq: int, vector: int) -> None:
self.library.courier_c5x_configure_line_frame_interrupt(
self.handle, irq, vector
+41 -10
View File
@@ -46,6 +46,7 @@ class ImodemDsp(ImodemMailbox):
self._pcm_partial = b''
self._realtime_origin = None
self.realtime_cycles = 0
self._loader_started = False
def close(self):
if self.core is not None:
@@ -176,20 +177,21 @@ class ImodemDsp(ImodemMailbox):
self.lanes[port] = value & 0xff
if port == 0x18:
if value & 0xff == 0xff:
self.close()
self.boot_origin = self._word(0x40)
self.boot_words = []
self._begin_boot()
self.boot_status = 0xff
self.reset_status = True
self.rx = None
self.host_pending = False
elif value in (1, 2):
base = 0x40 if value == 1 else 0x50
self.boot_words.extend(self._word(base + 4*i) for i in range(4))
self._commit_boot_group(value, base)
self.bootstrap_words += 4
self.boot_status = 3
elif value == 4:
if self.boot_origin == 0x8000 and self.boot_words and self.core is None:
self._start()
self._commit_boot_group(value, None)
self._finish_boot()
self.boot_status = 7
self.reset_status = True # completion bus, released by CPU bit-1 ACK
return
@@ -221,22 +223,51 @@ class ImodemDsp(ImodemMailbox):
def _word(self, port):
return self.lanes.get(port, 0) | (self.lanes.get(port+2, 0) << 8)
def _start(self):
def _begin_boot(self):
self.close()
rom = (Path(__file__).resolve().parent.parent /
'artifacts/dsp-onchip-rom-20mhz-8k/c5x-onchip-rom-8k.bin').read_bytes()
if sha256(rom).hexdigest() != ROM_SHA256:
raise ValueError('recovered DSP mask ROM checksum mismatch')
program = b''.join(word.to_bytes(2, 'little') for word in self.boot_words)
self.core = NativeC5x.from_program(self.boot_origin, program)
self.core.configure_host_mailbox()
self.core = NativeC5x.from_program(0, b'')
self.core.configure_rom_codec()
self.core.load_rom(rom)
self.core.set_mpmc_pin(0)
self.core.set_pc(self.boot_origin)
self.core.reset()
for _ in range(64):
self.core.step(1)
self.core.set_io(0x58, self.boot_origin)
self.core.nmi()
for _ in range(4096):
if self.core.state()['pc'] in (0x0638, 0x0639, 0x063b):
break
self.core.step(1)
else:
raise RuntimeError('C51 ROM loader did not reach its ASIC poll')
self.bootstrap_words = 0
self._loader_started = True
def _commit_boot_group(self, strobe, base):
if self.core is None or not self._loader_started:
raise RuntimeError('DSP download strobe without ASIC reset command')
before = self.core.io_port_stats([0x56])['0x56']['writes']
if base is not None:
for index in range(4):
self.core.set_io(0x58 + index, self._word(base + 4*index))
self.core.set_io(0x56, strobe)
for _ in range(4096):
self.core.step(1)
if self.core.io_port_stats([0x56])['0x56']['writes'] > before:
return
raise RuntimeError(f'C51 ROM loader did not acknowledge strobe {strobe}')
def _finish_boot(self):
self.core.configure_rom_codec(False)
self.core.configure_host_mailbox()
# The peripheral port clocks a DS0 even when its MUX is disconnected.
self.core.configure_digital_pcm(
idle_codeword=IDLE_CODEWORD, clock_hz=DIGITAL_PCM_CLOCK_HZ)
self.core.configure_line_frame_interrupt(5, 0xffff)
self.bootstrap_words = len(self.boot_words)
self._reply_writes = 0
self._pcm_cursor = 0
self._pcm_partial = b''
+1 -2
View File
@@ -2424,8 +2424,7 @@ class CourierMachine:
# resets the codec too and returns its registers to defaults.
# Nothing below models that - see docs/asic-pinout.md.
asserted = not value & DSP_RESET_BIT
if asserted and not self._dsp_in_reset:
self.dsp_bridge.float_runtime_bus()
self.dsp_bridge.set_reset(asserted)
self._dsp_in_reset = asserted
if self.uart is not None:
sent = self.uart.write(address, size, value)
+141
View File
@@ -0,0 +1,141 @@
# The 80186/C51 download architecture
Analysis of the captured 4.03 supervisor and recovered C51 mask ROM, 2026-09-14.
Addresses in the CPU listings are offsets in the supervisor's `0x8000` code
segment; addresses in the C51 listings are DSP word addresses.
## Conclusion
The 80186 does not address the DSP program SRAM and the ASIC does not need the
DSP's full program address bus. The CPU fills four-word ASIC holding windows.
Code running on the C51 reads those words through the ASIC's DSP-side register
window and writes them to program memory with `BLDP`/`BLD(P)`, maintaining the
full destination address itself.
There are two consumers of the same physical transport:
* the mask-ROM service loader at program `0610` installs or reloads the
resident image;
* the downloaded resident's loader at `811b..8138` installs call overlays.
Consequently, emulation must not publish a completed resident through the
serial receiver or publish an overlay with `load_program`. It should model the
shared ASIC holding registers, status, acknowledgements and C51 event, then let
the original CPU and DSP instructions perform the transfer.
## Reset line
The supervisor is an 80C186EB in the 80-lead QFP. CPU pin 58 is `P1.1`, whose
latch is bit 1 of `P1LTCH` at relocated peripheral-control address `ff56`.
That one net reaches C51 `RS` (pin 127) and the codec reset input:
```text
ff56 bit 1 -> P1.1 / CPU pin 58 -> C51 RS
-> codec RESET
```
The line is active low. The routine at CPU `e3aa` clears bit 1, resets the
download/status registers, delays, and sets bit 1 again. The emulator should
therefore reset and stop both modeled devices on the falling edge and start the
C51 at program `0000` on the rising edge. Recognising the first eight payload
bytes is not a substitute for this observable signal.
## Resident transfer from the CPU
The launch routine at CPU `e3aa` first writes the requested DSP destination to
ports `40` and `42`, then pulses `ff56` bit 1. After release it waits for the
far-side state and writes `02` to port `1c`.
The checksum routine at `e447` sums the 16-bit payload words and saves the
result at CPU data `0e39`.
The transfer routine at `e47b` sends eight words per outer iteration:
1. Four little-endian words go through CPU ports `40..4e`; `out 18,1` commits
the group and the CPU waits for acknowledgement bit 1.
2. Four little-endian words go through CPU ports `50..5e`; `out 18,2` commits
the group and the CPU waits for acknowledgement bit 2.
3. At the end, the saved checksum goes through `40/42`; `out 18,4` submits it
and the CPU waits for acknowledgement bit 4.
Thus ports `40..4e` and `50..5e` are two CPU-facing banks of four 16-bit
holding registers. Port `18` is their resident-download commit/status port.
## Matching mask-ROM service loader
Reset code installs the service entry in the ROM interrupt trampoline table:
```asm
0672 splk @6a, #0610
```
The routine at `0610` initializes the service state. It obtains the requested
program destination through ASIC cell `@58`, saves it as the program-memory
pointer in `@1f`, and retains it in `@7d` as the final entry address. It polls
ASIC status cell `@56`.
For status bit/group 1 it takes four words beginning at `@58` and executes a
four-word `BLDP *+` transfer. It writes `1` to `@56` to acknowledge and advances
the program pointer by four. Group 2 repeats the same operation and acknowledges
with `2`. Completion writes `4` to `@56` and branches through the entry saved in
`@7d`.
This is an exact structural match for the CPU routine: four-word banks,
statuses 1 and 2, completion 4, and a destination supplied before reset. It is
not the generic `XF`/`BIO` boot loader at `072c`.
## Overlay transfer
The overlay sender uses the same eight CPU data ports but port `1e` for its
handshake. It commits words 1-2 with value 1 and words 3-4 with value 2, then
uses value 4 as the transfer boundary.
The resident C51 routine at `811b..8138` is the receiving side. It reads the
initial program address through external ASIC cell `ff62`, reads four source
words beginning at `ff58`, calls the existing wait/handshake helper at `23f0`,
writes each word to program memory with `BLDP`, increments the destination, and
writes `0300` to `ff57` as its acknowledgement.
The resident and overlay protocols therefore differ in framing and in the C51
routine consuming the words, but not in physical architecture. Both use ASIC
holding registers and make the C51 perform the program-memory writes.
## Emulator consequence
The bridge should expose one shared ASIC download device with:
* CPU-side byte lanes `40..5e` and command/status ports `18` and `1e`;
* DSP-side registers/status at `ff57`, `ff58..ff5f` and `ff62` (with the
applicable mask-ROM direct-page aliases);
* four-word commit state and real back-pressure;
* the C51 interrupt/event associated with a committed group;
* acknowledgements generated only by the C51's writes.
For ROM-enabled boards, remove the synthesized `queue_codec_boot` table and
boot-word selection of the serial loader. For overlays, remove direct
`load_program` publication. Correct completion is the original C51 reaching
the requested program address after its own `BLDP` operations.
## I-Modem reset control
The I-Modem presents the same four-word transfer protocol to its 386EX, but
not the analog board's 80C186EB GPIO register. Its software-visible reset
transaction is `out 18,ff`: the supervisor writes the destination to `40/42`,
sends `ff` to ASIC port `18`, and subsequently uses values 1, 2 and 4 on that
port for the two four-word banks and completion. The current `ImodemDsp.write`
model already treats `18=ff` as reset, but implements it by closing the native
core and later constructing a preloaded one.
The proper model should make `18=ff` an ASIC command that asserts the C51 reset
output. Release and loader entry must follow the subsequent supervisor/ASIC
handshake, rather than recognizing destination `8000` or waiting until the
checksum. Unlike the analog board's directly measured `P1.1` net, the I-Modem
ASIC output pin and physical reset-net routing have not yet been established by
continuity, so the software command is firm while its final pin remains open.
## Remaining electrical question
The exact ASIC signal used to enter the ROM service trampoline, and its C51
interrupt identity, still need to be tied to a measured pin or captured event.
That uncertainty does not change the data path: the CPU and C51 instruction
streams independently agree on the four-word windows and 1/2/4 handshake.
+13 -1
View File
@@ -1,4 +1,16 @@
# The DSP's boot ROM has two transports, and the board uses neither
# The DSP's boot ROM has two generic boot transports
> **Superseded for the Courier CPU download path, 2026-09-14.** Complete
> comparison of the captured 80186 downloader with the ROM code identifies the
> board protocol as the separate mask-ROM service loader at `0610`, using
> four-word ASIC holding registers and `BLDP`. The same ASIC transport is used
> later by the downloaded resident's overlay loader. See
> [The 80186/C51 download architecture](c51-cpu-loader.md).
>
> The serial and `XF`/`BIO` loaders documented below are real ROM facilities,
> but neither matches the supervisor's four-word 1/2/4 protocol. In particular,
> the later inference that the ASIC writes program RAM directly while the DSP
> is held in reset is withdrawn.
> **Measured, but weaker than first stated.** The board's ASIC presents
> **`0x0083`** at DSP data `0xffff` *while the modem is running normally*, long
+7
View File
@@ -1,5 +1,12 @@
# The DSP takes four images, not one
> **Transport correction, 2026-09-14.** The overlay is consumed by the
> downloaded C51 loader at `811b..8138`, which reads the ASIC holding registers
> and performs the program-memory `BLDP` writes itself. It uses the same
> physical ASIC register bridge as the mask-ROM resident loader at `0610`.
> Direct `core.load_program` publication is an emulator shortcut, not the board
> mechanism. See [The 80186/C51 download architecture](c51-cpu-loader.md).
The supervisor downloads a resident C52 bank at boot. It can also send three
further images, and the resident bank is simply one row of the same table that
names them. This records the mechanism, the map, and what it does and does not
+10
View File
@@ -27,6 +27,11 @@ void *courier_c5x_create()
void courier_c5x_destroy(void *handle) { delete static_cast<C5xCore *>(handle); }
void courier_c5x_reset(void *handle)
{
if (handle) static_cast<C5xCore *>(handle)->reset();
}
int courier_c5x_load_program(
void *handle, uint16_t origin, const uint8_t *bytes, std::size_t byte_count,
char *error, std::size_t error_size)
@@ -262,6 +267,11 @@ void courier_c5x_interrupt(void *handle, unsigned irq)
if (handle) static_cast<C5xCore *>(handle)->interrupt(irq);
}
void courier_c5x_nmi(void *handle)
{
if (handle) static_cast<C5xCore *>(handle)->nmi();
}
void courier_c5x_configure_line_frame_interrupt(void *handle, unsigned irq, uint16_t vector)
{
if (handle) static_cast<C5xCore *>(handle)->configure_line_frame_interrupt(irq, vector);
+19 -1
View File
@@ -108,6 +108,7 @@ void C5xCore::reset()
m_step_cycles = 0;
m_io.fill(0xffff);
m_mailbox_output.fill(0);
m_asic_output.fill(0xffff);
m_io_events.clear();
m_data_events.clear();
m_data_write_counts.fill(0);
@@ -391,6 +392,8 @@ void C5xCore::set_v8_answering(bool enabled)
uint16_t C5xCore::io(uint16_t port) const { return m_io[port]; }
uint16_t C5xCore::io_output(uint16_t port) const
{
if (m_rom_codec && port >= 0x50 && port <= 0x5f)
return m_asic_output[port - 0x50];
return (m_rom_codec || m_host_mailbox) && port >= 0x5e && port <= 0x60
? m_mailbox_output[port - 0x5e] : m_io[port];
}
@@ -583,7 +586,9 @@ void C5xCore::IO_WRITE16(uint16_t port, uint16_t value)
// to invent download-ready bit 9; with NDX working the firmware then
// consumed nonexistent download words indefinitely.
m_io[port] &= uint16_t(~value);
else if ((m_rom_codec || m_host_mailbox) && port >= 0x5e && port <= 0x60)
else if (m_rom_codec && port >= 0x50 && port <= 0x5f)
m_asic_output[port - 0x50] = value;
else if (m_host_mailbox && port >= 0x5e && port <= 0x60)
// The CPU and DSP each own a holding register. A DSP reply must not
// overwrite an incoming CPU word, or vice versa.
m_mailbox_output[port - 0x5e] = value;
@@ -853,6 +858,19 @@ void C5xCore::interrupt(unsigned irq)
check_interrupts();
}
void C5xCore::nmi()
{
// The 'C51's NMI vector is the fixed slot at 0x0024. Unlike the maskable
// inputs it is accepted regardless of IMR/INTM. The Courier ASIC uses
// this entry after releasing reset; the mask ROM dispatches it through
// @6a to its resident-download service at 0x0610.
PUSH_STACK(m_pc);
m_st0.intm = 1;
save_interrupt_context();
m_pc = 0x0024;
m_idle = false;
}
void C5xCore::configure_line_frame_interrupt(unsigned irq, uint16_t vector)
{
if (irq >= 16) throw std::out_of_range("C5x line-frame interrupt number");
+4
View File
@@ -226,6 +226,7 @@ public:
uint16_t data(uint16_t address) const;
void set_data(uint16_t address, uint16_t value);
void interrupt(unsigned irq);
void nmi();
void configure_line_frame_interrupt(unsigned irq, uint16_t vector);
void configure_rom_codec(bool enabled);
void set_codec_mclk(uint32_t hz);
@@ -291,6 +292,9 @@ private:
std::array<uint16_t, 65536> m_data{};
std::array<uint16_t, 65536> m_io{};
std::array<uint16_t, 3> m_mailbox_output{};
// CPU-facing ASIC inputs and DSP-facing outputs are separate holding
// registers even where they share a C51 port number.
std::array<uint16_t, 16> m_asic_output{};
std::array<uint16_t, C5X_ROM_WORDS> m_rom{};
bool m_rom_present = false;
// PMST.MPMC is preserved by this firmware's reset code rather than