]> Git Repo - qemu.git/blobdiff - vl.c
allow '-nics 0'
[qemu.git] / vl.c
diff --git a/vl.c b/vl.c
index 84e8698897b51c1d6473660370a93a4ff3905d0f..18f957dccf438f5f52498f125483b7ac3475a881 100644 (file)
--- a/vl.c
+++ b/vl.c
 #include <fcntl.h>
 #include <signal.h>
 #include <time.h>
-#include <malloc.h>
 #include <errno.h>
 #include <sys/time.h>
 
 #ifndef _WIN32
 #include <sys/times.h>
 #include <sys/wait.h>
-#include <pty.h>
 #include <termios.h>
 #include <sys/poll.h>
 #include <sys/mman.h>
 #include <sys/ioctl.h>
 #include <sys/socket.h>
+#ifdef _BSD
+#include <sys/stat.h>
+#include <libutil.h>
+#else
 #include <linux/if.h>
 #include <linux/if_tun.h>
+#include <pty.h>
+#include <malloc.h>
+#include <linux/rtc.h>
+#endif
+#endif
+
+#if defined(CONFIG_SLIRP)
+#include "libslirp.h"
 #endif
 
 #ifdef _WIN32
+#include <malloc.h>
 #include <sys/timeb.h>
 #include <windows.h>
 #define getopt_long_only getopt_long
 #endif
 
 #ifdef CONFIG_SDL
+#if defined(__linux__)
 /* SDL use the pthreads and they modify sigaction. We don't
    want that. */
-#if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2)
+#if (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2))
 extern void __libc_sigaction();
 #define sigaction(sig, act, oact) __libc_sigaction(sig, act, oact)
 #else
 extern void __sigaction();
 #define sigaction(sig, act, oact) __sigaction(sig, act, oact)
 #endif
+#endif /* __linux__ */
 #endif /* CONFIG_SDL */
 
 #include "disas.h"
 
 #include "exec-all.h"
 
+//#define DO_TB_FLUSH
+
 #define DEFAULT_NETWORK_SCRIPT "/etc/qemu-ifup"
 
 //#define DEBUG_UNUSED_IOPORT
+//#define DEBUG_IOPORT
 
 #if !defined(CONFIG_SOFTMMU)
 #define PHYS_RAM_MAX_SIZE (256 * 1024 * 1024)
@@ -105,9 +121,12 @@ NetDriverState nd_table[MAX_NICS];
 SerialState *serial_console;
 QEMUTimer *gui_timer;
 int vm_running;
+int audio_enabled = 0;
 
 /***********************************************************/
-/* x86 io ports */
+/* x86 ISA bus support */
+
+target_phys_addr_t isa_mem_base = 0;
 
 uint32_t default_ioport_readb(void *opaque, uint32_t address)
 {
@@ -128,15 +147,17 @@ void default_ioport_writeb(void *opaque, uint32_t address, uint32_t data)
 uint32_t default_ioport_readw(void *opaque, uint32_t address)
 {
     uint32_t data;
-    data = ioport_read_table[0][address & (MAX_IOPORTS - 1)](opaque, address);
-    data |= ioport_read_table[0][(address + 1) & (MAX_IOPORTS - 1)](opaque, address + 1) << 8;
+    data = ioport_read_table[0][address](ioport_opaque[address], address);
+    address = (address + 1) & (MAX_IOPORTS - 1);
+    data |= ioport_read_table[0][address](ioport_opaque[address], address) << 8;
     return data;
 }
 
 void default_ioport_writew(void *opaque, uint32_t address, uint32_t data)
 {
-    ioport_write_table[0][address & (MAX_IOPORTS - 1)](opaque, address, data & 0xff);
-    ioport_write_table[0][(address + 1) & (MAX_IOPORTS - 1)](opaque, address + 1, (data >> 8) & 0xff);
+    ioport_write_table[0][address](ioport_opaque[address], address, data & 0xff);
+    address = (address + 1) & (MAX_IOPORTS - 1);
+    ioport_write_table[0][address](ioport_opaque[address], address, (data >> 8) & 0xff);
 }
 
 uint32_t default_ioport_readl(void *opaque, uint32_t address)
@@ -264,38 +285,62 @@ int load_image(const char *filename, uint8_t *addr)
 
 void cpu_outb(CPUState *env, int addr, int val)
 {
-    addr &= (MAX_IOPORTS - 1);
+#ifdef DEBUG_IOPORT
+    if (loglevel & CPU_LOG_IOPORT)
+        fprintf(logfile, "outb: %04x %02x\n", addr, val);
+#endif    
     ioport_write_table[0][addr](ioport_opaque[addr], addr, val);
 }
 
 void cpu_outw(CPUState *env, int addr, int val)
 {
-    addr &= (MAX_IOPORTS - 1);
+#ifdef DEBUG_IOPORT
+    if (loglevel & CPU_LOG_IOPORT)
+        fprintf(logfile, "outw: %04x %04x\n", addr, val);
+#endif    
     ioport_write_table[1][addr](ioport_opaque[addr], addr, val);
 }
 
 void cpu_outl(CPUState *env, int addr, int val)
 {
-    addr &= (MAX_IOPORTS - 1);
+#ifdef DEBUG_IOPORT
+    if (loglevel & CPU_LOG_IOPORT)
+        fprintf(logfile, "outl: %04x %08x\n", addr, val);
+#endif
     ioport_write_table[2][addr](ioport_opaque[addr], addr, val);
 }
 
 int cpu_inb(CPUState *env, int addr)
 {
-    addr &= (MAX_IOPORTS - 1);
-    return ioport_read_table[0][addr](ioport_opaque[addr], addr);
+    int val;
+    val = ioport_read_table[0][addr](ioport_opaque[addr], addr);
+#ifdef DEBUG_IOPORT
+    if (loglevel & CPU_LOG_IOPORT)
+        fprintf(logfile, "inb : %04x %02x\n", addr, val);
+#endif
+    return val;
 }
 
 int cpu_inw(CPUState *env, int addr)
 {
-    addr &= (MAX_IOPORTS - 1);
-    return ioport_read_table[1][addr](ioport_opaque[addr], addr);
+    int val;
+    val = ioport_read_table[1][addr](ioport_opaque[addr], addr);
+#ifdef DEBUG_IOPORT
+    if (loglevel & CPU_LOG_IOPORT)
+        fprintf(logfile, "inw : %04x %04x\n", addr, val);
+#endif
+    return val;
 }
 
 int cpu_inl(CPUState *env, int addr)
 {
-    addr &= (MAX_IOPORTS - 1);
-    return ioport_read_table[2][addr](ioport_opaque[addr], addr);
+    int val;
+    val = ioport_read_table[2][addr](ioport_opaque[addr], addr);
+#ifdef DEBUG_IOPORT
+    if (loglevel & CPU_LOG_IOPORT)
+        fprintf(logfile, "inl : %04x %08x\n", addr, val);
+#endif
+    return val;
 }
 
 /***********************************************************/
@@ -356,6 +401,19 @@ int64_t cpu_get_real_ticks(void)
     return val;
 }
 
+#elif defined(__x86_64__)
+
+int64_t cpu_get_real_ticks(void)
+{
+    uint32_t low,high;
+    int64_t val;
+    asm volatile("rdtsc" : "=a" (low), "=d" (high));
+    val = high;
+    val <<= 32;
+    val |= low;
+    return val;
+}
+
 #else
 #error unsupported CPU
 #endif
@@ -583,11 +641,17 @@ int64_t qemu_get_clock(QEMUClock *clock)
 #ifdef _WIN32
         return GetTickCount();
 #else
-        /* XXX: portability among Linux hosts */
-        if (timer_freq == 100) {
-            return times(NULL) * 10;
-        } else {
-            return ((int64_t)times(NULL) * 1000) / timer_freq;
+        {
+            struct tms tp;
+
+            /* Note that using gettimeofday() is not a good solution
+               for timers because its value change when the date is
+               modified. */
+            if (timer_freq == 100) {
+                return times(&tp) * 10;
+            } else {
+                return ((int64_t)times(&tp) * 1000) / timer_freq;
+            }
         }
 #endif
     default:
@@ -658,6 +722,34 @@ static void host_alarm_handler(int host_signum)
     }
 }
 
+#ifndef _WIN32
+
+#define RTC_FREQ 1024
+
+static int rtc_fd;
+    
+static int start_rtc_timer(void)
+{
+    rtc_fd = open("/dev/rtc", O_RDONLY);
+    if (rtc_fd < 0)
+        return -1;
+    if (ioctl(rtc_fd, RTC_IRQP_SET, RTC_FREQ) < 0) {
+        fprintf(stderr, "Could not configure '/dev/rtc' to have a 1024 Hz timer. This is not a fatal\n"
+                "error, but for better emulation accuracy either use a 2.6 host Linux kernel or\n"
+                "type 'echo 1024 > /proc/sys/dev/rtc/max-user-freq' as root.\n");
+        goto fail;
+    }
+    if (ioctl(rtc_fd, RTC_PIE_ON, 0) < 0) {
+    fail:
+        close(rtc_fd);
+        return -1;
+    }
+    pit_min_timer_count = PIT_FREQ / RTC_FREQ;
+    return 0;
+}
+
+#endif
+
 static void init_timers(void)
 {
     rt_clock = qemu_new_clock(QEMU_TIMER_REALTIME);
@@ -693,7 +785,7 @@ static void init_timers(void)
 #endif
         act.sa_handler = host_alarm_handler;
         sigaction(SIGALRM, &act, NULL);
-        
+
         itv.it_interval.tv_sec = 0;
         itv.it_interval.tv_usec = 1000;
         itv.it_value.tv_sec = 0;
@@ -702,8 +794,27 @@ static void init_timers(void)
         /* 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);
-        pit_min_timer_count = ((uint64_t)itv.it_interval.tv_usec * PIT_FREQ) / 
-            1000000;
+
+        if (itv.it_interval.tv_usec > 1000) {
+            /* try to use /dev/rtc to have a faster timer */
+            if (start_rtc_timer() < 0)
+                goto use_itimer;
+            /* disable itimer */
+            itv.it_interval.tv_sec = 0;
+            itv.it_interval.tv_usec = 0;
+            itv.it_value.tv_sec = 0;
+            itv.it_value.tv_usec = 0;
+            setitimer(ITIMER_REAL, &itv, NULL);
+
+            /* use the RTC */
+            sigaction(SIGIO, &act, NULL);
+            fcntl(rtc_fd, F_SETFL, O_ASYNC);
+            fcntl(rtc_fd, F_SETOWN, getpid());
+        } else {
+        use_itimer:
+            pit_min_timer_count = ((uint64_t)itv.it_interval.tv_usec * 
+                                   PIT_FREQ) / 1000000;
+        }
     }
 #endif
 }
@@ -748,21 +859,142 @@ int serial_open_device(void)
 #endif
 
 /***********************************************************/
-/* Linux network device redirector */
+/* Linux network device redirectors */
 
-#ifdef _WIN32
+void hex_dump(FILE *f, const uint8_t *buf, int size)
+{
+    int len, i, j, c;
+
+    for(i=0;i<size;i+=16) {
+        len = size - i;
+        if (len > 16)
+            len = 16;
+        fprintf(f, "%08x ", i);
+        for(j=0;j<16;j++) {
+            if (j < len)
+                fprintf(f, " %02x", buf[i+j]);
+            else
+                fprintf(f, "   ");
+        }
+        fprintf(f, " ");
+        for(j=0;j<len;j++) {
+            c = buf[i+j];
+            if (c < ' ' || c > '~')
+                c = '.';
+            fprintf(f, "%c", c);
+        }
+        fprintf(f, "\n");
+    }
+}
+
+void qemu_send_packet(NetDriverState *nd, const uint8_t *buf, int size)
+{
+    nd->send_packet(nd, buf, size);
+}
 
-static int net_init(void)
+void qemu_add_read_packet(NetDriverState *nd, IOCanRWHandler *fd_can_read, 
+                          IOReadHandler *fd_read, void *opaque)
 {
+    nd->add_read_packet(nd, fd_can_read, fd_read, opaque);
+}
+
+/* dummy network adapter */
+
+static void dummy_send_packet(NetDriverState *nd, const uint8_t *buf, int size)
+{
+}
+
+static void dummy_add_read_packet(NetDriverState *nd, 
+                                  IOCanRWHandler *fd_can_read, 
+                                  IOReadHandler *fd_read, void *opaque)
+{
+}
+
+static int net_dummy_init(NetDriverState *nd)
+{
+    nd->send_packet = dummy_send_packet;
+    nd->add_read_packet = dummy_add_read_packet;
+    pstrcpy(nd->ifname, sizeof(nd->ifname), "dummy");
     return 0;
 }
 
-void net_send_packet(NetDriverState *nd, const uint8_t *buf, int size)
+#if defined(CONFIG_SLIRP)
+
+/* slirp network adapter */
+
+static void *slirp_fd_opaque;
+static IOCanRWHandler *slirp_fd_can_read;
+static IOReadHandler *slirp_fd_read;
+static int slirp_inited;
+
+int slirp_can_output(void)
 {
+    return slirp_fd_can_read(slirp_fd_opaque);
 }
 
-#else
+void slirp_output(const uint8_t *pkt, int pkt_len)
+{
+#if 0
+    printf("output:\n");
+    hex_dump(stdout, pkt, pkt_len);
+#endif
+    slirp_fd_read(slirp_fd_opaque, pkt, pkt_len);
+}
+
+static void slirp_send_packet(NetDriverState *nd, const uint8_t *buf, int size)
+{
+#if 0
+    printf("input:\n");
+    hex_dump(stdout, buf, size);
+#endif
+    slirp_input(buf, size);
+}
 
+static void slirp_add_read_packet(NetDriverState *nd, 
+                                  IOCanRWHandler *fd_can_read, 
+                                  IOReadHandler *fd_read, void *opaque)
+{
+    slirp_fd_opaque = opaque;
+    slirp_fd_can_read = fd_can_read;
+    slirp_fd_read = fd_read;
+}
+
+static int net_slirp_init(NetDriverState *nd)
+{
+    if (!slirp_inited) {
+        slirp_inited = 1;
+        slirp_init();
+    }
+    nd->send_packet = slirp_send_packet;
+    nd->add_read_packet = slirp_add_read_packet;
+    pstrcpy(nd->ifname, sizeof(nd->ifname), "slirp");
+    return 0;
+}
+
+#endif /* CONFIG_SLIRP */
+
+#if !defined(_WIN32)
+#ifdef _BSD
+static int tun_open(char *ifname, int ifname_size)
+{
+    int fd;
+    char *dev;
+    struct stat s;
+
+    fd = open("/dev/tap", O_RDWR);
+    if (fd < 0) {
+        fprintf(stderr, "warning: could not open /dev/tap: no virtual network emulation\n");
+        return -1;
+    }
+
+    fstat(fd, &s);
+    dev = devname(s.st_rdev, S_IFCHR);
+    pstrcpy(ifname, ifname_size, dev);
+
+    fcntl(fd, F_SETFL, O_NONBLOCK);
+    return fd;
+}
+#else
 static int tun_open(char *ifname, int ifname_size)
 {
     struct ifreq ifr;
@@ -787,61 +1019,63 @@ static int tun_open(char *ifname, int ifname_size)
     fcntl(fd, F_SETFL, O_NONBLOCK);
     return fd;
 }
+#endif
 
-static int net_init(void)
+static void tun_send_packet(NetDriverState *nd, const uint8_t *buf, int size)
 {
-    int pid, status, launch_script, i;
-    NetDriverState *nd;
-    char *args[MAX_NICS + 2];
+    write(nd->fd, buf, size);
+}
+
+static void tun_add_read_packet(NetDriverState *nd, 
+                                IOCanRWHandler *fd_can_read, 
+                                IOReadHandler *fd_read, void *opaque)
+{
+    qemu_add_fd_read_handler(nd->fd, fd_can_read, fd_read, opaque);
+}
+
+static int net_tun_init(NetDriverState *nd)
+{
+    int pid, status;
+    char *args[3];
     char **parg;
 
-    launch_script = 0;
-    for(i = 0; i < nb_nics; i++) {
-        nd = &nd_table[i];
-        if (nd->fd < 0) {
-            nd->fd = tun_open(nd->ifname, sizeof(nd->ifname));
-            if (nd->fd >= 0) 
-                launch_script = 1;
-        }
-    }
+    nd->fd = tun_open(nd->ifname, sizeof(nd->ifname));
+    if (nd->fd < 0)
+        return -1;
 
-    if (launch_script) {
-        /* try to launch network init script */
-        pid = fork();
-        if (pid >= 0) {
-            if (pid == 0) {
-                parg = args;
-                *parg++ = network_script;
-                for(i = 0; i < nb_nics; i++) {
-                    nd = &nd_table[i];
-                    if (nd->fd >= 0) {
-                        *parg++ = nd->ifname;
-                    }
-                }
-                *parg++ = NULL;
-                execv(network_script, args);
-                exit(1);
-            }
-            while (waitpid(pid, &status, 0) != pid);
-            if (!WIFEXITED(status) ||
-                WEXITSTATUS(status) != 0) {
-                fprintf(stderr, "%s: could not launch network script\n",
-                        network_script);
-            }
+    /* try to launch network init script */
+    pid = fork();
+    if (pid >= 0) {
+        if (pid == 0) {
+            parg = args;
+            *parg++ = network_script;
+            *parg++ = nd->ifname;
+            *parg++ = NULL;
+            execv(network_script, args);
+            exit(1);
+        }
+        while (waitpid(pid, &status, 0) != pid);
+        if (!WIFEXITED(status) ||
+            WEXITSTATUS(status) != 0) {
+            fprintf(stderr, "%s: could not launch network script\n",
+                    network_script);
         }
     }
+    nd->send_packet = tun_send_packet;
+    nd->add_read_packet = tun_add_read_packet;
     return 0;
 }
 
-void net_send_packet(NetDriverState *nd, const uint8_t *buf, int size)
+static int net_fd_init(NetDriverState *nd, int fd)
 {
-#ifdef DEBUG_NE2000
-    printf("NE2000: sending packet size=%d\n", size);
-#endif
-    write(nd->fd, buf, size);
+    nd->fd = fd;
+    nd->send_packet = tun_send_packet;
+    nd->add_read_packet = tun_add_read_packet;
+    pstrcpy(nd->ifname, sizeof(nd->ifname), "tunfd");
+    return 0;
 }
 
-#endif
+#endif /* !_WIN32 */
 
 /***********************************************************/
 /* dumb display */
@@ -1201,6 +1435,9 @@ int qemu_loadvm(const char *filename)
         goto the_end;
     }
     for(;;) {
+#if defined (DO_TB_FLUSH)
+        tb_flush(global_env);
+#endif
         len = qemu_get_byte(f);
         if (feof(f))
             break;
@@ -1380,6 +1617,15 @@ int cpu_load(QEMUFile *f, void *opaque, int version_id)
     return 0;
 }
 
+#elif defined(TARGET_PPC)
+void cpu_save(QEMUFile *f, void *opaque)
+{
+}
+
+int cpu_load(QEMUFile *f, void *opaque, int version_id)
+{
+    return 0;
+}
 #else
 
 #warning No CPU save/restore functions
@@ -1583,14 +1829,38 @@ int main_loop(void)
                 }
             }
         }
+
+#if defined(CONFIG_SLIRP)
+        /* XXX: merge with poll() */
+        if (slirp_inited) {
+            fd_set rfds, wfds, xfds;
+            int nfds;
+            struct timeval tv;
+
+            nfds = -1;
+            FD_ZERO(&rfds);
+            FD_ZERO(&wfds);
+            FD_ZERO(&xfds);
+            slirp_select_fill(&nfds, &rfds, &wfds, &xfds);
+            tv.tv_sec = 0;
+            tv.tv_usec = 0;
+            ret = select(nfds + 1, &rfds, &wfds, &xfds, &tv);
+            if (ret >= 0) {
+                slirp_select_poll(&rfds, &wfds, &xfds);
+            }
+        }
+#endif
+
 #endif
 
         if (vm_running) {
             qemu_run_timers(&active_timers[QEMU_TIMER_VIRTUAL], 
                             qemu_get_clock(vm_clock));
             
-            /* XXX: add explicit timer */
-            SB16_run();
+            if (audio_enabled) {
+                /* XXX: add explicit timer */
+                SB16_run();
+            }
             
             /* run dma transfers, if any */
             DMA_run();
@@ -1606,7 +1876,7 @@ int main_loop(void)
 
 void help(void)
 {
-    printf("QEMU PC emulator version " QEMU_VERSION ", Copyright (c) 2003 Fabrice Bellard\n"
+    printf("QEMU PC emulator version " QEMU_VERSION ", Copyright (c) 2003-2004 Fabrice Bellard\n"
            "usage: %s [options] [disk_image]\n"
            "\n"
            "'disk_image' is a raw hard image image for IDE hard disk 0\n"
@@ -1620,12 +1890,17 @@ void help(void)
           "-snapshot       write to temporary files instead of disk image files\n"
            "-m megs         set virtual RAM size to megs MB\n"
            "-nographic      disable graphical output and redirect serial I/Os to console\n"
+           "-enable-audio   enable audio support\n"
            "\n"
            "Network options:\n"
-           "-n script       set network init script [default=%s]\n"
-           "-nics n         simulate 'n' network interfaces [default=1]\n"
+           "-nics n         simulate 'n' network cards [default=1]\n"
            "-macaddr addr   set the mac address of the first interface\n"
-           "-tun-fd fd0[,...] use these fds as already opened tap/tun interfaces\n"
+           "-n script       set tap/tun network init script [default=%s]\n"
+           "-tun-fd fd      use this fd as already opened tap/tun interface\n"
+#ifdef CONFIG_SLIRP
+           "-user-net       use user mode network stack [default if no tap/tun script]\n"
+#endif
+           "-dummy-net      use dummy network stack\n"
            "\n"
            "Linux boot specific:\n"
            "-kernel bzImage use 'bzImage' as kernel image\n"
@@ -1681,6 +1956,9 @@ struct option long_options[] = {
     { "no-code-copy", 0, NULL, 0 },
     { "nics", 1, NULL, 0 },
     { "macaddr", 1, NULL, 0 },
+    { "user-net", 0, NULL, 0 },
+    { "dummy-net", 0, NULL, 0 },
+    { "enable-audio", 0, NULL, 0 },
     { NULL, 0, NULL, 0 },
 };
 
@@ -1693,6 +1971,10 @@ static uint8_t *signal_stack;
 
 #endif
 
+#define NET_IF_TUN   0
+#define NET_IF_USER  1
+#define NET_IF_DUMMY 2
+
 int main(int argc, char **argv)
 {
 #ifdef CONFIG_GDBSTUB
@@ -1706,8 +1988,10 @@ int main(int argc, char **argv)
     const char *kernel_filename, *kernel_cmdline;
     DisplayState *ds = &display_state;
     int cyls, heads, secs;
+    int start_emulation = 1;
     uint8_t macaddr[6];
-
+    int net_if_type, nb_tun_fds, tun_fds[MAX_NICS];
+    
 #if !defined(CONFIG_SOFTMMU)
     /* we never want that malloc() uses mmap() */
     mallopt(M_MMAP_THRESHOLD, 4096 * 1024);
@@ -1731,6 +2015,8 @@ int main(int argc, char **argv)
     has_cdrom = 1;
     cyls = heads = secs = 0;
 
+    nb_tun_fds = 0;
+    net_if_type = -1;
     nb_nics = 1;
     /* default mac address of the first network interface */
     macaddr[0] = 0x52;
@@ -1739,12 +2025,10 @@ int main(int argc, char **argv)
     macaddr[3] = 0x12;
     macaddr[4] = 0x34;
     macaddr[5] = 0x56;
-    
-    for(i = 0; i < MAX_NICS; i++) 
-        nd_table[i].fd = -1;
-    
+
+
     for(;;) {
-        c = getopt_long_only(argc, argv, "hm:d:n:sp:L:", long_options, &long_index);
+        c = getopt_long_only(argc, argv, "hm:d:n:sp:L:S", long_options, &long_index);
         if (c == -1)
             break;
         switch(c) {
@@ -1794,23 +2078,13 @@ int main(int argc, char **argv)
                 {
                     const char *p;
                     int fd;
-                    p = optarg;
-                    nb_nics = 0;
-                    for(;;) {
-                        fd = strtol(p, (char **)&p, 0);
-                        nd_table[nb_nics].fd = fd;
-                        snprintf(nd_table[nb_nics].ifname, 
-                                 sizeof(nd_table[nb_nics].ifname),
-                                 "fd%d", nb_nics);
-                        nb_nics++;
-                        if (*p == ',') {
-                            p++;
-                        } else if (*p != '\0') {
-                            fprintf(stderr, "qemu: invalid fd for network interface %d\n", nb_nics);
+                    if (nb_tun_fds < MAX_NICS) {
+                        fd = strtol(optarg, (char **)&p, 0);
+                        if (*p != '\0') {
+                            fprintf(stderr, "qemu: invalid fd for network interface %d\n", nb_tun_fds);
                             exit(1);
-                        } else {
-                            break;
                         }
+                        tun_fds[nb_tun_fds++] = fd;
                     }
                 }
                break;
@@ -1844,7 +2118,7 @@ int main(int argc, char **argv)
                 break;
             case 16:
                 nb_nics = atoi(optarg);
-                if (nb_nics < 1 || nb_nics > MAX_NICS) {
+                if (nb_nics < 0 || nb_nics > MAX_NICS) {
                     fprintf(stderr, "qemu: invalid number of network interfaces\n");
                     exit(1);
                 }
@@ -1870,6 +2144,15 @@ int main(int argc, char **argv)
                     }
                 }
                 break;
+            case 18:
+                net_if_type = NET_IF_USER;
+                break;
+            case 19:
+                net_if_type = NET_IF_DUMMY;
+                break;
+            case 20:
+                audio_enabled = 1;
+                break;
             }
             break;
         case 'h':
@@ -1915,6 +2198,9 @@ int main(int argc, char **argv)
         case 'L':
             bios_dir = optarg;
             break;
+       case 'S':
+           start_emulation = 0;
+           break;
         }
     }
 
@@ -1947,8 +2233,18 @@ int main(int argc, char **argv)
 #endif
 
     /* init host network redirectors */
-    for(i = 0; i < MAX_NICS; i++) {
+    if (net_if_type == -1) {
+        net_if_type = NET_IF_TUN;
+#if defined(CONFIG_SLIRP)
+        if (access(network_script, R_OK) < 0) {
+            net_if_type = NET_IF_USER;
+        }
+#endif
+    }
+
+    for(i = 0; i < nb_nics; i++) {
         NetDriverState *nd = &nd_table[i];
+        nd->index = i;
         /* init virtual mac address */
         nd->macaddr[0] = macaddr[0];
         nd->macaddr[1] = macaddr[1];
@@ -1956,14 +2252,39 @@ int main(int argc, char **argv)
         nd->macaddr[3] = macaddr[3];
         nd->macaddr[4] = macaddr[4];
         nd->macaddr[5] = macaddr[5] + i;
+        switch(net_if_type) {
+#if defined(CONFIG_SLIRP)
+        case NET_IF_USER:
+            net_slirp_init(nd);
+            break;
+#endif
+#if !defined(_WIN32)
+        case NET_IF_TUN:
+            if (i < nb_tun_fds) {
+                net_fd_init(nd, tun_fds[i]);
+            } else {
+                if (net_tun_init(nd) < 0)
+                    net_dummy_init(nd);
+            }
+            break;
+#endif
+        case NET_IF_DUMMY:
+        default:
+            net_dummy_init(nd);
+            break;
+        }
     }
-    net_init();
 
     /* init the memory */
     phys_ram_size = ram_size + vga_ram_size;
 
 #ifdef CONFIG_SOFTMMU
+#ifdef _BSD
+    /* mallocs are always aligned on BSD. */
+    phys_ram_base = malloc(phys_ram_size);
+#else
     phys_ram_base = memalign(TARGET_PAGE_SIZE, phys_ram_size);
+#endif
     if (!phys_ram_base) {
         fprintf(stderr, "Could not allocate physical memory\n");
         exit(1);
@@ -2040,7 +2361,7 @@ int main(int argc, char **argv)
             }
             if (fd_filename[i] != '\0') {
                 if (bdrv_open(fd_table[i], fd_filename[i], snapshot) < 0) {
-                    fprintf(stderr, "qemu: could not open floppy disk image '%s\n",
+                    fprintf(stderr, "qemu: could not open floppy disk image '%s'\n",
                             fd_filename[i]);
                     exit(1);
                 }
@@ -2121,7 +2442,9 @@ int main(int argc, char **argv)
             ds, fd_filename, snapshot,
             kernel_filename, kernel_cmdline, initrd_filename);
 #elif defined(TARGET_PPC)
-    ppc_init();
+    ppc_init(ram_size, vga_ram_size, boot_device,
+            ds, fd_filename, snapshot,
+            kernel_filename, kernel_cmdline, initrd_filename);
 #endif
 
     /* launched after the device init so that it can display or not a
@@ -2142,6 +2465,7 @@ int main(int argc, char **argv)
         }
     } else 
 #endif
+    if (start_emulation)
     {
         vm_start();
     }
This page took 0.042101 seconds and 4 git commands to generate.