<commit_before>#include <stdbool.h>
#include <kernel/idt.h>

extern void isr_stub_0(void);
extern void isr_stub_1(void);
extern void isr_stub_128(void);

void idt_set_entry(volatile struct IDTEntry *entry, void (*handler)(void), bool restricted) {
	uint32_t base_address = (uint32_t)handler;
	entry->base_address_low = base_address & 0xFFFF;
	entry->base_address_high = (base_address >> 16) & 0xFFFF;
	entry->selector = 0x8;
	entry->reserved = 0;
	entry->type = 0xE; /* 80386 32-bit interrupt gate */
	entry->storage_segment = 0; /* 0 for interrupt gates */
	entry->privilege = restricted ? 0 : 3;
	entry->present = 1;
}

void idt_init(volatile struct IDT *idt) {
	idt->descriptor.limiter = sizeof(idt->entries);
	idt->descriptor.base_address = &idt->entries;

	uint32_t stub_size = (uint32_t)isr_stub_1 - (uint32_t)isr_stub_0;

	uint16_t entry;
	for(entry = 0; entry < 128; ++entry) {
		idt_set_entry(&idt->entries[entry], isr_stub_0 + entry * stub_size, true);
	}
	idt_set_entry(&idt->entries[128], isr_stub_128, false);

	__asm__ ("lidt (%0)" : : "r" (&idt->descriptor));
}<commit_msg>Inline set_entry for further reduced object size<commit_after>#include <stdbool.h>
#include <kernel/idt.h>

extern void isr_stub_0(void);
extern void isr_stub_1(void);
extern void isr_stub_128(void);

inline void set_entry(volatile struct IDTEntry *entry, void (*handler)(void), bool restricted) {
	uint32_t base_address = (uint32_t)handler;
	entry->base_address_low = base_address & 0xFFFF;
	entry->base_address_high = (base_address >> 16) & 0xFFFF;
	entry->selector = 0x8;
	entry->reserved = 0;
	entry->type = 0xE; /* 80386 32-bit interrupt gate */
	entry->storage_segment = 0; /* 0 for interrupt gates */
	entry->privilege = restricted ? 0 : 3;
	entry->present = 1;
}

void idt_init(volatile struct IDT *idt) {
	idt->descriptor.limiter = sizeof(idt->entries);
	idt->descriptor.base_address = &idt->entries;

	uint32_t stub_size = (uint32_t)isr_stub_1 - (uint32_t)isr_stub_0;

	uint16_t entry;
	for(entry = 0; entry < 128; ++entry) {
		set_entry(&idt->entries[entry], isr_stub_0 + entry * stub_size, true);
	}
	set_entry(&idt->entries[128], isr_stub_128, false);

	__asm__ ("lidt (%0)" : : "r" (&idt->descriptor));
}
{'fraction_non_alphanumeric': 0.14959202175883954, 'fraction_numerical': 0.04623753399818677, 'mean_word_length': 5.305714285714286, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 41, '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': '5643387', 'n_tokens_mistral': 933, 'n_tokens_neox': 860, 'n_words': 181}