amos 9d633e9e67 Batch 15 (20261023-C-hwe-scale-15): 320 HWE-derived repair tasks
One user-space repair task per eligible HWE debug-diag / compile-deploy base
ID: 320 admitted (C 218, C++ 97, build scripts 5), 1 skipped by the content
filter. Each ships a public spec with a check-to-basis table, at least two
defects with single-fix fixtures, a symptom-masking fixture and an alternative
correct implementation. Claude re-checked all 320: structure, the HWE quality
items and trace6 Docker calibration receipts against current digests
(320/320 USABLE). Difficulty is unmeasured. Known follow-up: 212 tasks use 120
ad-hoc family names; the next batch maps them to the canonical list.
The batch's 1,256-line progress log stays in its factory report and the
36-local branch batch15-hwe.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 01:55:56 +08:00

112 lines
3.2 KiB
C

#include "tx.h"
#include <string.h>
static int slot_valid(int slot)
{
return slot >= 0 && slot < TX_SLOTS;
}
static int range_valid(size_t offset, size_t length)
{
if (length == 0 || length > TX_CAPACITY)
return 0;
if (offset >= TX_CAPACITY)
return 0;
return length <= TX_CAPACITY - offset;
}
static struct port_descriptor *descriptor_for(struct memory_port *p, int id)
{
for (int i = 0; i < TX_SLOTS; ++i) {
if (p->queue[i].active && p->queue[i].id == id)
return &p->queue[i];
}
return NULL;
}
static struct port_descriptor *empty_descriptor(struct memory_port *p)
{
for (int i = 0; i < TX_SLOTS; ++i) {
if (!p->queue[i].active)
return &p->queue[i];
}
return NULL;
}
int port_init(struct memory_port *p, int line)
{
if (line != 16 && line != 32 && line != 64)
return TX_INVALID;
memset(p, 0, sizeof(*p));
p->line = (size_t)line;
for (int s = 0; s < TX_SLOTS; ++s) {
for (size_t i = 0; i < TX_CAPACITY; ++i) {
p->cpu[s][i] = 0x5a;
p->memory[s][i] = 0x5a;
}
}
return TX_OK;
}
int port_write(struct memory_port *p, int slot, size_t offset,
const uint8_t *data, size_t length)
{
if (!slot_valid(slot) || !range_valid(offset, length) || !data)
return TX_INVALID;
memcpy(&p->cpu[slot][offset], data, length);
return TX_OK;
}
int port_fill(struct memory_port *p, int slot, size_t offset,
size_t length, uint8_t value)
{
if (!slot_valid(slot) || !range_valid(offset, length))
return TX_INVALID;
memset(&p->cpu[slot][offset], value, length);
return TX_OK;
}
int port_clean(struct memory_port *p, int slot, size_t offset, size_t length)
{
if (!slot_valid(slot) || !range_valid(offset, length))
return TX_INVALID;
size_t first = offset - offset % p->line;
size_t limit = offset + length;
if (limit % p->line)
limit += p->line - limit % p->line;
if (limit > TX_CAPACITY)
limit = TX_CAPACITY;
memcpy(&p->memory[slot][first], &p->cpu[slot][first], limit - first);
return TX_OK;
}
int port_queue(struct memory_port *p, int slot, int id, size_t length)
{
if (!slot_valid(slot) || id < 1 || id > 65535 ||
length < 1 || length > TX_CAPACITY)
return TX_INVALID;
if (descriptor_for(p, id))
return TX_BUSY;
for (int i = 0; i < TX_SLOTS; ++i) {
if (p->queue[i].active && p->queue[i].slot == slot)
return TX_BUSY;
}
struct port_descriptor *d = empty_descriptor(p);
if (!d)
return TX_BUSY;
d->id = id;
d->slot = slot;
d->length = length;
d->active = 1;
return TX_OK;
}
int port_complete(struct memory_port *p, int id, int status,
struct tx_completion *out)
{
out->id = 0;
out->length = 0;
if (id < 1 || id > 65535 || (status != 0 && status != 1))
return TX_INVALID;
struct port_descriptor *d = descriptor_for(p, id);
if (!d)
return TX_ABSENT;
out->id = id;
if (status == 0) {
out->length = d->length;
memcpy(out->data, p->memory[d->slot], d->length);
}
d->active = 0;
return TX_OK;
}