2001-04-10 06:20:02 +04:00
|
|
|
// Copyright (C) 2001 MandrakeSoft S.A.
|
2001-04-10 05:04:59 +04:00
|
|
|
//
|
|
|
|
// MandrakeSoft S.A.
|
|
|
|
// 43, rue d'Aboukir
|
|
|
|
// 75002 Paris - France
|
|
|
|
// http://www.linux-mandrake.com/
|
|
|
|
// http://www.mandrakesoft.com/
|
|
|
|
//
|
|
|
|
// This library is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Lesser General Public
|
|
|
|
// License as published by the Free Software Foundation; either
|
|
|
|
// version 2 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public
|
|
|
|
// License along with this library; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// This is the glue logic needed to connect the wm-FPU-emu
|
|
|
|
// FPU emulator written by Bill Metzenthen to bochs.
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
#include "bochs.h"
|
2001-09-15 10:55:14 +04:00
|
|
|
#include <math.h>
|
2001-04-10 05:04:59 +04:00
|
|
|
extern "C" {
|
|
|
|
#include "fpu_emu.h"
|
|
|
|
#include "linux/signal.h"
|
|
|
|
}
|
|
|
|
|
merge in BRANCH-io-cleanup.
To see the commit logs for this use either cvsweb or
cvs update -r BRANCH-io-cleanup and then 'cvs log' the various files.
In general this provides a generic interface for logging.
logfunctions:: is a class that is inherited by some classes, and also
. allocated as a standalone global called 'genlog'. All logging uses
. one of the ::info(), ::error(), ::ldebug(), ::panic() methods of this
. class through 'BX_INFO(), BX_ERROR(), BX_DEBUG(), BX_PANIC()' macros
. respectively.
.
. An example usage:
. BX_INFO(("Hello, World!\n"));
iofunctions:: is a class that is allocated once by default, and assigned
as the iofunction of each logfunctions instance. It is this class that
maintains the file descriptor and other output related code, at this
point using vfprintf(). At some future point, someone may choose to
write a gui 'console' for bochs to which messages would be redirected
simply by assigning a different iofunction class to the various logfunctions
objects.
More cleanup is coming, but this works for now. If you want to see alot
of debugging output, in main.cc, change onoff[LOGLEV_DEBUG]=0 to =1.
Comments, bugs, flames, to me: todd@fries.net
2001-05-15 18:49:57 +04:00
|
|
|
#define LOG_THIS genlog->
|
2001-05-23 12:16:07 +04:00
|
|
|
#if BX_USE_CPU_SMF
|
|
|
|
#define this (BX_CPU(0))
|
|
|
|
#endif
|
merge in BRANCH-io-cleanup.
To see the commit logs for this use either cvsweb or
cvs update -r BRANCH-io-cleanup and then 'cvs log' the various files.
In general this provides a generic interface for logging.
logfunctions:: is a class that is inherited by some classes, and also
. allocated as a standalone global called 'genlog'. All logging uses
. one of the ::info(), ::error(), ::ldebug(), ::panic() methods of this
. class through 'BX_INFO(), BX_ERROR(), BX_DEBUG(), BX_PANIC()' macros
. respectively.
.
. An example usage:
. BX_INFO(("Hello, World!\n"));
iofunctions:: is a class that is allocated once by default, and assigned
as the iofunction of each logfunctions instance. It is this class that
maintains the file descriptor and other output related code, at this
point using vfprintf(). At some future point, someone may choose to
write a gui 'console' for bochs to which messages would be redirected
simply by assigning a different iofunction class to the various logfunctions
objects.
More cleanup is coming, but this works for now. If you want to see alot
of debugging output, in main.cc, change onoff[LOGLEV_DEBUG]=0 to =1.
Comments, bugs, flames, to me: todd@fries.net
2001-05-15 18:49:57 +04:00
|
|
|
|
2001-04-10 05:04:59 +04:00
|
|
|
// Use this to hold a pointer to the instruction since
|
|
|
|
// we can't pass this to the FPU emulation routines, which
|
|
|
|
// will ultimately call routines here.
|
2002-09-18 02:50:53 +04:00
|
|
|
static bxInstruction_c *fpu_iptr = NULL;
|
2001-05-23 12:16:07 +04:00
|
|
|
static BX_CPU_C *fpu_cpu_ptr = NULL;
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2002-09-09 20:11:25 +04:00
|
|
|
i387_t *current_i387;
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
extern "C" void
|
|
|
|
math_emulate2(fpu_addr_modes addr_modes,
|
|
|
|
u_char FPU_modrm,
|
|
|
|
u_char byte1,
|
|
|
|
void *data_address,
|
|
|
|
struct address data_sel_off,
|
|
|
|
struct address entry_sel_off);
|
|
|
|
|
|
|
|
extern "C" void printfp(char *s, FPU_REG *r);
|
|
|
|
|
|
|
|
|
|
|
|
// This is called by bochs upon reset
|
|
|
|
void
|
|
|
|
BX_CPU_C::fpu_init(void)
|
|
|
|
{
|
2002-09-09 20:11:25 +04:00
|
|
|
current_i387 = &(BX_CPU_THIS_PTR the_i387);
|
2001-04-10 05:04:59 +04:00
|
|
|
finit();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-09-18 02:50:53 +04:00
|
|
|
BX_CPU_C::fpu_execute(bxInstruction_c *i)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
|
|
|
fpu_addr_modes addr_modes;
|
|
|
|
void *data_address;
|
|
|
|
struct address data_sel_off;
|
|
|
|
struct address entry_sel_off;
|
2002-10-25 15:44:41 +04:00
|
|
|
bx_bool is_32;
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
fpu_iptr = i;
|
2001-05-23 12:16:07 +04:00
|
|
|
fpu_cpu_ptr = this;
|
2002-09-09 20:11:25 +04:00
|
|
|
current_i387 = &(BX_CPU_THIS_PTR the_i387);
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
addr_modes.default_mode = VM86;
|
|
|
|
addr_modes.default_mode = 0; // FPU_CS == __USER_CS && FPU_DS == __USER_DS
|
|
|
|
addr_modes.default_mode = SEG32;
|
|
|
|
addr_modes.default_mode = PM16;
|
|
|
|
#endif
|
|
|
|
if (protected_mode()) {
|
|
|
|
addr_modes.default_mode = SEG32;
|
|
|
|
}
|
|
|
|
else if (v8086_mode()) {
|
|
|
|
addr_modes.default_mode = VM86;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// real mode, use vm86 for now
|
|
|
|
addr_modes.default_mode = VM86;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Mark if instruction used opsize or addrsize prefixes
|
|
|
|
// Actually, addr_modes.override.address_size is not used,
|
|
|
|
// could delete that code.
|
|
|
|
is_32 = BX_CPU_THIS_PTR sregs[BX_SEG_REG_CS].cache.u.segment.d_b;
|
2002-09-18 09:36:48 +04:00
|
|
|
if (i->as32B() == is_32)
|
2001-04-10 05:04:59 +04:00
|
|
|
addr_modes.override.address_size = 0;
|
|
|
|
else
|
|
|
|
addr_modes.override.address_size = ADDR_SIZE_PREFIX;
|
2002-09-18 09:36:48 +04:00
|
|
|
if (i->os32B() == is_32)
|
2001-04-10 05:04:59 +04:00
|
|
|
addr_modes.override.operand_size = 0;
|
|
|
|
else
|
|
|
|
addr_modes.override.operand_size = OP_SIZE_PREFIX;
|
|
|
|
|
|
|
|
// For now set access_limit to max. It seems to be
|
|
|
|
// a number from 0..255 denoting how many bytes the
|
|
|
|
// current instruction can access according to its
|
|
|
|
// memory operand. 255 means >= 255.
|
|
|
|
access_limit = 0xff;
|
|
|
|
|
|
|
|
// fill in orig eip here in offset
|
|
|
|
// fill in CS in selector
|
|
|
|
entry_sel_off.offset = BX_CPU_THIS_PTR prev_eip;
|
2001-05-23 12:16:07 +04:00
|
|
|
entry_sel_off.selector = BX_CPU_THIS_PTR sregs[BX_SEG_REG_CS].selector.value;
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
// should set these fields to 0 if mem operand not used
|
2002-09-18 09:36:48 +04:00
|
|
|
data_address = (void *) RMAddr(i);
|
|
|
|
data_sel_off.offset = RMAddr(i);
|
|
|
|
data_sel_off.selector = BX_CPU_THIS_PTR sregs[i->seg()].selector.value;
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2002-09-18 12:00:43 +04:00
|
|
|
math_emulate2(addr_modes, i->modrm(), i->b1(), data_address,
|
2001-04-10 05:04:59 +04:00
|
|
|
data_sel_off, entry_sel_off);
|
|
|
|
}
|
|
|
|
|
2001-09-15 10:55:14 +04:00
|
|
|
static double sigh_scale_factor = pow(2.0, -31.0);
|
|
|
|
static double sigl_scale_factor = pow(2.0, -63.0);
|
|
|
|
|
|
|
|
void
|
|
|
|
BX_CPU_C::fpu_print_regs()
|
|
|
|
{
|
|
|
|
Bit32u reg;
|
|
|
|
reg = i387.soft.cwd;
|
|
|
|
fprintf(stderr, "cwd 0x%-8x\t%d\n", (unsigned) reg, (int) reg);
|
|
|
|
reg = i387.soft.swd;
|
|
|
|
fprintf(stderr, "swd 0x%-8x\t%d\n", (unsigned) reg, (int) reg);
|
|
|
|
reg = i387.soft.twd;
|
|
|
|
fprintf(stderr, "twd 0x%-8x\t%d\n", (unsigned) reg, (int) reg);
|
|
|
|
reg = i387.soft.fip;
|
|
|
|
fprintf(stderr, "fip 0x%-8x\t%d\n", (unsigned) reg, (int) reg);
|
|
|
|
reg = i387.soft.fcs;
|
|
|
|
fprintf(stderr, "fcs 0x%-8x\t%d\n", (unsigned) reg, (int) reg);
|
|
|
|
reg = i387.soft.foo;
|
|
|
|
fprintf(stderr, "foo 0x%-8x\t%d\n", (unsigned) reg, (int) reg);
|
|
|
|
reg = i387.soft.fos;
|
|
|
|
fprintf(stderr, "fos 0x%-8x\t%d\n", (unsigned) reg, (int) reg);
|
|
|
|
// print stack too
|
|
|
|
for (int i=0; i<8; i++) {
|
|
|
|
FPU_REG *fpr = &st(i);
|
|
|
|
double f1 = pow(2.0, ((0x7fff&fpr->exp) - EXTENDED_Ebias));
|
|
|
|
if (fpr->exp & SIGN_Negative) f1 = -f1;
|
|
|
|
double f2 = ((double)fpr->sigh * sigh_scale_factor);
|
|
|
|
double f3 = ((double)fpr->sigl * sigl_scale_factor);
|
|
|
|
double f = f1*(f2+f3);
|
|
|
|
fprintf(stderr, "st%d %.10f (raw 0x%04x%08x%08x)\n", i, f, 0xffff&fpr->exp, fpr->sigh, fpr->sigl);
|
|
|
|
}
|
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
unsigned
|
|
|
|
fpu_get_ds(void)
|
|
|
|
{
|
2001-05-23 12:16:07 +04:00
|
|
|
return(fpu_cpu_ptr->sregs[BX_SEG_REG_DS].selector.value);
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
fpu_set_ax(unsigned short val16)
|
|
|
|
{
|
2001-05-23 12:16:07 +04:00
|
|
|
// define to set AX in the current CPU -- not ideal.
|
2001-05-23 12:44:59 +04:00
|
|
|
#undef AX
|
2001-05-23 12:16:07 +04:00
|
|
|
#define AX (fpu_cpu_ptr->gen_reg[0].word.rx)
|
2001-04-10 05:04:59 +04:00
|
|
|
AX = val16;
|
2001-05-23 12:16:07 +04:00
|
|
|
#undef AX
|
2001-05-30 22:56:02 +04:00
|
|
|
//BX_DEBUG(( "fpu_set_ax(0x%04x)", (unsigned) val16));
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
fpu_verify_area(unsigned what, void *ptr, unsigned n)
|
|
|
|
{
|
|
|
|
bx_segment_reg_t *seg;
|
|
|
|
|
2002-09-18 09:36:48 +04:00
|
|
|
seg = &fpu_cpu_ptr->sregs[fpu_iptr->seg()];
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
if (what == VERIFY_READ) {
|
2001-05-23 12:16:07 +04:00
|
|
|
fpu_cpu_ptr->read_virtual_checks(seg, PTR2INT(ptr), n);
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
else { // VERIFY_WRITE
|
2001-05-23 12:16:07 +04:00
|
|
|
fpu_cpu_ptr->write_virtual_checks(seg, PTR2INT(ptr), n);
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
2001-05-30 22:56:02 +04:00
|
|
|
//BX_DEBUG(( "verify_area: 0x%x", PTR2INT(ptr)));
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
FPU_printall(void)
|
|
|
|
{
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_PANIC(("FPU_printall"));
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
unsigned
|
|
|
|
fpu_get_user(void *ptr, unsigned len)
|
|
|
|
{
|
|
|
|
Bit32u val32;
|
|
|
|
Bit16u val16;
|
|
|
|
Bit8u val8;
|
|
|
|
|
|
|
|
switch (len) {
|
|
|
|
case 1:
|
2002-09-18 09:36:48 +04:00
|
|
|
fpu_cpu_ptr->read_virtual_byte(fpu_iptr->seg(), PTR2INT(ptr), &val8);
|
2001-04-10 05:04:59 +04:00
|
|
|
val32 = val8;
|
|
|
|
break;
|
|
|
|
case 2:
|
2002-09-18 09:36:48 +04:00
|
|
|
fpu_cpu_ptr->read_virtual_word(fpu_iptr->seg(), PTR2INT(ptr), &val16);
|
2001-04-10 05:04:59 +04:00
|
|
|
val32 = val16;
|
|
|
|
break;
|
|
|
|
case 4:
|
2002-09-18 09:36:48 +04:00
|
|
|
fpu_cpu_ptr->read_virtual_dword(fpu_iptr->seg(), PTR2INT(ptr), &val32);
|
2001-04-10 05:04:59 +04:00
|
|
|
break;
|
|
|
|
default:
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_PANIC(("fpu_get_user: len=%u", len));
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
return(val32);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
fpu_put_user(unsigned val, void *ptr, unsigned len)
|
|
|
|
{
|
|
|
|
Bit32u val32;
|
|
|
|
Bit16u val16;
|
|
|
|
Bit8u val8;
|
|
|
|
|
|
|
|
switch (len) {
|
|
|
|
case 1:
|
|
|
|
val8 = val;
|
2002-09-18 09:36:48 +04:00
|
|
|
fpu_cpu_ptr->write_virtual_byte(fpu_iptr->seg(), PTR2INT(ptr), &val8);
|
2001-04-10 05:04:59 +04:00
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
val16 = val;
|
2002-09-18 09:36:48 +04:00
|
|
|
fpu_cpu_ptr->write_virtual_word(fpu_iptr->seg(), PTR2INT(ptr), &val16);
|
2001-04-10 05:04:59 +04:00
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
val32 = val;
|
2002-09-18 09:36:48 +04:00
|
|
|
fpu_cpu_ptr->write_virtual_dword(fpu_iptr->seg(), PTR2INT(ptr), &val32);
|
2001-04-10 05:04:59 +04:00
|
|
|
break;
|
|
|
|
default:
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_PANIC(("fpu_put_user: len=%u", len));
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
math_abort(struct info *info, unsigned int signal)
|
|
|
|
{
|
|
|
|
UNUSED(info); // info is always passed NULL
|
|
|
|
#if BX_CPU_LEVEL >= 4
|
|
|
|
|
|
|
|
// values of signal:
|
|
|
|
// SIGILL : opcodes which are illegal
|
|
|
|
// SIGFPE : unmasked FP exception before WAIT or non-control instruction
|
|
|
|
// SIGSEGV : access data beyond segment violation
|
|
|
|
switch (signal) {
|
|
|
|
case SIGFPE:
|
2001-05-23 12:16:07 +04:00
|
|
|
if (fpu_cpu_ptr->cr0.ne == 0) {
|
2001-04-10 05:04:59 +04:00
|
|
|
// MSDOS compatibility external interrupt (IRQ13)
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_PANIC (("math_abort: MSDOS compatibility not supported yet"));
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
2001-05-23 12:16:07 +04:00
|
|
|
fpu_cpu_ptr->exception(BX_MF_EXCEPTION, 0, 0);
|
2001-04-10 05:04:59 +04:00
|
|
|
// execution does not reach here
|
|
|
|
|
|
|
|
case SIGILL:
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_PANIC (("math_abort: SIGILL not implemented yet."));
|
2001-04-10 05:04:59 +04:00
|
|
|
break;
|
|
|
|
case SIGSEGV:
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_PANIC (("math_abort: SIGSEGV not implemented yet."));
|
2001-04-10 05:04:59 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
UNUSED(signal);
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_INFO(("math_abort: CPU<4 not supported yet"));
|
2001-04-10 05:04:59 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
printk(const char * fmt, ...)
|
|
|
|
{
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_INFO(("printk not complete: %s", fmt));
|
2001-04-10 05:04:59 +04:00
|
|
|
return(0); // for now
|
|
|
|
}
|