crt0.S 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. _zimage_start_opd:
  15. .long _zimage_start, 0, 0, 0
  16. .weak _zimage_start
  17. .globl _zimage_start
  18. _zimage_start:
  19. /* Work out the offset between the address we were linked at
  20. and the address where we're running. */
  21. bl 1f
  22. 1: mflr r0
  23. lis r9,1b@ha
  24. addi r9,r9,1b@l
  25. subf. r0,r9,r0
  26. beq 3f /* if running at same address as linked */
  27. /* The .got2 section contains a list of addresses, so add
  28. the address offset onto each entry. */
  29. lis r9,__got2_start@ha
  30. addi r9,r9,__got2_start@l
  31. lis r8,__got2_end@ha
  32. addi r8,r8,__got2_end@l
  33. subf. r8,r9,r8
  34. beq 3f
  35. srwi. r8,r8,2
  36. mtctr r8
  37. add r9,r0,r9
  38. 2: lwz r8,0(r9)
  39. add r8,r8,r0
  40. stw r8,0(r9)
  41. addi r9,r9,4
  42. bdnz 2b
  43. /* Do a cache flush for our text, in case the loader didn't */
  44. 3: lis r9,_start@ha
  45. addi r9,r9,_start@l
  46. add r9,r0,r9
  47. lis r8,_etext@ha
  48. addi r8,r8,_etext@l
  49. add r8,r0,r8
  50. 4: dcbf r0,r9
  51. icbi r0,r9
  52. addi r9,r9,0x20
  53. cmplw cr0,r9,r8
  54. blt 4b
  55. sync
  56. isync
  57. /* Clear the BSS */
  58. lis r9,__bss_start@ha
  59. addi r9,r9,__bss_start@l
  60. lis r8,_end@ha
  61. addi r8,r8,_end@l
  62. li r0,0
  63. 5: stw r0,0(r9)
  64. addi r9,r9,4
  65. cmplw cr0,r9,r8
  66. blt 5b
  67. /* Possibly set up a custom stack */
  68. .weak _platform_stack_top
  69. lis r8,_platform_stack_top@ha
  70. addi r8,r8,_platform_stack_top@l
  71. cmpwi r8,0
  72. beq 6f
  73. lwz r1,0(r8)
  74. li r0,0
  75. stwu r0,-16(r1) /* establish a stack frame */
  76. 6:
  77. /* Call platform_init() */
  78. bl platform_init
  79. /* Call start */
  80. mr r3,r1
  81. b start