diff --git a/src/CPU/codegen.h b/src/CPU/codegen.h index e86919c3a..d9175d3a5 100644 --- a/src/CPU/codegen.h +++ b/src/CPU/codegen.h @@ -311,7 +311,8 @@ static __inline void addbyte(uint8_t val) static __inline void addword(uint16_t val) { - *(uint16_t *)&codeblock[block_current].data[block_pos] = val; + uint16_t *p = (uint16_t *)&codeblock[block_current].data[block_pos]; + *p = val; block_pos += 2; if (block_pos >= BLOCK_MAX) { @@ -321,7 +322,8 @@ static __inline void addword(uint16_t val) static __inline void addlong(uint32_t val) { - *(uint32_t *)&codeblock[block_current].data[block_pos] = val; + uint32_t *p = (uint32_t *)&codeblock[block_current].data[block_pos]; + *p = val; block_pos += 4; if (block_pos >= BLOCK_MAX) { @@ -331,7 +333,8 @@ static __inline void addlong(uint32_t val) static __inline void addquad(uint64_t val) { - *(uint64_t *)&codeblock[block_current].data[block_pos] = val; + uint64_t *p = (uint64_t *)&codeblock[block_current].data[block_pos]; + *p = val; block_pos += 8; if (block_pos >= BLOCK_MAX) { diff --git a/src/CPU/codegen_ops_arith.h b/src/CPU/codegen_ops_arith.h index fc67be9f1..ed2ce1ece 100644 --- a/src/CPU/codegen_ops_arith.h +++ b/src/CPU/codegen_ops_arith.h @@ -2,15 +2,15 @@ static uint32_t ropINC_rw(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uin { int host_reg; - CALL_FUNC((void *) flags_rebuild_c); + CALL_FUNC((uintptr_t)flags_rebuild_c); host_reg = LOAD_REG_W(opcode & 7); - STORE_HOST_REG_ADDR_WL((uint32_t)&cpu_state.flags_op1, host_reg); + STORE_HOST_REG_ADDR_WL((uintptr_t)&cpu_state.flags_op1, host_reg); ADD_HOST_REG_IMM_W(host_reg, 1); - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op2, 1); - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op, FLAGS_INC16); - STORE_HOST_REG_ADDR_WL((uint32_t)&cpu_state.flags_res, host_reg); + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op2, 1); + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op, FLAGS_INC16); + STORE_HOST_REG_ADDR_WL((uintptr_t)&cpu_state.flags_res, host_reg); STORE_REG_W_RELEASE(host_reg); codegen_flags_changed = 1; @@ -21,15 +21,15 @@ static uint32_t ropINC_rl(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uin { int host_reg; - CALL_FUNC((void *) flags_rebuild_c); + CALL_FUNC((uintptr_t)flags_rebuild_c); host_reg = LOAD_REG_L(opcode & 7); - STORE_HOST_REG_ADDR((uint32_t)&cpu_state.flags_op1, host_reg); + STORE_HOST_REG_ADDR((uintptr_t)&cpu_state.flags_op1, host_reg); ADD_HOST_REG_IMM(host_reg, 1); - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op2, 1); - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op, FLAGS_INC32); - STORE_HOST_REG_ADDR((uint32_t)&cpu_state.flags_res, host_reg); + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op2, 1); + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op, FLAGS_INC32); + STORE_HOST_REG_ADDR((uintptr_t)&cpu_state.flags_res, host_reg); STORE_REG_L_RELEASE(host_reg); codegen_flags_changed = 1; @@ -40,15 +40,15 @@ static uint32_t ropDEC_rw(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uin { int host_reg; - CALL_FUNC((void *) flags_rebuild_c); + CALL_FUNC((uintptr_t)flags_rebuild_c); host_reg = LOAD_REG_W(opcode & 7); - STORE_HOST_REG_ADDR_WL((uint32_t)&cpu_state.flags_op1, host_reg); + STORE_HOST_REG_ADDR_WL((uintptr_t)&cpu_state.flags_op1, host_reg); SUB_HOST_REG_IMM_W(host_reg, 1); - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op2, 1); - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op, FLAGS_DEC16); - STORE_HOST_REG_ADDR_WL((uint32_t)&cpu_state.flags_res, host_reg); + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op2, 1); + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op, FLAGS_DEC16); + STORE_HOST_REG_ADDR_WL((uintptr_t)&cpu_state.flags_res, host_reg); STORE_REG_W_RELEASE(host_reg); codegen_flags_changed = 1; @@ -59,15 +59,15 @@ static uint32_t ropDEC_rl(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uin { int host_reg; - CALL_FUNC((void *) flags_rebuild_c); + CALL_FUNC((uintptr_t)flags_rebuild_c); host_reg = LOAD_REG_L(opcode & 7); - STORE_HOST_REG_ADDR((uint32_t)&cpu_state.flags_op1, host_reg); + STORE_HOST_REG_ADDR((uintptr_t)&cpu_state.flags_op1, host_reg); SUB_HOST_REG_IMM(host_reg, 1); - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op2, 1); - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op, FLAGS_DEC32); - STORE_HOST_REG_ADDR((uint32_t)&cpu_state.flags_res, host_reg); + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op2, 1); + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op, FLAGS_DEC32); + STORE_HOST_REG_ADDR((uintptr_t)&cpu_state.flags_res, host_reg); STORE_REG_L_RELEASE(host_reg); codegen_flags_changed = 1; @@ -93,12 +93,12 @@ static uint32_t ropDEC_rl(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uin MEM_CHECK_WRITE(target_seg); \ dst_reg = MEM_LOAD_ADDR_EA_B_NO_ABRT(target_seg); \ } \ - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op, FLAGS_ ## op ## 8); \ + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op, FLAGS_ ## op ## 8); \ src_reg = LOAD_REG_B((fetchdat >> 3) & 7); \ - STORE_HOST_REG_ADDR_BL((uint32_t)&cpu_state.flags_op1, dst_reg); \ - STORE_HOST_REG_ADDR_BL((uint32_t)&cpu_state.flags_op2, src_reg); \ + STORE_HOST_REG_ADDR_BL((uintptr_t)&cpu_state.flags_op1, dst_reg); \ + STORE_HOST_REG_ADDR_BL((uintptr_t)&cpu_state.flags_op2, src_reg); \ op ## _HOST_REG_B(dst_reg, src_reg); \ - STORE_HOST_REG_ADDR_BL((uint32_t)&cpu_state.flags_res, dst_reg); \ + STORE_HOST_REG_ADDR_BL((uintptr_t)&cpu_state.flags_res, dst_reg); \ if (writeback) \ { \ if ((fetchdat & 0xc0) == 0xc0) \ @@ -133,12 +133,12 @@ static uint32_t ropDEC_rl(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uin MEM_CHECK_WRITE_W(target_seg); \ dst_reg = MEM_LOAD_ADDR_EA_W_NO_ABRT(target_seg); \ } \ - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op, FLAGS_ ## op ## 16); \ + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op, FLAGS_ ## op ## 16); \ src_reg = LOAD_REG_W((fetchdat >> 3) & 7); \ - STORE_HOST_REG_ADDR_WL((uint32_t)&cpu_state.flags_op1, dst_reg); \ - STORE_HOST_REG_ADDR_WL((uint32_t)&cpu_state.flags_op2, src_reg); \ + STORE_HOST_REG_ADDR_WL((uintptr_t)&cpu_state.flags_op1, dst_reg); \ + STORE_HOST_REG_ADDR_WL((uintptr_t)&cpu_state.flags_op2, src_reg); \ op ## _HOST_REG_W(dst_reg, src_reg); \ - STORE_HOST_REG_ADDR_WL((uint32_t)&cpu_state.flags_res, dst_reg); \ + STORE_HOST_REG_ADDR_WL((uintptr_t)&cpu_state.flags_res, dst_reg); \ if (writeback) \ { \ if ((fetchdat & 0xc0) == 0xc0) \ @@ -173,12 +173,12 @@ static uint32_t ropDEC_rl(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uin MEM_CHECK_WRITE_L(target_seg); \ dst_reg = MEM_LOAD_ADDR_EA_L_NO_ABRT(target_seg); \ } \ - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op, FLAGS_ ## op ## 32); \ + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op, FLAGS_ ## op ## 32); \ src_reg = LOAD_REG_L((fetchdat >> 3) & 7); \ - STORE_HOST_REG_ADDR((uint32_t)&cpu_state.flags_op1, dst_reg); \ - STORE_HOST_REG_ADDR((uint32_t)&cpu_state.flags_op2, src_reg); \ + STORE_HOST_REG_ADDR((uintptr_t)&cpu_state.flags_op1, dst_reg); \ + STORE_HOST_REG_ADDR((uintptr_t)&cpu_state.flags_op2, src_reg); \ op ## _HOST_REG_L(dst_reg, src_reg); \ - STORE_HOST_REG_ADDR((uint32_t)&cpu_state.flags_res, dst_reg); \ + STORE_HOST_REG_ADDR((uintptr_t)&cpu_state.flags_res, dst_reg); \ if (writeback) \ { \ if ((fetchdat & 0xc0) == 0xc0) \ @@ -215,11 +215,11 @@ static uint32_t ropDEC_rl(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uin } \ \ dst_reg = LOAD_REG_B((fetchdat >> 3) & 7); \ - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op, FLAGS_ ## op ## 8); \ - STORE_HOST_REG_ADDR_BL((uint32_t)&cpu_state.flags_op1, dst_reg); \ - STORE_HOST_REG_ADDR_BL((uint32_t)&cpu_state.flags_op2, src_reg); \ + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op, FLAGS_ ## op ## 8); \ + STORE_HOST_REG_ADDR_BL((uintptr_t)&cpu_state.flags_op1, dst_reg); \ + STORE_HOST_REG_ADDR_BL((uintptr_t)&cpu_state.flags_op2, src_reg); \ op ## _HOST_REG_B(dst_reg, src_reg); \ - STORE_HOST_REG_ADDR_BL((uint32_t)&cpu_state.flags_res, dst_reg); \ + STORE_HOST_REG_ADDR_BL((uintptr_t)&cpu_state.flags_res, dst_reg); \ if (writeback) STORE_REG_B_RELEASE(dst_reg); \ else RELEASE_REG(dst_reg); \ RELEASE_REG(src_reg); \ @@ -244,11 +244,11 @@ static uint32_t ropDEC_rl(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uin } \ \ dst_reg = LOAD_REG_W((fetchdat >> 3) & 7); \ - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op, FLAGS_ ## op ## 16); \ - STORE_HOST_REG_ADDR_WL((uint32_t)&cpu_state.flags_op1, dst_reg); \ - STORE_HOST_REG_ADDR_WL((uint32_t)&cpu_state.flags_op2, src_reg); \ + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op, FLAGS_ ## op ## 16); \ + STORE_HOST_REG_ADDR_WL((uintptr_t)&cpu_state.flags_op1, dst_reg); \ + STORE_HOST_REG_ADDR_WL((uintptr_t)&cpu_state.flags_op2, src_reg); \ op ## _HOST_REG_W(dst_reg, src_reg); \ - STORE_HOST_REG_ADDR_WL((uint32_t)&cpu_state.flags_res, dst_reg); \ + STORE_HOST_REG_ADDR_WL((uintptr_t)&cpu_state.flags_res, dst_reg); \ if (writeback) STORE_REG_W_RELEASE(dst_reg); \ else RELEASE_REG(dst_reg); \ RELEASE_REG(src_reg); \ @@ -273,11 +273,11 @@ static uint32_t ropDEC_rl(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uin } \ \ dst_reg = LOAD_REG_L((fetchdat >> 3) & 7); \ - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op, FLAGS_ ## op ## 32); \ - STORE_HOST_REG_ADDR((uint32_t)&cpu_state.flags_op1, dst_reg); \ - STORE_HOST_REG_ADDR((uint32_t)&cpu_state.flags_op2, src_reg); \ + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op, FLAGS_ ## op ## 32); \ + STORE_HOST_REG_ADDR((uintptr_t)&cpu_state.flags_op1, dst_reg); \ + STORE_HOST_REG_ADDR((uintptr_t)&cpu_state.flags_op2, src_reg); \ op ## _HOST_REG_L(dst_reg, src_reg); \ - STORE_HOST_REG_ADDR((uint32_t)&cpu_state.flags_res, dst_reg); \ + STORE_HOST_REG_ADDR((uintptr_t)&cpu_state.flags_res, dst_reg); \ if (writeback) STORE_REG_L_RELEASE(dst_reg); \ else RELEASE_REG(dst_reg); \ RELEASE_REG(src_reg); \ @@ -308,11 +308,11 @@ static uint32_t ropCMP_b_rm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, u } dst_reg = LOAD_REG_B((fetchdat >> 3) & 7); - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op, FLAGS_SUB8); - STORE_HOST_REG_ADDR_BL((uint32_t)&cpu_state.flags_op1, dst_reg); + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op, FLAGS_SUB8); + STORE_HOST_REG_ADDR_BL((uintptr_t)&cpu_state.flags_op1, dst_reg); dst_reg = CMP_HOST_REG_B(dst_reg, src_reg); - STORE_HOST_REG_ADDR_BL((uint32_t)&cpu_state.flags_op2, src_reg); - STORE_HOST_REG_ADDR_BL((uint32_t)&cpu_state.flags_res, dst_reg); + STORE_HOST_REG_ADDR_BL((uintptr_t)&cpu_state.flags_op2, src_reg); + STORE_HOST_REG_ADDR_BL((uintptr_t)&cpu_state.flags_res, dst_reg); RELEASE_REG(dst_reg); RELEASE_REG(src_reg); @@ -336,11 +336,11 @@ static uint32_t ropCMP_w_rm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, u } dst_reg = LOAD_REG_W((fetchdat >> 3) & 7); - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op, FLAGS_SUB16); - STORE_HOST_REG_ADDR_WL((uint32_t)&cpu_state.flags_op1, dst_reg); + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op, FLAGS_SUB16); + STORE_HOST_REG_ADDR_WL((uintptr_t)&cpu_state.flags_op1, dst_reg); dst_reg = CMP_HOST_REG_W(dst_reg, src_reg); - STORE_HOST_REG_ADDR_WL((uint32_t)&cpu_state.flags_op2, src_reg); - STORE_HOST_REG_ADDR_WL((uint32_t)&cpu_state.flags_res, dst_reg); + STORE_HOST_REG_ADDR_WL((uintptr_t)&cpu_state.flags_op2, src_reg); + STORE_HOST_REG_ADDR_WL((uintptr_t)&cpu_state.flags_res, dst_reg); RELEASE_REG(dst_reg); RELEASE_REG(src_reg); @@ -364,11 +364,11 @@ static uint32_t ropCMP_l_rm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, u } dst_reg = LOAD_REG_L((fetchdat >> 3) & 7); - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op, FLAGS_SUB32); - STORE_HOST_REG_ADDR((uint32_t)&cpu_state.flags_op1, dst_reg); + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op, FLAGS_SUB32); + STORE_HOST_REG_ADDR((uintptr_t)&cpu_state.flags_op1, dst_reg); dst_reg = CMP_HOST_REG_L(dst_reg, src_reg); - STORE_HOST_REG_ADDR((uint32_t)&cpu_state.flags_op2, src_reg); - STORE_HOST_REG_ADDR((uint32_t)&cpu_state.flags_res, dst_reg); + STORE_HOST_REG_ADDR((uintptr_t)&cpu_state.flags_op2, src_reg); + STORE_HOST_REG_ADDR((uintptr_t)&cpu_state.flags_res, dst_reg); RELEASE_REG(dst_reg); RELEASE_REG(src_reg); @@ -392,12 +392,12 @@ static uint32_t ropCMP_b_rmw(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, dst_reg = 0; } - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op, FLAGS_SUB8); + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op, FLAGS_SUB8); src_reg = LOAD_REG_B((fetchdat >> 3) & 7); - STORE_HOST_REG_ADDR_BL((uint32_t)&cpu_state.flags_op1, dst_reg); + STORE_HOST_REG_ADDR_BL((uintptr_t)&cpu_state.flags_op1, dst_reg); dst_reg = CMP_HOST_REG_B(dst_reg, src_reg); - STORE_HOST_REG_ADDR_BL((uint32_t)&cpu_state.flags_op2, src_reg); - STORE_HOST_REG_ADDR_BL((uint32_t)&cpu_state.flags_res, dst_reg); + STORE_HOST_REG_ADDR_BL((uintptr_t)&cpu_state.flags_op2, src_reg); + STORE_HOST_REG_ADDR_BL((uintptr_t)&cpu_state.flags_res, dst_reg); RELEASE_REG(dst_reg); RELEASE_REG(src_reg); @@ -420,12 +420,12 @@ static uint32_t ropCMP_w_rmw(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, dst_reg = 0; } \ - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op, FLAGS_SUB16); + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op, FLAGS_SUB16); src_reg = LOAD_REG_W((fetchdat >> 3) & 7); - STORE_HOST_REG_ADDR_WL((uint32_t)&cpu_state.flags_op1, dst_reg); + STORE_HOST_REG_ADDR_WL((uintptr_t)&cpu_state.flags_op1, dst_reg); dst_reg = CMP_HOST_REG_W(dst_reg, src_reg); - STORE_HOST_REG_ADDR_WL((uint32_t)&cpu_state.flags_op2, src_reg); - STORE_HOST_REG_ADDR_WL((uint32_t)&cpu_state.flags_res, dst_reg); + STORE_HOST_REG_ADDR_WL((uintptr_t)&cpu_state.flags_op2, src_reg); + STORE_HOST_REG_ADDR_WL((uintptr_t)&cpu_state.flags_res, dst_reg); RELEASE_REG(dst_reg); RELEASE_REG(src_reg); @@ -448,12 +448,12 @@ static uint32_t ropCMP_l_rmw(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, dst_reg = 0; } - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op, FLAGS_SUB32); + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op, FLAGS_SUB32); src_reg = LOAD_REG_L((fetchdat >> 3) & 7); - STORE_HOST_REG_ADDR((uint32_t)&cpu_state.flags_op1, dst_reg); + STORE_HOST_REG_ADDR((uintptr_t)&cpu_state.flags_op1, dst_reg); dst_reg = CMP_HOST_REG_L(dst_reg, src_reg); - STORE_HOST_REG_ADDR((uint32_t)&cpu_state.flags_op2, src_reg); - STORE_HOST_REG_ADDR((uint32_t)&cpu_state.flags_res, dst_reg); + STORE_HOST_REG_ADDR((uintptr_t)&cpu_state.flags_op2, src_reg); + STORE_HOST_REG_ADDR((uintptr_t)&cpu_state.flags_res, dst_reg); RELEASE_REG(dst_reg); RELEASE_REG(src_reg); @@ -466,11 +466,11 @@ static uint32_t ropADD_AL_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, { int host_reg = LOAD_REG_B(REG_AL); - STORE_HOST_REG_ADDR_BL((uint32_t)&cpu_state.flags_op1, host_reg); + STORE_HOST_REG_ADDR_BL((uintptr_t)&cpu_state.flags_op1, host_reg); ADD_HOST_REG_IMM_B(host_reg, fetchdat & 0xff); - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op2, fetchdat & 0xff); - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op, FLAGS_ADD8); - STORE_HOST_REG_ADDR_BL((uint32_t)&cpu_state.flags_res, host_reg); + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op2, fetchdat & 0xff); + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op, FLAGS_ADD8); + STORE_HOST_REG_ADDR_BL((uintptr_t)&cpu_state.flags_res, host_reg); STORE_REG_B_RELEASE(host_reg); codegen_flags_changed = 1; @@ -480,11 +480,11 @@ static uint32_t ropADD_AX_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, { int host_reg = LOAD_REG_W(REG_AX); - STORE_HOST_REG_ADDR_WL((uint32_t)&cpu_state.flags_op1, host_reg); + STORE_HOST_REG_ADDR_WL((uintptr_t)&cpu_state.flags_op1, host_reg); ADD_HOST_REG_IMM_W(host_reg, fetchdat & 0xffff); - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op2, fetchdat & 0xffff); - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op, FLAGS_ADD16); - STORE_HOST_REG_ADDR_WL((uint32_t)&cpu_state.flags_res, host_reg); + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op2, fetchdat & 0xffff); + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op, FLAGS_ADD16); + STORE_HOST_REG_ADDR_WL((uintptr_t)&cpu_state.flags_res, host_reg); STORE_REG_W_RELEASE(host_reg); codegen_flags_changed = 1; @@ -494,12 +494,12 @@ static uint32_t ropADD_EAX_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32 { int host_reg = LOAD_REG_L(REG_EAX); - STORE_HOST_REG_ADDR((uint32_t)&cpu_state.flags_op1, host_reg); + STORE_HOST_REG_ADDR((uintptr_t)&cpu_state.flags_op1, host_reg); fetchdat = fastreadl(cs + op_pc); ADD_HOST_REG_IMM(host_reg, fetchdat); - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op2, fetchdat); - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op, FLAGS_ADD32); - STORE_HOST_REG_ADDR((uint32_t)&cpu_state.flags_res, host_reg); + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op2, fetchdat); + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op, FLAGS_ADD32); + STORE_HOST_REG_ADDR((uintptr_t)&cpu_state.flags_res, host_reg); STORE_REG_L_RELEASE(host_reg); codegen_flags_changed = 1; @@ -510,11 +510,11 @@ static uint32_t ropCMP_AL_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, { int host_reg = LOAD_REG_B(REG_AL); - STORE_HOST_REG_ADDR_BL((uint32_t)&cpu_state.flags_op1, host_reg); + STORE_HOST_REG_ADDR_BL((uintptr_t)&cpu_state.flags_op1, host_reg); host_reg = CMP_HOST_REG_IMM_B(host_reg, fetchdat & 0xff); - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op2, fetchdat & 0xff); - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op, FLAGS_SUB8); - STORE_HOST_REG_ADDR_BL((uint32_t)&cpu_state.flags_res, host_reg); + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op2, fetchdat & 0xff); + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op, FLAGS_SUB8); + STORE_HOST_REG_ADDR_BL((uintptr_t)&cpu_state.flags_res, host_reg); RELEASE_REG(host_reg); codegen_flags_changed = 1; @@ -524,11 +524,11 @@ static uint32_t ropCMP_AX_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, { int host_reg = LOAD_REG_W(REG_AX); - STORE_HOST_REG_ADDR_WL((uint32_t)&cpu_state.flags_op1, host_reg); + STORE_HOST_REG_ADDR_WL((uintptr_t)&cpu_state.flags_op1, host_reg); host_reg = CMP_HOST_REG_IMM_W(host_reg, fetchdat & 0xffff); - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op2, fetchdat & 0xffff); - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op, FLAGS_SUB16); - STORE_HOST_REG_ADDR_WL((uint32_t)&cpu_state.flags_res, host_reg); + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op2, fetchdat & 0xffff); + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op, FLAGS_SUB16); + STORE_HOST_REG_ADDR_WL((uintptr_t)&cpu_state.flags_res, host_reg); RELEASE_REG(host_reg); codegen_flags_changed = 1; @@ -538,12 +538,12 @@ static uint32_t ropCMP_EAX_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32 { int host_reg = LOAD_REG_L(REG_EAX); - STORE_HOST_REG_ADDR((uint32_t)&cpu_state.flags_op1, host_reg); + STORE_HOST_REG_ADDR((uintptr_t)&cpu_state.flags_op1, host_reg); fetchdat = fastreadl(cs + op_pc); host_reg = CMP_HOST_REG_IMM_L(host_reg, fetchdat); - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op2, fetchdat); - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op, FLAGS_SUB32); - STORE_HOST_REG_ADDR((uint32_t)&cpu_state.flags_res, host_reg); + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op2, fetchdat); + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op, FLAGS_SUB32); + STORE_HOST_REG_ADDR((uintptr_t)&cpu_state.flags_res, host_reg); RELEASE_REG(host_reg); codegen_flags_changed = 1; @@ -554,11 +554,11 @@ static uint32_t ropSUB_AL_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, { int host_reg = LOAD_REG_B(REG_AL); - STORE_HOST_REG_ADDR_BL((uint32_t)&cpu_state.flags_op1, host_reg); + STORE_HOST_REG_ADDR_BL((uintptr_t)&cpu_state.flags_op1, host_reg); SUB_HOST_REG_IMM_B(host_reg, fetchdat & 0xff); - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op2, fetchdat & 0xff); - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op, FLAGS_SUB8); - STORE_HOST_REG_ADDR_BL((uint32_t)&cpu_state.flags_res, host_reg); + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op2, fetchdat & 0xff); + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op, FLAGS_SUB8); + STORE_HOST_REG_ADDR_BL((uintptr_t)&cpu_state.flags_res, host_reg); STORE_REG_B_RELEASE(host_reg); codegen_flags_changed = 1; @@ -568,11 +568,11 @@ static uint32_t ropSUB_AX_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, { int host_reg = LOAD_REG_W(REG_AX); - STORE_HOST_REG_ADDR_WL((uint32_t)&cpu_state.flags_op1, host_reg); + STORE_HOST_REG_ADDR_WL((uintptr_t)&cpu_state.flags_op1, host_reg); SUB_HOST_REG_IMM_W(host_reg, fetchdat & 0xffff); - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op2, fetchdat & 0xffff); - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op, FLAGS_SUB16); - STORE_HOST_REG_ADDR_WL((uint32_t)&cpu_state.flags_res, host_reg); + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op2, fetchdat & 0xffff); + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op, FLAGS_SUB16); + STORE_HOST_REG_ADDR_WL((uintptr_t)&cpu_state.flags_res, host_reg); STORE_REG_W_RELEASE(host_reg); codegen_flags_changed = 1; @@ -582,12 +582,12 @@ static uint32_t ropSUB_EAX_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32 { int host_reg = LOAD_REG_L(REG_EAX); - STORE_HOST_REG_ADDR((uint32_t)&cpu_state.flags_op1, host_reg); + STORE_HOST_REG_ADDR((uintptr_t)&cpu_state.flags_op1, host_reg); fetchdat = fastreadl(cs + op_pc); SUB_HOST_REG_IMM(host_reg, fetchdat); - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op2, fetchdat); - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op, FLAGS_SUB32); - STORE_HOST_REG_ADDR((uint32_t)&cpu_state.flags_res, host_reg); + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op2, fetchdat); + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op, FLAGS_SUB32); + STORE_HOST_REG_ADDR((uintptr_t)&cpu_state.flags_res, host_reg); STORE_REG_L_RELEASE(host_reg); codegen_flags_changed = 1; @@ -598,7 +598,7 @@ static uint32_t rop80(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_ { int host_reg; uint32_t imm; - x86seg *target_seg; + x86seg *target_seg = NULL; if ((fetchdat & 0x30) == 0x10) return 0; @@ -629,38 +629,38 @@ static uint32_t rop80(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_ switch (fetchdat & 0x38) { case 0x00: /*ADD*/ - STORE_HOST_REG_ADDR_BL((uint32_t)&cpu_state.flags_op1, host_reg); + STORE_HOST_REG_ADDR_BL((uintptr_t)&cpu_state.flags_op1, host_reg); ADD_HOST_REG_IMM_B(host_reg, imm); - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op2, imm); - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op, FLAGS_ADD8); + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op2, imm); + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op, FLAGS_ADD8); break; case 0x08: /*OR*/ OR_HOST_REG_IMM(host_reg, imm); - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op, FLAGS_ZN8); + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op, FLAGS_ZN8); break; case 0x20: /*AND*/ AND_HOST_REG_IMM(host_reg, imm | 0xffffff00); - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op, FLAGS_ZN8); + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op, FLAGS_ZN8); break; case 0x28: /*SUB*/ - STORE_HOST_REG_ADDR_BL((uint32_t)&cpu_state.flags_op1, host_reg); + STORE_HOST_REG_ADDR_BL((uintptr_t)&cpu_state.flags_op1, host_reg); SUB_HOST_REG_IMM_B(host_reg, imm); - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op2, imm); - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op, FLAGS_SUB8); + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op2, imm); + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op, FLAGS_SUB8); break; case 0x30: /*XOR*/ XOR_HOST_REG_IMM(host_reg, imm); - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op, FLAGS_ZN8); + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op, FLAGS_ZN8); break; case 0x38: /*CMP*/ - STORE_HOST_REG_ADDR_BL((uint32_t)&cpu_state.flags_op1, host_reg); + STORE_HOST_REG_ADDR_BL((uintptr_t)&cpu_state.flags_op1, host_reg); host_reg = CMP_HOST_REG_IMM_B(host_reg, imm); - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op2, imm); - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op, FLAGS_SUB8); + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op2, imm); + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op, FLAGS_SUB8); break; } - STORE_HOST_REG_ADDR_BL((uint32_t)&cpu_state.flags_res, host_reg); + STORE_HOST_REG_ADDR_BL((uintptr_t)&cpu_state.flags_res, host_reg); if ((fetchdat & 0x38) != 0x38) { if ((fetchdat & 0xc0) != 0xc0) @@ -684,7 +684,7 @@ static uint32_t rop81_w(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint3 { int host_reg; uint32_t imm; - x86seg *target_seg; + x86seg *target_seg = NULL; if ((fetchdat & 0x30) == 0x10) return 0; @@ -715,38 +715,38 @@ static uint32_t rop81_w(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint3 switch (fetchdat & 0x38) { case 0x00: /*ADD*/ - STORE_HOST_REG_ADDR_WL((uint32_t)&cpu_state.flags_op1, host_reg); + STORE_HOST_REG_ADDR_WL((uintptr_t)&cpu_state.flags_op1, host_reg); ADD_HOST_REG_IMM_W(host_reg, imm); - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op2, imm); - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op, FLAGS_ADD16); + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op2, imm); + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op, FLAGS_ADD16); break; case 0x08: /*OR*/ OR_HOST_REG_IMM(host_reg, imm); - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op, FLAGS_ZN16); + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op, FLAGS_ZN16); break; case 0x20: /*AND*/ AND_HOST_REG_IMM(host_reg, imm | 0xffff0000); - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op, FLAGS_ZN16); + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op, FLAGS_ZN16); break; case 0x28: /*SUB*/ - STORE_HOST_REG_ADDR_WL((uint32_t)&cpu_state.flags_op1, host_reg); + STORE_HOST_REG_ADDR_WL((uintptr_t)&cpu_state.flags_op1, host_reg); SUB_HOST_REG_IMM_W(host_reg, imm); - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op2, imm); - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op, FLAGS_SUB16); + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op2, imm); + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op, FLAGS_SUB16); break; case 0x30: /*XOR*/ XOR_HOST_REG_IMM(host_reg, imm); - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op, FLAGS_ZN16); + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op, FLAGS_ZN16); break; case 0x38: /*CMP*/ - STORE_HOST_REG_ADDR_WL((uint32_t)&cpu_state.flags_op1, host_reg); + STORE_HOST_REG_ADDR_WL((uintptr_t)&cpu_state.flags_op1, host_reg); host_reg = CMP_HOST_REG_IMM_W(host_reg, imm); - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op2, imm); - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op, FLAGS_SUB16); + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op2, imm); + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op, FLAGS_SUB16); break; } - STORE_HOST_REG_ADDR_WL((uint32_t)&cpu_state.flags_res, host_reg); + STORE_HOST_REG_ADDR_WL((uintptr_t)&cpu_state.flags_res, host_reg); if ((fetchdat & 0x38) != 0x38) { if ((fetchdat & 0xc0) != 0xc0) @@ -769,7 +769,7 @@ static uint32_t rop81_l(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint3 { int host_reg; uint32_t imm; - x86seg *target_seg; + x86seg *target_seg = NULL; if ((fetchdat & 0x30) == 0x10) return 0; @@ -799,38 +799,38 @@ static uint32_t rop81_l(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint3 switch (fetchdat & 0x38) { case 0x00: /*ADD*/ - STORE_HOST_REG_ADDR((uint32_t)&cpu_state.flags_op1, host_reg); + STORE_HOST_REG_ADDR((uintptr_t)&cpu_state.flags_op1, host_reg); ADD_HOST_REG_IMM(host_reg, imm); - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op2, imm); - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op, FLAGS_ADD32); + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op2, imm); + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op, FLAGS_ADD32); break; case 0x08: /*OR*/ OR_HOST_REG_IMM(host_reg, imm); - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op, FLAGS_ZN32); + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op, FLAGS_ZN32); break; case 0x20: /*AND*/ AND_HOST_REG_IMM(host_reg, imm); - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op, FLAGS_ZN32); + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op, FLAGS_ZN32); break; case 0x28: /*SUB*/ - STORE_HOST_REG_ADDR((uint32_t)&cpu_state.flags_op1, host_reg); + STORE_HOST_REG_ADDR((uintptr_t)&cpu_state.flags_op1, host_reg); SUB_HOST_REG_IMM(host_reg, imm); - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op2, imm); - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op, FLAGS_SUB32); + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op2, imm); + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op, FLAGS_SUB32); break; case 0x30: /*XOR*/ XOR_HOST_REG_IMM(host_reg, imm); - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op, FLAGS_ZN32); + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op, FLAGS_ZN32); break; case 0x38: /*CMP*/ - STORE_HOST_REG_ADDR((uint32_t)&cpu_state.flags_op1, host_reg); + STORE_HOST_REG_ADDR((uintptr_t)&cpu_state.flags_op1, host_reg); host_reg = CMP_HOST_REG_IMM_L(host_reg, imm); - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op2, imm); - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op, FLAGS_SUB32); + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op2, imm); + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op, FLAGS_SUB32); break; } - STORE_HOST_REG_ADDR((uint32_t)&cpu_state.flags_res, host_reg); + STORE_HOST_REG_ADDR((uintptr_t)&cpu_state.flags_res, host_reg); if ((fetchdat & 0x38) != 0x38) { if ((fetchdat & 0xc0) != 0xc0) @@ -854,7 +854,7 @@ static uint32_t rop83_w(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint3 { int host_reg; uint32_t imm; - x86seg *target_seg; + x86seg *target_seg = NULL; if ((fetchdat & 0x30) == 0x10) return 0; @@ -888,38 +888,38 @@ static uint32_t rop83_w(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint3 switch (fetchdat & 0x38) { case 0x00: /*ADD*/ - STORE_HOST_REG_ADDR_WL((uint32_t)&cpu_state.flags_op1, host_reg); + STORE_HOST_REG_ADDR_WL((uintptr_t)&cpu_state.flags_op1, host_reg); ADD_HOST_REG_IMM_W(host_reg, imm); - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op2, imm); - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op, FLAGS_ADD16); + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op2, imm); + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op, FLAGS_ADD16); break; case 0x08: /*OR*/ OR_HOST_REG_IMM(host_reg, imm); - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op, FLAGS_ZN16); + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op, FLAGS_ZN16); break; case 0x20: /*AND*/ AND_HOST_REG_IMM(host_reg, imm | 0xffff0000); - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op, FLAGS_ZN16); + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op, FLAGS_ZN16); break; case 0x28: /*SUB*/ - STORE_HOST_REG_ADDR_WL((uint32_t)&cpu_state.flags_op1, host_reg); + STORE_HOST_REG_ADDR_WL((uintptr_t)&cpu_state.flags_op1, host_reg); SUB_HOST_REG_IMM_W(host_reg, imm); - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op2, imm); - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op, FLAGS_SUB16); + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op2, imm); + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op, FLAGS_SUB16); break; case 0x30: /*XOR*/ XOR_HOST_REG_IMM(host_reg, imm); - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op, FLAGS_ZN16); + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op, FLAGS_ZN16); break; case 0x38: /*CMP*/ - STORE_HOST_REG_ADDR_WL((uint32_t)&cpu_state.flags_op1, host_reg); + STORE_HOST_REG_ADDR_WL((uintptr_t)&cpu_state.flags_op1, host_reg); host_reg = CMP_HOST_REG_IMM_W(host_reg, imm); - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op2, imm); - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op, FLAGS_SUB16); + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op2, imm); + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op, FLAGS_SUB16); break; } - STORE_HOST_REG_ADDR_WL((uint32_t)&cpu_state.flags_res, host_reg); + STORE_HOST_REG_ADDR_WL((uintptr_t)&cpu_state.flags_res, host_reg); if ((fetchdat & 0x38) != 0x38) { if ((fetchdat & 0xc0) != 0xc0) @@ -942,7 +942,7 @@ static uint32_t rop83_l(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint3 { int host_reg; uint32_t imm; - x86seg *target_seg; + x86seg *target_seg = NULL; if ((fetchdat & 0x30) == 0x10) return 0; @@ -976,38 +976,38 @@ static uint32_t rop83_l(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint3 switch (fetchdat & 0x38) { case 0x00: /*ADD*/ - STORE_HOST_REG_ADDR((uint32_t)&cpu_state.flags_op1, host_reg); + STORE_HOST_REG_ADDR((uintptr_t)&cpu_state.flags_op1, host_reg); ADD_HOST_REG_IMM(host_reg, imm); - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op2, imm); - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op, FLAGS_ADD32); + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op2, imm); + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op, FLAGS_ADD32); break; case 0x08: /*OR*/ OR_HOST_REG_IMM(host_reg, imm); - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op, FLAGS_ZN32); + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op, FLAGS_ZN32); break; case 0x20: /*AND*/ AND_HOST_REG_IMM(host_reg, imm); - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op, FLAGS_ZN32); + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op, FLAGS_ZN32); break; case 0x28: /*SUB*/ - STORE_HOST_REG_ADDR((uint32_t)&cpu_state.flags_op1, host_reg); + STORE_HOST_REG_ADDR((uintptr_t)&cpu_state.flags_op1, host_reg); SUB_HOST_REG_IMM(host_reg, imm); - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op2, imm); - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op, FLAGS_SUB32); + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op2, imm); + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op, FLAGS_SUB32); break; case 0x30: /*XOR*/ XOR_HOST_REG_IMM(host_reg, imm); - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op, FLAGS_ZN32); + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op, FLAGS_ZN32); break; case 0x38: /*CMP*/ - STORE_HOST_REG_ADDR((uint32_t)&cpu_state.flags_op1, host_reg); + STORE_HOST_REG_ADDR((uintptr_t)&cpu_state.flags_op1, host_reg); host_reg = CMP_HOST_REG_IMM_L(host_reg, imm); - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op2, imm); - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op, FLAGS_SUB32); + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op2, imm); + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op, FLAGS_SUB32); break; } - STORE_HOST_REG_ADDR((uint32_t)&cpu_state.flags_res, host_reg); + STORE_HOST_REG_ADDR((uintptr_t)&cpu_state.flags_res, host_reg); if ((fetchdat & 0x38) != 0x38) { if ((fetchdat & 0xc0) != 0xc0) diff --git a/src/CPU/codegen_ops_fpu.h b/src/CPU/codegen_ops_fpu.h index 7c414c3b5..7cc9499e5 100644 --- a/src/CPU/codegen_ops_fpu.h +++ b/src/CPU/codegen_ops_fpu.h @@ -200,30 +200,30 @@ static uint32_t ropF ## name ## size(uint8_t opcode, uint32_t fetchdat, uint32_t return op_pc + 1; \ } -ropFarith(ADD, s, MEM_LOAD_ADDR_EA_L, FP_OP_S) -ropFarith(DIV, s, MEM_LOAD_ADDR_EA_L, FP_OP_S) -ropFarith(DIVR, s, MEM_LOAD_ADDR_EA_L, FP_OP_S) -ropFarith(MUL, s, MEM_LOAD_ADDR_EA_L, FP_OP_S) -ropFarith(SUB, s, MEM_LOAD_ADDR_EA_L, FP_OP_S) -ropFarith(SUBR, s, MEM_LOAD_ADDR_EA_L, FP_OP_S) -ropFarith(ADD, d, MEM_LOAD_ADDR_EA_Q, FP_OP_D) -ropFarith(DIV, d, MEM_LOAD_ADDR_EA_Q, FP_OP_D) -ropFarith(DIVR, d, MEM_LOAD_ADDR_EA_Q, FP_OP_D) -ropFarith(MUL, d, MEM_LOAD_ADDR_EA_Q, FP_OP_D) -ropFarith(SUB, d, MEM_LOAD_ADDR_EA_Q, FP_OP_D) -ropFarith(SUBR, d, MEM_LOAD_ADDR_EA_Q, FP_OP_D) -ropFarith(ADD, iw, MEM_LOAD_ADDR_EA_W, FP_OP_IW) -ropFarith(DIV, iw, MEM_LOAD_ADDR_EA_W, FP_OP_IW) -ropFarith(DIVR, iw, MEM_LOAD_ADDR_EA_W, FP_OP_IW) -ropFarith(MUL, iw, MEM_LOAD_ADDR_EA_W, FP_OP_IW) -ropFarith(SUB, iw, MEM_LOAD_ADDR_EA_W, FP_OP_IW) -ropFarith(SUBR, iw, MEM_LOAD_ADDR_EA_W, FP_OP_IW) -ropFarith(ADD, il, MEM_LOAD_ADDR_EA_L, FP_OP_IL) -ropFarith(DIV, il, MEM_LOAD_ADDR_EA_L, FP_OP_IL) -ropFarith(DIVR, il, MEM_LOAD_ADDR_EA_L, FP_OP_IL) -ropFarith(MUL, il, MEM_LOAD_ADDR_EA_L, FP_OP_IL) -ropFarith(SUB, il, MEM_LOAD_ADDR_EA_L, FP_OP_IL) -ropFarith(SUBR, il, MEM_LOAD_ADDR_EA_L, FP_OP_IL) +ropFarith(ADD, s, MEM_LOAD_ADDR_EA_L, FP_OP_S); +ropFarith(DIV, s, MEM_LOAD_ADDR_EA_L, FP_OP_S); +ropFarith(DIVR, s, MEM_LOAD_ADDR_EA_L, FP_OP_S); +ropFarith(MUL, s, MEM_LOAD_ADDR_EA_L, FP_OP_S); +ropFarith(SUB, s, MEM_LOAD_ADDR_EA_L, FP_OP_S); +ropFarith(SUBR, s, MEM_LOAD_ADDR_EA_L, FP_OP_S); +ropFarith(ADD, d, MEM_LOAD_ADDR_EA_Q, FP_OP_D); +ropFarith(DIV, d, MEM_LOAD_ADDR_EA_Q, FP_OP_D); +ropFarith(DIVR, d, MEM_LOAD_ADDR_EA_Q, FP_OP_D); +ropFarith(MUL, d, MEM_LOAD_ADDR_EA_Q, FP_OP_D); +ropFarith(SUB, d, MEM_LOAD_ADDR_EA_Q, FP_OP_D); +ropFarith(SUBR, d, MEM_LOAD_ADDR_EA_Q, FP_OP_D); +ropFarith(ADD, iw, MEM_LOAD_ADDR_EA_W, FP_OP_IW); +ropFarith(DIV, iw, MEM_LOAD_ADDR_EA_W, FP_OP_IW); +ropFarith(DIVR, iw, MEM_LOAD_ADDR_EA_W, FP_OP_IW); +ropFarith(MUL, iw, MEM_LOAD_ADDR_EA_W, FP_OP_IW); +ropFarith(SUB, iw, MEM_LOAD_ADDR_EA_W, FP_OP_IW); +ropFarith(SUBR, iw, MEM_LOAD_ADDR_EA_W, FP_OP_IW); +ropFarith(ADD, il, MEM_LOAD_ADDR_EA_L, FP_OP_IL); +ropFarith(DIV, il, MEM_LOAD_ADDR_EA_L, FP_OP_IL); +ropFarith(DIVR, il, MEM_LOAD_ADDR_EA_L, FP_OP_IL); +ropFarith(MUL, il, MEM_LOAD_ADDR_EA_L, FP_OP_IL); +ropFarith(SUB, il, MEM_LOAD_ADDR_EA_L, FP_OP_IL); +ropFarith(SUBR, il, MEM_LOAD_ADDR_EA_L, FP_OP_IL); #define ropFcompare(name, size, load, op) \ static uint32_t ropF ## name ## size(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \ @@ -252,10 +252,10 @@ static uint32_t ropF ## name ## P ## size(uint8_t opcode, uint32_t fetchdat, uin return new_pc; \ } -ropFcompare(COM, s, MEM_LOAD_ADDR_EA_L, FP_COMPARE_S) -ropFcompare(COM, d, MEM_LOAD_ADDR_EA_Q, FP_COMPARE_D) -ropFcompare(COM, iw, MEM_LOAD_ADDR_EA_W, FP_COMPARE_IW) -ropFcompare(COM, il, MEM_LOAD_ADDR_EA_L, FP_COMPARE_IL) +ropFcompare(COM, s, MEM_LOAD_ADDR_EA_L, FP_COMPARE_S); +ropFcompare(COM, d, MEM_LOAD_ADDR_EA_Q, FP_COMPARE_D); +ropFcompare(COM, iw, MEM_LOAD_ADDR_EA_W, FP_COMPARE_IW); +ropFcompare(COM, il, MEM_LOAD_ADDR_EA_L, FP_COMPARE_IL); /*static uint32_t ropFADDs(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) { @@ -491,7 +491,7 @@ static uint32_t ropFSTSW_AX(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, u int host_reg; FP_ENTER(); - host_reg = LOAD_VAR_W((uintptr_t) &cpu_state.npxs); + host_reg = LOAD_VAR_W((uintptr_t)&cpu_state.npxs); STORE_REG_TARGET_W_RELEASE(host_reg, REG_AX); return op_pc; @@ -622,17 +622,19 @@ static uint32_t ropFCHS(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint3 static uint32_t ropFLD ## name(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) \ { \ static double fp_imm = v; \ + static uint64_t *fpp; \ \ FP_ENTER(); \ - FP_LOAD_IMM_Q(*(uint64_t *)&fp_imm); \ + fpp = (uint64_t *)&fp_imm; \ + FP_LOAD_IMM_Q(*fpp); \ \ return op_pc; \ } opFLDimm(1, 1.0) opFLDimm(L2T, 3.3219280948873623) -opFLDimm(L2E, 1.4426950408889634) -opFLDimm(PI, 3.141592653589793) -opFLDimm(EG2, 0.3010299956639812) -opFLDimm(LN2, 0.693147180559945) +opFLDimm(L2E, 1.4426950408889634); +opFLDimm(PI, 3.141592653589793); +opFLDimm(EG2, 0.3010299956639812); +opFLDimm(LN2, 0.693147180559945); opFLDimm(Z, 0.0) diff --git a/src/CPU/codegen_ops_jump.h b/src/CPU/codegen_ops_jump.h index 440f867ef..0ad293744 100644 --- a/src/CPU/codegen_ops_jump.h +++ b/src/CPU/codegen_ops_jump.h @@ -77,7 +77,7 @@ static uint32_t ropLOOP(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint3 static void BRANCH_COND_B(int pc_offset, uint32_t op_pc, uint32_t offset, int not) { - CALL_FUNC((void *) CF_SET); + CALL_FUNC((uintptr_t)CF_SET); if (not) TEST_ZERO_JUMP_L(0, op_pc+pc_offset+offset, timing_bt); else @@ -122,7 +122,7 @@ static void BRANCH_COND_E(int pc_offset, uint32_t op_pc, uint32_t offset, int no break; case FLAGS_UNKNOWN: - CALL_FUNC((void *) ZF_SET); + CALL_FUNC((uintptr_t)ZF_SET); if (not) TEST_ZERO_JUMP_L(0, op_pc+pc_offset+offset, timing_bt); else @@ -133,7 +133,7 @@ static void BRANCH_COND_E(int pc_offset, uint32_t op_pc, uint32_t offset, int no static void BRANCH_COND_O(int pc_offset, uint32_t op_pc, uint32_t offset, int not) { - CALL_FUNC((void *) VF_SET); + CALL_FUNC((uintptr_t)VF_SET); if (not) TEST_ZERO_JUMP_L(0, op_pc+pc_offset+offset, timing_bt); else @@ -142,7 +142,7 @@ static void BRANCH_COND_O(int pc_offset, uint32_t op_pc, uint32_t offset, int no static void BRANCH_COND_P(int pc_offset, uint32_t op_pc, uint32_t offset, int not) { - CALL_FUNC((void *) PF_SET); + CALL_FUNC((uintptr_t)PF_SET); if (not) TEST_ZERO_JUMP_L(0, op_pc+pc_offset+offset, timing_bt); else @@ -204,7 +204,7 @@ static void BRANCH_COND_S(int pc_offset, uint32_t op_pc, uint32_t offset, int no break; case FLAGS_UNKNOWN: - CALL_FUNC((void *) NF_SET); + CALL_FUNC((uintptr_t)NF_SET); if (not) TEST_ZERO_JUMP_L(0, op_pc+pc_offset+offset, timing_bt); else diff --git a/src/CPU/codegen_ops_misc.h b/src/CPU/codegen_ops_misc.h index 63ee0d6bd..e5d4f59dd 100644 --- a/src/CPU/codegen_ops_misc.h +++ b/src/CPU/codegen_ops_misc.h @@ -27,13 +27,13 @@ static uint32_t ropSTI(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32 static uint32_t ropFE(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) { - x86seg *target_seg; + x86seg *target_seg = NULL; int host_reg; if ((fetchdat & 0x30) != 0x00) return 0; - CALL_FUNC((void *) flags_rebuild_c); + CALL_FUNC((uintptr_t)flags_rebuild_c); if ((fetchdat & 0xc0) == 0xc0) host_reg = LOAD_REG_B(fetchdat & 7); @@ -50,18 +50,18 @@ static uint32_t ropFE(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_ switch (fetchdat & 0x38) { case 0x00: /*INC*/ - STORE_HOST_REG_ADDR_BL((uint32_t)&cpu_state.flags_op1, host_reg); + STORE_HOST_REG_ADDR_BL((uintptr_t)&cpu_state.flags_op1, host_reg); ADD_HOST_REG_IMM_B(host_reg, 1); - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op2, 1); - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op, FLAGS_INC8); - STORE_HOST_REG_ADDR_BL((uint32_t)&cpu_state.flags_res, host_reg); + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op2, 1); + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op, FLAGS_INC8); + STORE_HOST_REG_ADDR_BL((uintptr_t)&cpu_state.flags_res, host_reg); break; case 0x08: /*DEC*/ - STORE_HOST_REG_ADDR_BL((uint32_t)&cpu_state.flags_op1, host_reg); + STORE_HOST_REG_ADDR_BL((uintptr_t)&cpu_state.flags_op1, host_reg); SUB_HOST_REG_IMM_B(host_reg, 1); - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op2, 1); - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op, FLAGS_DEC8); - STORE_HOST_REG_ADDR_BL((uint32_t)&cpu_state.flags_res, host_reg); + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op2, 1); + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op, FLAGS_DEC8); + STORE_HOST_REG_ADDR_BL((uintptr_t)&cpu_state.flags_res, host_reg); break; } @@ -79,14 +79,14 @@ static uint32_t ropFE(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_ static uint32_t codegen_temp; static uint32_t ropFF_16(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) { - x86seg *target_seg; + x86seg *target_seg = NULL; int host_reg; if ((fetchdat & 0x30) != 0x00 && (fetchdat & 0x08)) return 0; if ((fetchdat & 0x30) == 0x00) - CALL_FUNC((void *) flags_rebuild_c); + CALL_FUNC((uintptr_t)flags_rebuild_c); if ((fetchdat & 0xc0) == 0xc0) host_reg = LOAD_REG_W(fetchdat & 7); @@ -111,11 +111,11 @@ static uint32_t ropFF_16(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint switch (fetchdat & 0x38) { case 0x00: /*INC*/ - STORE_HOST_REG_ADDR_WL((uint32_t)&cpu_state.flags_op1, host_reg); + STORE_HOST_REG_ADDR_WL((uintptr_t)&cpu_state.flags_op1, host_reg); ADD_HOST_REG_IMM_W(host_reg, 1); - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op2, 1); - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op, FLAGS_INC16); - STORE_HOST_REG_ADDR_WL((uint32_t)&cpu_state.flags_res, host_reg); + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op2, 1); + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op, FLAGS_INC16); + STORE_HOST_REG_ADDR_WL((uintptr_t)&cpu_state.flags_res, host_reg); if ((fetchdat & 0xc0) == 0xc0) STORE_REG_W_RELEASE(host_reg); else @@ -126,11 +126,11 @@ static uint32_t ropFF_16(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint codegen_flags_changed = 1; return op_pc + 1; case 0x08: /*DEC*/ - STORE_HOST_REG_ADDR_WL((uint32_t)&cpu_state.flags_op1, host_reg); + STORE_HOST_REG_ADDR_WL((uintptr_t)&cpu_state.flags_op1, host_reg); SUB_HOST_REG_IMM_W(host_reg, 1); - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op2, 1); - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op, FLAGS_DEC16); - STORE_HOST_REG_ADDR_WL((uint32_t)&cpu_state.flags_res, host_reg); + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op2, 1); + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op, FLAGS_DEC16); + STORE_HOST_REG_ADDR_WL((uintptr_t)&cpu_state.flags_res, host_reg); if ((fetchdat & 0xc0) == 0xc0) STORE_REG_W_RELEASE(host_reg); else @@ -167,21 +167,19 @@ static uint32_t ropFF_16(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint MEM_STORE_ADDR_EA_W(&_ss, host_reg); SP_MODIFY(-2); return op_pc + 1; - - default: - return -1; } + return 0; } static uint32_t ropFF_32(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) { - x86seg *target_seg; + x86seg *target_seg = NULL; int host_reg; if ((fetchdat & 0x30) != 0x00 && (fetchdat & 0x08)) return 0; if ((fetchdat & 0x30) == 0x00) - CALL_FUNC((void *) flags_rebuild_c); + CALL_FUNC((uintptr_t)flags_rebuild_c); if ((fetchdat & 0xc0) == 0xc0) host_reg = LOAD_REG_L(fetchdat & 7); @@ -206,11 +204,11 @@ static uint32_t ropFF_32(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint switch (fetchdat & 0x38) { case 0x00: /*INC*/ - STORE_HOST_REG_ADDR((uint32_t)&cpu_state.flags_op1, host_reg); + STORE_HOST_REG_ADDR((uintptr_t)&cpu_state.flags_op1, host_reg); ADD_HOST_REG_IMM(host_reg, 1); - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op2, 1); - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op, FLAGS_INC32); - STORE_HOST_REG_ADDR((uint32_t)&cpu_state.flags_res, host_reg); + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op2, 1); + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op, FLAGS_INC32); + STORE_HOST_REG_ADDR((uintptr_t)&cpu_state.flags_res, host_reg); if ((fetchdat & 0xc0) == 0xc0) STORE_REG_L_RELEASE(host_reg); else @@ -221,11 +219,11 @@ static uint32_t ropFF_32(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint codegen_flags_changed = 1; return op_pc + 1; case 0x08: /*DEC*/ - STORE_HOST_REG_ADDR((uint32_t)&cpu_state.flags_op1, host_reg); + STORE_HOST_REG_ADDR((uintptr_t)&cpu_state.flags_op1, host_reg); SUB_HOST_REG_IMM(host_reg, 1); - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op2, 1); - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op, FLAGS_DEC32); - STORE_HOST_REG_ADDR((uint32_t)&cpu_state.flags_res, host_reg); + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op2, 1); + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op, FLAGS_DEC32); + STORE_HOST_REG_ADDR((uintptr_t)&cpu_state.flags_res, host_reg); if ((fetchdat & 0xc0) == 0xc0) STORE_REG_L_RELEASE(host_reg); else @@ -262,8 +260,6 @@ static uint32_t ropFF_32(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint MEM_STORE_ADDR_EA_L(&_ss, host_reg); SP_MODIFY(-4); return op_pc + 1; - - default: - return -1; } + return 0; } diff --git a/src/CPU/codegen_ops_mmx.h b/src/CPU/codegen_ops_mmx.h index 1c425daa2..14730cb93 100644 --- a/src/CPU/codegen_ops_mmx.h +++ b/src/CPU/codegen_ops_mmx.h @@ -154,22 +154,22 @@ MMX_OP(ropPSUBSW, MMX_SUBSW) MMX_OP(ropPSUBUSB, MMX_SUBUSB) MMX_OP(ropPSUBUSW, MMX_SUBUSW) -MMX_OP(ropPUNPCKLBW, MMX_PUNPCKLBW) -MMX_OP(ropPUNPCKLWD, MMX_PUNPCKLWD) -MMX_OP(ropPUNPCKLDQ, MMX_PUNPCKLDQ) -MMX_OP(ropPACKSSWB, MMX_PACKSSWB) -MMX_OP(ropPCMPGTB, MMX_PCMPGTB) -MMX_OP(ropPCMPGTW, MMX_PCMPGTW) -MMX_OP(ropPCMPGTD, MMX_PCMPGTD) -MMX_OP(ropPACKUSWB, MMX_PACKUSWB) -MMX_OP(ropPUNPCKHBW, MMX_PUNPCKHBW) -MMX_OP(ropPUNPCKHWD, MMX_PUNPCKHWD) -MMX_OP(ropPUNPCKHDQ, MMX_PUNPCKHDQ) -MMX_OP(ropPACKSSDW, MMX_PACKSSDW) +MMX_OP(ropPUNPCKLBW, MMX_PUNPCKLBW); +MMX_OP(ropPUNPCKLWD, MMX_PUNPCKLWD); +MMX_OP(ropPUNPCKLDQ, MMX_PUNPCKLDQ); +MMX_OP(ropPACKSSWB, MMX_PACKSSWB); +MMX_OP(ropPCMPGTB, MMX_PCMPGTB); +MMX_OP(ropPCMPGTW, MMX_PCMPGTW); +MMX_OP(ropPCMPGTD, MMX_PCMPGTD); +MMX_OP(ropPACKUSWB, MMX_PACKUSWB); +MMX_OP(ropPUNPCKHBW, MMX_PUNPCKHBW); +MMX_OP(ropPUNPCKHWD, MMX_PUNPCKHWD); +MMX_OP(ropPUNPCKHDQ, MMX_PUNPCKHDQ); +MMX_OP(ropPACKSSDW, MMX_PACKSSDW); -MMX_OP(ropPCMPEQB, MMX_PCMPEQB) -MMX_OP(ropPCMPEQW, MMX_PCMPEQW) -MMX_OP(ropPCMPEQD, MMX_PCMPEQD) +MMX_OP(ropPCMPEQB, MMX_PCMPEQB); +MMX_OP(ropPCMPEQW, MMX_PCMPEQW); +MMX_OP(ropPCMPEQD, MMX_PCMPEQD); MMX_OP(ropPSRLW, MMX_PSRLW) MMX_OP(ropPSRLD, MMX_PSRLD) @@ -180,9 +180,9 @@ MMX_OP(ropPSLLW, MMX_PSLLW) MMX_OP(ropPSLLD, MMX_PSLLD) MMX_OP(ropPSLLQ, MMX_PSLLQ) -MMX_OP(ropPMULLW, MMX_PMULLW) -MMX_OP(ropPMULHW, MMX_PMULHW) -MMX_OP(ropPMADDWD, MMX_PMADDWD) +MMX_OP(ropPMULLW, MMX_PMULLW); +MMX_OP(ropPMULHW, MMX_PMULHW); +MMX_OP(ropPMADDWD, MMX_PMADDWD); static uint32_t ropPSxxW_imm(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) { diff --git a/src/CPU/codegen_ops_mov.h b/src/CPU/codegen_ops_mov.h index 4679c03f4..cb4498343 100644 --- a/src/CPU/codegen_ops_mov.h +++ b/src/CPU/codegen_ops_mov.h @@ -512,22 +512,22 @@ static uint32_t ropMOV_w_seg(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, switch (fetchdat & 0x38) { case 0x00: /*ES*/ - host_reg = LOAD_VAR_WL((uintptr_t) &ES); + host_reg = LOAD_VAR_WL((uintptr_t)&ES); break; case 0x08: /*CS*/ - host_reg = LOAD_VAR_WL((uintptr_t) &CS); + host_reg = LOAD_VAR_WL((uintptr_t)&CS); break; case 0x18: /*DS*/ - host_reg = LOAD_VAR_WL((uintptr_t) &DS); + host_reg = LOAD_VAR_WL((uintptr_t)&DS); break; case 0x10: /*SS*/ - host_reg = LOAD_VAR_WL((uintptr_t) &SS); + host_reg = LOAD_VAR_WL((uintptr_t)&SS); break; case 0x20: /*FS*/ - host_reg = LOAD_VAR_WL((uintptr_t) &FS); + host_reg = LOAD_VAR_WL((uintptr_t)&FS); break; case 0x28: /*GS*/ - host_reg = LOAD_VAR_WL((uintptr_t) &GS); + host_reg = LOAD_VAR_WL((uintptr_t)&GS); break; default: return 0; diff --git a/src/CPU/codegen_ops_shift.h b/src/CPU/codegen_ops_shift.h index 937a82ee8..b67c34544 100644 --- a/src/CPU/codegen_ops_shift.h +++ b/src/CPU/codegen_ops_shift.h @@ -13,29 +13,29 @@ reg = MEM_LOAD_ADDR_EA_ ## size ## _NO_ABRT(target_seg); \ if (immediate) count = fastreadb(cs + op_pc + 1) & 0x1f; \ } \ - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op2, count); \ + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op2, count); \ \ - res_store((uint32_t)&cpu_state.flags_op1, reg); \ + res_store((uintptr_t)&cpu_state.flags_op1, reg); \ \ switch (fetchdat & 0x38) \ { \ case 0x20: case 0x30: /*SHL*/ \ SHL_ ## size ## _IMM(reg, count); \ - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op, FLAGS_SHL ## size2); \ + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op, FLAGS_SHL ## size2); \ break; \ \ case 0x28: /*SHR*/ \ SHR_ ## size ## _IMM(reg, count); \ - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op, FLAGS_SHR ## size2); \ + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op, FLAGS_SHR ## size2); \ break; \ \ case 0x38: /*SAR*/ \ SAR_ ## size ## _IMM(reg, count); \ - STORE_IMM_ADDR_L((uint32_t)&cpu_state.flags_op, FLAGS_SAR ## size2); \ + STORE_IMM_ADDR_L((uintptr_t)&cpu_state.flags_op, FLAGS_SAR ## size2); \ break; \ } \ \ - res_store((uint32_t)&cpu_state.flags_res, reg); \ + res_store((uintptr_t)&cpu_state.flags_res, reg); \ if ((fetchdat & 0xc0) == 0xc0) \ STORE_REG_ ## size ## _RELEASE(reg); \ else \ @@ -46,7 +46,7 @@ static uint32_t ropC0(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) { - x86seg *target_seg; + x86seg *target_seg = NULL; int count; int reg; @@ -59,7 +59,7 @@ static uint32_t ropC0(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_ } static uint32_t ropC1_w(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) { - x86seg *target_seg; + x86seg *target_seg = NULL; int count; int reg; @@ -72,7 +72,7 @@ static uint32_t ropC1_w(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint3 } static uint32_t ropC1_l(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) { - x86seg *target_seg; + x86seg *target_seg = NULL; int count; int reg; @@ -86,7 +86,7 @@ static uint32_t ropC1_l(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint3 static uint32_t ropD0(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) { - x86seg *target_seg; + x86seg *target_seg = NULL; int count = 1; int reg; @@ -99,7 +99,7 @@ static uint32_t ropD0(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_ } static uint32_t ropD1_w(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) { - x86seg *target_seg; + x86seg *target_seg = NULL; int count = 1; int reg; @@ -112,7 +112,7 @@ static uint32_t ropD1_w(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint3 } static uint32_t ropD1_l(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) { - x86seg *target_seg; + x86seg *target_seg = NULL; int count = 1; int reg; diff --git a/src/CPU/codegen_ops_stack.h b/src/CPU/codegen_ops_stack.h index 9aadbaa4e..96b900273 100644 --- a/src/CPU/codegen_ops_stack.h +++ b/src/CPU/codegen_ops_stack.h @@ -85,8 +85,6 @@ static uint32_t ropPUSH_imm_b32(uint8_t opcode, uint32_t fetchdat, uint32_t op_3 static uint32_t ropPOP_16(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) { - /* int host_reg; */ - STORE_IMM_ADDR_L((uintptr_t)&cpu_state.oldpc, op_old_pc); LOAD_STACK_TO_EA(0); MEM_LOAD_ADDR_EA_W(&_ss); @@ -97,8 +95,6 @@ static uint32_t ropPOP_16(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uin } static uint32_t ropPOP_32(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) { - /* int host_reg; */ - STORE_IMM_ADDR_L((uintptr_t)&cpu_state.oldpc, op_old_pc); LOAD_STACK_TO_EA(0); MEM_LOAD_ADDR_EA_L(&_ss); @@ -110,8 +106,6 @@ static uint32_t ropPOP_32(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uin static uint32_t ropRET_16(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) { - /* int host_reg; */ - STORE_IMM_ADDR_L((uintptr_t)&cpu_state.oldpc, op_old_pc); LOAD_STACK_TO_EA(0); MEM_LOAD_ADDR_EA_W(&_ss); @@ -122,8 +116,6 @@ static uint32_t ropRET_16(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uin } static uint32_t ropRET_32(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) { - /* int host_reg; */ - STORE_IMM_ADDR_L((uintptr_t)&cpu_state.oldpc, op_old_pc); LOAD_STACK_TO_EA(0); MEM_LOAD_ADDR_EA_L(&_ss); @@ -136,7 +128,6 @@ static uint32_t ropRET_32(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uin static uint32_t ropRET_imm_16(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) { uint16_t offset = fetchdat & 0xffff; - /* int host_reg; */ STORE_IMM_ADDR_L((uintptr_t)&cpu_state.oldpc, op_old_pc); LOAD_STACK_TO_EA(0); @@ -149,7 +140,6 @@ static uint32_t ropRET_imm_16(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, static uint32_t ropRET_imm_32(uint8_t opcode, uint32_t fetchdat, uint32_t op_32, uint32_t op_pc, codeblock_t *block) { uint16_t offset = fetchdat & 0xffff; - /* int host_reg; */ STORE_IMM_ADDR_L((uintptr_t)&cpu_state.oldpc, op_old_pc); LOAD_STACK_TO_EA(0); diff --git a/src/CPU/codegen_ops_x86-64.h b/src/CPU/codegen_ops_x86-64.h index 4805be498..f6ec2f055 100644 --- a/src/CPU/codegen_ops_x86-64.h +++ b/src/CPU/codegen_ops_x86-64.h @@ -1,6 +1,7 @@ /*Register allocation : R8-R15 - emulated registers */ +#include #define HOST_REG_XMM_START 0 #define HOST_REG_XMM_END 7 @@ -20,7 +21,7 @@ static inline int find_host_xmm_reg() fatal("Out of host XMM regs!\n"); return c; } -static void call(codeblock_t *block, uintptr_t func) +static inline void call(codeblock_t *block, uintptr_t func) { uintptr_t diff = func - (uintptr_t)&block->data[block_pos + 5]; @@ -42,7 +43,7 @@ static void call(codeblock_t *block, uintptr_t func) } } -static void call_long(uintptr_t func) +static inline void call_long(uintptr_t func) { codegen_reg_loaded[0] = codegen_reg_loaded[1] = codegen_reg_loaded[2] = codegen_reg_loaded[3] = 0; codegen_reg_loaded[4] = codegen_reg_loaded[5] = codegen_reg_loaded[6] = codegen_reg_loaded[7] = 0; @@ -54,7 +55,7 @@ static void call_long(uintptr_t func) addbyte(0xd0); } -static void load_param_1_32(codeblock_t *block, uint32_t param) +static inline void load_param_1_32(codeblock_t *block, uint32_t param) { #if WIN64 addbyte(0xb9); /*MOVL $fetchdat,%ecx*/ @@ -63,7 +64,7 @@ static void load_param_1_32(codeblock_t *block, uint32_t param) #endif addlong(param); } -static void load_param_1_reg_32(int reg) +static inline void load_param_1_reg_32(int reg) { #if WIN64 if (reg & 8) @@ -77,7 +78,8 @@ static void load_param_1_reg_32(int reg) addbyte(0xc0 | REG_EDI | (reg << 3)); #endif } -static void load_param_1_64(codeblock_t *block, uint64_t param) +#if 0 +static inline void load_param_1_64(codeblock_t *block, uint64_t param) { addbyte(0x48); #if WIN64 @@ -87,8 +89,9 @@ static void load_param_1_64(codeblock_t *block, uint64_t param) #endif addquad(param); } +#endif -static void load_param_2_32(codeblock_t *block, uint32_t param) +static inline void load_param_2_32(codeblock_t *block, uint32_t param) { #if WIN64 addbyte(0xba); /*MOVL $fetchdat,%edx*/ @@ -97,7 +100,7 @@ static void load_param_2_32(codeblock_t *block, uint32_t param) #endif addlong(param); } -static void load_param_2_reg_32(int reg) +static inline void load_param_2_reg_32(int reg) { #if WIN64 if (reg & 8) @@ -111,7 +114,7 @@ static void load_param_2_reg_32(int reg) addbyte(0xc0 | REG_ESI | (reg << 3)); #endif } -static void load_param_2_64(codeblock_t *block, uint64_t param) +static inline void load_param_2_64(codeblock_t *block, uint64_t param) { addbyte(0x48); #if WIN64 @@ -122,7 +125,7 @@ static void load_param_2_64(codeblock_t *block, uint64_t param) addquad(param); } -static void load_param_3_reg_32(int reg) +static inline void load_param_3_reg_32(int reg) { if (reg & 8) { @@ -149,7 +152,7 @@ static void load_param_3_reg_32(int reg) #endif } } -static void load_param_3_reg_64(int reg) +static inline void load_param_3_reg_64(int reg) { if (reg & 8) { @@ -177,7 +180,7 @@ static void load_param_3_reg_64(int reg) } } -static void CALL_FUNC(uintptr_t func) +static inline void CALL_FUNC(uintptr_t func) { codegen_reg_loaded[0] = codegen_reg_loaded[1] = codegen_reg_loaded[2] = codegen_reg_loaded[3] = 0; codegen_reg_loaded[4] = codegen_reg_loaded[5] = codegen_reg_loaded[6] = codegen_reg_loaded[7] = 0; @@ -189,14 +192,13 @@ static void CALL_FUNC(uintptr_t func) addbyte(0xd0); } -static void RELEASE_REG(int host_reg) +static inline void RELEASE_REG(int host_reg) { } -static int LOAD_REG_B(int reg) +static inline int LOAD_REG_B(int reg) { int host_reg = reg & 3; -// host_reg_mapping[host_reg] = reg; if (!codegen_reg_loaded[reg & 3]) { @@ -213,10 +215,9 @@ static int LOAD_REG_B(int reg) return host_reg | 8; } -static int LOAD_REG_W(int reg) +static inline int LOAD_REG_W(int reg) { int host_reg = reg; -// host_reg_mapping[host_reg] = reg; if (!codegen_reg_loaded[reg & 7]) { @@ -230,10 +231,9 @@ static int LOAD_REG_W(int reg) return host_reg | 8; } -static int LOAD_REG_L(int reg) +static inline int LOAD_REG_L(int reg) { int host_reg = reg; -// host_reg_mapping[host_reg] = reg; if (!codegen_reg_loaded[reg & 7]) { @@ -248,7 +248,7 @@ static int LOAD_REG_L(int reg) return host_reg | 8; } -static int LOAD_REG_IMM(uint32_t imm) +static inline int LOAD_REG_IMM(uint32_t imm) { int host_reg = REG_EBX; @@ -258,7 +258,7 @@ static int LOAD_REG_IMM(uint32_t imm) return host_reg; } -static void STORE_REG_TARGET_B_RELEASE(int host_reg, int guest_reg) +static inline void STORE_REG_TARGET_B_RELEASE(int host_reg, int guest_reg) { int dest_reg = LOAD_REG_L(guest_reg & 3) & 7; @@ -359,7 +359,7 @@ static void STORE_REG_TARGET_B_RELEASE(int host_reg, int guest_reg) } } } -static void STORE_REG_TARGET_W_RELEASE(int host_reg, int guest_reg) +static inline void STORE_REG_TARGET_W_RELEASE(int host_reg, int guest_reg) { int dest_reg = LOAD_REG_L(guest_reg & 7) & 7; @@ -387,7 +387,7 @@ static void STORE_REG_TARGET_W_RELEASE(int host_reg, int guest_reg) addbyte(cpu_state_offset(regs[guest_reg & 7].w)); } } -static void STORE_REG_TARGET_L_RELEASE(int host_reg, int guest_reg) +static inline void STORE_REG_TARGET_L_RELEASE(int host_reg, int guest_reg) { if (host_reg & 8) { @@ -410,7 +410,7 @@ static void STORE_REG_TARGET_L_RELEASE(int host_reg, int guest_reg) } } -static void STORE_REG_B_RELEASE(int host_reg) +static inline void STORE_REG_B_RELEASE(int host_reg) { if (host_reg & 0x10) { @@ -428,7 +428,7 @@ static void STORE_REG_B_RELEASE(int host_reg) addbyte(cpu_state_offset(regs[host_reg & 7].b)); } } -static void STORE_REG_W_RELEASE(int host_reg) +static inline void STORE_REG_W_RELEASE(int host_reg) { addbyte(0x66); /*MOVW [reg],host_reg*/ addbyte(0x44); @@ -436,7 +436,7 @@ static void STORE_REG_W_RELEASE(int host_reg) addbyte(0x45 | ((host_reg & 7) << 3)); addbyte(cpu_state_offset(regs[host_reg & 7].w)); } -static void STORE_REG_L_RELEASE(int host_reg) +static inline void STORE_REG_L_RELEASE(int host_reg) { addbyte(0x44); /*MOVL [reg],host_reg*/ addbyte(0x89); @@ -444,7 +444,7 @@ static void STORE_REG_L_RELEASE(int host_reg) addbyte(cpu_state_offset(regs[host_reg & 7].l)); } -static void STORE_IMM_REG_B(int reg, uint8_t val) +static inline void STORE_IMM_REG_B(int reg, uint8_t val) { if (reg & 4) { @@ -476,7 +476,7 @@ static void STORE_IMM_REG_B(int reg, uint8_t val) addbyte(cpu_state_offset(regs[reg & 7].b)); } } -static void STORE_IMM_REG_W(int reg, uint16_t val) +static inline void STORE_IMM_REG_W(int reg, uint16_t val) { addbyte(0x66); /*MOVW reg, imm*/ addbyte(0x41); @@ -488,7 +488,7 @@ static void STORE_IMM_REG_W(int reg, uint16_t val) addbyte(0x45 | (reg << 3)); addbyte(cpu_state_offset(regs[reg & 7].w)); } -static void STORE_IMM_REG_L(int reg, uint32_t val) +static inline void STORE_IMM_REG_L(int reg, uint32_t val) { addbyte(0x41); /*MOVL reg, imm*/ addbyte(0xb8 | reg); @@ -499,7 +499,7 @@ static void STORE_IMM_REG_L(int reg, uint32_t val) addbyte(cpu_state_offset(regs[reg & 7].l)); } -static void STORE_IMM_ADDR_L(uintptr_t addr, uint32_t val) +static inline void STORE_IMM_ADDR_L(uintptr_t addr, uint32_t val) { if (addr >= (uintptr_t)&cpu_state && addr < ((uintptr_t)&cpu_state)+0x100) { @@ -533,7 +533,6 @@ static void STORE_IMM_ADDR_L(uintptr_t addr, uint32_t val) static x86seg *FETCH_EA_16(x86seg *op_ea_seg, uint32_t fetchdat, int op_ssegs, uint32_t *op_pc) { int mod = (fetchdat >> 6) & 3; - int reg = (fetchdat >> 3) & 7; int rm = fetchdat & 7; if (!mod && rm == 6) @@ -655,7 +654,6 @@ static x86seg *FETCH_EA_16(x86seg *op_ea_seg, uint32_t fetchdat, int op_ssegs, u static x86seg *FETCH_EA_32(x86seg *op_ea_seg, uint32_t fetchdat, int op_ssegs, uint32_t *op_pc, int stack_offset) { int mod = (fetchdat >> 6) & 3; - int reg = (fetchdat >> 3) & 7; int rm = fetchdat & 7; uint32_t new_eaaddr; @@ -847,7 +845,7 @@ static x86seg *FETCH_EA_32(x86seg *op_ea_seg, uint32_t fetchdat, int op_ssegs, u return op_ea_seg; } -static x86seg *FETCH_EA(x86seg *op_ea_seg, uint32_t fetchdat, int op_ssegs, uint32_t *op_pc, uint32_t op_32) +static inline x86seg *FETCH_EA(x86seg *op_ea_seg, uint32_t fetchdat, int op_ssegs, uint32_t *op_pc, uint32_t op_32) { if (op_32 & 0x200) return FETCH_EA_32(op_ea_seg, fetchdat, op_ssegs, op_pc, 0); @@ -856,7 +854,7 @@ static x86seg *FETCH_EA(x86seg *op_ea_seg, uint32_t fetchdat, int op_ssegs, uint -static void CHECK_SEG_READ(x86seg *seg) +static inline void CHECK_SEG_READ(x86seg *seg) { /*Segments always valid in real/V86 mode*/ if (!(cr0 & 1) || (eflags & VM_FLAG)) @@ -874,7 +872,7 @@ static void CHECK_SEG_READ(x86seg *seg) addbyte(0x83); /*CMP seg->base, -1*/ addbyte(0x3c); addbyte(0x25); - addlong((uint32_t)&seg->base); + addlong((uint32_t)(uintptr_t)&seg->base); addbyte(-1); } else @@ -892,7 +890,7 @@ static void CHECK_SEG_READ(x86seg *seg) seg->checked = 1; } -static void CHECK_SEG_WRITE(x86seg *seg) +static inline void CHECK_SEG_WRITE(x86seg *seg) { /*Segments always valid in real/V86 mode*/ if (!(cr0 & 1) || (eflags & VM_FLAG)) @@ -910,7 +908,7 @@ static void CHECK_SEG_WRITE(x86seg *seg) addbyte(0x83); /*CMP seg->base, -1*/ addbyte(0x3c); addbyte(0x25); - addlong((uint32_t)&seg->base); + addlong((uint32_t)(uintptr_t)&seg->base); addbyte(-1); } else @@ -928,7 +926,7 @@ static void CHECK_SEG_WRITE(x86seg *seg) seg->checked = 1; } -static void CHECK_SEG_LIMITS(x86seg *seg, int end_offset) +static inline void CHECK_SEG_LIMITS(x86seg *seg, int end_offset) { if ((seg == &_ds && codegen_flat_ds) || (seg == &_ss && codegen_flat_ss)) return; @@ -936,7 +934,7 @@ static void CHECK_SEG_LIMITS(x86seg *seg, int end_offset) if (IS_32_ADDR(&seg->base)) { addbyte(0xb8 | REG_ESI); /*MOV ESI, &addr*/ - addlong((uint32_t)seg); + addlong((uint32_t)(uintptr_t)seg); } else { @@ -967,7 +965,7 @@ static void CHECK_SEG_LIMITS(x86seg *seg, int end_offset) } } -static void MEM_LOAD_ADDR_EA_B(x86seg *seg) +static inline void MEM_LOAD_ADDR_EA_B(x86seg *seg) { if ((seg == &_ds && codegen_flat_ds) || (seg == &_ss && codegen_flat_ss)) { @@ -979,7 +977,7 @@ static void MEM_LOAD_ADDR_EA_B(x86seg *seg) addbyte(0x8b); /*MOVL ECX, seg->base*/ addbyte(0x0c); addbyte(0x25); - addlong((uint32_t)&seg->base); + addlong((uint32_t)(uintptr_t)&seg->base); } else { @@ -1005,7 +1003,7 @@ static void MEM_LOAD_ADDR_EA_B(x86seg *seg) addbyte(0x8b); addbyte(0x34); addbyte(0xf5); - addlong((uint32_t)readlookup2); + addlong((uint32_t)(uintptr_t)readlookup2); } else { @@ -1030,17 +1028,17 @@ static void MEM_LOAD_ADDR_EA_B(x86seg *seg) /*slowpath:*/ load_param_1_reg_32(REG_ECX); load_param_2_reg_32(REG_EAX); - call_long(readmemb386l); + call_long((uintptr_t)readmemb386l); addbyte(0x80); /*CMP abrt, 0*/ addbyte(0x7d); - addbyte(cpu_state_offset(abrt)); + addbyte((uint8_t)cpu_state_offset(abrt)); addbyte(0); addbyte(0x0f); /*JNE end*/ addbyte(0x85); addlong(BLOCK_EXIT_OFFSET - (block_pos + 4)); /*done:*/ } -static void MEM_LOAD_ADDR_EA_W(x86seg *seg) +static inline void MEM_LOAD_ADDR_EA_W(x86seg *seg) { if ((seg == &_ds && codegen_flat_ds) || (seg == &_ss && codegen_flat_ss)) { @@ -1052,7 +1050,7 @@ static void MEM_LOAD_ADDR_EA_W(x86seg *seg) addbyte(0x8b); /*MOVL ECX, seg->base*/ addbyte(0x0c); addbyte(0x25); - addlong((uint32_t)&seg->base); + addlong((uint32_t)(uintptr_t)&seg->base); } else { @@ -1081,7 +1079,7 @@ static void MEM_LOAD_ADDR_EA_W(x86seg *seg) addbyte(0x8b); addbyte(0x34); addbyte(0xf5); - addlong((uint32_t)readlookup2); + addlong((uint32_t)(uintptr_t)readlookup2); } else { @@ -1109,24 +1107,24 @@ static void MEM_LOAD_ADDR_EA_W(x86seg *seg) /*slowpath:*/ load_param_1_reg_32(REG_ECX); load_param_2_reg_32(REG_EAX); - call_long(readmemwl); + call_long((uintptr_t)readmemwl); addbyte(0x80); /*CMP abrt, 0*/ addbyte(0x7d); - addbyte(cpu_state_offset(abrt)); + addbyte((uint8_t)cpu_state_offset(abrt)); addbyte(0); addbyte(0x0f); /*JNE end*/ addbyte(0x85); addlong(BLOCK_EXIT_OFFSET - (block_pos + 4)); /*done:*/ } -static void MEM_LOAD_ADDR_EA_W_OFFSET(x86seg *seg, int offset) +static inline void MEM_LOAD_ADDR_EA_W_OFFSET(x86seg *seg, int offset) { addbyte(0x83); /*ADD EAX, offset*/ addbyte(0xc0); addbyte(offset); MEM_LOAD_ADDR_EA_W(seg); } -static void MEM_LOAD_ADDR_EA_L(x86seg *seg) +static inline void MEM_LOAD_ADDR_EA_L(x86seg *seg) { if ((seg == &_ds && codegen_flat_ds) || (seg == &_ss && codegen_flat_ss)) { @@ -1138,7 +1136,7 @@ static void MEM_LOAD_ADDR_EA_L(x86seg *seg) addbyte(0x8b); /*MOVL ECX, seg->base*/ addbyte(0x0c); addbyte(0x25); - addlong((uint32_t)&seg->base); + addlong((uint32_t)(uintptr_t)&seg->base); } else { @@ -1167,7 +1165,7 @@ static void MEM_LOAD_ADDR_EA_L(x86seg *seg) addbyte(0x8b); addbyte(0x34); addbyte(0xf5); - addlong((uint32_t)readlookup2); + addlong((uint32_t)(uintptr_t)readlookup2); } else { @@ -1194,17 +1192,17 @@ static void MEM_LOAD_ADDR_EA_L(x86seg *seg) /*slowpath:*/ load_param_1_reg_32(REG_ECX); load_param_2_reg_32(REG_EAX); - call_long(readmemll); + call_long((uintptr_t)readmemll); addbyte(0x80); /*CMP abrt, 0*/ addbyte(0x7d); - addbyte(cpu_state_offset(abrt)); + addbyte((uint8_t)cpu_state_offset(abrt)); addbyte(0); addbyte(0x0f); /*JNE end*/ addbyte(0x85); addlong(BLOCK_EXIT_OFFSET - (block_pos + 4)); /*done:*/ } -static void MEM_LOAD_ADDR_EA_Q(x86seg *seg) +static inline void MEM_LOAD_ADDR_EA_Q(x86seg *seg) { if ((seg == &_ds && codegen_flat_ds) || (seg == &_ss && codegen_flat_ss)) { @@ -1216,7 +1214,7 @@ static void MEM_LOAD_ADDR_EA_Q(x86seg *seg) addbyte(0x8b); /*MOVL ECX, seg->base*/ addbyte(0x0c); addbyte(0x25); - addlong((uint32_t)&seg->base); + addlong((uint32_t)(uintptr_t)&seg->base); } else { @@ -1245,7 +1243,7 @@ static void MEM_LOAD_ADDR_EA_Q(x86seg *seg) addbyte(0x8b); addbyte(0x34); addbyte(0xf5); - addlong((uint32_t)readlookup2); + addlong((uint32_t)(uintptr_t)readlookup2); } else { @@ -1273,10 +1271,10 @@ static void MEM_LOAD_ADDR_EA_Q(x86seg *seg) /*slowpath:*/ load_param_1_reg_32(REG_ECX); load_param_2_reg_32(REG_EAX); - call_long(readmemql); + call_long((uintptr_t)readmemql); addbyte(0x80); /*CMP abrt, 0*/ addbyte(0x7d); - addbyte(cpu_state_offset(abrt)); + addbyte((uint8_t)cpu_state_offset(abrt)); addbyte(0); addbyte(0x0f); /*JNE end*/ addbyte(0x85); @@ -1284,26 +1282,26 @@ static void MEM_LOAD_ADDR_EA_Q(x86seg *seg) /*done:*/ } -static void MEM_LOAD_ADDR_IMM_B(x86seg *seg, uint32_t addr) +static inline void MEM_LOAD_ADDR_IMM_B(x86seg *seg, uint32_t addr) { addbyte(0xb8); /*MOV EAX, addr*/ addlong(addr); MEM_LOAD_ADDR_EA_B(seg); } -static void MEM_LOAD_ADDR_IMM_W(x86seg *seg, uint32_t addr) +static inline void MEM_LOAD_ADDR_IMM_W(x86seg *seg, uint32_t addr) { addbyte(0xb8); /*MOV EAX, addr*/ addlong(addr); MEM_LOAD_ADDR_EA_W(seg); } -static void MEM_LOAD_ADDR_IMM_L(x86seg *seg, uint32_t addr) +static inline void MEM_LOAD_ADDR_IMM_L(x86seg *seg, uint32_t addr) { addbyte(0xb8); /*MOV EAX, addr*/ addlong(addr); MEM_LOAD_ADDR_EA_L(seg); } -static void MEM_STORE_ADDR_EA_B(x86seg *seg, int host_reg) +static inline void MEM_STORE_ADDR_EA_B(x86seg *seg, int host_reg) { if (host_reg & 0x10) { @@ -1337,7 +1335,7 @@ static void MEM_STORE_ADDR_EA_B(x86seg *seg, int host_reg) addbyte(0x8b); /*MOVL ECX, seg->base*/ addbyte(0x0c); addbyte(0x25); - addlong((uint32_t)&seg->base); + addlong((uint32_t)(uintptr_t)&seg->base); } else { @@ -1363,7 +1361,7 @@ static void MEM_STORE_ADDR_EA_B(x86seg *seg, int host_reg) addbyte(0x8b); addbyte(0x34); addbyte(0xf5); - addlong((uint32_t)writelookup2); + addlong((uint32_t)(uintptr_t)writelookup2); } else { @@ -1399,17 +1397,17 @@ static void MEM_STORE_ADDR_EA_B(x86seg *seg, int host_reg) load_param_1_reg_32(REG_ECX); load_param_2_reg_32(REG_EAX); load_param_3_reg_32(host_reg); - call_long(writememb386l); + call_long((uintptr_t)writememb386l); addbyte(0x80); /*CMP abrt, 0*/ addbyte(0x7d); - addbyte(cpu_state_offset(abrt)); + addbyte((uint8_t)cpu_state_offset(abrt)); addbyte(0); addbyte(0x0f); /*JNE end*/ addbyte(0x85); addlong(BLOCK_EXIT_OFFSET - (block_pos + 4)); /*done:*/ } -static void MEM_STORE_ADDR_EA_W(x86seg *seg, int host_reg) +static inline void MEM_STORE_ADDR_EA_W(x86seg *seg, int host_reg) { if ((seg == &_ds && codegen_flat_ds) || (seg == &_ss && codegen_flat_ss)) { @@ -1421,7 +1419,7 @@ static void MEM_STORE_ADDR_EA_W(x86seg *seg, int host_reg) addbyte(0x8b); /*MOVL ECX, seg->base*/ addbyte(0x0c); addbyte(0x25); - addlong((uint32_t)&seg->base); + addlong((uint32_t)(uintptr_t)&seg->base); } else { @@ -1450,7 +1448,7 @@ static void MEM_STORE_ADDR_EA_W(x86seg *seg, int host_reg) addbyte(0x8b); addbyte(0x34); addbyte(0xf5); - addlong((uint32_t)writelookup2); + addlong((uint32_t)(uintptr_t)writelookup2); } else { @@ -1490,17 +1488,17 @@ static void MEM_STORE_ADDR_EA_W(x86seg *seg, int host_reg) load_param_1_reg_32(REG_ECX); load_param_2_reg_32(REG_EAX); load_param_3_reg_32(host_reg); - call_long(writememwl); + call_long((uintptr_t)writememwl); addbyte(0x80); /*CMP abrt, 0*/ addbyte(0x7d); - addbyte(cpu_state_offset(abrt)); + addbyte((uint8_t)cpu_state_offset(abrt)); addbyte(0); addbyte(0x0f); /*JNE end*/ addbyte(0x85); addlong(BLOCK_EXIT_OFFSET - (block_pos + 4)); /*done:*/ } -static void MEM_STORE_ADDR_EA_L(x86seg *seg, int host_reg) +static inline void MEM_STORE_ADDR_EA_L(x86seg *seg, int host_reg) { if ((seg == &_ds && codegen_flat_ds) || (seg == &_ss && codegen_flat_ss)) { @@ -1512,7 +1510,7 @@ static void MEM_STORE_ADDR_EA_L(x86seg *seg, int host_reg) addbyte(0x8b); /*MOVL ECX, seg->base*/ addbyte(0x0c); addbyte(0x25); - addlong((uint32_t)&seg->base); + addlong((uint32_t)(uintptr_t)&seg->base); } else { @@ -1541,7 +1539,7 @@ static void MEM_STORE_ADDR_EA_L(x86seg *seg, int host_reg) addbyte(0x8b); addbyte(0x34); addbyte(0xf5); - addlong((uint32_t)writelookup2); + addlong((uint32_t)(uintptr_t)writelookup2); } else { @@ -1579,17 +1577,17 @@ static void MEM_STORE_ADDR_EA_L(x86seg *seg, int host_reg) load_param_1_reg_32(REG_ECX); load_param_2_reg_32(REG_EAX); load_param_3_reg_32(host_reg); - call_long(writememll); + call_long((uintptr_t)writememll); addbyte(0x80); /*CMP abrt, 0*/ addbyte(0x7d); - addbyte(cpu_state_offset(abrt)); + addbyte((uint8_t)cpu_state_offset(abrt)); addbyte(0); addbyte(0x0f); /*JNE end*/ addbyte(0x85); addlong(BLOCK_EXIT_OFFSET - (block_pos + 4)); /*done:*/ } -static void MEM_STORE_ADDR_EA_Q(x86seg *seg, int host_reg, int host_reg2) +static inline void MEM_STORE_ADDR_EA_Q(x86seg *seg, int host_reg, int host_reg2) { if ((seg == &_ds && codegen_flat_ds) || (seg == &_ss && codegen_flat_ss)) { @@ -1601,7 +1599,7 @@ static void MEM_STORE_ADDR_EA_Q(x86seg *seg, int host_reg, int host_reg2) addbyte(0x8b); /*MOVL ECX, seg->base*/ addbyte(0x0c); addbyte(0x25); - addlong((uint32_t)&seg->base); + addlong((uint32_t)(uintptr_t)&seg->base); } else { @@ -1630,7 +1628,7 @@ static void MEM_STORE_ADDR_EA_Q(x86seg *seg, int host_reg, int host_reg2) addbyte(0x8b); addbyte(0x34); addbyte(0xf5); - addlong((uint32_t)writelookup2); + addlong((uint32_t)(uintptr_t)writelookup2); } else { @@ -1669,10 +1667,10 @@ static void MEM_STORE_ADDR_EA_Q(x86seg *seg, int host_reg, int host_reg2) load_param_1_reg_32(REG_ECX); load_param_2_reg_32(REG_EAX); load_param_3_reg_64(host_reg); - call_long(writememql); + call_long((uintptr_t)writememql); addbyte(0x80); /*CMP abrt, 0*/ addbyte(0x7d); - addbyte(cpu_state_offset(abrt)); + addbyte((uint8_t)cpu_state_offset(abrt)); addbyte(0); addbyte(0x0f); /*JNE end*/ addbyte(0x85); @@ -1680,26 +1678,26 @@ static void MEM_STORE_ADDR_EA_Q(x86seg *seg, int host_reg, int host_reg2) /*done:*/ } -static void MEM_STORE_ADDR_IMM_B(x86seg *seg, uint32_t addr, int host_reg) +static inline void MEM_STORE_ADDR_IMM_B(x86seg *seg, uint32_t addr, int host_reg) { addbyte(0xb8); /*MOV EAX, addr*/ addlong(addr); MEM_STORE_ADDR_EA_B(seg, host_reg); } -static void MEM_STORE_ADDR_IMM_W(x86seg *seg, uint32_t addr, int host_reg) +static inline void MEM_STORE_ADDR_IMM_W(x86seg *seg, uint32_t addr, int host_reg) { addbyte(0xb8); /*MOV EAX, addr*/ addlong(addr); MEM_STORE_ADDR_EA_W(seg, host_reg); } -static void MEM_STORE_ADDR_IMM_L(x86seg *seg, uint32_t addr, int host_reg) +static inline void MEM_STORE_ADDR_IMM_L(x86seg *seg, uint32_t addr, int host_reg) { addbyte(0xb8); /*MOV EAX, addr*/ addlong(addr); MEM_STORE_ADDR_EA_L(seg, host_reg); } -static void STORE_HOST_REG_ADDR_BL(uintptr_t addr, int host_reg) +static inline void STORE_HOST_REG_ADDR_BL(uintptr_t addr, int host_reg) { int temp_reg = REG_ECX; @@ -1729,7 +1727,7 @@ static void STORE_HOST_REG_ADDR_BL(uintptr_t addr, int host_reg) { addbyte(0x89); /*MOV addr, temp_reg*/ addbyte(0x45 | (temp_reg << 3)); - addbyte((uint32_t)addr - (uint32_t)&cpu_state - 128); + addbyte((uint32_t)addr - (uint32_t)(uintptr_t)&cpu_state - 128); } else if (IS_32_ADDR(addr)) { @@ -1747,7 +1745,7 @@ static void STORE_HOST_REG_ADDR_BL(uintptr_t addr, int host_reg) addbyte(0x06 | (temp_reg << 3)); } } -static void STORE_HOST_REG_ADDR_WL(uintptr_t addr, int host_reg) +static inline void STORE_HOST_REG_ADDR_WL(uintptr_t addr, int host_reg) { int temp_reg = REG_ECX; @@ -1763,7 +1761,7 @@ static void STORE_HOST_REG_ADDR_WL(uintptr_t addr, int host_reg) { addbyte(0x89); /*MOV addr, temp_reg*/ addbyte(0x45 | (temp_reg << 3)); - addbyte((uint32_t)addr - (uint32_t)&cpu_state - 128); + addbyte((uint32_t)addr - (uint32_t)(uintptr_t)&cpu_state - 128); } else if (IS_32_ADDR(addr)) { @@ -1781,7 +1779,7 @@ static void STORE_HOST_REG_ADDR_WL(uintptr_t addr, int host_reg) addbyte(0x06 | (temp_reg << 3)); } } -static void STORE_HOST_REG_ADDR_W(uintptr_t addr, int host_reg) +static inline void STORE_HOST_REG_ADDR_W(uintptr_t addr, int host_reg) { if (addr >= (uintptr_t)&cpu_state && addr < ((uintptr_t)&cpu_state)+0x100) { @@ -1790,7 +1788,7 @@ static void STORE_HOST_REG_ADDR_W(uintptr_t addr, int host_reg) addbyte(0x44); addbyte(0x89); addbyte(0x45 | ((host_reg & 7) << 3)); - addbyte((uint32_t)addr - (uint32_t)&cpu_state - 128); + addbyte((uint32_t)addr - (uint32_t)(uintptr_t)&cpu_state - 128); } else if (IS_32_ADDR(addr)) { @@ -1815,7 +1813,7 @@ static void STORE_HOST_REG_ADDR_W(uintptr_t addr, int host_reg) addbyte(0x06 | ((host_reg & 7) << 3)); } } -static void STORE_HOST_REG_ADDR(uintptr_t addr, int host_reg) +static inline void STORE_HOST_REG_ADDR(uintptr_t addr, int host_reg) { if (addr >= (uintptr_t)&cpu_state && addr < ((uintptr_t)&cpu_state)+0x100) { @@ -1823,7 +1821,7 @@ static void STORE_HOST_REG_ADDR(uintptr_t addr, int host_reg) addbyte(0x44); addbyte(0x89); /*MOVL [addr],host_reg*/ addbyte(0x45 | ((host_reg & 7) << 3)); - addbyte((uint32_t)addr - (uint32_t)&cpu_state - 128); + addbyte((uint32_t)addr - (uint32_t)(uintptr_t)&cpu_state - 128); } else if (IS_32_ADDR(addr)) { @@ -1847,7 +1845,7 @@ static void STORE_HOST_REG_ADDR(uintptr_t addr, int host_reg) } } -static void AND_HOST_REG_B(int dst_reg, int src_reg) +static inline void AND_HOST_REG_B(int dst_reg, int src_reg) { if (dst_reg & src_reg & 8) { @@ -1970,7 +1968,7 @@ static void AND_HOST_REG_B(int dst_reg, int src_reg) } } } -static void AND_HOST_REG_W(int dst_reg, int src_reg) +static inline void AND_HOST_REG_W(int dst_reg, int src_reg) { if (dst_reg & src_reg & 8) { @@ -2000,7 +1998,7 @@ static void AND_HOST_REG_W(int dst_reg, int src_reg) addbyte(0xc0 | (dst_reg & 7) | ((src_reg & 7) << 3)); } } -static void AND_HOST_REG_L(int dst_reg, int src_reg) +static inline void AND_HOST_REG_L(int dst_reg, int src_reg) { if (dst_reg & src_reg & 8) { @@ -2026,7 +2024,7 @@ static void AND_HOST_REG_L(int dst_reg, int src_reg) addbyte(0xc0 | (dst_reg & 7) | ((src_reg & 7) << 3)); } } -static void AND_HOST_REG_IMM(int host_reg, uint32_t imm) +static inline void AND_HOST_REG_IMM(int host_reg, uint32_t imm) { if (host_reg & 0x10) { @@ -2047,7 +2045,7 @@ static void AND_HOST_REG_IMM(int host_reg, uint32_t imm) } } -static int TEST_HOST_REG_B(int dst_reg, int src_reg) +static inline int TEST_HOST_REG_B(int dst_reg, int src_reg) { if (dst_reg & 8) { @@ -2062,7 +2060,7 @@ static int TEST_HOST_REG_B(int dst_reg, int src_reg) return dst_reg & ~0x10; } -static int TEST_HOST_REG_W(int dst_reg, int src_reg) +static inline int TEST_HOST_REG_W(int dst_reg, int src_reg) { if (dst_reg & 8) { @@ -2077,7 +2075,7 @@ static int TEST_HOST_REG_W(int dst_reg, int src_reg) return dst_reg; } -static int TEST_HOST_REG_L(int dst_reg, int src_reg) +static inline int TEST_HOST_REG_L(int dst_reg, int src_reg) { if (dst_reg & 8) { @@ -2092,7 +2090,7 @@ static int TEST_HOST_REG_L(int dst_reg, int src_reg) return dst_reg; } -static int TEST_HOST_REG_IMM(int host_reg, uint32_t imm) +static inline int TEST_HOST_REG_IMM(int host_reg, uint32_t imm) { if (host_reg & 8) { @@ -2118,7 +2116,7 @@ static int TEST_HOST_REG_IMM(int host_reg, uint32_t imm) return host_reg; } -static void OR_HOST_REG_B(int dst_reg, int src_reg) +static inline void OR_HOST_REG_B(int dst_reg, int src_reg) { if (dst_reg & src_reg & 8) { @@ -2240,7 +2238,7 @@ static void OR_HOST_REG_B(int dst_reg, int src_reg) } } } -static void OR_HOST_REG_W(int dst_reg, int src_reg) +static inline void OR_HOST_REG_W(int dst_reg, int src_reg) { if (dst_reg & src_reg & 8) { @@ -2270,7 +2268,7 @@ static void OR_HOST_REG_W(int dst_reg, int src_reg) addbyte(0xc0 | (dst_reg & 7) | ((src_reg & 7) << 3)); } } -static void OR_HOST_REG_L(int dst_reg, int src_reg) +static inline void OR_HOST_REG_L(int dst_reg, int src_reg) { if (dst_reg & src_reg & 8) { @@ -2296,7 +2294,7 @@ static void OR_HOST_REG_L(int dst_reg, int src_reg) addbyte(0xc0 | (dst_reg & 7) | ((src_reg & 7) << 3)); } } -static void OR_HOST_REG_IMM(int host_reg, uint32_t imm) +static inline void OR_HOST_REG_IMM(int host_reg, uint32_t imm) { if (host_reg & 0x10) { @@ -2319,10 +2317,9 @@ static void OR_HOST_REG_IMM(int host_reg, uint32_t imm) addbyte(0xc8 | (host_reg & 7)); addlong(imm); } -// fatal("OR to bad register\n"); } -static void XOR_HOST_REG_B(int dst_reg, int src_reg) +static inline void XOR_HOST_REG_B(int dst_reg, int src_reg) { if (dst_reg & src_reg & 8) { @@ -2444,7 +2441,7 @@ static void XOR_HOST_REG_B(int dst_reg, int src_reg) } } } -static void XOR_HOST_REG_W(int dst_reg, int src_reg) +static inline void XOR_HOST_REG_W(int dst_reg, int src_reg) { if (dst_reg & src_reg & 8) { @@ -2474,7 +2471,7 @@ static void XOR_HOST_REG_W(int dst_reg, int src_reg) addbyte(0xc0 | (dst_reg & 7) | ((src_reg & 7) << 3)); } } -static void XOR_HOST_REG_L(int dst_reg, int src_reg) +static inline void XOR_HOST_REG_L(int dst_reg, int src_reg) { if (dst_reg & src_reg & 8) { @@ -2500,7 +2497,7 @@ static void XOR_HOST_REG_L(int dst_reg, int src_reg) addbyte(0xc0 | (dst_reg & 7) | ((src_reg & 7) << 3)); } } -static void XOR_HOST_REG_IMM(int host_reg, uint32_t imm) +static inline void XOR_HOST_REG_IMM(int host_reg, uint32_t imm) { if (host_reg & 0x10) { @@ -2523,10 +2520,9 @@ static void XOR_HOST_REG_IMM(int host_reg, uint32_t imm) addbyte(0xf0 | (host_reg & 7)); addlong(imm); } -// fatal("XOR to bad register\n"); } -static void ADD_HOST_REG_B(int dst_reg, int src_reg) +static inline void ADD_HOST_REG_B(int dst_reg, int src_reg) { if (dst_reg & src_reg & 8) { @@ -2620,7 +2616,7 @@ static void ADD_HOST_REG_B(int dst_reg, int src_reg) else fatal("!(dst_reg & src_reg & 8)\n"); } -static void ADD_HOST_REG_W(int dst_reg, int src_reg) +static inline void ADD_HOST_REG_W(int dst_reg, int src_reg) { if (dst_reg & src_reg & 8) { @@ -2646,7 +2642,7 @@ static void ADD_HOST_REG_W(int dst_reg, int src_reg) else fatal("!(dst_reg & src_reg & 8)\n"); } -static void ADD_HOST_REG_L(int dst_reg, int src_reg) +static inline void ADD_HOST_REG_L(int dst_reg, int src_reg) { if (dst_reg & src_reg & 8) { @@ -2670,7 +2666,7 @@ static void ADD_HOST_REG_L(int dst_reg, int src_reg) fatal("!(dst_reg & src_reg & 8)\n"); } -static void SUB_HOST_REG_B(int dst_reg, int src_reg) +static inline void SUB_HOST_REG_B(int dst_reg, int src_reg) { if (dst_reg & src_reg & 8) { @@ -2791,10 +2787,8 @@ static void SUB_HOST_REG_B(int dst_reg, int src_reg) addbyte(0xc0 | (dst_reg & 7) | ((src_reg & 7) << 3)); } } - -// fatal("!(dst_reg & src_reg & 8) subb %i %i\n", dst_reg, src_reg); } -static void SUB_HOST_REG_W(int dst_reg, int src_reg) +static inline void SUB_HOST_REG_W(int dst_reg, int src_reg) { if (dst_reg & src_reg & 8) { @@ -2824,7 +2818,7 @@ static void SUB_HOST_REG_W(int dst_reg, int src_reg) addbyte(0xc0 | (dst_reg & 7) | ((src_reg & 7) << 3)); } } -static void SUB_HOST_REG_L(int dst_reg, int src_reg) +static inline void SUB_HOST_REG_L(int dst_reg, int src_reg) { if (dst_reg & src_reg & 8) { @@ -2851,7 +2845,7 @@ static void SUB_HOST_REG_L(int dst_reg, int src_reg) } } -static int CMP_HOST_REG_B(int dst_reg, int src_reg) +static inline int CMP_HOST_REG_B(int dst_reg, int src_reg) { if (dst_reg & 8) { @@ -2866,7 +2860,7 @@ static int CMP_HOST_REG_B(int dst_reg, int src_reg) return dst_reg & ~0x10; } -static int CMP_HOST_REG_W(int dst_reg, int src_reg) +static inline int CMP_HOST_REG_W(int dst_reg, int src_reg) { if (dst_reg & 8) { @@ -2881,7 +2875,7 @@ static int CMP_HOST_REG_W(int dst_reg, int src_reg) return dst_reg; } -static int CMP_HOST_REG_L(int dst_reg, int src_reg) +static inline int CMP_HOST_REG_L(int dst_reg, int src_reg) { if (dst_reg & 8) { @@ -2897,7 +2891,7 @@ static int CMP_HOST_REG_L(int dst_reg, int src_reg) return dst_reg; } -static void ADD_HOST_REG_IMM_B(int host_reg, uint8_t imm) +static inline void ADD_HOST_REG_IMM_B(int host_reg, uint8_t imm) { if (host_reg & 0x10) { @@ -2917,7 +2911,7 @@ static void ADD_HOST_REG_IMM_B(int host_reg, uint8_t imm) addbyte(imm); } } -static void ADD_HOST_REG_IMM_W(int host_reg, uint16_t imm) +static inline void ADD_HOST_REG_IMM_W(int host_reg, uint16_t imm) { addbyte(0x66); /*ADDW host_reg, imm*/ if (host_reg & 8) @@ -2926,7 +2920,7 @@ static void ADD_HOST_REG_IMM_W(int host_reg, uint16_t imm) addbyte(0xC0 | (host_reg & 7)); addword(imm); } -static void ADD_HOST_REG_IMM(int host_reg, uint32_t imm) +static inline void ADD_HOST_REG_IMM(int host_reg, uint32_t imm) { if (host_reg & 8) addbyte(0x41); @@ -2935,7 +2929,7 @@ static void ADD_HOST_REG_IMM(int host_reg, uint32_t imm) addlong(imm); } -static void SUB_HOST_REG_IMM_B(int host_reg, uint8_t imm) +static inline void SUB_HOST_REG_IMM_B(int host_reg, uint8_t imm) { if (host_reg & 0x10) { @@ -2955,7 +2949,7 @@ static void SUB_HOST_REG_IMM_B(int host_reg, uint8_t imm) addbyte(imm); } } -static void SUB_HOST_REG_IMM_W(int host_reg, uint16_t imm) +static inline void SUB_HOST_REG_IMM_W(int host_reg, uint16_t imm) { addbyte(0x66); /*SUBW host_reg, imm*/ if (host_reg & 8) @@ -2964,7 +2958,7 @@ static void SUB_HOST_REG_IMM_W(int host_reg, uint16_t imm) addbyte(0xE8 | (host_reg & 7)); addword(imm); } -static void SUB_HOST_REG_IMM(int host_reg, uint32_t imm) +static inline void SUB_HOST_REG_IMM(int host_reg, uint32_t imm) { if (host_reg & 8) addbyte(0x41); @@ -2973,7 +2967,7 @@ static void SUB_HOST_REG_IMM(int host_reg, uint32_t imm) addlong(imm); } -static int CMP_HOST_REG_IMM_B(int host_reg, uint8_t imm) +static inline int CMP_HOST_REG_IMM_B(int host_reg, uint8_t imm) { if (host_reg & 8) { @@ -2986,9 +2980,9 @@ static int CMP_HOST_REG_IMM_B(int host_reg, uint8_t imm) SUB_HOST_REG_IMM_B(host_reg, imm); - return host_reg;// & ~0x10; + return host_reg; } -static int CMP_HOST_REG_IMM_W(int host_reg, uint16_t imm) +static inline int CMP_HOST_REG_IMM_W(int host_reg, uint16_t imm) { if (host_reg & 8) { @@ -3003,7 +2997,7 @@ static int CMP_HOST_REG_IMM_W(int host_reg, uint16_t imm) return host_reg; } -static int CMP_HOST_REG_IMM_L(int host_reg, uint32_t imm) +static inline int CMP_HOST_REG_IMM_L(int host_reg, uint32_t imm) { if (host_reg & 8) { @@ -3019,13 +3013,13 @@ static int CMP_HOST_REG_IMM_L(int host_reg, uint32_t imm) return host_reg; } -static void LOAD_STACK_TO_EA(int off) +static inline void LOAD_STACK_TO_EA(int off) { if (stack32) { addbyte(0x8b); /*MOVL EAX,[ESP]*/ addbyte(0x45 | (REG_EAX << 3)); - addbyte(cpu_state_offset(regs[REG_ESP].l)); + addbyte((uint8_t)cpu_state_offset(regs[REG_ESP].l)); if (off) { addbyte(0x83); /*ADD EAX, off*/ @@ -3038,7 +3032,7 @@ static void LOAD_STACK_TO_EA(int off) addbyte(0x0f); /*MOVZX EAX,W[ESP]*/ addbyte(0xb7); addbyte(0x45 | (REG_EAX << 3)); - addbyte(cpu_state_offset(regs[REG_ESP].w)); + addbyte((uint8_t)cpu_state_offset(regs[REG_ESP].w)); if (off) { addbyte(0x66); /*ADD AX, off*/ @@ -3047,13 +3041,13 @@ static void LOAD_STACK_TO_EA(int off) } } } -static void LOAD_EBP_TO_EA(int off) +static inline void LOAD_EBP_TO_EA(int off) { if (stack32) { addbyte(0x8b); /*MOVL EAX,[EBP]*/ addbyte(0x45 | (REG_EAX << 3)); - addbyte(cpu_state_offset(regs[REG_EBP].l)); + addbyte((uint8_t)cpu_state_offset(regs[REG_EBP].l)); if (off) { addbyte(0x83); /*ADD EAX, off*/ @@ -3066,7 +3060,7 @@ static void LOAD_EBP_TO_EA(int off) addbyte(0x0f); /*MOVZX EAX,W[EBP]*/ addbyte(0xb7); addbyte(0x45 | (REG_EAX << 3)); - addbyte(cpu_state_offset(regs[REG_BP].l)); + addbyte((uint8_t)cpu_state_offset(regs[REG_BP].l)); if (off) { addbyte(0x66); /*ADD AX, off*/ @@ -3076,7 +3070,7 @@ static void LOAD_EBP_TO_EA(int off) } } -static void SP_MODIFY(int off) +static inline void SP_MODIFY(int off) { if (stack32) { @@ -3084,14 +3078,14 @@ static void SP_MODIFY(int off) { addbyte(0x83); /*ADD [ESP], off*/ addbyte(0x45); - addbyte(cpu_state_offset(regs[REG_ESP].l)); + addbyte((uint8_t)cpu_state_offset(regs[REG_ESP].l)); addbyte(off); } else { addbyte(0x81); /*ADD [ESP], off*/ addbyte(0x45); - addbyte(cpu_state_offset(regs[REG_ESP].l)); + addbyte((uint8_t)cpu_state_offset(regs[REG_ESP].l)); addlong(off); } } @@ -3102,7 +3096,7 @@ static void SP_MODIFY(int off) addbyte(0x66); /*ADD [SP], off*/ addbyte(0x83); addbyte(0x45); - addbyte(cpu_state_offset(regs[REG_ESP].w)); + addbyte((uint8_t)cpu_state_offset(regs[REG_ESP].w)); addbyte(off); } else @@ -3110,13 +3104,13 @@ static void SP_MODIFY(int off) addbyte(0x66); /*ADD [SP], off*/ addbyte(0x81); addbyte(0x45); - addbyte(cpu_state_offset(regs[REG_ESP].w)); + addbyte((uint8_t)cpu_state_offset(regs[REG_ESP].w)); addword(off); } } } -static void TEST_ZERO_JUMP_W(int host_reg, uint32_t new_pc, int taken_cycles) +static inline void TEST_ZERO_JUMP_W(int host_reg, uint32_t new_pc, int taken_cycles) { addbyte(0x66); /*CMPW host_reg, 0*/ if (host_reg & 8) @@ -3128,19 +3122,19 @@ static void TEST_ZERO_JUMP_W(int host_reg, uint32_t new_pc, int taken_cycles) addbyte(7+5+(taken_cycles ? 4 : 0)); addbyte(0xC7); /*MOVL [pc], new_pc*/ addbyte(0x45); - addbyte(cpu_state_offset(pc)); + addbyte((uint8_t)cpu_state_offset(pc)); addlong(new_pc); if (taken_cycles) { addbyte(0x83); /*SUB $codegen_block_cycles, cyclcs*/ addbyte(0x6d); - addbyte(cpu_state_offset(_cycles)); + addbyte((uint8_t)cpu_state_offset(_cycles)); addbyte(taken_cycles); } addbyte(0xe9); /*JMP end*/ addlong(BLOCK_EXIT_OFFSET - (block_pos + 4)); } -static void TEST_ZERO_JUMP_L(int host_reg, uint32_t new_pc, int taken_cycles) +static inline void TEST_ZERO_JUMP_L(int host_reg, uint32_t new_pc, int taken_cycles) { if (host_reg & 8) addbyte(0x41); @@ -3151,20 +3145,20 @@ static void TEST_ZERO_JUMP_L(int host_reg, uint32_t new_pc, int taken_cycles) addbyte(7+5+(taken_cycles ? 4 : 0)); addbyte(0xC7); /*MOVL [pc], new_pc*/ addbyte(0x45); - addbyte(cpu_state_offset(pc)); + addbyte((uint8_t)cpu_state_offset(pc)); addlong(new_pc); if (taken_cycles) { addbyte(0x83); /*SUB $codegen_block_cycles, cyclcs*/ addbyte(0x6d); - addbyte(cpu_state_offset(_cycles)); + addbyte((uint8_t)cpu_state_offset(_cycles)); addbyte(taken_cycles); } addbyte(0xe9); /*JMP end*/ addlong(BLOCK_EXIT_OFFSET - (block_pos + 4)); } -static void TEST_NONZERO_JUMP_W(int host_reg, uint32_t new_pc, int taken_cycles) +static inline void TEST_NONZERO_JUMP_W(int host_reg, uint32_t new_pc, int taken_cycles) { addbyte(0x66); /*CMPW host_reg, 0*/ if (host_reg & 8) @@ -3176,19 +3170,19 @@ static void TEST_NONZERO_JUMP_W(int host_reg, uint32_t new_pc, int taken_cycles) addbyte(7+5+(taken_cycles ? 4 : 0)); addbyte(0xC7); /*MOVL [pc], new_pc*/ addbyte(0x45); - addbyte(cpu_state_offset(pc)); + addbyte((uint8_t)cpu_state_offset(pc)); addlong(new_pc); if (taken_cycles) { addbyte(0x83); /*SUB $codegen_block_cycles, cyclcs*/ addbyte(0x6d); - addbyte(cpu_state_offset(_cycles)); + addbyte((uint8_t)cpu_state_offset(_cycles)); addbyte(taken_cycles); } addbyte(0xe9); /*JMP end*/ addlong(BLOCK_EXIT_OFFSET - (block_pos + 4)); } -static void TEST_NONZERO_JUMP_L(int host_reg, uint32_t new_pc, int taken_cycles) +static inline void TEST_NONZERO_JUMP_L(int host_reg, uint32_t new_pc, int taken_cycles) { if (host_reg & 8) addbyte(0x41); @@ -3199,20 +3193,20 @@ static void TEST_NONZERO_JUMP_L(int host_reg, uint32_t new_pc, int taken_cycles) addbyte(7+5+(taken_cycles ? 4 : 0)); addbyte(0xC7); /*MOVL [pc], new_pc*/ addbyte(0x45); - addbyte(cpu_state_offset(pc)); + addbyte((uint8_t)cpu_state_offset(pc)); addlong(new_pc); if (taken_cycles) { addbyte(0x83); /*SUB $codegen_block_cycles, cyclcs*/ addbyte(0x6d); - addbyte(cpu_state_offset(_cycles)); + addbyte((uint8_t)cpu_state_offset(_cycles)); addbyte(taken_cycles); } addbyte(0xe9); /*JMP end*/ addlong(BLOCK_EXIT_OFFSET - (block_pos + 4)); } -static int BRANCH_COND_BE(int pc_offset, uint32_t op_pc, uint32_t offset, int not) +static inline void BRANCH_COND_BE(int pc_offset, uint32_t op_pc, uint32_t offset, int not) { uint8_t *jump1; @@ -3220,20 +3214,20 @@ static int BRANCH_COND_BE(int pc_offset, uint32_t op_pc, uint32_t offset, int no { addbyte(0x83); /*CMP flags_res, 0*/ addbyte(0x7d); - addbyte(cpu_state_offset(flags_res)); + addbyte((uint8_t)cpu_state_offset(flags_res)); addbyte(0); addbyte(0x74); /*JZ +*/ } else { - CALL_FUNC(ZF_SET); + CALL_FUNC((uintptr_t)ZF_SET); addbyte(0x85); /*TEST EAX,EAX*/ addbyte(0xc0); addbyte(0x75); /*JNZ +*/ } jump1 = &codeblock[block_current].data[block_pos]; addbyte(0); - CALL_FUNC(CF_SET); + CALL_FUNC((uintptr_t)CF_SET); addbyte(0x85); /*TEST EAX,EAX*/ addbyte(0xc0); if (not) @@ -3246,13 +3240,13 @@ static int BRANCH_COND_BE(int pc_offset, uint32_t op_pc, uint32_t offset, int no *jump1 = (uintptr_t)&codeblock[block_current].data[block_pos] - (uintptr_t)jump1 - 1; addbyte(0xC7); /*MOVL [pc], new_pc*/ addbyte(0x45); - addbyte(cpu_state_offset(pc)); + addbyte((uint8_t)cpu_state_offset(pc)); addlong(op_pc+pc_offset+offset); if (timing_bt) { addbyte(0x83); /*SUB $codegen_block_cycles, cyclcs*/ addbyte(0x6d); - addbyte(cpu_state_offset(_cycles)); + addbyte((uint8_t)cpu_state_offset(_cycles)); addbyte(timing_bt); } addbyte(0xe9); /*JMP end*/ @@ -3261,15 +3255,15 @@ static int BRANCH_COND_BE(int pc_offset, uint32_t op_pc, uint32_t offset, int no *jump1 = (uintptr_t)&codeblock[block_current].data[block_pos] - (uintptr_t)jump1 - 1; } -static int BRANCH_COND_L(int pc_offset, uint32_t op_pc, uint32_t offset, int not) +static inline void BRANCH_COND_L(int pc_offset, uint32_t op_pc, uint32_t offset, int not) { - CALL_FUNC(NF_SET); + CALL_FUNC((uintptr_t)NF_SET); addbyte(0x85); /*TEST EAX,EAX*/ addbyte(0xc0); addbyte(0x0f); /*SETNE BL*/ addbyte(0x95); addbyte(0xc3); - CALL_FUNC(VF_SET); + CALL_FUNC((uintptr_t)VF_SET); addbyte(0x85); /*TEST EAX,EAX*/ addbyte(0xc0); addbyte(0x0f); /*SETNE AL*/ @@ -3284,46 +3278,46 @@ static int BRANCH_COND_L(int pc_offset, uint32_t op_pc, uint32_t offset, int not addbyte(7+5+(timing_bt ? 4 : 0)); addbyte(0xC7); /*MOVL [pc], new_pc*/ addbyte(0x45); - addbyte(cpu_state_offset(pc)); + addbyte((uint8_t)cpu_state_offset(pc)); addlong(op_pc+pc_offset+offset); if (timing_bt) { addbyte(0x83); /*SUB $codegen_block_cycles, cyclcs*/ addbyte(0x6d); - addbyte(cpu_state_offset(_cycles)); + addbyte((uint8_t)cpu_state_offset(_cycles)); addbyte(timing_bt); } addbyte(0xe9); /*JMP end*/ addlong(BLOCK_EXIT_OFFSET - (block_pos + 4)); } -static int BRANCH_COND_LE(int pc_offset, uint32_t op_pc, uint32_t offset, int not) +static inline void BRANCH_COND_LE(int pc_offset, uint32_t op_pc, uint32_t offset, int not) { uint8_t *jump1; if (codegen_flags_changed && cpu_state.flags_op != FLAGS_UNKNOWN) { addbyte(0x83); /*CMP flags_res, 0*/ addbyte(0x7d); - addbyte(cpu_state_offset(flags_res)); + addbyte((uint8_t)cpu_state_offset(flags_res)); addbyte(0); addbyte(0x74); /*JZ +*/ } else { - CALL_FUNC(ZF_SET); + CALL_FUNC((uintptr_t)ZF_SET); addbyte(0x85); /*TEST EAX,EAX*/ addbyte(0xc0); addbyte(0x75); /*JNZ +*/ } jump1 = &codeblock[block_current].data[block_pos]; addbyte(0); - CALL_FUNC(NF_SET); + CALL_FUNC((uintptr_t)NF_SET); addbyte(0x85); /*TEST EAX,EAX*/ addbyte(0xc0); addbyte(0x0f); /*SETNE BL*/ addbyte(0x95); addbyte(0xc3); - CALL_FUNC(VF_SET); + CALL_FUNC((uintptr_t)VF_SET); addbyte(0x85); /*TEST EAX,EAX*/ addbyte(0xc0); addbyte(0x0f); /*SETNE AL*/ @@ -3340,13 +3334,13 @@ static int BRANCH_COND_LE(int pc_offset, uint32_t op_pc, uint32_t offset, int no *jump1 = (uintptr_t)&codeblock[block_current].data[block_pos] - (uintptr_t)jump1 - 1; addbyte(0xC7); /*MOVL [pc], new_pc*/ addbyte(0x45); - addbyte(cpu_state_offset(pc)); + addbyte((uint8_t)cpu_state_offset(pc)); addlong(op_pc+pc_offset+offset); if (timing_bt) { addbyte(0x83); /*SUB $codegen_block_cycles, cyclcs*/ addbyte(0x6d); - addbyte(cpu_state_offset(_cycles)); + addbyte((uint8_t)cpu_state_offset(_cycles)); addbyte(timing_bt); } addbyte(0xe9); /*JMP end*/ @@ -3355,7 +3349,7 @@ static int BRANCH_COND_LE(int pc_offset, uint32_t op_pc, uint32_t offset, int no *jump1 = (uintptr_t)&codeblock[block_current].data[block_pos] - (uintptr_t)jump1 - 1; } -static int LOAD_VAR_W(uintptr_t addr) +static inline int LOAD_VAR_W(uintptr_t addr) { int host_reg = REG_EBX; @@ -3386,11 +3380,11 @@ static int LOAD_VAR_W(uintptr_t addr) return host_reg; } -static int LOAD_VAR_WL(uintptr_t addr) +static inline int LOAD_VAR_WL(uintptr_t addr) { return LOAD_VAR_W(addr); } -static int LOAD_VAR_L(uintptr_t addr) +static inline int LOAD_VAR_L(uintptr_t addr) { int host_reg = REG_EBX; @@ -3419,7 +3413,7 @@ static int LOAD_VAR_L(uintptr_t addr) return host_reg; } -static int COPY_REG(int src_reg) +static inline int COPY_REG(int src_reg) { if (src_reg & 8) addbyte(0x44); @@ -3429,7 +3423,7 @@ static int COPY_REG(int src_reg) return REG_ECX | (src_reg & 0x10); } -static int LOAD_HOST_REG(int host_reg) +static inline int LOAD_HOST_REG(int host_reg) { if (host_reg & 8) addbyte(0x44); @@ -3439,7 +3433,7 @@ static int LOAD_HOST_REG(int host_reg) return REG_EBX | (host_reg & 0x10); } -static int ZERO_EXTEND_W_B(int reg) +static inline int ZERO_EXTEND_W_B(int reg) { if (reg & 0x10) { @@ -3461,7 +3455,7 @@ static int ZERO_EXTEND_W_B(int reg) return REG_EAX; } -static int ZERO_EXTEND_L_B(int reg) +static inline int ZERO_EXTEND_L_B(int reg) { if (reg & 0x10) { @@ -3483,7 +3477,7 @@ static int ZERO_EXTEND_L_B(int reg) return REG_EAX; } -static int ZERO_EXTEND_L_W(int reg) +static inline int ZERO_EXTEND_L_W(int reg) { if (reg & 8) addbyte(0x41); @@ -3494,7 +3488,7 @@ static int ZERO_EXTEND_L_W(int reg) return REG_EAX; } -static int SIGN_EXTEND_W_B(int reg) +static inline int SIGN_EXTEND_W_B(int reg) { if (reg & 0x10) { @@ -3516,7 +3510,7 @@ static int SIGN_EXTEND_W_B(int reg) return REG_EAX; } -static int SIGN_EXTEND_L_B(int reg) +static inline int SIGN_EXTEND_L_B(int reg) { if (reg & 0x10) { @@ -3538,7 +3532,7 @@ static int SIGN_EXTEND_L_B(int reg) return REG_EAX; } -static int SIGN_EXTEND_L_W(int reg) +static inline int SIGN_EXTEND_L_W(int reg) { if (reg & 8) addbyte(0x41); @@ -3549,7 +3543,7 @@ static int SIGN_EXTEND_L_W(int reg) return REG_EAX; } -static void SHL_B_IMM(int reg, int count) +static inline void SHL_B_IMM(int reg, int count) { if (reg & 0x10) { @@ -3572,7 +3566,7 @@ static void SHL_B_IMM(int reg, int count) addbyte(count); } } -static void SHL_W_IMM(int reg, int count) +static inline void SHL_W_IMM(int reg, int count) { addbyte(0x66); /*SHL reg, count*/ if (reg & 8) @@ -3581,7 +3575,7 @@ static void SHL_W_IMM(int reg, int count) addbyte(0xc0 | (reg & 7) | 0x20); addbyte(count); } -static void SHL_L_IMM(int reg, int count) +static inline void SHL_L_IMM(int reg, int count) { if (reg & 8) addbyte(0x41); @@ -3589,7 +3583,7 @@ static void SHL_L_IMM(int reg, int count) addbyte(0xc0 | (reg & 7) | 0x20); addbyte(count); } -static void SHR_B_IMM(int reg, int count) +static inline void SHR_B_IMM(int reg, int count) { if (reg & 0x10) { @@ -3612,7 +3606,7 @@ static void SHR_B_IMM(int reg, int count) addbyte(count); } } -static void SHR_W_IMM(int reg, int count) +static inline void SHR_W_IMM(int reg, int count) { addbyte(0x66); /*SHR reg, count*/ if (reg & 8) @@ -3621,7 +3615,7 @@ static void SHR_W_IMM(int reg, int count) addbyte(0xc0 | (reg & 7) | 0x28); addbyte(count); } -static void SHR_L_IMM(int reg, int count) +static inline void SHR_L_IMM(int reg, int count) { if (reg & 8) addbyte(0x41); @@ -3629,7 +3623,7 @@ static void SHR_L_IMM(int reg, int count) addbyte(0xc0 | (reg & 7) | 0x28); addbyte(count); } -static void SAR_B_IMM(int reg, int count) +static inline void SAR_B_IMM(int reg, int count) { if (reg & 0x10) { @@ -3652,7 +3646,7 @@ static void SAR_B_IMM(int reg, int count) addbyte(count); } } -static void SAR_W_IMM(int reg, int count) +static inline void SAR_W_IMM(int reg, int count) { addbyte(0x66); /*SAR reg, count*/ if (reg & 8) @@ -3661,7 +3655,7 @@ static void SAR_W_IMM(int reg, int count) addbyte(0xc0 | (reg & 7) | 0x38); addbyte(count); } -static void SAR_L_IMM(int reg, int count) +static inline void SAR_L_IMM(int reg, int count) { if (reg & 8) addbyte(0x41); @@ -3670,7 +3664,7 @@ static void SAR_L_IMM(int reg, int count) addbyte(count); } -static void NEG_HOST_REG_B(int reg) +static inline void NEG_HOST_REG_B(int reg) { if (reg & 0x10) { @@ -3693,7 +3687,7 @@ static void NEG_HOST_REG_B(int reg) addbyte(0xd8 | (reg & 7)); } } -static void NEG_HOST_REG_W(int reg) +static inline void NEG_HOST_REG_W(int reg) { addbyte(0x66); if (reg & 8) @@ -3701,7 +3695,7 @@ static void NEG_HOST_REG_W(int reg) addbyte(0xf7); addbyte(0xd8 | (reg & 7)); } -static void NEG_HOST_REG_L(int reg) +static inline void NEG_HOST_REG_L(int reg) { if (reg & 8) addbyte(0x41); @@ -3710,7 +3704,7 @@ static void NEG_HOST_REG_L(int reg) } -static void FP_ENTER() +static inline void FP_ENTER() { if (codegen_fpu_entered) return; @@ -3726,7 +3720,7 @@ static void FP_ENTER() { addbyte(0x48); /*MOV RAX, &cr0*/ addbyte(0xb8 | REG_EAX); - addquad(&cr0); + addquad((uint64_t)&cr0); addbyte(0xf6); /*TEST [RAX], 0xc*/ addbyte(0 | (REG_EAX << 3)); addbyte(0x0c); @@ -3735,21 +3729,21 @@ static void FP_ENTER() addbyte(7+5+12+5); addbyte(0xC7); /*MOVL [oldpc],op_old_pc*/ addbyte(0x45); - addbyte(cpu_state_offset(oldpc)); + addbyte((uint8_t)cpu_state_offset(oldpc)); addlong(op_old_pc); load_param_1_32(&codeblock[block_current], 7); - CALL_FUNC(x86_int); + CALL_FUNC((uintptr_t)x86_int); addbyte(0xe9); /*JMP end*/ addlong(BLOCK_EXIT_OFFSET - (block_pos + 4)); codegen_fpu_entered = 1; } -static void FP_FXCH(int reg) +static inline void FP_FXCH(int reg) { addbyte(0x8b); /*MOV EAX, [TOP]*/ addbyte(0x45); - addbyte(cpu_state_offset(TOP)); + addbyte((uint8_t)cpu_state_offset(TOP)); addbyte(0x89); /*MOV EBX, EAX*/ addbyte(0xc3); addbyte(0x83); /*ADD EAX, reg*/ @@ -3760,7 +3754,7 @@ static void FP_FXCH(int reg) addbyte(0x8b); addbyte(0x54); addbyte(0xdd); - addbyte(cpu_state_offset(ST)); + addbyte((uint8_t)cpu_state_offset(ST)); addbyte(0x83); /*AND EAX, 7*/ addbyte(0xe0); addbyte(0x07); @@ -3768,65 +3762,65 @@ static void FP_FXCH(int reg) addbyte(0x8b); addbyte(0x4c); addbyte(0xc5); - addbyte(cpu_state_offset(ST)); + addbyte((uint8_t)cpu_state_offset(ST)); addbyte(0x48); /*MOV ST[RAX*8], RDX*/ addbyte(0x89); addbyte(0x54); addbyte(0xc5); - addbyte(cpu_state_offset(ST)); + addbyte((uint8_t)cpu_state_offset(ST)); addbyte(0x48); /*MOV ST[RBX*8], RCX*/ addbyte(0x89); addbyte(0x4c); addbyte(0xdd); - addbyte(cpu_state_offset(ST)); + addbyte((uint8_t)cpu_state_offset(ST)); addbyte(0x8a); /*MOV CL, tag[EAX]*/ addbyte(0x4c); addbyte(0x05); - addbyte(cpu_state_offset(tag)); + addbyte((uint8_t)cpu_state_offset(tag)); addbyte(0x8a); /*MOV DL, tag[EBX]*/ addbyte(0x54); addbyte(0x1d); - addbyte(cpu_state_offset(tag)); + addbyte((uint8_t)cpu_state_offset(tag)); addbyte(0x88); /*MOV tag[EBX], CL*/ addbyte(0x4c); addbyte(0x1d); - addbyte(cpu_state_offset(tag)); + addbyte((uint8_t)cpu_state_offset(tag)); addbyte(0x88); /*MOV tag[EAX], DL*/ addbyte(0x54); addbyte(0x05); - addbyte(cpu_state_offset(tag)); + addbyte((uint8_t)cpu_state_offset(tag)); addbyte(0x48); /*MOV RDX, MM[RBX*8]*/ addbyte(0x8b); addbyte(0x54); addbyte(0xdd); - addbyte(cpu_state_offset(MM)); + addbyte((uint8_t)cpu_state_offset(MM)); addbyte(0x48); /*MOV RCX, MM[RAX*8]*/ addbyte(0x8b); addbyte(0x4c); addbyte(0xc5); - addbyte(cpu_state_offset(MM)); + addbyte((uint8_t)cpu_state_offset(MM)); addbyte(0x48); /*MOV MM[RAX*8], RDX*/ addbyte(0x89); addbyte(0x54); addbyte(0xc5); - addbyte(cpu_state_offset(MM)); + addbyte((uint8_t)cpu_state_offset(MM)); addbyte(0x48); /*MOV MM[RBX*8], RCX*/ addbyte(0x89); addbyte(0x4c); addbyte(0xdd); - addbyte(cpu_state_offset(MM)); + addbyte((uint8_t)cpu_state_offset(MM)); reg = reg; } -static void FP_FLD(int reg) +static inline void FP_FLD(int reg) { addbyte(0x8b); /*MOV EAX, [TOP]*/ addbyte(0x45); - addbyte(cpu_state_offset(TOP)); + addbyte((uint8_t)cpu_state_offset(TOP)); addbyte(0x89); /*MOV EBX, EAX*/ addbyte(0xc3); if (reg) @@ -3852,7 +3846,7 @@ static void FP_FLD(int reg) addbyte(0x8b); addbyte(0x4c); addbyte(0xc5); - addbyte(cpu_state_offset(ST)); + addbyte((uint8_t)cpu_state_offset(ST)); addbyte(0x83); /*AND EBX, 7*/ addbyte(0xe3); addbyte(0x07); @@ -3860,45 +3854,45 @@ static void FP_FLD(int reg) addbyte(0x8b); addbyte(0x54); addbyte(0xc5); - addbyte(cpu_state_offset(MM)); + addbyte((uint8_t)cpu_state_offset(MM)); addbyte(0x8a); /*MOV AL, [tag+EAX]*/ addbyte(0x44); addbyte(0x05); - addbyte(cpu_state_offset(tag)); + addbyte((uint8_t)cpu_state_offset(tag)); addbyte(0x48); /*MOV ST[EBX*8], RCX*/ addbyte(0x89); addbyte(0x4c); addbyte(0xdd); - addbyte(cpu_state_offset(ST)); + addbyte((uint8_t)cpu_state_offset(ST)); addbyte(0x48); /*MOV ST_i64[EBX*8], RDX*/ addbyte(0x89); addbyte(0x54); addbyte(0xdd); - addbyte(cpu_state_offset(MM)); + addbyte((uint8_t)cpu_state_offset(MM)); addbyte(0x88); /*MOV [tag+EBX], AL*/ addbyte(0x44); addbyte(0x1d); - addbyte(cpu_state_offset(tag)); + addbyte((uint8_t)cpu_state_offset(tag)); addbyte(0x89); /*MOV [TOP], EBX*/ addbyte(0x5d); - addbyte(cpu_state_offset(TOP)); + addbyte((uint8_t)cpu_state_offset(TOP)); } -static void FP_FST(int reg) +static inline void FP_FST(int reg) { addbyte(0x8b); /*MOV EAX, [TOP]*/ addbyte(0x45); - addbyte(cpu_state_offset(TOP)); + addbyte((uint8_t)cpu_state_offset(TOP)); addbyte(0x48); /*MOV RCX, ST[EAX*8]*/ addbyte(0x8b); addbyte(0x4c); addbyte(0xc5); - addbyte(cpu_state_offset(ST)); + addbyte((uint8_t)cpu_state_offset(ST)); addbyte(0x8a); /*MOV BL, [tag+EAX]*/ addbyte(0x5c); addbyte(0x05); - addbyte(cpu_state_offset(tag)); + addbyte((uint8_t)cpu_state_offset(tag)); if (reg) { @@ -3914,22 +3908,22 @@ static void FP_FST(int reg) addbyte(0x89); addbyte(0x4c); addbyte(0xc5); - addbyte(cpu_state_offset(ST)); + addbyte((uint8_t)cpu_state_offset(ST)); addbyte(0x88); /*MOV [tag+EAX], BL*/ addbyte(0x5c); addbyte(0x05); - addbyte(cpu_state_offset(tag)); + addbyte((uint8_t)cpu_state_offset(tag)); } -static void FP_POP() +static inline void FP_POP() { addbyte(0x8b); /*MOV EAX, [TOP]*/ addbyte(0x45); - addbyte(cpu_state_offset(TOP)); + addbyte((uint8_t)cpu_state_offset(TOP)); addbyte(0xc6); /*MOVB tag[EAX], 3*/ addbyte(0x44); addbyte(0x05); - addbyte(cpu_state_offset(tag)); + addbyte((uint8_t)cpu_state_offset(tag)); addbyte(3); addbyte(0x83); /*ADD AL, 1*/ addbyte(0xc0); @@ -3939,17 +3933,17 @@ static void FP_POP() addbyte(7); addbyte(0x89); /*MOV [TOP], EAX*/ addbyte(0x45); - addbyte(cpu_state_offset(TOP)); + addbyte((uint8_t)cpu_state_offset(TOP)); } -static void FP_POP2() +static inline void FP_POP2() { addbyte(0x8b); /*MOV EAX, [TOP]*/ addbyte(0x45); - addbyte(cpu_state_offset(TOP)); + addbyte((uint8_t)cpu_state_offset(TOP)); addbyte(0xc6); /*MOVB tag[EAX], 3*/ addbyte(0x44); addbyte(0x05); - addbyte(cpu_state_offset(tag)); + addbyte((uint8_t)cpu_state_offset(tag)); addbyte(3); addbyte(0x83); /*ADD AL, 2*/ addbyte(0xc0); @@ -3959,14 +3953,14 @@ static void FP_POP2() addbyte(7); addbyte(0x89); /*MOV [TOP], EAX*/ addbyte(0x45); - addbyte(cpu_state_offset(TOP)); + addbyte((uint8_t)cpu_state_offset(TOP)); } -static void FP_LOAD_S() +static inline void FP_LOAD_S() { addbyte(0x8b); /*MOV EBX, TOP*/ addbyte(0x5d); - addbyte(cpu_state_offset(TOP)); + addbyte((uint8_t)cpu_state_offset(TOP)); addbyte(0x66); /*MOVD XMM0, EAX*/ addbyte(0x0f); addbyte(0x6e); @@ -3985,24 +3979,24 @@ static void FP_LOAD_S() addbyte(0xc0); addbyte(0x89); /*MOV TOP, EBX*/ addbyte(0x5d); - addbyte(cpu_state_offset(TOP)); + addbyte((uint8_t)cpu_state_offset(TOP)); addbyte(0x66); /*MOVQ [ST+EBX*8], XMM0*/ addbyte(0x0f); addbyte(0xd6); addbyte(0x44); addbyte(0xdd); - addbyte(cpu_state_offset(ST)); + addbyte((uint8_t)cpu_state_offset(ST)); addbyte(0x0f); /*SETE [tag+EBX]*/ addbyte(0x94); addbyte(0x44); addbyte(0x1d); - addbyte(cpu_state_offset(tag)); + addbyte((uint8_t)cpu_state_offset(tag)); } -static void FP_LOAD_D() +static inline void FP_LOAD_D() { addbyte(0x8b); /*MOV EBX, TOP*/ addbyte(0x5d); - addbyte(cpu_state_offset(TOP)); + addbyte((uint8_t)cpu_state_offset(TOP)); addbyte(0x83); /*SUB EBX, 1*/ addbyte(0xeb); addbyte(0x01); @@ -4014,24 +4008,24 @@ static void FP_LOAD_D() addbyte(0xc0); addbyte(0x89); /*MOV TOP, EBX*/ addbyte(0x5d); - addbyte(cpu_state_offset(TOP)); + addbyte((uint8_t)cpu_state_offset(TOP)); addbyte(0x48); /*MOVQ [ST+EBX*8], RAX*/ addbyte(0x89); addbyte(0x44); addbyte(0xdd); - addbyte(cpu_state_offset(ST)); + addbyte((uint8_t)cpu_state_offset(ST)); addbyte(0x0f); /*SETE [tag+EBX]*/ addbyte(0x94); addbyte(0x44); addbyte(0x1d); - addbyte(cpu_state_offset(tag)); + addbyte((uint8_t)cpu_state_offset(tag)); } -static void FP_LOAD_IW() +static inline void FP_LOAD_IW() { addbyte(0x8b); /*MOV EBX, TOP*/ addbyte(0x5d); - addbyte(cpu_state_offset(TOP)); + addbyte((uint8_t)cpu_state_offset(TOP)); addbyte(0x0f); /*MOVSX EAX, AX*/ addbyte(0xbf); addbyte(0xc0); @@ -4049,24 +4043,24 @@ static void FP_LOAD_IW() addbyte(0xc0); addbyte(0x89); /*MOV TOP, EBX*/ addbyte(0x5d); - addbyte(cpu_state_offset(TOP)); + addbyte((uint8_t)cpu_state_offset(TOP)); addbyte(0x66); /*MOVQ [ST+EBX*8], XMM0*/ addbyte(0x0f); addbyte(0xd6); addbyte(0x44); addbyte(0xdd); - addbyte(cpu_state_offset(ST)); + addbyte((uint8_t)cpu_state_offset(ST)); addbyte(0x0f); /*SETE [tag+EBX]*/ addbyte(0x94); addbyte(0x44); addbyte(0x1d); - addbyte(cpu_state_offset(tag)); + addbyte((uint8_t)cpu_state_offset(tag)); } -static void FP_LOAD_IL() +static inline void FP_LOAD_IL() { addbyte(0x8b); /*MOV EBX, TOP*/ addbyte(0x5d); - addbyte(cpu_state_offset(TOP)); + addbyte((uint8_t)cpu_state_offset(TOP)); addbyte(0x83); /*SUB EBX, 1*/ addbyte(0xeb); addbyte(0x01); @@ -4081,24 +4075,24 @@ static void FP_LOAD_IL() addbyte(0xc0); addbyte(0x89); /*MOV TOP, EBX*/ addbyte(0x5d); - addbyte(cpu_state_offset(TOP)); + addbyte((uint8_t)cpu_state_offset(TOP)); addbyte(0x66); /*MOVQ [ST+EBX*8], XMM0*/ addbyte(0x0f); addbyte(0xd6); addbyte(0x44); addbyte(0xdd); - addbyte(cpu_state_offset(ST)); + addbyte((uint8_t)cpu_state_offset(ST)); addbyte(0x0f); /*SETE [tag+EBX]*/ addbyte(0x94); addbyte(0x44); addbyte(0x1d); - addbyte(cpu_state_offset(tag)); + addbyte((uint8_t)cpu_state_offset(tag)); } -static void FP_LOAD_IQ() +static inline void FP_LOAD_IQ() { addbyte(0x8b); /*MOV EBX, TOP*/ addbyte(0x5d); - addbyte(cpu_state_offset(TOP)); + addbyte((uint8_t)cpu_state_offset(TOP)); addbyte(0x83); /*SUB EBX, 1*/ addbyte(0xeb); addbyte(0x01); @@ -4117,10 +4111,10 @@ static void FP_LOAD_IQ() addbyte(0x89); addbyte(0x44); addbyte(0xdd); - addbyte(cpu_state_offset(MM)); + addbyte((uint8_t)cpu_state_offset(MM)); addbyte(0x89); /*MOV TOP, EBX*/ addbyte(0x5d); - addbyte(cpu_state_offset(TOP)); + addbyte((uint8_t)cpu_state_offset(TOP)); addbyte(0x0f); /*SETE AL*/ addbyte(0x94); addbyte(0xc0); @@ -4129,20 +4123,20 @@ static void FP_LOAD_IQ() addbyte(0xd6); addbyte(0x44); addbyte(0xdd); - addbyte(cpu_state_offset(ST)); + addbyte((uint8_t)cpu_state_offset(ST)); addbyte(0x0c); /*OR AL, TAG_UINT64*/ addbyte(TAG_UINT64); addbyte(0x88); /*MOV [tag+EBX], AL*/ addbyte(0x44); addbyte(0x1d); - addbyte(cpu_state_offset(tag)); + addbyte((uint8_t)cpu_state_offset(tag)); } -static void FP_LOAD_IMM_Q(uint64_t v) +static inline void FP_LOAD_IMM_Q(uint64_t v) { addbyte(0x8b); /*MOV EBX, TOP*/ addbyte(0x5d); - addbyte(cpu_state_offset(TOP)); + addbyte((uint8_t)cpu_state_offset(TOP)); addbyte(0x83); /*SUB EBX, 1*/ addbyte(0xeb); addbyte(0x01); @@ -4152,28 +4146,28 @@ static void FP_LOAD_IMM_Q(uint64_t v) addbyte(0xc7); /*MOV ST[EBP+EBX*8], v*/ addbyte(0x44); addbyte(0xdd); - addbyte(cpu_state_offset(ST)); + addbyte((uint8_t)cpu_state_offset(ST)); addlong(v & 0xffffffff); addbyte(0xc7); /*MOV ST[EBP+EBX*8]+4, v*/ addbyte(0x44); addbyte(0xdd); - addbyte(cpu_state_offset(ST) + 4); + addbyte((uint8_t)cpu_state_offset(ST) + 4); addlong(v >> 32); addbyte(0x89); /*MOV TOP, EBX*/ addbyte(0x5d); - addbyte(cpu_state_offset(TOP)); + addbyte((uint8_t)cpu_state_offset(TOP)); addbyte(0xc6); /*MOV [tag+EBX], (v ? 0 : 1)*/ addbyte(0x44); addbyte(0x1d); - addbyte(cpu_state_offset(tag)); + addbyte((uint8_t)cpu_state_offset(tag)); addbyte(v ? 0 : 1); } -static void FP_FCHS() +static inline void FP_FCHS() { addbyte(0x8b); /*MOV EAX, TOP*/ addbyte(0x45); - addbyte(cpu_state_offset(TOP)); + addbyte((uint8_t)cpu_state_offset(TOP)); addbyte(0xf2); /*SUBSD XMM0, XMM0*/ addbyte(0x0f); addbyte(0x5c); @@ -4183,25 +4177,25 @@ static void FP_FCHS() addbyte(0x5c); addbyte(0x44); addbyte(0xc5); - addbyte(cpu_state_offset(ST)); + addbyte((uint8_t)cpu_state_offset(ST)); addbyte(0x80); /*AND tag[EAX], ~TAG_UINT64*/ addbyte(0x64); addbyte(0x05); - addbyte(cpu_state_offset(tag[0])); + addbyte((uint8_t)cpu_state_offset(tag[0])); addbyte(~TAG_UINT64); addbyte(0xf2); /*MOVSD ST[EAX*8], XMM0*/ addbyte(0x0f); addbyte(0x11); addbyte(0x44); addbyte(0xc5); - addbyte(cpu_state_offset(ST)); + addbyte((uint8_t)cpu_state_offset(ST)); } -static int FP_LOAD_REG(int reg) +static inline int FP_LOAD_REG(int reg) { addbyte(0x8b); /*MOV EBX, TOP*/ addbyte(0x5d); - addbyte(cpu_state_offset(TOP)); + addbyte((uint8_t)cpu_state_offset(TOP)); if (reg) { addbyte(0x83); /*ADD EBX, reg*/ @@ -4216,7 +4210,7 @@ static int FP_LOAD_REG(int reg) addbyte(0x7e); addbyte(0x44); addbyte(0xdd); - addbyte(cpu_state_offset(ST)); + addbyte((uint8_t)cpu_state_offset(ST)); addbyte(0xf2); /*CVTSD2SS XMM0, XMM0*/ addbyte(0x0f); addbyte(0x5a); @@ -4228,11 +4222,11 @@ static int FP_LOAD_REG(int reg) return REG_EBX; } -static void FP_LOAD_REG_D(int reg, int *host_reg1, int *host_reg2) +static inline void FP_LOAD_REG_D(int reg, int *host_reg1, int *host_reg2) { addbyte(0x8b); /*MOV EBX, TOP*/ addbyte(0x5d); - addbyte(cpu_state_offset(TOP)); + addbyte((uint8_t)cpu_state_offset(TOP)); if (reg) { addbyte(0x83); /*ADD EBX, reg*/ @@ -4246,11 +4240,11 @@ static void FP_LOAD_REG_D(int reg, int *host_reg1, int *host_reg2) addbyte(0x8b); addbyte(0x5c); addbyte(0xdd); - addbyte(cpu_state_offset(ST)); + addbyte((uint8_t)cpu_state_offset(ST)); *host_reg1 = REG_EBX; } -static int64_t x87_fround(double b) +static inline int64_t x87_fround(double b) { int64_t a, c; @@ -4272,15 +4266,17 @@ static int64_t x87_fround(double b) case 3: /*Chop*/ return (int64_t)b; } + + return 0; } -static int FP_LOAD_REG_INT_W(int reg) +static inline int FP_LOAD_REG_INT_W(int reg) { addbyte(0x89); /*MOV EBX, EAX*/ addbyte(0xc3); addbyte(0x8b); /*MOV EAX, [TOP]*/ addbyte(0x45); - addbyte(cpu_state_offset(TOP)); + addbyte((uint8_t)cpu_state_offset(TOP)); if (reg) { addbyte(0x83); /*ADD EAX, reg*/ @@ -4295,22 +4291,22 @@ static int FP_LOAD_REG_INT_W(int reg) addbyte(0x7e); addbyte(0x44); addbyte(0xc5); - addbyte(cpu_state_offset(ST)); + addbyte((uint8_t)cpu_state_offset(ST)); - CALL_FUNC(x87_fround); + CALL_FUNC((uintptr_t)x87_fround); addbyte(0x93); /*XCHG EBX, EAX*/ return REG_EBX; } -static int FP_LOAD_REG_INT(int reg) +static inline int FP_LOAD_REG_INT(int reg) { addbyte(0x89); /*MOV EBX, EAX*/ addbyte(0xc3); addbyte(0x8b); /*MOV EAX, [TOP]*/ addbyte(0x45); - addbyte(cpu_state_offset(TOP)); + addbyte((uint8_t)cpu_state_offset(TOP)); if (reg) { addbyte(0x83); /*ADD EAX, reg*/ @@ -4325,22 +4321,22 @@ static int FP_LOAD_REG_INT(int reg) addbyte(0x7e); addbyte(0x44); addbyte(0xc5); - addbyte(cpu_state_offset(ST)); + addbyte((uint8_t)cpu_state_offset(ST)); - CALL_FUNC(x87_fround); + CALL_FUNC((uintptr_t)x87_fround); addbyte(0x93); /*XCHG EBX, EAX*/ return REG_EBX; } -static void FP_LOAD_REG_INT_Q(int reg, int *host_reg1, int *host_reg2) +static inline void FP_LOAD_REG_INT_Q(int reg, int *host_reg1, int *host_reg2) { addbyte(0x89); /*MOV EBX, EAX*/ addbyte(0xc3); addbyte(0x8b); /*MOV EAX, [TOP]*/ addbyte(0x45); - addbyte(cpu_state_offset(TOP)); + addbyte((uint8_t)cpu_state_offset(TOP)); if (reg) { addbyte(0x83); /*ADD EAX, reg*/ @@ -4360,7 +4356,7 @@ static void FP_LOAD_REG_INT_Q(int reg, int *host_reg1, int *host_reg2) addbyte(0x8b); addbyte(0x44); addbyte(0xc5); - addbyte(cpu_state_offset(MM)); + addbyte((uint8_t)cpu_state_offset(MM)); addbyte(0x48); /*XCHG RBX, RAX*/ addbyte(0x93); @@ -4373,7 +4369,7 @@ static void FP_LOAD_REG_INT_Q(int reg, int *host_reg1, int *host_reg2) addbyte(0xf6); /*TEST TAG[EAX], TAG_UINT64*/ addbyte(0x44); addbyte(0x05); - addbyte(cpu_state_offset(tag)); + addbyte((uint8_t)cpu_state_offset(tag)); addbyte(TAG_UINT64); addbyte(0x74); /*JZ +*/ @@ -4383,7 +4379,7 @@ static void FP_LOAD_REG_INT_Q(int reg, int *host_reg1, int *host_reg2) addbyte(0x8b); addbyte(0x44); addbyte(0xc5); - addbyte(cpu_state_offset(MM)); + addbyte((uint8_t)cpu_state_offset(MM)); addbyte(0xeb); /*JMP done*/ addbyte(6+12); @@ -4393,9 +4389,9 @@ static void FP_LOAD_REG_INT_Q(int reg, int *host_reg1, int *host_reg2) addbyte(0x7e); addbyte(0x44); addbyte(0xc5); - addbyte(cpu_state_offset(ST)); + addbyte((uint8_t)cpu_state_offset(ST)); - CALL_FUNC(x87_fround); + CALL_FUNC((uintptr_t)x87_fround); addbyte(0x48); /*XCHG RBX, RAX*/ addbyte(0x93); @@ -4410,11 +4406,11 @@ static void FP_LOAD_REG_INT_Q(int reg, int *host_reg1, int *host_reg2) #define FPU_SUB 2 #define FPU_SUBR 3 -static void FP_OP_REG(int op, int dst, int src) +static inline void FP_OP_REG(int op, int dst, int src) { addbyte(0x8b); /*MOV EAX, [TOP]*/ addbyte(0x45); - addbyte(cpu_state_offset(TOP)); + addbyte((uint8_t)cpu_state_offset(TOP)); addbyte(0x89); /*MOV EBX, EAX*/ addbyte(0xc3); if (dst) @@ -4438,7 +4434,7 @@ static void FP_OP_REG(int op, int dst, int src) addbyte(0x80); /*AND tag[EAX], ~TAG_UINT64*/ addbyte(0x64); addbyte(0x05); - addbyte(cpu_state_offset(tag)); + addbyte((uint8_t)cpu_state_offset(tag)); addbyte(~TAG_UINT64); if (op == FPU_DIVR || op == FPU_SUBR) { @@ -4447,7 +4443,7 @@ static void FP_OP_REG(int op, int dst, int src) addbyte(0x7e); addbyte(0x44); addbyte(0xdd); - addbyte(cpu_state_offset(ST)); + addbyte((uint8_t)cpu_state_offset(ST)); } else { @@ -4456,7 +4452,7 @@ static void FP_OP_REG(int op, int dst, int src) addbyte(0x7e); addbyte(0x44); addbyte(0xc5); - addbyte(cpu_state_offset(ST)); + addbyte((uint8_t)cpu_state_offset(ST)); } switch (op) { @@ -4466,7 +4462,7 @@ static void FP_OP_REG(int op, int dst, int src) addbyte(0x58); addbyte(0x44); addbyte(0xdd); - addbyte(cpu_state_offset(ST)); + addbyte((uint8_t)cpu_state_offset(ST)); break; case FPU_DIV: addbyte(0xf2); /*DIVSD XMM0, ST[RBX*8]*/ @@ -4474,7 +4470,7 @@ static void FP_OP_REG(int op, int dst, int src) addbyte(0x5e); addbyte(0x44); addbyte(0xdd); - addbyte(cpu_state_offset(ST)); + addbyte((uint8_t)cpu_state_offset(ST)); break; case FPU_DIVR: addbyte(0xf2); /*DIVSD XMM0, ST[RAX*8]*/ @@ -4482,7 +4478,7 @@ static void FP_OP_REG(int op, int dst, int src) addbyte(0x5e); addbyte(0x44); addbyte(0xc5); - addbyte(cpu_state_offset(ST)); + addbyte((uint8_t)cpu_state_offset(ST)); break; case FPU_MUL: addbyte(0xf2); /*MULSD XMM0, ST[RBX*8]*/ @@ -4490,7 +4486,7 @@ static void FP_OP_REG(int op, int dst, int src) addbyte(0x59); addbyte(0x44); addbyte(0xdd); - addbyte(cpu_state_offset(ST)); + addbyte((uint8_t)cpu_state_offset(ST)); break; case FPU_SUB: addbyte(0xf2); /*SUBSD XMM0, ST[RBX*8]*/ @@ -4498,7 +4494,7 @@ static void FP_OP_REG(int op, int dst, int src) addbyte(0x5c); addbyte(0x44); addbyte(0xdd); - addbyte(cpu_state_offset(ST)); + addbyte((uint8_t)cpu_state_offset(ST)); break; case FPU_SUBR: addbyte(0xf2); /*SUBSD XMM0, ST[RAX*8]*/ @@ -4506,7 +4502,7 @@ static void FP_OP_REG(int op, int dst, int src) addbyte(0x5c); addbyte(0x44); addbyte(0xc5); - addbyte(cpu_state_offset(ST)); + addbyte((uint8_t)cpu_state_offset(ST)); break; } addbyte(0x66); /*MOVQ [RSI+RAX*8], XMM0*/ @@ -4514,24 +4510,24 @@ static void FP_OP_REG(int op, int dst, int src) addbyte(0xd6); addbyte(0x44); addbyte(0xc5); - addbyte(cpu_state_offset(ST)); + addbyte((uint8_t)cpu_state_offset(ST)); } -static void FP_OP_MEM(int op) +static inline void FP_OP_MEM(int op) { addbyte(0x8b); /*MOV EAX, [TOP]*/ addbyte(0x45); - addbyte(cpu_state_offset(TOP)); + addbyte((uint8_t)cpu_state_offset(TOP)); addbyte(0xf3); /*MOVQ XMM0, ST[RAX*8]*/ addbyte(0x0f); addbyte(0x7e); addbyte(0x44); addbyte(0xc5); - addbyte(cpu_state_offset(ST)); + addbyte((uint8_t)cpu_state_offset(ST)); addbyte(0x80); /*AND tag[EAX], ~TAG_UINT64*/ addbyte(0x64); addbyte(0x05); - addbyte(cpu_state_offset(tag)); + addbyte((uint8_t)cpu_state_offset(tag)); addbyte(~TAG_UINT64); switch (op) @@ -4580,7 +4576,7 @@ static void FP_OP_MEM(int op) addbyte(0xd6); addbyte(0x4c); addbyte(0xc5); - addbyte(cpu_state_offset(ST)); + addbyte((uint8_t)cpu_state_offset(ST)); } else { @@ -4589,11 +4585,11 @@ static void FP_OP_MEM(int op) addbyte(0xd6); addbyte(0x44); addbyte(0xc5); - addbyte(cpu_state_offset(ST)); + addbyte((uint8_t)cpu_state_offset(ST)); } } -static void FP_OP_S(int op) +static inline void FP_OP_S(int op) { addbyte(0x66); /*MOVD XMM1, EAX*/ addbyte(0x0f); @@ -4605,7 +4601,7 @@ static void FP_OP_S(int op) addbyte(0xc9); FP_OP_MEM(op); } -static void FP_OP_D(int op) +static inline void FP_OP_D(int op) { addbyte(0x66); /*MOVQ XMM1, RAX*/ addbyte(0x48); @@ -4647,7 +4643,7 @@ static void FP_OP_D(int op) addbyte(0x08); } } -static void FP_OP_IW(int op) +static inline void FP_OP_IW(int op) { addbyte(0x0f); /*MOVSX EAX, AX*/ addbyte(0xbf); @@ -4658,7 +4654,7 @@ static void FP_OP_IW(int op) addbyte(0xc8); FP_OP_MEM(op); } -static void FP_OP_IL(int op) +static inline void FP_OP_IL(int op) { addbyte(0xf2); /*CVTSI2SD XMM1, EAX*/ addbyte(0x0f); @@ -4672,11 +4668,11 @@ static void FP_OP_IL(int op) #define C2 (1<<10) #define C3 (1<<14) -static void FP_COMPARE_REG(int dst, int src) +static inline void FP_COMPARE_REG(int dst, int src) { addbyte(0x8b); /*MOV EAX, [TOP]*/ addbyte(0x45); - addbyte(cpu_state_offset(TOP)); + addbyte((uint8_t)cpu_state_offset(TOP)); addbyte(0x89); /*MOV EBX, EAX*/ addbyte(0xc3); if (src || dst) @@ -4691,9 +4687,7 @@ static void FP_COMPARE_REG(int dst, int src) addbyte(0x8a); /*MOV CL, [npxs+1]*/ addbyte(0x4d); - addbyte(cpu_state_offset(npxs) + 1); -// addbyte(0xdb); /*FCLEX*/ -// addbyte(0xe2); + addbyte((uint8_t)cpu_state_offset(npxs) + 1); addbyte(0x80); /*AND CL, ~(C0|C2|C3)*/ addbyte(0xe1); addbyte((~(C0|C2|C3)) >> 8); @@ -4705,13 +4699,13 @@ static void FP_COMPARE_REG(int dst, int src) addbyte(0x7e); addbyte(0x44); addbyte(0xdd); - addbyte(cpu_state_offset(ST)); + addbyte((uint8_t)cpu_state_offset(ST)); addbyte(0x66); /*COMISD XMM0, ST[RAX*8]*/ addbyte(0x0f); addbyte(0x2f); addbyte(0x44); addbyte(0xc5); - addbyte(cpu_state_offset(ST)); + addbyte((uint8_t)cpu_state_offset(ST)); } else { @@ -4720,13 +4714,13 @@ static void FP_COMPARE_REG(int dst, int src) addbyte(0x7e); addbyte(0x44); addbyte(0xc5); - addbyte(cpu_state_offset(ST)); + addbyte((uint8_t)cpu_state_offset(ST)); addbyte(0x66); /*COMISD XMM0, ST[RBX*8]*/ addbyte(0x0f); addbyte(0x2f); addbyte(0x44); addbyte(0xdd); - addbyte(cpu_state_offset(ST)); + addbyte((uint8_t)cpu_state_offset(ST)); } addbyte(0x9f); /*LAHF*/ @@ -4737,26 +4731,24 @@ static void FP_COMPARE_REG(int dst, int src) addbyte(0xe1); addbyte(0x88); /*MOV [npxs+1], CL*/ addbyte(0x4d); - addbyte(cpu_state_offset(npxs) + 1); + addbyte((uint8_t)cpu_state_offset(npxs) + 1); } -static void FP_COMPARE_MEM() +static inline void FP_COMPARE_MEM() { addbyte(0x8b); /*MOV EAX, [TOP]*/ addbyte(0x45); - addbyte(cpu_state_offset(TOP)); + addbyte((uint8_t)cpu_state_offset(TOP)); addbyte(0x8a); /*MOV CL, [npxs+1]*/ addbyte(0x4d); - addbyte(cpu_state_offset(npxs) + 1); -// addbyte(0xdb); /*FCLEX*/ -// addbyte(0xe2); + addbyte((uint8_t)cpu_state_offset(npxs) + 1); addbyte(0xf3); /*MOVQ XMM0, ST[RAX*8]*/ addbyte(0x0f); addbyte(0x7e); addbyte(0x44); addbyte(0xc5); - addbyte(cpu_state_offset(ST)); + addbyte((uint8_t)cpu_state_offset(ST)); addbyte(0x80); /*AND CL, ~(C0|C2|C3)*/ addbyte(0xe1); addbyte((~(C0|C2|C3)) >> 8); @@ -4772,9 +4764,9 @@ static void FP_COMPARE_MEM() addbyte(0xe1); addbyte(0x88); /*MOV [npxs+1], CL*/ addbyte(0x4d); - addbyte(cpu_state_offset(npxs) + 1); + addbyte((uint8_t)cpu_state_offset(npxs) + 1); } -static void FP_COMPARE_S() +static inline void FP_COMPARE_S() { addbyte(0x66); /*MOVD XMM1, EAX*/ addbyte(0x0f); @@ -4786,7 +4778,7 @@ static void FP_COMPARE_S() addbyte(0xc9); FP_COMPARE_MEM(); } -static void FP_COMPARE_D() +static inline void FP_COMPARE_D() { addbyte(0x66); /*MOVQ XMM1, RAX*/ addbyte(0x48); @@ -4795,7 +4787,7 @@ static void FP_COMPARE_D() addbyte(0xc8); FP_COMPARE_MEM(); } -static void FP_COMPARE_IW() +static inline void FP_COMPARE_IW() { addbyte(0x0f); /*MOVSX EAX, AX*/ addbyte(0xbf); @@ -4806,7 +4798,7 @@ static void FP_COMPARE_IW() addbyte(0xc8); FP_COMPARE_MEM(); } -static void FP_COMPARE_IL() +static inline void FP_COMPARE_IL() { addbyte(0xf2); /*CVTSI2SD XMM1, EAX*/ addbyte(0x0f); @@ -4815,11 +4807,11 @@ static void FP_COMPARE_IL() FP_COMPARE_MEM(); } -static void UPDATE_NPXC(int reg) +static inline void UPDATE_NPXC(int reg) { } -static void SET_BITS(uintptr_t addr, uint32_t val) +static inline void SET_BITS(uintptr_t addr, uint32_t val) { if (IS_32_ADDR(addr)) { @@ -4860,7 +4852,7 @@ static void SET_BITS(uintptr_t addr, uint32_t val) } } -static void CLEAR_BITS(uintptr_t addr, uint32_t val) +static inline void CLEAR_BITS(uintptr_t addr, uint32_t val) { if (IS_32_ADDR(addr)) { @@ -4904,7 +4896,7 @@ static void CLEAR_BITS(uintptr_t addr, uint32_t val) #define LOAD_Q_REG_1 REG_EAX #define LOAD_Q_REG_2 REG_EDX -static void MMX_ENTER() +static inline void MMX_ENTER() { if (codegen_mmx_entered) return; @@ -4921,7 +4913,7 @@ static void MMX_ENTER() { addbyte(0x48); /*MOV RAX, &cr0*/ addbyte(0xb8 | REG_EAX); - addquad(&cr0); + addquad((uint64_t)&cr0); addbyte(0xf6); /*TEST [RAX], 0xc*/ addbyte(0 | (REG_EAX << 3)); addbyte(0x0c); @@ -4930,10 +4922,10 @@ static void MMX_ENTER() addbyte(7+5+12+5); addbyte(0xC7); /*MOVL [oldpc],op_old_pc*/ addbyte(0x45); - addbyte(cpu_state_offset(oldpc)); + addbyte((uint8_t)cpu_state_offset(oldpc)); addlong(op_old_pc); load_param_1_32(&codeblock[block_current], 7); - CALL_FUNC(x86_int); + CALL_FUNC((uintptr_t)x86_int); addbyte(0xe9); /*JMP end*/ addlong(BLOCK_EXIT_OFFSET - (block_pos + 4)); @@ -4942,35 +4934,35 @@ static void MMX_ENTER() addbyte(0xc0); addbyte(0xc6); /*MOV ISMMX, 1*/ addbyte(0x45); - addbyte(cpu_state_offset(ismmx)); + addbyte((uint8_t)cpu_state_offset(ismmx)); addbyte(1); addbyte(0x89); /*MOV TOP, EAX*/ addbyte(0x45); - addbyte(cpu_state_offset(TOP)); + addbyte((uint8_t)cpu_state_offset(TOP)); addbyte(0x89); /*MOV tag, EAX*/ addbyte(0x45); - addbyte(cpu_state_offset(tag[0])); + addbyte((uint8_t)cpu_state_offset(tag[0])); addbyte(0x89); /*MOV tag+4, EAX*/ addbyte(0x45); - addbyte(cpu_state_offset(tag[4])); + addbyte((uint8_t)cpu_state_offset(tag[4])); codegen_mmx_entered = 1; } extern int mmx_ebx_ecx_loaded; -static int LOAD_MMX_D(int guest_reg) +static inline int LOAD_MMX_D(int guest_reg) { int host_reg = REG_EBX; addbyte(0x8b); /*MOV EBX, reg*/ addbyte(0x44 | (host_reg << 3)); addbyte(0x25); - addbyte(cpu_state_offset(MM[guest_reg].l[0])); + addbyte((uint8_t)cpu_state_offset(MM[guest_reg].l[0])); return host_reg; } -static void LOAD_MMX_Q(int guest_reg, int *host_reg1, int *host_reg2) +static inline void LOAD_MMX_Q(int guest_reg, int *host_reg1, int *host_reg2) { int host_reg = REG_EBX; @@ -4981,11 +4973,11 @@ static void LOAD_MMX_Q(int guest_reg, int *host_reg1, int *host_reg2) addbyte(0x8b); /*MOV RBX, reg*/ addbyte(0x44 | ((host_reg & 7) << 3)); addbyte(0x25); - addbyte(cpu_state_offset(MM[guest_reg].q)); + addbyte((uint8_t)cpu_state_offset(MM[guest_reg].q)); *host_reg1 = host_reg; } -static int LOAD_MMX_Q_MMX(int guest_reg) +static inline int LOAD_MMX_Q_MMX(int guest_reg) { int dst_reg = find_host_xmm_reg(); host_reg_xmm_mapping[dst_reg] = 100; @@ -4995,12 +4987,12 @@ static int LOAD_MMX_Q_MMX(int guest_reg) addbyte(0x7e); addbyte(0x44 | ((dst_reg & 7) << 3)); addbyte(0x25); - addbyte(cpu_state_offset(MM[guest_reg].q)); + addbyte((uint8_t)cpu_state_offset(MM[guest_reg].q)); return dst_reg; } -static int LOAD_INT_TO_MMX(int src_reg1, int src_reg2) +static inline int LOAD_INT_TO_MMX(int src_reg1, int src_reg2) { int dst_reg = find_host_xmm_reg(); host_reg_xmm_mapping[dst_reg] = 100; @@ -5017,21 +5009,21 @@ static int LOAD_INT_TO_MMX(int src_reg1, int src_reg2) return dst_reg; } -static void STORE_MMX_LQ(int guest_reg, int host_reg1) +static inline void STORE_MMX_LQ(int guest_reg, int host_reg1) { addbyte(0xC7); /*MOVL [reg],0*/ addbyte(0x44); addbyte(0x25); - addbyte(cpu_state_offset(MM[guest_reg].l[1])); + addbyte((uint8_t)cpu_state_offset(MM[guest_reg].l[1])); addlong(0); if (host_reg1 & 8) addbyte(0x44); addbyte(0x89); /*MOVL [reg],host_reg*/ addbyte(0x44 | ((host_reg1 & 7) << 3)); addbyte(0x25); - addbyte(cpu_state_offset(MM[guest_reg].l[0])); + addbyte((uint8_t)cpu_state_offset(MM[guest_reg].l[0])); } -static void STORE_MMX_Q(int guest_reg, int host_reg1, int host_reg2) +static inline void STORE_MMX_Q(int guest_reg, int host_reg1, int host_reg2) { if (host_reg1 & 8) addbyte(0x4c); @@ -5040,20 +5032,20 @@ static void STORE_MMX_Q(int guest_reg, int host_reg1, int host_reg2) addbyte(0x89); /*MOV [reg],host_reg*/ addbyte(0x44 | ((host_reg1 & 7) << 3)); addbyte(0x25); - addbyte(cpu_state_offset(MM[guest_reg].l[0])); + addbyte((uint8_t)cpu_state_offset(MM[guest_reg].l[0])); } -static void STORE_MMX_Q_MMX(int guest_reg, int host_reg) +static inline void STORE_MMX_Q_MMX(int guest_reg, int host_reg) { addbyte(0x66); /*MOVQ [guest_reg],host_reg*/ addbyte(0x0f); addbyte(0xd6); addbyte(0x44 | (host_reg << 3)); addbyte(0x25); - addbyte(cpu_state_offset(MM[guest_reg].q)); + addbyte((uint8_t)cpu_state_offset(MM[guest_reg].q)); } #define MMX_x86_OP(name, opcode) \ -static void MMX_ ## name(int dst_reg, int src_reg) \ +static inline void MMX_ ## name(int dst_reg, int src_reg) \ { \ addbyte(0x66); /*op dst_reg, src_reg*/ \ addbyte(0x0f); \ @@ -5106,7 +5098,7 @@ MMX_x86_OP(PMULLW, 0xd5); MMX_x86_OP(PMULHW, 0xe5); MMX_x86_OP(PMADDWD, 0xf5); -static void MMX_PACKSSWB(int dst_reg, int src_reg) +static inline void MMX_PACKSSWB(int dst_reg, int src_reg) { addbyte(0x66); /*PACKSSWB dst_reg, src_reg*/ addbyte(0x0f); @@ -5118,7 +5110,7 @@ static void MMX_PACKSSWB(int dst_reg, int src_reg) addbyte(0xc0 | (dst_reg << 3) | dst_reg); addbyte(0x08); } -static void MMX_PACKUSWB(int dst_reg, int src_reg) +static inline void MMX_PACKUSWB(int dst_reg, int src_reg) { addbyte(0x66); /*PACKUSWB dst_reg, src_reg*/ addbyte(0x0f); @@ -5130,7 +5122,7 @@ static void MMX_PACKUSWB(int dst_reg, int src_reg) addbyte(0xc0 | (dst_reg << 3) | dst_reg); addbyte(0x08); } -static void MMX_PACKSSDW(int dst_reg, int src_reg) +static inline void MMX_PACKSSDW(int dst_reg, int src_reg) { addbyte(0x66); /*PACKSSDW dst_reg, src_reg*/ addbyte(0x0f); @@ -5142,7 +5134,7 @@ static void MMX_PACKSSDW(int dst_reg, int src_reg) addbyte(0xc0 | (dst_reg << 3) | dst_reg); addbyte(0x08); } -static void MMX_PUNPCKHBW(int dst_reg, int src_reg) +static inline void MMX_PUNPCKHBW(int dst_reg, int src_reg) { addbyte(0x66); /*PUNPCKLBW dst_reg, src_reg*/ addbyte(0x0f); @@ -5154,7 +5146,7 @@ static void MMX_PUNPCKHBW(int dst_reg, int src_reg) addbyte(0xc0 | (dst_reg << 3) | dst_reg); addbyte(0x0e); } -static void MMX_PUNPCKHWD(int dst_reg, int src_reg) +static inline void MMX_PUNPCKHWD(int dst_reg, int src_reg) { addbyte(0x66); /*PUNPCKLWD dst_reg, src_reg*/ addbyte(0x0f); @@ -5166,7 +5158,7 @@ static void MMX_PUNPCKHWD(int dst_reg, int src_reg) addbyte(0xc0 | (dst_reg << 3) | dst_reg); addbyte(0x0e); } -static void MMX_PUNPCKHDQ(int dst_reg, int src_reg) +static inline void MMX_PUNPCKHDQ(int dst_reg, int src_reg) { addbyte(0x66); /*PUNPCKLDQ dst_reg, src_reg*/ addbyte(0x0f); @@ -5179,7 +5171,7 @@ static void MMX_PUNPCKHDQ(int dst_reg, int src_reg) addbyte(0x0e); } -static void MMX_PSRLW_imm(int dst_reg, int amount) +static inline void MMX_PSRLW_imm(int dst_reg, int amount) { addbyte(0x66); /*PSRLW dst_reg, amount*/ addbyte(0x0f); @@ -5187,7 +5179,7 @@ static void MMX_PSRLW_imm(int dst_reg, int amount) addbyte(0xc0 | dst_reg | 0x10); addbyte(amount); } -static void MMX_PSRAW_imm(int dst_reg, int amount) +static inline void MMX_PSRAW_imm(int dst_reg, int amount) { addbyte(0x66); /*PSRAW dst_reg, amount*/ addbyte(0x0f); @@ -5195,7 +5187,7 @@ static void MMX_PSRAW_imm(int dst_reg, int amount) addbyte(0xc0 | dst_reg | 0x20); addbyte(amount); } -static void MMX_PSLLW_imm(int dst_reg, int amount) +static inline void MMX_PSLLW_imm(int dst_reg, int amount) { addbyte(0x66); /*PSLLW dst_reg, amount*/ addbyte(0x0f); @@ -5204,7 +5196,7 @@ static void MMX_PSLLW_imm(int dst_reg, int amount) addbyte(amount); } -static void MMX_PSRLD_imm(int dst_reg, int amount) +static inline void MMX_PSRLD_imm(int dst_reg, int amount) { addbyte(0x66); /*PSRLD dst_reg, amount*/ addbyte(0x0f); @@ -5212,7 +5204,7 @@ static void MMX_PSRLD_imm(int dst_reg, int amount) addbyte(0xc0 | dst_reg | 0x10); addbyte(amount); } -static void MMX_PSRAD_imm(int dst_reg, int amount) +static inline void MMX_PSRAD_imm(int dst_reg, int amount) { addbyte(0x66); /*PSRAD dst_reg, amount*/ addbyte(0x0f); @@ -5220,7 +5212,7 @@ static void MMX_PSRAD_imm(int dst_reg, int amount) addbyte(0xc0 | dst_reg | 0x20); addbyte(amount); } -static void MMX_PSLLD_imm(int dst_reg, int amount) +static inline void MMX_PSLLD_imm(int dst_reg, int amount) { addbyte(0x66); /*PSLLD dst_reg, amount*/ addbyte(0x0f); @@ -5229,7 +5221,7 @@ static void MMX_PSLLD_imm(int dst_reg, int amount) addbyte(amount); } -static void MMX_PSRLQ_imm(int dst_reg, int amount) +static inline void MMX_PSRLQ_imm(int dst_reg, int amount) { addbyte(0x66); /*PSRLQ dst_reg, amount*/ addbyte(0x0f); @@ -5237,7 +5229,7 @@ static void MMX_PSRLQ_imm(int dst_reg, int amount) addbyte(0xc0 | dst_reg | 0x10); addbyte(amount); } -static void MMX_PSRAQ_imm(int dst_reg, int amount) +static inline void MMX_PSRAQ_imm(int dst_reg, int amount) { addbyte(0x66); /*PSRAQ dst_reg, amount*/ addbyte(0x0f); @@ -5245,7 +5237,7 @@ static void MMX_PSRAQ_imm(int dst_reg, int amount) addbyte(0xc0 | dst_reg | 0x20); addbyte(amount); } -static void MMX_PSLLQ_imm(int dst_reg, int amount) +static inline void MMX_PSLLQ_imm(int dst_reg, int amount) { addbyte(0x66); /*PSLLQ dst_reg, amount*/ addbyte(0x0f); @@ -5255,14 +5247,14 @@ static void MMX_PSLLQ_imm(int dst_reg, int amount) } -static void SAVE_EA() +static inline void SAVE_EA() { addbyte(0x89); /*MOV [ESP+0x24], EAX*/ addbyte(0x44); addbyte(0x24); addbyte(0x24); } -static void LOAD_EA() +static inline void LOAD_EA() { addbyte(0x8b); /*MOV EAX, [ESP+0x24]*/ addbyte(0x44); @@ -5272,9 +5264,9 @@ static void LOAD_EA() #define MEM_CHECK_WRITE_B MEM_CHECK_WRITE -static void MEM_CHECK_WRITE(x86seg *seg) +static inline void MEM_CHECK_WRITE(x86seg *seg) { - uint8_t *jump1, *jump2, *jump3; + uint8_t *jump1, *jump2, *jump3 = NULL; CHECK_SEG_WRITE(seg); @@ -5288,7 +5280,7 @@ static void MEM_CHECK_WRITE(x86seg *seg) addbyte(0x8b); /*MOV ESI, seg->base*/ addbyte(0x34); addbyte(0x25); - addlong((uint32_t)&seg->base); + addlong((uint32_t)(uintptr_t)&seg->base); } else { @@ -5307,7 +5299,7 @@ static void MEM_CHECK_WRITE(x86seg *seg) addbyte(0x83); /*CMP cr0, 0*/ addbyte(0x3c); addbyte(0x25); - addlong((uint32_t)&cr0); + addlong((uint32_t)(uintptr_t)&cr0); addbyte(0); } else @@ -5326,7 +5318,6 @@ static void MEM_CHECK_WRITE(x86seg *seg) addbyte(0x79); /*JNS +*/ jump1 = &codeblock[block_current].data[block_pos]; addbyte(0); -// addbyte(0xc3); /*RET*/ addbyte(0xc1); /*SHR EDI, 12*/ addbyte(0xef); addbyte(12); @@ -5344,7 +5335,7 @@ static void MEM_CHECK_WRITE(x86seg *seg) addbyte(0x83); /*CMP writelookup2[RDI*8],-1*/ addbyte(0x3c); addbyte(0xfd); - addlong((uint32_t)writelookup2); + addlong((uint32_t)(uintptr_t)writelookup2); addbyte(-1); } else @@ -5360,7 +5351,6 @@ static void MEM_CHECK_WRITE(x86seg *seg) addbyte(0x75); /*JNE +*/ jump2 = &codeblock[block_current].data[block_pos]; addbyte(0); -// addbyte(0xc3); /*RET*/ if (!(seg == &_ds && codegen_flat_ds) && !(seg == &_ss && codegen_flat_ss)) *jump3 = (uintptr_t)&codeblock[block_current].data[block_pos] - (uintptr_t)jump3 - 1; @@ -5374,41 +5364,28 @@ static void MEM_CHECK_WRITE(x86seg *seg) load_param_1_reg_32(REG_EDI); load_param_2_32(&codeblock[block_current], 1); - -// addbyte(0x6a); /*PUSH 1*/ -// addbyte(1); -// addbyte(0x57); /*PUSH EDI*/ - call(&codeblock[block_current], mmutranslatereal); -// addbyte(0x48); /*ADD ESP, 8*/ -// addbyte(0x83); -// addbyte(0xc4); -// addbyte(8); + call(&codeblock[block_current], (uintptr_t)mmutranslatereal); addbyte(0x80); /*CMP abrt, 0*/ addbyte(0x7d); - addbyte(cpu_state_offset(abrt)); + addbyte((uint8_t)cpu_state_offset(abrt)); addbyte(0); addbyte(0x0f); /*JNE mem_abrt_rout*/ addbyte(0x85); - addlong((uintptr_t)&codeblock[block_current].data[BLOCK_EXIT_OFFSET] - ((uint32_t)(&codeblock[block_current].data[block_pos]) + 4)); -// addbyte(0xc3); /*RET*/ + addlong((uintptr_t)&codeblock[block_current].data[BLOCK_EXIT_OFFSET] - ((uintptr_t)(&codeblock[block_current].data[block_pos]) + 4)); *jump1 = (uintptr_t)&codeblock[block_current].data[block_pos] - (uintptr_t)jump1 - 1; *jump2 = (uintptr_t)&codeblock[block_current].data[block_pos] - (uintptr_t)jump2 - 1; - - -// addbyte(0xe8); /*CALL mem_store_addr_ea_b*/ -// addlong(mem_check_write - (uint32_t)(&codeblock[block_current].data[block_pos + 4])); LOAD_EA(); } -static void MEM_CHECK_WRITE_W(x86seg *seg) +static inline void MEM_CHECK_WRITE_W(x86seg *seg) { - uint8_t *jump1, *jump2, *jump3, *jump4; + uint8_t *jump1, *jump2, *jump3, *jump4 = NULL; int jump_pos; CHECK_SEG_WRITE(seg); - if ((seg == &_ds && codegen_flat_ds) || (seg == &_ss && codegen_flat_ss)) + if ((seg == &_ds && codegen_flat_ds) || (seg == &_ss && codegen_flat_ss)) { addbyte(0x31); /*XOR ESI, ESI*/ addbyte(0xf6); @@ -5418,7 +5395,7 @@ static void MEM_CHECK_WRITE_W(x86seg *seg) addbyte(0x8b); /*MOV ESI, seg->base*/ addbyte(0x34); addbyte(0x25); - addlong((uint32_t)&seg->base); + addlong((uint32_t)(uintptr_t)&seg->base); } else { @@ -5437,7 +5414,7 @@ static void MEM_CHECK_WRITE_W(x86seg *seg) addbyte(0x83); /*CMP cr0, 0*/ addbyte(0x3c); addbyte(0x25); - addlong((uint32_t)&cr0); + addlong((uint32_t)(uintptr_t)&cr0); addbyte(0); } else @@ -5484,7 +5461,7 @@ static void MEM_CHECK_WRITE_W(x86seg *seg) addbyte(0x83); /*CMP writelookup2[RDI*8],-1*/ addbyte(0x3c); addbyte(0xfd); - addlong((uint32_t)writelookup2); + addlong((uint32_t)(uintptr_t)writelookup2); addbyte(-1); } else @@ -5505,7 +5482,7 @@ static void MEM_CHECK_WRITE_W(x86seg *seg) addbyte(0x83); /*CMP writelookup2[RSI*8],-1*/ addbyte(0x3c); addbyte(0xf5); - addlong((uint32_t)writelookup2); + addlong((uint32_t)(uintptr_t)writelookup2); addbyte(-1); } else @@ -5526,17 +5503,17 @@ static void MEM_CHECK_WRITE_W(x86seg *seg) jump_pos = block_pos; load_param_1_reg_32(REG_EBX); load_param_2_32(&codeblock[block_current], 1); - call(&codeblock[block_current], mmutranslatereal); + call(&codeblock[block_current], (uintptr_t)mmutranslatereal); addbyte(0x83); /*ADD EBX, 1*/ addbyte(0xc3); addbyte(1); addbyte(0x80); /*CMP abrt, 0*/ addbyte(0x7d); - addbyte(cpu_state_offset(abrt)); + addbyte((uint8_t)cpu_state_offset(abrt)); addbyte(0); addbyte(0x0f); /*JNE mem_abrt_rout*/ addbyte(0x85); - addlong((uintptr_t)&codeblock[block_current].data[BLOCK_EXIT_OFFSET] - ((uint32_t)(&codeblock[block_current].data[block_pos]) + 4)); + addlong((uintptr_t)&codeblock[block_current].data[BLOCK_EXIT_OFFSET] - ((uintptr_t)(&codeblock[block_current].data[block_pos]) + 4)); /*If bits 0-11 of the address are now 0 then this crosses a page, so loop back*/ addbyte(0xf7); /*TEST $fff, EBX*/ addbyte(0xc3); @@ -5550,9 +5527,9 @@ static void MEM_CHECK_WRITE_W(x86seg *seg) LOAD_EA(); } -static void MEM_CHECK_WRITE_L(x86seg *seg) +static inline void MEM_CHECK_WRITE_L(x86seg *seg) { - uint8_t *jump1, *jump2, *jump3, *jump4; + uint8_t *jump1, *jump2, *jump3, *jump4 = NULL; int jump_pos; CHECK_SEG_WRITE(seg); @@ -5567,7 +5544,7 @@ static void MEM_CHECK_WRITE_L(x86seg *seg) addbyte(0x8b); /*MOV ESI, seg->base*/ addbyte(0x34); addbyte(0x25); - addlong((uint32_t)&seg->base); + addlong((uint32_t)(uintptr_t)&seg->base); } else { @@ -5586,7 +5563,7 @@ static void MEM_CHECK_WRITE_L(x86seg *seg) addbyte(0x83); /*CMP cr0, 0*/ addbyte(0x3c); addbyte(0x25); - addlong((uint32_t)&cr0); + addlong((uint32_t)(uintptr_t)&cr0); addbyte(0); } else @@ -5633,7 +5610,7 @@ static void MEM_CHECK_WRITE_L(x86seg *seg) addbyte(0x83); /*CMP writelookup2[RDI*8],-1*/ addbyte(0x3c); addbyte(0xfd); - addlong((uint32_t)writelookup2); + addlong((uint32_t)(uintptr_t)writelookup2); addbyte(-1); } else @@ -5654,7 +5631,7 @@ static void MEM_CHECK_WRITE_L(x86seg *seg) addbyte(0x83); /*CMP writelookup2[RSI*8],-1*/ addbyte(0x3c); addbyte(0xf5); - addlong((uint32_t)writelookup2); + addlong((uint32_t)(uintptr_t)writelookup2); addbyte(-1); } else @@ -5675,17 +5652,17 @@ static void MEM_CHECK_WRITE_L(x86seg *seg) jump_pos = block_pos; load_param_1_reg_32(REG_EBX); load_param_2_32(&codeblock[block_current], 1); - call(&codeblock[block_current], mmutranslatereal); + call(&codeblock[block_current], (uintptr_t)mmutranslatereal); addbyte(0x83); /*ADD EBX, 3*/ addbyte(0xc3); addbyte(3); addbyte(0x80); /*CMP abrt, 0*/ addbyte(0x7d); - addbyte(cpu_state_offset(abrt)); + addbyte((uint8_t)cpu_state_offset(abrt)); addbyte(0); addbyte(0x0f); /*JNE mem_abrt_rout*/ addbyte(0x85); - addlong((uintptr_t)&codeblock[block_current].data[BLOCK_EXIT_OFFSET] - ((uint32_t)(&codeblock[block_current].data[block_pos]) + 4)); + addlong((uintptr_t)&codeblock[block_current].data[BLOCK_EXIT_OFFSET] - ((uintptr_t)(&codeblock[block_current].data[block_pos]) + 4)); /*If bits 0-11 of the address are now 0 then this crosses a page, so loop back*/ addbyte(0xf7); /*TEST $ffc, EBX*/ addbyte(0xc3); @@ -5699,7 +5676,7 @@ static void MEM_CHECK_WRITE_L(x86seg *seg) LOAD_EA(); } -static int MEM_LOAD_ADDR_EA_B_NO_ABRT(x86seg *seg) +static inline int MEM_LOAD_ADDR_EA_B_NO_ABRT(x86seg *seg) { if ((seg == &_ds && codegen_flat_ds) || (seg == &_ss && codegen_flat_ss)) { @@ -5711,7 +5688,7 @@ static int MEM_LOAD_ADDR_EA_B_NO_ABRT(x86seg *seg) addbyte(0x8b); /*MOVL ECX, seg->base*/ addbyte(0x0c); addbyte(0x25); - addlong((uint32_t)&seg->base); + addlong((uint32_t)(uintptr_t)&seg->base); } else { @@ -5737,7 +5714,7 @@ static int MEM_LOAD_ADDR_EA_B_NO_ABRT(x86seg *seg) addbyte(0x8b); addbyte(0x34); addbyte(0xf5); - addlong((uint32_t)readlookup2); + addlong((uint32_t)(uintptr_t)readlookup2); } else { @@ -5762,7 +5739,7 @@ static int MEM_LOAD_ADDR_EA_B_NO_ABRT(x86seg *seg) /*slowpath:*/ load_param_1_reg_32(REG_ECX); load_param_2_reg_32(REG_EAX); - call_long(readmemb386l); + call_long((uintptr_t)readmemb386l); addbyte(0x89); /*MOV ECX, EAX*/ addbyte(0xc1); /*done:*/ @@ -5771,7 +5748,7 @@ static int MEM_LOAD_ADDR_EA_B_NO_ABRT(x86seg *seg) return REG_ECX; } -static int MEM_LOAD_ADDR_EA_W_NO_ABRT(x86seg *seg) +static inline int MEM_LOAD_ADDR_EA_W_NO_ABRT(x86seg *seg) { if ((seg == &_ds && codegen_flat_ds) || (seg == &_ss && codegen_flat_ss)) { @@ -5783,7 +5760,7 @@ static int MEM_LOAD_ADDR_EA_W_NO_ABRT(x86seg *seg) addbyte(0x8b); /*MOVL ECX, seg->base*/ addbyte(0x0c); addbyte(0x25); - addlong((uint32_t)&seg->base); + addlong((uint32_t)(uintptr_t)&seg->base); } else { @@ -5812,7 +5789,7 @@ static int MEM_LOAD_ADDR_EA_W_NO_ABRT(x86seg *seg) addbyte(0x8b); addbyte(0x34); addbyte(0xf5); - addlong((uint32_t)readlookup2); + addlong((uint32_t)(uintptr_t)readlookup2); } else { @@ -5824,7 +5801,7 @@ static int MEM_LOAD_ADDR_EA_W_NO_ABRT(x86seg *seg) addbyte(0x34); addbyte(0xf2); } - addbyte(0x75); /*JE slowpath*/ + addbyte(0x75); /*JNE slowpath*/ addbyte(3+2+4+2); addbyte(0x83); /*CMP ESI, -1*/ addbyte(0xf8 | REG_ESI); @@ -5840,7 +5817,7 @@ static int MEM_LOAD_ADDR_EA_W_NO_ABRT(x86seg *seg) /*slowpath:*/ load_param_1_reg_32(REG_ECX); load_param_2_reg_32(REG_EAX); - call_long(readmemwl); + call_long((uintptr_t)readmemwl); addbyte(0x89); /*MOV ECX, EAX*/ addbyte(0xc1); /*done:*/ @@ -5849,7 +5826,7 @@ static int MEM_LOAD_ADDR_EA_W_NO_ABRT(x86seg *seg) return REG_ECX; } -static int MEM_LOAD_ADDR_EA_L_NO_ABRT(x86seg *seg) +static inline int MEM_LOAD_ADDR_EA_L_NO_ABRT(x86seg *seg) { if ((seg == &_ds && codegen_flat_ds) || (seg == &_ss && codegen_flat_ss)) { @@ -5861,7 +5838,7 @@ static int MEM_LOAD_ADDR_EA_L_NO_ABRT(x86seg *seg) addbyte(0x8b); /*MOVL ECX, seg->base*/ addbyte(0x0c); addbyte(0x25); - addlong((uint32_t)&seg->base); + addlong((uint32_t)(uintptr_t)&seg->base); } else { @@ -5890,7 +5867,7 @@ static int MEM_LOAD_ADDR_EA_L_NO_ABRT(x86seg *seg) addbyte(0x8b); addbyte(0x34); addbyte(0xf5); - addlong((uint32_t)readlookup2); + addlong((uint32_t)(uintptr_t)readlookup2); } else { @@ -5902,14 +5879,14 @@ static int MEM_LOAD_ADDR_EA_L_NO_ABRT(x86seg *seg) addbyte(0x34); addbyte(0xf2); } - addbyte(0x54); /*JNE slowpath*/ + addbyte(0x75); /*JNE slowpath*/ addbyte(3+2+3+2); addbyte(0x83); /*CMP ESI, -1*/ addbyte(0xf8 | REG_ESI); addbyte(-1); addbyte(0x74); /*JE slowpath*/ addbyte(3+2); - addbyte(0x8b); /*MOV EAX,-3[RDI+RSI]*/ + addbyte(0x8b); /*MOV EAX,[RDI+RSI]*/ addbyte(0x04); addbyte(REG_EDI | (REG_ESI << 3)); addbyte(0xeb); /*JMP done*/ @@ -5917,7 +5894,7 @@ static int MEM_LOAD_ADDR_EA_L_NO_ABRT(x86seg *seg) /*slowpath:*/ load_param_1_reg_32(REG_ECX); load_param_2_reg_32(REG_EAX); - call_long(readmemll); + call_long((uintptr_t)readmemll); addbyte(0x89); /*MOV ECX, EAX*/ addbyte(0xc1); /*done:*/ @@ -5927,7 +5904,7 @@ static int MEM_LOAD_ADDR_EA_L_NO_ABRT(x86seg *seg) return REG_ECX; } -static void MEM_STORE_ADDR_EA_B_NO_ABRT(x86seg *seg, int host_reg) +static inline void MEM_STORE_ADDR_EA_B_NO_ABRT(x86seg *seg, int host_reg) { if (host_reg & 0x10) { @@ -5951,8 +5928,7 @@ static void MEM_STORE_ADDR_EA_B_NO_ABRT(x86seg *seg, int host_reg) addbyte(8); host_reg = 8; } - if (((seg == &_ds) && (cpu_cur_status & CPU_STATUS_FLATDS)) || - ((seg == &_ss) && (cpu_cur_status & CPU_STATUS_FLATSS))) + if ((seg == &_ds && codegen_flat_ds) || (seg == &_ss && codegen_flat_ss)) { addbyte(0x31); /*XOR EBX, EBX*/ addbyte(0xdb); @@ -5962,7 +5938,7 @@ static void MEM_STORE_ADDR_EA_B_NO_ABRT(x86seg *seg, int host_reg) addbyte(0x8b); /*MOVL EBX, seg->base*/ addbyte(0x1c); addbyte(0x25); - addlong((uint32_t)&seg->base); + addlong((uint32_t)(uintptr_t)&seg->base); } else { @@ -5988,7 +5964,7 @@ static void MEM_STORE_ADDR_EA_B_NO_ABRT(x86seg *seg, int host_reg) addbyte(0x8b); addbyte(0x34); addbyte(0xf5); - addlong((uint32_t)writelookup2); + addlong((uint32_t)(uintptr_t)writelookup2); } else { @@ -6024,13 +6000,12 @@ static void MEM_STORE_ADDR_EA_B_NO_ABRT(x86seg *seg, int host_reg) load_param_3_reg_32(host_reg); load_param_1_reg_32(REG_EBX); load_param_2_reg_32(REG_EAX); - call_long(writememb386l); + call_long((uintptr_t)writememb386l); /*done:*/ } -static void MEM_STORE_ADDR_EA_W_NO_ABRT(x86seg *seg, int host_reg) +static inline void MEM_STORE_ADDR_EA_W_NO_ABRT(x86seg *seg, int host_reg) { - if (((seg == &_ds) && (cpu_cur_status & CPU_STATUS_FLATDS)) || - ((seg == &_ss) && (cpu_cur_status & CPU_STATUS_FLATSS))) + if ((seg == &_ds && codegen_flat_ds) || (seg == &_ss && codegen_flat_ss)) { addbyte(0x31); /*XOR EBX, EBX*/ addbyte(0xdb); @@ -6040,7 +6015,7 @@ static void MEM_STORE_ADDR_EA_W_NO_ABRT(x86seg *seg, int host_reg) addbyte(0x8b); /*MOVL EBX, seg->base*/ addbyte(0x1c); addbyte(0x25); - addlong((uint32_t)&seg->base); + addlong((uint32_t)(uintptr_t)&seg->base); } else { @@ -6069,7 +6044,7 @@ static void MEM_STORE_ADDR_EA_W_NO_ABRT(x86seg *seg, int host_reg) addbyte(0x8b); addbyte(0x34); addbyte(0xf5); - addlong((uint32_t)writelookup2); + addlong((uint32_t)(uintptr_t)writelookup2); } else { @@ -6109,13 +6084,12 @@ static void MEM_STORE_ADDR_EA_W_NO_ABRT(x86seg *seg, int host_reg) load_param_3_reg_32(host_reg); load_param_1_reg_32(REG_EBX); load_param_2_reg_32(REG_EAX); - call_long(writememwl); + call_long((uintptr_t)writememwl); /*done:*/ } -static void MEM_STORE_ADDR_EA_L_NO_ABRT(x86seg *seg, int host_reg) +static inline void MEM_STORE_ADDR_EA_L_NO_ABRT(x86seg *seg, int host_reg) { - if (((seg == &_ds) && (cpu_cur_status & CPU_STATUS_FLATDS)) || - ((seg == &_ss) && (cpu_cur_status & CPU_STATUS_FLATSS))) + if ((seg == &_ds && codegen_flat_ds) || (seg == &_ss && codegen_flat_ss)) { addbyte(0x31); /*XOR EBX, EBX*/ addbyte(0xdb); @@ -6125,7 +6099,7 @@ static void MEM_STORE_ADDR_EA_L_NO_ABRT(x86seg *seg, int host_reg) addbyte(0x8b); /*MOVL EBX, seg->base*/ addbyte(0x1c); addbyte(0x25); - addlong((uint32_t)&seg->base); + addlong((uint32_t)(uintptr_t)&seg->base); } else { @@ -6154,7 +6128,7 @@ static void MEM_STORE_ADDR_EA_L_NO_ABRT(x86seg *seg, int host_reg) addbyte(0x8b); addbyte(0x34); addbyte(0xf5); - addlong((uint32_t)writelookup2); + addlong((uint32_t)(uintptr_t)writelookup2); } else { @@ -6192,18 +6166,18 @@ static void MEM_STORE_ADDR_EA_L_NO_ABRT(x86seg *seg, int host_reg) load_param_3_reg_32(host_reg); load_param_1_reg_32(REG_EBX); load_param_2_reg_32(REG_EAX); - call_long(writememll); + call_long((uintptr_t)writememll); /*done:*/ } -static void LOAD_SEG(int host_reg, void *seg) +static inline void LOAD_SEG(int host_reg, void *seg) { load_param_2_64(&codeblock[block_current], (uint64_t)seg); load_param_1_reg_32(host_reg); - CALL_FUNC(loadseg); + CALL_FUNC((uintptr_t)loadseg); addbyte(0x80); /*CMP abrt, 0*/ addbyte(0x7d); - addbyte(cpu_state_offset(abrt)); + addbyte((uint8_t)cpu_state_offset(abrt)); addbyte(0); addbyte(0x0f); /*JNE end*/ addbyte(0x85); diff --git a/src/CPU/codegen_ops_x86.h b/src/CPU/codegen_ops_x86.h index 5251884b7..3af481791 100644 --- a/src/CPU/codegen_ops_x86.h +++ b/src/CPU/codegen_ops_x86.h @@ -8,7 +8,7 @@ #define HOST_REG_END 4 #define HOST_REG_XMM_START 0 #define HOST_REG_XMM_END 7 -static __inline int find_host_reg() +static inline int find_host_reg() { int c; for (c = HOST_REG_START; c < HOST_REG_END; c++) @@ -21,7 +21,7 @@ static __inline int find_host_reg() fatal("Out of host regs!\n"); return c; } -static __inline int find_host_xmm_reg() +static inline int find_host_xmm_reg() { int c; for (c = HOST_REG_XMM_START; c < HOST_REG_XMM_END; c++) @@ -35,14 +35,15 @@ static __inline int find_host_xmm_reg() return c; } -static void STORE_IMM_ADDR_B(uintptr_t addr, uint8_t val) +#if 0 +static inline void STORE_IMM_ADDR_B(uintptr_t addr, uint8_t val) { addbyte(0xC6); /*MOVB [addr],val*/ addbyte(0x05); addlong(addr); addbyte(val); } -static void STORE_IMM_ADDR_W(uintptr_t addr, uint16_t val) +static inline void STORE_IMM_ADDR_W(uintptr_t addr, uint16_t val) { addbyte(0x66); /*MOVW [addr],val*/ addbyte(0xC7); @@ -50,7 +51,8 @@ static void STORE_IMM_ADDR_W(uintptr_t addr, uint16_t val) addlong(addr); addword(val); } -static void STORE_IMM_ADDR_L(uintptr_t addr, uint32_t val) +#endif +static inline void STORE_IMM_ADDR_L(uintptr_t addr, uint32_t val) { if (addr >= (uintptr_t)&cpu_state && addr < ((uintptr_t)&cpu_state)+0x100) { @@ -68,33 +70,33 @@ static void STORE_IMM_ADDR_L(uintptr_t addr, uint32_t val) } } -static void STORE_IMM_REG_B(int reg, uint8_t val) +static inline void STORE_IMM_REG_B(int reg, uint8_t val) { addbyte(0xC6); /*MOVB [addr],val*/ addbyte(0x45); if (reg & 4) - addbyte(cpu_state_offset(regs[reg & 3].b.h)); + addbyte((uint8_t)cpu_state_offset(regs[reg & 3].b.h)); else - addbyte(cpu_state_offset(regs[reg & 3].b.l)); + addbyte((uint8_t)cpu_state_offset(regs[reg & 3].b.l)); addbyte(val); } -static void STORE_IMM_REG_W(int reg, uint16_t val) +static inline void STORE_IMM_REG_W(int reg, uint16_t val) { addbyte(0x66); /*MOVW [addr],val*/ addbyte(0xC7); addbyte(0x45); - addbyte(cpu_state_offset(regs[reg & 7].w)); + addbyte((uint8_t)cpu_state_offset(regs[reg & 7].w)); addword(val); } -static void STORE_IMM_REG_L(int reg, uint32_t val) +static inline void STORE_IMM_REG_L(int reg, uint32_t val) { addbyte(0xC7); /*MOVL [addr],val*/ addbyte(0x45); - addbyte(cpu_state_offset(regs[reg & 7].l)); + addbyte((uint8_t)cpu_state_offset(regs[reg & 7].l)); addlong(val); } -static int LOAD_REG_B(int reg) +static inline int LOAD_REG_B(int reg) { int host_reg = find_host_reg(); host_reg_mapping[host_reg] = reg; @@ -103,13 +105,13 @@ static int LOAD_REG_B(int reg) addbyte(0xb6); addbyte(0x45 | (host_reg << 3)); if (reg & 4) - addbyte(cpu_state_offset(regs[reg & 3].b.h)); + addbyte((uint8_t)cpu_state_offset(regs[reg & 3].b.h)); else - addbyte(cpu_state_offset(regs[reg & 3].b.l)); + addbyte((uint8_t)cpu_state_offset(regs[reg & 3].b.l)); return host_reg; } -static int LOAD_REG_W(int reg) +static inline int LOAD_REG_W(int reg) { int host_reg = find_host_reg(); host_reg_mapping[host_reg] = reg; @@ -117,23 +119,23 @@ static int LOAD_REG_W(int reg) addbyte(0x0f); /*MOVZX W[reg],host_reg*/ addbyte(0xb7); addbyte(0x45 | (host_reg << 3)); - addbyte(cpu_state_offset(regs[reg & 7].w)); + addbyte((uint8_t)cpu_state_offset(regs[reg & 7].w)); return host_reg; } -static int LOAD_REG_L(int reg) +static inline int LOAD_REG_L(int reg) { int host_reg = find_host_reg(); host_reg_mapping[host_reg] = reg; addbyte(0x8b); /*MOVL host_reg,[reg]*/ addbyte(0x45 | (host_reg << 3)); - addbyte(cpu_state_offset(regs[reg & 7].l)); + addbyte((uint8_t)cpu_state_offset(regs[reg & 7].l)); return host_reg; } -static int LOAD_VAR_W(uintptr_t addr) +static inline int LOAD_VAR_W(uintptr_t addr) { int host_reg = find_host_reg(); host_reg_mapping[host_reg] = 0; @@ -145,7 +147,7 @@ static int LOAD_VAR_W(uintptr_t addr) return host_reg; } -static int LOAD_VAR_WL(uintptr_t addr) +static inline int LOAD_VAR_WL(uintptr_t addr) { int host_reg = find_host_reg(); host_reg_mapping[host_reg] = 0; @@ -157,7 +159,7 @@ static int LOAD_VAR_WL(uintptr_t addr) return host_reg; } -static int LOAD_VAR_L(uintptr_t addr) +static inline int LOAD_VAR_L(uintptr_t addr) { int host_reg = find_host_reg(); host_reg_mapping[host_reg] = 0; @@ -169,7 +171,7 @@ static int LOAD_VAR_L(uintptr_t addr) return host_reg; } -static int LOAD_REG_IMM(uint32_t imm) +static inline int LOAD_REG_IMM(uint32_t imm) { int host_reg = find_host_reg(); host_reg_mapping[host_reg] = 0; @@ -181,7 +183,7 @@ static int LOAD_REG_IMM(uint32_t imm) return host_reg; } -static int LOAD_HOST_REG(int host_reg) +static inline int LOAD_HOST_REG(int host_reg) { int new_host_reg = find_host_reg(); host_reg_mapping[new_host_reg] = 0; @@ -192,64 +194,64 @@ static int LOAD_HOST_REG(int host_reg) return new_host_reg; } -static void STORE_REG_B_RELEASE(int host_reg) +static inline void STORE_REG_B_RELEASE(int host_reg) { addbyte(0x88); /*MOVB [reg],host_reg*/ addbyte(0x45 | (host_reg << 3)); if (host_reg_mapping[host_reg] & 4) - addbyte(cpu_state_offset(regs[host_reg_mapping[host_reg] & 3].b.h)); + addbyte((uint8_t)cpu_state_offset(regs[host_reg_mapping[host_reg] & 3].b.h)); else - addbyte(cpu_state_offset(regs[host_reg_mapping[host_reg] & 3].b.l)); + addbyte((uint8_t)cpu_state_offset(regs[host_reg_mapping[host_reg] & 3].b.l)); host_reg_mapping[host_reg] = -1; } -static void STORE_REG_W_RELEASE(int host_reg) +static inline void STORE_REG_W_RELEASE(int host_reg) { addbyte(0x66); /*MOVW [reg],host_reg*/ addbyte(0x89); addbyte(0x45 | (host_reg << 3)); - addbyte(cpu_state_offset(regs[host_reg_mapping[host_reg]].w)); + addbyte((uint8_t)cpu_state_offset(regs[host_reg_mapping[host_reg]].w)); host_reg_mapping[host_reg] = -1; } -static void STORE_REG_L_RELEASE(int host_reg) +static inline void STORE_REG_L_RELEASE(int host_reg) { addbyte(0x89); /*MOVL [reg],host_reg*/ addbyte(0x45 | (host_reg << 3)); - addbyte(cpu_state_offset(regs[host_reg_mapping[host_reg]].l)); + addbyte((uint8_t)cpu_state_offset(regs[host_reg_mapping[host_reg]].l)); host_reg_mapping[host_reg] = -1; } -static void STORE_REG_TARGET_B_RELEASE(int host_reg, int guest_reg) +static inline void STORE_REG_TARGET_B_RELEASE(int host_reg, int guest_reg) { addbyte(0x88); /*MOVB [guest_reg],host_reg*/ addbyte(0x45 | (host_reg << 3)); if (guest_reg & 4) - addbyte(cpu_state_offset(regs[guest_reg & 3].b.h)); + addbyte((uint8_t)cpu_state_offset(regs[guest_reg & 3].b.h)); else - addbyte(cpu_state_offset(regs[guest_reg & 3].b.l)); + addbyte((uint8_t)cpu_state_offset(regs[guest_reg & 3].b.l)); host_reg_mapping[host_reg] = -1; } -static void STORE_REG_TARGET_W_RELEASE(int host_reg, int guest_reg) +static inline void STORE_REG_TARGET_W_RELEASE(int host_reg, int guest_reg) { addbyte(0x66); /*MOVW [guest_reg],host_reg*/ addbyte(0x89); addbyte(0x45 | (host_reg << 3)); - addbyte(cpu_state_offset(regs[guest_reg & 7].w)); + addbyte((uint8_t)cpu_state_offset(regs[guest_reg & 7].w)); host_reg_mapping[host_reg] = -1; } -static void STORE_REG_TARGET_L_RELEASE(int host_reg, int guest_reg) +static inline void STORE_REG_TARGET_L_RELEASE(int host_reg, int guest_reg) { addbyte(0x89); /*MOVL [guest_reg],host_reg*/ addbyte(0x45 | (host_reg << 3)); - addbyte(cpu_state_offset(regs[guest_reg & 7].l)); + addbyte((uint8_t)cpu_state_offset(regs[guest_reg & 7].l)); host_reg_mapping[host_reg] = -1; } -static void RELEASE_REG(int host_reg) +static inline void RELEASE_REG(int host_reg) { host_reg_mapping[host_reg] = -1; } -static void STORE_HOST_REG_ADDR_W(uintptr_t addr, int host_reg) +static inline void STORE_HOST_REG_ADDR_W(uintptr_t addr, int host_reg) { if (addr >= (uintptr_t)&cpu_state && addr < ((uintptr_t)&cpu_state)+0x100) { @@ -266,7 +268,7 @@ static void STORE_HOST_REG_ADDR_W(uintptr_t addr, int host_reg) addlong(addr); } } -static void STORE_HOST_REG_ADDR(uintptr_t addr, int host_reg) +static inline void STORE_HOST_REG_ADDR(uintptr_t addr, int host_reg) { if (addr >= (uintptr_t)&cpu_state && addr < ((uintptr_t)&cpu_state)+0x100) { @@ -284,29 +286,29 @@ static void STORE_HOST_REG_ADDR(uintptr_t addr, int host_reg) #define STORE_HOST_REG_ADDR_BL STORE_HOST_REG_ADDR #define STORE_HOST_REG_ADDR_WL STORE_HOST_REG_ADDR -static void ADD_HOST_REG_B(int dst_reg, int src_reg) +static inline void ADD_HOST_REG_B(int dst_reg, int src_reg) { addbyte(0x00); /*ADDB dst_reg, src_reg*/ addbyte(0xc0 | dst_reg | (src_reg << 3)); } -static void ADD_HOST_REG_W(int dst_reg, int src_reg) +static inline void ADD_HOST_REG_W(int dst_reg, int src_reg) { addbyte(0x66); /*ADDW dst_reg, src_reg*/ addbyte(0x01); addbyte(0xc0 | dst_reg | (src_reg << 3)); } -static void ADD_HOST_REG_L(int dst_reg, int src_reg) +static inline void ADD_HOST_REG_L(int dst_reg, int src_reg) { addbyte(0x01); /*ADDL dst_reg, src_reg*/ addbyte(0xc0 | dst_reg | (src_reg << 3)); } -static void ADD_HOST_REG_IMM_B(int host_reg, uint8_t imm) +static inline void ADD_HOST_REG_IMM_B(int host_reg, uint8_t imm) { addbyte(0x80); /*ADDB host_reg, imm*/ addbyte(0xC0 | host_reg); addbyte(imm); } -static void ADD_HOST_REG_IMM_W(int host_reg, uint16_t imm) +static inline void ADD_HOST_REG_IMM_W(int host_reg, uint16_t imm) { if (imm < 0x80 || imm >= 0xff80) { @@ -323,7 +325,7 @@ static void ADD_HOST_REG_IMM_W(int host_reg, uint16_t imm) addword(imm); } } -static void ADD_HOST_REG_IMM(int host_reg, uint32_t imm) +static inline void ADD_HOST_REG_IMM(int host_reg, uint32_t imm) { if (imm < 0x80 || imm >= 0xffffff80) { @@ -341,12 +343,12 @@ static void ADD_HOST_REG_IMM(int host_reg, uint32_t imm) #define AND_HOST_REG_B AND_HOST_REG_L #define AND_HOST_REG_W AND_HOST_REG_L -static void AND_HOST_REG_L(int dst_reg, int src_reg) +static inline void AND_HOST_REG_L(int dst_reg, int src_reg) { addbyte(0x21); /*ANDL dst_reg, src_reg*/ addbyte(0xc0 | dst_reg | (src_reg << 3)); } -static void AND_HOST_REG_IMM(int host_reg, uint32_t imm) +static inline void AND_HOST_REG_IMM(int host_reg, uint32_t imm) { if (imm < 0x80 || imm >= 0xffffff80) { @@ -361,25 +363,25 @@ static void AND_HOST_REG_IMM(int host_reg, uint32_t imm) addlong(imm); } } -static int TEST_HOST_REG_B(int dst_reg, int src_reg) +static inline int TEST_HOST_REG_B(int dst_reg, int src_reg) { AND_HOST_REG_B(dst_reg, src_reg); return dst_reg; } -static int TEST_HOST_REG_W(int dst_reg, int src_reg) +static inline int TEST_HOST_REG_W(int dst_reg, int src_reg) { AND_HOST_REG_W(dst_reg, src_reg); return dst_reg; } -static int TEST_HOST_REG_L(int dst_reg, int src_reg) +static inline int TEST_HOST_REG_L(int dst_reg, int src_reg) { AND_HOST_REG_L(dst_reg, src_reg); return dst_reg; } -static int TEST_HOST_REG_IMM(int host_reg, uint32_t imm) +static inline int TEST_HOST_REG_IMM(int host_reg, uint32_t imm) { AND_HOST_REG_IMM(host_reg, imm); @@ -388,12 +390,12 @@ static int TEST_HOST_REG_IMM(int host_reg, uint32_t imm) #define OR_HOST_REG_B OR_HOST_REG_L #define OR_HOST_REG_W OR_HOST_REG_L -static void OR_HOST_REG_L(int dst_reg, int src_reg) +static inline void OR_HOST_REG_L(int dst_reg, int src_reg) { addbyte(0x09); /*ORL dst_reg, src_reg*/ addbyte(0xc0 | dst_reg | (src_reg << 3)); } -static void OR_HOST_REG_IMM(int host_reg, uint32_t imm) +static inline void OR_HOST_REG_IMM(int host_reg, uint32_t imm) { if (imm < 0x80 || imm >= 0xffffff80) { @@ -409,46 +411,46 @@ static void OR_HOST_REG_IMM(int host_reg, uint32_t imm) } } -static void NEG_HOST_REG_B(int reg) +static inline void NEG_HOST_REG_B(int reg) { addbyte(0xf6); addbyte(0xd8 | reg); } -static void NEG_HOST_REG_W(int reg) +static inline void NEG_HOST_REG_W(int reg) { addbyte(0x66); addbyte(0xf7); addbyte(0xd8 | reg); } -static void NEG_HOST_REG_L(int reg) +static inline void NEG_HOST_REG_L(int reg) { addbyte(0xf7); addbyte(0xd8 | reg); } -static void SUB_HOST_REG_B(int dst_reg, int src_reg) +static inline void SUB_HOST_REG_B(int dst_reg, int src_reg) { addbyte(0x28); /*SUBB dst_reg, src_reg*/ addbyte(0xc0 | dst_reg | (src_reg << 3)); } -static void SUB_HOST_REG_W(int dst_reg, int src_reg) +static inline void SUB_HOST_REG_W(int dst_reg, int src_reg) { addbyte(0x66); /*SUBW dst_reg, src_reg*/ addbyte(0x29); addbyte(0xc0 | dst_reg | (src_reg << 3)); } -static void SUB_HOST_REG_L(int dst_reg, int src_reg) +static inline void SUB_HOST_REG_L(int dst_reg, int src_reg) { addbyte(0x29); /*SUBL dst_reg, src_reg*/ addbyte(0xc0 | dst_reg | (src_reg << 3)); } -static void SUB_HOST_REG_IMM_B(int host_reg, uint8_t imm) +static inline void SUB_HOST_REG_IMM_B(int host_reg, uint8_t imm) { addbyte(0x80); /*SUBB host_reg, imm*/ addbyte(0xE8 | host_reg); addbyte(imm); } -static void SUB_HOST_REG_IMM_W(int host_reg, uint16_t imm) +static inline void SUB_HOST_REG_IMM_W(int host_reg, uint16_t imm) { if (imm < 0x80 || imm >= 0xff80) { @@ -465,7 +467,7 @@ static void SUB_HOST_REG_IMM_W(int host_reg, uint16_t imm) addword(imm); } } -static void SUB_HOST_REG_IMM(int host_reg, uint32_t imm) +static inline void SUB_HOST_REG_IMM(int host_reg, uint32_t imm) { if (imm < 0x80 || imm >= 0xffffff80) { @@ -481,37 +483,37 @@ static void SUB_HOST_REG_IMM(int host_reg, uint32_t imm) } } -static int CMP_HOST_REG_B(int dst_reg, int src_reg) +static inline int CMP_HOST_REG_B(int dst_reg, int src_reg) { SUB_HOST_REG_B(dst_reg, src_reg); return dst_reg; } -static int CMP_HOST_REG_W(int dst_reg, int src_reg) +static inline int CMP_HOST_REG_W(int dst_reg, int src_reg) { SUB_HOST_REG_W(dst_reg, src_reg); return dst_reg; } -static int CMP_HOST_REG_L(int dst_reg, int src_reg) +static inline int CMP_HOST_REG_L(int dst_reg, int src_reg) { SUB_HOST_REG_L(dst_reg, src_reg); return dst_reg; } -static int CMP_HOST_REG_IMM_B(int host_reg, uint8_t imm) +static inline int CMP_HOST_REG_IMM_B(int host_reg, uint8_t imm) { SUB_HOST_REG_IMM_B(host_reg, imm); return host_reg; } -static int CMP_HOST_REG_IMM_W(int host_reg, uint16_t imm) +static inline int CMP_HOST_REG_IMM_W(int host_reg, uint16_t imm) { SUB_HOST_REG_IMM_W(host_reg, imm); return host_reg; } -static int CMP_HOST_REG_IMM_L(int host_reg, uint32_t imm) +static inline int CMP_HOST_REG_IMM_L(int host_reg, uint32_t imm) { SUB_HOST_REG_IMM(host_reg, imm); @@ -520,12 +522,12 @@ static int CMP_HOST_REG_IMM_L(int host_reg, uint32_t imm) #define XOR_HOST_REG_B XOR_HOST_REG_L #define XOR_HOST_REG_W XOR_HOST_REG_L -static void XOR_HOST_REG_L(int dst_reg, int src_reg) +static inline void XOR_HOST_REG_L(int dst_reg, int src_reg) { addbyte(0x31); /*XORL dst_reg, src_reg*/ addbyte(0xc0 | dst_reg | (src_reg << 3)); } -static void XOR_HOST_REG_IMM(int host_reg, uint32_t imm) +static inline void XOR_HOST_REG_IMM(int host_reg, uint32_t imm) { if (imm < 0x80 || imm >= 0xffffff80) { @@ -541,64 +543,64 @@ static void XOR_HOST_REG_IMM(int host_reg, uint32_t imm) } } -static void CALL_FUNC(void *dest) +static inline void CALL_FUNC(uintptr_t dest) { addbyte(0xE8); /*CALL*/ - addlong(((uint8_t *)dest - (uint8_t *)(&codeblock[block_current].data[block_pos + 4]))); + addlong(((uintptr_t)dest - (uintptr_t)(&codeblock[block_current].data[block_pos + 4]))); } -static void SHL_B_IMM(int reg, int count) +static inline void SHL_B_IMM(int reg, int count) { addbyte(0xc0); /*SHL reg, count*/ addbyte(0xc0 | reg | 0x20); addbyte(count); } -static void SHL_W_IMM(int reg, int count) +static inline void SHL_W_IMM(int reg, int count) { addbyte(0x66); /*SHL reg, count*/ addbyte(0xc1); addbyte(0xc0 | reg | 0x20); addbyte(count); } -static void SHL_L_IMM(int reg, int count) +static inline void SHL_L_IMM(int reg, int count) { addbyte(0xc1); /*SHL reg, count*/ addbyte(0xc0 | reg | 0x20); addbyte(count); } -static void SHR_B_IMM(int reg, int count) +static inline void SHR_B_IMM(int reg, int count) { addbyte(0xc0); /*SHR reg, count*/ addbyte(0xc0 | reg | 0x28); addbyte(count); } -static void SHR_W_IMM(int reg, int count) +static inline void SHR_W_IMM(int reg, int count) { addbyte(0x66); /*SHR reg, count*/ addbyte(0xc1); addbyte(0xc0 | reg | 0x28); addbyte(count); } -static void SHR_L_IMM(int reg, int count) +static inline void SHR_L_IMM(int reg, int count) { addbyte(0xc1); /*SHR reg, count*/ addbyte(0xc0 | reg | 0x28); addbyte(count); } -static void SAR_B_IMM(int reg, int count) +static inline void SAR_B_IMM(int reg, int count) { addbyte(0xc0); /*SAR reg, count*/ addbyte(0xc0 | reg | 0x38); addbyte(count); } -static void SAR_W_IMM(int reg, int count) +static inline void SAR_W_IMM(int reg, int count) { addbyte(0x66); /*SAR reg, count*/ addbyte(0xc1); addbyte(0xc0 | reg | 0x38); addbyte(count); } -static void SAR_L_IMM(int reg, int count) +static inline void SAR_L_IMM(int reg, int count) { addbyte(0xc1); /*SAR reg, count*/ addbyte(0xc0 | reg | 0x38); @@ -606,7 +608,7 @@ static void SAR_L_IMM(int reg, int count) } -static void CHECK_SEG_READ(x86seg *seg) +static inline void CHECK_SEG_READ(x86seg *seg) { /*Segments always valid in real/V86 mode*/ if (!(cr0 & 1) || (eflags & VM_FLAG)) @@ -629,7 +631,7 @@ static void CHECK_SEG_READ(x86seg *seg) seg->checked = 1; } -static void CHECK_SEG_WRITE(x86seg *seg) +static inline void CHECK_SEG_WRITE(x86seg *seg) { /*Segments always valid in real/V86 mode*/ if (!(cr0 & 1) || (eflags & VM_FLAG)) @@ -652,7 +654,7 @@ static void CHECK_SEG_WRITE(x86seg *seg) seg->checked = 1; } -static void CHECK_SEG_LIMITS(x86seg *seg, int end_offset) +static inline void CHECK_SEG_LIMITS(x86seg *seg, int end_offset) { if ((seg == &_ds && codegen_flat_ds) || (seg == &_ss && codegen_flat_ss)) return; @@ -680,10 +682,9 @@ static void CHECK_SEG_LIMITS(x86seg *seg, int end_offset) } } -static void MEM_LOAD_ADDR_EA_B(x86seg *seg) +static inline void MEM_LOAD_ADDR_EA_B(x86seg *seg) { - if (((seg == &_ds) && (cpu_cur_status & CPU_STATUS_FLATDS)) || - ((seg == &_ss) && (cpu_cur_status & CPU_STATUS_FLATSS))) + if ((seg == &_ds && codegen_flat_ds) || (seg == &_ss && codegen_flat_ss)) { addbyte(0x31); /*XOR EDX, EDX*/ addbyte(0xd2); @@ -699,7 +700,7 @@ static void MEM_LOAD_ADDR_EA_B(x86seg *seg) host_reg_mapping[0] = 8; } -static int MEM_LOAD_ADDR_EA_B_NO_ABRT(x86seg *seg) +static inline int MEM_LOAD_ADDR_EA_B_NO_ABRT(x86seg *seg) { if ((seg == &_ds && codegen_flat_ds) || (seg == &_ss && codegen_flat_ss)) { @@ -719,7 +720,7 @@ static int MEM_LOAD_ADDR_EA_B_NO_ABRT(x86seg *seg) return REG_ECX; } -static void MEM_LOAD_ADDR_EA_W(x86seg *seg) +static inline void MEM_LOAD_ADDR_EA_W(x86seg *seg) { if ((seg == &_ds && codegen_flat_ds) || (seg == &_ss && codegen_flat_ss)) { @@ -737,7 +738,7 @@ static void MEM_LOAD_ADDR_EA_W(x86seg *seg) host_reg_mapping[0] = 8; } -static void MEM_LOAD_ADDR_EA_W_OFFSET(x86seg *seg, int offset) +static inline void MEM_LOAD_ADDR_EA_W_OFFSET(x86seg *seg, int offset) { if ((seg == &_ds && codegen_flat_ds) || (seg == &_ss && codegen_flat_ss)) { @@ -758,7 +759,7 @@ static void MEM_LOAD_ADDR_EA_W_OFFSET(x86seg *seg, int offset) host_reg_mapping[0] = 8; } -static int MEM_LOAD_ADDR_EA_W_NO_ABRT(x86seg *seg) +static inline int MEM_LOAD_ADDR_EA_W_NO_ABRT(x86seg *seg) { if ((seg == &_ds && codegen_flat_ds) || (seg == &_ss && codegen_flat_ss)) { @@ -778,7 +779,7 @@ static int MEM_LOAD_ADDR_EA_W_NO_ABRT(x86seg *seg) return REG_ECX; } -static void MEM_LOAD_ADDR_EA_L(x86seg *seg) +static inline void MEM_LOAD_ADDR_EA_L(x86seg *seg) { if ((seg == &_ds && codegen_flat_ds) || (seg == &_ss && codegen_flat_ss)) { @@ -797,7 +798,7 @@ static void MEM_LOAD_ADDR_EA_L(x86seg *seg) host_reg_mapping[0] = 8; } -static int MEM_LOAD_ADDR_EA_L_NO_ABRT(x86seg *seg) +static inline int MEM_LOAD_ADDR_EA_L_NO_ABRT(x86seg *seg) { if ((seg == &_ds && codegen_flat_ds) || (seg == &_ss && codegen_flat_ss)) { @@ -818,7 +819,7 @@ static int MEM_LOAD_ADDR_EA_L_NO_ABRT(x86seg *seg) return REG_ECX; } -static void MEM_LOAD_ADDR_EA_Q(x86seg *seg) +static inline void MEM_LOAD_ADDR_EA_Q(x86seg *seg) { if ((seg == &_ds && codegen_flat_ds) || (seg == &_ss && codegen_flat_ss)) { @@ -837,26 +838,26 @@ static void MEM_LOAD_ADDR_EA_Q(x86seg *seg) host_reg_mapping[0] = 8; } -static void MEM_LOAD_ADDR_IMM_B(x86seg *seg, uint32_t addr) +static inline void MEM_LOAD_ADDR_IMM_B(x86seg *seg, uint32_t addr) { addbyte(0xb8); /*MOV EAX, addr*/ addlong(addr); MEM_LOAD_ADDR_EA_B(seg); } -static void MEM_LOAD_ADDR_IMM_W(x86seg *seg, uint32_t addr) +static inline void MEM_LOAD_ADDR_IMM_W(x86seg *seg, uint32_t addr) { addbyte(0xb8); /*MOV EAX, addr*/ addlong(addr); MEM_LOAD_ADDR_EA_W(seg); } -static void MEM_LOAD_ADDR_IMM_L(x86seg *seg, uint32_t addr) +static inline void MEM_LOAD_ADDR_IMM_L(x86seg *seg, uint32_t addr) { addbyte(0xb8); /*MOV EAX, addr*/ addlong(addr); MEM_LOAD_ADDR_EA_L(seg); } -static void MEM_STORE_ADDR_EA_B(x86seg *seg, int host_reg) +static inline void MEM_STORE_ADDR_EA_B(x86seg *seg, int host_reg) { if ((seg == &_ds && codegen_flat_ds) || (seg == &_ss && codegen_flat_ss)) { @@ -877,7 +878,7 @@ static void MEM_STORE_ADDR_EA_B(x86seg *seg, int host_reg) addbyte(0xe8); /*CALL mem_store_addr_ea_b*/ addlong(mem_store_addr_ea_b - (uint32_t)(&codeblock[block_current].data[block_pos + 4])); } -static void MEM_STORE_ADDR_EA_B_NO_ABRT(x86seg *seg, int host_reg) +static inline void MEM_STORE_ADDR_EA_B_NO_ABRT(x86seg *seg, int host_reg) { if ((seg == &_ds && codegen_flat_ds) || (seg == &_ss && codegen_flat_ss)) { @@ -898,7 +899,7 @@ static void MEM_STORE_ADDR_EA_B_NO_ABRT(x86seg *seg, int host_reg) addbyte(0xe8); /*CALL mem_store_addr_ea_b_no_abrt*/ addlong(mem_store_addr_ea_b_no_abrt - (uint32_t)(&codeblock[block_current].data[block_pos + 4])); } -static void MEM_STORE_ADDR_EA_W(x86seg *seg, int host_reg) +static inline void MEM_STORE_ADDR_EA_W(x86seg *seg, int host_reg) { if ((seg == &_ds && codegen_flat_ds) || (seg == &_ss && codegen_flat_ss)) { @@ -919,7 +920,7 @@ static void MEM_STORE_ADDR_EA_W(x86seg *seg, int host_reg) addbyte(0xe8); /*CALL mem_store_addr_ea_w*/ addlong(mem_store_addr_ea_w - (uint32_t)(&codeblock[block_current].data[block_pos + 4])); } -static void MEM_STORE_ADDR_EA_W_NO_ABRT(x86seg *seg, int host_reg) +static inline void MEM_STORE_ADDR_EA_W_NO_ABRT(x86seg *seg, int host_reg) { if ((seg == &_ds && codegen_flat_ds) || (seg == &_ss && codegen_flat_ss)) { @@ -940,7 +941,7 @@ static void MEM_STORE_ADDR_EA_W_NO_ABRT(x86seg *seg, int host_reg) addbyte(0xe8); /*CALL mem_store_addr_ea_w_no_abrt*/ addlong(mem_store_addr_ea_w_no_abrt - (uint32_t)(&codeblock[block_current].data[block_pos + 4])); } -static void MEM_STORE_ADDR_EA_L(x86seg *seg, int host_reg) +static inline void MEM_STORE_ADDR_EA_L(x86seg *seg, int host_reg) { if ((seg == &_ds && codegen_flat_ds) || (seg == &_ss && codegen_flat_ss)) { @@ -961,7 +962,7 @@ static void MEM_STORE_ADDR_EA_L(x86seg *seg, int host_reg) addbyte(0xe8); /*CALL mem_store_addr_ea_l*/ addlong(mem_store_addr_ea_l - (uint32_t)(&codeblock[block_current].data[block_pos + 4])); } -static void MEM_STORE_ADDR_EA_L_NO_ABRT(x86seg *seg, int host_reg) +static inline void MEM_STORE_ADDR_EA_L_NO_ABRT(x86seg *seg, int host_reg) { if ((seg == &_ds && codegen_flat_ds) || (seg == &_ss && codegen_flat_ss)) { @@ -982,7 +983,7 @@ static void MEM_STORE_ADDR_EA_L_NO_ABRT(x86seg *seg, int host_reg) addbyte(0xe8); /*CALL mem_store_addr_ea_l_no_abrt*/ addlong(mem_store_addr_ea_l_no_abrt - (uint32_t)(&codeblock[block_current].data[block_pos + 4])); } -static void MEM_STORE_ADDR_EA_Q(x86seg *seg, int host_reg, int host_reg2) +static inline void MEM_STORE_ADDR_EA_Q(x86seg *seg, int host_reg, int host_reg2) { if (host_reg != REG_EBX) { @@ -1009,19 +1010,19 @@ static void MEM_STORE_ADDR_EA_Q(x86seg *seg, int host_reg, int host_reg2) addlong(mem_store_addr_ea_q - (uint32_t)(&codeblock[block_current].data[block_pos + 4])); } -static void MEM_STORE_ADDR_IMM_B(x86seg *seg, uint32_t addr, int host_reg) +static inline void MEM_STORE_ADDR_IMM_B(x86seg *seg, uint32_t addr, int host_reg) { addbyte(0xb8); /*MOV EAX, addr*/ addlong(addr); MEM_STORE_ADDR_EA_B(seg, host_reg); } -static void MEM_STORE_ADDR_IMM_L(x86seg *seg, uint32_t addr, int host_reg) +static inline void MEM_STORE_ADDR_IMM_L(x86seg *seg, uint32_t addr, int host_reg) { addbyte(0xb8); /*MOV EAX, addr*/ addlong(addr); MEM_STORE_ADDR_EA_L(seg, host_reg); } -static void MEM_STORE_ADDR_IMM_W(x86seg *seg, uint32_t addr, int host_reg) +static inline void MEM_STORE_ADDR_IMM_W(x86seg *seg, uint32_t addr, int host_reg) { addbyte(0xb8); /*MOV EAX, addr*/ addlong(addr); @@ -1029,10 +1030,9 @@ static void MEM_STORE_ADDR_IMM_W(x86seg *seg, uint32_t addr, int host_reg) } -static x86seg *FETCH_EA_16(x86seg *op_ea_seg, uint32_t fetchdat, int op_ssegs, uint32_t *op_pc) +static inline x86seg *FETCH_EA_16(x86seg *op_ea_seg, uint32_t fetchdat, int op_ssegs, uint32_t *op_pc) { int mod = (fetchdat >> 6) & 3; - int reg = (fetchdat >> 3) & 7; int rm = fetchdat & 7; if (!mod && rm == 6) { @@ -1092,11 +1092,10 @@ static x86seg *FETCH_EA_16(x86seg *op_ea_seg, uint32_t fetchdat, int op_ssegs, u return op_ea_seg; } -static x86seg *FETCH_EA_32(x86seg *op_ea_seg, uint32_t fetchdat, int op_ssegs, uint32_t *op_pc, int stack_offset) +static inline x86seg *FETCH_EA_32(x86seg *op_ea_seg, uint32_t fetchdat, int op_ssegs, uint32_t *op_pc, int stack_offset) { uint32_t new_eaaddr; int mod = (fetchdat >> 6) & 3; - int reg = (fetchdat >> 3) & 7; int rm = fetchdat & 7; if (rm == 4) @@ -1118,13 +1117,13 @@ static x86seg *FETCH_EA_32(x86seg *op_ea_seg, uint32_t fetchdat, int op_ssegs, u { addbyte(0x8b); /*MOVL EAX, regs[sib&7].l*/ addbyte(0x45); - addbyte(cpu_state_offset(regs[sib & 7].l)); + addbyte((uint8_t)cpu_state_offset(regs[sib & 7].l)); } break; case 1: addbyte(0x8b); /*MOVL EAX, regs[sib&7].l*/ addbyte(0x45); - addbyte(cpu_state_offset(regs[sib & 7].l)); + addbyte((uint8_t)cpu_state_offset(regs[sib & 7].l)); addbyte(0x83); /*ADDL EAX, imm8*/ addbyte(0xc0 | REG_EAX); addbyte((int8_t)(rmdat >> 16)); @@ -1136,7 +1135,7 @@ static x86seg *FETCH_EA_32(x86seg *op_ea_seg, uint32_t fetchdat, int op_ssegs, u addlong(new_eaaddr); addbyte(0x03); /*ADDL EAX, regs[sib&7].l*/ addbyte(0x45); - addbyte(cpu_state_offset(regs[sib & 7].l)); + addbyte((uint8_t)cpu_state_offset(regs[sib & 7].l)); (*op_pc) += 4; break; } @@ -1163,20 +1162,20 @@ static x86seg *FETCH_EA_32(x86seg *op_ea_seg, uint32_t fetchdat, int op_ssegs, u case 0: addbyte(0x03); /*ADDL EAX, regs[sib&7].l*/ addbyte(0x45); - addbyte(cpu_state_offset(regs[(sib >> 3) & 7].l)); + addbyte((uint8_t)cpu_state_offset(regs[(sib >> 3) & 7].l)); break; case 1: - addbyte(0x8B); addbyte(0x45 | (REG_EDI << 3)); addbyte(cpu_state_offset(regs[(sib >> 3) & 7].l)); /*MOVL EDI, reg*/ + addbyte(0x8B); addbyte(0x45 | (REG_EDI << 3)); addbyte((uint8_t)cpu_state_offset(regs[(sib >> 3) & 7].l)); /*MOVL EDI, reg*/ addbyte(0x01); addbyte(0xc0 | REG_EAX | (REG_EDI << 3)); /*ADDL EAX, EDI*/ addbyte(0x01); addbyte(0xc0 | REG_EAX | (REG_EDI << 3)); /*ADDL EAX, EDI*/ break; case 2: - addbyte(0x8B); addbyte(0x45 | (REG_EDI << 3)); addbyte(cpu_state_offset(regs[(sib >> 3) & 7].l)); /*MOVL EDI, reg*/ + addbyte(0x8B); addbyte(0x45 | (REG_EDI << 3)); addbyte((uint8_t)cpu_state_offset(regs[(sib >> 3) & 7].l)); /*MOVL EDI, reg*/ addbyte(0xC1); addbyte(0xE0 | REG_EDI); addbyte(2); /*SHL EDI, 2*/ addbyte(0x01); addbyte(0xc0 | REG_EAX | (REG_EDI << 3)); /*ADDL EAX, EDI*/ break; case 3: - addbyte(0x8B); addbyte(0x45 | (REG_EDI << 3)); addbyte(cpu_state_offset(regs[(sib >> 3) & 7].l)); /*MOVL EDI reg*/ + addbyte(0x8B); addbyte(0x45 | (REG_EDI << 3)); addbyte((uint8_t)cpu_state_offset(regs[(sib >> 3) & 7].l)); /*MOVL EDI reg*/ addbyte(0xC1); addbyte(0xE0 | REG_EDI); addbyte(3); /*SHL EDI, 3*/ addbyte(0x01); addbyte(0xc0 | REG_EAX | (REG_EDI << 3)); /*ADDL EAX, EDI*/ break; @@ -1195,7 +1194,7 @@ static x86seg *FETCH_EA_32(x86seg *op_ea_seg, uint32_t fetchdat, int op_ssegs, u } addbyte(0x8b); /*MOVL EAX, regs[rm].l*/ addbyte(0x45); - addbyte(cpu_state_offset(regs[rm].l)); + addbyte((uint8_t)cpu_state_offset(regs[rm].l)); cpu_state.eaaddr = cpu_state.regs[rm].l; if (mod) { @@ -1220,7 +1219,7 @@ static x86seg *FETCH_EA_32(x86seg *op_ea_seg, uint32_t fetchdat, int op_ssegs, u return op_ea_seg; } -static x86seg *FETCH_EA(x86seg *op_ea_seg, uint32_t fetchdat, int op_ssegs, uint32_t *op_pc, uint32_t op_32) +static inline x86seg *FETCH_EA(x86seg *op_ea_seg, uint32_t fetchdat, int op_ssegs, uint32_t *op_pc, uint32_t op_32) { if (op_32 & 0x200) return FETCH_EA_32(op_ea_seg, fetchdat, op_ssegs, op_pc, 0); @@ -1228,13 +1227,13 @@ static x86seg *FETCH_EA(x86seg *op_ea_seg, uint32_t fetchdat, int op_ssegs, uint } -static void LOAD_STACK_TO_EA(int off) +static inline void LOAD_STACK_TO_EA(int off) { if (stack32) { addbyte(0x8b); /*MOVL EAX,[ESP]*/ addbyte(0x45 | (REG_EAX << 3)); - addbyte(cpu_state_offset(regs[REG_ESP].l)); + addbyte((uint8_t)cpu_state_offset(regs[REG_ESP].l)); if (off) { addbyte(0x83); /*ADD EAX, off*/ @@ -1247,7 +1246,7 @@ static void LOAD_STACK_TO_EA(int off) addbyte(0x0f); /*MOVZX EAX,W[ESP]*/ addbyte(0xb7); addbyte(0x45 | (REG_EAX << 3)); - addbyte(cpu_state_offset(regs[REG_ESP].w)); + addbyte((uint8_t)cpu_state_offset(regs[REG_ESP].w)); if (off) { addbyte(0x66); /*ADD AX, off*/ @@ -1257,13 +1256,13 @@ static void LOAD_STACK_TO_EA(int off) } } -static void LOAD_EBP_TO_EA(int off) +static inline void LOAD_EBP_TO_EA(int off) { if (stack32) { addbyte(0x8b); /*MOVL EAX,[EBP]*/ addbyte(0x45 | (REG_EAX << 3)); - addbyte(cpu_state_offset(regs[REG_EBP].l)); + addbyte((uint8_t)cpu_state_offset(regs[REG_EBP].l)); if (off) { addbyte(0x83); /*ADD EAX, off*/ @@ -1276,7 +1275,7 @@ static void LOAD_EBP_TO_EA(int off) addbyte(0x0f); /*MOVZX EAX,W[EBP]*/ addbyte(0xb7); addbyte(0x45 | (REG_EAX << 3)); - addbyte(cpu_state_offset(regs[REG_EBP].w)); + addbyte((uint8_t)cpu_state_offset(regs[REG_EBP].w)); if (off) { addbyte(0x66); /*ADD AX, off*/ @@ -1286,7 +1285,7 @@ static void LOAD_EBP_TO_EA(int off) } } -static void SP_MODIFY(int off) +static inline void SP_MODIFY(int off) { if (stack32) { @@ -1294,14 +1293,14 @@ static void SP_MODIFY(int off) { addbyte(0x83); /*ADD [ESP], off*/ addbyte(0x45); - addbyte(cpu_state_offset(regs[REG_ESP].l)); + addbyte((uint8_t)cpu_state_offset(regs[REG_ESP].l)); addbyte(off); } else { addbyte(0x81); /*ADD [ESP], off*/ addbyte(0x45); - addbyte(cpu_state_offset(regs[REG_ESP].l)); + addbyte((uint8_t)cpu_state_offset(regs[REG_ESP].l)); addlong(off); } } @@ -1312,7 +1311,7 @@ static void SP_MODIFY(int off) addbyte(0x66); /*ADD [SP], off*/ addbyte(0x83); addbyte(0x45); - addbyte(cpu_state_offset(regs[REG_ESP].w)); + addbyte((uint8_t)cpu_state_offset(regs[REG_ESP].w)); addbyte(off); } else @@ -1320,14 +1319,14 @@ static void SP_MODIFY(int off) addbyte(0x66); /*ADD [SP], off*/ addbyte(0x81); addbyte(0x45); - addbyte(cpu_state_offset(regs[REG_ESP].w)); + addbyte((uint8_t)cpu_state_offset(regs[REG_ESP].w)); addword(off); } } } -static void TEST_ZERO_JUMP_W(int host_reg, uint32_t new_pc, int taken_cycles) +static inline void TEST_ZERO_JUMP_W(int host_reg, uint32_t new_pc, int taken_cycles) { addbyte(0x66); /*CMPW host_reg, 0*/ addbyte(0x83); @@ -1337,19 +1336,19 @@ static void TEST_ZERO_JUMP_W(int host_reg, uint32_t new_pc, int taken_cycles) addbyte(7+5+(taken_cycles ? 4 : 0)); addbyte(0xC7); /*MOVL [pc], new_pc*/ addbyte(0x45); - addbyte(cpu_state_offset(pc)); + addbyte((uint8_t)cpu_state_offset(pc)); addlong(new_pc); if (taken_cycles) { addbyte(0x83); /*SUB $codegen_block_cycles, cyclcs*/ addbyte(0x6d); - addbyte(cpu_state_offset(_cycles)); + addbyte((uint8_t)cpu_state_offset(_cycles)); addbyte(taken_cycles); } addbyte(0xe9); /*JMP end*/ addlong(BLOCK_EXIT_OFFSET - (block_pos + 4)); } -static void TEST_ZERO_JUMP_L(int host_reg, uint32_t new_pc, int taken_cycles) +static inline void TEST_ZERO_JUMP_L(int host_reg, uint32_t new_pc, int taken_cycles) { addbyte(0x83); /*CMPW host_reg, 0*/ addbyte(0xc0 | 0x38 | host_reg); @@ -1358,20 +1357,20 @@ static void TEST_ZERO_JUMP_L(int host_reg, uint32_t new_pc, int taken_cycles) addbyte(7+5+(taken_cycles ? 4 : 0)); addbyte(0xC7); /*MOVL [pc], new_pc*/ addbyte(0x45); - addbyte(cpu_state_offset(pc)); + addbyte((uint8_t)cpu_state_offset(pc)); addlong(new_pc); if (taken_cycles) { addbyte(0x83); /*SUB $codegen_block_cycles, cyclcs*/ addbyte(0x6d); - addbyte(cpu_state_offset(_cycles)); + addbyte((uint8_t)cpu_state_offset(_cycles)); addbyte(taken_cycles); } addbyte(0xe9); /*JMP end*/ addlong(BLOCK_EXIT_OFFSET - (block_pos + 4)); } -static void TEST_NONZERO_JUMP_W(int host_reg, uint32_t new_pc, int taken_cycles) +static inline void TEST_NONZERO_JUMP_W(int host_reg, uint32_t new_pc, int taken_cycles) { addbyte(0x66); /*CMPW host_reg, 0*/ addbyte(0x83); @@ -1381,19 +1380,19 @@ static void TEST_NONZERO_JUMP_W(int host_reg, uint32_t new_pc, int taken_cycles) addbyte(7+5+(taken_cycles ? 4 : 0)); addbyte(0xC7); /*MOVL [pc], new_pc*/ addbyte(0x45); - addbyte(cpu_state_offset(pc)); + addbyte((uint8_t)cpu_state_offset(pc)); addlong(new_pc); if (taken_cycles) { addbyte(0x83); /*SUB $codegen_block_cycles, cyclcs*/ addbyte(0x6d); - addbyte(cpu_state_offset(_cycles)); + addbyte((uint8_t)cpu_state_offset(_cycles)); addbyte(taken_cycles); } addbyte(0xe9); /*JMP end*/ addlong(BLOCK_EXIT_OFFSET - (block_pos + 4)); } -static void TEST_NONZERO_JUMP_L(int host_reg, uint32_t new_pc, int taken_cycles) +static inline void TEST_NONZERO_JUMP_L(int host_reg, uint32_t new_pc, int taken_cycles) { addbyte(0x83); /*CMPW host_reg, 0*/ addbyte(0xc0 | 0x38 | host_reg); @@ -1402,30 +1401,30 @@ static void TEST_NONZERO_JUMP_L(int host_reg, uint32_t new_pc, int taken_cycles) addbyte(7+5+(taken_cycles ? 4 : 0)); addbyte(0xC7); /*MOVL [pc], new_pc*/ addbyte(0x45); - addbyte(cpu_state_offset(pc)); + addbyte((uint8_t)cpu_state_offset(pc)); addlong(new_pc); if (taken_cycles) { addbyte(0x83); /*SUB $codegen_block_cycles, cyclcs*/ addbyte(0x6d); - addbyte(cpu_state_offset(_cycles)); + addbyte((uint8_t)cpu_state_offset(_cycles)); addbyte(taken_cycles); } addbyte(0xe9); /*JMP end*/ addlong(BLOCK_EXIT_OFFSET - (block_pos + 4)); } -static int BRANCH_COND_BE(int pc_offset, uint32_t op_pc, uint32_t offset, int not) +static inline void BRANCH_COND_BE(int pc_offset, uint32_t op_pc, uint32_t offset, int not) { switch (codegen_flags_changed ? cpu_state.flags_op : FLAGS_UNKNOWN) { case FLAGS_SUB8: addbyte(0x8a); /*MOV AL, flags_op1*/ addbyte(0x45); - addbyte(cpu_state_offset(flags_op1)); + addbyte((uint8_t)cpu_state_offset(flags_op1)); addbyte(0x3a); /*CMP AL, flags_op2*/ addbyte(0x45); - addbyte(cpu_state_offset(flags_op2)); + addbyte((uint8_t)cpu_state_offset(flags_op2)); if (not) addbyte(0x76); /*JBE*/ else @@ -1435,11 +1434,11 @@ static int BRANCH_COND_BE(int pc_offset, uint32_t op_pc, uint32_t offset, int no addbyte(0x66); /*MOV AX, flags_op1*/ addbyte(0x8b); addbyte(0x45); - addbyte(cpu_state_offset(flags_op1)); + addbyte((uint8_t)cpu_state_offset(flags_op1)); addbyte(0x66); /*CMP AX, flags_op2*/ addbyte(0x3b); addbyte(0x45); - addbyte(cpu_state_offset(flags_op2)); + addbyte((uint8_t)cpu_state_offset(flags_op2)); if (not) addbyte(0x76); /*JBE*/ else @@ -1448,10 +1447,10 @@ static int BRANCH_COND_BE(int pc_offset, uint32_t op_pc, uint32_t offset, int no case FLAGS_SUB32: addbyte(0x8b); /*MOV EAX, flags_op1*/ addbyte(0x45); - addbyte(cpu_state_offset(flags_op1)); + addbyte((uint8_t)cpu_state_offset(flags_op1)); addbyte(0x3b); /*CMP EAX, flags_op2*/ addbyte(0x45); - addbyte(cpu_state_offset(flags_op2)); + addbyte((uint8_t)cpu_state_offset(flags_op2)); if (not) addbyte(0x76); /*JBE*/ else @@ -1463,13 +1462,13 @@ static int BRANCH_COND_BE(int pc_offset, uint32_t op_pc, uint32_t offset, int no { addbyte(0x83); /*CMP flags_res, 0*/ addbyte(0x7d); - addbyte(cpu_state_offset(flags_res)); + addbyte((uint8_t)cpu_state_offset(flags_res)); addbyte(0); addbyte(0x74); /*JZ +*/ } else { - CALL_FUNC(ZF_SET); + CALL_FUNC((uintptr_t)ZF_SET); addbyte(0x85); /*TEST EAX,EAX*/ addbyte(0xc0); addbyte(0x75); /*JNZ +*/ @@ -1478,7 +1477,7 @@ static int BRANCH_COND_BE(int pc_offset, uint32_t op_pc, uint32_t offset, int no addbyte(5+2+2+7+5+(timing_bt ? 4 : 0)); else addbyte(5+2+2); - CALL_FUNC(CF_SET); + CALL_FUNC((uintptr_t)CF_SET); addbyte(0x85); /*TEST EAX,EAX*/ addbyte(0xc0); if (not) @@ -1490,30 +1489,30 @@ static int BRANCH_COND_BE(int pc_offset, uint32_t op_pc, uint32_t offset, int no addbyte(7+5+(timing_bt ? 4 : 0)); addbyte(0xC7); /*MOVL [pc], new_pc*/ addbyte(0x45); - addbyte(cpu_state_offset(pc)); + addbyte((uint8_t)cpu_state_offset(pc)); addlong(op_pc+pc_offset+offset); if (timing_bt) { addbyte(0x83); /*SUB $codegen_block_cycles, cyclcs*/ addbyte(0x6d); - addbyte(cpu_state_offset(_cycles)); + addbyte((uint8_t)cpu_state_offset(_cycles)); addbyte(timing_bt); } addbyte(0xe9); /*JMP end*/ addlong(BLOCK_EXIT_OFFSET - (block_pos + 4)); } -static int BRANCH_COND_L(int pc_offset, uint32_t op_pc, uint32_t offset, int not) +static inline void BRANCH_COND_L(int pc_offset, uint32_t op_pc, uint32_t offset, int not) { switch (codegen_flags_changed ? cpu_state.flags_op : FLAGS_UNKNOWN) { case FLAGS_SUB8: addbyte(0x8a); /*MOV AL, flags_op1*/ addbyte(0x45); - addbyte(cpu_state_offset(flags_op1)); + addbyte((uint8_t)cpu_state_offset(flags_op1)); addbyte(0x3a); /*CMP AL, flags_op2*/ addbyte(0x45); - addbyte(cpu_state_offset(flags_op2)); + addbyte((uint8_t)cpu_state_offset(flags_op2)); if (not) addbyte(0x7c); /*JL*/ else @@ -1523,11 +1522,11 @@ static int BRANCH_COND_L(int pc_offset, uint32_t op_pc, uint32_t offset, int not addbyte(0x66); /*MOV AX, flags_op1*/ addbyte(0x8b); addbyte(0x45); - addbyte(cpu_state_offset(flags_op1)); + addbyte((uint8_t)cpu_state_offset(flags_op1)); addbyte(0x66); /*CMP AX, flags_op2*/ addbyte(0x3b); addbyte(0x45); - addbyte(cpu_state_offset(flags_op2)); + addbyte((uint8_t)cpu_state_offset(flags_op2)); if (not) addbyte(0x7c); /*JL*/ else @@ -1536,10 +1535,10 @@ static int BRANCH_COND_L(int pc_offset, uint32_t op_pc, uint32_t offset, int not case FLAGS_SUB32: addbyte(0x8b); /*MOV EAX, flags_op1*/ addbyte(0x45); - addbyte(cpu_state_offset(flags_op1)); + addbyte((uint8_t)cpu_state_offset(flags_op1)); addbyte(0x3b); /*CMP EAX, flags_op2*/ addbyte(0x45); - addbyte(cpu_state_offset(flags_op2)); + addbyte((uint8_t)cpu_state_offset(flags_op2)); if (not) addbyte(0x7c); /*JL*/ else @@ -1547,13 +1546,13 @@ static int BRANCH_COND_L(int pc_offset, uint32_t op_pc, uint32_t offset, int not break; default: - CALL_FUNC(NF_SET); + CALL_FUNC((uintptr_t)NF_SET); addbyte(0x85); /*TEST EAX,EAX*/ addbyte(0xc0); addbyte(0x0f); /*SETNE BL*/ addbyte(0x95); addbyte(0xc3); - CALL_FUNC(VF_SET); + CALL_FUNC((uintptr_t)VF_SET); addbyte(0x85); /*TEST EAX,EAX*/ addbyte(0xc0); addbyte(0x0f); /*SETNE AL*/ @@ -1570,30 +1569,30 @@ static int BRANCH_COND_L(int pc_offset, uint32_t op_pc, uint32_t offset, int not addbyte(7+5+(timing_bt ? 4 : 0)); addbyte(0xC7); /*MOVL [pc], new_pc*/ addbyte(0x45); - addbyte(cpu_state_offset(pc)); + addbyte((uint8_t)cpu_state_offset(pc)); addlong(op_pc+pc_offset+offset); if (timing_bt) { addbyte(0x83); /*SUB $codegen_block_cycles, cyclcs*/ addbyte(0x6d); - addbyte(cpu_state_offset(_cycles)); + addbyte((uint8_t)cpu_state_offset(_cycles)); addbyte(timing_bt); } addbyte(0xe9); /*JMP end*/ addlong(BLOCK_EXIT_OFFSET - (block_pos + 4)); } -static int BRANCH_COND_LE(int pc_offset, uint32_t op_pc, uint32_t offset, int not) +static inline void BRANCH_COND_LE(int pc_offset, uint32_t op_pc, uint32_t offset, int not) { switch (codegen_flags_changed ? cpu_state.flags_op : FLAGS_UNKNOWN) { case FLAGS_SUB8: addbyte(0x8a); /*MOV AL, flags_op1*/ addbyte(0x45); - addbyte(cpu_state_offset(flags_op1)); + addbyte((uint8_t)cpu_state_offset(flags_op1)); addbyte(0x3a); /*CMP AL, flags_op2*/ addbyte(0x45); - addbyte(cpu_state_offset(flags_op2)); + addbyte((uint8_t)cpu_state_offset(flags_op2)); if (not) addbyte(0x7e); /*JLE*/ else @@ -1603,11 +1602,11 @@ static int BRANCH_COND_LE(int pc_offset, uint32_t op_pc, uint32_t offset, int no addbyte(0x66); /*MOV AX, flags_op1*/ addbyte(0x8b); addbyte(0x45); - addbyte(cpu_state_offset(flags_op1)); + addbyte((uint8_t)cpu_state_offset(flags_op1)); addbyte(0x66); /*CMP AX, flags_op2*/ addbyte(0x3b); addbyte(0x45); - addbyte(cpu_state_offset(flags_op2)); + addbyte((uint8_t)cpu_state_offset(flags_op2)); if (not) addbyte(0x7e); /*JLE*/ else @@ -1616,10 +1615,10 @@ static int BRANCH_COND_LE(int pc_offset, uint32_t op_pc, uint32_t offset, int no case FLAGS_SUB32: addbyte(0x8b); /*MOV EAX, flags_op1*/ addbyte(0x45); - addbyte(cpu_state_offset(flags_op1)); + addbyte((uint8_t)cpu_state_offset(flags_op1)); addbyte(0x3b); /*CMP EAX, flags_op2*/ addbyte(0x45); - addbyte(cpu_state_offset(flags_op2)); + addbyte((uint8_t)cpu_state_offset(flags_op2)); if (not) addbyte(0x7e); /*JLE*/ else @@ -1631,13 +1630,13 @@ static int BRANCH_COND_LE(int pc_offset, uint32_t op_pc, uint32_t offset, int no { addbyte(0x83); /*CMP flags_res, 0*/ addbyte(0x7d); - addbyte(cpu_state_offset(flags_res)); + addbyte((uint8_t)cpu_state_offset(flags_res)); addbyte(0); addbyte(0x74); /*JZ +*/ } else { - CALL_FUNC(ZF_SET); + CALL_FUNC((uintptr_t)ZF_SET); addbyte(0x85); /*TEST EAX,EAX*/ addbyte(0xc0); addbyte(0x75); /*JNZ +*/ @@ -1647,13 +1646,13 @@ static int BRANCH_COND_LE(int pc_offset, uint32_t op_pc, uint32_t offset, int no else addbyte(5+2+3+5+2+3+2+2); - CALL_FUNC(NF_SET); + CALL_FUNC((uintptr_t)NF_SET); addbyte(0x85); /*TEST EAX,EAX*/ addbyte(0xc0); addbyte(0x0f); /*SETNE BL*/ addbyte(0x95); addbyte(0xc3); - CALL_FUNC(VF_SET); + CALL_FUNC((uintptr_t)VF_SET); addbyte(0x85); /*TEST EAX,EAX*/ addbyte(0xc0); addbyte(0x0f); /*SETNE AL*/ @@ -1670,13 +1669,13 @@ static int BRANCH_COND_LE(int pc_offset, uint32_t op_pc, uint32_t offset, int no addbyte(7+5+(timing_bt ? 4 : 0)); addbyte(0xC7); /*MOVL [pc], new_pc*/ addbyte(0x45); - addbyte(cpu_state_offset(pc)); + addbyte((uint8_t)cpu_state_offset(pc)); addlong(op_pc+pc_offset+offset); if (timing_bt) { addbyte(0x83); /*SUB $codegen_block_cycles, cyclcs*/ addbyte(0x6d); - addbyte(cpu_state_offset(_cycles)); + addbyte((uint8_t)cpu_state_offset(_cycles)); addbyte(timing_bt); } addbyte(0xe9); /*JMP end*/ @@ -1684,7 +1683,7 @@ static int BRANCH_COND_LE(int pc_offset, uint32_t op_pc, uint32_t offset, int no } -static void FP_ENTER() +static inline void FP_ENTER() { if (codegen_fpu_entered) return; @@ -1697,7 +1696,7 @@ static void FP_ENTER() addbyte(7+7+5+5); addbyte(0xC7); /*MOVL [oldpc],op_old_pc*/ addbyte(0x45); - addbyte(cpu_state_offset(oldpc)); + addbyte((uint8_t)cpu_state_offset(oldpc)); addlong(op_old_pc); addbyte(0xc7); /*MOV [ESP], 7*/ addbyte(0x04); @@ -1711,7 +1710,7 @@ static void FP_ENTER() codegen_fpu_entered = 1; } -static void FP_FLD(int reg) +static inline void FP_FLD(int reg) { if (codeblock[block_current].flags & CODEBLOCK_STATIC_TOP) { @@ -1719,38 +1718,38 @@ static void FP_FLD(int reg) addbyte(0x0f); addbyte(0x7e); addbyte(0x45); - addbyte(cpu_state_offset(ST[(cpu_state.TOP + reg) & 7])); + addbyte((uint8_t)cpu_state_offset(ST[(cpu_state.TOP + reg) & 7])); addbyte(0xc6); /*MOVB TOP[EBP], (TOP-1) & 7*/ addbyte(0x45); - addbyte(cpu_state_offset(TOP)); + addbyte((uint8_t)cpu_state_offset(TOP)); addbyte((cpu_state.TOP - 1) & 7); addbyte(0xf3); /*MOVQ XMM1, MM[reg][EBP]*/ addbyte(0x0f); addbyte(0x7e); addbyte(0x4d); - addbyte(cpu_state_offset(MM[(cpu_state.TOP + reg) & 7].q)); + addbyte((uint8_t)cpu_state_offset(MM[(cpu_state.TOP + reg) & 7].q)); addbyte(0x66); /*MOVQ ST[-1][EBP], XMM0*/ addbyte(0x0f); addbyte(0xd6); addbyte(0x45); - addbyte(cpu_state_offset(ST[(cpu_state.TOP - 1) & 7])); + addbyte((uint8_t)cpu_state_offset(ST[(cpu_state.TOP - 1) & 7])); addbyte(0x8a); /*MOV AL, tag[reg][EBP]*/ addbyte(0x45); - addbyte(cpu_state_offset(tag[(cpu_state.TOP + reg) & 7])); + addbyte((uint8_t)cpu_state_offset(tag[(cpu_state.TOP + reg) & 7])); addbyte(0x66); /*MOVQ MM[-1][EBP], XMM1*/ addbyte(0x0f); addbyte(0xd6); addbyte(0x4d); - addbyte(cpu_state_offset(MM[(cpu_state.TOP - 1) & 7].q)); + addbyte((uint8_t)cpu_state_offset(MM[(cpu_state.TOP - 1) & 7].q)); addbyte(0x88); /*MOV tag[-1][EBP], AL*/ addbyte(0x45); - addbyte(cpu_state_offset(tag[(cpu_state.TOP - 1) & 7])); + addbyte((uint8_t)cpu_state_offset(tag[(cpu_state.TOP - 1) & 7])); } else { addbyte(0x8b); /*MOV EAX, [TOP]*/ addbyte(0x45); - addbyte(cpu_state_offset(TOP)); + addbyte((uint8_t)cpu_state_offset(TOP)); addbyte(0x89); /*MOV EBX, EAX*/ addbyte(0xc3); if (reg) @@ -1775,46 +1774,46 @@ static void FP_FLD(int reg) addbyte(0xdd); /*FLD [ST+EAX*8]*/ addbyte(0x44); addbyte(0xc5); - addbyte(cpu_state_offset(ST)); + addbyte((uint8_t)cpu_state_offset(ST)); addbyte(0x83); /*AND EBX, 7*/ addbyte(0xe3); addbyte(0x07); addbyte(0x8b); /*MOV EDX, [ST_i64+EAX]*/ addbyte(0x54); addbyte(0xc5); - addbyte(cpu_state_offset(MM)); + addbyte((uint8_t)cpu_state_offset(MM)); addbyte(0x8b); /*MOV ECX, [ST_i64+4+EAX]*/ addbyte(0x4c); addbyte(0xc5); - addbyte(cpu_state_offset(MM)+4); + addbyte((uint8_t)cpu_state_offset(MM)+4); addbyte(0x8a); /*MOV AL, [tag+EAX]*/ addbyte(0x44); addbyte(0x05); - addbyte(cpu_state_offset(tag[0])); + addbyte((uint8_t)cpu_state_offset(tag[0])); addbyte(0xdd); /*FSTP [ST+EBX*8]*/ addbyte(0x5c); addbyte(0xdd); - addbyte(cpu_state_offset(ST)); + addbyte((uint8_t)cpu_state_offset(ST)); addbyte(0x88); /*MOV [tag+EBX], AL*/ addbyte(0x44); addbyte(0x1d); - addbyte(cpu_state_offset(tag[0])); + addbyte((uint8_t)cpu_state_offset(tag[0])); addbyte(0x89); /*MOV [ST_i64+EBX], EDX*/ addbyte(0x54); addbyte(0xdd); - addbyte(cpu_state_offset(MM)); + addbyte((uint8_t)cpu_state_offset(MM)); addbyte(0x89); /*MOV [ST_i64+EBX+4], ECX*/ addbyte(0x4c); addbyte(0xdd); - addbyte(cpu_state_offset(MM)+4); + addbyte((uint8_t)cpu_state_offset(MM)+4); addbyte(0x89); /*MOV [TOP], EBX*/ addbyte(0x5d); - addbyte(cpu_state_offset(TOP)); + addbyte((uint8_t)cpu_state_offset(TOP)); } } -static void FP_FST(int reg) +static inline void FP_FST(int reg) { if (codeblock[block_current].flags & CODEBLOCK_STATIC_TOP) { @@ -1822,32 +1821,32 @@ static void FP_FST(int reg) addbyte(0x0f); addbyte(0x7e); addbyte(0x45); - addbyte(cpu_state_offset(ST[cpu_state.TOP])); + addbyte((uint8_t)cpu_state_offset(ST[cpu_state.TOP])); addbyte(0x8a); /*MOV AL, tag[0][EBP]*/ addbyte(0x45); - addbyte(cpu_state_offset(tag[cpu_state.TOP])); + addbyte((uint8_t)cpu_state_offset(tag[cpu_state.TOP])); addbyte(0x66); /*MOVQ ST[reg][EBP], XMM0*/ addbyte(0x0f); addbyte(0xd6); addbyte(0x45); - addbyte(cpu_state_offset(ST[(cpu_state.TOP + reg) & 7])); + addbyte((uint8_t)cpu_state_offset(ST[(cpu_state.TOP + reg) & 7])); addbyte(0x88); /*MOV tag[reg][EBP], AL*/ addbyte(0x45); - addbyte(cpu_state_offset(tag[(cpu_state.TOP + reg) & 7])); + addbyte((uint8_t)cpu_state_offset(tag[(cpu_state.TOP + reg) & 7])); } else { addbyte(0x8b); /*MOV EAX, [TOP]*/ addbyte(0x45); - addbyte(cpu_state_offset(TOP)); + addbyte((uint8_t)cpu_state_offset(TOP)); addbyte(0xdd); /*FLD [ST+EAX*8]*/ addbyte(0x44); addbyte(0xc5); - addbyte(cpu_state_offset(ST)); + addbyte((uint8_t)cpu_state_offset(ST)); addbyte(0x8a); /*MOV BL, [tag+EAX]*/ addbyte(0x5c); addbyte(0x05); - addbyte(cpu_state_offset(tag[0])); + addbyte((uint8_t)cpu_state_offset(tag[0])); if (reg) { @@ -1862,15 +1861,15 @@ static void FP_FST(int reg) addbyte(0xdd); /*FSTP [ST+EAX*8]*/ addbyte(0x5c); addbyte(0xc5); - addbyte(cpu_state_offset(ST)); + addbyte((uint8_t)cpu_state_offset(ST)); addbyte(0x88); /*MOV [tag+EAX], BL*/ addbyte(0x5c); addbyte(0x05); - addbyte(cpu_state_offset(tag[0])); + addbyte((uint8_t)cpu_state_offset(tag[0])); } } -static void FP_FXCH(int reg) +static inline void FP_FXCH(int reg) { if (codeblock[block_current].flags & CODEBLOCK_STATIC_TOP) { @@ -1878,60 +1877,60 @@ static void FP_FXCH(int reg) addbyte(0x0f); addbyte(0x7e); addbyte(0x45); - addbyte(cpu_state_offset(ST[cpu_state.TOP])); + addbyte((uint8_t)cpu_state_offset(ST[cpu_state.TOP])); addbyte(0xf3); /*MOVQ XMM1, ST[reg][EBP]*/ addbyte(0x0f); addbyte(0x7e); addbyte(0x4d); - addbyte(cpu_state_offset(ST[(cpu_state.TOP + reg) & 7])); + addbyte((uint8_t)cpu_state_offset(ST[(cpu_state.TOP + reg) & 7])); addbyte(0x66); /*MOVQ ST[reg][EBP], XMM0*/ addbyte(0x0f); addbyte(0xd6); addbyte(0x45); - addbyte(cpu_state_offset(ST[(cpu_state.TOP + reg) & 7])); + addbyte((uint8_t)cpu_state_offset(ST[(cpu_state.TOP + reg) & 7])); addbyte(0xf3); /*MOVQ XMM2, MM[0][EBP]*/ addbyte(0x0f); addbyte(0x7e); addbyte(0x55); - addbyte(cpu_state_offset(MM[cpu_state.TOP].q)); + addbyte((uint8_t)cpu_state_offset(MM[cpu_state.TOP].q)); addbyte(0x66); /*MOVQ ST[0][EBP], XMM1*/ addbyte(0x0f); addbyte(0xd6); addbyte(0x4d); - addbyte(cpu_state_offset(ST[cpu_state.TOP])); + addbyte((uint8_t)cpu_state_offset(ST[cpu_state.TOP])); addbyte(0xf3); /*MOVQ XMM3, MM[reg][EBP]*/ addbyte(0x0f); addbyte(0x7e); addbyte(0x5d); - addbyte(cpu_state_offset(MM[(cpu_state.TOP + reg) & 7].q)); + addbyte((uint8_t)cpu_state_offset(MM[(cpu_state.TOP + reg) & 7].q)); addbyte(0x66); /*MOVQ MM[reg][EBP], XMM2*/ addbyte(0x0f); addbyte(0xd6); addbyte(0x55); - addbyte(cpu_state_offset(MM[(cpu_state.TOP + reg) & 7].q)); + addbyte((uint8_t)cpu_state_offset(MM[(cpu_state.TOP + reg) & 7].q)); addbyte(0x8a); /*MOV AL, tag[0][EBP]*/ addbyte(0x45); - addbyte(cpu_state_offset(tag[cpu_state.TOP])); + addbyte((uint8_t)cpu_state_offset(tag[cpu_state.TOP])); addbyte(0x66); /*MOVQ MM[0][EBP], XMM3*/ addbyte(0x0f); addbyte(0xd6); addbyte(0x5d); - addbyte(cpu_state_offset(MM[cpu_state.TOP].q)); + addbyte((uint8_t)cpu_state_offset(MM[cpu_state.TOP].q)); addbyte(0x8a); /*MOV AH, tag[reg][EBP]*/ addbyte(0x65); - addbyte(cpu_state_offset(tag[(cpu_state.TOP + reg) & 7])); + addbyte((uint8_t)cpu_state_offset(tag[(cpu_state.TOP + reg) & 7])); addbyte(0x88); /*MOV tag[reg][EBP], AL*/ addbyte(0x45); - addbyte(cpu_state_offset(tag[(cpu_state.TOP + reg) & 7])); + addbyte((uint8_t)cpu_state_offset(tag[(cpu_state.TOP + reg) & 7])); addbyte(0x88); /*MOV tag[0][EBP], AH*/ addbyte(0x65); - addbyte(cpu_state_offset(tag[cpu_state.TOP])); + addbyte((uint8_t)cpu_state_offset(tag[cpu_state.TOP])); } else { addbyte(0x8b); /*MOV EAX, [TOP]*/ addbyte(0x45); - addbyte(cpu_state_offset(TOP)); + addbyte((uint8_t)cpu_state_offset(TOP)); addbyte(0x89); /*MOV EBX, EAX*/ addbyte(0xc3); addbyte(0x83); /*ADD EAX, reg*/ @@ -1941,38 +1940,38 @@ static void FP_FXCH(int reg) addbyte(0xdd); /*FLD [ST+EBX*8]*/ addbyte(0x44); addbyte(0xdd); - addbyte(cpu_state_offset(ST)); + addbyte((uint8_t)cpu_state_offset(ST)); addbyte(0x83); /*AND EAX, 7*/ addbyte(0xe0); addbyte(0x07); addbyte(0xdd); /*FLD [ST+EAX*8]*/ addbyte(0x44); addbyte(0xc5); - addbyte(cpu_state_offset(ST)); + addbyte((uint8_t)cpu_state_offset(ST)); addbyte(0xdd); /*FSTP [ST+EBX*8]*/ addbyte(0x5c); addbyte(0xdd); - addbyte(cpu_state_offset(ST)); + addbyte((uint8_t)cpu_state_offset(ST)); addbyte(0xdd); /*FSTP [ST+EAX*8]*/ addbyte(0x5c); addbyte(0xc5); - addbyte(cpu_state_offset(ST)); + addbyte((uint8_t)cpu_state_offset(ST)); addbyte(0x8a); /*MOV CL, tag[EAX]*/ addbyte(0x4c); addbyte(0x05); - addbyte(cpu_state_offset(tag[0])); + addbyte((uint8_t)cpu_state_offset(tag[0])); addbyte(0x8a); /*MOV DL, tag[EBX]*/ addbyte(0x54); addbyte(0x1d); - addbyte(cpu_state_offset(tag[0])); + addbyte((uint8_t)cpu_state_offset(tag[0])); addbyte(0x88); /*MOV tag[EBX], CL*/ addbyte(0x4c); addbyte(0x1d); - addbyte(cpu_state_offset(tag[0])); + addbyte((uint8_t)cpu_state_offset(tag[0])); addbyte(0x88); /*MOV tag[EAX], DL*/ addbyte(0x54); addbyte(0x05); - addbyte(cpu_state_offset(tag[0])); + addbyte((uint8_t)cpu_state_offset(tag[0])); addbyte(0xbe); /*MOVL ESI, ST_int64*/ addlong((uintptr_t)cpu_state.MM); addbyte(0x8b); /*MOV ECX, ST_int64[EAX*8]*/ @@ -2007,7 +2006,7 @@ static void FP_FXCH(int reg) } -static void FP_LOAD_S() +static inline void FP_LOAD_S() { if (codeblock[block_current].flags & CODEBLOCK_STATIC_TOP) { @@ -2021,22 +2020,22 @@ static void FP_LOAD_S() addbyte(0x24); addbyte(0xc6); /*MOVB TOP[EBP], (TOP-1) & 7*/ addbyte(0x45); - addbyte(cpu_state_offset(TOP)); + addbyte((uint8_t)cpu_state_offset(TOP)); addbyte((cpu_state.TOP - 1) & 7); addbyte(0x0f); /*SETE tag[reg][EBP]*/ addbyte(0x94); addbyte(0x45); - addbyte(cpu_state_offset(tag[(cpu_state.TOP - 1) & 7])); + addbyte((uint8_t)cpu_state_offset(tag[(cpu_state.TOP - 1) & 7])); addbyte(0xdd); /*FSTP ST[reg][EBP]*/ addbyte(0x5d); - addbyte(cpu_state_offset(ST[(cpu_state.TOP - 1) & 7])); + addbyte((uint8_t)cpu_state_offset(ST[(cpu_state.TOP - 1) & 7])); block_current = block_current; } else { addbyte(0x8b); /*MOV EBX, TOP*/ addbyte(0x5d); - addbyte(cpu_state_offset(TOP)); + addbyte((uint8_t)cpu_state_offset(TOP)); addbyte(0x89); /*MOV [ESP], EAX*/ addbyte(0x04); addbyte(0x24); @@ -2053,44 +2052,44 @@ static void FP_LOAD_S() addbyte(0xc0); addbyte(0x89); /*MOV TOP, EBX*/ addbyte(0x5d); - addbyte(cpu_state_offset(TOP)); + addbyte((uint8_t)cpu_state_offset(TOP)); addbyte(0xdd); /*FSTP [ST+EBX*8]*/ addbyte(0x5c); addbyte(0xdd); - addbyte(cpu_state_offset(ST)); + addbyte((uint8_t)cpu_state_offset(ST)); addbyte(0x0f); /*SETE [tag+EBX]*/ addbyte(0x94); addbyte(0x44); addbyte(0x1d); - addbyte(cpu_state_offset(tag[0])); + addbyte((uint8_t)cpu_state_offset(tag[0])); } } -static void FP_LOAD_D() +static inline void FP_LOAD_D() { if (codeblock[block_current].flags & CODEBLOCK_STATIC_TOP) { addbyte(0x89); /*MOV ST[reg][EBP], EAX*/ addbyte(0x45); - addbyte(cpu_state_offset(ST[(cpu_state.TOP - 1) & 7])); + addbyte((uint8_t)cpu_state_offset(ST[(cpu_state.TOP - 1) & 7])); addbyte(0x09); /*OR EAX, EDX*/ addbyte(0xd0); addbyte(0x89); /*MOV ST[reg][EBP]+4, EDX*/ addbyte(0x55); - addbyte(cpu_state_offset(ST[(cpu_state.TOP - 1) & 7]) + 4); + addbyte((uint8_t)cpu_state_offset(ST[(cpu_state.TOP - 1) & 7]) + 4); addbyte(0xc6); /*MOVB TOP[EBP], (TOP-1) & 7*/ addbyte(0x45); - addbyte(cpu_state_offset(TOP)); + addbyte((uint8_t)cpu_state_offset(TOP)); addbyte((cpu_state.TOP - 1) & 7); addbyte(0x0f); /*SETE tag[reg][EBP]*/ addbyte(0x94); addbyte(0x45); - addbyte(cpu_state_offset(tag[(cpu_state.TOP - 1) & 7])); + addbyte((uint8_t)cpu_state_offset(tag[(cpu_state.TOP - 1) & 7])); } else { addbyte(0x8b); /*MOV EBX, TOP*/ addbyte(0x5d); - addbyte(cpu_state_offset(TOP)); + addbyte((uint8_t)cpu_state_offset(TOP)); addbyte(0x89); /*MOV [ESP], EAX*/ addbyte(0x04); addbyte(0x24); @@ -2114,19 +2113,19 @@ static void FP_LOAD_D() addbyte(0); addbyte(0x89); /*MOV TOP, EBX*/ addbyte(0x5d); - addbyte(cpu_state_offset(TOP)); + addbyte((uint8_t)cpu_state_offset(TOP)); addbyte(0xdd); /*FSTP [ST+EBX*8]*/ addbyte(0x5c); addbyte(0xdd); - addbyte(cpu_state_offset(ST)); + addbyte((uint8_t)cpu_state_offset(ST)); addbyte(0x0f); /*SETE [tag+EBX]*/ addbyte(0x94); addbyte(0x44); addbyte(0x1d); - addbyte(cpu_state_offset(tag[0])); + addbyte((uint8_t)cpu_state_offset(tag[0])); } } -static void FP_LOAD_IW() +static inline void FP_LOAD_IW() { if (codeblock[block_current].flags & CODEBLOCK_STATIC_TOP) { @@ -2142,21 +2141,21 @@ static void FP_LOAD_IW() addbyte(0x24); addbyte(0xc6); /*MOVB TOP[EBP], (TOP-1) & 7*/ addbyte(0x45); - addbyte(cpu_state_offset(TOP)); + addbyte((uint8_t)cpu_state_offset(TOP)); addbyte((cpu_state.TOP - 1) & 7); addbyte(0x0f); /*SETE tag[reg][EBP]*/ addbyte(0x94); addbyte(0x45); - addbyte(cpu_state_offset(tag[(cpu_state.TOP - 1) & 7])); + addbyte((uint8_t)cpu_state_offset(tag[(cpu_state.TOP - 1) & 7])); addbyte(0xdd); /*FSTP ST[reg][EBP]*/ addbyte(0x5d); - addbyte(cpu_state_offset(ST[(cpu_state.TOP - 1) & 7])); + addbyte((uint8_t)cpu_state_offset(ST[(cpu_state.TOP - 1) & 7])); } else { addbyte(0x8b); /*MOV EBX, TOP*/ addbyte(0x5d); - addbyte(cpu_state_offset(TOP)); + addbyte((uint8_t)cpu_state_offset(TOP)); addbyte(0x89); /*MOV [ESP], EAX*/ addbyte(0x04); addbyte(0x24); @@ -2174,19 +2173,19 @@ static void FP_LOAD_IW() addbyte(0); addbyte(0x89); /*MOV TOP, EBX*/ addbyte(0x5d); - addbyte(cpu_state_offset(TOP)); + addbyte((uint8_t)cpu_state_offset(TOP)); addbyte(0xdd); /*FSTP [ST+EBX*8]*/ addbyte(0x5c); addbyte(0xdd); - addbyte(cpu_state_offset(ST)); + addbyte((uint8_t)cpu_state_offset(ST)); addbyte(0x0f); /*SETE [tag+EBX]*/ addbyte(0x94); addbyte(0x44); addbyte(0x1d); - addbyte(cpu_state_offset(tag[0])); + addbyte((uint8_t)cpu_state_offset(tag[0])); } } -static void FP_LOAD_IL() +static inline void FP_LOAD_IL() { if (codeblock[block_current].flags & CODEBLOCK_STATIC_TOP) { @@ -2200,21 +2199,21 @@ static void FP_LOAD_IL() addbyte(0x24); addbyte(0xc6); /*MOVB TOP[EBP], (TOP-1) & 7*/ addbyte(0x45); - addbyte(cpu_state_offset(TOP)); + addbyte((uint8_t)cpu_state_offset(TOP)); addbyte((cpu_state.TOP - 1) & 7); addbyte(0x0f); /*SETE tag[reg][EBP]*/ addbyte(0x94); addbyte(0x45); - addbyte(cpu_state_offset(tag[(cpu_state.TOP - 1) & 7])); + addbyte((uint8_t)cpu_state_offset(tag[(cpu_state.TOP - 1) & 7])); addbyte(0xdd); /*FSTP ST[reg][EBP]*/ addbyte(0x5d); - addbyte(cpu_state_offset(ST[(cpu_state.TOP - 1) & 7])); + addbyte((uint8_t)cpu_state_offset(ST[(cpu_state.TOP - 1) & 7])); } else { addbyte(0x8b); /*MOV EBX, TOP*/ addbyte(0x5d); - addbyte(cpu_state_offset(TOP)); + addbyte((uint8_t)cpu_state_offset(TOP)); addbyte(0x89); /*MOV [ESP], EAX*/ addbyte(0x04); addbyte(0x24); @@ -2232,54 +2231,54 @@ static void FP_LOAD_IL() addbyte(0); addbyte(0x89); /*MOV TOP, EBX*/ addbyte(0x5d); - addbyte(cpu_state_offset(TOP)); + addbyte((uint8_t)cpu_state_offset(TOP)); addbyte(0xdd); /*FSTP [ST+EBX*8]*/ addbyte(0x5c); addbyte(0xdd); - addbyte(cpu_state_offset(ST)); + addbyte((uint8_t)cpu_state_offset(ST)); addbyte(0x0f); /*SETE [tag+EBX]*/ addbyte(0x94); addbyte(0x44); addbyte(0x1d); - addbyte(cpu_state_offset(tag[0])); + addbyte((uint8_t)cpu_state_offset(tag[0])); } } -static void FP_LOAD_IQ() +static inline void FP_LOAD_IQ() { if (codeblock[block_current].flags & CODEBLOCK_STATIC_TOP) { addbyte(0x89); /*MOV MM[reg][EBP], EAX*/ addbyte(0x45); - addbyte(cpu_state_offset(MM[(cpu_state.TOP - 1) & 7].q)); + addbyte((uint8_t)cpu_state_offset(MM[(cpu_state.TOP - 1) & 7].q)); addbyte(0x09); /*OR EAX, EDX*/ addbyte(0xd0); addbyte(0x89); /*MOV MM[reg][EBP]+4, EDX*/ addbyte(0x55); - addbyte(cpu_state_offset(MM[(cpu_state.TOP - 1) & 7].q) + 4); + addbyte((uint8_t)cpu_state_offset(MM[(cpu_state.TOP - 1) & 7].q) + 4); addbyte(0x0f); /*SETE AL*/ addbyte(0x94); addbyte(0xc0); addbyte(0xdf); /*FILDq MM[reg][EBP]*/ addbyte(0x6d); - addbyte(cpu_state_offset(MM[(cpu_state.TOP - 1) & 7].q)); + addbyte((uint8_t)cpu_state_offset(MM[(cpu_state.TOP - 1) & 7].q)); addbyte(0x0c); /*OR AL, TAG_UINT64*/ addbyte(TAG_UINT64); addbyte(0xc6); /*MOVB TOP[EBP], (TOP-1) & 7*/ addbyte(0x45); - addbyte(cpu_state_offset(TOP)); + addbyte((uint8_t)cpu_state_offset(TOP)); addbyte((cpu_state.TOP - 1) & 7); addbyte(0x88); /*MOV tag[reg][EBP], AL*/ addbyte(0x45); - addbyte(cpu_state_offset(tag[(cpu_state.TOP - 1) & 7])); + addbyte((uint8_t)cpu_state_offset(tag[(cpu_state.TOP - 1) & 7])); addbyte(0xdd); /*FSTP ST[reg][EBP]*/ addbyte(0x5d); - addbyte(cpu_state_offset(ST[(cpu_state.TOP - 1) & 7])); + addbyte((uint8_t)cpu_state_offset(ST[(cpu_state.TOP - 1) & 7])); } else { addbyte(0x8b); /*MOV EBX, TOP*/ addbyte(0x5d); - addbyte(cpu_state_offset(TOP)); + addbyte((uint8_t)cpu_state_offset(TOP)); addbyte(0x83); /*SUB EBX, 1*/ addbyte(0xeb); addbyte(1); @@ -2289,65 +2288,65 @@ static void FP_LOAD_IQ() addbyte(0x89); /*MOV [ST_i64+EBX*8], EAX*/ addbyte(0x44); addbyte(0xdd); - addbyte(cpu_state_offset(MM)); + addbyte((uint8_t)cpu_state_offset(MM)); addbyte(0x09); /*OR EAX, EDX*/ addbyte(0xd0); addbyte(0x89); /*MOV [ST_i64+4+EBX*8], EDX*/ addbyte(0x54); addbyte(0xdd); - addbyte(cpu_state_offset(MM)+4); + addbyte((uint8_t)cpu_state_offset(MM)+4); addbyte(0x83); /*CMP EAX, 0*/ addbyte(0xf8); addbyte(0); addbyte(0xdf); /*FILDl [ST_i64+EBX*8]*/ addbyte(0x6c); addbyte(0xdd); - addbyte(cpu_state_offset(MM)); + addbyte((uint8_t)cpu_state_offset(MM)); addbyte(0x0f); /*SETE AL*/ addbyte(0x94); addbyte(0xc0); addbyte(0xdd); /*FSTP [ST+EBX*8]*/ addbyte(0x5c); addbyte(0xdd); - addbyte(cpu_state_offset(ST)); + addbyte((uint8_t)cpu_state_offset(ST)); addbyte(0x0c); /*OR AL, TAG_UINT64*/ addbyte(TAG_UINT64); addbyte(0x89); /*MOV TOP, EBX*/ addbyte(0x5d); - addbyte(cpu_state_offset(TOP)); + addbyte((uint8_t)cpu_state_offset(TOP)); addbyte(0x88); /*MOV [tag+EBX], AL*/ addbyte(0x44); addbyte(0x1d); - addbyte(cpu_state_offset(tag[0])); + addbyte((uint8_t)cpu_state_offset(tag[0])); } } -static void FP_LOAD_IMM_Q(uint64_t v) +static inline void FP_LOAD_IMM_Q(uint64_t v) { if (codeblock[block_current].flags & CODEBLOCK_STATIC_TOP) { addbyte(0xc7); /*MOV ST[reg][EBP], v*/ addbyte(0x45); - addbyte(cpu_state_offset(ST[(cpu_state.TOP - 1) & 7])); + addbyte((uint8_t)cpu_state_offset(ST[(cpu_state.TOP - 1) & 7])); addlong(v & 0xffffffff); addbyte(0xc7); /*MOV ST[reg][EBP]+4, v*/ addbyte(0x45); - addbyte(cpu_state_offset(ST[(cpu_state.TOP - 1) & 7]) + 4); + addbyte((uint8_t)cpu_state_offset(ST[(cpu_state.TOP - 1) & 7]) + 4); addlong(v >> 32); addbyte(0xc6); /*MOVB TOP[EBP], (TOP-1) & 7*/ addbyte(0x45); - addbyte(cpu_state_offset(TOP)); + addbyte((uint8_t)cpu_state_offset(TOP)); addbyte((cpu_state.TOP - 1) & 7); addbyte(0xc6); /*MOVB tag[reg][EBP], 1:0*/ addbyte(0x45); - addbyte(cpu_state_offset(tag[(cpu_state.TOP - 1) & 7])); + addbyte((uint8_t)cpu_state_offset(tag[(cpu_state.TOP - 1) & 7])); addbyte(v ? 0 : 1); } else { addbyte(0x8b); /*MOV EBX, TOP*/ addbyte(0x5d); - addbyte(cpu_state_offset(TOP)); + addbyte((uint8_t)cpu_state_offset(TOP)); addbyte(0x83); /*SUB EBX, 1*/ addbyte(0xeb); addbyte(1); @@ -2357,37 +2356,37 @@ static void FP_LOAD_IMM_Q(uint64_t v) addbyte(0xc7); /*MOV ST[EBP+EBX*8], v*/ addbyte(0x44); addbyte(0xdd); - addbyte(cpu_state_offset(ST)); + addbyte((uint8_t)cpu_state_offset(ST)); addlong(v & 0xffffffff); addbyte(0xc7); /*MOV ST[EBP+EBX*8]+4, v*/ addbyte(0x44); addbyte(0xdd); - addbyte(cpu_state_offset(ST) + 4); + addbyte((uint8_t)cpu_state_offset(ST) + 4); addlong(v >> 32); addbyte(0xc6); /*MOVB tag[reg][EBP], 1:0*/ addbyte(0x44); addbyte(0x1d); - addbyte(cpu_state_offset(tag[0])); + addbyte((uint8_t)cpu_state_offset(tag[0])); addbyte(v ? 0 : 1); addbyte(0x89); /*MOV TOP, EBX*/ addbyte(0x5d); - addbyte(cpu_state_offset(TOP)); + addbyte((uint8_t)cpu_state_offset(TOP)); } } -static int FP_LOAD_REG(int reg) +static inline int FP_LOAD_REG(int reg) { if (codeblock[block_current].flags & CODEBLOCK_STATIC_TOP) { addbyte(0xdd); /*FLD ST[reg][EBP]*/ addbyte(0x45); - addbyte(cpu_state_offset(ST[(cpu_state.TOP + reg) & 7])); + addbyte((uint8_t)cpu_state_offset(ST[(cpu_state.TOP + reg) & 7])); } else { addbyte(0x8b); /*MOV EBX, TOP*/ addbyte(0x5d); - addbyte(cpu_state_offset(TOP)); + addbyte((uint8_t)cpu_state_offset(TOP)); if (reg) { addbyte(0x83); /*ADD EBX, reg*/ @@ -2400,7 +2399,7 @@ static int FP_LOAD_REG(int reg) addbyte(0xdd); /*FLD ST[EBX*8]*/ addbyte(0x44); addbyte(0xdd); - addbyte(cpu_state_offset(ST)); + addbyte((uint8_t)cpu_state_offset(ST)); } addbyte(0xd9); /*FSTP [ESP]*/ addbyte(0x1c); @@ -2412,19 +2411,19 @@ static int FP_LOAD_REG(int reg) return REG_EBX; } -static void FP_LOAD_REG_D(int reg, int *host_reg1, int *host_reg2) +static inline void FP_LOAD_REG_D(int reg, int *host_reg1, int *host_reg2) { if (codeblock[block_current].flags & CODEBLOCK_STATIC_TOP) { addbyte(0xdd); /*FLD ST[reg][EBP]*/ addbyte(0x45); - addbyte(cpu_state_offset(ST[(cpu_state.TOP + reg) & 7])); + addbyte((uint8_t)cpu_state_offset(ST[(cpu_state.TOP + reg) & 7])); } else { addbyte(0x8b); /*MOV EBX, TOP*/ addbyte(0x5d); - addbyte(cpu_state_offset(TOP)); + addbyte((uint8_t)cpu_state_offset(TOP)); if (reg) { addbyte(0x83); /*ADD EBX, reg*/ @@ -2437,7 +2436,7 @@ static void FP_LOAD_REG_D(int reg, int *host_reg1, int *host_reg2) addbyte(0xdd); /*FLD ST[EBX*8]*/ addbyte(0x44); addbyte(0xdd); - addbyte(cpu_state_offset(ST)); + addbyte((uint8_t)cpu_state_offset(ST)); } addbyte(0xdd); /*FSTP [ESP]*/ addbyte(0x1c); @@ -2454,11 +2453,11 @@ static void FP_LOAD_REG_D(int reg, int *host_reg1, int *host_reg2) *host_reg2 = REG_ECX; } -static int FP_LOAD_REG_INT_W(int reg) +static inline int FP_LOAD_REG_INT_W(int reg) { addbyte(0x8b); /*MOV EBX, TOP*/ addbyte(0x5d); - addbyte(cpu_state_offset(TOP)); + addbyte((uint8_t)cpu_state_offset(TOP)); if (reg) { addbyte(0x83); /*ADD EBX, reg*/ @@ -2471,28 +2470,28 @@ static int FP_LOAD_REG_INT_W(int reg) addbyte(0xdd); /*FLD ST[EBX*8]*/ addbyte(0x44); addbyte(0xdd); - addbyte(cpu_state_offset(ST)); + addbyte((uint8_t)cpu_state_offset(ST)); addbyte(0xd9); /*FLDCW cpu_state.new_npxc*/ addbyte(0x6d); - addbyte(cpu_state_offset(new_npxc)); + addbyte((uint8_t)cpu_state_offset(new_npxc)); addbyte(0xdb); /*FISTP [ESP]*/ addbyte(0x1c); addbyte(0x24); addbyte(0xd9); /*FLDCW cpu_state.old_npxc*/ addbyte(0x6d); - addbyte(cpu_state_offset(old_npxc)); + addbyte((uint8_t)cpu_state_offset(old_npxc)); addbyte(0x8b); /*MOV EBX, [ESP]*/ addbyte(0x1c); addbyte(0x24); return REG_EBX; } -static int FP_LOAD_REG_INT(int reg) +static inline int FP_LOAD_REG_INT(int reg) { addbyte(0x8b); /*MOV EBX, TOP*/ addbyte(0x5d); - addbyte(cpu_state_offset(TOP)); + addbyte((uint8_t)cpu_state_offset(TOP)); if (reg) { addbyte(0x83); /*ADD EBX, reg*/ @@ -2505,28 +2504,28 @@ static int FP_LOAD_REG_INT(int reg) addbyte(0xdd); /*FLD ST[EBX*8]*/ addbyte(0x44); addbyte(0xdd); - addbyte(cpu_state_offset(ST)); + addbyte((uint8_t)cpu_state_offset(ST)); addbyte(0xd9); /*FLDCW cpu_state.new_npxc*/ addbyte(0x6d); - addbyte(cpu_state_offset(new_npxc)); + addbyte((uint8_t)cpu_state_offset(new_npxc)); addbyte(0xdb); /*FISTP [ESP]*/ addbyte(0x1c); addbyte(0x24); addbyte(0xd9); /*FLDCW cpu_state.old_npxc*/ addbyte(0x6d); - addbyte(cpu_state_offset(old_npxc)); + addbyte((uint8_t)cpu_state_offset(old_npxc)); addbyte(0x8b); /*MOV EBX, [ESP]*/ addbyte(0x1c); addbyte(0x24); return REG_EBX; } -static void FP_LOAD_REG_INT_Q(int reg, int *host_reg1, int *host_reg2) +static inline void FP_LOAD_REG_INT_Q(int reg, int *host_reg1, int *host_reg2) { addbyte(0x8b); /*MOV EBX, TOP*/ addbyte(0x5d); - addbyte(cpu_state_offset(TOP)); + addbyte((uint8_t)cpu_state_offset(TOP)); if (reg) { addbyte(0x83); /*ADD EBX, reg*/ @@ -2544,11 +2543,11 @@ static void FP_LOAD_REG_INT_Q(int reg, int *host_reg1, int *host_reg2) addbyte(0x8b); /*MOV ECX, [ST_i64+EBX*8]*/ addbyte(0x4c); addbyte(0xdd); - addbyte(cpu_state_offset(MM)+4); + addbyte((uint8_t)cpu_state_offset(MM)+4); addbyte(0x8b); /*MOV EBX, [ST_i64+EBX*8]*/ addbyte(0x5c); addbyte(0xdd); - addbyte(cpu_state_offset(MM)); + addbyte((uint8_t)cpu_state_offset(MM)); return; } @@ -2556,7 +2555,7 @@ static void FP_LOAD_REG_INT_Q(int reg, int *host_reg1, int *host_reg2) addbyte(0xf6); /*TEST TAG[EBX], TAG_UINT64*/ addbyte(0x44); addbyte(0x1d); - addbyte(cpu_state_offset(tag[0])); + addbyte((uint8_t)cpu_state_offset(tag[0])); addbyte(TAG_UINT64); addbyte(0x74); /*JZ +*/ addbyte(4+4+2); @@ -2564,11 +2563,11 @@ static void FP_LOAD_REG_INT_Q(int reg, int *host_reg1, int *host_reg2) addbyte(0x8b); /*MOV ECX, [ST_i64+EBX*8]*/ addbyte(0x4c); addbyte(0xdd); - addbyte(cpu_state_offset(MM)+4); + addbyte((uint8_t)cpu_state_offset(MM)+4); addbyte(0x8b); /*MOV EBX, [ST_i64+EBX*8]*/ addbyte(0x5c); addbyte(0xdd); - addbyte(cpu_state_offset(MM)); + addbyte((uint8_t)cpu_state_offset(MM)); addbyte(0xeb); /*JMP done*/ addbyte(4+3+3+3+3+4); @@ -2576,17 +2575,17 @@ static void FP_LOAD_REG_INT_Q(int reg, int *host_reg1, int *host_reg2) addbyte(0xdd); /*FLD ST[EBX*8]*/ addbyte(0x44); addbyte(0xdd); - addbyte(cpu_state_offset(ST)); + addbyte((uint8_t)cpu_state_offset(ST)); addbyte(0xd9); /*FLDCW cpu_state.new_npxc*/ addbyte(0x6d); - addbyte(cpu_state_offset(new_npxc)); + addbyte((uint8_t)cpu_state_offset(new_npxc)); addbyte(0xdf); /*FISTPQ [ESP]*/ addbyte(0x3c); addbyte(0x24); addbyte(0xd9); /*FLDCW cpu_state.old_npxc*/ addbyte(0x6d); - addbyte(cpu_state_offset(old_npxc)); + addbyte((uint8_t)cpu_state_offset(old_npxc)); addbyte(0x8b); /*MOV EBX, [ESP]*/ addbyte(0x1c); addbyte(0x24); @@ -2599,28 +2598,28 @@ static void FP_LOAD_REG_INT_Q(int reg, int *host_reg1, int *host_reg2) *host_reg2 = REG_ECX; } -static void FP_POP() +static inline void FP_POP() { if (codeblock[block_current].flags & CODEBLOCK_STATIC_TOP) { addbyte(0xc6); /*MOVB tag[0][EBP], 3*/ addbyte(0x45); - addbyte(cpu_state_offset(tag[cpu_state.TOP])); + addbyte((uint8_t)cpu_state_offset(tag[cpu_state.TOP])); addbyte(3); addbyte(0xc6); /*MOVB TOP[EBP], (TOP-1) & 7*/ addbyte(0x45); - addbyte(cpu_state_offset(TOP)); + addbyte((uint8_t)cpu_state_offset(TOP)); addbyte((cpu_state.TOP + 1) & 7); } else { addbyte(0x8b); /*MOV EAX, TOP*/ addbyte(0x45); - addbyte(cpu_state_offset(TOP)); + addbyte((uint8_t)cpu_state_offset(TOP)); addbyte(0xc6); /*MOVB tag[EAX], 3*/ addbyte(0x44); addbyte(0x05); - addbyte(cpu_state_offset(tag[0])); + addbyte((uint8_t)cpu_state_offset(tag[0])); addbyte(3); addbyte(0x04); /*ADD AL, 1*/ addbyte(1); @@ -2628,35 +2627,35 @@ static void FP_POP() addbyte(7); addbyte(0x88); /*MOV TOP, AL*/ addbyte(0x45); - addbyte(cpu_state_offset(TOP)); + addbyte((uint8_t)cpu_state_offset(TOP)); } } -static void FP_POP2() +static inline void FP_POP2() { if (codeblock[block_current].flags & CODEBLOCK_STATIC_TOP) { addbyte(0xc6); /*MOVB tag[0][EBP], 3*/ addbyte(0x45); - addbyte(cpu_state_offset(tag[cpu_state.TOP])); + addbyte((uint8_t)cpu_state_offset(tag[cpu_state.TOP])); addbyte(3); addbyte(0xc6); /*MOVB tag[1][EBP], 3*/ addbyte(0x45); - addbyte(cpu_state_offset(tag[(cpu_state.TOP+1)&7])); + addbyte((uint8_t)cpu_state_offset(tag[(cpu_state.TOP+1)&7])); addbyte(3); addbyte(0xc6); /*MOVB TOP[EBP], (TOP+2) & 7*/ addbyte(0x45); - addbyte(cpu_state_offset(TOP)); + addbyte((uint8_t)cpu_state_offset(TOP)); addbyte((cpu_state.TOP + 2) & 7); } else { addbyte(0x8b); /*MOV EAX, TOP*/ addbyte(0x45); - addbyte(cpu_state_offset(TOP)); + addbyte((uint8_t)cpu_state_offset(TOP)); addbyte(0xc6); /*MOVB tag[EAX], 3*/ addbyte(0x44); addbyte(0x05); - addbyte(cpu_state_offset(tag[0])); + addbyte((uint8_t)cpu_state_offset(tag[0])); addbyte(3); addbyte(0x04); /*ADD AL, 2*/ addbyte(2); @@ -2664,7 +2663,7 @@ static void FP_POP2() addbyte(7); addbyte(0x88); /*MOV TOP, AL*/ addbyte(0x45); - addbyte(cpu_state_offset(TOP)); + addbyte((uint8_t)cpu_state_offset(TOP)); } } @@ -2675,7 +2674,7 @@ static void FP_POP2() #define FPU_SUB 0x20 #define FPU_SUBR 0x28 -static void FP_OP_S(int op) +static inline void FP_OP_S(int op) { if (codeblock[block_current].flags & CODEBLOCK_STATIC_TOP) { @@ -2684,34 +2683,34 @@ static void FP_OP_S(int op) addbyte(0x24); addbyte(0xdd); /*FLD ST[dst][EBP]*/ addbyte(0x45); - addbyte(cpu_state_offset(ST[cpu_state.TOP])); + addbyte((uint8_t)cpu_state_offset(ST[cpu_state.TOP])); addbyte(0x80); /*AND tag[dst][EBP], ~TAG_UINT64*/ addbyte(0x65); - addbyte(cpu_state_offset(tag[cpu_state.TOP])); + addbyte((uint8_t)cpu_state_offset(tag[cpu_state.TOP])); addbyte(~TAG_UINT64); addbyte(0xd8); /*FADD [ESP]*/ addbyte(0x04 | op); addbyte(0x24); addbyte(0xdd); /*FSTP ST[dst][EBP]*/ addbyte(0x5d); - addbyte(cpu_state_offset(ST[cpu_state.TOP])); + addbyte((uint8_t)cpu_state_offset(ST[cpu_state.TOP])); } else { addbyte(0x8b); /*MOV EBX, TOP*/ addbyte(0x5d); - addbyte(cpu_state_offset(TOP)); + addbyte((uint8_t)cpu_state_offset(TOP)); addbyte(0x89); /*MOV [ESP], EAX*/ addbyte(0x04); addbyte(0x24); addbyte(0xdd); /*FLD ST[EBX*8]*/ addbyte(0x44); addbyte(0xdd); - addbyte(cpu_state_offset(ST)); + addbyte((uint8_t)cpu_state_offset(ST)); addbyte(0x80); /*AND tag[EBX], ~TAG_UINT64*/ addbyte(0x64); addbyte(0x1d); - addbyte(cpu_state_offset(tag[0])); + addbyte((uint8_t)cpu_state_offset(tag[0])); addbyte(~TAG_UINT64); addbyte(0xd8); /*FADD [ESP]*/ addbyte(0x04 | op); @@ -2719,10 +2718,10 @@ static void FP_OP_S(int op) addbyte(0xdd); /*FSTP [ST+EBX*8]*/ addbyte(0x5c); addbyte(0xdd); - addbyte(cpu_state_offset(ST)); + addbyte((uint8_t)cpu_state_offset(ST)); } } -static void FP_OP_D(int op) +static inline void FP_OP_D(int op) { if (codeblock[block_current].flags & CODEBLOCK_STATIC_TOP) { @@ -2737,33 +2736,33 @@ static void FP_OP_D(int op) { addbyte(0xd9); /*FLDCW cpu_state.new_npxc*/ addbyte(0x6d); - addbyte(cpu_state_offset(new_npxc)); + addbyte((uint8_t)cpu_state_offset(new_npxc)); } addbyte(0xdd); /*FLD ST[dst][EBP]*/ addbyte(0x45); - addbyte(cpu_state_offset(ST[cpu_state.TOP])); + addbyte((uint8_t)cpu_state_offset(ST[cpu_state.TOP])); addbyte(0x80); /*AND tag[dst][EBP], ~TAG_UINT64*/ addbyte(0x65); - addbyte(cpu_state_offset(tag[cpu_state.TOP])); + addbyte((uint8_t)cpu_state_offset(tag[cpu_state.TOP])); addbyte(~TAG_UINT64); addbyte(0xdc); /*FADD [ESP]*/ addbyte(0x04 | op); addbyte(0x24); addbyte(0xdd); /*FSTP ST[dst][EBP]*/ addbyte(0x5d); - addbyte(cpu_state_offset(ST[cpu_state.TOP])); + addbyte((uint8_t)cpu_state_offset(ST[cpu_state.TOP])); if (((cpu_state.npxc >> 10) & 3) && op == FPU_ADD) { addbyte(0xd9); /*FLDCW cpu_state.old_npxc*/ addbyte(0x6d); - addbyte(cpu_state_offset(old_npxc)); + addbyte((uint8_t)cpu_state_offset(old_npxc)); } } else { addbyte(0x8b); /*MOV EBX, TOP*/ addbyte(0x5d); - addbyte(cpu_state_offset(TOP)); + addbyte((uint8_t)cpu_state_offset(TOP)); addbyte(0x89); /*MOV [ESP], EAX*/ addbyte(0x04); addbyte(0x24); @@ -2771,7 +2770,7 @@ static void FP_OP_D(int op) { addbyte(0xd9); /*FLDCW cpu_state.new_npxc*/ addbyte(0x6d); - addbyte(cpu_state_offset(new_npxc)); + addbyte((uint8_t)cpu_state_offset(new_npxc)); } addbyte(0x89); /*MOV [ESP+4], EDX*/ addbyte(0x54); @@ -2780,11 +2779,11 @@ static void FP_OP_D(int op) addbyte(0xdd); /*FLD ST[EBX*8]*/ addbyte(0x44); addbyte(0xdd); - addbyte(cpu_state_offset(ST)); + addbyte((uint8_t)cpu_state_offset(ST)); addbyte(0x80); /*AND tag[EBX], ~TAG_UINT64*/ addbyte(0x64); addbyte(0x1d); - addbyte(cpu_state_offset(tag[0])); + addbyte((uint8_t)cpu_state_offset(tag[0])); addbyte(~TAG_UINT64); addbyte(0xdc); /*FADD [ESP]*/ addbyte(0x04 | op); @@ -2792,16 +2791,16 @@ static void FP_OP_D(int op) addbyte(0xdd); /*FSTP [ST+EBX*8]*/ addbyte(0x5c); addbyte(0xdd); - addbyte(cpu_state_offset(ST)); + addbyte((uint8_t)cpu_state_offset(ST)); if (((cpu_state.npxc >> 10) & 3) && op == FPU_ADD) { addbyte(0xd9); /*FLDCW cpu_state.old_npxc*/ addbyte(0x6d); - addbyte(cpu_state_offset(old_npxc)); + addbyte((uint8_t)cpu_state_offset(old_npxc)); } } } -static void FP_OP_IW(int op) +static inline void FP_OP_IW(int op) { if (codeblock[block_current].flags & CODEBLOCK_STATIC_TOP) { @@ -2811,34 +2810,34 @@ static void FP_OP_IW(int op) addbyte(0x24); addbyte(0xdd); /*FLD ST[0][EBP]*/ addbyte(0x45); - addbyte(cpu_state_offset(ST[cpu_state.TOP])); + addbyte((uint8_t)cpu_state_offset(ST[cpu_state.TOP])); addbyte(0x80); /*AND tag[0][EBP], ~TAG_UINT64*/ addbyte(0x65); - addbyte(cpu_state_offset(tag[cpu_state.TOP])); + addbyte((uint8_t)cpu_state_offset(tag[cpu_state.TOP])); addbyte(~TAG_UINT64); addbyte(0xde); /*FADD [ESP]*/ addbyte(0x04 | op); addbyte(0x24); addbyte(0xdd); /*FSTP ST[0][EBP]*/ addbyte(0x5d); - addbyte(cpu_state_offset(ST[cpu_state.TOP])); + addbyte((uint8_t)cpu_state_offset(ST[cpu_state.TOP])); } else { addbyte(0x8b); /*MOV EBX, TOP*/ addbyte(0x5d); - addbyte(cpu_state_offset(TOP)); + addbyte((uint8_t)cpu_state_offset(TOP)); addbyte(0x89); /*MOV [ESP], EAX*/ addbyte(0x04); addbyte(0x24); addbyte(0xdd); /*FLD ST[EBX*8]*/ addbyte(0x44); addbyte(0xdd); - addbyte(cpu_state_offset(ST)); + addbyte((uint8_t)cpu_state_offset(ST)); addbyte(0x80); /*AND tag[EBX], ~TAG_UINT64*/ addbyte(0x64); addbyte(0x1d); - addbyte(cpu_state_offset(tag[0])); + addbyte((uint8_t)cpu_state_offset(tag[0])); addbyte(~TAG_UINT64); addbyte(0xde); /*FADD [ESP]*/ addbyte(0x04 | op); @@ -2846,10 +2845,10 @@ static void FP_OP_IW(int op) addbyte(0xdd); /*FSTP [ST+EBX*8]*/ addbyte(0x5c); addbyte(0xdd); - addbyte(cpu_state_offset(ST)); + addbyte((uint8_t)cpu_state_offset(ST)); } } -static void FP_OP_IL(int op) +static inline void FP_OP_IL(int op) { if (codeblock[block_current].flags & CODEBLOCK_STATIC_TOP) { @@ -2858,34 +2857,34 @@ static void FP_OP_IL(int op) addbyte(0x24); addbyte(0xdd); /*FLD ST[0][EBP]*/ addbyte(0x45); - addbyte(cpu_state_offset(ST[cpu_state.TOP])); + addbyte((uint8_t)cpu_state_offset(ST[cpu_state.TOP])); addbyte(0x80); /*AND tag[0][EBP], ~TAG_UINT64*/ addbyte(0x65); - addbyte(cpu_state_offset(tag[cpu_state.TOP])); + addbyte((uint8_t)cpu_state_offset(tag[cpu_state.TOP])); addbyte(~TAG_UINT64); addbyte(0xda); /*FADD [ESP]*/ addbyte(0x04 | op); addbyte(0x24); addbyte(0xdd); /*FSTP ST[0][EBP]*/ addbyte(0x5d); - addbyte(cpu_state_offset(ST[cpu_state.TOP])); + addbyte((uint8_t)cpu_state_offset(ST[cpu_state.TOP])); } else { addbyte(0x8b); /*MOV EBX, TOP*/ addbyte(0x5d); - addbyte(cpu_state_offset(TOP)); + addbyte((uint8_t)cpu_state_offset(TOP)); addbyte(0x89); /*MOV [ESP], EAX*/ addbyte(0x04); addbyte(0x24); addbyte(0xdd); /*FLD ST[EBX*8]*/ addbyte(0x44); addbyte(0xdd); - addbyte(cpu_state_offset(ST)); + addbyte((uint8_t)cpu_state_offset(ST)); addbyte(0x80); /*AND tag[EBX], ~TAG_UINT64*/ addbyte(0x64); addbyte(0x1d); - addbyte(cpu_state_offset(tag[0])); + addbyte((uint8_t)cpu_state_offset(tag[0])); addbyte(~TAG_UINT64); addbyte(0xda); /*FADD [ESP]*/ addbyte(0x04 | op); @@ -2893,10 +2892,11 @@ static void FP_OP_IL(int op) addbyte(0xdd); /*FSTP [ST+EBX*8]*/ addbyte(0x5c); addbyte(0xdd); - addbyte(cpu_state_offset(ST)); + addbyte((uint8_t)cpu_state_offset(ST)); } } -static void FP_OP_IQ(int op) +#if 0 +static inline void FP_OP_IQ(int op) { if (codeblock[block_current].flags & CODEBLOCK_STATIC_TOP) { @@ -2909,23 +2909,23 @@ static void FP_OP_IQ(int op) addbyte(0x04); addbyte(0xdd); /*FLD ST[0][EBP]*/ addbyte(0x45); - addbyte(cpu_state_offset(ST[cpu_state.TOP])); + addbyte((uint8_t)cpu_state_offset(ST[cpu_state.TOP])); addbyte(0x80); /*AND tag[0][EBP], ~TAG_UINT64*/ addbyte(0x65); - addbyte(cpu_state_offset(tag[cpu_state.TOP])); + addbyte((uint8_t)cpu_state_offset(tag[cpu_state.TOP])); addbyte(~TAG_UINT64); addbyte(0xdc); /*FADD [ESP]*/ addbyte(0x04 | op); addbyte(0x24); addbyte(0xdd); /*FSTP ST[0][EBP]*/ addbyte(0x5d); - addbyte(cpu_state_offset(ST[cpu_state.TOP])); + addbyte((uint8_t)cpu_state_offset(ST[cpu_state.TOP])); } else { addbyte(0x8b); /*MOV EBX, TOP*/ addbyte(0x5d); - addbyte(cpu_state_offset(TOP)); + addbyte((uint8_t)cpu_state_offset(TOP)); addbyte(0x89); /*MOV [ESP], EAX*/ addbyte(0x04); addbyte(0x24); @@ -2936,11 +2936,11 @@ static void FP_OP_IQ(int op) addbyte(0xdd); /*FLD ST[EBX*8]*/ addbyte(0x44); addbyte(0xdd); - addbyte(cpu_state_offset(ST)); + addbyte((uint8_t)cpu_state_offset(ST)); addbyte(0x80); /*AND tag[EBX], ~TAG_UINT64*/ addbyte(0x64); addbyte(0x1d); - addbyte(cpu_state_offset(tag[0])); + addbyte((uint8_t)cpu_state_offset(tag[0])); addbyte(~TAG_UINT64); addbyte(0xdc); /*FADD [ESP]*/ addbyte(0x04 | op); @@ -2948,16 +2948,16 @@ static void FP_OP_IQ(int op) addbyte(0xdd); /*FSTP [ST+EBX*8]*/ addbyte(0x5c); addbyte(0xdd); - addbyte(cpu_state_offset(ST)); + addbyte((uint8_t)cpu_state_offset(ST)); } } - +#endif #define C0 (1<<8) #define C1 (1<<9) #define C2 (1<<10) #define C3 (1<<14) -static void FP_COMPARE_S() +static inline void FP_COMPARE_S() { if (codeblock[block_current].flags & CODEBLOCK_STATIC_TOP) { @@ -2966,10 +2966,10 @@ static void FP_COMPARE_S() addbyte(0x24); addbyte(0xdd); /*FLD ST[0][EBP]*/ addbyte(0x45); - addbyte(cpu_state_offset(ST[cpu_state.TOP])); + addbyte((uint8_t)cpu_state_offset(ST[cpu_state.TOP])); addbyte(0x8a); /*MOV BL, [npxs+1]*/ addbyte(0x5d); - addbyte(cpu_state_offset(npxs) + 1); + addbyte((uint8_t)cpu_state_offset(npxs) + 1); addbyte(0xdb); /*FCLEX*/ addbyte(0xe2); addbyte(0x80); /*AND BL, ~(C0|C2|C3)*/ @@ -2987,23 +2987,23 @@ static void FP_COMPARE_S() addbyte(0xe3); addbyte(0x88); /*MOV [npxs+1], BL*/ addbyte(0x5d); - addbyte(cpu_state_offset(npxs) + 1); + addbyte((uint8_t)cpu_state_offset(npxs) + 1); } else { addbyte(0x8b); /*MOV EBX, TOP*/ addbyte(0x5d); - addbyte(cpu_state_offset(TOP)); + addbyte((uint8_t)cpu_state_offset(TOP)); addbyte(0x89); /*MOV [ESP], EAX*/ addbyte(0x04); addbyte(0x24); addbyte(0xdd); /*FLD ST[EBX*8]*/ addbyte(0x44); addbyte(0xdd); - addbyte(cpu_state_offset(ST)); + addbyte((uint8_t)cpu_state_offset(ST)); addbyte(0x8a); /*MOV BL, [npxs+1]*/ addbyte(0x5d); - addbyte(cpu_state_offset(npxs) + 1); + addbyte((uint8_t)cpu_state_offset(npxs) + 1); addbyte(0xdb); /*FCLEX*/ addbyte(0xe2); addbyte(0x80); /*AND BL, ~(C0|C2|C3)*/ @@ -3021,10 +3021,10 @@ static void FP_COMPARE_S() addbyte(0xe3); addbyte(0x88); /*MOV [npxs+1], BL*/ addbyte(0x5d); - addbyte(cpu_state_offset(npxs) + 1); + addbyte((uint8_t)cpu_state_offset(npxs) + 1); } } -static void FP_COMPARE_D() +static inline void FP_COMPARE_D() { if (codeblock[block_current].flags & CODEBLOCK_STATIC_TOP) { @@ -3037,10 +3037,10 @@ static void FP_COMPARE_D() addbyte(0x04); addbyte(0xdd); /*FLD ST[0][EBP]*/ addbyte(0x45); - addbyte(cpu_state_offset(ST[cpu_state.TOP])); + addbyte((uint8_t)cpu_state_offset(ST[cpu_state.TOP])); addbyte(0x8a); /*MOV BL, [npxs+1]*/ addbyte(0x5d); - addbyte(cpu_state_offset(npxs) + 1); + addbyte((uint8_t)cpu_state_offset(npxs) + 1); addbyte(0xdb); /*FCLEX*/ addbyte(0xe2); addbyte(0x80); /*AND BL, ~(C0|C2|C3)*/ @@ -3058,13 +3058,13 @@ static void FP_COMPARE_D() addbyte(0xe3); addbyte(0x88); /*MOV [npxs+1], BL*/ addbyte(0x5d); - addbyte(cpu_state_offset(npxs) + 1); + addbyte((uint8_t)cpu_state_offset(npxs) + 1); } else { addbyte(0x8b); /*MOV EBX, TOP*/ addbyte(0x5d); - addbyte(cpu_state_offset(TOP)); + addbyte((uint8_t)cpu_state_offset(TOP)); addbyte(0x89); /*MOV [ESP], EAX*/ addbyte(0x04); addbyte(0x24); @@ -3075,10 +3075,10 @@ static void FP_COMPARE_D() addbyte(0xdd); /*FLD ST[EBX*8]*/ addbyte(0x44); addbyte(0xdd); - addbyte(cpu_state_offset(ST)); + addbyte((uint8_t)cpu_state_offset(ST)); addbyte(0x8a); /*MOV BL, [npxs+1]*/ addbyte(0x5d); - addbyte(cpu_state_offset(npxs) + 1); + addbyte((uint8_t)cpu_state_offset(npxs) + 1); addbyte(0xdb); /*FCLEX*/ addbyte(0xe2); addbyte(0x80); /*AND BL, ~(C0|C2|C3)*/ @@ -3096,10 +3096,10 @@ static void FP_COMPARE_D() addbyte(0xe3); addbyte(0x88); /*MOV [npxs+1], BL*/ addbyte(0x5d); - addbyte(cpu_state_offset(npxs) + 1); + addbyte((uint8_t)cpu_state_offset(npxs) + 1); } } -static void FP_COMPARE_IW() +static inline void FP_COMPARE_IW() { if (codeblock[block_current].flags & CODEBLOCK_STATIC_TOP) { @@ -3109,10 +3109,10 @@ static void FP_COMPARE_IW() addbyte(0x24); addbyte(0xdd); /*FLD ST[0][EBP]*/ addbyte(0x45); - addbyte(cpu_state_offset(ST[cpu_state.TOP])); + addbyte((uint8_t)cpu_state_offset(ST[cpu_state.TOP])); addbyte(0x8a); /*MOV BL, [npxs+1]*/ addbyte(0x5d); - addbyte(cpu_state_offset(npxs) + 1); + addbyte((uint8_t)cpu_state_offset(npxs) + 1); addbyte(0xdb); /*FCLEX*/ addbyte(0xe2); addbyte(0x80); /*AND BL, ~(C0|C2|C3)*/ @@ -3130,23 +3130,23 @@ static void FP_COMPARE_IW() addbyte(0xe3); addbyte(0x88); /*MOV [npxs+1], BL*/ addbyte(0x5d); - addbyte(cpu_state_offset(npxs) + 1); + addbyte((uint8_t)cpu_state_offset(npxs) + 1); } else { addbyte(0x8b); /*MOV EBX, TOP*/ addbyte(0x5d); - addbyte(cpu_state_offset(TOP)); + addbyte((uint8_t)cpu_state_offset(TOP)); addbyte(0x89); /*MOV [ESP], EAX*/ addbyte(0x04); addbyte(0x24); addbyte(0xdd); /*FLD ST[EBX*8]*/ addbyte(0x44); addbyte(0xdd); - addbyte(cpu_state_offset(ST)); + addbyte((uint8_t)cpu_state_offset(ST)); addbyte(0x8a); /*MOV BL, [npxs+1]*/ addbyte(0x5d); - addbyte(cpu_state_offset(npxs) + 1); + addbyte((uint8_t)cpu_state_offset(npxs) + 1); addbyte(0xdb); /*FCLEX*/ addbyte(0xe2); addbyte(0x80); /*AND BL, ~(C0|C2|C3)*/ @@ -3164,10 +3164,10 @@ static void FP_COMPARE_IW() addbyte(0xe3); addbyte(0x88); /*MOV [npxs+1], BL*/ addbyte(0x5d); - addbyte(cpu_state_offset(npxs) + 1); + addbyte((uint8_t)cpu_state_offset(npxs) + 1); } } -static void FP_COMPARE_IL() +static inline void FP_COMPARE_IL() { if (codeblock[block_current].flags & CODEBLOCK_STATIC_TOP) { @@ -3176,10 +3176,10 @@ static void FP_COMPARE_IL() addbyte(0x24); addbyte(0xdd); /*FLD ST[0][EBP]*/ addbyte(0x45); - addbyte(cpu_state_offset(ST[cpu_state.TOP])); + addbyte((uint8_t)cpu_state_offset(ST[cpu_state.TOP])); addbyte(0x8a); /*MOV BL, [npxs+1]*/ addbyte(0x5d); - addbyte(cpu_state_offset(npxs) + 1); + addbyte((uint8_t)cpu_state_offset(npxs) + 1); addbyte(0xdb); /*FCLEX*/ addbyte(0xe2); addbyte(0x80); /*AND BL, ~(C0|C2|C3)*/ @@ -3197,23 +3197,23 @@ static void FP_COMPARE_IL() addbyte(0xe3); addbyte(0x88); /*MOV [npxs+1], BL*/ addbyte(0x5d); - addbyte(cpu_state_offset(npxs) + 1); + addbyte((uint8_t)cpu_state_offset(npxs) + 1); } else { addbyte(0x8b); /*MOV EBX, TOP*/ addbyte(0x5d); - addbyte(cpu_state_offset(TOP)); + addbyte((uint8_t)cpu_state_offset(TOP)); addbyte(0x89); /*MOV [ESP], EAX*/ addbyte(0x04); addbyte(0x24); addbyte(0xdd); /*FLD ST[EBX*8]*/ addbyte(0x44); addbyte(0xdd); - addbyte(cpu_state_offset(ST)); + addbyte((uint8_t)cpu_state_offset(ST)); addbyte(0x8a); /*MOV BL, [npxs+1]*/ addbyte(0x5d); - addbyte(cpu_state_offset(npxs) + 1); + addbyte((uint8_t)cpu_state_offset(npxs) + 1); addbyte(0xdb); /*FCLEX*/ addbyte(0xe2); addbyte(0x80); /*AND BL, ~(C0|C2|C3)*/ @@ -3231,33 +3231,33 @@ static void FP_COMPARE_IL() addbyte(0xe3); addbyte(0x88); /*MOV [npxs+1], BL*/ addbyte(0x5d); - addbyte(cpu_state_offset(npxs) + 1); + addbyte((uint8_t)cpu_state_offset(npxs) + 1); } } -static void FP_OP_REG(int op, int dst, int src) +static inline void FP_OP_REG(int op, int dst, int src) { if (codeblock[block_current].flags & CODEBLOCK_STATIC_TOP) { addbyte(0xdd); /*FLD ST[dst][EBP]*/ addbyte(0x45); - addbyte(cpu_state_offset(ST[(cpu_state.TOP + dst) & 7])); + addbyte((uint8_t)cpu_state_offset(ST[(cpu_state.TOP + dst) & 7])); addbyte(0xdc); /*FADD ST[src][EBP]*/ addbyte(0x45 | op); - addbyte(cpu_state_offset(ST[(cpu_state.TOP + src) & 7])); + addbyte((uint8_t)cpu_state_offset(ST[(cpu_state.TOP + src) & 7])); addbyte(0x80); /*AND tag[dst][EBP], ~TAG_UINT64*/ addbyte(0x65); - addbyte(cpu_state_offset(tag[(cpu_state.TOP + dst) & 7])); + addbyte((uint8_t)cpu_state_offset(tag[(cpu_state.TOP + dst) & 7])); addbyte(~TAG_UINT64); addbyte(0xdd); /*FSTP ST[dst][EBP]*/ addbyte(0x5d); - addbyte(cpu_state_offset(ST[(cpu_state.TOP + dst) & 7])); + addbyte((uint8_t)cpu_state_offset(ST[(cpu_state.TOP + dst) & 7])); } else { addbyte(0x8b); /*MOV EAX, TOP*/ addbyte(0x45); - addbyte(cpu_state_offset(TOP)); + addbyte((uint8_t)cpu_state_offset(TOP)); addbyte(0x89); /*MOV EBX, EAX*/ addbyte(0xc3); if (src || dst) @@ -3275,62 +3275,62 @@ static void FP_OP_REG(int op, int dst, int src) addbyte(0xdd); /*FLD ST[EBX*8]*/ addbyte(0x44); addbyte(0xdd); - addbyte(cpu_state_offset(ST)); + addbyte((uint8_t)cpu_state_offset(ST)); addbyte(0x80); /*AND tag[EBX], ~TAG_UINT64*/ addbyte(0x64); addbyte(0x1d); - addbyte(cpu_state_offset(tag[0])); + addbyte((uint8_t)cpu_state_offset(tag[0])); addbyte(~TAG_UINT64); addbyte(0xdc); /*FADD ST[EAX*8]*/ addbyte(0x44 | op); addbyte(0xc5); - addbyte(cpu_state_offset(ST)); + addbyte((uint8_t)cpu_state_offset(ST)); addbyte(0xdd); /*FSTP ST[EBX*8]*/ addbyte(0x5c); addbyte(0xdd); - addbyte(cpu_state_offset(ST)); + addbyte((uint8_t)cpu_state_offset(ST)); } else { addbyte(0xdd); /*FLD [ESI+EAX*8]*/ addbyte(0x44); addbyte(0xc5); - addbyte(cpu_state_offset(ST)); + addbyte((uint8_t)cpu_state_offset(ST)); addbyte(0x80); /*AND tag[EAX], ~TAG_UINT64*/ addbyte(0x64); addbyte(0x05); - addbyte(cpu_state_offset(tag[0])); + addbyte((uint8_t)cpu_state_offset(tag[0])); addbyte(~TAG_UINT64); addbyte(0xdc); /*FADD ST[EBX*8]*/ addbyte(0x44 | op); addbyte(0xdd); - addbyte(cpu_state_offset(ST)); + addbyte((uint8_t)cpu_state_offset(ST)); addbyte(0xdd); /*FSTP ST[EAX*8]*/ addbyte(0x5c); addbyte(0xc5); - addbyte(cpu_state_offset(ST)); + addbyte((uint8_t)cpu_state_offset(ST)); } } } -static void FP_COMPARE_REG(int dst, int src) +static inline void FP_COMPARE_REG(int dst, int src) { if (codeblock[block_current].flags & CODEBLOCK_STATIC_TOP) { addbyte(0x8a); /*MOV CL, [npxs+1]*/ addbyte(0x4d); - addbyte(cpu_state_offset(npxs) + 1); + addbyte((uint8_t)cpu_state_offset(npxs) + 1); addbyte(0xdb); /*FCLEX*/ addbyte(0xe2); addbyte(0xdd); /*FLD ST[dst][EBP]*/ addbyte(0x45); - addbyte(cpu_state_offset(ST[(cpu_state.TOP + dst) & 7])); + addbyte((uint8_t)cpu_state_offset(ST[(cpu_state.TOP + dst) & 7])); addbyte(0x80); /*AND CL, ~(C0|C2|C3)*/ addbyte(0xe1); addbyte((~(C0|C2|C3)) >> 8); addbyte(0xdc); /*FCOMP ST[src][EBP]*/ addbyte(0x5d); - addbyte(cpu_state_offset(ST[(cpu_state.TOP + src) & 7])); + addbyte((uint8_t)cpu_state_offset(ST[(cpu_state.TOP + src) & 7])); addbyte(0xdf); /*FSTSW AX*/ addbyte(0xe0); addbyte(0x80); /*AND AH, (C0|C2|C3)*/ @@ -3340,13 +3340,13 @@ static void FP_COMPARE_REG(int dst, int src) addbyte(0xe1); addbyte(0x88); /*MOV [npxs+1], CL*/ addbyte(0x4d); - addbyte(cpu_state_offset(npxs) + 1); + addbyte((uint8_t)cpu_state_offset(npxs) + 1); } else { addbyte(0x8b); /*MOV EAX, TOP*/ addbyte(0x45); - addbyte(cpu_state_offset(TOP)); + addbyte((uint8_t)cpu_state_offset(TOP)); addbyte(0x89); /*MOV EBX, EAX*/ addbyte(0xc3); if (src || dst) @@ -3361,7 +3361,7 @@ static void FP_COMPARE_REG(int dst, int src) addbyte(0x8a); /*MOV CL, [npxs+1]*/ addbyte(0x4d); - addbyte(cpu_state_offset(npxs) + 1); + addbyte((uint8_t)cpu_state_offset(npxs) + 1); addbyte(0xdb); /*FCLEX*/ addbyte(0xe2); addbyte(0x80); /*AND CL, ~(C0|C2|C3)*/ @@ -3373,22 +3373,22 @@ static void FP_COMPARE_REG(int dst, int src) addbyte(0xdd); /*FLD ST[EBX*8]*/ addbyte(0x44); addbyte(0xdd); - addbyte(cpu_state_offset(ST)); + addbyte((uint8_t)cpu_state_offset(ST)); addbyte(0xdc); /*FCOMP ST[EAX*8]*/ addbyte(0x44 | 0x18); addbyte(0xc5); - addbyte(cpu_state_offset(ST)); + addbyte((uint8_t)cpu_state_offset(ST)); } else { addbyte(0xdd); /*FLD [ESI+EAX*8]*/ addbyte(0x44); addbyte(0xc5); - addbyte(cpu_state_offset(ST)); + addbyte((uint8_t)cpu_state_offset(ST)); addbyte(0xdc); /*FCOMP ST[EBX*8]*/ addbyte(0x44 | 0x18); addbyte(0xdd); - addbyte(cpu_state_offset(ST)); + addbyte((uint8_t)cpu_state_offset(ST)); } addbyte(0xdf); /*FSTSW AX*/ @@ -3400,57 +3400,57 @@ static void FP_COMPARE_REG(int dst, int src) addbyte(0xe1); addbyte(0x88); /*MOV [npxs+1], CL*/ addbyte(0x4d); - addbyte(cpu_state_offset(npxs) + 1); + addbyte((uint8_t)cpu_state_offset(npxs) + 1); } } -static void FP_FCHS() +static inline void FP_FCHS() { if (codeblock[block_current].flags & CODEBLOCK_STATIC_TOP) { addbyte(0xdd); /*FLD ST[0][EBP]*/ addbyte(0x45); - addbyte(cpu_state_offset(ST[cpu_state.TOP])); + addbyte((uint8_t)cpu_state_offset(ST[cpu_state.TOP])); addbyte(0xd9); /*FCHS*/ addbyte(0xe0); addbyte(0x80); /*AND tag[dst][EBP], ~TAG_UINT64*/ addbyte(0x65); - addbyte(cpu_state_offset(tag[cpu_state.TOP])); + addbyte((uint8_t)cpu_state_offset(tag[cpu_state.TOP])); addbyte(~TAG_UINT64); addbyte(0xdd); /*FSTP ST[dst][EBP]*/ addbyte(0x5d); - addbyte(cpu_state_offset(ST[cpu_state.TOP])); + addbyte((uint8_t)cpu_state_offset(ST[cpu_state.TOP])); } else { addbyte(0x8b); /*MOV EAX, TOP*/ addbyte(0x45); - addbyte(cpu_state_offset(TOP)); + addbyte((uint8_t)cpu_state_offset(TOP)); addbyte(0xdd); /*FLD [ESI+EAX*8]*/ addbyte(0x44); addbyte(0xc5); - addbyte(cpu_state_offset(ST)); + addbyte((uint8_t)cpu_state_offset(ST)); addbyte(0x80); /*AND tag[EAX], ~TAG_UINT64*/ addbyte(0x64); addbyte(0x05); - addbyte(cpu_state_offset(tag[0])); + addbyte((uint8_t)cpu_state_offset(tag[0])); addbyte(~TAG_UINT64); addbyte(0xd9); /*FCHS*/ addbyte(0xe0); addbyte(0xdd); /*FSTP ST[EAX*8]*/ addbyte(0x5c); addbyte(0xc5); - addbyte(cpu_state_offset(ST)); + addbyte((uint8_t)cpu_state_offset(ST)); } } -static void UPDATE_NPXC(int reg) +static inline void UPDATE_NPXC(int reg) { addbyte(0x66); /*AND cpu_state.new_npxc, ~0xc00*/ addbyte(0x81); addbyte(0x65); - addbyte(cpu_state_offset(new_npxc)); + addbyte((uint8_t)cpu_state_offset(new_npxc)); addword(~0xc00); if (reg) { @@ -3468,24 +3468,24 @@ static void UPDATE_NPXC(int reg) addbyte(0x66); /*OR cpu_state.new_npxc, reg*/ addbyte(0x09); addbyte(0x45 | (reg << 3)); - addbyte(cpu_state_offset(new_npxc)); + addbyte((uint8_t)cpu_state_offset(new_npxc)); } -static int ZERO_EXTEND_W_B(int reg) +static inline int ZERO_EXTEND_W_B(int reg) { addbyte(0x0f); /*MOVZX regl, regb*/ addbyte(0xb6); addbyte(0xc0 | reg | (reg << 3)); return reg; } -static int ZERO_EXTEND_L_B(int reg) +static inline int ZERO_EXTEND_L_B(int reg) { addbyte(0x0f); /*MOVZX regl, regb*/ addbyte(0xb6); addbyte(0xc0 | reg | (reg << 3)); return reg; } -static int ZERO_EXTEND_L_W(int reg) +static inline int ZERO_EXTEND_L_W(int reg) { addbyte(0x0f); /*MOVZX regl, regw*/ addbyte(0xb7); @@ -3493,21 +3493,21 @@ static int ZERO_EXTEND_L_W(int reg) return reg; } -static int SIGN_EXTEND_W_B(int reg) +static inline int SIGN_EXTEND_W_B(int reg) { addbyte(0x0f); /*MOVSX regl, regb*/ addbyte(0xbe); addbyte(0xc0 | reg | (reg << 3)); return reg; } -static int SIGN_EXTEND_L_B(int reg) +static inline int SIGN_EXTEND_L_B(int reg) { addbyte(0x0f); /*MOVSX regl, regb*/ addbyte(0xbe); addbyte(0xc0 | reg | (reg << 3)); return reg; } -static int SIGN_EXTEND_L_W(int reg) +static inline int SIGN_EXTEND_L_W(int reg) { addbyte(0x0f); /*MOVSX regl, regw*/ addbyte(0xbf); @@ -3515,12 +3515,12 @@ static int SIGN_EXTEND_L_W(int reg) return reg; } -static int COPY_REG(int src_reg) +static inline int COPY_REG(int src_reg) { return src_reg; } -static void SET_BITS(uintptr_t addr, uint32_t val) +static inline void SET_BITS(uintptr_t addr, uint32_t val) { if (val & ~0xff) { @@ -3537,7 +3537,7 @@ static void SET_BITS(uintptr_t addr, uint32_t val) addbyte(val); } } -static void CLEAR_BITS(uintptr_t addr, uint32_t val) +static inline void CLEAR_BITS(uintptr_t addr, uint32_t val) { if (val & ~0xff) { @@ -3558,7 +3558,7 @@ static void CLEAR_BITS(uintptr_t addr, uint32_t val) #define LOAD_Q_REG_1 REG_EAX #define LOAD_Q_REG_2 REG_EDX -static void MMX_ENTER() +static inline void MMX_ENTER() { if (codegen_mmx_entered) return; @@ -3571,7 +3571,7 @@ static void MMX_ENTER() addbyte(7+7+5+5); addbyte(0xC7); /*MOVL [oldpc],op_old_pc*/ addbyte(0x45); - addbyte(cpu_state_offset(oldpc)); + addbyte((uint8_t)cpu_state_offset(oldpc)); addlong(op_old_pc); addbyte(0xc7); /*MOV [ESP], 7*/ addbyte(0x04); @@ -3586,35 +3586,35 @@ static void MMX_ENTER() addbyte(0xc0); addbyte(0xc6); /*MOV ISMMX, 1*/ addbyte(0x45); - addbyte(cpu_state_offset(ismmx)); + addbyte((uint8_t)cpu_state_offset(ismmx)); addbyte(1); addbyte(0x89); /*MOV TOP, EAX*/ addbyte(0x45); - addbyte(cpu_state_offset(TOP)); + addbyte((uint8_t)cpu_state_offset(TOP)); addbyte(0x89); /*MOV tag, EAX*/ addbyte(0x45); - addbyte(cpu_state_offset(tag[0])); + addbyte((uint8_t)cpu_state_offset(tag[0])); addbyte(0x89); /*MOV tag+4, EAX*/ addbyte(0x45); - addbyte(cpu_state_offset(tag[4])); + addbyte((uint8_t)cpu_state_offset(tag[4])); codegen_mmx_entered = 1; } extern int mmx_ebx_ecx_loaded; -static int LOAD_MMX_D(int guest_reg) +static inline int LOAD_MMX_D(int guest_reg) { int host_reg = find_host_reg(); host_reg_mapping[host_reg] = 100; addbyte(0x8b); /*MOV EBX, reg*/ addbyte(0x45 | (host_reg << 3)); - addbyte(cpu_state_offset(MM[guest_reg].l[0])); + addbyte((uint8_t)cpu_state_offset(MM[guest_reg].l[0])); return host_reg; } -static int LOAD_MMX_Q(int guest_reg, int *host_reg1, int *host_reg2) +static inline void LOAD_MMX_Q(int guest_reg, int *host_reg1, int *host_reg2) { if (!mmx_ebx_ecx_loaded) { @@ -3630,12 +3630,12 @@ static int LOAD_MMX_Q(int guest_reg, int *host_reg1, int *host_reg2) addbyte(0x8b); /*MOV EBX, reg*/ addbyte(0x45 | ((*host_reg1) << 3)); - addbyte(cpu_state_offset(MM[guest_reg].l[0])); + addbyte((uint8_t)cpu_state_offset(MM[guest_reg].l[0])); addbyte(0x8b); /*MOV ECX, reg+4*/ addbyte(0x45 | ((*host_reg2) << 3)); - addbyte(cpu_state_offset(MM[guest_reg].l[1])); + addbyte((uint8_t)cpu_state_offset(MM[guest_reg].l[1])); } -static int LOAD_MMX_Q_MMX(int guest_reg) +static inline int LOAD_MMX_Q_MMX(int guest_reg) { int dst_reg = find_host_xmm_reg(); host_reg_xmm_mapping[dst_reg] = guest_reg; @@ -3644,12 +3644,12 @@ static int LOAD_MMX_Q_MMX(int guest_reg) addbyte(0x0f); addbyte(0x7e); addbyte(0x45 | (dst_reg << 3)); - addbyte(cpu_state_offset(MM[guest_reg].q)); + addbyte((uint8_t)cpu_state_offset(MM[guest_reg].q)); return dst_reg; } -static int LOAD_INT_TO_MMX(int src_reg1, int src_reg2) +static inline int LOAD_INT_TO_MMX(int src_reg1, int src_reg2) { int dst_reg = find_host_xmm_reg(); host_reg_xmm_mapping[dst_reg] = 100; @@ -3670,36 +3670,36 @@ static int LOAD_INT_TO_MMX(int src_reg1, int src_reg2) return dst_reg; } -static void STORE_MMX_LQ(int guest_reg, int host_reg1) +static inline void STORE_MMX_LQ(int guest_reg, int host_reg1) { addbyte(0xC7); /*MOVL [reg],0*/ addbyte(0x45); - addbyte(cpu_state_offset(MM[guest_reg].l[1])); + addbyte((uint8_t)cpu_state_offset(MM[guest_reg].l[1])); addlong(0); addbyte(0x89); /*MOVL [reg],host_reg*/ addbyte(0x45 | (host_reg1 << 3)); - addbyte(cpu_state_offset(MM[guest_reg].l[0])); + addbyte((uint8_t)cpu_state_offset(MM[guest_reg].l[0])); } -static void STORE_MMX_Q(int guest_reg, int host_reg1, int host_reg2) +static inline void STORE_MMX_Q(int guest_reg, int host_reg1, int host_reg2) { addbyte(0x89); /*MOVL [reg],host_reg*/ addbyte(0x45 | (host_reg1 << 3)); - addbyte(cpu_state_offset(MM[guest_reg].l[0])); + addbyte((uint8_t)cpu_state_offset(MM[guest_reg].l[0])); addbyte(0x89); /*MOVL [reg],host_reg*/ addbyte(0x45 | (host_reg2 << 3)); - addbyte(cpu_state_offset(MM[guest_reg].l[1])); + addbyte((uint8_t)cpu_state_offset(MM[guest_reg].l[1])); } -static void STORE_MMX_Q_MMX(int guest_reg, int host_reg) +static inline void STORE_MMX_Q_MMX(int guest_reg, int host_reg) { addbyte(0x66); /*MOVQ [guest_reg],host_reg*/ addbyte(0x0f); addbyte(0xd6); addbyte(0x45 | (host_reg << 3)); - addbyte(cpu_state_offset(MM[guest_reg].q)); + addbyte((uint8_t)cpu_state_offset(MM[guest_reg].q)); } #define MMX_x86_OP(name, opcode) \ -static void MMX_ ## name(int dst_reg, int src_reg) \ +static inline void MMX_ ## name(int dst_reg, int src_reg) \ { \ addbyte(0x66); /*op dst_reg, src_reg*/ \ addbyte(0x0f); \ @@ -3728,31 +3728,31 @@ MMX_x86_OP(SUBSW, 0xe9) MMX_x86_OP(SUBUSB, 0xd8) MMX_x86_OP(SUBUSW, 0xd9) -MMX_x86_OP(PUNPCKLBW, 0x60) -MMX_x86_OP(PUNPCKLWD, 0x61) -MMX_x86_OP(PUNPCKLDQ, 0x62) -MMX_x86_OP(PCMPGTB, 0x64) -MMX_x86_OP(PCMPGTW, 0x65) -MMX_x86_OP(PCMPGTD, 0x66) +MMX_x86_OP(PUNPCKLBW, 0x60); +MMX_x86_OP(PUNPCKLWD, 0x61); +MMX_x86_OP(PUNPCKLDQ, 0x62); +MMX_x86_OP(PCMPGTB, 0x64); +MMX_x86_OP(PCMPGTW, 0x65); +MMX_x86_OP(PCMPGTD, 0x66); -MMX_x86_OP(PCMPEQB, 0x74) -MMX_x86_OP(PCMPEQW, 0x75) -MMX_x86_OP(PCMPEQD, 0x76) +MMX_x86_OP(PCMPEQB, 0x74); +MMX_x86_OP(PCMPEQW, 0x75); +MMX_x86_OP(PCMPEQD, 0x76); -MMX_x86_OP(PSRLW, 0xd1) -MMX_x86_OP(PSRLD, 0xd2) -MMX_x86_OP(PSRLQ, 0xd3) -MMX_x86_OP(PSRAW, 0xe1) -MMX_x86_OP(PSRAD, 0xe2) -MMX_x86_OP(PSLLW, 0xf1) -MMX_x86_OP(PSLLD, 0xf2) -MMX_x86_OP(PSLLQ, 0xf3) +MMX_x86_OP(PSRLW, 0xd1); +MMX_x86_OP(PSRLD, 0xd2); +MMX_x86_OP(PSRLQ, 0xd3); +MMX_x86_OP(PSRAW, 0xe1); +MMX_x86_OP(PSRAD, 0xe2); +MMX_x86_OP(PSLLW, 0xf1); +MMX_x86_OP(PSLLD, 0xf2); +MMX_x86_OP(PSLLQ, 0xf3); -MMX_x86_OP(PMULLW, 0xd5) -MMX_x86_OP(PMULHW, 0xe5) -MMX_x86_OP(PMADDWD, 0xf5) +MMX_x86_OP(PMULLW, 0xd5); +MMX_x86_OP(PMULHW, 0xe5); +MMX_x86_OP(PMADDWD, 0xf5); -static void MMX_PACKSSWB(int dst_reg, int src_reg) +static inline void MMX_PACKSSWB(int dst_reg, int src_reg) { addbyte(0x66); /*PACKSSWB dst_reg, src_reg*/ addbyte(0x0f); @@ -3764,7 +3764,7 @@ static void MMX_PACKSSWB(int dst_reg, int src_reg) addbyte(0xc0 | (dst_reg << 3) | dst_reg); addbyte(0x08); } -static void MMX_PACKUSWB(int dst_reg, int src_reg) +static inline void MMX_PACKUSWB(int dst_reg, int src_reg) { addbyte(0x66); /*PACKUSWB dst_reg, src_reg*/ addbyte(0x0f); @@ -3776,7 +3776,7 @@ static void MMX_PACKUSWB(int dst_reg, int src_reg) addbyte(0xc0 | (dst_reg << 3) | dst_reg); addbyte(0x08); } -static void MMX_PACKSSDW(int dst_reg, int src_reg) +static inline void MMX_PACKSSDW(int dst_reg, int src_reg) { addbyte(0x66); /*PACKSSDW dst_reg, src_reg*/ addbyte(0x0f); @@ -3788,7 +3788,7 @@ static void MMX_PACKSSDW(int dst_reg, int src_reg) addbyte(0xc0 | (dst_reg << 3) | dst_reg); addbyte(0x08); } -static void MMX_PUNPCKHBW(int dst_reg, int src_reg) +static inline void MMX_PUNPCKHBW(int dst_reg, int src_reg) { addbyte(0x66); /*PUNPCKLBW dst_reg, src_reg*/ addbyte(0x0f); @@ -3800,7 +3800,7 @@ static void MMX_PUNPCKHBW(int dst_reg, int src_reg) addbyte(0xc0 | (dst_reg << 3) | dst_reg); addbyte(0x0e); } -static void MMX_PUNPCKHWD(int dst_reg, int src_reg) +static inline void MMX_PUNPCKHWD(int dst_reg, int src_reg) { addbyte(0x66); /*PUNPCKLWD dst_reg, src_reg*/ addbyte(0x0f); @@ -3812,7 +3812,7 @@ static void MMX_PUNPCKHWD(int dst_reg, int src_reg) addbyte(0xc0 | (dst_reg << 3) | dst_reg); addbyte(0x0e); } -static void MMX_PUNPCKHDQ(int dst_reg, int src_reg) +static inline void MMX_PUNPCKHDQ(int dst_reg, int src_reg) { addbyte(0x66); /*PUNPCKLDQ dst_reg, src_reg*/ addbyte(0x0f); @@ -3825,7 +3825,7 @@ static void MMX_PUNPCKHDQ(int dst_reg, int src_reg) addbyte(0x0e); } -static void MMX_PSRLW_imm(int dst_reg, int amount) +static inline void MMX_PSRLW_imm(int dst_reg, int amount) { addbyte(0x66); /*PSRLW dst_reg, amount*/ addbyte(0x0f); @@ -3833,7 +3833,7 @@ static void MMX_PSRLW_imm(int dst_reg, int amount) addbyte(0xc0 | dst_reg | 0x10); addbyte(amount); } -static void MMX_PSRAW_imm(int dst_reg, int amount) +static inline void MMX_PSRAW_imm(int dst_reg, int amount) { addbyte(0x66); /*PSRAW dst_reg, amount*/ addbyte(0x0f); @@ -3841,7 +3841,7 @@ static void MMX_PSRAW_imm(int dst_reg, int amount) addbyte(0xc0 | dst_reg | 0x20); addbyte(amount); } -static void MMX_PSLLW_imm(int dst_reg, int amount) +static inline void MMX_PSLLW_imm(int dst_reg, int amount) { addbyte(0x66); /*PSLLW dst_reg, amount*/ addbyte(0x0f); @@ -3850,7 +3850,7 @@ static void MMX_PSLLW_imm(int dst_reg, int amount) addbyte(amount); } -static void MMX_PSRLD_imm(int dst_reg, int amount) +static inline void MMX_PSRLD_imm(int dst_reg, int amount) { addbyte(0x66); /*PSRLD dst_reg, amount*/ addbyte(0x0f); @@ -3858,7 +3858,7 @@ static void MMX_PSRLD_imm(int dst_reg, int amount) addbyte(0xc0 | dst_reg | 0x10); addbyte(amount); } -static void MMX_PSRAD_imm(int dst_reg, int amount) +static inline void MMX_PSRAD_imm(int dst_reg, int amount) { addbyte(0x66); /*PSRAD dst_reg, amount*/ addbyte(0x0f); @@ -3866,7 +3866,7 @@ static void MMX_PSRAD_imm(int dst_reg, int amount) addbyte(0xc0 | dst_reg | 0x20); addbyte(amount); } -static void MMX_PSLLD_imm(int dst_reg, int amount) +static inline void MMX_PSLLD_imm(int dst_reg, int amount) { addbyte(0x66); /*PSLLD dst_reg, amount*/ addbyte(0x0f); @@ -3875,7 +3875,7 @@ static void MMX_PSLLD_imm(int dst_reg, int amount) addbyte(amount); } -static void MMX_PSRLQ_imm(int dst_reg, int amount) +static inline void MMX_PSRLQ_imm(int dst_reg, int amount) { addbyte(0x66); /*PSRLQ dst_reg, amount*/ addbyte(0x0f); @@ -3883,7 +3883,7 @@ static void MMX_PSRLQ_imm(int dst_reg, int amount) addbyte(0xc0 | dst_reg | 0x10); addbyte(amount); } -static void MMX_PSRAQ_imm(int dst_reg, int amount) +static inline void MMX_PSRAQ_imm(int dst_reg, int amount) { addbyte(0x66); /*PSRAQ dst_reg, amount*/ addbyte(0x0f); @@ -3891,7 +3891,7 @@ static void MMX_PSRAQ_imm(int dst_reg, int amount) addbyte(0xc0 | dst_reg | 0x20); addbyte(amount); } -static void MMX_PSLLQ_imm(int dst_reg, int amount) +static inline void MMX_PSLLQ_imm(int dst_reg, int amount) { addbyte(0x66); /*PSLLQ dst_reg, amount*/ addbyte(0x0f); @@ -3901,14 +3901,14 @@ static void MMX_PSLLQ_imm(int dst_reg, int amount) } -static void SAVE_EA() +static inline void SAVE_EA() { addbyte(0x89); /*MOV [ESP+12], EAX*/ addbyte(0x44); addbyte(0x24); addbyte(12); } -static void LOAD_EA() +static inline void LOAD_EA() { addbyte(0x8b); /*MOV EAX, [ESP+12]*/ addbyte(0x44); @@ -3917,7 +3917,7 @@ static void LOAD_EA() } #define MEM_CHECK_WRITE_B MEM_CHECK_WRITE -static void MEM_CHECK_WRITE(x86seg *seg) +static inline void MEM_CHECK_WRITE(x86seg *seg) { CHECK_SEG_WRITE(seg); if ((seg == &_ds && codegen_flat_ds) || (seg == &_ss && codegen_flat_ss)) @@ -3935,7 +3935,7 @@ static void MEM_CHECK_WRITE(x86seg *seg) addlong(mem_check_write - (uint32_t)(&codeblock[block_current].data[block_pos + 4])); LOAD_EA(); } -static void MEM_CHECK_WRITE_W(x86seg *seg) +static inline void MEM_CHECK_WRITE_W(x86seg *seg) { CHECK_SEG_WRITE(seg); if ((seg == &_ds && codegen_flat_ds) || (seg == &_ss && codegen_flat_ss)) @@ -3953,7 +3953,7 @@ static void MEM_CHECK_WRITE_W(x86seg *seg) addlong(mem_check_write_w - (uint32_t)(&codeblock[block_current].data[block_pos + 4])); LOAD_EA(); } -static void MEM_CHECK_WRITE_L(x86seg *seg) +static inline void MEM_CHECK_WRITE_L(x86seg *seg) { CHECK_SEG_WRITE(seg); if ((seg == &_ds && codegen_flat_ds) || (seg == &_ss && codegen_flat_ss)) @@ -3972,7 +3972,7 @@ static void MEM_CHECK_WRITE_L(x86seg *seg) LOAD_EA(); } -static void LOAD_SEG(int host_reg, void *seg) +static inline void LOAD_SEG(int host_reg, void *seg) { addbyte(0xc7); /*MOV [ESP+4], seg*/ addbyte(0x44); @@ -3982,10 +3982,10 @@ static void LOAD_SEG(int host_reg, void *seg) addbyte(0x89); /*MOV [ESP], host_reg*/ addbyte(0x04 | (host_reg << 3)); addbyte(0x24); - CALL_FUNC(loadseg); + CALL_FUNC((uintptr_t)loadseg); addbyte(0x80); /*CMP abrt, 0*/ addbyte(0x7d); - addbyte(cpu_state_offset(abrt)); + addbyte((uint8_t)cpu_state_offset(abrt)); addbyte(0); addbyte(0x0f); /*JNE end*/ addbyte(0x85); diff --git a/src/CPU/codegen_timing_686.c b/src/CPU/codegen_timing_686.c index eab10357b..550c7e231 100644 --- a/src/CPU/codegen_timing_686.c +++ b/src/CPU/codegen_timing_686.c @@ -7,12 +7,13 @@ - FPU queue - Out of order execution (beyond most simplistic approximation) */ + #include "../ibm.h" -#include "../mem.h" #include "cpu.h" #include "x86.h" #include "x86_ops.h" #include "x87.h" +#include "../mem.h" #include "codegen.h" /*Instruction has different execution time for 16 and 32 bit data. Does not pair */ @@ -818,7 +819,7 @@ static uint32_t opcode_timings_8x[8] = static int decode_delay; static uint8_t last_prefix; -static __inline int COUNT(uint32_t c, int op_32) +static inline int COUNT(uint32_t c, int op_32) { if (c & CYCLES_HAS_MULTI) { @@ -854,7 +855,7 @@ void codegen_timing_686_prefix(uint8_t prefix, uint32_t fetchdat) void codegen_timing_686_opcode(uint8_t opcode, uint32_t fetchdat, int op_32) { - int *timings; + uint32_t *timings; int mod3 = ((fetchdat & 0xc0) == 0xc0); int bit8 = !(opcode & 1); diff --git a/src/CPU/codegen_timing_pentium.c b/src/CPU/codegen_timing_pentium.c index 2812e63ae..e5e4ed13d 100644 --- a/src/CPU/codegen_timing_pentium.c +++ b/src/CPU/codegen_timing_pentium.c @@ -8,12 +8,13 @@ - FPU latencies - MMX latencies */ + #include "../ibm.h" -#include "../mem.h" #include "cpu.h" #include "x86.h" #include "x86_ops.h" #include "x87.h" +#include "../mem.h" #include "codegen.h" /*Instruction has different execution time for 16 and 32 bit data. Does not pair */ @@ -818,7 +819,7 @@ static uint32_t opcode_timings_8x[8] = static int decode_delay; static uint8_t last_prefix; -static __inline int COUNT(uint32_t c, int op_32) +static inline int COUNT(uint32_t c, int op_32) { if (c & CYCLES_HAS_MULTI) { @@ -886,7 +887,7 @@ void codegen_timing_pentium_prefix(uint8_t prefix, uint32_t fetchdat) void codegen_timing_pentium_opcode(uint8_t opcode, uint32_t fetchdat, int op_32) { - int *timings; + uint32_t *timings; int mod3 = ((fetchdat & 0xc0) == 0xc0); int bit8 = !(opcode & 1); diff --git a/src/CPU/codegen_x86.c b/src/CPU/codegen_x86.c index 50fa7bc35..f747fd262 100644 --- a/src/CPU/codegen_x86.c +++ b/src/CPU/codegen_x86.c @@ -1,12 +1,13 @@ #if defined i386 || defined __i386 || defined __i386__ || defined _X86_ || defined WIN32 || defined _WIN32 || defined _WIN32 + #include #include "../ibm.h" -#include "../mem.h" #include "cpu.h" #include "x86.h" #include "x86_flags.h" #include "x86_ops.h" #include "x87.h" +#include "../mem.h" #include "386_common.h" @@ -115,7 +116,7 @@ static uint32_t gen_MEM_LOAD_ADDR_EA_B() addbyte(8); addbyte(0x80); /*CMP abrt, 0*/ addbyte(0x7d); - addbyte(cpu_state_offset(abrt)); + addbyte((uint8_t)cpu_state_offset(abrt)); addbyte(0); addbyte(0x0f); /*MOVZX EAX, AL*/ addbyte(0xb6); @@ -170,7 +171,7 @@ static uint32_t gen_MEM_LOAD_ADDR_EA_W() addbyte(8); addbyte(0x80); /*CMP abrt, 0*/ addbyte(0x7d); - addbyte(cpu_state_offset(abrt)); + addbyte((uint8_t)cpu_state_offset(abrt)); addbyte(0); addbyte(0x0f); /*MOVZX EAX, AX*/ addbyte(0xb7); @@ -224,7 +225,7 @@ static uint32_t gen_MEM_LOAD_ADDR_EA_L() addbyte(8); addbyte(0x80); /*CMP abrt, 0*/ addbyte(0x7d); - addbyte(cpu_state_offset(abrt)); + addbyte((uint8_t)cpu_state_offset(abrt)); addbyte(0); addbyte(0x0f); /*JNE mem_abrt_rout*/ addbyte(0x85); @@ -279,7 +280,7 @@ static uint32_t gen_MEM_LOAD_ADDR_EA_Q() addbyte(8); addbyte(0x80); /*CMP abrt, 0*/ addbyte(0x7d); - addbyte(cpu_state_offset(abrt)); + addbyte((uint8_t)cpu_state_offset(abrt)); addbyte(0); addbyte(0x0f); /*JNE mem_abrt_rout*/ addbyte(0x85); @@ -327,7 +328,7 @@ static uint32_t gen_MEM_STORE_ADDR_EA_B() addbyte(12); addbyte(0x80); /*CMP abrt, 0*/ addbyte(0x7d); - addbyte(cpu_state_offset(abrt)); + addbyte((uint8_t)cpu_state_offset(abrt)); addbyte(0); addbyte(0x0f); /*JNE mem_abrt_rout*/ addbyte(0x85); @@ -381,7 +382,7 @@ static uint32_t gen_MEM_STORE_ADDR_EA_W() addbyte(12); addbyte(0x80); /*CMP abrt, 0*/ addbyte(0x7d); - addbyte(cpu_state_offset(abrt)); + addbyte((uint8_t)cpu_state_offset(abrt)); addbyte(0); addbyte(0x0f); /*JNE mem_abrt_rout*/ addbyte(0x85); @@ -434,7 +435,7 @@ static uint32_t gen_MEM_STORE_ADDR_EA_L() addbyte(12); addbyte(0x80); /*CMP abrt, 0*/ addbyte(0x7d); - addbyte(cpu_state_offset(abrt)); + addbyte((uint8_t)cpu_state_offset(abrt)); addbyte(0); addbyte(0x0f); /*JNE mem_abrt_rout*/ addbyte(0x85); @@ -492,7 +493,7 @@ static uint32_t gen_MEM_STORE_ADDR_EA_Q() addbyte(16); addbyte(0x80); /*CMP abrt, 0*/ addbyte(0x7d); - addbyte(cpu_state_offset(abrt)); + addbyte((uint8_t)cpu_state_offset(abrt)); addbyte(0); addbyte(0x0f); /*JNE mem_abrt_rout*/ addbyte(0x85); @@ -543,7 +544,7 @@ static uint32_t gen_MEM_LOAD_ADDR_EA_B_NO_ABRT() #ifndef RELEASE_BUILD addbyte(0x80); /*CMP abrt, 0*/ addbyte(0x7d); - addbyte(cpu_state_offset(abrt)); + addbyte((uint8_t)cpu_state_offset(abrt)); addbyte(0); #endif addbyte(0x0f); /*MOVZX ECX, AL*/ @@ -612,7 +613,7 @@ static uint32_t gen_MEM_LOAD_ADDR_EA_W_NO_ABRT() #ifndef RELEASE_BUILD addbyte(0x80); /*CMP abrt, 0*/ addbyte(0x7d); - addbyte(cpu_state_offset(abrt)); + addbyte((uint8_t)cpu_state_offset(abrt)); addbyte(0); #endif addbyte(0x0f); /*MOVZX ECX, AX*/ @@ -658,7 +659,7 @@ static uint32_t gen_MEM_LOAD_ADDR_EA_L_NO_ABRT() addbyte(0x14); addbyte(0x95); addlong((uint32_t)readlookup2); - addbyte(0x75); /*JNE slowpath*/ + addbyte(0x75); /*JE slowpath*/ addbyte(3+2+3+1); addbyte(0x83); /*CMP EDX, -1*/ addbyte(0xfa); @@ -682,7 +683,7 @@ static uint32_t gen_MEM_LOAD_ADDR_EA_L_NO_ABRT() #ifndef RELEASE_BUILD addbyte(0x80); /*CMP abrt, 0*/ addbyte(0x7d); - addbyte(cpu_state_offset(abrt)); + addbyte((uint8_t)cpu_state_offset(abrt)); addbyte(0); addbyte(0x75); /*JNE mem_abrt_rout*/ addbyte(1); @@ -745,7 +746,7 @@ static uint32_t gen_MEM_STORE_ADDR_EA_B_NO_ABRT() #ifndef RELEASE_BUILD addbyte(0x80); /*CMP abrt, 0*/ addbyte(0x7d); - addbyte(cpu_state_offset(abrt)); + addbyte((uint8_t)cpu_state_offset(abrt)); addbyte(0); addbyte(0x75); /*JNE mem_abrt_rout*/ addbyte(1); @@ -811,7 +812,7 @@ static uint32_t gen_MEM_STORE_ADDR_EA_W_NO_ABRT() #ifndef RELEASE_BUILD addbyte(0x80); /*CMP abrt, 0*/ addbyte(0x7d); - addbyte(cpu_state_offset(abrt)); + addbyte((uint8_t)cpu_state_offset(abrt)); addbyte(0); addbyte(0x75); /*JNE mem_abrt_rout*/ addbyte(1); @@ -876,17 +877,17 @@ static uint32_t gen_MEM_STORE_ADDR_EA_L_NO_ABRT() #ifndef RELEASE_BUILD addbyte(0x80); /*CMP abrt, 0*/ addbyte(0x7d); - addbyte(cpu_state_offset(abrt)); + addbyte((uint8_t)cpu_state_offset(abrt)); addbyte(0); addbyte(0x75); /*JNE mem_abrt_rout*/ addbyte(1); #endif addbyte(0xc3); /*RET*/ #ifndef RELEASE_BUILD - addbyte(0xc7); /*MOV [ESP], gen_MEM_STORE_ADDR_EA_W_NO_ABRT_err*/ + addbyte(0xc7); /*MOV [ESP], gen_MEM_STORE_ADDR_EA_L_NO_ABRT_err*/ addbyte(0x04); addbyte(0x24); - addlong((uint32_t)gen_MEM_STORE_ADDR_EA_W_NO_ABRT_err); + addlong((uint32_t)gen_MEM_STORE_ADDR_EA_L_NO_ABRT_err); addbyte(0xe8); /*CALL fatal*/ addlong((uint32_t)fatal - (uint32_t)(&codeblock[block_current].data[block_pos + 4])); /*Should not return!*/ @@ -941,7 +942,7 @@ static uint32_t gen_MEM_CHECK_WRITE() addbyte(8); addbyte(0x80); /*CMP abrt, 0*/ addbyte(0x7d); - addbyte(cpu_state_offset(abrt)); + addbyte((uint8_t)cpu_state_offset(abrt)); addbyte(0); addbyte(0x0f); /*JNE mem_abrt_rout*/ addbyte(0x85); @@ -1022,7 +1023,7 @@ static uint32_t gen_MEM_CHECK_WRITE_W() addbyte(1); addbyte(0x80); /*CMP abrt, 0*/ addbyte(0x7d); - addbyte(cpu_state_offset(abrt)); + addbyte((uint8_t)cpu_state_offset(abrt)); addbyte(0); addbyte(0x0f); /*JNE mem_abrt_rout*/ addbyte(0x85); @@ -1104,7 +1105,7 @@ static uint32_t gen_MEM_CHECK_WRITE_L() addbyte(3); addbyte(0x80); /*CMP abrt, 0*/ addbyte(0x7d); - addbyte(cpu_state_offset(abrt)); + addbyte((uint8_t)cpu_state_offset(abrt)); addbyte(0); addbyte(0x0f); /*JNE mem_abrt_rout*/ addbyte(0x85); @@ -1122,7 +1123,6 @@ static uint32_t gen_MEM_CHECK_WRITE_L() void codegen_init() { - int c; #ifdef __linux__ void *start; size_t len; @@ -1149,7 +1149,6 @@ void codegen_init() exit(-1); } #endif - /* pclog("Codegen is %p\n", (void *)pages[0xfab12 >> 12].block); */ block_current = BLOCK_SIZE; block_pos = 0; @@ -1163,50 +1162,44 @@ void codegen_init() addbyte(0x5b); /*POP EDX*/ addbyte(0xC3); /*RET*/ block_pos = (block_pos + 15) & ~15; - mem_load_addr_ea_l = gen_MEM_LOAD_ADDR_EA_L(); + mem_load_addr_ea_l = (uint32_t)gen_MEM_LOAD_ADDR_EA_L(); block_pos = (block_pos + 15) & ~15; - mem_load_addr_ea_w = gen_MEM_LOAD_ADDR_EA_W(); + mem_load_addr_ea_w = (uint32_t)gen_MEM_LOAD_ADDR_EA_W(); block_pos = (block_pos + 15) & ~15; - mem_load_addr_ea_b = gen_MEM_LOAD_ADDR_EA_B(); + mem_load_addr_ea_b = (uint32_t)gen_MEM_LOAD_ADDR_EA_B(); block_pos = (block_pos + 15) & ~15; - mem_load_addr_ea_q = gen_MEM_LOAD_ADDR_EA_Q(); + mem_load_addr_ea_q = (uint32_t)gen_MEM_LOAD_ADDR_EA_Q(); block_pos = (block_pos + 15) & ~15; - mem_store_addr_ea_l = gen_MEM_STORE_ADDR_EA_L(); + mem_store_addr_ea_l = (uint32_t)gen_MEM_STORE_ADDR_EA_L(); block_pos = (block_pos + 15) & ~15; - mem_store_addr_ea_w = gen_MEM_STORE_ADDR_EA_W(); + mem_store_addr_ea_w = (uint32_t)gen_MEM_STORE_ADDR_EA_W(); block_pos = (block_pos + 15) & ~15; - mem_store_addr_ea_b = gen_MEM_STORE_ADDR_EA_B(); + mem_store_addr_ea_b = (uint32_t)gen_MEM_STORE_ADDR_EA_B(); block_pos = (block_pos + 15) & ~15; - mem_store_addr_ea_q = gen_MEM_STORE_ADDR_EA_Q(); + mem_store_addr_ea_q = (uint32_t)gen_MEM_STORE_ADDR_EA_Q(); block_pos = (block_pos + 15) & ~15; - mem_load_addr_ea_b_no_abrt = gen_MEM_LOAD_ADDR_EA_B_NO_ABRT(); + mem_load_addr_ea_b_no_abrt = (uint32_t)gen_MEM_LOAD_ADDR_EA_B_NO_ABRT(); block_pos = (block_pos + 15) & ~15; - mem_store_addr_ea_b_no_abrt = gen_MEM_STORE_ADDR_EA_B_NO_ABRT(); + mem_store_addr_ea_b_no_abrt = (uint32_t)gen_MEM_STORE_ADDR_EA_B_NO_ABRT(); block_pos = (block_pos + 15) & ~15; - mem_load_addr_ea_w_no_abrt = gen_MEM_LOAD_ADDR_EA_W_NO_ABRT(); + mem_load_addr_ea_w_no_abrt = (uint32_t)gen_MEM_LOAD_ADDR_EA_W_NO_ABRT(); block_pos = (block_pos + 15) & ~15; - mem_store_addr_ea_w_no_abrt = gen_MEM_STORE_ADDR_EA_W_NO_ABRT(); + mem_store_addr_ea_w_no_abrt = (uint32_t)gen_MEM_STORE_ADDR_EA_W_NO_ABRT(); block_pos = (block_pos + 15) & ~15; - mem_load_addr_ea_l_no_abrt = gen_MEM_LOAD_ADDR_EA_L_NO_ABRT(); + mem_load_addr_ea_l_no_abrt = (uint32_t)gen_MEM_LOAD_ADDR_EA_L_NO_ABRT(); block_pos = (block_pos + 15) & ~15; - mem_store_addr_ea_l_no_abrt = gen_MEM_STORE_ADDR_EA_L_NO_ABRT(); + mem_store_addr_ea_l_no_abrt = (uint32_t)gen_MEM_STORE_ADDR_EA_L_NO_ABRT(); block_pos = (block_pos + 15) & ~15; - mem_check_write = gen_MEM_CHECK_WRITE(); + mem_check_write = (uint32_t)gen_MEM_CHECK_WRITE(); block_pos = (block_pos + 15) & ~15; - mem_check_write_w = gen_MEM_CHECK_WRITE_W(); + mem_check_write_w = (uint32_t)gen_MEM_CHECK_WRITE_W(); block_pos = (block_pos + 15) & ~15; - mem_check_write_l = gen_MEM_CHECK_WRITE_L(); + mem_check_write_l = (uint32_t)gen_MEM_CHECK_WRITE_L(); -#ifdef __MSC__ - __asm { - fstcw cpu_state.old_npxc - } -#else - __asm( + asm( "fstcw %0\n" : "=m" (cpu_state.old_npxc) ); -#endif } void codegen_reset() @@ -1218,6 +1211,20 @@ void codegen_reset() void dump_block() { +/* codeblock_t *block = pages[0x119000 >> 12].block; + + pclog("dump_block:\n"); + while (block) + { + uint32_t start_pc = (block->pc & 0xffc) | (block->phys & ~0xfff); + uint32_t end_pc = (block->endpc & 0xffc) | (block->phys & ~0xfff); + pclog(" %p : %08x-%08x %08x-%08x %p %p\n", (void *)block, start_pc, end_pc, block->pc, block->endpc, (void *)block->prev, (void *)block->next); + if (!block->pc) + fatal("Dead PC=0\n"); + + block = block->next; + } + pclog("dump_block done\n");*/ } static void add_to_block_list(codeblock_t *block) @@ -1297,7 +1304,6 @@ static void remove_from_block_list(codeblock_t *block, uint32_t pc) } else { - /* pclog(" pages.block_2=%p 3 %p %p\n", (void *)block->next_2, (void *)block, (void *)pages[block->phys_2 >> 12].block_2); */ pages[block->phys_2 >> 12].block_2[(block->phys_2 >> 10) & 3] = block->next_2; if (block->next_2) block->next_2->prev_2 = NULL; @@ -1355,7 +1361,6 @@ void codegen_check_flush(page_t *page, uint64_t mask, uint32_t phys_addr) void codegen_block_init(uint32_t phys_addr) { codeblock_t *block; - int has_evicted = 0; page_t *page = &pages[phys_addr >> 12]; if (!page->block[(phys_addr >> 10) & 3]) @@ -1366,7 +1371,6 @@ void codegen_block_init(uint32_t phys_addr) if (block->pc != 0) { - /* pclog("Reuse block : was %08x now %08x\n", block->pc, cs+pc); */ delete_block(block); cpu_recomp_reuse++; } @@ -1384,7 +1388,7 @@ void codegen_block_init(uint32_t phys_addr) block->next_2 = block->prev_2 = NULL; block->page_mask = 0; block->flags = CODEBLOCK_STATIC_TOP; - block->status = cpu_cur_status; + block->status = cpu_cur_status; block->was_recompiled = 0; @@ -1395,7 +1399,6 @@ void codegen_block_init(uint32_t phys_addr) void codegen_block_start_recompile(codeblock_t *block) { - int has_evicted = 0; page_t *page = &pages[block->phys >> 12]; if (!page->block[(block->phys >> 10) & 3]) @@ -1440,8 +1443,6 @@ void codegen_block_start_recompile(codeblock_t *block) addbyte(0xBD); /*MOVL EBP, &cpu_state*/ addlong(((uintptr_t)&cpu_state) + 128); - /* pclog("New block %i for %08X %03x\n", block_current, cs+pc, block_num); */ - last_op32 = -1; last_ea_seg = NULL; last_ssegs = -1; @@ -1499,11 +1500,9 @@ void codegen_block_generate_end_mask() start_pc >>= PAGE_MASK_SHIFT; end_pc >>= PAGE_MASK_SHIFT; - /* pclog("block_end: %08x %08x\n", start_pc, end_pc); */ for (; start_pc <= end_pc; start_pc++) { block->page_mask |= ((uint64_t)1 << start_pc); - /* pclog(" %08x %llx\n", start_pc, block->page_mask); */ } pages[block->phys >> 12].code_present_mask[(block->phys >> 10) & 3] |= block->page_mask; @@ -1531,7 +1530,6 @@ void codegen_block_generate_end_mask() fatal("!page_mask2\n"); if (block->next_2) { - /* pclog(" next_2->pc=%08x\n", block->next_2->pc); */ if (!block->next_2->pc) fatal("block->next_2->pc=0 %p\n", (void *)block->next_2); } @@ -1540,7 +1538,6 @@ void codegen_block_generate_end_mask() } } - /* pclog("block_end: %08x %08x %016llx\n", block->pc, block->endpc, block->page_mask); */ recomp_page = -1; } @@ -1560,14 +1557,14 @@ void codegen_block_end_recompile(codeblock_t *block) { addbyte(0x81); /*SUB $codegen_block_cycles, cyclcs*/ addbyte(0x6d); - addbyte(cpu_state_offset(_cycles)); + addbyte((uint8_t)cpu_state_offset(_cycles)); addlong(codegen_block_cycles); } if (codegen_block_ins) { addbyte(0x81); /*ADD $codegen_block_ins,ins*/ addbyte(0x45); - addbyte(cpu_state_offset(cpu_recomp_ins)); + addbyte((uint8_t)cpu_state_offset(cpu_recomp_ins)); addlong(codegen_block_ins); } #if 0 @@ -1596,7 +1593,6 @@ void codegen_block_end_recompile(codeblock_t *block) block->next_2 = block->prev_2 = NULL; codegen_block_generate_end_mask(); add_to_block_list(block); - /* pclog("End block %i\n", block_num); */ if (!(block->flags & CODEBLOCK_HAS_FPU)) block->flags &= ~CODEBLOCK_STATIC_TOP; @@ -1607,29 +1603,6 @@ void codegen_flush() return; } -static int opcode_conditional_jump[256] = -{ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, /*00*/ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*10*/ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*20*/ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*30*/ - - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*40*/ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*50*/ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*60*/ - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /*70*/ - - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*80*/ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*90*/ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*a0*/ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*b0*/ - - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*c0*/ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*d0*/ - 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*e0*/ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*f0*/ -}; - static int opcode_modrm[256] = { 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, /*00*/ @@ -1666,7 +1639,7 @@ int opcode_0f_modrm[256] = 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*80*/ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /*90*/ - 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, /*a0*/ + 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, /*a0*/ 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, /*b0*/ 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, /*c0*/ @@ -1689,7 +1662,7 @@ static x86seg *codegen_generate_ea_16_long(x86seg *op_ea_seg, uint32_t fetchdat, { addbyte(0xC7); /*MOVL $0,(ssegs)*/ addbyte(0x45); - addbyte(cpu_state_offset(eaaddr)); + addbyte((uint8_t)cpu_state_offset(eaaddr)); addlong((fetchdat >> 8) & 0xffff); (*op_pc) += 2; } @@ -1706,7 +1679,7 @@ static x86seg *codegen_generate_ea_16_long(x86seg *op_ea_seg, uint32_t fetchdat, break; case 1: addbyte(0xb8); /*MOVL ,%eax*/ - addlong((uint32_t)(int8_t)(rmdat >> 8)); /* pc++; */ + addlong((uint32_t)(int8_t)(rmdat >> 8)); addbyte(0x03); /*ADDL *mod1add[0][cpu_rm], %eax*/ addbyte(0x05); addlong((uint32_t)mod1add[0][cpu_rm]); @@ -1717,7 +1690,7 @@ static x86seg *codegen_generate_ea_16_long(x86seg *op_ea_seg, uint32_t fetchdat, break; case 2: addbyte(0xb8); /*MOVL ,%eax*/ - addlong((fetchdat >> 8) & 0xffff); /* pc++; */ + addlong((fetchdat >> 8) & 0xffff); addbyte(0x03); /*ADDL *mod1add[0][cpu_rm], %eax*/ addbyte(0x05); addlong((uint32_t)mod1add[0][cpu_rm]); @@ -1754,14 +1727,14 @@ static x86seg *codegen_generate_ea_32_long(x86seg *op_ea_seg, uint32_t fetchdat, { new_eaaddr = fastreadl(cs + (*op_pc) + 1); addbyte(0xb8); /*MOVL ,%eax*/ - addlong(new_eaaddr); /* pc++; */ + addlong(new_eaaddr); (*op_pc) += 4; } else { addbyte(0x8b); /*MOVL regs[sib&7].l, %eax*/ addbyte(0x45); - addbyte(cpu_state_offset(regs[sib & 7].l)); + addbyte((uint8_t)cpu_state_offset(regs[sib & 7].l)); } break; case 1: @@ -1770,7 +1743,7 @@ static x86seg *codegen_generate_ea_32_long(x86seg *op_ea_seg, uint32_t fetchdat, addlong(new_eaaddr); addbyte(0x03); /*ADDL regs[sib&7].l, %eax*/ addbyte(0x45); - addbyte(cpu_state_offset(regs[sib & 7].l)); + addbyte((uint8_t)cpu_state_offset(regs[sib & 7].l)); (*op_pc)++; break; case 2: @@ -1779,7 +1752,7 @@ static x86seg *codegen_generate_ea_32_long(x86seg *op_ea_seg, uint32_t fetchdat, addlong(new_eaaddr); addbyte(0x03); /*ADDL regs[sib&7].l, %eax*/ addbyte(0x45); - addbyte(cpu_state_offset(regs[sib & 7].l)); + addbyte((uint8_t)cpu_state_offset(regs[sib & 7].l)); (*op_pc) += 4; break; } @@ -1797,20 +1770,20 @@ static x86seg *codegen_generate_ea_32_long(x86seg *op_ea_seg, uint32_t fetchdat, case 0: addbyte(0x03); /*ADDL regs[sib&7].l, %eax*/ addbyte(0x45); - addbyte(cpu_state_offset(regs[(sib >> 3) & 7].l)); + addbyte((uint8_t)cpu_state_offset(regs[(sib >> 3) & 7].l)); break; case 1: - addbyte(0x8B); addbyte(0x5D); addbyte(cpu_state_offset(regs[(sib >> 3) & 7].l)); /*MOVL armregs[RD],%ebx*/ + addbyte(0x8B); addbyte(0x5D); addbyte((uint8_t)cpu_state_offset(regs[(sib >> 3) & 7].l)); /*MOVL armregs[RD],%ebx*/ addbyte(0x01); addbyte(0xD8); /*ADDL %ebx,%eax*/ addbyte(0x01); addbyte(0xD8); /*ADDL %ebx,%eax*/ break; case 2: - addbyte(0x8B); addbyte(0x5D); addbyte(cpu_state_offset(regs[(sib >> 3) & 7].l)); /*MOVL armregs[RD],%ebx*/ + addbyte(0x8B); addbyte(0x5D); addbyte((uint8_t)cpu_state_offset(regs[(sib >> 3) & 7].l)); /*MOVL armregs[RD],%ebx*/ addbyte(0xC1); addbyte(0xE3); addbyte(2); /*SHL $2,%ebx*/ addbyte(0x01); addbyte(0xD8); /*ADDL %ebx,%eax*/ break; case 3: - addbyte(0x8B); addbyte(0x5D); addbyte(cpu_state_offset(regs[(sib >> 3) & 7].l)); /*MOVL armregs[RD],%ebx*/ + addbyte(0x8B); addbyte(0x5D); addbyte((uint8_t)cpu_state_offset(regs[(sib >> 3) & 7].l)); /*MOVL armregs[RD],%ebx*/ addbyte(0xC1); addbyte(0xE3); addbyte(3); /*SHL $2,%ebx*/ addbyte(0x01); addbyte(0xD8); /*ADDL %ebx,%eax*/ break; @@ -1826,18 +1799,14 @@ static x86seg *codegen_generate_ea_32_long(x86seg *op_ea_seg, uint32_t fetchdat, new_eaaddr = fastreadl(cs + (*op_pc) + 1); addbyte(0xC7); /*MOVL $new_eaaddr,(eaaddr)*/ addbyte(0x45); - addbyte(cpu_state_offset(eaaddr)); + addbyte((uint8_t)cpu_state_offset(eaaddr)); addlong(new_eaaddr); (*op_pc) += 4; return op_ea_seg; } addbyte(0x8b); /*MOVL regs[sib&7].l, %eax*/ addbyte(0x45); - addbyte(cpu_state_offset(regs[cpu_rm].l)); -#if 0 - addbyte(0xa1); /*MOVL regs[cpu_rm].l, %eax*/ - addlong((uint32_t)&cpu_state.regs[cpu_rm].l); -#endif + addbyte((uint8_t)cpu_state_offset(regs[cpu_rm].l)); cpu_state.eaaddr = cpu_state.regs[cpu_rm].l; if (cpu_mod) { @@ -2025,19 +1994,19 @@ void codegen_generate_call(uint8_t opcode, OpFn op, uint32_t fetchdat, uint32_t generate_call: codegen_timing_opcode(opcode, fetchdat, op_32); - + if ((op_table == x86_dynarec_opcodes && - ((opcode & 0xf0) == 0x70 || (opcode & 0xfc) == 0xe0 || opcode == 0xc2 || + ((opcode & 0xf0) == 0x70 || (opcode & 0xfc) == 0xe0 || opcode == 0xc2 || (opcode & 0xfe) == 0xca || (opcode & 0xfc) == 0xcc || (opcode & 0xfc) == 0xe8 || - (opcode == 0xff && ((fetchdat & 0x38) >= 0x10 && (fetchdat & 0x38) < 0x30))) || - (op_table == x86_dynarec_opcodes_0f && ((opcode & 0xf0) == 0x80)))) + (opcode == 0xff && ((fetchdat & 0x38) >= 0x10 && (fetchdat & 0x38) < 0x30)))) || + (op_table == x86_dynarec_opcodes_0f && ((opcode & 0xf0) == 0x80))) { /*Opcode is likely to cause block to exit, update cycle count*/ if (codegen_block_cycles) { addbyte(0x81); /*SUB $codegen_block_cycles, cyclcs*/ addbyte(0x6d); - addbyte(cpu_state_offset(_cycles)); + addbyte((uint8_t)cpu_state_offset(_cycles)); addlong(codegen_block_cycles); codegen_block_cycles = 0; } @@ -2045,7 +2014,7 @@ generate_call: { addbyte(0x81); /*ADD $codegen_block_ins,ins*/ addbyte(0x45); - addbyte(cpu_state_offset(cpu_recomp_ins)); + addbyte((uint8_t)cpu_state_offset(cpu_recomp_ins)); addlong(codegen_block_ins); codegen_block_ins = 0; } @@ -2079,17 +2048,13 @@ generate_call: } op = op_table[((opcode >> opcode_shift) | op_32) & opcode_mask]; -#if 0 - if (output) - pclog("Generate call at %08X %02X %08X %02X %08X %08X %08X %08X %08X %02X %02X %02X %02X\n", &codeblock[block_current][block_pos], opcode, new_pc, ram[old_pc], EAX, EBX, ECX, EDX, ESI, ram[0x7bd2+6],ram[0x7bd2+7],ram[0x7bd2+8],ram[0x7bd2+9]); -#endif if (op_ssegs != last_ssegs) { last_ssegs = op_ssegs; addbyte(0xC6); /*MOVB [ssegs],op_ssegs*/ addbyte(0x45); - addbyte(cpu_state_offset(ssegs)); + addbyte((uint8_t)cpu_state_offset(ssegs)); addbyte(op_pc + pc_off); } @@ -2108,7 +2073,7 @@ generate_call: addbyte(0xC7); /*MOVL $rm | mod | reg,(rm_mod_reg_data)*/ addbyte(0x45); - addbyte(cpu_state_offset(rm_data.rm_mod_reg_data)); + addbyte((uint8_t)cpu_state_offset(rm_data.rm_mod_reg_data)); addlong(cpu_rm | (cpu_mod << 8) | (cpu_reg << 16)); op_pc += pc_off; @@ -2124,18 +2089,18 @@ generate_call: last_ea_seg = op_ea_seg; addbyte(0xC7); /*MOVL $&_ds,(ea_seg)*/ addbyte(0x45); - addbyte(cpu_state_offset(ea_seg)); + addbyte((uint8_t)cpu_state_offset(ea_seg)); addlong((uint32_t)op_ea_seg); } addbyte(0xC7); /*MOVL pc,new_pc*/ addbyte(0x45); - addbyte(cpu_state_offset(pc)); + addbyte((uint8_t)cpu_state_offset(pc)); addlong(op_pc + pc_off); addbyte(0xC7); /*MOVL $old_pc,(oldpc)*/ addbyte(0x45); - addbyte(cpu_state_offset(oldpc)); + addbyte((uint8_t)cpu_state_offset(oldpc)); addlong(old_pc); if (op_32 != last_op32) @@ -2143,7 +2108,7 @@ generate_call: last_op32 = op_32; addbyte(0xC7); /*MOVL $use32,(op32)*/ addbyte(0x45); - addbyte(cpu_state_offset(op32)); + addbyte((uint8_t)cpu_state_offset(op32)); addlong(op_32); } @@ -2164,11 +2129,6 @@ generate_call: addbyte(0x0F); addbyte(0x85); /*JNZ 0*/ addlong((uint32_t)&block->data[BLOCK_EXIT_OFFSET] - (uint32_t)(&block->data[block_pos + 4])); -#if 0 - addbyte(0xE8); /*CALL*/ - addlong(((uint8_t *)codegen_debug - (uint8_t *)(&block->data[block_pos + 4]))); -#endif - codegen_endpc = (cs + cpu_state.pc) + 8; } diff --git a/src/CPU/x86_ops_call.h b/src/CPU/x86_ops_call.h index 6d27373f4..d1f61021c 100644 --- a/src/CPU/x86_ops_call.h +++ b/src/CPU/x86_ops_call.h @@ -61,7 +61,7 @@ static int opCALL_far_w(uint32_t fetchdat) { uint32_t old_cs, old_pc; uint16_t new_cs, new_pc; - int cycles_old = cycles; + int cycles_old = cycles; UNUSED(cycles_old); new_pc = getwordf(); new_cs = getword(); if (cpu_state.abrt) return 1; @@ -77,7 +77,7 @@ static int opCALL_far_l(uint32_t fetchdat) { uint32_t old_cs, old_pc; uint32_t new_cs, new_pc; - int cycles_old = cycles; + int cycles_old = cycles; UNUSED(cycles_old); new_pc = getlong(); new_cs = getword(); if (cpu_state.abrt) return 1; @@ -95,7 +95,7 @@ static int opFF_w_a16(uint32_t fetchdat) { uint16_t old_cs, new_cs; uint32_t old_pc, new_pc; - int cycles_old = cycles; + int cycles_old = cycles; UNUSED(cycles_old); uint16_t temp; @@ -163,6 +163,7 @@ static int opFF_w_a16(uint32_t fetchdat) break; default: +// fatal("Bad FF opcode %02X\n",rmdat&0x38); x86illegal(); } return cpu_state.abrt; @@ -171,7 +172,7 @@ static int opFF_w_a32(uint32_t fetchdat) { uint16_t old_cs, new_cs; uint32_t old_pc, new_pc; - int cycles_old = cycles; + int cycles_old = cycles; UNUSED(cycles_old); uint16_t temp; @@ -239,6 +240,7 @@ static int opFF_w_a32(uint32_t fetchdat) break; default: +// fatal("Bad FF opcode %02X\n",rmdat&0x38); x86illegal(); } return cpu_state.abrt; @@ -248,7 +250,7 @@ static int opFF_l_a16(uint32_t fetchdat) { uint16_t old_cs, new_cs; uint32_t old_pc, new_pc; - int cycles_old = cycles; + int cycles_old = cycles; UNUSED(cycles_old); uint32_t temp; @@ -316,6 +318,7 @@ static int opFF_l_a16(uint32_t fetchdat) break; default: +// fatal("Bad FF opcode %02X\n",rmdat&0x38); x86illegal(); } return cpu_state.abrt; @@ -324,7 +327,7 @@ static int opFF_l_a32(uint32_t fetchdat) { uint16_t old_cs, new_cs; uint32_t old_pc, new_pc; - int cycles_old = cycles; + int cycles_old = cycles; UNUSED(cycles_old); uint32_t temp; @@ -391,6 +394,7 @@ static int opFF_l_a32(uint32_t fetchdat) break; default: +// fatal("Bad FF opcode %02X\n",rmdat&0x38); x86illegal(); } return cpu_state.abrt; diff --git a/src/CPU/x86_ops_i686.h b/src/CPU/x86_ops_i686.h index 84a10c28b..a61d27025 100644 --- a/src/CPU/x86_ops_i686.h +++ b/src/CPU/x86_ops_i686.h @@ -166,6 +166,7 @@ static int opFXSAVESTOR_a16(uint32_t fetchdat) uint8_t ftwb = 0; uint16_t rec_ftw = 0; uint16_t fpus = 0; + uint64_t *p; if (CPUID < 0x650) return ILLEGAL(fetchdat); @@ -258,9 +259,10 @@ static int opFXSAVESTOR_a16(uint32_t fetchdat) cpu_state.ismmx = 0; /*Horrible hack, but as PCem doesn't keep the FPU stack in 80-bit precision at all times something like this is needed*/ + p = (uint64_t *)cpu_state.tag; if (cpu_state.MM_w4[0] == 0xffff && cpu_state.MM_w4[1] == 0xffff && cpu_state.MM_w4[2] == 0xffff && cpu_state.MM_w4[3] == 0xffff && cpu_state.MM_w4[4] == 0xffff && cpu_state.MM_w4[5] == 0xffff && cpu_state.MM_w4[6] == 0xffff && cpu_state.MM_w4[7] == 0xffff && - !cpu_state.TOP && !(*(uint64_t *)cpu_state.tag)) + !cpu_state.TOP && !(*p)) cpu_state.ismmx = 1; x87_settag(rec_ftw); @@ -321,7 +323,8 @@ static int opFXSAVESTOR_a16(uint32_t fetchdat) cpu_state.npxc = 0x37F; cpu_state.new_npxc = (cpu_state.old_npxc & ~0xc00); cpu_state.npxs = 0; - *(uint64_t *)cpu_state.tag = 0x0303030303030303ll; + p = (uint64_t *)cpu_state.tag; + *p = 0x0303030303030303ll; cpu_state.TOP = 0; cpu_state.ismmx = 0; @@ -341,6 +344,7 @@ static int opFXSAVESTOR_a32(uint32_t fetchdat) uint8_t ftwb = 0; uint16_t rec_ftw = 0; uint16_t fpus = 0; + uint64_t *p; if (CPUID < 0x650) return ILLEGAL(fetchdat); @@ -433,9 +437,10 @@ static int opFXSAVESTOR_a32(uint32_t fetchdat) cpu_state.ismmx = 0; /*Horrible hack, but as PCem doesn't keep the FPU stack in 80-bit precision at all times something like this is needed*/ + p = (uint64_t *)cpu_state.tag; if (cpu_state.MM_w4[0] == 0xffff && cpu_state.MM_w4[1] == 0xffff && cpu_state.MM_w4[2] == 0xffff && cpu_state.MM_w4[3] == 0xffff && cpu_state.MM_w4[4] == 0xffff && cpu_state.MM_w4[5] == 0xffff && cpu_state.MM_w4[6] == 0xffff && cpu_state.MM_w4[7] == 0xffff && - !cpu_state.TOP && !(*(uint64_t *)cpu_state.tag)) + !cpu_state.TOP && !(*p)) cpu_state.ismmx = 1; x87_settag(rec_ftw); @@ -496,7 +501,8 @@ static int opFXSAVESTOR_a32(uint32_t fetchdat) cpu_state.npxc = 0x37F; cpu_state.new_npxc = (cpu_state.old_npxc & ~0xc00); cpu_state.npxs = 0; - *(uint64_t *)cpu_state.tag = 0x0303030303030303ll; + p = (uint64_t *)cpu_state.tag; + *p = 0x0303030303030303ll; cpu_state.TOP = 0; cpu_state.ismmx = 0; diff --git a/src/CPU/x86_ops_int.h b/src/CPU/x86_ops_int.h index dafb1dde5..e488ae83a 100644 --- a/src/CPU/x86_ops_int.h +++ b/src/CPU/x86_ops_int.h @@ -1,6 +1,6 @@ static int opINT3(uint32_t fetchdat) { - int cycles_old = cycles; + int cycles_old = cycles; UNUSED(cycles_old); if ((cr0 & 1) && (eflags & VM_FLAG) && (IOPL != 3)) { x86gpf(NULL,0); @@ -14,7 +14,7 @@ static int opINT3(uint32_t fetchdat) static int opINT1(uint32_t fetchdat) { - int cycles_old = cycles; + int cycles_old = cycles; UNUSED(cycles_old); if ((cr0 & 1) && (eflags & VM_FLAG) && (IOPL != 3)) { x86gpf(NULL,0); @@ -28,7 +28,7 @@ static int opINT1(uint32_t fetchdat) static int opINT(uint32_t fetchdat) { - int cycles_old = cycles; + int cycles_old = cycles; UNUSED(cycles_old); uint8_t temp; /*if (msw&1) pclog("INT %i %i %i\n",cr0&1,eflags&VM_FLAG,IOPL);*/ @@ -38,6 +38,38 @@ static int opINT(uint32_t fetchdat) return 1; } temp = getbytef(); +// /*if (temp == 0x10 && AH == 0xe) */pclog("INT %02X : %04X %04X %04X %04X %c %04X:%04X\n", temp, AX, BX, CX, DX, (AL < 32) ? ' ' : AL, CS, pc); +// if (CS == 0x0028 && pc == 0xC03813C0) +// output = 3; +/* if (pc == 0x8028009A) + output = 3; + if (pc == 0x80282B6F) + { + __times++; + if (__times == 2) + fatal("WRONG\n"); + } + if (pc == 0x802809CE) + fatal("RIGHT\n");*/ +// if (CS == 0x0028 && pc == 0x80037FE9) +// output = 3; +//if (CS == 0x9087 && pc == 0x3763) +// fatal("Here\n"); +//if (CS==0x9087 && pc == 0x0850) +// output = 1; + +/* if (output && pc == 0x80033008) + { + __times++; + if (__times == 2) + fatal("WRONG\n"); + }*/ +/* if (output && pc == 0x80D8) + { + __times++; + if (__times == 2) + fatal("RIGHT\n"); + }*/ x86_int_sw(temp); PREFETCH_RUN(cycles_old-cycles, 2, -1, 0,0,0,0, 0); @@ -46,7 +78,7 @@ static int opINT(uint32_t fetchdat) static int opINTO(uint32_t fetchdat) { - int cycles_old = cycles; + int cycles_old = cycles; UNUSED(cycles_old); if ((cr0 & 1) && (eflags & VM_FLAG) && (IOPL != 3)) { diff --git a/src/CPU/x86_ops_ret.h b/src/CPU/x86_ops_ret.h index 4f41a2049..0bc88e466 100644 --- a/src/CPU/x86_ops_ret.h +++ b/src/CPU/x86_ops_ret.h @@ -44,7 +44,7 @@ static int opRETF_a16(uint32_t fetchdat) { - int cycles_old = cycles; + int cycles_old = cycles; UNUSED(cycles_old); CPU_BLOCK_END(); RETF_a16(0); @@ -55,7 +55,7 @@ static int opRETF_a16(uint32_t fetchdat) } static int opRETF_a32(uint32_t fetchdat) { - int cycles_old = cycles; + int cycles_old = cycles; UNUSED(cycles_old); CPU_BLOCK_END(); RETF_a32(0); @@ -67,8 +67,8 @@ static int opRETF_a32(uint32_t fetchdat) static int opRETF_a16_imm(uint32_t fetchdat) { - int cycles_old = cycles; uint16_t offset = getwordf(); + int cycles_old = cycles; UNUSED(cycles_old); CPU_BLOCK_END(); RETF_a16(offset); @@ -79,8 +79,8 @@ static int opRETF_a16_imm(uint32_t fetchdat) } static int opRETF_a32_imm(uint32_t fetchdat) { - int cycles_old = cycles; uint16_t offset = getwordf(); + int cycles_old = cycles; UNUSED(cycles_old); CPU_BLOCK_END(); RETF_a32(offset); @@ -92,7 +92,7 @@ static int opRETF_a32_imm(uint32_t fetchdat) static int opIRET_286(uint32_t fetchdat) { - int cycles_old = cycles; + int cycles_old = cycles; UNUSED(cycles_old); if ((cr0 & 1) && (eflags & VM_FLAG) && (IOPL != 3)) { @@ -137,7 +137,7 @@ static int opIRET_286(uint32_t fetchdat) static int opIRET(uint32_t fetchdat) { - int cycles_old = cycles; + int cycles_old = cycles; UNUSED(cycles_old); if ((cr0 & 1) && (eflags & VM_FLAG) && (IOPL != 3)) { @@ -182,7 +182,7 @@ static int opIRET(uint32_t fetchdat) static int opIRETD(uint32_t fetchdat) { - int cycles_old = cycles; + int cycles_old = cycles; UNUSED(cycles_old); if ((cr0 & 1) && (eflags & VM_FLAG) && (IOPL != 3)) { diff --git a/src/CPU/x87_ops.h b/src/CPU/x87_ops.h index b9320081f..5af874826 100644 --- a/src/CPU/x87_ops.h +++ b/src/CPU/x87_ops.h @@ -54,14 +54,18 @@ static int rounding_modes[4] = {FE_TONEAREST, FE_DOWNWARD, FE_UPWARD, FE_TOWARDZ static __inline void x87_set_mmx() { + uint64_t *p; cpu_state.TOP = 0; - *(uint64_t *)cpu_state.tag = 0; + p = (uint64_t *)cpu_state.tag; + *p = 0; cpu_state.ismmx = 1; } static __inline void x87_emms() { - *(uint64_t *)cpu_state.tag = 0x0303030303030303ll; + uint64_t *p; + p = (uint64_t *)cpu_state.tag; + *p = 0x0303030303030303ll; cpu_state.ismmx = 0; } diff --git a/src/CPU/x87_ops_arith.h b/src/CPU/x87_ops_arith.h index 1313839bb..f53ad9213 100644 --- a/src/CPU/x87_ops_arith.h +++ b/src/CPU/x87_ops_arith.h @@ -165,11 +165,14 @@ static int opFCOMP(uint32_t fetchdat) static int opFCOMPP(uint32_t fetchdat) { + uint64_t *p, *q; FP_ENTER(); cpu_state.pc++; if (fplog) pclog("FCOMPP\n"); cpu_state.npxs &= ~(C0|C2|C3); - if ((*(uint64_t *)&ST(0) == ((uint64_t)1 << 63) && *(uint64_t *)&ST(1) == 0) && is386) + p = (uint64_t *)&ST(0); + q = (uint64_t *)&ST(1); + if ((*p == ((uint64_t)1 << 63) && *q == 0) && is386) cpu_state.npxs |= C0; /*Nasty hack to fix 80387 detection*/ else cpu_state.npxs |= x87_compare(ST(0), ST(1)); diff --git a/src/CPU/x87_ops_misc.h b/src/CPU/x87_ops_misc.h index 178261fd5..fd1cc3de6 100644 --- a/src/CPU/x87_ops_misc.h +++ b/src/CPU/x87_ops_misc.h @@ -29,12 +29,14 @@ static int opFCLEX(uint32_t fetchdat) static int opFINIT(uint32_t fetchdat) { + uint64_t *p; FP_ENTER(); cpu_state.pc++; cpu_state.npxc = 0x37F; cpu_state.new_npxc = (cpu_state.old_npxc & ~0xc00); cpu_state.npxs = 0; - *(uint64_t *)cpu_state.tag = 0x0303030303030303ll; + p = (uint64_t *)cpu_state.tag; + *p = 0x0303030303030303ll; cpu_state.TOP = 0; cpu_state.ismmx = 0; CLOCK_CYCLES(17); @@ -91,6 +93,7 @@ static int opFSTP(uint32_t fetchdat) static int FSTOR() { + uint64_t *p; FP_ENTER(); switch ((cr0 & 1) | (cpu_state.op32 & 0x100)) { @@ -125,9 +128,10 @@ static int FSTOR() cpu_state.ismmx = 0; /*Horrible hack, but as PCem doesn't keep the FPU stack in 80-bit precision at all times something like this is needed*/ + p = (uint64_t *)cpu_state.tag; if (cpu_state.MM_w4[0] == 0xffff && cpu_state.MM_w4[1] == 0xffff && cpu_state.MM_w4[2] == 0xffff && cpu_state.MM_w4[3] == 0xffff && cpu_state.MM_w4[4] == 0xffff && cpu_state.MM_w4[5] == 0xffff && cpu_state.MM_w4[6] == 0xffff && cpu_state.MM_w4[7] == 0xffff && - !cpu_state.TOP && !(*(uint64_t *)cpu_state.tag)) + !cpu_state.TOP && !(*p)) cpu_state.ismmx = 1; CLOCK_CYCLES((cr0 & 1) ? 34 : 44); @@ -151,6 +155,8 @@ static int opFSTOR_a32(uint32_t fetchdat) static int FSAVE() { + uint64_t *p; + FP_ENTER(); if (fplog) pclog("FSAVE %08X:%08X %i\n", easeg, cpu_state.eaaddr, cpu_state.ismmx); cpu_state.npxs = (cpu_state.npxs & ~(7 << 11)) | (cpu_state.TOP << 11); @@ -287,7 +293,8 @@ static int FSAVE() cpu_state.npxc = 0x37F; cpu_state.new_npxc = (cpu_state.old_npxc & ~0xc00); cpu_state.npxs = 0; - *(uint64_t *)cpu_state.tag = 0x0303030303030303ll; + p = (uint64_t *)cpu_state.tag; + *p = 0x0303030303030303ll; cpu_state.TOP = 0; cpu_state.ismmx = 0; diff --git a/src/Makefile.mingw b/src/Makefile.mingw index 4da10181a..0c34101c1 100644 --- a/src/Makefile.mingw +++ b/src/Makefile.mingw @@ -8,7 +8,7 @@ # # Modified Makefile for Win32 (MinGW32) environment. # -# Version: @(#)Makefile.mingw 1.0.27 2017/06/14 +# Version: @(#)Makefile.mingw 1.0.29 2017/06/16 # # Authors: Miran Grca, # Fred N. van Kempen, @@ -65,8 +65,8 @@ endif VPATH = . cpu sound sound/resid-fp video lzf network network/slirp win PLAT = win/ ifeq ($(X64), y) -CPP = g++.exe -m64 -U__unix -CC = gcc.exe -m64 -U__unix +CPP = g++.exe -m64 +CC = gcc.exe -m64 else CPP = g++.exe -m32 CC = gcc.exe -m32 @@ -100,7 +100,7 @@ else endif AFLAGS = -msse -msse2 -mfpmath=sse CFLAGS = $(OPTS) $(DFLAGS) $(COPTIM) $(AOPTIM) $(AFLAGS) \ - -fomit-frame-pointer -mstackrealign + -fomit-frame-pointer -mstackrealign -Wall RFLAGS = --input-format=rc -O coff ifeq ($(RELEASE), y) CFLAGS += -DRELEASE_BUILD @@ -141,6 +141,7 @@ SYSOBJ = model.o \ olivetti_m24.o ps1.o ps2.o ps2_mca.o \ tandy_eeprom.o tandy_rom.o DEVOBJ = bugger.o lpt.o serial.o \ + fdc37c665.o fdc37c669.o fdc37c932fr.o \ pc87306.o sis85c471.o w83877f.o \ keyboard.o \ keyboard_xt.o keyboard_at.o keyboard_pcjr.o \ @@ -149,9 +150,8 @@ DEVOBJ = bugger.o lpt.o serial.o \ joystick_standard.o joystick_ch_flightstick_pro.o \ joystick_sw_pad.o joystick_tm_fcs.o \ mouse.o mouse_serial.o mouse_ps2.o mouse_bus.o \ - fdd.o fdc.o \ - fdc37c665.o fdc37c669.o fdc37c932fr.o fdi2raw.o \ - hdd.o \ + fdd.o fdc.o fdi2raw.o \ + hdd.o hdd_image.o \ mfm_at.o mfm_xebec.o hdd_esdi.o ide.o xtide.o piix.o \ disc.o \ disc_86f.o disc_fdi.o disc_imd.o disc_img.o \ @@ -162,7 +162,11 @@ ifdef USB USBOBJ = usb.o endif NETOBJ = network.o \ - net_pcap.o net_slirp.o \ + net_pcap.o \ + net_slirp.o \ + bootp.o ip_icmp.o misc.o socket.o tcp_timer.o cksum.o \ + ip_input.o queue.o tcp_input.o debug.o ip_output.o \ + sbuf.o tcp_output.o udp.o if.o mbuf.o slirp.o tcp_subr.o \ net_ne2000.o SCSIOBJ = scsi.o scsi_disk.o scsi_buslogic.o scsi_aha154x.o SNDOBJ = sound.o \ @@ -216,9 +220,6 @@ OBJ = $(MAINOBJ) $(CPUOBJ) $(SYSOBJ) $(DEVOBJ) $(USBOBJ) \ $(NETOBJ) $(SCSIOBJ) $(SNDOBJ) $(VIDOBJ) $(WINOBJ) LZFOBJ = lzf_c.o lzf_d.o -SLIRPOBJ= bootp.o ip_icmp.o misc.o socket.o tcp_timer.o cksum.o \ - ip_input.o queue.o tcp_input.o debug.o ip_output.o \ - sbuf.o tcp_output.o udp.o if.o mbuf.o slirp.o tcp_subr.o LIBS = -lddraw -ldinput8 -ldxguid -ld3d9 -ld3dx9 -lopenal.dll \ -mwindows -lcomctl32 -lwinmm -lwsock32 -liphlpapi -lpsapi \ @@ -241,9 +242,9 @@ LIBS = -lddraw -ldinput8 -ldxguid -ld3d9 -ld3dx9 -lopenal.dll \ all: $(PROG).exe pcap_if.exe -$(PROG).exe: $(OBJ) $(LZFOBJ) $(SLIRPOBJ) +$(PROG).exe: $(OBJ) $(LZFOBJ) @echo Linking $(PROG).exe .. - @$(CC) -o $(PROG).exe $(OBJ) $(LZFOBJ) $(SLIRPOBJ) $(LIBS) + @$(CC) -o $(PROG).exe $(OBJ) $(LZFOBJ) $(LIBS) ifneq ($(DEBUG), y) @strip $(PROG).exe endif @@ -271,4 +272,259 @@ pcap_if.res: pcap_if.rc @$(WINDRES) $(RFLAGS) -i win/pcap_if.rc -o pcap_if.res +# Module dependencies. +acer386sx.o: ibm.h cpu/cpu.h io.h acer386sx.h + +acerm3a.o: ibm.h io.h acerm3a.h + +ali1429.o: ibm.h cpu/cpu.h io.h mem.h ali1429.h + +amstrad.o: ibm.h io.h keyboard.h lpt.h mouse.h amstrad.h + +bugger.o: ibm.h io.h bugger.h + +cdrom.o: 86box.h cdrom.h ibm.h ide.h piix.h scsi.h timer.h \ + win/plat_iodev.h + +cdrom_ioctl.o: ibm.h cdrom.h cdrom_ioctl.h scsi.h + +cdrom_null.o: ibm.h cdrom.h cdrom_ioctl.h + +compaq.o: ibm.h mem.h + +config.o: cdrom.h config.h device.h disc.h fdc.h fdd.h ibm.h \ + cpu/cpu.h gameport.h ide.h hdd.h model.h mouse.h \ + network/network.h nvr.h scsi.h win/plat_joystick.h \ + win/plat_midi.h sound/snd_dbopl.h sound/snd_mpu401.h \ + sound/snd_opl.h sound/sound.h video/video.h win/win.h \ + win/win_language.h + +device.o: ibm.h cpu/cpu.h config.h device.h model.h sound/sound.h + +disc.o: ibm.h config.h disc.h disc_fdi.h disc_img.h disc_86f.h \ + disc_td0.h disc_imd.h fdc.h fdd.h timer.h + +disc_86f.o: lzf/lzf.h config.h dma.h disc.h disc_86f.h disc_random.h \ + fdc.h fdd.h ibm.h + +disc_fdi.o: ibm.h disc.h disc_img.h disc_fdi.h fdc.h fdd.h fdi2raw.h \ + ibm.h disc.h disc_imd.h fdc.h fdd.h ibm.h config.h disc.h \ + disc_img.h fdc.h fdd.h + +disc_random.o: disc_random.h + +disc_td0.o: ibm.h disc.h disc_td0.h fdc.h fdd.h + +dma.o: ibm.h cpu/x86.h mem.h io.h dma.h + +fdc.o: ibm.h disc.h dma.h fdc.h fdd.h io.h pic.h timer.h + +fdc37c665.o: ibm.h disc.h fdc.h fdd.h ide.h io.h lpt.h serial.h \ + fdc37c665.h ibm.h disc.h fdc.h fdd.h io.h ide.h \ + lpt.h serial.h fdc37c669.h + +fdc37c932fr.o: ibm.h disc.h fdc.h fdd.h ide.h io.h lpt.h serial.h \ + fdc37c932fr.h + +fdd.o: ibm.h disc.h fdc.h fdd.h + +fdi2raw.o: fdi2raw.h ibm.h + +gameport.o: ibm.h cpu/cpu.h device.h io.h timer.h gameport.h \ + joystick_ch_flightstick_pro.h joystick_standard.h \ + joystick_sw_pad.h joystick_tm_fcs.h plat_joystick.h + +hdd.o: ibm.h cpu/cpu.h device.h hdd.h model.h hdd_esdi.h \ + mfm_at.h mfm_xebec.h xtide.h + +hdd_image.o: ibm.h ide.h hdd_image.h + +hdd_esdi.o: ibm.h device.h dma.h hdd_image.h io.h mca.h mem.h \ + pic.h rom.h timer.h hdd_esdi.h + +headland.o: ibm.h cpu/cpu.h io.h mem.h headland.h + +i430fx.o: ibm.h mem.h pci.h i430fx.h + +i430hx.o: ibm.h io.h mem.h pci.h i430hx.h + +i430lx.o: ibm.h mem.h pci.h i430lx.h + +i430nx.o: ibm.h mem.h pci.h i430nx.h + +i430vx.o: ibm.h io.h mem.h pci.h i430vx.h + +i440fx.o: ibm.h io.h mem.h pci.h i440fx.h + +i82335.o: ibm.h io.h mem.h + +ide.o: 86box.h cdrom.h hdd_image.h ibm.h io.h pic.h timer.h cdrom.h scsi.h ide.h + +intel.o: ibm.h cpu/cpu.h io.h mem.h pit.h timer.h intel.h + +intel_flash.o: ibm.h cpu/cpu.h device.h mem.h model.h rom.h + +io.o: ibm.h io.h + +jim.o: ibm.h io.h + +joystick_ch_flightstick_pro.o: ibm.h device.h timer.h gameport.h \ + joystick_standard.h plat_joystick.h + +joystick_standard.o: ibm.h device.h timer.h gameport.h \ + joystick_standard.h plat_joystick.h + +joystick_sw_pad.o: ibm.h device.h timer.h gameport.h \ + joystick_sw_pad.h plat_joystick.h + +joystick_tm_fcs.o: ibm.h device.h timer.h gameport.h \ + joystick_standard.h plat_joystick.h + +keyboard.o: ibm.h plat_keyboard.h keyboard.h + +keyboard_amstrad.o: ibm.h io.h mem.h pic.h pit.h timer.h sound/sound.h \ + sound/snd_speaker.h keyboard.h keyboard_amstrad.h + +keyboard_at.o: ibm.h io.h mem.h pic.h pit.h timer.h disc.h fdc.h \ + sound/sound.h sound/snd_speaker.h keyboard.h keyboard_at.h + +keyboard_olim24.o: ibm.h io.h mem.h pic.h pit.h timer.h mouse.h \ + sound/sound.h sound/snd_speaker.h keyboard.h keyboard_olim24.h + +keyboard_pcjr.o: ibm.h io.h mem.h nmi.h pic.h pit.h timer.h \ + device.h sound/sound.h sound/snd_speaker.h \ + sound/snd_sn76489.h keyboard.h keyboard_pcjr.h + +keyboard_xt.o: ibm.h io.h mem.h pic.h pit.h timer.h device.h tandy_eeprom.h \ + sound/sound.h sound/snd_speaker.h keyboard.h keyboard_xt.h + +laserxt.o: ibm.h io.h mem.h + +lpt.o: ibm.h io.h lpt.h + +mca.o: ibm.h io.h mem.h mca.h + +mcr.o: ibm.h + +mem.o: ibm.h cpu/cpu.h cpu/x86_ops.h cpu/x86.h config.h \ + io.h mem.h rom.h cpu/codegen.h video/video.h + +memregs.o: ibm.h io.h memregs.h + +mfm_at.o: ibm.h device.h hdd_image.h io.h pic.h timer.h mfm_at.h + +mfm_xebec.o: ibm.h device.h dma.h hdd_image.h io.h mem.h pic.h rom.h timer.h mfm_xebec.h + +model.o: ibm.h cpu/cpu.h io.h mem.h rom.h device.h model.h mouse.h \ + mouse_ps2.h cdrom.h acerm3a.h ali1429.h amstrad.h compaq.h \ + disc.h dma.h fdc.h fdc37c665.h fdc37c669.h fdc37c932fr.h \ + gameport.h headland.h i430fx.h i430hx.h i430lx.h i430nx.h \ + i430vx.h i440fx.h i82335.h ide.h intel.h intel_flash.h jim.h \ + keyboard_amstrad.h keyboard_at.h keyboard_olim24.h \ + keyboard_pcjr.h keyboard_xt.h laserxt.h lpt.h mem.h memregs.h \ + neat.h nmi.h nvr.h olivetti_m24.h opti495.h pc87306.h pci.h \ + pic.h piix.h pit.h ps1.h ps2.h ps2_mca.h scat.h serial.h \ + sis496.h sis85c471.h sio.h sound/snd_ps1.h sound/snd_pssj.h \ + sound/snd_sn76489.h tandy_eeprom.h tandy_rom.h \ + video/vid_pcjr.h video/vid_tandy.h w83877f.h wd76c10.h \ + xtide.h bugger.h + +mouse.o: ibm.h mouse.h mouse_serial.h mouse_ps2.h mouse_bus.h \ + amstrad.h keyboard_olim24.h + +mouse_bus.o: ibm.h io.h pic.h mouse.h mouse_bus.h plat_mouse.h + +mouse_ps2.o: ibm.h keyboard_at.h mouse.h mouse_ps2.h plat_mouse.h + +mouse_serial.o: ibm.h timer.h serial.h mouse.h mouse_serial.h + +neat.o: ibm.h io.h neat.h + +nmi.o: ibm.h io.h nmi.h + +nvr.o: ibm.h cpu/cpu.h device.h io.h mem.h model.h nvr.h \ + pic.h rom.h timer.h rtc.h + +olivetti_m24.o: ibm.h io.h olivetti_m24.h + +opti495.o: ibm.h cpu/cpu.h io.h mem.h + +pc.o: 86box.h ibm.h mem.h cpu/cpu.h cpu/x86_ops.h cpu/codegen.h \ + dma.h nvr.h pic.h pit.h timer.h device.h ali1429.h disc.h \ + disc_86f.h disc_fdi.h disc_imd.h disc_img.h disc_td0.h \ + disc_random.h config.h fdc.h fdd.h gameport.h plat_joystick.h \ + plat_midi.h hdd.h ide.h cdrom.h cdrom_ioctl.h cdrom_image.h \ + cdrom_null.h scsi.h keyboard.h plat_keyboard.h keyboard_at.h \ + model.h mouse.h plat_mouse.h network/network.h serial.h \ + sound/sound.h sound/snd_cms.h sound/snd_dbopl.h \ + sound/snd_mpu401.h sound/snd_opl.h sound/snd_gus.h \ + sound/snd_sb.h sound/snd_speaker.h sound/snd_ssi2001.h \ + video/video.h video/vid_voodoo.h amstrad.h win/plat_ui.h + +pc87306.o: ibm.h disc.h fdc.h fdd.h ide.h io.h lpt.h serial.h pc87306.h + +pci.o: ibm.h io.h mem.h pic.h pci.h + +pic.o: ibm.h io.h pic.h pit.h + +piix.o: ibm.h dma.h ide.h io.h mem.h pci.h piix.h + +pit.o: ibm.h cpu/cpu.h dma.h io.h pic.h pit.h device.h timer.h \ + model.h sound/snd_speaker.h video/video.h + +ppi.o: ibm.h pit.h plat_keyboard.h plat_mouse.h + +ps1.o: ibm.h io.h mem.h ps1.h rom.h lpt.h serial.h + +ps2.o: ibm.h io.h mem.h ps2.h rom.h lpt.h serial.h + +ps2_mca.o: ibm.h cpu/cpu.h cpu/x86.h io.h mca.h mem.h rom.h device.h \ + lpt.h ps2_mca.h ps2_nvr.h serial.h + +ps2_nvr.o: ibm.h device.h io.h mem.h rom.h ps2_nvr.h + +rom.o: config.h ibm.h mem.h rom.h + +rtc.o: nvr.h rtc.h + +scat.o: ibm.h io.h scat.h mem.h + +scsi.o: 86box.h ibm.h timer.h device.h cdrom.h scsi.h \ + scsi_aha154x.h scsi_buslogic.h + +scsi_aha154x.o: ibm.h io.h mca.h mem.h mca.h rom.h dma.h pic.h timer.h \ + device.h cdrom.h scsi.h scsi_disk.h scsi_aha154x.h \ + +scsi_buslogic.o: ibm.h io.h mem.h rom.h dma.h pic.h pci.h timer.h \ + device.h scsi.h scsi_disk.h cdrom.h scsi_buslogic.h + +scsi_disk.o: 86box.h cdrom.h hdd_image.h ibm.h ide.h piix.h scsi.h \ + scsi_disk.h timer.h win/plat_iodev.h + +serial.o: ibm.h io.h pic.h timer.h serial.h plat_serial.h + +sio.o: ibm.h cdrom.h disc.h dma.h fdc.h keyboard_at.h ide.h \ + io.h mem.h pci.h sio.h + +sis496.o: ibm.h device.h io.h mem.h pci.h sis496.h + +sis50x.o: ibm.h device.h io.h mem.h pci.h sis50x.h + +sis85c471.o: ibm.h ide.h disc.h fdc.h fdd.h io.h lpt.h serial.h sis85c471.h + +tandy_eeprom.o: ibm.h device.h mem.h io.h rom.h tandy_eeprom.h + +tandy_rom.o: ibm.h device.h io.h mem.h rom.h tandy_rom.h + +timer.o: ibm.h timer.h + +usb.o: ibm.h io.h mem.h usb.h + +w83877f.o: ibm.h disc.h fdc.h fdd.h io.h lpt.h serial.h w83877f.h + +wd76c10.o: ibm.h disc.h fdc.h io.h mem.h serial.h wd76c10.h + +xtide.o: ibm.h io.h mem.h rom.h device.h ide.h xtide.h + + # End of Makefile.mingw. diff --git a/src/NETWORK/net_ne2000.c b/src/NETWORK/net_ne2000.c index b9fb05a34..43eec0796 100644 --- a/src/NETWORK/net_ne2000.c +++ b/src/NETWORK/net_ne2000.c @@ -1591,8 +1591,8 @@ nic_pci_write(int func, int addr, uint8_t val, void *priv) val |= 0x01; /* re-enable IOIN bit */ /*FALLTHROUGH*/ - case 0x11: /* PCI_BAR - case 0x12: /* PCI_BAR + case 0x11: /* PCI_BAR */ + case 0x12: /* PCI_BAR */ case 0x13: /* PCI_BAR */ /* Remove old I/O. */ nic_ioremove(dev, dev->base_address); @@ -1819,6 +1819,11 @@ nic_rom_init(nic_t *dev, wchar_t *s) uint32_t temp; FILE *f; + if (s == NULL) + { + return; + } + if (dev->bios_addr > 0) { if ((f = romfopen(s, L"rb")) != NULL) { fseek(f, 0L, SEEK_END); @@ -1864,6 +1869,7 @@ nic_init(int board) dev = malloc(sizeof(nic_t)); memset(dev, 0x00, sizeof(nic_t)); dev->board = board; + rom = NULL; switch(dev->board) { case NE2K_NE1000: strcpy(dev->name, "NE1000"); diff --git a/src/NETWORK/net_slirp.c b/src/NETWORK/net_slirp.c index 89c8eb1ac..514845fdb 100644 --- a/src/NETWORK/net_slirp.c +++ b/src/NETWORK/net_slirp.c @@ -67,7 +67,6 @@ slirp_tic(void) static void poll_thread(void *arg) { - uint8_t *mac = (uint8_t *)arg; struct queuepacket *qp; event_t *evt; @@ -112,8 +111,6 @@ poll_thread(void *arg) int network_slirp_setup(uint8_t *mac, NETRXCB func, void *arg) { - int rc; - pclog("SLiRP: initializing..\n"); if (slirp_init() != 0) { diff --git a/src/NETWORK/network.c b/src/NETWORK/network.c index abac44263..87d2613ac 100644 --- a/src/NETWORK/network.c +++ b/src/NETWORK/network.c @@ -24,8 +24,7 @@ #include "../device.h" #include "network.h" #include "net_ne2000.h" -#include "../WIN/win.h" -#include "../WIN/win_language.h" +#include "../WIN/plat_ui.h" static netcard_t net_cards[] = { @@ -112,7 +111,7 @@ network_attach(void *dev, uint8_t *mac, NETRXCB rx) case NET_TYPE_PCAP: ret = network_pcap_setup(mac, rx, dev); if (ret < 0) { - msgbox_error(ghwnd, IDS_2219); + plat_msgbox_error(IDS_2219); network_type = NET_TYPE_NONE; } break; @@ -154,8 +153,6 @@ network_close(void) void network_reset(void) { - int i = 0; - pclog("NETWORK: reset (type=%d, card=%d)\n", network_type, network_card); /* Just in case.. */ diff --git a/src/NETWORK/pcap_if.c b/src/NETWORK/pcap_if.c index 3cf321a9d..31ec33f7d 100644 --- a/src/NETWORK/pcap_if.c +++ b/src/NETWORK/pcap_if.c @@ -90,7 +90,7 @@ hex_dump(unsigned char *bufp, int len) while (len-- > 0) { c = bufp[addr]; if ((addr % 16) == 0) - printf("%04x %02x", addr, c); + printf("%04lx %02x", addr, c); else printf(" %02x", c); asci[(addr & 15)] = (uint8_t)isprint(c) ? c : '.'; @@ -175,7 +175,7 @@ start_cap(char *dev) strftime(temp, sizeof(temp), "%H:%M:%S", ltime); /* Process and print the packet. */ - printf("\n<< %s,%.6d len=%d\n", + printf("\n<< %s,%.6ld len=%u\n", temp, hdr->ts.tv_usec, hdr->len); rc = eth_prhdr((unsigned char *)pkt); hex_dump((unsigned char *)pkt+rc, hdr->len-rc); @@ -227,7 +227,6 @@ int main(int argc, char **argv) { dev_t interfaces[32]; - dev_t *dev = interfaces; int numdev, i; /* Try loading the DLL. */ diff --git a/src/SOUND/dbopl.cpp b/src/SOUND/dbopl.cpp index b5d4bfe65..e8002b7cf 100644 --- a/src/SOUND/dbopl.cpp +++ b/src/SOUND/dbopl.cpp @@ -869,6 +869,9 @@ Channel* Channel::BlockTemplate( Chip* chip, Bit32u samples, Bit32s* output ) { return (this + 2); } break; + case sm2Percussion: + case sm3Percussion: + break; } //Init the operators with the the current vibrato and tremolo values Op( 0 )->Prepare( chip ); @@ -940,6 +943,9 @@ Channel* Channel::BlockTemplate( Chip* chip, Bit32u samples, Bit32s* output ) { output[ i * 2 + 0 ] += sample & maskLeft; output[ i * 2 + 1 ] += sample & maskRight; break; + case sm2Percussion: + case sm3Percussion: + break; } } switch( mode ) { diff --git a/src/VIDEO/vid_ega_render.c b/src/VIDEO/vid_ega_render.c index bd4b6a358..eea08992b 100644 --- a/src/VIDEO/vid_ega_render.c +++ b/src/VIDEO/vid_ega_render.c @@ -180,17 +180,15 @@ void ega_jega_render_blit_text(ega_t *ega, int x, int dl, int start, int width, void ega_render_text_jega(ega_t *ega, int drawcursor) { - int x_add = (enable_overscan) ? 8 : 0; int dl = ega_display_line(ega); uint8_t chr, attr; - uint16_t dat, dat2; - uint32_t charaddr; - int x, xx; - uint32_t fg, bg; + uint16_t dat = 0, dat2; + int x; + uint32_t fg = 0, bg = 0; /* Temporary for DBCS. */ - unsigned int chr_left; - unsigned int bsattr; + unsigned int chr_left = 0; + unsigned int bsattr = 0; int chr_wide = 0; uint32_t bg_ex = 0; uint32_t fg_ex = 0; @@ -208,7 +206,7 @@ void ega_render_text_jega(ega_t *ega, int drawcursor) chr = ega->vram[(ega->ma << 1) & ega->vrammask]; attr = ega->vram[((ega->ma << 1) + 1) & ega->vrammask]; - if (chr_wide = 0) + if (chr_wide == 0) { if (ega->RMOD2 & 0x80) { diff --git a/src/VIDEO/vid_et4000w32.c b/src/VIDEO/vid_et4000w32.c index 254fe8072..d0a2b1e90 100644 --- a/src/VIDEO/vid_et4000w32.c +++ b/src/VIDEO/vid_et4000w32.c @@ -212,7 +212,6 @@ uint8_t et4000w32p_in(uint16_t addr, void *p) { et4000w32p_t *et4000 = (et4000w32p_t *)p; svga_t *svga = &et4000->svga; - uint8_t temp; if (((addr & 0xfff0) == 0x3d0 || (addr & 0xfff0) == 0x3b0) && !(svga->miscout & 1)) addr ^= 0x60; diff --git a/src/VIDEO/vid_s3.c b/src/VIDEO/vid_s3.c index 8b762aeb9..51bd873d9 100644 --- a/src/VIDEO/vid_s3.c +++ b/src/VIDEO/vid_s3.c @@ -1464,7 +1464,7 @@ uint8_t s3_accel_read(uint32_t addr, void *p) void s3_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat, s3_t *s3) { svga_t *svga = &s3->svga; - uint32_t src_dat, dest_dat; + uint32_t src_dat = 0, dest_dat; int frgd_mix, bkgd_mix; int clip_t = s3->accel.multifunc[1] & 0xfff; int clip_l = s3->accel.multifunc[2] & 0xfff; diff --git a/src/VIDEO/vid_s3_virge.c b/src/VIDEO/vid_s3_virge.c index 95f040128..4cb96ab8b 100644 --- a/src/VIDEO/vid_s3_virge.c +++ b/src/VIDEO/vid_s3_virge.c @@ -22,10 +22,10 @@ static int reg_writes = 0, reg_reads = 0; static int dither[4][4] = { - 0, 4, 1, 5, - 6, 2, 7, 3, - 1, 5, 0, 4, - 7, 3, 6, 2, + {0, 4, 1, 5}, + {6, 2, 7, 3}, + {1, 5, 0, 4}, + {7, 3, 6, 2}, }; #define RB_SIZE 256 diff --git a/src/VIDEO/vid_svga_render.c b/src/VIDEO/vid_svga_render.c index c942cf6ab..4c0c5c617 100644 --- a/src/VIDEO/vid_svga_render.c +++ b/src/VIDEO/vid_svga_render.c @@ -511,15 +511,20 @@ void svga_render_2bpp_highres(svga_t *svga) void svga_render_4bpp_lowres(svga_t *svga) { + int x; int y_add = (enable_overscan) ? 16 : 0; int x_add = y_add >> 1; int dl = svga_display_line(svga); + int offset; + uint32_t *p; + uint32_t *r, *q; + uint8_t edat[4]; + uint8_t dat; if (svga->changedvram[svga->ma >> 12] || svga->changedvram[(svga->ma >> 12) + 1] || svga->fullchange) { - int x; - int offset = ((8 - svga->scrollcache) << 1) + 16; - uint32_t *p = &((uint32_t *)buffer32->line[dl])[offset + x_add]; + offset = ((8 - svga->scrollcache) << 1) + 16; + p = &((uint32_t *)buffer32->line[dl])[offset + x_add]; if (svga->firstline_draw == 2000) svga->firstline_draw = svga->displine; @@ -527,10 +532,9 @@ void svga_render_4bpp_lowres(svga_t *svga) for (x = 0; x <= svga->hdisp; x += 16) { - uint8_t edat[4]; - uint8_t dat; - - *(uint32_t *)(&edat[0]) = *(uint32_t *)(&svga->vram[svga->ma]); + r = (uint32_t *)(&edat[0]); + q = (uint32_t *)(&svga->vram[svga->ma]); + *r = *q; svga->ma += 4; svga->ma = svga_mask_addr(svga->ma, svga); @@ -559,6 +563,12 @@ void svga_render_4bpp_highres(svga_t *svga) int y_add = (enable_overscan) ? 16 : 0; int x_add = y_add >> 1; int dl = svga_display_line(svga); + int x; + int offset; + uint32_t *p; + uint8_t edat[4]; + uint8_t dat; + uint32_t *r, *q; if (svga->sc & 1 && !(svga->crtc[0x17] & 1)) changed_offset = svga_mask_addr(svga->ma | 0x8000, svga) >> 12; @@ -572,9 +582,8 @@ void svga_render_4bpp_highres(svga_t *svga) if (svga->changedvram[changed_offset] || svga->changedvram[changed_offset2] || svga->fullchange) { - int x; - int offset = (8 - svga->scrollcache) + 24; - uint32_t *p = &((uint32_t *)buffer32->line[dl])[offset + x_add]; + offset = (8 - svga->scrollcache) + 24; + p = &((uint32_t *)buffer32->line[dl])[offset + x_add]; if (svga->firstline_draw == 2000) svga->firstline_draw = svga->displine; @@ -582,13 +591,12 @@ void svga_render_4bpp_highres(svga_t *svga) for (x = 0; x <= svga->hdisp; x += 8) { - uint8_t edat[4]; - uint8_t dat; - - if (svga->sc & 1 && !(svga->crtc[0x17] & 1)) - *(uint32_t *)(&edat[0]) = *(uint32_t *)(&svga->vram[svga_mask_addr(svga->ma | 0x8000, svga)]); + r = (uint32_t *)(&edat[0]); + if (svga->sc & 1 && !(svga->crtc[0x17] & 1)) + q = (uint32_t *)(&svga->vram[svga_mask_addr(svga->ma | 0x8000, svga)]); else - *(uint32_t *)(&edat[0]) = *(uint32_t *)(&svga->vram[svga->ma]); + q = (uint32_t *)(&svga->vram[svga->ma]); + *r = *q; svga->ma += 4; svga->ma = svga_mask_addr(svga->ma, svga); diff --git a/src/VIDEO/vid_voodoo.c b/src/VIDEO/vid_voodoo.c index f033acdbb..042e88a42 100644 --- a/src/VIDEO/vid_voodoo.c +++ b/src/VIDEO/vid_voodoo.c @@ -745,6 +745,7 @@ enum LFB_FORMAT_RGB565 = 0, LFB_FORMAT_RGB555 = 1, LFB_FORMAT_ARGB1555 = 2, + LFB_FORMAT_XRGB8888 = 4, LFB_FORMAT_ARGB8888 = 5, LFB_FORMAT_DEPTH = 15, LFB_FORMAT_MASK = 15 @@ -5408,6 +5409,13 @@ static void voodoo_fb_writel(uint32_t addr, uint32_t val, void *p) count = 2; break; + case LFB_FORMAT_XRGB8888: + colour_data[0].b = val & 0xff; + colour_data[0].g = (val >> 8) & 0xff; + colour_data[0].r = (val >> 16) & 0xff; + write_mask = LFB_WRITE_COLOUR; + addr >>= 1; + break; case LFB_FORMAT_ARGB8888: colour_data[0].b = val & 0xff; colour_data[0].g = (val >> 8) & 0xff; diff --git a/src/VIDEO/vid_voodoo_codegen_x86.h b/src/VIDEO/vid_voodoo_codegen_x86.h index 5a9f65e46..0cd0fc7eb 100644 --- a/src/VIDEO/vid_voodoo_codegen_x86.h +++ b/src/VIDEO/vid_voodoo_codegen_x86.h @@ -759,10 +759,14 @@ static inline void voodoo_generate(uint8_t *code_block, voodoo_t *voodoo, voodoo addbyte(0x47); addbyte(0xc3); - if (depth_jump_pos) - *(uint8_t *)&code_block[depth_jump_pos] = (block_pos - depth_jump_pos) - 1; - if (depth_jump_pos) - *(uint8_t *)&code_block[depth_jump_pos2] = (block_pos - depth_jump_pos2) - 1; + if (depth_jump_pos) + { + *(uint8_t *)&code_block[depth_jump_pos] = (block_pos - depth_jump_pos) - 1; + } + if (depth_jump_pos2) + { + *(uint8_t *)&code_block[depth_jump_pos2] = (block_pos - depth_jump_pos2) - 1; + } if ((params->fogMode & (FOG_ENABLE|FOG_CONSTANT|FOG_Z|FOG_ALPHA)) == FOG_ENABLE) { diff --git a/src/WIN/86Box.rc b/src/WIN/86Box.rc index 0a64e8b42..73f326984 100644 --- a/src/WIN/86Box.rc +++ b/src/WIN/86Box.rc @@ -8,7 +8,7 @@ * * Windows resource script. * - * Version: @(#)86Box.rc 1.0.2 2017/06/04 + * Version: @(#)86Box.rc 1.0.3 2017/06/16 * * Authors: Miran Grca, * Fred N. van Kempen, @@ -384,7 +384,6 @@ BEGIN LTEXT "LUN:",IDT_1724,200,118,38,8 COMBOBOX IDC_COMBO_HD_CHANNEL_IDE,170,117,90,12,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP - LTEXT "Channel:",IDT_1725,131,118,38,8 END DLG_CFG_HARD_DISKS_ADD DIALOG DISCARDABLE 0, 0, 219, 111 @@ -410,67 +409,20 @@ BEGIN LTEXT "File name:",IDT_1731,7,7,204,9 COMBOBOX IDC_COMBO_HD_BUS,33,71,58,12,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP - LTEXT "Bus:",IDT_1732,7,72,24,8 + LTEXT "Bus:",IDT_1721,7,72,24,8 COMBOBOX IDC_COMBO_HD_CHANNEL,134,71,77,12,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP - LTEXT "Channel:",IDT_1733,99,72,34,8 + LTEXT "Channel:",IDT_1722,99,72,34,8 COMBOBOX IDC_COMBO_HD_ID,133,71,26,12,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP - LTEXT "ID:",IDT_1734,117,72,15,8 + LTEXT "ID:",IDT_1723,117,72,15,8 COMBOBOX IDC_COMBO_HD_LUN,185,71,26,12,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP - LTEXT "LUN:",IDT_1735,168,72,15,8 + LTEXT "LUN:",IDT_1724,168,72,15,8 COMBOBOX IDC_COMBO_HD_CHANNEL_IDE,134,71,77,12,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP - LTEXT "Channel:",IDT_1736,99,72,34,8 END -/* Static text label IDs. */ -#define IDT_1700 1700 // Language: -#define IDT_1701 1701 // Machine: -#define IDT_1702 1702 // CPU type: -#define IDT_1703 1703 // Wait states: -#define IDT_1704 1704 // CPU: -#define IDT_1705 1705 // MB == IDC_TEXT_MB -#define IDT_1706 1706 // Memory: -#define IDT_1707 1707 // Video: -#define IDT_1708 1708 // Video speed: -#define IDT_1709 1709 // Mouse: -#define IDT_1710 1710 // Joystick: -#define IDT_1711 1711 // Sound card: -#define IDT_1712 1712 // MIDI Out Device: -#define IDT_1713 1713 // Network type: -#define IDT_1714 1714 // PCap device: -#define IDT_1715 1715 // Network adapter: -#define IDT_1716 1716 // SCSI Controller: -#define IDT_1717 1717 // HD Controller: -#define IDT_1718 1718 // Tertiary IDE: -#define IDT_1719 1719 // Quaternary IDE: -#define IDT_1720 1720 // Hard disks: -#define IDT_1721 1721 // Bus: -#define IDT_1722 1722 // Channel: -#define IDT_1723 1723 // ID: -#define IDT_1724 1724 // LUN: -#define IDT_1725 1725 // Channel: -#define IDT_1726 1726 // Sectors: -#define IDT_1727 1727 // Heads: -#define IDT_1728 1728 // Cylinders: -#define IDT_1729 1729 // Size (MB): -#define IDT_1730 1730 // Type: -#define IDT_1731 1731 // File name: -#define IDT_1732 1732 // Bus: -#define IDT_1733 1733 // Channel: -#define IDT_1734 1734 // ID: -#define IDT_1735 1735 // LUN: -#define IDT_1736 1736 // Channel: -#define IDT_1737 1737 // Floppy drives: -#define IDT_1738 1738 // Type: -#define IDT_1739 1739 // CD-ROM drives: -#define IDT_1740 1740 // Bus: -#define IDT_1741 1741 // ID: -#define IDT_1742 1742 // LUN: -#define IDT_1743 1743 // Channel: - DLG_CFG_REMOVABLE_DEVICES DIALOG DISCARDABLE 97, 0, 267, 202 STYLE DS_CONTROL | WS_CHILD FONT 9, "Segoe UI" diff --git a/src/WIN/plat_ui.h b/src/WIN/plat_ui.h new file mode 100644 index 000000000..7bc6d35d9 --- /dev/null +++ b/src/WIN/plat_ui.h @@ -0,0 +1,26 @@ +#ifndef __unix +extern void plat_msgbox_error(int i); +extern wchar_t *plat_get_string_from_id(int i); + +#ifndef IDS_2219 +#define IDS_2219 2219 +#endif + +#ifndef IDS_2077 +#define IDS_2077 2077 +#endif + +#ifndef IDS_2078 +#define IDS_2078 2078 +#endif + +#ifndef IDS_2079 +#define IDS_2079 2079 +#endif +#endif + +extern void plat_msgbox_fatal(char *string); +extern void get_executable_name(wchar_t *s, int size); +extern void set_window_title(wchar_t *s); +extern void startblit(void); +extern void endblit(void); diff --git a/src/WIN/resource.h b/src/WIN/resource.h index 39feb0a5d..d73057c21 100644 --- a/src/WIN/resource.h +++ b/src/WIN/resource.h @@ -10,7 +10,7 @@ * * NOTE: FIXME: Strings 2176 and 2193 are same. * - * Version: @(#)resource.h 1.0.3 2017/06/04 + * Version: @(#)resource.h 1.0.4 2017/06/16 * * Authors: Sarah Walker, * Miran Grca, @@ -37,52 +37,46 @@ #define DLG_CFG_REMOVABLE_DEVICES 119 /* sub-dialog of config */ /* Static text label IDs. */ -#define IDT_1700 1700 // Language: -#define IDT_1701 1701 // Machine: -#define IDT_1702 1702 // CPU type: -#define IDT_1703 1703 // Wait states: -#define IDT_1704 1704 // CPU: -#define IDT_1705 1705 // MB == IDC_TEXT_MB -#define IDT_1706 1706 // Memory: -#define IDT_1707 1707 // Video: -#define IDT_1708 1708 // Video speed: -#define IDT_1709 1709 // Mouse: -#define IDT_1710 1710 // Joystick: -#define IDT_1711 1711 // Sound card: -#define IDT_1712 1712 // MIDI Out Device: -#define IDT_1713 1713 // Network type: -#define IDT_1714 1714 // PCap device: -#define IDT_1715 1715 // Network adapter: -#define IDT_1716 1716 // SCSI Controller: -#define IDT_1717 1717 // HD Controller: -#define IDT_1718 1718 // Tertiary IDE: -#define IDT_1719 1719 // Quaternary IDE: -#define IDT_1720 1720 // Hard disks: -#define IDT_1721 1721 // Bus: -#define IDT_1722 1722 // Channel: -#define IDT_1723 1723 // ID: -#define IDT_1724 1724 // LUN: -#define IDT_1725 1725 // Channel: -#define IDT_1726 1726 // Sectors: -#define IDT_1727 1727 // Heads: -#define IDT_1728 1728 // Cylinders: -#define IDT_1729 1729 // Size (MB): -#define IDT_1730 1730 // Type: -#define IDT_1731 1731 // File name: -#define IDT_1732 1732 // Bus: -#define IDT_1733 1733 // Channel: -#define IDT_1734 1734 // ID: -#define IDT_1735 1735 // LUN: -#define IDT_1736 1736 // Channel: -#define IDT_1737 1737 // Floppy drives: -#define IDT_1738 1738 // Type: -#define IDT_1739 1739 // CD-ROM drives: -#define IDT_1740 1740 // Bus: -#define IDT_1741 1741 // ID: -#define IDT_1742 1742 // LUN: -#define IDT_1743 1743 // Channel: -#define IDT_STEXT 1744 // text in status window -#define IDT_SDEVICE 1745 // text in status window +#define IDT_1700 1700 /* Language: */ +#define IDT_1701 1701 /* Machine: */ +#define IDT_1702 1702 /* CPU type: */ +#define IDT_1703 1703 /* Wait states: */ +#define IDT_1704 1704 /* CPU: */ +#define IDT_1705 1705 /* MB == IDC_TEXT_MB */ +#define IDT_1706 1706 /* Memory: */ +#define IDT_1707 1707 /* Video: */ +#define IDT_1708 1708 /* Video speed: */ +#define IDT_1709 1709 /* Mouse: */ +#define IDT_1710 1710 /* Joystick: */ +#define IDT_1711 1711 /* Sound card: */ +#define IDT_1712 1712 /* MIDI Out Device: */ +#define IDT_1713 1713 /* Network type: */ +#define IDT_1714 1714 /* PCap device: */ +#define IDT_1715 1715 /* Network adapter: */ +#define IDT_1716 1716 /* SCSI Controller: */ +#define IDT_1717 1717 /* HD Controller: */ +#define IDT_1718 1718 /* Tertiary IDE: */ +#define IDT_1719 1719 /* Quaternary IDE: */ +#define IDT_1720 1720 /* Hard disks: */ +#define IDT_1721 1721 /* Bus: */ +#define IDT_1722 1722 /* Channel: */ +#define IDT_1723 1723 /* ID: */ +#define IDT_1724 1724 /* LUN: */ +#define IDT_1726 1726 /* Sectors: */ +#define IDT_1727 1727 /* Heads: */ +#define IDT_1728 1728 /* Cylinders: */ +#define IDT_1729 1729 /* Size (MB): */ +#define IDT_1730 1730 /* Type: */ +#define IDT_1731 1731 /* File name: */ +#define IDT_1737 1737 /* Floppy drives: */ +#define IDT_1738 1738 /* Type: */ +#define IDT_1739 1739 /* CD-ROM drives: */ +#define IDT_1740 1740 /* Bus: */ +#define IDT_1741 1741 /* ID: */ +#define IDT_1742 1742 /* LUN: */ +#define IDT_1743 1743 /* Channel: */ +#define IDT_STEXT 1744 /* text in status window */ +#define IDT_SDEVICE 1745 /* text in status window */ /* diff --git a/src/WIN/win.c b/src/WIN/win.c index 394a05e3b..41eb621dc 100644 --- a/src/WIN/win.c +++ b/src/WIN/win.c @@ -49,6 +49,7 @@ #include "plat_mouse.h" #include "plat_midi.h" #include "plat_thread.h" +#include "plat_ui.h" #include "win.h" #include "win_cgapal.h" @@ -525,12 +526,12 @@ void create_removable_disk_submenu(HMENU m, int id) AppendMenu(m, MF_STRING, IDM_RDISK_IMAGE_WP | id, win_language_get_string_from_id(2220)); } -void get_executable_name(WCHAR *s, int size) +void get_executable_name(wchar_t *s, int size) { GetModuleFileName(hinstance, s, size); } -void set_window_title(WCHAR *s) +void set_window_title(wchar_t *s) { if (video_fullscreen) return; diff --git a/src/WIN/win.h b/src/WIN/win.h index 72bad6dcf..d2006df00 100644 --- a/src/WIN/win.h +++ b/src/WIN/win.h @@ -83,8 +83,8 @@ extern void joystickconfig_open(HWND hwnd, int joy_nr, int type); extern int getfile(HWND hwnd, char *f, char *fn); extern int getsfile(HWND hwnd, char *f, char *fn); -extern void get_executable_name(WCHAR *s, int size); -extern void set_window_title(WCHAR *s); +extern void get_executable_name(wchar_t *s, int size); +extern void set_window_title(wchar_t *s); extern void startblit(void); extern void endblit(void); diff --git a/src/WIN/win_d3d.cc b/src/WIN/win_d3d.cc index 97953515f..456b67254 100644 --- a/src/WIN/win_d3d.cc +++ b/src/WIN/win_d3d.cc @@ -71,7 +71,6 @@ static CUSTOMVERTEX d3d_verts[] = int d3d_init(HWND h) { int c; - int ret; for (c = 0; c < 256; c++) pal_lookup[c] = makecol(cgapal[c].r << 2, cgapal[c].g << 2, cgapal[c].b << 2); diff --git a/src/WIN/win_deviceconfig.c b/src/WIN/win_deviceconfig.c index 1b1f994ce..cf0474c16 100644 --- a/src/WIN/win_deviceconfig.c +++ b/src/WIN/win_deviceconfig.c @@ -30,8 +30,6 @@ static BOOL CALLBACK deviceconfig_dlgproc(HWND hdlg, UINT message, WPARAM wParam { HWND h; int val_int; - int num; - char s[80]; switch (message) { diff --git a/src/WIN/win_dynld.c b/src/WIN/win_dynld.c index 9f7d4d3c5..42b245fc5 100644 --- a/src/WIN/win_dynld.c +++ b/src/WIN/win_dynld.c @@ -29,7 +29,7 @@ dynld_module(const char *name, dllimp_t *table) HMODULE h; dllimp_t *imp; void *func; - char **foo; + /* char **foo; */ /* See if we can load the desired module. */ if ((h = LoadLibrary(name)) == NULL) { diff --git a/src/WIN/win_language.c b/src/WIN/win_language.c index 6279e2da6..61dae5f2c 100644 --- a/src/WIN/win_language.c +++ b/src/WIN/win_language.c @@ -20,6 +20,7 @@ #define BITMAP WINDOWS_BITMAP #include #include +#include #undef BITMAP #include @@ -27,6 +28,7 @@ #include "../ibm.h" #include "../device.h" #include "../ide.h" +#include "plat_ui.h" #include "win.h" #include "win_language.h" @@ -82,6 +84,11 @@ LPTSTR win_language_get_string_from_id(int i) return lpResourceString[i - 2048]; } +wchar_t *plat_get_string_from_id(int i) +{ + return (wchar_t *) win_language_get_string_from_id(i); +} + LPTSTR win_language_get_string_from_string(char *str) { return lpResourceString[atoi(str) - 2048]; @@ -117,6 +124,11 @@ void msgbox_error(HWND hwndParent, int i) MessageBox(hwndParent, win_language_get_string_from_id(i), lpResourceString[1], MB_OK | MB_ICONWARNING); } +void plat_msgbox_error(int i) +{ + msgbox_error(ghwnd, i); +} + void msgbox_error_wstr(HWND hwndParent, WCHAR *wstr) { MessageBox(hwndParent, wstr, lpResourceString[1], MB_OK | MB_ICONWARNING); @@ -139,6 +151,11 @@ void msgbox_fatal(HWND hwndParent, char *string) free(lptsTemp); } +void plat_msgbox_fatal(char *string) +{ + msgbox_fatal(ghwnd, string); +} + int file_dlg_w(HWND hwnd, WCHAR *f, WCHAR *fn, int save) { OPENFILENAME ofn; /* common dialog box structure */ @@ -207,3 +224,47 @@ int file_dlg_st(HWND hwnd, int i, char *fn, int save) { return file_dlg(hwnd, win_language_get_string_from_id(i), fn, save); } + +static int CALLBACK BrowseCallbackProc(HWND hwnd,UINT uMsg, LPARAM lParam, LPARAM lpData) +{ + if(uMsg == BFFM_INITIALIZED) + { + SendMessage(hwnd, BFFM_SETSELECTION, TRUE, lpData); + } + + return 0; +} + +WCHAR path[MAX_PATH]; + +wchar_t *BrowseFolder(wchar_t *saved_path) +{ + BROWSEINFO bi = { 0 }; + bi.lpszTitle = L"Browse for folder..."; + bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE; + bi.lpfn = BrowseCallbackProc; + bi.lParam = (LPARAM) saved_path; + + LPITEMIDLIST pidl = SHBrowseForFolder(&bi); + + if (pidl != 0) + { + /* Get the name of the folder and put it in path. */ + SHGetPathFromIDList(pidl, path); + + /* Free memory used. */ +#if 0 + IMalloc *imalloc = 0; + if (SUCCEEDED(SHGetMalloc(&imalloc))) + { + imalloc->Free(pidl); + imalloc->Release(); + } +#endif + free(pidl); + + return path; + } + + return L""; +} diff --git a/src/WIN/win_midi.c b/src/WIN/win_midi.c index 3850201bf..1515fa5ac 100644 --- a/src/WIN/win_midi.c +++ b/src/WIN/win_midi.c @@ -113,25 +113,8 @@ void midi_get_dev_name(int num, char *s) strcpy(s, caps.szPname); } -static int midi_pos, midi_len; -static uint32_t midi_command; -static int midi_lengths[8] = {3, 3, 3, 3, 2, 2, 3, 1}; -static int midi_insysex; -static char midi_sysex_data[1024+2]; - -static void midi_send_sysex() -{ - MIDIHDR hdr; - - hdr.lpData = midi_sysex_data; - hdr.dwBufferLength = midi_pos; - hdr.dwFlags = 0; - - midiOutPrepareHeader(midi_out_device, &hdr, sizeof(MIDIHDR)); - midiOutLongMsg(midi_out_device, &hdr, sizeof(MIDIHDR)); - - midi_insysex = 0; -} +static int midi_pos; +static uint8_t midi_sysex_data[1024+2]; void PlayMsg(uint8_t *msg) { @@ -262,7 +245,7 @@ void midi_write(uint8_t val) void midi_reset() { - uint8_t buf[64], used; + uint8_t buf[64]; /* Flush buffers */ midiOutReset(midi_out_device); diff --git a/src/WIN/win_serial.c b/src/WIN/win_serial.c index 1db962177..b6ec04e3f 100644 --- a/src/WIN/win_serial.c +++ b/src/WIN/win_serial.c @@ -87,8 +87,6 @@ pclog("%s: queued byte %02x (%d)\n", pp->name, b, pp->icnt+1); int bhtty_sstate(BHTTY *pp, void *arg) { - int i = 0; - /* Make sure we can do this. */ if (arg == NULL) { pclog("%s: invalid argument\n", pp->name); @@ -109,8 +107,6 @@ bhtty_sstate(BHTTY *pp, void *arg) int bhtty_gstate(BHTTY *pp, void *arg) { - int i = 0; - /* Make sure we can do this. */ if (arg == NULL) { pclog("%s: invalid argument\n", pp->name); @@ -304,8 +300,6 @@ bhtty_raw(BHTTY *pp, void *arg) int bhtty_speed(BHTTY *pp, long speed) { - int i; - /* Get the current mode and speed. */ if (bhtty_gstate(pp, &pp->dcb) < 0) return(-1); @@ -331,7 +325,6 @@ bhtty_flush(BHTTY *pp) { DWORD dwErrs; COMSTAT cs; - int i = 0; /* First, clear any errors. */ (void)ClearCommError(pp->handle, &dwErrs, &cs); diff --git a/src/WIN/win_settings.c b/src/WIN/win_settings.c index 865bc39dd..d16435b22 100644 --- a/src/WIN/win_settings.c +++ b/src/WIN/win_settings.c @@ -1860,7 +1860,7 @@ static void recalc_location_controls(HWND hdlg, int is_add_dlg) int bus = 0; - for (i = 1799; i < 1803; i++) + for (i = IDT_1722; i <= IDT_1724; i++) { h = GetDlgItem(hdlg, i); EnableWindow(h, FALSE); @@ -1892,7 +1892,7 @@ static void recalc_location_controls(HWND hdlg, int is_add_dlg) switch(bus) { case HDD_BUS_MFM: /* MFM */ - h = GetDlgItem(hdlg, 1799); + h = GetDlgItem(hdlg, IDT_1722); ShowWindow(h, SW_SHOW); EnableWindow(h, TRUE); @@ -1902,7 +1902,7 @@ static void recalc_location_controls(HWND hdlg, int is_add_dlg) SendMessage(h, CB_SETCURSEL, is_add_dlg ? new_hdc.mfm_channel : temp_hdc[hdlv_current_sel].mfm_channel, 0); break; case HDD_BUS_RLL: /* RLL */ - h = GetDlgItem(hdlg, 1799); + h = GetDlgItem(hdlg, IDT_1722); ShowWindow(h, SW_SHOW); EnableWindow(h, TRUE); @@ -1912,7 +1912,7 @@ static void recalc_location_controls(HWND hdlg, int is_add_dlg) SendMessage(h, CB_SETCURSEL, is_add_dlg ? new_hdc.rll_channel : temp_hdc[hdlv_current_sel].rll_channel, 0); break; case HDD_BUS_XTIDE: /* XT IDE */ - h = GetDlgItem(hdlg, 1799); + h = GetDlgItem(hdlg, IDT_1722); ShowWindow(h, SW_SHOW); EnableWindow(h, TRUE); @@ -1923,7 +1923,7 @@ static void recalc_location_controls(HWND hdlg, int is_add_dlg) break; case HDD_BUS_IDE_PIO_ONLY: /* IDE (PIO-only) */ case HDD_BUS_IDE_PIO_AND_DMA: /* IDE (PIO and DMA) */ - h = GetDlgItem(hdlg, 1802); + h = GetDlgItem(hdlg, IDT_1722); ShowWindow(h, SW_SHOW); EnableWindow(h, TRUE); @@ -1934,10 +1934,10 @@ static void recalc_location_controls(HWND hdlg, int is_add_dlg) break; case HDD_BUS_SCSI: /* SCSI */ case HDD_BUS_SCSI_REMOVABLE: /* SCSI (removable) */ - h = GetDlgItem(hdlg, 1800); + h = GetDlgItem(hdlg, IDT_1723); ShowWindow(h, SW_SHOW); EnableWindow(h, TRUE); - h = GetDlgItem(hdlg, 1801); + h = GetDlgItem(hdlg, IDT_1724); ShowWindow(h, SW_SHOW); EnableWindow(h, TRUE); @@ -1956,7 +1956,7 @@ static void recalc_location_controls(HWND hdlg, int is_add_dlg) if ((hd_listview_items == 0) && !is_add_dlg) { - h = GetDlgItem(hdlg, 1798); + h = GetDlgItem(hdlg, IDT_1721); EnableWindow(h, FALSE); ShowWindow(h, SW_HIDE); @@ -1965,7 +1965,7 @@ static void recalc_location_controls(HWND hdlg, int is_add_dlg) } else { - h = GetDlgItem(hdlg, 1798); + h = GetDlgItem(hdlg, IDT_1721); ShowWindow(h, SW_SHOW); EnableWindow(h, TRUE); @@ -3130,12 +3130,9 @@ int hard_disk_was_added(void) void hard_disk_add_open(HWND hwnd, int is_existing) { - BOOL ret; - existing = is_existing; hard_disk_added = 0; - ret = DialogBox(hinstance, (LPCWSTR)DLG_CFG_HARD_DISKS_ADD, - hwnd, win_settings_hard_disks_add_proc); + DialogBox(hinstance, (LPCWSTR)DLG_CFG_HARD_DISKS_ADD, hwnd, win_settings_hard_disks_add_proc); } int ignore_change = 0; @@ -3758,7 +3755,7 @@ static void cdrom_recalc_location_controls(HWND hdlg) int bus = temp_cdrom_drives[cdlv_current_sel].bus_type; - for (i = 1800; i < 1803; i++) + for (i = IDT_1741; i < (IDT_1743 + 1); i++) { h = GetDlgItem(hdlg, i); EnableWindow(h, FALSE); @@ -3779,9 +3776,9 @@ static void cdrom_recalc_location_controls(HWND hdlg) switch(bus) { - case CDROM_BUS_ATAPI_PIO_ONLY: /* ATAPI (PIO-only) */ + case CDROM_BUS_ATAPI_PIO_ONLY: /* ATAPI (PIO-only) */ case CDROM_BUS_ATAPI_PIO_AND_DMA: /* ATAPI (PIO and DMA) */ - h = GetDlgItem(hdlg, 1802); + h = GetDlgItem(hdlg, IDT_1743); ShowWindow(h, SW_SHOW); EnableWindow(h, TRUE); @@ -3791,10 +3788,10 @@ static void cdrom_recalc_location_controls(HWND hdlg) SendMessage(h, CB_SETCURSEL, temp_cdrom_drives[cdlv_current_sel].ide_channel, 0); break; case CDROM_BUS_SCSI: /* SCSI */ - h = GetDlgItem(hdlg, 1800); + h = GetDlgItem(hdlg, IDT_1741); ShowWindow(h, SW_SHOW); EnableWindow(h, TRUE); - h = GetDlgItem(hdlg, 1801); + h = GetDlgItem(hdlg, IDT_1742); ShowWindow(h, SW_SHOW); EnableWindow(h, TRUE); diff --git a/src/cdrom_dosbox.cpp b/src/cdrom_dosbox.cpp index 7b621a710..4def610ca 100644 --- a/src/cdrom_dosbox.cpp +++ b/src/cdrom_dosbox.cpp @@ -51,8 +51,6 @@ using namespace std; CDROM_Interface_Image::BinaryFile::BinaryFile(const char *filename, bool &error) { - // file = fopen64(filename, "rb"); - // error = (file == NULL); memset(fn, 0, sizeof(fn)); strcpy(fn, filename); error = false; @@ -60,19 +58,16 @@ CDROM_Interface_Image::BinaryFile::BinaryFile(const char *filename, bool &error) CDROM_Interface_Image::BinaryFile::~BinaryFile() { - // delete file; memset(fn, 0, sizeof(fn)); } bool CDROM_Interface_Image::BinaryFile::read(Bit8u *buffer, uint64_t seek, uint64_t count) { - uint64_t offs = 0; file = fopen64(fn, "rb"); if (file == NULL) return 0; fseeko64(file, seek, SEEK_SET); - offs = fread(buffer, 1, count, file); + fread(buffer, 1, count, file); fclose(file); - // return (offs == count); return 1; } @@ -179,7 +174,7 @@ bool CDROM_Interface_Image::LoadUnloadMedia(bool unload) return true; } -int CDROM_Interface_Image::GetTrack(int sector) +int CDROM_Interface_Image::GetTrack(unsigned int sector) { vector::iterator i = tracks.begin(); vector::iterator end = tracks.end() - 1; @@ -225,9 +220,6 @@ bool CDROM_Interface_Image::IsMode2(unsigned long sector) bool CDROM_Interface_Image::LoadIsoFile(char* filename) { - int shift = 0; - int totalPregap = 0; - tracks.clear(); // data track diff --git a/src/cdrom_dosbox.h b/src/cdrom_dosbox.h index 243723fe4..dc88bbe45 100644 --- a/src/cdrom_dosbox.h +++ b/src/cdrom_dosbox.h @@ -149,7 +149,7 @@ public: bool HasDataTrack (void); bool HasAudioTracks (void); - int GetTrack (int sector); + int GetTrack (unsigned int sector); private: // player diff --git a/src/cdrom_image.cc b/src/cdrom_image.cc index 810601b24..204708742 100644 --- a/src/cdrom_image.cc +++ b/src/cdrom_image.cc @@ -108,7 +108,6 @@ static void image_playaudio(uint8_t id, uint32_t pos, uint32_t len, int ismsf) unsigned char attr; TMSF tmsf; int m = 0, s = 0, f = 0; - uint32_t start_msf = 0, end_msf = 0; cdimg[id]->GetAudioTrackInfo(cdimg[id]->GetTrack(pos), number, tmsf, attr); if (attr == DATA_TRACK) { @@ -185,13 +184,6 @@ static void image_stop(uint8_t id) cdrom_image[id].cd_state = CD_STOPPED; } -static void image_seek(uint8_t id, uint32_t pos) -{ - if (!cdimg[id] || cdrom_image[id].image_is_iso) return; - cdrom_image[id].cd_pos = pos; - cdrom_image[id].cd_state = CD_STOPPED; -} - static int image_ready(uint8_t id) { if (!cdimg[id]) @@ -771,14 +763,6 @@ read_mode2: } -static void lba_to_msf(uint8_t *buf, int lba) -{ - lba += 150; - buf[0] = (lba / 75) / 60; - buf[1] = (lba / 75) % 60; - buf[2] = lba % 75; -} - static uint32_t image_size(uint8_t id) { return cdrom_image[id].cdrom_capacity; @@ -905,7 +889,6 @@ static int image_readtoc_raw(uint8_t id, unsigned char *b, int maxlen) int number; unsigned char attr; TMSF tmsf; - int lb; if (!cdimg[id]) return 0; diff --git a/src/cdrom_ioctl.c b/src/cdrom_ioctl.c index 201753e47..0b32b79b7 100644 --- a/src/cdrom_ioctl.c +++ b/src/cdrom_ioctl.c @@ -1047,7 +1047,7 @@ split_block_read_iterate: static int ioctl_readtoc(uint8_t id, unsigned char *b, unsigned char starttrack, int msf, int maxlen, int single) { int len=4; - long size; + DWORD size; int c,d; uint32_t temp; uint32_t last_block; @@ -1156,9 +1156,7 @@ static int ioctl_readtoc_raw(uint8_t id, uint8_t *b, int maxlen) { int len=4; int size; - uint32_t temp; int i; - int BytesRead = 0; CDROM_READ_TOC_EX toc_ex; CDROM_TOC_FULL_TOC_DATA toc; if (!cdrom_drives[id].host_drive) diff --git a/src/config.c b/src/config.c index 7a044a6c0..1b6b9f561 100644 --- a/src/config.c +++ b/src/config.c @@ -109,6 +109,7 @@ void config_dump(void) } +#if 0 static void config_free(void) { section_t *current_section; @@ -133,6 +134,7 @@ static void config_free(void) current_section = next_section; } } +#endif static wchar_t cfgbuffer[1024]; @@ -477,7 +479,6 @@ void config_delete_var(char *head, char *name) void config_delete_section_if_empty(char *head) { section_t *section; - entry_t *entry; section = find_section(head); diff --git a/src/disc_imd.c b/src/disc_imd.c index b0a8b0016..d511dd46d 100644 --- a/src/disc_imd.c +++ b/src/disc_imd.c @@ -508,10 +508,10 @@ void imd_seek(int drive, int track) int real_sector = 0; int actual_sector = 0; - char *c_map; - char *h_map; + char *c_map = NULL; + char *h_map = NULL; char *r_map; - char *n_map; + char *n_map = NULL; uint8_t *data; uint32_t track_buf_pos[2] = { 0, 0 }; diff --git a/src/disc_img.c b/src/disc_img.c index f9016be4b..4220e5af0 100644 --- a/src/disc_img.c +++ b/src/disc_img.c @@ -61,38 +61,38 @@ uint8_t xdf_gap3_sizes[2][2] = { { 60, 69 }, { 60, 50 } }; uint16_t xdf_trackx_spos[2][8] = { { 0xA7F, 0xF02, 0x11B7, 0xB66, 0xE1B, 0x129E }, { 0x302, 0x7E2, 0xA52, 0x12DA, 0x572, 0xDFA, 0x106A, 0x154A } }; /* XDF: Layout of the sectors in the image. */ -xdf_sector_t xdf_img_layout[2][2][46] = { { { 0x8100, 0x8200, 0x8300, 0x8400, 0x8500, 0x8600, 0x8700, 0x8800, - 0x8101, 0x8201, 0x0100, 0x0200, 0x0300, 0x0400, 0x0500, 0x0600, - 0x0700, 0x0800, 0, - 0x8301, 0x8401, 0x8501, 0x8601, 0x8701, 0x8801, 0x8901, 0x8A01, - 0x8B01, 0x8C01, 0x8D01, 0x8E01, 0x8F01, 0x9001, 0, 0, - 0, 0, 0 }, - { 0x8300, 0x8600, 0x8201, 0x8200, 0x8601, 0x8301 } +xdf_sector_t xdf_img_layout[2][2][46] = { { { {0x8100}, {0x8200}, {0x8300}, {0x8400}, {0x8500}, {0x8600}, {0x8700}, {0x8800}, + {0x8101}, {0x8201}, {0x0100}, {0x0200}, {0x0300}, {0x0400}, {0x0500}, {0x0600}, + {0x0700}, {0x0800}, { 0}, + {0x8301}, {0x8401}, {0x8501}, {0x8601}, {0x8701}, {0x8801}, {0x8901}, {0x8A01}, + {0x8B01}, {0x8C01}, {0x8D01}, {0x8E01}, {0x8F01}, {0x9001}, { 0}, { 0}, + { 0}, { 0}, { 0} }, + { {0x8300}, {0x8600}, {0x8201}, {0x8200}, {0x8601}, {0x8301} } }, /* 5.25" 2HD */ - { { 0x8100, 0x8200, 0x8300, 0x8400, 0x8500, 0x8600, 0x8700, 0x8800, - 0x8900, 0x8A00, 0x8B00, 0x8101, 0x0100, 0x0200, 0x0300, 0x0400, - 0x0500, 0x0600, 0x0700, 0x0800, 0, 0, 0, - 0x8201, 0x8301, 0x8401, 0x8501, 0x8601, 0x8701, 0x8801, 0x8901, - 0x8A01, 0x8B01, 0x8C01, 0x8D01, 0x8E01, 0x8F01, 0, 0, - 0, 0, 0, 0x9001, 0x9101, 0x9201, 0x9301 }, - { 0x8300, 0x8400, 0x8601, 0x8200, 0x8201, 0x8600, 0x8401, 0x8301 } + { { {0x8100}, {0x8200}, {0x8300}, {0x8400}, {0x8500}, {0x8600}, {0x8700}, {0x8800}, + {0x8900}, {0x8A00}, {0x8B00}, {0x8101}, {0x0100}, {0x0200}, {0x0300}, {0x0400}, + {0x0500}, {0x0600}, {0x0700}, {0x0800}, { 0}, { 0}, { 0}, + {0x8201}, {0x8301}, {0x8401}, {0x8501}, {0x8601}, {0x8701}, {0x8801}, {0x8901}, + {0x8A01}, {0x8B01}, {0x8C01}, {0x8D01}, {0x8E01}, {0x8F01}, { 0}, { 0}, + { 0}, { 0}, { 0}, {0x9001}, {0x9101}, {0x9201}, {0x9301} }, + { {0x8300}, {0x8400}, {0x8601}, {0x8200}, {0x8201}, {0x8600}, {0x8401}, {0x8301} } } /* 3.5" 2HD */ }; /* XDF: Layout of the sectors on the disk's track. */ -xdf_sector_t xdf_disk_layout[2][2][38] = { { { 0x0100, 0x0200, 0x8100, 0x8800, 0x8200, 0x0300, 0x8300, 0x0400, - 0x8400, 0x0500, 0x8500, 0x0600, 0x8600, 0x0700, 0x8700, 0x0800, - 0x8D01, 0x8501, 0x8E01, 0x8601, 0x8F01, 0x8701, 0x9001, 0x8801, - 0x8101, 0x8901, 0x8201, 0x8A01, 0x8301, 0x8B01, 0x8401, 0x8C01 }, - { 0x8300, 0x8200, 0x8600, 0x8201, 0x8301, 0x8601 } +xdf_sector_t xdf_disk_layout[2][2][38] = { { { {0x0100}, {0x0200}, {0x8100}, {0x8800}, {0x8200}, {0x0300}, {0x8300}, {0x0400}, + {0x8400}, {0x0500}, {0x8500}, {0x0600}, {0x8600}, {0x0700}, {0x8700}, {0x0800}, + {0x8D01}, {0x8501}, {0x8E01}, {0x8601}, {0x8F01}, {0x8701}, {0x9001}, {0x8801}, + {0x8101}, {0x8901}, {0x8201}, {0x8A01}, {0x8301}, {0x8B01}, {0x8401}, {0x8C01} }, + { {0x8300}, {0x8200}, {0x8600}, {0x8201}, {0x8301}, {0x8601} } }, /* 5.25" 2HD */ - { { 0x0100, 0x8A00, 0x8100, 0x8B00, 0x8200, 0x0200, 0x8300, 0x0300, - 0x8400, 0x0400, 0x8500, 0x0500, 0x8600, 0x0600, 0x8700, 0x0700, - 0x8800, 0x0800, 0x8900, - 0x9001, 0x8701, 0x9101, 0x8801, 0x9201, 0x8901, 0x9301, 0x8A01, - 0x8101, 0x8B01, 0x8201, 0x8C01, 0x8301, 0x8D01, 0x8401, 0x8E01, - 0x8501, 0x8F01, 0x8601 }, - { 0x8300, 0x8200, 0x8400, 0x8600, 0x8401, 0x8201, 0x8301, 0x8601 }, + { { {0x0100}, {0x8A00}, {0x8100}, {0x8B00}, {0x8200}, {0x0200}, {0x8300}, {0x0300}, + {0x8400}, {0x0400}, {0x8500}, {0x0500}, {0x8600}, {0x0600}, {0x8700}, {0x0700}, + {0x8800}, {0x0800}, {0x8900}, + {0x9001}, {0x8701}, {0x9101}, {0x8801}, {0x9201}, {0x8901}, {0x9301}, {0x8A01}, + {0x8101}, {0x8B01}, {0x8201}, {0x8C01}, {0x8301}, {0x8D01}, {0x8401}, {0x8E01}, + {0x8501}, {0x8F01}, {0x8601} }, + { {0x8300}, {0x8200}, {0x8400}, {0x8600}, {0x8401}, {0x8201}, {0x8301}, {0x8601} }, }, /* 3.5" 2HD */ }; diff --git a/src/fdc37c665.c b/src/fdc37c665.c index 00a80c429..56623d054 100644 --- a/src/fdc37c665.c +++ b/src/fdc37c665.c @@ -45,6 +45,7 @@ static void write_lock(uint8_t val) static void ide_handler() { +#if 0 uint16_t or_value = 0; if ((romset == ROM_440FX) || (romset == ROM_R418) || (romset == ROM_MB500N)) { @@ -65,6 +66,7 @@ static void ide_handler() ide_set_side(0, 0x376 | or_value); ide_pri_enable_ex(); } +#endif } static void set_com34_addr() diff --git a/src/hdd_esdi.c b/src/hdd_esdi.c index 4c3cc152d..4f31c8836 100644 --- a/src/hdd_esdi.c +++ b/src/hdd_esdi.c @@ -1,17 +1,9 @@ -#define _LARGEFILE_SOURCE -#define _LARGEFILE64_SOURCE -#define _GNU_SOURCE -#include -#include -#include -#include -#include - -#include +#include #include "ibm.h" #include "device.h" #include "dma.h" +#include "hdd_image.h" #include "io.h" #include "mca.h" #include "mem.h" @@ -30,7 +22,8 @@ typedef struct esdi_drive_t int spt, hpc; int tracks; int sectors; - FILE *hdfile; + int present; + int hdc_num; } esdi_drive_t; typedef struct esdi_t @@ -395,7 +388,7 @@ static void esdi_callback(void *p) case CMD_READ: ESDI_DRIVE_ONLY(); - if (!drive->hdfile) + if (!drive->present) { device_not_present(esdi); return; @@ -431,8 +424,7 @@ static void esdi_callback(void *p) { if (esdi->rba >= drive->sectors) fatal("Read past end of drive\n"); - fseek(drive->hdfile, esdi->rba * 512, SEEK_SET); - fread(esdi->data, 512, 1, drive->hdfile); + hdd_image_read(drive->hdc_num, esdi->rba, 1, (uint8_t *) esdi->data); update_status_bar_icon(SB_HDD | HDD_BUS_RLL, 1); } while (esdi->data_pos < 256) @@ -471,7 +463,7 @@ static void esdi_callback(void *p) case CMD_WRITE_VERIFY: ESDI_DRIVE_ONLY(); - if (!drive->hdfile) + if (!drive->present) { device_not_present(esdi); return; @@ -518,8 +510,7 @@ static void esdi_callback(void *p) if (esdi->rba >= drive->sectors) fatal("Write past end of drive\n"); - fseek(drive->hdfile, esdi->rba * 512, SEEK_SET); - fwrite(esdi->data, 512, 1, drive->hdfile); + hdd_image_write(drive->hdc_num, esdi->rba, 1, (uint8_t *) esdi->data); esdi->rba++; esdi->sector_pos++; update_status_bar_icon(SB_HDD | HDD_BUS_RLL, 1); @@ -545,7 +536,7 @@ static void esdi_callback(void *p) case CMD_READ_VERIFY: ESDI_DRIVE_ONLY(); - if (!drive->hdfile) + if (!drive->present) { device_not_present(esdi); return; @@ -560,7 +551,7 @@ static void esdi_callback(void *p) case CMD_SEEK: ESDI_DRIVE_ONLY(); - if (!drive->hdfile) + if (!drive->present) { device_not_present(esdi); return; @@ -575,7 +566,7 @@ static void esdi_callback(void *p) case CMD_GET_DEV_CONFIG: ESDI_DRIVE_ONLY(); - if (!drive->hdfile) + if (!drive->present) { device_not_present(esdi); return; @@ -799,40 +790,22 @@ static void esdi_mca_write(int port, uint8_t val, void *p) static void loadhd(esdi_t *esdi, int hdc_num, int d, const wchar_t *fn) { esdi_drive_t *drive = &esdi->drives[d]; - - if (drive->hdfile == NULL) - { - /* Try to open existing hard disk image */ - drive->hdfile = _wfopen(fn, L"rb+"); - if (drive->hdfile == NULL) - { - /* Failed to open existing hard disk image */ - if (errno == ENOENT) - { - /* Failed because it does not exist, - so try to create new file */ - drive->hdfile = _wfopen(fn, L"wb+"); - if (drive->hdfile == NULL) - { - pclog("Cannot create file '%s': %s", - fn, strerror(errno)); - return; - } - } - else - { - /* Failed for another reason */ - pclog("Cannot open file '%s': %s", - fn, strerror(errno)); - return; - } - } - } + int ret = 0; + ret = hdd_image_load(hdc_num); + + if (!ret) + { + drive->present = 0; + return; + } + drive->spt = hdc[hdc_num].spt; drive->hpc = hdc[hdc_num].hpc; drive->tracks = hdc[hdc_num].tracks; drive->sectors = hdc[hdc_num].spt * hdc[hdc_num].hpc * hdc[hdc_num].tracks; + drive->hdc_num = hdc_num; + drive->present = 1; } static void *esdi_init() @@ -878,9 +851,8 @@ static void esdi_close(void *p) for (d = 0; d < 2; d++) { esdi_drive_t *drive = &esdi->drives[d]; - - if (drive->hdfile != NULL) - fclose(drive->hdfile); + + hdd_image_close(drive->hdc_num); } free(esdi); diff --git a/src/hdd_image.c b/src/hdd_image.c new file mode 100644 index 000000000..ecfcbeb3a --- /dev/null +++ b/src/hdd_image.c @@ -0,0 +1,441 @@ +#define _LARGEFILE_SOURCE +#define _LARGEFILE64_SOURCE +#define _GNU_SOURCE +#include +#include +#include +#include +#include + +#include "ibm.h" +#include "ide.h" +#include "hdd_image.h" + +typedef struct +{ + FILE *file; + uint32_t base; + uint32_t last_sector; + uint8_t type; + uint8_t loaded; +} hdd_image_t; + +hdd_image_t hdd_images[HDC_NUM]; + +static char empty_sector[512]; +static char *empty_sector_1mb; + +int hdd_image_do_log = 0; + +void hdd_image_log(const char *format, ...) +{ +#ifdef ENABLE_HDD_IMAGE_LOG + if (hdd_image_do_log) + { + va_list ap; + va_start(ap, format); + vprintf(format, ap); + va_end(ap); + fflush(stdout); + } +#endif +} + +int image_is_hdi(const wchar_t *s) +{ + int len; + wchar_t ext[5] = { 0, 0, 0, 0, 0 }; + char *ws = (char *) s; + len = wcslen(s); + if ((len < 4) || (s[0] == L'.')) + { + return 0; + } + memcpy(ext, ws + ((len - 4) << 1), 8); + if (wcsicmp(ext, L".HDI") == 0) + { + return 1; + } + else + { + return 0; + } +} + +int image_is_hdx(const wchar_t *s, int check_signature) +{ + int len; + FILE *f; + uint64_t filelen; + uint64_t signature; + char *ws = (char *) s; + wchar_t ext[5] = { 0, 0, 0, 0, 0 }; + len = wcslen(s); + if ((len < 4) || (s[0] == L'.')) + { + return 0; + } + memcpy(ext, ws + ((len - 4) << 1), 8); + if (wcsicmp(ext, L".HDX") == 0) + { + if (check_signature) + { + f = _wfopen(s, L"rb"); + if (!f) + { + return 0; + } + fseeko64(f, 0, SEEK_END); + filelen = ftello64(f); + fseeko64(f, 0, SEEK_SET); + if (filelen < 44) + { + return 0; + } + fread(&signature, 1, 8, f); + fclose(f); + if (signature == 0xD778A82044445459ll) + { + return 1; + } + else + { + return 0; + } + } + else + { + return 1; + } + } + else + { + return 0; + } +} + +int hdd_image_load(int id) +{ + uint32_t sector_size = 512; + uint32_t zero = 0; + uint64_t signature = 0xD778A82044445459ll; + uint64_t full_size = 0; + uint64_t spt = 0, hpc = 0, tracks = 0; + int c; + uint64_t i = 0, s = 0, t = 0; + wchar_t *fn = hdc[id].fn; + + memset(empty_sector, 0, sizeof(empty_sector)); + + hdd_images[id].base = 0; + hdd_images[id].loaded = 0; + + if (hdd_images[id].file != NULL) + { + fclose(hdd_images[id].file); + hdd_images[id].file = NULL; + } + + /* Try to open existing hard disk image */ + if (fn[0] == '.') + { + hdd_image_log("File name starts with .\n"); + memset(hdc[id].fn, 0, sizeof(hdc[id].fn)); + return 0; + } + hdd_images[id].file = _wfopen(fn, L"rb+"); + if (hdd_images[id].file == NULL) + { + /* Failed to open existing hard disk image */ + if (errno == ENOENT) + { + /* Failed because it does not exist, + so try to create new file */ + if (hdc[id].wp) + { + hdd_image_log("A write-protected image must exist\n"); + memset(hdc[id].fn, 0, sizeof(hdc[id].fn)); + return 0; + } + + hdd_images[id].file = _wfopen(fn, L"wb+"); + if (hdd_images[id].file == NULL) + { + hdd_image_log("Unable to open image\n"); + memset(hdc[id].fn, 0, sizeof(hdc[id].fn)); + return 0; + } + else + { + if (image_is_hdi(fn)) + { + full_size = hdc[id].spt * hdc[id].hpc * hdc[id].tracks * 512; + hdd_images[id].base = 0x1000; + fwrite(&zero, 1, 4, hdd_images[id].file); + fwrite(&zero, 1, 4, hdd_images[id].file); + fwrite(&(hdd_images[id].base), 1, 4, hdd_images[id].file); + fwrite(&full_size, 1, 4, hdd_images[id].file); + fwrite(§or_size, 1, 4, hdd_images[id].file); + fwrite(&(hdc[id].spt), 1, 4, hdd_images[id].file); + fwrite(&(hdc[id].hpc), 1, 4, hdd_images[id].file); + fwrite(&(hdc[id].tracks), 1, 4, hdd_images[id].file); + for (c = 0; c < 0x3f8; c++) + { + fwrite(&zero, 1, 4, hdd_images[id].file); + } + hdd_images[id].type = 1; + } + else if (image_is_hdx(fn, 0)) + { + full_size = hdc[id].spt * hdc[id].hpc * hdc[id].tracks * 512; + hdd_images[id].base = 0x28; + fwrite(&signature, 1, 8, hdd_images[id].file); + fwrite(&full_size, 1, 8, hdd_images[id].file); + fwrite(§or_size, 1, 4, hdd_images[id].file); + fwrite(&(hdc[id].spt), 1, 4, hdd_images[id].file); + fwrite(&(hdc[id].hpc), 1, 4, hdd_images[id].file); + fwrite(&(hdc[id].tracks), 1, 4, hdd_images[id].file); + fwrite(&zero, 1, 4, hdd_images[id].file); + fwrite(&zero, 1, 4, hdd_images[id].file); + hdd_images[id].type = 2; + } + else + { + hdd_images[id].type = 0; + } + hdd_images[id].last_sector = 0; + } + + s = full_size = hdc[id].spt * hdc[id].hpc * hdc[id].tracks * 512; + + goto prepare_new_hard_disk; + } + else + { + /* Failed for another reason */ + hdd_image_log("Failed for another reason\n"); + memset(hdc[id].fn, 0, sizeof(hdc[id].fn)); + return 0; + } + } + else + { + if (image_is_hdi(fn)) + { + fseeko64(hdd_images[id].file, 0x8, SEEK_SET); + fread(&(hdd_images[id].base), 1, 4, hdd_images[id].file); + fseeko64(hdd_images[id].file, 0xC, SEEK_SET); + full_size = 0; + fread(&full_size, 1, 4, hdd_images[id].file); + fseeko64(hdd_images[id].file, 0x10, SEEK_SET); + fread(§or_size, 1, 4, hdd_images[id].file); + if (sector_size != 512) + { + /* Sector size is not 512 */ + hdd_image_log("HDI: Sector size is not 512\n"); + fclose(hdd_images[id].file); + hdd_images[id].file = NULL; + memset(hdc[id].fn, 0, sizeof(hdc[id].fn)); + return 0; + } + fread(&spt, 1, 4, hdd_images[id].file); + fread(&hpc, 1, 4, hdd_images[id].file); + fread(&tracks, 1, 4, hdd_images[id].file); + if (hdc[id].bus == HDD_BUS_SCSI_REMOVABLE) + { + if ((spt != hdc[id].spt) || (hpc != hdc[id].hpc) || (tracks != hdc[id].tracks)) + { + hdd_image_log("HDI: Geometry mismatch\n"); + fclose(hdd_images[id].file); + hdd_images[id].file = NULL; + memset(hdc[id].fn, 0, sizeof(hdc[id].fn)); + return 0; + } + } + hdc[id].spt = spt; + hdc[id].hpc = hpc; + hdc[id].tracks = tracks; + hdd_images[id].type = 1; + } + else if (image_is_hdx(fn, 1)) + { + hdd_images[id].base = 0x28; + fseeko64(hdd_images[id].file, 8, SEEK_SET); + fread(&full_size, 1, 8, hdd_images[id].file); + fseeko64(hdd_images[id].file, 0x10, SEEK_SET); + fread(§or_size, 1, 4, hdd_images[id].file); + if (sector_size != 512) + { + /* Sector size is not 512 */ + hdd_image_log("HDX: Sector size is not 512\n"); + fclose(hdd_images[id].file); + hdd_images[id].file = NULL; + memset(hdc[id].fn, 0, sizeof(hdc[id].fn)); + return 0; + } + fread(&spt, 1, 4, hdd_images[id].file); + fread(&hpc, 1, 4, hdd_images[id].file); + fread(&tracks, 1, 4, hdd_images[id].file); + if (hdc[id].bus == HDD_BUS_SCSI_REMOVABLE) + { + if ((spt != hdc[id].spt) || (hpc != hdc[id].hpc) || (tracks != hdc[id].tracks)) + { + hdd_image_log("HDX: Geometry mismatch\n"); + fclose(hdd_images[id].file); + hdd_images[id].file = NULL; + memset(hdc[id].fn, 0, sizeof(hdc[id].fn)); + return 0; + } + } + hdc[id].spt = spt; + hdc[id].hpc = hpc; + hdc[id].tracks = tracks; + fread(&(hdc[id].at_spt), 1, 4, hdd_images[id].file); + fread(&(hdc[id].at_hpc), 1, 4, hdd_images[id].file); + hdd_images[id].type = 2; + } + else + { + full_size = hdc[id].spt * hdc[id].hpc * hdc[id].tracks * 512; + hdd_images[id].type = 0; + } + } + + fseeko64(hdd_images[id].file, 0, SEEK_END); + if (ftello64(hdd_images[id].file) < (full_size + hdd_images[id].base)) + { + s = (full_size + hdd_images[id].base) - ftello64(hdd_images[id].file); +prepare_new_hard_disk: + s >>= 9; + t = (s >> 11) << 11; + s -= t; + t >>= 11; + + empty_sector_1mb = (char *) malloc(1048576); + memset(empty_sector_1mb, 0, 1048576); + + if (s > 0) + { + for (i = 0; i < s; i++) + { + fwrite(empty_sector, 1, 512, hdd_images[id].file); + } + } + + if (t > 0) + { + for (i = 0; i < t; i++) + { + fwrite(empty_sector_1mb, 1, 1045876, hdd_images[id].file); + } + } + + free(empty_sector_1mb); + } + + hdd_images[id].last_sector = (uint32_t) (full_size >> 9) - 1; + + return 1; + hdd_images[id].loaded = 1; +} + +void hdd_image_seek(uint8_t id, uint32_t sector) +{ + uint64_t addr = sector; + addr <<= 9; + addr += hdd_images[id].base; + + fseeko64(hdd_images[id].file, addr, SEEK_SET); +} + +void hdd_image_read(uint8_t id, uint32_t sector, uint32_t count, uint8_t *buffer) +{ + count <<= 9; + + hdd_image_seek(id, sector); + memset(buffer, 0, count); + fread(buffer, 1, count, hdd_images[id].file); +} + +void hdd_image_write(uint8_t id, uint32_t sector, uint32_t count, uint8_t *buffer) +{ + count <<= 9; + + hdd_image_seek(id, sector); + fwrite(buffer, 1, count, hdd_images[id].file); +} + +void hdd_image_zero(uint8_t id, uint32_t sector, uint32_t count) +{ + int i = 0; + uint8_t *b; + + b = (uint8_t *) malloc(512); + memset(b, 0, 512); + + hdd_image_seek(id, sector); + for (i = 0; i < count; i++) + { + fwrite(b, 1, 512, hdd_images[id].file); + } + + free(b); +} + +uint32_t hdd_image_get_last_sector(uint8_t id) +{ + return hdd_images[id].last_sector; +} + +uint8_t hdd_image_get_type(uint8_t id) +{ + return hdd_images[id].type; +} + +void hdd_image_specify(uint8_t id, uint64_t hpc, uint64_t spt) +{ + if (hdd_images[id].type == 2) + { + hdc[id].at_hpc = hpc; + hdc[id].at_spt = spt; + fseeko64(hdd_images[id].file, 0x20, SEEK_SET); + fwrite(&(hdc[id].at_spt), 1, 4, hdd_images[id].file); + fwrite(&(hdc[id].at_hpc), 1, 4, hdd_images[id].file); + } +} + +void hdd_image_unload(uint8_t id, int fn_preserve) +{ + if (wcslen(hdc[id].fn) == 0) + { + return; + } + + if (hdd_images[id].loaded) + { + if (hdd_images[id].file != NULL) + { + fclose(hdd_images[id].file); + hdd_images[id].file = NULL; + } + } + + hdd_images[id].last_sector = -1; + + memset(hdc[id].prev_fn, 0, sizeof(hdc[id].prev_fn)); + if (fn_preserve) + { + wcscpy(hdc[id].prev_fn, hdc[id].fn); + } + + memset(hdc[id].fn, 0, sizeof(hdc[id].fn)); +} + +void hdd_image_close(uint8_t id) +{ + if (hdd_images[id].file != NULL) + { + fclose(hdd_images[id].file); + hdd_images[id].file = NULL; + } +} diff --git a/src/hdd_image.h b/src/hdd_image.h new file mode 100644 index 000000000..e972894fe --- /dev/null +++ b/src/hdd_image.h @@ -0,0 +1,10 @@ +extern int hdd_image_load(int id); +extern void hdd_image_seek(uint8_t id, uint32_t sector); +extern void hdd_image_read(uint8_t id, uint32_t sector, uint32_t count, uint8_t *buffer); +extern void hdd_image_write(uint8_t id, uint32_t sector, uint32_t count, uint8_t *buffer); +extern void hdd_image_zero(uint8_t id, uint32_t sector, uint32_t count); +extern uint32_t hdd_image_get_last_sector(uint8_t id); +extern uint8_t hdd_image_get_type(uint8_t id); +extern void hdd_image_specify(uint8_t id, uint64_t hpc, uint64_t spt); +extern void hdd_image_unload(uint8_t id, int fn_preserve); +extern void hdd_image_close(uint8_t id); diff --git a/src/ibm.h b/src/ibm.h index a95d3635e..2e22ad740 100644 --- a/src/ibm.h +++ b/src/ibm.h @@ -471,6 +471,8 @@ enum ROM_S1668, /*Tyan Titan-Pro ATX / 440FX / AMI BIOS / SMC FDC37C669*/ ROM_IBMPS1_2133, + ROM_PRESIDENT, /*President Award 430FX PCI / 430FX / Award BIOS / Unknown Super I/O chip*/ + ROM_MAX }; @@ -793,3 +795,5 @@ extern void status_settext(char *str); #define SB_RDISK 0x20 #define SB_HDD 0x40 #define SB_TEXT 0x50 + +#define UNUSED(x) (void)x diff --git a/src/ide.c b/src/ide.c index d92ce13be..4a11ed3a7 100644 --- a/src/ide.c +++ b/src/ide.c @@ -9,7 +9,7 @@ * Implementation of the IDE emulation for hard disks and ATAPI * CD-ROM devices. * - * Version: @(#)ide.c 1.0.1 2017/06/03 + * Version: @(#)ide.c 1.0.2 2017/06/16 * * Authors: Sarah Walker, * Miran Grca, @@ -18,23 +18,14 @@ * Copyright 2016-2017 Miran Grca. * Copyright 2016-2017 TheCollector1995. */ -#define _LARGEFILE_SOURCE -#define _LARGEFILE64_SOURCE -#define _GNU_SOURCE -#include -#include -#include #include -#include -#include -#include - #include #include #include "86box.h" #include "cdrom.h" #include "ibm.h" +#include "hdd_image.h" #include "io.h" #include "pic.h" #include "timer.h" @@ -163,79 +154,6 @@ int ide_drive_is_cdrom(IDE *ide) } } -int image_is_hdi(const wchar_t *s) -{ - int len; - wchar_t ext[5] = { 0, 0, 0, 0, 0 }; - char *ws = (char *) s; - len = wcslen(s); - if ((len < 4) || (s[0] == L'.')) - { - return 0; - } - memcpy(ext, ws + ((len - 4) << 1), 8); - if (wcsicmp(ext, L".HDI") == 0) - { - return 1; - } - else - { - return 0; - } -} - -int image_is_hdx(const wchar_t *s, int check_signature) -{ - int len; - FILE *f; - uint64_t filelen; - uint64_t signature; - char *ws = (char *) s; - wchar_t ext[5] = { 0, 0, 0, 0, 0 }; - len = wcslen(s); - if ((len < 4) || (s[0] == L'.')) - { - return 0; - } - memcpy(ext, ws + ((len - 4) << 1), 8); - if (wcsicmp(ext, L".HDX") == 0) - { - if (check_signature) - { - f = _wfopen(s, L"rb"); - if (!f) - { - return 0; - } - fseeko64(f, 0, SEEK_END); - filelen = ftello64(f); - fseeko64(f, 0, SEEK_SET); - if (filelen < 44) - { - return 0; - } - fread(&signature, 1, 8, f); - fclose(f); - if (signature == 0xD778A82044445459ll) - { - return 1; - } - else - { - return 0; - } - } - else - { - return 1; - } - } - else - { - return 0; - } -} - int ide_enable[5] = { 1, 1, 0, 0, 1 }; int ide_irq[5] = { 14, 15, 10, 11, 0 }; @@ -371,7 +289,7 @@ static void ide_identify(IDE *ide) #if 0 uint64_t full_size = (hdc[ide->hdc_num].tracks * hdc[ide->hdc_num].hpc * hdc[ide->hdc_num].spt); #endif - + device_identify[6] = (ide->hdc_num / 10) + 0x30; device_identify[7] = (ide->hdc_num % 10) + 0x30; ide_log("IDE Identify: %s\n", device_identify); @@ -525,126 +443,22 @@ static void ide_next_sector(IDE *ide) static void loadhd(IDE *ide, int d, const wchar_t *fn) { - uint32_t sector_size = 512; - uint32_t zero = 0; - uint64_t signature = 0xD778A82044445459ll; - uint64_t full_size = 0; - int c; - ide->base = 0; - ide->hdi = 0; - if (ide->hdfile == NULL) + int ret = 0; + + ret = hdd_image_load(d); + + if (!ret) { - /* Try to open existing hard disk image */ - if (fn[0] == L'.') - { - ide->type = IDE_NONE; - return; - } - ide->hdfile = _wfopen(fn, L"rb+"); - if (ide->hdfile == NULL) - { - /* Failed to open existing hard disk image */ - if (errno == ENOENT) - { - /* Failed because it does not exist, - so try to create new file */ - ide->hdfile = _wfopen(fn, L"wb+"); - if (ide->hdfile == NULL) - { - ide->type = IDE_NONE; - return; - } - else - { - if (image_is_hdi(fn)) - { - full_size = hdc[d].spt * hdc[d].hpc * hdc[d].tracks * 512; - ide->base = 0x1000; - ide->hdi = 1; - fwrite(&zero, 1, 4, ide->hdfile); - fwrite(&zero, 1, 4, ide->hdfile); - fwrite(&(ide->base), 1, 4, ide->hdfile); - fwrite(&full_size, 1, 4, ide->hdfile); - fwrite(§or_size, 1, 4, ide->hdfile); - fwrite(&(hdc[d].spt), 1, 4, ide->hdfile); - fwrite(&(hdc[d].hpc), 1, 4, ide->hdfile); - fwrite(&(hdc[d].tracks), 1, 4, ide->hdfile); - for (c = 0; c < 0x3f8; c++) - { - fwrite(&zero, 1, 4, ide->hdfile); - } - } - else if (image_is_hdx(fn, 0)) - { - full_size = hdc[d].spt * hdc[d].hpc * hdc[d].tracks * 512; - ide->base = 0x28; - ide->hdi = 2; - fwrite(&signature, 1, 8, ide->hdfile); - fwrite(&full_size, 1, 8, ide->hdfile); - fwrite(§or_size, 1, 4, ide->hdfile); - fwrite(&(hdc[d].spt), 1, 4, ide->hdfile); - fwrite(&(hdc[d].hpc), 1, 4, ide->hdfile); - fwrite(&(hdc[d].tracks), 1, 4, ide->hdfile); - fwrite(&zero, 1, 4, ide->hdfile); - fwrite(&zero, 1, 4, ide->hdfile); - } - ide->hdc_num = d; - } - } - else - { - /* Failed for another reason */ - ide->type = IDE_NONE; - return; - } - } - else - { - if (image_is_hdi(fn)) - { - fseeko64(ide->hdfile, 0x8, SEEK_SET); - fread(&(ide->base), 1, 4, ide->hdfile); - fseeko64(ide->hdfile, 0x10, SEEK_SET); - fread(§or_size, 1, 4, ide->hdfile); - if (sector_size != 512) - { - /* Sector size is not 512 */ - fclose(ide->hdfile); - ide->type = IDE_NONE; - return; - } - fread(&(hdc[d].spt), 1, 4, ide->hdfile); - fread(&(hdc[d].hpc), 1, 4, ide->hdfile); - fread(&(hdc[d].tracks), 1, 4, ide->hdfile); - ide->hdi = 1; - } - else if (image_is_hdx(fn, 1)) - { - ide->base = 0x28; - fseeko64(ide->hdfile, 0x10, SEEK_SET); - fread(§or_size, 1, 4, ide->hdfile); - if (sector_size != 512) - { - /* Sector size is not 512 */ - fclose(ide->hdfile); - ide->type = IDE_NONE; - return; - } - fread(&(hdc[d].spt), 1, 4, ide->hdfile); - fread(&(hdc[d].hpc), 1, 4, ide->hdfile); - fread(&(hdc[d].tracks), 1, 4, ide->hdfile); - fread(&(hdc[d].at_spt), 1, 4, ide->hdfile); - fread(&(hdc[d].at_hpc), 1, 4, ide->hdfile); - ide->hdi = 2; - } - } + ide->type = IDE_NONE; + return; } - - ide->spt = hdc[d].spt; - ide->hpc = hdc[d].hpc; - ide->tracks = hdc[d].tracks; - ide->type = IDE_HDD; + + ide->spt = hdc[d].spt; + ide->hpc = hdc[d].hpc; + ide->tracks = hdc[d].tracks; + ide->type = IDE_HDD; ide->hdc_num = d; + ide->hdi = hdd_image_get_type(d); } void ide_set_signature(IDE *ide) @@ -771,11 +585,7 @@ void resetide(void) { ide_drives[d].channel = d; ide_drives[d].type = IDE_NONE; - if (ide_drives[d].hdfile != NULL) - { - fclose(ide_drives[d].hdfile); - ide_drives[d].hdfile = NULL; - } + hdd_image_close(ide_drives[d].hdc_num); if (ide_drive_is_cdrom(&ide_drives[d])) { cdrom[atapi_cdrom_drives[d]].status = READY_STAT | DSC_STAT; @@ -856,13 +666,6 @@ void ide_write_data(int ide_board, uint32_t val, int length) uint16_t *idebufferw = ide->buffer; uint32_t *idebufferl = (uint32_t *) ide->buffer; -#if 0 - if (ide_drive_is_cdrom(ide)) - { - ide_log("CD-ROM write data: %04X\n", val); - } -#endif - if (ide->command == WIN_PACKETCMD) { ide->pos = 0; @@ -1621,8 +1424,6 @@ int times30=0; void callbackide(int ide_board) { IDE *ide, *ide_other; - off64_t addr; - int c; int64_t snum; int cdrom_id; uint64_t full_size = 0; @@ -1760,10 +1561,8 @@ void callbackide(int ide_board) { goto id_not_found; } - addr = ide_get_sector(ide) * 512; - fseeko64(ide->hdfile, ide->base + addr, SEEK_SET); - fread(ide->buffer, 512, 1, ide->hdfile); + hdd_image_read(ide->hdc_num, ide_get_sector(ide), 1, (uint8_t *) ide->buffer); ide->pos=0; ide->atastat = DRQ_STAT | READY_STAT | DSC_STAT; @@ -1781,9 +1580,7 @@ void callbackide(int ide_board) { goto id_not_found; } - addr = ide_get_sector(ide) * 512; - fseeko64(ide->hdfile, addr, SEEK_SET); - fread(ide->buffer, 512, 1, ide->hdfile); + hdd_image_read(ide->hdc_num, ide_get_sector(ide), 1, (uint8_t *) ide->buffer); ide->pos=0; if (ide_bus_master_read) @@ -1831,9 +1628,7 @@ void callbackide(int ide_board) goto id_not_found; } - addr = ide_get_sector(ide) * 512; - fseeko64(ide->hdfile, ide->base + addr, SEEK_SET); - fread(ide->buffer, 512, 1, ide->hdfile); + hdd_image_read(ide->hdc_num, ide_get_sector(ide), 1, (uint8_t *) ide->buffer); ide->pos=0; ide->atastat = DRQ_STAT | READY_STAT | DSC_STAT; if (!ide->blockcount) @@ -1859,9 +1654,7 @@ void callbackide(int ide_board) { goto id_not_found; } - addr = ide_get_sector(ide) * 512; - fseeko64(ide->hdfile, ide->base + addr, SEEK_SET); - fwrite(ide->buffer, 512, 1, ide->hdfile); + hdd_image_write(ide->hdc_num, ide_get_sector(ide), 1, (uint8_t *) ide->buffer); ide_irq_raise(ide); ide->secount = (ide->secount - 1) & 0xff; if (ide->secount) @@ -1898,9 +1691,7 @@ void callbackide(int ide_board) else { /*DMA successful*/ - addr = ide_get_sector(ide) * 512; - fseeko64(ide->hdfile, ide->base + addr, SEEK_SET); - fwrite(ide->buffer, 512, 1, ide->hdfile); + hdd_image_write(ide->hdc_num, ide_get_sector(ide), 1, (uint8_t *) ide->buffer); ide->atastat = DRQ_STAT | READY_STAT | DSC_STAT; @@ -1931,9 +1722,7 @@ void callbackide(int ide_board) { goto id_not_found; } - addr = ide_get_sector(ide) * 512; - fseeko64(ide->hdfile, ide->base + addr, SEEK_SET); - fwrite(ide->buffer, 512, 1, ide->hdfile); + hdd_image_write(ide->hdc_num, ide_get_sector(ide), 1, (uint8_t *) ide->buffer); ide->blockcount++; if (ide->blockcount >= ide->blocksize || ide->secount == 1) { @@ -1980,13 +1769,8 @@ void callbackide(int ide_board) { goto id_not_found; } - addr = ide_get_sector(ide) * 512; - fseeko64(ide->hdfile, ide->base + addr, SEEK_SET); - memset(ide->buffer, 0, 512); - for (c=0;csecount;c++) - { - fwrite(ide->buffer, 512, 1, ide->hdfile); - } + hdd_image_zero(ide->hdc_num, ide_get_sector(ide), ide->secount); + ide->atastat = READY_STAT | DSC_STAT; ide_irq_raise(ide); @@ -2019,14 +1803,7 @@ void callbackide(int ide_board) full_size /= (ide->head+1); full_size /= ide->secount; ide->specify_success = 1; - if (ide->hdi == 2) - { - hdc[ide->hdc_num].at_hpc = ide->head+1; - hdc[ide->hdc_num].at_spt = ide->secount; - fseeko64(ide->hdfile, 0x20, SEEK_SET); - fwrite(&(hdc[ide->hdc_num].at_spt), 1, 4, ide->hdfile); - fwrite(&(hdc[ide->hdc_num].at_hpc), 1, 4, ide->hdfile); - } + hdd_image_specify(ide->hdc_num, ide->head + 1, ide->secount); ide->spt=ide->secount; ide->hpc=ide->head+1; ide->atastat = READY_STAT | DSC_STAT; diff --git a/src/ide.h b/src/ide.h index 003cbbb07..57057af13 100644 --- a/src/ide.h +++ b/src/ide.h @@ -38,7 +38,6 @@ typedef struct { int packetstatus; uint8_t asc; int reset; - FILE *hdfile; uint16_t buffer[65536]; int irqstat; int service; diff --git a/src/intel_flash.c b/src/intel_flash.c index d03e1de94..f807cd63f 100644 --- a/src/intel_flash.c +++ b/src/intel_flash.c @@ -85,17 +85,21 @@ static uint8_t flash_read(uint32_t addr, void *p) static uint16_t flash_readw(uint32_t addr, void *p) { flash_t *flash = (flash_t *)p; + uint16_t *q; addr &= 0x1ffff; if (flash->invert_high_pin) addr ^= 0x10000; - return *(uint16_t *)&(flash->array[addr]); + q = (uint16_t *)&(flash->array[addr]); + return *q; } static uint32_t flash_readl(uint32_t addr, void *p) { flash_t *flash = (flash_t *)p; + uint32_t *q; addr &= 0x1ffff; if (flash->invert_high_pin) addr ^= 0x10000; - return *(uint32_t *)&(flash->array[addr]); + q = (uint32_t *)&(flash->array[addr]); + return *q; } static void flash_write(uint32_t addr, uint8_t val, void *p) diff --git a/src/keyboard_amstrad.c b/src/keyboard_amstrad.c index 3765b43ca..f87cfd983 100644 --- a/src/keyboard_amstrad.c +++ b/src/keyboard_amstrad.c @@ -112,7 +112,7 @@ void keyboard_amstrad_write(uint16_t port, uint8_t val, void *priv) uint8_t keyboard_amstrad_read(uint16_t port, void *priv) { - uint8_t temp; + uint8_t temp = 0xff; switch (port) { case 0x60: diff --git a/src/keyboard_olim24.c b/src/keyboard_olim24.c index e031bafad..55c2f1868 100644 --- a/src/keyboard_olim24.c +++ b/src/keyboard_olim24.c @@ -45,7 +45,6 @@ static uint8_t mouse_scancodes[7]; void keyboard_olim24_poll() { keybsenddelay += (1000 * TIMER_USEC); - //pclog("poll %i\n", keyboard_olim24.wantirq); if (keyboard_olim24.wantirq) { keyboard_olim24.wantirq = 0; @@ -108,8 +107,6 @@ void keyboard_olim24_write(uint16_t port, uint8_t val, void *priv) default: pclog("Bad keyboard command complete %02X\n", keyboard_olim24.command); -// dumpregs(); -// exit(-1); } } } @@ -137,8 +134,6 @@ void keyboard_olim24_write(uint16_t port, uint8_t val, void *priv) default: pclog("Bad keyboard command %02X\n", val); -// dumpregs(); -// exit(-1); } } @@ -162,8 +157,7 @@ void keyboard_olim24_write(uint16_t port, uint8_t val, void *priv) uint8_t keyboard_olim24_read(uint16_t port, void *priv) { - uint8_t temp; -// pclog("keyboard_olim24 : read %04X ", port); + uint8_t temp = 0xff; switch (port) { case 0x60: @@ -193,10 +187,7 @@ uint8_t keyboard_olim24_read(uint16_t port, void *priv) default: pclog("\nBad olim24 keyboard read %04X\n", port); -// dumpregs(); -// exit(-1); } -// pclog("%02X\n", temp); return temp; } @@ -231,8 +222,6 @@ uint8_t mouse_olim24_poll(int x, int y, int z, int b, void *p) mouse->x += x; mouse->y += y; -// pclog("mouse_poll - %i, %i %i, %i\n", x, y, mouse->x, mouse->y); - if (((key_queue_end - key_queue_start) & 0xf) > 14) return(0xff); if ((b & 1) && !(mouse->b & 1)) @@ -342,7 +331,6 @@ mouse_t mouse_olim24 = void keyboard_olim24_init() { - //return; io_sethandler(0x0060, 0x0002, keyboard_olim24_read, NULL, NULL, keyboard_olim24_write, NULL, NULL, NULL); io_sethandler(0x0064, 0x0001, keyboard_olim24_read, NULL, NULL, keyboard_olim24_write, NULL, NULL, NULL); keyboard_olim24_reset(); diff --git a/src/mem.c b/src/mem.c index fd393e446..2f6d2bf46 100644 --- a/src/mem.c +++ b/src/mem.c @@ -700,6 +700,14 @@ int loadbios() biosmask = 0x1ffff; return 1; + case ROM_PRESIDENT: + f = romfopen(L"roms/president/BIOS.BIN", L"rb"); + if (!f) break; + fread(rom, 0x20000, 1, f); + fclose(f); + biosmask = 0x1ffff; + return 1; + case ROM_P54TP4XE: f = romfopen(L"roms/p54tp4xe/T15I0302.AWD", L"rb"); if (!f) break; @@ -716,7 +724,6 @@ int loadbios() biosmask = 0x1ffff; return 1; -#if 0 case ROM_ACERV35N: f = romfopen(L"roms/acerv35n/V35ND1S1.BIN", L"rb"); if (!f) break; @@ -724,7 +731,6 @@ int loadbios() fclose(f); biosmask = 0x1ffff; return 1; -#endif case ROM_P55VA: f = romfopen(L"roms/p55va/VA021297.BIN", L"rb"); @@ -1779,11 +1785,13 @@ uint8_t mem_read_romext(uint32_t addr, void *priv) } uint16_t mem_read_romextw(uint32_t addr, void *priv) { - return *(uint16_t *)&romext[addr & 0x7fff]; + uint16_t *p = (uint16_t *)&romext[addr & 0x7fff]; + return *p; } uint32_t mem_read_romextl(uint32_t addr, void *priv) { - return *(uint32_t *)&romext[addr & 0x7fff]; + uint32_t *p = (uint32_t *)&romext[addr & 0x7fff]; + return *p; } void mem_write_null(uint32_t addr, uint8_t val, void *p) diff --git a/src/mfm_at.c b/src/mfm_at.c index b62fbbef0..eca973a85 100644 --- a/src/mfm_at.c +++ b/src/mfm_at.c @@ -1,16 +1,7 @@ -#define _LARGEFILE_SOURCE -#define _LARGEFILE64_SOURCE -#define _GNU_SOURCE -#include #include -#include -#include -#include - -#include -#include #include "ibm.h" +#include "hdd_image.h" #include "device.h" #include "io.h" #include "pic.h" @@ -53,7 +44,8 @@ typedef struct mfm_drive_t int cfg_spt; int cfg_hpc; int current_cylinder; - FILE *hdfile; + int present; + int hdc_num; } mfm_drive_t; typedef struct mfm_t @@ -163,39 +155,21 @@ static void mfm_next_sector(mfm_t *mfm) static void loadhd(mfm_t *mfm, int c, int d, const wchar_t *fn) { mfm_drive_t *drive = &mfm->drives[c]; - - if (drive->hdfile == NULL) - { - /* Try to open existing hard disk image */ - drive->hdfile = _wfopen(fn, L"rb+"); - if (drive->hdfile == NULL) - { - /* Failed to open existing hard disk image */ - if (errno == ENOENT) - { - /* Failed because it does not exist, - so try to create new file */ - drive->hdfile = _wfopen(fn, L"wb+"); - if (drive->hdfile == NULL) - { - pclog("Cannot create file '%s': %s", - fn, strerror(errno)); - return; - } - } - else - { - /* Failed for another reason */ - pclog("Cannot open file '%s': %s", - fn, strerror(errno)); - return; - } - } - } + int ret = 0; + ret = hdd_image_load(d); + + if (!ret) + { + drive->present = 0; + return; + } + drive->spt = hdc[d].spt; drive->hpc = hdc[d].hpc; drive->tracks = hdc[d].tracks; + drive->hdc_num = d; + drive->present = 1; } @@ -233,14 +207,14 @@ void mfm_write(uint16_t port, uint8_t val, void *p) case 0x1F6: /* Drive/Head */ mfm->head = val & 0xF; mfm->drive_sel = (val & 0x10) ? 1 : 0; - if (mfm->drives[mfm->drive_sel].hdfile == NULL) - mfm->status = 0; - else + if (mfm->drives[mfm->drive_sel].present) mfm->status = STAT_READY | STAT_DSC; + else + mfm->status = 0; return; case 0x1F7: /* Command register */ - if (mfm->drives[mfm->drive_sel].hdfile == NULL) + if (!mfm->drives[mfm->drive_sel].present) fatal("Command on non-present drive\n"); mfm_irq_lower(mfm); @@ -462,7 +436,6 @@ void mfm_callback(void *p) mfm_t *mfm = (mfm_t *)p; mfm_drive_t *drive = &mfm->drives[mfm->drive_sel]; off64_t addr; - int c; mfm->callback = 0; if (mfm->reset) @@ -500,8 +473,7 @@ void mfm_callback(void *p) break; } - fseeko64(drive->hdfile, addr * 512, SEEK_SET); - fread(mfm->buffer, 512, 1, drive->hdfile); + hdd_image_read(drive->hdc_num, addr, 1, (uint8_t *) mfm->buffer); mfm->pos = 0; mfm->status = STAT_DRQ | STAT_READY | STAT_DSC; mfm_irq_raise(mfm); @@ -517,8 +489,7 @@ void mfm_callback(void *p) mfm_irq_raise(mfm); break; } - fseeko64(drive->hdfile, addr * 512, SEEK_SET); - fwrite(mfm->buffer, 512, 1, drive->hdfile); + hdd_image_write(drive->hdc_num, addr, 1, (uint8_t *) mfm->buffer); mfm_irq_raise(mfm); mfm->secount = (mfm->secount - 1) & 0xff; if (mfm->secount) @@ -552,12 +523,7 @@ void mfm_callback(void *p) mfm_irq_raise(mfm); break; } - fseeko64(drive->hdfile, addr * 512, SEEK_SET); - memset(mfm->buffer, 0, 512); - for (c = 0; c < mfm->secount; c++) - { - fwrite(mfm->buffer, 512, 1, drive->hdfile); - } + hdd_image_zero(drive->hdc_num, addr, mfm->secount); mfm->status = STAT_READY | STAT_DSC; mfm_irq_raise(mfm); update_status_bar_icon(SB_HDD | HDD_BUS_MFM, 1); @@ -624,9 +590,8 @@ void mfm_close(void *p) for (d = 0; d < 2; d++) { mfm_drive_t *drive = &mfm->drives[d]; - - if (drive->hdfile != NULL) - fclose(drive->hdfile); + + hdd_image_close(drive->hdc_num); } free(mfm); diff --git a/src/mfm_xebec.c b/src/mfm_xebec.c index b318c4de3..eb56d2ec0 100644 --- a/src/mfm_xebec.c +++ b/src/mfm_xebec.c @@ -1,17 +1,10 @@ -#define _LARGEFILE_SOURCE -#define _LARGEFILE64_SOURCE -#define _GNU_SOURCE -#include -#include -#include -#include -#include - +#include #include #include "ibm.h" #include "device.h" #include "dma.h" +#include "hdd_image.h" #include "io.h" #include "mem.h" #include "pic.h" @@ -43,7 +36,8 @@ typedef struct mfm_drive_t int cfg_hpc; int cfg_cyl; int current_cylinder; - FILE *hdfile; + int present; + int hdc_num; } mfm_drive_t; typedef struct xebec_t @@ -297,6 +291,8 @@ static void xebec_next_sector(xebec_t *xebec) static void xebec_callback(void *p) { + off64_t addr; + xebec_t *xebec = (xebec_t *)p; mfm_drive_t *drive; @@ -310,13 +306,13 @@ static void xebec_callback(void *p) switch (xebec->command[0]) { case CMD_TEST_DRIVE_READY: - if (!drive->hdfile) + if (!drive->present) xebec_error(xebec, ERR_NOT_READY); xebec_complete(xebec); break; case CMD_RECALIBRATE: - if (!drive->hdfile) + if (!drive->present) xebec_error(xebec, ERR_NOT_READY); else { @@ -357,8 +353,6 @@ static void xebec_callback(void *p) xebec->sector_count = xebec->command[4]; do { - off64_t addr; - if (xebec_get_sector(xebec, &addr)) { pclog("xebec_get_sector failed\n"); @@ -384,9 +378,6 @@ static void xebec_callback(void *p) case CMD_FORMAT_TRACK: { - off64_t addr; - int c; - xebec->cylinder = xebec->command[3] | ((xebec->command[2] & 0xc0) << 2); drive->current_cylinder = (xebec->cylinder >= drive->cfg_cyl) ? drive->cfg_cyl-1 : xebec->cylinder; xebec->head = xebec->command[1] & 0x1f; @@ -398,10 +389,8 @@ static void xebec_callback(void *p) xebec_complete(xebec); return; } - - fseeko64(drive->hdfile, addr * 512, SEEK_SET); - for (c = 0; c < 17; c++) - fwrite(xebec->sector_buf, 512, 1, drive->hdfile); + + hdd_image_zero(drive->hdc_num, addr, 17); xebec_complete(xebec); } @@ -420,8 +409,6 @@ static void xebec_callback(void *p) xebec->data_pos = 0; xebec->data_len = 512; { - off64_t addr; - if (xebec_get_sector(xebec, &addr)) { xebec_error(xebec, xebec->error); @@ -429,8 +416,7 @@ static void xebec_callback(void *p) return; } - fseeko64(drive->hdfile, addr * 512, SEEK_SET); - fread(xebec->sector_buf, 512, 1, drive->hdfile); + hdd_image_read(drive->hdc_num, addr, 1, (uint8_t *) xebec->sector_buf); update_status_bar_icon(SB_HDD | HDD_BUS_MFM, 1); } if (xebec->irq_dma_mask & DMA_ENA) @@ -474,8 +460,6 @@ static void xebec_callback(void *p) if (xebec->sector_count) { - off64_t addr; - if (xebec_get_sector(xebec, &addr)) { xebec_error(xebec, xebec->error); @@ -483,8 +467,7 @@ static void xebec_callback(void *p) return; } - fseeko64(drive->hdfile, addr * 512, SEEK_SET); - fread(xebec->sector_buf, 512, 1, drive->hdfile); + hdd_image_read(drive->hdc_num, addr, 1, (uint8_t *) xebec->sector_buf); update_status_bar_icon(SB_HDD | HDD_BUS_MFM, 1); xebec->state = STATE_SEND_DATA; @@ -559,8 +542,6 @@ static void xebec_callback(void *p) memcpy(xebec->sector_buf, xebec->data, 512); { - off64_t addr; - if (xebec_get_sector(xebec, &addr)) { xebec_error(xebec, xebec->error); @@ -568,8 +549,7 @@ static void xebec_callback(void *p) return; } - fseeko64(drive->hdfile, addr * 512, SEEK_SET); - fwrite(xebec->sector_buf, 512, 1, drive->hdfile); + hdd_image_write(drive->hdc_num, addr, 1, (uint8_t *) xebec->sector_buf); } update_status_bar_icon(SB_HDD | HDD_BUS_MFM, 1); @@ -596,7 +576,7 @@ static void xebec_callback(void *p) break; case CMD_SEEK: - if (!drive->hdfile) + if (!drive->present) xebec_error(xebec, ERR_NOT_READY); else { @@ -766,39 +746,21 @@ static void xebec_callback(void *p) static void loadhd(xebec_t *xebec, int c, int d, const wchar_t *fn) { mfm_drive_t *drive = &xebec->drives[d]; - - if (drive->hdfile == NULL) - { - /* Try to open existing hard disk image */ - drive->hdfile = _wfopen(fn, L"rb+"); - if (drive->hdfile == NULL) - { - /* Failed to open existing hard disk image */ - if (errno == ENOENT) - { - /* Failed because it does not exist, - so try to create new file */ - drive->hdfile = _wfopen(fn, L"wb+"); - if (drive->hdfile == NULL) - { - pclog("Cannot create file '%s': %s", - fn, strerror(errno)); - return; - } - } - else - { - /* Failed for another reason */ - pclog("Cannot open file '%s': %s", - fn, strerror(errno)); - return; - } - } - } + int ret = 0; + ret = hdd_image_load(d); + + if (!ret) + { + drive->present = 0; + return; + } + drive->spt = hdc[c].spt; drive->hpc = hdc[c].hpc; drive->tracks = hdc[c].tracks; + drive->hdc_num = c; + drive->present = 1; } static struct @@ -822,7 +784,7 @@ static void xebec_set_switches(xebec_t *xebec) { mfm_drive_t *drive = &xebec->drives[d]; - if (!drive->hdfile) + if (!drive->present) continue; for (c = 0; c < 4; c++) @@ -878,9 +840,8 @@ static void xebec_close(void *p) for (d = 0; d < 2; d++) { mfm_drive_t *drive = &xebec->drives[d]; - - if (drive->hdfile != NULL) - fclose(drive->hdfile); + + hdd_image_close(drive->hdc_num); } free(xebec); diff --git a/src/model.c b/src/model.c index b45b89efc..d564138c8 100644 --- a/src/model.c +++ b/src/model.c @@ -82,6 +82,9 @@ #include "sound/snd_ps1.h" #include "sound/snd_pssj.h" #include "sound/snd_sn76489.h" +#if 0 +#include "superio_detect.h" +#endif #include "tandy_eeprom.h" #include "tandy_rom.h" #if 0 @@ -120,16 +123,21 @@ extern void at_ali1429_init(void); extern void at_headland_init(void); extern void at_opti495_init(void); extern void at_batman_init(void); +#if 0 +extern void at_586mc1_init(void); +#endif extern void at_endeavor_init(void); extern void at_dtk486_init(void); extern void at_r418_init(void); extern void at_plato_init(void); extern void at_mb500n_init(void); +extern void at_president_init(void); extern void at_p54tp4xe_init(void); extern void at_ap53_init(void); extern void at_p55t2s_init(void); extern void at_acerm3a_init(void); +extern void at_acerv35n_init(void); extern void at_p55t2p4_init(void); extern void at_p55tvp4_init(void); extern void at_p55va_init(void); @@ -151,73 +159,77 @@ int romset; MODEL models[] = { - {"IBM PC", ROM_IBMPC, "ibmpc", { "", cpus_8088, "", NULL, "", NULL, "", NULL, "", NULL}, 0, 0, 64, 640, 64, 0, xt_init, NULL}, - {"IBM XT", ROM_IBMXT, "ibmxt", { "", cpus_8088, "", NULL, "", NULL, "", NULL, "", NULL}, 0, 0, 64, 640, 64, 0, xt_init, NULL}, - {"Compaq Portable", ROM_PORTABLE, "portable", { "", cpus_8088, "", NULL, "", NULL, "", NULL, "", NULL}, 0, 0, 128, 640, 128, 0, xt_init, NULL}, - {"IBM PCjr", ROM_IBMPCJR, "ibmpcjr", { "", cpus_pcjr, "", NULL, "", NULL, "", NULL, "", NULL}, 1, 0, 128, 640, 128, 0, pcjr_init, &pcjr_device}, - {"Generic XT clone", ROM_GENXT, "genxt", { "", cpus_8088, "", NULL, "", NULL, "", NULL, "", NULL}, 0, 0, 64, 640, 64, 0, xt_init, NULL}, - {"AMI XT clone", ROM_AMIXT, "amixt", { "", cpus_8088, "", NULL, "", NULL, "", NULL, "", NULL}, 0, 0, 64, 640, 64, 0, xt_init, NULL}, - {"DTK XT clone", ROM_DTKXT, "dtk", { "", cpus_8088, "", NULL, "", NULL, "", NULL, "", NULL}, 0, 0, 64, 640, 64, 0, xt_init, NULL}, - {"VTech Laser Turbo XT", ROM_LTXT, "ltxt", { "", cpus_8088, "", NULL, "", NULL, "", NULL, "", NULL}, 0, 0, 64, 1152, 64, 0, xt_laserxt_init, NULL}, - {"VTech Laser XT3", ROM_LXT3, "lxt3", { "", cpus_8088, "", NULL, "", NULL, "", NULL, "", NULL}, 0, 0, 64, 1152, 64, 0, xt_laserxt_init, NULL}, - {"Phoenix XT clone", ROM_PXXT, "pxxt", { "", cpus_8088, "", NULL, "", NULL, "", NULL, "", NULL}, 0, 0, 64, 640, 64, 0, xt_init, NULL}, - {"Juko XT clone", ROM_JUKOPC, "jukopc", { "", cpus_8088, "", NULL, "", NULL, "", NULL, "", NULL}, 0, 0, 64, 640, 64, 0, xt_init, NULL}, - {"Tandy 1000", ROM_TANDY, "tandy", { "", cpus_8088, "", NULL, "", NULL, "", NULL, "", NULL}, 1, 0, 128, 640, 128, 0, tandy1k_init, &tandy1000_device}, - {"Tandy 1000 HX", ROM_TANDY1000HX, "tandy1000hx", { "", cpus_8088, "", NULL, "", NULL, "", NULL, "", NULL}, 1, 0, 256, 640, 128, 0, tandy1k_init, &tandy1000hx_device}, - {"Tandy 1000 SL/2", ROM_TANDY1000SL2, "tandy1000sl2", { "", cpus_8086, "", NULL, "", NULL, "", NULL, "", NULL}, 1, 0, 512, 768, 128, 0, tandy1ksl2_init, NULL}, - {"Amstrad PC1512", ROM_PC1512, "pc1512", { "", cpus_pc1512, "", NULL, "", NULL, "", NULL, "", NULL}, 1, MODEL_AMSTRAD, 512, 640, 128, 63, ams_init, NULL}, - {"Sinclair PC200", ROM_PC200, "pc200", { "", cpus_8086, "", NULL, "", NULL, "", NULL, "", NULL}, 1, MODEL_AMSTRAD, 512, 640, 128, 63, ams_init, NULL}, - {"Schneider EuroPC", ROM_EUROPC, "europc", { "", cpus_europc, "", NULL, "", NULL, "", NULL, "", NULL}, 0, 0, 512, 640, 128, 0, europc_init, NULL}, - {"Olivetti M24", ROM_OLIM24, "olivetti_m24", { "", cpus_8086, "", NULL, "", NULL, "", NULL, "", NULL}, 1, MODEL_OLIM24, 128, 640, 128, 0, olim24_init, NULL}, - {"Amstrad PC1640", ROM_PC1640, "pc1640", { "", cpus_8086, "", NULL, "", NULL, "", NULL, "", NULL}, 1, MODEL_AMSTRAD, 640, 640, 0, 63, ams_init, NULL}, - {"Amstrad PC2086", ROM_PC2086, "pc2086", { "", cpus_8086, "", NULL, "", NULL, "", NULL, "", NULL}, 1, MODEL_AMSTRAD, 640, 640, 0, 63, ams_init, NULL}, - {"Amstrad PC3086", ROM_PC3086, "pc3086", { "", cpus_8086, "", NULL, "", NULL, "", NULL, "", NULL}, 1, MODEL_AMSTRAD, 640, 640, 0, 63, ams_init, NULL}, - {"IBM AT", ROM_IBMAT, "ibmat", { "", cpus_ibmat, "", NULL, "", NULL, "", NULL, "", NULL}, 0, MODEL_AT, 1, 16, 1, 63, ibm_at_init, NULL}, - {"Compaq Portable II", ROM_PORTABLEII, "portableii", { "", cpus_286, "", NULL, "", NULL, "", NULL, "", NULL}, 0, MODEL_AT, 1, 15, 1, 63, at_init, NULL}, - {"Compaq Portable III", ROM_PORTABLEIII, "portableiii", { "", cpus_286, "", NULL, "", NULL, "", NULL, "", NULL}, 0, MODEL_AT, 1, 15, 1, 63, at_init, NULL}, - {"Commodore PC 30 III", ROM_CMDPC30, "cmdpc30", { "", cpus_286, "", NULL, "", NULL, "", NULL, "", NULL}, 0, MODEL_AT | MODEL_HAS_IDE, 1, 16, 1, 127, at_ide_init, NULL}, - {"AMI 286 clone", ROM_AMI286, "ami286", { "", cpus_286, "", NULL, "", NULL, "", NULL, "", NULL}, 0, MODEL_AT | MODEL_HAS_IDE, 1, 16, 1, 127, at_neat_init, NULL}, - {"Award 286 clone", ROM_AWARD286, "award286", { "", cpus_286, "", NULL, "", NULL, "", NULL, "", NULL}, 0, MODEL_AT | MODEL_HAS_IDE, 1, 16, 1, 127, at_scat_init, NULL}, - {"Hyundai Super-286TR", ROM_SUPER286TR, "super286tr", { "", cpus_286, "", NULL, "", NULL, "", NULL, "", NULL}, 0, MODEL_AT, 1, 16, 1, 127, at_scat_init, NULL}, - {"Samsung SPC-4200P", ROM_SPC4200P, "spc4200p", { "", cpus_286, "", NULL, "", NULL, "", NULL, "", NULL}, 0, MODEL_AT, 1, 16, 1, 127, at_scat_init, NULL}, - {"IBM PS/1 model 2011", ROM_IBMPS1_2011, "ibmps1es", { "", cpus_ps1_m2011, "", NULL, "", NULL, "", NULL, "", NULL}, 1, MODEL_AT | MODEL_PS2 | MODEL_PS2_HDD, 1, 16, 1, 127, ps1_m2011_init, NULL}, - {"IBM PS/2 Model 30-286", ROM_IBMPS2_M30_286, "ibmps2_m30_286", { "", cpus_ps2_m30_286, "", NULL, "", NULL, "", NULL, "", NULL}, 0, MODEL_AT | MODEL_PS2 | MODEL_PS2_HDD, 1, 16, 1, 127, ps2_m30_286_init, NULL}, - {"IBM PS/2 Model 50", ROM_IBMPS2_M50, "ibmps2_m50", { "", cpus_ps2_m30_286, "", NULL, "", NULL, "", NULL, "", NULL}, 0, MODEL_AT | MODEL_PS2 | MODEL_PS2_HDD | MODEL_MCA, 1, 16, 1, 63, ps2_model_50_init, NULL}, - {"IBM PS/1 model 2121", ROM_IBMPS1_2121, "ibmps1_2121", { "Intel", cpus_i386SX, "AMD", cpus_Am386SX, "Cyrix", cpus_486SLC, "", NULL, "", NULL}, 1, MODEL_AT | MODEL_PS2 | MODEL_HAS_IDE, 1, 16, 1, 127, ps1_m2121_init, NULL}, - {"IBM PS/1 m.2121 + ISA", ROM_IBMPS1_2121_ISA, "ibmps1_2121_isa", { "Intel", cpus_i386DX, "AMD", cpus_Am386DX, "Cyrix", cpus_486DLC, "", NULL, "", NULL}, 0, MODEL_AT | MODEL_PS2 | MODEL_HAS_IDE, 1, 16, 1, 127, ps1_m2121_init, NULL}, - {"IBM PS/2 Model 55SX", ROM_IBMPS2_M55SX, "ibmps2_m55sx", { "Intel", cpus_i386SX, "AMD", cpus_Am386SX, "Cyrix", cpus_486SLC, "", NULL, "", NULL}, 0, MODEL_AT | MODEL_PS2 | MODEL_PS2_HDD | MODEL_MCA, 1, 8, 1, 63, ps2_model_55sx_init, NULL}, - {"Compaq Deskpro 386", ROM_DESKPRO_386, "dekspro386", { "Intel", cpus_i386DX, "AMD", cpus_Am386DX, "Cyrix", cpus_486DLC, "", NULL, "", NULL}, 0, MODEL_AT, 1, 15, 1, 63, deskpro386_init, NULL}, - {"Compaq Portable III 386", ROM_PORTABLEIII386, "portableiii386", { "Intel", cpus_i386DX, "AMD", cpus_Am386DX, "Cyrix", cpus_486DLC, "", NULL, "", NULL}, 0, MODEL_AT, 1, 15, 1, 63, at_init, NULL}, - {"DTK 386SX clone", ROM_DTK386, "dtk386", { "Intel", cpus_i386SX, "AMD", cpus_Am386SX, "Cyrix", cpus_486SLC, "", NULL, "", NULL}, 0, MODEL_AT | MODEL_HAS_IDE, 1, 16, 1, 127, at_neat_init, NULL}, - {"Amstrad MegaPC", ROM_MEGAPC, "megapc", { "Intel", cpus_i386SX, "AMD", cpus_Am386SX, "Cyrix", cpus_486SLC, "", NULL, "", NULL}, 1, MODEL_AT | MODEL_PS2 | MODEL_HAS_IDE, 1, 16, 1, 127, at_wd76c10_init, NULL}, - {"AMI 386SX clone", ROM_AMI386SX, "ami386", { "Intel", cpus_i386SX, "AMD", cpus_Am386SX, "Cyrix", cpus_486SLC, "", NULL, "", NULL}, 0, MODEL_AT | MODEL_HAS_IDE, 1, 64, 1, 127, at_headland_init, NULL}, - {"IBM PS/2 Model 80", ROM_IBMPS2_M80, "ibmps2_m80", { "Intel", cpus_i386DX, "AMD", cpus_Am386DX, "Cyrix", cpus_486DLC, "", NULL, "", NULL}, 0, MODEL_AT | MODEL_PS2 | MODEL_PS2_HDD | MODEL_MCA, 1, 12, 1, 63, ps2_model_80_init, NULL}, -/* The MegaPC manual says 386DX model of the Amstrad PC70386 exists, but Sarah Walker just *had* to remove 386DX CPU's from some boards. */ - {"Amstrad MegaPC 386DX", ROM_MEGAPCDX, "megapcdx", { "Intel", cpus_i386DX, "AMD", cpus_Am386DX, "Cyrix", cpus_486DLC, "", NULL, "", NULL}, 1, MODEL_AT | MODEL_PS2 | MODEL_HAS_IDE, 1, 16, 1, 127, at_wd76c10_init, NULL}, - {"MR 386DX clone", ROM_MR386DX_OPTI495, "mr386dx", { "Intel", cpus_i386DX, "AMD", cpus_Am386DX, "Cyrix", cpus_486DLC, "", NULL, "", NULL}, 0, MODEL_AT | MODEL_HAS_IDE, 1, 64, 1, 127, at_opti495_init, NULL}, - {"AMI 386DX clone", ROM_AMI386DX_OPTI495, "ami386dx", { "Intel", cpus_i386DX, "AMD", cpus_Am386DX, "Cyrix", cpus_486DLC, "", NULL, "", NULL}, 0, MODEL_AT | MODEL_HAS_IDE, 1, 64, 1, 127, at_opti495_init, NULL}, - {"IBM PS/1 model 2133", ROM_IBMPS1_2133, "ibmps1_2133", { "Intel", cpus_i486, "AMD", cpus_Am486, "Cyrix", cpus_Cx486, "", NULL, "", NULL}, 0, MODEL_AT | MODEL_PS2 | MODEL_HAS_IDE, 1, 64, 1, 127, ps1_m2133_init, NULL}, - {"AMI 486 clone", ROM_AMI486, "ami486", { "Intel", cpus_i486, "AMD", cpus_Am486, "Cyrix", cpus_Cx486, "", NULL, "", NULL}, 0, MODEL_AT | MODEL_HAS_IDE, 1, 64, 1, 127, at_ali1429_init, NULL}, - {"AMI WinBIOS 486", ROM_WIN486, "win486", { "Intel", cpus_i486, "AMD", cpus_Am486, "Cyrix", cpus_Cx486, "", NULL, "", NULL}, 0, MODEL_AT | MODEL_HAS_IDE, 1, 64, 1, 127, at_ali1429_init, NULL}, - {"DTK PKM-0038S E-2", ROM_DTK486, "dtk486", { "Intel", cpus_i486, "AMD", cpus_Am486, "Cyrix", cpus_Cx486, "", NULL, "", NULL}, 0, MODEL_AT | MODEL_HAS_IDE, 1, 64, 1, 127, at_dtk486_init, NULL}, - {"Rise Computer R418", ROM_R418, "r418", { "Intel", cpus_i486, "AMD", cpus_Am486, "Cyrix", cpus_Cx486, "", NULL, "", NULL}, 0, MODEL_AT | MODEL_HAS_IDE | MODEL_PCI, 1, 64, 1, 127, at_r418_init, NULL}, - {"Intel Premiere/PCI", ROM_REVENGE, "revenge", { "Intel", cpus_Pentium5V, "", NULL, "", NULL, "", NULL, "", NULL}, 0, MODEL_AT | MODEL_PS2 | MODEL_HAS_IDE | MODEL_PCI, 1, 128, 1, 127, at_batman_init, NULL}, - {"Intel Premiere/PCI II", ROM_PLATO, "plato", { "Intel", cpus_PentiumS5, "IDT", cpus_WinChip, "AMD", cpus_K5, "", NULL, "", NULL}, 0, MODEL_AT | MODEL_PS2 | MODEL_HAS_IDE | MODEL_PCI, 1, 128, 1, 127, at_plato_init, NULL}, - {"Intel Advanced/EV", ROM_ENDEAVOR, "endeavor", { "Intel", cpus_PentiumS5, "IDT", cpus_WinChip, "AMD", cpus_K5, "", NULL, "", NULL}, 0, MODEL_AT | MODEL_PS2 | MODEL_HAS_IDE | MODEL_PCI, 1, 128, 1, 127, at_endeavor_init, NULL}, - {"Intel Advanced/ZP", ROM_ZAPPA, "zappa", { "Intel", cpus_PentiumS5, "IDT", cpus_WinChip, "AMD", cpus_K5, "", NULL, "", NULL}, 0, MODEL_AT | MODEL_PS2 | MODEL_HAS_IDE | MODEL_PCI, 1, 128, 1, 127, at_endeavor_init, NULL}, - {"PC Partner MB500N", ROM_MB500N, "mb500n", { "Intel", cpus_PentiumS5, "IDT", cpus_WinChip, "AMD", cpus_K5, "", NULL, "", NULL}, 0, MODEL_AT | MODEL_PS2 | MODEL_HAS_IDE | MODEL_PCI, 1, 128, 1, 127, at_mb500n_init, NULL}, - {"Intel Advanced/ATX", ROM_THOR, "thor", { "Intel", cpus_Pentium, "IDT", cpus_WinChip, "Cyrix", cpus_6x86, "AMD", cpus_K56, "", NULL}, 0, MODEL_AT | MODEL_PS2 | MODEL_HAS_IDE | MODEL_PCI, 1, 256, 1, 127, at_endeavor_init, NULL}, - {"MR Intel Advanced/ATX", ROM_MRTHOR, "mrthor", { "Intel", cpus_Pentium, "IDT", cpus_WinChip, "Cyrix", cpus_6x86, "AMD", cpus_K56, "", NULL}, 0, MODEL_AT | MODEL_PS2 | MODEL_HAS_IDE | MODEL_PCI, 1, 256, 1, 127, at_endeavor_init, NULL}, - {"ASUS P/I-P54TP4XE", ROM_P54TP4XE, "p54tp4xe", { "Intel", cpus_PentiumS5, "IDT", cpus_WinChip, "AMD", cpus_K5, "", NULL, "", NULL}, 0, MODEL_AT | MODEL_PS2 | MODEL_HAS_IDE | MODEL_PCI, 1, 256, 1, 127, at_p54tp4xe_init, NULL}, - {"AOpen AP53", ROM_AP53, "ap53", { "Intel", cpus_Pentium, "IDT", cpus_WinChip, "Cyrix", cpus_6x86, "AMD", cpus_K56, "", NULL}, 0, MODEL_AT | MODEL_PS2 | MODEL_HAS_IDE | MODEL_PCI, 1, 256, 1, 127, at_ap53_init, NULL}, - {"ASUS P/I-P55T2S", ROM_P55T2S, "p55t2s", { "Intel", cpus_Pentium, "IDT", cpus_WinChip, "Cyrix", cpus_6x86, "AMD", cpus_K56, "", NULL}, 0, MODEL_AT | MODEL_PS2 | MODEL_HAS_IDE | MODEL_PCI, 1, 256, 1, 127, at_p55t2s_init, NULL}, - {"Acer M3a", ROM_ACERM3A, "acerm3a", { "Intel", cpus_Pentium, "IDT", cpus_WinChip, "Cyrix", cpus_6x86, "AMD", cpus_K56, "", NULL}, 0, MODEL_AT | MODEL_PS2 | MODEL_HAS_IDE | MODEL_PCI, 1, 256, 1, 127, at_acerm3a_init, NULL}, - {"ASUS P/I-P55T2P4", ROM_P55T2P4, "p55r2p4", { "Intel", cpus_Pentium, "IDT", cpus_WinChip, "Cyrix", cpus_6x86, "AMD", cpus_K56, "", NULL}, 0, MODEL_AT | MODEL_PS2 | MODEL_HAS_IDE | MODEL_PCI, 1, 256, 1, 127, at_p55t2p4_init, NULL}, - {"Epox P55-VA", ROM_P55VA, "p55va", { "Intel", cpus_Pentium, "IDT", cpus_WinChip, "Cyrix", cpus_6x86, "AMD", cpus_K56, "", NULL}, 0, MODEL_AT | MODEL_PS2 | MODEL_HAS_IDE | MODEL_PCI, 1, 256, 1, 127, at_p55va_init, NULL}, - {"ASUS P/I-P55TVP4", ROM_P55TVP4, "p55tvp4", { "Intel", cpus_Pentium, "IDT", cpus_WinChip, "Cyrix", cpus_6x86, "AMD", cpus_K56, "", NULL}, 0, MODEL_AT | MODEL_PS2 | MODEL_HAS_IDE | MODEL_PCI, 1, 256, 1, 127, at_p55tvp4_init, NULL}, - {"Tyan Titan-Pro AT", ROM_440FX, "440fx", { "Intel", cpus_PentiumPro, "", NULL, "", NULL, "", NULL, "", NULL}, 0, MODEL_AT | MODEL_PS2 | MODEL_HAS_IDE | MODEL_PCI, 1, 256, 1, 127, at_i440fx_init, NULL}, - {"Tyan Titan-Pro ATX", ROM_S1668, "tpatx", { "Intel", cpus_PentiumPro, "", NULL, "", NULL, "", NULL, "", NULL}, 0, MODEL_AT | MODEL_PS2 | MODEL_HAS_IDE | MODEL_PCI, 1, 256, 1, 127, at_s1668_init, NULL}, - {"", -1, "", {"", 0, "", 0, "", 0}, 0,0,0,0, 0} + {"IBM PC", ROM_IBMPC, "ibmpc", {{"", cpus_8088}, {"", NULL}, {"", NULL}, {"", NULL}, {"", NULL}}, 0, 0, 64, 640, 64, 0, xt_init, NULL}, + {"IBM XT", ROM_IBMXT, "ibmxt", {{"", cpus_8088}, {"", NULL}, {"", NULL}, {"", NULL}, {"", NULL}}, 0, 0, 64, 640, 64, 0, xt_init, NULL}, + {"Compaq Portable", ROM_PORTABLE, "portable", {{"", cpus_8088}, {"", NULL}, {"", NULL}, {"", NULL}, {"", NULL}}, 0, 0, 128, 640, 128, 0, xt_init, NULL}, + {"IBM PCjr", ROM_IBMPCJR, "ibmpcjr", {{"", cpus_pcjr}, {"", NULL}, {"", NULL}, {"", NULL}, {"", NULL}}, 1, 0, 128, 640, 128, 0, pcjr_init, &pcjr_device}, + {"Generic XT clone", ROM_GENXT, "genxt", {{"", cpus_8088}, {"", NULL}, {"", NULL}, {"", NULL}, {"", NULL}}, 0, 0, 64, 640, 64, 0, xt_init, NULL}, + {"AMI XT clone", ROM_AMIXT, "amixt", {{"", cpus_8088}, {"", NULL}, {"", NULL}, {"", NULL}, {"", NULL}}, 0, 0, 64, 640, 64, 0, xt_init, NULL}, + {"DTK XT clone", ROM_DTKXT, "dtk", {{"", cpus_8088}, {"", NULL}, {"", NULL}, {"", NULL}, {"", NULL}}, 0, 0, 64, 640, 64, 0, xt_init, NULL}, + {"VTech Laser Turbo XT", ROM_LTXT, "ltxt", {{"", cpus_8088}, {"", NULL}, {"", NULL}, {"", NULL}, {"", NULL}}, 0, 0, 64, 1152, 64, 0, xt_laserxt_init, NULL}, + {"VTech Laser XT3", ROM_LXT3, "lxt3", {{"", cpus_8088}, {"", NULL}, {"", NULL}, {"", NULL}, {"", NULL}}, 0, 0, 64, 1152, 64, 0, xt_laserxt_init, NULL}, + {"Phoenix XT clone", ROM_PXXT, "pxxt", {{"", cpus_8088}, {"", NULL}, {"", NULL}, {"", NULL}, {"", NULL}}, 0, 0, 64, 640, 64, 0, xt_init, NULL}, + {"Juko XT clone", ROM_JUKOPC, "jukopc", {{"", cpus_8088}, {"", NULL}, {"", NULL}, {"", NULL}, {"", NULL}}, 0, 0, 64, 640, 64, 0, xt_init, NULL}, + {"Tandy 1000", ROM_TANDY, "tandy", {{"", cpus_8088}, {"", NULL}, {"", NULL}, {"", NULL}, {"", NULL}}, 1, 0, 128, 640, 128, 0, tandy1k_init, &tandy1000_device}, + {"Tandy 1000 HX", ROM_TANDY1000HX, "tandy1000hx", {{"", cpus_8088}, {"", NULL}, {"", NULL}, {"", NULL}, {"", NULL}}, 1, 0, 256, 640, 128, 0, tandy1k_init, &tandy1000hx_device}, + {"Tandy 1000 SL/2", ROM_TANDY1000SL2, "tandy1000sl2", {{"", cpus_8086}, {"", NULL}, {"", NULL}, {"", NULL}, {"", NULL}}, 1, 0, 512, 768, 128, 0, tandy1ksl2_init, NULL}, + {"Amstrad PC1512", ROM_PC1512, "pc1512", {{"", cpus_pc1512}, {"", NULL}, {"", NULL}, {"", NULL}, {"", NULL}}, 1, MODEL_AMSTRAD, 512, 640, 128, 63, ams_init, NULL}, + {"Sinclair PC200", ROM_PC200, "pc200", {{"", cpus_8086}, {"", NULL}, {"", NULL}, {"", NULL}, {"", NULL}}, 1, MODEL_AMSTRAD, 512, 640, 128, 63, ams_init, NULL}, + {"Schneider EuroPC", ROM_EUROPC, "europc", {{"", cpus_europc}, {"", NULL}, {"", NULL}, {"", NULL}, {"", NULL}}, 0, 0, 512, 640, 128, 0, europc_init, NULL}, + {"Olivetti M24", ROM_OLIM24, "olivetti_m24", {{"", cpus_8086}, {"", NULL}, {"", NULL}, {"", NULL}, {"", NULL}}, 1, MODEL_OLIM24, 128, 640, 128, 0, olim24_init, NULL}, + {"Amstrad PC1640", ROM_PC1640, "pc1640", {{"", cpus_8086}, {"", NULL}, {"", NULL}, {"", NULL}, {"", NULL}}, 1, MODEL_AMSTRAD, 640, 640, 0, 63, ams_init, NULL}, + {"Amstrad PC2086", ROM_PC2086, "pc2086", {{"", cpus_8086}, {"", NULL}, {"", NULL}, {"", NULL}, {"", NULL}}, 1, MODEL_AMSTRAD, 640, 640, 0, 63, ams_init, NULL}, + {"Amstrad PC3086", ROM_PC3086, "pc3086", {{"", cpus_8086}, {"", NULL}, {"", NULL}, {"", NULL}, {"", NULL}}, 1, MODEL_AMSTRAD, 640, 640, 0, 63, ams_init, NULL}, + {"IBM AT", ROM_IBMAT, "ibmat", {{"", cpus_ibmat}, {"", NULL}, {"", NULL}, {"", NULL}, {"", NULL}}, 0, MODEL_AT, 1, 16, 1, 63, ibm_at_init, NULL}, + {"Compaq Portable II", ROM_PORTABLEII, "portableii", {{"", cpus_286}, {"", NULL}, {"", NULL}, {"", NULL}, {"", NULL}}, 0, MODEL_AT, 1, 15, 1, 63, at_init, NULL}, + {"Compaq Portable III", ROM_PORTABLEIII, "portableiii", {{"", cpus_286}, {"", NULL}, {"", NULL}, {"", NULL}, {"", NULL}}, 0, MODEL_AT, 1, 15, 1, 63, at_init, NULL}, + {"Commodore PC 30 III", ROM_CMDPC30, "cmdpc30", {{"", cpus_286}, {"", NULL}, {"", NULL}, {"", NULL}, {"", NULL}}, 0, MODEL_AT | MODEL_HAS_IDE, 1, 16, 1, 127, at_ide_init, NULL}, + {"AMI 286 clone", ROM_AMI286, "ami286", {{"", cpus_286}, {"", NULL}, {"", NULL}, {"", NULL}, {"", NULL}}, 0, MODEL_AT | MODEL_HAS_IDE, 1, 16, 1, 127, at_neat_init, NULL}, + {"Award 286 clone", ROM_AWARD286, "award286", {{"", cpus_286}, {"", NULL}, {"", NULL}, {"", NULL}, {"", NULL}}, 0, MODEL_AT | MODEL_HAS_IDE, 1, 16, 1, 127, at_scat_init, NULL}, + {"Hyundai Super-286TR", ROM_SUPER286TR, "super286tr", {{"", cpus_286}, {"", NULL}, {"", NULL}, {"", NULL}, {"", NULL}}, 0, MODEL_AT, 1, 16, 1, 127, at_scat_init, NULL}, + {"Samsung SPC-4200P", ROM_SPC4200P, "spc4200p", {{"", cpus_286}, {"", NULL}, {"", NULL}, {"", NULL}, {"", NULL}}, 0, MODEL_AT, 1, 16, 1, 127, at_scat_init, NULL}, + {"IBM PS/1 model 2011", ROM_IBMPS1_2011, "ibmps1es", {{"", cpus_ps1_m2011}, {"", NULL}, {"", NULL}, {"", NULL}, {"", NULL}}, 1, MODEL_AT | MODEL_PS2 | MODEL_PS2_HDD, 1, 16, 1, 127, ps1_m2011_init, NULL}, + {"IBM PS/2 Model 30-286", ROM_IBMPS2_M30_286, "ibmps2_m30_286", {{"", cpus_ps2_m30_286}, {"", NULL}, {"", NULL}, {"", NULL}, {"", NULL}}, 0, MODEL_AT | MODEL_PS2 | MODEL_PS2_HDD, 1, 16, 1, 127, ps2_m30_286_init, NULL}, + {"IBM PS/2 Model 50", ROM_IBMPS2_M50, "ibmps2_m50", {{"", cpus_ps2_m30_286}, {"", NULL}, {"", NULL}, {"", NULL}, {"", NULL}}, 0, MODEL_AT | MODEL_PS2 | MODEL_PS2_HDD | MODEL_MCA, 1, 16, 1, 63, ps2_model_50_init, NULL}, + {"IBM PS/1 model 2121", ROM_IBMPS1_2121, "ibmps1_2121", {{"Intel", cpus_i386SX}, {"AMD", cpus_Am386SX}, {"Cyrix", cpus_486SLC}, {"", NULL}, {"", NULL}}, 1, MODEL_AT | MODEL_PS2 | MODEL_HAS_IDE, 1, 16, 1, 127, ps1_m2121_init, NULL}, + {"IBM PS/1 m.2121 + ISA", ROM_IBMPS1_2121_ISA, "ibmps1_2121_isa", {{"Intel", cpus_i386SX}, {"AMD", cpus_Am386SX}, {"Cyrix", cpus_486SLC}, {"", NULL}, {"", NULL}}, 0, MODEL_AT | MODEL_PS2 | MODEL_HAS_IDE, 1, 16, 1, 127, ps1_m2121_init, NULL}, + {"IBM PS/2 Model 55SX", ROM_IBMPS2_M55SX, "ibmps2_m55sx", {{"Intel", cpus_i386SX}, {"AMD", cpus_Am386SX}, {"Cyrix", cpus_486SLC}, {"", NULL}, {"", NULL}}, 0, MODEL_AT | MODEL_PS2 | MODEL_PS2_HDD | MODEL_MCA, 1, 8, 1, 63, ps2_model_55sx_init, NULL}, + {"DTK 386SX clone", ROM_DTK386, "dtk386", {{"Intel", cpus_i386SX}, {"AMD", cpus_Am386SX}, {"Cyrix", cpus_486SLC}, {"", NULL}, {"", NULL}}, 0, MODEL_AT | MODEL_HAS_IDE, 1, 16, 1, 127, at_neat_init, NULL}, + {"Amstrad MegaPC", ROM_MEGAPC, "megapc", {{"Intel", cpus_i386SX}, {"AMD", cpus_Am386SX}, {"Cyrix", cpus_486SLC}, {"", NULL}, {"", NULL}}, 1, MODEL_AT | MODEL_PS2 | MODEL_HAS_IDE, 1, 16, 1, 127, at_wd76c10_init, NULL}, + {"AMI 386SX clone", ROM_AMI386SX, "ami386", {{"Intel", cpus_i386SX}, {"AMD", cpus_Am386SX}, {"Cyrix", cpus_486SLC}, {"", NULL}, {"", NULL}}, 0, MODEL_AT | MODEL_HAS_IDE, 1, 64, 1, 127, at_headland_init, NULL}, + {"Compaq Deskpro 386", ROM_DESKPRO_386, "dekspro386", {{"Intel", cpus_i386DX}, {"AMD", cpus_Am386DX}, {"Cyrix", cpus_486DLC}, {"", NULL}, {"", NULL}}, 0, MODEL_AT, 1, 15, 1, 63, deskpro386_init, NULL}, + {"Compaq Portable III 386", ROM_PORTABLEIII386, "portableiii386", {{"Intel", cpus_i386DX}, {"AMD", cpus_Am386DX}, {"Cyrix", cpus_486DLC}, {"", NULL}, {"", NULL}}, 0, MODEL_AT, 1, 15, 1, 63, at_init, NULL}, + {"IBM PS/2 Model 80", ROM_IBMPS2_M80, "ibmps2_m80", {{"Intel", cpus_i386DX}, {"AMD", cpus_Am386DX}, {"Cyrix", cpus_486DLC}, {"", NULL}, {"", NULL}}, 0, MODEL_AT | MODEL_PS2 | MODEL_PS2_HDD | MODEL_MCA, 1, 12, 1, 63, ps2_model_80_init, NULL}, + {"Amstrad MegaPC 386DX", ROM_MEGAPCDX, "megapcdx", {{"Intel", cpus_i386DX}, {"AMD", cpus_Am386DX}, {"Cyrix", cpus_486DLC}, {"", NULL}, {"", NULL}}, 1, MODEL_AT | MODEL_PS2 | MODEL_HAS_IDE, 1, 16, 1, 127, at_wd76c10_init, NULL}, + {"MR 386DX clone", ROM_MR386DX_OPTI495, "mr386dx", {{"Intel", cpus_i386DX}, {"AMD", cpus_Am386DX}, {"Cyrix", cpus_486DLC}, {"", NULL}, {"", NULL}}, 0, MODEL_AT | MODEL_HAS_IDE, 1, 64, 1, 127, at_opti495_init, NULL}, + {"AMI 386DX clone", ROM_AMI386DX_OPTI495, "ami386dx", {{"Intel", cpus_i386DX}, {"AMD", cpus_Am386DX}, {"Cyrix", cpus_486DLC}, {"", NULL}, {"", NULL}}, 0, MODEL_AT | MODEL_HAS_IDE, 1, 64, 1, 127, at_opti495_init, NULL}, + {"IBM PS/1 model 2133", ROM_IBMPS1_2133, "ibmps1_2133", {{"Intel", cpus_i486}, {"AMD", cpus_Am486}, {"Cyrix", cpus_Cx486}, {"", NULL}, {"", NULL}}, 0, MODEL_AT | MODEL_PS2 | MODEL_HAS_IDE, 1, 64, 1, 127, ps1_m2133_init, NULL}, + {"AMI 486 clone", ROM_AMI486, "ami486", {{"Intel", cpus_i486}, {"AMD", cpus_Am486}, {"Cyrix", cpus_Cx486}, {"", NULL}, {"", NULL}}, 0, MODEL_AT | MODEL_HAS_IDE, 1, 64, 1, 127, at_ali1429_init, NULL}, + {"AMI WinBIOS 486", ROM_WIN486, "win486", {{"Intel", cpus_i486}, {"AMD", cpus_Am486}, {"Cyrix", cpus_Cx486}, {"", NULL}, {"", NULL}}, 0, MODEL_AT | MODEL_HAS_IDE, 1, 64, 1, 127, at_ali1429_init, NULL}, + {"DTK PKM-0038S E-2", ROM_DTK486, "dtk486", {{"Intel", cpus_i486}, {"AMD", cpus_Am486}, {"Cyrix", cpus_Cx486}, {"", NULL}, {"", NULL}}, 0, MODEL_AT | MODEL_HAS_IDE, 1, 64, 1, 127, at_dtk486_init, NULL}, + {"Rise Computer R418", ROM_R418, "r418", {{"Intel", cpus_i486}, {"AMD", cpus_Am486}, {"Cyrix", cpus_Cx486}, {"", NULL}, {"", NULL}}, 0, MODEL_AT | MODEL_HAS_IDE | MODEL_PCI, 1, 64, 1, 127, at_r418_init, NULL}, + {"Intel Premiere/PCI", ROM_REVENGE, "revenge", {{"Intel", cpus_Pentium5V}, {"", NULL}, {"", NULL}, {"", NULL}, {"", NULL}}, 0, MODEL_AT | MODEL_PS2 | MODEL_HAS_IDE | MODEL_PCI, 1, 128, 1, 127, at_batman_init, NULL}, +#if 0 + {"Micro Star 586MC1", ROM_586MC1, "586mc1", {{"Intel", cpus_Pentium5V50}, {"", NULL}, {"", NULL}, {"", NULL}, {"", NULL}}, 0, MODEL_AT | MODEL_PS2 | MODEL_HAS_IDE | MODEL_PCI, 1, 128, 1, 127, at_586mc1_init, NULL}, +#endif + {"Intel Premiere/PCI II", ROM_PLATO, "plato", {{ "Intel", cpus_PentiumS5}, {"IDT", cpus_WinChip}, {"AMD", cpus_K5}, {"", NULL}, {"", NULL}}, 0, MODEL_AT | MODEL_PS2 | MODEL_HAS_IDE | MODEL_PCI, 1, 128, 1, 127, at_plato_init, NULL}, + {"Intel Advanced/EV", ROM_ENDEAVOR, "endeavor", {{ "Intel", cpus_PentiumS5}, {"IDT", cpus_WinChip}, {"AMD", cpus_K5}, {"", NULL}, {"", NULL}}, 0, MODEL_AT | MODEL_PS2 | MODEL_HAS_IDE | MODEL_PCI, 1, 128, 1, 127, at_endeavor_init, NULL}, + {"Intel Advanced/ZP", ROM_ZAPPA, "zappa", {{ "Intel", cpus_PentiumS5}, {"IDT", cpus_WinChip}, {"AMD", cpus_K5}, {"", NULL}, {"", NULL}}, 0, MODEL_AT | MODEL_PS2 | MODEL_HAS_IDE | MODEL_PCI, 1, 128, 1, 127, at_endeavor_init, NULL}, + {"PC Partner MB500N", ROM_MB500N, "mb500n", {{ "Intel", cpus_PentiumS5}, {"IDT", cpus_WinChip}, {"AMD", cpus_K5}, {"", NULL}, {"", NULL}}, 0, MODEL_AT | MODEL_PS2 | MODEL_HAS_IDE | MODEL_PCI, 1, 128, 1, 127, at_mb500n_init, NULL}, + {"President Award 430FX PCI", ROM_PRESIDENT, "president", {{ "Intel", cpus_PentiumS5}, {"IDT", cpus_WinChip}, {"AMD", cpus_K5}, {"", NULL}, {"", NULL}}, 0, MODEL_AT | MODEL_HAS_IDE | MODEL_PCI, 1, 128, 1, 127, at_president_init, NULL}, + {"ASUS P/I-P54TP4XE", ROM_P54TP4XE, "p54tp4xe", {{ "Intel", cpus_PentiumS5}, {"IDT", cpus_WinChip}, {"AMD", cpus_K5}, {"", NULL}, {"", NULL}}, 0, MODEL_AT | MODEL_PS2 | MODEL_HAS_IDE | MODEL_PCI, 1, 256, 1, 127, at_p54tp4xe_init, NULL}, + {"Intel Advanced/ATX", ROM_THOR, "thor", {{"Intel", cpus_Pentium}, {"IDT", cpus_WinChip}, {"AMD", cpus_K56}, {"Cyrix", cpus_6x86},{"", NULL}}, 0, MODEL_AT | MODEL_PS2 | MODEL_HAS_IDE | MODEL_PCI, 1, 256, 1, 127, at_endeavor_init, NULL}, + {"MR Intel Advanced/ATX", ROM_MRTHOR, "mrthor", {{"Intel", cpus_Pentium}, {"IDT", cpus_WinChip}, {"AMD", cpus_K56}, {"Cyrix", cpus_6x86},{"", NULL}}, 0, MODEL_AT | MODEL_PS2 | MODEL_HAS_IDE | MODEL_PCI, 1, 256, 1, 127, at_endeavor_init, NULL}, + {"AOpen AP53", ROM_AP53, "ap53", {{"Intel", cpus_Pentium}, {"IDT", cpus_WinChip}, {"AMD", cpus_K56}, {"Cyrix", cpus_6x86},{"", NULL}}, 0, MODEL_AT | MODEL_PS2 | MODEL_HAS_IDE | MODEL_PCI, 1, 256, 1, 127, at_ap53_init, NULL}, + {"ASUS P/I-P55T2S", ROM_P55T2S, "p55t2s", {{"Intel", cpus_Pentium}, {"IDT", cpus_WinChip}, {"AMD", cpus_K56}, {"Cyrix", cpus_6x86},{"", NULL}}, 0, MODEL_AT | MODEL_PS2 | MODEL_HAS_IDE | MODEL_PCI, 1, 256, 1, 127, at_p55t2s_init, NULL}, + {"Acer M3a", ROM_ACERM3A, "acerm3a", {{"Intel", cpus_Pentium}, {"IDT", cpus_WinChip}, {"AMD", cpus_K56}, {"Cyrix", cpus_6x86},{"", NULL}}, 0, MODEL_AT | MODEL_PS2 | MODEL_HAS_IDE | MODEL_PCI, 1, 256, 1, 127, at_acerm3a_init, NULL}, + {"Acer V35n", ROM_ACERV35N, "acerv35n", {{"Intel", cpus_Pentium}, {"IDT", cpus_WinChip}, {"AMD", cpus_K56}, {"Cyrix", cpus_6x86},{"", NULL}}, 0, MODEL_AT | MODEL_PS2 | MODEL_HAS_IDE | MODEL_PCI, 1, 256, 1, 127, at_acerv35n_init, NULL}, + {"ASUS P/I-P55T2P4", ROM_P55T2P4, "p55r2p4", {{"Intel", cpus_Pentium}, {"IDT", cpus_WinChip}, {"AMD", cpus_K56}, {"Cyrix", cpus_6x86},{"", NULL}}, 0, MODEL_AT | MODEL_PS2 | MODEL_HAS_IDE | MODEL_PCI, 1, 256, 1, 127, at_p55t2p4_init, NULL}, + {"Epox P55-VA", ROM_P55VA, "p55va", {{"Intel", cpus_Pentium}, {"IDT", cpus_WinChip}, {"AMD", cpus_K56}, {"Cyrix", cpus_6x86},{"", NULL}}, 0, MODEL_AT | MODEL_PS2 | MODEL_HAS_IDE | MODEL_PCI, 1, 256, 1, 127, at_p55va_init, NULL}, + {"ASUS P/I-P55TVP4", ROM_P55TVP4, "p55tvp4", {{"Intel", cpus_Pentium}, {"IDT", cpus_WinChip}, {"AMD", cpus_K56}, {"Cyrix", cpus_6x86},{"", NULL}}, 0, MODEL_AT | MODEL_PS2 | MODEL_HAS_IDE | MODEL_PCI, 1, 256, 1, 127, at_p55tvp4_init, NULL}, + {"Tyan Titan-Pro AT", ROM_440FX, "440fx", {{"Intel", cpus_PentiumPro}, {"", NULL}, {"", NULL}, {"", NULL}, {"", NULL}}, 0, MODEL_AT | MODEL_PS2 | MODEL_HAS_IDE | MODEL_PCI, 1, 256, 1, 127, at_i440fx_init, NULL}, + {"Tyan Titan-Pro ATX", ROM_S1668, "tpatx", {{"Intel", cpus_PentiumPro}, {"", NULL}, {"", NULL}, {"", NULL}, {"", NULL}}, 0, MODEL_AT | MODEL_PS2 | MODEL_HAS_IDE | MODEL_PCI, 1, 256, 1, 127, at_s1668_init, NULL}, + {"", -1, "", {{"", 0}, {"", 0}, {"", 0}}, 0,0,0,0, 0} }; @@ -646,7 +658,7 @@ void at_premiere_common_init(void) pci_slot(0xc); pci_slot(0xe); pci_slot(0x6); - sio_init(2, 0xc, 0xe, 0x6, 0); + sio_init(1, 0xc, 0xe, 0x6, 0); fdc37c665_init(); intel_batman_init(); device_add(&intel_flash_bxt_ami_device); @@ -668,7 +680,7 @@ void at_586mc1_init(void) pci_slot(0xc); pci_slot(0xe); pci_slot(0x6); - sio_init(2, 0xc, 0xe, 0x6, 0); + sio_init(1, 0xc, 0xe, 0x6, 0); device_add(&intel_flash_bxt_device); secondary_ide_check(); } @@ -714,6 +726,24 @@ void at_mb500n_init(void) device_add(&intel_flash_bxt_device); } +void at_president_init(void) +{ + at_ide_init(); + memregs_init(); + pci_init(PCI_CONFIG_TYPE_1); + pci_slot(8); + pci_slot(9); + pci_slot(10); + pci_slot(11); + i430fx_init(); + piix_init(7, 8, 9, 10, 11); +#if 0 + superio_detect_init(); +#endif + w83877f_init(); + device_add(&intel_flash_bxt_device); +} + void at_p54tp4xe_init(void) { at_ide_init(); @@ -774,30 +804,28 @@ void at_acerm3a_init(void) pci_slot(0xe); pci_slot(0xf); i430hx_init(); - piix_init(7, 0xc, 0xd, 0xe, 0xf); + piix3_init(7, 0xc, 0xd, 0xe, 0xf); fdc37c932fr_init(); acerm3a_io_init(); device_add(&intel_flash_bxb_device); } -#if 0 void at_acerv35n_init(void) { at_ide_init(); memregs_init(); powermate_memregs_init(); pci_init(PCI_CONFIG_TYPE_1); - pci_slot(0xc); - pci_slot(0xd); - pci_slot(0xe); - pci_slot(0xf); + pci_slot(0x11); + pci_slot(0x12); + pci_slot(0x13); + pci_slot(0x14); i430hx_init(); - piix_init(7, 0xc, 0xd, 0xe, 0xf); + piix3_init(7, 0x11, 0x12, 0x13, 0x14); fdc37c932fr_init(); acerm3a_io_init(); device_add(&intel_flash_bxb_device); } -#endif void at_p55t2p4_init(void) { diff --git a/src/mouse_bus.c b/src/mouse_bus.c index 32063bfb0..b8cec9f82 100644 --- a/src/mouse_bus.c +++ b/src/mouse_bus.c @@ -380,7 +380,7 @@ static uint8_t bm_read(uint16_t port, void *priv) { mouse_bus_t *ms = (mouse_bus_t *)priv; - uint8_t r; + uint8_t r = 0xff; if (ms->flags & MOUSE_LOGITECH) r = lt_read(ms, port - ms->port); diff --git a/src/pc.c b/src/pc.c index 8ced5b20b..45016bf4a 100644 --- a/src/pc.c +++ b/src/pc.c @@ -8,7 +8,7 @@ * * Emulation core dispatcher. * - * Version: @(#)pc.c 1.0.3 2017/06/03 + * Version: @(#)pc.c 1.0.4 2017/06/15 * * Authors: Sarah Walker, * Miran Grca, @@ -73,10 +73,11 @@ #include "video/video.h" #include "video/vid_voodoo.h" #include "amstrad.h" -#include "win.h" -#include "win_language.h" +#include "plat_ui.h" #ifdef WALTJE +# define UNICODE # include "plat_dir.h" +# undef UNICODE #endif @@ -187,7 +188,7 @@ void fatal(const char *format, ...) { *newline = 0; } - msgbox_fatal(ghwnd, msg); + plat_msgbox_fatal(msg); #endif dumppic(); dumpregs(1); @@ -288,12 +289,15 @@ void initpc(int argc, wchar_t *argv[]) wchar_t *p; wchar_t *config_file = NULL; int c; - FILE *ff; get_executable_name(pcempath, 511); pclog("executable_name = %ws\n", pcempath); p=get_filename_w(pcempath); *p=L'\0'; pclog("path = %ws\n", pcempath); +#ifdef WALTJE + DIR *dir; + struct direct *dp; +#endif for (c = 1; c < argc; c++) { @@ -324,9 +328,6 @@ void initpc(int argc, wchar_t *argv[]) { /* some (undocumented) test function here.. */ #ifdef WALTJE - DIR *dir; - struct direct *dp; - dir = opendirw(pcempath); if (dir != NULL) { printf("Directory '%ws':\n", pcempath); @@ -577,8 +578,8 @@ int serial_fifo_read, serial_fifo_write; int emu_fps = 0; -static WCHAR wmodel[2048]; -static WCHAR wcpu[2048]; +static wchar_t wmodel[2048]; +static wchar_t wcpu[2048]; void runpc(void) { @@ -659,7 +660,7 @@ void runpc(void) win_title_update=0; mbstowcs(wmodel, model_getname(), strlen(model_getname()) + 1); mbstowcs(wcpu, models[model].cpu[cpu_manufacturer].cpus[cpu].name, strlen(models[model].cpu[cpu_manufacturer].cpus[cpu].name) + 1); - _swprintf(s, L"%s v%s - %i%% - %s - %s - %s", EMU_NAME_W, EMU_VERSION_W, fps, wmodel, wcpu, (!mousecapture) ? win_language_get_string_from_id(2077) : ((mouse_get_type(mouse_type) & MOUSE_TYPE_3BUTTON) ? win_language_get_string_from_id(2078) : win_language_get_string_from_id(2079))); + _swprintf(s, L"%s v%s - %i%% - %s - %s - %s", EMU_NAME_W, EMU_VERSION_W, fps, wmodel, wcpu, (!mousecapture) ? plat_get_string_from_id(IDS_2077) : ((mouse_get_type(mouse_type) & MOUSE_TYPE_3BUTTON) ? plat_get_string_from_id(IDS_2078) : plat_get_string_from_id(IDS_2079))); set_window_title(s); } done++; diff --git a/src/pit.c b/src/pit.c index 53169d27f..144630d5f 100644 --- a/src/pit.c +++ b/src/pit.c @@ -436,7 +436,7 @@ uint8_t pit_read(uint16_t addr, void *p) { PIT *pit = (PIT *)p; int t; - uint8_t temp; + uint8_t temp = 0xff; cycles -= (int)PITCONST; switch (addr&3) { diff --git a/src/ps1.c b/src/ps1.c index 97b319e75..0e7d5148c 100644 --- a/src/ps1.c +++ b/src/ps1.c @@ -295,13 +295,8 @@ void ps1mb_m2121_init() MEM_MAPPING_EXTERNAL); ps1_190 = 0; - lpt1_remove(); - lpt2_remove(); lpt1_init(0x3bc); - - serial_remove(1); - serial_remove(2); - + mem_remap_top_384k(); } @@ -315,12 +310,7 @@ void ps1mb_m2133_init() ps1_190 = 0; - lpt1_remove(); - lpt2_remove(); lpt1_init(0x3bc); - - serial_remove(1); - serial_remove(2); - + mem_remap_top_384k(); } diff --git a/src/ps2.c b/src/ps2.c index 0f1e1a964..1f91591d1 100644 --- a/src/ps2.c +++ b/src/ps2.c @@ -126,13 +126,8 @@ void ps2board_init() io_sethandler(0x0324, 0x0001, ps2_read, NULL, NULL, ps2_write, NULL, NULL, NULL); ps2_190 = 0; - - lpt1_remove(); - lpt2_remove(); + lpt1_init(0x3bc); - serial_remove(1); - serial_remove(2); - memset(&ps2_hd, 0, sizeof(ps2_hd)); } diff --git a/src/ps2_mca.c b/src/ps2_mca.c index 5af537b6e..1a31e07d5 100644 --- a/src/ps2_mca.c +++ b/src/ps2_mca.c @@ -552,12 +552,7 @@ static void ps2_mca_board_common_init() ps2.setup = 0xff; - lpt1_remove(); - lpt2_remove(); lpt1_init(0x3bc); - - serial_remove(1); - serial_remove(2); } void ps2_mca_board_model_50_init() @@ -701,7 +696,7 @@ void ps2_mca_board_model_80_type2_init() mem_remap_top_256k(); ps2.split_addr = mem_size * 1024; - mca_init(8); + mca_init(24); ps2.planar_read = model_80_read; ps2.planar_write = model_80_write; @@ -746,7 +741,7 @@ void ps2_mca_board_model_80_type2_init() if (mem_size > 4096) { /* Only 4 MB supported on planar, create a memory expansion card for the rest */ - mem_mapping_set_addr(&ram_high_mapping, 0x100000, 0x300000); + mem_mapping_set_addr(&ram_high_mapping, 0x100000, 0x800000); ps2.mem_pos_regs[0] = 0xff; ps2.mem_pos_regs[1] = 0xfc; diff --git a/src/scsi_aha154x.c b/src/scsi_aha154x.c index f37838cf1..83d32d55d 100644 --- a/src/scsi_aha154x.c +++ b/src/scsi_aha154x.c @@ -949,15 +949,6 @@ aha_reset(aha_t *dev) } -static void -aha_softreset(void) -{ - if (ResetDev != NULL) { - aha_reset(ResetDev); - } -} - - static void aha_reset_ctrl(aha_t *dev, uint8_t Reset) { @@ -1483,8 +1474,8 @@ aha_0x01: break; case 0x04: - dev->DataBuf[0] = dev->aha.bid; - dev->DataBuf[1] = 0x30; + dev->DataBuf[0] = (dev->chip != CHIP_AHA1640) ? dev->aha.bid : 0x42; + dev->DataBuf[1] = (dev->chip != CHIP_AHA1640) ? 0x30 : 0x42; dev->DataBuf[2] = dev->aha.fwh; dev->DataBuf[3] = dev->aha.fwl; dev->DataReplyLeft = 4; @@ -1796,12 +1787,12 @@ aha_disk_cmd(aha_t *dev) pclog("SCSI Cdb[%i]=%i\n", i, req->CmdBlock.common.Cdb[i]); } - memset(temp_cdb, 0, shdc[hdc_id].cdb_len); - if (req->CmdBlock.common.CdbLength <= shdc[hdc_id].cdb_len) { + memset(temp_cdb, 0, 12); + if (req->CmdBlock.common.CdbLength <= 12) { memcpy(temp_cdb, req->CmdBlock.common.Cdb, req->CmdBlock.common.CdbLength); } else { - memcpy(temp_cdb, req->CmdBlock.common.Cdb, shdc[hdc_id].cdb_len); + memcpy(temp_cdb, req->CmdBlock.common.Cdb, 12); } /* @@ -2147,7 +2138,38 @@ uint8_t aha_mca_read(int port, void *p) return dev->pos_regs[port & 7]; } -static uint16_t aha_mca_addr[6] = {0x130, 0x134, 0x230, 0x234, 0x330, 0x334}; +uint16_t aha_mca_get_port(uint8_t pos_port) +{ + uint16_t addr = 0; + switch (pos_port & 0xC7) + { + case 0x01: + addr = 0x130; + break; + + case 0x02: + addr = 0x230; + break; + + case 0x03: + addr = 0x330; + break; + + case 0x41: + addr = 0x134; + break; + + case 0x42: + addr = 0x234; + break; + + case 0x43: + addr = 0x334; + break; + } + + return addr; +} void aha_mca_write(int port, uint8_t val, void *p) { @@ -2157,18 +2179,21 @@ void aha_mca_write(int port, uint8_t val, void *p) if (port < 0x102) return; - addr = aha_mca_addr[dev->pos_regs[4] & 6]; - io_removehandler(addr, 0x0004, aha_read, aha_readw, NULL, aha_write, aha_writew, NULL, dev); - + addr = aha_mca_get_port(dev->pos_regs[3]); + io_removehandler(addr, 0x0004, aha_read, aha_readw, NULL, aha_write, aha_writew, NULL, dev); + dev->pos_regs[port & 7] = val; if (dev->pos_regs[2] & 1) { + addr = aha_mca_get_port(dev->pos_regs[3]); io_sethandler(addr, 0x0004, aha_read, aha_readw, NULL, aha_write, aha_writew, NULL, dev); } + + dev->Irq = (dev->pos_regs[4] & 0x7) + 8; + dev->DmaChannel = dev->pos_regs[5] & 0xf; } - void aha_device_reset(void *p) { @@ -2222,14 +2247,6 @@ aha_init(int chip, int has_bios) } } - if (dev->chip == CHIP_AHA1640) - { - pclog("Aha1640 initialized\n"); - mca_add(aha_mca_read, aha_mca_write, dev); - dev->pos_regs[0] = 0x1F; - dev->pos_regs[1] = 0x0F; - } - timer_add(aha_reset_poll, &ResetCB, &ResetCB, dev); timer_add(aha_cmd_cb, &AHA_Callback, &AHA_Callback, dev); @@ -2262,7 +2279,46 @@ aha_154xCF_init(void) static void * aha_1640_init(void) { - return(aha_init(CHIP_AHA1640, 1)); + aha_t *dev; + int i = 0; + int j = 0; + + dev = malloc(sizeof(aha_t)); + memset(dev, 0x00, sizeof(aha_t)); + + ResetDev = dev; + dev->chip = CHIP_AHA1640; + + pclog("Aha1640 initialized\n"); + mca_add(aha_mca_read, aha_mca_write, dev); + dev->pos_regs[0] = 0x1F; + dev->pos_regs[1] = 0x0F; + + pclog("Building SCSI hard disk map...\n"); + build_scsi_hd_map(); + pclog("Building SCSI CD-ROM map...\n"); + build_scsi_cdrom_map(); + + for (i=0; i<16; i++) { + for (j=0; j<8; j++) { + if (scsi_hard_disks[i][j] != 0xff) { + SCSIDevices[i][j].LunType = SCSI_DISK; + } + else if (find_cdrom_for_scsi_id(i, j) != 0xff) { + SCSIDevices[i][j].LunType = SCSI_CDROM; + } + else { + SCSIDevices[i][j].LunType = SCSI_NONE; + } + } + } + + timer_add(aha_reset_poll, &ResetCB, &ResetCB, dev); + timer_add(aha_cmd_cb, &AHA_Callback, &AHA_Callback, dev); + + aha_reset_ctrl(dev, CTRL_HRST); + + return(dev); } @@ -2373,78 +2429,6 @@ static device_config_t aha_154XCF_config[] = { } }; -static device_config_t aha_1640_config[] = { - { - "base", "Address", CONFIG_HEX16, "", 0x330, - { - { - "0x330", 0x330 - }, - { - "0x334", 0x334 - }, - { - "0x230", 0x230 - }, - { - "0x234", 0x234 - }, - { - "0x130", 0x130 - }, - { - "0x134", 0x134 - }, - { - "" - } - }, - }, - { - "irq", "IRQ", CONFIG_SELECTION, "", 10, - { - { - "IRQ 10", 10 - }, - { - "IRQ 11", 11 - }, - { - "IRQ 12", 12 - }, - { - "IRQ 14", 14 - }, - { - "IRQ 15", 15 - }, - { - "" - } - }, - }, - { - "dma", "DMA channel", CONFIG_SELECTION, "", 6, - { - { - "DMA 5", 5 - }, - { - "DMA 6", 6 - }, - { - "DMA 7", 7 - }, - { - "" - } - }, - }, - { - "", "", -1 - } -}; - device_t aha1540b_device = { "Adaptec AHA-1540B", 0, @@ -2477,6 +2461,5 @@ device_t aha1640_device = { NULL, NULL, NULL, - NULL, - aha_1640_config + NULL }; \ No newline at end of file diff --git a/src/scsi_buslogic.c b/src/scsi_buslogic.c index 1b4c8794d..26dbdc8fa 100644 --- a/src/scsi_buslogic.c +++ b/src/scsi_buslogic.c @@ -623,15 +623,6 @@ BuslogicReset(Buslogic_t *bl) } -static void -BuslogicSoftReset(void) -{ - if (BuslogicResetDevice != NULL) { - BuslogicReset(BuslogicResetDevice); - } -} - - static void BuslogicResetControl(Buslogic_t *bl, uint8_t Reset) { @@ -1685,12 +1676,12 @@ BuslogicHDCommand(Buslogic_t *bl) pclog("SCSI Cdb[%i]=%i\n", i, req->CmdBlock.common.Cdb[i]); } - memset(temp_cdb, 0, shdc[hdc_id].cdb_len); - if (req->CmdBlock.common.CdbLength <= shdc[hdc_id].cdb_len) { + memset(temp_cdb, 0, 12); + if (req->CmdBlock.common.CdbLength <= 12) { memcpy(temp_cdb, req->CmdBlock.common.Cdb, req->CmdBlock.common.CdbLength); } else { - memcpy(temp_cdb, req->CmdBlock.common.Cdb, shdc[hdc_id].cdb_len); + memcpy(temp_cdb, req->CmdBlock.common.Cdb, 12); } /* diff --git a/src/scsi_disk.c b/src/scsi_disk.c index 69726cf0b..340ffd6b3 100644 --- a/src/scsi_disk.c +++ b/src/scsi_disk.c @@ -6,26 +6,19 @@ * * Emulation of SCSI fixed and removable disks. * - * Version: @(#)scsi_disk.c 1.0.1 2017/06/03 + * Version: @(#)scsi_disk.c 1.0.2 2017/06/16 * * Author: Miran Grca, * Copyright 2017-2017 Miran Grca. */ -#define _LARGEFILE_SOURCE -#define _LARGEFILE64_SOURCE -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include +#include #include -#include +#include #include "86box.h" #include "cdrom.h" #include "ibm.h" +#include "hdd_image.h" #include "ide.h" #include "piix.h" #include "scsi.h" @@ -213,278 +206,28 @@ void scsi_disk_insert(uint8_t id) shdc[id].unit_attention = (hdc[id].bus == HDD_BUS_SCSI_REMOVABLE) ? 1 : 0; } -static char empty_sector[512]; -static char *empty_sector_1mb; - void scsi_loadhd(int scsi_id, int scsi_lun, int id) { - uint32_t sector_size = 512; - uint32_t zero = 0; - uint64_t signature = 0xD778A82044445459ll; - uint64_t full_size = 0; - uint64_t spt = 0, hpc = 0, tracks = 0; - int c; - uint64_t i = 0, s = 0, t = 0; - wchar_t *fn = hdc[id].fn; + int ret = 0; - memset(empty_sector, 0, sizeof(empty_sector)); + ret = hdd_image_load(id); - shdc[id].base = 0; - - if (shdf[id] != NULL) + if (!ret) { - fclose(shdf[id]); - shdf[id] = NULL; - } - - /* Try to open existing hard disk image */ - if (fn[0] == '.') - { - scsi_hd_log("File name starts with .\n"); - memset(hdc[id].fn, 0, sizeof(hdc[id].fn)); if (hdc[id].bus != HDD_BUS_SCSI_REMOVABLE) { scsi_hard_disks[scsi_id][scsi_lun] = 0xff; } - else - { - shdc[id].cdb_len = 12; - } - return; - } - shdf[id] = _wfopen(fn, L"rb+"); - if (shdf[id] == NULL) - { - /* Failed to open existing hard disk image */ - if (errno == ENOENT) - { - /* Failed because it does not exist, - so try to create new file */ - if (hdc[id].wp) - { - scsi_hd_log("A write-protected image must exist\n"); - goto scsi_hd_load_error; - } - - shdf[id] = _wfopen(fn, L"wb+"); - if (shdf[id] == NULL) - { -scsi_hd_load_error: - scsi_hd_log("Unable to open image\n"); - memset(hdc[id].fn, 0, sizeof(hdc[id].fn)); - if (hdc[id].bus != HDD_BUS_SCSI_REMOVABLE) - { - scsi_hard_disks[scsi_id][scsi_lun] = 0xff; - } - else - { - shdc[id].cdb_len = 12; - } - return; - } - else - { - memset(&(shdc[id]), 0, sizeof(scsi_hard_disk_t)); - if (image_is_hdi(fn)) - { - full_size = hdc[id].spt * hdc[id].hpc * hdc[id].tracks * 512; - shdc[id].base = 0x1000; - fwrite(&zero, 1, 4, shdf[id]); - fwrite(&zero, 1, 4, shdf[id]); - fwrite(&(shdc[id].base), 1, 4, shdf[id]); - fwrite(&full_size, 1, 4, shdf[id]); - fwrite(§or_size, 1, 4, shdf[id]); - fwrite(&(hdc[id].spt), 1, 4, shdf[id]); - fwrite(&(hdc[id].hpc), 1, 4, shdf[id]); - fwrite(&(hdc[id].tracks), 1, 4, shdf[id]); - for (c = 0; c < 0x3f8; c++) - { - fwrite(&zero, 1, 4, shdf[id]); - } - } - else if (image_is_hdx(fn, 0)) - { - full_size = hdc[id].spt * hdc[id].hpc * hdc[id].tracks * 512; - shdc[id].base = 0x28; - fwrite(&signature, 1, 8, shdf[id]); - fwrite(&full_size, 1, 8, shdf[id]); - fwrite(§or_size, 1, 4, shdf[id]); - fwrite(&(hdc[id].spt), 1, 4, shdf[id]); - fwrite(&(hdc[id].hpc), 1, 4, shdf[id]); - fwrite(&(hdc[id].tracks), 1, 4, shdf[id]); - fwrite(&zero, 1, 4, shdf[id]); - fwrite(&zero, 1, 4, shdf[id]); - } - shdc[id].last_sector = 0; - shdc[id].cdb_len = 12; - } - - scsi_disk_insert(id); - - s = full_size = hdc[id].spt * hdc[id].hpc * hdc[id].tracks * 512; - - goto prepare_new_hard_disk; - } - else - { - /* Failed for another reason */ - scsi_hd_log("Failed for another reason\n"); - if (hdc[id].bus != HDD_BUS_SCSI_REMOVABLE) - { - scsi_hard_disks[scsi_id][scsi_lun] = 0xff; - } - else - { - memset(hdc[id].fn, 0, sizeof(hdc[id].fn)); - shdc[id].cdb_len = 12; - } - return; - } } else { - memset(&(shdc[id]), 0, sizeof(scsi_hard_disk_t)); - if (image_is_hdi(fn)) - { - fseeko64(shdf[id], 0x8, SEEK_SET); - fread(&(shdc[id].base), 1, 4, shdf[id]); - fseeko64(shdf[id], 0xC, SEEK_SET); - full_size = 0; - fread(&full_size, 1, 4, shdf[id]); - fseeko64(shdf[id], 0x10, SEEK_SET); - fread(§or_size, 1, 4, shdf[id]); - if (sector_size != 512) - { - /* Sector size is not 512 */ - scsi_hd_log("HDI: Sector size is not 512\n"); - fclose(shdf[id]); - if (hdc[id].bus != HDD_BUS_SCSI_REMOVABLE) - { - scsi_hard_disks[scsi_id][scsi_lun] = 0xff; - } - else - { - memset(hdc[id].fn, 0, sizeof(hdc[id].fn)); - shdc[id].cdb_len = 12; - } - return; - } - fread(&spt, 1, 4, shdf[id]); - fread(&hpc, 1, 4, shdf[id]); - fread(&tracks, 1, 4, shdf[id]); - if (hdc[id].bus == HDD_BUS_SCSI_REMOVABLE) - { - if ((spt != hdc[id].spt) || (hpc != hdc[id].hpc) || (tracks != hdc[id].tracks)) - { - fclose(shdf[id]); - shdf[id] = NULL; - goto scsi_hd_load_error; - } - } - hdc[id].spt = spt; - hdc[id].hpc = hpc; - hdc[id].tracks = tracks; - } - else if (image_is_hdx(fn, 1)) - { - shdc[id].base = 0x28; - fseeko64(shdf[id], 8, SEEK_SET); - fread(&full_size, 1, 8, shdf[id]); - fseeko64(shdf[id], 0x10, SEEK_SET); - fread(§or_size, 1, 4, shdf[id]); - if (sector_size != 512) - { - /* Sector size is not 512 */ - scsi_hd_log("HDX: Sector size is not 512\n"); - fclose(shdf[id]); - if (hdc[id].bus != HDD_BUS_SCSI_REMOVABLE) - { - scsi_hard_disks[scsi_id][scsi_lun] = 0xff; - } - else - { - memset(hdc[id].fn, 0, sizeof(hdc[id].fn)); - shdc[id].cdb_len = 12; - } - return; - } - fread(&spt, 1, 4, shdf[id]); - fread(&hpc, 1, 4, shdf[id]); - fread(&tracks, 1, 4, shdf[id]); - if (hdc[id].bus == HDD_BUS_SCSI_REMOVABLE) - { - if ((spt != hdc[id].spt) || (hpc != hdc[id].hpc) || (tracks != hdc[id].tracks)) - { - fclose(shdf[id]); - shdf[id] = NULL; - goto scsi_hd_load_error; - } - } - hdc[id].spt = spt; - hdc[id].hpc = hpc; - hdc[id].tracks = tracks; - fread(&(hdc[id].at_spt), 1, 4, shdf[id]); - fread(&(hdc[id].at_hpc), 1, 4, shdf[id]); - } - else - { - full_size = hdc[id].spt * hdc[id].hpc * hdc[id].tracks * 512; - } - shdc[id].cdb_len = 12; scsi_disk_insert(id); } - - fseeko64(shdf[id], 0, SEEK_END); - if (ftello64(shdf[id]) < (full_size + shdc[id].base)) - { - s = (full_size + shdc[id].base) - ftello64(shdf[id]); -prepare_new_hard_disk: - s >>= 9; - t = (s >> 11) << 11; - s -= t; - t >>= 11; - - empty_sector_1mb = (char *) malloc(1048576); - memset(empty_sector_1mb, 0, 1048576); - - if (s > 0) - { - for (i = 0; i < s; i++) - { - fwrite(empty_sector, 1, 512, shdf[id]); - } - } - - if (t > 0) - { - for (i = 0; i < t; i++) - { - fwrite(empty_sector_1mb, 1, 1045876, shdf[id]); - } - } - - free(empty_sector_1mb); - } - - shdc[id].last_sector = (uint32_t) (full_size >> 9) - 1; - -#if 0 - fclose(shdf[id]); -#endif } void scsi_reloadhd(int id) { - uint32_t sector_size = 512; - uint32_t zero = 0; - uint64_t signature = 0xD778A82044445459ll; - uint64_t full_size = 0; - uint64_t spt = 0, hpc = 0, tracks = 0; - int c; - uint64_t i = 0, s = 0, t = 0; - wchar_t *fn = hdc[id].fn; - - memset(empty_sector, 0, sizeof(empty_sector)); + int ret = 0; if(hdc[id].prev_fn == NULL) { @@ -496,232 +239,17 @@ void scsi_reloadhd(int id) memset(hdc[id].prev_fn, 0, sizeof(hdc[id].prev_fn)); } - shdc[id].base = 0; + ret = hdd_image_load(id); - if (shdf[id] != NULL) + if (ret) { - fclose(shdf[id]); - shdf[id] = NULL; - } - - /* Try to open existing hard disk image */ - if (fn[0] == '.') - { - scsi_hd_log("File name starts with .\n"); - memset(hdc[id].fn, 0, sizeof(hdc[id].fn)); - shdc[id].cdb_len = 12; - return; - } - shdf[id] = _wfopen(fn, L"rb+"); - if (shdf[id] == NULL) - { - /* Failed to open existing hard disk image */ - if (errno == ENOENT) - { - /* Failed because it does not exist, - so try to create new file */ - if (hdc[id].wp) - { - scsi_hd_log("A write-protected image must exist\n"); - goto scsi_hd_reload_error; - } - - shdf[id] = _wfopen(fn, L"wb+"); - if (shdf[id] == NULL) - { -scsi_hd_reload_error: - scsi_hd_log("Unable to open image\n"); - memset(hdc[id].fn, 0, sizeof(hdc[id].fn)); - shdc[id].cdb_len = 12; - return; - } - else - { - memset(&(shdc[id]), 0, sizeof(scsi_hard_disk_t)); - if (image_is_hdi(fn)) - { - full_size = hdc[id].spt * hdc[id].hpc * hdc[id].tracks * 512; - shdc[id].base = 0x1000; - fwrite(&zero, 1, 4, shdf[id]); - fwrite(&zero, 1, 4, shdf[id]); - fwrite(&(shdc[id].base), 1, 4, shdf[id]); - fwrite(&full_size, 1, 4, shdf[id]); - fwrite(§or_size, 1, 4, shdf[id]); - fwrite(&(hdc[id].spt), 1, 4, shdf[id]); - fwrite(&(hdc[id].hpc), 1, 4, shdf[id]); - fwrite(&(hdc[id].tracks), 1, 4, shdf[id]); - for (c = 0; c < 0x3f8; c++) - { - fwrite(&zero, 1, 4, shdf[id]); - } - } - else if (image_is_hdx(fn, 0)) - { - full_size = hdc[id].spt * hdc[id].hpc * hdc[id].tracks * 512; - shdc[id].base = 0x28; - fwrite(&signature, 1, 8, shdf[id]); - fwrite(&full_size, 1, 8, shdf[id]); - fwrite(§or_size, 1, 4, shdf[id]); - fwrite(&(hdc[id].spt), 1, 4, shdf[id]); - fwrite(&(hdc[id].hpc), 1, 4, shdf[id]); - fwrite(&(hdc[id].tracks), 1, 4, shdf[id]); - fwrite(&zero, 1, 4, shdf[id]); - fwrite(&zero, 1, 4, shdf[id]); - } - shdc[id].last_sector = 0; - shdc[id].cdb_len = 12; - } - - scsi_disk_insert(id); - - s = full_size = hdc[id].spt * hdc[id].hpc * hdc[id].tracks * 512; - - goto reload_prepare_new_hard_disk; - } - else - { - /* Failed for another reason */ - scsi_hd_log("Failed for another reason\n"); - memset(hdc[id].fn, 0, sizeof(hdc[id].fn)); - shdc[id].cdb_len = 12; - return; - } - } - else - { - memset(&(shdc[id]), 0, sizeof(scsi_hard_disk_t)); - if (image_is_hdi(fn)) - { - fseeko64(shdf[id], 0x8, SEEK_SET); - fread(&(shdc[id].base), 1, 4, shdf[id]); - fseeko64(shdf[id], 0xC, SEEK_SET); - full_size = 0; - fread(&full_size, 1, 4, shdf[id]); - fseeko64(shdf[id], 0x10, SEEK_SET); - fread(§or_size, 1, 4, shdf[id]); - if (sector_size != 512) - { - /* Sector size is not 512 */ - scsi_hd_log("HDI: Sector size is not 512\n"); - fclose(shdf[id]); - memset(hdc[id].fn, 0, sizeof(hdc[id].fn)); - shdc[id].cdb_len = 12; - return; - } - fread(&spt, 1, 4, shdf[id]); - fread(&hpc, 1, 4, shdf[id]); - fread(&tracks, 1, 4, shdf[id]); - if ((spt != hdc[id].spt) || (hpc != hdc[id].hpc) || (tracks != hdc[id].tracks)) - { - fclose(shdf[id]); - shdf[id] = NULL; - goto scsi_hd_reload_error; - } - hdc[id].spt = spt; - hdc[id].hpc = hpc; - hdc[id].tracks = tracks; - } - else if (image_is_hdx(fn, 1)) - { - shdc[id].base = 0x28; - fseeko64(shdf[id], 8, SEEK_SET); - fread(&full_size, 1, 8, shdf[id]); - fseeko64(shdf[id], 0x10, SEEK_SET); - fread(§or_size, 1, 4, shdf[id]); - if (sector_size != 512) - { - /* Sector size is not 512 */ - scsi_hd_log("HDX: Sector size is not 512\n"); - fclose(shdf[id]); - memset(hdc[id].fn, 0, sizeof(hdc[id].fn)); - shdc[id].cdb_len = 12; - return; - } - fread(&spt, 1, 4, shdf[id]); - fread(&hpc, 1, 4, shdf[id]); - fread(&tracks, 1, 4, shdf[id]); - if ((spt != hdc[id].spt) || (hpc != hdc[id].hpc) || (tracks != hdc[id].tracks)) - { - fclose(shdf[id]); - shdf[id] = NULL; - goto scsi_hd_reload_error; - } - hdc[id].spt = spt; - hdc[id].hpc = hpc; - hdc[id].tracks = tracks; - fread(&(hdc[id].at_spt), 1, 4, shdf[id]); - fread(&(hdc[id].at_hpc), 1, 4, shdf[id]); - } - else - { - full_size = hdc[id].spt * hdc[id].hpc * hdc[id].tracks * 512; - } - shdc[id].cdb_len = 12; scsi_disk_insert(id); } - - fseeko64(shdf[id], 0, SEEK_END); - if (ftello64(shdf[id]) < (full_size + shdc[id].base)) - { - s = (full_size + shdc[id].base) - ftello64(shdf[id]); -reload_prepare_new_hard_disk: - s >>= 9; - t = (s >> 11) << 11; - s -= t; - t >>= 11; - - empty_sector_1mb = (char *) malloc(1048576); - memset(empty_sector_1mb, 0, 1048576); - - if (s > 0) - { - for (i = 0; i < s; i++) - { - fwrite(empty_sector, 1, 512, shdf[id]); - } - } - - if (t > 0) - { - for (i = 0; i < t; i++) - { - fwrite(empty_sector_1mb, 1, 1045876, shdf[id]); - } - } - - free(empty_sector_1mb); - } - - shdc[id].last_sector = (uint32_t) (full_size >> 9) - 1; - -#if 0 - fclose(shdf[id]); -#endif } void scsi_unloadhd(int scsi_id, int scsi_lun, int id) { - if (wcslen(hdc[id].fn) == 0) - { - return; - } - - if (shdf[id] != NULL) - { - fclose(shdf[id]); - shdf[id] = NULL; - } - - shdc[id].last_sector = -1; - - memset(hdc[id].prev_fn, 0, sizeof(hdc[id].prev_fn)); - wcscpy(hdc[id].prev_fn, hdc[id].fn); - - memset(hdc[id].fn, 0, sizeof(hdc[id].fn)); - - shdc[id].cdb_len = 12; - - fclose(shdf[id]); + hdd_image_unload(id, 1); } void build_scsi_hd_map() @@ -746,10 +274,6 @@ void build_scsi_hd_map() { scsi_loadhd(i, j, scsi_hard_disks[i][j]); } - else - { - shdc[scsi_hard_disks[i][j]].cdb_len = 12; - } } } } @@ -759,7 +283,7 @@ int scsi_hd_read_capacity(uint8_t id, uint8_t *cdb, uint8_t *buffer, uint32_t *l { int size = 0; - size = shdc[id].last_sector; + size = hdd_image_get_last_sector(id); memset(buffer, 0, 8); buffer[0] = (size >> 24) & 0xff; buffer[1] = (size >> 16) & 0xff; @@ -771,16 +295,6 @@ int scsi_hd_read_capacity(uint8_t id, uint8_t *cdb, uint8_t *buffer, uint32_t *l return 1; } -void scsi_hd_set_cdb_len(int id, int cdb_len) -{ - shdc[id].cdb_len = cdb_len; -} - -void scsi_hd_reset_cdb_len(int id) -{ - shdc[id].cdb_len = 12; -} - void scsi_hd_update_request_length(uint8_t id, int len, int block_len) { /* For media access commands, make sure the requested DRQ length matches the block length. */ @@ -1080,7 +594,7 @@ int scsi_hd_pre_execution_check(uint8_t id, uint8_t *cdb) static void scsi_hd_seek(uint8_t id, uint32_t pos) { /* scsi_hd_log("SCSI HD %i: Seek %08X\n", id, pos); */ - shdc[id].seek_pos = pos; + hdd_image_seek(id, pos); } static void scsi_hd_rezero(uint8_t id) @@ -1179,14 +693,16 @@ void scsi_hd_command(uint8_t id, uint8_t *cdb) unsigned size_idx; unsigned preamble_len; uint32_t alloc_length; - uint64_t pos64; char device_identify[9] = { '8', '6', 'B', '_', 'H', 'D', '0', '0', 0 }; char device_identify_ex[15] = { '8', '6', 'B', '_', 'H', 'D', '0', '0', ' ', 'v', '1', '.', '0', '0', 0 }; - char *tempbuffer; + uint8_t *tempbuffer; + uint32_t last_sector = 0; #if 0 int CdbLength; #endif + last_sector = hdd_image_get_last_sector(id); + shdc[id].status &= ~ERR_STAT; shdc[id].packet_len = 0; @@ -1210,7 +726,7 @@ void scsi_hd_command(uint8_t id, uint8_t *cdb) shdc[id].data_pos = 0; - memcpy(shdc[id].current_cdb, cdb, shdc[id].cdb_len); + memcpy(shdc[id].current_cdb, cdb, 12); if (cdb[0] != 0) { @@ -1218,7 +734,7 @@ void scsi_hd_command(uint8_t id, uint8_t *cdb) scsi_hd_log("SCSI HD %i: Request length: %04X\n", id, shdc[id].request_length); #if 0 - for (CdbLength = 1; CdbLength < shdc[id].cdb_len; CdbLength++) + for (CdbLength = 1; CdbLength < 12; CdbLength++) { scsi_hd_log("SCSI HD %i: CDB[%d] = 0x%02X\n", id, CdbLength, cdb[CdbLength]); } @@ -1284,7 +800,7 @@ void scsi_hd_command(uint8_t id, uint8_t *cdb) break; } - if ((shdc[id].sector_pos > shdc[id].last_sector) || ((shdc[id].sector_pos + shdc[id].sector_len - 1) > shdc[id].last_sector)) + if ((shdc[id].sector_pos > last_sector) || ((shdc[id].sector_pos + shdc[id].sector_len - 1) > last_sector)) { scsi_hd_lba_out_of_range(id); return; @@ -1301,27 +817,18 @@ void scsi_hd_command(uint8_t id, uint8_t *cdb) max_len = shdc[id].sector_len; shdc[id].requested_blocks = max_len; - pos64 = (uint64_t) shdc[id].sector_pos; - alloc_length = shdc[id].packet_len = max_len << 9; if ((shdc[id].requested_blocks > 0) && (SCSIDevices[hdc[id].scsi_id][hdc[id].scsi_lun].InitLength > 0)) { -#if 0 - shdf[id] = _wfopen(hdc[id].fn, L"rb+"); -#endif - fseeko64(shdf[id], shdc[id].base + (pos64 << 9), SEEK_SET); if (alloc_length > SCSIDevices[hdc[id].scsi_id][hdc[id].scsi_lun].InitLength) { - fread(hdbufferb, 1, SCSIDevices[hdc[id].scsi_id][hdc[id].scsi_lun].InitLength, shdf[id]); + hdd_image_read(id, shdc[id].sector_pos, SCSIDevices[hdc[id].scsi_id][hdc[id].scsi_lun].InitLength >> 9, hdbufferb); } else { - fread(hdbufferb, 1, alloc_length, shdf[id]); + hdd_image_read(id, shdc[id].sector_pos, max_len, hdbufferb); } -#if 0 - fclose(shdf[id]); -#endif } if (shdc[id].requested_blocks > 1) @@ -1369,7 +876,7 @@ void scsi_hd_command(uint8_t id, uint8_t *cdb) break; } - if ((shdc[id].sector_pos > shdc[id].last_sector) || ((shdc[id].sector_pos + shdc[id].sector_len - 1) > shdc[id].last_sector)) + if ((shdc[id].sector_pos > last_sector) || ((shdc[id].sector_pos + shdc[id].sector_len - 1) > last_sector)) { scsi_hd_lba_out_of_range(id); return; @@ -1386,27 +893,18 @@ void scsi_hd_command(uint8_t id, uint8_t *cdb) max_len = shdc[id].sector_len; shdc[id].requested_blocks = max_len; - pos64 = (uint64_t) shdc[id].sector_pos; - alloc_length = shdc[id].packet_len = max_len << 9; if ((shdc[id].requested_blocks > 0) && (SCSIDevices[hdc[id].scsi_id][hdc[id].scsi_lun].InitLength > 0)) { -#if 0 - shdf[id] = _wfopen(hdc[id].fn, L"rb+"); -#endif - fseeko64(shdf[id], shdc[id].base + (pos64 << 9), SEEK_SET); if (alloc_length > SCSIDevices[hdc[id].scsi_id][hdc[id].scsi_lun].InitLength) { - fwrite(hdbufferb, 1, SCSIDevices[hdc[id].scsi_id][hdc[id].scsi_lun].InitLength, shdf[id]); + hdd_image_write(id, shdc[id].sector_pos, SCSIDevices[hdc[id].scsi_id][hdc[id].scsi_lun].InitLength >> 9, hdbufferb); } else { - fwrite(hdbufferb, 1, alloc_length, shdf[id]); + hdd_image_write(id, shdc[id].sector_pos, max_len, hdbufferb); } -#if 0 - fclose(shdf[id]); -#endif } if (shdc[id].requested_blocks > 1) diff --git a/src/scsi_disk.h b/src/scsi_disk.h index 95fdd9316..db3ea9848 100644 --- a/src/scsi_disk.h +++ b/src/scsi_disk.h @@ -36,14 +36,10 @@ typedef struct { uint8_t error; uint32_t sector_pos; uint32_t sector_len; - uint32_t last_sector; uint32_t seek_pos; int data_pos; int old_len; - int cdb_len_setting; - int cdb_len; int request_pos; - uint64_t base; uint8_t hd_cdb[16]; } scsi_hard_disk_t; #pragma pack(pop) diff --git a/src/serial.c b/src/serial.c index 035e443f2..ae33dc16d 100644 --- a/src/serial.c +++ b/src/serial.c @@ -116,7 +116,7 @@ enum { #define MCR_OUT1 (0x04) /* 8250 */ #define MCR_OUT2 (0x08) /* 8250, INTEN on IBM-PC */ #define MCR_LMS (0x10) -#define MCR_AUTOFLOW (0x20) /* 16750 +#define MCR_AUTOFLOW (0x20) /* 16750 */ /* LSR register bits. */ #define LSR_DR (0x01) @@ -144,6 +144,7 @@ static SERIAL ports[NUM_SERIAL]; /* serial port data */ int serial_do_log; +#if 0 static void serial_log(int lvl, const char *fmt, ...) { @@ -158,6 +159,7 @@ serial_log(int lvl, const char *fmt, ...) } #endif } +#endif static void diff --git a/src/sio.c b/src/sio.c index 96d2ef375..03389a0ed 100644 --- a/src/sio.c +++ b/src/sio.c @@ -36,8 +36,8 @@ void sio_write(int func, int addr, uint8_t val, void *priv) if (func > 0) return; - if (addr >= 0x0f && addr < 0x4c) - return; + if (addr >= 0x0f && addr < 0x4c) + return; switch (addr) { diff --git a/src/superio_detect.c b/src/superio_detect.c new file mode 100644 index 000000000..dbedca3cd --- /dev/null +++ b/src/superio_detect.c @@ -0,0 +1,52 @@ +/* + SMSC SMC FDC37C665 Super I/O Chip + Used by Batman's Revenge +*/ + +#include "ibm.h" + +#include "io.h" +#include "disc.h" +#include "fdd.h" +#include "fdc.h" +#include "superio_detect.h" + +static int fdc37c665_locked; +static int fdc37c665_curreg = 0; +static uint8_t detect_regs[2]; +static uint8_t tries; + +void superio_detect_write(uint16_t port, uint8_t val, void *priv) +{ + uint8_t index = (port & 1) ? 0 : 1; + uint8_t valxor = 0; + int temp; + pclog("superio_detect_write : port=%04x = %02X\n", port, val); + + detect_regs[port & 1] = val; + return; +} + +uint8_t superio_detect_read(uint16_t port, void *priv) +{ + pclog("superio_detect_read : port=%04x = %02X\n", port, detect_regs[port & 1]); + + return detect_regs[port & 1]; +} + +void superio_detect_init() +{ + fdc_remove(); + fdc_add_for_superio(); + + io_sethandler(0x24, 0x0002, superio_detect_read, NULL, NULL, superio_detect_write, NULL, NULL, NULL); + io_sethandler(0x26, 0x0002, superio_detect_read, NULL, NULL, superio_detect_write, NULL, NULL, NULL); + io_sethandler(0x2e, 0x0002, superio_detect_read, NULL, NULL, superio_detect_write, NULL, NULL, NULL); + io_sethandler(0x44, 0x0002, superio_detect_read, NULL, NULL, superio_detect_write, NULL, NULL, NULL); + io_sethandler(0x46, 0x0002, superio_detect_read, NULL, NULL, superio_detect_write, NULL, NULL, NULL); + io_sethandler(0x4e, 0x0002, superio_detect_read, NULL, NULL, superio_detect_write, NULL, NULL, NULL); + io_sethandler(0x108, 0x0002, superio_detect_read, NULL, NULL, superio_detect_write, NULL, NULL, NULL); + io_sethandler(0x250, 0x0002, superio_detect_read, NULL, NULL, superio_detect_write, NULL, NULL, NULL); + io_sethandler(0x370, 0x0002, superio_detect_read, NULL, NULL, superio_detect_write, NULL, NULL, NULL); + io_sethandler(0x3f0, 0x0002, superio_detect_read, NULL, NULL, superio_detect_write, NULL, NULL, NULL); +} diff --git a/src/superio_detect.h b/src/superio_detect.h new file mode 100644 index 000000000..542fafac5 --- /dev/null +++ b/src/superio_detect.h @@ -0,0 +1 @@ +extern void superio_detect_init(); diff --git a/src/tandy_eeprom.c b/src/tandy_eeprom.c index 8d1a9eff2..0a5751d90 100644 --- a/src/tandy_eeprom.c +++ b/src/tandy_eeprom.c @@ -118,7 +118,7 @@ int tandy_eeprom_read() void *tandy_eeprom_init() { tandy_eeprom_t *eeprom = malloc(sizeof(tandy_eeprom_t)); - FILE *f; + FILE *f = NULL; memset(eeprom, 0, sizeof(tandy_eeprom_t)); @@ -148,7 +148,7 @@ void *tandy_eeprom_init() void tandy_eeprom_close(void *p) { tandy_eeprom_t *eeprom = (tandy_eeprom_t *)p; - FILE *f; + FILE *f = NULL; switch (eeprom->romset) { diff --git a/src/w83877f.c b/src/w83877f.c index 6a6dd0552..f9fc3c6ec 100644 --- a/src/w83877f.c +++ b/src/w83877f.c @@ -216,6 +216,7 @@ static void w83877f_remap() winbond_port = (HEFRAS ? 0x3f0 : 0x250); winbond_key_times = HEFRAS + 1; winbond_key = (HEFRAS ? 0x86 : 0x88) | HEFERE; + pclog("W83877F: Remapped to port %04X, key %02X\n", winbond_port, winbond_key); } static uint8_t is_in_array(uint16_t *port_array, uint8_t max, uint16_t port) @@ -282,6 +283,24 @@ static uint16_t make_port(uint8_t reg) return p; } +void w83877f_serial_handler(int id) +{ + int reg_mask = (id - 1) ? 0x10 : 0x20; + int reg_id = (id - 1) ? 0x24 : 0x25; + int irq_mask = (id - 1) ? 0xF : 0xF0; + + /* pclog("Registers (%i): %02X %02X %02X\n", id, w83877f_regs[4], w83877f_regs[reg_id], w83877f_regs[0x28]); */ + + if ((w83877f_regs[4] & reg_mask) || !(w83877f_regs[reg_id] & 0xc0)) + { + serial_remove(id); + } + else + { + serial_setup(id, make_port(reg_id), w83877f_regs[0x28] & irq_mask); + } +} + void w83877f_write(uint16_t port, uint8_t val, void *priv) { uint8_t index = (port & 1) ? 0 : 1; @@ -353,16 +372,11 @@ process_value: case 4: if (valxor & 0x10) { - serial_remove(2); - if (!(w83877f_regs[2] & 0x10)) serial_setup(2, make_port(0x25), w83877f_regs[0x28] & 0xF); + w83877f_serial_handler(2); } if (valxor & 0x20) { - serial_remove(1); - if (!(w83877f_regs[4] & 0x20)) - { - serial_setup(1, make_port(0x24), (w83877f_regs[0x28] & 0xF0) >> 8); - } + w83877f_serial_handler(1); } if (valxor & 0x80) { @@ -418,16 +432,13 @@ process_value: case 0x24: if (valxor & 0xfe) { - if (!(w83877f_regs[4] & 0x20)) - { - serial_setup(1, make_port(0x24), (w83877f_regs[0x28] & 0xF0) >> 8); - } + w83877f_serial_handler(1); } break; case 0x25: if (valxor & 0xfe) { - if (!(w83877f_regs[2] & 0x10)) serial_setup(2, make_port(0x25), w83877f_regs[0x28] & 0xF); + w83877f_serial_handler(2); } break; case 0x28: @@ -486,7 +497,7 @@ void w83877f_reset(void) w83877f_regs[0xA] = 0x1F; w83877f_regs[0xC] = 0x28; w83877f_regs[0xD] = 0xA3; - w83877f_regs[0x16] = 5; + w83877f_regs[0x16] = (romset == ROM_PRESIDENT) ? 4 : 5; w83877f_regs[0x1E] = 0x81; w83877f_regs[0x20] = (0x3f0 >> 2) & 0xfc; w83877f_regs[0x21] = (0x1f0 >> 2) & 0xfc;