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
 ENDSTRUC
32
 ENDSTRUC
33
 
33
 
34
 
34
 
35
-%macro TIMESPEC 1
35
+%macro TIMESPEC 3
36
 	%1: ISTRUC TIMESPEC_STRUC
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
 	IEND
39
 	IEND
40
 	%define %1.tv_sec %1+TIMESPEC_STRUC.tv_sec
40
 	%define %1.tv_sec %1+TIMESPEC_STRUC.tv_sec
41
 	%define %1.tv_nsec %1+TIMESPEC_STRUC.tv_nsec
41
 	%define %1.tv_nsec %1+TIMESPEC_STRUC.tv_nsec
61
 	%define sigaction.sa_restorer sigaction+SIGACTION_STRUC.sa_restorer
61
 	%define sigaction.sa_restorer sigaction+SIGACTION_STRUC.sa_restorer
62
 	%define sigaction.sa_mask sigaction+SIGACTION_STRUC.sa_mask
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
 	faultmsg: db "Fault !", 0xA
69
 	faultmsg: db "Fault !", 0xA
101
 	timestr: db ":00:00.0           ", 0x0a
93
 	timestr: db ":00:00.0           ", 0x0a
102
 	timestrlen: equ $ - timestr
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
 	nl: db 0x0A
98
 	nl: db 0x0A
107
 	buf: db 0
99
 	buf: db 0
168
 mov rdx, startmsglen
160
 mov rdx, startmsglen
169
 syscall
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
 main_loop:
178
 main_loop:
172
 	push 2 ; stderr
179
 	push 2 ; stderr
173
 	push 0x0D ; \r
180
 	push 0x0D ; \r
454
 
461
 
455
 ;
462
 ;
456
 ;	Argument parsing
463
 ;	Argument parsing
464
+;		TODO : support -r2
457
 ;
465
 ;
458
 arg_parse:
466
 arg_parse:
459
 	; Checking argument count
467
 	; Checking argument count

Loading…
Cancel
Save