[Bootloader] initial System

Source: Internet
Author: User
[Bootloader] initial System

1. Websites for reference:
(1) Absolute classic Website:
Operating System Resource Center
This website is good and cannot be expressed in words ............

OSD home
Good!

OS Dev
Not bad.

Execpc
Come and have a look ......

Http://www.xemean.net/
Compiled OS: menuetos
This website has a lot of compilation materials and hardware programming materials.

(2) Search for outportb !? Recommended websites
PC-hardware
Vgadoc
One vag package
Execpc ConsoleCode

(3)
Openblt
Reactos
Brainix team
V2os
Nachos
Thix
Hello
AROs
Kerne Link
OS file
File Format

(4) recommended methods for using BIOS output text in real mode
Ralf Brown's famous interrupt list
Recommended freshground (old hand)
BiOS interrupt table

2. Before starting to compile the OS, consider the following:
1. Why write OS?
Research: higher, stronger, and better
High Availability, higher performance, real-time, distributed, object-oriented, easier porting, challenging business, challenging yourself, and new architecture.

Learning
Multi-task, memory protection, C library tagging, device driver, file system, and Application

Interest
Just like it!

2. design decisions
Portability
Limited by Intel? Using x86-only features? Four privileged levels (most machines have only two), segment-based address conversion and protection (generally with paging), and tsses Task Switching (vs. Stack switching ).

Kernel System
Linux? Monolithic kernel? Microkernel? Exokernel? Sasos? .

Multi-task
Not Supported? Collaboration? Preemptive scheduling?

Thread
None? Does the Kernel support process collaboration? How to coordinate the address space between the same thread?

Multi-processor
Not Supported? Tightly coupled SMP? Loose distributed?

Multiple users and security

Development Workstation
Linux? No sourceinsight!
Win? ...........

Development language
C ++ ASM ......

Executable File Format
Is dynamic link supported? (Like elf and PE, they are simple)

Advanced Language Library
GNU glibc, Cygnus newlib, homebrew ,.........

Compatible?

Code plagiarism
Code for learning .......

Iii. Initial versions 0.0.1 to 0.0.5

Do I need to write my OS from a simple bootsect?
The following website provides some suggestions:
Do not write bootloader. At least do not regard it as the first thing to write OS.
Bootloader is not an OS.
Bootloader is only a very small part of the OS.
Writing a better bootloader is equivalent to writing a small OS.
Writing a bootloader requires some mysterious knowledge, such as A20.
If it is developed in DOS or Windows 9x, you can use dos as your boottloader. How do you see grub.

But why not write your own?
Since it is so mysterious, since there are a huge number of open-source bootloader..., it is quite good to copy some code and trim it.

Do you choose to write or not? Do not hesitate to spend half a year in the middle of the night... write !? Some research on bootloader
In bootloader, version 0.0.5 has the following features:
1. Boot mounting setup + OS to 0x10000
2. In real mode, jump to setup, and setup moves the OS to 0x100000 (1 m)
3. Switch to the protection mode and use a long line to jump to jmp dword 8: 0x100000.
(NASM can mix 16bit and 32bit code)
4. c ++ is used.
1). setup. s reserves 2048 (0x800) bytes for future use.
2). setup. s reserved space. The location of setup to move the OS (next to setup) should be consistent.

Summary:
The system runs from 1 MB. It is like an operating system loader !!!!!

The first version 0.0.1 is the first step, which may take the longest time.
0.0.1 is the smallest thing.
It is equivalent to a hello wold!
I wrote it in win, but I don't know where VMware is, and I don't know partcopy. only DD and GCC in Linux are recommended. only a few simple lines of information on the screen can be seen after being moved to Linux. the feeling is really incomparable. that is midnight. the eve of the year of China.

For this reason, the printed minix bootsect is held on sleepless nights, and the bootsect of linux0.0.1 looks like this .... so far this mark is still in the code. I am not really interested in reading OS code from floppy, so it is still the same as Linux.

If you do not have make binary use C compier and nondot, it is estimated that the birth of 0.0.1 is not possible for the current write.
In makefile 0.0.1, the most useful sentence is:

# Convert the generated operating system file from ELF format to binary format
OS. Bin: OS. Elf
Objcopy-R. comment-R. Note-S-O binary OS. Elf OS. Bin


From nondot.Article.

This makefile may be worth reading:

....
Objs = c. o
.......
OS. Elf: $ (objs)
$ (LD) $ (objs)-o OS. Elf-E c-ttext 0
# Because our image is in binary format.
# So the entry point function should be the first function in the First. o file.

Sorry, head. S. is not used in 0.0.1.
Only boot. S and C. C.

Boot. s loads the binfile OS. Bin generated by C. C from the disk to the memory, switches to the protection mode, and jumps to OS. Bin.
Look at

# Generate the final file bootimg
Bootimg: OS. Bin boot
Cat boot OS. Bin> bootimg
# Boot is the content of the boot sector. The kernel OS. Bin follows the kernel sector.

Imagine the entire process.

C. C does not seem to have done anything except printing a piece of information.
The OS. Bin generated from C. C is a 32-bit code and must be protected to run.

/*
Text mode kprint
Show 'C'
Line: x (0... 24)
Col: Y (0... 79)
*/
Void kputc (char C, char color, int X, int y)
{
/* P ponitor to video memory */
Char * P = (char *) 0xb8000;

/* Calc line POS */
P + = 2 * x * 80 + y * 2;

/* Show char whith color */
* P = C;

* (P + 1) = color;
}

To work properly, the base address of the segment described by the sub-selection descriptor of the OS DS must start from 0 and can be read and written. The limit is greater than the video mem ceiling (0.0.1 is 8 m, see boot. s ).

0.0.1 is the light of my hope.
0.0.1 is too simple to know what he can do.
In 0.0.2, it seems that C. C is just involved and there is no substantive work.

0.0.3 contains two files, setup. s and head. S. which can be seen in makefile.
The key is that the protection mode is no longer switched in Boot. S. In this case, I can do more things in setup. s, because boot. s only has 512 bytes, too little!
We can see that the setting is 0.0.3. S is also very simple. it sets the OS (head. s, C. c) Move to the physical address 0. then use a temporary gdt to switch to the protection mode. finally, jump to the head of the OS. s.
Head. s reloads the OS's own gdt, because setup. S is not part of the operating system!
You can see that setup. S and head. basic functions of S. more importantly, based on this assumption. s, you can write more code to complete more functions before switching to the protection mode. even if I use 16-bit C compiler and bios, it is much more convenient. head. S is mainly an OS entry, which is placed in a single file to facilitate entry management. among them, IDT and gdt make OS global variables more centralized.

Considering that it is not appropriate to place the OS at 0: 0, the OS is moved to 0x20000 in 0.0.3.5 and is located at K of the physical memory.

But I still feel uncomfortable. In 0.0.4, after switching to the protection mode, I put the OS directly in the 1 m place. Leaving the regular memory is the right place.

The LD-T option in makefile clearly shows this change.
I encountered many problems, some of which were recorded but not found.

In 0.0.5, I want to try C ++.
In the new simple kernel, for example, bootloader 0.0.5 ----, there is no multi-task support, no interrupt Mechanism support, and nothing should be done.

How to do some simple I/O in this case may be a concern during the development stage.
Find some information, such as KBD, HD, VGA ......

0.0.5 supports VGA only by operating the default framebuffer, and even the optical mark cannot be moved.
I have recommended many websites for some good foreign information.

Take a look at these materials... we will use them first!


Thanks to the outstanding and selfless contributions of execpc. OSD.

Versions earlier than 0.0.5 are compiled in Linux. At that time, I didn't know much about Boch VMware.
Debugging and its pain. Although the syntax of VIM in Linux is highlighted, it is not very easy for me to use.

I like sourceinsight very much.
I know that the NASM djgpp in Windows is also free, but at that time, I have never compiled a bin kernel under windows.
I tried to find a Linux version with good Chinese support and a tool similar to sourceinsight. Of course I don't want to comment out my code in plain English ....
However, there is no Chinese environment to satisfy you.
When playing Turbo 4.1, it will only be installed,
Now I try to use the OS in Linux .......

Continue to work hard to develop in win .......
In Windows, I can easily find a 16-bit C compiler to enhance the loader.

On this day, we found NASM, VMWare, djgpp .....
Unexpectedly, we were able to bring up a familiar picture under VMware so smoothly.
It's exciting.
In the previous version, if make cannot find a file pad.
This pad is nothing, just to extend bootimg to 1.4m or above during VMware debugging, you can find something to replace!


new features
see readme.txt 0.0.5.1< br> 5. port to djgpp and use gcc nasm in Windows for compilation, and use VMWare for debugging.
at this point, use the following tools: sourceinsight, vmvare, djgpp, and NASM. (This is my dream environment ^_^)
next, we will consider using TC or other compilers to create a 16-bit Program In setup. (use C to enhance setup. s function)

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.