more cleanups, remove nemu

This commit is contained in:
Yanyan Jiang 2017-05-26 12:49:00 -04:00
parent 2b61b3afa0
commit f198252791
207 changed files with 1 additions and 6977 deletions

View File

@ -1,3 +0,0 @@
# NEMU
A x86 full-system (partial) emulator.

View File

@ -1,39 +0,0 @@
#ifndef __COMMON_H__
#define __COMMON_H__
//#define USE_RAMDISK
/* You will define this macro in PA4 */
#define HAS_DEVICE
//#define DEBUG
#define LOG_FILE
#include "debug.h"
#include "macro.h"
#include <stdint.h>
#include <assert.h>
#include <string.h>
typedef uint8_t bool;
typedef uint32_t hwaddr_t;
typedef uint32_t lnaddr_t;
typedef uint32_t swaddr_t;
typedef uint16_t ioaddr_t;
#pragma pack (1)
typedef union {
uint32_t _4;
uint32_t _3 : 24;
uint16_t _2;
uint8_t _1;
} unalign;
#pragma pack ()
#define false 0
#define true 1
#endif

View File

@ -1,57 +0,0 @@
#ifndef __DECODE_H__
#define __DECODE_H__
#include "cpu/helper.h"
make_helper(decode_r_b);
make_helper(decode_r_w);
make_helper(decode_r_l);
make_helper(decode_rm_b);
make_helper(decode_rm_w);
make_helper(decode_rm_l);
make_helper(decode_i_b);
make_helper(decode_i_w);
make_helper(decode_i_l);
make_helper(decode_si_b);
make_helper(decode_si_l);
make_helper(decode_i2rm_b);
make_helper(decode_i2rm_w);
make_helper(decode_i2rm_l);
make_helper(decode_i2a_b);
make_helper(decode_i2a_w);
make_helper(decode_i2a_l);
make_helper(decode_i2r_b);
make_helper(decode_i2r_w);
make_helper(decode_i2r_l);
make_helper(decode_si2rm_w);
make_helper(decode_si2rm_l);
make_helper(decode_si_rm2r_w);
make_helper(decode_si_rm2r_l);
make_helper(decode_i_rm2r_w);
make_helper(decode_i_rm2r_l);
make_helper(decode_r2rm_b);
make_helper(decode_r2rm_w);
make_helper(decode_r2rm_l);
make_helper(decode_rm2r_b);
make_helper(decode_rm2r_w);
make_helper(decode_rm2r_l);
make_helper(decode_rm2a_b);
make_helper(decode_rm2a_w);
make_helper(decode_rm2a_l);
make_helper(decode_rm_1_b);
make_helper(decode_rm_1_w);
make_helper(decode_rm_1_l);
make_helper(decode_rm_cl_b);
make_helper(decode_rm_cl_w);
make_helper(decode_rm_cl_l);
make_helper(decode_rm_imm_b);
make_helper(decode_rm_imm_w);
make_helper(decode_rm_imm_l);
void write_operand_b(Operand *, uint8_t);
void write_operand_w(Operand *, uint16_t);
void write_operand_l(Operand *, uint32_t);
#endif

View File

@ -1,37 +0,0 @@
#ifndef __MODRM_H__
#define __MODRM_H__
#include "common.h"
#include "cpu/decode/operand.h"
/* See i386 manual for more details about instruction format. */
typedef union {
struct {
uint8_t R_M :3;
uint8_t reg :3;
uint8_t mod :2;
};
struct {
uint8_t dont_care :3;
uint8_t opcode :3;
};
uint8_t val;
} ModR_M;
typedef union {
struct {
uint8_t base :3;
uint8_t index :3;
uint8_t ss :2;
};
uint8_t val;
} SIB;
int load_addr(swaddr_t, ModR_M *, Operand *);
int read_ModR_M(swaddr_t, Operand *, Operand *);
#define MODRM_ASM_BUF_SIZE 32
extern char ModR_M_asm[];
#endif

View File

@ -1,30 +0,0 @@
#ifndef __OPERAND_H__
#define __OPERAND_H__
enum { OP_TYPE_REG, OP_TYPE_MEM, OP_TYPE_IMM };
#define OP_STR_SIZE 40
typedef struct {
uint32_t type;
size_t size;
union {
uint32_t reg;
struct {
swaddr_t addr;
uint8_t sreg;
};
uint32_t imm;
int32_t simm;
};
uint32_t val;
char str[OP_STR_SIZE];
} Operand;
typedef struct {
uint32_t opcode;
bool is_data_size_16;
Operand src, dest, src2;
} Operands;
#endif

View File

@ -1,34 +0,0 @@
#define CHANGE_PF \
uint8_t least = result & 0xFF;\
least ^= least>>4;\
least ^= least>>2;\
least ^= least>>1;\
bool test_PF = !(least & 0x1);\
test_PF?(cpu.EFLAGS.PF = 1):(cpu.EFLAGS.PF = 0);
#define CHANGE_ZF \
if(result == 0)\
cpu.EFLAGS.ZF = 1;\
else\
cpu.EFLAGS.ZF = 0;
#define CHANGE_SUB_CF \
if((DATA_TYPE)op_dest->val < (DATA_TYPE)op_src->val)\
cpu.EFLAGS.CF = 1;\
else\
cpu.EFLAGS.CF = 0;
#define CHANGE_SF \
cpu.EFLAGS.SF = MSB(result);
#define CHANGE_ADD_OF \
if(MSB(op_src->val) == MSB(op_dest->val) && MSB(result) != MSB(op_src->val))\
cpu.EFLAGS.OF = 1;\
else\
cpu.EFLAGS.OF = 0;
#define CHANGE_SUB_OF \
if((MSB(op_src->val) == 1 && MSB(op_dest->val) == 0 && MSB(result) == 1) ||(MSB(op_src->val) == 0 && MSB(op_dest->val) == 1 && MSB(result) == 0))\
cpu.EFLAGS.OF = 1;\
else\
cpu.EFLAGS.OF = 0;
#define CHANGE_ADD_CF \
if((DATA_TYPE)result < (DATA_TYPE)op_src->val || (DATA_TYPE)result < (DATA_TYPE)op_dest->val)\
cpu.EFLAGS.CF = 1;\
else\
cpu.EFLAGS.CF = 0;

View File

@ -1,35 +0,0 @@
#ifndef __EXEC_HELPER_H__
#define __EXEC_HELPER_H__
#include "cpu/helper.h"
#include "cpu/decode/decode.h"
#define make_helper_v(name) \
make_helper(concat(name, _v)) { \
return (ops_decoded.is_data_size_16 ? concat(name, _w) : concat(name, _l)) (eip); \
}
#define do_execute concat4(do_, instr, _, SUFFIX)
#define make_instr_helper(type) \
make_helper(concat5(instr, _, type, _, SUFFIX)) { \
return idex(eip, concat4(decode_, type, _, SUFFIX), do_execute); \
}
extern char assembly[];
#ifdef DEBUG
#define print_asm(...) Assert(snprintf(assembly, 80, __VA_ARGS__) < 80, "buffer overflow!")
#else
#define print_asm(...)
#endif
#define print_asm_template1() \
print_asm(str(instr) str(SUFFIX) " %s", op_src->str)
#define print_asm_template2() \
print_asm(str(instr) str(SUFFIX) " %s,%s", op_src->str, op_dest->str)
#define print_asm_template3() \
print_asm(str(instr) str(SUFFIX) " %s,%s,%s", op_src->str, op_src2->str, op_dest->str)
#endif

View File

@ -1,44 +0,0 @@
#include <setjmp.h>
#include "x86-inc/mmu.h"
#include "x86-inc/addr_struct.h"
#include "cpu/reg.h"
extern jmp_buf jbuf;
static void raise_intr(uint8_t NO) {
/* TODO: Trigger an interrupt/exception with "NO"
* That is, use "NO" to index the IDT.
*/
cpu.esp = cpu.esp - 4;
swaddr_write(cpu.esp, 4, cpu.EFLAGS.val, R_SS);
cpu.esp = cpu.esp - 4;
swaddr_write(cpu.esp, 2, cpu.CS.val, R_CS);
cpu.esp = cpu.esp - 4;
if(NO == 0x80)
swaddr_write(cpu.esp, 4, cpu.eip+2, R_CS);
else
swaddr_write(cpu.esp, 4, cpu.eip, R_CS);
gate_desc gate_temp;
gate_temp.val[0] = lnaddr_read(cpu.IDTR.IDT_BASE + NO * 8,4);
gate_temp.val[1] = lnaddr_read(cpu.IDTR.IDT_BASE + NO * 8 + 4,4);
cpu.CS.val = gate_temp.gate.segment;
sreg_desc seg_temp;
seg_temp.val[0] = lnaddr_read(cpu.GDTR.GDT_BASE + cpu.CS.INDEX * 8,4);
seg_temp.val[1] = lnaddr_read(cpu.GDTR.GDT_BASE + cpu.CS.INDEX * 8 + 4,4);
base_addr base;
limit lim;
base.base15 = seg_temp.sr_des.base_15_0;
base.base23 = seg_temp.sr_des.base_23_16;
base.base31 = seg_temp.sr_des.base_31_24;
lim.limit15 = seg_temp.sr_des.limit_15_0;
lim.limit19 = seg_temp.sr_des.limit_19_16;
cpu.CS.base = base.val;
cpu.CS.limit = lim.val;
cpu.CS.valid = true;
offset gate_offset;
gate_offset.offset15 = gate_temp.gate.offset_15_0;
gate_offset.offset31 = gate_temp.gate.offset_31_16;
cpu.eip = base.val + gate_offset.val;
/* Jump back to cpu_exec() */
longjmp(jbuf, 1);
}

View File

@ -1,14 +0,0 @@
#undef SUFFIX
#undef DATA_TYPE
#undef DATA_TYPE_S
#undef REG
#undef REG_NAME
#undef MEM_R
#undef MEM_W
#undef OPERAND_W
#undef MSB

View File

@ -1,35 +0,0 @@
#include "cpu/exec/helper.h"
#if DATA_BYTE == 1
#define SUFFIX b
#define DATA_TYPE uint8_t
#define DATA_TYPE_S int8_t
#elif DATA_BYTE == 2
#define SUFFIX w
#define DATA_TYPE uint16_t
#define DATA_TYPE_S int16_t
#elif DATA_BYTE == 4
#define SUFFIX l
#define DATA_TYPE uint32_t
#define DATA_TYPE_S int32_t
#else
#error unknown DATA_BYTE
#endif
#define REG(index) concat(reg_, SUFFIX) (index)
#define REG_NAME(index) concat(regs, SUFFIX) [index]
#define MEM_R(addr, sreg) swaddr_read(addr, DATA_BYTE, sreg)
#define MEM_W(addr, data, sreg) swaddr_write(addr, DATA_BYTE, data, sreg)
#define OPERAND_W(op, src) concat(write_operand_, SUFFIX) (op, src)
#define MSB(n) ((DATA_TYPE)(n) >> ((DATA_BYTE << 3) - 1))

View File

@ -1,30 +0,0 @@
#ifndef __HELPER_H__
#define __HELPER_H__
#include "nemu.h"
#include "cpu/decode/operand.h"
/* All function defined with 'make_helper' return the length of the operation. */
#define make_helper(name) int name(swaddr_t eip)
static inline uint32_t instr_fetch(swaddr_t addr, size_t len) {
return swaddr_read(addr, len, R_CS);
}
/* Instruction Decode and EXecute */
static inline int idex(swaddr_t eip, int (*decode)(swaddr_t), void (*execute) (void)) {
/* eip is pointing to the opcode */
int len = decode(eip + 1);
execute();
return len + 1; // "1" for opcode
}
/* shared by all helper function */
extern Operands ops_decoded;
#define op_src (&ops_decoded.src)
#define op_src2 (&ops_decoded.src2)
#define op_dest (&ops_decoded.dest)
#endif

View File

@ -1,151 +0,0 @@
#ifndef __REG_H__
#define __REG_H__
#include "common.h"
#include "x86-inc/cpu.h"
enum { R_EAX, R_ECX, R_EDX, R_EBX, R_ESP, R_EBP, R_ESI, R_EDI };
enum { R_AX, R_CX, R_DX, R_BX, R_SP, R_BP, R_SI, R_DI };
enum { R_AL, R_CL, R_DL, R_BL, R_AH, R_CH, R_DH, R_BH };
enum { R_ES, R_CS, R_SS, R_DS };
/* TODO: Re-organize the `CPU_state' structure to match the register
* encoding scheme in i386 instruction format. For example, if we
* access cpu.gpr[3]._16, we will get the `bx' register; if we access
* cpu.gpr[1]._8[1], we will get the 'ch' register. Hint: Use `union'.
* For more details about the register encoding scheme, see i386 manual.
*/
typedef struct {
union {
union {
uint32_t _32;
uint16_t _16;
uint8_t _8[2];
}gpr[8];
/* Do NOT change the order of the GPRs' definitions. */
struct {
uint32_t eax, ecx, edx, ebx, esp, ebp, esi, edi;
};
};
swaddr_t eip;
union {
struct {
uint32_t CF:1;
uint32_t D:1;
uint32_t PF:1;
uint32_t C:3;
uint32_t ZF:1;
uint32_t SF:1;
uint32_t B:1;
uint32_t IF:1;
uint32_t DF:1;
uint32_t OF:1;
uint32_t A:20;
};
uint32_t val;
}EFLAGS;
CR0 cr0;
CR3 cr3;
CR3 pre_cr3;
union {
struct {
uint16_t GDT_LIMIT;
uint32_t GDT_BASE;
};
uint64_t val : 48;
}GDTR;
union {
struct {
uint16_t IDT_LIMIT;
uint32_t IDT_BASE;
};
uint64_t val : 48;
}IDTR;
struct {
struct {
union {
struct {
uint16_t RPL : 2;
uint16_t TI : 1;
uint16_t INDEX : 13;
};
uint16_t val;
};
struct {
uint32_t base;
uint32_t limit : 20;
uint32_t root : 12;
bool valid;
};
}CS;
struct {
union {
struct {
uint16_t RPL : 2;
uint16_t TI : 1;
uint16_t INDEX : 13;
};
uint16_t val;
};
struct {
uint32_t base;
uint32_t limit : 20;
uint32_t root : 12;
bool valid;
};
}DS;
struct {
union {
struct {
uint16_t RPL : 2;
uint16_t TI : 1;
uint16_t INDEX : 13;
};
uint16_t val;
};
struct {
uint32_t base;
uint32_t limit : 20;
uint32_t root : 12;
bool valid;
};
}ES;
struct {
union {
struct {
uint16_t RPL : 2;
uint16_t TI : 1;
uint16_t INDEX : 13;
};
uint16_t val;
};
struct {
uint32_t base;
uint32_t limit : 20;
uint32_t root : 12;
bool valid;
};
}SS;
};
volatile bool INTR;
//bool INTR;
} CPU_state;
extern CPU_state cpu;
static inline int check_reg_index(int index) {
assert(index >= 0 && index < 8);
return index;
}
#define reg_l(index) (cpu.gpr[check_reg_index(index)]._32)
#define reg_w(index) (cpu.gpr[check_reg_index(index)]._16)
#define reg_b(index) (cpu.gpr[check_reg_index(index) & 0x3]._8[index >> 2])
extern const char* regsl[];
extern const char* regsw[];
extern const char* regsb[];
#endif

View File

@ -1,39 +0,0 @@
#ifndef __DEBUG_H__
#define __DEBUG_H__
#include <stdio.h>
#include <assert.h>
extern FILE* log_fp;
#ifdef LOG_FILE
# define Log_write(format, ...) fprintf(log_fp, format, ## __VA_ARGS__), fflush(log_fp)
#else
# define Log_write(format, ...)
#endif
#define Log(format, ...) \
do { \
fprintf(stdout, "\33[1;34m[%s,%d,%s] " format "\33[0m\n", \
__FILE__, __LINE__, __func__, ## __VA_ARGS__); \
fflush(stdout); \
Log_write("[%s,%d,%s] " format "\n", \
__FILE__, __LINE__, __func__, ## __VA_ARGS__); \
} while(0)
#define Assert(cond, ...) \
do { \
if(!(cond)) { \
fflush(stdout); \
fprintf(stderr, "\33[1;31m"); \
fprintf(stderr, __VA_ARGS__); \
fprintf(stderr, "\33[0m\n"); \
assert(cond); \
} \
} while(0)
#define panic(format, ...) \
Assert(0, format, ## __VA_ARGS__)
#endif

View File

@ -1,11 +0,0 @@
#ifndef __I8259_H__
#define __I8259_H__
#include "common.h"
void i8259_raise_intr(int);
uint8_t i8259_query_intr();
void i8259_ack_intr();
void do_i8259();
#endif

View File

@ -1,14 +0,0 @@
#ifndef __MMIO_H__
#define __MMIO_H__
#include "common.h"
typedef void(*mmio_callback_t)(hwaddr_t, size_t, bool);
void* add_mmio_map(hwaddr_t, size_t, mmio_callback_t);
int is_mmio(hwaddr_t);
uint32_t mmio_read(hwaddr_t, size_t, int);
void mmio_write(hwaddr_t, size_t, uint32_t, int);
#endif

View File

@ -1,13 +0,0 @@
#ifndef __PORT_IO_H__
#define __PORT_IO_H__
#include "common.h"
typedef void(*pio_callback_t)(ioaddr_t, size_t, bool);
void* add_pio_map(ioaddr_t, size_t, pio_callback_t);
uint32_t pio_read(ioaddr_t, size_t);
void pio_write(ioaddr_t, size_t, uint32_t);
#endif

View File

@ -1,15 +0,0 @@
#ifndef __MACRO_H__
#define __MACRO_H__
#define str_temp(x) #x
#define str(x) str_temp(x)
#define concat_temp(x, y) x ## y
#define concat(x, y) concat_temp(x, y)
#define concat3(x, y, z) concat(concat(x, y), z)
#define concat4(x, y, z, w) concat3(concat(x, y), z, w)
#define concat5(x, y, z, v, w) concat4(concat(x, y), z, v, w)
#define unalign_rw(addr, len) (((unalign *)(addr))->concat(_, len))
#endif

View File

@ -1,27 +0,0 @@
#ifndef __MEMORY_H__
#define __MEMORY_H__
#include "common.h"
#define HW_MEM_SIZE (128 * 1024 * 1024)
extern uint8_t *hw_mem;
/* convert the hardware address in the test program to virtual address in NEMU */
#define hwa_to_va(p) ((void *)(hw_mem + (unsigned)p))
/* convert the virtual address in NEMU to hardware address in the test program */
#define va_to_hwa(p) ((hwaddr_t)((void *)p - (void *)hw_mem))
#define hw_rw(addr, type) *(type *)({\
Assert(addr < HW_MEM_SIZE, "physical address(0x%08x) is out of bound", addr); \
hwa_to_va(addr); \
})
uint32_t swaddr_read(swaddr_t, size_t, uint8_t);
uint32_t lnaddr_read(lnaddr_t, size_t);
uint32_t hwaddr_read(hwaddr_t, size_t);
void swaddr_write(swaddr_t, size_t, uint32_t, uint8_t);
void lnaddr_write(lnaddr_t, size_t, uint32_t);
void hwaddr_write(hwaddr_t, size_t, uint32_t);
#endif

View File

@ -1,15 +0,0 @@
#ifndef __LIB_MISC_H__
#define __LIB_MISC_H__
#include "common.h"
inline static void memcpy_with_mask(void *dest, const void *src, size_t len, uint8_t *mask) {
int l;
for(l = 0; l < len; l ++) {
if(mask[l]) {
((uint8_t *)dest)[l] = ((uint8_t *)src)[l];
}
}
}
#endif

View File

@ -1,14 +0,0 @@
#ifndef __EXPR_H__
#define __EXPR_H__
#include "common.h"
#include <elf.h>
uint32_t expr(char *, bool *);
int get_sym(char *var);
void get_funcname(swaddr_t addr);
char *strtab;
Elf32_Sym *symtab;
int nr_symtab_entry;
#endif

View File

@ -1,7 +0,0 @@
#ifndef __MONITOR_H__
#define __MONITOR_H__
enum { STOP, RUNNING, END };
extern int nemu_state;
#endif

View File

@ -1,19 +0,0 @@
#ifndef __WATCHPOINT_H__
#define __WATCHPOINT_H__
#include "common.h"
typedef struct watchpoint {
int NO;
struct watchpoint *next;
char expr[32];
uint32_t result;
/* TODO: Add more members if necessary */
} WP;
WP* new_wp();
void free_wp(WP* wp);
#endif

View File

@ -1,8 +0,0 @@
#ifndef __NEMU_H__
#define __NEMU_H__
#include "common.h"
#include "memory/memory.h"
#include "cpu/reg.h"
#endif

View File

@ -1,47 +0,0 @@
#ifndef __ADDR_S__
#define __ADDR_S__
typedef union {
lnaddr_t lnaddr;
struct {
uint32_t OFFSET : 12;
uint32_t PAGE : 10;
uint32_t DIR : 10;
};
} ln_addr;
typedef union {
SegDesc sr_des;
uint32_t val[2];
} sreg_desc;
typedef union {
GateDesc gate;
uint32_t val[2];
} gate_desc;
typedef union {
uint32_t val;
struct {
uint32_t base15 : 16;
uint32_t base23 : 8;
uint32_t base31 : 8;
};
} base_addr;
typedef union {
uint32_t val : 20;
struct {
uint32_t limit15 : 16;
uint32_t limit19 : 4;
};
} limit;
typedef union {
uint32_t val;
struct {
uint16_t offset15;
uint16_t offset31;
};
} offset;
#endif

View File

@ -1,37 +0,0 @@
#ifndef __X86_INC_CPU_H__
#define __X86_INC_CPU_H__
/* the Control Register 0 */
typedef union CR0 {
struct {
uint32_t protect_enable : 1;
uint32_t monitor_coprocessor : 1;
uint32_t emulation : 1;
uint32_t task_switched : 1;
uint32_t extension_type : 1;
uint32_t numeric_error : 1;
uint32_t pad0 : 10;
uint32_t write_protect : 1;
uint32_t pad1 : 1;
uint32_t alignment_mask : 1;
uint32_t pad2 : 10;
uint32_t no_write_through : 1;
uint32_t cache_disable : 1;
uint32_t paging : 1;
};
uint32_t val;
} CR0;
/* the Control Register 3 (physical address of page directory) */
typedef union CR3 {
struct {
uint32_t pad0 : 3;
uint32_t page_write_through : 1;
uint32_t page_cache_disable : 1;
uint32_t pad1 : 7;
uint32_t page_directory_base : 20;
};
uint32_t val;
} CR3;
#endif

View File

@ -1,105 +0,0 @@
#ifndef __X86_INC_MMU_H__
#define __X86_INC_MMU_H__
#define SEG_CODEDATA 1
#define SEG_32BIT 1
#define SEG_4KB_GRANULARITY 1
#define SEG_TSS_32BIT 0x9
#define DPL_KERNEL 0
#define DPL_USER 3
#define SEG_WRITABLE 0x2
#define SEG_READABLE 0x2
#define SEG_EXECUTABLE 0x8
#define NR_SEGMENTS 3
#define SEG_NULL 0
#define SEG_KERNEL_CODE 1
#define SEG_KERNEL_DATA 2
#define SELECTOR_KERNEL(s) ( (s << 3) | DPL_KERNEL )
#define SELECTOR_USER(s) ( (s << 3) | DPL_USER )
/* 32bit x86 uses 4KB page size */
#define PAGE_SIZE 4096
#define NR_PDE 1024
#define NR_PTE 1024
#define PAGE_MASK (4096 - 1)
#define PT_SIZE ((NR_PTE) * (PAGE_SIZE))
/* force the data to be aligned with page boundary.
statically defined page tables uses this feature. */
#define align_to_page __attribute((aligned(PAGE_SIZE)))
/* this marco will be defined by gcc if the source file is an assembly */
#ifndef __ASSEMBLER__
#include <stdint.h>
/* the 32bit Page Directory(first level page table) data structure */
typedef union PageDirectoryEntry {
struct {
uint32_t present : 1;
uint32_t read_write : 1;
uint32_t user_supervisor : 1;
uint32_t page_write_through : 1;
uint32_t page_cache_disable : 1;
uint32_t accessed : 1;
uint32_t pad0 : 6;
uint32_t page_frame : 20;
};
uint32_t val;
} PDE;
/* the 32bit Page Table Entry(second level page table) data structure */
typedef union PageTableEntry {
struct {
uint32_t present : 1;
uint32_t read_write : 1;
uint32_t user_supervisor : 1;
uint32_t page_write_through : 1;
uint32_t page_cache_disable : 1;
uint32_t accessed : 1;
uint32_t dirty : 1;
uint32_t pad0 : 1;
uint32_t global : 1;
uint32_t pad1 : 3;
uint32_t page_frame : 20;
};
uint32_t val;
} PTE;
typedef PTE (*PT) [NR_PTE];
/* the 64bit segment descriptor */
typedef struct SegmentDescriptor {
uint32_t limit_15_0 : 16;
uint32_t base_15_0 : 16;
uint32_t base_23_16 : 8;
uint32_t type : 4;
uint32_t segment_type : 1;
uint32_t privilege_level : 2;
uint32_t present : 1;
uint32_t limit_19_16 : 4;
uint32_t soft_use : 1;
uint32_t operation_size : 1;
uint32_t pad0 : 1;
uint32_t granularity : 1;
uint32_t base_31_24 : 8;
} SegDesc;
typedef struct GateDescriptor {
uint32_t offset_15_0 : 16;
uint32_t segment : 16;
uint32_t pad0 : 8;
uint32_t type : 4;
uint32_t system : 1;
uint32_t privilege_level : 2;
uint32_t present : 1;
uint32_t offset_31_16 : 16;
} GateDesc;
#endif
#endif

View File

@ -1,181 +0,0 @@
#include "cpu/exec/template-start.h"
#include "cpu/decode/modrm.h"
#define decode_r_internal concat3(decode_r_, SUFFIX, _internal)
#define decode_rm_internal concat3(decode_rm_, SUFFIX, _internal)
#define decode_i concat(decode_i_, SUFFIX)
#define decode_a concat(decode_a_, SUFFIX)
#define decode_r2rm concat(decode_r2rm_, SUFFIX)
/* Ib, Iv */
make_helper(concat(decode_i_, SUFFIX)) {
/* eip here is pointing to the immediate */
op_src->type = OP_TYPE_IMM;
op_src->imm = instr_fetch(eip, DATA_BYTE);
op_src->val = op_src->imm;
#ifdef DEBUG
snprintf(op_src->str, OP_STR_SIZE, "$0x%x", op_src->imm);
#endif
return DATA_BYTE;
}
#if DATA_BYTE == 1 || DATA_BYTE == 4
/* sign immediate */
make_helper(concat(decode_si_, SUFFIX)) {
op_src->type = OP_TYPE_IMM;
DATA_TYPE_S n = instr_fetch(eip, DATA_BYTE);
op_src->simm = n;
op_src->val = op_src->simm;
#ifdef DEBUG
snprintf(op_src->str, OP_STR_SIZE, "$0x%x", op_src->val);
#endif
return DATA_BYTE;
}
#endif
/* eAX */
static int concat(decode_a_, SUFFIX) (swaddr_t eip, Operand *op) {
op->type = OP_TYPE_REG;
op->reg = R_EAX;
op->val = REG(R_EAX);
#ifdef DEBUG
snprintf(op->str, OP_STR_SIZE, "%%%s", REG_NAME(R_EAX));
#endif
return 0;
}
/* eXX: eAX, eCX, eDX, eBX, eSP, eBP, eSI, eDI */
static int concat3(decode_r_, SUFFIX, _internal) (swaddr_t eip, Operand *op) {
op->type = OP_TYPE_REG;
op->reg = ops_decoded.opcode & 0x7;
op->val = REG(op->reg);
#ifdef DEBUG
snprintf(op->str, OP_STR_SIZE, "%%%s", REG_NAME(op->reg));
#endif
return 0;
}
static int concat3(decode_rm_, SUFFIX, _internal) (swaddr_t eip, Operand *rm, Operand *reg) {
rm->size = DATA_BYTE;
int len = read_ModR_M(eip, rm, reg);
reg->val = REG(reg->reg);
#ifdef DEBUG
snprintf(reg->str, OP_STR_SIZE, "%%%s", REG_NAME(reg->reg));
#endif
return len;
}
/* Eb <- Gb
* Ev <- Gv
*/
make_helper(concat(decode_r2rm_, SUFFIX)) {
return decode_rm_internal(eip, op_dest, op_src);
}
/* Gb <- Eb
* Gv <- Ev
*/
make_helper(concat(decode_rm2r_, SUFFIX)) {
return decode_rm_internal(eip, op_src, op_dest);
}
/* AL <- Ib
* eAX <- Iv
*/
make_helper(concat(decode_i2a_, SUFFIX)) {
decode_a(eip, op_dest);
return decode_i(eip);
}
/* Gv <- EvIb
* Gv <- EvIv
* use for imul */
make_helper(concat(decode_i_rm2r_, SUFFIX)) {
int len = decode_rm_internal(eip, op_src2, op_dest);
len += decode_i(eip + len);
return len;
}
/* Eb <- Ib
* Ev <- Iv
*/
make_helper(concat(decode_i2rm_, SUFFIX)) {
int len = decode_rm_internal(eip, op_dest, op_src2); /* op_src2 not use here */
len += decode_i(eip + len);
return len;
}
/* XX <- Ib
* eXX <- Iv
*/
make_helper(concat(decode_i2r_, SUFFIX)) {
decode_r_internal(eip, op_dest);
return decode_i(eip);
}
/* used by unary operations */
make_helper(concat(decode_rm_, SUFFIX)) {
return decode_rm_internal(eip, op_src, op_src2); /* op_src2 not use here */
}
make_helper(concat(decode_r_, SUFFIX)) {
return decode_r_internal(eip, op_src);
}
#if DATA_BYTE == 2 || DATA_BYTE == 4
make_helper(concat(decode_si2rm_, SUFFIX)) {
int len = decode_rm_internal(eip, op_dest, op_src2); /* op_src2 not use here */
len += decode_si_b(eip + len);
return len;
}
make_helper(concat(decode_si_rm2r_, SUFFIX)) {
int len = decode_rm_internal(eip, op_src2, op_dest);
len += decode_si_b(eip + len);
return len;
}
#endif
/* used by shift instructions */
make_helper(concat(decode_rm_1_, SUFFIX)) {
int len = decode_r2rm(eip);
op_src->type = OP_TYPE_IMM;
op_src->imm = 1;
op_src->val = 1;
#ifdef DEBUG
sprintf(op_src->str, "$1");
#endif
return len;
}
make_helper(concat(decode_rm_cl_, SUFFIX)) {
int len = decode_r2rm(eip);
op_src->type = OP_TYPE_REG;
op_src->reg = R_CL;
op_src->val = reg_b(R_CL);
#ifdef DEBUG
sprintf(op_src->str, "%%cl");
#endif
return len;
}
make_helper(concat(decode_rm_imm_, SUFFIX)) {
int len = decode_r2rm(eip);
len += decode_i_b(eip + len);
return len;
}
void concat(write_operand_, SUFFIX) (Operand *op, DATA_TYPE src) {
if(op->type == OP_TYPE_REG) { REG(op->reg) = src; }
else if(op->type == OP_TYPE_MEM) { swaddr_write(op->addr, op->size, src, op->sreg); }
else { assert(0); }
}
#include "cpu/exec/template-end.h"

View File

@ -1,17 +0,0 @@
#include "common.h"
#include "cpu/decode/decode.h"
/* shared by all helper function */
Operands ops_decoded;
#define DATA_BYTE 1
#include "decode-template.h"
#undef DATA_BYTE
#define DATA_BYTE 2
#include "decode-template.h"
#undef DATA_BYTE
#define DATA_BYTE 4
#include "decode-template.h"
#undef DATA_BYTE

View File

@ -1,125 +0,0 @@
#include "cpu/decode/modrm.h"
#include "cpu/helper.h"
int load_addr(swaddr_t eip, ModR_M *m, Operand *rm) {
assert(m->mod != 3);
int32_t disp;
int instr_len, disp_offset, disp_size = 4;
int base_reg = -1, index_reg = -1, scale = 0;
swaddr_t addr = 0;
if(m->R_M == R_ESP) {
SIB s;
s.val = instr_fetch(eip + 1, 1);
base_reg = s.base;
disp_offset = 2;
scale = s.ss;
if(s.index != R_ESP) { index_reg = s.index; }
}
else {
/* no SIB */
base_reg = m->R_M;
disp_offset = 1;
}
if(m->mod == 0) {
if(base_reg == R_EBP) { base_reg = -1; }
else { disp_size = 0; }
}
else if(m->mod == 1) { disp_size = 1; }
instr_len = disp_offset;
if(disp_size != 0) {
/* has disp */
disp = instr_fetch(eip + disp_offset, disp_size);
if(disp_size == 1) { disp = (int8_t)disp; }
instr_len += disp_size;
addr += disp;
}
if(base_reg != -1) {
addr += reg_l(base_reg);
}
if(index_reg != -1) {
addr += reg_l(index_reg) << scale;
}
#ifdef DEBUG
char disp_buf[16];
char base_buf[8];
char index_buf[8];
if(disp_size != 0) {
/* has disp */
sprintf(disp_buf, "%s%#x", (disp < 0 ? "-" : ""), (disp < 0 ? -disp : disp));
}
else { disp_buf[0] = '\0'; }
if(base_reg == -1) { base_buf[0] = '\0'; }
else {
sprintf(base_buf, "%%%s", regsl[base_reg]);
}
if(index_reg == -1) { index_buf[0] = '\0'; }
else {
sprintf(index_buf, ",%%%s,%d", regsl[index_reg], 1 << scale);
}
if(base_reg == -1 && index_reg == -1) {
sprintf(rm->str, "%s", disp_buf);
}
else {
sprintf(rm->str, "%s(%s%s)", disp_buf, base_buf, index_buf);
}
#endif
rm->type = OP_TYPE_MEM;
rm->addr = addr;
return instr_len;
}
int read_ModR_M(swaddr_t eip, Operand *rm, Operand *reg) {
ModR_M m;
m.val = instr_fetch(eip, 1);
reg->type = OP_TYPE_REG;
reg->reg = m.reg;
if(m.reg == 0x100 || m.reg == 0x101)
{
//reg->sreg = 0x2; /* bind with SS */
rm->sreg = 0x2;
}
else
{
//reg->sreg = 0x3; /* bind with DS */
rm->sreg = 0x3;
}
if(m.mod == 3) {
rm->type = OP_TYPE_REG;
rm->reg = m.R_M;
switch(rm->size) {
case 1: rm->val = reg_b(m.R_M); break;
case 2: rm->val = reg_w(m.R_M); break;
case 4: rm->val = reg_l(m.R_M); break;
default: assert(0);
}
#ifdef DEBUG
switch(rm->size) {
case 1: sprintf(rm->str, "%%%s", regsb[m.R_M]); break;
case 2: sprintf(rm->str, "%%%s", regsw[m.R_M]); break;
case 4: sprintf(rm->str, "%%%s", regsl[m.R_M]); break;
}
#endif
return 1;
}
else {
int instr_len = load_addr(eip, &m, rm);
rm->val = swaddr_read(rm->addr, rm->size, rm->sreg);
return instr_len;
}
}

View File

@ -1,57 +0,0 @@
#include "prefix/prefix.h"
#include "data-mov/mov.h"
#include "data-mov/cmovcc.h"
#include "data-mov/xchg.h"
#include "data-mov/push.h"
#include "data-mov/pop.h"
#include "data-mov/movzx.h"
#include "data-mov/leave.h"
#include "data-mov/movsx.h"
#include "data-mov/cvw.h"
#include "data-mov/in.h"
#include "data-mov/out.h"
#include "arith/dec.h"
#include "arith/inc.h"
#include "arith/neg.h"
#include "arith/imul.h"
#include "arith/mul.h"
#include "arith/idiv.h"
#include "arith/div.h"
#include "arith/cmp.h"
#include "arith/sub.h"
#include "arith/add.h"
#include "arith/adc.h"
#include "arith/sbb.h"
#include "arith/neg.h"
#include "logic/and.h"
#include "logic/or.h"
#include "logic/not.h"
#include "logic/xor.h"
#include "logic/sar.h"
#include "logic/shl.h"
#include "logic/shr.h"
#include "logic/shrd.h"
#include "logic/test.h"
#include "logic/setcc.h"
#include "logic/bt.h"
#include "string/rep.h"
#include "string/movs.h"
#include "string/stos.h"
#include "string/cmps.h"
#include "misc/misc.h"
#include "misc/lgdt.h"
#include "misc/lidt.h"
#include "misc/int.h"
#include "ctrl-tran/call.h"
#include "ctrl-tran/ret.h"
#include "ctrl-tran/jcc.h"
#include "ctrl-tran/jmp.h"
#include "special/special.h"

View File

@ -1,24 +0,0 @@
#include "cpu/exec/template-start.h"
#include "cpu/exec/flag.h"
#define instr adc
static void do_execute(){
DATA_TYPE result = op_src->val + op_dest->val + cpu.EFLAGS.CF;
op_src->val = op_src->val + cpu.EFLAGS.CF;
CHANGE_ZF
CHANGE_SF
CHANGE_PF
CHANGE_ADD_OF
CHANGE_ADD_CF
OPERAND_W(op_dest, result);
print_asm_template2();
}
make_instr_helper(r2rm)
#if DATA_BYTE == 2 || DATA_BYTE == 4
make_instr_helper(si2rm)
#endif
#include "cpu/exec/template-end.h"

View File

@ -1,14 +0,0 @@
#include "cpu/exec/helper.h"
#define DATA_BYTE 2
#include "adc-template.h"
#undef DATA_BYTE
#define DATA_BYTE 4
#include "adc-template.h"
#undef DATA_BYTE
make_helper_v(adc_r2rm)
make_helper_v(adc_si2rm)

View File

@ -1,8 +0,0 @@
#ifndef __ADC_H__
#define __ADC_H__
make_helper(adc_r2rm_v);
make_helper(adc_si2rm_v);
#endif

View File

@ -1,25 +0,0 @@
#include "cpu/exec/template-start.h"
#include "cpu/exec/flag.h"
#define instr add
static void do_execute(){
DATA_TYPE result = op_dest->val + op_src->val;
CHANGE_ZF
CHANGE_SF
CHANGE_PF
CHANGE_ADD_OF
CHANGE_ADD_CF
OPERAND_W(op_dest, result);
print_asm_template2();
}
make_instr_helper(rm2r)
make_instr_helper(r2rm)
#if DATA_BYTE == 2 || DATA_BYTE == 4
make_instr_helper(si2rm)
#endif
make_instr_helper(i2a)
make_instr_helper(i2rm)
#include "cpu/exec/template-end.h"

View File

@ -1,19 +0,0 @@
#include "cpu/exec/helper.h"
#define DATA_BYTE 1
#include "add-template.h"
#undef DATA_BYTE
#define DATA_BYTE 2
#include "add-template.h"
#undef DATA_BYTE
#define DATA_BYTE 4
#include "add-template.h"
#undef DATA_BYTE
make_helper_v(add_r2rm)
make_helper_v(add_si2rm)
make_helper_v(add_i2a)
make_helper_v(add_i2rm)
make_helper_v(add_rm2r);

View File

@ -1,12 +0,0 @@
#ifndef __ADD_H__
#define __ADD_H__
make_helper(add_r2rm_b);
make_helper(add_rm2r_b);
make_helper(add_i2a_b);
make_helper(add_rm2r_v);
make_helper(add_r2rm_v);
make_helper(add_si2rm_v);
make_helper(add_i2a_v);
make_helper(add_i2rm_v);
#endif

View File

@ -1,24 +0,0 @@
#include "cpu/exec/template-start.h"
#include "cpu/exec/flag.h"
#define instr cmp
static void do_execute(){
DATA_TYPE result = op_dest->val - (DATA_TYPE_S)op_src->val;
CHANGE_ZF
CHANGE_SF
CHANGE_PF
CHANGE_SUB_OF
CHANGE_SUB_CF
print_asm_template2();
}
make_instr_helper(i2a)
make_instr_helper(i2rm)
#if DATA_BYTE == 2 || DATA_BYTE == 4
make_instr_helper(si2rm)
#endif
make_instr_helper(r2rm)
make_instr_helper(rm2r)
#include "cpu/exec/template-end.h"

View File

@ -1,19 +0,0 @@
#include "cpu/exec/helper.h"
#define DATA_BYTE 1
#include "cmp-template.h"
#undef DATA_BYTE
#define DATA_BYTE 2
#include "cmp-template.h"
#undef DATA_BYTE
#define DATA_BYTE 4
#include "cmp-template.h"
#undef DATA_BYTE
make_helper_v(cmp_si2rm)
make_helper_v(cmp_r2rm)
make_helper_v(cmp_i2rm)
make_helper_v(cmp_rm2r)
make_helper_v(cmp_i2a)

View File

@ -1,14 +0,0 @@
#ifndef __CMP_H__
#define __CMP_H__
make_helper(cmp_si2rm_v);
make_helper(cmp_i2a_b);
make_helper(cmp_i2a_v);
make_helper(cmp_i2rm_b);
make_helper(cmp_r2rm_v);
make_helper(cmp_i2rm_v);
make_helper(cmp_rm2r_v);
make_helper(cmp_rm2r_b);
make_helper(cmp_r2rm_b);
#endif

View File

@ -1,24 +0,0 @@
#include "cpu/exec/template-start.h"
#include "cpu/exec/flag.h"
#define instr dec
static void do_execute () {
op_dest->val = op_src->val;
DATA_TYPE result = op_src->val - 1;
op_src->val = 1;
CHANGE_ZF
CHANGE_SF
CHANGE_PF
CHANGE_SUB_OF
CHANGE_SUB_CF
OPERAND_W(op_src, result);
print_asm_template1();
}
make_instr_helper(rm)
#if DATA_BYTE == 2 || DATA_BYTE == 4
make_instr_helper(r)
#endif
#include "cpu/exec/template-end.h"

View File

@ -1,18 +0,0 @@
#include "cpu/exec/helper.h"
#define DATA_BYTE 1
#include "dec-template.h"
#undef DATA_BYTE
#define DATA_BYTE 2
#include "dec-template.h"
#undef DATA_BYTE
#define DATA_BYTE 4
#include "dec-template.h"
#undef DATA_BYTE
/* for instruction encoding overloading */
make_helper_v(dec_rm)
make_helper_v(dec_r)

View File

@ -1,9 +0,0 @@
#ifndef __DEC_H__
#define __DEC_H__
make_helper(dec_rm_b);
make_helper(dec_rm_v);
make_helper(dec_r_v);
#endif

View File

@ -1,21 +0,0 @@
#include "cpu/exec/template-start.h"
#define instr div
static void do_execute() {
uint64_t a;
uint32_t b = (DATA_TYPE)op_src->val;
#if DATA_BYTE == 1
a = reg_w(R_EAX);
#else
a = ((uint64_t)REG(R_EDX) << (DATA_BYTE * 8)) | REG(R_EAX);
#endif
REG(R_EAX) = a / b;
REG(R_EDX) = a % b;
print_asm_template1();
}
make_instr_helper(rm)
#include "cpu/exec/template-end.h"

View File

@ -1,17 +0,0 @@
#include "cpu/exec/helper.h"
#define DATA_BYTE 1
#include "div-template.h"
#undef DATA_BYTE
#define DATA_BYTE 2
#include "div-template.h"
#undef DATA_BYTE
#define DATA_BYTE 4
#include "div-template.h"
#undef DATA_BYTE
/* for instruction encoding overloading */
make_helper_v(div_rm)

View File

@ -1,8 +0,0 @@
#ifndef __DIV_H__
#define __DIV_H__
make_helper(div_rm_b);
make_helper(div_rm_v);
#endif

View File

@ -1,21 +0,0 @@
#include "cpu/exec/template-start.h"
#define instr idiv
static void do_execute() {
int64_t a;
int32_t b = (DATA_TYPE_S)op_src->val;
#if DATA_BYTE == 1
a = (int16_t)reg_w(R_EAX);
#else
a = ((int64_t)REG(R_EDX) << (DATA_BYTE * 8)) | (int64_t)REG(R_EAX);
#endif
REG(R_EAX) = a / b;
REG(R_EDX) = a % b;
print_asm_template1();
}
make_instr_helper(rm)
#include "cpu/exec/template-end.h"

View File

@ -1,17 +0,0 @@
#include "cpu/exec/helper.h"
#define DATA_BYTE 1
#include "idiv-template.h"
#undef DATA_BYTE
#define DATA_BYTE 2
#include "idiv-template.h"
#undef DATA_BYTE
#define DATA_BYTE 4
#include "idiv-template.h"
#undef DATA_BYTE
/* for instruction encoding overloading */
make_helper_v(idiv_rm)

View File

@ -1,8 +0,0 @@
#ifndef __IDIV_H__
#define __IDIV_H__
make_helper(idiv_rm_b);
make_helper(idiv_rm_v);
#endif

View File

@ -1,60 +0,0 @@
#include "cpu/exec/template-start.h"
#if DATA_BYTE == 1
#define RET_DATA_TYPE int16_t
#elif DATA_BYTE == 2
#define RET_DATA_TYPE int32_t
#elif DATA_BYTE == 4
#define RET_DATA_TYPE int64_t
#endif
#define instr imul
#if DATA_BYTE == 2 || DATA_BYTE == 4
static void do_execute() {
RET_DATA_TYPE result = (RET_DATA_TYPE)op_src->val * (RET_DATA_TYPE)op_src2->val;
OPERAND_W(op_dest, result);
/* There is no need to update EFLAGS, since no other instructions
* in PA will test the flags updated by this instruction.
*/
print_asm_template3();
}
make_helper(concat(imul_rm2r_, SUFFIX)) {
int len = concat(decode_rm2r_, SUFFIX)(eip + 1);
ops_decoded.src2 = ops_decoded.dest;
do_execute();
return len + 1;
}
make_instr_helper(si_rm2r)
make_instr_helper(i_rm2r)
#endif
make_helper(concat(imul_rm2a_, SUFFIX)) {
int len = concat(decode_rm_, SUFFIX)(eip + 1);
int64_t src = (DATA_TYPE_S)op_src->val;
int64_t result = (DATA_TYPE_S)REG(R_EAX) * src;
#if DATA_BYTE == 1
reg_w(R_AX) = result;
#elif DATA_BYTE == 2
REG(R_EAX) = result & 0xffff;
REG(R_EDX) = result >> 16;
#else
REG(R_EAX) = result & 0xffffffff;
REG(R_EDX) = result >> 32;
#endif
/* There is no need to update EFLAGS, since no other instructions
* in PA will test the flags updated by this instruction.
*/
print_asm_template1();
return len + 1;
}
#undef RET_DATA_TYPE
#include "cpu/exec/template-end.h"

View File

@ -1,20 +0,0 @@
#include "cpu/exec/helper.h"
#define DATA_BYTE 1
#include "imul-template.h"
#undef DATA_BYTE
#define DATA_BYTE 2
#include "imul-template.h"
#undef DATA_BYTE
#define DATA_BYTE 4
#include "imul-template.h"
#undef DATA_BYTE
/* for instruction encoding overloading */
make_helper_v(imul_rm2a)
make_helper_v(imul_rm2r)
make_helper_v(imul_si_rm2r)
make_helper_v(imul_i_rm2r)

View File

@ -1,11 +0,0 @@
#ifndef __IMUL_H__
#define __IMUL_H__
make_helper(imul_rm2a_b);
make_helper(imul_rm2a_v);
make_helper(imul_rm2r_v);
make_helper(imul_si_rm2r_v);
make_helper(imul_i_rm2r_v);
#endif

View File

@ -1,24 +0,0 @@
#include "cpu/exec/template-start.h"
#include "cpu/exec/flag.h"
#define instr inc
static void do_execute () {
op_dest->val = op_src->val;
DATA_TYPE result = op_src->val + 1;
op_src->val = 1;
CHANGE_ZF
CHANGE_SF
CHANGE_PF
CHANGE_ADD_OF
CHANGE_ADD_CF
OPERAND_W(op_src, result);
print_asm_template1();
}
make_instr_helper(rm)
#if DATA_BYTE == 2 || DATA_BYTE == 4
make_instr_helper(r)
#endif
#include "cpu/exec/template-end.h"

View File

@ -1,18 +0,0 @@
#include "cpu/exec/helper.h"
#define DATA_BYTE 1
#include "inc-template.h"
#undef DATA_BYTE
#define DATA_BYTE 2
#include "inc-template.h"
#undef DATA_BYTE
#define DATA_BYTE 4
#include "inc-template.h"
#undef DATA_BYTE
/* for instruction encoding overloading */
make_helper_v(inc_rm)
make_helper_v(inc_r)

View File

@ -1,9 +0,0 @@
#ifndef __INC_H__
#define __INC_H__
make_helper(inc_rm_b);
make_helper(inc_rm_v);
make_helper(inc_r_v);
#endif

View File

@ -1,27 +0,0 @@
#include "cpu/exec/template-start.h"
#define instr mul
static void do_execute() {
uint64_t src = op_src->val;
uint64_t result = REG(R_EAX) * src;
#if DATA_BYTE == 1
reg_w(R_AX) = result;
#elif DATA_BYTE == 2
REG(R_EAX) = result & 0xffff;
REG(R_EDX) = result >> 16;
#else
REG(R_EAX) = result & 0xffffffff;
REG(R_EDX) = result >> 32;
#endif
/* There is no need to update EFLAGS, since no other instructions
* in PA will test the flags updated by this instruction.
*/
print_asm_template1();
}
make_instr_helper(rm)
#include "cpu/exec/template-end.h"

View File

@ -1,17 +0,0 @@
#include "cpu/exec/helper.h"
#define DATA_BYTE 1
#include "mul-template.h"
#undef DATA_BYTE
#define DATA_BYTE 2
#include "mul-template.h"
#undef DATA_BYTE
#define DATA_BYTE 4
#include "mul-template.h"
#undef DATA_BYTE
/* for instruction encoding overloading */
make_helper_v(mul_rm)

View File

@ -1,8 +0,0 @@
#ifndef __MUL_H__
#define __MUL_H__
make_helper(mul_rm_b);
make_helper(mul_rm_v);
#endif

View File

@ -1,18 +0,0 @@
#include "cpu/exec/template-start.h"
#define instr neg
static void do_execute() {
DATA_TYPE result = -op_src->val;
OPERAND_W(op_src, result);
/* There is no need to update EFLAGS, since no other instructions
* in PA will test the flags updated by this instruction.
*/
print_asm_template1();
}
make_instr_helper(rm)
#include "cpu/exec/template-end.h"

View File

@ -1,17 +0,0 @@
#include "cpu/exec/helper.h"
#define DATA_BYTE 1
#include "neg-template.h"
#undef DATA_BYTE
#define DATA_BYTE 2
#include "neg-template.h"
#undef DATA_BYTE
#define DATA_BYTE 4
#include "neg-template.h"
#undef DATA_BYTE
/* for instruction encoding overloading */
make_helper_v(neg_rm)

View File

@ -1,7 +0,0 @@
#ifndef __NEG_H__
#define __NEG_H__
make_helper(neg_rm_b);
make_helper(neg_rm_v);
#endif

View File

@ -1,21 +0,0 @@
#include "cpu/exec/template-start.h"
#include "cpu/exec/flag.h"
#define instr sbb
static void do_execute(){
DATA_TYPE result = op_dest->val - ((DATA_TYPE_S)op_src->val + cpu.EFLAGS.CF);
op_src->val = (DATA_TYPE_S)op_src->val + cpu.EFLAGS.CF;
CHANGE_ZF
CHANGE_SF
CHANGE_PF
CHANGE_SUB_OF
CHANGE_SUB_CF
OPERAND_W(op_dest,result);
print_asm_template2();
}
make_instr_helper(rm2r)
make_instr_helper(r2rm)
#include "cpu/exec/template-end.h"

View File

@ -1,13 +0,0 @@
#include "cpu/exec/helper.h"
#define DATA_BYTE 2
#include "sbb-template.h"
#undef DATA_BYTE
#define DATA_BYTE 4
#include "sbb-template.h"
#undef DATA_BYTE
make_helper_v(sbb_rm2r)
make_helper_v(sbb_r2rm)

View File

@ -1,7 +0,0 @@
#ifndef __SBB_H__
#define __SBB_H__
make_helper(sbb_rm2r_v);
make_helper(sbb_r2rm_v);
#endif

View File

@ -1,25 +0,0 @@
#include "cpu/exec/template-start.h"
#include "cpu/exec/flag.h"
#define instr sub
static void do_execute(){
DATA_TYPE result = op_dest->val - op_src->val;
CHANGE_ZF
CHANGE_SF
CHANGE_PF
CHANGE_SUB_OF
CHANGE_SUB_CF
OPERAND_W(op_dest, result);
print_asm_template2();
}
make_instr_helper(r2rm)
make_instr_helper(rm2r)
make_instr_helper(i2rm)
make_instr_helper(i2a)
#if DATA_BYTE == 2 || DATA_BYTE == 4
make_instr_helper(si2rm)
#endif
#include "cpu/exec/template-end.h"

View File

@ -1,19 +0,0 @@
#include "cpu/exec/helper.h"
#define DATA_BYTE 1
#include "sub-template.h"
#undef DATA_BYTE
#define DATA_BYTE 2
#include "sub-template.h"
#undef DATA_BYTE
#define DATA_BYTE 4
#include "sub-template.h"
#undef DATA_BYTE
make_helper_v(sub_r2rm)
make_helper_v(sub_rm2r)
make_helper_v(sub_i2rm)
make_helper_v(sub_i2a)
make_helper_v(sub_si2rm)

View File

@ -1,18 +0,0 @@
#ifndef __SUB_H__
#define __SUB_H__
make_helper(sub_r2rm_b);
make_helper(sub_rm2r_b);
make_helper(sub_i2rm_b);
make_helper(sub_r2rm_v);
make_helper(sub_rm2r_v);
make_helper(sub_i2rm_v);
make_helper(sub_i2a_v);
make_helper(sub_si2rm_v);
#endif

View File

@ -1,24 +0,0 @@
#include "cpu/exec/template-start.h"
#define instr call
make_helper(concat(call_rel_, SUFFIX)){
uint32_t disp = instr_fetch(eip + 1, DATA_BYTE);
cpu.esp = cpu.esp - 4;
swaddr_write(cpu.esp, 4, eip + DATA_BYTE, R_CS);
cpu.eip = eip + disp;
print_asm("call " "%x", cpu.eip + DATA_BYTE + 1);
return DATA_BYTE + 1;
}
static void do_execute(){
cpu.esp = cpu.esp - 4;
uint32_t ret = read_ModR_M(cpu.eip + 1,op_src,op_src2);
swaddr_write(cpu.esp, 4, cpu.eip + ret, R_CS);
cpu.eip = op_src->val - ret - 1;
print_asm_template1();
}
make_instr_helper(rm)
#include "cpu/exec/template-end.h"

View File

@ -1,19 +0,0 @@
#include "cpu/exec/helper.h"
#include "cpu/decode/modrm.h"
#define DATA_BYTE 1
#include "call-template.h"
#undef DATA_BYTE
#define DATA_BYTE 2
#include "call-template.h"
#undef DATA_BYTE
#define DATA_BYTE 4
#include "call-template.h"
#undef DATA_BYTE
make_helper_v(call_rel)
make_helper_v(call_rm)

View File

@ -1,7 +0,0 @@
#ifndef __CALL_H__
#define __CALL_H__
make_helper(call_rel_v);
make_helper(call_rm_v);
#endif

View File

@ -1,117 +0,0 @@
#include "cpu/exec/template-start.h"
#define instr jcc
make_helper(concat(jz_rel_,SUFFIX)){
DATA_TYPE_S addr = instr_fetch(eip + 1 , DATA_BYTE);
if(cpu.EFLAGS.ZF == 1)
cpu.eip = cpu.eip + addr;
print_asm(str(instr) " %x",cpu.eip+DATA_BYTE+1);
return DATA_BYTE+1;
}
make_helper(concat(js_rel_,SUFFIX)){
DATA_TYPE_S addr = instr_fetch(eip + 1 , DATA_BYTE);
if(cpu.EFLAGS.SF == 1)
cpu.eip = cpu.eip + addr;
print_asm(str(instr) " %x",cpu.eip+DATA_BYTE+1);
return DATA_BYTE+1;
}
make_helper(concat(jns_rel_,SUFFIX)){
DATA_TYPE_S addr = instr_fetch(eip + 1 , DATA_BYTE);
if(cpu.EFLAGS.SF == 0)
cpu.eip = cpu.eip + addr;
print_asm(str(instr) " %x",cpu.eip+DATA_BYTE+1);
return DATA_BYTE+1;
}
make_helper(concat(jne_rel_,SUFFIX)){
DATA_TYPE_S addr = instr_fetch(eip + 1 , DATA_BYTE);
if(cpu.EFLAGS.ZF == 0)
cpu.eip = cpu.eip + addr;
print_asm(str(instr) " %x",cpu.eip+DATA_BYTE+1);
return DATA_BYTE+1;
}
make_helper(concat(jnb_rel_,SUFFIX)){
DATA_TYPE_S addr = instr_fetch(eip + 1 , DATA_BYTE);
if(cpu.EFLAGS.CF == 0)
cpu.eip = cpu.eip + addr;
print_asm(str(instr) " %x",cpu.eip+DATA_BYTE+1);
return DATA_BYTE+1;
}
make_helper(concat(jl_rel_,SUFFIX)){
DATA_TYPE_S addr = instr_fetch(eip + 1 , DATA_BYTE);
if(cpu.EFLAGS.SF != cpu.EFLAGS.OF)
cpu.eip = cpu.eip + addr;
print_asm(str(instr) " %x",cpu.eip+DATA_BYTE+1);
return DATA_BYTE+1;
}
make_helper(concat(jle_rel_,SUFFIX)){
DATA_TYPE_S addr = instr_fetch(eip + 1 , DATA_BYTE);
if(cpu.EFLAGS.ZF == 1 || cpu.EFLAGS.SF != cpu.EFLAGS.OF)
cpu.eip = cpu.eip + addr;
print_asm(str(instr) " %x",cpu.eip+DATA_BYTE+1);
return DATA_BYTE+1;
}
make_helper(concat(jg_rel_,SUFFIX)){
DATA_TYPE_S addr = instr_fetch(eip + 1 , DATA_BYTE);
if(cpu.EFLAGS.ZF == 0 && cpu.EFLAGS.SF == cpu.EFLAGS.OF)
cpu.eip = cpu.eip + addr;
print_asm(str(instr) " %x",cpu.eip+DATA_BYTE+1);
return DATA_BYTE+1;
}
make_helper(concat(jge_rel_,SUFFIX)){
DATA_TYPE_S addr = instr_fetch(eip + 1 , DATA_BYTE);
if(cpu.EFLAGS.SF == cpu.EFLAGS.OF)
cpu.eip = cpu.eip + addr;
print_asm(str(instr) " %x",cpu.eip+DATA_BYTE+1);
return DATA_BYTE+1;
}
make_helper(concat(je_rel_,SUFFIX)){
DATA_TYPE_S addr = instr_fetch(eip + 1 , DATA_BYTE);
if(cpu.EFLAGS.ZF == 1)
cpu.eip = cpu.eip + addr;
print_asm(str(instr) " %x",cpu.eip+DATA_BYTE+1);
return DATA_BYTE+1;
}
make_helper(concat(jc_rel_,SUFFIX)){
DATA_TYPE_S addr = instr_fetch(eip + 1 , DATA_BYTE);
if(cpu.EFLAGS.CF == 1)
cpu.eip = cpu.eip + addr;
print_asm(str(instr) " %x",cpu.eip+DATA_BYTE+1);
return DATA_BYTE+1;
}
make_helper(concat(jbe_rel_,SUFFIX)){
DATA_TYPE_S addr = instr_fetch(eip + 1 , DATA_BYTE);
if(cpu.EFLAGS.ZF == 1||cpu.EFLAGS.CF == 1)
cpu.eip = cpu.eip + addr;
print_asm(str(instr) " %x",cpu.eip+DATA_BYTE+1);
return DATA_BYTE+1;
}
make_helper(concat(jb_rel_,SUFFIX)){
DATA_TYPE_S addr = instr_fetch(eip + 1 , DATA_BYTE);
if(cpu.EFLAGS.CF == 1)
cpu.eip = cpu.eip + addr;
print_asm(str(instr) " %x",cpu.eip+DATA_BYTE+1);
return DATA_BYTE+1;
}
make_helper(concat(ja_rel_,SUFFIX)){
DATA_TYPE_S addr = instr_fetch(eip + 1 , DATA_BYTE);
if(cpu.EFLAGS.CF == 0 && cpu.EFLAGS.ZF == 0)
cpu.eip = cpu.eip + addr;
print_asm(str(instr) " %x",cpu.eip+DATA_BYTE+1);
return DATA_BYTE+1;
}
#include "cpu/exec/template-end.h"

View File

@ -1,28 +0,0 @@
#include "cpu/exec/helper.h"
#define DATA_BYTE 1
#include "jcc-template.h"
#undef DATA_BYTE
#define DATA_BYTE 2
#include "jcc-template.h"
#undef DATA_BYTE
#define DATA_BYTE 4
#include "jcc-template.h"
#undef DATA_BYTE
make_helper_v(ja_rel)
make_helper_v(jbe_rel)
make_helper_v(jb_rel)
make_helper_v(jc_rel)
make_helper_v(je_rel)
make_helper_v(jg_rel)
make_helper_v(jge_rel)
make_helper_v(jl_rel)
make_helper_v(jle_rel)
make_helper_v(jnb_rel)
make_helper_v(jne_rel)
make_helper_v(jns_rel)
make_helper_v(js_rel)
make_helper_v(jz_rel)

View File

@ -1,33 +0,0 @@
#ifndef __JCC_H__
#define __JCC_H__
make_helper(ja_rel_b);
make_helper(ja_rel_v);
make_helper(jb_rel_b);
make_helper(jb_rel_v);
make_helper(jbe_rel_b);
make_helper(jbe_rel_v);
make_helper(jc_rel_b);
make_helper(jc_rel_v);
make_helper(je_rel_b);
make_helper(je_rel_v);
make_helper(jg_rel_b);
make_helper(jg_rel_v);
make_helper(jge_rel_b);
make_helper(jge_rel_v);
make_helper(jl_rel_b);
make_helper(jl_rel_v);
make_helper(jle_rel_b);
make_helper(jle_rel_v);
make_helper(jnb_rel_b);
make_helper(jnb_rel_v);
make_helper(jne_rel_b);
make_helper(jne_rel_v);
make_helper(jns_rel_b);
make_helper(jns_rel_v);
make_helper(js_rel_b);
make_helper(js_rel_v);
make_helper(jz_rel_b);
make_helper(jz_rel_v);
#endif

View File

@ -1,42 +0,0 @@
#include "cpu/exec/template-start.h"
#define instr jmp
static void do_execute(){
uint32_t ret = read_ModR_M(cpu.eip + 1,op_src,op_src2) + 1;
if(DATA_BYTE == 2)
cpu.eip = (op_src->val & 0x0000FFFF) - ret;
else
cpu.eip = op_src->val - ret;
print_asm_template1();
}
make_helper(concat(jmp_rel_,SUFFIX)){
DATA_TYPE_S disp = instr_fetch(eip + 1, DATA_BYTE);
cpu.eip = eip + disp;
print_asm(str(instr) " %x", cpu.eip + DATA_BYTE + 1);
return DATA_BYTE + 1;
}
make_helper(concat(ljmp_ptr_,SUFFIX)) {
if(DATA_BYTE == 4)
{
cpu.eip = instr_fetch(cpu.eip + 1,4) - 7;
cpu.CS.val = instr_fetch(cpu.eip + 5,2);
print_asm("ljmp " "$0x%x,$0x%x",cpu.CS.val,cpu.eip + 7);
return 7;
}
else
{
cpu.CS.val = instr_fetch(cpu.eip + 3,2);
cpu.eip = (cpu.eip & 0xFFFF0000) + instr_fetch(cpu.eip + 1,2) - 5;
cpu.eip = cpu.eip & 0x0000FFFF;
print_asm("ljmp " "$0x%x,$0x%x",cpu.CS.val,cpu.eip + 5);
return 5;
}
}
make_instr_helper(rm)
#include "cpu/exec/template-end.h"

View File

@ -1,19 +0,0 @@
#include "cpu/exec/helper.h"
#include "cpu/decode/modrm.h"
#define DATA_BYTE 1
#include "jmp-template.h"
#undef DATA_BYTE
#define DATA_BYTE 2
#include "jmp-template.h"
#undef DATA_BYTE
#define DATA_BYTE 4
#include "jmp-template.h"
#undef DATA_BYTE
make_helper_v(jmp_rel)
make_helper_v(jmp_rm)
make_helper_v(ljmp_ptr)

View File

@ -1,9 +0,0 @@
#ifndef __JMP_H__
#define __JMP_H__
make_helper(jmp_rel_b);
make_helper(jmp_rel_v);
make_helper(jmp_rm_v);
make_helper(ljmp_ptr_v);
#endif

View File

@ -1,23 +0,0 @@
#include "cpu/exec/template-start.h"
#define instr ret
make_helper(concat(ret_none_, SUFFIX)){
cpu.eip = swaddr_read(cpu.esp, DATA_BYTE, R_CS);
cpu.esp = cpu.esp + DATA_BYTE;
if(DATA_BYTE == 2)
cpu.eip = cpu.eip & 0x0000FFFF;
print_asm(str(instr));
return 1;
}
make_helper(concat(ret_i_,SUFFIX)){
cpu.eip = swaddr_read(cpu.esp, DATA_BYTE, R_CS);
int16_t disp = instr_fetch(cpu.eip + 1, 1);
cpu.esp = cpu.esp + DATA_BYTE + disp;
cpu.eip = cpu.eip - 1;
print_asm(str(instr) " 0x%x", disp);
return 2;
}
#include "cpu/exec/template-end.h"

View File

@ -1,14 +0,0 @@
#include "cpu/exec/helper.h"
#define DATA_BYTE 2
#include "ret-template.h"
#undef DATA_BYTE
#define DATA_BYTE 4
#include "ret-template.h"
#undef DATA_BYTE
make_helper_v(ret_none)
make_helper_v(ret_i)

View File

@ -1,7 +0,0 @@
#ifndef __RET_H__
#define __RET_H__
make_helper(ret_none_v);
make_helper(ret_i_v);
#endif

View File

@ -1,63 +0,0 @@
#include "cpu/exec/template-start.h"
static void concat(do_cmova_,SUFFIX)() {
if(cpu.EFLAGS.ZF == 0 && cpu.EFLAGS.CF == 0)
OPERAND_W(op_dest,op_src->val);
print_asm_template2();
}
static void concat(do_cmove_,SUFFIX)() {
if(cpu.EFLAGS.ZF == 1)
OPERAND_W(op_dest,op_src->val);
print_asm_template2();
}
static void concat(do_cmovge_,SUFFIX)() {
if(cpu.EFLAGS.SF == cpu.EFLAGS.OF)
OPERAND_W(op_dest,op_src->val);
print_asm_template2();
}
static void concat(do_cmovne_,SUFFIX)() {
if(cpu.EFLAGS.ZF == 0)
OPERAND_W(op_dest,op_src->val);
print_asm_template2();
}
static void concat(do_cmovns_,SUFFIX)() {
if(cpu.EFLAGS.SF == 0)
OPERAND_W(op_dest,op_src->val);
print_asm_template2();
}
static void concat(do_cmovs_,SUFFIX)() {
if(cpu.EFLAGS.SF == 1)
OPERAND_W(op_dest,op_src->val);
print_asm_template2();
}
#define instr cmova
make_instr_helper(rm2r)
#undef instr
#define instr cmove
make_instr_helper(rm2r)
#undef instr
#define instr cmovge
make_instr_helper(rm2r)
#undef instr
#define instr cmovne
make_instr_helper(rm2r)
#undef instr
#define instr cmovns
make_instr_helper(rm2r)
#undef instr
#define instr cmovs
make_instr_helper(rm2r)
#undef instr
#include "cpu/exec/template-end.h"

View File

@ -1,16 +0,0 @@
#include "cpu/exec/helper.h"
#define DATA_BYTE 2
#include "cmovcc-template.h"
#undef DATA_BYTE
#define DATA_BYTE 4
#include "cmovcc-template.h"
#undef DATA_BYTE
make_helper_v(cmova_rm2r)
make_helper_v(cmove_rm2r)
make_helper_v(cmovge_rm2r)
make_helper_v(cmovne_rm2r)
make_helper_v(cmovns_rm2r)
make_helper_v(cmovs_rm2r)

View File

@ -1,11 +0,0 @@
#ifndef __CMOVCC_H__
#define __CMOVCC_H__
make_helper(cmova_rm2r_v);
make_helper(cmove_rm2r_v);
make_helper(cmovge_rm2r_v);
make_helper(cmovne_rm2r_v);
make_helper(cmovns_rm2r_v);
make_helper(cmovs_rm2r_v);
#endif

View File

@ -1,41 +0,0 @@
#include "cpu/exec/template-start.h"
#define instr cvw
make_helper(concat(cvw_none_,SUFFIX)){
if(DATA_BYTE == 2)
{
if((DATA_TYPE_S)REG(R_AX)< 0)
REG(R_DX) = 0xFFFF;
else
REG(R_DX) = 0x0;
print_asm("%s" ,"cltd");
}
else
{
if((DATA_TYPE_S)cpu.eax < 0)
cpu.edx = 0xFFFFFFFF;
else
cpu.edx = 0x0;
print_asm("%s" ,"cltd");
}
return 1;
}
make_helper(concat(cbw_none_,SUFFIX)){
if(DATA_BYTE == 2)
{
REG(R_AX) = (DATA_TYPE_S)(REG(R_AL));
print_asm("%s" ,"cwtl");
}
else
{
REG(R_EAX) = (DATA_TYPE_S)(REG(R_AX));
print_asm("%s" ,"cwtl");
}
return 1;
}
#include "cpu/exec/template-end.h"

View File

@ -1,14 +0,0 @@
#include "cpu/exec/helper.h"
#define DATA_BYTE 2
#include "cvw-template.h"
#undef DATA_BYTE
#define DATA_BYTE 4
#include "cvw-template.h"
#undef DATA_BYTE
make_helper_v(cvw_none)
make_helper_v(cbw_none)

View File

@ -1,7 +0,0 @@
#ifndef __CVW_H__
#define __CVW_H__
make_helper(cvw_none_v);
make_helper(cbw_none_v);
#endif

View File

@ -1,32 +0,0 @@
#include "cpu/exec/template-start.h"
#define instr in
static void do_execute() {
assert(0);
/*DATA_TYPE io_temp = pio_read(op_src->val, DATA_BYTE);
if(DATA_BYTE == 1)
cpu.eax = (cpu.eax & 0xFFFFFF00) + io_temp;
else if(DATA_BYTE == 2)
cpu.eax = (cpu.eax & 0xFFFF0000) + io_temp;
else
cpu.eax = io_temp;
print_asm_template1();*/
}
make_instr_helper(i2a);
make_helper(concat(in_d2a_,SUFFIX)) {
uint16_t dx = cpu.edx;
DATA_TYPE io_temp = pio_read(dx, DATA_BYTE);
if(DATA_BYTE == 1)
REG(R_AL) = io_temp;
else if(DATA_BYTE == 2)
REG(R_AX) = io_temp;
else
REG(R_EAX) = io_temp;
print_asm_template1();
return 1;
}
#include "cpu/exec/template-end.h"

View File

@ -1,17 +0,0 @@
#include "cpu/exec/helper.h"
#include "device/port-io.h"
#define DATA_BYTE 1
#include "in-template.h"
#undef DATA_BYTE
#define DATA_BYTE 2
#include "in-template.h"
#undef DATA_BYTE
#define DATA_BYTE 4
#include "in-template.h"
#undef DATA_BYTE
make_helper_v(in_i2a)
make_helper_v(in_d2a)

View File

@ -1,9 +0,0 @@
#ifndef __IN_H__
#define __IN_H__
make_helper(in_i2a_v);
make_helper(in_i2a_b);
make_helper(in_d2a_v);
make_helper(in_d2a_b);
#endif

View File

@ -1,13 +0,0 @@
#include "cpu/exec/template-start.h"
#define instr leave
make_helper(concat(leave_none_ , SUFFIX)){
cpu.esp = cpu.ebp;
cpu.ebp = swaddr_read(cpu.esp, 4, R_SS);
cpu.esp = cpu.esp + 4;
print_asm(str(instr));
return 1;
}
#include "cpu/exec/template-end.h"

View File

@ -1,11 +0,0 @@
#include "cpu/exec/helper.h"
#define DATA_BYTE 2
#include "leave-template.h"
#undef DATA_BYTE
#define DATA_BYTE 4
#include "leave-template.h"
#undef DATA_BYTE
make_helper_v(leave_none);

View File

@ -1,6 +0,0 @@
#ifndef __LEAVE_H__
#define __LEAVE_H__
make_helper(leave_none_v);
#endif

View File

@ -1,123 +0,0 @@
#include "cpu/exec/template-start.h"
#define instr mov
static void do_execute() {
OPERAND_W(op_dest, op_src->val);
print_asm_template2();
}
make_instr_helper(i2r)
make_instr_helper(i2rm)
make_instr_helper(r2rm)
make_instr_helper(rm2r)
make_helper(concat(mov_a2moffs_, SUFFIX)) {
swaddr_t addr = instr_fetch(eip + 1, 4);
MEM_W(addr, REG(R_EAX), R_DS);
print_asm("mov" str(SUFFIX) " %%%s,0x%x", REG_NAME(R_EAX), addr);
return 5;
}
make_helper(concat(mov_moffs2a_, SUFFIX)) {
swaddr_t addr = instr_fetch(eip + 1, 4);
REG(R_EAX) = MEM_R(addr, R_DS);
print_asm("mov" str(SUFFIX) " 0x%x,%%%s", addr, REG_NAME(R_EAX));
return 5;
}
make_helper(concat(mov_cr2r_,SUFFIX)) {
uint8_t rm = instr_fetch(eip + 1,1) & 0x7;
uint8_t reg = (instr_fetch(eip + 1,1) >> 3) & 0x7;
if(reg == 0)
REG(rm) = cpu.cr0.val;
else if(reg == 3)
REG(rm) = cpu.cr3.val;
else
assert(0);
print_asm("mov" str(SUFFIX) " %s%x,%%%s", "CR", reg, REG_NAME(rm));
return 2;
}
make_helper(concat(mov_r2cr_,SUFFIX)) {
uint8_t rm = instr_fetch(eip + 1,1) & 0x7;
uint8_t reg = (instr_fetch(eip + 1,1) >> 3) & 0x7;
if(reg == 0)
cpu.cr0.val = REG(rm);
else if(reg == 3)
cpu.cr3.val = REG(rm);
else
assert(0);
print_asm("mov" str(SUFFIX) " %%%s,%s%x", REG_NAME(rm),"CR",reg);
return 2;
}
make_helper(concat(mov_a2sreg_,SUFFIX)) {
uint8_t reg = (instr_fetch(eip + 1, 1) >> 3) & 0x7;
uint16_t index = 0;
switch(reg)
{
case R_ES:{
cpu.ES.val = REG(R_EAX);
index = cpu.ES.INDEX;
break;
}
case R_CS:{
cpu.CS.val = REG(R_EAX);
index = cpu.CS.INDEX;
break;
}
case R_SS:{
cpu.SS.val = REG(R_EAX);
index = cpu.SS.INDEX;
break;
}
case R_DS:{
cpu.DS.val = REG(R_EAX);
index = cpu.DS.INDEX;
break;
}
}
sreg_desc s;
base_addr b;
limit lim;
s.val[0] = lnaddr_read(cpu.GDTR.GDT_BASE + index * 8, 4);
s.val[1] = lnaddr_read(cpu.GDTR.GDT_BASE + index * 8 + 4, 4);
b.base15 = s.sr_des.base_15_0;
b.base23 = s.sr_des.base_23_16;
b.base31 = s.sr_des.base_31_24;
lim.limit15 = s.sr_des.limit_15_0;
lim.limit19 = s.sr_des.limit_19_16;
switch(reg)
{
case R_ES:{
cpu.ES.base = b.val;
cpu.ES.limit = lim.val;
cpu.ES.valid = true;
break;
}
case R_CS:{
cpu.CS.base = b.val;
cpu.CS.limit = lim.val;
cpu.CS.valid = true;
break;
}
case R_SS:{
cpu.SS.base = b.val;
cpu.SS.limit = lim.val;
cpu.SS.valid = true;
break;
}
case R_DS:{
cpu.DS.base = b.val;
cpu.DS.limit = lim.val;
cpu.DS.valid = true;
break;
}
}
print_asm("mov" str(SUFFIX) " %%%s,%s", REG_NAME(R_EAX), "sreg");
return 2;
}
#include "cpu/exec/template-end.h"

View File

@ -1,28 +0,0 @@
#include "cpu/exec/helper.h"
#include "x86-inc/mmu.h"
#include "x86-inc/addr_struct.h"
#define DATA_BYTE 1
#include "mov-template.h"
#undef DATA_BYTE
#define DATA_BYTE 2
#include "mov-template.h"
#undef DATA_BYTE
#define DATA_BYTE 4
#include "mov-template.h"
#undef DATA_BYTE
/* for instruction encoding overloading */
make_helper_v(mov_i2r)
make_helper_v(mov_i2rm)
make_helper_v(mov_r2rm)
make_helper_v(mov_rm2r)
make_helper_v(mov_a2moffs)
make_helper_v(mov_moffs2a)
make_helper_v(mov_cr2r)
make_helper_v(mov_r2cr)
make_helper_v(mov_a2sreg)

View File

@ -1,21 +0,0 @@
#ifndef __MOV_H__
#define __MOV_H__
make_helper(mov_i2r_b);
make_helper(mov_i2rm_b);
make_helper(mov_r2rm_b);
make_helper(mov_rm2r_b);
make_helper(mov_a2moffs_b);
make_helper(mov_moffs2a_b);
make_helper(mov_i2r_v);
make_helper(mov_i2rm_v);
make_helper(mov_r2rm_v);
make_helper(mov_rm2r_v);
make_helper(mov_a2moffs_v);
make_helper(mov_moffs2a_v);
make_helper(mov_cr2r_v);
make_helper(mov_r2cr_v);
make_helper(mov_a2sreg_v);
#endif

View File

@ -1,21 +0,0 @@
#include "cpu/exec/template-start.h"
#define instr movsx
static void do_execute(){
if(instr_fetch(cpu.eip + 1,1) == 0xbe) /* movsb */
{
int8_t result = (DATA_TYPE_S)op_src->val;
OPERAND_W(op_dest, result);
}
else
{
int16_t result = (DATA_TYPE_S)op_src->val;
OPERAND_W(op_dest, result);
}
print_asm_template2();
}
make_instr_helper(rm2r)
#include "cpu/exec/template-end.h"

View File

@ -1,16 +0,0 @@
#include "cpu/exec/helper.h"
#define DATA_BYTE 1
#include "movsx-template.h"
#undef DATA_BYTE
#define DATA_BYTE 2
#include "movsx-template.h"
#undef DATA_BYTE
#define DATA_BYTE 4
#include "movsx-template.h"
#undef DATA_BYTE
make_helper_v(movsx_rm2r)

View File

@ -1,6 +0,0 @@
#ifndef __MOVSX_H__
#define __MOVSX_H__
make_helper(movsx_rm2r_v);
#endif

View File

@ -1,21 +0,0 @@
#include "cpu/exec/template-start.h"
#define instr movzx
static void do_execute(){
if(instr_fetch(cpu.eip+1,1) == 0xb6)/* movzb */
{
uint8_t result = (DATA_TYPE)op_src->val;
OPERAND_W(op_dest,result);
}
else
{
uint16_t result = (DATA_TYPE)op_src->val;
OPERAND_W(op_dest,result);
}
print_asm_template2();
}
make_instr_helper(rm2r);
#include "cpu/exec/template-end.h"

View File

@ -1,15 +0,0 @@
#include "cpu/exec/helper.h"
#define DATA_BYTE 1
#include "movzx-template.h"
#undef DATA_BYTE
#define DATA_BYTE 2
#include "movzx-template.h"
#undef DATA_BYTE
#define DATA_BYTE 4
#include "movzx-template.h"
#undef DATA_BYTE
make_helper_v(movzx_rm2r)

View File

@ -1,6 +0,0 @@
#ifndef __MOVZX_H__
#define __MOVZX_H__
make_helper(movzx_rm2r_v);
#endif

View File

@ -1,22 +0,0 @@
#include "cpu/exec/template-start.h"
#define instr out
make_helper(concat(out_a2i_,SUFFIX)) {
assert(0);
/*DATA_TYPE io_temp = cpu.eax;
op_dest->val = instr_fetch(cpu.eip + 1, DATA_BYTE);
pio_write(op_dest->val,DATA_BYTE,io_temp);
print_asm_template1();
return DATA_BYTE + 1;*/
}
make_helper(concat(out_a2d_,SUFFIX)) {
DATA_TYPE io_temp = cpu.eax;
uint16_t dx = cpu.edx;
pio_write(dx,DATA_BYTE,io_temp);
print_asm("out" str(SUFFIX) " al,(dl)");
return 1;
}
#include "cpu/exec/template-end.h"

Some files were not shown because too many files have changed in this diff Show More