25 |
* SUCH DAMAGE. |
* SUCH DAMAGE. |
26 |
* |
* |
27 |
* |
* |
28 |
* $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 $ |
29 |
* |
* |
30 |
* Device registry framework. |
* Device registry framework. |
31 |
*/ |
*/ |
164 |
if (step == 0) |
if (step == 0) |
165 |
do_return = 1; |
do_return = 1; |
166 |
|
|
167 |
step /= 2; |
if (step & 1) |
168 |
|
step = (step/2) + 1; |
169 |
|
else |
170 |
|
step /= 2; |
171 |
} |
} |
172 |
} |
} |
173 |
|
|
181 |
*/ |
*/ |
182 |
int device_unregister(char *name) |
int device_unregister(char *name) |
183 |
{ |
{ |
184 |
size_t i; |
ssize_t i; |
185 |
struct device_entry *p = device_lookup(name); |
struct device_entry *p = device_lookup(name); |
186 |
|
|
187 |
if (p == NULL) { |
if (p == NULL) { |
216 |
/* |
/* |
217 |
* device_add(): |
* device_add(): |
218 |
* |
* |
219 |
* Add a device to a machine. |
* Add a device to a machine. For example: "kn210 addr=0x12340000" adds a |
220 |
|
* device called "kn210" at a specific address. |
221 |
* |
* |
222 |
* "kn210 addr=0x12340000" adds a kn210 device at a specific address. |
* TODO: This function is quite ugly, and should be cleaned up. |
223 |
*/ |
*/ |
224 |
void *device_add(struct machine *machine, char *name_and_params) |
void *device_add(struct machine *machine, char *name_and_params) |
225 |
{ |
{ |
233 |
|
|
234 |
/* Default values: */ |
/* Default values: */ |
235 |
devinit.addr_mult = 1; |
devinit.addr_mult = 1; |
236 |
|
devinit.in_use = 1; |
237 |
|
|
238 |
/* Get the device name first: */ |
/* Get the device name first: */ |
239 |
s2 = name_and_params; |
s2 = name_and_params; |
291 |
devinit.addr_mult = mystrtoull(s3, NULL, 0); |
devinit.addr_mult = mystrtoull(s3, NULL, 0); |
292 |
} else if (strncmp(s2, "irq=", 4) == 0) { |
} else if (strncmp(s2, "irq=", 4) == 0) { |
293 |
devinit.irq_nr = mystrtoull(s3, NULL, 0); |
devinit.irq_nr = mystrtoull(s3, NULL, 0); |
294 |
|
} else if (strncmp(s2, "in_use=", 7) == 0) { |
295 |
|
devinit.in_use = mystrtoull(s3, NULL, 0); |
296 |
|
} else if (strncmp(s2, "name2=", 6) == 0) { |
297 |
|
char *h = s2 + 6; |
298 |
|
size_t len = 0; |
299 |
|
while (*h && *h != ' ') |
300 |
|
h++, len++; |
301 |
|
devinit.name2 = malloc(len + 1); |
302 |
|
if (devinit.name2 == NULL) { |
303 |
|
fprintf(stderr, "out of memory\n"); |
304 |
|
exit(1); |
305 |
|
} |
306 |
|
snprintf(devinit.name2, len + 1, s2 + 6); |
307 |
} else { |
} else { |
308 |
fatal("unknown param: %s\n", s2); |
fatal("unknown param: %s\n", s2); |
309 |
if (device_exit_on_error) |
if (device_exit_on_error) |
367 |
|
|
368 |
/* |
/* |
369 |
* device_set_exit_on_error(): |
* device_set_exit_on_error(): |
370 |
|
* |
371 |
|
* This function selects the behaviour of the emulator when a device is not |
372 |
|
* found. During startup, it is nicest to abort the whole emulator session, |
373 |
|
* but if a device addition is attempted from within the debugger, then it is |
374 |
|
* nicer to just print a warning and continue. |
375 |
*/ |
*/ |
376 |
void device_set_exit_on_error(int exit_on_error) |
void device_set_exit_on_error(int exit_on_error) |
377 |
{ |
{ |
383 |
* device_init(): |
* device_init(): |
384 |
* |
* |
385 |
* Initialize the device registry, and call autodev_init() to automatically |
* Initialize the device registry, and call autodev_init() to automatically |
386 |
* add all normal devices (from the devices/ directory). |
* add all normal devices (from the src/devices/ directory). |
387 |
* |
* |
388 |
* This function should be called before any other device_*() function is used. |
* This function should be called before any other device_*() function is used. |
389 |
*/ |
*/ |