<commit_before>#include <stddef.h>

#include "init/initcall.h"
#include "common/compiler.h"
#include "common/asm.h"
#include "common/list.h"
#include "bug/debug.h"
#include "bug/panic.h"
#include "arch/idt.h"
#include "arch/gdt.h"
#include "arch/cpl.h"
#include "arch/pit.h"
#include "mm/cache.h"
#include "sched/sched.h"
#include "video/log.h"

//command io port of PICs
#define MASTER_COMMAND 0x20
#define SLAVE_COMMAND  0xA0

//data io port of PICs
#define MASTER_DATA 0x21
#define SLAVE_DATA  0xA1

//PIC commands
#define INIT 0x11 //enter "init" mode
#define EOI  0x20 //end of interrupt handler

#define PIC_REG_IRR 0x0A
#define PIC_REG_ISR 0x0B

static void pic_eoi(uint32_t vector) {
    if(vector > PIC_SLAVE_OFFSET + PIC_NUM_PINS) return;

    if(vector >= PIC_SLAVE_OFFSET && vector != INT_SPURIOUS_SLAVE) {
        outb(SLAVE_COMMAND , EOI);
    }

    if(vector != INT_SPURIOUS_MASTER) {
        outb(MASTER_COMMAND, EOI);
    }
}

void __init pic_init() {
    eoi_handler = pic_eoi;

    //send INIT command
    outb(MASTER_COMMAND, INIT);
    outb(SLAVE_COMMAND , INIT);

    //set interrupt vector offset
    outb(MASTER_DATA, PIC_MASTER_OFFSET);
    outb(SLAVE_DATA , PIC_SLAVE_OFFSET);

    //set master/slave status
    outb(MASTER_DATA, 2);
    outb(SLAVE_DATA , 4);

    //set mode
    outb(MASTER_DATA, 0x05);
    outb(SLAVE_DATA , 0x01);

    //clear IRQ masks
    outb(MASTER_DATA, 0x0);
    outb(SLAVE_DATA , 0x0);

    sti();<commit_msg>Fix PIC not sending EOI on IRQ 15 interrupts<commit_after>#include <stddef.h>

#include "init/initcall.h"
#include "common/compiler.h"
#include "common/asm.h"
#include "common/list.h"
#include "bug/debug.h"
#include "bug/panic.h"
#include "arch/idt.h"
#include "arch/gdt.h"
#include "arch/cpl.h"
#include "arch/pit.h"
#include "mm/cache.h"
#include "sched/sched.h"
#include "video/log.h"

//command io port of PICs
#define MASTER_COMMAND 0x20
#define SLAVE_COMMAND  0xA0

//data io port of PICs
#define MASTER_DATA 0x21
#define SLAVE_DATA  0xA1

//PIC commands
#define INIT 0x11 //enter "init" mode
#define EOI  0x20 //end of interrupt handler

#define PIC_REG_IRR 0x0A
#define PIC_REG_ISR 0x0B

static void pic_eoi(uint32_t vector) {
    if(vector > PIC_SLAVE_OFFSET + PIC_NUM_PINS) return;

    //don't ignore INT_SPURIOUS_MASTER interrupts because that is the IDE
    //secondary IRQ vector
    if(vector >= PIC_SLAVE_OFFSET) {
        outb(SLAVE_COMMAND, EOI);
    }

    if(vector != INT_SPURIOUS_MASTER) {
        outb(MASTER_COMMAND, EOI);
    }
}

void __init pic_init() {
    eoi_handler = pic_eoi;

    //send INIT command
    outb(MASTER_COMMAND, INIT);
    outb(SLAVE_COMMAND , INIT);

    //set interrupt vector offset
    outb(MASTER_DATA, PIC_MASTER_OFFSET);
    outb(SLAVE_DATA , PIC_SLAVE_OFFSET);

    //set master/slave status
    outb(MASTER_DATA, 2);
    outb(SLAVE_DATA , 4);

    //set mode
    outb(MASTER_DATA, 0x05);
    outb(SLAVE_DATA , 0x01);

    //clear IRQ masks
    outb(MASTER_DATA, 0x0);
    outb(SLAVE_DATA , 0x0);

    sti();
{'fraction_non_alphanumeric': 0.12198347107438016, 'fraction_numerical': 0.023140495867768594, 'mean_word_length': 3.5435435435435436, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5071474', 'n_tokens_mistral': 1310, 'n_tokens_neox': 1255, 'n_words': 277}