Commit | Line | Data |
---|---|---|
52edddb9 MM |
1 | /* This file is part of the program psim. |
2 | ||
3 | Copyright (C) 1994-1995, Andrew Cagney <cagney@highland.com.au> | |
4 | ||
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. | |
9 | ||
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. | |
14 | ||
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. | |
18 | ||
19 | */ | |
20 | ||
21 | ||
22 | #ifndef _EMUL_GENERIC_H_ | |
23 | #define _EMUL_GENERIC_H_ | |
24 | ||
25 | #include "cpu.h" | |
26 | #include "idecode.h" | |
27 | #include "os_emul.h" | |
28 | ||
29 | #include "bfd.h" | |
30 | ||
31 | #ifndef INLINE_EMUL_GENERIC | |
32 | #define INLINE_EMUL_GENERIC | |
33 | #endif | |
34 | ||
35 | /* various PowerPC instructions for writing into memory */ | |
36 | enum { | |
37 | emul_call_instruction = 0x1, | |
38 | emul_loop_instruction = 0x48000000, /* branch to . */ | |
39 | emul_rfi_instruction = 0x4c000064, | |
40 | emul_blr_instruction = 0x4e800020, | |
41 | }; | |
42 | ||
43 | ||
44 | /* emulation specific data */ | |
45 | ||
46 | typedef struct _os_emul_data os_emul_data; | |
47 | ||
48 | typedef os_emul_data *(os_emul_create_handler) | |
49 | (device *tree, | |
50 | bfd *image, | |
51 | const char *emul_name); | |
52 | typedef void (os_emul_init_handler) | |
53 | (os_emul_data *emul_data, | |
54 | int nr_cpus); | |
55 | typedef void (os_emul_system_call_handler) | |
56 | (cpu *processor, | |
57 | unsigned_word cia, | |
58 | os_emul_data *emul_data); | |
59 | typedef int (os_emul_instruction_call_handler) | |
60 | (cpu *processor, | |
61 | unsigned_word cia, | |
62 | unsigned_word ra, | |
63 | os_emul_data *emul_data); | |
64 | ||
65 | struct _os_emul { | |
66 | const char *name; | |
67 | os_emul_create_handler *create; | |
68 | os_emul_init_handler *init; | |
69 | os_emul_system_call_handler *system_call; | |
70 | os_emul_instruction_call_handler *instruction_call; | |
71 | os_emul_data *data; | |
72 | }; | |
73 | ||
74 | ||
75 | /* One class of emulation - system call is pretty general, provide a | |
76 | common template for implementing this */ | |
77 | ||
78 | typedef struct _emul_syscall emul_syscall; | |
79 | typedef struct _emul_syscall_descriptor emul_syscall_descriptor; | |
80 | ||
81 | typedef void (emul_syscall_handler) | |
82 | (os_emul_data *emul_data, | |
83 | unsigned call, | |
84 | const int arg0, | |
85 | cpu *processor, | |
86 | unsigned_word cia); | |
87 | ||
88 | struct _emul_syscall_descriptor { | |
89 | emul_syscall_handler *handler; | |
90 | const char *name; | |
91 | }; | |
92 | ||
93 | struct _emul_syscall { | |
94 | emul_syscall_descriptor *syscall_descriptor; | |
95 | int nr_system_calls; | |
96 | char **error_names; | |
97 | int nr_error_names; | |
98 | char **signal_names; | |
99 | int nr_signal_names; | |
100 | }; | |
101 | ||
102 | ||
103 | INLINE_EMUL_GENERIC void emul_do_system_call | |
104 | (os_emul_data *emul_data, | |
105 | emul_syscall *syscall, | |
106 | unsigned call, | |
107 | const int arg0, | |
108 | cpu *processor, | |
109 | unsigned_word cia); | |
110 | ||
111 | ||
112 | INLINE_EMUL_GENERIC unsigned64 emul_read_gpr64 | |
113 | (cpu *processor, | |
114 | int g); | |
115 | ||
116 | INLINE_EMUL_GENERIC void emul_write_gpr64 | |
117 | (cpu *processor, | |
118 | int g, | |
119 | unsigned64 val); | |
120 | ||
121 | INLINE_EMUL_GENERIC void emul_write_status | |
122 | (cpu *processor, | |
123 | int status, | |
124 | int errno); | |
125 | ||
126 | INLINE_EMUL_GENERIC char *emul_read_string | |
127 | (char *dest, | |
128 | unsigned_word addr, | |
129 | unsigned nr_bytes, | |
130 | cpu *processor, | |
131 | unsigned_word cia); | |
132 | ||
133 | INLINE_EMUL_GENERIC unsigned_word emul_read_word | |
134 | (unsigned_word addr, | |
135 | cpu *processor, | |
136 | unsigned_word cia); | |
137 | ||
138 | INLINE_EMUL_GENERIC void emul_write_word | |
139 | (unsigned_word addr, | |
140 | unsigned_word buf, | |
141 | cpu *processor, | |
142 | unsigned_word cia); | |
143 | ||
144 | INLINE_EMUL_GENERIC void emul_read_buffer | |
145 | (void *dest, | |
146 | unsigned_word addr, | |
147 | unsigned nr_bytes, | |
148 | cpu *processor, | |
149 | unsigned_word cia); | |
150 | ||
151 | INLINE_EMUL_GENERIC void emul_write_buffer | |
152 | (const void *source, | |
153 | unsigned_word addr, | |
154 | unsigned nr_bytes, | |
155 | cpu *processor, | |
156 | unsigned_word cia); | |
157 | ||
158 | #endif /* _EMUL_GENERIC_H_ */ |