OpenCores
URL https://opencores.org/ocsvn/zipcpu/zipcpu/trunk

Subversion Repositories zipcpu

[/] [zipcpu/] [trunk/] [sw/] [zasm/] [zopcodes.cpp] - Diff between revs 69 and 70

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 69 Rev 70
Line 503... Line 503...
static  int     getbits(const ZIPI ins, const int which) {
static  int     getbits(const ZIPI ins, const int which) {
        if (which & 0x40000000) {
        if (which & 0x40000000) {
                // printf("SBITS: %08x, %08x = %08lx\n", ins, which,
                // printf("SBITS: %08x, %08x = %08lx\n", ins, which,
                        // sbits(ins>>(which & 0x03f), (which>>8)&0x03f));
                        // sbits(ins>>(which & 0x03f), (which>>8)&0x03f));
                return sbits(ins>>(which & 0x03f), (which>>8)&0x03f);
                return sbits(ins>>(which & 0x03f), (which>>8)&0x03f);
        } else if (which &0x03f) {
        } else { // if (which &0x03f)
                return ubits(ins>>(which & 0x03f), (which>>8)&0x03f)
                return ubits(ins>>(which & 0x03f), (which>>8)&0x03f)
                        + ((which>>16)&0x0ff);
                        + ((which>>16)&0x0ff);
        } else
        // } else {
                return which;
                // fprintf(stderr, "Returning an uncoded %08x\n", which);
 
                // return which;
 
        }
}
}
 
 
void    zipi_to_string(const ZIPI ins, char *line) {
static  void static_zipi_to_string(const ZIPI ins, char *line, const ZOPCODE *listp) {
        for(int i=0; i<nzoplist; i++) {
        for(int i=0; i<nzoplist; i++) {
                if (((~zoplist[i].s_mask)&zoplist[i].s_val)!=0) {
                if (((~zoplist[i].s_mask)&zoplist[i].s_val)!=0) {
                        printf("Instruction %d, %s, fails consistency check\n",
                        printf("Instruction %d, %s, fails consistency check\n",
                                i, zoplist[i].s_opstr);
                                i, zoplist[i].s_opstr);
                        assert(((~zoplist[i].s_mask)&zoplist[i].s_val)==0);
                        assert(((~zoplist[i].s_mask)&zoplist[i].s_val)==0);
                }
                }
        }
        } line[0] = '\0';
        for(int i=0; i<nzoplist; i++) {
        for(int i=0; (listp[i].s_mask != 0); i++) {
                // printf("%2d: %6s %08x & %08x == %08x\n",
                // printf("%2d: %6s %08x & %08x == %08x\n",
                        // i, zoplist[i].s_opstr, ins,
                        // i, zoplist[i].s_opstr, ins,
                        // zoplist[i].s_mask, zoplist[i].s_val);
                        // zoplist[i].s_mask, zoplist[i].s_val);
                if ((ins & zoplist[i].s_mask) == zoplist[i].s_val) {
                if ((ins & listp[i].s_mask) == listp[i].s_val) {
                        sprintf(line, "  %s", zoplist[i].s_opstr);
                        sprintf(line, "%s", listp[i].s_opstr);
                        if (zoplist[i].s_cf != OPUNUSED) {
                        if (listp[i].s_cf != OPUNUSED) {
                                int bv = getbits(ins, zoplist[i].s_cf);
                                int bv = getbits(ins, listp[i].s_cf);
                                strcat(line, zop_ccstr[bv]);
                                strcat(line, zop_ccstr[bv]);
                        } sprintf(line, "%-13s", line);
                        } sprintf(line, "%-11s", line);
 
 
                        // Treat stores special
                        // Treat stores special
                        if (strncasecmp("STO",zoplist[i].s_opstr, 3)==0) {
                        if (strncasecmp("STO",listp[i].s_opstr, 3)==0) {
                                int ra = getbits(ins, zoplist[i].s_ra);
                                int ra = getbits(ins, listp[i].s_ra);
                                strcat(line, zop_regstr[ra]);
                                strcat(line, zop_regstr[ra]);
                                strcat(line, ",");
                                strcat(line, ",");
 
 
                                if (zoplist[i].s_i != OPUNUSED) {
                                if (listp[i].s_i != OPUNUSED) {
                                        int     imv = 0;
                                        int     imv = 0;
                                        imv = getbits(ins, zoplist[i].s_i);
                                        imv = getbits(ins, listp[i].s_i);
                                        if ((imv != 0)&&(zoplist[i].s_rb != OPUNUSED))
                                        if ((imv != 0)&&(listp[i].s_rb != OPUNUSED))
                                                sprintf(&line[strlen(line)],
                                                sprintf(&line[strlen(line)],
                                                        "$%d", imv);
                                                        "$%d", imv);
                                        else if (imv != 0)
                                        else if (imv != 0)
                                                sprintf(&line[strlen(line)],
                                                sprintf(&line[strlen(line)],
                                                        "($%d)", imv);
                                                        "($%d)", imv);
                                } if (zoplist[i].s_rb != OPUNUSED) {
                                } if (listp[i].s_rb != OPUNUSED) {
                                        int rb = getbits(ins, zoplist[i].s_rb);
                                        int rb = getbits(ins, listp[i].s_rb);
                                        sprintf(&line[strlen(line)],
                                        sprintf(&line[strlen(line)],
                                                "(%s)", zop_regstr[rb]);
                                                "(%s)", zop_regstr[rb]);
                                }
                                }
 
 
                        } else {
                        } else {
                                bool memop = (strncasecmp("LOD",
                                bool memop = (strncasecmp("LOD",
                                                zoplist[i].s_opstr, 3)==0);
                                                listp[i].s_opstr, 3)==0);
                                if (zoplist[i].s_i != OPUNUSED) {
                                if (listp[i].s_i != OPUNUSED) {
                                        int     imv = 0;
                                        int     imv = 0;
                                        imv = getbits(ins, zoplist[i].s_i);
 
                                        if ((imv != 0)||(zoplist[i].s_rb == OPUNUSED))
                                        imv = getbits(ins, listp[i].s_i);
 
                                        if ((imv != 0)||(listp[i].s_rb == OPUNUSED))
                                                sprintf(&line[strlen(line)],
                                                sprintf(&line[strlen(line)],
                                                        "$%d%s", imv,
                                                        "$%d%s", imv,
                                                        ((!memop)&&(zoplist[i].s_rb!=OPUNUSED))?"+":"");
                                                        ((!memop)&&(listp[i].s_rb!=OPUNUSED))?"+":"");
                                } if (zoplist[i].s_rb != OPUNUSED) {
                                } if (listp[i].s_rb != OPUNUSED) {
                                        int rb = getbits(ins, zoplist[i].s_rb);
                                        int rb = getbits(ins, listp[i].s_rb);
                                        if (memop)
                                        if (memop)
                                                sprintf(&line[strlen(line)],
                                                sprintf(&line[strlen(line)],
                                                        "(%s)", zop_regstr[rb]);
                                                        "(%s)", zop_regstr[rb]);
                                        else
                                        else
                                                strcat(line, zop_regstr[rb]);
                                                strcat(line, zop_regstr[rb]);
                                } if(((zoplist[i].s_i != OPUNUSED)||(zoplist[i].s_rb != OPUNUSED))
                                } if(((listp[i].s_i != OPUNUSED)||(listp[i].s_rb != OPUNUSED))
                                        &&((zoplist[i].s_ra != OPUNUSED)||(zoplist[i].s_result != OPUNUSED)))
                                        &&((listp[i].s_ra != OPUNUSED)||(listp[i].s_result != OPUNUSED)))
                                        strcat(line, ",");
                                        strcat(line, ",");
 
 
                                if (zoplist[i].s_ra != OPUNUSED) {
                                if (listp[i].s_ra != OPUNUSED) {
                                        int ra = getbits(ins, zoplist[i].s_ra);
                                        int ra = getbits(ins, listp[i].s_ra);
                                        strcat(line, zop_regstr[ra]);
                                        strcat(line, zop_regstr[ra]);
                                } else if (zoplist[i].s_result != OPUNUSED) {
                                } else if (listp[i].s_result != OPUNUSED) {
                                        int ra = getbits(ins, zoplist[i].s_result);
                                        int ra = getbits(ins, listp[i].s_result);
                                        strcat(line, zop_regstr[ra]);
                                        strcat(line, zop_regstr[ra]);
                                }
                                }
 
 
                        }
                        }
                        break;
                        break;
                }
                }
 
        } if (line[0] == '\0') {
 
                sprintf(line, "ILL %08x", ins);
 
        }
 
}
 
 
 
void    zipi_to_string(const ZIPI ins, char *la, char *lb) {
 
        static_zipi_to_string(ins, la, zoplist);
 
        if (lb) {
 
                if (ins & 0x80000000) {
 
                        static_zipi_to_string(ins, lb, zbottomlist);
 
                } else lb[0] = '\0';
        }
        }
}
}
 
 
 
unsigned int    zop_early_branch(const unsigned int pc, const ZIPI ins) {
 
        if ((ins & 0xf8000000) != 0x78000000)
 
                return pc+1;
 
        if ((ins & 0x07c00000) == 0x05800000) // LDI, high bit clear
 
                return (ins & 0x003fffff);
 
        if ((ins & 0x07c00000) == 0x05c00000) // LDI, high bit set
 
                return (ins & 0x007fffff)|0xffc00000;
 
        if ((ins & 0xffffe000) == 0x7bc3c000) // MOV
 
                return ((ins & 0x001fff)|((ins&0x01000)?0xffffe000:0))+pc+1;
 
        if ((ins & 0x07fc0000) == 0x00800000) // ADD, unconditional
 
                return ((ins & 0x03ffff)|((ins&0x020000)?0xfffc0000:0))+pc+1;
 
        return pc+1;
 
}
 
 
 
 
 
 
 No newline at end of file
 No newline at end of file

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.