[FREELDR] Minor code improvements
authorDmitry Borisov <di.sean@protonmail.com>
Thu, 5 Mar 2020 19:48:00 +0000 (01:48 +0600)
committerHermès BÉLUSCA - MAÏTO <hermes.belusca-maito@reactos.org>
Fri, 6 Mar 2020 23:52:40 +0000 (00:52 +0100)
- Add missing allocation check in DetectApmBios()
- Check 'PM' signature in FindApmBios()
- Properly set machine type in hardware detection
- Set Component->Key value for hard drives
- Get rid of the unused XboxBeep()
- Cast Xbox LPC I/O ports to PUCHAR
- Improve shadow rendering with VGA font
- Include ntoskrnl.h in the proper order

boot/freeldr/freeldr/arch/i386/hwapm.c
boot/freeldr/freeldr/arch/i386/ntoskrnl.c
boot/freeldr/freeldr/arch/i386/pc/machpc.c
boot/freeldr/freeldr/arch/i386/pc/pchw.c
boot/freeldr/freeldr/arch/i386/pc98/pc98video.c
boot/freeldr/freeldr/arch/i386/xbox/machxbox.c
boot/freeldr/freeldr/arch/i386/xbox/xboxfont.c
boot/freeldr/freeldr/arch/i386/xbox/xboxvideo.c
boot/freeldr/freeldr/include/arch/i386/machxbox.h
boot/freeldr/freeldr/include/ui/gui.h
boot/freeldr/freeldr/include/ui/tui.h

index 7339af9..313cf90 100644 (file)
@@ -1,21 +1,8 @@
 /*
- *  FreeLoader
- *
- *  Copyright (C) 2004  Eric Kohl
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License along
- *  with this program; if not, write to the Free Software Foundation, Inc.,
- *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ * PROJECT:     FreeLoader
+ * LICENSE:     GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
+ * PURPOSE:     APM BIOS detection routines
+ * COPYRIGHT:   Copyright 2004 Eric Kohl (eric.kohl@reactos.org)
  */
 
 #include <freeldr.h>
@@ -26,9 +13,9 @@ DBG_DEFAULT_CHANNEL(HWDETECT);
 static BOOLEAN
 FindApmBios(VOID)
 {
-    REGS  RegsIn;
-    REGS  RegsOut;
+    REGS RegsIn, RegsOut;
 
+    /* APM BIOS - Installation check */
 #if defined(SARCH_PC98)
     RegsIn.w.ax = 0x9A00;
     RegsIn.w.bx = 0x0000;
@@ -38,7 +25,7 @@ FindApmBios(VOID)
     RegsIn.w.bx = 0x0000;
     Int386(0x15, &RegsIn, &RegsOut);
 #endif
-    if (INT386_SUCCESS(RegsOut))
+    if (INT386_SUCCESS(RegsOut) && RegsOut.w.bx == 'PM')
     {
         TRACE("Found APM BIOS\n");
         TRACE("AH: %x\n", RegsOut.b.ah);
@@ -55,7 +42,6 @@ FindApmBios(VOID)
     return FALSE;
 }
 
-
 VOID
 DetectApmBios(PCONFIGURATION_COMPONENT_DATA SystemKey, ULONG *BusNumber)
 {
@@ -63,35 +49,40 @@ DetectApmBios(PCONFIGURATION_COMPONENT_DATA SystemKey, ULONG *BusNumber)
     PCM_PARTIAL_RESOURCE_LIST PartialResourceList;
     ULONG Size;
 
+    if (!FindApmBios())
+        return;
+
     Size = sizeof(CM_PARTIAL_RESOURCE_LIST) -
            sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR);
 
-    if (FindApmBios())
+    /* Set 'Configuration Data' value */
+    PartialResourceList = FrLdrHeapAlloc(Size, TAG_HW_RESOURCE_LIST);
+    if (PartialResourceList == NULL)
     {
-        /* Create 'Configuration Data' value */
-        PartialResourceList = FrLdrHeapAlloc(Size, TAG_HW_RESOURCE_LIST);
-        memset(PartialResourceList, 0, Size);
-        PartialResourceList->Version = 0;
-        PartialResourceList->Revision = 0;
-        PartialResourceList->Count = 0;
-
-        /* Create new bus key */
-        FldrCreateComponentKey(SystemKey,
-                               AdapterClass,
-                               MultiFunctionAdapter,
-                               0x0,
-                               0x0,
-                               0xFFFFFFFF,
-                               "APM",
-                               PartialResourceList,
-                               Size,
-                               &BiosKey);
-
-        /* Increment bus number */
-        (*BusNumber)++;
+        ERR("Failed to allocate resource descriptor\n");
+        return;
     }
+    RtlZeroMemory(PartialResourceList, Size);
+    PartialResourceList->Version = 0;
+    PartialResourceList->Revision = 0;
+    PartialResourceList->Count = 0;
 
     /* FIXME: Add configuration data */
+
+    /* Create new bus key */
+    FldrCreateComponentKey(SystemKey,
+                           AdapterClass,
+                           MultiFunctionAdapter,
+                           0x0,
+                           0,
+                           0xFFFFFFFF,
+                           "APM",
+                           PartialResourceList,
+                           Size,
+                           &BiosKey);
+
+    /* Increment bus number */
+    (*BusNumber)++;
 }
 
 /* EOF */
index 33ce99b..4a846f0 100644 (file)
@@ -8,8 +8,8 @@
 
 /* INCLUDES ******************************************************************/
 
-#include <ntoskrnl.h>
 #include <freeldr.h>
+#include <ntoskrnl.h>
 
 /* FUNCTIONS *****************************************************************/
 
index d5b629f..8aea5d9 100644 (file)
@@ -1373,7 +1373,8 @@ PcHwDetect(VOID)
 
     /* Create the 'System' key */
     FldrCreateSystemKey(&SystemKey);
-    // TODO: Discover and set the machine type as the Component->Identifier
+    // TODO: Discover and set the other machine types
+    FldrSetIdentifier(SystemKey, "AT/AT COMPATIBLE");
 
     GetHarddiskConfigurationData = PcGetHarddiskConfigurationData;
     FindPciBios = PcFindPciBios;
index 67074c0..bed2a11 100644 (file)
@@ -426,7 +426,7 @@ DetectBiosDisks(PCONFIGURATION_COMPONENT_DATA SystemKey,
                                PeripheralClass,
                                DiskPeripheral,
                                Output | Input,
-                               0x0,
+                               i,
                                0xFFFFFFFF,
                                Identifier,
                                PartialResourceList,
index cb21eaa..a920382 100644 (file)
@@ -10,7 +10,7 @@
 #include <freeldr.h>
 #include <drivers/pc98/video.h>
 
-extern UCHAR XboxFont8x16[];
+extern UCHAR BitmapFont8x16[];
 extern BOOLEAN HiResoMachine;
 
 /* GLOBALS ********************************************************************/
@@ -241,7 +241,7 @@ Pc98VideoPutChar(int Ch, UCHAR Attr, unsigned X, unsigned Y)
     UCHAR R = (Attr & 0x40) ? 0xFF : 0;
     UCHAR I = (Attr & 0x80) ? 0xFF : 0;
     ULONG VramOffset = X + (Y * CHAR_HEIGHT) * BYTES_PER_SCANLINE;
-    PUCHAR FontPtr = XboxFont8x16 + Ch * 16;
+    PUCHAR FontPtr = BitmapFont8x16 + Ch * 16;
 
     for (Line = 0; Line < CHAR_HEIGHT; Line++)
     {
index 4d84089..438e887 100644 (file)
@@ -50,29 +50,29 @@ XboxGetSerialPort(ULONG Index, PULONG Irq)
     ULONG ComBase = 0;
 
     // Enter Configuration
-    WRITE_PORT_UCHAR(LPC_IO_BASE, LPC_ENTER_CONFIG_KEY);
+    WRITE_PORT_UCHAR((PUCHAR)LPC_IO_BASE, LPC_ENTER_CONFIG_KEY);
 
     // Select serial device
-    WRITE_PORT_UCHAR(LPC_IO_BASE, LPC_CONFIG_DEVICE_NUMBER);
-    WRITE_PORT_UCHAR(LPC_IO_BASE + 1, Device[Index]);
+    WRITE_PORT_UCHAR((PUCHAR)LPC_IO_BASE, LPC_CONFIG_DEVICE_NUMBER);
+    WRITE_PORT_UCHAR((PUCHAR)(LPC_IO_BASE + 1), Device[Index]);
 
     // Check if selected device is active
-    WRITE_PORT_UCHAR(LPC_IO_BASE, LPC_CONFIG_DEVICE_ACTIVATE);
-    if (READ_PORT_UCHAR(LPC_IO_BASE + 1) == 1)
+    WRITE_PORT_UCHAR((PUCHAR)LPC_IO_BASE, LPC_CONFIG_DEVICE_ACTIVATE);
+    if (READ_PORT_UCHAR((PUCHAR)(LPC_IO_BASE + 1)) == 1)
     {
         // Read LSB
-        WRITE_PORT_UCHAR(LPC_IO_BASE, LPC_CONFIG_DEVICE_BASE_ADDRESS_LOW);
-        ComBase = READ_PORT_UCHAR(LPC_IO_BASE + 1);
+        WRITE_PORT_UCHAR((PUCHAR)LPC_IO_BASE, LPC_CONFIG_DEVICE_BASE_ADDRESS_LOW);
+        ComBase = READ_PORT_UCHAR((PUCHAR)(LPC_IO_BASE + 1));
         // Read MSB
-        WRITE_PORT_UCHAR(LPC_IO_BASE, LPC_CONFIG_DEVICE_BASE_ADDRESS_HIGH);
-        ComBase |= (READ_PORT_UCHAR(LPC_IO_BASE + 1) << 8);
+        WRITE_PORT_UCHAR((PUCHAR)LPC_IO_BASE, LPC_CONFIG_DEVICE_BASE_ADDRESS_HIGH);
+        ComBase |= (READ_PORT_UCHAR((PUCHAR)(LPC_IO_BASE + 1)) << 8);
         // Read IRQ
-        WRITE_PORT_UCHAR(LPC_IO_BASE, LPC_CONFIG_DEVICE_INTERRUPT);
-        *Irq = READ_PORT_UCHAR(LPC_IO_BASE + 1);
+        WRITE_PORT_UCHAR((PUCHAR)LPC_IO_BASE, LPC_CONFIG_DEVICE_INTERRUPT);
+        *Irq = READ_PORT_UCHAR((PUCHAR)(LPC_IO_BASE + 1));
     }
 
     // Exit Configuration
-    WRITE_PORT_UCHAR(LPC_IO_BASE, LPC_EXIT_CONFIG_KEY);
+    WRITE_PORT_UCHAR((PUCHAR)LPC_IO_BASE, LPC_EXIT_CONFIG_KEY);
 
     return ComBase;
 }
index 0e67d1f..0a731d3 100644 (file)
@@ -1,28 +1,17 @@
 /*
- *  FreeLoader
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License along
- *  with this program; if not, write to the Free Software Foundation, Inc.,
- *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Note: Converted from the XFree vga.bdf font
+ * PROJECT:     FreeLoader
+ * LICENSE:     GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
+ * PURPOSE:     VGA font 8x16
+ * COPYRIGHT:   Copyright 2004 Gé van Geldorp (gvg@reactos.org)
  */
 
+/* Note: Converted from the XFree vga.bdf font */
+
 #include <freeldr.h>
 
-UCHAR XboxFont8x16[256 * 16] =
+UCHAR BitmapFont8x16[256 * 16] =
 {
-  0x00,0x00,0x00,0x7c,0xc6,0xc6,0xde,0xde,0xde,0xdc,0xc0,0x7c,0x00,0x00,0x00,0x00, /* 0x00 */
+  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 0x00 */
   0x00,0x00,0x7e,0x81,0xa5,0x81,0x81,0xa5,0x99,0x81,0x81,0x7e,0x00,0x00,0x00,0x00, /* 0x01 */
   0x00,0x00,0x7e,0xff,0xdb,0xff,0xff,0xdb,0xe7,0xff,0xff,0x7e,0x00,0x00,0x00,0x00, /* 0x02 */
   0x00,0x00,0x00,0x00,0x6c,0xfe,0xfe,0xfe,0xfe,0x7c,0x38,0x10,0x00,0x00,0x00,0x00, /* 0x03 */
@@ -281,4 +270,3 @@ UCHAR XboxFont8x16[256 * 16] =
 };
 
 /* EOF */
-
index b1fd251..b0e38a3 100644 (file)
@@ -50,7 +50,7 @@ XboxVideoOutputChar(UCHAR Char, unsigned X, unsigned Y, ULONG FgColor, ULONG BgC
   unsigned Line;
   unsigned Col;
 
-  FontPtr = XboxFont8x16 + Char * 16;
+  FontPtr = BitmapFont8x16 + Char * 16;
   Pixel = (PULONG) ((char *) FrameBuffer + (Y * CHAR_HEIGHT + TOP_BOTTOM_LINES) * Delta
                   + X * CHAR_WIDTH * BytesPerPixel);
   for (Line = 0; Line < CHAR_HEIGHT; Line++)
@@ -290,13 +290,6 @@ XboxVideoSync(VOID)
   /* Not supported */
 }
 
-VOID
-XboxBeep(VOID)
-{
-    /* Call PC version */
-    PcBeep();
-}
-
 VOID
 XboxVideoPrepareForReactOS(VOID)
 {
index 062d74f..6a95fe6 100644 (file)
@@ -46,7 +46,7 @@
 #define     NV2A_RAMDAC_FP_HVALID_END      (0x838 + NV2A_RAMDAC_OFFSET)
 #define     NV2A_RAMDAC_FP_VVALID_END      (0x818 + NV2A_RAMDAC_OFFSET)
 
-extern UCHAR XboxFont8x16[256 * 16];
+extern UCHAR BitmapFont8x16[256 * 16];
 
 VOID XboxConsPutChar(int Ch);
 BOOLEAN XboxConsKbHit(VOID);
index 516394b..a2ce937 100644 (file)
@@ -19,7 +19,6 @@
 
 #pragma once
 
-#define    TUI_SCREEN_MEM                0xB8000
 #define TITLE_BOX_CHAR_HEIGHT        5
 
 ///////////////////////////////////////////////////////////////////////////////////////
index 6daf7c3..8959276 100644 (file)
@@ -19,7 +19,6 @@
 
 #pragma once
 
-#define    TUI_SCREEN_MEM                0xB8000
 #define TUI_TITLE_BOX_CHAR_HEIGHT    5
 
 ///////////////////////////////////////////////////////////////////////////////////////