/[dynamips]/upstream/dynamips-0.2.7-RC1/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

Contents of /upstream/dynamips-0.2.7-RC1/dev_zero.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 7 - (show annotations)
Sat Oct 6 16:23:47 2007 UTC (12 years, 1 month ago) by dpavlin
File MIME type: text/plain
File size: 1552 byte(s)
dynamips-0.2.7-RC1

1 /*
2 * Cisco router simulation platform.
3 * 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 #include "cpu.h"
16 #include "vm.h"
17 #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 void *dev_zero_access(cpu_gen_t *cpu,struct vdevice *dev,
31 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