int.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /* Copyright (C) 2021 Rain */
  2. /* This file is part of XNIX. */
  3. /*
  4. XNIX is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) and later version.
  8. */
  9. /*
  10. XNIX 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. /*
  16. You should have received a copy of the GNU General Public License
  17. along with XNIX. If not, see <https://www.gnu.org/licenses/>.
  18. */
  19. #include <kernel/init.h>
  20. #include <kernel/errno.h>
  21. #include <kernel/types.h>
  22. #include <arch/x86/int.h>
  23. #include <arch/io.h>
  24. #include <arch/sys.h>
  25. #include <modules/tty.h>
  26. int init_int(void) {
  27. /* init PIC */
  28. /* disable all irqs */
  29. /* IMR: interrupt mask register */
  30. // outb(0xff, PIC0_IMR);
  31. // outb(0xff, PIC1_IMR);
  32. /* ICW: initial control word */
  33. // outb(0x11, PIC0_ICW1);
  34. // outb(0x20, PIC0_ICW2);
  35. // outb(0x04, PIC0_ICW3);
  36. // outb(0x01, PIC0_ICW4);
  37. // outb(0x11, PIC1_ICW1);
  38. // outb(0x28, PIC1_ICW2);
  39. // outb(0x02, PIC1_ICW3);
  40. // outb(0x01, PIC1_ICW4);
  41. /* enable all interrupts */
  42. // outb(0x00, PIC0_IMR);
  43. // outb(0x00, PIC1_IMR);
  44. set_int_gate(idt_table + 0x80, 0, syscall);
  45. return 0;
  46. }
  47. void set_gate(struct idt_entry *entry, char attr, char ist, void *addr) {
  48. #define handler ((__uint64_t) addr)
  49. entry->selector = KERNEL_CS;
  50. entry->ist = ist;
  51. entry->attr = attr;
  52. entry->off_0_16 = handler & 0xffff;
  53. entry->off_16_32 = handler >> 16;
  54. entry->off_32_64 = handler >> 32;
  55. entry->zero = 0x00000000;
  56. return;
  57. }
  58. void syscall(void) {
  59. printf("int #0x80: system call. \n");
  60. for (;;);
  61. }