Super simple Boot Sector

Source: Internet
Author: User

Write a simple bootsector that is similar to guiding and guiding.

 

Microsoftxiao@163.com

 

First, let's talk about some other things. Are you a programmer interested in the operating system? Are you programming? Are you a college student? If you are a software developer, do you use your spare time to develop an open-source project?

 

First, I would like to answer my question. I have a strong interest in operating systems. I have been a college student. Now I am not. I am not engaged in software development, but I am engaged in game development, I have an amateur project, but it seems that development is limited.

 

Okay. Now I am on the topic. Have you read the manual editing operating system? After reading this, I will post the first example of the book below. Then, in combination with my feelings, this article is used.

 

The most exciting example of this book is the first example. Yu Yuan made beginners excited before introducing the background and required pre-knowledge, after a while, I wrote a simple boot program based on 80x86 assembly. It can run on IBM PC, but it cannot guide loader and kernel.

 

The Code is as follows:

Org 0100 h; com format

; Org 07c00h

 

MoV ax, CS

MoV ds, ax

MoV es, ax

Call printstr

JMP $

 

Printstr:

MoV ax, helloworld

MoV bp, ax

MoV CX, 24

MoV ax, 01301 H

MoV BX, 000ch

MoV DL, 0

Int 10 h

RET

 

Helloworld: DB "Welcome to Lee's OS *_*";

Times 510-($-$) db 0

DW 0xaa55

I will not explain the code. It does take some compilation basics to understand it.

But now I want to simplify this bootsector because it is easier to understand simple things. The following is my simplified bootsector.

; Org 100 h; com format

Org 7c00h

JMP $

DW 0xaa55

Well, this most streamlined Bootstrap actually only needs four lines.

Org is used for addressing. Each segment can be initialized to the same base address. If it is executed on a bare metal instance in ibm pc, the program is loaded to 100 h or H of memory.

However, org H compiles the code into com format.

The JMP $ command indicates that the current line is always repeating, which is an endless loop.

DW 0xaa55 or dw 0xaa55 indicates the Boot Sector.

Now, I will give you some instructions for your reference.

With such a small boot sector framework, you can use everything you know about the bios and interrupt service programs in 80x86.

If you are familiar with BIOS calling, but do not know how to write bootsector, you can easily expand it now, but no matter how you write it, you know that the amount of code you write exceeds 512 bytes, you can use the Virtual Machine Virtual PC VMware bochs to test.

 

For normal expansion, I will demonstrate how to output a character a on the screen and use BIOS 10 for interruption.

Org 7c00h

MoV ax, 0e41h

Int 10 h

JMP $

DW 0xaa55

In this way, the character A can be output on the VM and the loop is endless.

 

So far, the mysterious bootsector can be as simple as this.

Well, the following describes what you need to learn in depth, the first protection mode, the second BIOS call, and the key to learning about writing interrupt service programs in BIOS.

Use BIOS 13 h to load other programs, loader kernel, etc.

 

In addition, programs written on bare metal can help to digest the protection model knowledge in this way. Because today's ibm pc's 32-bit and 64-bit user software is protected by virtual addresses, permissions, and other operating systems supporting the processor. Therefore, our general applications work in the protection mode and work with the minimum permissions.

However, some programs work under the highest permission, and the highest permission is ring0. So what are these programs? First, system programs, including drivers and various core programs.

The second type of Security Program, the third type of anti-virus program, and the fourth type of debugging program.

Although we may not need to write the operating system, we have to understand the details of the operating system for the writing tool software to let us know what operations the operating system has performed on our programs, 1. Why is the error? Is it because of us or the user. In addition, there are not only Operating System bugs, but also Intel processors.

We just don't know.

 

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.