19
19
*/
20
20
21
21
#include "qemu/osdep.h"
22
- #include "qapi/error.h"
23
- #include "qemu/qemu-print.h"
24
22
#include "exec/exec-all.h"
25
23
#include "cpu.h"
26
24
#include "disas/dis-asm.h"
25
+ #include "unicorn_helper.h"
27
26
28
27
static void avr_cpu_set_pc (CPUState * cs , vaddr value )
29
28
{
@@ -56,7 +55,8 @@ static void avr_cpu_reset(DeviceState *ds)
56
55
AVRCPUClass * mcc = AVR_CPU_GET_CLASS (cpu );
57
56
CPUAVRState * env = & cpu -> env ;
58
57
59
- mcc -> parent_reset (ds );
58
+ if (mcc -> parent_reset )
59
+ mcc -> parent_reset (ds );
60
60
61
61
env -> pc_w = 0 ;
62
62
env -> sregI = 1 ;
@@ -80,29 +80,28 @@ static void avr_cpu_reset(DeviceState *ds)
80
80
memset (env -> r , 0 , sizeof (env -> r ));
81
81
}
82
82
83
+ #if 0
83
84
static void avr_cpu_disas_set_info (CPUState * cpu , disassemble_info * info )
84
85
{
85
86
info -> mach = bfd_arch_avr ;
86
87
info -> print_insn = avr_print_insn ;
87
88
}
89
+ #endif
88
90
89
- static void avr_cpu_realizefn (DeviceState * dev , Error * * errp )
91
+ static void avr_cpu_realizefn (DeviceState * dev )
90
92
{
91
93
CPUState * cs = CPU (dev );
92
94
AVRCPUClass * mcc = AVR_CPU_GET_CLASS (dev );
93
- Error * local_err = NULL ;
94
95
95
- cpu_exec_realizefn (cs , & local_err );
96
- if (local_err != NULL ) {
97
- error_propagate (errp , local_err );
98
- return ;
99
- }
96
+ cpu_exec_realizefn (cs );
100
97
qemu_init_vcpu (cs );
101
98
cpu_reset (cs );
102
99
103
- mcc -> parent_realize (dev , errp );
100
+ if (mcc -> parent_realize )
101
+ mcc -> parent_realize (dev );
104
102
}
105
103
104
+ #if 0
106
105
static void avr_cpu_set_int (void * opaque , int irq , int level )
107
106
{
108
107
AVRCPU * cpu = opaque ;
@@ -120,18 +119,24 @@ static void avr_cpu_set_int(void *opaque, int irq, int level)
120
119
}
121
120
}
122
121
}
122
+ #endif
123
123
124
- static void avr_cpu_initfn (Object * obj )
124
+ static void avr_cpu_initfn (Object * obj , struct uc_struct * uc )
125
125
{
126
126
AVRCPU * cpu = AVR_CPU (obj );
127
+ CPUAVRState * const env = & cpu -> env ;
127
128
129
+ env -> uc = uc ;
128
130
cpu_set_cpustate_pointers (cpu );
129
131
132
+ #if 0
130
133
/* Set the number of interrupts supported by the CPU. */
131
134
qdev_init_gpio_in (DEVICE (cpu ), avr_cpu_set_int ,
132
135
sizeof (cpu -> env .intsrc ) * 8 );
136
+ #endif
133
137
}
134
138
139
+ #if 0
135
140
static ObjectClass * avr_cpu_class_by_name (const char * cpu_model )
136
141
{
137
142
ObjectClass * oc ;
@@ -143,7 +148,9 @@ static ObjectClass *avr_cpu_class_by_name(const char *cpu_model)
143
148
}
144
149
return oc ;
145
150
}
151
+ #endif
146
152
153
+ #if 0
147
154
static void avr_cpu_dump_state (CPUState * cs , FILE * f , int flags )
148
155
{
149
156
AVRCPU * cpu = AVR_CPU (cs );
@@ -182,36 +189,45 @@ static void avr_cpu_dump_state(CPUState *cs, FILE *f, int flags)
182
189
}
183
190
qemu_fprintf (f , "\n" );
184
191
}
192
+ #endif
185
193
186
194
static void avr_cpu_class_init (ObjectClass * oc , void * data )
187
195
{
188
- DeviceClass * dc = DEVICE_CLASS (oc );
189
196
CPUClass * cc = CPU_CLASS (oc );
190
197
AVRCPUClass * mcc = AVR_CPU_CLASS (oc );
191
198
192
- mcc -> parent_realize = dc -> realize ;
193
- dc -> realize = avr_cpu_realizefn ;
194
-
195
- device_class_set_parent_reset (dc , avr_cpu_reset , & mcc -> parent_reset );
199
+ mcc -> parent_realize = NULL ;
200
+ mcc -> parent_reset = NULL ;
196
201
202
+ #if 0
197
203
cc -> class_by_name = avr_cpu_class_by_name ;
204
+ #endif
198
205
206
+ cc -> reset = avr_cpu_reset ;
199
207
cc -> has_work = avr_cpu_has_work ;
200
208
cc -> do_interrupt = avr_cpu_do_interrupt ;
201
209
cc -> cpu_exec_interrupt = avr_cpu_exec_interrupt ;
210
+ #if 0
202
211
cc -> dump_state = avr_cpu_dump_state ;
212
+ #endif
203
213
cc -> set_pc = avr_cpu_set_pc ;
214
+ #if 0
204
215
cc -> memory_rw_debug = avr_cpu_memory_rw_debug ;
216
+ #endif
205
217
cc -> get_phys_page_debug = avr_cpu_get_phys_page_debug ;
206
218
cc -> tlb_fill = avr_cpu_tlb_fill ;
219
+ #if 0
207
220
cc -> vmsd = & vms_avr_cpu ;
208
221
cc -> disas_set_info = avr_cpu_disas_set_info ;
222
+ #endif
209
223
cc -> tcg_initialize = avr_cpu_tcg_init ;
210
224
cc -> synchronize_from_tb = avr_cpu_synchronize_from_tb ;
225
+ #if 0
211
226
cc -> gdb_read_register = avr_cpu_gdb_read_register ;
212
227
cc -> gdb_write_register = avr_cpu_gdb_write_register ;
213
228
cc -> gdb_num_core_regs = 35 ;
214
229
cc -> gdb_core_xml_file = "avr-cpu.xml" ;
230
+ #endif
215
231
}
216
232
217
233
/*
@@ -321,11 +337,28 @@ static void avr_avr6_initfn(Object *obj)
321
337
}
322
338
323
339
typedef struct AVRCPUInfo {
340
+ int model ;
324
341
const char * name ;
325
342
void (* initfn )(Object * obj );
326
343
} AVRCPUInfo ;
327
344
345
+ static const AVRCPUInfo avr_cpu_info [] = {
346
+ {UC_CPU_AVR_AVR5 , "avr5" , avr_avr5_initfn },
347
+ {UC_CPU_AVR_AVR51 , "avr51" , avr_avr51_initfn },
348
+ {UC_CPU_AVR_AVR6 , "avr6" , avr_avr6_initfn },
349
+ };
350
+
351
+ static const AVRCPUInfo * avr_cpu_info_get (int cpu_model )
352
+ {
353
+ for (int i = 0 ; i < ARRAY_SIZE (avr_cpu_info ); i ++ ) {
354
+ const AVRCPUInfo * const cip = & avr_cpu_info [i ];
355
+ if (cpu_model == cip -> model )
356
+ return cip ;
357
+ }
358
+ return NULL ;
359
+ }
328
360
361
+ #if 0
329
362
static void avr_cpu_list_entry (gpointer data , gpointer user_data )
330
363
{
331
364
const char * typename = object_class_get_name (OBJECT_CLASS (data ));
@@ -364,3 +397,48 @@ static const TypeInfo avr_cpu_type_info[] = {
364
397
};
365
398
366
399
DEFINE_TYPES (avr_cpu_type_info )
400
+ #endif
401
+
402
+ AVRCPU * cpu_avr_init (struct uc_struct * uc )
403
+ {
404
+ AVRCPU * cpu ;
405
+ CPUState * cs ;
406
+ CPUClass * cc ;
407
+ ObjectClass * oc ;
408
+
409
+ cpu = calloc (1 , sizeof (* cpu ));
410
+ if (cpu == NULL ) {
411
+ return NULL ;
412
+ }
413
+
414
+ if (uc -> cpu_model == INT_MAX )
415
+ uc -> cpu_model = UC_CPU_AVR_AVR6 ;
416
+ const AVRCPUInfo * const cip = avr_cpu_info_get (uc -> cpu_model );
417
+ if (!cip ) {
418
+ free (cpu );
419
+ return NULL ;
420
+ }
421
+
422
+ cs = & cpu -> parent_obj ;
423
+ cc = & AVR_CPU_GET_CLASS (cpu )-> parent_class ;
424
+ oc = (ObjectClass * )cc ;
425
+ cs -> cc = cc ;
426
+ cs -> uc = uc ;
427
+ uc -> cpu = cs ;
428
+
429
+ cpu_class_init (uc , cc );
430
+ avr_cpu_class_init (oc , NULL );
431
+
432
+ cpu_common_initfn (uc , cs );
433
+ avr_cpu_initfn (cs , uc );
434
+ cip -> initfn (cs );
435
+
436
+ avr_cpu_realizefn (cs );
437
+
438
+ // init address space
439
+ cpu_address_space_init (cs , 0 , cs -> memory );
440
+
441
+ qemu_init_vcpu (cs );
442
+
443
+ return cpu ;
444
+ }
0 commit comments