操作系统学习_编译和写入_nasm dd

首先得有一个asm

;boot1.asm
;2017.8.16

;nasm boot1.asm -o boot

bits 16
org 7c00h

start:
    cli

; macro: FAST_A20_ENABLE
; description:
;                 set 0x92[1] to enable A20 line
        in al,0x92                                         ; port 0x92
        or al, 0x02                                                ; set A20 bit
        out 0x92, al
    sti

    mov ax,cs
    mov ds,ax
    mov ss,ax
    mov es,ax
    mov sp,7c00h

dot:        

        push ax

        push bx

        mov ah, 0x0e

        xor bh, bh

        mov al,'a'

        int 0x10                

        pop bx

        pop ax

        ret

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

times 510-($-$$) db 0
    dw 0xaa55

在命令行中

nasm boot1.asm -o boot
编译后输出为boot

当然你得先安装nasm

    sudo apt-get install nasm

之后是写入
首先得有一个空的img

bximage
执行后跟据提示完成制作
 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]** 

Creating floppy image 'a.img' with 2880 sectors

The following line should appear in your bochsrc:
  floppya: image="a.img", status=inserted

加粗的部分为需要输入的。

下面就可以用dd写入了

 dd if=boot of=demo.img count=1

if输入文件
of输出文件

现在打开bochs,如果配置文件没有错的话,应该是这样的

bochs 
========================================================================
                       Bochs x86 Emulator 2.6.9
               Built from SVN snapshot on April 9, 2017
                  Compiled on Aug 11 2017 at 18:38:30
========================================================================
00000000000i[      ] BXSHARE not set. using compile time default '/usr/local/share/bochs'
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] 

回车

Please choose one: [6] 
00000000000i[      ] installing x module as the Bochs GUI
00000000000i[      ] using log file bochsout.txt
Next at t=0
(0) [0x0000fffffff0] f000:fff0 (unk. ctxt): jmpf 0xf000:e05b          ; ea5be000f0
<bochs:1> 

如果回车后有报错,就需要按照提示折腾一下。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值