2017-02-05 19:50:52 -05:00
/ *
* Copyright C 2 0 1 6 , O r a c l e a n d / o r i t s a f f i l i a t e s . A l l r i g h t s r e s e r v e d .
*
* 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
* it 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 a s p u b l i s h e d b y
* the 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 the License, or
* ( at 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 .
*
* This p r o g r a m i s d i s t r i b u t e d i n t h e h o p e t h a t i t w i l l b e u s e f u l ,
* but W I T H O U T A N Y W A R R A N T Y ; without even the implied warranty of
* MERCHANTABILITY o r F I T N E S S F O R A P A R T I C U L A R P U R P O S E . S e e t h e
* GNU G e n e r a l P u b l i c L i c e n s e f o r m o r e d e t a i l s .
*
* You s h o u l d h a v e r e c e i v e d a c o p y 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 a l o n g
* with t h i s p r o g r a m . I f n o t , s e e < h t t p : / / w w w . g n u . o r g / l i c e n s e s / > .
* /
.code32
.text
# define _ p a ( x ) ( ( x ) - _ _ S T A R T _ K E R N E L _ m a p )
# include < l i n u x / e l f n o t e . h >
# include < l i n u x / i n i t . h >
# include < l i n u x / l i n k a g e . h >
# include < a s m / s e g m e n t . h >
# include < a s m / a s m . h >
# include < a s m / b o o t . h >
# include < a s m / p r o c e s s o r - f l a g s . h >
# include < a s m / m s r . h >
# include < x e n / i n t e r f a c e / e l f n o t e . h >
_ _ HEAD
/ *
* Entry p o i n t f o r P V H g u e s t s .
*
* Xen A B I s p e c i f i e s t h e f o l l o w i n g r e g i s t e r s t a t e w h e n w e c o m e h e r e :
*
* - ` ebx` : c o n t a i n s t h e p h y s i c a l m e m o r y a d d r e s s w h e r e t h e l o a d e r h a s p l a c e d
* the b o o t s t a r t i n f o s t r u c t u r e .
* - ` cr0 ` : b i t 0 ( P E ) m u s t b e s e t . A l l t h e o t h e r w r i t e a b l e b i t s a r e c l e a r e d .
* - ` cr4 ` : a l l b i t s a r e c l e a r e d .
* - ` cs ` : m u s t b e a 3 2 - b i t r e a d / e x e c u t e c o d e s e g m e n t w i t h a b a s e o f ‘ 0 ’
* and a l i m i t o f ‘ 0 x F F F F F F F F ’ . T h e s e l e c t o r v a l u e i s u n s p e c i f i e d .
* - ` ds` , ` e s ` : m u s t b e a 3 2 - b i t r e a d / w r i t e d a t a s e g m e n t w i t h a b a s e o f
* ‘ 0 ’ and a l i m i t o f ‘ 0 x F F F F F F F F ’ . T h e s e l e c t o r v a l u e s a r e a l l
* unspecified.
* - ` tr` : m u s t b e a 3 2 - b i t T S S ( a c t i v e ) w i t h a b a s e o f ' 0 ' a n d a l i m i t
* of ' 0 x67 ' .
* - ` eflags` : b i t 1 7 ( V M ) m u s t b e c l e a r e d . B i t 9 ( I F ) m u s t b e c l e a r e d .
* Bit 8 ( T F ) m u s t b e c l e a r e d . O t h e r b i t s a r e a l l u n s p e c i f i e d .
*
* All o t h e r p r o c e s s o r r e g i s t e r s a n d f l a g b i t s a r e u n s p e c i f i e d . T h e O S i s i n
* charge o f s e t t i n g u p i t ' s o w n s t a c k , G D T a n d I D T .
* /
ENTRY( p v h _ s t a r t _ x e n )
cld
lgdt ( _ p a ( g d t ) )
mov $ ( _ _ B O O T _ D S ) ,% e a x
mov % e a x ,% d s
mov % e a x ,% e s
mov % e a x ,% s s
/* Stash hvm_start_info. */
mov $ _ p a ( p v h _ s t a r t _ i n f o ) , % e d i
mov % e b x , % e s i
mov _ p a ( p v h _ s t a r t _ i n f o _ s z ) , % e c x
shr $ 2 ,% e c x
rep
movsl
mov $ _ p a ( e a r l y _ s t a c k _ e n d ) , % e s p
/* Enable PAE mode. */
mov % c r4 , % e a x
orl $ X 8 6 _ C R 4 _ P A E , % e a x
mov % e a x , % c r4
# ifdef C O N F I G _ X 8 6 _ 6 4
/* Enable Long mode. */
mov $ M S R _ E F E R , % e c x
rdmsr
btsl $ _ E F E R _ L M E , % e a x
wrmsr
/* Enable pre-constructed page tables. */
2017-06-06 14:31:27 +03:00
mov $ _ p a ( i n i t _ t o p _ p g t ) , % e a x
2017-02-05 19:50:52 -05:00
mov % e a x , % c r3
mov $ ( X 8 6 _ C R 0 _ P G | X 8 6 _ C R 0 _ P E ) , % e a x
mov % e a x , % c r0
/* Jump to 64-bit mode. */
ljmp $ _ _ K E R N E L _ C S , $ _ p a ( 1 f )
/* 64-bit entry point. */
.code64
1 :
call x e n _ p r e p a r e _ p v h
/* startup_64 expects boot_params in %rsi. */
mov $ _ p a ( p v h _ b o o t p a r a m s ) , % r s i
mov $ _ p a ( s t a r t u p _ 6 4 ) , % r a x
jmp * % r a x
# else / * C O N F I G _ X 8 6 _ 6 4 * /
call m k _ e a r l y _ p g t b l _ 3 2
mov $ _ p a ( i n i t i a l _ p a g e _ t a b l e ) , % e a x
mov % e a x , % c r3
mov % c r0 , % e a x
or $ ( X 8 6 _ C R 0 _ P G | X 8 6 _ C R 0 _ P E ) , % e a x
mov % e a x , % c r0
ljmp $ _ _ B O O T _ C S , $ 1 f
1 :
call x e n _ p r e p a r e _ p v h
mov $ _ p a ( p v h _ b o o t p a r a m s ) , % e s i
/* startup_32 doesn't expect paging and PAE to be on. */
ljmp $ _ _ B O O T _ C S , $ _ p a ( 2 f )
2 :
mov % c r0 , % e a x
and $ ~ X 8 6 _ C R 0 _ P G , % e a x
mov % e a x , % c r0
mov % c r4 , % e a x
and $ ~ X 8 6 _ C R 4 _ P A E , % e a x
mov % e a x , % c r4
ljmp $ _ _ B O O T _ C S , $ _ p a ( s t a r t u p _ 3 2 )
# endif
END( p v h _ s t a r t _ x e n )
.section " .init .data " , " aw"
.balign 8
gdt :
.word gdt_end - gdt_ s t a r t
.long _ pa( g d t _ s t a r t )
.word 0
gdt_start :
.quad 0x0000000000000000 /* NULL descriptor */
.quad 0x0000000000000000 /* reserved */
# ifdef C O N F I G _ X 8 6 _ 6 4
.quad GDT_ E N T R Y ( 0 x a09 a , 0 , 0 x f f f f f ) / * _ _ K E R N E L _ C S * /
# else
.quad GDT_ E N T R Y ( 0 x c09 a , 0 , 0 x f f f f f ) / * _ _ K E R N E L _ C S * /
# endif
.quad GDT_ E N T R Y ( 0 x c09 2 , 0 , 0 x f f f f f ) / * _ _ K E R N E L _ D S * /
gdt_end :
.balign 4
early_stack :
.fill 2 5 6 , 1 , 0
early_stack_end :
ELFNOTE( X e n , X E N _ E L F N O T E _ P H Y S 3 2 _ E N T R Y ,
_ ASM_ P T R ( p v h _ s t a r t _ x e n - _ _ S T A R T _ K E R N E L _ m a p ) )