Skip to content

Commit 772e34b

Browse files
committed
Add VFP saving and restore
1 parent 75dd774 commit 772e34b

File tree

1 file changed

+84
-9
lines changed

1 file changed

+84
-9
lines changed

libco/mips.c

Lines changed: 84 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@
1919
extern "C" {
2020
#endif
2121

22-
static thread_local uint64_t co_active_buffer[64];
23-
static thread_local cothread_t co_active_handle;
24-
2522
#if __mips >= 3
2623
/* If we have 64-bit registers. */
2724
#define STORE_REG "sd"
@@ -32,12 +29,22 @@ static thread_local cothread_t co_active_handle;
3229
#define STORE_REG "sw"
3330
#define LOAD_REG "lw"
3431
#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
35-
#define REG_TRANSFORM(x) (((uint64_t)(x)) << 64)
32+
#define REG_TRANSFORM(x) (((uint64_t)(x)) << 32)
3633
#else
3734
#define REG_TRANSFORM(x) (x)
3835
#endif
3936
#endif
4037
#define HAVE_FP 1
38+
#ifdef __psp__
39+
#define HAVE_VFP 1
40+
#else
41+
#define HAVE_VFP 0
42+
#endif
43+
44+
#define CONTEXT_SIZE 0x300
45+
46+
static thread_local uint64_t co_active_buffer[CONTEXT_SIZE / 8] __attribute__((__aligned__((16))));
47+
static thread_local cothread_t co_active_handle;
4148

4249
__asm__ (
4350
".align 4\n"
@@ -69,6 +76,40 @@ __asm__ (
6976
" swc1 $f28, 0x80($a1)\n"
7077
" swc1 $f29, 0x84($a1)\n"
7178
" swc1 $f30, 0x88($a1)\n"
79+
#endif
80+
#if HAVE_VFP
81+
" sv.q c000, 0x90($a1), wt\n"
82+
" sv.q c010, 0xa0($a1), wt\n"
83+
" sv.q c020, 0xb0($a1), wt\n"
84+
" sv.q c030, 0xc0($a1), wt\n"
85+
" sv.q c100, 0xd0($a1), wt\n"
86+
" sv.q c110, 0xe0($a1), wt\n"
87+
" sv.q c120, 0xf0($a1), wt\n"
88+
" sv.q c130, 0x100($a1), wt\n"
89+
" sv.q c200, 0x110($a1), wt\n"
90+
" sv.q c210, 0x120($a1), wt\n"
91+
" sv.q c220, 0x130($a1), wt\n"
92+
" sv.q c230, 0x140($a1), wt\n"
93+
" sv.q c300, 0x150($a1), wt\n"
94+
" sv.q c310, 0x160($a1), wt\n"
95+
" sv.q c320, 0x170($a1), wt\n"
96+
" sv.q c330, 0x180($a1), wt\n"
97+
" sv.q c400, 0x190($a1), wt\n"
98+
" sv.q c410, 0x1a0($a1), wt\n"
99+
" sv.q c420, 0x1b0($a1), wt\n"
100+
" sv.q c430, 0x1c0($a1), wt\n"
101+
" sv.q c500, 0x1d0($a1), wt\n"
102+
" sv.q c510, 0x1e0($a1), wt\n"
103+
" sv.q c520, 0x1f0($a1), wt\n"
104+
" sv.q c530, 0x200($a1), wt\n"
105+
" sv.q c600, 0x210($a1), wt\n"
106+
" sv.q c610, 0x220($a1), wt\n"
107+
" sv.q c620, 0x230($a1), wt\n"
108+
" sv.q c630, 0x240($a1), wt\n"
109+
" sv.q c700, 0x250($a1), wt\n"
110+
" sv.q c710, 0x260($a1), wt\n"
111+
" sv.q c720, 0x270($a1), wt\n"
112+
" sv.q c730, 0x280($a1), wt\n"
72113
#endif
73114
LOAD_REG " $s0, 0($a0)\n"
74115
LOAD_REG " $s1, 8($a0)\n"
@@ -94,6 +135,40 @@ __asm__ (
94135
" lwc1 $f28, 0x80($a0)\n"
95136
" lwc1 $f29, 0x84($a0)\n"
96137
" lwc1 $f30, 0x88($a0)\n"
138+
#endif
139+
#if HAVE_VFP
140+
" lv.q c000, 0x90($a0)\n"
141+
" lv.q c010, 0xa0($a0)\n"
142+
" lv.q c020, 0xb0($a0)\n"
143+
" lv.q c030, 0xc0($a0)\n"
144+
" lv.q c100, 0xd0($a0)\n"
145+
" lv.q c110, 0xe0($a0)\n"
146+
" lv.q c120, 0xf0($a0)\n"
147+
" lv.q c130, 0x100($a0)\n"
148+
" lv.q c200, 0x110($a0)\n"
149+
" lv.q c210, 0x120($a0)\n"
150+
" lv.q c220, 0x130($a0)\n"
151+
" lv.q c230, 0x140($a0)\n"
152+
" lv.q c300, 0x150($a0)\n"
153+
" lv.q c310, 0x160($a0)\n"
154+
" lv.q c320, 0x170($a0)\n"
155+
" lv.q c330, 0x180($a0)\n"
156+
" lv.q c400, 0x190($a0)\n"
157+
" lv.q c410, 0x1a0($a0)\n"
158+
" lv.q c420, 0x1b0($a0)\n"
159+
" lv.q c430, 0x1c0($a0)\n"
160+
" lv.q c500, 0x1d0($a0)\n"
161+
" lv.q c510, 0x1e0($a0)\n"
162+
" lv.q c520, 0x1f0($a0)\n"
163+
" lv.q c530, 0x200($a0)\n"
164+
" lv.q c600, 0x210($a0)\n"
165+
" lv.q c610, 0x220($a0)\n"
166+
" lv.q c620, 0x230($a0)\n"
167+
" lv.q c630, 0x240($a0)\n"
168+
" lv.q c700, 0x250($a0)\n"
169+
" lv.q c710, 0x260($a0)\n"
170+
" lv.q c720, 0x270($a0)\n"
171+
" lv.q c730, 0x280($a0)\n"
97172
#endif
98173
" jr $ra\n"
99174
" nop\n"
@@ -113,24 +188,24 @@ void store_gp(uint64_t *s);
113188

114189
cothread_t co_create(unsigned int size, void (*entrypoint)(void))
115190
{
116-
size = (size + 1023) & ~1023;
191+
size = (size + CONTEXT_SIZE + 1023) & ~1023;
117192
cothread_t handle = 0;
118193
#if defined(__APPLE__) || HAVE_POSIX_MEMALIGN >= 1
119-
if (posix_memalign(&handle, 1024, size + 512) < 0)
194+
if (posix_memalign(&handle, 1024, size) < 0)
120195
return 0;
121196
#else
122-
handle = memalign(1024, size + 512);
197+
handle = memalign(1024, size);
123198
#endif
124199

125200
if (!handle)
126201
return handle;
127202

128203
uint64_t *ptr = (uint64_t*)handle;
129-
memset(ptr, 0, 512);
204+
memset(ptr, 0, CONTEXT_SIZE);
130205
/* Non-volatiles. */
131206
/* ptr[0],..., ptr[7] -> s0,..., s7 */
132207
store_gp(&ptr[8]); /* gp */
133-
ptr[9] = REG_TRANSFORM(((uintptr_t)ptr + size + 512 - 8)); /* sp */
208+
ptr[9] = REG_TRANSFORM(((uintptr_t)ptr + size - 8)); /* sp */
134209
/* ptr[10] is fp */
135210
ptr[11] = REG_TRANSFORM((uintptr_t)entrypoint); /* ra */
136211
return handle;

0 commit comments

Comments
 (0)