2 * Simulator for the Renesas (formerly Hitachi) H8/300 architecture.
4 * Written by Steve Chamberlain of Cygnus Support. sac@cygnus.com
6 * This file is part of H8/300 sim
9 * THIS SOFTWARE IS NOT COPYRIGHTED
11 * Cygnus offers the following for use in the public domain. Cygnus makes no
12 * warranty with regard to the software or its performance and the user
13 * accepts the software "AS IS" with all faults.
15 * CYGNUS DISCLAIMS ANY WARRANTIES, EXPRESS OR IMPLIED, WITH REGARD TO THIS
16 * SOFTWARE INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY
17 * AND FITNESS FOR A PARTICULAR PURPOSE.
27 #ifdef HAVE_SYS_PARAM_H
28 #include <sys/param.h>
33 #include "gdb/sim-h8300.h"
35 #include "sys/types.h"
43 host_callback *sim_callback;
45 static SIM_OPEN_KIND sim_kind;
48 /* FIXME: Needs to live in header file.
49 This header should also include the things in remote-sim.h.
50 One could move this to remote-sim.h but this function isn't needed
52 static void set_simcache_size (SIM_DESC, int);
54 #define X(op, size) (op * 4 + size)
56 #define SP (h8300hmode ? SL : SW)
58 #define h8_opcodes ops
60 #include "opcode/h8300.h"
62 /* CPU data object: */
65 sim_state_initialize (SIM_DESC sd, sim_cpu *cpu)
67 /* FIXME: not really necessary, since sim_cpu_alloc calls zalloc. */
69 memset (&cpu->regs, 0, sizeof(cpu->regs));
70 cpu->regs[SBR_REGNUM] = 0xFFFFFF00;
72 cpu->delayed_branch = 0;
77 /* Initialize local simulator state. */
79 sd->sim_cache_size = 0;
85 memset (&cpu->stats, 0, sizeof (cpu->stats));
91 h8_get_pc (SIM_DESC sd)
93 return (STATE_CPU (sd, 0)) -> pc;
97 h8_set_pc (SIM_DESC sd, unsigned int val)
99 (STATE_CPU (sd, 0)) -> pc = val;
103 h8_get_ccr (SIM_DESC sd)
105 return (STATE_CPU (sd, 0)) -> regs[CCR_REGNUM];
109 h8_set_ccr (SIM_DESC sd, unsigned int val)
111 (STATE_CPU (sd, 0)) -> regs[CCR_REGNUM] = val;
115 h8_get_exr (SIM_DESC sd)
117 return (STATE_CPU (sd, 0)) -> regs[EXR_REGNUM];
121 h8_set_exr (SIM_DESC sd, unsigned int val)
123 (STATE_CPU (sd, 0)) -> regs[EXR_REGNUM] = val;
127 h8_get_sbr (SIM_DESC sd)
129 return (STATE_CPU (sd, 0)) -> regs[SBR_REGNUM];
133 h8_set_sbr (SIM_DESC sd, int val)
135 (STATE_CPU (sd, 0)) -> regs[SBR_REGNUM] = val;
139 h8_get_vbr (SIM_DESC sd)
141 return (STATE_CPU (sd, 0)) -> regs[VBR_REGNUM];
145 h8_set_vbr (SIM_DESC sd, int val)
147 (STATE_CPU (sd, 0)) -> regs[VBR_REGNUM] = val;
151 h8_get_cache_top (SIM_DESC sd)
153 return sd -> cache_top;
157 h8_set_cache_top (SIM_DESC sd, int val)
159 sd -> cache_top = val;
163 h8_get_mask (SIM_DESC sd)
165 return (STATE_CPU (sd, 0)) -> mask;
169 h8_set_mask (SIM_DESC sd, int val)
171 (STATE_CPU (sd, 0)) -> mask = val;
175 h8_get_exception (SIM_DESC sd)
177 return (STATE_CPU (sd, 0)) -> exception;
181 h8_set_exception (SIM_DESC sd, int val)
183 (STATE_CPU (sd, 0)) -> exception = val;
186 static enum h8300_sim_state
187 h8_get_state (SIM_DESC sd)
193 h8_set_state (SIM_DESC sd, enum h8300_sim_state val)
199 h8_get_cycles (SIM_DESC sd)
201 return (STATE_CPU (sd, 0)) -> regs[CYCLE_REGNUM];
205 h8_set_cycles (SIM_DESC sd, unsigned int val)
207 (STATE_CPU (sd, 0)) -> regs[CYCLE_REGNUM] = val;
211 h8_get_insts (SIM_DESC sd)
213 return (STATE_CPU (sd, 0)) -> regs[INST_REGNUM];
217 h8_set_insts (SIM_DESC sd, unsigned int val)
219 (STATE_CPU (sd, 0)) -> regs[INST_REGNUM] = val;
223 h8_get_ticks (SIM_DESC sd)
225 return (STATE_CPU (sd, 0)) -> regs[TICK_REGNUM];
229 h8_set_ticks (SIM_DESC sd, unsigned int val)
231 (STATE_CPU (sd, 0)) -> regs[TICK_REGNUM] = val;
235 h8_get_mach (SIM_DESC sd)
237 return (STATE_CPU (sd, 0)) -> regs[MACH_REGNUM];
241 h8_set_mach (SIM_DESC sd, unsigned int val)
243 (STATE_CPU (sd, 0)) -> regs[MACH_REGNUM] = val;
247 h8_get_macl (SIM_DESC sd)
249 return (STATE_CPU (sd, 0)) -> regs[MACL_REGNUM];
253 h8_set_macl (SIM_DESC sd, unsigned int val)
255 (STATE_CPU (sd, 0)) -> regs[MACL_REGNUM] = val;
259 h8_get_compiles (SIM_DESC sd)
261 return sd -> compiles;
265 h8_increment_compiles (SIM_DESC sd)
270 static unsigned int *
271 h8_get_reg_buf (SIM_DESC sd)
273 return &(((STATE_CPU (sd, 0)) -> regs)[0]);
277 h8_get_reg (SIM_DESC sd, int regnum)
279 return (STATE_CPU (sd, 0)) -> regs[regnum];
283 h8_set_reg (SIM_DESC sd, int regnum, int val)
285 (STATE_CPU (sd, 0)) -> regs[regnum] = val;
290 h8_get_stats (SIM_DESC sd, int idx)
292 return sd -> stats[idx];
296 h8_increment_stats (SIM_DESC sd, int idx)
302 static unsigned short *
303 h8_get_cache_idx_buf (SIM_DESC sd)
305 return sd -> cache_idx;
309 h8_set_cache_idx_buf (SIM_DESC sd, unsigned short *ptr)
311 sd -> cache_idx = ptr;
314 static unsigned short
315 h8_get_cache_idx (SIM_DESC sd, unsigned int idx)
317 if (idx > sd->memory_size)
318 return (unsigned short) -1;
319 return sd -> cache_idx[idx];
323 h8_set_cache_idx (SIM_DESC sd, int idx, unsigned int val)
325 sd -> cache_idx[idx] = (unsigned short) val;
328 static unsigned char *
329 h8_get_memory_buf (SIM_DESC sd)
331 return (STATE_CPU (sd, 0)) -> memory;
335 h8_set_memory_buf (SIM_DESC sd, unsigned char *ptr)
337 (STATE_CPU (sd, 0)) -> memory = ptr;
341 h8_get_memory (SIM_DESC sd, int idx)
343 return (STATE_CPU (sd, 0)) -> memory[idx];
347 h8_set_memory (SIM_DESC sd, int idx, unsigned int val)
349 (STATE_CPU (sd, 0)) -> memory[idx] = (unsigned char) val;
352 static unsigned char *
353 h8_get_eightbit_buf (SIM_DESC sd)
355 return (STATE_CPU (sd, 0)) -> eightbit;
359 h8_set_eightbit_buf (SIM_DESC sd, unsigned char *ptr)
361 (STATE_CPU (sd, 0)) -> eightbit = ptr;
365 h8_get_eightbit (SIM_DESC sd, int idx)
367 return (STATE_CPU (sd, 0)) -> eightbit[idx];
371 h8_set_eightbit (SIM_DESC sd, int idx, unsigned int val)
373 (STATE_CPU (sd, 0)) -> eightbit[idx] = (unsigned char) val;
377 h8_get_delayed_branch (SIM_DESC sd)
379 return (STATE_CPU (sd, 0)) -> delayed_branch;
383 h8_set_delayed_branch (SIM_DESC sd, unsigned int dest)
385 (STATE_CPU (sd, 0)) -> delayed_branch = dest;
389 h8_get_command_line (SIM_DESC sd)
391 return (STATE_CPU (sd, 0)) -> command_line;
395 h8_set_command_line (SIM_DESC sd, char ** val)
397 (STATE_CPU (sd, 0)) -> command_line = val;
401 h8_get_cmdline_arg (SIM_DESC sd, int index)
403 return (STATE_CPU (sd, 0)) -> command_line[index];
407 h8_set_cmdline_arg (SIM_DESC sd, int index, char * val)
409 (STATE_CPU (sd, 0)) -> command_line[index] = val;
412 /* MAC Saturation Mode */
414 h8_get_macS (SIM_DESC sd)
416 return (STATE_CPU (sd, 0)) -> macS;
420 h8_set_macS (SIM_DESC sd, int val)
422 (STATE_CPU (sd, 0)) -> macS = (val != 0);
427 h8_get_macZ (SIM_DESC sd)
429 return (STATE_CPU (sd, 0)) -> macZ;
433 h8_set_macZ (SIM_DESC sd, int val)
435 (STATE_CPU (sd, 0)) -> macZ = (val != 0);
438 /* MAC Negative Flag */
440 h8_get_macN (SIM_DESC sd)
442 return (STATE_CPU (sd, 0)) -> macN;
446 h8_set_macN (SIM_DESC sd, int val)
448 (STATE_CPU (sd, 0)) -> macN = (val != 0);
451 /* MAC Overflow Flag */
453 h8_get_macV (SIM_DESC sd)
455 return (STATE_CPU (sd, 0)) -> macV;
459 h8_set_macV (SIM_DESC sd, int val)
461 (STATE_CPU (sd, 0)) -> macV = (val != 0);
464 /* End CPU data object. */
466 /* The rate at which to call the host's poll_quit callback. */
468 enum { POLL_QUIT_INTERVAL = 0x80000 };
470 #define LOW_BYTE(x) ((x) & 0xff)
471 #define HIGH_BYTE(x) (((x) >> 8) & 0xff)
472 #define P(X, Y) ((X << 8) | Y)
481 #define I (intMaskBit != 0)
483 #define BUILDSR(SD) \
484 h8_set_ccr (SD, (I << 7) | (UI << 6) | (H << 5) | (U << 4) \
485 | (N << 3) | (Z << 2) | (V << 1) | C)
488 /* Get Status Register (flags). */ \
489 c = (h8_get_ccr (sd) >> 0) & 1; \
490 v = (h8_get_ccr (sd) >> 1) & 1; \
491 nz = !((h8_get_ccr (sd) >> 2) & 1); \
492 n = (h8_get_ccr (sd) >> 3) & 1; \
493 u = (h8_get_ccr (sd) >> 4) & 1; \
494 h = (h8_get_ccr (sd) >> 5) & 1; \
495 ui = ((h8_get_ccr (sd) >> 6) & 1); \
496 intMaskBit = (h8_get_ccr (sd) >> 7) & 1
499 #ifdef __CHAR_IS_SIGNED__
500 #define SEXTCHAR(x) ((char) (x))
504 #define SEXTCHAR(x) ((x & 0x80) ? (x | ~0xff) : x & 0xff)
507 #define UEXTCHAR(x) ((x) & 0xff)
508 #define UEXTSHORT(x) ((x) & 0xffff)
509 #define SEXTSHORT(x) ((short) (x))
515 static int memory_size;
520 return time (0); /* WinXX HAS UNIX like 'time', so why not use it? */
542 return h8300hmode ? SL : SW;
547 /* Simulate an indirection / dereference.
548 return 0 for success, -1 for failure.
552 lvalue (SIM_DESC sd, int x, int rn, unsigned int *val)
554 if (val == NULL) /* Paranoia. */
560 if (rn == ZERO_REGNUM)
561 *val = X (OP_IMM, SP);
563 *val = X (OP_REG, SP);
566 *val = X (OP_MEM, SP);
569 sim_engine_set_run_state (sd, sim_stopped, SIGSEGV);
587 decode (SIM_DESC sd, int addr, unsigned char *data, decoded_inst *dst)
589 int cst[3] = {0, 0, 0};
590 int reg[3] = {0, 0, 0};
591 int rdisp[3] = {0, 0, 0};
593 const struct h8_opcode *q;
598 /* Find the exact opcode/arg combo. */
599 for (q = h8_opcodes; q->name; q++)
601 op_type *nib = q->data.nib;
602 unsigned int len = 0;
604 if ((q->available == AV_H8SX && !h8300sxmode) ||
605 (q->available == AV_H8S && !h8300smode) ||
606 (q->available == AV_H8H && !h8300hmode))
611 op_type looking_for = *nib;
612 int thisnib = data[len / 2];
614 thisnib = (len & 1) ? (thisnib & 0xf) : ((thisnib >> 4) & 0xf);
615 opnum = ((looking_for & OP3) ? 2 :
616 (looking_for & DST) ? 1 : 0);
618 if (looking_for < 16 && looking_for >= 0)
620 if (looking_for != thisnib)
625 if (looking_for & B31)
627 if (!((thisnib & 0x8) != 0))
630 looking_for = (op_type) (looking_for & ~B31);
633 else if (looking_for & B30)
635 if (!((thisnib & 0x8) == 0))
638 looking_for = (op_type) (looking_for & ~B30);
641 if (looking_for & B21)
643 if (!((thisnib & 0x4) != 0))
646 looking_for = (op_type) (looking_for & ~B21);
649 else if (looking_for & B20)
651 if (!((thisnib & 0x4) == 0))
654 looking_for = (op_type) (looking_for & ~B20);
657 if (looking_for & B11)
659 if (!((thisnib & 0x2) != 0))
662 looking_for = (op_type) (looking_for & ~B11);
665 else if (looking_for & B10)
667 if (!((thisnib & 0x2) == 0))
670 looking_for = (op_type) (looking_for & ~B10);
673 if (looking_for & B01)
675 if (!((thisnib & 0x1) != 0))
678 looking_for = (op_type) (looking_for & ~B01);
681 else if (looking_for & B00)
683 if (!((thisnib & 0x1) == 0))
686 looking_for = (op_type) (looking_for & ~B00);
689 if (looking_for & IGNORE)
691 /* Hitachi has declared that IGNORE must be zero. */
695 else if ((looking_for & MODE) == DATA)
697 ; /* Skip embedded data. */
699 else if ((looking_for & MODE) == DBIT)
701 /* Exclude adds/subs by looking at bit 0 and 2, and
702 make sure the operand size, either w or l,
703 matches by looking at bit 1. */
704 if ((looking_for & 7) != (thisnib & 7))
707 cst[opnum] = (thisnib & 0x8) ? 2 : 1;
709 else if ((looking_for & MODE) == REG ||
710 (looking_for & MODE) == LOWREG ||
711 (looking_for & MODE) == IND ||
712 (looking_for & MODE) == PREINC ||
713 (looking_for & MODE) == POSTINC ||
714 (looking_for & MODE) == PREDEC ||
715 (looking_for & MODE) == POSTDEC)
717 reg[opnum] = thisnib;
719 else if (looking_for & CTRL)
722 if (((looking_for & MODE) == CCR && (thisnib != C_CCR)) ||
723 ((looking_for & MODE) == EXR && (thisnib != C_EXR)) ||
724 ((looking_for & MODE) == MACH && (thisnib != C_MACH)) ||
725 ((looking_for & MODE) == MACL && (thisnib != C_MACL)) ||
726 ((looking_for & MODE) == VBR && (thisnib != C_VBR)) ||
727 ((looking_for & MODE) == SBR && (thisnib != C_SBR)))
729 if (((looking_for & MODE) == CCR_EXR &&
730 (thisnib != C_CCR && thisnib != C_EXR)) ||
731 ((looking_for & MODE) == VBR_SBR &&
732 (thisnib != C_VBR && thisnib != C_SBR)) ||
733 ((looking_for & MODE) == MACREG &&
734 (thisnib != C_MACH && thisnib != C_MACL)))
736 if (((looking_for & MODE) == CC_EX_VB_SB &&
737 (thisnib != C_CCR && thisnib != C_EXR &&
738 thisnib != C_VBR && thisnib != C_SBR)))
741 reg[opnum] = thisnib;
743 else if ((looking_for & MODE) == ABS)
745 /* Absolute addresses are unsigned. */
746 switch (looking_for & SIZE)
749 cst[opnum] = UEXTCHAR (data[len / 2]);
753 cst[opnum] = (data[len / 2] << 8) + data[len / 2 + 1];
757 (data[len / 2 + 0] << 24) +
758 (data[len / 2 + 1] << 16) +
759 (data[len / 2 + 2] << 8) +
763 printf ("decode: bad size ABS: %d\n",
764 (looking_for & SIZE));
768 else if ((looking_for & MODE) == DISP ||
769 (looking_for & MODE) == PCREL ||
770 (looking_for & MODE) == INDEXB ||
771 (looking_for & MODE) == INDEXW ||
772 (looking_for & MODE) == INDEXL)
775 switch (looking_for & SIZE)
778 cst[opnum] = thisnib & 3;
780 /* DISP2 special treatment. */
781 if ((looking_for & MODE) == DISP)
783 switch (OP_SIZE (q->how)) {
795 cst[opnum] = SEXTCHAR (data[len / 2]);
798 cst[opnum] = (data[len / 2] << 8) + data[len / 2 + 1];
799 cst[opnum] = (short) cst[opnum]; /* Sign extend. */
802 cst[opnum] = (data[len / 2] << 8) + data[len / 2 + 1];
806 (data[len / 2 + 0] << 24) +
807 (data[len / 2 + 1] << 16) +
808 (data[len / 2 + 2] << 8) +
812 printf ("decode: bad size DISP/PCREL/INDEX: %d\n",
813 (looking_for & SIZE));
817 else if ((looking_for & SIZE) == L_16 ||
818 (looking_for & SIZE) == L_16U)
820 cst[opnum] = (data[len / 2] << 8) + data[len / 2 + 1];
821 if ((looking_for & SIZE) != L_16U)
822 cst[opnum] = (short) cst[opnum]; /* Sign extend. */
824 else if (looking_for & ABSJMP)
826 switch (looking_for & SIZE) {
828 cst[opnum] = (data[1] << 16) | (data[2] << 8) | (data[3]);
832 (data[len / 2 + 0] << 24) +
833 (data[len / 2 + 1] << 16) +
834 (data[len / 2 + 2] << 8) +
838 printf ("decode: bad size ABSJMP: %d\n",
839 (looking_for & SIZE));
843 else if ((looking_for & MODE) == MEMIND)
845 cst[opnum] = data[1];
847 else if ((looking_for & MODE) == VECIND)
849 /* FIXME: Multiplier should be 2 for "normal" mode. */
850 cst[opnum] = ((data[1] & 0x7f) + 0x80) * 4;
851 cst[opnum] += h8_get_vbr (sd); /* Add vector base reg. */
853 else if ((looking_for & SIZE) == L_32)
858 (data[i + 0] << 24) |
859 (data[i + 1] << 16) |
863 else if ((looking_for & SIZE) == L_24)
868 (data[i + 0] << 16) |
872 else if (looking_for & DISPREG)
874 rdisp[opnum] = thisnib & 0x7;
876 else if ((looking_for & MODE) == KBIT)
893 else if ((looking_for & SIZE) == L_8)
895 if ((looking_for & MODE) == ABS)
897 /* Will be combined with contents of SBR_REGNUM
898 by fetch (). For all modes except h8sx, this
899 will always contain the value 0xFFFFFF00. */
900 cst[opnum] = data[len / 2] & 0xff;
904 cst[opnum] = data[len / 2] & 0xff;
907 else if ((looking_for & SIZE) == L_2)
909 cst[opnum] = thisnib & 3;
911 else if ((looking_for & SIZE) == L_3 ||
912 (looking_for & SIZE) == L_3NZ)
914 cst[opnum] = thisnib & 7;
915 if (cst[opnum] == 0 && (looking_for & SIZE) == L_3NZ)
918 else if ((looking_for & SIZE) == L_4)
920 cst[opnum] = thisnib & 15;
922 else if ((looking_for & SIZE) == L_5)
924 cst[opnum] = data[len / 2] & 0x1f;
926 else if (looking_for == E)
931 /* Fill in the args. */
933 op_type *args = q->args.nib;
938 nargs < 3 && *args != E;
944 opnum = ((x & OP3) ? 2 :
953 if ((x & MODE) == IMM ||
954 (x & MODE) == KBIT ||
957 /* Use the instruction to determine
959 p->type = X (OP_IMM, OP_SIZE (q->how));
960 p->literal = cst[opnum];
962 else if ((x & MODE) == CONST_2 ||
963 (x & MODE) == CONST_4 ||
964 (x & MODE) == CONST_8 ||
965 (x & MODE) == CONST_16)
967 /* Use the instruction to determine
969 p->type = X (OP_IMM, OP_SIZE (q->how));
971 case CONST_2: p->literal = 2; break;
972 case CONST_4: p->literal = 4; break;
973 case CONST_8: p->literal = 8; break;
974 case CONST_16: p->literal = 16; break;
977 else if ((x & MODE) == REG)
979 p->type = X (OP_REG, bitfrom (x));
982 else if ((x & MODE) == LOWREG)
984 p->type = X (OP_LOWREG, bitfrom (x));
987 else if ((x & MODE) == PREINC)
989 /* Use the instruction to determine
991 p->type = X (OP_PREINC, OP_SIZE (q->how));
992 p->reg = reg[opnum] & 0x7;
994 else if ((x & MODE) == POSTINC)
996 /* Use the instruction to determine
998 p->type = X (OP_POSTINC, OP_SIZE (q->how));
999 p->reg = reg[opnum] & 0x7;
1001 else if ((x & MODE) == PREDEC)
1003 /* Use the instruction to determine
1004 the operand size. */
1005 p->type = X (OP_PREDEC, OP_SIZE (q->how));
1006 p->reg = reg[opnum] & 0x7;
1008 else if ((x & MODE) == POSTDEC)
1010 /* Use the instruction to determine
1011 the operand size. */
1012 p->type = X (OP_POSTDEC, OP_SIZE (q->how));
1013 p->reg = reg[opnum] & 0x7;
1015 else if ((x & MODE) == IND)
1017 /* Note: an indirect is transformed into
1018 a displacement of zero.
1020 /* Use the instruction to determine
1021 the operand size. */
1022 p->type = X (OP_DISP, OP_SIZE (q->how));
1023 p->reg = reg[opnum] & 0x7;
1025 if (OP_KIND (q->how) == O_JSR ||
1026 OP_KIND (q->how) == O_JMP)
1027 if (lvalue (sd, p->type, p->reg, &p->type))
1030 else if ((x & MODE) == ABS)
1032 /* Note: a 16 or 32 bit ABS is transformed into a
1033 displacement from pseudo-register ZERO_REGNUM,
1034 which is always zero. An 8 bit ABS becomes
1035 a displacement from SBR_REGNUM.
1037 /* Use the instruction to determine
1038 the operand size. */
1039 p->type = X (OP_DISP, OP_SIZE (q->how));
1040 p->literal = cst[opnum];
1042 /* 8-bit ABS is displacement from SBR.
1043 16 and 32-bit ABS are displacement from ZERO.
1044 (SBR will always be zero except for h8/sx)
1046 if ((x & SIZE) == L_8)
1047 p->reg = SBR_REGNUM;
1049 p->reg = ZERO_REGNUM;;
1051 else if ((x & MODE) == MEMIND ||
1052 (x & MODE) == VECIND)
1054 /* Size doesn't matter. */
1055 p->type = X (OP_MEM, SB);
1056 p->literal = cst[opnum];
1057 if (OP_KIND (q->how) == O_JSR ||
1058 OP_KIND (q->how) == O_JMP)
1059 if (lvalue (sd, p->type, p->reg, &p->type))
1062 else if ((x & MODE) == PCREL)
1064 /* Size doesn't matter. */
1065 p->type = X (OP_PCREL, SB);
1066 p->literal = cst[opnum];
1068 else if (x & ABSJMP)
1070 p->type = X (OP_IMM, SP);
1071 p->literal = cst[opnum];
1073 else if ((x & MODE) == INDEXB ||
1074 (x & MODE) == INDEXW ||
1075 (x & MODE) == INDEXL ||
1078 /* Use the instruction to determine
1079 the operand size. */
1082 p->type = X (OP_INDEXB, OP_SIZE (q->how));
1085 p->type = X (OP_INDEXW, OP_SIZE (q->how));
1088 p->type = X (OP_INDEXL, OP_SIZE (q->how));
1091 p->type = X (OP_DISP, OP_SIZE (q->how));
1095 p->literal = cst[opnum];
1096 p->reg = rdisp[opnum];
1103 p->type = X (OP_CCR, SB);
1106 p->type = X (OP_EXR, SB);
1109 p->type = X (OP_MACH, SL);
1112 p->type = X (OP_MACL, SL);
1115 p->type = X (OP_VBR, SL);
1118 p->type = X (OP_SBR, SL);
1122 else if ((x & MODE) == CCR)
1126 else if ((x & MODE) == EXR)
1131 printf ("Hmmmm 0x%x...\n", x);
1137 /* Unary operators: treat src and dst as equivalent. */
1138 if (dst->dst.type == -1)
1139 dst->dst = dst->src;
1140 if (dst->src.type == -1)
1141 dst->src = dst->dst;
1143 dst->opcode = q->how;
1144 dst->cycles = q->time;
1146 /* And jsr's to these locations are turned into
1149 if (OP_KIND (dst->opcode) == O_JSR)
1151 switch (dst->src.literal)
1154 dst->opcode = O (O_SYS_OPEN, SB);
1157 dst->opcode = O (O_SYS_READ, SB);
1160 dst->opcode = O (O_SYS_WRITE, SB);
1163 dst->opcode = O (O_SYS_LSEEK, SB);
1166 dst->opcode = O (O_SYS_CLOSE, SB);
1169 dst->opcode = O (O_SYS_STAT, SB);
1172 dst->opcode = O (O_SYS_FSTAT, SB);
1175 dst->opcode = O (O_SYS_CMDLINE, SB);
1178 /* End of Processing for system calls. */
1181 dst->next_pc = addr + len / 2;
1185 printf ("Don't understand 0x%x \n", looking_for);
1196 /* Fell off the end. */
1197 dst->opcode = O (O_ILL, SB);
1201 compile (SIM_DESC sd, int pc)
1205 /* Find the next cache entry to use. */
1206 idx = h8_get_cache_top (sd) + 1;
1207 h8_increment_compiles (sd);
1208 if (idx >= sd->sim_cache_size)
1212 h8_set_cache_top (sd, idx);
1214 /* Throw away its old meaning. */
1215 h8_set_cache_idx (sd, sd->sim_cache[idx].oldpc, 0);
1217 /* Set to new address. */
1218 sd->sim_cache[idx].oldpc = pc;
1220 /* Fill in instruction info. */
1221 decode (sd, pc, h8_get_memory_buf (sd) + pc, sd->sim_cache + idx);
1223 /* Point to new cache entry. */
1224 h8_set_cache_idx (sd, pc, idx);
1228 static unsigned char *breg[32];
1229 static unsigned short *wreg[16];
1230 static unsigned int *lreg[18];
1232 #define GET_B_REG(X) *(breg[X])
1233 #define SET_B_REG(X, Y) (*(breg[X])) = (Y)
1234 #define GET_W_REG(X) *(wreg[X])
1235 #define SET_W_REG(X, Y) (*(wreg[X])) = (Y)
1236 #define GET_L_REG(X) h8_get_reg (sd, X)
1237 #define SET_L_REG(X, Y) h8_set_reg (sd, X, Y)
1239 #define GET_MEMORY_L(X) \
1240 ((X) < memory_size \
1241 ? ((h8_get_memory (sd, (X)+0) << 24) | (h8_get_memory (sd, (X)+1) << 16) \
1242 | (h8_get_memory (sd, (X)+2) << 8) | (h8_get_memory (sd, (X)+3) << 0)) \
1243 : ((h8_get_eightbit (sd, ((X)+0) & 0xff) << 24) \
1244 | (h8_get_eightbit (sd, ((X)+1) & 0xff) << 16) \
1245 | (h8_get_eightbit (sd, ((X)+2) & 0xff) << 8) \
1246 | (h8_get_eightbit (sd, ((X)+3) & 0xff) << 0)))
1248 #define GET_MEMORY_W(X) \
1249 ((X) < memory_size \
1250 ? ((h8_get_memory (sd, (X)+0) << 8) \
1251 | (h8_get_memory (sd, (X)+1) << 0)) \
1252 : ((h8_get_eightbit (sd, ((X)+0) & 0xff) << 8) \
1253 | (h8_get_eightbit (sd, ((X)+1) & 0xff) << 0)))
1256 #define GET_MEMORY_B(X) \
1257 ((X) < memory_size ? (h8_get_memory (sd, (X))) \
1258 : (h8_get_eightbit (sd, (X) & 0xff)))
1260 #define SET_MEMORY_L(X, Y) \
1261 { register unsigned char *_p; register int __y = (Y); \
1262 _p = ((X) < memory_size ? h8_get_memory_buf (sd) + (X) : \
1263 h8_get_eightbit_buf (sd) + ((X) & 0xff)); \
1264 _p[0] = __y >> 24; _p[1] = __y >> 16; \
1265 _p[2] = __y >> 8; _p[3] = __y >> 0; \
1268 #define SET_MEMORY_W(X, Y) \
1269 { register unsigned char *_p; register int __y = (Y); \
1270 _p = ((X) < memory_size ? h8_get_memory_buf (sd) + (X) : \
1271 h8_get_eightbit_buf (sd) + ((X) & 0xff)); \
1272 _p[0] = __y >> 8; _p[1] = __y; \
1275 #define SET_MEMORY_B(X, Y) \
1276 ((X) < memory_size ? (h8_set_memory (sd, (X), (Y))) \
1277 : (h8_set_eightbit (sd, (X) & 0xff, (Y))))
1279 /* Simulate a memory fetch.
1280 Return 0 for success, -1 for failure.
1284 fetch_1 (SIM_DESC sd, ea_type *arg, int *val, int twice)
1287 int abs = arg->literal;
1292 return -1; /* Paranoia. */
1296 /* Indexed register plus displacement mode:
1298 This new family of addressing modes are similar to OP_DISP
1299 (register plus displacement), with two differences:
1300 1) INDEXB uses only the least significant byte of the register,
1301 INDEXW uses only the least significant word, and
1302 INDEXL uses the entire register (just like OP_DISP).
1304 2) The displacement value in abs is multiplied by two
1305 for SW-sized operations, and by four for SL-size.
1307 This gives nine possible variations.
1310 case X (OP_INDEXB, SB):
1311 case X (OP_INDEXB, SW):
1312 case X (OP_INDEXB, SL):
1313 case X (OP_INDEXW, SB):
1314 case X (OP_INDEXW, SW):
1315 case X (OP_INDEXW, SL):
1316 case X (OP_INDEXL, SB):
1317 case X (OP_INDEXL, SW):
1318 case X (OP_INDEXL, SL):
1320 switch (OP_KIND (arg->type)) {
1321 case OP_INDEXB: t &= 0xff; break;
1322 case OP_INDEXW: t &= 0xffff; break;
1326 switch (OP_SIZE (arg->type)) {
1328 *val = GET_MEMORY_B ((t * 1 + abs) & h8_get_mask (sd));
1331 *val = GET_MEMORY_W ((t * 2 + abs) & h8_get_mask (sd));
1334 *val = GET_MEMORY_L ((t * 4 + abs) & h8_get_mask (sd));
1339 case X (OP_LOWREG, SB):
1340 *val = GET_L_REG (rn) & 0xff;
1342 case X (OP_LOWREG, SW):
1343 *val = GET_L_REG (rn) & 0xffff;
1346 case X (OP_REG, SB): /* Register direct, byte. */
1347 *val = GET_B_REG (rn);
1349 case X (OP_REG, SW): /* Register direct, word. */
1350 *val = GET_W_REG (rn);
1352 case X (OP_REG, SL): /* Register direct, long. */
1353 *val = GET_L_REG (rn);
1355 case X (OP_IMM, SB): /* Immediate, byte. */
1356 case X (OP_IMM, SW): /* Immediate, word. */
1357 case X (OP_IMM, SL): /* Immediate, long. */
1360 case X (OP_POSTINC, SB): /* Register indirect w/post-incr: byte. */
1362 t &= h8_get_mask (sd);
1363 r = GET_MEMORY_B (t);
1366 t = t & h8_get_mask (sd);
1370 case X (OP_POSTINC, SW): /* Register indirect w/post-incr: word. */
1372 t &= h8_get_mask (sd);
1373 r = GET_MEMORY_W (t);
1376 t = t & h8_get_mask (sd);
1380 case X (OP_POSTINC, SL): /* Register indirect w/post-incr: long. */
1382 t &= h8_get_mask (sd);
1383 r = GET_MEMORY_L (t);
1386 t = t & h8_get_mask (sd);
1391 case X (OP_POSTDEC, SB): /* Register indirect w/post-decr: byte. */
1393 t &= h8_get_mask (sd);
1394 r = GET_MEMORY_B (t);
1397 t = t & h8_get_mask (sd);
1401 case X (OP_POSTDEC, SW): /* Register indirect w/post-decr: word. */
1403 t &= h8_get_mask (sd);
1404 r = GET_MEMORY_W (t);
1407 t = t & h8_get_mask (sd);
1411 case X (OP_POSTDEC, SL): /* Register indirect w/post-decr: long. */
1413 t &= h8_get_mask (sd);
1414 r = GET_MEMORY_L (t);
1417 t = t & h8_get_mask (sd);
1422 case X (OP_PREDEC, SB): /* Register indirect w/pre-decr: byte. */
1423 t = GET_L_REG (rn) - 1;
1424 t &= h8_get_mask (sd);
1426 *val = GET_MEMORY_B (t);
1429 case X (OP_PREDEC, SW): /* Register indirect w/pre-decr: word. */
1430 t = GET_L_REG (rn) - 2;
1431 t &= h8_get_mask (sd);
1433 *val = GET_MEMORY_W (t);
1436 case X (OP_PREDEC, SL): /* Register indirect w/pre-decr: long. */
1437 t = GET_L_REG (rn) - 4;
1438 t &= h8_get_mask (sd);
1440 *val = GET_MEMORY_L (t);
1443 case X (OP_PREINC, SB): /* Register indirect w/pre-incr: byte. */
1444 t = GET_L_REG (rn) + 1;
1445 t &= h8_get_mask (sd);
1447 *val = GET_MEMORY_B (t);
1450 case X (OP_PREINC, SW): /* Register indirect w/pre-incr: long. */
1451 t = GET_L_REG (rn) + 2;
1452 t &= h8_get_mask (sd);
1454 *val = GET_MEMORY_W (t);
1457 case X (OP_PREINC, SL): /* Register indirect w/pre-incr: long. */
1458 t = GET_L_REG (rn) + 4;
1459 t &= h8_get_mask (sd);
1461 *val = GET_MEMORY_L (t);
1464 case X (OP_DISP, SB): /* Register indirect w/displacement: byte. */
1465 t = GET_L_REG (rn) + abs;
1466 t &= h8_get_mask (sd);
1467 *val = GET_MEMORY_B (t);
1470 case X (OP_DISP, SW): /* Register indirect w/displacement: word. */
1471 t = GET_L_REG (rn) + abs;
1472 t &= h8_get_mask (sd);
1473 *val = GET_MEMORY_W (t);
1476 case X (OP_DISP, SL): /* Register indirect w/displacement: long. */
1477 t = GET_L_REG (rn) + abs;
1478 t &= h8_get_mask (sd);
1479 *val =GET_MEMORY_L (t);
1482 case X (OP_MEM, SL): /* Absolute memory address, long. */
1483 t = GET_MEMORY_L (abs);
1484 t &= h8_get_mask (sd);
1488 case X (OP_MEM, SW): /* Absolute memory address, word. */
1489 t = GET_MEMORY_W (abs);
1490 t &= h8_get_mask (sd);
1494 case X (OP_PCREL, SB): /* PC relative (for jump, branch etc). */
1495 case X (OP_PCREL, SW):
1496 case X (OP_PCREL, SL):
1497 case X (OP_PCREL, SN):
1501 case X (OP_MEM, SB): /* Why isn't this implemented? */
1503 sim_engine_set_run_state (sd, sim_stopped, SIGSEGV);
1506 return 0; /* Success. */
1512 fetch (SIM_DESC sd, ea_type *arg, int *val)
1514 return fetch_1 (sd, arg, val, 0);
1517 /* Fetch which will be followed by a store to the same location.
1518 The difference being that we don't want to do a post-increment
1519 or post-decrement at this time: we'll do it when we store. */
1522 fetch2 (SIM_DESC sd, ea_type *arg, int *val)
1524 return fetch_1 (sd, arg, val, 1);
1527 /* Simulate a memory store.
1528 Return 0 for success, -1 for failure.
1532 store_1 (SIM_DESC sd, ea_type *arg, int n, int twice)
1535 int abs = arg->literal;
1540 /* Indexed register plus displacement mode:
1542 This new family of addressing modes are similar to OP_DISP
1543 (register plus displacement), with two differences:
1544 1) INDEXB uses only the least significant byte of the register,
1545 INDEXW uses only the least significant word, and
1546 INDEXL uses the entire register (just like OP_DISP).
1548 2) The displacement value in abs is multiplied by two
1549 for SW-sized operations, and by four for SL-size.
1551 This gives nine possible variations.
1554 case X (OP_INDEXB, SB):
1555 case X (OP_INDEXB, SW):
1556 case X (OP_INDEXB, SL):
1557 case X (OP_INDEXW, SB):
1558 case X (OP_INDEXW, SW):
1559 case X (OP_INDEXW, SL):
1560 case X (OP_INDEXL, SB):
1561 case X (OP_INDEXL, SW):
1562 case X (OP_INDEXL, SL):
1564 switch (OP_KIND (arg->type)) {
1565 case OP_INDEXB: t &= 0xff; break;
1566 case OP_INDEXW: t &= 0xffff; break;
1570 switch (OP_SIZE (arg->type)) {
1572 SET_MEMORY_B ((t * 1 + abs) & h8_get_mask (sd), n);
1575 SET_MEMORY_W ((t * 2 + abs) & h8_get_mask (sd), n);
1578 SET_MEMORY_L ((t * 4 + abs) & h8_get_mask (sd), n);
1583 case X (OP_REG, SB): /* Register direct, byte. */
1586 case X (OP_REG, SW): /* Register direct, word. */
1589 case X (OP_REG, SL): /* Register direct, long. */
1593 case X (OP_PREDEC, SB): /* Register indirect w/pre-decr, byte. */
1597 t &= h8_get_mask (sd);
1599 SET_MEMORY_B (t, n);
1602 case X (OP_PREDEC, SW): /* Register indirect w/pre-decr, word. */
1606 t &= h8_get_mask (sd);
1608 SET_MEMORY_W (t, n);
1611 case X (OP_PREDEC, SL): /* Register indirect w/pre-decr, long. */
1615 t &= h8_get_mask (sd);
1617 SET_MEMORY_L (t, n);
1620 case X (OP_PREINC, SB): /* Register indirect w/pre-incr, byte. */
1624 t &= h8_get_mask (sd);
1626 SET_MEMORY_B (t, n);
1629 case X (OP_PREINC, SW): /* Register indirect w/pre-incr, word. */
1633 t &= h8_get_mask (sd);
1635 SET_MEMORY_W (t, n);
1638 case X (OP_PREINC, SL): /* Register indirect w/pre-incr, long. */
1642 t &= h8_get_mask (sd);
1644 SET_MEMORY_L (t, n);
1647 case X (OP_POSTDEC, SB): /* Register indirect w/post-decr, byte. */
1648 t = GET_L_REG (rn) & h8_get_mask (sd);
1649 SET_MEMORY_B (t, n);
1650 SET_L_REG (rn, t - 1);
1653 case X (OP_POSTDEC, SW): /* Register indirect w/post-decr, word. */
1654 t = GET_L_REG (rn) & h8_get_mask (sd);
1655 SET_MEMORY_W (t, n);
1656 SET_L_REG (rn, t - 2);
1659 case X (OP_POSTDEC, SL): /* Register indirect w/post-decr, long. */
1660 t = GET_L_REG (rn) & h8_get_mask (sd);
1661 SET_MEMORY_L (t, n);
1662 SET_L_REG (rn, t - 4);
1665 case X (OP_POSTINC, SB): /* Register indirect w/post-incr, byte. */
1666 t = GET_L_REG (rn) & h8_get_mask (sd);
1667 SET_MEMORY_B (t, n);
1668 SET_L_REG (rn, t + 1);
1671 case X (OP_POSTINC, SW): /* Register indirect w/post-incr, word. */
1672 t = GET_L_REG (rn) & h8_get_mask (sd);
1673 SET_MEMORY_W (t, n);
1674 SET_L_REG (rn, t + 2);
1677 case X (OP_POSTINC, SL): /* Register indirect w/post-incr, long. */
1678 t = GET_L_REG (rn) & h8_get_mask (sd);
1679 SET_MEMORY_L (t, n);
1680 SET_L_REG (rn, t + 4);
1683 case X (OP_DISP, SB): /* Register indirect w/displacement, byte. */
1684 t = GET_L_REG (rn) + abs;
1685 t &= h8_get_mask (sd);
1686 SET_MEMORY_B (t, n);
1689 case X (OP_DISP, SW): /* Register indirect w/displacement, word. */
1690 t = GET_L_REG (rn) + abs;
1691 t &= h8_get_mask (sd);
1692 SET_MEMORY_W (t, n);
1695 case X (OP_DISP, SL): /* Register indirect w/displacement, long. */
1696 t = GET_L_REG (rn) + abs;
1697 t &= h8_get_mask (sd);
1698 SET_MEMORY_L (t, n);
1702 case X (OP_MEM, SB): /* Why isn't this implemented? */
1703 case X (OP_MEM, SW): /* Why isn't this implemented? */
1704 case X (OP_MEM, SL): /* Why isn't this implemented? */
1706 sim_engine_set_run_state (sd, sim_stopped, SIGSEGV);
1715 store (SIM_DESC sd, ea_type *arg, int n)
1717 return store_1 (sd, arg, n, 0);
1720 /* Store which follows a fetch from the same location.
1721 The difference being that we don't want to do a pre-increment
1722 or pre-decrement at this time: it was already done when we fetched. */
1725 store2 (SIM_DESC sd, ea_type *arg, int n)
1727 return store_1 (sd, arg, n, 1);
1741 /* Flag to be set whenever a new SIM_DESC object is created. */
1742 static int init_pointers_needed = 1;
1745 init_pointers (SIM_DESC sd)
1747 if (init_pointers_needed)
1754 memory_size = H8300S_MSIZE;
1755 else if (h8300hmode)
1756 memory_size = H8300H_MSIZE;
1758 memory_size = H8300_MSIZE;
1759 /* `msize' must be a power of two. */
1760 if ((memory_size & (memory_size - 1)) != 0)
1762 (*sim_callback->printf_filtered)
1764 "init_pointers: bad memory size %d, defaulting to %d.\n",
1765 memory_size, memory_size = H8300S_MSIZE);
1768 if (h8_get_memory_buf (sd))
1769 free (h8_get_memory_buf (sd));
1770 if (h8_get_cache_idx_buf (sd))
1771 free (h8_get_cache_idx_buf (sd));
1772 if (h8_get_eightbit_buf (sd))
1773 free (h8_get_eightbit_buf (sd));
1775 h8_set_memory_buf (sd, (unsigned char *)
1776 calloc (sizeof (char), memory_size));
1777 h8_set_cache_idx_buf (sd, (unsigned short *)
1778 calloc (sizeof (short), memory_size));
1779 sd->memory_size = memory_size;
1780 h8_set_eightbit_buf (sd, (unsigned char *) calloc (sizeof (char), 256));
1782 h8_set_mask (sd, memory_size - 1);
1784 memset (h8_get_reg_buf (sd), 0, sizeof (((STATE_CPU (sd, 0))->regs)));
1786 for (i = 0; i < 8; i++)
1788 /* FIXME: rewrite using local buffer. */
1789 unsigned char *p = (unsigned char *) (h8_get_reg_buf (sd) + i);
1790 unsigned char *e = (unsigned char *) (h8_get_reg_buf (sd) + i + 1);
1791 unsigned short *q = (unsigned short *) (h8_get_reg_buf (sd) + i);
1792 unsigned short *u = (unsigned short *) (h8_get_reg_buf (sd) + i + 1);
1793 h8_set_reg (sd, i, 0x00112233);
1808 wreg[i] = wreg[i + 8] = 0;
1822 if (wreg[i] == 0 || wreg[i + 8] == 0)
1823 (*sim_callback->printf_filtered) (sim_callback,
1824 "init_pointers: internal error.\n");
1826 h8_set_reg (sd, i, 0);
1827 lreg[i] = h8_get_reg_buf (sd) + i;
1830 /* Note: sim uses pseudo-register ZERO as a zero register. */
1831 lreg[ZERO_REGNUM] = h8_get_reg_buf (sd) + ZERO_REGNUM;
1832 init_pointers_needed = 0;
1834 /* Initialize the seg registers. */
1836 set_simcache_size (sd, CSIZE);
1840 /* Grotty global variable for use by control_c signal handler. */
1841 static SIM_DESC control_c_sim_desc;
1846 sim_engine_set_run_state (control_c_sim_desc, sim_stopped, SIGINT);
1850 sim_stop (SIM_DESC sd)
1852 /* FIXME: use a real signal value. */
1853 sim_engine_set_run_state (sd, sim_stopped, SIGINT);
1857 #define OBITOP(name, f, s, op) \
1858 case O (name, SB): \
1863 if (fetch (sd, &code->dst, &ea)) \
1865 if (fetch (sd, &code->src, &tmp)) \
1870 if (store (sd, &code->dst,ea)) \
1876 sim_resume (SIM_DESC sd, int step, int siggnal)
1881 int tick_start = get_now ();
1890 int c, nz, v, n, u, h, ui, intMaskBit;
1893 enum sim_stop reason;
1898 control_c_sim_desc = sd;
1899 prev = signal (SIGINT, control_c);
1903 sim_engine_set_run_state (sd, sim_stopped, SIGTRAP);
1907 sim_engine_set_run_state (sd, sim_running, 0);
1910 pc = h8_get_pc (sd);
1912 /* The PC should never be odd. */
1915 sim_engine_set_run_state (sd, sim_stopped, SIGBUS);
1919 /* Get Status Register (flags). */
1922 if (h8300smode) /* Get exr. */
1924 trace = (h8_get_exr (sd) >> 7) & 1;
1925 intMask = h8_get_exr (sd) & 7;
1928 oldmask = h8_get_mask (sd);
1930 h8_set_mask (sd, 0xffff);
1933 unsigned short cidx;
1937 cidx = h8_get_cache_idx (sd, pc);
1938 if (cidx == (unsigned short) -1 ||
1939 cidx >= sd->sim_cache_size)
1942 code = sd->sim_cache + cidx;
1947 printf ("%x %d %s\n", pc, code->opcode,
1948 code->op ? code->op->name : "**");
1950 h8_increment_stats (sd, code->opcode);
1955 cycles += code->cycles;
1959 switch (code->opcode)
1963 * This opcode is a fake for when we get to an
1964 * instruction which hasnt been compiled
1970 case O (O_MOVAB, SL):
1971 case O (O_MOVAW, SL):
1972 case O (O_MOVAL, SL):
1973 /* 1) Evaluate 2nd argument (dst).
1974 2) Mask / zero extend according to whether 1st argument (src)
1975 is INDEXB, INDEXW, or INDEXL.
1976 3) Left-shift the result by 0, 1 or 2, according to size of mova
1977 (mova/b, mova/w, mova/l).
1978 4) Add literal value of 1st argument (src).
1979 5) Store result in 3rd argument (op3).
1982 if (fetch (sd, &code->dst, &ea))
1985 switch (OP_KIND (code->src.type)) {
1986 case OP_INDEXB: ea = ea & 0xff; break;
1987 case OP_INDEXW: ea = ea & 0xffff; break;
1988 case OP_INDEXL: break;
1989 default: goto illegal;
1992 switch (code->opcode) {
1993 case O (O_MOVAB, SL): break;
1994 case O (O_MOVAW, SL): ea = ea << 1; break;
1995 case O (O_MOVAL, SL): ea = ea << 2; break;
1996 default: goto illegal;
1999 ea = ea + code->src.literal;
2001 if (store (sd, &code->op3, ea))
2006 case O (O_SUBX, SB): /* subx, extended sub */
2007 if (fetch2 (sd, &code->dst, &rd))
2009 if (fetch (sd, &code->src, &ea))
2015 case O (O_SUBX, SW): /* subx, extended sub */
2016 if (fetch2 (sd, &code->dst, &rd))
2018 if (fetch (sd, &code->src, &ea))
2024 case O (O_SUBX, SL): /* subx, extended sub */
2025 if (fetch2 (sd, &code->dst, &rd))
2027 if (fetch (sd, &code->src, &ea))
2033 case O (O_ADDX, SB): /* addx, extended add */
2034 if (fetch2 (sd, &code->dst, &rd))
2036 if (fetch (sd, &code->src, &ea))
2042 case O (O_ADDX, SW): /* addx, extended add */
2043 if (fetch2 (sd, &code->dst, &rd))
2045 if (fetch (sd, &code->src, &ea))
2051 case O (O_ADDX, SL): /* addx, extended add */
2052 if (fetch2 (sd, &code->dst, &rd))
2054 if (fetch (sd, &code->src, &ea))
2060 case O (O_SUB, SB): /* sub.b */
2061 /* Fetch rd and ea. */
2062 if (fetch (sd, &code->src, &ea) || fetch2 (sd, &code->dst, &rd))
2068 case O (O_SUB, SW): /* sub.w */
2069 /* Fetch rd and ea. */
2070 if (fetch (sd, &code->src, &ea) || fetch2 (sd, &code->dst, &rd))
2076 case O (O_SUB, SL): /* sub.l */
2077 /* Fetch rd and ea. */
2078 if (fetch (sd, &code->src, &ea) || fetch2 (sd, &code->dst, &rd))
2084 case O (O_NEG, SB): /* neg.b */
2086 if (fetch2 (sd, &code->src, &ea))
2093 case O (O_NEG, SW): /* neg.w */
2095 if (fetch2 (sd, &code->src, &ea))
2102 case O (O_NEG, SL): /* neg.l */
2104 if (fetch2 (sd, &code->src, &ea))
2111 case O (O_ADD, SB): /* add.b */
2112 if (fetch2 (sd, &code->dst, &rd))
2114 if (fetch (sd, &code->src, &ea))
2119 case O (O_ADD, SW): /* add.w */
2120 if (fetch2 (sd, &code->dst, &rd))
2122 if (fetch (sd, &code->src, &ea))
2127 case O (O_ADD, SL): /* add.l */
2128 if (fetch2 (sd, &code->dst, &rd))
2130 if (fetch (sd, &code->src, &ea))
2135 case O (O_AND, SB): /* and.b */
2136 /* Fetch rd and ea. */
2137 if (fetch (sd, &code->src, &ea) || fetch2 (sd, &code->dst, &rd))
2142 case O (O_AND, SW): /* and.w */
2143 /* Fetch rd and ea. */
2144 if (fetch (sd, &code->src, &ea) || fetch2 (sd, &code->dst, &rd))
2149 case O (O_AND, SL): /* and.l */
2150 /* Fetch rd and ea. */
2151 if (fetch (sd, &code->src, &ea) || fetch2 (sd, &code->dst, &rd))
2156 case O (O_OR, SB): /* or.b */
2157 /* Fetch rd and ea. */
2158 if (fetch (sd, &code->src, &ea) || fetch2 (sd, &code->dst, &rd))
2163 case O (O_OR, SW): /* or.w */
2164 /* Fetch rd and ea. */
2165 if (fetch (sd, &code->src, &ea) || fetch2 (sd, &code->dst, &rd))
2170 case O (O_OR, SL): /* or.l */
2171 /* Fetch rd and ea. */
2172 if (fetch (sd, &code->src, &ea) || fetch2 (sd, &code->dst, &rd))
2177 case O (O_XOR, SB): /* xor.b */
2178 /* Fetch rd and ea. */
2179 if (fetch (sd, &code->src, &ea) || fetch2 (sd, &code->dst, &rd))
2184 case O (O_XOR, SW): /* xor.w */
2185 /* Fetch rd and ea. */
2186 if (fetch (sd, &code->src, &ea) || fetch2 (sd, &code->dst, &rd))
2191 case O (O_XOR, SL): /* xor.l */
2192 /* Fetch rd and ea. */
2193 if (fetch (sd, &code->src, &ea) || fetch2 (sd, &code->dst, &rd))
2199 if (fetch (sd, &code->src, &res))
2201 if (store (sd, &code->dst, res))
2203 goto just_flags_log8;
2205 if (fetch (sd, &code->src, &res))
2207 if (store (sd, &code->dst, res))
2209 goto just_flags_log16;
2211 if (fetch (sd, &code->src, &res))
2213 if (store (sd, &code->dst, res))
2215 goto just_flags_log32;
2217 case O (O_MOVMD, SB): /* movmd.b */
2224 rd = GET_MEMORY_B (GET_L_REG (5));
2225 SET_MEMORY_B (GET_L_REG (6), rd);
2226 SET_L_REG (5, GET_L_REG (5) + 1);
2227 SET_L_REG (6, GET_L_REG (6) + 1);
2232 case O (O_MOVMD, SW): /* movmd.w */
2239 rd = GET_MEMORY_W (GET_L_REG (5));
2240 SET_MEMORY_W (GET_L_REG (6), rd);
2241 SET_L_REG (5, GET_L_REG (5) + 2);
2242 SET_L_REG (6, GET_L_REG (6) + 2);
2247 case O (O_MOVMD, SL): /* movmd.l */
2254 rd = GET_MEMORY_L (GET_L_REG (5));
2255 SET_MEMORY_L (GET_L_REG (6), rd);
2256 SET_L_REG (5, GET_L_REG (5) + 4);
2257 SET_L_REG (6, GET_L_REG (6) + 4);
2262 case O (O_MOVSD, SB): /* movsd.b */
2263 /* This instruction implements strncpy, with a conditional branch.
2264 r4 contains n, r5 contains src, and r6 contains dst.
2265 The 16-bit displacement operand is added to the pc
2266 if and only if the end of string is reached before
2267 n bytes are transferred. */
2269 ea = GET_L_REG (4) & 0xffff;
2275 rd = GET_MEMORY_B (GET_L_REG (5));
2276 SET_MEMORY_B (GET_L_REG (6), rd);
2277 SET_L_REG (5, GET_L_REG (5) + 1);
2278 SET_L_REG (6, GET_L_REG (6) + 1);
2285 case O (O_EEPMOV, SB): /* eepmov.b */
2286 case O (O_EEPMOV, SW): /* eepmov.w */
2287 if (h8300hmode || h8300smode)
2289 register unsigned char *_src, *_dst;
2290 unsigned int count = ((code->opcode == O (O_EEPMOV, SW))
2291 ? h8_get_reg (sd, R4_REGNUM) & 0xffff
2292 : h8_get_reg (sd, R4_REGNUM) & 0xff);
2294 _src = (h8_get_reg (sd, R5_REGNUM) < memory_size
2295 ? h8_get_memory_buf (sd) + h8_get_reg (sd, R5_REGNUM)
2296 : h8_get_eightbit_buf (sd) +
2297 (h8_get_reg (sd, R5_REGNUM) & 0xff));
2298 if ((_src + count) >= (h8_get_memory_buf (sd) + memory_size))
2300 if ((_src + count) >= (h8_get_eightbit_buf (sd) + 0x100))
2303 _dst = (h8_get_reg (sd, R6_REGNUM) < memory_size
2304 ? h8_get_memory_buf (sd) + h8_get_reg (sd, R6_REGNUM)
2305 : h8_get_eightbit_buf (sd) +
2306 (h8_get_reg (sd, R6_REGNUM) & 0xff));
2308 if ((_dst + count) >= (h8_get_memory_buf (sd) + memory_size))
2310 if ((_dst + count) >= (h8_get_eightbit_buf (sd) + 0x100))
2313 memcpy (_dst, _src, count);
2315 h8_set_reg (sd, R5_REGNUM, h8_get_reg (sd, R5_REGNUM) + count);
2316 h8_set_reg (sd, R6_REGNUM, h8_get_reg (sd, R6_REGNUM) + count);
2317 h8_set_reg (sd, R4_REGNUM, h8_get_reg (sd, R4_REGNUM) &
2318 ((code->opcode == O (O_EEPMOV, SW))
2319 ? (~0xffff) : (~0xff)));
2320 cycles += 2 * count;
2325 case O (O_ADDS, SL): /* adds (.l) */
2327 * This insn only uses register operands, but still
2328 * it would be cleaner to use fetch and store... */
2329 SET_L_REG (code->dst.reg,
2330 GET_L_REG (code->dst.reg)
2331 + code->src.literal);
2335 case O (O_SUBS, SL): /* subs (.l) */
2337 * This insn only uses register operands, but still
2338 * it would be cleaner to use fetch and store... */
2339 SET_L_REG (code->dst.reg,
2340 GET_L_REG (code->dst.reg)
2341 - code->src.literal);
2344 case O (O_CMP, SB): /* cmp.b */
2345 if (fetch (sd, &code->dst, &rd))
2347 if (fetch (sd, &code->src, &ea))
2351 goto just_flags_alu8;
2353 case O (O_CMP, SW): /* cmp.w */
2354 if (fetch (sd, &code->dst, &rd))
2356 if (fetch (sd, &code->src, &ea))
2360 goto just_flags_alu16;
2362 case O (O_CMP, SL): /* cmp.l */
2363 if (fetch (sd, &code->dst, &rd))
2365 if (fetch (sd, &code->src, &ea))
2369 goto just_flags_alu32;
2371 case O (O_DEC, SB): /* dec.b */
2373 * This insn only uses register operands, but still
2374 * it would be cleaner to use fetch and store... */
2375 rd = GET_B_REG (code->src.reg);
2378 SET_B_REG (code->src.reg, res);
2379 goto just_flags_inc8;
2381 case O (O_DEC, SW): /* dec.w */
2383 * This insn only uses register operands, but still
2384 * it would be cleaner to use fetch and store... */
2385 rd = GET_W_REG (code->dst.reg);
2386 ea = -code->src.literal;
2388 SET_W_REG (code->dst.reg, res);
2389 goto just_flags_inc16;
2391 case O (O_DEC, SL): /* dec.l */
2393 * This insn only uses register operands, but still
2394 * it would be cleaner to use fetch and store... */
2395 rd = GET_L_REG (code->dst.reg);
2396 ea = -code->src.literal;
2398 SET_L_REG (code->dst.reg, res);
2399 goto just_flags_inc32;
2401 case O (O_INC, SB): /* inc.b */
2403 * This insn only uses register operands, but still
2404 * it would be cleaner to use fetch and store... */
2405 rd = GET_B_REG (code->src.reg);
2408 SET_B_REG (code->src.reg, res);
2409 goto just_flags_inc8;
2411 case O (O_INC, SW): /* inc.w */
2413 * This insn only uses register operands, but still
2414 * it would be cleaner to use fetch and store... */
2415 rd = GET_W_REG (code->dst.reg);
2416 ea = code->src.literal;
2418 SET_W_REG (code->dst.reg, res);
2419 goto just_flags_inc16;
2421 case O (O_INC, SL): /* inc.l */
2423 * This insn only uses register operands, but still
2424 * it would be cleaner to use fetch and store... */
2425 rd = GET_L_REG (code->dst.reg);
2426 ea = code->src.literal;
2428 SET_L_REG (code->dst.reg, res);
2429 goto just_flags_inc32;
2431 case O (O_LDC, SB): /* ldc.b */
2432 if (fetch (sd, &code->src, &res))
2436 case O (O_LDC, SW): /* ldc.w */
2437 if (fetch (sd, &code->src, &res))
2440 /* Word operand, value from MSB, must be shifted. */
2444 case O (O_LDC, SL): /* ldc.l */
2445 if (fetch (sd, &code->src, &res))
2447 switch (code->dst.type) {
2448 case X (OP_SBR, SL):
2449 h8_set_sbr (sd, res);
2451 case X (OP_VBR, SL):
2452 h8_set_vbr (sd, res);
2459 case O (O_STC, SW): /* stc.w */
2460 case O (O_STC, SB): /* stc.b */
2461 if (code->src.type == X (OP_CCR, SB))
2464 res = h8_get_ccr (sd);
2466 else if (code->src.type == X (OP_EXR, SB) && h8300smode)
2469 h8_set_exr (sd, (trace << 7) | intMask);
2470 res = h8_get_exr (sd);
2475 /* Word operand, value to MSB, must be shifted. */
2476 if (code->opcode == X (O_STC, SW))
2478 if (store (sd, &code->dst, res))
2481 case O (O_STC, SL): /* stc.l */
2482 switch (code->src.type) {
2483 case X (OP_SBR, SL):
2484 res = h8_get_sbr (sd);
2486 case X (OP_VBR, SL):
2487 res = h8_get_vbr (sd);
2492 if (store (sd, &code->dst, res))
2496 case O (O_ANDC, SB): /* andc.b */
2497 if (code->dst.type == X (OP_CCR, SB))
2500 rd = h8_get_ccr (sd);
2502 else if (code->dst.type == X (OP_EXR, SB) && h8300smode)
2505 h8_set_exr (sd, (trace << 7) | intMask);
2506 res = h8_get_exr (sd);
2510 ea = code->src.literal;
2514 case O (O_ORC, SB): /* orc.b */
2515 if (code->dst.type == X (OP_CCR, SB))
2518 rd = h8_get_ccr (sd);
2520 else if (code->dst.type == X (OP_EXR, SB) && h8300smode)
2523 h8_set_exr (sd, (trace << 7) | intMask);
2524 rd = h8_get_exr (sd);
2528 ea = code->src.literal;
2532 case O (O_XORC, SB): /* xorc.b */
2533 if (code->dst.type == X (OP_CCR, SB))
2536 rd = h8_get_ccr (sd);
2538 else if (code->dst.type == X (OP_EXR, SB) && h8300smode)
2541 h8_set_exr (sd, (trace << 7) | intMask);
2542 rd = h8_get_exr (sd);
2546 ea = code->src.literal;
2550 case O (O_BRAS, SB): /* bra/s */
2551 /* This is basically an ordinary branch, with a delay slot. */
2552 if (fetch (sd, &code->src, &res))
2560 /* Execution continues at next instruction, but
2561 delayed_branch is set up for next cycle. */
2562 h8_set_delayed_branch (sd, code->next_pc + res);
2566 case O (O_BRAB, SB): /* bra rd.b */
2567 case O (O_BRAW, SW): /* bra rd.w */
2568 case O (O_BRAL, SL): /* bra erd.l */
2569 if (fetch (sd, &code->src, &rd))
2571 switch (OP_SIZE (code->opcode)) {
2572 case SB: rd &= 0xff; break;
2573 case SW: rd &= 0xffff; break;
2574 case SL: rd &= 0xffffffff; break;
2576 pc = code->next_pc + rd;
2579 case O (O_BRABC, SB): /* bra/bc, branch if bit clear */
2580 case O (O_BRABS, SB): /* bra/bs, branch if bit set */
2581 case O (O_BSRBC, SB): /* bsr/bc, call if bit clear */
2582 case O (O_BSRBS, SB): /* bsr/bs, call if bit set */
2583 if (fetch (sd, &code->dst, &rd) ||
2584 fetch (sd, &code->src, &bit))
2587 if (code->opcode == O (O_BRABC, SB) || /* branch if clear */
2588 code->opcode == O (O_BSRBC, SB)) /* call if clear */
2590 if ((rd & (1 << bit))) /* no branch */
2593 else /* branch/call if set */
2595 if (!(rd & (1 << bit))) /* no branch */
2599 if (fetch (sd, &code->op3, &res)) /* branch */
2601 pc = code->next_pc + res;
2603 if (code->opcode == O (O_BRABC, SB) ||
2604 code->opcode == O (O_BRABS, SB)) /* branch */
2612 case O (O_BRA, SB): /* bra, branch always */
2617 case O (O_BRN, SB): /* brn, ;-/ branch never? */
2622 case O (O_BHI, SB): /* bhi */
2628 case O (O_BLS, SB): /* bls */
2633 case O (O_BCS, SB): /* bcs, branch if carry set */
2638 case O (O_BCC, SB): /* bcc, branch if carry clear */
2643 case O (O_BEQ, SB): /* beq, branch if zero set */
2647 case O (O_BGT, SB): /* bgt */
2648 if (((Z || (N ^ V)) == 0))
2652 case O (O_BLE, SB): /* ble */
2653 if (((Z || (N ^ V)) == 1))
2657 case O (O_BGE, SB): /* bge */
2661 case O (O_BLT, SB): /* blt */
2665 case O (O_BMI, SB): /* bmi */
2669 case O (O_BNE, SB): /* bne, branch if zero clear */
2674 case O (O_BPL, SB): /* bpl */
2678 case O (O_BVC, SB): /* bvc */
2682 case O (O_BVS, SB): /* bvs */
2687 /* Trap for Command Line setup. */
2688 case O (O_SYS_CMDLINE, SB):
2690 int i = 0; /* Loop counter. */
2691 int j = 0; /* Loop counter. */
2692 int ind_arg_len = 0; /* Length of each argument. */
2693 int no_of_args = 0; /* The no. or cmdline args. */
2694 int current_location = 0; /* Location of string. */
2695 int old_sp = 0; /* The Initial Stack Pointer. */
2696 int no_of_slots = 0; /* No. of slots required on the stack
2697 for storing cmdline args. */
2698 int sp_move = 0; /* No. of locations by which the stack needs
2700 int new_sp = 0; /* The final stack pointer location passed
2702 int *argv_ptrs; /* Pointers of argv strings to be stored. */
2703 int argv_ptrs_location = 0; /* Location of pointers to cmdline
2704 args on the stack. */
2705 int char_ptr_size = 0; /* Size of a character pointer on
2707 int addr_cmdline = 0; /* Memory location where cmdline has
2709 int size_cmdline = 0; /* Size of cmdline. */
2711 /* Set the address of 256 free locations where command line is
2713 addr_cmdline = cmdline_location();
2714 h8_set_reg (sd, 0, addr_cmdline);
2716 /* Counting the no. of commandline arguments. */
2717 for (i = 0; h8_get_cmdline_arg (sd, i) != NULL; i++)
2720 /* No. of arguments in the command line. */
2723 /* Current location is just a temporary variable,which we are
2724 setting to the point to the start of our commandline string. */
2725 current_location = addr_cmdline;
2727 /* Allocating space for storing pointers of the command line
2729 argv_ptrs = (int *) malloc (sizeof (int) * no_of_args);
2731 /* Setting char_ptr_size to the sizeof (char *) on the different
2733 if (h8300hmode || h8300smode)
2742 for (i = 0; i < no_of_args; i++)
2746 /* The size of the commandline argument. */
2747 ind_arg_len = strlen (h8_get_cmdline_arg (sd, i) + 1);
2749 /* The total size of the command line string. */
2750 size_cmdline += ind_arg_len;
2752 /* As we have only 256 bytes, we need to provide a graceful
2753 exit. Anyways, a program using command line arguments
2754 where we cannot store all the command line arguments
2755 given may behave unpredictably. */
2756 if (size_cmdline >= 256)
2758 h8_set_reg (sd, 0, 0);
2763 /* current_location points to the memory where the next
2764 commandline argument is stored. */
2765 argv_ptrs[i] = current_location;
2766 for (j = 0; j < ind_arg_len; j++)
2768 SET_MEMORY_B ((current_location +
2769 (sizeof (char) * j)),
2770 *(h8_get_cmdline_arg (sd, i) +
2771 sizeof (char) * j));
2774 /* Setting current_location to the starting of next
2776 current_location += ind_arg_len;
2780 /* This is the original position of the stack pointer. */
2781 old_sp = h8_get_reg (sd, SP_REGNUM);
2783 /* We need space from the stack to store the pointers to argvs. */
2784 /* As we will infringe on the stack, we need to shift the stack
2785 pointer so that the data is not overwritten. We calculate how
2786 much space is required. */
2787 sp_move = (no_of_args) * (char_ptr_size);
2789 /* The final position of stack pointer, we have thus taken some
2790 space from the stack. */
2791 new_sp = old_sp - sp_move;
2793 /* Temporary variable holding value where the argv pointers need
2795 argv_ptrs_location = new_sp;
2797 /* The argv pointers are stored at sequential locations. As per
2799 for (i = 0; i < no_of_args; i++)
2801 /* Saving the argv pointer. */
2802 if (h8300hmode || h8300smode)
2804 SET_MEMORY_L (argv_ptrs_location, argv_ptrs[i]);
2808 SET_MEMORY_W (argv_ptrs_location, argv_ptrs[i]);
2811 /* The next location where the pointer to the next argv
2812 string has to be stored. */
2813 argv_ptrs_location += char_ptr_size;
2816 /* Required by POSIX, Setting 0x0 at the end of the list of argv
2818 if (h8300hmode || h8300smode)
2820 SET_MEMORY_L (old_sp, 0x0);
2824 SET_MEMORY_W (old_sp, 0x0);
2827 /* Freeing allocated memory. */
2829 for (i = 0; i <= no_of_args; i++)
2831 free (h8_get_cmdline_arg (sd, i));
2833 free (h8_get_command_line (sd));
2835 /* The no. of argv arguments are returned in Reg 0. */
2836 h8_set_reg (sd, 0, no_of_args);
2837 /* The Pointer to argv in Register 1. */
2838 h8_set_reg (sd, 1, new_sp);
2839 /* Setting the stack pointer to the new value. */
2840 h8_set_reg (sd, SP_REGNUM, new_sp);
2844 /* System call processing starts. */
2845 case O (O_SYS_OPEN, SB):
2847 int len = 0; /* Length of filename. */
2848 char *filename; /* Filename would go here. */
2849 char temp_char; /* Temporary character */
2850 int mode = 0; /* Mode bits for the file. */
2851 int open_return; /* Return value of open, file descriptor. */
2852 int i; /* Loop counter */
2853 int filename_ptr; /* Pointer to filename in cpu memory. */
2855 /* Setting filename_ptr to first argument of open, */
2856 /* and trying to get mode. */
2857 if (h8300sxmode || h8300hmode || h8300smode)
2859 filename_ptr = GET_L_REG (0);
2860 mode = GET_MEMORY_L (h8_get_reg (sd, SP_REGNUM) + 4);
2864 filename_ptr = GET_W_REG (0);
2865 mode = GET_MEMORY_W (h8_get_reg (sd, SP_REGNUM) + 2);
2868 /* Trying to find the length of the filename. */
2869 temp_char = GET_MEMORY_B (h8_get_reg (sd, 0));
2872 while (temp_char != '\0')
2874 temp_char = GET_MEMORY_B (filename_ptr + len);
2878 /* Allocating space for the filename. */
2879 filename = (char *) malloc (sizeof (char) * len);
2881 /* String copying the filename from memory. */
2882 for (i = 0; i < len; i++)
2884 temp_char = GET_MEMORY_B (filename_ptr + i);
2885 filename[i] = temp_char;
2888 /* Callback to open and return the file descriptor. */
2889 open_return = sim_callback->open (sim_callback, filename, mode);
2891 /* Return value in register 0. */
2892 h8_set_reg (sd, 0, open_return);
2894 /* Freeing memory used for filename. */
2899 case O (O_SYS_READ, SB):
2901 char *char_ptr; /* Where characters read would be stored. */
2902 int fd; /* File descriptor */
2903 int buf_size; /* BUF_SIZE parameter in read. */
2904 int i = 0; /* Temporary Loop counter */
2905 int read_return = 0; /* Return value from callback to
2908 fd = h8300hmode ? GET_L_REG (0) : GET_W_REG (0);
2909 buf_size = h8300hmode ? GET_L_REG (2) : GET_W_REG (2);
2911 char_ptr = (char *) malloc (sizeof (char) * buf_size);
2913 /* Callback to read and return the no. of characters read. */
2915 sim_callback->read (sim_callback, fd, char_ptr, buf_size);
2917 /* The characters read are stored in cpu memory. */
2918 for (i = 0; i < buf_size; i++)
2920 SET_MEMORY_B ((h8_get_reg (sd, 1) + (sizeof (char) * i)),
2921 *(char_ptr + (sizeof (char) * i)));
2924 /* Return value in Register 0. */
2925 h8_set_reg (sd, 0, read_return);
2927 /* Freeing memory used as buffer. */
2932 case O (O_SYS_WRITE, SB):
2934 int fd; /* File descriptor */
2935 char temp_char; /* Temporary character */
2936 int len; /* Length of write, Parameter II to write. */
2937 int char_ptr; /* Character Pointer, Parameter I of write. */
2938 char *ptr; /* Where characters to be written are stored.
2940 int write_return; /* Return value from callback to write. */
2941 int i = 0; /* Loop counter */
2943 fd = h8300hmode ? GET_L_REG (0) : GET_W_REG (0);
2944 char_ptr = h8300hmode ? GET_L_REG (1) : GET_W_REG (1);
2945 len = h8300hmode ? GET_L_REG (2) : GET_W_REG (2);
2947 /* Allocating space for the characters to be written. */
2948 ptr = (char *) malloc (sizeof (char) * len);
2950 /* Fetching the characters from cpu memory. */
2951 for (i = 0; i < len; i++)
2953 temp_char = GET_MEMORY_B (char_ptr + i);
2957 /* Callback write and return the no. of characters written. */
2958 write_return = sim_callback->write (sim_callback, fd, ptr, len);
2960 /* Return value in Register 0. */
2961 h8_set_reg (sd, 0, write_return);
2963 /* Freeing memory used as buffer. */
2968 case O (O_SYS_LSEEK, SB):
2970 int fd; /* File descriptor */
2971 int offset; /* Offset */
2972 int origin; /* Origin */
2973 int lseek_return; /* Return value from callback to lseek. */
2975 fd = h8300hmode ? GET_L_REG (0) : GET_W_REG (0);
2976 offset = h8300hmode ? GET_L_REG (1) : GET_W_REG (1);
2977 origin = h8300hmode ? GET_L_REG (2) : GET_W_REG (2);
2979 /* Callback lseek and return offset. */
2981 sim_callback->lseek (sim_callback, fd, offset, origin);
2983 /* Return value in register 0. */
2984 h8_set_reg (sd, 0, lseek_return);
2988 case O (O_SYS_CLOSE, SB):
2990 int fd; /* File descriptor */
2991 int close_return; /* Return value from callback to close. */
2993 fd = h8300hmode ? GET_L_REG (0) : GET_W_REG (0);
2995 /* Callback close and return. */
2996 close_return = sim_callback->close (sim_callback, fd);
2998 /* Return value in register 0. */
2999 h8_set_reg (sd, 0, close_return);
3003 case O (O_SYS_FSTAT, SB):
3005 int fd; /* File descriptor */
3006 struct stat stat_rec; /* Stat record */
3007 int fstat_return; /* Return value from callback to stat. */
3008 int stat_ptr; /* Pointer to stat record. */
3009 char *temp_stat_ptr; /* Temporary stat_rec pointer. */
3011 fd = h8300hmode ? GET_L_REG (0) : GET_W_REG (0);
3013 /* Setting stat_ptr to second argument of stat. */
3014 stat_ptr = h8300hmode ? GET_L_REG (1) : GET_W_REG (1);
3016 /* Callback stat and return. */
3017 fstat_return = sim_callback->fstat (sim_callback, fd, &stat_rec);
3019 /* Have stat_ptr point to starting of stat_rec. */
3020 temp_stat_ptr = (char *) (&stat_rec);
3022 /* Setting up the stat structure returned. */
3023 SET_MEMORY_W (stat_ptr, stat_rec.st_dev);
3025 SET_MEMORY_W (stat_ptr, stat_rec.st_ino);
3027 SET_MEMORY_L (stat_ptr, stat_rec.st_mode);
3029 SET_MEMORY_W (stat_ptr, stat_rec.st_nlink);
3031 SET_MEMORY_W (stat_ptr, stat_rec.st_uid);
3033 SET_MEMORY_W (stat_ptr, stat_rec.st_gid);
3035 SET_MEMORY_W (stat_ptr, stat_rec.st_rdev);
3037 SET_MEMORY_L (stat_ptr, stat_rec.st_size);
3039 SET_MEMORY_L (stat_ptr, stat_rec.st_atime);
3041 SET_MEMORY_L (stat_ptr, stat_rec.st_mtime);
3043 SET_MEMORY_L (stat_ptr, stat_rec.st_ctime);
3045 /* Return value in register 0. */
3046 h8_set_reg (sd, 0, fstat_return);
3050 case O (O_SYS_STAT, SB):
3052 int len = 0; /* Length of filename. */
3053 char *filename; /* Filename would go here. */
3054 char temp_char; /* Temporary character */
3055 int filename_ptr; /* Pointer to filename in cpu memory. */
3056 struct stat stat_rec; /* Stat record */
3057 int stat_return; /* Return value from callback to stat */
3058 int stat_ptr; /* Pointer to stat record. */
3059 char *temp_stat_ptr; /* Temporary stat_rec pointer. */
3060 int i = 0; /* Loop Counter */
3062 /* Setting filename_ptr to first argument of open. */
3063 filename_ptr = h8300hmode ? GET_L_REG (0) : GET_W_REG (0);
3065 /* Trying to find the length of the filename. */
3066 temp_char = GET_MEMORY_B (h8_get_reg (sd, 0));
3069 while (temp_char != '\0')
3071 temp_char = GET_MEMORY_B (filename_ptr + len);
3075 /* Allocating space for the filename. */
3076 filename = (char *) malloc (sizeof (char) * len);
3078 /* String copying the filename from memory. */
3079 for (i = 0; i < len; i++)
3081 temp_char = GET_MEMORY_B (filename_ptr + i);
3082 filename[i] = temp_char;
3085 /* Setting stat_ptr to second argument of stat. */
3086 /* stat_ptr = h8_get_reg (sd, 1); */
3087 stat_ptr = h8300hmode ? GET_L_REG (1) : GET_W_REG (1);
3089 /* Callback stat and return. */
3091 sim_callback->stat (sim_callback, filename, &stat_rec);
3093 /* Have stat_ptr point to starting of stat_rec. */
3094 temp_stat_ptr = (char *) (&stat_rec);
3096 /* Freeing memory used for filename. */
3099 /* Setting up the stat structure returned. */
3100 SET_MEMORY_W (stat_ptr, stat_rec.st_dev);
3102 SET_MEMORY_W (stat_ptr, stat_rec.st_ino);
3104 SET_MEMORY_L (stat_ptr, stat_rec.st_mode);
3106 SET_MEMORY_W (stat_ptr, stat_rec.st_nlink);
3108 SET_MEMORY_W (stat_ptr, stat_rec.st_uid);
3110 SET_MEMORY_W (stat_ptr, stat_rec.st_gid);
3112 SET_MEMORY_W (stat_ptr, stat_rec.st_rdev);
3114 SET_MEMORY_L (stat_ptr, stat_rec.st_size);
3116 SET_MEMORY_L (stat_ptr, stat_rec.st_atime);
3118 SET_MEMORY_L (stat_ptr, stat_rec.st_mtime);
3120 SET_MEMORY_L (stat_ptr, stat_rec.st_ctime);
3122 /* Return value in register 0. */
3123 h8_set_reg (sd, 0, stat_return);
3126 /* End of system call processing. */
3128 case O (O_NOT, SB): /* not.b */
3129 if (fetch2 (sd, &code->src, &rd))
3135 case O (O_NOT, SW): /* not.w */
3136 if (fetch2 (sd, &code->src, &rd))
3142 case O (O_NOT, SL): /* not.l */
3143 if (fetch2 (sd, &code->src, &rd))
3149 case O (O_SHLL, SB): /* shll.b */
3150 case O (O_SHLR, SB): /* shlr.b */
3151 if (fetch2 (sd, &code->dst, &rd))
3154 if (code->src.type == X (OP_IMM, SB))
3155 fetch (sd, &code->src, &ea);
3159 if (code->opcode == O (O_SHLL, SB))
3162 c = rd & (0x80 >> (ea - 1));
3168 c = rd & (1 << (ea - 1));
3169 rd = (unsigned char) rd >> ea;
3173 case O (O_SHLL, SW): /* shll.w */
3174 case O (O_SHLR, SW): /* shlr.w */
3175 if (fetch2 (sd, &code->dst, &rd))
3178 if (code->src.type == X (OP_IMM, SW))
3179 fetch (sd, &code->src, &ea);
3183 if (code->opcode == O (O_SHLL, SW))
3186 c = rd & (0x8000 >> (ea - 1));
3192 c = rd & (1 << (ea - 1));
3193 rd = (unsigned short) rd >> ea;
3197 case O (O_SHLL, SL): /* shll.l */
3198 case O (O_SHLR, SL): /* shlr.l */
3199 if (fetch2 (sd, &code->dst, &rd))
3202 if (code->src.type == X (OP_IMM, SL))
3203 fetch (sd, &code->src, &ea);
3207 if (code->opcode == O (O_SHLL, SL))
3210 c = rd & (0x80000000 >> (ea - 1));
3216 c = rd & (1 << (ea - 1));
3217 rd = (unsigned int) rd >> ea;
3221 case O (O_SHAL, SB):
3222 case O (O_SHAR, SB):
3223 if (fetch2 (sd, &code->dst, &rd))
3226 if (code->src.type == X (OP_IMM, SB))
3227 fetch (sd, &code->src, &ea);
3231 if (code->opcode == O (O_SHAL, SB))
3233 c = rd & (0x80 >> (ea - 1));
3234 res = rd >> (7 - ea);
3235 v = ((res & 1) && !(res & 2))
3236 || (!(res & 1) && (res & 2));
3241 c = rd & (1 << (ea - 1));
3243 rd = ((signed char) rd) >> ea;
3247 case O (O_SHAL, SW):
3248 case O (O_SHAR, SW):
3249 if (fetch2 (sd, &code->dst, &rd))
3252 if (code->src.type == X (OP_IMM, SW))
3253 fetch (sd, &code->src, &ea);
3257 if (code->opcode == O (O_SHAL, SW))
3259 c = rd & (0x8000 >> (ea - 1));
3260 res = rd >> (15 - ea);
3261 v = ((res & 1) && !(res & 2))
3262 || (!(res & 1) && (res & 2));
3267 c = rd & (1 << (ea - 1));
3269 rd = ((signed short) rd) >> ea;
3273 case O (O_SHAL, SL):
3274 case O (O_SHAR, SL):
3275 if (fetch2 (sd, &code->dst, &rd))
3278 if (code->src.type == X (OP_IMM, SL))
3279 fetch (sd, &code->src, &ea);
3283 if (code->opcode == O (O_SHAL, SL))
3285 c = rd & (0x80000000 >> (ea - 1));
3286 res = rd >> (31 - ea);
3287 v = ((res & 1) && !(res & 2))
3288 || (!(res & 1) && (res & 2));
3293 c = rd & (1 << (ea - 1));
3295 rd = ((signed int) rd) >> ea;
3299 case O (O_ROTL, SB):
3300 case O (O_ROTR, SB):
3301 if (fetch2 (sd, &code->dst, &rd))
3304 if (code->src.type == X (OP_IMM, SB))
3305 fetch (sd, &code->src, &ea);
3310 if (code->opcode == O (O_ROTL, SB))
3320 rd = ((unsigned char) rd) >> 1;
3328 case O (O_ROTL, SW):
3329 case O (O_ROTR, SW):
3330 if (fetch2 (sd, &code->dst, &rd))
3333 if (code->src.type == X (OP_IMM, SW))
3334 fetch (sd, &code->src, &ea);
3339 if (code->opcode == O (O_ROTL, SW))
3349 rd = ((unsigned short) rd) >> 1;
3357 case O (O_ROTL, SL):
3358 case O (O_ROTR, SL):
3359 if (fetch2 (sd, &code->dst, &rd))
3362 if (code->src.type == X (OP_IMM, SL))
3363 fetch (sd, &code->src, &ea);
3368 if (code->opcode == O (O_ROTL, SL))
3370 c = rd & 0x80000000;
3378 rd = ((unsigned int) rd) >> 1;
3386 case O (O_ROTXL, SB):
3387 case O (O_ROTXR, SB):
3388 if (fetch2 (sd, &code->dst, &rd))
3391 if (code->src.type == X (OP_IMM, SB))
3392 fetch (sd, &code->src, &ea);
3397 if (code->opcode == O (O_ROTXL, SB))
3408 rd = ((unsigned char) rd) >> 1;
3417 case O (O_ROTXL, SW):
3418 case O (O_ROTXR, SW):
3419 if (fetch2 (sd, &code->dst, &rd))
3422 if (code->src.type == X (OP_IMM, SW))
3423 fetch (sd, &code->src, &ea);
3428 if (code->opcode == O (O_ROTXL, SW))
3439 rd = ((unsigned short) rd) >> 1;
3448 case O (O_ROTXL, SL):
3449 case O (O_ROTXR, SL):
3450 if (fetch2 (sd, &code->dst, &rd))
3453 if (code->src.type == X (OP_IMM, SL))
3454 fetch (sd, &code->src, &ea);
3459 if (code->opcode == O (O_ROTXL, SL))
3461 res = rd & 0x80000000;
3470 rd = ((unsigned int) rd) >> 1;
3481 case O (O_JMP, SB): /* jmp */
3483 fetch (sd, &code->src, &pc);
3488 case O (O_JSR, SB): /* jsr, jump to subroutine */
3490 if (fetch (sd, &code->src, &pc))
3493 tmp = h8_get_reg (sd, SP_REGNUM);
3498 SET_MEMORY_L (tmp, code->next_pc);
3503 SET_MEMORY_W (tmp, code->next_pc);
3505 h8_set_reg (sd, SP_REGNUM, tmp);
3511 case O (O_BSR, SB): /* bsr, branch to subroutine */
3512 if (fetch (sd, &code->src, &res))
3514 pc = code->next_pc + res;
3517 case O (O_RTE, SN): /* rte, return from exception */
3519 /* Pops exr and ccr before pc -- otherwise identical to rts. */
3520 tmp = h8_get_reg (sd, SP_REGNUM);
3522 if (h8300smode) /* pop exr */
3524 h8_set_exr (sd, GET_MEMORY_L (tmp));
3529 h8_set_ccr (sd, GET_MEMORY_L (tmp));
3531 pc = GET_MEMORY_L (tmp);
3536 h8_set_ccr (sd, GET_MEMORY_W (tmp));
3538 pc = GET_MEMORY_W (tmp);
3543 h8_set_reg (sd, SP_REGNUM, tmp);
3546 case O (O_RTS, SN): /* rts, return from subroutine */
3548 tmp = h8_get_reg (sd, SP_REGNUM);
3552 pc = GET_MEMORY_L (tmp);
3557 pc = GET_MEMORY_W (tmp);
3561 h8_set_reg (sd, SP_REGNUM, tmp);
3564 case O (O_ILL, SB): /* illegal */
3565 sim_engine_set_run_state (sd, sim_stopped, SIGILL);
3568 case O (O_SLEEP, SN): /* sleep */
3569 /* Check for magic numbers in r1 and r2. */
3570 if ((h8_get_reg (sd, R1_REGNUM) & 0xffff) == LIBC_EXIT_MAGIC1 &&
3571 (h8_get_reg (sd, R2_REGNUM) & 0xffff) == LIBC_EXIT_MAGIC2 &&
3572 SIM_WIFEXITED (h8_get_reg (sd, 0)))
3574 /* This trap comes from _exit, not from gdb. */
3575 sim_engine_set_run_state (sd, sim_exited,
3576 SIM_WEXITSTATUS (h8_get_reg (sd, 0)));
3578 else if (SIM_WIFSTOPPED (h8_get_reg (sd, 0)))
3580 /* Pass the stop signal up to gdb. */
3581 sim_engine_set_run_state (sd, sim_stopped,
3582 SIM_WSTOPSIG (h8_get_reg (sd, 0)));
3586 /* Treat it as a sigtrap. */
3587 sim_engine_set_run_state (sd, sim_stopped, SIGTRAP);
3591 case O (O_TRAPA, SB): /* trapa */
3592 if (fetch (sd, &code->src, &res))
3593 goto end; /* res is vector number. */
3595 tmp = h8_get_reg (sd, SP_REGNUM);
3597 SET_MEMORY_L (tmp, code->next_pc);
3599 SET_MEMORY_L (tmp, h8_get_ccr (sd));
3606 SET_MEMORY_L (tmp, h8_get_exr (sd));
3609 h8_set_reg (sd, SP_REGNUM, tmp);
3611 /* FIXME: "normal" mode should use 2-byte ptrs. */
3612 pc = GET_MEMORY_L (0x20 + res * 4);
3616 sim_engine_set_run_state (sd, sim_stopped, SIGTRAP);
3619 case O (O_BSETEQ, SB):
3624 case O (O_BSETNE, SB):
3629 case O (O_BCLREQ, SB):
3634 case O (O_BCLRNE, SB):
3639 OBITOP (O_BNOT, 1, 1, ea ^= m); /* bnot */
3640 OBITOP (O_BTST, 1, 0, nz = ea & m); /* btst */
3642 OBITOP (O_BSET, 1, 1, ea |= m); /* bset */
3644 OBITOP (O_BCLR, 1, 1, ea &= ~m); /* bclr */
3645 OBITOP (O_BLD, 1, 0, c = ea & m); /* bld */
3646 OBITOP (O_BILD, 1, 0, c = !(ea & m)); /* bild */
3647 OBITOP (O_BST, 1, 1, ea &= ~m;
3648 if (C) ea |= m); /* bst */
3649 OBITOP (O_BIST, 1, 1, ea &= ~m;
3650 if (!C) ea |= m); /* bist */
3651 OBITOP (O_BSTZ, 1, 1, ea &= ~m;
3652 if (Z) ea |= m); /* bstz */
3653 OBITOP (O_BISTZ, 1, 1, ea &= ~m;
3654 if (!Z) ea |= m); /* bistz */
3655 OBITOP (O_BAND, 1, 0, c = (ea & m) && C); /* band */
3656 OBITOP (O_BIAND, 1, 0, c = !(ea & m) && C); /* biand */
3657 OBITOP (O_BOR, 1, 0, c = (ea & m) || C); /* bor */
3658 OBITOP (O_BIOR, 1, 0, c = !(ea & m) || C); /* bior */
3659 OBITOP (O_BXOR, 1, 0, c = ((ea & m) != 0)!= C); /* bxor */
3660 OBITOP (O_BIXOR, 1, 0, c = !(ea & m) != C); /* bixor */
3662 case O (O_BFLD, SB): /* bfld */
3665 if (fetch (sd, &code->src, &bit))
3670 if (fetch (sd, &code->dst, &ea))
3680 if (store (sd, &code->op3, ea))
3685 case O(O_BFST, SB): /* bfst */
3686 /* bitfield store */
3687 /* NOTE: the imm8 value is in dst, and the ea value
3688 (which is actually the destination) is in op3.
3689 It has to be that way, to avoid breaking the assembler. */
3691 if (fetch (sd, &code->dst, &bit)) /* imm8 */
3693 if (bit == 0) /* noop -- nothing to do. */
3696 if (fetch (sd, &code->src, &rd)) /* reg8 src */
3699 if (fetch2 (sd, &code->op3, &ea)) /* ea dst */
3702 /* Left-shift the register data into position. */
3703 for (tmp = bit; !(tmp & 1); tmp >>= 1)
3706 /* Combine it with the neighboring bits. */
3707 ea = (ea & ~bit) | (rd & bit);
3710 if (store2 (sd, &code->op3, ea))
3714 case O (O_CLRMAC, SN): /* clrmac */
3715 h8_set_mach (sd, 0);
3716 h8_set_macl (sd, 0);
3717 h8_set_macZ (sd, 1);
3718 h8_set_macV (sd, 0);
3719 h8_set_macN (sd, 0);
3722 case O (O_STMAC, SL): /* stmac, 260 */
3723 switch (code->src.type) {
3724 case X (OP_MACH, SL):
3725 res = h8_get_mach (sd);
3726 if (res & 0x200) /* sign extend */
3729 case X (OP_MACL, SL):
3730 res = h8_get_macl (sd);
3732 default: goto illegal;
3734 nz = !h8_get_macZ (sd);
3735 n = h8_get_macN (sd);
3736 v = h8_get_macV (sd);
3738 if (store (sd, &code->dst, res))
3743 case O (O_LDMAC, SL): /* ldmac, 179 */
3744 if (fetch (sd, &code->src, &rd))
3747 switch (code->dst.type) {
3748 case X (OP_MACH, SL):
3749 rd &= 0x3ff; /* Truncate to 10 bits */
3750 h8_set_mach (sd, rd);
3752 case X (OP_MACL, SL):
3753 h8_set_macl (sd, rd);
3755 default: goto illegal;
3757 h8_set_macV (sd, 0);
3761 if (fetch (sd, &code->src, &rd) ||
3762 fetch (sd, &code->dst, &res))
3765 /* Ye gods, this is non-portable!
3766 However, the existing mul/div code is similar. */
3767 res = SEXTSHORT (res) * SEXTSHORT (rd);
3769 if (h8_get_macS (sd)) /* Saturating mode */
3771 long long mac = h8_get_macl (sd);
3773 if (mac & 0x80000000) /* sign extend */
3774 mac |= 0xffffffff00000000LL;
3777 if (mac > 0x7fffffff || mac < 0xffffffff80000000LL)
3778 h8_set_macV (sd, 1);
3779 h8_set_macZ (sd, (mac == 0));
3780 h8_set_macN (sd, (mac < 0));
3781 h8_set_macl (sd, (int) mac);
3783 else /* "Less Saturating" mode */
3785 long long mac = h8_get_mach (sd);
3787 mac += h8_get_macl (sd);
3789 if (mac & 0x20000000000LL) /* sign extend */
3790 mac |= 0xfffffc0000000000LL;
3793 if (mac > 0x1ffffffffffLL ||
3794 mac < (long long) 0xfffffe0000000000LL)
3795 h8_set_macV (sd, 1);
3796 h8_set_macZ (sd, (mac == 0));
3797 h8_set_macN (sd, (mac < 0));
3798 h8_set_macl (sd, (int) mac);
3800 h8_set_mach (sd, (int) (mac & 0x3ff));
3804 case O (O_MULS, SW): /* muls.w */
3805 if (fetch (sd, &code->src, &ea) ||
3806 fetch (sd, &code->dst, &rd))
3809 /* FIXME: is this the right place to be doing sign extend? */
3810 if (OP_KIND (code->src.type) == OP_IMM &&
3814 ea = SEXTSHORT (ea);
3816 res = SEXTSHORT (ea * SEXTSHORT (rd));
3820 if (store (sd, &code->dst, res))
3825 case O (O_MULS, SL): /* muls.l */
3826 if (fetch (sd, &code->src, &ea) ||
3827 fetch (sd, &code->dst, &rd))
3830 /* FIXME: is this the right place to be doing sign extend? */
3831 if (OP_KIND (code->src.type) == OP_IMM &&
3837 n = res & 0x80000000;
3838 nz = res & 0xffffffff;
3839 if (store (sd, &code->dst, res))
3843 case O (O_MULSU, SL): /* muls/u.l */
3844 if (fetch (sd, &code->src, &ea) ||
3845 fetch (sd, &code->dst, &rd))
3848 /* FIXME: is this the right place to be doing sign extend? */
3849 if (OP_KIND (code->src.type) == OP_IMM &&
3853 /* Compute upper 32 bits of the 64-bit result. */
3854 res = (((long long) ea) * ((long long) rd)) >> 32;
3856 n = res & 0x80000000;
3857 nz = res & 0xffffffff;
3858 if (store (sd, &code->dst, res))
3862 case O (O_MULU, SW): /* mulu.w */
3863 if (fetch (sd, &code->src, &ea) ||
3864 fetch (sd, &code->dst, &rd))
3867 res = UEXTSHORT ((UEXTSHORT (ea) * UEXTSHORT (rd)));
3869 /* Don't set Z or N. */
3870 if (store (sd, &code->dst, res))
3875 case O (O_MULU, SL): /* mulu.l */
3876 if (fetch (sd, &code->src, &ea) ||
3877 fetch (sd, &code->dst, &rd))
3882 /* Don't set Z or N. */
3883 if (store (sd, &code->dst, res))
3888 case O (O_MULUU, SL): /* mulu/u.l */
3889 if (fetch (sd, &code->src, &ea) ||
3890 fetch (sd, &code->dst, &rd))
3893 /* Compute upper 32 bits of the 64-bit result. */
3894 res = (((unsigned long long) (unsigned) ea) *
3895 ((unsigned long long) (unsigned) rd)) >> 32;
3897 /* Don't set Z or N. */
3898 if (store (sd, &code->dst, res))
3903 case O (O_MULXS, SB): /* mulxs.b */
3904 if (fetch (sd, &code->src, &ea) ||
3905 fetch (sd, &code->dst, &rd))
3908 /* FIXME: is this the right place to be doing sign extend? */
3909 if (OP_KIND (code->src.type) == OP_IMM &&
3915 res = ea * SEXTCHAR (rd);
3919 if (store (sd, &code->dst, res))
3924 case O (O_MULXS, SW): /* mulxs.w */
3925 if (fetch (sd, &code->src, &ea) ||
3926 fetch (sd, &code->dst, &rd))
3929 /* FIXME: is this the right place to be doing sign extend? */
3930 if (OP_KIND (code->src.type) == OP_IMM &&
3934 ea = SEXTSHORT (ea);
3936 res = ea * SEXTSHORT (rd & 0xffff);
3938 n = res & 0x80000000;
3939 nz = res & 0xffffffff;
3940 if (store (sd, &code->dst, res))
3945 case O (O_MULXU, SB): /* mulxu.b */
3946 if (fetch (sd, &code->src, &ea) ||
3947 fetch (sd, &code->dst, &rd))
3950 res = UEXTCHAR (ea) * UEXTCHAR (rd);
3952 if (store (sd, &code->dst, res))
3957 case O (O_MULXU, SW): /* mulxu.w */
3958 if (fetch (sd, &code->src, &ea) ||
3959 fetch (sd, &code->dst, &rd))
3962 res = UEXTSHORT (ea) * UEXTSHORT (rd);
3964 if (store (sd, &code->dst, res))
3969 case O (O_TAS, SB): /* tas (test and set) */
3970 if (!h8300sxmode) /* h8sx can use any register. */
3971 switch (code->src.reg)
3982 if (fetch (sd, &code->src, &res))
3984 if (store (sd, &code->src, res | 0x80))
3987 goto just_flags_log8;
3989 case O (O_DIVU, SW): /* divu.w */
3990 if (fetch (sd, &code->src, &ea) ||
3991 fetch (sd, &code->dst, &rd))
3997 res = (unsigned) (UEXTSHORT (rd) / UEXTSHORT (ea));
4001 if (store (sd, &code->dst, res))
4005 case O (O_DIVU, SL): /* divu.l */
4006 if (fetch (sd, &code->src, &ea) ||
4007 fetch (sd, &code->dst, &rd))
4010 n = ea & 0x80000000;
4011 nz = ea & 0xffffffff;
4013 res = (unsigned) rd / ea;
4017 if (store (sd, &code->dst, res))
4021 case O (O_DIVS, SW): /* divs.w */
4022 if (fetch (sd, &code->src, &ea) ||
4023 fetch (sd, &code->dst, &rd))
4026 /* FIXME: is this the right place to be doing sign extend? */
4027 if (OP_KIND (code->src.type) == OP_IMM &&
4033 res = SEXTSHORT (rd) / SEXTSHORT (ea);
4043 if (store (sd, &code->dst, res))
4047 case O (O_DIVS, SL): /* divs.l */
4048 if (fetch (sd, &code->src, &ea) ||
4049 fetch (sd, &code->dst, &rd))
4052 /* FIXME: is this the right place to be doing sign extend? */
4053 if (OP_KIND (code->src.type) == OP_IMM &&
4068 n = res & 0x80000000;
4069 if (store (sd, &code->dst, res))
4073 case O (O_DIVXU, SB): /* divxu.b */
4074 if (fetch (sd, &code->src, &ea) ||
4075 fetch (sd, &code->dst, &rd))
4078 rd = UEXTSHORT (rd);
4085 tmp = (unsigned) rd % ea;
4086 res = (unsigned) rd / ea;
4094 if (store (sd, &code->dst, (res & 0xff) | (tmp << 8)))
4098 case O (O_DIVXU, SW): /* divxu.w */
4099 if (fetch (sd, &code->src, &ea) ||
4100 fetch (sd, &code->dst, &rd))
4103 ea = UEXTSHORT (ea);
4109 tmp = (unsigned) rd % ea;
4110 res = (unsigned) rd / ea;
4118 if (store (sd, &code->dst, (res & 0xffff) | (tmp << 16)))
4122 case O (O_DIVXS, SB): /* divxs.b */
4123 if (fetch (sd, &code->src, &ea) ||
4124 fetch (sd, &code->dst, &rd))
4127 rd = SEXTSHORT (rd);
4129 /* FIXME: is this the right place to be doing sign extend? */
4130 if (OP_KIND (code->src.type) == OP_IMM &&
4138 tmp = (int) rd % (int) ea;
4139 res = (int) rd / (int) ea;
4150 if (store (sd, &code->dst, (res & 0xff) | (tmp << 8)))
4154 case O (O_DIVXS, SW): /* divxs.w */
4155 if (fetch (sd, &code->src, &ea) ||
4156 fetch (sd, &code->dst, &rd))
4159 /* FIXME: is this the right place to be doing sign extend? */
4160 if (OP_KIND (code->src.type) == OP_IMM &&
4164 ea = SEXTSHORT (ea);
4168 tmp = (int) rd % (int) ea;
4169 res = (int) rd / (int) ea;
4179 n = res & 0x80000000;
4180 if (store (sd, &code->dst, (res & 0xffff) | (tmp << 16)))
4184 case O (O_EXTS, SW): /* exts.w, signed extend */
4185 if (fetch2 (sd, &code->dst, &rd))
4187 ea = rd & 0x80 ? -256 : 0;
4188 res = (rd & 0xff) + ea;
4191 case O (O_EXTS, SL): /* exts.l, signed extend */
4192 if (fetch2 (sd, &code->dst, &rd))
4194 if (code->src.type == X (OP_IMM, SL))
4196 if (fetch (sd, &code->src, &ea))
4199 if (ea == 2) /* exts.l #2, nn */
4201 /* Sign-extend from 8-bit to 32-bit. */
4202 ea = rd & 0x80 ? -256 : 0;
4203 res = (rd & 0xff) + ea;
4207 /* Sign-extend from 16-bit to 32-bit. */
4208 ea = rd & 0x8000 ? -65536 : 0;
4209 res = (rd & 0xffff) + ea;
4212 case O (O_EXTU, SW): /* extu.w, unsigned extend */
4213 if (fetch2 (sd, &code->dst, &rd))
4216 res = (rd & 0xff) + ea;
4219 case O (O_EXTU, SL): /* extu.l, unsigned extend */
4220 if (fetch2 (sd, &code->dst, &rd))
4222 if (code->src.type == X (OP_IMM, SL))
4224 if (fetch (sd, &code->src, &ea))
4227 if (ea == 2) /* extu.l #2, nn */
4229 /* Zero-extend from 8-bit to 32-bit. */
4231 res = (rd & 0xff) + ea;
4235 /* Zero-extend from 16-bit to 32-bit. */
4237 res = (rd & 0xffff) + ea;
4240 case O (O_NOP, SN): /* nop */
4243 case O (O_STM, SL): /* stm, store to memory */
4245 int nregs, firstreg, i;
4247 nregs = GET_MEMORY_B (pc + 1);
4250 firstreg = code->src.reg;
4252 for (i = firstreg; i <= firstreg + nregs; i++)
4254 h8_set_reg (sd, SP_REGNUM, h8_get_reg (sd, SP_REGNUM) - 4);
4255 SET_MEMORY_L (h8_get_reg (sd, SP_REGNUM), h8_get_reg (sd, i));
4260 case O (O_LDM, SL): /* ldm, load from memory */
4261 case O (O_RTEL, SN): /* rte/l, ldm plus rte */
4262 case O (O_RTSL, SN): /* rts/l, ldm plus rts */
4264 int nregs, firstreg, i;
4266 nregs = ((GET_MEMORY_B (pc + 1) >> 4) & 0xf);
4267 firstreg = code->dst.reg & 0xf;
4268 for (i = firstreg; i >= firstreg - nregs; i--)
4270 h8_set_reg (sd, i, GET_MEMORY_L (h8_get_reg (sd, SP_REGNUM)));
4271 h8_set_reg (sd, SP_REGNUM, h8_get_reg (sd, SP_REGNUM) + 4);
4274 switch (code->opcode) {
4275 case O (O_RTEL, SN):
4277 case O (O_RTSL, SN):
4286 /* Decimal Adjust Addition. This is for BCD arithmetic. */
4287 res = GET_B_REG (code->src.reg); /* FIXME fetch? */
4288 if (!c && (0 <= (res >> 4) && (res >> 4) <= 9) &&
4289 !h && (0 <= (res & 0xf) && (res & 0xf) <= 9))
4290 res = res; /* Value added == 0. */
4291 else if (!c && (0 <= (res >> 4) && (res >> 4) <= 8) &&
4292 !h && (10 <= (res & 0xf) && (res & 0xf) <= 15))
4293 res = res + 0x6; /* Value added == 6. */
4294 else if (!c && (0 <= (res >> 4) && (res >> 4) <= 9) &&
4295 h && (0 <= (res & 0xf) && (res & 0xf) <= 3))
4296 res = res + 0x6; /* Value added == 6. */
4297 else if (!c && (10 <= (res >> 4) && (res >> 4) <= 15) &&
4298 !h && (0 <= (res & 0xf) && (res & 0xf) <= 9))
4299 res = res + 0x60; /* Value added == 60. */
4300 else if (!c && (9 <= (res >> 4) && (res >> 4) <= 15) &&
4301 !h && (10 <= (res & 0xf) && (res & 0xf) <= 15))
4302 res = res + 0x66; /* Value added == 66. */
4303 else if (!c && (10 <= (res >> 4) && (res >> 4) <= 15) &&
4304 h && (0 <= (res & 0xf) && (res & 0xf) <= 3))
4305 res = res + 0x66; /* Value added == 66. */
4306 else if ( c && (1 <= (res >> 4) && (res >> 4) <= 2) &&
4307 !h && (0 <= (res & 0xf) && (res & 0xf) <= 9))
4308 res = res + 0x60; /* Value added == 60. */
4309 else if ( c && (1 <= (res >> 4) && (res >> 4) <= 2) &&
4310 !h && (10 <= (res & 0xf) && (res & 0xf) <= 15))
4311 res = res + 0x66; /* Value added == 66. */
4312 else if (c && (1 <= (res >> 4) && (res >> 4) <= 3) &&
4313 h && (0 <= (res & 0xf) && (res & 0xf) <= 3))
4314 res = res + 0x66; /* Value added == 66. */
4319 /* Decimal Adjust Subtraction. This is for BCD arithmetic. */
4320 res = GET_B_REG (code->src.reg); /* FIXME fetch, fetch2... */
4321 if (!c && (0 <= (res >> 4) && (res >> 4) <= 9) &&
4322 !h && (0 <= (res & 0xf) && (res & 0xf) <= 9))
4323 res = res; /* Value added == 0. */
4324 else if (!c && (0 <= (res >> 4) && (res >> 4) <= 8) &&
4325 h && (6 <= (res & 0xf) && (res & 0xf) <= 15))
4326 res = res + 0xfa; /* Value added == 0xfa. */
4327 else if ( c && (7 <= (res >> 4) && (res >> 4) <= 15) &&
4328 !h && (0 <= (res & 0xf) && (res & 0xf) <= 9))
4329 res = res + 0xa0; /* Value added == 0xa0. */
4330 else if (c && (6 <= (res >> 4) && (res >> 4) <= 15) &&
4331 h && (6 <= (res & 0xf) && (res & 0xf) <= 15))
4332 res = res + 0x9a; /* Value added == 0x9a. */
4338 sim_engine_set_run_state (sd, sim_stopped, SIGILL);
4343 (*sim_callback->printf_filtered) (sim_callback,
4344 "sim_resume: internal error.\n");
4345 sim_engine_set_run_state (sd, sim_stopped, SIGILL);
4349 if (code->dst.type == X (OP_CCR, SB) ||
4350 code->dst.type == X (OP_CCR, SW))
4352 h8_set_ccr (sd, res);
4355 else if (h8300smode &&
4356 (code->dst.type == X (OP_EXR, SB) ||
4357 code->dst.type == X (OP_EXR, SW)))
4359 h8_set_exr (sd, res);
4360 if (h8300smode) /* Get exr. */
4362 trace = (h8_get_exr (sd) >> 7) & 1;
4363 intMask = h8_get_exr (sd) & 7;
4372 /* When a branch works */
4373 if (fetch (sd, &code->src, &res))
4375 if (res & 1) /* bad address */
4377 pc = code->next_pc + res;
4380 /* Set the cond codes from res */
4383 /* Set the flags after an 8 bit inc/dec operation */
4387 v = (rd & 0x7f) == 0x7f;
4390 /* Set the flags after an 16 bit inc/dec operation */
4394 v = (rd & 0x7fff) == 0x7fff;
4397 /* Set the flags after an 32 bit inc/dec operation */
4399 n = res & 0x80000000;
4400 nz = res & 0xffffffff;
4401 v = (rd & 0x7fffffff) == 0x7fffffff;
4405 /* Set flags after an 8 bit shift op, carry,overflow set in insn */
4408 if (store2 (sd, &code->dst, rd))
4413 /* Set flags after an 16 bit shift op, carry,overflow set in insn */
4416 if (store2 (sd, &code->dst, rd))
4421 /* Set flags after an 32 bit shift op, carry,overflow set in insn */
4422 n = (rd & 0x80000000);
4423 nz = rd & 0xffffffff;
4424 if (store2 (sd, &code->dst, rd))
4429 if (store2 (sd, &code->dst, res))
4433 /* flags after a 32bit logical operation */
4434 n = res & 0x80000000;
4435 nz = res & 0xffffffff;
4440 if (store2 (sd, &code->dst, res))
4444 /* flags after a 16bit logical operation */
4451 if (store2 (sd, &code->dst, res))
4461 if (store2 (sd, &code->dst, res))
4468 switch (code->opcode / 4)
4472 v = ((rd & 0x80) == (ea & 0x80)
4473 && (rd & 0x80) != (res & 0x80));
4478 v = ((rd & 0x80) != (-ea & 0x80)
4479 && (rd & 0x80) != (res & 0x80));
4486 break; /* No effect on v flag. */
4491 if (store2 (sd, &code->dst, res))
4497 c = (res & 0x10000);
4498 switch (code->opcode / 4)
4502 v = ((rd & 0x8000) == (ea & 0x8000)
4503 && (rd & 0x8000) != (res & 0x8000));
4508 v = ((rd & 0x8000) != (-ea & 0x8000)
4509 && (rd & 0x8000) != (res & 0x8000));
4518 if (store2 (sd, &code->dst, res))
4522 n = res & 0x80000000;
4523 nz = res & 0xffffffff;
4524 switch (code->opcode / 4)
4528 v = ((rd & 0x80000000) == (ea & 0x80000000)
4529 && (rd & 0x80000000) != (res & 0x80000000));
4530 c = ((unsigned) res < (unsigned) rd) ||
4531 ((unsigned) res < (unsigned) ea);
4536 v = ((rd & 0x80000000) != (-ea & 0x80000000)
4537 && (rd & 0x80000000) != (res & 0x80000000));
4538 c = (unsigned) rd < (unsigned) -ea;
4541 v = (rd == 0x80000000);
4548 if ((res = h8_get_delayed_branch (sd)) != 0)
4551 h8_set_delayed_branch (sd, 0);
4558 if (--poll_count < 0)
4560 poll_count = POLL_QUIT_INTERVAL;
4561 if ((*sim_callback->poll_quit) != NULL
4562 && (*sim_callback->poll_quit) (sim_callback))
4563 sim_engine_set_run_state (sd, sim_stopped, SIGINT);
4565 sim_engine_get_run_state (sd, &reason, &sigrc);
4566 } while (reason == sim_running);
4568 h8_set_ticks (sd, h8_get_ticks (sd) + get_now () - tick_start);
4569 h8_set_cycles (sd, h8_get_cycles (sd) + cycles);
4570 h8_set_insts (sd, h8_get_insts (sd) + insts);
4575 h8_set_exr (sd, (trace<<7) | intMask);
4577 h8_set_mask (sd, oldmask);
4578 signal (SIGINT, prev);
4582 sim_trace (SIM_DESC sd)
4584 /* FIXME: Unfinished. */
4585 (*sim_callback->printf_filtered) (sim_callback,
4586 "sim_trace: trace not supported.\n");
4587 return 1; /* Done. */
4591 sim_write (SIM_DESC sd, SIM_ADDR addr, unsigned char *buffer, int size)
4598 for (i = 0; i < size; i++)
4600 if (addr < memory_size)
4602 h8_set_memory (sd, addr + i, buffer[i]);
4603 h8_set_cache_idx (sd, addr + i, 0);
4607 h8_set_eightbit (sd, (addr + i) & 0xff, buffer[i]);
4614 sim_read (SIM_DESC sd, SIM_ADDR addr, unsigned char *buffer, int size)
4619 if (addr < memory_size)
4620 memcpy (buffer, h8_get_memory_buf (sd) + addr, size);
4622 memcpy (buffer, h8_get_eightbit_buf (sd) + (addr & 0xff), size);
4628 sim_store_register (SIM_DESC sd, int rn, unsigned char *value, int length)
4633 longval = (value[0] << 24) | (value[1] << 16) | (value[2] << 8) | value[3];
4634 shortval = (value[0] << 8) | (value[1]);
4635 intval = h8300hmode ? longval : shortval;
4641 h8_set_pc (sd, intval);
4644 (*sim_callback->printf_filtered) (sim_callback,
4645 "sim_store_register: bad regnum %d.\n",
4655 h8_set_reg (sd, rn, intval);
4658 h8_set_ccr (sd, intval);
4661 h8_set_exr (sd, intval);
4664 h8_set_sbr (sd, intval);
4667 h8_set_vbr (sd, intval);
4670 h8_set_mach (sd, intval);
4673 h8_set_macl (sd, intval);
4676 h8_set_cycles (sd, longval);
4680 h8_set_insts (sd, longval);
4684 h8_set_ticks (sd, longval);
4691 sim_fetch_register (SIM_DESC sd, int rn, unsigned char *buf, int length)
4698 if (!h8300smode && rn >= EXR_REGNUM)
4703 (*sim_callback->printf_filtered) (sim_callback,
4704 "sim_fetch_register: bad regnum %d.\n",
4709 v = h8_get_ccr (sd);
4712 v = h8_get_exr (sd);
4718 v = h8_get_sbr (sd);
4721 v = h8_get_vbr (sd);
4724 v = h8_get_mach (sd);
4727 v = h8_get_macl (sd);
4737 v = h8_get_reg (sd, rn);
4740 v = h8_get_cycles (sd);
4744 v = h8_get_ticks (sd);
4748 v = h8_get_insts (sd);
4752 if (h8300hmode || longreg)
4768 sim_stop_reason (SIM_DESC sd, enum sim_stop *reason, int *sigrc)
4770 sim_engine_get_run_state (sd, reason, sigrc);
4773 /* FIXME: Rename to sim_set_mem_size. */
4778 /* Memory size is fixed. */
4782 set_simcache_size (SIM_DESC sd, int n)
4785 free (sd->sim_cache);
4788 sd->sim_cache = (decoded_inst *) malloc (sizeof (decoded_inst) * n);
4789 memset (sd->sim_cache, 0, sizeof (decoded_inst) * n);
4790 sd->sim_cache_size = n;
4795 sim_info (SIM_DESC sd, int verbose)
4797 double timetaken = (double) h8_get_ticks (sd) / (double) now_persec ();
4798 double virttime = h8_get_cycles (sd) / 10.0e6;
4800 (*sim_callback->printf_filtered) (sim_callback,
4801 "\n\n#instructions executed %10d\n",
4803 (*sim_callback->printf_filtered) (sim_callback,
4804 "#cycles (v approximate) %10d\n",
4805 h8_get_cycles (sd));
4806 (*sim_callback->printf_filtered) (sim_callback,
4807 "#real time taken %10.4f\n",
4809 (*sim_callback->printf_filtered) (sim_callback,
4810 "#virtual time taken %10.4f\n",
4812 if (timetaken != 0.0)
4813 (*sim_callback->printf_filtered) (sim_callback,
4814 "#simulation ratio %10.4f\n",
4815 virttime / timetaken);
4816 (*sim_callback->printf_filtered) (sim_callback,
4818 h8_get_compiles (sd));
4819 (*sim_callback->printf_filtered) (sim_callback,
4820 "#cache size %10d\n",
4821 sd->sim_cache_size);
4824 /* This to be conditional on `what' (aka `verbose'),
4825 however it was never passed as non-zero. */
4829 for (i = 0; i < O_LAST; i++)
4831 if (h8_get_stats (sd, i))
4832 (*sim_callback->printf_filtered) (sim_callback, "%d: %d\n",
4833 i, h8_get_stats (sd, i));
4839 /* Indicate whether the cpu is an H8/300 or H8/300H.
4840 FLAG is non-zero for the H8/300H. */
4843 set_h8300h (unsigned long machine)
4845 /* FIXME: Much of the code in sim_load can be moved to sim_open.
4846 This function being replaced by a sim_open:ARGV configuration
4849 if (machine == bfd_mach_h8300sx || machine == bfd_mach_h8300sxn)
4852 if (machine == bfd_mach_h8300s || machine == bfd_mach_h8300sn || h8300sxmode)
4855 if (machine == bfd_mach_h8300h || machine == bfd_mach_h8300hn || h8300smode)
4859 /* Cover function of sim_state_free to free the cpu buffers as well. */
4862 free_state (SIM_DESC sd)
4864 if (STATE_MODULES (sd) != NULL)
4865 sim_module_uninstall (sd);
4867 /* Fixme: free buffers in _sim_cpu. */
4868 sim_state_free (sd);
4872 sim_open (SIM_OPEN_KIND kind,
4873 struct host_callback_struct *callback,
4880 sd = sim_state_alloc (kind, callback);
4881 sd->cpu = sim_cpu_alloc (sd, 0);
4882 cpu = STATE_CPU (sd, 0);
4883 SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER);
4884 sim_state_initialize (sd, cpu);
4885 /* sim_cpu object is new, so some initialization is needed. */
4886 init_pointers_needed = 1;
4888 /* For compatibility (FIXME: is this right?). */
4889 current_alignment = NONSTRICT_ALIGNMENT;
4890 current_target_byte_order = BIG_ENDIAN;
4892 if (sim_pre_argv_init (sd, argv[0]) != SIM_RC_OK)
4898 /* getopt will print the error message so we just have to exit if
4899 this fails. FIXME: Hmmm... in the case of gdb we need getopt
4900 to call print_filtered. */
4901 if (sim_parse_args (sd, argv) != SIM_RC_OK)
4903 /* Uninstall the modules to avoid memory leaks,
4904 file descriptor leaks, etc. */
4909 /* Check for/establish the a reference program image. */
4910 if (sim_analyze_program (sd,
4911 (STATE_PROG_ARGV (sd) != NULL
4912 ? *STATE_PROG_ARGV (sd)
4913 : NULL), abfd) != SIM_RC_OK)
4919 /* Establish any remaining configuration options. */
4920 if (sim_config (sd) != SIM_RC_OK)
4926 if (sim_post_argv_init (sd) != SIM_RC_OK)
4928 /* Uninstall the modules to avoid memory leaks,
4929 file descriptor leaks, etc. */
4934 /* sim_hw_configure (sd); */
4936 /* FIXME: Much of the code in sim_load can be moved here. */
4940 sim_callback = callback;
4945 sim_close (SIM_DESC sd, int quitting)
4947 /* Nothing to do. */
4950 /* Called by gdb to load a program into memory. */
4953 sim_load (SIM_DESC sd, char *prog, bfd *abfd, int from_tty)
4957 /* FIXME: The code below that sets a specific variant of the H8/300
4958 being simulated should be moved to sim_open(). */
4960 /* See if the file is for the H8/300 or H8/300H. */
4961 /* ??? This may not be the most efficient way. The z8k simulator
4962 does this via a different mechanism (INIT_EXTRA_SYMTAB_INFO). */
4966 prog_bfd = bfd_openr (prog, "coff-h8300");
4967 if (prog_bfd != NULL)
4969 /* Set the cpu type. We ignore failure from bfd_check_format
4970 and bfd_openr as sim_load_file checks too. */
4971 if (bfd_check_format (prog_bfd, bfd_object))
4973 set_h8300h (bfd_get_mach (prog_bfd));
4977 /* If we're using gdb attached to the simulator, then we have to
4978 reallocate memory for the simulator.
4980 When gdb first starts, it calls fetch_registers (among other
4981 functions), which in turn calls init_pointers, which allocates
4984 The problem is when we do that, we don't know whether we're
4985 debugging an H8/300 or H8/300H program.
4987 This is the first point at which we can make that determination,
4988 so we just reallocate memory now; this will also allow us to handle
4989 switching between H8/300 and H8/300H programs without exiting
4993 memory_size = H8300S_MSIZE;
4994 else if (h8300hmode)
4995 memory_size = H8300H_MSIZE;
4997 memory_size = H8300_MSIZE;
4999 if (h8_get_memory_buf (sd))
5000 free (h8_get_memory_buf (sd));
5001 if (h8_get_cache_idx_buf (sd))
5002 free (h8_get_cache_idx_buf (sd));
5003 if (h8_get_eightbit_buf (sd))
5004 free (h8_get_eightbit_buf (sd));
5006 h8_set_memory_buf (sd, (unsigned char *)
5007 calloc (sizeof (char), memory_size));
5008 h8_set_cache_idx_buf (sd, (unsigned short *)
5009 calloc (sizeof (short), memory_size));
5010 h8_set_eightbit_buf (sd, (unsigned char *) calloc (sizeof (char), 256));
5012 /* `msize' must be a power of two. */
5013 if ((memory_size & (memory_size - 1)) != 0)
5015 (*sim_callback->printf_filtered) (sim_callback,
5016 "sim_load: bad memory size.\n");
5019 h8_set_mask (sd, memory_size - 1);
5021 if (sim_load_file (sd, myname, sim_callback, prog, prog_bfd,
5022 sim_kind == SIM_OPEN_DEBUG,
5026 /* Close the bfd if we opened it. */
5027 if (abfd == NULL && prog_bfd != NULL)
5028 bfd_close (prog_bfd);
5032 /* Close the bfd if we opened it. */
5033 if (abfd == NULL && prog_bfd != NULL)
5034 bfd_close (prog_bfd);
5039 sim_create_inferior (SIM_DESC sd, struct bfd *abfd, char **argv, char **env)
5046 h8_set_pc (sd, bfd_get_start_address (abfd));
5050 /* Command Line support. */
5053 /* Counting the no. of commandline arguments. */
5054 for (no_of_args = 0; argv[no_of_args] != NULL; no_of_args++)
5057 /* Allocating memory for the argv pointers. */
5058 h8_set_command_line (sd, (char **) malloc ((sizeof (char *))
5059 * (no_of_args + 1)));
5061 for (i = 0; i < no_of_args; i++)
5063 /* Copying the argument string. */
5064 h8_set_cmdline_arg (sd, i, (char *) strdup (argv[i]));
5066 h8_set_cmdline_arg (sd, i, NULL);
5073 sim_do_command (SIM_DESC sd, char *cmd)
5075 (*sim_callback->printf_filtered) (sim_callback,
5076 "This simulator does not accept any commands.\n");
5080 sim_set_callbacks (struct host_callback_struct *ptr)