If we copy the code from the manual, we might as well copy the comments.
Okay?

Index: arch/amd64/amd64/locore.S
===================================================================
RCS file: /cvs/src/sys/arch/amd64/amd64/locore.S,v
retrieving revision 1.52
diff -u -p -r1.52 locore.S
--- arch/amd64/amd64/locore.S   6 May 2012 04:20:40 -0000       1.52
+++ arch/amd64/amd64/locore.S   18 Sep 2012 21:09:12 -0000
@@ -1060,29 +1060,42 @@ ENTRY(pagezero)
 
 #if NACPI > 0
 ENTRY(acpi_acquire_global_lock)
-       movq    %rdi, %rcx
-1:     movl    (%rcx), %eax
+       movq    %rdi, %rcx      /* ecx = Address of Global Lock in FACS */
+1:     movl    (%rcx), %eax    /* Get current value of Global Lock */
+
        movl    %eax, %edx
-       andl    $~1, %edx
-       btsl    $1, %edx
-       adcl    $0, %edx
+       andl    $~1, %edx       /* Clear pending bit */
+       btsl    $1, %edx        /* Check and set owner bit */
+       adcl    $0, %edx        /* If owned set pending bit */
+
        lock
-       cmpxchgl       %edx, (%rcx)
-       jnz     1b
-       andl    $3, %edx
+       cmpxchgl %edx, (%rcx)   /* Attempt to set new value */
+       jnz     1b              /* If not set, try again */
+
+       andl    $3, %edx        /* Was it acquired or marked pending? */
        cmpl    $3, %edx
-       sbb     %eax, %eax
+       sbb     %eax, %eax      /* acquired = -1, pending = 0 */
+
        ret
 
 ENTRY(acpi_release_global_lock)
-       movq    %rdi, %rcx
-1:     movl    (%rcx), %eax
+       movq    %rdi, %rcx      /* ecx = Address of Global Lock in FACS */
+1:     movl    (%rcx), %eax    /* Get current value of Global Lock */
+
        movl    %eax, %edx
-       andl    $~3, %edx
+       andl    $~3, %edx       /* Clear owner and pending field */
+
        lock
-       cmpxchgl        %edx, (%rcx)
-       jnz     1b
-       andl    $1, %eax
+       cmpxchgl %edx, (%rcx)   /* Attempt to set it */
+       jnz     1b              /* If not set, try again */
+
+       andl    $1, %eax        /* Was pending set? */
+
+       /*
+        * If one is returned (we were pending) the caller must signal that the
+        * lock has been released using either GBL_RLS or BIOS_RLS as 
+        * appropriate.
+        */
        ret
 #endif
 
Index: arch/i386/i386/locore.s
===================================================================
RCS file: /cvs/src/sys/arch/i386/i386/locore.s,v
retrieving revision 1.141
diff -u -p -r1.141 locore.s
--- arch/i386/i386/locore.s     2 Nov 2011 23:53:44 -0000       1.141
+++ arch/i386/i386/locore.s     18 Sep 2012 21:09:13 -0000
@@ -1653,29 +1653,42 @@ ENTRY(i686_pagezero)
 
 #if NACPI > 0
 ENTRY(acpi_acquire_global_lock)
-       movl    4(%esp), %ecx
-1:     movl    (%ecx), %eax
+       movl    4(%esp), %ecx   /* ecx = Address of Global Lock in FACS */
+1:     movl    (%ecx), %eax    /* Get current value of Global Lock */
+
        movl    %eax, %edx
-       andl    $~1, %edx
-       btsl    $1, %edx
-       adcl    $0, %edx
+       andl    $~1, %edx       /* Clear pending bit */
+       btsl    $1, %edx        /* Check and set owner bit */
+       adcl    $0, %edx        /* If owned set pending bit */
+
        lock
-       cmpxchgl        %edx, (%ecx)
-       jnz     1b
-       andl    $3, %edx
+       cmpxchgl %edx, (%ecx)   /* Attempt to set new value */
+       jnz     1b              /* If not set, try again */
+
+       andl    $3, %edx        /* Was it acquired or marked pending? */
        cmpl    $3, %edx
-       sbb     %eax, %eax
+       sbb     %eax, %eax      /* acquired = -1, pending = 0 */
+
        ret
 
 ENTRY(acpi_release_global_lock)
-       movl    4(%esp), %ecx
-1:     movl    (%ecx), %eax
+       movl    4(%esp), %ecx   /* ecx = Address of Global Lock in FACS */
+1:     movl    (%ecx), %eax    /* Get current value of Global Lock */
+
        movl    %eax, %edx
-       andl    $~3, %edx
+       andl    $~3, %edx       /* Clear owner and pending field */
+
        lock
-       cmpxchgl        %edx, (%ecx)
-       jnz     1b
-       andl    $1, %eax
+       cmpxchgl %edx, (%ecx)   /* Attempt to set it */
+       jnz     1b              /* If not set, try again */
+
+       andl    $1, %eax        /* Was pending set? */
+
+       /*
+        * If one is returned (we were pending) the caller must signal that the
+        * lock has been released using either GBL_RLS or BIOS_RLS as 
+        * appropriate.
+        */
        ret
 #endif

Reply via email to