|
|
| version 1.10, 2004/01/23 16:32:36 | version 1.42, 2012/01/08 11:32:16 |
|---|---|
| Line 1 | Line 1 |
| /* $Id$ */ | |
| /* | /* |
| * Copyright (c) 2002-2003 NONAKA Kimihiro | * Copyright (c) 2002-2003 NONAKA Kimihiro |
| * All rights reserved. | * All rights reserved. |
| Line 12 | Line 10 |
| * 2. Redistributions in binary form must reproduce the above copyright | * 2. Redistributions in binary form must reproduce the above copyright |
| * notice, this list of conditions and the following disclaimer in the | * notice, this list of conditions and the following disclaimer in the |
| * documentation and/or other materials provided with the distribution. | * documentation and/or other materials provided with the distribution. |
| * 3. The name of the author may not be used to endorse or promote products | |
| * derived from this software without specific prior written permission. | |
| * | * |
| * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
| * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| Line 32 | Line 28 |
| Copyright by Yui/Studio Milmake 1999-2000 | Copyright by Yui/Studio Milmake 1999-2000 |
| Copyright by Norio HATTORI 2000,2001 | Copyright by Norio HATTORI 2000,2001 |
| Copyright by NONAKA Kimihiro 2002-2003 | Copyright by NONAKA Kimihiro 2002-2004 |
| */ | */ |
| #ifndef IA32_CPU_CPU_H__ | #ifndef IA32_CPU_CPU_H__ |
| Line 47 extern "C" { | Line 43 extern "C" { |
| typedef union { | typedef union { |
| #if defined(BYTESEX_LITTLE) | #if defined(BYTESEX_LITTLE) |
| struct { | struct { |
| BYTE l; | UINT8 l; |
| BYTE h; | UINT8 h; |
| BYTE _hl; | UINT8 _hl; |
| BYTE _hh; | UINT8 _hh; |
| } b; | } b; |
| struct { | struct { |
| WORD w; | UINT16 w; |
| WORD _hw; | UINT16 _hw; |
| } w; | } w; |
| #elif defined(BYTESEX_BIG) | #elif defined(BYTESEX_BIG) |
| struct { | struct { |
| BYTE _hh; | UINT8 _hh; |
| BYTE _hl; | UINT8 _hl; |
| BYTE h; | UINT8 h; |
| BYTE l; | UINT8 l; |
| } b; | } b; |
| struct { | struct { |
| WORD _hw; | UINT16 _hw; |
| WORD w; | UINT16 w; |
| } w; | } w; |
| #endif | #endif |
| DWORD d; | UINT32 d; |
| } REG32; | } REG32; |
| typedef struct { | |
| UINT8 b[10]; | |
| } REG80; | |
| #ifdef __cplusplus | #ifdef __cplusplus |
| } | } |
| #endif | #endif |
| #include "cpu_io.h" | |
| #include "cpu_mem.h" | |
| #include "exception.h" | |
| #include "paging.h" | |
| #include "resolve.h" | |
| #include "segments.h" | #include "segments.h" |
| #include "task.h" | |
| #ifdef __cplusplus | #ifdef __cplusplus |
| extern "C" { | extern "C" { |
| Line 115 enum { | Line 109 enum { |
| }; | }; |
| enum { | enum { |
| CPU_DEBUG_REG_NUM = 8 | CPU_DEBUG_REG_NUM = 8, |
| CPU_DEBUG_REG_INDEX_NUM = 4 | |
| }; | }; |
| enum { | enum { |
| Line 124 enum { | Line 119 enum { |
| typedef struct { | typedef struct { |
| REG32 reg[CPU_REG_NUM]; | REG32 reg[CPU_REG_NUM]; |
| WORD sreg[CPU_SEGREG_NUM]; | UINT16 sreg[CPU_SEGREG_NUM]; |
| REG32 eflags; | REG32 eflags; |
| REG32 eip; | REG32 eip; |
| REG32 prev_eip; | REG32 prev_eip; |
| REG32 prev_esp; | |
| DWORD tr[CPU_TEST_REG_NUM]; | UINT32 tr[CPU_TEST_REG_NUM]; |
| DWORD dr[CPU_DEBUG_REG_NUM]; | UINT32 dr[CPU_DEBUG_REG_NUM]; |
| } CPU_REGS; | } CPU_REGS; |
| typedef struct { | typedef struct { |
| WORD gdtr_limit; | UINT16 gdtr_limit; |
| DWORD gdtr_base; | UINT16 pad0; |
| WORD idtr_limit; | UINT32 gdtr_base; |
| DWORD idtr_base; | UINT16 idtr_limit; |
| UINT16 pad1; | |
| WORD ldtr; | UINT32 idtr_base; |
| WORD tr; | |
| descriptor_t ldtr_desc; | UINT16 ldtr; |
| descriptor_t tr_desc; | UINT16 tr; |
| DWORD cr0; | UINT32 cr0; |
| DWORD cr1; | UINT32 cr1; |
| DWORD cr2; | UINT32 cr2; |
| DWORD cr3; | UINT32 cr3; |
| DWORD cr4; | UINT32 cr4; |
| DWORD mxcsr; | UINT32 mxcsr; |
| } CPU_SYSREGS; | } CPU_SYSREGS; |
| typedef struct { | typedef struct { |
| descriptor_t sreg[CPU_SEGREG_NUM]; | descriptor_t sreg[CPU_SEGREG_NUM]; |
| descriptor_t ldtr; | |
| descriptor_t tr; | |
| UINT32 adrsmask; | UINT32 adrsmask; |
| DWORD ovflag; | UINT32 ovflag; |
| BYTE ss_32; | UINT8 ss_32; |
| BYTE resetreq; | UINT8 resetreq; |
| BYTE trap; | UINT8 trap; |
| BYTE _dummy; | |
| BYTE cpl; | |
| BYTE protected_mode; | |
| BYTE paging; | |
| BYTE vm86; | |
| DWORD ioaddr; /* I/O bitmap linear address */ | UINT8 page_wp; |
| WORD iolimit; /* I/O bitmap count */ | |
| BYTE nerror; /* double fault/ triple fault */ | UINT8 protected_mode; |
| BYTE prev_exception; | UINT8 paging; |
| UINT8 vm86; | |
| UINT8 user_mode; | |
| UINT8 hlt; | |
| UINT8 bp; /* break point bitmap */ | |
| UINT8 bp_ev; /* break point event */ | |
| UINT8 backout_sp; /* backout ESP, when exception */ | |
| UINT32 pde_base; | |
| UINT32 ioaddr; /* I/O bitmap linear address */ | |
| UINT16 iolimit; /* I/O bitmap count */ | |
| UINT8 nerror; /* double fault/ triple fault */ | |
| UINT8 prev_exception; | |
| } CPU_STAT; | } CPU_STAT; |
| typedef struct { | typedef struct { |
| BYTE op_32; | UINT8 op_32; |
| BYTE as_32; | UINT8 as_32; |
| BYTE rep_used; | UINT8 rep_used; |
| BYTE seg_used; | UINT8 seg_used; |
| DWORD seg_base; | UINT32 seg_base; |
| } CPU_INST; | } CPU_INST; |
| /* FPU */ | |
| enum { | |
| FPU_REG_NUM = 8 | |
| }; | |
| typedef struct { | |
| UINT16 seg; | |
| UINT16 pad; | |
| UINT32 offset; | |
| } FPU_PTR; | |
| typedef struct { | |
| UINT16 control; | |
| UINT16 status; | |
| UINT16 op; | |
| FPU_PTR inst; | |
| FPU_PTR data; | |
| } FPU_REGS; | |
| typedef struct { | |
| UINT8 valid; /* ¥ì¥¸¥¹¥¿Í¸ú */ | |
| UINT8 sign; /* É乿 */ | |
| UINT8 zero; /* ¥¼¥í */ | |
| UINT8 inf; /* ¡ç */ | |
| UINT8 nan; /* NaN */ | |
| UINT8 denorm; /* ÈóÀµµ¬²½ */ | |
| SINT16 exp; /* »Ø¿ôÉô */ | |
| UINT64 num; /* ¾®¿ôÉô */ | |
| } FP_REG; | |
| typedef struct { | |
| UINT8 top; /* ¥¹¥¿¥Ã¥¯°ÌÃÖ */ | |
| UINT8 pc; /* ÀºÅÙ */ | |
| UINT8 rc; /* ´Ý¤á */ | |
| UINT8 dmy[1]; | |
| FP_REG reg[FPU_REG_NUM]; | |
| } FPU_STAT; | |
| typedef struct { | typedef struct { |
| CPU_REGS cpu_regs; | CPU_REGS cpu_regs; |
| CPU_SYSREGS cpu_sysregs; | CPU_SYSREGS cpu_sysregs; |
| Line 192 typedef struct { | Line 239 typedef struct { |
| CPU_INST cpu_inst; | CPU_INST cpu_inst; |
| CPU_INST cpu_inst_default; | CPU_INST cpu_inst_default; |
| #if defined(USE_FPU) | |
| FPU_REGS fpu_regs; | |
| FPU_STAT fpu_stat; | |
| #endif | |
| /* protected by cpu shut */ | /* protected by cpu shut */ |
| UINT8 cpu_type; | UINT8 cpu_type; |
| UINT8 itfbank; | UINT8 itfbank; |
| Line 201 typedef struct { | Line 253 typedef struct { |
| UINT32 clock; | UINT32 clock; |
| } I386STAT; | } I386STAT; |
| typedef struct { /* for ver0.73 */ | typedef struct { |
| BYTE *ext; | UINT8 *ext; |
| UINT32 extsize; | UINT32 extsize; |
| UINT8 *extbase; /* = ext - 0x100000 */ | |
| UINT32 extlimit16mb; /* = extsize + 0x100000 (MAX:16MB) */ | |
| UINT32 extlimit4gb; /* = extsize + 0x100000 */ | |
| UINT32 inport; | UINT32 inport; |
| UINT8 *ems[4]; | |
| } I386EXT; | } I386EXT; |
| typedef struct { | typedef struct { |
| I386STAT s; /* STATsave¡¢¥ª¡¢ø¦öÇ¥í */ | I386STAT s; /* STATsaveåáÊå£ìåâ¶ç¡¦¥¨ */ |
| I386EXT e; | I386EXT e; |
| } I386CORE; | } I386CORE; |
| Line 230 extern I386CORE i386core; | Line 286 extern I386CORE i386core; |
| #define CPU_EXTMEM i386core.e.ext | #define CPU_EXTMEM i386core.e.ext |
| #define CPU_EXTMEMSIZE i386core.e.extsize | #define CPU_EXTMEMSIZE i386core.e.extsize |
| #define CPU_EXTMEMBASE i386core.e.extbase | |
| #define CPU_EXTLIMIT16 i386core.e.extlimit16mb | |
| #define CPU_EXTLIMIT i386core.e.extlimit4gb | |
| #define CPU_INPADRS i386core.e.inport | #define CPU_INPADRS i386core.e.inport |
| #define CPU_EMSPTR i386core.e.ems | |
| extern BYTE iflags[]; | |
| extern sigjmp_buf exec_1step_jmpbuf; | extern sigjmp_buf exec_1step_jmpbuf; |
| Line 246 extern sigjmp_buf exec_1step_jmpbuf; | Line 305 extern sigjmp_buf exec_1step_jmpbuf; |
| /* version */ | /* version */ |
| #define CPU_FAMILY 4 | #define CPU_FAMILY 4 |
| #define CPU_MODEL 1 | #if defined(USE_FPU) |
| #define CPU_MODEL 1 /* 486DX */ | |
| #else | |
| #define CPU_MODEL 2 /* 486SX */ | |
| #endif | |
| #define CPU_STEPPING 3 | #define CPU_STEPPING 3 |
| /* feature */ | /* feature */ |
| Line 282 extern sigjmp_buf exec_1step_jmpbuf; | Line 345 extern sigjmp_buf exec_1step_jmpbuf; |
| /* (1 << 29) */ | /* (1 << 29) */ |
| /* (1 << 30) */ | /* (1 << 30) */ |
| /* (1 << 31) */ | /* (1 << 31) */ |
| #ifdef USE_FPU | #if defined(USE_FPU) |
| #define CPU_FEATURES (CPU_FEATURE_CMOV|CPU_FEATURE_FPU) | #define CPU_FEATURES (CPU_FEATURE_CMOV|CPU_FEATURE_FPU) |
| #else | #else |
| #define CPU_FEATURES (CPU_FEATURE_CMOV) | #define CPU_FEATURES (CPU_FEATURE_CMOV) |
| Line 296 extern sigjmp_buf exec_1step_jmpbuf; | Line 359 extern sigjmp_buf exec_1step_jmpbuf; |
| #define CPU_REGS_SREG(n) CPU_STATSAVE.cpu_regs.sreg[(n)] | #define CPU_REGS_SREG(n) CPU_STATSAVE.cpu_regs.sreg[(n)] |
| #define CPU_STAT_SREG(n) CPU_STATSAVE.cpu_stat.sreg[(n)] | #define CPU_STAT_SREG(n) CPU_STATSAVE.cpu_stat.sreg[(n)] |
| #define CPU_STAT_SREGBASE(n) CPU_STATSAVE.cpu_stat.sreg[(n)].u.seg.segbase | #define CPU_STAT_SREGBASE(n) CPU_STAT_SREG((n)).u.seg.segbase |
| #define CPU_STAT_SREGEND(n) CPU_STATSAVE.cpu_stat.sreg[(n)].u.seg.segend | #define CPU_STAT_SREGLIMIT(n) CPU_STAT_SREG((n)).u.seg.limit |
| #define CPU_STAT_SREGLIMIT(n) CPU_STATSAVE.cpu_stat.sreg[(n)].u.seg.limit | |
| #define CPU_STAT_SREG_CLEAR(n) \ | |
| do { \ | |
| memset(&CPU_STAT_SREG(n), 0, sizeof(descriptor_t)); \ | |
| } while (/*CONSTCOND*/ 0) | |
| #define CPU_STAT_SREG_INIT(n) \ | |
| do { \ | |
| descriptor_t sd; \ | |
| \ | |
| memset(&sd, 0, sizeof(sd)); \ | |
| sd.u.seg.limit = 0xffff; \ | |
| CPU_SET_SEGDESC_DEFAULT(&sd, (n), 0); \ | |
| CPU_STAT_SREG(n) = sd; \ | |
| } while (/*CONSTCOND*/ 0) | |
| #define CPU_AL CPU_REGS_BYTEL(CPU_EAX_INDEX) | #define CPU_AL CPU_REGS_BYTEL(CPU_EAX_INDEX) |
| Line 343 do { \ | Line 392 do { \ |
| #define CPU_EDI CPU_REGS_DWORD(CPU_EDI_INDEX) | #define CPU_EDI CPU_REGS_DWORD(CPU_EDI_INDEX) |
| #define CPU_EIP CPU_STATSAVE.cpu_regs.eip.d | #define CPU_EIP CPU_STATSAVE.cpu_regs.eip.d |
| #define CPU_PREV_EIP CPU_STATSAVE.cpu_regs.prev_eip.d | #define CPU_PREV_EIP CPU_STATSAVE.cpu_regs.prev_eip.d |
| #define CPU_PREV_ESP CPU_STATSAVE.cpu_regs.prev_esp.d | |
| #define CPU_ES CPU_REGS_SREG(CPU_ES_INDEX) | #define CPU_ES CPU_REGS_SREG(CPU_ES_INDEX) |
| #define CPU_CS CPU_REGS_SREG(CPU_CS_INDEX) | #define CPU_CS CPU_REGS_SREG(CPU_CS_INDEX) |
| Line 351 do { \ | Line 401 do { \ |
| #define CPU_FS CPU_REGS_SREG(CPU_FS_INDEX) | #define CPU_FS CPU_REGS_SREG(CPU_FS_INDEX) |
| #define CPU_GS CPU_REGS_SREG(CPU_GS_INDEX) | #define CPU_GS CPU_REGS_SREG(CPU_GS_INDEX) |
| #define ES_BASE CPU_STATSAVE.cpu_stat.sreg[CPU_ES_INDEX].u.seg.segbase | #define CPU_ES_DESC CPU_STAT_SREG(CPU_ES_INDEX) |
| #define CS_BASE CPU_STATSAVE.cpu_stat.sreg[CPU_CS_INDEX].u.seg.segbase | #define CPU_CS_DESC CPU_STAT_SREG(CPU_CS_INDEX) |
| #define SS_BASE CPU_STATSAVE.cpu_stat.sreg[CPU_SS_INDEX].u.seg.segbase | #define CPU_SS_DESC CPU_STAT_SREG(CPU_SS_INDEX) |
| #define DS_BASE CPU_STATSAVE.cpu_stat.sreg[CPU_DS_INDEX].u.seg.segbase | #define CPU_DS_DESC CPU_STAT_SREG(CPU_DS_INDEX) |
| #define FS_BASE CPU_STATSAVE.cpu_stat.sreg[CPU_FS_INDEX].u.seg.segbase | #define CPU_FS_DESC CPU_STAT_SREG(CPU_FS_INDEX) |
| #define GS_BASE CPU_STATSAVE.cpu_stat.sreg[CPU_GS_INDEX].u.seg.segbase | #define CPU_GS_DESC CPU_STAT_SREG(CPU_GS_INDEX) |
| #define ES_BASE CPU_STAT_SREGBASE(CPU_ES_INDEX) | |
| #define CS_BASE CPU_STAT_SREGBASE(CPU_CS_INDEX) | |
| #define SS_BASE CPU_STAT_SREGBASE(CPU_SS_INDEX) | |
| #define DS_BASE CPU_STAT_SREGBASE(CPU_DS_INDEX) | |
| #define FS_BASE CPU_STAT_SREGBASE(CPU_FS_INDEX) | |
| #define GS_BASE CPU_STAT_SREGBASE(CPU_GS_INDEX) | |
| #define CPU_EFLAG CPU_STATSAVE.cpu_regs.eflags.d | #define CPU_EFLAG CPU_STATSAVE.cpu_regs.eflags.d |
| #define CPU_FLAG CPU_STATSAVE.cpu_regs.eflags.w.w | #define CPU_FLAG CPU_STATSAVE.cpu_regs.eflags.w.w |
| #define CPU_FLAGL CPU_STATSAVE.cpu_regs.eflags.b.l | #define CPU_FLAGL CPU_STATSAVE.cpu_regs.eflags.b.l |
| #define CPU_FLAGH CPU_STATSAVE.cpu_regs.eflags.b.h | #define CPU_FLAGH CPU_STATSAVE.cpu_regs.eflags.b.h |
| #define CPU_TRAP CPU_STATSAVE.cpu_stat.trap | #define CPU_TRAP CPU_STATSAVE.cpu_stat.trap |
| // #define CPU_INPORT CPU_STATSAVE.cpu_stat.inport | #define CPU_INPORT CPU_STATSAVE.cpu_stat.inport |
| #define CPU_OV CPU_STATSAVE.cpu_stat.ovflag | #define CPU_OV CPU_STATSAVE.cpu_stat.ovflag |
| #define C_FLAG (1 << 0) | #define C_FLAG (1 << 0) |
| Line 390 do { \ | Line 447 do { \ |
| #define ALL_FLAG (SZAPC_FLAG|T_FLAG|I_FLAG|D_FLAG|O_FLAG|IOPL_FLAG|NT_FLAG) | #define ALL_FLAG (SZAPC_FLAG|T_FLAG|I_FLAG|D_FLAG|O_FLAG|IOPL_FLAG|NT_FLAG) |
| #define ALL_EFLAG (ALL_FLAG|RF_FLAG|VM_FLAG|AC_FLAG|VIF_FLAG|VIP_FLAG|ID_FLAG) | #define ALL_EFLAG (ALL_FLAG|RF_FLAG|VM_FLAG|AC_FLAG|VIF_FLAG|VIP_FLAG|ID_FLAG) |
| #define REAL_FLAGREG ((CPU_FLAG & 0xf7ff) | (CPU_OV ? O_FLAG : 0)) | #define REAL_FLAGREG ((CPU_FLAG & 0xf7ff) | (CPU_OV ? O_FLAG : 0) | 2) |
| #define REAL_EFLAGREG ((CPU_EFLAG & 0xfffff7ff) | (CPU_OV ? O_FLAG : 0)) | #define REAL_EFLAGREG ((CPU_EFLAG & 0xfffff7ff) | (CPU_OV ? O_FLAG : 0) | 2) |
| void set_flags(WORD new_flags, WORD mask); | void CPUCALL set_flags(UINT16 new_flags, UINT16 mask); |
| void set_eflags(DWORD new_flags, DWORD mask); | void CPUCALL set_eflags(UINT32 new_flags, UINT32 mask); |
| #define CPU_INST_OP32 CPU_STATSAVE.cpu_inst.op_32 | #define CPU_INST_OP32 CPU_STATSAVE.cpu_inst.op_32 |
| Line 405 void set_eflags(DWORD new_flags, DWORD m | Line 462 void set_eflags(DWORD new_flags, DWORD m |
| #define DS_FIX (!CPU_INST_SEGUSE ? CPU_DS_INDEX : CPU_INST_SEGREG_INDEX) | #define DS_FIX (!CPU_INST_SEGUSE ? CPU_DS_INDEX : CPU_INST_SEGREG_INDEX) |
| #define SS_FIX (!CPU_INST_SEGUSE ? CPU_SS_INDEX : CPU_INST_SEGREG_INDEX) | #define SS_FIX (!CPU_INST_SEGUSE ? CPU_SS_INDEX : CPU_INST_SEGREG_INDEX) |
| #define CPU_STAT_CS_BASE CPU_STATSAVE.cpu_stat.sreg[CPU_CS_INDEX].u.seg.limit | #define CPU_STAT_CS_BASE CPU_STAT_SREGBASE(CPU_CS_INDEX) |
| #define CPU_STAT_CS_LIMIT CPU_STATSAVE.cpu_stat.sreg[CPU_CS_INDEX].u.seg.limit | #define CPU_STAT_CS_LIMIT CPU_STAT_SREGLIMIT(CPU_CS_INDEX) |
| #define CPU_STAT_CS_END CPU_STATSAVE.cpu_stat.sreg[CPU_CS_INDEX].u.seg.segend | |
| #define CPU_STAT_ADRSMASK CPU_STATSAVE.cpu_stat.adrsmask | #define CPU_STAT_ADRSMASK CPU_STATSAVE.cpu_stat.adrsmask |
| #define CPU_STAT_SS32 CPU_STATSAVE.cpu_stat.ss_32 | #define CPU_STAT_SS32 CPU_STATSAVE.cpu_stat.ss_32 |
| #define CPU_STAT_RESETREQ CPU_STATSAVE.cpu_stat.resetreq | #define CPU_STAT_RESETREQ CPU_STATSAVE.cpu_stat.resetreq |
| #define CPU_STAT_PM CPU_STATSAVE.cpu_stat.protected_mode | #define CPU_STAT_PM CPU_STATSAVE.cpu_stat.protected_mode |
| #define CPU_STAT_VM86 CPU_STATSAVE.cpu_stat.vm86 | |
| #define CPU_STAT_PAGING CPU_STATSAVE.cpu_stat.paging | #define CPU_STAT_PAGING CPU_STATSAVE.cpu_stat.paging |
| #define CPU_STAT_CPL CPU_STATSAVE.cpu_stat.cpl | #define CPU_STAT_VM86 CPU_STATSAVE.cpu_stat.vm86 |
| #define CPU_STAT_WP CPU_STATSAVE.cpu_stat.page_wp | |
| #define CPU_STAT_CPL CPU_CS_DESC.rpl | |
| #define CPU_STAT_USER_MODE CPU_STATSAVE.cpu_stat.user_mode | |
| #define CPU_STAT_PDE_BASE CPU_STATSAVE.cpu_stat.pde_base | |
| #define CPU_SET_PREV_ESP1(esp) \ | |
| do { \ | |
| CPU_STATSAVE.cpu_stat.backout_sp = 1; \ | |
| CPU_PREV_ESP = (esp); \ | |
| } while (/*CONSTCOND*/0) | |
| #define CPU_SET_PREV_ESP() CPU_SET_PREV_ESP1(CPU_ESP) | |
| #define CPU_CLEAR_PREV_ESP() \ | |
| do { \ | |
| CPU_STATSAVE.cpu_stat.backout_sp = 0; \ | |
| } while (/*CONSTCOND*/0) | |
| #define CPU_STAT_HLT CPU_STATSAVE.cpu_stat.hlt | |
| #define CPU_STAT_IOPL ((CPU_EFLAG & IOPL_FLAG) >> 12) | #define CPU_STAT_IOPL ((CPU_EFLAG & IOPL_FLAG) >> 12) |
| #define CPU_IOPL0 0 | #define CPU_IOPL0 0 |
| Line 426 void set_eflags(DWORD new_flags, DWORD m | Line 497 void set_eflags(DWORD new_flags, DWORD m |
| #define CPU_STAT_IOADDR CPU_STATSAVE.cpu_stat.ioaddr | #define CPU_STAT_IOADDR CPU_STATSAVE.cpu_stat.ioaddr |
| #define CPU_STAT_IOLIMIT CPU_STATSAVE.cpu_stat.iolimit | #define CPU_STAT_IOLIMIT CPU_STATSAVE.cpu_stat.iolimit |
| #define CPU_STAT_NERROR CPU_STATSAVE.cpu_stat.nerror | #define CPU_STAT_PREV_EXCEPTION CPU_STATSAVE.cpu_stat.prev_exception |
| #define CPU_STAT_PREV_EXCEPTION CPU_STATSAVE.cpu_stat.prev_exception | #define CPU_STAT_EXCEPTION_COUNTER CPU_STATSAVE.cpu_stat.nerror |
| #define CPU_STAT_EXCEPTION_COUNTER_INC() CPU_STATSAVE.cpu_stat.nerror++ | |
| #define CPU_STAT_EXCEPTION_COUNTER_CLEAR() CPU_STATSAVE.cpu_stat.nerror = 0 | |
| #define CPU_CLI do { CPU_FLAG &= ~I_FLAG; \ | #define CPU_MODE_SUPERVISER 0 |
| CPU_TRAP = 0; } while (/*CONSTCOND*/ 0) | #define CPU_MODE_USER (1 << 3) |
| #define CPU_STI do { CPU_FLAG |= I_FLAG; \ | |
| CPU_TRAP = (CPU_FLAG >> 8) & 1; } while (/*CONSTCOND*/0) | #define CPU_CLI \ |
| do { \ | |
| CPU_FLAG &= ~I_FLAG; \ | |
| CPU_TRAP = 0; \ | |
| } while (/*CONSTCOND*/0) | |
| #define CPU_STI \ | |
| do { \ | |
| CPU_FLAG |= I_FLAG; \ | |
| CPU_TRAP = (CPU_FLAG & (I_FLAG|T_FLAG)) == (I_FLAG|T_FLAG) ; \ | |
| } while (/*CONSTCOND*/0) | |
| #define CPU_GDTR_LIMIT CPU_STATSAVE.cpu_sysregs.gdtr_limit | #define CPU_GDTR_LIMIT CPU_STATSAVE.cpu_sysregs.gdtr_limit |
| #define CPU_GDTR_BASE CPU_STATSAVE.cpu_sysregs.gdtr_base | #define CPU_GDTR_BASE CPU_STATSAVE.cpu_sysregs.gdtr_base |
| #define CPU_IDTR_LIMIT CPU_STATSAVE.cpu_sysregs.idtr_limit | #define CPU_IDTR_LIMIT CPU_STATSAVE.cpu_sysregs.idtr_limit |
| #define CPU_IDTR_BASE CPU_STATSAVE.cpu_sysregs.idtr_base | #define CPU_IDTR_BASE CPU_STATSAVE.cpu_sysregs.idtr_base |
| #define CPU_LDTR CPU_STATSAVE.cpu_sysregs.ldtr | #define CPU_LDTR CPU_STATSAVE.cpu_sysregs.ldtr |
| #define CPU_LDTR_DESC CPU_STATSAVE.cpu_sysregs.ldtr_desc | #define CPU_LDTR_DESC CPU_STATSAVE.cpu_stat.ldtr |
| #define CPU_LDTR_BASE CPU_STATSAVE.cpu_sysregs.ldtr_desc.u.seg.segbase | #define CPU_LDTR_BASE CPU_LDTR_DESC.u.seg.segbase |
| #define CPU_LDTR_END CPU_STATSAVE.cpu_sysregs.ldtr_desc.u.seg.segend | #define CPU_LDTR_LIMIT CPU_LDTR_DESC.u.seg.limit |
| #define CPU_LDTR_LIMIT CPU_STATSAVE.cpu_sysregs.ldtr_desc.u.seg.limit | |
| #define CPU_TR CPU_STATSAVE.cpu_sysregs.tr | #define CPU_TR CPU_STATSAVE.cpu_sysregs.tr |
| #define CPU_TR_DESC CPU_STATSAVE.cpu_sysregs.tr_desc | #define CPU_TR_DESC CPU_STATSAVE.cpu_stat.tr |
| #define CPU_TR_BASE CPU_STATSAVE.cpu_sysregs.tr_desc.u.seg.segbase | #define CPU_TR_BASE CPU_TR_DESC.u.seg.segbase |
| #define CPU_TR_END CPU_STATSAVE.cpu_sysregs.tr_desc.u.seg.segend | #define CPU_TR_LIMIT CPU_TR_DESC.u.seg.limit |
| #define CPU_TR_LIMIT CPU_STATSAVE.cpu_sysregs.tr_desc.u.seg.limit | |
| /* | /* |
| * control register | * control register |
| Line 472 void set_eflags(DWORD new_flags, DWORD m | Line 553 void set_eflags(DWORD new_flags, DWORD m |
| #define CPU_CR0_NW (1 << 29) | #define CPU_CR0_NW (1 << 29) |
| #define CPU_CR0_CD (1 << 30) | #define CPU_CR0_CD (1 << 30) |
| #define CPU_CR0_PG (1 << 31) | #define CPU_CR0_PG (1 << 31) |
| #define CPU_CR0_ALL (CPU_CR0_PE|CPU_CR0_MP|CPU_CR0_EM|CPU_CR0_TS|CPU_CR0_ET|CPU_CR0_NE|CPU_CR0_WP|CPU_CR0_AM|CPU_CR0_NW|CPU_CR0_CD|CPU_CR0_PG) | |
| #define CPU_CR3_PD_MASK 0xfffff000 | #define CPU_CR3_PD_MASK 0xfffff000 |
| #define CPU_CR3_PWT (1 << 3) | #define CPU_CR3_PWT (1 << 3) |
| Line 490 void set_eflags(DWORD new_flags, DWORD m | Line 572 void set_eflags(DWORD new_flags, DWORD m |
| #define CPU_CR4_OSFXSR (1 << 9) | #define CPU_CR4_OSFXSR (1 << 9) |
| #define CPU_CR4_OSXMMEXCPT (1 << 10) | #define CPU_CR4_OSXMMEXCPT (1 << 10) |
| /* | |
| * debug register | |
| */ | |
| #define CPU_DR(r) CPU_STATSAVE.cpu_regs.dr[(r)] | |
| #define CPU_DR6 CPU_DR(6) | |
| #define CPU_DR7 CPU_DR(7) | |
| #define CPU_STAT_BP CPU_STATSAVE.cpu_stat.bp | |
| #define CPU_STAT_BP_EVENT CPU_STATSAVE.cpu_stat.bp_ev | |
| #define CPU_STAT_BP_EVENT_B(r) (1 << (r)) | |
| #define CPU_STAT_BP_EVENT_DR (1 << 4) /* fault */ | |
| #define CPU_STAT_BP_EVENT_STEP (1 << 5) /* as CPU_TRAP */ | |
| #define CPU_STAT_BP_EVENT_TASK (1 << 6) | |
| #define CPU_STAT_BP_EVENT_RF (1 << 7) /* RF_FLAG */ | |
| #define CPU_DR6_B(r) (1 << (r)) | |
| #define CPU_DR6_BD (1 << 13) | |
| #define CPU_DR6_BS (1 << 14) | |
| #define CPU_DR6_BT (1 << 15) | |
| #define CPU_DR7_L(r) (1 << ((r) * 2)) | |
| #define CPU_DR7_G(r) (1 << ((r) * 2 + 1)) | |
| #define CPU_DR7_LE (1 << 8) | |
| #define CPU_DR7_GE (1 << 9) | |
| #define CPU_DR7_GD (1 << 13) | |
| #define CPU_DR7_RW(r) (3 << ((r) * 4 + 16)) | |
| #define CPU_DR7_LEN(r) (3 << ((r) * 4 + 16 + 2)) | |
| #define CPU_DR7_GET_RW(r) ((CPU_DR7) >> (16 + (r) * 4)) | |
| #define CPU_DR7_RW_CODE 0 | |
| #define CPU_DR7_RW_RO 1 | |
| #define CPU_DR7_RW_IO 2 | |
| #define CPU_DR7_RW_RW 3 | |
| #define CPU_DR7_GET_LEN(r) ((CPU_DR7) >> (16 + 2 + (r) * 4)) | |
| void ia32_init(void); | void ia32_init(void); |
| void ia32_initreg(void); | |
| void ia32_setextsize(UINT32 size); | |
| void ia32_setemm(UINT frame, UINT32 addr); | |
| void ia32reset(void); | void ia32reset(void); |
| void ia32shut(void); | void ia32shut(void); |
| void ia32a20enable(BOOL enable); | |
| void ia32(void); | void ia32(void); |
| void ia32withtrap(void); | |
| void ia32withdma(void); | |
| void ia32_step(void); | void ia32_step(void); |
| void CPUCALL ia32_interrupt(BYTE vect); | void CPUCALL ia32_interrupt(int vect, int soft); |
| void CPUCALL ia32_exception(DWORD vect, DWORD p1, DWORD p2); | |
| void exec_1step(void); | void exec_1step(void); |
| #define INST_PREFIX (1 << 0) | #define INST_PREFIX (1 << 0) |
| #define INST_STRING (1 << 1) | #define INST_STRING (1 << 1) |
| #define REP_CHECKZF (1 << 7) | #define REP_CHECKZF (1 << 7) |
| void disasm(WORD cs, DWORD maddr); | |
| void ia32_printf(const char *buf, ...); | void ia32_printf(const char *buf, ...); |
| void ia32_warning(const char *buf, ...); | void ia32_warning(const char *buf, ...); |
| void ia32_panic(const char *buf, ...); | void ia32_panic(const char *buf, ...); |
| void ia32_bioscall(void); | void ia32_bioscall(void); |
| void FASTCALL change_pm(BOOL onoff); | void CPUCALL change_pm(BOOL onoff); |
| void FASTCALL change_vm(BOOL onoff); | void CPUCALL change_vm(BOOL onoff); |
| void CPUCALL change_pg(BOOL onoff); | |
| extern BYTE szpcflag[0x200]; | |
| extern BYTE szpflag_w[0x10000]; | void CPUCALL set_cr3(UINT32 new_cr3); |
| void CPUCALL set_cpl(int new_cpl); | |
| extern BYTE *reg8_b20[0x100]; | |
| extern BYTE *reg8_b53[0x100]; | extern const UINT8 iflags[]; |
| extern WORD *reg16_b20[0x100]; | #define szpcflag iflags |
| extern WORD *reg16_b53[0x100]; | extern UINT8 szpflag_w[0x10000]; |
| extern DWORD *reg32_b20[0x100]; | |
| extern DWORD *reg32_b53[0x100]; | extern UINT8 *reg8_b20[0x100]; |
| extern UINT8 *reg8_b53[0x100]; | |
| extern UINT16 *reg16_b20[0x100]; | |
| extern UINT16 *reg16_b53[0x100]; | |
| extern UINT32 *reg32_b20[0x100]; | |
| extern UINT32 *reg32_b53[0x100]; | |
| extern const char *reg8_str[8]; | extern const char *reg8_str[8]; |
| extern const char *reg16_str[8]; | extern const char *reg16_str[8]; |
| extern const char *reg32_str[8]; | extern const char *reg32_str[8]; |
| char *cpu_reg2str(void); | |
| #if defined(USE_FPU) | |
| char *fpu_reg2str(void); | |
| #endif | |
| void put_cpuinfo(void); | |
| void dbg_printf(const char *str, ...); | |
| /* | |
| * FPU | |
| */ | |
| #define FPU_REGS CPU_STATSAVE.fpu_regs | |
| #define FPU_CTRLWORD FPU_REGS.control | |
| #define FPU_STATUSWORD FPU_REGS.status | |
| #define FPU_INSTPTR FPU_REGS.inst | |
| #define FPU_DATAPTR FPU_REGS.data | |
| #define FPU_LASTINSTOP FPU_REGS.op | |
| #define FPU_INSTPTR_OFFSET FPU_REGS.inst.offset | |
| #define FPU_INSTPTR_SEG FPU_REGS.inst.seg | |
| #define FPU_DATAPTR_OFFSET FPU_REGS.data.offset | |
| #define FPU_DATAPTR_SEG FPU_REGS.data.seg | |
| #define FPU_STAT CPU_STATSAVE.fpu_stat | |
| #define FPU_STAT_TOP FPU_STAT.top | |
| #define FPU_STAT_PC FPU_STAT.pc | |
| #define FPU_STAT_RC FPU_STAT.rc | |
| #define FPU_ST(i) FPU_STAT.reg[((i) + FPU_STAT_TOP) & 7] | |
| #define FPU_REG(i) FPU_STAT.reg[i] | |
| /* FPU status register */ | |
| #define FP_IE_FLAG (1 << 0) /* íä¡£éꥱåᥧéëÊæ¥¹*/ | |
| #define FP_DE_FLAG (1 << 1) /* ¥Ç¥Î¡¼¥Þ¥é¥¤¥º¥É¡¦¥ª¥Ú¥é¥ó¥É */ | |
| #define FP_ZE_FLAG (1 << 2) /* ¥¼¥í¤Ë¤è¤ë½ü»» */ | |
| #define FP_OE_FLAG (1 << 3) /* ¥ª¡¼¥Ð¡¼¥Õ¥í¡¼ */ | |
| #define FP_UE_FLAG (1 << 4) /* ¥¢¥ó¥À¡¼¥Õ¥í¡¼ */ | |
| #define FP_PE_FLAG (1 << 5) /* ÀºÅÙ */ | |
| #define FP_SF_FLAG (1 << 6) /* ¥¹¥¿¥Ã¥¯¥Õ¥©¥ë¥È */ | |
| #define FP_ES_FLAG (1 << 7) /* ¥¨¥é¡¼¥µ¥Þ¥ê¥¹¥Æ¡¼¥¿¥¹ */ | |
| #define FP_C0_FLAG (1 << 8) /* ¾ò·ï¥³¡¼¥É */ | |
| #define FP_C1_FLAG (1 << 9) /* ¾ò·ï¥³¡¼¥É */ | |
| #define FP_C2_FLAG (1 << 10) /* ¾ò·ï¥³¡¼¥É */ | |
| #define FP_TOP_FLAG (7 << 11) /* ¥¹¥¿¥Ã¥¯¥Ý¥¤¥ó¥È¤Î¥È¥Ã¥× */ | |
| #define FP_C3_FLAG (1 << 14) /* ¾ò·ï¥³¡¼¥É */ | |
| #define FP_B_FLAG (1 << 15) /* FPU ¥Ó¥¸¡¼ */ | |
| #define FP_TOP_SHIFT 11 | |
| #define FP_TOP_GET() ((FPU_STATUSWORD & FP_TOP_FLAG) >> FP_TOP_SHIFT) | |
| #define FP_TOP_SET(v) ((FPU_STATUSWORD & ~FP_TOP_FLAG) | ((v) << FP_TOP_SHIFT)) | |
| #define FPU_STAT_TOP_INC() \ | |
| do { \ | |
| FPU_STAT.top = (FPU_STAT.top + 1) & 7; \ | |
| } while (/*CONSTCOND*/0) | |
| #define FPU_STAT_TOP_DEC() \ | |
| do { \ | |
| FPU_STAT.top = (FPU_STAT.top - 1) & 7; \ | |
| } while (/*CONSTCOND*/0) | |
| /* FPU control register */ | |
| #define FP_CTRL_PC_SHIFT 8 /* ÀºÅÙÀ©¸æ */ | |
| #define FP_CTRL_RC_SHIFT 10 /* ´Ý¤áÀ©¸æ */ | |
| #define FP_CTRL_PC_24 0 /* ñÀºÅÙ */ | |
| #define FP_CTRL_PC_53 1 /* ÇÜÀºÅÙ */ | |
| #define FP_CTRL_PC_64 3 /* ³ÈÄ¥ÀºÅÙ */ | |
| #define FP_CTRL_RC_NEAREST_EVEN 0 | |
| #define FP_CTRL_RC_DOWN 1 | |
| #define FP_CTRL_RC_UP 2 | |
| #define FP_CTRL_RC_TO_ZERO 3 | |
| /* | /* |
| * Misc. | * Misc. |
| */ | */ |
| void gdtr_dump(DWORD base, DWORD limit); | void memory_dump(int idx, UINT32 madr); |
| void idtr_dump(DWORD base, DWORD limit); | void gdtr_dump(UINT32 base, UINT limit); |
| void ldtr_dump(DWORD base, DWORD limit); | void idtr_dump(UINT32 base, UINT limit); |
| void tr_dump(WORD selector, DWORD base, DWORD limit); | void ldtr_dump(UINT32 base, UINT limit); |
| void tr_dump(UINT16 selector, UINT32 base, UINT limit); | |
| UINT32 pde_dump(UINT32 base, int idx); | |
| void segdesc_dump(descriptor_t *sdp); | |
| UINT32 convert_laddr_to_paddr(UINT32 laddr); | |
| UINT32 convert_vaddr_to_paddr(unsigned int idx, UINT32 offset); | |
| /* | |
| * disasm | |
| */ | |
| /* context */ | |
| typedef struct { | |
| UINT32 val; | |
| UINT32 eip; | |
| BOOL op32; | |
| BOOL as32; | |
| UINT32 baseaddr; | |
| UINT8 opcode[3]; | |
| UINT8 modrm; | |
| UINT8 sib; | |
| BOOL useseg; | |
| int seg; | |
| UINT8 opbyte[32]; | |
| int nopbytes; | |
| char str[256]; | |
| size_t remain; | |
| char *next; | |
| char *prefix; | |
| char *op; | |
| char *arg[3]; | |
| int narg; | |
| char pad; | |
| } disasm_context_t; | |
| int disasm(UINT32 *eip, disasm_context_t *ctx); | |
| char *cpu_disasm2str(UINT32 eip); | |
| #ifdef __cplusplus | #ifdef __cplusplus |
| } | } |
| #endif | #endif |
| #include "cpu_io.h" | |
| #include "cpu_mem.h" | |
| #include "exception.h" | |
| #include "paging.h" | |
| #include "resolve.h" | |
| #include "task.h" | |
| #endif /* !IA32_CPU_CPU_H__ */ | #endif /* !IA32_CPU_CPU_H__ */ |