Trap Gates?

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
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Trap Gates?

Post by pcmattman »

I've seen the light in switching to trap gates after reads from the console device failed miserably thanks to the read function being called via a syscall (interrupt gate) and hence blocking all other interrupts (including the keyboard).

This is what I've tried to do to get trap gates working:

Code: Select all

idt_set_gate(128, (unsigned)isr128, 0x08, 0x8F);
Unfortunately, interrupts are still disabled when this trap gate is called.

Any hints?
Aali
Member
Member
Posts: 58
Joined: Sat Apr 14, 2007 12:13 pm

Post by Aali »

i find it easier to keep that consistant for every type of interrupt and just enable interrupts later if need be
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post by JamesM »

I always enable interrupts before dispatching from my 'catch-all' exception handler to the code that will actually handle the exception. Then I disable them again when it finishes.
User avatar
os64dev
Member
Member
Posts: 553
Joined: Sat Jan 27, 2007 3:21 pm
Location: Best, Netherlands

Post by os64dev »

I've seen the light in switching to trap gates after reads from the console device failed miserably thanks to the read function being called via a syscall (interrupt gate) and hence blocking all other interrupts (including the keyboard).
normally i would make the syscall read not dependand on the keyboard read. I would have an interrupt service routine that will put the keyboard pressed in a keyboard buffer. And the read function uses that buffer for handling its state.

in pseudo code:

Code: Select all

Buffer<unsigned char>  keyBuffer;

void keyBoardIsr(void) {
    //- store character in keyboard buffer.
    keyBuffer.AddLast(inport(0x60));
    //- acknowledge interrupt.
    outport(0x20, 0x20);
}

int readFromKeyBoard(void) {
    if(keyBuffer.Length() > 0) {
        return(keyBuffer.getFirst());
    }
    //- no keyboard data available.
    return(-1);
}
in userland you then get a function

Code: Select all

int getch(void) {
    int ch;
    while((ch = syscall(readFromKeyBoard)) == -1) {
        sleep(10); // wait ten milliseconds.
    }
}
Author of COBOS
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post by pcmattman »

Makes sense now :D.
Post Reply