2005-04-16 15:20:36 -07: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 .
*
* 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 .
*
* In f a c t w e d o n ' t a c t u a l l y n e e d a s t a c k s o w e d o n ' t
* set o n e u p .
*
* On e n t r y t o t r a m p o l i n e _ d a t a , t h e p r o c e s s o r i s i n r e a l m o d e
* 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 , d a t a a d d r e s s e s n e e d t o b e a b s o l u t e
* ( no r e l o c a t i o n ) a n d a r e t a k e n w i t h r e g a r d t o r _ b a s e .
*
* If y o u w o r k o n t h i s f i l e , c h e c k t h e o b j e c t m o d u l e w i t h o b j d u m p
* - - full- c o n t e n t s - - r e l o c t o m a k e s u r e t h e r e a r e n o r e l o c a t i o n
* entries. F o r t h e G D T e n t r y w e d o h a n d r e l o c a t i o n i n s m p b o o t . c
* because o f 6 4 b i t l i n k e r l i m i t a t i o n s .
* /
# 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 / p a g e . h >
.data
.code16
ENTRY( t r a m p o l i n e _ d a t a )
r_ b a s e = .
wbinvd
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
movl $ 0 x A 5 A 5 A 5 A 5 , t r a m p o l i n e _ d a t a - r _ b a s e
# 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
2006-01-12 03:35:20 +01: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
* 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 .
* /
lidtl i d t _ 4 8 - r _ b a s e # l o a d i d t w i t h 0 , 0
lgdtl g d t _ 4 8 - r _ b a s e # 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
2005-04-16 15:20:36 -07:00
xor % a x , % a x
inc % a x # p r o t e c t e d m o d e ( P E ) b i t
lmsw % a x # i n t o p r o t e c t e d m o d e
# flaush p r e f e t c h a n d j u m p t o s t a r t u p _ 3 2 i n a r c h / x86 _ 6 4 / k e r n e l / h e a d . S
ljmpl $ _ _ K E R N E L 3 2 _ C S , $ ( s t a r t u p _ 3 2 - _ _ S T A R T _ K E R N E L _ m a p )
# Careful t h e s e n e e d t o b e i n t h e s a m e 6 4 K s e g m e n t a s t h e a b o v e ;
idt_48 :
.word 0 # idt l i m i t = 0
.word 0 , 0 # idt b a s e = 0 L
gdt_48 :
.short __KERNEL32_CS + 7 # gdt l i m i t
.long cpu_ g d t _ t a b l e - _ _ S T A R T _ K E R N E L _ m a p
.globl trampoline_end
trampoline_end :