/[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 17 by dpavlin, Mon Oct 8 16:18:11 2007 UTC revision 18 by dpavlin, Mon Oct 8 16:19:11 2007 UTC
# Line 25  Line 25 
25   *  SUCH DAMAGE.   *  SUCH DAMAGE.
26   *     *  
27   *   *
28   *  $Id: dev_ram.c,v 1.14 2005/05/23 14:22:02 debug Exp $   *  $Id: dev_ram.c,v 1.19 2005/10/25 15:51:04 debug Exp $
29   *     *  
30   *  A generic RAM (memory) device.  Can also be used to mirror/alias another   *  A generic RAM (memory) device. Can also be used to mirror/alias another
31   *  part of RAM.   *  part of RAM.
32   */   */
33    
# Line 37  Line 37 
37  #include <sys/types.h>  #include <sys/types.h>
38  #include <sys/mman.h>  #include <sys/mman.h>
39    
 #include "console.h"  
40  #include "cpu.h"  #include "cpu.h"
41  #include "devices.h"  #include "devices.h"
42    #include "machine.h"
43  #include "memory.h"  #include "memory.h"
44  #include "misc.h"  #include "misc.h"
45    
# Line 50  struct ram_data { Line 50  struct ram_data {
50          int             mode;          int             mode;
51          uint64_t        otheraddress;          uint64_t        otheraddress;
52    
53            /*  If mode = DEV_RAM_MIRROR:  */
54            uint64_t        offset;
55    
56          /*  If mode = DEV_RAM_RAM:  */          /*  If mode = DEV_RAM_RAM:  */
57          unsigned char   *data;          unsigned char   *data;
58          uint64_t        length;          uint64_t        length;
# Line 101  int dev_ram_access(struct cpu *cpu, stru Line 104  int dev_ram_access(struct cpu *cpu, stru
104    
105  /*  /*
106   *  dev_ram_init():   *  dev_ram_init():
107     *
108     *  Initializes a RAM or mirror device. Things get a bit complicated because
109     *  of dyntrans (i.e. mirrored memory ranges should be entered into the
110     *  translation arrays just as normal memory and other devices are).
111   */   */
112  void dev_ram_init(struct memory *mem, uint64_t baseaddr, uint64_t length,  void dev_ram_init(struct machine *machine, uint64_t baseaddr, uint64_t length,
113          int mode, uint64_t otheraddress)          int mode, uint64_t otheraddress)
114  {  {
115          struct ram_data *d;          struct ram_data *d;
116            int flags = MEM_DEFAULT, points_to_ram = 1;
117    
118          d = malloc(sizeof(struct ram_data));          d = malloc(sizeof(struct ram_data));
119          if (d == NULL) {          if (d == NULL) {
# Line 115  void dev_ram_init(struct memory *mem, ui Line 123  void dev_ram_init(struct memory *mem, ui
123    
124          memset(d, 0, sizeof(struct ram_data));          memset(d, 0, sizeof(struct ram_data));
125    
126            if (mode & DEV_RAM_MIGHT_POINT_TO_DEVICES) {
127                    mode &= ~DEV_RAM_MIGHT_POINT_TO_DEVICES;
128                    points_to_ram = 0;
129            }
130    
131          d->mode         = mode;          d->mode         = mode;
132          d->otheraddress = otheraddress;          d->otheraddress = otheraddress;
133    
134          switch (d->mode) {          switch (d->mode) {
135    
136          case DEV_RAM_MIRROR:          case DEV_RAM_MIRROR:
137                    /*
138                     *  Calculate the amount that the mirror memory is offset from
139                     *  the real (physical) memory. This is used in src/memory_rw.c
140                     *  with dyntrans accesses if MEM_EMULATED_RAM is set.
141                     */
142                    d->offset = baseaddr - otheraddress;
143    
144                    /*  Aligned RAM? Then it works with dyntrans.  */
145                    if (points_to_ram &&
146                        (baseaddr & (machine->arch_pagesize-1)) == 0 &&
147                        (otheraddress & (machine->arch_pagesize - 1)) == 0 &&
148                        (length & (machine->arch_pagesize - 1)) == 0)
149                            flags |= MEM_DYNTRANS_OK | MEM_DYNTRANS_WRITE_OK
150                                | MEM_EMULATED_RAM;
151    
152                    memory_device_register(machine->memory, "ram [mirror]",
153                        baseaddr, length, dev_ram_access, d, flags
154                        | MEM_READING_HAS_NO_SIDE_EFFECTS, (void *) &d->offset);
155                  break;                  break;
156    
157          case DEV_RAM_RAM:          case DEV_RAM_RAM:
158                  /*                  /*
159                   *  Allocate zero-filled RAM using mmap(). If mmap() failed,                   *  Allocate zero-filled RAM using mmap(). If mmap() failed,
# Line 138  void dev_ram_init(struct memory *mem, ui Line 171  void dev_ram_init(struct memory *mem, ui
171                          }                          }
172                          memset(d->data, 0, length);                          memset(d->data, 0, length);
173                  }                  }
174    
175                    /*  Aligned memory? Then it works with dyntrans.  */
176                    if ((baseaddr & (machine->arch_pagesize - 1)) == 0 &&
177                        (length & (machine->arch_pagesize - 1)) == 0)
178                            flags |= MEM_DYNTRANS_OK | MEM_DYNTRANS_WRITE_OK;
179    
180                    memory_device_register(machine->memory, "ram", baseaddr,
181                        d->length, dev_ram_access, d, flags
182                        | MEM_READING_HAS_NO_SIDE_EFFECTS, d->data);
183                  break;                  break;
184    
185          default:          default:
186                  fatal("dev_ram_access(): unknown mode %i\n", d->mode);                  fatal("dev_ram_access(): unknown mode %i\n", d->mode);
187                  exit(1);                  exit(1);
188          }          }
   
         memory_device_register(mem, d->mode == DEV_RAM_MIRROR?  
             "ram [mirror]" : "ram", baseaddr, length,  
             dev_ram_access, d, MEM_DEFAULT | MEM_READING_HAS_NO_SIDE_EFFECTS,  
             NULL);  
189  }  }
190    

Legend:
Removed from v.17  
changed lines
  Added in v.18

  ViewVC Help
Powered by ViewVC 1.1.26