arch_int.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /* arch/x86/kernel/arch_int.c
  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. #include <kernel/init.h>
  19. #include <kernel/module.h>
  20. #include <kernel/mm.h>
  21. #include <kernel/kernel.h>
  22. #include <kernel/kmlog.h>
  23. #include <arch/archinfo.h>
  24. #include <arch/mm.h>
  25. #include <arch/int.h>
  26. #include <arch/string.h>
  27. #include <sys/types.h>
  28. #include <config.h>
  29. /* head$(BITS).S */
  30. /* extern struct idt_entry *idt; things interesting.
  31. * a struct idt_entry *idt, and that is a pointer. idt, is
  32. * the address.
  33. *
  34. * a struct idt_entry idt[], and that is an array. */
  35. extern struct idt_entry idt[256];
  36. static int set_gate(struct idt_entry *, void (*) (void), int attr);
  37. /* set the handlers for traps, 0 - 31 */
  38. int __init arch_traps_init(void) {
  39. set_gate(idt + 0x80, NULL, 0x8e);
  40. return 0;
  41. }
  42. static int set_gate(struct idt_entry *entry, void (* handler) (void), int attr) {
  43. /* no ist support in long-mode, well, that's not so useful */
  44. __archptr_t p = (__archptr_t) handler;
  45. entry->off_0 = p & 0xffffu;
  46. entry->seg = 8;
  47. #if CONFIG_64BIT
  48. entry->ist =
  49. #else
  50. entry->resv =
  51. #endif
  52. 0;
  53. entry->attr = attr;
  54. entry->off_1 = (p >> 16u) & 0xffffu;
  55. #if CONFIG_64BIT
  56. entry->off_2 = p >> 32u;
  57. entry->zero = 0;
  58. #endif
  59. return 0;
  60. }
  61. arch_init(arch_traps_init);