OSDev.org

The Place to Start for Operating System Developers
It is currently Fri Mar 29, 2024 12:55 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: how do i get irq_install_handler()?
PostPosted: Thu Mar 12, 2020 11:27 pm 
Offline

Joined: Mon Mar 09, 2020 5:06 pm
Posts: 16
i am following this tutorial:https://forum.osdev.org/viewtopic.php?f=1&t=10247&start=0
but i need this function: irq_install_handler().


Top
 Profile  
 
 Post subject: Re: how do i get irq_install_handler()?
PostPosted: Thu Mar 12, 2020 11:45 pm 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4591
Location: Chichester, UK
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.


Top
 Profile  
 
 Post subject: Re: how do i get irq_install_handler()?
PostPosted: Fri Mar 13, 2020 12:37 am 
Offline

Joined: Mon Mar 09, 2020 5:06 pm
Posts: 16
how do i write a interrupt handler for this?


Top
 Profile  
 
 Post subject: Re: how do i get irq_install_handler()?
PostPosted: Fri Mar 13, 2020 1:15 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4591
Location: Chichester, UK
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.


Top
 Profile  
 
 Post subject: Re: how do i get irq_install_handler()?
PostPosted: Fri Mar 13, 2020 1:30 am 
Offline

Joined: Mon Mar 09, 2020 5:06 pm
Posts: 16
i am very new to this.

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

idt.c
Code:
#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:
#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:
#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:
#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[]);         


Attachment:
screen.png
screen.png [ 4.89 KiB | Viewed 1544 times ]

ps thanks for the help


Last edited by haybame on Sat Mar 14, 2020 3:18 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: how do i get irq_install_handler()?
PostPosted: Sat Mar 14, 2020 2:44 am 
Offline
Member
Member
User avatar

Joined: Fri Oct 27, 2006 9:42 am
Posts: 1925
Location: Athens, GA, USA
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:
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.


Top
 Profile  
 
 Post subject: Re: how do i get irq_install_handler()?
PostPosted: Sat Mar 14, 2020 8:17 am 
Offline
Member
Member
User avatar

Joined: Mon May 22, 2017 5:56 am
Posts: 812
Location: Hyperspace
Schol-R-LEA wrote:
Code:
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


Top
 Profile  
 
 Post subject: Re: how do i get irq_install_handler()?
PostPosted: Sat Mar 14, 2020 3:20 pm 
Offline

Joined: Mon Mar 09, 2020 5:06 pm
Posts: 16
oops, i fixed it.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 99 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group