make sreg index tables static in fetchdecode and remove them from init.cc/cpu.h

This commit is contained in:
Stanislav Shwartsman 2007-11-18 21:07:40 +00:00
parent 1e0db62984
commit 30f42d74f1
5 changed files with 140 additions and 135 deletions

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: cpu.h,v 1.367 2007-11-18 19:46:14 sshwarts Exp $
// $Id: cpu.h,v 1.368 2007-11-18 21:07:40 sshwarts Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2001 MandrakeSoft S.A.
@ -1199,21 +1199,6 @@ public: // for now...
volatile bx_bool smi_pending;
volatile bx_bool nmi_pending;
// <TAG-CLASS-CPU-START>
// for decoding instructions; accessing seg reg's by index
unsigned sreg_mod00_rm16[8];
unsigned sreg_mod01or10_rm16[8];
#if BX_SUPPORT_X86_64
unsigned sreg_mod01or10_rm32[16];
unsigned sreg_mod0_base32[16];
unsigned sreg_mod1or2_base32[16];
#else
unsigned sreg_mod01or10_rm32[8];
unsigned sreg_mod0_base32[8];
unsigned sreg_mod1or2_base32[8];
#endif
// <TAG-CLASS-CPU-END>
// for exceptions
jmp_buf jmp_buf_env;
Bit8u curr_exception[2];

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: fetchdecode.cc,v 1.132 2007-11-18 19:46:14 sshwarts Exp $
// $Id: fetchdecode.cc,v 1.133 2007-11-18 21:07:40 sshwarts Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2001 MandrakeSoft S.A.
@ -78,10 +78,6 @@ static const bx_bool BxOpcodeHasModrm32[512] = {
/* 0 1 2 3 4 5 6 7 8 9 a b c d e f */
};
// UD2 opcode (according to Intel manuals):
// Use the 0F0B opcode (UD2 instruction) or the 0FB9H opcode when deliberately
// trying to generate an invalid opcode exception (#UD).
/* *********** */
// LOCK PREFIX //
/* *********** */
@ -154,6 +150,63 @@ static BxExecutePtr_tR Resolve32BaseIndex[8] = {
&BX_CPU_C::BxResolve32BaseIndex,
};
// decoding instructions; accessing seg reg's by index
static unsigned sreg_mod00_rm16[8] = {
BX_SEG_REG_DS,
BX_SEG_REG_DS,
BX_SEG_REG_SS,
BX_SEG_REG_SS,
BX_SEG_REG_DS,
BX_SEG_REG_DS,
BX_SEG_REG_DS,
BX_SEG_REG_DS
};
static unsigned sreg_mod01or10_rm16[8] = {
BX_SEG_REG_DS,
BX_SEG_REG_DS,
BX_SEG_REG_SS,
BX_SEG_REG_SS,
BX_SEG_REG_DS,
BX_SEG_REG_DS,
BX_SEG_REG_SS,
BX_SEG_REG_DS
};
// decoding instructions; accessing seg reg's by index
static unsigned sreg_mod01or10_rm32[8] = {
BX_SEG_REG_DS,
BX_SEG_REG_DS,
BX_SEG_REG_DS,
BX_SEG_REG_DS,
BX_SEG_REG_NULL, // escape to SIB-byte
BX_SEG_REG_SS,
BX_SEG_REG_DS,
BX_SEG_REG_DS
};
static unsigned sreg_mod0_base32[8] = {
BX_SEG_REG_DS,
BX_SEG_REG_DS,
BX_SEG_REG_DS,
BX_SEG_REG_DS,
BX_SEG_REG_SS,
BX_SEG_REG_DS,
BX_SEG_REG_DS,
BX_SEG_REG_DS
};
static unsigned sreg_mod1or2_base32[8] = {
BX_SEG_REG_DS,
BX_SEG_REG_DS,
BX_SEG_REG_DS,
BX_SEG_REG_DS,
BX_SEG_REG_SS,
BX_SEG_REG_SS,
BX_SEG_REG_DS,
BX_SEG_REG_DS
};
// common fetchdecode32/64 opcode tables
#include "fetchdecode.h"
@ -2614,7 +2667,7 @@ fetch_b1:
if (mod == 0x40) { // mod == 01b
instruction->ResolveModrm = BxResolve32Rm;
if (BX_NULL_SEG_REG(instruction->seg()))
instruction->setSeg(BX_CPU_THIS_PTR sreg_mod01or10_rm32[rm]);
instruction->setSeg(sreg_mod01or10_rm32[rm]);
get_8bit_displ:
if (ilen < remain) {
// 8 sign extended to 32
@ -2627,7 +2680,7 @@ get_8bit_displ:
// (mod == 0x80) mod == 10b
instruction->ResolveModrm = BxResolve32Rm;
if (BX_NULL_SEG_REG(instruction->seg()))
instruction->setSeg(BX_CPU_THIS_PTR sreg_mod01or10_rm32[rm]);
instruction->setSeg(sreg_mod01or10_rm32[rm]);
get_32bit_displ:
if ((ilen+3) < remain) {
instruction->modRMForm.displ32u = FetchDWORD(iptr);
@ -2658,7 +2711,7 @@ get_32bit_displ:
else
instruction->ResolveModrm = Resolve32BaseIndex[base];
if (BX_NULL_SEG_REG(instruction->seg()))
instruction->setSeg(BX_CPU_THIS_PTR sreg_mod0_base32[base]);
instruction->setSeg(sreg_mod0_base32[base]);
if (base == 0x05)
goto get_32bit_displ;
// mod==00b, rm==4, base!=5
@ -2670,7 +2723,7 @@ get_32bit_displ:
else
instruction->ResolveModrm = BxResolve32BaseIndex;
if (BX_NULL_SEG_REG(instruction->seg()))
instruction->setSeg(BX_CPU_THIS_PTR sreg_mod1or2_base32[base]);
instruction->setSeg(sreg_mod1or2_base32[base]);
goto get_8bit_displ;
}
// (mod == 0x80), mod==10b, rm==4
@ -2679,7 +2732,7 @@ get_32bit_displ:
else
instruction->ResolveModrm = BxResolve32BaseIndex;
if (BX_NULL_SEG_REG(instruction->seg()))
instruction->setSeg(BX_CPU_THIS_PTR sreg_mod1or2_base32[base]);
instruction->setSeg(sreg_mod1or2_base32[base]);
goto get_32bit_displ;
}
}
@ -2688,7 +2741,7 @@ get_32bit_displ:
if (mod == 0x40) { // mod == 01b
instruction->ResolveModrm = Resolve16Mod1or2[rm];
if (BX_NULL_SEG_REG(instruction->seg()))
instruction->setSeg(BX_CPU_THIS_PTR sreg_mod01or10_rm16[rm]);
instruction->setSeg(sreg_mod01or10_rm16[rm]);
if (ilen < remain) {
// 8 sign extended to 16
instruction->modRMForm.displ16u = (Bit8s) *iptr++;
@ -2700,7 +2753,7 @@ get_32bit_displ:
if (mod == 0x80) { // mod == 10b
instruction->ResolveModrm = Resolve16Mod1or2[rm];
if (BX_NULL_SEG_REG(instruction->seg()))
instruction->setSeg(BX_CPU_THIS_PTR sreg_mod01or10_rm16[rm]);
instruction->setSeg(sreg_mod01or10_rm16[rm]);
if ((ilen+1) < remain) {
instruction->modRMForm.displ16u = FetchWORD(iptr);
iptr += 2;
@ -2712,7 +2765,7 @@ get_32bit_displ:
// mod must be 00b at this point
instruction->ResolveModrm = Resolve16Mod0[rm];
if (BX_NULL_SEG_REG(instruction->seg()))
instruction->setSeg(BX_CPU_THIS_PTR sreg_mod00_rm16[rm]);
instruction->setSeg(sreg_mod00_rm16[rm]);
if (rm == 0x06) {
if ((ilen+1) < remain) {
instruction->modRMForm.displ16u = FetchWORD(iptr);

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: fetchdecode64.cc,v 1.140 2007-11-18 20:21:34 sshwarts Exp $
// $Id: fetchdecode64.cc,v 1.141 2007-11-18 21:07:40 sshwarts Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2001 MandrakeSoft S.A.
@ -84,10 +84,6 @@ static const bx_bool BxOpcodeHasModrm64[512] = {
/* 0 1 2 3 4 5 6 7 8 9 a b c d e f */
};
// UD2 opcode (according to Intel manuals):
// Use the 0F0B opcode (UD2 instruction) or the 0FB9H opcode when deliberately
// trying to generate an invalid opcode exception (#UD).
/* *********** */
// LOCK PREFIX //
/* *********** */
@ -200,6 +196,63 @@ static BxExecutePtr_tR Resolve64BaseIndex[16] = {
&BX_CPU_C::BxResolve64BaseIndex,
};
// decoding instructions; accessing seg reg's by index
static unsigned sreg_mod01or10_rm32[16] = {
BX_SEG_REG_DS,
BX_SEG_REG_DS,
BX_SEG_REG_DS,
BX_SEG_REG_DS,
BX_SEG_REG_NULL, // escape to SIB-byte
BX_SEG_REG_SS,
BX_SEG_REG_DS,
BX_SEG_REG_DS,
BX_SEG_REG_DS,
BX_SEG_REG_DS,
BX_SEG_REG_DS,
BX_SEG_REG_DS,
BX_SEG_REG_NULL, // escape to SIB-byte
BX_SEG_REG_DS,
BX_SEG_REG_DS,
BX_SEG_REG_DS,
};
static unsigned sreg_mod0_base32[16] = {
BX_SEG_REG_DS,
BX_SEG_REG_DS,
BX_SEG_REG_DS,
BX_SEG_REG_DS,
BX_SEG_REG_SS,
BX_SEG_REG_DS,
BX_SEG_REG_DS,
BX_SEG_REG_DS,
BX_SEG_REG_DS,
BX_SEG_REG_DS,
BX_SEG_REG_DS,
BX_SEG_REG_DS,
BX_SEG_REG_DS,
BX_SEG_REG_DS,
BX_SEG_REG_DS,
BX_SEG_REG_DS
};
static unsigned sreg_mod1or2_base32[16] = {
BX_SEG_REG_DS,
BX_SEG_REG_DS,
BX_SEG_REG_DS,
BX_SEG_REG_DS,
BX_SEG_REG_SS,
BX_SEG_REG_SS,
BX_SEG_REG_DS,
BX_SEG_REG_DS,
BX_SEG_REG_DS,
BX_SEG_REG_DS,
BX_SEG_REG_DS,
BX_SEG_REG_DS,
BX_SEG_REG_DS,
BX_SEG_REG_DS,
BX_SEG_REG_DS,
BX_SEG_REG_DS
};
// common fetchdecode32/64 opcode tables
#include "fetchdecode.h"
@ -3596,7 +3649,7 @@ fetch_b1:
if (mod == 0x40) { // mod == 01b
instruction->ResolveModrm = BxResolve64Rm;
if (BX_NULL_SEG_REG(instruction->seg()))
instruction->setSeg(BX_CPU_THIS_PTR sreg_mod01or10_rm32[rm]);
instruction->setSeg(sreg_mod01or10_rm32[rm]);
if (ilen < remain) {
// 8 sign extended to 32
instruction->modRMForm.displ32u = (Bit8s) *iptr++;
@ -3608,7 +3661,7 @@ fetch_b1:
// (mod == 0x80) mod == 10b
instruction->ResolveModrm = BxResolve64Rm;
if (BX_NULL_SEG_REG(instruction->seg()))
instruction->setSeg(BX_CPU_THIS_PTR sreg_mod01or10_rm32[rm]);
instruction->setSeg(sreg_mod01or10_rm32[rm]);
if ((ilen+3) < remain) {
instruction->modRMForm.displ32u = FetchDWORD(iptr);
iptr += 4;
@ -3638,7 +3691,7 @@ fetch_b1:
else
instruction->ResolveModrm = Resolve64BaseIndex[base];
if (BX_NULL_SEG_REG(instruction->seg()))
instruction->setSeg(BX_CPU_THIS_PTR sreg_mod0_base32[base]);
instruction->setSeg(sreg_mod0_base32[base]);
if ((base & 0x7) == 5)
goto get_32bit_displ;
// mod==00b, rm==4, base!=5
@ -3650,7 +3703,7 @@ fetch_b1:
else
instruction->ResolveModrm = BxResolve64BaseIndex;
if (BX_NULL_SEG_REG(instruction->seg()))
instruction->setSeg(BX_CPU_THIS_PTR sreg_mod1or2_base32[base]);
instruction->setSeg(sreg_mod1or2_base32[base]);
goto get_8bit_displ;
}
// (mod == 0x80), mod==10b, rm==4
@ -3659,7 +3712,7 @@ fetch_b1:
else
instruction->ResolveModrm = BxResolve64BaseIndex;
if (BX_NULL_SEG_REG(instruction->seg()))
instruction->setSeg(BX_CPU_THIS_PTR sreg_mod1or2_base32[base]);
instruction->setSeg(sreg_mod1or2_base32[base]);
goto get_32bit_displ;
}
}
@ -3685,7 +3738,7 @@ fetch_b1:
if (mod == 0x40) { // mod == 01b
instruction->ResolveModrm = BxResolve32Rm;
if (BX_NULL_SEG_REG(instruction->seg()))
instruction->setSeg(BX_CPU_THIS_PTR sreg_mod01or10_rm32[rm]);
instruction->setSeg(sreg_mod01or10_rm32[rm]);
get_8bit_displ:
if (ilen < remain) {
// 8 sign extended to 32
@ -3698,7 +3751,7 @@ get_8bit_displ:
// (mod == 0x80) mod == 10b
instruction->ResolveModrm = BxResolve32Rm;
if (BX_NULL_SEG_REG(instruction->seg()))
instruction->setSeg(BX_CPU_THIS_PTR sreg_mod01or10_rm32[rm]);
instruction->setSeg(sreg_mod01or10_rm32[rm]);
get_32bit_displ:
if ((ilen+3) < remain) {
instruction->modRMForm.displ32u = FetchDWORD(iptr);
@ -3729,7 +3782,7 @@ get_32bit_displ:
else
instruction->ResolveModrm = Resolve32BaseIndex[base];
if (BX_NULL_SEG_REG(instruction->seg()))
instruction->setSeg(BX_CPU_THIS_PTR sreg_mod0_base32[base]);
instruction->setSeg(sreg_mod0_base32[base]);
if ((base & 0x7) == 5)
goto get_32bit_displ;
// mod==00b, rm==4, base!=5
@ -3741,7 +3794,7 @@ get_32bit_displ:
else
instruction->ResolveModrm = BxResolve32BaseIndex;
if (BX_NULL_SEG_REG(instruction->seg()))
instruction->setSeg(BX_CPU_THIS_PTR sreg_mod1or2_base32[base]);
instruction->setSeg(sreg_mod1or2_base32[base]);
goto get_8bit_displ;
}
// (mod == 0x80), mod==10b, rm==4
@ -3750,7 +3803,7 @@ get_32bit_displ:
else
instruction->ResolveModrm = BxResolve32BaseIndex;
if (BX_NULL_SEG_REG(instruction->seg()))
instruction->setSeg(BX_CPU_THIS_PTR sreg_mod1or2_base32[base]);
instruction->setSeg(sreg_mod1or2_base32[base]);
goto get_32bit_displ;
}
}

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: init.cc,v 1.143 2007-11-11 20:44:07 sshwarts Exp $
// $Id: init.cc,v 1.144 2007-11-18 21:07:40 sshwarts Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2001 MandrakeSoft S.A.
@ -163,95 +163,9 @@ void BX_CPU_C::initialize(BX_MEM_C *addrspace)
// in SMP mode, the prefix of the CPU will be changed to [CPUn] in
// bx_local_apic_c::set_id as soon as the apic ID is assigned.
// <TAG-INIT-CPU-START>
// for decoding instructions: access to seg reg's via index number
sreg_mod00_rm16[0] = BX_SEG_REG_DS;
sreg_mod00_rm16[1] = BX_SEG_REG_DS;
sreg_mod00_rm16[2] = BX_SEG_REG_SS;
sreg_mod00_rm16[3] = BX_SEG_REG_SS;
sreg_mod00_rm16[4] = BX_SEG_REG_DS;
sreg_mod00_rm16[5] = BX_SEG_REG_DS;
sreg_mod00_rm16[6] = BX_SEG_REG_DS;
sreg_mod00_rm16[7] = BX_SEG_REG_DS;
sreg_mod01or10_rm16[0] = BX_SEG_REG_DS;
sreg_mod01or10_rm16[1] = BX_SEG_REG_DS;
sreg_mod01or10_rm16[2] = BX_SEG_REG_SS;
sreg_mod01or10_rm16[3] = BX_SEG_REG_SS;
sreg_mod01or10_rm16[4] = BX_SEG_REG_DS;
sreg_mod01or10_rm16[5] = BX_SEG_REG_DS;
sreg_mod01or10_rm16[6] = BX_SEG_REG_SS;
sreg_mod01or10_rm16[7] = BX_SEG_REG_DS;
// the default segment to use for a one-byte modrm with
// mod==01b or mod==10b and rm == i
sreg_mod01or10_rm32[0] = BX_SEG_REG_DS;
sreg_mod01or10_rm32[1] = BX_SEG_REG_DS;
sreg_mod01or10_rm32[2] = BX_SEG_REG_DS;
sreg_mod01or10_rm32[3] = BX_SEG_REG_DS;
sreg_mod01or10_rm32[4] = BX_SEG_REG_NULL;
// this entry should never be accessed
// (escape to 2-byte)
sreg_mod01or10_rm32[5] = BX_SEG_REG_SS;
sreg_mod01or10_rm32[6] = BX_SEG_REG_DS;
sreg_mod01or10_rm32[7] = BX_SEG_REG_DS;
#if BX_SUPPORT_X86_64
sreg_mod01or10_rm32[8] = BX_SEG_REG_DS;
sreg_mod01or10_rm32[9] = BX_SEG_REG_DS;
sreg_mod01or10_rm32[10] = BX_SEG_REG_DS;
sreg_mod01or10_rm32[11] = BX_SEG_REG_DS;
sreg_mod01or10_rm32[12] = BX_SEG_REG_DS;
sreg_mod01or10_rm32[13] = BX_SEG_REG_DS;
sreg_mod01or10_rm32[14] = BX_SEG_REG_DS;
sreg_mod01or10_rm32[15] = BX_SEG_REG_DS;
#endif
// the default segment to use for a two-byte modrm with
// mod==00b and base == i
sreg_mod0_base32[0] = BX_SEG_REG_DS;
sreg_mod0_base32[1] = BX_SEG_REG_DS;
sreg_mod0_base32[2] = BX_SEG_REG_DS;
sreg_mod0_base32[3] = BX_SEG_REG_DS;
sreg_mod0_base32[4] = BX_SEG_REG_SS;
sreg_mod0_base32[5] = BX_SEG_REG_DS;
sreg_mod0_base32[6] = BX_SEG_REG_DS;
sreg_mod0_base32[7] = BX_SEG_REG_DS;
#if BX_SUPPORT_X86_64
sreg_mod0_base32[8] = BX_SEG_REG_DS;
sreg_mod0_base32[9] = BX_SEG_REG_DS;
sreg_mod0_base32[10] = BX_SEG_REG_DS;
sreg_mod0_base32[11] = BX_SEG_REG_DS;
sreg_mod0_base32[12] = BX_SEG_REG_DS;
sreg_mod0_base32[13] = BX_SEG_REG_DS;
sreg_mod0_base32[14] = BX_SEG_REG_DS;
sreg_mod0_base32[15] = BX_SEG_REG_DS;
#endif
// the default segment to use for a two-byte modrm with
// mod==01b or mod==10b and base == i
sreg_mod1or2_base32[0] = BX_SEG_REG_DS;
sreg_mod1or2_base32[1] = BX_SEG_REG_DS;
sreg_mod1or2_base32[2] = BX_SEG_REG_DS;
sreg_mod1or2_base32[3] = BX_SEG_REG_DS;
sreg_mod1or2_base32[4] = BX_SEG_REG_SS;
sreg_mod1or2_base32[5] = BX_SEG_REG_SS;
sreg_mod1or2_base32[6] = BX_SEG_REG_DS;
sreg_mod1or2_base32[7] = BX_SEG_REG_DS;
#if BX_SUPPORT_X86_64
sreg_mod1or2_base32[8] = BX_SEG_REG_DS;
sreg_mod1or2_base32[9] = BX_SEG_REG_DS;
sreg_mod1or2_base32[10] = BX_SEG_REG_DS;
sreg_mod1or2_base32[11] = BX_SEG_REG_DS;
sreg_mod1or2_base32[12] = BX_SEG_REG_DS;
sreg_mod1or2_base32[13] = BX_SEG_REG_DS;
sreg_mod1or2_base32[14] = BX_SEG_REG_DS;
sreg_mod1or2_base32[15] = BX_SEG_REG_DS;
#endif
// <TAG-INIT-CPU-END>
sprintf(name, "CPU %d", BX_CPU_ID);
mem = addrspace;
sprintf(name, "CPU %d", BX_CPU_ID);
#if BX_WITH_WX
register_wx_state();

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: main.cc,v 1.365 2007-11-18 18:27:09 sshwarts Exp $
// $Id: main.cc,v 1.366 2007-11-18 21:07:40 sshwarts Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2002 MandrakeSoft S.A.
@ -1234,8 +1234,8 @@ void bx_signal_handler(int signum)
bx_gui->show_ips((Bit32u) ips_count);
ticks_count = bx_pc_system.time_ticks();
counts++;
// printf("MIPS: %u\tticks/counts = %u\t(%us)\n",
// (unsigned) ips_count, (unsigned) (ticks_count/counts), (unsigned) counts);
printf("MIPS: %u\tticks/counts = %u\t\t(%us)\n",
(unsigned) ips_count, (unsigned) (ticks_count/counts), (unsigned) counts);
}
#if !defined(__MINGW32__) && !defined(_MSC_VER)
signal(SIGALRM, bx_signal_handler);