Revision 1a14026e linux-user/main.c

b/linux-user/main.c
626 626
   can be found at http://www.sics.se/~psm/sparcstack.html */
627 627
static inline int get_reg_index(CPUSPARCState *env, int cwp, int index)
628 628
{
629
    index = (index + cwp * 16) & (16 * NWINDOWS - 1);
629
    index = (index + cwp * 16) % (16 * env->nwindows);
630 630
    /* wrap handling : if cwp is on the last window, then we use the
631 631
       registers 'after' the end */
632
    if (index < 8 && env->cwp == (NWINDOWS - 1))
633
        index += (16 * NWINDOWS);
632
    if (index < 8 && env->cwp == env->nwindows - 1)
633
        index += 16 * env->nwindows;
634 634
    return index;
635 635
}
636 636

  
......
656 656
{
657 657
#ifndef TARGET_SPARC64
658 658
    unsigned int new_wim;
659
    new_wim = ((env->wim >> 1) | (env->wim << (NWINDOWS - 1))) &
660
        ((1LL << NWINDOWS) - 1);
661
    save_window_offset(env, (env->cwp - 2) & (NWINDOWS - 1));
659
    new_wim = ((env->wim >> 1) | (env->wim << (env->nwindows - 1))) &
660
        ((1LL << env->nwindows) - 1);
661
    save_window_offset(env, cpu_cwp_dec(env, env->cwp - 2));
662 662
    env->wim = new_wim;
663 663
#else
664
    save_window_offset(env, (env->cwp - 2) & (NWINDOWS - 1));
664
    save_window_offset(env, cpu_cwp_dec(env, env->cwp - 2));
665 665
    env->cansave++;
666 666
    env->canrestore--;
667 667
#endif
......
672 672
    unsigned int new_wim, i, cwp1;
673 673
    abi_ulong sp_ptr;
674 674

  
675
    new_wim = ((env->wim << 1) | (env->wim >> (NWINDOWS - 1))) &
676
        ((1LL << NWINDOWS) - 1);
675
    new_wim = ((env->wim << 1) | (env->wim >> (env->nwindows - 1))) &
676
        ((1LL << env->nwindows) - 1);
677 677

  
678 678
    /* restore the invalid window */
679
    cwp1 = (env->cwp + 1) & (NWINDOWS - 1);
679
    cwp1 = cpu_cwp_inc(env, env->cwp + 1);
680 680
    sp_ptr = env->regbase[get_reg_index(env, cwp1, 6)];
681 681
#if defined(DEBUG_WIN)
682 682
    printf("win_underflow: sp_ptr=0x%x load_cwp=%d\n",
......
690 690
    env->wim = new_wim;
691 691
#ifdef TARGET_SPARC64
692 692
    env->canrestore++;
693
    if (env->cleanwin < NWINDOWS - 1)
694
	env->cleanwin++;
693
    if (env->cleanwin < env->nwindows - 1)
694
        env->cleanwin++;
695 695
    env->cansave--;
696 696
#endif
697 697
}
......
703 703
    offset = 1;
704 704
    for(;;) {
705 705
        /* if restore would invoke restore_window(), then we can stop */
706
        cwp1 = (env->cwp + offset) & (NWINDOWS - 1);
706
        cwp1 = cpu_cwp_inc(env, env->cwp + offset);
707 707
        if (env->wim & (1 << cwp1))
708 708
            break;
709 709
        save_window_offset(env, cwp1);
710 710
        offset++;
711 711
    }
712 712
    /* set wim so that restore will reload the registers */
713
    cwp1 = (env->cwp + 1) & (NWINDOWS - 1);
713
    cwp1 = cpu_cwp_inc(env, env->cwp + 1);
714 714
    env->wim = 1 << cwp1;
715 715
#if defined(DEBUG_WIN)
716 716
    printf("flush_windows: nb=%d\n", offset - 1);

Also available in: Unified diff