大部分內容來自WB. YANG的一本書,書名忘記了
1.linux所需要的安裝的工具
vim, virtualbox,g++
2.編寫自己的作業系統,懶得在linux上裝個IME,只好用蹩腳的英文寫的注釋,閱讀時請內建避雷針
系統引導程式:boot.S
1 .code16#使用16位元模式彙編 2 .text#程式碼片段開始 3 mov %cs, %ax#初始化棧寄存器、資料區段寄存器和通用段寄存器 4 mov %ax, %ds 5 mov %ax, %es 6 call DispStr #調用字串顯示函數,call function to display string 7 jmp . #while(1),無限迴圈 8 DispStr:#字串顯示函數 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 = 01h 13 mov $0x00c, %bx #page number = BH=0, word color = BL = 0Ch 14 mov $0, %dl 15 int $0x10 #進入中段10h 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
串連指令碼:solrex_x86.ld
1 SECTIONS 2 { 3 . = 0x7c00; 4 .text : 5 { 6 _ftext = .; /*program will be loeaded to 0x7c00*/ 7 } = 0 8 }
編譯串連文本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.產生os的鏡像檔案
把以上三個檔案放在同一個目錄,並輸入make,則在同一目錄產生boot.img
4.載入和運行
運行virtualbox
new一個新的作業系統
setting->storage->Add controller->Add floopy controller->add floopy deviec->choose disk->匯入上一步中產生的boot.img
start