#include "../tdkpin_stack.h" #include #include 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; }