/[dynamips]/upstream/dynamips-0.2.6-RC3/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

Annotation of /upstream/dynamips-0.2.6-RC3/dev_ram.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4 - (hide annotations)
Sat Oct 6 16:06:49 2007 UTC (12 years, 2 months ago) by dpavlin
File MIME type: text/plain
File size: 2918 byte(s)
dynamips-0.2.6-RC3

1 dpavlin 1 /*
2     * Cisco C7200 (Predator) RAM emulation
3     * Copyright (c) 2006 Christophe Fillot. All rights reserved.
4     */
5    
6     #include <stdio.h>
7     #include <stdlib.h>
8     #include <string.h>
9     #include <time.h>
10     #include <errno.h>
11     #include <unistd.h>
12    
13     #include "mips64.h"
14     #include "dynamips.h"
15     #include "memory.h"
16     #include "device.h"
17    
18     /* RAM private data */
19     struct ram_data {
20     vm_obj_t vm_obj;
21     struct vdevice *dev;
22     char *filename;
23 dpavlin 4 int delete_file;
24 dpavlin 1 };
25    
26     /* Shutdown a RAM device */
27     void dev_ram_shutdown(vm_instance_t *vm,struct ram_data *d)
28     {
29     if (d != NULL) {
30     /* Remove the device */
31     dev_remove(vm,d->dev);
32     free(d->dev);
33    
34     /* Remove filename used to virtualize RAM */
35 dpavlin 4 if (d->filename && d->delete_file) {
36 dpavlin 1 unlink(d->filename);
37     free(d->filename);
38     }
39    
40     /* Free the structure itself */
41     free(d);
42     }
43     }
44    
45     /* Initialize a RAM zone */
46 dpavlin 4 int dev_ram_init(vm_instance_t *vm,char *name,int use_mmap,int delete_file,
47     char *alternate_name,m_uint64_t paddr,m_uint32_t len)
48 dpavlin 1 {
49     struct ram_data *d;
50    
51     /* allocate the private data structure */
52     if (!(d = malloc(sizeof(*d)))) {
53     fprintf(stderr,"RAM: unable to create device.\n");
54     return(-1);
55     }
56    
57     memset(d,0,sizeof(*d));
58 dpavlin 4 d->delete_file = delete_file;
59 dpavlin 1
60     vm_object_init(&d->vm_obj);
61     d->vm_obj.name = name;
62     d->vm_obj.data = d;
63     d->vm_obj.shutdown = (vm_shutdown_t)dev_ram_shutdown;
64    
65 dpavlin 4 if (use_mmap) {
66     if (!alternate_name)
67     d->filename = vm_build_filename(vm,name);
68     else
69     d->filename = strdup(alternate_name);
70    
71     if (!d->filename) {
72     fprintf(stderr,"RAM: unable to create filename.\n");
73     goto err_filename;
74     }
75 dpavlin 1 }
76    
77     if (!(d->dev = dev_create_ram(vm,name,d->filename,paddr,len))) {
78     fprintf(stderr,"RAM: unable to create device.\n");
79     goto err_dev_create;
80     }
81    
82     vm_object_add(vm,&d->vm_obj);
83     return(0);
84    
85     err_dev_create:
86     free(d->filename);
87     err_filename:
88     free(d);
89     return(-1);
90     }
91 dpavlin 4
92     /* Initialize a ghosted RAM zone */
93     int dev_ram_ghost_init(vm_instance_t *vm,char *name,char *filename,
94     m_uint64_t paddr,m_uint32_t len)
95     {
96     struct ram_data *d;
97    
98     /* allocate the private data structure */
99     if (!filename || !(d = malloc(sizeof(*d)))) {
100     fprintf(stderr,"RAM_ghost: unable to create device.\n");
101     return(-1);
102     }
103    
104     memset(d,0,sizeof(*d));
105     d->delete_file = FALSE;
106    
107     if (!(d->filename = strdup(filename)))
108     goto err_filename;
109    
110     vm_object_init(&d->vm_obj);
111     d->vm_obj.name = name;
112     d->vm_obj.data = d;
113     d->vm_obj.shutdown = (vm_shutdown_t)dev_ram_shutdown;
114    
115     if (!(d->dev = dev_create_ghost_ram(vm,name,d->filename,paddr,len))) {
116     fprintf(stderr,"RAM_ghost: unable to create device.\n");
117     goto err_dev_create;
118     }
119    
120     vm_object_add(vm,&d->vm_obj);
121     return(0);
122    
123     err_dev_create:
124     free(d->filename);
125     err_filename:
126     free(d);
127     return(-1);
128     }

  ViewVC Help
Powered by ViewVC 1.1.26