1 /*-------------------------------------------------------------------------
3 gstack.c :- debug stack tracing support function
5 Written for pic16 port by Vangelis Rokas, 2004 (vrokas@otenet.gr)
7 This library is free software; you can redistribute it and/or modify it
8 under the terms of the GNU Library General Public License as published by the
9 Free Software Foundation; either version 2, or (at your option) any
12 This library 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 Library General Public License for more details.
17 You should have received a copy of the GNU Library General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 In other words, you are welcome to use, share and improve this program.
22 You are forbidden to forbid anyone else to use, share and improve
23 what you give them. Help stamp out software-hoarding!
24 -------------------------------------------------------------------------*/
26 ** $Id: gstack.c 3835 2005-08-07 20:09:11Z tecodev $
47 #pragma udata access _wreg_store _status_store _fsr0_store
48 #pragma udata access _gstack_begin _gstack_end _init_ok
50 static char _init_ok=0;
51 static char _wreg_store;
52 static char _status_store;
53 static unsigned int _fsr0_store;
54 static unsigned int _gstack_begin;
55 static unsigned int _gstack_end;
57 char _gstack_fail_str[]="Stack overflow\n";
58 char _gstack_succ_str[]="Stack ok\n";
62 void _gstack_overflow_default(void) __naked
65 lfsr 0, __gstack_fail_str
80 void (* _gstack_overflow)(void)=_gstack_overflow_default;
83 void _gstack_init(void) __naked
91 movwf __gstack_begin+1
96 movlw HIGH(_stack_end)
99 ; load default handler
100 ; movlw LOW(__gstack_overflow_default)
101 ; movwf __gstack_overflow
103 ; movlw HIGH(__gstack_overflow_default)
104 ; movwf __gstack_overflow+1
106 ; movlw UPPER(__gstack_overflow_default)
107 ; movwf __gstack_overflow+2
118 void _gstack_test(void) __naked
121 movff _WREG, __wreg_store
122 movff _STATUS, __status_store
124 ; if first time, initialize boundary variables
130 movf __gstack_begin, w
136 movf __gstack_begin+1, w
148 movf __gstack_end+1, w
166 movff __gstack_overflow+2, _PCLATU
167 movff __gstack_overflow+1, _PCLATH
168 movf __gstack_overflow, w
178 movff _FSR0L, __fsr0_store
179 movff _FSR0H, __fsr0_store+1
180 lfsr 0, __gstack_succ_str
182 ; print corresponding string
189 movff __fsr0_store+1, _FSR0H
190 movff __fsr0_store, _FSR0L
193 movff __status_store, _STATUS
194 movff __wreg_store, _WREG