/[gxemul]/trunk/src/device.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/src/device.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 41 by dpavlin, Mon Oct 8 16:21:17 2007 UTC revision 42 by dpavlin, Mon Oct 8 16:22:32 2007 UTC
# Line 25  Line 25 
25   *  SUCH DAMAGE.   *  SUCH DAMAGE.
26   *   *
27   *   *
28   *  $Id: device.c,v 1.32 2006/12/30 13:30:51 debug Exp $   *  $Id: device.c,v 1.34 2007/06/15 17:02:37 debug Exp $
29   *   *
30   *  Device registry framework.   *  Device registry framework.
31   */   */
# Line 90  static void sort_entries(void) Line 90  static void sort_entries(void)
90   */   */
91  int device_register(char *name, int (*initf)(struct devinit *))  int device_register(char *name, int (*initf)(struct devinit *))
92  {  {
93          device_entries = realloc(device_entries, sizeof(struct device_entry)          CHECK_ALLOCATION(device_entries = realloc(device_entries,
94              * (n_device_entries + 1));              sizeof(struct device_entry) * (n_device_entries + 1)));
         if (device_entries == NULL) {  
                 fprintf(stderr, "device_register(): out of memory\n");  
                 exit(1);  
         }  
95    
96          memset(&device_entries[n_device_entries], 0,          memset(&device_entries[n_device_entries], 0,
97              sizeof(struct device_entry));              sizeof(struct device_entry));
98    
99          device_entries[n_device_entries].name = strdup(name);          CHECK_ALLOCATION(device_entries[n_device_entries].name = strdup(name));
100          device_entries[n_device_entries].initf = initf;          device_entries[n_device_entries].initf = initf;
101    
102          device_entries_sorted = 0;          device_entries_sorted = 0;
# Line 120  int device_register(char *name, int (*in Line 116  int device_register(char *name, int (*in
116  int pci_register(char *name, void (*initf)(struct machine *, struct memory *,  int pci_register(char *name, void (*initf)(struct machine *, struct memory *,
117          struct pci_device *))          struct pci_device *))
118  {  {
119          pci_entries = realloc(pci_entries, sizeof(struct pci_entry)          CHECK_ALLOCATION(pci_entries = realloc(pci_entries,
120              * (n_pci_entries + 1));              sizeof(struct pci_entry) * (n_pci_entries + 1)));
         if (pci_entries == NULL) {  
                 fprintf(stderr, "pci_register(): out of memory\n");  
                 exit(1);  
         }  
121    
122          memset(&pci_entries[n_pci_entries], 0, sizeof(struct pci_entry));          memset(&pci_entries[n_pci_entries], 0, sizeof(struct pci_entry));
123    
124          pci_entries[n_pci_entries].name = strdup(name);          CHECK_ALLOCATION(pci_entries[n_pci_entries].name = strdup(name));
125          pci_entries[n_pci_entries].initf = initf;          pci_entries[n_pci_entries].initf = initf;
126          n_pci_entries ++;          n_pci_entries ++;
127          return 1;          return 1;
# Line 281  void *device_add(struct machine *machine Line 273  void *device_add(struct machine *machine
273                  s2 ++;                  s2 ++;
274    
275          len = (size_t)s2 - (size_t)name_and_params;          len = (size_t)s2 - (size_t)name_and_params;
276          devinit.name = malloc(len + 1);          CHECK_ALLOCATION(devinit.name = malloc(len + 1));
         if (devinit.name == NULL) {  
                 fprintf(stderr, "device_add(): out of memory\n");  
                 exit(1);  
         }  
277          memcpy(devinit.name, name_and_params, len);          memcpy(devinit.name, name_and_params, len);
278          devinit.name[len] = '\0';          devinit.name[len] = '\0';
279    
280          /*  Allocate space for the default interrupt name:  */          /*  Allocate space for the default interrupt name:  */
281          devinit.interrupt_path = malloc(interrupt_path_len + 1);          CHECK_ALLOCATION(devinit.interrupt_path =
282          if (devinit.interrupt_path == NULL) {              malloc(interrupt_path_len + 1));
                 fprintf(stderr, "device_add(): out of memory\n");  
                 exit(1);  
         }  
283          snprintf(devinit.interrupt_path, interrupt_path_len,          snprintf(devinit.interrupt_path, interrupt_path_len,
284              "%s.cpu[%i]", machine->path, machine->bootstrap_cpu);              "%s.cpu[%i]", machine->path, machine->bootstrap_cpu);
285    
# Line 351  void *device_add(struct machine *machine Line 336  void *device_add(struct machine *machine
336                                  exit(1);                                  exit(1);
337                          }                          }
338                  } else if (strncmp(s2, "irq=", 4) == 0) {                  } else if (strncmp(s2, "irq=", 4) == 0) {
                         devinit.irq_nr = mystrtoull(s3, NULL, 0);  
   
                         /*  New-style interrupt path:  */  
339                          snprintf(devinit.interrupt_path, interrupt_path_len,s3);                          snprintf(devinit.interrupt_path, interrupt_path_len,s3);
340                          if (strchr(devinit.interrupt_path, ' ') != NULL)                          if (strchr(devinit.interrupt_path, ' ') != NULL)
341                                  *strchr(devinit.interrupt_path, ' ') = '\0';                                  *strchr(devinit.interrupt_path, ' ') = '\0';
   
                         if (strncmp(s3, "none", 4) == 0)  
                                 devinit.interrupt_path[0] = '\0';  
342                  } else if (strncmp(s2, "in_use=", 7) == 0) {                  } else if (strncmp(s2, "in_use=", 7) == 0) {
343                          devinit.in_use = mystrtoull(s3, NULL, 0);                          devinit.in_use = mystrtoull(s3, NULL, 0);
344                  } else if (strncmp(s2, "name2=", 6) == 0) {                  } else if (strncmp(s2, "name2=", 6) == 0) {
# Line 373  void *device_add(struct machine *machine Line 352  void *device_add(struct machine *machine
352                                  if (!quoted && *h == ' ')                                  if (!quoted && *h == ' ')
353                                          break;                                          break;
354                          }                          }
355                          devinit.name2 = malloc(len + 1);                          CHECK_ALLOCATION(devinit.name2 = malloc(len + 1));
                         if (devinit.name2 == NULL) {  
                                 fprintf(stderr, "out of memory\n");  
                                 exit(1);  
                         }  
356                          h = s2 + 6;                          h = s2 + 6;
357                          if (*h == '\'')                          if (*h == '\'')
358                                  len -= 2, h++;                                  len -= 2, h++;

Legend:
Removed from v.41  
changed lines
  Added in v.42

  ViewVC Help
Powered by ViewVC 1.1.26