VirtualBox

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

Last change on this file since 60484 was 60484, checked in by vboxsync, 9 years ago

PCBIOS: split up the support.asm file and implemented 32-bit division for pre-386 targets in C using uint32.h (derived from uint128.h via uint64.h).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.1 KB
Line 
1; $Id: __U4D.asm 60484 2016-04-14 09:25:51Z vboxsync $
2;; @file
3; Compiler support routines.
4;
5
6;
7; Copyright (C) 2012-2015 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 .8086
25
26if VBOX_BIOS_CPU lt 80386
27extrn _DoUInt32Div:near
28endif
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
45if 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
73else
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 8 bytes for the result buffer.
84 push bp
85 sub sp, 08h
86 mov bp, sp
87
88 ; Pointer to the return buffer.
89 push ss
90 push bp
91 add bp, 08h ; 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 reminder.
104 mov cx, [bp - 08h + 6]
105 mov bx, [bp - 08h + 4]
106
107 ; Load the quotient.
108 mov dx, [bp - 08h + 2]
109 mov ax, [bp - 08h]
110
111 mov sp, bp
112 pop bp
113 pop es
114 pop ds
115endif
116 popf
117 ret
118
119_TEXT ends
120 end
121
Note: See TracBrowser for help on using the repository browser.

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