[STORPORT] Fix x64 build
[reactos.git] / ntoskrnl / kdbg / i386 / kdb_help.S
1
2 #include <asm.inc>
3 #include <ks386.inc>
4
5 EXTERN _KdbEnterDebuggerException:PROC
6
7 .code
8
9 PUBLIC _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 1 /* FirstChance */
65 push eax /* Push a pointer to the trap frame */
66 push 0 /* Context */
67 push 0 /* PreviousMode (KernelMode) */
68 push 0 /* ExceptionRecord */
69 call _KdbEnterDebuggerException
70
71 /*
72 * Pop the arguments and unused portions of the trap frame:
73 * DebugEbp
74 * DebugEip
75 * DebugArgMark
76 * DebugPointer
77 * TempSegSs
78 * TempEsp
79 */
80 add esp, 11*4
81
82 /*
83 * Restore/update debugging registers.
84 */
85 pop eax /* Dr0 */
86 mov dr0, eax
87 pop eax /* Dr1 */
88 mov dr1, eax
89 pop eax /* Dr2 */
90 mov dr2, eax
91 pop eax /* Dr3 */
92 mov dr3, eax
93 pop eax /* Dr6 */
94 mov dr6, eax
95 pop eax /* Dr7 */
96 mov dr7, eax
97
98 /*
99 * Restore registers including any that might have been changed
100 * inside the debugger.
101 */
102 pop gs /* Gs */
103 pop es /* Es */
104 pop ds /* Ds */
105 pop edx /* Edx */
106 pop ecx /* Ecx */
107 pop eax /* Eax */
108 add esp, 8 /* PreviousMode, ExceptionList */
109 pop fs /* Fs */
110 pop edi /* Edi */
111 pop esi /* Esi */
112 pop ebx /* Ebx */
113 pop ebp /* Ebp */
114 add esp, 4 /* ErrorCode */
115
116 /*
117 * Return to the caller.
118 */
119 iretd
120
121
122 PUBLIC _KdbpStackSwitchAndCall@8
123 _KdbpStackSwitchAndCall@8:
124 push ebp
125 mov ebp, esp
126
127 mov eax, [esp + 8] /* New stack */
128 mov ecx, [esp + 12] /* Function to call */
129 mov edx, esp /* Old stack */
130
131 /* Switch stack */
132 mov esp, eax
133 push edx
134
135 /* Call function */
136 call ecx
137
138 /* Switch back to old stack */
139 pop esp
140
141 /* Return */
142 pop ebp
143 ret 8
144
145 END