struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / device / lib / pic16 / startup / crt0.c
blobec08ca69c7c40c05313eca6a3cfb341705d0bf3d
1 /*-------------------------------------------------------------------------
2 crt0.c - SDCC pic16 port runtime start code
4 Copyright (C) 2004, Vangelis Rokas <vrokas at otenet.gr>
6 This library is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
9 later version.
11 This library 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 library; see the file COPYING. If not, write to the
18 Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
19 MA 02110-1301, USA.
21 As a special exception, if you link this library with other files,
22 some of which are compiled with SDCC, to produce an executable,
23 this library does not by itself cause the resulting executable to
24 be covered by the GNU General Public License. This exception does
25 not however invalidate any other reasons why the executable file
26 might be covered by the GNU General Public License.
27 -------------------------------------------------------------------------*/
30 * based on Microchip MPLAB-C18 startup files
33 extern int stack_end;
34 extern int TBLPTRU;
36 /* external reference to the user's main routine */
37 extern void main (void);
39 void _entry (void) __naked __interrupt (0);
40 void _startup (void) __naked;
42 /* Access bank selector. */
43 #define a 0
47 * entry function, placed at interrupt vector 0 (RESET)
49 void
50 _entry (void) __naked __interrupt (0)
52 __asm
53 goto __startup
54 __endasm;
57 void
58 _startup (void) __naked
60 __asm
61 ; Initialize the stack pointer
62 lfsr 1, _stack_end
63 lfsr 2, _stack_end
65 ; 1st silicon does not do this on POR
66 clrf _TBLPTRU, a
68 ; Initialize the flash memory access configuration.
69 ; This is harmless for non-flash devices, so we do it on all parts.
70 bsf 0xa6, 7, a ; EECON1.EEPGD = 1, TBLPTR accesses program memory
71 bcf 0xa6, 6, a ; EECON1.CFGS = 0, TBLPTR accesses program memory
72 __endasm;
74 /* Call the main routine. */
75 main ();
77 __asm
78 lockup:
79 ; Returning from main will lock up.
80 bra lockup
81 __endasm;