VirtualBox

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

Last change on this file since 9569 was 8155, checked in by vboxsync, 17 years ago

The Big Sun Rebranding Header Change

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