| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- /* Copyright (C) 2021 Rain */
- /* This file is part of XNIX. */
- /*
- XNIX is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) and later version.
- */
- /*
- XNIX is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- */
- /*
- You should have received a copy of the GNU General Public License
- along with XNIX. If not, see <https://www.gnu.org/licenses/>.
- */
- #include <kernel/init.h>
- #include <kernel/errno.h>
- #include <kernel/types.h>
- #include <arch/x86/int.h>
- #include <arch/io.h>
- #include <arch/sys.h>
- #include <modules/tty.h>
- int init_int(void) {
- /* init PIC */
- /* disable all irqs */
- /* IMR: interrupt mask register */
- outb(0xff, PIC0_IMR);
- outb(0xff, PIC1_IMR);
- /* ICW: initial control word */
- outb(0x11, PIC0_ICW1);
- outb(0x20, PIC0_ICW2);
- outb(0x04, PIC0_ICW3);
- outb(0x01, PIC0_ICW4);
- outb(0x11, PIC1_ICW1);
- outb(0x28, PIC1_ICW2);
- outb(0x02, PIC1_ICW3);
- outb(0x01, PIC1_ICW4);
- /* enable all interrupts */
- outb(0x00, PIC0_IMR);
- outb(0x00, PIC1_IMR);
- set_int_gate(idt_table + 0x00, 0, divide_error);
- set_int_gate(idt_table + 0x80, 0, syscall);
- return 0;
- }
- void set_gate(struct idt_entry *entry, char attr, char ist, void *addr) {
- #define handler ((__uint64_t) addr)
- entry->selector = KERNEL_CS;
- entry->ist = ist;
- entry->attr = attr;
- entry->off_0_16 = handler & 0xffff;
- entry->off_16_32 = handler >> 16;
- entry->off_32_64 = handler >> 32;
- entry->zero = 0x00000000;
- return;
- }
- void syscall(void) {
- printf("int #0x80: system call. \n");
- for (;;);
- }
- void do_divide_error(__uint64_t *rsp) {
- printf("int #0x00: divide error. \n");
- printf("RSP: %q\n", rsp);
- return;
- }
|