how do i get irq_install_handler()?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
haybame
Posts: 16
Joined: Mon Mar 09, 2020 5:06 pm
Libera.chat IRC: haybame

how do i get irq_install_handler()?

Post by haybame »

i am following this tutorial:viewtopic.php?f=1&t=10247&start=0
but i need this function: irq_install_handler().
User avatar
iansjack
Member
Member
Posts: 4703
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: how do i get irq_install_handler()?

Post by iansjack »

It's just a function to install an interrupt handler. You have to write it for yourself. Presumably you have already set up other interrupt handlers for keyboard etc.

Tutorials are just examples of how to do things. Don't follow them blindly.
haybame
Posts: 16
Joined: Mon Mar 09, 2020 5:06 pm
Libera.chat IRC: haybame

Re: how do i get irq_install_handler()?

Post by haybame »

how do i write a interrupt handler for this?
User avatar
iansjack
Member
Member
Posts: 4703
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: how do i get irq_install_handler()?

Post by iansjack »

You are, seemingly, asking others to write your OS for you without you doing any research or background reading.

Are you sure that OS development is the right hobby for you with your current level of expertise? You might find it more rewarding to start with less ambitious projects. Learn how to read documentation and how to search the Internet for information, then come back to OS development more prepared for the task.
haybame
Posts: 16
Joined: Mon Mar 09, 2020 5:06 pm
Libera.chat IRC: haybame

Re: how do i get irq_install_handler()?

Post by haybame »

i am very new to this.

edit
i got it working i had to add a interrupt like this:

idt.c

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));
}
idt.h

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
util.c

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';
}
util.h

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[]);          

screen.png
screen.png (4.89 KiB) Viewed 1885 times
ps thanks for the help
Last edited by haybame on Sat Mar 14, 2020 3:18 pm, edited 1 time in total.
User avatar
Schol-R-LEA
Member
Member
Posts: 1925
Joined: Fri Oct 27, 2006 9:42 am
Location: Athens, GA, USA

Re: how do i get irq_install_handler()?

Post by Schol-R-LEA »

You've shown us the code you wrote (or copied, perhaps) for irq_install_handler(), but not where you are calling it, and more importantly, you haven't shown us the actual interrupt handler code you are using (hint: the code in the linked page is only for handling the mouse movement interrupt, those needed for any other interrupts you might need to handle such as mouse button input, keyboard input, timer interrupts, etc. would need to also be written and added).

Also, are you really sure that the function declaration

Code: Select all

void irq_install_handler()(int n, uint32 handler)
is a valid declaration for a function which (based on the intended use) ought to take an unsigned byte and a function pointer as its arguments? Is this even a valid C function declaration at all, and if it is, what are its parameters? Does it match the function prototype, and if not, just how does it differ? Is either this line or the prototype correct, or is one (or both) incorrect? Does anything in this seem misplaced or in the wrong location to you?

When you compiled this code (which I am guessing isn't exactly the code you really compiled, did you get any warnings? Did you enable GCC warnings with the -Wall option (which, despite its name, is really the minimum warning level you really want to be using)?

I would recommend reading the archetype/anti-pattern page Duct von Tape before proceeding with any more code you have copied from elsewhere. In OS dev, existing code should be seen as a guideline, not something to be copypasta'ed willy-nilly.
Rev. First Speaker Schol-R-LEA;2 LCF ELF JAM POEE KoR KCO PPWMTF
Ordo OS Project
Lisp programmers tend to seem very odd to outsiders, just like anyone else who has had a religious experience they can't quite explain to others.
User avatar
eekee
Member
Member
Posts: 892
Joined: Mon May 22, 2017 5:56 am
Location: Kerbin
Discord: eekee
Contact:

Re: how do i get irq_install_handler()?

Post by eekee »

Schol-R-LEA wrote:

Code: Select all

void irq_install_handler()(int n, uint32 handler)
Is this even a valid C function declaration at all, and if it is, what are its parameters?
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.

I agree with Schol; you should read Duct von Tape, haybame. (It's not long at all.) 2 of the 3 cons seem particularly applicable:
  • He creates many bugs while he is unable to fix any of them
  • He makes his code totally unreadable to others and to himself
I'm personally following the suggestion to start with easier projects because I'm not familiar with good practice of my chosen language, Forth, but at the same time I'm not ignoring my OS: the code I'm practicing with will become userspace and even filesystem within my OS.
Kaph — a modular OS intended to be easy and fun to administer and code for.
"May wisdom, fun, and the greater good shine forth in all your work." — Leo Brodie
haybame
Posts: 16
Joined: Mon Mar 09, 2020 5:06 pm
Libera.chat IRC: haybame

Re: how do i get irq_install_handler()?

Post by haybame »

oops, i fixed it.
Post Reply