1#!/usr/bin/env perl
2
3$flavour = shift;
4
5$0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
6( $xlate="${dir}ppc-xlate.pl" and -f $xlate ) or
7( $xlate="${dir}perlasm/ppc-xlate.pl" and -f $xlate) or
8die "can't locate ppc-xlate.pl";
9
10open STDOUT,"| $^X $xlate $flavour ".shift || die "can't call $xlate: $!";
11
12if ($flavour=~/64/) {
13    $CMPLI="cmpldi";
14    $SHRLI="srdi";
15    $SIGNX="extsw";
16} else {
17    $CMPLI="cmplwi";
18    $SHRLI="srwi";
19    $SIGNX="mr";
20}
21
22$code=<<___;
23.machine	"any"
24.text
25
26.globl	.OPENSSL_cpuid_setup
27.align	4
28.OPENSSL_cpuid_setup:
29	blr
30
31.globl	.OPENSSL_wipe_cpu
32.align	4
33.OPENSSL_wipe_cpu:
34	xor	r0,r0,r0
35	mr	r3,r1
36	xor	r4,r4,r4
37	xor	r5,r5,r5
38	xor	r6,r6,r6
39	xor	r7,r7,r7
40	xor	r8,r8,r8
41	xor	r9,r9,r9
42	xor	r10,r10,r10
43	xor	r11,r11,r11
44	xor	r12,r12,r12
45	blr
46
47.globl	.OPENSSL_atomic_add
48.align	4
49.OPENSSL_atomic_add:
50Loop:	lwarx	r5,0,r3
51	add	r0,r4,r5
52	stwcx.	r0,0,r3
53	bne-	Loop
54	$SIGNX	r3,r0
55	blr
56
57.globl	.OPENSSL_rdtsc
58.align	4
59.OPENSSL_rdtsc:
60	mftb	r3
61	mftbu	r4
62	blr
63
64.globl	.OPENSSL_cleanse
65.align	4
66.OPENSSL_cleanse:
67	$CMPLI	r4,7
68	li	r0,0
69	bge	Lot
70	$CMPLI	r4,0
71	beqlr-
72Little:	mtctr	r4
73	stb	r0,0(r3)
74	addi	r3,r3,1
75	bdnz-	\$-8
76	blr
77Lot:	andi.	r5,r3,3
78	beq	Laligned
79	stb	r0,0(r3)
80	subi	r4,r4,1
81	addi	r3,r3,1
82	b	Lot
83Laligned:
84	$SHRLI	r5,r4,2
85	mtctr	r5
86	stw	r0,0(r3)
87	addi	r3,r3,4
88	bdnz-	\$-8
89	andi.	r4,r4,3
90	bne	Little
91	blr
92___
93
94$code =~ s/\`([^\`]*)\`/eval $1/gem;
95print $code;
96close STDOUT;
97