Most of the content is from a book by WB. Yang.
1. Installation Tools Required for Linux
Vim, virtualbox, G ++
2. Write your own operating system. If you are too lazy to install an input method in Linux, you have to write comments in poor English. Please bring your own lightning rod when reading.
System Boot Program: boot. s
1. code16 # compile with 16-bit Mode 2. text # code snippet start 3 mov % CS, % ax # initialize stack register, data segment register, and general segment register 4 mov % ax, % DS 5 mov % ax, % es 6 call dispstr # Call the string display function, call function to display string 7 JMP. # While (1), infinite loop 8 dispstr: # string display function 9 mov $ bootmessage, % ax 10 mov % ax, % BP # Es: BP = address of string 11 mov $16, % CX # Cx = length of string 12 mov $0x1301, % ax # Ah = 13, al = 01 H 13 mov $ 0x00c, % BX # page number = bH = 0, word color = bl = 0ch 14 mov $0, % DL 15 int $0x10 # enter the middle section 10 h is interrupt number 16 RET #17 bootmessage:. ASCII "Hello, OS world! "18. org 510 # Fill 0 in first 510 byte 19. Word 0xaa55 # End with 0xaa55
Connection Script: solrex_x86.ld
1 SECTIONS 2 { 3 . = 0x7c00; 4 .text : 5 { 6 _ftext = .; /*program will be loeaded to 0x7c00*/ 7 } = 0 8 }
Compile the connection text makefile
1 CC=g++ 2 Ld=ld 3 LDFILE=solrex_x86.ld 4 OBJCOPY=objcopy 5 6 all:boot.img 7 8 #Step 1:g++ call as, boot.S -> boot.o 9 boot.o:boot.S 10 $(CC) -c boot.S 11 12 #Step 2:ld call link script, boot.o -> boot.elf 13 boot.elf:boot.o 14 $(LD) boot.o -o boot.elf -e c -T$(LDFILE) 15 16 #Step 4:objcopy remove the useless section(such as .pdr, .commemnt, .node) i n boot.efl, strip all signal information, the output is boot.bin 17 boot.bin:boot.elf 18 @$(OBJCOPY) -R .pdr -R .comment -R .note -S -O binary boot.elf boot.bin 19 20 #Step 4:generate bootable software image 21 boot.img:boot.bin
Boot. S-> boot. O-> boot. Elf-> boot. Bin-> boot. img
3. Generate OS image files
Put the preceding three files in the same directory and input make to generate boot. IMG in the same directory.
4. Load and run
Run virtualbox
A new operating system
Setting-> storage-> Add controller-> Add Floopy deviec-> choose disk-> import the boot. IMG generated in the previous step
Start