1 |
/* |
2 |
* Cisco router simulation platform. |
3 |
* Copyright (c) 2007 Christophe Fillot (cf@utc.fr) |
4 |
* |
5 |
* WIC-1T & WIC-2T devices. |
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 <assert.h> |
16 |
|
17 |
#include "crc.h" |
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 "ptask.h" |
27 |
#include "dev_wic_serial.h" |
28 |
|
29 |
/* Debugging flags */ |
30 |
#define DEBUG_UNKNOWN 1 |
31 |
|
32 |
struct wic_serial_data { |
33 |
char *name; |
34 |
struct vdevice dev; |
35 |
vm_instance_t *vm; |
36 |
}; |
37 |
|
38 |
/* |
39 |
* dev_wic1t_access() |
40 |
*/ |
41 |
static void *dev_wic1t_access(cpu_gen_t *cpu,struct vdevice *dev, |
42 |
m_uint32_t offset,u_int op_size,u_int op_type, |
43 |
m_uint64_t *data) |
44 |
{ |
45 |
struct wic_serial_data *d = dev->priv_data; |
46 |
|
47 |
switch(offset) { |
48 |
case 0x04: |
49 |
if (op_type == MTS_READ) |
50 |
*data = 0xFF; |
51 |
break; |
52 |
|
53 |
case 0x08: |
54 |
if (op_type == MTS_READ) |
55 |
*data = 0xFF; |
56 |
break; |
57 |
|
58 |
#if DEBUG_UNKNOWN |
59 |
default: |
60 |
if (op_type == MTS_READ) { |
61 |
cpu_log(cpu,d->name, |
62 |
"read from unknown addr 0x%x, pc=0x%llx (size=%u)\n", |
63 |
offset,cpu_get_pc(cpu),op_size); |
64 |
} else { |
65 |
cpu_log(cpu,d->name, |
66 |
"write to unknown addr 0x%x, value=0x%llx, " |
67 |
"pc=0x%llx (size=%u)\n", |
68 |
offset,*data,cpu_get_pc(cpu),op_size); |
69 |
} |
70 |
#endif |
71 |
} |
72 |
|
73 |
return NULL; |
74 |
} |
75 |
|
76 |
/* |
77 |
* dev_wic2t_access() |
78 |
*/ |
79 |
static void *dev_wic2t_access(cpu_gen_t *cpu,struct vdevice *dev, |
80 |
m_uint32_t offset,u_int op_size,u_int op_type, |
81 |
m_uint64_t *data) |
82 |
{ |
83 |
struct wic_serial_data *d = dev->priv_data; |
84 |
|
85 |
switch(offset) { |
86 |
/* Port 0 */ |
87 |
case 0x04: |
88 |
if (op_type == MTS_READ) |
89 |
*data = 0xFF; |
90 |
break; |
91 |
|
92 |
case 0x08: |
93 |
if (op_type == MTS_READ) |
94 |
*data = 0xFF; |
95 |
break; |
96 |
|
97 |
/* Port 1 */ |
98 |
case 0x14: |
99 |
if (op_type == MTS_READ) |
100 |
*data = 0xFF; |
101 |
break; |
102 |
|
103 |
case 0x18: |
104 |
if (op_type == MTS_READ) |
105 |
*data = 0xFF; |
106 |
break; |
107 |
|
108 |
#if DEBUG_UNKNOWN |
109 |
default: |
110 |
if (op_type == MTS_READ) { |
111 |
cpu_log(cpu,d->name, |
112 |
"read from unknown addr 0x%x, pc=0x%llx (size=%u)\n", |
113 |
offset,cpu_get_pc(cpu),op_size); |
114 |
} else { |
115 |
cpu_log(cpu,d->name, |
116 |
"write to unknown addr 0x%x, value=0x%llx, " |
117 |
"pc=0x%llx (size=%u)\n", |
118 |
offset,*data,cpu_get_pc(cpu),op_size); |
119 |
} |
120 |
#endif |
121 |
} |
122 |
|
123 |
return NULL; |
124 |
} |
125 |
|
126 |
/* |
127 |
* dev_wic_serial_init() |
128 |
* |
129 |
* Generic WIC Serial initialization code. |
130 |
*/ |
131 |
struct wic_serial_data * |
132 |
dev_wic_serial_init(vm_instance_t *vm,char *name,u_int model, |
133 |
m_uint64_t paddr,m_uint32_t len) |
134 |
{ |
135 |
struct wic_serial_data *d; |
136 |
struct vdevice *dev; |
137 |
|
138 |
/* Allocate the private data structure for WIC */ |
139 |
if (!(d = malloc(sizeof(*d)))) { |
140 |
fprintf(stderr,"%s (WIC-SERIAL): out of memory\n",name); |
141 |
return NULL; |
142 |
} |
143 |
|
144 |
memset(d,0,sizeof(*d)); |
145 |
|
146 |
/* Create the device itself */ |
147 |
if (!(dev = dev_create(name))) { |
148 |
fprintf(stderr,"%s (WIC): unable to create device.\n",name); |
149 |
free(d); |
150 |
return NULL; |
151 |
} |
152 |
|
153 |
d->name = name; |
154 |
d->vm = vm; |
155 |
|
156 |
dev_init(&d->dev); |
157 |
d->dev.name = name; |
158 |
d->dev.priv_data = d; |
159 |
d->dev.phys_addr = paddr; |
160 |
d->dev.phys_len = len; |
161 |
|
162 |
switch(model) { |
163 |
case WIC_SERIAL_MODEL_1T: |
164 |
d->dev.handler = dev_wic1t_access; |
165 |
break; |
166 |
case WIC_SERIAL_MODEL_2T: |
167 |
d->dev.handler = dev_wic2t_access; |
168 |
break; |
169 |
default: |
170 |
fprintf(stderr,"%s (WIC-SERIAL): unknown model %u\n",name,model); |
171 |
free(d); |
172 |
return NULL; |
173 |
} |
174 |
|
175 |
/* Map this device to the VM */ |
176 |
vm_bind_device(vm,&d->dev); |
177 |
return(d); |
178 |
} |
179 |
|
180 |
/* Remove a WIC serial device */ |
181 |
void dev_wic_serial_remove(struct wic_serial_data *d) |
182 |
{ |
183 |
if (d != NULL) { |
184 |
/* Remove the device */ |
185 |
dev_remove(d->vm,&d->dev); |
186 |
|
187 |
/* Free the structure itself */ |
188 |
free(d); |
189 |
} |
190 |
} |