newlib: Regenerate autotools files
[newlib-cygwin.git] / libgloss / cr16 / crt1.S
blobeee6fc10b7538a0698c61ee2df2c60404046cd7e
1  ##############################################################################
2  # crt0.s -- CR16 default start-up routine                                    #
3  #                                                                            #
4  # Copyright (c) 2004 National Semiconductor Corporation                      #
5  #                                                                            #
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   #
14  # they apply.                                                                #
15  #                                                                            #
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  ##############################################################################
24         .text
25 #ifdef __CR16CP__
26         .align 4
27 #else
28         .align 2
29 #endif
30         .global _main
31         .global _atexit
32         .global _exit
33         .global _start
34         .global __fini
35         .global __init
36         .global __STACK_START
37         .global __ISTACK_START
39 _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)
48         lprd    (r1,r0), isp
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
60         orw     $0x100, r0
61         lpr     r0, cfg
63  #----------------------------------------------------------------------------#
66  #----------------------------------------------------------------------------#
67  # Handle global and static constructurs execution and setup                  #
68  # destructors to be called from exit.                                        #
70         bal     (ra),__init
71         movd    $__fini@c, (r3,r2)
72         bal     (ra), _atexit
74  #----------------------------------------------------------------------------#
75  # Jump to the main function in your application.                             #
77 #ifdef __INT32__
78         movd    $0, (r3,r2) # Number of arguments
79         movd    $0, (r5,r4) # conatins pointer to argument string.
80 #else
81         movw    $0, r2      # Number of arguments
82         movd    $0, (r4,r3) # conatins pointer to argument string.
83 #endif
84         bal             (ra), _main
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             #
89  # library 'libc.a'.                                                          #
91 #ifdef __INT32__
92         movd    (r1,r0), (r3,r2) # _main return value gets forwarded.
93 #else
94         movw    r0, r2          # _main return value gets forwarded.
95 #endif
96         br              _exit           # returns control to the functional simulator.