how do i get irq_install_handler()?
how do i get irq_install_handler()?
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().
Re: how do i get irq_install_handler()?
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.
Tutorials are just examples of how to do things. Don't follow them blindly.
Re: how do i get irq_install_handler()?
how do i write a interrupt handler for this?
Re: how do i get irq_install_handler()?
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.
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.
Re: how do i get irq_install_handler()?
i am very new to this.
edit
i got it working i had to add a interrupt like this:
idt.c
idt.h
util.c
util.h
ps thanks for the help
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));
}
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[]);
Last edited by haybame on Sat Mar 14, 2020 3:18 pm, edited 1 time in total.
- Schol-R-LEA
- Member
- Posts: 1925
- Joined: Fri Oct 27, 2006 9:42 am
- Location: Athens, GA, USA
Re: how do i get irq_install_handler()?
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
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.
Also, are you really sure that the function declaration
Code: Select all
void irq_install_handler()(int n, uint32 handler)
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.
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.
Re: how do i get irq_install_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)
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
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
"May wisdom, fun, and the greater good shine forth in all your work." — Leo Brodie
Re: how do i get irq_install_handler()?
oops, i fixed it.