Page 1 of 1
keyboard ISR stuck in loop after returning.
Posted: Tue Oct 15, 2019 3:40 am
by 0xCC
hello
I managed to implement the keyboard ISR and i prints the keys entered but the problem is the CPU usage goes to high levels after the first key entered.
here is the ISR:
Code: Select all
void _declspec(naked) keyboard_interrupt_wrapper() {
_asm {
CLI;
PUSHAD;
CALL IO_keyboard_handler;
POPAD;
STI;
IRETD;
}
}
but the problem is solved when i added HLT before IRETD
Code: Select all
void _declspec(naked) keyboard_interrupt_wrapper() {
_asm {
CLI;
PUSHAD;
CALL IO_keyboard_handler;
POPAD;
STI;
HLT;
IRETD;
}
}
so i guess the problem is from IRETD, maybe i haven't setup stack properly and execution went to random place?
Re: keyboard ISR stuck in loop after returning.
Posted: Tue Oct 15, 2019 3:47 am
by Octocontrabass
What code is being interrupted?
Re: keyboard ISR stuck in loop after returning.
Posted: Tue Oct 15, 2019 3:49 am
by 0xCC
Octocontrabass wrote:What code is being interrupted?
after setting up the IDT and PIC the CPU just HLT:
Code: Select all
void kmain() {
GDT_Setup(GDTBASE);
IDT_Setup((PVOID)IDTBASE);
clear();
printf("Welcome to my new OS");
SetupIODrivers();//setup PIC
_asm STI;
_asm HLT;
}
Re: keyboard ISR stuck in loop after returning.
Posted: Tue Oct 15, 2019 3:57 am
by Octocontrabass
And what happens after you HLT?
Re: keyboard ISR stuck in loop after returning.
Posted: Tue Oct 15, 2019 4:14 am
by 0xCC
Octocontrabass wrote:And what happens after you HLT?
nothing.
isnt HLT supposed to suspend the CPU until the next interrupt ?
Re: keyboard ISR stuck in loop after returning.
Posted: Tue Oct 15, 2019 4:34 am
by Octocontrabass
Right, it suspends the CPU until the next interrupt, which is where your keyboard handler runs and returns.
What does it return to?
Re: keyboard ISR stuck in loop after returning.
Posted: Tue Oct 15, 2019 4:52 am
by 0xCC
Octocontrabass wrote:Right, it suspends the CPU until the next interrupt, which is where your keyboard handler runs and returns.
What does it return to?
i thought it continues the execution of HLT and suspend CPU again.
but when i replaced it by a loop it solved the problem.
so i guess if HLT is interrupted and returned, the CPU executes what's after HLT right ?
Re: keyboard ISR stuck in loop after returning.
Posted: Tue Oct 15, 2019 4:56 am
by Octocontrabass
That's right.
Re: keyboard ISR stuck in loop after returning.
Posted: Tue Oct 15, 2019 8:14 am
by nullplan
Also:
0xCC wrote:Code: Select all
void _declspec(naked) keyboard_interrupt_wrapper() {
_asm {
CLI;
PUSHAD;
CALL IO_keyboard_handler;
POPAD;
STI;
IRETD;
}
}
If you set up your interrupt handler as an interrupt gate in the IDT, rather than a trap gate (look it up!), you don't need the CLI, the CPU will automatically delete the IF for you. And the STI before the IRET is useless anyway, since IRET will pop the flags from stack.
Re: keyboard ISR stuck in loop after returning.
Posted: Wed Oct 16, 2019 5:26 am
by 0xCC
nullplan wrote:Also:
0xCC wrote:Code: Select all
void _declspec(naked) keyboard_interrupt_wrapper() {
_asm {
CLI;
PUSHAD;
CALL IO_keyboard_handler;
POPAD;
STI;
IRETD;
}
}
If you set up your interrupt handler as an interrupt gate in the IDT, rather than a trap gate (look it up!), you don't need the CLI, the CPU will automatically delete the IF for you. And the STI before the IRET is useless anyway, since IRET will pop the flags from stack.
indeed i had set it to interrupt gate.
thank you both for the info.