This patch should clean up the While loop code.. it makes the code closer 
to IF/ELSE loop.  It sets the code pointer to the beginning of the while
loop.  Doesn't really fix anything, more code cleanup.

Please test this code and report any issues.

Index: amltypes.h
===================================================================
RCS file: /cvs/src/sys/dev/acpi/amltypes.h,v
retrieving revision 1.32
diff -u -p -u -p -r1.32 amltypes.h
--- amltypes.h  30 May 2009 22:49:56 -0000      1.32
+++ amltypes.h  16 Jul 2009 19:23:34 -0000
@@ -213,7 +213,6 @@ enum aml_objecttype {
 #define AML_ARG_TERMOBJ                't'

 #define AML_ARG_IFELSE          'I'
-#define AML_ARG_WHILE           'W'
 #define AML_ARG_BUFFER          'B'
 #define AML_ARG_SEARCHNAME      'n'
 #define AML_ARG_CREATENAME      'N'
Index: dsdt.c
===================================================================
RCS file: /cvs/src/sys/dev/acpi/dsdt.c,v
retrieving revision 1.150
diff -u -p -u -p -r1.150 dsdt.c
--- dsdt.c      1 Jun 2009 22:36:12 -0000       1.150
+++ dsdt.c      16 Jul 2009 19:17:50 -0000
@@ -159,7 +159,7 @@ struct aml_opcode aml_table[] = {
        /* Control flow */
        { AMLOP_IF,             "If",           "piI",  },
        { AMLOP_ELSE,           "Else",         "pT" },
-       { AMLOP_WHILE,          "While",        "pW",   },
+       { AMLOP_WHILE,          "While",        "piT",  },
        { AMLOP_BREAK,          "Break",        "" },
        { AMLOP_CONTINUE,       "Continue",     "" },
        { AMLOP_RETURN,         "Return",       "t",    },
@@ -1800,8 +1800,11 @@ aml_xfindscope(struct aml_scope *scope,
                        break;
                case AMLOP_BREAK:
                        scope->pos = scope->end;
-                       if (scope->type == type)
+                       if (scope->type == type) {
+                               /* Set parent position (currently at WHILE) */
+                               scope->parent->pos = scope->end;
                                scope->pos = NULL;
+                       }
                        break;
                }
                if (scope->type == type)
@@ -3129,6 +3132,7 @@ aml_xeval(struct aml_scope *scope, struc
 #endif

                /* Evaluate method scope */
+               aml_root.start = tmp->v_method.base;
                if (tmp->v_method.fneval != NULL) {
                        my_ret = tmp->v_method.fneval(ms, NULL);
                }
@@ -3369,6 +3373,7 @@ aml_xparse(struct aml_scope *scope, int
        struct aml_opcode *htab;
        struct aml_value *opargs[8], *my_ret, *rv;
        struct aml_scope *mscope, *iscope;
+       uint8_t *start, *end;
        const char *ch;
        int64_t ival;

@@ -3385,6 +3390,7 @@ aml_xparse(struct aml_scope *scope, int
        iscope = scope;
  start:
        /* --== Stage 0: Get Opcode ==-- */
+       start = scope->pos;
        pc = aml_pc(scope->pos);
        aml_debugger(scope);

@@ -3400,8 +3406,6 @@ aml_xparse(struct aml_scope *scope, int
        memset(opargs, 0, sizeof(opargs));
        idx = 0;
        for (ch = htab->args; *ch; ch++) {
-               uint8_t *end;
-
                rv = NULL;
                switch (*ch) {
                case AML_ARG_OBJLEN:
@@ -3432,7 +3436,6 @@ aml_xparse(struct aml_scope *scope, int
                        break;

                        /* Simple arguments */
-               case AML_ARG_WHILE:
                case AML_ARG_BUFFER:
                case AML_ARG_METHOD:
                case AML_ARG_FIELDLIST:
@@ -4044,26 +4047,15 @@ aml_xparse(struct aml_scope *scope, int
                }
                break;
        case AMLOP_WHILE:
-               mscope = aml_xpushscope(scope, opargs[0], scope->node,
-                   AMLOP_WHILE);
-               while (mscope->pos != NULL) {
-                       /* At beginning of scope.. reset and perform test */
-                       mscope->pos = mscope->start;
-                       rv = aml_xparse(mscope, AML_ARG_INTEGER, "While-Test");
-                       ival = rv->v_integer;
-                       aml_xdelref(&rv, "while");
-
-                       dnprintf(10,"@@@@@@ WHILE: %llx @ %x\n", ival, pc);
-                       if (ival == 0) {
-                               break;
-                       }
-                       aml_xparse(mscope, 'T', "While");
+               if (opargs[0]->v_integer) {
+                       /* Reset parent position to start of WHILE opcode */
+                       scope->pos = start;
+                       mscope = aml_xpushscope(scope, opargs[1], scope->node,
+                           AMLOP_WHILE);
                }
-               aml_xpopscope(mscope);
-               mscope = NULL;
                break;
        case AMLOP_BREAK:
-               /* Break: Find While Scope parent, mark type as null */
+               /* Break: Find While Scope parent, set pointer to end of WHILE 
*/
                aml_xfindscope(scope, AMLOP_WHILE, AMLOP_BREAK);
                break;
        case AMLOP_CONTINUE:

Reply via email to