/[dynamips]/upstream/dynamips-0.2.6-RC3/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

Annotation of /upstream/dynamips-0.2.6-RC3/dev_remote.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4 - (hide annotations)
Sat Oct 6 16:06:49 2007 UTC (12 years, 2 months ago) by dpavlin
File MIME type: text/plain
File size: 6152 byte(s)
dynamips-0.2.6-RC3

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

  ViewVC Help
Powered by ViewVC 1.1.26