1
/* mc68020 rshift -- Shift right a low-level natural-number integer.
3
* Copyright (C) 1996, 1998, 2001 Free Software Foundation, Inc.
5
* This file is part of GnuPG.
7
* GnuPG is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation; either version 2 of the License, or
10
* (at your option) any later version.
12
* GnuPG 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 General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* 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.
26
* The GNU MP Library itself is published under the LGPL;
27
* however I decided to publish this code under the plain GPL.
32
#include "asm-syntax.h"
37
* mpihelp_rshift( mpi_ptr_t wp, (sp + 4)
38
* mpi_ptr_t up, (sp + 8)
39
* mpi_size_t usize, (sp + 12)
40
* unsigned cnt) (sp + 16)
50
GLOBL C_SYMBOL_NAME(mpihelp_rshift)
52
C_SYMBOL_NAME(mpihelp_rshift:)
53
PROLOG(mpihelp_rshift)
54
/* Save used registers on the stack. */
55
moveml R(d2)-R(d6)/R(a2),MEM_PREDEC(sp)
57
/* Copy the arguments to registers. */
58
movel MEM_DISP(sp,28),R(res_ptr)
59
movel MEM_DISP(sp,32),R(s_ptr)
60
movel MEM_DISP(sp,36),R(s_size)
61
movel MEM_DISP(sp,40),R(cnt)
66
cmpl R(res_ptr),R(s_ptr)
67
bls L(Rspecial) /* jump if res_ptr >= s_ptr */
68
#if (defined (__mc68020__) || defined (__NeXT__) || defined(mc68020))
69
lea MEM_INDX1(res_ptr,s_size,l,4),R(a2)
70
#else /* not mc68020 */
73
lea MEM_INDX(res_ptr,d0,l),R(a2)
76
bls L(Rspecial) /* jump if s_ptr >= res_ptr + s_size */
81
movel MEM_POSTINC(s_ptr),R(d2)
83
lsll R(d5),R(d0) /* compute carry limb */
94
movel MEM_POSTINC(s_ptr),R(d2)
98
movel R(d1),MEM_POSTINC(res_ptr)
101
movel MEM_POSTINC(s_ptr),R(d1)
105
movel R(d2),MEM_POSTINC(res_ptr)
108
dbf R(s_size),L(Roop)
109
subl #0x10000,R(s_size)
113
movel R(d1),MEM(res_ptr) /* store most significant limb */
115
/* Restore used registers from stack frame. */
116
moveml MEM_POSTINC(sp),R(d2)-R(d6)/R(a2)
119
/* We loop from most significant end of the arrays, which is only
120
permissable if the source and destination don't overlap, since the
121
function is documented to work for overlapping source and destination. */
124
#if (defined (__mc68020__) || defined (__NeXT__) || defined(mc68020))
125
lea MEM_INDX1(s_ptr,s_size,l,4),R(s_ptr)
126
lea MEM_INDX1(res_ptr,s_size,l,4),R(res_ptr)
127
#else /* not mc68000 */
128
movel R(s_size),R(d0)
130
addl R(s_size),R(s_ptr)
131
addl R(s_size),R(res_ptr)
134
clrl R(d0) /* initialize carry */
141
movel MEM_PREDEC(s_ptr),R(d2)
143
movel R(d2),MEM_PREDEC(res_ptr)
145
movel MEM_PREDEC(s_ptr),R(d2)
147
movel R(d2),MEM_PREDEC(res_ptr)
149
dbf R(s_size),L(LRoop)
150
roxrl #1,R(d0) /* save cy in msb */
151
subl #0x10000,R(s_size)
153
addl R(d0),R(d0) /* restore cy */
157
/* Restore used registers from stack frame. */
158
moveml MEM_POSTINC(sp),R(d2)-R(d6)/R(a2)
160
EPILOG(mpihelp_rshift)