start16.S 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. /*
  38. * First we let the BSP do some early initialization
  39. * this code have to map the flash to its final position
  40. */
  41. jmp board_init16
  42. .globl board_init16_ret
  43. board_init16_ret:
  44. /* Turn of cache (this might require a 486-class CPU) */
  45. movl %cr0, %eax
  46. orl $(X86_CR0_NW | X86_CR0_CD), %eax
  47. movl %eax, %cr0
  48. wbinvd
  49. /* load the temporary Global Descriptor Table */
  50. o32 cs lidt idt_ptr
  51. o32 cs lgdt gdt_ptr
  52. /* Now, we enter protected mode */
  53. movl %cr0, %eax
  54. orl $X86_CR0_PE, %eax
  55. movl %eax, %cr0
  56. /* Flush the prefetch queue */
  57. jmp ff
  58. ff:
  59. /* Finally jump to the 32bit initialization code */
  60. movw $code32start, %ax
  61. movw %ax, %bp
  62. o32 cs ljmp *(%bp)
  63. /* 48-bit far pointer */
  64. code32start:
  65. .long _start /* offset */
  66. .word 0x10 /* segment */
  67. idt_ptr:
  68. .word 0 /* limit */
  69. .long 0 /* base */
  70. /*
  71. * The following Global Descriptor Table is just enough to get us into
  72. * 'Flat Protected Mode' - It will be discarded as soon as the final
  73. * GDT is setup in a safe location in RAM
  74. */
  75. gdt_ptr:
  76. .word 0x20 /* limit (32 bytes = 4 GDT entries) */
  77. .long BOOT_SEG + gdt /* base */
  78. /* The GDT table ...
  79. *
  80. * Selector Type
  81. * 0x00 NULL
  82. * 0x08 Unused
  83. * 0x10 32bit code
  84. * 0x18 32bit data/stack
  85. */
  86. gdt:
  87. .word 0, 0, 0, 0 /* NULL */
  88. .word 0, 0, 0, 0 /* unused */
  89. .word 0xFFFF /* 4Gb - (0x100000*0x1000 = 4Gb) */
  90. .word 0 /* base address = 0 */
  91. .word 0x9B00 /* code read/exec */
  92. .word 0x00CF /* granularity = 4096, 386 (+5th nibble of limit) */
  93. .word 0xFFFF /* 4Gb - (0x100000*0x1000 = 4Gb) */
  94. .word 0x0 /* base address = 0 */
  95. .word 0x9300 /* data read/write */
  96. .word 0x00CF /* granularity = 4096, 386 (+5th nibble of limit) */