/[dynamips]/trunk/dev_zero.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 /trunk/dev_zero.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 12 - (hide annotations)
Sat Oct 6 16:45:40 2007 UTC (16 years, 6 months ago) by dpavlin
File MIME type: text/plain
File size: 1552 byte(s)
make working copy

1 dpavlin 1 /*
2 dpavlin 7 * Cisco router simulation platform.
3 dpavlin 1 * Copyright (C) 2005,2006 Christophe Fillot. All rights reserved.
4     *
5     * Zeroed memory zone.
6     */
7    
8     #include <stdio.h>
9     #include <stdlib.h>
10     #include <string.h>
11     #include <unistd.h>
12     #include <pthread.h>
13     #include <errno.h>
14    
15 dpavlin 7 #include "cpu.h"
16     #include "vm.h"
17 dpavlin 1 #include "dynamips.h"
18     #include "memory.h"
19     #include "device.h"
20    
21     /* Zero zone private data */
22     struct zero_data {
23     vm_obj_t vm_obj;
24     struct vdevice dev;
25     };
26    
27     /*
28     * dev_zero_access()
29     */
30 dpavlin 7 void *dev_zero_access(cpu_gen_t *cpu,struct vdevice *dev,
31 dpavlin 1 m_uint32_t offset,u_int op_size,u_int op_type,
32     m_uint64_t *data)
33     {
34     if (op_type == MTS_READ)
35     *data = 0;
36    
37     return NULL;
38     }
39    
40     /* Shutdown a zeroed memory zone */
41     void dev_zero_shutdown(vm_instance_t *vm,struct zero_data *d)
42     {
43     if (d != NULL) {
44     dev_remove(vm,&d->dev);
45     free(d);
46     }
47     }
48    
49     /* Initialized a zeroed memory zone */
50     int dev_zero_init(vm_instance_t *vm,char *name,m_uint64_t paddr,m_uint32_t len)
51     {
52     struct zero_data *d;
53    
54     if (!(d = malloc(sizeof(*d)))) {
55     fprintf(stderr,"ZERO: unable to create device.\n");
56     return(-1);
57     }
58    
59     vm_object_init(&d->vm_obj);
60     d->vm_obj.name = name;
61     d->vm_obj.data = d;
62     d->vm_obj.shutdown = (vm_shutdown_t)dev_zero_shutdown;
63    
64     dev_init(&d->dev);
65     d->dev.name = name;
66     d->dev.phys_addr = paddr;
67     d->dev.phys_len = len;
68     d->dev.handler = dev_zero_access;
69    
70     /* Map this device to the VM */
71     vm_bind_device(vm,&d->dev);
72     vm_object_add(vm,&d->vm_obj);
73     return(0);
74     }

  ViewVC Help
Powered by ViewVC 1.1.26