]> git.cryptolib.org Git - avr-crypto-lib.git/blob - stack_measuring.S
Bug in TDES fixed
[avr-crypto-lib.git] / stack_measuring.S
1 /* stack_measuring.S */
2 /*
3     This file is part of the AVR-Crypto-Lib.
4     Copyright (C) 2010 Daniel Otte (daniel.otte@rub.de)
5
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.
10
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.
15
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/>.
18 */
19
20 #include <avr/io.h>
21
22 .extern __brkval
23
24 .global stack_measure_init
25 stack_measure_init:
26         movw r30, r24
27         lds r20, __brkval
28         lds r21, __brkval+1
29         in r0, _SFR_IO_ADDR(SREG)
30         cli
31         in r26, _SFR_IO_ADDR(SPL)
32         out _SFR_IO_ADDR(SREG), r0
33         in r27, _SFR_IO_ADDR(SPH)
34         st Z+, r20
35         st Z+, r21
36         st Z+, r26
37         st Z+, r27
38         st Z, r22
39         movw r24, r26
40         sub r24, r20
41         sbc r25, r21
42         sbiw r24, 1
43         st X, r22
44 1:  st -X, r22
45         sbiw r24, 1
46         brne 1b
47         ret
48
49 .global stack_measure_final
50 stack_measure_final:
51         movw r30, r24
52         lds r20, __brkval
53         lds r21, __brkval+1
54         ld r26, Z+
55         ld r27, Z+
56         cp r20, r26
57         cpc r21, r27
58         brlo 1f
59         movw r26, r20
60 1:
61         adiw r26, 1
62         ld r24, Z+
63         ld r25, Z+
64         ld r22, Z
65         sub r24, r26
66         sbc r25, r27
67         adiw r24, 2
68 1:
69         sbiw r24, 1
70         breq 2f
71         ld r20, X+
72         cpse r20, r22
73 2:  ret
74         rjmp 1b
75
76 /* for testing only
77 .global stack_measure_usestack
78 stack_measure_usestack:
79         adiw r24, 0
80         brne 2f
81 1:      ret
82 2:
83         in r0, _SFR_IO_ADDR(SREG)
84         cli
85         in r26, _SFR_IO_ADDR(SPL)
86         out _SFR_IO_ADDR(SREG), r0
87         in r27, _SFR_IO_ADDR(SPH)
88     st X, r22
89         sbiw r24, 1
90         breq 1b
91 3:  st -X, r22
92         sbiw r24, 1
93         breq 1b
94         rjmp 3b
95
96         */