crt0.S 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * Copyright (C) Paul Mackerras 1997.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation; either version
  7. * 2 of the License, or (at your option) any later version.
  8. *
  9. * NOTE: this code runs in 32 bit mode and is packaged as ELF32.
  10. */
  11. #include "ppc_asm.h"
  12. .text
  13. /* a procedure descriptor used when booting this as a COFF file */
  14. .globl _zimage_start_opd
  15. _zimage_start_opd:
  16. .long _zimage_start, 0, 0, 0
  17. .weak _zimage_start
  18. .globl _zimage_start
  19. _zimage_start:
  20. .globl _zimage_start_lib
  21. _zimage_start_lib:
  22. /* Work out the offset between the address we were linked at
  23. and the address where we're running. */
  24. bl 1f
  25. 1: mflr r0
  26. lis r9,1b@ha
  27. addi r9,r9,1b@l
  28. subf. r0,r9,r0
  29. beq 3f /* if running at same address as linked */
  30. /* The .got2 section contains a list of addresses, so add
  31. the address offset onto each entry. */
  32. lis r9,__got2_start@ha
  33. addi r9,r9,__got2_start@l
  34. lis r8,__got2_end@ha
  35. addi r8,r8,__got2_end@l
  36. subf. r8,r9,r8
  37. beq 3f
  38. srwi. r8,r8,2
  39. mtctr r8
  40. add r9,r0,r9
  41. 2: lwz r8,0(r9)
  42. add r8,r8,r0
  43. stw r8,0(r9)
  44. addi r9,r9,4
  45. bdnz 2b
  46. /* Do a cache flush for our text, in case the loader didn't */
  47. 3: lis r9,_start@ha
  48. addi r9,r9,_start@l
  49. add r9,r0,r9
  50. lis r8,_etext@ha
  51. addi r8,r8,_etext@l
  52. add r8,r0,r8
  53. 4: dcbf r0,r9
  54. icbi r0,r9
  55. addi r9,r9,0x20
  56. cmplw cr0,r9,r8
  57. blt 4b
  58. sync
  59. isync
  60. /* Clear the BSS */
  61. lis r9,__bss_start@ha
  62. addi r9,r9,__bss_start@l
  63. add r9,r0,r9
  64. lis r8,_end@ha
  65. addi r8,r8,_end@l
  66. add r8,r0,r8
  67. li r10,0
  68. 5: stw r10,0(r9)
  69. addi r9,r9,4
  70. cmplw cr0,r9,r8
  71. blt 5b
  72. /* Possibly set up a custom stack */
  73. .weak _platform_stack_top
  74. lis r8,_platform_stack_top@ha
  75. addi r8,r8,_platform_stack_top@l
  76. cmpwi r8,0
  77. beq 6f
  78. add r8,r0,r8
  79. lwz r1,0(r8)
  80. add r1,r0,r1
  81. li r0,0
  82. stwu r0,-16(r1) /* establish a stack frame */
  83. 6:
  84. /* Call platform_init() */
  85. bl platform_init
  86. /* Call start */
  87. b start