Batch 21 (20261027-A-bos-redo-21) rebuilt 40 of the 53 rejected Bos-qiao environments: hidden assertions that ran inside the candidate's process now run in a trusted parent that reads observations from a low-UID worker; gold bytes are unchanged. 9 were excluded for scope (ROS2, oversize, security core), 3 are blocked because the source requires an exec bit the platform does not freeze, 1 lacks requests/bs4 in trace6. Batch 18 (20261026-C-hwe-codegen-18) adds its last 34 of 134 tasks; the first 100 landed in 2f32624d. Claude reviewed 74/74 USABLE against current digests, canonical families, no ID or source overlap with main, plain public docs. Only the new task directories are taken; the stale pre-batch-20 copies of concur-release-capsule and resource-temp-link on the batch 21 branch and both branches' progress notes stay as main has them. Difficulty is unmeasured. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
184 lines
5.0 KiB
C++
184 lines
5.0 KiB
C++
#include "eeprom.hpp"
|
|
#include <algorithm>
|
|
namespace eeprom {
|
|
bool Bus::valid_id(Number id) {
|
|
return id >= 0 && id <= 3;
|
|
}
|
|
bool Bus::valid_bytes(const std::vector<Number>& values, std::size_t limit) {
|
|
if (values.size() > limit) {
|
|
return false;
|
|
}
|
|
for (Number value : values) {
|
|
if (value < 0 || value > 255) {
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
Bus::Device Bus::state(Number id) const {
|
|
return devices_.at(id);
|
|
}
|
|
void Bus::record(Number id, char operation, Number first, Number second, const std::vector<Number>& data) {
|
|
Device& device = devices_.at(id);
|
|
if (operation == 'S') {
|
|
device.cursor = first;
|
|
return;
|
|
}
|
|
if (operation == 'W') {
|
|
device.pending = data;
|
|
device.pending_start = device.cursor;
|
|
device.busy = device.cycle;
|
|
device.accepted += 1;
|
|
return;
|
|
}
|
|
if (operation == 'P') {
|
|
device.polls += 1;
|
|
if (device.pending.empty()) {
|
|
return;
|
|
}
|
|
if (device.busy > 0) {
|
|
device.busy -= 1;
|
|
return;
|
|
}
|
|
Number base = device.pending_start / 8 * 8;
|
|
for (std::size_t i = 0; i < device.pending.size(); ++i) {
|
|
Number offset = (device.pending_start % 8 + static_cast<Number>(i)) % 8;
|
|
device.bytes[static_cast<std::size_t>(base + offset)] = device.pending[i];
|
|
}
|
|
device.cursor = (device.pending_start + static_cast<Number>(device.pending.size())) % 256;
|
|
device.pending.clear();
|
|
device.pending_start = 0;
|
|
device.committed += 1;
|
|
return;
|
|
}
|
|
if (operation == 'R') {
|
|
device.cursor = (device.cursor + first) % 256;
|
|
}
|
|
(void)second;
|
|
}
|
|
Reply Bus::mount(Number id, Number fill, Number cycle) {
|
|
if (!valid_id(id)) {
|
|
return {Code::RANGE, 0, {}};
|
|
}
|
|
if (fill < 0 || fill > 255) {
|
|
return {Code::RANGE, 0, {}};
|
|
}
|
|
if (cycle < 0 || cycle > 4) {
|
|
return {Code::RANGE, 0, {}};
|
|
}
|
|
if (devices_.count(id) != 0) {
|
|
return {Code::EXISTS, 0, {}};
|
|
}
|
|
Device device;
|
|
device.cycle = cycle;
|
|
device.bytes.assign(256, fill);
|
|
devices_.emplace(id, std::move(device));
|
|
return {};
|
|
}
|
|
Reply Bus::unmount(Number id) {
|
|
if (!valid_id(id)) {
|
|
return {Code::RANGE, 0, {}};
|
|
}
|
|
if (devices_.count(id) == 0) {
|
|
return {Code::ABSENT, 0, {}};
|
|
}
|
|
if (!state(id).pending.empty()) {
|
|
return {Code::BUSY, 0, {}};
|
|
}
|
|
devices_.erase(id);
|
|
return {};
|
|
}
|
|
Reply Bus::seek(Number id, Number address) {
|
|
if (!valid_id(id)) {
|
|
return {Code::RANGE, 0, {}};
|
|
}
|
|
if (address < 0 || address > 255) {
|
|
return {Code::RANGE, 0, {}};
|
|
}
|
|
if (devices_.count(id) == 0) {
|
|
return {Code::ABSENT, 0, {}};
|
|
}
|
|
if (!state(id).pending.empty()) {
|
|
return {Code::BUSY, 0, {}};
|
|
}
|
|
record(id, 'S', address, 0, {});
|
|
return {};
|
|
}
|
|
Reply Bus::page(Number id, const std::vector<Number>& values) {
|
|
if (!valid_id(id)) {
|
|
return {Code::RANGE, 0, {}};
|
|
}
|
|
if (!valid_bytes(values, 8)) {
|
|
return {Code::RANGE, 0, {}};
|
|
}
|
|
if (devices_.count(id) == 0) {
|
|
return {Code::ABSENT, 0, {}};
|
|
}
|
|
if (!state(id).pending.empty()) {
|
|
return {Code::BUSY, 0, {}};
|
|
}
|
|
if (!values.empty()) {
|
|
record(id, 'W', 0, 0, values);
|
|
}
|
|
return {};
|
|
}
|
|
Reply Bus::poll(Number id) {
|
|
if (!valid_id(id)) {
|
|
return {Code::RANGE, 0, {}};
|
|
}
|
|
if (devices_.count(id) == 0) {
|
|
return {Code::ABSENT, 0, {}};
|
|
}
|
|
Device before = state(id);
|
|
record(id, 'P', 0, 0, {});
|
|
if (!before.pending.empty() && before.busy > 0) {
|
|
return {Code::BUSY, 0, {}};
|
|
}
|
|
return {Code::OK, static_cast<Number>(before.pending.size()), {}};
|
|
}
|
|
Reply Bus::read(Number id, Number count) {
|
|
if (!valid_id(id)) {
|
|
return {Code::RANGE, 0, {}};
|
|
}
|
|
if (count < 0 || count > 256) {
|
|
return {Code::RANGE, 0, {}};
|
|
}
|
|
if (devices_.count(id) == 0) {
|
|
return {Code::ABSENT, 0, {}};
|
|
}
|
|
Device before = state(id);
|
|
if (!before.pending.empty()) {
|
|
return {Code::BUSY, 0, {}};
|
|
}
|
|
Reply reply;
|
|
reply.completed = count;
|
|
for (Number i = 0; i < count; ++i) {
|
|
std::size_t index = static_cast<std::size_t>((before.cursor + i) % 256);
|
|
reply.data.push_back(before.bytes[index]);
|
|
}
|
|
record(id, 'R', 0, 0, {});
|
|
return reply;
|
|
}
|
|
Snapshot Bus::inspect(Number id) const {
|
|
Snapshot snapshot;
|
|
if (!valid_id(id)) {
|
|
snapshot.code = Code::RANGE;
|
|
return snapshot;
|
|
}
|
|
if (devices_.count(id) == 0) {
|
|
snapshot.code = Code::ABSENT;
|
|
return snapshot;
|
|
}
|
|
Device device = state(id);
|
|
snapshot.cursor = device.cursor;
|
|
snapshot.busy = device.busy;
|
|
snapshot.accepted = device.accepted;
|
|
snapshot.committed = device.committed;
|
|
snapshot.polls = device.polls;
|
|
snapshot.pending_start = device.pending_start;
|
|
snapshot.pending = device.pending;
|
|
snapshot.bytes = device.bytes;
|
|
return snapshot;
|
|
}
|
|
}
|