@ -55,17 +55,56 @@
* registers.
*
* /
# if _ _ r i s c v _ x l e n = = 6 4
# define p o r t W O R D _ S I Z E 8
/ * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* This f i l e i s p a r t o f t h e F r e e R T O S d i s t r i b u t i o n a n d w a s c o n t r i b u t e d
* to t h e p r o j e c t b y S i F i v e
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* /
# if( _ _ r i s c v _ x l e n = = 6 4 )
# define s t o r e _ x s d
# define l o a d _ x l d
# elif _ _ r i s c v _ x l e n = = 3 2
# elif( _ _ r i s c v _ x l e n = = 3 2 )
# define s t o r e _ x s w
# define l o a d _ x l w
# define p o r t W O R D _ S I Z E 4
# else
# error A s s e m b l e r d i d n o t d e f i n e _ _ r i s c v _ x l e n
# endif
# endif / * ( _ _ r i s c v _ x l e n = = x x ) * /
/* Nb registers to save */
# ifdef _ _ r i s c v _ 3 2 e
# define p o r t a s m N B _ R E G S _ S A V E D ( 1 6 )
# else
# define p o r t a s m N B _ R E G S _ S A V E D ( 3 2 )
# endif / * _ _ r i s c v _ 3 2 e * /
# define p o r t W O R D _ S I Z E ( _ _ r i s c v _ x l e n / 8 )
/* Number of FPU register */
# ifdef _ _ r i s c v _ f d i v
# define M S T A T U S _ F S 0 x00 0 0 6 0 0 0 / * F l o a t i n g - p o i n t S t a t u s * /
# define M S T A T U S _ F S _ O F F 0 x00 0 0 0 0 0 0
# define M S T A T U S _ F S _ I N I T I A L 0 x00 0 0 2 0 0 0
# define M S T A T U S _ F S _ C L E A N 0 x00 0 0 4 0 0 0
# define M S T A T U S _ F S _ D I R T Y 0 x00 0 0 6 0 0 0
# if _ _ r i s c v _ f l e n = = 3 2
# define s t o r e _ f p u f s w
# define l o a d _ f p u f l w
# endif / * _ _ r i s c v _ f l e n = = 3 2 * /
# if _ _ r i s c v _ f l e n = = 6 4
# define s t o r e _ f p u f s d
# define l o a d _ f p u f l d
# endif / * _ _ r i s c v _ f l e n = = 6 4 * /
# define p o r t a s m F P U _ C O N T E X T _ S I Z E ( 3 2 )
# define p o r t F P U W O R D _ S I Z E ( _ _ r i s c v _ f l e n / 8 )
# else
# define p o r t a s m F P U _ C O N T E X T _ S I Z E ( 0 )
# define p o r t F P U W O R D _ S I Z E ( 0 )
# endif / * _ _ r i s c v _ f d i v * /
# include " f r e e r t o s _ r i s c _ v _ c h i p _ s p e c i f i c _ e x t e n s i o n s . h "
@ -85,20 +124,47 @@ definitions. */
# error f r e e r t o s _ r i s c _ v _ c h i p _ s p e c i f i c _ e x t e n s i o n s . h m u s t d e f i n e p o r t a s m H A S _ M T I M E t o e i t h e r 1 ( M T I M E c l o c k p r e s e n t ) o r 0 ( M T I M E c l o c k n o t p r e s e n t ) . S e e h t t p s : / / w w w . F r e e R T O S . o r g / U s i n g - F r e e R T O S - o n - R I S C - V . h t m l
# endif
# ifndef p o r t as m HA N D L E _ I N T E R R U P T
# error p o r t as m HA N D L E _ I N T E R R U P T m u s t b e d e f i n e d t o t h e f u n c t i o n t o b e c a l l e d t o h a n d l e e x t e r n a l / p e r i p h e r a l i n t e r r u p t s . p o r t a s m H A N D L E _ I N T E R R U P T c a n b e d e f i n e d o n t h e a s s e m b l e r c o m m a n d l i n e o r i n t h e a p p r o p r i a t e f r e e r t o s _ r i s c _ v _ c h i p _ s p e c i f i c _ e x t e n s i o n s . h h e a d e r f i l e . h t t p s : / / w w w . F r e e R T O S . o r g / U s i n g - F r e e R T O S - o n - R I S C - V . h t m l
# ifndef p o r t HA N D L E _ I N T E R R U P T
# error p o r t HA N D L E _ I N T E R R U P T m u s t b e d e f i n e d t o t h e f u n c t i o n t o b e c a l l e d t o h a n d l e e x t e r n a l / p e r i p h e r a l i n t e r r u p t s .
# endif
# ifndef p o r t H A N D L E _ E X C E P T I O N
# error p o r t H A N D L E _ E X C E P T I O N m u s t b e d e f i n e d t o t h e f u n c t i o n t o b e c a l l e d t o h a n d l e e x e c p t i o n s .
# endif
# ifndef p o r t a s m H A S _ S I F I V E _ C L I N T
# define p o r t a s m H A S _ S I F I V E _ C L I N T 0
# endif
/ * Only t h e s t a n d a r d c o r e r e g i s t e r s a r e s t o r e d b y d e f a u l t . A n y a d d i t i o n a l
registers m u s t b e s a v e d b y t h e p o r t a s m S A V E _ A D D I T I O N A L _ R E G I S T E R S a n d
portasmRESTORE_ A D D I T I O N A L _ R E G I S T E R S m a c r o s - w h i c h c a n b e d e f i n e d i n a c h i p
specific v e r s i o n o f f r e e r t o s _ r i s c _ v _ c h i p _ s p e c i f i c _ e x t e n s i o n s . h . S e e t h e n o t e s
at t h e t o p o f t h i s f i l e . * /
# define p o r t C O N T E X T _ S I Z E ( 3 0 * p o r t W O R D _ S I Z E )
/ *
* To m a i n t a i n R I S C V A B I s t a c k a l i g n m e n t r e q u i r e m e n t s ( 1 6 b y t e s )
* this d a t a s t r u c t u r e m u s t b e a M U L T I P L E o f 1 6 b y t e s i n s i z e .
* 3 2 Registers ( f o r s t a n d a r d c o r e ) i s 1 6 b y t e a l i g n e d : )
* We a d d s p a c e t o s a v e a d d i t i o n a l i n f o r m a t i o n s o i t m u s t b e m u l t i p l e o f 4 .
* mepc 3 3 t h r e g i s t e r
* mstatus 3 4 t h r e g i s t e r
* ruf 3 5 t h r e g i s t e r
* ruf 3 6 t h r e g i s t e r
* /
# define P O R T _ C O N T E X T _ m e p c I D X ( p o r t a s m N B _ R E G S _ S A V E D )
# define P O R T _ C O N T E X T _ m s t a t u s I D X ( p o r t a s m N B _ R E G S _ S A V E D + 1 )
# define p o r t a s m L A S T _ B A S E _ R E G S ( p o r t a s m N B _ R E G S _ S A V E D + 4 )
# define P O R T _ C O N T E X T _ l a s t I D X ( ( p o r t a s m N B _ R E G S _ S A V E D ) + p o r t a s m A D D I T I O N A L _ C O N T E X T _ S I Z E )
/* used in assembler, as byte offsets from the start of the context */
# define P O R T _ C O N T E X T _ x I D X ( X ) ( X ) / * i n d e x i n t o " r a w " f o r r e g i s t e r x ? * /
# define P O R T _ C O N T E X T _ x O F F S E T ( X ) ( P O R T _ C O N T E X T _ x I D X ( X ) * p o r t W O R D _ S I Z E )
# define P O R T _ C O N T E X T _ m e p c O F F S E T ( P O R T _ C O N T E X T _ m e p c I D X * p o r t W O R D _ S I Z E )
# define P O R T _ C O N T E X T _ m s t a t u s O F F S E T ( P O R T _ C O N T E X T _ m s t a t u s I D X * p o r t W O R D _ S I Z E )
# define P O R T _ C O N T E X T _ r u f O F F S E T ( P O R T _ C O N T E X T _ r u f I D X * p o r t W O R D _ S I Z E )
# define P O R T _ C O N T E X T _ f p u O F F S E T ( X ) ( ( X ) * p o r t F P U W O R D _ S I Z E )
/* total size of the structure usable in ASM. */
# define p o r t a s m R E G I S T E R _ C O N T E X T _ W O R D S I Z E ( ( p o r t a s m L A S T _ B A S E _ R E G S ) * ( p o r t W O R D _ S I Z E ) )
# define p o r t a s m A D D I T I O N A L _ C O N T E X T _ W O R D S I Z E ( ( p o r t a s m A D D I T I O N A L _ C O N T E X T _ S I Z E ) * ( p o r t W O R D _ S I Z E ) )
# define p o r t a s m F P U _ C O N T E X T _ W O R D S I Z E ( ( p o r t a s m F P U _ C O N T E X T _ S I Z E ) * ( p o r t F P U W O R D _ S I Z E ) )
.global xPortStartFirstTask
.global freertos_risc_v_trap_handler
@ -112,184 +178,422 @@ at the top of this file. */
.extern pullNextTime
.extern uxTimerIncrementsForOneTick /* size_t type so 32-bit on 32-bit core and 64-bits on 64-bit core. */
.extern xISRStackTop
.extern port asm HANDLE_INTERRUPT
.extern port HANDLE_INTERRUPT
.extern portHANDLE_EXCEPTION
/*-----------------------------------------------------------*/
.align 8
.func
freertos_risc_v_trap_handler :
addi s p , s p , - p o r t C O N T E X T _ S I Z E
store_ x x1 , 1 * p o r t W O R D _ S I Z E ( s p )
store_ x x5 , 2 * p o r t W O R D _ S I Z E ( s p )
store_ x x6 , 3 * p o r t W O R D _ S I Z E ( s p )
store_ x x7 , 4 * p o r t W O R D _ S I Z E ( s p )
store_ x x8 , 5 * p o r t W O R D _ S I Z E ( s p )
store_ x x9 , 6 * p o r t W O R D _ S I Z E ( s p )
store_ x x10 , 7 * p o r t W O R D _ S I Z E ( s p )
store_ x x11 , 8 * p o r t W O R D _ S I Z E ( s p )
store_ x x12 , 9 * p o r t W O R D _ S I Z E ( s p )
store_ x x13 , 1 0 * p o r t W O R D _ S I Z E ( s p )
store_ x x14 , 1 1 * p o r t W O R D _ S I Z E ( s p )
store_ x x15 , 1 2 * p o r t W O R D _ S I Z E ( s p )
store_ x x16 , 1 3 * p o r t W O R D _ S I Z E ( s p )
store_ x x17 , 1 4 * p o r t W O R D _ S I Z E ( s p )
store_ x x18 , 1 5 * p o r t W O R D _ S I Z E ( s p )
store_ x x19 , 1 6 * p o r t W O R D _ S I Z E ( s p )
store_ x x20 , 1 7 * p o r t W O R D _ S I Z E ( s p )
store_ x x21 , 1 8 * p o r t W O R D _ S I Z E ( s p )
store_ x x22 , 1 9 * p o r t W O R D _ S I Z E ( s p )
store_ x x23 , 2 0 * p o r t W O R D _ S I Z E ( s p )
store_ x x24 , 2 1 * p o r t W O R D _ S I Z E ( s p )
store_ x x25 , 2 2 * p o r t W O R D _ S I Z E ( s p )
store_ x x26 , 2 3 * p o r t W O R D _ S I Z E ( s p )
store_ x x27 , 2 4 * p o r t W O R D _ S I Z E ( s p )
store_ x x28 , 2 5 * p o r t W O R D _ S I Z E ( s p )
store_ x x29 , 2 6 * p o r t W O R D _ S I Z E ( s p )
store_ x x30 , 2 7 * p o r t W O R D _ S I Z E ( s p )
store_ x x31 , 2 8 * p o r t W O R D _ S I Z E ( s p )
csrr t 0 , m s t a t u s / * R e q u i r e d f o r M P I E b i t . * /
store_ x t 0 , 2 9 * p o r t W O R D _ S I Z E ( s p )
portasmSAVE_ A D D I T I O N A L _ R E G I S T E R S / * D e f i n e d i n f r e e r t o s _ r i s c _ v _ c h i p _ s p e c i f i c _ e x t e n s i o n s . h t o s a v e a n y r e g i s t e r s u n i q u e t o t h e R I S C - V i m p l e m e n t a t i o n . * /
load_ x t 0 , p x C u r r e n t T C B / * L o a d p x C u r r e n t T C B . * /
store_ x s p , 0 ( t 0 ) / * W r i t e s p t o f i r s t T C B m e m b e r . * /
csrr a0 , m c a u s e
csrr a1 , m e p c
test_if_asynchronous :
srli a2 , a0 , _ _ r i s c v _ x l e n - 1 / * M S B o f m c a u s e i s 1 i f h a n d i n g a n a s y n c h r o n o u s i n t e r r u p t - s h i f t t o L S B t o c l e a r o t h e r b i t s . * /
beq a2 , x0 , h a n d l e _ s y n c h r o n o u s / * B r a n c h p a s t i n t e r r u p t h a n d i n g i f n o t a s y n c h r o n o u s . * /
store_ x a1 , 0 ( s p ) / * A s y n c h s o s a v e u n m o d i f i e d e x c e p t i o n r e t u r n a d d r e s s . * /
handle_asynchronous :
# if( p o r t a s m H A S _ M T I M E ! = 0 )
test_if_mtimer : /* If there is a CLINT then the mtimer is used to generate the tick interrupt. */
addi t 0 , x0 , 1
slli t 0 , t 0 , _ _ r i s c v _ x l e n - 1 / * L S B i s a l r e a d y s e t , s h i f t i n t o M S B . S h i f t 3 1 o n 3 2 - b i t o r 6 3 o n 6 4 - b i t c o r e s . * /
addi t 1 , t 0 , 7 / * 0 x80 0 0 [ ] 0 0 0 7 = = m a c h i n e t i m e r i n t e r r u p t . * /
bne a0 , t 1 , t e s t _ i f _ e x t e r n a l _ i n t e r r u p t
load_ x t 0 , p u l l M a c h i n e T i m e r C o m p a r e R e g i s t e r / * L o a d a d d r e s s o f c o m p a r e r e g i s t e r i n t o t 0 . * /
load_ x t 1 , p u l l N e x t T i m e / * L o a d t h e a d d r e s s o f u l l N e x t T i m e i n t o t 1 . * /
# if( _ _ r i s c v _ x l e n = = 3 2 )
/* Update the 64-bit mtimer compare match value in two 32-bit writes. */
li t 4 , - 1
lw t 2 , 0 ( t 1 ) / * L o a d t h e l o w w o r d o f u l l N e x t T i m e i n t o t 2 . * /
lw t 3 , 4 ( t 1 ) / * L o a d t h e h i g h w o r d o f u l l N e x t T i m e i n t o t 3 . * /
sw t 4 , 0 ( t 0 ) / * L o w w o r d n o s m a l l e r t h a n o l d v a l u e t o s t a r t w i t h - w i l l b e o v e r w r i t t e n b e l o w . * /
sw t 3 , 4 ( t 0 ) / * S t o r e h i g h w o r d o f u l l N e x t T i m e i n t o c o m p a r e r e g i s t e r . N o s m a l l e r t h a n n e w v a l u e . * /
sw t 2 , 0 ( t 0 ) / * S t o r e l o w w o r d o f u l l N e x t T i m e i n t o c o m p a r e r e g i s t e r . * /
lw t 0 , u x T i m e r I n c r e m e n t s F o r O n e T i c k / * L o a d t h e v a l u e o f u l l T i m e r I n c r e m e n t F o r O n e T i c k i n t o t 0 ( c o u l d t h i s b e o p t i m i z e d b y s t o r i n g i n a n a r r a y n e x t t o p u l l N e x t T i m e ? ) . * /
add t 4 , t 0 , t 2 / * A d d t h e l o w w o r d o f u l l N e x t T i m e t o t h e t i m e r i n c r e m e n t s f o r o n e t i c k ( a s s u m e s t i m e r i n c r e m e n t f o r o n e t i c k f i t s i n 3 2 - b i t s ) . * /
sltu t 5 , t 4 , t 2 / * S e e i f t h e s u m o f l o w w o r d s o v e r f l o w e d ( w h a t a b o u t t h e z e r o c a s e ? ) . * /
add t 6 , t 3 , t 5 / * A d d o v e r f l o w t o h i g h w o r d o f u l l N e x t T i m e . * /
sw t 4 , 0 ( t 1 ) / * S t o r e n e w l o w w o r d o f u l l N e x t T i m e . * /
sw t 6 , 4 ( t 1 ) / * S t o r e n e w h i g h w o r d o f u l l N e x t T i m e . * /
# endif / * _ _ r i s c v _ x l e n = = 3 2 * /
# if( _ _ r i s c v _ x l e n = = 6 4 )
/* Update the 64-bit mtimer compare match value. */
ld t 2 , 0 ( t 1 ) / * L o a d u l l N e x t T i m e i n t o t 2 . * /
sd t 2 , 0 ( t 0 ) / * S t o r e u l l N e x t T i m e i n t o c o m p a r e r e g i s t e r . * /
ld t 0 , u x T i m e r I n c r e m e n t s F o r O n e T i c k / * L o a d t h e v a l u e o f u l l T i m e r I n c r e m e n t F o r O n e T i c k i n t o t 0 ( c o u l d t h i s b e o p t i m i z e d b y s t o r i n g i n a n a r r a y n e x t t o p u l l N e x t T i m e ? ) . * /
add t 4 , t 0 , t 2 / * A d d u l l N e x t T i m e t o t h e t i m e r i n c r e m e n t s f o r o n e t i c k . * /
sd t 4 , 0 ( t 1 ) / * S t o r e u l l N e x t T i m e . * /
# endif / * _ _ r i s c v _ x l e n = = 6 4 * /
load_ x s p , x I S R S t a c k T o p / * S w i t c h t o I S R s t a c k b e f o r e f u n c t i o n c a l l . * /
jal x T a s k I n c r e m e n t T i c k
beqz a0 , p r o c e s s e d _ s o u r c e / * D o n ' t s w i t c h c o n t e x t i f i n c r e m e n t i n g t i c k d i d n ' t u n b l o c k a t a s k . * /
jal v T a s k S w i t c h C o n t e x t
j p r o c e s s e d _ s o u r c e
test_if_external_interrupt : /* If there is a CLINT and the mtimer interrupt is not pending then check to see if an external interrupt is pending. */
addi t 1 , t 1 , 4 / * 0 x80 0 0 0 0 0 7 + 4 = 0 x80 0 0 0 0 0 b = = M a c h i n e e x t e r n a l i n t e r r u p t . * /
bne a0 , t 1 , a s _ y e t _ u n h a n d l e d / * S o m e t h i n g a s y e t u n h a n d l e d . * /
# ifdef _ _ r i s c v _ f d i v
.macro portSAVE_FpuReg
/* get FS field from mstatus */
li t 0 , M S T A T U S _ F S
csrr t 1 , m s t a t u s
and t 0 , t 1 , t 0
li t 2 , M S T A T U S _ F S _ D I R T Y
bne t 2 , t 0 , 1 f
/* FS == dirty */
/* Make room for the additional FPU registers. */
addi s p , s p , - p o r t a s m F P U _ C O N T E X T _ W O R D S I Z E
store_ f p u f0 , P O R T _ C O N T E X T _ f p u O F F S E T ( 0 ) ( s p ) / * f0 ( f t 0 ) F P t e m p o r a r y r e g i s t e r * /
store_ f p u f1 , P O R T _ C O N T E X T _ f p u O F F S E T ( 1 ) ( s p ) / * f1 ( f t 1 ) F P t e m p o r a r y r e g i s t e r * /
store_ f p u f2 , P O R T _ C O N T E X T _ f p u O F F S E T ( 2 ) ( s p ) / * f2 ( f t 2 ) F P t e m p o r a r y r e g i s t e r * /
store_ f p u f3 , P O R T _ C O N T E X T _ f p u O F F S E T ( 3 ) ( s p ) / * f3 ( f t 3 ) F P t e m p o r a r y r e g i s t e r * /
store_ f p u f4 , P O R T _ C O N T E X T _ f p u O F F S E T ( 4 ) ( s p ) / * f4 ( f t 4 ) F P t e m p o r a r y r e g i s t e r * /
store_ f p u f5 , P O R T _ C O N T E X T _ f p u O F F S E T ( 5 ) ( s p ) / * f5 ( f t 5 ) F P t e m p o r a r y r e g i s t e r * /
store_ f p u f6 , P O R T _ C O N T E X T _ f p u O F F S E T ( 6 ) ( s p ) / * f6 ( f t 6 ) F P t e m p o r a r y r e g i s t e r * /
store_ f p u f7 , P O R T _ C O N T E X T _ f p u O F F S E T ( 7 ) ( s p ) / * f7 ( f t 7 ) F P t e m p o r a r y r e g i s t e r * /
store_ f p u f8 , P O R T _ C O N T E X T _ f p u O F F S E T ( 8 ) ( s p ) / * f8 ( f s0 ) F P S a v e d r e g i s t e r * /
store_ f p u f9 , P O R T _ C O N T E X T _ f p u O F F S E T ( 9 ) ( s p ) / * f9 ( f s0 ) F P S a v e d r e g i s t e r * /
store_ f p u f10 , P O R T _ C O N T E X T _ f p u O F F S E T ( 1 0 ) ( s p ) / * f10 ( f a0 ) F P a r g u m e n t s / r e t u r n v a l u e s r e g i s t e r * /
store_ f p u f11 , P O R T _ C O N T E X T _ f p u O F F S E T ( 1 1 ) ( s p ) / * f11 ( f a1 ) F P a r g u m e n t s / r e t u r n v a l u e s r e g i s t e r * /
store_ f p u f12 , P O R T _ C O N T E X T _ f p u O F F S E T ( 1 2 ) ( s p ) / * f12 ( f a2 ) F P a r g u m e n t s r e g i s t e r * /
store_ f p u f13 , P O R T _ C O N T E X T _ f p u O F F S E T ( 1 3 ) ( s p ) / * f13 ( f a3 ) F P a r g u m e n t s r e g i s t e r * /
store_ f p u f14 , P O R T _ C O N T E X T _ f p u O F F S E T ( 1 4 ) ( s p ) / * f14 ( f a4 ) F P a r g u m e n t s r e g i s t e r * /
store_ f p u f15 , P O R T _ C O N T E X T _ f p u O F F S E T ( 1 5 ) ( s p ) / * f15 ( f a5 ) F P a r g u m e n t s r e g i s t e r * /
store_ f p u f16 , P O R T _ C O N T E X T _ f p u O F F S E T ( 1 6 ) ( s p ) / * f16 ( f a6 ) F P a r g u m e n t s r e g i s t e r * /
store_ f p u f17 , P O R T _ C O N T E X T _ f p u O F F S E T ( 1 7 ) ( s p ) / * f17 ( f a7 ) F P a r g u m e n t s r e g i s t e r * /
store_ f p u f18 , P O R T _ C O N T E X T _ f p u O F F S E T ( 1 8 ) ( s p ) / * f18 ( f s2 ) F P S a v e d r e g i s t e r * /
store_ f p u f19 , P O R T _ C O N T E X T _ f p u O F F S E T ( 1 9 ) ( s p ) / * f19 ( f s3 ) F P S a v e d r e g i s t e r * /
store_ f p u f20 , P O R T _ C O N T E X T _ f p u O F F S E T ( 2 0 ) ( s p ) / * f20 ( f s4 ) F P S a v e d r e g i s t e r * /
store_ f p u f21 , P O R T _ C O N T E X T _ f p u O F F S E T ( 2 1 ) ( s p ) / * f21 ( f s5 ) F P S a v e d r e g i s t e r * /
store_ f p u f22 , P O R T _ C O N T E X T _ f p u O F F S E T ( 2 2 ) ( s p ) / * f22 ( f s6 ) F P S a v e d r e g i s t e r * /
store_ f p u f23 , P O R T _ C O N T E X T _ f p u O F F S E T ( 2 3 ) ( s p ) / * f23 ( f s7 ) F P S a v e d r e g i s t e r * /
store_ f p u f24 , P O R T _ C O N T E X T _ f p u O F F S E T ( 2 4 ) ( s p ) / * f24 ( f s8 ) F P S a v e d r e g i s t e r * /
store_ f p u f25 , P O R T _ C O N T E X T _ f p u O F F S E T ( 2 5 ) ( s p ) / * f25 ( f s9 ) F P S a v e d r e g i s t e r * /
store_ f p u f26 , P O R T _ C O N T E X T _ f p u O F F S E T ( 2 6 ) ( s p ) / * f26 ( f s10 ) F P S a v e d r e g i s t e r * /
store_ f p u f27 , P O R T _ C O N T E X T _ f p u O F F S E T ( 2 7 ) ( s p ) / * f27 ( f s11 ) F P S a v e d r e g i s t e r * /
store_ f p u f28 , P O R T _ C O N T E X T _ f p u O F F S E T ( 2 8 ) ( s p ) / * f28 ( f t 8 ) F P t e m p o r a r y r e g i s t e r * /
store_ f p u f29 , P O R T _ C O N T E X T _ f p u O F F S E T ( 2 9 ) ( s p ) / * f29 ( f t 9 ) F P t e m p o r a r y r e g i s t e r * /
store_ f p u f30 , P O R T _ C O N T E X T _ f p u O F F S E T ( 3 0 ) ( s p ) / * f30 ( f t 1 0 ) F P t e m p o r a r y r e g i s t e r * /
store_ f p u f31 , P O R T _ C O N T E X T _ f p u O F F S E T ( 3 1 ) ( s p ) / * f31 ( f t 1 1 ) F P t e m p o r a r y r e g i s t e r * /
/* must set FS to clean */
csrc m s t a t u s , t 0
li t 1 , M S T A T U S _ F S _ C L E A N
csrs m s t a t u s , t 1
1 :
.endm
# else
.macro portSAVE_FpuReg
/* No fpu registers to save, so this macro does nothing. */
.endm
# endif / * _ _ r i s c v _ f d i v * /
/*-----------------------------------------------------------*/
# endif / * p o r t a s m H A S _ M T I M E * /
# ifdef _ _ r i s c v _ f d i v
.macro portRESTORE_FpuReg
/* get FS field from mstatus */
li t 0 , M S T A T U S _ F S
csrr t 1 , m s t a t u s
and t 0 , t 1 , t 0
li t 2 , M S T A T U S _ F S _ O F F
beq t 2 , t 0 , 1 f
/* FS != off */
csrs m s t a t u s , t 0
/* Remove space added for additional fpu registers. */
addi s p , s p , p o r t a s m F P U _ C O N T E X T _ W O R D S I Z E
load_ f p u f0 , P O R T _ C O N T E X T _ f p u O F F S E T ( 0 ) ( s p ) / * f0 ( f t 0 ) F P t e m p o r a r y r e g i s t e r * /
load_ f p u f1 , P O R T _ C O N T E X T _ f p u O F F S E T ( 1 ) ( s p ) / * f1 ( f t 1 ) F P t e m p o r a r y r e g i s t e r * /
load_ f p u f2 , P O R T _ C O N T E X T _ f p u O F F S E T ( 2 ) ( s p ) / * f2 ( f t 2 ) F P t e m p o r a r y r e g i s t e r * /
load_ f p u f3 , P O R T _ C O N T E X T _ f p u O F F S E T ( 3 ) ( s p ) / * f3 ( f t 3 ) F P t e m p o r a r y r e g i s t e r * /
load_ f p u f4 , P O R T _ C O N T E X T _ f p u O F F S E T ( 4 ) ( s p ) / * f4 ( f t 4 ) F P t e m p o r a r y r e g i s t e r * /
load_ f p u f5 , P O R T _ C O N T E X T _ f p u O F F S E T ( 5 ) ( s p ) / * f5 ( f t 5 ) F P t e m p o r a r y r e g i s t e r * /
load_ f p u f6 , P O R T _ C O N T E X T _ f p u O F F S E T ( 6 ) ( s p ) / * f6 ( f t 6 ) F P t e m p o r a r y r e g i s t e r * /
load_ f p u f7 , P O R T _ C O N T E X T _ f p u O F F S E T ( 7 ) ( s p ) / * f7 ( f t 7 ) F P t e m p o r a r y r e g i s t e r * /
load_ f p u f8 , P O R T _ C O N T E X T _ f p u O F F S E T ( 8 ) ( s p ) / * f8 ( f s0 ) F P S a v e d r e g i s t e r * /
load_ f p u f9 , P O R T _ C O N T E X T _ f p u O F F S E T ( 9 ) ( s p ) / * f9 ( f s0 ) F P S a v e d r e g i s t e r * /
load_ f p u f10 , P O R T _ C O N T E X T _ f p u O F F S E T ( 1 0 ) ( s p ) / * f10 ( f a0 ) F P a r g u m e n t s / r e t u r n v a l u e s r e g i s t e r * /
load_ f p u f11 , P O R T _ C O N T E X T _ f p u O F F S E T ( 1 1 ) ( s p ) / * f11 ( f a1 ) F P a r g u m e n t s / r e t u r n v a l u e s r e g i s t e r * /
load_ f p u f12 , P O R T _ C O N T E X T _ f p u O F F S E T ( 1 2 ) ( s p ) / * f12 ( f a2 ) F P a r g u m e n t s r e g i s t e r * /
load_ f p u f13 , P O R T _ C O N T E X T _ f p u O F F S E T ( 1 3 ) ( s p ) / * f13 ( f a3 ) F P a r g u m e n t s r e g i s t e r * /
load_ f p u f14 , P O R T _ C O N T E X T _ f p u O F F S E T ( 1 4 ) ( s p ) / * f14 ( f a4 ) F P a r g u m e n t s r e g i s t e r * /
load_ f p u f15 , P O R T _ C O N T E X T _ f p u O F F S E T ( 1 5 ) ( s p ) / * f15 ( f a5 ) F P a r g u m e n t s r e g i s t e r * /
load_ f p u f16 , P O R T _ C O N T E X T _ f p u O F F S E T ( 1 6 ) ( s p ) / * f16 ( f a6 ) F P a r g u m e n t s r e g i s t e r * /
load_ f p u f17 , P O R T _ C O N T E X T _ f p u O F F S E T ( 1 7 ) ( s p ) / * f17 ( f a7 ) F P a r g u m e n t s r e g i s t e r * /
load_ f p u f18 , P O R T _ C O N T E X T _ f p u O F F S E T ( 1 8 ) ( s p ) / * f18 ( f s2 ) F P S a v e d r e g i s t e r * /
load_ f p u f19 , P O R T _ C O N T E X T _ f p u O F F S E T ( 1 9 ) ( s p ) / * f19 ( f s3 ) F P S a v e d r e g i s t e r * /
load_ f p u f20 , P O R T _ C O N T E X T _ f p u O F F S E T ( 2 0 ) ( s p ) / * f20 ( f s4 ) F P S a v e d r e g i s t e r * /
load_ f p u f21 , P O R T _ C O N T E X T _ f p u O F F S E T ( 2 1 ) ( s p ) / * f21 ( f s5 ) F P S a v e d r e g i s t e r * /
load_ f p u f22 , P O R T _ C O N T E X T _ f p u O F F S E T ( 2 2 ) ( s p ) / * f22 ( f s6 ) F P S a v e d r e g i s t e r * /
load_ f p u f23 , P O R T _ C O N T E X T _ f p u O F F S E T ( 2 3 ) ( s p ) / * f23 ( f s7 ) F P S a v e d r e g i s t e r * /
load_ f p u f24 , P O R T _ C O N T E X T _ f p u O F F S E T ( 2 4 ) ( s p ) / * f24 ( f s8 ) F P S a v e d r e g i s t e r * /
load_ f p u f25 , P O R T _ C O N T E X T _ f p u O F F S E T ( 2 5 ) ( s p ) / * f25 ( f s9 ) F P S a v e d r e g i s t e r * /
load_ f p u f26 , P O R T _ C O N T E X T _ f p u O F F S E T ( 2 6 ) ( s p ) / * f26 ( f s10 ) F P S a v e d r e g i s t e r * /
load_ f p u f27 , P O R T _ C O N T E X T _ f p u O F F S E T ( 2 7 ) ( s p ) / * f27 ( f s11 ) F P S a v e d r e g i s t e r * /
load_ f p u f28 , P O R T _ C O N T E X T _ f p u O F F S E T ( 2 8 ) ( s p ) / * f28 ( f t 8 ) F P t e m p o r a r y r e g i s t e r * /
load_ f p u f29 , P O R T _ C O N T E X T _ f p u O F F S E T ( 2 9 ) ( s p ) / * f29 ( f t 9 ) F P t e m p o r a r y r e g i s t e r * /
load_ f p u f30 , P O R T _ C O N T E X T _ f p u O F F S E T ( 3 0 ) ( s p ) / * f30 ( f t 1 0 ) F P t e m p o r a r y r e g i s t e r * /
load_ f p u f31 , P O R T _ C O N T E X T _ f p u O F F S E T ( 3 1 ) ( s p ) / * f31 ( f t 1 1 ) F P t e m p o r a r y r e g i s t e r * /
/* must set FS to clean */
csrc m s t a t u s , t 0
li t 1 , M S T A T U S _ F S _ C L E A N
csrs m s t a t u s , t 1
1 :
.endm
# else
.macro portRESTORE_FpuReg
/* No fpu registers to restore, so this macro does nothing. */
.endm
# endif / * _ _ r i s c v _ f d i v * /
/*-----------------------------------------------------------*/
load_ x s p , x I S R S t a c k T o p / * S w i t c h t o I S R s t a c k b e f o r e f u n c t i o n c a l l . * /
jal p o r t a s m H A N D L E _ I N T E R R U P T / * J u m p t o t h e i n t e r r u p t h a n d l e r i f t h e r e i s n o C L I N T o r i f t h e r e i s a C L I N T a n d i t h a s b e e n d e t e r m i n e d t h a t a n e x t e r n a l i n t e r r u p t i s p e n d i n g . * /
j p r o c e s s e d _ s o u r c e
.macro portSAVE_BaseReg
/* Make room for the registers. */
addi s p , s p , - p o r t a s m R E G I S T E R _ C O N T E X T _ W O R D S I Z E
store_ x x1 , P O R T _ C O N T E X T _ x O F F S E T ( 1 ) ( s p ) / * x1 ( r a ) R e t u r n a d d r e s s * /
/* x2(sp) ***** Should be save ouside this macro */
store_ x x3 , P O R T _ C O N T E X T _ x O F F S E T ( 3 ) ( s p ) / * x3 ( g p ) G l o b a l p o i n t e r * /
store_ x x4 , P O R T _ C O N T E X T _ x O F F S E T ( 4 ) ( s p ) / * x4 ( t p ) T h r e a d p o i n t e r * /
store_ x x5 , P O R T _ C O N T E X T _ x O F F S E T ( 5 ) ( s p ) / * x5 ( t 0 ) T e m p o r a r y r e g i s t e r * /
store_ x x6 , P O R T _ C O N T E X T _ x O F F S E T ( 6 ) ( s p ) / * x6 ( t 1 ) T e m p o r a r y r e g i s t e r * /
store_ x x7 , P O R T _ C O N T E X T _ x O F F S E T ( 7 ) ( s p ) / * x7 ( t 2 ) T e m p o r a r y r e g i s t e r * /
store_ x x8 , P O R T _ C O N T E X T _ x O F F S E T ( 8 ) ( s p ) / * x8 ( s0 / f p ) S a v e d r e g i s t e r / F r a m e p o i n t e r * /
store_ x x9 , P O R T _ C O N T E X T _ x O F F S E T ( 9 ) ( s p ) / * x9 ( s1 ) S a v e d r e g i s t e r * /
store_ x x10 , P O R T _ C O N T E X T _ x O F F S E T ( 1 0 ) ( s p ) / * x10 ( a0 ) F u n c t i o n a r g u m e n t * /
store_ x x11 , P O R T _ C O N T E X T _ x O F F S E T ( 1 1 ) ( s p ) / * x11 ( a1 ) F u n c t i o n a r g u m e n t * /
store_ x x12 , P O R T _ C O N T E X T _ x O F F S E T ( 1 2 ) ( s p ) / * x12 ( a2 ) F u n c t i o n a r g u m e n t * /
store_ x x13 , P O R T _ C O N T E X T _ x O F F S E T ( 1 3 ) ( s p ) / * x13 ( a3 ) F u n c t i o n a r g u m e n t * /
store_ x x14 , P O R T _ C O N T E X T _ x O F F S E T ( 1 4 ) ( s p ) / * x14 ( a4 ) F u n c t i o n a r g u m e n t * /
store_ x x15 , P O R T _ C O N T E X T _ x O F F S E T ( 1 5 ) ( s p ) / * x15 ( a5 ) F u n c t i o n a r g u m e n t * /
# ifndef _ _ r i s c v _ 3 2 e
store_ x x16 , P O R T _ C O N T E X T _ x O F F S E T ( 1 6 ) ( s p ) / * x16 ( a6 ) F u n c t i o n a r g u m e n t s * /
store_ x x17 , P O R T _ C O N T E X T _ x O F F S E T ( 1 7 ) ( s p ) / * x17 ( a7 ) F u n c t i o n a r g u m e n t s * /
store_ x x18 , P O R T _ C O N T E X T _ x O F F S E T ( 1 8 ) ( s p ) / * x18 ( s2 ) S a v e d r e g i s t e r * /
store_ x x19 , P O R T _ C O N T E X T _ x O F F S E T ( 1 9 ) ( s p ) / * x19 ( s3 ) S a v e d r e g i s t e r * /
store_ x x20 , P O R T _ C O N T E X T _ x O F F S E T ( 2 0 ) ( s p ) / * x20 ( s4 ) S a v e d r e g i s t e r * /
store_ x x21 , P O R T _ C O N T E X T _ x O F F S E T ( 2 1 ) ( s p ) / * x21 ( s5 ) S a v e d r e g i s t e r * /
store_ x x22 , P O R T _ C O N T E X T _ x O F F S E T ( 2 2 ) ( s p ) / * x22 ( s6 ) S a v e d r e g i s t e r * /
store_ x x23 , P O R T _ C O N T E X T _ x O F F S E T ( 2 3 ) ( s p ) / * x23 ( s7 ) S a v e d r e g i s t e r * /
store_ x x24 , P O R T _ C O N T E X T _ x O F F S E T ( 2 4 ) ( s p ) / * x24 ( s8 ) S a v e d r e g i s t e r * /
store_ x x25 , P O R T _ C O N T E X T _ x O F F S E T ( 2 5 ) ( s p ) / * x25 ( s9 ) S a v e d r e g i s t e r * /
store_ x x26 , P O R T _ C O N T E X T _ x O F F S E T ( 2 6 ) ( s p ) / * x26 ( s10 ) S a v e d r e g i s t e r * /
store_ x x27 , P O R T _ C O N T E X T _ x O F F S E T ( 2 7 ) ( s p ) / * x27 ( s11 ) S a v e d r e g i s t e r * /
store_ x x28 , P O R T _ C O N T E X T _ x O F F S E T ( 2 8 ) ( s p ) / * x28 ( t 3 ) T e m p o r a r y r e g i s t e r * /
store_ x x29 , P O R T _ C O N T E X T _ x O F F S E T ( 2 9 ) ( s p ) / * x29 ( t 4 ) T e m p o r a r y r e g i s t e r * /
store_ x x30 , P O R T _ C O N T E X T _ x O F F S E T ( 3 0 ) ( s p ) / * x30 ( t 5 ) T e m p o r a r y r e g i s t e r * /
store_ x x31 , P O R T _ C O N T E X T _ x O F F S E T ( 3 1 ) ( s p ) / * x31 ( t 6 ) T e m p o r a r y r e g i s t e r * /
# endif / * _ _ r i s c v _ 3 2 e * /
/* Save mcause, mepc & mstatus state */
csrr a4 , m e p c
csrr a5 , m s t a t u s / * R e q u i r e d f o r M P I E b i t . * /
store_ x a4 , P O R T _ C O N T E X T _ m e p c O F F S E T ( s p )
store_ x a5 , P O R T _ C O N T E X T _ m s t a t u s O F F S E T ( s p )
.endm
/*-----------------------------------------------------------*/
handle_synchronous :
addi a1 , a1 , 4 / * S y n c h r o n o u s s o u p d a t e d e x c e p t i o n r e t u r n a d d r e s s t o t h e i n s t r u c t i o n a f t e r t h e i n s t r u c t i o n t h a t g e n e r a t e d t h e e x e p t i o n . * /
store_ x a1 , 0 ( s p ) / * S a v e u p d a t e d e x c e p t i o n r e t u r n a d d r e s s . * /
.macro portRESTORE_BaseReg
/* Restore mepc & mstatus state */
load_ x t 0 , P O R T _ C O N T E X T _ m e p c O F F S E T ( s p )
load_ x t 1 , P O R T _ C O N T E X T _ m s t a t u s O F F S E T ( s p )
csrw m e p c , t 0
csrw m s t a t u s , t 1
load_ x x1 , P O R T _ C O N T E X T _ x O F F S E T ( 1 ) ( s p ) / * x1 ( r a ) R e t u r n a d d r e s s * /
/* x2(sp) ***** Should be save ouside this macro */
load_ x x3 , P O R T _ C O N T E X T _ x O F F S E T ( 3 ) ( s p ) / * x3 ( g p ) G l o b a l p o i n t e r * /
load_ x x4 , P O R T _ C O N T E X T _ x O F F S E T ( 4 ) ( s p ) / * x4 ( t p ) T h r e a d p o i n t e r * /
load_ x x5 , P O R T _ C O N T E X T _ x O F F S E T ( 5 ) ( s p ) / * x5 ( t 0 ) T e m p o r a r y r e g i s t e r * /
load_ x x6 , P O R T _ C O N T E X T _ x O F F S E T ( 6 ) ( s p ) / * x6 ( t 1 ) T e m p o r a r y r e g i s t e r * /
load_ x x7 , P O R T _ C O N T E X T _ x O F F S E T ( 7 ) ( s p ) / * x7 ( t 2 ) T e m p o r a r y r e g i s t e r * /
load_ x x8 , P O R T _ C O N T E X T _ x O F F S E T ( 8 ) ( s p ) / * x8 ( s0 / f p ) S a v e d r e g i s t e r / F r a m e p o i n t e r * /
load_ x x9 , P O R T _ C O N T E X T _ x O F F S E T ( 9 ) ( s p ) / * x9 ( s1 ) S a v e d r e g i s t e r * /
load_ x x10 , P O R T _ C O N T E X T _ x O F F S E T ( 1 0 ) ( s p ) / * x10 ( a0 ) F u n c t i o n a r g u m e n t * /
load_ x x11 , P O R T _ C O N T E X T _ x O F F S E T ( 1 1 ) ( s p ) / * x11 ( a1 ) F u n c t i o n a r g u m e n t * /
load_ x x12 , P O R T _ C O N T E X T _ x O F F S E T ( 1 2 ) ( s p ) / * x12 ( a2 ) F u n c t i o n a r g u m e n t * /
load_ x x13 , P O R T _ C O N T E X T _ x O F F S E T ( 1 3 ) ( s p ) / * x13 ( a3 ) F u n c t i o n a r g u m e n t * /
load_ x x14 , P O R T _ C O N T E X T _ x O F F S E T ( 1 4 ) ( s p ) / * x14 ( a4 ) F u n c t i o n a r g u m e n t * /
load_ x x15 , P O R T _ C O N T E X T _ x O F F S E T ( 1 5 ) ( s p ) / * x15 ( a5 ) F u n c t i o n a r g u m e n t * /
# ifndef _ _ r i s c v _ 3 2 e
load_ x x16 , P O R T _ C O N T E X T _ x O F F S E T ( 1 6 ) ( s p ) / * x16 ( a6 ) F u n c t i o n a r g u m e n t s * /
load_ x x17 , P O R T _ C O N T E X T _ x O F F S E T ( 1 7 ) ( s p ) / * x17 ( a7 ) F u n c t i o n a r g u m e n t s * /
load_ x x18 , P O R T _ C O N T E X T _ x O F F S E T ( 1 8 ) ( s p ) / * x18 ( s2 ) S a v e d r e g i s t e r * /
load_ x x19 , P O R T _ C O N T E X T _ x O F F S E T ( 1 9 ) ( s p ) / * x19 ( s3 ) S a v e d r e g i s t e r * /
load_ x x20 , P O R T _ C O N T E X T _ x O F F S E T ( 2 0 ) ( s p ) / * x20 ( s4 ) S a v e d r e g i s t e r * /
load_ x x21 , P O R T _ C O N T E X T _ x O F F S E T ( 2 1 ) ( s p ) / * x21 ( s5 ) S a v e d r e g i s t e r * /
load_ x x22 , P O R T _ C O N T E X T _ x O F F S E T ( 2 2 ) ( s p ) / * x22 ( s6 ) S a v e d r e g i s t e r * /
load_ x x23 , P O R T _ C O N T E X T _ x O F F S E T ( 2 3 ) ( s p ) / * x23 ( s7 ) S a v e d r e g i s t e r * /
load_ x x24 , P O R T _ C O N T E X T _ x O F F S E T ( 2 4 ) ( s p ) / * x24 ( s8 ) S a v e d r e g i s t e r * /
load_ x x25 , P O R T _ C O N T E X T _ x O F F S E T ( 2 5 ) ( s p ) / * x25 ( s9 ) S a v e d r e g i s t e r * /
load_ x x26 , P O R T _ C O N T E X T _ x O F F S E T ( 2 6 ) ( s p ) / * x26 ( s10 ) S a v e d r e g i s t e r * /
load_ x x27 , P O R T _ C O N T E X T _ x O F F S E T ( 2 7 ) ( s p ) / * x27 ( s11 ) S a v e d r e g i s t e r * /
load_ x x28 , P O R T _ C O N T E X T _ x O F F S E T ( 2 8 ) ( s p ) / * x28 ( t 3 ) T e m p o r a r y r e g i s t e r * /
load_ x x29 , P O R T _ C O N T E X T _ x O F F S E T ( 2 9 ) ( s p ) / * x29 ( t 4 ) T e m p o r a r y r e g i s t e r * /
load_ x x30 , P O R T _ C O N T E X T _ x O F F S E T ( 3 0 ) ( s p ) / * x30 ( t 5 ) T e m p o r a r y r e g i s t e r * /
load_ x x31 , P O R T _ C O N T E X T _ x O F F S E T ( 3 1 ) ( s p ) / * x31 ( t 6 ) T e m p o r a r y r e g i s t e r * /
# endif / * _ _ r i s c v _ 3 2 e * /
.endm
/*-----------------------------------------------------------*/
test_if_environment_call :
li t 0 , 1 1 / * 1 1 = = e n v i r o n m e n t c a l l . * /
bne a0 , t 0 , i s _ e x c e p t i o n / * N o t a n M e n v i r o n m e n t c a l l , s o s o m e o t h e r e x c e p t i o n . * /
load_ x s p , x I S R S t a c k T o p / * S w i t c h t o I S R s t a c k b e f o r e f u n c t i o n c a l l . * /
jal v T a s k S w i t c h C o n t e x t
j p r o c e s s e d _ s o u r c e
.align 8
.func
freertos_risc_v_trap_handler :
/ * We d o n o t k n o w i f t h i s i s a n A S Y N C o r S Y N C
* If A S Y N C , i t i s a n o r m a l i n t e r r u p t
* and t h e s t a c k p o i n t e r i s a s s u m e d g o o d .
* else ( S Y N C )
* We c o u l d b e h e r e d u e t o a b u s f a u l t .
* /
csrw m s c r a t c h , t 0
csrr t 0 , m c a u s e
blt t 0 , x0 , h a n d l e _ i n t e r r u p t
handle_exception :
/ * mscratch = o l d t 0
* t0 = m c a u s e
* mcause = s m a l l n u m b e r 0 . . 1 6
* 0 Instruction a d d r e s s m i s a l i g n e d
* 1 Instruction a c c e s s f a u l t
* 2 Illegal i n s t r u c t i o n
* 3 Breakpoint
* 4 Load a d d r e s s m i s a l i g n e d
* 5 Load a c c e s s f a u l t
* 6 Store/ A M O a d d r e s s m i s a l i g n e d
* 7 Store/ A M O a c c e s s f a u l t
* 8 Environment c a l l f r o m U - m o d e
* 9 Environment c a l l f r o m S - m o d e
* 1 0 Reserved
* 1 1 Environment c a l l f r o m M - m o d e
* 1 2 Instruction p a g e f a u l t
* 1 3 Load p a g e f a u l t
* 1 4 Reserved
* 1 5 Store/ A M O p a g e f a u l t
* ≥ 1 6 Reserved
*
* if( m c a u s e b e t w e e n 8 a n d 1 1 ) w e a r e g o o d - e c a l l
* else : problem
* /
addi t 0 , t 0 , - 8
blt t 0 , x0 , i s _ e x c e p t i o n / * m c a u s e < 8 , m u s t b e f a u l t * /
addi t 0 , t 0 , - 4
blt t 0 , x0 , e c a l l _ y i e l d
is_exception :
csrr t 0 , m c a u s e / * F o r v i e w i n g i n t h e d e b u g g e r o n l y . * /
csrr t 1 , m e p c / * F o r v i e w i n g i n t h e d e b u g g e r o n l y * /
csrr t 2 , m s t a t u s
j i s _ e x c e p t i o n / * N o o t h e r e x c e p t i o n s h a n d l e d y e t . * /
as_yet_unhandled :
csrr t 0 , m c a u s e / * F o r v i e w i n g i n t h e d e b u g g e r o n l y . * /
j a s _ y e t _ u n h a n d l e d
processed_source :
load_ x t 1 , p x C u r r e n t T C B / * L o a d p x C u r r e n t T C B . * /
load_ x s p , 0 ( t 1 ) / * R e a d s p f r o m f i r s t T C B m e m b e r . * /
/* Load mret with the address of the next instruction in the task to run next. */
load_ x t 0 , 0 ( s p )
csrw m e p c , t 0
portasmRESTORE_ A D D I T I O N A L _ R E G I S T E R S / * D e f i n e d i n f r e e r t o s _ r i s c _ v _ c h i p _ s p e c i f i c _ e x t e n s i o n s . h t o r e s t o r e a n y r e g i s t e r s u n i q u e t o t h e R I S C - V i m p l e m e n t a t i o n . * /
/* Load mstatus with the interrupt enable bits used by the task. */
load_ x t 0 , 2 9 * p o r t W O R D _ S I Z E ( s p )
csrw m s t a t u s , t 0 / * R e q u i r e d f o r M P I E b i t . * /
load_ x x1 , 1 * p o r t W O R D _ S I Z E ( s p )
load_ x x5 , 2 * p o r t W O R D _ S I Z E ( s p ) / * t 0 * /
load_ x x6 , 3 * p o r t W O R D _ S I Z E ( s p ) / * t 1 * /
load_ x x7 , 4 * p o r t W O R D _ S I Z E ( s p ) / * t 2 * /
load_ x x8 , 5 * p o r t W O R D _ S I Z E ( s p ) / * s0 / f p * /
load_ x x9 , 6 * p o r t W O R D _ S I Z E ( s p ) / * s1 * /
load_ x x10 , 7 * p o r t W O R D _ S I Z E ( s p ) / * a0 * /
load_ x x11 , 8 * p o r t W O R D _ S I Z E ( s p ) / * a1 * /
load_ x x12 , 9 * p o r t W O R D _ S I Z E ( s p ) / * a2 * /
load_ x x13 , 1 0 * p o r t W O R D _ S I Z E ( s p ) / * a3 * /
load_ x x14 , 1 1 * p o r t W O R D _ S I Z E ( s p ) / * a4 * /
load_ x x15 , 1 2 * p o r t W O R D _ S I Z E ( s p ) / * a5 * /
load_ x x16 , 1 3 * p o r t W O R D _ S I Z E ( s p ) / * a6 * /
load_ x x17 , 1 4 * p o r t W O R D _ S I Z E ( s p ) / * a7 * /
load_ x x18 , 1 5 * p o r t W O R D _ S I Z E ( s p ) / * s2 * /
load_ x x19 , 1 6 * p o r t W O R D _ S I Z E ( s p ) / * s3 * /
load_ x x20 , 1 7 * p o r t W O R D _ S I Z E ( s p ) / * s4 * /
load_ x x21 , 1 8 * p o r t W O R D _ S I Z E ( s p ) / * s5 * /
load_ x x22 , 1 9 * p o r t W O R D _ S I Z E ( s p ) / * s6 * /
load_ x x23 , 2 0 * p o r t W O R D _ S I Z E ( s p ) / * s7 * /
load_ x x24 , 2 1 * p o r t W O R D _ S I Z E ( s p ) / * s8 * /
load_ x x25 , 2 2 * p o r t W O R D _ S I Z E ( s p ) / * s9 * /
load_ x x26 , 2 3 * p o r t W O R D _ S I Z E ( s p ) / * s10 * /
load_ x x27 , 2 4 * p o r t W O R D _ S I Z E ( s p ) / * s11 * /
load_ x x28 , 2 5 * p o r t W O R D _ S I Z E ( s p ) / * t 3 * /
load_ x x29 , 2 6 * p o r t W O R D _ S I Z E ( s p ) / * t 4 * /
load_ x x30 , 2 7 * p o r t W O R D _ S I Z E ( s p ) / * t 5 * /
load_ x x31 , 2 8 * p o r t W O R D _ S I Z E ( s p ) / * t 6 * /
addi s p , s p , p o r t C O N T E X T _ S I Z E
/* restore t0 and save sp in mscratch. */
csrr t 0 , m s c r a t c h
csrw m s c r a t c h , s p
/* Switch to ISR stack before function call. */
load_ x s p , x I S R S t a c k T o p
portSAVE_ B a s e R e g
csrrw t 0 , m s c r a t c h , t 0
/* SP = X2, so save it */
store_ x t 0 , P O R T _ C O N T E X T _ x O F F S E T ( 2 ) ( s p )
/* Defined in freertos_risc_v_chip_specific_extensions.h to save any registers unique to the RISC-V implementation. */
portasmSAVE_ A D D I T I O N A L _ R E G I S T E R S
/* Save any fpu registers */
portSAVE_ F p u R e g
/* Execption is treated by external function */
jal p o r t H A N D L E _ E X C E P T I O N
/* in case that the go back from exception, restore registers */
portRESTORE_ F p u R e g
portasmRESTORE_ A D D I T I O N A L _ R E G I S T E R S
portRESTORE_ B a s e R e g
load_ x x2 , P O R T _ C O N T E X T _ x O F F S E T ( 2 ) ( s p )
mret
ecall_yield :
portSAVE_ B a s e R e g
/ * a4 = m e p c
* a5 = m s t a t u s
* s0 w i l l b e u s e f o r p x C u r r e n t T C B
* s1 w i l l b e u s e t o s a v e s p
* /
/* Synchronous so updated exception return address to the instruction after the instruction that generated the exeption. */
addi t 0 , a4 , 4
store_ x t 0 , P O R T _ C O N T E X T _ m e p c O F F S E T ( s p )
/* Store the value of sp when the interrupt occur */
addi t 0 , s p , p o r t a s m R E G I S T E R _ C O N T E X T _ W O R D S I Z E
store_ x t 0 , P O R T _ C O N T E X T _ x O F F S E T ( 2 ) ( s p )
/* Defined in freertos_risc_v_chip_specific_extensions.h to save any registers unique to the RISC-V implementation. */
portasmSAVE_ A D D I T I O N A L _ R E G I S T E R S
/* Save any fpu registers */
portSAVE_ F p u R e g
/* Load pxCurrentTCB and update first TCB member(pxTopOfStack) with sp. */
load_ x s0 , p x C u r r e n t T C B
store_ x s p , 0 ( s0 )
/* Save sp into s1 */
mv s1 , s p
load_ x s p , x I S R S t a c k T o p / * S w i t c h t o I S R s t a c k b e f o r e f u n c t i o n c a l l . * /
j s w i t c h _ c o n t e x t
handle_interrupt :
portSAVE_ B a s e R e g
/ * a4 = m e p c
* a5 = m s t a t u s
* s0 w i l l b e u s e f o r p x C u r r e n t T C B
* s1 w i l l b e u s e t o s a v e s p
* /
/* Store the value of sp when the interrupt occur */
addi t 0 , s p , p o r t a s m R E G I S T E R _ C O N T E X T _ W O R D S I Z E
store_ x t 0 , P O R T _ C O N T E X T _ x O F F S E T ( 2 ) ( s p )
/* Defined in freertos_risc_v_chip_specific_extensions.h to save any registers unique to the RISC-V implementation. */
portasmSAVE_ A D D I T I O N A L _ R E G I S T E R S
/* Save any fpu registers */
portSAVE_ F p u R e g
/* Load pxCurrentTCB and update first TCB member(pxTopOfStack) with sp. */
load_ x s0 , p x C u r r e n t T C B
store_ x s p , 0 ( s0 )
/* Save sp into s1 */
mv s1 , s p
load_ x s p , x I S R S t a c k T o p / * S w i t c h t o I S R s t a c k b e f o r e f u n c t i o n c a l l . * /
# if( p o r t a s m H A S _ M T I M E ! = 0 )
addi t 0 , x0 , 1
slli t 0 , t 0 , _ _ r i s c v _ x l e n - 1 / * L S B i s a l r e a d y s e t , s h i f t i n t o M S B . S h i f t 3 1 o n 3 2 - b i t o r 6 3 o n 6 4 - b i t c o r e s . * /
addi t 1 , t 0 , 7 / * 0 x80 0 0 [ ] 0 0 0 7 = = m a c h i n e t i m e r i n t e r r u p t . * /
csrr t 2 , m c a u s e
bne t 2 , t 1 , t e s t _ i f _ e x t e r n a l _ i n t e r r u p t
load_ x t 0 , p u l l M a c h i n e T i m e r C o m p a r e R e g i s t e r / * L o a d a d d r e s s o f c o m p a r e r e g i s t e r i n t o t 0 . * /
load_ x t 1 , p u l l N e x t T i m e / * L o a d t h e a d d r e s s o f u l l N e x t T i m e i n t o t 1 . * /
# if( _ _ r i s c v _ x l e n = = 3 2 )
/* Update the 64-bit mtimer compare match value in two 32-bit writes. */
lw a0 , 0 ( t 1 ) / * L o a d t h e l o w w o r d o f u l l N e x t T i m e i n t o a0 . * /
lw a1 , 4 ( t 1 ) / * L o a d t h e h i g h w o r d o f u l l N e x t T i m e i n t o a1 . * /
li t 2 , - 1
sw t 2 , 4 ( t 0 ) / * S t o r e l o w w o r d o f u l l N e x t T i m e i n t o c o m p a r e r e g i s t e r . * /
sw a0 , 0 ( t 0 ) / * S t o r e l o w w o r d o f u l l N e x t T i m e i n t o c o m p a r e r e g i s t e r . * /
sw a1 , 4 ( t 0 ) / * S t o r e h i g h w o r d o f u l l N e x t T i m e i n t o c o m p a r e r e g i s t e r . * /
lw t 0 , u x T i m e r I n c r e m e n t s F o r O n e T i c k / * L o a d t h e v a l u e o f u l l T i m e r I n c r e m e n t F o r O n e T i c k i n t o t 0 ( c o u l d t h i s b e o p t i m i z e d b y s t o r i n g i n a n a r r a y n e x t t o p u l l N e x t T i m e ? ) . * /
add a2 , t 0 , a0 / * A d d t h e l o w w o r d o f u l l N e x t T i m e t o t h e t i m e r i n c r e m e n t s f o r o n e t i c k ( a s s u m e s t i m e r i n c r e m e n t f o r o n e t i c k f i t s i n 3 2 - b i t s ) . * /
sltu t 2 , a2 , a0 / * S e e i f t h e s u m o f l o w w o r d s o v e r f l o w e d ( w h a t a b o u t t h e z e r o c a s e ? ) . * /
add a3 , a1 , t 2 / * A d d o v e r f l o w t o h i g h w o r d o f u l l N e x t T i m e . * /
sw a2 , 0 ( t 1 ) / * S t o r e n e w l o w w o r d o f u l l N e x t T i m e . * /
sw a3 , 4 ( t 1 ) / * S t o r e n e w h i g h w o r d o f u l l N e x t T i m e . * /
# endif / * ( _ _ r i s c v _ x l e n = = 3 2 ) * /
# if( _ _ r i s c v _ x l e n = = 6 4 )
/* Update the 64-bit mtimer compare match value. */
ld a0 , 0 ( t 1 ) / * L o a d u l l N e x t T i m e i n t o a0 . * /
sd a0 , 0 ( t 0 ) / * S t o r e u l l N e x t T i m e i n t o c o m p a r e r e g i s t e r . * /
ld t 0 , u x T i m e r I n c r e m e n t s F o r O n e T i c k / * L o a d t h e v a l u e o f u l l T i m e r I n c r e m e n t F o r O n e T i c k i n t o t 0 ( c o u l d t h i s b e o p t i m i z e d b y s t o r i n g i n a n a r r a y n e x t t o p u l l N e x t T i m e ? ) . * /
add a2 , t 0 , a0 / * A d d u l l N e x t T i m e t o t h e t i m e r i n c r e m e n t s f o r o n e t i c k . * /
sd a2 , 0 ( t 1 ) / * S t o r e u l l N e x t T i m e . * /
# endif / * ( _ _ r i s c v _ x l e n = = 6 4 ) * /
jal x T a s k I n c r e m e n t T i c k
beqz a0 , r e s t o r e _ b e f o r e _ e x i t / * D o n ' t s w i t c h c o n t e x t i f i n c r e m e n t i n g t i c k d i d n ' t u n b l o c k a t a s k . * /
j s w i t c h _ c o n t e x t
restore_before_exit :
mv s p , s1
j e n d _ t r a p _ h a n d l e r
test_if_external_interrupt : /* If there is a CLINT and the mtimer interrupt is not pending then check to see if an external interrupt is pending. */
addi t 1 , t 1 , 4 / * 0 x80 0 0 0 0 0 7 + 4 = 0 x80 0 0 0 0 0 b = = M a c h i n e e x t e r n a l i n t e r r u p t . * /
csrr t 2 , m c a u s e
bne t 2 , t 1 , u n r e c o v e r a b l e _ e r r o r / * S o m e t h i n g a s y e t u n h a n d l e d . * /
j u n r e c o v e r a b l e _ e r r o r
# endif / * ( p o r t a s m H A S _ M T I M E ! = 0 ) * /
external_interrupt :
/* Switch to ISR stack before function call. */
load_ x s p , x I S R S t a c k T o p
jal p o r t H A N D L E _ I N T E R R U P T
mv s p , s1
j e n d _ t r a p _ h a n d l e r
unrecoverable_error :
csrr t 0 , m c a u s e / * F o r v i e w i n g i n t h e d e b u g g e r o n l y . * /
csrr t 1 , m e p c / * F o r v i e w i n g i n t h e d e b u g g e r o n l y . * /
csrr t 2 , m s t a t u s
wfi
j u n r e c o v e r a b l e _ e r r o r
switch_context :
jal v T a s k S w i t c h C o n t e x t
load_ x s0 , p x C u r r e n t T C B / * L o a d p x C u r r e n t T C B . * /
load_ x s p , 0 ( s0 ) / * R e a d s p f r o m f i r s t T C B m e m b e r . * /
end_trap_handler :
load_ x s0 , p x C u r r e n t T C B / * L o a d p x C u r r e n t T C B . * /
load_ x t 1 , P O R T _ C O N T E X T _ x O F F S E T ( 2 ) ( s p )
store_ x t 1 , 0 ( s0 ) / * W r i t e s p s a v e d v a l u e t o f i r s t T C B m e m b e r . * /
/* restore registers */
portRESTORE_ F p u R e g
portasmRESTORE_ A D D I T I O N A L _ R E G I S T E R S
portRESTORE_ B a s e R e g
load_ x x2 , P O R T _ C O N T E X T _ x O F F S E T ( 2 ) ( s p )
mret
.endfunc
/*-----------------------------------------------------------*/
@ -304,49 +608,37 @@ xPortStartFirstTask:
outside o f t h i s f i l e . * /
la t 0 , f r e e r t o s _ r i s c _ v _ t r a p _ h a n d l e r
csrw m t v e c , t 0
# endif / * p o r t a s m H A S _ C L I L N T * /
load_ x s p , p x C u r r e n t T C B / * L o a d p x C u r r e n t T C B . * /
load_ x s p , 0 ( s p ) / * R e a d s p f r o m f i r s t T C B m e m b e r . * /
load_ x x1 , 0 ( s p ) / * N o t e f o r s t a r t i n g t h e s c h e d u l e r t h e e x c e p t i o n r e t u r n a d d r e s s i s u s e d a s t h e f u n c t i o n r e t u r n a d d r e s s . * /
portasmRESTORE_ A D D I T I O N A L _ R E G I S T E R S / * D e f i n e d i n f r e e r t o s _ r i s c _ v _ c h i p _ s p e c i f i c _ e x t e n s i o n s . h t o r e s t o r e a n y r e g i s t e r s u n i q u e t o t h e R I S C - V i m p l e m e n t a t i o n . * /
load_ x x6 , 3 * p o r t W O R D _ S I Z E ( s p ) / * t 1 * /
load_ x x7 , 4 * p o r t W O R D _ S I Z E ( s p ) / * t 2 * /
load_ x x8 , 5 * p o r t W O R D _ S I Z E ( s p ) / * s0 / f p * /
load_ x x9 , 6 * p o r t W O R D _ S I Z E ( s p ) / * s1 * /
load_ x x10 , 7 * p o r t W O R D _ S I Z E ( s p ) / * a0 * /
load_ x x11 , 8 * p o r t W O R D _ S I Z E ( s p ) / * a1 * /
load_ x x12 , 9 * p o r t W O R D _ S I Z E ( s p ) / * a2 * /
load_ x x13 , 1 0 * p o r t W O R D _ S I Z E ( s p ) / * a3 * /
load_ x x14 , 1 1 * p o r t W O R D _ S I Z E ( s p ) / * a4 * /
load_ x x15 , 1 2 * p o r t W O R D _ S I Z E ( s p ) / * a5 * /
load_ x x16 , 1 3 * p o r t W O R D _ S I Z E ( s p ) / * a6 * /
load_ x x17 , 1 4 * p o r t W O R D _ S I Z E ( s p ) / * a7 * /
load_ x x18 , 1 5 * p o r t W O R D _ S I Z E ( s p ) / * s2 * /
load_ x x19 , 1 6 * p o r t W O R D _ S I Z E ( s p ) / * s3 * /
load_ x x20 , 1 7 * p o r t W O R D _ S I Z E ( s p ) / * s4 * /
load_ x x21 , 1 8 * p o r t W O R D _ S I Z E ( s p ) / * s5 * /
load_ x x22 , 1 9 * p o r t W O R D _ S I Z E ( s p ) / * s6 * /
load_ x x23 , 2 0 * p o r t W O R D _ S I Z E ( s p ) / * s7 * /
load_ x x24 , 2 1 * p o r t W O R D _ S I Z E ( s p ) / * s8 * /
load_ x x25 , 2 2 * p o r t W O R D _ S I Z E ( s p ) / * s9 * /
load_ x x26 , 2 3 * p o r t W O R D _ S I Z E ( s p ) / * s10 * /
load_ x x27 , 2 4 * p o r t W O R D _ S I Z E ( s p ) / * s11 * /
load_ x x28 , 2 5 * p o r t W O R D _ S I Z E ( s p ) / * t 3 * /
load_ x x29 , 2 6 * p o r t W O R D _ S I Z E ( s p ) / * t 4 * /
load_ x x30 , 2 7 * p o r t W O R D _ S I Z E ( s p ) / * t 5 * /
load_ x x31 , 2 8 * p o r t W O R D _ S I Z E ( s p ) / * t 6 * /
load_ x x5 , 2 9 * p o r t W O R D _ S I Z E ( s p ) / * I n i t i a l m s t a t u s i n t o x5 ( t 0 ) * /
addi x5 , x5 , 0 x08 / * S e t M I E b i t s o t h e f i r s t t a s k s t a r t s w i t h i n t e r r u p t s e n a b l e d - r e q u i r e d a s r e t u r n s w i t h r e t n o t e r e t . * /
csrrw x0 , m s t a t u s , x5 / * I n t e r r u p t s e n a b l e d f r o m h e r e ! * /
load_ x x5 , 2 * p o r t W O R D _ S I Z E ( s p ) / * I n i t i a l x5 ( t 0 ) v a l u e . * /
addi s p , s p , p o r t C O N T E X T _ S I Z E
ret
# endif / * ( p o r t a s m H A S _ S I F I V E _ C L I N T ! = 0 ) * /
/** Set all register to the FirstTask context */
load_ x t 2 , p x C u r r e n t T C B / * L o a d p x C u r r e n t T C B . * /
load_ x s p , 0 ( t 2 ) / * R e a d s p f r o m f i r s t T C B m e m b e r . * /
/* Restore first TCB member */
load_ x t 1 , P O R T _ C O N T E X T _ x O F F S E T ( 2 ) ( s p )
store_ x t 1 , 0 ( t 2 ) / * W r i t e s p s a v e d v a l u e t o f i r s t T C B m e m b e r . * /
/* enable interrupt */
# if( p o r t a s m H A S _ M T I M E ! = 0 )
li t 0 , 0 x88 0
csrs m i e , t 0
# else
li t 0 , 0 x80 0
csrs m i e , t 0
# endif / * ( p o r t a s m H A S _ M T I M E ! = 0 ) * /
portRESTORE_ F p u R e g
portasmRESTORE_ A D D I T I O N A L _ R E G I S T E R S
/* Set MIE bit so the first task starts with interrupts enabled - required as returns with ret not eret. */
load_ x t 1 , P O R T _ C O N T E X T _ m s t a t u s O F F S E T ( s p )
addi t 1 , t 1 , 0 x08
store_ x t 1 , P O R T _ C O N T E X T _ m s t a t u s O F F S E T ( s p )
portRESTORE_ B a s e R e g
load_ x r a , P O R T _ C O N T E X T _ m e p c O F F S E T ( s p ) / * N o t e f o r s t a r t i n g t h e s c h e d u l e r t h e e x c e p t i o n r e t u r n a d d r e s s i s u s e d a s t h e f u n c t i o n r e t u r n a d d r e s s . * /
load_ x x2 , P O R T _ C O N T E X T _ x O F F S E T ( 2 ) ( s p )
mret
.endfunc
/*-----------------------------------------------------------*/
@ -360,7 +652,7 @@ xPortStartFirstTask:
* a1 , a n d p v P a r a m e t e r s i n a2 . T h e n e w t o p o f s t a c k i s p a s s e d o u t i n a0 .
*
* RISC- V m a p s r e g i s t e r s t o A B I n a m e s a s f o l l o w s ( X 1 t o X 3 1 i n t e g e r r e g i s t e r s
* for t h e ' I ' p r o f i l e , X 1 t o X 1 5 f o r t h e ' E ' p r o f i l e , c u r r e n t l y I a s s u m e d ) .
* for t h e ' I ' p r o f i l e , X 1 t o X 1 5 f o r t h e ' E ' p r o f i l e ) .
*
* Register A B I N a m e D e s c r i p t i o n S a v e r
* x0 z e r o H a r d - w i r e d z e r o -
@ -379,36 +671,44 @@ xPortStartFirstTask:
* The R I S C - V c o n t e x t i s s a v e d t F r e e R T O S t a s k s i n t h e f o l l o w i n g s t a c k f r a m e ,
* where t h e g l o b a l a n d t h r e a d p o i n t e r s a r e c u r r e n t l y a s s u m e d t o b e c o n s t a n t s o
* are n o t s a v e d :
* The R I S C - V c o n t e x t i s s a v e d t F r e e R T O S t a s k s i n t h e f o l l o w i n g s t a c k f r a m e :
*
* ruf ( i n o r d e r t o b e 1 6 b y t e s a l i g n e d )
* ruf ( i n o r d e r t o b e 1 6 b y t e s a l i g n e d )
* pxCode - m e p c
* mstatus
* x3 1
* x3 0
* x2 9
* x2 8
* x2 7
* x2 6
* x2 5
* x2 4
* x2 3
* x2 2
* x2 1
* x2 0
* x1 9
* x1 8
* x1 7
* x1 6
* x3 1 ( O n l y f o r ' I ' p r o f i l e )
* x3 0 ( O n l y f o r ' I ' p r o f i l e )
* x2 9 ( O n l y f o r ' I ' p r o f i l e )
* x2 8 ( O n l y f o r ' I ' p r o f i l e )
* x2 7 ( O n l y f o r ' I ' p r o f i l e )
* x2 6 ( O n l y f o r ' I ' p r o f i l e )
* x2 5 ( O n l y f o r ' I ' p r o f i l e )
* x2 4 ( O n l y f o r ' I ' p r o f i l e )
* x2 3 ( O n l y f o r ' I ' p r o f i l e )
* x2 2 ( O n l y f o r ' I ' p r o f i l e )
* x2 1 ( O n l y f o r ' I ' p r o f i l e )
* x2 0 ( O n l y f o r ' I ' p r o f i l e )
* x1 9 ( O n l y f o r ' I ' p r o f i l e )
* x1 8 ( O n l y f o r ' I ' p r o f i l e )
* x1 7 ( O n l y f o r ' I ' p r o f i l e )
* x1 6 ( O n l y f o r ' I ' p r o f i l e )
* x1 5
* x1 4
* x1 3
* x1 2
* x1 1
* pvParameters
* pvParameters - x10 ( a0 )
* x9
* x8
* x7
* x6
* x5
* portTASK_ R E T U R N _ A D D R E S S
* x4 ( t p )
* x3 ( g p )
* x2 ( s p )
* portTASK_ R E T U R N _ A D D R E S S - x1 ( r a )
* x0
* [ chip s p e c i f i c r e g i s t e r s g o h e r e ]
* pxCode
* /
@ -420,24 +720,75 @@ pxPortInitialiseStack:
andi t 0 , t 0 , ~ 0 x8 / * E n s u r e i n t e r r u p t s a r e d i s a b l e d w h e n t h e s t a c k i s r e s t o r e d w i t h i n a n I S R . R e q u i r e d w h e n a t a s k i s c r e a t e d a f t e r t h e s c h e d u l r e h a s b e e n s t a r t e d , o t h e r w i s e i n t e r r u p t s w o u l d b e d i s a b l e d a n y w a y . * /
addi t 1 , x0 , 0 x18 8 / * G e n e r a t e t h e v a l u e 0 x18 8 0 , w h i c h a r e t h e M P I E a n d M P P b i t s t o s e t i n m s t a t u s . * /
slli t 1 , t 1 , 4
not t 2 , t 1 / * r e s e t p r e v i o u s v a l u e * /
and t 0 , t 0 , t 2
or t 0 , t 0 , t 1 / * S e t M P I E a n d M P P b i t s i n m s t a t u s v a l u e . * /
addi a0 , a0 , - p o r t W O R D _ S I Z E
store_ x t 0 , 0 ( a0 ) / * m s t a t u s o n t o t h e s t a c k . * /
addi a0 , a0 , - ( 2 2 * p o r t W O R D _ S I Z E ) / * S p a c e f o r r e g i s t e r s x11 - x31 . * /
store_ x a2 , 0 ( a0 ) / * T a s k p a r a m e t e r s ( p v P a r a m e t e r s p a r a m e t e r ) g o e s i n t o r e g i s t e r X 1 0 / a0 o n t h e s t a c k . * /
addi a0 , a0 , - ( 6 * p o r t W O R D _ S I Z E ) / * S p a c e f o r r e g i s t e r s x5 - x9 . * /
store_ x x0 , 0 ( a0 ) / * R e t u r n a d d r e s s o n t o t h e s t a c k , c o u l d b e p o r t T A S K _ R E T U R N _ A D D R E S S * /
addi t 0 , x0 , p o r t a s m A D D I T I O N A L _ C O N T E X T _ S I Z E / * T h e n u m b e r o f c h i p s p e c i f i c a d d i t i o n a l r e g i s t e r s . * /
/* Make room for the registers. */
addi t 2 , a0 , - p o r t a s m R E G I S T E R _ C O N T E X T _ W O R D S I Z E
store_ x x0 , P O R T _ C O N T E X T _ x O F F S E T ( 1 ) ( t 2 ) / * x1 ( r a ) R e t u r n a d d r e s s * /
store_ x a0 , P O R T _ C O N T E X T _ x O F F S E T ( 2 ) ( t 2 ) / * x2 ( s p ) S t a c k p o i n t e r * /
store_ x x3 , P O R T _ C O N T E X T _ x O F F S E T ( 3 ) ( t 2 ) / * x3 ( g p ) G l o b a l p o i n t e r * /
store_ x x4 , P O R T _ C O N T E X T _ x O F F S E T ( 4 ) ( t 2 ) / * x4 ( t p ) T h r e a d p o i n t e r * /
store_ x x0 , P O R T _ C O N T E X T _ x O F F S E T ( 5 ) ( t 2 ) / * x5 ( t 0 ) T e m p o r a r i e s * /
store_ x x0 , P O R T _ C O N T E X T _ x O F F S E T ( 6 ) ( t 2 ) / * x6 ( t 1 ) T e m p o r a r i e s * /
store_ x x0 , P O R T _ C O N T E X T _ x O F F S E T ( 7 ) ( t 2 ) / * x7 ( t 2 ) T e m p o r a r i e s * /
store_ x x0 , P O R T _ C O N T E X T _ x O F F S E T ( 8 ) ( t 2 ) / * x8 ( s0 / f p ) S a v e d r e g i s t e r / F r a m e p o i n t e r * /
store_ x x0 , P O R T _ C O N T E X T _ x O F F S E T ( 9 ) ( t 2 ) / * x9 ( s1 ) S a v e d r e g i s t e r * /
store_ x a2 , P O R T _ C O N T E X T _ x O F F S E T ( 1 0 ) ( t 2 ) / * x10 ( a0 ) F u n c t i o n a r g u m e n t s * /
store_ x x0 , P O R T _ C O N T E X T _ x O F F S E T ( 1 1 ) ( t 2 ) / * x11 ( a1 ) F u n c t i o n a r g u m e n t s * /
store_ x x0 , P O R T _ C O N T E X T _ x O F F S E T ( 1 2 ) ( t 2 ) / * x12 ( a2 ) F u n c t i o n a r g u m e n t s * /
store_ x x0 , P O R T _ C O N T E X T _ x O F F S E T ( 1 3 ) ( t 2 ) / * x13 ( a3 ) F u n c t i o n a r g u m e n t s * /
store_ x x0 , P O R T _ C O N T E X T _ x O F F S E T ( 1 4 ) ( t 2 ) / * x14 ( a4 ) F u n c t i o n a r g u m e n t s * /
store_ x x0 , P O R T _ C O N T E X T _ x O F F S E T ( 1 5 ) ( t 2 ) / * x15 ( a5 ) F u n c t i o n a r g u m e n t s * /
# ifndef _ _ r i s c v _ 3 2 e
store_ x x0 , P O R T _ C O N T E X T _ x O F F S E T ( 1 6 ) ( t 2 ) / * x16 ( a6 ) F u n c t i o n a r g u m e n t s * /
store_ x x0 , P O R T _ C O N T E X T _ x O F F S E T ( 1 7 ) ( t 2 ) / * x17 ( a7 ) F u n c t i o n a r g u m e n t s * /
store_ x x0 , P O R T _ C O N T E X T _ x O F F S E T ( 1 8 ) ( t 2 ) / * x18 ( s2 ) S a v e d r e g i s t e r s * /
store_ x x0 , P O R T _ C O N T E X T _ x O F F S E T ( 1 9 ) ( t 2 ) / * x19 ( s3 ) S a v e d r e g i s t e r s * /
store_ x x0 , P O R T _ C O N T E X T _ x O F F S E T ( 2 0 ) ( t 2 ) / * x20 ( s4 ) S a v e d r e g i s t e r s * /
store_ x x0 , P O R T _ C O N T E X T _ x O F F S E T ( 2 1 ) ( t 2 ) / * x21 ( s5 ) S a v e d r e g i s t e r s * /
store_ x x0 , P O R T _ C O N T E X T _ x O F F S E T ( 2 2 ) ( t 2 ) / * x22 ( s6 ) S a v e d r e g i s t e r s * /
store_ x x0 , P O R T _ C O N T E X T _ x O F F S E T ( 2 3 ) ( t 2 ) / * x23 ( s7 ) S a v e d r e g i s t e r s * /
store_ x x0 , P O R T _ C O N T E X T _ x O F F S E T ( 2 4 ) ( t 2 ) / * x24 ( s8 ) S a v e d r e g i s t e r s * /
store_ x x0 , P O R T _ C O N T E X T _ x O F F S E T ( 2 5 ) ( t 2 ) / * x25 ( s9 ) S a v e d r e g i s t e r s * /
store_ x x0 , P O R T _ C O N T E X T _ x O F F S E T ( 2 6 ) ( t 2 ) / * x26 ( s10 ) S a v e d r e g i s t e r s * /
store_ x x0 , P O R T _ C O N T E X T _ x O F F S E T ( 2 7 ) ( t 2 ) / * x27 ( s11 ) S a v e d r e g i s t e r s * /
store_ x x0 , P O R T _ C O N T E X T _ x O F F S E T ( 2 8 ) ( t 2 ) / * x28 ( t 3 ) T e m p o r a r i e s * /
store_ x x0 , P O R T _ C O N T E X T _ x O F F S E T ( 2 9 ) ( t 2 ) / * x29 ( t 4 ) T e m p o r a r i e s * /
store_ x x0 , P O R T _ C O N T E X T _ x O F F S E T ( 3 0 ) ( t 2 ) / * x30 ( t 5 ) T e m p o r a r i e s * /
store_ x x0 , P O R T _ C O N T E X T _ x O F F S E T ( 3 1 ) ( t 2 ) / * x31 ( t 6 ) T e m p o r a r i e s * /
# endif / * _ _ r i s c v _ 3 2 e * /
store_ x a1 , P O R T _ C O N T E X T _ m e p c O F F S E T ( t 2 )
store_ x t 0 , P O R T _ C O N T E X T _ m s t a t u s O F F S E T ( t 2 )
/* The number of additional registers. */
addi t 0 , x0 , p o r t a s m A D D I T I O N A L _ C O N T E X T _ S I Z E
chip_specific_stack_frame : /* First add any chip specific registers to the stack frame being created. */
beq t 0 , x0 , 1 f / * N o m o r e c h i p s p e c i f i c r e g i s t e r s t o s a v e . * /
addi a0 , a0 , - p o r t W O R D _ S I Z E / * M a k e s p a c e f o r c h i p s p e c i f i c r e g i s t e r . * /
store_ x x0 , 0 ( a0 ) / * G i v e t h e c h i p s p e c i f i c r e g i s t e r a n i n i t i a l v a l u e o f z e r o . * /
addi t 2 , t 2 , - p o r t W O R D _ S I Z E / * M a k e s p a c e f o r c h i p s p e c i f i c r e g i s t e r . * /
store_ x x0 , 0 ( t 2 ) / * G i v e t h e c h i p s p e c i f i c r e g i s t e r a n i n i t i a l v a l u e o f z e r o . * /
addi t 0 , t 0 , - 1 / * D e c r e m e n t t h e c o u n t o f c h i p s p e c i f i c r e g i s t e r s r e m a i n i n g . * /
j c h i p _ s p e c i f i c _ s t a c k _ f r a m e / * U n t i l n o m o r e c h i p s p e c i f i c r e g i s t e r s . * /
1 :
addi a0 , a0 , - p o r t W O R D _ S I Z E
store_ x a1 , 0 ( a0 ) / * m r e t v a l u e ( p x C o d e p a r a m e t e r ) o n t o t h e s t a c k . * /
# ifdef _ _ r i s c v _ f d i v
/* Make room for the fpu registers. */
/* Here we use the memory space needed for all fpu registers instead of using the number of fpu registers */
/* Thanks to it we usually manage any xxbits core with yybits fpu */
addi t 0 , x0 , p o r t a s m F P U _ C O N T E X T _ W O R D S I Z E
fpu_specific_stack_frame :
beq t 0 , x0 , 1 f / * N o m o r e s p a c e i s n e e d e d . * /
addi t 2 , t 2 , - p o r t W O R D _ S I Z E
store_ x x0 , 0 ( t 2 ) / * G i v e a n i n i t i a l v a l u e o f z e r o . * /
addi t 0 , t 0 , - p o r t W O R D _ S I Z E / * D e c r e m e n t t h e c o u n t s p a c e r e m a i n i n g . * /
j f p u _ s p e c i f i c _ s t a c k _ f r a m e / * U n t i l n o m o r e s p a c e i s n e e d e d . * /
1 :
# endif / * _ _ r i s c v _ f d i v * /
mv a0 , t 2
ret
.endfunc
/*-----------------------------------------------------------*/