The art of Linux kernel design--Loading kernel code

Source: Internet
Author: User

After the BIOS triggers a 0x19 interrupt, the first sector (512B) of the disk is loaded into memory. The computer really starts running programs on disk. And this 512B program is BOOTSECT.S, 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?

</pre><pre name= "code" class= "cpp" >syssize = 0x3000                        //kernel program size Setuplen = 4// The setup program to be loaded is in the unit number of sectors bootseg  = 0x07c0//boot sector is loaded in the BIOS location, which is now in the location initseg  = 0x9000// Bootsect.s the location to be moved to SETUPSEG = 0x9020//setup program to be loaded starting position sysseg   = 0x1000//kernel load start position endseg   = sysseg + syssize Kernel End Position Root_dev = 0x306                        //device number of the root file system


The code above declares the assignment of a series of variables for memory planning

</pre><pre name= "code" class= "CPP" >entry Startstart:movax, #BOOTSEG             //movds,ax                   //movax,# Initseg             //This code is the code of Bootsect from 0x07c0moves,ax                   //Copy to 0x9020 movcx, #256                 //subsi,si                   //subdi,di                   // Rep                             //        MOVW                            //

</pre> because in later programs, the location before Bootsect is overwritten by other programs. So you need to move the location of the Bootsect program to 0x90200 <p></p><p></p><p> after the copy is complete. Immediately after running </p><p></p><pre code_snippet_id= "403621" snippet_file_name= "blog_20140623_7_6144482" Name= "code" class= "CPP" >jmpigo,initseggo:movax,csmovds,ax


This command means to jump to the new copy of Bootsect where go continues to run

This time. Start loading Setup (SETUP.S) into memory

It's still the same, loaded into setup, just this time a series of information is specified by the Register to facilitate interrupt service program access to disk


LOAD_SETUP:MOVDX, #0x0000//Specifies that the head is a No. 0 movcx, #0x0002//specified in the 2nd sector. No. 0 Track Movbx, #0x0200//setup Physical address in Disk Movax, #0x0200 +setuplen//Specify end location int0x13//Interrupt Read disk jncok_load_setup//load complete, run Ok_ LOAD_SETUPMOVDX, #0x0000movax, #0x0000//reset disk Int0x13jload_setup


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

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


To this step. Bootsect's work is finished. At this point, the kernel code has been loaded into the memory, but in the direct running kernel program is another way to go, the next article will explain how to prepare for kernel code run

The art of Linux kernel design--Loading kernel code

Related Article

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.