1 ##############################################################################
2 # crt0.s -- CR16 default start-up routine #
4 # Copyright (c) 2004 National Semiconductor Corporation #
6 # The authors hereby grant permission to use, copy, modify, distribute, #
7 # and license this software and its documentation for any purpose, provided #
8 # that existing copyright notices are retained in all copies and that this #
9 # notice is included verbatim in any distributions. No written agreement, #
10 # license, or royalty fee is required for any of the authorized uses. #
11 # Modifications to this software may be copyrighted by their authors #
12 # and need not follow the licensing terms described here, provided that #
13 # the new terms are clearly indicated on the first page of each file where #
16 # This is the start routine of your CR16 program. #
17 # It is linked with your application automatically. You can use #
18 # this routine as a template and modify it to your needs, yet this #
19 # file must be supplied for the compiler. #
20 # It is assumed that the following symbols are defined in your linker #
21 # script: __STACK_START, __ISTACK_START #
22 ##############################################################################
37 .global __ISTACK_START
41 #----------------------------------------------------------------------------#
42 # Initialize the stack pointers. The constants __STACK_START and #
43 # __ISTACK_START should be defined in the linker script. #
45 movd $__STACK_START, (sp)
47 movd $__ISTACK_START, (r1,r0)
50 #----------------------------------------------------------------------------#
51 # Initialize the default sections according to the linker script. #
53 # bal (ra), __init_bss_data
55 #----------------------------------------------------------------------#
56 # Set the Extended Dispatch bit in the CFG register. This is the #
57 # default configuration for CR16C. #
59 spr cfg, r0 # Set dispatch table width
63 #----------------------------------------------------------------------------#
66 #----------------------------------------------------------------------------#
67 # Handle global and static constructurs execution and setup #
68 # destructors to be called from exit. #
71 movd $__fini@c, (r3,r2)
74 #----------------------------------------------------------------------------#
75 # Jump to the main function in your application. #
78 movd $0, (r3,r2) # Number of arguments
79 movd $0, (r5,r4) # conatins pointer to argument string.
81 movw $0, r2 # Number of arguments
82 movd $0, (r4,r3) # conatins pointer to argument string.
86 #----------------------------------------------------------------------------#
87 # Upon returning from the main function (if it isn't an infinite loop), #
88 # jump to the exit function. The exit function is located in the #
92 movd (r1,r0), (r3,r2) # _main return value gets forwarded.
94 movw r0, r2 # _main return value gets forwarded.
96 br _exit # returns control to the functional simulator.