master
c 120 lines 3.19 KB
Raw
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/qemu-file-types.h"
24 #include "migration/vmstate.h"
25
26 static int get_sreg(QEMUFile *f, void *opaque, size_t size,
27 const VMStateField *field)
28 {
29 CPUAVRState *env = opaque;
30 uint8_t sreg;
31
32 sreg = qemu_get_byte(f);
33 cpu_set_sreg(env, sreg);
34 return 0;
35 }
36
37 static int put_sreg(QEMUFile *f, void *opaque, size_t size,
38 const VMStateField *field, JSONWriter *vmdesc)
39 {
40 CPUAVRState *env = opaque;
41 uint8_t sreg = cpu_get_sreg(env);
42
43 qemu_put_byte(f, sreg);
44 return 0;
45 }
46
47 static const VMStateInfo vms_sreg = {
48 .name = "sreg",
49 .get = get_sreg,
50 .put = put_sreg,
51 };
52
53 static int get_segment(QEMUFile *f, void *opaque, size_t size,
54 const VMStateField *field)
55 {
56 uint32_t *ramp = opaque;
57 uint8_t temp;
58
59 temp = qemu_get_byte(f);
60 *ramp = ((uint32_t)temp) << 16;
61 return 0;
62 }
63
64 static int put_segment(QEMUFile *f, void *opaque, size_t size,
65 const VMStateField *field, JSONWriter *vmdesc)
66 {
67 uint32_t *ramp = opaque;
68 uint8_t temp = *ramp >> 16;
69
70 qemu_put_byte(f, temp);
71 return 0;
72 }
73
74 static const VMStateInfo vms_rampD = {
75 .name = "rampD",
76 .get = get_segment,
77 .put = put_segment,
78 };
79 static const VMStateInfo vms_rampX = {
80 .name = "rampX",
81 .get = get_segment,
82 .put = put_segment,
83 };
84 static const VMStateInfo vms_rampY = {
85 .name = "rampY",
86 .get = get_segment,
87 .put = put_segment,
88 };
89 static const VMStateInfo vms_rampZ = {
90 .name = "rampZ",
91 .get = get_segment,
92 .put = put_segment,
93 };
94 static const VMStateInfo vms_eind = {
95 .name = "eind",
96 .get = get_segment,
97 .put = put_segment,
98 };
99
100 const VMStateDescription vms_avr_cpu = {
101 .name = "cpu",
102 .version_id = 1,
103 .minimum_version_id = 1,
104 .fields = (const VMStateField[]) {
105 VMSTATE_UINT32(env.pc_w, AVRCPU),
106 VMSTATE_UINT32(env.sp, AVRCPU),
107 VMSTATE_UINT32(env.skip, AVRCPU),
108
109 VMSTATE_UINT32_ARRAY(env.r, AVRCPU, NUMBER_OF_CPU_REGISTERS),
110
111 VMSTATE_SINGLE(env, AVRCPU, 0, vms_sreg, CPUAVRState),
112 VMSTATE_SINGLE(env.rampD, AVRCPU, 0, vms_rampD, uint32_t),
113 VMSTATE_SINGLE(env.rampX, AVRCPU, 0, vms_rampX, uint32_t),
114 VMSTATE_SINGLE(env.rampY, AVRCPU, 0, vms_rampY, uint32_t),
115 VMSTATE_SINGLE(env.rampZ, AVRCPU, 0, vms_rampZ, uint32_t),
116 VMSTATE_SINGLE(env.eind, AVRCPU, 0, vms_eind, uint32_t),
117
118 VMSTATE_END_OF_LIST()
119 }
120 };