head32.S 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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 __stack_chk_fail, __stack_chk_fail_local
  58. __stack_chk_fail_local:
  59. __stack_chk_fail:
  60. hlt
  61. jmp __stack_chk_fail
  62. .data
  63. .align 16
  64. .globl gdt
  65. gdt: .long 0x00000000, 0x00000000
  66. .long 0x0000ffff, 0x00cf9a00
  67. .long 0x0000ffff, 0x00cf9200
  68. .globl gdt_descr
  69. gdt_descr:
  70. .word . - gdt
  71. .long gdt
  72. .align 16
  73. .globl idt
  74. idt: .fill 256, 8, 0
  75. .globl idt_descr
  76. idt_descr:
  77. .word . - idt
  78. .long idt