Linux0.11 Core Series-1. Bootloader Analysis

Source: Internet
Author: User

1. Introduction

This article mainly introduces three files Bootsect.s, SETUP.S, Head.s, mainly to do some load the kernel from the floppy disk and set up 32-bit protection mode operation.

2. Program Analysis

When the PC power is turned on, the BIOS self-test will bootsect read into the memory absolute address 0x7c00 at the end of the BOOTSECT.S:

. Word 0xaa55

It then jumps to the 0x7c00 and gives execution to the code here, starting at start: execution.

Bootseg  = 0x07c0initseg  = 0x9000start:movax, #BOOTSEGmovds, Axmovax, #INITSEGmoves, AXMOVCX, #256subsi, Sisubdi,direpmovwjmpigo,initseg

BOOTSEG is the segment address of the current program's starting memory address, INITSEG represents the segment address of the memory address that Bootsect is about to move, which means to repeat the MOVW instruction 256 times, each time from Bootseg (0x7c0 segment address) + The address of SI moves a word (2 bytes) of data to Initseg (0x9000 segment address) +di address, move 256 times, so the total is 256 words (512 bytes), BOOTSECT.S compiled out is 512 bytes of size. So after this code is executed, it is to copy itself to the 0x90000 address, and then Jmpi jump to 0x9000 's offset address for go place execution.

So then the program executes to go: At the beginning of the whole program, the address becomes the 0x9000,go code set the next stack, followed by the Load_setup:

Setuplen = 4LOAD_SETUP:MOVDX, #0x0000! Drive 0, head 0movcx, #0x0002! Sector 2, Track 0MOVBX, #0x0200! Address = +setuplen!, in Initsegmovax, #0x0200 Service 2, nr of sectorsint0x13! Read itjncok_load_setup! OK-CONTINUEMOVDX, #0x0000movax, #0x0000! Reset the Disketteint0x13jload_setup

Using the BIOS interrupt int 0x13 to read setup from the 2nd sector of the disk to the beginning of the 0x90200, a total of setuplen (number of sectors of the Setup program) to read 4 sectors. Jump to Ok_load_setup after success.

Setupseg = 0x9020ok_load_setup:...movax, #SYSSEGmoves, ax! Segment of 0X010000CALLREAD_ITCALLKILL_MOTOR...JMPI0,SETUPSEG

The omitted code is some data that reads hard drives and drives. The key here is call Read_it, which calls Read_it:

Syssize = 0x3000sysseg   = 0x1000endseg   = sysseg + Syssizeread_it:mov ax,estest ax, #0x0fffdie: jne die! es must bes at 64kB Boundaryxor bx,bx! BX is starting address within Segmentrp_read:mov ax,escmp ax, #ENDSEG! We loaded all YET?JB Ok1_readretok1_read: ...

Syssize is the size of the compiled system module, SYSSEG is the address of the memory segment to which the system module will be loaded, so the value of ENDSEG is the segment address where the system module stops loading. Then the role of READ_IT is to determine whether ES is to the system module stop loading the segment address, if not the jump to read the system module to this address. The RET returns after loading is complete. Then turn off the motor after reading some drive information, and finally Jmpi 0,setupseg jump to 0x9020:0000 that is the beginning of the SETUP.S program.

Bootsect.s to this end, so far the core of the various modules in memory position as in the 3rd step:

Next go into SETUP.S.

Not to be continued

Linux0.11 Core Series-1. Bootloader Analysis

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.