知是行的主意,行是知的功夫。这篇文章主要讲述操作系统实现1_bochs 和 nasm 安装相关的知识,希望能为你提供帮助。
操作系统实现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
安装完成后显示如下:
(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=00000000EBX=00000000ECX=00000000EDX=00000000
00000000000i[CPU0] | ESP=00000000EBP=00000000ESI=00000000EDI=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)baselimit 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 nasm 安装
sudo apt-get install nasm
1.3 示例程序
//boot.asm
org07c00h;
告诉编译程序加载到 7c00 处
movax, cs
movds,ax
moves,ax
callDispStr ;
调用显示字符串例程
jmp$ ;
无限循环
DispStr:
movax,BootMessage
movbp,ax;
ES : BP = 串地址
movcx,16;
CX = 串长度
movax,01301h ;
AH = 13 , AL = 01h
movbx,000ch ;
页号为 0 (BH = 0) 黑底红字 (BL = 0Ch, 高亮)
movdl,0
int10h;
10h 号中断
ret
BootMessage: db "Hello, OS World!"
times510-($-$$) db 0;
$-$$ 表示本行距离程序开始处的相对距离
``;
用 0 填充剩下的空间,使生成二进制恰好 512 字节
dw0xaa55 ;
结束标志
终端中编译:
nasm boot.asm -o boot.bin
1.4 用 bochs 生成软盘
终端输入
bximage
操作如下:
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 info0. QuitPlease choose one [0] 1Create imageDo you want to create a floppy disk image or a hard disk image?
Please type hd or fd. [hd] fdChoose 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.imgCreating floppy image a.img with 2880 sectorsThe following line should appear in your bochsrc:
floppya: image="a.img", status=inserted
ubuntu@ubuntu:~/coos$
将引导扇区写进软盘:
dd if=boot.bin of=a.img bs=512 count=1 conv=notrunc
再编写 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
编写完成后:
bochs -f bochsrc
【操作系统实现1_bochs 和 nasm 安装】调试指令略
结果如下:
文章图片
推荐阅读
- ssh相关工具
- poj1850 Code
- oeasy教您玩转vim - 81 - # 宏macro的进阶
- WINDOWS7右键菜单只能新建文件夹正常吗()
- 服务器特点
- Centos7安装Redis
- c#-string 插值
- 防火墙基础及编写规则
- 揭开“QUIC”的神秘面纱