crt0.S 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. .globl _zimage_start
  17. _zimage_start:
  18. /* Work out the offset between the address we were linked at
  19. and the address where we're running. */
  20. bl 1f
  21. 1: mflr r0
  22. lis r9,1b@ha
  23. addi r9,r9,1b@l
  24. subf. r0,r9,r0
  25. beq 3f /* if running at same address as linked */
  26. /* The .got2 section contains a list of addresses, so add
  27. the address offset onto each entry. */
  28. lis r9,__got2_start@ha
  29. addi r9,r9,__got2_start@l
  30. lis r8,__got2_end@ha
  31. addi r8,r8,__got2_end@l
  32. subf. r8,r9,r8
  33. beq 3f
  34. srwi. r8,r8,2
  35. mtctr r8
  36. add r9,r0,r9
  37. 2: lwz r8,0(r9)
  38. add r8,r8,r0
  39. stw r8,0(r9)
  40. addi r9,r9,4
  41. bdnz 2b
  42. /* Do a cache flush for our text, in case OF didn't */
  43. 3: lis r9,_start@h
  44. add r9,r0,r9
  45. lis r8,_etext@ha
  46. addi r8,r8,_etext@l
  47. add r8,r0,r8
  48. 4: dcbf r0,r9
  49. icbi r0,r9
  50. addi r9,r9,0x20
  51. cmplwi 0,r9,8
  52. blt 4b
  53. sync
  54. isync
  55. mr r6,r1
  56. b start