[prev in list] [next in list] [prev in thread] [next in thread] 

List:       qemu-devel
Subject:    Re: [Qemu-devel] Installing Qemu on a host MacOSX station
From:       "Pierre d'Herbemont" <stegefin () free ! fr>
Date:       2004-06-29 17:40:21
Message-ID: 64B0D9C2-C9F3-11D8-B69F-000A2796D230 () free ! fr
[Download RAW message or body]

Le 29 juin 04, à 18:40, Jean-Michel POURE a écrit :
>
> Are there pre-compiled binaries available for Qemu under MacOsX?
> Did someone here compile Qemu recently for MacOsX?
>

I don't think someone made binaries for Mac OS X. I have patches for 
Qemu to build under Mac OS X. It mostly works, but bugs remain, and you 
won't be able to boot the linux image provided by Fabrice properly. It 
crashes before giving a prompt.

Here is a diff of my current work.

["qemuosx.diff.txt" (qemuosx.diff.txt)]

? .DS_Store
? .gdb_history
? config-host.h
? config-host.mak
? copying
? copying.lib
? dyngen
? freedos.img
? i386-softmmu
? i386-user
? linux-test
? op.s
? op.syms
? out.c
? ppc-softmmu
? qemu-doc.html
? qemu-mkcow
? qemu-tech.html
? qemu.1
? readme
? small.ffs
? todo
? version
? vmdk2raw
? slirp/copyright
Index: Makefile.target
===================================================================
RCS file: /cvsroot/qemu/qemu/Makefile.target,v
retrieving revision 1.34
diff -u -r1.34 Makefile.target
--- Makefile.target	21 Jun 2004 16:44:21 -0000	1.34
+++ Makefile.target	29 Jun 2004 17:37:14 -0000
@@ -100,6 +100,7 @@
 endif
 
 ifeq ($(ARCH),ppc)
+CFLAGS+= -D__powerpc__
 OP_CFLAGS=$(CFLAGS)
 LDFLAGS+=-Wl,-T,$(SRC_PATH)/ppc.ld
 endif
@@ -152,6 +153,10 @@
 OP_CFLAGS+=-fno-reorder-blocks -fno-optimize-sibling-calls
 endif
 
+ifeq ($(CONFIG_DARWIN),yes)
+OP_CFLAGS+= -mdynamic-no-pic
+endif
+
 #########################################################
 
 DEFINES+=-D_GNU_SOURCE
@@ -268,8 +273,10 @@
 VL_LDFLAGS+=-Wl,-T,$(SRC_PATH)/i386-vl.ld 
 endif
 ifndef CONFIG_WIN32
+ifndef CONFIG_DARWIN
 VL_LIBS=-lutil
 endif
+endif
 
 $(QEMU_SYSTEM): $(VL_OBJS) libqemu.a
 	$(CC) $(VL_LDFLAGS) -o $@ $^ $(LIBS) $(SDL_LIBS) $(VL_LIBS)
Index: configure
===================================================================
RCS file: /cvsroot/qemu/qemu/configure,v
retrieving revision 1.40
diff -u -r1.40 configure
--- configure	4 Jun 2004 11:13:20 -0000	1.40
+++ configure	29 Jun 2004 17:37:14 -0000
@@ -88,12 +88,19 @@
 OpenBSD)
 bsd="yes"
 ;;
+Darwin)
+bsd="yes"
+darwin="yes"
+;;
 *) ;;
 esac
 
-if [ "$bsd" = "yes" ] ; then
+if [ "$bsd" = "yes" ] && ! [ "$darwin" = "yes" ] ; then
   make="gmake"
-  target_list="i386-softmmu"
+fi
+
+if [ "$bsd" = "yes" ] ; then
+  target_list="i386-softmmu ppc-softmmu"
 fi
 
 # find source path
@@ -391,6 +398,10 @@
 elif test -f "/usr/include/byteswap.h" ; then
   echo "#define HAVE_BYTESWAP_H 1" >> $config_h
 fi
+if test "$darwin" = "yes" ; then
+  echo "CONFIG_DARWIN=yes" >> $config_mak
+  echo "#define CONFIG_DARWIN 1" >> $config_h
+fi
 if test "$gdbstub" = "yes" ; then
   echo "CONFIG_GDBSTUB=yes" >> $config_mak
   echo "#define CONFIG_GDBSTUB 1" >> $config_h
@@ -420,9 +431,11 @@
 if [ "$bsd" = "yes" ] ; then
   echo "#define O_LARGEFILE 0" >> $config_h
   echo "#define lseek64 lseek" >> $config_h
+  echo "#define mkstemp64 mkstemp" >> $config_h
   echo "#define ftruncate64 ftruncate" >> $config_h
   echo "#define MAP_ANONYMOUS MAP_ANON" >> $config_h
   echo "#define _BSD 1" >> $config_h
+  echo "#define off64_t off_t" >> $config_h
 fi
 
 for target in $target_list; do 
Index: cpu-all.h
===================================================================
RCS file: /cvsroot/qemu/qemu/cpu-all.h,v
retrieving revision 1.33
diff -u -r1.33 cpu-all.h
--- cpu-all.h	20 Jun 2004 12:35:26 -0000	1.33
+++ cpu-all.h	29 Jun 2004 17:37:15 -0000
@@ -538,12 +538,12 @@
 #define TARGET_PAGE_MASK ~(TARGET_PAGE_SIZE - 1)
 #define TARGET_PAGE_ALIGN(addr) (((addr) + TARGET_PAGE_SIZE - 1) & TARGET_PAGE_MASK)
 
-extern unsigned long real_host_page_size;
-extern unsigned long host_page_bits;
-extern unsigned long host_page_size;
-extern unsigned long host_page_mask;
+extern unsigned long qemu_real_host_page_size;
+extern unsigned long qemu_host_page_bits;
+extern unsigned long qemu_host_page_size;
+extern unsigned long qemu_host_page_mask;
 
-#define HOST_PAGE_ALIGN(addr) (((addr) + host_page_size - 1) & host_page_mask)
+#define HOST_PAGE_ALIGN(addr) (((addr) + qemu_host_page_size - 1) & \
qemu_host_page_mask)  
 /* same as PROT_xxx */
 #define PAGE_READ      0x0001
Index: dyngen-exec.h
===================================================================
RCS file: /cvsroot/qemu/qemu/dyngen-exec.h,v
retrieving revision 1.12
diff -u -r1.12 dyngen-exec.h
--- dyngen-exec.h	12 May 2004 19:32:15 -0000	1.12
+++ dyngen-exec.h	29 Jun 2004 17:37:25 -0000
@@ -32,6 +32,7 @@
 typedef unsigned long long uint64_t;
 #endif
 
+#ifndef __APPLE__
 typedef signed char int8_t;
 typedef signed short int16_t;
 typedef signed int int32_t;
@@ -40,6 +41,7 @@
 #else
 typedef signed long long int64_t;
 #endif
+#endif
 
 #define INT8_MIN		(-128)
 #define INT16_MIN		(-32767-1)
@@ -59,7 +61,7 @@
 extern int printf(const char *, ...);
 #undef NULL
 #define NULL 0
-#ifdef _BSD
+#if defined(_BSD) && !defined(__APPLE__)
 #include <ieeefp.h>
 #else
 #include <fenv.h>
@@ -187,6 +189,15 @@
 #define PARAM1 ({ int _r; asm("" : "=r"(_r) : "0" (&__op_param1)); _r; })
 #define PARAM2 ({ int _r; asm("" : "=r"(_r) : "0" (&__op_param2)); _r; })
 #define PARAM3 ({ int _r; asm("" : "=r"(_r) : "0" (&__op_param3)); _r; })
+
+#elif defined(__APPLE__)
+static int __op_param1 ;
+static int __op_param2 ;
+static int __op_param3 ;
+#define PARAM1 ((long)(&__op_param1))
+#define PARAM2 ((long)(&__op_param2))
+#define PARAM3 ((long)(&__op_param3))
+
 #else
 extern int __op_param1, __op_param2, __op_param3;
 #define PARAM1 ((long)(&__op_param1))
Index: dyngen.c
===================================================================
RCS file: /cvsroot/qemu/qemu/dyngen.c,v
retrieving revision 1.34
diff -u -r1.34 dyngen.c
--- dyngen.c	4 Apr 2004 12:56:28 -0000	1.34
+++ dyngen.c	29 Jun 2004 17:37:25 -0000
@@ -34,6 +34,8 @@
    compilation */
 #if defined(CONFIG_WIN32)
 #define CONFIG_FORMAT_COFF
+#elif defined(CONFIG_DARWIN)
+#define CONFIG_FORMAT_MACH
 #else
 #define CONFIG_FORMAT_ELF
 #endif
@@ -169,6 +171,44 @@
 
 #endif /* CONFIG_FORMAT_COFF */
 
+#ifdef CONFIG_FORMAT_MACH
+
+#include <mach-o/loader.h>
+#include <mach-o/nlist.h>
+#include <mach-o/reloc.h>
+#include <mach-o/ppc/reloc.h>
+
+# define check_mach_header(x) (x.magic == MH_MAGIC)
+typedef int32_t host_long;
+typedef uint32_t host_ulong;
+
+/* File Header */
+struct mach_header 	mach_hdr;
+
+/* commands */
+struct segment_command 	*segment = 0;
+struct dysymtab_command *dysymtabcmd = 0;
+struct symtab_command 	*symtabcmd = 0;
+
+/* section */
+struct section 	*section_hdr;
+struct section *text_sec_hdr;
+uint8_t 	**sdata;
+
+/* relocs */
+struct relocation_info *relocs;
+	
+/* symbols */
+struct nlist 	*symtab;
+char 		*strtab;
+
+/* indirect symbols */
+uint32_t 	*tocdylib;
+#define EXE_RELOC struct relocation_info
+#define EXE_SYM struct nlist
+
+#endif /* CONFIG_FORMAT_MACH */
+
 #include "bswap.h"
 
 enum {
@@ -177,8 +217,17 @@
     OUT_INDEX_OP,
 };
 
+
+#ifdef CONFIG_FORMAT_MACH
+# define ASM_NAME(x)			"_" #x
+# define CSYM_NAME(x)			((char*)x)+1
+#else
+# define ASM_NAME(x)			x
+# define CSYM_NAME(x)			x
+#endif
+
 /* all dynamically generated functions begin with this code */
-#define OP_PREFIX "op_"
+#define OP_PREFIX ASM_NAME(op_)
 
 int do_swap;
 
@@ -399,6 +448,11 @@
     return 0;
 }
 
+static int get_rel_offset(EXE_RELOC *rel)
+{
+    return rel->r_offset;
+}
+
 static char *get_rel_sym_name(EXE_RELOC *rel)
 {
     return strtab + symtab[ELFW(R_SYM)(rel->r_info)].st_name;
@@ -600,6 +654,11 @@
     return name;
 }
 
+static int get_rel_offset(EXE_RELOC *rel)
+{
+    return rel->r_offset;
+}
+
 struct external_scnhdr *find_coff_section(struct external_scnhdr *shdr, int shnum, \
const char *name)  {
     int i;
@@ -758,6 +817,358 @@
 
 #endif /* CONFIG_FORMAT_COFF */
 
+#ifdef CONFIG_FORMAT_MACH
+
+/* Utility functions */
+
+static inline char *find_str_by_index(int index)
+{
+    return strtab+index;
+}
+
+static inline char *find_symname_by_symindex(EXE_SYM *syms, int index)
+{
+    return find_str_by_index(syms[index].n_un.n_strx);
+}
+
+/* Used by dyngen common code */
+static char *get_sym_name(EXE_SYM *sym)
+{
+    return find_str_by_index(sym->n_un.n_strx);
+}
+
+/* find a section index given its segname, sectname */
+static int find_mach_sec_index(struct section *section_hdr, int shnum, const char \
*segname,  +                                  const char *sectname)
+{
+    int i;
+    struct section *sec = section_hdr;
+
+    for(i = 0; i < shnum; i++, sec++) {
+        if (!sec->segname || !sec->sectname)
+            continue;
+        if (!strcmp(sec->sectname, sectname) && !strcmp(sec->segname, segname))
+            return i;
+    }
+    return -1;
+}
+
+/* find a section header given its segname, sectname */
+struct section *find_mach_sec_hdr(struct section *section_hdr, int shnum, const char \
*segname,  +                                  const char *sectname)
+{
+    int index = find_mach_sec_index(section_hdr, shnum, segname, sectname);
+	if(index == -1)
+		return NULL;
+	return section_hdr+index;
+}
+
+
+static inline void fetch_next_pair_value(struct relocation_info * rel, unsigned int \
*value) +{
+    struct scattered_relocation_info * scarel;
+	
+    if(R_SCATTERED & rel->r_address) {
+        scarel = (struct scattered_relocation_info*)rel;
+        if(scarel->r_type != PPC_RELOC_PAIR)
+            error("fetch_next_pair_value: looking for a pair which was not found \
(1)"); +        *value = scarel->r_value;
+    } else {
+		if(rel->r_type != PPC_RELOC_PAIR)
+			error("fetch_next_pair_value: looking for a pair which was not found (2)");
+		*value = rel->r_address;
+	}
+}
+
+/* find a sym name given its value, in a section number */
+static const char * find_sym_with_value_and_sec_number( int value, int sectnum, int \
* offset ) +{
+	int i, ret = -1;
+	
+	for( i = 0 ; i < nb_syms; i++ )
+	{
+	    if( !(symtab[i].n_type & N_STAB) &&
+			(symtab[i].n_type & N_SECT) &&
+			 (symtab[i].n_sect ==  sectnum) &&
+			 (symtab[i].n_value <= value))
+		{
+			if( (ret<0) || (symtab[i].n_value >= symtab[ret].n_value) )
+			{
+				ret = i;
+			}
+		}
+	}
+	if(ret<0) {
+		*offset = 0;
+		return 0;
+	} else {
+		*offset = value - symtab[ret].n_value;
+		return find_str_by_index(symtab[ret].n_un.n_strx);
+	}
+}
+
+/* 
+ *  Find symbol name given a (virtual) address, and a section which is of type 
+ *  S_NON_LAZY_SYMBOL_POINTERS or S_LAZY_SYMBOL_POINTERS or S_SYMBOL_STUBS
+ */
+static const char * find_reloc_name_in_sec_ptr(int address, struct section * \
sec_hdr) +{
+    unsigned int tocindex, symindex, size;
+    const char *name = 0;
+    
+    /* Sanity check */
+    if(!( address >= sec_hdr->addr && address < (sec_hdr->addr + sec_hdr->size) ) )
+        return (char*)0;
+		
+	if( sec_hdr->flags & S_SYMBOL_STUBS ){
+		size = sec_hdr->reserved2;
+		if(size == 0)
+		    error("size = 0");
+		
+	}
+	else if( sec_hdr->flags & S_LAZY_SYMBOL_POINTERS ||
+	            sec_hdr->flags & S_NON_LAZY_SYMBOL_POINTERS)
+		size = sizeof(unsigned long);
+	else
+		return 0;
+		
+    /* Compute our index in toc */
+	tocindex = (address - sec_hdr->addr)/size;
+	symindex = tocdylib[sec_hdr->reserved1 + tocindex];
+	
+	name = find_str_by_index(symtab[symindex].n_un.n_strx);
+
+    return name;
+}
+
+static const char * find_reloc_name_given_its_address(int address)
+{
+    unsigned int i;
+    for(i = 0; i < segment->nsects ; i++)
+    {
+        const char * name = find_reloc_name_in_sec_ptr(address, &section_hdr[i]);
+        if((long)name != -1)
+            return name;
+    }
+    return 0;
+}
+
+static const char * get_reloc_name(EXE_RELOC * rel, int * sslide, FILE *file)
+{
+	char * name = 0;
+	struct scattered_relocation_info * sca_rel = (struct \
scattered_relocation_info*)rel; +	
+	/* init it */
+	*sslide = 0;
+	
+	if(R_SCATTERED & rel->r_address)
+	{
+		if(file)
+			fprintf(file, "/* R_SCATTERED rel->r_address 0x%x*/\n", rel->r_address);
+		name = (char *)find_reloc_name_given_its_address(sca_rel->r_value);
+	}
+	else
+	{
+		if(rel->r_extern)
+		{
+			/* ignore debug sym */
+			if ( symtab[rel->r_symbolnum].n_type & N_STAB /* || \
symtab[rel->r_symbolnum].n_sect != 1*/)  +				return 0;
+			if(file)
+				fprintf(file, "/* rel->r_extern */\n");
+			name = find_symname_by_symindex(symtab, rel->r_symbolnum);
+		}
+		else
+		{
+			int sectnum = rel->r_symbolnum;
+			int sectoffset;
+			int other_half=0;
+			/* Intruction contains an offset to the symbols pointed to, in the \
rel->r_symbolnum section */ +			sectoffset = *(uint32_t *)(text + rel->r_address) & \
0xffff; +			
+			if(file)
+				fprintf(file, "/* sectoffset 0x%x (rel->r_address 0x%x) [0x%x] Section %d*/\n", \
sectoffset, +							(int)rel->r_address, *(int *)(text + rel->r_address), sectnum);
+				
+			if(sectnum==0xffffff)
+				return 0;
+
+			/* Sanity Check */
+			if(sectnum > segment->nsects)
+				error("sectnum > segment->nsects");
+
+			switch(rel->r_type)
+			{
+				case PPC_RELOC_LO16: fetch_next_pair_value(rel+1, &other_half); sectoffset = \
(sectoffset & 0xffff); +					break;
+				case PPC_RELOC_HI16: fetch_next_pair_value(rel+1, &other_half); sectoffset = \
(other_half & 0xffff); +					break;
+				case PPC_RELOC_HA16: fetch_next_pair_value(rel+1, &other_half); sectoffset = \
(other_half & 0xffff); +					break;
+				case PPC_RELOC_BR24: sectoffset = ( (*(uint32_t *)(text + rel->r_address)) & \
0x03fffffc ); break; +				default:
+					error("switch(rel->type) not found");
+			}
+			if(file)
+				fprintf(file, "/* sectoffset 0x%x */\n", sectoffset);
+			if(rel->r_pcrel)
+				sectoffset += rel->r_address;
+			sectoffset &= 0x03FFFFFF;
+			if(file)
+				fprintf(file, "/* sectoffset 0x%x */\n", sectoffset);
+			
+			/* search it in the full symbol list */
+			if(file)
+				fprintf(file, "/* looking in the full sym list (%d) %s,%s */\n", sectnum, \
section_hdr[sectnum-1].sectname, section_hdr[sectnum-1].segname); +
+			name = (char *)find_sym_with_value_and_sec_number(sectoffset, sectnum, sslide);
+			
+			if(file)
+				fprintf(file, "/* name %s */\n", name);
+				
+			/* Find a lazy ptr */
+			if(file)
+				fprintf(file, "/* looking for lazy in (%d) %s,%s */\n", sectnum, \
section_hdr[sectnum-1].sectname, section_hdr[sectnum-1].segname); +			
+			if(!name)
+				name = (char *)find_reloc_name_in_sec_ptr((int)sectoffset, \
&section_hdr[sectnum-1]); +			
+			if(file)
+				fprintf(file, "/* name %s */\n", name);
+				
+		}
+	}
+	return name;
+}
+
+/* Used by dyngen common code */
+static const char * get_rel_sym_name(EXE_RELOC * rel)
+{
+	int sslide;
+	return get_reloc_name( rel, &sslide, 0);
+}
+
+/* Used by dyngen common code */
+static int get_rel_offset(EXE_RELOC *rel)
+{
+	struct scattered_relocation_info * sca_rel = (struct \
scattered_relocation_info*)rel; +    if(R_SCATTERED & rel->r_address)
+		return sca_rel->r_address;
+	else
+		return rel->r_address;
+}
+
+/* load a mach-o object file */
+int load_object(const char *filename)
+{
+	int fd;
+	unsigned int offset_to_segment = 0;
+    unsigned int offset_to_dysymtab = 0;
+    unsigned int offset_to_symtab = 0;
+    
+    struct load_command lc;
+    unsigned int i, j;
+    
+	fd = open(filename, O_RDONLY);
+    if (fd < 0) 
+        error("can't open file '%s'", filename);
+		
+    /* Read Mach header.  */
+    if (read(fd, &mach_hdr, sizeof (mach_hdr)) != sizeof (mach_hdr))
+        error("unable to read file header");
+
+    /* Check Mach identification.  */
+    if (!check_mach_header(mach_hdr)) {
+        error("bad Mach header");
+    }
+    
+    if (mach_hdr.cputype != CPU_TYPE_POWERPC)
+        error("Unsupported CPU");
+        
+    if (mach_hdr.filetype != MH_OBJECT)
+        error("Unsupported Mach Object");
+    
+    /* read segment headers */
+    for(i=0, j=sizeof(mach_hdr); i<mach_hdr.ncmds ; i++)
+    {
+        if(read(fd, &lc, sizeof(struct load_command)) != sizeof(struct \
load_command)) +            error("unable to read load_command");
+        if(lc.cmd == LC_SEGMENT)
+        {
+            offset_to_segment = j;
+            lseek(fd, offset_to_segment, SEEK_SET);
+            segment = malloc(sizeof(struct segment_command));
+            if(read(fd, segment, sizeof(struct segment_command)) != sizeof(struct \
segment_command)) +                error("unable to read LC_SEGMENT");
+        }
+        if(lc.cmd == LC_DYSYMTAB)
+        {
+            offset_to_dysymtab = j;
+            lseek(fd, offset_to_dysymtab, SEEK_SET);
+            dysymtabcmd = malloc(sizeof(struct dysymtab_command));
+            if(read(fd, dysymtabcmd, sizeof(struct dysymtab_command)) != \
sizeof(struct dysymtab_command)) +                error("unable to read \
LC_DYSYMTAB"); +        }
+        if(lc.cmd == LC_SYMTAB)
+        {
+            offset_to_symtab = j;
+            lseek(fd, offset_to_symtab, SEEK_SET);
+            symtabcmd = malloc(sizeof(struct symtab_command));
+            if(read(fd, symtabcmd, sizeof(struct symtab_command)) != sizeof(struct \
symtab_command)) +                error("unable to read LC_SYMTAB");
+        }
+        j+=lc.cmdsize;
+
+        lseek(fd, j, SEEK_SET);
+    }
+
+    if(!segment)
+        error("unable to find LC_SEGMENT");
+
+    /* read section headers */
+    section_hdr = load_data(fd, offset_to_segment + sizeof(struct segment_command), \
segment->nsects * sizeof(struct section)); +
+    /* read all section data */
+    sdata = (uint8_t **)malloc(sizeof(void *) * segment->nsects);
+    memset(sdata, 0, sizeof(void *) * segment->nsects);
+    
+	/* Load the data in section data */
+	for(i = 0; i < segment->nsects; i++) {
+        sdata[i] = load_data(fd, section_hdr[i].offset, section_hdr[i].size);
+    }
+	
+    /* text section */
+	text_sec_hdr = find_mach_sec_hdr(section_hdr, segment->nsects, SEG_TEXT, \
SECT_TEXT); +	i = find_mach_sec_index(section_hdr, segment->nsects, SEG_TEXT, \
SECT_TEXT); +	if (i == -1 || !text_sec_hdr)
+        error("could not find __TEXT,__text section");
+    text = sdata[i];
+	
+    /* Make sure dysym was loaded */
+    if(!(int)dysymtabcmd)
+        error("could not find __DYSYMTAB segment");
+    
+    /* read the table of content of the indirect sym */
+    tocdylib = load_data( fd, dysymtabcmd->indirectsymoff, \
dysymtabcmd->nindirectsyms * sizeof(uint32_t) ); +    
+    /* Make sure symtab was loaded  */
+    if(!(int)symtabcmd)
+        error("could not find __SYMTAB segment");
+    nb_syms = symtabcmd->nsyms;
+
+    symtab = load_data(fd, symtabcmd->symoff, symtabcmd->nsyms * sizeof(struct \
nlist)); +    strtab = load_data(fd, symtabcmd->stroff, symtabcmd->strsize);
+
+    /* Find Reloc */
+    relocs = load_data(fd, text_sec_hdr->reloff, text_sec_hdr->nreloc * \
sizeof(struct relocation_info)); +    nb_relocs = text_sec_hdr->nreloc;
+
+	close(fd);
+	return 0;
+}
+
+#endif /* CONFIG_FORMAT_MACH */
+
 #ifdef HOST_ARM
 
 int arm_emit_ldr_info(const char *name, unsigned long start_offset,
@@ -1049,10 +1460,13 @@
         args_present[i] = 0;
 
     for(i = 0, rel = relocs;i < nb_relocs; i++, rel++) {
-        if (rel->r_offset >= start_offset &&
-	    rel->r_offset < start_offset + (p_end - p_start)) {
+		int offset = get_rel_offset(rel);
+        if (offset >= start_offset &&
+	    offset < start_offset + (p_end - p_start)) {
             sym_name = get_rel_sym_name(rel);
-            if (strstart(sym_name, "__op_param", &p)) {
+			if(!sym_name)
+				continue;
+            if (strstart(sym_name, ASM_NAME(__op_param), &p)) {
                 n = strtoul(p, NULL, 10);
                 if (n > MAX_ARGS)
                     error("too many arguments in %s", name);
@@ -1070,11 +1484,11 @@
     }
 
     if (gen_switch == 2) {
-        fprintf(outfile, "DEF(%s, %d, %d)\n", name + 3, nb_args, copy_size);
+        fprintf(outfile, "DEF(%s, %d, %d)\n", CSYM_NAME(name) + 3, nb_args, \
copy_size);  } else if (gen_switch == 1) {
 
         /* output C code */
-        fprintf(outfile, "case INDEX_%s: {\n", name);
+        fprintf(outfile, "case INDEX_%s: {\n", CSYM_NAME(name));
         if (nb_args > 0) {
             fprintf(outfile, "    long ");
             for(i = 0; i < nb_args; i++) {
@@ -1084,15 +1498,18 @@
             }
             fprintf(outfile, ";\n");
         }
-        fprintf(outfile, "    extern void %s();\n", name);
+        fprintf(outfile, "    extern void %s();\n", CSYM_NAME(name));
 
         for(i = 0, rel = relocs;i < nb_relocs; i++, rel++) {
-            if (rel->r_offset >= start_offset &&
-		rel->r_offset < start_offset + (p_end - p_start)) {
+			int offset = get_rel_offset(rel);
+            if (offset >= start_offset &&
+				offset < start_offset + (p_end - p_start)) {
                 sym_name = get_rel_sym_name(rel);
+				if(!sym_name)
+					continue;
                 if (*sym_name && 
-                    !strstart(sym_name, "__op_param", NULL) &&
-                    !strstart(sym_name, "__op_jmp", NULL)) {
+                    !strstart(sym_name, ASM_NAME(__op_param), NULL) &&
+                    !strstart(sym_name, ASM_NAME(__op_jmp), NULL)) {
 #if defined(HOST_SPARC)
 		    if (sym_name[0] == '.') {
 			fprintf(outfile,
@@ -1101,12 +1518,13 @@
 			continue;
 		    }
 #endif
-                    fprintf(outfile, "extern char %s;\n", sym_name);
+                    fprintf(outfile, "extern char %s;\n", CSYM_NAME(sym_name));
                 }
             }
         }
 
-        fprintf(outfile, "    memcpy(gen_code_ptr, (void *)((char *)&%s+%d), \
%d);\n", name, start_offset - offset, copy_size); +        fprintf(outfile, "    \
memcpy(gen_code_ptr, (void *)((char *)&%s+%d), %d);\n", +					CSYM_NAME(name), \
(int)(start_offset - offset), copy_size);  
         /* emit code offset information */
         {
@@ -1117,7 +1535,7 @@
 
             for(i = 0, sym = symtab; i < nb_syms; i++, sym++) {
                 sym_name = get_sym_name(sym);
-                if (strstart(sym_name, "__op_label", &p)) {
+                if (strstart(sym_name, ASM_NAME(__op_label), &p)) {
                     uint8_t *ptr;
                     unsigned long offset;
                     
@@ -1131,12 +1549,20 @@
                     } else {
                         ptr = NULL;
                     }
+#elif defined(CONFIG_FORMAT_MACH)
+					if(!sym->n_sect)
+						continue;
+					ptr = sdata[sym->n_sect-1];
 #else
                     ptr = sdata[sym->st_shndx];
 #endif
                     if (!ptr)
                         error("__op_labelN in invalid section");
+#ifdef CONFIG_FORMAT_MACH
+					offset = sym->n_value - section_hdr[sym->n_sect-1].addr;
+#else
                     offset = sym->st_value;
+#endif
                     val = *(unsigned long *)(ptr + offset);
 #ifdef ELF_USES_RELOCA
                     {
@@ -1284,6 +1710,7 @@
             }
 #elif defined(HOST_PPC)
             {
+#ifdef CONFIG_FORMAT_ELF
                 char name[256];
                 int type;
                 int addend;
@@ -1337,6 +1764,101 @@
                         }
                     }
                 }
+#elif defined(CONFIG_FORMAT_MACH)
+				struct scattered_relocation_info *scarel;
+				struct relocation_info * rel;
+				char final_sym_name[256];
+				const char *sym_name;
+				const char *p;
+				int slide, sslide;
+				int i;
+	
+				for(i = 0, rel = relocs; i < nb_relocs; i++, rel++) {
+					unsigned int offset, length, value = 0;
+					unsigned int type, pcrel, isym = 0;
+					unsigned int usesym = 0;
+				
+					if(R_SCATTERED & rel->r_address) {
+						scarel = (struct scattered_relocation_info*)rel;
+						offset = (unsigned int)scarel->r_address;
+						length = scarel->r_length;
+						pcrel = scarel->r_pcrel;
+						type = scarel->r_type;
+						value = scarel->r_value;
+					} else {
+						value = isym = rel->r_symbolnum;
+						usesym = (rel->r_extern);
+						offset = rel->r_address;
+						length = rel->r_length;
+						pcrel = rel->r_pcrel;
+						type = rel->r_type;
+					}
+				
+					slide = offset - start_offset;
+		
+					if (!(offset >= start_offset && offset < start_offset + size)) 
+						continue;  /* not in our range */
+
+					sym_name = get_reloc_name(rel, &sslide, outfile);
+					
+					if(usesym && symtab[isym].n_type & N_STAB)
+					{
+						fprintf(outfile, "    /* N_STAB %s */\n", sym_name);
+						continue; /* don't handle STAB (debug sym) */
+					}
+					
+					if (sym_name && strstart(sym_name, ASM_NAME(__op_jmp), &p)) {
+						int n;
+						n = strtol(p, NULL, 10);
+						fprintf(outfile, "    jmp_offsets[%d] = %d + (gen_code_ptr - \
gen_code_buf);\n", +							n, slide);
+						continue; /* Nothing more to do */
+					}
+					
+					if(!sym_name)
+					{
+						fprintf(outfile, "/* #warning relocation not handled in %s (value 0x%x, %s, \
offset 0x%x, length 0x%x, %s, type 0x%x) */\n", +						           CSYM_NAME(name), \
value, usesym ? "use sym" : "don't use sym", offset, length, pcrel ? "pcrel":"", \
type); +						continue; /* dunno how to handle without final_sym_name */
+					}
+					fprintf(outfile, "/* reloc %s (value 0x%x, %s, offset 0x%x, length 0x%x, %s, \
type 0x%x) */\n", +						           CSYM_NAME(name), value, usesym ? "use sym" : \
"don't use sym", offset, length, pcrel ? "pcrel":"", type); +					if \
(strstart(sym_name, ASM_NAME(__op_param), &p)) { +						snprintf(final_sym_name, \
sizeof(final_sym_name), "param%s", p); +					} else {
+						snprintf(final_sym_name, sizeof(final_sym_name), "(long)(&%s)", \
CSYM_NAME(sym_name)); +						//fprintf(outfile, "extern char %s;\n", \
CSYM_NAME(sym_name)); +					}
+			
+					switch(type) {
+					case PPC_RELOC_BR24:
+						fprintf(outfile, "/* PPC_RELOC_BR24 %s */\n", sym_name ? sym_name : "without \
syms"); +						fprintf(outfile, "    *(uint32_t *)(gen_code_ptr + %d) = (*(uint32_t \
*)(gen_code_ptr + %d) & ~0x03fffffc) | ((%s - (long)(gen_code_ptr + %d) + %d) & \
0x03fffffc);\n",  +							slide, slide, final_sym_name, slide, sslide /* value */ );
+						break;
+					case PPC_RELOC_HI16:
+						fprintf(outfile, "/* PPC_RELOC_HI16 %s */\n", sym_name ? sym_name : "without \
syms"); +						fprintf(outfile, "    *(uint16_t *)(gen_code_ptr + %d + 2) = (%s + %d) \
>> 16;\n",  +							slide, final_sym_name, sslide);
+						break;
+					case PPC_RELOC_LO16:
+						fprintf(outfile, "/* PPC_RELOC_LO16 %s */\n", sym_name ? sym_name : "without \
syms"); +						fprintf(outfile, "    *(uint16_t *)(gen_code_ptr + %d + 2) = (%s + \
%d);\n",  +					slide, final_sym_name, sslide);
+                            break;
+					case PPC_RELOC_HA16:
+						fprintf(outfile, "/* PPC_RELOC_HA16 %s */\n", sym_name ? sym_name : "without \
syms"); +						fprintf(outfile, "    *(uint16_t *)(gen_code_ptr + %d + 2) = (%s + %d \
+ 0x8000) >> 16;\n",  +							slide, final_sym_name, sslide);
+						break;
+				default:
+					fprintf(outfile, "/* unsupported powerpc relocation %d %s */\n", type, usesym ? \
"with sym" : "without syms"); +					error("unsupported powerpc relocation (%d)", \
type); +				}
+			}
+#else
+#error unsupport object format
+#endif
             }
 #elif defined(HOST_S390)
             {
@@ -1657,7 +2179,7 @@
         fprintf(outfile, "}\n");
         fprintf(outfile, "break;\n\n");
     } else {
-        fprintf(outfile, "static inline void gen_%s(", name);
+        fprintf(outfile, "static inline void gen_%s(", CSYM_NAME(name));
         if (nb_args == 0) {
             fprintf(outfile, "void");
         } else {
@@ -1672,11 +2194,50 @@
         for(i = 0; i < nb_args; i++) {
             fprintf(outfile, "    *gen_opparam_ptr++ = param%d;\n", i + 1);
         }
-        fprintf(outfile, "    *gen_opc_ptr++ = INDEX_%s;\n", name);
+        fprintf(outfile, "    *gen_opc_ptr++ = INDEX_%s;\n", CSYM_NAME(name));
         fprintf(outfile, "}\n\n");
     }
 }
 
+#ifdef CONFIG_FORMAT_MACH
+# define begin_go_through_syms(symtab, nb_syms, sym, i) \
+	for(i = 0, sym = symtab; i < nb_syms; i++, sym++) { \
+        const char *name; \
+        struct nlist *sym_follow, *sym_next = 0; \
+        unsigned int j, size; \
+        name = find_str_by_index(sym->n_un.n_strx); \
+        if ( sym->n_type & N_STAB || sym->n_sect != 1 || !strstart(name, OP_PREFIX, \
NULL) ) \ +            continue; \
+		/* Find the following symbol in order to get the current symbol size */ \
+        for(j = 0, sym_follow = symtab; j < nb_syms; j++, sym_follow++) { \
+            if ( sym_follow->n_sect != 1 || sym_follow->n_type & N_STAB || \
!(sym_follow->n_value > sym->n_value)) \ +                continue; \
+            if(!sym_next) { \
+                sym_next = sym_follow; \
+                continue; \
+            } \
+            if(!(sym_next->n_value > sym_follow->n_value)) \
+                continue; \
+            sym_next = sym_follow; \
+        } \
+		if(sym_next) \
+            size = sym_next->n_value - sym->n_value; \
+		else \
+            size = text_sec_hdr->size - sym->n_value;
+# define end_go_through_syms() \
+	}
+# define macro_gen_code(i)  gen_code(name, sym->n_value, size, outfile, i)
+#else
+# define begin_go_through_syms(symtab, nb_syms, sym, i) \
+	for(i = 0, sym = symtab; i < nb_syms; i++, sym++) { \
+		const char *name, *p; \
+		name = get_sym_name(sym); \
+		if (strstart(name, OP_PREFIX, &p)) {
+# define end_go_through_syms() \
+	} }
+# define macro_gen_code(i) gen_code(name, sym->st_value, sym->st_size, outfile, i)
+#endif
+
 int gen_file(FILE *outfile, int out_type)
 {
     int i;
@@ -1688,25 +2249,20 @@
         fprintf(outfile, "DEF(nop1, 1, 0)\n");
         fprintf(outfile, "DEF(nop2, 2, 0)\n");
         fprintf(outfile, "DEF(nop3, 3, 0)\n");
-        for(i = 0, sym = symtab; i < nb_syms; i++, sym++) {
-            const char *name, *p;
-            name = get_sym_name(sym);
-            if (strstart(name, OP_PREFIX, &p)) {
-                gen_code(name, sym->st_value, sym->st_size, outfile, 2);
-            }
-        }
+
+        begin_go_through_syms(symtab, nb_syms, sym, i)
+			macro_gen_code(2);
+		end_go_through_syms()
+		
     } else if (out_type == OUT_GEN_OP) {
         /* generate gen_xxx functions */
-
-        for(i = 0, sym = symtab; i < nb_syms; i++, sym++) {
-            const char *name;
-            name = get_sym_name(sym);
-            if (strstart(name, OP_PREFIX, NULL)) {
-                if (sym->st_shndx != text_shndx)
+		begin_go_through_syms(symtab, nb_syms, sym, i)
+#if defined(CONFIG_FORMAT_ELF) || defined(CONFIG_FORMAT_COFF)
+			if (sym->st_shndx != text_shndx)
                     error("invalid section for opcode (0x%x)", sym->st_shndx);
-                gen_code(name, sym->st_value, sym->st_size, outfile, 0);
-            }
-        }
+#endif
+			macro_gen_code(0);
+		end_go_through_syms()
         
     } else {
         /* generate big code generation switch */
@@ -1738,20 +2294,18 @@
 "    for(;;) {\n"
 "        switch(*opc_ptr++) {\n"
 );
-
-        for(i = 0, sym = symtab; i < nb_syms; i++, sym++) {
-            const char *name;
-            name = get_sym_name(sym);
-            if (strstart(name, OP_PREFIX, NULL)) {
+		begin_go_through_syms(symtab, nb_syms, sym, i)
 #if 0
-                printf("%4d: %s pos=0x%08x len=%d\n", 
-                       i, name, sym->st_value, sym->st_size);
+			printf("%4d: %s pos=0x%08x len=%d\n", 
+			i, name, sym->st_value, sym->st_size);
 #endif
-                if (sym->st_shndx != text_shndx)
-                    error("invalid section for opcode (0x%x)", sym->st_shndx);
-                gen_code(name, sym->st_value, sym->st_size, outfile, 1);
-            }
-        }
+#if defined(CONFIG_FORMAT_ELF) || defined(CONFIG_FORMAT_COFF)
+			if (sym->st_shndx != text_shndx)
+				error("invalid section for opcode (0x%x)", sym->st_shndx);
+#endif
+			macro_gen_code(1);
+		end_go_through_syms()
+
 
 fprintf(outfile,
 "        case INDEX_op_nop:\n"
Index: exec-all.h
===================================================================
RCS file: /cvsroot/qemu/qemu/exec-all.h,v
retrieving revision 1.19
diff -u -r1.19 exec-all.h
--- exec-all.h	3 Jun 2004 14:01:42 -0000	1.19
+++ exec-all.h	29 Jun 2004 17:37:25 -0000
@@ -303,16 +303,30 @@
 #define offsetof(type, field) ((size_t) &((type *)0)->field)
 #endif
 
+#ifdef _WIN32
+#define ASM_DATA_SECTION ".section \".data\"\n"
+#define ASM_PREVIOUS_SECTION ".section .text\n"
+#elif __APPLE__
+#define ASM_DATA_SECTION ".data\n"
+#define ASM_PREVIOUS_SECTION ".text\n"
+#define ASM_NAME(x) "_" #x
+#else
+#define ASM_DATA_SECTION ".section \".data\"\n"
+#define ASM_PREVIOUS_SECTION ".previous\n"
+#define ASM_NAME(x) stringify(x)
+#endif
+
+
 #if defined(__powerpc__)
 
 /* we patch the jump instruction directly */
 #define JUMP_TB(opname, tbparam, n, eip)\
 do {\
-    asm volatile (".section \".data\"\n"\
-		  "__op_label" #n "." stringify(opname) ":\n"\
+    asm volatile (ASM_DATA_SECTION\
+		  ASM_NAME(__op_label) #n "." ASM_NAME(opname) ":\n"\
 		  ".long 1f\n"\
-		  ".previous\n"\
-                  "b __op_jmp" #n "\n"\
+		  ASM_PREVIOUS_SECTION\
+                  "b " ASM_NAME(__op_jmp) #n "\n"\
 		  "1:\n");\
     T0 = (long)(tbparam) + (n);\
     EIP = eip;\
@@ -321,17 +335,11 @@
 
 #define JUMP_TB2(opname, tbparam, n)\
 do {\
-    asm volatile ("b __op_jmp" #n "\n");\
+    asm volatile ("b " ASM_NAME(__op_jmp) #n "\n");\
 } while (0)
 
 #elif defined(__i386__) && defined(USE_DIRECT_JUMP)
 
-#ifdef _WIN32
-#define ASM_PREVIOUS_SECTION ".section .text\n"
-#else
-#define ASM_PREVIOUS_SECTION ".previous\n"
-#endif
-
 /* we patch the jump instruction directly */
 #define JUMP_TB(opname, tbparam, n, eip)\
 do {\
@@ -384,11 +392,11 @@
 {
     int ret;
     __asm__ __volatile__ (
-                          "0:    lwarx %0,0,%1 ;"
-                          "      xor. %0,%3,%0;"
-                          "      bne 1f;"
-                          "      stwcx. %2,0,%1;"
-                          "      bne- 0b;"
+                          "0:    lwarx %0,0,%1\n"
+                          "      xor. %0,%3,%0\n"
+                          "      bne 1f\n"
+                          "      stwcx. %2,0,%1\n"
+                          "      bne- 0b\n"
                           "1:    "
                           : "=&r" (ret)
                           : "r" (p), "r" (1), "r" (0)
Index: exec.c
===================================================================
RCS file: /cvsroot/qemu/qemu/exec.c,v
retrieving revision 1.43
diff -u -r1.43 exec.c
--- exec.c	22 Jun 2004 18:48:46 -0000	1.43
+++ exec.c	29 Jun 2004 17:37:25 -0000
@@ -100,10 +100,10 @@
 
 static void io_mem_init(void);
 
-unsigned long real_host_page_size;
-unsigned long host_page_bits;
-unsigned long host_page_size;
-unsigned long host_page_mask;
+unsigned long qemu_real_host_page_size;
+unsigned long qemu_host_page_bits;
+unsigned long qemu_host_page_size;
+unsigned long qemu_host_page_mask;
 
 /* XXX: for system emulation, it could just be an array */
 static PageDesc *l1_map[L1_SIZE];
@@ -127,21 +127,21 @@
 
 static void page_init(void)
 {
-    /* NOTE: we can always suppose that host_page_size >=
+    /* NOTE: we can always suppose that qemu_host_page_size >=
        TARGET_PAGE_SIZE */
 #ifdef _WIN32
-    real_host_page_size = 4096;
+    qemu_real_host_page_size = 4096;
 #else
-    real_host_page_size = getpagesize();
+    qemu_real_host_page_size = getpagesize();
 #endif
-    if (host_page_size == 0)
-        host_page_size = real_host_page_size;
-    if (host_page_size < TARGET_PAGE_SIZE)
-        host_page_size = TARGET_PAGE_SIZE;
-    host_page_bits = 0;
-    while ((1 << host_page_bits) < host_page_size)
-        host_page_bits++;
-    host_page_mask = ~(host_page_size - 1);
+    if (qemu_host_page_size == 0)
+        qemu_host_page_size = qemu_real_host_page_size;
+    if (qemu_host_page_size < TARGET_PAGE_SIZE)
+        qemu_host_page_size = TARGET_PAGE_SIZE;
+    qemu_host_page_bits = 0;
+    while ((1 << qemu_host_page_bits) < qemu_host_page_size)
+        qemu_host_page_bits++;
+    qemu_host_page_mask = ~(qemu_host_page_size - 1);
 #if !defined(CONFIG_USER_ONLY)
     virt_valid_tag = 1;
 #endif
@@ -831,12 +831,12 @@
 
         /* force the host page as non writable (writes will have a
            page fault + mprotect overhead) */
-        host_start = page_addr & host_page_mask;
-        host_end = host_start + host_page_size;
+        host_start = page_addr & qemu_host_page_mask;
+        host_end = host_start + qemu_host_page_size;
         prot = 0;
         for(addr = host_start; addr < host_end; addr += TARGET_PAGE_SIZE)
             prot |= page_get_flags(addr);
-        mprotect((void *)host_start, host_page_size, 
+        mprotect((void *)host_start, qemu_host_page_size, 
                  (prot & PAGE_BITS) & ~PAGE_WRITE);
 #ifdef DEBUG_TB_INVALIDATE
         printf("protecting code page: 0x%08lx\n", 
@@ -1737,12 +1737,12 @@
     PageDesc *p, *p1;
     unsigned long host_start, host_end, addr;
 
-    host_start = address & host_page_mask;
+    host_start = address & qemu_host_page_mask;
     page_index = host_start >> TARGET_PAGE_BITS;
     p1 = page_find(page_index);
     if (!p1)
         return 0;
-    host_end = host_start + host_page_size;
+    host_end = host_start + qemu_host_page_size;
     p = p1;
     prot = 0;
     for(addr = host_start;addr < host_end; addr += TARGET_PAGE_SIZE) {
@@ -1754,7 +1754,7 @@
     if (prot & PAGE_WRITE_ORG) {
         pindex = (address - host_start) >> TARGET_PAGE_BITS;
         if (!(p1[pindex].flags & PAGE_WRITE)) {
-            mprotect((void *)host_start, host_page_size, 
+            mprotect((void *)host_start, qemu_host_page_size, 
                      (prot & PAGE_BITS) | PAGE_WRITE);
             p1[pindex].flags |= PAGE_WRITE;
             /* and since the content will be modified, we must invalidate
Index: oss.c
===================================================================
RCS file: /cvsroot/qemu/qemu/oss.c,v
retrieving revision 1.4
diff -u -r1.4 oss.c
--- oss.c	7 Jun 2004 20:58:31 -0000	1.4
+++ oss.c	29 Jun 2004 17:37:25 -0000
@@ -23,7 +23,7 @@
  */
 #include "vl.h"
 
-#ifndef _WIN32
+#if !defined(_WIN32) && !defined(__APPLE__)
 #include <ctype.h>
 #include <fcntl.h>
 #include <errno.h>
Index: vl.c
===================================================================
RCS file: /cvsroot/qemu/qemu/vl.c,v
retrieving revision 1.86
diff -u -r1.86 vl.c
--- vl.c	25 Jun 2004 17:06:27 -0000	1.86
+++ vl.c	29 Jun 2004 17:37:27 -0000
@@ -40,7 +40,9 @@
 #include <sys/socket.h>
 #ifdef _BSD
 #include <sys/stat.h>
+# ifndef __APPLE__
 #include <libutil.h>
+# endif
 #else
 #include <linux/if.h>
 #include <linux/if_tun.h>
@@ -50,6 +52,8 @@
 #endif
 #endif
 
+#include <SDL/SDL.h>
+
 #if defined(CONFIG_SLIRP)
 #include "libslirp.h"
 #endif
@@ -80,7 +84,7 @@
 
 #include "exec-all.h"
 
-//#define DO_TB_FLUSH
+#define DO_TB_FLUSH
 
 #define DEFAULT_NETWORK_SCRIPT "/etc/qemu-ifup"
 
@@ -825,7 +829,7 @@
     }
 }
 
-#ifndef _WIN32
+#if !defined(_WIN32)
 
 #if defined(__linux__)
 
@@ -908,7 +912,7 @@
         /* we probe the tick duration of the kernel to inform the user if
            the emulated kernel requested a too high timer frequency */
         getitimer(ITIMER_REAL, &itv);
-
+#if defined(__linux__)
         if (itv.it_interval.tv_usec > 1000) {
             /* try to use /dev/rtc to have a faster timer */
             if (start_rtc_timer() < 0)
@@ -924,7 +928,9 @@
             sigaction(SIGIO, &act, NULL);
             fcntl(rtc_fd, F_SETFL, O_ASYNC);
             fcntl(rtc_fd, F_SETOWN, getpid());
-        } else {
+        } else
+#endif
+		{
         use_itimer:
             pit_min_timer_count = ((uint64_t)itv.it_interval.tv_usec * 
                                    PIT_FREQ) / 1000000;
Index: hw/cirrus_vga.c
===================================================================
RCS file: /cvsroot/qemu/qemu/hw/cirrus_vga.c,v
retrieving revision 1.11
diff -u -r1.11 cirrus_vga.c
--- hw/cirrus_vga.c	21 Jun 2004 19:42:46 -0000	1.11
+++ hw/cirrus_vga.c	29 Jun 2004 17:37:30 -0000
@@ -36,8 +36,8 @@
  *    - optimize bitblt functions
  */
 
-//#define DEBUG_CIRRUS
-//#define DEBUG_BITBLT
+#define DEBUG_CIRRUS
+#define DEBUG_BITBLT
 
 /***************************************
  *
Index: hw/fdc.c
===================================================================
RCS file: /cvsroot/qemu/qemu/hw/fdc.c,v
retrieving revision 1.11
diff -u -r1.11 fdc.c
--- hw/fdc.c	12 May 2004 22:07:40 -0000	1.11
+++ hw/fdc.c	29 Jun 2004 17:37:31 -0000
@@ -25,7 +25,7 @@
 
 /********************************************************/
 /* debug Floppy devices */
-//#define DEBUG_FLOPPY
+#define DEBUG_FLOPPY
 
 #ifdef DEBUG_FLOPPY
 #define FLOPPY_DPRINTF(fmt, args...) \
Index: hw/pc.c
===================================================================
RCS file: /cvsroot/qemu/qemu/hw/pc.c,v
retrieving revision 1.24
diff -u -r1.24 pc.c
--- hw/pc.c	21 Jun 2004 19:42:46 -0000	1.24
+++ hw/pc.c	29 Jun 2004 17:37:33 -0000
@@ -24,7 +24,7 @@
 #include "vl.h"
 
 /* output Bochs bios info messages */
-//#define DEBUG_BIOS
+#define DEBUG_BIOS
 
 #define BIOS_FILENAME "bios.bin"
 #define VGABIOS_FILENAME "vgabios.bin"
Index: linux-user/elfload.c
===================================================================
RCS file: /cvsroot/qemu/qemu/linux-user/elfload.c,v
retrieving revision 1.22
diff -u -r1.22 elfload.c
--- linux-user/elfload.c	19 Jun 2004 17:23:13 -0000	1.22
+++ linux-user/elfload.c	29 Jun 2004 17:37:34 -0000
@@ -13,6 +13,16 @@
 #include "qemu.h"
 #include "disas.h"
 
+/* this flag is uneffective under linux too, should be deleted */
+#ifndef MAP_DENYWRITE
+#define MAP_DENYWRITE 0
+#endif
+
+/* should probably go in elf.h */
+#ifndef ELIBBAD
+#define ELIBBAD 80
+#endif
+
 #ifdef TARGET_I386
 
 #define ELF_START_MMAP 0x80000000
@@ -332,7 +342,7 @@
     /* User-space version of kernel get_free_page.  Returns a page-aligned
      * page-sized chunk of memory.
      */
-    retval = (void *)target_mmap(0, host_page_size, PROT_READ|PROT_WRITE, 
+    retval = (void *)target_mmap(0, qemu_host_page_size, PROT_READ|PROT_WRITE, 
                                  MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
 
     if((long)retval == -1) {
@@ -346,7 +356,7 @@
 
 static void free_page(void * pageaddr)
 {
-    target_munmap((unsigned long)pageaddr, host_page_size);
+    target_munmap((unsigned long)pageaddr, qemu_host_page_size);
 }
 
 /*
@@ -502,7 +512,7 @@
     if (size < MAX_ARG_PAGES*TARGET_PAGE_SIZE)
         size = MAX_ARG_PAGES*TARGET_PAGE_SIZE;
     error = target_mmap(0, 
-                        size + host_page_size,
+                        size + qemu_host_page_size,
                         PROT_READ | PROT_WRITE,
                         MAP_PRIVATE | MAP_ANONYMOUS,
                         -1, 0);
@@ -511,7 +521,7 @@
         exit(-1);
     }
     /* we reserve one extra page at the top of the stack as guard */
-    target_mprotect(error + size, host_page_size, PROT_NONE);
+    target_mprotect(error + size, qemu_host_page_size, PROT_NONE);
 
     stack_base = error + size - MAX_ARG_PAGES*TARGET_PAGE_SIZE;
     p += stack_base;
@@ -562,10 +572,10 @@
            of the file may not be mapped. A better fix would be to
            patch target_mmap(), but it is more complicated as the file
            size must be known */
-        if (real_host_page_size < host_page_size) {
+        if (qemu_real_host_page_size < qemu_host_page_size) {
             unsigned long end_addr, end_addr1;
-            end_addr1 = (elf_bss + real_host_page_size - 1) & 
-                ~(real_host_page_size - 1);
+            end_addr1 = (elf_bss + qemu_real_host_page_size - 1) & 
+                ~(qemu_real_host_page_size - 1);
             end_addr = HOST_PAGE_ALIGN(elf_bss);
             if (end_addr1 < end_addr) {
                 mmap((void *)end_addr1, end_addr - end_addr1,
@@ -574,9 +584,9 @@
             }
         }
 
-        nbyte = elf_bss & (host_page_size-1);
+        nbyte = elf_bss & (qemu_host_page_size-1);
         if (nbyte) {
-	    nbyte = host_page_size - nbyte;
+	    nbyte = qemu_host_page_size - nbyte;
 	    fpnt = (char *) elf_bss;
 	    do {
 		*fpnt++ = 0;
@@ -811,7 +821,7 @@
 	 * bss page.
 	 */
 	padzero(elf_bss);
-	elf_bss = TARGET_ELF_PAGESTART(elf_bss + host_page_size - 1); /* What we have \
mapped so far */ +	elf_bss = TARGET_ELF_PAGESTART(elf_bss + qemu_host_page_size - 1); \
/* What we have mapped so far */  
 	/* Map the last of the bss segment */
 	if (last_bss > elf_bss) {
@@ -1252,7 +1262,7 @@
 	       and some applications "depend" upon this behavior.
 	       Since we do not have the power to recompile these, we
 	       emulate the SVr4 behavior.  Sigh.  */
-	    mapped_addr = target_mmap(0, host_page_size, PROT_READ | PROT_EXEC,
+	    mapped_addr = target_mmap(0, qemu_host_page_size, PROT_READ | PROT_EXEC,
                                       MAP_FIXED | MAP_PRIVATE, -1, 0);
     }
 
Index: linux-user/main.c
===================================================================
RCS file: /cvsroot/qemu/qemu/linux-user/main.c,v
retrieving revision 1.51
diff -u -r1.51 main.c
--- linux-user/main.c	21 May 2004 12:59:18 -0000	1.51
+++ linux-user/main.c	29 Jun 2004 17:37:35 -0000
@@ -28,6 +28,11 @@
 
 #define DEBUG_LOGFILE "/tmp/qemu.log"
 
+#ifdef __APPLE__
+#include <crt_externs.h>
+# define environ  (*_NSGetEnviron())
+#endif
+
 static const char *interp_prefix = CONFIG_QEMU_PREFIX;
 
 #if defined(__i386__) && !defined(CONFIG_STATIC)
@@ -977,9 +982,9 @@
         } else if (!strcmp(r, "L")) {
             interp_prefix = argv[optind++];
         } else if (!strcmp(r, "p")) {
-            host_page_size = atoi(argv[optind++]);
-            if (host_page_size == 0 ||
-                (host_page_size & (host_page_size - 1)) != 0) {
+            qemu_host_page_size = atoi(argv[optind++]);
+            if (qemu_host_page_size == 0 ||
+                (qemu_host_page_size & (qemu_host_page_size - 1)) != 0) {
                 fprintf(stderr, "page size must be a power of two\n");
                 exit(1);
             }
@@ -1007,7 +1012,7 @@
     init_paths(interp_prefix);
 
     /* NOTE: we need to init the CPU at this stage to get the
-       host_page_size */
+       qemu_host_page_size */
     env = cpu_init();
     
     if (elf_exec(filename, argv+optind, environ, regs, info) != 0) {
Index: linux-user/syscall.c
===================================================================
RCS file: /cvsroot/qemu/qemu/linux-user/syscall.c,v
retrieving revision 1.50
diff -u -r1.50 syscall.c
--- linux-user/syscall.c	19 Jun 2004 16:59:03 -0000	1.50
+++ linux-user/syscall.c	29 Jun 2004 17:37:46 -0000
@@ -22,7 +22,9 @@
 #include <stdarg.h>
 #include <string.h>
 #include <elf.h>
+#ifndef __APPLE__
 #include <endian.h>
+#endif
 #include <errno.h>
 #include <unistd.h>
 #include <fcntl.h>
@@ -34,10 +36,11 @@
 #include <sys/mount.h>
 #include <sys/resource.h>
 #include <sys/mman.h>
+#ifndef __APPLE__
 #include <sys/swap.h>
+#endif
 #include <signal.h>
 #include <sched.h>
-#include <sys/socket.h>
 #include <sys/uio.h>
 #include <sys/poll.h>
 #include <sys/times.h>
@@ -45,6 +48,7 @@
 #include <utime.h>
 #include <sys/sysinfo.h>
 //#include <sys/user.h>
+#include <sys/socket.h>
 #include <netinet/ip.h>
 #include <netinet/tcp.h>
 
@@ -55,6 +59,7 @@
 #define tchars host_tchars /* same as target */
 #define ltchars host_ltchars /* same as target */
 
+#ifndef __APPLE__
 #include <linux/termios.h>
 #include <linux/unistd.h>
 #include <linux/utsname.h>
@@ -63,6 +68,7 @@
 #include <linux/soundcard.h>
 #include <linux/dirent.h>
 #include <linux/kd.h>
+#endif
 
 #include "qemu.h"
 
Index: slirp/slirp.h
===================================================================
RCS file: /cvsroot/qemu/qemu/slirp/slirp.h,v
retrieving revision 1.3
diff -u -r1.3 slirp.h
--- slirp/slirp.h	3 Jun 2004 12:53:17 -0000	1.3
+++ slirp/slirp.h	29 Jun 2004 17:37:46 -0000
@@ -127,6 +127,10 @@
 # define WANT_SYS_TERMIOS_H
 #endif
 
+#ifdef __APPLE__
+#define HAVE_TERMIOS_H
+#endif
+
 #ifdef WANT_SYS_TERMIOS_H
 # ifndef INCLUDED_TERMIOS_H
 #  ifdef HAVE_TERMIOS_H
Index: slirp/socket.c
===================================================================
RCS file: /cvsroot/qemu/qemu/slirp/socket.c,v
retrieving revision 1.1
diff -u -r1.1 socket.c
--- slirp/socket.c	22 Apr 2004 00:10:47 -0000	1.1
+++ slirp/socket.c	29 Jun 2004 17:37:46 -0000
@@ -369,6 +369,16 @@
 	return nn;
 }
 
+#ifdef __APPLE__
+void
+sorecvfrom(so)
+	struct socket *so;
+{
+	DEBUG_CALL("sorecvfrom");
+	printf("sorecvfrom not supported");
+	exit(0x123);
+}
+#else
 /*
  * recvfrom() a UDP socket
  */
@@ -468,7 +478,7 @@
 	  } /* rx error */
 	} /* if ping packet */
 }
-
+#endif
 /*
  * sendto() a socket
  */
Index: target-i386/op.c
===================================================================
RCS file: /cvsroot/qemu/qemu/target-i386/op.c,v
retrieving revision 1.20
diff -u -r1.20 op.c
--- target-i386/op.c	25 Jun 2004 14:58:58 -0000	1.20
+++ target-i386/op.c	29 Jun 2004 17:37:48 -0000
@@ -1955,7 +1955,7 @@
     int rnd_type;
     env->fpuc = lduw((void *)A0);
     /* set rounding mode */
-#ifdef _BSD
+#if defined(_BSD) && !defined(__APPLE__)
     switch(env->fpuc & RC_MASK) {
     default:
     case RC_NEAR:
Index: target-ppc/op_helper.c
===================================================================
RCS file: /cvsroot/qemu/qemu/target-ppc/op_helper.c,v
retrieving revision 1.7
diff -u -r1.7 op_helper.c
--- target-ppc/op_helper.c	23 May 2004 22:18:12 -0000	1.7
+++ target-ppc/op_helper.c	29 Jun 2004 17:37:54 -0000
@@ -464,10 +464,17 @@
 
 /*****************************************************************************/
 /* Special helpers for debug */
+#ifdef __APPLE__
+static FILE *stdout;
+#else
 extern FILE *stdout;
+#endif
 
 void dump_state (void)
 {
+#ifdef __APPLE__
+	stdout = open("/dev/stdout", 777);
+#endif
     cpu_ppc_dump_state(env, stdout, 0);
 }
 
Index: target-ppc/translate.c
===================================================================
RCS file: /cvsroot/qemu/qemu/target-ppc/translate.c,v
retrieving revision 1.18
diff -u -r1.18 translate.c
--- target-ppc/translate.c	22 Jun 2004 10:56:33 -0000	1.18
+++ target-ppc/translate.c	29 Jun 2004 17:37:56 -0000
@@ -277,7 +277,7 @@
 }
 
 #define GEN_OPCODE(name, op1, op2, op3, invl, _typ)                           \
-__attribute__ ((section(".opcodes"), unused, aligned (8) ))                   \
+__attribute__ ((section("__TEXT,.opcodes"), unused, aligned (8) ))                   \
\  static opcode_t opc_##name = {                                                \
     .opc1 = op1,                                                              \
     .opc2 = op2,                                                              \
@@ -290,7 +290,7 @@
 }
 
 #define GEN_OPCODE_MARK(name)                                                 \
-__attribute__ ((section(".opcodes"), unused, aligned (8) ))                   \
+__attribute__ ((section("__TEXT,.opcodes"), unused, aligned (8) ))                   \
\  static opcode_t opc_##name = {                                                \
     .opc1 = 0xFF,                                                             \
     .opc2 = 0xFF,                                                             \



Pierre

_______________________________________________
Qemu-devel mailing list
Qemu-devel@nongnu.org
http://lists.nongnu.org/mailman/listinfo/qemu-devel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic