[OpenBIOS] [PATCH v2] implement convert_to_ints()

Programmingkid programmingkidx at gmail.com
Fri Sep 30 02:08:36 CEST 2016


convert_to_ints() converts all the string resolutions in the resolutions
property of the QEMU,VGA node and converts them to an int array. Needed
to support the VGA driver.

Signed-off-by: John Arbuckle <programmingkidx at gmail.com>
---
v2 changes:
Added function resolutions_property_available() - used to determine if there
is a resolutions property.
Removed convert_to_ints() prototype.

 arch/ppc/qemu/init.c | 109 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 108 insertions(+), 1 deletion(-)

diff --git a/arch/ppc/qemu/init.c b/arch/ppc/qemu/init.c
index 6f21814..b950a61 100644
--- a/arch/ppc/qemu/init.c
+++ b/arch/ppc/qemu/init.c
@@ -619,6 +619,106 @@ id_cpu(void)
     }
 }
 
+
+/* convert ASCII string to number */
+static int atoi(const char *str)
+{
+    int result = 0;
+    while (*str) {
+        result = result * 10 + *str - '0';
+        str++;
+    }
+    return result;
+}
+
+
+/* Converts the QEMU,VGA node's resolutions property to int's*/
+static void convert_to_ints(void)
+{
+    const int max_buffer_size = 200;
+    char *orig_property;
+    char buffer[max_buffer_size];
+    int index, count, value, addr, len;
+    char c;
+    
+    count = 0;
+    index = 0;
+    push_str("/pci/QEMU,VGA");
+    fword("find-package");
+    if (POP() == 0) {
+        fword("cr");
+        push_str("convert-to-ints(): could not find package /pci/QEMU,VGA!");
+        fword("type");
+        fword("cr");
+        return;
+    }        
+    fword("active-package!");
+    push_str("resolutions");
+    fword("active-package");
+    fword("get-package-property");
+    if (POP() == -1) {
+        fword("cr");
+        push_str("convert-to-ints(): could not find resolutions property!");
+        fword("type");
+        fword("cr");
+        return;
+    }
+    len = POP();
+    addr = POP();
+    orig_property = (char *) malloc(len);
+    strncpy(orig_property, (char *)addr, len);
+    c = orig_property[0];
+    while(c != '\0') {
+        if (c == 'x' || c == ',') {
+            buffer[index] = '\0';
+            value = atoi(buffer);
+            count++;
+            if (count == 3) {
+                count = 1;
+                fword("encode+");
+                continue;
+            }
+            PUSH(value);
+            fword("encode-int");
+            index = -1;
+        }
+        else {
+            buffer[index] = c;
+        }
+        index++;
+        c = *(++orig_property);
+    }
+    fword("encode+");
+    push_str("resolutions");
+    fword("property");
+    free(orig_property);
+}
+
+
+/* Determines if there is a resolutions property in the options node*/
+static bool resolutions_property_available(void)
+{
+    push_str("/options");
+    fword("find-package");
+    if (POP() != -1) {
+        return false;
+    }
+    fword("active-package!");
+    push_str("resolutions");
+    fword("active-package");
+    fword("get-package-property");
+    if (POP() == -1) {
+        return false;
+    }
+
+    /* Remove str-addr and str-len */
+    POP();
+    POP();
+
+    return true;
+}
+
+
 static void go(void);
 unsigned int start_elf(unsigned long entry_point, unsigned long param);
 
@@ -631,7 +731,13 @@ go(void)
     if (find_dev("/rom/macos")) {
         fword("insert-copyright-property");
     }
-    
+
+    /* Used to support user specified resolutions */
+    if (resolutions_property_available()) {
+        fword("copy-resolutions-property");
+        convert_to_ints();
+    }
+
     feval("saved-program-state >sps.entry @");
     addr = POP();
 
@@ -1078,3 +1184,4 @@ arch_of_init(void)
     bind_func("platform-boot", boot);
     bind_func("(go)", go);
 }
+
-- 
2.7.2





More information about the OpenBIOS mailing list