/[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 2 - (hide annotations)
Sat Oct 6 16:03:58 2007 UTC (12 years, 2 months ago) by dpavlin
Original Path: upstream/dynamips-0.2.6-RC1/dev_ram.c
File MIME type: text/plain
File size: 1750 byte(s)
import dynamips-0.2.6-RC1

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     };
24    
25     /* Shutdown a RAM device */
26     void dev_ram_shutdown(vm_instance_t *vm,struct ram_data *d)
27     {
28     if (d != NULL) {
29     /* Remove the device */
30     dev_remove(vm,d->dev);
31     free(d->dev);
32    
33     /* Remove filename used to virtualize RAM */
34     if (d->filename) {
35     unlink(d->filename);
36     free(d->filename);
37     }
38    
39     /* Free the structure itself */
40     free(d);
41     }
42     }
43    
44     /* Initialize a RAM zone */
45     int dev_ram_init(vm_instance_t *vm,char *name,int use_mmap,
46     m_uint64_t paddr,m_uint32_t len)
47     {
48     struct ram_data *d;
49    
50     /* allocate the private data structure */
51     if (!(d = malloc(sizeof(*d)))) {
52     fprintf(stderr,"RAM: unable to create device.\n");
53     return(-1);
54     }
55    
56     memset(d,0,sizeof(*d));
57    
58     vm_object_init(&d->vm_obj);
59     d->vm_obj.name = name;
60     d->vm_obj.data = d;
61     d->vm_obj.shutdown = (vm_shutdown_t)dev_ram_shutdown;
62    
63     if (use_mmap && !(d->filename = vm_build_filename(vm,name))) {
64     fprintf(stderr,"RAM: unable to create filename.\n");
65     goto err_filename;
66     }
67    
68     if (!(d->dev = dev_create_ram(vm,name,d->filename,paddr,len))) {
69     fprintf(stderr,"RAM: unable to create device.\n");
70     goto err_dev_create;
71     }
72    
73     vm_object_add(vm,&d->vm_obj);
74     return(0);
75    
76     err_dev_create:
77     free(d->filename);
78     err_filename:
79     free(d);
80     return(-1);
81     }

  ViewVC Help
Powered by ViewVC 1.1.26