VirtualBox

source: vbox/trunk/src/VBox/Devices/BiosCommonCode/__U4D.asm

Last change on this file was 98103, checked in by vboxsync, 17 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.9 KB
RevLine 
[41604]1; $Id: __U4D.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;*******************************************************************************
32public __U4D
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.
36ifdef __WASM__
[60484]37 .8086
[86686]38endif
[41604]39
[86686]40
[60484]41if VBOX_BIOS_CPU lt 80386
42extrn _DoUInt32Div:near
43endif
[41604]44
45
46_TEXT segment public 'CODE' use16
47 assume cs:_TEXT
48
49
50;;
51; 32-bit unsigned division.
52;
53; @param dx:ax Dividend.
54; @param cx:bx Divisor.
55; @returns dx:ax Quotient.
[58723]56; cx:bx Remainder.
[41604]57;
58__U4D:
59 pushf
[60484]60if VBOX_BIOS_CPU ge 80386
61 .386
[41604]62 push eax
63 push edx
64 push ecx
65
66 rol eax, 16
67 mov ax, dx
68 ror eax, 16
69 xor edx, edx
70
71 shr ecx, 16
72 mov cx, bx
73
[58723]74 div ecx ; eax:edx / ecx -> eax=quotient, edx=remainder.
[41604]75
76 mov bx, dx
77 pop ecx
78 shr edx, 16
79 mov cx, dx
80
81 pop edx
82 ror eax, 16
83 mov dx, ax
84 add sp, 2
85 pop ax
86 rol eax, 16
[86686]87ifdef __WASM__
[60484]88 .8086
[86686]89endif
[60484]90else
[75248]91 ;
92 ; If the divisor is only 16-bit, use a fast path
93 ;
94 test cx, cx
95 jnz do_it_the_hard_way
[75263]96
[75248]97 div bx ; dx:ax / bx -> ax=quotient, dx=remainder
[41604]98
[75248]99 mov bx, dx ; remainder in cx:bx, and we know cx=0
100
101 xor dx, dx ; quotient in dx:ax, dx must be zero
102
103 popf
104 ret
105
106do_it_the_hard_way:
[60484]107 ; Call C function do this.
108 push ds
109 push es
[41604]110
[60484]111 ;
112 ; Convert to a C __cdecl call - not doing this in assembly.
113 ;
[41604]114
[60530]115 ; Set up a frame of sorts, allocating 4 bytes for the result buffer.
[60484]116 push bp
[60530]117 sub sp, 04h
[60484]118 mov bp, sp
[42059]119
[60484]120 ; Pointer to the return buffer.
121 push ss
122 push bp
[60530]123 add bp, 04h ; Correct bp.
[42059]124
[60484]125 ; The divisor.
126 push cx
127 push bx
[42059]128
[60484]129 ; The dividend.
130 push dx
131 push ax
[42059]132
[60484]133 call _DoUInt32Div
[42059]134
[60530]135 ; Load the remainder.
136 mov cx, [bp - 02h]
137 mov bx, [bp - 04h]
[42059]138
[60530]139 ; The quotient is already in dx:ax
[42059]140
[60484]141 mov sp, bp
142 pop bp
143 pop es
144 pop ds
145endif
[41604]146 popf
147 ret
148
149_TEXT ends
150 end
151
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use