how do i get irq_install_handler()?
Posted: Thu Mar 12, 2020 11:27 pm
i am following this tutorial:viewtopic.php?f=1&t=10247&start=0
but i need this function: irq_install_handler().
but i need this function: irq_install_handler().
The Place to Start for Operating System Developers
http://f.osdev.org/
Code: Select all
#include "idt.h"
#include "util.h"
void irq_install_handler(int n, uint32 handler) {
idt[n].low_offset = low_16(handler);
idt[n].sel = KERNEL_CS;
idt[n].always0 = 0;
idt[n].flags = 0x8E;
idt[n].high_offset = high_16(handler);
}
void set_idt() {
idt_reg.base = (uint32) &idt;
idt_reg.limit = IDT_ENTRIES * sizeof(idt_gate_t) - 1;
__asm__ __volatile__("lidtl (%0)" : : "r" (&idt_reg));
}
Code: Select all
#ifndef IDT_H
#define IDT_H
#include "types.h"
#define KERNEL_CS 0x08
typedef struct {
uint16 low_offset;
uint16 sel;
uint8 always0;
uint8 flags;
uint16 high_offset;
} __attribute__((packed)) idt_gate_t ;
typedef struct {
uint16 limit;
uint32 base;
} __attribute__((packed)) idt_register_t;
#define IDT_ENTRIES 256
idt_gate_t idt[IDT_ENTRIES];
idt_register_t idt_reg;
void irq_install_handler(int n, uint32 handler);
void set_idt();
#endif
Code: Select all
#include "util.h"
void memory_copy(char *source, char *dest, int nbytes) {
int i;
for (i = 0; i < nbytes; i++) {
*(dest + i) = *(source + i);
}
}
void memory_set(uint8 *dest, uint8 val, uint32 len) {
uint8 *temp = (uint8 *)dest;
for ( ; len != 0; len--) *temp++ = val;
}
void int_to_ascii(int n, char str[]) {
int i, sign;
if ((sign = n) < 0) n = -n;
i = 0;
do {
str[i++] = n % 10 + '0';
} while ((n /= 10) > 0);
if (sign < 0) str[i++] = '-';
str[i] = '\0';
}
Code: Select all
#ifndef UTIL_H
#define UTIL_H
#include "types.h"
void memory_copy(char *source, char *dest, int nbytes);
void memory_set(uint8 *dest, uint8 val, uint32 len);
void int_to_ascii(int n, char str[]);
Code: Select all
void irq_install_handler()(int n, uint32 handler)
C's syntax is disturbingly flexible. This looks like a fusion of the feature allowing parameter types to be declared after the parameters, the empty argument list meaning a variable number of arguments, and parentheses being applicable just-about anywhere because almost everything is an expression. It's a bad idea to allow a variable number of arguments here; it'll needlessly fail to catch some errors. The whole line is exceedingly uncommon practice. We have better syntax for "varargs" now and putting type declaration after the parameters is pointless; no-one does it.Schol-R-LEA wrote:Is this even a valid C function declaration at all, and if it is, what are its parameters?Code: Select all
void irq_install_handler()(int n, uint32 handler)