Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -813,13 +813,18 @@ UCI (`cfg/c64-https-uci.cfg`, W1 hot/cold split — the reference):
$0801-$1FFF LOADER BASIC stub + boot + HTTP + net wrapper
$2000-$3B65 NET_CODE UCI adapter + LOADER_OVERFLOW + TLS_CODE
+ CRYPTO_AUX_CODE
$3B66-$41FF NET_BSS_TAIL NET_BSS_TAIL segment (deframer/viewer BSS)
+ LIB_NISTCURVES_P256_BSS. NOT `BSS_TAIL`
and NOT `UCI_BSS` — both are elsewhere
(below, and CRYPTO_HOT). Read the map.
$3B66-$41FF NET_BSS_TAIL NET_BSS_TAIL segment (deframer/viewer BSS),
then free. NOT `BSS_TAIL` and NOT `UCI_BSS`
— both are elsewhere (below, and
CRYPTO_HOT). Read the map.
$4200-$5FFF CRYPTO_OVERLAY 7.5 KB. Resident tenants in every UCI
build: TLS_DEFRAME_CODE (~1.4 KB),
CERT_BUF_BSS (2,048 B), HTTPS_TARGET_RODATA,
CERT_BUF_BSS (2,048 B, pinned at $4200;
LIB_NISTCURVES_P256_BSS shares it —
P256_SCRATCH_UNION, #68's ip65 rule; so
nothing may read cert_buf after
CertificateVerify or run from it and
call ecdsa_verify), HTTPS_TARGET_RODATA,
x509_name; comb adds RODATA/LIMLEE_BSS
(small tail — the rigs' scratch). Also
the slot for the (broken) overlay-embed
Expand Down
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,13 @@ $(error COLD_BANK must be 1 (default on comb: cold code in the REU) or 0 (reside
endif
ifeq ($(USE_NISTCURVES_ONCHIP_COMB),1)
ifneq ($(COLD_BANK),0)
# The cold bank runs trust_bundle FROM cert_buf, and trust_bundle calls
# ecdsa_verify, whose scratch (LIB_NISTCURVES_P256_BSS) is unioned onto
# cert_buf on every UCI cfg (P256_SCRATCH_UNION): the verify would overwrite
# the code running it. src/net/uci/trust_bundle.s asserts the same at link.
ifeq ($(TRUST_BUNDLE),1)
$(error TRUST_BUNDLE=1 cannot link on comb: the cold bank runs trust_bundle from cert_buf, which ecdsa_verify's scratch shares (P256_SCRATCH_UNION). Build the bundle on uci-onchip)
endif
CA65FLAGS += -D COLD_BANK=1
CFG := cfg/c64-https-$(BACKEND)-onchip-cold.cfg
UCI_SRCS += src/net/uci/cold_bank.s
Expand Down
76 changes: 46 additions & 30 deletions cfg/c64-https-uci-onchip-cold.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
# cfg/c64-https-uci-onchip.cfg instead, byte-identical to the image before
# the bank existed. This file is that one plus the cold bank, and
# tools/test_cold_bank.py fails if they differ by anything else:
# * CERT_BUF_BSS is pinned at the head of CRYPTO_OVERLAY ($4200), and
# each COLD_RUN_<group> area overlays it: the cold groups are LINKED to
# run there, one at a time.
# * each COLD_RUN_<group> area overlays cert_buf, which both cfgs pin
# at the head of CRYPTO_OVERLAY ($4200): the cold groups are LINKED to
# run there, one at a time. (P256_SCRATCH_UNION sits there too; a cold
# group never calls ecdsa_verify — the Makefile refuses TRUST_BUNDLE=1
# here, and src/net/uci/trust_bundle.s asserts it.)
# * COLD_IMAGE ($C000-$CFFF, the head of the old OVERLAY_FILE_PAD) is
# where the PRG carries them, back to back; boot stashes it into the
# REU before anything touches the TCP ring that shares the range.
Expand Down Expand Up @@ -63,8 +65,10 @@
# TLS_CODE + CRYPTO_AUX_CODE)
# $3B66-$41FF : NET_BSS_TAIL (BSS spill-over reclaimed from the
# NET_CODE tail — the NET_BSS_TAIL
# segment, i.e. deframer + viewer BSS,
# plus LIB_NISTCURVES_P256_BSS. NOT
# segment, i.e. deframer + viewer BSS.
# LIB_NISTCURVES_P256_BSS is NOT here:
# it shares cert_buf, see
# P256_SCRATCH_UNION. NOT
# UCI_BSS, which is in CRYPTO_HOT, and
# NOT BSS_TAIL, which is in
# CRYPTO_COLD_SHADOW)
Expand Down Expand Up @@ -125,11 +129,10 @@
# in CRYPTO_HOT); that move is the whole
# point of this file — see the header at
# the top and the routing line below.
# LIB_NISTCURVES_P256_BSS - data_p256 working buffers. NET_BSS_TAIL
# (NOT CRYPTO_HOT — see the routing line
# near the bottom of this file and the
# measured table at the MEMORY block;
# it links at $3CB5-$41D4).
# LIB_NISTCURVES_P256_BSS - data_p256 working buffers. On cert_buf
# (P256_SCRATCH_UNION, MEMORY block): the
# two lifetimes are disjoint — see the
# routing line near the bottom of this file.
# LIB_NISTCURVES_P256_LIMLEE_BSS - comb precompute table. CRYPTO_OVERLAY,
# per the variant header at the top of
# this file.
Expand Down Expand Up @@ -168,8 +171,9 @@ MEMORY {
# that region was collapsed to the zero-size alias below and its 512 B
# handed to NET_BSS_TAIL, of which only ~$125 had ever been used.
#
# It holds the NET_BSS_TAIL segment (deframer + viewer BSS), the
# sibling's LIB_NISTCURVES_P256_BSS, and the stub UCI_BSS_REGION.
# It holds the NET_BSS_TAIL segment (deframer + viewer BSS) and the
# stub UCI_BSS_REGION. The sibling's LIB_NISTCURVES_P256_BSS used to
# pack here too; it now shares cert_buf (P256_SCRATCH_UNION, below).
# It does **NOT** hold UCI_BSS. UCI_BSS is routed to CRYPTO_HOT by the
# SEGMENTS block below, and both shipped UCI products link it there
# (measured 2026-08-31, build/c64-https.map). The header map at the top
Expand All @@ -183,6 +187,15 @@ MEMORY {
# `define = yes` emits __UCI_BSS_REGION_START__ etc.).
UCI_BSS_REGION: start = $4000, size = $0000, type = rw, define = yes;
CRYPTO_OVERLAY: start = $4200, size = $1E00, file = %O, define = yes, fill = yes, fillval = $00;
# P256_SCRATCH_UNION: LIB_NISTCURVES_P256_BSS (verify scratch) on top
# of cert_buf, which is pinned at the head of CRYPTO_OVERLAY — the UCI
# twin of cfg/c64-https-ip65.cfg's SCRATCH_UNION (#68). Disjoint
# lifetimes: the LIFETIME CONTRACT at CERT_BUF_BSS in src/der_decode.s.
# The size is CERT_BUF_SIZE (src/net/uci/net_tuning.inc), so P-256 BSS
# growth past cert_buf is a link error, not a silent overlap with the
# next CRYPTO_OVERLAY tenant; src/der_decode.s asserts start and size.
# Not file-backed: the bytes are cert_buf's.
P256_SCRATCH_UNION: start = $4200, size = $0800, type = rw, define = yes;

# W1 HOT/COLD SPLIT (Worker I — root-cause fix for the
# boot zero-fill regression):
Expand Down Expand Up @@ -290,8 +303,9 @@ SEGMENTS {
HTTP_AUX_CODE: load = LOADER, type = ro, optional = yes;
# x25_basepoint + fe_p (libs/x25519, #245). Ahead of RODATA so its
# 32-byte alignment lands on the region start and costs no fill.
# Cold bank: cert_buf first, at a fixed address, so the COLD_RUN_*
# areas can sit on it (src/net/uci/cold_bank.s asserts they do).
# cert_buf first, at a fixed address, so the areas that time-share it
# can sit on it: P256_SCRATCH_UNION (src/der_decode.s asserts it does)
# and, on the cold cfg, the COLD_RUN_* areas (src/net/uci/cold_bank.s).
CERT_BUF_BSS: load = CRYPTO_OVERLAY, type = bss, start = $4200;
X25519_RODATA: load = CRYPTO_OVERLAY, type = ro, align = $20;
RODATA: load = CRYPTO_OVERLAY, type = ro; # onchip-comb variant: relieve CRYPTO_HOT
Expand Down Expand Up @@ -348,11 +362,10 @@ SEGMENTS {
# one the MEMORY block's NET_BSS_TAIL comment defers to.
UCI_BSS: load = CRYPTO_HOT, type = bss, optional = yes;
# NET_BSS_TAIL is the spill-over BSS region carved from the
# NET_CODE tail, and it is NOT free: LIB_NISTCURVES_P256_BSS is
# routed here (see the segment near the bottom of this file), and
# the NET_BSS_TAIL segment itself carries the deframer + viewer
# BSS, with LIB_NISTCURVES_P256_BSS packed after it; the tail
# left over is small. The harness must take scratch addresses
# NET_CODE tail. The NET_BSS_TAIL segment carries the deframer +
# viewer BSS; LIB_NISTCURVES_P256_BSS no longer packs after it (it
# shares cert_buf, see the segment near the bottom of this file),
# so most of the region is free. The harness must take scratch addresses
# from tools/uci/_memory_policy.py, which parses build/labels.txt,
# not from any figure written here.
NET_BSS_TAIL: load = NET_BSS_TAIL, type = bss, optional = yes;
Expand Down Expand Up @@ -395,7 +408,7 @@ SEGMENTS {
# A runtime overlay swap-in would now clobber the staged leaf
# certificate mid-handshake (live data, not just code) — the
# embed-flag exclusion is a data-integrity constraint here.
# (cold bank: CERT_BUF_BSS is pinned at the head of the region, above)
# (CERT_BUF_BSS is pinned at the head of the region, above)


# Lane G stretch goal: REU-backed text viewer (src/viewer.s). This
Expand Down Expand Up @@ -477,16 +490,19 @@ SEGMENTS {
# link time.
LIB_NISTCURVES_P256_CODE: load = CRYPTO_HOT, type = ro, optional = yes;
LIB_NISTCURVES_P256_RODATA: load = CRYPTO_OVERLAY, type = ro, optional = yes; # onchip-comb variant
# P-256 BSS is 1,312 B (fp256/mod256/points256 scratch + ecdsa256
# input/output staging + data_p256 working buffers). Stays in
# NET_BSS_TAIL under the W1 hot/cold split — CRYPTO_COLD_SHADOW
# is full carrying the in-tree BSS chunks (BSS / CRYPTO_BSS /
# TABLES_BSS / BSS_TAIL = ~8.1 KB out of the 8 KB budget once
# TABLES_BSS page-alignment is accounted for). It packs after the
# NET_BSS_TAIL segment. Do not size harness scratch from it;
# tools/uci/_memory_policy.py reads
# build/labels.txt.
LIB_NISTCURVES_P256_BSS: load = NET_BSS_TAIL, type = bss, optional = yes;
# P-256 BSS (fp256/mod256/points256 scratch + ecdsa256 input/output
# staging + data_p256 working buffers) is per-call verify scratch, so
# it time-shares cert_buf exactly as ip65's SCRATCH_UNION does (#68):
# cert_buf is dead once x509_extract_pubkey returns (the pubkey, SAN
# check and SPKI pin all run inside it), and ecdsa_verify runs only
# after that. Two things would break the union: code RUNNING from
# cert_buf that calls ecdsa_verify (TRUST_BUNDLE=1 on the comb cold
# bank; refused by a Makefile $(error) and an lderror in
# src/net/uci/trust_bundle.s), and anything that re-reads cert_buf
# after CertificateVerify (the LIFETIME CONTRACT in src/der_decode.s).
# Do not size harness scratch from it; tools/uci/_memory_policy.py
# reads build/labels.txt.
LIB_NISTCURVES_P256_BSS: load = P256_SCRATCH_UNION, type = bss, optional = yes;
# Comb profile: Lim-Lee anchors + working k (data_p256_limlee.o).
# CRYPTO_COLD_SHADOW is flush-full (sqtab ends at $BFFF), so this
# rides in the file-backed CRYPTO_OVERLAY with the other variant
Expand Down
67 changes: 42 additions & 25 deletions cfg/c64-https-uci-onchip.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@
# TLS_CODE + CRYPTO_AUX_CODE)
# $3B66-$41FF : NET_BSS_TAIL (BSS spill-over reclaimed from the
# NET_CODE tail — the NET_BSS_TAIL
# segment, i.e. deframer + viewer BSS,
# plus LIB_NISTCURVES_P256_BSS. NOT
# segment, i.e. deframer + viewer BSS.
# LIB_NISTCURVES_P256_BSS is NOT here:
# it shares cert_buf, see
# P256_SCRATCH_UNION. NOT
# UCI_BSS, which is in CRYPTO_HOT, and
# NOT BSS_TAIL, which is in
# CRYPTO_COLD_SHADOW)
Expand Down Expand Up @@ -106,11 +108,10 @@
# in CRYPTO_HOT); that move is the whole
# point of this file — see the header at
# the top and the routing line below.
# LIB_NISTCURVES_P256_BSS - data_p256 working buffers. NET_BSS_TAIL
# (NOT CRYPTO_HOT — see the routing line
# near the bottom of this file and the
# measured table at the MEMORY block;
# it links at $3CB5-$41D4).
# LIB_NISTCURVES_P256_BSS - data_p256 working buffers. On cert_buf
# (P256_SCRATCH_UNION, MEMORY block): the
# two lifetimes are disjoint — see the
# routing line near the bottom of this file.
# LIB_NISTCURVES_P256_LIMLEE_BSS - comb precompute table. CRYPTO_OVERLAY,
# per the variant header at the top of
# this file.
Expand Down Expand Up @@ -149,8 +150,9 @@ MEMORY {
# that region was collapsed to the zero-size alias below and its 512 B
# handed to NET_BSS_TAIL, of which only ~$125 had ever been used.
#
# It holds the NET_BSS_TAIL segment (deframer + viewer BSS), the
# sibling's LIB_NISTCURVES_P256_BSS, and the stub UCI_BSS_REGION.
# It holds the NET_BSS_TAIL segment (deframer + viewer BSS) and the
# stub UCI_BSS_REGION. The sibling's LIB_NISTCURVES_P256_BSS used to
# pack here too; it now shares cert_buf (P256_SCRATCH_UNION, below).
# It does **NOT** hold UCI_BSS. UCI_BSS is routed to CRYPTO_HOT by the
# SEGMENTS block below, and both shipped UCI products link it there
# (measured 2026-08-31, build/c64-https.map). The header map at the top
Expand All @@ -164,6 +166,15 @@ MEMORY {
# `define = yes` emits __UCI_BSS_REGION_START__ etc.).
UCI_BSS_REGION: start = $4000, size = $0000, type = rw, define = yes;
CRYPTO_OVERLAY: start = $4200, size = $1E00, file = %O, define = yes, fill = yes, fillval = $00;
# P256_SCRATCH_UNION: LIB_NISTCURVES_P256_BSS (verify scratch) on top
# of cert_buf, which is pinned at the head of CRYPTO_OVERLAY — the UCI
# twin of cfg/c64-https-ip65.cfg's SCRATCH_UNION (#68). Disjoint
# lifetimes: the LIFETIME CONTRACT at CERT_BUF_BSS in src/der_decode.s.
# The size is CERT_BUF_SIZE (src/net/uci/net_tuning.inc), so P-256 BSS
# growth past cert_buf is a link error, not a silent overlap with the
# next CRYPTO_OVERLAY tenant; src/der_decode.s asserts start and size.
# Not file-backed: the bytes are cert_buf's.
P256_SCRATCH_UNION: start = $4200, size = $0800, type = rw, define = yes;

# W1 HOT/COLD SPLIT (Worker I — root-cause fix for the
# boot zero-fill regression):
Expand Down Expand Up @@ -264,6 +275,10 @@ SEGMENTS {
HTTP_AUX_CODE: load = LOADER, type = ro, optional = yes;
# x25_basepoint + fe_p (libs/x25519, #245). Ahead of RODATA so its
# 32-byte alignment lands on the region start and costs no fill.
# cert_buf first, at a fixed address, so the areas that time-share it
# can sit on it: P256_SCRATCH_UNION (src/der_decode.s asserts it does)
# and, on the cold cfg, the COLD_RUN_* areas (src/net/uci/cold_bank.s).
CERT_BUF_BSS: load = CRYPTO_OVERLAY, type = bss, start = $4200;
X25519_RODATA: load = CRYPTO_OVERLAY, type = ro, align = $20;
RODATA: load = CRYPTO_OVERLAY, type = ro; # onchip-comb variant: relieve CRYPTO_HOT
INIT: load = LOADER, type = ro, optional = yes;
Expand Down Expand Up @@ -315,11 +330,10 @@ SEGMENTS {
# one the MEMORY block's NET_BSS_TAIL comment defers to.
UCI_BSS: load = CRYPTO_HOT, type = bss, optional = yes;
# NET_BSS_TAIL is the spill-over BSS region carved from the
# NET_CODE tail, and it is NOT free: LIB_NISTCURVES_P256_BSS is
# routed here (see the segment near the bottom of this file), and
# the NET_BSS_TAIL segment itself carries the deframer + viewer
# BSS, with LIB_NISTCURVES_P256_BSS packed after it; the tail
# left over is small. The harness must take scratch addresses
# NET_CODE tail. The NET_BSS_TAIL segment carries the deframer +
# viewer BSS; LIB_NISTCURVES_P256_BSS no longer packs after it (it
# shares cert_buf, see the segment near the bottom of this file),
# so most of the region is free. The harness must take scratch addresses
# from tools/uci/_memory_policy.py, which parses build/labels.txt,
# not from any figure written here.
NET_BSS_TAIL: load = NET_BSS_TAIL, type = bss, optional = yes;
Expand Down Expand Up @@ -362,7 +376,7 @@ SEGMENTS {
# A runtime overlay swap-in would now clobber the staged leaf
# certificate mid-handshake (live data, not just code) — the
# embed-flag exclusion is a data-integrity constraint here.
CERT_BUF_BSS: load = CRYPTO_OVERLAY, type = bss, optional = yes;
# (CERT_BUF_BSS is pinned at the head of the region, above)


# Lane G stretch goal: REU-backed text viewer (src/viewer.s). This
Expand Down Expand Up @@ -441,16 +455,19 @@ SEGMENTS {
# link time.
LIB_NISTCURVES_P256_CODE: load = CRYPTO_HOT, type = ro, optional = yes;
LIB_NISTCURVES_P256_RODATA: load = CRYPTO_OVERLAY, type = ro, optional = yes; # onchip-comb variant
# P-256 BSS is 1,312 B (fp256/mod256/points256 scratch + ecdsa256
# input/output staging + data_p256 working buffers). Stays in
# NET_BSS_TAIL under the W1 hot/cold split — CRYPTO_COLD_SHADOW
# is full carrying the in-tree BSS chunks (BSS / CRYPTO_BSS /
# TABLES_BSS / BSS_TAIL = ~8.1 KB out of the 8 KB budget once
# TABLES_BSS page-alignment is accounted for). It packs after the
# NET_BSS_TAIL segment. Do not size harness scratch from it;
# tools/uci/_memory_policy.py reads
# build/labels.txt.
LIB_NISTCURVES_P256_BSS: load = NET_BSS_TAIL, type = bss, optional = yes;
# P-256 BSS (fp256/mod256/points256 scratch + ecdsa256 input/output
# staging + data_p256 working buffers) is per-call verify scratch, so
# it time-shares cert_buf exactly as ip65's SCRATCH_UNION does (#68):
# cert_buf is dead once x509_extract_pubkey returns (the pubkey, SAN
# check and SPKI pin all run inside it), and ecdsa_verify runs only
# after that. Two things would break the union: code RUNNING from
# cert_buf that calls ecdsa_verify (TRUST_BUNDLE=1 on the comb cold
# bank; refused by a Makefile $(error) and an lderror in
# src/net/uci/trust_bundle.s), and anything that re-reads cert_buf
# after CertificateVerify (the LIFETIME CONTRACT in src/der_decode.s).
# Do not size harness scratch from it; tools/uci/_memory_policy.py
# reads build/labels.txt.
LIB_NISTCURVES_P256_BSS: load = P256_SCRATCH_UNION, type = bss, optional = yes;
# Comb profile: Lim-Lee anchors + working k (data_p256_limlee.o).
# CRYPTO_COLD_SHADOW is flush-full (sqtab ends at $BFFF), so this
# rides in the file-backed CRYPTO_OVERLAY with the other variant
Expand Down
Loading