summaryrefslogtreecommitdiff
path: root/sim/ppc/emul_generic.h
blob: 9ea23d4cbd551ee0a2344767d103a94bf4837fb4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/*  This file is part of the program psim.

    Copyright (C) 1994-1996, Andrew Cagney <cagney@highland.com.au>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
    along with this program; if not, see <http://www.gnu.org/licenses/>.
 
    */


#ifndef _EMUL_GENERIC_H_
#define _EMUL_GENERIC_H_

#include "cpu.h"
#include "idecode.h"
#include "os_emul.h"

#include "tree.h"

#include "bfd.h"
#include "libiberty.h"

#ifndef INLINE_EMUL_GENERIC
#define INLINE_EMUL_GENERIC
#endif

/* various PowerPC instructions for writing into memory */
enum {
  emul_call_instruction = 0x1,
  emul_loop_instruction = 0x48000000, /* branch to . */
  emul_rfi_instruction = 0x4c000064,
  emul_blr_instruction = 0x4e800020,
};


/* emulation specific data */

typedef struct _os_emul_data os_emul_data;

typedef os_emul_data *(os_emul_create_handler)
     (device *tree,
      bfd *image,
      const char *emul_name);
typedef void (os_emul_init_handler)
     (os_emul_data *emul_data,
      int nr_cpus);
typedef void (os_emul_system_call_handler)
     (cpu *processor,
      unsigned_word cia,
      os_emul_data *emul_data);
typedef int (os_emul_instruction_call_handler)
     (cpu *processor,
      unsigned_word cia,
      unsigned_word ra,
      os_emul_data *emul_data);

struct _os_emul {
  const char *name;
  os_emul_create_handler *create;
  os_emul_init_handler *init;
  os_emul_system_call_handler *system_call;
  os_emul_instruction_call_handler *instruction_call;
  os_emul_data *data;
};


/* One class of emulation - system call is pretty general, provide a
   common template for implementing this */

typedef struct _emul_syscall emul_syscall;
typedef struct _emul_syscall_descriptor emul_syscall_descriptor;

typedef void (emul_syscall_handler)
     (os_emul_data *emul_data,
      unsigned call,
      const int arg0,
      cpu *processor,
      unsigned_word cia);

struct _emul_syscall_descriptor {
  emul_syscall_handler *handler;
  const char *name;
};

struct _emul_syscall {
  emul_syscall_descriptor *syscall_descriptor;
  int nr_system_calls;
  char **error_names;
  int nr_error_names;
  char **signal_names;
  int nr_signal_names;
};


INLINE_EMUL_GENERIC void emul_do_system_call
(os_emul_data *emul_data,
 emul_syscall *syscall,
 unsigned call,
 const int arg0,
 cpu *processor,
 unsigned_word cia);


INLINE_EMUL_GENERIC unsigned64 emul_read_gpr64
(cpu *processor,
 int g);

INLINE_EMUL_GENERIC void emul_write_gpr64
(cpu *processor,
 int g,
 unsigned64 val);

INLINE_EMUL_GENERIC void emul_write_status
(cpu *processor,
 int status,
 int errno);

INLINE_EMUL_GENERIC void emul_write2_status
(cpu *processor,
 int status1,
 int status2,
 int errno);

INLINE_EMUL_GENERIC char *emul_read_string
(char *dest,
 unsigned_word addr,
 unsigned nr_bytes,
 cpu *processor,
 unsigned_word cia);

INLINE_EMUL_GENERIC unsigned_word emul_read_word
(unsigned_word addr,
 cpu *processor,
 unsigned_word cia);
 
INLINE_EMUL_GENERIC void emul_write_word
(unsigned_word addr,
 unsigned_word buf,
 cpu *processor,
 unsigned_word cia);
 
INLINE_EMUL_GENERIC void emul_read_buffer
(void *dest,
 unsigned_word addr,
 unsigned nr_bytes,
 cpu *processor,
 unsigned_word cia);

INLINE_EMUL_GENERIC void emul_write_buffer
(const void *source,
 unsigned_word addr,
 unsigned nr_bytes,
 cpu *processor,
 unsigned_word cia);

/* Simplify the construction of device trees */

INLINE_EMUL_GENERIC void emul_add_tree_options
(device *tree,
 bfd *image,
 const char *emul,
 const char *env,
 int oea_interrupt_prefix);

INLINE_EMUL_GENERIC void emul_add_tree_hardware
(device *tree);

#endif /* _EMUL_GENERIC_H_ */