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