1 | ;; @file
|
---|
2 | ; VirtualBox YASM/NASM macros, structs, etc.
|
---|
3 | ;
|
---|
4 |
|
---|
5 | ;
|
---|
6 | ; Copyright (C) 2006-2007 innotek GmbH
|
---|
7 | ;
|
---|
8 | ; This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
9 | ; available from http://www.virtualbox.org. This file is free software;
|
---|
10 | ; you can redistribute it and/or modify it under the terms of the GNU
|
---|
11 | ; General Public License as published by the Free Software Foundation,
|
---|
12 | ; in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
|
---|
13 | ; distribution. VirtualBox OSE is distributed in the hope that it will
|
---|
14 | ; be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
15 |
|
---|
16 | %ifndef __VBox_asmdefs_mac__
|
---|
17 | %define __VBox_asmdefs_mac__
|
---|
18 |
|
---|
19 | ;; @def VBOX_WITH_STATISTICS
|
---|
20 | ; When defined all statistics will be included in the build.
|
---|
21 | ; This is enabled by default in all debug builds.
|
---|
22 | %ifndef VBOX_WITH_STATISTICS
|
---|
23 | %ifdef DEBUG
|
---|
24 | %define VBOX_WITH_STATISTICS
|
---|
25 | %endif
|
---|
26 | %endif
|
---|
27 |
|
---|
28 | %include "iprt/asmdefs.mac"
|
---|
29 |
|
---|
30 |
|
---|
31 |
|
---|
32 | ;%define UART_BASE 2f8h ; com2
|
---|
33 | %define UART_BASE 3f8h ; com1
|
---|
34 | %define UART_RATE 12 ; 9600 bps
|
---|
35 | %define UART_PARAMS 00000011b ; 8n1
|
---|
36 |
|
---|
37 |
|
---|
38 | ;;
|
---|
39 | ; Initializes the com port to 9600 baud 8n1.
|
---|
40 | ; al and dx are wasted.
|
---|
41 | ; @todo comport init doesn't quite work. :/
|
---|
42 | %macro COM_INIT 0
|
---|
43 | push eax
|
---|
44 | push edx
|
---|
45 |
|
---|
46 | mov dx, UART_BASE + 3
|
---|
47 | mov al, 80h
|
---|
48 | out dx, al ; make DL register accessible
|
---|
49 |
|
---|
50 | mov dx, UART_BASE
|
---|
51 | mov ax, UART_RATE
|
---|
52 | out dx, ax ; write bps rate divisor
|
---|
53 |
|
---|
54 | mov dx, UART_BASE + 3
|
---|
55 | mov al, UART_PARAMS
|
---|
56 | out dx, al ; write parameters
|
---|
57 |
|
---|
58 |
|
---|
59 | xor ax, ax
|
---|
60 | mov dx, UART_BASE + 4 ; disconnect the UART from the int line
|
---|
61 | out dx, al
|
---|
62 |
|
---|
63 | mov dx, UART_BASE + 1 ; disable UART ints
|
---|
64 | out dx, al
|
---|
65 |
|
---|
66 | mov dx, UART_BASE + 2 ; disable the fifos (old software relies on it)
|
---|
67 | out dx, al
|
---|
68 |
|
---|
69 | mov dx, UART_BASE
|
---|
70 | in al, dx ; clear receiver
|
---|
71 | mov dx, UART_BASE + 5
|
---|
72 | in al, dx ; clear line status
|
---|
73 | inc dx
|
---|
74 | in al, dx ; clear modem status
|
---|
75 |
|
---|
76 | pop edx
|
---|
77 | pop eax
|
---|
78 | %endmacro
|
---|
79 |
|
---|
80 |
|
---|
81 | ;;
|
---|
82 | ; writes string to comport
|
---|
83 | ; trashes nothing (uses stack though)
|
---|
84 |
|
---|
85 | %macro COM32_S_PRINT 1+
|
---|
86 | push esi
|
---|
87 | push ecx
|
---|
88 | push eax
|
---|
89 | mov ecx, edx
|
---|
90 | shl ecx, 16
|
---|
91 |
|
---|
92 | call %%stringend
|
---|
93 | %%string: db %1
|
---|
94 | %%stringend:
|
---|
95 | pop esi
|
---|
96 | mov cx, %%stringend - %%string
|
---|
97 | %%status:
|
---|
98 | mov dx, UART_BASE + 5
|
---|
99 | in al, dx
|
---|
100 | test al, 20h
|
---|
101 | jz short %%status
|
---|
102 |
|
---|
103 | mov al, [esi]
|
---|
104 | mov dx, UART_BASE
|
---|
105 | out dx, al
|
---|
106 | inc esi
|
---|
107 | dec cx
|
---|
108 | jnz short %%status
|
---|
109 |
|
---|
110 | %%status2:
|
---|
111 | mov dx, UART_BASE + 5
|
---|
112 | in al, dx
|
---|
113 | test al, 20h
|
---|
114 | jz short %%status2
|
---|
115 |
|
---|
116 | shr ecx, 16
|
---|
117 | mov dx, cx
|
---|
118 | pop eax
|
---|
119 | pop ecx
|
---|
120 | pop esi
|
---|
121 | %endmacro
|
---|
122 |
|
---|
123 | %macro COM64_S_PRINT 1+
|
---|
124 | push rsi
|
---|
125 | push rdx
|
---|
126 | push rcx
|
---|
127 | push rax
|
---|
128 |
|
---|
129 | jmp %%stringend
|
---|
130 | %%string: db %1
|
---|
131 | %%stringend:
|
---|
132 | lea rsi, [%%string wrt rip]
|
---|
133 | mov cx, %%stringend - %%string
|
---|
134 | %%status:
|
---|
135 | mov dx, UART_BASE + 5
|
---|
136 | in al, dx
|
---|
137 | test al, 20h
|
---|
138 | jz short %%status
|
---|
139 |
|
---|
140 | mov al, [rsi]
|
---|
141 | mov dx, UART_BASE
|
---|
142 | out dx, al
|
---|
143 | inc rsi
|
---|
144 | dec cx
|
---|
145 | jnz short %%status
|
---|
146 |
|
---|
147 | %%status2:
|
---|
148 | mov dx, UART_BASE + 5
|
---|
149 | in al, dx
|
---|
150 | test al, 20h
|
---|
151 | jz short %%status2
|
---|
152 |
|
---|
153 | pop rax
|
---|
154 | pop rcx
|
---|
155 | pop rdx
|
---|
156 | pop rsi
|
---|
157 | %endmacro
|
---|
158 |
|
---|
159 | %macro COM_S_PRINT 1+
|
---|
160 | %ifdef RT_ARCH_AMD64
|
---|
161 | COM64_S_PRINT %1
|
---|
162 | %else
|
---|
163 | COM32_S_PRINT %1
|
---|
164 | %endif
|
---|
165 | %endmacro
|
---|
166 |
|
---|
167 |
|
---|
168 | ;; Write char.
|
---|
169 | ; trashes esi
|
---|
170 | %macro COM_CHAR 1
|
---|
171 | mov esi, eax
|
---|
172 | shl esi, 16
|
---|
173 | mov si, dx
|
---|
174 |
|
---|
175 | %%status:
|
---|
176 | mov dx, UART_BASE + 5
|
---|
177 | in al, dx
|
---|
178 | test al, 20h
|
---|
179 | jz short %%status
|
---|
180 |
|
---|
181 | mov al, %1
|
---|
182 | mov dx, UART_BASE
|
---|
183 | out dx, al
|
---|
184 |
|
---|
185 | %%status2:
|
---|
186 | mov dx, UART_BASE + 5
|
---|
187 | in al, dx
|
---|
188 | test al, 20h
|
---|
189 | jz short %%status2
|
---|
190 |
|
---|
191 | mov dx, si
|
---|
192 | shr esi, 16
|
---|
193 | mov ax, si
|
---|
194 | %endmacro
|
---|
195 |
|
---|
196 |
|
---|
197 | ;; Write char.
|
---|
198 | ; trashes nothing (uses stack though)
|
---|
199 |
|
---|
200 | %macro COM32_S_CHAR 1
|
---|
201 | push eax
|
---|
202 | push edx
|
---|
203 |
|
---|
204 | %%status:
|
---|
205 | mov dx, UART_BASE + 5
|
---|
206 | in al, dx
|
---|
207 | test al, 20h
|
---|
208 | jz short %%status
|
---|
209 |
|
---|
210 | mov al, %1
|
---|
211 | mov dx, UART_BASE
|
---|
212 | out dx, al
|
---|
213 |
|
---|
214 | %%status2:
|
---|
215 | mov dx, UART_BASE + 5
|
---|
216 | in al, dx
|
---|
217 | test al, 20h
|
---|
218 | jz short %%status2
|
---|
219 |
|
---|
220 | pop edx
|
---|
221 | pop eax
|
---|
222 | %endmacro
|
---|
223 |
|
---|
224 | %macro COM64_S_CHAR 1
|
---|
225 | push rax
|
---|
226 | push rdx
|
---|
227 |
|
---|
228 | %%status:
|
---|
229 | mov dx, UART_BASE + 5
|
---|
230 | in al, dx
|
---|
231 | test al, 20h
|
---|
232 | jz short %%status
|
---|
233 |
|
---|
234 | mov al, %1
|
---|
235 | mov dx, UART_BASE
|
---|
236 | out dx, al
|
---|
237 |
|
---|
238 | %%status2:
|
---|
239 | mov dx, UART_BASE + 5
|
---|
240 | in al, dx
|
---|
241 | test al, 20h
|
---|
242 | jz short %%status2
|
---|
243 |
|
---|
244 | pop rdx
|
---|
245 | pop rax
|
---|
246 | %endmacro
|
---|
247 |
|
---|
248 | %macro COM_S_CHAR 1
|
---|
249 | %ifdef RT_ARCH_AMD64
|
---|
250 | COM64_S_CHAR %1
|
---|
251 | %else
|
---|
252 | COM32_S_CHAR %1
|
---|
253 | %endif
|
---|
254 | %endmacro
|
---|
255 |
|
---|
256 |
|
---|
257 | ;; Writes newline
|
---|
258 | ; trashes esi
|
---|
259 | %macro COM_NEWLINE 0
|
---|
260 | mov esi, eax
|
---|
261 | shl esi, 16
|
---|
262 | mov si, dx
|
---|
263 |
|
---|
264 | %%status1:
|
---|
265 | mov dx, UART_BASE + 5
|
---|
266 | in al, dx
|
---|
267 | test al, 20h
|
---|
268 | jz short %%status1
|
---|
269 |
|
---|
270 | mov al, 13
|
---|
271 | mov dx, UART_BASE
|
---|
272 | out dx, al
|
---|
273 |
|
---|
274 | %%status2:
|
---|
275 | mov dx, UART_BASE + 5
|
---|
276 | in al, dx
|
---|
277 | test al, 20h
|
---|
278 | jz short %%status2
|
---|
279 |
|
---|
280 | mov al, 10
|
---|
281 | mov dx, UART_BASE
|
---|
282 | out dx, al
|
---|
283 |
|
---|
284 | %%status3:
|
---|
285 | mov dx, UART_BASE + 5
|
---|
286 | in al, dx
|
---|
287 | test al, 20h
|
---|
288 | jz short %%status3
|
---|
289 |
|
---|
290 | mov dx, si
|
---|
291 | shr esi, 16
|
---|
292 | mov ax, si
|
---|
293 | %endmacro
|
---|
294 |
|
---|
295 |
|
---|
296 | ;; Writes newline
|
---|
297 | ; trashes nothing (uses stack though)
|
---|
298 |
|
---|
299 | %macro COM32_S_NEWLINE 0
|
---|
300 | push edx
|
---|
301 | push eax
|
---|
302 |
|
---|
303 | %%status1:
|
---|
304 | mov dx, UART_BASE + 5
|
---|
305 | in al, dx
|
---|
306 | test al, 20h
|
---|
307 | jz short %%status1
|
---|
308 |
|
---|
309 | mov al, 13
|
---|
310 | mov dx, UART_BASE
|
---|
311 | out dx, al
|
---|
312 |
|
---|
313 | %%status2:
|
---|
314 | mov dx, UART_BASE + 5
|
---|
315 | in al, dx
|
---|
316 | test al, 20h
|
---|
317 | jz short %%status2
|
---|
318 |
|
---|
319 | mov al, 10
|
---|
320 | mov dx, UART_BASE
|
---|
321 | out dx, al
|
---|
322 |
|
---|
323 | %%status3:
|
---|
324 | mov dx, UART_BASE + 5
|
---|
325 | in al, dx
|
---|
326 | test al, 20h
|
---|
327 | jz short %%status3
|
---|
328 |
|
---|
329 | pop eax
|
---|
330 | pop edx
|
---|
331 | %endmacro
|
---|
332 |
|
---|
333 | %macro COM64_S_NEWLINE 0
|
---|
334 | push rdx
|
---|
335 | push rax
|
---|
336 |
|
---|
337 | %%status1:
|
---|
338 | mov dx, UART_BASE + 5
|
---|
339 | in al, dx
|
---|
340 | test al, 20h
|
---|
341 | jz short %%status1
|
---|
342 |
|
---|
343 | mov al, 13
|
---|
344 | mov dx, UART_BASE
|
---|
345 | out dx, al
|
---|
346 |
|
---|
347 | %%status2:
|
---|
348 | mov dx, UART_BASE + 5
|
---|
349 | in al, dx
|
---|
350 | test al, 20h
|
---|
351 | jz short %%status2
|
---|
352 |
|
---|
353 | mov al, 10
|
---|
354 | mov dx, UART_BASE
|
---|
355 | out dx, al
|
---|
356 |
|
---|
357 | %%status3:
|
---|
358 | mov dx, UART_BASE + 5
|
---|
359 | in al, dx
|
---|
360 | test al, 20h
|
---|
361 | jz short %%status3
|
---|
362 |
|
---|
363 | pop rax
|
---|
364 | pop rdx
|
---|
365 | %endmacro
|
---|
366 |
|
---|
367 | %macro COM_S_NEWLINE 0
|
---|
368 | %ifdef RT_ARCH_AMD64
|
---|
369 | COM64_S_NEWLINE
|
---|
370 | %else
|
---|
371 | COM32_S_NEWLINE
|
---|
372 | %endif
|
---|
373 | %endmacro
|
---|
374 |
|
---|
375 |
|
---|
376 | ;; Writes a dword from register to com port.
|
---|
377 | ; trashes esi, edi
|
---|
378 | ; edi cannot be used as input register
|
---|
379 | %macro COM_DWORD_REG 1
|
---|
380 | mov edi, ebx ; save ebx
|
---|
381 | mov ebx, %1 ; get value we're supposed to print
|
---|
382 | mov esi, eax ; save ax
|
---|
383 | shl esi, 16 ; save dx
|
---|
384 | mov si, dx
|
---|
385 |
|
---|
386 | mov ah, 8 ; loop counter.
|
---|
387 | %%daloop:
|
---|
388 | rol ebx, 4 ; shift next digit to the front
|
---|
389 |
|
---|
390 | %%status0:
|
---|
391 | mov dx, UART_BASE + 5
|
---|
392 | in al, dx
|
---|
393 | test al, 20h
|
---|
394 | jz short %%status0
|
---|
395 |
|
---|
396 | mov al, bl ; get next char
|
---|
397 | and al, 0fh
|
---|
398 | cmp al, 10
|
---|
399 | jae short %%hex ; yasm BUG! It sometimes generate a near jump here. YASMCHECK!
|
---|
400 | add al, '0'
|
---|
401 | jmp short %%print
|
---|
402 | %%hex:
|
---|
403 | add al, 'a' - 10
|
---|
404 | %%print:
|
---|
405 | mov dx, UART_BASE
|
---|
406 | out dx, al
|
---|
407 |
|
---|
408 | dec ah
|
---|
409 | jnz short %%daloop ; loop
|
---|
410 |
|
---|
411 | mov dx, si ; restore dx
|
---|
412 | shr esi, 16
|
---|
413 | mov ax, si ; restore ax
|
---|
414 | mov ebx, edi ; restore ebx
|
---|
415 | %endmacro
|
---|
416 |
|
---|
417 |
|
---|
418 | ;; Writes a dword from register to com port.
|
---|
419 | ; trashes nothing (uses stack though)
|
---|
420 |
|
---|
421 | %macro COM32_S_DWORD_REG 1
|
---|
422 | push edx
|
---|
423 | push eax
|
---|
424 | push ebx
|
---|
425 |
|
---|
426 | mov ebx, %1 ; get value we're supposed to print
|
---|
427 |
|
---|
428 | mov ah, 8 ; loop counter.
|
---|
429 | %%daloop:
|
---|
430 | rol ebx, 4 ; shift next digit to the front
|
---|
431 |
|
---|
432 | %%status0:
|
---|
433 | mov dx, UART_BASE + 5
|
---|
434 | in al, dx
|
---|
435 | test al, 20h
|
---|
436 | jz short %%status0
|
---|
437 |
|
---|
438 | mov al, bl ; get next char
|
---|
439 | and al, 0fh
|
---|
440 | cmp al, 10
|
---|
441 | jae short %%hex ; yasm BUG! It sometimes generate a near jump here. YASMCHECK!
|
---|
442 | add al, '0'
|
---|
443 | jmp short %%print
|
---|
444 | %%hex:
|
---|
445 | add al, 'a' - 10
|
---|
446 | %%print:
|
---|
447 | mov dx, UART_BASE
|
---|
448 | out dx, al
|
---|
449 |
|
---|
450 | dec ah
|
---|
451 | jnz short %%daloop ; loop
|
---|
452 |
|
---|
453 | pop ebx
|
---|
454 | pop eax
|
---|
455 | pop edx
|
---|
456 | %endmacro
|
---|
457 |
|
---|
458 | %macro COM64_S_DWORD_REG 1
|
---|
459 | push rdx
|
---|
460 | push rax
|
---|
461 | push rbx
|
---|
462 |
|
---|
463 | mov ebx, %1 ; get value we're supposed to print
|
---|
464 |
|
---|
465 | mov ah, 8 ; loop counter.
|
---|
466 | %%daloop:
|
---|
467 | rol ebx, 4 ; shift next digit to the front
|
---|
468 |
|
---|
469 | %%status0:
|
---|
470 | mov dx, UART_BASE + 5
|
---|
471 | in al, dx
|
---|
472 | test al, 20h
|
---|
473 | jz short %%status0
|
---|
474 |
|
---|
475 | mov al, bl ; get next char
|
---|
476 | and al, 0fh
|
---|
477 | cmp al, 10
|
---|
478 | jae short %%hex ; yasm BUG! It sometimes generate a near jump here. YASMCHECK!
|
---|
479 | add al, '0'
|
---|
480 | jmp short %%print
|
---|
481 | %%hex:
|
---|
482 | add al, 'a' - 10
|
---|
483 | %%print:
|
---|
484 | mov dx, UART_BASE
|
---|
485 | out dx, al
|
---|
486 |
|
---|
487 | dec ah
|
---|
488 | jnz short %%daloop ; loop
|
---|
489 |
|
---|
490 | pop rbx
|
---|
491 | pop rax
|
---|
492 | pop rdx
|
---|
493 | %endmacro
|
---|
494 |
|
---|
495 | %macro COM_S_DWORD_REG 1
|
---|
496 | %ifdef RT_ARCH_AMD64
|
---|
497 | COM64_S_DWORD_REG %1
|
---|
498 | %else
|
---|
499 | COM32_S_DWORD_REG %1
|
---|
500 | %endif
|
---|
501 | %endmacro
|
---|
502 |
|
---|
503 |
|
---|
504 | ;; Writes a qword from register to com port.
|
---|
505 | ; trashes nothing (uses stack though)
|
---|
506 | %macro COM64_S_QWORD_REG 1
|
---|
507 | push rdx
|
---|
508 | push rax
|
---|
509 | push rbx
|
---|
510 |
|
---|
511 | mov rbx, %1 ; get value we're supposed to print
|
---|
512 |
|
---|
513 | mov ah, 16 ; loop counter.
|
---|
514 | %%daloop:
|
---|
515 | rol rbx, 4 ; shift next digit to the front
|
---|
516 |
|
---|
517 | %%status0:
|
---|
518 | mov dx, UART_BASE + 5
|
---|
519 | in al, dx
|
---|
520 | test al, 20h
|
---|
521 | jz short %%status0
|
---|
522 |
|
---|
523 | mov al, bl ; get next char
|
---|
524 | and al, 0fh
|
---|
525 | cmp al, 10
|
---|
526 | jae short %%hex ; yasm BUG! It sometimes generate a near jump here. YASMCHECK!
|
---|
527 | add al, '0'
|
---|
528 | jmp short %%print
|
---|
529 | %%hex:
|
---|
530 | add al, 'a' - 10
|
---|
531 | %%print:
|
---|
532 | mov dx, UART_BASE
|
---|
533 | out dx, al
|
---|
534 |
|
---|
535 | dec ah
|
---|
536 | jnz short %%daloop ; loop
|
---|
537 |
|
---|
538 | pop rbx
|
---|
539 | pop rax
|
---|
540 | pop rdx
|
---|
541 | %endmacro
|
---|
542 |
|
---|
543 |
|
---|
544 | ;; Writes a byte from register to com port.
|
---|
545 | ; trashes nothing (uses stack though)
|
---|
546 |
|
---|
547 | %macro COM32_S_BYTE_REG 1
|
---|
548 | push edx
|
---|
549 | push eax
|
---|
550 | push ebx
|
---|
551 |
|
---|
552 | mov ebx, %1 ; get value we're supposed to print
|
---|
553 |
|
---|
554 | mov ah, 2 ; loop counter.
|
---|
555 | ror ebx, 8 ; shift next digit to the front
|
---|
556 | %%daloop:
|
---|
557 | rol ebx, 4 ; shift next digit to the front
|
---|
558 |
|
---|
559 | %%status0:
|
---|
560 | mov dx, UART_BASE + 5
|
---|
561 | in al, dx
|
---|
562 | test al, 20h
|
---|
563 | jz short %%status0
|
---|
564 |
|
---|
565 | mov al, bl ; get next char
|
---|
566 | and al, 0fh
|
---|
567 | cmp al, 10
|
---|
568 | jae short %%hex ; yasm BUG! It sometimes generate a near jump here. YASMCHECK!
|
---|
569 | add al, '0'
|
---|
570 | jmp short %%print
|
---|
571 | %%hex:
|
---|
572 | add al, 'a' - 10
|
---|
573 | %%print:
|
---|
574 | mov dx, UART_BASE
|
---|
575 | out dx, al
|
---|
576 |
|
---|
577 | dec ah
|
---|
578 | jnz short %%daloop ; loop
|
---|
579 |
|
---|
580 | pop ebx
|
---|
581 | pop eax
|
---|
582 | pop edx
|
---|
583 | %endmacro
|
---|
584 |
|
---|
585 | %macro COM64_S_BYTE_REG 1
|
---|
586 | push rdx
|
---|
587 | push rax
|
---|
588 | push rbx
|
---|
589 |
|
---|
590 | mov ebx, %1 ; get value we're supposed to print
|
---|
591 |
|
---|
592 | mov ah, 2 ; loop counter.
|
---|
593 | ror ebx, 8 ; shift next digit to the front
|
---|
594 | %%daloop:
|
---|
595 | rol ebx, 4 ; shift next digit to the front
|
---|
596 |
|
---|
597 | %%status0:
|
---|
598 | mov dx, UART_BASE + 5
|
---|
599 | in al, dx
|
---|
600 | test al, 20h
|
---|
601 | jz short %%status0
|
---|
602 |
|
---|
603 | mov al, bl ; get next char
|
---|
604 | and al, 0fh
|
---|
605 | cmp al, 10
|
---|
606 | jae short %%hex ; yasm BUG! It sometimes generate a near jump here. YASMCHECK!
|
---|
607 | add al, '0'
|
---|
608 | jmp short %%print
|
---|
609 | %%hex:
|
---|
610 | add al, 'a' - 10
|
---|
611 | %%print:
|
---|
612 | mov dx, UART_BASE
|
---|
613 | out dx, al
|
---|
614 |
|
---|
615 | dec ah
|
---|
616 | jnz short %%daloop ; loop
|
---|
617 |
|
---|
618 | pop rbx
|
---|
619 | pop rax
|
---|
620 | pop rdx
|
---|
621 | %endmacro
|
---|
622 |
|
---|
623 | %macro COM_S_BYTE_REG 1
|
---|
624 | %ifdef RT_ARCH_AMD64
|
---|
625 | COM64_S_BYTE_REG %1
|
---|
626 | %else
|
---|
627 | COM32_S_BYTE_REG %1
|
---|
628 | %endif
|
---|
629 | %endmacro
|
---|
630 |
|
---|
631 |
|
---|
632 |
|
---|
633 | ;; Writes a single hex digit from register to com port.
|
---|
634 | ; trashes nothing (uses stack though)
|
---|
635 |
|
---|
636 | %macro COM32_S_DIGIT_REG 1
|
---|
637 | push edx
|
---|
638 | push eax
|
---|
639 | push ebx
|
---|
640 |
|
---|
641 | mov ebx, %1 ; get value we're supposed to print
|
---|
642 | %%status0:
|
---|
643 | mov dx, UART_BASE + 5
|
---|
644 | in al, dx
|
---|
645 | test al, 20h
|
---|
646 | jz short %%status0
|
---|
647 |
|
---|
648 | mov al, bl ; get next char
|
---|
649 | and al, 0fh
|
---|
650 | cmp al, 10
|
---|
651 | jae short %%hex ; yasm BUG! It sometimes generate a near jump here. YASMCHECK!
|
---|
652 | add al, '0'
|
---|
653 | jmp short %%print
|
---|
654 | %%hex:
|
---|
655 | add al, 'a' - 10
|
---|
656 | %%print:
|
---|
657 | mov dx, UART_BASE
|
---|
658 | out dx, al
|
---|
659 |
|
---|
660 | pop ebx
|
---|
661 | pop eax
|
---|
662 | pop edx
|
---|
663 | %endmacro
|
---|
664 |
|
---|
665 | %macro COM64_S_DIGIT_REG 1
|
---|
666 | push rdx
|
---|
667 | push rax
|
---|
668 | push rbx
|
---|
669 |
|
---|
670 | mov ebx, %1 ; get value we're supposed to print
|
---|
671 | %%status0:
|
---|
672 | mov dx, UART_BASE + 5
|
---|
673 | in al, dx
|
---|
674 | test al, 20h
|
---|
675 | jz short %%status0
|
---|
676 |
|
---|
677 | mov al, bl ; get next char
|
---|
678 | and al, 0fh
|
---|
679 | cmp al, 10
|
---|
680 | jae short %%hex ; yasm BUG! It sometimes generate a near jump here. YASMCHECK!
|
---|
681 | add al, '0'
|
---|
682 | jmp short %%print
|
---|
683 | %%hex:
|
---|
684 | add al, 'a' - 10
|
---|
685 | %%print:
|
---|
686 | mov dx, UART_BASE
|
---|
687 | out dx, al
|
---|
688 |
|
---|
689 | pop rbx
|
---|
690 | pop rax
|
---|
691 | pop rdx
|
---|
692 | %endmacro
|
---|
693 |
|
---|
694 | %macro COM_S_DIGIT_REG 1
|
---|
695 | %ifdef RT_ARCH_AMD64
|
---|
696 | COM64_S_DIGIT_REG %1
|
---|
697 | %else
|
---|
698 | COM32_S_DIGIT_REG %1
|
---|
699 | %endif
|
---|
700 | %endmacro
|
---|
701 |
|
---|
702 |
|
---|
703 | ;;
|
---|
704 | ; Loops for a while.
|
---|
705 | ; ecx is trashed.
|
---|
706 | %macro LOOP_A_WHILE 0
|
---|
707 |
|
---|
708 | xor ecx, ecx
|
---|
709 | dec ecx
|
---|
710 | shr ecx, 1
|
---|
711 | %%looplabel:
|
---|
712 | nop
|
---|
713 | nop
|
---|
714 | nop
|
---|
715 | dec ecx
|
---|
716 | jnz short %%looplabel
|
---|
717 |
|
---|
718 | %endmacro
|
---|
719 |
|
---|
720 |
|
---|
721 | ;;
|
---|
722 | ; Loops for a short while.
|
---|
723 | ; ecx is trashed.
|
---|
724 | %macro LOOP_SHORT_WHILE 0
|
---|
725 |
|
---|
726 | xor ecx, ecx
|
---|
727 | dec ecx
|
---|
728 | shr ecx, 4
|
---|
729 | %%looplabel:
|
---|
730 | nop
|
---|
731 | nop
|
---|
732 | dec ecx
|
---|
733 | jnz short %%looplabel
|
---|
734 |
|
---|
735 | %endmacro
|
---|
736 |
|
---|
737 | %endif
|
---|
738 |
|
---|