clang format in cpu
This commit is contained in:
@@ -40,128 +40,137 @@
|
||||
*/
|
||||
#include "x86_ops.h"
|
||||
|
||||
#define ILLEGAL_ON(cond) \
|
||||
do { \
|
||||
if ((cond)) { \
|
||||
cpu_state.pc = cpu_state.oldpc; \
|
||||
x86illegal(); \
|
||||
return 0; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define ILLEGAL_ON(cond) \
|
||||
do \
|
||||
{ \
|
||||
if ((cond)) \
|
||||
{ \
|
||||
cpu_state.pc = cpu_state.oldpc; \
|
||||
x86illegal(); \
|
||||
return 0; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
static __inline void PUSH_W(uint16_t val)
|
||||
static __inline void
|
||||
PUSH_W(uint16_t val)
|
||||
{
|
||||
if (stack32)
|
||||
{
|
||||
writememw(ss, ESP - 2, val); if (cpu_state.abrt) return;
|
||||
ESP -= 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
writememw(ss, (SP - 2) & 0xFFFF, val); if (cpu_state.abrt) return;
|
||||
SP -= 2;
|
||||
}
|
||||
if (stack32) {
|
||||
writememw(ss, ESP - 2, val);
|
||||
if (cpu_state.abrt)
|
||||
return;
|
||||
ESP -= 2;
|
||||
} else {
|
||||
writememw(ss, (SP - 2) & 0xFFFF, val);
|
||||
if (cpu_state.abrt)
|
||||
return;
|
||||
SP -= 2;
|
||||
}
|
||||
}
|
||||
|
||||
static __inline void PUSH_L(uint32_t val)
|
||||
static __inline void
|
||||
PUSH_L(uint32_t val)
|
||||
{
|
||||
if (stack32)
|
||||
{
|
||||
writememl(ss, ESP - 4, val); if (cpu_state.abrt) return;
|
||||
ESP -= 4;
|
||||
}
|
||||
else
|
||||
{
|
||||
writememl(ss, (SP - 4) & 0xFFFF, val); if (cpu_state.abrt) return;
|
||||
SP -= 4;
|
||||
}
|
||||
if (stack32) {
|
||||
writememl(ss, ESP - 4, val);
|
||||
if (cpu_state.abrt)
|
||||
return;
|
||||
ESP -= 4;
|
||||
} else {
|
||||
writememl(ss, (SP - 4) & 0xFFFF, val);
|
||||
if (cpu_state.abrt)
|
||||
return;
|
||||
SP -= 4;
|
||||
}
|
||||
}
|
||||
|
||||
static __inline uint16_t POP_W(void)
|
||||
static __inline uint16_t
|
||||
POP_W(void)
|
||||
{
|
||||
uint16_t ret;
|
||||
if (stack32)
|
||||
{
|
||||
ret = readmemw(ss, ESP); if (cpu_state.abrt) return 0;
|
||||
ESP += 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = readmemw(ss, SP); if (cpu_state.abrt) return 0;
|
||||
SP += 2;
|
||||
}
|
||||
return ret;
|
||||
uint16_t ret;
|
||||
if (stack32) {
|
||||
ret = readmemw(ss, ESP);
|
||||
if (cpu_state.abrt)
|
||||
return 0;
|
||||
ESP += 2;
|
||||
} else {
|
||||
ret = readmemw(ss, SP);
|
||||
if (cpu_state.abrt)
|
||||
return 0;
|
||||
SP += 2;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static __inline uint32_t POP_L(void)
|
||||
static __inline uint32_t
|
||||
POP_L(void)
|
||||
{
|
||||
uint32_t ret;
|
||||
if (stack32)
|
||||
{
|
||||
ret = readmeml(ss, ESP); if (cpu_state.abrt) return 0;
|
||||
ESP += 4;
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = readmeml(ss, SP); if (cpu_state.abrt) return 0;
|
||||
SP += 4;
|
||||
}
|
||||
return ret;
|
||||
uint32_t ret;
|
||||
if (stack32) {
|
||||
ret = readmeml(ss, ESP);
|
||||
if (cpu_state.abrt)
|
||||
return 0;
|
||||
ESP += 4;
|
||||
} else {
|
||||
ret = readmeml(ss, SP);
|
||||
if (cpu_state.abrt)
|
||||
return 0;
|
||||
SP += 4;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static __inline uint16_t POP_W_seg(uint32_t seg)
|
||||
static __inline uint16_t
|
||||
POP_W_seg(uint32_t seg)
|
||||
{
|
||||
uint16_t ret;
|
||||
if (stack32)
|
||||
{
|
||||
ret = readmemw(seg, ESP); if (cpu_state.abrt) return 0;
|
||||
ESP += 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = readmemw(seg, SP); if (cpu_state.abrt) return 0;
|
||||
SP += 2;
|
||||
}
|
||||
return ret;
|
||||
uint16_t ret;
|
||||
if (stack32) {
|
||||
ret = readmemw(seg, ESP);
|
||||
if (cpu_state.abrt)
|
||||
return 0;
|
||||
ESP += 2;
|
||||
} else {
|
||||
ret = readmemw(seg, SP);
|
||||
if (cpu_state.abrt)
|
||||
return 0;
|
||||
SP += 2;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static __inline uint32_t POP_L_seg(uint32_t seg)
|
||||
static __inline uint32_t
|
||||
POP_L_seg(uint32_t seg)
|
||||
{
|
||||
uint32_t ret;
|
||||
if (stack32)
|
||||
{
|
||||
ret = readmeml(seg, ESP); if (cpu_state.abrt) return 0;
|
||||
ESP += 4;
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = readmeml(seg, SP); if (cpu_state.abrt) return 0;
|
||||
SP += 4;
|
||||
}
|
||||
return ret;
|
||||
uint32_t ret;
|
||||
if (stack32) {
|
||||
ret = readmeml(seg, ESP);
|
||||
if (cpu_state.abrt)
|
||||
return 0;
|
||||
ESP += 4;
|
||||
} else {
|
||||
ret = readmeml(seg, SP);
|
||||
if (cpu_state.abrt)
|
||||
return 0;
|
||||
SP += 4;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int fopcode;
|
||||
|
||||
static int ILLEGAL(uint32_t fetchdat)
|
||||
static int
|
||||
ILLEGAL(uint32_t fetchdat)
|
||||
{
|
||||
pclog("[%04X:%08X] Illegal instruction %08X (%02X)\n", CS, cpu_state.pc, fetchdat, fopcode);
|
||||
cpu_state.pc = cpu_state.oldpc;
|
||||
pclog("[%04X:%08X] Illegal instruction %08X (%02X)\n", CS, cpu_state.pc, fetchdat, fopcode);
|
||||
cpu_state.pc = cpu_state.oldpc;
|
||||
|
||||
x86illegal();
|
||||
return 0;
|
||||
x86illegal();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
#ifdef ENABLE_386_DYNAREC_LOG
|
||||
extern void x386_dynarec_log(const char *fmt, ...);
|
||||
extern void x386_dynarec_log(const char *fmt, ...);
|
||||
#else
|
||||
#ifndef x386_dynarec_log
|
||||
#define x386_dynarec_log(fmt, ...)
|
||||
#endif
|
||||
# ifndef x386_dynarec_log
|
||||
# define x386_dynarec_log(fmt, ...)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#include "x86seg.h"
|
||||
@@ -196,9 +205,9 @@ extern void x386_dynarec_log(const char *fmt, ...);
|
||||
#include "x86_ops_pmode.h"
|
||||
#include "x86_ops_prefix.h"
|
||||
#ifdef IS_DYNAREC
|
||||
#include "x86_ops_rep_dyn.h"
|
||||
# include "x86_ops_rep_dyn.h"
|
||||
#else
|
||||
#include "x86_ops_rep.h"
|
||||
# include "x86_ops_rep.h"
|
||||
#endif
|
||||
#include "x86_ops_ret.h"
|
||||
#include "x86_ops_set.h"
|
||||
@@ -211,157 +220,160 @@ extern void x386_dynarec_log(const char *fmt, ...);
|
||||
#include "x86_ops_3dnow.h"
|
||||
#include <time.h>
|
||||
|
||||
|
||||
static int opVPCEXT(uint32_t fetchdat)
|
||||
static int
|
||||
opVPCEXT(uint32_t fetchdat)
|
||||
{
|
||||
uint8_t b1, b2;
|
||||
uint16_t cent;
|
||||
time_t now;
|
||||
struct tm *tm;
|
||||
uint8_t b1, b2;
|
||||
uint16_t cent;
|
||||
time_t now;
|
||||
struct tm *tm;
|
||||
|
||||
if (!is_vpc) /* only emulate this on Virtual PC machines */
|
||||
return ILLEGAL(fetchdat);
|
||||
if (!is_vpc) /* only emulate this on Virtual PC machines */
|
||||
return ILLEGAL(fetchdat);
|
||||
|
||||
cpu_state.pc += 2;
|
||||
cpu_state.pc += 2;
|
||||
|
||||
b1 = fetchdat & 0xff;
|
||||
b2 = (fetchdat >> 8) & 0xff;
|
||||
b1 = fetchdat & 0xff;
|
||||
b2 = (fetchdat >> 8) & 0xff;
|
||||
|
||||
/* a lot of these opcodes (which?) return illegal instruction in user mode */
|
||||
ILLEGAL_ON(CPL > 0);
|
||||
/* a lot of these opcodes (which?) return illegal instruction in user mode */
|
||||
ILLEGAL_ON(CPL > 0);
|
||||
|
||||
CLOCK_CYCLES(1);
|
||||
CLOCK_CYCLES(1);
|
||||
|
||||
/* 0f 3f 03 xx opcodes are mostly related to the host clock, so fetch it now */
|
||||
if (b1 == 0x03) {
|
||||
(void)time(&now);
|
||||
tm = localtime(&now);
|
||||
}
|
||||
/* 0f 3f 03 xx opcodes are mostly related to the host clock, so fetch it now */
|
||||
if (b1 == 0x03) {
|
||||
(void) time(&now);
|
||||
tm = localtime(&now);
|
||||
}
|
||||
|
||||
if ((b1 == 0x07) && (b2 == 0x0b)) {
|
||||
/* 0f 3f 07 0b: unknown, EDX output depends on EAX input */
|
||||
switch (EAX) {
|
||||
case 0x00000000:
|
||||
EDX = 0x00000003;
|
||||
break;
|
||||
if ((b1 == 0x07) && (b2 == 0x0b)) {
|
||||
/* 0f 3f 07 0b: unknown, EDX output depends on EAX input */
|
||||
switch (EAX) {
|
||||
case 0x00000000:
|
||||
EDX = 0x00000003;
|
||||
break;
|
||||
|
||||
case 0x00000001:
|
||||
EDX = 0x00000012;
|
||||
break;
|
||||
case 0x00000001:
|
||||
EDX = 0x00000012;
|
||||
break;
|
||||
|
||||
case 0x00000002:
|
||||
case 0x00000003:
|
||||
case 0x00000004:
|
||||
case 0x00000005:
|
||||
EDX = 0x00000001;
|
||||
break;
|
||||
case 0x00000002:
|
||||
case 0x00000003:
|
||||
case 0x00000004:
|
||||
case 0x00000005:
|
||||
EDX = 0x00000001;
|
||||
break;
|
||||
|
||||
case 0x00000007:
|
||||
EDX = 0x0000009c;
|
||||
break;
|
||||
case 0x00000007:
|
||||
EDX = 0x0000009c;
|
||||
break;
|
||||
|
||||
default:
|
||||
EDX = 0x00000000;
|
||||
if (EAX > 0x00000012) /* unknown EAX values set zero flag */
|
||||
cpu_state.flags &= ~(Z_FLAG);
|
||||
}
|
||||
} else if ((b1 == 0x03) && (b2 == 0x00)) {
|
||||
/* 0f 3f 03 00: host time in BCD */
|
||||
EDX = BCD8(tm->tm_hour);
|
||||
ECX = BCD8(tm->tm_min);
|
||||
EAX = BCD8(tm->tm_sec);
|
||||
} else if ((b1 == 0x03) && (b2 == 0x01)) {
|
||||
/* 0f 3f 03 00: host date in BCD */
|
||||
EDX = BCD8(tm->tm_year % 100);
|
||||
ECX = BCD8(tm->tm_mon + 1);
|
||||
EAX = BCD8(tm->tm_mday);
|
||||
cent = (((tm->tm_year - (tm->tm_year % 100)) / 100) % 4); /* Sunday = 0 */
|
||||
EBX = ((tm->tm_mday + tm->tm_mon + (tm->tm_year % 100) + cent + 3) % 7);
|
||||
} else if ((b1 == 0x03) && (b2 == 0x03)) {
|
||||
/* 0f 3f 03 03: host time in binary */
|
||||
EDX = tm->tm_hour;
|
||||
ECX = tm->tm_min;
|
||||
EAX = tm->tm_sec;
|
||||
} else if ((b1 == 0x03) && (b2 == 0x04)) {
|
||||
/* 0f 3f 03 04: host date in binary */
|
||||
EDX = 1900 + tm->tm_year;
|
||||
ECX = tm->tm_mon + 1;
|
||||
EBX = tm->tm_mday;
|
||||
} else if ((b1 == 0x03) && (b2 == 0x05)) {
|
||||
/* 0f 3f 03 05: unknown */
|
||||
EBX = 0x0000000F;
|
||||
ECX = 0x0000000A;
|
||||
} else if ((b1 == 0x03) && (b2 == 0x06)) {
|
||||
/* 0f 3f 03 06: some kind of timestamp. BX jumps around very quickly, CX not so much. */
|
||||
EBX = 0x00000000;
|
||||
ECX = 0x00000000;
|
||||
} else if ((b1 == 0x03) && (b2 >= 0x07)) {
|
||||
/* 0f 3f 03 07+: set zero flag */
|
||||
cpu_state.flags &= ~(Z_FLAG);
|
||||
} else if ((b1 == 0x0a) && (b2 == 0x00)) {
|
||||
/* 0f 3f 0a 00: memory size in KB */
|
||||
EAX = mem_size;
|
||||
} else if ((b1 == 0x11) && (b2 == 0x00)) {
|
||||
/* 0f 3f 11 00: unknown, set EAX to 0 */
|
||||
EAX = 0x00000000;
|
||||
} else if ((b1 == 0x11) && (b2 == 0x01)) {
|
||||
/* 0f 3f 11 00: unknown, set EAX to 0 and set zero flag */
|
||||
EAX = 0x00000000;
|
||||
cpu_state.flags &= ~(Z_FLAG);
|
||||
} else if ((b1 == 0x11) && (b2 == 0x02)) {
|
||||
/* 0f 3f 11 02: unknown, no-op */
|
||||
} else {
|
||||
/* other unknown opcodes: illegal instruction */
|
||||
cpu_state.pc = cpu_state.oldpc;
|
||||
default:
|
||||
EDX = 0x00000000;
|
||||
if (EAX > 0x00000012) /* unknown EAX values set zero flag */
|
||||
cpu_state.flags &= ~(Z_FLAG);
|
||||
}
|
||||
} else if ((b1 == 0x03) && (b2 == 0x00)) {
|
||||
/* 0f 3f 03 00: host time in BCD */
|
||||
EDX = BCD8(tm->tm_hour);
|
||||
ECX = BCD8(tm->tm_min);
|
||||
EAX = BCD8(tm->tm_sec);
|
||||
} else if ((b1 == 0x03) && (b2 == 0x01)) {
|
||||
/* 0f 3f 03 00: host date in BCD */
|
||||
EDX = BCD8(tm->tm_year % 100);
|
||||
ECX = BCD8(tm->tm_mon + 1);
|
||||
EAX = BCD8(tm->tm_mday);
|
||||
cent = (((tm->tm_year - (tm->tm_year % 100)) / 100) % 4); /* Sunday = 0 */
|
||||
EBX = ((tm->tm_mday + tm->tm_mon + (tm->tm_year % 100) + cent + 3) % 7);
|
||||
} else if ((b1 == 0x03) && (b2 == 0x03)) {
|
||||
/* 0f 3f 03 03: host time in binary */
|
||||
EDX = tm->tm_hour;
|
||||
ECX = tm->tm_min;
|
||||
EAX = tm->tm_sec;
|
||||
} else if ((b1 == 0x03) && (b2 == 0x04)) {
|
||||
/* 0f 3f 03 04: host date in binary */
|
||||
EDX = 1900 + tm->tm_year;
|
||||
ECX = tm->tm_mon + 1;
|
||||
EBX = tm->tm_mday;
|
||||
} else if ((b1 == 0x03) && (b2 == 0x05)) {
|
||||
/* 0f 3f 03 05: unknown */
|
||||
EBX = 0x0000000F;
|
||||
ECX = 0x0000000A;
|
||||
} else if ((b1 == 0x03) && (b2 == 0x06)) {
|
||||
/* 0f 3f 03 06: some kind of timestamp. BX jumps around very quickly, CX not so much. */
|
||||
EBX = 0x00000000;
|
||||
ECX = 0x00000000;
|
||||
} else if ((b1 == 0x03) && (b2 >= 0x07)) {
|
||||
/* 0f 3f 03 07+: set zero flag */
|
||||
cpu_state.flags &= ~(Z_FLAG);
|
||||
} else if ((b1 == 0x0a) && (b2 == 0x00)) {
|
||||
/* 0f 3f 0a 00: memory size in KB */
|
||||
EAX = mem_size;
|
||||
} else if ((b1 == 0x11) && (b2 == 0x00)) {
|
||||
/* 0f 3f 11 00: unknown, set EAX to 0 */
|
||||
EAX = 0x00000000;
|
||||
} else if ((b1 == 0x11) && (b2 == 0x01)) {
|
||||
/* 0f 3f 11 00: unknown, set EAX to 0 and set zero flag */
|
||||
EAX = 0x00000000;
|
||||
cpu_state.flags &= ~(Z_FLAG);
|
||||
} else if ((b1 == 0x11) && (b2 == 0x02)) {
|
||||
/* 0f 3f 11 02: unknown, no-op */
|
||||
} else {
|
||||
/* other unknown opcodes: illegal instruction */
|
||||
cpu_state.pc = cpu_state.oldpc;
|
||||
|
||||
pclog("Illegal VPCEXT %08X (%02X %02X)\n", fetchdat, b1, b2);
|
||||
x86illegal();
|
||||
return 0;
|
||||
}
|
||||
pclog("Illegal VPCEXT %08X (%02X %02X)\n", fetchdat, b1, b2);
|
||||
x86illegal();
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
static int op0F_w_a16(uint32_t fetchdat)
|
||||
static int
|
||||
op0F_w_a16(uint32_t fetchdat)
|
||||
{
|
||||
int opcode = fetchdat & 0xff;
|
||||
fopcode = opcode;
|
||||
cpu_state.pc++;
|
||||
int opcode = fetchdat & 0xff;
|
||||
fopcode = opcode;
|
||||
cpu_state.pc++;
|
||||
|
||||
PREFETCH_PREFIX();
|
||||
PREFETCH_PREFIX();
|
||||
|
||||
return x86_opcodes_0f[opcode](fetchdat >> 8);
|
||||
return x86_opcodes_0f[opcode](fetchdat >> 8);
|
||||
}
|
||||
static int op0F_l_a16(uint32_t fetchdat)
|
||||
static int
|
||||
op0F_l_a16(uint32_t fetchdat)
|
||||
{
|
||||
int opcode = fetchdat & 0xff;
|
||||
fopcode = opcode;
|
||||
cpu_state.pc++;
|
||||
int opcode = fetchdat & 0xff;
|
||||
fopcode = opcode;
|
||||
cpu_state.pc++;
|
||||
|
||||
PREFETCH_PREFIX();
|
||||
PREFETCH_PREFIX();
|
||||
|
||||
return x86_opcodes_0f[opcode | 0x100](fetchdat >> 8);
|
||||
return x86_opcodes_0f[opcode | 0x100](fetchdat >> 8);
|
||||
}
|
||||
static int op0F_w_a32(uint32_t fetchdat)
|
||||
static int
|
||||
op0F_w_a32(uint32_t fetchdat)
|
||||
{
|
||||
int opcode = fetchdat & 0xff;
|
||||
fopcode = opcode;
|
||||
cpu_state.pc++;
|
||||
int opcode = fetchdat & 0xff;
|
||||
fopcode = opcode;
|
||||
cpu_state.pc++;
|
||||
|
||||
PREFETCH_PREFIX();
|
||||
PREFETCH_PREFIX();
|
||||
|
||||
return x86_opcodes_0f[opcode | 0x200](fetchdat >> 8);
|
||||
return x86_opcodes_0f[opcode | 0x200](fetchdat >> 8);
|
||||
}
|
||||
static int op0F_l_a32(uint32_t fetchdat)
|
||||
static int
|
||||
op0F_l_a32(uint32_t fetchdat)
|
||||
{
|
||||
int opcode = fetchdat & 0xff;
|
||||
fopcode = opcode;
|
||||
cpu_state.pc++;
|
||||
int opcode = fetchdat & 0xff;
|
||||
fopcode = opcode;
|
||||
cpu_state.pc++;
|
||||
|
||||
PREFETCH_PREFIX();
|
||||
PREFETCH_PREFIX();
|
||||
|
||||
return x86_opcodes_0f[opcode | 0x300](fetchdat >> 8);
|
||||
return x86_opcodes_0f[opcode | 0x300](fetchdat >> 8);
|
||||
}
|
||||
|
||||
const OpFn OP_TABLE(186_0f)[1024] =
|
||||
|
||||
Reference in New Issue
Block a user