/[gxemul]/trunk/src/cpus/cpu_ppc_instr.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/src/cpus/cpu_ppc_instr.c

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

revision 22 by dpavlin, Mon Oct 8 16:19:37 2007 UTC revision 44 by dpavlin, Mon Oct 8 16:22:56 2007 UTC
# Line 1  Line 1 
1  /*  /*
2   *  Copyright (C) 2005-2006  Anders Gavare.  All rights reserved.   *  Copyright (C) 2005-2007  Anders Gavare.  All rights reserved.
3   *   *
4   *  Redistribution and use in source and binary forms, with or without   *  Redistribution and use in source and binary forms, with or without
5   *  modification, are permitted provided that the following conditions are met:   *  modification, are permitted provided that the following conditions are met:
# Line 25  Line 25 
25   *  SUCH DAMAGE.   *  SUCH DAMAGE.
26   *   *
27   *   *
28   *  $Id: cpu_ppc_instr.c,v 1.59 2006/02/09 22:40:27 debug Exp $   *  $Id: cpu_ppc_instr.c,v 1.77 2007/06/28 13:36:47 debug Exp $
29   *   *
30   *  POWER/PowerPC instructions.   *  POWER/PowerPC instructions.
31   *   *
# Line 190  X(bclr) Line 190  X(bclr)
190                  cpu->cd.ppc.spr[SPR_CTR] --;                  cpu->cd.ppc.spr[SPR_CTR] --;
191          ctr_ok = (bo >> 2) & 1;          ctr_ok = (bo >> 2) & 1;
192          tmp = cpu->cd.ppc.spr[SPR_CTR];          tmp = cpu->cd.ppc.spr[SPR_CTR];
193          ctr_ok |= ( (tmp != 0) ^ ((bo >> 1) & 1) );          ctr_ok |= ( (tmp == 0) == ((bo >> 1) & 1) );
194          cond_ok = (bo >> 4) & 1;          cond_ok = (bo >> 4) & 1;
195          cond_ok |= ( ((bo >> 3) & 1) == ((cpu->cd.ppc.cr >> bi31m) & 1) );          cond_ok |= ( ((bo >> 3) & 1) == ((cpu->cd.ppc.cr >> bi31m) & 1) );
196          if (ctr_ok && cond_ok) {          if (ctr_ok && cond_ok) {
# Line 228  X(bclr_l) Line 228  X(bclr_l)
228                  cpu->cd.ppc.spr[SPR_CTR] --;                  cpu->cd.ppc.spr[SPR_CTR] --;
229          ctr_ok = (bo >> 2) & 1;          ctr_ok = (bo >> 2) & 1;
230          tmp = cpu->cd.ppc.spr[SPR_CTR];          tmp = cpu->cd.ppc.spr[SPR_CTR];
231          ctr_ok |= ( (tmp != 0) ^ ((bo >> 1) & 1) );          ctr_ok |= ( (tmp == 0) == ((bo >> 1) & 1) );
232          cond_ok = (bo >> 4) & 1;          cond_ok = (bo >> 4) & 1;
233          cond_ok |= ( ((bo >> 3) & 1) == ((cpu->cd.ppc.cr >> bi31m) & 1) );          cond_ok |= ( ((bo >> 3) & 1) == ((cpu->cd.ppc.cr >> bi31m) & 1) );
234    
# Line 272  X(bclr_l) Line 272  X(bclr_l)
272   */   */
273  X(bcctr)  X(bcctr)
274  {  {
275          unsigned int bo = ic->arg[0], bi31m = ic->arg[1]  /*,bh = ic->arg[2]*/;          unsigned int bo = ic->arg[0], bi31m = ic->arg[1];
276          uint64_t old_pc = cpu->pc;          uint64_t old_pc = cpu->pc;
277          MODE_uint_t addr = cpu->cd.ppc.spr[SPR_CTR];          MODE_uint_t addr = cpu->cd.ppc.spr[SPR_CTR];
278          int cond_ok = (bo >> 4) & 1;          int cond_ok = (bo >> 4) & 1;
# Line 369  X(bc) Line 369  X(bc)
369                  cpu->cd.ppc.spr[SPR_CTR] --;                  cpu->cd.ppc.spr[SPR_CTR] --;
370          ctr_ok = (bo >> 2) & 1;          ctr_ok = (bo >> 2) & 1;
371          tmp = cpu->cd.ppc.spr[SPR_CTR];          tmp = cpu->cd.ppc.spr[SPR_CTR];
372          ctr_ok |= ( (tmp != 0) ^ ((bo >> 1) & 1) );          ctr_ok |= ( (tmp == 0) == ((bo >> 1) & 1) );
373          cond_ok = (bo >> 4) & 1;          cond_ok = (bo >> 4) & 1;
374          cond_ok |= ( ((bo >> 3) & 1) ==          cond_ok |= ( ((bo >> 3) & 1) ==
375              ((cpu->cd.ppc.cr >> (bi31m)) & 1)  );              ((cpu->cd.ppc.cr >> (bi31m)) & 1)  );
# Line 393  X(bcl) Line 393  X(bcl)
393                  cpu->cd.ppc.spr[SPR_CTR] --;                  cpu->cd.ppc.spr[SPR_CTR] --;
394          ctr_ok = (bo >> 2) & 1;          ctr_ok = (bo >> 2) & 1;
395          tmp = cpu->cd.ppc.spr[SPR_CTR];          tmp = cpu->cd.ppc.spr[SPR_CTR];
396          ctr_ok |= ( (tmp != 0) ^ ((bo >> 1) & 1) );          ctr_ok |= ( (tmp == 0) == ((bo >> 1) & 1) );
397          cond_ok = (bo >> 4) & 1;          cond_ok = (bo >> 4) & 1;
398          cond_ok |= ( ((bo >> 3) & 1) ==          cond_ok |= ( ((bo >> 3) & 1) ==
399              ((cpu->cd.ppc.cr >> bi31m) & 1)  );              ((cpu->cd.ppc.cr >> bi31m) & 1)  );
# Line 428  X(bc_samepage) Line 428  X(bc_samepage)
428                  cpu->cd.ppc.spr[SPR_CTR] --;                  cpu->cd.ppc.spr[SPR_CTR] --;
429          ctr_ok = (bo >> 2) & 1;          ctr_ok = (bo >> 2) & 1;
430          tmp = cpu->cd.ppc.spr[SPR_CTR];          tmp = cpu->cd.ppc.spr[SPR_CTR];
431          ctr_ok |= ( (tmp != 0) ^ ((bo >> 1) & 1) );          ctr_ok |= ( (tmp == 0) == ((bo >> 1) & 1) );
432          cond_ok = (bo >> 4) & 1;          cond_ok = (bo >> 4) & 1;
433          cond_ok |= ( ((bo >> 3) & 1) ==          cond_ok |= ( ((bo >> 3) & 1) ==
434              ((cpu->cd.ppc.cr >> bi31m) & 1)  );              ((cpu->cd.ppc.cr >> bi31m) & 1)  );
# Line 464  X(bcl_samepage) Line 464  X(bcl_samepage)
464                  cpu->cd.ppc.spr[SPR_CTR] --;                  cpu->cd.ppc.spr[SPR_CTR] --;
465          ctr_ok = (bo >> 2) & 1;          ctr_ok = (bo >> 2) & 1;
466          tmp = cpu->cd.ppc.spr[SPR_CTR];          tmp = cpu->cd.ppc.spr[SPR_CTR];
467          ctr_ok |= ( (tmp != 0) ^ ((bo >> 1) & 1) );          ctr_ok |= ( (tmp == 0) == ((bo >> 1) & 1) );
468          cond_ok = (bo >> 4) & 1;          cond_ok = (bo >> 4) & 1;
469          cond_ok |= ( ((bo >> 3) & 1) ==          cond_ok |= ( ((bo >> 3) & 1) ==
470              ((cpu->cd.ppc.cr >> bi31m) & 1)  );              ((cpu->cd.ppc.cr >> bi31m) & 1)  );
# Line 987  X(frsp) Line 987  X(frsp)
987  X(fctiwz)  X(fctiwz)
988  {  {
989          struct ieee_float_value frb;          struct ieee_float_value frb;
990          int32_t res = 0;          uint32_t res = 0;
991    
992          CHECK_FOR_FPU_EXCEPTION;          CHECK_FOR_FPU_EXCEPTION;
993    
# Line 1411  X(mfsrin) Line 1411  X(mfsrin)
1411    
1412    
1413  /*  /*
1414     *  rldicl:
1415     *
1416     *  arg[0] = copy of the instruction word
1417     */
1418    X(rldicl)
1419    {
1420            int rs = (ic->arg[0] >> 21) & 31;
1421            int ra = (ic->arg[0] >> 16) & 31;
1422            int sh = ((ic->arg[0] >> 11) & 31) | ((ic->arg[0] & 2) << 4);
1423            int mb = ((ic->arg[0] >> 6) & 31) | (ic->arg[0] & 0x20);
1424            int rc = ic->arg[0] & 1;
1425            uint64_t tmp = cpu->cd.ppc.gpr[rs], tmp2;
1426            /*  TODO: Fix this, its performance is awful:  */
1427            while (sh-- != 0) {
1428                    int b = (tmp >> 63) & 1;
1429                    tmp = (tmp << 1) | b;
1430            }
1431            tmp2 = 0;
1432            while (mb <= 63) {
1433                    tmp |= ((uint64_t)1 << (63-mb));
1434                    mb ++;
1435            }
1436            cpu->cd.ppc.gpr[ra] = tmp & tmp2;
1437            if (rc)
1438                    update_cr0(cpu, cpu->cd.ppc.gpr[ra]);
1439    }
1440    
1441    
1442    /*
1443   *  rldicr:   *  rldicr:
1444   *   *
1445   *  arg[0] = copy of the instruction word   *  arg[0] = copy of the instruction word
# Line 1437  X(rldicr) Line 1466  X(rldicr)
1466    
1467    
1468  /*  /*
1469     *  rldimi:
1470     *
1471     *  arg[0] = copy of the instruction word
1472     */
1473    X(rldimi)
1474    {
1475            uint32_t iw = ic->arg[0];
1476            int rs = (iw >> 21) & 31, ra = (iw >> 16) & 31;
1477            int sh = ((iw >> 11) & 31) | ((iw & 2) << 4);
1478            int mb = ((iw >> 6) & 31) | (iw & 0x20);
1479            int rc = ic->arg[0] & 1;
1480            int m;
1481            uint64_t tmp, s = cpu->cd.ppc.gpr[rs];
1482            /*  TODO: Fix this, its performance is awful:  */
1483            while (sh-- != 0) {
1484                    int b = (s >> 63) & 1;
1485                    s = (s << 1) | b;
1486            }
1487            m = mb; tmp = 0;
1488            do {
1489                    tmp |= ((uint64_t)1 << (63-m));
1490                    m ++;
1491            } while (m != 63 - sh);
1492            cpu->cd.ppc.gpr[ra] &= ~tmp;
1493            cpu->cd.ppc.gpr[ra] |= (tmp & s);
1494            if (rc)
1495                    update_cr0(cpu, cpu->cd.ppc.gpr[ra]);
1496    }
1497    
1498    
1499    /*
1500   *  rlwnm:   *  rlwnm:
1501   *   *
1502   *  arg[0] = ptr to ra   *  arg[0] = ptr to ra
# Line 1673  X(mtctr) { Line 1733  X(mtctr) {
1733    
1734    
1735  /*  /*
1736   *  rfi:  Return from Interrupt   *  rfi[d]:  Return from Interrupt
1737   */   */
1738  X(rfi)  X(rfi)
1739  {  {
# Line 1687  X(rfi) Line 1747  X(rfi)
1747          cpu->pc = cpu->cd.ppc.spr[SPR_SRR0];          cpu->pc = cpu->cd.ppc.spr[SPR_SRR0];
1748          quick_pc_to_pointers(cpu);          quick_pc_to_pointers(cpu);
1749  }  }
1750    X(rfid)
1751    {
1752            uint64_t tmp, mask = 0x800000000000ff73ULL;
1753    
1754            reg_access_msr(cpu, &tmp, 0, 0);
1755            tmp &= ~mask;
1756            tmp |= (cpu->cd.ppc.spr[SPR_SRR1] & mask);
1757            reg_access_msr(cpu, &tmp, 1, 0);
1758    
1759            cpu->pc = cpu->cd.ppc.spr[SPR_SRR0];
1760            if (!(tmp & PPC_MSR_SF))
1761                    cpu->pc = (uint32_t)cpu->pc;
1762            quick_pc_to_pointers(cpu);
1763    }
1764    
1765    
1766  /*  /*
# Line 1715  X(mfmsr) Line 1789  X(mfmsr)
1789   *  mtmsr:  Move To MSR   *  mtmsr:  Move To MSR
1790   *   *
1791   *  arg[0] = pointer to source register   *  arg[0] = pointer to source register
1792     *  arg[1] = page offset of the next instruction
1793     *  arg[2] = 0 for 32-bit (mtmsr), 1 for 64-bit (mtmsrd)
1794   */   */
1795  X(mtmsr)  X(mtmsr)
1796  {  {
1797          MODE_uint_t old_pc;          MODE_uint_t old_pc;
1798            uint64_t x = reg(ic->arg[0]);
1799    
1800          /*  TODO: check permission!  */          /*  TODO: check permission!  */
1801    
# Line 1726  X(mtmsr) Line 1803  X(mtmsr)
1803          cpu->pc = (cpu->pc & ~0xfff) + ic->arg[1];          cpu->pc = (cpu->pc & ~0xfff) + ic->arg[1];
1804          old_pc = cpu->pc;          old_pc = cpu->pc;
1805    
1806          reg_access_msr(cpu, (uint64_t*)ic->arg[0], 1, 1);          if (!ic->arg[2]) {
1807                    uint64_t y;
1808                    reg_access_msr(cpu, &y, 0, 0);
1809                    x = (y & 0xffffffff00000000ULL) | (x & 0xffffffffULL);
1810            }
1811    
1812            reg_access_msr(cpu, &x, 1, 1);
1813    
1814          /*          /*
1815           *  Super-ugly hack:  If the pc wasn't changed (i.e. if there was no           *  Super-ugly hack:  If the pc wasn't changed (i.e. if there was no
# Line 1948  X(extsh) { Line 2031  X(extsh) {
2031  DOT2(extsh)  DOT2(extsh)
2032  X(extsw) {  X(extsw) {
2033  #ifdef MODE32  #ifdef MODE32
2034          fatal("TODO: extsw: invalid instruction\n"); exit(1);          fatal("TODO: extsw: invalid instruction\n");
2035  #else  #else
2036          reg(ic->arg[2]) = (int64_t)(int32_t)reg(ic->arg[0]);          reg(ic->arg[2]) = (int64_t)(int32_t)reg(ic->arg[0]);
2037  #endif  #endif
# Line 1957  DOT2(extsw) Line 2040  DOT2(extsw)
2040  X(slw) {        reg(ic->arg[2]) = (uint64_t)reg(ic->arg[0])  X(slw) {        reg(ic->arg[2]) = (uint64_t)reg(ic->arg[0])
2041                      << (reg(ic->arg[1]) & 31); }                      << (reg(ic->arg[1]) & 31); }
2042  DOT2(slw)  DOT2(slw)
2043    X(sld) {int sa = reg(ic->arg[1]) & 127;
2044            if (sa >= 64)   reg(ic->arg[2]) = 0;
2045            else reg(ic->arg[2]) = (uint64_t)reg(ic->arg[0]) << (sa & 63); }
2046    DOT2(sld)
2047  X(sraw)  X(sraw)
2048  {  {
2049          uint32_t tmp = reg(ic->arg[0]);          uint32_t tmp = reg(ic->arg[0]);
# Line 1995  X(orc) {       reg(ic->arg[2]) = reg(ic->arg[0 Line 2082  X(orc) {       reg(ic->arg[2]) = reg(ic->arg[0
2082  DOT2(orc)  DOT2(orc)
2083  X(xor) {        reg(ic->arg[2]) = reg(ic->arg[0]) ^ reg(ic->arg[1]); }  X(xor) {        reg(ic->arg[2]) = reg(ic->arg[0]) ^ reg(ic->arg[1]); }
2084  DOT2(xor)  DOT2(xor)
2085    X(eqv) {        reg(ic->arg[2]) = ~(reg(ic->arg[0]) ^ reg(ic->arg[1])); }
2086    DOT2(eqv)
2087    
2088    
2089  /*  /*
# Line 2384  X(stfdx) Line 2473  X(stfdx)
2473    
2474    
2475  /*  /*
2476     *  lvx, stvx:  Vector (16-byte) load/store  (slow implementation)
2477     *
2478     *  arg[0] = v-register nr of rs
2479     *  arg[1] = pointer to ra
2480     *  arg[2] = pointer to rb
2481     */
2482    X(lvx)
2483    {
2484            MODE_uint_t addr = reg(ic->arg[1]) + reg(ic->arg[2]);
2485            uint8_t data[16];
2486            uint64_t hi, lo;
2487            int rs = ic->arg[0];
2488    
2489            if (cpu->memory_rw(cpu, cpu->mem, addr, data, sizeof(data),
2490                MEM_READ, CACHE_DATA) != MEMORY_ACCESS_OK) {
2491                    /*  exception  */
2492                    return;
2493            }
2494    
2495            hi = ((uint64_t)data[0] << 56) +
2496                 ((uint64_t)data[1] << 48) +
2497                 ((uint64_t)data[2] << 40) +
2498                 ((uint64_t)data[3] << 32) +
2499                 ((uint64_t)data[4] << 24) +
2500                 ((uint64_t)data[5] << 16) +
2501                 ((uint64_t)data[6] << 8) +
2502                 ((uint64_t)data[7]);
2503            lo = ((uint64_t)data[8] << 56) +
2504                 ((uint64_t)data[9] << 48) +
2505                 ((uint64_t)data[10] << 40) +
2506                 ((uint64_t)data[11] << 32) +
2507                 ((uint64_t)data[12] << 24) +
2508                 ((uint64_t)data[13] << 16) +
2509                 ((uint64_t)data[14] << 8) +
2510                 ((uint64_t)data[15]);
2511    
2512            cpu->cd.ppc.vr_hi[rs] = hi; cpu->cd.ppc.vr_lo[rs] = lo;
2513    }
2514    X(stvx)
2515    {
2516            uint8_t data[16];
2517            MODE_uint_t addr = reg(ic->arg[1]) + reg(ic->arg[2]);
2518            int rs = ic->arg[0];
2519            uint64_t hi = cpu->cd.ppc.vr_hi[rs], lo = cpu->cd.ppc.vr_lo[rs];
2520    
2521            data[0] = hi >> 56;
2522            data[1] = hi >> 48;
2523            data[2] = hi >> 40;
2524            data[3] = hi >> 32;
2525            data[4] = hi >> 24;
2526            data[5] = hi >> 16;
2527            data[6] = hi >> 8;
2528            data[7] = hi;
2529            data[8] = lo >> 56;
2530            data[9] = lo >> 48;
2531            data[10] = lo >> 40;
2532            data[11] = lo >> 32;
2533            data[12] = lo >> 24;
2534            data[13] = lo >> 16;
2535            data[14] = lo >> 8;
2536            data[15] = lo;
2537    
2538            cpu->memory_rw(cpu, cpu->mem, addr, data,
2539                sizeof(data), MEM_WRITE, CACHE_DATA);
2540    }
2541    
2542    
2543    /*
2544     *  vxor:  Vector (16-byte) XOR
2545     *
2546     *  arg[0] = v-register nr of source 1
2547     *  arg[1] = v-register nr of source 2
2548     *  arg[2] = v-register nr of destination
2549     */
2550    X(vxor)
2551    {
2552            cpu->cd.ppc.vr_hi[ic->arg[2]] =
2553                cpu->cd.ppc.vr_hi[ic->arg[0]] ^ cpu->cd.ppc.vr_hi[ic->arg[1]];
2554            cpu->cd.ppc.vr_lo[ic->arg[2]] =
2555                cpu->cd.ppc.vr_lo[ic->arg[0]] ^ cpu->cd.ppc.vr_lo[ic->arg[1]];
2556    }
2557    
2558    
2559    /*
2560   *  tlbia:  TLB invalidate all   *  tlbia:  TLB invalidate all
2561   */   */
2562  X(tlbia)  X(tlbia)
2563  {  {
2564          printf("[ tlbia ]\n");          fatal("[ tlbia ]\n");
2565          cpu->invalidate_translation_caches(cpu, 0, INVALIDATE_ALL);          cpu->invalidate_translation_caches(cpu, 0, INVALIDATE_ALL);
2566  }  }
2567    
# Line 2398  X(tlbia) Line 2571  X(tlbia)
2571   */   */
2572  X(tlbie)  X(tlbie)
2573  {  {
2574            /*  fatal("[ tlbie ]\n");  */
2575          cpu->invalidate_translation_caches(cpu, reg(ic->arg[0]),          cpu->invalidate_translation_caches(cpu, reg(ic->arg[0]),
2576              INVALIDATE_VADDR);              INVALIDATE_VADDR);
2577  }  }
# Line 2426  X(sc) Line 2600  X(sc)
2600  X(user_syscall)  X(user_syscall)
2601  {  {
2602          useremul_syscall(cpu, ic->arg[0]);          useremul_syscall(cpu, ic->arg[0]);
2603    
2604            if (!cpu->running) {
2605                    cpu->n_translated_instrs --;
2606                    cpu->cd.ppc.next_ic = &nothing_call;
2607            }
2608  }  }
2609    
2610    
# Line 2436  X(openfirmware) Line 2615  X(openfirmware)
2615  {  {
2616          of_emul(cpu);          of_emul(cpu);
2617          if (cpu->running == 0) {          if (cpu->running == 0) {
2618                  cpu->running_translated = 0;                  cpu->n_translated_instrs --;
2619                    cpu->cd.ppc.next_ic = &nothing_call;
2620          }          }
2621          cpu->pc = cpu->cd.ppc.spr[SPR_LR];          cpu->pc = cpu->cd.ppc.spr[SPR_LR];
2622          if (cpu->machine->show_trace_tree)          if (cpu->machine->show_trace_tree)
# Line 2503  X(end_of_page) Line 2683  X(end_of_page)
2683  /*  /*
2684   *  ppc_instr_to_be_translated():   *  ppc_instr_to_be_translated():
2685   *   *
2686   *  Translate an instruction word into an ppc_instr_call. ic is filled in with   *  Translate an instruction word into a ppc_instr_call. ic is filled in with
2687   *  valid data for the translated instruction, or a "nothing" instruction if   *  valid data for the translated instruction, or a "nothing" instruction if
2688   *  there was a translation failure. The newly translated instruction is then   *  there was a translation failure. The newly translated instruction is then
2689   *  executed.   *  executed.
# Line 2514  X(to_be_translated) Line 2694  X(to_be_translated)
2694          uint32_t iword, mask;          uint32_t iword, mask;
2695          unsigned char *page;          unsigned char *page;
2696          unsigned char ib[4];          unsigned char ib[4];
 #ifdef DYNTRANS_BACKEND  
         int simple = 0;  
 #endif  
2697          int main_opcode, rt, rs, ra, rb, rc, aa_bit, l_bit, lk_bit, spr, sh,          int main_opcode, rt, rs, ra, rb, rc, aa_bit, l_bit, lk_bit, spr, sh,
2698              xo, imm, load, size, update, zero, bf, bo, bi, bh, oe_bit, n64=0,              xo, imm, load, size, update, zero, bf, bo, bi, bh, oe_bit, n64=0,
2699              bfa, fp, byterev, nb, mb, me;              bfa, fp, byterev, nb, mb, me;
# Line 2533  X(to_be_translated) Line 2710  X(to_be_translated)
2710          addr &= ~((1 << PPC_INSTR_ALIGNMENT_SHIFT) - 1);          addr &= ~((1 << PPC_INSTR_ALIGNMENT_SHIFT) - 1);
2711    
2712          /*  Read the instruction word from memory:  */          /*  Read the instruction word from memory:  */
2713          page = cpu->cd.ppc.host_load[addr >> 12];  #ifdef MODE32
2714            page = cpu->cd.ppc.host_load[((uint32_t)addr) >> 12];
2715    #else
2716            {
2717                    const uint32_t mask1 = (1 << DYNTRANS_L1N) - 1;
2718                    const uint32_t mask2 = (1 << DYNTRANS_L2N) - 1;
2719                    const uint32_t mask3 = (1 << DYNTRANS_L3N) - 1;
2720                    uint32_t x1 = (addr >> (64-DYNTRANS_L1N)) & mask1;
2721                    uint32_t x2 = (addr >> (64-DYNTRANS_L1N-DYNTRANS_L2N)) & mask2;
2722                    uint32_t x3 = (addr >> (64-DYNTRANS_L1N-DYNTRANS_L2N-
2723                        DYNTRANS_L3N)) & mask3;
2724                    struct DYNTRANS_L2_64_TABLE *l2 = cpu->cd.ppc.l1_64[x1];
2725                    struct DYNTRANS_L3_64_TABLE *l3 = l2->l3[x2];
2726                    page = l3->host_load[x3];
2727            }
2728    #endif
2729    
2730          if (page != NULL) {          if (page != NULL) {
2731                  /*  fatal("TRANSLATION HIT!\n");  */                  /*  fatal("TRANSLATION HIT!\n");  */
# Line 2567  X(to_be_translated) Line 2759  X(to_be_translated)
2759          switch (main_opcode) {          switch (main_opcode) {
2760    
2761          case 0x04:          case 0x04:
2762                  fatal("[ TODO: ALTIVEC ]\n");                  if (iword == 0x12739cc4) {
2763                  ic->f = instr(nop);                          /*  vxor v19,v19,v19  */
2764                            ic->f = instr(vxor);
2765                            ic->arg[0] = 19;
2766                            ic->arg[1] = 19;
2767                            ic->arg[2] = 19;
2768                    } else {
2769                            if (!cpu->translation_readahead)
2770                                    fatal("[ TODO: Unimplemented ALTIVEC, iword"
2771                                        " = 0x%08"PRIx32"x ]\n", iword);
2772                            goto bad;
2773                    }
2774                  break;                  break;
2775    
2776          case PPC_HI6_MULLI:          case PPC_HI6_MULLI:
# Line 2621  X(to_be_translated) Line 2823  X(to_be_translated)
2823          case PPC_HI6_ADDIC:          case PPC_HI6_ADDIC:
2824          case PPC_HI6_ADDIC_DOT:          case PPC_HI6_ADDIC_DOT:
2825                  if (cpu->cd.ppc.bits == 64) {                  if (cpu->cd.ppc.bits == 64) {
2826                          fatal("addic for 64-bit: TODO\n");                          if (!cpu->translation_readahead)
2827                                    fatal("addic for 64-bit: TODO\n");
2828                          goto bad;                          goto bad;
2829                  }                  }
2830                  rt = (iword >> 21) & 31;                  rt = (iword >> 21) & 31;
# Line 2689  X(to_be_translated) Line 2892  X(to_be_translated)
2892          case PPC_HI6_LHAU:          case PPC_HI6_LHAU:
2893          case PPC_HI6_LWZ:          case PPC_HI6_LWZ:
2894          case PPC_HI6_LWZU:          case PPC_HI6_LWZU:
2895            case PPC_HI6_LD:
2896          case PPC_HI6_LFD:          case PPC_HI6_LFD:
2897          case PPC_HI6_LFS:          case PPC_HI6_LFS:
2898          case PPC_HI6_STB:          case PPC_HI6_STB:
# Line 2697  X(to_be_translated) Line 2901  X(to_be_translated)
2901          case PPC_HI6_STHU:          case PPC_HI6_STHU:
2902          case PPC_HI6_STW:          case PPC_HI6_STW:
2903          case PPC_HI6_STWU:          case PPC_HI6_STWU:
2904            case PPC_HI6_STD:
2905          case PPC_HI6_STFD:          case PPC_HI6_STFD:
2906          case PPC_HI6_STFS:          case PPC_HI6_STFS:
2907                  rs = (iword >> 21) & 31;                  rs = (iword >> 21) & 31;
# Line 2713  X(to_be_translated) Line 2918  X(to_be_translated)
2918                  case PPC_HI6_LHZU: load=1; size=1; update=1; break;                  case PPC_HI6_LHZU: load=1; size=1; update=1; break;
2919                  case PPC_HI6_LWZ:  load=1; size=2; break;                  case PPC_HI6_LWZ:  load=1; size=2; break;
2920                  case PPC_HI6_LWZU: load=1; size=2; update=1; break;                  case PPC_HI6_LWZU: load=1; size=2; update=1; break;
2921                    case PPC_HI6_LD:   load=1; size=3; break;
2922                  case PPC_HI6_LFD:  load=1; size=3; fp=1;ic->f=instr(lfd);break;                  case PPC_HI6_LFD:  load=1; size=3; fp=1;ic->f=instr(lfd);break;
2923                  case PPC_HI6_LFS:  load=1; size=2; fp=1;ic->f=instr(lfs);break;                  case PPC_HI6_LFS:  load=1; size=2; fp=1;ic->f=instr(lfs);break;
2924                  case PPC_HI6_STB:  break;                  case PPC_HI6_STB:  break;
# Line 2721  X(to_be_translated) Line 2927  X(to_be_translated)
2927                  case PPC_HI6_STHU: size=1; update=1; break;                  case PPC_HI6_STHU: size=1; update=1; break;
2928                  case PPC_HI6_STW:  size=2; break;                  case PPC_HI6_STW:  size=2; break;
2929                  case PPC_HI6_STWU: size=2; update=1; break;                  case PPC_HI6_STWU: size=2; update=1; break;
2930                    case PPC_HI6_STD:  size=3; break;
2931                  case PPC_HI6_STFD: size=3; fp=1; ic->f = instr(stfd); break;                  case PPC_HI6_STFD: size=3; fp=1; ic->f = instr(stfd); break;
2932                  case PPC_HI6_STFS: size=2; fp=1; ic->f = instr(stfs); break;                  case PPC_HI6_STFS: size=2; fp=1; ic->f = instr(stfs); break;
2933                  }                  }
# Line 2735  X(to_be_translated) Line 2942  X(to_be_translated)
2942                              + 32*update];                              + 32*update];
2943                  }                  }
2944                  if (ra == 0 && update) {                  if (ra == 0 && update) {
2945                          fatal("TODO: ra=0 && update?\n");                          if (!cpu->translation_readahead)
2946                                    fatal("TODO: ra=0 && update?\n");
2947                          goto bad;                          goto bad;
2948                  }                  }
2949                  if (fp)                  if (fp)
# Line 2756  X(to_be_translated) Line 2964  X(to_be_translated)
2964                  bi = (iword >> 16) & 31;                  bi = (iword >> 16) & 31;
2965                  tmp_addr = (int64_t)(int16_t)(iword & 0xfffc);                  tmp_addr = (int64_t)(int16_t)(iword & 0xfffc);
2966                  if (aa_bit) {                  if (aa_bit) {
2967                          fatal("aa_bit: NOT YET\n");                          if (!cpu->translation_readahead)
2968                                    fatal("aa_bit: NOT YET\n");
2969                          goto bad;                          goto bad;
2970                  }                  }
2971                  if (lk_bit) {                  if (lk_bit) {
# Line 2871  X(to_be_translated) Line 3080  X(to_be_translated)
3080                                                  ic->f = instr(bclr_20);                                                  ic->f = instr(bclr_20);
3081                                  }                                  }
3082                          } else {                          } else {
3083                                    if (!(bo & 4)) {
3084                                            if (!cpu->translation_readahead)
3085                                                    fatal("TODO: bclr/bcctr "
3086                                                        "bo bit 2 clear!\n");
3087                                            goto bad;
3088                                    }
3089                                  if (lk_bit)                                  if (lk_bit)
3090                                          ic->f = instr(bcctr_l);                                          ic->f = instr(bcctr_l);
3091                                  else                                  else
# Line 2890  X(to_be_translated) Line 3105  X(to_be_translated)
3105                          ic->f = instr(rfi);                          ic->f = instr(rfi);
3106                          break;                          break;
3107    
3108                    case PPC_19_RFID:
3109                            ic->f = instr(rfid);
3110                            break;
3111    
3112                  case PPC_19_MCRF:                  case PPC_19_MCRF:
3113                          bf = (iword >> 23) & 7;                          bf = (iword >> 23) & 7;
3114                          bfa = (iword >> 18) & 7;                          bfa = (iword >> 18) & 7;
# Line 2979  X(to_be_translated) Line 3198  X(to_be_translated)
3198                  xo = (iword >> 2) & 7;                  xo = (iword >> 2) & 7;
3199                  switch (xo) {                  switch (xo) {
3200    
3201                    case PPC_30_RLDICL:
3202                  case PPC_30_RLDICR:                  case PPC_30_RLDICR:
3203                          ic->f = instr(rldicr);                  case PPC_30_RLDIMI:
3204                            switch (xo) {
3205                            case PPC_30_RLDICL: ic->f = instr(rldicl); break;
3206                            case PPC_30_RLDICR: ic->f = instr(rldicr); break;
3207                            case PPC_30_RLDIMI: ic->f = instr(rldimi); break;
3208                            }
3209                          ic->arg[0] = iword;                          ic->arg[0] = iword;
3210                          if (cpu->cd.ppc.bits == 32) {                          if (cpu->cd.ppc.bits == 32) {
3211                                  fatal("TODO: rldicr in 32-bit mode?\n");                                  if (!cpu->translation_readahead)
3212                                            fatal("TODO: rld* in 32-bit mode?\n");
3213                                  goto bad;                                  goto bad;
3214                          }                          }
3215                          break;                          break;
# Line 3027  X(to_be_translated) Line 3253  X(to_be_translated)
3253                          ra = (iword >> 16) & 31;                          ra = (iword >> 16) & 31;
3254                          rc = iword & 1;                          rc = iword & 1;
3255                          if (rc) {                          if (rc) {
3256                                  fatal("TODO: rc\n");                                  if (!cpu->translation_readahead)
3257                                            fatal("TODO: rc\n");
3258                                  goto bad;                                  goto bad;
3259                          }                          }
3260                          ic->arg[0] = (size_t)(&cpu->cd.ppc.gpr[rs]);                          ic->arg[0] = (size_t)(&cpu->cd.ppc.gpr[rs]);
# Line 3077  X(to_be_translated) Line 3304  X(to_be_translated)
3304                          break;                          break;
3305    
3306                  case PPC_31_MTMSR:                  case PPC_31_MTMSR:
3307                    case PPC_31_MTMSRD:
3308                          rs = (iword >> 21) & 31;                          rs = (iword >> 21) & 31;
3309                          l_bit = (iword >> 16) & 1;                          l_bit = (iword >> 16) & 1;
3310                          if (l_bit) {                          if (l_bit) {
3311                                  fatal("TODO: mtmsr l-bit\n");                                  if (!cpu->translation_readahead)
3312                                            fatal("TODO: mtmsr l-bit\n");
3313                                  goto bad;                                  goto bad;
3314                          }                          }
3315                          ic->arg[0] = (size_t)(&cpu->cd.ppc.gpr[rs]);                          ic->arg[0] = (size_t)(&cpu->cd.ppc.gpr[rs]);
3316                          ic->arg[1] = (addr & 0xfff) + 4;                          ic->arg[1] = (addr & 0xfff) + 4;
3317                            ic->arg[2] = xo == PPC_31_MTMSRD;
3318                          ic->f = instr(mtmsr);                          ic->f = instr(mtmsr);
3319                          break;                          break;
3320    
# Line 3115  X(to_be_translated) Line 3345  X(to_be_translated)
3345                          case PPC_31_MTSRIN: ic->f = instr(mtsrin); break;                          case PPC_31_MTSRIN: ic->f = instr(mtsrin); break;
3346                          }                          }
3347                          if (cpu->cd.ppc.bits == 64) {                          if (cpu->cd.ppc.bits == 64) {
3348                                  fatal("Not yet for 64-bit mode\n");                                  if (!cpu->translation_readahead)
3349                                            fatal("Not yet for 64-bit mode\n");
3350                                  goto bad;                                  goto bad;
3351                          }                          }
3352                          break;                          break;
# Line 3130  X(to_be_translated) Line 3361  X(to_be_translated)
3361                          case PPC_31_MTSR:   ic->f = instr(mtsr); break;                          case PPC_31_MTSR:   ic->f = instr(mtsr); break;
3362                          }                          }
3363                          if (cpu->cd.ppc.bits == 64) {                          if (cpu->cd.ppc.bits == 64) {
3364                                  fatal("Not yet for 64-bit mode\n");                                  if (!cpu->translation_readahead)
3365                                            fatal("Not yet for 64-bit mode\n");
3366                                  goto bad;                                  goto bad;
3367                          }                          }
3368                          break;                          break;
# Line 3150  X(to_be_translated) Line 3382  X(to_be_translated)
3382                          break;                          break;
3383    
3384                  case PPC_31_SYNC:                  case PPC_31_SYNC:
3385                    case PPC_31_DSSALL:
3386                  case PPC_31_EIEIO:                  case PPC_31_EIEIO:
3387                  case PPC_31_DCBST:                  case PPC_31_DCBST:
3388                  case PPC_31_DCBTST:                  case PPC_31_DCBTST:
# Line 3214  X(to_be_translated) Line 3447  X(to_be_translated)
3447                          switch (spr) {                          switch (spr) {
3448                          case 268: ic->f = instr(mftb); break;                          case 268: ic->f = instr(mftb); break;
3449                          case 269: ic->f = instr(mftbu); break;                          case 269: ic->f = instr(mftbu); break;
3450                          default:fatal("mftb spr=%i?\n", spr);                          default:if (!cpu->translation_readahead)
3451                                            fatal("mftb spr=%i?\n", spr);
3452                                  goto bad;                                  goto bad;
3453                          }                          }
3454                          break;                          break;
# Line 3349  X(to_be_translated) Line 3583  X(to_be_translated)
3583                                      [size + 4*zero + 8*load + 16*update];                                      [size + 4*zero + 8*load + 16*update];
3584                          }                          }
3585                          if (ra == 0 && update) {                          if (ra == 0 && update) {
3586                                  fatal("TODO: ra=0 && update?\n");                                  if (!cpu->translation_readahead)
3587                                            fatal("TODO: ra=0 && update?\n");
3588                                  goto bad;                                  goto bad;
3589                          }                          }
3590                          break;                          break;
# Line 3358  X(to_be_translated) Line 3593  X(to_be_translated)
3593                  case PPC_31_EXTSH:                  case PPC_31_EXTSH:
3594                  case PPC_31_EXTSW:                  case PPC_31_EXTSW:
3595                  case PPC_31_SLW:                  case PPC_31_SLW:
3596                    case PPC_31_SLD:
3597                  case PPC_31_SRAW:                  case PPC_31_SRAW:
3598                  case PPC_31_SRW:                  case PPC_31_SRW:
3599                  case PPC_31_AND:                  case PPC_31_AND:
# Line 3367  X(to_be_translated) Line 3603  X(to_be_translated)
3603                  case PPC_31_OR:                  case PPC_31_OR:
3604                  case PPC_31_ORC:                  case PPC_31_ORC:
3605                  case PPC_31_XOR:                  case PPC_31_XOR:
3606                    case PPC_31_EQV:
3607                          rs = (iword >> 21) & 31;                          rs = (iword >> 21) & 31;
3608                          ra = (iword >> 16) & 31;                          ra = (iword >> 16) & 31;
3609                          rb = (iword >> 11) & 31;                          rb = (iword >> 11) & 31;
# Line 3381  X(to_be_translated) Line 3618  X(to_be_translated)
3618                                            rc_f  = instr(extsw_dot); break;                                            rc_f  = instr(extsw_dot); break;
3619                          case PPC_31_SLW:  ic->f = instr(slw);                          case PPC_31_SLW:  ic->f = instr(slw);
3620                                            rc_f  = instr(slw_dot); break;                                            rc_f  = instr(slw_dot); break;
3621                            case PPC_31_SLD:  ic->f = instr(sld);
3622                                              rc_f  = instr(sld_dot); break;
3623                          case PPC_31_SRAW: ic->f = instr(sraw);                          case PPC_31_SRAW: ic->f = instr(sraw);
3624                                            rc_f  = instr(sraw_dot); break;                                            rc_f  = instr(sraw_dot); break;
3625                          case PPC_31_SRW:  ic->f = instr(srw);                          case PPC_31_SRW:  ic->f = instr(srw);
# Line 3400  X(to_be_translated) Line 3639  X(to_be_translated)
3639                                            rc_f  = instr(orc_dot); break;                                            rc_f  = instr(orc_dot); break;
3640                          case PPC_31_XOR:  ic->f = instr(xor);                          case PPC_31_XOR:  ic->f = instr(xor);
3641                                            rc_f  = instr(xor_dot); break;                                            rc_f  = instr(xor_dot); break;
3642                            case PPC_31_EQV:  ic->f = instr(eqv);
3643                                              rc_f  = instr(eqv_dot); break;
3644                          }                          }
3645                          ic->arg[0] = (size_t)(&cpu->cd.ppc.gpr[rs]);                          ic->arg[0] = (size_t)(&cpu->cd.ppc.gpr[rs]);
3646                          ic->arg[1] = (size_t)(&cpu->cd.ppc.gpr[rb]);                          ic->arg[1] = (size_t)(&cpu->cd.ppc.gpr[rb]);
# Line 3429  X(to_be_translated) Line 3670  X(to_be_translated)
3670                          oe_bit = (iword >> 10) & 1;                          oe_bit = (iword >> 10) & 1;
3671                          rc = iword & 1;                          rc = iword & 1;
3672                          if (oe_bit) {                          if (oe_bit) {
3673                                  fatal("oe_bit not yet implemented\n");                                  if (!cpu->translation_readahead)
3674                                            fatal("oe_bit not yet implemented\n");
3675                                  goto bad;                                  goto bad;
3676                          }                          }
3677                          switch (xo) {                          switch (xo) {
# Line 3479  X(to_be_translated) Line 3721  X(to_be_translated)
3721                                          ic->f = instr(subfme_dot); break;                                          ic->f = instr(subfme_dot); break;
3722                                  case PPC_31_SUBFZE:                                  case PPC_31_SUBFZE:
3723                                          ic->f = instr(subfze_dot); break;                                          ic->f = instr(subfze_dot); break;
3724                                  default:fatal("RC bit not yet implemented\n");                                  default:if (!cpu->translation_readahead)
3725                                                    fatal("RC bit not yet "
3726                                                        "implemented\n");
3727                                          goto bad;                                          goto bad;
3728                                  }                                  }
3729                          }                          }
# Line 3487  X(to_be_translated) Line 3731  X(to_be_translated)
3731                          ic->arg[1] = (size_t)(&cpu->cd.ppc.gpr[rb]);                          ic->arg[1] = (size_t)(&cpu->cd.ppc.gpr[rb]);
3732                          ic->arg[2] = (size_t)(&cpu->cd.ppc.gpr[rt]);                          ic->arg[2] = (size_t)(&cpu->cd.ppc.gpr[rt]);
3733                          if (cpu->cd.ppc.bits == 64 && n64) {                          if (cpu->cd.ppc.bits == 64 && n64) {
3734                                  fatal("Not yet for 64-bit mode\n");                                  if (!cpu->translation_readahead)
3735                                            fatal("Not yet for 64-bit mode\n");
3736                                  goto bad;                                  goto bad;
3737                          }                          }
3738                          break;                          break;
3739    
                 case 359:  
                         fatal("[ TODO: 359 ]\n");  
                         ic->f = instr(nop);  
                         break;  
3740                  case PPC_31_LVX:                  case PPC_31_LVX:
3741                          fatal("[ TODO: lvx ]\n");                  case PPC_31_LVXL:
                         ic->f = instr(nop);  
                         break;  
3742                  case PPC_31_STVX:                  case PPC_31_STVX:
                         fatal("[ TODO: stvx ]\n");  
                         ic->f = instr(nop);  
                         break;  
3743                  case PPC_31_STVXL:                  case PPC_31_STVXL:
3744                          fatal("[ TODO: stvxl ]\n");                          load = 0;
3745                          ic->f = instr(nop);                          switch (xo) {
3746                            case PPC_31_LVX:
3747                            case PPC_31_LVXL:
3748                                    load = 1; break;
3749                            }
3750                            rs = (iword >> 21) & 31;
3751                            ra = (iword >> 16) & 31;
3752                            rb = (iword >> 11) & 31;
3753                            ic->arg[0] = rs;
3754                            if (ra == 0)
3755                                    ic->arg[1] = (size_t)(&cpu->cd.ppc.zero);
3756                            else
3757                                    ic->arg[1] = (size_t)(&cpu->cd.ppc.gpr[ra]);
3758                            ic->arg[2] = (size_t)(&cpu->cd.ppc.gpr[rb]);
3759                            ic->f = load? instr(lvx) : instr(stvx);
3760                          break;                          break;
3761    
3762                  default:goto bad;                  default:goto bad;
# Line 3522  X(to_be_translated) Line 3772  X(to_be_translated)
3772                  rc = iword & 1;                  rc = iword & 1;
3773    
3774                  if (rc) {                  if (rc) {
3775                          fatal("Floating point (59) with rc bit! TODO\n");                          if (!cpu->translation_readahead)
3776                                    fatal("Floating point (59) "
3777                                        "with rc bit! TODO\n");
3778                          goto bad;                          goto bad;
3779                  }                  }
3780    
# Line 3563  X(to_be_translated) Line 3815  X(to_be_translated)
3815                  rc = iword & 1;                  rc = iword & 1;
3816    
3817                  if (rc) {                  if (rc) {
3818                          fatal("Floating point (63) with rc bit! TODO\n");                          if (!cpu->translation_readahead)
3819                                    fatal("Floating point (63) "
3820                                        "with rc bit! TODO\n");
3821                          goto bad;                          goto bad;
3822                  }                  }
3823    

Legend:
Removed from v.22  
changed lines
  Added in v.44

  ViewVC Help
Powered by ViewVC 1.1.26