diff --git a/CLAUDE.md b/CLAUDE.md index 1fd16fe..abf050e 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -119,7 +119,9 @@ Variables: `$(error)`s, not in `PACKAGE_VARIANTS`. `HTTPS_PIN_SPKI_SHA256` = trust PIN, `M3_ALLOW_TLS12=1` offers hardened 1.2. UCI reads are unfenced (writes keep `uci_fence`); `M3_READ_FENCE=1` restores the old client - byte for byte, `M3_TRACE=1` = per-READ timing records (measurement only; + byte for byte; READs ask 1472 B over one Data More continuation, + `M3_READ_ONE_BLOCK=1` = 893 B one-block READs (the previous default); + `M3_TRACE=1` = per-READ timing records (measurement only; `rig_https_m3.py timed`). Model + mutants: `tools/check_m3_client.py`, `tools/mutate_m3_client.py` (standalone, need an m3 build); hardware: `rig_https_banner.py`, `rig_https_m3.py`. diff --git a/Makefile b/Makefile index 9499c27..d533ea3 100644 --- a/Makefile +++ b/Makefile @@ -50,10 +50,12 @@ $(error M3_ALLOW_TLS12 must be 1 (offer TLS 1.3 and hardened 1.2) or 0/unset (TL endif # M3_READ_FENCE=1: a uci_fence after every UCI register READ too, as before # (src/net/uci-m3/m3.inc, "Read pacing"): the A/B arm and the fallback. +# M3_READ_ONE_BLOCK=1: READs of one block (893 B), no Data More continuation +# (m3.inc, "READ size"): the stage-1 client, an A/B arm. # M3_TRACE=1: per-net_poll timing records, a measurement build only. -$(foreach k,M3_READ_FENCE M3_TRACE,$(if $(filter-out 0 1,$($(k))),$(error $(k) must be 1 or 0/unset))) +$(foreach k,M3_READ_FENCE M3_READ_ONE_BLOCK M3_TRACE,$(if $(filter-out 0 1,$($(k))),$(error $(k) must be 1 or 0/unset))) else -$(foreach k,M3_READ_FENCE M3_TRACE,$(if $(filter-out 0,$($(k))),$(error $(k)=$($(k)) applies only to BACKEND=uci-m3))) +$(foreach k,M3_READ_FENCE M3_READ_ONE_BLOCK M3_TRACE,$(if $(filter-out 0,$($(k))),$(error $(k)=$($(k)) applies only to BACKEND=uci-m3))) endif # X25519 is always the libs/x25519 sibling (issue #245 retired the in-tree @@ -125,6 +127,9 @@ endif ifeq ($(M3_READ_FENCE),1) CA65FLAGS += -D M3_READ_FENCE=1 endif +ifeq ($(M3_READ_ONE_BLOCK),1) +CA65FLAGS += -D M3_READ_ONE_BLOCK=1 +endif ifeq ($(M3_TRACE),1) CA65FLAGS += -D M3_TRACE=1 endif diff --git a/src/net/uci-m3/m3.inc b/src/net/uci-m3/m3.inc index 186ed6e..fe15d31 100644 --- a/src/net/uci-m3/m3.inc +++ b/src/net/uci-m3/m3.inc @@ -35,6 +35,8 @@ M3_FLAG_TLS13_ONLY = $01 ; REQUIRE_TLS13; bits 1-7 must be 0 (82) M3_HOST_MAX = 253 ; host 1..253 bytes, no $00 (S 1.1 tail grammar) M3_WRITE_MAX = 892 ; WRITE_SOCKET plaintext per command M3_READ_MAX = 893 ; one response block: 2-byte header + 893 +M3_READ_MORE = 895 ; a continuation block: payload only +M3_READ_TOTAL = 1472 ; one READ, over Data More (S:2012-2013) M3_STATUS_MAX = 40 ; every M3 status line is <= 40 B (ER-8) M3_SWEEP_HANDLES = 16 ; this firmware's handle range 0..15 (ER-9) @@ -81,6 +83,22 @@ M3_B_HTTP_IDLE = 6000 ; http_recv_body: 60 s with no byte arrived ; +8 bytes put into the ring (16-bit) ; +10 m3_poll_result ; +11 $DF1C read right after that READ's PUSH and its fence +; --- READ size (M3_READ_ONE_BLOCK) ---------------------------------------- +; A READ asks for up to M3_READ_TOTAL: the first block holds the header and +; 893 bytes, the rest comes in ONE continuation block over Data More, which +; the client data-accepts after reading the first block to its end (S:2013, +; errata ER-1 N-1 and ER-5; firmware network_target.cc start_read_reply / +; get_more_data). A continuation is taken only after a FULL block and only +; while the header still owes bytes; anything else stays a hole (ER-5). +; `M3_READ_ONE_BLOCK=1` (and M3_READ_FENCE=1, the pre-change client) asks +; for at most one block and takes every Data More as a hole, as before. +.if .defined(M3_READ_FENCE) .or .defined(M3_READ_ONE_BLOCK) +M3_READ_REQ = M3_READ_MAX +.else +M3_READ_REQ = M3_READ_TOTAL +M3_MULTI_BLOCK = 1 +.endif + M3_TR_BASE = $6000 M3_TR_REC = 12 M3_TR_CAP = ($A000 - M3_TR_BASE) / M3_TR_REC diff --git a/src/net/uci-m3/m3_cmd.s b/src/net/uci-m3/m3_cmd.s index 91d13a6..75e6c1f 100644 --- a/src/net/uci-m3/m3_cmd.s +++ b/src/net/uci-m3/m3_cmd.s @@ -54,6 +54,9 @@ .export m3_code .export m3_wedged .export m3_dl +.ifdef M3_MULTI_BLOCK +.export m3_next_block +.endif .ifdef M3_TRACE .export m3_tr_sample .export m3_tr_delta @@ -465,6 +468,35 @@ m3_accept: sta UCI_CONTROL jmp m3_settle +.ifdef M3_MULTI_BLOCK +; ============================================================================= +; m3_next_block — data-accept a Data More block (read to its end) and wait for +; the next one, up to 12 s from the accept (errata ER-1, N-1: the Nios serves +; it from its buffer). The accept drops the interface to state "01" until +; the next block is validated (command_protocol.vhd). +; Out: C=0 the next block is staged. C=1 ABORTed at the bound (net_last_error +; $89, m3_wedged if bit 2 never cleared): its bytes are lost. +; Clobbers: A, X, Y +; ============================================================================= +m3_next_block: + jsr m3_accept + lda #M3_B_TLS + ldy #M3_DL_CMD + jsr m3_dl_arm ; the accept + 12 s + lda #UCI_STAT_REPLY_VALID + jsr m3_wait_set + bcs :+ + rts ; C=0 +: lda #UCI_ERR_WAIT_TIMEOUT + sta net_last_error + lda #M3_B_POST_ABORT + jsr m3_abort_wait + sec + rts +.endif + ; m3_finish — drop the rest of the block, read the status line, accept. ; The status is read BEFORE the accept, which empties both queues. m3_finish: diff --git a/src/net/uci-m3/net.s b/src/net/uci-m3/net.s index 5432770..94c3d52 100644 --- a/src/net/uci-m3/net.s +++ b/src/net/uci-m3/net.s @@ -82,6 +82,9 @@ .import m3_status_seen .import m3_code .import m3_wedged +.ifdef M3_MULTI_BLOCK +.import m3_next_block +.endif .ifdef M3_TRACE .import m3_tr_sample .import m3_tr_delta @@ -708,14 +711,19 @@ m3_status_number: ; ============================================================================= ; net_poll — one READ into the rx ring. ; -; Request min(ring free - 1, 893): one response block, no Data More (S 1.5). +; Request min(ring free - 1, M3_READ_REQ): 1472 over a first block and one +; Data More continuation, or 893 and one block under M3_READ_ONE_BLOCK / +; M3_READ_FENCE (m3.inc, "READ size"; S 1.5, S:2013). ; Then, by header and status (S 1.6, Appendix A, ER-5/7/12): ; no header (bit 7 clear) an empty reply (81/82): a READ of ours that ; the firmware refused. ERROR, still owned. ; n > 0 data into the ring. A block that is not read -; to its end (short, over-long, Data More) -; leaves a hole in the stream: ERROR, owned, -; so the CLOSE that follows is sent (ER-5). +; to its end, a short one, an over-long one, or +; a Data More the header does not owe, leaves a +; hole in the stream: ERROR, owned, so the CLOSE +; that follows is sent (ER-5). A continuation +; that does not come within 12 s of its accept +; is ABORTed: $89, ERROR, owned. ; $FFFF + 02,..: 11 nothing yet (M3_POLL_IDLE). ; $FFFF + anything else the number is not ours ("02,NO DATA: 9", ER-7): ; stop, and do NOT CLOSE it. ERROR, not owned. @@ -773,13 +781,13 @@ net_poll: rts : lda m3_req - cmp #M3_READ_MAX ; C=1 iff req >= MAX + sbc #>M3_READ_REQ ; C=1 iff req >= MAX bcc :+ - lda #M3_READ_MAX + lda #>M3_READ_REQ sta m3_req+1 : lda #M3_POLL_END @@ -908,6 +916,16 @@ net_poll: lda tcp_recv_tail+1 adc #>tcp_recv_buf sta @p_store+2 +.ifdef M3_MULTI_BLOCK + lda tcp_recv_tail+0 ; where this READ's bytes start + sta m3_cp0 + lda tcp_recv_tail+1 + sta m3_cp0+1 + lda #M3_READ_MAX + sta m3_blk_end+1 +.endif @p_copy: lda UCI_STATUS ; ER-12: DATA_AV before EVERY byte, or a bpl @p_short ; short block reads as $00s (bit 7) @@ -929,6 +947,38 @@ net_poll: bne @p_copy beq @p_tail ; always @p_short: +.ifdef M3_MULTI_BLOCK + ; A = $DF1C, bit 7 clear: this block is read to its end and the + ; header still owes bytes. Take the continuation only on Data More + ; ("11") after a FULL block; anything else is a hole (ER-5). + and #UCI_STAT_STATE + cmp #UCI_STAT_STATE + bne @p_hole + stx m3_left + sty m3_left+1 + lda @p_store+1 ; bytes so far = store - start, mod ring + sec + sbc m3_cp0 + sta m3_got + lda @p_store+2 ; (>tcp_recv_buf is 0 under the mask) + sbc m3_cp0+1 + and #>TCP_RECV_MASK + cmp m3_blk_end+1 + bne @p_hole + lda m3_got + cmp m3_blk_end + bne @p_hole + jsr m3_next_block ; data-accept, <= 12 s from it (ER-1) + bcc :+ + jmp @p_dead_owned ; ABORTed: $89, the bytes are lost +: ldx m3_left ; m3_blk_end stays 893: a second + ldy m3_left+1 ; Data More never matches it (ER-5) + jmp @p_copy +@p_hole: +.assert (>tcp_recv_buf & >TCP_RECV_MASK) = 0, error, "@p_short drops >tcp_recv_buf by masking" +.assert M3_READ_TOTAL <= M3_READ_MAX + M3_READ_MORE, error, "a READ is at most two blocks" +.assert M3_READ_TOTAL <= TCP_RECV_MASK, error, "bytes so far are counted mod the ring" +.endif lda #UCI_ERR_SHORT_READ ; short of its header: a hole (ER-5) sta m3_bad @p_tail: @@ -1364,6 +1414,12 @@ m3_rem: .res 2 m3_piece: .res 2 m3_cnt: .res 2 m3_wresp: .res 2 +.ifdef M3_MULTI_BLOCK +m3_cp0: .res 2 ; ring tail where this READ's bytes start +m3_blk_end: .res 2 ; bytes in the READ when block 1 is full +m3_left: .res 2 ; the copy's X/Y over a continuation +m3_got: .res 1 +.endif .ifdef M3_TRACE m3_tr_zero: ; net_init zeroes these m3_tr_count: .res 2 ; CONNECTED net_poll calls since net_init diff --git a/tools/check_m3_client.py b/tools/check_m3_client.py index 3d5199d..5681884 100644 --- a/tools/check_m3_client.py +++ b/tools/check_m3_client.py @@ -115,6 +115,17 @@ class Unavailable(Exception): pass +def _read_blocks(payload): + """A READ reply as the firmware blocks it (network_target.cc + start_read_reply / get_more_data @3a1ff9ff): the header and up to 893 + bytes, then continuation blocks of up to 895 bytes, payload only.""" + n = len(payload) + blocks = [bytes([n & 0xFF, n >> 8]) + payload[:893]] + for i in range(893, n, 895): + blocks.append(payload[i:i + 895]) + return blocks + + class M3Device: """$DF1B-$DF1F + an M3 Nios, driven by the CPU's reads and writes.""" @@ -151,6 +162,8 @@ def __init__(self, clock): self.next_handle = 5 self.release_delays = [] # per-`03 25` delays, then FAST self.abort_never = False # an ABORT that is never serviced + self.more_delay = 0 # units from a Data More accept to the + self.more_due = None # next block (inf: it never comes) # observation self.log = [] # (units, command bytes) self.ctrl_writes = [] # (units, value) @@ -166,6 +179,9 @@ def __init__(self, clock): # ---------------------------------------------------------------- time -- def _advance(self): now = self.clock() + if self.more_due is not None and now >= self.more_due: + self.more_due = None + self._load_block() if self.done_at is not None and now >= self.done_at: self.done_at = None blocks, status = self.pending @@ -206,8 +222,8 @@ def read(self, addr): if self.state & 2: if self.rp < len(self.response): bits |= DATA_AV - if self.sp < len(self.status): - bits |= STAT_AV + if self.sp < len(self.status) and self.state == ST_LAST: + bits |= STAT_AV # the status rides the LAST block if self.error_busy: bits |= ERROR_BIT if self.abort_pending: @@ -223,7 +239,7 @@ def read(self, addr): self.rp += 1 return self.response[self.rp - 1] if addr == 0xDF1F: - if not self.state & 2 or self.sp >= len(self.status): + if self.state != ST_LAST or self.sp >= len(self.status): return 0x00 self.sp += 1 return self.status[self.sp - 1] @@ -256,7 +272,13 @@ def write(self, addr, value): self.accepts += 1 if self.state == ST_MORE: self.accepts_on_more += 1 - self._load_block() + if self.more_delay: # "01" until the Nios validates + self.state = ST_BUSY + self.response = b"" + self.rp = 0 + self.more_due = now + self.more_delay + else: + self._load_block() else: self.state = ST_IDLE self.response = self.status = b"" @@ -402,7 +424,7 @@ def _execute(self, cmd, now): s["rx"][0] = ("data", rest) else: s["rx"].pop(0) - return [bytes([len(chunk) & 0xFF, len(chunk) >> 8]) + chunk], OK, d + return _read_blocks(chunk), OK, d if ev[0] == "idle": s["rx"].pop(0) return [b"\xff\xff"], IDLE, d @@ -568,6 +590,19 @@ def _refuse_trace(labels=None): "without M3_TRACE" % stamp) +def _one_block(labels=None): + """True when READs ask for one block (893 B): M3_READ_ONE_BLOCK=1 or + M3_READ_FENCE=1 (m3.inc, "READ size"). Else 1472 over Data More.""" + stamp = Path(labels or LABELS).parent / "flags.stamp" + if not stamp.is_file(): + raise Unavailable("%s is missing: cannot tell the READ size" % stamp) + for line in stamp.read_text().splitlines(): + if line.startswith("CA65FLAGS="): + return ("-D M3_READ_ONE_BLOCK" in line + or "-D M3_READ_FENCE" in line) + raise Unavailable("%s has no CA65FLAGS line" % stamp) + + def _fence_sbc(): """SBC #1 executions in one uci_fence (OUTER x INNER, uci_regs.inc).""" text = (REPO / "src" / "net" / "uci" / "uci_regs.inc").read_text() @@ -997,7 +1032,7 @@ def _http_fetch(m, response_events): def test_http_content_length_end_to_end(prg=None, labels=None): """The whole path: OPEN, GET, a 2,000 B Content-Length body over several - READs (each at most 893 B), C=0, then CLOSE.""" + READs (each at most 1472 B, or 893 on a one-block image), C=0, CLOSE.""" m = _connected(Machine(prg, labels)) body = bytes((i * 7) & 0x7F | 0x20 for i in range(2000)) resp = b"HTTP/1.1 200 OK\r\nContent-Length: 2000\r\n\r\n" + body @@ -1008,8 +1043,9 @@ def test_http_content_length_end_to_end(prg=None, labels=None): _check(status == 200, "http_status %d" % status) _check(total == 2000, "http_body_total %d, expected 2000" % total) reads = [c for c in m.dev.commands() if c[1] == 0x10] - _check(all((c[3] | c[4] << 8) <= 893 for c in reads), - "a READ asked for more than 893 B (one block, S 1.5)") + cap = 893 if _one_block(labels) else 1472 + _check(all((c[3] | c[4] << 8) <= cap for c in reads), + "a READ asked for more than %d B (S 1.5, S:2012)" % cap) m.call("net_tcp_close") m.no_violations() @@ -1212,7 +1248,7 @@ def test_block_tail_is_dead(prg=None, labels=None): def test_overclaimed_header_is_dead(prg=None, labels=None): """ER-5: a header over the request (not $FFFF): the excess is dropped.""" - _block_case([bytes([0x00, 0x04]) + bytes(1024)], "over-claimed header")(prg, labels) + _block_case([bytes([0x00, 0x06]) + bytes(1536)], "over-claimed header")(prg, labels) def test_rejected_push_is_not_a_reply(prg=None, labels=None): @@ -1569,12 +1605,139 @@ def _pacing_flows(prg, labels): return traces +def _multi_case(prg, labels, payload, more_delay=0): + m = _connected(Machine(prg, labels)) + m.dev.more_delay = more_delay + m.dev.sessions[5]["rx"] = [("data", payload)] + m.call("net_poll", budget=80_000_000) + return m + + +def test_read_continues_over_data_more(prg=None, labels=None): + """S:2012-2013, errata ER-1 N-1: a READ asks for up to 1472 B; a reply + over 893 B comes as the first block plus a Data More continuation, which + the client data-accepts once the first block is read to its end, then + reads to the end, then the status line. On a one-block image (893 B, + M3_READ_ONE_BLOCK / M3_READ_FENCE) no READ asks for a continuation.""" + payload = bytes((i * 29 + 3) & 0xFF for i in range(1472)) + m = _multi_case(prg, labels, payload, more_delay=SECOND // 2) + reads = [c for c in m.dev.commands() if c[1] == 0x10] + asked = reads[-1][3] | reads[-1][4] << 8 + _check(m.peek("net_tcp_state") == NET_TCP_CONNECTED, + "the READ ended the connection (net_last_error $%02X)" + % m.peek("net_last_error")) + if _one_block(labels): + _check(asked == 893, "a one-block image asked for %d B" % asked) + _check(m.dev.accepts_on_more == 0, "a one-block image data-accepted " + "a Data More block") + _check(m.ring() == payload[:893], "the ring does not hold the block") + else: + _check(asked == 1472, "the READ asked for %d B, expected 1472" % asked) + _check(m.dev.accepts_on_more == 1, "%d Data More accepts, expected 1" + % m.dev.accepts_on_more) + _check(m.ring() == payload, "the ring does not hold both blocks, in " + "order (%d B of 1472)" % len(m.ring())) + _check(m.peek("m3_poll_result") == 0, "m3_poll_result is not DATA") + m.no_violations() + + +def _continuation_dead(prg, labels, blocks, note, want): + m = _connected(Machine(prg, labels)) + m.dev.more_delay = FAST + m.dev.forced_blocks = (blocks, OK) + m.call("net_poll", budget=80_000_000) + _check(m.peek("net_tcp_state") == NET_TCP_ERROR, "%s: net_tcp_state $%02X, " + "expected ERROR (ER-5)" % (note, m.peek("net_tcp_state"))) + _code(m, want, note) + m.call("net_tcp_close") + _check(m.dev.commands()[-1] == b"\x03\x09\x05", + "%s: the handle was not CLOSEd" % note) + m.no_violations() + return m + + +def test_continuation_after_short_block_is_a_hole(prg=None, labels=None): + """ER-5: the first block ends before 893 B with Data More behind it. + The firmware never sends that; taking the continuation would join the + stream over a hole. No accept on the Data More block.""" + if _one_block(labels): + return + m = _continuation_dead(prg, labels, [bytes([0xD0, 0x03]) + bytes(500), + bytes(476)], "short first block", + ERR_SHORT_READ) + _check(m.dev.accepts_on_more == 0, "a short block's Data More was accepted") + + +def test_short_continuation_is_a_hole(prg=None, labels=None): + """ER-5: header 1000, the continuation (the LAST block) holds 50 of the + 107 bytes still owed: short.""" + if _one_block(labels): + return + _continuation_dead(prg, labels, [bytes([0xE8, 0x03]) + bytes(893), + bytes(50)], "short continuation", + ERR_SHORT_READ) + + +def test_long_continuation_is_a_hole(prg=None, labels=None): + """ER-5: header 900, the continuation holds 10 bytes, not 7: the bytes + past the header are dropped and flagged.""" + if _one_block(labels): + return + _continuation_dead(prg, labels, [bytes([0x84, 0x03]) + bytes(893), + bytes(10)], "over-long continuation", + ERR_BAD_READ_HDR) + + +def test_unowed_continuation_is_a_hole(prg=None, labels=None): + """ER-5: header 1000, but a third block follows the continuation (Data + More again once the header is paid): never accepted, ABORT.""" + if _one_block(labels): + return + m = _continuation_dead(prg, labels, [bytes([0xE8, 0x03]) + bytes(893), + bytes(107), bytes(20)], + "a continuation the header does not owe", + ERR_BAD_READ_HDR) + _check(m.dev.accepts_on_more == 1, "%d Data More accepts, expected only " + "the one the header owed" % m.dev.accepts_on_more) + m = _continuation_dead(prg, labels, [bytes([0xE8, 0x03]) + bytes(893), + bytes(50), bytes(57)], + "a second continuation after a short one", + ERR_SHORT_READ) + _check(m.dev.accepts_on_more == 1, "a second Data More was accepted") + + +def test_continuation_timeout_aborts(prg=None, labels=None): + """Errata ER-1 N-1: a continuation that does not come within 12 s of the + accept is ABORTed; its bytes are lost, so ERROR, owned, CLOSE, $89. And + not before: one that comes at 11 s is taken.""" + if _one_block(labels): + return + payload = bytes(range(256)) * 3 + bytes(232) # 1000 B + m = _multi_case(prg, labels, payload, more_delay=11 * SECOND) + _check(m.peek("net_tcp_state") == NET_TCP_CONNECTED and m.ring() == payload, + "a continuation at accept + 11 s was not taken (net_last_error $%02X)" + % m.peek("net_last_error")) + m.no_violations() + m = _connected(Machine(prg, labels)) + m.dev.more_delay = float("inf") + m.dev.sessions[5]["rx"] = [("data", payload)] + m.call("net_poll", budget=80_000_000) + _check(m.peek("net_tcp_state") == NET_TCP_ERROR, "net_tcp_state $%02X " + "after a continuation that never came" % m.peek("net_tcp_state")) + _code(m, ERR_WAIT_TIMEOUT, "a continuation that never came") + _check(m.dev.aborts >= 1, "no ABORT for a continuation that never came") + m.call("net_tcp_close") + _check(m.dev.commands()[-1] == b"\x03\x09\x05", "the handle was not " + "CLOSEd after a lost continuation") + m.no_violations() + #: Default image: the most instructions that may run between a READ of #: this register and the next UCI access, on the traced flows. Measured -#: maxima at 4464886: $DF1C 49, $DF1D 10, $DF1E 35, $DF1F 7. A delay of -#: any shape (a fence, a NOP sled, a loop) past these is caught; one that -#: fits under them is not -- that is the detector's resolution. -READ_GAP_BUDGET = {0xDF1C: 64, 0xDF1D: 16, 0xDF1E: 40, 0xDF1F: 16} +#: maxima at 4464886: $DF1C 49, $DF1D 10, $DF1E 35, $DF1F 7; the 1472 B +#: READ image adds 8 to $DF1E (43: the continuation set-up before the copy +#: loop). A delay of any shape (a fence, a NOP sled, a loop) past these is +#: caught; one that fits under them is not -- the detector's resolution. +READ_GAP_BUDGET = {0xDF1C: 64, 0xDF1D: 16, 0xDF1E: 48, 0xDF1F: 16} def test_read_pacing(prg=None, labels=None): @@ -1788,6 +1951,12 @@ def test_ring_wraps_in_one_block(prg=None, labels=None): test_read_pacing, test_ring_wraps_in_one_block, test_copy_counts_at_page_edges, + test_read_continues_over_data_more, + test_continuation_after_short_block_is_a_hole, + test_short_continuation_is_a_hole, + test_long_continuation_is_a_hole, + test_unowed_continuation_is_a_hole, + test_continuation_timeout_aborts, ) # Need `make BACKEND=uci-m3 HTTPS_BODY_TO_REU=1` (flags.stamp says so); main diff --git a/tools/mutate_m3_client.py b/tools/mutate_m3_client.py index 9ffc660..8847ba8 100644 --- a/tools/mutate_m3_client.py +++ b/tools/mutate_m3_client.py @@ -113,7 +113,7 @@ ("write-max-1024", "S 1.5 WRITE <= 892 B", INC, "M3_WRITE_MAX = 892", "M3_WRITE_MAX = 1024", ["test_long_write_is_split_at_892"]), - ("read-max-1472", "S 1.5 one block: READ <= 893 B", INC, + ("read-max-1472", "S 1.5 a first block holds 893 B", INC, "M3_READ_MAX = 893", "M3_READ_MAX = 1472", ["test_http_content_length_end_to_end"]), ("05-unframed-trusted", "S 1.6 05: trust only framed data", HTTP, @@ -322,6 +322,26 @@ " lda UCI_STATUS_DATA\n.ifdef M3_READ_FENCE\n jsr m3_settle\n.endif\n", " lda UCI_STATUS_DATA\n.repeat 40\n nop\n.endrep\n", ["test_read_pacing"]), + # READs of 1472 B over a Data More continuation (m3.inc, "READ size") + ("more-never-taken", "S:2013 a READ continues over Data More", NET, + " and #UCI_STAT_STATE\n cmp #UCI_STAT_STATE\n bne @p_hole\n", + " jmp @p_hole\n", ["test_read_continues_over_data_more"]), + ("more-after-short-block", "ER-5 a continuation only after a FULL block", NET, + " cmp m3_blk_end+1\n bne @p_hole\n lda m3_got\n cmp m3_blk_end\n bne @p_hole\n", + "", ["test_continuation_after_short_block_is_a_hole"]), + ("more-no-wait", "wait for the continuation to be validated", CMD, + " lda #UCI_STAT_REPLY_VALID\n jsr m3_wait_set\n bcs :+\n rts ; C=0\n:", + " clc\n rts\n:", ["test_read_continues_over_data_more"]), + ("more-bound-short", "ER-1 N-1: 12 s from the accept", CMD, + " jsr m3_accept\n lda #M3_B_TLS", + " jsr m3_accept\n lda #10\n ldx #0", + ["test_continuation_timeout_aborts"]), + ("more-lost-not-89", "a lost continuation is $89 + CLOSE", NET, + " jmp @p_dead_owned ; ABORTed: $89, the bytes are lost", + " jmp @p_hole", ["test_continuation_timeout_aborts"]), + ("request-893", "READs ask for 1472 B (S:2012)", INC, + "M3_READ_REQ = M3_READ_TOTAL", "M3_READ_REQ = M3_READ_MAX", + ["test_read_continues_over_data_more"]), ] @@ -341,7 +361,7 @@ def _stamp(): # and the rules here are the plain image's. raise SystemExit("build/ is an HTTPS_BODY_TO_REU image: the mutants " "are written against plain `make BACKEND=uci-m3`") - for knob in ("M3_READ_FENCE", "M3_TRACE"): + for knob in ("M3_READ_FENCE", "M3_READ_ONE_BLOCK", "M3_TRACE"): # The pacing mutants target the default image's code; the fenced # copy loop is not assembled there, and the trace moves timings. if "-D " + knob in vals.get("CA65FLAGS", ""): diff --git a/tools/package/build_m3_demo.sh b/tools/package/build_m3_demo.sh index 1ad22d1..0fd6242 100755 --- a/tools/package/build_m3_demo.sh +++ b/tools/package/build_m3_demo.sh @@ -201,7 +201,7 @@ mounted on drive 8 and loaded with LOAD"*",8,1 (tools/uci/rig_https_m3_demo.py), 2026-10-13: 1. HTTP 200, 751,823 B consumed == Content-Length, 18 s from G to CONNECTION CLOSED (the page size changes as the article is edited). - 2. HTTP 200, 16,739 B consumed == Content-Length, 4 s. + 2. HTTP 200, 16,739 B consumed == Content-Length, 5 s. 3. Refused: 94,CERTIFICATE NAME MISMATCH: 0x00000004. Other Ultimate models, and other clock speeds, have not been tested. diff --git a/tools/uci/rig_https_m3.py b/tools/uci/rig_https_m3.py index a034c08..e8077ae 100644 --- a/tools/uci/rig_https_m3.py +++ b/tools/uci/rig_https_m3.py @@ -534,6 +534,17 @@ def timed_attempt(client, name, bdir: Path, page: str, run_dir: Path) -> dict: rec["http_status"] = le(client, lab["http_status"], 2) rec["body_total"] = le(client, lab["http_body_total"], 3) rec["net_last_error"] = f"${bytes(client.read_mem(lab['net_last_error'], 1))[0]:02X}" + # The client's own framing facts (tools/http_body_checks.py), so a + # short body says whether the client or the server ended it. + from http_body_checks import SYMBOLS, check_body_complete, decode_body_state + state = decode_body_state({n: bytes(client.read_mem(lab[n], w)) + for n, w in SYMBOLS.items()}) + rec["framing"] = {"chunked": state.chunked, "cl_valid": state.cl_valid, + "content_length": state.content_length, + "chunk_state": state.chunk_state, + "parse_state": state.parse_state, + "client_verdict": str(check_body_complete(state)), + "m3_eof_code": bytes(client.read_mem(lab["m3_eof_code"], 1))[0]} tr = read_trace(client, lab) if tr is not None: (run_dir / f"trace-{name}-{page}-{rec['start']}.json").write_text(json.dumps(tr))