]>
Commit | Line | Data |
---|---|---|
d45a4bef JB |
1 | /* load.c --- loading object files into the M32C simulator. |
2 | ||
6aba47ca | 3 | Copyright (C) 2005, 2007 Free Software Foundation, Inc. |
d45a4bef JB |
4 | Contributed by Red Hat, Inc. |
5 | ||
6 | This file is part of the GNU simulators. | |
7 | ||
8 | The GNU simulators are free software; you can redistribute them and/or | |
9 | modify them under the terms of the GNU General Public License as | |
10 | published by the Free Software Foundation; either version 2 of the | |
11 | License, or (at your option) any later version. | |
12 | ||
13 | The GNU simulators are distributed in the hope that they will be | |
14 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 | General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
19 | along with the GNU simulators; if not, write to the Free Software | |
20 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | |
21 | 02110-1301, USA */ | |
22 | ||
23 | ||
24 | #include <stdlib.h> | |
25 | #include <stdio.h> | |
26 | #include <string.h> | |
27 | ||
28 | #include "bfd.h" | |
29 | ||
30 | #include "cpu.h" | |
31 | #include "mem.h" | |
32 | ||
33 | int (*decode_opcode) () = 0; | |
34 | int default_machine = 0; | |
35 | ||
36 | void | |
37 | m32c_set_mach (unsigned long mach) | |
38 | { | |
39 | switch (mach) | |
40 | { | |
41 | case bfd_mach_m16c: | |
42 | m32c_set_cpu (CPU_M16C); | |
43 | if (verbose) | |
44 | fprintf (stderr, "[cpu: r8c/m16c]\n"); | |
45 | break; | |
46 | case bfd_mach_m32c: | |
47 | m32c_set_cpu (CPU_M32C); | |
48 | if (verbose) | |
49 | fprintf (stderr, "[cpu: m32cm/m32c]\n"); | |
50 | break; | |
51 | default: | |
52 | fprintf (stderr, "unknown m32c machine type 0x%lx\n", mach); | |
53 | decode_opcode = 0; | |
54 | break; | |
55 | } | |
56 | } | |
57 | ||
58 | void | |
59 | m32c_load (bfd *prog) | |
60 | { | |
61 | asection *s; | |
62 | unsigned long mach = bfd_get_mach (prog); | |
63 | unsigned long highest_addr_loaded = 0; | |
64 | ||
65 | if (mach == 0 && default_machine != 0) | |
66 | mach = default_machine; | |
67 | ||
68 | m32c_set_mach (mach); | |
69 | ||
70 | for (s = prog->sections; s; s = s->next) | |
71 | { | |
72 | #if 0 | |
73 | /* This was a good idea until we started storing the RAM data in | |
74 | ROM, at which point everything was all messed up. The code | |
75 | remains as a reminder. */ | |
76 | if ((s->flags & SEC_ALLOC) && !(s->flags & SEC_READONLY)) | |
77 | { | |
78 | if (strcmp (bfd_get_section_name (prog, s), ".stack")) | |
79 | { | |
80 | int secend = | |
81 | bfd_get_section_size (s) + bfd_section_lma (prog, s); | |
82 | if (heaptop < secend && bfd_section_lma (prog, s) < 0x10000) | |
83 | { | |
84 | heaptop = heapbottom = secend; | |
85 | } | |
86 | } | |
87 | } | |
88 | #endif | |
89 | if (s->flags & SEC_LOAD) | |
90 | { | |
91 | char *buf; | |
92 | bfd_size_type size; | |
93 | ||
94 | size = bfd_get_section_size (s); | |
95 | if (size <= 0) | |
96 | continue; | |
97 | ||
98 | bfd_vma base = bfd_section_lma (prog, s); | |
99 | if (verbose) | |
100 | fprintf (stderr, "[load a=%08x s=%08x %s]\n", | |
101 | (int) base, (int) size, bfd_get_section_name (prog, s)); | |
102 | buf = (char *) malloc (size); | |
103 | bfd_get_section_contents (prog, s, buf, 0, size); | |
104 | mem_put_blk (base, buf, size); | |
105 | free (buf); | |
106 | if (highest_addr_loaded < base + size - 1 && size >= 4) | |
107 | highest_addr_loaded = base + size - 1; | |
108 | } | |
109 | } | |
110 | ||
111 | if (strcmp (bfd_get_target (prog), "srec") == 0) | |
112 | { | |
113 | heaptop = heapbottom = 0; | |
114 | switch (mach) | |
115 | { | |
116 | case bfd_mach_m16c: | |
117 | if (highest_addr_loaded > 0x10000) | |
118 | regs.r_pc = mem_get_si (0x000ffffc) & membus_mask; | |
119 | else | |
120 | regs.r_pc = mem_get_si (0x000fffc) & membus_mask; | |
121 | break; | |
122 | case bfd_mach_m32c: | |
123 | regs.r_pc = mem_get_si (0x00fffffc) & membus_mask; | |
124 | break; | |
125 | } | |
126 | } | |
127 | else | |
128 | regs.r_pc = prog->start_address; | |
129 | if (verbose) | |
130 | fprintf (stderr, "[start pc=%08x]\n", (unsigned int) regs.r_pc); | |
131 | } |