VirtualBox

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

Last change on this file since 101084 was 98103, checked in by vboxsync, 22 months ago

Copyright year updates by scm.

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