]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - sim/mn10300/interp.c
* interp.c: Replace all references to load_mem and store_mem
[thirdparty/binutils-gdb.git] / sim / mn10300 / interp.c
CommitLineData
05ccbdfd
JL
1#include <signal.h>
2#include "sysdep.h"
3#include "bfd.h"
4
5#include "mn10300_sim.h"
6
05ccbdfd
JL
7host_callback *mn10300_callback;
8int mn10300_debug;
6cc6987e
DE
9static SIM_OPEN_KIND sim_kind;
10static char *myname;
05ccbdfd 11
baa83bcc 12static void dispatch PARAMS ((uint32, uint32, int));
05ccbdfd
JL
13static long hash PARAMS ((long));
14static void init_system PARAMS ((void));
baa83bcc 15#define MAX_HASH 127
05ccbdfd
JL
16
17struct hash_entry
18{
19 struct hash_entry *next;
20 long opcode;
21 long mask;
22 struct simops *ops;
baa83bcc
JL
23#ifdef HASH_STAT
24 unsigned long count;
25#endif
05ccbdfd
JL
26};
27
234a9a49 28static int max_mem = 0;
05ccbdfd
JL
29struct hash_entry hash_table[MAX_HASH+1];
30
31
d2523010
JL
32/* This probably doesn't do a very good job at bucket filling, but
33 it's simple... */
05ccbdfd
JL
34static INLINE long
35hash(insn)
36 long insn;
37{
baa83bcc
JL
38 /* These are one byte insns, we special case these since, in theory,
39 they should be the most heavily used. */
d2523010
JL
40 if ((insn & 0xffffff00) == 0)
41 {
baa83bcc
JL
42 switch (insn & 0xf0)
43 {
44 case 0x00:
45 return 0x70;
46
47 case 0x40:
48 return 0x71;
49
50 case 0x10:
51 return 0x72;
52
53 case 0x30:
54 return 0x73;
55
56 case 0x50:
57 return 0x74;
58
59 case 0x60:
60 return 0x75;
61
62 case 0x70:
63 return 0x76;
64
65 case 0x80:
66 return 0x77;
67
68 case 0x90:
69 return 0x78;
70
71 case 0xa0:
72 return 0x79;
73
74 case 0xb0:
75 return 0x7a;
76
77 case 0xe0:
78 return 0x7b;
79
80 default:
81 return 0x7c;
82 }
d2523010
JL
83 }
84
85 /* These are two byte insns */
86 if ((insn & 0xffff0000) == 0)
87 {
88 if ((insn & 0xf000) == 0x2000
89 || (insn & 0xf000) == 0x5000)
baa83bcc 90 return ((insn & 0xfc00) >> 8) & 0x7f;
d2523010
JL
91
92 if ((insn & 0xf000) == 0x4000)
baa83bcc 93 return ((insn & 0xf300) >> 8) & 0x7f;
d2523010
JL
94
95 if ((insn & 0xf000) == 0x8000
96 || (insn & 0xf000) == 0x9000
97 || (insn & 0xf000) == 0xa000
98 || (insn & 0xf000) == 0xb000)
baa83bcc
JL
99 return ((insn & 0xf000) >> 8) & 0x7f;
100
101 if ((insn & 0xff00) == 0xf000
102 || (insn & 0xff00) == 0xf100
103 || (insn & 0xff00) == 0xf200
104 || (insn & 0xff00) == 0xf500
105 || (insn & 0xff00) == 0xf600)
106 return ((insn & 0xfff0) >> 4) & 0x7f;
107
108 if ((insn & 0xf000) == 0xc000)
109 return ((insn & 0xff00) >> 8) & 0x7f;
110
111 return ((insn & 0xffc0) >> 6) & 0x7f;
d2523010
JL
112 }
113
114 /* These are three byte insns. */
115 if ((insn & 0xff000000) == 0)
116 {
117 if ((insn & 0xf00000) == 0x000000)
baa83bcc 118 return ((insn & 0xf30000) >> 16) & 0x7f;
d2523010
JL
119
120 if ((insn & 0xf00000) == 0x200000
121 || (insn & 0xf00000) == 0x300000)
baa83bcc
JL
122 return ((insn & 0xfc0000) >> 16) & 0x7f;
123
124 if ((insn & 0xff0000) == 0xf80000)
125 return ((insn & 0xfff000) >> 12) & 0x7f;
d2523010 126
baa83bcc
JL
127 if ((insn & 0xff0000) == 0xf90000)
128 return ((insn & 0xfffc00) >> 10) & 0x7f;
129
130 return ((insn & 0xff0000) >> 16) & 0x7f;
d2523010
JL
131 }
132
133 /* These are four byte or larger insns. */
baa83bcc
JL
134 if ((insn & 0xf0000000) == 0xf0000000)
135 return ((insn & 0xfff00000) >> 20) & 0x7f;
136
137 return ((insn & 0xff000000) >> 24) & 0x7f;
05ccbdfd
JL
138}
139
4df7aeb3 140static INLINE void
baa83bcc
JL
141dispatch (insn, extension, length)
142 uint32 insn;
143 uint32 extension;
d2523010 144 int length;
05ccbdfd
JL
145{
146 struct hash_entry *h;
147
baa83bcc 148 h = &hash_table[hash(insn)];
05ccbdfd 149
baa83bcc
JL
150 while ((insn & h->mask) != h->opcode
151 || (length != h->ops->length))
05ccbdfd 152 {
baa83bcc 153 if (!h->next)
05ccbdfd 154 {
baa83bcc
JL
155 (*mn10300_callback->printf_filtered) (mn10300_callback,
156 "ERROR looking up hash for 0x%x, PC=0x%x\n", insn, PC);
05ccbdfd
JL
157 exit(1);
158 }
159 h = h->next;
160 }
baa83bcc
JL
161
162
163#ifdef HASH_STAT
164 h->count++;
165#endif
166
167 /* Now call the right function. */
168 (h->ops->func)(insn, extension);
169 PC += length;
05ccbdfd
JL
170}
171
172/* FIXME These would more efficient to use than load_mem/store_mem,
173 but need to be changed to use the memory map. */
174
175uint8
176get_byte (x)
177 uint8 *x;
178{
179 return *x;
180}
181
182uint16
183get_half (x)
184 uint8 *x;
185{
186 uint8 *a = x;
187 return (a[1] << 8) + (a[0]);
188}
189
190uint32
191get_word (x)
192 uint8 *x;
193{
194 uint8 *a = x;
195 return (a[3]<<24) + (a[2]<<16) + (a[1]<<8) + (a[0]);
196}
197
198void
199put_byte (addr, data)
200 uint8 *addr;
201 uint8 data;
202{
203 uint8 *a = addr;
204 a[0] = data;
205}
206
207void
208put_half (addr, data)
209 uint8 *addr;
210 uint16 data;
211{
212 uint8 *a = addr;
213 a[0] = data & 0xff;
214 a[1] = (data >> 8) & 0xff;
215}
216
217void
218put_word (addr, data)
219 uint8 *addr;
220 uint32 data;
221{
222 uint8 *a = addr;
223 a[0] = data & 0xff;
224 a[1] = (data >> 8) & 0xff;
225 a[2] = (data >> 16) & 0xff;
226 a[3] = (data >> 24) & 0xff;
227}
228
05ccbdfd
JL
229void
230sim_size (power)
231 int power;
232
233{
234 if (State.mem)
235 free (State.mem);
236
234a9a49 237 max_mem = 1 << power;
05ccbdfd
JL
238 State.mem = (uint8 *) calloc (1, 1 << power);
239 if (!State.mem)
240 {
241 (*mn10300_callback->printf_filtered) (mn10300_callback, "Allocation of main memory failed.\n");
242 exit (1);
243 }
244}
245
246static void
247init_system ()
248{
249 if (!State.mem)
6cc6987e 250 sim_size(19);
05ccbdfd
JL
251}
252
253int
6cc6987e
DE
254sim_write (sd, addr, buffer, size)
255 SIM_DESC sd;
05ccbdfd
JL
256 SIM_ADDR addr;
257 unsigned char *buffer;
258 int size;
259{
260 int i;
261
262 init_system ();
263
264 for (i = 0; i < size; i++)
003c91be 265 store_byte (addr + i, buffer[i]);
05ccbdfd
JL
266
267 return size;
268}
269
b07a1e78
JL
270/* Compare two opcode table entries for qsort. */
271static int
272compare_simops (arg1, arg2)
273 const PTR arg1;
274 const PTR arg2;
275{
276 unsigned long code1 = ((struct simops *)arg1)->opcode;
277 unsigned long code2 = ((struct simops *)arg2)->opcode;
278
279 if (code1 < code2)
280 return -1;
281 if (code2 < code1)
282 return 1;
283 return 0;
284}
285
6cc6987e 286SIM_DESC
003c91be 287sim_open (kind,cb,argv)
6cc6987e 288 SIM_OPEN_KIND kind;
003c91be 289 host_callback *cb;
6cc6987e 290 char **argv;
05ccbdfd
JL
291{
292 struct simops *s;
293 struct hash_entry *h;
6cc6987e 294 char **p;
b07a1e78
JL
295 int i;
296
003c91be
JL
297 mn10300_callback = cb;
298
b07a1e78
JL
299 /* Sort the opcode array from smallest opcode to largest.
300 This will generally improve simulator performance as the smaller
301 opcodes are generally preferred to the larger opcodes. */
302 for (i = 0, s = Simops; s->func; s++, i++)
303 ;
304 qsort (Simops, i, sizeof (Simops[0]), compare_simops);
6cc6987e
DE
305
306 sim_kind = kind;
307 myname = argv[0];
308
309 for (p = argv + 1; *p; ++p)
05ccbdfd 310 {
6cc6987e
DE
311 if (strcmp (*p, "-E") == 0)
312 ++p; /* ignore endian spec */
313 else
05ccbdfd 314#ifdef DEBUG
6cc6987e 315 if (strcmp (*p, "-t") == 0)
05ccbdfd
JL
316 mn10300_debug = DEBUG;
317 else
318#endif
6cc6987e 319 (*mn10300_callback->printf_filtered) (mn10300_callback, "ERROR: unsupported option(s): %s\n",*p);
05ccbdfd
JL
320 }
321
baa83bcc 322 /* put all the opcodes in the hash table */
05ccbdfd
JL
323 for (s = Simops; s->func; s++)
324 {
325 h = &hash_table[hash(s->opcode)];
baa83bcc 326
05ccbdfd
JL
327 /* go to the last entry in the chain */
328 while (h->next)
baa83bcc
JL
329 {
330 /* Don't insert the same opcode more than once. */
331 if (h->opcode == s->opcode
332 && h->mask == s->mask
333 && h->ops == s)
334 continue;
335 else
336 h = h->next;
337 }
338
339 /* Don't insert the same opcode more than once. */
340 if (h->opcode == s->opcode
341 && h->mask == s->mask
342 && h->ops == s)
343 continue;
05ccbdfd
JL
344
345 if (h->ops)
346 {
347 h->next = calloc(1,sizeof(struct hash_entry));
348 h = h->next;
349 }
350 h->ops = s;
351 h->mask = s->mask;
352 h->opcode = s->opcode;
baa83bcc
JL
353#if HASH_STAT
354 h->count = 0;
355#endif
05ccbdfd 356 }
6cc6987e 357
baa83bcc 358
6cc6987e
DE
359 /* fudge our descriptor for now */
360 return (SIM_DESC) 1;
05ccbdfd
JL
361}
362
363
364void
6cc6987e
DE
365sim_close (sd, quitting)
366 SIM_DESC sd;
05ccbdfd
JL
367 int quitting;
368{
369 /* nothing to do */
370}
371
372void
373sim_set_profile (n)
374 int n;
375{
376 (*mn10300_callback->printf_filtered) (mn10300_callback, "sim_set_profile %d\n", n);
377}
378
379void
380sim_set_profile_size (n)
381 int n;
382{
383 (*mn10300_callback->printf_filtered) (mn10300_callback, "sim_set_profile_size %d\n", n);
384}
385
baa83bcc
JL
386int
387sim_stop (sd)
388 SIM_DESC sd;
389{
390 return 0;
391}
392
05ccbdfd 393void
6cc6987e
DE
394sim_resume (sd, step, siggnal)
395 SIM_DESC sd;
05ccbdfd
JL
396 int step, siggnal;
397{
7c52bf32 398 uint32 inst;
05ccbdfd 399 reg_t oldpc;
d2523010 400 struct hash_entry *h;
05ccbdfd
JL
401
402 if (step)
403 State.exception = SIGTRAP;
404 else
405 State.exception = 0;
406
407 do
408 {
d2523010
JL
409 unsigned long insn, extension;
410
05ccbdfd 411 /* Fetch the current instruction. */
baa83bcc 412 inst = load_mem_big (PC, 2);
05ccbdfd 413 oldpc = PC;
05ccbdfd 414
baa83bcc
JL
415 /* Using a giant case statement may seem like a waste because of the
416 code/rodata size the table itself will consume. However, using
417 a giant case statement speeds up the simulator by 10-15% by avoiding
418 cascading if/else statements or cascading case statements. */
d2523010 419
baa83bcc 420 switch ((inst >> 8) & 0xff)
d2523010 421 {
baa83bcc
JL
422 /* All the single byte insns except 0x80, 0x90, 0xa0, 0xb0
423 which must be handled specially. */
424 case 0x00:
425 case 0x04:
426 case 0x08:
427 case 0x0c:
428 case 0x11:
429 case 0x12:
430 case 0x13:
431 case 0x14:
432 case 0x15:
433 case 0x16:
434 case 0x17:
435 case 0x18:
436 case 0x19:
437 case 0x1a:
438 case 0x1b:
439 case 0x1c:
440 case 0x1d:
441 case 0x1e:
442 case 0x1f:
443 case 0x3c:
444 case 0x3d:
445 case 0x3e:
446 case 0x3f:
447 case 0x40:
448 case 0x41:
449 case 0x44:
450 case 0x45:
451 case 0x48:
452 case 0x49:
453 case 0x4c:
454 case 0x4d:
455 case 0x50:
456 case 0x51:
457 case 0x52:
458 case 0x53:
459 case 0x54:
460 case 0x55:
461 case 0x56:
462 case 0x57:
463 case 0x60:
464 case 0x61:
465 case 0x62:
466 case 0x63:
467 case 0x64:
468 case 0x65:
469 case 0x66:
470 case 0x67:
471 case 0x68:
472 case 0x69:
473 case 0x6a:
474 case 0x6b:
475 case 0x6c:
476 case 0x6d:
477 case 0x6e:
478 case 0x6f:
479 case 0x70:
480 case 0x71:
481 case 0x72:
482 case 0x73:
483 case 0x74:
484 case 0x75:
485 case 0x76:
486 case 0x77:
487 case 0x78:
488 case 0x79:
489 case 0x7a:
490 case 0x7b:
491 case 0x7c:
492 case 0x7d:
493 case 0x7e:
494 case 0x7f:
495 case 0xcb:
496 case 0xd0:
497 case 0xd1:
498 case 0xd2:
499 case 0xd3:
500 case 0xd4:
501 case 0xd5:
502 case 0xd6:
503 case 0xd7:
504 case 0xd8:
505 case 0xd9:
506 case 0xda:
507 case 0xdb:
508 case 0xe0:
509 case 0xe1:
510 case 0xe2:
511 case 0xe3:
512 case 0xe4:
513 case 0xe5:
514 case 0xe6:
515 case 0xe7:
516 case 0xe8:
517 case 0xe9:
518 case 0xea:
519 case 0xeb:
520 case 0xec:
521 case 0xed:
522 case 0xee:
523 case 0xef:
524 case 0xff:
525 insn = (inst >> 8) & 0xff;
526 extension = 0;
527 dispatch (insn, extension, 1);
528 break;
529
530 /* Special cases where dm == dn is used to encode a different
531 instruction. */
532 case 0x80:
533 case 0x85:
534 case 0x8a:
535 case 0x8f:
536 case 0x90:
537 case 0x95:
538 case 0x9a:
539 case 0x9f:
540 case 0xa0:
541 case 0xa5:
542 case 0xaa:
543 case 0xaf:
544 case 0xb0:
545 case 0xb5:
546 case 0xba:
547 case 0xbf:
548 insn = inst;
549 extension = 0;
550 dispatch (insn, extension, 2);
551 break;
552
553 case 0x81:
554 case 0x82:
555 case 0x83:
556 case 0x84:
557 case 0x86:
558 case 0x87:
559 case 0x88:
560 case 0x89:
561 case 0x8b:
562 case 0x8c:
563 case 0x8d:
564 case 0x8e:
565 case 0x91:
566 case 0x92:
567 case 0x93:
568 case 0x94:
569 case 0x96:
570 case 0x97:
571 case 0x98:
572 case 0x99:
573 case 0x9b:
574 case 0x9c:
575 case 0x9d:
576 case 0x9e:
577 case 0xa1:
578 case 0xa2:
579 case 0xa3:
580 case 0xa4:
581 case 0xa6:
582 case 0xa7:
583 case 0xa8:
584 case 0xa9:
585 case 0xab:
586 case 0xac:
587 case 0xad:
588 case 0xae:
589 case 0xb1:
590 case 0xb2:
591 case 0xb3:
592 case 0xb4:
593 case 0xb6:
594 case 0xb7:
595 case 0xb8:
596 case 0xb9:
597 case 0xbb:
598 case 0xbc:
599 case 0xbd:
600 case 0xbe:
601 insn = (inst >> 8) & 0xff;
602 extension = 0;
603 dispatch (insn, extension, 1);
604 break;
605
606 /* The two byte instructions. */
607 case 0x20:
608 case 0x21:
609 case 0x22:
610 case 0x23:
611 case 0x28:
612 case 0x29:
613 case 0x2a:
614 case 0x2b:
615 case 0x42:
616 case 0x43:
617 case 0x46:
618 case 0x47:
619 case 0x4a:
620 case 0x4b:
621 case 0x4e:
622 case 0x4f:
623 case 0x58:
624 case 0x59:
625 case 0x5a:
626 case 0x5b:
627 case 0x5c:
628 case 0x5d:
629 case 0x5e:
630 case 0x5f:
631 case 0xc0:
632 case 0xc1:
633 case 0xc2:
634 case 0xc3:
635 case 0xc4:
636 case 0xc5:
637 case 0xc6:
638 case 0xc7:
639 case 0xc8:
640 case 0xc9:
641 case 0xca:
642 case 0xce:
643 case 0xcf:
644 case 0xf0:
645 case 0xf1:
646 case 0xf2:
647 case 0xf3:
648 case 0xf4:
649 case 0xf5:
650 case 0xf6:
651 insn = inst;
652 extension = 0;
653 dispatch (insn, extension, 2);
654 break;
655
656 /* The three byte insns with a 16bit operand in little endian
657 format. */
658 case 0x01:
659 case 0x02:
660 case 0x03:
661 case 0x05:
662 case 0x06:
663 case 0x07:
664 case 0x09:
665 case 0x0a:
666 case 0x0b:
667 case 0x0d:
668 case 0x0e:
669 case 0x0f:
670 case 0x24:
671 case 0x25:
672 case 0x26:
673 case 0x27:
674 case 0x2c:
675 case 0x2d:
676 case 0x2e:
677 case 0x2f:
678 case 0x30:
679 case 0x31:
680 case 0x32:
681 case 0x33:
682 case 0x34:
683 case 0x35:
684 case 0x36:
685 case 0x37:
686 case 0x38:
687 case 0x39:
688 case 0x3a:
689 case 0x3b:
690 case 0xcc:
003c91be 691 insn = load_byte (PC);
baa83bcc 692 insn <<= 16;
003c91be 693 insn |= load_half (PC + 1);
baa83bcc
JL
694 extension = 0;
695 dispatch (insn, extension, 3);
696 break;
697
698 /* The three byte insns without 16bit operand. */
699 case 0xde:
700 case 0xdf:
701 case 0xf8:
702 case 0xf9:
703 insn = load_mem_big (PC, 3);
704 extension = 0;
705 dispatch (insn, extension, 3);
706 break;
707
708 /* Four byte insns. */
709 case 0xfa:
710 case 0xfb:
711 if ((inst & 0xfffc) == 0xfaf0
712 || (inst & 0xfffc) == 0xfaf4
713 || (inst & 0xfffc) == 0xfaf8)
714 insn = load_mem_big (PC, 4);
715 else
716 {
717 insn = inst;
718 insn <<= 16;
003c91be 719 insn |= load_half (PC + 2);
baa83bcc
JL
720 extension = 0;
721 }
722 dispatch (insn, extension, 4);
723 break;
724
725 /* Five byte insns. */
726 case 0xcd:
003c91be 727 insn = load_byte (PC);
baa83bcc 728 insn <<= 24;
003c91be
JL
729 insn |= (load_half (PC + 1) << 8);
730 insn |= load_byte (PC + 3);
731 extension = load_byte (PC + 4);
baa83bcc
JL
732 dispatch (insn, extension, 5);
733 break;
734
735 case 0xdc:
003c91be 736 insn = load_byte (PC);
baa83bcc 737 insn <<= 24;
003c91be 738 extension = load_word (PC + 1);
baa83bcc
JL
739 insn |= (extension & 0xffffff00) >> 8;
740 extension &= 0xff;
741 dispatch (insn, extension, 5);
742 break;
743
744 /* Six byte insns. */
745 case 0xfc:
746 case 0xfd:
747 insn = (inst << 16);
003c91be 748 extension = load_word (PC + 2);
baa83bcc
JL
749 insn |= ((extension & 0xffff0000) >> 16);
750 extension &= 0xffff;
751 dispatch (insn, extension, 6);
752 break;
753
754 case 0xdd:
003c91be
JL
755 insn = load_byte (PC) << 24;
756 extension = load_word (PC + 1);
baa83bcc
JL
757 insn |= ((extension >> 8) & 0xffffff);
758 extension = (extension & 0xff) << 16;
003c91be
JL
759 extension |= load_byte (PC + 5) << 8;
760 extension |= load_byte (PC + 6);
baa83bcc
JL
761 dispatch (insn, extension, 7);
762 break;
763
764 case 0xfe:
765 insn = inst << 16;
003c91be 766 extension = load_word (PC + 2);
baa83bcc
JL
767 insn |= ((extension >> 16) & 0xffff);
768 extension <<= 8;
769 extension &= 0xffff00;
003c91be 770 extension |= load_byte (PC + 6);
baa83bcc
JL
771 dispatch (insn, extension, 7);
772 break;
773
774 default:
775 abort ();
05ccbdfd
JL
776 }
777 }
778 while (!State.exception);
baa83bcc
JL
779
780#ifdef HASH_STAT
781 {
782 int i;
783 for (i = 0; i < MAX_HASH; i++)
784 {
785 struct hash_entry *h;
786 h = &hash_table[i];
787
788 printf("hash 0x%x:\n", i);
789
790 while (h)
791 {
792 printf("h->opcode = 0x%x, count = 0x%x\n", h->opcode, h->count);
793 h = h->next;
794 }
795
796 printf("\n\n");
797 }
798 fflush (stdout);
799 }
800#endif
801
05ccbdfd
JL
802}
803
804int
6cc6987e
DE
805sim_trace (sd)
806 SIM_DESC sd;
05ccbdfd
JL
807{
808#ifdef DEBUG
809 mn10300_debug = DEBUG;
810#endif
6cc6987e 811 sim_resume (sd, 0, 0);
05ccbdfd
JL
812 return 1;
813}
814
815void
6cc6987e
DE
816sim_info (sd, verbose)
817 SIM_DESC sd;
05ccbdfd
JL
818 int verbose;
819{
820 (*mn10300_callback->printf_filtered) (mn10300_callback, "sim_info\n");
821}
822
6cc6987e
DE
823SIM_RC
824sim_create_inferior (sd, argv, env)
825 SIM_DESC sd;
05ccbdfd
JL
826 char **argv;
827 char **env;
828{
6cc6987e 829 return SIM_RC_OK;
05ccbdfd
JL
830}
831
832void
6cc6987e
DE
833sim_kill (sd)
834 SIM_DESC sd;
05ccbdfd
JL
835{
836 /* nothing to do */
837}
838
839void
003c91be 840sim_set_callbacks (p)
05ccbdfd
JL
841 host_callback *p;
842{
843 mn10300_callback = p;
844}
845
846/* All the code for exiting, signals, etc needs to be revamped.
847
848 This is enough to get c-torture limping though. */
849
850void
6cc6987e
DE
851sim_stop_reason (sd, reason, sigrc)
852 SIM_DESC sd;
05ccbdfd
JL
853 enum sim_stop *reason;
854 int *sigrc;
855{
856 *reason = sim_stopped;
857 if (State.exception == SIGQUIT)
858 *sigrc = 0;
859 else
860 *sigrc = State.exception;
861}
862
863void
6cc6987e
DE
864sim_fetch_register (sd, rn, memory)
865 SIM_DESC sd;
05ccbdfd
JL
866 int rn;
867 unsigned char *memory;
868{
869 put_word (memory, State.regs[rn]);
870}
871
872void
6cc6987e
DE
873sim_store_register (sd, rn, memory)
874 SIM_DESC sd;
05ccbdfd
JL
875 int rn;
876 unsigned char *memory;
877{
878 State.regs[rn] = get_word (memory);
879}
880
881int
6cc6987e
DE
882sim_read (sd, addr, buffer, size)
883 SIM_DESC sd;
05ccbdfd
JL
884 SIM_ADDR addr;
885 unsigned char *buffer;
886 int size;
887{
888 int i;
889 for (i = 0; i < size; i++)
003c91be 890 buffer[i] = load_byte (addr + i);
05ccbdfd
JL
891
892 return size;
893}
894
895void
6cc6987e
DE
896sim_do_command (sd, cmd)
897 SIM_DESC sd;
05ccbdfd
JL
898 char *cmd;
899{
900 (*mn10300_callback->printf_filtered) (mn10300_callback, "\"%s\" is not a valid mn10300 simulator command.\n", cmd);
901}
902
6cc6987e
DE
903SIM_RC
904sim_load (sd, prog, abfd, from_tty)
905 SIM_DESC sd;
05ccbdfd 906 char *prog;
6cc6987e 907 bfd *abfd;
05ccbdfd
JL
908 int from_tty;
909{
6cc6987e
DE
910 extern bfd *sim_load_file (); /* ??? Don't know where this should live. */
911 bfd *prog_bfd;
912
913 prog_bfd = sim_load_file (sd, myname, mn10300_callback, prog, abfd,
914 sim_kind == SIM_OPEN_DEBUG);
915 if (prog_bfd == NULL)
916 return SIM_RC_FAIL;
917 PC = bfd_get_start_address (prog_bfd);
918 if (abfd == NULL)
919 bfd_close (prog_bfd);
920 return SIM_RC_OK;
05ccbdfd 921}