start16.S 2.8 KB

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