crt0.S 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /* Startup code for Alpha/ELF.
  2. Copyright (C) 1993,1995,1996,1997,1998,2000,2001 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. Contributed by Richard Henderson <rth@tamu.edu>
  5. The GNU C Library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public
  7. License as published by the Free Software Foundation; either
  8. version 2.1 of the License, or (at your option) any later version.
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with the GNU C Library; if not, write to the Free
  15. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  16. 02111-1307 USA. */
  17. #include <features.h>
  18. #define a0 $16 /* argument registers (caller-saved) */
  19. #define a1 $17
  20. #define a2 $18
  21. #define a3 $19
  22. #define a4 $20
  23. #define a5 $21
  24. #define ra $26 /* return address register */
  25. #define s6 $15
  26. #define fp s6 /* frame-pointer (s6 in frame-less procedures) */
  27. #define gp $29 /* global pointer */
  28. #define sp $30 /* stack pointer */
  29. #define zero $31 /* reads as zero, writes are noops */
  30. .text
  31. .align 3
  32. .globl _start
  33. .ent _start, 0
  34. .type _start,@function
  35. #if defined L_crt0 || ! defined __UCLIBC_CTOR_DTOR__
  36. .type __uClibc_main,@function
  37. #else
  38. .weak _init
  39. .weak _fini
  40. .type __uClibc_start_main,@function
  41. #endif
  42. /* Stick in a dummy reference to main(), so that if an application
  43. * is linking when the main() function is in a static library (.a)
  44. * we can be sure that main() actually gets linked in */
  45. .type main,@function
  46. _start:
  47. .frame fp, 0, zero
  48. mov zero, fp
  49. br gp, 1f
  50. 1: ldgp gp, 0(gp)
  51. subq sp, 16, sp
  52. .prologue 0
  53. ldl a0, 16(sp) /* get argc */
  54. lda a1, 24(sp) /* get argv */
  55. addq a0, 1, a2
  56. s8addq a2, a1, a2 /* Calculate environ */
  57. /* Call the user's main function, and exit with its value.
  58. But let the libc call main. */
  59. jsr ra, __uClibc_main
  60. /* Die very horribly if exit returns. Call_pal hlt is callable from
  61. kernel mode only; this will result in an illegal instruction trap. */
  62. call_pal 0
  63. .end _start
  64. /* For ECOFF backwards compatibility. */
  65. .weak __start;
  66. __start = _start
  67. /* Define a symbol for the first piece of initialized data. */
  68. .data
  69. .globl __data_start
  70. __data_start:
  71. .long 0
  72. .weak data_start
  73. data_start = __data_start