@ -25,6 +25,15 @@
* 1 tab = = 4 s p a c e s !
* /
# if _ _ r i s c v _ x l e n = = 6 4
# error N o t i m p l e m e n t e d y e t - c h a n g e l w t o l d , a n d s w t o s d .
# define p o r t W O R D _ S I Z E 8
# elif _ _ r i s c v _ x l e n = = 3 2
# 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
/ *
* The F r e e R T O S k e r n e l ' s R I S C - V p o r t i s s p l i t b e t w e e n t h e t h e c o d e t h a t i s
* common a c r o s s a l l c u r r e n t l y s u p p o r t e d R I S C - V c h i p s ( i m p l e m e n t a t i o n s o f t h e
@ -42,7 +51,7 @@
* base s e t o f R I S C - V r e g i s t e r s . T h e r e a r e a d d i t i o n a l
* freertos_ r i s c _ v _ p o r t _ s p e c i f i c _ e x t e n s i o n s . h f i l e s f o r R I S C - V i m p l e m e n t a t i o n s
* that d o n o t i n c l u d e a s t a n d a r d C L I N T o r d o a d d t o t h e b a s e s e t o f R I S C - V
* regiters.
* regis ters.
*
* CARE M U S T B E T A K E N T O I N C L D U E T H E C O R R E C T
* freertos_ r i s c _ v _ p o r t _ 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 F O R T H E C H I P
@ -67,27 +76,6 @@ definitions. */
# error p o r t a s m H A 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 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 _ p o r t _ 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 .
# endif
# ifndef 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
/ * portasmSAVE_ A D D I T I O N A L _ R E G I S T E R S i s n o t d e f i n e d s o a s s u m e n o a d d i t i o n a l
registers n e e d t o b e s a v e d . * /
# define 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
# endif
# ifndef p o r t a s m R E S T O R E _ A D D I T I O N A L _ R E G I S T E R S
/ * portasmRESTORE_ A D D I T I O N A L _ R E G I S T E R S i s n o t d e f i n e d s o a s s u m e n o
additional r e g i s t e r s n e e d t o b e r e s t o r e d . * /
# define p o r t a s m R E S T O R E _ A D D I T I O N A L _ R E G I S T E R S
# endif
# if _ _ r i s c v _ x l e n = = 6 4
# error N o t i m p l e m e n t e d y e t - c h a n g e l w t o l d , a n d s w t o s d .
# define p o r t W O R D _ S I Z E 8
# elif _ _ r i s c v _ x l e n = = 3 2
# 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
/ * 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
@ -97,6 +85,7 @@ at the top of this file. */
.global xPortStartFirstTask
.global vFreeRTOSPortTrapHandler
.global pxPortInitialiseStack
.extern pxCurrentTCB
.extern ulPortTrapHandler
.extern vTaskSwitchContext
@ -105,11 +94,11 @@ at the top of this file. */
.extern pullNextTime
.extern ulTimerIncrementsForOneTick
.extern xISRStackTop
.extern vPortHandleInterrupt
/*-----------------------------------------------------------*/
.align 16
.align 8
.func
vFreeRTOSPortTrapHandler :
addi s p , s p , - p o r t C O N T E X T _ S I Z E
sw x1 , 1 * p o r t W O R D _ S I Z E ( s p )
@ -141,11 +130,11 @@ vFreeRTOSPortTrapHandler:
sw x30 , 2 7 * p o r t W O R D _ S I Z E ( s p )
sw x31 , 2 8 * 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 _ p o r t _ 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 . * /
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 . * /
sw 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 _ p o r t _ 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 . * /
lw 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 . * /
sw 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 . * /
@ -217,16 +206,16 @@ processed_source:
lw 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 . * /
lw 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 mret with the address of the next task. */
/* Load mret with the address of the next instruction in the task to run next . */
lw 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 _ p o r t _ 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. */
lw 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 . * /
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 _ p o r t _ 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 . * /
lw x1 , 1 * p o r t W O R D _ S I Z E ( s p )
lw x5 , 2 * p o r t W O R D _ S I Z E ( s p ) / * t 0 * /
lw x6 , 3 * p o r t W O R D _ S I Z E ( s p ) / * t 1 * /
@ -255,12 +244,14 @@ processed_source:
lw x29 , 2 6 * p o r t W O R D _ S I Z E ( s p ) / * t 4 * /
lw x30 , 2 7 * p o r t W O R D _ S I Z E ( s p ) / * t 5 * /
lw 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
addi s p , s p , p o r t C O N T E X T _ S I Z E
mret
.endfunc
/*-----------------------------------------------------------*/
.align 16
.align 8
.func
xPortStartFirstTask :
# if( p o r t a s m H A S _ C L I N T ! = 0 )
@ -275,6 +266,12 @@ xPortStartFirstTask:
lw 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 . * /
lw 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 _ p o r t _ 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 . * /
lw t 0 , 2 9 * p o r t W O R D _ S I Z E ( s p ) / * m s t a t u s * /
csrrw x0 , m s t a t u s , t 0 / * 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 ! * /
lw x5 , 2 * p o r t W O R D _ S I Z E ( s p ) / * t 0 * /
lw x6 , 3 * p o r t W O R D _ S I Z E ( s p ) / * t 1 * /
lw x7 , 4 * p o r t W O R D _ S I Z E ( s p ) / * t 2 * /
@ -303,8 +300,98 @@ xPortStartFirstTask:
lw x30 , 2 7 * p o r t W O R D _ S I Z E ( s p ) / * t 5 * /
lw 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
csrs m s t a t u s , 8 / * E n a b l e m a c h i n e i n t e r r u p t s . * /
ret
.endfunc
/*-----------------------------------------------------------*/
/ *
* Unlike o t h e r p o r t s p x P o r t I n i t i a l i s e S t a c k ( ) i s w r i t t e n i n a s s e m b l y c o d e a s i t
* needs a c c e s s t o t h 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 c o n s t a n t . T h e p r o t o t y p e
* for t h e f u n c t i o n i s a s p e r t h e o t h e r p o r t s :
* StackType_ t * p x P o r t I n i t i a l i s e S t a c k ( S t a c k T y p e _ t * p x T o p O f S t a c k , T a s k F u n c t i o n _ t p x C o d e , v o i d * p v P a r a m e t e r s ) ;
*
* As p e r t h e s t a n d a r d R I S C - V A B I p x T o p c O f S t a c k i s p a s s e d i n i n a0 , p x C o d e i n
* 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 ) .
*
* 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 -
* x1 r a R e t u r n a d d r e s s C a l l e r
* x2 s p S t a c k p o i n t e r C a l l e e
* x3 g p G l o b a l p o i n t e r -
* x4 t p T h r e a d p o i n t e r -
* x5 - 7 t 0 - 2 T e m p o r a r i e s C a l l e r
* 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 C a l l e e
* x9 s1 S a v e d r e g i s t e r C a l l e e
* x1 0 - 1 1 a0 - 1 F u n c t i o n A r g u m e n t s / r e t u r n v a l u e s C a l l e r
* x1 2 - 1 7 a2 - 7 F u n c t i o n a r g u m e n t s C a l l e r
* x1 8 - 2 7 s2 - 1 1 S a v e d r e g i s t e r s C a l l e e
* x2 8 - 3 1 t 3 - 6 T e m p o r a r i e s C a l l e r
*
* 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 :
*
* 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
* x1 5
* x1 4
* x1 3
* x1 2
* x1 1
* pvParameters
* x9
* x8
* x7
* x6
* x5
* portTASK_ R E T U R N _ A D D R E S S
* pxCode
* /
.align 8
.func
pxPortInitialiseStack :
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 . * /
chip_specific_stack_frame : /* First add any chip specific registers to the stack frame being created. */
beq t 0 , x0 , s t a n d a r d _ s t a c k _ f r a m e / * 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 . * /
sw 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 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 . * /
standard_stack_frame : /* Now create the stack frame for the standard registers. */
csrr t 0 , m s t a t u s / * O b t a i n c u r r e n t m s t a t u s v a l u e . * /
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
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
sw 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 . * /
sw 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 . * /
sw 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 a0 , a0 , - p o r t W O R D _ S I Z E
sw 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 . * /
ret
.endfunc
/*-----------------------------------------------------------*/