2 * crt0_cfe.S -- Runtime startup for MIPS targets running CFE.
5 * Broadcom Corporation. All rights reserved.
7 * This software is furnished under license and may be used and copied only
8 * in accordance with the following terms and conditions. Subject to these
9 * conditions, you may download, copy, install, use, modify and distribute
10 * modified or unmodified copies of this software in source and/or binary
11 * form. No title or ownership is transferred hereby.
13 * 1) Any source code used, modified or distributed must reproduce and
14 * retain this copyright notice and list of conditions as they appear in
17 * 2) No right is granted to use any trade name, trademark, or logo of
18 * Broadcom Corporation. The "Broadcom Corporation" name may not be
19 * used to endorse or promote products derived from this software
20 * without the prior written permission of Broadcom Corporation.
22 * 3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR IMPLIED
23 * WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED WARRANTIES OF
24 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
25 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL BROADCOM BE LIABLE
26 * FOR ANY DAMAGES WHATSOEVER, AND IN PARTICULAR, BROADCOM SHALL NOT BE
27 * LIABLE FOR DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
30 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
31 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
32 * OR OTHERWISE), EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 * Derived from crt0_cygmon.S:
38 * Copyright (c) 1995, 1996, 1997, 2000 Red Hat, Inc.
40 * The authors hereby grant permission to use, copy, modify, distribute,
41 * and license this software and its documentation for any purpose, provided
42 * that existing copyright notices are retained in all copies and that this
43 * notice is included verbatim in any distributions. No written agreement,
44 * license, or royalty fee is required for any of the authorized uses.
45 * Modifications to this software may be copyrighted by their authors
46 * and need not follow the licensing terms described here, provided that
47 * the new terms are clearly indicated on the first page of each file where
52 * This file does minimal runtime startup for code running under
55 * It does minimal hardware initialization. In particular
56 * it sets Status:FR to match the requested floating point
59 * It is meant to be linked with the other files provided by libcfe.a,
60 * and calls routines in those files.
64 /* This file contains 32 bit assembly code. */
67 #ifdef __mips_embedded_pic
68 # error -membedded-pic is not supported.
74 * Set up some room for a stack. We just grab a chunk of memory.
76 #define STARTUP_STACK_SIZE (1 * 1024)
78 .comm _lstack, STARTUP_STACK_SIZE
84 * Without the following nop, GDB thinks _start is a data variable.
85 * This is probably a bug in GDB in handling a symbol that is at the
86 * start of the .text section.
92 * On entry, the following values have been passed in registers
97 * a2: firmware callback entrypoint
98 * a3: CFE entrypoint seal (unused)
100 * They must be preserved until the CFE entrypoint and handle
101 * are passed to __libcfe_init().
108 /* Set the global data pointer, defined in the linker script. */
111 #ifndef __mips_soft_float
112 /* If compiled for hard float, set the FPU mode based on the
113 compilation flags. Note that this assumes that enough code
114 will run after the mtc0 to clear any hazards. */
116 or t0, t0, (SR_CU1 | SR_FR)
117 #if (__mips_fpr == 32)
118 xor t0, t0, SR_FR /* If 32-bit FP mode, clear FR. */
125 * zero out the bss section.
130 /* These variables are defined in the linker script. */
137 addiu v0, v0, 4 /* Delay slot. */
141 * Setup a small stack so we can run some C code, and do
142 * the library initialization. (32 bytes are saved for
143 * the argument registers' stack slots.)
149 addiu sp, t0, (STARTUP_STACK_SIZE - 32)
154 * Setup the stack pointer --
155 * __libcfe_init() returns the value to be used as the top of
156 * the program's stack.
158 * We subtract 32 bytes for the 4 argument registers, in case
159 * main() wants to write them back to the stack. The caller
160 * allocates stack space for parameters in the old MIPS ABIs.
161 * We must do this even though we aren't passing arguments,
162 * because main might be declared to have them.)
164 * We subtract 32 more bytes for the argv/envp setup for the
173 * initialize target specific stuff. Only execute these
174 * functions it they exist.
176 .globl hardware_init_hook .text
177 .globl software_init_hook .text
178 .type _fini,@function
179 .type _init,@function
185 la t9, hardware_init_hook # init the hardware if needed
191 la t9, software_init_hook # init the software if needed
210 jal _init # run global constructors
213 addiu a1,sp,32 # argv = sp + 32
214 addiu a2,sp,40 # envp = sp + 40
216 sd zero,(a1) # argv[argc] = 0
217 sd zero,(a2) # envp[0] = 0
223 jal main # call the program start function
224 move a0,zero # set argc to 0; delay slot.
226 # fall through to the "exit" routine
227 jal exit # call libc exit to run the G++
229 move a0, v0 # pass through the exit code
233 * _exit -- Exit from the application. This is provided in this file because
234 * program exit should shut down profiling (if GCRT0 is defined),
235 * and only this file is compiled with GCRT0 defined.
241 move s0, a0 /* Save in case we loop. */
248 la t0, hardware_exit_hook
255 /* Call into the library to do the heavy lifting. */
257 move a0, s0 /* Delay slot. */
259 b 7b /* Loop back just in case. */