* device/lib/Makefile.in: removed comment line with model-pic16,
[fw/sdcc] / device / lib / pic16 / startup / crt0.c
1 /*
2  * crt0.c - SDCC pic16 port runtime start code
3  *
4  * Converted for SDCC and pic16 port
5  * by Vangelis Rokas (vrokas@otenet.gr)
6  *
7  * based on Microchip MPLAB-C18 startup files
8  *
9  * $Id$
10  */
11
12 extern stack;
13
14 extern TBLPTRU;
15
16 /* external reference to the user's main routine */
17 extern void main (void);
18
19 /* prototype for the startup function */
20 void _entry (void) _naked interrupt 0;
21 void _startup (void);
22
23
24 /*
25  * entry function, placed at interrupt vector 0 (RESET)
26  */
27
28 void _entry (void) _naked interrupt 0
29 {
30   _asm goto __startup _endasm;
31 }
32
33
34 void _startup (void)
35 {
36         _asm
37                 // Initialize the stack pointer
38                 lfsr 1, _stack
39                 lfsr 2, _stack
40                 clrf _TBLPTRU, 0        // 1st silicon doesn't do this on POR
41     
42                 // initialize the flash memory access configuration. this is harmless
43                 // for non-flash devices, so we do it on all parts.
44                 bsf 0xa6, 7, 0
45                 bcf 0xa6, 6, 0
46
47         _endasm ;
48     
49         /* Call the user's main routine */
50         main ();
51
52 loop:
53         /* return from main will lock up */
54         goto loop;
55 }
56