[41604] | 1 | ; $Id: __U4M.asm 98103 2023-01-17 14:15:46Z vboxsync $
|
---|
| 2 | ;; @file
|
---|
| 3 | ; Compiler support routines.
|
---|
| 4 | ;
|
---|
| 5 |
|
---|
| 6 | ;
|
---|
[98103] | 7 | ; Copyright (C) 2012-2023 Oracle and/or its affiliates.
|
---|
[41604] | 8 | ;
|
---|
[96407] | 9 | ; This file is part of VirtualBox base platform packages, as
|
---|
| 10 | ; available from https://www.virtualbox.org.
|
---|
[41604] | 11 | ;
|
---|
[96407] | 12 | ; This program is free software; you can redistribute it and/or
|
---|
| 13 | ; modify it under the terms of the GNU General Public License
|
---|
| 14 | ; as published by the Free Software Foundation, in version 3 of the
|
---|
| 15 | ; License.
|
---|
| 16 | ;
|
---|
| 17 | ; This program is distributed in the hope that it will be useful, but
|
---|
| 18 | ; WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 19 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
| 20 | ; General Public License for more details.
|
---|
| 21 | ;
|
---|
| 22 | ; You should have received a copy of the GNU General Public License
|
---|
| 23 | ; along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
| 24 | ;
|
---|
| 25 | ; SPDX-License-Identifier: GPL-3.0-only
|
---|
| 26 | ;
|
---|
[41604] | 27 |
|
---|
| 28 |
|
---|
| 29 | ;*******************************************************************************
|
---|
| 30 | ;* Exported Symbols *
|
---|
| 31 | ;*******************************************************************************
|
---|
[42059] | 32 | public __U4M
|
---|
[41604] | 33 |
|
---|
[86686] | 34 | ; MASM (ML.EXE) is used for PXE and no longer understands the .8086 directive.
|
---|
| 35 | ; WASM is used for the BIOS and understands it just fine.
|
---|
| 36 | ifdef __WASM__
|
---|
[60484] | 37 | .8086
|
---|
[86686] | 38 | endif
|
---|
[41604] | 39 |
|
---|
| 40 | _TEXT segment public 'CODE' use16
|
---|
| 41 | assume cs:_TEXT
|
---|
| 42 |
|
---|
| 43 | ;;
|
---|
| 44 | ; 32-bit unsigned multiplication.
|
---|
| 45 | ;
|
---|
| 46 | ; @param dx:ax Factor 1.
|
---|
| 47 | ; @param cx:bx Factor 2.
|
---|
| 48 | ; @returns dx:ax Result.
|
---|
| 49 | ;
|
---|
| 50 | __U4M:
|
---|
| 51 | pushf
|
---|
[60484] | 52 | if VBOX_BIOS_CPU ge 80386
|
---|
| 53 | .386
|
---|
[41604] | 54 | push eax
|
---|
| 55 | push edx
|
---|
| 56 | push ecx
|
---|
| 57 |
|
---|
| 58 | rol eax, 16
|
---|
| 59 | mov ax, dx
|
---|
| 60 | ror eax, 16
|
---|
| 61 | xor edx, edx
|
---|
| 62 |
|
---|
| 63 | shr ecx, 16
|
---|
| 64 | mov cx, bx
|
---|
| 65 |
|
---|
| 66 | mul ecx ; eax * ecx -> edx:eax
|
---|
| 67 |
|
---|
| 68 | pop ecx
|
---|
| 69 |
|
---|
| 70 | pop edx
|
---|
| 71 | ror eax, 16
|
---|
| 72 | mov dx, ax
|
---|
| 73 | add sp, 2
|
---|
| 74 | pop ax
|
---|
| 75 | rol eax, 16
|
---|
[86686] | 76 | ifdef __WASM__
|
---|
[60484] | 77 | .8086
|
---|
[86686] | 78 | endif
|
---|
[41604] | 79 |
|
---|
[60484] | 80 | else
|
---|
| 81 | push si ; high result
|
---|
| 82 | push di ; low result
|
---|
[41604] | 83 |
|
---|
[60484] | 84 | ;
|
---|
| 85 | ; dx:ax * cx:bx =
|
---|
| 86 | ;-----------------------
|
---|
| 87 | ; ax*bx
|
---|
| 88 | ; + dx*bx ; only lower 16 bits relevant.
|
---|
| 89 | ; + ax*cx ; ditto
|
---|
| 90 | ; +dx*cx ; not relevant
|
---|
| 91 | ; -------------
|
---|
| 92 | ; = dx:ax
|
---|
| 93 | ;
|
---|
[41604] | 94 |
|
---|
[60484] | 95 | push ax ; stash the low factor 1 part for the 3rd multiplication.
|
---|
| 96 | mov di, dx ; stash the high factor 1 part for the 2nd multiplication.
|
---|
[42059] | 97 |
|
---|
[60484] | 98 | ; multiply the two low factor "digits": ax * bx
|
---|
| 99 | mul bx
|
---|
| 100 | mov si, dx
|
---|
| 101 | xchg di, ax ; save low result and loads high factor 1 into ax for the next step
|
---|
[42059] | 102 |
|
---|
[60484] | 103 | ; Multiply the low right "digit" by the high left one and add it to the high result part
|
---|
| 104 | mul bx
|
---|
| 105 | add si, ax
|
---|
[42059] | 106 |
|
---|
[60484] | 107 | ; Multiply the high right "digit" by the low left on and add it ot the high result part.
|
---|
[42059] | 108 | pop ax
|
---|
[60484] | 109 | mul cx
|
---|
| 110 | add si, ax
|
---|
[42059] | 111 |
|
---|
[60484] | 112 | ; Load the result.
|
---|
| 113 | mov dx, si
|
---|
| 114 | mov ax, di
|
---|
[42059] | 115 |
|
---|
[41604] | 116 | pop di
|
---|
| 117 | pop si
|
---|
[60484] | 118 | endif
|
---|
| 119 | popf
|
---|
[41604] | 120 | ret
|
---|
| 121 |
|
---|
| 122 |
|
---|
| 123 | _TEXT ends
|
---|
| 124 | end
|
---|
| 125 |
|
---|