reactos/reactos/ntoskrnl/kd/service.c
Alex Ionescu e160c0fb26 KD System Rewrite:
- Totally dynamic based on the principle of Native Providers built-in the Kernel (like Screen, 
      FileLog and Serial) and a pluggable Wrapper which is optionally compiled (Bochs, GDB)
    - Nothing changed in KDBG, except for that its settings (KDSERIAL/KDNOECHO) are now stored in
      KdbDebugState instead.
    - Wrappers are currently built uncondtionally. With rbuild, I'll make them easily removable.
    - Debug Log code simplified greatly, sped up and now supports printing even the first boot messages,
      which wasn't supported before.
    - Removed most of KDBG compile-time settings, ones which are needed are in include/dbg as macros now.
    - Left in some kdbg init code and break code, but it could be made to be used as a 'wrapper' for those
      functions. I will do it later.
    - Made a hack for KdpEnterDebuggerException..it seems to be called differently and at different times
      for GDB vs KDBG and I couldn't unite them.
    - KdpServiceDispatcher now does both the documented and ros-internal debug functions and will eventually
      be called through INT2D from keyboard.sys instead of as an API.

All in all, this patch makes KD  separated from KDBG and creates a pluggable architecture for creating future wrappers that don't require changing tons of code in the future. It improves the debug
log by printing even the earliest debug messages to it and it removes many of the manual ifdef(KDBG) but making them automatic though a single macro file. It makes extra debugging functionality optional and it
allows removal of a private API from our exports.

svn path=/trunk/; revision=14799
2005-04-25 14:44:48 +00:00

170 lines
3.7 KiB
C

/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: ntoskrnl/kd/service.c
* PURPOSE: Debug service dispatcher
*
* PROGRAMMERS: Eric Kohl (ekohl@abo.rhein-zeitung.de)
*/
#include <ntoskrnl.h>
/* FUNCTIONS ***************************************************************/
#define _STR(x) #x
#define STR(x) _STR(x)
#if defined(__GNUC__)
void interrupt_handler2d(void);
__asm__("\n\t.global _interrupt_handler2d\n\t"
"_interrupt_handler2d:\n\t"
/* Save the user context */
"pushl %ebp\n\t" /* Ebp */
"pushl %eax\n\t" /* Eax */
"pushl %ecx\n\t" /* Ecx */
"pushl %edx\n\t" /* Edx */
"pushl %ebx\n\t" /* Ebx */
"pushl %esi\n\t" /* Esi */
"pushl %edi\n\t" /* Edi */
"pushl %ds\n\t" /* SegDs */
"pushl %es\n\t" /* SegEs */
"pushl %fs\n\t" /* SegFs */
"pushl %gs\n\t" /* SegGs */
"subl $112,%esp\n\t" /* FloatSave */
"pushl $0\n\t" /* Dr7 */
"pushl $0\n\t" /* Dr6 */
"pushl $0\n\t" /* Dr3 */
"pushl $0\n\t" /* Dr2 */
"pushl $0\n\t" /* Dr1 */
"pushl $0\n\t" /* Dr0 */
"pushl $0\n\t" /* ContextFlags */
/* Set ES to kernel segment */
"movw $"STR(KERNEL_DS)",%bx\n\t"
"movw %bx,%es\n\t"
/* FIXME: check to see if SS is valid/inrange */
/* DS and GS are now also kernel segments */
"movw %bx,%ds\n\t"
"movw %bx,%gs\n\t"
/* Set FS to the PCR */
"movw $"STR(PCR_SELECTOR)",%bx\n\t"
"movw %bx,%fs\n\t"
/* Call debug service dispatcher */
"pushl %edx\n\t"
"pushl %ecx\n\t"
"pushl %eax\n\t"
"call _KdpServiceDispatcher@12\n\t"
/* Restore the user context */
"addl $4,%esp\n\t" /* UserContext */
"addl $24,%esp\n\t" /* Dr[0-3,6-7] */
"addl $112,%esp\n\t" /* FloatingSave */
"popl %gs\n\t" /* SegGs */
"popl %fs\n\t" /* SegFs */
"popl %es\n\t" /* SegEs */
"popl %ds\n\t" /* SegDs */
"popl %edi\n\t" /* Edi */
"popl %esi\n\t" /* Esi */
"popl %ebx\n\t" /* Ebx */
"popl %edx\n\t" /* Edx */
"popl %ecx\n\t" /* Ecx */
"addl $4,%esp\n\t" /* Eax (Not restored) */
"popl %ebp\n\t" /* Ebp */
"iret\n\t");
#elif defined(_MSC_VER)
__declspec(naked)
void interrupt_handler2d()
{
__asm
{
/* Save the user context */
push ebp
push eax
push ecx
push edx
push ebx
push esi
push edi
push ds
push es
push fs
push gs
sub esp, 112 /* FloatSave */
mov ebx, eax
mov eax, dr7 __asm push eax
mov eax, dr6 __asm push eax
mov eax, dr3 __asm push eax
mov eax, dr2 __asm push eax
mov eax, dr1 __asm push eax
mov eax, dr0 __asm push eax
mov eax, ebx
push 0 /* ContextFlags */
/* Set ES to kernel segment */
mov bx, KERNEL_DS
mov es, bx
/* FIXME: check to see if SS is valid/inrange */
mov ds, bx /* DS is now also kernel segment */
/* Call debug service dispatcher */
push edx
push ecx
push eax
call KdpServiceDispatcher
add esp, 12 /* restore stack pointer */
/* Restore the user context */
add esp, 4 /* UserContext */
pop eax __asm mov dr0, eax
pop eax __asm mov dr1, eax
pop eax __asm mov dr2, eax
pop eax __asm mov dr3, eax
pop eax __asm mov dr6, eax
pop eax __asm mov dr7, eax
add esp, 112 /* FloatingSave */
pop gs
pop fs
pop es
pop ds
pop edi
pop esi
pop ebx
pop edx
pop ecx
add esp, 4 /* Eax Not restored */
pop ebp
iretd
}
}
#else
#error Unknown compiler for inline assembler
#endif
/* EOF */