From 3d1c4216ede8c628558c9fe700fb2be1aa08b473 Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Mon, 2 Nov 2020 21:24:53 -0800 Subject: 7162 --- html/402time.mu.html | 72 +++++++++++++++++++++++++++------------------------- 1 file changed, 38 insertions(+), 34 deletions(-) (limited to 'html/402time.mu.html') diff --git a/html/402time.mu.html b/html/402time.mu.html index 1d5eb787..912366b2 100644 --- a/html/402time.mu.html +++ b/html/402time.mu.html @@ -61,40 +61,44 @@ if ('onhashchange' in window) { 3 tv_nsec: int 4 } 5 - 6 # TODO: y2038 - 7 fn time -> secs/eax: int { - 8 var t: timespec - 9 var clock/ebx: int <- copy 0 # CLOCK_MONOTONIC -10 var t-addr/ecx: (addr timespec) <- address t -11 syscall_clock_gettime -12 var t-secs-addr/ecx: (addr int) <- get t-addr, tv_sec -13 secs <- copy *t-secs-addr -14 } -15 -16 fn ntime -> nsecs/eax: int { -17 var t: timespec -18 var clock/ebx: int <- copy 0 # CLOCK_MONOTONIC -19 var t-addr/ecx: (addr timespec) <- address t -20 syscall_clock_gettime -21 var t-nsecs-addr/ecx: (addr int) <- get t-addr, tv_nsec -22 nsecs <- copy *t-nsecs-addr -23 } -24 -25 # nsecs must be less than 999999999 or 0x3b9ac9ff nanoseconds -26 fn sleep secs: int, nsecs: int { -27 var t: timespec -28 # initialize t -29 var tmp/eax: (addr int) <- get t, tv_sec -30 var tmp2/ecx: int <- copy secs -31 copy-to *tmp, tmp2 -32 tmp <- get t, tv_nsec -33 tmp2 <- copy nsecs -34 copy-to *tmp, tmp2 -35 # perform the syscall -36 var t-addr/ebx: (addr timespec) <- address t -37 var rem-addr/ecx: (addr timespec) <- copy 0 -38 syscall_nanosleep -39 } + 6 # return time in seconds since epoch + 7 # TODO: y2038 + 8 fn time -> _/eax: int { + 9 var t: timespec +10 var clock/ebx: int <- copy 0 # CLOCK_MONOTONIC +11 var t-addr/ecx: (addr timespec) <- address t +12 syscall_clock_gettime +13 var t-secs-addr/ecx: (addr int) <- get t-addr, tv_sec +14 var secs/eax: int <- copy *t-secs-addr +15 return secs +16 } +17 +18 # return time in nanoseconds since epoch +19 fn ntime -> _/eax: int { +20 var t: timespec +21 var clock/ebx: int <- copy 0 # CLOCK_MONOTONIC +22 var t-addr/ecx: (addr timespec) <- address t +23 syscall_clock_gettime +24 var t-nsecs-addr/ecx: (addr int) <- get t-addr, tv_nsec +25 var nsecs/eax: int <- copy *t-nsecs-addr +26 return nsecs +27 } +28 +29 # nsecs must be less than 999999999 or 0x3b9ac9ff nanoseconds +30 fn sleep secs: int, nsecs: int { +31 var t: timespec +32 # initialize t +33 var tmp/eax: (addr int) <- get t, tv_sec +34 var tmp2/ecx: int <- copy secs +35 copy-to *tmp, tmp2 +36 tmp <- get t, tv_nsec +37 tmp2 <- copy nsecs +38 copy-to *tmp, tmp2 +39 # perform the syscall +40 var t-addr/ebx: (addr timespec) <- address t +41 var rem-addr/ecx: (addr timespec) <- copy 0 +42 syscall_nanosleep +43 } -- cgit 1.4.1-2-gfad0