From 54023a94a6d7a282571ab18da7862a909d36d894 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Oudompheng?= Date: Mon, 26 Nov 2012 21:31:42 +0100 Subject: [PATCH] cmd/8l: fix data corruption for MULB SI, The 8l linker automatically inserts XCHG instructions to support otherwise impossible byte registers (only available on AX, BX, CX, DX). Sometimes AX or DX is needed (for MUL and DIV) so we need to avoid clobbering them. R=golang-dev, dave, iant, iant, rsc CC=golang-dev https://golang.org/cl/6846057 --- src/cmd/6l/span.c | 4 +++- src/cmd/8l/span.c | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/cmd/6l/span.c b/src/cmd/6l/span.c index abffc2935cf..a181178680a 100644 --- a/src/cmd/6l/span.c +++ b/src/cmd/6l/span.c @@ -1618,7 +1618,9 @@ bad: pp = *p; z = p->from.type; if(z >= D_BP && z <= D_DI) { - if(isax(&p->to)) { + if(isax(&p->to) || p->to.type == D_NONE) { + // We certainly don't want to exchange + // with AX if the op is MUL or DIV. *andptr++ = 0x87; /* xchg lhs,bx */ asmando(&p->from, reg[D_BX]); subreg(&pp, z, D_BX); diff --git a/src/cmd/8l/span.c b/src/cmd/8l/span.c index d90ddc2233e..9e3447c2d28 100644 --- a/src/cmd/8l/span.c +++ b/src/cmd/8l/span.c @@ -1272,7 +1272,9 @@ bad: pp = *p; z = p->from.type; if(z >= D_BP && z <= D_DI) { - if(isax(&p->to)) { + if(isax(&p->to) || p->to.type == D_NONE) { + // We certainly don't want to exchange + // with AX if the op is MUL or DIV. *andptr++ = 0x87; /* xchg lhs,bx */ asmand(&p->from, reg[D_BX]); subreg(&pp, z, D_BX);