- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

# /space/home/slher/rel/Beken/v6_4_5/macsw/plf/refip/src/arch/tl4xx/boot/tl4/crt0.c

    00001 /*************************************************************************************
    00002 *                                                                                     *
    00003 * Copyright (C) CEVA(R) Inc. All rights reserved                                      *
    00004 *                                                                                     *
    00005 *                                                                                     *
    00006 * This product or Software is made available exclusively to licensees that have       *
    00007 * received express written authorization from CEVA to download or receive the product *
    00008 * or Software and have agreed to the End User License Agreement (EULA).  If you have  *
    00009 * not received such express authorization and agreed to the CEVA EULA, you may not    *
    00010 * download, install or use this product or Software.                                  *
    00011 *                                                                                     *
    00012 * The information contained in this document is subject to change without notice and  *
    00013 * does not represent a commitment on any part of CEVA(R), Inc. CEVA(R), Inc. and its  *
    00014 * subsidiaries make no warranty of any kind with regard to this material, including,  *
    00015 * but not limited to implied warranties of merchantability and fitness for a          *
    00016 * particular purpose whether arising out of law, custom, conduct or otherwise.        *
    00017 *                                                                                     *
    00018 * While the information contained herein is assumed to be accurate, CEVA(R), Inc.     *
    00019 * assumes no responsibility for any errors or omissions contained herein, and         *
    00020 * assumes no liability for special, direct, indirect or consequential damage,         *
    00021 * losses, costs, charges, claims, demands, fees or expenses, of any nature or kind,   *
    00022 * which are incurred in connection with the furnishing, performance or use of this    *
    00023 * material.                                                                           *
    00024 *                                                                                     *
    00025 * This document contains proprietary information, which is protected by U.S. and      *
    00026 * international copyright laws. All rights reserved. No part of this document may be  *
    00027 * reproduced, photocopied, or translated into another language without the prior      *
    00028 * written consent of CEVA(R), Inc.                                                    *
    00029 *                                                                                     *
    00030 *************************************************************************************/
    00031
    00032 #include <asm-dsp.h>
    00033
    00034 extern void initConfigRegs ();
    00035 extern void initDataSections ();
    00036 extern void crt0HookPreMain ();
    00037 extern int main(int, char **);
    00038 extern void exit();
    00039 extern void initConfigRegs();
    00040 extern void initDataSections();
    00041 extern void crt0HookPreMain();
    00042 extern void initFileIo();
    00043
    00044 extern void bpi_handler(void) __attribute__((interrupt_retb));
    00045 extern void trap_handler(void) __attribute__((interrupt_retb));
    00046 extern void nmi_handler(void) __attribute__((interrupt));
    00047 extern void int0_handler(void) __attribute__((interrupt));
    00048 extern void int1_handler(void) __attribute__((interrupt));
    00049 extern void int2_handler(void) __attribute__((interrupt));
    00050 extern void int3_handler(void) __attribute__((interrupt));
    00051 #if defined (TL410) || defined (TL420)
    00052 extern void trap0_handler(void) __attribute__((interrupt));
    00053 extern void trap1_handler(void) __attribute__((interrupt));
    00054 extern void trap2_handler(void) __attribute__((interrupt));
    00055 extern void trap3_handler(void) __attribute__((interrupt));
    00056 #endif
    00057
    00058 /*
    00059  * crt0.c:
    00060  * Composed of three parts:
    00061  *
    00062  * 1. The interrupt handlers table.
    00063  * 2. Data sections for stack, heap, stdin/stdout and virtual registers
    00064  * 3. The start() routine which calls main() and then exit(),
    00065  */
    00066
    00067 #ifdef BIG_ENDIAN
    00068 void big_endian_argv (int argc, char *argv[])
    00069 {
    00070   int i;
    00071
    00072   for (i = 0; i < argc; i++)
    00073   {
    00074     char h, l;
    00075     char *p = (char *)&argv[i];
    00076
    00077     l = *p;
    00078     h = *(p + 1);
    00079
    00080     *p = h;
    00081     *(p + 1) = l;
    00082   }
    00083 }
    00084 #endif
    00085
    00086 /*
    00087  * The interrupt handlers table.
    00088  */
    00089 _dsp_asm(".CSECT inttbl");
    00090
    00091 /* Reset jumps to start(). */
    00092
    00093 _dsp_asm("br _start, true");
    00094
    00095 /* TRAP/BI jumps to trap handler  */
    00096
    00097 _dsp_asm("br _trap_handler, true");
    00098
    00099 /* NMI jumps to nmi_handler */
    00100
    00101 _dsp_asm("br _nmi_handler, true");
    00102
    00103 /* INT0 jumps to int0_handler */
    00104 #ifdef CRU_PUSHPOP_CRPC
    00105 _dsp_asm("pushdw crpc");
    00106 #endif
    00107 _dsp_asm("br _int0_handler, true");
    00108 _dsp_asm("nop");
    00109 _dsp_asm("nop");
    00110 _dsp_asm("nop");
    00111 _dsp_asm("nop");
    00112 #ifndef CRU_PUSHPOP_CRPC
    00113 _dsp_asm("nop");
    00114 _dsp_asm("nop");
    00115 #endif
    00116
    00117 /* INT1 jumps to int1_handler */
    00118
    00119 #ifdef CRU_PUSHPOP_CRPC
    00120 _dsp_asm("pushdw crpc");
    00121 #endif
    00122 _dsp_asm("br _int1_handler, true");
    00123 _dsp_asm("nop");
    00124 _dsp_asm("nop");
    00125 _dsp_asm("nop");
    00126 _dsp_asm("nop");
    00127 #ifndef CRU_PUSHPOP_CRPC
    00128 _dsp_asm("nop");
    00129 _dsp_asm("nop");
    00130 #endif
    00131
    00132 /* INT2 jumps to int2_handler */
    00133
    00134 #ifdef CRU_PUSHPOP_CRPC
    00135 _dsp_asm("pushdw crpc");
    00136 #endif
    00137 _dsp_asm("br _int2_handler, true");
    00138 _dsp_asm("nop");
    00139 _dsp_asm("nop");
    00140 _dsp_asm("nop");
    00141 _dsp_asm("nop");
    00142 _dsp_asm("nop");
    00143 _dsp_asm("nop");
    00144 #ifndef CRU_PUSHPOP_CRPC
    00145 _dsp_asm("nop");
    00146 _dsp_asm("nop");
    00147 #endif
    00148
    00149 /* INT3 jumps to int3_handler */
    00150
    00151 #ifdef CRU_PUSHPOP_CRPC
    00152 _dsp_asm("pushdw crpc");
    00153 #endif
    00154 _dsp_asm("br _int3_handler, true");
    00155 _dsp_asm("nop");
    00156 _dsp_asm("nop");
    00157 _dsp_asm("nop");
    00158 _dsp_asm("nop");
    00159 _dsp_asm("nop");
    00160 _dsp_asm("nop");
    00161 #ifndef CRU_PUSHPOP_CRPC
    00162 _dsp_asm("nop");
    00163 _dsp_asm("nop");
    00164 #endif
    00165
    00166 #if defined (TL410) || defined (TL420)
    00167 /* software interrupts: */
    00168
    00169 _dsp_asm("nop");
    00170 _dsp_asm("nop");
    00171 _dsp_asm("nop");
    00172 _dsp_asm("nop");
    00173 _dsp_asm("nop");
    00174 _dsp_asm("nop");
    00175 _dsp_asm("nop");
    00176 _dsp_asm("nop");
    00177 _dsp_asm("nop");
    00178 _dsp_asm("nop");
    00179 _dsp_asm("nop");
    00180 _dsp_asm("nop");
    00181 _dsp_asm("nop");
    00182 _dsp_asm("nop");
    00183 _dsp_asm("nop");
    00184 _dsp_asm("nop");
    00185 _dsp_asm("nop");
    00186 _dsp_asm("nop");
    00187 _dsp_asm("nop");
    00188 _dsp_asm("nop");
    00189 _dsp_asm("nop");
    00190 _dsp_asm("nop");
    00191 _dsp_asm("nop");
    00192 _dsp_asm("nop");
    00193 _dsp_asm("nop");
    00194 _dsp_asm("nop");
    00195 _dsp_asm("nop");
    00196 _dsp_asm("nop");
    00197 _dsp_asm("nop");
    00198 _dsp_asm("nop");
    00199 _dsp_asm("nop");
    00200 _dsp_asm("nop");
    00201 _dsp_asm("nop");
    00202 _dsp_asm("nop");
    00203 _dsp_asm("nop");
    00204 _dsp_asm("nop");
    00205 _dsp_asm("nop");
    00206 _dsp_asm("nop");
    00207
    00208 /* TRAP0 jumps to trap0_handler */
    00209 _dsp_asm("br _trap0_handler, true");
    00210 _dsp_asm("nop");
    00211 _dsp_asm("nop");
    00212 _dsp_asm("nop");
    00213 _dsp_asm("nop");
    00214 _dsp_asm("nop");
    00215 _dsp_asm("nop");
    00216 _dsp_asm("nop");
    00217 _dsp_asm("nop");
    00218 _dsp_asm("nop");
    00219 _dsp_asm("nop");
    00220 _dsp_asm("nop");
    00221 _dsp_asm("nop");
    00222 _dsp_asm("nop");
    00223 _dsp_asm("nop");
    00224
    00225 /* TRAP1 jumps to trap1_handler */
    00226 _dsp_asm("br _trap1_handler, true");
    00227 _dsp_asm("nop");
    00228 _dsp_asm("nop");
    00229 _dsp_asm("nop");
    00230 _dsp_asm("nop");
    00231 _dsp_asm("nop");
    00232 _dsp_asm("nop");
    00233 _dsp_asm("nop");
    00234 _dsp_asm("nop");
    00235 _dsp_asm("nop");
    00236 _dsp_asm("nop");
    00237 _dsp_asm("nop");
    00238 _dsp_asm("nop");
    00239 _dsp_asm("nop");
    00240 _dsp_asm("nop");
    00241
    00242 /* TRAP2 jumps to trap2_handler */
    00243 _dsp_asm("br _trap2_handler, true");
    00244 _dsp_asm("nop");
    00245 _dsp_asm("nop");
    00246 _dsp_asm("nop");
    00247 _dsp_asm("nop");
    00248 _dsp_asm("nop");
    00249 _dsp_asm("nop");
    00250 _dsp_asm("nop");
    00251 _dsp_asm("nop");
    00252 _dsp_asm("nop");
    00253 _dsp_asm("nop");
    00254 _dsp_asm("nop");
    00255 _dsp_asm("nop");
    00256 _dsp_asm("nop");
    00257 _dsp_asm("nop");
    00258
    00259 /* TRAP3 jumps to trap3_handler */
    00260 _dsp_asm("br _trap3_handler, true");
    00261 _dsp_asm("nop");
    00262 _dsp_asm("nop");
    00263 _dsp_asm("nop");
    00264 _dsp_asm("nop");
    00265 _dsp_asm("nop");
    00266 _dsp_asm("nop");
    00267 _dsp_asm("nop");
    00268 _dsp_asm("nop");
    00269
    00270 #endif
    00271
    00272 /* The malloc segment can be mapped to anywhere within memory. */
    00273 _dsp_asm(".DSECT __MALLOC_SECT");
    00274
    00275 /* The stack segment can be mapped to anywhere within memory. */
    00276 _dsp_asm(".DSECT __STACK_SECT");
    00277
    00278 /* The mailbox segment can be mapped to anywhere within memory. */
    00279 _dsp_asm(".DSECT __MAILBOX_SECT");
    00280
    00281 /* The mmio segment can be mapped to anywhere within memory. */
    00282 _dsp_asm(".DSECT __MMIO_SECT");
    00283
    00284
    00285
    00286
    00287 volatile char _outport __attribute__((section(".DSECT __OUTPORT_SECT")));
    00288
    00289 volatile char _inport  __attribute__((section(".DSECT __INPORT_SECT")));
    00290
    00291 /* The 80 virtual registers are allocated a separate section, that are
    00292    followed by the small memory model global variables. When using the
    00293    small memory model, up to 256-80=176 global scalars can be used. If
    00294    more are used, the linker will issue an error message. If more globals
    00295    are needed in the small memory model, it is possible to reduce the
    00296    number of virtual registers. For example, if 216 global scalars are
    00297    needed, decrease the number 80 in the following line to 40 and instruct
    00298    the compiler not to use these by compiling with the -mfix-zp-40-79 flag */
    00299
    00300 char _page_regs[80]   __attribute__((section(".DSECT __PAGE_REGS_SECT")));
    00301
    00302
    00303 _dsp_asm(".GLOBAL ___crt0_const_data_start__");
    00304 _dsp_asm(".DSECT const_data");
    00305 _dsp_asm("___crt0_const_data_start__:");
    00306
    00307 _dsp_asm(".GLOBAL ___crt0_data_start__");
    00308 _dsp_asm(".ndata");
    00309 _dsp_asm("___crt0_data_start__:");
    00310 /* This is a dummy to make sure ___crt0_data_start__ points at the beggining
    00311    of .data section */
    00312 _dsp_asm("DW 2");
    00313
    00314 _dsp_asm(".GLOBAL ___crt0_bss_start__");
    00315 _dsp_asm(".bss");
    00316 _dsp_asm("___crt0_bss_start__:");
    00317
    00318 /*
    00319  * The start() routine.
    00320  *
    00321  * start() calls main() and then exit(),
    00322  */
    00323
    00324 _dsp_asm(".CSECT ctor_sect");
    00325 _dsp_asm(".CSECT dtor_sect");
    00326 _dsp_asm(".CSECT call_saved_store_restore_sect");
    00327 _dsp_asm(".text");
    00328 _dsp_asm(".GLOBAL _errno");
    00329 _dsp_asm(".GLOBAL _crt0HookPostStart");
    00330 _dsp_asm(".GLOBAL __crt0HookPostStartRetLabel__");
    00331
    00332 /* RW: add global to remove warning */
    00333 _dsp_asm(".GLOBAL _trap_handler");
    00334 _dsp_asm(".GLOBAL _nmi_handler");
    00335 _dsp_asm(".GLOBAL _int0_handler");
    00336 _dsp_asm(".GLOBAL _int1_handler");
    00337 _dsp_asm(".GLOBAL _int2_handler");
    00338 _dsp_asm(".GLOBAL _int3_handler");
    00339 _dsp_asm(".GLOBAL _trap0_handler");
    00340 _dsp_asm(".GLOBAL _trap1_handler");
    00341 _dsp_asm(".GLOBAL _trap2_handler");
    00342 _dsp_asm(".GLOBAL _trap3_handler");
    00343 _dsp_asm(".GLOBAL _initConfigRegs");
    00344 _dsp_asm(".GLOBAL _initDataSections");
    00345 _dsp_asm(".GLOBAL _crt0HookPreMain");
    00346 _dsp_asm(".GLOBAL _main");
    00347
    00348 _dsp_asm(".CSECT inttbl$crt0_start0");
    00349 _dsp_asm(".func_start 2 _start");
    00350 _dsp_asm("_start:");
    00351 _dsp_asm(".CSECT inttbl$crt0_start1");
    00352 _dsp_asm("brf{t} _start_text");
    00353 _dsp_asm(".func_end 2 _start");
    00354
    00355 _dsp_asm(".text");
    00356 _dsp_asm(".func_start 2 _start_text");
    00357 _dsp_asm("_start_text:");
    00358
    00359 /* reset tlb/tkb bits */
    00360 #if !(defined TEAKLITE4_VOICE || defined TEAKLITE4_AUDIO)
    00361 _dsp_asm("lbf 0, tlb");
    00362 _dsp_asm("nop");
    00363 _dsp_asm("lbf 0, tkb");
    00364 #endif
    00365 _dsp_asm("nop");
    00366 /* set big-endianess bit */
    00367 #if defined TL421 || defined TL420
    00368 _dsp_asm("mov 0x30c, r5");
    00369 _dsp_asm("in{cpm} (r5).dw, r4");
    00370 _dsp_asm("nop");
    00371 _dsp_asm("nop");
    00372 _dsp_asm("nop");
    00373 #ifdef BIG_ENDIAN
    00374 _dsp_asm("ors r4, 0x1, r4");
    00375 #else /* BIG_ENDIAN */
    00376 _dsp_asm("ands r4, 0xfffffffe, r4");
    00377 #endif /* BIG_ENDIAN */
    00378 #else /* TL421 || TL420 */
    00379 _dsp_asm("mov 0x300, r5");
    00380 _dsp_asm("in{cpm} (r5).dw, r4");
    00381 _dsp_asm("nop");
    00382 _dsp_asm("nop");
    00383 _dsp_asm("nop");
    00384 #ifdef BIG_ENDIAN
    00385 _dsp_asm("ors r4, 0x10000, r4");
    00386 #else /* BIG_ENDIAN */
    00387 _dsp_asm("ands r4, 0xfffeffff, r4");
    00388 #endif /* BIG_ENDIAN */
    00389 #endif /* TL421 || TL420 */
    00390 _dsp_asm("nop");
    00391 _dsp_asm("nop");
    00392 _dsp_asm("out{cpm} r4, (r5).dw");
    00393
    00394 _dsp_asm("brf _crt0HookPostStart");
    00395 _dsp_asm("__crt0HookPostStartRetLabel__:");
    00396
    00397 _dsp_asm("mov __STACK_SECT.0, r0");
    00398 _dsp_asm("adds r0, SIZEOF(__STACK_SECT)-2, r0");
    00399 _dsp_asm("mov r0, sp");
    00400
    00401 /* start_clock () */
    00402 _dsp_asm("mov    1044, r1");
    00403 _dsp_asm("in{cpm}    (r1).dw, r0");
    00404 _dsp_asm("nop 2");
    00405 _dsp_asm("andnots    r0, 1, r0");
    00406 _dsp_asm("nop 1");
    00407 _dsp_asm("out{cpm}    r0, (r1).dw");
    00408
    00409 /* init all configuration registers. */
    00410 _dsp_asm("callf _initConfigRegs");
    00411 _dsp_asm("callf _initDataSections");
    00412
    00413 _dsp_asm("__not_needed:");
    00414
    00415 /*
    00416  * initializations must come after globals have been copied from
    00417  * program memory to data memory.
    00418  */
    00419 /* RW: We don't need file IO */
    00420 /* _dsp_asm("callf _initFileIo"); */
    00421 _dsp_asm("callf ctor_sect.0");
    00422 _dsp_asm("callf _crt0HookPreMain");
    00423 /* RW: We don't need to pass argument to firmware */
    00424 #define NO_ARGV_SECT
    00425 #ifndef NO_ARGV_SECT
    00426 /*
    00427  * preparing the arguments for main:
    00428  * - [ARG_SECT.0] holds argc.
    00429  * - ARG_SECT.1 holds argv.
    00430  */
    00431 #ifdef BIG_ENDIAN
    00432 /*
    00433  * adjust the values in argv[] for big endian
    00434  * (the program arguments are set before the beb)
    00435  */
    00436 _dsp_asm("ld [ARG_SECT.0],a0");
    00437 _dsp_asm("mov ARG_SECT.1,a1");
    00438 _dsp_asm("callf _big_endian_argv");
    00439 #endif
    00440 _dsp_asm("ld [ARG_SECT.0],a0");
    00441 _dsp_asm("mov ARG_SECT.1,a1");
    00442 #endif
    00443 _dsp_asm("callf _main");
    00444 _dsp_asm("st a0l,[_errno]");
    00445 _dsp_asm("callf dtor_sect.0");
    00446 _dsp_asm("ld [_errno],a0");
    00447 /* RW: remove call to exit as it pull some unsed code and we never reach here */
    00448 //_dsp_asm("brf  _exit");
    00449 _dsp_asm(".func_end 2 _start_text");