VirtualBox

Changeset 18

Show
Ignore:
Timestamp:
01/15/07 13:53:28 (2 years ago)
Author:
vboxsync
Message:

nasm.mac -> asmdefs.mac

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/include/VBox/asmdefs.mac

    • Property svn:keywords deleted
    r1 r18  
    11;; @file 
    2 
    3 ; Global NASM macros 
     2; VirtualBox YASM/NASM macros, structs, etc. 
    43; 
    54 
     
    2019; 
    2120 
    22 %ifndef __VBox_nasm_mac__ 
    23 %define __VBox_nasm_mac__ 
     21%ifndef __VBox_asmdefs_mac__ 
     22%define __VBox_asmdefs_mac__ 
    2423 
    2524;; @def VBOX_WITH_STATISTICS 
  • trunk/include/VBox/nasm.mac

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

© 2008 Sun Microsystems, Inc.
ContactPrivacy policy