[HEADERS]
[reactos.git] / reactos / drivers / base / kdcom / i386 / kdbg.c
index a2e9c7f..c8fad2f 100644 (file)
@@ -5,35 +5,27 @@
  * PURPOSE:         Serial i/o functions for the kernel debugger.
  * PROGRAMMER:      Alex Ionescu
  *                  HervĂ© Poussineau
- *                  Timo Kreuzer
  */
 
 /* INCLUDES *****************************************************************/
 
 #define NOEXTAPI
 #include <ntddk.h>
+#include <ntifs.h>
 #define NDEBUG
 #include <halfuncs.h>
 #include <stdio.h>
-#include <stdlib.h>
 #include <debug.h>
 #include "arc/arc.h"
 #include "windbgkd.h"
 #include <kddll.h>
 #include <ioaccess.h> /* port intrinsics */
 
-typedef enum _KD_RECV_CODE
-{
-       KD_RECV_CODE_OK       = 0,
-       KD_RECV_CODE_TIMEOUT  = 1,
-       KD_RECV_CODE_FAILED   = 2
-} KD_RECV_CODE, * PKD_RECV_CODE;
-
 typedef struct _KD_PORT_INFORMATION
 {
     ULONG ComPort;
     ULONG BaudRate;
-    ULONG_PTR BaseAddress;
+    ULONG BaseAddress;
 } KD_PORT_INFORMATION, *PKD_PORT_INFORMATION;
 
 BOOLEAN
@@ -61,12 +53,6 @@ KdPortPutByteEx(
     IN PKD_PORT_INFORMATION PortInformation,
     IN UCHAR ByteToSend);
 
-/* serial debug connection */
-#define DEFAULT_DEBUG_PORT      2 /* COM2 */
-#define DEFAULT_DEBUG_COM1_IRQ  4 /* COM1 IRQ */
-#define DEFAULT_DEBUG_COM2_IRQ  3 /* COM2 IRQ */
-#define DEFAULT_DEBUG_BAUD_RATE 115200 /* 115200 Baud */
-
 #define DEFAULT_BAUD_RATE    19200
 
 #ifdef _M_IX86
@@ -77,8 +63,6 @@ const ULONG BaseArray[2] = {0, 0x800003f8};
 const ULONG BaseArray[3] = {0, 0x80006000, 0x80007000};
 #elif defined(_M_ARM)
 const ULONG BaseArray[2] = {0, 0xF1012000};
-#elif defined(_M_AMD64)
-const ULONG BaseArray[5] = {0, 0x3F8, 0x2F8, 0x3E8, 0x2E8};
 #else
 #error Unknown architecture
 #endif
@@ -138,18 +122,12 @@ static KD_PORT_INFORMATION DefaultPort = { 0, 0, 0 };
 /* The com port must only be initialized once! */
 static BOOLEAN PortInitialized = FALSE;
 
-ULONG KdpPort;
-ULONG KdpPortIrq;
-
-// HACK!!!
-typedef ULONG (*DBGRNT)(const char *Format, ...);
-DBGRNT FrLdrDbgPrint = 0;
 
 /* STATIC FUNCTIONS *********************************************************/
 
 static BOOLEAN
 KdpDoesComPortExist(
-    IN ULONG_PTR BaseAddress)
+    IN ULONG BaseAddress)
 {
     BOOLEAN found;
     UCHAR mcr;
@@ -209,14 +187,6 @@ KdpDoesComPortExist(
 
 /* FUNCTIONS ****************************************************************/
 
-NTSTATUS
-DriverEntry(
-    IN PDRIVER_OBJECT  DriverObject,
-    IN PUNICODE_STRING  RegistryPath)
-{
-    return STATUS_SUCCESS;
-}
-
 /* HAL.KdPortInitialize */
 BOOLEAN
 NTAPI
@@ -262,7 +232,7 @@ KdPortInitialize(
         return FALSE;
 
     /* set global info */
-    *KdComPortInUse = (PUCHAR)DefaultPort.BaseAddress;
+    KdComPortInUse = (PUCHAR)DefaultPort.BaseAddress;
 
     return TRUE;
 }
@@ -276,7 +246,7 @@ KdPortInitializeEx(
     IN ULONG Unknown1,
     IN ULONG Unknown2)
 {
-    ULONG_PTR ComPortBase;
+    ULONG ComPortBase;
     CHAR buffer[80];
     ULONG divisor;
     UCHAR lcr;
@@ -497,217 +467,25 @@ KdPortEnableInterrupts(VOID)
     return TRUE;
 }
 
-/* NEW INTERNAL FUNCTIONS ****************************************************/
-
-/******************************************************************************
- * \name KdpCalculateChecksum
- * \brief Calculates the checksum for the packet data.
- * \param Buffer Pointer to the packet data.
- * \param Length Length of data in bytes.
- * \return The calculated checksum.
- * \sa http://www.vista-xp.co.uk/forums/technical-reference-library/2540-basics-debugging.html
- */
-ULONG
-NTAPI
-KdpCalculateChecksum(
-    IN PVOID Buffer,
-    IN ULONG Length)
-{
-    ULONG i, Checksum = 0;
-
-    for (i = 0; i < Length; i++)
-    {
-        Checksum += ((PUCHAR)Buffer)[i];
-    }
-    return Checksum;
-}
-
-/******************************************************************************
- * \name KdpSendBuffer
- * \brief Sends a buffer of data to the KD port.
- * \param Buffer Pointer to the data.
- * \param Size Size of data in bytes.
- */
-VOID
-NTAPI
-KdpSendBuffer(
-    IN PVOID Buffer,
-    IN ULONG Size)
-{
-    INT i;
-    for (i = 0; i < Size; i++)
-    {
-        KdPortPutByteEx(&DefaultPort, ((PUCHAR)Buffer)[i]);
-    }
-}
-
-/******************************************************************************
- * \name KdpReceiveBuffer
- * \brief Recieves data from the KD port and fills a buffer.
- * \param Buffer Pointer to a buffer that receives the data.
- * \param Size Size of data to receive in bytes.
- * \return KD_RECV_CODE_OK if successful. 
- *         KD_RECV_CODE_TIMEOUT if the receice timed out (10 seconds).
- * \todo Handle timeout.
- */
-KDSTATUS
-NTAPI
-KdpReceiveBuffer(
-    OUT PVOID Buffer,
-    IN  ULONG Size)
-{
-    ULONG i;
-    PUCHAR ByteBuffer = Buffer;
-    BOOLEAN Ret, TimeOut;
-
-    for (i = 0; i < Size; i++)
-    {
-        do
-        {
-            Ret = KdPortGetByteEx(&DefaultPort, &ByteBuffer[i]);
-            TimeOut = FALSE; // FIXME timeout after 10 Sec
-        }
-        while (!Ret | TimeOut);
-
-        if (TimeOut)
-        {
-            return KD_RECV_CODE_TIMEOUT;
-        }
-        FrLdrDbgPrint("Received byte: %x\n", ByteBuffer[i]);
-    }
-
-    return KD_RECV_CODE_OK;
-}
-
-/* NEW PUBLIC FUNCTIONS ******************************************************/
-
-/******************************************************************************
- * \name KdDebuggerInitialize0
- * \brief Phase 0 initialization.
- * \param [opt] LoaderBlock Pointer to the Loader parameter block. Can be NULL.
- * \return Status
+/*
+ * @unimplemented
  */
 NTSTATUS
 NTAPI
 KdDebuggerInitialize0(
     IN PLOADER_PARAMETER_BLOCK LoaderBlock OPTIONAL)
 {
-    ULONG Value;
-    PCHAR CommandLine, Port, BaudRate, Irq;
-
-    /* Apply default values */
-    KdpPortIrq = 0;
-    DefaultPort.ComPort = DEFAULT_DEBUG_PORT;
-    DefaultPort.BaudRate = DEFAULT_DEBUG_BAUD_RATE;
-
-    /* Check if e have a LoaderBlock */
-    if (LoaderBlock)
-    {
-        /* Get the Command Line */
-        CommandLine = LoaderBlock->LoadOptions;
-
-        /* Upcase it */
-        _strupr(CommandLine);
-
-        /* Get the port and baud rate */
-        Port = strstr(CommandLine, "DEBUGPORT");
-        BaudRate = strstr(CommandLine, "BAUDRATE");
-        Irq = strstr(CommandLine, "IRQ");
-
-        /* Check if we got the /DEBUGPORT parameter */
-        if (Port)
-        {
-            /* Move past the actual string, to reach the port*/
-            Port += strlen("DEBUGPORT");
-
-            /* Now get past any spaces and skip the equal sign */
-            while (*Port == ' ') Port++;
-            Port++;
-
-            /* Do we have a serial port? */
-            if (strncmp(Port, "COM", 3) != 0)
-            {
-                return STATUS_INVALID_PARAMETER;
-            }
-
-            /* Gheck for a valid Serial Port */
-            Port += 3;
-            Value = atol(Port);
-            if (Value > 4)
-            {
-                return STATUS_INVALID_PARAMETER;
-            }
-
-            /* Set the port to use */
-            DefaultPort.ComPort = Value;
-       }
-
-        /* Check if we got a baud rate */
-        if (BaudRate)
-        {
-            /* Move past the actual string, to reach the rate */
-            BaudRate += strlen("BAUDRATE");
-
-            /* Now get past any spaces */
-            while (*BaudRate == ' ') BaudRate++;
-
-            /* And make sure we have a rate */
-            if (*BaudRate)
-            {
-                /* Read and set it */
-                Value = atol(BaudRate + 1);
-                if (Value) DefaultPort.BaudRate = Value;
-            }
-        }
-
-        /* Check Serial Port Settings [IRQ] */
-        if (Irq)
-        {
-            /* Move past the actual string, to reach the rate */
-            Irq += strlen("IRQ");
-
-            /* Now get past any spaces */
-            while (*Irq == ' ') Irq++;
-
-            /* And make sure we have an IRQ */
-            if (*Irq)
-            {
-                /* Read and set it */
-                Value = atol(Irq + 1);
-                if (Value) KdpPortIrq = Value;
-            }
-        }
-    }
-
-    /* Get base address */
-    DefaultPort.BaseAddress = BaseArray[DefaultPort.ComPort];
-
-    /* Check if the COM port does exist */
-    if (!KdpDoesComPortExist(DefaultPort.BaseAddress))
-    {
-        return STATUS_INVALID_PARAMETER;
-    }
-
-    /* Initialize the port */
-    KdPortInitializeEx(&DefaultPort, 0, 0);
-
-    return STATUS_SUCCESS;
+    return STATUS_NOT_IMPLEMENTED;
 }
 
-/******************************************************************************
- * \name KdDebuggerInitialize0
- * \brief Phase 0 initialization.
- * \param [opt] LoaderBlock Pointer to the Loader parameter block. Can be NULL.
- * \return Status
+/*
+ * @unimplemented
  */
 NTSTATUS
 NTAPI
 KdDebuggerInitialize1(
     IN PLOADER_PARAMETER_BLOCK LoaderBlock OPTIONAL)
 {
-    // HACK: misuse this function to get a pointer to FrLdrDbgPrint
-    FrLdrDbgPrint = (PVOID)LoaderBlock;
-    UNIMPLEMENTED;
     return STATUS_NOT_IMPLEMENTED;
 }
 
@@ -746,31 +524,7 @@ KdSendPacket(
     IN PSTRING MessageData,
     IN OUT PKD_CONTEXT Context)
 {
-    ULONG i;
-
-    switch (PacketType)
-    {
-        case PACKET_TYPE_KD_DEBUG_IO:
-            /* Copy Message to COM port */
-            for (i = 0; i < MessageData->Length; i++)
-            {
-                char c = MessageData->Buffer[i];
-                if ( c == 10 )
-                {
-                    KdPortPutByteEx(&DefaultPort, 13);
-                    KdPortPutByteEx(&DefaultPort, 10);
-                }
-                else
-                {
-                    KdPortPutByteEx(&DefaultPort, c);
-                }
-            }
-            break;
-
-        default:
-            break;
-    }
-
+    UNIMPLEMENTED;
     return;
 }
 
@@ -786,7 +540,7 @@ KdReceivePacket(
     OUT PULONG DataLength,
     IN OUT PKD_CONTEXT Context)
 {
-//    UNIMPLEMENTED;
+    UNIMPLEMENTED;
     return 0;
 }