Linux kernel 0.11 bootsect file description

Source: Internet
Author: User

First, the overall function of the introduction

This is a Linux-kernel-0.11 description of the source file under the Boot folder bootsect.s , which involves some basic knowledge that can be referenced in these two articles.

    1. Operating system startup process
    2. Floppy disk-related knowledge and interrupt access via BIOS

The BOOTSECT.S code is a disk boot block program that is stored in the first sector of the disk (0-side, 0-channel, 1-sector), and the BIOS will boot sector code bootsect load to the memory 0x90000 and run after the computer's power-on-bios self-test.

The Bootsect code mainly accomplishes the following tasks:

    • Loads the contents of 4 sectors starting from the second sector of the disk (compiled by SETUP.S) to memory immediately following Bootsect 0x90200.

    • Take advantage of the BIOS interrupt int 13h to get the parameters for the current boot drive in the disk parameters table.

    • Displays the string on the screen "Loading system..." .

    • Load the system module behind the Setup module on disk into the place where memory 0x10000 begins.

    • Determine the device number of the root filesystem and, if not specified, the type and kind of disk (1.2MB or 1.44MB floppy disk) based on the number of sectors per track of the saved boot disk, and save its device number in Root_dev (the 508 address of the boot sector, which is the No. 509 byte of the first sector).

    • Long jump to the start of the Setup program (0X90200) to execute the Setup program.

On disk, the sector location and size of the boot block bootsect, Setup module, and System module are as follows:

Second, code comments
!! Sys_size is the number of clicks ( -bytes) to be loaded.!0x3000Is0x30000bytes = 196kB, more than enough for current! Versions of linux! Sys_size is the length of the system module to be loaded, in units of the section1Section = -Bytes0x3000byte = 196kB.! The system module length is defined here, so the rules in the makefile are invalidated! Syssize =0x3000!! Bootsect.s (C)1991Linus torvalds!! Bootsect.s is loaded at0x7c00By the Bios-startup routines, andmoves! Iself outThe To Address0x90000, andJumps there.!! It then loads' Setup 'Directly after itself (0x90200), andThe system! at0x10000,Using BIOS interrupts. !! note! Currently system is atMost8*65536Bytes long. This should is no! Problem, eveninchThe future. I want to keep it simple. This +Kb! Kernel size should be enough, especially as this doesn' t contain the! Buffer Cache asinchMinix!! The loader have been made as simple as possible, andcontinuos! Read errors'll resultinchA unbreakableLoop. Reboot by hand. It! Loads pretty fast by getting whole sectors atA time whenever possible.! . Globl or. Global is used to define subsequent identifiers that are external or global, and are forced to introduce even if not used.!. Text.Data. BSS defines the current code snippet, data segment, and uninitialized data segment: Globl begtext, Begdata, BEGBSS, Endtext, Enddata, ENDBSS! Defines the6A global identifier. Text paragraphBegtext:.Data! Data segmentBegdata:. BSS! Uninitialized data segmentBEGBSS:. Textsetuplen =4! NR of Setup-sectors Setup program sector (setup-sectors) Value bootseg =0x07c0! Original address of Boot-sector Bootsect original value (is segment) Initseg =0x9000! We move boot here- outThe the the-the-Bootsect is moved here setupseg =0x9020! The setup starts Here Setup program starts here Sysseg =0x1000! System loaded at0x10000(65536). The system module is loaded into0x10000(64KB) at endseg = sysseg + syssize! Where to stop loading stop loading the segment address! Root_dev:0x000-same type of floppy as boot. Root filesystem device and boot use the same floppy drive device!0x301-First partition on primary drive etc root file system device on first hard disk partition. Root_dev =0x306entryStart! Tell the linker that the program executes from the label startStart:    mov Ax, #BOOTSEG! Set DS to0x07c0(segment address)mov DS,Ax    mov Ax, #INITSEG! Set ES to0x9000(segment address)mov es,Ax    mov CX,# the! Move Count Value theA wordSub si,si! Source AddressDS:si=0x07c0:0x0000    Sub di,di! Destination Addresses:di=0x9000:0x0000Rep! Repeat and CX values until CX =0MOVW! String transfer instruction, from [si] Move CX words to [diSecretariat From start to here, this program will bootsect from0x07c0Copied to0x9000Place Jmpi go,initseg! Jump between segments, initseg refers to the segment address that jumps to, and the label go is the offset address within the paragraph.go: mov Ax,CSSet Ds,ss and Es to the segment where code is copied after the code.mov DS,Ax    mov es,Ax! PutStack  at 0x9ff00.mov SS,Ax    mov SP,#0xff00! Arbitrary value >> +Sets the top pointer of the stack, much larger than +byte offset.LoadThe setup-sectors directly after the bootblock.! Note that' es 'is already set up.! Load the Setup module code data, note that ES already points to the0x9000No more settings. Read Setup from the second sector of the disk0x90200At the beginning, read together4A sector. If there is a read error, reset the drive and reread.Load_setup:    mov DX,#0x0000! Drive0, head0to the drive0To operatemov CX,#0x0002! Sector2, track0      mov BX,#0x0200! Address = +,inchInitsegmov Ax,#0x0200+setuplen! Service2, NR of Sectorsint0x13! Read itJncOk_load_setup! Ok-continuemov DX,#0x0000    mov Ax,#0x0000! Reset the disketteint0x13J Load_setup! J is the JMP directiveOk_load_setup:! Get disk drive parameters, specifically nr of sectors/track! Get disk parameters, especially the number of sectors per channelmov DL,#0x00    mov Ax,#0x0800!AH=8is get drive parametersint0x13    movCH,#0x00SegCS    movSectors,CX    mov Ax, #INITSEGmov es,Ax! Print Some inane message displays the string that MSG1 points to on the screen,"Loading system ..."    movAh,#0x03! Read Cursor posXORBH,BH    int0x10        mov CX,# -    mov BX,#0x0007! Page0, attribute7(normal)mov BP, #msg1mov Ax,#0x1301! Write String, move cursorint0x10! Writes a string and moves the cursor to the end of the string. OK, we' ve written the message, now start loading the system module at 0x10000 (64KB)! We want toLoadThe System ( at 0x10000)mov Ax, #SYSSEGmov es,Ax!segmentOf0x010000    PagerRead_it! Read the system module on the disk, ES is the input parameterPagerKill_motor! Turn off the drive motor so you know the status of the drive. After the We check which root-device to use.IfThe device is! Defined (! =0), nothing was done andThe given device is used.! Otherwise, Either/dev/ps0 (2, -)or/dev/at0 (2,8), depending! On the number of sectors the BIOS reports currently.! Determine which root file system seg is selectedCS    mov Ax, Root_devCMP Ax,#0    jneroot_defined SEGCS    mov BX, sectorsmov Ax,#0x0208! /DEV/PS0-1.2MbCMP BX,# the! Determines whether the number of sectors per track is the    JEroot_definedmov Ax,#0x021c! /DEV/PS0-1.44MbCMP BX,# -! Determines whether the number of sectors per track is -    JEroot_definedUndef_root:    jmpUndef_root if the root file system device is not correct, the loop is dead.root_defined:SegCS    movRoot_dev,Ax! Save the checked device number to Root_dev! After this (everyting loaded), we jump to! The Setup-routine loaded directly after! The Bootblock:jmpi0, Setupseg!  All the files here have been loaded and the program jumps to the setup file to execute.!!!!! Bootsect.s execution is over here. Here are two sub-programs. This routine loads the system atAddress0x10000,Making sure! No 64kB boundaries is crossed. We try toLoadit as fast as! Possible, loading whole tracks whenever we can.!!inch:es-Starting Addresssegment(Normally0x1000)!sread:.Word 1+setuplen! Sectors read sector number in current trackHead:.Word 0! Current head Magnetic Number oneTrack :.Word 0! Current track numberRead_it:    mov Ax,es    Test Ax,#0x0fffDie :    jneDie!esMust be at64kB boundaryXOR BX,BX!BXis starting address withinsegmentRp_read:    mov Ax,es    CMP Ax, #ENDSEG! Have we loaded all yet?JBOk1_readretOk1_read:SegCS    mov Ax, sectorsSub Ax, Sreadmov CX,Ax    SHL CX,#9    Add CX,BX    JncOk2_readJEOk2_readXOR Ax,Ax    Sub Ax,BX    SHR Ax,#9Ok2_read:    PagerRead_trackmov CX,Ax    Add Ax, Sread segCS    CMP Ax, sectorsjneOk3_readmov Ax,#1    Sub Ax, headjneOk4_readIncTrackOk4_read:    movHeadAx    XOR Ax,AxOk3_read:    movSread,Ax    SHL CX,#9    Add BX,CX    JncRp_readmov Ax,es    Add Ax,#0x1000    mov es,Ax    XOR BX,BX    jmpRp_readRead_track:    Push Ax    Push BX    Push CX    Push DX    mov DX, trackmov CX, SreadInc CX    movCH,DL    mov DX, headmovDH,DL    mov DL,#0     and DX,#0x0100    movAh,#2    int0x13    JCBad_rtPop DX    Pop CX    Pop BX    Pop Ax    retBad_rt: mov Ax,#0    mov DX,#0    int0x13    Pop DX    Pop CX    Pop BX    Pop Ax    jmpread_track/* * This procedure turns off the floppy driveEnterThe kernelinchA known state, and* Don' t has to worry about it later.*/Kill_motor:    Push DX    mov DX,#0x3f2Floppy control card Digital output register (DOR) port, write onlymov Al,#0!    A drive, turn off FDC, disable DMA and interrupt requests, turn off the motor. Outb! Outputs the contents of Al to the port specified by DX.Pop DX    retSectors:.Word 0Store the number of storage sectors per track for the current boot floppy.MSG1:Call the BIOS to interrupt the display of the information.byte  -,TenEnter the Ascⅱ code for the newline. ASCII"Loading system ...".byte  -,Ten, -,Ten! Total -A Ascⅱ code character.org 508! Represents the statement from the address508(0X01FC) starts, so root_dev in the boot sector508Started with2Bytes in a single byte.Root_dev:.WordRoot_dev! The device number where the root filesystem is stored (used in INIT/MAIN.C)Boot_flag:.Word 0xaa55The boot disk has a valid boot sector flag that is used only when the BIOS program loads the boot sector. It must be in the last two bytes of the boot sector: textEndtext:.DataEnddata:. BSSENDBSS:

Linux kernel 0.11 bootsect file description

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.