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
11 // Control arrives here at _start from the reset vector or from crt0-app.S.
13 // Copyright (c) 1998-2010 Tensilica Inc.
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:
23 // The above copyright notice and this permission notice shall be included
24 // in all copies or substantial portions of the Software.
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.
34 #include <xtensa/coreasm.h>
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
45 #ifdef __XTENSA_CALL0_ABI__
52 /**************************************************************************/
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.
63 #if !XCHAL_HAVE_HALT || !XCHAL_HAVE_BOOTLOADER // not needed for Xtensa TX
64 movi a0, 0 // mark base of call stack
67 movi sp, __stack // setup the stack
69 #if XCHAL_HAVE_EXCEPTIONS
70 # ifdef __XTENSA_CALL0_ABI__
71 movi a3, PS_UM // PS: WOE=0, UM=1, EXCM=0, INTLEVEL=0
73 movi a3, PS_UM|PS_WOE // PS: WOE=1, UM=1, EXCM=0, INTLEVEL=0
75 wsr a3, PS // setup PS for the application
80 // Clear the BSS (uninitialized data) segment.
82 // This code only supports .bss, not multiple *.bss sections.
83 // Corresponding code in crt1-boards.S does, and is faster but bigger.
85 #if !XCHAL_HAVE_BOOTLOADER
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.
101 // In this tiny C runtime, main() is not expected to return.
102 // If it does, just loop forever.
104 //CALL xthal_dcache_all_writeback // sync dirty dcaches to memory
105 //extw // sync TIE queues/ports/etc (LX or later only)
109 break 1, 15 // give control to debugger
110 #elif XCHAL_HAVE_HALT
115 .size _start, . - _start
120 // comment-start: "// "
121 // comment-start-skip: "// *"