OSDev.org

The Place to Start for Operating System Developers
It is currently Tue Apr 23, 2024 10:02 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 32 posts ]  Go to page 1, 2, 3  Next
Author Message
 Post subject: How do i get my keyboard handler to work?
PostPosted: Sat Jan 14, 2017 10:58 am 
Offline
Member
Member
User avatar

Joined: Tue Jan 10, 2017 3:19 pm
Posts: 84
I'm trying to get my keyboard handler to be able to work properly.

However, I can't seem to get a grip on this.

My tries:

Polling:

Polling is the only one that I can get working and actually go to the next character. However, this puts way too many characters when I hold this for less than a second. This can display upwards of 4 characters when I hold the key for 0.75 seconds, instead of the normal 1 character. This also displayed unwanted spaces/nulls.

Using interrupts:

Using the (proper) normal way that uses Interrupts doesn't help, too. This displays absolutely nothing. Nothing. Nothing happens. It's like it's frozen.

Nothing displays on the screen.

_________________
(not so frequently updated) Code is at:

https://github.com/NunoLava1998/DixiumOS-1


Top
 Profile  
 
 Post subject: Re: How do i get my keyboard handler to work?
PostPosted: Sat Jan 14, 2017 11:00 am 
Offline
Member
Member
User avatar

Joined: Sat Dec 27, 2014 9:11 am
Posts: 901
Location: Maadi, Cairo, Egypt
By looking at your GitHub repo, you don't know how to properly handle interrupts.
Seriously, why not try to do it yourself once?

_________________
You know your OS is advanced when you stop using the Intel programming guide as a reference.


Top
 Profile  
 
 Post subject: Re: How do i get my keyboard handler to work?
PostPosted: Sat Jan 14, 2017 11:05 am 
Offline
Member
Member
User avatar

Joined: Tue Jan 10, 2017 3:19 pm
Posts: 84
omarrx024 wrote:
By looking at your GitHub repo, you don't know how to properly handle interrupts.
Seriously, why not try to do it yourself once?


What? I did write most of the code myself.

_________________
(not so frequently updated) Code is at:

https://github.com/NunoLava1998/DixiumOS-1


Top
 Profile  
 
 Post subject: Re: How do i get my keyboard handler to work?
PostPosted: Sat Jan 14, 2017 11:06 am 
Offline
Member
Member
User avatar

Joined: Sat Dec 27, 2014 9:11 am
Posts: 901
Location: Maadi, Cairo, Egypt
DixiumOS wrote:
What? I did write most of the code myself.

Why don't you read the wiki and then try to write code yourself?

_________________
You know your OS is advanced when you stop using the Intel programming guide as a reference.


Top
 Profile  
 
 Post subject: Re: How do i get my keyboard handler to work?
PostPosted: Sat Jan 14, 2017 11:18 am 
Offline
Member
Member
User avatar

Joined: Tue Jan 10, 2017 3:19 pm
Posts: 84
omarrx024 wrote:
DixiumOS wrote:
What? I did write most of the code myself.

Why don't you read the wiki and then try to write code yourself?


I do.
And seriously, if you want to help someone, don't bring up a completely different topic with no relation to this and then say bad things. Please, don't.

If you don't feel like helping, then don't. Just don't bring up a discussion that never solved anything.

_________________
(not so frequently updated) Code is at:

https://github.com/NunoLava1998/DixiumOS-1


Top
 Profile  
 
 Post subject: Re: How do i get my keyboard handler to work?
PostPosted: Sat Jan 14, 2017 11:40 am 
Offline
Member
Member
User avatar

Joined: Tue Aug 02, 2016 1:52 pm
Posts: 286
Location: East Riding of Yorkshire, UK
DixiumOS wrote:
omarrx024 wrote:
DixiumOS wrote:
What? I did write most of the code myself.

Why don't you read the wiki and then try to write code yourself?


I do.
And seriously, if you want to help someone, don't bring up a completely different topic with no relation to this and then say bad things. Please, don't.

If you don't feel like helping, then don't. Just don't bring up a discussion that never solved anything.
Do you not understand why people are getting frustrated though? You don't really seem to read what people say and make thousands of threads on the same topic.

_________________
com.sun.java.swing.plaf.nimbus.InternalFrameInternalFrameTitlePaneInternalFrameTitlePaneMaximizeButtonWindowNotFocusedState
Compiler Development Forum


Top
 Profile  
 
 Post subject: Re: How do i get my keyboard handler to work?
PostPosted: Sat Jan 14, 2017 11:44 am 
Offline
Member
Member
User avatar

Joined: Tue Jan 10, 2017 3:19 pm
Posts: 84
zenzizenzicube wrote:
snip


Do I? Oh, sorry.

Anyway, can we return 0; to our question?

_________________
(not so frequently updated) Code is at:

https://github.com/NunoLava1998/DixiumOS-1


Top
 Profile  
 
 Post subject: Re: How do i get my keyboard handler to work?
PostPosted: Sat Jan 14, 2017 11:58 am 
Offline
Member
Member
User avatar

Joined: Thu Aug 06, 2015 6:41 am
Posts: 97
Location: Netherlands
Have you tried putting:
Code:
terminal_writechar("A", ...);
right at the start of your keyboard handler, or even inside the IRQ handler, just to make sure it actually gets called?
Are you sure the compiler doesn't do anything unexpected/undesired in your ISRs, such as changing the stack pointers (esp/ebp)?

I think the article about ISRs might be of help.


Top
 Profile  
 
 Post subject: Re: How do i get my keyboard handler to work?
PostPosted: Sat Jan 14, 2017 1:24 pm 
Offline
Member
Member
User avatar

Joined: Tue Jan 10, 2017 3:19 pm
Posts: 84
sleephacker wrote:
Have you tried putting:
Code:
terminal_writechar("A", ...);
right at the start of your keyboard handler, or even inside the IRQ handler, just to make sure it actually gets called?
Are you sure the compiler doesn't do anything unexpected/undesired in your ISRs, such as changing the stack pointers (esp/ebp)?

I think the article about ISRs might be of help.


Doesn't work...

Ugh, looks like I'll need to fix my IDT code.

EDIT: Nope. The keyboard just went on vacation and forgot to fire IRQ1.

_________________
(not so frequently updated) Code is at:

https://github.com/NunoLava1998/DixiumOS-1


Last edited by DixiumOS on Sat Jan 14, 2017 1:59 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: How do i get my keyboard handler to work?
PostPosted: Sat Jan 14, 2017 1:54 pm 
Offline
Member
Member
User avatar

Joined: Fri Oct 27, 2006 9:42 am
Posts: 1925
Location: Athens, GA, USA
DixiumOS wrote:
sleephacker wrote:
Have you tried putting:
Code:
terminal_writechar("A", ...);
right at the start of your keyboard handler, or even inside the IRQ handler, just to make sure it actually gets called?
Are you sure the compiler doesn't do anything unexpected/undesired in your ISRs, such as changing the stack pointers (esp/ebp)?

I think the article about ISRs might be of help.


Doesn't work...

Ugh, looks like I'll need to fix my IDT code.


If I could offer two pieces of advice: first, if you are using GCC for your compiler, and want to use a C function for an interrupt handler, use the __attribute__ ((interrupt)) function attribute, rather than emitting an IRET manually. It does require a certain amount of GCC-specific and non-portable code, but since this is an interrupt handler that's hardly a concern. Take note that you will need a data structure for representing the interrupt frame, as explained in the GCC documents and the Intel manuals.

Second, you should be redirect all of the interrupt vectors to a single IDT entry rather than having several dozen which are repeating the same code. Indeed, I would recommend initializing the entire IDT in this manner (with a default handler that issues a system initialization error message), and then adding the actual entries you need, just as a backstop in case of a programming error.

Code:
void addisrfunctions(void) {
    for (int i = 0; i < 256; i++) {
        idt_set_gate(i, (unsigned)isr_default, 0x08, 0x8E);
    }

    // now that you have everything initialized, add the
    // actual interrupt handlers to the vectors you want

}


Code:
__attribute__ ((interrupt)) void isr_default(struct interrupt_frame *frame) {
    // for now, just put this as a stub that will panic
    // the kernel, you can write a more elegant
    // default handler later
   
    terminal_clrscr();
    terminal_writestring("Fatal error - unsupported interrupt", BLACK, WHITE, 0, 0);
    panic();    // you will need to write this function, I guess
}


This is just off the top of my head; you'll need to work the details out as you you can.

_________________
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.


Last edited by Schol-R-LEA on Sat Jan 14, 2017 2:07 pm, edited 2 times in total.

Top
 Profile  
 
 Post subject: Re: How do i get my keyboard handler to work?
PostPosted: Sat Jan 14, 2017 2:03 pm 
Offline
Member
Member

Joined: Wed Jun 17, 2015 9:40 am
Posts: 501
Location: Athens, Greece
Hi,


Another problem is that he doesn't send an EOI in interrupt handlers.


Regards,
glauxosdever


Top
 Profile  
 
 Post subject: Re: How do i get my keyboard handler to work?
PostPosted: Sat Jan 14, 2017 2:42 pm 
Offline
Member
Member
User avatar

Joined: Tue Jan 10, 2017 3:19 pm
Posts: 84
Optimized my IDT code to work and now it's randomly issuing interrupts before triple faulting (literally 7600 lines of logs from QEMU before it triple faulted). It isn't at executing interrupts, but rather loading the IDT.

The last few lines tell that it's crashing at pop %ds in isr8 and pop %ds in isr13.

EDIT: I also realized as this is getting to the last line, esp decreases.

EDIT: Now it works. And IRQ1 never fires. Dammit.

_________________
(not so frequently updated) Code is at:

https://github.com/NunoLava1998/DixiumOS-1


Top
 Profile  
 
 Post subject: IRQ1 never gets fired
PostPosted: Sat Jan 14, 2017 3:43 pm 
Offline
Member
Member
User avatar

Joined: Tue Jan 10, 2017 3:19 pm
Posts: 84
Just to say: the IDT is fine as IRQ0 gets fired constantly by the PIT. It is seen in the QEMU logs.
The IRQ1 is correctly loaded and is the proper example of a keyboard handler.

Resuming to the question:

My IRQ1 handler never gets called by my keyboard. IRQ0, however, gets constantly called, and the QEMU logs report it.

How do i fix this?
seesignatureforcode

_________________
(not so frequently updated) Code is at:

https://github.com/NunoLava1998/DixiumOS-1


Top
 Profile  
 
 Post subject: Re: IRQ1 never gets fired
PostPosted: Sat Jan 14, 2017 3:52 pm 
Offline
Member
Member
User avatar

Joined: Thu Aug 06, 2015 6:41 am
Posts: 97
Location: Netherlands
Did you unmask IRQ1 when setting up the PIC?
Did you configure the keyboard to send interrupts during initialisation?


Top
 Profile  
 
 Post subject: Re: IRQ1 never gets fired
PostPosted: Sat Jan 14, 2017 4:00 pm 
Offline
Member
Member
User avatar

Joined: Tue Jan 10, 2017 3:19 pm
Posts: 84
sleephacker wrote:
Did you unmask IRQ1 when setting up the PIC?
Did you configure the keyboard to send interrupts during initialisation?


Nope about unmasking.
Now it works except i only get one IRQ, and i do send an EOI.

_________________
(not so frequently updated) Code is at:

https://github.com/NunoLava1998/DixiumOS-1


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 32 posts ]  Go to page 1, 2, 3  Next

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 116 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