prevent buffer overflow, LoadString accepts the size of the buffer in TCHARs, not...
[reactos.git] / reactos / ntoskrnl / dbg / i386 / kdb_help.S
1 #include <internal/ke.h>
2 #include <internal/i386/segment.h>
3
4 .text
5
6 .globl _KdbEnter
7 _KdbEnter:
8 /*
9 * Set up a trap frame
10 */
11 /* Ss - space already reserved by return EIP */
12 pushl %esp /* Esp */
13 pushfl /* Eflags */
14 pushl %cs /* Cs */
15 pushl 12(%esp) /* Eip */
16 movl %ss, 16(%esp) /* Save Ss */
17 pushl $0 /* ErrorCode */
18 pushl %ebp /* Ebp */
19 pushl %ebx /* Ebx */
20 pushl %esi /* Esi */
21 pushl %edi /* Edi */
22 pushl %fs /* Fs */
23 pushl $0 /* ExceptionList */
24 pushl $0 /* PreviousMode */
25 pushl %eax /* Eax */
26 pushl %ecx /* Ecx */
27 pushl %edx /* Edx */
28 pushl %ds /* Ds */
29 pushl %es /* Es */
30 pushl %gs /* Gs */
31 movl %dr7, %eax
32 pushl %eax /* Dr7 */
33 /* Clear all breakpoint enables in dr7. */
34 andl $0xFFFF0000, %eax
35 movl %eax, %dr7
36 movl %dr6, %eax
37 pushl %eax /* Dr6 */
38 movl %dr3, %eax
39 pushl %eax /* Dr3 */
40 movl %dr2, %eax
41 pushl %eax /* Dr2 */
42 movl %dr1, %eax
43 pushl %eax /* Dr1 */
44 movl %dr0, %eax
45 pushl %eax /* Dr0 */
46 pushl $0 /* TempEip */
47 pushl $0 /* TempCs */
48 pushl $0 /* DebugPointer */
49 pushl $3 /* DebugArgMark (Exception number) */
50 pushl 0x60(%esp) /* DebugEip */
51 pushl %ebp /* DebugEbp */
52
53 /*
54 * Call KDB
55 */
56 movl %esp, %eax
57 pushl $1 /* FirstChance */
58 pushl %eax /* Push a pointer to the trap frame */
59 pushl $0 /* Context */
60 pushl $0 /* PreviousMode (KernelMode) */
61 pushl $0 /* ExceptionRecord */
62 call _KdbEnterDebuggerException
63
64 /*
65 * Pop the arguments and unused portions of the trap frame:
66 * DebugEbp
67 * DebugEip
68 * DebugArgMark
69 * DebugPointer
70 * TempCs
71 * TempEip
72 */
73 addl $(11*4), %esp
74
75 /*
76 * Restore/update debugging registers.
77 */
78 popl %eax /* Dr0 */
79 movl %eax, %dr0
80 popl %eax /* Dr1 */
81 movl %eax, %dr1
82 popl %eax /* Dr2 */
83 movl %eax, %dr2
84 popl %eax /* Dr3 */
85 movl %eax, %dr3
86 popl %eax /* Dr6 */
87 movl %eax, %dr6
88 popl %eax /* Dr7 */
89 movl %eax, %dr7
90
91 /*
92 * Restore registers including any that might have been changed
93 * inside the debugger.
94 */
95 popl %gs /* Gs */
96 popl %es /* Es */
97 popl %ds /* Ds */
98 popl %edx /* Edx */
99 popl %ecx /* Ecx */
100 popl %eax /* Eax */
101 addl $4, %esp /* PreviousMode */
102 addl $4, %esp /* ExceptionList */
103 popl %fs /* Fs */
104 popl %edi /* Edi */
105 popl %esi /* Esi */
106 popl %ebx /* Ebx */
107
108 /* Remove SS:ESP from the stack */
109 movl 16(%esp), %ebp
110 movl %ebp, 24(%esp)
111 movl 12(%esp), %ebp
112 movl %ebp, 20(%esp)
113 movl 8(%esp), %ebp
114 movl %ebp, 16(%esp)
115
116 popl %ebp /* Ebp */
117 addl $12, %esp /* ErrorCode and SS:ESP */
118
119 /*
120 * Return to the caller.
121 */
122 iret
123
124
125 .globl _KdbpStackSwitchAndCall@8
126 _KdbpStackSwitchAndCall@8:
127 pushl %ebp
128 movl %esp, %ebp
129
130 movl 0x8(%esp), %eax /* New stack */
131 movl 0xC(%esp), %ecx /* Function to call */
132 movl %esp, %edx /* Old stack */
133
134 /* Switch stack */
135 movl %eax, %esp
136 pushl %edx
137
138 /* Call function */
139 call *%ecx
140
141 /* Switch back to old stack */
142 popl %esp
143
144 /* Return */
145 popl %ebp
146 ret $8
147