start16.S 2.8 KB

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