start16.S 3.0 KB

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