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