Merge tag 'pull-loongarch-20241016' of https://gitlab.com/gaosong/qemu into staging
[qemu/armbru.git] / target / avr / machine.c
blob4402862fb962d9384a79f9e6792727dc1e12bc33
1 /*
2 * QEMU AVR CPU
4 * Copyright (c) 2016-2020 Michael Rolnik
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.
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.
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>
21 #include "qemu/osdep.h"
22 #include "cpu.h"
23 #include "migration/cpu.h"
25 static int get_sreg(QEMUFile *f, void *opaque, size_t size,
26 const VMStateField *field)
28 CPUAVRState *env = opaque;
29 uint8_t sreg;
31 sreg = qemu_get_byte(f);
32 cpu_set_sreg(env, sreg);
33 return 0;
36 static int put_sreg(QEMUFile *f, void *opaque, size_t size,
37 const VMStateField *field, JSONWriter *vmdesc)
39 CPUAVRState *env = opaque;
40 uint8_t sreg = cpu_get_sreg(env);
42 qemu_put_byte(f, sreg);
43 return 0;
46 static const VMStateInfo vms_sreg = {
47 .name = "sreg",
48 .get = get_sreg,
49 .put = put_sreg,
52 static int get_segment(QEMUFile *f, void *opaque, size_t size,
53 const VMStateField *field)
55 uint32_t *ramp = opaque;
56 uint8_t temp;
58 temp = qemu_get_byte(f);
59 *ramp = ((uint32_t)temp) << 16;
60 return 0;
63 static int put_segment(QEMUFile *f, void *opaque, size_t size,
64 const VMStateField *field, JSONWriter *vmdesc)
66 uint32_t *ramp = opaque;
67 uint8_t temp = *ramp >> 16;
69 qemu_put_byte(f, temp);
70 return 0;
73 static const VMStateInfo vms_rampD = {
74 .name = "rampD",
75 .get = get_segment,
76 .put = put_segment,
78 static const VMStateInfo vms_rampX = {
79 .name = "rampX",
80 .get = get_segment,
81 .put = put_segment,
83 static const VMStateInfo vms_rampY = {
84 .name = "rampY",
85 .get = get_segment,
86 .put = put_segment,
88 static const VMStateInfo vms_rampZ = {
89 .name = "rampZ",
90 .get = get_segment,
91 .put = put_segment,
93 static const VMStateInfo vms_eind = {
94 .name = "eind",
95 .get = get_segment,
96 .put = put_segment,
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),
108 VMSTATE_UINT32_ARRAY(env.r, AVRCPU, NUMBER_OF_CPU_REGISTERS),
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),
117 VMSTATE_END_OF_LIST()