2 * crt0_cygmon.S -- Minimal startup file for MIPS targets running Cygmon.
4 * Copyright (c) 1995, 1996, 1997, 2000 Red Hat, Inc.
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
18 * This file contains the minimal startup code necessary.
19 * This will not do any hardware initialization. It is assumed that we are talking to Cygmon
20 * and therefore the hardware will be initialized properly.
24 /* This file contains 32 bit assembly code. */
31 * Set up some room for a stack. We just grab a chunk of memory.
33 #define STACK_SIZE 0x4000
34 #define GLOBAL_SIZE 0x2000
36 #define STARTUP_STACK_SIZE 0x0100
39 .comm __lstack, STARTUP_STACK_SIZE
45 * Without the following nop, GDB thinks _start is a data variable.
46 * This is probably a bug in GDB in handling a symbol that is at the
47 * start of the .text section.
55 la gp, _gp # set the global data pointer, defined in the linker script
59 * zero out the bss section.
62 .globl get_mem_info .text
66 la v0, _fbss # These variables are defined in the linker script
72 addiu v0, v0, 4 # executed in delay slot
75 * Setup a small stack so we can run some C code,
76 * and get the usable memory size.
79 addiu sp, t0, STARTUP_STACK_SIZE
85 * Setup the stack pointer --
86 * get_mem_info returns the top of memory, so just use that In
87 * addition, we must subtract 24 bytes for the 3 8 byte
88 * arguments to main, in case main wants to write them back to
89 * the stack. The caller is supposed to allocate stack space
90 * for parameters in registers in the old MIPS ABIs. We must
91 * do this even though we aren't passing arguments, because
92 * main might be declared to have them.
93 * Some ports need a larger alignment for the stack, so we
94 * subtract 32, which satisifes the stack for the arguments and
95 * keeps the stack pointer better aligned.
100 sw sp, __stackbase # keep this for future ref
104 * initialize target specific stuff. Only execute these
105 * functions it they exist.
107 .globl hardware_init_hook .text
108 .globl software_init_hook .text
109 .globl __do_global_dtors .text
115 la t9, hardware_init_hook # init the hardware if needed
121 la t9, software_init_hook # init the software if needed
127 la a0, __do_global_dtors
140 move a0,zero # set argc to 0
141 jal main # call the program start function
144 # fall through to the "exit" routine
145 jal exit # call libc exit to run the G++
147 move a0, v0 # pass through the exit code
151 * _exit -- Exit from the application. Normally we cause a user trap
152 * to return to the ROM monitor for another run. NOTE: This is
153 * the only other routine we provide in the crt0.o object, since
154 * it may be tied to the "_start" routine. It also allows
155 * executables that contain a complete world to be linked with
156 * just the crt0.o object.
166 # Cygmon expects a break 5
169 b 7b # loop back just in-case