WHEN Do We Write Our Chinese OS? (1)

zhaozj2021-02-16  53

The operating system is the core of the computer, there is no operating system, all computer applications are free, but the operating system is basically monopolized by foreigners, Windows will not say, even if Linux is also Bohu, when can we write Chinese characteristic operating system? At the University, each of us has learned the operating system, I am the same, but the teacher is really just theory. An actual system is complicated more than 10,000 times better than the teacher! However, we basically do not have the opportunity to practice, even if there are some experiments, it also stays in a very high surface. I am very stupid, after learning, I still don't know how the system is from nothing, starting working. How is the system started? I used to write a assembly code into the disk, but no matter how it didn't start the machine (the reason is now clear, talk later). I want to see Linux source code, but it is like a book! Even if minix is ​​very large, it is difficult to understand! Depressed ~~~, today I accidentally saw an old-written E text, telling this, Hawran cheerful, after mad, I found a bunch of E text, and finally played the machine. (I have no bottom, basically, basically use Jinshan word tyrannical translation, pain! It seems that I want to learn computer E text is not good, I can't really: (, many information Chinese is No, only E text, what do you do?). Nowadays describe the whole process, let a commemoration, two people hope that the University can have more people to be interested, the super big cow is written as soon as possible. Our own operating system. LINUX is also a college student in Finland. Read this article is best there is a compilation basis for the dock. In addition, the level is extremely limited, and the operating system is not very familiar, and the number of mistakes in the discussion I hope everyone is forgiven, don't cut me ~~~ First, I will first explain how the computer does after you press the power button, what you do when you press the power button, together with this button The wire will send an electric signal to the motherboard. The motherboard passes the electrical signal to the power supply system. The power supply system starts to work, and the entire system is powered, and a electrical signal is sent to the BIOS, and notify the BIOS power supply system is ready. Program, host self-test, main computer self-test main work is to ensure that each part of the system has received power support, internal memory, other chips, keyboard, mouse, disk controller and some I / O ports available, and some I / O ports. Since then, the self-test program will control the control to the BIOS. Next, the BIOS starts to start the operating system. BIOS will access the first sector of the startup disk (0 track, 1 sector, a total of 512 bytes), BIOS will this The content in the first sector is transferred to the 0x7C00 address of the memory and starts to execute it. This is the first level of the start system. From then on, the system will give the control to the operating system, and the things left by you The program is completed. Now our task is to write such a program, the system calls it as a boot program, use it to guide or say to launch our computer. It has the following two features: 1. Size can only be 512 words Section, not one byte, can not be less than one byte. Because BIOS can only read 512 bytes of data into memory, many part BIOS will not reason hard 2. It must end with "55? Aa", That is, the last two bytes (511, 512) must be them.

This is the sign of the end of the guide area, without its BIOS does not treat it as a boot program. (I didn't execute before, because I didn't write "55? Aa" here) put this program on disk 0 track, 1 sector, this, this disk can be used to boot the system, and use Your own boot process! Before you start making a boot process, let's introduce how to develop this in a Windows environment. First, you need an experimental environment, you can of course use a real computer, if you have multiple computers, don't feel trouble. Here we use virtual machines to perform experiments, it is the same as using real computer, do not believe you can experiment with yourself. I am using it? MS? Virtual? PC, very simple use, here is here, it can use a 1.44M size IMG file as analog floppy disk, so we just write our boot program to In an IMG file, you can use it to boot the system as you write on a disk. After starting the virtual machine, under the FLOOPY menu, select the FLOOPY® Disk? Image item, and then select it to the IMG file we generated, you can. Let's talk about the creation of the IMG file to write the boot program to this 1.44m file. I use the WinHex tool. It is very convenient to pass the write to the binary file directly, and you can also create a specified size. document. 1.44M IMG file can be created with WinHex, click New Buttons to make a line, size input 1474560, unit byte. When you arrive, use the program we wrote with WinHex, and then copy its content to the generated IMG file. These tools are connected in the experimental procedures described in this article, you can download ftp://202.118.239.46/incoming/other/btc/temp/os_test/os_test.rar by the following address, then introduce one of this program to use The only BIOS interrupt, int? 0x100x10? Interrupt is the BIOS display interrupt, all outputs need to call this interrupt, you need to set the value of a part of the register to tell BIOS how to output AH?:? 0x0E? Typewriter mode, Tell the BIOS, output the characters to the screen on the screen?:? Page BL?:? Text property Al?: • Want to show the ASCII code of the characters, and we can create our bootstrap, the complete source program is as follows : [BITS? 16] ???????????????????????;? Tell the compiler, compile into 16-bit programs

[ORG? 0x7c00] ??????????????????????????????;? Tell the compiler, the code will start from 0x7C00

Main: ???????????????????????????; main program?

MOV? AX?,? 0x0000 ?????????????????;? The following two sentence setting data segments are 0000

MOV? DS?,? AX

MOV? Si?,? message ???????????????;? set the base pointer

Call? ShowMessage ???????????????; call display function

JMP? $ ???????????????????????????; $? represents the address of this statement, indicating that this statement is infinite loop

ShowMessage: ???????????????????;? Display function

MOV? AH?,? 0x0e ??????????????????;? Set the current mode

MOV? BH?,? 0x00 ??????????????????;? set page code

MOV? BL?,? 0x07 ??????????????????;? Set font attribute nextchar:

Lodsb ??????????????????????????; ?? Character load instruction

?????????????????????????????????;? It puts the SI in the DS data segment into the source string of the offset address A character takes out to send Al,

????????????????????????????????; simultaneously modify Si point to the next character

OR? Al?,? Al ?????????????????????;? Test string is 0

JZ? RETURN ?????????????????????????????????;? If zero indicates the end of the string, jump to the return instruction to return to the original call function

INT? 0x10 ????????????????????????;? Call BIOS? No. 10 interrupt display character

JMP? nextchar ????????????????????;? Continue to display the next character

Return:

RET ????????????????????????????;? Returns the original call function

Message:

DB? 'CAN? WE? WRITE? A? Chinese? OS ??';? Defining Display Message

DB? 13?,? 10?,? 0 ????????????????????????????;? 13? Represents to the carriage return, 10? Continued to the next line? 0? indicates the end of the string ?

Times? 510? -? (? $? -? $$?)? DB? 0 ????;? Fill? 0? to meet the file size 512 bytes?

????????????????????????????????;? $? Indicates the address of the current statement, $$? Represents the start address of the program

DB? 0x55?,? 0xaa ?????????????????; end sign

After entering it with any file editor, save it as Test.asm and compile it with a assembler. I use NASM, enter? NASM? Test.asm compilation, will generate one? Test? File, use WinHex Open it, then you will write it to an IMG file, you can try to start the computer with your own program. You can also write it directly to the disk with WinHEX, start on the disk, this feeling is very cool ~~~ below is its operation results

A operating system is very complicated, here is only an experience of an experiment, it only completed the system to start this step, strictly said that the bootloader is not an operating system, although it is extremely important, in general, it needs to take real The kernel load of the operating system is loaded, and then jumps to the true kernel with a JMP instruction. Throwing bricks, I hope some people can make a Chinese core, and have a practical operating system with independent intellectual property. There are countless mistakes, I hope that the teacher's heroes don't finish, and the same good people discuss research learning ~~~ Leave a mail:? _ Xiao_han_@126.com? ^_^

Original: http://purec.binghua.com/Article/showArticle.asp? ArticleId = 1

转载请注明原文地址:https://www.9cbs.com/read-20498.html

New Post(0)