/[gxemul]/upstream/0.4.0.1/src/include/misc.h
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /upstream/0.4.0.1/src/include/misc.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 27 - (show annotations)
Mon Oct 8 16:20:18 2007 UTC (16 years, 8 months ago) by dpavlin
File MIME type: text/plain
File size: 4927 byte(s)
0.4.0.1
1 #ifndef MISC_H
2 #define MISC_H
3
4 /*
5 * Copyright (C) 2003-2006 Anders Gavare. All rights reserved.
6 *
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 * $Id: misc.h,v 1.241 2006/06/16 18:31:26 debug Exp $
32 *
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
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 */
54 #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
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 #ifdef HOST_LITTLE_ENDIAN
115 #define LE32_TO_HOST(x) (x)
116 #define BE32_TO_HOST(x) ((((x) & 0xff000000) >> 24) | ((x) << 24) | \
117 (((x) & 0xff0000) >> 8) | (((x) & 0xff00) << 8))
118 #else
119 #define LE32_TO_HOST(x) ((((x) & 0xff000000) >> 24) | ((x) << 24) | \
120 (((x) & 0xff0000) >> 8) | (((x) & 0xff00) << 8))
121 #define BE32_TO_HOST(x) (x)
122 #endif
123
124 /* Debug stuff: */
125 #define DEBUG_BUFSIZE 1024
126 #define DEBUG_INDENTATION 4
127
128
129 /* dec_prom.c: */
130 int decstation_prom_emul(struct cpu *cpu);
131
132
133 /* file.c: */
134 int file_n_executables_loaded(void);
135 void file_load(struct machine *machine, struct memory *mem,
136 char *filename, uint64_t *entrypointp,
137 int arch, uint64_t *gpp, int *byte_order, uint64_t *tocp);
138
139
140 /* main.c: */
141 void debug_indentation(int diff);
142 void debug(char *fmt, ...);
143 void fatal(char *fmt, ...);
144
145
146 /* misc.c: */
147 unsigned long long mystrtoull(const char *s, char **endp, int base);
148 int mymkstemp(char *template);
149 #ifdef USE_STRLCPY_REPLACEMENTS
150 size_t mystrlcpy(char *dst, const char *src, size_t size);
151 size_t mystrlcat(char *dst, const char *src, size_t size);
152 #endif
153
154
155 /* pc_bios.c: */
156 void pc_bios_simple_pmode_setup(struct cpu *cpu);
157 void pc_bios_init(struct cpu *cpu);
158 int pc_bios_emul(struct cpu *cpu);
159
160
161 /* ps2_bios.c: */
162 int playstation2_sifbios_emul(struct cpu *cpu);
163
164
165 /* useremul.c: */
166 void useremul_setup(struct cpu *, int, char **);
167 void useremul_syscall(struct cpu *cpu, uint32_t code);
168 void useremul_name_to_useremul(struct cpu *, char *name,
169 int *arch, char **machine_name, char **cpu_name);
170 void useremul_list_emuls(void);
171 void useremul_init(void);
172
173
174 /* yamon.c: */
175 int yamon_emul(struct cpu *cpu);
176
177
178 #endif /* MISC_H */

  ViewVC Help
Powered by ViewVC 1.1.26