VirtualBox

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

Last change on this file since 94567 was 93115, checked in by vboxsync, 3 years ago

scm --update-copyright-year

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

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