Update
[gdb.git] / sim / ppc / os_emul.c
blobdc60c8f66414fd8ab3454f875b17d00c2a4da7df
1 /* This file is part of the program psim.
3 Copyright (C) 1994-1996, Andrew Cagney <cagney@highland.com.au>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 #ifndef _OS_EMUL_C_
23 #define _OS_EMUL_C_
25 #include "cpu.h"
26 #include "idecode.h"
27 #include "os_emul.h"
29 #include "emul_generic.h"
30 #include "emul_netbsd.h"
31 #include "emul_unix.h"
32 #include "emul_chirp.h"
33 #include "emul_bugapi.h"
35 static const os_emul *(os_emulations[]) = {
36 &emul_chirp,
37 &emul_bugapi,
38 &emul_netbsd,
39 &emul_solaris,
40 &emul_linux,
45 INLINE_OS_EMUL\
46 (os_emul *)
47 os_emul_create(const char *file_name,
48 device *root)
50 const char *emulation_name = NULL;
51 bfd *image;
52 os_emul *chosen_emulation = NULL;
54 bfd_init(); /* would never hurt */
56 /* open the file */
57 image = bfd_openr(file_name, NULL);
58 if (image == NULL) {
59 bfd_perror(file_name);
60 error("nothing loaded\n");
63 /* check it is an executable */
64 if (!bfd_check_format(image, bfd_object)) {
65 TRACE(trace_tbd,
66 ("FIXME - should check more than just bfd_check_format\n"));
67 TRACE(trace_os_emul,
68 ("%s not an executable, assumeing a device file\n", file_name));
69 bfd_close(image);
70 image = NULL;
73 /* if a device file, load that before trying the emulations on */
74 if (image == NULL) {
75 psim_merge_device_file(root, file_name);
78 /* see if the device tree already specifies the required emulation */
79 if (tree_find_property(root, "/openprom/options/os-emul") != NULL)
80 emulation_name =
81 tree_find_string_property(root, "/openprom/options/os-emul");
82 else
83 emulation_name = NULL;
85 /* go through each emulation to see if they reconize it. FIXME -
86 should have some sort of imported table from a separate file */
88 os_emul_data *emul_data;
89 const os_emul **possible_emulation;
90 chosen_emulation = NULL;
91 for (possible_emulation = os_emulations, emul_data = NULL;
92 *possible_emulation != NULL && emul_data == NULL;
93 possible_emulation++) {
94 emul_data = (*possible_emulation)->create(root,
95 image,
96 emulation_name);
97 if (emul_data != NULL) {
98 chosen_emulation = ZALLOC(os_emul);
99 *chosen_emulation = **possible_emulation;
100 chosen_emulation->data = emul_data;
105 /* clean up */
106 if (image != NULL)
107 bfd_close(image);
108 return chosen_emulation;
111 INLINE_OS_EMUL\
112 (void)
113 os_emul_init(os_emul *emulation,
114 int nr_cpus)
116 if (emulation != (os_emul*)0)
117 emulation->init(emulation->data, nr_cpus);
120 INLINE_OS_EMUL\
121 (void)
122 os_emul_system_call(cpu *processor,
123 unsigned_word cia)
125 os_emul *emulation = cpu_os_emulation(processor);
126 if (emulation != (os_emul*)0 && emulation->system_call != 0)
127 emulation->system_call(processor, cia, emulation->data);
128 else
129 error("System call emulation not available\n");
132 INLINE_OS_EMUL\
133 (int)
134 os_emul_instruction_call(cpu *processor,
135 unsigned_word cia,
136 unsigned_word ra)
138 os_emul *emulation = cpu_os_emulation(processor);
139 if (emulation != (os_emul*)0 && emulation->instruction_call != 0)
140 return emulation->instruction_call(processor, cia, ra, emulation->data);
141 else
142 return 0;
146 #endif /* _OS_EMUL_C_ */