引导

硬盘引导模块

主机按下启动键后,CPU读取BIOS,BIOS初始化,将启动盘的第一扇区512B数据读到内存的0x7c00-0x7d00,并跳转至0x7c00。

这一段的代码的作用是: 选择要启动的分区,并将要启动分区的数据读至合适的内存位置并跳转。

start:

// 初始化各寄存器
    cli
    mov ss, ax
    mov sp, offset start
    mov ds, ax
    mov es, ax
    mov fs, ax
    mov gs, ax
    sti

   //将代码复制到0x7c00
    cld
    mov cx, 512 / 4
    mov si, HEX(7C00)
    mov di, offset start
    rep movsd

    // Jump to the relocated code.
    ljmp16 0, relocated

relocated:
    // 利用BIOS中断功能,读取启动扇区代码
    push 0
    push 0
    push dword ptr es:[pBootSectorLBA]
    push es
    push HEX(7C00)
    push 4
    push HEX(10)

    // Call the BIOS function. Note that we haven't clobbered DL up to this point, so the Drive Number passed by the BIOS is still there.
    // Read errors are indicated by the Carry Flag.
    mov ah, HEX(42)
    mov si, sp
    int HEX(13)
    jc read_error

    // Verify the Hybrid Signature.
    cmp dword ptr es:[pBootSectorHybridSignature], HybridSignature
    jne invalid_signature

    // 跳转至代码位置,
    ljmp16 0, pBootSectorHybridEntryPoint

read_error:
    call die_with_error
    .ascii "ISOMBR: Read Error!", CR, LF

invalid_signature:
    call die_with_error
    .ascii "ISOMBR: Invalid Boot Sector Hybrid Signature!", CR, LF

die_with_error:
    // Fetch the message to output stored at the return address on the stack.
    pop si

    // Call BIOS INT 10h, Function 0Eh to output a single character.
    // Do this in a loop and stop after we have printed the newline LF character.
next_character:
    lodsb
    mov ah, HEX(0E)
    xor bx, bx
    int HEX(10)
    cmp al, 10
    jne next_character

    // Die gracefully, that means in an infinite HLT loop to not put any stress on the CPU.
die:
    hlt
    jmp die

// The "isohybrid" tool will add the remaining information, including the infamous 0xAA55 MBR signature.
.org 431
    .byte 0

.endcode16

END

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

麻雀123

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值