home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
rtsi.com
/
2014.01.www.rtsi.com.tar
/
www.rtsi.com
/
OS9
/
OSK
/
SRC
/
unc.lzh
/
UNC
/
iset.c
< prev
next >
Wrap
Text File
|
1991-06-12
|
25KB
|
1,170 lines
/*
* SCCS: %W% %G% %U%
* Decode instructions.
*
*EMACS_MODES:c
*/
#include <stdio.h>
#ifdef OSK
#include "a.out.h"
#else
#include <a.out.h>
#endif
#include "unc.h"
extern ef_fids mainfile;
void gette(), putte();
void mkdref();
long gettw();
symbol textlab(), inventsymb();
void gopos();
int l1(), l2(), el1(), lea(), lmove(), lcbch(), jj();
int limed(), lsbit(), lmvml(), lone(), loone(), lonew(), lonel();
int ltrap(), linvalid();
int pmove(), pcbch(), pdbcc(), pscc(), pcs(), pmovc(), pstop(), pexg();
int pimed(), pmovp(), psbit(), pdbit(), pcs2(), pone(), ppea();
int plea(), pdreg(), pmvml(), ptrap(), plink(), pareg(), podreg();
int pqu(), pmqu(), ptreg(), pcmpm(), pomode(), pmshf(), pshf();
struct opstr {
unsigned short mask;
unsigned short match;
int (*opsize)();
int (*opprin)();
char *prarg;
} optab[] = {
0xf000, 0x2000, lmove, pmove, ".l",
0xf000, 0x3000, lmove, pmove, ".w",
0xf000, 0x1000, lmove, pmove, ".b",
0xf000, 0x6000, lcbch, pcbch, 0,
0xffbf, 0x003c, l2, pcs, "or",
0xff00, 0x0000, limed, pimed, "or",
0xffbf, 0x023c, l2, pcs, "and",
0xff00, 0x0200, limed, pimed, "and",
0xff00, 0x0400, limed, pimed, "sub",
0xff00, 0x0600, limed, pimed, "add",
0xffbf, 0x0a3c, l2, pcs, "eor",
0xff00, 0x0a00, limed, pimed, "eor",
0xff00, 0x0c00, limed, pimed, "cmp",
0xf138, 0x0108, l2, pmovp, 0,
0xff00, 0x0800, lsbit, psbit, 0,
0xf100, 0x0100, lonew, pdbit, 0,
0xffc0, 0x40c0, lonew, pcs2, "sr",
0xff00, 0x4000, lone, pone, "negx",
0xff00, 0x4200, lone, pone, "clr",
0xffc0, 0x44c0, lonew, pcs2, "cc",
0xff00, 0x4400, lone, pone, "neg",
0xffc0, 0x46c0, lonew, pcs2, "sr",
0xff00, 0x4600, lone, pone, "not",
0xffc0, 0x4800, lonew, ppea, "nbcd",
0xfff8, 0x4840, l1, pdreg, "swap.w",
0xffc0, 0x4840, lonel, ppea, "pea",
0xfff8, 0x4880, l1, pdreg, "ext.w",
0xfff8, 0x48c0, l1, pdreg, "ext.l",
0xfb80, 0x4880, lmvml, pmvml, 0,
0xffc0, 0x4ac0, lonew, ppea, "tas",
0xff00, 0x4a00, lone, pone, "tst",
0xfff0, 0x4e40, ltrap, ptrap, 0,
0xfff8, 0x4e50, l2, plink, 0,
0xfff8, 0x4e58, l1, pareg, "unlk %s",
0xfff8, 0x4e60, l1, pareg, "move.l %s,usp",
0xfff8, 0x4e68, l1, pareg, "move.l usp,%s",
0xffff, 0x4e70, l1, pareg, "reset",
0xffff, 0x4e71, l1, pareg, "nop",
0xffff, 0x4e72, l2, pstop, 0,
0xffff, 0x4e73, el1, pareg, "rte",
0xffff, 0x4e75, el1, pareg, "rts",
0xffff, 0x4e76, el1, pareg, "trapv",
0xffff, 0x4e77, el1, pareg, "rtr",
0xfffe, 0x4e7a, l2, pmovc, 0,
0xffc0, 0x4e80, jj, ppea, "jsr",
0xffc0, 0x4ec0, jj, ppea, "jmp",
0xf1c0, 0x4180, lonew,podreg,"chk",
0xf1c0, 0x41c0, lonel, plea, 0,
0xf0f8, 0x50c8, lcbch, pdbcc, 0,
0xf0c0, 0x50c0, lonew, pscc, 0,
0xf100, 0x5000, lone, pqu, "add",
0xf100, 0x5100, lone, pqu, "sub",
0xf100, 0x7000, l1, pmqu, 0,
0xf1c0, 0x80c0, lonew, podreg,"divu",
0xf1c0, 0x81c0, lonew, podreg,"divs",
0xf1f0, 0x8100, l1, ptreg, "sbcd",
0xf000, 0x8000, loone, pomode,"or",
0xf1f0, 0x9100, l1, ptreg, "subx.b",
0xf1f0, 0x9140, l1, ptreg, "subx.w",
0xf1f0, 0x9180, l1, ptreg, "subx.l",
0xf000, 0x9000, loone, pomode,"sub",
0xf1f8, 0xb108, l1, pcmpm, "cmp.b", /* CMPM */
0xf1f8, 0xb148, l1, pcmpm, "cmp.w", /* CMPM */
0xf1f8, 0xb188, l1, pcmpm, "cmp.l", /* CMPM */
0xf100, 0xb000, loone, pomode,"cmp",
0xf1c0, 0xb1c0, loone, pomode,"cmp",
0xf100, 0xb100, loone, pomode,"eor",
0xf1c0, 0xc0c0, lonew, podreg,"mulu",
0xf1c0, 0xc1c0, lonew, podreg,"muls",
0xf1f0, 0xc100, l1, ptreg, "abcd",
0xf130, 0xc100, l1, pexg, 0,
0xf000, 0xc000, loone, pomode,"and",
0xf1f0, 0xd100, l1, ptreg, "addx.b",
0xf1f0, 0xd140, l1, ptreg, "addx.w",
0xf1f0, 0xd180, l1, ptreg, "addx.l",
0xf000, 0xd000, loone, pomode,"add",
0xf8c0, 0xe0c0, lonew, pmshf, 0,
0xf000, 0xe000, l1, pshf, 0,
0, 0, linvalid, NULL, NULL
};
char *areg[] = { "a0", "a1", "a2", "a3", "a4", "a5", "a6", "sp"};
char *cclist[] = { "hi", "ls", "cc", "cs", "ne", "eq", "vc", "vs",
"pl", "mi", "ge", "lt", "gt", "le"};
char *shtype[] = { "as", "ls", "rox", "ro" };
char *bittyp[] = { "tst", "chg", "clr", "set" };
char *creg[] = { "sfc", "dfc", "usp", "vbr" };
#define MAX_SYSTRAP 0x60
#define MAX_IOTRAP 0x93
/*
* Length functions.
*/
int l1()
{
return 1;
}
int l2()
{
return 2;
}
int el1(te)
t_entry *te;
{
te->t_bchtyp = T_UNBR;
return 1;
}
/* Extrawurscht für OS9-Trap */
int ltrap(te, pos)
t_entry *te;
long pos;
{
unsigned tc;
if (te->t_contents == 0x4e40 && ropt == 0)
{ /* os9 syscall */
switch (tc = gettw(pos+2, R_WORD))
{
case 5: /* F$Chain */
case 6: /* F$Exit */
case 0x24: /* F$DExit */
case 0x34: /* F$SLink */
case 0x35: /* resvd */
case 0x36: /* resvd */
case 0x90:
case 0x91:
te->t_bchtyp = T_UNBR;
default:
if ((tc > 0x5a && tc < 0x80) || (tc > 0x93) ) /* undefined codes */
te->t_bchtyp = T_UNBR;
return(2);
} /* switch */
} /* if */
te->t_bchtyp = T_UNBR;
return(1);
}
int lea(instr, size, pos)
unsigned instr, size;
long pos;
{
switch ((instr >> 3) & 0x7) {
case 0:
case 1:
case 2:
case 3:
case 4:
return 1;
case 5:
case 6:
return 2;
default:
switch (instr & 0x7) {
case 0:
case 2:
case 3:
return 2;
case 1:
return 3;
case 4:
if (size > 2)
return 3;
return 2;
default:
return 0;
}
}
}
/*
* Lengths of move instructions.
*/
int lmove(te, pos)
t_entry *te;
long pos;
{
register unsigned tc = te->t_contents;
unsigned sz = 1;
int lng, lng2;
lng = tc & 0xf000;
if (lng == 0x3000)
sz = 2;
else if (lng == 0x2000)
sz = 4;
if ((lng = lea(tc, sz, pos+2)) <= 0)
return 0;
lng2 = lea(((tc>>3) & 0x38) | ((tc>>9) & 0x7), sz, pos+lng+lng);
if (lng2 <= 0)
return 0;
return lng + lng2 - 1;
}
/*
* Lengths for conditional branches and dbcc instructions.
*/
int lcbch(te, pos)
t_entry *te;
long pos;
{
unsigned tc = te->t_contents;
long dest = pos + 2;
int res = 2;
if ((tc & 0xf000) == 0x5000 || (tc & 0xff) == 0)
dest += (short)gettw(pos+2, R_WORD);
else {
dest += (char) tc;
res = 1;
}
if ( dest < hdr._mexec
|| dest >= endp
|| (dest & 1) != 0
)
return 0; /* Illegal branch destination */
if ((tc & 0xff00) == 0x6000)
te->t_bchtyp = T_UNBR;
else if ((tc & 0xff00) == 0x6100)
te->t_bchtyp = T_JSR;
else
te->t_bchtyp = T_CONDBR;
if ((te->t_relsymb = textlab(dest, pos)) == NULL)
return (0); /* Sprungziel ungültig */
return res;
}
int jj(te, pos)
t_entry *te;
long pos;
{
unsigned tc = te->t_contents;
t_entry nextl;
long dest;
te->t_bchtyp = (tc & 0x40)? T_UNBR: T_JSR;
if ((tc & 0x3f) == 0x39) {
gette(pos+2, &nextl);
if (nextl.t_relsymb == NULL) {
dest = gettw(pos + 2, R_LONG );
if ( (dest < hdr._mexec
|| dest >= endp
|| (dest & 1) != 0 ))
return 0; /* Illegal branch destination */
if ( dest < 0x290000 && ( nextl.t_relsymb = textlab(dest, pos) ) == NULL )
return 0; /* Branch to a continuation */
putte(&mainfile, pos+2, &nextl);
}
te->t_relsymb = nextl.t_relsymb; /* Easy ref */
}
return lea(tc, 4, pos+2);
}
int limed(te, pos)
t_entry *te;
long pos;
{
unsigned tc = te->t_contents;
int lng;
/*
* Specifically exclude byte address register operands,
* and ones which have lengths of 3.
*/
if ((tc & 0xf8) == 0x08)
return 0;
if ((tc & 0xc0) >= 0x80) {
if (tc & 0x40)
return 0;
lng = lea(tc, 4, pos+6);
if (lng > 0)
lng += 2;
}
else {
lng = lea(tc, (unsigned)((tc & 0xc0)?2:1), pos+4);
if (lng > 0)
lng++;
}
return lng;
}
int lsbit(te, pos)
t_entry *te;
long pos;
{
int lng = lea(te->t_contents, 1, pos+4);
if (lng > 0)
lng++;
return lng;
}
int lmvml(te, pos)
t_entry *te;
long pos;
{
int lng = lea(te->t_contents,
(unsigned)(te->t_contents&0x40? 4:2), pos+4);
if (lng > 0)
lng++;
return lng;
}
/*
* Length depends on bits 6 and 7 of instruction.
*/
int lone(te, pos)
t_entry *te;
long pos;
{
unsigned tc = te->t_contents;
return lea(tc, 1 << ((tc >> 6) & 3), pos+2);
}
/*
* Length depends on bits 6-8 of instruction.
*/
int loone(te, pos)
t_entry *te;
long pos;
{
unsigned tc = te->t_contents;
switch ((tc >> 6) & 7) {
case 0:
case 4:
return lea(tc, 1, pos+2);
case 1:
case 3:
case 5:
return lea(tc, 2, pos+2);
case 2:
case 6:
case 7:
return lea(tc, 4, pos+2);
}
/*NOTREACHED*/
}
int lonew(te, pos)
t_entry *te;
long pos;
{
return lea(te->t_contents, 2, pos+2);
}
int lonel(te, pos)
t_entry *te;
long pos;
{
return lea(te->t_contents, 4, pos+2);
}
/*
* Print routines.
*/
/*
* print out small integers in decamil notation, all others in hex.
*/
void prind(n)
unsigned short n;
{
if ((short) n > -128 && (short) n < 128)
xp += printf("%d", (long) ((short) n));
else
xp += printf("$%x",(unsigned long) n);
}
int findleng(tc)
unsigned tc;
{
switch ((tc >> 6) & 3) {
case 0:
return 'b';
case 1:
return 'w';
default:
return 'l';
}
}
void piword(reg,disp)
char * reg;
unsigned disp;
{
int szc;
xp += printf("%d(%s,", disp & 0xff, reg);
if (disp & 0x8000) {
xp += printf("%s.", areg[(disp >> 12) & 0x7]);
}
else
xp += printf("d%d.%c)", (disp >> 12) & 0x7, disp & (1 << 10) ? 'l' :'w');
}
void paddr(pos)
long pos;
{
t_entry tent;
symbol symb;
gette(pos, &tent);
if (tent.t_relsymb != NULL)
{
xp += printf("%s", symb->s_name);
return;
}
xp += printf("$%x", gettw(pos, R_LONG));
}
int prea(ea, pos, sz)
unsigned ea, sz;
long pos; /* Address of previous word to extn */
{
unsigned reg = ea & 0x7;
long disp;
t_entry tent;
d_entry dent;
pos += 2;
switch ((ea >> 3) & 0x7) {
case 0:
xp += printf("d%d", reg);
return 0;
case 1:
xp += printf("%s", areg[reg]);
return 0;
case 2:
xp += printf("(%s)", areg[reg]);
return 0;
case 3:
xp += printf("(%s)+", areg[reg]);
return 0;
case 4:
xp += printf("-(%s)", areg[reg]);
return 0;
case 5:
disp = gettw(pos, R_WORD);
if (reg == 6 && (getde(disp, &dent) == 0))
{
if (dent.d_lab == NULL)
{
dent.d_lab = inventsymb("V");
putde(disp, &dent);
}
if (dent.d_lab != NULL)
xp += printf("%s", dent.d_lab->s_name);
else
(void) prind(disp);
}
else
(void) prind(disp);
xp += printf("(%s)", areg[reg]);
return 2;
case 6:
piword(areg[reg], (unsigned) gettw(pos, R_WORD));
return 2;
default:
switch (reg) {
case 0:
disp = gettw(&mainfile, pos, R_WORD);
(void) prind(disp);
xp += printf(".w");
return 2;
case 1:
paddr(pos);
return 4;
case 2:{
symbol symb;
register int addr;
disp = ((short) gettw(pos, R_WORD));
if ((addr=pos+disp) < hdr._mexec ||
addr >= endp ||
(addr & 1) != 0)
goto skiplabs;
gette(addr, &tent);
if (tent.t_relsymb != NULL) {
symb = tent.t_relsymb;
}
else if (tent.t_lab != NULL) {
symb = tent.t_lab;
}
else {
skiplabs:
(void) prind(disp);
xp += printf("(pc)");
return 2;
}
xp += printf("%s", symb->s_name);
return 2;
}
case 3:
piword("pc", (unsigned)gettw(pos, R_WORD));
return 2;
case 4:
xp += printf("#");
if (sz < 4)
xp += printf("$%x", gettw(pos, R_WORD));
else
paddr(pos);
return sz;
default:
(void) fprintf(stderr, "Funny mode\n");
/* exit(220); */
}
}
/*NOTREACHED*/
}
int pmove(te, pos)
t_entry *te;
long pos;
{
unsigned sz = 2;
unsigned tc = te->t_contents;
xp += printf("move%s", optab[te->t_iindex].prarg);
if ((tc & 0xf000) == 0x2000)
sz = 4;
gopos(ARGUMENT);
pos += prea(tc, pos, sz);
xp += printf(",");
(void) prea(((tc >> 9) & 0x7) | ((tc >> 3) & 0x38), pos, sz);
}
int pcbch(te)
t_entry *te;
{
int cc = ((te->t_contents >> 8) & 0xf) - 2;
char *msg;
register symbol ts;
if (cc < 0)
msg = cc < -1? "ra": "sr";
else
msg = cclist[cc];
xp += printf("b%s", msg);
if (te->t_lng < 2)
xp += printf(".s");
ts = te->t_relsymb;
gopos(ARGUMENT);
if (ts != 0)
{
xp += printf("%s", ts->s_name);
gopos(COMMENT);
xp += printf("($%x)", ts->s_value);
}
else
printf("??? ts == NULL in pcbch (!)");
}
int pdbcc(te)
t_entry *te;
{
unsigned tc = te->t_contents;
int cc = ((tc >> 8) & 0xf) - 2;
char *msg;
register symbol ts;
if (cc < 0)
msg = cc < -1? "t": "f";
else
msg = cclist[cc];
ts = te->t_relsymb;
xp += printf("db%s", msg);
gopos(ARGUMENT);
xp += printf("d%d,", tc & 0x7);
xp += printf("%s", ts->s_name);
}
int pscc(te, pos)
t_entry *te;
long pos;
{
unsigned tc = te->t_contents;
int cc = ((tc >> 8) & 0xf) - 2;
char *msg;
if (cc < 0)
msg = cc < -1? "t": "f";
else
msg = cclist[cc];
xp += printf("s%s", msg);
gopos(ARGUMENT);
(void) prea(tc, pos, 1);
}
int pcs(te, pos)
t_entry *te;
long pos;
{
long disp = gettw(pos+2, R_WORD);
xp += printf("%s", optab[te->t_iindex].prarg);
if ((te->t_contents & 0xc0) == 0){
xp += printf(".b");
gopos(ARGUMENT);
(void) prind(disp);
xp += printf(",cc");
}
else {
xp += printf(".w");
gopos(ARGUMENT);
(void) prind(disp);
xp += printf(",sr");
}
}
int pmovc(te, pos)
t_entry *te;
long pos;
{
int disp = gettw(pos+2, R_WORD);
int ctrl = ((disp >> 10) & 2) | (disp & 1);
xp += printf("movec");
gopos(ARGUMENT);
if ((te->t_contents & 1) == 0)
xp += printf("%s", creg[ctrl]);
if (disp & 0x8000)
{
xp += printf("%s", areg[(disp >> 12) & 7]);
}
else
xp += printf("d%d,", disp >> 12);
if (te->t_contents & 1)
xp += printf("%s", creg[ctrl]);
}
int pimed(te, pos)
t_entry *te;
long pos;
{
int sz = findleng(te->t_contents);
xp += printf("%s.%c", optab[te->t_iindex].prarg, sz);
gopos(ARGUMENT);
xp += printf("#");
if (sz == 'l') {
paddr(pos+2);
xp += printf(",");
(void) prea(te->t_contents, pos+4, 4);
}
else {
xp += printf("$%x,", gettw(pos+2, R_WORD));
(void) prea(te->t_contents, pos+2, 2);
}
}
int pmovp(te, pos)
t_entry *te;
long pos;
{
unsigned tc = te->t_contents;
long disp = gettw(pos+2, R_WORD);
int dreg = tc >> 9;
char *ar = areg[tc & 0x7];
xp += printf("movep.%c", tc & (1 << 6) ? 'l' : 'w');
gopos(ARGUMENT);
if (tc & (1 << 7)) {
xp += printf("%%d%d,", dreg);
(void) prind(disp);
xp += printf("(%s)", ar);
}
else {
(void) prind(disp);
xp += printf("(%s),%%d%d", ar, dreg);
}
}
int psbit(te, pos)
t_entry *te;
long pos;
{
unsigned tc = te->t_contents;
xp += printf("b%s", bittyp[(tc >> 6) & 0x3]);
gopos(ARGUMENT);
xp += printf("#%d,", gettw(pos+2, R_WORD));
(void) prea(tc, pos+2, 1);
}
/*ARGSUSED*/
int pstop(te, pos)
t_entry *te;
long pos;
{
xp += printf("stop");
gopos(ARGUMENT);
xp += printf("#$%x", gettw(pos+2, R_WORD));
}
int pdbit(te, pos)
t_entry *te;
long pos;
{
unsigned tc = te->t_contents;
xp += printf("b%s", bittyp[(tc >> 6) & 0x3]);
gopos(ARGUMENT);
xp += printf("d%d,", (tc >> 9) & 0x7);
(void) prea(tc, pos, 1);
}
int pcs2(te, pos)
t_entry *te;
long pos;
{
unsigned tc = te->t_contents;
xp += printf("move.w");
gopos(ARGUMENT);
if ((tc & 0xffc0) == 0x40c0) {
xp += printf("sr,");
(void) prea(tc, pos, 2);
}
else {
(void) prea(tc, pos, 2);
xp += printf(",%s", optab[te->t_iindex].prarg);
}
}
int pone(te, pos)
t_entry *te;
long pos;
{
unsigned tc = te->t_contents;
int sz = findleng(tc);
xp += printf("%s.%c", optab[te->t_iindex].prarg, sz);
gopos(ARGUMENT);
(void) prea(tc, pos, (unsigned)(sz == 'l'? 4: 2));
}
int ppea(te, pos) /* nbcd, pea, tas, jmp, jsr */
t_entry *te;
long pos;
{
xp += printf("%s", optab[te->t_iindex].prarg);
gopos(ARGUMENT);
(void) prea(te->t_contents, pos, (unsigned)(te->t_lng > 2? 4: 2));
}
int plea(te, pos)
t_entry *te;
long pos;
{
xp += printf("lea");
gopos(ARGUMENT);
(void) prea(te->t_contents, pos, 4);
xp += printf(",%s", areg[(te->t_contents >> 9) & 0x7]);
}
int pdreg(te)
t_entry *te;
{
xp += printf("%s", optab[te->t_iindex].prarg);
gopos(ARGUMENT);
xp += printf("d%d", te->t_contents & 7);
}
int pmvml(te, pos)
t_entry *te;
long pos;
{
unsigned tc = te->t_contents;
register unsigned dw = gettw(pos+2, R_WORD);
unsigned sz = 4;
int sc = 'l';
register int i;
register unsigned bit;
xp += printf("movem.");
if ((tc & 0x40) == 0) {
sc = 'w';
sz = 2;
}
xp += printf("%c", sc);
gopos(ARGUMENT);
if (tc & 0x400) {
(void) prea(tc, pos+2, sz);
xp += printf(",&$%x", dw);
}
else {
xp += printf("&$%x,", dw);
(void) prea(tc, pos+2, sz);
}
xp += printf("\t#\t");
xp += printf("\t|");
if ((tc & 0x38) == 0x20) {
bit = 0x8000;
for (i = 0; i < 8; i++) {
if (dw & bit)
xp += printf(" d%d", i);
bit >>= 1;
}
for (i = 0; i < 8; i++) {
if (dw & bit)
xp += printf(" %s", areg[i]);
bit >>= 1;
}
}
else {
bit = 1;
for (i = 0; i < 8; i++) {
if (dw & bit)
xp += printf(" d%d", i);
bit <<= 1;
}
for (i = 0; i < 8; i++) {
if (dw & bit)
xp += printf(" %s", areg[i]);
bit <<= 1;
}
}
}
int ptrap(te, pos)
t_entry *te;
long pos;
{
if (te->t_contents != 0x4e40)
{
xp += printf("trap");
gopos(ARGUMENT);
xp += printf("#$%x", te->t_contents & 0xf);
}
else
{
char deftext[8];
char *s = deftext;
t_entry postword;
unsigned short trapcode;
extern char *systraps[], *iotraps[];
gette(pos+2, &postword);
if ((trapcode = postword.t_contents) <= MAX_SYSTRAP)
s = systraps[trapcode];
else if (trapcode >= 0x80 && trapcode <= MAX_IOTRAP)
s = iotraps[trapcode - 0x80];
else
sprintf(deftext, "#$%x", trapcode);
xp += printf("os9");
gopos(ARGUMENT);
printf("%s", s);
}
return(0);
}
int plink(te, pos)
t_entry *te;
long pos;
{
xp += printf("link");
gopos(ARGUMENT);
xp += printf("%s,#$%x", areg[te->t_contents & 0x7],
gettw(pos+2, R_WORD));
}
int pareg(te)
t_entry *te;
{
xp += printf(optab[te->t_iindex].prarg, areg[te->t_contents & 0x7]);
}
int podreg(te, pos)
t_entry *te;
long pos;
{
unsigned tc = te->t_contents;
xp += printf("%s", optab[te->t_iindex].prarg);
gopos(ARGUMENT);
(void) prea(tc, pos, 2);
xp += printf(",d%d", (tc >> 9) & 0x7);
}
int pqu(te, pos)
t_entry *te;
long pos;
{
unsigned tc = te->t_contents;
int sz = findleng(tc);
int amt = (tc >> 9) & 0x7;
if (amt == 0)
amt = 8;
xp += printf("%s.%c", optab[te->t_iindex].prarg, sz);
gopos(ARGUMENT);
xp += printf("#%d,", amt);
(void) prea(tc, pos, (unsigned)(sz == 'l'? 4: 2));
}
int pmqu(te)
t_entry *te;
{
unsigned tc = te->t_contents;
xp += printf("moveq.l");
gopos(ARGUMENT);
xp += printf("#$%x,d%d", (char)tc, (tc >> 9) & 0x7);
}
int ptreg(te)
t_entry *te;
{
register unsigned tc = te->t_contents;
int rx = (tc >> 9) & 0x7;
int ry = tc & 0x7;
xp += printf("%s", optab[te->t_iindex].prarg);
gopos(ARGUMENT);
if (tc & 0x8)
xp += printf("-(%s),-(%s)", areg[ry], areg[rx]);
else
xp += printf("%%d%d,%%d%d", ry, rx);
}
int pcmpm(te)
t_entry *te;
{
register unsigned tc = te->t_contents;
xp += printf("%s", optab[te->t_iindex].prarg);
gopos(ARGUMENT);
xp += printf("(%s)+,(%s)+", areg[tc & 7], areg[(tc >> 9) & 7]);
}
int pomode(te, pos)
t_entry *te;
long pos;
{
unsigned tc = te->t_contents;
char buf[5];
char bef[4], aft[4];
int sz;
int reg = (tc >> 9) & 7;
buf[0] = '\0';
bef[0] = aft[0] = '\0';
switch ((tc >> 6) & 7) {
case 0:
sz = 'b';
goto toreg;
case 1:
sz = 'w';
goto toreg;
case 2:
sz = 'l';
toreg:
(void) sprintf(aft, ",d%d", reg);
break;
case 3:
sz = 'w';
goto toareg;
case 7:
sz = 'l';
toareg:
(void) sprintf(aft, ",%s", areg[reg]);
break;
case 4:
sz = 'b';
goto frreg;
case 5:
sz = 'w';
goto frreg;
case 6:
sz = 'l';
frreg:
(void) sprintf(bef, "d%d,", reg);
break;
}
xp += printf("%s.%c", optab[te->t_iindex].prarg, sz);
gopos(ARGUMENT);
xp += printf("%s", bef);
(void) prea(tc, pos, (unsigned)(sz == 'l'? 4: 2));
xp += printf(aft);
}
int pexg(te)
t_entry *te;
{
unsigned tc = te->t_contents;
int r1 = (tc >> 9) & 7, r2 = tc & 7;
xp += printf("exg");
gopos(ARGUMENT);
if ((tc & 0x00f8) == 0x0048)
xp += printf("%s,", areg[r1]);
else
xp += printf("d%d,", r1);
if (tc & 0x8)
xp += printf("%s", areg[r2]);
else
xp += printf("d%d", r2);
}
int pmshf(te, pos)
t_entry *te;
long pos;
{
unsigned tc = te->t_contents;
xp += printf("%s%c.w", shtype[(tc >> 9) & 3], tc & 0x100? 'l': 'r');
gopos(ARGUMENT);
(void) prea(tc, pos, 2);
}
int pshf(te)
t_entry *te;
{
unsigned tc = te->t_contents;
int sz = findleng(tc);
int disp = (tc >> 9) & 7;
xp += printf("%s%c.%c", shtype[(tc >> 3) & 3], tc & 0x100? 'l': 'r', sz);
gopos(ARGUMENT);
if (tc & 0x20)
xp += printf("%%d%d", disp);
else
xp += printf("&%d", disp == 0? 8: disp);
xp += printf(",%%d%d", tc & 7);
}
int linvalid()
{
return (0);
}
/*
* Find length etc of instruction.
*/
int findinst(te, pos)
register t_entry *te;
long pos;
/*
Disassembliert die Instruktion in te, die die ADresse pos haben muss.
Rückkehrwert:
ISFALSCH, wenn kein gültiger Opcode.
ISOK ansonsten. Dann sind folgende Felder gültig (aber nicht
aus File rausgeschrieben):
t_iindex Index in OpCode-Tafel
t_bchtyp T_CONDBR (bedingte Verzweigung),
T_UNBR (unbedingte Verzweigung),
T_JSR
T_NOBR (unbedingte Verzweigung)
t_lng Länge der Instruktion
t_relsymb (nur bei Verzweigungen): Zieladresse
*/
{
register struct opstr *op;
unsigned tc = te->t_contents;
int endpos, npos;
for (op = &optab[0]; (tc & op->mask) != op->match; op++)
;
te->t_iindex = op - optab;
te->t_bchtyp = T_NOBR;
if ((te->t_lng = (op->opsize)(te, pos)) == 0)
return(ISFALSCH);
return(ISOK);
}
/*
* Print instruction.
*/
void prinst(te, pos)
t_entry *te;
long pos;
{
(optab[te->t_iindex].opprin)(te, pos);
if (te->t_bchtyp == T_UNBR)
putchar('\n');
putchar('\n');
}