That doesn't seem to make much sense. Why enumerate from the end? It
should rather enumerate from the start and skip the KdComPort. So far we
used COM1 as debug port on MSVC builds and COM2 as terminal debug port
for both freeldr and KDCOM. Preferably this should configurable. I
really don't like this unintuitive and quite random behaviour.
+#ifdef KDDEBUG
+ /*
+ * Try to find a free COM port and use it as the KD debugging port.
+ * NOTE: Inspired by reactos/boot/freeldr/freeldr/comm/rs232.c,
Rs232PortInitialize(...)
+ */
+ {
+ /*
+ * 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.
+ */
+ ULONG ComPort;
+ for (ComPort = MAX_COM_PORTS; ComPort > 0; ComPort--)
+ {
+ /* Check if the port exist; skip the KD port */
+ if ((ComPort != ComPortNumber) &&
CpDoesPortExist(UlongToPtr(BaseArray[ComPort])))
+ break;
+ }
+ if (ComPort != 0)
+ CpInitialize(&KdDebugComPort, UlongToPtr(BaseArray[ComPort]),
DEFAULT_BAUD_RATE);
+ }
+#endif
+
+ KDDBGPRINT("KdDebuggerInitialize0\n");