/[dynamips]/trunk/ppc32_exec.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/ppc32_exec.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

upstream/dynamips-0.2.7-RC1/ppc32_exec.c revision 7 by dpavlin, Sat Oct 6 16:23:47 2007 UTC upstream/dynamips-0.2.8-RC1/ppc32_exec.c revision 11 by dpavlin, Sat Oct 6 16:33:40 2007 UTC
# Line 51  void ppc32_exec_create_ilt(void) Line 51  void ppc32_exec_create_ilt(void)
51     for(i=0,count=0;ppc32_exec_tags[i].exec;i++)     for(i=0,count=0;ppc32_exec_tags[i].exec;i++)
52        count++;        count++;
53    
54     ilt = ilt_create(count+1,     ilt = ilt_create("ppc32e",count,
55                      (ilt_get_insn_cbk_t)ppc32_exec_get_insn,                      (ilt_get_insn_cbk_t)ppc32_exec_get_insn,
56                      (ilt_check_cbk_t)ppc32_exec_chk_lo,                      (ilt_check_cbk_t)ppc32_exec_chk_lo,
57                      (ilt_check_cbk_t)ppc32_exec_chk_hi);                      (ilt_check_cbk_t)ppc32_exec_chk_hi);
# Line 76  void ppc32_dump_stats(cpu_ppc_t *cpu) Line 76  void ppc32_dump_stats(cpu_ppc_t *cpu)
76  }  }
77    
78  /* Execute a memory operation */  /* Execute a memory operation */
79  static forced_inline int ppc32_exec_memop(cpu_ppc_t *cpu,int memop,  static forced_inline void ppc32_exec_memop(cpu_ppc_t *cpu,int memop,
80                                            m_uint32_t vaddr,u_int dst_reg)                                             m_uint32_t vaddr,u_int dst_reg)
81  {      {    
82     fastcall ppc_memop_fn fn;     fastcall ppc_memop_fn fn;
83            
84     fn = cpu->mem_op_fn[memop];     fn = cpu->mem_op_fn[memop];
85     return(fn(cpu,vaddr,dst_reg));     fn(cpu,vaddr,dst_reg);
86  }  }
87    
88  /* Fetch an instruction */  /* Fetch an instruction */
# Line 103  static forced_inline int ppc32_exec_fetc Line 103  static forced_inline int ppc32_exec_fetc
103     return(0);     return(0);
104  }  }
105    
106    /* Unknown opcode */
107    static fastcall int ppc32_exec_unknown(cpu_ppc_t *cpu,ppc_insn_t insn)
108    {  
109       printf("PPC32: unknown opcode 0x%8.8x at ia = 0x%x\n",insn,cpu->ia);
110       ppc32_dump_regs(cpu->gen);
111       return(0);
112    }
113    
114  /* Execute a single instruction */  /* Execute a single instruction */
115  static forced_inline int  static forced_inline int
116  ppc32_exec_single_instruction(cpu_ppc_t *cpu,ppc_insn_t instruction)  ppc32_exec_single_instruction(cpu_ppc_t *cpu,ppc_insn_t instruction)
# Line 110  ppc32_exec_single_instruction(cpu_ppc_t Line 118  ppc32_exec_single_instruction(cpu_ppc_t
118     register fastcall int (*exec)(cpu_ppc_t *,ppc_insn_t) = NULL;     register fastcall int (*exec)(cpu_ppc_t *,ppc_insn_t) = NULL;
119     struct ppc32_insn_exec_tag *tag;     struct ppc32_insn_exec_tag *tag;
120     int index;     int index;
121      
122  #if DEBUG_INSN_PERF_CNT  #if DEBUG_INSN_PERF_CNT
123     cpu->perf_counter++;     cpu->perf_counter++;
124  #endif  #endif
# Line 120  ppc32_exec_single_instruction(cpu_ppc_t Line 128  ppc32_exec_single_instruction(cpu_ppc_t
128     tag = ppc32_exec_get_insn(index);     tag = ppc32_exec_get_insn(index);
129     exec = tag->exec;     exec = tag->exec;
130    
    if (likely(exec != NULL)) {  
131  #if NJM_STATS_ENABLE  #if NJM_STATS_ENABLE
132        cpu->insn_exec_count++;     cpu->insn_exec_count++;
133        ppc32_exec_tags[index].count++;     ppc32_exec_tags[index].count++;
134  #endif  #endif
135        return(exec(cpu,instruction));     return(exec(cpu,instruction));
    }  
   
    printf("PPC32: unknown opcode 0x%8.8x at ia = 0x%x\n",  
           instruction,cpu->ia);  
    ppc32_dump_regs(cpu->gen);  
    return(0);  
136  }  }
137    
138  /* Execute a single instruction (external) */  /* Execute a single instruction (external) */
# Line 144  fastcall int ppc32_exec_single_insn_ext( Line 145  fastcall int ppc32_exec_single_insn_ext(
145     return(res);     return(res);
146  }  }
147    
148    /* Execute a page */
149    fastcall int ppc32_exec_page(cpu_ppc_t *cpu)
150    {
151       m_uint32_t exec_page,offset;
152       ppc_insn_t insn;
153       int res;
154    
155       exec_page = cpu->ia & ~PPC32_MIN_PAGE_IMASK;
156       cpu->njm_exec_page = exec_page;
157       cpu->njm_exec_ptr  = cpu->mem_op_lookup(cpu,exec_page,PPC32_MTS_ICACHE);
158    
159       do {
160          offset = (cpu->ia & PPC32_MIN_PAGE_IMASK) >> 2;
161          insn = vmtoh32(cpu->njm_exec_ptr[offset]);
162    
163          res = ppc32_exec_single_instruction(cpu,insn);
164          if (likely(!res)) cpu->ia += sizeof(ppc_insn_t);
165       }while((cpu->ia & ~PPC32_MIN_PAGE_IMASK) == exec_page);
166    
167       return(0);
168    }
169    
170  /* Run PowerPC code in step-by-step mode */  /* Run PowerPC code in step-by-step mode */
171  void *ppc32_exec_run_cpu(cpu_gen_t *gen)  void *ppc32_exec_run_cpu(cpu_gen_t *gen)
172  {    {  
# Line 163  void *ppc32_exec_run_cpu(cpu_gen_t *gen) Line 186  void *ppc32_exec_run_cpu(cpu_gen_t *gen)
186     }     }
187    
188     gen->cpu_thread_running = TRUE;     gen->cpu_thread_running = TRUE;
189       cpu_exec_loop_set(gen);
190    
191   start_cpu:   start_cpu:
192     for(;;) {     for(;;) {
# Line 237  static forced_inline void ppc32_exec_upd Line 261  static forced_inline void ppc32_exec_upd
261     m_uint32_t res;     m_uint32_t res;
262    
263     if (val & 0x80000000)     if (val & 0x80000000)
264        res = PPC32_CR0_LT;        res = 1 << PPC32_CR_LT_BIT;
265     else {     else {
266        if (val > 0)        if (val > 0)
267           res = PPC32_CR0_GT;           res = 1 << PPC32_CR_GT_BIT;
268        else        else
269           res = PPC32_CR0_EQ;           res = 1 << PPC32_CR_EQ_BIT;
270     }     }
271    
272     if (cpu->xer & PPC32_XER_SO)     if (cpu->xer & PPC32_XER_SO)
273        res |= PPC32_CR0_SO;        res |= 1 << PPC32_CR_SO_BIT;
274    
275     cpu->cr &= ~(PPC32_CR0_LT|PPC32_CR0_GT|PPC32_CR0_EQ|PPC32_CR0_SO);     cpu->cr_fields[0] = res;
    cpu->cr |= res;  
276  }  }
277    
278  /*  /*
# Line 312  static forced_inline int ppc32_check_con Line 335  static forced_inline int ppc32_check_con
335  {  {
336     u_int ctr_ok = TRUE;     u_int ctr_ok = TRUE;
337     u_int cond_ok;     u_int cond_ok;
338       u_int cr_bit;
339    
340     if (!(bo & 0x04)) {     if (!(bo & 0x04)) {
341        cpu->ctr--;        cpu->ctr--;
342        ctr_ok = (cpu->ctr != 0) ^ ((bo >> 1) & 0x1);        ctr_ok = (cpu->ctr != 0) ^ ((bo >> 1) & 0x1);
343     }     }
344    
345     cond_ok = (bo >> 4) | (((cpu->cr >> (31 - bi)) ^ (~bo >> 3)) & 0x1);     cr_bit = ppc32_read_cr_bit(cpu,bi);
346       cond_ok = (bo >> 4) | ((cr_bit ^ (~bo >> 3)) & 0x1);
347    
348     return(ctr_ok & cond_ok);     return(ctr_ok & cond_ok);
349  }  }
# Line 1005  static fastcall int ppc32_exec_CMP(cpu_p Line 1030  static fastcall int ppc32_exec_CMP(cpu_p
1030    
1031     if (cpu->xer & PPC32_XER_SO)     if (cpu->xer & PPC32_XER_SO)
1032        res |= 0x01;        res |= 0x01;
1033      
1034     cpu->cr &= ~(0xF0000000 >> (rd << 2));     cpu->cr_fields[rd] = res;
    cpu->cr |= res << (28 - (rd << 2));  
1035     return(0);     return(0);
1036  }  }
1037    
# Line 1035  static fastcall int ppc32_exec_CMPI(cpu_ Line 1059  static fastcall int ppc32_exec_CMPI(cpu_
1059     if (cpu->xer & PPC32_XER_SO)     if (cpu->xer & PPC32_XER_SO)
1060        res |= 0x01;        res |= 0x01;
1061        
1062     cpu->cr &= ~(0xF0000000 >> (rd << 2));     cpu->cr_fields[rd] = res;
    cpu->cr |= res << (28 - (rd << 2));  
1063     return(0);     return(0);
1064  }  }
1065    
# Line 1063  static fastcall int ppc32_exec_CMPL(cpu_ Line 1086  static fastcall int ppc32_exec_CMPL(cpu_
1086     if (cpu->xer & PPC32_XER_SO)     if (cpu->xer & PPC32_XER_SO)
1087        res |= 0x01;        res |= 0x01;
1088    
1089     cpu->cr &= ~(0xF0000000 >> (rd << 2));     cpu->cr_fields[rd] = res;
    cpu->cr |= res << (28 - (rd << 2));  
1090     return(0);     return(0);
1091  }  }
1092    
# Line 1090  static fastcall int ppc32_exec_CMPLI(cpu Line 1112  static fastcall int ppc32_exec_CMPLI(cpu
1112     if (cpu->xer & PPC32_XER_SO)     if (cpu->xer & PPC32_XER_SO)
1113        res |= 0x01;        res |= 0x01;
1114        
1115     cpu->cr &= ~(0xF0000000 >> (rd << 2));     cpu->cr_fields[rd] = res;
    cpu->cr |= res << (28 - (rd << 2));  
1116     return(0);     return(0);
1117  }  }
1118    
# Line 1125  static fastcall int ppc32_exec_CRAND(cpu Line 1146  static fastcall int ppc32_exec_CRAND(cpu
1146     int ba = bits(insn,11,15);     int ba = bits(insn,11,15);
1147     m_uint32_t tmp;     m_uint32_t tmp;
1148    
1149     tmp =  cpu->cr >> (31 - ba);     tmp =  ppc32_read_cr_bit(cpu,ba);
1150     tmp &= cpu->cr >> (31 - bb);     tmp &= ppc32_read_cr_bit(cpu,bb);
1151    
1152     if (tmp & 0x1)     if (tmp & 0x1)
1153        cpu->cr |= 1 << (31 - bd);        ppc32_set_cr_bit(cpu,bd);
1154     else     else
1155        cpu->cr &= ~(1 << (31 - bd));        ppc32_clear_cr_bit(cpu,bd);
1156    
1157     return(0);     return(0);
1158  }  }
# Line 1144  static fastcall int ppc32_exec_CREQV(cpu Line 1165  static fastcall int ppc32_exec_CREQV(cpu
1165     int ba = bits(insn,11,15);     int ba = bits(insn,11,15);
1166     m_uint32_t tmp;     m_uint32_t tmp;
1167    
1168     tmp =  cpu->cr >> (31 - ba);     tmp =  ppc32_read_cr_bit(cpu,ba);
1169     tmp ^= cpu->cr >> (31 - bb);     tmp ^= ppc32_read_cr_bit(cpu,bb);
1170    
1171     if (!(tmp & 0x1))     if (!(tmp & 0x1))
1172        cpu->cr |= 1 << (31 - bd);        ppc32_set_cr_bit(cpu,bd);
1173     else     else
1174        cpu->cr &= ~(1 << (31 - bd));        ppc32_clear_cr_bit(cpu,bd);
1175    
1176     return(0);     return(0);
1177  }  }
# Line 1163  static fastcall int ppc32_exec_CRANDC(cp Line 1184  static fastcall int ppc32_exec_CRANDC(cp
1184     int ba = bits(insn,11,15);     int ba = bits(insn,11,15);
1185     m_uint32_t tmp;     m_uint32_t tmp;
1186    
1187     tmp =  cpu->cr >> (31 - ba);     tmp =  ppc32_read_cr_bit(cpu,ba);
1188     tmp &= ~(cpu->cr >> (31 - bb));     tmp &= ~ppc32_read_cr_bit(cpu,bb);
1189    
1190     if (tmp & 0x1)     if (tmp & 0x1)
1191        cpu->cr |= 1 << (31 - bd);        ppc32_set_cr_bit(cpu,bd);
1192     else     else
1193        cpu->cr &= ~(1 << (31 - bd));        ppc32_clear_cr_bit(cpu,bd);
1194    
1195     return(0);     return(0);
1196  }  }
# Line 1182  static fastcall int ppc32_exec_CRNAND(cp Line 1203  static fastcall int ppc32_exec_CRNAND(cp
1203     int ba = bits(insn,11,15);     int ba = bits(insn,11,15);
1204     m_uint32_t tmp;     m_uint32_t tmp;
1205    
1206     tmp =  cpu->cr >> (31 - ba);     tmp =  ppc32_read_cr_bit(cpu,ba);
1207     tmp &= cpu->cr >> (31 - bb);     tmp &= ppc32_read_cr_bit(cpu,bb);
1208    
1209     if (!(tmp & 0x1))     if (!(tmp & 0x1))
1210        cpu->cr |= 1 << (31 - bd);        ppc32_set_cr_bit(cpu,bd);
1211     else     else
1212        cpu->cr &= ~(1 << (31 - bd));        ppc32_clear_cr_bit(cpu,bd);
1213    
1214     return(0);     return(0);
1215  }  }
# Line 1201  static fastcall int ppc32_exec_CRNOR(cpu Line 1222  static fastcall int ppc32_exec_CRNOR(cpu
1222     int ba = bits(insn,11,15);     int ba = bits(insn,11,15);
1223     m_uint32_t tmp;     m_uint32_t tmp;
1224    
1225     tmp =  cpu->cr >> (31 - ba);     tmp =  ppc32_read_cr_bit(cpu,ba);
1226     tmp |= cpu->cr >> (31 - bb);     tmp |= ppc32_read_cr_bit(cpu,bb);
1227    
1228     if (!(tmp & 0x1))     if (!(tmp & 0x1))
1229        cpu->cr |= 1 << (31 - bd);        ppc32_set_cr_bit(cpu,bd);
1230     else     else
1231        cpu->cr &= ~(1 << (31 - bd));        ppc32_clear_cr_bit(cpu,bd);
1232    
1233     return(0);     return(0);
1234  }  }
# Line 1220  static fastcall int ppc32_exec_CROR(cpu_ Line 1241  static fastcall int ppc32_exec_CROR(cpu_
1241     int ba = bits(insn,11,15);     int ba = bits(insn,11,15);
1242     m_uint32_t tmp;     m_uint32_t tmp;
1243    
1244     tmp =  cpu->cr >> (31 - ba);     tmp =  ppc32_read_cr_bit(cpu,ba);
1245     tmp |= cpu->cr >> (31 - bb);     tmp |= ppc32_read_cr_bit(cpu,bb);
1246    
1247     if (tmp & 0x1)     if (tmp & 0x1)
1248        cpu->cr |= 1 << (31 - bd);        ppc32_set_cr_bit(cpu,bd);
1249     else     else
1250        cpu->cr &= ~(1 << (31 - bd));        ppc32_clear_cr_bit(cpu,bd);
1251    
1252     return(0);     return(0);
1253  }  }
# Line 1239  static fastcall int ppc32_exec_CRORC(cpu Line 1260  static fastcall int ppc32_exec_CRORC(cpu
1260     int ba = bits(insn,11,15);     int ba = bits(insn,11,15);
1261     m_uint32_t tmp;     m_uint32_t tmp;
1262    
1263     tmp =  cpu->cr >> (31 - ba);     tmp =  ppc32_read_cr_bit(cpu,ba);
1264     tmp |= ~(cpu->cr >> (31 - bb));     tmp |= ~ppc32_read_cr_bit(cpu,bb);
1265    
1266     if (tmp & 0x1)     if (tmp & 0x1)
1267        cpu->cr |= 1 << (31 - bd);        ppc32_set_cr_bit(cpu,bd);
1268     else     else
1269        cpu->cr &= ~(1 << (31 - bd));        ppc32_clear_cr_bit(cpu,bd);
1270    
1271     return(0);     return(0);
1272  }  }
# Line 1258  static fastcall int ppc32_exec_CRXOR(cpu Line 1279  static fastcall int ppc32_exec_CRXOR(cpu
1279     int ba = bits(insn,11,15);     int ba = bits(insn,11,15);
1280     m_uint32_t tmp;     m_uint32_t tmp;
1281    
1282     tmp =  cpu->cr >> (31 - ba);     tmp =  ppc32_read_cr_bit(cpu,ba);
1283     tmp ^= cpu->cr >> (31 - bb);     tmp ^= ppc32_read_cr_bit(cpu,bb);
1284    
1285     if (tmp & 0x1)     if (tmp & 0x1)
1286        cpu->cr |= 1 << (31 - bd);        ppc32_set_cr_bit(cpu,bd);
1287     else     else
1288        cpu->cr &= ~(1 << (31 - bd));        ppc32_clear_cr_bit(cpu,bd);
1289    
1290     return(0);     return(0);
1291  }  }
# Line 1480  static fastcall int ppc32_exec_ICBI(cpu_ Line 1501  static fastcall int ppc32_exec_ICBI(cpu_
1501     if (ra != 0)     if (ra != 0)
1502        vaddr += cpu->gpr[ra];        vaddr += cpu->gpr[ra];
1503    
1504     return(ppc32_exec_memop(cpu,PPC_MEMOP_ICBI,vaddr,0));     ppc32_exec_memop(cpu,PPC_MEMOP_ICBI,vaddr,0);
1505       return(0);
1506  }  }
1507    
1508  /* ISYNC - Instruction Synchronize */  /* ISYNC - Instruction Synchronize */
# Line 1502  static fastcall int ppc32_exec_LBZ(cpu_p Line 1524  static fastcall int ppc32_exec_LBZ(cpu_p
1524     if (ra != 0)     if (ra != 0)
1525        vaddr += cpu->gpr[ra];        vaddr += cpu->gpr[ra];
1526    
1527     return(ppc32_exec_memop(cpu,PPC_MEMOP_LBZ,vaddr,rd));     ppc32_exec_memop(cpu,PPC_MEMOP_LBZ,vaddr,rd);
1528       return(0);
1529  }  }
1530    
1531  /* LBZU - Load Byte and Zero with Update */  /* LBZU - Load Byte and Zero with Update */
# Line 1512  static fastcall int ppc32_exec_LBZU(cpu_ Line 1535  static fastcall int ppc32_exec_LBZU(cpu_
1535     int ra = bits(insn,16,20);     int ra = bits(insn,16,20);
1536     m_uint16_t imm = bits(insn,0,15);     m_uint16_t imm = bits(insn,0,15);
1537     m_uint32_t vaddr;     m_uint32_t vaddr;
    int res;  
1538    
1539     vaddr = cpu->gpr[ra] + sign_extend_32(imm,16);     vaddr = cpu->gpr[ra] + sign_extend_32(imm,16);
1540     res = ppc32_exec_memop(cpu,PPC_MEMOP_LBZ,vaddr,rd);     ppc32_exec_memop(cpu,PPC_MEMOP_LBZ,vaddr,rd);
1541     cpu->gpr[ra] = vaddr;     cpu->gpr[ra] = vaddr;
1542     return(res);     return(0);
1543  }  }
1544    
1545  /* LBZUX - Load Byte and Zero with Update Indexed */  /* LBZUX - Load Byte and Zero with Update Indexed */
# Line 1527  static fastcall int ppc32_exec_LBZUX(cpu Line 1549  static fastcall int ppc32_exec_LBZUX(cpu
1549     int ra = bits(insn,16,20);     int ra = bits(insn,16,20);
1550     int rb = bits(insn,11,15);     int rb = bits(insn,11,15);
1551     m_uint32_t vaddr;     m_uint32_t vaddr;
    int res;  
1552    
1553     vaddr = cpu->gpr[ra] + cpu->gpr[rb];     vaddr = cpu->gpr[ra] + cpu->gpr[rb];
1554     res = ppc32_exec_memop(cpu,PPC_MEMOP_LBZ,vaddr,rd);     ppc32_exec_memop(cpu,PPC_MEMOP_LBZ,vaddr,rd);
1555     cpu->gpr[ra] = vaddr;     cpu->gpr[ra] = vaddr;
1556     return(res);     return(0);
1557  }  }
1558    
1559  /* LBZX - Load Byte and Zero Indexed */  /* LBZX - Load Byte and Zero Indexed */
# Line 1548  static fastcall int ppc32_exec_LBZX(cpu_ Line 1569  static fastcall int ppc32_exec_LBZX(cpu_
1569     if (ra != 0)     if (ra != 0)
1570        vaddr += cpu->gpr[ra];        vaddr += cpu->gpr[ra];
1571    
1572     return(ppc32_exec_memop(cpu,PPC_MEMOP_LBZ,vaddr,rd));     ppc32_exec_memop(cpu,PPC_MEMOP_LBZ,vaddr,rd);
1573       return(0);
1574  }  }
1575    
1576  /* LHA - Load Half-Word Algebraic */  /* LHA - Load Half-Word Algebraic */
# Line 1564  static fastcall int ppc32_exec_LHA(cpu_p Line 1586  static fastcall int ppc32_exec_LHA(cpu_p
1586     if (ra != 0)     if (ra != 0)
1587        vaddr += cpu->gpr[ra];        vaddr += cpu->gpr[ra];
1588    
1589     return(ppc32_exec_memop(cpu,PPC_MEMOP_LHA,vaddr,rd));     ppc32_exec_memop(cpu,PPC_MEMOP_LHA,vaddr,rd);
1590       return(0);
1591  }  }
1592    
1593  /* LHAU - Load Half-Word Algebraic with Update */  /* LHAU - Load Half-Word Algebraic with Update */
# Line 1574  static fastcall int ppc32_exec_LHAU(cpu_ Line 1597  static fastcall int ppc32_exec_LHAU(cpu_
1597     int ra = bits(insn,16,20);     int ra = bits(insn,16,20);
1598     m_uint16_t imm = bits(insn,0,15);     m_uint16_t imm = bits(insn,0,15);
1599     m_uint32_t vaddr;     m_uint32_t vaddr;
    int res;  
1600    
1601     vaddr = cpu->gpr[ra] + sign_extend_32(imm,16);     vaddr = cpu->gpr[ra] + sign_extend_32(imm,16);
1602     res = ppc32_exec_memop(cpu,PPC_MEMOP_LHA,vaddr,rd);     ppc32_exec_memop(cpu,PPC_MEMOP_LHA,vaddr,rd);
1603     cpu->gpr[ra] = vaddr;     cpu->gpr[ra] = vaddr;
1604     return(res);     return(0);
1605  }  }
1606    
1607  /* LHAUX - Load Half-Word Algebraic with Update Indexed */  /* LHAUX - Load Half-Word Algebraic with Update Indexed */
# Line 1589  static fastcall int ppc32_exec_LHAUX(cpu Line 1611  static fastcall int ppc32_exec_LHAUX(cpu
1611     int ra = bits(insn,16,20);     int ra = bits(insn,16,20);
1612     int rb = bits(insn,11,15);     int rb = bits(insn,11,15);
1613     m_uint32_t vaddr;     m_uint32_t vaddr;
    int res;  
1614    
1615     vaddr = cpu->gpr[ra] + cpu->gpr[rb];     vaddr = cpu->gpr[ra] + cpu->gpr[rb];
1616     res = ppc32_exec_memop(cpu,PPC_MEMOP_LHA,vaddr,rd);     ppc32_exec_memop(cpu,PPC_MEMOP_LHA,vaddr,rd);
1617     cpu->gpr[ra] = vaddr;     cpu->gpr[ra] = vaddr;
1618     return(res);     return(0);
1619  }  }
1620    
1621  /* LHAX - Load Half-Word Algebraic ndexed */  /* LHAX - Load Half-Word Algebraic ndexed */
# Line 1610  static fastcall int ppc32_exec_LHAX(cpu_ Line 1631  static fastcall int ppc32_exec_LHAX(cpu_
1631     if (ra != 0)     if (ra != 0)
1632        vaddr += cpu->gpr[ra];        vaddr += cpu->gpr[ra];
1633    
1634     return(ppc32_exec_memop(cpu,PPC_MEMOP_LHA,vaddr,rd));     ppc32_exec_memop(cpu,PPC_MEMOP_LHA,vaddr,rd);
1635       return(0);
1636  }  }
1637    
1638  /* LHZ - Load Half-Word and Zero */  /* LHZ - Load Half-Word and Zero */
# Line 1626  static fastcall int ppc32_exec_LHZ(cpu_p Line 1648  static fastcall int ppc32_exec_LHZ(cpu_p
1648     if (ra != 0)     if (ra != 0)
1649        vaddr += cpu->gpr[ra];        vaddr += cpu->gpr[ra];
1650    
1651     return(ppc32_exec_memop(cpu,PPC_MEMOP_LHZ,vaddr,rd));     ppc32_exec_memop(cpu,PPC_MEMOP_LHZ,vaddr,rd);
1652       return(0);
1653  }  }
1654    
1655  /* LHZU - Load Half-Word and Zero with Update */  /* LHZU - Load Half-Word and Zero with Update */
# Line 1636  static fastcall int ppc32_exec_LHZU(cpu_ Line 1659  static fastcall int ppc32_exec_LHZU(cpu_
1659     int ra = bits(insn,16,20);     int ra = bits(insn,16,20);
1660     m_uint16_t imm = bits(insn,0,15);     m_uint16_t imm = bits(insn,0,15);
1661     m_uint32_t vaddr;     m_uint32_t vaddr;
    int res;  
1662    
1663     vaddr = cpu->gpr[ra] + sign_extend_32(imm,16);     vaddr = cpu->gpr[ra] + sign_extend_32(imm,16);
1664     res = ppc32_exec_memop(cpu,PPC_MEMOP_LHZ,vaddr,rd);     ppc32_exec_memop(cpu,PPC_MEMOP_LHZ,vaddr,rd);
1665     cpu->gpr[ra] = vaddr;     cpu->gpr[ra] = vaddr;
1666     return(res);     return(0);
1667  }  }
1668    
1669  /* LHZUX - Load Half-Word and Zero with Update Indexed */  /* LHZUX - Load Half-Word and Zero with Update Indexed */
# Line 1651  static fastcall int ppc32_exec_LHZUX(cpu Line 1673  static fastcall int ppc32_exec_LHZUX(cpu
1673     int ra = bits(insn,16,20);     int ra = bits(insn,16,20);
1674     int rb = bits(insn,11,15);     int rb = bits(insn,11,15);
1675     m_uint32_t vaddr;     m_uint32_t vaddr;
    int res;  
1676    
1677     vaddr = cpu->gpr[ra] + cpu->gpr[rb];     vaddr = cpu->gpr[ra] + cpu->gpr[rb];
1678     res = ppc32_exec_memop(cpu,PPC_MEMOP_LHZ,vaddr,rd);     ppc32_exec_memop(cpu,PPC_MEMOP_LHZ,vaddr,rd);
1679     cpu->gpr[ra] = vaddr;     cpu->gpr[ra] = vaddr;
1680     return(res);     return(0);
1681  }  }
1682    
1683  /* LHZX - Load Half-Word and Zero Indexed */  /* LHZX - Load Half-Word and Zero Indexed */
# Line 1672  static fastcall int ppc32_exec_LHZX(cpu_ Line 1693  static fastcall int ppc32_exec_LHZX(cpu_
1693     if (ra != 0)     if (ra != 0)
1694        vaddr += cpu->gpr[ra];        vaddr += cpu->gpr[ra];
1695    
1696     return(ppc32_exec_memop(cpu,PPC_MEMOP_LHZ,vaddr,rd));     ppc32_exec_memop(cpu,PPC_MEMOP_LHZ,vaddr,rd);
1697       return(0);
1698  }  }
1699    
1700  /* LMW - Load Multiple Word */  /* LMW - Load Multiple Word */
# Line 1682  static fastcall int ppc32_exec_LMW(cpu_p Line 1704  static fastcall int ppc32_exec_LMW(cpu_p
1704     int ra = bits(insn,16,20);     int ra = bits(insn,16,20);
1705     m_uint16_t imm = bits(insn,0,15);     m_uint16_t imm = bits(insn,0,15);
1706     m_uint32_t vaddr;     m_uint32_t vaddr;
1707     int r,res;     int r;
1708    
1709     vaddr = sign_extend_32(imm,16);     vaddr = sign_extend_32(imm,16);
1710        
# Line 1690  static fastcall int ppc32_exec_LMW(cpu_p Line 1712  static fastcall int ppc32_exec_LMW(cpu_p
1712        vaddr += cpu->gpr[ra];        vaddr += cpu->gpr[ra];
1713    
1714     for(r=rd;r<=31;r++) {     for(r=rd;r<=31;r++) {
1715        res = ppc32_exec_memop(cpu,PPC_MEMOP_LWZ,vaddr,r);        ppc32_exec_memop(cpu,PPC_MEMOP_LWZ,vaddr,r);
       if (res != 0) return(res);  
   
1716        vaddr += sizeof(m_uint32_t);        vaddr += sizeof(m_uint32_t);
1717     }     }
1718    
# Line 1712  static fastcall int ppc32_exec_LWBRX(cpu Line 1732  static fastcall int ppc32_exec_LWBRX(cpu
1732     if (ra != 0)     if (ra != 0)
1733        vaddr += cpu->gpr[ra];        vaddr += cpu->gpr[ra];
1734    
1735     return(ppc32_exec_memop(cpu,PPC_MEMOP_LWBR,vaddr,rd));     ppc32_exec_memop(cpu,PPC_MEMOP_LWBR,vaddr,rd);
1736       return(0);
1737  }  }
1738    
1739  /* LWZ - Load Word and Zero */  /* LWZ - Load Word and Zero */
# Line 1728  static fastcall int ppc32_exec_LWZ(cpu_p Line 1749  static fastcall int ppc32_exec_LWZ(cpu_p
1749     if (ra != 0)     if (ra != 0)
1750        vaddr += cpu->gpr[ra];        vaddr += cpu->gpr[ra];
1751    
1752     return(ppc32_exec_memop(cpu,PPC_MEMOP_LWZ,vaddr,rd));     ppc32_exec_memop(cpu,PPC_MEMOP_LWZ,vaddr,rd);
1753       return(0);
1754  }  }
1755    
1756  /* LWZU - Load Word and Zero with Update */  /* LWZU - Load Word and Zero with Update */
# Line 1738  static fastcall int ppc32_exec_LWZU(cpu_ Line 1760  static fastcall int ppc32_exec_LWZU(cpu_
1760     int ra = bits(insn,16,20);     int ra = bits(insn,16,20);
1761     m_uint16_t imm = bits(insn,0,15);     m_uint16_t imm = bits(insn,0,15);
1762     m_uint32_t vaddr;     m_uint32_t vaddr;
    int res;  
1763    
1764     vaddr = cpu->gpr[ra] + sign_extend_32(imm,16);     vaddr = cpu->gpr[ra] + sign_extend_32(imm,16);
1765     res = ppc32_exec_memop(cpu,PPC_MEMOP_LWZ,vaddr,rd);     ppc32_exec_memop(cpu,PPC_MEMOP_LWZ,vaddr,rd);
1766     cpu->gpr[ra] = vaddr;     cpu->gpr[ra] = vaddr;
1767     return(res);     return(0);
1768  }  }
1769    
1770  /* LWZUX - Load Word and Zero with Update Indexed */  /* LWZUX - Load Word and Zero with Update Indexed */
# Line 1753  static fastcall int ppc32_exec_LWZUX(cpu Line 1774  static fastcall int ppc32_exec_LWZUX(cpu
1774     int ra = bits(insn,16,20);     int ra = bits(insn,16,20);
1775     int rb = bits(insn,11,15);     int rb = bits(insn,11,15);
1776     m_uint32_t vaddr;     m_uint32_t vaddr;
    int res;  
1777    
1778     vaddr = cpu->gpr[ra] + cpu->gpr[rb];     vaddr = cpu->gpr[ra] + cpu->gpr[rb];
1779     res = ppc32_exec_memop(cpu,PPC_MEMOP_LWZ,vaddr,rd);     ppc32_exec_memop(cpu,PPC_MEMOP_LWZ,vaddr,rd);
1780     cpu->gpr[ra] = vaddr;     cpu->gpr[ra] = vaddr;
1781     return(res);     return(0);
1782  }  }
1783    
1784  /* LWZX - Load Word and Zero Indexed */  /* LWZX - Load Word and Zero Indexed */
# Line 1774  static fastcall int ppc32_exec_LWZX(cpu_ Line 1794  static fastcall int ppc32_exec_LWZX(cpu_
1794     if (ra != 0)     if (ra != 0)
1795        vaddr += cpu->gpr[ra];        vaddr += cpu->gpr[ra];
1796    
1797     return(ppc32_exec_memop(cpu,PPC_MEMOP_LWZ,vaddr,rd));     ppc32_exec_memop(cpu,PPC_MEMOP_LWZ,vaddr,rd);
1798       return(0);
1799  }  }
1800    
1801  /* LWARX - Load Word and Reserve Indexed */  /* LWARX - Load Word and Reserve Indexed */
# Line 1791  static fastcall int ppc32_exec_LWARX(cpu Line 1812  static fastcall int ppc32_exec_LWARX(cpu
1812        vaddr += cpu->gpr[ra];        vaddr += cpu->gpr[ra];
1813    
1814     cpu->reserve = 1;     cpu->reserve = 1;
1815       ppc32_exec_memop(cpu,PPC_MEMOP_LWZ,vaddr,rd);
1816     return(ppc32_exec_memop(cpu,PPC_MEMOP_LWZ,vaddr,rd));     return(0);
1817  }  }
1818    
1819  /* LFD - Load Floating-Point Double */  /* LFD - Load Floating-Point Double */
# Line 1808  static fastcall int ppc32_exec_LFD(cpu_p Line 1829  static fastcall int ppc32_exec_LFD(cpu_p
1829     if (ra != 0)     if (ra != 0)
1830        vaddr += cpu->gpr[ra];        vaddr += cpu->gpr[ra];
1831    
1832     return(ppc32_exec_memop(cpu,PPC_MEMOP_LFD,vaddr,rd));     ppc32_exec_memop(cpu,PPC_MEMOP_LFD,vaddr,rd);
1833       return(0);
1834  }  }
1835    
1836  /* LFDU - Load Floating-Point Double with Update */  /* LFDU - Load Floating-Point Double with Update */
# Line 1818  static fastcall int ppc32_exec_LFDU(cpu_ Line 1840  static fastcall int ppc32_exec_LFDU(cpu_
1840     int ra = bits(insn,16,20);     int ra = bits(insn,16,20);
1841     m_uint16_t imm = bits(insn,0,15);     m_uint16_t imm = bits(insn,0,15);
1842     m_uint32_t vaddr;     m_uint32_t vaddr;
    int res;  
1843    
1844     vaddr = cpu->gpr[ra] + sign_extend_32(imm,16);     vaddr = cpu->gpr[ra] + sign_extend_32(imm,16);
1845     res = ppc32_exec_memop(cpu,PPC_MEMOP_LFD,vaddr,rd);     ppc32_exec_memop(cpu,PPC_MEMOP_LFD,vaddr,rd);
1846     cpu->gpr[ra] = vaddr;     cpu->gpr[ra] = vaddr;
1847     return(res);     return(0);
1848  }  }
1849    
1850  /* LFDUX - Load Floating-Point Double with Update Indexed */  /* LFDUX - Load Floating-Point Double with Update Indexed */
# Line 1833  static fastcall int ppc32_exec_LFDUX(cpu Line 1854  static fastcall int ppc32_exec_LFDUX(cpu
1854     int ra = bits(insn,16,20);     int ra = bits(insn,16,20);
1855     int rb = bits(insn,11,15);     int rb = bits(insn,11,15);
1856     m_uint32_t vaddr;     m_uint32_t vaddr;
    int res;  
1857    
1858     vaddr = cpu->gpr[ra] + cpu->gpr[rb];     vaddr = cpu->gpr[ra] + cpu->gpr[rb];
1859     res = ppc32_exec_memop(cpu,PPC_MEMOP_LFD,vaddr,rd);     ppc32_exec_memop(cpu,PPC_MEMOP_LFD,vaddr,rd);
1860     cpu->gpr[ra] = vaddr;     cpu->gpr[ra] = vaddr;
1861     return(res);     return(0);
1862  }  }
1863    
1864  /* LFDX - Load Floating-Point Double Indexed */  /* LFDX - Load Floating-Point Double Indexed */
# Line 1854  static fastcall int ppc32_exec_LFDX(cpu_ Line 1874  static fastcall int ppc32_exec_LFDX(cpu_
1874     if (ra != 0)     if (ra != 0)
1875        vaddr += cpu->gpr[ra];        vaddr += cpu->gpr[ra];
1876    
1877     return(ppc32_exec_memop(cpu,PPC_MEMOP_LFD,vaddr,rd));     ppc32_exec_memop(cpu,PPC_MEMOP_LFD,vaddr,rd);
1878       return(0);
1879  }  }
1880    
1881  /* LSWI - Load String Word Immediate */  /* LSWI - Load String Word Immediate */
# Line 1864  static fastcall int ppc32_exec_LSWI(cpu_ Line 1885  static fastcall int ppc32_exec_LSWI(cpu_
1885     int ra = bits(insn,16,20);     int ra = bits(insn,16,20);
1886     int nb = bits(insn,11,15);     int nb = bits(insn,11,15);
1887     m_uint32_t vaddr = 0;     m_uint32_t vaddr = 0;
1888     int res,r;     int r;
1889    
1890     if (ra != 0)     if (ra != 0)
1891        vaddr += cpu->gpr[ra];        vaddr += cpu->gpr[ra];
# Line 1881  static fastcall int ppc32_exec_LSWI(cpu_ Line 1902  static fastcall int ppc32_exec_LSWI(cpu_
1902           cpu->gpr[r] = 0;           cpu->gpr[r] = 0;
1903        }        }
1904                
1905        if (unlikely(res = ppc32_exec_memop(cpu,PPC_MEMOP_LSW,vaddr,r)) != 0)        ppc32_exec_memop(cpu,PPC_MEMOP_LSW,vaddr,r);
          return(res);  
   
1906        cpu->sw_pos += 8;        cpu->sw_pos += 8;
1907    
1908        if (cpu->sw_pos == 32)        if (cpu->sw_pos == 32)
# Line 1903  static fastcall int ppc32_exec_LSWX(cpu_ Line 1922  static fastcall int ppc32_exec_LSWX(cpu_
1922     int ra = bits(insn,16,20);     int ra = bits(insn,16,20);
1923     int rb = bits(insn,11,15);     int rb = bits(insn,11,15);
1924     m_uint32_t vaddr;     m_uint32_t vaddr;
1925     int res,r,nb;     int r,nb;
1926    
1927     vaddr = cpu->gpr[rb];     vaddr = cpu->gpr[rb];
1928    
# Line 1920  static fastcall int ppc32_exec_LSWX(cpu_ Line 1939  static fastcall int ppc32_exec_LSWX(cpu_
1939           cpu->gpr[r] = 0;           cpu->gpr[r] = 0;
1940        }        }
1941                
1942        if (unlikely(res = ppc32_exec_memop(cpu,PPC_MEMOP_LSW,vaddr,r)) != 0)        ppc32_exec_memop(cpu,PPC_MEMOP_LSW,vaddr,r);
          return(res);  
   
1943        cpu->sw_pos += 8;        cpu->sw_pos += 8;
1944    
1945        if (cpu->sw_pos == 32)        if (cpu->sw_pos == 32)
# Line 1940  static fastcall int ppc32_exec_MCRF(cpu_ Line 1957  static fastcall int ppc32_exec_MCRF(cpu_
1957  {  {
1958     int rd = bits(insn,23,25);     int rd = bits(insn,23,25);
1959     int rs = bits(insn,18,20);     int rs = bits(insn,18,20);
    m_uint32_t tmp,dmask;  
   
    tmp = (cpu->cr >> (28 - (rs << 2))) & 0xF;  
   
    /* clear the destination bits */  
    dmask = (0xF0000000 >> (rd << 2));  
    cpu->cr &= ~dmask;  
1960    
1961     /* set the new field value */     cpu->cr_fields[rd] = cpu->cr_fields[rs];
    cpu->cr |= tmp << (28 - (rd << 2));  
1962     return(0);     return(0);
1963  }  }
1964    
# Line 1958  static fastcall int ppc32_exec_MFCR(cpu_ Line 1967  static fastcall int ppc32_exec_MFCR(cpu_
1967  {  {
1968     int rd = bits(insn,21,25);     int rd = bits(insn,21,25);
1969    
1970     cpu->gpr[rd] = cpu->cr;     cpu->gpr[rd] = ppc32_get_cr(cpu);
1971     return(0);     return(0);
1972  }  }
1973    
# Line 2064  static fastcall int ppc32_exec_MFSPR(cpu Line 2073  static fastcall int ppc32_exec_MFSPR(cpu
2073    
2074        /* MPC860 IMMR */        /* MPC860 IMMR */
2075        case 638:        case 638:
2076           cpu->gpr[rd] = 0x68010000;           cpu->gpr[rd] = cpu->mpc860_immr;
2077           break;           break;
2078    
2079        default:        default:
# Line 2100  static fastcall int ppc32_exec_MTCRF(cpu Line 2109  static fastcall int ppc32_exec_MTCRF(cpu
2109  {  {
2110     int rs = bits(insn,21,25);     int rs = bits(insn,21,25);
2111     int crm = bits(insn,12,19);     int crm = bits(insn,12,19);
    m_uint32_t mask = 0;  
2112     int i;     int i;
2113        
2114     for(i=0;i<8;i++)     for(i=0;i<8;i++)
2115        if (crm & (1 << i))        if (crm & (1 << (7 - i)))
2116           mask |= 0xF << (i << 2);           cpu->cr_fields[i] = (cpu->gpr[rs] >> (28 - (i << 2))) & 0x0F;
2117    
    cpu->cr = (cpu->gpr[rs] & mask) | (cpu->cr & ~mask);  
2118     return(0);     return(0);
2119  }  }
2120    
# Line 2827  static fastcall int ppc32_exec_STB(cpu_p Line 2834  static fastcall int ppc32_exec_STB(cpu_p
2834     if (ra != 0)     if (ra != 0)
2835        vaddr += cpu->gpr[ra];        vaddr += cpu->gpr[ra];
2836    
2837     return(ppc32_exec_memop(cpu,PPC_MEMOP_STB,vaddr,rs));     ppc32_exec_memop(cpu,PPC_MEMOP_STB,vaddr,rs);
2838       return(0);
2839  }  }
2840    
2841  /* STBU - Store Byte with Update */  /* STBU - Store Byte with Update */
# Line 2837  static fastcall int ppc32_exec_STBU(cpu_ Line 2845  static fastcall int ppc32_exec_STBU(cpu_
2845     int ra = bits(insn,16,20);     int ra = bits(insn,16,20);
2846     m_uint16_t imm = bits(insn,0,15);     m_uint16_t imm = bits(insn,0,15);
2847     m_uint32_t vaddr;     m_uint32_t vaddr;
    int res;  
2848    
2849     vaddr = cpu->gpr[ra] + sign_extend_32(imm,16);     vaddr = cpu->gpr[ra] + sign_extend_32(imm,16);
2850     res = ppc32_exec_memop(cpu,PPC_MEMOP_STB,vaddr,rs);     ppc32_exec_memop(cpu,PPC_MEMOP_STB,vaddr,rs);
2851     cpu->gpr[ra] = vaddr;     cpu->gpr[ra] = vaddr;
2852     return(res);     return(0);
2853  }  }
2854    
2855  /* STBUX - Store Byte with Update Indexed */  /* STBUX - Store Byte with Update Indexed */
# Line 2852  static fastcall int ppc32_exec_STBUX(cpu Line 2859  static fastcall int ppc32_exec_STBUX(cpu
2859     int ra = bits(insn,16,20);     int ra = bits(insn,16,20);
2860     int rb = bits(insn,11,15);     int rb = bits(insn,11,15);
2861     m_uint32_t vaddr;     m_uint32_t vaddr;
    int res;  
2862    
2863     vaddr = cpu->gpr[ra] + cpu->gpr[rb];     vaddr = cpu->gpr[ra] + cpu->gpr[rb];
2864     res = ppc32_exec_memop(cpu,PPC_MEMOP_STB,vaddr,rs);     ppc32_exec_memop(cpu,PPC_MEMOP_STB,vaddr,rs);
2865     cpu->gpr[ra] = vaddr;     cpu->gpr[ra] = vaddr;
2866     return(res);     return(0);
2867  }  }
2868    
2869  /* STBX - Store Byte Indexed */  /* STBX - Store Byte Indexed */
# Line 2873  static fastcall int ppc32_exec_STBX(cpu_ Line 2879  static fastcall int ppc32_exec_STBX(cpu_
2879     if (ra != 0)     if (ra != 0)
2880        vaddr += cpu->gpr[ra];        vaddr += cpu->gpr[ra];
2881    
2882     return(ppc32_exec_memop(cpu,PPC_MEMOP_STB,vaddr,rs));     ppc32_exec_memop(cpu,PPC_MEMOP_STB,vaddr,rs);
2883       return(0);
2884  }  }
2885    
2886  /* STH - Store Half-Word */  /* STH - Store Half-Word */
# Line 2889  static fastcall int ppc32_exec_STH(cpu_p Line 2896  static fastcall int ppc32_exec_STH(cpu_p
2896     if (ra != 0)     if (ra != 0)
2897        vaddr += cpu->gpr[ra];        vaddr += cpu->gpr[ra];
2898    
2899     return(ppc32_exec_memop(cpu,PPC_MEMOP_STH,vaddr,rs));     ppc32_exec_memop(cpu,PPC_MEMOP_STH,vaddr,rs);
2900       return(0);
2901  }  }
2902    
2903  /* STHU - Store Half-Word with Update */  /* STHU - Store Half-Word with Update */
# Line 2899  static fastcall int ppc32_exec_STHU(cpu_ Line 2907  static fastcall int ppc32_exec_STHU(cpu_
2907     int ra  = bits(insn,16,20);     int ra  = bits(insn,16,20);
2908     m_uint16_t imm = bits(insn,0,15);     m_uint16_t imm = bits(insn,0,15);
2909     m_uint32_t vaddr;     m_uint32_t vaddr;
    int res;  
2910    
2911     vaddr = cpu->gpr[ra] + sign_extend_32(imm,16);     vaddr = cpu->gpr[ra] + sign_extend_32(imm,16);
2912     res = ppc32_exec_memop(cpu,PPC_MEMOP_STH,vaddr,rs);     ppc32_exec_memop(cpu,PPC_MEMOP_STH,vaddr,rs);
2913     cpu->gpr[ra] = vaddr;     cpu->gpr[ra] = vaddr;
2914     return(res);     return(0);
2915  }  }
2916    
2917  /* STHUX - Store Half-Word with Update Indexed */  /* STHUX - Store Half-Word with Update Indexed */
# Line 2914  static fastcall int ppc32_exec_STHUX(cpu Line 2921  static fastcall int ppc32_exec_STHUX(cpu
2921     int ra = bits(insn,16,20);     int ra = bits(insn,16,20);
2922     int rb = bits(insn,11,15);     int rb = bits(insn,11,15);
2923     m_uint32_t vaddr;     m_uint32_t vaddr;
    int res;  
2924    
2925     vaddr = cpu->gpr[ra] + cpu->gpr[rb];     vaddr = cpu->gpr[ra] + cpu->gpr[rb];
2926     res = ppc32_exec_memop(cpu,PPC_MEMOP_STH,vaddr,rs);     ppc32_exec_memop(cpu,PPC_MEMOP_STH,vaddr,rs);
2927     cpu->gpr[ra] = vaddr;     cpu->gpr[ra] = vaddr;
2928     return(res);     return(0);
2929  }  }
2930    
2931  /* STHX - Store Half-Word Indexed */  /* STHX - Store Half-Word Indexed */
# Line 2935  static fastcall int ppc32_exec_STHX(cpu_ Line 2941  static fastcall int ppc32_exec_STHX(cpu_
2941     if (ra != 0)     if (ra != 0)
2942        vaddr += cpu->gpr[ra];        vaddr += cpu->gpr[ra];
2943    
2944     return(ppc32_exec_memop(cpu,PPC_MEMOP_STH,vaddr,rs));     ppc32_exec_memop(cpu,PPC_MEMOP_STH,vaddr,rs);
2945       return(0);
2946  }  }
2947    
2948  /* STMW - Store Multiple Word */  /* STMW - Store Multiple Word */
# Line 2945  static fastcall int ppc32_exec_STMW(cpu_ Line 2952  static fastcall int ppc32_exec_STMW(cpu_
2952     int ra = bits(insn,16,20);     int ra = bits(insn,16,20);
2953     m_uint16_t imm = bits(insn,0,15);     m_uint16_t imm = bits(insn,0,15);
2954     m_uint32_t vaddr;     m_uint32_t vaddr;
2955     int r,res;     int r;
2956    
2957     vaddr = sign_extend_32(imm,16);     vaddr = sign_extend_32(imm,16);
2958        
# Line 2953  static fastcall int ppc32_exec_STMW(cpu_ Line 2960  static fastcall int ppc32_exec_STMW(cpu_
2960        vaddr += cpu->gpr[ra];        vaddr += cpu->gpr[ra];
2961    
2962     for(r=rs;r<=31;r++) {     for(r=rs;r<=31;r++) {
2963        res = ppc32_exec_memop(cpu,PPC_MEMOP_STW,vaddr,r);        ppc32_exec_memop(cpu,PPC_MEMOP_STW,vaddr,r);
       if (res != 0) return(res);  
   
2964        vaddr += sizeof(m_uint32_t);        vaddr += sizeof(m_uint32_t);
2965     }     }
2966    
# Line 2975  static fastcall int ppc32_exec_STW(cpu_p Line 2980  static fastcall int ppc32_exec_STW(cpu_p
2980     if (ra != 0)     if (ra != 0)
2981        vaddr += cpu->gpr[ra];        vaddr += cpu->gpr[ra];
2982    
2983     return(ppc32_exec_memop(cpu,PPC_MEMOP_STW,vaddr,rs));     ppc32_exec_memop(cpu,PPC_MEMOP_STW,vaddr,rs);
2984       return(0);
2985  }  }
2986    
2987  /* STWU - Store Word with Update */  /* STWU - Store Word with Update */
# Line 2985  static fastcall int ppc32_exec_STWU(cpu_ Line 2991  static fastcall int ppc32_exec_STWU(cpu_
2991     int ra = bits(insn,16,20);     int ra = bits(insn,16,20);
2992     m_uint16_t imm = bits(insn,0,15);     m_uint16_t imm = bits(insn,0,15);
2993     m_uint32_t vaddr;     m_uint32_t vaddr;
    int res;  
2994    
2995     vaddr = cpu->gpr[ra] + sign_extend_32(imm,16);     vaddr = cpu->gpr[ra] + sign_extend_32(imm,16);
2996     res = ppc32_exec_memop(cpu,PPC_MEMOP_STW,vaddr,rs);     ppc32_exec_memop(cpu,PPC_MEMOP_STW,vaddr,rs);
2997     cpu->gpr[ra] = vaddr;     cpu->gpr[ra] = vaddr;
2998     return(res);     return(0);
2999  }  }
3000    
3001  /* STWUX - Store Word with Update Indexed */  /* STWUX - Store Word with Update Indexed */
# Line 3000  static fastcall int ppc32_exec_STWUX(cpu Line 3005  static fastcall int ppc32_exec_STWUX(cpu
3005     int ra = bits(insn,16,20);     int ra = bits(insn,16,20);
3006     int rb = bits(insn,11,15);     int rb = bits(insn,11,15);
3007     m_uint32_t vaddr;     m_uint32_t vaddr;
    int res;  
3008    
3009     vaddr = cpu->gpr[ra] + cpu->gpr[rb];     vaddr = cpu->gpr[ra] + cpu->gpr[rb];
3010     res = ppc32_exec_memop(cpu,PPC_MEMOP_STW,vaddr,rs);     ppc32_exec_memop(cpu,PPC_MEMOP_STW,vaddr,rs);
3011     cpu->gpr[ra] = vaddr;     cpu->gpr[ra] = vaddr;
3012     return(res);     return(0);
3013  }  }
3014    
3015  /* STWX - Store Word Indexed */  /* STWX - Store Word Indexed */
# Line 3021  static fastcall int ppc32_exec_STWX(cpu_ Line 3025  static fastcall int ppc32_exec_STWX(cpu_
3025     if (ra != 0)     if (ra != 0)
3026        vaddr += cpu->gpr[ra];        vaddr += cpu->gpr[ra];
3027    
3028     return(ppc32_exec_memop(cpu,PPC_MEMOP_STW,vaddr,rs));     ppc32_exec_memop(cpu,PPC_MEMOP_STW,vaddr,rs);
3029       return(0);
3030  }  }
3031    
3032  /* STWBRX - Store Word Byte-Reverse Indexed */  /* STWBRX - Store Word Byte-Reverse Indexed */
# Line 3037  static fastcall int ppc32_exec_STWBRX(cp Line 3042  static fastcall int ppc32_exec_STWBRX(cp
3042     if (ra != 0)     if (ra != 0)
3043        vaddr += cpu->gpr[ra];        vaddr += cpu->gpr[ra];
3044    
3045     return(ppc32_exec_memop(cpu,PPC_MEMOP_STWBR,vaddr,rs));     ppc32_exec_memop(cpu,PPC_MEMOP_STWBR,vaddr,rs);
3046       return(0);
3047  }  }
3048    
3049  /* STWCX. - Store Word Conditional Indexed */  /* STWCX. - Store Word Conditional Indexed */
# Line 3047  static fastcall int ppc32_exec_STWCX_dot Line 3053  static fastcall int ppc32_exec_STWCX_dot
3053     int ra = bits(insn,16,20);     int ra = bits(insn,16,20);
3054     int rb = bits(insn,11,15);     int rb = bits(insn,11,15);
3055     m_uint32_t vaddr;     m_uint32_t vaddr;
    int res;  
3056    
3057     vaddr = cpu->gpr[rb];     vaddr = cpu->gpr[rb];
3058    
# Line 3055  static fastcall int ppc32_exec_STWCX_dot Line 3060  static fastcall int ppc32_exec_STWCX_dot
3060        vaddr += cpu->gpr[ra];        vaddr += cpu->gpr[ra];
3061    
3062     if (cpu->reserve) {     if (cpu->reserve) {
3063        res = ppc32_exec_memop(cpu,PPC_MEMOP_STW,vaddr,rs);        ppc32_exec_memop(cpu,PPC_MEMOP_STW,vaddr,rs);
       if (res != 0) return(res);  
3064    
3065        cpu->cr &= ~0xF0000000;        cpu->cr_fields[0] = 1 << PPC32_CR_EQ_BIT;
       cpu->cr |= PPC32_CR0_EQ;  
3066    
3067        if (cpu->xer & PPC32_XER_SO)        if (cpu->xer & PPC32_XER_SO)
3068           cpu->cr |= PPC32_CR0_SO;           cpu->cr_fields[0] |= 1 << PPC32_CR_SO_BIT;
3069    
3070        cpu->reserve = 0;        cpu->reserve = 0;
3071     } else {     } else {
3072        cpu->cr &= ~0xF0000000;        cpu->cr_fields[0] = 0;
3073    
3074        if (cpu->xer & PPC32_XER_SO)        if (cpu->xer & PPC32_XER_SO)
3075           cpu->cr |= PPC32_CR0_SO;           cpu->cr_fields[0] |= 1 << PPC32_CR_SO_BIT;
3076     }     }
3077    
3078     return(0);     return(0);
# Line 3088  static fastcall int ppc32_exec_STFD(cpu_ Line 3091  static fastcall int ppc32_exec_STFD(cpu_
3091     if (ra != 0)     if (ra != 0)
3092        vaddr += cpu->gpr[ra];        vaddr += cpu->gpr[ra];
3093    
3094     return(ppc32_exec_memop(cpu,PPC_MEMOP_STFD,vaddr,rs));     ppc32_exec_memop(cpu,PPC_MEMOP_STFD,vaddr,rs);
3095       return(0);
3096  }  }
3097    
3098  /* STFDU - Store Floating-Point Double with Update */  /* STFDU - Store Floating-Point Double with Update */
# Line 3098  static fastcall int ppc32_exec_STFDU(cpu Line 3102  static fastcall int ppc32_exec_STFDU(cpu
3102     int ra = bits(insn,16,20);     int ra = bits(insn,16,20);
3103     m_uint16_t imm = bits(insn,0,15);     m_uint16_t imm = bits(insn,0,15);
3104     m_uint32_t vaddr;     m_uint32_t vaddr;
    int res;  
3105    
3106     vaddr = cpu->gpr[ra] + sign_extend_32(imm,16);     vaddr = cpu->gpr[ra] + sign_extend_32(imm,16);
3107     res = ppc32_exec_memop(cpu,PPC_MEMOP_STFD,vaddr,rs);     ppc32_exec_memop(cpu,PPC_MEMOP_STFD,vaddr,rs);
3108     cpu->gpr[ra] = vaddr;     cpu->gpr[ra] = vaddr;
3109     return(res);     return(0);
3110  }  }
3111    
3112  /* STFDUX - Store Floating-Point Double with Update Indexed */  /* STFDUX - Store Floating-Point Double with Update Indexed */
# Line 3113  static fastcall int ppc32_exec_STFDUX(cp Line 3116  static fastcall int ppc32_exec_STFDUX(cp
3116     int ra = bits(insn,16,20);     int ra = bits(insn,16,20);
3117     int rb = bits(insn,11,15);     int rb = bits(insn,11,15);
3118     m_uint32_t vaddr;     m_uint32_t vaddr;
    int res;  
3119    
3120     vaddr = cpu->gpr[ra] + cpu->gpr[rb];     vaddr = cpu->gpr[ra] + cpu->gpr[rb];
3121     res = ppc32_exec_memop(cpu,PPC_MEMOP_STFD,vaddr,rs);     ppc32_exec_memop(cpu,PPC_MEMOP_STFD,vaddr,rs);
3122     cpu->gpr[ra] = vaddr;     cpu->gpr[ra] = vaddr;
3123     return(res);     return(0);
3124  }  }
3125    
3126  /* STFDX - Store Floating-Point Double Indexed */  /* STFDX - Store Floating-Point Double Indexed */
# Line 3134  static fastcall int ppc32_exec_STFDX(cpu Line 3136  static fastcall int ppc32_exec_STFDX(cpu
3136     if (ra != 0)     if (ra != 0)
3137        vaddr += cpu->gpr[ra];        vaddr += cpu->gpr[ra];
3138    
3139     return(ppc32_exec_memop(cpu,PPC_MEMOP_STFD,vaddr,rs));     ppc32_exec_memop(cpu,PPC_MEMOP_STFD,vaddr,rs);
3140       return(0);
3141  }  }
3142    
3143  /* STSWI - Store String Word Immediate */  /* STSWI - Store String Word Immediate */
# Line 3144  static fastcall int ppc32_exec_STSWI(cpu Line 3147  static fastcall int ppc32_exec_STSWI(cpu
3147     int ra = bits(insn,16,20);     int ra = bits(insn,16,20);
3148     int nb = bits(insn,11,15);     int nb = bits(insn,11,15);
3149     m_uint32_t vaddr = 0;     m_uint32_t vaddr = 0;
3150     int res,r;     int r;
3151    
3152     if (ra != 0)     if (ra != 0)
3153        vaddr += cpu->gpr[ra];        vaddr += cpu->gpr[ra];
# Line 3159  static fastcall int ppc32_exec_STSWI(cpu Line 3162  static fastcall int ppc32_exec_STSWI(cpu
3162        if (cpu->sw_pos == 0)        if (cpu->sw_pos == 0)
3163           r = (r + 1) & 0x1F;           r = (r + 1) & 0x1F;
3164                
3165        if (unlikely(res = ppc32_exec_memop(cpu,PPC_MEMOP_STSW,vaddr,r)) != 0)        ppc32_exec_memop(cpu,PPC_MEMOP_STSW,vaddr,r);
          return(res);  
   
3166        cpu->sw_pos += 8;        cpu->sw_pos += 8;
3167    
3168        if (cpu->sw_pos == 32)        if (cpu->sw_pos == 32)
# Line 3181  static fastcall int ppc32_exec_STSWX(cpu Line 3182  static fastcall int ppc32_exec_STSWX(cpu
3182     int ra = bits(insn,16,20);     int ra = bits(insn,16,20);
3183     int rb = bits(insn,11,15);     int rb = bits(insn,11,15);
3184     m_uint32_t vaddr;     m_uint32_t vaddr;
3185     int res,r,nb;     int r,nb;
3186    
3187     vaddr = cpu->gpr[rb];     vaddr = cpu->gpr[rb];
3188    
# Line 3196  static fastcall int ppc32_exec_STSWX(cpu Line 3197  static fastcall int ppc32_exec_STSWX(cpu
3197        if (cpu->sw_pos == 0)        if (cpu->sw_pos == 0)
3198           r = (r + 1) & 0x1F;           r = (r + 1) & 0x1F;
3199                
3200        if (unlikely(res = ppc32_exec_memop(cpu,PPC_MEMOP_STSW,vaddr,r)) != 0)        ppc32_exec_memop(cpu,PPC_MEMOP_STSW,vaddr,r);
          return(res);  
   
3201        cpu->sw_pos += 8;        cpu->sw_pos += 8;
3202    
3203        if (cpu->sw_pos == 32)        if (cpu->sw_pos == 32)
# Line 3847  static struct ppc32_insn_exec_tag ppc32_ Line 3846  static struct ppc32_insn_exec_tag ppc32_
3846     { "tlbre"   , ppc32_exec_TLBRE      , 0xfc0007ff , 0x7c000764, 0 },     { "tlbre"   , ppc32_exec_TLBRE      , 0xfc0007ff , 0x7c000764, 0 },
3847     { "tlbwe"   , ppc32_exec_TLBWE      , 0xfc0007ff , 0x7c0007a4, 0 },     { "tlbwe"   , ppc32_exec_TLBWE      , 0xfc0007ff , 0x7c0007a4, 0 },
3848    
3849     { NULL      , NULL                  , 0x00000000 , 0x00000000, 0 },     /* Unknown opcode fallback */
3850       { "unknown" , ppc32_exec_unknown    , 0x00000000 , 0x00000000, 0 },
3851    
3852       { NULL      , NULL, 0, 0, 0 },
3853  };  };

Legend:
Removed from v.7  
changed lines
  Added in v.11

  ViewVC Help
Powered by ViewVC 1.1.26