start16.S 2.9 KB

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