操作系统实现1_bochs 和 nasm 安装

举报
陈沧夜 发表于 2022/05/06 22:51:09 2022/05/06
【摘要】 操作系统实现1_bochs 和 nasm 安装 1.1 bochs安装 wget https://nchc.dl.sourceforge.net/project/bochs/bochs/2.6.9/b...

操作系统实现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

调试指令略
结果如下:
在这里插入图片描述

文章来源: blog.csdn.net,作者:沧夜2021,版权归原作者所有,如需转载,请联系作者。

原文链接:blog.csdn.net/CANGYE0504/article/details/86664947

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。