crt0.S 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * xrt0.s for ERC32.
  3. *
  4. * This program is free software; you can redistribute it and/or modify it under
  5. * the terms of the GNU General Public License as published by the Free
  6. * Software Foundation; either version 2 of the License, or (at your option)
  7. * any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * this program; if not, write to the Free Software Foundation, Inc., 675
  16. * Mass Ave, Cambridge, MA 02139, USA.
  17. *
  18. */
  19. /* code taken from leonccs 1.0 leon/src/libio/crt0.S
  20. I don't know if this is available anymore, now that LECCS
  21. is out. And I'm not sure if this source is in the LECCS distro :(
  22. */
  23. .text
  24. ! Original :
  25. ! .global __start, _main
  26. ! uC-libc version :
  27. .global _start
  28. .global __uClibc_main
  29. ! Start the real-time clock with a tick of 14 clocks
  30. !
  31. _start:
  32. save %sp, -64, %sp
  33. /* clear the bss */
  34. sethi %hi(edata),%g2
  35. or %g2,%lo(edata),%g2 ! g2 = start of bss
  36. sethi %hi(_end),%g3
  37. or %g3,%lo(_end),%g3 ! g3 = end of bss
  38. mov %g0,%g1 ! so std has two zeros
  39. zerobss:
  40. std %g0,[%g2]
  41. add %g2,8,%g2
  42. cmp %g2,%g3
  43. bleu,a zerobss
  44. nop
  45. /* move data segment to proper location */
  46. relocd:
  47. set (_endtext),%g2 ! g2 = start of data in aout file
  48. set (_environ),%g4 ! g4 = start of where data should go
  49. set (_edata),%g3 ! g3 = end of where data should go
  50. subcc %g3, %g4, %g5 ! g5 = length of data
  51. subcc %g4, %g2, %g0 ! need to relocate data ?
  52. ble initok
  53. ld [%g4], %g6
  54. ! subcc %g6, 1, %g0
  55. ! be initok
  56. mvdata:
  57. subcc %g5, 8, %g5
  58. ldd [%g2 + %g5], %g6
  59. bg mvdata
  60. std %g6, [%g4 + %g5]
  61. initok:
  62. ! call _main
  63. call __uClibc_main
  64. nop
  65. ! Should not return from uClibc main()
  66. ! ret
  67. ! nop
  68. .seg "data"
  69. .global .bdata
  70. .bdata:
  71. .align 8
  72. .global _environ ! first symbol in sdata
  73. _environ:
  74. .word 1