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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
/*
* Save/restore CPU state macros
*
* Copyright (C) 2016 Mark Cave-Ayland (mark.cave-ayland@ilande.co.uk>)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 2
*
*/
#include "autoconf.h"
#define STACKFRAME_SZ 0x60
/* These are just handy. */
#define _SV save %sp, -STACKFRAME_SZ, %sp
#define _RS restore
#define FLUSH_ALL_KERNEL_WINDOWS \
_SV; _SV; _SV; _SV; _SV; _SV; _SV; \
_RS; _RS; _RS; _RS; _RS; _RS; _RS;
#define SAVE_CPU_GENERAL_STATE(type) \
/* Save general state into context at %g1 */ \
rd %psr, %g4; \
st %g4, [%g1]; \
rd %wim, %g4; \
st %g4, [%g1 + 0x4];
#define SAVE_CPU_WINDOW_STATE(type) \
/* Save window state into context at %g1 */ \
st %o0, [%g1 + 0x30]; \
st %o1, [%g1 + 0x34]; \
st %o2, [%g1 + 0x38]; \
st %o3, [%g1 + 0x3c]; \
st %o4, [%g1 + 0x40]; \
st %o5, [%g1 + 0x44]; \
st %o6, [%g1 + 0x48]; \
st %o7, [%g1 + 0x4c]; \
\
set nwindows, %g6; \
ld [%g6], %g6; /* nwindows */ \
mov %g6, %g5; \
sub %g5, 1, %g5; /* mask */ \
\
rd %psr, %g4; \
and %g4, %g5, %g4; /* window */ \
\
rd %psr, %g3; \
srl %g3, 5, %g3; \
sll %g3, 5, %g3; /* psr hi */ \
\
mov %g1, %g2; \
add %g2, 0x50, %g2; \
\
save_cpu_window_##type: \
mov %g3, %g7; \
or %g7, %g4, %g7; \
wr %g7, %psr; \
\
st %l0, [%g2]; \
st %l1, [%g2 + 0x4]; \
st %l2, [%g2 + 0x8]; \
st %l3, [%g2 + 0xc]; \
st %l4, [%g2 + 0x10]; \
st %l5, [%g2 + 0x14]; \
st %l6, [%g2 + 0x18]; \
st %l7, [%g2 + 0x1c]; \
st %i0, [%g2 + 0x20]; \
st %i1, [%g2 + 0x24]; \
st %i2, [%g2 + 0x28]; \
st %i3, [%g2 + 0x2c]; \
st %i4, [%g2 + 0x30]; \
st %i5, [%g2 + 0x34]; \
st %i6, [%g2 + 0x38]; \
st %i7, [%g2 + 0x3c]; \
dec %g4; \
and %g4, %g5, %g4; \
subcc %g6, 1, %g6; \
bne save_cpu_window_##type; \
add %g2, 0x40, %g2; \
\
/* Get back to the correct window */ \
ld [%g1], %g2; \
wr %g2, %psr;
#define SAVE_CPU_STATE(type) \
SAVE_CPU_GENERAL_STATE(type); \
SAVE_CPU_WINDOW_STATE(type);
#define RESTORE_CPU_GENERAL_STATE(type) \
/* Restore window state from context at %g1 */ \
ld [%g1], %g2; \
wr %g2, %psr; \
ld [%g1 + 0x4], %g2; \
wr %g2, %wim;
#define RESTORE_CPU_WINDOW_STATE(type) \
/* Restore window state from context at %g1 */ \
set nwindows, %g6; \
ld [%g6], %g6; /* nwindows */ \
mov %g6, %g5; \
sub %g5, 1, %g5; /* mask */ \
\
rd %psr, %g4; \
and %g4, %g5, %g4; /* window */ \
\
rd %psr, %g3; \
srl %g3, 5, %g3; \
sll %g3, 5, %g3; /* psr hi */ \
\
mov %g1, %g2; \
add %g2, 0x50, %g2; \
\
restore_cpu_window_##type: \
mov %g3, %g7; \
or %g7, %g4, %g7; \
wr %g7, %psr; \
\
ld [%g2], %l0; \
ld [%g2 + 0x4], %l1; \
ld [%g2 + 0x8], %l2; \
ld [%g2 + 0xc], %l3; \
ld [%g2 + 0x10], %l4; \
ld [%g2 + 0x14], %l5; \
ld [%g2 + 0x18], %l6; \
ld [%g2 + 0x1c], %l7; \
ld [%g2 + 0x20], %i0; \
ld [%g2 + 0x24], %i1; \
ld [%g2 + 0x28], %i2; \
ld [%g2 + 0x2c], %i3; \
ld [%g2 + 0x30], %i4; \
ld [%g2 + 0x34], %i5; \
ld [%g2 + 0x38], %i6; \
ld [%g2 + 0x3c], %i7; \
dec %g4; \
and %g4, %g5, %g4; \
subcc %g6, 1, %g6; \
bne restore_cpu_window_##type; \
add %g2, 0x40, %g2; \
\
/* Get back to the correct window */ \
ld [%g1], %g2; \
wr %g2, %psr; \
\
ld [%g1 + 0x30], %o0; \
ld [%g1 + 0x34], %o1; \
ld [%g1 + 0x38], %o2; \
ld [%g1 + 0x3c], %o3; \
ld [%g1 + 0x40], %o4; \
ld [%g1 + 0x44], %o5; \
ld [%g1 + 0x48], %o6; \
ld [%g1 + 0x4c], %o7;
#define RESTORE_CPU_STATE(type) \
RESTORE_CPU_GENERAL_STATE(type); \
RESTORE_CPU_WINDOW_STATE(type);
|