From c95bcac91de056e6b804fabb22b15caec62fbee0 Mon Sep 17 00:00:00 2001 From: George Koehler Date: Thu, 7 Dec 2017 15:39:41 -0500 Subject: [PATCH] Correct the stack pointer when i80 shrinks an integer. The code used `sphl` to set the stack pointer, but the correct value was in de, not hl. Fix by swapping the values of de and hl, so `sphl` is now correct. When we shrink an integer from 4 to 2 bytes, both registers de and hl point to copies of the result, but only one register preserves the stack below the result. This fixes writehex() in tests/plat/lib/test.c, when I compile it with ack -mcpm, so it preserves the pointer to "0123456789abcdef", so it writes hexadecimal digits and not garbage. This bug goes back to commit 157b243 of Mar 18, 1985, so the bug is 32 years old, and probably the oldest bug that I ever fixed. --- mach/i80/libem/cii.s | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/mach/i80/libem/cii.s b/mach/i80/libem/cii.s index 7d091da5e..bf4e7efb8 100644 --- a/mach/i80/libem/cii.s +++ b/mach/i80/libem/cii.s @@ -65,19 +65,19 @@ jmp 3f ! done !if destination size < source size only: -shrink: mov l,c ! load source size in hl +shrink: mov l,b ! load destination size in hl mvi h,0 dad sp mov d,h - mov e,l ! de points just above source - mov l,b ! load destination size in hl + mov e,l ! de points just above lowest bytes of source + mov l,c ! load source size in hl mvi h,0 dad sp ! hl points just above "destination" 1: dcx d ! move upwards dcx h - mov a,m - stax d + ldax d + mov m,a dcr b jnz 1b sphl