2005-04-16 15:20:36 -07:00
/ *
* EFI c a l l s t u b f o r I A 3 2 .
*
* This s t u b a l l o w s u s t o m a k e E F I c a l l s i n p h y s i c a l m o d e w i t h i n t e r r u p t s
* turned o f f .
* /
# include < l i n u x / l i n k a g e . h >
2009-02-13 11:14:01 -08:00
# include < a s m / p a g e _ t y p e s . h >
2005-04-16 15:20:36 -07:00
/ *
* efi_ c a l l _ p h y s ( v o i d * , . . . ) i s a f u n c t i o n w i t h v a r i a b l e p a r a m e t e r s .
* All t h e c a l l e r s o f t h i s f u n c t i o n a s s u r e t h a t a l l t h e p a r a m e t e r s a r e 4 - b y t e s .
* /
/ *
* In g c c c a l l i n g c o n v e n t i o n , E B X , E S P , E B P , E S I a n d E D I a r e a l l c a l l e e s a v e .
* So w e ' d b e t t e r s a v e a l l o f t h e m a t t h e b e g i n n i n g o f t h i s f u n c t i o n a n d r e s t o r e
* at t h e e n d n o m a t t e r h o w m a n y w e u s e , b e c a u s e w e c a n n o t a s s u r e E F I r u n t i m e
* service f u n c t i o n s w i l l c o m p l y w i t h g c c c a l l i n g c o n v e n t i o n , t o o .
* /
.text
ENTRY( e f i _ c a l l _ p h y s )
/ *
* 0 . The f u n c t i o n c a n o n l y b e c a l l e d i n L i n u x k e r n e l . S o C S h a s b e e n
* set t o 0 x00 1 0 , D S a n d S S h a v e b e e n s e t t o 0 x00 1 8 . I n E F I , I f o u n d
* the v a l u e s o f t h e s e r e g i s t e r s a r e t h e s a m e . A n d , t h e c o r r e s p o n d i n g
* GDT e n t r i e s a r e i d e n t i c a l . S o I w i l l d o n o t h i n g a b o u t s e g m e n t r e g
* and G D T , b u t c h a n g e G D T b a s e r e g i s t e r i n p r e l o g a n d e p i l o g .
* /
/ *
* 1 . Now I a m r u n n i n g w i t h E I P = < p h y s i c a l a d d r e s s > + P A G E _ O F F S E T .
* But t o m a k e i t s m o o t h l y s w i t c h f r o m v i r t u a l m o d e t o f l a t m o d e .
* The m a p p i n g o f l o w e r v i r t u a l m e m o r y h a s b e e n c r e a t e d i n p r e l o g a n d
* epilog.
* /
movl $ 1 f , % e d x
subl $ _ _ P A G E _ O F F S E T , % e d x
jmp * % e d x
1 :
/ *
* 2 . Now o n t h e t o p o f s t a c k i s t h e r e t u r n
* address i n t h e c a l l e r o f e f i _ c a l l _ p h y s ( ) , t h e n p a r a m e t e r 1 ,
* parameter 2 , . . . , p a r a m n . T o m a k e t h i n g s e a s y , w e s a v e t h e r e t u r n
* address o f e f i _ c a l l _ p h y s i n a g l o b a l v a r i a b l e .
* /
popl % e d x
movl % e d x , s a v e d _ r e t u r n _ a d d r
/* get the function pointer into ECX*/
popl % e c x
movl % e c x , e f i _ r t _ f u n c t i o n _ p t r
movl $ 2 f , % e d x
subl $ _ _ P A G E _ O F F S E T , % e d x
pushl % e d x
/ *
* 3 . Clear P G b i t i n % C R 0 .
* /
movl % c r0 , % e d x
andl $ 0 x7 f f f f f f f , % e d x
movl % e d x , % c r0
jmp 1 f
1 :
/ *
* 4 . Adjust s t a c k p o i n t e r .
* /
subl $ _ _ P A G E _ O F F S E T , % e s p
/ *
* 5 . Call t h e p h y s i c a l f u n c t i o n .
* /
jmp * % e c x
2 :
/ *
* 6 . After E F I r u n t i m e s e r v i c e r e t u r n s , c o n t r o l w i l l r e t u r n t o
* following i n s t r u c t i o n . W e ' d b e t t e r r e a d j u s t s t a c k p o i n t e r f i r s t .
* /
addl $ _ _ P A G E _ O F F S E T , % e s p
/ *
* 7 . Restore P G b i t
* /
movl % c r0 , % e d x
orl $ 0 x80 0 0 0 0 0 0 , % e d x
movl % e d x , % c r0
jmp 1 f
1 :
/ *
* 8 . Now r e s t o r e t h e v i r t u a l m o d e f r o m f l a t m o d e b y
* adding E I P w i t h P A G E _ O F F S E T .
* /
movl $ 1 f , % e d x
jmp * % e d x
1 :
/ *
* 9 . Balance t h e s t a c k . A n d b e c a u s e E A X c o n t a i n t h e r e t u r n v a l u e ,
* we' d b e t t e r n o t c l o b b e r i t .
* /
leal e f i _ r t _ f u n c t i o n _ p t r , % e d x
movl ( % e d x ) , % e c x
pushl % e c x
/ *
* 1 0 . Push t h e s a v e d 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 a n d r e t u r n .
* /
leal s a v e d _ r e t u r n _ a d d r , % e d x
movl ( % e d x ) , % e c x
pushl % e c x
ret
2009-02-23 22:57:02 +03:00
ENDPROC( e f i _ c a l l _ p h y s )
2005-04-16 15:20:36 -07:00
.previous
.data
saved_return_addr :
.long 0
efi_rt_function_ptr :
.long 0