Home | History | Annotate | Line # | Download | only in fpe
fpu_calcea.c revision 1.13.6.2
      1  1.13.6.2  nathanw /*	$NetBSD: fpu_calcea.c,v 1.13.6.2 2002/10/18 02:38:14 nathanw Exp $	*/
      2  1.13.6.2  nathanw 
      3  1.13.6.2  nathanw /*
      4  1.13.6.2  nathanw  * Copyright (c) 1995 Gordon W. Ross
      5  1.13.6.2  nathanw  * portion Copyright (c) 1995 Ken Nakata
      6  1.13.6.2  nathanw  * All rights reserved.
      7  1.13.6.2  nathanw  *
      8  1.13.6.2  nathanw  * Redistribution and use in source and binary forms, with or without
      9  1.13.6.2  nathanw  * modification, are permitted provided that the following conditions
     10  1.13.6.2  nathanw  * are met:
     11  1.13.6.2  nathanw  * 1. Redistributions of source code must retain the above copyright
     12  1.13.6.2  nathanw  *    notice, this list of conditions and the following disclaimer.
     13  1.13.6.2  nathanw  * 2. Redistributions in binary form must reproduce the above copyright
     14  1.13.6.2  nathanw  *    notice, this list of conditions and the following disclaimer in the
     15  1.13.6.2  nathanw  *    documentation and/or other materials provided with the distribution.
     16  1.13.6.2  nathanw  * 3. The name of the author may not be used to endorse or promote products
     17  1.13.6.2  nathanw  *    derived from this software without specific prior written permission.
     18  1.13.6.2  nathanw  * 4. All advertising materials mentioning features or use of this software
     19  1.13.6.2  nathanw  *    must display the following acknowledgement:
     20  1.13.6.2  nathanw  *      This product includes software developed by Gordon Ross
     21  1.13.6.2  nathanw  *
     22  1.13.6.2  nathanw  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     23  1.13.6.2  nathanw  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     24  1.13.6.2  nathanw  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     25  1.13.6.2  nathanw  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     26  1.13.6.2  nathanw  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     27  1.13.6.2  nathanw  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     28  1.13.6.2  nathanw  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     29  1.13.6.2  nathanw  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     30  1.13.6.2  nathanw  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     31  1.13.6.2  nathanw  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     32  1.13.6.2  nathanw  */
     33  1.13.6.2  nathanw 
     34  1.13.6.2  nathanw #include <sys/param.h>
     35  1.13.6.2  nathanw #include <sys/signal.h>
     36  1.13.6.2  nathanw #include <sys/systm.h>
     37  1.13.6.2  nathanw #include <machine/frame.h>
     38  1.13.6.2  nathanw #include <m68k/m68k.h>
     39  1.13.6.2  nathanw 
     40  1.13.6.2  nathanw #include "fpu_emulate.h"
     41  1.13.6.2  nathanw 
     42  1.13.6.2  nathanw /*
     43  1.13.6.2  nathanw  * Prototypes of static functions
     44  1.13.6.2  nathanw  */
     45  1.13.6.2  nathanw static int decode_ea6 __P((struct frame *frame, struct instruction *insn,
     46  1.13.6.2  nathanw 			   struct insn_ea *ea, int modreg));
     47  1.13.6.2  nathanw static int fetch_immed __P((struct frame *frame, struct instruction *insn,
     48  1.13.6.2  nathanw 			    int *dst));
     49  1.13.6.2  nathanw static int fetch_disp __P((struct frame *frame, struct instruction *insn,
     50  1.13.6.2  nathanw 			   int size, int *res));
     51  1.13.6.2  nathanw static int calc_ea __P((struct insn_ea *ea, char *ptr, char **eaddr));
     52  1.13.6.2  nathanw 
     53  1.13.6.2  nathanw /*
     54  1.13.6.2  nathanw  * Helper routines for dealing with "effective address" values.
     55  1.13.6.2  nathanw  */
     56  1.13.6.2  nathanw 
     57  1.13.6.2  nathanw /*
     58  1.13.6.2  nathanw  * Decode an effective address into internal form.
     59  1.13.6.2  nathanw  * Returns zero on success, else signal number.
     60  1.13.6.2  nathanw  */
     61  1.13.6.2  nathanw int
     62  1.13.6.2  nathanw fpu_decode_ea(frame, insn, ea, modreg)
     63  1.13.6.2  nathanw      struct frame *frame;
     64  1.13.6.2  nathanw      struct instruction *insn;
     65  1.13.6.2  nathanw      struct insn_ea *ea;
     66  1.13.6.2  nathanw      int modreg;
     67  1.13.6.2  nathanw {
     68  1.13.6.2  nathanw     int sig;
     69  1.13.6.2  nathanw 
     70  1.13.6.2  nathanw #ifdef DEBUG
     71  1.13.6.2  nathanw     if (insn->is_datasize < 0) {
     72  1.13.6.2  nathanw 	panic("decode_ea: called with uninitialized datasize");
     73  1.13.6.2  nathanw     }
     74  1.13.6.2  nathanw #endif
     75  1.13.6.2  nathanw 
     76  1.13.6.2  nathanw     sig = 0;
     77  1.13.6.2  nathanw 
     78  1.13.6.2  nathanw     /* Set the most common value here. */
     79  1.13.6.2  nathanw     ea->ea_regnum = 8 + (modreg & 7);
     80  1.13.6.2  nathanw 
     81  1.13.6.2  nathanw     if ((modreg & 060) == 0) {
     82  1.13.6.2  nathanw 	/* register direct */
     83  1.13.6.2  nathanw 	ea->ea_regnum = modreg & 0xf;
     84  1.13.6.2  nathanw 	ea->ea_flags = EA_DIRECT;
     85  1.13.6.2  nathanw #ifdef DEBUG_FPE
     86  1.13.6.2  nathanw 	printf("decode_ea: register direct reg=%d\n", ea->ea_regnum);
     87  1.13.6.2  nathanw #endif
     88  1.13.6.2  nathanw     } else if ((modreg & 077) == 074) {
     89  1.13.6.2  nathanw 	/* immediate */
     90  1.13.6.2  nathanw 	ea->ea_flags = EA_IMMED;
     91  1.13.6.2  nathanw 	sig = fetch_immed(frame, insn, &ea->ea_immed[0]);
     92  1.13.6.2  nathanw #ifdef DEBUG_FPE
     93  1.13.6.2  nathanw 	printf("decode_ea: immediate size=%d\n", insn->is_datasize);
     94  1.13.6.2  nathanw #endif
     95  1.13.6.2  nathanw     }
     96  1.13.6.2  nathanw     /*
     97  1.13.6.2  nathanw      * rest of the address modes need to be separately
     98  1.13.6.2  nathanw      * handled for the LC040 and the others.
     99  1.13.6.2  nathanw      */
    100  1.13.6.2  nathanw #if 0 /* XXX */
    101  1.13.6.2  nathanw     else if (frame->f_format == 4 && frame->f_fmt4.f_fa) {
    102  1.13.6.2  nathanw 	/* LC040 */
    103  1.13.6.2  nathanw 	ea->ea_flags = EA_FRAME_EA;
    104  1.13.6.2  nathanw 	ea->ea_fea = frame->f_fmt4.f_fa;
    105  1.13.6.2  nathanw #ifdef DEBUG_FPE
    106  1.13.6.2  nathanw 	printf("decode_ea: 68LC040 - in-frame EA (%p) size %d\n",
    107  1.13.6.2  nathanw 		(void *)ea->ea_fea, insn->is_datasize);
    108  1.13.6.2  nathanw #endif
    109  1.13.6.2  nathanw 	if ((modreg & 070) == 030) {
    110  1.13.6.2  nathanw 	    /* postincrement mode */
    111  1.13.6.2  nathanw 	    ea->ea_flags |= EA_POSTINCR;
    112  1.13.6.2  nathanw 	} else if ((modreg & 070) == 040) {
    113  1.13.6.2  nathanw 	    /* predecrement mode */
    114  1.13.6.2  nathanw 	    ea->ea_flags |= EA_PREDECR;
    115  1.13.6.2  nathanw #ifdef M68060
    116  1.13.6.2  nathanw #if defined(M68020) || defined(M68030) || defined(M68040)
    117  1.13.6.2  nathanw 	    if (cputype == CPU_68060)
    118  1.13.6.2  nathanw #endif
    119  1.13.6.2  nathanw 		if (insn->is_datasize == 12)
    120  1.13.6.2  nathanw 			ea->ea_fea -= 8;
    121  1.13.6.2  nathanw #endif
    122  1.13.6.2  nathanw 	}
    123  1.13.6.2  nathanw     }
    124  1.13.6.2  nathanw #endif /* XXX */
    125  1.13.6.2  nathanw     else {
    126  1.13.6.2  nathanw 	/* 020/030 */
    127  1.13.6.2  nathanw 	switch (modreg & 070) {
    128  1.13.6.2  nathanw 
    129  1.13.6.2  nathanw 	case 020:			/* (An) */
    130  1.13.6.2  nathanw 	    ea->ea_flags = 0;
    131  1.13.6.2  nathanw #ifdef DEBUG_FPE
    132  1.13.6.2  nathanw 	    printf("decode_ea: register indirect reg=%d\n", ea->ea_regnum);
    133  1.13.6.2  nathanw #endif
    134  1.13.6.2  nathanw 	    break;
    135  1.13.6.2  nathanw 
    136  1.13.6.2  nathanw 	case 030:			/* (An)+ */
    137  1.13.6.2  nathanw 	    ea->ea_flags = EA_POSTINCR;
    138  1.13.6.2  nathanw #ifdef DEBUG_FPE
    139  1.13.6.2  nathanw 	    printf("decode_ea: reg indirect postincrement reg=%d\n",
    140  1.13.6.2  nathanw 		   ea->ea_regnum);
    141  1.13.6.2  nathanw #endif
    142  1.13.6.2  nathanw 	    break;
    143  1.13.6.2  nathanw 
    144  1.13.6.2  nathanw 	case 040:			/* -(An) */
    145  1.13.6.2  nathanw 	    ea->ea_flags = EA_PREDECR;
    146  1.13.6.2  nathanw #ifdef DEBUG_FPE
    147  1.13.6.2  nathanw 	    printf("decode_ea: reg indirect predecrement reg=%d\n",
    148  1.13.6.2  nathanw 		   ea->ea_regnum);
    149  1.13.6.2  nathanw #endif
    150  1.13.6.2  nathanw 	    break;
    151  1.13.6.2  nathanw 
    152  1.13.6.2  nathanw 	case 050:			/* (d16,An) */
    153  1.13.6.2  nathanw 	    ea->ea_flags = EA_OFFSET;
    154  1.13.6.2  nathanw 	    sig = fetch_disp(frame, insn, 1, &ea->ea_offset);
    155  1.13.6.2  nathanw #ifdef DEBUG_FPE
    156  1.13.6.2  nathanw 	    printf("decode_ea: reg indirect with displacement reg=%d\n",
    157  1.13.6.2  nathanw 		   ea->ea_regnum);
    158  1.13.6.2  nathanw #endif
    159  1.13.6.2  nathanw 	    break;
    160  1.13.6.2  nathanw 
    161  1.13.6.2  nathanw 	case 060:			/* (d8,An,Xn) */
    162  1.13.6.2  nathanw 	    ea->ea_flags = EA_INDEXED;
    163  1.13.6.2  nathanw 	    sig = decode_ea6(frame, insn, ea, modreg);
    164  1.13.6.2  nathanw 	    break;
    165  1.13.6.2  nathanw 
    166  1.13.6.2  nathanw 	case 070:			/* misc. */
    167  1.13.6.2  nathanw 	    ea->ea_regnum = (modreg & 7);
    168  1.13.6.2  nathanw 	    switch (modreg & 7) {
    169  1.13.6.2  nathanw 
    170  1.13.6.2  nathanw 	    case 0:			/* (xxxx).W */
    171  1.13.6.2  nathanw 		ea->ea_flags = EA_ABS;
    172  1.13.6.2  nathanw 		sig = fetch_disp(frame, insn, 1, &ea->ea_absaddr);
    173  1.13.6.2  nathanw #ifdef DEBUG_FPE
    174  1.13.6.2  nathanw 		printf("decode_ea: absolute address (word)\n");
    175  1.13.6.2  nathanw #endif
    176  1.13.6.2  nathanw 		break;
    177  1.13.6.2  nathanw 
    178  1.13.6.2  nathanw 	    case 1:			/* (xxxxxxxx).L */
    179  1.13.6.2  nathanw 		ea->ea_flags = EA_ABS;
    180  1.13.6.2  nathanw 		sig = fetch_disp(frame, insn, 2, &ea->ea_absaddr);
    181  1.13.6.2  nathanw #ifdef DEBUG_FPE
    182  1.13.6.2  nathanw 		printf("decode_ea: absolute address (long)\n");
    183  1.13.6.2  nathanw #endif
    184  1.13.6.2  nathanw 		break;
    185  1.13.6.2  nathanw 
    186  1.13.6.2  nathanw 	    case 2:			/* (d16,PC) */
    187  1.13.6.2  nathanw 		ea->ea_flags = EA_PC_REL | EA_OFFSET;
    188  1.13.6.2  nathanw 		sig = fetch_disp(frame, insn, 1, &ea->ea_absaddr);
    189  1.13.6.2  nathanw #ifdef DEBUG_FPE
    190  1.13.6.2  nathanw 		printf("decode_ea: pc relative word displacement\n");
    191  1.13.6.2  nathanw #endif
    192  1.13.6.2  nathanw 		break;
    193  1.13.6.2  nathanw 
    194  1.13.6.2  nathanw 	    case 3:			/* (d8,PC,Xn) */
    195  1.13.6.2  nathanw 		ea->ea_flags = EA_PC_REL | EA_INDEXED;
    196  1.13.6.2  nathanw 		sig = decode_ea6(frame, insn, ea, modreg);
    197  1.13.6.2  nathanw 		break;
    198  1.13.6.2  nathanw 
    199  1.13.6.2  nathanw 	    case 4:			/* #data */
    200  1.13.6.2  nathanw 		/* it should have been taken care of earlier */
    201  1.13.6.2  nathanw 	    default:
    202  1.13.6.2  nathanw #ifdef DEBUG_FPE
    203  1.13.6.2  nathanw 		printf("decode_ea: invalid addr mode (7,%d)\n", modreg & 7);
    204  1.13.6.2  nathanw #endif
    205  1.13.6.2  nathanw 		return SIGILL;
    206  1.13.6.2  nathanw 	    } /* switch for mode 7 */
    207  1.13.6.2  nathanw 	    break;
    208  1.13.6.2  nathanw 	} /* switch mode */
    209  1.13.6.2  nathanw     }
    210  1.13.6.2  nathanw     ea->ea_moffs = 0;
    211  1.13.6.2  nathanw 
    212  1.13.6.2  nathanw     return sig;
    213  1.13.6.2  nathanw }
    214  1.13.6.2  nathanw 
    215  1.13.6.2  nathanw /*
    216  1.13.6.2  nathanw  * Decode Mode=6 address modes
    217  1.13.6.2  nathanw  */
    218  1.13.6.2  nathanw static int
    219  1.13.6.2  nathanw decode_ea6(frame, insn, ea, modreg)
    220  1.13.6.2  nathanw      struct frame *frame;
    221  1.13.6.2  nathanw      struct instruction *insn;
    222  1.13.6.2  nathanw      struct insn_ea *ea;
    223  1.13.6.2  nathanw      int modreg;
    224  1.13.6.2  nathanw {
    225  1.13.6.2  nathanw     int extword, idx;
    226  1.13.6.2  nathanw     int basedisp, outerdisp;
    227  1.13.6.2  nathanw     int bd_size, od_size;
    228  1.13.6.2  nathanw     int sig;
    229  1.13.6.2  nathanw 
    230  1.13.6.2  nathanw     extword = fusword((void *) (insn->is_pc + insn->is_advance));
    231  1.13.6.2  nathanw     if (extword < 0) {
    232  1.13.6.2  nathanw 	return SIGSEGV;
    233  1.13.6.2  nathanw     }
    234  1.13.6.2  nathanw     insn->is_advance += 2;
    235  1.13.6.2  nathanw 
    236  1.13.6.2  nathanw     /* get register index */
    237  1.13.6.2  nathanw     ea->ea_idxreg = (extword >> 12) & 0xf;
    238  1.13.6.2  nathanw     idx = frame->f_regs[ea->ea_idxreg];
    239  1.13.6.2  nathanw     if ((extword & 0x0800) == 0) {
    240  1.13.6.2  nathanw 	/* if word sized index, sign-extend */
    241  1.13.6.2  nathanw 	idx &= 0xffff;
    242  1.13.6.2  nathanw 	if (idx & 0x8000) {
    243  1.13.6.2  nathanw 	    idx |= 0xffff0000;
    244  1.13.6.2  nathanw 	}
    245  1.13.6.2  nathanw     }
    246  1.13.6.2  nathanw     /* scale register index */
    247  1.13.6.2  nathanw     idx <<= ((extword >>9) & 3);
    248  1.13.6.2  nathanw 
    249  1.13.6.2  nathanw     if ((extword & 0x100) == 0) {
    250  1.13.6.2  nathanw 	/* brief extension word - sign-extend the displacement */
    251  1.13.6.2  nathanw 	basedisp = (extword & 0xff);
    252  1.13.6.2  nathanw 	if (basedisp & 0x80) {
    253  1.13.6.2  nathanw 	    basedisp |= 0xffffff00;
    254  1.13.6.2  nathanw 	}
    255  1.13.6.2  nathanw 
    256  1.13.6.2  nathanw 	ea->ea_basedisp = idx + basedisp;
    257  1.13.6.2  nathanw 	ea->ea_outerdisp = 0;
    258  1.13.6.2  nathanw #if DEBUG_FPE
    259  1.13.6.2  nathanw 	printf("decode_ea6: brief ext word idxreg=%d, basedisp=%08x\n",
    260  1.13.6.2  nathanw 	       ea->ea_idxreg, ea->ea_basedisp);
    261  1.13.6.2  nathanw #endif
    262  1.13.6.2  nathanw     } else {
    263  1.13.6.2  nathanw 	/* full extension word */
    264  1.13.6.2  nathanw 	if (extword & 0x80) {
    265  1.13.6.2  nathanw 	    ea->ea_flags |= EA_BASE_SUPPRSS;
    266  1.13.6.2  nathanw 	}
    267  1.13.6.2  nathanw 	bd_size = ((extword >> 4) & 3) - 1;
    268  1.13.6.2  nathanw 	od_size = (extword & 3) - 1;
    269  1.13.6.2  nathanw 	sig = fetch_disp(frame, insn, bd_size, &basedisp);
    270  1.13.6.2  nathanw 	if (sig) {
    271  1.13.6.2  nathanw 	    return sig;
    272  1.13.6.2  nathanw 	}
    273  1.13.6.2  nathanw 	if (od_size >= 0) {
    274  1.13.6.2  nathanw 	    ea->ea_flags |= EA_MEM_INDIR;
    275  1.13.6.2  nathanw 	}
    276  1.13.6.2  nathanw 	sig = fetch_disp(frame, insn, od_size, &outerdisp);
    277  1.13.6.2  nathanw 	if (sig) {
    278  1.13.6.2  nathanw 	    return sig;
    279  1.13.6.2  nathanw 	}
    280  1.13.6.2  nathanw 
    281  1.13.6.2  nathanw 	switch (extword & 0x44) {
    282  1.13.6.2  nathanw 	case 0:			/* preindexed */
    283  1.13.6.2  nathanw 	    ea->ea_basedisp = basedisp + idx;
    284  1.13.6.2  nathanw 	    ea->ea_outerdisp = outerdisp;
    285  1.13.6.2  nathanw 	    break;
    286  1.13.6.2  nathanw 	case 4:			/* postindexed */
    287  1.13.6.2  nathanw 	    ea->ea_basedisp = basedisp;
    288  1.13.6.2  nathanw 	    ea->ea_outerdisp = outerdisp + idx;
    289  1.13.6.2  nathanw 	    break;
    290  1.13.6.2  nathanw 	case 0x40:		/* no index */
    291  1.13.6.2  nathanw 	    ea->ea_basedisp = basedisp;
    292  1.13.6.2  nathanw 	    ea->ea_outerdisp = outerdisp;
    293  1.13.6.2  nathanw 	    break;
    294  1.13.6.2  nathanw 	default:
    295  1.13.6.2  nathanw #ifdef DEBUG
    296  1.13.6.2  nathanw 	    printf("decode_ea6: invalid indirect mode: ext word %04x\n",
    297  1.13.6.2  nathanw 		   extword);
    298  1.13.6.2  nathanw #endif
    299  1.13.6.2  nathanw 	    return SIGILL;
    300  1.13.6.2  nathanw 	    break;
    301  1.13.6.2  nathanw 	}
    302  1.13.6.2  nathanw #if DEBUG_FPE
    303  1.13.6.2  nathanw 	printf("decode_ea6: full ext idxreg=%d, basedisp=%x, outerdisp=%x\n",
    304  1.13.6.2  nathanw 	       ea->ea_idxreg, ea->ea_basedisp, ea->ea_outerdisp);
    305  1.13.6.2  nathanw #endif
    306  1.13.6.2  nathanw     }
    307  1.13.6.2  nathanw #if DEBUG_FPE
    308  1.13.6.2  nathanw     printf("decode_ea6: regnum=%d, flags=%x\n",
    309  1.13.6.2  nathanw 	   ea->ea_regnum, ea->ea_flags);
    310  1.13.6.2  nathanw #endif
    311  1.13.6.2  nathanw     return 0;
    312  1.13.6.2  nathanw }
    313  1.13.6.2  nathanw 
    314  1.13.6.2  nathanw /*
    315  1.13.6.2  nathanw  * Load a value from an effective address.
    316  1.13.6.2  nathanw  * Returns zero on success, else signal number.
    317  1.13.6.2  nathanw  */
    318  1.13.6.2  nathanw int
    319  1.13.6.2  nathanw fpu_load_ea(frame, insn, ea, dst)
    320  1.13.6.2  nathanw      struct frame *frame;
    321  1.13.6.2  nathanw      struct instruction *insn;
    322  1.13.6.2  nathanw      struct insn_ea *ea;
    323  1.13.6.2  nathanw      char *dst;
    324  1.13.6.2  nathanw {
    325  1.13.6.2  nathanw     int *reg;
    326  1.13.6.2  nathanw     char *src;
    327  1.13.6.2  nathanw     int len, step;
    328  1.13.6.2  nathanw     int sig;
    329  1.13.6.2  nathanw 
    330  1.13.6.2  nathanw #ifdef DIAGNOSTIC
    331  1.13.6.2  nathanw     if (ea->ea_regnum & ~0xF) {
    332  1.13.6.2  nathanw 	panic("load_ea: bad regnum");
    333  1.13.6.2  nathanw     }
    334  1.13.6.2  nathanw #endif
    335  1.13.6.2  nathanw 
    336  1.13.6.2  nathanw #ifdef DEBUG_FPE
    337  1.13.6.2  nathanw     printf("load_ea: frame at %p\n", frame);
    338  1.13.6.2  nathanw #endif
    339  1.13.6.2  nathanw     /* dst is always int or larger. */
    340  1.13.6.2  nathanw     len = insn->is_datasize;
    341  1.13.6.2  nathanw     if (len < 4) {
    342  1.13.6.2  nathanw 	dst += (4 - len);
    343  1.13.6.2  nathanw     }
    344  1.13.6.2  nathanw     step = (len == 1 && ea->ea_regnum == 15 /* sp */) ? 2 : len;
    345  1.13.6.2  nathanw 
    346  1.13.6.2  nathanw #if 0
    347  1.13.6.2  nathanw     if (ea->ea_flags & EA_FRAME_EA) {
    348  1.13.6.2  nathanw 	/* Using LC040 frame EA */
    349  1.13.6.2  nathanw #ifdef DEBUG_FPE
    350  1.13.6.2  nathanw 	if (ea->ea_flags & (EA_PREDECR|EA_POSTINCR)) {
    351  1.13.6.2  nathanw 	    printf("load_ea: frame ea %08x w/r%d\n",
    352  1.13.6.2  nathanw 		   ea->ea_fea, ea->ea_regnum);
    353  1.13.6.2  nathanw 	} else {
    354  1.13.6.2  nathanw 	    printf("load_ea: frame ea %08x\n", ea->ea_fea);
    355  1.13.6.2  nathanw 	}
    356  1.13.6.2  nathanw #endif
    357  1.13.6.2  nathanw 	src = (char *)ea->ea_fea;
    358  1.13.6.2  nathanw 	copyin(src + ea->ea_moffs, dst, len);
    359  1.13.6.2  nathanw 	if (ea->ea_flags & EA_PREDECR) {
    360  1.13.6.2  nathanw 	    frame->f_regs[ea->ea_regnum] = ea->ea_fea;
    361  1.13.6.2  nathanw 	    ea->ea_fea -= step;
    362  1.13.6.2  nathanw 	    ea->ea_moffs = 0;
    363  1.13.6.2  nathanw 	} else if (ea->ea_flags & EA_POSTINCR) {
    364  1.13.6.2  nathanw 	    ea->ea_fea += step;
    365  1.13.6.2  nathanw 	    frame->f_regs[ea->ea_regnum] = ea->ea_fea;
    366  1.13.6.2  nathanw 	    ea->ea_moffs = 0;
    367  1.13.6.2  nathanw 	} else {
    368  1.13.6.2  nathanw 	    ea->ea_moffs += step;
    369  1.13.6.2  nathanw 	}
    370  1.13.6.2  nathanw 	/* That's it, folks */
    371  1.13.6.2  nathanw     } else if (ea->ea_flags & EA_DIRECT) {
    372  1.13.6.2  nathanw 	if (len > 4) {
    373  1.13.6.2  nathanw #ifdef DEBUG
    374  1.13.6.2  nathanw 	    printf("load_ea: operand doesn't fit cpu reg\n");
    375  1.13.6.2  nathanw #endif
    376  1.13.6.2  nathanw 	    return SIGILL;
    377  1.13.6.2  nathanw 	}
    378  1.13.6.2  nathanw 	if (ea->ea_moffs > 0) {
    379  1.13.6.2  nathanw #ifdef DEBUG
    380  1.13.6.2  nathanw 	    printf("load_ea: more than one move from cpu reg\n");
    381  1.13.6.2  nathanw #endif
    382  1.13.6.2  nathanw 	    return SIGILL;
    383  1.13.6.2  nathanw 	}
    384  1.13.6.2  nathanw 	src = (char *)&frame->f_regs[ea->ea_regnum];
    385  1.13.6.2  nathanw 	/* The source is an int. */
    386  1.13.6.2  nathanw 	if (len < 4) {
    387  1.13.6.2  nathanw 	    src += (4 - len);
    388  1.13.6.2  nathanw #ifdef DEBUG_FPE
    389  1.13.6.2  nathanw 	    printf("load_ea: short/byte opr - addr adjusted\n");
    390  1.13.6.2  nathanw #endif
    391  1.13.6.2  nathanw 	}
    392  1.13.6.2  nathanw #ifdef DEBUG_FPE
    393  1.13.6.2  nathanw 	printf("load_ea: src %p\n", src);
    394  1.13.6.2  nathanw #endif
    395  1.13.6.2  nathanw 	memcpy(dst, src, len);
    396  1.13.6.2  nathanw     } else
    397  1.13.6.2  nathanw #endif
    398  1.13.6.2  nathanw     if (ea->ea_flags & EA_IMMED) {
    399  1.13.6.2  nathanw #ifdef DEBUG_FPE
    400  1.13.6.2  nathanw 	printf("load_ea: immed %08x%08x%08x size %d\n",
    401  1.13.6.2  nathanw 	       ea->ea_immed[0], ea->ea_immed[1], ea->ea_immed[2], len);
    402  1.13.6.2  nathanw #endif
    403  1.13.6.2  nathanw 	src = (char *)&ea->ea_immed[0];
    404  1.13.6.2  nathanw 	if (len < 4) {
    405  1.13.6.2  nathanw 	    src += (4 - len);
    406  1.13.6.2  nathanw #ifdef DEBUG_FPE
    407  1.13.6.2  nathanw 	    printf("load_ea: short/byte immed opr - addr adjusted\n");
    408  1.13.6.2  nathanw #endif
    409  1.13.6.2  nathanw 	}
    410  1.13.6.2  nathanw 	memcpy(dst, src, len);
    411  1.13.6.2  nathanw     } else if (ea->ea_flags & EA_ABS) {
    412  1.13.6.2  nathanw #ifdef DEBUG_FPE
    413  1.13.6.2  nathanw 	printf("load_ea: abs addr %08x\n", ea->ea_absaddr);
    414  1.13.6.2  nathanw #endif
    415  1.13.6.2  nathanw 	src = (char *)ea->ea_absaddr;
    416  1.13.6.2  nathanw 	copyin(src, dst, len);
    417  1.13.6.2  nathanw     } else /* register indirect */ {
    418  1.13.6.2  nathanw 	if (ea->ea_flags & EA_PC_REL) {
    419  1.13.6.2  nathanw #ifdef DEBUG_FPE
    420  1.13.6.2  nathanw 	    printf("load_ea: using PC\n");
    421  1.13.6.2  nathanw #endif
    422  1.13.6.2  nathanw 	    reg = NULL;
    423  1.13.6.2  nathanw 	    /* Grab the register contents. 4 is offset to the first
    424  1.13.6.2  nathanw 	       extension word from the opcode */
    425  1.13.6.2  nathanw 	    src = (char *)insn->is_pc + 4;
    426  1.13.6.2  nathanw #ifdef DEBUG_FPE
    427  1.13.6.2  nathanw 	    printf("load_ea: pc relative pc+4 = %p\n", src);
    428  1.13.6.2  nathanw #endif
    429  1.13.6.2  nathanw 	} else /* not PC relative */ {
    430  1.13.6.2  nathanw #ifdef DEBUG_FPE
    431  1.13.6.2  nathanw 	    printf("load_ea: using register %c%d\n",
    432  1.13.6.2  nathanw 		   (ea->ea_regnum >= 8) ? 'a' : 'd', ea->ea_regnum & 7);
    433  1.13.6.2  nathanw #endif
    434  1.13.6.2  nathanw 	    /* point to the register */
    435  1.13.6.2  nathanw 	    reg = &frame->f_regs[ea->ea_regnum];
    436  1.13.6.2  nathanw 
    437  1.13.6.2  nathanw 	    if (ea->ea_flags & EA_PREDECR) {
    438  1.13.6.2  nathanw #ifdef DEBUG_FPE
    439  1.13.6.2  nathanw 		printf("load_ea: predecr mode - reg decremented\n");
    440  1.13.6.2  nathanw #endif
    441  1.13.6.2  nathanw 		*reg -= step;
    442  1.13.6.2  nathanw 		ea->ea_moffs = 0;
    443  1.13.6.2  nathanw 	    }
    444  1.13.6.2  nathanw 
    445  1.13.6.2  nathanw 	    /* Grab the register contents. */
    446  1.13.6.2  nathanw 	    src = (char *)*reg;
    447  1.13.6.2  nathanw #ifdef DEBUG_FPE
    448  1.13.6.2  nathanw 	    printf("load_ea: reg indirect reg = %p\n", src);
    449  1.13.6.2  nathanw #endif
    450  1.13.6.2  nathanw 	}
    451  1.13.6.2  nathanw 
    452  1.13.6.2  nathanw 	sig = calc_ea(ea, src, &src);
    453  1.13.6.2  nathanw 	if (sig)
    454  1.13.6.2  nathanw 	    return sig;
    455  1.13.6.2  nathanw 
    456  1.13.6.2  nathanw 	copyin(src + ea->ea_moffs, dst, len);
    457  1.13.6.2  nathanw 
    458  1.13.6.2  nathanw 	/* do post-increment */
    459  1.13.6.2  nathanw 	if (ea->ea_flags & EA_POSTINCR) {
    460  1.13.6.2  nathanw 	    if (ea->ea_flags & EA_PC_REL) {
    461  1.13.6.2  nathanw #ifdef DEBUG
    462  1.13.6.2  nathanw 		printf("load_ea: tried to postincrement PC\n");
    463  1.13.6.2  nathanw #endif
    464  1.13.6.2  nathanw 		return SIGILL;
    465  1.13.6.2  nathanw 	    }
    466  1.13.6.2  nathanw 	    *reg += step;
    467  1.13.6.2  nathanw 	    ea->ea_moffs = 0;
    468  1.13.6.2  nathanw #ifdef DEBUG_FPE
    469  1.13.6.2  nathanw 	    printf("load_ea: postinc mode - reg incremented\n");
    470  1.13.6.2  nathanw #endif
    471  1.13.6.2  nathanw 	} else {
    472  1.13.6.2  nathanw 	    ea->ea_moffs += len;
    473  1.13.6.2  nathanw 	}
    474  1.13.6.2  nathanw     }
    475  1.13.6.2  nathanw 
    476  1.13.6.2  nathanw     return 0;
    477  1.13.6.2  nathanw }
    478  1.13.6.2  nathanw 
    479  1.13.6.2  nathanw /*
    480  1.13.6.2  nathanw  * Store a value at the effective address.
    481  1.13.6.2  nathanw  * Returns zero on success, else signal number.
    482  1.13.6.2  nathanw  */
    483  1.13.6.2  nathanw int
    484  1.13.6.2  nathanw fpu_store_ea(frame, insn, ea, src)
    485  1.13.6.2  nathanw      struct frame *frame;
    486  1.13.6.2  nathanw      struct instruction *insn;
    487  1.13.6.2  nathanw      struct insn_ea *ea;
    488  1.13.6.2  nathanw      char *src;
    489  1.13.6.2  nathanw {
    490  1.13.6.2  nathanw     int *reg;
    491  1.13.6.2  nathanw     char *dst;
    492  1.13.6.2  nathanw     int len, step;
    493  1.13.6.2  nathanw     int sig;
    494  1.13.6.2  nathanw 
    495  1.13.6.2  nathanw #ifdef	DIAGNOSTIC
    496  1.13.6.2  nathanw     if (ea->ea_regnum & ~0xf) {
    497  1.13.6.2  nathanw 	panic("store_ea: bad regnum");
    498  1.13.6.2  nathanw     }
    499  1.13.6.2  nathanw #endif
    500  1.13.6.2  nathanw 
    501  1.13.6.2  nathanw     if (ea->ea_flags & (EA_IMMED|EA_PC_REL)) {
    502  1.13.6.2  nathanw 	/* not alterable address mode */
    503  1.13.6.2  nathanw #ifdef DEBUG
    504  1.13.6.2  nathanw 	printf("store_ea: not alterable address mode\n");
    505  1.13.6.2  nathanw #endif
    506  1.13.6.2  nathanw 	return SIGILL;
    507  1.13.6.2  nathanw     }
    508  1.13.6.2  nathanw 
    509  1.13.6.2  nathanw     /* src is always int or larger. */
    510  1.13.6.2  nathanw     len = insn->is_datasize;
    511  1.13.6.2  nathanw     if (len < 4) {
    512  1.13.6.2  nathanw 	src += (4 - len);
    513  1.13.6.2  nathanw     }
    514  1.13.6.2  nathanw     step = (len == 1 && ea->ea_regnum == 15 /* sp */) ? 2 : len;
    515  1.13.6.2  nathanw 
    516  1.13.6.2  nathanw     if (ea->ea_flags & EA_FRAME_EA) {
    517  1.13.6.2  nathanw 	/* Using LC040 frame EA */
    518  1.13.6.2  nathanw #ifdef DEBUG_FPE
    519  1.13.6.2  nathanw 	if (ea->ea_flags & (EA_PREDECR|EA_POSTINCR)) {
    520  1.13.6.2  nathanw 	    printf("store_ea: frame ea %08x w/r%d\n",
    521  1.13.6.2  nathanw 		   ea->ea_fea, ea->ea_regnum);
    522  1.13.6.2  nathanw 	} else {
    523  1.13.6.2  nathanw 	    printf("store_ea: frame ea %08x\n", ea->ea_fea);
    524  1.13.6.2  nathanw 	}
    525  1.13.6.2  nathanw #endif
    526  1.13.6.2  nathanw 	dst = (char *)ea->ea_fea;
    527  1.13.6.2  nathanw 	copyout(src, dst + ea->ea_moffs, len);
    528  1.13.6.2  nathanw 	if (ea->ea_flags & EA_PREDECR) {
    529  1.13.6.2  nathanw 	    frame->f_regs[ea->ea_regnum] = ea->ea_fea;
    530  1.13.6.2  nathanw 	    ea->ea_fea -= step;
    531  1.13.6.2  nathanw 	    ea->ea_moffs = 0;
    532  1.13.6.2  nathanw 	} else if (ea->ea_flags & EA_POSTINCR) {
    533  1.13.6.2  nathanw 	    ea->ea_fea += step;
    534  1.13.6.2  nathanw 	    frame->f_regs[ea->ea_regnum] = ea->ea_fea;
    535  1.13.6.2  nathanw 	    ea->ea_moffs = 0;
    536  1.13.6.2  nathanw 	} else {
    537  1.13.6.2  nathanw 	    ea->ea_moffs += step;
    538  1.13.6.2  nathanw 	}
    539  1.13.6.2  nathanw 	/* That's it, folks */
    540  1.13.6.2  nathanw     } else if (ea->ea_flags & EA_ABS) {
    541  1.13.6.2  nathanw #ifdef DEBUG_FPE
    542  1.13.6.2  nathanw 	printf("store_ea: abs addr %08x\n", ea->ea_absaddr);
    543  1.13.6.2  nathanw #endif
    544  1.13.6.2  nathanw 	dst = (char *)ea->ea_absaddr;
    545  1.13.6.2  nathanw 	copyout(src, dst + ea->ea_moffs, len);
    546  1.13.6.2  nathanw 	ea->ea_moffs += len;
    547  1.13.6.2  nathanw     } else if (ea->ea_flags & EA_DIRECT) {
    548  1.13.6.2  nathanw 	if (len > 4) {
    549  1.13.6.2  nathanw #ifdef DEBUG
    550  1.13.6.2  nathanw 	    printf("store_ea: operand doesn't fit cpu reg\n");
    551  1.13.6.2  nathanw #endif
    552  1.13.6.2  nathanw 	    return SIGILL;
    553  1.13.6.2  nathanw 	}
    554  1.13.6.2  nathanw 	if (ea->ea_moffs > 0) {
    555  1.13.6.2  nathanw #ifdef DEBUG
    556  1.13.6.2  nathanw 	    printf("store_ea: more than one move to cpu reg\n");
    557  1.13.6.2  nathanw #endif
    558  1.13.6.2  nathanw 	    return SIGILL;
    559  1.13.6.2  nathanw 	}
    560  1.13.6.2  nathanw 	dst = (char*)&frame->f_regs[ea->ea_regnum];
    561  1.13.6.2  nathanw 	/* The destination is an int. */
    562  1.13.6.2  nathanw 	if (len < 4) {
    563  1.13.6.2  nathanw 	    dst += (4 - len);
    564  1.13.6.2  nathanw #ifdef DEBUG_FPE
    565  1.13.6.2  nathanw 	    printf("store_ea: short/byte opr - dst addr adjusted\n");
    566  1.13.6.2  nathanw #endif
    567  1.13.6.2  nathanw 	}
    568  1.13.6.2  nathanw #ifdef DEBUG_FPE
    569  1.13.6.2  nathanw 	printf("store_ea: dst %p\n", dst);
    570  1.13.6.2  nathanw #endif
    571  1.13.6.2  nathanw 	memcpy(dst, src, len);
    572  1.13.6.2  nathanw     } else /* One of MANY indirect forms... */ {
    573  1.13.6.2  nathanw #ifdef DEBUG_FPE
    574  1.13.6.2  nathanw 	printf("store_ea: using register %c%d\n",
    575  1.13.6.2  nathanw 	       (ea->ea_regnum >= 8) ? 'a' : 'd', ea->ea_regnum & 7);
    576  1.13.6.2  nathanw #endif
    577  1.13.6.2  nathanw 	/* point to the register */
    578  1.13.6.2  nathanw 	reg = &(frame->f_regs[ea->ea_regnum]);
    579  1.13.6.2  nathanw 
    580  1.13.6.2  nathanw 	/* do pre-decrement */
    581  1.13.6.2  nathanw 	if (ea->ea_flags & EA_PREDECR) {
    582  1.13.6.2  nathanw #ifdef DEBUG_FPE
    583  1.13.6.2  nathanw 	    printf("store_ea: predecr mode - reg decremented\n");
    584  1.13.6.2  nathanw #endif
    585  1.13.6.2  nathanw 	    *reg -= step;
    586  1.13.6.2  nathanw 	    ea->ea_moffs = 0;
    587  1.13.6.2  nathanw 	}
    588  1.13.6.2  nathanw 
    589  1.13.6.2  nathanw 	/* calculate the effective address */
    590  1.13.6.2  nathanw 	sig = calc_ea(ea, (char *)*reg, &dst);
    591  1.13.6.2  nathanw 	if (sig)
    592  1.13.6.2  nathanw 	    return sig;
    593  1.13.6.2  nathanw 
    594  1.13.6.2  nathanw #ifdef DEBUG_FPE
    595  1.13.6.2  nathanw 	printf("store_ea: dst addr=%p+%d\n", dst, ea->ea_moffs);
    596  1.13.6.2  nathanw #endif
    597  1.13.6.2  nathanw 	copyout(src, dst + ea->ea_moffs, len);
    598  1.13.6.2  nathanw 
    599  1.13.6.2  nathanw 	/* do post-increment */
    600  1.13.6.2  nathanw 	if (ea->ea_flags & EA_POSTINCR) {
    601  1.13.6.2  nathanw 	    *reg += step;
    602  1.13.6.2  nathanw 	    ea->ea_moffs = 0;
    603  1.13.6.2  nathanw #ifdef DEBUG_FPE
    604  1.13.6.2  nathanw 	    printf("store_ea: postinc mode - reg incremented\n");
    605  1.13.6.2  nathanw #endif
    606  1.13.6.2  nathanw 	} else {
    607  1.13.6.2  nathanw 	    ea->ea_moffs += len;
    608  1.13.6.2  nathanw 	}
    609  1.13.6.2  nathanw     }
    610  1.13.6.2  nathanw 
    611  1.13.6.2  nathanw     return 0;
    612  1.13.6.2  nathanw }
    613  1.13.6.2  nathanw 
    614  1.13.6.2  nathanw /*
    615  1.13.6.2  nathanw  * fetch_immed: fetch immediate operand
    616  1.13.6.2  nathanw  */
    617  1.13.6.2  nathanw static int
    618  1.13.6.2  nathanw fetch_immed(frame, insn, dst)
    619  1.13.6.2  nathanw      struct frame *frame;
    620  1.13.6.2  nathanw      struct instruction *insn;
    621  1.13.6.2  nathanw      int *dst;
    622  1.13.6.2  nathanw {
    623  1.13.6.2  nathanw     int data, ext_bytes;
    624  1.13.6.2  nathanw 
    625  1.13.6.2  nathanw     ext_bytes = insn->is_datasize;
    626  1.13.6.2  nathanw 
    627  1.13.6.2  nathanw     if (0 < ext_bytes) {
    628  1.13.6.2  nathanw 	data = fusword((void *) (insn->is_pc + insn->is_advance));
    629  1.13.6.2  nathanw 	if (data < 0) {
    630  1.13.6.2  nathanw 	    return SIGSEGV;
    631  1.13.6.2  nathanw 	}
    632  1.13.6.2  nathanw 	if (ext_bytes == 1) {
    633  1.13.6.2  nathanw 	    /* sign-extend byte to long */
    634  1.13.6.2  nathanw 	    data &= 0xff;
    635  1.13.6.2  nathanw 	    if (data & 0x80) {
    636  1.13.6.2  nathanw 		data |= 0xffffff00;
    637  1.13.6.2  nathanw 	    }
    638  1.13.6.2  nathanw 	} else if (ext_bytes == 2) {
    639  1.13.6.2  nathanw 	    /* sign-extend word to long */
    640  1.13.6.2  nathanw 	    data &= 0xffff;
    641  1.13.6.2  nathanw 	    if (data & 0x8000) {
    642  1.13.6.2  nathanw 		data |= 0xffff0000;
    643  1.13.6.2  nathanw 	    }
    644  1.13.6.2  nathanw 	}
    645  1.13.6.2  nathanw 	insn->is_advance += 2;
    646  1.13.6.2  nathanw 	dst[0] = data;
    647  1.13.6.2  nathanw     }
    648  1.13.6.2  nathanw     if (2 < ext_bytes) {
    649  1.13.6.2  nathanw 	data = fusword((void *) (insn->is_pc + insn->is_advance));
    650  1.13.6.2  nathanw 	if (data < 0) {
    651  1.13.6.2  nathanw 	    return SIGSEGV;
    652  1.13.6.2  nathanw 	}
    653  1.13.6.2  nathanw 	insn->is_advance += 2;
    654  1.13.6.2  nathanw 	dst[0] <<= 16;
    655  1.13.6.2  nathanw 	dst[0] |= data;
    656  1.13.6.2  nathanw     }
    657  1.13.6.2  nathanw     if (4 < ext_bytes) {
    658  1.13.6.2  nathanw 	data = fusword((void *) (insn->is_pc + insn->is_advance));
    659  1.13.6.2  nathanw 	if (data < 0) {
    660  1.13.6.2  nathanw 	    return SIGSEGV;
    661  1.13.6.2  nathanw 	}
    662  1.13.6.2  nathanw 	dst[1] = data << 16;
    663  1.13.6.2  nathanw 	data = fusword((void *) (insn->is_pc + insn->is_advance + 2));
    664  1.13.6.2  nathanw 	if (data < 0) {
    665  1.13.6.2  nathanw 	    return SIGSEGV;
    666  1.13.6.2  nathanw 	}
    667  1.13.6.2  nathanw 	insn->is_advance += 4;
    668  1.13.6.2  nathanw 	dst[1] |= data;
    669  1.13.6.2  nathanw     }
    670  1.13.6.2  nathanw     if (8 < ext_bytes) {
    671  1.13.6.2  nathanw 	data = fusword((void *) (insn->is_pc + insn->is_advance));
    672  1.13.6.2  nathanw 	if (data < 0) {
    673  1.13.6.2  nathanw 	    return SIGSEGV;
    674  1.13.6.2  nathanw 	}
    675  1.13.6.2  nathanw 	dst[2] = data << 16;
    676  1.13.6.2  nathanw 	data = fusword((void *) (insn->is_pc + insn->is_advance + 2));
    677  1.13.6.2  nathanw 	if (data < 0) {
    678  1.13.6.2  nathanw 	    return SIGSEGV;
    679  1.13.6.2  nathanw 	}
    680  1.13.6.2  nathanw 	insn->is_advance += 4;
    681  1.13.6.2  nathanw 	dst[2] |= data;
    682  1.13.6.2  nathanw     }
    683  1.13.6.2  nathanw 
    684  1.13.6.2  nathanw     return 0;
    685  1.13.6.2  nathanw }
    686  1.13.6.2  nathanw 
    687  1.13.6.2  nathanw /*
    688  1.13.6.2  nathanw  * fetch_disp: fetch displacement in full extension words
    689  1.13.6.2  nathanw  */
    690  1.13.6.2  nathanw static int
    691  1.13.6.2  nathanw fetch_disp(frame, insn, size, res)
    692  1.13.6.2  nathanw      struct frame *frame;
    693  1.13.6.2  nathanw      struct instruction *insn;
    694  1.13.6.2  nathanw      int size, *res;
    695  1.13.6.2  nathanw {
    696  1.13.6.2  nathanw     int disp, word;
    697  1.13.6.2  nathanw 
    698  1.13.6.2  nathanw     if (size == 1) {
    699  1.13.6.2  nathanw 	word = fusword((void *) (insn->is_pc + insn->is_advance));
    700  1.13.6.2  nathanw 	if (word < 0) {
    701  1.13.6.2  nathanw 	    return SIGSEGV;
    702  1.13.6.2  nathanw 	}
    703  1.13.6.2  nathanw 	disp = word & 0xffff;
    704  1.13.6.2  nathanw 	if (disp & 0x8000) {
    705  1.13.6.2  nathanw 	    /* sign-extend */
    706  1.13.6.2  nathanw 	    disp |= 0xffff0000;
    707  1.13.6.2  nathanw 	}
    708  1.13.6.2  nathanw 	insn->is_advance += 2;
    709  1.13.6.2  nathanw     } else if (size == 2) {
    710  1.13.6.2  nathanw 	word = fusword((void *) (insn->is_pc + insn->is_advance));
    711  1.13.6.2  nathanw 	if (word < 0) {
    712  1.13.6.2  nathanw 	    return SIGSEGV;
    713  1.13.6.2  nathanw 	}
    714  1.13.6.2  nathanw 	disp = word << 16;
    715  1.13.6.2  nathanw 	word = fusword((void *) (insn->is_pc + insn->is_advance + 2));
    716  1.13.6.2  nathanw 	if (word < 0) {
    717  1.13.6.2  nathanw 	    return SIGSEGV;
    718  1.13.6.2  nathanw 	}
    719  1.13.6.2  nathanw 	disp |= (word & 0xffff);
    720  1.13.6.2  nathanw 	insn->is_advance += 4;
    721  1.13.6.2  nathanw     } else {
    722  1.13.6.2  nathanw 	disp = 0;
    723  1.13.6.2  nathanw     }
    724  1.13.6.2  nathanw     *res = disp;
    725  1.13.6.2  nathanw     return 0;
    726  1.13.6.2  nathanw }
    727  1.13.6.2  nathanw 
    728  1.13.6.2  nathanw /*
    729  1.13.6.2  nathanw  * Calculates an effective address for all address modes except for
    730  1.13.6.2  nathanw  * register direct, absolute, and immediate modes.  However, it does
    731  1.13.6.2  nathanw  * not take care of predecrement/postincrement of register content.
    732  1.13.6.2  nathanw  * Returns a signal value (0 == no error).
    733  1.13.6.2  nathanw  */
    734  1.13.6.2  nathanw static int
    735  1.13.6.2  nathanw calc_ea(ea, ptr, eaddr)
    736  1.13.6.2  nathanw      struct insn_ea *ea;
    737  1.13.6.2  nathanw      char *ptr;		/* base address (usually a register content) */
    738  1.13.6.2  nathanw      char **eaddr;	/* pointer to result pointer */
    739  1.13.6.2  nathanw {
    740  1.13.6.2  nathanw     int data, word;
    741  1.13.6.2  nathanw 
    742  1.13.6.2  nathanw #if DEBUG_FPE
    743  1.13.6.2  nathanw     printf("calc_ea: reg indirect (reg) = %p\n", ptr);
    744  1.13.6.2  nathanw #endif
    745  1.13.6.2  nathanw 
    746  1.13.6.2  nathanw     if (ea->ea_flags & EA_OFFSET) {
    747  1.13.6.2  nathanw 	/* apply the signed offset */
    748  1.13.6.2  nathanw #if DEBUG_FPE
    749  1.13.6.2  nathanw 	printf("calc_ea: offset %d\n", ea->ea_offset);
    750  1.13.6.2  nathanw #endif
    751  1.13.6.2  nathanw 	ptr += ea->ea_offset;
    752  1.13.6.2  nathanw     } else if (ea->ea_flags & EA_INDEXED) {
    753  1.13.6.2  nathanw #if DEBUG_FPE
    754  1.13.6.2  nathanw 	printf("calc_ea: indexed mode\n");
    755  1.13.6.2  nathanw #endif
    756  1.13.6.2  nathanw 
    757  1.13.6.2  nathanw 	if (ea->ea_flags & EA_BASE_SUPPRSS) {
    758  1.13.6.2  nathanw 	    /* base register is suppressed */
    759  1.13.6.2  nathanw 	    ptr = (char *)ea->ea_basedisp;
    760  1.13.6.2  nathanw 	} else {
    761  1.13.6.2  nathanw 	    ptr += ea->ea_basedisp;
    762  1.13.6.2  nathanw 	}
    763  1.13.6.2  nathanw 
    764  1.13.6.2  nathanw 	if (ea->ea_flags & EA_MEM_INDIR) {
    765  1.13.6.2  nathanw #if DEBUG_FPE
    766  1.13.6.2  nathanw 	    printf("calc_ea: mem indir mode: basedisp=%08x, outerdisp=%08x\n",
    767  1.13.6.2  nathanw 		   ea->ea_basedisp, ea->ea_outerdisp);
    768  1.13.6.2  nathanw 	    printf("calc_ea: addr fetched from %p\n", ptr);
    769  1.13.6.2  nathanw #endif
    770  1.13.6.2  nathanw 	    /* memory indirect modes */
    771  1.13.6.2  nathanw 	    word = fusword(ptr);
    772  1.13.6.2  nathanw 	    if (word < 0) {
    773  1.13.6.2  nathanw 		return SIGSEGV;
    774  1.13.6.2  nathanw 	    }
    775  1.13.6.2  nathanw 	    word <<= 16;
    776  1.13.6.2  nathanw 	    data = fusword(ptr + 2);
    777  1.13.6.2  nathanw 	    if (data < 0) {
    778  1.13.6.2  nathanw 		return SIGSEGV;
    779  1.13.6.2  nathanw 	    }
    780  1.13.6.2  nathanw 	    word |= data;
    781  1.13.6.2  nathanw #if DEBUG_FPE
    782  1.13.6.2  nathanw 	    printf("calc_ea: fetched ptr 0x%08x\n", word);
    783  1.13.6.2  nathanw #endif
    784  1.13.6.2  nathanw 	    ptr = (char *)word + ea->ea_outerdisp;
    785  1.13.6.2  nathanw 	}
    786  1.13.6.2  nathanw     }
    787  1.13.6.2  nathanw 
    788  1.13.6.2  nathanw     *eaddr = ptr;
    789  1.13.6.2  nathanw 
    790  1.13.6.2  nathanw     return 0;
    791  1.13.6.2  nathanw }
    792