微吼云上線多路互動直播服務 加速多場景互動直播落地
994
2022-05-28
操作系統實現1_bochs 和 nasm 安裝
1.1 bochs安裝
wget https://nchc.dl.sourceforge.net/project/bochs/bochs/2.6.9/bochs-2.6.9.tar.gz sudo tar zxvf bochs-2.6.9.tar.gz sudo ./configure --enable-debugger --enable-disasm sudo make sudo make install
1
2
3
4
5
安裝完成后顯示如下:
(coos) ubuntu@ubuntu:~/bochs-2.6.9$ bochs ======================================================================== Bochs x86 Emulator 2.6.9 Built from SVN snapshot on April 9, 2017 Compiled on Jan 26 2019 at 23:13:17 ======================================================================== 00000000000i[ ] BXSHARE not set. using compile time default '/usr/local/share/bochs' 00000000000i[ ] reading configuration from .bochsrc 00000000000e[ ] .bochsrc:187: wrong value for parameter 'model' 00000000000p[ ] >>PANIC<< .bochsrc:187: cpu directive malformed. 00000000000e[SIM ] notify called, but no bxevent_callback function is registered 00000000000e[SIM ] notify called, but no bxevent_callback function is registered ======================================================================== Bochs is exiting with the following message: [ ] .bochsrc:187: cpu directive malformed. ======================================================================== 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=0x000000000000, lin=0x00000000) 00000000000i[SIM ] quit_sim called with exit code 1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
1.2 nasm 安裝
sudo apt-get install nasm
1
1.3 示例程序
//boot.asm org 07c00h ; 告訴編譯程序加載到 7c00 處 mov ax, cs mov ds,ax mov es,ax call DispStr ; 調用顯示字符串例程 jmp $ ; 無限循環 DispStr: mov ax,BootMessage mov bp,ax ; ES : BP = 串地址 mov cx,16 ; CX = 串長度 mov ax,01301h ; AH = 13 , AL = 01h mov bx,000ch ; 頁號為 0 (BH = 0) 黑底紅字 (BL = 0Ch, 高亮) mov dl,0 int 10h ; 10h 號中斷 ret BootMessage: db "Hello, OS World!" times 510-($-$$) db 0 ; $-$$ 表示本行距離程序開始處的相對距離 ``; 用 0 填充剩下的空間,使生成二進制恰好 512 字節 dw 0xaa55 ; 結束標志
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
終端中編譯:
nasm boot.asm -o boot.bin
1
1.4 用 bochs 生成軟盤
終端輸入
bximage
1
操作如下:
ubuntu@ubuntu:~/coos$ bximage ======================================================================== bximage Disk Image Creation / Conversion / Resize and Commit Tool for Bochs $Id: bximage.cc 13069 2017-02-12 16:51:52Z vruppert $ ======================================================================== 1. Create new floppy or hard disk image 2. Convert hard disk image to other format (mode) 3. Resize hard disk image 4. Commit 'undoable' redolog to base image 5. Disk image info 0. Quit Please choose one [0] 1 Create image Do you want to create a floppy disk image or a hard disk image? Please type hd or fd. [hd] fd Choose the size of floppy disk image to create. Please type 160k, 180k, 320k, 360k, 720k, 1.2M, 1.44M, 1.68M, 1.72M, or 2.88M. [1.44M] What should be the name of the image? [a.img] a.img Creating floppy image 'a.img' with 2880 sectors The following line should appear in your bochsrc: floppya: image="a.img", status=inserted ubuntu@ubuntu:~/coos$
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
將引導扇區寫進軟盤:
dd if=boot.bin of=a.img bs=512 count=1 conv=notrunc
1
再編寫 bochsrc 配置
//bochsrc #configuration file foe bochs #how much memory the emulated machine will have megs: 32 #filename of ROM images romimage:file=/home/ubuntu/bochs-2.6.9/bios/BIOS-bochs-latest # 這個文件需要自己在電腦里找 vgaromimage:file=/home/ubuntu/bochs-2.6.9/bios/VGABIOS-lgpl-latest # 這個文件需要自己在電腦里找 #what disk images will be used floppya:1_44=a.img,status=inserted #choose he boot disk boot:floppy #where do we send log messages log:bochsout.txt #disable the mouse mouse:enabled=0 #enable key mapping,using US layout as default keyboard:keymap=/home/ubuntu/bochs-2.6.9/gui/keymaps/x11-pc-us.map
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
編寫完成后:
bochs -f bochsrc
1
調試指令略
結果如下:
Windows
版權聲明:本文內容由網絡用戶投稿,版權歸原作者所有,本站不擁有其著作權,亦不承擔相應法律責任。如果您發現本站中有涉嫌抄襲或描述失實的內容,請聯系我們jiasou666@gmail.com 處理,核實后本網站將在24小時內刪除侵權內容。