VirtualBox

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

Last change on this file since 5999 was 5999, checked in by vboxsync, 16 years ago

The Giant CDDL Dual-License Header Change.

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

© 2023 Oracle
ContactPrivacy policyTerms of Use