運行自己的作業系統(linux版) -0.01

來源:互聯網
上載者:User

大部分內容來自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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.