3 #include "remote-sim.h"
8 #define IMEM_SIZE 18 /* D10V instruction memory size is 18 bits */
9 #define DMEM_SIZE 16 /* Data memory */
13 static struct hash_entry *lookup_hash PARAMS ((uint32 ins, int size));
18 struct hash_entry *next;
24 struct hash_entry hash_table[MAX_HASH+1];
31 if (format & LONG_OPCODE)
32 return ((insn & 0x3F000000) >> 24);
34 return((insn & 0x7E00) >> 9);
37 static struct hash_entry *
38 lookup_hash (ins, size)
45 h = &hash_table[(ins & 0x3F000000) >> 24];
47 h = &hash_table[(ins & 0x7E00) >> 9];
49 while ( (ins & h->mask) != h->opcode)
53 printf ("ERROR looking up hash for %x\n",ins);
65 uint8 *a = (uint8 *)(x + State.imem);
66 return (a[0]<<24) + (a[1]<<16) + (a[2]<<8) + (a[3]);
73 uint8 *a = (uint8 *)(x + State.imem);
74 return (a[0]<<8) + a[1];
78 write_word_swap (addr, data)
81 uint8 *a = (uint8 *)(addr + State.imem);
88 get_operands (struct simops *s, uint32 ins)
90 int i, shift, bits, flags;
92 for (i=0; i < s->numops; i++)
94 shift = s->operands[3*i];
95 bits = s->operands[3*i+1];
96 flags = s->operands[3*i+2];
97 mask = 0x7FFFFFFF >> (31 - bits);
98 OP[i] = (ins >> shift) & mask;
106 struct hash_entry *h;
107 /* printf ("do_long %x\n",ins); */
108 h = lookup_hash (ins, 1);
109 get_operands (h->ops, ins);
113 do_2_short (ins1, ins2)
116 struct hash_entry *h;
117 /* printf ("do_2_short %x -> %x\n",ins1,ins2); */
118 h = lookup_hash (ins1, 0);
119 get_operands (h->ops, ins1);
121 h = lookup_hash (ins2, 0);
122 get_operands (h->ops, ins2);
126 do_parallel (ins1, ins2)
129 struct hash_entry *h1, *h2;
130 /* printf ("do_parallel %x || %x\n",ins1,ins2); */
131 h1 = lookup_hash (ins1, 0);
132 get_operands (h1->ops, ins1);
133 h2 = lookup_hash (ins2, 0);
134 get_operands (h2->ops, ins2);
135 if (h1->ops->exec_type == PARONLY)
141 else if (h2->ops->exec_type == PARONLY)
166 State.imem = (uint8 *)calloc(1,1<<IMEM_SIZE);
167 State.dmem = (uint8 *)calloc(1,1<<DMEM_SIZE);
168 if (!State.imem || !State.dmem )
170 fprintf (stderr,"Memory allocation failed.\n");
173 printf ("Allocated %d bytes instruction memory and\n",1<<IMEM_SIZE);
174 printf (" %d bytes data memory.\n",1<<DMEM_SIZE);
185 sim_write (addr, buffer, size)
187 unsigned char *buffer;
193 printf ("sim_write %d bytes to 0x%x\n",size,addr);
194 for (i = 0; i < size; i++)
196 State.imem[i+addr] = buffer[i];
206 struct hash_entry *h, *prev;
208 printf ("sim_open %s\n",args);
210 /* put all the opcodes in the hash table */
211 for (s = Simops; s->func; s++)
213 h = &hash_table[hash(s->opcode,s->format)];
215 /* go to the last entry in the chain */
221 h->next = calloc(1,sizeof(struct hash_entry));
226 h->opcode = s->opcode;
242 printf ("sim_set_profile %d\n",n);
246 sim_set_profile_size (n)
249 printf ("sim_set_profile_size %d\n",n);
253 sim_resume (step, siggnal)
260 printf ("sim_resume %d %d\n",step,siggnal);
264 inst = RLW (PC << 2);
266 switch (inst & 0xC0000000)
269 /* long instruction */
270 do_long (inst & 0x3FFFFFFF);
274 do_2_short ( inst & 0x7FFF, (inst & 0x3FFF8000) >> 15);
278 do_2_short ((inst & 0x3FFF8000) >> 15, inst & 0x7FFF);
281 do_parallel ((inst & 0x3FFF8000) >> 15, inst & 0x7FFF);
285 if (State.RP && PC == RPT_E)
303 printf ("sim_trace\n");
311 printf ("sim_verbose\n");
315 sim_create_inferior (start_address, argv, env)
316 SIM_ADDR start_address;
320 printf ("sim_create_inferior: PC=0x%x\n",start_address);
321 PC = start_address >> 2;
335 printf ("sim_set_callbacks\n");
340 sim_stop_reason (reason, sigrc)
341 enum sim_stop *reason;
344 printf ("sim_stop_reason\n");