| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- /* 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 <kernel/graphic.h>
- #include <arch/x86/int.h>
- #include <arch/io.h>
- #include <arch/sys.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) {
- print(0x00ff0000, 0x00, "int #0x80: system call. \n");
- return;
- }
- void die(char *s, __uint64_t *rsp, char nr) {
- print(0x00ff0000, 0x00, "int #%b: %s. \n");
- for (;;);
- }
- void do_divide_error(__uint64_t *rsp) {
- die("divide error", rsp, 0);
- return;
- }
|