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

Diff of /trunk/dev_remote.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

upstream/dynamips-0.2.6-RC3/dev_remote.c revision 4 by dpavlin, Sat Oct 6 16:06:49 2007 UTC trunk/dev_remote.c revision 12 by dpavlin, Sat Oct 6 16:45:40 2007 UTC
# Line 1  Line 1 
1  /*  /*
2   * Cisco C7200 (Predator) Remote Control Module.   * Cisco router simulation platform.
3   * Copyright (C) 2006 Christophe Fillot.  All rights reserved.   * Copyright (C) 2006 Christophe Fillot.  All rights reserved.
4     *
5     * Remote control module.
6   */   */
7    
8  #include <stdio.h>  #include <stdio.h>
# Line 14  Line 16 
16  #include <assert.h>  #include <assert.h>
17    
18  #include "utils.h"  #include "utils.h"
19  #include "mips64.h"  #include "cpu.h"
20  #include "cp0.h"  #include "vm.h"
21  #include "dynamips.h"  #include "dynamips.h"
22  #include "memory.h"  #include "memory.h"
23  #include "device.h"  #include "device.h"
# Line 23  Line 25 
25  #include "net_io.h"  #include "net_io.h"
26  #include "registry.h"  #include "registry.h"
27  #include "ptask.h"  #include "ptask.h"
 #include "vm.h"  
28  #include "dev_c7200.h"  #include "dev_c7200.h"
29  #include "dev_c3600.h"  #include "dev_c3600.h"
30  #include "dev_c2691.h"  #include "dev_c2691.h"
31  #include "dev_c3725.h"  #include "dev_c3725.h"
32  #include "dev_c3745.h"  #include "dev_c3745.h"
33    #include "dev_c2600.h"
34    
35  #define DEBUG_ACCESS 0  #define DEBUG_ACCESS 0
36    
37    #define ROMMON_SET_VAR   0x01
38    #define ROMMON_GET_VAR   0x02
39    #define ROMMON_CLEAR_VAR_STAT  0x03
40    
41  /* Remote control private data */  /* Remote control private data */
42  struct remote_data {  struct remote_data {
43     vm_obj_t vm_obj;     vm_obj_t vm_obj;
44     struct vdevice dev;     struct vdevice dev;
45    
46     char buffer[512];     /* Console buffer */
47     u_int buf_pos;     char con_buffer[512];
48       u_int con_buf_pos;
49    
50       /* ROMMON variables buffer */
51       char var_buffer[512];
52       u_int var_buf_pos;
53       u_int var_status;
54    
55       /* Position for cookie reading */
56       u_int cookie_pos;
57  };  };
58    
59  /*  /*
60   * dev_remote_control_access()   * dev_remote_control_access()
61   */   */
62  void *dev_remote_control_access(cpu_mips_t *cpu,struct vdevice *dev,  void *dev_remote_control_access(cpu_gen_t *cpu,struct vdevice *dev,
63                                  m_uint32_t offset,u_int op_size,u_int op_type,                                  m_uint32_t offset,u_int op_size,u_int op_type,
64                                  m_uint64_t *data)                                  m_uint64_t *data)
65  {  {
66       vm_instance_t *vm = cpu->vm;
67     struct remote_data *d = dev->priv_data;     struct remote_data *d = dev->priv_data;
68     struct vdevice *storage_dev;     struct vdevice *storage_dev;
69     size_t len;     size_t len;
# Line 57  void *dev_remote_control_access(cpu_mips Line 73  void *dev_remote_control_access(cpu_mips
73    
74  #if DEBUG_ACCESS  #if DEBUG_ACCESS
75     if (op_type == MTS_READ) {     if (op_type == MTS_READ) {
76        cpu_log(cpu,"REMOTE","reading reg 0x%x at pc=0x%llx\n",offset,cpu->pc);        cpu_log(cpu,"REMOTE","reading reg 0x%x at pc=0x%llx\n",
77                  offset,cpu_get_pc(cpu));
78     } else {     } else {
79        cpu_log(cpu,"REMOTE","writing reg 0x%x at pc=0x%llx, data=0x%llx\n",        cpu_log(cpu,"REMOTE","writing reg 0x%x at pc=0x%llx, data=0x%llx\n",
80                offset,cpu->pc,*data);                offset,cpu_get_pc(cpu),*data);
81     }     }
82  #endif  #endif
83    
# Line 80  void *dev_remote_control_access(cpu_mips Line 97  void *dev_remote_control_access(cpu_mips
97        /* Display CPU registers */        /* Display CPU registers */
98        case 0x008:        case 0x008:
99           if (op_type == MTS_WRITE)           if (op_type == MTS_WRITE)
100              mips64_dump_regs(cpu);              cpu->reg_dump(cpu);
101           break;           break;
102    
103        /* Display CPU TLB */        /* Display CPU memory info */
104        case 0x00c:        case 0x00c:
105           if (op_type == MTS_WRITE)           if (op_type == MTS_WRITE)
106              tlb_dump(cpu);              cpu->mmu_dump(cpu);
107           break;           break;
108    
109        /* Reserved/Unused */        /* Reserved/Unused */
# Line 96  void *dev_remote_control_access(cpu_mips Line 113  void *dev_remote_control_access(cpu_mips
113        /* RAM size */        /* RAM size */
114        case 0x014:        case 0x014:
115           if (op_type == MTS_READ)           if (op_type == MTS_READ)
116              *data = cpu->vm->ram_size;              *data = vm->ram_size;
117           break;           break;
118    
119        /* ROM size */        /* ROM size */
120        case 0x018:        case 0x018:
121           if (op_type == MTS_READ)           if (op_type == MTS_READ)
122              *data = cpu->vm->rom_size;              *data = vm->rom_size;
123           break;           break;
124    
125        /* NVRAM size */        /* NVRAM size */
126        case 0x01c:        case 0x01c:
127           if (op_type == MTS_READ)           if (op_type == MTS_READ)
128              *data = cpu->vm->nvram_size;              *data = vm->nvram_size;
129           break;                       break;            
130    
131        /* IOMEM size */        /* IOMEM size */
132        case 0x020:        case 0x020:
133          if (op_type == MTS_READ)          if (op_type == MTS_READ)
134              *data = cpu->vm->iomem_size;              *data = vm->iomem_size;
135           break;           break;
136    
137        /* Config Register */        /* Config Register */
138        case 0x024:        case 0x024:
139           if (op_type == MTS_READ)           if (op_type == MTS_READ)
140              *data = cpu->vm->conf_reg;              *data = vm->conf_reg;
141           break;           break;
142    
143        /* ELF entry point */        /* ELF entry point */
144        case 0x028:        case 0x028:
145           if (op_type == MTS_READ)           if (op_type == MTS_READ)
146              *data = cpu->vm->ios_entry_point;              *data = vm->ios_entry_point;
147           break;                 break;      
148    
149        /* ELF machine id */        /* ELF machine id */
150        case 0x02c:        case 0x02c:
151           if (op_type == MTS_READ)           if (op_type == MTS_READ)
152              *data = cpu->vm->elf_machine_id;              *data = vm->elf_machine_id;
153           break;           break;
154    
155        /* Restart IOS Image */        /* Restart IOS Image */
# Line 142  void *dev_remote_control_access(cpu_mips Line 159  void *dev_remote_control_access(cpu_mips
159    
160        /* Stop the virtual machine */        /* Stop the virtual machine */
161        case 0x034:        case 0x034:
162           cpu->vm->status = VM_STATUS_SHUTDOWN;           vm->status = VM_STATUS_SHUTDOWN;
163           break;           break;
164    
165        /* Debugging/Log message: /!\ physical address */        /* Debugging/Log message: /!\ physical address */
166        case 0x038:        case 0x038:
167           if (op_type == MTS_WRITE) {           if (op_type == MTS_WRITE) {
168              len = physmem_strlen(cpu->vm,*data);              len = physmem_strlen(vm,*data);
169              if (len < sizeof(d->buffer)) {              if (len < sizeof(d->con_buffer)) {
170                 physmem_copy_from_vm(cpu->vm,d->buffer,*data,len+1);                 physmem_copy_from_vm(vm,d->con_buffer,*data,len+1);
171                 vm_log(cpu->vm,"ROM",d->buffer);                 vm_log(vm,"ROM",d->con_buffer);
172              }              }
173           }           }
174           break;           break;
175    
176        /* Buffering */        /* Console Buffering */
177        case 0x03c:        case 0x03c:
178           if (d->buf_pos < (sizeof(d->buffer)-1)) {           if (op_type == MTS_WRITE) {
179              d->buffer[d->buf_pos++] = *data & 0xFF;              if (d->con_buf_pos < (sizeof(d->con_buffer)-1)) {
180              d->buffer[d->buf_pos] = 0;                 d->con_buffer[d->con_buf_pos++] = *data & 0xFF;
181                   d->con_buffer[d->con_buf_pos] = 0;
182              if (d->buffer[d->buf_pos-1] == '\n') {  
183                 vm_log(cpu->vm,"ROM","%s",d->buffer);                 if (d->con_buffer[d->con_buf_pos-1] == '\n') {
184                 d->buf_pos = 0;                    vm_log(vm,"ROM","%s",d->con_buffer);
185              }                    d->con_buf_pos = 0;
186           } else                 }
187              d->buf_pos = 0;              } else
188                   d->con_buf_pos = 0;
189             }
190           break;           break;
191    
192        /* Console output */        /* Console output */
193        case 0x040:        case 0x040:
194           if (op_type == MTS_WRITE)           if (op_type == MTS_WRITE)
195              vtty_put_char(cpu->vm->vtty_con,(char)*data);              vtty_put_char(vm->vtty_con,(char)*data);
196           break;           break;
197    
198        /* NVRAM address */        /* NVRAM address */
199        case 0x044:        case 0x044:
200           if (op_type == MTS_READ) {           if (op_type == MTS_READ) {
201              if ((storage_dev = dev_get_by_name(cpu->vm,"nvram")))              if ((storage_dev = dev_get_by_name(vm,"nvram")))
202                 *data = storage_dev->phys_addr;                 *data = storage_dev->phys_addr;
203    
204              if ((storage_dev = dev_get_by_name(cpu->vm,"ssa")))              if ((storage_dev = dev_get_by_name(vm,"ssa")))
205                 *data = storage_dev->phys_addr;                 *data = storage_dev->phys_addr;
206    
207                if (cpu->type == CPU_TYPE_MIPS64)
208                   *data += MIPS_KSEG1_BASE;
209           }           }
210           break;           break;
211    
212        /* IO memory size for Smart-Init (C3600, others ?) */        /* IO memory size for Smart-Init (C3600, others ?) */
213        case 0x048:        case 0x048:
214           if (op_type == MTS_READ) {           if (op_type == MTS_READ)
215              switch(cpu->vm->type) {              *data = vm->nm_iomem_size;
216                 case VM_TYPE_C3600:           break;
217                    *data = VM_C3600(cpu->vm)->nm_iomem_size;  
218                    break;        /* Cookie position selector */
219                 case VM_TYPE_C2691:        case 0x04c:
220                    *data = VM_C2691(cpu->vm)->nm_iomem_size;           if (op_type == MTS_READ)
221                *data = d->cookie_pos;
222             else
223                d->cookie_pos = *data;
224             break;
225            
226          /* Cookie data */
227          case 0x050:
228             if ((op_type == MTS_READ) && (d->cookie_pos < 64))
229                *data = vm->chassis_cookie[d->cookie_pos];
230             break;
231    
232          /* ROMMON variable */
233          case 0x054:
234             if (op_type == MTS_WRITE) {
235                if (d->var_buf_pos < (sizeof(d->var_buffer)-1)) {
236                   d->var_buffer[d->var_buf_pos++] = *data & 0xFF;
237                   d->var_buffer[d->var_buf_pos] = 0;
238                } else
239                   d->var_buf_pos = 0;
240             } else {
241                if (d->var_buf_pos < (sizeof(d->var_buffer)-1)) {
242                   *data = d->var_buffer[d->var_buf_pos++];
243                } else {
244                   d->var_buf_pos = 0;
245                   *data = 0;
246                }
247             }
248             break;
249    
250          /* ROMMON variable command */
251          case 0x058:
252             if (op_type == MTS_WRITE) {
253                switch(*data & 0xFF) {
254                   case ROMMON_SET_VAR:
255                      d->var_status = rommon_var_add_str(&vm->rommon_vars,
256                                                         d->var_buffer);
257                      d->var_buf_pos = 0;
258                    break;                    break;
259                 case VM_TYPE_C3725:                 case ROMMON_GET_VAR:
260                    *data = VM_C3725(cpu->vm)->nm_iomem_size;                    d->var_status = rommon_var_get(&vm->rommon_vars,
261                                                     d->var_buffer,
262                                                     d->var_buffer,
263                                                     sizeof(d->var_buffer));
264                      d->var_buf_pos = 0;
265                    break;                    break;
266                 case VM_TYPE_C3745:                 case ROMMON_CLEAR_VAR_STAT:
267                    *data = VM_C3745(cpu->vm)->nm_iomem_size;                    d->var_buf_pos = 0;
268                    break;                    break;
269                 default:                 default:
270                    *data = 0;                    d->var_status = -1;
271              }              }
272             } else {
273                *data = d->var_status;
274           }           }
275           break;           break;
           
276     }     }
277    
278     return NULL;     return NULL;

Legend:
Removed from v.4  
changed lines
  Added in v.12

  ViewVC Help
Powered by ViewVC 1.1.26