forked from sysprog21/semu
-
Notifications
You must be signed in to change notification settings - Fork 5
/
persistence.h
53 lines (40 loc) · 1.23 KB
/
persistence.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#pragma once
#include <stdint.h>
#include "riscv.h"
// set value to 0 in deser first to deal with variable sized fields
#define SER(value, N) \
do { \
uint8_t *obuf = *obufp; \
uint8_t *v = (uint8_t*)&(value); \
for (int i=0; i < (N); i++) \
*obuf++ = v[i]; \
*obufp+=(N); \
} while(0); \
#define DESER(value, N) \
do { \
(value)=0; \
uint8_t *ibuf = *ibufp; \
uint8_t *v = (uint8_t*)(&(value)); \
for (int i=0; i < (N); i++) \
v[i] = *ibuf++; \
*ibufp+=(N); \
} while(0); \
#define SER8(value) SER(value, 1)
#define SER32(value) SER(value, 4)
#define DESER8(value) DESER(value, 1)
#define DESER32(value) DESER(value, 4)
extern void save_cpu(const vm_t *vm,
uint8_t **obufp);
extern void save_plic(const vm_t *vm,
uint8_t **obufp);
extern void save_uart(const vm_t *vm,
uint8_t **obufp);
extern void save_all(const vm_t *vm, uint8_t **obufp);
extern void load_cpu(vm_t *vm,
uint8_t **ibufp);
extern void load_plic(vm_t *vm,
uint8_t **ibufp);
extern void load_uart(vm_t *vm,
uint8_t **ibufp);
extern bool load_all(vm_t *vm, uint8_t **ibufp);
#define PERSISTENCE_BASEADR 0xfff000