From 75f2f5b22ed22d1c7955e8e351f8168e152fbfb5 Mon Sep 17 00:00:00 2001 From: Eric Kohl Date: Wed, 19 Jan 2000 16:24:15 +0000 Subject: [PATCH] Fixed ugly bug in the serial debugging code svn path=/trunk/; revision=941 --- reactos/ntoskrnl/hal/x86/kdbg.c | 94 ++++++++++----------------------- reactos/ntoskrnl/kd/kdebug.c | 14 ++--- 2 files changed, 36 insertions(+), 72 deletions(-) diff --git a/reactos/ntoskrnl/hal/x86/kdbg.c b/reactos/ntoskrnl/hal/x86/kdbg.c index 7615c96ca6c..4cd04a368e4 100644 --- a/reactos/ntoskrnl/hal/x86/kdbg.c +++ b/reactos/ntoskrnl/hal/x86/kdbg.c @@ -1,10 +1,11 @@ -/* $Id: kdbg.c,v 1.3 1999/12/12 03:48:47 phreak Exp $ +/* $Id: kdbg.c,v 1.4 2000/01/19 16:24:15 ekohl Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel * FILE: ntoskrnl/hal/x86/kdbg.c * PURPOSE: Serial i/o functions for the kernel debugger. * PROGRAMMER: Emanuele Aliberti + * Eric Kohl * UPDATE HISTORY: * Created 05/09/99 */ @@ -13,16 +14,11 @@ #include - +#define NDEBUG #include #define DEFAULT_BAUD_RATE 19200 -//#define DEFAULT_COM_PORT 2 -//#define DEFAULT_BASE_ADDRESS 0x2F8 - -#define DEFAULT_COM_PORT 1 -#define DEFAULT_BASE_ADDRESS 0x3F8 /* MACROS *******************************************************************/ @@ -58,8 +54,6 @@ #define SER_SCR(x) ((x)+7) - - /* GLOBAL VARIABLES *********************************************************/ ULONG KdComPortInUse = 0; @@ -78,7 +72,7 @@ static BOOLEAN PortInitialized = FALSE; /* STATIC FUNCTIONS *********************************************************/ static BOOLEAN -KdDoesComPortExist (PUCHAR BaseAddress) +KdpDoesComPortExist (PUCHAR BaseAddress) { BOOLEAN found; BYTE mcr; @@ -131,17 +125,16 @@ KdDoesComPortExist (PUCHAR BaseAddress) BOOLEAN STDCALL KdPortInitialize ( - PKD_PORT_INFORMATION PortInformation, - DWORD Unknown1, - DWORD Unknown2 - ) + PKD_PORT_INFORMATION PortInformation, + DWORD Unknown1, + DWORD Unknown2 + ) { - ULONG BaseArray[5] = {0, 0x3F8, 0x2F8, 3E8, 2E8}; + ULONG BaseArray[5] = {0, 0x3F8, 0x2F8, 0x3E8, 0x2E8}; char buffer[80]; ULONG divisor; BYTE lcr; - if (PortInitialized == FALSE) { if (PortInformation->BaudRate != 0) @@ -155,97 +148,69 @@ KdPortInitialize ( if (PortInformation->ComPort == 0) { - if (KdDoesComPortExist ((PUCHAR)BaseArray[2])) + if (KdpDoesComPortExist ((PUCHAR)BaseArray[2])) { PortBase = (PUCHAR)BaseArray[2]; ComPort = 2; + PortInformation->BaseAddress = (ULONG)PortBase; + PortInformation->ComPort = ComPort; #ifndef NDEBUG sprintf (buffer, "\nSerial port COM%ld found at 0x%lx\n", ComPort, (ULONG)PortBase); HalDisplayString (buffer); -#endif +#endif /* NDEBUG */ } - else if (KdDoesComPortExist ((PUCHAR)BaseArray[1])) + else if (KdpDoesComPortExist ((PUCHAR)BaseArray[1])) { PortBase = (PUCHAR)BaseArray[1]; ComPort = 1; + PortInformation->BaseAddress = (ULONG)PortBase; + PortInformation->ComPort = ComPort; #ifndef NDEBUG sprintf (buffer, "\nSerial port COM%ld found at 0x%lx\n", ComPort, (ULONG)PortBase); HalDisplayString (buffer); -#endif +#endif /* NDEBUG */ } else { sprintf (buffer, "\nKernel Debugger: No COM port found!!!\n\n"); - HalDisplayString (buffer); return FALSE; } } else { - if (KdDoesComPortExist ((PUCHAR)BaseArray[PortInformation->ComPort])) + if (KdpDoesComPortExist ((PUCHAR)BaseArray[PortInformation->ComPort])) { PortBase = (PUCHAR)BaseArray[PortInformation->ComPort]; ComPort = PortInformation->ComPort; + PortInformation->BaseAddress = (ULONG)PortBase; #ifndef NDEBUG sprintf (buffer, "\nSerial port COM%ld found at 0x%lx\n", ComPort, (ULONG)PortBase); HalDisplayString (buffer); -#endif +#endif /* NDEBUG */ } else { sprintf (buffer, "\nKernel Debugger: No serial port found!!!\n\n"); - HalDisplayString (buffer); return FALSE; } } -/* - if (KdDoesComPortExist ((PUCHAR)BaseArray[2])) - { - PortBase = (PUCHAR)BaseArray[2]; - ComPort = 2; - sprintf (buffer, - "\nCOM port found at 0x%lx\n", - (ULONG)PortBase); - - HalDisplayString (buffer); - } - else if (KdDoesComPortExist ((PUCHAR)BaseArray[1])) - { - PortBase = (PUCHAR)BaseArray[1]; - ComPort = 1; - sprintf (buffer, - "\nCOM port found at 0x%lx\n", - (ULONG)PortBase); - - HalDisplayString (buffer); - } - else - { - sprintf (buffer, - "\nKernel Debugger: No COM port found!!!\n"); - - HalDisplayString (buffer); - return FALSE; - } -*/ PortInitialized = TRUE; } - /* * set baud rate and data format (8N1) */ @@ -278,7 +243,7 @@ KdPortInitialize ( * print message to blue screen */ sprintf (buffer, - "\nKernel Debugger using: COM%ld (Port 0x%lx) BaudRate %ld\n\n", + "\nKernel Debugger: COM%ld (Port 0x%lx) BaudRate %ld\n\n", ComPort, (ULONG)PortBase, BaudRate); @@ -296,9 +261,8 @@ KdPortGetByte ( VOID ) { - if (PortInitialized == FALSE) - return 0; - + if (PortInitialized == FALSE) + return 0; return (BYTE) 0; } @@ -319,16 +283,16 @@ KdPortPollByte ( VOID STDCALL KdPortPutByte ( - UCHAR ByteToSend + UCHAR ByteToSend ) { - if (PortInitialized == FALSE) - return; + if (PortInitialized == FALSE) + return; - while ((READ_PORT_UCHAR (SER_LSR(PortBase)) & SR_LSR_TBE) == 0) - ; + while ((READ_PORT_UCHAR (SER_LSR(PortBase)) & SR_LSR_TBE) == 0) + ; - WRITE_PORT_UCHAR (SER_THR(PortBase), ByteToSend); + WRITE_PORT_UCHAR (SER_THR(PortBase), ByteToSend); } diff --git a/reactos/ntoskrnl/kd/kdebug.c b/reactos/ntoskrnl/kd/kdebug.c index 3a8b1274d44..0cad9b05bf9 100644 --- a/reactos/ntoskrnl/kd/kdebug.c +++ b/reactos/ntoskrnl/kd/kdebug.c @@ -1,4 +1,4 @@ -/* $Id: kdebug.c,v 1.3 2000/01/17 21:02:06 ekohl Exp $ +/* $Id: kdebug.c,v 1.4 2000/01/19 16:23:56 ekohl Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -30,13 +30,13 @@ * 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 */ +#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 0x03f8 /* COM 1 */ -// #define SERIAL_DEBUG_PORT 0x02f8 /* COM 2 */ +#define SERIAL_DEBUG_PORT 1 /* COM 1 */ +// #define SERIAL_DEBUG_PORT 2 /* COM 2 */ #define SERIAL_DEBUG_BAUD_RATE 19200 @@ -75,7 +75,7 @@ KdInitSystem (VOID) #ifdef SERIAL_DEBUGGING KD_PORT_INFORMATION PortInfo; - PortInfo.BaseAddress = SERIAL_DEBUG_PORT; + PortInfo.ComPort = SERIAL_DEBUG_PORT; PortInfo.BaudRate = SERIAL_DEBUG_BAUD_RATE; KdPortInitialize (&PortInfo,