PIIX4 SMBus host, EEPROM device emulation, by Ed Swierk.
[qemu] / vl.c
diff --git a/vl.c b/vl.c
index 7b3d880..daeec82 100644 (file)
--- a/vl.c
+++ b/vl.c
 /* XXX: use a two level table to limit memory usage */
 #define MAX_IOPORTS 65536
 
-#define DISK_OPTIONS_SIZE 256
-
 const char *bios_dir = CONFIG_QEMU_SHAREDIR;
 char phys_ram_file[1024];
 void *ioport_opaque[MAX_IOPORTS];
@@ -126,9 +124,6 @@ IOPortWriteFunc *ioport_write_table[3][MAX_IOPORTS];
 BlockDriverState *bs_table[MAX_DISKS + 1], *fd_table[MAX_FD];
 /* point to the block driver where the snapshots are managed */
 BlockDriverState *bs_snapshots;
-BlockDriverState *bs_scsi_table[MAX_SCSI_DISKS];
-SCSIDiskInfo scsi_disks_info[MAX_SCSI_DISKS];
-int scsi_hba_lsi; /* Count of scsi disks/cdrom using this lsi adapter */
 int vga_ram_size;
 int bios_size;
 static DisplayState display_state;
@@ -176,6 +171,8 @@ int no_reboot = 0;
 int daemonize = 0;
 const char *option_rom[MAX_OPTION_ROMS];
 int nb_option_roms;
+int semihosting_enabled = 0;
+int autostart = 1;
 
 /***********************************************************/
 /* x86 ISA bus support */
@@ -311,49 +308,6 @@ void isa_unassign_ioport(int start, int length)
 
 /***********************************************************/
 
-void pstrcpy(char *buf, int buf_size, const char *str)
-{
-    int c;
-    char *q = buf;
-
-    if (buf_size <= 0)
-        return;
-
-    for(;;) {
-        c = *str++;
-        if (c == 0 || q >= buf + buf_size - 1)
-            break;
-        *q++ = c;
-    }
-    *q = '\0';
-}
-
-/* strcat and truncate. */
-char *pstrcat(char *buf, int buf_size, const char *s)
-{
-    int len;
-    len = strlen(buf);
-    if (len < buf_size) 
-        pstrcpy(buf + len, buf_size - len, s);
-    return buf;
-}
-
-int strstart(const char *str, const char *val, const char **ptr)
-{
-    const char *p, *q;
-    p = str;
-    q = val;
-    while (*q != '\0') {
-        if (*p != *q)
-            return 0;
-        p++;
-        q++;
-    }
-    if (ptr)
-        *ptr = p;
-    return 1;
-}
-
 void cpu_outb(CPUState *env, int addr, int val)
 {
 #ifdef DEBUG_IOPORT
@@ -1165,6 +1119,29 @@ void quit_timers(void)
 /***********************************************************/
 /* character device */
 
+static void qemu_chr_event(CharDriverState *s, int event)
+{
+    if (!s->chr_event)
+        return;
+    s->chr_event(s->handler_opaque, event);
+}
+
+static void qemu_chr_reset_bh(void *opaque)
+{
+    CharDriverState *s = opaque;
+    qemu_chr_event(s, CHR_EVENT_RESET);
+    qemu_bh_delete(s->bh);
+    s->bh = NULL;
+}
+
+void qemu_chr_reset(CharDriverState *s)
+{
+    if (s->bh == NULL) {
+       s->bh = qemu_bh_new(qemu_chr_reset_bh, s);
+       qemu_bh_schedule(s->bh);
+    }
+}
+
 int qemu_chr_write(CharDriverState *s, const uint8_t *buf, int len)
 {
     return s->chr_write(s, buf, len);
@@ -1177,6 +1154,19 @@ int qemu_chr_ioctl(CharDriverState *s, int cmd, void *arg)
     return s->chr_ioctl(s, cmd, arg);
 }
 
+int qemu_chr_can_read(CharDriverState *s)
+{
+    if (!s->chr_can_read)
+        return 0;
+    return s->chr_can_read(s->handler_opaque);
+}
+
+void qemu_chr_read(CharDriverState *s, uint8_t *buf, int len)
+{
+    s->chr_read(s->handler_opaque, buf, len);
+}
+
+
 void qemu_chr_printf(CharDriverState *s, const char *fmt, ...)
 {
     char buf[4096];
@@ -1193,29 +1183,25 @@ void qemu_chr_send_event(CharDriverState *s, int event)
         s->chr_send_event(s, event);
 }
 
-void qemu_chr_add_read_handler(CharDriverState *s, 
-                               IOCanRWHandler *fd_can_read, 
-                               IOReadHandler *fd_read, void *opaque)
+void qemu_chr_add_handlers(CharDriverState *s, 
+                           IOCanRWHandler *fd_can_read, 
+                           IOReadHandler *fd_read,
+                           IOEventHandler *fd_event,
+                           void *opaque)
 {
-    s->chr_add_read_handler(s, fd_can_read, fd_read, opaque);
+    s->chr_can_read = fd_can_read;
+    s->chr_read = fd_read;
+    s->chr_event = fd_event;
+    s->handler_opaque = opaque;
+    if (s->chr_update_read_handler)
+        s->chr_update_read_handler(s);
 }
              
-void qemu_chr_add_event_handler(CharDriverState *s, IOEventHandler *chr_event)
-{
-    s->chr_event = chr_event;
-}
-
 static int null_chr_write(CharDriverState *chr, const uint8_t *buf, int len)
 {
     return len;
 }
 
-static void null_chr_add_read_handler(CharDriverState *chr, 
-                                    IOCanRWHandler *fd_can_read, 
-                                    IOReadHandler *fd_read, void *opaque)
-{
-}
-
 static CharDriverState *qemu_chr_open_null(void)
 {
     CharDriverState *chr;
@@ -1224,7 +1210,6 @@ static CharDriverState *qemu_chr_open_null(void)
     if (!chr)
         return NULL;
     chr->chr_write = null_chr_write;
-    chr->chr_add_read_handler = null_chr_add_read_handler;
     return chr;
 }
 
@@ -1316,9 +1301,6 @@ void socket_set_nonblock(int fd)
 
 typedef struct {
     int fd_in, fd_out;
-    IOCanRWHandler *fd_can_read; 
-    IOReadHandler *fd_read;
-    void *fd_opaque;
     int max_size;
 } FDCharDriver;
 
@@ -1338,7 +1320,7 @@ static int fd_chr_read_poll(void *opaque)
     CharDriverState *chr = opaque;
     FDCharDriver *s = chr->opaque;
 
-    s->max_size = s->fd_can_read(s->fd_opaque);
+    s->max_size = qemu_chr_can_read(chr);
     return s->max_size;
 }
 
@@ -1361,20 +1343,15 @@ static void fd_chr_read(void *opaque)
         return;
     }
     if (size > 0) {
-        s->fd_read(s->fd_opaque, buf, size);
+        qemu_chr_read(chr, buf, size);
     }
 }
 
-static void fd_chr_add_read_handler(CharDriverState *chr, 
-                                    IOCanRWHandler *fd_can_read, 
-                                    IOReadHandler *fd_read, void *opaque)
+static void fd_chr_update_read_handler(CharDriverState *chr)
 {
     FDCharDriver *s = chr->opaque;
 
     if (s->fd_in >= 0) {
-        s->fd_can_read = fd_can_read;
-        s->fd_read = fd_read;
-        s->fd_opaque = opaque;
         if (nographic && s->fd_in == 0) {
         } else {
             qemu_set_fd_handler2(s->fd_in, fd_chr_read_poll, 
@@ -1401,7 +1378,10 @@ static CharDriverState *qemu_chr_open_fd(int fd_in, int fd_out)
     s->fd_out = fd_out;
     chr->opaque = s;
     chr->chr_write = fd_chr_write;
-    chr->chr_add_read_handler = fd_chr_add_read_handler;
+    chr->chr_update_read_handler = fd_chr_update_read_handler;
+
+    qemu_chr_reset(chr);
+
     return chr;
 }
 
@@ -1491,7 +1471,7 @@ static void stdio_received_byte(int ch)
 
                 chr = stdio_clients[client_index];
                 s = chr->opaque;
-                chr->chr_event(s->fd_opaque, CHR_EVENT_BREAK);
+                qemu_chr_event(chr, CHR_EVENT_BREAK);
             }
             break;
         case 'c':
@@ -1518,13 +1498,11 @@ static void stdio_received_byte(int ch)
         if (client_index < stdio_nb_clients) {
             uint8_t buf[1];
             CharDriverState *chr;
-            FDCharDriver *s;
             
             chr = stdio_clients[client_index];
-            s = chr->opaque;
-            if (s->fd_can_read(s->fd_opaque) > 0) {
+            if (qemu_chr_can_read(chr) > 0) {
                 buf[0] = ch;
-                s->fd_read(s->fd_opaque, buf, 1);
+                qemu_chr_read(chr, buf, 1);
             } else if (term_fifo_size == 0) {
                 term_fifo[term_fifo_size++] = ch;
             }
@@ -1535,14 +1513,12 @@ static void stdio_received_byte(int ch)
 static int stdio_read_poll(void *opaque)
 {
     CharDriverState *chr;
-    FDCharDriver *s;
 
     if (client_index < stdio_nb_clients) {
         chr = stdio_clients[client_index];
-        s = chr->opaque;
         /* try to flush the queue if needed */
-        if (term_fifo_size != 0 && s->fd_can_read(s->fd_opaque) > 0) {
-            s->fd_read(s->fd_opaque, term_fifo, 1);
+        if (term_fifo_size != 0 && qemu_chr_can_read(chr) > 0) {
+            qemu_chr_read(chr, term_fifo, 1);
             term_fifo_size = 0;
         }
         /* see if we can absorb more chars */
@@ -1819,6 +1795,7 @@ static CharDriverState *qemu_chr_open_tty(const char *filename)
     if (!chr)
         return NULL;
     chr->chr_ioctl = tty_serial_ioctl;
+    qemu_chr_reset(chr);
     return chr;
 }
 
@@ -1880,8 +1857,10 @@ static CharDriverState *qemu_chr_open_pp(const char *filename)
     }
     chr->opaque = (void *)fd;
     chr->chr_write = null_chr_write;
-    chr->chr_add_read_handler = null_chr_add_read_handler;
     chr->chr_ioctl = pp_ioctl;
+
+    qemu_chr_reset(chr);
+
     return chr;
 }
 
@@ -1896,9 +1875,6 @@ static CharDriverState *qemu_chr_open_pty(void)
 
 #ifdef _WIN32
 typedef struct {
-    IOCanRWHandler *fd_can_read; 
-    IOReadHandler *fd_read;
-    void *win_opaque;
     int max_size;
     HANDLE hcom, hrecv, hsend;
     OVERLAPPED orecv, osend;
@@ -2042,10 +2018,10 @@ static int win_chr_write(CharDriverState *chr, const uint8_t *buf, int len1)
 
 static int win_chr_read_poll(WinCharState *s)
 {
-    s->max_size = s->fd_can_read(s->win_opaque);
+    s->max_size = qemu_chr_can_read(s->chr);
     return s->max_size;
 }
-            
+
 static void win_chr_readfile(WinCharState *s)
 {
     int ret, err;
@@ -2063,7 +2039,7 @@ static void win_chr_readfile(WinCharState *s)
     }
 
     if (size > 0) {
-        s->fd_read(s->win_opaque, buf, size);
+        qemu_chr_read(s->chr, buf, size);
     }
 }
 
@@ -2093,17 +2069,6 @@ static int win_chr_poll(void *opaque)
     return 0;
 }
 
-static void win_chr_add_read_handler(CharDriverState *chr, 
-                                    IOCanRWHandler *fd_can_read, 
-                                    IOReadHandler *fd_read, void *opaque)
-{
-    WinCharState *s = chr->opaque;
-
-    s->fd_can_read = fd_can_read;
-    s->fd_read = fd_read;
-    s->win_opaque = opaque;
-}
-
 static CharDriverState *qemu_chr_open_win(const char *filename)
 {
     CharDriverState *chr;
@@ -2119,7 +2084,6 @@ static CharDriverState *qemu_chr_open_win(const char *filename)
     }
     chr->opaque = s;
     chr->chr_write = win_chr_write;
-    chr->chr_add_read_handler = win_chr_add_read_handler;
     chr->chr_close = win_chr_close;
 
     if (win_chr_init(s, filename) < 0) {
@@ -2127,6 +2091,7 @@ static CharDriverState *qemu_chr_open_win(const char *filename)
         free(chr);
         return NULL;
     }
+    qemu_chr_reset(chr);
     return chr;
 }
 
@@ -2222,7 +2187,6 @@ static CharDriverState *qemu_chr_open_win_pipe(const char *filename)
     }
     chr->opaque = s;
     chr->chr_write = win_chr_write;
-    chr->chr_add_read_handler = win_chr_add_read_handler;
     chr->chr_close = win_chr_close;
     
     if (win_chr_pipe_init(s, filename) < 0) {
@@ -2230,6 +2194,7 @@ static CharDriverState *qemu_chr_open_win_pipe(const char *filename)
         free(chr);
         return NULL;
     }
+    qemu_chr_reset(chr);
     return chr;
 }
 
@@ -2249,7 +2214,7 @@ static CharDriverState *qemu_chr_open_win_file(HANDLE fd_out)
     s->hcom = fd_out;
     chr->opaque = s;
     chr->chr_write = win_chr_write;
-    chr->chr_add_read_handler = win_chr_add_read_handler;
+    qemu_chr_reset(chr);
     return chr;
 }
     
@@ -2270,9 +2235,6 @@ static CharDriverState *qemu_chr_open_win_file_out(const char *file_out)
 /* UDP Net console */
 
 typedef struct {
-    IOCanRWHandler *fd_can_read;
-    IOReadHandler *fd_read;
-    void *fd_opaque;
     int fd;
     struct sockaddr_in daddr;
     char buf[1024];
@@ -2294,15 +2256,15 @@ static int udp_chr_read_poll(void *opaque)
     CharDriverState *chr = opaque;
     NetCharDriver *s = chr->opaque;
 
-    s->max_size = s->fd_can_read(s->fd_opaque);
+    s->max_size = qemu_chr_can_read(chr);
 
     /* If there were any stray characters in the queue process them
      * first
      */
     while (s->max_size > 0 && s->bufptr < s->bufcnt) {
-        s->fd_read(s->fd_opaque, &s->buf[s->bufptr], 1);
+        qemu_chr_read(chr, &s->buf[s->bufptr], 1);
         s->bufptr++;
-        s->max_size = s->fd_can_read(s->fd_opaque);
+        s->max_size = qemu_chr_can_read(chr);
     }
     return s->max_size;
 }
@@ -2321,22 +2283,17 @@ static void udp_chr_read(void *opaque)
 
     s->bufptr = 0;
     while (s->max_size > 0 && s->bufptr < s->bufcnt) {
-        s->fd_read(s->fd_opaque, &s->buf[s->bufptr], 1);
+        qemu_chr_read(chr, &s->buf[s->bufptr], 1);
         s->bufptr++;
-        s->max_size = s->fd_can_read(s->fd_opaque);
+        s->max_size = qemu_chr_can_read(chr);
     }
 }
 
-static void udp_chr_add_read_handler(CharDriverState *chr,
-                                    IOCanRWHandler *fd_can_read,
-                                    IOReadHandler *fd_read, void *opaque)
+static void udp_chr_update_read_handler(CharDriverState *chr)
 {
     NetCharDriver *s = chr->opaque;
 
     if (s->fd >= 0) {
-        s->fd_can_read = fd_can_read;
-        s->fd_read = fd_read;
-        s->fd_opaque = opaque;
         qemu_set_fd_handler2(s->fd, udp_chr_read_poll,
                              udp_chr_read, NULL, chr);
     }
@@ -2386,7 +2343,7 @@ static CharDriverState *qemu_chr_open_udp(const char *def)
     s->bufptr = 0;
     chr->opaque = s;
     chr->chr_write = udp_chr_write;
-    chr->chr_add_read_handler = udp_chr_add_read_handler;
+    chr->chr_update_read_handler = udp_chr_update_read_handler;
     return chr;
 
 return_err:
@@ -2403,13 +2360,11 @@ return_err:
 /* TCP Net console */
 
 typedef struct {
-    IOCanRWHandler *fd_can_read;
-    IOReadHandler *fd_read;
-    void *fd_opaque;
     int fd, listen_fd;
     int connected;
     int max_size;
     int do_telnetopt;
+    int do_nodelay;
     int is_unix;
 } TCPCharDriver;
 
@@ -2432,9 +2387,7 @@ static int tcp_chr_read_poll(void *opaque)
     TCPCharDriver *s = chr->opaque;
     if (!s->connected)
         return 0;
-    if (!s->fd_can_read)
-       return 0;
-    s->max_size = s->fd_can_read(s->fd_opaque);
+    s->max_size = qemu_chr_can_read(chr);
     return s->max_size;
 }
 
@@ -2467,7 +2420,7 @@ static void tcp_chr_process_IAC_bytes(CharDriverState *chr,
             } else {
                 if ((unsigned char)buf[i] == IAC_BREAK && s->do_telnetopt == 2) {
                     /* Handle IAC break commands by sending a serial break */
-                    chr->chr_event(s->fd_opaque, CHR_EVENT_BREAK);
+                    qemu_chr_event(chr, CHR_EVENT_BREAK);
                     s->do_telnetopt++;
                 }
                 s->do_telnetopt++;
@@ -2514,21 +2467,10 @@ static void tcp_chr_read(void *opaque)
         if (s->do_telnetopt)
             tcp_chr_process_IAC_bytes(chr, s, buf, &size);
         if (size > 0)
-            s->fd_read(s->fd_opaque, buf, size);
+            qemu_chr_read(chr, buf, size);
     }
 }
 
-static void tcp_chr_add_read_handler(CharDriverState *chr,
-                                     IOCanRWHandler *fd_can_read,
-                                    IOReadHandler *fd_read, void *opaque)
-{
-    TCPCharDriver *s = chr->opaque;
-
-    s->fd_can_read = fd_can_read;
-    s->fd_read = fd_read;
-    s->fd_opaque = opaque;
-}
-
 static void tcp_chr_connect(void *opaque)
 {
     CharDriverState *chr = opaque;
@@ -2537,6 +2479,7 @@ static void tcp_chr_connect(void *opaque)
     s->connected = 1;
     qemu_set_fd_handler2(s->fd, tcp_chr_read_poll,
                          tcp_chr_read, NULL, chr);
+    qemu_chr_reset(chr);
 }
 
 #define IACSET(x,a,b,c) x[0] = a; x[1] = b; x[2] = c;
@@ -2554,6 +2497,12 @@ static void tcp_chr_telnet_init(int fd)
     send(fd, (char *)buf, 3, 0);
 }
 
+static void socket_set_nodelay(int fd)
+{
+    int val = 1;
+    setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (char *)&val, sizeof(val));
+}
+
 static void tcp_chr_accept(void *opaque)
 {
     CharDriverState *chr = opaque;
@@ -2587,6 +2536,8 @@ static void tcp_chr_accept(void *opaque)
         }
     }
     socket_set_nonblock(fd);
+    if (s->do_nodelay)
+        socket_set_nodelay(fd);
     s->fd = fd;
     qemu_set_fd_handler(s->listen_fd, NULL, NULL, NULL);
     tcp_chr_connect(chr);
@@ -2611,6 +2562,7 @@ static CharDriverState *qemu_chr_open_tcp(const char *host_str,
     int fd = -1, ret, err, val;
     int is_listen = 0;
     int is_waitconnect = 1;
+    int do_nodelay = 0;
     const char *ptr;
     struct sockaddr_in saddr;
 #ifndef _WIN32
@@ -2641,6 +2593,8 @@ static CharDriverState *qemu_chr_open_tcp(const char *host_str,
             is_listen = 1;
         } else if (!strncmp(ptr,"nowait",6)) {
             is_waitconnect = 0;
+        } else if (!strncmp(ptr,"nodelay",6)) {
+            do_nodelay = 1;
         } else {
             printf("Unknown option: %s\n", ptr);
             goto fail;
@@ -2673,10 +2627,10 @@ static CharDriverState *qemu_chr_open_tcp(const char *host_str,
     s->fd = -1;
     s->listen_fd = -1;
     s->is_unix = is_unix;
+    s->do_nodelay = do_nodelay && !is_unix;
 
     chr->opaque = s;
     chr->chr_write = tcp_chr_write;
-    chr->chr_add_read_handler = tcp_chr_add_read_handler;
     chr->chr_close = tcp_chr_close;
 
     if (is_listen) {
@@ -2723,6 +2677,7 @@ static CharDriverState *qemu_chr_open_tcp(const char *host_str,
             }
         }
         s->fd = fd;
+        socket_set_nodelay(fd);
         if (s->connected)
             tcp_chr_connect(chr);
         else
@@ -3334,7 +3289,7 @@ static int net_tap_init(VLANState *vlan, const char *ifname1,
     if (fd < 0)
         return -1;
 
-    if (!setup_script)
+    if (!setup_script || !strcmp(setup_script, "no"))
         setup_script = "";
     if (setup_script[0] != '\0') {
         /* try to launch network init script */
@@ -3906,7 +3861,9 @@ static int net_client_init(const char *str)
             if (net_tap_fd_init(vlan, fd))
                 ret = 0;
         } else {
-            get_param_value(ifname, sizeof(ifname), "ifname", p);
+            if (get_param_value(ifname, sizeof(ifname), "ifname", p) <= 0) {
+                ifname[0] = '\0';
+            }
             if (get_param_value(setup_script, sizeof(setup_script), "script", p) == 0) {
                 pstrcpy(setup_script, sizeof(setup_script), DEFAULT_NETWORK_SCRIPT);
             }
@@ -3955,178 +3912,6 @@ void do_info_network(void)
     }
 }
 
-/* Parse IDE and SCSI disk options */
-static int disk_options_init(int num_ide_disks,
-                             char ide_disk_options[][DISK_OPTIONS_SIZE],
-                             int snapshot,
-                             int num_scsi_disks,
-                             char scsi_disk_options[][DISK_OPTIONS_SIZE],
-                             int cdrom_index,
-                             int cyls,
-                             int heads,
-                             int secs,
-                             int translation)
-{
-    char buf[256];
-    char dev_name[64];
-    int id, i, j;
-    int cdrom_device;
-    int ide_cdrom_created = 0;
-    int scsi_index;
-    scsi_host_adapters temp_adapter;
-
-    /* Process any IDE disks/cdroms */
-    for (i=0; i< num_ide_disks; i++) {
-        for (j=0; j<MAX_DISKS; j++) {
-            if (ide_disk_options[j][0] == '\0')
-                continue;
-
-            if (get_param_value(buf, sizeof(buf),"type",ide_disk_options[j])) {
-                if (!strcmp(buf, "disk")) {
-                    cdrom_device = 0;
-                } else if (!strcmp(buf, "cdrom")) {
-                    cdrom_device = 1;
-                    ide_cdrom_created = 1;
-                } else {
-                    fprintf(stderr, "qemu: invalid IDE disk type= value: %s\n", buf);
-                    return -1;
-                }
-            } else {
-                cdrom_device = 0;
-            }
-
-            if (cdrom_device) {
-                snprintf(dev_name, sizeof(dev_name), "cdrom%c", i + '0');
-            } else {
-                snprintf(dev_name, sizeof(dev_name), "hd%c", i + 'a');
-            }
-
-            if (!(get_param_value(buf, sizeof(buf),"img",ide_disk_options[j]))) {
-                fprintf(stderr, "qemu: missing IDE disk img= value.\n");
-                return -1;
-            }
-
-            if (!(bs_table[i] = bdrv_new(dev_name))) {
-                fprintf(stderr, "qemu: unable to create new block device for:%s\n",dev_name);
-                return -1;
-            }
-
-            if (cdrom_device) {
-                bdrv_set_type_hint(bs_table[i], BDRV_TYPE_CDROM);
-            }
-
-            if (bdrv_open(bs_table[i], buf, snapshot ? BDRV_O_SNAPSHOT : 0) < 0) {
-                fprintf(stderr, "qemu: could not open hard disk image: '%s'\n",
-                        buf);
-                return -1;
-            }
-            if (i == 0 && cyls != 0) {
-                bdrv_set_geometry_hint(bs_table[i], cyls, heads, secs);
-                bdrv_set_translation_hint(bs_table[i], translation);
-            }
-            ide_disk_options[j][0] = '\0';
-
-            if (i == cdrom_index) {
-                cdrom_index = -1;
-            }
-            break; /* finished with this IDE device*/
-        }
-    }
-
-    if (cdrom_index >= 0 && (!ide_cdrom_created)) {
-        bs_table[cdrom_index] = bdrv_new("cdrom");
-        bdrv_set_type_hint(bs_table[cdrom_index], BDRV_TYPE_CDROM);
-    }
-
-    for(i = 0; i < num_scsi_disks; i++) {
-
-#if !defined(TARGET_SPARC) || defined(TARGET_SPARC64)
-        temp_adapter = SCSI_LSI_53C895A;
-        scsi_hba_lsi++;
-#else
-        temp_adapter = SCSI_ESP;
-#endif
-
-        /*Check for sdx= parameter */
-        if (get_param_value(buf, sizeof(buf), "sdx", scsi_disk_options[i])) {
-            if (buf[0] >= 'a' && buf[0] <= 'g') {
-                scsi_index = buf[0] - 'a';
-            } else{
-                fprintf(stderr, "qemu: sdx= option for SCSI must be one letter from a-g. %s \n",buf);
-                exit(1);
-            }
-        } else {
-             scsi_index = 0;
-        }
-
-        /* Check for SCSI id specified. */
-        if (get_param_value(buf, sizeof(buf),"id",scsi_disk_options[i])) {
-            id = strtol(buf, NULL, 0);
-            if (id < 0 || id > 6) {
-                fprintf(stderr, "qemu: SCSI id must be from 0-6: %d\n", id);
-                return -1;
-            }
-            /* Check if id already used */
-            for(j = 0; j < MAX_SCSI_DISKS; j++) {
-                if (scsi_disks_info[j].device_type != SCSI_NONE &&
-                    j != i &&
-                    scsi_disks_info[j].adapter == temp_adapter &&
-                    scsi_disks_info[j].id == id  ) {
-                    fprintf(stderr, "qemu: SCSI id already used: %u\n", id);
-                    return -1;
-                }
-            }
-        } else {
-            id = -1;
-        }
-        scsi_disks_info[i].adapter = temp_adapter;
-        scsi_disks_info[i].id = id;
-
-        if (get_param_value(buf, sizeof(buf),"type",scsi_disk_options[i])) {
-            if (!strcmp(buf, "disk")) {
-                cdrom_device = 0;
-            } else if (!strcmp(buf, "cdrom")) {
-                cdrom_device = 1;
-            } else {
-                fprintf(stderr, "qemu: invalid SCSI disk type= value: %s\n", buf);
-                return -1;
-            }
-        } else {
-            cdrom_device = 0;
-        }
-
-        if (cdrom_device) {
-            snprintf(dev_name, sizeof(buf), "cdrom%c", scsi_index + '0');
-            scsi_disks_info[scsi_index].device_type = SCSI_CDROM;
-        } else {
-            snprintf(dev_name, sizeof(buf), "sd%c", scsi_index + 'a');
-            scsi_disks_info[scsi_index].device_type = SCSI_DISK;
-        }
-
-        if (!(bs_scsi_table[scsi_index] = bdrv_new(dev_name))) {
-            fprintf(stderr, "qemu: unable to create new block device for:%s\n",dev_name);
-            return -1;
-        }
-
-        /* Get image filename from options and then try to open it */
-        if (get_param_value(buf, sizeof(buf),"img",scsi_disk_options[i])) {
-            if (bdrv_open(bs_scsi_table[scsi_index], buf, 0) < 0) {
-                fprintf(stderr, "qemu: could not open SCSI disk image img='%s'\n",buf);
-                return -1;
-            }
-        } else {
-            fprintf(stderr, "qemu: SCSI disk image not specified for sd%c \n", i + 'a');
-            return -1;
-        }
-        if (cdrom_device) {
-            bdrv_set_type_hint(bs_scsi_table[scsi_index], BDRV_TYPE_CDROM);
-        }
-    }
-
-    return 0;
-}
-
-
 /***********************************************************/
 /* USB devices */
 
@@ -6235,10 +6020,6 @@ void help(void)
            "-hdc/-hdd file  use 'file' as IDE hard disk 2/3 image\n"
            "-cdrom file     use 'file' as IDE cdrom image (cdrom is ide1 master)\n"
            "-boot [a|c|d|n] boot on floppy (a), hard disk (c), CD-ROM (d), or network (n)\n"
-           "-disk ide,img=file[,hdx=a..dd][,type=disk|cdrom] \n"
-           "                defaults are: hdx=a,type=disk \n"
-           "-disk scsi,img=file[,sdx=a..g][,type=disk|cdrom][,id=n]  \n"
-           "                defaults are: sdx=a,type=disk,id='auto assign' \n"
            "-snapshot       write to temporary files instead of disk image files\n"
 #ifdef CONFIG_SDL
            "-no-quit        disable SDL window close capability\n"
@@ -6285,6 +6066,7 @@ void help(void)
            "-net tap[,vlan=n][,fd=h][,ifname=name][,script=file]\n"
            "                connect the host TAP network interface to VLAN 'n' and use\n"
            "                the network script 'file' (default=%s);\n"
+           "                use 'script=no' to disable script execution;\n"
            "                use 'fd=h' to connect to an already opened TAP interface\n"
 #endif
            "-net socket[,vlan=n][,fd=h][,listen=[host]:port][,connect=host:port]\n"
@@ -6420,8 +6202,8 @@ enum {
     QEMU_OPTION_no_acpi,
     QEMU_OPTION_no_reboot,
     QEMU_OPTION_daemonize,
-    QEMU_OPTION_disk,
     QEMU_OPTION_option_rom,
+    QEMU_OPTION_semihosting
 };
 
 typedef struct QEMUOption {
@@ -6432,6 +6214,7 @@ typedef struct QEMUOption {
 
 const QEMUOption qemu_options[] = {
     { "h", 0, QEMU_OPTION_h },
+    { "help", 0, QEMU_OPTION_h },
 
     { "M", HAS_ARG, QEMU_OPTION_M },
     { "fda", HAS_ARG, QEMU_OPTION_fda },
@@ -6496,8 +6279,7 @@ const QEMUOption qemu_options[] = {
     { "usbdevice", HAS_ARG, QEMU_OPTION_usbdevice },
     { "smp", HAS_ARG, QEMU_OPTION_smp },
     { "vnc", HAS_ARG, QEMU_OPTION_vnc },
-    { "disk", HAS_ARG, QEMU_OPTION_disk },
-    
+
     /* temporary options */
     { "usb", 0, QEMU_OPTION_usb },
     { "cirrusvga", 0, QEMU_OPTION_cirrusvga },
@@ -6505,6 +6287,9 @@ const QEMUOption qemu_options[] = {
     { "no-reboot", 0, QEMU_OPTION_no_reboot },
     { "daemonize", 0, QEMU_OPTION_daemonize },
     { "option-rom", HAS_ARG, QEMU_OPTION_option_rom },
+#if defined(TARGET_ARM)
+    { "semihosting", 0, QEMU_OPTION_semihosting },
+#endif
     { NULL },
 };
 
@@ -6566,6 +6351,7 @@ void register_machines(void)
     qemu_register_machine(&prep_machine);
 #elif defined(TARGET_MIPS)
     qemu_register_machine(&mips_machine);
+    qemu_register_machine(&mips_malta_machine);
 #elif defined(TARGET_SPARC)
 #ifdef TARGET_SPARC64
     qemu_register_machine(&sun4u_machine);
@@ -6711,20 +6497,16 @@ static BOOL WINAPI qemu_ctrl_handler(DWORD type)
 int main(int argc, char **argv)
 {
 #ifdef CONFIG_GDBSTUB
-    int use_gdbstub, gdbstub_port;
+    int use_gdbstub;
+    char gdbstub_port_name[128];
 #endif
     int i, cdrom_index;
     int snapshot, linux_boot;
     const char *initrd_filename;
-    const char *fd_filename[MAX_FD];
-    char scsi_options[MAX_SCSI_DISKS] [DISK_OPTIONS_SIZE];
-    char ide_options[MAX_DISKS] [DISK_OPTIONS_SIZE];
-    int num_ide_disks;
-    int num_scsi_disks;
+    const char *hd_filename[MAX_DISKS], *fd_filename[MAX_FD];
     const char *kernel_filename, *kernel_cmdline;
     DisplayState *ds = &display_state;
     int cyls, heads, secs, translation;
-    int start_emulation = 1;
     char net_clients[MAX_NET_CLIENTS][256];
     int nb_net_clients;
     int optind;
@@ -6775,25 +6557,16 @@ int main(int argc, char **argv)
     register_machines();
     machine = first_machine;
     initrd_filename = NULL;
-    for(i = 0; i < MAX_SCSI_DISKS; i++) {
-        scsi_disks_info[i].device_type = SCSI_NONE;
-        bs_scsi_table[i] = NULL;
-    }
-
-    num_ide_disks = 0;
-    num_scsi_disks = 0;
-
     for(i = 0; i < MAX_FD; i++)
         fd_filename[i] = NULL;
-    for(i = 0; i < MAX_DISKS; i++) {
-        ide_options[i][0] =  '\0';
-    }
+    for(i = 0; i < MAX_DISKS; i++)
+        hd_filename[i] = NULL;
     ram_size = DEFAULT_RAM_SIZE * 1024 * 1024;
     vga_ram_size = VGA_RAM_SIZE;
     bios_size = BIOS_SIZE;
 #ifdef CONFIG_GDBSTUB
     use_gdbstub = 0;
-    gdbstub_port = DEFAULT_GDBSTUB_PORT;
+    sprintf(gdbstub_port_name, "%d", DEFAULT_GDBSTUB_PORT);
 #endif
     snapshot = 0;
     nographic = 0;
@@ -6831,20 +6604,14 @@ int main(int argc, char **argv)
             break;
         r = argv[optind];
         if (r[0] != '-') {
-
-        /* Build new disk IDE syntax string */
-        pstrcpy(ide_options[0],
-                14,
-                "hdx=a,img=");
-        /*Add on image filename */
-        pstrcpy(&(ide_options[0][13]),
-                sizeof(ide_options[0])-13,
-                argv[optind++]);
-        num_ide_disks++;
+            hd_filename[0] = argv[optind++];
         } else {
             const QEMUOption *popt;
 
             optind++;
+            /* Treat --foo the same as -foo.  */
+            if (r[1] == '-')
+                r++;
             popt = qemu_options;
             for(;;) {
                 if (!popt->name) {
@@ -6890,75 +6657,10 @@ int main(int argc, char **argv)
             case QEMU_OPTION_hdd:
                 {
                     int hd_index;
-                    const char newIDE_DiskSyntax [][10] = {
-                       "hdx=a,img=", "hdx=b,img=", "hdx=c,img=", "hdx=d,img=" };
-
                     hd_index = popt->index - QEMU_OPTION_hda;
-                    if (num_ide_disks >= MAX_DISKS) {
-                        fprintf(stderr, "qemu: too many IDE disks defined.\n");
-                        exit(1);
-                    }
-                    /* Build new disk IDE syntax string */
-                    pstrcpy(ide_options[hd_index],
-                            11,
-                            newIDE_DiskSyntax[hd_index]);
-                    /* Add on image filename */
-                    pstrcpy(&(ide_options[hd_index][10]),
-                            sizeof(ide_options[0])-10,
-                            optarg);
-                    num_ide_disks++;
-                }
-                break;
-            case QEMU_OPTION_disk: /*Combined IDE and SCSI, for disk and CDROM */
-                {
-                    const char *p_input_char;
-                    char *p_output_string;
-                    char device[64];
-                    int disk_index;
-
-                    p_input_char = optarg;
-                    p_output_string = device;
-                    while (*p_input_char != '\0' && *p_input_char != ',') {
-                        if ((p_output_string - device) < sizeof(device) - 1)
-                            *p_output_string++ = *p_input_char;
-                        p_input_char++;
-                    }
-                    *p_output_string = '\0';
-                    if (*p_input_char == ',')
-                        p_input_char++;
-
-                    if (!strcmp(device, "scsi")) {
-                        if (num_scsi_disks >= MAX_SCSI_DISKS) {
-                            fprintf(stderr, "qemu: too many SCSI disks defined.\n");
-                            exit(1);
-                        }
-                        pstrcpy(scsi_options[num_scsi_disks],
-                                sizeof(scsi_options[0]),
-                                p_input_char);
-                        num_scsi_disks++;
-                    } else if (!strcmp(device,"ide")) {
-                        if (num_ide_disks >= MAX_DISKS) {
-                            fprintf(stderr, "qemu: too many IDE disks/cdroms defined.\n");
-                            exit(1);
-                        }
-                        disk_index = 0; /* default is hda */
-                        if (get_param_value(device, sizeof(device),"hdx",p_input_char)) {
-                            if (device[0] >= 'a' && device[0] <= 'd') {
-                                disk_index = device[0] - 'a';
-                            } else {
-                                fprintf(stderr, "qemu: invalid IDE disk hdx= value: %s\n", device);
-                                return -1;
-                            }
-                        }
-                        else disk_index=0;
-                        pstrcpy(ide_options[disk_index],
-                                sizeof(ide_options[0]),
-                                p_input_char);
-                        num_ide_disks++;
-                    } else {
-                        fprintf(stderr, "qemu: -disk option must specify IDE or SCSI: %s \n",device);
-                        exit(1);
-                    }
+                    hd_filename[hd_index] = optarg;
+                    if (hd_index == cdrom_index)
+                        cdrom_index = -1;
                 }
                 break;
             case QEMU_OPTION_snapshot:
@@ -7012,46 +6714,9 @@ int main(int argc, char **argv)
                 kernel_cmdline = optarg;
                 break;
             case QEMU_OPTION_cdrom:
-#if !defined(TARGET_SPARC) || defined(TARGET_SPARC64)
-                /* Assume boot cdrom is IDE */
-                {
-                    char buf[22];
-                    if (num_ide_disks >= MAX_DISKS) {
-                        fprintf(stderr, "qemu: too many IDE disks/cdroms defined.\n");
-                        exit(1);
-                    }
-                    snprintf(buf, sizeof(buf), "type=cdrom,hdx=%c,img=", cdrom_index + 'a');
-                    /* Build new disk IDE syntax string */
-                    pstrcpy(ide_options[cdrom_index],
-                            22,
-                            buf);
-                    /* Add on image filename */
-                    pstrcpy(&(ide_options[cdrom_index][21]),
-                            sizeof(ide_options[0])-21,
-                            optarg);
-                    num_ide_disks++;
-                }
-#else
-                /* Assume boot cdrom is SCSI */
-                {
-                    char buf[27];
-                    if (num_scsi_disks >= MAX_SCSI_DISKS) {
-                        fprintf(stderr, "qemu: too many SCSI disks/cdroms defined.\n");
-                        exit(1);
-                    }
-                    snprintf(buf, sizeof(buf), "type=cdrom,sdx=%c,id=%d,img=",
-                             num_scsi_disks + 'a', num_scsi_disks + 2);
-                    /* Build new disk SCSI syntax string */
-                    pstrcpy(scsi_options[num_scsi_disks],
-                            27,
-                            buf);
-                    /* Add on image filename */
-                    pstrcpy(&(scsi_options[num_scsi_disks][26]),
-                            sizeof(scsi_options[0])-26,
-                            optarg);
-                    num_scsi_disks++;
+                if (cdrom_index >= 0) {
+                    hd_filename[cdrom_index] = optarg;
                 }
-#endif
                 break;
             case QEMU_OPTION_boot:
                 boot_device = optarg[0];
@@ -7145,14 +6810,14 @@ int main(int argc, char **argv)
                 use_gdbstub = 1;
                 break;
             case QEMU_OPTION_p:
-                gdbstub_port = atoi(optarg);
+                pstrcpy(gdbstub_port_name, sizeof(gdbstub_port_name), optarg);
                 break;
 #endif
             case QEMU_OPTION_L:
                 bios_dir = optarg;
                 break;
             case QEMU_OPTION_S:
-                start_emulation = 0;
+                autostart = 0;
                 break;
            case QEMU_OPTION_k:
                keyboard_layout = optarg;
@@ -7289,6 +6954,9 @@ int main(int argc, char **argv)
                option_rom[nb_option_roms] = optarg;
                nb_option_roms++;
                break;
+            case QEMU_OPTION_semihosting:
+                semihosting_enabled = 1;
+                break;
             }
         }
     }
@@ -7348,11 +7016,19 @@ int main(int argc, char **argv)
     linux_boot = (kernel_filename != NULL);
 
     if (!linux_boot &&
-        num_ide_disks == 0 &&
-        num_scsi_disks == 0 &&
+        hd_filename[0] == '\0' && 
+        (cdrom_index >= 0 && hd_filename[cdrom_index] == '\0') &&
         fd_filename[0] == '\0')
         help();
 
+    /* boot to floppy or the default cd if no hard disk defined yet */
+    if (hd_filename[0] == '\0' && boot_device == 'c') {
+        if (fd_filename[0] != '\0')
+            boot_device = 'a';
+        else
+            boot_device = 'd';
+    }
+
     setvbuf(stdout, NULL, _IOLBF, 0);
     
     init_timers();
@@ -7418,22 +7094,31 @@ int main(int argc, char **argv)
         exit(1);
     }
 
+    /* we always create the cdrom drive, even if no disk is there */
     bdrv_init();
-
-    /* open the virtual block devices, disks or CDRoms */
-    if (disk_options_init(num_ide_disks,ide_options,snapshot,
-                          num_scsi_disks,scsi_options,
-                          cdrom_index,
-                          cyls, heads, secs, translation)){
-        exit(1);
+    if (cdrom_index >= 0) {
+        bs_table[cdrom_index] = bdrv_new("cdrom");
+        bdrv_set_type_hint(bs_table[cdrom_index], BDRV_TYPE_CDROM);
     }
 
-    /* boot to floppy or default cd if no hard disk */
-    if (num_ide_disks == 0 && boot_device == 'c') {
-        if (fd_filename[0] != '\0')
-            boot_device = 'a';
-        else
-            boot_device = 'd';
+    /* open the virtual block devices */
+    for(i = 0; i < MAX_DISKS; i++) {
+        if (hd_filename[i]) {
+            if (!bs_table[i]) {
+                char buf[64];
+                snprintf(buf, sizeof(buf), "hd%c", i + 'a');
+                bs_table[i] = bdrv_new(buf);
+            }
+            if (bdrv_open(bs_table[i], hd_filename[i], snapshot ? BDRV_O_SNAPSHOT : 0) < 0) {
+                fprintf(stderr, "qemu: could not open hard disk image '%s'\n",
+                        hd_filename[i]);
+                exit(1);
+            }
+            if (i == 0 && cyls != 0) {
+                bdrv_set_geometry_hint(bs_table[i], cyls, heads, secs);
+                bdrv_set_translation_hint(bs_table[i], translation);
+            }
+        }
     }
 
     /* we always create at least one floppy disk */
@@ -7533,13 +7218,19 @@ int main(int argc, char **argv)
 
 #ifdef CONFIG_GDBSTUB
     if (use_gdbstub) {
-        if (gdbserver_start(gdbstub_port) < 0) {
-            fprintf(stderr, "Could not open gdbserver socket on port %d\n", 
-                    gdbstub_port);
+        CharDriverState *chr;
+        int port;
+
+        port = atoi(gdbstub_port_name);
+        if (port != 0)
+            sprintf(gdbstub_port_name, "tcp::%d,nowait,nodelay,server", port);
+        chr = qemu_chr_open(gdbstub_port_name);
+        if (!chr) {
+            fprintf(stderr, "qemu: could not open gdbstub device '%s'\n",
+                    gdbstub_port_name);
             exit(1);
-        } else {
-            printf("Waiting gdb connection on port %d\n", gdbstub_port);
         }
+        gdbserver_start(chr);
     } else 
 #endif
     if (loadvm)
@@ -7548,7 +7239,7 @@ int main(int argc, char **argv)
     {
         /* XXX: simplify init */
         read_passwords();
-        if (start_emulation) {
+        if (autostart) {
             vm_start();
         }
     }