VirtualBox

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

Last change on this file since 7944 was 6525, checked in by vboxsync, 17 years ago

UART_BASE -> IPRT_UART_BASE so it can safely be overrided by a DEFS += IPRT_UART_BASE=0xd800 statement in LocalConfig.kmk.

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