setup32.S 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /* arch/x86/boot/setup32.S
  2. *
  3. * This file is part of evx.
  4. *
  5. * evx is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * evx is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with evx. If not, see <https://www.gnu.org/licenses/>
  17. */
  18. .code16
  19. /* switch to the protected-mode, and to real system */
  20. .globl _start
  21. _start: xorw %ax, %ax
  22. movw %ax, %ds
  23. movw %ax, %es
  24. movw %ax, %ss
  25. /* yeah, we should move it again. */
  26. movw $0x7e00, %di
  27. movw $0x8000, %si
  28. movw $512, %cx
  29. cld
  30. rep
  31. movsb
  32. movw $0x7c00, %sp
  33. ljmp $0, $real_start
  34. real_start:
  35. /* open a20 */
  36. cli
  37. inb $0x92, %al
  38. orb $0x02, %al
  39. outb %al, $0x92
  40. /* setup idt and gdt */
  41. lgdt gdt32_descr
  42. movl %cr0, %eax
  43. orl $1, %eax
  44. /* that's it! */
  45. movl %eax, %cr0
  46. /* setup paging */
  47. movl $0, %edi
  48. movl $512, %ecx
  49. xorl %eax, %eax
  50. cld
  51. rsetpt: rep
  52. stosl
  53. movl $0x00001007, 0
  54. movl $0x00001007, 0xc00
  55. movl $0x1000, %edi
  56. movl $1024, %ecx
  57. movl $0x00000007, %eax
  58. rsetp: stosl
  59. addl $4096, %eax
  60. loop rsetp
  61. xorl %eax, %eax
  62. movl %eax, %cr3
  63. movl %cr0, %eax
  64. orl $0x80000000, %eax
  65. movl %eax, %cr0
  66. ljmp $0x08, $init_prot
  67. .code32
  68. init_prot:
  69. movl $0x10, %eax
  70. movl %eax, %ds
  71. movl %eax, %es
  72. movl %eax, %fs
  73. movl %eax, %gs
  74. movl %eax, %ss
  75. movl $0x7c00, %esp
  76. /* move it to 1mb */
  77. movl $1048576, %edi
  78. movl $0x8200, %esi
  79. movl $131072, %ecx
  80. cld
  81. rep
  82. movsl
  83. ljmp $0x08, $1048576
  84. .globl gdt32
  85. gdt32: .long 0x00000000, 0x00000000
  86. .long 0x0000ffff, 0x00cf9a00
  87. .long 0x0000ffff, 0x00cf9200
  88. .globl gdt32_descr
  89. gdt32_descr:
  90. .word . - gdt32
  91. .long gdt32