/[dynamips]/upstream/dynamips-0.2.5/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.5/dev_remote.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (show annotations)
Sat Oct 6 16:01:44 2007 UTC (12 years, 2 months ago) by dpavlin
File MIME type: text/plain
File size: 5605 byte(s)
import 0.2.5 from upstream

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

  ViewVC Help
Powered by ViewVC 1.1.26