KD System Rewrite:
[reactos.git] / reactos / ntoskrnl / kd / service.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * FILE: ntoskrnl/kd/service.c
5 * PURPOSE: Debug service dispatcher
6 *
7 * PROGRAMMERS: Eric Kohl (ekohl@abo.rhein-zeitung.de)
8 */
9
10 #include <ntoskrnl.h>
11
12
13 /* FUNCTIONS ***************************************************************/
14
15 #define _STR(x) #x
16 #define STR(x) _STR(x)
17
18 #if defined(__GNUC__)
19
20 void interrupt_handler2d(void);
21 __asm__("\n\t.global _interrupt_handler2d\n\t"
22 "_interrupt_handler2d:\n\t"
23
24 /* Save the user context */
25 "pushl %ebp\n\t" /* Ebp */
26
27 "pushl %eax\n\t" /* Eax */
28 "pushl %ecx\n\t" /* Ecx */
29 "pushl %edx\n\t" /* Edx */
30 "pushl %ebx\n\t" /* Ebx */
31 "pushl %esi\n\t" /* Esi */
32 "pushl %edi\n\t" /* Edi */
33
34 "pushl %ds\n\t" /* SegDs */
35 "pushl %es\n\t" /* SegEs */
36 "pushl %fs\n\t" /* SegFs */
37 "pushl %gs\n\t" /* SegGs */
38
39 "subl $112,%esp\n\t" /* FloatSave */
40
41 "pushl $0\n\t" /* Dr7 */
42 "pushl $0\n\t" /* Dr6 */
43 "pushl $0\n\t" /* Dr3 */
44 "pushl $0\n\t" /* Dr2 */
45 "pushl $0\n\t" /* Dr1 */
46 "pushl $0\n\t" /* Dr0 */
47
48 "pushl $0\n\t" /* ContextFlags */
49
50 /* Set ES to kernel segment */
51 "movw $"STR(KERNEL_DS)",%bx\n\t"
52 "movw %bx,%es\n\t"
53
54 /* FIXME: check to see if SS is valid/inrange */
55
56 /* DS and GS are now also kernel segments */
57 "movw %bx,%ds\n\t"
58 "movw %bx,%gs\n\t"
59
60 /* Set FS to the PCR */
61 "movw $"STR(PCR_SELECTOR)",%bx\n\t"
62 "movw %bx,%fs\n\t"
63
64 /* Call debug service dispatcher */
65 "pushl %edx\n\t"
66 "pushl %ecx\n\t"
67 "pushl %eax\n\t"
68 "call _KdpServiceDispatcher@12\n\t"
69
70 /* Restore the user context */
71 "addl $4,%esp\n\t" /* UserContext */
72 "addl $24,%esp\n\t" /* Dr[0-3,6-7] */
73 "addl $112,%esp\n\t" /* FloatingSave */
74 "popl %gs\n\t" /* SegGs */
75 "popl %fs\n\t" /* SegFs */
76 "popl %es\n\t" /* SegEs */
77 "popl %ds\n\t" /* SegDs */
78
79 "popl %edi\n\t" /* Edi */
80 "popl %esi\n\t" /* Esi */
81 "popl %ebx\n\t" /* Ebx */
82 "popl %edx\n\t" /* Edx */
83 "popl %ecx\n\t" /* Ecx */
84 "addl $4,%esp\n\t" /* Eax (Not restored) */
85
86 "popl %ebp\n\t" /* Ebp */
87
88 "iret\n\t");
89
90 #elif defined(_MSC_VER)
91
92 __declspec(naked)
93 void interrupt_handler2d()
94 {
95 __asm
96 {
97 /* Save the user context */
98 push ebp
99 push eax
100 push ecx
101 push edx
102 push ebx
103 push esi
104 push edi
105
106 push ds
107 push es
108 push fs
109 push gs
110
111 sub esp, 112 /* FloatSave */
112
113 mov ebx, eax
114 mov eax, dr7 __asm push eax
115 mov eax, dr6 __asm push eax
116 mov eax, dr3 __asm push eax
117 mov eax, dr2 __asm push eax
118 mov eax, dr1 __asm push eax
119 mov eax, dr0 __asm push eax
120 mov eax, ebx
121
122 push 0 /* ContextFlags */
123
124 /* Set ES to kernel segment */
125 mov bx, KERNEL_DS
126 mov es, bx
127
128 /* FIXME: check to see if SS is valid/inrange */
129
130 mov ds, bx /* DS is now also kernel segment */
131
132 /* Call debug service dispatcher */
133 push edx
134 push ecx
135 push eax
136 call KdpServiceDispatcher
137 add esp, 12 /* restore stack pointer */
138
139 /* Restore the user context */
140 add esp, 4 /* UserContext */
141 pop eax __asm mov dr0, eax
142 pop eax __asm mov dr1, eax
143 pop eax __asm mov dr2, eax
144 pop eax __asm mov dr3, eax
145 pop eax __asm mov dr6, eax
146 pop eax __asm mov dr7, eax
147 add esp, 112 /* FloatingSave */
148 pop gs
149 pop fs
150 pop es
151 pop ds
152
153 pop edi
154 pop esi
155 pop ebx
156 pop edx
157 pop ecx
158 add esp, 4 /* Eax Not restored */
159
160 pop ebp
161
162 iretd
163 }
164 }
165
166 #else
167 #error Unknown compiler for inline assembler
168 #endif
169
170 /* EOF */