1
/* mc68020 rshift -- Shift right a low-level natural-number integer.
3
* Copyright (C) 1996, 1998, 2001, 2002 Free Software Foundation, Inc.
5
* This file is part of Libgcrypt.
7
* Libgcrypt is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU Lesser General Public License as
9
* published by the Free Software Foundation; either version 2.1 of
10
* the License, or (at your option) any later version.
12
* Libgcrypt is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU Lesser General Public License for more details.
17
* You should have received a copy of the GNU Lesser General Public
18
* License along with this program; if not, write to the Free Software
19
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
21
* Note: This code is heavily based on the GNU MP Library.
22
* Actually it's the same code with only minor changes in the
23
* way the data is stored; this is to support the abstraction
24
* of an optional secure memory allocation which may be used
25
* to avoid revealing of sensitive data due to paging etc.
30
#include "asm-syntax.h"
35
* _gcry_mpih_rshift( mpi_ptr_t wp, (sp + 4)
36
* mpi_ptr_t up, (sp + 8)
37
* mpi_size_t usize, (sp + 12)
38
* unsigned cnt) (sp + 16)
48
GLOBL C_SYMBOL_NAME(_gcry_mpih_rshift)
50
C_SYMBOL_NAME(_gcry_mpih_rshift:)
51
PROLOG(_gcry_mpih_rshift)
52
/* Save used registers on the stack. */
53
moveml R(d2)-R(d6)/R(a2),MEM_PREDEC(sp)
55
/* Copy the arguments to registers. */
56
movel MEM_DISP(sp,28),R(res_ptr)
57
movel MEM_DISP(sp,32),R(s_ptr)
58
movel MEM_DISP(sp,36),R(s_size)
59
movel MEM_DISP(sp,40),R(cnt)
64
cmpl R(res_ptr),R(s_ptr)
65
bls L(Rspecial) /* jump if res_ptr >= s_ptr */
66
#if (defined (__mc68020__) || defined (__NeXT__) || defined(mc68020))
67
lea MEM_INDX1(res_ptr,s_size,l,4),R(a2)
68
#else /* not mc68020 */
71
lea MEM_INDX(res_ptr,d0,l),R(a2)
74
bls L(Rspecial) /* jump if s_ptr >= res_ptr + s_size */
79
movel MEM_POSTINC(s_ptr),R(d2)
81
lsll R(d5),R(d0) /* compute carry limb */
92
movel MEM_POSTINC(s_ptr),R(d2)
96
movel R(d1),MEM_POSTINC(res_ptr)
99
movel MEM_POSTINC(s_ptr),R(d1)
103
movel R(d2),MEM_POSTINC(res_ptr)
106
dbf R(s_size),L(Roop)
107
subl #0x10000,R(s_size)
111
movel R(d1),MEM(res_ptr) /* store most significant limb */
113
/* Restore used registers from stack frame. */
114
moveml MEM_POSTINC(sp),R(d2)-R(d6)/R(a2)
117
/* We loop from most significant end of the arrays, which is only
118
permissable if the source and destination don't overlap, since the
119
function is documented to work for overlapping source and destination. */
122
#if (defined (__mc68020__) || defined (__NeXT__) || defined(mc68020))
123
lea MEM_INDX1(s_ptr,s_size,l,4),R(s_ptr)
124
lea MEM_INDX1(res_ptr,s_size,l,4),R(res_ptr)
125
#else /* not mc68000 */
126
movel R(s_size),R(d0)
128
addl R(s_size),R(s_ptr)
129
addl R(s_size),R(res_ptr)
132
clrl R(d0) /* initialize carry */
139
movel MEM_PREDEC(s_ptr),R(d2)
141
movel R(d2),MEM_PREDEC(res_ptr)
143
movel MEM_PREDEC(s_ptr),R(d2)
145
movel R(d2),MEM_PREDEC(res_ptr)
147
dbf R(s_size),L(LRoop)
148
roxrl #1,R(d0) /* save cy in msb */
149
subl #0x10000,R(s_size)
151
addl R(d0),R(d0) /* restore cy */
155
/* Restore used registers from stack frame. */
156
moveml MEM_POSTINC(sp),R(d2)-R(d6)/R(a2)
158
EPILOG(_gcry_mpih_rshift)