2012-05-08 21:22:28 +03:00
/ *
*
* Trampoline. S D e r i v e d f r o m S e t u p . S b y L i n u s T o r v a l d s
*
* 4 Jan 1 9 9 7 M i c h a e l C h a s t a i n : c h a n g e d t o g n u a s .
*
* This i s o n l y u s e d f o r b o o t i n g s e c o n d a r y C P U s i n S M P m a c h i n e
*
* Entry : CS : IP p o i n t t o t h e s t a r t o f o u r c o d e , w e a r e
* in r e a l m o d e w i t h n o s t a c k , b u t t h e r e s t o f t h e
* trampoline p a g e t o m a k e o u r s t a c k a n d e v e r y t h i n g e l s e
* is a m y s t e r y .
*
* We j u m p i n t o a r c h / x86 / k e r n e l / h e a d _ 3 2 . S .
*
2012-05-08 21:22:43 +03:00
* On e n t r y t o t r a m p o l i n e _ s t a r t , t h e p r o c e s s o r i s i n r e a l m o d e
2012-05-08 21:22:28 +03:00
* with 1 6 - b i t a d d r e s s i n g a n d 1 6 - b i t d a t a . C S h a s s o m e v a l u e
* and I P i s z e r o . T h u s , w e l o a d C S t o t h e p h y s i c a l s e g m e n t
* of t h e r e a l m o d e c o d e b e f o r e d o i n g a n y t h i n g f u r t h e r .
* /
# include < l i n u x / l i n k a g e . h >
# include < l i n u x / i n i t . h >
# include < a s m / s e g m e n t . h >
# include < a s m / p a g e _ t y p e s . h >
2012-05-08 21:22:37 +03:00
# include " r e a l m o d e . h "
2012-05-08 21:22:28 +03:00
.text
.code16
2012-05-08 21:22:40 +03:00
.balign PAGE_SIZE
2012-05-08 21:22:43 +03:00
ENTRY( t r a m p o l i n e _ s t a r t )
2012-05-08 21:22:28 +03:00
wbinvd # N e e d e d f o r N U M A - Q s h o u l d b e h a r m l e s s f o r o t h e r s
2012-05-08 21:22:37 +03:00
LJMPW_ R M ( 1 f )
2012-05-08 21:22:28 +03:00
1 :
mov % c s , % a x # C o d e a n d d a t a i n t h e s a m e p l a c e
mov % a x , % d s
cli # W e s h o u l d b e s a f e a n y w a y
2012-05-08 21:22:43 +03:00
movl t r _ s t a r t , % e a x # w h e r e w e n e e d t o g o
2012-05-08 21:22:36 +03:00
2012-05-08 21:22:28 +03:00
movl $ 0 x A 5 A 5 A 5 A 5 , t r a m p o l i n e _ s t a t u s
# write m a r k e r f o r m a s t e r k n o w s w e ' r e r u n n i n g
2012-05-08 21:22:36 +03:00
/ *
* GDT t a b l e s i n n o n d e f a u l t l o c a t i o n k e r n e l c a n b e b e y o n d 1 6 M B a n d
2012-05-08 21:22:28 +03:00
* lgdt w i l l n o t b e a b l e t o l o a d t h e a d d r e s s a s i n r e a l m o d e d e f a u l t
* operand s i z e i s 1 6 b i t . U s e l g d t l i n s t e a d t o f o r c e o p e r a n d s i z e
* to 3 2 b i t .
* /
2012-05-08 21:22:43 +03:00
lidtl t r _ i d t # l o a d i d t w i t h 0 , 0
lgdtl t r _ g d t # l o a d g d t w i t h w h a t e v e r i s a p p r o p r i a t e
2012-05-08 21:22:28 +03:00
2012-05-08 21:22:36 +03:00
movw $ 1 , % d x # p r o t e c t e d m o d e ( P E ) b i t
lmsw % d x # i n t o p r o t e c t e d m o d e
2012-05-08 21:22:28 +03:00
2012-05-08 21:22:36 +03:00
ljmpl $ _ _ B O O T _ C S , $ p a _ s t a r t u p _ 3 2
.section " .text32 " , " ax"
.code32
ENTRY( s t a r t u p _ 3 2 ) # n o t e : a l s o u s e d f r o m w a k e u p _ a s m . S
jmp * % e a x
2012-05-08 21:22:28 +03:00
2012-05-16 13:44:10 -07:00
.bss
.balign 8
GLOBAL( t r a m p o l i n e _ h e a d e r )
tr_start : .space 4
tr_gdt_pad : .space 2
tr_gdt : .space 6
END( t r a m p o l i n e _ h e a d e r )
2012-05-08 21:22:43 +03:00
# include " t r a m p o l i n e _ c o m m o n . S "