head.S 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. * Copyright (C) 2009 Thomas Chou <thomas@wytron.com.tw>
  3. *
  4. * Based on arch/nios2/kernel/head.S
  5. *
  6. * This file is subject to the terms and conditions of the GNU General Public
  7. * License. See the file "COPYING" in the main directory of this archive
  8. * for more details.
  9. *
  10. */
  11. /*
  12. * This code can be loaded anywhere, eg FLASH ROM as reset vector,
  13. * as long as output does not overlap it.
  14. */
  15. #include <linux/linkage.h>
  16. #include <asm/cache.h>
  17. .text
  18. .set noat
  19. ENTRY(_start)
  20. wrctl status, r0 /* disable interrupt */
  21. /* invalidate all instruction cache */
  22. movia r1, NIOS2_ICACHE_SIZE
  23. movui r2, NIOS2_ICACHE_LINE_SIZE
  24. 1: initi r1
  25. sub r1, r1, r2
  26. bgt r1, r0, 1b
  27. /* invalidate all data cache */
  28. movia r1, NIOS2_DCACHE_SIZE
  29. movui r2, NIOS2_DCACHE_LINE_SIZE
  30. 1: initd 0(r1)
  31. sub r1, r1, r2
  32. bgt r1, r0, 1b
  33. nextpc r1 /* Find out where we are */
  34. chkadr:
  35. movia r2, chkadr
  36. beq r1, r2, finish_move /* We are running in correct address,
  37. done */
  38. /* move code, r1: src, r2: dest, r3: last dest */
  39. addi r1, r1, (_start - chkadr) /* Source */
  40. movia r2, _start /* Destination */
  41. movia r3, __bss_start /* End of copy */
  42. 1: ldw r8, 0(r1) /* load a word from [r1] */
  43. stw r8, 0(r2) /* stort a word to dest [r2] */
  44. addi r1, r1, 4 /* inc the src addr */
  45. addi r2, r2, 4 /* inc the dest addr */
  46. blt r2, r3, 1b
  47. /* flush the data cache after moving */
  48. movia r1, NIOS2_DCACHE_SIZE
  49. movui r2, NIOS2_DCACHE_LINE_SIZE
  50. 1: flushd 0(r1)
  51. sub r1, r1, r2
  52. bgt r1, r0, 1b
  53. movia r1, finish_move
  54. jmp r1 /* jmp to linked address */
  55. finish_move:
  56. /* zero out the .bss segment (uninitialized common data) */
  57. movia r2, __bss_start /* presume nothing is between */
  58. movia r1, _end /* the .bss and _end. */
  59. 1: stb r0, 0(r2)
  60. addi r2, r2, 1
  61. bne r1, r2, 1b
  62. /*
  63. * set up the stack pointer, some where higher than _end.
  64. * The stack space must be greater than 32K for decompress.
  65. */
  66. movia sp, 0x10000
  67. add sp, sp, r1
  68. /* save args passed from u-boot, maybe */
  69. addi sp, sp, -16
  70. stw r4, 0(sp)
  71. stw r5, 4(sp)
  72. stw r6, 8(sp)
  73. stw r7, 12(sp)
  74. /* decompress the kernel */
  75. call decompress_kernel
  76. /* pass saved args to kernel */
  77. ldw r4, 0(sp)
  78. ldw r5, 4(sp)
  79. ldw r6, 8(sp)
  80. ldw r7, 12(sp)
  81. /* flush all data cache after decompressing */
  82. movia r1, NIOS2_DCACHE_SIZE
  83. movui r2, NIOS2_DCACHE_LINE_SIZE
  84. 1: flushd 0(r1)
  85. sub r1, r1, r2
  86. bgt r1, r0, 1b
  87. /* flush all instruction cache */
  88. movia r1, NIOS2_ICACHE_SIZE
  89. movui r2, NIOS2_ICACHE_LINE_SIZE
  90. 1: flushi r1
  91. sub r1, r1, r2
  92. bgt r1, r0, 1b
  93. flushp
  94. /* jump to start real kernel */
  95. movia r1, (CONFIG_NIOS2_MEM_BASE | CONFIG_NIOS2_KERNEL_REGION_BASE)
  96. jmp r1
  97. .balign 512
  98. fake_headers_as_bzImage:
  99. .short 0
  100. .ascii "HdrS"
  101. .short 0x0202
  102. .short 0
  103. .short 0
  104. .byte 0x00, 0x10
  105. .short 0
  106. .byte 0
  107. .byte 1
  108. .byte 0x00, 0x80
  109. .long 0
  110. .long 0