start.S 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /*
  2. * U-boot - x86 Startup Code
  3. *
  4. * (C) Copyright 2008-2011
  5. * Graeme Russ, <graeme.russ@gmail.com>
  6. *
  7. * (C) Copyright 2002
  8. * Daniel Engström, Omicron Ceti AB, <daniel@omicron.se>
  9. *
  10. * See file CREDITS for list of people who contributed to this
  11. * project.
  12. *
  13. * This program is free software; you can redistribute it and/or
  14. * modify it under the terms of the GNU General Public License as
  15. * published by the Free Software Foundation; either version 2 of
  16. * the License, or (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with this program; if not, write to the Free Software
  25. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  26. * MA 02111-1307 USA
  27. */
  28. #include <config.h>
  29. #include <version.h>
  30. #include <asm/global_data.h>
  31. #include <asm/processor.h>
  32. #include <asm/processor-flags.h>
  33. #include <generated/generic-asm-offsets.h>
  34. .section .text
  35. .code32
  36. .globl _start
  37. .type _start, @function
  38. .globl _x86boot_start
  39. _x86boot_start:
  40. /*
  41. * This is the fail safe 32-bit bootstrap entry point. The
  42. * following code is not executed from a cold-reset (actually, a
  43. * lot of it is, but from real-mode after cold reset. It is
  44. * repeated here to put the board into a state as close to cold
  45. * reset as necessary)
  46. */
  47. cli
  48. cld
  49. /* Turn off cache (this might require a 486-class CPU) */
  50. movl %cr0, %eax
  51. orl $(X86_CR0_NW | X86_CR0_CD), %eax
  52. movl %eax, %cr0
  53. wbinvd
  54. _start:
  55. /* This is the 32-bit cold-reset entry point */
  56. /* Load the segement registes to match the gdt loaded in start16.S */
  57. movl $(X86_GDT_ENTRY_32BIT_DS * X86_GDT_ENTRY_SIZE), %eax
  58. movw %ax, %fs
  59. movw %ax, %ds
  60. movw %ax, %gs
  61. movw %ax, %es
  62. movw %ax, %ss
  63. /* Clear the interrupt vectors */
  64. lidt blank_idt_ptr
  65. /* Early platform init (setup gpio, etc ) */
  66. jmp early_board_init
  67. .globl early_board_init_ret
  68. early_board_init_ret:
  69. /* Initialise Cache-As-RAM */
  70. jmp car_init
  71. .globl car_init_ret
  72. car_init_ret:
  73. /*
  74. * We now have CONFIG_SYS_CAR_SIZE bytes of Cache-As-RAM (or SRAM,
  75. * or fully initialised SDRAM - we really don't care which)
  76. * starting at CONFIG_SYS_CAR_ADDR to be used as a temporary stack
  77. */
  78. /* Stack grows down from top of CAR */
  79. movl $(CONFIG_SYS_CAR_ADDR + CONFIG_SYS_CAR_SIZE), %esp
  80. /* Reserve space on stack for global data */
  81. subl $GENERATED_GBL_DATA_SIZE, %esp
  82. /* Align global data to 16-byte boundary */
  83. andl $0xfffffff0, %esp
  84. /* Setup first parameter to setup_gdt */
  85. movl %esp, %eax
  86. /* Reserve space for global descriptor table */
  87. subl $X86_GDT_SIZE, %esp
  88. /* Align temporary global descriptor table to 16-byte boundary */
  89. andl $0xfffffff0, %esp
  90. /* Set second parameter to setup_gdt */
  91. movl %esp, %edx
  92. /* gd->gd_addr = gd (Required to allow gd->xyz to work) */
  93. movl %eax, (%eax)
  94. /* Setup global descriptor table so gd->xyz works */
  95. call setup_gdt
  96. /* Set parameter to board_init_f() to boot flags */
  97. xorl %eax, %eax
  98. movw %bx, %ax
  99. /* Enter, U-boot! */
  100. call board_init_f
  101. /* indicate (lack of) progress */
  102. movw $0x85, %ax
  103. jmp die
  104. .globl board_init_f_r_trampoline
  105. .type board_init_f_r_trampoline, @function
  106. board_init_f_r_trampoline:
  107. /*
  108. * SDRAM has been initialised, U-Boot code has been copied into
  109. * RAM, BSS has been cleared and relocation adjustments have been
  110. * made. It is now time to jump into the in-RAM copy of U-Boot
  111. *
  112. * %eax = Address of top of new stack
  113. */
  114. /* Stack grows down from top of SDRAM */
  115. movl %eax, %esp
  116. /* Reserve space on stack for global data */
  117. subl $GENERATED_GBL_DATA_SIZE, %esp
  118. /* Align global data to 16-byte boundary */
  119. andl $0xfffffff0, %esp
  120. /* Setup first parameter to memcpy (and setup_gdt) */
  121. movl %esp, %eax
  122. /* Setup second parameter to memcpy */
  123. fs movl 0, %edx
  124. /* Set third parameter to memcpy */
  125. movl $GENERATED_GBL_DATA_SIZE, %ecx
  126. /* Copy global data from CAR to SDRAM stack */
  127. call memcpy
  128. /* Reserve space for global descriptor table */
  129. subl $X86_GDT_SIZE, %esp
  130. /* Align global descriptor table to 16-byte boundary */
  131. andl $0xfffffff0, %esp
  132. /* Set second parameter to setup_gdt */
  133. movl %esp, %edx
  134. /* gd->gd_addr = gd (Required to allow gd->xyz to work) */
  135. movl %eax, (%eax)
  136. /* Setup global descriptor table so gd->xyz works */
  137. call setup_gdt
  138. /* Re-enter U-Boot by calling board_init_f_r */
  139. call board_init_f_r
  140. die:
  141. hlt
  142. jmp die
  143. hlt
  144. blank_idt_ptr:
  145. .word 0 /* limit */
  146. .long 0 /* base */
  147. .p2align 2 /* force 4-byte alignment */
  148. multiboot_header:
  149. /* magic */
  150. .long 0x1BADB002
  151. /* flags */
  152. .long (1 << 16)
  153. /* checksum */
  154. .long -0x1BADB002 - (1 << 16)
  155. /* header addr */
  156. .long multiboot_header - _x86boot_start + CONFIG_SYS_TEXT_BASE
  157. /* load addr */
  158. .long CONFIG_SYS_TEXT_BASE
  159. /* load end addr */
  160. .long 0
  161. /* bss end addr */
  162. .long 0
  163. /* entry addr */
  164. .long CONFIG_SYS_TEXT_BASE