VirtualBox

Changeset 60484 in vbox for trunk/src/VBox/Devices


Ignore:
Timestamp:
Apr 14, 2016 9:25:51 AM (9 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
106586
Message:

PCBIOS: split up the support.asm file and implemented 32-bit division for pre-386 targets in C using uint32.h (derived from uint128.h via uint64.h).

Location:
trunk/src/VBox/Devices
Files:
1 added
1 edited
8 copied
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/BiosCommonCode/ASMBitLastSetU16.asm

    r60406 r60484  
    11; $Id$
    22;; @file
    3 ; IPRT - ASMBitLastSetU16().
     3; BiosCommonCode - ASMBitLastSetU16() - borrowed from IPRT.
    44;
    55
     
    2929;* Header Files                                                                *
    3030;*******************************************************************************
    31 %include "iprt/asmdefs.mac"
     31public _ASMBitLastSetU16
    3232
    33 BEGINCODE
     33        .8086
     34
     35_TEXT   segment public 'CODE' use16
     36        assume cs:_TEXT
     37
    3438
    3539;;
     
    3842; Bits are numbered from 1 (least significant) to 16.
    3943;
    40 ; @returns (xAX)        index [1..16] of the last set bit.
    41 ; @returns (xAX)        0 if all bits are cleared.
    42 ; @param   msc:cx gcc:di x86:stack u16  Integer to search for set bits.
     44; @returns (ax)     index [1..16] of the last set bit.
     45; @returns (ax)     0 if all bits are cleared.
     46; @param   u16      Integer to search for set bits.
    4347;
    4448; @cproto DECLASM(unsigned) ASMBitLastSetU16(uint32_t u16);
    4549;
    46 BEGINPROC_EXPORTED ASMBitLastSetU16
    47 %if ARCH_BITS == 16
    48         CPU     8086
     50_ASMBitLastSetU16   proc
     51        .8086
    4952        push    bp
    5053        mov     bp, sp
     
    5255        mov     cx, [bp + 2 + 2]
    5356        test    cx, cx                  ; check if zero (eliminates checking dec ax result)
    54         jz      .return_zero
     57        jz      return_zero
    5558
    5659        mov     ax, 16
    57 .next_bit:
     60next_bit:
    5861        shl     cx, 1
    59         jc      .return
     62        jc      return
    6063        dec     ax
    61         jmp     .next_bit
     64        jmp     next_bit
    6265
    63 .return_zero:
     66return_zero:
    6467        xor     ax, ax
    65 .return:
     68return:
    6669        pop     bp
    6770        ret
     71_ASMBitLastSetU16   endp
    6872
    69 %else
    70         xor     eax, eax
    71  %if    ARCH_BITS == 64
    72   %ifdef ASM_CALL64_GCC
    73         bsr     ax, si
    74   %else
    75         bsr     ax, cx
    76   %endif
    77  %elif ARCH_BITS == 32
    78         bsr     ax, word [esp + 4]
    79  %else
    80   %error "Missing or invalid ARCH_BITS."
    81  %endif
    82         jz      .return_zero
    83         inc     eax
    84 .return:
    85         ret
    86 .return_zero:
    87         xor     eax, eax
    88         ret
    89 %endif
    90 ENDPROC ASMBitLastSetU16
     73_TEXT           ends
     74                end
    9175
  • trunk/src/VBox/Devices/BiosCommonCode/__I4D.asm

    r60406 r60484  
    2020;*  Exported Symbols                                                           *
    2121;*******************************************************************************
    22 public          __U4D
    23 public          __U4M
    24 public          __U8LS
    25 public          __U8RS
    26 ifndef          VBOX_PC_BIOS
    2722public          __I4D
    28 public          __I4M
     23
     24if VBOX_BIOS_CPU lt 80386
     25extrn NeedToImplementOn8086__I4D:near
    2926endif
    30 public          _fmemset_
    31 public          _fmemcpy_
    3227
     28                .8086
    3329
    34 
    35                 .386p
    3630
    3731_TEXT           segment public 'CODE' use16
    3832                assume cs:_TEXT
    3933
    40 
    41 ;;
    42 ; 32-bit unsigned division.
    43 ;
    44 ; @param    dx:ax   Dividend.
    45 ; @param    cx:bx   Divisor.
    46 ; @returns  dx:ax   Quotient.
    47 ;           cx:bx   Remainder.
    48 ;
    49 __U4D:
    50                 pushf
    51                 push    eax
    52                 push    edx
    53                 push    ecx
    54 
    55                 rol     eax, 16
    56                 mov     ax, dx
    57                 ror     eax, 16
    58                 xor     edx, edx
    59 
    60                 shr     ecx, 16
    61                 mov     cx, bx
    62 
    63                 div     ecx                 ; eax:edx / ecx -> eax=quotient, edx=remainder.
    64 
    65                 mov     bx, dx
    66                 pop     ecx
    67                 shr     edx, 16
    68                 mov     cx, dx
    69 
    70                 pop     edx
    71                 ror     eax, 16
    72                 mov     dx, ax
    73                 add     sp, 2
    74                 pop     ax
    75                 rol     eax, 16
    76 
    77                 popf
    78                 ret
    79 
    80 
    81 ifndef          VBOX_PC_BIOS
    8234;;
    8335; 32-bit signed division.
     
    9042__I4D:
    9143                pushf
     44if VBOX_BIOS_CPU ge 80386
     45                .386
    9246                push    eax
    9347                push    edx
     
    11569                pop     ax
    11670                rol     eax, 16
    117 
     71                .8086
     72else
     73                call    NeedToImplementOn8086__I4D
     74endif
    11875                popf
    119                 ret
    120 endif           ; VBOX_PC_BIOS
    121 
    122 
    123 ;;
    124 ; 32-bit unsigned multiplication.
    125 ;
    126 ; @param    dx:ax   Factor 1.
    127 ; @param    cx:bx   Factor 2.
    128 ; @returns  dx:ax   Result.
    129 ;
    130 __U4M:
    131                 pushf
    132                 push    eax
    133                 push    edx
    134                 push    ecx
    135 
    136                 rol     eax, 16
    137                 mov     ax, dx
    138                 ror     eax, 16
    139                 xor     edx, edx
    140 
    141                 shr     ecx, 16
    142                 mov     cx, bx
    143 
    144                 mul     ecx                 ; eax * ecx -> edx:eax
    145 
    146                 pop     ecx
    147 
    148                 pop     edx
    149                 ror     eax, 16
    150                 mov     dx, ax
    151                 add     sp, 2
    152                 pop     ax
    153                 rol     eax, 16
    154 
    155                 popf
    156                 ret
    157 
    158 
    159 ifndef          VBOX_PC_BIOS
    160 ;;
    161 ; 32-bit signed multiplication.
    162 ;
    163 ; @param    dx:ax   Factor 1.
    164 ; @param    cx:bx   Factor 2.
    165 ; @returns  dx:ax   Result.
    166 ; cx, es may be modified; di is preserved
    167 ;
    168 __I4M:
    169                 pushf
    170                 push    eax
    171                 push    edx
    172                 push    ecx
    173                 push    ebx
    174 
    175                 rol     eax, 16
    176                 mov     ax, dx
    177                 ror     eax, 16
    178                 xor     edx, edx
    179 
    180                 shr     ecx, 16
    181                 mov     cx, bx
    182 
    183                 imul    ecx                 ; eax * ecx -> edx:eax
    184 
    185                 pop     ebx
    186                 pop     ecx
    187 
    188                 pop     edx
    189                 ror     eax, 16
    190                 mov     dx, ax
    191                 add     sp, 2
    192                 pop     ax
    193                 rol     eax, 16
    194 
    195                 popf
    196                 ret
    197 endif           ; VBOX_PC_BIOS
    198 
    199 
    200 ;;
    201 ; 64-bit left shift.
    202 ;
    203 ; @param    ax:bx:cx:dx Value.
    204 ; @param    si          Shift count.
    205 ; @returns  ax:bx:cx:dx Shifted value.
    206 ; si is zeroed
    207 ;
    208 __U8LS:
    209 
    210                 test    si, si
    211                 jz      u8ls_quit
    212 u8ls_rot:
    213                 shl     dx, 1
    214                 rcl     cx, 1
    215                 rcl     bx, 1
    216                 rcl     ax, 1
    217                 dec     si
    218                 jnz     u8ls_rot
    219 u8ls_quit:
    220                 ret
    221 
    222 
    223 ;;
    224 ; 64-bit unsigned right shift.
    225 ;
    226 ; @param    ax:bx:cx:dx Value.
    227 ; @param    si          Shift count.
    228 ; @returns  ax:bx:cx:dx Shifted value.
    229 ; si is zeroed
    230 ;
    231 __U8RS:
    232 
    233                 test    si, si
    234                 jz      u8rs_quit
    235 u8rs_rot:
    236                 shr     ax, 1
    237                 rcr     bx, 1
    238                 rcr     cx, 1
    239                 rcr     dx, 1
    240                 dec     si
    241                 jnz     u8rs_rot
    242 u8rs_quit:
    243                 ret
    244 
    245 
    246 ;;
    247 ; memset taking a far pointer.
    248 ;
    249 ; cx, es may be modified; di is preserved
    250 ;
    251 ; @returns  dx:ax unchanged.
    252 ; @param    dx:ax   Pointer to the memory.
    253 ; @param    bl      The fill value.
    254 ; @param    cx      The number of bytes to fill.
    255 ;
    256 _fmemset_:
    257                 push    di
    258 
    259                 mov     es, dx
    260                 mov     di, ax
    261                 xchg    al, bl
    262                 rep stosb
    263                 xchg    al, bl
    264 
    265                 pop     di
    266                 ret
    267 
    268 
    269 ;;
    270 ; memcpy taking far pointers.
    271 ;
    272 ; cx, es may be modified; si, di are preserved
    273 ;
    274 ; @returns  dx:ax unchanged.
    275 ; @param    dx:ax   Pointer to the destination memory.
    276 ; @param    cx:bx   Pointer to the source memory.
    277 ; @param    sp+2    The number of bytes to copy (dw).
    278 ;
    279 _fmemcpy_:
    280                 push    bp
    281                 mov     bp, sp
    282                 push    di
    283                 push    ds
    284                 push    si
    285 
    286                 mov     es, dx
    287                 mov     di, ax
    288                 mov     ds, cx
    289                 mov     si, bx
    290                 mov     cx, [bp + 4]
    291                 rep     movsb
    292 
    293                 pop     si
    294                 pop     ds
    295                 pop     di
    296                 leave
    29776                ret
    29877
  • trunk/src/VBox/Devices/BiosCommonCode/__I4M.asm

    r60406 r60484  
    2020;*  Exported Symbols                                                           *
    2121;*******************************************************************************
    22 public          __U4D
    23 public          __U4M
    24 public          __U8LS
    25 public          __U8RS
    26 ifndef          VBOX_PC_BIOS
    27 public          __I4D
    2822public          __I4M
     23
     24if VBOX_BIOS_CPU lt 80386
     25extrn NeedToImplementOn8086__I4M:near
    2926endif
    30 public          _fmemset_
    31 public          _fmemcpy_
    3227
    33 
    34 
    35                 .386p
     28                .8086
    3629
    3730_TEXT           segment public 'CODE' use16
    3831                assume cs:_TEXT
    3932
    40 
    41 ;;
    42 ; 32-bit unsigned division.
    43 ;
    44 ; @param    dx:ax   Dividend.
    45 ; @param    cx:bx   Divisor.
    46 ; @returns  dx:ax   Quotient.
    47 ;           cx:bx   Remainder.
    48 ;
    49 __U4D:
    50                 pushf
    51                 push    eax
    52                 push    edx
    53                 push    ecx
    54 
    55                 rol     eax, 16
    56                 mov     ax, dx
    57                 ror     eax, 16
    58                 xor     edx, edx
    59 
    60                 shr     ecx, 16
    61                 mov     cx, bx
    62 
    63                 div     ecx                 ; eax:edx / ecx -> eax=quotient, edx=remainder.
    64 
    65                 mov     bx, dx
    66                 pop     ecx
    67                 shr     edx, 16
    68                 mov     cx, dx
    69 
    70                 pop     edx
    71                 ror     eax, 16
    72                 mov     dx, ax
    73                 add     sp, 2
    74                 pop     ax
    75                 rol     eax, 16
    76 
    77                 popf
    78                 ret
    79 
    80 
    81 ifndef          VBOX_PC_BIOS
    82 ;;
    83 ; 32-bit signed division.
    84 ;
    85 ; @param    dx:ax   Dividend.
    86 ; @param    cx:bx   Divisor.
    87 ; @returns  dx:ax   Quotient.
    88 ;           cx:bx   Remainder.
    89 ;
    90 __I4D:
    91                 pushf
    92                 push    eax
    93                 push    edx
    94                 push    ecx
    95 
    96                 rol     eax, 16
    97                 mov     ax, dx
    98                 ror     eax, 16
    99                 xor     edx, edx
    100 
    101                 shr     ecx, 16
    102                 mov     cx, bx
    103 
    104                 idiv    ecx                 ; eax:edx / ecx -> eax=quotient, edx=remainder.
    105 
    106                 mov     bx, dx
    107                 pop     ecx
    108                 shr     edx, 16
    109                 mov     cx, dx
    110 
    111                 pop     edx
    112                 ror     eax, 16
    113                 mov     dx, ax
    114                 add     sp, 2
    115                 pop     ax
    116                 rol     eax, 16
    117 
    118                 popf
    119                 ret
    120 endif           ; VBOX_PC_BIOS
    121 
    122 
    123 ;;
    124 ; 32-bit unsigned multiplication.
    125 ;
    126 ; @param    dx:ax   Factor 1.
    127 ; @param    cx:bx   Factor 2.
    128 ; @returns  dx:ax   Result.
    129 ;
    130 __U4M:
    131                 pushf
    132                 push    eax
    133                 push    edx
    134                 push    ecx
    135 
    136                 rol     eax, 16
    137                 mov     ax, dx
    138                 ror     eax, 16
    139                 xor     edx, edx
    140 
    141                 shr     ecx, 16
    142                 mov     cx, bx
    143 
    144                 mul     ecx                 ; eax * ecx -> edx:eax
    145 
    146                 pop     ecx
    147 
    148                 pop     edx
    149                 ror     eax, 16
    150                 mov     dx, ax
    151                 add     sp, 2
    152                 pop     ax
    153                 rol     eax, 16
    154 
    155                 popf
    156                 ret
    157 
    158 
    159 ifndef          VBOX_PC_BIOS
    16033;;
    16134; 32-bit signed multiplication.
     
    16841__I4M:
    16942                pushf
     43if VBOX_BIOS_CPU ge 80386
     44                .386
    17045                push    eax
    17146                push    edx
     
    19267                pop     ax
    19368                rol     eax, 16
     69                .8086
     70else
     71                call    NeedToImplementOn8086__I4M
     72endif
    19473
    19574                popf
    196                 ret
    197 endif           ; VBOX_PC_BIOS
    198 
    199 
    200 ;;
    201 ; 64-bit left shift.
    202 ;
    203 ; @param    ax:bx:cx:dx Value.
    204 ; @param    si          Shift count.
    205 ; @returns  ax:bx:cx:dx Shifted value.
    206 ; si is zeroed
    207 ;
    208 __U8LS:
    209 
    210                 test    si, si
    211                 jz      u8ls_quit
    212 u8ls_rot:
    213                 shl     dx, 1
    214                 rcl     cx, 1
    215                 rcl     bx, 1
    216                 rcl     ax, 1
    217                 dec     si
    218                 jnz     u8ls_rot
    219 u8ls_quit:
    220                 ret
    221 
    222 
    223 ;;
    224 ; 64-bit unsigned right shift.
    225 ;
    226 ; @param    ax:bx:cx:dx Value.
    227 ; @param    si          Shift count.
    228 ; @returns  ax:bx:cx:dx Shifted value.
    229 ; si is zeroed
    230 ;
    231 __U8RS:
    232 
    233                 test    si, si
    234                 jz      u8rs_quit
    235 u8rs_rot:
    236                 shr     ax, 1
    237                 rcr     bx, 1
    238                 rcr     cx, 1
    239                 rcr     dx, 1
    240                 dec     si
    241                 jnz     u8rs_rot
    242 u8rs_quit:
    243                 ret
    244 
    245 
    246 ;;
    247 ; memset taking a far pointer.
    248 ;
    249 ; cx, es may be modified; di is preserved
    250 ;
    251 ; @returns  dx:ax unchanged.
    252 ; @param    dx:ax   Pointer to the memory.
    253 ; @param    bl      The fill value.
    254 ; @param    cx      The number of bytes to fill.
    255 ;
    256 _fmemset_:
    257                 push    di
    258 
    259                 mov     es, dx
    260                 mov     di, ax
    261                 xchg    al, bl
    262                 rep stosb
    263                 xchg    al, bl
    264 
    265                 pop     di
    266                 ret
    267 
    268 
    269 ;;
    270 ; memcpy taking far pointers.
    271 ;
    272 ; cx, es may be modified; si, di are preserved
    273 ;
    274 ; @returns  dx:ax unchanged.
    275 ; @param    dx:ax   Pointer to the destination memory.
    276 ; @param    cx:bx   Pointer to the source memory.
    277 ; @param    sp+2    The number of bytes to copy (dw).
    278 ;
    279 _fmemcpy_:
    280                 push    bp
    281                 mov     bp, sp
    282                 push    di
    283                 push    ds
    284                 push    si
    285 
    286                 mov     es, dx
    287                 mov     di, ax
    288                 mov     ds, cx
    289                 mov     si, bx
    290                 mov     cx, [bp + 4]
    291                 rep     movsb
    292 
    293                 pop     si
    294                 pop     ds
    295                 pop     di
    296                 leave
    29775                ret
    29876
  • trunk/src/VBox/Devices/BiosCommonCode/__U4D.asm

    r60406 r60484  
    2121;*******************************************************************************
    2222public          __U4D
    23 public          __U4M
    24 public          __U8LS
    25 public          __U8RS
    26 ifndef          VBOX_PC_BIOS
    27 public          __I4D
    28 public          __I4M
     23
     24                .8086
     25
     26if VBOX_BIOS_CPU lt 80386
     27extrn _DoUInt32Div:near
    2928endif
    30 public          _fmemset_
    31 public          _fmemcpy_
    3229
    33 
    34 
    35                 .386p
    3630
    3731_TEXT           segment public 'CODE' use16
     
    4943__U4D:
    5044                pushf
     45if VBOX_BIOS_CPU ge 80386
     46                .386
    5147                push    eax
    5248                push    edx
     
    7470                pop     ax
    7571                rol     eax, 16
     72                .8086
     73else
    7674
     75                ; Call C function do this.
     76                push    ds
     77                push    es
     78
     79                ;
     80                ; Convert to a C __cdecl call - not doing this in assembly.
     81                ;
     82
     83                ; Set up a frame of sorts, allocating 8 bytes for the result buffer.
     84                push    bp
     85                sub     sp, 08h
     86                mov     bp, sp
     87
     88                ; Pointer to the return buffer.
     89                push    ss
     90                push    bp
     91                add     bp, 08h                 ; Correct bp.
     92
     93                ; The divisor.
     94                push    cx
     95                push    bx
     96
     97                ; The dividend.
     98                push    dx
     99                push    ax
     100
     101                call    _DoUInt32Div
     102
     103                ; Load the reminder.
     104                mov     cx, [bp - 08h + 6]
     105                mov     bx, [bp - 08h + 4]
     106
     107                ; Load the quotient.
     108                mov     dx, [bp - 08h + 2]
     109                mov     ax, [bp - 08h]
     110
     111                mov     sp, bp
     112                pop     bp
     113                pop     es
     114                pop     ds
     115endif
    77116                popf
    78117                ret
    79 
    80 
    81 ifndef          VBOX_PC_BIOS
    82 ;;
    83 ; 32-bit signed division.
    84 ;
    85 ; @param    dx:ax   Dividend.
    86 ; @param    cx:bx   Divisor.
    87 ; @returns  dx:ax   Quotient.
    88 ;           cx:bx   Remainder.
    89 ;
    90 __I4D:
    91                 pushf
    92                 push    eax
    93                 push    edx
    94                 push    ecx
    95 
    96                 rol     eax, 16
    97                 mov     ax, dx
    98                 ror     eax, 16
    99                 xor     edx, edx
    100 
    101                 shr     ecx, 16
    102                 mov     cx, bx
    103 
    104                 idiv    ecx                 ; eax:edx / ecx -> eax=quotient, edx=remainder.
    105 
    106                 mov     bx, dx
    107                 pop     ecx
    108                 shr     edx, 16
    109                 mov     cx, dx
    110 
    111                 pop     edx
    112                 ror     eax, 16
    113                 mov     dx, ax
    114                 add     sp, 2
    115                 pop     ax
    116                 rol     eax, 16
    117 
    118                 popf
    119                 ret
    120 endif           ; VBOX_PC_BIOS
    121 
    122 
    123 ;;
    124 ; 32-bit unsigned multiplication.
    125 ;
    126 ; @param    dx:ax   Factor 1.
    127 ; @param    cx:bx   Factor 2.
    128 ; @returns  dx:ax   Result.
    129 ;
    130 __U4M:
    131                 pushf
    132                 push    eax
    133                 push    edx
    134                 push    ecx
    135 
    136                 rol     eax, 16
    137                 mov     ax, dx
    138                 ror     eax, 16
    139                 xor     edx, edx
    140 
    141                 shr     ecx, 16
    142                 mov     cx, bx
    143 
    144                 mul     ecx                 ; eax * ecx -> edx:eax
    145 
    146                 pop     ecx
    147 
    148                 pop     edx
    149                 ror     eax, 16
    150                 mov     dx, ax
    151                 add     sp, 2
    152                 pop     ax
    153                 rol     eax, 16
    154 
    155                 popf
    156                 ret
    157 
    158 
    159 ifndef          VBOX_PC_BIOS
    160 ;;
    161 ; 32-bit signed multiplication.
    162 ;
    163 ; @param    dx:ax   Factor 1.
    164 ; @param    cx:bx   Factor 2.
    165 ; @returns  dx:ax   Result.
    166 ; cx, es may be modified; di is preserved
    167 ;
    168 __I4M:
    169                 pushf
    170                 push    eax
    171                 push    edx
    172                 push    ecx
    173                 push    ebx
    174 
    175                 rol     eax, 16
    176                 mov     ax, dx
    177                 ror     eax, 16
    178                 xor     edx, edx
    179 
    180                 shr     ecx, 16
    181                 mov     cx, bx
    182 
    183                 imul    ecx                 ; eax * ecx -> edx:eax
    184 
    185                 pop     ebx
    186                 pop     ecx
    187 
    188                 pop     edx
    189                 ror     eax, 16
    190                 mov     dx, ax
    191                 add     sp, 2
    192                 pop     ax
    193                 rol     eax, 16
    194 
    195                 popf
    196                 ret
    197 endif           ; VBOX_PC_BIOS
    198 
    199 
    200 ;;
    201 ; 64-bit left shift.
    202 ;
    203 ; @param    ax:bx:cx:dx Value.
    204 ; @param    si          Shift count.
    205 ; @returns  ax:bx:cx:dx Shifted value.
    206 ; si is zeroed
    207 ;
    208 __U8LS:
    209 
    210                 test    si, si
    211                 jz      u8ls_quit
    212 u8ls_rot:
    213                 shl     dx, 1
    214                 rcl     cx, 1
    215                 rcl     bx, 1
    216                 rcl     ax, 1
    217                 dec     si
    218                 jnz     u8ls_rot
    219 u8ls_quit:
    220                 ret
    221 
    222 
    223 ;;
    224 ; 64-bit unsigned right shift.
    225 ;
    226 ; @param    ax:bx:cx:dx Value.
    227 ; @param    si          Shift count.
    228 ; @returns  ax:bx:cx:dx Shifted value.
    229 ; si is zeroed
    230 ;
    231 __U8RS:
    232 
    233                 test    si, si
    234                 jz      u8rs_quit
    235 u8rs_rot:
    236                 shr     ax, 1
    237                 rcr     bx, 1
    238                 rcr     cx, 1
    239                 rcr     dx, 1
    240                 dec     si
    241                 jnz     u8rs_rot
    242 u8rs_quit:
    243                 ret
    244 
    245 
    246 ;;
    247 ; memset taking a far pointer.
    248 ;
    249 ; cx, es may be modified; di is preserved
    250 ;
    251 ; @returns  dx:ax unchanged.
    252 ; @param    dx:ax   Pointer to the memory.
    253 ; @param    bl      The fill value.
    254 ; @param    cx      The number of bytes to fill.
    255 ;
    256 _fmemset_:
    257                 push    di
    258 
    259                 mov     es, dx
    260                 mov     di, ax
    261                 xchg    al, bl
    262                 rep stosb
    263                 xchg    al, bl
    264 
    265                 pop     di
    266                 ret
    267 
    268 
    269 ;;
    270 ; memcpy taking far pointers.
    271 ;
    272 ; cx, es may be modified; si, di are preserved
    273 ;
    274 ; @returns  dx:ax unchanged.
    275 ; @param    dx:ax   Pointer to the destination memory.
    276 ; @param    cx:bx   Pointer to the source memory.
    277 ; @param    sp+2    The number of bytes to copy (dw).
    278 ;
    279 _fmemcpy_:
    280                 push    bp
    281                 mov     bp, sp
    282                 push    di
    283                 push    ds
    284                 push    si
    285 
    286                 mov     es, dx
    287                 mov     di, ax
    288                 mov     ds, cx
    289                 mov     si, bx
    290                 mov     cx, [bp + 4]
    291                 rep     movsb
    292 
    293                 pop     si
    294                 pop     ds
    295                 pop     di
    296                 leave
    297                 ret
    298 
    299118
    300119_TEXT           ends
  • trunk/src/VBox/Devices/BiosCommonCode/__U4M.asm

    r60406 r60484  
    2020;*  Exported Symbols                                                           *
    2121;*******************************************************************************
    22 public          __U4D
    2322public          __U4M
    24 public          __U8LS
    25 public          __U8RS
    26 ifndef          VBOX_PC_BIOS
    27 public          __I4D
    28 public          __I4M
    29 endif
    30 public          _fmemset_
    31 public          _fmemcpy_
    3223
    33 
    34 
    35                 .386p
     24                .8086
    3625
    3726_TEXT           segment public 'CODE' use16
    3827                assume cs:_TEXT
    39 
    40 
    41 ;;
    42 ; 32-bit unsigned division.
    43 ;
    44 ; @param    dx:ax   Dividend.
    45 ; @param    cx:bx   Divisor.
    46 ; @returns  dx:ax   Quotient.
    47 ;           cx:bx   Remainder.
    48 ;
    49 __U4D:
    50                 pushf
    51                 push    eax
    52                 push    edx
    53                 push    ecx
    54 
    55                 rol     eax, 16
    56                 mov     ax, dx
    57                 ror     eax, 16
    58                 xor     edx, edx
    59 
    60                 shr     ecx, 16
    61                 mov     cx, bx
    62 
    63                 div     ecx                 ; eax:edx / ecx -> eax=quotient, edx=remainder.
    64 
    65                 mov     bx, dx
    66                 pop     ecx
    67                 shr     edx, 16
    68                 mov     cx, dx
    69 
    70                 pop     edx
    71                 ror     eax, 16
    72                 mov     dx, ax
    73                 add     sp, 2
    74                 pop     ax
    75                 rol     eax, 16
    76 
    77                 popf
    78                 ret
    79 
    80 
    81 ifndef          VBOX_PC_BIOS
    82 ;;
    83 ; 32-bit signed division.
    84 ;
    85 ; @param    dx:ax   Dividend.
    86 ; @param    cx:bx   Divisor.
    87 ; @returns  dx:ax   Quotient.
    88 ;           cx:bx   Remainder.
    89 ;
    90 __I4D:
    91                 pushf
    92                 push    eax
    93                 push    edx
    94                 push    ecx
    95 
    96                 rol     eax, 16
    97                 mov     ax, dx
    98                 ror     eax, 16
    99                 xor     edx, edx
    100 
    101                 shr     ecx, 16
    102                 mov     cx, bx
    103 
    104                 idiv    ecx                 ; eax:edx / ecx -> eax=quotient, edx=remainder.
    105 
    106                 mov     bx, dx
    107                 pop     ecx
    108                 shr     edx, 16
    109                 mov     cx, dx
    110 
    111                 pop     edx
    112                 ror     eax, 16
    113                 mov     dx, ax
    114                 add     sp, 2
    115                 pop     ax
    116                 rol     eax, 16
    117 
    118                 popf
    119                 ret
    120 endif           ; VBOX_PC_BIOS
    121 
    12228
    12329;;
     
    13036__U4M:
    13137                pushf
     38if VBOX_BIOS_CPU ge 80386
     39                .386
    13240                push    eax
    13341                push    edx
     
    15260                pop     ax
    15361                rol     eax, 16
     62                .8086
    15463
    155                 popf
    156                 ret
     64else
     65                push    bp
     66                mov     bp, sp
     67                push    si              ; high result
     68                push    di              ; low result
    15769
     70                ;
     71                ;        dx:ax * cx:bx =
     72                ;-----------------------
     73                ;        ax*bx
     74                ; +   dx*bx             ; only lower 16 bits relevant.
     75                ; +   ax*cx             ; ditto
     76                ; +dx*cx                ; not relevant
     77                ; -------------
     78                ; =      dx:ax
     79                ;
    15880
    159 ifndef          VBOX_PC_BIOS
    160 ;;
    161 ; 32-bit signed multiplication.
    162 ;
    163 ; @param    dx:ax   Factor 1.
    164 ; @param    cx:bx   Factor 2.
    165 ; @returns  dx:ax   Result.
    166 ; cx, es may be modified; di is preserved
    167 ;
    168 __I4M:
    169                 pushf
    170                 push    eax
    171                 push    edx
    172                 push    ecx
    173                 push    ebx
     81                push    ax              ; stash the low factor 1 part for the 3rd multiplication.
     82                mov     di, dx          ; stash the high factor 1 part for the 2nd multiplication.
    17483
    175                 rol     eax, 16
    176                 mov     ax, dx
    177                 ror     eax, 16
    178                 xor     edx, edx
     84                ; multiply the two low factor "digits": ax * bx
     85                mul     bx
     86                mov     si, dx
     87                xchg    di, ax          ; save low result and loads high factor 1 into ax for the next step
    17988
    180                 shr     ecx, 16
    181                 mov     cx, bx
     89                ; Multiply the low right "digit" by the high left one and add it to the high result part
     90                mul     bx
     91                add     si, ax
    18292
    183                 imul    ecx                 ; eax * ecx -> edx:eax
     93                ; Multiply the high right "digit" by the low left on and add it ot the high result part.
     94                pop     ax
     95                mul     cx
     96                add     si, ax
    18497
    185                 pop     ebx
    186                 pop     ecx
    187 
    188                 pop     edx
    189                 ror     eax, 16
    190                 mov     dx, ax
    191                 add     sp, 2
    192                 pop     ax
    193                 rol     eax, 16
    194 
    195                 popf
    196                 ret
    197 endif           ; VBOX_PC_BIOS
    198 
    199 
    200 ;;
    201 ; 64-bit left shift.
    202 ;
    203 ; @param    ax:bx:cx:dx Value.
    204 ; @param    si          Shift count.
    205 ; @returns  ax:bx:cx:dx Shifted value.
    206 ; si is zeroed
    207 ;
    208 __U8LS:
    209 
    210                 test    si, si
    211                 jz      u8ls_quit
    212 u8ls_rot:
    213                 shl     dx, 1
    214                 rcl     cx, 1
    215                 rcl     bx, 1
    216                 rcl     ax, 1
    217                 dec     si
    218                 jnz     u8ls_rot
    219 u8ls_quit:
    220                 ret
    221 
    222 
    223 ;;
    224 ; 64-bit unsigned right shift.
    225 ;
    226 ; @param    ax:bx:cx:dx Value.
    227 ; @param    si          Shift count.
    228 ; @returns  ax:bx:cx:dx Shifted value.
    229 ; si is zeroed
    230 ;
    231 __U8RS:
    232 
    233                 test    si, si
    234                 jz      u8rs_quit
    235 u8rs_rot:
    236                 shr     ax, 1
    237                 rcr     bx, 1
    238                 rcr     cx, 1
    239                 rcr     dx, 1
    240                 dec     si
    241                 jnz     u8rs_rot
    242 u8rs_quit:
    243                 ret
    244 
    245 
    246 ;;
    247 ; memset taking a far pointer.
    248 ;
    249 ; cx, es may be modified; di is preserved
    250 ;
    251 ; @returns  dx:ax unchanged.
    252 ; @param    dx:ax   Pointer to the memory.
    253 ; @param    bl      The fill value.
    254 ; @param    cx      The number of bytes to fill.
    255 ;
    256 _fmemset_:
    257                 push    di
    258 
    259                 mov     es, dx
    260                 mov     di, ax
    261                 xchg    al, bl
    262                 rep stosb
    263                 xchg    al, bl
     98                ; Load the result.
     99                mov     dx, si
     100                mov     ax, di
    264101
    265102                pop     di
    266                 ret
    267 
    268 
    269 ;;
    270 ; memcpy taking far pointers.
    271 ;
    272 ; cx, es may be modified; si, di are preserved
    273 ;
    274 ; @returns  dx:ax unchanged.
    275 ; @param    dx:ax   Pointer to the destination memory.
    276 ; @param    cx:bx   Pointer to the source memory.
    277 ; @param    sp+2    The number of bytes to copy (dw).
    278 ;
    279 _fmemcpy_:
    280                 push    bp
    281                 mov     bp, sp
    282                 push    di
    283                 push    ds
    284                 push    si
    285 
    286                 mov     es, dx
    287                 mov     di, ax
    288                 mov     ds, cx
    289                 mov     si, bx
    290                 mov     cx, [bp + 4]
    291                 rep     movsb
    292 
    293103                pop     si
    294                 pop     ds
    295                 pop     di
    296                 leave
     104endif
     105                popf
    297106                ret
    298107
  • trunk/src/VBox/Devices/BiosCommonCode/__U8LS.asm

    r60406 r60484  
    2020;*  Exported Symbols                                                           *
    2121;*******************************************************************************
    22 public          __U4D
    23 public          __U4M
    2422public          __U8LS
    25 public          __U8RS
    26 ifndef          VBOX_PC_BIOS
    27 public          __I4D
    28 public          __I4M
    29 endif
    30 public          _fmemset_
    31 public          _fmemcpy_
    3223
    3324
    34 
    35                 .386p
     25                .8086
    3626
    3727_TEXT           segment public 'CODE' use16
    3828                assume cs:_TEXT
    39 
    40 
    41 ;;
    42 ; 32-bit unsigned division.
    43 ;
    44 ; @param    dx:ax   Dividend.
    45 ; @param    cx:bx   Divisor.
    46 ; @returns  dx:ax   Quotient.
    47 ;           cx:bx   Remainder.
    48 ;
    49 __U4D:
    50                 pushf
    51                 push    eax
    52                 push    edx
    53                 push    ecx
    54 
    55                 rol     eax, 16
    56                 mov     ax, dx
    57                 ror     eax, 16
    58                 xor     edx, edx
    59 
    60                 shr     ecx, 16
    61                 mov     cx, bx
    62 
    63                 div     ecx                 ; eax:edx / ecx -> eax=quotient, edx=remainder.
    64 
    65                 mov     bx, dx
    66                 pop     ecx
    67                 shr     edx, 16
    68                 mov     cx, dx
    69 
    70                 pop     edx
    71                 ror     eax, 16
    72                 mov     dx, ax
    73                 add     sp, 2
    74                 pop     ax
    75                 rol     eax, 16
    76 
    77                 popf
    78                 ret
    79 
    80 
    81 ifndef          VBOX_PC_BIOS
    82 ;;
    83 ; 32-bit signed division.
    84 ;
    85 ; @param    dx:ax   Dividend.
    86 ; @param    cx:bx   Divisor.
    87 ; @returns  dx:ax   Quotient.
    88 ;           cx:bx   Remainder.
    89 ;
    90 __I4D:
    91                 pushf
    92                 push    eax
    93                 push    edx
    94                 push    ecx
    95 
    96                 rol     eax, 16
    97                 mov     ax, dx
    98                 ror     eax, 16
    99                 xor     edx, edx
    100 
    101                 shr     ecx, 16
    102                 mov     cx, bx
    103 
    104                 idiv    ecx                 ; eax:edx / ecx -> eax=quotient, edx=remainder.
    105 
    106                 mov     bx, dx
    107                 pop     ecx
    108                 shr     edx, 16
    109                 mov     cx, dx
    110 
    111                 pop     edx
    112                 ror     eax, 16
    113                 mov     dx, ax
    114                 add     sp, 2
    115                 pop     ax
    116                 rol     eax, 16
    117 
    118                 popf
    119                 ret
    120 endif           ; VBOX_PC_BIOS
    121 
    122 
    123 ;;
    124 ; 32-bit unsigned multiplication.
    125 ;
    126 ; @param    dx:ax   Factor 1.
    127 ; @param    cx:bx   Factor 2.
    128 ; @returns  dx:ax   Result.
    129 ;
    130 __U4M:
    131                 pushf
    132                 push    eax
    133                 push    edx
    134                 push    ecx
    135 
    136                 rol     eax, 16
    137                 mov     ax, dx
    138                 ror     eax, 16
    139                 xor     edx, edx
    140 
    141                 shr     ecx, 16
    142                 mov     cx, bx
    143 
    144                 mul     ecx                 ; eax * ecx -> edx:eax
    145 
    146                 pop     ecx
    147 
    148                 pop     edx
    149                 ror     eax, 16
    150                 mov     dx, ax
    151                 add     sp, 2
    152                 pop     ax
    153                 rol     eax, 16
    154 
    155                 popf
    156                 ret
    157 
    158 
    159 ifndef          VBOX_PC_BIOS
    160 ;;
    161 ; 32-bit signed multiplication.
    162 ;
    163 ; @param    dx:ax   Factor 1.
    164 ; @param    cx:bx   Factor 2.
    165 ; @returns  dx:ax   Result.
    166 ; cx, es may be modified; di is preserved
    167 ;
    168 __I4M:
    169                 pushf
    170                 push    eax
    171                 push    edx
    172                 push    ecx
    173                 push    ebx
    174 
    175                 rol     eax, 16
    176                 mov     ax, dx
    177                 ror     eax, 16
    178                 xor     edx, edx
    179 
    180                 shr     ecx, 16
    181                 mov     cx, bx
    182 
    183                 imul    ecx                 ; eax * ecx -> edx:eax
    184 
    185                 pop     ebx
    186                 pop     ecx
    187 
    188                 pop     edx
    189                 ror     eax, 16
    190                 mov     dx, ax
    191                 add     sp, 2
    192                 pop     ax
    193                 rol     eax, 16
    194 
    195                 popf
    196                 ret
    197 endif           ; VBOX_PC_BIOS
    198 
    19929
    20030;;
     
    22151
    22252
    223 ;;
    224 ; 64-bit unsigned right shift.
    225 ;
    226 ; @param    ax:bx:cx:dx Value.
    227 ; @param    si          Shift count.
    228 ; @returns  ax:bx:cx:dx Shifted value.
    229 ; si is zeroed
    230 ;
    231 __U8RS:
    232 
    233                 test    si, si
    234                 jz      u8rs_quit
    235 u8rs_rot:
    236                 shr     ax, 1
    237                 rcr     bx, 1
    238                 rcr     cx, 1
    239                 rcr     dx, 1
    240                 dec     si
    241                 jnz     u8rs_rot
    242 u8rs_quit:
    243                 ret
    244 
    245 
    246 ;;
    247 ; memset taking a far pointer.
    248 ;
    249 ; cx, es may be modified; di is preserved
    250 ;
    251 ; @returns  dx:ax unchanged.
    252 ; @param    dx:ax   Pointer to the memory.
    253 ; @param    bl      The fill value.
    254 ; @param    cx      The number of bytes to fill.
    255 ;
    256 _fmemset_:
    257                 push    di
    258 
    259                 mov     es, dx
    260                 mov     di, ax
    261                 xchg    al, bl
    262                 rep stosb
    263                 xchg    al, bl
    264 
    265                 pop     di
    266                 ret
    267 
    268 
    269 ;;
    270 ; memcpy taking far pointers.
    271 ;
    272 ; cx, es may be modified; si, di are preserved
    273 ;
    274 ; @returns  dx:ax unchanged.
    275 ; @param    dx:ax   Pointer to the destination memory.
    276 ; @param    cx:bx   Pointer to the source memory.
    277 ; @param    sp+2    The number of bytes to copy (dw).
    278 ;
    279 _fmemcpy_:
    280                 push    bp
    281                 mov     bp, sp
    282                 push    di
    283                 push    ds
    284                 push    si
    285 
    286                 mov     es, dx
    287                 mov     di, ax
    288                 mov     ds, cx
    289                 mov     si, bx
    290                 mov     cx, [bp + 4]
    291                 rep     movsb
    292 
    293                 pop     si
    294                 pop     ds
    295                 pop     di
    296                 leave
    297                 ret
    298 
    299 
    30053_TEXT           ends
    30154                end
  • trunk/src/VBox/Devices/BiosCommonCode/__U8RS.asm

    r60406 r60484  
    2020;*  Exported Symbols                                                           *
    2121;*******************************************************************************
    22 public          __U4D
    23 public          __U4M
    24 public          __U8LS
    2522public          __U8RS
    26 ifndef          VBOX_PC_BIOS
    27 public          __I4D
    28 public          __I4M
    29 endif
    30 public          _fmemset_
    31 public          _fmemcpy_
    3223
    3324
    34 
    35                 .386p
     25                .8086
    3626
    3727_TEXT           segment public 'CODE' use16
    3828                assume cs:_TEXT
    39 
    40 
    41 ;;
    42 ; 32-bit unsigned division.
    43 ;
    44 ; @param    dx:ax   Dividend.
    45 ; @param    cx:bx   Divisor.
    46 ; @returns  dx:ax   Quotient.
    47 ;           cx:bx   Remainder.
    48 ;
    49 __U4D:
    50                 pushf
    51                 push    eax
    52                 push    edx
    53                 push    ecx
    54 
    55                 rol     eax, 16
    56                 mov     ax, dx
    57                 ror     eax, 16
    58                 xor     edx, edx
    59 
    60                 shr     ecx, 16
    61                 mov     cx, bx
    62 
    63                 div     ecx                 ; eax:edx / ecx -> eax=quotient, edx=remainder.
    64 
    65                 mov     bx, dx
    66                 pop     ecx
    67                 shr     edx, 16
    68                 mov     cx, dx
    69 
    70                 pop     edx
    71                 ror     eax, 16
    72                 mov     dx, ax
    73                 add     sp, 2
    74                 pop     ax
    75                 rol     eax, 16
    76 
    77                 popf
    78                 ret
    79 
    80 
    81 ifndef          VBOX_PC_BIOS
    82 ;;
    83 ; 32-bit signed division.
    84 ;
    85 ; @param    dx:ax   Dividend.
    86 ; @param    cx:bx   Divisor.
    87 ; @returns  dx:ax   Quotient.
    88 ;           cx:bx   Remainder.
    89 ;
    90 __I4D:
    91                 pushf
    92                 push    eax
    93                 push    edx
    94                 push    ecx
    95 
    96                 rol     eax, 16
    97                 mov     ax, dx
    98                 ror     eax, 16
    99                 xor     edx, edx
    100 
    101                 shr     ecx, 16
    102                 mov     cx, bx
    103 
    104                 idiv    ecx                 ; eax:edx / ecx -> eax=quotient, edx=remainder.
    105 
    106                 mov     bx, dx
    107                 pop     ecx
    108                 shr     edx, 16
    109                 mov     cx, dx
    110 
    111                 pop     edx
    112                 ror     eax, 16
    113                 mov     dx, ax
    114                 add     sp, 2
    115                 pop     ax
    116                 rol     eax, 16
    117 
    118                 popf
    119                 ret
    120 endif           ; VBOX_PC_BIOS
    121 
    122 
    123 ;;
    124 ; 32-bit unsigned multiplication.
    125 ;
    126 ; @param    dx:ax   Factor 1.
    127 ; @param    cx:bx   Factor 2.
    128 ; @returns  dx:ax   Result.
    129 ;
    130 __U4M:
    131                 pushf
    132                 push    eax
    133                 push    edx
    134                 push    ecx
    135 
    136                 rol     eax, 16
    137                 mov     ax, dx
    138                 ror     eax, 16
    139                 xor     edx, edx
    140 
    141                 shr     ecx, 16
    142                 mov     cx, bx
    143 
    144                 mul     ecx                 ; eax * ecx -> edx:eax
    145 
    146                 pop     ecx
    147 
    148                 pop     edx
    149                 ror     eax, 16
    150                 mov     dx, ax
    151                 add     sp, 2
    152                 pop     ax
    153                 rol     eax, 16
    154 
    155                 popf
    156                 ret
    157 
    158 
    159 ifndef          VBOX_PC_BIOS
    160 ;;
    161 ; 32-bit signed multiplication.
    162 ;
    163 ; @param    dx:ax   Factor 1.
    164 ; @param    cx:bx   Factor 2.
    165 ; @returns  dx:ax   Result.
    166 ; cx, es may be modified; di is preserved
    167 ;
    168 __I4M:
    169                 pushf
    170                 push    eax
    171                 push    edx
    172                 push    ecx
    173                 push    ebx
    174 
    175                 rol     eax, 16
    176                 mov     ax, dx
    177                 ror     eax, 16
    178                 xor     edx, edx
    179 
    180                 shr     ecx, 16
    181                 mov     cx, bx
    182 
    183                 imul    ecx                 ; eax * ecx -> edx:eax
    184 
    185                 pop     ebx
    186                 pop     ecx
    187 
    188                 pop     edx
    189                 ror     eax, 16
    190                 mov     dx, ax
    191                 add     sp, 2
    192                 pop     ax
    193                 rol     eax, 16
    194 
    195                 popf
    196                 ret
    197 endif           ; VBOX_PC_BIOS
    198 
    199 
    200 ;;
    201 ; 64-bit left shift.
    202 ;
    203 ; @param    ax:bx:cx:dx Value.
    204 ; @param    si          Shift count.
    205 ; @returns  ax:bx:cx:dx Shifted value.
    206 ; si is zeroed
    207 ;
    208 __U8LS:
    209 
    210                 test    si, si
    211                 jz      u8ls_quit
    212 u8ls_rot:
    213                 shl     dx, 1
    214                 rcl     cx, 1
    215                 rcl     bx, 1
    216                 rcl     ax, 1
    217                 dec     si
    218                 jnz     u8ls_rot
    219 u8ls_quit:
    220                 ret
    221 
    22229
    22330;;
     
    24350                ret
    24451
    245 
    246 ;;
    247 ; memset taking a far pointer.
    248 ;
    249 ; cx, es may be modified; di is preserved
    250 ;
    251 ; @returns  dx:ax unchanged.
    252 ; @param    dx:ax   Pointer to the memory.
    253 ; @param    bl      The fill value.
    254 ; @param    cx      The number of bytes to fill.
    255 ;
    256 _fmemset_:
    257                 push    di
    258 
    259                 mov     es, dx
    260                 mov     di, ax
    261                 xchg    al, bl
    262                 rep stosb
    263                 xchg    al, bl
    264 
    265                 pop     di
    266                 ret
    267 
    268 
    269 ;;
    270 ; memcpy taking far pointers.
    271 ;
    272 ; cx, es may be modified; si, di are preserved
    273 ;
    274 ; @returns  dx:ax unchanged.
    275 ; @param    dx:ax   Pointer to the destination memory.
    276 ; @param    cx:bx   Pointer to the source memory.
    277 ; @param    sp+2    The number of bytes to copy (dw).
    278 ;
    279 _fmemcpy_:
    280                 push    bp
    281                 mov     bp, sp
    282                 push    di
    283                 push    ds
    284                 push    si
    285 
    286                 mov     es, dx
    287                 mov     di, ax
    288                 mov     ds, cx
    289                 mov     si, bx
    290                 mov     cx, [bp + 4]
    291                 rep     movsb
    292 
    293                 pop     si
    294                 pop     ds
    295                 pop     di
    296                 leave
    297                 ret
    298 
    299 
    30052_TEXT           ends
    30153                end
  • trunk/src/VBox/Devices/BiosCommonCode/fmemcpy.asm

    r60406 r60484  
    2020;*  Exported Symbols                                                           *
    2121;*******************************************************************************
    22 public          __U4D
    23 public          __U4M
    24 public          __U8LS
    25 public          __U8RS
    26 ifndef          VBOX_PC_BIOS
    27 public          __I4D
    28 public          __I4M
    29 endif
    30 public          _fmemset_
    3122public          _fmemcpy_
    3223
    3324
    34 
    35                 .386p
     25                .8086
    3626
    3727_TEXT           segment public 'CODE' use16
    3828                assume cs:_TEXT
    39 
    40 
    41 ;;
    42 ; 32-bit unsigned division.
    43 ;
    44 ; @param    dx:ax   Dividend.
    45 ; @param    cx:bx   Divisor.
    46 ; @returns  dx:ax   Quotient.
    47 ;           cx:bx   Remainder.
    48 ;
    49 __U4D:
    50                 pushf
    51                 push    eax
    52                 push    edx
    53                 push    ecx
    54 
    55                 rol     eax, 16
    56                 mov     ax, dx
    57                 ror     eax, 16
    58                 xor     edx, edx
    59 
    60                 shr     ecx, 16
    61                 mov     cx, bx
    62 
    63                 div     ecx                 ; eax:edx / ecx -> eax=quotient, edx=remainder.
    64 
    65                 mov     bx, dx
    66                 pop     ecx
    67                 shr     edx, 16
    68                 mov     cx, dx
    69 
    70                 pop     edx
    71                 ror     eax, 16
    72                 mov     dx, ax
    73                 add     sp, 2
    74                 pop     ax
    75                 rol     eax, 16
    76 
    77                 popf
    78                 ret
    79 
    80 
    81 ifndef          VBOX_PC_BIOS
    82 ;;
    83 ; 32-bit signed division.
    84 ;
    85 ; @param    dx:ax   Dividend.
    86 ; @param    cx:bx   Divisor.
    87 ; @returns  dx:ax   Quotient.
    88 ;           cx:bx   Remainder.
    89 ;
    90 __I4D:
    91                 pushf
    92                 push    eax
    93                 push    edx
    94                 push    ecx
    95 
    96                 rol     eax, 16
    97                 mov     ax, dx
    98                 ror     eax, 16
    99                 xor     edx, edx
    100 
    101                 shr     ecx, 16
    102                 mov     cx, bx
    103 
    104                 idiv    ecx                 ; eax:edx / ecx -> eax=quotient, edx=remainder.
    105 
    106                 mov     bx, dx
    107                 pop     ecx
    108                 shr     edx, 16
    109                 mov     cx, dx
    110 
    111                 pop     edx
    112                 ror     eax, 16
    113                 mov     dx, ax
    114                 add     sp, 2
    115                 pop     ax
    116                 rol     eax, 16
    117 
    118                 popf
    119                 ret
    120 endif           ; VBOX_PC_BIOS
    121 
    122 
    123 ;;
    124 ; 32-bit unsigned multiplication.
    125 ;
    126 ; @param    dx:ax   Factor 1.
    127 ; @param    cx:bx   Factor 2.
    128 ; @returns  dx:ax   Result.
    129 ;
    130 __U4M:
    131                 pushf
    132                 push    eax
    133                 push    edx
    134                 push    ecx
    135 
    136                 rol     eax, 16
    137                 mov     ax, dx
    138                 ror     eax, 16
    139                 xor     edx, edx
    140 
    141                 shr     ecx, 16
    142                 mov     cx, bx
    143 
    144                 mul     ecx                 ; eax * ecx -> edx:eax
    145 
    146                 pop     ecx
    147 
    148                 pop     edx
    149                 ror     eax, 16
    150                 mov     dx, ax
    151                 add     sp, 2
    152                 pop     ax
    153                 rol     eax, 16
    154 
    155                 popf
    156                 ret
    157 
    158 
    159 ifndef          VBOX_PC_BIOS
    160 ;;
    161 ; 32-bit signed multiplication.
    162 ;
    163 ; @param    dx:ax   Factor 1.
    164 ; @param    cx:bx   Factor 2.
    165 ; @returns  dx:ax   Result.
    166 ; cx, es may be modified; di is preserved
    167 ;
    168 __I4M:
    169                 pushf
    170                 push    eax
    171                 push    edx
    172                 push    ecx
    173                 push    ebx
    174 
    175                 rol     eax, 16
    176                 mov     ax, dx
    177                 ror     eax, 16
    178                 xor     edx, edx
    179 
    180                 shr     ecx, 16
    181                 mov     cx, bx
    182 
    183                 imul    ecx                 ; eax * ecx -> edx:eax
    184 
    185                 pop     ebx
    186                 pop     ecx
    187 
    188                 pop     edx
    189                 ror     eax, 16
    190                 mov     dx, ax
    191                 add     sp, 2
    192                 pop     ax
    193                 rol     eax, 16
    194 
    195                 popf
    196                 ret
    197 endif           ; VBOX_PC_BIOS
    198 
    199 
    200 ;;
    201 ; 64-bit left shift.
    202 ;
    203 ; @param    ax:bx:cx:dx Value.
    204 ; @param    si          Shift count.
    205 ; @returns  ax:bx:cx:dx Shifted value.
    206 ; si is zeroed
    207 ;
    208 __U8LS:
    209 
    210                 test    si, si
    211                 jz      u8ls_quit
    212 u8ls_rot:
    213                 shl     dx, 1
    214                 rcl     cx, 1
    215                 rcl     bx, 1
    216                 rcl     ax, 1
    217                 dec     si
    218                 jnz     u8ls_rot
    219 u8ls_quit:
    220                 ret
    221 
    222 
    223 ;;
    224 ; 64-bit unsigned right shift.
    225 ;
    226 ; @param    ax:bx:cx:dx Value.
    227 ; @param    si          Shift count.
    228 ; @returns  ax:bx:cx:dx Shifted value.
    229 ; si is zeroed
    230 ;
    231 __U8RS:
    232 
    233                 test    si, si
    234                 jz      u8rs_quit
    235 u8rs_rot:
    236                 shr     ax, 1
    237                 rcr     bx, 1
    238                 rcr     cx, 1
    239                 rcr     dx, 1
    240                 dec     si
    241                 jnz     u8rs_rot
    242 u8rs_quit:
    243                 ret
    244 
    245 
    246 ;;
    247 ; memset taking a far pointer.
    248 ;
    249 ; cx, es may be modified; di is preserved
    250 ;
    251 ; @returns  dx:ax unchanged.
    252 ; @param    dx:ax   Pointer to the memory.
    253 ; @param    bl      The fill value.
    254 ; @param    cx      The number of bytes to fill.
    255 ;
    256 _fmemset_:
    257                 push    di
    258 
    259                 mov     es, dx
    260                 mov     di, ax
    261                 xchg    al, bl
    262                 rep stosb
    263                 xchg    al, bl
    264 
    265                 pop     di
    266                 ret
    26729
    26830
     
    29456                pop     ds
    29557                pop     di
    296                 leave
     58                mov     sp, bp
     59                pop     bp
    29760                ret
    29861
  • trunk/src/VBox/Devices/BiosCommonCode/fmemset.asm

    r60406 r60484  
    2020;*  Exported Symbols                                                           *
    2121;*******************************************************************************
    22 public          __U4D
    23 public          __U4M
    24 public          __U8LS
    25 public          __U8RS
    26 ifndef          VBOX_PC_BIOS
    27 public          __I4D
    28 public          __I4M
    29 endif
    3022public          _fmemset_
    31 public          _fmemcpy_
    3223
    3324
    34 
    35                 .386p
     25                .8086
    3626
    3727_TEXT           segment public 'CODE' use16
    3828                assume cs:_TEXT
    39 
    40 
    41 ;;
    42 ; 32-bit unsigned division.
    43 ;
    44 ; @param    dx:ax   Dividend.
    45 ; @param    cx:bx   Divisor.
    46 ; @returns  dx:ax   Quotient.
    47 ;           cx:bx   Remainder.
    48 ;
    49 __U4D:
    50                 pushf
    51                 push    eax
    52                 push    edx
    53                 push    ecx
    54 
    55                 rol     eax, 16
    56                 mov     ax, dx
    57                 ror     eax, 16
    58                 xor     edx, edx
    59 
    60                 shr     ecx, 16
    61                 mov     cx, bx
    62 
    63                 div     ecx                 ; eax:edx / ecx -> eax=quotient, edx=remainder.
    64 
    65                 mov     bx, dx
    66                 pop     ecx
    67                 shr     edx, 16
    68                 mov     cx, dx
    69 
    70                 pop     edx
    71                 ror     eax, 16
    72                 mov     dx, ax
    73                 add     sp, 2
    74                 pop     ax
    75                 rol     eax, 16
    76 
    77                 popf
    78                 ret
    79 
    80 
    81 ifndef          VBOX_PC_BIOS
    82 ;;
    83 ; 32-bit signed division.
    84 ;
    85 ; @param    dx:ax   Dividend.
    86 ; @param    cx:bx   Divisor.
    87 ; @returns  dx:ax   Quotient.
    88 ;           cx:bx   Remainder.
    89 ;
    90 __I4D:
    91                 pushf
    92                 push    eax
    93                 push    edx
    94                 push    ecx
    95 
    96                 rol     eax, 16
    97                 mov     ax, dx
    98                 ror     eax, 16
    99                 xor     edx, edx
    100 
    101                 shr     ecx, 16
    102                 mov     cx, bx
    103 
    104                 idiv    ecx                 ; eax:edx / ecx -> eax=quotient, edx=remainder.
    105 
    106                 mov     bx, dx
    107                 pop     ecx
    108                 shr     edx, 16
    109                 mov     cx, dx
    110 
    111                 pop     edx
    112                 ror     eax, 16
    113                 mov     dx, ax
    114                 add     sp, 2
    115                 pop     ax
    116                 rol     eax, 16
    117 
    118                 popf
    119                 ret
    120 endif           ; VBOX_PC_BIOS
    121 
    122 
    123 ;;
    124 ; 32-bit unsigned multiplication.
    125 ;
    126 ; @param    dx:ax   Factor 1.
    127 ; @param    cx:bx   Factor 2.
    128 ; @returns  dx:ax   Result.
    129 ;
    130 __U4M:
    131                 pushf
    132                 push    eax
    133                 push    edx
    134                 push    ecx
    135 
    136                 rol     eax, 16
    137                 mov     ax, dx
    138                 ror     eax, 16
    139                 xor     edx, edx
    140 
    141                 shr     ecx, 16
    142                 mov     cx, bx
    143 
    144                 mul     ecx                 ; eax * ecx -> edx:eax
    145 
    146                 pop     ecx
    147 
    148                 pop     edx
    149                 ror     eax, 16
    150                 mov     dx, ax
    151                 add     sp, 2
    152                 pop     ax
    153                 rol     eax, 16
    154 
    155                 popf
    156                 ret
    157 
    158 
    159 ifndef          VBOX_PC_BIOS
    160 ;;
    161 ; 32-bit signed multiplication.
    162 ;
    163 ; @param    dx:ax   Factor 1.
    164 ; @param    cx:bx   Factor 2.
    165 ; @returns  dx:ax   Result.
    166 ; cx, es may be modified; di is preserved
    167 ;
    168 __I4M:
    169                 pushf
    170                 push    eax
    171                 push    edx
    172                 push    ecx
    173                 push    ebx
    174 
    175                 rol     eax, 16
    176                 mov     ax, dx
    177                 ror     eax, 16
    178                 xor     edx, edx
    179 
    180                 shr     ecx, 16
    181                 mov     cx, bx
    182 
    183                 imul    ecx                 ; eax * ecx -> edx:eax
    184 
    185                 pop     ebx
    186                 pop     ecx
    187 
    188                 pop     edx
    189                 ror     eax, 16
    190                 mov     dx, ax
    191                 add     sp, 2
    192                 pop     ax
    193                 rol     eax, 16
    194 
    195                 popf
    196                 ret
    197 endif           ; VBOX_PC_BIOS
    198 
    199 
    200 ;;
    201 ; 64-bit left shift.
    202 ;
    203 ; @param    ax:bx:cx:dx Value.
    204 ; @param    si          Shift count.
    205 ; @returns  ax:bx:cx:dx Shifted value.
    206 ; si is zeroed
    207 ;
    208 __U8LS:
    209 
    210                 test    si, si
    211                 jz      u8ls_quit
    212 u8ls_rot:
    213                 shl     dx, 1
    214                 rcl     cx, 1
    215                 rcl     bx, 1
    216                 rcl     ax, 1
    217                 dec     si
    218                 jnz     u8ls_rot
    219 u8ls_quit:
    220                 ret
    221 
    222 
    223 ;;
    224 ; 64-bit unsigned right shift.
    225 ;
    226 ; @param    ax:bx:cx:dx Value.
    227 ; @param    si          Shift count.
    228 ; @returns  ax:bx:cx:dx Shifted value.
    229 ; si is zeroed
    230 ;
    231 __U8RS:
    232 
    233                 test    si, si
    234                 jz      u8rs_quit
    235 u8rs_rot:
    236                 shr     ax, 1
    237                 rcr     bx, 1
    238                 rcr     cx, 1
    239                 rcr     dx, 1
    240                 dec     si
    241                 jnz     u8rs_rot
    242 u8rs_quit:
    243                 ret
    24429
    24530
     
    26651                ret
    26752
    268 
    269 ;;
    270 ; memcpy taking far pointers.
    271 ;
    272 ; cx, es may be modified; si, di are preserved
    273 ;
    274 ; @returns  dx:ax unchanged.
    275 ; @param    dx:ax   Pointer to the destination memory.
    276 ; @param    cx:bx   Pointer to the source memory.
    277 ; @param    sp+2    The number of bytes to copy (dw).
    278 ;
    279 _fmemcpy_:
    280                 push    bp
    281                 mov     bp, sp
    282                 push    di
    283                 push    ds
    284                 push    si
    285 
    286                 mov     es, dx
    287                 mov     di, ax
    288                 mov     ds, cx
    289                 mov     si, bx
    290                 mov     cx, [bp + 4]
    291                 rep     movsb
    292 
    293                 pop     si
    294                 pop     ds
    295                 pop     di
    296                 leave
    297                 ret
    298 
    299 
    30053_TEXT           ends
    30154                end
  • trunk/src/VBox/Devices/PC/BIOS/Makefile.kmk

    r60441 r60484  
    6969        pciutil.c \
    7070        vds.c \
    71         ../../BiosCommonCode/support.asm \
     71        ../../BiosCommonCode/__U4M.asm \
     72        ../../BiosCommonCode/__U4D.asm \
     73        ../../BiosCommonCode/__U8RS.asm \
     74        ../../BiosCommonCode/__U8LS.asm \
     75        ../../BiosCommonCode/fmemset.asm \
     76        ../../BiosCommonCode/fmemcpy.asm \
    7277        pcibio32.asm \
    7378        apm_pm.asm \
     
    8287       pci32.c
    8388
     89 ../../BiosCommonCode/DoUInt32Div.c_CFLAGS = -mc # asm.h and uint32.h both require far data pointers by default.
     90
    8491 MISCBINS += VBoxPcBios286
    8592 VBoxPcBios286_EXTENDS = VBoxPcBios386
    8693 VBoxPcBios286_CFLAGS  = -2
    8794 VBoxPcBios286_DEFS    = $(filter-out VBOX_BIOS_CPU=80386,$(VBoxPcBios386_DEFS)) VBOX_BIOS_CPU=80286
     95 VBoxPcBios286_SOURCES = $(VBoxPcBios386_SOURCES) \
     96        ../../BiosCommonCode/DoUInt32Div.c \
     97       ../../BiosCommonCode/ASMBitLastSetU16.asm
    8898
    8999 MISCBINS += VBoxPcBios8086
     
    91101 VBoxPcBios8086_CFLAGS  = -0
    92102 VBoxPcBios8086_DEFS    = $(filter-out VBOX_BIOS_CPU=80386,$(VBoxPcBios386_DEFS)) VBOX_BIOS_CPU=8086
     103 VBoxPcBios8086_SOURCES = $(VBoxPcBios386_SOURCES) \
     104        ../../BiosCommonCode/DoUInt32Div.c \
     105       ../../BiosCommonCode/ASMBitLastSetU16.asm
    93106
    94107
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette