* Get the effective address from an FPU instruction.
* Copyright (C) 1992, 1993 W. Metzenthen, 22 Parker St, Ormond,
* E-mail apm233m@vaxc.cc.monash.edu.au
* This copyright notice covers the redistribution and use of the
* FPU emulator developed by W. Metzenthen. It covers only its use
* in the 386BSD operating system. Any other use is not permitted
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must include information specifying
* that source code for the emulator is freely available and include
* a) an offer to provide the source code for a nominal distribution
* b) list at least two alternative methods whereby the source
* can be obtained, e.g. a publically accessible bulletin board
* and an anonymous ftp site from which the software can be
* 3. All advertising materials specifically mentioning features or use of
* this emulator must acknowledge that it was developed by W. Metzenthen.
* 4. The name of W. Metzenthen may not be used to endorse or promote
* products derived from this software without specific prior written
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* W. METZENTHEN BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
/*---------------------------------------------------------------------------+
| The file contains code which accesses user memory. |
| Emulator static data may change when user memory is accessed, due to |
| other processes using the emulator while swapping is in progress. |
+---------------------------------------------------------------------------*/
static int reg_offset
[] = {
tEAX
, tECX
, tEDX
, tEBX
, tESP
, tEBP
, tESI
, tEDI
};
#define REG_(x) (*(((int*)FPU_info) + reg_offset[(x)]))
/* Decode the SIB byte. This function assumes mod != 0 */
unsigned char ss
, index
, base
;
base
= fubyte((char *) FPU_EIP
); /* The SIB byte */
if ((mod
== 0) && (base
== 5))
offset
= 0; /* No base register */
/* A non-zero ss is illegal */
offset
+= (REG_(index
)) << ss
;
/* 8 bit signed displacement */
offset
+= (signed char) fubyte((char *) FPU_EIP
);
if (mod
== 2 || base
== 5) { /* The second condition also
offset
+= (signed) fuword((unsigned long *) FPU_EIP
);
MOD R/M byte: MOD == 3 has a special use for the FPU
SIB byte used iff R/M = 100b
..... ......... .........
..... ......... .........
get_address(unsigned char FPU_modrm
)
int offset
= 0; /* Initialized just to stop compiler warnings. */
mod
= (FPU_modrm
>> 6) & 3;
if (FPU_rm
== 4 && mod
!= 3) {
FPU_data_address
= sib(mod
);
cpu_reg_ptr
= (long *) ®_(FPU_rm
);
/* Special case: disp32 */
offset
= fuword((unsigned long *) FPU_EIP
);
FPU_data_address
= (void *) offset
;
FPU_data_address
= (void *) *cpu_reg_ptr
; /* Just return the
/* 8 bit signed displacement */
offset
= (signed char) fubyte((char *) FPU_EIP
);
/* 32 bit displacement */
offset
= (signed) fuword((unsigned long *) FPU_EIP
);
/* Not legal for the FPU */
FPU_data_address
= offset
+ (char *) *cpu_reg_ptr
;