crt0.S 1.9 KB

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