Linux Kernel series-9. Loader for Operating System Development and linuxloader

Source: Internet
Author: User

Linux Kernel series-9. Loader for Operating System Development and linuxloader

An operating system starts running from boot to boot, and generally goes through the process of "boot-> loading the kernel into memory-> jumping into protection mode-> starting to execute the kernel. That is to say, before the kernel starts to execute, we should not only load the kernel, but also prepare a series of work such as protection mode. If all work is done by the Boot Sector, 512 bytes may not be enough, therefore, we may wish to hand over this process to another module. We call this module Loader. The boot sector is responsible for loading the Loader into the memory and giving control to it. Other work is safely handed over to the Loader because it does not have a limit of 512 bytes and will be much more flexible.

For ease of operation, make the floppy disk in FAT12 format. In this way, the operations on the Loader and the Kernel will be very simple.

The boot sector is the 0th sector of the entire floppy disk. The FAT12 format is as follows:

Loader source code:

Org0100hmovax, 0B800hmovgs, axmovah, 0Fh; 0000: Black Bottom 1111: White moval, 'L' mov [gs :( (80*0 + 39) * 2)], ax; the screen stops at 0th rows and 39th columns of jmp $;

Then execute the command

Nasm boot. asm-o boot. bin

Nasm loader. asm-o loader. bin

First, use bximage to generate a floppy disk image, and then in linx, because in linux, only/mnt/hgfs/

Dd if = boot. bin of = a. img bs = 512 count = 1 conv = notrunc

Sudo mount-o loop a. img/mnt/hgfs/

Sudo cp loader. bin/mnt/hgfs/-v

Sudo umount/mnt/hgfs/

The running result is as follows:

The character "L" is displayed ".

If you want to run the previously learned clock interrupt program as follows

It can run on a virtual machine, which indicates that the limit of 512 bytes has been exceeded.

Now we assume that we already have a kernel, and the Loader must load it into the memory, and the kernel must be in the protection mode when it starts to run. Therefore, loader must do at least two things:

1. Load the kernel into the memory

2. Jump-in protection mode

 

 

Source 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.