Skip to content

Commit a5f515a

Browse files
Fabien-Chouteauburratoo
authored andcommitted
Leon3: implement errata GRLIB-TN-0018 workaround #1
Part of T226-001. Change-Id: I0ffdf524b7312e20d379aa37358058ea06431ae6
1 parent 113460f commit a5f515a

File tree

3 files changed

+76
-19
lines changed

3 files changed

+76
-19
lines changed

sparc/leon/crt0.S

+62-12
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@
5050

5151
/* Entry for traps which do nothing */
5252

53-
#define DUMMY_TRAP \
54-
jmpl %l2, %g0; \
55-
rett %l2 + 4; \
56-
nop; \
53+
#define DUMMY_TRAP \
54+
mov %l2, %l1; \
55+
add %l2, 4, %l2; \
56+
b __gnat_return_from_trap; \
5757
nop;
5858

5959
/* Entry for traps that should not occur. They cause program termination */
@@ -475,8 +475,10 @@ overflow:
475475
std %i6, [%sp + I6_OFFSET]
476476

477477
restore ! Increment CWP
478-
jmpl %l1, %g0 ! Load npc with saved pc
479-
rett %l2 ! return from trap
478+
479+
! %l1 is PC and %l2 is nPC
480+
b __gnat_return_from_trap
481+
nop
480482

481483
.size overflow, . - overflow
482484

@@ -507,8 +509,9 @@ underflow:
507509
save ! Come back to the trap window
508510
save ! where return address is located
509511

510-
jmpl %l1, %g0
511-
rett %l2 ! Return from trap
512+
! %l1 is PC and %l2 is nPC
513+
b __gnat_return_from_trap
514+
nop
512515

513516
.size underflow, . - underflow
514517
.type flush_windows,#function
@@ -605,8 +608,12 @@ flush_windows:
605608
nop
606609
nop
607610

608-
jmp %l2 ! return to nPC
609-
rett %l2 + 4
611+
mov %l2, %l1
612+
add %l2, 4, %l2
613+
614+
! %l1 is PC and %l2 is nPC
615+
b __gnat_return_from_trap
616+
nop
610617

611618
.size flush_windows, . - flush_windows
612619

@@ -621,11 +628,54 @@ mask_interrupt_level:
621628
nop
622629
nop
623630

624-
jmp %l2
625-
rett %l2 + 4 ! Return from trap
631+
mov %l2, %l1
632+
add %l2, 4, %l2
633+
634+
! %l1 is PC and %l2 is nPC
635+
b __gnat_return_from_trap
636+
nop
626637

627638
.size mask_interrupt_level, . - mask_interrupt_level
628639

640+
641+
/* Routine to return from trap, potentially with handling of Leon3 errata.
642+
%l1 must be set to the PC after return, and %l2 to nPC after return. */
643+
644+
.global __gnat_return_from_trap
645+
.type __gnat_return_from_trap,#function
646+
__gnat_return_from_trap:
647+
648+
#if defined(LEON3)
649+
/* Comment the #define below to disable the handling of Leon3 errata
650+
GRLIB-TN-0018 */
651+
#define LEON3_ERRATA_GRLIB_TN_0018
652+
#endif
653+
654+
#if defined (LEON3_ERRATA_GRLIB_TN_0018)
655+
656+
/* LEON3FT RETT Restart Errata (GRLIB-TN-0018) workaround #1 */
657+
mov %psr, %l0 ! save condition codes
658+
1: lda [%g0] 2, %l3 ! read cache control register
659+
srl %l3, 15, %l4 ! check bit 15 if flush in progress
660+
andcc %l4, 1, %g0
661+
bne 1b ! loop back if flushing
662+
! let following instruction go into the delay slot
663+
andn %l3, 3, %l4 ! mask out DCS field
664+
! align cache line boundary at this point for optimum performance
665+
sta %l4, [%g0] 2 ! write to disable Icache
666+
mov %l0, %psr ! delay + restore condition codes
667+
or %l1, %l1, %l1 ! delay + catch rf parity error on l1
668+
or %l2, %l2, %l2 ! delay + catch rf parity error on l2
669+
sta %l3, [%g0] 2 ! write to re-enable Icache after rett
670+
nop ! delay to ensure first insn after gets cached
671+
jmp %l1
672+
rett %l2
673+
#else
674+
jmpl %l1, %g0 ! PC
675+
rett %l2 ! nPC
676+
#endif
677+
.size __gnat_return_from_trap, . - __gnat_return_from_trap
678+
629679
.section ".rodata"
630680
.align 8
631681
double_zero:

sparc/src/context_switch.S

+4-3
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,8 @@ fp_context_switch:
471471
nop
472472

473473
.Lreturn_from_trap:
474-
jmp %l1
475-
rett %l2 ! return from trap
474+
! %l1 is PC and %l2 is nPC
475+
b __gnat_return_from_trap
476+
nop
476477

477-
.size fp_context_switch, . - fp_context_switch
478+
.size fp_context_switch, . - fp_context_switch

sparc/src/trap_handler.S

+10-4
Original file line numberDiff line numberDiff line change
@@ -431,14 +431,20 @@ call_trap_handler:
431431
.Lreturn_to_next:
432432
nop ! delay slots after
433433
nop ! wrpsr (before rett)
434-
jmp %l2
435-
rett %l2 + 4
434+
mov %l2, %l1
435+
add %l2, 4, %l2
436+
437+
! %l1 is PC and %l2 is nPC
438+
b __gnat_return_from_trap
439+
nop
436440

437441
.Lreturn_to_interrupted:
438442
nop ! delay slots after
439443
nop ! wrpsr (before rett)
440-
jmp %l1
441-
rett %l2
444+
445+
! %l1 is PC and %l2 is nPC
446+
b __gnat_return_from_trap
447+
nop
442448
.cfi_endproc
443449

444450
.size call_trap_handler, . - call_trap_handler

0 commit comments

Comments
 (0)