first, let's ignore the "alphacpuid.s not bundled problem" as it is already 
filed as ticket #2309.  once that is fixed, we hit a rash of other issues.

seems this alpha assembly was tested with a toolchain other than the GNU one 
(meaning the GNU assembler or "gas"), and it was tested on a host other than 
Linux or glibc.

first, when using gas, there is no implicit offset of "0" when using 
load/store insns.  it must be explicitly specified as 0.  otherwise 
alphacpuid.s fails with:
alphacpuid.s:71: Error: inappropriate arguments for opcode `ldl_l'
alphacpuid.s:73: Error: inappropriate arguments for opcode `stl_c'
and then the alpha-mont.s fails with many errors like:
alpha-mont.s:66: Error: inappropriate arguments for opcode `ldq'
alpha-mont.s:207: Error: inappropriate arguments for opcode `stq'
(credit to Matt Turner for this info + fix)

next, on Linux/glibc systems, there is no "asm.h" or "regdef.h" headers.  so 
trying to generate alpha-mont.s originally fails with:
<stdin>:1:17: error: asm.h: No such file or directory
<stdin>:2:20: error: regdef.h: No such file or directory
there is however an asm/regdef.h which seems to provide everything this file 
is looking for in terms of register name defines.

getting past this hits another gas syntax error:
<stdin>:269: Error: unknown pseudo-op: `.rdata'
<stdin>:270: Error: unknown pseudo-op: `.asciiz'
gas uses ".section .rodata" and ".asciz".  but rather than fix/conditionalize 
this, it's a lot easier to simply remove it.  i cant see any references in 
this or any other file to this string in the first place, so it wont be 
shown/used in the final library.

finally, we're left with one warning:
<stdin>:36: Warning: operand out of range (0xfffffffffffff000 is not between 
0x0000000000000000 and 0x00000000000000ff)
which is due to this insn:
 mov -4096,$at
i dont know the correct fix here, so i imagine the original author will need 
to chime in.

at any rate, the attached patch fixes all the errors on alpha/Linux systems 
and i cant see it breaking any others ... it's against CVS head, but it should 
apply cleanly to the 1.0.0 branch as well.  both places need it.
-mike

Index: crypto/alphacpuid.pl
===================================================================
RCS file: /usr/local/src/openssl/CVSROOT/openssl/crypto/alphacpuid.pl,v
retrieving revision 1.2
diff -u -p -r1.2 alphacpuid.pl
--- crypto/alphacpuid.pl	28 Jul 2010 08:17:15 -0000	1.2
+++ crypto/alphacpuid.pl	12 Sep 2010 04:25:26 -0000
@@ -70,9 +70,9 @@ OPENSSL_wipe_cpu:
 OPENSSL_atomic_add:
 	.frame	$30,0,$26
 	.prologue 0
-1:	ldl_l	$0,($16)
+1:	ldl_l	$0,0($16)
 	addl	$0,$17,$1
-	stl_c	$1,($16)
+	stl_c	$1,0($16)
 	beq	$1,1b
 	addl	$0,$17,$0
 	ret	($26)
Index: crypto/bn/asm/alpha-mont.pl
===================================================================
RCS file: /usr/local/src/openssl/CVSROOT/openssl/crypto/bn/asm/alpha-mont.pl,v
retrieving revision 1.6
diff -u -p -r1.6 alpha-mont.pl
--- crypto/bn/asm/alpha-mont.pl	10 Apr 2010 13:33:04 -0000	1.6
+++ crypto/bn/asm/alpha-mont.pl	12 Sep 2010 04:44:04 -0000
@@ -41,8 +41,12 @@ $j="s4";
 $m1="s5";
 
 $code=<<___;
+#ifdef __linux__
+#include <asm/regdef.h>
+#else
 #include <asm.h>
 #include <regdef.h>
+#endif
 
 .text
 
@@ -106,9 +110,9 @@ bn_mul_mont:
 .align	4
 .L1st:
 	.set	noreorder
-	ldq	$aj,($aj)
+	ldq	$aj,0($aj)
 	addl	$j,1,$j
-	ldq	$nj,($nj)
+	ldq	$nj,0($nj)
 	lda	$tp,8($tp)
 
 	addq	$alo,$hi0,$lo0
@@ -159,12 +163,12 @@ bn_mul_mont:
 .align	4
 .Louter:
 	s8addq	$i,$bp,$bi
-	ldq	$hi0,($ap)
+	ldq	$hi0,0($ap)
 	ldq	$aj,8($ap)
-	ldq	$bi,($bi)
-	ldq	$hi1,($np)
+	ldq	$bi,0($bi)
+	ldq	$hi1,0($np)
 	ldq	$nj,8($np)
-	ldq	$tj,(sp)
+	ldq	$tj,0(sp)
 
 	mulq	$hi0,$bi,$lo0
 	umulh	$hi0,$bi,$hi0
@@ -195,10 +199,10 @@ bn_mul_mont:
 	.set	noreorder
 	ldq	$tj,8($tp)	#L0
 	nop			#U1
-	ldq	$aj,($aj)	#L1
+	ldq	$aj,0($aj)	#L1
 	s8addq	$j,$np,$nj	#U0
 
-	ldq	$nj,($nj)	#L0
+	ldq	$nj,0($nj)	#L0
 	nop			#U1
 	addq	$alo,$hi0,$lo0	#L1
 	lda	$tp,8($tp)
@@ -247,7 +251,7 @@ bn_mul_mont:
 	addq	$hi1,v0,$hi1
 
 	addq	$hi1,$hi0,$lo1
-	stq	$j,($tp)
+	stq	$j,0($tp)
 	cmpult	$lo1,$hi0,$hi1
 	addq	$lo1,$tj,$lo1
 	cmpult	$lo1,$tj,AT
@@ -265,8 +269,8 @@ bn_mul_mont:
 	mov	0,$hi0		# clear borrow bit
 
 .align	4
-.Lsub:	ldq	$lo0,($tp)
-	ldq	$lo1,($np)
+.Lsub:	ldq	$lo0,0($tp)
+	ldq	$lo1,0($np)
 	lda	$tp,8($tp)
 	lda	$np,8($np)
 	subq	$lo0,$lo1,$lo1	# tp[i]-np[i]
@@ -274,7 +278,7 @@ bn_mul_mont:
 	subq	$lo1,$hi0,$lo0
 	cmpult	$lo1,$lo0,$hi0
 	or	$hi0,AT,$hi0
-	stq	$lo0,($rp)
+	stq	$lo0,0($rp)
 	cmpult	$tp,$tj,v0
 	lda	$rp,8($rp)
 	bne	v0,.Lsub
@@ -288,7 +292,7 @@ bn_mul_mont:
 	bis	$bp,$ap,$ap	# ap=borrow?tp:rp
 
 .align	4
-.Lcopy:	ldq	$aj,($ap)	# copy or in-place refresh
+.Lcopy:	ldq	$aj,0($ap)	# copy or in-place refresh
 	lda	$tp,8($tp)
 	lda	$rp,8($rp)
 	lda	$ap,8($ap)
@@ -309,8 +313,10 @@ bn_mul_mont:
 	lda	sp,48(sp)
 	ret	(ra)
 .end	bn_mul_mont
+#if 0
 .rdata
 .asciiz	"Montgomery Multiplication for Alpha, CRYPTOGAMS by <[email protected]>"
+#endif
 ___
 
 print $code;

Attachment: signature.asc
Description: PGP signature

Reply via email to