1 | ; $Id: __U4D.asm 69120 2017-10-17 19:13:23Z vboxsync $
|
---|
2 | ;; @file
|
---|
3 | ; Compiler support routines.
|
---|
4 | ;
|
---|
5 |
|
---|
6 | ;
|
---|
7 | ; Copyright (C) 2012-2017 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 __U4D
|
---|
23 |
|
---|
24 | .8086
|
---|
25 |
|
---|
26 | if VBOX_BIOS_CPU lt 80386
|
---|
27 | extrn _DoUInt32Div:near
|
---|
28 | endif
|
---|
29 |
|
---|
30 |
|
---|
31 | _TEXT segment public 'CODE' use16
|
---|
32 | assume cs:_TEXT
|
---|
33 |
|
---|
34 |
|
---|
35 | ;;
|
---|
36 | ; 32-bit unsigned division.
|
---|
37 | ;
|
---|
38 | ; @param dx:ax Dividend.
|
---|
39 | ; @param cx:bx Divisor.
|
---|
40 | ; @returns dx:ax Quotient.
|
---|
41 | ; cx:bx Remainder.
|
---|
42 | ;
|
---|
43 | __U4D:
|
---|
44 | pushf
|
---|
45 | if VBOX_BIOS_CPU ge 80386
|
---|
46 | .386
|
---|
47 | push eax
|
---|
48 | push edx
|
---|
49 | push ecx
|
---|
50 |
|
---|
51 | rol eax, 16
|
---|
52 | mov ax, dx
|
---|
53 | ror eax, 16
|
---|
54 | xor edx, edx
|
---|
55 |
|
---|
56 | shr ecx, 16
|
---|
57 | mov cx, bx
|
---|
58 |
|
---|
59 | div ecx ; eax:edx / ecx -> eax=quotient, edx=remainder.
|
---|
60 |
|
---|
61 | mov bx, dx
|
---|
62 | pop ecx
|
---|
63 | shr edx, 16
|
---|
64 | mov cx, dx
|
---|
65 |
|
---|
66 | pop edx
|
---|
67 | ror eax, 16
|
---|
68 | mov dx, ax
|
---|
69 | add sp, 2
|
---|
70 | pop ax
|
---|
71 | rol eax, 16
|
---|
72 | .8086
|
---|
73 | else
|
---|
74 |
|
---|
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 4 bytes for the result buffer.
|
---|
84 | push bp
|
---|
85 | sub sp, 04h
|
---|
86 | mov bp, sp
|
---|
87 |
|
---|
88 | ; Pointer to the return buffer.
|
---|
89 | push ss
|
---|
90 | push bp
|
---|
91 | add bp, 04h ; 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 remainder.
|
---|
104 | mov cx, [bp - 02h]
|
---|
105 | mov bx, [bp - 04h]
|
---|
106 |
|
---|
107 | ; The quotient is already in dx:ax
|
---|
108 |
|
---|
109 | mov sp, bp
|
---|
110 | pop bp
|
---|
111 | pop es
|
---|
112 | pop ds
|
---|
113 | endif
|
---|
114 | popf
|
---|
115 | ret
|
---|
116 |
|
---|
117 | _TEXT ends
|
---|
118 | end
|
---|
119 |
|
---|