3 This file is part of the AVR-Crypto-Lib.
4 Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de)
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 * File: avr-asm-macros.S
24 * License: GPLv3 or later
25 * Description: some macros which are quite usefull
29 //#ifndef AVR_ASM_MACROS__S__
30 //#define AVR_ASM_MACROS__S__
33 /*******************************************************************************
35 *******************************************************************************/
37 .macro push_ p1:req, p2:vararg
44 .macro pop_ p1:req, p2:vararg
51 .macro push_range from:req, to:req
54 push_range "(\from+1)",\to
58 .macro pop_range from:req, to:req
61 pop_range \from,"(\to-1)"
65 .macro stack_alloc size:req, reg1=r30, reg2=r31
66 in r0, _SFR_IO_ADDR(SREG)
67 in \reg1, _SFR_IO_ADDR(SPL)
68 in \reg2, _SFR_IO_ADDR(SPH)
71 out _SFR_IO_ADDR(SPH), \reg2
72 out _SFR_IO_ADDR(SREG), r0
73 out _SFR_IO_ADDR(SPL), \reg1
76 .macro stack_free size:req, reg1=r30, reg2=r31
77 in r0, _SFR_IO_ADDR(SREG)
78 in \reg1, _SFR_IO_ADDR(SPL)
79 in \reg2, _SFR_IO_ADDR(SPH)
82 out _SFR_IO_ADDR(SPH), \reg2
83 out _SFR_IO_ADDR(SREG), r0
84 out _SFR_IO_ADDR(SPL), \reg1
88 .macro stack_alloc_large size:req, reg1=r30, reg2=r31
89 in r0, _SFR_IO_ADDR(SREG)
90 in \reg1, _SFR_IO_ADDR(SPL)
91 in \reg2, _SFR_IO_ADDR(SPH)
92 subi \reg1, lo8(\size)
93 sbci \reg2, hi8(\size)
95 out _SFR_IO_ADDR(SPH), \reg2
96 out _SFR_IO_ADDR(SREG), r0
97 out _SFR_IO_ADDR(SPL), \reg1
100 .macro stack_free_large size:req, reg1=r30, reg2=r31
101 in r0, _SFR_IO_ADDR(SREG)
102 in \reg1, _SFR_IO_ADDR(SPL)
103 in \reg2, _SFR_IO_ADDR(SPH)
105 adiw \reg1, (\size-63)
107 out _SFR_IO_ADDR(SPH), \reg2
108 out _SFR_IO_ADDR(SREG), r0
109 out _SFR_IO_ADDR(SPL), \reg1
112 .macro stack_free_large2 size:req, reg1=r30, reg2=r31
113 in r0, _SFR_IO_ADDR(SREG)
114 in \reg1, _SFR_IO_ADDR(SPL)
115 in \reg2, _SFR_IO_ADDR(SPH)
118 adiw \reg1, (\size-63*2)
120 out _SFR_IO_ADDR(SPH), \reg2
121 out _SFR_IO_ADDR(SREG), r0
122 out _SFR_IO_ADDR(SPL), \reg1
125 .macro stack_free_large3 size:req, reg1=r30, reg2=r31
126 in r0, _SFR_IO_ADDR(SREG)
127 in \reg1, _SFR_IO_ADDR(SPL)
128 in \reg2, _SFR_IO_ADDR(SPH)
138 out _SFR_IO_ADDR(SPH), \reg2
139 out _SFR_IO_ADDR(SREG), r0
140 out _SFR_IO_ADDR(SPL), \reg1
144 /*******************************************************************************
145 * END of MACRO SECTION *
146 *******************************************************************************/
149 //#endif /* AVR_ASM_MACROS__S__ */