7 #include "../common/allocator.h"
91 if (numoperands == 2) {
108 #define EXTMACRO_BEGIN do {
110 #define EXTMACRO_END } __pragma(warning(push)) __pragma(warning(disable:4127)) while (0) __pragma(warning(pop))
112 #define EXTMACRO_END } while (0)
117 #define SignFlag 0x80000000
119 #define SignExtend(a) ((uint32_t)((int8_t)(a)))
124 #define GetOperand1() _RARGetOperand(vm, opcode->addressingmode1, opcode->value1, opcode->bytemode & 1)
125 #define GetOperand2() _RARGetOperand(vm, opcode->addressingmode2, opcode->value2, opcode->bytemode & 2)
126 #define SetOperand1(data) _RARSetOperand(vm, opcode->addressingmode1, opcode->value1, opcode->bytemode & 1, data)
127 #define SetOperand2(data) _RARSetOperand(vm, opcode->addressingmode2, opcode->value2, opcode->bytemode & 2, data)
129 #define SetFlagsWithCarry(res, carry) EXTMACRO_BEGIN uint32_t result = (res); flags = (result == 0 ? ZeroFlag : (result & SignFlag)) | ((carry) ? CarryFlag : 0); EXTMACRO_END
130 #define SetByteFlagsWithCarry(res, carry) EXTMACRO_BEGIN uint8_t result = (res); flags = (result == 0 ? ZeroFlag : (SignExtend(result) & SignFlag)) | ((carry) ? CarryFlag : 0); EXTMACRO_END
131 #define SetFlags(res) SetFlagsWithCarry(res, 0)
133 #define SetOperand1AndFlagsWithCarry(res, carry) EXTMACRO_BEGIN uint32_t r = (res); SetFlagsWithCarry(r, carry); SetOperand1(r); EXTMACRO_END
134 #define SetOperand1AndByteFlagsWithCarry(res, carry) EXTMACRO_BEGIN uint8_t r = (res); SetByteFlagsWithCarry(r, carry); SetOperand1(r); EXTMACRO_END
135 #define SetOperand1AndFlags(res) EXTMACRO_BEGIN uint32_t r = (res); SetFlags(r); SetOperand1(r); EXTMACRO_END
137 #define NextInstruction() { opcode++; continue; }
138 #define Jump(offs) { uint32_t o = (offs); if (o >= prog->length) return false; opcode = &prog->opcodes[o]; continue; }
144 uint32_t op1, op2, carry, i;
145 uint32_t counter = 0;
185 if (!(flags & ZeroFlag))
228 if (!(flags & SignFlag))
238 if ((flags & (CarryFlag | ZeroFlag)))
243 if (!(flags & (CarryFlag | ZeroFlag)))
248 if (!(flags & CarryFlag))
302 for (i = 0; i < 8; i++)
307 for (i = 0; i < 8; i++)
378 return ((uint32_t)b[3] << 24) | ((uint32_t)b[2] << 16) | ((uint32_t)b[1] << 8) | (uint32_t)b[0];
383 b[3] = (n >> 24) & 0xFF;
384 b[2] = (n >> 16) & 0xFF;
385 b[1] = (n >> 8) & 0xFF;
420 uint32_t result = vm->
registers[addressingmode % 8];
422 result = result & 0xFF;
449 vm->
registers[addressingmode % 8] = data;
473 #define RAR0OperandsFlag 0
474 #define RAR1OperandFlag 1
475 #define RAR2OperandsFlag 2
476 #define RAROperandsFlag 3
477 #define RARHasByteModeFlag 4
478 #define RARIsUnconditionalJumpFlag 8
479 #define RARIsRelativeJumpFlag 16
480 #define RARWritesFirstOperandFlag 32
481 #define RARWritesSecondOperandFlag 64
482 #define RARReadsStatusFlag 128
483 #define RARWritesStatusFlag 256
578 printf(
"r%d", addressingmode % 8);
580 printf(
"@(r%d)", addressingmode % 8);
582 printf(
"@(r%d+$%02x)", addressingmode % 8, value);
584 printf(
"@($%02x)", value);
586 printf(
"$%02x", value);
592 "Mov",
"Cmp",
"Add",
"Sub",
"Jz",
"Jnz",
"Inc",
"Dec",
"Jmp",
"Xor",
593 "And",
"Or",
"Test",
"Js",
"Jns",
"Jb",
"Jbe",
"Ja",
"Jae",
"Push",
594 "Pop",
"Call",
"Ret",
"Not",
"Shl",
"Shr",
"Sar",
"Neg",
"Pusha",
"Popa",
595 "Pushf",
"Popf",
"Movzx",
"Movsx",
"Xchg",
"Mul",
"Div",
"Adc",
"Sbb",
"Print",
599 for (i = 0; i < prog->
length; i++) {
602 printf(
" %02x: %s", i, instructionNames[opcode->
instruction]);
605 if (numoperands >= 1) {
609 if (numoperands == 2) {