xref: /reactos/ntoskrnl/kdbg/i386/kdb_help.S (revision c8d07514)
1
2#include <asm.inc>
3#include <ks386.inc>
4
5EXTERN _KdbEnterDebuggerFirstChanceException:PROC
6
7.code
8
9PUBLIC _KdbEnter
10_KdbEnter:
11    /*
12     * Set up a trap frame
13     */
14    pushf                      /* Eflags */
15    push cs                 /* Cs */
16    push 0                  /* ErrorCode */
17    push ebp                /* Ebp */
18    push ebx                /* Ebx */
19    mov ebp, [esp + 20]      /* Eip */
20    mov ebx, [esp + 16]      /* Eflags */
21    mov [esp + 20], ebx
22    mov ebx, [esp + 12]      /* Cs */
23    mov [esp + 16], ebx
24    mov [esp + 12], ebp
25    push esi                /* Esi */
26    push edi                /* Edi */
27    push fs                 /* Fs */
28    push 0                  /* ExceptionList */
29    push 0                  /* PreviousMode */
30    push eax                /* Eax */
31    push ecx                /* Ecx */
32    push edx                /* Edx */
33    push ds                 /* Ds */
34    push es                 /* Es */
35    push gs                 /* Gs */
36    mov eax, dr7
37    push eax                /* Dr7 */
38
39    /* Clear all breakpoint enables in dr7. */
40    and eax, HEX(0FFFF0000)
41    mov dr7, eax
42    mov eax, dr6
43    push eax                /* Dr6 */
44    mov eax, dr3
45    push eax                /* Dr3 */
46    mov eax, dr2
47    push eax                /* Dr2 */
48    mov eax, dr1
49    push eax                /* Dr1 */
50    mov eax, dr0
51    push eax                /* Dr0 */
52    lea eax, [esp + HEX(58)]
53    push eax                /* TempEsp */
54    push ss                 /* TempSegSs */
55    push 0                  /* DebugPointer */
56    push 3                  /* DebugArgMark (Exception number) */
57    push [esp + HEX(60)]          /* DebugEip */
58    push ebp                /* DebugEbp */
59
60    /*
61     * Call KDB
62     */
63    mov eax, esp
64    push eax                /* Push a pointer to the trap frame */
65    call _KdbEnterDebuggerFirstChanceException
66
67    /*
68     * Pop the arguments and unused portions of the trap frame:
69     *   DebugEbp
70     *   DebugEip
71     *   DebugArgMark
72     *   DebugPointer
73     *   TempSegSs
74     *   TempEsp
75     */
76    add esp, 11*4
77
78    /*
79     * Restore/update debugging registers.
80     */
81    pop eax            /* Dr0 */
82    mov dr0, eax
83    pop eax            /* Dr1 */
84    mov dr1, eax
85    pop eax            /* Dr2 */
86    mov dr2, eax
87    pop eax            /* Dr3 */
88    mov dr3, eax
89    pop eax            /* Dr6 */
90    mov dr6, eax
91    pop eax            /* Dr7 */
92    mov dr7, eax
93
94    /*
95     * Restore registers including any that might have been changed
96     * inside the debugger.
97     */
98    pop gs         /* Gs */
99    pop es         /* Es */
100    pop ds         /* Ds */
101    pop edx        /* Edx */
102    pop ecx        /* Ecx */
103    pop eax        /* Eax */
104    add esp, 8    /* PreviousMode, ExceptionList */
105    pop fs         /* Fs */
106    pop edi        /* Edi */
107    pop esi        /* Esi */
108    pop ebx        /* Ebx */
109    pop ebp        /* Ebp */
110    add esp, 4    /* ErrorCode */
111
112    /*
113     * Return to the caller.
114     */
115    iretd
116
117
118PUBLIC _KdbpStackSwitchAndCall@8
119_KdbpStackSwitchAndCall@8:
120    push ebp
121    mov ebp, esp
122
123    mov eax, [esp + 8]         /* New stack */
124    mov ecx, [esp + 12]         /* Function to call */
125    mov edx, esp              /* Old stack */
126
127    /* Switch stack */
128    mov esp, eax
129    push edx
130
131    /* Call function */
132    call ecx
133
134    /* Switch back to old stack */
135    pop esp
136
137    /* Return */
138    pop ebp
139    ret 8
140
141END
142