From d9c526b2002aeba943382aeb16098034c6068f47 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Niels=20M=C3=B6ller?= <nisse@lysator.liu.se>
Date: Wed, 15 May 2002 01:35:37 +0200
Subject: [PATCH] * sparc/aes.asm: The frame setup was broken. Tried to fix it.

Rev: src/nettle/sparc/aes.asm:1.75
---
 sparc/aes.asm | 25 +++++++++++++++++--------
 1 file changed, 17 insertions(+), 8 deletions(-)

diff --git a/sparc/aes.asm b/sparc/aes.asm
index 34592ff5..79a5d37f 100644
--- a/sparc/aes.asm
+++ b/sparc/aes.asm
@@ -42,7 +42,9 @@ define(dst, %i3)
 define(src, %i4)
 
 ! Loop invariants
-define(wtxt, %sp)
+! NOTE: We overwrite %fp with the wtxt pointer,
+!       so it must be restored at the end of the function.
+define(wtxt, %fp)
 define(tmp, %l1)
 define(diff, %l2)
 define(nrounds, %l3)
@@ -66,29 +68,36 @@ define(t1, %o1)
 define(t2, %o2)
 define(t3, %o3)
 
-define(<FRAME_SIZE>, 32)
-define(<FRAME_WTXT>, 0)
-define(<FRAME_TMP>, 16)
+C The stack frame looks like
+C
+C %fp -   4: OS-dependent link field
+C %fp -   8: OS-dependent link field
+C %fp -  24: tmp, uint32_t[4]
+C %fp -  40: wtxt, uint32_t[4]
+C %fp - 136: OS register save area. 
+define(<FRAME_SIZE>, 136)
 
 _aes_crypt:
 	save	%sp, -FRAME_SIZE, %sp
 	cmp	length, 0
 	be	.Lend
-	add	%sp, FRAME_TMP, tmp
+	add	%fp, -24, tmp
 
+	C NOTE: Over writes %fp
+	add	%fp, -40, wtxt
 	ld	[ctx + AES_NROUNDS], nrounds
 	! Compute xor, so that we can swap efficiently.
 	xor	wtxt, tmp, diff
 	! The loop variable will be multiplied by 16.
 	! More loop invariants
 	add	T, AES_TABLE0, T0
-	add	T, AES_TABLE1, T1
 	
+	add	T, AES_TABLE1, T1
 	add	T, AES_TABLE2, T2
 	add	T, AES_TABLE3, T3
 	add	T, AES_SIDX1, IDX1
-	add	T, AES_SIDX3, IDX3
 	
+	add	T, AES_SIDX3, IDX3
 	! Read src, and add initial subkey
 	! Difference between ctx and src.
 	! NOTE: These instructions are duplicated in the delay slot,
@@ -100,7 +109,6 @@ _aes_crypt:
 	! For stop condition. Note that src is incremented in the
 	! delay slot
 	add	src, 8, %g1
-	nop
 		
 .Lsource_loop:
 	ldub	[src+3], t3
@@ -238,6 +246,7 @@ define(i, round)
 	bne	.Lblock_loop
 	sub	wtxt, src, %g3
 
+	add	%sp, FRAME_SIZE, %fp
 .Lend:
 	ret
 	restore
-- 
GitLab