VirtualBox

source: vbox/trunk/include/VBox/asmdefs.mac@ 69198

Last change on this file since 69198 was 69107, checked in by vboxsync, 7 years ago

include/VBox/: (C) year

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette