2 * BBC micro:bit machine
3 * http://tech.microbit.org/hardware/
5 * Copyright 2018 Joel Stanley <joel@jms.id.au>
7 * This code is licensed under the GPL version 2 or later. See
8 * the COPYING file in the top-level directory.
11 #include "qemu/osdep.h"
12 #include "qapi/error.h"
13 #include "hw/boards.h"
14 #include "hw/arm/arm.h"
15 #include "sysemu/sysemu.h"
16 #include "exec/address-spaces.h"
18 #include "hw/arm/nrf51_soc.h"
24 } MicrobitMachineState
;
26 #define TYPE_MICROBIT_MACHINE MACHINE_TYPE_NAME("microbit")
28 #define MICROBIT_MACHINE(obj) \
29 OBJECT_CHECK(MicrobitMachineState, obj, TYPE_MICROBIT_MACHINE)
31 static void microbit_init(MachineState
*machine
)
33 MicrobitMachineState
*s
= MICROBIT_MACHINE(machine
);
34 MemoryRegion
*system_memory
= get_system_memory();
35 Object
*soc
= OBJECT(&s
->nrf51
);
37 sysbus_init_child_obj(OBJECT(machine
), "nrf51", soc
, sizeof(s
->nrf51
),
39 qdev_prop_set_chr(DEVICE(&s
->nrf51
), "serial0", serial_hd(0));
40 object_property_set_link(soc
, OBJECT(system_memory
), "memory",
42 object_property_set_bool(soc
, true, "realized", &error_fatal
);
44 armv7m_load_kernel(ARM_CPU(first_cpu
), machine
->kernel_filename
,
45 NRF51_SOC(soc
)->flash_size
);
48 static void microbit_machine_class_init(ObjectClass
*oc
, void *data
)
50 MachineClass
*mc
= MACHINE_CLASS(oc
);
52 mc
->desc
= "BBC micro:bit";
53 mc
->init
= microbit_init
;
57 static const TypeInfo microbit_info
= {
58 .name
= TYPE_MICROBIT_MACHINE
,
59 .parent
= TYPE_MACHINE
,
60 .instance_size
= sizeof(MicrobitMachineState
),
61 .class_init
= microbit_machine_class_init
,
64 static void microbit_machine_init(void)
66 type_register_static(µbit_info
);
69 type_init(microbit_machine_init
);