Autor Thema: Stack nach Interrupt..  (Gelesen 2361 mal)

nnosdev

  • Beiträge: 61
    • Profil anzeigen
Gespeichert
« am: 07. October 2012, 11:08 »
Hallo Leute, bei mir funktioniert zwar soweit alles wunderbar, jedoch habe ich an einer bestimmten Stelle versucht genauer zu verstehen warum bis jetzt alles funktioniert und da kamen ein paar ungereimtheiten ans Licht.

Das hier ist mein struct für den CPU-Zustand:

typedef struct cpu_state_struct {
uint32_t ds;

uint32_t edi;
uint32_t esi;
uint32_t ebp;
uint32_t esp;
uint32_t ebx;
uint32_t edx;
uint32_t ecx;
uint32_t eax;

uint32_t int_no, err_code;
uint32_t eip, cs, eflags, useresp, ss; // um usersp und ss geht es...
} cpu_state;

Und hier der common_stub für die Interrupts:

isr_common_stub:
; pusha: (E)AX, (E)CX, (E)DX, (E)BX, (E)SP, (E)BP, (E)SI, (E)DI
; pushes these registers in that order on the stack
pusha

        mov eax, ds
push eax

push esp ; pointer to cpu_state structure
call Isr_Handler
mov esp, eax

pop eax
popa

add esp, 8
sti ; enable interrupts
iret ; interrupt return

Nun zu meiner Frage: Hier steht, auf Seite 346, steht:

The primary difference is that with the INT n
instruction, the EFLAGS register is pushed onto the stack before the return address. (The return
address is a far address consisting of the current values of the CS and EIP registers.) Returns
from interrupt procedures are handled with the IRET instruction, which pops the EFLAGS
information and return address from the stack.



In diesem Tutorial steht:

u32int eip, cs, eflags, useresp, ss; // Pushed by the processor automatically.

allerdings konnte ich dafür noch keinen Nachweis finden. CS:EIP bzw. EFLAGS ist klar, steht auch so in der Dokumentation aber mir fehlen noch die restlichen 8 Byte in dieser Rechnung. Also wann bzw. wo werden diese "automatisch" vom Prozessor gepusht? Was habe ich übersehen?

LG
« Letzte Änderung: 07. October 2012, 11:10 von nnosdev »

Svenska

  • Beiträge: 1 792
    • Profil anzeigen
Gespeichert
« Antwort #1 am: 07. October 2012, 12:07 »
Laut Tutorial schiebt die CPU diese Felder auf den Stack, wenn sie sich zum Zeitpunkt des Interrupts im Ring 3 befindet.

MNemo

  • Beiträge: 547
    • Profil anzeigen
Gespeichert
« Antwort #2 am: 07. October 2012, 13:38 »
Und hier gibt es dann noch die offiziellen Dokumente dazu:
Intel Manuals Volume 3A: System Programming  6.12.1
AMD Manuals Volume 2: System Programming: 8.7.3
„Wichtig ist nicht, besser zu sein als alle anderen. Wichtig ist, besser zu sein als du gestern warst!“

nnosdev

  • Beiträge: 61
    • Profil anzeigen
Gespeichert
« Antwort #3 am: 07. October 2012, 15:21 »
Ah jetzt hab ichs!

Okay also am Stack liegt dann einfach:

Stack Segment Pointer
Stack Pointer
EFLAGS
Code Segment Pointer
Index Pointer (Nächste Instruktion)
Error Code
Interrupt Nummer
EAX
ECX
.
.
EDI
DS
Return Address
TOP OF STACK

Ich glaub dann hab ichs ^^

 

Einloggen