-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscreen.s
324 lines (324 loc) · 5.52 KB
/
screen.s
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
.file "screen.c"
.text
.globl set_cursor
.type set_cursor, @function
set_cursor:
.LFB0:
.cfi_startproc
endbr64
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
subq $16, %rsp
movl %edi, -4(%rbp)
movl -4(%rbp), %eax
movl %eax, %edx
shrl $31, %edx
addl %edx, %eax
sarl %eax
movl %eax, -4(%rbp)
movl $14, %esi
movl $980, %edi
call port_byte_out@PLT
movl -4(%rbp), %eax
sarl $8, %eax
movzbl %al, %eax
movl %eax, %esi
movl $981, %edi
call port_byte_out@PLT
movl $15, %esi
movl $980, %edi
call port_byte_out@PLT
movl -4(%rbp), %eax
movzbl %al, %eax
movl %eax, %esi
movl $981, %edi
call port_byte_out@PLT
nop
leave
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE0:
.size set_cursor, .-set_cursor
.globl get_cursor
.type get_cursor, @function
get_cursor:
.LFB1:
.cfi_startproc
endbr64
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
subq $16, %rsp
movl $14, %esi
movl $980, %edi
call port_byte_out@PLT
movl $981, %edi
call port_byte_in@PLT
movzbl %al, %eax
sall $8, %eax
movl %eax, -4(%rbp)
movl $15, %esi
movl $980, %edi
call port_byte_out@PLT
movl $981, %edi
call port_byte_in@PLT
movzbl %al, %eax
addl %eax, -4(%rbp)
movl -4(%rbp), %eax
addl %eax, %eax
leave
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE1:
.size get_cursor, .-get_cursor
.globl get_row_from_offset
.type get_row_from_offset, @function
get_row_from_offset:
.LFB2:
.cfi_startproc
endbr64
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
movl %edi, -4(%rbp)
movl -4(%rbp), %eax
movslq %eax, %rdx
imulq $1717986919, %rdx, %rdx
shrq $32, %rdx
sarl $5, %edx
sarl $31, %eax
movl %eax, %ecx
movl %edx, %eax
subl %ecx, %eax
popq %rbp
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE2:
.size get_row_from_offset, .-get_row_from_offset
.globl get_offset
.type get_offset, @function
get_offset:
.LFB3:
.cfi_startproc
endbr64
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
movl %edi, -4(%rbp)
movl %esi, -8(%rbp)
movl -8(%rbp), %edx
movl %edx, %eax
sall $2, %eax
addl %edx, %eax
sall $4, %eax
movl %eax, %edx
movl -4(%rbp), %eax
addl %edx, %eax
addl %eax, %eax
popq %rbp
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE3:
.size get_offset, .-get_offset
.globl set_char_at_video_memory
.type set_char_at_video_memory, @function
set_char_at_video_memory:
.LFB4:
.cfi_startproc
endbr64
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
movl %edi, %eax
movl %esi, -24(%rbp)
movb %al, -20(%rbp)
movq $753666, -8(%rbp)
movl -24(%rbp), %eax
cltq
leaq 1(%rax), %rdx
movq -8(%rbp), %rax
addq %rax, %rdx
movzbl -20(%rbp), %eax
movb %al, (%rdx)
movl -24(%rbp), %eax
cltq
leaq 2(%rax), %rdx
movq -8(%rbp), %rax
addq %rdx, %rax
movb $15, (%rax)
nop
popq %rbp
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE4:
.size set_char_at_video_memory, .-set_char_at_video_memory
.globl move_offset_to_new_line
.type move_offset_to_new_line, @function
move_offset_to_new_line:
.LFB5:
.cfi_startproc
endbr64
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
subq $8, %rsp
movl %edi, -4(%rbp)
movl -4(%rbp), %eax
movl %eax, %edi
call get_row_from_offset
addl $1, %eax
movl %eax, %esi
movl $0, %edi
call get_offset
leave
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE5:
.size move_offset_to_new_line, .-move_offset_to_new_line
.globl clear_screen
.type clear_screen, @function
clear_screen:
.LFB6:
.cfi_startproc
endbr64
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
subq $16, %rsp
movl $0, -4(%rbp)
jmp .L12
.L13:
movl -4(%rbp), %eax
addl %eax, %eax
movl %eax, %esi
movl $0, %edi
call set_char_at_video_memory
addl $1, -4(%rbp)
.L12:
cmpl $1999, -4(%rbp)
jle .L13
movl $0, %edi
call set_cursor
nop
leave
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE6:
.size clear_screen, .-clear_screen
.globl print_char
.type print_char, @function
print_char:
.LFB7:
.cfi_startproc
endbr64
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
subq $32, %rsp
movl %edi, %eax
movb %al, -20(%rbp)
movl $0, %eax
call get_cursor
movl %eax, -4(%rbp)
movsbl -20(%rbp), %eax
movl -4(%rbp), %edx
movl %edx, %esi
movl %eax, %edi
call set_char_at_video_memory
movl -4(%rbp), %eax
addl $2, %eax
movl %eax, %edi
call set_cursor
nop
leave
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE7:
.size print_char, .-print_char
.globl print_string
.type print_string, @function
print_string:
.LFB8:
.cfi_startproc
endbr64
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
subq $32, %rsp
movq %rdi, -24(%rbp)
movl $120, %edi
call print_char
movl $120, %edi
call print_char
movl $0, -4(%rbp)
jmp .L16
.L17:
movl -4(%rbp), %eax
movslq %eax, %rdx
movq -24(%rbp), %rax
addq %rdx, %rax
movzbl (%rax), %eax
movsbl %al, %eax
movl %eax, %edi
call print_char
addl $1, -4(%rbp)
.L16:
movl -4(%rbp), %eax
movslq %eax, %rdx
movq -24(%rbp), %rax
addq %rdx, %rax
movzbl (%rax), %eax
testb %al, %al
jne .L17
movl $0, %eax
leave
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE8:
.size print_string, .-print_string
.ident "GCC: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0"
.section .note.GNU-stack,"",@progbits
.section .note.gnu.property,"a"
.align 8
.long 1f - 0f
.long 4f - 1f
.long 5
0:
.string "GNU"
1:
.align 8
.long 0xc0000002
.long 3f - 2f
2:
.long 0x3
3:
.align 8
4: