Recently in the "do-it-yourself-write operating system" Yu Yu, see the first page is covered, the book said to prepare a blank floppy disk, all 2010 years, where to find a floppy disk ah, since the contact with the computer I have not seen a floppy, it is estimated to go to the Science and Technology Museum to find it, hehe. In fact, in the second chapter-to build your work environment, the author mentions that it is not necessary to use a real floppy disk, the virtual floppy image can be, that is, *. IMG file, in turn think, even the computer can be virtual, floppy, of course, can also be virtual. Floppy image files do not need to make their own, with the book attached to the CD in the source code inside (Tinix. IMG), compile your own compilation source code into a *.bin file and use the floppy disk absolute sector read-write tool provided by the author Floppywriter write *.bin to tinix.img, so that a virtual boot disk is completed. The Floppywriter tool is in the Tools folder of the CD. If there is no disc also do not matter, can be downloaded from the blog point of view website, the URL is: http://www.broadview.com.cn/01577 (need to log in first), can also be in HTTP://OSFROMSCRATCH.ORG/DOWNLOADCN Download the source code.
First, start to build the working environment:
1. One computer (Windows operating system)
2. Virtual Machine VirtualBox
Can be downloaded on the official website, download address: http://www.virtualbox.org/wiki/Downloads
VirtualBox is chosen because it is open source free, the speed can also, the author uses Virtual PC 5.0, the virtual machine is commercial software, 5.0 version of the comparison is difficult to find, Can be found on the Internet 5.2 version, but I download the installation can not run normally, prompted not to run in PAE mode, although the network can find a solution, need to do some configuration of the computer, but feel trouble, personal or like to use VirtualBox, download after installation without any problems.
3. NASM Compilation Program
Download Address: Http://sourceforge.net/projects/nasm
or official website download: http://www.nasm.us/pub/nasm/releasebuilds/
This is used to compile the assembler we wrote, used to MASM, but the author recommends this.
4. Floppy disk absolute sector read/write tool FloppyWriter.exe
Available in the CD-ROM attached to the book, under the Os/tools/floppywriter/release folder, run the program has two buttons to choose, using a floppy image, use the following write File to image. As mentioned earlier, if there is no disc, you can go to the Internet to download the contents of the CD.
5. Source Code Editor
You can use Notepad, or you can use other editing tools.
Second, write a small "operating system"
1. Write the source code: (The book has)
org 07c00h; Tell the compiler that the program is loaded at 7C00
MOV ax, CS
MOV ds, ax
MOV es, ax
Call Dispstr; invoke display string routines
JMP $; infinite loops
mov ax, bootmessage
mov bp, ax; es:bp= string Address
MOV cx, 33
mov ax, 01301h; ah=13, al=01h
mov bx, 000ch; page number 0 (bh=0) black-bottom Scarlet Letter (bl=0ch, highlight)
mov dl, 0
int 10h; interrupt number 10h
Bootmessage:db "Hello Lijie, Welcome to OS world!"
Times 510-($-$$) DB 0; Fills the rest of the space so that the generated binary code is exactly 512 bytes
DW 0xaa55; end Flag
2. Compiling boot.asm
After installing or decompressing nasm, add the NASM installation directory to the PATH environment variable and you can use the NASM command in any directory on the command line. Enter the source code in the directory, enter the command NASM Boot.asm-o Boot.bin after the return of the source code to complete the compilation.
3. Write Boot.bin to Tinix.img
Copy the tinix.img file from the CD source to your source code directory, run FloppyWriter.exe, click on the write file to Image, select Boot.bin and tinix.img in the pop-up window respectively, prompt success OK.
4. Running in a virtual machine
A. Create a new PC in the virtual machine
Start virtualbox-> new name any fetch, operating system selected Other,version other/unknown-> memory default (can be changed), create a new virtual hard disk--dynamic expansion, Select the virtual hard disk save address or default, size default (can be changed), complete.
B. Registering the tinix.img with the VirtualBox
Management (f), Virtual Media Management (V), virtual floppy disk (f), registration (A), in the pop-up window, locate the newly completed tinix.img open, OK.
C. Run the PC you just created
Select the type of media that you just created, First Run wizard, next to the pc->, choose Floppy drive, media location Select just registered tinix.img-> next and finish. OK, you should be able to see which line of black red words, hehe.
The second method:
Recently in the amateur reading to find a "write your own operating system" feel good, the perspective is very novel, is about the operating system books in the few read the reading do not want to sleep.
Since the book was published earlier, the guide disk in the book was also used as a floppy disk, so it was difficult to follow the first experiment code. This is a record of the results of the final experiment.
The first experiment in the book is to write a piece of assembly code as a bootloader, compile the binaries to the boot disk (the book uses a floppy disk), and then let the computer boot from the floppy disk to execute our boot program.
First give the Guide program in the book--boot.asm
MOV ax, CS
MOV ds, ax
MOV es, ax
mov ax, bootmessage
MOV bp, ax
MOV cx, 16
mov ax, 01301h
MOV bx, 000ch
mov dl, 0
Bootmessage:db "Hello, OS world!"
Times 510-($-$$) DB 0
The next step is to compile the assembler code, so we have the first question: what compiler to choose. How to compile the code.
The book recommended the use of NASM, as to why to choose NASM, we can Baidu a nasm the birth of the story, it was born because of the various disadvantages of compiling compilers, and finally spawned NASM this relatively useful compiler.
Install NASM. NASM does not have a graphical interface, either in DOS or under Linux. My Computer is Win8+ubuntu virtual machine, so decisively choose to install NASM in Ubuntu, just need to knock on the terminal apt-get install NASM, and then wait for the installation to complete. After the installation test:
After installing the compiler, copy the code written in Windows to Ubuntu and compile it with the compiler, and find an error. The compiled binary file Boot.bin size is 0, not the 512 bytes we expect. So in Ubuntu under the VI Open our Assembly code to see, found: In the code there are a lot of "^m" characters. Oh, I used the DOS file in the UNIX under the compilation, no wonder the compiler does not know. Note: Under DOS format, carriage return line is 0x0d0a, and Unix is 0x0a, so when the DOS format file under Unix 0x0d will become "^m" this control character. There are many ways to solve this problem, and I am directly in the UE to change the file to be edited in UNIX format: After modifying the format, under Ubuntu can be compiled correctly. Generates a 512-byte binary file, Boot.bin. The following is the question of making a startup disk. You know, it's impossible for a computer to start using a floppy disk. But we have a thing called a virtual machine-it can provide us with a "floppy" interface, but also a virtual interface. Virtual machine I'm using VM player and I'm not using workstation because the new version of the player is powerful enough. Set up your own virtual machine as shown below, but choose to boot from the floppy when you drive the selection. We have to provide an image file for the floppy disk, but before compiling the boot.asm file, we get the binary file Boot.bin. Online there are many ways to package the bin file into an img file, in fact, we will find a simple analysis, the conversion of the two actually only need to change the suffix name in Windows ... The reason is that the img file, which is the image file, is originally a binary level copy of the data on the floppy disk, and our bin file itself is a binary file, so for memory or storage devices, in this place the IMG and bin files are exactly the same. After you change the boot.bin suffix to boot.img, you can let the virtual machine load it. Then go ahead and start your "OS".