The art of Linux kernel design--Loading kernel code

Source: Internet
Author: User

After the BIOS triggers a 0x19 interrupt to load the first sector (512B) of the disk into memory, the computer actually starts executing the program on the disk. And this 512B program Bootsect.s in the first batch of code, at this time the processor is still in real mode memory addressing the maximum range is 1M (0X0000-0XFFFF), next we look at Bootsect.s in the first batch of code to do?

Syssize =                        size of 0x3000//kernel program
Setuplen = 4//The setup program to be loaded is in the number of sectors bootseg  = 0x07c0//boot sector is loaded by the BIOS, where it is now initseg  = 0x9000// Bootsect.s is about to move to the location setupseg = 0x9020//setup program to be loaded starting position sysseg   = 0x1000//kernel load start position endseg   = sysseg + syssize The end position of the kernel
Root_dev =                        device number of the 0x306//root file system

The code above declares assigning values to a series of variables, which are then used in later code

Entry Startstart:movax, #BOOTSEG             //movds,ax                   //movax, #INITSEG             //This code is to bootsect the code from 0x07c0moves,ax                   Copy to 0x9020 at MOVCX, #256                 //subsi,si                   //subdi,di                   //rep                             //
<span style= "White-space:pre" ></SPAN>MOVW                            //

Because in later programs, the location before Bootsect is overwritten by another program, you need to move the location of the Bootsect program


After the replication is complete, the execution

Jmpigo,initseggo:movax,csmovds,ax


This instruction means to jump to the new copy of Bootsect where go continues execution

At this point, we start loading the Setup program into memory.


LOAD_SETUP:MOVDX, #0x0000//Specifies a No. 0 movcx, #0x0002//Specifies the 2nd sector, No. 0 track movbx, #0x0200//setup Physical address on disk Movax, #0x0200 + setuplen//Specifies the end of the location int0x13//interrupt Read disk jncok_load_setup//loading complete, execution ok_load_setupmovdx, #0x0000movax, #0x0000// Reset Disk Int0x13jload_setup

It's still the same, loading setup, but this time, the register specifies a series of information to facilitate the interrupt service program to access the disk


Then call Read_it to load the system, the kernel module.

Movax, #SYSSEG      //Specifies the location where the system module is loaded in memory Moves,axcallread_itcallkill_motor


At this point, Bootsect's work will be completed, this time, the kernel code has been loaded into memory, but in the direct execution of the kernel program, there is still a way to go, the next article will explain how to prepare for kernel code execution

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.