|
@@ -0,0 +1,134 @@
|
|
1
|
+[bits 64]
|
|
2
|
+
|
|
3
|
+section .text
|
|
4
|
+global _start
|
|
5
|
+
|
|
6
|
+_start:
|
|
7
|
+
|
|
8
|
+; set stdin non blocking
|
|
9
|
+mov rax, 72 ; fcntl
|
|
10
|
+mov rdi, 0 ; stdin
|
|
11
|
+mov rsi, 3 ; F_GETFL
|
|
12
|
+mov rdx, 0
|
|
13
|
+syscall
|
|
14
|
+mov rdx, rax
|
|
15
|
+or rdx, 4 ; O_NONBLOCK
|
|
16
|
+mov rax, 72 ; fcntl
|
|
17
|
+mov rdi, 0 ; stdin
|
|
18
|
+mov rsi, 4 ; F_SETFL
|
|
19
|
+syscall
|
|
20
|
+
|
|
21
|
+mov rax, 228 ; clock_gettime
|
|
22
|
+mov rdi, 0 ; CLOCK_REALTIME
|
|
23
|
+mov rsi, ts_start
|
|
24
|
+syscall
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+print_time:
|
|
28
|
+
|
|
29
|
+mov rax, 228 ; clock_gettime
|
|
30
|
+mov rdi, 0 ; CLOCK_REALTIME
|
|
31
|
+mov rsi, ts_cur
|
|
32
|
+syscall
|
|
33
|
+
|
|
34
|
+mov rax, [tv_cur_s]
|
|
35
|
+mov rbx, [tv_start_s]
|
|
36
|
+sub rax, rbx
|
|
37
|
+fifoo:
|
|
38
|
+add al, 0x30
|
|
39
|
+mov byte [msg], al
|
|
40
|
+;xor rax, rax
|
|
41
|
+;mov al, byte [msg]
|
|
42
|
+;mov rdi, [tv_cur_s]
|
|
43
|
+;mov rdx, [tv_start_s]
|
|
44
|
+;sub rdi, rdx
|
|
45
|
+;fifoo:
|
|
46
|
+;add rax, rdi
|
|
47
|
+;mov byte [msg], al
|
|
48
|
+
|
|
49
|
+mov rax, 1
|
|
50
|
+mov rdi, 1
|
|
51
|
+mov rsi, msg
|
|
52
|
+mov rdx, msglen
|
|
53
|
+syscall
|
|
54
|
+
|
|
55
|
+sleep:
|
|
56
|
+mov rax, 35
|
|
57
|
+mov rdi, ts_sleep
|
|
58
|
+mov rsi, 0
|
|
59
|
+syscall
|
|
60
|
+jmp print_time
|
|
61
|
+
|
|
62
|
+mov rax, 60 ; sys_exit
|
|
63
|
+mov rdi, 0 ; 0
|
|
64
|
+syscall
|
|
65
|
+
|
|
66
|
+dumprax:
|
|
67
|
+ push rax
|
|
68
|
+ loopdump:
|
|
69
|
+ push rax
|
|
70
|
+ mov rbx, rax
|
|
71
|
+ and rbx, 0x0F
|
|
72
|
+ cmp bl, 0xA
|
|
73
|
+ jge hexdigit
|
|
74
|
+ add bl, 0x30
|
|
75
|
+ jmp loopcont
|
|
76
|
+ hexdigit:
|
|
77
|
+ sub bl, 10
|
|
78
|
+ add bl, 0x41
|
|
79
|
+ loopcont:
|
|
80
|
+dbg:
|
|
81
|
+ mov byte [digit], bl
|
|
82
|
+ mov rax, 1
|
|
83
|
+ mov rdi, 1
|
|
84
|
+ mov rsi, digit
|
|
85
|
+ mov rdx, 1
|
|
86
|
+ syscall
|
|
87
|
+ pop rax
|
|
88
|
+ mov rdi, 10
|
|
89
|
+ xor rdx, rdx
|
|
90
|
+ mov rsi, rax
|
|
91
|
+ div rdi
|
|
92
|
+ cmp rax, 10
|
|
93
|
+ jge loopdump
|
|
94
|
+
|
|
95
|
+ mov al, 10
|
|
96
|
+ mov al, [digit]
|
|
97
|
+ mov rax, 1
|
|
98
|
+ mov rdi, 1
|
|
99
|
+ mov rsi, nl
|
|
100
|
+ mov rdx, 1
|
|
101
|
+ syscall
|
|
102
|
+
|
|
103
|
+ pop rax
|
|
104
|
+ret
|
|
105
|
+
|
|
106
|
+section .data
|
|
107
|
+foobar: ISTRUC timespec
|
|
108
|
+ts_start:
|
|
109
|
+ tv_start_s dq 0
|
|
110
|
+ tv_start_us dq 0
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+msg: db "0 Hello, world!", 10
|
|
114
|
+msglen: equ $ - msg
|
|
115
|
+
|
|
116
|
+digit: db "0"
|
|
117
|
+nl: db 10
|
|
118
|
+
|
|
119
|
+ts_cur:
|
|
120
|
+ tv_cur_s dq 0
|
|
121
|
+ tv_cur_us dq 0
|
|
122
|
+
|
|
123
|
+;ts_sleep:
|
|
124
|
+; tv_sleep_s dd 0,0
|
|
125
|
+; tv_sleep_us dd 10000000,0
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+; 1/2s sleep
|
|
129
|
+ts_sleep:
|
|
130
|
+ tv_sleep_s dq 0
|
|
131
|
+ tv_sleep_us dq 500000000
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+.end:
|