From: George Koehler Date: Wed, 23 Nov 2016 18:25:55 +0000 (-0500) Subject: Make working gettimeofday() for Mac OS X. X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=b6b707d9df40d8bdebce51281d610f264f03e0d9;p=ack.git Make working gettimeofday() for Mac OS X. The system call puts the time in a pair of registers, not in the timeval structure. Add code to move the time to the structure, so programs see the correct time, not garbage. This fixes our example programs that use the time as a random seed. --- diff --git a/plat/osx386/libsys/gettimeofday.s b/plat/osx386/libsys/gettimeofday.s index 3a4c2229f..43aff5fa9 100644 --- a/plat/osx386/libsys/gettimeofday.s +++ b/plat/osx386/libsys/gettimeofday.s @@ -1,7 +1,18 @@ +! The system call checks the timeval pointer but doesn't store the +! time there. If the pointer wasn't NULL, then the system call +! returns the time in a pair of registers. + .sect .text .define _gettimeofday _gettimeofday: mov eax, 116 int 0x80 jb .set_errno + mov ebx, 4(esp) ! timeval pointer + test ebx, ebx + je 1f + mov 0(ebx), eax ! seconds + mov 4(ebx), edx ! microseconds +1: + mov eax, 0 ! return 0 ret diff --git a/plat/osxppc/libsys/gettimeofday.s b/plat/osxppc/libsys/gettimeofday.s index c01bf5bae..178d17fdd 100644 --- a/plat/osxppc/libsys/gettimeofday.s +++ b/plat/osxppc/libsys/gettimeofday.s @@ -1,9 +1,19 @@ +! The system call checks the timeval pointer but doesn't store the +! time there. If the pointer wasn't NULL, then the system call +! returns the time in a pair of registers. + .sect .text .define _gettimeofday _gettimeofday: addi r0, r0, 116 ! gettimeofday lwz r3, 0(sp) ! timeval pointer lwz r4, 4(sp) ! timezone pointer + or. r5, r3, r3 sc 0 b .set_errno + bc 12, 2, 1f ! beq 1f + stw r3, 0(r5) ! seconds + stw r4, 4(r5) ! microseconds +1: + addi r3, r0, 0 ! return 0 bclr 20, 0, 0