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