So.. I've been messing with cpu for a little bit, and understand asm thoroughly, but I'm having trouble with nmi's. For my example, I've got a cpu wired to an address bus that has a keyboard and a console screen. I also have the NMI output from cpu going to keyboard, and when I press the 'a' key on the keyboard, it triggers interrupt 97. I've got code in place to handle the interrupt, interrupts are enabled, and the code returns with nmiret, but for some reason the code isn't being called, and the cpu is locking at the interrupt, with the nmi number as the error output(obviously). So, thought maybe you gurus could take a look at the pieces of code I'll post here, and see what I'm doing wrong.
Near the top of my data section we have..
Code:
_interrupts:
alloc 1024 A little bit further down I have an example interrupt handler, for this example 'a' pressed on a wired keybooard:
Code:
_interrupt_a:
push eax // I push the registers onto the stack before
push esi // each call's main work, to preserve whatever
//may have been in the registers
cmp #ConsoleCurrentChar, #ConsoleLastChar
cge _screenshiftup
mov eax, #ConsoleCurrentChar //Current console character
mov esi, _a // _a is a pointer to the character 'a' in memory
mov #eax, esi
inc eax
mov #eax, #ConsoleParams // Obvious..
inc eax
mov #ConsoleCurrentChar, eax
sub #ModChar, 2
cmp #ModChar, 2
cl _resetmod //Dont worry about this, my way of keeping track of line endings
pop esi
pop eax
nmiret //Return from nmi And a bit further down in my interrupt table initialization function..:
Code:
//------------------------------
// Function: Interrupt Setup
// Purpose: Set up interrupts
// Notes:
// Should be called very soon
// after boot.
//------------------------------
_interruptsetup:
lidtr _interrupts //Tell cpu where interrupt table begins
mov edi, _interrupts
add edi, 388 //Move to interrupt address
mov #edi, _interrupt_a //Move address of handler into the table
add edi, 3
mov #edi, 96
inc edi
mov #edi, _interrupt_b
add edi, 3
mov #edi, 96
inc edi
mov #edi, _interrupt_c
add edi, 3
mov #edi, 96
ret
So for the life of me I can't figure out why this isnt working. I'll say it again since I didn't include it in the code: protected mode and interrupts are turned on.
Edit: So, I've figured out it IS calling the interrupt, its just taking forever to do so.. and once done with this, it quickly alternates between error 2 and 4.???. ??? being digits I can't identify because it swaps out so fast. So that brings about two more questions: Why does it take so long for the interrupt to be handled, and why does it alternate between errors once completed?
Bookmarks