xref: /openbmc/qemu/hw/arm/armv7m.c (revision 67b5595d)
1 /*
2  * ARMV7M System emulation.
3  *
4  * Copyright (c) 2006-2007 CodeSourcery.
5  * Written by Paul Brook
6  *
7  * This code is licensed under the GPL.
8  */
9 
10 #include "qemu/osdep.h"
11 #include "hw/arm/armv7m.h"
12 #include "qapi/error.h"
13 #include "hw/sysbus.h"
14 #include "hw/arm/boot.h"
15 #include "hw/loader.h"
16 #include "hw/qdev-properties.h"
17 #include "hw/qdev-clock.h"
18 #include "elf.h"
19 #include "sysemu/reset.h"
20 #include "qemu/error-report.h"
21 #include "qemu/module.h"
22 #include "qemu/log.h"
23 #include "target/arm/idau.h"
24 #include "target/arm/cpu-features.h"
25 #include "migration/vmstate.h"
26 
27 /* Bitbanded IO.  Each word corresponds to a single bit.  */
28 
29 /* Get the byte address of the real memory for a bitband access.  */
30 static inline hwaddr bitband_addr(BitBandState *s, hwaddr offset)
31 {
32     return s->base | (offset & 0x1ffffff) >> 5;
33 }
34 
35 static MemTxResult bitband_read(void *opaque, hwaddr offset,
36                                 uint64_t *data, unsigned size, MemTxAttrs attrs)
37 {
38     BitBandState *s = opaque;
39     uint8_t buf[4];
40     MemTxResult res;
41     int bitpos, bit;
42     hwaddr addr;
43 
44     assert(size <= 4);
45 
46     /* Find address in underlying memory and round down to multiple of size */
47     addr = bitband_addr(s, offset) & (-size);
48     res = address_space_read(&s->source_as, addr, attrs, buf, size);
49     if (res) {
50         return res;
51     }
52     /* Bit position in the N bytes read... */
53     bitpos = (offset >> 2) & ((size * 8) - 1);
54     /* ...converted to byte in buffer and bit in byte */
55     bit = (buf[bitpos >> 3] >> (bitpos & 7)) & 1;
56     *data = bit;
57     return MEMTX_OK;
58 }
59 
60 static MemTxResult bitband_write(void *opaque, hwaddr offset, uint64_t value,
61                                  unsigned size, MemTxAttrs attrs)
62 {
63     BitBandState *s = opaque;
64     uint8_t buf[4];
65     MemTxResult res;
66     int bitpos, bit;
67     hwaddr addr;
68 
69     assert(size <= 4);
70 
71     /* Find address in underlying memory and round down to multiple of size */
72     addr = bitband_addr(s, offset) & (-size);
73     res = address_space_read(&s->source_as, addr, attrs, buf, size);
74     if (res) {
75         return res;
76     }
77     /* Bit position in the N bytes read... */
78     bitpos = (offset >> 2) & ((size * 8) - 1);
79     /* ...converted to byte in buffer and bit in byte */
80     bit = 1 << (bitpos & 7);
81     if (value & 1) {
82         buf[bitpos >> 3] |= bit;
83     } else {
84         buf[bitpos >> 3] &= ~bit;
85     }
86     return address_space_write(&s->source_as, addr, attrs, buf, size);
87 }
88 
89 static const MemoryRegionOps bitband_ops = {
90     .read_with_attrs = bitband_read,
91     .write_with_attrs = bitband_write,
92     .endianness = DEVICE_NATIVE_ENDIAN,
93     .impl.min_access_size = 1,
94     .impl.max_access_size = 4,
95     .valid.min_access_size = 1,
96     .valid.max_access_size = 4,
97 };
98 
99 static void bitband_init(Object *obj)
100 {
101     BitBandState *s = BITBAND(obj);
102     SysBusDevice *dev = SYS_BUS_DEVICE(obj);
103 
104     memory_region_init_io(&s->iomem, obj, &bitband_ops, s,
105                           "bitband", 0x02000000);
106     sysbus_init_mmio(dev, &s->iomem);
107 }
108 
109 static void bitband_realize(DeviceState *dev, Error **errp)
110 {
111     BitBandState *s = BITBAND(dev);
112 
113     if (!s->source_memory) {
114         error_setg(errp, "source-memory property not set");
115         return;
116     }
117 
118     address_space_init(&s->source_as, s->source_memory, "bitband-source");
119 }
120 
121 /* Board init.  */
122 
123 static const hwaddr bitband_input_addr[ARMV7M_NUM_BITBANDS] = {
124     0x20000000, 0x40000000
125 };
126 
127 static const hwaddr bitband_output_addr[ARMV7M_NUM_BITBANDS] = {
128     0x22000000, 0x42000000
129 };
130 
131 static MemTxResult v7m_sysreg_ns_write(void *opaque, hwaddr addr,
132                                        uint64_t value, unsigned size,
133                                        MemTxAttrs attrs)
134 {
135     MemoryRegion *mr = opaque;
136 
137     if (attrs.secure) {
138         /* S accesses to the alias act like NS accesses to the real region */
139         attrs.secure = 0;
140         return memory_region_dispatch_write(mr, addr, value,
141                                             size_memop(size) | MO_TE, attrs);
142     } else {
143         /* NS attrs are RAZ/WI for privileged, and BusFault for user */
144         if (attrs.user) {
145             return MEMTX_ERROR;
146         }
147         return MEMTX_OK;
148     }
149 }
150 
151 static MemTxResult v7m_sysreg_ns_read(void *opaque, hwaddr addr,
152                                       uint64_t *data, unsigned size,
153                                       MemTxAttrs attrs)
154 {
155     MemoryRegion *mr = opaque;
156 
157     if (attrs.secure) {
158         /* S accesses to the alias act like NS accesses to the real region */
159         attrs.secure = 0;
160         return memory_region_dispatch_read(mr, addr, data,
161                                            size_memop(size) | MO_TE, attrs);
162     } else {
163         /* NS attrs are RAZ/WI for privileged, and BusFault for user */
164         if (attrs.user) {
165             return MEMTX_ERROR;
166         }
167         *data = 0;
168         return MEMTX_OK;
169     }
170 }
171 
172 static const MemoryRegionOps v7m_sysreg_ns_ops = {
173     .read_with_attrs = v7m_sysreg_ns_read,
174     .write_with_attrs = v7m_sysreg_ns_write,
175     .endianness = DEVICE_NATIVE_ENDIAN,
176 };
177 
178 static MemTxResult v7m_systick_write(void *opaque, hwaddr addr,
179                                      uint64_t value, unsigned size,
180                                      MemTxAttrs attrs)
181 {
182     ARMv7MState *s = opaque;
183     MemoryRegion *mr;
184 
185     /* Direct the access to the correct systick */
186     mr = sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->systick[attrs.secure]), 0);
187     return memory_region_dispatch_write(mr, addr, value,
188                                         size_memop(size) | MO_TE, attrs);
189 }
190 
191 static MemTxResult v7m_systick_read(void *opaque, hwaddr addr,
192                                     uint64_t *data, unsigned size,
193                                     MemTxAttrs attrs)
194 {
195     ARMv7MState *s = opaque;
196     MemoryRegion *mr;
197 
198     /* Direct the access to the correct systick */
199     mr = sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->systick[attrs.secure]), 0);
200     return memory_region_dispatch_read(mr, addr, data, size_memop(size) | MO_TE,
201                                        attrs);
202 }
203 
204 static const MemoryRegionOps v7m_systick_ops = {
205     .read_with_attrs = v7m_systick_read,
206     .write_with_attrs = v7m_systick_write,
207     .endianness = DEVICE_NATIVE_ENDIAN,
208 };
209 
210 /*
211  * Unassigned portions of the PPB space are RAZ/WI for privileged
212  * accesses, and fault for non-privileged accesses.
213  */
214 static MemTxResult ppb_default_read(void *opaque, hwaddr addr,
215                                     uint64_t *data, unsigned size,
216                                     MemTxAttrs attrs)
217 {
218     qemu_log_mask(LOG_UNIMP, "Read of unassigned area of PPB: offset 0x%x\n",
219                   (uint32_t)addr);
220     if (attrs.user) {
221         return MEMTX_ERROR;
222     }
223     *data = 0;
224     return MEMTX_OK;
225 }
226 
227 static MemTxResult ppb_default_write(void *opaque, hwaddr addr,
228                                      uint64_t value, unsigned size,
229                                      MemTxAttrs attrs)
230 {
231     qemu_log_mask(LOG_UNIMP, "Write of unassigned area of PPB: offset 0x%x\n",
232                   (uint32_t)addr);
233     if (attrs.user) {
234         return MEMTX_ERROR;
235     }
236     return MEMTX_OK;
237 }
238 
239 static const MemoryRegionOps ppb_default_ops = {
240     .read_with_attrs = ppb_default_read,
241     .write_with_attrs = ppb_default_write,
242     .endianness = DEVICE_NATIVE_ENDIAN,
243     .valid.min_access_size = 1,
244     .valid.max_access_size = 8,
245 };
246 
247 static void armv7m_instance_init(Object *obj)
248 {
249     ARMv7MState *s = ARMV7M(obj);
250     int i;
251 
252     /* Can't init the cpu here, we don't yet know which model to use */
253 
254     memory_region_init(&s->container, obj, "armv7m-container", UINT64_MAX);
255 
256     object_initialize_child(obj, "nvic", &s->nvic, TYPE_NVIC);
257     object_property_add_alias(obj, "num-irq",
258                               OBJECT(&s->nvic), "num-irq");
259     object_property_add_alias(obj, "num-prio-bits",
260                               OBJECT(&s->nvic), "num-prio-bits");
261 
262     object_initialize_child(obj, "systick-reg-ns", &s->systick[M_REG_NS],
263                             TYPE_SYSTICK);
264     /*
265      * We can't initialize the secure systick here, as we don't know
266      * yet if we need it.
267      */
268 
269     for (i = 0; i < ARRAY_SIZE(s->bitband); i++) {
270         object_initialize_child(obj, "bitband[*]", &s->bitband[i],
271                                 TYPE_BITBAND);
272     }
273 
274     s->refclk = qdev_init_clock_in(DEVICE(obj), "refclk", NULL, NULL, 0);
275     s->cpuclk = qdev_init_clock_in(DEVICE(obj), "cpuclk", NULL, NULL, 0);
276 }
277 
278 static void armv7m_realize(DeviceState *dev, Error **errp)
279 {
280     ARMv7MState *s = ARMV7M(dev);
281     SysBusDevice *sbd;
282     Error *err = NULL;
283     int i;
284 
285     if (!s->board_memory) {
286         error_setg(errp, "memory property was not set");
287         return;
288     }
289 
290     /* cpuclk must be connected; refclk is optional */
291     if (!clock_has_source(s->cpuclk)) {
292         error_setg(errp, "armv7m: cpuclk must be connected");
293         return;
294     }
295 
296     memory_region_add_subregion_overlap(&s->container, 0, s->board_memory, -1);
297 
298     s->cpu = ARM_CPU(object_new_with_props(s->cpu_type, OBJECT(s), "cpu",
299                                            &err, NULL));
300     if (err != NULL) {
301         error_propagate(errp, err);
302         return;
303     }
304 
305     object_property_set_link(OBJECT(s->cpu), "memory", OBJECT(&s->container),
306                              &error_abort);
307     if (object_property_find(OBJECT(s->cpu), "idau")) {
308         object_property_set_link(OBJECT(s->cpu), "idau", s->idau,
309                                  &error_abort);
310     }
311     if (object_property_find(OBJECT(s->cpu), "init-svtor")) {
312         if (!object_property_set_uint(OBJECT(s->cpu), "init-svtor",
313                                       s->init_svtor, errp)) {
314             return;
315         }
316     }
317     if (object_property_find(OBJECT(s->cpu), "init-nsvtor")) {
318         if (!object_property_set_uint(OBJECT(s->cpu), "init-nsvtor",
319                                       s->init_nsvtor, errp)) {
320             return;
321         }
322     }
323     if (object_property_find(OBJECT(s->cpu), "vfp")) {
324         if (!object_property_set_bool(OBJECT(s->cpu), "vfp", s->vfp, errp)) {
325             return;
326         }
327     }
328     if (object_property_find(OBJECT(s->cpu), "dsp")) {
329         if (!object_property_set_bool(OBJECT(s->cpu), "dsp", s->dsp, errp)) {
330             return;
331         }
332     }
333     object_property_set_bool(OBJECT(s->cpu), "start-powered-off",
334                              s->start_powered_off, &error_abort);
335 
336     /*
337      * Real M-profile hardware can be configured with a different number of
338      * MPU regions for Secure vs NonSecure. QEMU's CPU implementation doesn't
339      * support that yet, so catch attempts to select that.
340      */
341     if (arm_feature(&s->cpu->env, ARM_FEATURE_M_SECURITY) &&
342         s->mpu_ns_regions != s->mpu_s_regions) {
343         error_setg(errp,
344                    "mpu-ns-regions and mpu-s-regions properties must have the same value");
345         return;
346     }
347     if (s->mpu_ns_regions != UINT_MAX &&
348         object_property_find(OBJECT(s->cpu), "pmsav7-dregion")) {
349         if (!object_property_set_uint(OBJECT(s->cpu), "pmsav7-dregion",
350                                       s->mpu_ns_regions, errp)) {
351             return;
352         }
353     }
354 
355     /*
356      * Tell the CPU where the NVIC is; it will fail realize if it doesn't
357      * have one. Similarly, tell the NVIC where its CPU is.
358      */
359     s->cpu->env.nvic = &s->nvic;
360     s->nvic.cpu = s->cpu;
361 
362     if (!qdev_realize(DEVICE(s->cpu), NULL, errp)) {
363         return;
364     }
365 
366     /* Note that we must realize the NVIC after the CPU */
367     if (!sysbus_realize(SYS_BUS_DEVICE(&s->nvic), errp)) {
368         return;
369     }
370 
371     /* Alias the NVIC's input and output GPIOs as our own so the board
372      * code can wire them up. (We do this in realize because the
373      * NVIC doesn't create the input GPIO array until realize.)
374      */
375     qdev_pass_gpios(DEVICE(&s->nvic), dev, NULL);
376     qdev_pass_gpios(DEVICE(&s->nvic), dev, "SYSRESETREQ");
377     qdev_pass_gpios(DEVICE(&s->nvic), dev, "NMI");
378 
379     /*
380      * We map various devices into the container MR at their architected
381      * addresses. In particular, we map everything corresponding to the
382      * "System PPB" space. This is the range from 0xe0000000 to 0xe00fffff
383      * and includes the NVIC, the System Control Space (system registers),
384      * the systick timer, and for CPUs with the Security extension an NS
385      * banked version of all of these.
386      *
387      * The default behaviour for unimplemented registers/ranges
388      * (for instance the Data Watchpoint and Trace unit at 0xe0001000)
389      * is to RAZ/WI for privileged access and BusFault for non-privileged
390      * access.
391      *
392      * The NVIC and System Control Space (SCS) starts at 0xe000e000
393      * and looks like this:
394      *  0x004 - ICTR
395      *  0x010 - 0xff - systick
396      *  0x100..0x7ec - NVIC
397      *  0x7f0..0xcff - Reserved
398      *  0xd00..0xd3c - SCS registers
399      *  0xd40..0xeff - Reserved or Not implemented
400      *  0xf00 - STIR
401      *
402      * Some registers within this space are banked between security states.
403      * In v8M there is a second range 0xe002e000..0xe002efff which is the
404      * NonSecure alias SCS; secure accesses to this behave like NS accesses
405      * to the main SCS range, and non-secure accesses (including when
406      * the security extension is not implemented) are RAZ/WI.
407      * Note that both the main SCS range and the alias range are defined
408      * to be exempt from memory attribution (R_BLJT) and so the memory
409      * transaction attribute always matches the current CPU security
410      * state (attrs.secure == env->v7m.secure). In the v7m_sysreg_ns_ops
411      * wrappers we change attrs.secure to indicate the NS access; so
412      * generally code determining which banked register to use should
413      * use attrs.secure; code determining actual behaviour of the system
414      * should use env->v7m.secure.
415      *
416      * Within the PPB space, some MRs overlap, and the priority
417      * of overlapping regions is:
418      *  - default region (for RAZ/WI and BusFault) : -1
419      *  - system register regions (provided by the NVIC) : 0
420      *  - systick : 1
421      * This is because the systick device is a small block of registers
422      * in the middle of the other system control registers.
423      */
424 
425     memory_region_init_io(&s->defaultmem, OBJECT(s), &ppb_default_ops, s,
426                           "nvic-default", 0x100000);
427     memory_region_add_subregion_overlap(&s->container, 0xe0000000,
428                                         &s->defaultmem, -1);
429 
430     /* Wire the NVIC up to the CPU */
431     sbd = SYS_BUS_DEVICE(&s->nvic);
432     sysbus_connect_irq(sbd, 0,
433                        qdev_get_gpio_in(DEVICE(s->cpu), ARM_CPU_IRQ));
434 
435     memory_region_add_subregion(&s->container, 0xe000e000,
436                                 sysbus_mmio_get_region(sbd, 0));
437     if (arm_feature(&s->cpu->env, ARM_FEATURE_V8)) {
438         /* Create the NS alias region for the NVIC sysregs */
439         memory_region_init_io(&s->sysreg_ns_mem, OBJECT(s),
440                               &v7m_sysreg_ns_ops,
441                               sysbus_mmio_get_region(sbd, 0),
442                               "nvic_sysregs_ns", 0x1000);
443         memory_region_add_subregion(&s->container, 0xe002e000,
444                                     &s->sysreg_ns_mem);
445     }
446 
447     /*
448      * Create and map the systick devices. Note that we only connect
449      * refclk if it has been connected to us; otherwise the systick
450      * device gets the wrong answer for clock_has_source(refclk), because
451      * it has an immediate source (the ARMv7M's clock object) but not
452      * an ultimate source, and then it won't correctly auto-select the
453      * CPU clock as its only possible clock source.
454      */
455     if (clock_has_source(s->refclk)) {
456         qdev_connect_clock_in(DEVICE(&s->systick[M_REG_NS]), "refclk",
457                               s->refclk);
458     }
459     qdev_connect_clock_in(DEVICE(&s->systick[M_REG_NS]), "cpuclk", s->cpuclk);
460     if (!sysbus_realize(SYS_BUS_DEVICE(&s->systick[M_REG_NS]), errp)) {
461         return;
462     }
463     sysbus_connect_irq(SYS_BUS_DEVICE(&s->systick[M_REG_NS]), 0,
464                        qdev_get_gpio_in_named(DEVICE(&s->nvic),
465                                               "systick-trigger", M_REG_NS));
466 
467     if (arm_feature(&s->cpu->env, ARM_FEATURE_M_SECURITY)) {
468         /*
469          * We couldn't init the secure systick device in instance_init
470          * as we didn't know then if the CPU had the security extensions;
471          * so we have to do it here.
472          */
473         object_initialize_child(OBJECT(dev), "systick-reg-s",
474                                 &s->systick[M_REG_S], TYPE_SYSTICK);
475         if (clock_has_source(s->refclk)) {
476             qdev_connect_clock_in(DEVICE(&s->systick[M_REG_S]), "refclk",
477                                   s->refclk);
478         }
479         qdev_connect_clock_in(DEVICE(&s->systick[M_REG_S]), "cpuclk",
480                               s->cpuclk);
481 
482         if (!sysbus_realize(SYS_BUS_DEVICE(&s->systick[M_REG_S]), errp)) {
483             return;
484         }
485         sysbus_connect_irq(SYS_BUS_DEVICE(&s->systick[M_REG_S]), 0,
486                            qdev_get_gpio_in_named(DEVICE(&s->nvic),
487                                                   "systick-trigger", M_REG_S));
488     }
489 
490     memory_region_init_io(&s->systickmem, OBJECT(s),
491                           &v7m_systick_ops, s,
492                           "v7m_systick", 0xe0);
493 
494     memory_region_add_subregion_overlap(&s->container, 0xe000e010,
495                                         &s->systickmem, 1);
496     if (arm_feature(&s->cpu->env, ARM_FEATURE_V8)) {
497         memory_region_init_io(&s->systick_ns_mem, OBJECT(s),
498                               &v7m_sysreg_ns_ops, &s->systickmem,
499                               "v7m_systick_ns", 0xe0);
500         memory_region_add_subregion_overlap(&s->container, 0xe002e010,
501                                             &s->systick_ns_mem, 1);
502     }
503 
504     /* If the CPU has RAS support, create the RAS register block */
505     if (cpu_isar_feature(aa32_ras, s->cpu)) {
506         object_initialize_child(OBJECT(dev), "armv7m-ras",
507                                 &s->ras, TYPE_ARMV7M_RAS);
508         sbd = SYS_BUS_DEVICE(&s->ras);
509         if (!sysbus_realize(sbd, errp)) {
510             return;
511         }
512         memory_region_add_subregion_overlap(&s->container, 0xe0005000,
513                                             sysbus_mmio_get_region(sbd, 0), 1);
514     }
515 
516     for (i = 0; i < ARRAY_SIZE(s->bitband); i++) {
517         if (s->enable_bitband) {
518             Object *obj = OBJECT(&s->bitband[i]);
519             sbd = SYS_BUS_DEVICE(&s->bitband[i]);
520 
521             if (!object_property_set_int(obj, "base",
522                                          bitband_input_addr[i], errp)) {
523                 return;
524             }
525             object_property_set_link(obj, "source-memory",
526                                      OBJECT(s->board_memory), &error_abort);
527             if (!sysbus_realize(SYS_BUS_DEVICE(obj), errp)) {
528                 return;
529             }
530 
531             memory_region_add_subregion(&s->container, bitband_output_addr[i],
532                                         sysbus_mmio_get_region(sbd, 0));
533         } else {
534             object_unparent(OBJECT(&s->bitband[i]));
535         }
536     }
537 }
538 
539 static Property armv7m_properties[] = {
540     DEFINE_PROP_STRING("cpu-type", ARMv7MState, cpu_type),
541     DEFINE_PROP_LINK("memory", ARMv7MState, board_memory, TYPE_MEMORY_REGION,
542                      MemoryRegion *),
543     DEFINE_PROP_LINK("idau", ARMv7MState, idau, TYPE_IDAU_INTERFACE, Object *),
544     DEFINE_PROP_UINT32("init-svtor", ARMv7MState, init_svtor, 0),
545     DEFINE_PROP_UINT32("init-nsvtor", ARMv7MState, init_nsvtor, 0),
546     DEFINE_PROP_BOOL("enable-bitband", ARMv7MState, enable_bitband, false),
547     DEFINE_PROP_BOOL("start-powered-off", ARMv7MState, start_powered_off,
548                      false),
549     DEFINE_PROP_BOOL("vfp", ARMv7MState, vfp, true),
550     DEFINE_PROP_BOOL("dsp", ARMv7MState, dsp, true),
551     DEFINE_PROP_UINT32("mpu-ns-regions", ARMv7MState, mpu_ns_regions, UINT_MAX),
552     DEFINE_PROP_UINT32("mpu-s-regions", ARMv7MState, mpu_s_regions, UINT_MAX),
553     DEFINE_PROP_END_OF_LIST(),
554 };
555 
556 static const VMStateDescription vmstate_armv7m = {
557     .name = "armv7m",
558     .version_id = 1,
559     .minimum_version_id = 1,
560     .fields = (const VMStateField[]) {
561         VMSTATE_CLOCK(refclk, ARMv7MState),
562         VMSTATE_CLOCK(cpuclk, ARMv7MState),
563         VMSTATE_END_OF_LIST()
564     }
565 };
566 
567 static void armv7m_class_init(ObjectClass *klass, void *data)
568 {
569     DeviceClass *dc = DEVICE_CLASS(klass);
570 
571     dc->realize = armv7m_realize;
572     dc->vmsd = &vmstate_armv7m;
573     device_class_set_props(dc, armv7m_properties);
574 }
575 
576 static const TypeInfo armv7m_info = {
577     .name = TYPE_ARMV7M,
578     .parent = TYPE_SYS_BUS_DEVICE,
579     .instance_size = sizeof(ARMv7MState),
580     .instance_init = armv7m_instance_init,
581     .class_init = armv7m_class_init,
582 };
583 
584 static void armv7m_reset(void *opaque)
585 {
586     ARMCPU *cpu = opaque;
587 
588     cpu_reset(CPU(cpu));
589 }
590 
591 void armv7m_load_kernel(ARMCPU *cpu, const char *kernel_filename,
592                         hwaddr mem_base, int mem_size)
593 {
594     ssize_t image_size;
595     uint64_t entry;
596     AddressSpace *as;
597     int asidx;
598     CPUState *cs = CPU(cpu);
599 
600     if (arm_feature(&cpu->env, ARM_FEATURE_EL3)) {
601         asidx = ARMASIdx_S;
602     } else {
603         asidx = ARMASIdx_NS;
604     }
605     as = cpu_get_address_space(cs, asidx);
606 
607     if (kernel_filename) {
608         image_size = load_elf_as(kernel_filename, NULL, NULL, NULL,
609                                  &entry, NULL, NULL,
610                                  NULL, 0, EM_ARM, 1, 0, as);
611         if (image_size < 0) {
612             image_size = load_image_targphys_as(kernel_filename, mem_base,
613                                                 mem_size, as);
614         }
615         if (image_size < 0) {
616             error_report("Could not load kernel '%s'", kernel_filename);
617             exit(1);
618         }
619     }
620 
621     /* CPU objects (unlike devices) are not automatically reset on system
622      * reset, so we must always register a handler to do so. Unlike
623      * A-profile CPUs, we don't need to do anything special in the
624      * handler to arrange that it starts correctly.
625      * This is arguably the wrong place to do this, but it matches the
626      * way A-profile does it. Note that this means that every M profile
627      * board must call this function!
628      */
629     qemu_register_reset(armv7m_reset, cpu);
630 }
631 
632 static Property bitband_properties[] = {
633     DEFINE_PROP_UINT32("base", BitBandState, base, 0),
634     DEFINE_PROP_LINK("source-memory", BitBandState, source_memory,
635                      TYPE_MEMORY_REGION, MemoryRegion *),
636     DEFINE_PROP_END_OF_LIST(),
637 };
638 
639 static void bitband_class_init(ObjectClass *klass, void *data)
640 {
641     DeviceClass *dc = DEVICE_CLASS(klass);
642 
643     dc->realize = bitband_realize;
644     device_class_set_props(dc, bitband_properties);
645 }
646 
647 static const TypeInfo bitband_info = {
648     .name          = TYPE_BITBAND,
649     .parent        = TYPE_SYS_BUS_DEVICE,
650     .instance_size = sizeof(BitBandState),
651     .instance_init = bitband_init,
652     .class_init    = bitband_class_init,
653 };
654 
655 static void armv7m_register_types(void)
656 {
657     type_register_static(&bitband_info);
658     type_register_static(&armv7m_info);
659 }
660 
661 type_init(armv7m_register_types)
662