From 3350c34a74844e21ea69077e01efff3bae64bdcd Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Tue, 23 Mar 2021 17:31:08 -0700 Subject: . --- html/linux/402time.mu.html | 105 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 html/linux/402time.mu.html (limited to 'html/linux/402time.mu.html') diff --git a/html/linux/402time.mu.html b/html/linux/402time.mu.html new file mode 100644 index 00000000..afea34e8 --- /dev/null +++ b/html/linux/402time.mu.html @@ -0,0 +1,105 @@ + + + + +Mu - linux/402time.mu + + + + + + + + + + +https://github.com/akkartik/mu/blob/main/linux/402time.mu +
+ 1 type timespec {
+ 2   tv_sec: int
+ 3   tv_nsec: int
+ 4 }
+ 5 
+ 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