-/* $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
#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.
- */
-
-#define SCREEN_DEBUGGING /* debug info is printed on the screen */
-//#define SERIAL_DEBUGGING /* remote debugging */
-//#define BOCHS_DEBUGGING /* debug output using bochs */
+/* serial debug connection */
+#define DEFAULT_DEBUG_PORT 2 /* COM2 */
+#define DEFAULT_DEBUG_BAUD_RATE 19200 /* 19200 Baud */
+/* bochs debug output */
+#define BOCHS_LOGGER_PORT (0xe9)
-#define SERIAL_DEBUG_PORT 1 /* COM 1 */
-// #define SERIAL_DEBUG_PORT 2 /* COM 2 */
-#define SERIAL_DEBUG_BAUD_RATE 19200
+/* TYPEDEFS ****************************************************************/
-//#define BOCHS_DEBUGGING
-#ifdef BOCHS_DEBUGGING
-#define BOCHS_LOGGER_PORT (0xe9)
-#endif
+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;
- /* FIXME: parse kernel command line */
+ va_start(ap, fmt);
+ vsprintf(buffer, fmt, ap);
+ va_end(ap);
- /* initialize debug port */
-#ifdef SERIAL_DEBUGGING
+ 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");
- PortInfo.ComPort = SERIAL_DEBUG_PORT;
- PortInfo.BaudRate = SERIAL_DEBUG_BAUD_RATE;
- KdPortInitialize (&PortInfo,
- 0,
- 0);
-#endif
+ /* initialize debug port */
+ 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
-
-#ifdef SCREEN_DEBUGGING
- HalDisplayString (String->Buffer);
-#endif
-
-#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;
+ PCH pch = String->Buffer;
+
+ 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++;
+ }
+ }
+
+ 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
-/* $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
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 */
"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 */
"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 */
"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 */
-/* $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
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)
/*
__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;
}
/*
* Copy the parameters to a local buffer because lowmem will go away
*/
memcpy(&bp,_bp,sizeof(boot_param));
-
+
/*
- * Initalize the hal (Phase 0)
+ * FIXME: Preliminary hack!!!!
+ * Initializes the kernel parameter line.
+ * This should be done by the boot loader.
*/
- HalInitSystem (0, &bp);
-
- HalDisplayString("Starting ReactOS "KERNEL_VERSION_STR" (Build "KERNEL_VERSION_BUILD_STR")\n");
+ strcpy (bp.kernel_parameters, "/DEBUGPORT=SCREEN");
/*
- * Initialize the debug output
+ * Initalize the hal (Phase 0)
*/
- KdInitSystem ();
+ HalInitSystem (0, &bp);
+
+ 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
*/
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
*/