c2f9c3ed009d84e36c0c5d8df90070225ca44998
[reactos.git] / reactos / ntoskrnl / kd / service.c
1 /* $Id: service.c,v 1.5 2002/09/08 10:23:27 chorns 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 void interrupt_handler2d(void);
51 __asm__("\n\t.global _interrupt_handler2d\n\t"
52 "_interrupt_handler2d:\n\t"
53
54 /* Save the user context */
55 "pushl %ebp\n\t" /* Ebp */
56
57 "pushl %eax\n\t" /* Eax */
58 "pushl %ecx\n\t" /* Ecx */
59 "pushl %edx\n\t" /* Edx */
60 "pushl %ebx\n\t" /* Ebx */
61 "pushl %esi\n\t" /* Esi */
62 "pushl %edi\n\t" /* Edi */
63
64 "pushl %ds\n\t" /* SegDs */
65 "pushl %es\n\t" /* SegEs */
66 "pushl %fs\n\t" /* SegFs */
67 "pushl %gs\n\t" /* SegGs */
68
69 "subl $112,%esp\n\t" /* FloatSave */
70
71 "pushl $0\n\t" /* Dr7 */
72 "pushl $0\n\t" /* Dr6 */
73 "pushl $0\n\t" /* Dr3 */
74 "pushl $0\n\t" /* Dr2 */
75 "pushl $0\n\t" /* Dr1 */
76 "pushl $0\n\t" /* Dr0 */
77
78 "pushl $0\n\t" /* ContextFlags */
79
80 /* Set ES to kernel segment */
81 "movw $"STR(KERNEL_DS)",%bx\n\t"
82 "movw %bx,%es\n\t"
83
84 /* FIXME: check to see if SS is valid/inrange */
85
86 /* DS is now also kernel segment */
87 "movw %bx,%ds\n\t"
88
89 /* Call debug service dispatcher */
90 "pushl %edx\n\t"
91 "pushl %ecx\n\t"
92 "pushl %eax\n\t"
93 "call _KdpServiceDispatcher\n\t"
94 "addl $12,%esp\n\t" /* restore stack pointer */
95
96 /* Restore the user context */
97 "addl $4,%esp\n\t" /* UserContext */
98 "addl $24,%esp\n\t" /* Dr[0-3,6-7] */
99 "addl $112,%esp\n\t" /* FloatingSave */
100 "popl %gs\n\t" /* SegGs */
101 "popl %fs\n\t" /* SegFs */
102 "popl %es\n\t" /* SegEs */
103 "popl %ds\n\t" /* SegDs */
104
105 "popl %edi\n\t" /* Edi */
106 "popl %esi\n\t" /* Esi */
107 "popl %ebx\n\t" /* Ebx */
108 "popl %edx\n\t" /* Edx */
109 "popl %ecx\n\t" /* Ecx */
110 "addl $4,%esp\n\t" /* Eax (Not restored) */
111
112 "popl %ebp\n\t" /* Ebp */
113
114 "iret\n\t");
115
116 /* EOF */