VirtualBox

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

Last change on this file since 3269 was 2981, checked in by vboxsync, 17 years ago

InnoTek -> innotek: all the headers and comments.

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