start16.S 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. /* The GDT table ...
  81. *
  82. * Selector Type
  83. * 0x00 NULL
  84. * 0x08 Unused
  85. * 0x10 32bit code
  86. * 0x18 32bit data/stack
  87. */
  88. gdt:
  89. .word 0, 0, 0, 0 /* NULL */
  90. .word 0, 0, 0, 0 /* unused */
  91. .word 0xFFFF /* 4Gb - (0x100000*0x1000 = 4Gb) */
  92. .word 0 /* base address = 0 */
  93. .word 0x9B00 /* code read/exec */
  94. .word 0x00CF /* granularity = 4096, 386 (+5th nibble of limit) */
  95. .word 0xFFFF /* 4Gb - (0x100000*0x1000 = 4Gb) */
  96. .word 0x0 /* base address = 0 */
  97. .word 0x9300 /* data read/write */
  98. .word 0x00CF /* granularity = 4096, 386 (+5th nibble of limit) */