Implemented kernel parameter line

Some kernel debugger improvements

svn path=/trunk/; revision=1030
This commit is contained in:
Eric Kohl 2000-03-04 22:03:32 +00:00
parent 51df161b78
commit 9eac680002
11 changed files with 384 additions and 137 deletions

View file

@ -1,6 +1,14 @@
#ifndef __INCLUDE_DDK_DBGFUNCS_H
#define __INCLUDE_DDK_DBGFUNCS_H
/* $Id: dbgfuncs.h,v 1.4 2000/03/04 21:58:49 ekohl Exp $ */
VOID STDCALL DbgBreakPoint(VOID);
#define DBG_STATUS_CONTROL_C 1
#define DBG_STATUS_SYSRQ 2
#define DBG_STATUS_BUGCHECK_FIRST 3
#define DBG_STATUS_BUGCHECK_SECOND 4
#define DBG_STATUS_FATAL 5
VOID STDCALL DbgBreakPointWithStatus (ULONG Status);
VOID STDCALL DbgBreakPoint(VOID);
ULONG DbgPrint(PCH Format,...);
#define DBG_GET_SHOW_FACILITY 0x0001
@ -10,3 +18,4 @@ ULONG DbgPrint(PCH Format,...);
VOID DbgGetErrorText(NTSTATUS ErrorCode, PUNICODE_STRING ErrorText, ULONG Flags);
VOID DbgPrintErrorMessage(NTSTATUS ErrorCode);
#endif /* __INCLUDE_DDK_DBGFUNCS_H */

View file

@ -1,6 +1,6 @@
#ifndef __INCLUDE_DDK_KDFUNCS_H
#define __INCLUDE_DDK_KDFUNCS_H
/* $Id: kdfuncs.h,v 1.2 2000/02/29 23:57:44 ea Exp $ */
/* $Id: kdfuncs.h,v 1.3 2000/03/04 21:58:49 ekohl Exp $ */
/* --- NTOSKRNL.EXE --- */
#if defined(__NTOSKRNL__)
@ -31,15 +31,15 @@ KdPortInitialize (
DWORD Unknown1,
DWORD Unknown2
);
BYTE
BOOLEAN
STDCALL
KdPortGetByte (
VOID
PUCHAR ByteRecieved
);
BYTE
BOOLEAN
STDCALL
KdPortPollByte (
VOID
PUCHAR ByteRecieved
);
VOID
STDCALL

View file

@ -1,4 +1,4 @@
/* $Id: ddk.h,v 1.10 2000/03/04 20:45:33 ea Exp $
/* $Id: ddk.h,v 1.11 2000/03/04 21:59:32 ekohl Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -208,6 +208,14 @@ KdPortInitialize (PKD_PORT_INFORMATION PortInformation,
DWORD Unknown1,
DWORD Unknown2);
BOOLEAN
STDCALL
KdPortGetByte (PUCHAR ByteRecieved);
BOOLEAN
STDCALL
KdPortPollByte (PUCHAR ByteRecieved);
VOID
STDCALL
KdPortPutByte (UCHAR ByteToSend);

View file

@ -33,6 +33,11 @@ typedef struct
* List of module lengths (terminated by a 0)
*/
unsigned int module_length[64];
/*
* Kernel parameter string
*/
char kernel_parameters[256];
} boot_param;
@ -87,6 +92,6 @@ VOID TstBegin(VOID);
VOID KeInit(VOID);
VOID CmInitializeRegistry(VOID);
VOID CmImportHive(PCHAR);
VOID KdInitSystem(VOID);
VOID KdInitSystem(ULONG Reserved, boot_param* BootParam);
#endif

View file

@ -1,4 +1,4 @@
/* $Id: kdbg.c,v 1.7 2000/02/29 23:57:45 ea Exp $
/* $Id: kdbg.c,v 1.8 2000/03/04 22:01:17 ekohl Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -258,36 +258,41 @@ KdPortInitialize (
/* HAL.KdPortGetByte */
BYTE
BOOLEAN
STDCALL
KdPortGetByte (
VOID
PUCHAR ByteRecieved
)
{
if (PortInitialized == FALSE)
return 0;
return FALSE;
if ((READ_PORT_UCHAR (SER_LSR(PortBase)) & SR_LSR_DR))
return (BYTE)READ_PORT_UCHAR (SER_RBR(PortBase));
{
*ByteRecieved = READ_PORT_UCHAR (SER_RBR(PortBase));
return TRUE;
}
return 0;
return FALSE;
}
/* HAL.KdPortPollByte */
BYTE
BOOLEAN
STDCALL
KdPortPollByte (
VOID
PUCHAR ByteRecieved
)
{
if (PortInitialized == FALSE)
return 0;
return FALSE;
while ((READ_PORT_UCHAR (SER_LSR(PortBase)) & SR_LSR_DR) == 0)
;
return (BYTE)READ_PORT_UCHAR (SER_RBR(PortBase));
*ByteRecieved = READ_PORT_UCHAR (SER_RBR(PortBase));
return TRUE;
}

View file

@ -1,4 +1,4 @@
/* $Id: kdebug.c,v 1.7 2000/03/03 00:46:37 ekohl Exp $
/* $Id: kdebug.c,v 1.8 2000/03/04 22:02:13 ekohl Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -12,121 +12,308 @@
#include <ddk/ntddk.h>
#include <internal/ntoskrnl.h>
#include <internal/kd.h>
#include <stdlib.h>
#include <ctype.h>
/*
* Uncomment one of the following symbols to select a debug output style.
*
* SCREEN_DEBUGGING:
* Debug information is printed on the screen.
*
* SERIAL_DEBUGGING:
* Debug information is printed to a serial device. Check the port
* address, the baud rate and the data format.
* Default: COM1 19200 Baud 8N1 (8 data bits, no parity, 1 stop bit)
*
* BOCHS_DEBUGGING: (not tested yet)
* Debug information is printed to the bochs logging port. Bochs
* writes the output to a log file.
*/
/* serial debug connection */
#define DEFAULT_DEBUG_PORT 2 /* COM2 */
#define DEFAULT_DEBUG_BAUD_RATE 19200 /* 19200 Baud */
#define SCREEN_DEBUGGING /* debug info is printed on the screen */
//#define SERIAL_DEBUGGING /* remote debugging */
//#define BOCHS_DEBUGGING /* debug output using bochs */
#define SERIAL_DEBUG_PORT 1 /* COM 1 */
// #define SERIAL_DEBUG_PORT 2 /* COM 2 */
#define SERIAL_DEBUG_BAUD_RATE 19200
//#define BOCHS_DEBUGGING
#ifdef BOCHS_DEBUGGING
/* bochs debug output */
#define BOCHS_LOGGER_PORT (0xe9)
#endif
/* TYPEDEFS ****************************************************************/
typedef enum
{
ScreenDebug,
SerialDebug,
BochsDebug
} DEBUGTYPE;
/* VARIABLES ***************************************************************/
BOOLEAN KdDebuggerEnabled = FALSE; /* EXPORTED */
BOOLEAN KdDebuggerNotPresent = TRUE; /* EXPORTED */
BOOLEAN
__declspec(dllexport)
KdDebuggerEnabled = FALSE; /* EXPORTED */
BOOLEAN
__declspec(dllexport)
KdDebuggerNotPresent = TRUE; /* EXPORTED */
static BOOLEAN KdpBreakPending = FALSE;
static BOOLEAN KdpBreakRecieved = FALSE;
static DEBUGTYPE KdpDebugType = ScreenDebug;
/* PRIVATE FUNCTIONS ********************************************************/
VOID
KdInitSystem (VOID)
static void
PrintString (char* fmt,...)
{
char buffer[512];
va_list ap;
va_start(ap, fmt);
vsprintf(buffer, fmt, ap);
va_end(ap);
HalDisplayString (buffer);
}
VOID
KdInitSystem (
ULONG Reserved,
boot_param* BootParam
)
{
KD_PORT_INFORMATION PortInfo;
ULONG Value;
PCHAR p1, p2;
/* set debug port default values */
PortInfo.ComPort = DEFAULT_DEBUG_PORT;
PortInfo.BaudRate = DEFAULT_DEBUG_BAUD_RATE;
/*
* parse kernel command line
*/
/* check for 'DEBUGPORT' */
p1 = BootParam->kernel_parameters;
while (p1 && (p2 = strchr (p1, '/')))
{
p2++;
if (!_strnicmp (p2, "DEBUGPORT", 9))
{
p2 += 9;
if (*p2 != '=')
break;
p2++;
if (!_strnicmp (p2, "SCREEN", 6))
{
p2 += 6;
KdDebuggerEnabled = TRUE;
KdpDebugType = ScreenDebug;
}
else if (!_strnicmp (p2, "BOCHS", 5))
{
p2 += 5;
KdDebuggerEnabled = TRUE;
KdpDebugType = BochsDebug;
}
else if (!_strnicmp (p2, "COM", 3))
{
p2 += 3;
Value = (ULONG)atol (p2);
if (Value > 0 && Value < 5)
{
KdDebuggerEnabled = TRUE;
KdpDebugType = SerialDebug;
PortInfo.ComPort = Value;
}
}
break;
}
p1 = p2;
}
/* check for 'BAUDRATE' */
p1 = BootParam->kernel_parameters;
while (p1 && (p2 = strchr (p1, '/')))
{
p2++;
if (!_strnicmp (p2, "BAUDRATE", 8))
{
p2 += 8;
if (*p2 != '=')
break;
p2++;
Value = (ULONG)atol (p2);
if (Value > 0)
{
KdDebuggerEnabled = TRUE;
KdpDebugType = SerialDebug;
PortInfo.BaudRate = Value;
}
break;
}
p1 = p2;
}
/* Check for 'DEBUG'. Dont' accept 'DEBUGPORT'!*/
p1 = BootParam->kernel_parameters;
while (p1 && (p2 = strchr (p1, '/')))
{
p2++;
if (!_strnicmp (p2, "DEBUG", 5) &&
_strnicmp (p2, "DEBUGPORT", 9))
{
p2 += 5;
KdDebuggerEnabled = TRUE;
KdpDebugType = SerialDebug;
break;
}
p1 = p2;
}
/* Check for 'NODEBUG' */
p1 = BootParam->kernel_parameters;
while (p1 && (p2 = strchr (p1, '/')))
{
p2++;
if (!_strnicmp (p2, "NODEBUG", 7))
{
p2 += 7;
KdDebuggerEnabled = FALSE;
break;
}
p1 = p2;
}
/* Check for 'CRASHDEBUG' */
p1 = BootParam->kernel_parameters;
while (p1 && (p2 = strchr (p1, '/')))
{
p2++;
if (!_strnicmp (p2, "CRASHDEBUG", 10))
{
p2 += 10;
KdDebuggerEnabled = FALSE;
break;
}
p1 = p2;
}
/* Check for 'BREAK' */
p1 = BootParam->kernel_parameters;
while (p1 && (p2 = strchr (p1, '/')))
{
p2++;
if (!_strnicmp (p2, "BREAK", 5))
{
p2 += 7;
KdpBreakPending = TRUE;
break;
}
p1 = p2;
}
/* print some information */
if (KdDebuggerEnabled == TRUE)
{
if (KdpDebugType == ScreenDebug)
{
PrintString ("\n Screen debugging enabled\n\n");
}
else if (KdpDebugType == BochsDebug)
{
PrintString ("\n Bochs debugging enabled\n\n");
}
else if (KdpDebugType == SerialDebug)
{
PrintString ("\n Serial debugging enabled: COM%ld %ld Baud\n\n",
PortInfo.ComPort, PortInfo.BaudRate);
}
}
else
PrintString ("\n Debugging disabled\n\n");
/* FIXME: parse kernel command line */
/* initialize debug port */
#ifdef SERIAL_DEBUGGING
KD_PORT_INFORMATION PortInfo;
PortInfo.ComPort = SERIAL_DEBUG_PORT;
PortInfo.BaudRate = SERIAL_DEBUG_BAUD_RATE;
KdPortInitialize (&PortInfo,
0,
0);
#endif
if (KdDebuggerEnabled && KdpDebugType == SerialDebug)
{
KdPortInitialize (&PortInfo,
0,
0);
}
}
ULONG
KdpPrintString (PANSI_STRING String)
{
#if defined(SERIAL_DEBUGGING) || defined(BOCHS_DEBUGGING)
PCH pch = String->Buffer;
#endif
PCH pch = String->Buffer;
#ifdef SCREEN_DEBUGGING
HalDisplayString (String->Buffer);
#endif
if (KdpDebugType == ScreenDebug)
{
HalDisplayString (String->Buffer);
}
else if (KdpDebugType == SerialDebug)
{
while (*pch != 0)
{
if (*pch == '\n')
{
KdPortPutByte ('\r');
}
KdPortPutByte (*pch);
pch++;
}
}
else if (KdpDebugType == BochsDebug)
{
while (*pch != 0)
{
if (*pch == '\n')
{
WRITE_PORT_UCHAR((PUCHAR)BOCHS_LOGGER_PORT, '\r');
}
WRITE_PORT_UCHAR((PUCHAR)BOCHS_LOGGER_PORT, *pch);
pch++;
}
}
#ifdef SERIAL_DEBUGGING
while (*pch != 0)
{
if (*pch == '\n')
{
KdPortPutByte ('\r');
}
KdPortPutByte (*pch);
pch++;
}
#endif
#ifdef BOCHS_DEBUGGING
while (*pch != 0)
{
if (*pch == '\n')
{
WRITE_PORT_UCHAR((PUCHAR)BOCHS_LOGGER_PORT, '\r');
}
WRITE_PORT_UCHAR((PUCHAR)BOCHS_LOGGER_PORT, *pch);
pch++;
}
#endif
return (ULONG)String->Length;
return (ULONG)String->Length;
}
/* PUBLIC FUNCTIONS *********************************************************/
/* NTOSKRNL.KdPollBreakIn */
BYTE
BOOLEAN
STDCALL
KdPollBreakIn (
VOID
)
{
return KdPortPollByte();
BOOLEAN Result = FALSE;
UCHAR ByteRead;
if (KdDebuggerEnabled == FALSE || KdpDebugType != SerialDebug)
return Result;
// Flags = KiDisableInterrupts();
HalDisplayString ("Waiting for kernel debugger connection...\n");
if (KdPortPollByte (&ByteRead))
{
if (ByteRead == 0x62)
{
if (KdpBreakPending == TRUE)
{
KdpBreakPending = FALSE;
KdpBreakRecieved = TRUE;
Result = TRUE;
}
HalDisplayString (" Kernel debugger connected\n");
}
else
{
HalDisplayString (" Kernel debugger connection failed\n");
}
}
// KiRestoreInterrupts (Flags);
return Result;
}
VOID

View file

@ -1,4 +1,4 @@
/* $Id: service.c,v 1.2 2000/02/27 02:09:40 ekohl Exp $
/* $Id: service.c,v 1.3 2000/03/04 22:02:13 ekohl Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -49,8 +49,8 @@ KdpServiceDispatcher (
void interrupt_handler2d(void);
__asm__("\n\t.global _interrupt_handler2d\n\t"
"_interrupt_handler2d:\n\t"
"_interrupt_handler2d:\n\t"
/* Save the user context */
"pushl %ebp\n\t" /* Ebp */
@ -77,10 +77,10 @@ void interrupt_handler2d(void);
"pushl $0\n\t" /* ContextFlags */
/* Set ES to kernel segment */
"movw $"STR(KERNEL_DS)",%bx\n\t"
"movw %bx,%es\n\t"
/* 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 is now also kernel segment */
@ -90,10 +90,10 @@ void interrupt_handler2d(void);
"pushl %edx\n\t"
"pushl %ecx\n\t"
"pushl %eax\n\t"
"call _KdpServiceDispatcher\n\t"
"addl $12,%esp\n\t" /* restore stack pointer */
"call _KdpServiceDispatcher\n\t"
"addl $12,%esp\n\t" /* restore stack pointer */
/* Restore the user context */
/* 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 */
@ -107,10 +107,10 @@ void interrupt_handler2d(void);
"popl %ebx\n\t" /* Ebx */
"popl %edx\n\t" /* Edx */
"popl %ecx\n\t" /* Ecx */
"addl $4,%esp\n\t" /* Eax (Not restored) */
"addl $4,%esp\n\t" /* Eax (Not restored) */
"popl %ebp\n\t" /* Ebp */
"iret\n\t");
"iret\n\t");
/* EOF */

View file

@ -185,7 +185,7 @@ asmlinkage void exception_handler(unsigned int edi,
{
"Divide Error",
"Debug Trap",
"Unknown(2)",
"NMI",
"Breakpoint",
"Overflow",
"BOUND range exceeded",

View file

@ -1,4 +1,4 @@
/* $Id: main.c,v 1.38 2000/02/29 23:57:45 ea Exp $
/* $Id: main.c,v 1.39 2000/03/04 22:03:01 ekohl Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -39,7 +39,21 @@ __declspec(dllexport)
NtGlobalFlag = 0; /* FIXME: EXPORTED */
/* FUNCTIONS ****************************************************************/
static void
PrintString (char* fmt,...)
{
char buffer[512];
va_list ap;
va_start(ap, fmt);
vsprintf(buffer, fmt, ap);
va_end(ap);
HalDisplayString (buffer);
}
void set_breakpoint(unsigned int i, unsigned int addr, unsigned int type,
unsigned int len)
/*
@ -86,19 +100,19 @@ void set_breakpoint(unsigned int i, unsigned int addr, unsigned int type,
__asm__("movl %0,%%db1\n\t"
: /* no outputs */
: "d" (addr));
break;
break;
case 2:
__asm__("movl %0,%%db2\n\t"
: /* no outputs */
: "d" (addr));
break;
break;
case 3:
__asm__("movl %0,%%db3\n\t"
: /* no outputs */
: "d" (addr));
break;
break;
}
/*
@ -158,36 +172,49 @@ asmlinkage void _main(boot_param* _bp)
* Copy the parameters to a local buffer because lowmem will go away
*/
memcpy(&bp,_bp,sizeof(boot_param));
/*
* FIXME: Preliminary hack!!!!
* Initializes the kernel parameter line.
* This should be done by the boot loader.
*/
strcpy (bp.kernel_parameters, "/DEBUGPORT=SCREEN");
/*
* Initalize the hal (Phase 0)
*/
HalInitSystem (0, &bp);
HalDisplayString("Starting ReactOS "KERNEL_VERSION_STR" (Build "KERNEL_VERSION_BUILD_STR")\n");
/*
* Initialize the debug output
*/
KdInitSystem ();
HalDisplayString("Starting ReactOS "KERNEL_VERSION_STR" (Build "KERNEL_VERSION_BUILD_STR")\n");
start = KERNEL_BASE + PAGE_ROUND_UP(bp.module_length[0]);
if (start < ((int)&end))
{
DbgPrint("start %x end %x\n",start,(int)&end);
DbgPrint("Kernel booted incorrectly, aborting\n");
DbgPrint("Reduce the amount of uninitialized data\n");
for(;;);
}
PrintString("start %x end %x\n",start,(int)&end);
PrintString("Kernel booted incorrectly, aborting\n");
PrintString("Reduce the amount of uninitialized data\n");
PrintString("\n\n*** The system has halted ***\n");
for(;;)
__asm__("hlt\n\t");
}
start1 = start+PAGE_ROUND_UP(bp.module_length[1]);
last_kernel_address = KERNEL_BASE;
for (i=0; i<=bp.nr_files; i++)
{
last_kernel_address = last_kernel_address +
PAGE_ROUND_UP(bp.module_length[i]);
}
/*
* Initialize the kernel debugger
*/
KdInitSystem (0, &bp);
// if (KdPollBreakIn ())
// {
// DbgBreakPointWithStatus (DBG_STATUS_CONTROL_C);
// }
/*
* Initalize various critical subsystems
*/
@ -213,6 +240,12 @@ asmlinkage void _main(boot_param* _bp)
memcpy(old_idt, KiIdt, sizeof(old_idt));
old_idt_valid = 0;
/* Just a test. Exceptions and Interrupts are initialized now */
if (KdPollBreakIn ())
{
DbgBreakPointWithStatus (DBG_STATUS_CONTROL_C);
}
/*
* Initalize services loaded at boot time
*/

View file

@ -1,4 +1,4 @@
; $Id: ntoskrnl.def,v 1.50 2000/03/04 20:45:34 ea Exp $
; $Id: ntoskrnl.def,v 1.51 2000/03/04 22:00:21 ekohl Exp $
;
; reactos/ntoskrnl/ntoskrnl.def
;
@ -665,9 +665,9 @@ HalSetRealTimeClock
;IoSetPartitionInformation
;IoWritePartitionTable
KdComPortInUse DATA
KdPortGetByte@0
KdPortGetByte@4
KdPortInitialize@12
KdPortPollByte@0
KdPortPollByte@4
KdPortPutByte@4
KdPortRestore@0
KdPortSave@0

View file

@ -1,4 +1,4 @@
; $Id: ntoskrnl.edf,v 1.37 2000/03/04 20:45:34 ea Exp $
; $Id: ntoskrnl.edf,v 1.38 2000/03/04 22:00:21 ekohl Exp $
;
; reactos/ntoskrnl/ntoskrnl.def
;
@ -579,9 +579,9 @@ HalSetRealTimeClock
;IoSetPartitionInformation
;IoWritePartitionTable
KdComPortInUse DATA
KdPortGetByte=KdPortGetByte@0
KdPortGetByte=KdPortGetByte@4
KdPortInitialize=KdPortInitialize@12
KdPortPollByte=KdPortPollByte@0
KdPortPollByte=KdPortPollByte@4
KdPortPutByte=KdPortPutByte@4
KdPortRestore=KdPortRestore@0
KdPortSave=KdPortSave@0