2007-07-11 23:18:54 +04:00
/ *
* header. S
*
* Copyright ( C ) 1 9 9 1 , 1 9 9 2 L i n u s T o r v a l d s
*
* Based o n b o o t s e c t . S a n d s e t u p . S
* modified b y m o r e p e o p l e t h a n c a n b e c o u n t e d
*
* Rewritten a s a c o m m o n f i l e b y H . P e t e r A n v i n ( A p r 2 0 0 7 )
*
* BIG F A T N O T E : W e ' r e i n r e a l m o d e u s i n g 6 4 k s e g m e n t s . T h e r e f o r e s e g m e n t
* addresses m u s t b e m u l t i p l i e d b y 1 6 t o o b t a i n t h e i r r e s p e c t i v e l i n e a r
* addresses. T o a v o i d c o n f u s i o n , l i n e a r a d d r e s s e s a r e w r i t t e n u s i n g l e a d i n g
* hex w h i l e s e g m e n t a d d r e s s e s a r e w r i t t e n a s s e g m e n t : o f f s e t .
*
* /
# include < a s m / s e g m e n t . h >
# include < l i n u x / u t s r e l e a s e . h >
# include < a s m / b o o t . h >
# include < a s m / e 8 2 0 . h >
# include < a s m / p a g e . h >
# include < a s m / s e t u p . h >
# include " b o o t . h "
SETUPSECTS = 4 / * d e f a u l t n r o f s e t u p - s e c t o r s * /
BOOTSEG = 0 x07 C 0 / * o r i g i n a l a d d r e s s o f b o o t - s e c t o r * /
SYSSEG = D E F _ S Y S S E G / * s y s t e m l o a d e d a t 0 x10 0 0 0 ( 6 5 5 3 6 ) * /
SYSSIZE = D E F _ S Y S S I Z E / * s y s t e m s i z e : # o f 16 - b y t e c l i c k s * /
/* to be loaded */
ROOT_ D E V = 0 / * R O O T _ D E V i s n o w w r i t t e n b y " b u i l d " * /
SWAP_ D E V = 0 / * S W A P _ D E V i s n o w w r i t t e n b y " b u i l d " * /
# ifndef S V G A _ M O D E
# define S V G A _ M O D E A S K _ V G A
# endif
# ifndef R A M D I S K
# define R A M D I S K 0
# endif
# ifndef R O O T _ R D O N L Y
# define R O O T _ R D O N L Y 1
# endif
.code16
.section " .bstext " , " ax"
.global bootsect_start
bootsect_start :
# Normalize t h e s t a r t a d d r e s s
ljmp $ B O O T S E G , $ s t a r t 2
start2 :
movw % c s , % a x
movw % a x , % d s
movw % a x , % e s
movw % a x , % s s
xorw % s p , % s p
sti
cld
movw $ b u g g e r _ o f f _ m s g , % s i
msg_loop :
lodsb
andb % a l , % a l
jz b s _ d i e
movb $ 0 x e , % a h
movw $ 7 , % b x
int $ 0 x10
jmp m s g _ l o o p
bs_die :
# Allow t h e u s e r t o p r e s s a k e y , t h e n r e b o o t
xorw % a x , % a x
int $ 0 x16
int $ 0 x19
# int 0 x19 s h o u l d n e v e r r e t u r n . I n c a s e i t d o e s a n y w a y ,
# invoke t h e B I O S r e s e t c o d e . . .
ljmp $ 0 x f00 0 ,$ 0 x f f f0
.section " .bsdata " , " a"
bugger_off_msg :
.ascii " Direct b o o t i n g f r o m f l o p p y i s n o l o n g e r s u p p o r t e d . \ r \ n "
.ascii " Please u s e a b o o t l o a d e r p r o g r a m i n s t e a d . \ r \ n "
.ascii " \ n"
.ascii " Remove d i s k a n d p r e s s a n y k e y t o r e b o o t . . . \ r \ n "
.byte 0
# Kernel a t t r i b u t e s ; used by setup. This is part 1 of the
# header, f r o m t h e o l d b o o t s e c t o r .
.section " .header " , " a"
.globl hdr
hdr :
setup_sects : .byte S E T U P S E C T S
root_flags : .word R O O T _ R D O N L Y
syssize : .long S Y S S I Z E
ram_size : .word R A M D I S K
vid_mode : .word S V G A _ M O D E
root_dev : .word R O O T _ D E V
boot_flag : .word 0xAA55
# offset 5 1 2 , e n t r y p o i n t
.globl _start
_start :
# Explicitly e n t e r t h i s a s b y t e s , o r t h e a s s e m b l e r
# tries t o g e n e r a t e a 3 - b y t e j u m p h e r e , w h i c h c a u s e s
# everything e l s e t o p u s h o f f t o t h e w r o n g o f f s e t .
.byte 0xeb # short ( 2 - b y t e ) j u m p
.byte start_ o f _ s e t u p - 1 f
1 :
# Part 2 o f t h e h e a d e r , f r o m t h e o l d s e t u p . S
.ascii " HdrS" # h e a d e r s i g n a t u r e
.word 0x0206 # header v e r s i o n n u m b e r ( > = 0 x01 0 5 )
# or e l s e o l d l o a d l i n - 1 . 5 w i l l f a i l )
.globl realmode_swtch
realmode_swtch : .word 0 , 0 # default_ s w i t c h , S E T U P S E G
start_sys_seg : .word S Y S S E G
.word kernel_ v e r s i o n - 5 1 2 # p o i n t i n g t o k e r n e l v e r s i o n s t r i n g
# above s e c t i o n o f h e a d e r i s c o m p a t i b l e
# with l o a d l i n - 1 . 5 ( h e a d e r v1 . 5 ) . D o n ' t
# change i t .
type_of_loader : .byte 0 # = 0 , old o n e ( L I L O , L o a d l i n ,
# Bootlin, S Y S L X , b o o t s e c t . . . )
# See D o c u m e n t a t i o n / i 3 8 6 / b o o t . t x t f o r
# assigned i d s
# flags, u n u s e d b i t s m u s t b e z e r o ( R F U ) b i t w i t h i n l o a d f l a g s
loadflags :
LOADED_ H I G H = 1 # I f s e t , t h e k e r n e l i s l o a d e d h i g h
CAN_ U S E _ H E A P = 0 x80 # I f s e t , t h e l o a d e r a l s o h a s s e t
# heap_ e n d _ p t r t o t e l l h o w m u c h
# space b e h i n d s e t u p . S c a n b e u s e d f o r
# heap p u r p o s e s .
# Only t h e l o a d e r k n o w s w h a t i s f r e e
# ifndef _ _ B I G _ K E R N E L _ _
.byte 0
# else
.byte LOADED_HIGH
# endif
setup_move_size : .word 0x8000 # size t o m o v e , w h e n s e t u p i s n o t
# loaded a t 0 x90 0 0 0 . W e w i l l m o v e s e t u p
# to 0 x90 0 0 0 t h e n j u s t b e f o r e j u m p i n g
# into t h e k e r n e l . H o w e v e r , o n l y t h e
# loader k n o w s h o w m u c h d a t a b e h i n d
# us a l s o n e e d s t o b e l o a d e d .
code32_start : # here l o a d e r s c a n p u t a d i f f e r e n t
# start a d d r e s s f o r 3 2 - b i t c o d e .
# ifndef _ _ B I G _ K E R N E L _ _
.long 0x1000 # 0 x1 0 0 0 = d e f a u l t f o r z I m a g e
# else
.long 0x100000 # 0 x1 0 0 0 0 0 = d e f a u l t f o r b i g k e r n e l
# endif
ramdisk_image : .long 0 # address o f l o a d e d r a m d i s k i m a g e
# Here t h e l o a d e r p u t s t h e 3 2 - b i t
# address w h e r e i t l o a d e d t h e i m a g e .
# This o n l y w i l l b e r e a d b y t h e k e r n e l .
ramdisk_size : .long 0 # its s i z e i n b y t e s
bootsect_kludge :
.long 0 # obsolete
heap_end_ptr : .word _ e n d + 1024 # ( Header v e r s i o n 0 x02 0 1 o r l a t e r )
# space f r o m h e r e ( e x c l u s i v e ) d o w n t o
# end o f s e t u p c o d e c a n b e u s e d b y s e t u p
# for l o c a l h e a p p u r p o s e s .
pad1 : .word 0
cmd_line_ptr : .long 0 # ( Header v e r s i o n 0 x02 0 2 o r l a t e r )
# If n o n z e r o , a 3 2 - b i t p o i n t e r
# to t h e k e r n e l c o m m a n d l i n e .
# The c o m m a n d l i n e s h o u l d b e
# located b e t w e e n t h e s t a r t o f
# setup a n d t h e e n d o f l o w
# memory ( 0 x a00 0 0 ) , o r i t m a y
# get o v e r w r i t t e n b e f o r e i t
# gets r e a d . I f t h i s f i e l d i s
# used, t h e r e i s n o l o n g e r
# anything m a g i c a l a b o u t t h e
# 0 x9 0 0 0 0 s e g m e n t ; the setup
# can b e l o c a t e d a n y w h e r e i n
# low m e m o r y 0 x10 0 0 0 o r h i g h e r .
ramdisk_max : .long ( - _ _ P A G E _ O F F S E T - ( 512 < < 2 0 ) - 1 ) & 0 x7 f f f f f f f
# ( Header v e r s i o n 0 x02 0 3 o r l a t e r )
# The h i g h e s t s a f e a d d r e s s f o r
# the c o n t e n t s o f a n i n i t r d
kernel_alignment : .long C O N F I G _ P H Y S I C A L _ A L I G N # p h y s i c a l a d d r a l i g n m e n t
# required f o r p r o t e c t e d m o d e
# kernel
# ifdef C O N F I G _ R E L O C A T A B L E
relocatable_kernel : .byte 1
# else
relocatable_kernel : .byte 0
# endif
pad2 : .byte 0
pad3 : .word 0
cmdline_size : .long C O M M A N D _ L I N E _ S I Z E - 1 # length o f t h e c o m m a n d l i n e ,
# added w i t h b o o t p r o t o c o l
# version 2 . 0 6
# End o f s e t u p h e a d e r ## # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
.section " .inittext " , " ax"
start_of_setup :
# ifdef S A F E _ R E S E T _ D I S K _ C O N T R O L L E R
# Reset t h e d i s k c o n t r o l l e r .
movw $ 0 x00 0 0 , % a x # R e s e t d i s k c o n t r o l l e r
movb $ 0 x80 , % d l # A l l d i s k s
int $ 0 x13
# endif
2007-07-26 21:10:35 +04:00
# We w i l l h a v e e n t e r e d w i t h % c s = % d s + 0 x20 , n o r m a l i z e % c s s o
2007-07-11 23:18:54 +04:00
# it i s o n p a r w i t h t h e o t h e r s e g m e n t s .
pushw % d s
pushw $ s e t u p2
lretw
setup2 :
# Force % e s = % d s
movw % d s , % a x
movw % a x , % e s
cld
# Stack p a r a n o i a : a l i g n t h e s t a c k a n d m a k e s u r e i t i s g o o d
# for b o t h 1 6 - a n d 3 2 - b i t r e f e r e n c e s . I n p a r t i c u l a r , i f w e
# were m e a n t t o h a v e b e e n u s i n g t h e f u l l 1 6 - b i t s e g m e n t , t h e
# caller m i g h t h a v e s e t % s p t o z e r o , w h i c h b r e a k s % e s p - b a s e d
# references.
andw $ ~ 3 , % s p # d w o r d a l i g n ( m i g h t a s w e l l . . . )
jnz 1 f
movw $ 0 x f f f c , % s p # M a k e s u r e w e ' r e n o t z e r o
1 : movzwl % s p , % e s p # C l e a r u p p e r h a l f o f % e s p
sti
# Check s i g n a t u r e a t e n d o f s e t u p
cmpl $ 0 x5 a5 a a a55 , s e t u p _ s i g
jne s e t u p _ b a d
# Zero t h e b s s
movw $ _ _ b s s _ s t a r t , % d i
movw $ _ e n d + 3 , % c x
xorl % e a x , % e a x
subw % d i , % c x
shrw $ 2 , % c x
rep; stosl
# Jump t o C c o d e ( s h o u l d n o t r e t u r n )
calll m a i n
# Setup c o r r u p t s o m e h o w . . .
setup_bad :
movl $ s e t u p _ c o r r u p t , % e a x
calll p u t s
# Fall t h r o u g h . . .
.globl die
.type die, @function
die :
hlt
jmp d i e
2007-09-11 01:39:02 +04:00
.size die, . - d i e
2007-07-11 23:18:54 +04:00
.section " .initdata " , " a"
setup_corrupt :
.byte 7
2007-07-27 03:10:22 +04:00
.string " No s e t u p s i g n a t u r e f o u n d . . . \ n "