head32.S 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /* arch/x86/init/head32.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. .code32
  19. .globl _start
  20. _start:
  21. /* we are now in the protected-mode, just
  22. * do some initializes, and call main */
  23. lgdt gdt_descr
  24. call init_idt
  25. movl $0xc0000000, %eax
  26. leal 1f, %ecx
  27. orl %ecx, %eax
  28. pushl %eax
  29. movl $0xc0000000, %eax
  30. leal init, %ecx
  31. orl %ecx, %eax
  32. pushl %eax
  33. retl
  34. 1: hlt
  35. jmp 1b
  36. init_idt:
  37. /* edx: high 32 eax: low 32 */
  38. leal default_int_handler, %edx
  39. /* KERNEL_CS */
  40. movl %edx, %eax
  41. andl $0x0000ffff, %eax
  42. addl $(8 << 16), %eax
  43. andl $0xffff0000, %edx
  44. addl $0x8e00, %edx
  45. movl $256, %ecx
  46. leal idt, %edi
  47. rsidt: movl %eax, (%edi)
  48. movl %edx, 4(%edi)
  49. addl $8, %edi
  50. decl %ecx
  51. jnz rsidt
  52. lidt idt_descr
  53. ret
  54. default_int_handler:
  55. incl 0xb8000
  56. iretl
  57. .globl ret_intr
  58. ret_intr:
  59. popl %eax
  60. movl %eax, %gs
  61. popl %eax
  62. movl %eax, %fs
  63. popl %eax
  64. movl %eax, %es
  65. popl %eax
  66. movl %eax, %ds
  67. popl %edi
  68. popl %esi
  69. popl %ebp
  70. popl %edx
  71. popl %ebx
  72. popl %ecx
  73. popl %eax
  74. popfl
  75. iretl
  76. .globl __stack_chk_fail, __stack_chk_fail_local
  77. __stack_chk_fail_local:
  78. __stack_chk_fail:
  79. hlt
  80. jmp __stack_chk_fail
  81. .data
  82. .align 16
  83. .globl gdt
  84. gdt: .long 0x00000000, 0x00000000
  85. .long 0x0000ffff, 0x00cf9a00
  86. .long 0x0000ffff, 0x00cf9200
  87. .globl gdt_descr
  88. gdt_descr:
  89. .word . - gdt
  90. .long gdt
  91. .align 16
  92. .globl idt
  93. idt: .fill 256, 8, 0
  94. .globl idt_descr
  95. idt_descr:
  96. .word . - idt
  97. .long idt