avr-crypto-lib/stack_measuring.S

116 lines
2.1 KiB
ArmAsm
Raw Permalink Normal View History

2010-03-18 18:53:47 +00:00
/* stack_measuring.S */
/*
This file is part of the AVR-Crypto-Lib.
2015-02-06 02:43:31 +00:00
Copyright (C) 2006-2015 Daniel Otte (bg@nerilex.org)
2010-03-18 18:53:47 +00:00
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <avr/io.h>
.extern __brkval
.global stack_measure_init
stack_measure_init:
movw r30, r24
lds r20, __brkval
2012-09-18 04:07:04 +00:00
lds r21, __brkval + 1
2010-03-18 18:53:47 +00:00
in r0, _SFR_IO_ADDR(SREG)
cli
in r26, _SFR_IO_ADDR(SPL)
out _SFR_IO_ADDR(SREG), r0
in r27, _SFR_IO_ADDR(SPH)
2012-09-18 04:07:04 +00:00
cp r20, r26
cpc r21, r27
brlo 10f
ldi r20, lo8(__bss_end)
ldi r21, hi8(__bss_end)
cp r20, r26
cpc r21, r27
brlo 10f
ldi r21, 1
clr r20
10:
2010-03-18 18:53:47 +00:00
st Z+, r20
st Z+, r21
st Z+, r26
st Z+, r27
st Z, r22
movw r24, r26
sub r24, r20
sbc r25, r21
sbiw r24, 1
st X, r22
2012-09-18 04:07:04 +00:00
50: st -X, r22
2010-03-18 18:53:47 +00:00
sbiw r24, 1
2012-09-18 04:07:04 +00:00
brne 50b
2010-03-18 18:53:47 +00:00
ret
.global stack_measure_final
stack_measure_final:
movw r30, r24
lds r20, __brkval
2012-09-18 04:07:04 +00:00
lds r21, __brkval + 1
2010-03-18 18:53:47 +00:00
ld r26, Z+
ld r27, Z+
2012-09-18 04:07:04 +00:00
2010-03-18 18:53:47 +00:00
cp r20, r26
cpc r21, r27
2012-09-18 04:07:04 +00:00
brlo 10f
ldi r20, lo8(__bss_end)
ldi r21, hi8(__bss_end)
cp r20, r26
cpc r21, r27
brlo 10f
ldi r21, 1
clr r20
10:
2010-03-18 18:53:47 +00:00
adiw r26, 1
ld r24, Z+
ld r25, Z+
ld r22, Z
sub r24, r26
sbc r25, r27
adiw r24, 2
1:
sbiw r24, 1
breq 2f
ld r20, X+
cpse r20, r22
2: ret
rjmp 1b
/* for testing only
.global stack_measure_usestack
stack_measure_usestack:
adiw r24, 0
brne 2f
1: ret
2:
in r0, _SFR_IO_ADDR(SREG)
cli
in r26, _SFR_IO_ADDR(SPL)
out _SFR_IO_ADDR(SREG), r0
in r27, _SFR_IO_ADDR(SPH)
st X, r22
sbiw r24, 1
breq 1b
3: st -X, r22
sbiw r24, 1
breq 1b
rjmp 3b
*/