/[dynamips]/upstream/dynamips-0.2.7-RC1/dev_remote.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_remote.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: 6732 byte(s)
dynamips-0.2.7-RC1

1 /*
2 * Cisco router simulation platform.
3 * Copyright (C) 2006 Christophe Fillot. All rights reserved.
4 *
5 * Remote control module.
6 */
7
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <string.h>
11 #include <stdarg.h>
12 #include <unistd.h>
13 #include <time.h>
14 #include <errno.h>
15 #include <pthread.h>
16 #include <assert.h>
17
18 #include "utils.h"
19 #include "cpu.h"
20 #include "vm.h"
21 #include "dynamips.h"
22 #include "memory.h"
23 #include "device.h"
24 #include "net.h"
25 #include "net_io.h"
26 #include "registry.h"
27 #include "ptask.h"
28 #include "dev_c7200.h"
29 #include "dev_c3600.h"
30 #include "dev_c2691.h"
31 #include "dev_c3725.h"
32 #include "dev_c3745.h"
33 #include "dev_c2600.h"
34
35 #define DEBUG_ACCESS 0
36
37 /* Remote control private data */
38 struct remote_data {
39 vm_obj_t vm_obj;
40 struct vdevice dev;
41
42 char buffer[512];
43 u_int buf_pos;
44
45 u_int cookie_pos;
46 };
47
48 /*
49 * dev_remote_control_access()
50 */
51 void *dev_remote_control_access(cpu_gen_t *cpu,struct vdevice *dev,
52 m_uint32_t offset,u_int op_size,u_int op_type,
53 m_uint64_t *data)
54 {
55 vm_instance_t *vm = cpu->vm;
56 struct remote_data *d = dev->priv_data;
57 struct vdevice *storage_dev;
58 size_t len;
59
60 if (op_type == MTS_READ)
61 *data = 0;
62
63 #if DEBUG_ACCESS
64 if (op_type == MTS_READ) {
65 cpu_log(cpu,"REMOTE","reading reg 0x%x at pc=0x%llx\n",
66 offset,cpu_get_pc(cpu));
67 } else {
68 cpu_log(cpu,"REMOTE","writing reg 0x%x at pc=0x%llx, data=0x%llx\n",
69 offset,cpu_get_pc(cpu),*data);
70 }
71 #endif
72
73 switch(offset) {
74 /* ROM Identification tag */
75 case 0x000:
76 if (op_type == MTS_READ)
77 *data = ROM_ID;
78 break;
79
80 /* CPU ID */
81 case 0x004:
82 if (op_type == MTS_READ)
83 *data = cpu->id;
84 break;
85
86 /* Display CPU registers */
87 case 0x008:
88 if (op_type == MTS_WRITE)
89 cpu->reg_dump(cpu);
90 break;
91
92 /* Display CPU memory info */
93 case 0x00c:
94 if (op_type == MTS_WRITE)
95 cpu->mmu_dump(cpu);
96 break;
97
98 /* Reserved/Unused */
99 case 0x010:
100 break;
101
102 /* RAM size */
103 case 0x014:
104 if (op_type == MTS_READ)
105 *data = vm->ram_size;
106 break;
107
108 /* ROM size */
109 case 0x018:
110 if (op_type == MTS_READ)
111 *data = vm->rom_size;
112 break;
113
114 /* NVRAM size */
115 case 0x01c:
116 if (op_type == MTS_READ)
117 *data = vm->nvram_size;
118 break;
119
120 /* IOMEM size */
121 case 0x020:
122 if (op_type == MTS_READ)
123 *data = vm->iomem_size;
124 break;
125
126 /* Config Register */
127 case 0x024:
128 if (op_type == MTS_READ)
129 *data = vm->conf_reg;
130 break;
131
132 /* ELF entry point */
133 case 0x028:
134 if (op_type == MTS_READ)
135 *data = vm->ios_entry_point;
136 break;
137
138 /* ELF machine id */
139 case 0x02c:
140 if (op_type == MTS_READ)
141 *data = vm->elf_machine_id;
142 break;
143
144 /* Restart IOS Image */
145 case 0x030:
146 /* not implemented */
147 break;
148
149 /* Stop the virtual machine */
150 case 0x034:
151 vm->status = VM_STATUS_SHUTDOWN;
152 break;
153
154 /* Debugging/Log message: /!\ physical address */
155 case 0x038:
156 if (op_type == MTS_WRITE) {
157 len = physmem_strlen(vm,*data);
158 if (len < sizeof(d->buffer)) {
159 physmem_copy_from_vm(vm,d->buffer,*data,len+1);
160 vm_log(vm,"ROM",d->buffer);
161 }
162 }
163 break;
164
165 /* Buffering */
166 case 0x03c:
167 if (d->buf_pos < (sizeof(d->buffer)-1)) {
168 d->buffer[d->buf_pos++] = *data & 0xFF;
169 d->buffer[d->buf_pos] = 0;
170
171 if (d->buffer[d->buf_pos-1] == '\n') {
172 vm_log(vm,"ROM","%s",d->buffer);
173 d->buf_pos = 0;
174 }
175 } else
176 d->buf_pos = 0;
177 break;
178
179 /* Console output */
180 case 0x040:
181 if (op_type == MTS_WRITE)
182 vtty_put_char(vm->vtty_con,(char)*data);
183 break;
184
185 /* NVRAM address */
186 case 0x044:
187 if (op_type == MTS_READ) {
188 if ((storage_dev = dev_get_by_name(vm,"nvram")))
189 *data = storage_dev->phys_addr;
190
191 if ((storage_dev = dev_get_by_name(vm,"ssa")))
192 *data = storage_dev->phys_addr;
193
194 if (cpu->type == CPU_TYPE_MIPS64)
195 *data += MIPS_KSEG1_BASE;
196 }
197 break;
198
199 /* IO memory size for Smart-Init (C3600, others ?) */
200 case 0x048:
201 if (op_type == MTS_READ) {
202 switch(vm->type) {
203 case VM_TYPE_C3600:
204 *data = VM_C3600(vm)->nm_iomem_size;
205 break;
206 case VM_TYPE_C2691:
207 *data = VM_C2691(vm)->nm_iomem_size;
208 break;
209 case VM_TYPE_C3725:
210 *data = VM_C3725(vm)->nm_iomem_size;
211 break;
212 case VM_TYPE_C3745:
213 *data = VM_C3745(vm)->nm_iomem_size;
214 break;
215 case VM_TYPE_C2600:
216 *data = VM_C2600(vm)->nm_iomem_size;
217 break;
218 default:
219 *data = 0;
220 }
221 }
222 break;
223
224 /* Cookie position selector */
225 case 0x04c:
226 if (op_type == MTS_READ)
227 *data = d->cookie_pos;
228 else
229 d->cookie_pos = *data;
230 break;
231
232 /* Cookie data */
233 case 0x050:
234 if ((op_type == MTS_READ) && (d->cookie_pos < 64))
235 *data = vm->chassis_cookie[d->cookie_pos];
236 break;
237 }
238
239 return NULL;
240 }
241
242 /* Shutdown a remote control device */
243 void dev_remote_control_shutdown(vm_instance_t *vm,struct remote_data *d)
244 {
245 if (d != NULL) {
246 dev_remove(vm,&d->dev);
247 free(d);
248 }
249 }
250
251 /* remote control device */
252 int dev_remote_control_init(vm_instance_t *vm,m_uint64_t paddr,m_uint32_t len)
253 {
254 struct remote_data *d;
255
256 if (!(d = malloc(sizeof(*d)))) {
257 fprintf(stderr,"Remote Control: unable to create device.\n");
258 return(-1);
259 }
260
261 memset(d,0,sizeof(*d));
262
263 vm_object_init(&d->vm_obj);
264 d->vm_obj.name = "remote_ctrl";
265 d->vm_obj.data = d;
266 d->vm_obj.shutdown = (vm_shutdown_t)dev_remote_control_shutdown;
267
268 dev_init(&d->dev);
269 d->dev.name = "remote_ctrl";
270 d->dev.phys_addr = paddr;
271 d->dev.phys_len = len;
272 d->dev.handler = dev_remote_control_access;
273 d->dev.priv_data = d;
274
275 /* Map this device to the VM */
276 vm_bind_device(vm,&d->dev);
277 vm_object_add(vm,&d->vm_obj);
278 return(0);
279 }

  ViewVC Help
Powered by ViewVC 1.1.26