[444] | 1 | /* (C) Copyright IBM Corp. 2005, 2006 |
---|
| 2 | All rights reserved. |
---|
| 3 | |
---|
| 4 | Redistribution and use in source and binary forms, with or without |
---|
| 5 | modification, are permitted provided that the following conditions are met: |
---|
| 6 | |
---|
| 7 | * Redistributions of source code must retain the above copyright notice, |
---|
| 8 | this list of conditions and the following disclaimer. |
---|
| 9 | * Redistributions in binary form must reproduce the above copyright |
---|
| 10 | notice, this list of conditions and the following disclaimer in the |
---|
| 11 | documentation and/or other materials provided with the distribution. |
---|
| 12 | * Neither the name of IBM nor the names of its contributors may be |
---|
| 13 | used to endorse or promote products derived from this software without |
---|
| 14 | specific prior written permission. |
---|
| 15 | |
---|
| 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
| 17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
| 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
| 19 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
---|
| 20 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
| 21 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
| 22 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
| 23 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
| 24 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
| 25 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
---|
| 26 | POSSIBILITY OF SUCH DAMAGE. |
---|
| 27 | */ |
---|
| 28 | |
---|
| 29 | /* crt0.S - entry function for C Runtime. |
---|
| 30 | * |
---|
| 31 | * With _STD_MAIN switch, the crt0.S will be compiled to crt2.o. |
---|
| 32 | * The crt2.o sets up a C99-style interface for the SPU application's |
---|
| 33 | * main() function, including a local copy of argv strings. |
---|
| 34 | * |
---|
| 35 | * The number of argument strings is passed in R3. The size and EA |
---|
| 36 | * location of the argument vector region is passed in R4. Once the |
---|
| 37 | * argv region is copied to the highest range of LS, and $SP is set |
---|
| 38 | * just below it. |
---|
| 39 | * |
---|
| 40 | * Without _STD_MAIN, the crt0.S is compiled to crt1.o. |
---|
| 41 | * The crt1.o prepares the entry for an SPU module. The main() function |
---|
| 42 | * is called with different parameter list: spu_id, param and env |
---|
| 43 | * are passed by R3, R4 and R5 respectively. |
---|
| 44 | */ |
---|
| 45 | |
---|
| 46 | #ifdef _STD_MAIN |
---|
| 47 | #define MFC_TAG_UPDATE_ALL 2 |
---|
| 48 | #define MFC_GET_CMD 0x40 |
---|
| 49 | #define TAGID 0 |
---|
| 50 | #define TAGMASK 1 |
---|
| 51 | #endif |
---|
| 52 | |
---|
| 53 | .comm __ea_local_store,16,16 |
---|
| 54 | |
---|
| 55 | .text |
---|
| 56 | .global _start |
---|
| 57 | .type _start, @function |
---|
| 58 | |
---|
| 59 | _start: |
---|
| 60 | /* Save the local store base from $6. */ |
---|
| 61 | stqr $6, __ea_local_store |
---|
| 62 | |
---|
| 63 | #ifdef _STD_MAIN |
---|
| 64 | /* |
---|
| 65 | * Copy the argument vector region from EA to LS. The DMA |
---|
| 66 | * parameters are passed in R4: |
---|
| 67 | * |
---|
| 68 | * +-------+-------+-------+-------+ |
---|
| 69 | * R4 | LS | EA-HI | EA-LO | SIZE | |
---|
| 70 | * +-------+-------+-------+-------+ |
---|
| 71 | * word 0 1 2 3 |
---|
| 72 | * |
---|
| 73 | * By the end of this sequence, the prefered slot (word 0) of |
---|
| 74 | * R4 will contain the LS offset of argv region, which also |
---|
| 75 | * serves as the base offset for $SP. |
---|
| 76 | */ |
---|
| 77 | wrch $MFC_LSA, $4 |
---|
| 78 | rotqbyi $4, $4, 4 |
---|
| 79 | wrch $MFC_EAH, $4 |
---|
| 80 | rotqbyi $4, $4, 4 |
---|
| 81 | wrch $MFC_EAL, $4 |
---|
| 82 | rotqbyi $4, $4, 4 |
---|
| 83 | wrch $MFC_Size, $4 |
---|
| 84 | rotqbyi $4, $4, 4 |
---|
| 85 | il $LR, TAGID |
---|
| 86 | wrch $MFC_TagID, $LR |
---|
| 87 | |
---|
| 88 | /* Issue MFC_GET_CMD, then wait for transfer of argument |
---|
| 89 | * vector region to complete. |
---|
| 90 | */ |
---|
| 91 | il $LR, MFC_GET_CMD |
---|
| 92 | wrch $MFC_Cmd, $LR |
---|
| 93 | il $LR, TAGMASK |
---|
| 94 | wrch $MFC_WrTagMask, $LR |
---|
| 95 | il $LR, MFC_TAG_UPDATE_ALL |
---|
| 96 | wrch $MFC_WrTagUpdate, $LR |
---|
| 97 | rdch $LR, $MFC_RdTagStat |
---|
| 98 | #endif |
---|
| 99 | |
---|
| 100 | /* Save parameter list of main function to the non-volatile |
---|
| 101 | * registers. spu_thread module has three parameters, while |
---|
| 102 | * spulet only has two. |
---|
| 103 | */ |
---|
| 104 | ori $80, $3, 0 |
---|
| 105 | ori $81, $4, 0 |
---|
| 106 | #ifndef _STD_MAIN |
---|
| 107 | ori $82, $5, 0 |
---|
| 108 | #endif |
---|
| 109 | |
---|
| 110 | /* The Link Register is initialized to NULL. |
---|
| 111 | */ |
---|
| 112 | il $LR, 0 |
---|
| 113 | |
---|
| 114 | #ifdef _STD_MAIN |
---|
| 115 | /* For spulet, initialize stack pointer just below the argv region. |
---|
| 116 | */ |
---|
| 117 | ai $SP,$4,-16 |
---|
| 118 | #else |
---|
| 119 | /* For spe_thread module, the stack pointer is initialized |
---|
| 120 | * below the area where __stack points to. |
---|
| 121 | */ |
---|
| 122 | ila $SP,__stack |
---|
| 123 | #endif |
---|
| 124 | /* Initialize back chain to NULL. |
---|
| 125 | */ |
---|
| 126 | stqd $LR,0($SP) |
---|
| 127 | |
---|
| 128 | /* Allocate 2 slots for stack frame. |
---|
| 129 | */ |
---|
| 130 | stqd $SP,-32($SP) |
---|
| 131 | ai $SP,$SP,-32 |
---|
| 132 | |
---|
| 133 | /* Save the Link Register in Link Register Save Area. |
---|
| 134 | */ |
---|
| 135 | stqd $LR,16($SP) |
---|
| 136 | |
---|
| 137 | /* Calculate stack size. |
---|
| 138 | */ |
---|
| 139 | ila $3,_end |
---|
| 140 | sf $3,$3,$SP |
---|
| 141 | rotqbyi $3,$3,12 |
---|
| 142 | |
---|
| 143 | /* The BE Linux ABI passes the stack size in $2, or use |
---|
| 144 | * the default if $2 == 0. |
---|
| 145 | */ |
---|
| 146 | rotqbyi $4,$2,12 |
---|
| 147 | ceqi $5,$4,0 |
---|
| 148 | selb $3,$4,$3,$5 |
---|
| 149 | fsmbi $4,3840 |
---|
| 150 | selb $SP,$SP,$3,$4 |
---|
| 151 | |
---|
| 152 | /* Call the _init function. |
---|
| 153 | */ |
---|
| 154 | brsl $LR, _init |
---|
| 155 | |
---|
| 156 | /* Call the _fini function at exit time. |
---|
| 157 | */ |
---|
| 158 | ila $3, _fini |
---|
| 159 | brsl $LR, atexit |
---|
| 160 | |
---|
| 161 | #ifdef _PROFILE |
---|
| 162 | /* Call monstartup if profiling is enabled |
---|
| 163 | */ |
---|
| 164 | #ifdef _STD_MAIN |
---|
| 165 | ila $3,0 |
---|
| 166 | #else |
---|
| 167 | ori $3,$80,0 |
---|
| 168 | #endif |
---|
| 169 | brsl $LR, __monstartup |
---|
| 170 | #endif |
---|
| 171 | ori $3,$80,0 |
---|
| 172 | ori $4,$81,0 |
---|
| 173 | #ifndef _STD_MAIN |
---|
| 174 | ori $5,$82,0 |
---|
| 175 | #endif |
---|
| 176 | |
---|
| 177 | /* Call the programs main. |
---|
| 178 | */ |
---|
| 179 | brsl $LR, main |
---|
| 180 | |
---|
| 181 | /* Call exit. |
---|
| 182 | */ |
---|
| 183 | brsl $LR, exit |
---|
| 184 | |
---|