1. 程式人生 > >學習筆記 |《ORANGE’S:一個作業系統的實現》| (一) Ubuntu

學習筆記 |《ORANGE’S:一個作業系統的實現》| (一) Ubuntu

目錄

bochs的安裝

實驗環境

Ubuntu 16.04 + bochs 2.4.6 + nasm

軟盤製作和nasm編譯彙編檔案就如書裡所示此處略舉。

直接獲取

可以直接使用命令下載,由於版本原因,可能會和書中的操作不一樣導致困惑。

sudo apt-get install

所以下面是下載原始碼包進行編譯安裝的過程

下載bochs

在這個網站下載bochs 2.4.6.tar.gz壓縮包

    tar vxzf bochs-2.4.6.tar.gz
    cd bochs-2.4.6

安裝編輯依賴環境

 sudo apt-get install build-essential xorg-dev libgtk2.0-dev

在configure之後會出現Makefile檔案,修改Makefile檔案在找到 LIBS = … 一行,在行尾加上 -lpthread,儲存

ps:也有看過一篇是修改Makefile.in檔案的但是我是修改Makefile之後才可以的

如果沒有加這個引數後面編譯會失敗。

配置引數開啟除錯功能開關

 ./configure --enable-debugger --enable-disasm

編譯

make

安裝

make install

出現錯誤的話先make clean之後再重新configure,一般出現錯誤都是沒有安裝環境包或者make失敗是因為上面沒有加上編譯執行緒的庫,筆者之前出現過這幾個錯誤。

輸入命令

bochs

如果能顯示以下程式碼表示安裝成功

========================================================================
                   Bochs x86 Emulator 2.4.6
         Build from CVS snapshot, on February 22, 2011
               Compiled at Nov 14 2017, 22:04:17
========================================================================
00000000000i[     ] reading configuration from bochsrc
------------------------------
Bochs Configuration: Main Menu
------------------------------

This is the Bochs Configuration Interface, where you can describe the
machine that you want to simulate.  Bochs has already searched for a
configuration file (typically called bochsrc.txt) and loaded it if it
could be found.  When you are satisfied with the configuration, go
ahead and start the simulation.

You can also start bochs with the -q option to skip these menus.

1. Restore factory default configuration
2. Read options from...
3. Edit options
4. Save options to...
5. Restore the Bochs state from...
6. Begin simulation
7. Quit now

Please choose one: [6] 

正如書中所說,我們的bochs執行需要配置檔案,所以我們可以建立一個資料夾專門用於執行bochs。
這裡寫圖片描述

配置檔案

下面是我的配置檔案↓

# Configuration file for Bochs
###############################################################

# how much memory the emulated machine will have
megs: 32

# filename of ROM images
romimage: file=$BXSHARE/BIOS-bochs-latest
vgaromimage: file=$BXSHARE/VGABIOS-lgpl-latest

# what disk images will be used
floppya: 1_44=a.img, status=inserted

# choose the boot disk.
boot: a

# where do we send log messages?
# log: bochsout.txt

# disable the mouse
mouse: enabled=0

# enable key mapping, using US layout as default.
keyboard_mapping: enabled=1, map=/usr/local/share/bochs/keymaps/x11-pc-us.map

根據書中所說,主要是romiage和vgaromimage兩個的路徑需要與自己系統相符,其次是軟盤檔案的名詞需要對應還有boot的裝置要配置對(如果有多個裝置的話)書中的程式碼於文尾連結。

把書中bochsrc和a.img拷入建立的資料夾就可以運行了,執行結果如書中所示,會有紅色的P。

操作命令

具體的命令如書中所示,按c執行之後要按ctrl+c中斷才能進行後續輸入,按q是退出虛擬機器。

在Bochs中使用Dos的步驟

  1. 在文末下載的隨書原始碼壓縮包找到相應的章節,找到裡面的FreeDos.img,pm.img複製到自己的bochs目錄中。(或者安裝書中所說去bochs官網下載FreeDos)

  2. 更改我們的bochsrc檔案,在floppy那裡改為下面這樣

    floppya: 1_44=freedos.img, status=inserted
    
    floppyb: 1_44=pm.img, status=inserted
    
  3. 修改我們的程式碼,把07c00h改為0100h重新編譯,因為Dos與系統的載入位置不同。

    nasm pmtest1.asm -o pmtest1.com
    
  4. 製作軟盤pm.img,先將軟盤掛載在虛擬機器上然後把pmtest1.com:

    sudo mkdir mnt/floppy/
    sudo mount -o loop pm.img /mnt/floppy/
    sudo cp pmtest1.com /mnt/floppy/
    sudo umount /mnt/floppy/
    
  5. 執行Bochs,一開始A:的時候format,格式完之後執行

    b:\pmtest1.com
    

實驗結果如同上面,一個紅色的P出現,證明成功在FreeDos中運行了我們的程式。