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