2008-01-04 23:31:07 +01:00
/ *
* O3 2 i n t e r f a c e f o r t h e 6 4 ( o r N 3 2 ) A B I .
*
2014-04-01 00:14:41 +01:00
* Copyright ( C ) 2 0 0 2 , 2 0 1 4 M a c i e j W . R o z y c k i
2008-01-04 23:31:07 +01:00
*
* This p r o g r a m i s f r e e s o f t w a r e ; you can redistribute it and/or
* modify i t u n d e r t h e t e r m s o f t h e G N U G e n e r a l P u b l i c L i c e n s e
* as p u b l i s h e d b y t h e F r e e S o f t w a r e F o u n d a t i o n ; either version
* 2 of t h e L i c e n s e , o r ( a t y o u r o p t i o n ) a n y l a t e r v e r s i o n .
* /
# include < a s m / a s m . h >
# include < a s m / r e g d e f . h >
2014-04-01 00:14:41 +01:00
/* O32 register size. */
# define O 3 2 _ S Z R E G 4
2008-01-04 23:31:07 +01:00
/* Maximum number of arguments supported. Must be even! */
# define O 3 2 _ A R G C 3 2
2014-04-01 00:14:41 +01:00
/* Number of static registers we save. */
2008-01-04 23:31:07 +01:00
# define O 3 2 _ S T A T C 1 1
2014-04-01 00:14:41 +01:00
/* Argument area frame size. */
# define O 3 2 _ A R G S Z ( O 3 2 _ S Z R E G * O 3 2 _ A R G C )
/* Static register save area frame size. */
# define O 3 2 _ S T A T S Z ( S Z R E G * O 3 2 _ S T A T C )
/* Stack pointer register save area frame size. */
# define O 3 2 _ S P S Z S Z R E G
/* Combined area frame size. */
# define O 3 2 _ F R A M E S Z ( O 3 2 _ A R G S Z + O 3 2 _ S P S Z + O 3 2 _ S T A T S Z )
/* Switched stack frame size. */
# define O 3 2 _ N F R A M E S Z ( O 3 2 _ A R G S Z + O 3 2 _ S P S Z )
2008-01-04 23:31:07 +01:00
.text
/ *
* O3 2 f u n c t i o n c a l l d i s p a t c h e r , f o r i n t e r f a c i n g 3 2 - b i t R O M r o u t i n e s .
*
2014-04-01 00:14:41 +01:00
* The s t a n d a r d 6 4 ( N 3 2 ) c a l l i n g s e q u e n c e i s s u p p o r t e d , w i t h a0 h o l d i n g
* a f u n c t i o n p o i n t e r , a1 a p o i n t e r t o t h e n e w s t a c k t o c a l l t h e
* function w i t h o r 0 i f n o s t a c k s w i t c h i n g i s r e q u e s t e d , a2 - a7 - - t h e
* function c a l l ' s f i r s t s i x a r g u m e n t s , a n d t h e s t a c k - - t h e r e m a i n i n g
* arguments ( u p t o O 3 2 _ A R G C , i n c l u d i n g a2 - a7 ) . S t a t i c r e g i s t e r s , g p
* and f p a r e p r e s e r v e d , v0 h o l d s t h e r e s u l t . T h i s c o d e r e l i e s o n t h e
* called o 3 2 f u n c t i o n f o r s p a n d r a r e s t o r a t i o n a n d t h i s d i s p a t c h e r h a s
* to b e p l a c e d i n a K S E G x ( o r K U S E G ) a d d r e s s s p a c e . A n y p o i n t e r s
* passed h a v e t o p o i n t t o a d d r e s s e s w i t h i n o n e o f t h e s e s p a c e s a s w e l l .
2008-01-04 23:31:07 +01:00
* /
NESTED( c a l l _ o 3 2 , O 3 2 _ F R A M E S Z , r a )
REG_ S U B U s p ,O 3 2 _ F R A M E S Z
REG_ S r a ,O 3 2 _ F R A M E S Z - 1 * S Z R E G ( s p )
REG_ S f p ,O 3 2 _ F R A M E S Z - 2 * S Z R E G ( s p )
REG_ S g p ,O 3 2 _ F R A M E S Z - 3 * S Z R E G ( s p )
REG_ S s7 ,O 3 2 _ F R A M E S Z - 4 * S Z R E G ( s p )
REG_ S s6 ,O 3 2 _ F R A M E S Z - 5 * S Z R E G ( s p )
REG_ S s5 ,O 3 2 _ F R A M E S Z - 6 * S Z R E G ( s p )
REG_ S s4 ,O 3 2 _ F R A M E S Z - 7 * S Z R E G ( s p )
REG_ S s3 ,O 3 2 _ F R A M E S Z - 8 * S Z R E G ( s p )
REG_ S s2 ,O 3 2 _ F R A M E S Z - 9 * S Z R E G ( s p )
REG_ S s1 ,O 3 2 _ F R A M E S Z - 1 0 * S Z R E G ( s p )
REG_ S s0 ,O 3 2 _ F R A M E S Z - 1 1 * S Z R E G ( s p )
move j p ,a0
2014-04-01 00:14:41 +01:00
move f p ,s p
beqz a1 ,0 f
REG_ S U B U f p ,a1 ,O 3 2 _ N F R A M E S Z
0 :
REG_ S s p ,O 3 2 _ N F R A M E S Z - 1 * S Z R E G ( f p )
2008-01-04 23:31:07 +01:00
sll a0 ,a2 ,z e r o
sll a1 ,a3 ,z e r o
sll a2 ,a4 ,z e r o
sll a3 ,a5 ,z e r o
2014-04-01 00:14:41 +01:00
sw a6 ,4 * O 3 2 _ S Z R E G ( f p )
sw a7 ,5 * O 3 2 _ S Z R E G ( f p )
2008-01-04 23:31:07 +01:00
PTR_ L A t 0 ,O 3 2 _ F R A M E S Z ( s p )
2014-04-01 00:14:41 +01:00
PTR_ L A t 1 ,6 * O 3 2 _ S Z R E G ( f p )
2008-01-04 23:31:07 +01:00
li t 2 ,O 3 2 _ A R G C - 6
1 :
lw t 3 ,( t 0 )
REG_ A D D U t 0 ,S Z R E G
sw t 3 ,( t 1 )
REG_ S U B U t 2 ,1
2014-04-01 00:14:41 +01:00
REG_ A D D U t 1 ,O 3 2 _ S Z R E G
2008-01-04 23:31:07 +01:00
bnez t 2 ,1 b
2014-04-01 00:14:41 +01:00
move s p ,f p
2008-01-04 23:31:07 +01:00
jalr j p
2014-04-01 00:14:41 +01:00
REG_ L s p ,O 3 2 _ N F R A M E S Z - 1 * S Z R E G ( s p )
2008-01-04 23:31:07 +01:00
REG_ L s0 ,O 3 2 _ F R A M E S Z - 1 1 * S Z R E G ( s p )
REG_ L s1 ,O 3 2 _ F R A M E S Z - 1 0 * S Z R E G ( s p )
REG_ L s2 ,O 3 2 _ F R A M E S Z - 9 * S Z R E G ( s p )
REG_ L s3 ,O 3 2 _ F R A M E S Z - 8 * S Z R E G ( s p )
REG_ L s4 ,O 3 2 _ F R A M E S Z - 7 * S Z R E G ( s p )
REG_ L s5 ,O 3 2 _ F R A M E S Z - 6 * S Z R E G ( s p )
REG_ L s6 ,O 3 2 _ F R A M E S Z - 5 * S Z R E G ( s p )
REG_ L s7 ,O 3 2 _ F R A M E S Z - 4 * S Z R E G ( s p )
REG_ L g p ,O 3 2 _ F R A M E S Z - 3 * S Z R E G ( s p )
REG_ L f p ,O 3 2 _ F R A M E S Z - 2 * S Z R E G ( s p )
REG_ L r a ,O 3 2 _ F R A M E S Z - 1 * S Z R E G ( s p )
REG_ A D D U s p ,O 3 2 _ F R A M E S Z
jr r a
END( c a l l _ o 3 2 )