flat assembler
Message board for the users of flat assembler.

Index > OS Construction > stack usage on transfers to interrupt handling routines

Author
Thread Post new topic Reply to topic
zhak



Joined: 12 Apr 2005
Posts: 490
Location: Belarus
zhak
Intel 64 and IA-32 Architectures Software Developer's Manual, Volume 1, pg 6-15:
Quote:

If no stack switch occurs, the processor does the following when calling an interrupt or exception handler (see Figure 6-5):
1. Pushes the current contents of the EFLAGS, CS, and EIP registers (in that order) on the stack.
2. Pushes an error code (if appropriate) on the stack.


I intercept INT 06h, INT 09h, and INT 70h in real mode. and I use hardcoded pointers to redirect execution flow in the following way:

Code:
int_handler:
push bx
push ax
. . .
. . .
mov bp, sp
mov bx, [ss:bp+4]     ;mov IP of interrupted instruction to BX 
mov ax, label         ;
mov [ss:bp+4], ax     ;mov new return point (IP) on the stack
mov bp, bx            ;BP = previous return point (IP)
mov al, 20h
out 20h, al
out 0A0h, al
pop ax
pop bx
iret
    


This code works fine on Bochs 2.3.6. As you can see, no error code is pushed on the stack when passing control to interrupt handler.
So, my question is: what does this error code, that is described in the manual, stand for? if this error code is pushed for some reason on the stack, my program will crash.

one more question is: should I call CLI/STI commands when enter/exit interrupt handler?
Post 19 Jan 2008, 16:06
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17714
Location: In your JS exploiting you and your system
revolution
Error codes are only relevant to protected mode and it's multiple stack pointers..

Real mode works just like to original 8086, no error codes or stack switching occur.
Post 19 Jan 2008, 16:39
View user's profile Send private message Visit poster's website Reply with quote
Japheth



Joined: 26 Oct 2004
Posts: 151
Japheth
Quote:

one more question is: should I call CLI/STI commands when enter/exit interrupt handler?


No. Interrupts are already disabled and will be restored with IRET.

However, you must not write EOI (20h) to the PICs inside an interrupt 06 handler.
Post 21 Jan 2008, 21:29
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
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 vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.