1 |
/* |
/* |
2 |
* Copyright (C) 2003-2006 Anders Gavare. All rights reserved. |
* Copyright (C) 2003-2007 Anders Gavare. All rights reserved. |
3 |
* |
* |
4 |
* Redistribution and use in source and binary forms, with or without |
* Redistribution and use in source and binary forms, with or without |
5 |
* modification, are permitted provided that the following conditions are met: |
* modification, are permitted provided that the following conditions are met: |
25 |
* SUCH DAMAGE. |
* SUCH DAMAGE. |
26 |
* |
* |
27 |
* |
* |
28 |
* $Id: machine.c,v 1.689 2006/10/04 11:56:40 debug Exp $ |
* $Id: machine.c,v 1.693 2007/01/28 14:15:29 debug Exp $ |
29 |
*/ |
*/ |
30 |
|
|
31 |
#include <stdio.h> |
#include <stdio.h> |
45 |
#include "diskimage.h" |
#include "diskimage.h" |
46 |
#include "emul.h" |
#include "emul.h" |
47 |
#include "machine.h" |
#include "machine.h" |
|
#include "machine_interrupts.h" |
|
48 |
#include "memory.h" |
#include "memory.h" |
49 |
#include "misc.h" |
#include "misc.h" |
50 |
#include "net.h" |
#include "net.h" |
66 |
* |
* |
67 |
* Returns a reasonably initialized struct machine. |
* Returns a reasonably initialized struct machine. |
68 |
*/ |
*/ |
69 |
struct machine *machine_new(char *name, struct emul *emul) |
struct machine *machine_new(char *name, struct emul *emul, int id) |
70 |
{ |
{ |
71 |
struct machine *m; |
struct machine *m; |
72 |
m = malloc(sizeof(struct machine)); |
m = malloc(sizeof(struct machine)); |
82 |
|
|
83 |
m->name = strdup(name); |
m->name = strdup(name); |
84 |
|
|
85 |
|
/* Full path, e.g. "emul[0].machine[0]": */ |
86 |
|
m->path = malloc(strlen(emul->path) + 20); |
87 |
|
if (m->path == NULL) { |
88 |
|
fprintf(stderr, "out of memory\n"); |
89 |
|
exit(1); |
90 |
|
} |
91 |
|
snprintf(m->path, strlen(emul->path) + 20, "%s.machine[%i]", |
92 |
|
emul->path, id); |
93 |
|
|
94 |
/* Sane default values: */ |
/* Sane default values: */ |
95 |
m->serial_nr = 1; |
m->serial_nr = 1; |
96 |
m->machine_type = MACHINE_NONE; |
m->machine_type = MACHINE_NONE; |
155 |
if (machine->name != NULL) |
if (machine->name != NULL) |
156 |
free(machine->name); |
free(machine->name); |
157 |
|
|
158 |
|
if (machine->path != NULL) |
159 |
|
free(machine->path); |
160 |
|
|
161 |
/* Remove any remaining level-1 settings: */ |
/* Remove any remaining level-1 settings: */ |
162 |
settings_remove_all(machine->settings); |
settings_remove_all(machine->settings); |
163 |
settings_destroy(machine->settings); |
settings_destroy(machine->settings); |
386 |
|
|
387 |
|
|
388 |
/* |
/* |
|
* machine_bus_register(): |
|
|
* |
|
|
* Registers a bus in a machine. |
|
|
*/ |
|
|
void machine_bus_register(struct machine *machine, char *busname, |
|
|
void (*debug_dump)(void *), void *extra) |
|
|
{ |
|
|
struct machine_bus *tmp, *last = NULL, *new; |
|
|
|
|
|
new = zeroed_alloc(sizeof(struct machine_bus)); |
|
|
new->name = strdup(busname); |
|
|
new->debug_dump = debug_dump; |
|
|
new->extra = extra; |
|
|
|
|
|
/* Register last in the bus list: */ |
|
|
tmp = machine->first_bus; |
|
|
while (tmp != NULL) { |
|
|
last = tmp; |
|
|
tmp = tmp->next; |
|
|
} |
|
|
|
|
|
if (last == NULL) |
|
|
machine->first_bus = new; |
|
|
else |
|
|
last->next = new; |
|
|
|
|
|
machine->n_busses ++; |
|
|
} |
|
|
|
|
|
|
|
|
/* |
|
|
* machine_dump_bus_info(): |
|
|
* |
|
|
* Dumps info about registered busses. |
|
|
*/ |
|
|
void machine_dump_bus_info(struct machine *m) |
|
|
{ |
|
|
struct machine_bus *bus = m->first_bus; |
|
|
int iadd = DEBUG_INDENTATION; |
|
|
|
|
|
if (m->n_busses > 0) |
|
|
debug("busses:\n"); |
|
|
debug_indentation(iadd); |
|
|
while (bus != NULL) { |
|
|
bus->debug_dump(bus->extra); |
|
|
bus = bus->next; |
|
|
} |
|
|
debug_indentation(-iadd); |
|
|
} |
|
|
|
|
|
|
|
|
/* |
|
389 |
* machine_dumpinfo(): |
* machine_dumpinfo(): |
390 |
* |
* |
391 |
* Dumps info about a machine in some kind of readable format. (Used by |
* Dumps info about a machine in some kind of readable format. (Used by |
437 |
debug("\n"); |
debug("\n"); |
438 |
} |
} |
439 |
|
|
|
machine_dump_bus_info(m); |
|
|
|
|
440 |
diskimage_dump_info(m); |
diskimage_dump_info(m); |
441 |
|
|
442 |
if (m->force_netboot) |
if (m->force_netboot) |
896 |
debug("\n"); |
debug("\n"); |
897 |
} |
} |
898 |
|
|
|
if (verbose >= 2) |
|
|
machine_dump_bus_info(machine); |
|
|
|
|
899 |
if (!machine->stable) |
if (!machine->stable) |
900 |
fatal("!\n! NOTE: This machine type is not implemented well" |
fatal("!\n! NOTE: This machine type is not implemented well" |
901 |
" enough yet to run\n! any real-world code!" |
" enough yet to run\n! any real-world code!" |