Ver Fonte

I did a quick review of the MS x86_64 calling convention for floating
point and as far as I can tell it agrees with the UEFI spec.
The attached patch removes -mno-mmx and -mno-sse for x86_64 and adds
a new Print target, "%f", to print float and double types.

It seems to compile for ia32, although I'm not sure why - shouldn't
it be throwing errors because the new function FloatToStr() in print.c
accepts a float, yet I left -no-sse for ARCH=ia32? A better solution
might be to add -msoft-float for targets where the floating point
calling convention doesn't match the UEFI spec. As I'm not familiar
with UEFI on ia32, I didn't make any changes to it.

Signed-off-by: Nathan Blythe <nblythe@lgsinnovations.com>
Signed-off-by: Nigel Croxon <nigel.croxon@hpe.com>

Nigel Croxon há 8 anos atrás
pai
commit
b2c4db065f
3 ficheiros alterados com 52 adições e 1 exclusões
  1. 1 1
      Make.defaults
  2. 7 0
      inc/efilib.h
  3. 44 0
      lib/print.c

+ 1 - 1
Make.defaults

@@ -111,7 +111,7 @@ ifeq ($(ARCH),x86_64)
     CPPFLAGS += -DGNU_EFI_USE_MS_ABI -maccumulate-outgoing-args --std=c11
   endif
 
-  CFLAGS += -mno-red-zone -mno-mmx -mno-sse
+  CFLAGS += -mno-red-zone
   ifeq ($(HOSTARCH),ia32)
     ARCH3264 = -m64
   endif

+ 7 - 0
inc/efilib.h

@@ -499,6 +499,13 @@ ValueToString (
     IN INT64    v
     );
 
+VOID
+FloatToString (
+    IN CHAR16   *Buffer,
+    IN BOOLEAN  Comma,
+    IN double    v
+    );
+
 VOID
 TimeToString (
     OUT CHAR16      *Buffer,

+ 44 - 0
lib/print.c

@@ -1000,6 +1000,7 @@ Routine Description:
     x       -   hex value
     d       -   value as signed decimal
     u       -   value as unsigned decimal
+    f       -   value as floating point
     c       -   Unicode char
     t       -   EFI time structure
     g       -   Pointer to GUID
@@ -1163,6 +1164,15 @@ Returns:
                     );
                 break;
 
+            case 'f':
+                Item.Item.pw = Item.Scratch;
+                FloatToString (
+                    Item.Item.pw,
+                    Item.Comma,
+                    va_arg(ps->args, double)
+                    );
+                break;
+
             case 't':
                 Item.Item.pw = Item.Scratch;
                 TimeToString (Item.Item.pw, va_arg(ps->args, EFI_TIME *));
@@ -1307,6 +1317,40 @@ ValueToString (
     *p2 = 0;
 }
 
+VOID
+FloatToString (
+    IN CHAR16   *Buffer,
+    IN BOOLEAN  Comma,
+    IN double   v
+    )
+{
+    /*
+     * Integer part.
+     */
+    INTN i = (INTN)v;
+    ValueToString(Buffer, Comma, i);
+
+
+    /*
+     * Decimal point.
+     */
+    UINTN x = StrLen(Buffer);
+    Buffer[x] = L'.';
+
+
+    /*
+     * Fractional part.
+     */
+    float f = v - (float)i;
+    if (f < 0) f = -f;
+    while ((float)(INTN)f != f)
+    {
+      f *= 10;
+    }
+    ValueToString(Buffer + x + 1, FALSE, (INTN)f);
+    return;
+}
+
 VOID
 TimeToString (
     OUT CHAR16      *Buffer,