start16.S 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. * U-boot - i386 Startup Code
  3. *
  4. * Copyright (c) 2002 Omicron Ceti AB, Daniel Engström <denaiel@omicron.se>
  5. *
  6. * See file CREDITS for list of people who contributed to this
  7. * project.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation; either version 2 of
  12. * the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  22. * MA 02111-1307 USA
  23. */
  24. #define BOOT_SEG 0xffff0000 /* linear segment of boot code */
  25. #define a32 .byte 0x67;
  26. #define o32 .byte 0x66;
  27. .section .start16, "ax"
  28. .code16
  29. .globl start16
  30. start16:
  31. /* First we let the BSP do some early initialization
  32. * this code have to map the flash to its final position
  33. */
  34. mov $board_init16_ret, %bp
  35. jmp board_init16
  36. board_init16_ret:
  37. /* Turn of cache (this might require a 486-class CPU) */
  38. movl %cr0, %eax
  39. orl $060000000,%eax
  40. movl %eax, %cr0
  41. wbinvd
  42. /* load the descriptor tables */
  43. o32 cs lidt idt_ptr
  44. o32 cs lgdt gdt_ptr
  45. /* Now, we enter protected mode */
  46. movl %cr0, %eax
  47. orl $1,%eax
  48. movl %eax, %cr0
  49. /* Flush the prefetch queue */
  50. jmp ff
  51. ff:
  52. /* Finally jump to the 32bit initialization code */
  53. movw $code32start, %ax
  54. movw %ax,%bp
  55. o32 cs ljmp *(%bp)
  56. /* 48-bit far pointer */
  57. code32start:
  58. .long _start /* offset */
  59. .word 0x10 /* segment */
  60. idt_ptr:
  61. .word 0 /* limit */
  62. .long 0 /* base */
  63. gdt_ptr:
  64. .word 0x30 /* limit (48 bytes = 6 GDT entries) */
  65. .long BOOT_SEG + gdt /* base */
  66. /* The GDT table ...
  67. *
  68. * Selector Type
  69. * 0x00 NULL
  70. * 0x08 Unused
  71. * 0x10 32bit code
  72. * 0x18 32bit data/stack
  73. * 0x20 16bit code
  74. * 0x28 16bit data/stack
  75. */
  76. gdt:
  77. .word 0, 0, 0, 0 /* NULL */
  78. .word 0, 0, 0, 0 /* unused */
  79. .word 0xFFFF /* 4Gb - (0x100000*0x1000 = 4Gb) */
  80. .word 0 /* base address = 0 */
  81. .word 0x9B00 /* code read/exec */
  82. .word 0x00CF /* granularity = 4096, 386 (+5th nibble of limit) */
  83. .word 0xFFFF /* 4Gb - (0x100000*0x1000 = 4Gb) */
  84. .word 0x0 /* base address = 0 */
  85. .word 0x9300 /* data read/write */
  86. .word 0x00CF /* granularity = 4096, 386 (+5th nibble of limit) */
  87. .word 0xFFFF /* 64kb */
  88. .word 0 /* base address = 0 */
  89. .word 0x9b00 /* data read/write */
  90. .word 0x0010 /* granularity = 1 (+5th nibble of limit) */
  91. .word 0xFFFF /* 64kb */
  92. .word 0 /* base address = 0 */
  93. .word 0x9300 /* data read/write */
  94. .word 0x0010 /* granularity = 1 (+5th nibble of limit) */