start16.S 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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,2003
  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 <asm/global_data.h>
  29. #include <asm/processor-flags.h>
  30. #define BOOT_SEG 0xffff0000 /* linear segment of boot code */
  31. #define a32 .byte 0x67;
  32. #define o32 .byte 0x66;
  33. .section .start16, "ax"
  34. .code16
  35. .globl start16
  36. start16:
  37. /* Set the Cold Boot / Hard Reset flag */
  38. movl $GD_FLG_COLD_BOOT, %ebx
  39. /*
  40. * First we let the BSP do some early initialization
  41. * this code have to map the flash to its final position
  42. */
  43. jmp board_init16
  44. .globl board_init16_ret
  45. board_init16_ret:
  46. /* Turn of cache (this might require a 486-class CPU) */
  47. movl %cr0, %eax
  48. orl $(X86_CR0_NW | X86_CR0_CD), %eax
  49. movl %eax, %cr0
  50. wbinvd
  51. /* load the temporary Global Descriptor Table */
  52. o32 cs lidt idt_ptr
  53. o32 cs lgdt gdt_ptr
  54. /* Now, we enter protected mode */
  55. movl %cr0, %eax
  56. orl $X86_CR0_PE, %eax
  57. movl %eax, %cr0
  58. /* Flush the prefetch queue */
  59. jmp ff
  60. ff:
  61. /* Finally jump to the 32bit initialization code */
  62. movw $code32start, %ax
  63. movw %ax, %bp
  64. o32 cs ljmp *(%bp)
  65. /* 48-bit far pointer */
  66. code32start:
  67. .long _start /* offset */
  68. .word 0x10 /* segment */
  69. idt_ptr:
  70. .word 0 /* limit */
  71. .long 0 /* base */
  72. /*
  73. * The following Global Descriptor Table is just enough to get us into
  74. * 'Flat Protected Mode' - It will be discarded as soon as the final
  75. * GDT is setup in a safe location in RAM
  76. */
  77. gdt_ptr:
  78. .word 0x20 /* limit (32 bytes = 4 GDT entries) */
  79. .long BOOT_SEG + gdt /* base */
  80. /* Some CPUs are picky about GDT alignment... */
  81. .align 16
  82. gdt:
  83. /*
  84. * The GDT table ...
  85. *
  86. * Selector Type
  87. * 0x00 NULL
  88. * 0x08 Unused
  89. * 0x10 32bit code
  90. * 0x18 32bit data/stack
  91. */
  92. /* The NULL Desciptor - Mandatory */
  93. .word 0x0000 /* limit_low */
  94. .word 0x0000 /* base_low */
  95. .byte 0x00 /* base_middle */
  96. .byte 0x00 /* access */
  97. .byte 0x00 /* flags + limit_high */
  98. .byte 0x00 /* base_high */
  99. /* Unused Desciptor - (matches Linux) */
  100. .word 0x0000 /* limit_low */
  101. .word 0x0000 /* base_low */
  102. .byte 0x00 /* base_middle */
  103. .byte 0x00 /* access */
  104. .byte 0x00 /* flags + limit_high */
  105. .byte 0x00 /* base_high */
  106. /*
  107. * The Code Segment Descriptor:
  108. * - Base = 0x00000000
  109. * - Size = 4GB
  110. * - Access = Present, Ring 0, Exec (Code), Readable
  111. * - Flags = 4kB Granularity, 32-bit
  112. */
  113. .word 0xffff /* limit_low */
  114. .word 0x0000 /* base_low */
  115. .byte 0x00 /* base_middle */
  116. .byte 0x9b /* access */
  117. .byte 0xcf /* flags + limit_high */
  118. .byte 0x00 /* base_high */
  119. /*
  120. * The Data Segment Descriptor:
  121. * - Base = 0x00000000
  122. * - Size = 4GB
  123. * - Access = Present, Ring 0, Non-Exec (Data), Writable
  124. * - Flags = 4kB Granularity, 32-bit
  125. */
  126. .word 0xffff /* limit_low */
  127. .word 0x0000 /* base_low */
  128. .byte 0x00 /* base_middle */
  129. .byte 0x93 /* access */
  130. .byte 0xcf /* flags + limit_high */
  131. .byte 0x00 /* base_high */