46
46
#define _lr (0 *8 )
47
47
#define _mstatus (1*8 )
48
48
#define _mepc (2*8 )
49
- #define excCtxSize (3*8 )
49
+ #define _mregtmp (3*8 )
50
+ #define excCtxSize (4*8 )
50
51
51
52
52
53
// This will be copied into the processor's general exception vector. Since the
@@ -69,6 +70,9 @@ TEXT runtime·intvector(SB),NOSPLIT|NOFRAME,$0
69
70
// Only syscalls and interrupts are handled at the moment, all other exceptions
70
71
// are fatal.
71
72
TEXT runtime·exceptionHandler(SB),NOSPLIT|NOFRAME,$0
73
+ // Be especially careful to not clobber REGTMP with multi-instruction
74
+ // statements until it's saved on the stack.
75
+
72
76
// Determine caller stack
73
77
MOVV $·cpu0(SB), R26
74
78
BNE R26, g, fromThread
@@ -89,6 +93,7 @@ fromThread:
89
93
fromHandler:
90
94
// Save exception context on ISR stack
91
95
SUB $excCtxSize, R29
96
+ MOVV R23, _mregtmp(R29) // R23 (REGTMP) is now free for use
92
97
OR $1 , R31, R26 // Encode smallCtx flag in lr
93
98
MOVV R26, _lr(R29) // R29 is now free for use
94
99
MOVV M(C0_SR), R26
@@ -170,7 +175,8 @@ TEXT runtime·syscallHandler(SB),NOSPLIT|NOFRAME,$0
170
175
171
176
MOVV _lr(R29), R3
172
177
MOVV R3, (m_mOS+mOS_ra)(R2)
173
-
178
+ MOVV _mregtmp(R29), R3
179
+ MOVV R3, (m_mOS+mOS_tmp)(R2)
174
180
MOVV _mepc(R29), R3
175
181
AND $~1 , R3 // Remove fromHandler flag from epc
176
182
MOVV R3, (m_mOS+mOS_epc)(R2)
@@ -249,6 +255,9 @@ TEXT runtime·softwareInterruptHandler(SB),NOSPLIT|NOFRAME,$0
249
255
// Save thread context in mOS
250
256
MOVV (cpuctx_exe)(g), R27
251
257
258
+ MOVV _mregtmp(R29), R26
259
+ MOVV R26, (m_mOS+mOS_tmp)(R27)
260
+
252
261
MOVV _lr(R29), R26
253
262
AND $~1 , R26 // Remove smallCtx flag from lr
254
263
MOVV R26, (m_mOS+mOS_ra)(R27)
@@ -315,8 +324,8 @@ smallCtx:
315
324
MOVV (m_mOS+mOS_ra)(R27), R31
316
325
MOVV (m_mOS+mOS_epc)(R27), R26
317
326
MOVV R26, M(C0_EPC)
318
- MOVV $~1 , R27
319
- AND R27, R31 // Remove smallCtx flag
327
+ AND $~1 , R31 // Remove smallCtx flag
328
+ MOVV (m_mOS+mOS_tmp)( R27), R23
320
329
321
330
ERET
322
331
@@ -426,11 +435,9 @@ TEXT runtime·exceptionReturn(SB),NOSPLIT|NOFRAME,$0
426
435
MOVV $1 , R27
427
436
AND R26, R27
428
437
429
- ADD $excCtxSize, R29
430
-
431
438
// Don't restore interrupt mask or switch stacks yet if we were called
432
439
// from handler
433
- BNE R27, R0, return
440
+ BNE R27, R0, fromHandler
434
441
435
442
MOVW M(C0_SR), R26
436
443
MOVW $~INTR_EXT, R27
@@ -441,11 +448,18 @@ TEXT runtime·exceptionReturn(SB),NOSPLIT|NOFRAME,$0
441
448
OR R27, R26
442
449
MOVW R26, M(C0_SR)
443
450
451
+ MOVV _mregtmp(R29), R23
452
+ ADD $excCtxSize, R29
444
453
MOVV $·cpu0(SB), R26
445
454
MOVV (g_sched+gobuf_sp)(R26), R29
446
455
MOVV (g_sched+gobuf_g)(R26), g
447
456
448
- return:
457
+ ERET
458
+
459
+ fromHandler:
460
+ MOVV _mregtmp(R29), R23
461
+ ADD $excCtxSize, R29
462
+
449
463
ERET
450
464
451
465
@@ -478,29 +492,25 @@ TEXT ·saveGPRs(SB),NOSPLIT|NOFRAME,$0
478
492
MOVV R20, 152 (R26)
479
493
MOVV R21, 160 (R26)
480
494
MOVV R22, 168 (R26)
481
- MOVV R23, 176 (R26)
482
- MOVV R24, 184 (R26)
483
- MOVV R25, 192 (R26)
484
- MOVV RSB, 200 (R26)
495
+ MOVV R24, 176 (R26)
496
+ MOVV R25, 184 (R26)
497
+ MOVV RSB, 192 (R26)
485
498
MOVV HI, R1
486
- MOVV R1, 208 (R26)
499
+ MOVV R1, 200 (R26)
487
500
MOVV LO, R1
488
- MOVV R1, 216 (R26)
501
+ MOVV R1, 208 (R26)
489
502
RET
490
503
491
504
492
- // R26 must point to stored gprs. Only use R26, R27 after restoring. Be
493
- // especially careful and look at the disassembly; The assembler might decide
494
- // to use R16-R23 for you.
505
+ // R26 must point to stored gprs. Only use R26, R27 after restoring.
495
506
TEXT ·restoreGPRs(SB),NOSPLIT|NOFRAME,$0
496
- MOVV 216 (R26), R1
497
- MOVV R1, LO
498
507
MOVV 208 (R26), R1
508
+ MOVV R1, LO
509
+ MOVV 200 (R26), R1
499
510
MOVV R1, HI
500
- MOVV 200 (R26), RSB
501
- MOVV 192 (R26), R25
502
- MOVV 184 (R26), R24
503
- MOVV 176 (R26), R23
511
+ MOVV 192 (R26), RSB
512
+ MOVV 184 (R26), R25
513
+ MOVV 176 (R26), R24
504
514
MOVV 168 (R26), R22
505
515
MOVV 160 (R26), R21
506
516
MOVV 152 (R26), R20
0 commit comments