2005-04-16 15:20:36 -07:00
/ *
* BIOS E n h a n c e d D i s k D r i v e s u p p o r t
* Copyright ( C ) 2 0 0 2 , 2 0 0 3 , 2 0 0 4 D e l l , I n c .
* by M a t t D o m s c h < M a t t _ D o m s c h @dell.com> October 2002
* conformant t o T 1 3 C o m m i t t e e w w w . t 1 3 . o r g
* projects 1 5 7 2 D , 1 4 8 4 D , 1 3 8 6 D , 1 2 2 6 D T
* disk s i g n a t u r e r e a d b y M a t t D o m s c h < M a t t _ D o m s c h @dell.com>
* and A n d r e w W i l k s < A n d r e w _ W i l k s @dell.com> September 2003, June 2004
2005-06-25 14:58:59 -07:00
* legacy C H S r e t r i e v a l b y P a t r i c k J . L o P r e s t i < p a t l @users.sourceforge.net>
2005-04-16 15:20:36 -07:00
* March 2 0 0 4
* Command l i n e o p t i o n p a r s i n g , M a t t D o m s c h , N o v e m b e r 2 0 0 4
* /
# include < l i n u x / e d d . h >
# include < a s m / s e t u p . h >
# if d e f i n e d ( C O N F I G _ E D D ) | | d e f i n e d ( C O N F I G _ E D D _ M O D U L E )
movb $ 0 , ( E D D _ M B R _ S I G _ N R _ B U F )
movb $ 0 , ( E D D N R )
# Check t h e c o m m a n d l i n e f o r t w o o p t i o n s :
# edd=of d i s a b l e s E D D c o m p l e t e l y ( e d d =off )
# edd=sk s k i p s t h e M B R t e s t ( e d d =skipmbr )
pushl % e s i
cmpl $ 0 , % c s : c m d _ l i n e _ p t r
jz d o n e _ c l
movl % c s : ( c m d _ l i n e _ p t r ) , % e s i
# ds : esi h a s t h e p o i n t e r t o t h e c o m m a n d l i n e n o w
movl $ ( C O M M A N D _ L I N E _ S I Z E - 7 ) , % e c x
# loop t h r o u g h k e r n e l c o m m a n d l i n e o n e b y t e a t a t i m e
cl_loop :
cmpl $ E D D _ C L _ E Q U A L S , ( % s i )
jz f o u n d _ e d d _ e q u a l s
incl % e s i
loop c l _ l o o p
jmp d o n e _ c l
found_edd_equals :
# only l o o k i n g a t f i r s t t w o c h a r a c t e r s a f t e r e q u a l s
addl $ 4 , % e s i
cmpw $ E D D _ C L _ O F F , ( % s i ) # e d d = o f
jz d o _ e d d _ o f f
cmpw $ E D D _ C L _ S K I P , ( % s i ) # e d d = s k
jz d o _ e d d _ s k i p m b r
jmp d o n e _ c l
do_edd_skipmbr :
popl % e s i
jmp e d d _ s t a r t
do_edd_off :
popl % e s i
jmp e d d _ d o n e
done_cl :
popl % e s i
# Read t h e f i r s t s e c t o r o f e a c h B I O S d i s k d e v i c e a n d s t o r e t h e 4 - b y t e s i g n a t u r e
edd_mbr_sig_start :
movb $ 0 x80 , % d l # f r o m d e v i c e 80
movw $ E D D _ M B R _ S I G _ B U F , % b x # s t o r e b u f f e r p t r i n b x
edd_mbr_sig_read :
movl $ 0 x F F F F F F F F , % e a x
movl % e a x , ( % b x ) # a s s u m e f a i l u r e
pushw % b x
movb $ R E A D _ S E C T O R S , % a h
movb $ 1 , % a l # r e a d 1 s e c t o r
movb $ 0 , % d h # a t h e a d 0
movw $ 1 , % c x # c y l i n d e r 0 , s e c t o r 0
pushw % e s
pushw % d s
popw % e s
movw $ E D D B U F , % b x # d i s k ' s d a t a g o e s i n t o E D D B U F
pushw % d x # w o r k a r o u n d b u g g y B I O S e s
stc # w o r k a r o u n d b u g g y B I O S e s
int $ 0 x13
sti # w o r k a r o u n d b u g g y B I O S e s
popw % d x
popw % e s
popw % b x
jc e d d _ m b r _ s i g _ d o n e # o n f a i l u r e , w e ' r e d o n e .
movl ( E D D B U F + E D D _ M B R _ S I G _ O F F S E T ) , % e a x # r e a d s i g o u t o f t h e M B R
movl % e a x , ( % b x ) # s t o r e s u c c e s s
incb ( E D D _ M B R _ S I G _ N R _ B U F ) # n o t e t h a t w e s t o r e d s o m e t h i n g
incb % d l # i n c r e m e n t t o n e x t d e v i c e
addw $ 4 , % b x # i n c r e m e n t s i g b u f f e r p t r
cmpb $ E D D _ M B R _ S I G _ M A X , ( E D D _ M B R _ S I G _ N R _ B U F ) # O u t o f s p a c e ?
jb e d d _ m b r _ s i g _ r e a d # k e e p l o o p i n g
edd_mbr_sig_done :
# Do t h e B I O S E n h a n c e d D i s k D r i v e c a l l s
# This c o n s i s t s o f t w o c a l l s :
# int 1 3 h a h =41h " C h e c k E x t e n s i o n s P r e s e n t "
# int 1 3 h a h =48h " G e t D e v i c e P a r a m e t e r s "
# int 1 3 h a h =08h " L e g a c y G e t D e v i c e P a r a m e t e r s "
#
# A b u f f e r o f s i z e E D D M A X N R * ( E D D E X T S I Z E + E D D P A R M S I Z E ) i s r e s e r v e d f o r o u r u s e
# in t h e b o o t _ p a r a m s a t E D D B U F . T h e f i r s t f o u r b y t e s o f w h i c h a r e
# used t o s t o r e t h e d e v i c e n u m b e r , i n t e r f a c e s u p p o r t m a p a n d v e r s i o n
# results f r o m f n 4 1 . T h e n e x t f o u r b y t e s a r e u s e d t o s t o r e t h e l e g a c y
# cylinders, h e a d s , a n d s e c t o r s f r o m f n 0 8 . T h e f o l l o w i n g 7 4 b y t e s a r e u s e d t o
# store t h e r e s u l t s f r o m f n 4 8 . S t a r t i n g f r o m d e v i c e 8 0 h , f n 4 1 , t h e n f n 4 8
# are c a l l e d a n d t h e i r r e s u l t s s t o r e d i n E D D B U F + n * ( E D D E X T S I Z E + E D D P A R M I Z E ) .
# Then t h e p o i n t e r i s i n c r e m e n t e d t o s t o r e t h e d a t a f o r t h e n e x t c a l l .
# This r e p e a t s u n t i l e i t h e r a d e v i c e d o e s n ' t e x i s t , o r u n t i l E D D M A X N R
# devices h a v e b e e n s t o r e d .
# The o n e t r i c k y p a r t i s t h a t d s : s i a l w a y s p o i n t s E D D E X T S I Z E b y t e s i n t o
# the s t r u c t u r e , a n d t h e f n 4 1 a n d f n 0 8 r e s u l t s a r e s t o r e d a t o f f s e t s
# from t h e r e . T h i s r e m o v e s t h e n e e d t o i n c r e m e n t t h e p o i n t e r f o r
# every s t o r e , a n d l e a v e s i t r e a d y f o r t h e f n 4 8 c a l l .
# A s e c o n d o n e - b y t e b u f f e r , E D D N R , i n t h e b o o t _ p a r a m s s t o r e s
# the n u m b e r o f B I O S d e v i c e s w h i c h e x i s t , u p t o E D D M A X N R .
# In s e t u p . c , c o p y _ e d d ( ) s t o r e s b o t h b o o t _ p a r a m s b u f f e r s a w a y
# for l a t e r u s e , a s t h e y w o u l d g e t o v e r w r i t t e n o t h e r w i s e .
# This c o d e i s s e n s i t i v e t o t h e s i z e o f t h e s t r u c t s i n e d d . h
edd_start :
# % ds p o i n t s t o t h e b o o t s e c t o r
# result b u f f e r f o r f n 4 8
movw $ E D D B U F + E D D E X T S I Z E , % s i # i n d s : s i , f n 41 r e s u l t s
# kept j u s t b e f o r e t h a t
movb $ 0 x80 , % d l # B I O S d e v i c e 0x80
edd_check_ext :
movb $ C H E C K E X T E N S I O N S P R E S E N T , % a h # F u n c t i o n 41
movw $ E D D M A G I C 1 , % b x # m a g i c
int $ 0 x13 # m a k e t h e c a l l
jc e d d _ d o n e # n o m o r e B I O S d e v i c e s
cmpw $ E D D M A G I C 2 , % b x # i s m a g i c r i g h t ?
jne e d d _ n e x t # n o p e , n e x t . . .
movb % d l , % d s : - 8 ( % s i ) # s t o r e d e v i c e n u m b e r
movb % a h , % d s : - 7 ( % s i ) # s t o r e v e r s i o n
movw % c x , % d s : - 6 ( % s i ) # s t o r e e x t e n s i o n s
incb ( E D D N R ) # n o t e t h a t w e s t o r e d s o m e t h i n g
edd_get_device_params :
movw $ E D D P A R M S I Z E , % d s : ( % s i ) # p u t s i z e
movw $ 0 x0 , % d s : 2 ( % s i ) # w o r k a r o u n d b u g g y B I O S e s
movb $ G E T D E V I C E P A R A M E T E R S , % a h # F u n c t i o n 48
int $ 0 x13 # m a k e t h e c a l l
# Don' t c h e c k f o r f a i l r e t u r n
# it d o e s n ' t m a t t e r .
edd_get_legacy_chs :
xorw % a x , % a x
movw % a x , % d s : - 4 ( % s i )
movw % a x , % d s : - 2 ( % s i )
# Ralf B r o w n ' s I n t e r r u p t L i s t s a y s t o s e t E S : D I t o
# 0000h : 0 0 0 0 h " t o g u a r d a g a i n s t B I O S b u g s "
pushw % e s
movw % a x , % e s
movw % a x , % d i
pushw % d x # l e g a c y c a l l c l o b b e r s % d l
movb $ L E G A C Y G E T D E V I C E P A R A M E T E R S , % a h # F u n c t i o n 08
int $ 0 x13 # m a k e t h e c a l l
jc e d d _ l e g a c y _ d o n e # f a i l e d
movb % c l , % a l # L o w 6 b i t s a r e m a x
andb $ 0 x3 F , % a l # s e c t o r n u m b e r
movb % a l , % d s : - 1 ( % s i ) # R e c o r d m a x s e c t
movb % d h , % d s : - 2 ( % s i ) # R e c o r d m a x h e a d n u m b e r
movb % c h , % a l # L o w 8 b i t s o f m a x c y l
shr $ 6 , % c l
movb % c l , % a h # H i g h 2 b i t s o f m a x c y l
movw % a x , % d s : - 4 ( % s i )
edd_legacy_done :
popw % d x
popw % e s
movw % s i , % a x # i n c r e m e n t s i
addw $ E D D P A R M S I Z E + E D D E X T S I Z E , % a x
movw % a x , % s i
edd_next :
incb % d l # i n c r e m e n t t o n e x t d e v i c e
cmpb $ E D D M A X N R , ( E D D N R ) # O u t o f s p a c e ?
jb e d d _ c h e c k _ e x t # k e e p l o o p i n g
edd_done :
# endif