Files
tdkpin/original/reconstructed/tests/test_stack.c
T
ddidderr 8b99e9607c feat(reconstruction): complete binary-backed C recovery
Replace the partial mechanics transcriptions with a separate, readable C11
reconstruction of the complete Win16 image while preserving the original raw
Ghidra export as immutable evidence. Cover all ordinary and overlapping entry
points, Borland runtime behavior, Win16 imports, segmented data, callbacks,
resources, indirect control flow, physics, rendering, persistence, and
startup/shutdown lifecycles.

Add deterministic extraction and audit tooling plus address-linked ledgers for
functions, imports, DGROUP ranges and objects, relocations, resources, and
callbacks. The final gate records zero raw, partial, restored, unknown,
blocked, or unclassified required units. Keep the semantic-fidelity boundary
explicit: the portable C is not claimed to reproduce a byte-identical Borland
NE build.

Add strict focused harnesses for every reconstructed C unit, exact resource
round-trip checks, and a 16-bit Borland Real48 reference probe. No Rust source
or Cargo metadata is changed in this phase.

Test Plan:
- `bash original/tools/test_reconstructed_c.sh` -- passed
- `bash original/tools/probe_real48_reference.sh` -- passed bit-for-bit
- `python3 original/tools/audit_reconstruction.py --require-complete` -- passed
- `git diff --cached --check` -- passed
- `git diff HEAD -- '*.rs' Cargo.toml Cargo.lock` -- empty
2026-08-23 16:41:17 +02:00

49 lines
1.2 KiB
C

#include "../tdkpin_stack.h"
#include <assert.h>
#include <setjmp.h>
static jmp_buf g_error_jump;
static uint16_t g_error_code;
_Noreturn void borland_runtime_error(uint16_t code)
{
g_error_code = code;
longjmp(g_error_jump, 1);
}
static void expect_stack_error(uint16_t requested_bytes)
{
g_error_code = 0;
if (setjmp(g_error_jump) == 0) {
borland_check_stack(requested_bytes);
assert(false);
}
assert(g_error_code == 202);
}
int main(void)
{
static uint8_t stack[0x10000];
win16_reset_segment_bindings();
win16_bind_segment(0x7000, stack, sizeof(stack), true);
win16_set_stack_state(0x7000, 0x8000);
win16_write_stack_u16(0x000a, 0x1000);
win16_write_stack_u16(0x000e, 0x7000);
tdkpin_initialize_stack_guard();
assert(win16_read_stack_u16(0x000e) == 0x7000);
borland_check_stack(0x2000);
assert(win16_read_stack_u16(0x000e) == 0x5c00);
win16_write_stack_u16(0x000e, 0x7000);
borland_check_stack(0x6c00);
assert(win16_read_stack_u16(0x000e) == 0x1000);
expect_stack_error(0xfc00); /* AX + 0x400 carry. */
expect_stack_error(0x7c00); /* Required bytes collide with SP. */
expect_stack_error(0x6c01); /* Remaining byte falls below SS:000a. */
return 0;
}