--- trunk/src/device.c 2007/10/08 16:17:48 2 +++ trunk/src/device.c 2007/10/08 16:18:38 12 @@ -25,7 +25,7 @@ * SUCH DAMAGE. * * - * $Id: device.c,v 1.13 2005/02/26 17:37:25 debug Exp $ + * $Id: device.c,v 1.16 2005/08/10 22:25:50 debug Exp $ * * Device registry framework. */ @@ -164,7 +164,10 @@ if (step == 0) do_return = 1; - step /= 2; + if (step & 1) + step = (step/2) + 1; + else + step /= 2; } } @@ -178,7 +181,7 @@ */ int device_unregister(char *name) { - size_t i; + ssize_t i; struct device_entry *p = device_lookup(name); if (p == NULL) { @@ -213,9 +216,10 @@ /* * device_add(): * - * Add a device to a machine. + * Add a device to a machine. For example: "kn210 addr=0x12340000" adds a + * device called "kn210" at a specific address. * - * "kn210 addr=0x12340000" adds a kn210 device at a specific address. + * TODO: This function is quite ugly, and should be cleaned up. */ void *device_add(struct machine *machine, char *name_and_params) { @@ -229,6 +233,7 @@ /* Default values: */ devinit.addr_mult = 1; + devinit.in_use = 1; /* Get the device name first: */ s2 = name_and_params; @@ -286,6 +291,19 @@ devinit.addr_mult = mystrtoull(s3, NULL, 0); } else if (strncmp(s2, "irq=", 4) == 0) { devinit.irq_nr = mystrtoull(s3, NULL, 0); + } else if (strncmp(s2, "in_use=", 7) == 0) { + devinit.in_use = mystrtoull(s3, NULL, 0); + } else if (strncmp(s2, "name2=", 6) == 0) { + char *h = s2 + 6; + size_t len = 0; + while (*h && *h != ' ') + h++, len++; + devinit.name2 = malloc(len + 1); + if (devinit.name2 == NULL) { + fprintf(stderr, "out of memory\n"); + exit(1); + } + snprintf(devinit.name2, len + 1, s2 + 6); } else { fatal("unknown param: %s\n", s2); if (device_exit_on_error) @@ -349,6 +367,11 @@ /* * device_set_exit_on_error(): + * + * This function selects the behaviour of the emulator when a device is not + * found. During startup, it is nicest to abort the whole emulator session, + * but if a device addition is attempted from within the debugger, then it is + * nicer to just print a warning and continue. */ void device_set_exit_on_error(int exit_on_error) { @@ -360,7 +383,7 @@ * device_init(): * * Initialize the device registry, and call autodev_init() to automatically - * add all normal devices (from the devices/ directory). + * add all normal devices (from the src/devices/ directory). * * This function should be called before any other device_*() function is used. */