start.S 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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. * SPDX-License-Identifier: GPL-2.0+
  11. */
  12. #include <config.h>
  13. #include <version.h>
  14. #include <asm/global_data.h>
  15. #include <asm/processor.h>
  16. #include <asm/processor-flags.h>
  17. #include <generated/generic-asm-offsets.h>
  18. .section .text
  19. .code32
  20. .globl _start
  21. .type _start, @function
  22. .globl _x86boot_start
  23. _x86boot_start:
  24. /*
  25. * This is the fail safe 32-bit bootstrap entry point. The
  26. * following code is not executed from a cold-reset (actually, a
  27. * lot of it is, but from real-mode after cold reset. It is
  28. * repeated here to put the board into a state as close to cold
  29. * reset as necessary)
  30. */
  31. cli
  32. cld
  33. /* Turn off cache (this might require a 486-class CPU) */
  34. movl %cr0, %eax
  35. orl $(X86_CR0_NW | X86_CR0_CD), %eax
  36. movl %eax, %cr0
  37. wbinvd
  38. /* Tell 32-bit code it is being entered from an in-RAM copy */
  39. movw $GD_FLG_WARM_BOOT, %bx
  40. jmp 1f
  41. _start:
  42. /*
  43. * This is the 32-bit cold-reset entry point. Initialize %bx to 0
  44. * in case we're preceeded by some sort of boot stub.
  45. */
  46. movw $GD_FLG_COLD_BOOT, %bx
  47. 1:
  48. /* Load the segement registes to match the gdt loaded in start16.S */
  49. movl $(X86_GDT_ENTRY_32BIT_DS * X86_GDT_ENTRY_SIZE), %eax
  50. movw %ax, %fs
  51. movw %ax, %ds
  52. movw %ax, %gs
  53. movw %ax, %es
  54. movw %ax, %ss
  55. /* Clear the interrupt vectors */
  56. lidt blank_idt_ptr
  57. /* Early platform init (setup gpio, etc ) */
  58. jmp early_board_init
  59. .globl early_board_init_ret
  60. early_board_init_ret:
  61. /* Initialise Cache-As-RAM */
  62. jmp car_init
  63. .globl car_init_ret
  64. car_init_ret:
  65. /*
  66. * We now have CONFIG_SYS_CAR_SIZE bytes of Cache-As-RAM (or SRAM,
  67. * or fully initialised SDRAM - we really don't care which)
  68. * starting at CONFIG_SYS_CAR_ADDR to be used as a temporary stack
  69. */
  70. /* Stack grows down from top of CAR */
  71. movl $(CONFIG_SYS_CAR_ADDR + CONFIG_SYS_CAR_SIZE), %esp
  72. /* Reserve space on stack for global data */
  73. subl $GENERATED_GBL_DATA_SIZE, %esp
  74. /* Align global data to 16-byte boundary */
  75. andl $0xfffffff0, %esp
  76. /* Setup first parameter to setup_gdt */
  77. movl %esp, %eax
  78. /* Reserve space for global descriptor table */
  79. subl $X86_GDT_SIZE, %esp
  80. /* Align temporary global descriptor table to 16-byte boundary */
  81. andl $0xfffffff0, %esp
  82. /* Set second parameter to setup_gdt */
  83. movl %esp, %edx
  84. /* Setup global descriptor table so gd->xyz works */
  85. call setup_gdt
  86. /* Set parameter to board_init_f() to boot flags */
  87. xorl %eax, %eax
  88. movw %bx, %ax
  89. /* Enter, U-boot! */
  90. call board_init_f
  91. /* indicate (lack of) progress */
  92. movw $0x85, %ax
  93. jmp die
  94. .globl board_init_f_r_trampoline
  95. .type board_init_f_r_trampoline, @function
  96. board_init_f_r_trampoline:
  97. /*
  98. * SDRAM has been initialised, U-Boot code has been copied into
  99. * RAM, BSS has been cleared and relocation adjustments have been
  100. * made. It is now time to jump into the in-RAM copy of U-Boot
  101. *
  102. * %eax = Address of top of new stack
  103. */
  104. /* Stack grows down from top of SDRAM */
  105. movl %eax, %esp
  106. /* Reserve space on stack for global data */
  107. subl $GENERATED_GBL_DATA_SIZE, %esp
  108. /* Align global data to 16-byte boundary */
  109. andl $0xfffffff0, %esp
  110. /* Setup first parameter to memcpy (and setup_gdt) */
  111. movl %esp, %eax
  112. /* Setup second parameter to memcpy */
  113. fs movl 0, %edx
  114. /* Set third parameter to memcpy */
  115. movl $GENERATED_GBL_DATA_SIZE, %ecx
  116. /* Copy global data from CAR to SDRAM stack */
  117. call memcpy
  118. /* Reserve space for global descriptor table */
  119. subl $X86_GDT_SIZE, %esp
  120. /* Align global descriptor table to 16-byte boundary */
  121. andl $0xfffffff0, %esp
  122. /* Set second parameter to setup_gdt */
  123. movl %esp, %edx
  124. /* Setup global descriptor table so gd->xyz works */
  125. call setup_gdt
  126. /* Re-enter U-Boot by calling board_init_f_r */
  127. call board_init_f_r
  128. die:
  129. hlt
  130. jmp die
  131. hlt
  132. blank_idt_ptr:
  133. .word 0 /* limit */
  134. .long 0 /* base */
  135. .p2align 2 /* force 4-byte alignment */
  136. multiboot_header:
  137. /* magic */
  138. .long 0x1BADB002
  139. /* flags */
  140. .long (1 << 16)
  141. /* checksum */
  142. .long -0x1BADB002 - (1 << 16)
  143. /* header addr */
  144. .long multiboot_header - _x86boot_start + CONFIG_SYS_TEXT_BASE
  145. /* load addr */
  146. .long CONFIG_SYS_TEXT_BASE
  147. /* load end addr */
  148. .long 0
  149. /* bss end addr */
  150. .long 0
  151. /* entry addr */
  152. .long CONFIG_SYS_TEXT_BASE