Publish VCC Plus OSS source distribution for 3.6.2 build 60

This commit is contained in:
Brian Holman committed 2026-11-13 00:14:03 -07:00
commit c652a5276d
1192 files changed
+272368

No files matched your search

+34
View File
@@ -0,0 +1,34 @@
# SPDX-License-Identifier: GPL-3.0-or-later
"""Run bounded-allocation checks and the manual's crew example on both guest CPUs."""
import argparse
import os
from pathlib import Path
import subprocess
import tempfile
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("runtime", type=Path, help="staged toolchain with vcccompat and wydealloc")
parser.add_argument("core", type=Path, help="current libVCCCore.a")
parser.add_argument("rom", type=Path, help="privately supplied CoCo 3 ROM")
args = parser.parse_args()
runtime = args.runtime.resolve(strict=True)
fixture = Path(__file__).resolve().parent
root = fixture.parents[2]
env = dict(os.environ, VCC_CMOC_COMPAT="1", PATH=str(runtime / "bin") + os.pathsep + os.environ["PATH"])
with tempfile.TemporaryDirectory(prefix="vcc-heap-") as work:
subprocess.run(["xcrun", "clang++", "-std=c++17", "-O2", "-mmacosx-version-min=14.0",
"-I", root / "src", fixture / "run.cpp", args.core.resolve(strict=True), "-o", "run"],
cwd=work, check=True)
for optimization in ("-O0", "-O2"):
for source, name in ((fixture / "qualification.c", "QUAL.BIN"),
(root / "examples/cmoc/manual/crew.c", "CREW.BIN")):
subprocess.run([runtime / "bin/cmoc", "--coco", optimization, "-Werror", "--org=2800",
"-o", name, source, "-lvcccompat", "-lwydealloc"], env=env, cwd=work, check=True)
print("Checking", optimization, flush=True)
subprocess.run(["./run", args.rom.resolve(strict=True), "QUAL.BIN", "CREW.BIN"], cwd=work, check=True)
if __name__ == "__main__":
main()
+123
View File
@@ -0,0 +1,123 @@
// SPDX-License-Identifier: GPL-3.0-or-later
#include <stdlib.h>
#include <coco.h>
#define CHECK(test) do { if (!(test)) return __LINE__; } while (0)
#define BUDGET 240
// Keep guard bytes immediately before and after the exact array given to the heap.
static byte guarded[BUDGET + 2];
static byte alternate[48];
// Materialize logical negation as an int result. This also checks the
// optimized CMOC call sequence, which differs from a branch on success.
static int initializationFailed(byte *storage, unsigned capacity)
{
return !vcc_heap_init(storage, capacity);
}
static int qualifies(void)
{
byte stackGuard[15];
byte *pool = guarded + 1, *p, *q, *other, *left, *middle, *right, *end;
unsigned i;
memset(guarded, 0xB9, sizeof(guarded));
memset(alternate, 0xCD, sizeof(alternate));
for (i = 0; i < sizeof(stackGuard); ++i)
stackGuard[i] = (byte)(i + 97);
// No hidden default heap, and a range wrapping through zero is not usable.
free(NULL);
CHECK(!malloc(1) && !calloc(1, 2) && !realloc(NULL, 3));
CHECK(!vcc_heap_init(NULL, BUDGET) && !vcc_heap_init(pool, 15));
CHECK(!vcc_heap_init((void *)0xFFF0, 32));
CHECK(initializationFailed(alternate, 15) == 1);
CHECK(initializationFailed(alternate, 16) == 0);
p = (byte *)malloc(1);
CHECK(p && p >= alternate && p < alternate + 16);
free(p);
CHECK(vcc_heap_init(pool, BUDGET));
CHECK(!malloc(0) && !calloc(0, 3) && !calloc(3, 0));
CHECK(!calloc(256, 256) && !calloc(32769U, 2) && !malloc(65535U));
p = (byte *)calloc(4, 9);
CHECK(p && p >= pool && p + 36 <= pool + BUDGET);
for (i = 0; i < 36; ++i) {
CHECK(p[i] == 0);
p[i] = (byte)(33 + i);
}
// A rejected reinitialization leaves both the old block and new region alone.
memset(alternate, 0xCD, sizeof(alternate));
CHECK(!vcc_heap_init(alternate, sizeof(alternate)));
CHECK(!vcc_heap_init(pool, BUDGET));
for (i = 0; i < sizeof(alternate); ++i) CHECK(alternate[i] == 0xCD);
other = (byte *)realloc(NULL, 24);
CHECK(other);
memset(other, 0x3A, 24);
CHECK(!realloc(p, 65535U));
q = (byte *)realloc(p, 68);
CHECK(q);
for (i = 0; i < 36; ++i) CHECK(q[i] == (byte)(33 + i));
for (i = 0; i < 24; ++i) CHECK(other[i] == 0x3A);
CHECK(!realloc(q, BUDGET)); // Exhaustion even though the integer size fits.
for (i = 0; i < 36; ++i) CHECK(q[i] == (byte)(33 + i));
p = (byte *)realloc(q, 11);
CHECK(p);
for (i = 0; i < 11; ++i) CHECK(p[i] == (byte)(33 + i));
CHECK(realloc(other, 0) == NULL);
free(p);
// Four live objects divide the pool. The two separate holes cannot hold
// 64 bytes until the middle object is freed and the three holes coalesce.
left = (byte *)malloc(40);
middle = (byte *)malloc(40);
right = (byte *)malloc(40);
end = (byte *)malloc(40);
CHECK(left && middle && right && end);
memset(end, 0x37, 40);
free(left);
free(right);
CHECK(!malloc(64));
free(middle);
p = (byte *)malloc(90);
CHECK(p);
memset(p, 0xAA, 90);
for (i = 0; i < 40; ++i) CHECK(end[i] == 0x37);
free(end);
free(p);
// After several fill/release cycles the pool must regain its original room.
for (i = 0; i < 50; ++i) {
p = (byte *)malloc(200);
CHECK(p && p >= pool && p + 200 <= pool + BUDGET);
memset(p, 0x35, 200);
free(p);
}
p = (byte *)calloc(100, 2);
CHECK(p);
for (i = 0; i < 200; ++i) CHECK(!p[i]);
free(p);
CHECK(!vcc_heap_init(NULL, BUDGET));
p = (byte *)malloc(200);
CHECK(p && p >= pool && p + 200 <= pool + BUDGET);
free(p);
CHECK(vcc_heap_init(alternate, sizeof(alternate)));
p = (byte *)malloc(16);
CHECK(p && p >= alternate && p + 16 <= alternate + sizeof(alternate));
free(p);
CHECK(guarded[0] == 0xB9 && guarded[BUDGET + 1] == 0xB9);
for (i = 0; i < sizeof(stackGuard); ++i) CHECK(stackGuard[i] == (byte)(i + 97));
return 0;
}
int main(void)
{
int line;
cls(1);
line = qualifies();
if (line) printf("FAIL LINE %d\n", line);
else printf("BOUNDED HEAP PASSED\n");
return line != 0;
}
+63
View File
@@ -0,0 +1,63 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// Exercise the same Direct Run entry point used by the C development workspace.
#include "core/MachineSession.h"
#include <fstream>
#include <iostream>
#include <iterator>
#include <stdexcept>
using namespace VCC::Mac;
using Bytes = std::vector<std::uint8_t>;
static Bytes readFile(const char* path) {
std::ifstream input(path, std::ios::binary);
if (!input) throw std::runtime_error(std::string("Cannot open ") + path);
return {std::istreambuf_iterator<char>(input), std::istreambuf_iterator<char>()};
}
static void waitFor(MachineSession& machine, const std::string& expected) {
for (unsigned frame = 0; frame < 900; ++frame) {
const auto text = machine.copyScreenText();
if (text.find("FAIL LINE") != std::string::npos) break;
if (text.find(expected) != std::string::npos) return;
machine.advance();
}
throw std::runtime_error("Expected " + expected + " on screen:\n" + machine.copyScreenText());
}
static void run(const Bytes& rom, const Bytes& binary, Processor cpu, const std::string& expected) {
MachineSession machine;
machine.load(rom, cpu);
machine.resume();
for (unsigned frame = 0; frame < 180; ++frame) machine.advance();
waitFor(machine, "OK");
if (binary.size() < 5 || binary[binary.size() - 5] != 0xFF)
throw std::runtime_error("Expected a DECB executable with an entry point");
const auto n = binary.size();
machine.debuggerLoadBinary(binary, std::uint16_t((binary[n - 2] << 8) | binary[n - 1]));
machine.debuggerClearDevelopmentBreakpoints();
machine.resume();
waitFor(machine, expected);
// PRINT 7*9, followed by Enter, through the guest keyboard matrix. The
// calculation confirms the interpreter accepted input after main returned.
auto key = [](int bit) { return std::uint64_t(1) << bit; };
machine.paste({key(16), key(18), key(9), key(14), key(20), key(31),
key(39), key(55) | key(42), key(41), key(48)});
waitFor(machine, " 63");
}
int main(int argc, char** argv) {
try {
if (argc != 4) throw std::runtime_error("Usage: run COCO3_ROM QUAL_BIN CREW_BIN");
const auto rom = readFile(argv[1]), qual = readFile(argv[2]), crew = readFile(argv[3]);
for (auto cpu : {Processor::MC6809, Processor::HD6309}) {
run(rom, qual, cpu, "BOUNDED HEAP PASSED\nOK");
run(rom, crew, cpu, "CREW AT LAUNCH: 0\nCREW AFTER GROWTH: 3\nNO ROOM FOR 200\nCREW STILL ABOARD: 3\nCREW LOG CLOSED\nOK");
std::cout << "PASS " << (cpu == Processor::MC6809 ? "MC6809" : "HD6309")
<< ": heap boundaries, manual exercise and BASIC return\n";
}
} catch (const std::exception& error) {
std::cerr << error.what() << '\n';
return 1;
}
}