xref: /openbmc/qemu/target/avr/machine.c (revision 2df1eb27)
1 /*
2  * QEMU AVR CPU
3  *
4  * Copyright (c) 2016-2020 Michael Rolnik
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, see
18  * <http://www.gnu.org/licenses/lgpl-2.1.html>
19  */
20 
21 #include "qemu/osdep.h"
22 #include "cpu.h"
23 #include "migration/cpu.h"
24 
25 static int get_sreg(QEMUFile *f, void *opaque, size_t size,
26                     const VMStateField *field)
27 {
28     CPUAVRState *env = opaque;
29     uint8_t sreg;
30 
31     sreg = qemu_get_byte(f);
32     cpu_set_sreg(env, sreg);
33     return 0;
34 }
35 
36 static int put_sreg(QEMUFile *f, void *opaque, size_t size,
37                     const VMStateField *field, JSONWriter *vmdesc)
38 {
39     CPUAVRState *env = opaque;
40     uint8_t sreg = cpu_get_sreg(env);
41 
42     qemu_put_byte(f, sreg);
43     return 0;
44 }
45 
46 static const VMStateInfo vms_sreg = {
47     .name = "sreg",
48     .get = get_sreg,
49     .put = put_sreg,
50 };
51 
52 static int get_segment(QEMUFile *f, void *opaque, size_t size,
53                        const VMStateField *field)
54 {
55     uint32_t *ramp = opaque;
56     uint8_t temp;
57 
58     temp = qemu_get_byte(f);
59     *ramp = ((uint32_t)temp) << 16;
60     return 0;
61 }
62 
63 static int put_segment(QEMUFile *f, void *opaque, size_t size,
64                        const VMStateField *field, JSONWriter *vmdesc)
65 {
66     uint32_t *ramp = opaque;
67     uint8_t temp = *ramp >> 16;
68 
69     qemu_put_byte(f, temp);
70     return 0;
71 }
72 
73 static const VMStateInfo vms_rampD = {
74     .name = "rampD",
75     .get = get_segment,
76     .put = put_segment,
77 };
78 static const VMStateInfo vms_rampX = {
79     .name = "rampX",
80     .get = get_segment,
81     .put = put_segment,
82 };
83 static const VMStateInfo vms_rampY = {
84     .name = "rampY",
85     .get = get_segment,
86     .put = put_segment,
87 };
88 static const VMStateInfo vms_rampZ = {
89     .name = "rampZ",
90     .get = get_segment,
91     .put = put_segment,
92 };
93 static const VMStateInfo vms_eind = {
94     .name = "eind",
95     .get = get_segment,
96     .put = put_segment,
97 };
98 
99 const VMStateDescription vms_avr_cpu = {
100     .name = "cpu",
101     .version_id = 1,
102     .minimum_version_id = 1,
103     .fields = (const VMStateField[]) {
104         VMSTATE_UINT32(env.pc_w, AVRCPU),
105         VMSTATE_UINT32(env.sp, AVRCPU),
106         VMSTATE_UINT32(env.skip, AVRCPU),
107 
108         VMSTATE_UINT32_ARRAY(env.r, AVRCPU, NUMBER_OF_CPU_REGISTERS),
109 
110         VMSTATE_SINGLE(env, AVRCPU, 0, vms_sreg, CPUAVRState),
111         VMSTATE_SINGLE(env.rampD, AVRCPU, 0, vms_rampD, uint32_t),
112         VMSTATE_SINGLE(env.rampX, AVRCPU, 0, vms_rampX, uint32_t),
113         VMSTATE_SINGLE(env.rampY, AVRCPU, 0, vms_rampY, uint32_t),
114         VMSTATE_SINGLE(env.rampZ, AVRCPU, 0, vms_rampZ, uint32_t),
115         VMSTATE_SINGLE(env.eind, AVRCPU, 0, vms_eind, uint32_t),
116 
117         VMSTATE_END_OF_LIST()
118     }
119 };
120