Initial cut of the open ath9k htc firmware.
[open-ath9k-htc-firmware.git] / target_firmware / magpie_fw_dev / build / magpie_1_1 / sboot / athos / src / xtos / crt1-tiny.S
1 // crt1-tiny.S
2 //
3 // This is a reduced version of the code in crt1-boards.S .
4 // For most hardware / boards, this code sets up the C calling context
5 // (setting up stack, PS, and clearing BSS) and calls main().
6 // It has some limitations (see LSP Ref Manual for details) such as:
7 //      - does not setup the C library (...)
8 //      - does not call C++ static constructors and destructors
9 //      - only clears .bss , not other *.bss sections
10 //
11 // Control arrives here at _start from the reset vector or from crt0-app.S.
12
13 // Copyright (c) 1998-2010 Tensilica Inc.
14 //
15 // Permission is hereby granted, free of charge, to any person obtaining
16 // a copy of this software and associated documentation files (the
17 // "Software"), to deal in the Software without restriction, including
18 // without limitation the rights to use, copy, modify, merge, publish,
19 // distribute, sublicense, and/or sell copies of the Software, and to
20 // permit persons to whom the Software is furnished to do so, subject to
21 // the following conditions:
22 //
23 // The above copyright notice and this permission notice shall be included
24 // in all copies or substantial portions of the Software.
25 //
26 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
29 // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
30 // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
31 // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
32 // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33
34 #include <xtensa/coreasm.h>
35
36
37 // Imports
38 //      __stack                 from linker script (see LSP Ref Manual)
39 //      _bss_start              from linker script (see LSP Ref Manual)
40 //      _bss_end                from linker script (see LSP Ref Manual)
41 //      main                    from user application
42
43
44
45 #ifdef __XTENSA_CALL0_ABI__
46 # define CALL           call0
47 #else
48 # define CALL           call4
49 #endif
50
51
52 /**************************************************************************/
53
54         .text
55         .global _start
56 _start:
57         //  _start is typically NOT at the beginning of the text segment --
58         //  it is always called from either the reset vector or other code
59         //  that does equivalent initialization (such as crt0-app.S).
60         //  See crt1-boards.S for assumptions on entry to _start ,
61         //  and for comments on what is being done in this file.
62
63 #if !XCHAL_HAVE_HALT || !XCHAL_HAVE_BOOTLOADER          // not needed for Xtensa TX
64         movi    a0, 0           // mark base of call stack
65 #endif
66
67         movi    sp, __stack     // setup the stack
68
69 #if XCHAL_HAVE_EXCEPTIONS
70 # ifdef __XTENSA_CALL0_ABI__
71         movi    a3, PS_UM               // PS:  WOE=0, UM=1, EXCM=0, INTLEVEL=0
72 # else  
73         movi    a3, PS_UM|PS_WOE        // PS:  WOE=1, UM=1, EXCM=0, INTLEVEL=0
74 # endif
75         wsr     a3, PS                  // setup PS for the application
76         rsync
77 #endif
78
79
80         // Clear the BSS (uninitialized data) segment.
81         //
82         // This code only supports .bss, not multiple *.bss sections.
83         // Corresponding code in crt1-boards.S does, and is faster but bigger.
84
85 #if !XCHAL_HAVE_BOOTLOADER
86         movi    a6, _bss_start
87         movi    a7, _bss_end
88         bgeu    a6, a7, 2f
89 1:      s32i    a0, a6, 0
90         addi    a6, a6, 4
91         bltu    a6, a7, 1b
92 2:
93 #endif
94
95         //  We can now call C code, the C calling environment is initialized.
96         //  This tiny C runtime assumes main is declared as "void main(void)"
97         //  rather than with the usual argc,argv.  So there are no arguments.
98
99         CALL    main
100
101         //  In this tiny C runtime, main() is not expected to return.
102         //  If it does, just loop forever.
103
104         //CALL  xthal_dcache_all_writeback      // sync dirty dcaches to memory
105         //extw                  // sync TIE queues/ports/etc (LX or later only)
106
107 .L0:
108 #if XCHAL_HAVE_DEBUG
109         break   1, 15           // give control to debugger
110 #elif XCHAL_HAVE_HALT
111         halt
112 #endif
113         j       .L0
114
115         .size   _start, . - _start
116
117
118 // Local Variables:
119 // mode:fundamental
120 // comment-start: "// "
121 // comment-start-skip: "// *"
122 // End: