1 |
dpavlin |
4 |
#ifndef MISC_H |
2 |
|
|
#define MISC_H |
3 |
|
|
|
4 |
|
|
/* |
5 |
dpavlin |
24 |
* Copyright (C) 2003-2006 Anders Gavare. All rights reserved. |
6 |
dpavlin |
4 |
* |
7 |
|
|
* Redistribution and use in source and binary forms, with or without |
8 |
|
|
* modification, are permitted provided that the following conditions are met: |
9 |
|
|
* |
10 |
|
|
* 1. Redistributions of source code must retain the above copyright |
11 |
|
|
* notice, this list of conditions and the following disclaimer. |
12 |
|
|
* 2. Redistributions in binary form must reproduce the above copyright |
13 |
|
|
* notice, this list of conditions and the following disclaimer in the |
14 |
|
|
* documentation and/or other materials provided with the distribution. |
15 |
|
|
* 3. The name of the author may not be used to endorse or promote products |
16 |
|
|
* derived from this software without specific prior written permission. |
17 |
|
|
* |
18 |
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
19 |
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
20 |
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
21 |
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
22 |
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
23 |
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
24 |
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
25 |
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
26 |
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
27 |
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
28 |
|
|
* SUCH DAMAGE. |
29 |
|
|
* |
30 |
|
|
* |
31 |
dpavlin |
30 |
* $Id: misc.h,v 1.242 2006/07/25 21:03:25 debug Exp $ |
32 |
dpavlin |
4 |
* |
33 |
|
|
* Misc. definitions for gxemul. |
34 |
|
|
*/ |
35 |
|
|
|
36 |
|
|
|
37 |
|
|
#include <sys/types.h> |
38 |
|
|
#include <inttypes.h> |
39 |
|
|
|
40 |
|
|
/* |
41 |
|
|
* ../../config.h contains #defines set by the configure script. Some of these |
42 |
|
|
* might reduce speed of the emulator, so don't enable them unless you |
43 |
|
|
* need them. |
44 |
|
|
*/ |
45 |
|
|
|
46 |
|
|
#include "../../config.h" |
47 |
|
|
|
48 |
dpavlin |
24 |
|
49 |
|
|
#ifdef NO_C99_PRINTF_DEFINES |
50 |
|
|
/* |
51 |
|
|
* This is a SUPER-UGLY HACK which happens to work on some machines. |
52 |
|
|
* The correct solution is to upgrade your compiler to C99. |
53 |
dpavlin |
4 |
*/ |
54 |
dpavlin |
24 |
#ifdef NO_C99_64BIT_LONGLONG |
55 |
|
|
#define PRIi16 "i" |
56 |
|
|
#define PRIi32 "i" |
57 |
|
|
#define PRIi64 "lli" |
58 |
|
|
#define PRIx16 "x" |
59 |
|
|
#define PRIx32 "x" |
60 |
|
|
#define PRIx64 "llx" |
61 |
|
|
#else |
62 |
|
|
#define PRIi16 "i" |
63 |
|
|
#define PRIi32 "i" |
64 |
|
|
#define PRIi64 "li" |
65 |
|
|
#define PRIx16 "x" |
66 |
|
|
#define PRIx32 "x" |
67 |
|
|
#define PRIx64 "lx" |
68 |
|
|
#endif |
69 |
|
|
#endif |
70 |
dpavlin |
4 |
|
71 |
|
|
|
72 |
|
|
#ifdef NO_MAP_ANON |
73 |
|
|
#ifdef mmap |
74 |
|
|
#undef mmap |
75 |
|
|
#endif |
76 |
|
|
#include <fcntl.h> |
77 |
|
|
#include <stdlib.h> |
78 |
|
|
#include <sys/mman.h> |
79 |
|
|
static void *no_map_anon_mmap(void *addr, size_t len, int prot, int flags, |
80 |
|
|
int nonsense_fd, off_t offset) |
81 |
|
|
{ |
82 |
|
|
void *p; |
83 |
|
|
int fd = open("/dev/zero", O_RDWR); |
84 |
|
|
if (fd < 0) { |
85 |
|
|
fprintf(stderr, "Could not open /dev/zero\n"); |
86 |
|
|
exit(1); |
87 |
|
|
} |
88 |
|
|
|
89 |
|
|
printf("addr=%p len=%lli prot=0x%x flags=0x%x nonsense_fd=%i " |
90 |
|
|
"offset=%16lli\n", addr, (long long) len, prot, flags, |
91 |
|
|
nonsense_fd, (long long) offset); |
92 |
|
|
|
93 |
|
|
p = mmap(addr, len, prot, flags, fd, offset); |
94 |
|
|
|
95 |
|
|
printf("p = %p\n", p); |
96 |
|
|
|
97 |
|
|
/* TODO: Close the descriptor? */ |
98 |
|
|
return p; |
99 |
|
|
} |
100 |
|
|
#define mmap no_map_anon_mmap |
101 |
|
|
#endif |
102 |
|
|
|
103 |
|
|
|
104 |
|
|
struct cpu; |
105 |
|
|
struct emul; |
106 |
|
|
struct machine; |
107 |
|
|
struct memory; |
108 |
|
|
|
109 |
|
|
|
110 |
|
|
#define NO_BYTE_ORDER_OVERRIDE -1 |
111 |
|
|
#define EMUL_LITTLE_ENDIAN 0 |
112 |
|
|
#define EMUL_BIG_ENDIAN 1 |
113 |
|
|
|
114 |
dpavlin |
22 |
#ifdef HOST_LITTLE_ENDIAN |
115 |
dpavlin |
30 |
#define LE16_TO_HOST(x) (x) |
116 |
|
|
#define BE16_TO_HOST(x) ((((x) & 0xff00) >> 8) | (((x)&0xff) << 8)) |
117 |
|
|
#else |
118 |
|
|
#define LE16_TO_HOST(x) ((((x) & 0xff00) >> 8) | (((x)&0xff) << 8)) |
119 |
|
|
#define BE16_TO_HOST(x) (x) |
120 |
|
|
#endif |
121 |
|
|
|
122 |
|
|
#ifdef HOST_LITTLE_ENDIAN |
123 |
dpavlin |
22 |
#define LE32_TO_HOST(x) (x) |
124 |
dpavlin |
30 |
#define BE32_TO_HOST(x) ((((x) & 0xff000000) >> 24) | (((x)&0xff) << 24) | \ |
125 |
dpavlin |
22 |
(((x) & 0xff0000) >> 8) | (((x) & 0xff00) << 8)) |
126 |
|
|
#else |
127 |
dpavlin |
30 |
#define LE32_TO_HOST(x) ((((x) & 0xff000000) >> 24) | (((x)&0xff) << 24) | \ |
128 |
dpavlin |
22 |
(((x) & 0xff0000) >> 8) | (((x) & 0xff00) << 8)) |
129 |
|
|
#define BE32_TO_HOST(x) (x) |
130 |
|
|
#endif |
131 |
dpavlin |
4 |
|
132 |
dpavlin |
30 |
|
133 |
dpavlin |
4 |
/* Debug stuff: */ |
134 |
|
|
#define DEBUG_BUFSIZE 1024 |
135 |
dpavlin |
22 |
#define DEBUG_INDENTATION 4 |
136 |
dpavlin |
4 |
|
137 |
|
|
|
138 |
|
|
/* dec_prom.c: */ |
139 |
|
|
int decstation_prom_emul(struct cpu *cpu); |
140 |
|
|
|
141 |
|
|
|
142 |
|
|
/* file.c: */ |
143 |
|
|
int file_n_executables_loaded(void); |
144 |
|
|
void file_load(struct machine *machine, struct memory *mem, |
145 |
|
|
char *filename, uint64_t *entrypointp, |
146 |
|
|
int arch, uint64_t *gpp, int *byte_order, uint64_t *tocp); |
147 |
|
|
|
148 |
|
|
|
149 |
|
|
/* main.c: */ |
150 |
|
|
void debug_indentation(int diff); |
151 |
|
|
void debug(char *fmt, ...); |
152 |
|
|
void fatal(char *fmt, ...); |
153 |
dpavlin |
10 |
|
154 |
|
|
|
155 |
|
|
/* misc.c: */ |
156 |
dpavlin |
4 |
unsigned long long mystrtoull(const char *s, char **endp, int base); |
157 |
dpavlin |
10 |
int mymkstemp(char *template); |
158 |
|
|
#ifdef USE_STRLCPY_REPLACEMENTS |
159 |
|
|
size_t mystrlcpy(char *dst, const char *src, size_t size); |
160 |
|
|
size_t mystrlcat(char *dst, const char *src, size_t size); |
161 |
|
|
#endif |
162 |
dpavlin |
4 |
|
163 |
|
|
|
164 |
|
|
/* pc_bios.c: */ |
165 |
dpavlin |
6 |
void pc_bios_simple_pmode_setup(struct cpu *cpu); |
166 |
|
|
void pc_bios_init(struct cpu *cpu); |
167 |
dpavlin |
4 |
int pc_bios_emul(struct cpu *cpu); |
168 |
|
|
|
169 |
|
|
|
170 |
|
|
/* ps2_bios.c: */ |
171 |
|
|
int playstation2_sifbios_emul(struct cpu *cpu); |
172 |
|
|
|
173 |
|
|
|
174 |
|
|
/* useremul.c: */ |
175 |
|
|
void useremul_setup(struct cpu *, int, char **); |
176 |
|
|
void useremul_syscall(struct cpu *cpu, uint32_t code); |
177 |
|
|
void useremul_name_to_useremul(struct cpu *, char *name, |
178 |
|
|
int *arch, char **machine_name, char **cpu_name); |
179 |
|
|
void useremul_list_emuls(void); |
180 |
|
|
void useremul_init(void); |
181 |
|
|
|
182 |
|
|
|
183 |
dpavlin |
10 |
/* yamon.c: */ |
184 |
|
|
int yamon_emul(struct cpu *cpu); |
185 |
|
|
|
186 |
|
|
|
187 |
dpavlin |
4 |
#endif /* MISC_H */ |