自己动手写操作系统之1:bochs初步使用
0x00 前言
自己動手寫操作系統,自然需要一個承載程序的運行環境,這一章記錄我使用bochs遇到的坑,凌晨十二點半才填完坑。
這次記錄的是使用bochs完整實現一個最簡單的操作系統(其實根本不算操作系統,只是通過硬盤啟動個mbr程序)。
0x01 bochs
1.安裝
安裝比較簡單了,我沒有使用源碼安裝,不想再折騰那個了,不然估計我就沒戲能開始了。
yum install bochs bochs-x -y需要裝兩個東東,后面一個如果不過,會報錯,如果報錯可以看我后面的錯誤記錄。
2.配置文件
bochs需要一個配置文件,來描述硬件信息。文件里面有詳細的注釋。
配置文件就叫bochs.disk,名字可以隨意,后綴是什么也無所謂。
############################################################### # Configuration file for Bochs ################################################################ how much memory the emulated machine will have megs: 32# 對應真實機器的BIOS和VGA BIOS romimage: file=/usr/share/bochs/BIOS-bochs-latest vgaromimage: file=/usr/share/bochs/VGABIOS-lgpl-latest# 設置bochs使用的磁盤,軟盤使用關鍵字floppya,硬盤使用disk # 若有多個軟盤,可寫floppya,floppyb #floppya: 1_44=a.img, status=inserted# choose the boot disk. # 默認是軟盤,注釋掉,改為disk #boot: floppy boot: disk# where do we send log messages? log: /tmp/bochsout.txt # disable the mouse mouse: enabled=0# enable key mapping, using US layout as default. keyboard_mapping: enabled=1, map=/usr/share/bochs/keymaps/x11-pc-us.mapata0: enabled=1, ioaddr1=0x1f0, ioaddr2=0x3f0, irq=14#這一句是根據bximage生成的,后面會解釋。 ata0-master: type=disk, path="/home/dante/workspace/os/hd60M.img", mode=flat, cylinders=121, heads=16, spt=633.制作虛擬硬盤
這里使用bochs配備的bximage。
root@dante-pc:/home/dante/workspace/os# bximage -hd -mode='flat' -size=60 -q hd60M.img========================================================================bximageDisk Image Creation Tool for Bochs$Id: bximage.c 11315 2012-08-05 18:13:38Z vruppert $ ========================================================================I will create a 'flat' hard disk image withcyl=121heads=16sectors per track=63total sectors=121968total size=59.55 megabytesWriting: [] Done.I wrote 62447616 bytes to hd60M.img.The following line should appear in your bochsrc:ata0-master: type=disk, path="hd60M.img", mode=flat, cylinders=121, heads=16, spt=63看到輸出的最后一句,指示我們把這句寫入bochs的配置文件中。
4.程序寫入硬盤
此處的mbr.bin是通過匯編編譯后生成的文件,下一篇博客專門記錄這次實現的匯編代碼。
代碼實現的內容就是在屏幕上打印幾個字符。
××注意:×如無必要,后面的參數就不要改了,如果想知道每個參數改了×改后在啟動的時候會出錯。不過也可以看一下錯誤信息多了解點知識。
root@dante-pc:/home/dante/workspace/os# dd if=mbr.bin of=hd60M.img bs=512 count=1 conv=notrunc 記錄了0+1 的讀入 記錄了0+1 的寫出 502字節(502 B)已復制,0.000140041 秒,3.6 MB/秒5.啟動
bochs -f bochs.disk這樣就能看到在界面上打印的字符了。
0x02 錯誤列表
錯誤1
錯誤信息
Event type: PANIC Device: [ ] Message: dlopen failed for module 'x': file not foundA PANIC has occurred. Do you want to:cont - continue executionalwayscont - continue execution, and don't ask again.This affects only PANIC events from device [ ]die - stop execution nowabort - dump core debug - continue and return to bochs debugger Choose one of the actions above: [die]分析和解決
這是由于在安裝的時候,少安裝了個bochs-x包,安裝即可。
sudo apt-get install bochs-x錯誤2
錯誤信息
# bochs -f bochs.disk ========================================================================Bochs x86 Emulator 2.6Built from SVN snapshot on September 2nd, 2012Compiled on Aug 10 2015 at 10:27:14 ======================================================================== 00000000000i[ ] LTDL_LIBRARY_PATH not set. using compile time default '/usr/lib/bochs/plugins' 00000000000i[ ] BXSHARE not set. using compile time default '/usr/share/bochs' 00000000000i[ ] lt_dlhandle is 0x3ae4fe0 00000000000i[PLGIN] loaded plugin libbx_unmapped.so 00000000000i[ ] lt_dlhandle is 0x3ae6ba0 00000000000i[PLGIN] loaded plugin libbx_biosdev.so 00000000000i[ ] lt_dlhandle is 0x3ae74e0 00000000000i[PLGIN] loaded plugin libbx_speaker.so 00000000000i[ ] lt_dlhandle is 0x3ae7d50 00000000000i[PLGIN] loaded plugin libbx_extfpuirq.so 00000000000i[ ] lt_dlhandle is 0x3ae8590 00000000000i[PLGIN] loaded plugin libbx_parallel.so 00000000000i[ ] lt_dlhandle is 0x3aea240 00000000000i[PLGIN] loaded plugin libbx_serial.so 00000000000i[ ] lt_dlhandle is 0x3aede20 00000000000i[PLGIN] loaded plugin libbx_gameport.so 00000000000i[ ] lt_dlhandle is 0x3aee8c0 00000000000i[PLGIN] loaded plugin libbx_iodebug.so 00000000000i[ ] reading configuration from bochs.disk 00000000000p[ ] >>PANIC<< reading from bochs.disk failed 00000000000e[CTRL ] notify called, but no bxevent_callback function is registered 00000000000i[CPU0 ] CPU is in real mode (active) 00000000000i[CPU0 ] CS.mode = 16 bit 00000000000i[CPU0 ] SS.mode = 16 bit 00000000000i[CPU0 ] EFER = 0x00000000 00000000000i[CPU0 ] | EAX=00000000 EBX=00000000 ECX=00000000 EDX=00000000 00000000000i[CPU0 ] | ESP=00000000 EBP=00000000 ESI=00000000 EDI=00000000 00000000000i[CPU0 ] | IOPL=0 id vip vif ac vm rf nt of df if tf sf ZF af PF cf 00000000000i[CPU0 ] | SEG sltr(index|ti|rpl) base limit G D 00000000000i[CPU0 ] | CS:0000( 0000| 0| 0) 00000000 00000000 0 0 00000000000i[CPU0 ] | DS:0000( 0000| 0| 0) 00000000 00000000 0 0 00000000000i[CPU0 ] | SS:0000( 0000| 0| 0) 00000000 00000000 0 0 00000000000i[CPU0 ] | ES:0000( 0000| 0| 0) 00000000 00000000 0 0 00000000000i[CPU0 ] | FS:0000( 0000| 0| 0) 00000000 00000000 0 0 00000000000i[CPU0 ] | GS:0000( 0000| 0| 0) 00000000 00000000 0 0 00000000000i[CPU0 ] | EIP=00000000 (00000000) 00000000000i[CPU0 ] | CR0=0x00000000 CR2=0x00000000 00000000000i[CPU0 ] | CR3=0x00000000 CR4=0x00000000 bx_dbg_read_linear: physical memory read error (phy=0x0000000000000000, lin=0x0000000000000000) 00000000000i[CTRL ] quit_sim called with exit code 1分析和解決
將boch.disk文件中的vgaromimage: /usr/share/vgabios/vgabios.bin改為vgaromimage: file=/usr/share/vgabios/vgabios.bin即可,出現這種錯誤的,很多是因為直接使用了orange‘s的代碼。
錯誤3
錯誤信息
啟動bochs后沒有反應,一直是黑屏。
...... 00000000000e[ ] bochs.disk:28: 'keyboard_mapping' will be replacedby new 'keyboard' option. 00000000000i[ ] lt_dlhandle is 0x36ac110 00000000000i[PLGIN] loaded plugin libbx_x.so 00000000000i[ ] installing x module as the Bochs GUI 00000000000i[ ] using log file /tmp/bochsout.txt Next at t=0 (0) [0x00000000fffffff0] f000:fff0 (unk. ctxt): jmp far f000:e05b ; ea5be000f0 <bochs:1>分析和解決
因為網路不好,也沒有翻墻,官網進不去,在一個論壇里面看到,直接輸入c接可以了。
錯誤4
錯誤信息
啟動后出現無啟動設備的錯誤。
Boot failed: not a bootable device. FATAL:No bootable device.分析和解決
這個問題我也忘了具體是怎么改的了,不過根據回憶,應該是和程序相關,我中間改過一次程序,沖洗編譯并使用dd寫入后就沒問題了。
我和網上其它人遇到的錯誤情形還不太一樣。
http://blog.csdn.net/zhaodedong
http://zhaodedong.leanote.com
http://zhaodedong.com
2016-04-07 00:56:00 hnds
總結
以上是生活随笔為你收集整理的自己动手写操作系统之1:bochs初步使用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 工作总结8:关于Vue中的slot-sc
- 下一篇: 前端学习(2323):angular文件