ia64/xen-unstable

changeset 8023:f7c7575695b3

Clean up some Xen files in the ioemulator.
1) fix indent
2) use fprintf(logfile, ...) instead of perror and printf
3) remove tailing spaces

Signed-off-by: Xin Li <xin.b.li@intel.com>
author kaf24@firebug.cl.cam.ac.uk
date Thu Nov 24 11:05:21 2005 +0100 (2005-11-24)
parents bd8418790797
children eb87d4c810d3
files tools/ioemu/target-i386-dm/helper2.c tools/ioemu/vl.c
line diff
     1.1 --- a/tools/ioemu/target-i386-dm/helper2.c	Thu Nov 24 11:03:07 2005 +0100
     1.2 +++ b/tools/ioemu/target-i386-dm/helper2.c	Thu Nov 24 11:05:21 2005 +0100
     1.3 @@ -1,6 +1,6 @@
     1.4  /*
     1.5   *  i386 helpers (without register variable usage)
     1.6 - * 
     1.7 + *
     1.8   *  Copyright (c) 2003 Fabrice Bellard
     1.9   *
    1.10   * This library is free software; you can redistribute it and/or
    1.11 @@ -56,6 +56,7 @@
    1.12  #include "vl.h"
    1.13  
    1.14  extern int domid;
    1.15 +extern int vcpus;
    1.16  
    1.17  void *shared_vram;
    1.18  
    1.19 @@ -93,7 +94,7 @@ void cpu_x86_close(CPUX86State *env)
    1.20  }
    1.21  
    1.22  
    1.23 -void cpu_dump_state(CPUState *env, FILE *f, 
    1.24 +void cpu_dump_state(CPUState *env, FILE *f,
    1.25                      int (*cpu_fprintf)(FILE *f, const char *fmt, ...),
    1.26                      int flags)
    1.27  {
    1.28 @@ -121,270 +122,273 @@ target_ulong cpu_get_phys_page_debug(CPU
    1.29  
    1.30  //the evtchn fd for polling
    1.31  int evtchn_fd = -1;
    1.32 -//the evtchn port for polling the notification, should be inputed as bochs's parameter
    1.33 +
    1.34 +//the evtchn port for polling the notification,
    1.35 +//should be inputed as bochs's parameter
    1.36  uint16_t ioreq_remote_port, ioreq_local_port;
    1.37  
    1.38  //some functions to handle the io req packet
    1.39 -void
    1.40 -sp_info()
    1.41 +void sp_info()
    1.42  {
    1.43 -	ioreq_t *req;
    1.44 +    ioreq_t *req;
    1.45 +    int i;
    1.46  
    1.47 -	req = &(shared_page->vcpu_iodata[0].vp_ioreq);
    1.48 -        term_printf("event port: %d\n", shared_page->sp_global.eport);
    1.49 -        term_printf("req state: %x, pvalid: %x, addr: %llx, data: %llx, count: %llx, size: %llx\n", req->state, req->pdata_valid, req->addr, req->u.data, req->count, req->size);
    1.50 +    term_printf("event port: %d\n", shared_page->sp_global.eport);
    1.51 +    for ( i = 0; i < vcpus; i++ ) {
    1.52 +        req = &(shared_page->vcpu_iodata[i].vp_ioreq);
    1.53 +        term_printf("vcpu %d:\n", i);
    1.54 +        term_printf("  req state: %x, pvalid: %x, addr: %llx, "
    1.55 +                    "data: %llx, count: %llx, size: %llx\n",
    1.56 +                    req->state, req->pdata_valid, req->addr,
    1.57 +                    req->u.data, req->count, req->size);
    1.58 +    }
    1.59  }
    1.60  
    1.61  //get the ioreq packets from share mem
    1.62  ioreq_t* __cpu_get_ioreq(void)
    1.63  {
    1.64 -	ioreq_t *req;
    1.65 +    ioreq_t *req;
    1.66  
    1.67 -	req = &(shared_page->vcpu_iodata[0].vp_ioreq);
    1.68 -	if (req->state == STATE_IOREQ_READY) {
    1.69 -		req->state = STATE_IOREQ_INPROCESS;
    1.70 -	} else {
    1.71 -		fprintf(logfile, "False I/O request ... in-service already: %x, pvalid: %x,port: %llx, data: %llx, count: %llx, size: %llx\n", req->state, req->pdata_valid, req->addr, req->u.data, req->count, req->size);
    1.72 -		req = NULL;
    1.73 -	}
    1.74 +    req = &(shared_page->vcpu_iodata[0].vp_ioreq);
    1.75 +    if (req->state == STATE_IOREQ_READY) {
    1.76 +        req->state = STATE_IOREQ_INPROCESS;
    1.77 +    } else {
    1.78 +        fprintf(logfile, "False I/O request ... in-service already: "
    1.79 +                         "%x, pvalid: %x, port: %llx, "
    1.80 +                         "data: %llx, count: %llx, size: %llx\n",
    1.81 +                         req->state, req->pdata_valid, req->addr,
    1.82 +                         req->u.data, req->count, req->size);
    1.83 +        req = NULL;
    1.84 +    }
    1.85  
    1.86 -	return req;
    1.87 +    return req;
    1.88  }
    1.89  
    1.90  //use poll to get the port notification
    1.91 -//ioreq_vec--out,the 
    1.92 +//ioreq_vec--out,the
    1.93  //retval--the number of ioreq packet
    1.94  ioreq_t* cpu_get_ioreq(void)
    1.95  {
    1.96 -	int rc;
    1.97 -	uint16_t port;
    1.98 -	rc = read(evtchn_fd, &port, sizeof(port));
    1.99 -	if ((rc == sizeof(port)) && (port == ioreq_local_port)) {
   1.100 -		// unmask the wanted port again
   1.101 -		write(evtchn_fd, &ioreq_local_port, 2);
   1.102 +    int rc;
   1.103 +    uint16_t port;
   1.104  
   1.105 -		//get the io packet from shared memory
   1.106 -		return __cpu_get_ioreq();
   1.107 -	}
   1.108 +    rc = read(evtchn_fd, &port, sizeof(port));
   1.109 +    if ((rc == sizeof(port)) && (port == ioreq_local_port)) {
   1.110 +        // unmask the wanted port again
   1.111 +        write(evtchn_fd, &ioreq_local_port, 2);
   1.112  
   1.113 -	//read error or read nothing
   1.114 -	return NULL;
   1.115 +        //get the io packet from shared memory
   1.116 +        return __cpu_get_ioreq();
   1.117 +    }
   1.118 +
   1.119 +    //read error or read nothing
   1.120 +    return NULL;
   1.121  }
   1.122  
   1.123 -unsigned long
   1.124 -do_inp(CPUState *env, unsigned long addr, unsigned long size)
   1.125 +unsigned long do_inp(CPUState *env, unsigned long addr, unsigned long size)
   1.126  {
   1.127 -	switch(size) {
   1.128 -	case 1:
   1.129 -		return cpu_inb(env, addr);
   1.130 -	case 2:
   1.131 -		return cpu_inw(env, addr);
   1.132 -	case 4:
   1.133 -		return cpu_inl(env, addr);
   1.134 -	default:
   1.135 -		fprintf(logfile, "inp: bad size: %lx %lx\n", addr, size);
   1.136 -		exit(-1);
   1.137 -	}
   1.138 +    switch(size) {
   1.139 +    case 1:
   1.140 +        return cpu_inb(env, addr);
   1.141 +    case 2:
   1.142 +        return cpu_inw(env, addr);
   1.143 +    case 4:
   1.144 +        return cpu_inl(env, addr);
   1.145 +    default:
   1.146 +        fprintf(logfile, "inp: bad size: %lx %lx\n", addr, size);
   1.147 +        exit(-1);
   1.148 +    }
   1.149  }
   1.150  
   1.151 -void
   1.152 -do_outp(CPUState *env, unsigned long addr, unsigned long size, 
   1.153 -        unsigned long val)
   1.154 +void do_outp(CPUState *env, unsigned long addr,
   1.155 +             unsigned long size, unsigned long val)
   1.156  {
   1.157 -	switch(size) {
   1.158 -	case 1:
   1.159 -		return cpu_outb(env, addr, val);
   1.160 -	case 2:
   1.161 -		return cpu_outw(env, addr, val);
   1.162 -	case 4:
   1.163 -		return cpu_outl(env, addr, val);
   1.164 -	default:
   1.165 -		fprintf(logfile, "outp: bad size: %lx %lx\n", addr, size);
   1.166 -		exit(-1);
   1.167 -	}
   1.168 +    switch(size) {
   1.169 +    case 1:
   1.170 +        return cpu_outb(env, addr, val);
   1.171 +    case 2:
   1.172 +        return cpu_outw(env, addr, val);
   1.173 +    case 4:
   1.174 +        return cpu_outl(env, addr, val);
   1.175 +    default:
   1.176 +        fprintf(logfile, "outp: bad size: %lx %lx\n", addr, size);
   1.177 +        exit(-1);
   1.178 +    }
   1.179  }
   1.180  
   1.181 -extern void cpu_physical_memory_rw(target_phys_addr_t addr, uint8_t *buf, 
   1.182 +extern void cpu_physical_memory_rw(target_phys_addr_t addr, uint8_t *buf,
   1.183                                     int len, int is_write);
   1.184  
   1.185 -static inline void
   1.186 -read_physical(uint64_t addr, unsigned long size, void *val)
   1.187 +static inline void read_physical(uint64_t addr, unsigned long size, void *val)
   1.188  {
   1.189 -        return cpu_physical_memory_rw((target_phys_addr_t)addr, val, size, 0);
   1.190 +    return cpu_physical_memory_rw((target_phys_addr_t)addr, val, size, 0);
   1.191  }
   1.192  
   1.193 -static inline void
   1.194 -write_physical(uint64_t addr, unsigned long size, void *val)
   1.195 +static inline void write_physical(uint64_t addr, unsigned long size, void *val)
   1.196  {
   1.197 -        return cpu_physical_memory_rw((target_phys_addr_t)addr, val, size, 1);
   1.198 +    return cpu_physical_memory_rw((target_phys_addr_t)addr, val, size, 1);
   1.199  }
   1.200  
   1.201 -void
   1.202 -cpu_ioreq_pio(CPUState *env, ioreq_t *req)
   1.203 +void cpu_ioreq_pio(CPUState *env, ioreq_t *req)
   1.204  {
   1.205 -	int i, sign;
   1.206 +    int i, sign;
   1.207 +
   1.208 +    sign = req->df ? -1 : 1;
   1.209  
   1.210 -	sign = req->df ? -1 : 1;
   1.211 -
   1.212 -	if (req->dir == IOREQ_READ) {
   1.213 -		if (!req->pdata_valid) {
   1.214 -			req->u.data = do_inp(env, req->addr, req->size);
   1.215 -		} else {
   1.216 -			unsigned long tmp; 
   1.217 +    if (req->dir == IOREQ_READ) {
   1.218 +        if (!req->pdata_valid) {
   1.219 +            req->u.data = do_inp(env, req->addr, req->size);
   1.220 +        } else {
   1.221 +            unsigned long tmp;
   1.222  
   1.223 -			for (i = 0; i < req->count; i++) {
   1.224 -				tmp = do_inp(env, req->addr, req->size);
   1.225 -				write_physical((target_phys_addr_t) req->u.pdata
   1.226 -						+ (sign * i * req->size), 
   1.227 -					req->size, &tmp);
   1.228 -			}
   1.229 -		}
   1.230 -	} else if (req->dir == IOREQ_WRITE) {
   1.231 -		if (!req->pdata_valid) {
   1.232 -			do_outp(env, req->addr, req->size, req->u.data);
   1.233 -		} else {
   1.234 -			for (i = 0; i < req->count; i++) {
   1.235 -				unsigned long tmp;
   1.236 +            for (i = 0; i < req->count; i++) {
   1.237 +                tmp = do_inp(env, req->addr, req->size);
   1.238 +                write_physical((target_phys_addr_t) req->u.pdata
   1.239 +                  + (sign * i * req->size),
   1.240 +                  req->size, &tmp);
   1.241 +            }
   1.242 +        }
   1.243 +    } else if (req->dir == IOREQ_WRITE) {
   1.244 +        if (!req->pdata_valid) {
   1.245 +            do_outp(env, req->addr, req->size, req->u.data);
   1.246 +        } else {
   1.247 +            for (i = 0; i < req->count; i++) {
   1.248 +                unsigned long tmp;
   1.249  
   1.250 -				read_physical((target_phys_addr_t) req->u.pdata
   1.251 -						+ (sign * i * req->size),
   1.252 -					req->size, &tmp);
   1.253 -				do_outp(env, req->addr, req->size, tmp);
   1.254 -			}
   1.255 -		}
   1.256 -	}
   1.257 +                read_physical((target_phys_addr_t) req->u.pdata
   1.258 +                  + (sign * i * req->size),
   1.259 +                  req->size, &tmp);
   1.260 +                do_outp(env, req->addr, req->size, tmp);
   1.261 +            }
   1.262 +        }
   1.263 +    }
   1.264  }
   1.265  
   1.266 -void
   1.267 -cpu_ioreq_move(CPUState *env, ioreq_t *req)
   1.268 +void cpu_ioreq_move(CPUState *env, ioreq_t *req)
   1.269  {
   1.270 -	int i, sign;
   1.271 +    int i, sign;
   1.272  
   1.273 -	sign = req->df ? -1 : 1;
   1.274 +    sign = req->df ? -1 : 1;
   1.275  
   1.276 -	if (!req->pdata_valid) {
   1.277 -		if (req->dir == IOREQ_READ) {
   1.278 -			for (i = 0; i < req->count; i++) {
   1.279 -				read_physical(req->addr
   1.280 -						+ (sign * i * req->size),
   1.281 -					req->size, &req->u.data);
   1.282 -			}
   1.283 -		} else if (req->dir == IOREQ_WRITE) {
   1.284 -			for (i = 0; i < req->count; i++) {
   1.285 -				write_physical(req->addr
   1.286 -						+ (sign * i * req->size),
   1.287 -					req->size, &req->u.data);
   1.288 -			}
   1.289 -		}
   1.290 -	} else {
   1.291 -		unsigned long tmp;
   1.292 +    if (!req->pdata_valid) {
   1.293 +        if (req->dir == IOREQ_READ) {
   1.294 +            for (i = 0; i < req->count; i++) {
   1.295 +                read_physical(req->addr
   1.296 +                  + (sign * i * req->size),
   1.297 +                  req->size, &req->u.data);
   1.298 +            }
   1.299 +        } else if (req->dir == IOREQ_WRITE) {
   1.300 +            for (i = 0; i < req->count; i++) {
   1.301 +                write_physical(req->addr
   1.302 +                  + (sign * i * req->size),
   1.303 +                  req->size, &req->u.data);
   1.304 +            }
   1.305 +        }
   1.306 +    } else {
   1.307 +        unsigned long tmp;
   1.308  
   1.309 -		if (req->dir == IOREQ_READ) {
   1.310 -			for (i = 0; i < req->count; i++) {
   1.311 -				read_physical(req->addr
   1.312 -						+ (sign * i * req->size),
   1.313 -					req->size, &tmp);
   1.314 -				write_physical((target_phys_addr_t )req->u.pdata
   1.315 -						+ (sign * i * req->size),
   1.316 -					req->size, &tmp);
   1.317 -			}
   1.318 -		} else if (req->dir == IOREQ_WRITE) {
   1.319 -			for (i = 0; i < req->count; i++) {
   1.320 -				read_physical((target_phys_addr_t) req->u.pdata
   1.321 -						+ (sign * i * req->size),
   1.322 -					req->size, &tmp);
   1.323 -				write_physical(req->addr
   1.324 -						+ (sign * i * req->size),
   1.325 -					req->size, &tmp);
   1.326 -			}
   1.327 -		}
   1.328 -	}
   1.329 +        if (req->dir == IOREQ_READ) {
   1.330 +            for (i = 0; i < req->count; i++) {
   1.331 +                read_physical(req->addr
   1.332 +                  + (sign * i * req->size),
   1.333 +                  req->size, &tmp);
   1.334 +                write_physical((target_phys_addr_t )req->u.pdata
   1.335 +                  + (sign * i * req->size),
   1.336 +                  req->size, &tmp);
   1.337 +            }
   1.338 +        } else if (req->dir == IOREQ_WRITE) {
   1.339 +            for (i = 0; i < req->count; i++) {
   1.340 +                read_physical((target_phys_addr_t) req->u.pdata
   1.341 +                  + (sign * i * req->size),
   1.342 +                  req->size, &tmp);
   1.343 +                write_physical(req->addr
   1.344 +                  + (sign * i * req->size),
   1.345 +                  req->size, &tmp);
   1.346 +            }
   1.347 +        }
   1.348 +    }
   1.349  }
   1.350  
   1.351 -void
   1.352 -cpu_ioreq_and(CPUState *env, ioreq_t *req)
   1.353 +void cpu_ioreq_and(CPUState *env, ioreq_t *req)
   1.354  {
   1.355 -	unsigned long tmp1, tmp2;
   1.356 +    unsigned long tmp1, tmp2;
   1.357 +
   1.358 +    if (req->pdata_valid != 0)
   1.359 +        hw_error("expected scalar value");
   1.360  
   1.361 -	if (req->pdata_valid != 0)
   1.362 -		hw_error("expected scalar value");
   1.363 -
   1.364 -	read_physical(req->addr, req->size, &tmp1);
   1.365 -	if (req->dir == IOREQ_WRITE) {
   1.366 -		tmp2 = tmp1 & (unsigned long) req->u.data;
   1.367 -		write_physical(req->addr, req->size, &tmp2);
   1.368 -	}
   1.369 -	req->u.data = tmp1;
   1.370 +    read_physical(req->addr, req->size, &tmp1);
   1.371 +    if (req->dir == IOREQ_WRITE) {
   1.372 +        tmp2 = tmp1 & (unsigned long) req->u.data;
   1.373 +        write_physical(req->addr, req->size, &tmp2);
   1.374 +    }
   1.375 +    req->u.data = tmp1;
   1.376  }
   1.377  
   1.378 -void
   1.379 -cpu_ioreq_or(CPUState *env, ioreq_t *req)
   1.380 +void cpu_ioreq_or(CPUState *env, ioreq_t *req)
   1.381  {
   1.382 -	unsigned long tmp1, tmp2;
   1.383 +    unsigned long tmp1, tmp2;
   1.384 +
   1.385 +    if (req->pdata_valid != 0)
   1.386 +        hw_error("expected scalar value");
   1.387  
   1.388 -	if (req->pdata_valid != 0)
   1.389 -		hw_error("expected scalar value");
   1.390 -
   1.391 -	read_physical(req->addr, req->size, &tmp1);
   1.392 -	if (req->dir == IOREQ_WRITE) {
   1.393 -		tmp2 = tmp1 | (unsigned long) req->u.data;
   1.394 -		write_physical(req->addr, req->size, &tmp2);
   1.395 -	}
   1.396 -	req->u.data = tmp1;
   1.397 +    read_physical(req->addr, req->size, &tmp1);
   1.398 +    if (req->dir == IOREQ_WRITE) {
   1.399 +        tmp2 = tmp1 | (unsigned long) req->u.data;
   1.400 +        write_physical(req->addr, req->size, &tmp2);
   1.401 +    }
   1.402 +    req->u.data = tmp1;
   1.403  }
   1.404  
   1.405 -void
   1.406 -cpu_ioreq_xor(CPUState *env, ioreq_t *req)
   1.407 +void cpu_ioreq_xor(CPUState *env, ioreq_t *req)
   1.408  {
   1.409 -	unsigned long tmp1, tmp2;
   1.410 +    unsigned long tmp1, tmp2;
   1.411 +
   1.412 +    if (req->pdata_valid != 0)
   1.413 +        hw_error("expected scalar value");
   1.414  
   1.415 -	if (req->pdata_valid != 0)
   1.416 -		hw_error("expected scalar value");
   1.417 -
   1.418 -	read_physical(req->addr, req->size, &tmp1);
   1.419 -	if (req->dir == IOREQ_WRITE) {
   1.420 -		tmp2 = tmp1 ^ (unsigned long) req->u.data;
   1.421 -		write_physical(req->addr, req->size, &tmp2);
   1.422 -	}
   1.423 -	req->u.data = tmp1;
   1.424 +    read_physical(req->addr, req->size, &tmp1);
   1.425 +    if (req->dir == IOREQ_WRITE) {
   1.426 +        tmp2 = tmp1 ^ (unsigned long) req->u.data;
   1.427 +        write_physical(req->addr, req->size, &tmp2);
   1.428 +    }
   1.429 +    req->u.data = tmp1;
   1.430  }
   1.431  
   1.432 -void
   1.433 -cpu_handle_ioreq(CPUState *env)
   1.434 +void cpu_handle_ioreq(CPUState *env)
   1.435  {
   1.436 -	ioreq_t *req = cpu_get_ioreq();
   1.437 +    ioreq_t *req = cpu_get_ioreq();
   1.438  
   1.439 -	if (req) {
   1.440 -		if ((!req->pdata_valid) && (req->dir == IOREQ_WRITE)) {
   1.441 -			if (req->size != 4)
   1.442 -				req->u.data &= (1UL << (8 * req->size))-1;
   1.443 -		}
   1.444 +    if (req) {
   1.445 +        if ((!req->pdata_valid) && (req->dir == IOREQ_WRITE)) {
   1.446 +            if (req->size != 4)
   1.447 +                req->u.data &= (1UL << (8 * req->size))-1;
   1.448 +        }
   1.449  
   1.450 -		switch (req->type) {
   1.451 -		case IOREQ_TYPE_PIO:
   1.452 -			cpu_ioreq_pio(env, req);
   1.453 -			break;
   1.454 -		case IOREQ_TYPE_COPY:
   1.455 -			cpu_ioreq_move(env, req);
   1.456 -			break;
   1.457 -		case IOREQ_TYPE_AND:
   1.458 -			cpu_ioreq_and(env, req);
   1.459 -			break;
   1.460 -		case IOREQ_TYPE_OR:
   1.461 -			cpu_ioreq_or(env, req);
   1.462 -			break;
   1.463 -		case IOREQ_TYPE_XOR:
   1.464 -			cpu_ioreq_xor(env, req);
   1.465 -			break;
   1.466 -		default:
   1.467 -			hw_error("Invalid ioreq type 0x%x", req->type);
   1.468 -		}
   1.469 +        switch (req->type) {
   1.470 +        case IOREQ_TYPE_PIO:
   1.471 +            cpu_ioreq_pio(env, req);
   1.472 +            break;
   1.473 +        case IOREQ_TYPE_COPY:
   1.474 +            cpu_ioreq_move(env, req);
   1.475 +            break;
   1.476 +        case IOREQ_TYPE_AND:
   1.477 +            cpu_ioreq_and(env, req);
   1.478 +            break;
   1.479 +        case IOREQ_TYPE_OR:
   1.480 +            cpu_ioreq_or(env, req);
   1.481 +            break;
   1.482 +        case IOREQ_TYPE_XOR:
   1.483 +            cpu_ioreq_xor(env, req);
   1.484 +            break;
   1.485 +        default:
   1.486 +            hw_error("Invalid ioreq type 0x%x\n", req->type);
   1.487 +        }
   1.488  
   1.489 -		/* No state change if state = STATE_IORESP_HOOK */
   1.490 -		if (req->state == STATE_IOREQ_INPROCESS)
   1.491 -			req->state = STATE_IORESP_READY;
   1.492 -		env->send_event = 1;
   1.493 -	}
   1.494 +        /* No state change if state = STATE_IORESP_HOOK */
   1.495 +        if (req->state == STATE_IOREQ_INPROCESS)
   1.496 +            req->state = STATE_IORESP_READY;
   1.497 +        env->send_event = 1;
   1.498 +    }
   1.499  }
   1.500  
   1.501  int xc_handle;
   1.502 @@ -393,7 +397,8 @@ void
   1.503  destroy_vmx_domain(void)
   1.504  {
   1.505      extern FILE* logfile;
   1.506 -    char destroy_cmd[20];
   1.507 +    char destroy_cmd[32];
   1.508 +
   1.509      sprintf(destroy_cmd, "xm destroy %d", domid);
   1.510      if (system(destroy_cmd) == -1)
   1.511          fprintf(logfile, "%s failed.!\n", destroy_cmd);
   1.512 @@ -403,40 +408,41 @@ fd_set wakeup_rfds;
   1.513  int    highest_fds;
   1.514  int main_loop(void)
   1.515  {
   1.516 - 	fd_set rfds;
   1.517 -	struct timeval tv;
   1.518 -	extern CPUState *global_env;
   1.519 -        extern int vm_running;
   1.520 -        extern int shutdown_requested;
   1.521 -	CPUState *env = global_env;
   1.522 -	int retval;
   1.523 -        extern void main_loop_wait(int);
   1.524 +    fd_set rfds;
   1.525 +    struct timeval tv;
   1.526 +    extern CPUState *global_env;
   1.527 +    extern int vm_running;
   1.528 +    extern int shutdown_requested;
   1.529 +    CPUState *env = global_env;
   1.530 +    int retval;
   1.531 +    extern void main_loop_wait(int);
   1.532 +
   1.533 +    /* Watch stdin (fd 0) to see when it has input. */
   1.534 +    FD_ZERO(&wakeup_rfds);
   1.535 +    FD_SET(evtchn_fd, &wakeup_rfds);
   1.536 +    highest_fds = evtchn_fd;
   1.537 +    env->send_event = 0;
   1.538  
   1.539 - 	/* Watch stdin (fd 0) to see when it has input. */
   1.540 -	FD_ZERO(&wakeup_rfds);
   1.541 -	FD_SET(evtchn_fd, &wakeup_rfds);
   1.542 -	highest_fds = evtchn_fd;
   1.543 -	env->send_event = 0;
   1.544 -	while (1) {
   1.545 -                if (vm_running) {
   1.546 -                    if (shutdown_requested) {
   1.547 -                        break;
   1.548 -                    }
   1.549 -                    if (reset_requested){
   1.550 -                        qemu_system_reset();
   1.551 -                        reset_requested = 0;
   1.552 -                    }
   1.553 -                }
   1.554 +    while (1) {
   1.555 +        if (vm_running) {
   1.556 +            if (shutdown_requested) {
   1.557 +                break;
   1.558 +            }
   1.559 +            if (reset_requested){
   1.560 +                qemu_system_reset();
   1.561 +                reset_requested = 0;
   1.562 +            }
   1.563 +        }
   1.564  
   1.565 -		/* Wait up to one seconds. */
   1.566 -		tv.tv_sec = 0;
   1.567 -		tv.tv_usec = 100000;
   1.568 +        /* Wait up to one seconds. */
   1.569 +        tv.tv_sec = 0;
   1.570 +        tv.tv_usec = 100000;
   1.571  
   1.572 -		retval = select(highest_fds+1, &wakeup_rfds, NULL, NULL, &tv);
   1.573 -		if (retval == -1) {
   1.574 -			perror("select");
   1.575 -			return 0;
   1.576 -		}
   1.577 +        retval = select(highest_fds+1, &wakeup_rfds, NULL, NULL, &tv);
   1.578 +        if (retval == -1) {
   1.579 +            fprintf(logfile, "select returned error %d\n", errno);
   1.580 +            return 0;
   1.581 +        }
   1.582          rfds = wakeup_rfds;
   1.583          FD_ZERO(&wakeup_rfds);
   1.584          FD_SET(evtchn_fd, &wakeup_rfds);
   1.585 @@ -451,65 +457,64 @@ int main_loop(void)
   1.586          if ( FD_ISSET(evtchn_fd, &rfds) ) {
   1.587              cpu_handle_ioreq(env);
   1.588          }
   1.589 -		main_loop_wait(0);
   1.590 -		if (env->send_event) {
   1.591 -		    env->send_event = 0;
   1.592 -			struct ioctl_evtchn_notify notify;
   1.593 -			notify.port = ioreq_local_port;
   1.594 -			(void)ioctl(evtchn_fd, IOCTL_EVTCHN_NOTIFY, &notify);
   1.595 -		}
   1.596 -	}
   1.597 -        destroy_vmx_domain();
   1.598 -	return 0;
   1.599 +        main_loop_wait(0);
   1.600 +
   1.601 +        if (env->send_event) {
   1.602 +            struct ioctl_evtchn_notify notify;
   1.603 +
   1.604 +            env->send_event = 0;
   1.605 +            notify.port = ioreq_local_port;
   1.606 +            (void)ioctl(evtchn_fd, IOCTL_EVTCHN_NOTIFY, &notify);
   1.607 +        }
   1.608 +    }
   1.609 +    destroy_vmx_domain();
   1.610 +    return 0;
   1.611  }
   1.612  
   1.613 -static void
   1.614 -qemu_vmx_reset(void *unused)
   1.615 +static void qemu_vmx_reset(void *unused)
   1.616  {
   1.617 -    char cmd[255];
   1.618 +    char cmd[64];
   1.619  
   1.620 -    /* pause domain first, to avoid repeated reboot request*/ 
   1.621 -    xc_domain_pause (xc_handle, domid);
   1.622 +    /* pause domain first, to avoid repeated reboot request*/
   1.623 +    xc_domain_pause(xc_handle, domid);
   1.624  
   1.625 -    sprintf(cmd,"xm shutdown -R %d", domid);
   1.626 -    system (cmd);
   1.627 +    sprintf(cmd, "xm shutdown -R %d", domid);
   1.628 +    system(cmd);
   1.629  }
   1.630  
   1.631 -CPUState *
   1.632 -cpu_init()
   1.633 +CPUState * cpu_init()
   1.634  {
   1.635 -	CPUX86State *env;
   1.636 -	struct ioctl_evtchn_bind_interdomain bind;
   1.637 -	int rc;
   1.638 -      
   1.639 -        cpu_exec_init();
   1.640 -        qemu_register_reset(qemu_vmx_reset, NULL);
   1.641 -	env = malloc(sizeof(CPUX86State));
   1.642 -	if (!env)
   1.643 -		return NULL;
   1.644 -	memset(env, 0, sizeof(CPUX86State));
   1.645 +    CPUX86State *env;
   1.646 +    struct ioctl_evtchn_bind_interdomain bind;
   1.647 +    int rc;
   1.648  
   1.649 -	cpu_single_env = env;
   1.650 +    cpu_exec_init();
   1.651 +    qemu_register_reset(qemu_vmx_reset, NULL);
   1.652 +    env = malloc(sizeof(CPUX86State));
   1.653 +    if (!env)
   1.654 +        return NULL;
   1.655 +    memset(env, 0, sizeof(CPUX86State));
   1.656  
   1.657 -	if (evtchn_fd != -1)//the evtchn has been opened by another cpu object
   1.658 -		return NULL;
   1.659 +    cpu_single_env = env;
   1.660 +
   1.661 +    if (evtchn_fd != -1)//the evtchn has been opened by another cpu object
   1.662 +        return NULL;
   1.663  
   1.664 -	//use nonblock reading not polling, may change in future.
   1.665 -	evtchn_fd = open("/dev/xen/evtchn", O_RDWR|O_NONBLOCK); 
   1.666 -	if (evtchn_fd == -1) {
   1.667 -		perror("open");
   1.668 -		return NULL;
   1.669 -	}
   1.670 +    //use nonblock reading not polling, may change in future.
   1.671 +    evtchn_fd = open("/dev/xen/evtchn", O_RDWR|O_NONBLOCK);
   1.672 +    if (evtchn_fd == -1) {
   1.673 +        fprintf(logfile, "open evtchn device error %d\n", errno);
   1.674 +        return NULL;
   1.675 +    }
   1.676  
   1.677 -	bind.remote_domain = domid;
   1.678 -	bind.remote_port   = ioreq_remote_port;
   1.679 -	rc = ioctl(evtchn_fd, IOCTL_EVTCHN_BIND_INTERDOMAIN, &bind);
   1.680 -	if (rc == -1) {
   1.681 -		perror("ioctl");
   1.682 -		return NULL;
   1.683 -	}
   1.684 -	ioreq_local_port = rc;
   1.685 +    bind.remote_domain = domid;
   1.686 +    bind.remote_port   = ioreq_remote_port;
   1.687 +    rc = ioctl(evtchn_fd, IOCTL_EVTCHN_BIND_INTERDOMAIN, &bind);
   1.688 +    if (rc == -1) {
   1.689 +        fprintf(logfile, "bind interdomain ioctl error %d\n", errno);
   1.690 +        return NULL;
   1.691 +    }
   1.692 +    ioreq_local_port = rc;
   1.693  
   1.694 -	return env;
   1.695 +    return env;
   1.696  }
   1.697 -
     2.1 --- a/tools/ioemu/vl.c	Thu Nov 24 11:03:07 2005 +0100
     2.2 +++ b/tools/ioemu/vl.c	Thu Nov 24 11:05:21 2005 +0100
     2.3 @@ -1,8 +1,8 @@
     2.4  /*
     2.5   * QEMU System Emulator
     2.6 - * 
     2.7 + *
     2.8   * Copyright (c) 2003-2004 Fabrice Bellard
     2.9 - * 
    2.10 + *
    2.11   * Permission is hereby granted, free of charge, to any person obtaining a copy
    2.12   * of this software and associated documentation files (the "Software"), to deal
    2.13   * in the Software without restriction, including without limitation the rights
    2.14 @@ -221,7 +221,7 @@ void init_ioports(void)
    2.15  }
    2.16  
    2.17  /* size is the word size in byte */
    2.18 -int register_ioport_read(int start, int length, int size, 
    2.19 +int register_ioport_read(int start, int length, int size,
    2.20                           IOPortReadFunc *func, void *opaque)
    2.21  {
    2.22      int i, bsize;
    2.23 @@ -246,7 +246,7 @@ int register_ioport_read(int start, int 
    2.24  }
    2.25  
    2.26  /* size is the word size in byte */
    2.27 -int register_ioport_write(int start, int length, int size, 
    2.28 +int register_ioport_write(int start, int length, int size,
    2.29                            IOPortWriteFunc *func, void *opaque)
    2.30  {
    2.31      int i, bsize;
    2.32 @@ -307,7 +307,7 @@ char *pstrcat(char *buf, int buf_size, c
    2.33  {
    2.34      int len;
    2.35      len = strlen(buf);
    2.36 -    if (len < buf_size) 
    2.37 +    if (len < buf_size)
    2.38          pstrcpy(buf + len, buf_size - len, s);
    2.39      return buf;
    2.40  }
    2.41 @@ -362,7 +362,7 @@ void cpu_outb(CPUState *env, int addr, i
    2.42  #ifdef DEBUG_IOPORT
    2.43      if (loglevel & CPU_LOG_IOPORT)
    2.44          fprintf(logfile, "outb: %04x %02x\n", addr, val);
    2.45 -#endif    
    2.46 +#endif
    2.47      ioport_write_table[0][addr](ioport_opaque[addr], addr, val);
    2.48  }
    2.49  
    2.50 @@ -371,7 +371,7 @@ void cpu_outw(CPUState *env, int addr, i
    2.51  #ifdef DEBUG_IOPORT
    2.52      if (loglevel & CPU_LOG_IOPORT)
    2.53          fprintf(logfile, "outw: %04x %04x\n", addr, val);
    2.54 -#endif    
    2.55 +#endif
    2.56      ioport_write_table[1][addr](ioport_opaque[addr], addr, val);
    2.57  }
    2.58  
    2.59 @@ -465,7 +465,7 @@ void kbd_put_keycode(int keycode)
    2.60  void kbd_mouse_event(int dx, int dy, int dz, int buttons_state)
    2.61  {
    2.62      if (qemu_put_mouse_event) {
    2.63 -        qemu_put_mouse_event(qemu_put_mouse_event_opaque, 
    2.64 +        qemu_put_mouse_event(qemu_put_mouse_event_opaque,
    2.65                               dx, dy, dz, buttons_state);
    2.66      }
    2.67  }
    2.68 @@ -475,14 +475,14 @@ void kbd_mouse_event(int dx, int dy, int
    2.69  
    2.70  #if defined(__powerpc__)
    2.71  
    2.72 -static inline uint32_t get_tbl(void) 
    2.73 +static inline uint32_t get_tbl(void)
    2.74  {
    2.75      uint32_t tbl;
    2.76      asm volatile("mftb %0" : "=r" (tbl));
    2.77      return tbl;
    2.78  }
    2.79  
    2.80 -static inline uint32_t get_tbu(void) 
    2.81 +static inline uint32_t get_tbu(void)
    2.82  {
    2.83  	uint32_t tbl;
    2.84  	asm volatile("mftbu %0" : "=r" (tbl));
    2.85 @@ -604,7 +604,7 @@ uint64_t muldiv64(uint64_t a, uint32_t b
    2.86              uint32_t high, low;
    2.87  #else
    2.88              uint32_t low, high;
    2.89 -#endif            
    2.90 +#endif
    2.91          } l;
    2.92      } u, res;
    2.93      uint64_t rl, rh;
    2.94 @@ -707,7 +707,7 @@ void qemu_mod_timer(QEMUTimer *ts, int64
    2.95          t = *pt;
    2.96          if (!t)
    2.97              break;
    2.98 -        if (t->expire_time > expire_time) 
    2.99 +        if (t->expire_time > expire_time)
   2.100              break;
   2.101          pt = &t->next;
   2.102      }
   2.103 @@ -736,7 +736,7 @@ static inline int qemu_timer_expired(QEM
   2.104  static void qemu_run_timers(QEMUTimer **ptimer_head, int64_t current_time)
   2.105  {
   2.106      QEMUTimer *ts;
   2.107 -    
   2.108 +
   2.109      for(;;) {
   2.110          ts = *ptimer_head;
   2.111          if (!ts || ts->expire_time > current_time)
   2.112 @@ -744,7 +744,7 @@ static void qemu_run_timers(QEMUTimer **
   2.113          /* remove timer from the list before calling the callback */
   2.114          *ptimer_head = ts->next;
   2.115          ts->next = NULL;
   2.116 -        
   2.117 +
   2.118          /* run the callback (the timer list can be modified) */
   2.119          ts->cb(ts->opaque);
   2.120      }
   2.121 @@ -814,17 +814,17 @@ static void init_timers(void)
   2.122                                 host_alarm_handler, // function
   2.123                                 (DWORD)&count,  // user parameter
   2.124                                 TIME_PERIODIC | TIME_CALLBACK_FUNCTION);
   2.125 - 	if( !timerID ) {
   2.126 -            perror("failed timer alarm");
   2.127 +        if( !timerID ) {
   2.128 +            fprintf(logfile, "failed timer alarm");
   2.129              exit(1);
   2.130 - 	}
   2.131 +        }
   2.132      }
   2.133      pit_min_timer_count = ((uint64_t)10000 * PIT_FREQ) / 1000000;
   2.134  #else
   2.135      {
   2.136          /* get times() syscall frequency */
   2.137          timer_freq = sysconf(_SC_CLK_TCK);
   2.138 -      
   2.139 +
   2.140  #ifndef TARGET_VMX
   2.141          /* timer signal */
   2.142          sigfillset(&act.sa_mask);
   2.143 @@ -860,11 +860,11 @@ static void init_timers(void)
   2.144              sigaction(SIGIO, &act, NULL);
   2.145              fcntl(rtc_fd, F_SETFL, O_ASYNC);
   2.146              fcntl(rtc_fd, F_SETOWN, getpid());
   2.147 -        } else 
   2.148 +        } else
   2.149  #endif /* defined(__linux__) */
   2.150          {
   2.151          use_itimer:
   2.152 -            pit_min_timer_count = ((uint64_t)itv.it_interval.tv_usec * 
   2.153 +            pit_min_timer_count = ((uint64_t)itv.it_interval.tv_usec *
   2.154                                     PIT_FREQ) / 1000000;
   2.155          }
   2.156  #endif /* TARGET_VMX */
   2.157 @@ -903,13 +903,13 @@ void qemu_chr_send_event(CharDriverState
   2.158          s->chr_send_event(s, event);
   2.159  }
   2.160  
   2.161 -void qemu_chr_add_read_handler(CharDriverState *s, 
   2.162 -                               IOCanRWHandler *fd_can_read, 
   2.163 +void qemu_chr_add_read_handler(CharDriverState *s,
   2.164 +                               IOCanRWHandler *fd_can_read,
   2.165                                 IOReadHandler *fd_read, void *opaque)
   2.166  {
   2.167      s->chr_add_read_handler(s, fd_can_read, fd_read, opaque);
   2.168  }
   2.169 -             
   2.170 +
   2.171  void qemu_chr_add_event_handler(CharDriverState *s, IOEventHandler *chr_event)
   2.172  {
   2.173      s->chr_event = chr_event;
   2.174 @@ -920,8 +920,8 @@ static int null_chr_write(CharDriverStat
   2.175      return len;
   2.176  }
   2.177  
   2.178 -static void null_chr_add_read_handler(CharDriverState *chr, 
   2.179 -                                    IOCanRWHandler *fd_can_read, 
   2.180 +static void null_chr_add_read_handler(CharDriverState *chr,
   2.181 +                                    IOCanRWHandler *fd_can_read,
   2.182                                      IOReadHandler *fd_read, void *opaque)
   2.183  {
   2.184  }
   2.185 @@ -943,7 +943,7 @@ CharDriverState *qemu_chr_open_null(void
   2.186  typedef struct {
   2.187      int fd_in, fd_out;
   2.188      /* for nographic stdio only */
   2.189 -    IOCanRWHandler *fd_can_read; 
   2.190 +    IOCanRWHandler *fd_can_read;
   2.191      IOReadHandler *fd_read;
   2.192      void *fd_opaque;
   2.193  } FDCharDriver;
   2.194 @@ -979,8 +979,8 @@ static int fd_chr_write(CharDriverState 
   2.195      return unix_write(s->fd_out, buf, len);
   2.196  }
   2.197  
   2.198 -static void fd_chr_add_read_handler(CharDriverState *chr, 
   2.199 -                                    IOCanRWHandler *fd_can_read, 
   2.200 +static void fd_chr_add_read_handler(CharDriverState *chr,
   2.201 +                                    IOCanRWHandler *fd_can_read,
   2.202                                      IOReadHandler *fd_read, void *opaque)
   2.203  {
   2.204      FDCharDriver *s = chr->opaque;
   2.205 @@ -1047,7 +1047,7 @@ static void stdio_received_byte(int ch)
   2.206          case 'x':
   2.207              exit(0);
   2.208              break;
   2.209 -        case 's': 
   2.210 +        case 's':
   2.211              {
   2.212                  int i;
   2.213                  for (i = 0; i < MAX_DISKS; i++) {
   2.214 @@ -1087,13 +1087,13 @@ static void stdio_received_byte(int ch)
   2.215              uint8_t buf[1];
   2.216              CharDriverState *chr;
   2.217              FDCharDriver *s;
   2.218 -            
   2.219 +
   2.220              chr = stdio_clients[client_index];
   2.221              s = chr->opaque;
   2.222              buf[0] = ch;
   2.223              /* XXX: should queue the char if the device is not
   2.224                 ready */
   2.225 -            if (s->fd_can_read(s->fd_opaque) > 0) 
   2.226 +            if (s->fd_can_read(s->fd_opaque) > 0)
   2.227                  s->fd_read(s->fd_opaque, buf, 1);
   2.228          }
   2.229      }
   2.230 @@ -1141,7 +1141,7 @@ static void term_init(void)
   2.231      tty.c_cflag |= CS8;
   2.232      tty.c_cc[VMIN] = 1;
   2.233      tty.c_cc[VTIME] = 0;
   2.234 -    
   2.235 +
   2.236      tcsetattr (0, TCSANOW, &tty);
   2.237  
   2.238      atexit(term_exit);
   2.239 @@ -1191,7 +1191,7 @@ int store_console_dev(int domid, char *p
   2.240          fprintf(logfile, "xc_interface_open() error\n");
   2.241          return -1;
   2.242      }
   2.243 -    
   2.244 +
   2.245      path = xs_get_domain_path(xs, domid);
   2.246      if (path == NULL) {
   2.247          fprintf(logfile, "xs_get_domain_path() error\n");
   2.248 @@ -1207,7 +1207,7 @@ int store_console_dev(int domid, char *p
   2.249          fprintf(logfile, "xs_write for console fail");
   2.250          return -1;
   2.251      }
   2.252 -    
   2.253 +
   2.254      free(path);
   2.255      xs_daemon_close(xs);
   2.256      close(xc_handle);
   2.257 @@ -1220,7 +1220,7 @@ CharDriverState *qemu_chr_open_pty(void)
   2.258  {
   2.259      char slave_name[1024];
   2.260      int master_fd, slave_fd;
   2.261 -    
   2.262 +
   2.263      /* Not satisfying */
   2.264      if (openpty(&master_fd, &slave_fd, slave_name, NULL, NULL) < 0) {
   2.265          return NULL;
   2.266 @@ -1244,13 +1244,13 @@ CharDriverState *qemu_chr_open(const cha
   2.267          return text_console_init(&display_state);
   2.268      } else if (!strcmp(filename, "null")) {
   2.269          return qemu_chr_open_null();
   2.270 -    } else 
   2.271 +    } else
   2.272  #ifndef _WIN32
   2.273      if (!strcmp(filename, "pty")) {
   2.274          return qemu_chr_open_pty();
   2.275      } else if (!strcmp(filename, "stdio")) {
   2.276          return qemu_chr_open_stdio();
   2.277 -    } else 
   2.278 +    } else
   2.279  #endif
   2.280      {
   2.281          return NULL;
   2.282 @@ -1291,7 +1291,7 @@ void qemu_send_packet(NetDriverState *nd
   2.283      nd->send_packet(nd, buf, size);
   2.284  }
   2.285  
   2.286 -void qemu_add_read_packet(NetDriverState *nd, IOCanRWHandler *fd_can_read, 
   2.287 +void qemu_add_read_packet(NetDriverState *nd, IOCanRWHandler *fd_can_read,
   2.288                            IOReadHandler *fd_read, void *opaque)
   2.289  {
   2.290      nd->add_read_packet(nd, fd_can_read, fd_read, opaque);
   2.291 @@ -1303,8 +1303,8 @@ static void dummy_send_packet(NetDriverS
   2.292  {
   2.293  }
   2.294  
   2.295 -static void dummy_add_read_packet(NetDriverState *nd, 
   2.296 -                                  IOCanRWHandler *fd_can_read, 
   2.297 +static void dummy_add_read_packet(NetDriverState *nd,
   2.298 +                                  IOCanRWHandler *fd_can_read,
   2.299                                    IOReadHandler *fd_read, void *opaque)
   2.300  {
   2.301  }
   2.302 @@ -1349,8 +1349,8 @@ static void slirp_send_packet(NetDriverS
   2.303      slirp_input(buf, size);
   2.304  }
   2.305  
   2.306 -static void slirp_add_read_packet(NetDriverState *nd, 
   2.307 -                                  IOCanRWHandler *fd_can_read, 
   2.308 +static void slirp_add_read_packet(NetDriverState *nd,
   2.309 +                                  IOCanRWHandler *fd_can_read,
   2.310                                    IOReadHandler *fd_read, void *opaque)
   2.311  {
   2.312      slirp_fd_opaque = opaque;
   2.313 @@ -1397,7 +1397,7 @@ static void net_slirp_redir(const char *
   2.314      const char *p;
   2.315      struct in_addr guest_addr;
   2.316      int host_port, guest_port;
   2.317 -    
   2.318 +
   2.319      if (!slirp_inited) {
   2.320          slirp_inited = 1;
   2.321          slirp_init();
   2.322 @@ -1427,11 +1427,11 @@ static void net_slirp_redir(const char *
   2.323      }
   2.324      if (!inet_aton(buf, &guest_addr))
   2.325          goto fail;
   2.326 -    
   2.327 +
   2.328      guest_port = strtol(p, &r, 0);
   2.329      if (r == p)
   2.330          goto fail;
   2.331 -    
   2.332 +
   2.333      if (slirp_redir(is_udp, host_port, guest_addr, guest_port) < 0) {
   2.334          fprintf(stderr, "qemu: could not set up redirection\n");
   2.335          exit(1);
   2.336 @@ -1441,7 +1441,7 @@ static void net_slirp_redir(const char *
   2.337      fprintf(stderr, "qemu: syntax: -redir [tcp|udp]:host-port:[guest-host]:guest-port\n");
   2.338      exit(1);
   2.339  }
   2.340 -    
   2.341 +
   2.342  #ifndef _WIN32
   2.343  
   2.344  char smb_dir[1024];
   2.345 @@ -1460,7 +1460,7 @@ static void smb_exit(void)
   2.346              break;
   2.347          if (strcmp(de->d_name, ".") != 0 &&
   2.348              strcmp(de->d_name, "..") != 0) {
   2.349 -            snprintf(filename, sizeof(filename), "%s/%s", 
   2.350 +            snprintf(filename, sizeof(filename), "%s/%s",
   2.351                       smb_dir, de->d_name);
   2.352              unlink(filename);
   2.353          }
   2.354 @@ -1488,13 +1488,13 @@ void net_slirp_smb(const char *exported_
   2.355          exit(1);
   2.356      }
   2.357      snprintf(smb_conf, sizeof(smb_conf), "%s/%s", smb_dir, "smb.conf");
   2.358 -    
   2.359 +
   2.360      f = fopen(smb_conf, "w");
   2.361      if (!f) {
   2.362          fprintf(stderr, "qemu: could not create samba server configuration file '%s'\n", smb_conf);
   2.363          exit(1);
   2.364      }
   2.365 -    fprintf(f, 
   2.366 +    fprintf(f,
   2.367              "[global]\n"
   2.368              "pid directory=%s\n"
   2.369              "lock directory=%s\n"
   2.370 @@ -1516,7 +1516,7 @@ void net_slirp_smb(const char *exported_
   2.371  
   2.372      snprintf(smb_cmdline, sizeof(smb_cmdline), "/usr/sbin/smbd -s %s",
   2.373               smb_conf);
   2.374 -    
   2.375 +
   2.376      slirp_add_exec(0, smb_cmdline, 4, 139);
   2.377  }
   2.378  
   2.379 @@ -1550,7 +1550,7 @@ static int tun_open(char *ifname, int if
   2.380  {
   2.381      struct ifreq ifr;
   2.382      int fd, ret;
   2.383 -    
   2.384 +
   2.385      fd = open("/dev/net/tun", O_RDWR);
   2.386      if (fd < 0) {
   2.387          fprintf(stderr, "warning: could not open /dev/net/tun: no virtual network emulation\n");
   2.388 @@ -1565,7 +1565,7 @@ static int tun_open(char *ifname, int if
   2.389          close(fd);
   2.390          return -1;
   2.391      }
   2.392 -    printf("Connected to host network interface: %s\n", ifr.ifr_name);
   2.393 +    fprintf(logfile, "Connected to host network interface: %s\n", ifr.ifr_name);
   2.394      pstrcpy(ifname, ifname_size, ifr.ifr_name);
   2.395      fcntl(fd, F_SETFL, O_NONBLOCK);
   2.396      return fd;
   2.397 @@ -1577,8 +1577,8 @@ static void tun_send_packet(NetDriverSta
   2.398      write(nd->fd, buf, size);
   2.399  }
   2.400  
   2.401 -static void tun_add_read_packet(NetDriverState *nd, 
   2.402 -                                IOCanRWHandler *fd_can_read, 
   2.403 +static void tun_add_read_packet(NetDriverState *nd,
   2.404 +                                IOCanRWHandler *fd_can_read,
   2.405                                  IOReadHandler *fd_read, void *opaque)
   2.406  {
   2.407      qemu_add_fd_event_read_handler(nd->fd, fd_can_read, fd_read, opaque);
   2.408 @@ -1660,7 +1660,7 @@ void dumb_display_init(DisplayState *ds)
   2.409  #if !defined(CONFIG_SOFTMMU)
   2.410  /***********************************************************/
   2.411  /* cpu signal handler */
   2.412 -static void host_segv_handler(int host_signum, siginfo_t *info, 
   2.413 +static void host_segv_handler(int host_signum, siginfo_t *info,
   2.414                                void *puc)
   2.415  {
   2.416      abort();
   2.417 @@ -1686,7 +1686,7 @@ typedef struct IOHandlerRecord {
   2.418  static IOHandlerRecord *first_io_handler;
   2.419  static IOHandlerRecord *first_eventio_handler;
   2.420  
   2.421 -int qemu_add_fd_read_handler(int fd, IOCanRWHandler *fd_can_read, 
   2.422 +int qemu_add_fd_read_handler(int fd, IOCanRWHandler *fd_can_read,
   2.423                               IOReadHandler *fd_read, void *opaque)
   2.424  {
   2.425      IOHandlerRecord *ioh;
   2.426 @@ -1703,7 +1703,7 @@ int qemu_add_fd_read_handler(int fd, IOC
   2.427      return 0;
   2.428  }
   2.429  
   2.430 -int qemu_add_fd_event_read_handler(int fd, IOCanRWHandler *fd_can_read, 
   2.431 +int qemu_add_fd_event_read_handler(int fd, IOCanRWHandler *fd_can_read,
   2.432                               IOReadHandler *fd_read, void *opaque)
   2.433  {
   2.434      IOHandlerRecord *ioh;
   2.435 @@ -1835,8 +1835,8 @@ typedef struct SaveStateEntry {
   2.436  
   2.437  static SaveStateEntry *first_se;
   2.438  
   2.439 -int register_savevm(const char *idstr, 
   2.440 -                    int instance_id, 
   2.441 +int register_savevm(const char *idstr,
   2.442 +                    int instance_id,
   2.443                      int version_id,
   2.444                      SaveStateHandler *save_state,
   2.445                      LoadStateHandler *load_state,
   2.446 @@ -1896,7 +1896,7 @@ int qemu_savevm(const char *filename)
   2.447          /* record size: filled later */
   2.448          len_pos = ftell(f);
   2.449          qemu_put_be32(f, 0);
   2.450 -        
   2.451 +
   2.452          se->save_state(f, se->opaque);
   2.453  
   2.454          /* fill record size */
   2.455 @@ -1920,7 +1920,7 @@ static SaveStateEntry *find_se(const cha
   2.456      SaveStateEntry *se;
   2.457  
   2.458      for(se = first_se; se != NULL; se = se->next) {
   2.459 -        if (!strcmp(se->idstr, idstr) && 
   2.460 +        if (!strcmp(se->idstr, idstr) &&
   2.461              instance_id == se->instance_id)
   2.462              return se;
   2.463      }
   2.464 @@ -1935,7 +1935,7 @@ int qemu_loadvm(const char *filename)
   2.465      int saved_vm_running;
   2.466      unsigned int v;
   2.467      char idstr[256];
   2.468 -    
   2.469 +
   2.470      saved_vm_running = vm_running;
   2.471      vm_stop(0);
   2.472  
   2.473 @@ -1968,18 +1968,18 @@ int qemu_loadvm(const char *filename)
   2.474          version_id = qemu_get_be32(f);
   2.475          record_len = qemu_get_be32(f);
   2.476  #if 0
   2.477 -        printf("idstr=%s instance=0x%x version=%d len=%d\n", 
   2.478 +        printf("idstr=%s instance=0x%x version=%d len=%d\n",
   2.479                 idstr, instance_id, version_id, record_len);
   2.480  #endif
   2.481          cur_pos = ftell(f);
   2.482          se = find_se(idstr, instance_id);
   2.483          if (!se) {
   2.484 -            fprintf(stderr, "qemu: warning: instance 0x%x of device '%s' not present in current VM\n", 
   2.485 +            fprintf(stderr, "qemu: warning: instance 0x%x of device '%s' not present in current VM\n",
   2.486                      instance_id, idstr);
   2.487          } else {
   2.488              ret = se->load_state(f, se->opaque, version_id);
   2.489              if (ret < 0) {
   2.490 -                fprintf(stderr, "qemu: warning: error while loading state for instance 0x%x of device '%s'\n", 
   2.491 +                fprintf(stderr, "qemu: warning: error while loading state for instance 0x%x of device '%s'\n",
   2.492                          instance_id, idstr);
   2.493              }
   2.494          }
   2.495 @@ -2042,7 +2042,7 @@ void polling_handler(void *opaque)
   2.496              }
   2.497              ioh->max_size = max_size;
   2.498          }
   2.499 -        
   2.500 +
   2.501          ret = poll(ufds, pf - ufds, timeout);
   2.502          if (ret > 0) {
   2.503              /* XXX: better handling of removal */
   2.504 @@ -2096,7 +2096,7 @@ void vm_start(void)
   2.505      }
   2.506  }
   2.507  
   2.508 -void vm_stop(int reason) 
   2.509 +void vm_stop(int reason)
   2.510  {
   2.511      if (vm_running) {
   2.512          cpu_disable_ticks();
   2.513 @@ -2160,14 +2160,14 @@ void qemu_system_shutdown_request(void)
   2.514  void main_loop_wait(int timeout)
   2.515  {
   2.516          if (vm_running) {
   2.517 -            qemu_run_timers(&active_timers[QEMU_TIMER_VIRTUAL], 
   2.518 +            qemu_run_timers(&active_timers[QEMU_TIMER_VIRTUAL],
   2.519                              qemu_get_clock(vm_clock));
   2.520              /* run dma transfers, if any */
   2.521              DMA_run();
   2.522          }
   2.523  
   2.524          /* real time timers */
   2.525 -        qemu_run_timers(&active_timers[QEMU_TIMER_REALTIME], 
   2.526 +        qemu_run_timers(&active_timers[QEMU_TIMER_REALTIME],
   2.527                          qemu_get_clock(rt_clock));
   2.528  }
   2.529  
   2.530 @@ -2184,19 +2184,19 @@ void help(void)
   2.531             "-hdc/-hdd file  use 'file' as IDE hard disk 2/3 image\n"
   2.532             "-cdrom file     use 'file' as IDE cdrom image (cdrom is ide1 master)\n"
   2.533             "-boot [a|c|d]   boot on floppy (a), hard disk (c) or CD-ROM (d)\n"
   2.534 -	   "-snapshot       write to temporary files instead of disk image files\n"
   2.535 +           "-snapshot       write to temporary files instead of disk image files\n"
   2.536             "-m megs         set virtual RAM size to megs MB [default=%d]\n"
   2.537             "-nographic      disable graphical output and redirect serial I/Os to console\n"
   2.538             "-vcpus          set CPU number of guest platform\n"
   2.539  #ifdef CONFIG_VNC
   2.540 -	   "-vnc port             use vnc instead of sdl\n"
   2.541 -	   "-vncport port         use a different port\n"
   2.542 -	   "-vncconnect host:port do a reverse connect\n"
   2.543 +           "-vnc port             use vnc instead of sdl\n"
   2.544 +           "-vncport port         use a different port\n"
   2.545 +           "-vncconnect host:port do a reverse connect\n"
   2.546  #ifdef CONFIG_SDL
   2.547 -	   "-vnc-and-sdl    use vnc and sdl simultaneously\n"
   2.548 +           "-vnc-and-sdl    use vnc and sdl simultaneously\n"
   2.549  #endif
   2.550  #endif
   2.551 -	   "-k <language>   use keyboard layout (for example \"fr\" for french)\n"
   2.552 +           "-k <language>   use keyboard layout (for example \"fr\" for french)\n"
   2.553             "-enable-audio   enable audio support\n"
   2.554             "-localtime      set the real time clock to local time [default=utc]\n"
   2.555             "-full-screen    start in full screen\n"
   2.556 @@ -2234,7 +2234,7 @@ void help(void)
   2.557             "-S              freeze CPU at startup (use 'c' to start execution)\n"
   2.558             "-s              wait gdb connection to port %d\n"
   2.559             "-p port         ioreq port for xen\n"
   2.560 -           "-d domain	    domain that we're serving\n"
   2.561 +           "-d domain       domain that we're serving\n"
   2.562             "-hdachs c,h,s   force hard disk 0 geometry (usually qemu can guess it)\n"
   2.563             "-L path         set the directory for the BIOS and VGA BIOS\n"
   2.564  #ifdef USE_CODE_COPY
   2.565 @@ -2408,7 +2408,7 @@ const QEMUOption qemu_options[] = {
   2.566      { "serial", 1, QEMU_OPTION_serial },
   2.567      { "loadvm", HAS_ARG, QEMU_OPTION_loadvm },
   2.568      { "full-screen", 0, QEMU_OPTION_full_screen },
   2.569 -    
   2.570 +
   2.571      /* temporary options */
   2.572      { "pci", 0, QEMU_OPTION_pci },
   2.573      { "nic-ne2000", 0, QEMU_OPTION_nic_ne2000 },
   2.574 @@ -2460,7 +2460,9 @@ get_vl2_table(unsigned long count, unsig
   2.575  }
   2.576  
   2.577  int
   2.578 -setup_mapping(int xc_handle, uint32_t dom, unsigned long toptab, unsigned long  *mem_page_array, unsigned long *page_table_array, unsigned long v_start, unsigned long v_end)
   2.579 +setup_mapping(int xc_handle, uint32_t dom, unsigned long toptab,
   2.580 +              unsigned long  *mem_page_array, unsigned long *page_table_array,
   2.581 +              unsigned long v_start, unsigned long v_end)
   2.582  {
   2.583      l1_pgentry_t *vl1tab=NULL, *vl1e=NULL;
   2.584      l2_pgentry_t *vl2tab[4] = {NULL, NULL, NULL, NULL};
   2.585 @@ -2472,23 +2474,24 @@ setup_mapping(int xc_handle, uint32_t do
   2.586  #if _LEVEL_3_
   2.587      l3_pgentry_t *vl3tab = NULL;
   2.588      unsigned long l2tab;
   2.589 -    if ( (vl3tab = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE, 
   2.590 -                                        PROT_READ|PROT_WRITE, 
   2.591 +
   2.592 +    if ( (vl3tab = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE,
   2.593 +                                        PROT_READ|PROT_WRITE,
   2.594                                          toptab >> PAGE_SHIFT)) == NULL )
   2.595          goto error_out;
   2.596      for (i = 0; i < 4 ; i++) {
   2.597          l2tab = vl3tab[i] & PAGE_MASK;
   2.598          vl2tab[i] = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE,
   2.599 -          PROT_READ|PROT_WRITE,
   2.600 -          l2tab >> PAGE_SHIFT);
   2.601 +                                         PROT_READ|PROT_WRITE,
   2.602 +                                         l2tab >> PAGE_SHIFT);
   2.603          if(vl2tab[i] == NULL)
   2.604              goto error_out;
   2.605      }
   2.606      munmap(vl3tab, PAGE_SIZE);
   2.607      vl3tab = NULL;
   2.608  #else
   2.609 -    if ( (vl2tab[0] = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE, 
   2.610 -                                           PROT_READ|PROT_WRITE, 
   2.611 +    if ( (vl2tab[0] = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE,
   2.612 +                                           PROT_READ|PROT_WRITE,
   2.613                                             toptab >> PAGE_SHIFT)) == NULL )
   2.614          goto error_out;
   2.615  #endif
   2.616 @@ -2498,8 +2501,8 @@ setup_mapping(int xc_handle, uint32_t do
   2.617          if ( ((unsigned long)vl1e & (PAGE_SIZE-1)) == 0 )
   2.618          {
   2.619              vl2_table = vl2tab[get_vl2_table(count, v_start)];
   2.620 -            vl2e = &vl2_table[l2_table_offset(
   2.621 -                v_start + (count << PAGE_SHIFT))];
   2.622 +            vl2e = &vl2_table[l2_table_offset(v_start +
   2.623 +                                              (count << PAGE_SHIFT))];
   2.624  
   2.625              l1tab = page_table_array[ppt_alloc++] << PAGE_SHIFT;
   2.626              if ( vl1tab != NULL )
   2.627 @@ -2520,14 +2523,16 @@ setup_mapping(int xc_handle, uint32_t do
   2.628          vl1e++;
   2.629      }
   2.630  error_out:
   2.631 -    if(vl1tab)  munmap(vl1tab, PAGE_SIZE);
   2.632 +    if (vl1tab)
   2.633 +        munmap(vl1tab, PAGE_SIZE);
   2.634      for(i = 0; i < 4; i++)
   2.635          if(vl2tab[i]) munmap(vl2tab[i], PAGE_SIZE);
   2.636      return ppt_alloc;
   2.637  }
   2.638  
   2.639  void
   2.640 -unsetup_mapping(int xc_handle, uint32_t dom, unsigned long toptab, unsigned long v_start, unsigned long v_end)
   2.641 +unsetup_mapping(int xc_handle, uint32_t dom, unsigned long toptab,
   2.642 +                unsigned long v_start, unsigned long v_end)
   2.643  {
   2.644      l1_pgentry_t *vl1tab=NULL, *vl1e=NULL;
   2.645      l2_pgentry_t *vl2tab[4], *vl2e=NULL, *vl2_table = NULL;
   2.646 @@ -2537,28 +2542,29 @@ unsetup_mapping(int xc_handle, uint32_t 
   2.647  #if _LEVEL_3_
   2.648      l3_pgentry_t *vl3tab = NULL;
   2.649      unsigned long l2tab;
   2.650 -    if ( (vl3tab = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE, 
   2.651 -                                        PROT_READ|PROT_WRITE, 
   2.652 +
   2.653 +    if ( (vl3tab = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE,
   2.654 +                                        PROT_READ|PROT_WRITE,
   2.655                                          toptab >> PAGE_SHIFT)) == NULL )
   2.656          goto error_out;
   2.657 -    for (i = 0; i < 4 ; i ++){
   2.658 +    for (i = 0; i < 4 ; i ++) {
   2.659          l2tab = vl3tab[i] & PAGE_MASK;
   2.660          vl2tab[i] = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE,
   2.661 -          PROT_READ|PROT_WRITE,
   2.662 -          l2tab >> PAGE_SHIFT);
   2.663 -        if(vl2tab[i] == NULL)
   2.664 +                                         PROT_READ|PROT_WRITE,
   2.665 +                                         l2tab >> PAGE_SHIFT);
   2.666 +        if (vl2tab[i] == NULL)
   2.667              goto error_out;
   2.668      }
   2.669      munmap(vl3tab, PAGE_SIZE);
   2.670      vl3tab = NULL;
   2.671  #else
   2.672 -    if ( (vl2tab[0] = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE, 
   2.673 -                                        PROT_READ|PROT_WRITE, 
   2.674 -                                        toptab >> PAGE_SHIFT)) == NULL )
   2.675 +    if ( (vl2tab[0] = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE,
   2.676 +                                           PROT_READ|PROT_WRITE,
   2.677 +                                           toptab >> PAGE_SHIFT)) == NULL )
   2.678          goto error_out;
   2.679  #endif
   2.680  
   2.681 -    for ( count = 0; count < ((v_end-v_start)>>PAGE_SHIFT); count++ ){
   2.682 +    for ( count = 0; count < ((v_end-v_start)>>PAGE_SHIFT); count++ ) {
   2.683          if ( ((unsigned long)vl1e & (PAGE_SIZE-1)) == 0 )
   2.684          {
   2.685              vl2_table = vl2tab[get_vl2_table(count, v_start)];
   2.686 @@ -2571,8 +2577,8 @@ unsetup_mapping(int xc_handle, uint32_t 
   2.687                  munmap(vl1tab, PAGE_SIZE);
   2.688  
   2.689              if ( (vl1tab = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE,
   2.690 -                      PROT_READ|PROT_WRITE,
   2.691 -                      l1tab >> PAGE_SHIFT)) == NULL )
   2.692 +                                                PROT_READ|PROT_WRITE,
   2.693 +                                                l1tab >> PAGE_SHIFT)) == NULL )
   2.694              {
   2.695                  goto error_out;
   2.696              }
   2.697 @@ -2583,17 +2589,20 @@ unsetup_mapping(int xc_handle, uint32_t 
   2.698          *vl1e = 0;
   2.699          vl1e++;
   2.700      }
   2.701 +
   2.702  error_out:
   2.703 -    if(vl1tab)  munmap(vl1tab, PAGE_SIZE);
   2.704 +    if (vl1tab)
   2.705 +        munmap(vl1tab, PAGE_SIZE);
   2.706      for(i = 0; i < 4; i++)
   2.707 -        if(vl2tab[i]) munmap(vl2tab[i], PAGE_SIZE);
   2.708 +        if (vl2tab[i])
   2.709 +            munmap(vl2tab[i], PAGE_SIZE);
   2.710  }
   2.711  
   2.712  void set_vram_mapping(unsigned long addr, unsigned long end)
   2.713  {
   2.714      end = addr + VGA_RAM_SIZE;
   2.715      setup_mapping(xc_handle, domid, toptab,
   2.716 -      vgapage_array, freepage_array, addr, end);
   2.717 +                  vgapage_array, freepage_array, addr, end);
   2.718  }
   2.719  
   2.720  void unset_vram_mapping(unsigned long addr, unsigned long end)
   2.721 @@ -2633,9 +2642,7 @@ int main(int argc, char **argv)
   2.722      unsigned long nr_pages, extra_pages, ram_pages, *page_array;
   2.723      extern void *shared_page;
   2.724      extern void *shared_vram;
   2.725 -    /* change the qemu-dm to daemon, just like bochs dm */
   2.726 -//    daemon(0, 0);
   2.727 -    
   2.728 +
   2.729  #if !defined(CONFIG_SOFTMMU)
   2.730      /* we never want that malloc() uses mmap() */
   2.731      mallopt(M_MMAP_THRESHOLD, 4096 * 1024);
   2.732 @@ -2668,7 +2675,7 @@ int main(int argc, char **argv)
   2.733      for(i = 1; i < MAX_SERIAL_PORTS; i++)
   2.734          serial_devices[i][0] = '\0';
   2.735      serial_device_index = 0;
   2.736 -    
   2.737 +
   2.738      nb_tun_fds = 0;
   2.739      net_if_type = -1;
   2.740      nb_nics = 1;
   2.741 @@ -2679,7 +2686,7 @@ int main(int argc, char **argv)
   2.742      macaddr[3] = 0x12;
   2.743      macaddr[4] = 0x34;
   2.744      macaddr[5] = 0x56;
   2.745 -    
   2.746 +
   2.747      /* init debug */
   2.748      cpu_set_log(0);
   2.749  
   2.750 @@ -2697,7 +2704,7 @@ int main(int argc, char **argv)
   2.751              popt = qemu_options;
   2.752              for(;;) {
   2.753                  if (!popt->name) {
   2.754 -                    fprintf(stderr, "%s: invalid option -- '%s'\n", 
   2.755 +                    fprintf(stderr, "%s: invalid option -- '%s'\n",
   2.756                              argv[0], r);
   2.757                      exit(1);
   2.758                  }
   2.759 @@ -2756,25 +2763,23 @@ int main(int argc, char **argv)
   2.760                  nographic = 1;
   2.761                  break;
   2.762  #ifdef CONFIG_VNC
   2.763 -	    case QEMU_OPTION_vnc:
   2.764 -            usevnc = 1;
   2.765 -            break;  
   2.766 -	    case QEMU_OPTION_vncport:
   2.767 -        {
   2.768 -            const char *p;
   2.769 -            p = optarg;
   2.770 -            vncport= strtol(optarg, (char **)&p, 0);
   2.771 -        }
   2.772 -        break;
   2.773 -	    case QEMU_OPTION_vncconnect:
   2.774 -        {
   2.775 -            vncconnect=optarg;
   2.776 -        }
   2.777 -        break;
   2.778 +            case QEMU_OPTION_vnc:
   2.779 +                usevnc = 1;
   2.780 +                break;
   2.781 +            case QEMU_OPTION_vncport:
   2.782 +                {
   2.783 +                    const char *p;
   2.784 +                    p = optarg;
   2.785 +                    vncport= strtol(optarg, (char **)&p, 0);
   2.786 +                }
   2.787 +                break;
   2.788 +            case QEMU_OPTION_vncconnect:
   2.789 +                vncconnect = optarg;
   2.790 +                break;
   2.791  #ifdef CONFIG_SDL
   2.792 -	    case QEMU_OPTION_vnc_and_sdl:
   2.793 -		usevnc = 2;
   2.794 -		break;
   2.795 +            case QEMU_OPTION_vnc_and_sdl:
   2.796 +                usevnc = 2;
   2.797 +                break;
   2.798  #endif
   2.799  #endif
   2.800              case QEMU_OPTION_kernel:
   2.801 @@ -2783,21 +2788,23 @@ int main(int argc, char **argv)
   2.802              case QEMU_OPTION_append:
   2.803                  kernel_cmdline = optarg;
   2.804                  break;
   2.805 -	    case QEMU_OPTION_tun_fd:
   2.806 +            case QEMU_OPTION_tun_fd:
   2.807                  {
   2.808                      const char *p;
   2.809                      int fd;
   2.810                      net_if_type = NET_IF_TUN;
   2.811 -                    if (nb_tun_fds < MAX_NICS) {
   2.812 +                    if ( nb_tun_fds < MAX_NICS ) {
   2.813                          fd = strtol(optarg, (char **)&p, 0);
   2.814                          if (*p != '\0') {
   2.815 -                            fprintf(stderr, "qemu: invalid fd for network interface %d\n", nb_tun_fds);
   2.816 +                            fprintf(stderr,
   2.817 +                                    "qemu: invalid fd for network interface %d\n",
   2.818 +                                    nb_tun_fds);
   2.819                              exit(1);
   2.820                          }
   2.821                          tun_fds[nb_tun_fds++] = fd;
   2.822                      }
   2.823                  }
   2.824 -		break;
   2.825 +                break;
   2.826              case QEMU_OPTION_hdc:
   2.827                  hd_filename[2] = optarg;
   2.828                  has_cdrom = 0;
   2.829 @@ -2811,9 +2818,11 @@ int main(int argc, char **argv)
   2.830                  break;
   2.831              case QEMU_OPTION_boot:
   2.832                  boot_device = optarg[0];
   2.833 -                if (boot_device != 'a' && 
   2.834 -                    boot_device != 'c' && boot_device != 'd') {
   2.835 -                    fprintf(stderr, "qemu: invalid boot device '%c'\n", boot_device);
   2.836 +                if ( boot_device != 'a' &&
   2.837 +                     boot_device != 'c' &&
   2.838 +                     boot_device != 'd' ) {
   2.839 +                    fprintf(stderr, "qemu: invalid boot device '%c'\n",
   2.840 +                                    boot_device);
   2.841                      exit(1);
   2.842                  }
   2.843                  break;
   2.844 @@ -2826,7 +2835,8 @@ int main(int argc, char **argv)
   2.845              case QEMU_OPTION_nics:
   2.846                  nb_nics = atoi(optarg);
   2.847                  if (nb_nics < 0 || nb_nics > MAX_NICS) {
   2.848 -                    fprintf(stderr, "qemu: invalid number of network interfaces\n");
   2.849 +                    fprintf(stderr,
   2.850 +                            "qemu: invalid number of network interfaces\n");
   2.851                      exit(1);
   2.852                  }
   2.853                  break;
   2.854 @@ -2837,16 +2847,18 @@ int main(int argc, char **argv)
   2.855                  {
   2.856                      const char *p;
   2.857                      int i;
   2.858 +
   2.859                      p = optarg;
   2.860 -                    for(i = 0; i < 6; i++) {
   2.861 +                    for (i = 0; i < 6; i++) {
   2.862                          macaddr[i] = strtol(p, (char **)&p, 16);
   2.863                          if (i == 5) {
   2.864 -                            if (*p != '\0') 
   2.865 +                            if (*p != '\0')
   2.866                                  goto macaddr_error;
   2.867                          } else {
   2.868                              if (*p != ':') {
   2.869                              macaddr_error:
   2.870 -                                fprintf(stderr, "qemu: invalid syntax for ethernet address\n");
   2.871 +                                fprintf(stderr, "qemu: invalid syntax "
   2.872 +                                                "for ethernet address\n");
   2.873                                  exit(1);
   2.874                              }
   2.875                              p++;
   2.876 @@ -2856,18 +2868,18 @@ int main(int argc, char **argv)
   2.877                  break;
   2.878  #ifdef CONFIG_SLIRP
   2.879              case QEMU_OPTION_tftp:
   2.880 -		tftp_prefix = optarg;
   2.881 +                tftp_prefix = optarg;
   2.882                  break;
   2.883  #ifndef _WIN32
   2.884              case QEMU_OPTION_smb:
   2.885 -		net_slirp_smb(optarg);
   2.886 +                net_slirp_smb(optarg);
   2.887                  break;
   2.888  #endif
   2.889              case QEMU_OPTION_user_net:
   2.890                  net_if_type = NET_IF_USER;
   2.891                  break;
   2.892              case QEMU_OPTION_redir:
   2.893 -                net_slirp_redir(optarg);                
   2.894 +                net_slirp_redir(optarg);
   2.895                  break;
   2.896  #endif
   2.897              case QEMU_OPTION_dummy_net:
   2.898 @@ -2886,24 +2898,23 @@ int main(int argc, char **argv)
   2.899                  break;
   2.900              case QEMU_OPTION_d:
   2.901                  {
   2.902 -                  domid = atoi(optarg);
   2.903 -                  printf("domid: %d\n", domid);
   2.904 +                    domid = atoi(optarg);
   2.905 +                    fprintf(logfile, "domid: %d\n", domid);
   2.906                  }
   2.907                  break;
   2.908 -
   2.909              case QEMU_OPTION_p:
   2.910                  {
   2.911 -                  extern uint16_t ioreq_remote_port;
   2.912 -                  ioreq_remote_port = atoi(optarg);
   2.913 -                  printf("port: %d\n", ioreq_remote_port);
   2.914 +                    extern uint16_t ioreq_remote_port;
   2.915 +                    ioreq_remote_port = atoi(optarg);
   2.916 +                    fprintf(logfile, "eport: %d\n", ioreq_remote_port);
   2.917                  }
   2.918                  break;
   2.919              case QEMU_OPTION_l:
   2.920                  {
   2.921 -                  int mask;
   2.922 -                  mask = cpu_str_to_log_mask(optarg);
   2.923 -                  printf("mask: %x\n", mask);
   2.924 -                  cpu_set_log(mask);
   2.925 +                    int mask;
   2.926 +                    mask = cpu_str_to_log_mask(optarg);
   2.927 +                    fprintf(logfile, "mask: %x\n", mask);
   2.928 +                    cpu_set_log(mask);
   2.929                  }
   2.930                  break;
   2.931              case QEMU_OPTION_n:
   2.932 @@ -2935,9 +2946,9 @@ int main(int argc, char **argv)
   2.933              case QEMU_OPTION_prep:
   2.934                  prep_enabled = 1;
   2.935                  break;
   2.936 -	    case QEMU_OPTION_k:
   2.937 -		keyboard_layout = optarg;
   2.938 -		break;
   2.939 +            case QEMU_OPTION_k:
   2.940 +                keyboard_layout = optarg;
   2.941 +                break;
   2.942              case QEMU_OPTION_localtime:
   2.943                  rtc_utc = 0;
   2.944                  break;
   2.945 @@ -2953,8 +2964,8 @@ int main(int argc, char **argv)
   2.946                          fprintf(stderr, "qemu: invalid vgaacc option\n");
   2.947                          exit(1);
   2.948                      }
   2.949 -                    break;
   2.950                  }
   2.951 +                break;
   2.952              case QEMU_OPTION_std_vga:
   2.953                  cirrus_vga_enabled = 0;
   2.954                  break;
   2.955 @@ -2978,7 +2989,7 @@ int main(int argc, char **argv)
   2.956                      if (*p == 'x') {
   2.957                          p++;
   2.958                          depth = strtol(p, (char **)&p, 10);
   2.959 -                        if (depth != 8 && depth != 15 && depth != 16 && 
   2.960 +                        if (depth != 8 && depth != 15 && depth != 16 &&
   2.961                              depth != 24 && depth != 32)
   2.962                              goto graphic_error;
   2.963                      } else if (*p == '\0') {
   2.964 @@ -2986,7 +2997,7 @@ int main(int argc, char **argv)
   2.965                      } else {
   2.966                          goto graphic_error;
   2.967                      }
   2.968 -                    
   2.969 +
   2.970                      graphic_width = w;
   2.971                      graphic_height = h;
   2.972                      graphic_depth = depth;
   2.973 @@ -3000,13 +3011,13 @@ int main(int argc, char **argv)
   2.974                      fprintf(stderr, "qemu: too many serial ports\n");
   2.975                      exit(1);
   2.976                  }
   2.977 -                pstrcpy(serial_devices[serial_device_index], 
   2.978 +                pstrcpy(serial_devices[serial_device_index],
   2.979                          sizeof(serial_devices[0]), optarg);
   2.980                  serial_device_index++;
   2.981                  break;
   2.982 -	    case QEMU_OPTION_loadvm:
   2.983 -		loadvm = optarg;
   2.984 -		break;
   2.985 +            case QEMU_OPTION_loadvm:
   2.986 +                loadvm = optarg;
   2.987 +                break;
   2.988              case QEMU_OPTION_full_screen:
   2.989                  full_screen = 1;
   2.990                  break;
   2.991 @@ -3015,11 +3026,11 @@ int main(int argc, char **argv)
   2.992      }
   2.993  
   2.994      linux_boot = (kernel_filename != NULL);
   2.995 -        
   2.996 -    if (!linux_boot && hd_filename[0] == '\0' && hd_filename[2] == '\0' &&
   2.997 -        fd_filename[0] == '\0')
   2.998 +
   2.999 +    if ( !linux_boot && hd_filename[0] == '\0' &&
  2.1000 +         hd_filename[2] == '\0' && fd_filename[0] == '\0' )
  2.1001          help();
  2.1002 -    
  2.1003 +
  2.1004      /* boot to cd by default if no hard disk */
  2.1005      if (hd_filename[0] == '\0' && boot_device == 'c') {
  2.1006          if (fd_filename[0] != '\0')
  2.1007 @@ -3102,89 +3113,96 @@ int main(int argc, char **argv)
  2.1008      nr_pages = info.nr_pages + extra_pages;
  2.1009  
  2.1010      if ( xc_domain_setmaxmem(xc_handle, domid,
  2.1011 -            (nr_pages) * PAGE_SIZE/1024 ) != 0)
  2.1012 +                             (nr_pages) * PAGE_SIZE/1024 ) != 0)
  2.1013      {
  2.1014 -        perror("set maxmem");
  2.1015 +        fprintf(logfile, "set maxmem returned error %d\n", errno);
  2.1016          exit(-1);
  2.1017      }
  2.1018 -   
  2.1019 +
  2.1020      if ( (page_array = (unsigned long *)
  2.1021 -	  malloc(nr_pages * sizeof(unsigned long))) == NULL)
  2.1022 +                        malloc(nr_pages * sizeof(unsigned long))) == NULL)
  2.1023      {
  2.1024 -	    perror("malloc");
  2.1025 -	    exit(-1);
  2.1026 +        fprintf(logfile, "malloc returned error %d\n", errno);
  2.1027 +        exit(-1);
  2.1028      }
  2.1029  
  2.1030 -    if (xc_domain_memory_increase_reservation(xc_handle, domid, 
  2.1031 -          extra_pages , 0, 0, NULL) != 0) {
  2.1032 -        perror("increase reservation");
  2.1033 +    if (xc_domain_memory_increase_reservation(xc_handle, domid,
  2.1034 +                                              extra_pages , 0, 0, NULL) != 0)
  2.1035 +    {
  2.1036 +        fprintf(logfile, "increase reservation returned error %d\n", errno);
  2.1037          exit(-1);
  2.1038      }
  2.1039  
  2.1040  #if defined(__i386__) || defined(__x86_64__)
  2.1041      if ( xc_get_pfn_list(xc_handle, domid, page_array, nr_pages) != nr_pages )
  2.1042      {
  2.1043 -	    perror("xc_get_pfn_list");
  2.1044 -	    exit(-1);
  2.1045 +        fprintf(logfile, "xc_get_pfn_list returned error %d\n", errno);
  2.1046 +        exit(-1);
  2.1047      }
  2.1048  
  2.1049 -    if ((phys_ram_base =  xc_map_foreign_batch(xc_handle, domid,
  2.1050 -						 PROT_READ|PROT_WRITE,
  2.1051 -						 page_array,
  2.1052 -						 ram_pages - 1)) == 0) {
  2.1053 -	    perror("xc_map_foreign_batch");
  2.1054 -	    exit(-1);
  2.1055 +    if ( (phys_ram_base = xc_map_foreign_batch(xc_handle, domid,
  2.1056 +                          PROT_READ|PROT_WRITE,
  2.1057 +                          page_array,
  2.1058 +                          ram_pages - 1)) == 0 )
  2.1059 +    {
  2.1060 +        fprintf(logfile, "xc_map_foreign_batch returned error %d\n", errno);
  2.1061 +        exit(-1);
  2.1062      }
  2.1063  
  2.1064      shared_page = xc_map_foreign_range(xc_handle, domid, PAGE_SIZE,
  2.1065 -				       PROT_READ|PROT_WRITE,
  2.1066 - 				       page_array[ram_pages - 1]);
  2.1067 +                                       PROT_READ|PROT_WRITE,
  2.1068 +                                       page_array[ram_pages - 1]);
  2.1069  
  2.1070      vgapage_array = &page_array[nr_pages - vgaram_pages];
  2.1071  
  2.1072 -    if ((shared_vram =  xc_map_foreign_batch(xc_handle, domid,
  2.1073 - 						 PROT_READ|PROT_WRITE,
  2.1074 - 						 vgapage_array,
  2.1075 - 						 vgaram_pages)) == 0) {
  2.1076 - 	    perror("xc_map_foreign_batch vgaram ");
  2.1077 - 	    exit(-1);
  2.1078 -     }
  2.1079 +    if ( (shared_vram =  xc_map_foreign_batch(xc_handle, domid,
  2.1080 +                                              PROT_READ|PROT_WRITE,
  2.1081 +                                              vgapage_array,
  2.1082 +                                              vgaram_pages)) == 0)
  2.1083 +    {
  2.1084 +        fprintf(logfile,
  2.1085 +                "xc_map_foreign_batch vgaram returned error %d\n", errno);
  2.1086 +        exit(-1);
  2.1087 +    }
  2.1088  
  2.1089      memset(shared_vram, 0, vgaram_pages * PAGE_SIZE);
  2.1090      toptab = page_array[ram_pages] << PAGE_SHIFT;
  2.1091  
  2.1092      vtop_table = xc_map_foreign_range(xc_handle, domid, PAGE_SIZE,
  2.1093 -				       PROT_READ|PROT_WRITE,
  2.1094 - 				       page_array[ram_pages]);
  2.1095 +                                      PROT_READ|PROT_WRITE,
  2.1096 +                                      page_array[ram_pages]);
  2.1097  
  2.1098      freepage_array = &page_array[nr_pages - extra_pages];
  2.1099  #elif defined(__ia64__)
  2.1100 -    if ( xc_ia64_get_pfn_list(xc_handle, domid, page_array, 0, ram_pages) != ram_pages)
  2.1101 +    if ( xc_ia64_get_pfn_list(xc_handle, domid, page_array, 0, ram_pages)
  2.1102 +         != ram_pages )
  2.1103      {
  2.1104 -        perror("xc_ia64_get_pfn_list");
  2.1105 +        fprintf(logfile, "xc_ia64_get_pfn_list returned error %d\n", errno);
  2.1106          exit(-1);
  2.1107      }
  2.1108  
  2.1109 -    if ((phys_ram_base =  xc_map_foreign_batch(xc_handle, domid,
  2.1110 -						 PROT_READ|PROT_WRITE,
  2.1111 -						 page_array,
  2.1112 -						 ram_pages)) == 0) {
  2.1113 -	    perror("xc_map_foreign_batch");
  2.1114 -	    exit(-1);
  2.1115 +    if ( (phys_ram_base = xc_map_foreign_batch(xc_handle, domid,
  2.1116 +                          PROT_READ|PROT_WRITE,
  2.1117 +                          page_array,
  2.1118 +                          ram_pages)) == 0 )
  2.1119 +    {
  2.1120 +        fprintf(logfile, "xc_map_foreign_batch returned error %d\n", errno);
  2.1121 +        exit(-1);
  2.1122      }
  2.1123  
  2.1124 -    if ( xc_ia64_get_pfn_list(xc_handle, domid, page_array, IO_PAGE_START>>PAGE_SHIFT, 1) != 1)
  2.1125 +    if ( xc_ia64_get_pfn_list(xc_handle, domid,
  2.1126 +                              page_array, IO_PAGE_START >> PAGE_SHIFT, 1) != 1 )
  2.1127      {
  2.1128 -        perror("xc_ia64_get_pfn_list");
  2.1129 +        fprintf(logfile, "xc_ia64_get_pfn_list returned error %d\n", errno);
  2.1130          exit(-1);
  2.1131      }
  2.1132  
  2.1133      shared_page = xc_map_foreign_range(xc_handle, domid, PAGE_SIZE,
  2.1134 -				       PROT_READ|PROT_WRITE,
  2.1135 - 				       page_array[0]);
  2.1136 -#endif 
  2.1137 -
  2.1138 -    fprintf(logfile, "shared page at pfn:%lx, mfn: %lx\n", (nr_pages-1), 
  2.1139 +                                       PROT_READ|PROT_WRITE,
  2.1140 +                                       page_array[0]);
  2.1141 +#endif
  2.1142 +
  2.1143 +    fprintf(logfile, "shared page at pfn:%lx, mfn: %lx\n", (nr_pages-1),
  2.1144             (page_array[nr_pages - 1]));
  2.1145  
  2.1146      /* we always create the cdrom drive, even if no disk is there */
  2.1147 @@ -3207,7 +3225,7 @@ int main(int argc, char **argv)
  2.1148                          hd_filename[i]);
  2.1149                  exit(1);
  2.1150              }
  2.1151 -            if (i == 0 && cyls != 0) 
  2.1152 +            if (i == 0 && cyls != 0)
  2.1153                  bdrv_set_geometry_hint(bs_table[i], cyls, heads, secs);
  2.1154          }
  2.1155      }
  2.1156 @@ -3246,23 +3264,23 @@ int main(int argc, char **argv)
  2.1157      if (nographic) {
  2.1158          dumb_display_init(ds);
  2.1159      } else {
  2.1160 -	if (usevnc) {
  2.1161 +        if (usevnc) {
  2.1162  #ifdef CONFIG_VNC
  2.1163 -	    vnc_display_init(ds, (usevnc==2), vncport, vncconnect);
  2.1164 +            vnc_display_init(ds, (usevnc==2), vncport, vncconnect);
  2.1165  #else
  2.1166 -	    perror("qemu not configured with vnc support");
  2.1167 +            fprintf(logfile, "qemu not configured with vnc support\n");
  2.1168  #endif
  2.1169 -	} else {
  2.1170 +        } else {
  2.1171  #ifdef CONFIG_SDL
  2.1172 -        sdl_display_init(ds, full_screen);
  2.1173 +            sdl_display_init(ds, full_screen);
  2.1174  #else
  2.1175 -        dumb_display_init(ds);
  2.1176 +            dumb_display_init(ds);
  2.1177  #endif
  2.1178 -    }
  2.1179 +        }
  2.1180      }
  2.1181  
  2.1182      vga_console = graphic_console_init(ds);
  2.1183 -    
  2.1184 +
  2.1185      monitor_hd = qemu_chr_open(monitor_device);
  2.1186      if (!monitor_hd) {
  2.1187          fprintf(stderr, "qemu: could not open monitor device '%s'\n", monitor_device);
  2.1188 @@ -3274,7 +3292,7 @@ int main(int argc, char **argv)
  2.1189          if (serial_devices[i][0] != '\0') {
  2.1190              serial_hds[i] = qemu_chr_open(serial_devices[i]);
  2.1191              if (!serial_hds[i]) {
  2.1192 -                fprintf(stderr, "qemu: could not open serial device '%s'\n", 
  2.1193 +                fprintf(stderr, "qemu: could not open serial device '%s'\n",
  2.1194                          serial_devices[i]);
  2.1195                  exit(1);
  2.1196              }
  2.1197 @@ -3285,7 +3303,7 @@ int main(int argc, char **argv)
  2.1198  
  2.1199      /* setup cpu signal handlers for MMU / self modifying code handling */
  2.1200  #if !defined(CONFIG_SOFTMMU)
  2.1201 -    
  2.1202 +
  2.1203  #if defined (TARGET_I386) && defined(USE_CODE_COPY)
  2.1204      {
  2.1205          stack_t stk;
  2.1206 @@ -3295,14 +3313,14 @@ int main(int argc, char **argv)
  2.1207          stk.ss_flags = 0;
  2.1208  
  2.1209          if (sigaltstack(&stk, NULL) < 0) {
  2.1210 -            perror("sigaltstack");
  2.1211 +            fprintf(logfile, "sigaltstack returned error %d\n", errno);
  2.1212              exit(1);
  2.1213          }
  2.1214      }
  2.1215  #endif
  2.1216      {
  2.1217          struct sigaction act;
  2.1218 -        
  2.1219 +
  2.1220          sigfillset(&act.sa_mask);
  2.1221          act.sa_flags = SA_SIGINFO;
  2.1222  #if defined (TARGET_I386) && defined(USE_CODE_COPY)
  2.1223 @@ -3334,8 +3352,8 @@ int main(int argc, char **argv)
  2.1224              kernel_filename, kernel_cmdline, initrd_filename);
  2.1225  #elif defined(TARGET_PPC)
  2.1226      ppc_init(ram_size, vga_ram_size, boot_device,
  2.1227 -	     ds, fd_filename, snapshot,
  2.1228 -	     kernel_filename, kernel_cmdline, initrd_filename);
  2.1229 +            ds, fd_filename, snapshot,
  2.1230 +            kernel_filename, kernel_cmdline, initrd_filename);
  2.1231  #elif defined(TARGET_SPARC)
  2.1232      sun4m_init(ram_size, vga_ram_size, boot_device,
  2.1233              ds, fd_filename, snapshot,
  2.1234 @@ -3351,13 +3369,13 @@ int main(int argc, char **argv)
  2.1235  #ifdef CONFIG_GDBSTUB
  2.1236      if (use_gdbstub) {
  2.1237          if (gdbserver_start(gdbstub_port) < 0) {
  2.1238 -            fprintf(stderr, "Could not open gdbserver socket on port %d\n", 
  2.1239 +            fprintf(stderr, "Could not open gdbserver socket on port %d\n",
  2.1240                      gdbstub_port);
  2.1241              exit(1);
  2.1242          } else {
  2.1243 -            printf("Waiting gdb connection on port %d\n", gdbstub_port);
  2.1244 +            fprintf(logfile, "Waiting gdb connection on port %d\n", gdbstub_port);
  2.1245          }
  2.1246 -    } else 
  2.1247 +    } else
  2.1248  #endif
  2.1249      if (loadvm)
  2.1250          qemu_loadvm(loadvm);
  2.1251 @@ -3389,7 +3407,7 @@ void tun_receive_handler(fd_set *rfds)
  2.1252                  n = read(ioh->fd, buf, max_size);
  2.1253                  if (n >= 0) {
  2.1254                      ioh->fd_read(ioh->opaque, buf, n);
  2.1255 -                } 
  2.1256 +                }
  2.1257              }
  2.1258          }
  2.1259      }
  2.1260 @@ -3411,5 +3429,3 @@ void update_select_wakeup_events(void)
  2.1261          }
  2.1262      }
  2.1263  }
  2.1264 -
  2.1265 -