[FORMATTING] Fix the indentation mess in KDBG and use a consistent 4 spaces indentation.
[reactos.git] / reactos / ntoskrnl / kdbg / i386 / kdb_help.S
1 #include <ndk/asm.h>
2
3 .text
4
5 .globl _KdbEnter
6 _KdbEnter:
7 /*
8 * Set up a trap frame
9 */
10 pushfl /* Eflags */
11 pushl %cs /* Cs */
12 pushl $0 /* ErrorCode */
13 pushl %ebp /* Ebp */
14 pushl %ebx /* Ebx */
15 movl 20(%esp), %ebp /* Eip */
16 movl 16(%esp), %ebx /* Eflags */
17 movl %ebx, 20(%esp)
18 movl 12(%esp), %ebx /* Cs */
19 movl %ebx, 16(%esp)
20 movl %ebp, 12(%esp)
21 pushl %esi /* Esi */
22 pushl %edi /* Edi */
23 pushl %fs /* Fs */
24 pushl $0 /* ExceptionList */
25 pushl $0 /* PreviousMode */
26 pushl %eax /* Eax */
27 pushl %ecx /* Ecx */
28 pushl %edx /* Edx */
29 pushl %ds /* Ds */
30 pushl %es /* Es */
31 pushl %gs /* Gs */
32 movl %dr7, %eax
33 pushl %eax /* Dr7 */
34
35 /* Clear all breakpoint enables in dr7. */
36 andl $0xFFFF0000, %eax
37 movl %eax, %dr7
38 movl %dr6, %eax
39 pushl %eax /* Dr6 */
40 movl %dr3, %eax
41 pushl %eax /* Dr3 */
42 movl %dr2, %eax
43 pushl %eax /* Dr2 */
44 movl %dr1, %eax
45 pushl %eax /* Dr1 */
46 movl %dr0, %eax
47 pushl %eax /* Dr0 */
48 leal 0x58(%esp), %eax
49 pushl %eax /* TempEsp */
50 pushl %ss /* TempSegSs */
51 pushl $0 /* DebugPointer */
52 pushl $3 /* DebugArgMark (Exception number) */
53 pushl 0x60(%esp) /* DebugEip */
54 pushl %ebp /* DebugEbp */
55
56 /*
57 * Call KDB
58 */
59 movl %esp, %eax
60 pushl $1 /* FirstChance */
61 pushl %eax /* Push a pointer to the trap frame */
62 pushl $0 /* Context */
63 pushl $0 /* PreviousMode (KernelMode) */
64 pushl $0 /* ExceptionRecord */
65 call _KdbEnterDebuggerException
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 addl $(11*4), %esp
77
78 /*
79 * Restore/update debugging registers.
80 */
81 popl %eax /* Dr0 */
82 movl %eax, %dr0
83 popl %eax /* Dr1 */
84 movl %eax, %dr1
85 popl %eax /* Dr2 */
86 movl %eax, %dr2
87 popl %eax /* Dr3 */
88 movl %eax, %dr3
89 popl %eax /* Dr6 */
90 movl %eax, %dr6
91 popl %eax /* Dr7 */
92 movl %eax, %dr7
93
94 /*
95 * Restore registers including any that might have been changed
96 * inside the debugger.
97 */
98 popl %gs /* Gs */
99 popl %es /* Es */
100 popl %ds /* Ds */
101 popl %edx /* Edx */
102 popl %ecx /* Ecx */
103 popl %eax /* Eax */
104 addl $8, %esp /* PreviousMode, ExceptionList */
105 popl %fs /* Fs */
106 popl %edi /* Edi */
107 popl %esi /* Esi */
108 popl %ebx /* Ebx */
109 popl %ebp /* Ebp */
110 addl $4, %esp /* ErrorCode */
111
112 /*
113 * Return to the caller.
114 */
115 iret
116
117
118 .globl _KdbpStackSwitchAndCall@8
119 _KdbpStackSwitchAndCall@8:
120 pushl %ebp
121 movl %esp, %ebp
122
123 movl 0x8(%esp), %eax /* New stack */
124 movl 0xC(%esp), %ecx /* Function to call */
125 movl %esp, %edx /* Old stack */
126
127 /* Switch stack */
128 movl %eax, %esp
129 pushl %edx
130
131 /* Call function */
132 call *%ecx
133
134 /* Switch back to old stack */
135 popl %esp
136
137 /* Return */
138 popl %ebp
139 ret $8
140