]> git.saurik.com Git - apple/xnu.git/blobdiff - osfmk/ppc/commpage/gettimeofday.s
xnu-1228.3.13.tar.gz
[apple/xnu.git] / osfmk / ppc / commpage / gettimeofday.s
index 6d17fd9ecd48088ae439cbf952298a2a9ee379ef..e9645ee3722beb9c38f84e151e00994fa53e5771 100644 (file)
@@ -1,34 +1,36 @@
 /*
 /*
- * Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2003-2005 Apple Computer, Inc. All rights reserved.
  *
  *
- * @APPLE_LICENSE_HEADER_START@
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
  * 
  * 
- * The contents of this file constitute Original Code as defined in and
- * are subject to the Apple Public Source License Version 1.1 (the
- * "License").  You may not use this file except in compliance with the
- * License.  Please obtain a copy of the License at
- * http://www.apple.com/publicsource and read it before using this file.
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. The rights granted to you under the License
+ * may not be used to create, or enable the creation or redistribution of,
+ * unlawful or unlicensed copies of an Apple operating system, or to
+ * circumvent, violate, or enable the circumvention or violation of, any
+ * terms of an Apple operating system software license agreement.
  * 
  * 
- * This Original Code and all software distributed under the License are
- * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this file.
+ * 
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
- * License for the specific language governing rights and limitations
- * under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
  * 
  * 
- * @APPLE_LICENSE_HEADER_END@
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
  */
 
  */
 
-#define        ASSEMBLER
 #include <sys/appleapiopts.h>
 #include <ppc/asm.h>                                   // EXT, LEXT
 #include <machine/cpu_capabilities.h>
 #include <machine/commpage.h>
 
 #include <sys/appleapiopts.h>
 #include <ppc/asm.h>                                   // EXT, LEXT
 #include <machine/cpu_capabilities.h>
 #include <machine/commpage.h>
 
-#define        USEC_PER_SEC    1000000
-
-
 /* The red zone is used to move data between GPRs and FPRs: */
 
 #define        rzTicks                 -8                      // elapsed ticks since timestamp (double)
 /* The red zone is used to move data between GPRs and FPRs: */
 
 #define        rzTicks                 -8                      // elapsed ticks since timestamp (double)
@@ -48,7 +50,7 @@
 // in user mode, usually without having to make a system call.  We do not deal with
 // the timezone.  The kernel maintains the following values in the comm page:
 //
 // in user mode, usually without having to make a system call.  We do not deal with
 // the timezone.  The kernel maintains the following values in the comm page:
 //
-//     _COMM_PAGE_TIMESTAMP = a BSD-style pair of uint_32's for seconds and microseconds
+//     _COMM_PAGE_TIMESTAMP = 64 bit seconds timestamp
 //
 //     _COMM_PAGE_TIMEBASE = the timebase at which the timestamp was valid
 //
 //
 //     _COMM_PAGE_TIMEBASE = the timebase at which the timestamp was valid
 //
@@ -69,8 +71,7 @@ gettimeofday_32:                                                              // int gettimeofday(timeval *tp);
 0:
         lwz            r5,_COMM_PAGE_TIMEBASE+0(0)             // r5,r6 = TBR at timestamp
         lwz            r6,_COMM_PAGE_TIMEBASE+4(0)
 0:
         lwz            r5,_COMM_PAGE_TIMEBASE+0(0)             // r5,r6 = TBR at timestamp
         lwz            r6,_COMM_PAGE_TIMEBASE+4(0)
-        lwz            r7,_COMM_PAGE_TIMESTAMP+0(0)    // r7 = timestamp seconds
-        lwz            r8,_COMM_PAGE_TIMESTAMP+4(0)    // r8 = timestamp microseconds
+        lwz            r8,_COMM_PAGE_TIMESTAMP+4(0)    // r8 = timestamp 32 bit seconds
         lfd            f1,_COMM_PAGE_SEC_PER_TICK(0)
 1:        
         mftbu  r10                                                             // r10,r11 = current timebase
         lfd            f1,_COMM_PAGE_SEC_PER_TICK(0)
 1:        
         mftbu  r10                                                             // r10,r11 = current timebase
@@ -84,31 +85,28 @@ gettimeofday_32:                                                            // int gettimeofday(timeval *tp);
         
         lwz            r0,_COMM_PAGE_TIMEBASE+0(0)             // then load data a 2nd time
         lwz            r12,_COMM_PAGE_TIMEBASE+4(0)
         
         lwz            r0,_COMM_PAGE_TIMEBASE+0(0)             // then load data a 2nd time
         lwz            r12,_COMM_PAGE_TIMEBASE+4(0)
-        lwz            r2,_COMM_PAGE_TIMESTAMP+0(0)
         lwz            r9,_COMM_PAGE_TIMESTAMP+4(0)
         cmplw  cr6,r5,r0                       // did we read a consistent set?
         cmplw  cr7,r6,r12
         beq-   3f                                      // timestamp is disabled so return bad status
         lwz            r9,_COMM_PAGE_TIMESTAMP+4(0)
         cmplw  cr6,r5,r0                       // did we read a consistent set?
         cmplw  cr7,r6,r12
         beq-   3f                                      // timestamp is disabled so return bad status
-        cmplw  cr1,r2,r7
         cmplw  cr5,r9,r8
         crand  cr0_eq,cr6_eq,cr7_eq
         cmplw  cr5,r9,r8
         crand  cr0_eq,cr6_eq,cr7_eq
-        crand  cr1_eq,cr1_eq,cr5_eq
-        crand  cr0_eq,cr0_eq,cr1_eq
+        crand  cr0_eq,cr0_eq,cr5_eq
         bne-   0b                                      // loop until we have a consistent set of data
         
         subfc  r11,r6,r11                      // compute ticks since timestamp
         lwz            r9,_COMM_PAGE_2_TO_52(0)        // get exponent for (2**52)
         subfe  r10,r5,r10                      // complete 64-bit subtract
         bne-   0b                                      // loop until we have a consistent set of data
         
         subfc  r11,r6,r11                      // compute ticks since timestamp
         lwz            r9,_COMM_PAGE_2_TO_52(0)        // get exponent for (2**52)
         subfe  r10,r5,r10                      // complete 64-bit subtract
-        lfd            f2,_COMM_PAGE_2_TO_52(0)        // f3 <- (2**52)
+        lfd            f2,_COMM_PAGE_2_TO_52(0)        // f2 <- (2**52)
         srwi.  r0,r10,2                        // if more than 2**34 ticks have elapsed...
         stw            r11,rzTicks+4(r1)       // store elapsed ticks into red zone
         or             r10,r10,r9                      // convert long-long in (r10,r11) into double
         bne-   3f                                      // ...call kernel to reprime timestamp
 
         stw            r10,rzTicks(r1)         // complete double
         srwi.  r0,r10,2                        // if more than 2**34 ticks have elapsed...
         stw            r11,rzTicks+4(r1)       // store elapsed ticks into red zone
         or             r10,r10,r9                      // convert long-long in (r10,r11) into double
         bne-   3f                                      // ...call kernel to reprime timestamp
 
         stw            r10,rzTicks(r1)         // complete double
-        lis            r12,hi16(USEC_PER_SEC)
-        ori            r12,r12,lo16(USEC_PER_SEC)
-        
+
+               mffs    f7
+               mtfsfi  7,1        
         lfd            f3,rzTicks(r1)          // get elapsed ticks since timestamp + 2**52
         fsub   f4,f3,f2                        // subtract 2**52 and normalize
         fmul   f5,f4,f1                        // f5 <- elapsed seconds since timestamp
         lfd            f3,rzTicks(r1)          // get elapsed ticks since timestamp + 2**52
         fsub   f4,f3,f2                        // subtract 2**52 and normalize
         fmul   f5,f4,f1                        // f5 <- elapsed seconds since timestamp
@@ -122,19 +120,14 @@ gettimeofday_32:                                                          // int gettimeofday(timeval *tp);
         fmul   f6,f6,f3                        // f6 <- fractional elapsed useconds
         fctiwz f6,f6                           // convert useconds to integer
         stfd   f6,rzUSeconds(r1)       // store useconds into red zone
         fmul   f6,f6,f3                        // f6 <- fractional elapsed useconds
         fctiwz f6,f6                           // convert useconds to integer
         stfd   f6,rzUSeconds(r1)       // store useconds into red zone
+               mtfsf   0xff,f7
         
         lwz            r5,rzSeconds+4(r1)      // r5 <- seconds since timestamp
         
         lwz            r5,rzSeconds+4(r1)      // r5 <- seconds since timestamp
-        lwz            r6,rzUSeconds+4(r1)     // r6 <- useconds since timestamp
-        add            r7,r7,r5                        // add elapsed seconds to timestamp seconds
-        add            r8,r8,r6                        // ditto useconds
+        lwz            r7,rzUSeconds+4(r1)     // r7 <- useconds since timestamp
+        add            r6,r8,r5                        // add elapsed seconds to timestamp seconds
         
         
-        cmplw  r8,r12                          // r8 >= USEC_PER_SEC ?
-        blt            2f                                      // no
-        addi   r7,r7,1                         // add 1 to secs
-        sub            r8,r8,r12                       // subtract USEC_PER_SEC from usecs
-2:
-        stw            r7,0(r3)                        // store secs//usecs into user's timeval
-        stw            r8,4(r3)
+        stw            r6,0(r3)                        // store secs//usecs into user's timeval
+        stw            r7,4(r3)
         li             r3,0                            // return success
         blr
 3:                                                                     // too long since last timestamp or this code is disabled
         li             r3,0                            // return success
         blr
 3:                                                                     // too long since last timestamp or this code is disabled
@@ -149,12 +142,12 @@ gettimeofday_32:                                                          // int gettimeofday(timeval *tp);
 // ***************************************
 //
 // This routine is called in 32-bit mode on 64-bit processors.  A timeval is a struct of
 // ***************************************
 //
 // This routine is called in 32-bit mode on 64-bit processors.  A timeval is a struct of
-// a long seconds and int useconds, so it's size depends on mode.
+// a long seconds and int useconds, so its size depends on mode.
 
 gettimeofday_g5_32:                                                    // int gettimeofday(timeval *tp);
 0:
         ld             r6,_COMM_PAGE_TIMEBASE(0)       // r6 = TBR at timestamp
 
 gettimeofday_g5_32:                                                    // int gettimeofday(timeval *tp);
 0:
         ld             r6,_COMM_PAGE_TIMEBASE(0)       // r6 = TBR at timestamp
-        ld             r8,_COMM_PAGE_TIMESTAMP(0)      // r8 = timestamp (seconds,useconds)
+        ld             r8,_COMM_PAGE_TIMESTAMP(0)      // r8 = timestamp (seconds)
         lfd            f1,_COMM_PAGE_SEC_PER_TICK(0)
         mftb   r10                                                     // r10 = get current timebase
         lwsync                                                         // create a barrier if MP (patched to NOP if UP)
         lfd            f1,_COMM_PAGE_SEC_PER_TICK(0)
         mftb   r10                                                     // r10 = get current timebase
         lwsync                                                         // create a barrier if MP (patched to NOP if UP)
@@ -172,6 +165,8 @@ gettimeofday_g5_32:                                                 // int gettimeofday(timeval *tp);
         std            r11,rzTicks(r1)         // put ticks in redzone where we can "lfd" it
         bne--  3f                                      // timestamp too old, so reprime
 
         std            r11,rzTicks(r1)         // put ticks in redzone where we can "lfd" it
         bne--  3f                                      // timestamp too old, so reprime
 
+               mffs    f7
+               mtfsfi  7,1
         lfd            f3,rzTicks(r1)          // get elapsed ticks since timestamp (fixed pt)
         fcfid  f4,f3                           // float the tick count
         fmul   f5,f4,f1                        // f5 <- elapsed seconds since timestamp
         lfd            f3,rzTicks(r1)          // get elapsed ticks since timestamp (fixed pt)
         fcfid  f4,f3                           // float the tick count
         fmul   f5,f4,f1                        // f5 <- elapsed seconds since timestamp
@@ -183,22 +178,14 @@ gettimeofday_g5_32:                                                       // int gettimeofday(timeval *tp);
         fmul   f6,f6,f3                        // f6 <- fractional elapsed useconds
         fctidz f6,f6                           // convert useconds to fixed pt integer
         stfd   f6,rzUSeconds(r1)       // store useconds into red zone
         fmul   f6,f6,f3                        // f6 <- fractional elapsed useconds
         fctidz f6,f6                           // convert useconds to fixed pt integer
         stfd   f6,rzUSeconds(r1)       // store useconds into red zone
+               mtfsf   0xff,f7
         
         
-        lis            r12,hi16(USEC_PER_SEC)  // r12 <- 10**6
-        srdi   r7,r8,32                        // extract seconds from doubleword timestamp
         lwz            r5,rzSeconds+4(r1)      // r5 <- seconds since timestamp
         lwz            r5,rzSeconds+4(r1)      // r5 <- seconds since timestamp
-        ori            r12,r12,lo16(USEC_PER_SEC)
-        lwz            r6,rzUSeconds+4(r1)     // r6 <- useconds since timestamp
-        add            r7,r7,r5                        // add elapsed seconds to timestamp seconds
-        add            r8,r8,r6                        // ditto useconds
+        lwz            r7,rzUSeconds+4(r1)     // r7 <- useconds since timestamp
+        add            r6,r8,r5                        // add elapsed seconds to timestamp seconds
         
         
-        cmplw  r8,r12                          // r8 >= USEC_PER_SEC ?
-        blt            2f                                      // no
-        addi   r7,r7,1                         // add 1 to secs
-        sub            r8,r8,r12                       // subtract USEC_PER_SEC from usecs
-2:
-        stw            r7,0(r3)                        // store secs//usecs into user's timeval
-        stw            r8,4(r3)
+        stw            r6,0(r3)                        // store secs//usecs into user's timeval
+        stw            r7,4(r3)
         li             r3,0                            // return success
         blr
 3:                                                                     // too long since last timestamp or this code is disabled
         li             r3,0                            // return success
         blr
 3:                                                                     // too long since last timestamp or this code is disabled
@@ -213,12 +200,12 @@ gettimeofday_g5_32:                                                       // int gettimeofday(timeval *tp);
 // ***************************************
 //
 // This routine is called in 64-bit mode on 64-bit processors.  A timeval is a struct of
 // ***************************************
 //
 // This routine is called in 64-bit mode on 64-bit processors.  A timeval is a struct of
-// a long seconds and int useconds, so it's size depends on mode.
+// a long seconds and int useconds, so its size depends on mode.
 
 gettimeofday_g5_64:                                                    // int gettimeofday(timeval *tp);
 0:
         ld             r6,_COMM_PAGE_TIMEBASE(0)       // r6 = TBR at timestamp
 
 gettimeofday_g5_64:                                                    // int gettimeofday(timeval *tp);
 0:
         ld             r6,_COMM_PAGE_TIMEBASE(0)       // r6 = TBR at timestamp
-        ld             r8,_COMM_PAGE_TIMESTAMP(0)      // r8 = timestamp (seconds,useconds)
+        ld             r8,_COMM_PAGE_TIMESTAMP(0)      // r8 = timestamp (seconds)
         lfd            f1,_COMM_PAGE_SEC_PER_TICK(0)
         mftb   r10                                                     // r10 = get current timebase
         lwsync                                                         // create a barrier if MP (patched to NOP if UP)
         lfd            f1,_COMM_PAGE_SEC_PER_TICK(0)
         mftb   r10                                                     // r10 = get current timebase
         lwsync                                                         // create a barrier if MP (patched to NOP if UP)
@@ -236,6 +223,8 @@ gettimeofday_g5_64:                                                 // int gettimeofday(timeval *tp);
         std            r11,rzTicks(r1)         // put ticks in redzone where we can "lfd" it
         bne--  3f                                      // timestamp too old, so reprime
 
         std            r11,rzTicks(r1)         // put ticks in redzone where we can "lfd" it
         bne--  3f                                      // timestamp too old, so reprime
 
+               mffs    f7
+               mtfsfi  7,1
         lfd            f3,rzTicks(r1)          // get elapsed ticks since timestamp (fixed pt)
         fcfid  f4,f3                           // float the tick count
         fmul   f5,f4,f1                        // f5 <- elapsed seconds since timestamp
         lfd            f3,rzTicks(r1)          // get elapsed ticks since timestamp (fixed pt)
         fcfid  f4,f3                           // float the tick count
         fmul   f5,f4,f1                        // f5 <- elapsed seconds since timestamp
@@ -247,22 +236,14 @@ gettimeofday_g5_64:                                                       // int gettimeofday(timeval *tp);
         fmul   f6,f6,f3                        // f6 <- fractional elapsed useconds
         fctidz f6,f6                           // convert useconds to fixed pt integer
         stfd   f6,rzUSeconds(r1)       // store useconds into red zone
         fmul   f6,f6,f3                        // f6 <- fractional elapsed useconds
         fctidz f6,f6                           // convert useconds to fixed pt integer
         stfd   f6,rzUSeconds(r1)       // store useconds into red zone
+               mtfsf   0xff,f7
         
         
-        lis            r12,hi16(USEC_PER_SEC)  // r12 <- 10**6
-        srdi   r7,r8,32                        // extract seconds from doubleword timestamp
         lwz            r5,rzSeconds+4(r1)      // r5 <- seconds since timestamp
         lwz            r5,rzSeconds+4(r1)      // r5 <- seconds since timestamp
-        ori            r12,r12,lo16(USEC_PER_SEC)
-        lwz            r6,rzUSeconds+4(r1)     // r6 <- useconds since timestamp
-        add            r7,r7,r5                        // add elapsed seconds to timestamp seconds
-        add            r8,r8,r6                        // ditto useconds
+        lwz            r7,rzUSeconds+4(r1)     // r7 <- useconds since timestamp
+        add            r6,r8,r5                        // add elapsed seconds to timestamp seconds
         
         
-        cmplw  r8,r12                          // r8 >= USEC_PER_SEC ?
-        blt            2f                                      // no
-        addi   r7,r7,1                         // add 1 to secs
-        sub            r8,r8,r12                       // subtract USEC_PER_SEC from usecs
-2:
-        std            r7,0(r3)                        // store secs//usecs into user's timeval
-        stw            r8,8(r3)
+        std            r6,0(r3)                        // store secs//usecs into user's timeval
+        stw            r7,8(r3)
         li             r3,0                            // return success
         blr
 3:                                                                     // too long since last timestamp or this code is disabled
         li             r3,0                            // return success
         blr
 3:                                                                     // too long since last timestamp or this code is disabled