Commit 67b915a5dd52a05f8030cd9edc005effd9c8eea5
1 parent
bb27c190
win32 port (initial patch by kazu)
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@692 c046a42c-6fe2-441c-8c8c-71466251a162
Showing
33 changed files
with
1154 additions
and
757 deletions
Changelog
Makefile
1 | 1 | include config-host.mak |
2 | 2 | |
3 | 3 | CFLAGS=-Wall -O2 -g |
4 | +ifdef CONFIG_WIN32 | |
5 | +CFLAGS+=-fpack-struct | |
6 | +endif | |
4 | 7 | LDFLAGS=-g |
5 | 8 | LIBS= |
6 | 9 | DEFINES+=-D_GNU_SOURCE |
10 | +ifndef CONFIG_WIN32 | |
7 | 11 | TOOLS=qemu-mkcow |
12 | +endif | |
8 | 13 | |
9 | -all: dyngen $(TOOLS) qemu-doc.html qemu.1 | |
14 | +all: dyngen$(EXESUF) $(TOOLS) qemu-doc.html qemu.1 | |
10 | 15 | for d in $(TARGET_DIRS); do \ |
11 | 16 | make -C $$d $@ || exit 1 ; \ |
12 | 17 | done |
... | ... | @@ -14,7 +19,7 @@ all: dyngen $(TOOLS) qemu-doc.html qemu.1 |
14 | 19 | qemu-mkcow: qemu-mkcow.o |
15 | 20 | $(HOST_CC) -o $@ $^ $(LIBS) |
16 | 21 | |
17 | -dyngen: dyngen.o | |
22 | +dyngen$(EXESUF): dyngen.o | |
18 | 23 | $(HOST_CC) -o $@ $^ $(LIBS) |
19 | 24 | |
20 | 25 | %.o: %.c |
... | ... | @@ -23,7 +28,7 @@ dyngen: dyngen.o |
23 | 28 | clean: |
24 | 29 | # avoid old build problems by removing potentially incorrect old files |
25 | 30 | rm -f config.mak config.h op-i386.h opc-i386.h gen-op-i386.h op-arm.h opc-arm.h gen-op-arm.h |
26 | - rm -f *.o *.a $(TOOLS) dyngen TAGS qemu.pod | |
31 | + rm -f *.o *.a $(TOOLS) dyngen$(EXESUF) TAGS qemu.pod | |
27 | 32 | make -C tests clean |
28 | 33 | for d in $(TARGET_DIRS); do \ |
29 | 34 | make -C $$d $@ || exit 1 ; \ | ... | ... |
Makefile.target
... | ... | @@ -11,12 +11,12 @@ CFLAGS=-Wall -O2 -g |
11 | 11 | LDFLAGS=-g |
12 | 12 | LIBS= |
13 | 13 | HELPER_CFLAGS=$(CFLAGS) |
14 | -DYNGEN=../dyngen | |
14 | +DYNGEN=../dyngen$(EXESUF) | |
15 | 15 | # user emulator name |
16 | 16 | QEMU_USER=qemu-$(TARGET_ARCH) |
17 | 17 | # system emulator name |
18 | 18 | ifdef CONFIG_SOFTMMU |
19 | -QEMU_SYSTEM=qemu | |
19 | +QEMU_SYSTEM=qemu$(EXESUF) | |
20 | 20 | else |
21 | 21 | QEMU_SYSTEM=qemu-fast |
22 | 22 | endif |
... | ... | @@ -146,6 +146,9 @@ endif |
146 | 146 | |
147 | 147 | DEFINES+=-D_GNU_SOURCE |
148 | 148 | LIBS+=-lm |
149 | +ifdef CONFIG_WIN32 | |
150 | +LIBS+=-lwinmm | |
151 | +endif | |
149 | 152 | |
150 | 153 | # profiling code |
151 | 154 | ifdef TARGET_GPROF |
... | ... | @@ -219,9 +222,12 @@ ifeq ($(ARCH),alpha) |
219 | 222 | endif |
220 | 223 | |
221 | 224 | # must use static linking to avoid leaving stuff in virtual address space |
222 | -VL_OBJS=vl.o osdep.o block.o monitor.o gdbstub.o \ | |
225 | +VL_OBJS=vl.o osdep.o block.o monitor.o \ | |
223 | 226 | ide.o ne2000.o pckbd.o vga.o sb16.o dma.o oss.o \ |
224 | 227 | fdc.o mc146818rtc.o serial.o i8259.o i8254.o pc.o |
228 | +ifdef CONFIG_GDBSTUB | |
229 | +VL_OBJS+=gdbstub.o | |
230 | +endif | |
225 | 231 | ifeq ($(TARGET_ARCH), ppc) |
226 | 232 | VL_OBJS+= hw.o |
227 | 233 | endif | ... | ... |
TODO
1 | 1 | short term: |
2 | 2 | ---------- |
3 | +- handle fast timers + add explicit clocks | |
4 | +- OS/2 install bug | |
5 | +- win 95 install bug | |
6 | +- handle Self Modifying Code even if modifying current TB (BE OS 5 install) | |
3 | 7 | - physical memory cache (reduce qemu-fast address space size to about 32 MB) |
4 | 8 | - better code fetch |
5 | 9 | - XP security bug |
6 | -- handle Self Modifying Code even if modifying current TB (BE OS 5 install) | |
7 | 10 | - cycle counter for all archs |
8 | 11 | - TLB code protection support for PPC |
9 | 12 | - add sysenter/sysexit and fxsr for L4 pistachio 686 | ... | ... |
block.c
... | ... | @@ -21,29 +21,11 @@ |
21 | 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
22 | 22 | * THE SOFTWARE. |
23 | 23 | */ |
24 | -#include <stdlib.h> | |
25 | -#include <stdio.h> | |
26 | -#include <stdarg.h> | |
27 | -#include <string.h> | |
28 | -#include <getopt.h> | |
29 | -#include <inttypes.h> | |
30 | -#include <unistd.h> | |
31 | -#include <sys/mman.h> | |
32 | -#include <fcntl.h> | |
33 | -#include <signal.h> | |
34 | -#include <time.h> | |
35 | -#include <sys/time.h> | |
36 | -#include <malloc.h> | |
37 | -#include <termios.h> | |
38 | -#include <sys/poll.h> | |
39 | -#include <errno.h> | |
40 | -#include <sys/wait.h> | |
41 | -#include <netinet/in.h> | |
42 | - | |
43 | 24 | #include "vl.h" |
44 | 25 | |
45 | -#define NO_THUNK_TYPE_SIZE | |
46 | -#include "thunk.h" | |
26 | +#ifndef _WIN32 | |
27 | +#include <sys/mman.h> | |
28 | +#endif | |
47 | 29 | |
48 | 30 | #include "cow.h" |
49 | 31 | |
... | ... | @@ -97,11 +79,14 @@ BlockDriverState *bdrv_new(const char *device_name) |
97 | 79 | |
98 | 80 | int bdrv_open(BlockDriverState *bs, const char *filename, int snapshot) |
99 | 81 | { |
100 | - int fd, cow_fd; | |
82 | + int fd; | |
101 | 83 | int64_t size; |
102 | - char template[] = "/tmp/vl.XXXXXX"; | |
103 | 84 | struct cow_header_v2 cow_header; |
85 | +#ifndef _WIN32 | |
86 | + char template[] = "/tmp/vl.XXXXXX"; | |
87 | + int cow_fd; | |
104 | 88 | struct stat st; |
89 | +#endif | |
105 | 90 | |
106 | 91 | bs->read_only = 0; |
107 | 92 | bs->fd = -1; |
... | ... | @@ -110,10 +95,18 @@ int bdrv_open(BlockDriverState *bs, const char *filename, int snapshot) |
110 | 95 | strcpy(bs->filename, filename); |
111 | 96 | |
112 | 97 | /* open standard HD image */ |
98 | +#ifdef _WIN32 | |
99 | + fd = open(filename, O_RDWR | O_BINARY); | |
100 | +#else | |
113 | 101 | fd = open(filename, O_RDWR | O_LARGEFILE); |
102 | +#endif | |
114 | 103 | if (fd < 0) { |
115 | 104 | /* read only image on disk */ |
105 | +#ifdef _WIN32 | |
106 | + fd = open(filename, O_RDONLY | O_BINARY); | |
107 | +#else | |
116 | 108 | fd = open(filename, O_RDONLY | O_LARGEFILE); |
109 | +#endif | |
117 | 110 | if (fd < 0) { |
118 | 111 | perror(filename); |
119 | 112 | goto fail; |
... | ... | @@ -128,8 +121,9 @@ int bdrv_open(BlockDriverState *bs, const char *filename, int snapshot) |
128 | 121 | fprintf(stderr, "%s: could not read header\n", filename); |
129 | 122 | goto fail; |
130 | 123 | } |
131 | - if (cow_header.magic == htonl(COW_MAGIC) && | |
132 | - cow_header.version == htonl(COW_VERSION)) { | |
124 | +#ifndef _WIN32 | |
125 | + if (be32_to_cpu(cow_header.magic) == COW_MAGIC && | |
126 | + be32_to_cpu(cow_header.version) == COW_VERSION) { | |
133 | 127 | /* cow image found */ |
134 | 128 | size = cow_header.size; |
135 | 129 | #ifndef WORDS_BIGENDIAN |
... | ... | @@ -144,7 +138,7 @@ int bdrv_open(BlockDriverState *bs, const char *filename, int snapshot) |
144 | 138 | fprintf(stderr, "%s: could not find original disk image '%s'\n", filename, cow_header.backing_file); |
145 | 139 | goto fail; |
146 | 140 | } |
147 | - if (st.st_mtime != htonl(cow_header.mtime)) { | |
141 | + if (st.st_mtime != be32_to_cpu(cow_header.mtime)) { | |
148 | 142 | fprintf(stderr, "%s: original raw disk image '%s' does not match saved timestamp\n", filename, cow_header.backing_file); |
149 | 143 | goto fail; |
150 | 144 | } |
... | ... | @@ -164,13 +158,16 @@ int bdrv_open(BlockDriverState *bs, const char *filename, int snapshot) |
164 | 158 | bs->cow_bitmap = bs->cow_bitmap_addr + sizeof(cow_header); |
165 | 159 | bs->cow_sectors_offset = (bs->cow_bitmap_size + 511) & ~511; |
166 | 160 | snapshot = 0; |
167 | - } else { | |
161 | + } else | |
162 | +#endif | |
163 | + { | |
168 | 164 | /* standard raw image */ |
169 | 165 | size = lseek64(fd, 0, SEEK_END); |
170 | 166 | bs->total_sectors = size / 512; |
171 | 167 | bs->fd = fd; |
172 | 168 | } |
173 | 169 | |
170 | +#ifndef _WIN32 | |
174 | 171 | if (snapshot) { |
175 | 172 | /* create a temporary COW file */ |
176 | 173 | cow_fd = mkstemp(template); |
... | ... | @@ -190,6 +187,7 @@ int bdrv_open(BlockDriverState *bs, const char *filename, int snapshot) |
190 | 187 | bs->cow_bitmap = bs->cow_bitmap_addr; |
191 | 188 | bs->cow_sectors_offset = 0; |
192 | 189 | } |
190 | +#endif | |
193 | 191 | |
194 | 192 | bs->inserted = 1; |
195 | 193 | |
... | ... | @@ -206,9 +204,11 @@ int bdrv_open(BlockDriverState *bs, const char *filename, int snapshot) |
206 | 204 | void bdrv_close(BlockDriverState *bs) |
207 | 205 | { |
208 | 206 | if (bs->inserted) { |
207 | +#ifndef _WIN32 | |
209 | 208 | /* we unmap the mapping so that it is written to the COW file */ |
210 | 209 | if (bs->cow_bitmap_addr) |
211 | 210 | munmap(bs->cow_bitmap_addr, bs->cow_bitmap_size); |
211 | +#endif | |
212 | 212 | if (bs->cow_fd >= 0) |
213 | 213 | close(bs->cow_fd); |
214 | 214 | if (bs->fd >= 0) | ... | ... |
configure
... | ... | @@ -68,10 +68,16 @@ case "$cpu" in |
68 | 68 | esac |
69 | 69 | gprof="no" |
70 | 70 | bigendian="no" |
71 | +mingw32="no" | |
72 | +EXESUF="" | |
73 | +gdbstub="yes" | |
71 | 74 | |
72 | 75 | # OS specific |
73 | 76 | targetos=`uname -s` |
74 | 77 | case $targetos in |
78 | +MINGW32*) | |
79 | +mingw32="yes" | |
80 | +;; | |
75 | 81 | *) ;; |
76 | 82 | esac |
77 | 83 | |
... | ... | @@ -136,6 +142,8 @@ for opt do |
136 | 142 | ;; |
137 | 143 | --disable-sdl) sdl="no" |
138 | 144 | ;; |
145 | + --enable-mingw32) mingw32="yes" ; cross_prefix="i386-mingw32-" | |
146 | + ;; | |
139 | 147 | esac |
140 | 148 | done |
141 | 149 | |
... | ... | @@ -148,6 +156,14 @@ cc="${cross_prefix}${cc}" |
148 | 156 | ar="${cross_prefix}${ar}" |
149 | 157 | strip="${cross_prefix}${strip}" |
150 | 158 | |
159 | +if test "$mingw32" = "yes" ; then | |
160 | + host_cc="$cc" | |
161 | + target_list="i386-softmmu" | |
162 | + prefix="/c/Program Files/Qemu" | |
163 | + EXESUF=".exe" | |
164 | + gdbstub="no" | |
165 | +fi | |
166 | + | |
151 | 167 | if test -z "$cross_prefix" ; then |
152 | 168 | |
153 | 169 | # --- |
... | ... | @@ -206,6 +222,7 @@ echo " --cross-prefix=PREFIX use PREFIX for compile tools [$cross_prefix]" |
206 | 222 | echo " --cc=CC use C compiler CC [$cc]" |
207 | 223 | echo " --make=MAKE use specified make [$make]" |
208 | 224 | echo " --static enable static build [$static]" |
225 | +echo " --enable-mingw32 enable Win32 cross compilation with mingw32" | |
209 | 226 | echo "" |
210 | 227 | echo "NOTE: The object files are build at the place where configure is launched" |
211 | 228 | exit 1 |
... | ... | @@ -227,6 +244,8 @@ echo "target list $target_list" |
227 | 244 | echo "gprof enabled $gprof" |
228 | 245 | echo "static build $static" |
229 | 246 | echo "SDL support $sdl" |
247 | +echo "mingw32 support $mingw32" | |
248 | + | |
230 | 249 | if test $sdl_too_old = "yes"; then |
231 | 250 | echo "-> Your SDL version is too old - please upgrade to have FFplay/SDL support" |
232 | 251 | fi |
... | ... | @@ -253,6 +272,7 @@ echo "AR=$ar" >> $config_mak |
253 | 272 | echo "STRIP=$strip -s -R .comment -R .note" >> $config_mak |
254 | 273 | echo "CFLAGS=$CFLAGS" >> $config_mak |
255 | 274 | echo "LDFLAGS=$LDFLAGS" >> $config_mak |
275 | +echo "EXESUF=$EXESUF" >> $config_mak | |
256 | 276 | if test "$cpu" = "i386" ; then |
257 | 277 | echo "ARCH=i386" >> $config_mak |
258 | 278 | echo "#define HOST_I386 1" >> $config_h |
... | ... | @@ -294,7 +314,15 @@ if test "$bigendian" = "yes" ; then |
294 | 314 | echo "WORDS_BIGENDIAN=yes" >> $config_mak |
295 | 315 | echo "#define WORDS_BIGENDIAN 1" >> $config_h |
296 | 316 | fi |
297 | -echo "#define HAVE_BYTESWAP_H 1" >> $config_h | |
317 | +if test "$mingw32" = "yes" ; then | |
318 | + echo "CONFIG_WIN32=yes" >> $config_mak | |
319 | +else | |
320 | + echo "#define HAVE_BYTESWAP_H 1" >> $config_h | |
321 | +fi | |
322 | +if test "$gdbstub" = "yes" ; then | |
323 | + echo "CONFIG_GDBSTUB=yes" >> $config_mak | |
324 | + echo "#define CONFIG_GDBSTUB 1" >> $config_h | |
325 | +fi | |
298 | 326 | if test "$gprof" = "yes" ; then |
299 | 327 | echo "TARGET_GPROF=yes" >> $config_mak |
300 | 328 | echo "#define HAVE_GPROF 1" >> $config_h | ... | ... |
cpu-exec.c
... | ... | @@ -592,6 +592,8 @@ void cpu_x86_frstor(CPUX86State *s, uint8_t *ptr, int data32) |
592 | 592 | |
593 | 593 | #endif /* TARGET_I386 */ |
594 | 594 | |
595 | +#if !defined(CONFIG_SOFTMMU) | |
596 | + | |
595 | 597 | #undef EAX |
596 | 598 | #undef ECX |
597 | 599 | #undef EDX |
... | ... | @@ -925,3 +927,5 @@ int cpu_signal_handler(int host_signum, struct siginfo *info, |
925 | 927 | #error host CPU specific signal handler needed |
926 | 928 | |
927 | 929 | #endif |
930 | + | |
931 | +#endif /* !defined(CONFIG_SOFTMMU) */ | ... | ... |
dyngen.c
... | ... | @@ -3,6 +3,9 @@ |
3 | 3 | * |
4 | 4 | * Copyright (c) 2003 Fabrice Bellard |
5 | 5 | * |
6 | + * The COFF object format support was extracted from Kazu's QEMU port | |
7 | + * to Win32. | |
8 | + * | |
6 | 9 | * This program is free software; you can redistribute it and/or modify |
7 | 10 | * it under the terms of the GNU General Public License as published by |
8 | 11 | * the Free Software Foundation; either version 2 of the License, or |
... | ... | @@ -27,6 +30,14 @@ |
27 | 30 | |
28 | 31 | #include "config-host.h" |
29 | 32 | |
33 | +#if defined(_WIN32) | |
34 | +#define CONFIG_FORMAT_COFF | |
35 | +#else | |
36 | +#define CONFIG_FORMAT_ELF | |
37 | +#endif | |
38 | + | |
39 | +#ifdef CONFIG_FORMAT_ELF | |
40 | + | |
30 | 41 | /* elf format definitions. We use these macros to test the CPU to |
31 | 42 | allow cross compilation (this tool must be ran on the build |
32 | 43 | platform) */ |
... | ... | @@ -122,6 +133,40 @@ typedef uint64_t host_ulong; |
122 | 133 | #define SHT_RELOC SHT_REL |
123 | 134 | #endif |
124 | 135 | |
136 | +#define EXE_RELOC ELF_RELOC | |
137 | +#define EXE_SYM ElfW(Sym) | |
138 | + | |
139 | +#endif /* CONFIG_FORMAT_ELF */ | |
140 | + | |
141 | +#ifdef CONFIG_FORMAT_COFF | |
142 | + | |
143 | +#include "a.out.h" | |
144 | + | |
145 | +typedef int32_t host_long; | |
146 | +typedef uint32_t host_ulong; | |
147 | + | |
148 | +#define FILENAMELEN 256 | |
149 | + | |
150 | +typedef struct coff_sym { | |
151 | + struct external_syment *st_syment; | |
152 | + char st_name[FILENAMELEN]; | |
153 | + uint32_t st_value; | |
154 | + int st_size; | |
155 | + uint8_t st_type; | |
156 | + uint8_t st_shndx; | |
157 | +} coff_Sym; | |
158 | + | |
159 | +typedef struct coff_rel { | |
160 | + struct external_reloc *r_reloc; | |
161 | + int r_offset; | |
162 | + uint8_t r_type; | |
163 | +} coff_Rel; | |
164 | + | |
165 | +#define EXE_RELOC struct coff_rel | |
166 | +#define EXE_SYM struct coff_sym | |
167 | + | |
168 | +#endif /* CONFIG_FORMAT_COFF */ | |
169 | + | |
125 | 170 | #include "bswap.h" |
126 | 171 | |
127 | 172 | enum { |
... | ... | @@ -133,18 +178,67 @@ enum { |
133 | 178 | /* all dynamically generated functions begin with this code */ |
134 | 179 | #define OP_PREFIX "op_" |
135 | 180 | |
136 | -int elf_must_swap(struct elfhdr *h) | |
181 | +int do_swap; | |
182 | + | |
183 | +void __attribute__((noreturn)) __attribute__((format (printf, 1, 2))) error(const char *fmt, ...) | |
137 | 184 | { |
138 | - union { | |
139 | - uint32_t i; | |
140 | - uint8_t b[4]; | |
141 | - } swaptest; | |
185 | + va_list ap; | |
186 | + va_start(ap, fmt); | |
187 | + fprintf(stderr, "dyngen: "); | |
188 | + vfprintf(stderr, fmt, ap); | |
189 | + fprintf(stderr, "\n"); | |
190 | + va_end(ap); | |
191 | + exit(1); | |
192 | +} | |
142 | 193 | |
143 | - swaptest.i = 1; | |
144 | - return (h->e_ident[EI_DATA] == ELFDATA2MSB) != | |
145 | - (swaptest.b[0] == 0); | |
194 | +void *load_data(int fd, long offset, unsigned int size) | |
195 | +{ | |
196 | + char *data; | |
197 | + | |
198 | + data = malloc(size); | |
199 | + if (!data) | |
200 | + return NULL; | |
201 | + lseek(fd, offset, SEEK_SET); | |
202 | + if (read(fd, data, size) != size) { | |
203 | + free(data); | |
204 | + return NULL; | |
205 | + } | |
206 | + return data; | |
146 | 207 | } |
147 | - | |
208 | + | |
209 | +int strstart(const char *str, const char *val, const char **ptr) | |
210 | +{ | |
211 | + const char *p, *q; | |
212 | + p = str; | |
213 | + q = val; | |
214 | + while (*q != '\0') { | |
215 | + if (*p != *q) | |
216 | + return 0; | |
217 | + p++; | |
218 | + q++; | |
219 | + } | |
220 | + if (ptr) | |
221 | + *ptr = p; | |
222 | + return 1; | |
223 | +} | |
224 | + | |
225 | +void pstrcpy(char *buf, int buf_size, const char *str) | |
226 | +{ | |
227 | + int c; | |
228 | + char *q = buf; | |
229 | + | |
230 | + if (buf_size <= 0) | |
231 | + return; | |
232 | + | |
233 | + for(;;) { | |
234 | + c = *str++; | |
235 | + if (c == 0 || q >= buf + buf_size - 1) | |
236 | + break; | |
237 | + *q++ = c; | |
238 | + } | |
239 | + *q = '\0'; | |
240 | +} | |
241 | + | |
148 | 242 | void swab16s(uint16_t *p) |
149 | 243 | { |
150 | 244 | *p = bswap16(*p); |
... | ... | @@ -160,6 +254,66 @@ void swab64s(uint64_t *p) |
160 | 254 | *p = bswap64(*p); |
161 | 255 | } |
162 | 256 | |
257 | +uint16_t get16(uint16_t *p) | |
258 | +{ | |
259 | + uint16_t val; | |
260 | + val = *p; | |
261 | + if (do_swap) | |
262 | + val = bswap16(val); | |
263 | + return val; | |
264 | +} | |
265 | + | |
266 | +uint32_t get32(uint32_t *p) | |
267 | +{ | |
268 | + uint32_t val; | |
269 | + val = *p; | |
270 | + if (do_swap) | |
271 | + val = bswap32(val); | |
272 | + return val; | |
273 | +} | |
274 | + | |
275 | +void put16(uint16_t *p, uint16_t val) | |
276 | +{ | |
277 | + if (do_swap) | |
278 | + val = bswap16(val); | |
279 | + *p = val; | |
280 | +} | |
281 | + | |
282 | +void put32(uint32_t *p, uint32_t val) | |
283 | +{ | |
284 | + if (do_swap) | |
285 | + val = bswap32(val); | |
286 | + *p = val; | |
287 | +} | |
288 | + | |
289 | +/* executable information */ | |
290 | +EXE_SYM *symtab; | |
291 | +int nb_syms; | |
292 | +int text_shndx; | |
293 | +uint8_t *text; | |
294 | +EXE_RELOC *relocs; | |
295 | +int nb_relocs; | |
296 | + | |
297 | +#ifdef CONFIG_FORMAT_ELF | |
298 | + | |
299 | +/* ELF file info */ | |
300 | +struct elf_shdr *shdr; | |
301 | +uint8_t **sdata; | |
302 | +struct elfhdr ehdr; | |
303 | +char *strtab; | |
304 | + | |
305 | +int elf_must_swap(struct elfhdr *h) | |
306 | +{ | |
307 | + union { | |
308 | + uint32_t i; | |
309 | + uint8_t b[4]; | |
310 | + } swaptest; | |
311 | + | |
312 | + swaptest.i = 1; | |
313 | + return (h->e_ident[EI_DATA] == ELFDATA2MSB) != | |
314 | + (swaptest.b[0] == 0); | |
315 | +} | |
316 | + | |
163 | 317 | void elf_swap_ehdr(struct elfhdr *h) |
164 | 318 | { |
165 | 319 | swab16s(&h->e_type); /* Object file type */ |
... | ... | @@ -212,122 +366,396 @@ void elf_swap_rel(ELF_RELOC *rel) |
212 | 366 | #endif |
213 | 367 | } |
214 | 368 | |
215 | -/* ELF file info */ | |
216 | -int do_swap; | |
217 | -struct elf_shdr *shdr; | |
218 | -uint8_t **sdata; | |
219 | -struct elfhdr ehdr; | |
220 | -ElfW(Sym) *symtab; | |
221 | -int nb_syms; | |
222 | -char *strtab; | |
223 | -int text_shndx; | |
369 | +struct elf_shdr *find_elf_section(struct elf_shdr *shdr, int shnum, const char *shstr, | |
370 | + const char *name) | |
371 | +{ | |
372 | + int i; | |
373 | + const char *shname; | |
374 | + struct elf_shdr *sec; | |
224 | 375 | |
225 | -uint16_t get16(uint16_t *p) | |
376 | + for(i = 0; i < shnum; i++) { | |
377 | + sec = &shdr[i]; | |
378 | + if (!sec->sh_name) | |
379 | + continue; | |
380 | + shname = shstr + sec->sh_name; | |
381 | + if (!strcmp(shname, name)) | |
382 | + return sec; | |
383 | + } | |
384 | + return NULL; | |
385 | +} | |
386 | + | |
387 | +int find_reloc(int sh_index) | |
226 | 388 | { |
227 | - uint16_t val; | |
228 | - val = *p; | |
229 | - if (do_swap) | |
230 | - val = bswap16(val); | |
231 | - return val; | |
389 | + struct elf_shdr *sec; | |
390 | + int i; | |
391 | + | |
392 | + for(i = 0; i < ehdr.e_shnum; i++) { | |
393 | + sec = &shdr[i]; | |
394 | + if (sec->sh_type == SHT_RELOC && sec->sh_info == sh_index) | |
395 | + return i; | |
396 | + } | |
397 | + return 0; | |
232 | 398 | } |
233 | 399 | |
234 | -uint32_t get32(uint32_t *p) | |
400 | +static char *get_rel_sym_name(EXE_RELOC *rel) | |
235 | 401 | { |
236 | - uint32_t val; | |
237 | - val = *p; | |
402 | + return strtab + symtab[ELFW(R_SYM)(rel->r_info)].st_name; | |
403 | +} | |
404 | + | |
405 | +static char *get_sym_name(EXE_SYM *sym) | |
406 | +{ | |
407 | + return strtab + sym->st_name; | |
408 | +} | |
409 | + | |
410 | +/* load an elf object file */ | |
411 | +int load_object(const char *filename) | |
412 | +{ | |
413 | + int fd; | |
414 | + struct elf_shdr *sec, *symtab_sec, *strtab_sec, *text_sec; | |
415 | + int i, j; | |
416 | + ElfW(Sym) *sym; | |
417 | + char *shstr; | |
418 | + ELF_RELOC *rel; | |
419 | + | |
420 | + fd = open(filename, O_RDONLY); | |
421 | + if (fd < 0) | |
422 | + error("can't open file '%s'", filename); | |
423 | + | |
424 | + /* Read ELF header. */ | |
425 | + if (read(fd, &ehdr, sizeof (ehdr)) != sizeof (ehdr)) | |
426 | + error("unable to read file header"); | |
427 | + | |
428 | + /* Check ELF identification. */ | |
429 | + if (ehdr.e_ident[EI_MAG0] != ELFMAG0 | |
430 | + || ehdr.e_ident[EI_MAG1] != ELFMAG1 | |
431 | + || ehdr.e_ident[EI_MAG2] != ELFMAG2 | |
432 | + || ehdr.e_ident[EI_MAG3] != ELFMAG3 | |
433 | + || ehdr.e_ident[EI_VERSION] != EV_CURRENT) { | |
434 | + error("bad ELF header"); | |
435 | + } | |
436 | + | |
437 | + do_swap = elf_must_swap(&ehdr); | |
238 | 438 | if (do_swap) |
239 | - val = bswap32(val); | |
240 | - return val; | |
439 | + elf_swap_ehdr(&ehdr); | |
440 | + if (ehdr.e_ident[EI_CLASS] != ELF_CLASS) | |
441 | + error("Unsupported ELF class"); | |
442 | + if (ehdr.e_type != ET_REL) | |
443 | + error("ELF object file expected"); | |
444 | + if (ehdr.e_version != EV_CURRENT) | |
445 | + error("Invalid ELF version"); | |
446 | + if (!elf_check_arch(ehdr.e_machine)) | |
447 | + error("Unsupported CPU (e_machine=%d)", ehdr.e_machine); | |
448 | + | |
449 | + /* read section headers */ | |
450 | + shdr = load_data(fd, ehdr.e_shoff, ehdr.e_shnum * sizeof(struct elf_shdr)); | |
451 | + if (do_swap) { | |
452 | + for(i = 0; i < ehdr.e_shnum; i++) { | |
453 | + elf_swap_shdr(&shdr[i]); | |
454 | + } | |
455 | + } | |
456 | + | |
457 | + /* read all section data */ | |
458 | + sdata = malloc(sizeof(void *) * ehdr.e_shnum); | |
459 | + memset(sdata, 0, sizeof(void *) * ehdr.e_shnum); | |
460 | + | |
461 | + for(i = 0;i < ehdr.e_shnum; i++) { | |
462 | + sec = &shdr[i]; | |
463 | + if (sec->sh_type != SHT_NOBITS) | |
464 | + sdata[i] = load_data(fd, sec->sh_offset, sec->sh_size); | |
465 | + } | |
466 | + | |
467 | + sec = &shdr[ehdr.e_shstrndx]; | |
468 | + shstr = sdata[ehdr.e_shstrndx]; | |
469 | + | |
470 | + /* swap relocations */ | |
471 | + for(i = 0; i < ehdr.e_shnum; i++) { | |
472 | + sec = &shdr[i]; | |
473 | + if (sec->sh_type == SHT_RELOC) { | |
474 | + nb_relocs = sec->sh_size / sec->sh_entsize; | |
475 | + if (do_swap) { | |
476 | + for(j = 0, rel = (ELF_RELOC *)sdata[i]; j < nb_relocs; j++, rel++) | |
477 | + elf_swap_rel(rel); | |
478 | + } | |
479 | + } | |
480 | + } | |
481 | + /* text section */ | |
482 | + | |
483 | + text_sec = find_elf_section(shdr, ehdr.e_shnum, shstr, ".text"); | |
484 | + if (!text_sec) | |
485 | + error("could not find .text section"); | |
486 | + text_shndx = text_sec - shdr; | |
487 | + text = sdata[text_shndx]; | |
488 | + | |
489 | + /* find text relocations, if any */ | |
490 | + relocs = NULL; | |
491 | + nb_relocs = 0; | |
492 | + i = find_reloc(text_shndx); | |
493 | + if (i != 0) { | |
494 | + relocs = (ELF_RELOC *)sdata[i]; | |
495 | + nb_relocs = shdr[i].sh_size / shdr[i].sh_entsize; | |
496 | + } | |
497 | + | |
498 | + symtab_sec = find_elf_section(shdr, ehdr.e_shnum, shstr, ".symtab"); | |
499 | + if (!symtab_sec) | |
500 | + error("could not find .symtab section"); | |
501 | + strtab_sec = &shdr[symtab_sec->sh_link]; | |
502 | + | |
503 | + symtab = (ElfW(Sym) *)sdata[symtab_sec - shdr]; | |
504 | + strtab = sdata[symtab_sec->sh_link]; | |
505 | + | |
506 | + nb_syms = symtab_sec->sh_size / sizeof(ElfW(Sym)); | |
507 | + if (do_swap) { | |
508 | + for(i = 0, sym = symtab; i < nb_syms; i++, sym++) { | |
509 | + swab32s(&sym->st_name); | |
510 | + swabls(&sym->st_value); | |
511 | + swabls(&sym->st_size); | |
512 | + swab16s(&sym->st_shndx); | |
513 | + } | |
514 | + } | |
515 | + close(fd); | |
516 | + return 0; | |
517 | +} | |
518 | + | |
519 | +#endif /* CONFIG_FORMAT_ELF */ | |
520 | + | |
521 | +#ifdef CONFIG_FORMAT_COFF | |
522 | + | |
523 | +/* COFF file info */ | |
524 | +struct external_scnhdr *shdr; | |
525 | +uint8_t **sdata; | |
526 | +struct external_filehdr fhdr; | |
527 | +struct external_syment *coff_symtab; | |
528 | +char *strtab; | |
529 | +int coff_text_shndx, coff_data_shndx; | |
530 | + | |
531 | +int data_shndx; | |
532 | + | |
533 | +#define STRTAB_SIZE 4 | |
534 | + | |
535 | +#define DIR32 0x06 | |
536 | +#define DISP32 0x14 | |
537 | + | |
538 | +#define T_FUNCTION 0x20 | |
539 | +#define C_EXTERNAL 2 | |
540 | + | |
541 | +void sym_ent_name(struct external_syment *ext_sym, EXE_SYM *sym) | |
542 | +{ | |
543 | + char *q; | |
544 | + int c, i, len; | |
545 | + | |
546 | + if (ext_sym->e.e.e_zeroes != 0) { | |
547 | + q = sym->st_name; | |
548 | + for(i = 0; i < 8; i++) { | |
549 | + c = ext_sym->e.e_name[i]; | |
550 | + if (c == '\0') | |
551 | + break; | |
552 | + *q++ = c; | |
553 | + } | |
554 | + *q = '\0'; | |
555 | + } else { | |
556 | + pstrcpy(sym->st_name, sizeof(sym->st_name), strtab + ext_sym->e.e.e_offset); | |
557 | + } | |
558 | + | |
559 | + /* now convert the name to a C name (suppress the leading '_') */ | |
560 | + if (sym->st_name[0] == '_') { | |
561 | + len = strlen(sym->st_name); | |
562 | + memmove(sym->st_name, sym->st_name + 1, len - 1); | |
563 | + sym->st_name[len - 1] = '\0'; | |
564 | + } | |
241 | 565 | } |
242 | 566 | |
243 | -void put16(uint16_t *p, uint16_t val) | |
567 | +char *name_for_dotdata(struct coff_rel *rel) | |
244 | 568 | { |
245 | - if (do_swap) | |
246 | - val = bswap16(val); | |
247 | - *p = val; | |
569 | + int i; | |
570 | + struct coff_sym *sym; | |
571 | + uint32_t text_data; | |
572 | + | |
573 | + text_data = *(uint32_t *)(text + rel->r_offset); | |
574 | + | |
575 | + for (i = 0, sym = symtab; i < nb_syms; i++, sym++) { | |
576 | + if (sym->st_syment->e_scnum == data_shndx && | |
577 | + text_data >= sym->st_value && | |
578 | + text_data < sym->st_value + sym->st_size) { | |
579 | + | |
580 | + return sym->st_name; | |
581 | + | |
582 | + } | |
583 | + } | |
584 | + return NULL; | |
248 | 585 | } |
249 | 586 | |
250 | -void put32(uint32_t *p, uint32_t val) | |
587 | +static char *get_sym_name(EXE_SYM *sym) | |
251 | 588 | { |
252 | - if (do_swap) | |
253 | - val = bswap32(val); | |
254 | - *p = val; | |
589 | + return sym->st_name; | |
255 | 590 | } |
256 | 591 | |
257 | -void __attribute__((noreturn)) __attribute__((format (printf, 1, 2))) error(const char *fmt, ...) | |
592 | +static char *get_rel_sym_name(EXE_RELOC *rel) | |
258 | 593 | { |
259 | - va_list ap; | |
260 | - va_start(ap, fmt); | |
261 | - fprintf(stderr, "dyngen: "); | |
262 | - vfprintf(stderr, fmt, ap); | |
263 | - fprintf(stderr, "\n"); | |
264 | - va_end(ap); | |
265 | - exit(1); | |
594 | + char *name; | |
595 | + name = get_sym_name(symtab + *(uint32_t *)(rel->r_reloc->r_symndx)); | |
596 | + if (!strcmp(name, ".data")) | |
597 | + name = name_for_dotdata(rel); | |
598 | + return name; | |
266 | 599 | } |
267 | 600 | |
268 | - | |
269 | -struct elf_shdr *find_elf_section(struct elf_shdr *shdr, int shnum, const char *shstr, | |
270 | - const char *name) | |
601 | +struct external_scnhdr *find_coff_section(struct external_scnhdr *shdr, int shnum, const char *name) | |
271 | 602 | { |
272 | 603 | int i; |
273 | 604 | const char *shname; |
274 | - struct elf_shdr *sec; | |
605 | + struct external_scnhdr *sec; | |
275 | 606 | |
276 | 607 | for(i = 0; i < shnum; i++) { |
277 | 608 | sec = &shdr[i]; |
278 | - if (!sec->sh_name) | |
609 | + if (!sec->s_name) | |
279 | 610 | continue; |
280 | - shname = shstr + sec->sh_name; | |
611 | + shname = sec->s_name; | |
281 | 612 | if (!strcmp(shname, name)) |
282 | 613 | return sec; |
283 | 614 | } |
284 | 615 | return NULL; |
285 | 616 | } |
286 | 617 | |
287 | -int find_reloc(int sh_index) | |
618 | +/* load a coff object file */ | |
619 | +int load_object(const char *filename) | |
288 | 620 | { |
289 | - struct elf_shdr *sec; | |
621 | + int fd; | |
622 | + struct external_scnhdr *sec, *text_sec, *data_sec; | |
290 | 623 | int i; |
624 | + struct external_syment *ext_sym; | |
625 | + struct external_reloc *coff_relocs; | |
626 | + struct external_reloc *ext_rel; | |
627 | + uint32_t *n_strtab; | |
628 | + EXE_SYM *sym; | |
629 | + EXE_RELOC *rel; | |
630 | + | |
631 | + fd = open(filename, O_RDONLY | |
632 | +#ifdef _WIN32 | |
633 | + | O_BINARY | |
634 | +#endif | |
635 | + ); | |
636 | + if (fd < 0) | |
637 | + error("can't open file '%s'", filename); | |
638 | + | |
639 | + /* Read COFF header. */ | |
640 | + if (read(fd, &fhdr, sizeof (fhdr)) != sizeof (fhdr)) | |
641 | + error("unable to read file header"); | |
291 | 642 | |
292 | - for(i = 0; i < ehdr.e_shnum; i++) { | |
643 | + /* Check COFF identification. */ | |
644 | + if (fhdr.f_magic != I386MAGIC) { | |
645 | + error("bad COFF header"); | |
646 | + } | |
647 | + do_swap = 0; | |
648 | + | |
649 | + /* read section headers */ | |
650 | + shdr = load_data(fd, sizeof(struct external_filehdr) + fhdr.f_opthdr, fhdr.f_nscns * sizeof(struct external_scnhdr)); | |
651 | + | |
652 | + /* read all section data */ | |
653 | + sdata = malloc(sizeof(void *) * fhdr.f_nscns); | |
654 | + memset(sdata, 0, sizeof(void *) * fhdr.f_nscns); | |
655 | + | |
656 | + const char *p; | |
657 | + for(i = 0;i < fhdr.f_nscns; i++) { | |
293 | 658 | sec = &shdr[i]; |
294 | - if (sec->sh_type == SHT_RELOC && sec->sh_info == sh_index) | |
295 | - return i; | |
659 | + if (!strstart(sec->s_name, ".bss", &p)) | |
660 | + sdata[i] = load_data(fd, sec->s_scnptr, sec->s_size); | |
296 | 661 | } |
297 | - return 0; | |
298 | -} | |
299 | 662 | |
300 | -void *load_data(int fd, long offset, unsigned int size) | |
301 | -{ | |
302 | - char *data; | |
303 | 663 | |
304 | - data = malloc(size); | |
305 | - if (!data) | |
306 | - return NULL; | |
307 | - lseek(fd, offset, SEEK_SET); | |
308 | - if (read(fd, data, size) != size) { | |
309 | - free(data); | |
310 | - return NULL; | |
664 | + /* text section */ | |
665 | + text_sec = find_coff_section(shdr, fhdr.f_nscns, ".text"); | |
666 | + if (!text_sec) | |
667 | + error("could not find .text section"); | |
668 | + coff_text_shndx = text_sec - shdr; | |
669 | + text = sdata[coff_text_shndx]; | |
670 | + | |
671 | + /* data section */ | |
672 | + data_sec = find_coff_section(shdr, fhdr.f_nscns, ".data"); | |
673 | + if (!data_sec) | |
674 | + error("could not find .data section"); | |
675 | + coff_data_shndx = data_sec - shdr; | |
676 | + | |
677 | + coff_symtab = load_data(fd, fhdr.f_symptr, fhdr.f_nsyms*SYMESZ); | |
678 | + for (i = 0, ext_sym = coff_symtab; i < nb_syms; i++, ext_sym++) { | |
679 | + for(i=0;i<8;i++) | |
680 | + printf(" %02x", ((uint8_t *)ext_sym->e.e_name)[i]); | |
681 | + printf("\n"); | |
311 | 682 | } |
312 | - return data; | |
313 | -} | |
314 | 683 | |
315 | -int strstart(const char *str, const char *val, const char **ptr) | |
316 | -{ | |
317 | - const char *p, *q; | |
318 | - p = str; | |
319 | - q = val; | |
320 | - while (*q != '\0') { | |
321 | - if (*p != *q) | |
322 | - return 0; | |
323 | - p++; | |
324 | - q++; | |
684 | + | |
685 | + n_strtab = load_data(fd, (fhdr.f_symptr + fhdr.f_nsyms*SYMESZ), STRTAB_SIZE); | |
686 | + strtab = load_data(fd, (fhdr.f_symptr + fhdr.f_nsyms*SYMESZ), *n_strtab); | |
687 | + | |
688 | + nb_syms = fhdr.f_nsyms; | |
689 | + | |
690 | + for (i = 0, ext_sym = coff_symtab; i < nb_syms; i++, ext_sym++) { | |
691 | + if (strstart(ext_sym->e.e_name, ".text", NULL)) | |
692 | + text_shndx = ext_sym->e_scnum; | |
693 | + if (strstart(ext_sym->e.e_name, ".data", NULL)) | |
694 | + data_shndx = ext_sym->e_scnum; | |
325 | 695 | } |
326 | - if (ptr) | |
327 | - *ptr = p; | |
328 | - return 1; | |
696 | + | |
697 | + /* set coff symbol */ | |
698 | + symtab = malloc(sizeof(struct coff_sym) * nb_syms); | |
699 | + | |
700 | + int aux_size, j; | |
701 | + for (i = 0, ext_sym = coff_symtab, sym = symtab; i < nb_syms; i++, ext_sym++, sym++) { | |
702 | + memset(sym, 0, sizeof(*sym)); | |
703 | + sym->st_syment = ext_sym; | |
704 | + sym_ent_name(ext_sym, sym); | |
705 | + sym->st_value = ext_sym->e_value; | |
706 | + | |
707 | + aux_size = *(int8_t *)ext_sym->e_numaux; | |
708 | + if (ext_sym->e_scnum == text_shndx && ext_sym->e_type == T_FUNCTION) { | |
709 | + for (j = aux_size + 1; j < nb_syms - i; j++) { | |
710 | + if ((ext_sym + j)->e_scnum == text_shndx && | |
711 | + (ext_sym + j)->e_type == T_FUNCTION ){ | |
712 | + sym->st_size = (ext_sym + j)->e_value - ext_sym->e_value; | |
713 | + break; | |
714 | + } else if (j == nb_syms - i - 1) { | |
715 | + sec = &shdr[coff_text_shndx]; | |
716 | + sym->st_size = sec->s_size - ext_sym->e_value; | |
717 | + break; | |
718 | + } | |
719 | + } | |
720 | + } else if (ext_sym->e_scnum == data_shndx && *(uint8_t *)ext_sym->e_sclass == C_EXTERNAL) { | |
721 | + for (j = aux_size + 1; j < nb_syms - i; j++) { | |
722 | + if ((ext_sym + j)->e_scnum == data_shndx) { | |
723 | + sym->st_size = (ext_sym + j)->e_value - ext_sym->e_value; | |
724 | + break; | |
725 | + } else if (j == nb_syms - i - 1) { | |
726 | + sec = &shdr[coff_data_shndx]; | |
727 | + sym->st_size = sec->s_size - ext_sym->e_value; | |
728 | + break; | |
729 | + } | |
730 | + } | |
731 | + } else { | |
732 | + sym->st_size = 0; | |
733 | + } | |
734 | + | |
735 | + sym->st_type = ext_sym->e_type; | |
736 | + sym->st_shndx = ext_sym->e_scnum; | |
737 | + } | |
738 | + | |
739 | + | |
740 | + /* find text relocations, if any */ | |
741 | + sec = &shdr[coff_text_shndx]; | |
742 | + coff_relocs = load_data(fd, sec->s_relptr, sec->s_nreloc*RELSZ); | |
743 | + nb_relocs = sec->s_nreloc; | |
744 | + | |
745 | + /* set coff relocation */ | |
746 | + relocs = malloc(sizeof(struct coff_rel) * nb_relocs); | |
747 | + for (i = 0, ext_rel = coff_relocs, rel = relocs; i < nb_relocs; | |
748 | + i++, ext_rel++, rel++) { | |
749 | + memset(rel, 0, sizeof(*rel)); | |
750 | + rel->r_reloc = ext_rel; | |
751 | + rel->r_offset = *(uint32_t *)ext_rel->r_vaddr; | |
752 | + rel->r_type = *(uint16_t *)ext_rel->r_type; | |
753 | + } | |
754 | + return 0; | |
329 | 755 | } |
330 | 756 | |
757 | +#endif /* CONFIG_FORMAT_COFF */ | |
758 | + | |
331 | 759 | #ifdef HOST_ARM |
332 | 760 | |
333 | 761 | int arm_emit_ldr_info(const char *name, unsigned long start_offset, |
... | ... | @@ -385,7 +813,7 @@ int arm_emit_ldr_info(const char *name, unsigned long start_offset, |
385 | 813 | relname[0] = '\0'; |
386 | 814 | for(i = 0, rel = relocs;i < nb_relocs; i++, rel++) { |
387 | 815 | if (rel->r_offset == (pc_offset + start_offset)) { |
388 | - sym_name = strtab + symtab[ELFW(R_SYM)(rel->r_info)].st_name; | |
816 | + sym_name = get_rel_sym_name(rel); | |
389 | 817 | /* the compiler leave some unnecessary references to the code */ |
390 | 818 | if (strstart(sym_name, "__op_param", &p)) { |
391 | 819 | snprintf(relname, sizeof(relname), "param%s", p); |
... | ... | @@ -432,8 +860,7 @@ int arm_emit_ldr_info(const char *name, unsigned long start_offset, |
432 | 860 | |
433 | 861 | /* generate op code */ |
434 | 862 | void gen_code(const char *name, host_ulong offset, host_ulong size, |
435 | - FILE *outfile, uint8_t *text, ELF_RELOC *relocs, int nb_relocs, | |
436 | - int gen_switch) | |
863 | + FILE *outfile, int gen_switch) | |
437 | 864 | { |
438 | 865 | int copy_size = 0; |
439 | 866 | uint8_t *p_start, *p_end; |
... | ... | @@ -441,7 +868,7 @@ void gen_code(const char *name, host_ulong offset, host_ulong size, |
441 | 868 | int nb_args, i, n; |
442 | 869 | uint8_t args_present[MAX_ARGS]; |
443 | 870 | const char *sym_name, *p; |
444 | - ELF_RELOC *rel; | |
871 | + EXE_RELOC *rel; | |
445 | 872 | |
446 | 873 | /* Compute exact size excluding prologue and epilogue instructions. |
447 | 874 | * Increment start_offset to skip epilogue instructions, then compute |
... | ... | @@ -451,136 +878,141 @@ void gen_code(const char *name, host_ulong offset, host_ulong size, |
451 | 878 | p_start = text + offset; |
452 | 879 | p_end = p_start + size; |
453 | 880 | start_offset = offset; |
454 | - switch(ELF_ARCH) { | |
455 | - case EM_386: | |
456 | - case EM_X86_64: | |
457 | - { | |
458 | - int len; | |
459 | - len = p_end - p_start; | |
460 | - if (len == 0) | |
461 | - error("empty code for %s", name); | |
462 | - if (p_end[-1] == 0xc3) { | |
463 | - len--; | |
464 | - } else { | |
881 | +#if defined(HOST_I386) || defined(HOST_AMD64) | |
882 | +#ifdef CONFIG_FORMAT_COFF | |
883 | + { | |
884 | + uint8_t *p; | |
885 | + p = p_end - 1; | |
886 | + if (p == p_start) | |
887 | + error("empty code for %s", name); | |
888 | + while (*p != 0xc3) { | |
889 | + p--; | |
890 | + if (p <= p_start) | |
465 | 891 | error("ret or jmp expected at the end of %s", name); |
466 | - } | |
467 | - copy_size = len; | |
468 | 892 | } |
469 | - break; | |
470 | - case EM_PPC: | |
471 | - { | |
472 | - uint8_t *p; | |
473 | - p = (void *)(p_end - 4); | |
474 | - if (p == p_start) | |
475 | - error("empty code for %s", name); | |
476 | - if (get32((uint32_t *)p) != 0x4e800020) | |
477 | - error("blr expected at the end of %s", name); | |
478 | - copy_size = p - p_start; | |
893 | + copy_size = p - p_start; | |
894 | + } | |
895 | +#else | |
896 | + { | |
897 | + int len; | |
898 | + len = p_end - p_start; | |
899 | + if (len == 0) | |
900 | + error("empty code for %s", name); | |
901 | + if (p_end[-1] == 0xc3) { | |
902 | + len--; | |
903 | + } else { | |
904 | + error("ret or jmp expected at the end of %s", name); | |
479 | 905 | } |
480 | - break; | |
481 | - case EM_S390: | |
482 | - { | |
483 | - uint8_t *p; | |
484 | - p = (void *)(p_end - 2); | |
485 | - if (p == p_start) | |
486 | - error("empty code for %s", name); | |
487 | - if (get16((uint16_t *)p) != 0x07fe && get16((uint16_t *)p) != 0x07f4) | |
488 | - error("br %%r14 expected at the end of %s", name); | |
489 | - copy_size = p - p_start; | |
490 | - } | |
491 | - break; | |
492 | - case EM_ALPHA: | |
493 | - { | |
494 | - uint8_t *p; | |
495 | - p = p_end - 4; | |
906 | + copy_size = len; | |
907 | + } | |
908 | +#endif | |
909 | +#elif defined(HOST_PPC) | |
910 | + { | |
911 | + uint8_t *p; | |
912 | + p = (void *)(p_end - 4); | |
913 | + if (p == p_start) | |
914 | + error("empty code for %s", name); | |
915 | + if (get32((uint32_t *)p) != 0x4e800020) | |
916 | + error("blr expected at the end of %s", name); | |
917 | + copy_size = p - p_start; | |
918 | + } | |
919 | +#elif defined(HOST_S390) | |
920 | + { | |
921 | + uint8_t *p; | |
922 | + p = (void *)(p_end - 2); | |
923 | + if (p == p_start) | |
924 | + error("empty code for %s", name); | |
925 | + if (get16((uint16_t *)p) != 0x07fe && get16((uint16_t *)p) != 0x07f4) | |
926 | + error("br %%r14 expected at the end of %s", name); | |
927 | + copy_size = p - p_start; | |
928 | + } | |
929 | +#elif defined(HOST_ALPHA) | |
930 | + { | |
931 | + uint8_t *p; | |
932 | + p = p_end - 4; | |
496 | 933 | #if 0 |
497 | - /* XXX: check why it occurs */ | |
498 | - if (p == p_start) | |
499 | - error("empty code for %s", name); | |
934 | + /* XXX: check why it occurs */ | |
935 | + if (p == p_start) | |
936 | + error("empty code for %s", name); | |
500 | 937 | #endif |
501 | - if (get32((uint32_t *)p) != 0x6bfa8001) | |
502 | - error("ret expected at the end of %s", name); | |
503 | - copy_size = p - p_start; | |
504 | - } | |
505 | - break; | |
506 | - case EM_IA_64: | |
507 | - { | |
508 | - uint8_t *p; | |
509 | - p = (void *)(p_end - 4); | |
510 | - if (p == p_start) | |
511 | - error("empty code for %s", name); | |
512 | - /* br.ret.sptk.many b0;; */ | |
513 | - /* 08 00 84 00 */ | |
514 | - if (get32((uint32_t *)p) != 0x00840008) | |
515 | - error("br.ret.sptk.many b0;; expected at the end of %s", name); | |
516 | - copy_size = p - p_start; | |
517 | - } | |
518 | - break; | |
519 | - case EM_SPARC: | |
520 | - case EM_SPARC32PLUS: | |
521 | - { | |
522 | - uint32_t start_insn, end_insn1, end_insn2; | |
523 | - uint8_t *p; | |
524 | - p = (void *)(p_end - 8); | |
525 | - if (p <= p_start) | |
526 | - error("empty code for %s", name); | |
527 | - start_insn = get32((uint32_t *)(p_start + 0x0)); | |
528 | - end_insn1 = get32((uint32_t *)(p + 0x0)); | |
529 | - end_insn2 = get32((uint32_t *)(p + 0x4)); | |
530 | - if ((start_insn & ~0x1fff) == 0x9de3a000) { | |
531 | - p_start += 0x4; | |
532 | - start_offset += 0x4; | |
533 | - if ((int)(start_insn | ~0x1fff) < -128) | |
534 | - error("Found bogus save at the start of %s", name); | |
535 | - if (end_insn1 != 0x81c7e008 || end_insn2 != 0x81e80000) | |
536 | - error("ret; restore; not found at end of %s", name); | |
537 | - } else { | |
538 | - error("No save at the beginning of %s", name); | |
539 | - } | |
938 | + if (get32((uint32_t *)p) != 0x6bfa8001) | |
939 | + error("ret expected at the end of %s", name); | |
940 | + copy_size = p - p_start; | |
941 | + } | |
942 | +#elif defined(HOST_IA64) | |
943 | + { | |
944 | + uint8_t *p; | |
945 | + p = (void *)(p_end - 4); | |
946 | + if (p == p_start) | |
947 | + error("empty code for %s", name); | |
948 | + /* br.ret.sptk.many b0;; */ | |
949 | + /* 08 00 84 00 */ | |
950 | + if (get32((uint32_t *)p) != 0x00840008) | |
951 | + error("br.ret.sptk.many b0;; expected at the end of %s", name); | |
952 | + copy_size = p - p_start; | |
953 | + } | |
954 | +#elif defined(HOST_SPARC) | |
955 | + { | |
956 | + uint32_t start_insn, end_insn1, end_insn2; | |
957 | + uint8_t *p; | |
958 | + p = (void *)(p_end - 8); | |
959 | + if (p <= p_start) | |
960 | + error("empty code for %s", name); | |
961 | + start_insn = get32((uint32_t *)(p_start + 0x0)); | |
962 | + end_insn1 = get32((uint32_t *)(p + 0x0)); | |
963 | + end_insn2 = get32((uint32_t *)(p + 0x4)); | |
964 | + if ((start_insn & ~0x1fff) == 0x9de3a000) { | |
965 | + p_start += 0x4; | |
966 | + start_offset += 0x4; | |
967 | + if ((int)(start_insn | ~0x1fff) < -128) | |
968 | + error("Found bogus save at the start of %s", name); | |
969 | + if (end_insn1 != 0x81c7e008 || end_insn2 != 0x81e80000) | |
970 | + error("ret; restore; not found at end of %s", name); | |
971 | + } else { | |
972 | + error("No save at the beginning of %s", name); | |
973 | + } | |
540 | 974 | #if 0 |
541 | - /* Skip a preceeding nop, if present. */ | |
542 | - if (p > p_start) { | |
543 | - skip_insn = get32((uint32_t *)(p - 0x4)); | |
544 | - if (skip_insn == 0x01000000) | |
545 | - p -= 4; | |
546 | - } | |
975 | + /* Skip a preceeding nop, if present. */ | |
976 | + if (p > p_start) { | |
977 | + skip_insn = get32((uint32_t *)(p - 0x4)); | |
978 | + if (skip_insn == 0x01000000) | |
979 | + p -= 4; | |
980 | + } | |
547 | 981 | #endif |
548 | - copy_size = p - p_start; | |
549 | - } | |
550 | - break; | |
551 | - case EM_SPARCV9: | |
552 | - { | |
553 | - uint32_t start_insn, end_insn1, end_insn2, skip_insn; | |
554 | - uint8_t *p; | |
555 | - p = (void *)(p_end - 8); | |
556 | - if (p <= p_start) | |
557 | - error("empty code for %s", name); | |
558 | - start_insn = get32((uint32_t *)(p_start + 0x0)); | |
559 | - end_insn1 = get32((uint32_t *)(p + 0x0)); | |
560 | - end_insn2 = get32((uint32_t *)(p + 0x4)); | |
561 | - if ((start_insn & ~0x1fff) == 0x9de3a000) { | |
562 | - p_start += 0x4; | |
563 | - start_offset += 0x4; | |
564 | - if ((int)(start_insn | ~0x1fff) < -256) | |
565 | - error("Found bogus save at the start of %s", name); | |
566 | - if (end_insn1 != 0x81c7e008 || end_insn2 != 0x81e80000) | |
567 | - error("ret; restore; not found at end of %s", name); | |
568 | - } else { | |
569 | - error("No save at the beginning of %s", name); | |
570 | - } | |
571 | - | |
572 | - /* Skip a preceeding nop, if present. */ | |
573 | - if (p > p_start) { | |
574 | - skip_insn = get32((uint32_t *)(p - 0x4)); | |
575 | - if (skip_insn == 0x01000000) | |
576 | - p -= 4; | |
577 | - } | |
578 | - | |
579 | - copy_size = p - p_start; | |
580 | - } | |
581 | - break; | |
582 | -#ifdef HOST_ARM | |
583 | - case EM_ARM: | |
982 | + copy_size = p - p_start; | |
983 | + } | |
984 | +#elif defined(HOST_SPARC64) | |
985 | + { | |
986 | + uint32_t start_insn, end_insn1, end_insn2, skip_insn; | |
987 | + uint8_t *p; | |
988 | + p = (void *)(p_end - 8); | |
989 | + if (p <= p_start) | |
990 | + error("empty code for %s", name); | |
991 | + start_insn = get32((uint32_t *)(p_start + 0x0)); | |
992 | + end_insn1 = get32((uint32_t *)(p + 0x0)); | |
993 | + end_insn2 = get32((uint32_t *)(p + 0x4)); | |
994 | + if ((start_insn & ~0x1fff) == 0x9de3a000) { | |
995 | + p_start += 0x4; | |
996 | + start_offset += 0x4; | |
997 | + if ((int)(start_insn | ~0x1fff) < -256) | |
998 | + error("Found bogus save at the start of %s", name); | |
999 | + if (end_insn1 != 0x81c7e008 || end_insn2 != 0x81e80000) | |
1000 | + error("ret; restore; not found at end of %s", name); | |
1001 | + } else { | |
1002 | + error("No save at the beginning of %s", name); | |
1003 | + } | |
1004 | + | |
1005 | + /* Skip a preceeding nop, if present. */ | |
1006 | + if (p > p_start) { | |
1007 | + skip_insn = get32((uint32_t *)(p - 0x4)); | |
1008 | + if (skip_insn == 0x01000000) | |
1009 | + p -= 4; | |
1010 | + } | |
1011 | + | |
1012 | + copy_size = p - p_start; | |
1013 | + } | |
1014 | +#elif defined(HOST_ARM) | |
1015 | + { | |
584 | 1016 | if ((p_end - p_start) <= 16) |
585 | 1017 | error("%s: function too small", name); |
586 | 1018 | if (get32((uint32_t *)p_start) != 0xe1a0c00d || |
... | ... | @@ -591,26 +1023,24 @@ void gen_code(const char *name, host_ulong offset, host_ulong size, |
591 | 1023 | start_offset += 12; |
592 | 1024 | copy_size = arm_emit_ldr_info(name, start_offset, NULL, p_start, p_end, |
593 | 1025 | relocs, nb_relocs); |
594 | - break; | |
595 | -#endif | |
596 | - case EM_68K: | |
597 | - { | |
598 | - uint8_t *p; | |
599 | - p = (void *)(p_end - 2); | |
600 | - if (p == p_start) | |
601 | - error("empty code for %s", name); | |
602 | - // remove NOP's, probably added for alignment | |
603 | - while ((get16((uint16_t *)p) == 0x4e71) && | |
604 | - (p>p_start)) | |
605 | - p -= 2; | |
606 | - if (get16((uint16_t *)p) != 0x4e75) | |
607 | - error("rts expected at the end of %s", name); | |
608 | - copy_size = p - p_start; | |
609 | - } | |
610 | - break; | |
611 | - default: | |
612 | - error("unknown ELF architecture"); | |
613 | 1026 | } |
1027 | +#elif defined(HOST_M68K) | |
1028 | + { | |
1029 | + uint8_t *p; | |
1030 | + p = (void *)(p_end - 2); | |
1031 | + if (p == p_start) | |
1032 | + error("empty code for %s", name); | |
1033 | + // remove NOP's, probably added for alignment | |
1034 | + while ((get16((uint16_t *)p) == 0x4e71) && | |
1035 | + (p>p_start)) | |
1036 | + p -= 2; | |
1037 | + if (get16((uint16_t *)p) != 0x4e75) | |
1038 | + error("rts expected at the end of %s", name); | |
1039 | + copy_size = p - p_start; | |
1040 | + } | |
1041 | +#else | |
1042 | +#error unsupported CPU | |
1043 | +#endif | |
614 | 1044 | |
615 | 1045 | /* compute the number of arguments by looking at the relocations */ |
616 | 1046 | for(i = 0;i < MAX_ARGS; i++) |
... | ... | @@ -619,7 +1049,7 @@ void gen_code(const char *name, host_ulong offset, host_ulong size, |
619 | 1049 | for(i = 0, rel = relocs;i < nb_relocs; i++, rel++) { |
620 | 1050 | if (rel->r_offset >= start_offset && |
621 | 1051 | rel->r_offset < start_offset + (p_end - p_start)) { |
622 | - sym_name = strtab + symtab[ELFW(R_SYM)(rel->r_info)].st_name; | |
1052 | + sym_name = get_rel_sym_name(rel); | |
623 | 1053 | if (strstart(sym_name, "__op_param", &p)) { |
624 | 1054 | n = strtoul(p, NULL, 10); |
625 | 1055 | if (n > MAX_ARGS) |
... | ... | @@ -657,7 +1087,7 @@ void gen_code(const char *name, host_ulong offset, host_ulong size, |
657 | 1087 | for(i = 0, rel = relocs;i < nb_relocs; i++, rel++) { |
658 | 1088 | if (rel->r_offset >= start_offset && |
659 | 1089 | rel->r_offset < start_offset + (p_end - p_start)) { |
660 | - sym_name = strtab + symtab[ELFW(R_SYM)(rel->r_info)].st_name; | |
1090 | + sym_name = get_rel_sym_name(rel); | |
661 | 1091 | if (*sym_name && |
662 | 1092 | !strstart(sym_name, "__op_param", NULL) && |
663 | 1093 | !strstart(sym_name, "__op_jmp", NULL)) { |
... | ... | @@ -678,20 +1108,30 @@ void gen_code(const char *name, host_ulong offset, host_ulong size, |
678 | 1108 | |
679 | 1109 | /* emit code offset information */ |
680 | 1110 | { |
681 | - ElfW(Sym) *sym; | |
1111 | + EXE_SYM *sym; | |
682 | 1112 | const char *sym_name, *p; |
683 | 1113 | unsigned long val; |
684 | 1114 | int n; |
685 | 1115 | |
686 | 1116 | for(i = 0, sym = symtab; i < nb_syms; i++, sym++) { |
687 | - sym_name = strtab + sym->st_name; | |
1117 | + sym_name = get_sym_name(sym); | |
688 | 1118 | if (strstart(sym_name, "__op_label", &p)) { |
689 | 1119 | uint8_t *ptr; |
690 | 1120 | unsigned long offset; |
691 | 1121 | |
692 | 1122 | /* test if the variable refers to a label inside |
693 | 1123 | the code we are generating */ |
1124 | +#ifdef CONFIG_FORMAT_COFF | |
1125 | + if (sym->st_shndx == text_shndx) { | |
1126 | + ptr = sdata[coff_text_shndx]; | |
1127 | + } else if (sym->st_shndx == data_shndx) { | |
1128 | + ptr = sdata[coff_data_shndx]; | |
1129 | + } else { | |
1130 | + ptr = NULL; | |
1131 | + } | |
1132 | +#else | |
694 | 1133 | ptr = sdata[sym->st_shndx]; |
1134 | +#endif | |
695 | 1135 | if (!ptr) |
696 | 1136 | error("__op_labelN in invalid section"); |
697 | 1137 | offset = sym->st_value; |
... | ... | @@ -739,7 +1179,7 @@ void gen_code(const char *name, host_ulong offset, host_ulong size, |
739 | 1179 | for(i = 0, rel = relocs;i < nb_relocs; i++, rel++) { |
740 | 1180 | if (rel->r_offset >= start_offset && |
741 | 1181 | rel->r_offset < start_offset + copy_size) { |
742 | - sym_name = strtab + symtab[ELFW(R_SYM)(rel->r_info)].st_name; | |
1182 | + sym_name = get_rel_sym_name(rel); | |
743 | 1183 | if (strstart(sym_name, "__op_jmp", &p)) { |
744 | 1184 | int n; |
745 | 1185 | n = strtol(p, NULL, 10); |
... | ... | @@ -757,8 +1197,9 @@ void gen_code(const char *name, host_ulong offset, host_ulong size, |
757 | 1197 | } else { |
758 | 1198 | snprintf(name, sizeof(name), "(long)(&%s)", sym_name); |
759 | 1199 | } |
760 | - type = ELF32_R_TYPE(rel->r_info); | |
761 | 1200 | addend = get32((uint32_t *)(text + rel->r_offset)); |
1201 | +#ifdef CONFIG_FORMAT_ELF | |
1202 | + type = ELF32_R_TYPE(rel->r_info); | |
762 | 1203 | switch(type) { |
763 | 1204 | case R_386_32: |
764 | 1205 | fprintf(outfile, " *(uint32_t *)(gen_code_ptr + %d) = %s + %d;\n", |
... | ... | @@ -771,6 +1212,23 @@ void gen_code(const char *name, host_ulong offset, host_ulong size, |
771 | 1212 | default: |
772 | 1213 | error("unsupported i386 relocation (%d)", type); |
773 | 1214 | } |
1215 | +#elif defined(CONFIG_FORMAT_COFF) | |
1216 | + type = rel->r_type; | |
1217 | + switch(type) { | |
1218 | + case DIR32: | |
1219 | + fprintf(outfile, " *(uint32_t *)(gen_code_ptr + %d) = %s + %d;\n", | |
1220 | + rel->r_offset - start_offset, name, addend); | |
1221 | + break; | |
1222 | + case DISP32: | |
1223 | + fprintf(outfile, " *(uint32_t *)(gen_code_ptr + %d) = %s - (long)(gen_code_ptr + %d) + %d -4;\n", | |
1224 | + rel->r_offset - start_offset, name, rel->r_offset - start_offset, addend); | |
1225 | + break; | |
1226 | + default: | |
1227 | + error("unsupported i386 relocation (%d)", type); | |
1228 | + } | |
1229 | +#else | |
1230 | +#error unsupport object format | |
1231 | +#endif | |
774 | 1232 | } |
775 | 1233 | } |
776 | 1234 | } |
... | ... | @@ -1204,114 +1662,10 @@ void gen_code(const char *name, host_ulong offset, host_ulong size, |
1204 | 1662 | } |
1205 | 1663 | } |
1206 | 1664 | |
1207 | -/* load an elf object file */ | |
1208 | -int load_elf(const char *filename, FILE *outfile, int out_type) | |
1665 | +int gen_file(FILE *outfile, int out_type) | |
1209 | 1666 | { |
1210 | - int fd; | |
1211 | - struct elf_shdr *sec, *symtab_sec, *strtab_sec, *text_sec; | |
1212 | - int i, j; | |
1213 | - ElfW(Sym) *sym; | |
1214 | - char *shstr; | |
1215 | - uint8_t *text; | |
1216 | - ELF_RELOC *relocs; | |
1217 | - int nb_relocs; | |
1218 | - ELF_RELOC *rel; | |
1219 | - | |
1220 | - fd = open(filename, O_RDONLY); | |
1221 | - if (fd < 0) | |
1222 | - error("can't open file '%s'", filename); | |
1223 | - | |
1224 | - /* Read ELF header. */ | |
1225 | - if (read(fd, &ehdr, sizeof (ehdr)) != sizeof (ehdr)) | |
1226 | - error("unable to read file header"); | |
1227 | - | |
1228 | - /* Check ELF identification. */ | |
1229 | - if (ehdr.e_ident[EI_MAG0] != ELFMAG0 | |
1230 | - || ehdr.e_ident[EI_MAG1] != ELFMAG1 | |
1231 | - || ehdr.e_ident[EI_MAG2] != ELFMAG2 | |
1232 | - || ehdr.e_ident[EI_MAG3] != ELFMAG3 | |
1233 | - || ehdr.e_ident[EI_VERSION] != EV_CURRENT) { | |
1234 | - error("bad ELF header"); | |
1235 | - } | |
1236 | - | |
1237 | - do_swap = elf_must_swap(&ehdr); | |
1238 | - if (do_swap) | |
1239 | - elf_swap_ehdr(&ehdr); | |
1240 | - if (ehdr.e_ident[EI_CLASS] != ELF_CLASS) | |
1241 | - error("Unsupported ELF class"); | |
1242 | - if (ehdr.e_type != ET_REL) | |
1243 | - error("ELF object file expected"); | |
1244 | - if (ehdr.e_version != EV_CURRENT) | |
1245 | - error("Invalid ELF version"); | |
1246 | - if (!elf_check_arch(ehdr.e_machine)) | |
1247 | - error("Unsupported CPU (e_machine=%d)", ehdr.e_machine); | |
1248 | - | |
1249 | - /* read section headers */ | |
1250 | - shdr = load_data(fd, ehdr.e_shoff, ehdr.e_shnum * sizeof(struct elf_shdr)); | |
1251 | - if (do_swap) { | |
1252 | - for(i = 0; i < ehdr.e_shnum; i++) { | |
1253 | - elf_swap_shdr(&shdr[i]); | |
1254 | - } | |
1255 | - } | |
1256 | - | |
1257 | - /* read all section data */ | |
1258 | - sdata = malloc(sizeof(void *) * ehdr.e_shnum); | |
1259 | - memset(sdata, 0, sizeof(void *) * ehdr.e_shnum); | |
1260 | - | |
1261 | - for(i = 0;i < ehdr.e_shnum; i++) { | |
1262 | - sec = &shdr[i]; | |
1263 | - if (sec->sh_type != SHT_NOBITS) | |
1264 | - sdata[i] = load_data(fd, sec->sh_offset, sec->sh_size); | |
1265 | - } | |
1266 | - | |
1267 | - sec = &shdr[ehdr.e_shstrndx]; | |
1268 | - shstr = sdata[ehdr.e_shstrndx]; | |
1269 | - | |
1270 | - /* swap relocations */ | |
1271 | - for(i = 0; i < ehdr.e_shnum; i++) { | |
1272 | - sec = &shdr[i]; | |
1273 | - if (sec->sh_type == SHT_RELOC) { | |
1274 | - nb_relocs = sec->sh_size / sec->sh_entsize; | |
1275 | - if (do_swap) { | |
1276 | - for(j = 0, rel = (ELF_RELOC *)sdata[i]; j < nb_relocs; j++, rel++) | |
1277 | - elf_swap_rel(rel); | |
1278 | - } | |
1279 | - } | |
1280 | - } | |
1281 | - /* text section */ | |
1282 | - | |
1283 | - text_sec = find_elf_section(shdr, ehdr.e_shnum, shstr, ".text"); | |
1284 | - if (!text_sec) | |
1285 | - error("could not find .text section"); | |
1286 | - text_shndx = text_sec - shdr; | |
1287 | - text = sdata[text_shndx]; | |
1288 | - | |
1289 | - /* find text relocations, if any */ | |
1290 | - relocs = NULL; | |
1291 | - nb_relocs = 0; | |
1292 | - i = find_reloc(text_shndx); | |
1293 | - if (i != 0) { | |
1294 | - relocs = (ELF_RELOC *)sdata[i]; | |
1295 | - nb_relocs = shdr[i].sh_size / shdr[i].sh_entsize; | |
1296 | - } | |
1297 | - | |
1298 | - symtab_sec = find_elf_section(shdr, ehdr.e_shnum, shstr, ".symtab"); | |
1299 | - if (!symtab_sec) | |
1300 | - error("could not find .symtab section"); | |
1301 | - strtab_sec = &shdr[symtab_sec->sh_link]; | |
1302 | - | |
1303 | - symtab = (ElfW(Sym) *)sdata[symtab_sec - shdr]; | |
1304 | - strtab = sdata[symtab_sec->sh_link]; | |
1305 | - | |
1306 | - nb_syms = symtab_sec->sh_size / sizeof(ElfW(Sym)); | |
1307 | - if (do_swap) { | |
1308 | - for(i = 0, sym = symtab; i < nb_syms; i++, sym++) { | |
1309 | - swab32s(&sym->st_name); | |
1310 | - swabls(&sym->st_value); | |
1311 | - swabls(&sym->st_size); | |
1312 | - swab16s(&sym->st_shndx); | |
1313 | - } | |
1314 | - } | |
1667 | + int i; | |
1668 | + EXE_SYM *sym; | |
1315 | 1669 | |
1316 | 1670 | if (out_type == OUT_INDEX_OP) { |
1317 | 1671 | fprintf(outfile, "DEF(end, 0, 0)\n"); |
... | ... | @@ -1321,10 +1675,9 @@ int load_elf(const char *filename, FILE *outfile, int out_type) |
1321 | 1675 | fprintf(outfile, "DEF(nop3, 3, 0)\n"); |
1322 | 1676 | for(i = 0, sym = symtab; i < nb_syms; i++, sym++) { |
1323 | 1677 | const char *name, *p; |
1324 | - name = strtab + sym->st_name; | |
1678 | + name = get_sym_name(sym); | |
1325 | 1679 | if (strstart(name, OP_PREFIX, &p)) { |
1326 | - gen_code(name, sym->st_value, sym->st_size, outfile, | |
1327 | - text, relocs, nb_relocs, 2); | |
1680 | + gen_code(name, sym->st_value, sym->st_size, outfile, 2); | |
1328 | 1681 | } |
1329 | 1682 | } |
1330 | 1683 | } else if (out_type == OUT_GEN_OP) { |
... | ... | @@ -1332,12 +1685,11 @@ int load_elf(const char *filename, FILE *outfile, int out_type) |
1332 | 1685 | |
1333 | 1686 | for(i = 0, sym = symtab; i < nb_syms; i++, sym++) { |
1334 | 1687 | const char *name; |
1335 | - name = strtab + sym->st_name; | |
1688 | + name = get_sym_name(sym); | |
1336 | 1689 | if (strstart(name, OP_PREFIX, NULL)) { |
1337 | - if (sym->st_shndx != (text_sec - shdr)) | |
1690 | + if (sym->st_shndx != text_shndx) | |
1338 | 1691 | error("invalid section for opcode (0x%x)", sym->st_shndx); |
1339 | - gen_code(name, sym->st_value, sym->st_size, outfile, | |
1340 | - text, relocs, nb_relocs, 0); | |
1692 | + gen_code(name, sym->st_value, sym->st_size, outfile, 0); | |
1341 | 1693 | } |
1342 | 1694 | } |
1343 | 1695 | |
... | ... | @@ -1374,16 +1726,15 @@ fprintf(outfile, |
1374 | 1726 | |
1375 | 1727 | for(i = 0, sym = symtab; i < nb_syms; i++, sym++) { |
1376 | 1728 | const char *name; |
1377 | - name = strtab + sym->st_name; | |
1729 | + name = get_sym_name(sym); | |
1378 | 1730 | if (strstart(name, OP_PREFIX, NULL)) { |
1379 | 1731 | #if 0 |
1380 | 1732 | printf("%4d: %s pos=0x%08x len=%d\n", |
1381 | 1733 | i, name, sym->st_value, sym->st_size); |
1382 | 1734 | #endif |
1383 | - if (sym->st_shndx != (text_sec - shdr)) | |
1735 | + if (sym->st_shndx != text_shndx) | |
1384 | 1736 | error("invalid section for opcode (0x%x)", sym->st_shndx); |
1385 | - gen_code(name, sym->st_value, sym->st_size, outfile, | |
1386 | - text, relocs, nb_relocs, 1); | |
1737 | + gen_code(name, sym->st_value, sym->st_size, outfile, 1); | |
1387 | 1738 | } |
1388 | 1739 | } |
1389 | 1740 | |
... | ... | @@ -1432,7 +1783,6 @@ fprintf(outfile, "gen_code_ptr = arm_flush_ldr(gen_code_ptr, arm_ldr_table, arm_ |
1432 | 1783 | |
1433 | 1784 | } |
1434 | 1785 | |
1435 | - close(fd); | |
1436 | 1786 | return 0; |
1437 | 1787 | } |
1438 | 1788 | |
... | ... | @@ -1480,7 +1830,9 @@ int main(int argc, char **argv) |
1480 | 1830 | outfile = fopen(outfilename, "w"); |
1481 | 1831 | if (!outfile) |
1482 | 1832 | error("could not open '%s'", outfilename); |
1483 | - load_elf(filename, outfile, out_type); | |
1833 | + | |
1834 | + load_object(filename); | |
1835 | + gen_file(outfile, out_type); | |
1484 | 1836 | fclose(outfile); |
1485 | 1837 | return 0; |
1486 | 1838 | } | ... | ... |
exec-all.h
... | ... | @@ -141,7 +141,7 @@ int tlb_set_page(CPUState *env, uint32_t vaddr, uint32_t paddr, int prot, |
141 | 141 | #if defined(__powerpc__) |
142 | 142 | #define USE_DIRECT_JUMP |
143 | 143 | #endif |
144 | -#if defined(__i386__) | |
144 | +#if defined(__i386__) && !defined(_WIN32) | |
145 | 145 | #define USE_DIRECT_JUMP |
146 | 146 | #endif |
147 | 147 | |
... | ... | @@ -322,13 +322,19 @@ do {\ |
322 | 322 | |
323 | 323 | #elif defined(__i386__) && defined(USE_DIRECT_JUMP) |
324 | 324 | |
325 | +#ifdef _WIN32 | |
326 | +#define ASM_PREVIOUS_SECTION ".section .text\n" | |
327 | +#else | |
328 | +#define ASM_PREVIOUS_SECTION ".previous\n" | |
329 | +#endif | |
330 | + | |
325 | 331 | /* we patch the jump instruction directly */ |
326 | 332 | #define JUMP_TB(opname, tbparam, n, eip)\ |
327 | 333 | do {\ |
328 | - asm volatile (".section \".data\"\n"\ | |
334 | + asm volatile (".section .data\n"\ | |
329 | 335 | "__op_label" #n "." stringify(opname) ":\n"\ |
330 | 336 | ".long 1f\n"\ |
331 | - ".previous\n"\ | |
337 | + ASM_PREVIOUS_SECTION \ | |
332 | 338 | "jmp __op_jmp" #n "\n"\ |
333 | 339 | "1:\n");\ |
334 | 340 | T0 = (long)(tbparam) + (n);\ | ... | ... |
exec.c
... | ... | @@ -17,6 +17,7 @@ |
17 | 17 | * License along with this library; if not, write to the Free Software |
18 | 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
19 | 19 | */ |
20 | +#include "config.h" | |
20 | 21 | #include <stdlib.h> |
21 | 22 | #include <stdio.h> |
22 | 23 | #include <stdarg.h> |
... | ... | @@ -24,9 +25,10 @@ |
24 | 25 | #include <errno.h> |
25 | 26 | #include <unistd.h> |
26 | 27 | #include <inttypes.h> |
28 | +#if !defined(CONFIG_SOFTMMU) | |
27 | 29 | #include <sys/mman.h> |
30 | +#endif | |
28 | 31 | |
29 | -#include "config.h" | |
30 | 32 | #include "cpu.h" |
31 | 33 | #include "exec-all.h" |
32 | 34 | |
... | ... | @@ -121,7 +123,11 @@ static void page_init(void) |
121 | 123 | { |
122 | 124 | /* NOTE: we can always suppose that host_page_size >= |
123 | 125 | TARGET_PAGE_SIZE */ |
126 | +#ifdef _WIN32 | |
127 | + real_host_page_size = 4096; | |
128 | +#else | |
124 | 129 | real_host_page_size = getpagesize(); |
130 | +#endif | |
125 | 131 | if (host_page_size == 0) |
126 | 132 | host_page_size = real_host_page_size; |
127 | 133 | if (host_page_size < TARGET_PAGE_SIZE) |
... | ... | @@ -1369,14 +1375,14 @@ int tlb_set_page(CPUState *env, uint32_t vaddr, uint32_t paddr, int prot, |
1369 | 1375 | |
1370 | 1376 | index = (vaddr >> 12) & (CPU_TLB_SIZE - 1); |
1371 | 1377 | addend -= vaddr; |
1372 | - if (prot & PROT_READ) { | |
1378 | + if (prot & PAGE_READ) { | |
1373 | 1379 | env->tlb_read[is_user][index].address = address; |
1374 | 1380 | env->tlb_read[is_user][index].addend = addend; |
1375 | 1381 | } else { |
1376 | 1382 | env->tlb_read[is_user][index].address = -1; |
1377 | 1383 | env->tlb_read[is_user][index].addend = -1; |
1378 | 1384 | } |
1379 | - if (prot & PROT_WRITE) { | |
1385 | + if (prot & PAGE_WRITE) { | |
1380 | 1386 | if ((pd & ~TARGET_PAGE_MASK) == IO_MEM_ROM) { |
1381 | 1387 | /* ROM: access is ignored (same as unassigned) */ |
1382 | 1388 | env->tlb_write[is_user][index].address = vaddr | IO_MEM_ROM; | ... | ... |
gdbstub.c
... | ... | @@ -17,18 +17,12 @@ |
17 | 17 | * License along with this library; if not, write to the Free Software |
18 | 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
19 | 19 | */ |
20 | -#include <stdlib.h> | |
21 | -#include <stdio.h> | |
22 | -#include <string.h> | |
23 | -#include <unistd.h> | |
24 | -#include <errno.h> | |
20 | +#include "vl.h" | |
21 | + | |
25 | 22 | #include <sys/socket.h> |
26 | 23 | #include <netinet/in.h> |
27 | 24 | #include <netinet/tcp.h> |
28 | 25 | #include <signal.h> |
29 | -#include <fcntl.h> | |
30 | - | |
31 | -#include "vl.h" | |
32 | 26 | |
33 | 27 | //#define DEBUG_GDB |
34 | 28 | ... | ... |
hw/dma.c
... | ... | @@ -21,11 +21,6 @@ |
21 | 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
22 | 22 | * THE SOFTWARE. |
23 | 23 | */ |
24 | -#include <stdio.h> | |
25 | -#include <stdlib.h> | |
26 | -#include <inttypes.h> | |
27 | - | |
28 | -#include "cpu.h" | |
29 | 24 | #include "vl.h" |
30 | 25 | |
31 | 26 | #define log(...) fprintf (stderr, "dma: " __VA_ARGS__) | ... | ... |
hw/fdc.c
... | ... | @@ -21,11 +21,6 @@ |
21 | 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
22 | 22 | * THE SOFTWARE. |
23 | 23 | */ |
24 | -#include <stdio.h> | |
25 | -#include <stdlib.h> | |
26 | -#include <string.h> | |
27 | -#include <inttypes.h> | |
28 | - | |
29 | 24 | #include "vl.h" |
30 | 25 | |
31 | 26 | /********************************************************/ | ... | ... |
hw/i8254.c
... | ... | @@ -21,26 +21,6 @@ |
21 | 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
22 | 22 | * THE SOFTWARE. |
23 | 23 | */ |
24 | -#include <stdlib.h> | |
25 | -#include <stdio.h> | |
26 | -#include <stdarg.h> | |
27 | -#include <string.h> | |
28 | -#include <getopt.h> | |
29 | -#include <inttypes.h> | |
30 | -#include <unistd.h> | |
31 | -#include <sys/mman.h> | |
32 | -#include <fcntl.h> | |
33 | -#include <signal.h> | |
34 | -#include <time.h> | |
35 | -#include <sys/time.h> | |
36 | -#include <malloc.h> | |
37 | -#include <termios.h> | |
38 | -#include <sys/poll.h> | |
39 | -#include <errno.h> | |
40 | -#include <sys/wait.h> | |
41 | -#include <netinet/in.h> | |
42 | - | |
43 | -#include "cpu.h" | |
44 | 24 | #include "vl.h" |
45 | 25 | |
46 | 26 | //#define DEBUG_PIT | ... | ... |
hw/i8259.c
... | ... | @@ -21,26 +21,6 @@ |
21 | 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
22 | 22 | * THE SOFTWARE. |
23 | 23 | */ |
24 | -#include <stdlib.h> | |
25 | -#include <stdio.h> | |
26 | -#include <stdarg.h> | |
27 | -#include <string.h> | |
28 | -#include <getopt.h> | |
29 | -#include <inttypes.h> | |
30 | -#include <unistd.h> | |
31 | -#include <sys/mman.h> | |
32 | -#include <fcntl.h> | |
33 | -#include <signal.h> | |
34 | -#include <time.h> | |
35 | -#include <sys/time.h> | |
36 | -#include <malloc.h> | |
37 | -#include <termios.h> | |
38 | -#include <sys/poll.h> | |
39 | -#include <errno.h> | |
40 | -#include <sys/wait.h> | |
41 | -#include <netinet/in.h> | |
42 | - | |
43 | -#include "cpu.h" | |
44 | 24 | #include "vl.h" |
45 | 25 | |
46 | 26 | /* debug PIC */ | ... | ... |
hw/ide.c
... | ... | @@ -21,31 +21,6 @@ |
21 | 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
22 | 22 | * THE SOFTWARE. |
23 | 23 | */ |
24 | -#include <stdlib.h> | |
25 | -#include <stdio.h> | |
26 | -#include <stdarg.h> | |
27 | -#include <string.h> | |
28 | -#include <getopt.h> | |
29 | -#include <inttypes.h> | |
30 | -#include <unistd.h> | |
31 | -#include <sys/mman.h> | |
32 | -#include <fcntl.h> | |
33 | -#include <signal.h> | |
34 | -#include <time.h> | |
35 | -#include <sys/time.h> | |
36 | -#include <malloc.h> | |
37 | -#include <termios.h> | |
38 | -#include <sys/poll.h> | |
39 | -#include <errno.h> | |
40 | -#include <sys/wait.h> | |
41 | -#include <netinet/in.h> | |
42 | - | |
43 | -#define NO_THUNK_TYPE_SIZE | |
44 | -#include "thunk.h" | |
45 | - | |
46 | -#include "cpu.h" | |
47 | -#include "exec-all.h" | |
48 | - | |
49 | 24 | #include "vl.h" |
50 | 25 | |
51 | 26 | /* debug IDE devices */ |
... | ... | @@ -375,6 +350,15 @@ static void padstr8(uint8_t *buf, int buf_size, const char *src) |
375 | 350 | } |
376 | 351 | } |
377 | 352 | |
353 | +static void put_le16(uint16_t *p, unsigned int v) | |
354 | +{ | |
355 | +#ifdef WORDS_BIGENDIAN | |
356 | + *p = bswap16(v); | |
357 | +#else | |
358 | + *p = v; | |
359 | +#endif | |
360 | +} | |
361 | + | |
378 | 362 | static void ide_identify(IDEState *s) |
379 | 363 | { |
380 | 364 | uint16_t *p; |
... | ... | @@ -382,43 +366,43 @@ static void ide_identify(IDEState *s) |
382 | 366 | |
383 | 367 | memset(s->io_buffer, 0, 512); |
384 | 368 | p = (uint16_t *)s->io_buffer; |
385 | - stw_raw(p + 0, 0x0040); | |
386 | - stw_raw(p + 1, s->cylinders); | |
387 | - stw_raw(p + 3, s->heads); | |
388 | - stw_raw(p + 4, 512 * s->sectors); /* XXX: retired, remove ? */ | |
389 | - stw_raw(p + 5, 512); /* XXX: retired, remove ? */ | |
390 | - stw_raw(p + 6, s->sectors); | |
369 | + put_le16(p + 0, 0x0040); | |
370 | + put_le16(p + 1, s->cylinders); | |
371 | + put_le16(p + 3, s->heads); | |
372 | + put_le16(p + 4, 512 * s->sectors); /* XXX: retired, remove ? */ | |
373 | + put_le16(p + 5, 512); /* XXX: retired, remove ? */ | |
374 | + put_le16(p + 6, s->sectors); | |
391 | 375 | padstr((uint8_t *)(p + 10), "QM00001", 20); /* serial number */ |
392 | - stw_raw(p + 20, 3); /* XXX: retired, remove ? */ | |
393 | - stw_raw(p + 21, 512); /* cache size in sectors */ | |
394 | - stw_raw(p + 22, 4); /* ecc bytes */ | |
376 | + put_le16(p + 20, 3); /* XXX: retired, remove ? */ | |
377 | + put_le16(p + 21, 512); /* cache size in sectors */ | |
378 | + put_le16(p + 22, 4); /* ecc bytes */ | |
395 | 379 | padstr((uint8_t *)(p + 23), QEMU_VERSION, 8); /* firmware version */ |
396 | 380 | padstr((uint8_t *)(p + 27), "QEMU HARDDISK", 40); /* model */ |
397 | 381 | #if MAX_MULT_SECTORS > 1 |
398 | - stw_raw(p + 47, 0x8000 | MAX_MULT_SECTORS); | |
382 | + put_le16(p + 47, 0x8000 | MAX_MULT_SECTORS); | |
399 | 383 | #endif |
400 | - stw_raw(p + 48, 1); /* dword I/O */ | |
401 | - stw_raw(p + 49, 1 << 9); /* LBA supported, no DMA */ | |
402 | - stw_raw(p + 51, 0x200); /* PIO transfer cycle */ | |
403 | - stw_raw(p + 52, 0x200); /* DMA transfer cycle */ | |
404 | - stw_raw(p + 53, 1); /* words 54-58 are valid */ | |
405 | - stw_raw(p + 54, s->cylinders); | |
406 | - stw_raw(p + 55, s->heads); | |
407 | - stw_raw(p + 56, s->sectors); | |
384 | + put_le16(p + 48, 1); /* dword I/O */ | |
385 | + put_le16(p + 49, 1 << 9); /* LBA supported, no DMA */ | |
386 | + put_le16(p + 51, 0x200); /* PIO transfer cycle */ | |
387 | + put_le16(p + 52, 0x200); /* DMA transfer cycle */ | |
388 | + put_le16(p + 53, 1); /* words 54-58 are valid */ | |
389 | + put_le16(p + 54, s->cylinders); | |
390 | + put_le16(p + 55, s->heads); | |
391 | + put_le16(p + 56, s->sectors); | |
408 | 392 | oldsize = s->cylinders * s->heads * s->sectors; |
409 | - stw_raw(p + 57, oldsize); | |
410 | - stw_raw(p + 58, oldsize >> 16); | |
393 | + put_le16(p + 57, oldsize); | |
394 | + put_le16(p + 58, oldsize >> 16); | |
411 | 395 | if (s->mult_sectors) |
412 | - stw_raw(p + 59, 0x100 | s->mult_sectors); | |
413 | - stw_raw(p + 60, s->nb_sectors); | |
414 | - stw_raw(p + 61, s->nb_sectors >> 16); | |
415 | - stw_raw(p + 80, (1 << 1) | (1 << 2)); | |
416 | - stw_raw(p + 82, (1 << 14)); | |
417 | - stw_raw(p + 83, (1 << 14)); | |
418 | - stw_raw(p + 84, (1 << 14)); | |
419 | - stw_raw(p + 85, (1 << 14)); | |
420 | - stw_raw(p + 86, 0); | |
421 | - stw_raw(p + 87, (1 << 14)); | |
396 | + put_le16(p + 59, 0x100 | s->mult_sectors); | |
397 | + put_le16(p + 60, s->nb_sectors); | |
398 | + put_le16(p + 61, s->nb_sectors >> 16); | |
399 | + put_le16(p + 80, (1 << 1) | (1 << 2)); | |
400 | + put_le16(p + 82, (1 << 14)); | |
401 | + put_le16(p + 83, (1 << 14)); | |
402 | + put_le16(p + 84, (1 << 14)); | |
403 | + put_le16(p + 85, (1 << 14)); | |
404 | + put_le16(p + 86, 0); | |
405 | + put_le16(p + 87, (1 << 14)); | |
422 | 406 | } |
423 | 407 | |
424 | 408 | static void ide_atapi_identify(IDEState *s) |
... | ... | @@ -428,32 +412,32 @@ static void ide_atapi_identify(IDEState *s) |
428 | 412 | memset(s->io_buffer, 0, 512); |
429 | 413 | p = (uint16_t *)s->io_buffer; |
430 | 414 | /* Removable CDROM, 50us response, 12 byte packets */ |
431 | - stw_raw(p + 0, (2 << 14) | (5 << 8) | (1 << 7) | (2 << 5) | (0 << 0)); | |
432 | - stw_raw(p + 1, s->cylinders); | |
433 | - stw_raw(p + 3, s->heads); | |
434 | - stw_raw(p + 4, 512 * s->sectors); /* sectors */ | |
435 | - stw_raw(p + 5, 512); /* sector size */ | |
436 | - stw_raw(p + 6, s->sectors); | |
415 | + put_le16(p + 0, (2 << 14) | (5 << 8) | (1 << 7) | (2 << 5) | (0 << 0)); | |
416 | + put_le16(p + 1, s->cylinders); | |
417 | + put_le16(p + 3, s->heads); | |
418 | + put_le16(p + 4, 512 * s->sectors); /* sectors */ | |
419 | + put_le16(p + 5, 512); /* sector size */ | |
420 | + put_le16(p + 6, s->sectors); | |
437 | 421 | padstr((uint8_t *)(p + 10), "QM00001", 20); /* serial number */ |
438 | - stw_raw(p + 20, 3); /* buffer type */ | |
439 | - stw_raw(p + 21, 512); /* cache size in sectors */ | |
440 | - stw_raw(p + 22, 4); /* ecc bytes */ | |
422 | + put_le16(p + 20, 3); /* buffer type */ | |
423 | + put_le16(p + 21, 512); /* cache size in sectors */ | |
424 | + put_le16(p + 22, 4); /* ecc bytes */ | |
441 | 425 | padstr((uint8_t *)(p + 23), QEMU_VERSION, 8); /* firmware version */ |
442 | 426 | padstr((uint8_t *)(p + 27), "QEMU CD-ROM", 40); /* model */ |
443 | - stw_raw(p + 48, 1); /* dword I/O (XXX: should not be set on CDROM) */ | |
444 | - stw_raw(p + 49, 1 << 9); /* LBA supported, no DMA */ | |
445 | - stw_raw(p + 53, 3); /* words 64-70, 54-58 valid */ | |
446 | - stw_raw(p + 63, 0x103); /* DMA modes XXX: may be incorrect */ | |
447 | - stw_raw(p + 64, 1); /* PIO modes */ | |
448 | - stw_raw(p + 65, 0xb4); /* minimum DMA multiword tx cycle time */ | |
449 | - stw_raw(p + 66, 0xb4); /* recommended DMA multiword tx cycle time */ | |
450 | - stw_raw(p + 67, 0x12c); /* minimum PIO cycle time without flow control */ | |
451 | - stw_raw(p + 68, 0xb4); /* minimum PIO cycle time with IORDY flow control */ | |
427 | + put_le16(p + 48, 1); /* dword I/O (XXX: should not be set on CDROM) */ | |
428 | + put_le16(p + 49, 1 << 9); /* LBA supported, no DMA */ | |
429 | + put_le16(p + 53, 3); /* words 64-70, 54-58 valid */ | |
430 | + put_le16(p + 63, 0x103); /* DMA modes XXX: may be incorrect */ | |
431 | + put_le16(p + 64, 1); /* PIO modes */ | |
432 | + put_le16(p + 65, 0xb4); /* minimum DMA multiword tx cycle time */ | |
433 | + put_le16(p + 66, 0xb4); /* recommended DMA multiword tx cycle time */ | |
434 | + put_le16(p + 67, 0x12c); /* minimum PIO cycle time without flow control */ | |
435 | + put_le16(p + 68, 0xb4); /* minimum PIO cycle time with IORDY flow control */ | |
452 | 436 | |
453 | - stw_raw(p + 71, 30); /* in ns */ | |
454 | - stw_raw(p + 72, 30); /* in ns */ | |
437 | + put_le16(p + 71, 30); /* in ns */ | |
438 | + put_le16(p + 72, 30); /* in ns */ | |
455 | 439 | |
456 | - stw_raw(p + 80, 0x1e); /* support up to ATA/ATAPI-4 */ | |
440 | + put_le16(p + 80, 0x1e); /* support up to ATA/ATAPI-4 */ | |
457 | 441 | } |
458 | 442 | |
459 | 443 | static void ide_set_signature(IDEState *s) | ... | ... |
hw/mc146818rtc.c
... | ... | @@ -21,26 +21,6 @@ |
21 | 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
22 | 22 | * THE SOFTWARE. |
23 | 23 | */ |
24 | -#include <stdlib.h> | |
25 | -#include <stdio.h> | |
26 | -#include <stdarg.h> | |
27 | -#include <string.h> | |
28 | -#include <getopt.h> | |
29 | -#include <inttypes.h> | |
30 | -#include <unistd.h> | |
31 | -#include <sys/mman.h> | |
32 | -#include <fcntl.h> | |
33 | -#include <signal.h> | |
34 | -#include <time.h> | |
35 | -#include <sys/time.h> | |
36 | -#include <malloc.h> | |
37 | -#include <termios.h> | |
38 | -#include <sys/poll.h> | |
39 | -#include <errno.h> | |
40 | -#include <sys/wait.h> | |
41 | -#include <netinet/in.h> | |
42 | - | |
43 | -#include "cpu.h" | |
44 | 24 | #include "vl.h" |
45 | 25 | |
46 | 26 | //#define DEBUG_CMOS | ... | ... |
hw/ne2000.c
... | ... | @@ -21,26 +21,6 @@ |
21 | 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
22 | 22 | * THE SOFTWARE. |
23 | 23 | */ |
24 | -#include <stdlib.h> | |
25 | -#include <stdio.h> | |
26 | -#include <stdarg.h> | |
27 | -#include <string.h> | |
28 | -#include <getopt.h> | |
29 | -#include <inttypes.h> | |
30 | -#include <unistd.h> | |
31 | -#include <sys/mman.h> | |
32 | -#include <fcntl.h> | |
33 | -#include <signal.h> | |
34 | -#include <time.h> | |
35 | -#include <sys/time.h> | |
36 | -#include <malloc.h> | |
37 | -#include <termios.h> | |
38 | -#include <sys/poll.h> | |
39 | -#include <errno.h> | |
40 | -#include <sys/wait.h> | |
41 | -#include <netinet/in.h> | |
42 | - | |
43 | -#include "cpu.h" | |
44 | 24 | #include "vl.h" |
45 | 25 | |
46 | 26 | /* debug NE2000 card */ | ... | ... |
hw/pc.c
... | ... | @@ -21,26 +21,6 @@ |
21 | 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
22 | 22 | * THE SOFTWARE. |
23 | 23 | */ |
24 | -#include <stdlib.h> | |
25 | -#include <stdio.h> | |
26 | -#include <stdarg.h> | |
27 | -#include <string.h> | |
28 | -#include <getopt.h> | |
29 | -#include <inttypes.h> | |
30 | -#include <unistd.h> | |
31 | -#include <sys/mman.h> | |
32 | -#include <fcntl.h> | |
33 | -#include <signal.h> | |
34 | -#include <time.h> | |
35 | -#include <sys/time.h> | |
36 | -#include <malloc.h> | |
37 | -#include <termios.h> | |
38 | -#include <sys/poll.h> | |
39 | -#include <errno.h> | |
40 | -#include <sys/wait.h> | |
41 | -#include <netinet/in.h> | |
42 | - | |
43 | -#include "cpu.h" | |
44 | 24 | #include "vl.h" |
45 | 25 | |
46 | 26 | /* output Bochs bios info messages */ |
... | ... | @@ -393,9 +373,13 @@ void pc_init(int ram_size, int vga_ram_size, int boot_device, |
393 | 373 | bs_table[2 * i], bs_table[2 * i + 1]); |
394 | 374 | } |
395 | 375 | kbd_init(); |
396 | - AUD_init(); | |
397 | 376 | DMA_init(); |
377 | + | |
378 | +#ifndef _WIN32 | |
379 | + /* no audio supported yet for win32 */ | |
380 | + AUD_init(); | |
398 | 381 | SB16_init(); |
382 | +#endif | |
399 | 383 | |
400 | 384 | floppy_controller = fdctrl_init(6, 2, 0, 0x3f0, fd_table); |
401 | 385 | ... | ... |
hw/pckbd.c
... | ... | @@ -21,26 +21,6 @@ |
21 | 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
22 | 22 | * THE SOFTWARE. |
23 | 23 | */ |
24 | -#include <stdlib.h> | |
25 | -#include <stdio.h> | |
26 | -#include <stdarg.h> | |
27 | -#include <string.h> | |
28 | -#include <getopt.h> | |
29 | -#include <inttypes.h> | |
30 | -#include <unistd.h> | |
31 | -#include <sys/mman.h> | |
32 | -#include <fcntl.h> | |
33 | -#include <signal.h> | |
34 | -#include <time.h> | |
35 | -#include <sys/time.h> | |
36 | -#include <malloc.h> | |
37 | -#include <termios.h> | |
38 | -#include <sys/poll.h> | |
39 | -#include <errno.h> | |
40 | -#include <sys/wait.h> | |
41 | -#include <netinet/in.h> | |
42 | - | |
43 | -#include "cpu.h" | |
44 | 24 | #include "vl.h" |
45 | 25 | |
46 | 26 | /* debug PC keyboard */ | ... | ... |
hw/sb16.c
... | ... | @@ -21,11 +21,6 @@ |
21 | 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
22 | 22 | * THE SOFTWARE. |
23 | 23 | */ |
24 | -#include <stdio.h> | |
25 | -#include <stdlib.h> | |
26 | -#include <inttypes.h> | |
27 | - | |
28 | -#include "cpu.h" | |
29 | 24 | #include "vl.h" |
30 | 25 | |
31 | 26 | #define MIN(a, b) ((a)>(b)?(b):(a)) | ... | ... |
hw/serial.c
... | ... | @@ -21,26 +21,6 @@ |
21 | 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
22 | 22 | * THE SOFTWARE. |
23 | 23 | */ |
24 | -#include <stdlib.h> | |
25 | -#include <stdio.h> | |
26 | -#include <stdarg.h> | |
27 | -#include <string.h> | |
28 | -#include <getopt.h> | |
29 | -#include <inttypes.h> | |
30 | -#include <unistd.h> | |
31 | -#include <sys/mman.h> | |
32 | -#include <fcntl.h> | |
33 | -#include <signal.h> | |
34 | -#include <time.h> | |
35 | -#include <sys/time.h> | |
36 | -#include <malloc.h> | |
37 | -#include <termios.h> | |
38 | -#include <sys/poll.h> | |
39 | -#include <errno.h> | |
40 | -#include <sys/wait.h> | |
41 | -#include <netinet/in.h> | |
42 | - | |
43 | -#include "cpu.h" | |
44 | 24 | #include "vl.h" |
45 | 25 | |
46 | 26 | //#define DEBUG_SERIAL | ... | ... |
hw/vga.c
... | ... | @@ -21,28 +21,6 @@ |
21 | 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
22 | 22 | * THE SOFTWARE. |
23 | 23 | */ |
24 | -#include <stdlib.h> | |
25 | -#include <stdio.h> | |
26 | -#include <stdarg.h> | |
27 | -#include <string.h> | |
28 | -#include <getopt.h> | |
29 | -#include <inttypes.h> | |
30 | -#include <unistd.h> | |
31 | -#include <sys/mman.h> | |
32 | -#include <fcntl.h> | |
33 | -#include <signal.h> | |
34 | -#include <time.h> | |
35 | -#include <sys/time.h> | |
36 | -#include <malloc.h> | |
37 | -#include <termios.h> | |
38 | -#include <sys/poll.h> | |
39 | -#include <errno.h> | |
40 | -#include <sys/wait.h> | |
41 | -#include <netinet/in.h> | |
42 | - | |
43 | -#include "cpu.h" | |
44 | -#include "exec-all.h" | |
45 | - | |
46 | 24 | #include "vl.h" |
47 | 25 | |
48 | 26 | //#define DEBUG_VGA | ... | ... |
monitor.c
... | ... | @@ -21,25 +21,6 @@ |
21 | 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
22 | 22 | * THE SOFTWARE. |
23 | 23 | */ |
24 | -#include <stdlib.h> | |
25 | -#include <stdio.h> | |
26 | -#include <stdarg.h> | |
27 | -#include <string.h> | |
28 | -#include <getopt.h> | |
29 | -#include <inttypes.h> | |
30 | -#include <unistd.h> | |
31 | -#include <sys/mman.h> | |
32 | -#include <fcntl.h> | |
33 | -#include <signal.h> | |
34 | -#include <time.h> | |
35 | -#include <sys/time.h> | |
36 | -#include <malloc.h> | |
37 | -#include <termios.h> | |
38 | -#include <sys/poll.h> | |
39 | -#include <errno.h> | |
40 | -#include <ctype.h> | |
41 | - | |
42 | -#include "cpu.h" | |
43 | 24 | #include "vl.h" |
44 | 25 | |
45 | 26 | //#define DEBUG |
... | ... | @@ -311,6 +292,7 @@ static void do_cont(int argc, const char **argv) |
311 | 292 | vm_start(); |
312 | 293 | } |
313 | 294 | |
295 | +#ifdef CONFIG_GDBSTUB | |
314 | 296 | static void do_gdbserver(int argc, const char **argv) |
315 | 297 | { |
316 | 298 | int port; |
... | ... | @@ -324,6 +306,7 @@ static void do_gdbserver(int argc, const char **argv) |
324 | 306 | qemu_printf("Waiting gdb connection on port %d\n", port); |
325 | 307 | } |
326 | 308 | } |
309 | +#endif | |
327 | 310 | |
328 | 311 | static term_cmd_t term_cmds[] = { |
329 | 312 | { "help|?", do_help, |
... | ... | @@ -348,7 +331,9 @@ static term_cmd_t term_cmds[] = { |
348 | 331 | "filename", "restore the whole virtual machine state from 'filename'" }, |
349 | 332 | { "stop", do_stop, "", "stop emulation", }, |
350 | 333 | { "c|cont", do_cont, "", "resume emulation", }, |
334 | +#ifdef CONFIG_GDBSTUB | |
351 | 335 | { "gdbserver", do_gdbserver, "[port]", "start gdbserver session (default port=1234)", }, |
336 | +#endif | |
352 | 337 | { NULL, NULL, }, |
353 | 338 | }; |
354 | 339 | ... | ... |
osdep.c
... | ... | @@ -25,8 +25,6 @@ |
25 | 25 | #include <stdio.h> |
26 | 26 | #include <stdarg.h> |
27 | 27 | #include <string.h> |
28 | -#include <sys/mman.h> | |
29 | -#include <sys/ipc.h> | |
30 | 28 | #include <errno.h> |
31 | 29 | #include <unistd.h> |
32 | 30 | |
... | ... | @@ -34,6 +32,9 @@ |
34 | 32 | |
35 | 33 | #if defined(__i386__) && !defined(CONFIG_SOFTMMU) && !defined(CONFIG_USER_ONLY) |
36 | 34 | |
35 | +#include <sys/mman.h> | |
36 | +#include <sys/ipc.h> | |
37 | + | |
37 | 38 | /* When not using soft mmu, libc independant functions are needed for |
38 | 39 | the CPU core because it needs to use alternates stacks and |
39 | 40 | libc/thread incompatibles settings */ | ... | ... |
oss.c
... | ... | @@ -21,6 +21,9 @@ |
21 | 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
22 | 22 | * THE SOFTWARE. |
23 | 23 | */ |
24 | +#include "vl.h" | |
25 | + | |
26 | +#ifndef _WIN32 | |
24 | 27 | #include <fcntl.h> |
25 | 28 | #include <errno.h> |
26 | 29 | #include <stdio.h> |
... | ... | @@ -33,7 +36,6 @@ |
33 | 36 | #include <sys/ioctl.h> |
34 | 37 | #include <sys/soundcard.h> |
35 | 38 | |
36 | -#include "vl.h" | |
37 | 39 | |
38 | 40 | /* http://www.df.lth.se/~john_e/gems/gem002d.html */ |
39 | 41 | /* http://www.multi-platforms.com/Tips/PopCount.htm */ |
... | ... | @@ -510,3 +512,43 @@ void AUD_init (void) |
510 | 512 | |
511 | 513 | conf_fragsize = lsbindex (fsp); |
512 | 514 | } |
515 | + | |
516 | +#else | |
517 | + | |
518 | +void AUD_run (void) | |
519 | +{ | |
520 | +} | |
521 | + | |
522 | +int AUD_write (void *in_buf, int size) | |
523 | +{ | |
524 | + return 0; | |
525 | +} | |
526 | + | |
527 | +void AUD_reset (int rfreq, int rnchannels, audfmt_e rfmt) | |
528 | +{ | |
529 | +} | |
530 | + | |
531 | +void AUD_adjust_estimate (int _leftover) | |
532 | +{ | |
533 | +} | |
534 | + | |
535 | +int AUD_get_free (void) | |
536 | +{ | |
537 | + return 0; | |
538 | +} | |
539 | + | |
540 | +int AUD_get_live (void) | |
541 | +{ | |
542 | + return 0; | |
543 | +} | |
544 | + | |
545 | +int AUD_get_buffer_size (void) | |
546 | +{ | |
547 | + return 0; | |
548 | +} | |
549 | + | |
550 | +void AUD_init (void) | |
551 | +{ | |
552 | +} | |
553 | + | |
554 | +#endif | ... | ... |
qemu-mkcow.c
... | ... | @@ -28,16 +28,11 @@ |
28 | 28 | #include <getopt.h> |
29 | 29 | #include <inttypes.h> |
30 | 30 | #include <unistd.h> |
31 | -#include <sys/mman.h> | |
32 | 31 | #include <fcntl.h> |
33 | 32 | #include <signal.h> |
34 | 33 | #include <time.h> |
35 | 34 | #include <sys/time.h> |
36 | -#include <malloc.h> | |
37 | -#include <termios.h> | |
38 | -#include <sys/poll.h> | |
39 | 35 | #include <errno.h> |
40 | -#include <sys/wait.h> | |
41 | 36 | #include <sys/stat.h> |
42 | 37 | #include <netinet/in.h> |
43 | 38 | ... | ... |
sdl.c
... | ... | @@ -21,31 +21,13 @@ |
21 | 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
22 | 22 | * THE SOFTWARE. |
23 | 23 | */ |
24 | -#include <stdlib.h> | |
25 | -#include <stdio.h> | |
26 | -#include <stdarg.h> | |
27 | -#include <string.h> | |
28 | -#include <getopt.h> | |
29 | -#include <inttypes.h> | |
30 | -#include <unistd.h> | |
31 | -#include <sys/mman.h> | |
32 | -#include <fcntl.h> | |
33 | -#include <signal.h> | |
34 | -#include <time.h> | |
35 | -#include <sys/time.h> | |
36 | -#include <malloc.h> | |
37 | -#include <termios.h> | |
38 | -#include <sys/poll.h> | |
39 | -#include <errno.h> | |
40 | -#include <sys/wait.h> | |
41 | -#include <netinet/in.h> | |
24 | +#include "vl.h" | |
42 | 25 | |
43 | 26 | #include <SDL.h> |
44 | 27 | |
45 | -#include "cpu.h" | |
46 | -#include "exec-all.h" | |
47 | - | |
48 | -#include "vl.h" | |
28 | +#ifndef _WIN32 | |
29 | +#include <signal.h> | |
30 | +#endif | |
49 | 31 | |
50 | 32 | static SDL_Surface *screen; |
51 | 33 | static int gui_grab; /* if true, all keyboard/mouse events are grabbed */ |
... | ... | @@ -291,9 +273,12 @@ void sdl_display_init(DisplayState *ds) |
291 | 273 | fprintf(stderr, "Could not initialize SDL - exiting\n"); |
292 | 274 | exit(1); |
293 | 275 | } |
276 | + | |
277 | +#ifndef _WIN32 | |
294 | 278 | /* NOTE: we still want Ctrl-C to work, so we undo the SDL redirections */ |
295 | 279 | signal(SIGINT, SIG_DFL); |
296 | 280 | signal(SIGQUIT, SIG_DFL); |
281 | +#endif | |
297 | 282 | |
298 | 283 | ds->dpy_update = sdl_update; |
299 | 284 | ds->dpy_resize = sdl_resize; | ... | ... |
target-i386/helper2.c
... | ... | @@ -24,7 +24,6 @@ |
24 | 24 | #include <inttypes.h> |
25 | 25 | #include <signal.h> |
26 | 26 | #include <assert.h> |
27 | -#include <sys/mman.h> | |
28 | 27 | |
29 | 28 | #include "cpu.h" |
30 | 29 | #include "exec-all.h" |
... | ... | @@ -334,7 +333,7 @@ int cpu_x86_handle_mmu_fault(CPUX86State *env, uint32_t addr, |
334 | 333 | if (!(env->cr[0] & CR0_PG_MASK)) { |
335 | 334 | pte = addr; |
336 | 335 | virt_addr = addr & TARGET_PAGE_MASK; |
337 | - prot = PROT_READ | PROT_WRITE; | |
336 | + prot = PAGE_READ | PAGE_WRITE; | |
338 | 337 | page_size = 4096; |
339 | 338 | goto do_mapping; |
340 | 339 | } |
... | ... | @@ -409,17 +408,17 @@ int cpu_x86_handle_mmu_fault(CPUX86State *env, uint32_t addr, |
409 | 408 | } |
410 | 409 | |
411 | 410 | /* the page can be put in the TLB */ |
412 | - prot = PROT_READ; | |
411 | + prot = PAGE_READ; | |
413 | 412 | if (pte & PG_DIRTY_MASK) { |
414 | 413 | /* only set write access if already dirty... otherwise wait |
415 | 414 | for dirty access */ |
416 | 415 | if (is_user) { |
417 | 416 | if (ptep & PG_RW_MASK) |
418 | - prot |= PROT_WRITE; | |
417 | + prot |= PAGE_WRITE; | |
419 | 418 | } else { |
420 | 419 | if (!(env->cr[0] & CR0_WP_MASK) || |
421 | 420 | (ptep & PG_RW_MASK)) |
422 | - prot |= PROT_WRITE; | |
421 | + prot |= PAGE_WRITE; | |
423 | 422 | } |
424 | 423 | } |
425 | 424 | ... | ... |
target-i386/translate-copy.c
... | ... | @@ -17,15 +17,14 @@ |
17 | 17 | * License along with this library; if not, write to the Free Software |
18 | 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
19 | 19 | */ |
20 | +#include "config.h" | |
21 | + | |
20 | 22 | #include <stdarg.h> |
21 | 23 | #include <stdlib.h> |
22 | 24 | #include <stdio.h> |
23 | 25 | #include <string.h> |
24 | 26 | #include <inttypes.h> |
25 | -#include <signal.h> | |
26 | 27 | #include <assert.h> |
27 | -#include <sys/mman.h> | |
28 | -#include <sys/ucontext.h> | |
29 | 28 | |
30 | 29 | #include "cpu.h" |
31 | 30 | #include "exec-all.h" |
... | ... | @@ -33,6 +32,10 @@ |
33 | 32 | |
34 | 33 | #ifdef USE_CODE_COPY |
35 | 34 | |
35 | +#include <signal.h> | |
36 | +#include <sys/mman.h> | |
37 | +#include <sys/ucontext.h> | |
38 | + | |
36 | 39 | extern char exec_loop; |
37 | 40 | |
38 | 41 | /* operand size */ | ... | ... |
target-i386/translate.c
vl.c
... | ... | @@ -21,35 +21,40 @@ |
21 | 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
22 | 22 | * THE SOFTWARE. |
23 | 23 | */ |
24 | -#include <stdlib.h> | |
25 | -#include <stdio.h> | |
26 | -#include <stdarg.h> | |
27 | -#include <string.h> | |
28 | -#include <ctype.h> | |
24 | +#include "vl.h" | |
25 | + | |
29 | 26 | #include <getopt.h> |
30 | -#include <inttypes.h> | |
31 | 27 | #include <unistd.h> |
32 | -#include <sys/mman.h> | |
33 | 28 | #include <fcntl.h> |
34 | 29 | #include <signal.h> |
35 | 30 | #include <time.h> |
36 | -#include <sys/time.h> | |
37 | 31 | #include <malloc.h> |
38 | -#include <termios.h> | |
39 | -#include <sys/poll.h> | |
40 | 32 | #include <errno.h> |
33 | +#include <sys/time.h> | |
34 | + | |
35 | +#ifndef _WIN32 | |
36 | +#include <sys/times.h> | |
41 | 37 | #include <sys/wait.h> |
42 | 38 | #include <pty.h> |
43 | -#include <sys/times.h> | |
44 | - | |
39 | +#include <termios.h> | |
40 | +#include <sys/poll.h> | |
41 | +#include <sys/mman.h> | |
45 | 42 | #include <sys/ioctl.h> |
46 | 43 | #include <sys/socket.h> |
47 | 44 | #include <linux/if.h> |
48 | 45 | #include <linux/if_tun.h> |
46 | +#endif | |
47 | + | |
48 | +#ifdef _WIN32 | |
49 | +#include <sys/timeb.h> | |
50 | +#include <windows.h> | |
51 | +#define getopt_long_only getopt_long | |
52 | +#define memalign(align, size) malloc(size) | |
53 | +#endif | |
54 | + | |
49 | 55 | |
50 | 56 | #include "disas.h" |
51 | 57 | |
52 | -#include "vl.h" | |
53 | 58 | #include "exec-all.h" |
54 | 59 | |
55 | 60 | #define DEFAULT_NETWORK_SCRIPT "/etc/qemu-ifup" |
... | ... | @@ -375,11 +380,17 @@ void cpu_disable_ticks(void) |
375 | 380 | } |
376 | 381 | } |
377 | 382 | |
378 | -int64_t get_clock(void) | |
383 | +static int64_t get_clock(void) | |
379 | 384 | { |
385 | +#ifdef _WIN32 | |
386 | + struct _timeb tb; | |
387 | + _ftime(&tb); | |
388 | + return ((int64_t)tb.time * 1000 + (int64_t)tb.millitm) * 1000; | |
389 | +#else | |
380 | 390 | struct timeval tv; |
381 | 391 | gettimeofday(&tv, NULL); |
382 | 392 | return tv.tv_sec * 1000000LL + tv.tv_usec; |
393 | +#endif | |
383 | 394 | } |
384 | 395 | |
385 | 396 | void cpu_calibrate_ticks(void) |
... | ... | @@ -388,7 +399,11 @@ void cpu_calibrate_ticks(void) |
388 | 399 | |
389 | 400 | usec = get_clock(); |
390 | 401 | ticks = cpu_get_real_ticks(); |
402 | +#ifdef _WIN32 | |
403 | + Sleep(50); | |
404 | +#else | |
391 | 405 | usleep(50 * 1000); |
406 | +#endif | |
392 | 407 | usec = get_clock() - usec; |
393 | 408 | ticks = cpu_get_real_ticks() - ticks; |
394 | 409 | ticks_per_sec = (ticks * 1000000LL + (usec >> 1)) / usec; |
... | ... | @@ -438,8 +453,10 @@ QEMUClock *rt_clock; |
438 | 453 | QEMUClock *vm_clock; |
439 | 454 | |
440 | 455 | static QEMUTimer *active_timers[2]; |
456 | +#ifndef _WIN32 | |
441 | 457 | /* frequency of the times() clock tick */ |
442 | 458 | static int timer_freq; |
459 | +#endif | |
443 | 460 | |
444 | 461 | QEMUClock *qemu_new_clock(int type) |
445 | 462 | { |
... | ... | @@ -550,12 +567,16 @@ int64_t qemu_get_clock(QEMUClock *clock) |
550 | 567 | { |
551 | 568 | switch(clock->type) { |
552 | 569 | case QEMU_TIMER_REALTIME: |
570 | +#ifdef _WIN32 | |
571 | + return GetTickCount(); | |
572 | +#else | |
553 | 573 | /* XXX: portability among Linux hosts */ |
554 | 574 | if (timer_freq == 100) { |
555 | 575 | return times(NULL) * 10; |
556 | 576 | } else { |
557 | 577 | return ((int64_t)times(NULL) * 1000) / timer_freq; |
558 | 578 | } |
579 | +#endif | |
559 | 580 | default: |
560 | 581 | case QEMU_TIMER_VIRTUAL: |
561 | 582 | return cpu_get_ticks(); |
... | ... | @@ -608,7 +629,12 @@ static int timer_load(QEMUFile *f, void *opaque, int version_id) |
608 | 629 | return 0; |
609 | 630 | } |
610 | 631 | |
632 | +#ifdef _WIN32 | |
633 | +void CALLBACK host_alarm_handler(UINT uTimerID, UINT uMsg, | |
634 | + DWORD_PTR dwUser, DWORD_PTR dw1, DWORD_PTR dw2) | |
635 | +#else | |
611 | 636 | static void host_alarm_handler(int host_signum) |
637 | +#endif | |
612 | 638 | { |
613 | 639 | if (qemu_timer_expired(active_timers[QEMU_TIMER_VIRTUAL], |
614 | 640 | qemu_get_clock(vm_clock)) || |
... | ... | @@ -621,39 +647,66 @@ static void host_alarm_handler(int host_signum) |
621 | 647 | |
622 | 648 | static void init_timers(void) |
623 | 649 | { |
624 | - struct sigaction act; | |
625 | - struct itimerval itv; | |
626 | - | |
627 | - /* get times() syscall frequency */ | |
628 | - timer_freq = sysconf(_SC_CLK_TCK); | |
629 | - | |
630 | 650 | rt_clock = qemu_new_clock(QEMU_TIMER_REALTIME); |
631 | 651 | vm_clock = qemu_new_clock(QEMU_TIMER_VIRTUAL); |
632 | 652 | |
633 | - /* timer signal */ | |
634 | - sigfillset(&act.sa_mask); | |
635 | - act.sa_flags = 0; | |
653 | +#ifdef _WIN32 | |
654 | + { | |
655 | + int count=0; | |
656 | + MMRESULT timerID = timeSetEvent(10, // interval (ms) | |
657 | + 0, // resolution | |
658 | + host_alarm_handler, // function | |
659 | + (DWORD)&count, // user parameter | |
660 | + TIME_PERIODIC | TIME_CALLBACK_FUNCTION); | |
661 | + if( !timerID ) { | |
662 | + perror("failed timer alarm"); | |
663 | + exit(1); | |
664 | + } | |
665 | + } | |
666 | + pit_min_timer_count = ((uint64_t)10000 * PIT_FREQ) / 1000000; | |
667 | +#else | |
668 | + { | |
669 | + struct sigaction act; | |
670 | + struct itimerval itv; | |
671 | + | |
672 | + /* get times() syscall frequency */ | |
673 | + timer_freq = sysconf(_SC_CLK_TCK); | |
674 | + | |
675 | + /* timer signal */ | |
676 | + sigfillset(&act.sa_mask); | |
677 | + act.sa_flags = 0; | |
636 | 678 | #if defined (TARGET_I386) && defined(USE_CODE_COPY) |
637 | - act.sa_flags |= SA_ONSTACK; | |
679 | + act.sa_flags |= SA_ONSTACK; | |
680 | +#endif | |
681 | + act.sa_handler = host_alarm_handler; | |
682 | + sigaction(SIGALRM, &act, NULL); | |
683 | + | |
684 | + itv.it_interval.tv_sec = 0; | |
685 | + itv.it_interval.tv_usec = 1000; | |
686 | + itv.it_value.tv_sec = 0; | |
687 | + itv.it_value.tv_usec = 10 * 1000; | |
688 | + setitimer(ITIMER_REAL, &itv, NULL); | |
689 | + /* we probe the tick duration of the kernel to inform the user if | |
690 | + the emulated kernel requested a too high timer frequency */ | |
691 | + getitimer(ITIMER_REAL, &itv); | |
692 | + pit_min_timer_count = ((uint64_t)itv.it_interval.tv_usec * PIT_FREQ) / | |
693 | + 1000000; | |
694 | + } | |
638 | 695 | #endif |
639 | - act.sa_handler = host_alarm_handler; | |
640 | - sigaction(SIGALRM, &act, NULL); | |
641 | - | |
642 | - itv.it_interval.tv_sec = 0; | |
643 | - itv.it_interval.tv_usec = 1000; | |
644 | - itv.it_value.tv_sec = 0; | |
645 | - itv.it_value.tv_usec = 10 * 1000; | |
646 | - setitimer(ITIMER_REAL, &itv, NULL); | |
647 | - /* we probe the tick duration of the kernel to inform the user if | |
648 | - the emulated kernel requested a too high timer frequency */ | |
649 | - getitimer(ITIMER_REAL, &itv); | |
650 | - pit_min_timer_count = ((uint64_t)itv.it_interval.tv_usec * PIT_FREQ) / | |
651 | - 1000000; | |
652 | 696 | } |
653 | 697 | |
654 | 698 | /***********************************************************/ |
655 | 699 | /* serial device */ |
656 | 700 | |
701 | +#ifdef _WIN32 | |
702 | + | |
703 | +int serial_open_device(void) | |
704 | +{ | |
705 | + return -1; | |
706 | +} | |
707 | + | |
708 | +#else | |
709 | + | |
657 | 710 | int serial_open_device(void) |
658 | 711 | { |
659 | 712 | char slave_name[1024]; |
... | ... | @@ -672,9 +725,24 @@ int serial_open_device(void) |
672 | 725 | } |
673 | 726 | } |
674 | 727 | |
728 | +#endif | |
729 | + | |
675 | 730 | /***********************************************************/ |
676 | 731 | /* Linux network device redirector */ |
677 | 732 | |
733 | +#ifdef _WIN32 | |
734 | + | |
735 | +static int net_init(void) | |
736 | +{ | |
737 | + return 0; | |
738 | +} | |
739 | + | |
740 | +void net_send_packet(NetDriverState *nd, const uint8_t *buf, int size) | |
741 | +{ | |
742 | +} | |
743 | + | |
744 | +#else | |
745 | + | |
678 | 746 | static int tun_open(char *ifname, int ifname_size) |
679 | 747 | { |
680 | 748 | struct ifreq ifr; |
... | ... | @@ -753,9 +821,23 @@ void net_send_packet(NetDriverState *nd, const uint8_t *buf, int size) |
753 | 821 | write(nd->fd, buf, size); |
754 | 822 | } |
755 | 823 | |
824 | +#endif | |
825 | + | |
756 | 826 | /***********************************************************/ |
757 | 827 | /* dumb display */ |
758 | 828 | |
829 | +#ifdef _WIN32 | |
830 | + | |
831 | +static void term_exit(void) | |
832 | +{ | |
833 | +} | |
834 | + | |
835 | +static void term_init(void) | |
836 | +{ | |
837 | +} | |
838 | + | |
839 | +#else | |
840 | + | |
759 | 841 | /* init terminal so that we can grab keys */ |
760 | 842 | static struct termios oldtty; |
761 | 843 | |
... | ... | @@ -790,6 +872,8 @@ static void term_init(void) |
790 | 872 | fcntl(0, F_SETFL, O_NONBLOCK); |
791 | 873 | } |
792 | 874 | |
875 | +#endif | |
876 | + | |
793 | 877 | static void dumb_update(DisplayState *ds, int x, int y, int w, int h) |
794 | 878 | { |
795 | 879 | } |
... | ... | @@ -1396,10 +1480,13 @@ void vm_stop(int reason) |
1396 | 1480 | |
1397 | 1481 | int main_loop(void) |
1398 | 1482 | { |
1483 | +#ifndef _WIN32 | |
1399 | 1484 | struct pollfd ufds[MAX_IO_HANDLERS + 1], *pf; |
1400 | - int ret, n, timeout, max_size; | |
1401 | - uint8_t buf[4096]; | |
1402 | 1485 | IOHandlerRecord *ioh, *ioh_next; |
1486 | + uint8_t buf[4096]; | |
1487 | + int n, max_size; | |
1488 | +#endif | |
1489 | + int ret, timeout; | |
1403 | 1490 | CPUState *env = global_env; |
1404 | 1491 | |
1405 | 1492 | for(;;) { |
... | ... | @@ -1422,6 +1509,7 @@ int main_loop(void) |
1422 | 1509 | timeout = 10; |
1423 | 1510 | } |
1424 | 1511 | |
1512 | +#ifndef _WIN32 | |
1425 | 1513 | /* poll any events */ |
1426 | 1514 | /* XXX: separate device handlers from system ones */ |
1427 | 1515 | pf = ufds; |
... | ... | @@ -1471,6 +1559,7 @@ int main_loop(void) |
1471 | 1559 | } |
1472 | 1560 | } |
1473 | 1561 | } |
1562 | +#endif | |
1474 | 1563 | |
1475 | 1564 | if (vm_running) { |
1476 | 1565 | qemu_run_timers(&active_timers[QEMU_TIMER_VIRTUAL], |
... | ... | @@ -1592,7 +1681,10 @@ static uint8_t *signal_stack; |
1592 | 1681 | |
1593 | 1682 | int main(int argc, char **argv) |
1594 | 1683 | { |
1595 | - int c, i, use_gdbstub, gdbstub_port, long_index, has_cdrom; | |
1684 | +#ifdef CONFIG_GDBSTUB | |
1685 | + int use_gdbstub, gdbstub_port; | |
1686 | +#endif | |
1687 | + int c, i, long_index, has_cdrom; | |
1596 | 1688 | int snapshot, linux_boot; |
1597 | 1689 | CPUState *env; |
1598 | 1690 | const char *initrd_filename; |
... | ... | @@ -1601,8 +1693,10 @@ int main(int argc, char **argv) |
1601 | 1693 | DisplayState *ds = &display_state; |
1602 | 1694 | int cyls, heads, secs; |
1603 | 1695 | |
1696 | +#if !defined(CONFIG_SOFTMMU) | |
1604 | 1697 | /* we never want that malloc() uses mmap() */ |
1605 | 1698 | mallopt(M_MMAP_THRESHOLD, 4096 * 1024); |
1699 | +#endif | |
1606 | 1700 | initrd_filename = NULL; |
1607 | 1701 | for(i = 0; i < MAX_FD; i++) |
1608 | 1702 | fd_filename[i] = NULL; |
... | ... | @@ -1611,8 +1705,10 @@ int main(int argc, char **argv) |
1611 | 1705 | ram_size = 32 * 1024 * 1024; |
1612 | 1706 | vga_ram_size = VGA_RAM_SIZE; |
1613 | 1707 | pstrcpy(network_script, sizeof(network_script), DEFAULT_NETWORK_SCRIPT); |
1708 | +#ifdef CONFIG_GDBSTUB | |
1614 | 1709 | use_gdbstub = 0; |
1615 | 1710 | gdbstub_port = DEFAULT_GDBSTUB_PORT; |
1711 | +#endif | |
1616 | 1712 | snapshot = 0; |
1617 | 1713 | nographic = 0; |
1618 | 1714 | kernel_filename = NULL; |
... | ... | @@ -1773,12 +1869,14 @@ int main(int argc, char **argv) |
1773 | 1869 | case 'n': |
1774 | 1870 | pstrcpy(network_script, sizeof(network_script), optarg); |
1775 | 1871 | break; |
1872 | +#ifdef CONFIG_GDBSTUB | |
1776 | 1873 | case 's': |
1777 | 1874 | use_gdbstub = 1; |
1778 | 1875 | break; |
1779 | 1876 | case 'p': |
1780 | 1877 | gdbstub_port = atoi(optarg); |
1781 | 1878 | break; |
1879 | +#endif | |
1782 | 1880 | case 'L': |
1783 | 1881 | bios_dir = optarg; |
1784 | 1882 | break; |
... | ... | @@ -1976,6 +2074,7 @@ int main(int argc, char **argv) |
1976 | 2074 | } |
1977 | 2075 | #endif |
1978 | 2076 | |
2077 | +#ifndef _WIN32 | |
1979 | 2078 | { |
1980 | 2079 | struct sigaction act; |
1981 | 2080 | sigfillset(&act.sa_mask); |
... | ... | @@ -1983,10 +2082,12 @@ int main(int argc, char **argv) |
1983 | 2082 | act.sa_handler = SIG_IGN; |
1984 | 2083 | sigaction(SIGPIPE, &act, NULL); |
1985 | 2084 | } |
2085 | +#endif | |
1986 | 2086 | |
1987 | 2087 | gui_timer = qemu_new_timer(rt_clock, gui_update, NULL); |
1988 | 2088 | qemu_mod_timer(gui_timer, qemu_get_clock(rt_clock)); |
1989 | 2089 | |
2090 | +#ifdef CONFIG_GDBSTUB | |
1990 | 2091 | if (use_gdbstub) { |
1991 | 2092 | if (gdbserver_start(gdbstub_port) < 0) { |
1992 | 2093 | fprintf(stderr, "Could not open gdbserver socket on port %d\n", |
... | ... | @@ -1995,7 +2096,9 @@ int main(int argc, char **argv) |
1995 | 2096 | } else { |
1996 | 2097 | printf("Waiting gdb connection on port %d\n", gdbstub_port); |
1997 | 2098 | } |
1998 | - } else { | |
2099 | + } else | |
2100 | +#endif | |
2101 | + { | |
1999 | 2102 | vm_start(); |
2000 | 2103 | } |
2001 | 2104 | term_init(); | ... | ... |
vl.h
... | ... | @@ -24,10 +24,79 @@ |
24 | 24 | #ifndef VL_H |
25 | 25 | #define VL_H |
26 | 26 | |
27 | +/* we put basic includes here to avoid repeating them in device drivers */ | |
28 | +#include <stdlib.h> | |
29 | +#include <stdio.h> | |
30 | +#include <stdarg.h> | |
31 | +#include <string.h> | |
32 | +#include <inttypes.h> | |
27 | 33 | #include <time.h> |
34 | +#include <ctype.h> | |
35 | +#include <errno.h> | |
36 | +#include <unistd.h> | |
37 | +#include <fcntl.h> | |
38 | + | |
39 | +#ifndef O_LARGEFILE | |
40 | +#define O_LARGEFILE 0 | |
41 | +#endif | |
42 | + | |
43 | +#ifdef _WIN32 | |
44 | +#define lseek64 lseek | |
45 | +#endif | |
28 | 46 | |
29 | 47 | #include "cpu.h" |
30 | 48 | |
49 | +#ifndef glue | |
50 | +#define xglue(x, y) x ## y | |
51 | +#define glue(x, y) xglue(x, y) | |
52 | +#define stringify(s) tostring(s) | |
53 | +#define tostring(s) #s | |
54 | +#endif | |
55 | + | |
56 | +#if defined(WORDS_BIGENDIAN) | |
57 | +static inline uint32_t be32_to_cpu(uint32_t v) | |
58 | +{ | |
59 | + return v; | |
60 | +} | |
61 | + | |
62 | +static inline uint16_t be16_to_cpu(uint16_t v) | |
63 | +{ | |
64 | + return v; | |
65 | +} | |
66 | + | |
67 | +static inline uint32_t le32_to_cpu(uint32_t v) | |
68 | +{ | |
69 | + return bswap32(v); | |
70 | +} | |
71 | + | |
72 | +static inline uint16_t le16_to_cpu(uint16_t v) | |
73 | +{ | |
74 | + return bswap16(v); | |
75 | +} | |
76 | + | |
77 | +#else | |
78 | +static inline uint32_t be32_to_cpu(uint32_t v) | |
79 | +{ | |
80 | + return bswap32(v); | |
81 | +} | |
82 | + | |
83 | +static inline uint16_t be16_to_cpu(uint16_t v) | |
84 | +{ | |
85 | + return bswap16(v); | |
86 | +} | |
87 | + | |
88 | +static inline uint32_t le32_to_cpu(uint32_t v) | |
89 | +{ | |
90 | + return v; | |
91 | +} | |
92 | + | |
93 | +static inline uint16_t le16_to_cpu(uint16_t v) | |
94 | +{ | |
95 | + return v; | |
96 | +} | |
97 | +#endif | |
98 | + | |
99 | + | |
31 | 100 | /* vl.c */ |
32 | 101 | extern int reset_requested; |
33 | 102 | ... | ... |