/[gxemul]/trunk/src/devices/dev_ram.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_ram.c

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

revision 41 by dpavlin, Mon Oct 8 16:21:34 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_ram.c,v 1.24 2007/03/08 11:43:44 debug Exp $   *  $Id: dev_ram.c,v 1.25 2007/06/15 19:57:33 debug Exp $
29   *     *  
30   *  A generic RAM (memory) device. Can also be used to mirror/alias another   *  COMMENT: A generic RAM (memory) device
31   *  part of RAM.   *
32     *  Note: This device can also be used to mirror/alias another part of RAM.
33   */   */
34    
35  #include <stdio.h>  #include <stdio.h>
# Line 79  DEVICE_ACCESS(ram) Line 80  DEVICE_ACCESS(ram)
80  #endif  #endif
81    
82          switch (d->mode) {          switch (d->mode) {
83    
84          case DEV_RAM_MIRROR:          case DEV_RAM_MIRROR:
85                  /*  TODO:  how about caches?  */                  /*  TODO:  how about caches?  */
86                  return cpu->memory_rw(cpu, mem,                  return cpu->memory_rw(cpu, mem,
87                      d->otheraddress + relative_addr, data, len,                      d->otheraddress + relative_addr, data, len,
88                      writeflag, PHYSICAL);                      writeflag, PHYSICAL);
89    
90          case DEV_RAM_RAM:          case DEV_RAM_RAM:
91                  if (writeflag == MEM_WRITE) {                  if (writeflag == MEM_WRITE) {
92                          memcpy(&d->data[relative_addr], data, len);                          memcpy(&d->data[relative_addr], data, len);
# Line 98  DEVICE_ACCESS(ram) Line 101  DEVICE_ACCESS(ram)
101                          memcpy(data, &d->data[relative_addr], len);                          memcpy(data, &d->data[relative_addr], len);
102                  }                  }
103                  break;                  break;
104    
105          default:          default:
106                  fatal("dev_ram_access(): unknown mode %i\n", d->mode);                  fatal("dev_ram_access(): unknown mode %i\n", d->mode);
107                  exit(1);                  exit(1);
# Line 120  void dev_ram_init(struct machine *machin Line 124  void dev_ram_init(struct machine *machin
124          struct ram_data *d;          struct ram_data *d;
125          int flags = DM_DEFAULT, points_to_ram = 1;          int flags = DM_DEFAULT, points_to_ram = 1;
126    
127          d = malloc(sizeof(struct ram_data));          CHECK_ALLOCATION(d = malloc(sizeof(struct ram_data)));
         if (d == NULL) {  
                 fprintf(stderr, "out of memory\n");  
                 exit(1);  
         }  
   
128          memset(d, 0, sizeof(struct ram_data));          memset(d, 0, sizeof(struct ram_data));
129    
130          if (mode & DEV_RAM_MIGHT_POINT_TO_DEVICES) {          if (mode & DEV_RAM_MIGHT_POINT_TO_DEVICES) {
# Line 163  void dev_ram_init(struct machine *machin Line 162  void dev_ram_init(struct machine *machin
162          case DEV_RAM_RAM:          case DEV_RAM_RAM:
163                  /*                  /*
164                   *  Allocate zero-filled RAM using mmap(). If mmap() failed,                   *  Allocate zero-filled RAM using mmap(). If mmap() failed,
165                   *  try malloc(), but then we also have to memset(), which                   *  try malloc(), but then memset() must also be called, which
166                   *  can be slow for large chunks of memory.                   *  can be slow for large chunks of memory.
167                   */                   */
168                  d->length = length;                  d->length = length;
169                  d->data = (unsigned char *) mmap(NULL, length,                  d->data = (unsigned char *) mmap(NULL, length,
170                      PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0);                      PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0);
171                  if (d->data == NULL) {                  if (d->data == NULL) {
172                          d->data = malloc(length);                          CHECK_ALLOCATION(d->data = malloc(length));
                         if (d->data == NULL) {  
                                 fprintf(stderr, "out of memory\n");  
                                 exit(1);  
                         }  
173                          memset(d->data, 0, length);                          memset(d->data, 0, length);
174                  }                  }
175    

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

  ViewVC Help
Powered by ViewVC 1.1.26