Browse Source

Now the sleep time depends on the time_res value

Yann Weber 5 years ago
parent
commit
faaf5d2791
1 changed files with 23 additions and 15 deletions
  1. 23
    15
      wtfstopw.asm

+ 23
- 15
wtfstopw.asm View File

@@ -32,10 +32,10 @@ STRUC TIMESPEC_STRUC
32 32
 ENDSTRUC
33 33
 
34 34
 
35
-%macro TIMESPEC 1
35
+%macro TIMESPEC 3
36 36
 	%1: ISTRUC TIMESPEC_STRUC
37
-		at TIMESPEC_STRUC.tv_sec, dq 0
38
-		at TIMESPEC_STRUC.tv_nsec, dq 0
37
+		at TIMESPEC_STRUC.tv_sec, dq %2
38
+		at TIMESPEC_STRUC.tv_nsec, dq %3
39 39
 	IEND
40 40
 	%define %1.tv_sec %1+TIMESPEC_STRUC.tv_sec
41 41
 	%define %1.tv_nsec %1+TIMESPEC_STRUC.tv_nsec
@@ -61,17 +61,9 @@ section .data
61 61
 	%define sigaction.sa_restorer sigaction+SIGACTION_STRUC.sa_restorer
62 62
 	%define sigaction.sa_mask sigaction+SIGACTION_STRUC.sa_mask
63 63
 
64
-	TIMESPEC ts_start
65
-	TIMESPEC ts_cur
66
-
67
-	ts_sleep:
68
-		tv_sleep_s dq 0
69
-		tv_sleep_us dq 10000000 ; set for 4 digits bellow seconds
70
-
71
-	;; 1/2s sleep
72
-	;ts_sleep:
73
-	;	tv_sleep_s dq 0
74
-	;	tv_sleep_us dq 500000000
64
+	TIMESPEC ts_start, 0, 0
65
+	TIMESPEC ts_cur, 0, 0
66
+	TIMESPEC ts_sleep, 0, 100000000 ; set before mainloop
75 67
 
76 68
 
77 69
 	faultmsg: db "Fault !", 0xA
@@ -101,7 +93,7 @@ section .data
101 93
 	timestr: db ":00:00.0           ", 0x0a
102 94
 	timestrlen: equ $ - timestr
103 95
 
104
-	time_res: dq 4 ; 4 digits bellow seconds
96
+	time_res: dq 2 ; 2 digits bellow seconds can grow to 8
105 97
 
106 98
 	nl: db 0x0A
107 99
 	buf: db 0
@@ -168,6 +160,21 @@ mov rsi, startmsg
168 160
 mov rdx, startmsglen
169 161
 syscall
170 162
 
163
+; set value for ts_sleep.tv_nsec given time_res
164
+; div sleep time by 10 for each digits added bellow seconds
165
+mov rax, 100000000
166
+mov r8, [time_res]
167
+mov r9, 10
168
+xor rdx, rdx
169
+setsleep_loop:
170
+	cmp r8, 1
171
+	jle setsleep_endloop
172
+	div r9
173
+	sub r8, 1
174
+	jmp setsleep_loop
175
+setsleep_endloop:
176
+mov [ts_sleep.tv_nsec], rax
177
+
171 178
 main_loop:
172 179
 	push 2 ; stderr
173 180
 	push 0x0D ; \r
@@ -454,6 +461,7 @@ sig_restorer:
454 461
 
455 462
 ;
456 463
 ;	Argument parsing
464
+;		TODO : support -r2
457 465
 ;
458 466
 arg_parse:
459 467
 	; Checking argument count

Loading…
Cancel
Save