start16.S 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. * SPDX-License-Identifier: GPL-2.0+
  11. */
  12. #include <asm/global_data.h>
  13. #include <asm/processor-flags.h>
  14. #define BOOT_SEG 0xffff0000 /* linear segment of boot code */
  15. #define a32 .byte 0x67;
  16. #define o32 .byte 0x66;
  17. .section .start16, "ax"
  18. .code16
  19. .globl start16
  20. start16:
  21. /* Save BIST */
  22. movl %eax, %ecx
  23. /* Set the Cold Boot / Hard Reset flag */
  24. movl $GD_FLG_COLD_BOOT, %ebx
  25. xorl %eax, %eax
  26. movl %eax, %cr3 /* Invalidate TLB */
  27. /* Turn off cache (this might require a 486-class CPU) */
  28. movl %cr0, %eax
  29. orl $(X86_CR0_NW | X86_CR0_CD), %eax
  30. movl %eax, %cr0
  31. wbinvd
  32. /* load the temporary Global Descriptor Table */
  33. o32 cs lidt idt_ptr
  34. o32 cs lgdt gdt_ptr
  35. /* Now, we enter protected mode */
  36. movl %cr0, %eax
  37. orl $X86_CR0_PE, %eax
  38. movl %eax, %cr0
  39. /* Flush the prefetch queue */
  40. jmp ff
  41. ff:
  42. /* Finally restore BIST and jump to the 32-bit initialization code */
  43. movw $code32start, %ax
  44. movw %ax, %bp
  45. movl %ecx, %eax
  46. o32 cs ljmp *(%bp)
  47. /* 48-bit far pointer */
  48. code32start:
  49. .long _start /* offset */
  50. .word 0x10 /* segment */
  51. idt_ptr:
  52. .word 0 /* limit */
  53. .long 0 /* base */
  54. /*
  55. * The following Global Descriptor Table is just enough to get us into
  56. * 'Flat Protected Mode' - It will be discarded as soon as the final
  57. * GDT is setup in a safe location in RAM
  58. */
  59. gdt_ptr:
  60. .word 0x1f /* limit (31 bytes = 4 GDT entries - 1) */
  61. .long BOOT_SEG + gdt_rom /* base */
  62. /* Some CPUs are picky about GDT alignment... */
  63. .align 16
  64. .globl gdt_rom
  65. gdt_rom:
  66. /*
  67. * The GDT table ...
  68. *
  69. * Selector Type
  70. * 0x00 NULL
  71. * 0x08 Unused
  72. * 0x10 32bit code
  73. * 0x18 32bit data/stack
  74. */
  75. /* The NULL Desciptor - Mandatory */
  76. .word 0x0000 /* limit_low */
  77. .word 0x0000 /* base_low */
  78. .byte 0x00 /* base_middle */
  79. .byte 0x00 /* access */
  80. .byte 0x00 /* flags + limit_high */
  81. .byte 0x00 /* base_high */
  82. /* Unused Desciptor - (matches Linux) */
  83. .word 0x0000 /* limit_low */
  84. .word 0x0000 /* base_low */
  85. .byte 0x00 /* base_middle */
  86. .byte 0x00 /* access */
  87. .byte 0x00 /* flags + limit_high */
  88. .byte 0x00 /* base_high */
  89. /*
  90. * The Code Segment Descriptor:
  91. * - Base = 0x00000000
  92. * - Size = 4GB
  93. * - Access = Present, Ring 0, Exec (Code), Readable
  94. * - Flags = 4kB Granularity, 32-bit
  95. */
  96. .word 0xffff /* limit_low */
  97. .word 0x0000 /* base_low */
  98. .byte 0x00 /* base_middle */
  99. .byte 0x9b /* access */
  100. .byte 0xcf /* flags + limit_high */
  101. .byte 0x00 /* base_high */
  102. /*
  103. * The Data Segment Descriptor:
  104. * - Base = 0x00000000
  105. * - Size = 4GB
  106. * - Access = Present, Ring 0, Non-Exec (Data), Writable
  107. * - Flags = 4kB Granularity, 32-bit
  108. */
  109. .word 0xffff /* limit_low */
  110. .word 0x0000 /* base_low */
  111. .byte 0x00 /* base_middle */
  112. .byte 0x93 /* access */
  113. .byte 0xcf /* flags + limit_high */
  114. .byte 0x00 /* base_high */