home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include "m98k-opcode.h"
-
- static int bits(
- unsigned long width);
-
- static char *cond[] = { "lt", "gt", "eq", "un"};
- static char *pred[] = { "+", "-" };
-
- void
- main(
- int argc,
- char *argv[],
- char *envp[])
- {
- long i, j, x, d, p;
-
- for(i = 0; *(m98k_opcodes[i].name) != '\0'; i++){
- printf("\t%s", m98k_opcodes[i].name);
- if(IS_BRANCH_CONDITIONAL(m98k_opcodes[i].opcode)){
- p = bits(5) & 1;
- printf("%s", pred[p]);
- }
- if(m98k_opcodes[i].ops[0].type == NONE)
- printf("\n");
- else
- printf("\t");
- d = 0;
- for(j = 0; j < 5 && m98k_opcodes[i].ops[j].type != NONE; j++){
- switch(m98k_opcodes[i].ops[j].type){
- case PCREL:
- printf("_relitive");
- break;
- case BADDR:
- printf("_absolute");
- break;
- case D:
- printf("0x%04x(", bits(16));
- d = 1;
- break;
- case DS:
- printf("0x%04x(", bits(14) << 2);
- d = 1;
- break;
- case SI:
- case UI:
- printf("0x%04x", bits(16));
- break;
- case GREG:
- printf("r%d", bits(5) );
- break;
- case G0REG:
- printf("r%d", bits(5) | 0x1 );
- break;
- case FREG:
- printf("f%d", bits(5) );
- break;
- case SGREG:
- printf("sr%d", bits(4) );
- break;
- case SPREG:
- printf("%d", bits(10) );
- break;
- case BCND:
- printf("cr%d+%s", bits(3), cond[bits(2)] );
- break;
- case CRF:
- case CRFONLY:
- x = bits(3);
- printf("cr%d", x == 0 ? 1 : x);
- break;
- case sh:
- printf("%d", bits(6) );
- break;
- case mb:
- printf("%d", bits(6) );
- break;
- case NUM0:
- case NUM:
- if(j == 0 &&
- IS_BRANCH_CONDITIONAL(m98k_opcodes[i].opcode)){
- x = bits(m98k_opcodes[i].ops[j].width);
- if(m98k_opcodes[i].ops[2].type == PCREL)
- if(p == 0) /* + with negative disp */
- x &= 0xfffffffe;
- else
- x |= 1;
- else
- if(p == 0) /* + with positive disp */
- x |= 1;
- else
- x &= 0xfffffffe;
- if(x == 20)
- x = 0;
- printf("%d", x);
- }
- else
- printf("%d", bits(m98k_opcodes[i].ops[j].width) );
- break;
- case NONE:
- break;
- }
- if(j == 5 || m98k_opcodes[i].ops[j+1].type == NONE){
- if(d == 1)
- printf(")\n");
- else
- printf("\n");
- }
- else{
- if(m98k_opcodes[i].ops[j].type != D &&
- m98k_opcodes[i].ops[j].type != DS)
- printf(",");
- }
- }
- }
- exit(0);
- }
-
- static
- int
- bits(
- unsigned long width)
- {
- static int x = 1;
-
- x = (x + 1) & ((1 << width) - 1);
- return(x);
- }
-