2007-12-06 13:11:21 +00:00
|
|
|
|
/*
|
2007-10-23 08:30:39 +00:00
|
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
|
|
|
|
* PROJECT: ReactOS kernel
|
2007-12-06 13:11:21 +00:00
|
|
|
|
* FILE: drivers/base/kdcom/kdbg.c
|
2007-10-23 08:30:39 +00:00
|
|
|
|
* PURPOSE: Serial i/o functions for the kernel debugger.
|
2007-12-06 13:11:21 +00:00
|
|
|
|
* PROGRAMMER: Alex Ionescu
|
|
|
|
|
* Herv<EFBFBD> Poussineau
|
2007-10-23 08:30:39 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/* INCLUDES *****************************************************************/
|
|
|
|
|
|
2013-05-08 15:36:38 +00:00
|
|
|
|
#include <ntoskrnl.h>
|
2012-11-29 10:26:00 +00:00
|
|
|
|
#define NDEBUG
|
|
|
|
|
#include <debug.h>
|
|
|
|
|
|
2007-10-23 08:30:39 +00:00
|
|
|
|
|
2013-05-07 00:14:36 +00:00
|
|
|
|
#define DEFAULT_BAUD_RATE 19200
|
2007-10-23 08:30:39 +00:00
|
|
|
|
|
2012-11-29 10:26:00 +00:00
|
|
|
|
#if defined(_M_IX86) || defined(_M_AMD64)
|
|
|
|
|
const ULONG BaseArray[] = {0, 0x3F8, 0x2F8, 0x3E8, 0x2E8};
|
2007-12-06 13:11:21 +00:00
|
|
|
|
#elif defined(_M_PPC)
|
2012-11-29 10:26:00 +00:00
|
|
|
|
const ULONG BaseArray[] = {0, 0x800003F8};
|
2007-12-06 13:11:21 +00:00
|
|
|
|
#elif defined(_M_MIPS)
|
2012-11-29 10:26:00 +00:00
|
|
|
|
const ULONG BaseArray[] = {0, 0x80006000, 0x80007000};
|
2008-02-08 08:20:06 +00:00
|
|
|
|
#elif defined(_M_ARM)
|
2012-11-29 10:26:00 +00:00
|
|
|
|
const ULONG BaseArray[] = {0, 0xF1012000};
|
2007-12-06 13:11:21 +00:00
|
|
|
|
#else
|
|
|
|
|
#error Unknown architecture
|
|
|
|
|
#endif
|
2007-10-23 08:30:39 +00:00
|
|
|
|
|
2013-05-07 00:14:36 +00:00
|
|
|
|
/* STATIC VARIABLES ***********************************************************/
|
2007-10-23 08:30:39 +00:00
|
|
|
|
|
2013-05-07 00:14:36 +00:00
|
|
|
|
// static CPPORT DefaultPort = {0, 0, 0};
|
2007-10-23 08:30:39 +00:00
|
|
|
|
|
2013-05-07 00:14:36 +00:00
|
|
|
|
/* The COM port must only be initialized once! */
|
2013-05-05 20:05:50 +00:00
|
|
|
|
// static BOOLEAN PortInitialized = FALSE;
|
2007-10-23 08:30:39 +00:00
|
|
|
|
|
|
|
|
|
|
2013-05-05 21:57:42 +00:00
|
|
|
|
/* REACTOS FUNCTIONS **********************************************************/
|
2007-10-23 08:30:39 +00:00
|
|
|
|
|
2013-05-08 15:36:38 +00:00
|
|
|
|
NTSTATUS
|
|
|
|
|
NTAPI
|
|
|
|
|
KdDebuggerInitialize1(
|
|
|
|
|
IN PLOADER_PARAMETER_BLOCK LoaderBlock OPTIONAL)
|
|
|
|
|
{
|
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
|
|
|
|
}
|
|
|
|
|
|
2007-10-23 08:30:39 +00:00
|
|
|
|
BOOLEAN
|
2007-12-06 13:11:21 +00:00
|
|
|
|
NTAPI
|
2013-05-05 19:55:42 +00:00
|
|
|
|
KdPortInitializeEx(
|
2013-05-07 00:14:36 +00:00
|
|
|
|
IN PCPPORT PortInformation,
|
|
|
|
|
IN ULONG ComPortNumber)
|
2007-10-23 08:30:39 +00:00
|
|
|
|
{
|
2013-05-07 00:14:36 +00:00
|
|
|
|
NTSTATUS Status;
|
2013-05-05 19:55:42 +00:00
|
|
|
|
|
2013-05-05 20:05:50 +00:00
|
|
|
|
#if 0 // Deactivated because never used in fact (was in KdPortInitialize but we use KdPortInitializeEx)
|
2013-05-05 19:55:42 +00:00
|
|
|
|
/*
|
|
|
|
|
* Find the port if needed
|
|
|
|
|
*/
|
2013-05-05 20:05:50 +00:00
|
|
|
|
SIZE_T i;
|
2007-10-23 08:30:39 +00:00
|
|
|
|
|
2007-12-06 13:11:21 +00:00
|
|
|
|
if (!PortInitialized)
|
|
|
|
|
{
|
|
|
|
|
DefaultPort.BaudRate = PortInformation->BaudRate;
|
2007-10-23 08:30:39 +00:00
|
|
|
|
|
2013-05-07 00:14:36 +00:00
|
|
|
|
if (ComPortNumber == 0)
|
2007-12-06 13:11:21 +00:00
|
|
|
|
{
|
2012-11-29 10:26:00 +00:00
|
|
|
|
/*
|
|
|
|
|
* Start enumerating COM ports from the last one to the first one,
|
|
|
|
|
* and break when we find a valid port.
|
|
|
|
|
* If we reach the first element of the list, the invalid COM port,
|
|
|
|
|
* then it means that no valid port was found.
|
|
|
|
|
*/
|
2007-12-06 13:11:21 +00:00
|
|
|
|
for (i = sizeof(BaseArray) / sizeof(BaseArray[0]) - 1; i > 0; i--)
|
|
|
|
|
{
|
2012-11-29 10:26:00 +00:00
|
|
|
|
if (CpDoesPortExist(UlongToPtr(BaseArray[i])))
|
2007-10-23 08:30:39 +00:00
|
|
|
|
{
|
2013-05-07 00:14:36 +00:00
|
|
|
|
PortInformation->Address = DefaultPort.Address = BaseArray[i];
|
|
|
|
|
ComPortNumber = (ULONG)i;
|
2007-12-06 13:11:21 +00:00
|
|
|
|
break;
|
2007-10-23 08:30:39 +00:00
|
|
|
|
}
|
2007-12-06 13:11:21 +00:00
|
|
|
|
}
|
2013-05-07 00:14:36 +00:00
|
|
|
|
if (ComPortNumber == 0)
|
2007-12-06 13:11:21 +00:00
|
|
|
|
{
|
2013-10-13 23:04:13 +00:00
|
|
|
|
HalDisplayString("\r\nKernel Debugger: No COM port found!\r\n\r\n");
|
2007-12-06 13:11:21 +00:00
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2007-10-23 08:30:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-12-06 13:11:21 +00:00
|
|
|
|
PortInitialized = TRUE;
|
|
|
|
|
}
|
2013-05-05 20:05:50 +00:00
|
|
|
|
#endif
|
2007-10-23 08:30:39 +00:00
|
|
|
|
|
2013-05-05 19:55:42 +00:00
|
|
|
|
/*
|
|
|
|
|
* Initialize the port
|
|
|
|
|
*/
|
2013-05-07 00:14:36 +00:00
|
|
|
|
Status = CpInitialize(PortInformation,
|
|
|
|
|
(ComPortNumber == 0 ? PortInformation->Address
|
|
|
|
|
: UlongToPtr(BaseArray[ComPortNumber])),
|
|
|
|
|
(PortInformation->BaudRate == 0 ? DEFAULT_BAUD_RATE
|
|
|
|
|
: PortInformation->BaudRate));
|
|
|
|
|
if (!NT_SUCCESS(Status))
|
2011-11-22 02:30:16 +00:00
|
|
|
|
{
|
2013-10-13 23:04:13 +00:00
|
|
|
|
HalDisplayString("\r\nKernel Debugger: Serial port not found!\r\n\r\n");
|
2013-05-07 00:14:36 +00:00
|
|
|
|
return FALSE;
|
2011-11-22 02:30:16 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
2007-12-06 13:11:21 +00:00
|
|
|
|
{
|
2007-10-23 08:30:39 +00:00
|
|
|
|
#ifndef NDEBUG
|
2013-10-13 23:07:26 +00:00
|
|
|
|
CHAR buffer[80];
|
|
|
|
|
|
2013-05-07 00:14:36 +00:00
|
|
|
|
/* Print message to blue screen */
|
|
|
|
|
sprintf(buffer,
|
2013-10-13 23:04:13 +00:00
|
|
|
|
"\r\nKernel Debugger: Serial port found: COM%ld (Port 0x%lx) BaudRate %ld\r\n\r\n",
|
2013-05-07 00:14:36 +00:00
|
|
|
|
ComPortNumber,
|
|
|
|
|
PortInformation->Address,
|
|
|
|
|
PortInformation->BaudRate);
|
|
|
|
|
HalDisplayString(buffer);
|
2007-10-23 08:30:39 +00:00
|
|
|
|
#endif /* NDEBUG */
|
|
|
|
|
|
2013-05-05 21:23:20 +00:00
|
|
|
|
#if 0
|
2013-05-07 00:14:36 +00:00
|
|
|
|
/* Set global info */
|
|
|
|
|
KdComPortInUse = DefaultPort.Address;
|
2013-05-05 21:23:20 +00:00
|
|
|
|
#endif
|
2013-05-07 00:14:36 +00:00
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
2007-10-23 08:30:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BOOLEAN
|
2007-12-06 13:11:21 +00:00
|
|
|
|
NTAPI
|
|
|
|
|
KdPortGetByteEx(
|
2013-05-07 00:14:36 +00:00
|
|
|
|
IN PCPPORT PortInformation,
|
2007-12-06 13:11:21 +00:00
|
|
|
|
OUT PUCHAR ByteReceived)
|
2007-10-23 08:30:39 +00:00
|
|
|
|
{
|
2013-08-31 15:01:50 +00:00
|
|
|
|
return (CpGetByte(PortInformation, ByteReceived, FALSE, FALSE) == CP_GET_SUCCESS);
|
2007-10-23 08:30:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VOID
|
2007-12-06 13:11:21 +00:00
|
|
|
|
NTAPI
|
|
|
|
|
KdPortPutByteEx(
|
2013-05-07 00:14:36 +00:00
|
|
|
|
IN PCPPORT PortInformation,
|
2007-12-06 13:11:21 +00:00
|
|
|
|
IN UCHAR ByteToSend)
|
2007-10-23 08:30:39 +00:00
|
|
|
|
{
|
2013-05-07 00:14:36 +00:00
|
|
|
|
CpPutByte(PortInformation, ByteToSend);
|
2007-10-23 08:30:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* EOF */
|