/[gxemul]/trunk/src/devices/dev_disk.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/devices/dev_disk.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: dev_disk.c,v 1.14 2007/02/03 20:14:23 debug Exp $   *  $Id: dev_disk.c,v 1.15 2007/06/15 18:44:19 debug Exp $
29     *
30     *  COMMENT: A simple disk controller device, for the test machines
31   *   *
32   *  Basic "disk" device. This is a simple test device which can be used to   *  Basic "disk" device. This is a simple test device which can be used to
33   *  read and write data from disk devices.   *  read and write data from disk devices.
# Line 55  struct disk_data { Line 57  struct disk_data {
57  };  };
58    
59    
 /*  
  *  dev_disk_buf_access():  
  */  
60  DEVICE_ACCESS(disk_buf)  DEVICE_ACCESS(disk_buf)
61  {  {
62          struct disk_data *d = (struct disk_data *) extra;          struct disk_data *d = extra;
63    
64          if (writeflag == MEM_WRITE)          if (writeflag == MEM_WRITE)
65                  memcpy(d->buf + relative_addr, data, len);                  memcpy(d->buf + relative_addr, data, len);
66          else          else
67                  memcpy(data, d->buf + relative_addr, len);                  memcpy(data, d->buf + relative_addr, len);
68    
69          return 1;          return 1;
70  }  }
71    
72    
 /*  
  *  dev_disk_access():  
  */  
73  DEVICE_ACCESS(disk)  DEVICE_ACCESS(disk)
74  {  {
75          struct disk_data *d = (struct disk_data *) extra;          struct disk_data *d = extra;
76          uint64_t idata = 0, odata = 0;          uint64_t idata = 0, odata = 0;
77    
78          if (writeflag == MEM_WRITE)          if (writeflag == MEM_WRITE)
# Line 144  DEVICE_ACCESS(disk) Line 141  DEVICE_ACCESS(disk)
141    
142  DEVINIT(disk)  DEVINIT(disk)
143  {  {
144          struct disk_data *d = malloc(sizeof(struct disk_data));          struct disk_data *d;
145          size_t nlen;          size_t nlen;
146          char *n1, *n2;          char *n1, *n2;
147                                    
148          nlen = strlen(devinit->name) + 30;          CHECK_ALLOCATION(d = malloc(sizeof(struct disk_data)));
         n1 = malloc(nlen);  
         n2 = malloc(nlen);  
   
         if (d == NULL || n1 == NULL || n2 == NULL) {  
                 fprintf(stderr, "out of memory\n");  
                 exit(1);  
         }  
149          memset(d, 0, sizeof(struct disk_data));          memset(d, 0, sizeof(struct disk_data));
150    
151          d->buf = malloc(devinit->machine->arch_pagesize);          nlen = strlen(devinit->name) + 30;
152          if (d->buf == NULL) {          CHECK_ALLOCATION(n1 = malloc(nlen));
153                  fprintf(stderr, "out of memory\n");          CHECK_ALLOCATION(n2 = malloc(nlen));
154                  exit(1);  
155          }          CHECK_ALLOCATION(d->buf = malloc(devinit->machine->arch_pagesize));
156          memset(d->buf, 0, devinit->machine->arch_pagesize);          memset(d->buf, 0, devinit->machine->arch_pagesize);
157    
158          snprintf(n1, nlen, "%s [control]", devinit->name);          snprintf(n1, nlen, "%s [control]", devinit->name);

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

  ViewVC Help
Powered by ViewVC 1.1.26