Retired 'bootsect.S'
We know that the latest linux kernel version is 2.6.x, which is different from the ‘old kernels’ in booting. The ‘bootsect.S’, which used to make the kernel image in the floppy disk bootable in the early days, becomes useless in linux kernel 2.6.x today, although it is still a part of the kernel image.
We know that ‘bootsect.S’ is usu placed in the first 512 bytes of the kernel image and installed in the first sector of some medium on which the kernel image is installed. the mediums usu include hard disk (or the active partition of the hard disk) and floppy disk. As a minimal ‘bootloader’ included in kernel images of earlier linux versions up to the 2.4, the ‘bootsect.S’ is in duty bound to copy the left kernel image from medium to main memory when we boot linux from the floppy disk and then execute the loaded code in order to complete its mission. when we boot linux from hard disk, the ‘bootsect.S’ does nothing actively but to be checked by other booting routine stored in BIOS(Basic Input/Output System) or MBR(Master Boot Record). Today if you wanna boot linux 2.6.x from a floppy disk, you have to select a suitable bootloader yourself, just like that you boot linux from hard disk, since the ‘bootsect.S’ has retired.
Here list the source code of ‘bootsect.S’ and some comments of mine. let us go and see what the retired ‘bootsect.S’ really does! (my comments usu occur following the symbol ‘!’)
/*
* bootsect.S Copyright (C) 1991, 1992 Linus Torvalds
*
* modified by Drew Eckhardt
* modified by Bruce Evans (bde)
* modified by Chris Noe (May 1999) (as86 -> gas)
* gutted by H. Peter Anvin (Jan 2003)
*
* BIG FAT NOTE: We’re in real mode using 64k segments. Therefore segment
* addresses must be multiplied by 16 to obtain their respective linear
* addresses. To avoid confusion, linear addresses are written using leading
* hex while segment addresses are written as segment:offset.
*
* ! $(linux-2.6.15.3_dir)/arch/i386/bootsect.S
*/
/* ! I found this header file in $(linux-2.6.15.3_dir)/include/asm-i386 */
#include
/*
* ! DEF_INITSEG 0×9000
* ! DEF_SYSSEG 0×1000
* ! DEF_SETUPSEG 0×9020
* ! DEF_SYSSIZE 0x7F00
* ! These macros above are defined in ‘boot.h’ and
* ! the values of the first three of them
* ! used to be stored into ‘cs’ register
*/
SETUPSECTS = 4 /* default nr of setup-sectors */
BOOTSEG = 0x07C0 /* original address of boot-sector */
INITSEG = DEF_INITSEG /* we move boot here – out of the way */
SETUPSEG = DEF_SETUPSEG /* setup starts here */
SYSSEG = DEF_SYSSEG /* system loaded at 0×10000 (65536) */
SYSSIZE = DEF_SYSSIZE /* system size: # of 16-byte clicks */
/* to be loaded */
/*
* ! Here no matter what the ‘ROOT_DEV’ is is insignificant.
* ! When kernel image builds, this ‘ROOT_DEV’ will be reset.
* ! And so does ‘SWAP_DEV’.
* ! ‘ROOT_DEV’ is variable which represents the type of the device
* ! in which the root file system stores.
* ! ‘ROOT_DEV = 0′ means the same type of floopy as boot.
*/
ROOT_DEV = 0 /* ROOT_DEV is now written by "build" */
SWAP_DEV = 0 /* SWAP_DEV is now written by "build" */
#ifndef SVGA_MODE
#define SVGA_MODE ASK_VGA
#endif
#ifndef RAMDISK
#define RAMDISK 0
#endif
#ifndef ROOT_RDONLY
#define ROOT_RDONLY 1
#endif
/*
* !Now we are running in 16-bit real mode, neither in
* ! 32-bit real mode nor in 32-bit protected mode
*/
.code16
.text
.global _start
_start:
/*
* ! jmpl is an ‘jump’ instruction which
* ! jumps between segments.
* ! the instruction below first stores the
* ! immediate number ‘$BOOTSEG’ into ‘CS’
* ! register and stores the address of label
* ! ‘start2′ into ‘EIP’ register, and then jumps
* ! to label ‘start2′ to execute.
* ! Now, R[%cs] = $BOOTSEG = 0x07C0
*/
# Normalize the start address
jmpl $BOOTSEG, $start2
start2:
/*
* ! initialize some general registers
* ! R[%ds] = R[%es] = R[%ss] = 0x07C0
* ! R[%sp] = 0x7c00
*/
movw %cs, %ax
movw %ax, %ds
movw %ax, %es
movw %ax, %ss
movw $0x7c00, %sp
/*
* ! sti – set the interrupt flag
* ! cld – clear ‘df’(direction flag). after it executed,
* ! string operations will increment the index
* ! registers (si and/or di) that they use
*/
sti
cld
/*
* ! store the address of ‘bugger_off_msg’
* ! into register ‘si’(source-index register)
*/
movw $bugger_off_msg, %si
/*
* ! this loop prints the ‘bugger_off_msg’ on screen
* ! and jumps to ‘die’ label.
*/
msg_loop:
/*
* ! lodsb loads ‘al’ register with single memory
* ! byte at the position pointed to by ‘si’ register
* ! after the executing, the ‘si’ is automatically
* ! increased or decreased according to the ‘df’.
*/
lodsb
andb %al, %al
jz die
movb $0xe, %ah
movw $7, %bx
int $0×10
jmp msg_loop
/*
* ! the computer dies and you have to reboot.
*/
die:
# Allow the user to press a key, then reboot
xorw %ax, %ax
/*
* ! int 16h – bios interrupt to give user
* ! a chance to enter something from the keyboard
*/
int $0×16
int $0×19
# int 0×19 should never return. In case it does anyway,
# invoke the BIOS reset code…
ljmp $0xf000,$0xfff0
bugger_off_msg:
.ascii "Direct booting from floppy is no longer supported.\r\n"
.ascii "Please use a boot loader program instead.\r\n"
.ascii "\n"
.ascii "Remove disk and press any key to reboot . . .\r\n"
.byte 0
# Kernel attributes; used by setup
/*
* ! variables below are important since
* ! they would be refered by ‘setup.S’
* ! the total size of these variables is
* ! 15 bytes, 497 + 15 = 512
* ! the last word is ’0xAA55′, which indicates
* ! this is a boot sector
*/
.org 497
setup_sects: .byte SETUPSECTS
root_flags: .word ROOT_RDONLY
syssize: .word SYSSIZE
swap_dev: .word SWAP_DEV
ram_size: .word RAMDISK
vid_mode: .word SVGA_MODE
root_dev: .word ROOT_DEV
boot_flag: .word 0xAA55
/* ! end of bootsect.S */
Thus, we know that the retired ‘bootsect.S’ only tells us it has retired.
评论