Skip to content

Commit 04215d3

Browse files
author
Wayne Ren
authored
Merge pull request #128 from foss-for-synopsys-dwc-arc-processors/r58_r59
arc: accl regs (r58,r59) are caller-saved regs
2 parents 88d13f7 + c908035 commit 04215d3

File tree

3 files changed

+63
-25
lines changed

3 files changed

+63
-25
lines changed

inc/arc/arc_asm_common.h

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -88,20 +88,23 @@
8888
.endm
8989
#endif
9090

91+
/* macro to save accl regs */
9192
.macro SAVE_R58_R59
9293
#if ARC_FEATURE_FPU || ARC_FEATURE_DSP || ARC_FEATURE_MPU_OPTION_NUM > 6
9394
PUSH r58
9495
PUSH r59
9596
#endif
9697
.endm
9798

99+
/* macro to restore accl regs */
98100
.macro RESTORE_R58_R59
99101
#if ARC_FEATURE_FPU || ARC_FEATURE_DSP || ARC_FEATURE_MPU_OPTION_NUM > 6
100102
POP r59
101103
POP r58
102104
#endif
103105
.endm
104106

107+
/* macro to save fpu related regs */
105108
.macro SAVE_FPU_REGS
106109
#if ARC_FEATURE_FPU
107110
PUSHAX AUX_FPU_CTRL
@@ -117,6 +120,7 @@
117120
#endif
118121
.endm
119122

123+
/* macro to restore fpu related regs */
120124
.macro RESTORE_FPU_REGS
121125
#if ARC_FEATURE_FPU
122126

@@ -132,7 +136,7 @@
132136

133137
.endm
134138

135-
139+
/* macro to save dsp related regs */
136140
.macro SAVE_DSP_REGS
137141
#if ARC_FEATURE_DSP
138142
PUSHAX AUX_DSP_CTRL
@@ -149,6 +153,7 @@
149153
#endif
150154
.endm
151155

156+
/* macro to restore dsp related regs */
152157
.macro RESTORE_DSP_REGS
153158
#if ARC_FEATURE_DSP
154159

@@ -196,7 +201,6 @@
196201
#endif
197202

198203
#if ARC_FEATURE_FPU_DSP_CONTEXT
199-
SAVE_R58_R59
200204
SAVE_FPU_REGS
201205
SAVE_DSP_REGS
202206
#endif
@@ -208,7 +212,6 @@
208212
#if ARC_FEATURE_FPU_DSP_CONTEXT
209213
RESTORE_DSP_REGS
210214
RESTORE_FPU_REGS
211-
RESTORE_R58_R59
212215
#endif
213216

214217
#if defined(ARC_ENABLE_EXTRA_CALLEE)
@@ -237,6 +240,7 @@
237240
POP r13
238241
.endm
239242

243+
/* macro to clear callee regs */
240244
.macro CLEAR_CALLEE_REGS
241245
#ifndef ARC_FEATURE_RF16
242246
mov r25, 0
@@ -280,14 +284,10 @@
280284
sr 0, [AUX_DSP_CTRL]
281285
#endif /* ARC_FEATURE_DSP */
282286

283-
#if ARC_FEATURE_FPU || ARC_FEATURE_DSP || ARC_FEATURE_MPU_OPTION_NUM > 6
284-
mov r59, 0
285-
mov r58, 0
286-
#endif
287-
288287
#endif /* ARC_FEATURE_FPU_DSP_CONTEXT */
289288
.endm
290289

290+
/* macro to clear scratch regs */
291291
.macro CLEAR_SCRATCH_REGS
292292
mov r1, 0
293293
mov r2, 0
@@ -302,6 +302,10 @@
302302
mov r11, 0
303303
mov r12, 0
304304

305+
#if ARC_FEATURE_FPU || ARC_FEATURE_DSP || ARC_FEATURE_MPU_OPTION_NUM > 6
306+
mov r59, 0
307+
mov r58, 0
308+
#endif
305309
mov fp, 0
306310
mov r29, 0
307311
mov r30, 0
@@ -322,6 +326,7 @@
322326

323327
.endm
324328

329+
/* macro to save r0 to r12 */
325330
.macro SAVE_R0_TO_R12
326331
PUSH r0
327332
PUSH r1
@@ -340,6 +345,7 @@
340345
PUSH r12
341346
.endm
342347

348+
/* macro to restore r0 to r12 */
343349
.macro RESTORE_R0_TO_R12
344350
POP r12
345351
POP r11
@@ -358,39 +364,44 @@
358364
POP r0
359365
.endm
360366

367+
/* macro to save code density regs */
361368
.macro SAVE_CODE_DENSITY
362369
PUSHAX AUX_JLI_BASE
363370
PUSHAX AUX_LDI_BASE
364371
PUSHAX AUX_EI_BASE
365372
.endm
366373

374+
/* macro to restore code density regs */
367375
.macro RESTORE_CODE_DENSITY
368376
POPAX AUX_EI_BASE
369377
POPAX AUX_LDI_BASE
370378
POPAX AUX_JLI_BASE
371379
.endm
372380

373-
/* todo: check the contents of NON_SCRATCH_REGS in debug */
381+
/* macro to save all non-caller saved regs */
374382
.macro SAVE_NONSCRATCH_REGS
375-
/* r0-r12 are saved by caller function */
383+
/* caller saved regs are saved by caller function */
376384
PUSH gp
377385
PUSH fp
378386
PUSH blink
379387
SAVE_CALLEE_REGS
380388
.endm
381389

390+
/* macro to restore all non-caller saved regs */
382391
.macro RESTORE_NONSCRATCH_REGS
383392
RESTORE_CALLEE_REGS
384393
POP blink
385394
POP fp
386395
POP gp
387396
.endm
388397

389-
398+
/* macro to save regs in firq */
390399
.macro SAVE_FIQ_EXC_REGS
391400
#ifndef ARC_FEATURE_RGF_BANKED_REGS
392401
SAVE_R0_TO_R12
393402

403+
SAVE_R58_R59
404+
394405
PUSH gp
395406
PUSH fp
396407
PUSH r30 /* general purpose */
@@ -402,7 +413,7 @@
402413
#error "unsupported ARC_FEATURE_RGF_BANKED_REGS"
403414
#endif
404415

405-
#if ARC_FEATURE_RGF_BANKED_REGS == 4 || ARC_FEATURE_BANKED_REGS == 8 || \
416+
#if ARC_FEATURE_RGF_BANKED_REGS == 4 || ARC_FEATURE_RGF_BANKED_REGS == 8 || \
406417
ARC_FEATURE_RGF_BANKED_REGS == 16
407418
#ifndef ARC_FEATURE_RF16
408419
PUSH r4
@@ -414,7 +425,7 @@
414425
#endif
415426
#endif
416427

417-
#if ARC_FEATURE_RGF_BANKED_REGS == 4 || ARC_FEATURE_BANKED_REGS == 8
428+
#if ARC_FEATURE_RGF_BANKED_REGS == 4 || ARC_FEATURE_RGF_BANKED_REGS == 8
418429
PUSH r10
419430
PUSH r11
420431
#endif
@@ -423,7 +434,9 @@
423434
PUSH r12
424435
#endif
425436

426-
#if ARC_FEATURE_RGF_BANKED_REGS == 4 || ARC_FEATURE_BANKED_REGS == 8
437+
SAVE_R58_R59
438+
439+
#if ARC_FEATURE_RGF_BANKED_REGS == 4 || ARC_FEATURE_RGF_BANKED_REGS == 8
427440
PUSH gp
428441
PUSH fp
429442
PUSH r30 /* general purpose */
@@ -438,6 +451,7 @@
438451
SAVE_LP_REGS
439452
.endm
440453

454+
/* macro to restore reg in firq */
441455
.macro RESTORE_FIQ_EXC_REGS
442456
RESTORE_LP_REGS
443457
#if ARC_FEATURE_CODE_DENSITY
@@ -450,6 +464,8 @@
450464
POP fp
451465
POP gp
452466

467+
RESTORE_R58_R59
468+
453469
RESTORE_R0_TO_R12
454470
#else
455471

@@ -458,23 +474,25 @@
458474
#error "unsupported ARC_FEATURE_RGF_BANKED_REGS"
459475
#endif
460476

461-
#if ARC_FEATURE_RGF_BANKED_REGS == 4 || ARC_FEATURE_BANKED_REGS == 8
477+
#if ARC_FEATURE_RGF_BANKED_REGS == 4 || ARC_FEATURE_RGF_BANKED_REGS == 8
462478
POP blink
463479
POP r30
464480
POP fp
465481
POP gp
466482
#endif
467483

484+
RESTORE_R58_R59
485+
468486
#if ARC_FEATURE_RGF_BANKED_REGS == 4
469487
POP r12
470488
#endif
471489

472-
#if ARC_FEATURE_RGF_BANKED_REGS == 4 || ARC_FEATURE_BANKED_REGS == 8
490+
#if ARC_FEATURE_RGF_BANKED_REGS == 4 || ARC_FEATURE_RGF_BANKED_REGS == 8
473491
POP r11
474492
POP r10
475493
#endif
476494

477-
#if ARC_FEATURE_RGF_BANKED_REGS == 4 || ARC_FEATURE_BANKED_REGS == 8 || \
495+
#if ARC_FEATURE_RGF_BANKED_REGS == 4 || ARC_FEATURE_RGF_BANKED_REGS == 8 || \
478496
ARC_FEATURE_RGF_BANKED_REGS == 16
479497
#ifndef ARC_FEATURE_RF16
480498
POP r9
@@ -492,6 +510,7 @@
492510
/* normal interrupt prologue, pc, status and r0-r11 are saved by hardware */
493511
.macro INTERRUPT_PROLOGUE
494512
PUSH r12
513+
SAVE_R58_R59
495514
PUSH gp
496515
PUSH fp
497516
PUSH ilink
@@ -509,6 +528,7 @@
509528
POP ilink
510529
POP fp
511530
POP gp
531+
RESTORE_R58_R59
512532
POP r12
513533
.endm
514534

@@ -544,6 +564,7 @@
544564
SAVE_LP_REGS
545565

546566
PUSH r12
567+
SAVE_R58_R59
547568
PUSH gp
548569
PUSH fp
549570
PUSH ilink
@@ -560,6 +581,7 @@
560581
POP ilink
561582
POP fp
562583
POP gp
584+
RESTORE_R58_R59
563585
POP r12
564586

565587
RESTORE_LP_REGS
@@ -584,7 +606,6 @@
584606

585607
POP blink
586608

587-
588609
POPAX AUX_ERRET
589610
add sp, sp, 4 /* slot for SEC_STAT */
590611
POPAX AUX_ERSTATUS
@@ -625,6 +646,7 @@
625646
PUSH r0
626647

627648
PUSH r12
649+
SAVE_R58_R59
628650
PUSH gp
629651
PUSH fp
630652
PUSH ilink
@@ -641,6 +663,7 @@
641663
POP ilink
642664
POP fp
643665
POP gp
666+
RESTORE_R58_R59
644667
POP r12
645668

646669
POP r0

inc/arc/arc_exception.h

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ typedef struct int_exc_frame {
7373
uint32_t fp; /* r27 */
7474
uint32_t gp; /* r26 */
7575

76+
#if ARC_FEATURE_DSP || ARC_FEATURE_FPU || ARC_FEATURE_MPU_OPTION_NUM > 6
77+
/* accl and acch, common for mpy_option >6 and fpu_fma option */
78+
uint32_t r59;
79+
uint32_t r58;
80+
#endif
81+
7682
uint32_t r12;
7783

7884
uint32_t lp_end, lp_start, lp_count;
@@ -102,6 +108,11 @@ typedef struct int_exc_frame {
102108
uint32_t fp; /* r27 */
103109
uint32_t gp; /* r26 */
104110

111+
#if ARC_FEATURE_DSP || ARC_FEATURE_FPU || ARC_FEATURE_MPU_OPTION_NUM > 6
112+
/* accl and acch, common for mpy_option >6 and fpu_fma option */
113+
uint32_t r59;
114+
uint32_t r58;
115+
#endif
105116
uint32_t r12;
106117

107118
uint32_t r0, r1, r2, r3;
@@ -162,12 +173,6 @@ typedef struct callee_frame {
162173
FPU_EXT_FRAME fpu_ext_regs;
163174
#endif
164175

165-
#if ARC_FEATURE_DSP || ARC_FEATURE_FPU || ARC_FEATURE_MPU_OPTION_NUM > 6
166-
/* accl and acch, common for mpy_option >6 and fpu_fma option */
167-
uint32_t r59;
168-
uint32_t r58;
169-
#endif
170-
171176
#endif /* ARC_FEATURE_FPU_DSP_CONTEXT */
172177

173178
#if defined(ARC_ENABLE_EXTRA_CALLEE)

os/freertos/portable/Synopsys/ARC/arc_support.s

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,8 +450,12 @@ ret_firq_2:
450450
#if ARC_FEATURE_CODE_DENSITY
451451
RESTORE_CODE_DENSITY
452452
#endif
453+
RESTORE_R58_R59
453454
#endif
454455

456+
/* when BANKED_REGS == 16, r4-r9 wiil be also saved in fast irq stack
457+
* so pop them out
458+
*/
455459
#if ARC_FEATURE_RGF_BANKED_REGS == 16 && !defined(ARC_FEATURE_RF16)
456460
POP r9
457461
POP r8
@@ -461,6 +465,10 @@ ret_firq_2:
461465
POP r4
462466
#endif
463467

468+
/* for other cases, unbanked regs are already in interrupted context's stack,
469+
* so just need to save and pop the banked regs
470+
*/
471+
464472
/* save the interruptted context */
465473
#if ARC_FEATURE_RGF_BANKED_REGS > 0
466474
/* switch back to bank0 */
@@ -483,9 +491,10 @@ ret_firq_2:
483491
PUSH r3
484492
PUSH r12
485493
#elif ARC_FEATURE_RGF_BANKED_REGS >= 16
486-
/* nothing is saved */
494+
/* nothing is saved, */
487495
SAVE_R0_TO_R12
488496

497+
SAVE_R58_R59
489498
PUSH gp
490499
PUSH fp
491500
PUSH r30 /* general purpose */
@@ -543,6 +552,7 @@ ret_firq_r:
543552
POP fp
544553
POP gp
545554

555+
RESTORE_R58_R59
546556
RESTORE_R0_TO_R12
547557
#endif /* ARC_FEATURE_RGF_BANKED_REGS */
548558
#else

0 commit comments

Comments
 (0)